@commmerce/ui 1.3.0 → 1.5.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 (106) hide show
  1. package/THIRD_PARTY_NOTICES.txt +101 -0
  2. package/dist/calendar.js +15 -19
  3. package/dist/cdn.js +1669 -1193
  4. package/dist/components/accordion.js +9 -8
  5. package/dist/components/action-bar.js +15 -15
  6. package/dist/components/action-menu.js +10 -9
  7. package/dist/components/app-card.js +15 -14
  8. package/dist/components/app-frame.d.ts +15 -0
  9. package/dist/components/app-frame.js +22 -2
  10. package/dist/components/badge.d.ts +2 -1
  11. package/dist/components/badge.js +4 -3
  12. package/dist/components/banner.js +6 -5
  13. package/dist/components/board.js +18 -18
  14. package/dist/components/bottom-navigation.d.ts +1 -1
  15. package/dist/components/bottom-navigation.js +9 -7
  16. package/dist/components/bottom-sheet.d.ts +1 -1
  17. package/dist/components/bottom-sheet.js +9 -8
  18. package/dist/components/button.d.ts +3 -3
  19. package/dist/components/button.js +22 -19
  20. package/dist/components/calendar.d.ts +380 -0
  21. package/dist/components/calendar.js +1480 -0
  22. package/dist/components/card.d.ts +1 -1
  23. package/dist/components/card.js +18 -12
  24. package/dist/components/checkbox.js +8 -7
  25. package/dist/components/color-field.js +9 -13
  26. package/dist/components/combobox.d.ts +8 -0
  27. package/dist/components/combobox.js +18 -18
  28. package/dist/components/comment.d.ts +1 -1
  29. package/dist/components/comment.js +12 -13
  30. package/dist/components/data-table.js +12 -11
  31. package/dist/components/date-picker.js +1 -1
  32. package/dist/components/date-range-picker.js +7 -7
  33. package/dist/components/empty-state.d.ts +1 -1
  34. package/dist/components/empty-state.js +16 -16
  35. package/dist/components/file-upload.js +18 -16
  36. package/dist/components/filter-panel.js +1 -1
  37. package/dist/components/flash-offer-bar.js +8 -7
  38. package/dist/components/global-search.d.ts +1 -1
  39. package/dist/components/global-search.js +12 -9
  40. package/dist/components/grid.d.ts +1 -1
  41. package/dist/components/grid.js +1 -1
  42. package/dist/components/header-bar.js +38 -31
  43. package/dist/components/info-panel.d.ts +1 -1
  44. package/dist/components/info-panel.js +11 -10
  45. package/dist/components/layout.d.ts +1 -1
  46. package/dist/components/layout.js +1 -1
  47. package/dist/components/link-tabs.js +8 -7
  48. package/dist/components/metric.js +4 -4
  49. package/dist/components/mobile-menu.js +16 -15
  50. package/dist/components/modal.js +2 -1
  51. package/dist/components/nested-list.d.ts +2 -2
  52. package/dist/components/nested-list.js +21 -22
  53. package/dist/components/notification-panel.js +12 -11
  54. package/dist/components/option-group.js +10 -11
  55. package/dist/components/page-header.js +16 -15
  56. package/dist/components/page.d.ts +18 -4
  57. package/dist/components/page.js +22 -7
  58. package/dist/components/pagination.d.ts +1 -1
  59. package/dist/components/pagination.js +16 -9
  60. package/dist/components/progress-bar.js +4 -3
  61. package/dist/components/radio.js +12 -12
  62. package/dist/components/report-tile.d.ts +2 -2
  63. package/dist/components/report-tile.js +18 -18
  64. package/dist/components/resource-list.d.ts +22 -6
  65. package/dist/components/resource-list.js +92 -52
  66. package/dist/components/save-bar.js +8 -8
  67. package/dist/components/search.d.ts +5 -2
  68. package/dist/components/search.js +20 -14
  69. package/dist/components/segmented-control.d.ts +67 -0
  70. package/dist/components/segmented-control.js +76 -0
  71. package/dist/components/select.d.ts +8 -0
  72. package/dist/components/select.js +18 -18
  73. package/dist/components/side-navigation.js +20 -17
  74. package/dist/components/side-panel.js +4 -3
  75. package/dist/components/signature-field.d.ts +153 -0
  76. package/dist/components/signature-field.js +728 -0
  77. package/dist/components/skeleton-display.js +4 -4
  78. package/dist/components/skeleton.d.ts +1 -1
  79. package/dist/components/skeleton.js +2 -2
  80. package/dist/components/smart-tip.d.ts +1 -1
  81. package/dist/components/smart-tip.js +16 -16
  82. package/dist/components/spinner.js +1 -1
  83. package/dist/components/stack.d.ts +1 -1
  84. package/dist/components/stack.js +1 -1
  85. package/dist/components/status-tabs.d.ts +4 -3
  86. package/dist/components/status-tabs.js +26 -12
  87. package/dist/components/table-header.d.ts +4 -3
  88. package/dist/components/table-header.js +22 -15
  89. package/dist/components/tag.js +3 -4
  90. package/dist/components/text-field.d.ts +1 -1
  91. package/dist/components/text-field.js +8 -15
  92. package/dist/components/thumbnail.js +1 -1
  93. package/dist/components/timeline.js +12 -11
  94. package/dist/components/toast.js +6 -6
  95. package/dist/components/toggle.js +12 -11
  96. package/dist/components/tooltip.js +4 -3
  97. package/dist/custom-elements.json +13655 -9770
  98. package/dist/field.d.ts +15 -0
  99. package/dist/field.js +47 -0
  100. package/dist/index.d.ts +4 -0
  101. package/dist/index.js +3 -0
  102. package/dist/overlay.js +5 -4
  103. package/dist/popover.js +8 -8
  104. package/dist/spacing.d.ts +14 -4
  105. package/dist/spacing.js +13 -4
  106. package/package.json +3 -3
