@commmerce/ui 1.0.0-rc.4 → 1.0.0-rc.5

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 (101) hide show
  1. package/README.md +1 -1
  2. package/dist/base.d.ts +5 -0
  3. package/dist/base.js +10 -0
  4. package/dist/calendar.d.ts +95 -0
  5. package/dist/calendar.js +280 -0
  6. package/dist/cdn.js +721 -477
  7. package/dist/components/accordion.js +2 -2
  8. package/dist/components/action-bar.d.ts +12 -2
  9. package/dist/components/action-bar.js +10 -5
  10. package/dist/components/action-menu.d.ts +17 -4
  11. package/dist/components/action-menu.js +8 -5
  12. package/dist/components/app-card.d.ts +24 -2
  13. package/dist/components/app-card.js +25 -10
  14. package/dist/components/banner.d.ts +2 -2
  15. package/dist/components/banner.js +4 -3
  16. package/dist/components/bottom-navigation.d.ts +16 -4
  17. package/dist/components/bottom-navigation.js +10 -7
  18. package/dist/components/bottom-sheet.d.ts +4 -1
  19. package/dist/components/bottom-sheet.js +2 -2
  20. package/dist/components/checkbox.d.ts +12 -2
  21. package/dist/components/checkbox.js +7 -2
  22. package/dist/components/combobox.d.ts +186 -0
  23. package/dist/components/combobox.js +521 -0
  24. package/dist/components/comment.d.ts +27 -9
  25. package/dist/components/comment.js +14 -13
  26. package/dist/components/data-table.d.ts +14 -2
  27. package/dist/components/data-table.js +31 -10
  28. package/dist/components/date-picker.d.ts +179 -0
  29. package/dist/components/date-picker.js +336 -0
  30. package/dist/components/date-range-picker.d.ts +251 -0
  31. package/dist/components/date-range-picker.js +484 -0
  32. package/dist/components/file-upload.d.ts +30 -4
  33. package/dist/components/file-upload.js +37 -17
  34. package/dist/components/filter-panel.d.ts +29 -6
  35. package/dist/components/filter-panel.js +16 -14
  36. package/dist/components/flash-offer-bar.d.ts +18 -4
  37. package/dist/components/flash-offer-bar.js +13 -8
  38. package/dist/components/header-bar.d.ts +20 -4
  39. package/dist/components/header-bar.js +20 -13
  40. package/dist/components/icon.d.ts +7 -0
  41. package/dist/components/icon.js +9 -1
  42. package/dist/components/link-tabs.d.ts +16 -4
  43. package/dist/components/link-tabs.js +10 -7
  44. package/dist/components/mobile-menu.d.ts +19 -4
  45. package/dist/components/mobile-menu.js +16 -10
  46. package/dist/components/modal.d.ts +4 -1
  47. package/dist/components/nested-list.d.ts +22 -3
  48. package/dist/components/nested-list.js +25 -12
  49. package/dist/components/notification-panel.d.ts +26 -5
  50. package/dist/components/notification-panel.js +17 -11
  51. package/dist/components/option-group.d.ts +12 -2
  52. package/dist/components/option-group.js +13 -7
  53. package/dist/components/page-header.d.ts +18 -2
  54. package/dist/components/page-header.js +23 -10
  55. package/dist/components/pagination.d.ts +27 -4
  56. package/dist/components/pagination.js +28 -16
  57. package/dist/components/progress-bar.d.ts +12 -2
  58. package/dist/components/progress-bar.js +9 -4
  59. package/dist/components/radio.d.ts +12 -1
  60. package/dist/components/radio.js +12 -6
  61. package/dist/components/report-tile.d.ts +12 -1
  62. package/dist/components/report-tile.js +9 -4
  63. package/dist/components/resource-list.d.ts +36 -5
  64. package/dist/components/resource-list.js +50 -23
  65. package/dist/components/save-bar.d.ts +23 -6
  66. package/dist/components/save-bar.js +14 -12
  67. package/dist/components/search.d.ts +28 -7
  68. package/dist/components/search.js +18 -13
  69. package/dist/components/select.d.ts +12 -2
  70. package/dist/components/select.js +9 -4
  71. package/dist/components/side-navigation.d.ts +16 -4
  72. package/dist/components/side-navigation.js +16 -12
  73. package/dist/components/side-panel.d.ts +5 -2
  74. package/dist/components/side-panel.js +5 -3
  75. package/dist/components/skeleton-display.d.ts +6 -4
  76. package/dist/components/skeleton-display.js +4 -5
  77. package/dist/components/smart-tip.d.ts +25 -6
  78. package/dist/components/smart-tip.js +18 -12
  79. package/dist/components/spinner.d.ts +4 -3
  80. package/dist/components/spinner.js +5 -6
  81. package/dist/components/status-tabs.d.ts +12 -2
  82. package/dist/components/status-tabs.js +14 -8
  83. package/dist/components/table-header.d.ts +15 -2
  84. package/dist/components/table-header.js +13 -5
  85. package/dist/components/tag.d.ts +12 -2
  86. package/dist/components/tag.js +9 -4
  87. package/dist/components/text-field.d.ts +12 -2
  88. package/dist/components/text-field.js +9 -4
  89. package/dist/components/thumbnail.d.ts +12 -2
  90. package/dist/components/thumbnail.js +8 -3
  91. package/dist/components/toast.d.ts +14 -3
  92. package/dist/components/toast.js +20 -9
  93. package/dist/components/toggle.js +2 -0
  94. package/dist/custom-elements.json +16477 -6434
  95. package/dist/index.d.ts +7 -1
  96. package/dist/index.js +5 -1
  97. package/dist/localize.d.ts +130 -0
  98. package/dist/localize.js +232 -0
  99. package/dist/overlay.d.ts +8 -4
  100. package/dist/overlay.js +9 -12
  101. package/package.json +4 -4
