@coreui/vue-pro 5.14.0 → 5.16.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 (127) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/components/calendar/CCalendar.js +67 -65
  3. package/dist/cjs/components/calendar/CCalendar.js.map +1 -1
  4. package/dist/cjs/components/calendar/utils.d.ts +53 -2
  5. package/dist/cjs/components/calendar/utils.js +466 -43
  6. package/dist/cjs/components/calendar/utils.js.map +1 -1
  7. package/dist/cjs/components/date-range-picker/CDateRangePicker.js +86 -57
  8. package/dist/cjs/components/date-range-picker/CDateRangePicker.js.map +1 -1
  9. package/dist/cjs/components/date-range-picker/utils.d.ts +0 -9
  10. package/dist/cjs/components/date-range-picker/utils.js +0 -38
  11. package/dist/cjs/components/date-range-picker/utils.js.map +1 -1
  12. package/dist/cjs/components/dropdown/CDropdown.d.ts +32 -7
  13. package/dist/cjs/components/dropdown/CDropdown.js +67 -29
  14. package/dist/cjs/components/dropdown/CDropdown.js.map +1 -1
  15. package/dist/cjs/components/dropdown/CDropdownToggle.d.ts +19 -0
  16. package/dist/cjs/components/dropdown/CDropdownToggle.js +17 -2
  17. package/dist/cjs/components/dropdown/CDropdownToggle.js.map +1 -1
  18. package/dist/cjs/components/dropdown/utils.d.ts +2 -0
  19. package/dist/cjs/components/dropdown/utils.js +13 -0
  20. package/dist/cjs/components/dropdown/utils.js.map +1 -1
  21. package/dist/cjs/components/focus-trap/CFocusTrap.d.ts +108 -0
  22. package/dist/cjs/components/focus-trap/CFocusTrap.js +254 -0
  23. package/dist/cjs/components/focus-trap/CFocusTrap.js.map +1 -0
  24. package/dist/cjs/components/focus-trap/index.d.ts +6 -0
  25. package/dist/cjs/components/focus-trap/index.js +13 -0
  26. package/dist/cjs/components/focus-trap/index.js.map +1 -0
  27. package/dist/cjs/components/focus-trap/utils.d.ts +28 -0
  28. package/dist/cjs/components/focus-trap/utils.js +83 -0
  29. package/dist/cjs/components/focus-trap/utils.js.map +1 -0
  30. package/dist/cjs/components/index.d.ts +1 -0
  31. package/dist/cjs/components/index.js +70 -66
  32. package/dist/cjs/components/index.js.map +1 -1
  33. package/dist/cjs/components/modal/CModal.d.ts +2 -2
  34. package/dist/cjs/components/modal/CModal.js +19 -27
  35. package/dist/cjs/components/modal/CModal.js.map +1 -1
  36. package/dist/cjs/components/modal/CModalHeader.js +4 -2
  37. package/dist/cjs/components/modal/CModalHeader.js.map +1 -1
  38. package/dist/cjs/components/nav/CNavItem.d.ts +2 -2
  39. package/dist/cjs/components/offcanvas/COffcanvas.js +3 -2
  40. package/dist/cjs/components/offcanvas/COffcanvas.js.map +1 -1
  41. package/dist/cjs/components/picker/CPicker.js +3 -2
  42. package/dist/cjs/components/picker/CPicker.js.map +1 -1
  43. package/dist/cjs/components/time-picker/CTimePicker.d.ts +45 -1
  44. package/dist/cjs/components/time-picker/CTimePicker.js +64 -8
  45. package/dist/cjs/components/time-picker/CTimePicker.js.map +1 -1
  46. package/dist/cjs/components/time-picker/CTimePickerRollCol.d.ts +19 -7
  47. package/dist/cjs/components/time-picker/CTimePickerRollCol.js +80 -8
  48. package/dist/cjs/components/time-picker/CTimePickerRollCol.js.map +1 -1
  49. package/dist/cjs/components/time-picker/utils.d.ts +1 -1
  50. package/dist/cjs/composables/useDebouncedCallback.d.ts +1 -1
  51. package/dist/cjs/composables/useDebouncedCallback.js +1 -1
  52. package/dist/cjs/composables/useDebouncedCallback.js.map +1 -1
  53. package/dist/cjs/index.js +76 -72
  54. package/dist/cjs/index.js.map +1 -1
  55. package/dist/esm/components/calendar/CCalendar.js +67 -65
  56. package/dist/esm/components/calendar/CCalendar.js.map +1 -1
  57. package/dist/esm/components/calendar/utils.d.ts +53 -2
  58. package/dist/esm/components/calendar/utils.js +464 -44
  59. package/dist/esm/components/calendar/utils.js.map +1 -1
  60. package/dist/esm/components/date-range-picker/CDateRangePicker.js +86 -57
  61. package/dist/esm/components/date-range-picker/CDateRangePicker.js.map +1 -1
  62. package/dist/esm/components/date-range-picker/utils.d.ts +0 -9
  63. package/dist/esm/components/date-range-picker/utils.js +1 -38
  64. package/dist/esm/components/date-range-picker/utils.js.map +1 -1
  65. package/dist/esm/components/dropdown/CDropdown.d.ts +32 -7
  66. package/dist/esm/components/dropdown/CDropdown.js +69 -31
  67. package/dist/esm/components/dropdown/CDropdown.js.map +1 -1
  68. package/dist/esm/components/dropdown/CDropdownToggle.d.ts +19 -0
  69. package/dist/esm/components/dropdown/CDropdownToggle.js +17 -2
  70. package/dist/esm/components/dropdown/CDropdownToggle.js.map +1 -1
  71. package/dist/esm/components/dropdown/utils.d.ts +2 -0
  72. package/dist/esm/components/dropdown/utils.js +13 -1
  73. package/dist/esm/components/dropdown/utils.js.map +1 -1
  74. package/dist/esm/components/focus-trap/CFocusTrap.d.ts +108 -0
  75. package/dist/esm/components/focus-trap/CFocusTrap.js +252 -0
  76. package/dist/esm/components/focus-trap/CFocusTrap.js.map +1 -0
  77. package/dist/esm/components/focus-trap/index.d.ts +6 -0
  78. package/dist/esm/components/focus-trap/index.js +10 -0
  79. package/dist/esm/components/focus-trap/index.js.map +1 -0
  80. package/dist/esm/components/focus-trap/utils.d.ts +28 -0
  81. package/dist/esm/components/focus-trap/utils.js +78 -0
  82. package/dist/esm/components/focus-trap/utils.js.map +1 -0
  83. package/dist/esm/components/index.d.ts +1 -0
  84. package/dist/esm/components/index.js +2 -0
  85. package/dist/esm/components/index.js.map +1 -1
  86. package/dist/esm/components/modal/CModal.d.ts +2 -2
  87. package/dist/esm/components/modal/CModal.js +19 -27
  88. package/dist/esm/components/modal/CModal.js.map +1 -1
  89. package/dist/esm/components/modal/CModalHeader.js +4 -2
  90. package/dist/esm/components/modal/CModalHeader.js.map +1 -1
  91. package/dist/esm/components/nav/CNavItem.d.ts +2 -2
  92. package/dist/esm/components/offcanvas/COffcanvas.js +3 -2
  93. package/dist/esm/components/offcanvas/COffcanvas.js.map +1 -1
  94. package/dist/esm/components/picker/CPicker.js +3 -2
  95. package/dist/esm/components/picker/CPicker.js.map +1 -1
  96. package/dist/esm/components/time-picker/CTimePicker.d.ts +45 -1
  97. package/dist/esm/components/time-picker/CTimePicker.js +64 -8
  98. package/dist/esm/components/time-picker/CTimePicker.js.map +1 -1
  99. package/dist/esm/components/time-picker/CTimePickerRollCol.d.ts +19 -7
  100. package/dist/esm/components/time-picker/CTimePickerRollCol.js +80 -8
  101. package/dist/esm/components/time-picker/CTimePickerRollCol.js.map +1 -1
  102. package/dist/esm/components/time-picker/utils.d.ts +1 -1
  103. package/dist/esm/composables/useDebouncedCallback.d.ts +1 -1
  104. package/dist/esm/composables/useDebouncedCallback.js +1 -1
  105. package/dist/esm/composables/useDebouncedCallback.js.map +1 -1
  106. package/dist/esm/index.js +2 -0
  107. package/dist/esm/index.js.map +1 -1
  108. package/package.json +5 -5
  109. package/src/components/calendar/CCalendar.ts +61 -70
  110. package/src/components/calendar/utils.ts +595 -47
  111. package/src/components/date-range-picker/CDateRangePicker.ts +131 -82
  112. package/src/components/date-range-picker/utils.ts +0 -58
  113. package/src/components/dropdown/CDropdown.ts +119 -52
  114. package/src/components/dropdown/CDropdownToggle.ts +18 -3
  115. package/src/components/dropdown/utils.ts +21 -0
  116. package/src/components/focus-trap/CFocusTrap.ts +303 -0
  117. package/src/components/focus-trap/index.ts +10 -0
  118. package/src/components/focus-trap/utils.ts +90 -0
  119. package/src/components/index.ts +1 -0
  120. package/src/components/modal/CModal.ts +32 -37
  121. package/src/components/modal/CModalHeader.ts +5 -3
  122. package/src/components/nav/CNavItem.ts +1 -1
  123. package/src/components/offcanvas/COffcanvas.ts +40 -36
  124. package/src/components/picker/CPicker.ts +58 -52
  125. package/src/components/time-picker/CTimePicker.ts +80 -22
  126. package/src/components/time-picker/CTimePickerRollCol.ts +87 -9
  127. package/src/composables/useDebouncedCallback.ts +1 -1