@@ -0,0 +1,1480 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _CmCalendar_instances, _CmCalendar_localeProp, _CmCalendar_id, _CmCalendar_announcer, _CmCalendar_model, _CmCalendar_held, _CmCalendar_drag, _CmCalendar_history, _CmCalendar_focusKey, _CmCalendar_pendingFocus, _CmCalendar_lastRange, _CmCalendar_scrollToStart, _CmCalendar_quietUntil, _CmCalendar_focusPop, _CmCalendar_ro, _CmCalendar_roFrame, _CmCalendar_mo, _CmCalendar_view_get, _CmCalendar_loc_get, _CmCalendar_fmt_get, _CmCalendar_tf_get, _CmCalendar_step_get, _CmCalendar_firstDay_get, _CmCalendar_todayISO_get, _CmCalendar_anchor_get, _CmCalendar_compact_get, _CmCalendar_timeView_get, _CmCalendar_days, _CmCalendar_parse, _CmCalendar_parsed, _CmCalendar_byDay, _CmCalendar_dayText, _CmCalendar_timeText, _CmCalendar_timeRange, _CmCalendar_when, _CmCalendar_name, _CmCalendar_rangeLabel, _CmCalendar_hourLabel, _CmCalendar_placeText, _CmCalendar_measure, _CmCalendar_shift, _CmCalendar_setView, _CmCalendar_items, _CmCalendar_find, _CmCalendar_defaultKey, _CmCalendar_syncTabStops, _CmCalendar_focusItem, _CmCalendar_onFocusIn, _CmCalendar_onFocusOut, _CmCalendar_neighbour, _CmCalendar_page, _CmCalendar_onKey, _CmCalendar_slots, _CmCalendar_moveKey, _CmCalendar_timesAt, _CmCalendar_holdFor, _CmCalendar_release, _CmCalendar_showTarget, _CmCalendar_keyboardDrop, _CmCalendar_commitPlace, _CmCalendar_times, _CmCalendar_commit, _CmCalendar_onNativeDrag, _CmCalendar_timeAt, _CmCalendar_dayAt, _CmCalendar_onPointerDown, _CmCalendar_onTouchMove, _CmCalendar_onContextMenu, _CmCalendar_onPointerMove, _CmCalendar_onPointerUp, _CmCalendar_onPointerCancel, _CmCalendar_startDrag, _CmCalendar_updateTarget, _CmCalendar_autoScroll, _CmCalendar_endDrag, _CmCalendar_add, _CmCalendar_slotClick, _CmCalendar_open, _CmCalendar_openMore, _CmCalendar_closeMore, _CmCalendar_activeEv, _CmCalendar_chip, _CmCalendar_placeholder, _CmCalendar_header, _CmCalendar_weekdayHeads, _CmCalendar_month, _CmCalendar_lanes, _CmCalendar_timeGrid;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { base, define, logicalKey, nextId } from '../base.js';
15
+ import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
16
+ import { MoveModel, Announcer } from '../move-model.js';
17
+ import { fromISO, toISO, addDays, addMonths, startOfMonth, endOfMonth, splitDateTime, fromISODateTime, todayISO, timeFormat, resolveLocale, localeFirstDay, dateFormat, } from '../calendar.js';
18
+ import './icon.js';
19
+ import './spinner.js';
20
+ const strings = defineStrings('calendar', {
21
+ /** Accessible name of the calendar when it has no `label`. */
22
+ label: 'Calendar',
23
+ /** Header buttons. */
24
+ previousMonth: 'Previous month',
25
+ nextMonth: 'Next month',
26
+ previousWeek: 'Previous week',
27
+ nextWeek: 'Next week',
28
+ /** The narrow week view shows three days at a time. */
29
+ previousDays: 'Previous {count} days',
30
+ nextDays: 'Next {count} days',
31
+ previousDay: 'Previous day',
32
+ nextDay: 'Next day',
33
+ today: 'Today',
34
+ /** The group of view buttons, and the buttons. */
35
+ views: 'View',
36
+ month: 'Month',
37
+ week: 'Week',
38
+ day: 'Day',
39
+ /** Row heading of all-day events in the week and day views. */
40
+ allDay: 'All day',
41
+ /** Heading of the hour column in the week and day views (read by screen readers only). */
42
+ time: 'Time',
43
+ /** The visible text of the Add button above the day's list on narrow screens. */
44
+ add: 'Add',
45
+ /** The "+" button of a day in the month view, and the Add button of the day's list. `{date}` e.g. "Wednesday 18 November". */
46
+ addOn: 'Add on {date}',
47
+ /** The "+" button in the all-day row of the week and day views. */
48
+ addAllDay: 'Add an all-day event on {date}',
49
+ /** An empty hour in the week and day views. `{time}` e.g. "3:00 pm". */
50
+ addAt: 'Add at {time}, {date}',
51
+ /** The overflow button of a month day, visible text. */
52
+ more: '+{count} more',
53
+ /** The overflow button's accessible name. */
54
+ moreLabel: '{count} more on {date}',
55
+ /** A day button in the narrow month view. */
56
+ dayEvents: { one: '{date}, {count} event', other: '{date}, {count} events' },
57
+ /** The day's list with nothing in it. */
58
+ noEvents: 'No events',
59
+ /** Announced while `loading`. */
60
+ loading: 'Loading events',
61
+ /** A time range: "3:00 to 3:30 pm". `{start}` and `{end}` are formatted for the locale (a shared am/pm is written once). */
62
+ timeRange: '{start} to {end}',
63
+ /** When an event happens, in its accessible name. */
64
+ timed: '{date}, {time}',
65
+ allDayOn: '{date}, all day',
66
+ allDayRange: '{start} to {end}, all day',
67
+ /** An event's accessible name: "Call Ravi Stores, Wednesday 18 November, 3:00 to 3:30 pm, Follow-up". */
68
+ eventName: '{title}, {when}',
69
+ eventNameKind: '{title}, {when}, {kind}',
70
+ /** What screen readers call a movable event, after its name. */
71
+ roleDescription: 'movable event',
72
+ /** Read after an event's name. */
73
+ openHint: 'Press Enter to open.',
74
+ instructions: 'Press Space to pick up, then the arrow keys to choose a day or time, Space or Enter to drop and Escape to cancel.',
75
+ /** Read with the grid. */
76
+ gridHelp: 'Use the arrow keys to move between days, times and events, and Page Up and Page Down for the previous or next period.',
77
+ /** Added to an event's name while its move is saved (`pending`). */
78
+ saving: 'Saving',
79
+ /** Move announcements. `{event}` the event's title, `{place}` a day ("Thursday 19 November") or a day and time. */
80
+ pickedUp: 'Picked up {event}. {place}.',
81
+ over: '{place}.',
82
+ moved: 'Moved {event} to {place}.',
83
+ sameSpot: '{event} dropped where it started.',
84
+ cancelled: 'Move cancelled. {event} is back on {place}.',
85
+ refused: '{event} can\'t be moved to {place}.',
86
+ reverted: 'Couldn\'t move {event}. It is back on {place}.',
87
+ });
88
+ /**
89
+ * One event on a `cm-calendar`: a call, a follow-up, a demo. It shows nothing itself: the calendar draws it as a
90
+ * chip in every view. Set `start` (and `end`) as local ISO date-times, or dates with `all-day`.
91
+ * @element cm-calendar-event
92
+ * @slot - The title, when `heading` is not set.
93
+ */
94
+ export class CmCalendarEvent extends LitElement {
95
+ constructor() {
96
+ super(...arguments);
97
+ /** Identifies the event in `cm-move` and `cm-open` (e.g. its id). Defaults to the title. */
98
+ this.value = '';
99
+ /** The title, e.g. "Call Ravi Stores". */
100
+ this.heading = '';
101
+ /** The title for screen readers and announcements, when it should differ from `heading`. */
102
+ this.label = '';
103
+ /** Local start, ISO `yyyy-mm-ddThh:mm`; for an all-day event `yyyy-mm-dd` (a date alone makes it all-day). */
104
+ this.start = '';
105
+ /** Local end, ISO `yyyy-mm-ddThh:mm` (default: 30 minutes after `start`); for an all-day event, its last day `yyyy-mm-dd` (default: the start day). */
106
+ this.end = '';
107
+ /** Lasts the whole day (or days): shown in the all-day row of the week and day views, and first in a month day. */
108
+ this.allDay = false;
109
+ /** What it is, in a word or two: "Follow-up", "Demo", "Call". Shown on the chip and read in its name, so colour is never the only signal. */
110
+ this.kind = '';
111
+ /** Colour of the chip, from the semantic tones. Pick one per kind and keep it. */
112
+ this.tone = 'neutral';
113
+ /** A `cm-icon` name shown before the title (e.g. `phone` for calls). The month view shows the icon instead of `kind`. */
114
+ this.icon = '';
115
+ /** Makes the chip a link to the record. Without it, activating the chip fires `cm-open`. */
116
+ this.href = '';
117
+ /** The event can't be moved (e.g. no permission). It can still be opened. */
118
+ this.locked = false;
119
+ /** The move is being saved: the chip is greyed and can't be moved again until it is cleared. Set by `waitUntil()` in `cm-move`, or by you. */
120
+ this.pending = false;
121
+ /** Set by the calendar while the event is picked up or dragged. Read it for styling; don't set it. */
122
+ this.moving = false;
123
+ }
124
+ /** The event's name: `label`, `heading`, or its text. */
125
+ get name() {
126
+ return this.label || this.heading || (this.textContent ?? '').replace(/\s+/g, ' ').trim();
127
+ }
128
+ /** The value used in events: `value`, or the name. */
129
+ get key() { return this.value || this.name; }
130
+ updated() {
131
+ const p = this.parentElement;
132
+ if (p?.localName === 'cm-calendar')
133
+ p.requestUpdate();
134
+ }
135
+ render() { return nothing; }
136
+ }
137
+ CmCalendarEvent.properties = {
138
+ value: { reflect: true },
139
+ heading: {},
140
+ label: {},
141
+ start: {},
142
+ end: {},
143
+ allDay: { type: Boolean, attribute: 'all-day', reflect: true },
144
+ kind: {},
145
+ tone: { reflect: true },
146
+ icon: {},
147
+ href: {},
148
+ locked: { type: Boolean, reflect: true },
149
+ pending: { type: Boolean, reflect: true },
150
+ moving: { type: Boolean, reflect: true },
151
+ };
152
+ CmCalendarEvent.styles = css `:host { display: none !important; }`;
153
+ define('cm-calendar-event', CmCalendarEvent);
154
+ const pad = (n) => String(n).padStart(2, '0');
155
+ const isoTime = (d) => `${toISO(d)}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
156
+ const dayDiff = (a, b) => Math.round((Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()) - Date.UTC(a.getFullYear(), a.getMonth(), a.getDate())) / 864e5);
157
+ const VIEWS = ['month', 'week', 'day'];
158
+ const NARROW = 600;
159
+ const rangeFormats = new Map();
160
+ const dtf = (locale, o) => {
161
+ const k = `${locale}|${JSON.stringify(o)}`;
162
+ let f = rangeFormats.get(k);
163
+ if (!f) {
164
+ f = new Intl.DateTimeFormat(locale, o);
165
+ rangeFormats.set(k, f);
166
+ }
167
+ return f;
168
+ };
169
+ const spaces = (s) => s.replace(/[  ]/g, ' ').trim();
170
+ /**
171
+ * A calendar of events in month, week and day views: an outreach planner of calls, follow-ups and demos. Events are
172
+ * `cm-calendar-event` children; the calendar draws them as chips with a kind and a colour.
173
+ *
174
+ * The header has Previous, Today and Next, the range shown and a view switch. Each change of view or range fires
175
+ * `cm-range-change` with the days shown, so the app loads their events. Events move between days (month, week) and
176
+ * times (week, day) by dragging (on touch, press and hold first) or with the keyboard: focus an event, press Space,
177
+ * choose a day or time with the arrow keys and press Enter. Each move fires a cancelable `cm-move`. A "+" on each
178
+ * day (and each hour in the week and day views) fires `cm-add`.
179
+ *
180
+ * When the calendar is narrower than 600px the month view becomes a compact grid with the chosen day's events
181
+ * listed under it, and the week view shows three days.
182
+ * @element cm-calendar
183
+ * @slot - `cm-calendar-event` elements, in any order.
184
+ * @fires cm-range-change - When the days shown change (view, Previous/Next/Today, `date`, or the width crossing 600px), and once on first render. `detail: { view, start, end }` (ISO dates, both included). Load the events for those days.
185
+ * @fires cm-move - Before an event moves. Cancelable: `preventDefault()` keeps it where it was. `detail: { value, event, from: { start, end }, to: { start, end }, allDay, source, waitUntil }` (see `CalendarMoveDetail`).
186
+ * @fires cm-add - From a "+" button or an empty hour. `detail: { start, allDay, view }`: `start` is `yyyy-mm-dd` for a day, `yyyy-mm-ddThh:mm` for an hour.
187
+ * @fires cm-open - When an event chip is activated (click or Enter). `detail: { value, event }`. Cancelable: on a chip with `href`, `preventDefault()` stops the link.
188
+ * @csspart header - The row with the navigation, the range and the view switch.
189
+ * @csspart title - The range shown ("November 2026").
190
+ * @csspart grid - The month table, or the week and day time grid.
191
+ * @csspart agenda - The chosen day's list under the narrow month view.
192
+ * @cssprop --cm-calendar-hour-height - Height of an hour in the week and day views. Default 48px.
193
+ * @cssprop --cm-calendar-time-height - Most height of the scrolling week and day views. Default 600px.
194
+ * @cssprop --cm-calendar-day-height - Height of a day in the month view. Default 112px.
195
+ */
196
+ export class CmCalendar extends CmLocalizedElement {
197
+ /** BCP 47 language for month and weekday names, times and the first day of the week. Empty: the same language as every other component. */
198
+ get locale() { return __classPrivateFieldGet(this, _CmCalendar_localeProp, "f"); }
199
+ set locale(v) { const old = __classPrivateFieldGet(this, _CmCalendar_localeProp, "f"); __classPrivateFieldSet(this, _CmCalendar_localeProp, v ?? '', "f"); this.requestUpdate('locale', old); }
200
+ constructor() {
201
+ super();
202
+ _CmCalendar_instances.add(this);
203
+ /** `month`, `week` or `day`. */
204
+ this.view = 'month';
205
+ /** A day in the range shown, ISO `yyyy-mm-dd`. Previous, Next and Today change it. Empty: today. On narrow screens it is also the day listed under the month. */
206
+ this.date = '';
207
+ /** Today's date, ISO `yyyy-mm-dd`, for the Today button and the highlight. Empty: the device's date. Set it from your server, or to fix the date in tests. */
208
+ this.today = '';
209
+ /** Minutes events snap to when moved in the week and day views (1 to 240). Default 15. */
210
+ this.step = 15;
211
+ _CmCalendar_localeProp.set(this, '');
212
+ /** `h12` or `h23` to force a 12- or 24-hour clock. Empty: the locale's clock. */
213
+ this.hourCycle = '';
214
+ /** The hour the week and day views scroll to when they open (0 to 23). Default 8. */
215
+ this.dayStart = 8;
216
+ /** Most chips in a month day; with more, the last place shows "+N more", which lists the whole day. Default 3. */
217
+ this.maxEvents = 3;
218
+ /** Level of the range heading for screen readers (1 to 6). Default 2. */
219
+ this.headingLevel = 2;
220
+ /** Events are loading: the grid is busy and "Loading events" is announced. */
221
+ this.loading = false;
222
+ /** No "+" buttons and no moving: events can only be opened. */
223
+ this.readonly = false;
224
+ /**
225
+ * You move the events: the calendar fires `cm-move` but never changes `start` and `end`. Change them (or re-render
226
+ * the event) in your `cm-move` listener. Use it with React, Vue and other frameworks that render from data.
227
+ */
228
+ this.controlled = false;
229
+ /** Set while an event is dragged with a pointer. Read it for styling; don't set it. */
230
+ this.dragging = false;
231
+ this._narrow = false;
232
+ /** The day whose "+N more" list is open. */
233
+ this._more = '';
234
+ /** Where the moving event would land. */
235
+ this._target = null;
236
+ _CmCalendar_id.set(this, nextId('cm-cal'));
237
+ _CmCalendar_announcer.set(this, new Announcer());
238
+ _CmCalendar_model.set(this, void 0);
239
+ _CmCalendar_held.set(this, null);
240
+ _CmCalendar_drag.set(this, null);
241
+ _CmCalendar_history.set(this, new WeakMap());
242
+ _CmCalendar_focusKey.set(this, '');
243
+ _CmCalendar_pendingFocus.set(this, null);
244
+ _CmCalendar_lastRange.set(this, '');
245
+ _CmCalendar_scrollToStart.set(this, true);
246
+ _CmCalendar_quietUntil.set(this, 0);
247
+ _CmCalendar_focusPop.set(this, false);
248
+ _CmCalendar_ro.set(this, void 0);
249
+ _CmCalendar_roFrame.set(this, 0);
250
+ _CmCalendar_mo.set(this, new MutationObserver(() => this.requestUpdate()));
251
+ _CmCalendar_onFocusIn.set(this, (e) => {
252
+ const t = e.composedPath()[0];
253
+ if (t instanceof HTMLElement && t.classList.contains('item') && t.dataset.k) {
254
+ __classPrivateFieldSet(this, _CmCalendar_focusKey, t.dataset.k, "f");
255
+ for (const i of __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_items).call(this))
256
+ i.tabIndex = i === t ? 0 : -1;
257
+ }
258
+ });
259
+ _CmCalendar_onFocusOut.set(this, (e) => {
260
+ const to = e.relatedTarget;
261
+ // The "+N more" list closes when focus leaves it.
262
+ if (this._more && !__classPrivateFieldGet(this, _CmCalendar_held, "f")) {
263
+ const pop = this.renderRoot.querySelector('.pop');
264
+ const t = e.composedPath()[0];
265
+ if (pop && pop.contains(t) && !(to && pop.contains(to))) {
266
+ queueMicrotask(() => { if (!pop.contains(this.renderRoot.activeElement))
267
+ this._more = ''; });
268
+ }
269
+ }
270
+ if (!__classPrivateFieldGet(this, _CmCalendar_model, "f").active || !__classPrivateFieldGet(this, _CmCalendar_held, "f"))
271
+ return;
272
+ if (!to && document.hasFocus() === false)
273
+ return;
274
+ // Wait for any re-render that moves focus to the held chip on purpose.
275
+ this.updateComplete.then(() => setTimeout(() => {
276
+ if (!__classPrivateFieldGet(this, _CmCalendar_model, "f").active || !__classPrivateFieldGet(this, _CmCalendar_held, "f"))
277
+ return;
278
+ const a = this.renderRoot.activeElement;
279
+ if (a?.dataset.ev !== __classPrivateFieldGet(this, _CmCalendar_held, "f").ev.key)
280
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel();
281
+ }));
282
+ });
283
+ _CmCalendar_onKey.set(this, (e) => {
284
+ if (__classPrivateFieldGet(this, _CmCalendar_drag, "f")?.started && e.key === 'Escape') {
285
+ e.preventDefault();
286
+ this.cancelMove();
287
+ return;
288
+ }
289
+ const key = logicalKey(e, this);
290
+ if (__classPrivateFieldGet(this, _CmCalendar_model, "f").active) {
291
+ if (__classPrivateFieldGet(this, _CmCalendar_model, "f").handleKey(e, key)) {
292
+ e.preventDefault();
293
+ e.stopPropagation();
294
+ }
295
+ return;
296
+ }
297
+ if (e.altKey || e.ctrlKey || e.metaKey)
298
+ return;
299
+ const t = e.composedPath()[0];
300
+ if (!(t instanceof HTMLElement) || t.getRootNode() !== this.renderRoot)
301
+ return;
302
+ const pop = t.closest('.pop');
303
+ if (pop && e.key === 'Escape') {
304
+ e.preventDefault();
305
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_closeMore).call(this, true);
306
+ return;
307
+ }
308
+ if (t.dataset.ev && e.key === ' ') {
309
+ e.preventDefault();
310
+ __classPrivateFieldSet(this, _CmCalendar_quietUntil, performance.now() + 400, "f");
311
+ this.pickUp(t.dataset.ev, t.dataset.day);
312
+ return;
313
+ }
314
+ if (pop && (key === 'ArrowDown' || key === 'ArrowUp')) {
315
+ const chips = [...pop.querySelectorAll('.chip')];
316
+ const next = chips[chips.indexOf(t) + (key === 'ArrowDown' ? 1 : -1)];
317
+ if (next) {
318
+ e.preventDefault();
319
+ next.focus();
320
+ }
321
+ return;
322
+ }
323
+ if (!t.classList.contains('item'))
324
+ return;
325
+ if (e.key === 'PageUp' || e.key === 'PageDown') {
326
+ e.preventDefault();
327
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_page).call(this, t, e.key === 'PageUp' ? -1 : 1);
328
+ return;
329
+ }
330
+ const next = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_neighbour).call(this, t, key);
331
+ if (next) {
332
+ e.preventDefault();
333
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_focusItem).call(this, next);
334
+ }
335
+ else if (key.startsWith('Arrow') || key === 'Home' || key === 'End')
336
+ e.preventDefault();
337
+ });
338
+ /* ---------- Pointer drag ---------- */
339
+ _CmCalendar_onNativeDrag.set(this, (e) => {
340
+ if (e.composedPath().some((n) => n.dataset?.ev))
341
+ e.preventDefault();
342
+ });
343
+ _CmCalendar_onPointerDown.set(this, (e) => {
344
+ if (__classPrivateFieldGet(this, _CmCalendar_drag, "f") || this.readonly || !e.isPrimary || (e.pointerType === 'mouse' && e.button !== 0))
345
+ return;
346
+ const chip = e.composedPath().find((n) => n.dataset?.ev);
347
+ if (!chip)
348
+ return;
349
+ const el = this.event(chip.dataset.ev);
350
+ const ev = el && __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, el);
351
+ if (!ev || el.locked || el.pending)
352
+ return;
353
+ const held = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_holdFor).call(this, ev, chip.dataset.day ?? ev.days[0]);
354
+ if (!held)
355
+ return;
356
+ if (__classPrivateFieldGet(this, _CmCalendar_model, "f").active)
357
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel();
358
+ let grab = 0;
359
+ if (held.mode === 'time') {
360
+ const at = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeAt).call(this, e.clientX, e.clientY);
361
+ if (at && chip.classList.contains('time'))
362
+ grab = Math.max(0, Math.min(ev.dur, at.min - ev.min));
363
+ }
364
+ __classPrivateFieldSet(this, _CmCalendar_drag, {
365
+ ...held, pointerId: e.pointerId, type: e.pointerType, x0: e.clientX, y0: e.clientY, x: e.clientX, y: e.clientY,
366
+ started: false, grab, to: { ...held.from },
367
+ }, "f");
368
+ if (e.pointerType !== 'mouse') {
369
+ // Touch and pen: press and hold to pick up, so a swipe still scrolls.
370
+ __classPrivateFieldGet(this, _CmCalendar_drag, "f").timer = setTimeout(() => { if (__classPrivateFieldGet(this, _CmCalendar_drag, "f") && !__classPrivateFieldGet(this, _CmCalendar_drag, "f").started)
371
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_startDrag).call(this); }, 300);
372
+ }
373
+ window.addEventListener('pointermove', __classPrivateFieldGet(this, _CmCalendar_onPointerMove, "f"), true);
374
+ window.addEventListener('pointerup', __classPrivateFieldGet(this, _CmCalendar_onPointerUp, "f"), true);
375
+ window.addEventListener('pointercancel', __classPrivateFieldGet(this, _CmCalendar_onPointerCancel, "f"), true);
376
+ window.addEventListener('touchmove', __classPrivateFieldGet(this, _CmCalendar_onTouchMove, "f"), { capture: true, passive: false });
377
+ window.addEventListener('contextmenu', __classPrivateFieldGet(this, _CmCalendar_onContextMenu, "f"), true);
378
+ });
379
+ _CmCalendar_onTouchMove.set(this, (e) => { if (__classPrivateFieldGet(this, _CmCalendar_drag, "f")?.started && e.cancelable)
380
+ e.preventDefault(); });
381
+ _CmCalendar_onContextMenu.set(this, (e) => { if (__classPrivateFieldGet(this, _CmCalendar_drag, "f"))
382
+ e.preventDefault(); });
383
+ _CmCalendar_onPointerMove.set(this, (e) => {
384
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
385
+ if (!d || e.pointerId !== d.pointerId)
386
+ return;
387
+ d.x = e.clientX;
388
+ d.y = e.clientY;
389
+ if (!d.started) {
390
+ const dist = Math.hypot(d.x - d.x0, d.y - d.y0);
391
+ if (d.type === 'mouse' ? dist > 4 : dist > 8) {
392
+ if (d.type === 'mouse')
393
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_startDrag).call(this);
394
+ else
395
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false); // moved before the hold: it's a scroll
396
+ }
397
+ return;
398
+ }
399
+ e.preventDefault();
400
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_updateTarget).call(this);
401
+ });
402
+ _CmCalendar_onPointerUp.set(this, (e) => {
403
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
404
+ if (!d || e.pointerId !== d.pointerId)
405
+ return;
406
+ if (!d.started) {
407
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false);
408
+ return;
409
+ }
410
+ // The click that follows a drag must not open the event.
411
+ const swallow = (ev) => { ev.stopPropagation(); ev.preventDefault(); };
412
+ window.addEventListener('click', swallow, { capture: true, once: true });
413
+ setTimeout(() => window.removeEventListener('click', swallow, true), 0);
414
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, true);
415
+ });
416
+ _CmCalendar_onPointerCancel.set(this, (e) => {
417
+ if (__classPrivateFieldGet(this, _CmCalendar_drag, "f") && e.pointerId === __classPrivateFieldGet(this, _CmCalendar_drag, "f").pointerId)
418
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false);
419
+ });
420
+ __classPrivateFieldSet(this, _CmCalendar_model, new MoveModel({
421
+ groupCount: () => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this).length,
422
+ slotCount: () => (!__classPrivateFieldGet(this, _CmCalendar_held, "f") ? 0 : __classPrivateFieldGet(this, _CmCalendar_held, "f").mode === 'day' ? 1 : __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_slots).call(this, __classPrivateFieldGet(this, _CmCalendar_held, "f").ev.dur)),
423
+ navigate: (key, at) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_moveKey).call(this, key, at),
424
+ onTarget: (at) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_showTarget).call(this, at),
425
+ onDrop: (from, to) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_keyboardDrop).call(this, from, to),
426
+ onCancel: () => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_release).call(this),
427
+ messages: {
428
+ pickedUp: (at) => this.t('pickedUp', { event: __classPrivateFieldGet(this, _CmCalendar_held, "f")?.ev.name ?? '', place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, __classPrivateFieldGet(this, _CmCalendar_held, "f"), at) }),
429
+ over: (at) => this.t('over', { place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, __classPrivateFieldGet(this, _CmCalendar_held, "f"), at) }),
430
+ cancelled: (from) => this.t('cancelled', { event: __classPrivateFieldGet(this, _CmCalendar_held, "f")?.ev.name ?? '', place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, __classPrivateFieldGet(this, _CmCalendar_held, "f"), from) }),
431
+ },
432
+ announce: (text) => __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(text),
433
+ }), "f");
434
+ }
435
+ /* ---------- Reading ---------- */
436
+ /** The `cm-calendar-event` children. */
437
+ get events() {
438
+ return [...this.children].filter((c) => c.localName === 'cm-calendar-event');
439
+ }
440
+ /** The event with this `value` (or title). */
441
+ event(value) {
442
+ return this.events.find((e) => e.key === value);
443
+ }
444
+ /** The view and the first and last day shown, as in `cm-range-change`. */
445
+ get range() {
446
+ const days = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this);
447
+ return { view: __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get), start: toISO(days[0]), end: toISO(days[days.length - 1]) };
448
+ }
449
+ /** The event picked up with the keyboard, if any. */
450
+ get heldEvent() { return __classPrivateFieldGet(this, _CmCalendar_held, "f")?.ev.el ?? null; }
451
+ /** The last message announced (for tests and logging). */
452
+ get announcement() { return __classPrivateFieldGet(this, _CmCalendar_announcer, "f").text; }
453
+ /** Announces a message in the calendar's live region. */
454
+ announce(text) { __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(text); }
455
+ /* ---------- Lifecycle ---------- */
456
+ connectedCallback() {
457
+ super.connectedCallback();
458
+ this.addEventListener('keydown', __classPrivateFieldGet(this, _CmCalendar_onKey, "f"));
459
+ this.addEventListener('focusin', __classPrivateFieldGet(this, _CmCalendar_onFocusIn, "f"));
460
+ this.addEventListener('focusout', __classPrivateFieldGet(this, _CmCalendar_onFocusOut, "f"));
461
+ this.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmCalendar_onPointerDown, "f"));
462
+ this.addEventListener('dragstart', __classPrivateFieldGet(this, _CmCalendar_onNativeDrag, "f"));
463
+ __classPrivateFieldGet(this, _CmCalendar_mo, "f").observe(this, { childList: true });
464
+ if (typeof ResizeObserver !== 'undefined') {
465
+ // Measured on the next frame: switching layout inside the callback would resize the calendar again in the
466
+ // same frame ("ResizeObserver loop completed with undelivered notifications" in WebKit).
467
+ __classPrivateFieldSet(this, _CmCalendar_ro, new ResizeObserver(() => {
468
+ cancelAnimationFrame(__classPrivateFieldGet(this, _CmCalendar_roFrame, "f"));
469
+ __classPrivateFieldSet(this, _CmCalendar_roFrame, requestAnimationFrame(() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_measure).call(this)), "f");
470
+ }), "f");
471
+ __classPrivateFieldGet(this, _CmCalendar_ro, "f").observe(this);
472
+ }
473
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_measure).call(this);
474
+ }
475
+ disconnectedCallback() {
476
+ super.disconnectedCallback();
477
+ this.removeEventListener('keydown', __classPrivateFieldGet(this, _CmCalendar_onKey, "f"));
478
+ this.removeEventListener('focusin', __classPrivateFieldGet(this, _CmCalendar_onFocusIn, "f"));
479
+ this.removeEventListener('focusout', __classPrivateFieldGet(this, _CmCalendar_onFocusOut, "f"));
480
+ this.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmCalendar_onPointerDown, "f"));
481
+ this.removeEventListener('dragstart', __classPrivateFieldGet(this, _CmCalendar_onNativeDrag, "f"));
482
+ __classPrivateFieldGet(this, _CmCalendar_mo, "f").disconnect();
483
+ __classPrivateFieldGet(this, _CmCalendar_ro, "f")?.disconnect();
484
+ cancelAnimationFrame(__classPrivateFieldGet(this, _CmCalendar_roFrame, "f"));
485
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel(true);
486
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false);
487
+ }
488
+ willUpdate(changed) {
489
+ if (changed.has('view')) {
490
+ __classPrivateFieldSet(this, _CmCalendar_scrollToStart, true, "f");
491
+ if (changed.get('view') !== undefined) {
492
+ this._more = '';
493
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel(true);
494
+ }
495
+ }
496
+ if (changed.has('date') || changed.has('_narrow'))
497
+ this._more = this._more && this.range.start <= this._more && this._more <= this.range.end ? this._more : '';
498
+ }
499
+ firstUpdated() {
500
+ this.renderRoot.appendChild(__classPrivateFieldGet(this, _CmCalendar_announcer, "f").element);
501
+ }
502
+ updated() {
503
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_syncTabStops).call(this);
504
+ if (__classPrivateFieldGet(this, _CmCalendar_pendingFocus, "f")) {
505
+ const el = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_find).call(this, __classPrivateFieldGet(this, _CmCalendar_pendingFocus, "f").key);
506
+ if (el) {
507
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, null, "f");
508
+ el.focus({ preventScroll: false });
509
+ }
510
+ else if (Date.now() > __classPrivateFieldGet(this, _CmCalendar_pendingFocus, "f").until)
511
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, null, "f");
512
+ }
513
+ if (__classPrivateFieldGet(this, _CmCalendar_focusPop, "f")) {
514
+ __classPrivateFieldSet(this, _CmCalendar_focusPop, false, "f");
515
+ (this.renderRoot.querySelector('.pop .chip') ?? this.renderRoot.querySelector('.pop button'))?.focus();
516
+ }
517
+ const tg = this.renderRoot.querySelector('.tg');
518
+ if (tg && __classPrivateFieldGet(this, _CmCalendar_scrollToStart, "f")) {
519
+ const cell = tg.querySelector('.tcell');
520
+ const h = Math.max(0, Math.min(23, Math.trunc(Number(this.dayStart)) || 0));
521
+ if (cell)
522
+ tg.scrollTop = cell.offsetHeight * h;
523
+ __classPrivateFieldSet(this, _CmCalendar_scrollToStart, false, "f");
524
+ }
525
+ if (!tg)
526
+ __classPrivateFieldSet(this, _CmCalendar_scrollToStart, true, "f");
527
+ if (__classPrivateFieldGet(this, _CmCalendar_held, "f") && this._target) {
528
+ this.renderRoot.querySelector('.ph')?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
529
+ }
530
+ const r = this.range;
531
+ const sig = `${r.view}|${r.start}|${r.end}`;
532
+ if (sig !== __classPrivateFieldGet(this, _CmCalendar_lastRange, "f")) {
533
+ __classPrivateFieldSet(this, _CmCalendar_lastRange, sig, "f");
534
+ this.dispatchEvent(new CustomEvent('cm-range-change', { detail: r, bubbles: true, composed: true }));
535
+ }
536
+ }
537
+ /** Shows the previous month, week (three days when narrow) or day. */
538
+ previous() { this.date = toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_shift).call(this, __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get), -1)); }
539
+ /** Shows the next month, week (three days when narrow) or day. */
540
+ next() { this.date = toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_shift).call(this, __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get), 1)); }
541
+ /** Shows the range with today in it. */
542
+ goToToday() { this.date = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_todayISO_get); }
543
+ /**
544
+ * Picks up an event for moving with the arrow keys, as Space does: e.g. from a "Move" item in your own menu.
545
+ * `day` (ISO) is the day it is picked up from, for an all-day event over several days. Returns false when the
546
+ * event is not shown, `locked`, `pending` or the calendar is `readonly`.
547
+ */
548
+ pickUp(event, day) {
549
+ const el = typeof event === 'string' ? this.event(event) : event;
550
+ if (!el || el.locked || el.pending || this.readonly)
551
+ return false;
552
+ const ev = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, el);
553
+ if (!ev)
554
+ return false;
555
+ const days = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this).map(toISO);
556
+ const origin = day && ev.days.includes(day) && days.includes(day) ? day : ev.days.find((d) => days.includes(d));
557
+ if (!origin)
558
+ return false;
559
+ const held = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_holdFor).call(this, ev, origin);
560
+ if (!held)
561
+ return false;
562
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false);
563
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel(true);
564
+ this._more = '';
565
+ __classPrivateFieldSet(this, _CmCalendar_held, held, "f");
566
+ el.moving = true;
567
+ const key = `ev:${ev.key}:${origin}`;
568
+ __classPrivateFieldSet(this, _CmCalendar_focusKey, key, "f");
569
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, { key, until: Date.now() + 1000 }, "f");
570
+ this.requestUpdate();
571
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").pickUp(held.from);
572
+ return true;
573
+ }
574
+ /** Cancels a keyboard move or a drag in progress: the event stays where it was. */
575
+ cancelMove() {
576
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
577
+ if (d?.started) {
578
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_endDrag).call(this, false);
579
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('cancelled', { event: d.ev.name, place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, d, d.from) }));
580
+ }
581
+ __classPrivateFieldGet(this, _CmCalendar_model, "f").cancel();
582
+ }
583
+ /**
584
+ * Moves an event to a new start (local ISO; `end` defaults to keeping its length), as a drop would: fires
585
+ * `cm-move`, and unless it is cancelled (or the calendar is `controlled`) changes `start` and `end`. Returns false
586
+ * when the move was cancelled or the event was not found.
587
+ */
588
+ moveEvent(event, start, end) {
589
+ const el = typeof event === 'string' ? this.event(event) : event;
590
+ const ev = el && __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, el);
591
+ if (!ev)
592
+ return false;
593
+ const s = ev.allDay ? fromISO(splitDateTime(start).date || start) : fromISODateTime(start);
594
+ if (!s)
595
+ return false;
596
+ let e = end ? (ev.allDay ? fromISO(splitDateTime(end).date || end) : fromISODateTime(end)) : null;
597
+ if (!e || e < s)
598
+ e = ev.allDay ? addDays(s, dayDiff(ev.start, ev.end)) : new Date(s.getTime() + ev.dur * 60000);
599
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_commit).call(this, ev, s, e, 'api', false, toISO(s));
600
+ }
601
+ /**
602
+ * Puts an event back where it was before its last move by the calendar, clears `pending` and announces it. Call
603
+ * it when saving the move failed (a rejected `waitUntil()` promise does this for you). Does nothing with
604
+ * `controlled` (put it back in your data) or when the event has not moved. Returns whether it went back.
605
+ */
606
+ revert(event) {
607
+ const el = typeof event === 'string' ? this.event(event) : event;
608
+ if (!el)
609
+ return false;
610
+ el.pending = false;
611
+ const was = __classPrivateFieldGet(this, _CmCalendar_history, "f").get(el);
612
+ if (this.controlled || !was)
613
+ return false;
614
+ __classPrivateFieldGet(this, _CmCalendar_history, "f").delete(el);
615
+ const focused = this.renderRoot.activeElement?.dataset.ev === el.key;
616
+ el.start = was.start;
617
+ el.end = was.end;
618
+ const ev = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, el);
619
+ if (ev && focused)
620
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, { key: `ev:${ev.key}:${ev.days[0]}`, until: Date.now() + 1000 }, "f");
621
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('reverted', { event: el.name, place: ev ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_when).call(this, ev) : was.start }));
622
+ return true;
623
+ }
624
+ render() {
625
+ const days = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this);
626
+ const byDay = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_byDay).call(this, __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parsed).call(this));
627
+ return html `<div class="cal ${this._narrow ? 'narrow' : ''}" role="group" aria-label=${this.label}>
628
+ ${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_header).call(this, days)}
629
+ ${__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month' ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_month).call(this, days, byDay) : __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeGrid).call(this, days, byDay)}
630
+ <span class="vh" role="status">${this.loading ? this.t('loading') : ''}</span>
631
+ <span id="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-gh" hidden>${this.t('gridHelp')}</span>
632
+ <span id="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-mv" hidden>${this.t('openHint')} ${this.t('instructions')}</span>
633
+ <span id="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-op" hidden>${this.t('openHint')}</span>
634
+ </div>`;
635
+ }
636
+ }
637
+ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalendar_announcer = new WeakMap(), _CmCalendar_model = new WeakMap(), _CmCalendar_held = new WeakMap(), _CmCalendar_drag = new WeakMap(), _CmCalendar_history = new WeakMap(), _CmCalendar_focusKey = new WeakMap(), _CmCalendar_pendingFocus = new WeakMap(), _CmCalendar_lastRange = new WeakMap(), _CmCalendar_scrollToStart = new WeakMap(), _CmCalendar_quietUntil = new WeakMap(), _CmCalendar_focusPop = new WeakMap(), _CmCalendar_ro = new WeakMap(), _CmCalendar_roFrame = new WeakMap(), _CmCalendar_mo = new WeakMap(), _CmCalendar_onFocusIn = new WeakMap(), _CmCalendar_onFocusOut = new WeakMap(), _CmCalendar_onKey = new WeakMap(), _CmCalendar_onNativeDrag = new WeakMap(), _CmCalendar_onPointerDown = new WeakMap(), _CmCalendar_onTouchMove = new WeakMap(), _CmCalendar_onContextMenu = new WeakMap(), _CmCalendar_onPointerMove = new WeakMap(), _CmCalendar_onPointerUp = new WeakMap(), _CmCalendar_onPointerCancel = new WeakMap(), _CmCalendar_instances = new WeakSet(), _CmCalendar_view_get = function _CmCalendar_view_get() { return VIEWS.includes(this.view) ? this.view : 'month'; }, _CmCalendar_loc_get = function _CmCalendar_loc_get() { return resolveLocale(this, this.locale); }, _CmCalendar_fmt_get = function _CmCalendar_fmt_get() { return dateFormat(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get)); }, _CmCalendar_tf_get = function _CmCalendar_tf_get() { return timeFormat(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get), this.hourCycle); }, _CmCalendar_step_get = function _CmCalendar_step_get() { const n = Math.trunc(Number(this.step)); return n >= 1 && n <= 240 ? n : 15; }, _CmCalendar_firstDay_get = function _CmCalendar_firstDay_get() {
638
+ const n = Number(this.firstDayOfWeek);
639
+ return this.firstDayOfWeek == null || Number.isNaN(n) ? localeFirstDay(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get)) : ((Math.trunc(n) % 7) + 7) % 7;
640
+ }, _CmCalendar_todayISO_get = function _CmCalendar_todayISO_get() { return fromISO(this.today) ? this.today : todayISO(); }, _CmCalendar_anchor_get = function _CmCalendar_anchor_get() { return fromISO(this.date) ?? fromISO(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_todayISO_get)); }, _CmCalendar_compact_get = function _CmCalendar_compact_get() { return __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month' && this._narrow; }, _CmCalendar_timeView_get = function _CmCalendar_timeView_get() { return __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) !== 'month'; }, _CmCalendar_days = function _CmCalendar_days() {
641
+ const a = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get);
642
+ const fd = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_firstDay_get);
643
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'day')
644
+ return [a];
645
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'week') {
646
+ if (this._narrow)
647
+ return [a, addDays(a, 1), addDays(a, 2)];
648
+ const s = addDays(a, -((a.getDay() - fd + 7) % 7));
649
+ return Array.from({ length: 7 }, (_, i) => addDays(s, i));
650
+ }
651
+ const first = startOfMonth(a);
652
+ const s = addDays(first, -((first.getDay() - fd + 7) % 7));
653
+ const n = Math.ceil((dayDiff(s, endOfMonth(a)) + 1) / 7) * 7;
654
+ return Array.from({ length: n }, (_, i) => addDays(s, i));
655
+ }, _CmCalendar_parse = function _CmCalendar_parse(el) {
656
+ const name = el.name;
657
+ const dateOnly = !!fromISO(el.start);
658
+ const allDay = el.allDay || dateOnly;
659
+ if (allDay) {
660
+ const s = fromISO(splitDateTime(el.start).date || el.start);
661
+ if (!s)
662
+ return null;
663
+ let e = fromISO(splitDateTime(el.end).date || el.end) ?? s;
664
+ if (e < s)
665
+ e = s;
666
+ const n = Math.min(dayDiff(s, e), 366);
667
+ return { el, key: el.key, name, allDay, start: s, end: e, min: 0, dur: 1440, days: Array.from({ length: n + 1 }, (_, i) => toISO(addDays(s, i))) };
668
+ }
669
+ const s = fromISODateTime(el.start);
670
+ if (!s)
671
+ return null;
672
+ let e = fromISODateTime(el.end);
673
+ if (!e || e <= s)
674
+ e = new Date(s.getTime() + 30 * 60000);
675
+ const dur = Math.max(1, Math.round((e.getTime() - s.getTime()) / 60000));
676
+ return { el, key: el.key, name, allDay, start: s, end: e, min: s.getHours() * 60 + s.getMinutes(), dur, days: [toISO(s)] };
677
+ }, _CmCalendar_parsed = function _CmCalendar_parsed() {
678
+ return this.events.map((e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, e)).filter((e) => !!e);
679
+ }, _CmCalendar_byDay = function _CmCalendar_byDay(evs) {
680
+ const m = new Map();
681
+ for (const ev of evs)
682
+ for (const d of ev.days)
683
+ (m.get(d) ?? m.set(d, []).get(d)).push(ev);
684
+ for (const list of m.values()) {
685
+ list.sort((a, b) => (a.allDay === b.allDay ? 0 : a.allDay ? -1 : 1) || a.start.getTime() - b.start.getTime() || a.name.localeCompare(b.name));
686
+ }
687
+ return m;
688
+ }, _CmCalendar_dayText = function _CmCalendar_dayText(d) { return formatDate(d, { weekday: 'long', day: 'numeric', month: 'long' }, __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get)); }, _CmCalendar_timeText = function _CmCalendar_timeText(min) { return __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_tf_get).format(((min % 1440) + 1440) % 1440); }, _CmCalendar_timeRange = function _CmCalendar_timeRange(s, e) {
689
+ const hc = this.hourCycle === 'h12' || this.hourCycle === 'h23' ? { hourCycle: this.hourCycle } : {};
690
+ const f = dtf(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get), { hour: 'numeric', minute: '2-digit', ...hc });
691
+ try {
692
+ if (toISO(s) === toISO(e) && f.formatRangeToParts) {
693
+ const parts = f.formatRangeToParts(s, e);
694
+ const firstEnd = parts.findIndex((p) => p.source === 'endRange');
695
+ let lastStart = -1;
696
+ parts.forEach((p, i) => { if (p.source === 'startRange')
697
+ lastStart = i; });
698
+ if (lastStart >= 0 && firstEnd > lastStart) {
699
+ const join = (ps) => spaces(ps.map((p) => p.value).join(''));
700
+ return this.t('timeRange', { start: join(parts.slice(0, lastStart + 1)), end: join(parts.slice(firstEnd)) });
701
+ }
702
+ }
703
+ }
704
+ catch { /* fall back below */ }
705
+ const sameDay = toISO(s) === toISO(e);
706
+ const at = (d) => (sameDay ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeText).call(this, d.getHours() * 60 + d.getMinutes()) : __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_tf_get).dateTime(d));
707
+ return this.t('timeRange', { start: at(s), end: at(e) });
708
+ }, _CmCalendar_when = function _CmCalendar_when(ev) {
709
+ if (ev.allDay) {
710
+ if (toISO(ev.start) === toISO(ev.end))
711
+ return this.t('allDayOn', { date: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, ev.start) });
712
+ return this.t('allDayRange', { start: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, ev.start), end: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, ev.end) });
713
+ }
714
+ if (toISO(ev.start) !== toISO(ev.end) && !(ev.end.getHours() === 0 && ev.end.getMinutes() === 0 && dayDiff(ev.start, ev.end) === 1)) {
715
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeRange).call(this, ev.start, ev.end);
716
+ }
717
+ return this.t('timed', { date: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, ev.start), time: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeRange).call(this, ev.start, ev.end) });
718
+ }, _CmCalendar_name = function _CmCalendar_name(ev) {
719
+ const vars = { title: ev.name, when: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_when).call(this, ev), kind: ev.el.kind };
720
+ return this.t(ev.el.kind ? 'eventNameKind' : 'eventName', vars);
721
+ }, _CmCalendar_rangeLabel = function _CmCalendar_rangeLabel(days) {
722
+ const loc = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get);
723
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month')
724
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_fmt_get).monthYear(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get));
725
+ if (days.length === 1)
726
+ return formatDate(days[0], { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }, loc);
727
+ const f = dtf(loc, { day: 'numeric', month: 'short', year: 'numeric' });
728
+ try {
729
+ if (f.formatRange)
730
+ return spaces(f.formatRange(days[0], days[days.length - 1]));
731
+ }
732
+ catch { /* below */ }
733
+ return `${f.format(days[0])} – ${f.format(days[days.length - 1])}`;
734
+ }, _CmCalendar_hourLabel = function _CmCalendar_hourLabel(h) {
735
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_tf_get).hour12)
736
+ return spaces(formatDate(new Date(2000, 0, 1, h), { hour: 'numeric', hourCycle: 'h12' }, __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_loc_get)));
737
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeText).call(this, h * 60);
738
+ }, _CmCalendar_placeText = function _CmCalendar_placeText(h, at) {
739
+ const { start, end } = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timesAt).call(this, h, at);
740
+ if (h.mode === 'time')
741
+ return this.t('timed', { date: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, start), time: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeRange).call(this, start, end) });
742
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, addDays(fromISO(h.origin), at.group - h.from.group));
743
+ }, _CmCalendar_measure = function _CmCalendar_measure() {
744
+ const w = this.getBoundingClientRect().width;
745
+ if (!w)
746
+ return;
747
+ const narrow = w < NARROW;
748
+ if (narrow !== this._narrow)
749
+ this._narrow = narrow;
750
+ }, _CmCalendar_shift = function _CmCalendar_shift(d, dir) {
751
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month')
752
+ return addMonths(d, dir);
753
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'week')
754
+ return addDays(d, dir * (this._narrow ? 3 : 7));
755
+ return addDays(d, dir);
756
+ }, _CmCalendar_setView = function _CmCalendar_setView(v) { if (this.view !== v)
757
+ this.view = v; }, _CmCalendar_items = function _CmCalendar_items() { return [...this.renderRoot.querySelectorAll('.item')]; }, _CmCalendar_find = function _CmCalendar_find(key) {
758
+ const all = [...this.renderRoot.querySelectorAll('[data-k]')];
759
+ const exact = all.find((e) => e.dataset.k === key && e.classList.contains('item')) ?? all.find((e) => e.dataset.k === key);
760
+ if (exact)
761
+ return exact;
762
+ if (key.startsWith('ev:') && !this.controlled) {
763
+ const iso = key.slice(key.lastIndexOf(':') + 1);
764
+ return all.find((e) => e.dataset.k === `more:${iso}`) ?? null;
765
+ }
766
+ return null;
767
+ }, _CmCalendar_defaultKey = function _CmCalendar_defaultKey() {
768
+ const iso = toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get));
769
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_compact_get))
770
+ return `day:${iso}`;
771
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month')
772
+ return this.readonly ? `cell:${iso}` : `add:${iso}`;
773
+ const h = Math.max(0, Math.min(23, Math.trunc(Number(this.dayStart)) || 0));
774
+ return `slot:${iso}:${h}`;
775
+ }, _CmCalendar_syncTabStops = function _CmCalendar_syncTabStops() {
776
+ const items = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_items).call(this);
777
+ if (!items.length)
778
+ return;
779
+ const active = items.find((i) => i.dataset.k === __classPrivateFieldGet(this, _CmCalendar_focusKey, "f")) ?? items.find((i) => i.dataset.k === __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_defaultKey).call(this))
780
+ ?? items.find((i) => i.dataset.day === toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get))) ?? items[0];
781
+ for (const i of items)
782
+ i.tabIndex = i === active ? 0 : -1;
783
+ }, _CmCalendar_focusItem = function _CmCalendar_focusItem(el) {
784
+ __classPrivateFieldSet(this, _CmCalendar_focusKey, el.dataset.k ?? '', "f");
785
+ for (const i of __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_items).call(this))
786
+ i.tabIndex = i === el ? 0 : -1;
787
+ el.focus();
788
+ }, _CmCalendar_neighbour = function _CmCalendar_neighbour(cur, key) {
789
+ const byDay = new Map();
790
+ for (const i of __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_items).call(this)) {
791
+ const d = Number(i.dataset.i);
792
+ (byDay.get(d) ?? byDay.set(d, []).get(d)).push(i);
793
+ }
794
+ const d = Number(cur.dataset.i);
795
+ const list = byDay.get(d) ?? [cur];
796
+ const idx = Math.max(0, list.indexOf(cur));
797
+ const n = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this).length;
798
+ const month = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month';
799
+ const row = cur.dataset.row;
800
+ const inDay = (day, pick) => {
801
+ const l = day >= 0 && day < n ? byDay.get(day) : undefined;
802
+ return (l?.length ? pick(l) : undefined) ?? null;
803
+ };
804
+ const sameRow = (l) => (month ? l[Math.min(idx, l.length - 1)] : l.find((x) => x.dataset.row === row) ?? l[0]);
805
+ switch (key) {
806
+ case 'ArrowRight': return inDay(d + 1, sameRow);
807
+ case 'ArrowLeft': return inDay(d - 1, sameRow);
808
+ case 'ArrowDown': return list[idx + 1] ?? (month ? inDay(d + 7, (l) => l[0]) : null);
809
+ case 'ArrowUp': return idx > 0 ? list[idx - 1] : month ? inDay(d - 7, (l) => l[l.length - 1]) : null;
810
+ case 'Home': return month ? inDay(d - (d % 7), (l) => l[0]) : inDay(0, sameRow);
811
+ case 'End': return month ? inDay(Math.min(n - 1, d - (d % 7) + 6), (l) => l[0]) : inDay(n - 1, sameRow);
812
+ default: return null;
813
+ }
814
+ }, _CmCalendar_page = function _CmCalendar_page(cur, dir) {
815
+ const iso = cur.dataset.day ?? toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get));
816
+ const day = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_shift).call(this, fromISO(iso) ?? __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get), dir);
817
+ const next = toISO(day);
818
+ const kind = (cur.dataset.k ?? '').split(':')[0];
819
+ let key;
820
+ if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_compact_get))
821
+ key = `day:${next}`;
822
+ else if (__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month')
823
+ key = this.readonly ? `cell:${next}` : `add:${next}`;
824
+ else if (kind === 'adadd' || cur.dataset.row === 'a')
825
+ key = `adadd:${next}`;
826
+ else
827
+ key = `slot:${next}:${cur.dataset.row ?? this.dayStart}`;
828
+ this.date = toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_shift).call(this, __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get), dir));
829
+ __classPrivateFieldSet(this, _CmCalendar_focusKey, key, "f");
830
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, { key, until: Date.now() + 1000 }, "f");
831
+ }, _CmCalendar_slots = function _CmCalendar_slots(dur) { return Math.floor((1440 - Math.min(dur, 1440)) / __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get)) + 1; }, _CmCalendar_moveKey = function _CmCalendar_moveKey(key, at) {
832
+ const h = __classPrivateFieldGet(this, _CmCalendar_held, "f");
833
+ if (!h)
834
+ return null;
835
+ const n = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this).length;
836
+ const g = (x) => Math.max(0, Math.min(n - 1, x));
837
+ if (h.mode === 'day') {
838
+ const month = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) === 'month';
839
+ switch (key) {
840
+ case 'ArrowRight': return { group: g(at.group + 1), index: 0 };
841
+ case 'ArrowLeft': return { group: g(at.group - 1), index: 0 };
842
+ case 'ArrowDown': return month ? { group: at.group + 7 < n ? at.group + 7 : at.group, index: 0 } : { ...at };
843
+ case 'ArrowUp': return month ? { group: at.group - 7 >= 0 ? at.group - 7 : at.group, index: 0 } : { ...at };
844
+ case 'Home': return { group: month ? at.group - (at.group % 7) : 0, index: 0 };
845
+ case 'End': return { group: month ? g(at.group - (at.group % 7) + 6) : n - 1, index: 0 };
846
+ default: return null;
847
+ }
848
+ }
849
+ const last = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_slots).call(this, h.ev.dur) - 1;
850
+ const hour = Math.max(1, Math.round(60 / __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get)));
851
+ const i = (x) => Math.max(0, Math.min(last, x));
852
+ switch (key) {
853
+ case 'ArrowRight': return { group: g(at.group + 1), index: at.index };
854
+ case 'ArrowLeft': return { group: g(at.group - 1), index: at.index };
855
+ case 'ArrowDown': return { group: at.group, index: i(at.index + 1) };
856
+ case 'ArrowUp': return { group: at.group, index: i(at.index - 1) };
857
+ case 'PageDown': return { group: at.group, index: i(at.index + hour) };
858
+ case 'PageUp': return { group: at.group, index: i(at.index - hour) };
859
+ case 'Home': return { group: at.group, index: 0 };
860
+ case 'End': return { group: at.group, index: last };
861
+ default: return null;
862
+ }
863
+ }, _CmCalendar_timesAt = function _CmCalendar_timesAt(h, at) {
864
+ const { ev } = h;
865
+ if (h.mode === 'time') {
866
+ const day = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this)[at.group] ?? fromISO(h.origin);
867
+ const start = new Date(day.getFullYear(), day.getMonth(), day.getDate(), 0, at.index * __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get));
868
+ return { start, end: new Date(start.getTime() + ev.dur * 60000) };
869
+ }
870
+ const delta = at.group - h.from.group;
871
+ const shift = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + delta, d.getHours(), d.getMinutes());
872
+ return { start: shift(ev.start), end: shift(ev.end) };
873
+ }, _CmCalendar_holdFor = function _CmCalendar_holdFor(ev, origin) {
874
+ const days = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this).map(toISO);
875
+ const group = days.indexOf(origin);
876
+ if (group < 0)
877
+ return null;
878
+ const mode = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_timeView_get) && !ev.allDay ? 'time' : 'day';
879
+ const index = mode === 'time' ? Math.min(Math.floor(ev.min / __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get)), __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_slots).call(this, ev.dur) - 1) : 0;
880
+ return { ev, origin, mode, from: { group, index } };
881
+ }, _CmCalendar_release = function _CmCalendar_release() {
882
+ if (__classPrivateFieldGet(this, _CmCalendar_held, "f"))
883
+ __classPrivateFieldGet(this, _CmCalendar_held, "f").ev.el.moving = false;
884
+ __classPrivateFieldSet(this, _CmCalendar_held, null, "f");
885
+ this._target = null;
886
+ }, _CmCalendar_showTarget = function _CmCalendar_showTarget(at) {
887
+ const h = __classPrivateFieldGet(this, _CmCalendar_held, "f");
888
+ if (!h || !at) {
889
+ this._target = null;
890
+ return;
891
+ }
892
+ const iso = toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this)[at.group] ?? fromISO(h.origin));
893
+ const same = at.group === h.from.group && at.index === h.from.index;
894
+ this._target = same ? null : { iso, min: h.mode === 'time' ? at.index * __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get) : undefined };
895
+ }, _CmCalendar_keyboardDrop = function _CmCalendar_keyboardDrop(from, to) {
896
+ const h = __classPrivateFieldGet(this, _CmCalendar_held, "f");
897
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_release).call(this);
898
+ if (!h)
899
+ return;
900
+ __classPrivateFieldSet(this, _CmCalendar_quietUntil, performance.now() + 400, "f");
901
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_commitPlace).call(this, h, from, to, 'keyboard');
902
+ }, _CmCalendar_commitPlace = function _CmCalendar_commitPlace(h, from, to, source) {
903
+ const same = from.group === to.group && from.index === to.index;
904
+ const { start, end } = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timesAt).call(this, h, to);
905
+ const day = toISO(addDays(fromISO(h.origin), to.group - from.group));
906
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_commit).call(this, h.ev, start, end, source, same, h.mode === 'time' ? toISO(start) : day);
907
+ }, _CmCalendar_times = function _CmCalendar_times(allDay, start, end) {
908
+ return allDay ? { start: toISO(start), end: toISO(end) } : { start: isoTime(start), end: isoTime(end) };
909
+ }, _CmCalendar_commit = function _CmCalendar_commit(ev, start, end, source, same, day) {
910
+ const el = ev.el;
911
+ const name = ev.name;
912
+ const from = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_times).call(this, ev.allDay, ev.start, ev.end);
913
+ const to = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_times).call(this, ev.allDay, start, end);
914
+ const refocus = (key) => { if (source === 'keyboard')
915
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, { key, until: Date.now() + 1000 }, "f"); };
916
+ if (same || (from.start === to.start && from.end === to.end)) {
917
+ if (source !== 'api')
918
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('sameSpot', { event: name }));
919
+ this.requestUpdate();
920
+ return false;
921
+ }
922
+ const moved = { ...ev, start, end };
923
+ const place = ev.allDay ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, start) : this.t('timed', { date: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, start), time: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeRange).call(this, start, end) });
924
+ const waits = [];
925
+ const detail = {
926
+ value: ev.key, event: el, from, to, allDay: ev.allDay, source,
927
+ waitUntil: (p) => { waits.push(Promise.resolve(p)); },
928
+ };
929
+ const ok = this.dispatchEvent(new CustomEvent('cm-move', { detail, bubbles: true, composed: true, cancelable: true }));
930
+ if (!ok) {
931
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('refused', { event: name, place }));
932
+ this.requestUpdate();
933
+ return false;
934
+ }
935
+ if (!this.controlled) {
936
+ __classPrivateFieldGet(this, _CmCalendar_history, "f").set(el, from);
937
+ el.start = to.start;
938
+ el.end = to.end;
939
+ }
940
+ refocus(`ev:${ev.key}:${day}`);
941
+ this.requestUpdate();
942
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('moved', { event: name, place: moved.allDay ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, start) : place }));
943
+ if (waits.length) {
944
+ el.pending = true;
945
+ Promise.all(waits).then(() => { el.pending = false; if (!this.controlled)
946
+ __classPrivateFieldGet(this, _CmCalendar_history, "f").delete(el); }, () => {
947
+ el.pending = false;
948
+ if (!this.controlled)
949
+ this.revert(el);
950
+ else
951
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('reverted', { event: name, place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_when).call(this, ev) }));
952
+ });
953
+ }
954
+ return true;
955
+ }, _CmCalendar_timeAt = function _CmCalendar_timeAt(x, y) {
956
+ const firsts = [...this.renderRoot.querySelectorAll('.tcell[data-row="0"]')];
957
+ if (!firsts.length)
958
+ return null;
959
+ let group = 0, best = Infinity;
960
+ firsts.forEach((c, i) => {
961
+ const r = c.getBoundingClientRect();
962
+ const dist = x < r.left ? r.left - x : x > r.right ? x - r.right : 0;
963
+ if (dist < best) {
964
+ best = dist;
965
+ group = Number(c.dataset.i ?? i);
966
+ }
967
+ });
968
+ const r = firsts[0].getBoundingClientRect();
969
+ return { group, min: ((y - r.top) / r.height) * 60 };
970
+ }, _CmCalendar_dayAt = function _CmCalendar_dayAt(x, y) {
971
+ const cells = [...this.renderRoot.querySelectorAll('[data-drop]')];
972
+ if (!cells.length)
973
+ return null;
974
+ let best = null, bestDist = Infinity;
975
+ for (const c of cells) {
976
+ const r = c.getBoundingClientRect();
977
+ const dx = x < r.left ? r.left - x : x > r.right ? x - r.right : 0;
978
+ const dy = y < r.top ? r.top - y : y > r.bottom ? y - r.bottom : 0;
979
+ const dist = Math.hypot(dx, dy);
980
+ if (dist < bestDist) {
981
+ bestDist = dist;
982
+ best = c;
983
+ }
984
+ }
985
+ return best ? Number(best.dataset.i) : null;
986
+ }, _CmCalendar_startDrag = function _CmCalendar_startDrag() {
987
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
988
+ d.started = true;
989
+ clearTimeout(d.timer);
990
+ getSelection()?.removeAllRanges();
991
+ this._more = '';
992
+ d.ev.el.moving = true;
993
+ this.dragging = true;
994
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('pickedUp', { event: d.ev.name, place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, d, d.from) }));
995
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_updateTarget).call(this);
996
+ const tick = () => {
997
+ if (!__classPrivateFieldGet(this, _CmCalendar_drag, "f")?.started)
998
+ return;
999
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_autoScroll).call(this);
1000
+ __classPrivateFieldGet(this, _CmCalendar_drag, "f").raf = requestAnimationFrame(tick);
1001
+ };
1002
+ d.raf = requestAnimationFrame(tick);
1003
+ }, _CmCalendar_updateTarget = function _CmCalendar_updateTarget() {
1004
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
1005
+ if (!d)
1006
+ return;
1007
+ let to = null;
1008
+ if (d.mode === 'time') {
1009
+ const at = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeAt).call(this, d.x, d.y);
1010
+ if (at) {
1011
+ const last = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_slots).call(this, d.ev.dur) - 1;
1012
+ to = { group: at.group, index: Math.max(0, Math.min(last, Math.round((at.min - d.grab) / __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get)))) };
1013
+ }
1014
+ }
1015
+ else {
1016
+ const g = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayAt).call(this, d.x, d.y);
1017
+ if (g !== null)
1018
+ to = { group: g, index: 0 };
1019
+ }
1020
+ if (!to || (to.group === d.to.group && to.index === d.to.index && this._target))
1021
+ return;
1022
+ const changedDay = to.group !== d.to.group;
1023
+ d.to = to;
1024
+ const same = to.group === d.from.group && to.index === d.from.index;
1025
+ this._target = same ? null : { iso: toISO(__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_days).call(this)[to.group]), min: d.mode === 'time' ? to.index * __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get) : undefined };
1026
+ if (changedDay)
1027
+ __classPrivateFieldGet(this, _CmCalendar_announcer, "f").announce(this.t('over', { place: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeText).call(this, d, to) }));
1028
+ }, _CmCalendar_autoScroll = function _CmCalendar_autoScroll() {
1029
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
1030
+ const tg = this.renderRoot.querySelector('.tg');
1031
+ if (!d || !tg || d.mode !== 'time')
1032
+ return;
1033
+ const EDGE = 40, MAX = 14;
1034
+ const speed = (dist) => (dist < EDGE ? Math.ceil(((EDGE - Math.max(dist, 0)) / EDGE) * MAX) : 0);
1035
+ const r = tg.getBoundingClientRect();
1036
+ if (d.x < r.left || d.x > r.right)
1037
+ return;
1038
+ const top = tg.querySelector('.tg-top')?.getBoundingClientRect().bottom ?? r.top;
1039
+ const up = speed(d.y - top), down = speed(r.bottom - d.y);
1040
+ const before = tg.scrollTop;
1041
+ if (up)
1042
+ tg.scrollTop -= up;
1043
+ else if (down)
1044
+ tg.scrollTop += down;
1045
+ if (tg.scrollTop !== before)
1046
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_updateTarget).call(this);
1047
+ }, _CmCalendar_endDrag = function _CmCalendar_endDrag(drop) {
1048
+ const d = __classPrivateFieldGet(this, _CmCalendar_drag, "f");
1049
+ if (!d)
1050
+ return;
1051
+ __classPrivateFieldSet(this, _CmCalendar_drag, null, "f");
1052
+ clearTimeout(d.timer);
1053
+ if (d.raf)
1054
+ cancelAnimationFrame(d.raf);
1055
+ window.removeEventListener('pointermove', __classPrivateFieldGet(this, _CmCalendar_onPointerMove, "f"), true);
1056
+ window.removeEventListener('pointerup', __classPrivateFieldGet(this, _CmCalendar_onPointerUp, "f"), true);
1057
+ window.removeEventListener('pointercancel', __classPrivateFieldGet(this, _CmCalendar_onPointerCancel, "f"), true);
1058
+ window.removeEventListener('touchmove', __classPrivateFieldGet(this, _CmCalendar_onTouchMove, "f"), true);
1059
+ window.removeEventListener('contextmenu', __classPrivateFieldGet(this, _CmCalendar_onContextMenu, "f"), true);
1060
+ if (!d.started)
1061
+ return;
1062
+ d.ev.el.moving = false;
1063
+ this.dragging = false;
1064
+ this._target = null;
1065
+ if (drop)
1066
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_commitPlace).call(this, d, d.from, d.to, 'pointer');
1067
+ }, _CmCalendar_add = function _CmCalendar_add(start, allDay) {
1068
+ if (this.readonly)
1069
+ return;
1070
+ this.dispatchEvent(new CustomEvent('cm-add', { detail: { start, allDay, view: __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get) }, bubbles: true, composed: true }));
1071
+ }, _CmCalendar_slotClick = function _CmCalendar_slotClick(e, iso, hour) {
1072
+ let min = hour * 60;
1073
+ // A pointer click starts at the step under the pointer; a key press at the hour.
1074
+ if (e.detail > 0) {
1075
+ const r = e.currentTarget.getBoundingClientRect();
1076
+ const within = Math.floor((((e.clientY - r.top) / r.height) * 60) / __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get)) * __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_step_get);
1077
+ min += Math.max(0, Math.min(59, within));
1078
+ }
1079
+ const h = Math.floor(min / 60), m = min % 60;
1080
+ __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_add).call(this, `${iso}T${pad(h)}:${pad(m)}`, false);
1081
+ }, _CmCalendar_open = function _CmCalendar_open(e, ev) {
1082
+ if (performance.now() < __classPrivateFieldGet(this, _CmCalendar_quietUntil, "f") || __classPrivateFieldGet(this, _CmCalendar_model, "f").active) {
1083
+ e.preventDefault();
1084
+ return;
1085
+ }
1086
+ const ok = this.dispatchEvent(new CustomEvent('cm-open', { detail: { value: ev.key, event: ev.el }, bubbles: true, composed: true, cancelable: true }));
1087
+ if (!ok)
1088
+ e.preventDefault();
1089
+ }, _CmCalendar_openMore = function _CmCalendar_openMore(iso) { this._more = iso; __classPrivateFieldSet(this, _CmCalendar_focusPop, true, "f"); }, _CmCalendar_closeMore = function _CmCalendar_closeMore(refocus) {
1090
+ const iso = this._more;
1091
+ this._more = '';
1092
+ if (refocus && iso) {
1093
+ __classPrivateFieldSet(this, _CmCalendar_focusKey, `more:${iso}`, "f");
1094
+ __classPrivateFieldSet(this, _CmCalendar_pendingFocus, { key: `more:${iso}`, until: Date.now() + 1000 }, "f");
1095
+ }
1096
+ }, _CmCalendar_activeEv = function _CmCalendar_activeEv() { return __classPrivateFieldGet(this, _CmCalendar_held, "f")?.ev ?? (__classPrivateFieldGet(this, _CmCalendar_drag, "f")?.started ? __classPrivateFieldGet(this, _CmCalendar_drag, "f").ev : null); }, _CmCalendar_chip = function _CmCalendar_chip(ev, iso, i, where, item, extra = {}) {
1097
+ const el = ev.el;
1098
+ const busy = el.pending;
1099
+ const name = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_name).call(this, ev);
1100
+ const movable = !this.readonly && !el.locked && !busy;
1101
+ const tone = ['attention', 'information', 'success', 'critical'].includes(el.tone) ? el.tone : 'neutral';
1102
+ const cls = `chip ${where} tone-${tone}${item ? ' item' : ''}${el.moving ? ' moving' : ''}${busy ? ' pending' : ''}${el.locked ? ' locked' : ''}`;
1103
+ const icon = el.icon ? html `<cm-icon name=${el.icon} size="14"></cm-icon>` : nothing;
1104
+ const time = ev.allDay ? nothing : html `<span class="tm">${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeText).call(this, ev.min)}</span>`;
1105
+ const kind = el.kind && (where !== 'month' || !el.icon) ? html `<span class="k">${el.kind}</span>` : nothing;
1106
+ const spin = busy ? html `<span class="spin" aria-hidden="true"></span>` : nothing;
1107
+ const body = where === 'time'
1108
+ ? html `<span class="lead">${icon}${time}${spin}</span><span class="h">${ev.name}</span>${kind}`
1109
+ : html `${icon}${time}<span class="h">${ev.name}</span>${kind}${spin}`;
1110
+ const label = busy ? `${name}, ${this.t('saving')}` : name;
1111
+ const desc = movable ? `${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-mv` : `${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-op`;
1112
+ const k = `ev:${ev.key}:${iso}`;
1113
+ const role = movable ? this.t('roleDescription') : nothing;
1114
+ if (el.href) {
1115
+ return html `<a class=${cls} href=${el.href} style=${extra.style ?? nothing} data-k=${k} data-ev=${ev.key} data-day=${iso} data-i=${i}
1116
+ data-row=${extra.row ?? nothing} aria-label=${label} aria-describedby=${desc} aria-roledescription=${role}
1117
+ @click=${(e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_open).call(this, e, ev)}>${body}</a>`;
1118
+ }
1119
+ return html `<button type="button" class=${cls} style=${extra.style ?? nothing} data-k=${k} data-ev=${ev.key} data-day=${iso} data-i=${i}
1120
+ data-row=${extra.row ?? nothing} aria-label=${label} aria-describedby=${desc} aria-roledescription=${role}
1121
+ @click=${(e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_open).call(this, e, ev)}>${body}</button>`;
1122
+ }, _CmCalendar_placeholder = function _CmCalendar_placeholder(ev, cls = '', style) {
1123
+ return html `<div class="ph ${cls}" style=${style ?? nothing} aria-hidden="true">${ev.name}</div>`;
1124
+ }, _CmCalendar_header = function _CmCalendar_header(days) {
1125
+ const v = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get);
1126
+ const narrowWeek = v === 'week' && this._narrow;
1127
+ const prev = v === 'month' ? this.t('previousMonth') : narrowWeek ? this.t('previousDays', { count: 3 }) : v === 'week' ? this.t('previousWeek') : this.t('previousDay');
1128
+ const next = v === 'month' ? this.t('nextMonth') : narrowWeek ? this.t('nextDays', { count: 3 }) : v === 'week' ? this.t('nextWeek') : this.t('nextDay');
1129
+ const level = Math.min(6, Math.max(1, Math.round(Number(this.headingLevel)) || 2));
1130
+ return html `<div class="head" part="header">
1131
+ <div class="nav">
1132
+ <button type="button" class="hb icon prev" aria-label=${prev} @click=${() => this.previous()}><cm-icon name="chevron-left" size="18"></cm-icon></button>
1133
+ <button type="button" class="hb today" @click=${() => this.goToToday()}>${this.t('today')}</button>
1134
+ <button type="button" class="hb icon next" aria-label=${next} @click=${() => this.next()}><cm-icon name="chevron-right" size="18"></cm-icon></button>
1135
+ </div>
1136
+ <div class="title" part="title" id="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-t" role="heading" aria-level=${level} aria-live="polite">${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_rangeLabel).call(this, days)}${this.loading
1137
+ ? html `<cm-spinner size="small" aria-hidden="true"></cm-spinner>` : nothing}</div>
1138
+ <div class="views" role="group" aria-label=${this.t('views')}>
1139
+ ${VIEWS.map((x) => html `<button type="button" class="hb" data-view=${x} aria-pressed=${x === v ? 'true' : 'false'} @click=${() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_setView).call(this, x)}>${this.t(x)}</button>`)}
1140
+ </div>
1141
+ </div>`;
1142
+ }, _CmCalendar_weekdayHeads = function _CmCalendar_weekdayHeads(compact) {
1143
+ const fmt = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_fmt_get);
1144
+ const order = Array.from({ length: 7 }, (_, i) => (i + __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_firstDay_get)) % 7);
1145
+ return html `<thead><tr>${order.map((d) => html `<th scope="col" abbr=${fmt.weekdaysLong[d]}><span aria-hidden="true">${compact ? fmt.weekdaysShort[d].slice(0, 2) : fmt.weekdaysShort[d]}</span><span class="vh">${fmt.weekdaysLong[d]}</span></th>`)}</tr></thead>`;
1146
+ }, _CmCalendar_month = function _CmCalendar_month(days, byDay) {
1147
+ const anchor = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_anchor_get);
1148
+ const today = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_todayISO_get);
1149
+ const max = Math.max(1, Math.trunc(Number(this.maxEvents)) || 3);
1150
+ const active = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_activeEv).call(this);
1151
+ const target = this._target;
1152
+ const weeks = Array.from({ length: days.length / 7 }, (_, w) => days.slice(w * 7, w * 7 + 7));
1153
+ const compact = this._narrow;
1154
+ const cell = (d, i, col) => {
1155
+ const iso = toISO(d);
1156
+ const list = byDay.get(iso) ?? [];
1157
+ const dayText = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, d);
1158
+ const cls = `${d.getMonth() !== anchor.getMonth() ? 'other' : ''} ${iso === today ? 'today' : ''} ${target?.iso === iso ? 'over' : ''}`;
1159
+ const num = html `<span class="num" aria-hidden="true">${__classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_fmt_get).day(d)}</span>`;
1160
+ if (compact) {
1161
+ const tones = list.slice(0, 3).map((ev) => (['attention', 'information', 'success', 'critical'].includes(ev.el.tone) ? ev.el.tone : 'neutral'));
1162
+ return html `<td class=${cls} data-drop data-i=${i} aria-selected=${iso === toISO(anchor) ? 'true' : 'false'} aria-current=${iso === today ? 'date' : nothing}>
1163
+ <button type="button" class="dayb item" data-k="day:${iso}" data-i=${i} data-day=${iso} aria-label=${this.t('dayEvents', { date: dayText, count: list.length })}
1164
+ @click=${() => { this.date = iso; __classPrivateFieldSet(this, _CmCalendar_focusKey, `day:${iso}`, "f"); }}>${num}<span class="dots">${tones.map((t) => html `<span class="dot tone-${t}"></span>`)}</span></button>
1165
+ </td>`;
1166
+ }
1167
+ let shown = list, hidden = 0;
1168
+ if (list.length > max) {
1169
+ shown = list.slice(0, max - 1);
1170
+ const mine = active && list.find((e) => e.key === active.key);
1171
+ if (mine && !shown.includes(mine))
1172
+ shown = [...list.slice(0, max - 2), mine];
1173
+ hidden = list.length - shown.length;
1174
+ }
1175
+ const ro = this.readonly;
1176
+ return html `<td class="${cls}${ro ? ' item' : ''}" data-drop data-i=${i} data-day=${iso} data-k=${ro ? `cell:${iso}` : nothing}
1177
+ aria-label=${ro ? this.t('dayEvents', { date: dayText, count: list.length }) : nothing} aria-current=${iso === today ? 'date' : nothing}>
1178
+ <div class="dh">${num}<span class="vh">${dayText}</span>
1179
+ ${ro ? nothing : html `<button type="button" class="add item" data-k="add:${iso}" data-i=${i} data-day=${iso} aria-label=${this.t('addOn', { date: dayText })}
1180
+ @click=${() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_add).call(this, iso, true)}><cm-icon name="plus" size="16"></cm-icon></button>`}
1181
+ </div>
1182
+ ${shown.length || (target?.iso === iso && active) ? html `<ul class="evs">
1183
+ ${shown.map((ev) => html `<li>${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_chip).call(this, ev, iso, i, 'month', true)}</li>`)}
1184
+ ${target?.iso === iso && active ? html `<li aria-hidden="true">${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeholder).call(this, active)}</li>` : nothing}
1185
+ </ul>` : nothing}
1186
+ ${hidden ? html `<button type="button" class="more item" data-k="more:${iso}" data-i=${i} data-day=${iso} aria-haspopup="dialog"
1187
+ aria-expanded=${this._more === iso ? 'true' : 'false'} aria-label=${this.t('moreLabel', { count: hidden, date: dayText })}
1188
+ @click=${() => (this._more === iso ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_closeMore).call(this, false) : __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_openMore).call(this, iso))}>${this.t('more', { count: hidden })}</button>` : nothing}
1189
+ ${this._more === iso ? html `<div class="pop ${col >= 4 ? 'end' : ''}" role="dialog" aria-label=${dayText}>
1190
+ <div class="pop-h"><span>${dayText}</span><button type="button" class="xb" aria-label=${this.t('close')} @click=${() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_closeMore).call(this, true)}><cm-icon name="close" size="16"></cm-icon></button></div>
1191
+ <ul>${list.map((ev) => html `<li>${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_chip).call(this, ev, iso, i, 'list', false)}</li>`)}</ul>
1192
+ </div>` : nothing}
1193
+ </td>`;
1194
+ };
1195
+ const table = html `<table class="month ${compact ? 'compact' : ''}" part="grid" role="grid" aria-labelledby="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-t" aria-describedby="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-gh"
1196
+ aria-busy=${this.loading ? 'true' : 'false'}>
1197
+ ${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_weekdayHeads).call(this, compact)}
1198
+ <tbody>${weeks.map((w, r) => html `<tr>${w.map((d, c) => cell(d, r * 7 + c, c))}</tr>`)}</tbody>
1199
+ </table>`;
1200
+ if (!compact)
1201
+ return table;
1202
+ const iso = toISO(anchor);
1203
+ const list = byDay.get(iso) ?? [];
1204
+ const i = days.findIndex((d) => toISO(d) === iso);
1205
+ const dayText = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, anchor);
1206
+ const level = Math.min(6, Math.max(1, Math.round(Number(this.headingLevel)) || 2) + 1);
1207
+ return html `${table}
1208
+ <section class="agenda" part="agenda" aria-labelledby="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-ag">
1209
+ <div class="ag-h">
1210
+ <div class="ag-t" id="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-ag" role="heading" aria-level=${level}>${dayText}</div>
1211
+ ${this.readonly ? nothing : html `<button type="button" class="hb ag-add" aria-label=${this.t('addOn', { date: dayText })} @click=${() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_add).call(this, iso, true)}>
1212
+ <cm-icon name="plus" size="16"></cm-icon>${this.t('add')}</button>`}
1213
+ </div>
1214
+ ${list.length
1215
+ ? html `<ul class="ag-list">${list.map((ev) => html `<li>${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_chip).call(this, ev, iso, i, 'list', false)}</li>`)}</ul>`
1216
+ : html `<p class="empty">${this.t('noEvents')}</p>`}
1217
+ </section>`;
1218
+ }, _CmCalendar_lanes = function _CmCalendar_lanes(list) {
1219
+ const out = new Map();
1220
+ const timed = list.filter((e) => !e.allDay).sort((a, b) => a.min - b.min || b.dur - a.dur);
1221
+ let cluster = [], ends = [], clusterEnd = -1;
1222
+ const close = () => { for (const e of cluster)
1223
+ out.get(e).lanes = ends.length; cluster = []; ends = []; };
1224
+ for (const e of timed) {
1225
+ const end = Math.min(1440, e.min + Math.max(e.dur, 20));
1226
+ if (e.min >= clusterEnd) {
1227
+ close();
1228
+ clusterEnd = -1;
1229
+ }
1230
+ let lane = ends.findIndex((x) => x <= e.min);
1231
+ if (lane < 0) {
1232
+ lane = ends.length;
1233
+ ends.push(end);
1234
+ }
1235
+ else
1236
+ ends[lane] = end;
1237
+ out.set(e, { lane, lanes: 1 });
1238
+ cluster.push(e);
1239
+ clusterEnd = Math.max(clusterEnd, end);
1240
+ }
1241
+ close();
1242
+ return out;
1243
+ }, _CmCalendar_timeGrid = function _CmCalendar_timeGrid(days, byDay) {
1244
+ const today = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_todayISO_get);
1245
+ const fmt = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_fmt_get);
1246
+ const active = __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_activeEv).call(this);
1247
+ const target = this._target;
1248
+ const ro = this.readonly;
1249
+ const cols = days.map((d) => {
1250
+ const iso = toISO(d);
1251
+ const list = byDay.get(iso) ?? [];
1252
+ return { d, iso, text: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_dayText).call(this, d), allDay: list.filter((e) => e.allDay), timed: list.filter((e) => !e.allDay), lanes: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_lanes).call(this, list) };
1253
+ });
1254
+ const hours = Array.from({ length: 24 }, (_, h) => h);
1255
+ return html `<div class="tg" part="grid" role="grid" aria-labelledby="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-t" aria-describedby="${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-gh" aria-busy=${this.loading ? 'true' : 'false'}
1256
+ style="--cols:${days.length}">
1257
+ <div class="tg-top" role="rowgroup">
1258
+ <div class="row" role="row">
1259
+ <div class="axis" role="columnheader"><span class="vh">${this.t('time')}</span></div>
1260
+ ${cols.map((c) => html `<div class="colh ${c.iso === today ? 'today' : ''}" role="columnheader" aria-current=${c.iso === today ? 'date' : nothing}>
1261
+ <span class="wd" aria-hidden="true">${fmt.weekdaysShort[c.d.getDay()]}</span><span class="dn" aria-hidden="true">${fmt.day(c.d)}</span><span class="vh">${c.text}</span>
1262
+ </div>`)}
1263
+ </div>
1264
+ <div class="row adrow" role="row">
1265
+ <div class="axis" role="rowheader">${this.t('allDay')}</div>
1266
+ ${cols.map((c, i) => html `<div class="adcell ${target?.iso === c.iso && active?.allDay ? 'over' : ''}" role="gridcell" data-drop data-i=${i}>
1267
+ ${ro ? nothing : html `<button type="button" class="add item" data-k="adadd:${c.iso}" data-i=${i} data-day=${c.iso} data-row="a"
1268
+ aria-label=${this.t('addAllDay', { date: c.text })} @click=${() => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_add).call(this, c.iso, true)}><cm-icon name="plus" size="16"></cm-icon></button>`}
1269
+ ${c.allDay.map((ev) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_chip).call(this, ev, c.iso, i, 'allday', true, { row: 'a' }))}
1270
+ ${target?.iso === c.iso && active?.allDay ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeholder).call(this, active) : nothing}
1271
+ </div>`)}
1272
+ </div>
1273
+ </div>
1274
+ <div class="tg-body" role="rowgroup">
1275
+ ${hours.map((h) => html `<div class="row hr" role="row">
1276
+ <div class="axis" role="rowheader"><span>${__classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_hourLabel).call(this, h)}</span></div>
1277
+ ${cols.map((c, i) => {
1278
+ const here = c.timed.filter((e) => Math.floor(e.min / 60) === h);
1279
+ const ph = active && !active.allDay && target?.iso === c.iso && target.min !== undefined && Math.floor(target.min / 60) === h;
1280
+ return html `<div class="tcell" role="gridcell" data-i=${i} data-row=${h} data-day=${c.iso}>
1281
+ ${ro ? nothing : html `<button type="button" class="slot item" data-k="slot:${c.iso}:${h}" data-i=${i} data-row=${h} data-day=${c.iso}
1282
+ aria-label=${this.t('addAt', { time: __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_timeText).call(this, h * 60), date: c.text })} @click=${(e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_slotClick).call(this, e, c.iso, h)}></button>`}
1283
+ ${here.map((ev) => {
1284
+ const l = c.lanes.get(ev) ?? { lane: 0, lanes: 1 };
1285
+ const len = Math.min(ev.dur, 1440 - ev.min) / 60;
1286
+ return __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_chip).call(this, ev, c.iso, i, 'time', true, { row: String(h), style: `--top:${(ev.min - h * 60) / 60};--len:${len};--lane:${l.lane};--lanes:${l.lanes}` });
1287
+ })}
1288
+ ${ph ? __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_placeholder).call(this, active, 'time', `--top:${(target.min - h * 60) / 60};--len:${Math.min(active.dur, 1440 - target.min) / 60}`) : nothing}
1289
+ </div>`;
1290
+ })}
1291
+ </div>`)}
1292
+ </div>
1293
+ </div>`;
1294
+ };
1295
+ CmCalendar.properties = {
1296
+ view: { reflect: true },
1297
+ date: { reflect: true },
1298
+ today: {},
1299
+ label: { string: 'label' },
1300
+ step: { type: Number },
1301
+ locale: { noAccessor: true },
1302
+ firstDayOfWeek: { type: Number, attribute: 'first-day-of-week' },
1303
+ hourCycle: { attribute: 'hour-cycle' },
1304
+ dayStart: { type: Number, attribute: 'day-start' },
1305
+ maxEvents: { type: Number, attribute: 'max-events' },
1306
+ headingLevel: { type: Number, attribute: 'heading-level' },
1307
+ loading: { type: Boolean, reflect: true },
1308
+ readonly: { type: Boolean, reflect: true },
1309
+ controlled: { type: Boolean, reflect: true },
1310
+ dragging: { type: Boolean, reflect: true },
1311
+ _narrow: { state: true },
1312
+ _more: { state: true },
1313
+ _target: { state: true },
1314
+ };
1315
+ CmCalendar.styles = [
1316
+ base,
1317
+ css `
1318
+ :host { display: block; position: relative; min-width: 0; font-size: 14px; line-height: 20px; }
1319
+ :host([dragging]) { cursor: grabbing; user-select: none; -webkit-user-select: none; }
1320
+ .cal { display: flex; flex-direction: column; gap: var(--cm-space-12); min-width: 0; }
1321
+ button { font: inherit; color: inherit; margin: 0; }
1322
+ [hidden] { display: none !important; }
1323
+ .vh {
1324
+ position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
1325
+ clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
1326
+ }
1327
+ :focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
1328
+
1329
+ /* Header */
1330
+ .head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cm-space-8) var(--cm-space-12); }
1331
+ .nav { display: flex; align-items: center; gap: 4px; }
1332
+ .title { flex: 1 1 10rem; min-width: 0; margin: 0; font-size: var(--cm-type-heading-sm-size); line-height: var(--cm-type-heading-sm-line-height); font-weight: 600; display: flex; align-items: center; gap: var(--cm-space-8); }
1333
+ .hb {
1334
+ display: inline-flex; align-items: center; justify-content: center; height: var(--cm-control-height-md); min-width: var(--cm-control-height-md); padding: 0 var(--cm-space-12);
1335
+ background: var(--cm-bg-surface); color: var(--cm-text-default); border: var(--cm-border-1) solid var(--cm-border-input);
1336
+ border-radius: var(--cm-radius-sm); cursor: pointer; white-space: nowrap;
1337
+ }
1338
+ .hb.icon { padding: 0; color: var(--cm-icon-selected); }
1339
+ .hb:hover { background: var(--cm-bg-hover); }
1340
+ .views { display: inline-flex; }
1341
+ .views .hb { border-radius: 0; }
1342
+ .views .hb:first-child { border-start-start-radius: var(--cm-radius-sm); border-end-start-radius: var(--cm-radius-sm); }
1343
+ .views .hb:last-child { border-start-end-radius: var(--cm-radius-sm); border-end-end-radius: var(--cm-radius-sm); }
1344
+ .views .hb + .hb { margin-inline-start: -1px; }
1345
+ .views .hb[aria-pressed='true'] { background: var(--cm-action-primary); color: var(--cm-action-primary-text); border-color: var(--cm-action-primary); position: relative; }
1346
+
1347
+ /* Chips */
1348
+ .chip {
1349
+ position: relative; display: flex; align-items: center; gap: 4px; width: 100%; min-width: 0; min-height: 24px; padding: 2px var(--cm-space-4);
1350
+ border: 0; border-inline-start: 3px solid var(--bar); border-radius: var(--cm-radius-xs);
1351
+ background: linear-gradient(var(--fill), var(--fill)), var(--cm-bg-surface); color: var(--cm-text-default);
1352
+ font-size: 12px; line-height: 16px; text-align: start; text-decoration: none; white-space: nowrap; overflow: hidden;
1353
+ cursor: grab; touch-action: manipulation; -webkit-touch-callout: none;
1354
+ }
1355
+ :host([readonly]) .chip, .chip.locked { cursor: pointer; }
1356
+ .chip:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 1px; z-index: 2; }
1357
+ .chip > * { flex: none; }
1358
+ .chip .h { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
1359
+ .chip .k { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
1360
+ .chip .tm { font-variant-numeric: tabular-nums; }
1361
+ .tone-neutral { --fill: var(--cm-bg-tag); --bar: var(--cm-text-tertiary); }
1362
+ .tone-attention { --fill: var(--cm-bg-attention); --bar: var(--cm-text-attention); }
1363
+ .tone-information { --fill: var(--cm-bg-information-soft); --bar: var(--cm-text-information); }
1364
+ .tone-success { --fill: var(--cm-bg-success-soft); --bar: var(--cm-text-success); }
1365
+ .tone-critical { --fill: var(--cm-bg-critical); --bar: var(--cm-text-critical); }
1366
+ .chip.moving { outline: 2px dashed var(--cm-border-strong); outline-offset: -2px; background: var(--cm-bg-page); }
1367
+ .chip.pending { background: var(--cm-bg-page); cursor: progress; }
1368
+ .spin {
1369
+ flex: none; width: 12px; height: 12px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%;
1370
+ animation: cm-cal-spin 0.8s linear infinite;
1371
+ }
1372
+ @keyframes cm-cal-spin { to { transform: rotate(360deg); } }
1373
+ @media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }
1374
+ .ph {
1375
+ display: flex; align-items: center; min-height: 24px; padding: 2px var(--cm-space-4); border: 2px dashed var(--cm-border-strong);
1376
+ border-radius: var(--cm-radius-xs); background: var(--cm-bg-surface); color: var(--cm-text-tertiary);
1377
+ font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
1378
+ }
1379
+
1380
+ /* Month */
1381
+ /* Separate borders: collapsed ones spill half a pixel outside the table (sideways scroll at 320px in WebKit). */
1382
+ .month { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-subtle); }
1383
+ .month th { padding: var(--cm-space-4) var(--cm-space-8); font-size: 12px; line-height: 16px; font-weight: 500; color: var(--cm-text-tertiary); text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1384
+ .month td {
1385
+ position: relative; vertical-align: top; height: var(--cm-calendar-day-height, 112px); padding: 4px;
1386
+ border: 0; border-block-start: var(--cm-border-1) solid var(--cm-border-subtle); border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle);
1387
+ background: var(--cm-bg-surface);
1388
+ }
1389
+ .month td:first-child { border-inline-start: 0; }
1390
+ .month td.other { background: var(--cm-bg-page); }
1391
+ .month td.over { box-shadow: inset 0 0 0 2px var(--cm-border-strong); }
1392
+ .dh { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-height: 28px; }
1393
+ .num {
1394
+ display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: var(--cm-radius-full);
1395
+ font-size: 12px; line-height: 16px; font-weight: 500;
1396
+ }
1397
+ .other .num { color: var(--cm-text-tertiary); }
1398
+ .today .num, .colh.today .dn { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
1399
+ .add, .xb {
1400
+ display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: var(--cm-radius-sm);
1401
+ background: none; color: var(--cm-icon-selected); cursor: pointer;
1402
+ }
1403
+ .add:hover, .xb:hover { background: var(--cm-bg-hover); }
1404
+ @media (hover: hover) {
1405
+ .month td:not(:hover) .add:not(:focus-visible), .adcell:not(:hover) .add:not(:focus-visible) { opacity: 0; }
1406
+ }
1407
+ .evs { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
1408
+ .evs li { display: block; min-width: 0; }
1409
+ .more {
1410
+ display: block; width: 100%; min-height: 24px; margin-block-start: 2px; padding: 2px var(--cm-space-4); border: 0; border-radius: var(--cm-radius-xs);
1411
+ background: none; color: var(--cm-text-default); font-size: 12px; line-height: 16px; font-weight: 500; text-align: start; cursor: pointer;
1412
+ }
1413
+ .more:hover { background: var(--cm-bg-hover); text-decoration: underline; }
1414
+ .pop {
1415
+ position: absolute; z-index: 5; inset-block-start: 0; inset-inline-start: 0; width: max(100%, 15rem); max-width: 80vw;
1416
+ padding: var(--cm-space-8); background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-subtle);
1417
+ border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-md);
1418
+ }
1419
+ .pop.end { inset-inline-start: auto; inset-inline-end: 0; }
1420
+ .pop-h { display: flex; align-items: center; justify-content: space-between; gap: var(--cm-space-8); margin-block-end: var(--cm-space-4); font-size: 14px; font-weight: 500; }
1421
+ .pop ul, .ag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
1422
+ .chip.list { min-height: 40px; padding: var(--cm-space-4) var(--cm-space-8); flex-wrap: wrap; column-gap: var(--cm-space-8); row-gap: 0; white-space: normal; font-size: 14px; line-height: 20px; }
1423
+ .chip.list .h { flex: 1 1 8rem; overflow-wrap: anywhere; }
1424
+ .chip.list .k { font-size: 12px; }
1425
+
1426
+ /* Narrow month: a compact grid and the day's list */
1427
+ .month.compact td { height: auto; padding: 2px; }
1428
+ .month.compact th { padding: 4px 2px; text-align: center; }
1429
+ .dayb {
1430
+ display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; min-height: 44px; padding: 4px 0;
1431
+ border: 0; border-radius: var(--cm-radius-sm); background: none; cursor: pointer;
1432
+ }
1433
+ .dayb:hover { background: var(--cm-bg-hover); }
1434
+ td[aria-selected='true'] .num { box-shadow: 0 0 0 2px var(--cm-border-strong); }
1435
+ .dots { display: flex; gap: 2px; height: 6px; } /* scale-exempt: event dots are a mark, not a layout size */
1436
+ .dot { width: 6px; height: 6px; /* scale-exempt: event dot */ border-radius: var(--cm-radius-full); background: var(--bar); }
1437
+ .agenda { display: flex; flex-direction: column; gap: var(--cm-space-8); }
1438
+ .ag-h { display: flex; align-items: center; justify-content: space-between; gap: var(--cm-space-8); }
1439
+ .ag-t { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; }
1440
+ .empty { margin: 0; padding: var(--cm-space-12) 0; color: var(--cm-text-tertiary); font-size: 14px; }
1441
+
1442
+ /* Week and day */
1443
+ .tg {
1444
+ --h: var(--cm-calendar-hour-height, 48px); --axis: 56px;
1445
+ position: relative; max-block-size: var(--cm-calendar-time-height, 600px); overflow-y: auto; overscroll-behavior: contain;
1446
+ border: var(--cm-border-1) solid var(--cm-border-subtle); border-radius: var(--cm-radius-md); background: var(--cm-bg-surface);
1447
+ scroll-padding-block-start: 104px;
1448
+ }
1449
+ .narrow .tg { --axis: 44px; }
1450
+ .row { display: grid; grid-template-columns: var(--axis) repeat(var(--cols), minmax(0, 1fr)); }
1451
+ .tg-top { position: sticky; inset-block-start: 0; z-index: 4; background: var(--cm-bg-surface); border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); }
1452
+ .colh { padding: var(--cm-space-4) 2px; text-align: center; font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); min-width: 0; overflow: hidden; }
1453
+ .colh .dn { display: inline-grid; place-items: center; min-width: 28px; height: 28px; margin-block-start: 2px; padding: 0 4px; border-radius: var(--cm-radius-full); font-size: 16px; line-height: 24px; font-weight: 500; color: var(--cm-text-default); }
1454
+ .colh .wd { display: block; }
1455
+ .axis { padding-inline-end: var(--cm-space-8); font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); text-align: end; }
1456
+ .adrow .axis { align-self: center; padding-block: 4px; overflow-wrap: anywhere; }
1457
+ .adcell { position: relative; display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 4px; min-height: 36px; border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); }
1458
+ .adcell.over { box-shadow: inset 0 0 0 2px var(--cm-border-strong); }
1459
+ .adcell .add { align-self: flex-end; width: 24px; height: 24px; }
1460
+ .hr .axis span { position: relative; inset-block-start: -8px; }
1461
+ .hr:first-child .axis span { inset-block-start: 0; }
1462
+ .tcell { position: relative; block-size: var(--h); min-width: 0; border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); border-block-start: var(--cm-border-1) solid var(--cm-border-subtle); }
1463
+ .hr:first-child .tcell { border-block-start: 0; }
1464
+ .slot { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; color: var(--cm-icon-selected); font-size: 16px; line-height: 1; }
1465
+
1466
+ .slot:hover { background: var(--cm-bg-hover); }
1467
+ .slot:hover::after, .slot:focus-visible::after { content: '+'; }
1468
+ .slot:focus-visible { outline-offset: -2px; }
1469
+ .chip.time {
1470
+ position: absolute; z-index: 1; flex-direction: column; align-items: stretch; gap: 0; padding: 2px 4px;
1471
+ inset-inline-start: calc(var(--lane) * 100% / var(--lanes)); width: calc(100% / var(--lanes) - 2px);
1472
+ inset-block-start: calc(var(--top) * var(--h)); height: calc(var(--len) * var(--h) - 1px); min-height: 24px;
1473
+ box-shadow: 0 0 0 1px var(--cm-bg-surface);
1474
+ }
1475
+ .chip.time > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1476
+ .chip.time .lead { display: flex; align-items: center; gap: 4px; min-width: 0; }
1477
+ .ph.time { position: absolute; z-index: 3; inset-inline: 0 2px; inset-block-start: calc(var(--top) * var(--h)); height: calc(var(--len) * var(--h)); align-items: flex-start; }
1478
+ `,
1479
+ ];
1480
+ define('cm-calendar', CmCalendar);