package/README.md CHANGED
@@ -37,6 +37,6 @@ Or without a build step, pinned to a version:
37
37
  Form controls take part in native forms: values appear in `FormData`, `required` blocks submission, and
38
38
  `form.reset()` restores them. Set `data-cm-theme="light" | "dark" | "auto"` on `<html>` for themes.
39
39
 
40
- Browsers: current Chrome, Edge and Safari 16.4+ (tested); Firefox 98+ (expected, not yet tested).
40
+ Browsers: current Chrome and Edge, Firefox 98+ and Safari 16.4+ (the test suite runs in Chromium, Firefox and WebKit).
41
41
 
42
42
  Support: support@commmerce.com
package/dist/base.d.ts CHANGED
@@ -5,3 +5,8 @@ export declare const nextId: (p: string) => string;
5
5
  /** Registers a custom element once, so two copies of the library on one page don't throw. */
6
6
  export declare function define(tag: string, ctor: CustomElementConstructor): void;
7
7
  export type Tone = 'attention' | 'information' | 'success' | 'critical';
8
+ /**
9
+ * The arrow key as it reads in the element's direction: in right-to-left text ArrowLeft moves forward, so it is
10
+ * reported as ArrowRight (and the other way round). Up, down and every other key are unchanged.
11
+ */
12
+ export declare function logicalKey(e: KeyboardEvent, el: Element): string;
package/dist/base.js CHANGED
@@ -20,3 +20,13 @@ export function define(tag, ctor) {
20
20
  if (!customElements.get(tag))
21
21
  customElements.define(tag, ctor);
22
22
  }