@@ -3,31 +3,421 @@
3
3
  * @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05").
4
4
  * @returns The Date object for the Monday of the specified week, or null if invalid.
5
5
  */
6
+ /**
7
+ * Helper function to calculate Monday of ISO week 1 for a given year.
8
+ * @param year - The year to calculate for.
9
+ * @returns The Monday of ISO week 1.
10
+ */
11
+ const getMondayOfISOWeek1 = (year) => {
12
+ const jan4 = new Date(year, 0, 4);
13
+ const jan4DayOfWeek = jan4.getDay();
14
+ const daysFromMonday = jan4DayOfWeek === 0 ? 6 : jan4DayOfWeek - 1; // Sunday = 6 days from Monday
15
+ const mondayOfWeek1 = new Date(jan4);
16
+ mondayOfWeek1.setDate(jan4.getDate() - daysFromMonday);
17
+ return mondayOfWeek1;
18
+ };
19
+ /**
20
+ * Helper function to calculate Monday of a specific ISO week.
21
+ * @param year - The year.
22
+ * @param week - The ISO week number.
23
+ * @returns The Monday of the specified ISO week.
24
+ */
25
+ const getMondayOfISOWeek = (year, week) => {
26
+ const mondayOfWeek1 = getMondayOfISOWeek1(year);
27
+ const weekStart = new Date(mondayOfWeek1);
28
+ // prettier-ignore
29
+ weekStart.setDate(mondayOfWeek1.getDate() + ((week - 1) * 7));
30
+ return weekStart;
31
+ };
32
+ /**
33
+ * Helper function to convert a date to a month number for comparison.
34
+ * @param date - The date to convert.
35
+ * @returns A number representing year*12 + month for easy comparison.
36
+ */
37
+ const dateToMonthNumber = (date) => {
38
+ // prettier-ignore
39
+ return (date.getFullYear() * 12) + date.getMonth();
40
+ };
41
+ /**
42
+ * Helper function to check if a value is within min/max range.
43
+ * @param value - The value to check.
44
+ * @param min - Minimum allowed value (null means no minimum).
45
+ * @param max - Maximum allowed value (null means no maximum).
46
+ * @returns True if the value is outside the range, false if within range.
47
+ */
48
+ const isOutsideRange = (value, min, max) => {
49
+ if (min !== null && value < min) {
50
+ return true;
51
+ }
52
+ if (max !== null && value > max) {
53
+ return true;
54
+ }
55
+ return false;
56
+ };
57
+ /**
58
+ * Converts an ISO week string to a Date object representing the Monday of that week.
59
+ * @param isoWeek - The ISO week string (e.g., "2023W05" or "2023w05").
60
+ * @returns The Date object for the Monday of the specified week.
61
+ */
6
62
  const convertIsoWeekToDate = (isoWeek) => {
7
63
  const [year, week] = isoWeek.split(/[Ww]/);
8
- const date = new Date(Number(year), 0, 4); // 4th Jan is always in week 1
9
- date.setDate(date.getDate() - (date.getDay() || 7) + 1 + (Number(week) - 1) * 7);
10
- return date;
64
+ const parsedYear = parseYearSmart(year);
65
+ const parsedWeek = Number.parseInt(week, 10);
66
+ // Create date from ISO week using helper function
67
+ return getMondayOfISOWeek(parsedYear, parsedWeek);
68
+ };
69
+ /**
70
+ * Parses a week string and returns a Date object for the Monday of that week.
71
+ * @param dateString - The week string to parse.
72
+ * @returns The Date object for the Monday of the week, or null if invalid.
73
+ */
74
+ const parseWeekString = (dateString) => {
75
+ const weekPatterns = [
76
+ /^(\d{4})-W(\d{1,2})$/, // 2023-W05, 2023-W5
77
+ /^(\d{4})W(\d{1,2})$/, // 2023W05, 2023W5
78
+ /^(\d{4})\s+W(\d{1,2})$/, // 2023 W05, 2023 W5
79
+ ];
80
+ for (const pattern of weekPatterns) {
81
+ const match = dateString.trim().match(pattern);
82
+ if (match) {
83
+ const parsedYear = parseYearSmart(match[1]);
84
+ const parsedWeek = Number.parseInt(match[2], 10);
85
+ // Create date from ISO week using helper function
86
+ return getMondayOfISOWeek(parsedYear, parsedWeek);
87
+ }
88
+ }
89
+ // Fallback to existing ISO week parsing
90
+ return convertIsoWeekToDate(dateString);
91
+ };
92
+ /**
93
+ * Parses a month string and returns a Date object for the first day of that month.
94
+ * @param dateString - The month string to parse.
95
+ * @returns The Date object for the first day of the month, or null if invalid.
96
+ */
97
+ const parseMonthString = (dateString) => {
98
+ const monthPatterns = [
99
+ /^(\d{2,4})[-/.\s](\d{1,2})$/, // 2023-12, 23-12, 2023/12, 23/12, 2023 12, etc.
100
+ /^(\d{1,2})[-/.\s](\d{2,4})$/, // 12-2023, 12-23, 12/2023, 12/23, 12 2023, etc.
101
+ ];
102
+ for (const pattern of monthPatterns) {
103
+ const match = dateString.trim().match(pattern);
104
+ if (match) {
105
+ const firstGroup = match[1];
106
+ const secondGroup = match[2];
107
+ // Determine which group is year and which is month
108
+ const parsedFirst = Number.parseInt(firstGroup, 10);
109
+ const parsedSecond = Number.parseInt(secondGroup, 10);
110
+ let parsedYear;
111
+ let parsedMonth;
112
+ // Determine which group is year and which is month based on several heuristics
113
+ if (firstGroup.length >= 3 || parsedFirst >= 100) {
114
+ // First group is clearly a year (3+ digits or >= 100)
115
+ parsedYear = parseYearSmart(firstGroup);
116
+ parsedMonth = parsedSecond - 1;
117
+ }
118
+ else if (secondGroup.length >= 3 || parsedSecond >= 100) {
119
+ // Second group is clearly a year (3+ digits or >= 100)
120
+ parsedYear = parseYearSmart(secondGroup);
121
+ parsedMonth = parsedFirst - 1;
122
+ }
123
+ else {
124
+ // Both groups are 1-2 digits, use context clues
125
+ // If second group is a valid month (1-12), treat first as year
126
+ if (parsedSecond >= 1 && parsedSecond <= 12 && (parsedFirst > 12 || parsedFirst < 1)) {
127
+ parsedYear = parseYearSmart(firstGroup);
128
+ parsedMonth = parsedSecond - 1;
129
+ }
130
+ else {
131
+ // Default: treat second group as year
132
+ parsedYear = parseYearSmart(secondGroup);
133
+ parsedMonth = parsedFirst - 1;
134
+ }
135
+ }
136
+ if (parsedMonth >= 0 && parsedMonth <= 11) {
137
+ return new Date(parsedYear, parsedMonth, 1);
138
+ }
139
+ }
140
+ }
141
+ // For month selection, don't use fallback parsing - return null if no pattern matches
142
+ return null;
143
+ };
144
+ /**
145
+ * Parses a year string or number and returns a Date object for January 1st of that year.
146
+ * @param dateString - The year string or number to parse.
147
+ * @returns The Date object for January 1st of the year, or null if invalid.
148
+ */
149
+ const parseYearString = (dateString) => {
150
+ const yearString = String(dateString);
151
+ const yearPattern = /^(\d{2,4})$/;
152
+ const match = yearString.trim().match(yearPattern);
153
+ if (match) {
154
+ const groups = { year: match[1] };
155
+ return createDateFromYear(groups);
156
+ }
157
+ return parseLocalDateString(yearString);
158
+ };
159
+ /**
160
+ * Helper function to generate multiple date format patterns based on locale.
161
+ * @param locale - The locale to use for date format patterns.
162
+ * @param includeTime - Whether to include time in the patterns.
163
+ * @returns Array of date format patterns.
164
+ */
165
+ const generateDatePatterns = (locale, includeTime) => {
166
+ const referenceDate = new Date(2013, 11, 31, 17, 19, 22);
167
+ const patterns = [];
168
+ try {
169
+ // Get the standard locale format
170
+ const standardFormat = includeTime
171
+ ? referenceDate.toLocaleString(locale)
172
+ : referenceDate.toLocaleDateString(locale);
173
+ patterns.push(standardFormat);
174
+ }
175
+ catch {
176
+ // Fallback to default locale if invalid locale provided
177
+ const standardFormat = includeTime
178
+ ? referenceDate.toLocaleString('en-US')
179
+ : referenceDate.toLocaleDateString('en-US');
180
+ patterns.push(standardFormat);
181
+ }
182
+ // Generate common alternative formats by replacing separators
183
+ const separators = ['/', '-', '.', ' '];
184
+ const standardFormat = patterns[0];
185
+ // Detect the original separator
186
+ let originalSeparator = '/'; // default
187
+ if (standardFormat.includes('/')) {
188
+ originalSeparator = '/';
189
+ }
190
+ else if (standardFormat.includes('-')) {
191
+ originalSeparator = '-';
192
+ }
193
+ else if (standardFormat.includes('.')) {
194
+ originalSeparator = '.';
195
+ }
196
+ for (const sep of separators) {
197
+ if (sep !== originalSeparator) {
198
+ // Escape the original separator for regex if it's a special character
199
+ const escapedSeparator = originalSeparator.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
200
+ const altFormat = standardFormat.replaceAll(new RegExp(escapedSeparator, 'g'), sep);
201
+ patterns.push(altFormat);
202
+ }
203
+ }
204
+ return patterns;
205
+ };
206
+ /**
207
+ * Helper function to build regex pattern for date parsing.
208
+ * @param formatString - The date format string.
209
+ * @param includeTime - Whether to include time patterns.
210
+ * @returns The regex pattern string.
211
+ */
212
+ const buildDateRegexPattern = (formatString, includeTime) => {
213
+ // First escape special regex characters
214
+ // eslint-disable-next-line unicorn/prefer-string-raw
215
+ let regexPattern = formatString.replaceAll(/[.*+?^${}()|[\\]\\]/g, '\\$&');
216
+ // Then replace the date/time components with regex groups
217
+ regexPattern = regexPattern
218
+ .replace('2013', String.raw `(?<year>\d{2,4})`)
219
+ .replace('12', String.raw `(?<month>\d{1,2})`)
220
+ .replace('31', String.raw `(?<day>\d{1,2})`);
221
+ if (includeTime) {
222
+ regexPattern = regexPattern
223
+ .replaceAll(/17|5/g, String.raw `(?<hour>\d{1,2})`)
224
+ .replace('19', String.raw `(?<minute>\d{1,2})`)
225
+ .replace('22', String.raw `(?<second>\d{1,2})`)
226
+ .replaceAll(/AM|PM/gi, '(?<ampm>[APap][Mm])');
227
+ }
228
+ return regexPattern;
229
+ };
230
+ /**
231
+ * Helper function to try parsing with multiple patterns.
232
+ * @param dateString - The date string to parse.
233
+ * @param patterns - Array of format patterns to try.
234
+ * @param includeTime - Whether time parsing is included.
235
+ * @returns Parsed groups or null if no match.
236
+ */
237
+ const tryParseWithPatterns = (dateString, patterns, includeTime) => {
238
+ for (const pattern of patterns) {
239
+ const regexPattern = buildDateRegexPattern(pattern, includeTime);
240
+ const regex = new RegExp(`^${regexPattern}$`);
241
+ const match = dateString.trim().match(regex);
242
+ if (match?.groups) {
243
+ return match.groups;
244
+ }
245
+ }
246
+ return null;
247
+ };
248
+ /**
249
+ * Helper function to convert 12-hour to 24-hour format.
250
+ * @param hour - Hour string.
251
+ * @param ampm - AM/PM indicator.
252
+ * @returns Hour in 24-hour format.
253
+ */
254
+ const convertTo24Hour = (hour, ampm) => {
255
+ const parsedHour = Number.parseInt(hour, 10);
256
+ if (!ampm) {
257
+ return parsedHour;
258
+ }
259
+ const isPM = ampm.toLowerCase() === 'pm';
260
+ if (isPM && parsedHour !== 12) {
261
+ return parsedHour + 12;
262
+ }
263
+ if (!isPM && parsedHour === 12) {
264
+ return 0;
265
+ }
266
+ return parsedHour;
267
+ };
268
+ /**
269
+ * Helper function to validate time components.
270
+ * @param hour - Hour value.
271
+ * @param minute - Minute value.
272
+ * @param second - Second value.
273
+ * @returns True if time components are valid.
274
+ */
275
+ const validateTimeComponents = (hour, minute, second) => {
276
+ return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59;
277
+ };
278
+ /**
279
+ * Helper function to validate date components.
280
+ * @param month - Month string.
281
+ * @param day - Day string.
282
+ * @returns True if date components are valid.
283
+ */
284
+ const validateDateComponents = (month, day) => {
285
+ const parsedMonth = Number.parseInt(month, 10) - 1;
286
+ const parsedDay = Number.parseInt(day, 10);
287
+ return parsedMonth >= 0 && parsedMonth <= 11 && parsedDay >= 1 && parsedDay <= 31;
288
+ };
289
+ /**
290
+ * Helper function to create date with time.
291
+ * @param groups - Parsed date and time groups.
292
+ * @returns Date object or null if invalid.
293
+ */
294
+ const createDateWithTime = (groups) => {
295
+ const { year, month, day, hour, minute, second, ampm } = groups;
296
+ const parsedYear = parseYearSmart(year);
297
+ const parsedMonth = Number.parseInt(month, 10) - 1;
298
+ const parsedDay = Number.parseInt(day, 10);
299
+ const parsedHour = convertTo24Hour(hour, ampm);
300
+ const parsedMinute = Number.parseInt(minute ?? '0', 10) || 0;
301
+ const parsedSecond = Number.parseInt(second ?? '0', 10) || 0;
302
+ if (!validateTimeComponents(parsedHour, parsedMinute, parsedSecond)) {
303
+ return null;
304
+ }
305
+ return new Date(parsedYear, parsedMonth, parsedDay, parsedHour, parsedMinute, parsedSecond);
306
+ };
307
+ /**
308
+ * Helper function to create date without time.
309
+ * @param groups - Parsed date groups.
310
+ * @returns Date object or null if invalid.
311
+ */
312
+ const createDateOnly = (groups) => {
313
+ const { year, month, day } = groups;
314
+ if (!validateDateComponents(month, day)) {
315
+ return null;
316
+ }
317
+ const parsedYear = parseYearSmart(year);
318
+ const parsedMonth = Number.parseInt(month, 10) - 1;
319
+ const parsedDay = Number.parseInt(day, 10);
320
+ return new Date(parsedYear, parsedMonth, parsedDay);
321
+ };
322
+ /**
323
+ * Enhanced day parsing with locale-aware patterns.
324
+ * @param dateString - The day string to parse.
325
+ * @param locale - The locale to use for parsing.
326
+ * @param includeTime - Whether to include time parsing.
327
+ * @returns Date object or null if invalid.
328
+ */
329
+ const parseDayString = (dateString, locale, includeTime) => {
330
+ const patterns = generateDatePatterns(locale, includeTime);
331
+ const groups = tryParseWithPatterns(dateString, patterns, includeTime);
332
+ if (!groups) {
333
+ // Check if input looks like a complete date (has separators and multiple parts)
334
+ // If so, use fallback parsing for formats like "2022/08/17", "2022-08-17"
335
+ // If not (like "1", "12"), return null
336
+ const trimmed = dateString.trim();
337
+ const hasDateSeparators = /[-/.:]/.test(trimmed);
338
+ const parts = trimmed.split(/[-/.\s:]+/).filter((part) => part.length > 0);
339
+ const hasMultipleParts = parts.length >= 2;
340
+ if (hasDateSeparators && hasMultipleParts) {
341
+ // Use fallback for complete date strings that don't match locale patterns
342
+ return parseLocalDateString(dateString);
343
+ }
344
+ // For incomplete input like "1" or "12", return null
345
+ return null;
346
+ }
347
+ // For day selection, require at least month and day to be present
348
+ if ('month' in groups && 'day' in groups) {
349
+ const { month, day } = groups;
350
+ if (!validateDateComponents(month, day)) {
351
+ return null;
352
+ }
353
+ }
354
+ else {
355
+ // If incomplete date information, return null instead of guessing
356
+ return null;
357
+ }
358
+ // Create and return appropriate date object
359
+ return includeTime
360
+ ? createDateWithTime(groups)
361
+ : createDateOnly(groups);
362
+ };
363
+ /**
364
+ * Parses a date string into a local Date object.
365
+ * @param dateString - The date string to parse.
366
+ * @returns The Date object in local timezone, or null if invalid.
367
+ */
368
+ const parseLocalDateString = (dateString) => {
369
+ const _date = new Date(Date.parse(dateString));
370
+ if (!Number.isNaN(_date.getTime())) {
371
+ return _date;
372
+ }
373
+ return null;
11
374
  };
