@klinking/colander 0.0.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 (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. package/src/weeks-view.tsx +127 -0
@@ -0,0 +1,4860 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let react = require("react");
24
+ react = __toESM(react);
25
+ let react_jsx_runtime = require("react/jsx-runtime");
26
+ let _base_ui_react_merge_props = require("@base-ui/react/merge-props");
27
+ let _base_ui_react_use_render = require("@base-ui/react/use-render");
28
+ //#region src/calendar-context.ts
29
+ /** @internal React context carrying stable CalendarProvider values (callbacks, config). */
30
+ const CalendarStableContext = (0, react.createContext)(null);
31
+ /** @internal React context carrying volatile CalendarProvider state. */
32
+ const CalendarStateContext = (0, react.createContext)(null);
33
+ /** Returns the stable (callbacks/config) part of CalendarProvider context. */
34
+ function useCalendarStable() {
35
+ const ctx = (0, react.useContext)(CalendarStableContext);
36
+ if (!ctx) throw new Error("useCalendarStable must be used within CalendarProvider");
37
+ return ctx;
38
+ }
39
+ /** Returns the volatile state part of CalendarProvider context. */
40
+ function useCalendarState() {
41
+ const ctx = (0, react.useContext)(CalendarStateContext);
42
+ if (!ctx) throw new Error("useCalendarState must be used within CalendarProvider");
43
+ return ctx;
44
+ }
45
+ //#endregion
46
+ //#region src/utils.ts
47
+ /**
48
+ * Returns the default calendar system for a given locale (e.g. `"gregory"` for `"en-US"`).
49
+ *
50
+ * @param locale - A BCP 47 locale string. Falls back to the runtime default when empty.
51
+ */
52
+ function calendarForLocale(locale) {
53
+ return new Intl.DateTimeFormat(locale || void 0).resolvedOptions().calendar;
54
+ }
55
+ /**
56
+ * Resolves a {@link TemporalNamespace} instance.
57
+ *
58
+ * Returns `provided` when given, otherwise checks `globalThis.Temporal`.
59
+ * Throws if neither is available.
60
+ *
61
+ * @param provided - An explicit Temporal polyfill or namespace.
62
+ */
63
+ function resolveTemporal(provided) {
64
+ if (provided) return provided;
65
+ if (typeof globalThis !== "undefined" && globalThis.Temporal) return globalThis.Temporal;
66
+ throw new Error("DatePicker: Temporal is not available. Pass a Temporal polyfill via the `temporal` prop, or use a browser that supports the Temporal API natively.");
67
+ }
68
+ /**
69
+ * Returns the IANA time zone identifier of the host environment (e.g. `"America/New_York"`).
70
+ *
71
+ * @param T - Temporal namespace.
72
+ */
73
+ function getSystemTimeZone(T) {
74
+ return T.Now.timeZoneId();
75
+ }
76
+ /**
77
+ * Converts any {@link DateValueObject} into a `Temporal.ZonedDateTime`.
78
+ *
79
+ * Handles all supported value formats (`PlainDate`, `PlainDateTime`,
80
+ * `PlainMonthDay`, `PlainTime`, `PlainYearMonth`, `ZonedDateTime`,
81
+ * `object`, and `Date`). For partial types (`PlainMonthDay`, `PlainTime`)
82
+ * the missing components are filled from the current date/time.
83
+ *
84
+ * @param tagged - The tagged date value to convert.
85
+ * @param timeZone - IANA time zone used for the resulting `ZonedDateTime`.
86
+ * @param T - Temporal namespace.
87
+ */
88
+ function toZonedDateTime(tagged, timeZone, T) {
89
+ const now = T.Now.zonedDateTimeISO(timeZone);
90
+ switch (tagged.format) {
91
+ case "PlainDate": return tagged.value.toZonedDateTime(timeZone);
92
+ case "PlainDateTime": return tagged.value.toZonedDateTime(timeZone);
93
+ case "PlainMonthDay": return tagged.value.toPlainDate({ year: now.year }).toZonedDateTime(timeZone);
94
+ case "PlainTime": return now.toPlainDate().toPlainDateTime(tagged.value).toZonedDateTime(timeZone);
95
+ case "PlainYearMonth": return tagged.value.toPlainDate({ day: 1 }).toZonedDateTime(timeZone);
96
+ case "ZonedDateTime": return tagged.value;
97
+ case "object": {
98
+ const obj = tagged.value;
99
+ return T.PlainDateTime.from({
100
+ year: obj.year ?? now.year,
101
+ month: obj.month ?? now.month,
102
+ day: obj.day ?? now.day,
103
+ hour: obj.hour ?? 0,
104
+ minute: obj.minute ?? 0,
105
+ second: obj.second ?? 0
106
+ }).toZonedDateTime(obj.timeZone ?? timeZone);
107
+ }
108
+ case "Date": {
109
+ const d = tagged.value;
110
+ return T.PlainDateTime.from({
111
+ year: d.getFullYear(),
112
+ month: d.getMonth() + 1,
113
+ day: d.getDate(),
114
+ hour: d.getHours(),
115
+ minute: d.getMinutes(),
116
+ second: d.getSeconds()
117
+ }).toZonedDateTime(timeZone);
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ * Converts a `Temporal.ZonedDateTime` back into a {@link DateValueObject}
123
+ * of the requested format.
124
+ *
125
+ * This is the inverse of {@link toZonedDateTime}.
126
+ *
127
+ * @param zdt - The zoned date-time to convert from.
128
+ * @param format - The target {@link ValueFormat}.
129
+ * @param T - Temporal namespace.
130
+ */
131
+ function fromZonedDateTime(zdt, format, T) {
132
+ switch (format) {
133
+ case "PlainDate": return {
134
+ format,
135
+ value: zdt.toPlainDate()
136
+ };
137
+ case "PlainDateTime": return {
138
+ format,
139
+ value: zdt.toPlainDateTime()
140
+ };
141
+ case "PlainMonthDay": return {
142
+ format,
143
+ value: T.PlainMonthDay.from({
144
+ month: zdt.month,
145
+ day: zdt.day
146
+ })
147
+ };
148
+ case "PlainTime": return {
149
+ format,
150
+ value: zdt.toPlainTime()
151
+ };
152
+ case "PlainYearMonth": return {
153
+ format,
154
+ value: T.PlainYearMonth.from({
155
+ year: zdt.year,
156
+ month: zdt.month
157
+ })
158
+ };
159
+ case "ZonedDateTime": return {
160
+ format,
161
+ value: zdt
162
+ };
163
+ case "object": return {
164
+ format,
165
+ value: {
166
+ year: zdt.year,
167
+ month: zdt.month,
168
+ day: zdt.day,
169
+ hour: zdt.hour,
170
+ minute: zdt.minute,
171
+ second: zdt.second,
172
+ timeZone: zdt.timeZoneId
173
+ }
174
+ };
175
+ case "Date": return {
176
+ format,
177
+ value: new Date(zdt.epochMilliseconds)
178
+ };
179
+ }
180
+ }
181
+ /**
182
+ * Convenience wrapper around {@link toZonedDateTime} that accepts `undefined`.
183
+ *
184
+ * Returns `undefined` when `selected` is not provided, otherwise converts to
185
+ * a `Temporal.ZonedDateTime`.
186
+ *
187
+ * @param selected - The currently selected value, or `undefined`.
188
+ * @param timeZone - IANA time zone.
189
+ * @param T - Temporal namespace.
190
+ */
191
+ function selectedToZdt(selected, timeZone, T) {
192
+ if (!selected) return void 0;
193
+ return toZonedDateTime(selected, timeZone, T);
194
+ }
195
+ /**
196
+ * Builds a 2D array of calendar weeks for a given month.
197
+ *
198
+ * Each inner array has exactly `daysInWeek` entries. The grid is padded
199
+ * with days from adjacent months so every week is complete.
200
+ *
201
+ * @param year - Calendar year.
202
+ * @param month - Calendar month (1–12).
203
+ * @param T - Temporal namespace.
204
+ * @param opts - Optional settings for week start day and fixed weeks.
205
+ * @returns An array of 4–6 weeks, each containing `daysInWeek` `PlainDate` values.
206
+ */
207
+ function getMonthWeeks(year, month, T, opts) {
208
+ const weekStartDay = opts?.weekStartDay ?? 0;
209
+ const fixedWeeks = opts?.fixedWeeks ?? false;
210
+ const firstOfMonth = T.PlainDate.from({
211
+ year,
212
+ month,
213
+ day: 1
214
+ });
215
+ const daysInWeek = firstOfMonth.daysInWeek;
216
+ const daysInMonth = firstOfMonth.daysInMonth;
217
+ const lastOfMonth = T.PlainDate.from({
218
+ year,
219
+ month,
220
+ day: daysInMonth
221
+ });
222
+ const adjustedFirst = (firstOfMonth.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek;
223
+ const gridStart = firstOfMonth.subtract({ days: adjustedFirst });
224
+ const adjustedLast = (lastOfMonth.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek;
225
+ const daysAfter = daysInWeek - 1 - adjustedLast;
226
+ const gridEnd = lastOfMonth.add({ days: daysAfter });
227
+ const weeks = [];
228
+ let current = gridStart;
229
+ while (T.PlainDate.compare(current, gridEnd) <= 0) {
230
+ const week = [];
231
+ for (let i = 0; i < daysInWeek; i++) {
232
+ week.push(current);
233
+ current = current.add({ days: 1 });
234
+ }
235
+ weeks.push(week);
236
+ }
237
+ if (fixedWeeks) while (weeks.length < 6) {
238
+ const week = [];
239
+ for (let i = 0; i < daysInWeek; i++) {
240
+ week.push(current);
241
+ current = current.add({ days: 1 });
242
+ }
243
+ weeks.push(week);
244
+ }
245
+ return weeks;
246
+ }
247
+ /**
248
+ * Converts a `Temporal.ZonedDateTime` to a native JavaScript `Date`.
249
+ *
250
+ * @param zdt - The zoned date-time to convert.
251
+ */
252
+ function zdtToNativeDate(zdt) {
253
+ return new Date(zdt.epochMilliseconds);
254
+ }
255
+ /**
256
+ * Returns a date falling on the configured week start day, used as an anchor
257
+ * for generating weekday name lists.
258
+ *
259
+ * @param T - Temporal namespace.
260
+ * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
261
+ */
262
+ function getReferenceWeekStart(T, weekStartDay = 0) {
263
+ return T.PlainDate.from("2024-01-07").add({ days: weekStartDay });
264
+ }
265
+ /**
266
+ * Computes the year/month and first day of the month adjacent to `current`.
267
+ *
268
+ * Handles year boundaries (e.g. Dec → Jan, Jan → Dec).
269
+ *
270
+ * @param current - The reference month.
271
+ * @param direction - `"next"` or `"prev"`.
272
+ * @param T - Temporal namespace.
273
+ */
274
+ function computeAdjacentMonth(current, direction, T) {
275
+ const d = T.PlainDate.from({
276
+ year: current.year,
277
+ month: current.month,
278
+ day: 1
279
+ })[direction === "next" ? "add" : "subtract"]({ months: 1 });
280
+ return {
281
+ year: d.year,
282
+ month: d.month,
283
+ firstDay: d
284
+ };
285
+ }
286
+ /**
287
+ * Determines the focused date after navigating to a new month.
288
+ *
289
+ * If `currentFocused` is already within `targetMonth`, it is preserved.
290
+ * Otherwise, `firstDay` of the target month is returned.
291
+ *
292
+ * @param currentFocused - The currently focused date.
293
+ * @param targetMonth - The month being navigated to.
294
+ * @param firstDay - The first day of the target month (fallback).
295
+ */
296
+ function focusedDateForMonth(currentFocused, targetMonth, firstDay) {
297
+ if (currentFocused.year === targetMonth.year && currentFocused.month === targetMonth.month) return currentFocused;
298
+ return firstDay;
299
+ }
300
+ /**
301
+ * Resolves which date should receive focus/tabindex in the calendar grid.
302
+ *
303
+ * Priority when `gridHasFocus` is `true` (keyboard navigation):
304
+ * 1. `focusedDate` if it exists in the grid.
305
+ * 2. `selectedDate` if it exists in the grid.
306
+ * 3. First enabled day of `currentMonth`, or first grid day as last resort.
307
+ *
308
+ * When `gridHasFocus` is `false` (tab-in), `selectedDate` takes priority
309
+ * over `focusedDate`.
310
+ *
311
+ * @param focusedDate - The date currently tracked as focused.
312
+ * @param selectedDate - The currently selected date, if any.
313
+ * @param weeks - The 2D weeks array from {@link getMonthWeeks}.
314
+ * @param currentMonth - The month being displayed.
315
+ * @param isDateDisabled - Predicate for disabled dates.
316
+ * @param T - Temporal namespace.
317
+ * @param gridHasFocus - Whether the grid currently holds DOM focus.
318
+ */
319
+ function resolveFocusTarget(focusedDate, selectedDate, weeks, currentMonth, isDateDisabled, T, gridHasFocus = true) {
320
+ const allDays = weeks.flat();
321
+ const inGrid = (d) => allDays.some((g) => T.PlainDate.compare(g, d) === 0);
322
+ if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
323
+ if (selectedDate && inGrid(selectedDate)) return selectedDate;
324
+ if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
325
+ return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0];
326
+ }
327
+ /**
328
+ * Determines whether a day cell should imperatively receive DOM focus.
329
+ *
330
+ * Only returns `true` when the cell is the focused date **and** the grid
331
+ * currently holds DOM focus (i.e. keyboard navigation is active).
332
+ *
333
+ * @param isFocused - Whether this cell is the logically focused date.
334
+ * @param gridHasFocus - Whether the grid currently holds DOM focus.
335
+ */
336
+ function shouldMoveDomFocus(isFocused, gridHasFocus) {
337
+ return isFocused && gridHasFocus;
338
+ }
339
+ /**
340
+ * Returns the normalized position of `date` within the inclusive range
341
+ * `[rangeStart, rangeEnd]` as a number from `0` (start) to `1` (end),
342
+ * or `false` if the date is outside the range.
343
+ * A single-day range returns `0` for that date.
344
+ *
345
+ * @param date - The date to test.
346
+ * @param rangeStart - Start of the range (inclusive). When `undefined` and `rangeEnd` is defined, the range collapses to a single-day range at `rangeEnd`.
347
+ * @param rangeEnd - End of the range (inclusive). When `undefined` and `rangeStart` is defined, the range collapses to a single-day range at `rangeStart`. Returns `false` when both boundaries are `undefined`.
348
+ * @param T - Temporal namespace used for date comparison.
349
+ */
350
+ function isInRange(date, rangeStart, rangeEnd, T) {
351
+ if (!rangeStart && !rangeEnd) return false;
352
+ const effectiveStart = rangeStart ?? rangeEnd;
353
+ const effectiveEnd = rangeEnd ?? rangeStart;
354
+ if (T.PlainDate.compare(date, effectiveStart) < 0 || T.PlainDate.compare(date, effectiveEnd) > 0) return false;
355
+ const totalDays = effectiveEnd.since(effectiveStart).days;
356
+ if (totalDays === 0) return 0;
357
+ return date.since(effectiveStart).days / totalDays;
358
+ }
359
+ /**
360
+ * Computes how a date range intersects with a single calendar week row.
361
+ *
362
+ * Used to position and style the range highlight overlay within a week.
363
+ *
364
+ * @param weekDays - Array of 7 `PlainDate` values for the week (Sun–Sat).
365
+ * @param rangeStart - Start of the selected range, or `undefined`.
366
+ * @param rangeEnd - End of the selected range, or `undefined`.
367
+ * @param T - Temporal namespace.
368
+ * @returns An object with `active` (whether the range overlaps this week),
369
+ * `startIndex` / `endIndex` (0-based column positions), and
370
+ * `extendsBefore` / `extendsAfter` (whether the range continues beyond the week).
371
+ */
372
+ function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
373
+ const inactive = {
374
+ active: false,
375
+ startIndex: 0,
376
+ endIndex: 0,
377
+ extendsBefore: false,
378
+ extendsAfter: false
379
+ };
380
+ if (weekDays.length === 0) return inactive;
381
+ if (!rangeStart && !rangeEnd) return inactive;
382
+ const effectiveStart = rangeStart ?? rangeEnd;
383
+ const effectiveEnd = rangeEnd ?? rangeStart;
384
+ const weekStart = weekDays[0];
385
+ const weekEnd = weekDays[weekDays.length - 1];
386
+ if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return inactive;
387
+ const extendsBefore = T.PlainDate.compare(effectiveStart, weekStart) < 0;
388
+ const extendsAfter = T.PlainDate.compare(effectiveEnd, weekEnd) > 0;
389
+ let startIndex = 0;
390
+ if (!extendsBefore) {
391
+ startIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveStart) === 0);
392
+ if (startIndex === -1) return inactive;
393
+ }
394
+ let endIndex = weekDays.length - 1;
395
+ if (!extendsAfter) {
396
+ endIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveEnd) === 0);
397
+ if (endIndex === -1) return inactive;
398
+ }
399
+ return {
400
+ active: true,
401
+ startIndex,
402
+ endIndex,
403
+ extendsBefore,
404
+ extendsAfter
405
+ };
406
+ }
407
+ /**
408
+ * Generates localized weekday names starting from the configured week start day.
409
+ *
410
+ * @param locale - BCP 47 locale string (e.g. `"en-US"`).
411
+ * @param T - Temporal namespace.
412
+ * @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
413
+ * @returns An array of 7 objects with `long`, `short`, and `narrow` name variants.
414
+ */
415
+ function getWeekdayNames(locale, T, weekStartDay = 0) {
416
+ const refStart = getReferenceWeekStart(T, weekStartDay);
417
+ const daysInWeek = refStart.daysInWeek;
418
+ const names = [];
419
+ for (let i = 0; i < daysInWeek; i++) {
420
+ const date = refStart.add({ days: i });
421
+ names.push({
422
+ long: date.toLocaleString(locale, { weekday: "long" }),
423
+ short: date.toLocaleString(locale, { weekday: "short" }),
424
+ narrow: date.toLocaleString(locale, { weekday: "narrow" })
425
+ });
426
+ }
427
+ return names;
428
+ }
429
+ /**
430
+ * Computes the ISO 8601 week number for a given date.
431
+ *
432
+ * The ISO week number is determined by the Thursday of the date's ISO week.
433
+ *
434
+ * @param date - The date to compute the week number for.
435
+ * @param T - Temporal namespace.
436
+ */
437
+ function getISOWeekNumber(date, T) {
438
+ const thursday = date.add({ days: 4 - date.dayOfWeek });
439
+ const jan4 = T.PlainDate.from({
440
+ year: thursday.year,
441
+ month: 1,
442
+ day: 4
443
+ });
444
+ const jan4Thursday = jan4.add({ days: 4 - jan4.dayOfWeek });
445
+ const daysDiff = thursday.since(jan4Thursday, { largestUnit: "days" }).days;
446
+ return Math.round(daysDiff / 7) + 1;
447
+ }
448
+ //#endregion
449
+ //#region src/root-selection.ts
450
+ /** Construct a DateRange (workaround for TS generic conditional type widening). */
451
+ function mkRange(start, end) {
452
+ return {
453
+ start,
454
+ end
455
+ };
456
+ }
457
+ function isDateRange(v) {
458
+ return v != null && typeof v === "object" && "start" in v && "end" in v;
459
+ }
460
+ function tagRaw(raw, format) {
461
+ if (raw == null) return void 0;
462
+ return {
463
+ format,
464
+ value: raw
465
+ };
466
+ }
467
+ /** Resolve a `RangeMode` to a concrete "start" | "end" | "reset" action for inside-range clicks. */
468
+ function resolveInsideAction(mode, date, start, end) {
469
+ if (mode === "adjust-start") return "start";
470
+ if (mode === "adjust-end") return "end";
471
+ if (mode === "reset") return "reset";
472
+ const daysFromStart = Math.abs(date.since(start).days);
473
+ const daysFromEnd = Math.abs(date.since(end).days);
474
+ if (daysFromStart < daysFromEnd) return "start";
475
+ if (daysFromEnd < daysFromStart) return "end";
476
+ return mode === "nearest-start" ? "start" : "end";
477
+ }
478
+ /** Compute what `onSelect(date)` should do, without touching React state. */
479
+ function computeSelectionUpdate(opts) {
480
+ const { date, readOnly, isDateDisabled, isMultiple, isRange, committedDates, committedStart, committedEnd, selectedZdt, rangeMode, allowRangeReversal, sortDates, currentSingleFormatted, currentRangeFormatted, currentMultipleFormatted, resolvedFormat, timeZone, T } = opts;
481
+ if (readOnly) return { skip: true };
482
+ if (isDateDisabled(date)) return { skip: true };
483
+ if (isMultiple) {
484
+ const dates = committedDates.filter((d) => d != null);
485
+ const prevArr = currentMultipleFormatted();
486
+ const idx = dates.findIndex((d) => T.PlainDate.compare(d, date) === 0);
487
+ let newDates;
488
+ if (idx >= 0) newDates = [...dates.slice(0, idx), ...dates.slice(idx + 1)];
489
+ else newDates = sortDates([...dates, date]);
490
+ return {
491
+ newDates,
492
+ fireCallback: (onValueChange, plainToFormatValue) => {
493
+ onValueChange?.(newDates.map(plainToFormatValue), {
494
+ date,
495
+ previous: prevArr
496
+ });
497
+ }
498
+ };
499
+ }
500
+ if (isRange && rangeMode === "start-end") {
501
+ const prevRange = currentRangeFormatted();
502
+ const isPending = committedDates.length === 2 && (committedDates[0] === null || committedDates[1] === null);
503
+ const isComplete = committedDates.length === 2 && committedDates[0] != null && committedDates[1] != null;
504
+ if (committedDates.length === 0) return {
505
+ newDates: [date, null],
506
+ fireCallback: (onValueChange, plainToFormatValue) => {
507
+ onValueChange?.(mkRange(plainToFormatValue(date), null), {
508
+ date,
509
+ previous: prevRange
510
+ });
511
+ }
512
+ };
513
+ if (isPending && committedDates[0] != null && committedDates[1] === null) {
514
+ const start = committedDates[0];
515
+ if (T.PlainDate.compare(date, start) === 0) return {
516
+ newDates: [date, date],
517
+ fireCallback: (onValueChange, plainToFormatValue) => {
518
+ onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(date)), {
519
+ date,
520
+ previous: prevRange
521
+ });
522
+ }
523
+ };
524
+ if (T.PlainDate.compare(date, start) >= 0) return {
525
+ newDates: [start, date],
526
+ fireCallback: (onValueChange, plainToFormatValue) => {
527
+ onValueChange?.(mkRange(plainToFormatValue(start), plainToFormatValue(date)), {
528
+ date,
529
+ previous: prevRange
530
+ });
531
+ }
532
+ };
533
+ if (allowRangeReversal) return {
534
+ newDates: [date, start],
535
+ fireCallback: (onValueChange, plainToFormatValue) => {
536
+ onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(start)), {
537
+ date,
538
+ previous: prevRange
539
+ });
540
+ }
541
+ };
542
+ return {
543
+ newDates: [start, start],
544
+ fireCallback: (onValueChange, plainToFormatValue) => {
545
+ onValueChange?.(mkRange(plainToFormatValue(start), plainToFormatValue(start)), {
546
+ date,
547
+ previous: prevRange
548
+ });
549
+ }
550
+ };
551
+ }
552
+ if (isComplete) {
553
+ const start = committedDates[0];
554
+ const end = committedDates[1];
555
+ const isOnStart = T.PlainDate.compare(date, start) === 0;
556
+ const isOnEnd = T.PlainDate.compare(date, end) === 0;
557
+ if (isOnStart || isOnEnd) return {
558
+ newDates: [],
559
+ fireCallback: (onValueChange) => {
560
+ onValueChange?.(null, {
561
+ date,
562
+ previous: prevRange
563
+ });
564
+ }
565
+ };
566
+ return {
567
+ newDates: [date, null],
568
+ fireCallback: (onValueChange, plainToFormatValue) => {
569
+ onValueChange?.(mkRange(plainToFormatValue(date), null), {
570
+ date,
571
+ previous: prevRange
572
+ });
573
+ }
574
+ };
575
+ }
576
+ return { skip: true };
577
+ }
578
+ if (isRange && committedStart && committedEnd) {
579
+ const prevRange = currentRangeFormatted();
580
+ const isSingleDay = T.PlainDate.compare(committedStart, committedEnd) === 0;
581
+ if (isSingleDay && T.PlainDate.compare(date, committedStart) === 0) return {
582
+ newDates: [],
583
+ fireCallback: (onValueChange) => {
584
+ onValueChange?.(null, {
585
+ date,
586
+ previous: prevRange
587
+ });
588
+ }
589
+ };
590
+ if (!isSingleDay) {
591
+ const isOnStart = T.PlainDate.compare(date, committedStart) === 0;
592
+ const isOnEnd = T.PlainDate.compare(date, committedEnd) === 0;
593
+ if (isOnStart || isOnEnd) return {
594
+ newDates: [date, date],
595
+ fireCallback: (onValueChange, plainToFormatValue) => {
596
+ onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(date)), {
597
+ date,
598
+ previous: prevRange
599
+ });
600
+ }
601
+ };
602
+ }
603
+ const beforeStart = T.PlainDate.compare(date, committedStart) < 0;
604
+ const afterEnd = T.PlainDate.compare(date, committedEnd) > 0;
605
+ let newDates;
606
+ if (beforeStart) newDates = [date, committedEnd];
607
+ else if (afterEnd) newDates = [committedStart, date];
608
+ else {
609
+ const action = resolveInsideAction(rangeMode, date, committedStart, committedEnd);
610
+ if (action === "start") newDates = [date, committedEnd];
611
+ else if (action === "end") newDates = [committedStart, date];
612
+ else newDates = [date, date];
613
+ }
614
+ return {
615
+ newDates,
616
+ fireCallback: (onValueChange, plainToFormatValue) => {
617
+ onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
618
+ date,
619
+ previous: prevRange
620
+ });
621
+ }
622
+ };
623
+ }
624
+ if (isRange) {
625
+ const prevRange = currentRangeFormatted();
626
+ const newDates = [date, date];
627
+ return {
628
+ newDates,
629
+ fireCallback: (onValueChange, plainToFormatValue) => {
630
+ onValueChange?.(mkRange(plainToFormatValue(newDates[0]), plainToFormatValue(newDates[1])), {
631
+ date,
632
+ previous: prevRange
633
+ });
634
+ }
635
+ };
636
+ }
637
+ const prevSingle = currentSingleFormatted();
638
+ if (committedDates.length === 1 && committedDates[0] != null && T.PlainDate.compare(committedDates[0], date) === 0) return {
639
+ newDates: [],
640
+ fireCallback: (onValueChange) => {
641
+ onValueChange?.(null, {
642
+ date,
643
+ previous: prevSingle
644
+ });
645
+ }
646
+ };
647
+ return {
648
+ newDates: [date],
649
+ fireCallback: (onValueChange) => {
650
+ const prevTime = selectedZdt ? {
651
+ hour: selectedZdt.hour,
652
+ minute: selectedZdt.minute,
653
+ second: selectedZdt.second
654
+ } : {
655
+ hour: 0,
656
+ minute: 0,
657
+ second: 0
658
+ };
659
+ const newTagged = fromZonedDateTime(date.toPlainDateTime(prevTime).toZonedDateTime(timeZone), resolvedFormat, T);
660
+ onValueChange?.(newTagged.value, {
661
+ date,
662
+ previous: prevSingle
663
+ });
664
+ }
665
+ };
666
+ }
667
+ /** Compute what `setRange(start, end)` should do, without touching React state. */
668
+ function computeSetRangeUpdate(opts) {
669
+ const { start, end, readOnly, isMultiple, isRange, currentRangeFormatted, currentSingleFormatted, resolvedFormat, timeZone, T } = opts;
670
+ if (readOnly || isMultiple) return { skip: true };
671
+ const [lo, hi] = T.PlainDate.compare(start, end) <= 0 ? [start, end] : [end, start];
672
+ const effectiveEnd = isRange ? hi : lo;
673
+ return {
674
+ newDates: isRange ? [lo, effectiveEnd] : [lo],
675
+ fireCallback: (onValueChange, plainToFormatValue) => {
676
+ if (isRange) {
677
+ const prevRange = currentRangeFormatted();
678
+ onValueChange?.(mkRange(plainToFormatValue(lo), plainToFormatValue(effectiveEnd)), {
679
+ date: void 0,
680
+ previous: prevRange
681
+ });
682
+ } else {
683
+ const prevSingle = currentSingleFormatted();
684
+ const tagged = fromZonedDateTime(lo.toPlainDateTime({
685
+ hour: 0,
686
+ minute: 0,
687
+ second: 0
688
+ }).toZonedDateTime(timeZone), resolvedFormat, T);
689
+ onValueChange?.(tagged.value, {
690
+ date: void 0,
691
+ previous: prevSingle
692
+ });
693
+ }
694
+ }
695
+ };
696
+ }
697
+ /** Truncate dates when selection mode changes. Returns new dates + fires callback. */
698
+ function truncateDatesForMode(opts) {
699
+ const { prev, maxDatesForMode, selectionMode, plainToFormatValue, onValueChange } = opts;
700
+ const clamped = prev.slice(0, maxDatesForMode);
701
+ if (clamped.length === prev.length) return prev;
702
+ const noDate = { date: void 0 };
703
+ const fmt = (d) => d != null ? plainToFormatValue(d) : null;
704
+ if (selectionMode === "single") {
705
+ const prevVal = prev.length > 0 && prev[0] != null ? plainToFormatValue(prev[0]) : null;
706
+ const newVal = clamped.length > 0 && clamped[0] != null ? plainToFormatValue(clamped[0]) : null;
707
+ onValueChange?.(newVal, {
708
+ ...noDate,
709
+ previous: prevVal
710
+ });
711
+ } else if (selectionMode === "range") {
712
+ const prevRange = prev.length >= 2 ? mkRange(fmt(prev[0]), fmt(prev[1])) : null;
713
+ let newRange = null;
714
+ if (clamped.length >= 2) newRange = mkRange(fmt(clamped[0]), fmt(clamped[1]));
715
+ else if (clamped.length === 1) {
716
+ const v = fmt(clamped[0]);
717
+ newRange = mkRange(v, v);
718
+ }
719
+ onValueChange?.(newRange, {
720
+ ...noDate,
721
+ previous: prevRange
722
+ });
723
+ } else {
724
+ const prevArr = prev.filter((d) => d != null).map(plainToFormatValue);
725
+ const clampedNonNull = clamped.filter((d) => d != null);
726
+ onValueChange?.(clampedNonNull.map(plainToFormatValue), {
727
+ ...noDate,
728
+ previous: prevArr
729
+ });
730
+ }
731
+ return clamped;
732
+ }
733
+ /**
734
+ * Pure utility that computes the preview range for a hovered date, using the
735
+ * same logic as the internal hook. Useful for deriving the preview in an
736
+ * `onHoveredDateChange` handler without needing a controlled `previewRange`.
737
+ */
738
+ function computePreviewRange(hoveredDate, currentRange, rangeMode, preventRangeReversal = false, T) {
739
+ const Temporal = T ?? globalThis.Temporal;
740
+ if (!Temporal) throw new Error("computePreviewRange requires a Temporal namespace. Pass it as the 5th argument or ensure globalThis.Temporal is available.");
741
+ const rawStart = currentRange?.start != null ? Temporal.PlainDate.from(currentRange.start) : null;
742
+ const rawEnd = currentRange?.end != null ? Temporal.PlainDate.from(currentRange.end) : null;
743
+ const committedDates = currentRange ? rawStart === null && rawEnd !== null ? [rawEnd, null] : [rawStart, rawEnd] : [];
744
+ const committedStart = committedDates[0] ?? void 0;
745
+ const committedEnd = committedDates[1] ?? void 0;
746
+ const noop = () => [];
747
+ const result = computeSelectionUpdate({
748
+ date: hoveredDate,
749
+ readOnly: false,
750
+ isDateDisabled: () => false,
751
+ isMultiple: false,
752
+ isRange: true,
753
+ committedDates,
754
+ committedStart,
755
+ committedEnd,
756
+ selectedZdt: void 0,
757
+ rangeMode,
758
+ allowRangeReversal: !preventRangeReversal,
759
+ sortDates: (d) => [...d].sort((a, b) => Temporal.PlainDate.compare(a, b)),
760
+ currentSingleFormatted: noop,
761
+ currentRangeFormatted: () => currentRange,
762
+ currentMultipleFormatted: noop,
763
+ resolvedFormat: "PlainDate",
764
+ timeZone: "UTC",
765
+ T: Temporal
766
+ });
767
+ if (result.skip || result.newDates.length === 0) return null;
768
+ const start = result.newDates[0];
769
+ const end = result.newDates.length > 1 ? result.newDates[1] : start;
770
+ if (start == null || end == null) return null;
771
+ return mkRange(start, end);
772
+ }
773
+ //#endregion
774
+ //#region src/calendar-provider.tsx
775
+ /**
776
+ * Provides shared calendar state (selection, config, range preview) to all
777
+ * descendant view components. Does NOT manage focus, navigation, or grid data.
778
+ */
779
+ function CalendarProvider(props) {
780
+ const { format: formatProp, selectionMode: selectionModeProp, min, max, disabled: disabledProp, readOnly: readOnlyProp, isDateDisabled: isDateDisabledProp, timeZone: timeZoneProp, locale: localeProp, temporal: temporalProp, weekStartDay: weekStartDayProp, children } = props;
781
+ const T = resolveTemporal(temporalProp);
782
+ const locale = localeProp ?? "en-US";
783
+ const timeZone = timeZoneProp ?? getSystemTimeZone(T);
784
+ const weekStartDay = weekStartDayProp ?? 0;
785
+ const resolvedFormat = formatProp ?? "PlainDate";
786
+ const selectionMode = selectionModeProp ?? "single";
787
+ const disabled = disabledProp ?? false;
788
+ const readOnly = readOnlyProp ?? false;
789
+ const rangeParams = selectionMode === "range" ? props : void 0;
790
+ const rangeMode = rangeParams?.rangeMode ?? "nearest-end";
791
+ const allowRangeReversal = !(rangeParams?.preventRangeReversal ?? false);
792
+ const previewRangeProp = rangeParams?.previewRange;
793
+ const onHoveredDateChange = rangeParams?.onHoveredDateChange;
794
+ const isRange = selectionMode === "range";
795
+ const isMultiple = selectionMode === "multiple";
796
+ const valueProp = props.value;
797
+ const defaultValueProp = props.defaultValue;
798
+ const onValueChange = props.onValueChange;
799
+ const singleValue = !isRange && !isMultiple ? valueProp : void 0;
800
+ const singleDefault = !isRange && !isMultiple ? defaultValueProp : void 0;
801
+ const rangeValue = isRange ? valueProp === null ? null : valueProp != null && isDateRange(valueProp) ? valueProp : void 0 : void 0;
802
+ const rangeDefault = isRange && defaultValueProp != null && isDateRange(defaultValueProp) ? defaultValueProp : void 0;
803
+ const multipleValue = isMultiple ? valueProp === null ? null : Array.isArray(valueProp) ? valueProp : void 0 : void 0;
804
+ const multipleDefault = isMultiple && Array.isArray(defaultValueProp) ? defaultValueProp : void 0;
805
+ const taggedValue = (0, react.useMemo)(() => tagRaw(singleValue ?? void 0, resolvedFormat), [singleValue, resolvedFormat]);
806
+ const minValue = (0, react.useMemo)(() => {
807
+ if (min == null) return void 0;
808
+ return toZonedDateTime({
809
+ format: resolvedFormat,
810
+ value: min
811
+ }, timeZone, T).toPlainDate();
812
+ }, [
813
+ min,
814
+ resolvedFormat,
815
+ timeZone,
816
+ T
817
+ ]);
818
+ const maxValue = (0, react.useMemo)(() => {
819
+ if (max == null) return void 0;
820
+ return toZonedDateTime({
821
+ format: resolvedFormat,
822
+ value: max
823
+ }, timeZone, T).toPlainDate();
824
+ }, [
825
+ max,
826
+ resolvedFormat,
827
+ timeZone,
828
+ T
829
+ ]);
830
+ const isDateDisabled = (0, react.useCallback)((date) => {
831
+ if (disabled) return true;
832
+ if (minValue && T.PlainDate.compare(date, minValue) < 0) return true;
833
+ if (maxValue && T.PlainDate.compare(date, maxValue) > 0) return true;
834
+ return isDateDisabledProp?.(date) ?? false;
835
+ }, [
836
+ disabled,
837
+ minValue,
838
+ maxValue,
839
+ isDateDisabledProp,
840
+ T
841
+ ]);
842
+ const rawToPlain = (0, react.useCallback)((raw) => {
843
+ return toZonedDateTime({
844
+ format: resolvedFormat,
845
+ value: raw
846
+ }, timeZone, T).toPlainDate();
847
+ }, [
848
+ resolvedFormat,
849
+ timeZone,
850
+ T
851
+ ]);
852
+ const sortDates = (0, react.useCallback)((dates) => [...dates].sort((a, b) => T.PlainDate.compare(a, b)), [T]);
853
+ const maxDatesForMode = isMultiple ? Number.POSITIVE_INFINITY : isRange ? 2 : 1;
854
+ const controlledDates = (0, react.useMemo)(() => {
855
+ if (isMultiple) {
856
+ if (multipleValue === null) return [];
857
+ if (multipleValue) return sortDates(multipleValue.map(rawToPlain));
858
+ return;
859
+ }
860
+ if (isRange) {
861
+ if (rangeValue === null) return [];
862
+ if (rangeValue) {
863
+ const start = rangeValue.start != null ? rawToPlain(rangeValue.start) : null;
864
+ const end = rangeValue.end != null ? rawToPlain(rangeValue.end) : null;
865
+ if (start === null && end === null) return [];
866
+ if (start === null && end !== null) return [end, null];
867
+ return [start, end];
868
+ }
869
+ return;
870
+ }
871
+ if (singleValue === null) return [];
872
+ if (singleValue !== void 0) return [rawToPlain(singleValue)];
873
+ }, [
874
+ isMultiple,
875
+ isRange,
876
+ multipleValue,
877
+ rangeValue,
878
+ singleValue,
879
+ rawToPlain,
880
+ sortDates
881
+ ]);
882
+ const [internalDates, setInternalDates] = (0, react.useState)((0, react.useMemo)(() => {
883
+ if (isMultiple) {
884
+ if (multipleDefault) return sortDates(multipleDefault.map(rawToPlain));
885
+ return [];
886
+ }
887
+ if (rangeDefault) {
888
+ const start = rangeDefault.start != null ? rawToPlain(rangeDefault.start) : null;
889
+ const end = rangeDefault.end != null ? rawToPlain(rangeDefault.end) : null;
890
+ if (start === null && end === null) return [];
891
+ if (start === null && end !== null) return [end, null];
892
+ return [start, end];
893
+ }
894
+ if (singleDefault != null) return [rawToPlain(singleDefault)];
895
+ return [];
896
+ }, [
897
+ isMultiple,
898
+ multipleDefault,
899
+ rangeDefault,
900
+ singleDefault,
901
+ rawToPlain,
902
+ sortDates
903
+ ]));
904
+ const isControlled = controlledDates !== void 0;
905
+ const committedDates = isControlled ? controlledDates : internalDates;
906
+ const rangeStart = !isMultiple && committedDates.length > 0 ? committedDates[0] ?? void 0 : void 0;
907
+ const rangeEnd = !isMultiple && committedDates.length >= 2 ? committedDates[1] ?? void 0 : void 0;
908
+ const committedStart = committedDates[0] ?? void 0;
909
+ const committedEnd = committedDates.length > 1 ? committedDates[committedDates.length - 1] ?? void 0 : committedStart;
910
+ const [hoveredDate, setHoveredDateRaw] = (0, react.useState)(void 0);
911
+ const setHoveredDate = (0, react.useCallback)((date) => {
912
+ onHoveredDateChange?.(date);
913
+ setHoveredDateRaw(date);
914
+ }, [onHoveredDateChange]);
915
+ const plainToFormatValue = (0, react.useCallback)((plain) => {
916
+ return fromZonedDateTime(plain.toPlainDateTime({
917
+ hour: 0,
918
+ minute: 0,
919
+ second: 0
920
+ }).toZonedDateTime(timeZone), resolvedFormat, T).value;
921
+ }, [
922
+ resolvedFormat,
923
+ timeZone,
924
+ T
925
+ ]);
926
+ const commitSelection = (0, react.useCallback)((result) => {
927
+ if (result.skip) return;
928
+ if (isControlled) setInternalDates((prev) => prev.length === 0 ? prev : []);
929
+ else setInternalDates(result.newDates);
930
+ result.fireCallback(onValueChange, plainToFormatValue);
931
+ }, [
932
+ isControlled,
933
+ onValueChange,
934
+ plainToFormatValue
935
+ ]);
936
+ const currentSingleFormatted = (0, react.useCallback)(() => {
937
+ if (committedDates.length === 0) return null;
938
+ const first = committedDates[0];
939
+ if (first == null) return null;
940
+ return plainToFormatValue(first);
941
+ }, [committedDates, plainToFormatValue]);
942
+ const currentRangeFormatted = (0, react.useCallback)(() => {
943
+ if (!committedStart && !committedEnd) return null;
944
+ return {
945
+ start: committedStart ? plainToFormatValue(committedStart) : null,
946
+ end: committedEnd ? plainToFormatValue(committedEnd) : null
947
+ };
948
+ }, [
949
+ committedStart,
950
+ committedEnd,
951
+ plainToFormatValue
952
+ ]);
953
+ const currentMultipleFormatted = (0, react.useCallback)(() => committedDates.filter((d) => d != null).map(plainToFormatValue), [committedDates, plainToFormatValue]);
954
+ const selected = (0, react.useMemo)(() => {
955
+ if (taggedValue) return taggedValue;
956
+ if (committedDates.length === 0) return void 0;
957
+ const first = committedDates[0];
958
+ if (!first) return void 0;
959
+ return fromZonedDateTime(first.toPlainDateTime({
960
+ hour: 0,
961
+ minute: 0,
962
+ second: 0
963
+ }).toZonedDateTime(timeZone), resolvedFormat, T);
964
+ }, [
965
+ taggedValue,
966
+ committedDates,
967
+ timeZone,
968
+ resolvedFormat,
969
+ T
970
+ ]);
971
+ const selectedZdt = (0, react.useMemo)(() => selectedToZdt(selected, timeZone, T), [
972
+ selected,
973
+ timeZone,
974
+ T
975
+ ]);
976
+ const [previewStart, previewEnd] = (0, react.useMemo)(() => {
977
+ if (previewRangeProp !== void 0) {
978
+ if (!previewRangeProp) return [void 0, void 0];
979
+ const rawToPlainLocal = (raw) => {
980
+ return toZonedDateTime({
981
+ format: resolvedFormat,
982
+ value: raw
983
+ }, timeZone, T).toPlainDate();
984
+ };
985
+ return [previewRangeProp.start != null ? rawToPlainLocal(previewRangeProp.start) : void 0, previewRangeProp.end != null ? rawToPlainLocal(previewRangeProp.end) : void 0];
986
+ }
987
+ if (!hoveredDate || !isRange) return [void 0, void 0];
988
+ const result = computeSelectionUpdate({
989
+ date: hoveredDate,
990
+ readOnly,
991
+ isDateDisabled,
992
+ isMultiple: false,
993
+ isRange: true,
994
+ committedDates,
995
+ committedStart,
996
+ committedEnd,
997
+ selectedZdt: void 0,
998
+ rangeMode,
999
+ allowRangeReversal,
1000
+ sortDates,
1001
+ currentSingleFormatted,
1002
+ currentRangeFormatted,
1003
+ currentMultipleFormatted,
1004
+ resolvedFormat,
1005
+ timeZone,
1006
+ T
1007
+ });
1008
+ if (result.skip || result.newDates.length === 0) return [void 0, void 0];
1009
+ const ps = result.newDates[0];
1010
+ const pe = result.newDates.length > 1 ? result.newDates[1] : ps;
1011
+ if (ps == null || pe == null) return [void 0, void 0];
1012
+ return [ps, pe];
1013
+ }, [
1014
+ previewRangeProp,
1015
+ hoveredDate,
1016
+ isRange,
1017
+ readOnly,
1018
+ isDateDisabled,
1019
+ committedDates,
1020
+ committedStart,
1021
+ committedEnd,
1022
+ rangeMode,
1023
+ allowRangeReversal,
1024
+ sortDates,
1025
+ currentSingleFormatted,
1026
+ currentRangeFormatted,
1027
+ currentMultipleFormatted,
1028
+ resolvedFormat,
1029
+ timeZone,
1030
+ T
1031
+ ]);
1032
+ const prevModeRef = (0, react.useRef)(selectionMode);
1033
+ (0, react.useEffect)(() => {
1034
+ if (prevModeRef.current === selectionMode) return;
1035
+ prevModeRef.current = selectionMode;
1036
+ if (isControlled) return;
1037
+ setInternalDates((prev) => truncateDatesForMode({
1038
+ prev,
1039
+ maxDatesForMode,
1040
+ selectionMode,
1041
+ plainToFormatValue,
1042
+ onValueChange
1043
+ }));
1044
+ }, [
1045
+ selectionMode,
1046
+ maxDatesForMode,
1047
+ onValueChange,
1048
+ plainToFormatValue,
1049
+ isControlled
1050
+ ]);
1051
+ (0, react.useEffect)(() => {
1052
+ if (isRange || isMultiple) return;
1053
+ const start = committedStart;
1054
+ if (!start) return;
1055
+ if (minValue && T.PlainDate.compare(start, minValue) < 0 || maxValue && T.PlainDate.compare(start, maxValue) > 0) {
1056
+ const prev = currentSingleFormatted();
1057
+ commitSelection({
1058
+ newDates: [],
1059
+ fireCallback: (onValueChange) => {
1060
+ onValueChange?.(null, {
1061
+ date: void 0,
1062
+ previous: prev
1063
+ });
1064
+ }
1065
+ });
1066
+ }
1067
+ }, [
1068
+ minValue,
1069
+ maxValue,
1070
+ committedStart,
1071
+ commitSelection,
1072
+ currentSingleFormatted,
1073
+ T,
1074
+ isRange,
1075
+ isMultiple
1076
+ ]);
1077
+ const onSelect = (0, react.useCallback)((date) => {
1078
+ const result = computeSelectionUpdate({
1079
+ date,
1080
+ readOnly,
1081
+ isDateDisabled,
1082
+ isMultiple,
1083
+ isRange,
1084
+ committedDates,
1085
+ committedStart,
1086
+ committedEnd,
1087
+ selectedZdt,
1088
+ rangeMode,
1089
+ allowRangeReversal,
1090
+ sortDates,
1091
+ currentSingleFormatted,
1092
+ currentRangeFormatted,
1093
+ currentMultipleFormatted,
1094
+ resolvedFormat,
1095
+ timeZone,
1096
+ T
1097
+ });
1098
+ if (result.skip) return;
1099
+ commitSelection(result);
1100
+ if (isRange) setHoveredDateRaw(void 0);
1101
+ }, [
1102
+ readOnly,
1103
+ isMultiple,
1104
+ committedDates,
1105
+ selectedZdt,
1106
+ commitSelection,
1107
+ resolvedFormat,
1108
+ isDateDisabled,
1109
+ timeZone,
1110
+ T,
1111
+ isRange,
1112
+ committedStart,
1113
+ committedEnd,
1114
+ sortDates,
1115
+ rangeMode,
1116
+ allowRangeReversal,
1117
+ currentSingleFormatted,
1118
+ currentRangeFormatted,
1119
+ currentMultipleFormatted
1120
+ ]);
1121
+ const setRange = (0, react.useCallback)((start, end) => {
1122
+ const result = computeSetRangeUpdate({
1123
+ start,
1124
+ end,
1125
+ readOnly,
1126
+ isMultiple,
1127
+ isRange,
1128
+ currentRangeFormatted,
1129
+ currentSingleFormatted,
1130
+ resolvedFormat,
1131
+ timeZone,
1132
+ T
1133
+ });
1134
+ if (result.skip) return;
1135
+ commitSelection(result);
1136
+ }, [
1137
+ readOnly,
1138
+ isMultiple,
1139
+ isRange,
1140
+ commitSelection,
1141
+ currentRangeFormatted,
1142
+ currentSingleFormatted,
1143
+ timeZone,
1144
+ resolvedFormat,
1145
+ T
1146
+ ]);
1147
+ const nonNullDates = (0, react.useMemo)(() => committedDates.filter((d) => d != null), [committedDates]);
1148
+ const stableCtx = (0, react.useMemo)(() => ({
1149
+ onSelect,
1150
+ setRange,
1151
+ selectionMode,
1152
+ disabled,
1153
+ readOnly,
1154
+ isDateDisabled,
1155
+ minValue,
1156
+ maxValue,
1157
+ timeZone,
1158
+ locale,
1159
+ temporal: T,
1160
+ weekStartDay,
1161
+ rangeMode,
1162
+ preventRangeReversal: !allowRangeReversal,
1163
+ valueFormat: resolvedFormat,
1164
+ setHoveredDate
1165
+ }), [
1166
+ onSelect,
1167
+ setRange,
1168
+ selectionMode,
1169
+ disabled,
1170
+ readOnly,
1171
+ isDateDisabled,
1172
+ minValue,
1173
+ maxValue,
1174
+ timeZone,
1175
+ locale,
1176
+ T,
1177
+ weekStartDay,
1178
+ rangeMode,
1179
+ allowRangeReversal,
1180
+ resolvedFormat,
1181
+ setHoveredDate
1182
+ ]);
1183
+ const stateCtx = (0, react.useMemo)(() => ({
1184
+ selected,
1185
+ selectedDates: nonNullDates,
1186
+ rangeStart,
1187
+ rangeEnd,
1188
+ hoveredDate,
1189
+ previewStart,
1190
+ previewEnd
1191
+ }), [
1192
+ selected,
1193
+ nonNullDates,
1194
+ rangeStart,
1195
+ rangeEnd,
1196
+ hoveredDate,
1197
+ previewStart,
1198
+ previewEnd
1199
+ ]);
1200
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarStableContext.Provider, {
1201
+ value: stableCtx,
1202
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarStateContext.Provider, {
1203
+ value: stateCtx,
1204
+ children
1205
+ })
1206
+ });
1207
+ }
1208
+ //#endregion
1209
+ //#region src/month-view-context.ts
1210
+ /** @internal React context for MonthView stable values (config + callbacks). */
1211
+ const MonthViewStableContext = (0, react.createContext)(null);
1212
+ /** @internal React context for MonthView volatile state. */
1213
+ const MonthViewStateContext = (0, react.createContext)(null);
1214
+ /** Returns the MonthView stable context (config + callbacks). */
1215
+ function useMonthViewStable() {
1216
+ const ctx = (0, react.useContext)(MonthViewStableContext);
1217
+ if (!ctx) throw new Error("useMonthViewStable must be used within MonthView.Root");
1218
+ return ctx;
1219
+ }
1220
+ /** Returns the MonthView state context (volatile grid data). */
1221
+ function useMonthViewState() {
1222
+ const ctx = (0, react.useContext)(MonthViewStateContext);
1223
+ if (!ctx) throw new Error("useMonthViewState must be used within MonthView.Root");
1224
+ return ctx;
1225
+ }
1226
+ //#endregion
1227
+ //#region src/view-context.ts
1228
+ /** @internal React context for the active view (MonthView or WeeksView). */
1229
+ const ViewContext = (0, react.createContext)(null);
1230
+ /** Returns the nearest view context (MonthView or WeeksView). */
1231
+ function useViewContext() {
1232
+ const ctx = (0, react.useContext)(ViewContext);
1233
+ if (!ctx) throw new Error("useViewContext must be used within MonthView or WeeksView");
1234
+ return ctx;
1235
+ }
1236
+ //#endregion
1237
+ //#region src/month-view.tsx
1238
+ function MonthViewRoot(props) {
1239
+ const { numberOfMonths: numberOfMonthsProp, fixedWeeks: fixedWeeksProp, outsideDays: outsideDaysProp, overflowBehavior: overflowBehaviorProp, month: monthProp, defaultMonth: defaultMonthProp, onMonthChange, children } = props;
1240
+ const numberOfMonths = Math.max(1, Math.min(numberOfMonthsProp ?? 1, 12));
1241
+ const fixedWeeks = fixedWeeksProp ?? false;
1242
+ const outsideDays = outsideDaysProp ?? "enabled";
1243
+ const overflowBehavior = overflowBehaviorProp ?? "unbounded";
1244
+ const calStable = useCalendarStable();
1245
+ const calState = useCalendarState();
1246
+ const T = calStable.temporal;
1247
+ const { timeZone, locale, weekStartDay, isDateDisabled } = calStable;
1248
+ const isMonthControlled = monthProp !== void 0;
1249
+ const [internalMonth, setInternalMonth] = (0, react.useState)(() => {
1250
+ if (monthProp) return {
1251
+ year: monthProp.year,
1252
+ month: monthProp.month
1253
+ };
1254
+ if (defaultMonthProp) return {
1255
+ year: defaultMonthProp.year,
1256
+ month: defaultMonthProp.month
1257
+ };
1258
+ if (calState.selected) {
1259
+ const zdt = toZonedDateTime(calState.selected, timeZone, T);
1260
+ return {
1261
+ year: zdt.year,
1262
+ month: zdt.month
1263
+ };
1264
+ }
1265
+ const now = T.Now.zonedDateTimeISO(timeZone);
1266
+ return {
1267
+ year: now.year,
1268
+ month: now.month
1269
+ };
1270
+ });
1271
+ const currentMonth = isMonthControlled ? {
1272
+ year: monthProp.year,
1273
+ month: monthProp.month
1274
+ } : internalMonth;
1275
+ const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
1276
+ if (calState.selected) return toZonedDateTime(calState.selected, timeZone, T).toPlainDate();
1277
+ return T.Now.plainDateISO();
1278
+ });
1279
+ const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
1280
+ const gridFocusedRef = (0, react.useRef)(false);
1281
+ const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
1282
+ const setGridLabelId = (0, react.useCallback)((monthIndex, id) => {
1283
+ setGridLabelIds((prev) => {
1284
+ if (id === void 0) {
1285
+ if (!(monthIndex in prev)) return prev;
1286
+ const next = { ...prev };
1287
+ delete next[monthIndex];
1288
+ return next;
1289
+ }
1290
+ if (prev[monthIndex] === id) return prev;
1291
+ return {
1292
+ ...prev,
1293
+ [monthIndex]: id
1294
+ };
1295
+ });
1296
+ }, []);
1297
+ const navigateToMonth = (0, react.useCallback)((targetYear, targetMonth) => {
1298
+ if (isMonthControlled) return;
1299
+ setInternalMonth((prev) => {
1300
+ for (let i = 0; i < numberOfMonths; i++) {
1301
+ const totalMonths = prev.year * 12 + (prev.month - 1) + i;
1302
+ const y = Math.floor(totalMonths / 12);
1303
+ const m = totalMonths % 12 + 1;
1304
+ if (targetYear === y && targetMonth === m) return prev;
1305
+ }
1306
+ return {
1307
+ year: targetYear,
1308
+ month: targetMonth
1309
+ };
1310
+ });
1311
+ }, [isMonthControlled, numberOfMonths]);
1312
+ (0, react.useEffect)(() => {
1313
+ navigateToMonth(focusedDate.year, focusedDate.month);
1314
+ }, [focusedDate, navigateToMonth]);
1315
+ const goNextMonth = (0, react.useCallback)(() => {
1316
+ if (isMonthControlled) {
1317
+ const { year, month, firstDay } = computeAdjacentMonth({
1318
+ year: monthProp.year,
1319
+ month: monthProp.month
1320
+ }, "next", T);
1321
+ setFocusedDate((prev) => focusedDateForMonth(prev, {
1322
+ year,
1323
+ month
1324
+ }, firstDay));
1325
+ return;
1326
+ }
1327
+ setInternalMonth((m) => {
1328
+ const { year, month, firstDay } = computeAdjacentMonth(m, "next", T);
1329
+ setFocusedDate((prev) => focusedDateForMonth(prev, {
1330
+ year,
1331
+ month
1332
+ }, firstDay));
1333
+ return {
1334
+ year,
1335
+ month
1336
+ };
1337
+ });
1338
+ }, [
1339
+ T,
1340
+ isMonthControlled,
1341
+ monthProp
1342
+ ]);
1343
+ const goPrevMonth = (0, react.useCallback)(() => {
1344
+ if (isMonthControlled) {
1345
+ const { year, month, firstDay } = computeAdjacentMonth({
1346
+ year: monthProp.year,
1347
+ month: monthProp.month
1348
+ }, "prev", T);
1349
+ setFocusedDate((prev) => focusedDateForMonth(prev, {
1350
+ year,
1351
+ month
1352
+ }, firstDay));
1353
+ return;
1354
+ }
1355
+ setInternalMonth((m) => {
1356
+ const { year, month, firstDay } = computeAdjacentMonth(m, "prev", T);
1357
+ setFocusedDate((prev) => focusedDateForMonth(prev, {
1358
+ year,
1359
+ month
1360
+ }, firstDay));
1361
+ return {
1362
+ year,
1363
+ month
1364
+ };
1365
+ });
1366
+ }, [
1367
+ T,
1368
+ isMonthControlled,
1369
+ monthProp
1370
+ ]);
1371
+ const allMonths = (0, react.useMemo)(() => {
1372
+ const opts = {
1373
+ weekStartDay,
1374
+ fixedWeeks
1375
+ };
1376
+ const result = [];
1377
+ for (let i = 0; i < numberOfMonths; i++) {
1378
+ const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
1379
+ const y = Math.floor(totalMonths / 12);
1380
+ const m = totalMonths % 12 + 1;
1381
+ result.push({
1382
+ year: y,
1383
+ month: m,
1384
+ weeks: getMonthWeeks(y, m, T, opts)
1385
+ });
1386
+ }
1387
+ return result;
1388
+ }, [
1389
+ currentMonth.year,
1390
+ currentMonth.month,
1391
+ T,
1392
+ weekStartDay,
1393
+ fixedWeeks,
1394
+ numberOfMonths
1395
+ ]);
1396
+ const weeks = allMonths[0].weeks;
1397
+ const selectedZdt = (0, react.useMemo)(() => selectedToZdt(calState.selected, timeZone, T), [
1398
+ calState.selected,
1399
+ timeZone,
1400
+ T
1401
+ ]);
1402
+ const currentDateTime = (0, react.useMemo)(() => T.PlainDateTime.from({
1403
+ year: currentMonth.year,
1404
+ month: currentMonth.month,
1405
+ day: focusedDate.day,
1406
+ hour: selectedZdt?.hour ?? 0,
1407
+ minute: selectedZdt?.minute ?? 0,
1408
+ second: selectedZdt?.second ?? 0
1409
+ }, { overflow: "constrain" }), [
1410
+ currentMonth,
1411
+ focusedDate.day,
1412
+ selectedZdt,
1413
+ T
1414
+ ]);
1415
+ const selectedPlain = selectedZdt?.toPlainDate();
1416
+ const isDateDisabledFn = (0, react.useCallback)((date) => {
1417
+ return isDateDisabled?.(date) ?? false;
1418
+ }, [isDateDisabled]);
1419
+ const tabTargetDate = (0, react.useMemo)(() => resolveFocusTarget(focusedDate, selectedPlain, weeks, currentMonth, isDateDisabledFn, T, gridHasFocus), [
1420
+ focusedDate,
1421
+ selectedPlain,
1422
+ weeks,
1423
+ currentMonth,
1424
+ isDateDisabledFn,
1425
+ T,
1426
+ gridHasFocus
1427
+ ]);
1428
+ const localeCalendar = (0, react.useMemo)(() => calendarForLocale(locale), [locale]);
1429
+ const viewingYearMonth = (0, react.useMemo)(() => T.PlainYearMonth.from({
1430
+ year: currentMonth.year,
1431
+ month: currentMonth.month,
1432
+ calendar: localeCalendar
1433
+ }), [
1434
+ currentMonth,
1435
+ T,
1436
+ localeCalendar
1437
+ ]);
1438
+ const onMonthChangeRef = (0, react.useRef)(onMonthChange);
1439
+ onMonthChangeRef.current = onMonthChange;
1440
+ const mountedRef = (0, react.useRef)(false);
1441
+ (0, react.useEffect)(() => {
1442
+ if (!mountedRef.current) {
1443
+ mountedRef.current = true;
1444
+ return;
1445
+ }
1446
+ onMonthChangeRef.current?.(viewingYearMonth);
1447
+ }, [viewingYearMonth]);
1448
+ const { selected, selectedDates, rangeStart, rangeEnd } = calState;
1449
+ const rootState = (0, react.useMemo)(() => ({
1450
+ hasSelection: selectedDates.length > 0,
1451
+ selected: selected?.value,
1452
+ selectedDates,
1453
+ rangeStart,
1454
+ rangeEnd,
1455
+ focused: focusedDate,
1456
+ viewing: viewingYearMonth,
1457
+ timeZone,
1458
+ locale,
1459
+ readOnly: calStable.readOnly
1460
+ }), [
1461
+ selectedDates,
1462
+ selected,
1463
+ rangeStart,
1464
+ rangeEnd,
1465
+ focusedDate,
1466
+ viewingYearMonth,
1467
+ timeZone,
1468
+ locale,
1469
+ calStable.readOnly
1470
+ ]);
1471
+ const stableCtx = (0, react.useMemo)(() => ({
1472
+ numberOfMonths,
1473
+ fixedWeeks,
1474
+ outsideDays,
1475
+ overflowBehavior,
1476
+ goNextMonth,
1477
+ goPrevMonth,
1478
+ setGridLabelId,
1479
+ gridFocusedRef
1480
+ }), [
1481
+ numberOfMonths,
1482
+ fixedWeeks,
1483
+ outsideDays,
1484
+ overflowBehavior,
1485
+ goNextMonth,
1486
+ goPrevMonth,
1487
+ setGridLabelId
1488
+ ]);
1489
+ const stateCtx = (0, react.useMemo)(() => ({
1490
+ currentMonth,
1491
+ weeks,
1492
+ allMonths,
1493
+ currentDateTime,
1494
+ gridLabelIds,
1495
+ rootState
1496
+ }), [
1497
+ currentMonth,
1498
+ weeks,
1499
+ allMonths,
1500
+ currentDateTime,
1501
+ gridLabelIds,
1502
+ rootState
1503
+ ]);
1504
+ const viewCtx = (0, react.useMemo)(() => ({
1505
+ viewType: "month",
1506
+ focusedDate,
1507
+ setFocusedDate,
1508
+ tabTargetDate,
1509
+ gridHasFocus,
1510
+ setGridHasFocus
1511
+ }), [
1512
+ focusedDate,
1513
+ tabTargetDate,
1514
+ gridHasFocus
1515
+ ]);
1516
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
1517
+ value: stableCtx,
1518
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
1519
+ value: stateCtx,
1520
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
1521
+ value: viewCtx,
1522
+ children
1523
+ })
1524
+ })
1525
+ });
1526
+ }
1527
+ function MonthView(props) {
1528
+ const { numberOfMonths, fixedWeeks, outsideDays, overflowBehavior, month, defaultMonth, onMonthChange, children, ...calendarProps } = props;
1529
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarProvider, {
1530
+ ...calendarProps,
1531
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewRoot, {
1532
+ numberOfMonths,
1533
+ fixedWeeks,
1534
+ outsideDays,
1535
+ overflowBehavior,
1536
+ month,
1537
+ defaultMonth,
1538
+ onMonthChange,
1539
+ children
1540
+ })
1541
+ });
1542
+ }
1543
+ MonthView.Root = MonthViewRoot;
1544
+ //#endregion
1545
+ //#region src/context.ts
1546
+ /** @internal Provides the days and index of the current week row to child components. */
1547
+ const WeekDataContext = (0, react.createContext)(null);
1548
+ /** @internal Provides the resolved grid orientation to descendant cells. */
1549
+ const GridContext = (0, react.createContext)({ orientation: "horizontal" });
1550
+ /** @internal Provides the date and column index from a `DayCellTemplate` to its child `DayButton`. */
1551
+ const DayCellDataContext = (0, react.createContext)(null);
1552
+ /** @internal Provides per-grid month data to WeekTemplate and DayCellTemplate. */
1553
+ const GridMonthContext = (0, react.createContext)(null);
1554
+ //#endregion
1555
+ //#region src/grid-header.tsx
1556
+ function useGridHeaderCellState(index) {
1557
+ const { locale, temporal: T, weekStartDay } = useCalendarStable();
1558
+ const { rootState } = useMonthViewState();
1559
+ const weekdayNames = (0, react.useMemo)(() => getWeekdayNames(locale, T, weekStartDay), [
1560
+ locale,
1561
+ T,
1562
+ weekStartDay
1563
+ ]);
1564
+ const state = (0, react.useMemo)(() => ({
1565
+ root: rootState,
1566
+ dayOfWeek: index,
1567
+ long: weekdayNames[index].long,
1568
+ short: weekdayNames[index].short,
1569
+ narrow: weekdayNames[index].narrow
1570
+ }), [
1571
+ rootState,
1572
+ index,
1573
+ weekdayNames
1574
+ ]);
1575
+ return {
1576
+ state,
1577
+ defaultProps: {
1578
+ scope: "col",
1579
+ abbr: state.long,
1580
+ "aria-label": state.long,
1581
+ children: state.narrow
1582
+ }
1583
+ };
1584
+ }
1585
+ const gridHeaderStateAttributesMapping = { root: () => null };
1586
+ const gridHeaderCellStateAttributesMapping = {
1587
+ root: () => null,
1588
+ dayOfWeek: () => null,
1589
+ long: () => null,
1590
+ short: () => null,
1591
+ narrow: () => null
1592
+ };
1593
+ function GridHeaderCellInstanceFn(props, ref) {
1594
+ const { render, index, ...otherProps } = props;
1595
+ const { state, defaultProps } = useGridHeaderCellState(index);
1596
+ return (0, _base_ui_react_use_render.useRender)({
1597
+ defaultTagName: "th",
1598
+ render,
1599
+ ref: ref ? [ref] : [],
1600
+ state,
1601
+ stateAttributesMapping: gridHeaderCellStateAttributesMapping,
1602
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
1603
+ });
1604
+ }
1605
+ const GridHeaderCellInstance = (0, react.forwardRef)(GridHeaderCellInstanceFn);
1606
+ function GridHeaderCellFn(props, ref) {
1607
+ const { index: indexProp, ...restProps } = props;
1608
+ const { temporal: T } = useCalendarStable();
1609
+ const Instance = GridHeaderCellInstance;
1610
+ if (indexProp != null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, {
1611
+ ...restProps,
1612
+ ref,
1613
+ index: indexProp
1614
+ });
1615
+ const daysInWeek = getReferenceWeekStart(T).daysInWeek;
1616
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: Array.from({ length: daysInWeek }, (_, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, {
1617
+ ...restProps,
1618
+ ref,
1619
+ index: i
1620
+ }, i)) });
1621
+ }
1622
+ /**
1623
+ * Renders weekday column headers (`<th>`). When no `index` is provided,
1624
+ * renders all 7 days (Sunday–Saturday). Each cell includes `abbr` and
1625
+ * `aria-label` with the full weekday name.
1626
+ */
1627
+ const GridHeaderCell = (0, react.forwardRef)(GridHeaderCellFn);
1628
+ function GridHeaderFn(props, ref) {
1629
+ const { render, children, ...otherProps } = props;
1630
+ const { rootState } = useMonthViewState();
1631
+ const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
1632
+ return (0, _base_ui_react_use_render.useRender)({
1633
+ defaultTagName: "thead",
1634
+ render,
1635
+ ref: ref ? [ref] : [],
1636
+ state,
1637
+ stateAttributesMapping: gridHeaderStateAttributesMapping,
1638
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridHeaderCell, {}) }) }, otherProps)
1639
+ });
1640
+ }
1641
+ /** Table header section (`<thead>`) wrapping a row of {@link GridHeaderCell}s. */
1642
+ const GridHeader = (0, react.forwardRef)(GridHeaderFn);
1643
+ //#endregion
1644
+ //#region src/keyboard.ts
1645
+ /**
1646
+ * Computes the target date when jumping by `months` from `focusedDate`.
1647
+ *
1648
+ * Day-of-month is constrained (e.g. Jan 31 + 1 month → Feb 28/29).
1649
+ */
1650
+ function computeMonthJumpTarget(focusedDate, months, T) {
1651
+ const totalMonths = focusedDate.year * 12 + (focusedDate.month - 1) + months;
1652
+ const targetYear = Math.floor(totalMonths / 12);
1653
+ const targetMonth = totalMonths % 12 + 1;
1654
+ return T.PlainDate.from({
1655
+ year: targetYear,
1656
+ month: targetMonth,
1657
+ day: focusedDate.day
1658
+ }, { overflow: "constrain" });
1659
+ }
1660
+ function clampToBounds(target, focusedDate, minValue, maxValue, T) {
1661
+ let clamped = target;
1662
+ if (minValue && T.PlainDate.compare(clamped, minValue) < 0) clamped = minValue;
1663
+ if (maxValue && T.PlainDate.compare(clamped, maxValue) > 0) clamped = maxValue;
1664
+ if (T.PlainDate.compare(clamped, focusedDate) === 0) return { action: "none" };
1665
+ return {
1666
+ action: "move",
1667
+ date: clamped
1668
+ };
1669
+ }
1670
+ /**
1671
+ * Pure function that maps a keyboard event to a navigation result.
1672
+ *
1673
+ * Handles Arrow keys (±1 day / ±1 week), Home/End (start/end of week),
1674
+ * PageUp/PageDown (±1 month, ±1 year with Shift), and Enter/Space (select).
1675
+ * Results are clamped to `minValue`/`maxValue` bounds.
1676
+ */
1677
+ function computeNextFocusDate(input) {
1678
+ const { key, shiftKey, focusedDate, minValue, maxValue, disabled, readOnly, isDateDisabled, T, weekStartDay = 0 } = input;
1679
+ if (disabled) return { action: "none" };
1680
+ const daysInWeek = focusedDate.daysInWeek;
1681
+ let nextDate = null;
1682
+ switch (key) {
1683
+ case "ArrowRight":
1684
+ nextDate = focusedDate.add({ days: 1 });
1685
+ break;
1686
+ case "ArrowLeft":
1687
+ nextDate = focusedDate.subtract({ days: 1 });
1688
+ break;
1689
+ case "ArrowDown":
1690
+ nextDate = focusedDate.add({ weeks: 1 });
1691
+ break;
1692
+ case "ArrowUp":
1693
+ nextDate = focusedDate.subtract({ weeks: 1 });
1694
+ break;
1695
+ case "Home": {
1696
+ const adjustedDow = (focusedDate.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek;
1697
+ nextDate = focusedDate.subtract({ days: adjustedDow });
1698
+ break;
1699
+ }
1700
+ case "End": {
1701
+ const adjustedDow = (focusedDate.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek;
1702
+ nextDate = focusedDate.add({ days: daysInWeek - 1 - adjustedDow });
1703
+ break;
1704
+ }
1705
+ case "PageUp": return clampToBounds(computeMonthJumpTarget(focusedDate, shiftKey ? -12 : -1, T), focusedDate, minValue, maxValue, T);
1706
+ case "PageDown": return clampToBounds(computeMonthJumpTarget(focusedDate, shiftKey ? 12 : 1, T), focusedDate, minValue, maxValue, T);
1707
+ case "Enter":
1708
+ case " ":
1709
+ if (readOnly) return { action: "none" };
1710
+ if (!isDateDisabled?.(focusedDate)) return { action: "select" };
1711
+ return { action: "none" };
1712
+ default: return { action: "none" };
1713
+ }
1714
+ if (nextDate) return clampToBounds(nextDate, focusedDate, minValue, maxValue, T);
1715
+ return { action: "none" };
1716
+ }
1717
+ //#endregion
1718
+ //#region src/month-separator.tsx
1719
+ /** Context providing MonthSeparator data to child components. */
1720
+ const MonthSeparatorDataContext = (0, react.createContext)(null);
1721
+ function useMonthSeparatorData() {
1722
+ const ctx = (0, react.useContext)(MonthSeparatorDataContext);
1723
+ if (!ctx) throw new Error("MonthSeparator child components must be used within a MonthSeparatorDataContext.Provider");
1724
+ return ctx;
1725
+ }
1726
+ const stateAttributesMapping = {
1727
+ month: (v) => ({ "data-month": String(v) }),
1728
+ year: (v) => ({ "data-year": String(v) }),
1729
+ firstOfYear: (v) => v ? { "data-first-of-year": "" } : null,
1730
+ firstVisible: (v) => v ? { "data-first-visible": "" } : null,
1731
+ weeksVisibleBefore: () => null,
1732
+ weeksVisibleAfter: () => null,
1733
+ firstDayColumn: (v) => ({ "data-first-day-column": String(v) }),
1734
+ totalColumns: (v) => ({ "data-total-columns": String(v) }),
1735
+ firstDayVisible: (v) => v ? { "data-first-day-visible": "" } : null,
1736
+ fullWeeksVisibleAfter: (v) => ({ "data-full-weeks-visible-after": String(v) }),
1737
+ gridRowStart: (v) => ({ "data-grid-row-start": String(v) })
1738
+ };
1739
+ function MonthSeparatorMonthFn(props, ref) {
1740
+ const { render, locale = "en-US", format = "long", ...otherProps } = props;
1741
+ const data = useMonthSeparatorData();
1742
+ const monthName = (0, react.useMemo)(() => {
1743
+ const date = new Date(data.year, data.month - 1, 1);
1744
+ return new Intl.DateTimeFormat(locale, { month: format }).format(date);
1745
+ }, [
1746
+ data.year,
1747
+ data.month,
1748
+ locale,
1749
+ format
1750
+ ]);
1751
+ return (0, _base_ui_react_use_render.useRender)({
1752
+ defaultTagName: "span",
1753
+ render,
1754
+ ref: ref ? [ref] : [],
1755
+ state: data,
1756
+ stateAttributesMapping,
1757
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: monthName }, otherProps)
1758
+ });
1759
+ }
1760
+ const MonthSeparatorMonth = (0, react.forwardRef)(MonthSeparatorMonthFn);
1761
+ function MonthSeparatorYearFn(props, ref) {
1762
+ const { render, ...otherProps } = props;
1763
+ const data = useMonthSeparatorData();
1764
+ return (0, _base_ui_react_use_render.useRender)({
1765
+ defaultTagName: "span",
1766
+ render,
1767
+ ref: ref ? [ref] : [],
1768
+ state: data,
1769
+ stateAttributesMapping,
1770
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: data.year }, otherProps)
1771
+ });
1772
+ }
1773
+ const MonthSeparatorYear = (0, react.forwardRef)(MonthSeparatorYearFn);
1774
+ function MonthSeparatorWeekCountFn(props, ref) {
1775
+ const { render, ...otherProps } = props;
1776
+ const data = useMonthSeparatorData();
1777
+ return (0, _base_ui_react_use_render.useRender)({
1778
+ defaultTagName: "span",
1779
+ render,
1780
+ ref: ref ? [ref] : [],
1781
+ state: data,
1782
+ stateAttributesMapping,
1783
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: data.weeksVisibleAfter }, otherProps)
1784
+ });
1785
+ }
1786
+ const MonthSeparatorWeekCount = (0, react.forwardRef)(MonthSeparatorWeekCountFn);
1787
+ function MonthSeparatorRowFn(props, ref) {
1788
+ const { render, ...otherProps } = props;
1789
+ const data = useMonthSeparatorData();
1790
+ const rendered = (0, _base_ui_react_use_render.useRender)({
1791
+ defaultTagName: "tr",
1792
+ render,
1793
+ ref: ref ? [ref] : [],
1794
+ state: data,
1795
+ stateAttributesMapping,
1796
+ props: (0, _base_ui_react_merge_props.mergeProps)({}, otherProps)
1797
+ });
1798
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorDataContext.Provider, {
1799
+ value: data,
1800
+ children: rendered
1801
+ });
1802
+ }
1803
+ /** Renders the `<tr>` for a month separator. Provides MonthSeparatorDataContext. */
1804
+ const MonthSeparatorRow = (0, react.forwardRef)(MonthSeparatorRowFn);
1805
+ function MonthSeparatorCellFn(props, ref) {
1806
+ const { render, ...otherProps } = props;
1807
+ const data = useMonthSeparatorData();
1808
+ return (0, _base_ui_react_use_render.useRender)({
1809
+ defaultTagName: "td",
1810
+ render,
1811
+ ref: ref ? [ref] : [],
1812
+ state: data,
1813
+ stateAttributesMapping,
1814
+ props: (0, _base_ui_react_merge_props.mergeProps)({ colSpan: 7 }, otherProps)
1815
+ });
1816
+ }
1817
+ /** Renders the `<td>` inside a MonthSeparatorRow. */
1818
+ const MonthSeparatorCell = (0, react.forwardRef)(MonthSeparatorCellFn);
1819
+ function MonthSeparatorFn(props, ref) {
1820
+ const { render, children, ...otherProps } = props;
1821
+ const data = useMonthSeparatorData();
1822
+ const rendered = (0, _base_ui_react_use_render.useRender)({
1823
+ defaultTagName: "tr",
1824
+ render,
1825
+ ref: ref ? [ref] : [],
1826
+ state: data,
1827
+ stateAttributesMapping,
1828
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
1829
+ colSpan: 7,
1830
+ children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1831
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorMonth, {}),
1832
+ " ",
1833
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorYear, {})
1834
+ ] })
1835
+ }) }, otherProps)
1836
+ });
1837
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorDataContext.Provider, {
1838
+ value: data,
1839
+ children: rendered
1840
+ });
1841
+ }
1842
+ /**
1843
+ * Convenience component: `<tr><td colspan="7">children</td></tr>`.
1844
+ * Combines MonthSeparatorRow + MonthSeparatorCell.
1845
+ * Default children: `<Month /> <Year />`.
1846
+ */
1847
+ const MonthSeparator = (0, react.forwardRef)(MonthSeparatorFn);
1848
+ //#endregion
1849
+ //#region src/weeks-view-context.ts
1850
+ /** @internal React context for WeeksView stable values (config + callbacks). */
1851
+ const WeeksViewStableContext = (0, react.createContext)(null);
1852
+ /** @internal React context for WeeksView volatile state. */
1853
+ const WeeksViewStateContext = (0, react.createContext)(null);
1854
+ /** Returns the WeeksView stable context (config + callbacks). */
1855
+ function useWeeksViewStable() {
1856
+ const ctx = (0, react.useContext)(WeeksViewStableContext);
1857
+ if (!ctx) throw new Error("useWeeksViewStable must be used within WeeksView.Root");
1858
+ return ctx;
1859
+ }
1860
+ /** Returns the WeeksView state context (volatile grid data). */
1861
+ function useWeeksViewState() {
1862
+ const ctx = (0, react.useContext)(WeeksViewStateContext);
1863
+ if (!ctx) throw new Error("useWeeksViewState must be used within WeeksView.Root");
1864
+ return ctx;
1865
+ }
1866
+ //#endregion
1867
+ //#region src/weeks-grid.tsx
1868
+ /**
1869
+ * @internal WeeksGrid — renders continuous week rows for WeeksView.
1870
+ * Not exported from the public API.
1871
+ */
1872
+ /**
1873
+ * Expand a WeekDescriptor into the 7 PlainDate values for that week.
1874
+ */
1875
+ function weekDays(week, _T) {
1876
+ const days = [];
1877
+ let d = week.startDate;
1878
+ for (let i = 0; i < 7; i++) {
1879
+ days.push(d);
1880
+ if (i < 6) d = d.add({ days: 1 });
1881
+ }
1882
+ return days;
1883
+ }
1884
+ /**
1885
+ * Check if a React element is a MonthSeparator (or wraps one).
1886
+ */
1887
+ function isSeparatorElement(child) {
1888
+ if (!(0, react.isValidElement)(child)) return false;
1889
+ return child.type === MonthSeparator || child.type === MonthSeparatorRow || child.type === MonthSeparator;
1890
+ }
1891
+ /**
1892
+ * Renders the `<tbody>` contents for a WeeksView grid.
1893
+ * Iterates over the weeks array and provides WeekDataContext per row.
1894
+ * Renders MonthSeparator children at month boundaries with proper context.
1895
+ */
1896
+ /**
1897
+ * Compute the 0-based column index of a date within a week row.
1898
+ * If hasWeekNumbers, column 0 is the week number column, and day columns are 1-7.
1899
+ * Otherwise day columns are 0-6.
1900
+ */
1901
+ function dayColumnIndex(date, weekStartDay, hasWeekNumbers) {
1902
+ const col = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
1903
+ return hasWeekNumbers ? col + 1 : col;
1904
+ }
1905
+ function WeeksGrid(props) {
1906
+ const { children, className, style, hasWeekNumbers = false } = props;
1907
+ const { temporal: T, weekStartDay } = useCalendarStable();
1908
+ const { weeks } = useWeeksViewState();
1909
+ const separatorTemplate = [];
1910
+ const weekRowChildren = [];
1911
+ react.Children.forEach(children, (child) => {
1912
+ if (isSeparatorElement(child)) separatorTemplate.push(child);
1913
+ else weekRowChildren.push(child);
1914
+ });
1915
+ const weekDaysArrays = (0, react.useMemo)(() => weeks.map((w) => weekDays(w, T)), [weeks, T]);
1916
+ const totalColumns = hasWeekNumbers ? 8 : 7;
1917
+ const monthBoundaries = (0, react.useMemo)(() => {
1918
+ const boundaries = [];
1919
+ const seenMonths = /* @__PURE__ */ new Set();
1920
+ for (let i = 0; i < weeks.length; i++) {
1921
+ const days = weekDaysArrays[i];
1922
+ const isFirstWeek = i === 0;
1923
+ const monthsInWeek = [];
1924
+ for (const day of days) {
1925
+ const monthKey = `${day.year}-${day.month}`;
1926
+ if (!seenMonths.has(monthKey) && !monthsInWeek.some((m) => m.key === monthKey)) monthsInWeek.push({
1927
+ month: day.month,
1928
+ year: day.year,
1929
+ key: monthKey
1930
+ });
1931
+ }
1932
+ const monthsToShow = isFirstWeek && monthsInWeek.length > 1 ? monthsInWeek.slice(1) : monthsInWeek;
1933
+ for (const m of monthsInWeek) seenMonths.add(m.key);
1934
+ for (const { month: newMonth, year: newYear } of monthsToShow) {
1935
+ const firstOfMonth = T.PlainDate.from({
1936
+ year: newYear,
1937
+ month: newMonth,
1938
+ day: 1
1939
+ });
1940
+ const firstDayCol = dayColumnIndex(firstOfMonth, weekStartDay, hasWeekNumbers);
1941
+ const windowStart = weekDaysArrays[0]?.[0];
1942
+ const windowEnd = weekDaysArrays[weekDaysArrays.length - 1]?.[6];
1943
+ const firstDayVisible = windowStart && windowEnd ? T.PlainDate.compare(firstOfMonth, windowStart) >= 0 && T.PlainDate.compare(firstOfMonth, windowEnd) <= 0 : false;
1944
+ let weeksVisibleBefore = 0;
1945
+ for (let j = i - 1; j >= 0; j--) if (!weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
1946
+ else break;
1947
+ let weeksVisibleAfter = 0;
1948
+ for (let j = i; j < weeks.length; j++) if (weekDaysArrays[j].some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
1949
+ else break;
1950
+ const isNewYear = boundaries.length > 0 ? boundaries[boundaries.length - 1].data.year !== newYear : newMonth === 1;
1951
+ boundaries.push({
1952
+ index: i,
1953
+ data: {
1954
+ month: newMonth,
1955
+ year: newYear,
1956
+ firstOfYear: isFirstWeek ? newMonth === 1 : isNewYear,
1957
+ firstVisible: boundaries.length === 0,
1958
+ weeksVisibleBefore,
1959
+ weeksVisibleAfter,
1960
+ firstDayColumn: firstDayCol,
1961
+ totalColumns,
1962
+ firstDayVisible,
1963
+ fullWeeksVisibleAfter: 0,
1964
+ gridRowStart: 0
1965
+ }
1966
+ });
1967
+ }
1968
+ }
1969
+ for (let b = 0; b < boundaries.length; b++) {
1970
+ const current = boundaries[b];
1971
+ const nextIndex = b + 1 < boundaries.length ? boundaries[b + 1].index : weeks.length;
1972
+ current.data.fullWeeksVisibleAfter = nextIndex - current.index;
1973
+ current.data.gridRowStart = current.index + 2;
1974
+ }
1975
+ return boundaries;
1976
+ }, [
1977
+ weeks,
1978
+ weekDaysArrays,
1979
+ weekStartDay,
1980
+ hasWeekNumbers,
1981
+ totalColumns,
1982
+ T
1983
+ ]);
1984
+ const boundariesAtIndex = (0, react.useMemo)(() => {
1985
+ const map = /* @__PURE__ */ new Map();
1986
+ for (const b of monthBoundaries) {
1987
+ const existing = map.get(b.index);
1988
+ if (existing) existing.push(b.data);
1989
+ else map.set(b.index, [b.data]);
1990
+ }
1991
+ return map;
1992
+ }, [monthBoundaries]);
1993
+ const rows = [];
1994
+ for (let i = 0; i < weeks.length; i++) {
1995
+ const week = weeks[i];
1996
+ const days = weekDaysArrays[i];
1997
+ const separators = boundariesAtIndex.get(i);
1998
+ if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthSeparatorDataContext.Provider, {
1999
+ value: separatorData,
2000
+ children: separatorTemplate
2001
+ }, `sep-${separatorData.year}-${separatorData.month}`));
2002
+ const weekGridRow = i + 2;
2003
+ rows.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
2004
+ value: {
2005
+ days,
2006
+ weekIndex: week.weekIndex,
2007
+ gridRowIndex: weekGridRow
2008
+ },
2009
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridMonthContext.Provider, {
2010
+ value: {
2011
+ weeks: [days],
2012
+ year: week.year,
2013
+ month: week.month
2014
+ },
2015
+ children: weekRowChildren
2016
+ })
2017
+ }, week.startDate.toString()));
2018
+ }
2019
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", {
2020
+ className,
2021
+ style,
2022
+ children: rows
2023
+ });
2024
+ }
2025
+ //#endregion
2026
+ //#region src/weeks-keyboard.ts
2027
+ const NONE = {
2028
+ action: "none",
2029
+ windowShift: 0,
2030
+ followFocus: false
2031
+ };
2032
+ /**
2033
+ * Pure function that maps a keyboard event to a weeks-view navigation result.
2034
+ *
2035
+ * Handles Arrow keys (±1 day / ±1 week), Home/End (first/last day of window),
2036
+ * PageUp/PageDown (±weekCount weeks, ±1 year with Shift), and Enter/Space (select).
2037
+ * Results are clamped to `minValue`/`maxValue` bounds.
2038
+ */
2039
+ function computeWeeksKeyNav(input) {
2040
+ const { key, shiftKey, focusedDate, windowStart, weekCount, minValue, maxValue, disabled, readOnly, isDateDisabled, scrollBy, T } = input;
2041
+ if (disabled) return NONE;
2042
+ const windowEnd = windowStart.add({ weeks: weekCount }).subtract({ days: 1 });
2043
+ function isOutsideWindow(date) {
2044
+ return T.PlainDate.compare(date, windowStart) < 0 || T.PlainDate.compare(date, windowEnd) > 0;
2045
+ }
2046
+ function windowShiftFor(target) {
2047
+ if (T.PlainDate.compare(target, windowEnd) > 0) return scrollBy === "row" ? 1 : weekCount;
2048
+ if (T.PlainDate.compare(target, windowStart) < 0) return scrollBy === "row" ? -1 : -weekCount;
2049
+ return 0;
2050
+ }
2051
+ function clampToMove(target, windowShift, followFocus) {
2052
+ let clamped = target;
2053
+ if (minValue && T.PlainDate.compare(clamped, minValue) < 0) clamped = minValue;
2054
+ if (maxValue && T.PlainDate.compare(clamped, maxValue) > 0) clamped = maxValue;
2055
+ if (T.PlainDate.compare(clamped, focusedDate) === 0) return NONE;
2056
+ return {
2057
+ action: "move",
2058
+ date: clamped,
2059
+ windowShift,
2060
+ followFocus
2061
+ };
2062
+ }
2063
+ switch (key) {
2064
+ case "ArrowRight": {
2065
+ const target = focusedDate.add({ days: 1 });
2066
+ return clampToMove(target, isOutsideWindow(target) ? windowShiftFor(target) : 0, false);
2067
+ }
2068
+ case "ArrowLeft": {
2069
+ const target = focusedDate.subtract({ days: 1 });
2070
+ return clampToMove(target, isOutsideWindow(target) ? windowShiftFor(target) : 0, false);
2071
+ }
2072
+ case "ArrowDown": {
2073
+ const target = focusedDate.add({ weeks: 1 });
2074
+ return clampToMove(target, isOutsideWindow(target) ? windowShiftFor(target) : 0, false);
2075
+ }
2076
+ case "ArrowUp": {
2077
+ const target = focusedDate.subtract({ weeks: 1 });
2078
+ return clampToMove(target, isOutsideWindow(target) ? windowShiftFor(target) : 0, false);
2079
+ }
2080
+ case "Home": return clampToMove(windowStart, 0, false);
2081
+ case "End": return clampToMove(windowEnd, 0, false);
2082
+ case "PageDown":
2083
+ if (shiftKey) return clampToMove(focusedDate.add({ years: 1 }), 0, true);
2084
+ return clampToMove(focusedDate.add({ weeks: weekCount }), weekCount, false);
2085
+ case "PageUp":
2086
+ if (shiftKey) return clampToMove(focusedDate.subtract({ years: 1 }), 0, true);
2087
+ return clampToMove(focusedDate.subtract({ weeks: weekCount }), -weekCount, false);
2088
+ case "Enter":
2089
+ case " ":
2090
+ if (readOnly) return NONE;
2091
+ if (!isDateDisabled?.(focusedDate)) return {
2092
+ action: "select",
2093
+ windowShift: 0,
2094
+ followFocus: false
2095
+ };
2096
+ return NONE;
2097
+ default: return NONE;
2098
+ }
2099
+ }
2100
+ //#endregion
2101
+ //#region src/day-cell.tsx
2102
+ /** Computes derived day cell state from context values. Pure function, no hooks. */
2103
+ function computeDayCellState(date, orientation, columnIndex, rootState, selectedDates, currentDateTime, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd) {
2104
+ const isCurrentMonth = date.year === currentDateTime.year && date.month === currentDateTime.month;
2105
+ if (!isCurrentMonth && outsideDays === "hidden") return {
2106
+ root: rootState,
2107
+ date,
2108
+ columnIndex,
2109
+ orientation,
2110
+ outsideMonth: true,
2111
+ hidden: true,
2112
+ selected: false,
2113
+ today: false,
2114
+ disabled: true,
2115
+ focused: false,
2116
+ rangeStart: false,
2117
+ rangeEnd: false,
2118
+ rangeBoundary: false,
2119
+ inRange: false,
2120
+ rangeIndex: false,
2121
+ rangeLength: false,
2122
+ rangeHasStart: false,
2123
+ rangeHasEnd: false,
2124
+ rangePreviewStart: false,
2125
+ rangePreviewEnd: false,
2126
+ rangePreviewBoundary: false,
2127
+ rangePreviewInRange: false,
2128
+ rangePreviewIndex: false,
2129
+ rangePreviewLength: false,
2130
+ rangePreviewHasStart: false,
2131
+ rangePreviewHasEnd: false,
2132
+ isTabTarget: false
2133
+ };
2134
+ const today = T.Now.plainDateISO();
2135
+ const isToday = T.PlainDate.compare(date, today) === 0;
2136
+ const isRange = selectionMode === "range";
2137
+ let isRangeStart = false;
2138
+ let isRangeEnd = false;
2139
+ let isInRangeDay = false;
2140
+ let rangeIdx = false;
2141
+ let rangeLen = false;
2142
+ let isPreviewRangeStart = false;
2143
+ let isPreviewRangeEnd = false;
2144
+ let isInPreviewRange = false;
2145
+ let previewIdx = false;
2146
+ let previewLen = false;
2147
+ if (isRange) {
2148
+ isRangeStart = rangeStart ? T.PlainDate.compare(date, rangeStart) === 0 : false;
2149
+ isRangeEnd = rangeEnd ? T.PlainDate.compare(date, rangeEnd) === 0 : false;
2150
+ isInRangeDay = isInRange(date, rangeStart, rangeEnd, T) !== false;
2151
+ const effectiveStart = rangeStart ?? rangeEnd;
2152
+ const effectiveEnd = rangeEnd ?? rangeStart;
2153
+ rangeIdx = isInRangeDay && effectiveStart ? date.since(effectiveStart).days : false;
2154
+ rangeLen = isInRangeDay && effectiveStart && effectiveEnd ? effectiveEnd.since(effectiveStart).days + 1 : false;
2155
+ isPreviewRangeStart = previewStart ? T.PlainDate.compare(date, previewStart) === 0 : false;
2156
+ isPreviewRangeEnd = previewEnd ? T.PlainDate.compare(date, previewEnd) === 0 : false;
2157
+ isInPreviewRange = previewStart && previewEnd ? isInRange(date, previewStart, previewEnd, T) !== false : false;
2158
+ previewIdx = isInPreviewRange && previewStart ? date.since(previewStart).days : false;
2159
+ previewLen = isInPreviewRange && previewStart && previewEnd ? previewEnd.since(previewStart).days + 1 : false;
2160
+ }
2161
+ const outsideNonInteractive = !isCurrentMonth && outsideDays !== "enabled";
2162
+ const suppressRange = !isCurrentMonth && (outsideDays === "disabled" || outsideDays === "hidden");
2163
+ if (outsideNonInteractive) return {
2164
+ root: rootState,
2165
+ date,
2166
+ columnIndex,
2167
+ orientation,
2168
+ outsideMonth: true,
2169
+ hidden: false,
2170
+ selected: false,
2171
+ today: isToday,
2172
+ disabled: true,
2173
+ focused: false,
2174
+ rangeStart: suppressRange ? false : isRangeStart,
2175
+ rangeEnd: suppressRange ? false : isRangeEnd,
2176
+ rangeBoundary: suppressRange ? false : isRangeStart || isRangeEnd,
2177
+ inRange: suppressRange ? false : isInRangeDay,
2178
+ rangeIndex: suppressRange ? false : rangeIdx,
2179
+ rangeLength: suppressRange ? false : rangeLen,
2180
+ rangeHasStart: suppressRange ? false : isInRangeDay && rangeStart !== void 0,
2181
+ rangeHasEnd: suppressRange ? false : isInRangeDay && rangeEnd !== void 0,
2182
+ rangePreviewStart: suppressRange ? false : isPreviewRangeStart,
2183
+ rangePreviewEnd: suppressRange ? false : isPreviewRangeEnd,
2184
+ rangePreviewBoundary: suppressRange ? false : isPreviewRangeStart || isPreviewRangeEnd,
2185
+ rangePreviewInRange: suppressRange ? false : isInPreviewRange,
2186
+ rangePreviewIndex: suppressRange ? false : previewIdx,
2187
+ rangePreviewLength: suppressRange ? false : previewLen,
2188
+ rangePreviewHasStart: suppressRange ? false : isInPreviewRange && previewStart !== void 0,
2189
+ rangePreviewHasEnd: suppressRange ? false : isInPreviewRange && previewEnd !== void 0,
2190
+ isTabTarget: false
2191
+ };
2192
+ const isSelected = selectionMode !== "range" ? selectedDates.some((d) => T.PlainDate.compare(d, date) === 0) : false;
2193
+ const isDisabled = disabled || (isDateDisabled?.(date) ?? false);
2194
+ const isFocused = T.PlainDate.compare(date, focusedDate) === 0;
2195
+ const isTabTarget = T.PlainDate.compare(date, tabTargetDate) === 0;
2196
+ return {
2197
+ root: rootState,
2198
+ date,
2199
+ columnIndex,
2200
+ orientation,
2201
+ selected: isSelected,
2202
+ today: isToday,
2203
+ disabled: isDisabled,
2204
+ outsideMonth: !isCurrentMonth,
2205
+ hidden: false,
2206
+ focused: isFocused,
2207
+ rangeStart: isRangeStart,
2208
+ rangeEnd: isRangeEnd,
2209
+ rangeBoundary: isRangeStart || isRangeEnd,
2210
+ inRange: isInRangeDay,
2211
+ rangeIndex: rangeIdx,
2212
+ rangeLength: rangeLen,
2213
+ rangeHasStart: isInRangeDay && rangeStart !== void 0,
2214
+ rangeHasEnd: isInRangeDay && rangeEnd !== void 0,
2215
+ rangePreviewStart: isPreviewRangeStart,
2216
+ rangePreviewEnd: isPreviewRangeEnd,
2217
+ rangePreviewBoundary: isPreviewRangeStart || isPreviewRangeEnd,
2218
+ rangePreviewInRange: isInPreviewRange,
2219
+ rangePreviewIndex: previewIdx,
2220
+ rangePreviewLength: previewLen,
2221
+ rangePreviewHasStart: isInPreviewRange && previewStart !== void 0,
2222
+ rangePreviewHasEnd: isInPreviewRange && previewEnd !== void 0,
2223
+ isTabTarget
2224
+ };
2225
+ }
2226
+ const dayStateAttributesMapping = {
2227
+ root: () => null,
2228
+ date: (v) => v ? { "data-date": v.toString() } : null,
2229
+ columnIndex: () => null,
2230
+ orientation: (v) => v ? { "data-orientation": v } : null,
2231
+ selected: (v) => v ? { "data-selected": "" } : null,
2232
+ today: (v) => v ? { "data-today": "" } : null,
2233
+ disabled: (v) => v ? { "data-disabled": "" } : null,
2234
+ outsideMonth: (v) => v ? { "data-outside-month": "" } : null,
2235
+ hidden: (v) => v ? { "data-hidden": "" } : null,
2236
+ focused: (v) => v ? { "data-focused": "" } : null,
2237
+ rangeStart: (v) => v ? { "data-range-start": "" } : null,
2238
+ rangeEnd: (v) => v ? { "data-range-end": "" } : null,
2239
+ rangeBoundary: (v) => v ? { "data-range-boundary": "" } : null,
2240
+ inRange: (v) => v ? { "data-in-range": "" } : null,
2241
+ rangeIndex: (v) => v !== false ? { "data-range-index": String(v) } : null,
2242
+ rangeLength: (v) => v !== false ? { "data-range-length": String(v) } : null,
2243
+ rangeHasStart: (v) => v ? { "data-range-has-start": "" } : null,
2244
+ rangeHasEnd: (v) => v ? { "data-range-has-end": "" } : null,
2245
+ rangePreviewStart: (v) => v ? { "data-range-preview-start": "" } : null,
2246
+ rangePreviewEnd: (v) => v ? { "data-range-preview-end": "" } : null,
2247
+ rangePreviewBoundary: (v) => v ? { "data-range-preview-boundary": "" } : null,
2248
+ rangePreviewInRange: (v) => v ? { "data-range-preview-in-range": "" } : null,
2249
+ rangePreviewIndex: (v) => v !== false ? { "data-range-preview-index": String(v) } : null,
2250
+ rangePreviewLength: (v) => v !== false ? { "data-range-preview-length": String(v) } : null,
2251
+ rangePreviewHasStart: (v) => v ? { "data-range-preview-has-start": "" } : null,
2252
+ rangePreviewHasEnd: (v) => v ? { "data-range-preview-has-end": "" } : null
2253
+ };
2254
+ function DayCellInstanceFn(props) {
2255
+ const { render, date, columnIndex, children, _derivedState, ...otherProps } = props;
2256
+ const state = _derivedState;
2257
+ const cell = (0, _base_ui_react_use_render.useRender)({
2258
+ defaultTagName: "td",
2259
+ render,
2260
+ ref: [],
2261
+ state,
2262
+ stateAttributesMapping: dayStateAttributesMapping,
2263
+ props: (0, _base_ui_react_merge_props.mergeProps)(state.hidden ? {
2264
+ role: "gridcell",
2265
+ "aria-hidden": true,
2266
+ children: null
2267
+ } : {
2268
+ role: "gridcell",
2269
+ "aria-selected": state.selected || void 0,
2270
+ "aria-disabled": state.disabled || void 0,
2271
+ children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, { _derivedState })
2272
+ }, otherProps)
2273
+ });
2274
+ const outsideDisabled = state.hidden || state.outsideMonth && state.disabled;
2275
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellDataContext.Provider, {
2276
+ value: {
2277
+ date,
2278
+ columnIndex,
2279
+ outsideDisabled
2280
+ },
2281
+ children: cell
2282
+ });
2283
+ }
2284
+ function dayCellInstancePropsAreEqual(prev, next) {
2285
+ if (prev.date !== next.date || prev.render !== next.render || prev.columnIndex !== next.columnIndex) return false;
2286
+ const a = prev._derivedState;
2287
+ const b = next._derivedState;
2288
+ return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget;
2289
+ }
2290
+ const DayCellInstance = (0, react.memo)(DayCellInstanceFn, dayCellInstancePropsAreEqual);
2291
+ /**
2292
+ * Renders one `<td role="gridcell">` per day. Exposes data-attributes for
2293
+ * `selected`, `today`, `disabled`, `outside-month`, `focused`,
2294
+ * `range-start`, `range-end`, `range-boundary`, `in-range`, and `date`.
2295
+ *
2296
+ * When used inside a {@link WeekTemplate}, iterates over that week's days.
2297
+ * An explicit `date` prop renders a single cell.
2298
+ */
2299
+ function DayCellTemplate(props) {
2300
+ const { date: dateProp, ...restProps } = props;
2301
+ const weekData = (0, react.useContext)(WeekDataContext);
2302
+ const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2303
+ const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2304
+ const viewCtx = useViewContext();
2305
+ const { focusedDate, tabTargetDate } = viewCtx;
2306
+ const monthStable = (0, react.useContext)(MonthViewStableContext);
2307
+ const { rootState, weeks, currentMonth: currentDateTime } = useMonthViewState();
2308
+ const outsideDays = monthStable?.outsideDays ?? "enabled";
2309
+ const isWeeksView = viewCtx.viewType === "weeks";
2310
+ const cellMonth = isWeeksView ? null : weekData?.gridMonth ?? currentDateTime;
2311
+ const { orientation } = (0, react.useContext)(GridContext);
2312
+ if (dateProp) {
2313
+ const daysInWeek = dateProp.daysInWeek;
2314
+ const derived = computeDayCellState(dateProp, orientation, (dateProp.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2315
+ year: dateProp.year,
2316
+ month: dateProp.month
2317
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2318
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2319
+ ...restProps,
2320
+ date: dateProp,
2321
+ _derivedState: derived
2322
+ });
2323
+ }
2324
+ const days = weekData ? weekData.days : weeks.flat();
2325
+ const perWeek = weekData != null;
2326
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: days.map((day, i) => {
2327
+ const daysInWeek = day.daysInWeek;
2328
+ const derived = computeDayCellState(day, orientation, perWeek ? i : (day.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, isWeeksView ? {
2329
+ year: day.year,
2330
+ month: day.month
2331
+ } : cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2332
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellInstance, {
2333
+ ...restProps,
2334
+ date: day,
2335
+ columnIndex: perWeek ? i : void 0,
2336
+ _derivedState: derived
2337
+ }, day.toString());
2338
+ }) });
2339
+ }
2340
+ function DayButtonInnerFn(props, ref) {
2341
+ const { render, date, _derivedState, ...otherProps } = props;
2342
+ const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
2343
+ const { setFocusedDate } = useViewContext();
2344
+ const gridFocusedRef = (0, react.useContext)(MonthViewStableContext).gridFocusedRef;
2345
+ const internalRef = (0, react.useRef)(null);
2346
+ const isHidden = _derivedState?.hidden ?? false;
2347
+ const isFocused = _derivedState?.focused ?? false;
2348
+ const isTabTarget = _derivedState?.isTabTarget ?? false;
2349
+ const isDisabled = _derivedState?.disabled ?? false;
2350
+ (0, react.useEffect)(() => {
2351
+ if (shouldMoveDomFocus(isFocused, gridFocusedRef.current) && internalRef.current) internalRef.current.focus();
2352
+ }, [isFocused, gridFocusedRef]);
2353
+ const state = _derivedState;
2354
+ const defaultProps = isHidden ? {} : {
2355
+ type: "button",
2356
+ tabIndex: isTabTarget ? 0 : -1,
2357
+ disabled: isDisabled,
2358
+ "aria-disabled": readOnly || void 0,
2359
+ "aria-label": date.toLocaleString(locale, {
2360
+ weekday: "long",
2361
+ month: "long",
2362
+ day: "numeric",
2363
+ year: "numeric"
2364
+ }),
2365
+ date: date.toString(),
2366
+ onClick: () => {
2367
+ setFocusedDate(date);
2368
+ onSelect(date);
2369
+ },
2370
+ onPointerEnter: () => {
2371
+ if (!isHidden && !isDisabled) setHoveredDate(date);
2372
+ },
2373
+ children: date.day
2374
+ };
2375
+ return (0, _base_ui_react_use_render.useRender)(isHidden ? {} : {
2376
+ defaultTagName: "button",
2377
+ render,
2378
+ ref: ref ? [ref, internalRef] : [internalRef],
2379
+ state,
2380
+ stateAttributesMapping: dayStateAttributesMapping,
2381
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
2382
+ });
2383
+ }
2384
+ function dayButtonInnerPropsAreEqual(prev, next) {
2385
+ if (prev.date !== next.date || prev.render !== next.render) return false;
2386
+ const a = prev._derivedState;
2387
+ const b = next._derivedState;
2388
+ if (!a || !b) return a === b;
2389
+ return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget;
2390
+ }
2391
+ const DayButtonInner = (0, react.memo)((0, react.forwardRef)(DayButtonInnerFn), dayButtonInnerPropsAreEqual);
2392
+ /**
2393
+ * Interactive `<button>` inside a day cell. Handles click-to-select,
2394
+ * roving tabindex, and imperative focus on keyboard navigation.
2395
+ *
2396
+ * Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
2397
+ */
2398
+ function DayButtonFn(props, ref) {
2399
+ const { date: dateProp, _derivedState, ...restProps } = props;
2400
+ const cellData = (0, react.useContext)(DayCellDataContext);
2401
+ const resolvedDate = dateProp ?? cellData?.date;
2402
+ if (resolvedDate) {
2403
+ if (_derivedState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
2404
+ ...restProps,
2405
+ ref,
2406
+ date: resolvedDate,
2407
+ _derivedState
2408
+ });
2409
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonFallback, {
2410
+ ref,
2411
+ ...restProps,
2412
+ date: resolvedDate
2413
+ });
2414
+ }
2415
+ throw new Error("DayButton must be used inside DayCellTemplate or receive an explicit date prop.");
2416
+ }
2417
+ const DayButton = (0, react.forwardRef)(DayButtonFn);
2418
+ /** Fallback for standalone DayButton usage that needs to read context. */
2419
+ function DayButtonFallbackFn(props, ref) {
2420
+ const { date, ...restProps } = props;
2421
+ const { orientation } = (0, react.useContext)(GridContext);
2422
+ const weekData = (0, react.useContext)(WeekDataContext);
2423
+ const { disabled, isDateDisabled, selectionMode, temporal: T, weekStartDay } = useCalendarStable();
2424
+ const { selectedDates, rangeStart, rangeEnd, previewStart, previewEnd } = useCalendarState();
2425
+ const viewCtx = useViewContext();
2426
+ const { focusedDate, tabTargetDate } = viewCtx;
2427
+ const monthStable = (0, react.useContext)(MonthViewStableContext);
2428
+ const { rootState, currentMonth: currentDateTime } = useMonthViewState();
2429
+ const outsideDays = monthStable?.outsideDays ?? "enabled";
2430
+ const cellMonth = viewCtx.viewType === "weeks" ? {
2431
+ year: date.year,
2432
+ month: date.month
2433
+ } : weekData?.gridMonth ?? currentDateTime;
2434
+ const daysInWeek = date.daysInWeek;
2435
+ const derived = computeDayCellState(date, orientation, (date.dayOfWeek % daysInWeek - weekStartDay + daysInWeek) % daysInWeek, rootState, selectedDates, cellMonth, disabled, isDateDisabled, focusedDate, rangeStart, rangeEnd, tabTargetDate, T, selectionMode, outsideDays, previewStart, previewEnd);
2436
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButtonInner, {
2437
+ ...restProps,
2438
+ ref,
2439
+ date,
2440
+ _derivedState: derived
2441
+ });
2442
+ }
2443
+ const DayButtonFallback = (0, react.forwardRef)(DayButtonFallbackFn);
2444
+ //#endregion
2445
+ //#region src/grid.tsx
2446
+ function useGridKeyboard() {
2447
+ const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
2448
+ const { focusedDate, setFocusedDate } = useViewContext();
2449
+ return (0, react.useCallback)((e) => {
2450
+ const result = computeNextFocusDate({
2451
+ key: e.key,
2452
+ shiftKey: e.shiftKey,
2453
+ focusedDate,
2454
+ minValue,
2455
+ maxValue,
2456
+ disabled,
2457
+ readOnly,
2458
+ isDateDisabled,
2459
+ T,
2460
+ weekStartDay
2461
+ });
2462
+ if (result.action === "move") {
2463
+ e.preventDefault();
2464
+ setFocusedDate(result.date);
2465
+ } else if (result.action === "select") {
2466
+ e.preventDefault();
2467
+ onSelect(focusedDate);
2468
+ }
2469
+ }, [
2470
+ focusedDate,
2471
+ setFocusedDate,
2472
+ onSelect,
2473
+ disabled,
2474
+ readOnly,
2475
+ isDateDisabled,
2476
+ minValue,
2477
+ maxValue,
2478
+ T,
2479
+ weekStartDay
2480
+ ]);
2481
+ }
2482
+ function useWeeksGridKeyboard() {
2483
+ const { onSelect, disabled, readOnly, isDateDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
2484
+ const { focusedDate, setFocusedDate } = useViewContext();
2485
+ const weeksStable = useWeeksViewStable();
2486
+ const weeksState = useWeeksViewState();
2487
+ return (0, react.useCallback)((e) => {
2488
+ const result = computeWeeksKeyNav({
2489
+ key: e.key,
2490
+ shiftKey: e.shiftKey,
2491
+ focusedDate,
2492
+ windowStart: weeksState.windowInfo.windowStart,
2493
+ weekCount: weeksStable.weekCount,
2494
+ minValue,
2495
+ maxValue,
2496
+ disabled,
2497
+ readOnly,
2498
+ isDateDisabled,
2499
+ scrollBy: weeksStable.scrollBy,
2500
+ T,
2501
+ weekStartDay
2502
+ });
2503
+ if (result.action === "move") {
2504
+ e.preventDefault();
2505
+ setFocusedDate(result.date);
2506
+ if (result.followFocus) weeksStable.scrollToWeek(result.date, { snap: "start" });
2507
+ else if (result.windowShift !== 0) weeksStable.scrollToWeek(result.date, { snap: "nearest" });
2508
+ } else if (result.action === "select") {
2509
+ e.preventDefault();
2510
+ onSelect(focusedDate);
2511
+ }
2512
+ }, [
2513
+ focusedDate,
2514
+ setFocusedDate,
2515
+ onSelect,
2516
+ disabled,
2517
+ readOnly,
2518
+ isDateDisabled,
2519
+ minValue,
2520
+ maxValue,
2521
+ T,
2522
+ weekStartDay,
2523
+ weeksStable,
2524
+ weeksState.windowInfo.windowStart
2525
+ ]);
2526
+ }
2527
+ const gridStateAttributesMapping = {
2528
+ root: () => null,
2529
+ month: () => null,
2530
+ year: () => null,
2531
+ orientation: (v) => ({ "data-orientation": v })
2532
+ };
2533
+ /**
2534
+ * Calendar grid container. Renders a `<table>` with `role="grid"` by default.
2535
+ *
2536
+ * Sets CSS custom properties `--calendar-days-per-week` and
2537
+ * `--calendar-weeks-in-month`, and matching `data-*` attributes.
2538
+ * Manages keyboard navigation, grid focus tracking, and
2539
+ * `aria-labelledby` linkage to {@link MonthYearString}.
2540
+ *
2541
+ * Automatically detects the active view type (MonthView or WeeksView) and
2542
+ * delegates to the appropriate internal renderer.
2543
+ */
2544
+ function GridFn(props, ref) {
2545
+ const monthState = (0, react.useContext)(MonthViewStableContext);
2546
+ const weeksState = (0, react.useContext)(WeeksViewStateContext);
2547
+ if (monthState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGrid, {
2548
+ ref,
2549
+ ...props
2550
+ });
2551
+ if (weeksState) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewGrid, {
2552
+ ref,
2553
+ ...props
2554
+ });
2555
+ throw new Error("Grid must be used inside MonthView.Root or WeeksView.Root.");
2556
+ }
2557
+ const Grid = (0, react.forwardRef)(GridFn);
2558
+ function MonthGridFn(props, ref) {
2559
+ const { render, mode: _mode, orientation, autoFocus, monthIndex: monthIndexProp, children, ...otherProps } = props;
2560
+ const monthIndex = monthIndexProp ?? 0;
2561
+ const { setHoveredDate } = useCalendarStable();
2562
+ const { setGridHasFocus } = useViewContext();
2563
+ const monthViewStable = useMonthViewStable();
2564
+ const monthViewState = useMonthViewState();
2565
+ const { gridFocusedRef } = monthViewStable;
2566
+ const { currentMonth: currentDateTime, gridLabelIds, rootState, weeks: defaultWeeks, allMonths } = monthViewState;
2567
+ if (monthIndex >= allMonths.length) console.warn(`[DatePicker] Grid monthIndex={${monthIndex}} is out of bounds (numberOfMonths=${allMonths.length}). Falling back to the first month.`);
2568
+ const monthData = allMonths[monthIndex];
2569
+ const gridWeeks = monthData?.weeks ?? defaultWeeks;
2570
+ const handleKeyDown = useGridKeyboard();
2571
+ const gridRef = (0, react.useRef)(null);
2572
+ (0, react.useEffect)(() => {
2573
+ if (autoFocus && gridRef.current) {
2574
+ const target = gridRef.current.querySelector("[tabindex=\"0\"]");
2575
+ if (target) {
2576
+ target.focus();
2577
+ gridFocusedRef.current = true;
2578
+ setGridHasFocus(true);
2579
+ }
2580
+ }
2581
+ }, [
2582
+ autoFocus,
2583
+ gridFocusedRef,
2584
+ setGridHasFocus
2585
+ ]);
2586
+ const resolvedOrientation = orientation ?? "horizontal";
2587
+ const daysPerWeek = gridWeeks[0]?.length ?? 7;
2588
+ const weeksInMonth = gridWeeks.length;
2589
+ const gridMonth = monthData ?? {
2590
+ year: currentDateTime.year,
2591
+ month: currentDateTime.month
2592
+ };
2593
+ const state = (0, react.useMemo)(() => ({
2594
+ root: rootState,
2595
+ month: gridMonth.month,
2596
+ year: gridMonth.year,
2597
+ orientation: resolvedOrientation
2598
+ }), [
2599
+ rootState,
2600
+ gridMonth.month,
2601
+ gridMonth.year,
2602
+ resolvedOrientation
2603
+ ]);
2604
+ const defaultProps = {
2605
+ role: "grid",
2606
+ "aria-labelledby": gridLabelIds[monthIndex] || void 0,
2607
+ "aria-label": gridLabelIds[monthIndex] ? void 0 : "Calendar",
2608
+ "data-days-per-week": daysPerWeek,
2609
+ "data-weeks-in-month": weeksInMonth,
2610
+ style: {
2611
+ "--calendar-days-per-week": daysPerWeek,
2612
+ "--calendar-weeks-in-month": weeksInMonth
2613
+ },
2614
+ onKeyDown: handleKeyDown,
2615
+ onFocus: () => {
2616
+ gridFocusedRef.current = true;
2617
+ setGridHasFocus(true);
2618
+ },
2619
+ onBlur: () => {
2620
+ gridFocusedRef.current = false;
2621
+ setGridHasFocus(false);
2622
+ },
2623
+ onPointerLeave: () => {
2624
+ setHoveredDate(void 0);
2625
+ },
2626
+ children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridHeader, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridHeaderCell, {}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridBody, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) })] })
2627
+ };
2628
+ const el = (0, _base_ui_react_use_render.useRender)({
2629
+ defaultTagName: "table",
2630
+ render,
2631
+ ref: ref ? [ref, gridRef] : [gridRef],
2632
+ state,
2633
+ stateAttributesMapping: gridStateAttributesMapping,
2634
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
2635
+ });
2636
+ const orientationCtx = (0, react.useMemo)(() => ({ orientation: resolvedOrientation }), [resolvedOrientation]);
2637
+ const monthCtx = (0, react.useMemo)(() => ({
2638
+ weeks: gridWeeks,
2639
+ year: gridMonth.year,
2640
+ month: gridMonth.month
2641
+ }), [
2642
+ gridWeeks,
2643
+ gridMonth.year,
2644
+ gridMonth.month
2645
+ ]);
2646
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridMonthContext.Provider, {
2647
+ value: monthCtx,
2648
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
2649
+ value: orientationCtx,
2650
+ children: el
2651
+ })
2652
+ });
2653
+ }
2654
+ const MonthGrid = (0, react.forwardRef)(MonthGridFn);
2655
+ function WeeksViewGridFn(props, ref) {
2656
+ const { render, mode: _mode, orientation, autoFocus, monthIndex: _monthIndex, children, ...otherProps } = props;
2657
+ const { setHoveredDate } = useCalendarStable();
2658
+ const { setGridHasFocus } = useViewContext();
2659
+ const weeksStable = useWeeksViewStable();
2660
+ const weeksState = useWeeksViewState();
2661
+ const { gridFocusedRef } = weeksStable;
2662
+ const { gridLabelIds, weeks, currentDateTime } = weeksState;
2663
+ const handleKeyDown = useWeeksGridKeyboard();
2664
+ const gridRef = (0, react.useRef)(null);
2665
+ (0, react.useEffect)(() => {
2666
+ if (autoFocus && gridRef.current) {
2667
+ const target = gridRef.current.querySelector("[tabindex=\"0\"]");
2668
+ if (target) {
2669
+ target.focus();
2670
+ gridFocusedRef.current = true;
2671
+ setGridHasFocus(true);
2672
+ }
2673
+ }
2674
+ }, [
2675
+ autoFocus,
2676
+ gridFocusedRef,
2677
+ setGridHasFocus
2678
+ ]);
2679
+ const resolvedOrientation = orientation ?? "horizontal";
2680
+ const weekCount = weeks.length;
2681
+ const firstWeek = weeks[0];
2682
+ const gridMonth = firstWeek ? {
2683
+ month: firstWeek.month,
2684
+ year: firstWeek.year
2685
+ } : {
2686
+ month: 1,
2687
+ year: 1970
2688
+ };
2689
+ const state = (0, react.useMemo)(() => ({
2690
+ root: {},
2691
+ month: gridMonth.month,
2692
+ year: gridMonth.year,
2693
+ orientation: resolvedOrientation
2694
+ }), [
2695
+ gridMonth.month,
2696
+ gridMonth.year,
2697
+ resolvedOrientation
2698
+ ]);
2699
+ const weekRowChildren = children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridHeader, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridHeaderCell, {}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksGrid, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) })] });
2700
+ const defaultProps = {
2701
+ role: "grid",
2702
+ "aria-labelledby": gridLabelIds[0] || void 0,
2703
+ "aria-label": gridLabelIds[0] ? void 0 : "Calendar",
2704
+ "data-days-per-week": 7,
2705
+ "data-weeks-in-month": weekCount,
2706
+ style: {
2707
+ "--calendar-days-per-week": 7,
2708
+ "--calendar-weeks-in-month": weekCount
2709
+ },
2710
+ onKeyDown: handleKeyDown,
2711
+ onFocus: () => {
2712
+ gridFocusedRef.current = true;
2713
+ setGridHasFocus(true);
2714
+ },
2715
+ onBlur: () => {
2716
+ gridFocusedRef.current = false;
2717
+ setGridHasFocus(false);
2718
+ },
2719
+ onPointerLeave: () => {
2720
+ setHoveredDate(void 0);
2721
+ },
2722
+ children: weekRowChildren
2723
+ };
2724
+ const el = (0, _base_ui_react_use_render.useRender)({
2725
+ defaultTagName: "table",
2726
+ render,
2727
+ ref: ref ? [ref, gridRef] : [gridRef],
2728
+ state,
2729
+ stateAttributesMapping: gridStateAttributesMapping,
2730
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
2731
+ });
2732
+ const orientationCtx = (0, react.useMemo)(() => ({ orientation: resolvedOrientation }), [resolvedOrientation]);
2733
+ const monthViewStableShim = (0, react.useMemo)(() => ({
2734
+ numberOfMonths: 1,
2735
+ fixedWeeks: false,
2736
+ outsideDays: "enabled",
2737
+ overflowBehavior: "unbounded",
2738
+ goNextMonth: () => {},
2739
+ goPrevMonth: () => {},
2740
+ setGridLabelId: () => {},
2741
+ gridFocusedRef
2742
+ }), [gridFocusedRef]);
2743
+ const monthViewStateShim = (0, react.useMemo)(() => ({
2744
+ currentMonth: {
2745
+ year: currentDateTime.year,
2746
+ month: currentDateTime.month
2747
+ },
2748
+ weeks: [],
2749
+ allMonths: [],
2750
+ currentDateTime,
2751
+ gridLabelIds,
2752
+ rootState: {}
2753
+ }), [currentDateTime, gridLabelIds]);
2754
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
2755
+ value: monthViewStableShim,
2756
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
2757
+ value: monthViewStateShim,
2758
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GridContext.Provider, {
2759
+ value: orientationCtx,
2760
+ children: el
2761
+ })
2762
+ })
2763
+ });
2764
+ }
2765
+ const WeeksViewGrid = (0, react.forwardRef)(WeeksViewGridFn);
2766
+ const gridBodyStateAttributesMapping = { root: () => null };
2767
+ /** Table body wrapping the week rows. Renders a `<tbody>` by default. */
2768
+ function GridBodyFn(props, ref) {
2769
+ if ((0, react.useContext)(WeeksViewStateContext)) {
2770
+ const { children, className, style } = props;
2771
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksGrid, {
2772
+ className,
2773
+ style,
2774
+ children
2775
+ });
2776
+ }
2777
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthGridBody, {
2778
+ ref,
2779
+ ...props
2780
+ });
2781
+ }
2782
+ const GridBody = (0, react.forwardRef)(GridBodyFn);
2783
+ function MonthGridBodyFn(props, ref) {
2784
+ const { render, ...otherProps } = props;
2785
+ const { rootState } = useMonthViewState();
2786
+ const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
2787
+ const defaultProps = { children: props.children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayCellTemplate, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DayButton, {}) }) }) };
2788
+ const { children: _children, ...restOtherProps } = otherProps;
2789
+ return (0, _base_ui_react_use_render.useRender)({
2790
+ defaultTagName: "tbody",
2791
+ render,
2792
+ ref: ref ? [ref] : [],
2793
+ state,
2794
+ stateAttributesMapping: gridBodyStateAttributesMapping,
2795
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, restOtherProps)
2796
+ });
2797
+ }
2798
+ const MonthGridBody = (0, react.forwardRef)(MonthGridBodyFn);
2799
+ const weekInstanceStateAttributesMapping = {
2800
+ root: () => null,
2801
+ weekIndex: () => null,
2802
+ gridRowIndex: () => null
2803
+ };
2804
+ function WeekInstance(props) {
2805
+ const { render, ...otherProps } = props;
2806
+ const weekData = (0, react.useContext)(WeekDataContext);
2807
+ const { rootState } = useMonthViewState();
2808
+ return (0, _base_ui_react_use_render.useRender)({
2809
+ defaultTagName: "tr",
2810
+ render,
2811
+ ref: [],
2812
+ state: (0, react.useMemo)(() => ({
2813
+ root: rootState,
2814
+ weekIndex: weekData.weekIndex,
2815
+ gridRowIndex: weekData.gridRowIndex
2816
+ }), [
2817
+ rootState,
2818
+ weekData.weekIndex,
2819
+ weekData.gridRowIndex
2820
+ ]),
2821
+ stateAttributesMapping: weekInstanceStateAttributesMapping,
2822
+ props: (0, _base_ui_react_merge_props.mergeProps)({}, otherProps)
2823
+ });
2824
+ }
2825
+ /**
2826
+ * Iterates over the weeks in the current month and renders one `<tr>` per week.
2827
+ * Each instance receives its week's days and index via {@link WeekDataContext}.
2828
+ */
2829
+ function WeekTemplate(props) {
2830
+ const outerWeekData = (0, react.useContext)(WeekDataContext);
2831
+ const gridMonthCtx = (0, react.useContext)(GridMonthContext);
2832
+ const { weeks: defaultWeeks } = useMonthViewState();
2833
+ const weeks = gridMonthCtx?.weeks ?? defaultWeeks;
2834
+ const gridMonth = (0, react.useMemo)(() => gridMonthCtx ? {
2835
+ year: gridMonthCtx.year,
2836
+ month: gridMonthCtx.month
2837
+ } : void 0, [gridMonthCtx]);
2838
+ const Instance = WeekInstance;
2839
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: weeks.map((weekDays, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeekDataContext.Provider, {
2840
+ value: {
2841
+ days: weekDays,
2842
+ weekIndex: i,
2843
+ gridMonth,
2844
+ gridRowIndex: outerWeekData?.gridRowIndex
2845
+ },
2846
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Instance, { ...props })
2847
+ }, weekDays[0].toString())) });
2848
+ }
2849
+ //#endregion
2850
+ //#region src/navigation.tsx
2851
+ const dateStringStateAttributesMapping = {
2852
+ root: () => null,
2853
+ month: () => null,
2854
+ year: () => null,
2855
+ day: () => null
2856
+ };
2857
+ const timeStringStateAttributesMapping = {
2858
+ root: () => null,
2859
+ hour: () => null,
2860
+ minute: () => null,
2861
+ second: () => null
2862
+ };
2863
+ const monthYearStringStateAttributesMapping = {
2864
+ root: () => null,
2865
+ month: () => null,
2866
+ year: () => null
2867
+ };
2868
+ function DateStringFn(props, ref) {
2869
+ const { render, locales, options, ...otherProps } = props;
2870
+ const { locale, temporal: T, timeZone } = useCalendarStable();
2871
+ const { selected } = useCalendarState();
2872
+ const { currentDateTime, rootState } = useMonthViewState();
2873
+ const selectedZdt = selectedToZdt(selected, timeZone, T);
2874
+ const displayDate = selectedZdt ? zdtToNativeDate(selectedZdt) : new Date(currentDateTime.year, currentDateTime.month - 1, 1);
2875
+ const formatted = displayDate.toLocaleDateString(locales ?? locale, options);
2876
+ const month = displayDate.getMonth() + 1;
2877
+ const year = displayDate.getFullYear();
2878
+ const day = displayDate.getDate();
2879
+ const state = (0, react.useMemo)(() => ({
2880
+ root: rootState,
2881
+ month,
2882
+ year,
2883
+ day
2884
+ }), [
2885
+ rootState,
2886
+ month,
2887
+ year,
2888
+ day
2889
+ ]);
2890
+ return (0, _base_ui_react_use_render.useRender)({
2891
+ defaultTagName: "span",
2892
+ render,
2893
+ ref: ref ? [ref] : [],
2894
+ state,
2895
+ stateAttributesMapping: dateStringStateAttributesMapping,
2896
+ props: (0, _base_ui_react_merge_props.mergeProps)({
2897
+ children: formatted,
2898
+ "aria-live": "polite"
2899
+ }, otherProps)
2900
+ });
2901
+ }
2902
+ /**
2903
+ * Displays the currently selected (or current) date as localized text.
2904
+ * Renders a `<span>` with `aria-live="polite"`.
2905
+ */
2906
+ const DateString = (0, react.forwardRef)(DateStringFn);
2907
+ function TimeStringFn(props, ref) {
2908
+ const { render, locales, options, ...otherProps } = props;
2909
+ const { locale, temporal: T, timeZone } = useCalendarStable();
2910
+ const { selected } = useCalendarState();
2911
+ const { rootState } = useMonthViewState();
2912
+ const selZdt = selectedToZdt(selected, timeZone, T);
2913
+ const displayDate = selZdt ? zdtToNativeDate(selZdt) : zdtToNativeDate(T.Now.zonedDateTimeISO(timeZone));
2914
+ const mergedOptions = {
2915
+ timeZone,
2916
+ ...options
2917
+ };
2918
+ const formatted = displayDate.toLocaleTimeString(locales ?? locale, mergedOptions);
2919
+ const nowZdt = selZdt ?? T.Now.zonedDateTimeISO(timeZone);
2920
+ const hour = nowZdt.hour;
2921
+ const minute = nowZdt.minute;
2922
+ const second = nowZdt.second;
2923
+ const state = (0, react.useMemo)(() => ({
2924
+ root: rootState,
2925
+ hour,
2926
+ minute,
2927
+ second
2928
+ }), [
2929
+ rootState,
2930
+ hour,
2931
+ minute,
2932
+ second
2933
+ ]);
2934
+ return (0, _base_ui_react_use_render.useRender)({
2935
+ defaultTagName: "span",
2936
+ render,
2937
+ ref: ref ? [ref] : [],
2938
+ state,
2939
+ stateAttributesMapping: timeStringStateAttributesMapping,
2940
+ props: (0, _base_ui_react_merge_props.mergeProps)({
2941
+ children: formatted,
2942
+ "aria-live": "polite"
2943
+ }, otherProps)
2944
+ });
2945
+ }
2946
+ /**
2947
+ * Displays the currently selected time as localized text.
2948
+ * Falls back to the current time when nothing is selected.
2949
+ * Renders a `<span>` with `aria-live="polite"`.
2950
+ */
2951
+ const TimeString = (0, react.forwardRef)(TimeStringFn);
2952
+ function MonthYearStringFn(props, ref) {
2953
+ const { render, locales, options, monthIndex: monthIndexProp, ...otherProps } = props;
2954
+ const monthIndex = monthIndexProp ?? 0;
2955
+ const { locale } = useCalendarStable();
2956
+ const monthViewStable = useMonthViewStable();
2957
+ const { currentMonth: currentDateTime, allMonths, rootState } = useMonthViewState();
2958
+ const { setGridLabelId } = monthViewStable;
2959
+ const id = (0, react.useId)();
2960
+ (0, react.useEffect)(() => {
2961
+ setGridLabelId(monthIndex, id);
2962
+ return () => setGridLabelId(monthIndex, void 0);
2963
+ }, [
2964
+ id,
2965
+ setGridLabelId,
2966
+ monthIndex
2967
+ ]);
2968
+ const monthData = allMonths[monthIndex];
2969
+ const displayYear = monthData?.year ?? currentDateTime.year;
2970
+ const displayMonth = monthData?.month ?? currentDateTime.month;
2971
+ const displayDate = new Date(displayYear, displayMonth - 1, 1);
2972
+ const defaultOptions = options ?? {
2973
+ month: "long",
2974
+ year: "numeric"
2975
+ };
2976
+ const formatted = displayDate.toLocaleDateString(locales ?? locale, defaultOptions);
2977
+ const state = (0, react.useMemo)(() => ({
2978
+ root: rootState,
2979
+ month: displayMonth,
2980
+ year: displayYear
2981
+ }), [
2982
+ rootState,
2983
+ displayMonth,
2984
+ displayYear
2985
+ ]);
2986
+ return (0, _base_ui_react_use_render.useRender)({
2987
+ defaultTagName: "span",
2988
+ render,
2989
+ ref: ref ? [ref] : [],
2990
+ state,
2991
+ stateAttributesMapping: monthYearStringStateAttributesMapping,
2992
+ props: (0, _base_ui_react_merge_props.mergeProps)({
2993
+ id,
2994
+ children: formatted,
2995
+ "aria-live": "polite"
2996
+ }, otherProps)
2997
+ });
2998
+ }
2999
+ /**
3000
+ * Displays the currently viewed month and year as a live-region heading for the
3001
+ * calendar grid. Defaults to `{ month: "long", year: "numeric" }` (e.g.
3002
+ * "March 2026"). Automatically registers a unique `id` so that `Grid` can
3003
+ * reference it via `aria-labelledby`.
3004
+ *
3005
+ * **Accessibility requirement:** When using a custom `render` function or custom
3006
+ * `options` that change the displayed format, both the month and year **must**
3007
+ * remain accessible to screen readers within this component. This element is
3008
+ * referenced by the calendar grid's `aria-labelledby` and serves as its
3009
+ * accessible name.
3010
+ */
3011
+ const MonthYearString = (0, react.forwardRef)(MonthYearStringFn);
3012
+ function useNavButton(direction) {
3013
+ const { disabled: globalDisabled, minValue, maxValue, locale, temporal: T } = useCalendarStable();
3014
+ const monthViewStable = useMonthViewStable();
3015
+ const monthViewState = useMonthViewState();
3016
+ const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths } = monthViewStable;
3017
+ const { currentMonth: currentDateTime, allMonths, rootState } = monthViewState;
3018
+ const refMonth = direction === "next" ? allMonths[numberOfMonths - 1] ?? currentDateTime : currentDateTime;
3019
+ const destMonth = direction === "prev" ? refMonth.month === 1 ? 12 : refMonth.month - 1 : refMonth.month === 12 ? 1 : refMonth.month + 1;
3020
+ const destYear = direction === "prev" ? refMonth.month === 1 ? refMonth.year - 1 : refMonth.year : refMonth.month === 12 ? refMonth.year + 1 : refMonth.year;
3021
+ const boundValue = direction === "prev" ? minValue : maxValue;
3022
+ const isDisabled = (0, react.useMemo)(() => {
3023
+ if (globalDisabled) return true;
3024
+ if (!boundValue) return false;
3025
+ if (direction === "prev") return destYear < boundValue.year || destYear === boundValue.year && destMonth < boundValue.month;
3026
+ return destYear > boundValue.year || destYear === boundValue.year && destMonth > boundValue.month;
3027
+ }, [
3028
+ globalDisabled,
3029
+ destYear,
3030
+ destMonth,
3031
+ boundValue,
3032
+ direction
3033
+ ]);
3034
+ const localeCalendar = (0, react.useMemo)(() => calendarForLocale(locale), [locale]);
3035
+ const target = (0, react.useMemo)(() => T.PlainYearMonth.from({
3036
+ year: destYear,
3037
+ month: destMonth,
3038
+ calendar: localeCalendar
3039
+ }), [
3040
+ destYear,
3041
+ destMonth,
3042
+ T,
3043
+ localeCalendar
3044
+ ]);
3045
+ return {
3046
+ state: (0, react.useMemo)(() => ({
3047
+ root: rootState,
3048
+ direction,
3049
+ disabled: isDisabled,
3050
+ target
3051
+ }), [
3052
+ rootState,
3053
+ direction,
3054
+ isDisabled,
3055
+ target
3056
+ ]),
3057
+ defaultProps: {
3058
+ type: "button",
3059
+ "aria-label": `Go to ${direction === "prev" ? "previous" : "next"} month`,
3060
+ disabled: isDisabled,
3061
+ onClick: isDisabled ? void 0 : direction === "prev" ? goToPrevMonth : goToNextMonth
3062
+ }
3063
+ };
3064
+ }
3065
+ const navButtonStateAttributesMapping = {
3066
+ root: () => null,
3067
+ direction: (v) => ({ "data-direction": v }),
3068
+ disabled: () => null,
3069
+ target: () => null
3070
+ };
3071
+ function PrevMonthButtonFn(props, ref) {
3072
+ const { render, ...otherProps } = props;
3073
+ const { state, defaultProps } = useNavButton("prev");
3074
+ return (0, _base_ui_react_use_render.useRender)({
3075
+ defaultTagName: "button",
3076
+ render,
3077
+ ref: ref ? [ref] : [],
3078
+ state,
3079
+ stateAttributesMapping: navButtonStateAttributesMapping,
3080
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
3081
+ });
3082
+ }
3083
+ /**
3084
+ * Button that navigates to the previous month. Automatically disabled
3085
+ * when the previous month falls before `min`. Exposes `data-direction="prev"`.
3086
+ */
3087
+ const PrevMonthButton = (0, react.forwardRef)(PrevMonthButtonFn);
3088
+ function NextMonthButtonFn(props, ref) {
3089
+ const { render, ...otherProps } = props;
3090
+ const { state, defaultProps } = useNavButton("next");
3091
+ return (0, _base_ui_react_use_render.useRender)({
3092
+ defaultTagName: "button",
3093
+ render,
3094
+ ref: ref ? [ref] : [],
3095
+ state,
3096
+ stateAttributesMapping: navButtonStateAttributesMapping,
3097
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
3098
+ });
3099
+ }
3100
+ /**
3101
+ * Button that navigates to the next month. Automatically disabled
3102
+ * when the next month falls after `max`. Exposes `data-direction="next"`.
3103
+ */
3104
+ const NextMonthButton = (0, react.forwardRef)(NextMonthButtonFn);
3105
+ //#endregion
3106
+ //#region src/selected-range.tsx
3107
+ const rangeOverlayStateAttributesMapping = {
3108
+ root: () => null,
3109
+ active: (v) => v ? { "data-active": "" } : null,
3110
+ weekIndex: (v) => ({ "data-week-index": String(v) }),
3111
+ startIndex: (v) => ({ "data-start-index": String(v) }),
3112
+ endIndex: (v) => ({ "data-end-index": String(v) }),
3113
+ startDate: (v) => v ? { "data-start-date": v } : null,
3114
+ endDate: (v) => v ? { "data-end-date": v } : null,
3115
+ extendsBefore: (v) => v ? { "data-extends-before": "" } : null,
3116
+ extendsAfter: (v) => v ? { "data-extends-after": "" } : null,
3117
+ hasStart: (v) => v ? { "data-has-start": "" } : null,
3118
+ hasEnd: (v) => v ? { "data-has-end": "" } : null,
3119
+ orientation: (v) => ({ "data-orientation": v })
3120
+ };
3121
+ function computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gridMonth) {
3122
+ const raw = computeWeekRangeInfo(days, rangeStart, rangeEnd, T);
3123
+ if ((outsideDays === "disabled" || outsideDays === "hidden") && raw.active && gridMonth) {
3124
+ let { startIndex, endIndex, extendsBefore, extendsAfter } = raw;
3125
+ while (startIndex <= endIndex && (days[startIndex].year !== gridMonth.year || days[startIndex].month !== gridMonth.month)) {
3126
+ startIndex++;
3127
+ extendsBefore = true;
3128
+ }
3129
+ while (endIndex >= startIndex && (days[endIndex].year !== gridMonth.year || days[endIndex].month !== gridMonth.month)) {
3130
+ endIndex--;
3131
+ extendsAfter = true;
3132
+ }
3133
+ if (startIndex > endIndex) return {
3134
+ active: false,
3135
+ startIndex: 0,
3136
+ endIndex: 0,
3137
+ extendsBefore: false,
3138
+ extendsAfter: false
3139
+ };
3140
+ return {
3141
+ active: true,
3142
+ startIndex,
3143
+ endIndex,
3144
+ extendsBefore,
3145
+ extendsAfter
3146
+ };
3147
+ }
3148
+ return raw;
3149
+ }
3150
+ function RangeSelectedFn(props, ref) {
3151
+ const { selectionMode } = useCalendarStable();
3152
+ if (selectionMode !== "range") return null;
3153
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangeSelectedInner, {
3154
+ ref,
3155
+ ...props
3156
+ });
3157
+ }
3158
+ /**
3159
+ * Visual overlay (`<td role="presentation">`) that highlights the selected
3160
+ * date range within a single week row. Exposes data-attributes for
3161
+ * `active`, `week-index`, `start-index`, `end-index`, `start-date`,
3162
+ * `end-date`, `extends-before`, and `extends-after`.
3163
+ */
3164
+ const RangeSelected = (0, react.forwardRef)(RangeSelectedFn);
3165
+ function RangeSelectedInnerFn(props, ref) {
3166
+ const { render, ...otherProps } = props;
3167
+ const weekData = (0, react.useContext)(WeekDataContext);
3168
+ const { orientation } = (0, react.useContext)(GridContext);
3169
+ const { temporal: T } = useCalendarStable();
3170
+ const { rangeStart, rangeEnd } = useCalendarState();
3171
+ const monthStable = (0, react.useContext)(MonthViewStableContext);
3172
+ const { rootState } = useMonthViewState();
3173
+ const outsideDays = monthStable?.outsideDays ?? "enabled";
3174
+ const days = weekData?.days ?? [];
3175
+ const gridMonth = weekData?.gridMonth;
3176
+ const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gridMonth), [
3177
+ days,
3178
+ rangeStart,
3179
+ rangeEnd,
3180
+ T,
3181
+ outsideDays,
3182
+ gridMonth
3183
+ ]);
3184
+ const startDate = info.active ? days[info.startIndex].toString() : "";
3185
+ const endDate = info.active ? days[info.endIndex].toString() : "";
3186
+ const weekIndex = weekData?.weekIndex ?? 0;
3187
+ const state = (0, react.useMemo)(() => ({
3188
+ root: rootState,
3189
+ active: info.active,
3190
+ weekIndex,
3191
+ startIndex: info.startIndex,
3192
+ endIndex: info.endIndex,
3193
+ startDate,
3194
+ endDate,
3195
+ extendsBefore: info.extendsBefore,
3196
+ extendsAfter: info.extendsAfter,
3197
+ hasStart: rangeStart !== void 0,
3198
+ hasEnd: rangeEnd !== void 0,
3199
+ orientation
3200
+ }), [
3201
+ rootState,
3202
+ info,
3203
+ weekIndex,
3204
+ startDate,
3205
+ endDate,
3206
+ rangeStart,
3207
+ rangeEnd,
3208
+ orientation
3209
+ ]);
3210
+ return (0, _base_ui_react_use_render.useRender)({
3211
+ defaultTagName: "td",
3212
+ render,
3213
+ ref: ref ? [ref] : [],
3214
+ state,
3215
+ stateAttributesMapping: rangeOverlayStateAttributesMapping,
3216
+ props: (0, _base_ui_react_merge_props.mergeProps)({
3217
+ role: "presentation",
3218
+ "aria-hidden": true
3219
+ }, otherProps)
3220
+ });
3221
+ }
3222
+ const RangeSelectedInner = (0, react.forwardRef)(RangeSelectedInnerFn);
3223
+ //#endregion
3224
+ //#region src/range-preview.tsx
3225
+ function RangePreviewFn(props, ref) {
3226
+ const { selectionMode } = useCalendarStable();
3227
+ if (selectionMode !== "range") return null;
3228
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangePreviewInner, {
3229
+ ref,
3230
+ ...props
3231
+ });
3232
+ }
3233
+ /**
3234
+ * Visual overlay (`<td role="presentation">`) that highlights the hover
3235
+ * preview range within a single week row. Structurally identical to
3236
+ * {@link RangeSelected} but reads `previewStart`/`previewEnd` instead of
3237
+ * the committed range boundaries.
3238
+ */
3239
+ const RangePreview = (0, react.forwardRef)(RangePreviewFn);
3240
+ function RangePreviewInnerFn(props, ref) {
3241
+ const { render, ...otherProps } = props;
3242
+ const weekData = (0, react.useContext)(WeekDataContext);
3243
+ const { orientation } = (0, react.useContext)(GridContext);
3244
+ const { temporal: T } = useCalendarStable();
3245
+ const { previewStart, previewEnd } = useCalendarState();
3246
+ const monthStable = (0, react.useContext)(MonthViewStableContext);
3247
+ const { rootState } = useMonthViewState();
3248
+ const outsideDays = monthStable?.outsideDays ?? "enabled";
3249
+ const days = weekData?.days ?? [];
3250
+ const gridMonth = weekData?.gridMonth;
3251
+ const info = (0, react.useMemo)(() => computeClippedRangeInfo(days, previewStart, previewEnd, T, outsideDays, gridMonth), [
3252
+ days,
3253
+ previewStart,
3254
+ previewEnd,
3255
+ T,
3256
+ outsideDays,
3257
+ gridMonth
3258
+ ]);
3259
+ const startDate = info.active ? days[info.startIndex].toString() : "";
3260
+ const endDate = info.active ? days[info.endIndex].toString() : "";
3261
+ const weekIndex = weekData?.weekIndex ?? 0;
3262
+ const state = (0, react.useMemo)(() => ({
3263
+ root: rootState,
3264
+ active: info.active,
3265
+ weekIndex,
3266
+ startIndex: info.startIndex,
3267
+ endIndex: info.endIndex,
3268
+ startDate,
3269
+ endDate,
3270
+ extendsBefore: info.extendsBefore,
3271
+ extendsAfter: info.extendsAfter,
3272
+ hasStart: previewStart !== void 0,
3273
+ hasEnd: previewEnd !== void 0,
3274
+ orientation
3275
+ }), [
3276
+ rootState,
3277
+ info,
3278
+ weekIndex,
3279
+ startDate,
3280
+ endDate,
3281
+ previewStart,
3282
+ previewEnd,
3283
+ orientation
3284
+ ]);
3285
+ return (0, _base_ui_react_use_render.useRender)({
3286
+ defaultTagName: "td",
3287
+ render,
3288
+ ref: ref ? [ref] : [],
3289
+ state,
3290
+ stateAttributesMapping: rangeOverlayStateAttributesMapping,
3291
+ props: (0, _base_ui_react_merge_props.mergeProps)({
3292
+ role: "presentation",
3293
+ "aria-hidden": true
3294
+ }, otherProps)
3295
+ });
3296
+ }
3297
+ const RangePreviewInner = (0, react.forwardRef)(RangePreviewInnerFn);
3298
+ //#endregion
3299
+ //#region src/drag-handle.tsx
3300
+ const dragHandleStateAttributesMapping = {
3301
+ root: () => null,
3302
+ active: (v) => v ? { "data-active": "" } : null,
3303
+ dragging: (v) => v ? { "data-dragging": "" } : null,
3304
+ edge: (v) => ({ "data-edge": v }),
3305
+ orientation: (v) => ({ "data-orientation": v })
3306
+ };
3307
+ function useDragHandle(edge, { dragging: draggingProp }) {
3308
+ const { temporal: T, setHoveredDate, readOnly, disabled } = useCalendarStable();
3309
+ const { rangeStart, rangeEnd } = useCalendarState();
3310
+ const { rootState } = useMonthViewState();
3311
+ const cellData = (0, react.useContext)(DayCellDataContext);
3312
+ const { orientation } = (0, react.useContext)(GridContext);
3313
+ const date = cellData?.date;
3314
+ const outsideDisabled = cellData?.outsideDisabled ?? false;
3315
+ const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
3316
+ const isDragging = (draggingProp ?? false) && isActive;
3317
+ const handleRef = (0, react.useRef)(null);
3318
+ return {
3319
+ state: (0, react.useMemo)(() => ({
3320
+ root: rootState,
3321
+ active: isActive,
3322
+ dragging: isDragging,
3323
+ edge,
3324
+ orientation
3325
+ }), [
3326
+ rootState,
3327
+ isActive,
3328
+ isDragging,
3329
+ edge,
3330
+ orientation
3331
+ ]),
3332
+ stateAttributesMapping: dragHandleStateAttributesMapping,
3333
+ defaultProps: {
3334
+ role: "slider",
3335
+ "aria-roledescription": "drag handle",
3336
+ "aria-label": edge === "start" ? "Range start date" : "Range end date",
3337
+ "aria-valuetext": date?.toString(),
3338
+ "aria-grabbed": isActive ? isDragging : void 0,
3339
+ "aria-hidden": isActive ? void 0 : true,
3340
+ onPointerEnter: () => {
3341
+ if (date && !outsideDisabled) setHoveredDate(date);
3342
+ }
3343
+ },
3344
+ handleRef
3345
+ };
3346
+ }
3347
+ function RangeDragHandleFn(props, ref) {
3348
+ const { render, dragging, edge, ...otherProps } = props;
3349
+ const { state, stateAttributesMapping, defaultProps, handleRef } = useDragHandle(edge, { dragging });
3350
+ const { selectionMode } = useCalendarStable();
3351
+ const { rangeStart: rs, rangeEnd: re } = useCalendarState();
3352
+ return (0, _base_ui_react_use_render.useRender)(selectionMode !== "range" || !rs || !re ? {} : {
3353
+ defaultTagName: "span",
3354
+ render,
3355
+ ref: ref ? [ref, handleRef] : [handleRef],
3356
+ state,
3357
+ stateAttributesMapping,
3358
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
3359
+ });
3360
+ }
3361
+ /**
3362
+ * Drag handle (`<span>`) rendered at a range boundary. Exposes
3363
+ * `data-active`, `data-dragging`, and `data-edge` attributes.
3364
+ */
3365
+ const RangeDragHandle = (0, react.forwardRef)(RangeDragHandleFn);
3366
+ function RangeStartDragHandleFn(props, ref) {
3367
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangeDragHandle, {
3368
+ edge: "start",
3369
+ ref,
3370
+ ...props
3371
+ });
3372
+ }
3373
+ /** Convenience wrapper for {@link RangeDragHandle} with `edge="start"`. */
3374
+ const RangeStartDragHandle = (0, react.forwardRef)(RangeStartDragHandleFn);
3375
+ function RangeEndDragHandleFn(props, ref) {
3376
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RangeDragHandle, {
3377
+ edge: "end",
3378
+ ref,
3379
+ ...props
3380
+ });
3381
+ }
3382
+ /** Convenience wrapper for {@link RangeDragHandle} with `edge="end"`. */
3383
+ const RangeEndDragHandle = (0, react.forwardRef)(RangeEndDragHandleFn);
3384
+ //#endregion
3385
+ //#region src/week-number.tsx
3386
+ const weekNumberCellStateAttributesMapping = {
3387
+ root: () => null,
3388
+ weekNumber: (v) => ({ "data-week-number": String(v) })
3389
+ };
3390
+ function WeekNumberCellFn(props, ref) {
3391
+ const { render, ...otherProps } = props;
3392
+ const weekData = (0, react.useContext)(WeekDataContext);
3393
+ const { rootState } = useMonthViewState();
3394
+ const { temporal: T } = useCalendarStable();
3395
+ const days = weekData?.days ?? [];
3396
+ const weekNumber = (0, react.useMemo)(() => {
3397
+ if (days.length === 0) return 0;
3398
+ let thursday = days[0];
3399
+ for (const d of days) if (d.dayOfWeek === 4) {
3400
+ thursday = d;
3401
+ break;
3402
+ }
3403
+ return getISOWeekNumber(thursday, T);
3404
+ }, [days, T]);
3405
+ const state = (0, react.useMemo)(() => ({
3406
+ root: rootState,
3407
+ weekNumber
3408
+ }), [rootState, weekNumber]);
3409
+ const defaultProps = {
3410
+ role: "rowheader",
3411
+ "aria-label": `Week ${weekNumber}`,
3412
+ children: weekNumber
3413
+ };
3414
+ return (0, _base_ui_react_use_render.useRender)({
3415
+ defaultTagName: "td",
3416
+ render,
3417
+ ref: ref ? [ref] : [],
3418
+ state,
3419
+ stateAttributesMapping: weekNumberCellStateAttributesMapping,
3420
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
3421
+ });
3422
+ }
3423
+ /**
3424
+ * Renders the ISO 8601 week number for a week row. Must be used inside
3425
+ * a {@link WeekTemplate}. Renders a `<td>` with `role="rowheader"`.
3426
+ */
3427
+ const WeekNumberCell = (0, react.forwardRef)(WeekNumberCellFn);
3428
+ const weekNumberHeaderStateAttributesMapping = { root: () => null };
3429
+ function WeekNumberHeaderFn(props, ref) {
3430
+ const { render, ...otherProps } = props;
3431
+ const { rootState } = useMonthViewState();
3432
+ const state = (0, react.useMemo)(() => ({ root: rootState }), [rootState]);
3433
+ return (0, _base_ui_react_use_render.useRender)({
3434
+ defaultTagName: "th",
3435
+ render,
3436
+ ref: ref ? [ref] : [],
3437
+ state,
3438
+ stateAttributesMapping: weekNumberHeaderStateAttributesMapping,
3439
+ props: (0, _base_ui_react_merge_props.mergeProps)({
3440
+ scope: "col",
3441
+ "aria-label": "Week number",
3442
+ children: "#"
3443
+ }, otherProps)
3444
+ });
3445
+ }
3446
+ /**
3447
+ * Column header for the week number column. Renders a `<th scope="col">`.
3448
+ */
3449
+ const WeekNumberHeader = (0, react.forwardRef)(WeekNumberHeaderFn);
3450
+ //#endregion
3451
+ //#region src/compute-weeks-in-window.ts
3452
+ /**
3453
+ * Computes an array of week descriptors for a continuous window.
3454
+ * `firstWeek` is snapped back to the nearest `weekStartDay`.
3455
+ */
3456
+ function computeWeeksInWindow(firstWeek, weekCount, weekStartDay, _T) {
3457
+ const offset = (firstWeek.dayOfWeek % 7 - weekStartDay + 7) % 7;
3458
+ let weekStart = firstWeek.subtract({ days: offset });
3459
+ const weeks = [];
3460
+ for (let i = 0; i < weekCount; i++) {
3461
+ const endDate = weekStart.add({ days: 6 });
3462
+ weeks.push({
3463
+ startDate: weekStart,
3464
+ endDate,
3465
+ weekIndex: i,
3466
+ month: weekStart.month,
3467
+ year: weekStart.year
3468
+ });
3469
+ weekStart = weekStart.add({ weeks: 1 });
3470
+ }
3471
+ return weeks;
3472
+ }
3473
+ //#endregion
3474
+ //#region src/overflow.ts
3475
+ /** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
3476
+ function weekHasValidDay(weekStart, min, max, T) {
3477
+ const weekEnd = weekStart.add({ days: 6 });
3478
+ return T.PlainDate.compare(weekStart, max) <= 0 && T.PlainDate.compare(weekEnd, min) >= 0;
3479
+ }
3480
+ /**
3481
+ * Returns the start of the week (per weekStartDay) that contains the given date.
3482
+ * Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
3483
+ */
3484
+ function weekStartContaining(date, weekStartDay, _T) {
3485
+ const daysFromStart = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3486
+ return date.subtract({ days: daysFromStart });
3487
+ }
3488
+ /** Find the week start (per weekStartDay) whose 7-day span contains min. */
3489
+ function findFirstValidWeekStart(min, weekStartDay, T) {
3490
+ return weekStartContaining(min, weekStartDay, T);
3491
+ }
3492
+ /** Find the week start (per weekStartDay) whose 7-day span contains max. */
3493
+ function findLastValidWeekStart(max, weekStartDay, T) {
3494
+ return weekStartContaining(max, weekStartDay, T);
3495
+ }
3496
+ /**
3497
+ * Trim leading and trailing fully-disabled weeks from a window.
3498
+ * Returns new { firstWeek, weekCount }.
3499
+ */
3500
+ function shrinkWindow(firstWeek, weekCount, min, max, T) {
3501
+ let start = 0;
3502
+ let end = weekCount - 1;
3503
+ while (start <= end) {
3504
+ if (weekHasValidDay(firstWeek.add({ days: start * 7 }), min, max, T)) break;
3505
+ start++;
3506
+ }
3507
+ while (end >= start) {
3508
+ if (weekHasValidDay(firstWeek.add({ days: end * 7 }), min, max, T)) break;
3509
+ end--;
3510
+ }
3511
+ if (start > end) return {
3512
+ firstWeek,
3513
+ weekCount
3514
+ };
3515
+ return {
3516
+ firstWeek: firstWeek.add({ days: start * 7 }),
3517
+ weekCount: end - start + 1
3518
+ };
3519
+ }
3520
+ /**
3521
+ * Given a target firstWeek and weekCount, apply overflow behavior and return
3522
+ * the adjusted { firstWeek, weekCount }.
3523
+ */
3524
+ function applyOverflow({ targetFirstWeek, weekCount, behavior, min, max, weekStartDay, T }) {
3525
+ if (!min || !max || behavior === "unbounded") return {
3526
+ firstWeek: targetFirstWeek,
3527
+ weekCount
3528
+ };
3529
+ if (behavior === "stop") return {
3530
+ firstWeek: targetFirstWeek,
3531
+ weekCount
3532
+ };
3533
+ if (behavior === "stop-shrink") return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
3534
+ if (behavior === "snap" || behavior === "snap-shrink") {
3535
+ const lastValid = findLastValidWeekStart(max, weekStartDay, T);
3536
+ const snappedFirst = lastValid.subtract({ days: (weekCount - 1) * 7 });
3537
+ const targetLastWeek = targetFirstWeek.add({ days: (weekCount - 1) * 7 });
3538
+ let resolvedFirst;
3539
+ if (T.PlainDate.compare(targetLastWeek, lastValid) <= 0) {
3540
+ const firstValid = findFirstValidWeekStart(min, weekStartDay, T);
3541
+ if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) resolvedFirst = targetFirstWeek;
3542
+ else resolvedFirst = firstValid;
3543
+ } else resolvedFirst = snappedFirst;
3544
+ if (behavior === "snap-shrink") return shrinkWindow(resolvedFirst, weekCount, min, max, T);
3545
+ return {
3546
+ firstWeek: resolvedFirst,
3547
+ weekCount
3548
+ };
3549
+ }
3550
+ return {
3551
+ firstWeek: targetFirstWeek,
3552
+ weekCount
3553
+ };
3554
+ }
3555
+ /**
3556
+ * Returns whether the navigation button for the given direction should be enabled.
3557
+ */
3558
+ function canShift({ currentFirstWeek, weekCount, direction, shiftBy, behavior, min, max, weekStartDay, T }) {
3559
+ if (behavior === "unbounded" || !min || !max) return true;
3560
+ const shift = shiftBy ?? weekCount;
3561
+ const targetFirstWeek = currentFirstWeek.add({ days: direction * shift * 7 });
3562
+ if (behavior === "stop" || behavior === "stop-shrink") {
3563
+ for (let i = 0; i < weekCount; i++) if (weekHasValidDay(targetFirstWeek.add({ days: i * 7 }), min, max, T)) return true;
3564
+ return false;
3565
+ }
3566
+ if (behavior === "snap" || behavior === "snap-shrink") {
3567
+ const applied = applyOverflow({
3568
+ targetFirstWeek,
3569
+ weekCount,
3570
+ behavior,
3571
+ min,
3572
+ max,
3573
+ weekStartDay,
3574
+ T
3575
+ });
3576
+ return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
3577
+ }
3578
+ return true;
3579
+ }
3580
+ //#endregion
3581
+ //#region src/resolve-first-week.ts
3582
+ /** Snaps `date` back to the start of its containing week (determined by `weekStartDay`). */
3583
+ function snapToWeekStart(date, weekStartDay) {
3584
+ const offset = (date.dayOfWeek % 7 - weekStartDay + 7) % 7;
3585
+ return date.subtract({ days: offset });
3586
+ }
3587
+ /**
3588
+ * Resolves any {@link FirstWeekSpec} variant to the `PlainDate` of the
3589
+ * containing week's start (snapped to `weekStartDay`).
3590
+ *
3591
+ * @param spec - The week specifier to resolve.
3592
+ * @param weekStartDay - Day the calendar week starts on (`0` = Sunday).
3593
+ * @param T - Temporal namespace.
3594
+ * @param timeZone - IANA time zone for native `Date` conversion. Defaults to system time zone.
3595
+ */
3596
+ function resolveFirstWeekSpec(spec, weekStartDay, T, timeZone) {
3597
+ if ("calendar" in spec) return snapToWeekStart(spec, weekStartDay);
3598
+ if (spec instanceof Date) {
3599
+ const tz = timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
3600
+ const parts = new Intl.DateTimeFormat("en-US", {
3601
+ timeZone: tz,
3602
+ year: "numeric",
3603
+ month: "numeric",
3604
+ day: "numeric"
3605
+ }).formatToParts(spec);
3606
+ const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? 0);
3607
+ return snapToWeekStart(T.PlainDate.from({
3608
+ year: get("year"),
3609
+ month: get("month"),
3610
+ day: get("day")
3611
+ }), weekStartDay);
3612
+ }
3613
+ if ("isoWeek" in spec) {
3614
+ const { isoWeek, isoYear } = spec;
3615
+ const jan4 = T.PlainDate.from({
3616
+ year: isoYear,
3617
+ month: 1,
3618
+ day: 4
3619
+ });
3620
+ const jan4dow = jan4.dayOfWeek;
3621
+ return snapToWeekStart(jan4.subtract({ days: jan4dow - 1 }).add({ weeks: isoWeek - 1 }), weekStartDay);
3622
+ }
3623
+ if ("week" in spec && !("month" in spec)) {
3624
+ const { week, year } = spec;
3625
+ const jan1 = T.PlainDate.from({
3626
+ year,
3627
+ month: 1,
3628
+ day: 1
3629
+ });
3630
+ const daysUntilStart = (weekStartDay - jan1.dayOfWeek % 7 + 7) % 7;
3631
+ return jan1.add({ days: daysUntilStart }).add({ weeks: week - 1 });
3632
+ }
3633
+ const { month, year, day } = spec;
3634
+ const targetDay = day ?? 1;
3635
+ return snapToWeekStart(T.PlainDate.from({
3636
+ year,
3637
+ month,
3638
+ day: targetDay
3639
+ }), weekStartDay);
3640
+ }
3641
+ /**
3642
+ * Computes a new `firstWeek` date given a scroll target and snap mode.
3643
+ *
3644
+ * The `weekStartDay` is inferred from `currentFirstWeek` (its day of week).
3645
+ *
3646
+ * @param currentFirstWeek - The current first visible week (a week-start date).
3647
+ * @param weekCount - Number of visible week rows.
3648
+ * @param target - The week-start date to scroll to.
3649
+ * @param options - Optional snap mode (default `"start"`).
3650
+ */
3651
+ function resolveFirstWeek(currentFirstWeek, weekCount, target, options) {
3652
+ switch (options?.snap ?? "start") {
3653
+ case "start": return target;
3654
+ case "center": return target.subtract({ weeks: Math.floor(weekCount / 2) });
3655
+ case "end": return target.subtract({ weeks: weekCount - 1 });
3656
+ case "nearest": {
3657
+ const lastWeek = currentFirstWeek.add({ weeks: weekCount - 1 });
3658
+ const cmp = (a, b) => {
3659
+ if (a.year !== b.year) return a.year - b.year;
3660
+ if (a.month !== b.month) return a.month - b.month;
3661
+ return a.day - b.day;
3662
+ };
3663
+ if (cmp(target, currentFirstWeek) < 0) return target;
3664
+ if (cmp(target, lastWeek) > 0) return target.subtract({ weeks: weekCount - 1 });
3665
+ return currentFirstWeek;
3666
+ }
3667
+ }
3668
+ }
3669
+ //#endregion
3670
+ //#region src/weeks-view-state.ts
3671
+ /**
3672
+ * Core state management hook for WeeksView.Root.
3673
+ * Reads calendar-level context and manages weeks-specific state.
3674
+ */
3675
+ function useWeeksViewRootState(props) {
3676
+ const { weekCount, firstWeek: firstWeekProp, defaultFirstWeek: defaultFirstWeekProp, onFirstWeekChange, scrollBy: scrollByProp, overflowBehavior: overflowBehaviorProp, onWindowChange } = props;
3677
+ const scrollBy = scrollByProp ?? "row";
3678
+ const overflowBehavior = overflowBehaviorProp ?? "unbounded";
3679
+ const calStable = useCalendarStable();
3680
+ const calState = useCalendarState();
3681
+ const T = calStable.temporal;
3682
+ const { weekStartDay, isDateDisabled, minValue, maxValue, timeZone } = calStable;
3683
+ const isControlled = firstWeekProp !== void 0;
3684
+ const resolveSpec = (0, react.useCallback)((spec) => resolveFirstWeekSpec(spec, weekStartDay, T), [weekStartDay, T]);
3685
+ const [internalFirstWeek, setInternalFirstWeek] = (0, react.useState)(() => {
3686
+ if (firstWeekProp !== void 0) return resolveSpec(firstWeekProp);
3687
+ if (defaultFirstWeekProp !== void 0) return resolveSpec(defaultFirstWeekProp);
3688
+ if (calState.selected) return resolveSpec(toZonedDateTime(calState.selected, timeZone, T).toPlainDate());
3689
+ return resolveSpec(T.Now.plainDateISO());
3690
+ });
3691
+ const resolvedFirstWeek = isControlled ? resolveSpec(firstWeekProp) : internalFirstWeek;
3692
+ const rawWeeks = (0, react.useMemo)(() => computeWeeksInWindow(resolvedFirstWeek, weekCount, weekStartDay, T), [
3693
+ resolvedFirstWeek,
3694
+ weekCount,
3695
+ weekStartDay,
3696
+ T
3697
+ ]);
3698
+ const overflowResult = (0, react.useMemo)(() => applyOverflow({
3699
+ targetFirstWeek: resolvedFirstWeek,
3700
+ weekCount,
3701
+ behavior: overflowBehavior,
3702
+ min: minValue,
3703
+ max: maxValue,
3704
+ weekStartDay,
3705
+ T
3706
+ }), [
3707
+ resolvedFirstWeek,
3708
+ weekCount,
3709
+ overflowBehavior,
3710
+ minValue,
3711
+ maxValue,
3712
+ weekStartDay,
3713
+ T
3714
+ ]);
3715
+ const adjustedWeeks = (0, react.useMemo)(() => {
3716
+ const sameFirst = T.PlainDate.compare(overflowResult.firstWeek, resolvedFirstWeek) === 0;
3717
+ const sameCount = overflowResult.weekCount === weekCount;
3718
+ if (sameFirst && sameCount) return rawWeeks;
3719
+ return computeWeeksInWindow(overflowResult.firstWeek, overflowResult.weekCount, weekStartDay, T);
3720
+ }, [
3721
+ overflowResult,
3722
+ resolvedFirstWeek,
3723
+ weekCount,
3724
+ rawWeeks,
3725
+ weekStartDay,
3726
+ T
3727
+ ]);
3728
+ const isDateEnabled = (0, react.useCallback)((date) => {
3729
+ if (minValue && T.PlainDate.compare(date, minValue) < 0) return false;
3730
+ if (maxValue && T.PlainDate.compare(date, maxValue) > 0) return false;
3731
+ if (isDateDisabled?.(date)) return false;
3732
+ return true;
3733
+ }, [
3734
+ minValue,
3735
+ maxValue,
3736
+ isDateDisabled,
3737
+ T
3738
+ ]);
3739
+ const windowInfo = (0, react.useMemo)(() => {
3740
+ const weeks = adjustedWeeks;
3741
+ if (weeks.length === 0) {
3742
+ const today = T.Now.plainDateISO();
3743
+ return {
3744
+ windowStart: today,
3745
+ windowEnd: today,
3746
+ weekCount: 0,
3747
+ dayCount: 0,
3748
+ enabledWeekCount: 0,
3749
+ enabledDayCount: 0,
3750
+ visibleMonths: []
3751
+ };
3752
+ }
3753
+ const windowStart = weeks[0].startDate;
3754
+ const windowEnd = weeks[weeks.length - 1].endDate;
3755
+ const wc = weeks.length;
3756
+ const dayCount = wc * 7;
3757
+ let enabledDayCount = 0;
3758
+ let enabledWeekCount = 0;
3759
+ for (const week of weeks) {
3760
+ let weekHasEnabled = false;
3761
+ let day = week.startDate;
3762
+ for (let d = 0; d < 7; d++) {
3763
+ if (isDateEnabled(day)) {
3764
+ enabledDayCount++;
3765
+ weekHasEnabled = true;
3766
+ }
3767
+ if (d < 6) day = day.add({ days: 1 });
3768
+ }
3769
+ if (weekHasEnabled) enabledWeekCount++;
3770
+ }
3771
+ const visibleMonths = [];
3772
+ const seenMonths = /* @__PURE__ */ new Set();
3773
+ for (const week of weeks) {
3774
+ let day = week.startDate;
3775
+ for (let d = 0; d < 7; d++) {
3776
+ const key = `${day.year}-${day.month}`;
3777
+ if (!seenMonths.has(key)) {
3778
+ seenMonths.add(key);
3779
+ visibleMonths.push({
3780
+ month: day.month,
3781
+ year: day.year
3782
+ });
3783
+ }
3784
+ if (d < 6) day = day.add({ days: 1 });
3785
+ }
3786
+ }
3787
+ return {
3788
+ windowStart,
3789
+ windowEnd,
3790
+ weekCount: wc,
3791
+ dayCount,
3792
+ enabledWeekCount,
3793
+ enabledDayCount,
3794
+ visibleMonths
3795
+ };
3796
+ }, [
3797
+ adjustedWeeks,
3798
+ isDateEnabled,
3799
+ T
3800
+ ]);
3801
+ const selectedPlain = (0, react.useMemo)(() => {
3802
+ if (!calState.selected) return void 0;
3803
+ return selectedToZdt(calState.selected, timeZone, T)?.toPlainDate();
3804
+ }, [
3805
+ calState.selected,
3806
+ timeZone,
3807
+ T
3808
+ ]);
3809
+ const isInWindow = (0, react.useCallback)((date) => {
3810
+ return T.PlainDate.compare(date, windowInfo.windowStart) >= 0 && T.PlainDate.compare(date, windowInfo.windowEnd) <= 0;
3811
+ }, [
3812
+ windowInfo.windowStart,
3813
+ windowInfo.windowEnd,
3814
+ T
3815
+ ]);
3816
+ const [focusedDate, setFocusedDate] = (0, react.useState)(() => {
3817
+ if (selectedPlain && isInWindow(selectedPlain)) return selectedPlain;
3818
+ return windowInfo.windowStart;
3819
+ });
3820
+ (0, react.useEffect)(() => {
3821
+ setFocusedDate((prev) => {
3822
+ if (isInWindow(prev)) return prev;
3823
+ return windowInfo.windowStart;
3824
+ });
3825
+ }, [windowInfo.windowStart, isInWindow]);
3826
+ const [gridHasFocus, setGridHasFocus] = (0, react.useState)(false);
3827
+ const gridFocusedRef = (0, react.useRef)(false);
3828
+ const [gridLabelIds, setGridLabelIds] = (0, react.useState)({});
3829
+ const setGridLabelId = (0, react.useCallback)((id) => {
3830
+ setGridLabelIds((prev) => {
3831
+ const key = 0;
3832
+ if (id === void 0) {
3833
+ if (!(key in prev)) return prev;
3834
+ const next = { ...prev };
3835
+ delete next[key];
3836
+ return next;
3837
+ }
3838
+ if (prev[key] === id) return prev;
3839
+ return {
3840
+ ...prev,
3841
+ [key]: id
3842
+ };
3843
+ });
3844
+ }, []);
3845
+ const tabTargetDate = (0, react.useMemo)(() => {
3846
+ const allDays = [];
3847
+ for (const week of adjustedWeeks) {
3848
+ let day = week.startDate;
3849
+ for (let d = 0; d < 7; d++) {
3850
+ allDays.push(day);
3851
+ if (d < 6) day = day.add({ days: 1 });
3852
+ }
3853
+ }
3854
+ const inGrid = (d) => allDays.some((g) => T.PlainDate.compare(g, d) === 0);
3855
+ if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
3856
+ if (selectedPlain && inGrid(selectedPlain)) return selectedPlain;
3857
+ if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
3858
+ return allDays.find((d) => isDateEnabled(d)) ?? allDays[0] ?? windowInfo.windowStart;
3859
+ }, [
3860
+ adjustedWeeks,
3861
+ focusedDate,
3862
+ selectedPlain,
3863
+ gridHasFocus,
3864
+ isDateEnabled,
3865
+ T,
3866
+ windowInfo.windowStart
3867
+ ]);
3868
+ const selectedZdt = (0, react.useMemo)(() => selectedToZdt(calState.selected, timeZone, T), [
3869
+ calState.selected,
3870
+ timeZone,
3871
+ T
3872
+ ]);
3873
+ const currentDateTime = (0, react.useMemo)(() => T.PlainDateTime.from({
3874
+ year: windowInfo.windowStart.year,
3875
+ month: windowInfo.windowStart.month,
3876
+ day: focusedDate.day,
3877
+ hour: selectedZdt?.hour ?? 0,
3878
+ minute: selectedZdt?.minute ?? 0,
3879
+ second: selectedZdt?.second ?? 0
3880
+ }, { overflow: "constrain" }), [
3881
+ windowInfo.windowStart,
3882
+ focusedDate.day,
3883
+ selectedZdt,
3884
+ T
3885
+ ]);
3886
+ const updateFirstWeek = (0, react.useCallback)((newFirstWeek) => {
3887
+ if (!isControlled) setInternalFirstWeek(newFirstWeek);
3888
+ onFirstWeekChange?.(newFirstWeek);
3889
+ }, [isControlled, onFirstWeekChange]);
3890
+ const goNext = (0, react.useCallback)((shiftBy) => {
3891
+ const shift = shiftBy ?? weekCount;
3892
+ updateFirstWeek(applyOverflow({
3893
+ targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
3894
+ weekCount,
3895
+ behavior: overflowBehavior,
3896
+ min: minValue,
3897
+ max: maxValue,
3898
+ weekStartDay,
3899
+ T
3900
+ }).firstWeek);
3901
+ }, [
3902
+ resolvedFirstWeek,
3903
+ weekCount,
3904
+ overflowBehavior,
3905
+ minValue,
3906
+ maxValue,
3907
+ weekStartDay,
3908
+ T,
3909
+ updateFirstWeek
3910
+ ]);
3911
+ const goPrev = (0, react.useCallback)((shiftBy) => {
3912
+ const shift = shiftBy ?? weekCount;
3913
+ updateFirstWeek(applyOverflow({
3914
+ targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
3915
+ weekCount,
3916
+ behavior: overflowBehavior,
3917
+ min: minValue,
3918
+ max: maxValue,
3919
+ weekStartDay,
3920
+ T
3921
+ }).firstWeek);
3922
+ }, [
3923
+ resolvedFirstWeek,
3924
+ weekCount,
3925
+ overflowBehavior,
3926
+ minValue,
3927
+ maxValue,
3928
+ weekStartDay,
3929
+ T,
3930
+ updateFirstWeek
3931
+ ]);
3932
+ const scrollToWeek = (0, react.useCallback)((target, options) => {
3933
+ updateFirstWeek(applyOverflow({
3934
+ targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
3935
+ weekCount,
3936
+ behavior: overflowBehavior,
3937
+ min: minValue,
3938
+ max: maxValue,
3939
+ weekStartDay,
3940
+ T
3941
+ }).firstWeek);
3942
+ }, [
3943
+ resolvedFirstWeek,
3944
+ weekCount,
3945
+ resolveSpec,
3946
+ overflowBehavior,
3947
+ minValue,
3948
+ maxValue,
3949
+ weekStartDay,
3950
+ T,
3951
+ updateFirstWeek
3952
+ ]);
3953
+ const onWindowChangeRef = (0, react.useRef)(onWindowChange);
3954
+ onWindowChangeRef.current = onWindowChange;
3955
+ const prevWindowInfoRef = (0, react.useRef)(null);
3956
+ (0, react.useEffect)(() => {
3957
+ const prev = prevWindowInfoRef.current;
3958
+ if (!prev || T.PlainDate.compare(prev.windowStart, windowInfo.windowStart) !== 0 || T.PlainDate.compare(prev.windowEnd, windowInfo.windowEnd) !== 0 || prev.weekCount !== windowInfo.weekCount) {
3959
+ prevWindowInfoRef.current = windowInfo;
3960
+ onWindowChangeRef.current?.(windowInfo);
3961
+ }
3962
+ }, [windowInfo, T]);
3963
+ return {
3964
+ stableCtx: (0, react.useMemo)(() => ({
3965
+ weekCount,
3966
+ scrollBy,
3967
+ overflowBehavior,
3968
+ goNext,
3969
+ goPrev,
3970
+ scrollToWeek,
3971
+ gridFocusedRef,
3972
+ setGridLabelId
3973
+ }), [
3974
+ weekCount,
3975
+ scrollBy,
3976
+ overflowBehavior,
3977
+ goNext,
3978
+ goPrev,
3979
+ scrollToWeek,
3980
+ setGridLabelId
3981
+ ]),
3982
+ stateCtx: (0, react.useMemo)(() => ({
3983
+ focusedDate,
3984
+ windowInfo,
3985
+ gridLabelIds,
3986
+ weeks: adjustedWeeks,
3987
+ currentDateTime
3988
+ }), [
3989
+ focusedDate,
3990
+ windowInfo,
3991
+ gridLabelIds,
3992
+ adjustedWeeks,
3993
+ currentDateTime
3994
+ ]),
3995
+ viewCtx: (0, react.useMemo)(() => ({
3996
+ viewType: "weeks",
3997
+ focusedDate,
3998
+ setFocusedDate,
3999
+ tabTargetDate,
4000
+ gridHasFocus,
4001
+ setGridHasFocus
4002
+ }), [
4003
+ focusedDate,
4004
+ tabTargetDate,
4005
+ gridHasFocus
4006
+ ]),
4007
+ scrollToWeek
4008
+ };
4009
+ }
4010
+ //#endregion
4011
+ //#region src/weeks-view.tsx
4012
+ function WeeksViewRootFn(props, ref) {
4013
+ const { children } = props;
4014
+ const { stableCtx, stateCtx, viewCtx, scrollToWeek } = useWeeksViewRootState(props);
4015
+ (0, react.useImperativeHandle)(ref, () => ({ scrollToWeek }), [scrollToWeek]);
4016
+ const gridFocusedRef = (0, react.useRef)(false);
4017
+ const monthViewStableShim = (0, react.useMemo)(() => ({
4018
+ numberOfMonths: 1,
4019
+ fixedWeeks: false,
4020
+ outsideDays: "enabled",
4021
+ overflowBehavior: "unbounded",
4022
+ goNextMonth: () => {},
4023
+ goPrevMonth: () => {},
4024
+ setGridLabelId: () => {},
4025
+ gridFocusedRef
4026
+ }), []);
4027
+ const monthViewStateShim = (0, react.useMemo)(() => ({
4028
+ currentMonth: {
4029
+ year: stateCtx.currentDateTime.year,
4030
+ month: stateCtx.currentDateTime.month
4031
+ },
4032
+ weeks: [],
4033
+ allMonths: [],
4034
+ currentDateTime: stateCtx.currentDateTime,
4035
+ gridLabelIds: stateCtx.gridLabelIds,
4036
+ rootState: {}
4037
+ }), [stateCtx.currentDateTime, stateCtx.gridLabelIds]);
4038
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStableContext.Provider, {
4039
+ value: monthViewStableShim,
4040
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MonthViewStateContext.Provider, {
4041
+ value: monthViewStateShim,
4042
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStableContext.Provider, {
4043
+ value: stableCtx,
4044
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewStateContext.Provider, {
4045
+ value: stateCtx,
4046
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewContext.Provider, {
4047
+ value: viewCtx,
4048
+ children
4049
+ })
4050
+ })
4051
+ })
4052
+ })
4053
+ });
4054
+ }
4055
+ const WeeksViewRoot = (0, react.forwardRef)(WeeksViewRootFn);
4056
+ function WeeksViewFn(props, ref) {
4057
+ const { weekCount, firstWeek, defaultFirstWeek, onFirstWeekChange, scrollBy, overflowBehavior, onWindowChange, children, ...calendarProps } = props;
4058
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarProvider, {
4059
+ ...calendarProps,
4060
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WeeksViewRoot, {
4061
+ ref,
4062
+ weekCount,
4063
+ firstWeek,
4064
+ defaultFirstWeek,
4065
+ onFirstWeekChange,
4066
+ scrollBy,
4067
+ overflowBehavior,
4068
+ onWindowChange,
4069
+ children
4070
+ })
4071
+ });
4072
+ }
4073
+ const WeeksView = (0, react.forwardRef)(WeeksViewFn);
4074
+ WeeksView.Root = WeeksViewRoot;
4075
+ //#endregion
4076
+ //#region src/weeks-navigation.tsx
4077
+ const weeksNavButtonStateAttributesMapping = {
4078
+ root: () => null,
4079
+ direction: (v) => ({ "data-direction": v }),
4080
+ disabled: () => null
4081
+ };
4082
+ const weekCountStateAttributesMapping = {
4083
+ root: () => null,
4084
+ weekCount: () => null
4085
+ };
4086
+ function useWeeksNavButton(direction, shiftByProp) {
4087
+ const { disabled: globalDisabled, minValue, maxValue, temporal: T, weekStartDay } = useCalendarStable();
4088
+ const { weekCount, overflowBehavior, goNext, goPrev } = useWeeksViewStable();
4089
+ const { windowInfo } = useWeeksViewState();
4090
+ const { rootState } = useMonthViewState();
4091
+ const currentFirstWeek = windowInfo.windowStart;
4092
+ const isDisabled = (0, react.useMemo)(() => {
4093
+ if (globalDisabled) return true;
4094
+ return !canShift({
4095
+ currentFirstWeek,
4096
+ weekCount,
4097
+ direction: direction === "next" ? 1 : -1,
4098
+ shiftBy: shiftByProp,
4099
+ behavior: overflowBehavior,
4100
+ min: minValue,
4101
+ max: maxValue,
4102
+ weekStartDay,
4103
+ T
4104
+ });
4105
+ }, [
4106
+ globalDisabled,
4107
+ currentFirstWeek,
4108
+ weekCount,
4109
+ direction,
4110
+ shiftByProp,
4111
+ overflowBehavior,
4112
+ minValue,
4113
+ maxValue,
4114
+ weekStartDay,
4115
+ T
4116
+ ]);
4117
+ const state = (0, react.useMemo)(() => ({
4118
+ root: rootState,
4119
+ direction,
4120
+ disabled: isDisabled
4121
+ }), [
4122
+ rootState,
4123
+ direction,
4124
+ isDisabled
4125
+ ]);
4126
+ const goFn = direction === "prev" ? goPrev : goNext;
4127
+ return {
4128
+ state,
4129
+ defaultProps: {
4130
+ type: "button",
4131
+ "aria-label": `Go to ${direction === "prev" ? "previous" : "next"} weeks`,
4132
+ disabled: isDisabled,
4133
+ onClick: isDisabled ? void 0 : () => goFn(shiftByProp)
4134
+ }
4135
+ };
4136
+ }
4137
+ function PrevWeeksButtonFn(props, ref) {
4138
+ const { render, shiftBy, ...otherProps } = props;
4139
+ const { state, defaultProps } = useWeeksNavButton("prev", shiftBy);
4140
+ return (0, _base_ui_react_use_render.useRender)({
4141
+ defaultTagName: "button",
4142
+ render,
4143
+ ref: ref ? [ref] : [],
4144
+ state,
4145
+ stateAttributesMapping: weeksNavButtonStateAttributesMapping,
4146
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
4147
+ });
4148
+ }
4149
+ /**
4150
+ * Button that navigates to the previous week(s). Automatically disabled when
4151
+ * no more weeks are available based on `overflowBehavior` and `min`.
4152
+ * Exposes `data-direction="prev"`.
4153
+ */
4154
+ const PrevWeeksButton = (0, react.forwardRef)(PrevWeeksButtonFn);
4155
+ function NextWeeksButtonFn(props, ref) {
4156
+ const { render, shiftBy, ...otherProps } = props;
4157
+ const { state, defaultProps } = useWeeksNavButton("next", shiftBy);
4158
+ return (0, _base_ui_react_use_render.useRender)({
4159
+ defaultTagName: "button",
4160
+ render,
4161
+ ref: ref ? [ref] : [],
4162
+ state,
4163
+ stateAttributesMapping: weeksNavButtonStateAttributesMapping,
4164
+ props: (0, _base_ui_react_merge_props.mergeProps)(defaultProps, otherProps)
4165
+ });
4166
+ }
4167
+ /**
4168
+ * Button that navigates to the next week(s). Automatically disabled when
4169
+ * no more weeks are available based on `overflowBehavior` and `max`.
4170
+ * Exposes `data-direction="next"`.
4171
+ */
4172
+ const NextWeeksButton = (0, react.forwardRef)(NextWeeksButtonFn);
4173
+ function WeekCountFn(props, ref) {
4174
+ const { render, ...otherProps } = props;
4175
+ const { windowInfo } = useWeeksViewState();
4176
+ const { rootState } = useMonthViewState();
4177
+ const count = windowInfo.weekCount;
4178
+ const state = (0, react.useMemo)(() => ({
4179
+ root: rootState,
4180
+ weekCount: count
4181
+ }), [rootState, count]);
4182
+ return (0, _base_ui_react_use_render.useRender)({
4183
+ defaultTagName: "span",
4184
+ render,
4185
+ ref: ref ? [ref] : [],
4186
+ state,
4187
+ stateAttributesMapping: weekCountStateAttributesMapping,
4188
+ props: (0, _base_ui_react_merge_props.mergeProps)({ children: count }, otherProps)
4189
+ });
4190
+ }
4191
+ /**
4192
+ * Renders the current visible week count as a number. Useful with shrink
4193
+ * overflow modes where the actual count may be less than the `weekCount` prop.
4194
+ */
4195
+ const WeekCount = (0, react.forwardRef)(WeekCountFn);
4196
+ //#endregion
4197
+ //#region src/temporal-polyfill.ts
4198
+ function daysInMonth(year, month) {
4199
+ return new Date(year, month, 0).getDate();
4200
+ }
4201
+ function toUTC(y, m, d) {
4202
+ return Date.UTC(y, m - 1, d);
4203
+ }
4204
+ function isoWeekday(utcDate) {
4205
+ const dow = utcDate.getUTCDay();
4206
+ return dow === 0 ? 7 : dow;
4207
+ }
4208
+ function pad2(n) {
4209
+ return n < 10 ? `0${n}` : `${n}`;
4210
+ }
4211
+ function clamp(val, min, max) {
4212
+ return val < min ? min : val > max ? max : val;
4213
+ }
4214
+ function parseDateISO(str) {
4215
+ const [datePart] = str.split("T");
4216
+ const [y, m, d] = datePart.split("-").map(Number);
4217
+ return {
4218
+ year: y,
4219
+ month: m,
4220
+ day: d
4221
+ };
4222
+ }
4223
+ function parseDateTimeISO(str) {
4224
+ const [datePart, timePart] = str.split("T");
4225
+ const [y, m, d] = datePart.split("-").map(Number);
4226
+ if (!timePart) return {
4227
+ year: y,
4228
+ month: m,
4229
+ day: d,
4230
+ hour: 0,
4231
+ minute: 0,
4232
+ second: 0
4233
+ };
4234
+ const [h, min, s] = timePart.split(":").map(Number);
4235
+ return {
4236
+ year: y,
4237
+ month: m,
4238
+ day: d,
4239
+ hour: h || 0,
4240
+ minute: min || 0,
4241
+ second: s || 0
4242
+ };
4243
+ }
4244
+ const dtfCache = /* @__PURE__ */ new Map();
4245
+ function getDTF(tz) {
4246
+ let dtf = dtfCache.get(tz);
4247
+ if (!dtf) {
4248
+ dtf = new Intl.DateTimeFormat("en-US", {
4249
+ timeZone: tz,
4250
+ year: "numeric",
4251
+ month: "numeric",
4252
+ day: "numeric",
4253
+ hour: "numeric",
4254
+ minute: "numeric",
4255
+ second: "numeric",
4256
+ hour12: false
4257
+ });
4258
+ dtfCache.set(tz, dtf);
4259
+ }
4260
+ return dtf;
4261
+ }
4262
+ function extractTzParts(epochMs, tz) {
4263
+ const parts = getDTF(tz).formatToParts(new Date(epochMs));
4264
+ const vals = {};
4265
+ for (const p of parts) if (p.type !== "literal") vals[p.type] = Number(p.value);
4266
+ return {
4267
+ year: vals.year,
4268
+ month: vals.month,
4269
+ day: vals.day,
4270
+ hour: vals.hour === 24 ? 0 : vals.hour,
4271
+ minute: vals.minute,
4272
+ second: vals.second
4273
+ };
4274
+ }
4275
+ function wallToEpoch(y, m, d, h, min, s, tz) {
4276
+ const utcGuess = Date.UTC(y, m - 1, d, h, min, s);
4277
+ const inTz = extractTzParts(utcGuess, tz);
4278
+ return utcGuess - (Date.UTC(inTz.year, inTz.month - 1, inTz.day, inTz.hour, inTz.minute, inTz.second) - utcGuess);
4279
+ }
4280
+ var MiniPlainDate = class MiniPlainDate {
4281
+ year;
4282
+ month;
4283
+ day;
4284
+ constructor(year, month, day) {
4285
+ this.year = year;
4286
+ this.month = month;
4287
+ this.day = day;
4288
+ }
4289
+ get dayOfWeek() {
4290
+ return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4291
+ }
4292
+ get daysInWeek() {
4293
+ return 7;
4294
+ }
4295
+ get daysInMonth() {
4296
+ return daysInMonth(this.year, this.month);
4297
+ }
4298
+ get monthCode() {
4299
+ return `M${pad2(this.month)}`;
4300
+ }
4301
+ add(dur) {
4302
+ let y = this.year + (dur.years || 0);
4303
+ let m = this.month + (dur.months || 0);
4304
+ while (m > 12) {
4305
+ m -= 12;
4306
+ y += 1;
4307
+ }
4308
+ while (m < 1) {
4309
+ m += 12;
4310
+ y -= 1;
4311
+ }
4312
+ const d = Math.min(this.day, daysInMonth(y, m));
4313
+ const totalDays = (dur.days || 0) + (dur.weeks || 0) * 7;
4314
+ if (totalDays === 0) return new MiniPlainDate(y, m, d);
4315
+ const epoch = toUTC(y, m, d) + totalDays * 864e5;
4316
+ const ud = new Date(epoch);
4317
+ return new MiniPlainDate(ud.getUTCFullYear(), ud.getUTCMonth() + 1, ud.getUTCDate());
4318
+ }
4319
+ subtract(dur) {
4320
+ return this.add({
4321
+ days: dur.days ? -dur.days : void 0,
4322
+ weeks: dur.weeks ? -dur.weeks : void 0,
4323
+ months: dur.months ? -dur.months : void 0,
4324
+ years: dur.years ? -dur.years : void 0
4325
+ });
4326
+ }
4327
+ since(other, _opts) {
4328
+ const thisUTC = toUTC(this.year, this.month, this.day);
4329
+ const otherUTC = toUTC(other.year, other.month, other.day);
4330
+ return { days: Math.round((thisUTC - otherUTC) / 864e5) };
4331
+ }
4332
+ until(other, _opts) {
4333
+ const thisUTC = toUTC(this.year, this.month, this.day);
4334
+ const otherUTC = toUTC(other.year, other.month, other.day);
4335
+ return { days: Math.round((otherUTC - thisUTC) / 864e5) };
4336
+ }
4337
+ equals(other) {
4338
+ return this.year === other.year && this.month === other.month && this.day === other.day;
4339
+ }
4340
+ toString() {
4341
+ return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}`;
4342
+ }
4343
+ toZonedDateTime(tz) {
4344
+ const tzId = typeof tz === "string" ? tz : tz.timeZone;
4345
+ return this.toPlainDateTime().toZonedDateTime(tzId);
4346
+ }
4347
+ toPlainDateTime(timeLike) {
4348
+ return new MiniPlainDateTime(this.year, this.month, this.day, timeLike?.hour ?? 0, timeLike?.minute ?? 0, timeLike?.second ?? 0);
4349
+ }
4350
+ toPlainMonthDay() {
4351
+ return new MiniPlainMonthDay(this.month, this.day);
4352
+ }
4353
+ toPlainYearMonth() {
4354
+ return new MiniPlainYearMonth(this.year, this.month);
4355
+ }
4356
+ toLocaleString(locale, options) {
4357
+ return new Date(toUTC(this.year, this.month, this.day)).toLocaleDateString(locale, {
4358
+ timeZone: "UTC",
4359
+ ...options
4360
+ });
4361
+ }
4362
+ };
4363
+ var MiniPlainDateTime = class {
4364
+ year;
4365
+ month;
4366
+ day;
4367
+ hour;
4368
+ minute;
4369
+ second;
4370
+ constructor(year, month, day, hour = 0, minute = 0, second = 0) {
4371
+ this.year = year;
4372
+ this.month = month;
4373
+ this.day = day;
4374
+ this.hour = hour;
4375
+ this.minute = minute;
4376
+ this.second = second;
4377
+ }
4378
+ get dayOfWeek() {
4379
+ return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4380
+ }
4381
+ get daysInMonth() {
4382
+ return daysInMonth(this.year, this.month);
4383
+ }
4384
+ toZonedDateTime(tz) {
4385
+ const tzId = typeof tz === "string" ? tz : tz.timeZone;
4386
+ return new MiniZonedDateTime(wallToEpoch(this.year, this.month, this.day, this.hour, this.minute, this.second, tzId), tzId);
4387
+ }
4388
+ toPlainDate() {
4389
+ return new MiniPlainDate(this.year, this.month, this.day);
4390
+ }
4391
+ toString() {
4392
+ return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}`;
4393
+ }
4394
+ };
4395
+ var MiniPlainMonthDay = class {
4396
+ monthCode;
4397
+ month;
4398
+ day;
4399
+ constructor(month, day) {
4400
+ this.month = month;
4401
+ this.day = day;
4402
+ this.monthCode = `M${pad2(month)}`;
4403
+ }
4404
+ toPlainDate(fields) {
4405
+ return new MiniPlainDate(fields.year, this.month, this.day);
4406
+ }
4407
+ equals(other) {
4408
+ return this.month === other.month && this.day === other.day;
4409
+ }
4410
+ toString() {
4411
+ return `${pad2(this.month)}-${pad2(this.day)}`;
4412
+ }
4413
+ };
4414
+ var MiniPlainYearMonth = class MiniPlainYearMonth {
4415
+ year;
4416
+ month;
4417
+ constructor(year, month) {
4418
+ this.year = year;
4419
+ this.month = month;
4420
+ }
4421
+ get monthCode() {
4422
+ return `M${pad2(this.month)}`;
4423
+ }
4424
+ get daysInMonth() {
4425
+ return daysInMonth(this.year, this.month);
4426
+ }
4427
+ toPlainDate(fields) {
4428
+ return new MiniPlainDate(this.year, this.month, fields.day);
4429
+ }
4430
+ add(dur) {
4431
+ let y = this.year + (dur.years || 0);
4432
+ let m = this.month + (dur.months || 0);
4433
+ while (m > 12) {
4434
+ m -= 12;
4435
+ y += 1;
4436
+ }
4437
+ while (m < 1) {
4438
+ m += 12;
4439
+ y -= 1;
4440
+ }
4441
+ return new MiniPlainYearMonth(y, m);
4442
+ }
4443
+ subtract(dur) {
4444
+ return this.add({
4445
+ months: dur.months ? -dur.months : void 0,
4446
+ years: dur.years ? -dur.years : void 0
4447
+ });
4448
+ }
4449
+ equals(other) {
4450
+ return this.year === other.year && this.month === other.month;
4451
+ }
4452
+ toString() {
4453
+ return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}`;
4454
+ }
4455
+ };
4456
+ var MiniZonedDateTime = class {
4457
+ epochMilliseconds;
4458
+ timeZoneId;
4459
+ _parts;
4460
+ constructor(epochMs, timeZoneId) {
4461
+ this.epochMilliseconds = epochMs;
4462
+ this.timeZoneId = timeZoneId;
4463
+ }
4464
+ get parts() {
4465
+ if (!this._parts) this._parts = extractTzParts(this.epochMilliseconds, this.timeZoneId);
4466
+ return this._parts;
4467
+ }
4468
+ get year() {
4469
+ return this.parts.year;
4470
+ }
4471
+ get month() {
4472
+ return this.parts.month;
4473
+ }
4474
+ get day() {
4475
+ return this.parts.day;
4476
+ }
4477
+ get hour() {
4478
+ return this.parts.hour;
4479
+ }
4480
+ get minute() {
4481
+ return this.parts.minute;
4482
+ }
4483
+ get second() {
4484
+ return this.parts.second;
4485
+ }
4486
+ get dayOfWeek() {
4487
+ return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
4488
+ }
4489
+ toPlainDate() {
4490
+ return new MiniPlainDate(this.year, this.month, this.day);
4491
+ }
4492
+ toPlainDateTime() {
4493
+ return new MiniPlainDateTime(this.year, this.month, this.day, this.hour, this.minute, this.second);
4494
+ }
4495
+ toPlainTime() {
4496
+ return {
4497
+ hour: this.hour,
4498
+ minute: this.minute,
4499
+ second: this.second
4500
+ };
4501
+ }
4502
+ toPlainYearMonth() {
4503
+ return new MiniPlainYearMonth(this.year, this.month);
4504
+ }
4505
+ toString() {
4506
+ return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}[${this.timeZoneId}]`;
4507
+ }
4508
+ };
4509
+ const PlainDate = {
4510
+ from(item, options) {
4511
+ if (typeof item === "string") {
4512
+ const { year, month, day } = parseDateISO(item);
4513
+ if (options?.overflow === "constrain") return new MiniPlainDate(year, month, clamp(day, 1, daysInMonth(year, month)));
4514
+ return new MiniPlainDate(year, month, day);
4515
+ }
4516
+ const year = item.year;
4517
+ const month = item.month;
4518
+ let day = item.day;
4519
+ if (options?.overflow === "constrain") day = clamp(day, 1, daysInMonth(year, month));
4520
+ return new MiniPlainDate(year, month, day);
4521
+ },
4522
+ compare(a, b) {
4523
+ if (a.year !== b.year) return Math.sign(a.year - b.year);
4524
+ if (a.month !== b.month) return Math.sign(a.month - b.month);
4525
+ if (a.day !== b.day) return Math.sign(a.day - b.day);
4526
+ return 0;
4527
+ }
4528
+ };
4529
+ const PlainDateTime = { from(item, _options) {
4530
+ if (typeof item === "string") {
4531
+ const { year, month, day, hour, minute, second } = parseDateTimeISO(item);
4532
+ return new MiniPlainDateTime(year, month, day, hour, minute, second);
4533
+ }
4534
+ return new MiniPlainDateTime(item.year, item.month, item.day, item.hour ?? 0, item.minute ?? 0, item.second ?? 0);
4535
+ } };
4536
+ const PlainMonthDay = { from(item) {
4537
+ if (typeof item === "string") {
4538
+ const parts = item.split("-").map(Number);
4539
+ if (parts.length >= 3) return new MiniPlainMonthDay(parts[1], parts[2]);
4540
+ return new MiniPlainMonthDay(parts[0], parts[1]);
4541
+ }
4542
+ return new MiniPlainMonthDay(item.month ?? (item.monthCode ? Number.parseInt(item.monthCode.slice(1), 10) : 1), item.day);
4543
+ } };
4544
+ const PlainYearMonth = {
4545
+ from(item) {
4546
+ if (typeof item === "string") {
4547
+ const [y, m] = item.split("-").map(Number);
4548
+ return new MiniPlainYearMonth(y, m);
4549
+ }
4550
+ return new MiniPlainYearMonth(item.year, item.month);
4551
+ },
4552
+ compare(a, b) {
4553
+ if (a.year !== b.year) return Math.sign(a.year - b.year);
4554
+ if (a.month !== b.month) return Math.sign(a.month - b.month);
4555
+ return 0;
4556
+ }
4557
+ };
4558
+ const Now = {
4559
+ timeZoneId() {
4560
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
4561
+ },
4562
+ zonedDateTimeISO(tz) {
4563
+ return new MiniZonedDateTime(Date.now(), tz ?? Now.timeZoneId());
4564
+ },
4565
+ plainDateISO() {
4566
+ const tz = Now.timeZoneId();
4567
+ const parts = extractTzParts(Date.now(), tz);
4568
+ return new MiniPlainDate(parts.year, parts.month, parts.day);
4569
+ }
4570
+ };
4571
+ const Temporal = {
4572
+ Now,
4573
+ PlainDate,
4574
+ PlainDateTime,
4575
+ PlainMonthDay,
4576
+ PlainYearMonth
4577
+ };
4578
+ //#endregion
4579
+ Object.defineProperty(exports, "CalendarProvider", {
4580
+ enumerable: true,
4581
+ get: function() {
4582
+ return CalendarProvider;
4583
+ }
4584
+ });
4585
+ Object.defineProperty(exports, "DateString", {
4586
+ enumerable: true,
4587
+ get: function() {
4588
+ return DateString;
4589
+ }
4590
+ });
4591
+ Object.defineProperty(exports, "DayButton", {
4592
+ enumerable: true,
4593
+ get: function() {
4594
+ return DayButton;
4595
+ }
4596
+ });
4597
+ Object.defineProperty(exports, "DayCellDataContext", {
4598
+ enumerable: true,
4599
+ get: function() {
4600
+ return DayCellDataContext;
4601
+ }
4602
+ });
4603
+ Object.defineProperty(exports, "DayCellTemplate", {
4604
+ enumerable: true,
4605
+ get: function() {
4606
+ return DayCellTemplate;
4607
+ }
4608
+ });
4609
+ Object.defineProperty(exports, "Grid", {
4610
+ enumerable: true,
4611
+ get: function() {
4612
+ return Grid;
4613
+ }
4614
+ });
4615
+ Object.defineProperty(exports, "GridBody", {
4616
+ enumerable: true,
4617
+ get: function() {
4618
+ return GridBody;
4619
+ }
4620
+ });
4621
+ Object.defineProperty(exports, "GridContext", {
4622
+ enumerable: true,
4623
+ get: function() {
4624
+ return GridContext;
4625
+ }
4626
+ });
4627
+ Object.defineProperty(exports, "GridHeader", {
4628
+ enumerable: true,
4629
+ get: function() {
4630
+ return GridHeader;
4631
+ }
4632
+ });
4633
+ Object.defineProperty(exports, "GridHeaderCell", {
4634
+ enumerable: true,
4635
+ get: function() {
4636
+ return GridHeaderCell;
4637
+ }
4638
+ });
4639
+ Object.defineProperty(exports, "MonthSeparator", {
4640
+ enumerable: true,
4641
+ get: function() {
4642
+ return MonthSeparator;
4643
+ }
4644
+ });
4645
+ Object.defineProperty(exports, "MonthSeparatorCell", {
4646
+ enumerable: true,
4647
+ get: function() {
4648
+ return MonthSeparatorCell;
4649
+ }
4650
+ });
4651
+ Object.defineProperty(exports, "MonthSeparatorMonth", {
4652
+ enumerable: true,
4653
+ get: function() {
4654
+ return MonthSeparatorMonth;
4655
+ }
4656
+ });
4657
+ Object.defineProperty(exports, "MonthSeparatorRow", {
4658
+ enumerable: true,
4659
+ get: function() {
4660
+ return MonthSeparatorRow;
4661
+ }
4662
+ });
4663
+ Object.defineProperty(exports, "MonthSeparatorWeekCount", {
4664
+ enumerable: true,
4665
+ get: function() {
4666
+ return MonthSeparatorWeekCount;
4667
+ }
4668
+ });
4669
+ Object.defineProperty(exports, "MonthSeparatorYear", {
4670
+ enumerable: true,
4671
+ get: function() {
4672
+ return MonthSeparatorYear;
4673
+ }
4674
+ });
4675
+ Object.defineProperty(exports, "MonthView", {
4676
+ enumerable: true,
4677
+ get: function() {
4678
+ return MonthView;
4679
+ }
4680
+ });
4681
+ Object.defineProperty(exports, "MonthViewRoot", {
4682
+ enumerable: true,
4683
+ get: function() {
4684
+ return MonthViewRoot;
4685
+ }
4686
+ });
4687
+ Object.defineProperty(exports, "MonthYearString", {
4688
+ enumerable: true,
4689
+ get: function() {
4690
+ return MonthYearString;
4691
+ }
4692
+ });
4693
+ Object.defineProperty(exports, "NextMonthButton", {
4694
+ enumerable: true,
4695
+ get: function() {
4696
+ return NextMonthButton;
4697
+ }
4698
+ });
4699
+ Object.defineProperty(exports, "NextWeeksButton", {
4700
+ enumerable: true,
4701
+ get: function() {
4702
+ return NextWeeksButton;
4703
+ }
4704
+ });
4705
+ Object.defineProperty(exports, "PrevMonthButton", {
4706
+ enumerable: true,
4707
+ get: function() {
4708
+ return PrevMonthButton;
4709
+ }
4710
+ });
4711
+ Object.defineProperty(exports, "PrevWeeksButton", {
4712
+ enumerable: true,
4713
+ get: function() {
4714
+ return PrevWeeksButton;
4715
+ }
4716
+ });
4717
+ Object.defineProperty(exports, "RangeEndDragHandle", {
4718
+ enumerable: true,
4719
+ get: function() {
4720
+ return RangeEndDragHandle;
4721
+ }
4722
+ });
4723
+ Object.defineProperty(exports, "RangePreview", {
4724
+ enumerable: true,
4725
+ get: function() {
4726
+ return RangePreview;
4727
+ }
4728
+ });
4729
+ Object.defineProperty(exports, "RangeSelected", {
4730
+ enumerable: true,
4731
+ get: function() {
4732
+ return RangeSelected;
4733
+ }
4734
+ });
4735
+ Object.defineProperty(exports, "RangeStartDragHandle", {
4736
+ enumerable: true,
4737
+ get: function() {
4738
+ return RangeStartDragHandle;
4739
+ }
4740
+ });
4741
+ Object.defineProperty(exports, "Temporal", {
4742
+ enumerable: true,
4743
+ get: function() {
4744
+ return Temporal;
4745
+ }
4746
+ });
4747
+ Object.defineProperty(exports, "TimeString", {
4748
+ enumerable: true,
4749
+ get: function() {
4750
+ return TimeString;
4751
+ }
4752
+ });
4753
+ Object.defineProperty(exports, "WeekCount", {
4754
+ enumerable: true,
4755
+ get: function() {
4756
+ return WeekCount;
4757
+ }
4758
+ });
4759
+ Object.defineProperty(exports, "WeekDataContext", {
4760
+ enumerable: true,
4761
+ get: function() {
4762
+ return WeekDataContext;
4763
+ }
4764
+ });
4765
+ Object.defineProperty(exports, "WeekNumberCell", {
4766
+ enumerable: true,
4767
+ get: function() {
4768
+ return WeekNumberCell;
4769
+ }
4770
+ });
4771
+ Object.defineProperty(exports, "WeekNumberHeader", {
4772
+ enumerable: true,
4773
+ get: function() {
4774
+ return WeekNumberHeader;
4775
+ }
4776
+ });
4777
+ Object.defineProperty(exports, "WeekTemplate", {
4778
+ enumerable: true,
4779
+ get: function() {
4780
+ return WeekTemplate;
4781
+ }
4782
+ });
4783
+ Object.defineProperty(exports, "WeeksView", {
4784
+ enumerable: true,
4785
+ get: function() {
4786
+ return WeeksView;
4787
+ }
4788
+ });
4789
+ Object.defineProperty(exports, "WeeksViewRoot", {
4790
+ enumerable: true,
4791
+ get: function() {
4792
+ return WeeksViewRoot;
4793
+ }
4794
+ });
4795
+ Object.defineProperty(exports, "computePreviewRange", {
4796
+ enumerable: true,
4797
+ get: function() {
4798
+ return computePreviewRange;
4799
+ }
4800
+ });
4801
+ Object.defineProperty(exports, "computeWeeksInWindow", {
4802
+ enumerable: true,
4803
+ get: function() {
4804
+ return computeWeeksInWindow;
4805
+ }
4806
+ });
4807
+ Object.defineProperty(exports, "resolveFirstWeek", {
4808
+ enumerable: true,
4809
+ get: function() {
4810
+ return resolveFirstWeek;
4811
+ }
4812
+ });
4813
+ Object.defineProperty(exports, "resolveFirstWeekSpec", {
4814
+ enumerable: true,
4815
+ get: function() {
4816
+ return resolveFirstWeekSpec;
4817
+ }
4818
+ });
4819
+ Object.defineProperty(exports, "useCalendarStable", {
4820
+ enumerable: true,
4821
+ get: function() {
4822
+ return useCalendarStable;
4823
+ }
4824
+ });
4825
+ Object.defineProperty(exports, "useCalendarState", {
4826
+ enumerable: true,
4827
+ get: function() {
4828
+ return useCalendarState;
4829
+ }
4830
+ });
4831
+ Object.defineProperty(exports, "useMonthViewStable", {
4832
+ enumerable: true,
4833
+ get: function() {
4834
+ return useMonthViewStable;
4835
+ }
4836
+ });
4837
+ Object.defineProperty(exports, "useMonthViewState", {
4838
+ enumerable: true,
4839
+ get: function() {
4840
+ return useMonthViewState;
4841
+ }
4842
+ });
4843
+ Object.defineProperty(exports, "useViewContext", {
4844
+ enumerable: true,
4845
+ get: function() {
4846
+ return useViewContext;
4847
+ }
4848
+ });
4849
+ Object.defineProperty(exports, "useWeeksViewStable", {
4850
+ enumerable: true,
4851
+ get: function() {
4852
+ return useWeeksViewStable;
4853
+ }
4854
+ });
4855
+ Object.defineProperty(exports, "useWeeksViewState", {
4856
+ enumerable: true,
4857
+ get: function() {
4858
+ return useWeeksViewState;
4859
+ }
4860
+ });