23
+ /**
24
+ * The arrow key as it reads in the element's direction: in right-to-left text ArrowLeft moves forward, so it is
25
+ * reported as ArrowRight (and the other way round). Up, down and every other key are unchanged.
26
+ */
27
+ export function logicalKey(e, el) {
28
+ const k = e.key;
29
+ if ((k === 'ArrowLeft' || k === 'ArrowRight') && getComputedStyle(el).direction === 'rtl')
30
+ return k === 'ArrowLeft' ? 'ArrowRight' : 'ArrowLeft';
31
+ return k;
32
+ }
@@ -0,0 +1,95 @@
1
+ import { type TemplateResult } from 'lit';
2
+ import './components/icon.js';
3
+ /** A Date at local midnight for an ISO date string, or null if the string is not a real date. */
4
+ export declare function fromISO(s: string | null | undefined): Date | null;
5
+ export declare const toISO: (d: Date) => string;
6
+ export declare const todayISO: () => string;
7
+ export declare const addDays: (d: Date, n: number) => Date;
8
+ /** Same day in another month, clamped to that month's last day (31 Jan + 1 month = 28/29 Feb). */
9
+ export declare function addMonths(d: Date, n: number): Date;
10
+ export declare const startOfMonth: (d: Date) => Date;
11
+ export declare const endOfMonth: (d: Date) => Date;
12
+ export declare const sameMonth: (a: Date, b: Date) => boolean;
13
+ /** Splits a list attribute (`"2026-12-25, 2026-12-31"` or `"today last-7-days"`) into an array. */
14
+ export declare const listConverter: {
15
+ fromAttribute: (v: string | null) => string[];
16
+ toAttribute: (v: unknown) => unknown;
17
+ };
18
+ /** An array from a list property that may have been given a string (React 19 passes attribute strings as properties). */
19
+ export declare const asList: <T>(v: T[] | string | null | undefined) => T[];
20
+ /**
21
+ * A usable BCP 47 locale: the element's own `locale` property, else the library's resolution (`configure({ locale })`,
22
+ * then the nearest `lang` attribute, crossing shadow roots), else the browser's language.
23
+ */
24
+ export declare function resolveLocale(el: Element, explicit: string): string;
25
+ /** First day of the week for a locale (0 = Sunday … 6 = Saturday), from Intl.Locale week info where the browser has it. */
26
+ export declare function localeFirstDay(locale: string): number;
27
+ export interface DateFormat {
28
+ /** Formats an ISO date for the text box, e.g. 15/11/2026 (en-IN) or 11/15/2026 (en-US). */
29
+ short(d: Date): string;
30
+ /** Full date for screen readers, e.g. "Sunday 15 November 2026". */
31
+ long(d: Date): string;
32
+ /** Medium date for summaries, e.g. "15 Nov 2026". */
33
+ medium(d: Date): string;
34
+ monthYear(d: Date): string;
35
+ day(d: Date): string;
36
+ /** Weekday names starting at Sunday. */
37
+ weekdaysShort: string[];
38
+ weekdaysLong: string[];
39
+ /** "{d}/{m}/{y}": the locale's order and separators; fill it with `datePattern()`. */
40
+ pattern: string;
41
+ /** Order of the numeric fields, e.g. ['day', 'month', 'year']. */
42
+ order: Array<'day' | 'month' | 'year'>;
43
+ /** Lowercase month names (long and short, locale and English) for parsing typed dates. */
44
+ months: string[][];
45
+ }
46
+ /** Intl formatters for a locale, cached. */
47
+ export declare function dateFormat(locale: string): DateFormat;
48
+ /** The typed-date pattern with the component's letters for day, month and year, e.g. "dd/mm/yyyy" or "jj/mm/aaaa". */
49
+ export declare const datePattern: (fmt: DateFormat, letters: {
50
+ d: string;
51
+ m: string;
52
+ y: string;
53
+ }) => string;
54
+ /**
55
+ * Reads a typed date: ISO (2026-11-15), the locale's numeric order (15/11/2026 in en-IN, 11/15/2026 in en-US,
56
+ * with / . - or spaces, two-digit years mean 20xx), or a month name in the locale or English (15 Nov 2026,
57
+ * November 15 2026). Returns the ISO date, or null if the text is not a real date.
58
+ */
59
+ export declare function parseDate(text: string, fmt: DateFormat): string | null;
60
+ export interface GridOptions {
61
+ id: string;
62
+ fmt: DateFormat;
63
+ firstDay: number;
64
+ /** Month shown. */
65
+ month: Date;
66
+ /** Date that has the roving tabindex. */
67
+ focus: Date;
68
+ min: Date | null;
69
+ max: Date | null;
70
+ isDisabled(d: Date): boolean;
71
+ /** 'selected' | 'start' | 'end' | 'in-range' | '' for a date. */
72
+ mark(d: Date): string;
73
+ /** Extra words after the date in its accessible name, e.g. "start date". */
74
+ note?(d: Date): string;
75
+ onPick(d: Date): void;
76
+ onKey(e: KeyboardEvent): void;
77
+ onMonth(step: number): void;
78
+ onHover?(d: Date): void;
79
+ /** Accessible names of the month buttons, in the component's language. */
80
+ previousLabel: string;
81
+ nextLabel: string;
82
+ }
83
+ /**
84
+ * The new focused date for a grid key (APG date picker dialog), or null if the key is not a grid key. Pass the key
85
+ * from `logicalKey()`, so Left and Right follow the reading direction (in RTL, Left goes to the next day).
86
+ */
87
+ export declare function gridKey(key: string, e: KeyboardEvent, focus: Date, firstDay: number): Date | null;
88
+ export declare const clamp: (d: Date, min: Date | null, max: Date | null) => Date;
89
+ export declare function renderGrid(o: GridOptions): TemplateResult;
90
+ /** Styles for the popover and grid. Hosts render `.pop[role=dialog]` around `renderGrid`. */
91
+ export declare const calendarStyles: import("lit").CSSResult;
92
+ /** Keeps focus inside an open calendar popover: Tab and Shift+Tab cycle its buttons, presets and the grid. */
93
+ export declare function trapTab(e: KeyboardEvent, pop: HTMLElement): void;
94
+ /** Shared field and popover styles of the two date pickers. */
95
+ export declare const dateFieldStyles: import("lit").CSSResult;
@@ -0,0 +1,280 @@
1
+ import { html, css, nothing } from 'lit';
2
+ import { localeFor, formatDate } from './localize.js';
3
+ import './components/icon.js';
4
+ /*
5
+ * Shared, internal helpers for cm-date-picker and cm-date-range-picker: ISO date maths, locale-aware formatting
6
+ * and parsing through Intl, and the month grid (WAI-ARIA APG "date picker dialog" grid). Not a public component.
7
+ * Dates are plain local calendar dates written as ISO `yyyy-mm-dd` strings; Date objects are local midnight.
8
+ */
9
+ const ISO = /^(\d{4})-(\d{2})-(\d{2})$/;
10
+ /** A Date at local midnight for an ISO date string, or null if the string is not a real date. */
11
+ export function fromISO(s) {
12
+ const m = ISO.exec(s ?? '');
13
+ if (!m)
14
+ return null;
15
+ const d = new Date(+m[1], +m[2] - 1, +m[3]);
16
+ return d.getFullYear() === +m[1] && d.getMonth() === +m[2] - 1 && d.getDate() === +m[3] ? d : null;
17
+ }
18
+ const pad = (n, w = 2) => String(n).padStart(w, '0');
19
+ export const toISO = (d) => `${pad(d.getFullYear(), 4)}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
20
+ export const todayISO = () => toISO(new Date());
21
+ export const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
22
+ /** Same day in another month, clamped to that month's last day (31 Jan + 1 month = 28/29 Feb). */
23
+ export function addMonths(d, n) {
24
+ const first = new Date(d.getFullYear(), d.getMonth() + n, 1);
25
+ const last = new Date(first.getFullYear(), first.getMonth() + 1, 0).getDate();
26
+ return new Date(first.getFullYear(), first.getMonth(), Math.min(d.getDate(), last));
27
+ }
28
+ export const startOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
29
+ export const endOfMonth = (d) => new Date(d.getFullYear(), d.getMonth() + 1, 0);
30
+ export const sameMonth = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
31
+ /** Splits a list attribute (`"2026-12-25, 2026-12-31"` or `"today last-7-days"`) into an array. */
32
+ export const listConverter = {
33
+ fromAttribute: (v) => (v ? v.split(/[\s,]+/).filter(Boolean) : []),
34
+ toAttribute: (v) => (Array.isArray(v) ? v.join(' ') : v),
35
+ };
36
+ /** An array from a list property that may have been given a string (React 19 passes attribute strings as properties). */
37
+ export const asList = (v) => Array.isArray(v) ? v : typeof v === 'string' ? listConverter.fromAttribute(v) : [];
38
+ /**
39
+ * A usable BCP 47 locale: the element's own `locale` property, else the library's resolution (`configure({ locale })`,
40
+ * then the nearest `lang` attribute, crossing shadow roots), else the browser's language.
41
+ */
42
+ export function resolveLocale(el, explicit) {
43
+ const candidates = [explicit, localeFor(el) ?? '', navigator.language, 'en'];
44
+ for (const c of candidates) {
45
+ if (!c)
46
+ continue;
47
+ try {
48
+ if (Intl.DateTimeFormat.supportedLocalesOf([c]).length)
49
+ return c;
50
+ }
51
+ catch { /* not a valid tag */ }
52
+ }
53
+ return 'en';
54
+ }
55
+ /** First day of the week for a locale (0 = Sunday … 6 = Saturday), from Intl.Locale week info where the browser has it. */
56
+ export function localeFirstDay(locale) {
57
+ try {
58
+ const l = new Intl.Locale(locale);
59
+ const info = l.getWeekInfo?.() ?? l.weekInfo;
60
+ if (info?.firstDay)
61
+ return info.firstDay % 7;
62
+ }
63
+ catch { /* fall through */ }
64
+ return 0;
65
+ }
66
+ const formats = new Map();
67
+ /** Intl formatters for a locale, cached. */
68
+ export function dateFormat(locale) {
69
+ const hit = formats.get(locale);
70
+ if (hit)
71
+ return hit;
72
+ const f = (o) => new Intl.DateTimeFormat(locale, o);
73
+ const short = f({ day: '2-digit', month: '2-digit', year: 'numeric', numberingSystem: 'latn' });
74
+ const wdS = f({ weekday: 'short' });
75
+ const wdL = f({ weekday: 'long' });
76
+ const sunday = new Date(2024, 0, 7);
77
+ const parts = short.formatToParts(new Date(2026, 10, 15));
78
+ const order = parts.filter((p) => p.type === 'day' || p.type === 'month' || p.type === 'year').map((p) => p.type);
79
+ const pattern = parts.map((p) => (p.type === 'day' ? '{d}' : p.type === 'month' ? '{m}' : p.type === 'year' ? '{y}' : p.value)).join('');
80
+ const names = (loc, month) => Array.from({ length: 12 }, (_, i) => new Intl.DateTimeFormat(loc, { month }).format(new Date(2024, i, 1)).toLowerCase().replace(/\./g, ''));
81
+ const months = Array.from({ length: 12 }, (_, i) => [...new Set([names(locale, 'long')[i], names(locale, 'short')[i], names('en', 'long')[i], names('en', 'short')[i]])]);
82
+ const fmt = {
83
+ short: (d) => short.format(d),
84
+ long: (d) => formatDate(d, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }, locale),
85
+ medium: (d) => formatDate(d, { day: 'numeric', month: 'short', year: 'numeric' }, locale),
86
+ monthYear: (d) => formatDate(d, { month: 'long', year: 'numeric' }, locale),
87
+ day: (d) => formatDate(d, { day: 'numeric' }, locale),
88
+ weekdaysShort: Array.from({ length: 7 }, (_, i) => wdS.format(addDays(sunday, i))),
89
+ weekdaysLong: Array.from({ length: 7 }, (_, i) => wdL.format(addDays(sunday, i))),
90
+ pattern: order.length === 3 ? pattern : '{y}-{m}-{d}', order: order.length === 3 ? order : ['year', 'month', 'day'], months,
91
+ };
92
+ formats.set(locale, fmt);
93
+ return fmt;
94
+ }
95
+ /** The typed-date pattern with the component's letters for day, month and year, e.g. "dd/mm/yyyy" or "jj/mm/aaaa". */
96
+ export const datePattern = (fmt, letters) => fmt.pattern.replace(/\{([dmy])\}/g, (_, k) => letters[k]);
97
+ /**
98
+ * Reads a typed date: ISO (2026-11-15), the locale's numeric order (15/11/2026 in en-IN, 11/15/2026 in en-US,
99
+ * with / . - or spaces, two-digit years mean 20xx), or a month name in the locale or English (15 Nov 2026,
100
+ * November 15 2026). Returns the ISO date, or null if the text is not a real date.
101
+ */
102
+ export function parseDate(text, fmt) {
103
+ const s = text.trim().toLowerCase();
104
+ if (!s)
105
+ return null;
106
+ const tokens = s.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
107
+ if (tokens.length !== 3)
108
+ return null;
109
+ let y, m, d;
110
+ const alpha = tokens.findIndex((t) => /\p{L}/u.test(t));
111
+ if (alpha >= 0) {
112
+ const t = tokens[alpha];
113
+ m = fmt.months.findIndex((names) => names.some((n) => n === t || (t.length >= 3 && n.startsWith(t)))) + 1;
114
+ const nums = tokens.filter((_, i) => i !== alpha);
115
+ if (!m || nums.some((n) => !/^\d+$/.test(n)))
116
+ return null;
117
+ const yi = nums.findIndex((n) => n.length === 4);
118
+ const yIndex = yi >= 0 ? yi : 1;
119
+ y = +nums[yIndex];
120
+ d = +nums[1 - yIndex];
121
+ if (nums[yIndex].length <= 2)
122
+ y += 2000;
123
+ }
124
+ else {
125
+ if (tokens.some((n) => !/^\d+$/.test(n)))
126
+ return null;
127
+ const order = tokens[0].length === 4 ? ['year', 'month', 'day'] : fmt.order;
128
+ const get = (k) => tokens[order.indexOf(k)];
129
+ y = +get('year');
130
+ m = +get('month');
131
+ d = +get('day');
132
+ if (get('year').length <= 2)
133
+ y += 2000;
134
+ else if (get('year').length !== 4)
135
+ return null;
136
+ }
137
+ const iso = `${pad(y, 4)}-${pad(m)}-${pad(d)}`;
138
+ return fromISO(iso) ? iso : null;
139
+ }
140
+ /**
141
+ * The new focused date for a grid key (APG date picker dialog), or null if the key is not a grid key. Pass the key
142
+ * from `logicalKey()`, so Left and Right follow the reading direction (in RTL, Left goes to the next day).
143
+ */
144
+ export function gridKey(key, e, focus, firstDay) {
145
+ const dow = (focus.getDay() - firstDay + 7) % 7;
146
+ switch (key) {
147
+ case 'ArrowRight': return addDays(focus, 1);
148
+ case 'ArrowLeft': return addDays(focus, -1);
149
+ case 'ArrowDown': return addDays(focus, 7);
150
+ case 'ArrowUp': return addDays(focus, -7);
151
+ case 'Home': return addDays(focus, -dow);
152
+ case 'End': return addDays(focus, 6 - dow);
153
+ case 'PageDown': return addMonths(focus, e.shiftKey ? 12 : 1);
154
+ case 'PageUp': return addMonths(focus, e.shiftKey ? -12 : -1);
155
+ default: return null;
156
+ }
157
+ }
158
+ export const clamp = (d, min, max) => (min && d < min ? min : max && d > max ? max : d);
159
+ export function renderGrid(o) {
160
+ const { fmt, firstDay, month, focus, min, max } = o;
161
+ const first = startOfMonth(month);
162
+ const lead = (first.getDay() - firstDay + 7) % 7;
163
+ const days = endOfMonth(month).getDate();
164
+ const weeks = [];
165
+ let row = Array(lead).fill(null);
166
+ for (let i = 1; i <= days; i++) {
167
+ row.push(new Date(month.getFullYear(), month.getMonth(), i));
168
+ if (row.length === 7) {
169
+ weeks.push(row);
170
+ row = [];
171
+ }
172
+ }
173
+ if (row.length)
174
+ weeks.push([...row, ...Array(7 - row.length).fill(null)]);
175
+ const order = Array.from({ length: 7 }, (_, i) => (i + firstDay) % 7);
176
+ const today = todayISO();
177
+ const prevOff = !!min && endOfMonth(addMonths(first, -1)) < min;
178
+ const nextOff = !!max && addMonths(first, 1) > max;
179
+ return html `<div class="cal-head">
180
+ <button type="button" class="cal-nav" part="calendar-nav" aria-label=${o.previousLabel} ?disabled=${prevOff} @click=${() => o.onMonth(-1)}><cm-icon name="chevron-left" size="18"></cm-icon></button>
181
+ <h2 id="${o.id}-month" class="cal-title" aria-live="polite">${fmt.monthYear(month)}</h2>
182
+ <button type="button" class="cal-nav" part="calendar-nav" aria-label=${o.nextLabel} ?disabled=${nextOff} @click=${() => o.onMonth(1)}><cm-icon name="chevron-right" size="18"></cm-icon></button>
183
+ </div>
184
+ <table role="grid" class="cal-grid" part="calendar" aria-labelledby="${o.id}-month" @keydown=${o.onKey}>
185
+ <thead><tr>${order.map((d) => html `<th scope="col" abbr=${fmt.weekdaysLong[d]}><span aria-hidden="true">${fmt.weekdaysShort[d]}</span><span class="vh">${fmt.weekdaysLong[d]}</span></th>`)}</tr></thead>
186
+ <tbody>${weeks.map((w) => html `<tr>${w.map((d) => {
187
+ if (!d)
188
+ return html `<td class="empty"></td>`;
189
+ const iso = toISO(d);
190
+ const off = o.isDisabled(d) || (!!min && d < min) || (!!max && d > max);
191
+ const mark = o.mark(d);
192
+ const note = o.note?.(d);
193
+ return html `<td class="day ${mark} ${iso === today ? 'today' : ''}" data-date=${iso}
194
+ tabindex=${iso === toISO(focus) ? '0' : '-1'}
195
+ aria-selected=${mark ? 'true' : 'false'} aria-disabled=${off ? 'true' : nothing}
196
+ aria-current=${iso === today ? 'date' : nothing}
197
+ aria-label="${fmt.long(d)}${note ? `, ${note}` : ''}"
198
+ @click=${() => !off && o.onPick(d)} @pointerenter=${() => o.onHover?.(d)}><span aria-hidden="true">${fmt.day(d)}</span></td>`;
199
+ })}</tr>`)}</tbody>
200
+ </table>`;
201
+ }
202
+ /** Styles for the popover and grid. Hosts render `.pop[role=dialog]` around `renderGrid`. */
203
+ export const calendarStyles = css `
204
+ .pop {
205
+ position: absolute; z-index: 20; inset-block-start: calc(100% + var(--cm-space-10)); inset-inline-start: 0;
206
+ width: max-content; max-width: calc(100vw - 32px); padding: var(--cm-space-15);
207
+ background: var(--cm-bg-surface); color: var(--cm-text-default);
208
+ border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-100);
209
+ }
210
+ .pop[hidden] { display: none; }
211
+ .cal { width: 280px; max-width: 100%; }
212
+ .cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--cm-space-10); margin-block-end: var(--cm-space-10); }
213
+ .cal-title { flex: 1; margin: 0; text-align: center; font-size: 14px; line-height: 20px; font-weight: 500; }
214
+ .cal-nav {
215
+ display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--cm-radius-sm);
216
+ background: none; color: var(--cm-icon-selected); cursor: pointer;
217
+ }
218
+ .cal-nav:hover { background: var(--cm-bg-hover); }
219
+ .cal-nav:disabled { color: var(--cm-text-secondary); cursor: not-allowed; background: none; }
220
+ .cal-nav:focus-visible, .day:focus, .preset:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
221
+ .cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
222
+ .cal-grid th { height: 32px; padding: 0; font-size: 12px; font-weight: 400; color: var(--cm-text-tertiary); text-align: center; }
223
+ .day, .empty { height: 40px; padding: 0; text-align: center; font-size: 14px; }
224
+ .day { cursor: pointer; border-radius: var(--cm-radius-sm); outline: none; }
225
+ .day:hover { background: var(--cm-bg-hover); }
226
+ .day.today span { text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
227
+ .day.in-range { background: var(--cm-bg-attention-soft); border-radius: 0; }
228
+ .day.selected, .day.start, .day.end { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
229
+ .day[aria-disabled='true'] { color: var(--cm-text-secondary); cursor: not-allowed; background: none; text-decoration: line-through; }
230
+ .vh {
231
+ position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
232
+ clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
233
+ }
234
+ @media (max-width: 640px) { .day, .empty { height: 36px; } }
235
+ `;
236
+ /** Keeps focus inside an open calendar popover: Tab and Shift+Tab cycle its buttons, presets and the grid. */
237
+ export function trapTab(e, pop) {
238
+ if (e.key !== 'Tab')
239
+ return;
240
+ const stops = [...pop.querySelectorAll('button:not([disabled]), [role=grid] td[tabindex="0"]')];
241
+ if (!stops.length)
242
+ return;
243
+ const root = pop.getRootNode();
244
+ const i = stops.indexOf(root.activeElement);
245
+ e.preventDefault();
246
+ stops[(i + (e.shiftKey ? -1 : 1) + stops.length) % stops.length].focus();
247
+ }
248
+ /** Shared field and popover styles of the two date pickers. */
249
+ export const dateFieldStyles = css `
250
+ :host { display: block; position: relative; }
251
+ .field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
252
+ .label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); }
253
+ .req { color: var(--cm-text-critical); margin-inline-start: 2px; }
254
+ .wrap { position: relative; }
255
+ .box {
256
+ display: flex; align-items: center; gap: 4px; width: 100%; height: 42px; padding-block: 0; padding-inline: var(--cm-space-10) 4px;
257
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
258
+ }
259
+ .box:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
260
+ input {
261
+ flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; background: none;
262
+ font: inherit; font-size: 16px; color: var(--cm-text-default);
263
+ }
264
+ input::placeholder { color: var(--cm-text-tertiary); }
265
+ .trigger {
266
+ flex: none; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0;
267
+ border-radius: var(--cm-radius-sm); background: none; color: var(--cm-icon-selected); cursor: pointer;
268
+ }
269
+ .trigger:hover { background: var(--cm-bg-hover); }
270
+ .trigger:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
271
+ :host([error]:not([error=''])) .box { border-color: var(--cm-border-critical); }
272
+ :host([disabled]) .box { background: var(--cm-bg-input-filled); border-color: var(--cm-border-default); }
273
+ :host([disabled]) input, :host([disabled]) .trigger { color: var(--cm-text-secondary); cursor: not-allowed; }
274
+ :host([disabled]) .trigger:hover { background: none; }
275
+ .help, .error { margin: 0; font-size: 12px; color: var(--cm-text-tertiary); }
276
+ .error { color: var(--cm-text-critical); }
277
+ :host([size='small']) .field { gap: 6px; }
278
+ :host([size='small']) .label { font-size: 12px; }
279
+ :host([size='small']) input { font-size: 14px; }
280
+ `;