@reliability-design/web 1.4.5 → 1.4.6

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 (42) hide show
  1. package/dist/components/rel-alert/rel-alert.ts +1 -1
  2. package/dist/components/rel-autocomplete/rel-autocomplete.ts +33 -2
  3. package/dist/components/rel-badge/rel-badge.ts +6 -1
  4. package/dist/components/rel-calendar/rel-calendar.ts +64 -18
  5. package/dist/components/rel-carousel/rel-carousel.ts +25 -2
  6. package/dist/components/rel-chip/rel-chip.ts +31 -20
  7. package/dist/components/rel-date-picker/date-parse.test.ts +116 -0
  8. package/dist/components/rel-date-picker/date-parse.ts +178 -0
  9. package/dist/components/rel-date-picker/rel-date-picker.ts +529 -90
  10. package/dist/components/rel-drawer/rel-drawer.ts +6 -3
  11. package/dist/components/rel-menu/rel-menu.ts +6 -0
  12. package/dist/components/rel-otp/rel-otp.ts +12 -2
  13. package/dist/components/rel-pagination/rel-pagination.ts +13 -0
  14. package/dist/components/rel-popover/rel-popover.ts +33 -2
  15. package/dist/components/rel-progress/rel-progress.ts +13 -4
  16. package/dist/components/rel-radio/README.md +6 -3
  17. package/dist/components/rel-radio/rel-radio.ts +236 -60
  18. package/dist/components/rel-range-picker/rel-range-picker.ts +452 -95
  19. package/dist/components/rel-segmented-button/rel-segmented-button.ts +5 -1
  20. package/dist/components/rel-select/rel-select.ts +44 -13
  21. package/dist/components/rel-sheet/rel-sheet.ts +163 -18
  22. package/dist/components/rel-sidebar/rel-sidebar.ts +7 -1
  23. package/dist/components/rel-skeleton/rel-skeleton.ts +9 -0
  24. package/dist/components/rel-slider/rel-slider.ts +6 -3
  25. package/dist/components/rel-snackbar/rel-snackbar.ts +20 -16
  26. package/dist/components/rel-stepper/rel-stepper.ts +3 -1
  27. package/dist/components/rel-switch/rel-switch.ts +3 -1
  28. package/dist/components/rel-textfield/rel-textfield.ts +263 -75
  29. package/dist/components/rel-time-picker/rel-time-picker.ts +450 -94
  30. package/dist/components/rel-time-picker/time-parse.test.ts +67 -0
  31. package/dist/components/rel-time-picker/time-parse.ts +85 -0
  32. package/dist/components/rel-toast/rel-toast.ts +4 -2
  33. package/dist/components/rel-tooltip/README.md +13 -5
  34. package/dist/components/rel-tooltip/rel-tooltip.ts +3 -0
  35. package/dist/components/rel-upload/rel-upload.ts +25 -0
  36. package/dist/index.d.mts +241 -11
  37. package/dist/index.d.ts +241 -11
  38. package/dist/index.js +2573 -598
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +2614 -640
  41. package/dist/index.mjs.map +1 -1
  42. package/package.json +2 -2
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Free-form date parsing for rel-date-picker's typed keyboard entry.
3
+ *
4
+ * Pure (Date + Intl only, no DOM, no Date.now — "today" comes in via
5
+ * `referenceDate`) so it is unit-testable in Node. The component owns range
6
+ * checks (minDate/maxDate); this module only turns text into a calendar day.
7
+ *
8
+ * Shortcuts (case/whitespace-insensitive):
9
+ * "t", "today" → referenceDate
10
+ * "t+7", "t7", "t +7" → referenceDate + 7 days
11
+ * "t-3" → referenceDate − 3 days
12
+ *
13
+ * Date entry — parts split on `/ - . ,` or spaces, then classified:
14
+ * "2026-07-21", "21/7/2026", "7/21/26", "21 Jul 2026", "July 21, 2026",
15
+ * "21/7" (reference year), "21" (reference month), "20260721" (ISO digits).
16
+ * Two-digit years map to 20YY. When day/month order is ambiguous (both ≤ 12),
17
+ * `dayFirst` decides — derive it from the display format or locale via
18
+ * `isDayFirstPattern` / `isDayFirstLocale`.
19
+ */
20
+
21
+ export interface ParseDateOptions {
22
+ /** "Today" and the fallback year/month for partial input. */
23
+ referenceDate: Date;
24
+ /** Ambiguous "a/b" order: true → day/month (EU), false → month/day (US). */
25
+ dayFirst?: boolean;
26
+ /** Locale for month-name matching (default "en-US"). */
27
+ locale?: string;
28
+ }
29
+
30
+ /** Day-before-month order of a display pattern, e.g. "DD/MM/YYYY" → true. */
31
+ export function isDayFirstPattern(pattern: string): boolean | null {
32
+ // Strip bracketed literals so "[Due] DD/MM" doesn't match the literal's letters.
33
+ const bare = pattern.replace(/\[[^\]]*\]/g, "");
34
+ const d = bare.search(/D/);
35
+ const m = bare.search(/M/);
36
+ if (d === -1 || m === -1) return null;
37
+ return d < m;
38
+ }
39
+
40
+ /** Day-before-month order of a locale's default numeric date format. */
41
+ export function isDayFirstLocale(locale: string): boolean {
42
+ try {
43
+ const parts = new Intl.DateTimeFormat(locale).formatToParts(
44
+ new Date(2020, 0, 15)
45
+ );
46
+ const d = parts.findIndex((p) => p.type === "day");
47
+ const m = parts.findIndex((p) => p.type === "month");
48
+ return d !== -1 && m !== -1 && d < m;
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ /** 0-based month index for a month name in the locale (long/short), or null. */
55
+ function matchMonthName(token: string, locale: string): number | null {
56
+ const cleaned = token.replace(/\.$/, "").toLowerCase();
57
+ if (!cleaned || /\d/.test(cleaned)) return null;
58
+ for (const style of ["long", "short"] as const) {
59
+ const fmt = new Intl.DateTimeFormat(locale, { month: style });
60
+ for (let m = 0; m < 12; m++) {
61
+ if (fmt.format(new Date(2020, m, 15)).toLowerCase() === cleaned) return m;
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+
67
+ /** Reject impossible days (Feb 30 …) by round-tripping through Date. */
68
+ function buildDate(year: number, monthIndex: number, day: number): Date | null {
69
+ if (monthIndex < 0 || monthIndex > 11 || day < 1 || day > 31) return null;
70
+ const date = new Date(year, monthIndex, day, 12, 0, 0);
71
+ if (date.getFullYear() !== year || date.getMonth() !== monthIndex || date.getDate() !== day) {
72
+ return null;
73
+ }
74
+ return date;
75
+ }
76
+
77
+ function normalizeYear(raw: string): number {
78
+ const n = parseInt(raw, 10);
79
+ return raw.length <= 2 ? 2000 + n : n;
80
+ }
81
+
82
+ export function parseDateInput(
83
+ text: string,
84
+ opts: ParseDateOptions
85
+ ): Date | null {
86
+ const input = text.trim();
87
+ if (!input) return null;
88
+ const locale = opts.locale ?? "en-US";
89
+ const ref = opts.referenceDate;
90
+
91
+ // ── Shortcuts: t / today / t±N ──
92
+ const shortcut = input.match(/^t(?:oday)?\s*(?:([+-])\s*)?(\d+)?$/i);
93
+ if (shortcut) {
94
+ const sign = shortcut[1] === "-" ? -1 : 1;
95
+ const offset = shortcut[2] ? sign * parseInt(shortcut[2], 10) : 0;
96
+ // "t-" / "t+" with no number is incomplete, not "today".
97
+ if (shortcut[1] && !shortcut[2]) return null;
98
+ return new Date(ref.getFullYear(), ref.getMonth(), ref.getDate() + offset, 12, 0, 0);
99
+ }
100
+
101
+ // ── Single run of digits: "21" (day), "0721"?, "20260721" (ISO) ──
102
+ if (/^\d+$/.test(input)) {
103
+ if (input.length <= 2) {
104
+ return buildDate(ref.getFullYear(), ref.getMonth(), parseInt(input, 10));
105
+ }
106
+ if (input.length === 8) {
107
+ return buildDate(
108
+ parseInt(input.slice(0, 4), 10),
109
+ parseInt(input.slice(4, 6), 10) - 1,
110
+ parseInt(input.slice(6), 10)
111
+ );
112
+ }
113
+ return null;
114
+ }
115
+
116
+ // ── Tokenized parts ──
117
+ const parts = input.split(/[\s/\-.,]+/).filter(Boolean);
118
+ if (parts.length < 2 || parts.length > 3) return null;
119
+
120
+ const dayFirst = opts.dayFirst ?? false;
121
+
122
+ // Classify each part: 4-digit year, month name, or plain number.
123
+ const yearIdx = parts.findIndex((p) => /^\d{4}$/.test(p));
124
+ const monthNameIdx = parts.findIndex((p) => matchMonthName(p, locale) !== null);
125
+
126
+ if (parts.length === 3) {
127
+ if (!parts.every((p, i) => i === monthNameIdx || /^\d{1,4}$/.test(p))) return null;
128
+ // ISO-style: 4-digit year leads → Y-M-D regardless of dayFirst.
129
+ if (yearIdx === 0 && monthNameIdx === -1) {
130
+ return buildDate(
131
+ parseInt(parts[0], 10),
132
+ parseInt(parts[1], 10) - 1,
133
+ parseInt(parts[2], 10)
134
+ );
135
+ }
136
+ // Year (2- or 4-digit) is last otherwise.
137
+ const yearRaw = parts[2];
138
+ if (!/^\d{1,4}$/.test(yearRaw) || monthNameIdx === 2) return null;
139
+ const year = normalizeYear(yearRaw);
140
+ let monthIndex: number;
141
+ let day: number;
142
+ if (monthNameIdx !== -1) {
143
+ monthIndex = matchMonthName(parts[monthNameIdx], locale)!;
144
+ const dayRaw = parts[monthNameIdx === 0 ? 1 : 0];
145
+ if (!/^\d{1,2}$/.test(dayRaw)) return null;
146
+ day = parseInt(dayRaw, 10);
147
+ } else {
148
+ if (!/^\d{1,2}$/.test(parts[0]) || !/^\d{1,2}$/.test(parts[1])) return null;
149
+ const a = parseInt(parts[0], 10);
150
+ const b = parseInt(parts[1], 10);
151
+ // A part that can't be a month forces the order; otherwise dayFirst decides.
152
+ if (a > 12 && b > 12) return null;
153
+ const useDayFirst = a > 12 ? true : b > 12 ? false : dayFirst;
154
+ day = useDayFirst ? a : b;
155
+ monthIndex = (useDayFirst ? b : a) - 1;
156
+ }
157
+ return buildDate(year, monthIndex, day);
158
+ }
159
+
160
+ // Two parts: day + month in the reference year ("21/7", "21 Jul", "Jul 21").
161
+ let monthIndex: number;
162
+ let day: number;
163
+ if (monthNameIdx !== -1) {
164
+ monthIndex = matchMonthName(parts[monthNameIdx], locale)!;
165
+ const dayRaw = parts[monthNameIdx === 0 ? 1 : 0];
166
+ if (!/^\d{1,2}$/.test(dayRaw)) return null;
167
+ day = parseInt(dayRaw, 10);
168
+ } else {
169
+ if (!/^\d{1,2}$/.test(parts[0]) || !/^\d{1,2}$/.test(parts[1])) return null;
170
+ const a = parseInt(parts[0], 10);
171
+ const b = parseInt(parts[1], 10);
172
+ if (a > 12 && b > 12) return null;
173
+ const useDayFirst = a > 12 ? true : b > 12 ? false : dayFirst;
174
+ day = useDayFirst ? a : b;
175
+ monthIndex = (useDayFirst ? b : a) - 1;
176
+ }
177
+ return buildDate(ref.getFullYear(), monthIndex, day);
178
+ }