@mk-kit/ui 0.48.0 → 0.49.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.
@@ -1,3 +1,5 @@
1
+ import { startOfMonth, formatDate, buildMonthMatrix, getWeekdayFullName, isSameDay, startOfDay, clampDate, isSameMonth, isBefore, isAfter, addMonths, addDays, parseISODate, endOfMonth, getISOWeek, endOfWeek, startOfWeek } from '@mk-kit/core';
2
+ export { addDays, addMonths, buildMonthMatrix, clampDate, endOfMonth, endOfWeek, formatDate, formatISODate, getISOWeek, getMonthNames, getWeekdayFullName, getWeekdayNames, isAfter, isBefore, isSameDay, isSameMonth, parseISODate, startOfDay, startOfMonth, startOfWeek } from '@mk-kit/core';
1
3
  import * as i0 from '@angular/core';
2
4
  import { inject, ElementRef, Injector, model, input, numberAttribute, booleanAttribute, output, signal, computed, effect, untracked, afterNextRender, forwardRef, ChangeDetectionStrategy, Component, viewChild, viewChildren } from '@angular/core';
3
5
  import { NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
@@ -5,252 +7,7 @@ import { MK_I18N, MkLiveAnnouncer, mkUniqueId, mkInjectFieldTouched, mkValidator
5
7
  import { MkFormField } from '@mk-kit/ui/forms';
6
8
  import { DOCUMENT } from '@angular/common';
7
9
 
8
- /** English full month names, January (index 0) December (index 11). */
9
- const MONTH_NAMES = [
10
- 'January',
11
- 'February',
12
- 'March',
13
- 'April',
14
- 'May',
15
- 'June',
16
- 'July',
17
- 'August',
18
- 'September',
19
- 'October',
20
- 'November',
21
- 'December',
22
- ];
23
- /** English abbreviated month names (`MMM`). */
24
- const MONTH_NAMES_SHORT = [
25
- 'Jan',
26
- 'Feb',
27
- 'Mar',
28
- 'Apr',
29
- 'May',
30
- 'Jun',
31
- 'Jul',
32
- 'Aug',
33
- 'Sep',
34
- 'Oct',
35
- 'Nov',
36
- 'Dec',
37
- ];
38
- /** English full weekday names, Sunday (index 0) → Saturday (index 6). */
39
- const WEEKDAY_NAMES = [
40
- 'Sunday',
41
- 'Monday',
42
- 'Tuesday',
43
- 'Wednesday',
44
- 'Thursday',
45
- 'Friday',
46
- 'Saturday',
47
- ];
48
- /** English abbreviated weekday names (`ddd`). */
49
- const WEEKDAY_NAMES_SHORT = [
50
- 'Sun',
51
- 'Mon',
52
- 'Tue',
53
- 'Wed',
54
- 'Thu',
55
- 'Fri',
56
- 'Sat',
57
- ];
58
- /** English single-letter weekday names (narrow). */
59
- const WEEKDAY_NAMES_NARROW = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
60
- function pad2$2(n) {
61
- return n < 10 ? `0${n}` : `${n}`;
62
- }
63
- /** True when both dates fall on the same calendar day (local time). */
64
- function isSameDay(a, b) {
65
- return (a.getFullYear() === b.getFullYear() &&
66
- a.getMonth() === b.getMonth() &&
67
- a.getDate() === b.getDate());
68
- }
69
- /** True when both dates fall in the same calendar month of the same year. */
70
- function isSameMonth(a, b) {
71
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
72
- }
73
- /** Midnight (00:00:00.000) on the first day of `date`'s month. */
74
- function startOfMonth(date) {
75
- return new Date(date.getFullYear(), date.getMonth(), 1);
76
- }
77
- /** Midnight on the last day of `date`'s month. */
78
- function endOfMonth(date) {
79
- return new Date(date.getFullYear(), date.getMonth() + 1, 0);
80
- }
81
- /** A new date `count` months after `date` (negative to subtract). Clamps the
82
- * day of month so e.g. Jan 31 + 1 month = Feb 28/29, not Mar 3. */
83
- function addMonths(date, count) {
84
- const targetMonth = date.getMonth() + count;
85
- const result = new Date(date.getFullYear(), targetMonth, 1, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
86
- const lastDay = new Date(result.getFullYear(), result.getMonth() + 1, 0).getDate();
87
- result.setDate(Math.min(date.getDate(), lastDay));
88
- return result;
89
- }
90
- /** A new date `count` days after `date` (negative to subtract). */
91
- function addDays(date, count) {
92
- const result = new Date(date);
93
- result.setDate(result.getDate() + count);
94
- return result;
95
- }
96
- /** Midnight (00:00:00.000) on `date`'s calendar day. */
97
- function startOfDay(date) {
98
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
99
- }
100
- /**
101
- * The first day of the week containing `date`, at midnight. `firstDayOfWeek`
102
- * is the week's starting weekday (0 = Sunday … 6 = Saturday).
103
- */
104
- function startOfWeek(date, firstDayOfWeek = 0) {
105
- const start = startOfDay(date);
106
- const diff = (start.getDay() - firstDayOfWeek + 7) % 7;
107
- return addDays(start, -diff);
108
- }
109
- /** The last day of the week containing `date`, at midnight. */
110
- function endOfWeek(date, firstDayOfWeek = 0) {
111
- return addDays(startOfWeek(date, firstDayOfWeek), 6);
112
- }
113
- /**
114
- * ISO-8601 week number (1–53) of `date`. Weeks start on Monday and week 1 is
115
- * the week containing the first Thursday of the year.
116
- */
117
- function getISOWeek(date) {
118
- // Shift to the Thursday of this ISO week, then count weeks from Jan 1.
119
- const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
120
- const day = (d.getDay() + 6) % 7; // Monday = 0 … Sunday = 6
121
- d.setDate(d.getDate() - day + 3);
122
- const firstThursday = new Date(d.getFullYear(), 0, 4);
123
- const firstDay = (firstThursday.getDay() + 6) % 7;
124
- firstThursday.setDate(firstThursday.getDate() - firstDay + 3);
125
- return (1 + Math.round((d.getTime() - firstThursday.getTime()) / (7 * 86400000)));
126
- }
127
- /** True when `a` is strictly before `b` (full timestamp comparison). */
128
- function isBefore(a, b) {
129
- return a.getTime() < b.getTime();
130
- }
131
- /** True when `a` is strictly after `b` (full timestamp comparison). */
132
- function isAfter(a, b) {
133
- return a.getTime() > b.getTime();
134
- }
135
- /** Clamp `date` into the inclusive `[min, max]` range (either bound optional). */
136
- function clampDate(date, min, max) {
137
- if (min && isBefore(date, min))
138
- return new Date(min);
139
- if (max && isAfter(date, max))
140
- return new Date(max);
141
- return date;
142
- }
143
- /** Format `date` as an ISO calendar date `YYYY-MM-DD` (local time). */
144
- function formatISODate(date) {
145
- return `${date.getFullYear().toString().padStart(4, '0')}-${pad2$2(date.getMonth() + 1)}-${pad2$2(date.getDate())}`;
146
- }
147
- /** Parse a `YYYY-MM-DD` string into a local-time `Date`, or `null` if invalid. */
148
- function parseISODate(value) {
149
- if (!value)
150
- return null;
151
- const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
152
- if (!match)
153
- return null;
154
- const year = Number(match[1]);
155
- const month = Number(match[2]) - 1;
156
- const day = Number(match[3]);
157
- const date = new Date(year, month, day);
158
- // Reject rollovers like 2024-02-31.
159
- if (date.getFullYear() !== year ||
160
- date.getMonth() !== month ||
161
- date.getDate() !== day) {
162
- return null;
163
- }
164
- return date;
165
- }
166
- /**
167
- * Format `date` using a small pattern set. Supported tokens:
168
- * `yyyy` (4-digit year), `MMMM` (full month), `MMM` (short month),
169
- * `MM` (2-digit month), `dd` (2-digit day), `d` (day), `ddd` (short weekday),
170
- * `HH` / `H` (24-hour, padded / bare), `hh` / `h` (12-hour, padded / bare),
171
- * `mm` (2-digit minutes) and `a` (`AM` / `PM`). Longer tokens are matched
172
- * first so `MMMM` wins over `MM`. Month/weekday names come from `names` when
173
- * given, else English.
174
- */
175
- function formatDate(date, pattern, names) {
176
- const tokens = [
177
- ['yyyy', () => date.getFullYear().toString().padStart(4, '0')],
178
- ['MMMM', () => (names?.months ?? MONTH_NAMES)[date.getMonth()]],
179
- ['MMM', () => (names?.monthsShort ?? MONTH_NAMES_SHORT)[date.getMonth()]],
180
- ['MM', () => pad2$2(date.getMonth() + 1)],
181
- // Longest-first: 'ddd' (short weekday) must be matched before 'dd'/'d',
182
- // otherwise 'ddd' is consumed as 'dd' + 'd' and produces day numbers.
183
- ['ddd', () => (names?.weekdaysShort ?? WEEKDAY_NAMES_SHORT)[date.getDay()]],
184
- ['dd', () => pad2$2(date.getDate())],
185
- ['d', () => date.getDate().toString()],
186
- ['HH', () => pad2$2(date.getHours())],
187
- ['H', () => date.getHours().toString()],
188
- ['hh', () => pad2$2(date.getHours() % 12 || 12)],
189
- ['h', () => (date.getHours() % 12 || 12).toString()],
190
- ['mm', () => pad2$2(date.getMinutes())],
191
- ['a', () => (date.getHours() < 12 ? 'AM' : 'PM')],
192
- ];
193
- let result = '';
194
- let i = 0;
195
- outer: while (i < pattern.length) {
196
- for (const [token, resolve] of tokens) {
197
- if (pattern.startsWith(token, i)) {
198
- result += resolve();
199
- i += token.length;
200
- continue outer;
201
- }
202
- }
203
- result += pattern[i];
204
- i += 1;
205
- }
206
- return result;
207
- }
208
- /**
209
- * Build a fixed 6×7 matrix of `Date` cells for `viewDate`'s month, including
210
- * the leading days from the previous month and trailing days from the next so
211
- * every row is full. `firstDayOfWeek` is 0 (Sunday) … 6 (Saturday).
212
- */
213
- function buildMonthMatrix(viewDate, firstDayOfWeek = 0) {
214
- const first = startOfMonth(viewDate);
215
- const firstDow = first.getDay();
216
- const offset = (firstDow - firstDayOfWeek + 7) % 7;
217
- const gridStart = addDays(first, -offset);
218
- const weeks = [];
219
- let cursor = gridStart;
220
- for (let week = 0; week < 6; week++) {
221
- const row = [];
222
- for (let day = 0; day < 7; day++) {
223
- row.push(cursor);
224
- cursor = addDays(cursor, 1);
225
- }
226
- weeks.push(row);
227
- }
228
- return weeks;
229
- }
230
- /** Full month names, index 0 = January (from `names`, else English). */
231
- function getMonthNames(names) {
232
- return names?.months ?? MONTH_NAMES;
233
- }
234
- /**
235
- * Weekday header labels ordered to start at `firstDayOfWeek`.
236
- * `format` selects `'short'` (e.g. `Mon`) or `'narrow'` (e.g. `M`).
237
- * Labels come from `names` when given, else English.
238
- */
239
- function getWeekdayNames(firstDayOfWeek = 0, format = 'short', names) {
240
- const source = format === 'narrow'
241
- ? (names?.weekdaysNarrow ?? WEEKDAY_NAMES_NARROW)
242
- : (names?.weekdaysShort ?? WEEKDAY_NAMES_SHORT);
243
- const start = ((firstDayOfWeek % 7) + 7) % 7;
244
- const labels = [];
245
- for (let i = 0; i < 7; i++) {
246
- labels.push(source[(start + i) % 7]);
247
- }
248
- return labels;
249
- }
250
- /** Full weekday name for `date` (for screen-reader labels). */
251
- function getWeekdayFullName(date, names) {
252
- return (names?.weekdays ?? WEEKDAY_NAMES)[date.getDay()];
253
- }
10
+ /** Delegates to `@mk-kit/core` the exported names are unchanged. */
254
11
 
255
12
  /**
256
13
  * Calendar — an accessible month-grid date picker following the WAI-ARIA
@@ -3996,5 +3753,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
3996
3753
  * Generated bundle index. Do not edit.
3997
3754
  */
3998
3755
 
3999
- export { MkCalendar, MkDatePicker, MkDateRangePicker, MkDateTimePicker, MkEventCalendar, MkMiniDate, MkMonthPicker, MkTimePicker, MkWeekPicker, addDays, addMonths, buildMonthMatrix, clampDate, endOfMonth, endOfWeek, formatDate, formatISODate, getISOWeek, getMonthNames, getWeekdayFullName, getWeekdayNames, isAfter, isBefore, isSameDay, isSameMonth, parseISODate, startOfDay, startOfMonth, startOfWeek };
3756
+ export { MkCalendar, MkDatePicker, MkDateRangePicker, MkDateTimePicker, MkEventCalendar, MkMiniDate, MkMonthPicker, MkTimePicker, MkWeekPicker };
4000
3757
  //# sourceMappingURL=mk-kit-ui-datetime.mjs.map