12
375
  /**
13
376
  * Converts a date string or Date object to a Date object based on selection type.
14
377
  * @param date - The date to convert.
15
378
  * @param selectionType - The type of selection ('day', 'week', 'month', 'year').
379
+ * @param locale - The locale to use for date parsing (for day parsing).
380
+ * @param includeTime - Whether to include time parsing (for day parsing).
16
381
  * @returns The corresponding Date object or null if invalid.
17
382
  */
18
- const convertToDateObject = (date, selectionType) => {
383
+ const convertToDateObject = (date, selectionType, locale = 'en-US', includeTime = false) => {
384
+ if (date === null) {
385
+ return null;
386
+ }
19
387
  if (date instanceof Date) {
20
- return date;
388
+ return Number.isNaN(date.getTime()) ? null : date;
21
389
  }
22
- if (selectionType === 'week') {
23
- return convertIsoWeekToDate(date);
390
+ const dateString = date;
391
+ switch (selectionType) {
392
+ case 'week': {
393
+ return parseWeekString(dateString);
394
+ }
395
+ case 'month': {
396
+ return parseMonthString(dateString);
397
+ }
398
+ case 'year': {
399
+ return parseYearString(dateString);
400
+ }
401
+ default: {
402
+ // Enhanced day parsing with locale support
403
+ return parseDayString(dateString, locale, includeTime);
404
+ }
24
405
  }
25
- if (selectionType === 'month' || selectionType === 'year') {
26
- const _date = new Date(Date.parse(date));
27
- const userTimezoneOffset = _date.getTimezoneOffset() * 60_000;
28
- return new Date(_date.getTime() + userTimezoneOffset);
406
+ };
407
+ /**
408
+ * Enhanced locale-aware date parsing function (replaces getLocalDateFromString).
409
+ * @param dateString - The date string to parse.
410
+ * @param locale - The locale to use for date format patterns.
411
+ * @param includeTime - Whether to include time parsing.
412
+ * @param selectionType - The selection type ('day', 'week', 'month', 'year').
413
+ * @returns A Date object if parsing succeeds, null if parsing fails.
414
+ */
415
+ const getLocalDateFromString = (dateString, locale = 'en-US', includeTime = false, selectionType = 'day') => {
416
+ // Input validation
417
+ if (!dateString || typeof dateString !== 'string') {
418
+ return null;
29
419
  }
30
- return new Date(Date.parse(date));
420
+ return convertToDateObject(dateString, selectionType, locale, includeTime);
31
421
  };
32
422
  /**
33
423
  * Creates groups from an array.
@@ -56,7 +446,8 @@ const getCalendarDate = (calendarDate, order, view) => {
56
446
  return new Date(calendarDate.getFullYear() + order, calendarDate.getMonth(), 1);
57
447
  }
58
448
  if (order !== 0 && view === 'years') {
59
- return new Date(calendarDate.getFullYear() + 12 * order, calendarDate.getMonth(), 1);
449
+ // prettier-ignore
450
+ return new Date(calendarDate.getFullYear() + (12 * order), calendarDate.getMonth(), 1);
60
451
  }
61
452
  return calendarDate;
62
453
  };
@@ -195,7 +586,7 @@ const getISOWeekNumberAndYear = (date) => {
195
586
  tempDate.setDate(tempDate.getDate() + 3 - ((tempDate.getDay() + 6) % 7));
196
587
  const week1 = new Date(tempDate.getFullYear(), 0, 4);
197
588
  // Calculate full weeks to the date
198
- const weekNumber = 1 + Math.round((tempDate.getTime() - week1.getTime()) / 86_400_000 / 7);
589
+ const weekNumber = 1 + Math.round((tempDate.getTime() - week1.getTime()) / (86_400_000 * 7));
199
590
  return { weekNumber, year: tempDate.getFullYear() };
200
591
  };
201
592
  /**
@@ -220,9 +611,15 @@ const getMonthDetails = (year, month, firstDayOfWeek) => {
220
611
  }
221
612
  if ((index + 1) % 7 === 0) {
222
613
  const { weekNumber, year } = getISOWeekNumberAndYear(day.date);
223
- weeks[weeks.length - 1].week = { number: weekNumber, year };
614
+ const lastWeek = weeks.at(-1);
615
+ if (lastWeek) {
616
+ lastWeek.week = { number: weekNumber, year };
617
+ }
618
+ }
619
+ const lastWeek = weeks.at(-1);
620
+ if (lastWeek) {
621
+ lastWeek.days.push(day);
224
622
  }
225
- weeks[weeks.length - 1].days.push(day);
226
623
  });
227
624
  return weeks;
228
625
  };
@@ -276,7 +673,7 @@ const isDateInRange = (date, start, end) => {
276
673
  const _date = removeTimeFromDate(date);
277
674
  const _start = start ? removeTimeFromDate(start) : null;
278
675
  const _end = end ? removeTimeFromDate(end) : null;
279
- return !!(_start && _end && _start <= _date && _date <= _end);
676
+ return Boolean(_start && _end && _start <= _date && _date <= _end);
280
677
  };
281
678
  /**
282
679
  * Checks if a date is selected based on start and end dates.
@@ -325,23 +722,20 @@ const isDisableDateInRange = (startDate, endDate, disabledDates) => {
325
722
  * @returns True if the month is disabled, false otherwise.
326
723
  */
327
724
  const isMonthDisabled = (date, min, max, disabledDates) => {
328
- const current = date.getFullYear() * 12 + date.getMonth();
329
- const _min = min ? min.getFullYear() * 12 + min.getMonth() : null;
330
- const _max = max ? max.getFullYear() * 12 + max.getMonth() : null;
331
- if (_min && current < _min) {
332
- return true;
333
- }
334
- if (_max && current > _max) {
725
+ const current = dateToMonthNumber(date);
726
+ const _min = min ? dateToMonthNumber(min) : null;
727
+ const _max = max ? dateToMonthNumber(max) : null;
728
+ if (isOutsideRange(current, _min, _max)) {
335
729
  return true;
336
730
  }
337
731
  if (disabledDates === undefined) {
338
732
  return false;
339
733
  }
340
- const start = min ? Math.max(date.getTime(), min.getTime()) : date;
341
- const end = max
734
+ const startTime = min ? Math.max(date.getTime(), min.getTime()) : date.getTime();
735
+ const endTime = max
342
736
  ? Math.min(date.getTime(), max.getTime())
343
- : new Date(new Date().getFullYear(), 11, 31);
344
- for (const currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
737
+ : new Date(new Date().getFullYear(), 11, 31).getTime();
738
+ for (const currentDate = new Date(startTime); currentDate.getTime() <= endTime; currentDate.setDate(currentDate.getDate() + 1)) {
345
739
  if (!isDateDisabled(currentDate, min, max, disabledDates)) {
346
740
  return false;
347
741
  }
@@ -374,12 +768,10 @@ const isMonthSelected = (date, start, end) => {
374
768
  * @returns True if the month is within the range, false otherwise.
375
769
  */
376
770
  const isMonthInRange = (date, start, end) => {
377
- const year = date.getFullYear();
378
- const month = date.getMonth();
379
- const _start = start ? start.getFullYear() * 12 + start.getMonth() : null;
380
- const _end = end ? end.getFullYear() * 12 + end.getMonth() : null;
381
- const _date = year * 12 + month;
382
- return !!(_start && _end && _start <= _date && _date <= _end);
771
+ const _start = start ? dateToMonthNumber(start) : null;
772
+ const _end = end ? dateToMonthNumber(end) : null;
773
+ const _date = dateToMonthNumber(date);
774
+ return Boolean(_start && _end && _start <= _date && _date <= _end);
383
775
  };
384
776
  /**
385
777
  * Checks if two dates are the same calendar date.
@@ -419,20 +811,17 @@ const isYearDisabled = (date, min, max, disabledDates) => {
419
811
  const year = date.getFullYear();
420
812
  const minYear = min ? min.getFullYear() : null;
421
813
  const maxYear = max ? max.getFullYear() : null;
422
- if (minYear && year < minYear) {
423
- return true;
424
- }
425
- if (maxYear && year > maxYear) {
814
+ if (isOutsideRange(year, minYear, maxYear)) {
426
815
  return true;
427
816
  }
428
817
  if (disabledDates === undefined) {
429
818
  return false;
430
819
  }
431
- const start = min ? Math.max(date.getTime(), min.getTime()) : date;
432
- const end = max
820
+ const startTime = min ? Math.max(date.getTime(), min.getTime()) : date.getTime();
821
+ const endTime = max
433
822
  ? Math.min(date.getTime(), max.getTime())
434
- : new Date(new Date().getFullYear(), 11, 31);
435
- for (const currentDate = new Date(start); currentDate <= end; currentDate.setDate(currentDate.getDate() + 1)) {
823
+ : new Date(new Date().getFullYear(), 11, 31).getTime();
824
+ for (const currentDate = new Date(startTime); currentDate.getTime() <= endTime; currentDate.setDate(currentDate.getDate() + 1)) {
436
825
  if (!isDateDisabled(currentDate, min, max, disabledDates)) {
437
826
  return false;
438
827
  }
@@ -467,7 +856,7 @@ const isYearInRange = (date, start, end) => {
467
856
  const year = date.getFullYear();
468
857
  const _start = start ? start.getFullYear() : null;
469
858
  const _end = end ? end.getFullYear() : null;
470
- return !!(_start && _end && _start <= year && year <= _end);
859
+ return Boolean(_start && _end && _start <= year && year <= _end);
471
860
  };
472
861
  /**
473
862
  * Removes the time component from a Date object.
@@ -497,6 +886,37 @@ const setTimeFromDate = (target, source) => {
497
886
  result.setHours(source.getHours(), source.getMinutes(), source.getSeconds(), source.getMilliseconds());
498
887
  return result;
499
888
  };
889
+ /**
890
+ * Parses a year string with smart 2-digit handling.
891
+ * @param yearString - The year string to parse.
892
+ * @returns The parsed year as a number with intelligent century assignment.
893
+ */
894
+ const parseYearSmart = (yearString) => {
895
+ let parsedYear = Number.parseInt(yearString, 10);
896
+ // Handle 2-digit years with intelligent century assignment
897
+ if (parsedYear < 100) {
898
+ const currentYear = new Date().getFullYear();
899
+ const currentCentury = Math.floor(currentYear / 100) * 100;
900
+ parsedYear = currentCentury + parsedYear;
901
+ // If the result is more than 50 years in the future, use previous century
902
+ // This creates a sliding window: for current year 2025, years 76-99 become 1976-1999
903
+ // and years 00-75 become 2000-2075
904
+ if (parsedYear > currentYear + 50) {
905
+ parsedYear -= 100;
906
+ }
907
+ }
908
+ return parsedYear;
909
+ };
910
+ /**
911
+ * Creates a date from year groups.
912
+ * @param groups - The year groups containing year string.
913
+ * @returns A Date object for January 1st of the year.
914
+ */
915
+ const createDateFromYear = (groups) => {
916
+ const { year } = groups;
917
+ const parsedYear = parseYearSmart(year);
918
+ return new Date(parsedYear, 0, 1);
919
+ };
500
920
 
501
- export { convertIsoWeekToDate, convertToDateObject, createGroupsInArray, getCalendarDate, getDateBySelectionType, getISOWeekNumberAndYear, getMonthDetails, getMonthsNames, getSelectableDates, getYears, isDateDisabled, isDateInRange, isDateSelected, isDisableDateInRange, isMonthDisabled, isMonthInRange, isMonthSelected, isSameDateAs, isToday, isYearDisabled, isYearInRange, isYearSelected, removeTimeFromDate, setTimeFromDate };
921
+ export { convertIsoWeekToDate, convertToDateObject, createDateFromYear, createGroupsInArray, getCalendarDate, getDateBySelectionType, getISOWeekNumberAndYear, getLocalDateFromString, getMonthDetails, getMonthsNames, getSelectableDates, getYears, isDateDisabled, isDateInRange, isDateSelected, isDisableDateInRange, isMonthDisabled, isMonthInRange, isMonthSelected, isSameDateAs, isToday, isYearDisabled, isYearInRange, isYearSelected, parseYearSmart, removeTimeFromDate, setTimeFromDate };
502
922
  //# sourceMappingURL=utils.js.map