jenosize-ui 0.1.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 (182) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +100 -0
  3. package/THIRD-PARTY-NOTICES.md +163 -0
  4. package/dist/Button-Bt7pzM4R.d.ts +82 -0
  5. package/dist/PaymentInput-CKPIPNWH.d.ts +141 -0
  6. package/dist/Select-CVbEQ2Ep.d.ts +118 -0
  7. package/dist/TagInput-CTJYOB4J.d.ts +90 -0
  8. package/dist/avatar.d.ts +161 -0
  9. package/dist/avatar.js +11 -0
  10. package/dist/badge.d.ts +109 -0
  11. package/dist/badge.js +10 -0
  12. package/dist/breadcrumb.d.ts +58 -0
  13. package/dist/breadcrumb.js +7 -0
  14. package/dist/button.d.ts +54 -0
  15. package/dist/button.js +14 -0
  16. package/dist/calendar.d.ts +368 -0
  17. package/dist/calendar.js +21 -0
  18. package/dist/callout.d.ts +70 -0
  19. package/dist/callout.js +16 -0
  20. package/dist/card-nWicloNi.d.ts +80 -0
  21. package/dist/card.d.ts +2 -0
  22. package/dist/card.js +7 -0
  23. package/dist/checkbox.d.ts +133 -0
  24. package/dist/checkbox.js +11 -0
  25. package/dist/chunk-24TO7E32.js +42 -0
  26. package/dist/chunk-3Y5X7B5C.js +146 -0
  27. package/dist/chunk-4OLULPQG.js +202 -0
  28. package/dist/chunk-4P2NBLBW.js +103 -0
  29. package/dist/chunk-52IFGFTL.js +11 -0
  30. package/dist/chunk-5FATN5YD.js +115 -0
  31. package/dist/chunk-5NOBSXJN.js +297 -0
  32. package/dist/chunk-5RAPA22E.js +106 -0
  33. package/dist/chunk-7EUAMHMU.js +16 -0
  34. package/dist/chunk-7EWQKTNQ.js +1336 -0
  35. package/dist/chunk-7HOIZ3UO.js +110 -0
  36. package/dist/chunk-7IU5TMFL.js +452 -0
  37. package/dist/chunk-7JBNLEJ7.js +29 -0
  38. package/dist/chunk-7S2TBALK.js +23 -0
  39. package/dist/chunk-BJUZVYQC.js +188 -0
  40. package/dist/chunk-BVJWBYIG.js +66 -0
  41. package/dist/chunk-CME4DIML.js +65 -0
  42. package/dist/chunk-CYPPEUX5.js +73 -0
  43. package/dist/chunk-D5BTFSL7.js +71 -0
  44. package/dist/chunk-D6TPWNRK.js +387 -0
  45. package/dist/chunk-DJSXIAFH.js +66 -0
  46. package/dist/chunk-DRZCJCBO.js +46 -0
  47. package/dist/chunk-DWKILXHE.js +17 -0
  48. package/dist/chunk-E7ZSWBAK.js +70 -0
  49. package/dist/chunk-EDSK6FEH.js +8 -0
  50. package/dist/chunk-F2K7VJUV.js +114 -0
  51. package/dist/chunk-F6NLE6XJ.js +40 -0
  52. package/dist/chunk-FHHAPGCR.js +32 -0
  53. package/dist/chunk-FXIBGTS5.js +14 -0
  54. package/dist/chunk-GCVA3OIV.js +72 -0
  55. package/dist/chunk-GFOAJVW5.js +336 -0
  56. package/dist/chunk-GRLSUQQE.js +136 -0
  57. package/dist/chunk-GTHJWR3Q.js +77 -0
  58. package/dist/chunk-HMUZE6EK.js +67 -0
  59. package/dist/chunk-I7WU4GTY.js +503 -0
  60. package/dist/chunk-J2BCKBHC.js +151 -0
  61. package/dist/chunk-J36M3KRX.js +1315 -0
  62. package/dist/chunk-J7ZQQFPT.js +113 -0
  63. package/dist/chunk-JP26LPCY.js +234 -0
  64. package/dist/chunk-JTNFJLIY.js +1046 -0
  65. package/dist/chunk-JVJRHBTD.js +50 -0
  66. package/dist/chunk-JYGR44ZC.js +133 -0
  67. package/dist/chunk-KDLPXXD2.js +173 -0
  68. package/dist/chunk-KMSYEE23.js +224 -0
  69. package/dist/chunk-KNYKWUYX.js +52 -0
  70. package/dist/chunk-LME57Z6J.js +138 -0
  71. package/dist/chunk-MFJP5FA7.js +20 -0
  72. package/dist/chunk-MKC5HNA7.js +1692 -0
  73. package/dist/chunk-MQGD2OUF.js +39 -0
  74. package/dist/chunk-MUFHLP4S.js +566 -0
  75. package/dist/chunk-O2LG3PNI.js +74 -0
  76. package/dist/chunk-O4GRKO3I.js +66 -0
  77. package/dist/chunk-OHUFNYGN.js +791 -0
  78. package/dist/chunk-PWKWNDBS.js +243 -0
  79. package/dist/chunk-QA74ITR4.js +103 -0
  80. package/dist/chunk-R6RGJF4L.js +170 -0
  81. package/dist/chunk-S7NNXWIN.js +7 -0
  82. package/dist/chunk-SV56BSUQ.js +162 -0
  83. package/dist/chunk-T7FCG7XV.js +435 -0
  84. package/dist/chunk-THC2ISYP.js +57 -0
  85. package/dist/chunk-VWC72TR3.js +115 -0
  86. package/dist/chunk-W46K56XU.js +216 -0
  87. package/dist/chunk-W5GGOUUI.js +75 -0
  88. package/dist/chunk-WEUJYDCV.js +269 -0
  89. package/dist/chunk-WFY7DKQD.js +279 -0
  90. package/dist/chunk-WZQFC7ZN.js +448 -0
  91. package/dist/chunk-Z3ETJN5G.js +136 -0
  92. package/dist/chunk-ZOOX3TUB.js +192 -0
  93. package/dist/chunk-ZSNJ6UA3.js +42 -0
  94. package/dist/chunk-ZZA2LUTL.js +130 -0
  95. package/dist/chunk-ZZT2E5VT.js +24 -0
  96. package/dist/color-CtSxc1Rh.d.ts +6 -0
  97. package/dist/combobox.d.ts +184 -0
  98. package/dist/combobox.js +21 -0
  99. package/dist/date-input.d.ts +83 -0
  100. package/dist/date-input.js +16 -0
  101. package/dist/date-picker.d.ts +249 -0
  102. package/dist/date-picker.js +29 -0
  103. package/dist/date-utils-7hTFTXNK.d.ts +34 -0
  104. package/dist/date-vMJBKAFK.d.ts +22 -0
  105. package/dist/dialog.d.ts +86 -0
  106. package/dist/dialog.js +15 -0
  107. package/dist/drawer.d.ts +77 -0
  108. package/dist/drawer.js +14 -0
  109. package/dist/dropdown-menu.d.ts +218 -0
  110. package/dist/dropdown-menu.js +10 -0
  111. package/dist/file-trigger.d.ts +42 -0
  112. package/dist/file-trigger.js +3 -0
  113. package/dist/form.d.ts +487 -0
  114. package/dist/form.js +1179 -0
  115. package/dist/header-navigation.d.ts +74 -0
  116. package/dist/header-navigation.js +23 -0
  117. package/dist/icons/app.d.ts +48 -0
  118. package/dist/icons/app.js +282 -0
  119. package/dist/icons/flag.d.ts +817 -0
  120. package/dist/icons/flag.js +58336 -0
  121. package/dist/icons/integration.d.ts +36 -0
  122. package/dist/icons/integration.js +531 -0
  123. package/dist/icons/payment.d.ts +116 -0
  124. package/dist/icons/payment.js +2418 -0
  125. package/dist/icons.d.ts +2013 -0
  126. package/dist/icons.js +2012 -0
  127. package/dist/illustration.d.ts +48 -0
  128. package/dist/illustration.js +4 -0
  129. package/dist/index.d.ts +68 -0
  130. package/dist/index.js +73 -0
  131. package/dist/indicator.d.ts +51 -0
  132. package/dist/indicator.js +7 -0
  133. package/dist/input.d.ts +66 -0
  134. package/dist/input.js +15 -0
  135. package/dist/multi-value-CJb_tnvi.d.ts +8 -0
  136. package/dist/nav-Bla0o_-1.d.ts +98 -0
  137. package/dist/number-input.d.ts +80 -0
  138. package/dist/number-input.js +15 -0
  139. package/dist/options-CPEIgjtd.d.ts +68 -0
  140. package/dist/overflow-Df0h42Oi.d.ts +29 -0
  141. package/dist/pagination.d.ts +77 -0
  142. package/dist/pagination.js +17 -0
  143. package/dist/payment-input.d.ts +7 -0
  144. package/dist/payment-input.js +15 -0
  145. package/dist/popover.d.ts +60 -0
  146. package/dist/popover.js +14 -0
  147. package/dist/progress.d.ts +87 -0
  148. package/dist/progress.js +5 -0
  149. package/dist/radio.d.ts +77 -0
  150. package/dist/radio.js +12 -0
  151. package/dist/select.d.ts +68 -0
  152. package/dist/select.js +24 -0
  153. package/dist/shared-BNXAdgh2.d.ts +9 -0
  154. package/dist/shared-BYXJPnsN.d.ts +11 -0
  155. package/dist/shared-Dc-GgA16.d.ts +42 -0
  156. package/dist/sidebar-navigation.d.ts +129 -0
  157. package/dist/sidebar-navigation.js +15 -0
  158. package/dist/styles.css +2 -0
  159. package/dist/switch.d.ts +23 -0
  160. package/dist/switch.js +7 -0
  161. package/dist/table.d.ts +692 -0
  162. package/dist/table.js +44 -0
  163. package/dist/tabs.d.ts +111 -0
  164. package/dist/tabs.js +8 -0
  165. package/dist/tag-input.d.ts +12 -0
  166. package/dist/tag-input.js +19 -0
  167. package/dist/tag.d.ts +98 -0
  168. package/dist/tag.js +9 -0
  169. package/dist/textarea.d.ts +40 -0
  170. package/dist/textarea.js +12 -0
  171. package/dist/theme-script.d.ts +29 -0
  172. package/dist/theme-script.js +15 -0
  173. package/dist/theme.css +929 -0
  174. package/dist/theme.d.ts +71 -0
  175. package/dist/theme.js +15 -0
  176. package/dist/toast.d.ts +242 -0
  177. package/dist/toast.js +15 -0
  178. package/dist/tooltip.d.ts +70 -0
  179. package/dist/tooltip.js +6 -0
  180. package/dist/tree.d.ts +308 -0
  181. package/dist/tree.js +11 -0
  182. package/package.json +352 -0
@@ -0,0 +1,1315 @@
1
+ import { useAutoScroll, useDrag, snapToStep } from './chunk-KMSYEE23.js';
2
+ import { DEFAULT_WEEK_START, resolveTimeZone, useControllable, startOfDayIn, dayKey, formatIn, displayYear, monthOf, differenceInDaysIn, startOfMonthIn, startOfLastDayOfMonthIn, toWireDate, toWireInstant, addDaysIn, startOfWeekIn, addMonthsIn, minutesFromMidnight, earlierOf, laterOf } from './chunk-5RAPA22E.js';
3
+ import { Card } from './chunk-DRZCJCBO.js';
4
+ import { Popover } from './chunk-3Y5X7B5C.js';
5
+ import { ACCENT, SUBTLE } from './chunk-CME4DIML.js';
6
+ import { Slot } from './chunk-52IFGFTL.js';
7
+ import { useIsomorphicLayoutEffect } from './chunk-EDSK6FEH.js';
8
+ import { ChevronLeftIcon, ChevronRightIcon } from './chunk-24TO7E32.js';
9
+ import { devWarn, warnStickyNoScrollport } from './chunk-GCVA3OIV.js';
10
+ import { cn } from './chunk-ZSNJ6UA3.js';
11
+ import { enUS } from 'date-fns/locale';
12
+ import * as React from 'react';
13
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
+
15
+ // src/components/calendar/geometry.ts
16
+ var MONTH_ROWS = 6;
17
+ var DAYS_PER_WEEK = 7;
18
+ function windowMinutes(cfg) {
19
+ const [from, to] = cfg.hours;
20
+ return (to - from) * 60;
21
+ }
22
+ function slotCount(cfg) {
23
+ return Math.round(windowMinutes(cfg) / cfg.slotDuration);
24
+ }
25
+ function day(midnight, cfg, monthAnchor) {
26
+ const key = dayKey(midnight, cfg.timeZone);
27
+ let outside = false;
28
+ if (monthAnchor !== null) {
29
+ const cell = monthOf(midnight, cfg.timeZone);
30
+ const anchor = monthOf(monthAnchor, cfg.timeZone);
31
+ outside = cell.month !== anchor.month || cell.year !== anchor.year;
32
+ }
33
+ return { key, date: midnight, outside, today: key === dayKey(cfg.now, cfg.timeZone) };
34
+ }
35
+ function monthGrid(month, cfg) {
36
+ const first = startOfWeekIn(startOfMonthIn(month, cfg.timeZone), cfg.timeZone, cfg.locale, cfg.weekStartsOn);
37
+ const rows = [];
38
+ for (let r = 0; r < MONTH_ROWS; r += 1) {
39
+ const row = [];
40
+ for (let c = 0; c < DAYS_PER_WEEK; c += 1) {
41
+ row.push(day(addDaysIn(first, cfg.timeZone, r * DAYS_PER_WEEK + c), cfg, month));
42
+ }
43
+ rows.push(row);
44
+ }
45
+ return rows;
46
+ }
47
+ function weekDays(focused, cfg) {
48
+ const first = startOfWeekIn(focused, cfg.timeZone, cfg.locale, cfg.weekStartsOn);
49
+ return Array.from({ length: DAYS_PER_WEEK }, (_, i) => day(addDaysIn(first, cfg.timeZone, i), cfg, null));
50
+ }
51
+ function dayColumns(focused, cfg) {
52
+ return [day(startOfDayIn(focused, cfg.timeZone), cfg, null)];
53
+ }
54
+ function viewDays(view, focused, cfg) {
55
+ switch (view) {
56
+ case "month": {
57
+ return monthGrid(focused, cfg).flat();
58
+ }
59
+ case "week":
60
+ case "agenda": {
61
+ return weekDays(focused, cfg);
62
+ }
63
+ case "day": {
64
+ return dayColumns(focused, cfg);
65
+ }
66
+ }
67
+ }
68
+ function visibleRange(view, focused, cfg) {
69
+ const days = viewDays(view, focused, cfg);
70
+ const first = days[0];
71
+ const last = days.at(-1);
72
+ if (!first || !last) {
73
+ const only = startOfDayIn(focused, cfg.timeZone);
74
+ return { start: only, end: addDaysIn(only, cfg.timeZone, 1) };
75
+ }
76
+ return { start: first.date, end: addDaysIn(last.date, cfg.timeZone, 1) };
77
+ }
78
+ function step(view, focused, delta, cfg) {
79
+ switch (view) {
80
+ case "month": {
81
+ return addMonthsIn(focused, cfg.timeZone, delta);
82
+ }
83
+ case "week":
84
+ case "agenda": {
85
+ return addDaysIn(focused, cfg.timeZone, delta * DAYS_PER_WEEK);
86
+ }
87
+ case "day": {
88
+ return addDaysIn(focused, cfg.timeZone, delta);
89
+ }
90
+ }
91
+ }
92
+ function slotFromPoint(y, rect, cfg) {
93
+ if (rect.height <= 0) return 0;
94
+ const total = windowMinutes(cfg);
95
+ const ratio = (y - rect.top) / rect.height;
96
+ return Math.max(0, Math.min(total, ratio * total));
97
+ }
98
+ function snapMinutes(minutes, cfg) {
99
+ return snapToStep(minutes, cfg.slotDuration);
100
+ }
101
+ function minutesToOffset(minutes, rect, cfg) {
102
+ const total = windowMinutes(cfg);
103
+ if (total <= 0) return 0;
104
+ return minutes / total * rect.height;
105
+ }
106
+ function instantToWindowMinutes(instant, cfg) {
107
+ return minutesFromMidnight(instant, cfg.timeZone) - cfg.hours[0] * 60;
108
+ }
109
+ var warnedOutside = /* @__PURE__ */ new Set();
110
+ function clampToHours(range, cfg, key) {
111
+ const total = windowMinutes(cfg);
112
+ const outside = range.end <= 0 || range.start >= total;
113
+ const partly = range.start < 0 || range.end > total;
114
+ if ((outside || partly) && key != null && !warnedOutside.has(key)) {
115
+ warnedOutside.add(key);
116
+ const [from, to] = cfg.hours;
117
+ devWarn(
118
+ `<Calendar> event "${key}" falls ${outside ? "entirely" : "partly"} outside the visible \`hours\` window [${from}, ${to}] \u2014 it is ${outside ? "not rendered" : "clipped"}. Widen \`hours\` or move the event.`
119
+ );
120
+ }
121
+ return { start: Math.max(0, Math.min(total, range.start)), end: Math.max(0, Math.min(total, range.end)) };
122
+ }
123
+ function nowOffset(cfg, rect, visibleDays) {
124
+ const todayKey2 = dayKey(cfg.now, cfg.timeZone);
125
+ if (visibleDays.every((d) => d.key !== todayKey2)) return null;
126
+ const minutes = instantToWindowMinutes(cfg.now, cfg);
127
+ if (minutes < 0 || minutes > windowMinutes(cfg)) return null;
128
+ return minutesToOffset(minutes, rect, cfg);
129
+ }
130
+ function initialScrollTop(nowPx, box, cfg, slotHeight) {
131
+ const { viewportHeight, contentHeight, gridTop } = box;
132
+ const target = nowPx !== null ? gridTop + nowPx - viewportHeight / 3 : (
133
+ // No line: the window's own start. `gridTop` applies here too — the offset is measured from
134
+ // the grid's first row, not from the top of the all-day row above it.
135
+ gridTop + ((cfg.hours[0] === 0 ? 8 : cfg.hours[0]) - cfg.hours[0]) * 60 * (slotHeight / cfg.slotDuration)
136
+ );
137
+ return Math.max(0, Math.min(target, contentHeight - viewportHeight));
138
+ }
139
+ function moveDraft(event, delta, cfg) {
140
+ const minutes = event.allDay === true ? 0 : snapMinutes(delta.minutes, cfg);
141
+ const duration = event.end.getTime() - event.start.getTime();
142
+ const byDay = delta.days === 0 ? event.start : addDaysIn(event.start, cfg.timeZone, delta.days);
143
+ const start = minutes === 0 ? byDay : new Date(byDay.getTime() + minutes * 6e4);
144
+ return { start, end: new Date(start.getTime() + duration) };
145
+ }
146
+ function resizeDraft(event, edge, deltaMinutes, cfg) {
147
+ const delta = snapMinutes(deltaMinutes, cfg) * 6e4;
148
+ const floor = cfg.slotDuration * 6e4;
149
+ let start = event.start.getTime();
150
+ let end = event.end.getTime();
151
+ if (edge === "start") {
152
+ start += delta;
153
+ if (start > end) [start, end] = [end, start];
154
+ if (end - start < floor) start = end - floor;
155
+ } else {
156
+ end += delta;
157
+ if (end < start) [start, end] = [end, start];
158
+ if (end - start < floor) end = start + floor;
159
+ }
160
+ return { start: new Date(start), end: new Date(end) };
161
+ }
162
+ function createDraft(anchor, current, cfg) {
163
+ const a = anchor.getTime();
164
+ const b = current.getTime();
165
+ const start = Math.min(a, b);
166
+ const end = Math.max(a, b);
167
+ const floor = cfg.slotDuration * 6e4;
168
+ return { start: new Date(start), end: new Date(end - start < floor ? start + floor : end) };
169
+ }
170
+ function windowMinutesToInstant(dayDate, minutes, cfg) {
171
+ const midnight = startOfDayIn(dayDate, cfg.timeZone).getTime();
172
+ return new Date(midnight + (cfg.hours[0] * 60 + minutes) * 6e4);
173
+ }
174
+ function dayDelta(from, to, cfg) {
175
+ return differenceInDaysIn(to, from, cfg.timeZone);
176
+ }
177
+
178
+ // src/components/calendar/layout.ts
179
+ function byStartThenEndThenId(a, b) {
180
+ return a.start.getTime() - b.start.getTime() || a.end.getTime() - b.end.getTime() || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
181
+ }
182
+ function timedOnly(events) {
183
+ return events.filter((e) => e.allDay !== true);
184
+ }
185
+ function packOverlaps(events, cfg, columnKey) {
186
+ const total = windowMinutes(cfg);
187
+ const sorted = [...timedOnly(events)].sort(byStartThenEndThenId);
188
+ const out = [];
189
+ let cluster = [];
190
+ let columnEnds = [];
191
+ const closeCluster = () => {
192
+ const width = columnEnds.length;
193
+ for (const i of cluster) {
194
+ const positioned = out[i];
195
+ if (positioned) positioned.columns = width;
196
+ }
197
+ cluster = [];
198
+ columnEnds = [];
199
+ };
200
+ for (const event of sorted) {
201
+ const raw = { start: instantToWindowMinutes(event.start, cfg), end: instantToWindowMinutes(event.end, cfg) };
202
+ if (raw.end <= 0 || raw.start >= total) {
203
+ clampToHours(raw, cfg, event.id);
204
+ continue;
205
+ }
206
+ const { start, end } = clampToHours(raw, cfg, event.id);
207
+ if (cluster.length > 0 && columnEnds.every((columnEnd) => columnEnd <= start)) closeCluster();
208
+ let column = columnEnds.findIndex((columnEnd) => columnEnd <= start);
209
+ if (column === -1) {
210
+ column = columnEnds.length;
211
+ columnEnds.push(end);
212
+ } else {
213
+ columnEnds[column] = end;
214
+ }
215
+ cluster.push(out.length);
216
+ out.push({ event, startMinutes: start, endMinutes: end, column, columns: 1, dayKey: columnKey });
217
+ }
218
+ closeCluster();
219
+ return out;
220
+ }
221
+ function laneMultiDay(events, rows, cfg, laneBudget = Infinity) {
222
+ const segments = [];
223
+ const overflow = /* @__PURE__ */ new Map();
224
+ const hidden = /* @__PURE__ */ new Map();
225
+ let maxLane = -1;
226
+ const spanning = [...events].filter((e) => {
227
+ if (e.allDay === true) return true;
228
+ return dayKey(e.start, cfg.timeZone) !== dayKey(exclusiveEnd(e, cfg), cfg.timeZone);
229
+ }).sort(byStartThenEndThenId);
230
+ for (const [rowIndex, row] of rows.entries()) {
231
+ maxLane = Math.max(maxLane, placeRow(row, rowIndex, spanning, cfg, laneBudget, segments, overflow, hidden));
232
+ }
233
+ return { segments, overflow, hidden, maxLane };
234
+ }
235
+ function placeRow(row, rowIndex, spanning, cfg, laneBudget, segments, overflow, hidden) {
236
+ const first = row[0];
237
+ const last = row.at(-1);
238
+ if (!first || !last) return -1;
239
+ const rowStart = first.date;
240
+ const rowEndExclusive = addDaysIn(last.date, cfg.timeZone, 1);
241
+ const laneFreeFrom = [];
242
+ let maxLane = -1;
243
+ for (const event of spanning) {
244
+ const placed = placeEvent(event, row, rowIndex, rowStart, rowEndExclusive, laneFreeFrom, cfg, laneBudget, segments, overflow, hidden);
245
+ if (placed !== null) maxLane = Math.max(maxLane, placed);
246
+ }
247
+ return maxLane;
248
+ }
249
+ function placeEvent(event, row, rowIndex, rowStart, rowEndExclusive, laneFreeFrom, cfg, laneBudget, segments, overflow, hidden) {
250
+ const eventStart = startOfDayIn(event.start, cfg.timeZone);
251
+ const eventEnd = startOfDayIn(exclusiveEnd(event, cfg), cfg.timeZone);
252
+ if (eventEnd < rowStart || eventStart >= rowEndExclusive) return null;
253
+ const clippedStart = eventStart.getTime() >= rowStart.getTime() ? eventStart : rowStart;
254
+ const clippedEnd = eventEnd >= rowEndExclusive ? addDaysIn(rowEndExclusive, cfg.timeZone, -1) : eventEnd;
255
+ const dayIndex = Math.max(0, differenceInDaysIn(clippedStart, rowStart, cfg.timeZone));
256
+ const span = Math.max(1, differenceInDaysIn(clippedEnd, clippedStart, cfg.timeZone) + 1);
257
+ let lane = laneFreeFrom.findIndex((freeFrom) => freeFrom <= dayIndex);
258
+ if (lane === -1) lane = laneFreeFrom.length;
259
+ laneFreeFrom[lane] = dayIndex + span;
260
+ if (lane >= laneBudget) {
261
+ for (let i = dayIndex; i < Math.min(row.length, dayIndex + span); i += 1) {
262
+ const cell = row[i];
263
+ if (cell) {
264
+ overflow.set(cell.key, (overflow.get(cell.key) ?? 0) + 1);
265
+ const list = hidden.get(cell.key);
266
+ if (list) list.push(event);
267
+ else hidden.set(cell.key, [event]);
268
+ }
269
+ }
270
+ return null;
271
+ }
272
+ segments.push({ event, rowIndex, dayIndex, span, lane, isStart: eventStart >= rowStart, isEnd: eventEnd < rowEndExclusive });
273
+ return lane;
274
+ }
275
+ function exclusiveEnd(event, cfg) {
276
+ if (event.end.getTime() > event.start.getTime()) {
277
+ const end = event.end;
278
+ const midnight = startOfDayIn(end, cfg.timeZone);
279
+ return end.getTime() === midnight.getTime() ? new Date(end.getTime() - 1) : end;
280
+ }
281
+ return event.start;
282
+ }
283
+ function groupByDay(events, days, cfg) {
284
+ const buckets = /* @__PURE__ */ new Map();
285
+ for (const event of [...events].sort(byStartThenEndThenId)) {
286
+ const key = dayKey(event.start, cfg.timeZone);
287
+ const list = buckets.get(key);
288
+ if (list) list.push(event);
289
+ else buckets.set(key, [event]);
290
+ }
291
+ return days.map((d) => ({ key: d.key, date: d.date, events: buckets.get(d.key) ?? [] }));
292
+ }
293
+
294
+ // src/components/calendar/use-calendar.ts
295
+ var MONTH_LANE_BUDGET = 3;
296
+ function useCalendar(options) {
297
+ const {
298
+ events,
299
+ view: viewProp,
300
+ defaultView = "month",
301
+ onViewChange,
302
+ focusedDate: focusedProp,
303
+ defaultFocusedDate,
304
+ onFocusedDateChange,
305
+ timeZone: timeZoneProp,
306
+ locale = enUS,
307
+ weekStartsOn = DEFAULT_WEEK_START,
308
+ era = "ce",
309
+ now: nowProp,
310
+ hours = [0, 24],
311
+ slotDuration = 30,
312
+ onEventClick,
313
+ onSlotClick,
314
+ onEventChange,
315
+ canPlace
316
+ } = options;
317
+ const pinned = nowProp !== void 0;
318
+ const [autoNow, setAutoNow] = React.useState(() => /* @__PURE__ */ new Date());
319
+ React.useEffect(() => {
320
+ if (pinned) return;
321
+ const id = setInterval(() => setAutoNow(/* @__PURE__ */ new Date()), 6e4);
322
+ return () => clearInterval(id);
323
+ }, [pinned]);
324
+ const now = nowProp ?? autoNow;
325
+ const timeZone = resolveTimeZone(timeZoneProp);
326
+ const bothView = viewProp !== void 0 && options.defaultView !== void 0;
327
+ const bothFocused = focusedProp !== void 0 && defaultFocusedDate !== void 0;
328
+ const warnedBoth = React.useRef(false);
329
+ if (!warnedBoth.current && (bothView || bothFocused)) {
330
+ warnedBoth.current = true;
331
+ const pair = bothView ? "`view` and `defaultView`" : "`focusedDate` and `defaultFocusedDate`";
332
+ devWarn(`useCalendar() received both ${pair} \u2014 the controlled prop wins. Pass one or the other.`);
333
+ }
334
+ const [view, setView] = useControllable(viewProp, defaultView, onViewChange);
335
+ const [focusedDate, setFocusedDate] = useControllable(
336
+ focusedProp,
337
+ // The uncontrolled seed is a DAY, not an instant: the grid draws a period, and a mid-afternoon
338
+ // seed would make `focusedDate` compare unequal to any cell's own midnight.
339
+ defaultFocusedDate ?? startOfDayIn(now, timeZone),
340
+ onFocusedDateChange
341
+ );
342
+ const [hoursFrom, hoursTo] = hours;
343
+ const config = React.useMemo(
344
+ () => ({ timeZone, locale, weekStartsOn, era, hours: [hoursFrom, hoursTo], slotDuration, now }),
345
+ [timeZone, locale, weekStartsOn, era, hoursFrom, hoursTo, slotDuration, now.getTime()]
346
+ // eslint-disable-line react-hooks/exhaustive-deps
347
+ );
348
+ const focusedKey = focusedDate.getTime();
349
+ const range = React.useMemo(() => visibleRange(view, focusedDate, config), [view, focusedKey, config]);
350
+ const eventsKey = React.useMemo(
351
+ () => events.map((e) => `${e.id}:${e.start.getTime()}:${e.end.getTime()}:${e.allDay === true ? 1 : 0}:${e.color ?? ""}:${e.disabled === true ? 1 : 0}:${e.title}`).join("|"),
352
+ [events]
353
+ );
354
+ const eventsRef = React.useRef(events);
355
+ eventsRef.current = events;
356
+ const visibleEvents = React.useMemo(
357
+ () => eventsRef.current.filter((e) => e.start < range.end && e.end > range.start),
358
+ [eventsKey, range]
359
+ // eslint-disable-line react-hooks/exhaustive-deps
360
+ );
361
+ const layout = React.useMemo(() => {
362
+ const monthRows = view === "month" ? monthGrid(focusedDate, config) : [];
363
+ const days = view === "month" ? monthRows.flat() : view === "day" ? dayColumns(focusedDate, config) : weekDays(focusedDate, config);
364
+ const timed = /* @__PURE__ */ new Map();
365
+ if (view === "week" || view === "day") {
366
+ for (const d of days) {
367
+ const ofDay = visibleEvents.filter((e) => dayKey(e.start, config.timeZone) === d.key);
368
+ timed.set(d.key, packOverlaps(ofDay, config, d.key));
369
+ }
370
+ }
371
+ const rows = view === "month" ? monthRows : [days];
372
+ const lanes = laneMultiDay(visibleEvents, rows, config, view === "month" ? MONTH_LANE_BUDGET : Infinity);
373
+ const groups = view === "agenda" ? groupByDay(visibleEvents, days, config) : [];
374
+ return { monthRows, days, timed, lanes, groups };
375
+ }, [view, focusedKey, config, visibleEvents]);
376
+ const prev = React.useCallback(() => setFocusedDate(step(view, focusedDate, -1, config)), [setFocusedDate, view, focusedDate, config]);
377
+ const next = React.useCallback(() => setFocusedDate(step(view, focusedDate, 1, config)), [setFocusedDate, view, focusedDate, config]);
378
+ const today = React.useCallback(
379
+ // The CONFIGURED zone's today, not the runtime's: with `timeZone: "Asia/Bangkok"` and `now` at
380
+ // 18:00Z, "today" is tomorrow's date.
381
+ () => setFocusedDate(startOfDayIn(config.now, config.timeZone)),
382
+ [setFocusedDate, config]
383
+ );
384
+ const periodLabel = React.useMemo(() => buildPeriodLabel(view, focusedDate, config), [view, focusedKey, config]);
385
+ const rangeLabel = React.useMemo(() => buildRangeLabel(view, focusedDate, config), [view, focusedKey, config]);
386
+ const monthLabel = React.useMemo(() => buildMonthLabel(focusedDate, config), [focusedKey, config]);
387
+ const weekLabel = React.useMemo(() => buildWeekLabel(focusedDate, config), [focusedKey, config]);
388
+ const todayLabel = React.useMemo(() => buildTodayLabel(config), [config]);
389
+ const [draft, setDraft] = React.useState(null);
390
+ const [grabbed, setGrabbed] = React.useState(null);
391
+ const canPlaceResolved = React.useCallback(
392
+ (candidate) => canPlace?.(candidate) ?? true,
393
+ [canPlace]
394
+ );
395
+ const handleEventClick = React.useCallback((event) => onEventClick?.(event), [onEventClick]);
396
+ const handleSlotClick = React.useCallback((r) => onSlotClick?.(r), [onSlotClick]);
397
+ const commit = React.useCallback((event, nextRange) => onEventChange?.(event, nextRange), [onEventChange]);
398
+ return {
399
+ view,
400
+ setView,
401
+ focusedDate,
402
+ setFocusedDate,
403
+ prev,
404
+ next,
405
+ today,
406
+ periodLabel,
407
+ rangeLabel,
408
+ monthLabel,
409
+ weekLabel,
410
+ todayLabel,
411
+ visibleRange: range,
412
+ visibleEvents,
413
+ config,
414
+ layout,
415
+ draft,
416
+ setDraft,
417
+ grabbed,
418
+ setGrabbed,
419
+ canPlace: canPlaceResolved,
420
+ onEventClick: handleEventClick,
421
+ onSlotClick: handleSlotClick,
422
+ commit
423
+ };
424
+ }
425
+ function buildPeriodLabel(view, focused, cfg) {
426
+ const { timeZone: tz, locale, era } = cfg;
427
+ if (view === "month") {
428
+ return `${formatIn(focused, tz, "LLLL", locale)} ${displayYear(focused, tz, era)}`;
429
+ }
430
+ if (view === "day") {
431
+ return `${formatIn(focused, tz, "EEEE, MMM d", locale)}, ${displayYear(focused, tz, era)}`;
432
+ }
433
+ const days = viewDays(view, focused, cfg);
434
+ const first = days[0]?.date ?? focused;
435
+ const last = days.at(-1)?.date ?? focused;
436
+ const sameMonth = monthOf(first, tz).month === monthOf(last, tz).month && monthOf(first, tz).year === monthOf(last, tz).year;
437
+ const left = formatIn(first, tz, "MMM d", locale);
438
+ const right = formatIn(last, tz, sameMonth ? "d" : "MMM d", locale);
439
+ return `${left} \u2013 ${right}, ${displayYear(last, tz, era)}`;
440
+ }
441
+ function buildMonthLabel(focused, cfg) {
442
+ return `${formatIn(focused, cfg.timeZone, "LLLL", cfg.locale)} ${displayYear(focused, cfg.timeZone, cfg.era)}`;
443
+ }
444
+ function buildWeekLabel(focused, cfg) {
445
+ const offset = differenceInDaysIn(focused, startOfMonthIn(focused, cfg.timeZone), cfg.timeZone);
446
+ return `Week ${Math.floor(offset / 7) + 1}`;
447
+ }
448
+ function buildTodayLabel(cfg) {
449
+ return {
450
+ month: formatIn(cfg.now, cfg.timeZone, "MMM", cfg.locale),
451
+ day: formatIn(cfg.now, cfg.timeZone, "d", cfg.locale)
452
+ };
453
+ }
454
+ function buildRangeLabel(view, focused, cfg) {
455
+ const { timeZone: tz, locale, era } = cfg;
456
+ const write = (d) => `${formatIn(d, tz, "MMM d", locale)}, ${displayYear(d, tz, era)}`;
457
+ if (view === "day") return write(focused);
458
+ if (view === "month") {
459
+ return `${write(startOfMonthIn(focused, tz))} \u2013 ${write(startOfLastDayOfMonthIn(focused, tz))}`;
460
+ }
461
+ const days = viewDays(view, focused, cfg);
462
+ return `${write(days[0]?.date ?? focused)} \u2013 ${write(days.at(-1)?.date ?? focused)}`;
463
+ }
464
+ function endOfDayExclusive(day2, cfg) {
465
+ return addDaysIn(startOfDayIn(day2, cfg.timeZone), cfg.timeZone, 1);
466
+ }
467
+
468
+ // src/components/calendar/serialize.ts
469
+ function serializeEvent(event) {
470
+ return event.allDay === true ? { start: toWireDate(event.start), end: toWireDate(event.end) } : { start: toWireInstant(event.start), end: toWireInstant(event.end) };
471
+ }
472
+ function parseEvent(raw) {
473
+ return { start: parseWire(raw.start), end: parseWire(raw.end) };
474
+ }
475
+ function isWireDate(value) {
476
+ return /^\d{4}-\d{2}-\d{2}$/.test(value);
477
+ }
478
+ function parseWire(value) {
479
+ if (!isWireDate(value)) return new Date(value);
480
+ const [y, m, d] = value.split("-").map(Number);
481
+ return new Date(y ?? 1970, (m ?? 1) - 1, d ?? 1);
482
+ }
483
+
484
+ // src/components/calendar/shared.ts
485
+ var SLOT_PX = { sm: 32, md: 40, lg: 48 };
486
+ var MONTH_CELL_MIN_PX = { sm: 88, md: 104, lg: 120 };
487
+ function monthRowTemplate(size) {
488
+ return `repeat(${MONTH_ROWS}, minmax(${MONTH_CELL_MIN_PX[size]}px, 1fr))`;
489
+ }
490
+ var GUTTER_W = { sm: "w-12", md: "w-14", lg: "w-16" };
491
+ var CHIP_TEXT = { sm: "text-xs", md: "text-sm", lg: "text-sm" };
492
+ var BAR_TEXT = { sm: "text-xs", md: "text-xs", lg: "text-sm" };
493
+ var CHIP_PAD = { sm: "px-1.5 py-0.5", md: "px-2 py-1", lg: "px-2 py-1" };
494
+ var BAR_PAD = { sm: "px-1.5 py-0.5", md: "px-2 py-0.5", lg: "px-2 py-0.5" };
495
+ var BAR_PX = { sm: 18, md: 20, lg: 22 };
496
+ var BAR_GAP_PX = 2;
497
+ var ROOT = "flex min-w-0 flex-col text-primary";
498
+ var WEEKDAY_HEADER = "text-quaternary text-xs font-medium";
499
+ var GRID_LINE = "border-secondary";
500
+ var GRID_LINE_SUBTLE = "border-tertiary";
501
+ function slotRuleEvery(slotDuration) {
502
+ return Math.max(1, Math.round(30 / slotDuration));
503
+ }
504
+ var DAY_NUMBER = "inline-flex size-6 items-center justify-center rounded-full text-sm tabular-nums text-primary";
505
+ var DAY_NUMBER_OUTSIDE = "text-fg-quaternary";
506
+ var DAY_NUMBER_DISC = "bg-brand-solid font-semibold text-fg-white";
507
+ var DAY_NUMBER_TODAY = "text-brand-secondary font-semibold";
508
+ var OUTSIDE_CELL = "bg-sunken";
509
+ var SLOT_UNAVAILABLE = "cursor-not-allowed bg-tertiary";
510
+ var SLOT_HOVER = "hover:bg-ghost-hover";
511
+ var FOCUS_RING = "outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2";
512
+ var NOW_LINE = "pointer-events-none absolute inset-x-0 z-0 h-px bg-brand-solid";
513
+ var NOW_DOT = "absolute -top-1 left-0 size-2 rounded-full bg-brand-solid";
514
+ var ALL_DAY_ROW = "sticky top-0 z-3 border-b border-secondary bg-primary";
515
+ var HOUR_GUTTER = "sticky left-0 z-3 shrink-0 bg-primary text-quaternary text-xs tabular-nums";
516
+ var SCROLLER = "relative min-h-0 flex-1 overflow-y-auto overscroll-contain rounded-[inherit]";
517
+ var CHIP_BASE = "group/chip relative flex min-w-0 cursor-pointer touch-manipulation items-center gap-1.5 rounded-md text-left font-medium transition-colors duration-100 ease-linear";
518
+ var BLOCK_POSITION = "absolute right-0 left-(--cal-inset) z-1 px-px";
519
+ var CHIP_VARIANT = {
520
+ // A month bar spans days, so it must not grow its row: one line, clipped.
521
+ bar: "h-full w-full overflow-hidden whitespace-nowrap",
522
+ // A week/day block is absolutely positioned by the view and fills the box it was given.
523
+ block: "h-full w-full flex-col items-start overflow-hidden",
524
+ // An agenda row is in normal flow and may wrap onto a second line.
525
+ row: "w-full"
526
+ };
527
+ function chipTone(color) {
528
+ return SUBTLE[color ?? "brand"];
529
+ }
530
+ function chipAccent(color) {
531
+ return ACCENT[color ?? "brand"];
532
+ }
533
+ var CHIP_TIME = "text-xs font-normal opacity-90 tabular-nums";
534
+ var CHIP_DISABLED = "cursor-default text-fg-disabled pointer-events-none";
535
+ function blockInsetPercent(column, columns) {
536
+ if (columns <= 1 || column === 0) return 0;
537
+ return column * Math.min(16, 50 / (columns - 1));
538
+ }
539
+ var RESIZE_ZONE = "absolute inset-x-0 z-1 h-1.5 cursor-ns-resize touch-manipulation";
540
+ var GHOST = "pointer-events-none absolute z-4 rounded-md ring-2 ring-brand shadow-lg transition-none";
541
+ var GHOST_INVALID = "ring-error_subtle cursor-not-allowed";
542
+ var MORE_TRIGGER = "w-full rounded-md px-1 text-left text-xs font-medium text-tertiary hover:bg-ghost-hover hover:text-primary";
543
+ var CONTAINER = "@container/cal min-w-0";
544
+ var WEEK_NARROW_HIDE = "@max-2xl/cal:hidden";
545
+ var WEEK_NARROW_COLS = "grid-cols-[repeat(7,minmax(0,1fr))] @max-2xl/cal:grid-cols-1";
546
+ var MONTH_CHIP_NARROW = "@max-lg/cal:hidden";
547
+ var MONTH_DOT_NARROW = "hidden @max-lg/cal:flex";
548
+ function timeRange(event, cfg) {
549
+ if (event.allDay === true) return "All day";
550
+ const { timeZone: tz, locale } = cfg;
551
+ return `${formatIn(event.start, tz, "HH:mm", locale)} \u2013 ${formatIn(event.end, tz, "HH:mm", locale)}`;
552
+ }
553
+ function timeStart(event, cfg) {
554
+ if (event.allDay === true) return "";
555
+ return formatIn(event.start, cfg.timeZone, "HH:mm", cfg.locale);
556
+ }
557
+ function chipLabel(event, cfg) {
558
+ const day2 = formatIn(event.start, cfg.timeZone, "EEEE, d MMMM", cfg.locale);
559
+ return `${event.title}, ${timeRange(event, cfg)}, ${day2}`;
560
+ }
561
+ function EventChip(props) {
562
+ const {
563
+ event,
564
+ size,
565
+ variant,
566
+ config,
567
+ showTime = variant !== "bar",
568
+ clipStart = false,
569
+ clipEnd = false,
570
+ dragging = false,
571
+ grabbed = false,
572
+ onActivate,
573
+ dragHandlers,
574
+ onKeyDown,
575
+ onBlur,
576
+ children,
577
+ className,
578
+ tabIndex
579
+ } = props;
580
+ const disabled = event.disabled === true;
581
+ return /* @__PURE__ */ jsxs(
582
+ "button",
583
+ {
584
+ type: "button",
585
+ onClick: disabled ? void 0 : () => onActivate?.(event),
586
+ onKeyDown,
587
+ onBlur,
588
+ onMouseDown: disabled ? void 0 : dragHandlers?.onMouseDown,
589
+ onTouchStart: disabled ? void 0 : dragHandlers?.onTouchStart,
590
+ "aria-label": chipLabel(event, config),
591
+ "aria-disabled": disabled || void 0,
592
+ "data-dragging": dragging || void 0,
593
+ "data-grabbed": grabbed || void 0,
594
+ tabIndex,
595
+ className: cn(
596
+ CHIP_BASE,
597
+ CHIP_VARIANT[variant],
598
+ // A bar runs one type step below a block and pads to match, so a single-day chip and the
599
+ // spanning bar above it in the same cell share one height (`BAR_PX`).
600
+ variant === "bar" ? BAR_PAD[size] : CHIP_PAD[size],
601
+ variant === "bar" ? BAR_TEXT[size] : CHIP_TEXT[size],
602
+ chipTone(event.color),
603
+ // A clipped end reads as continuing, so it loses its corner. `isStart`/`isEnd` from
604
+ // `laneMultiDay` are what drive these.
605
+ clipStart && "rounded-l-none",
606
+ clipEnd && "rounded-r-none",
607
+ disabled && CHIP_DISABLED,
608
+ dragging && "opacity-50",
609
+ // The grab-mode ring is the chip's own state, not a focus ring — a grabbed chip may lose
610
+ // :focus-visible to the arrow keys while still being held.
611
+ grabbed && "ring-2 ring-brand",
612
+ className
613
+ ),
614
+ children: [
615
+ clipStart ? /* @__PURE__ */ jsx(ChevronLeftIcon, { className: cn("size-3 shrink-0", chipAccent(event.color)) }) : null,
616
+ event.leading != null ? /* @__PURE__ */ jsx(Slot, { className: cn("[&>svg]:size-3.5", chipAccent(event.color)), children: event.leading }) : null,
617
+ /* @__PURE__ */ jsxs("span", { className: cn("flex min-w-0 flex-1", variant === "block" ? "flex-col items-start" : "items-center gap-1.5"), children: [
618
+ /* @__PURE__ */ jsx("span", { className: cn("min-w-0 truncate", variant !== "block" && "flex-1", variant === "row" && "whitespace-normal"), children: event.title }),
619
+ showTime ? (
620
+ // On one line the time is pushed to the far end and never squeezed: `shrink-0` so the
621
+ // TITLE absorbs the overflow. A time truncated to "17:3…" tells the reader nothing, while
622
+ // a truncated title still tells them roughly what it is.
623
+ /* @__PURE__ */ jsx("span", { className: cn(CHIP_TIME, variant === "block" ? "min-w-0 truncate" : "ml-auto shrink-0"), children: variant === "bar" ? timeStart(event, config) : timeRange(event, config) })
624
+ ) : null
625
+ ] }),
626
+ event.trailing != null ? /* @__PURE__ */ jsx(Slot, { className: "[&>svg]:size-3.5", children: event.trailing }) : null,
627
+ clipEnd ? /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-3 shrink-0", chipAccent(event.color)) }) : null,
628
+ children
629
+ ]
630
+ }
631
+ );
632
+ }
633
+ EventChip.displayName = "EventChip";
634
+ function AgendaView({ instance, size, focusRef }) {
635
+ const { config, layout, onEventClick } = instance;
636
+ const { groups } = layout;
637
+ const total = groups.reduce((sum, g) => sum + g.events.length, 0);
638
+ if (total === 0) {
639
+ return /* @__PURE__ */ jsx("div", { ref: focusRef, className: "min-w-0", children: /* @__PURE__ */ jsx(Card, { variant: "subtle", padding: "lg", className: "text-center", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-tertiary", children: "Nothing scheduled this week." }) }) });
640
+ }
641
+ return /* @__PURE__ */ jsx("div", { ref: focusRef, className: "min-w-0", children: /* @__PURE__ */ jsx(Card, { variant: "outlined", padding: "none", children: /* @__PURE__ */ jsx("dl", { className: "m-0 flex flex-col", children: groups.map((group, index) => /* @__PURE__ */ jsxs("div", { className: cn("flex min-w-0 flex-col gap-2 p-4 sm:flex-row sm:gap-6", index > 0 && cn("border-t", GRID_LINE)), children: [
642
+ /* @__PURE__ */ jsxs("dt", { className: "flex shrink-0 items-baseline gap-2 sm:w-32 sm:flex-col sm:gap-0.5", children: [
643
+ /* @__PURE__ */ jsx("span", { className: WEEKDAY_HEADER, children: formatIn(group.date, config.timeZone, "EEE", config.locale) }),
644
+ /* @__PURE__ */ jsx("span", { className: cn("text-md font-semibold text-primary tabular-nums", group.key === todayKey(instance) && DAY_NUMBER_TODAY), children: formatIn(group.date, config.timeZone, "d MMM", config.locale) })
645
+ ] }),
646
+ /* @__PURE__ */ jsx("dd", { className: "m-0 flex min-w-0 flex-1 flex-col gap-1", children: group.events.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-quaternary", children: "\u2014" }) : group.events.map((event) => (
647
+ // `row`: the one variant that WRAPS rather than truncating, because an agenda has
648
+ // the width to give and a clipped title in a list is just a worse list.
649
+ /* @__PURE__ */ jsx(EventChip, { event, size, variant: "row", config, onActivate: onEventClick }, event.id)
650
+ )) })
651
+ ] }, group.key)) }) }) });
652
+ }
653
+ function todayKey(instance) {
654
+ return instance.layout.days.find((d) => d.today)?.key;
655
+ }
656
+ AgendaView.displayName = "AgendaView";
657
+ var DAY_ATTR = "data-cal-day";
658
+ function dayKeyAt(pt) {
659
+ if (typeof document.elementFromPoint !== "function") return null;
660
+ const el = document.elementFromPoint(pt.x, pt.y);
661
+ const cell = el?.closest(`[${CSS.escape(DAY_ATTR)}]`);
662
+ return cell?.getAttribute(DAY_ATTR) ?? null;
663
+ }
664
+ function rectOf(el) {
665
+ if (!el) return null;
666
+ const r = el.getBoundingClientRect();
667
+ return { top: r.top, left: r.left, width: r.width, height: r.height };
668
+ }
669
+ function useCalendarDrag(opts) {
670
+ const { instance, gridRef, days, axis } = opts;
671
+ const { config, canPlace, setDraft, commit, onSlotClick } = instance;
672
+ const pending = React.useRef(null);
673
+ const [draggingId, setDraggingId] = React.useState(null);
674
+ const latest = React.useRef({ config, days, axis, canPlace, setDraft, commit, onSlotClick });
675
+ latest.current = { config, days, axis, canPlace, setDraft, commit, onSlotClick };
676
+ const autoScroll = useAutoScroll(gridRef);
677
+ const readPoint = React.useCallback(
678
+ (pt) => {
679
+ const cfg = latest.current.config;
680
+ const rect = rectOf(gridRef.current);
681
+ const minutes = rect ? slotFromPoint(pt.y, rect, cfg) : 0;
682
+ return { dayKey: dayKeyAt(pt), minutes };
683
+ },
684
+ [gridRef]
685
+ );
686
+ const dayOf = React.useCallback((key) => latest.current.days.find((d) => d.key === key) ?? null, []);
687
+ const publish = React.useCallback((live) => {
688
+ const event = live.pending.kind === "create" ? null : live.pending.event;
689
+ latest.current.setDraft({ kind: live.pending.kind, event, start: live.start, end: live.end, allDay: live.allDay, valid: live.valid });
690
+ }, []);
691
+ const { handlers } = useDrag({
692
+ onStart: (pt) => {
693
+ const p = pending.current;
694
+ if (!p) return null;
695
+ if (p.kind !== "create" && p.event.disabled === true) return null;
696
+ const cfg = latest.current.config;
697
+ const { dayKey: dayKey2, minutes } = readPoint(pt);
698
+ const originDay = dayOf(dayKey2) ?? latest.current.days[0];
699
+ if (!originDay) return null;
700
+ const base = p.kind === "create" ? latest.current.axis === "day" ? { pending: p, originDayKey: originDay.key, originMinutes: 0, start: originDay.date, end: endOfDayExclusive(originDay.date, cfg), allDay: true } : (() => {
701
+ const anchor = windowMinutesToInstant(originDay.date, p.minutes ?? snapMinutes(minutes, cfg), cfg);
702
+ const range = createDraft(anchor, anchor, cfg);
703
+ return { pending: p, originDayKey: originDay.key, originMinutes: minutes, ...range, allDay: false };
704
+ })() : { pending: p, originDayKey: originDay.key, originMinutes: minutes, start: p.event.start, end: p.event.end, allDay: p.event.allDay === true };
705
+ const valid = latest.current.canPlace({ event: p.kind === "create" ? null : p.event, start: base.start, end: base.end, allDay: base.allDay });
706
+ const live = { ...base, valid };
707
+ if (p.kind !== "create") setDraggingId(p.event.id);
708
+ publish(live);
709
+ autoScroll.arm();
710
+ return live;
711
+ },
712
+ onMove: (live, pt) => {
713
+ const cfg = latest.current.config;
714
+ const { dayKey: dayKey2, minutes } = readPoint(pt);
715
+ const currentDay = dayOf(dayKey2) ?? dayOf(live.originDayKey);
716
+ const originDay = dayOf(live.originDayKey);
717
+ const dayShift = currentDay && originDay ? dayDelta(originDay.date, currentDay.date, cfg) : 0;
718
+ const minuteShift = latest.current.axis === "time" ? minutes - live.originMinutes : 0;
719
+ let next;
720
+ let allDay = live.allDay;
721
+ switch (live.pending.kind) {
722
+ case "move": {
723
+ next = moveDraft(live.pending.event, { days: dayShift, minutes: minuteShift }, cfg);
724
+ break;
725
+ }
726
+ case "resize": {
727
+ next = resizeDraft(live.pending.event, live.pending.edge, minuteShift, cfg);
728
+ break;
729
+ }
730
+ case "create": {
731
+ if (latest.current.axis === "day") {
732
+ const from = originDay?.date ?? live.start;
733
+ const to = currentDay?.date ?? from;
734
+ const lo = earlierOf(from, to);
735
+ const hi = laterOf(from, to);
736
+ next = { start: startOfDayIn(lo, cfg.timeZone), end: endOfDayExclusive(hi, cfg) };
737
+ allDay = true;
738
+ } else {
739
+ const anchor = windowMinutesToInstant(originDay?.date ?? live.start, snapMinutes(live.originMinutes, cfg), cfg);
740
+ const current = windowMinutesToInstant(currentDay?.date ?? originDay?.date ?? live.start, snapMinutes(minutes, cfg), cfg);
741
+ next = createDraft(anchor, current, cfg);
742
+ allDay = false;
743
+ }
744
+ break;
745
+ }
746
+ }
747
+ const event = live.pending.kind === "create" ? null : live.pending.event;
748
+ const valid = latest.current.canPlace({ event, start: next.start, end: next.end, allDay });
749
+ const updated = { ...live, ...next, allDay, valid };
750
+ publish(updated);
751
+ return updated;
752
+ },
753
+ onEnd: (live) => {
754
+ autoScroll.disarm();
755
+ setDraggingId(null);
756
+ latest.current.setDraft(null);
757
+ pending.current = null;
758
+ if (!live.valid) return;
759
+ if (live.pending.kind === "create") {
760
+ latest.current.onSlotClick({ start: live.start, end: live.end, allDay: live.allDay });
761
+ } else if (live.start.getTime() !== live.pending.event.start.getTime() || live.end.getTime() !== live.pending.event.end.getTime()) {
762
+ latest.current.commit(live.pending.event, { start: live.start, end: live.end });
763
+ }
764
+ },
765
+ onCancel: () => {
766
+ autoScroll.disarm();
767
+ setDraggingId(null);
768
+ latest.current.setDraft(null);
769
+ pending.current = null;
770
+ }
771
+ });
772
+ const arm = React.useCallback(
773
+ (p) => ({
774
+ onMouseDown: (e) => {
775
+ e.stopPropagation();
776
+ pending.current = p;
777
+ handlers.onMouseDown(e);
778
+ },
779
+ onTouchStart: (e) => {
780
+ e.stopPropagation();
781
+ pending.current = p;
782
+ handlers.onTouchStart(e);
783
+ }
784
+ }),
785
+ [handlers]
786
+ );
787
+ const noop = React.useMemo(() => ({ onMouseDown: () => {
788
+ }, onTouchStart: () => {
789
+ } }), []);
790
+ return {
791
+ moveHandlers: React.useCallback((event) => arm({ kind: "move", event }), [arm]),
792
+ // A day-axis view has no minute axis, so there is nothing for an edge to move.
793
+ resizeHandlers: React.useCallback((event, edge) => axis === "day" ? noop : arm({ kind: "resize", event, edge }), [arm, axis, noop]),
794
+ createHandlers: React.useCallback((day2, minutes) => arm({ kind: "create", day: day2, minutes }), [arm]),
795
+ draggingId
796
+ };
797
+ }
798
+ function TimeGhost({ draft, config, days, slotHeight }) {
799
+ if (draft.allDay) return null;
800
+ const columnIndex = days.findIndex((d) => d.key === dayKey(draft.start, config.timeZone));
801
+ if (columnIndex === -1) return null;
802
+ const startMinutes = instantToWindowMinutes(draft.start, config);
803
+ const endMinutes = instantToWindowMinutes(draft.end, config);
804
+ const top = startMinutes / config.slotDuration * slotHeight;
805
+ const height = Math.max(slotHeight / 2, (endMinutes - startMinutes) / config.slotDuration * slotHeight);
806
+ return /* @__PURE__ */ jsx(
807
+ "div",
808
+ {
809
+ "aria-hidden": "true",
810
+ "data-invalid": draft.valid ? void 0 : "true",
811
+ className: cn(chipTone(draft.event?.color), GHOST, !draft.valid && GHOST_INVALID),
812
+ style: {
813
+ top,
814
+ height,
815
+ left: `${columnIndex / days.length * 100}%`,
816
+ width: `${1 / days.length * 100}%`
817
+ },
818
+ children: /* @__PURE__ */ jsxs("span", { className: "flex h-full items-center gap-1 px-2 text-xs font-medium", children: [
819
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatIn(draft.start, config.timeZone, "HH:mm", config.locale) }),
820
+ draft.event ? /* @__PURE__ */ jsx("span", { className: "truncate", children: draft.event.title }) : null
821
+ ] })
822
+ }
823
+ );
824
+ }
825
+ function LaneGhost({ draft, config, row, size }) {
826
+ if (!draft.allDay) return null;
827
+ const startKey = dayKey(draft.start, config.timeZone);
828
+ const lastKey = dayKey(new Date(draft.end.getTime() - 1), config.timeZone);
829
+ const from = row.findIndex((d) => d.key === startKey);
830
+ const to = row.findIndex((d) => d.key === lastKey);
831
+ if (from === -1 && to === -1) return null;
832
+ const first = from === -1 ? 0 : from;
833
+ const last = to === -1 ? row.length - 1 : to;
834
+ if (last < first) return null;
835
+ return /* @__PURE__ */ jsx(
836
+ "div",
837
+ {
838
+ "aria-hidden": "true",
839
+ "data-invalid": draft.valid ? void 0 : "true",
840
+ className: cn(chipTone(draft.event?.color), GHOST, "px-px", !draft.valid && GHOST_INVALID),
841
+ style: { gridColumn: `${first + 1} / span ${last - first + 1}`, gridRow: 1, position: "relative", height: BAR_PX[size] },
842
+ children: /* @__PURE__ */ jsx("span", { className: "flex h-full items-center px-2 text-xs font-medium", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: draft.event?.title ?? formatIn(draft.start, config.timeZone, "d MMM", config.locale) }) })
843
+ }
844
+ );
845
+ }
846
+ TimeGhost.displayName = "TimeGhost";
847
+ LaneGhost.displayName = "LaneGhost";
848
+ var ANNOUNCE_MS = 300;
849
+ var ARROWS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
850
+ function describe(event, range, kind, instance) {
851
+ const { timeZone: tz, locale } = instance.config;
852
+ if (kind === "resize") {
853
+ return `${event.title} now ends at ${formatIn(range.end, tz, "HH:mm", locale)}`;
854
+ }
855
+ const when = formatIn(range.start, tz, event.allDay === true ? "EEEE d MMMM" : "EEEE HH:mm", locale);
856
+ return `${event.title} moved to ${when}`;
857
+ }
858
+ function useGrabMode(instance) {
859
+ const { config, canPlace, setDraft, commit, grabbed, setGrabbed } = instance;
860
+ const [announcement, setAnnouncement] = React.useState("");
861
+ const range = React.useRef(null);
862
+ const timer = React.useRef(null);
863
+ const latest = React.useRef({ config, canPlace, setDraft, commit, grabbed, setGrabbed, instance });
864
+ latest.current = { config, canPlace, setDraft, commit, grabbed, setGrabbed, instance };
865
+ const announce = React.useCallback((text) => {
866
+ if (timer.current !== null) clearTimeout(timer.current);
867
+ timer.current = setTimeout(() => {
868
+ timer.current = null;
869
+ setAnnouncement(text);
870
+ }, ANNOUNCE_MS);
871
+ }, []);
872
+ React.useEffect(
873
+ () => () => {
874
+ if (timer.current !== null) clearTimeout(timer.current);
875
+ },
876
+ []
877
+ );
878
+ const release = React.useCallback(() => {
879
+ range.current = null;
880
+ latest.current.setDraft(null);
881
+ latest.current.setGrabbed(null);
882
+ }, []);
883
+ const keyHandler = React.useCallback(
884
+ (event) => (e) => {
885
+ const isHeld = latest.current.grabbed?.id === event.id;
886
+ if (!isHeld) {
887
+ if (e.key !== "Enter" && e.key !== " ") return;
888
+ if (event.disabled === true) return;
889
+ e.preventDefault();
890
+ range.current = { start: event.start, end: event.end };
891
+ latest.current.setGrabbed(event);
892
+ latest.current.setDraft({ kind: "move", event, start: event.start, end: event.end, allDay: event.allDay === true, valid: true });
893
+ setAnnouncement(`Grabbed ${event.title}. Use arrow keys to move, Enter to confirm, Escape to cancel.`);
894
+ return;
895
+ }
896
+ if (e.key === "Escape") {
897
+ e.preventDefault();
898
+ release();
899
+ setAnnouncement(`Cancelled. ${event.title} unchanged.`);
900
+ return;
901
+ }
902
+ if (e.key === "Enter" || e.key === " ") {
903
+ e.preventDefault();
904
+ const next2 = range.current;
905
+ release();
906
+ if (!next2) return;
907
+ if (next2.start.getTime() === event.start.getTime() && next2.end.getTime() === event.end.getTime()) return;
908
+ latest.current.commit(event, next2);
909
+ return;
910
+ }
911
+ if (!ARROWS.has(e.key)) return;
912
+ e.preventDefault();
913
+ e.stopPropagation();
914
+ const cfg = latest.current.config;
915
+ const from = range.current ?? { start: event.start, end: event.end };
916
+ const shifted = { ...event, start: from.start, end: from.end };
917
+ let next;
918
+ let kind = "move";
919
+ switch (e.key) {
920
+ case "ArrowUp":
921
+ case "ArrowDown": {
922
+ const step2 = e.key === "ArrowDown" ? cfg.slotDuration : -cfg.slotDuration;
923
+ if (e.shiftKey) {
924
+ kind = "resize";
925
+ next = resizeDraft(shifted, "end", step2, cfg);
926
+ } else {
927
+ next = moveDraft(shifted, { days: 0, minutes: step2 }, cfg);
928
+ }
929
+ break;
930
+ }
931
+ default: {
932
+ next = moveDraft(shifted, { days: e.key === "ArrowRight" ? 1 : -1, minutes: 0 }, cfg);
933
+ }
934
+ }
935
+ const allDay = event.allDay === true;
936
+ if (!latest.current.canPlace({ event, start: next.start, end: next.end, allDay })) return;
937
+ range.current = next;
938
+ latest.current.setDraft({ kind, event, start: next.start, end: next.end, allDay, valid: true });
939
+ announce(describe(event, next, kind, latest.current.instance));
940
+ },
941
+ [announce, release]
942
+ );
943
+ const blurHandler = React.useCallback(
944
+ (event) => () => {
945
+ if (latest.current.grabbed?.id !== event.id) return;
946
+ release();
947
+ },
948
+ [release]
949
+ );
950
+ return { keyHandler, blurHandler, grabbedId: grabbed?.id ?? null, announcement };
951
+ }
952
+ var MONTH_CELL_BUDGET = 4;
953
+ function MonthView({ instance, size, focusRef }) {
954
+ const { config, layout, visibleEvents, onEventClick, onSlotClick, canPlace, draft } = instance;
955
+ const { monthRows, lanes } = layout;
956
+ const gridRef = React.useRef(null);
957
+ const drag = useCalendarDrag({ instance, gridRef, days: monthRows.flat(), axis: "day" });
958
+ const grab = useGrabMode(instance);
959
+ const barHeight = BAR_PX[size];
960
+ const laneRows = lanes.maxLane + 1;
961
+ const laneStripHeight = laneRows * (barHeight + BAR_GAP_PX);
962
+ const headerDays = monthRows[0] ?? [];
963
+ const spanningIds = React.useMemo(() => new Set(lanes.segments.map((s) => s.event.id)), [lanes.segments]);
964
+ const hiddenIds = React.useMemo(() => new Set([...lanes.hidden.values()].flat().map((e) => e.id)), [lanes.hidden]);
965
+ const chipBudget = Math.max(1, MONTH_CELL_BUDGET - laneRows);
966
+ return /* @__PURE__ */ jsxs("div", { ref: focusRef, className: "flex min-w-0 flex-col", children: [
967
+ /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", children: grab.announcement }),
968
+ /* @__PURE__ */ jsx("div", { className: cn("grid grid-cols-7 border-b", GRID_LINE), children: headerDays.map((d) => /* @__PURE__ */ jsx("div", { className: cn("px-2 py-2 text-center", WEEKDAY_HEADER), children: formatIn(d.date, config.timeZone, "EEEEEE", config.locale) }, d.key)) }),
969
+ /* @__PURE__ */ jsx("div", { ref: gridRef, className: cn("grid min-w-0 border-l", GRID_LINE), style: { gridTemplateRows: monthRowTemplate(size) }, children: monthRows.map((row, rowIndex) => /* @__PURE__ */ jsxs("div", { className: "relative grid min-h-0 grid-cols-7", children: [
970
+ row.map((day2) => {
971
+ const ofDay = visibleEvents.filter((e) => !spanningIds.has(e.id) && !hiddenIds.has(e.id) && dayKey(e.start, config.timeZone) === day2.key);
972
+ const single = ofDay.slice(0, chipBudget);
973
+ const clipped = ofDay.slice(chipBudget);
974
+ const hiddenHere = [...lanes.hidden.get(day2.key) ?? [], ...clipped];
975
+ const moreCount = hiddenHere.length;
976
+ const wholeDay = { start: day2.date, end: endOfDayExclusive(day2.date, config), allDay: true };
977
+ const placeable = canPlace({ event: null, ...wholeDay });
978
+ const dayName = formatIn(day2.date, config.timeZone, "EEEE, d MMMM", config.locale);
979
+ return /* @__PURE__ */ jsxs(
980
+ "div",
981
+ {
982
+ ...{ [DAY_ATTR]: day2.key },
983
+ className: cn("relative flex min-h-0 min-w-0 flex-col gap-1 border-r border-b p-1", GRID_LINE, day2.outside && OUTSIDE_CELL),
984
+ children: [
985
+ /* @__PURE__ */ jsx(
986
+ "button",
987
+ {
988
+ type: "button",
989
+ "aria-label": placeable ? dayName : `${dayName} (unavailable)`,
990
+ disabled: !placeable,
991
+ onClick: placeable ? () => onSlotClick(wholeDay) : void 0,
992
+ ...placeable ? drag.createHandlers(day2, null) : {},
993
+ className: cn(
994
+ // No radius: the wash fills the whole square cell, and a rounded one left
995
+ // four unpainted corners against the grid lines.
996
+ "absolute inset-0",
997
+ // A refused day now SHOWS that it is refused. It used to carry a cursor and
998
+ // nothing else, so the only reader who found out was one already pointing at it.
999
+ placeable ? SLOT_HOVER : SLOT_UNAVAILABLE,
1000
+ FOCUS_RING,
1001
+ // Inset, because this cell's edge is its neighbour's too — an OFFSET outline
1002
+ // would paint over the grid line and read as a 2px-wide rule.
1003
+ "focus-visible:-outline-offset-2"
1004
+ )
1005
+ }
1006
+ ),
1007
+ /* @__PURE__ */ jsx("div", { className: "pointer-events-none relative flex items-center px-0.5", children: /* @__PURE__ */ jsx("span", { className: cn(DAY_NUMBER, day2.outside && DAY_NUMBER_OUTSIDE, day2.today && DAY_NUMBER_DISC), children: formatIn(day2.date, config.timeZone, "d", config.locale) }) }),
1008
+ laneRows > 0 ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", style: { height: laneStripHeight } }) : null,
1009
+ /* @__PURE__ */ jsx("div", { className: cn("relative flex min-w-0 flex-col gap-1", MONTH_CHIP_NARROW), children: single.map((event) => /* @__PURE__ */ jsx(
1010
+ EventChip,
1011
+ {
1012
+ event,
1013
+ size,
1014
+ variant: "bar",
1015
+ config,
1016
+ showTime: event.allDay !== true,
1017
+ onActivate: onEventClick,
1018
+ dragging: drag.draggingId === event.id,
1019
+ grabbed: grab.grabbedId === event.id,
1020
+ dragHandlers: drag.moveHandlers(event),
1021
+ onKeyDown: grab.keyHandler(event),
1022
+ onBlur: grab.blurHandler(event)
1023
+ },
1024
+ event.id
1025
+ )) }),
1026
+ /* @__PURE__ */ jsx("div", { className: cn("relative flex-wrap items-center gap-1 px-1", MONTH_DOT_NARROW), children: single.map((event) => /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("size-1.5 rounded-full bg-current", chipAccent(event.color)) }, event.id)) }),
1027
+ moreCount > 0 ? /* @__PURE__ */ jsx(
1028
+ Popover,
1029
+ {
1030
+ trigger: /* @__PURE__ */ jsxs("button", { type: "button", className: cn("relative", MORE_TRIGGER, FOCUS_RING), children: [
1031
+ "+",
1032
+ moreCount,
1033
+ " more"
1034
+ ] }),
1035
+ side: "bottom",
1036
+ align: "start",
1037
+ size: "sm",
1038
+ title: dayName,
1039
+ children: /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1", children: hiddenHere.map((event) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(EventChip, { event, size, variant: "row", config, onActivate: onEventClick }) }, event.id)) })
1040
+ }
1041
+ ) : null
1042
+ ]
1043
+ },
1044
+ day2.key
1045
+ );
1046
+ }),
1047
+ laneRows > 0 ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 grid grid-cols-7 px-1 pt-7", children: lanes.segments.filter((s) => s.rowIndex === rowIndex).map((segment) => /* @__PURE__ */ jsx(
1048
+ "div",
1049
+ {
1050
+ className: "pointer-events-auto px-px",
1051
+ style: {
1052
+ gridColumn: `${segment.dayIndex + 1} / span ${segment.span}`,
1053
+ gridRow: 1,
1054
+ height: barHeight,
1055
+ marginTop: segment.lane * (barHeight + BAR_GAP_PX)
1056
+ },
1057
+ children: /* @__PURE__ */ jsx(
1058
+ EventChip,
1059
+ {
1060
+ event: segment.event,
1061
+ size,
1062
+ variant: "bar",
1063
+ config,
1064
+ onActivate: onEventClick,
1065
+ clipStart: !segment.isStart,
1066
+ clipEnd: !segment.isEnd,
1067
+ dragging: drag.draggingId === segment.event.id,
1068
+ grabbed: grab.grabbedId === segment.event.id,
1069
+ dragHandlers: drag.moveHandlers(segment.event),
1070
+ onKeyDown: grab.keyHandler(segment.event),
1071
+ onBlur: grab.blurHandler(segment.event)
1072
+ }
1073
+ )
1074
+ },
1075
+ segment.event.id
1076
+ )) }) : null,
1077
+ draft ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 grid grid-cols-7 px-1 pt-7", children: /* @__PURE__ */ jsx(LaneGhost, { draft, config, row, size }) }) : null
1078
+ ] }, row[0]?.key ?? rowIndex)) })
1079
+ ] });
1080
+ }
1081
+ MonthView.displayName = "MonthView";
1082
+ function TimeGridView({ instance, size, showNowLine, focusRef }) {
1083
+ const { config, layout, onEventClick, onSlotClick, canPlace } = instance;
1084
+ const { days, timed, lanes } = layout;
1085
+ const slotHeight = SLOT_PX[size];
1086
+ const rows = slotCount(config);
1087
+ const gridHeight = rows * slotHeight;
1088
+ const barHeight = BAR_PX[size];
1089
+ const laneRows = Math.max(1, lanes.maxLane + 1);
1090
+ const scrollerRef = React.useRef(null);
1091
+ const gutterRef = React.useRef(null);
1092
+ const allDayRef = React.useRef(null);
1093
+ const gridRef = React.useRef(null);
1094
+ useIsomorphicLayoutEffect(() => {
1095
+ warnStickyNoScrollport("Calendar", "the hour gutter", gutterRef.current);
1096
+ warnStickyNoScrollport("Calendar", "the all-day row", allDayRef.current);
1097
+ }, []);
1098
+ const nowPx = React.useMemo(
1099
+ // The rect is passed IN, per the geometry contract — the view is the only thing allowed to read
1100
+ // the DOM, and it hands a plain `Rect` to the pure function.
1101
+ () => showNowLine ? nowOffset(config, { height: gridHeight }, days) : null,
1102
+ [config, days, gridHeight, showNowLine]
1103
+ );
1104
+ const scrolledOnce = React.useRef(false);
1105
+ useIsomorphicLayoutEffect(() => {
1106
+ if (scrolledOnce.current) return;
1107
+ const el = scrollerRef.current;
1108
+ const gridEl = gridRef.current;
1109
+ if (!el || !gridEl) return;
1110
+ scrolledOnce.current = true;
1111
+ const box = { viewportHeight: el.clientHeight, contentHeight: el.scrollHeight, gridTop: gridEl.offsetTop };
1112
+ el.scrollTop = initialScrollTop(nowPx, box, config, slotHeight);
1113
+ }, [config, nowPx, slotHeight]);
1114
+ const hourLabels = React.useMemo(() => {
1115
+ const [from] = config.hours;
1116
+ const perHour = 60 / config.slotDuration;
1117
+ const out = [];
1118
+ for (let i = 0; i < rows; i += 1) {
1119
+ if (i % perHour !== 0) continue;
1120
+ const hour = from + i / perHour;
1121
+ out.push({
1122
+ key: hour,
1123
+ // `HH:mm` at every step, locale-formatted — a 12-hour locale gets its own am/pm through the
1124
+ // locale object rather than through a format flag we would have to expose.
1125
+ label: formatIn(windowMinutesToInstant(days[0]?.date ?? config.now, i * config.slotDuration, config), config.timeZone, "HH:mm", config.locale),
1126
+ top: i * slotHeight
1127
+ });
1128
+ }
1129
+ return out;
1130
+ }, [config, days, rows, slotHeight]);
1131
+ const oneColumn = days.length === 1;
1132
+ const columnsClass = oneColumn ? "grid-cols-1" : WEEK_NARROW_COLS;
1133
+ const narrowHide = oneColumn ? "" : WEEK_NARROW_HIDE;
1134
+ const focusedKey = days.find((d) => d.date.getTime() === instance.focusedDate.getTime())?.key ?? days[0]?.key;
1135
+ const drag = useCalendarDrag({ instance, gridRef, days, axis: "time" });
1136
+ const grab = useGrabMode(instance);
1137
+ const { draft } = instance;
1138
+ return /* @__PURE__ */ jsxs("div", { ref: focusRef, className: "flex min-h-0 min-w-0 flex-col", children: [
1139
+ /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", children: grab.announcement }),
1140
+ /* @__PURE__ */ jsxs(
1141
+ "div",
1142
+ {
1143
+ className: cn("grid shrink-0 border-b", GRID_LINE, "grid-cols-[var(--cal-gutter)_1fr]"),
1144
+ style: { "--cal-gutter": gutterWidth(size) },
1145
+ children: [
1146
+ /* @__PURE__ */ jsx("div", { className: cn(GUTTER_W[size], "border-r", GRID_LINE) }),
1147
+ /* @__PURE__ */ jsx("div", { className: cn("grid", columnsClass), children: days.map((day2) => (
1148
+ // ONE line — `Sun 2`, not `Sun` stacked over `2`. Two lines cost ~20px of vertical space
1149
+ // in a header that repeats above a scrolling grid, and the pair reads as one label
1150
+ // anyway. Today's numeral takes the same brand disc the month cell uses; it used to be a
1151
+ // colour shift only, which is the weakest of the three marks in the component.
1152
+ /* @__PURE__ */ jsxs("div", { className: cn("flex items-center justify-center gap-1.5 border-r py-1.5", GRID_LINE, day2.key !== focusedKey && narrowHide), children: [
1153
+ /* @__PURE__ */ jsx("span", { className: WEEKDAY_HEADER, children: formatIn(day2.date, config.timeZone, "EEE", config.locale) }),
1154
+ /* @__PURE__ */ jsx("span", { className: cn(DAY_NUMBER, day2.today && DAY_NUMBER_DISC), children: formatIn(day2.date, config.timeZone, "d", config.locale) })
1155
+ ] }, day2.key)
1156
+ )) })
1157
+ ]
1158
+ }
1159
+ ),
1160
+ /* @__PURE__ */ jsxs("div", { ref: scrollerRef, className: cn(SCROLLER), children: [
1161
+ /* @__PURE__ */ jsxs(
1162
+ "div",
1163
+ {
1164
+ ref: allDayRef,
1165
+ className: cn("grid", ALL_DAY_ROW, "grid-cols-[var(--cal-gutter)_1fr]"),
1166
+ style: { "--cal-gutter": gutterWidth(size) },
1167
+ children: [
1168
+ /* @__PURE__ */ jsx("div", { className: cn(GUTTER_W[size], "border-r py-1 pr-2 text-right", GRID_LINE, HOUR_GUTTER, "static"), children: "all-day" }),
1169
+ /* @__PURE__ */ jsxs("div", { className: cn("relative grid px-1 py-1", columnsClass), style: { minHeight: laneRows * (barHeight + BAR_GAP_PX) }, children: [
1170
+ lanes.segments.map((segment) => /* @__PURE__ */ jsx(
1171
+ "div",
1172
+ {
1173
+ className: "px-px",
1174
+ style: {
1175
+ gridColumn: oneColumn ? "1 / span 1" : `${segment.dayIndex + 1} / span ${segment.span}`,
1176
+ gridRow: 1,
1177
+ height: barHeight,
1178
+ marginTop: segment.lane * (barHeight + BAR_GAP_PX)
1179
+ },
1180
+ children: /* @__PURE__ */ jsx(
1181
+ EventChip,
1182
+ {
1183
+ event: segment.event,
1184
+ size,
1185
+ variant: "bar",
1186
+ config,
1187
+ onActivate: onEventClick,
1188
+ clipStart: !segment.isStart,
1189
+ clipEnd: !segment.isEnd,
1190
+ dragging: drag.draggingId === segment.event.id,
1191
+ grabbed: grab.grabbedId === segment.event.id,
1192
+ dragHandlers: drag.moveHandlers(segment.event),
1193
+ onKeyDown: grab.keyHandler(segment.event),
1194
+ onBlur: grab.blurHandler(segment.event)
1195
+ }
1196
+ )
1197
+ },
1198
+ segment.event.id
1199
+ )),
1200
+ draft ? /* @__PURE__ */ jsx(LaneGhost, { draft, config, row: days, size }) : null
1201
+ ] })
1202
+ ]
1203
+ }
1204
+ ),
1205
+ /* @__PURE__ */ jsxs("div", { className: cn("grid", "grid-cols-[var(--cal-gutter)_1fr]"), style: { "--cal-gutter": gutterWidth(size) }, children: [
1206
+ /* @__PURE__ */ jsx("div", { ref: gutterRef, className: cn(GUTTER_W[size], "relative border-r", GRID_LINE, HOUR_GUTTER), style: { height: gridHeight }, children: hourLabels.map((h) => (
1207
+ // -translate-y-1/2 centres the label ON its rule rather than below it, and the first
1208
+ // label would otherwise be clipped by the scroller's top edge.
1209
+ /* @__PURE__ */ jsx("span", { className: "absolute right-2 -translate-y-1/2", style: { top: h.top }, children: h.top === 0 ? "" : h.label }, h.key)
1210
+ )) }),
1211
+ /* @__PURE__ */ jsxs("div", { ref: gridRef, className: cn("relative grid", columnsClass), style: { height: gridHeight }, children: [
1212
+ days.map((day2) => {
1213
+ const positioned = timed.get(day2.key) ?? [];
1214
+ return (
1215
+ // `data-cal-day` is how a gesture names the day under the pointer without measuring
1216
+ // 42 cells — see the note in `drag.ts`.
1217
+ /* @__PURE__ */ jsxs("div", { ...{ [DAY_ATTR]: day2.key }, className: cn("relative border-r", GRID_LINE, day2.key !== focusedKey && narrowHide), children: [
1218
+ Array.from({ length: rows }, (_, i) => {
1219
+ const start = windowMinutesToInstant(day2.date, i * config.slotDuration, config);
1220
+ const end = new Date(start.getTime() + config.slotDuration * 6e4);
1221
+ const placeable = canPlace({ event: null, start, end, allDay: false });
1222
+ return /* @__PURE__ */ jsx(
1223
+ "button",
1224
+ {
1225
+ type: "button",
1226
+ disabled: !placeable,
1227
+ onClick: placeable ? () => onSlotClick({ start, end, allDay: false }) : void 0,
1228
+ ...placeable ? drag.createHandlers(day2, i * config.slotDuration) : {},
1229
+ "aria-label": `${formatIn(start, config.timeZone, "EEEE d MMMM, HH:mm", config.locale)}${placeable ? "" : " (unavailable)"}`,
1230
+ className: cn(
1231
+ "absolute inset-x-0 border-b",
1232
+ // TWO weights, not one. The hour keeps the full rule; the half hour gets a
1233
+ // subtler one. Ruling the hour ALONE (what this did) left a 40px-tall hour
1234
+ // box with no internal reference, so an event on the half hour had nothing
1235
+ // to land on — while ruling every `slotDuration` step turns a 15-minute
1236
+ // grid into ruled paper. `slotRuleEvery` floors the interval at 30 minutes,
1237
+ // which is what buys both.
1238
+ (i + 1) % (60 / config.slotDuration) === 0 ? GRID_LINE : (i + 1) % slotRuleEvery(config.slotDuration) === 0 ? GRID_LINE_SUBTLE : "border-transparent",
1239
+ placeable ? SLOT_HOVER : SLOT_UNAVAILABLE,
1240
+ FOCUS_RING,
1241
+ "focus-visible:-outline-offset-2"
1242
+ ),
1243
+ style: { top: i * slotHeight, height: slotHeight }
1244
+ },
1245
+ i
1246
+ );
1247
+ }),
1248
+ positioned.map((p) => /* @__PURE__ */ jsx(
1249
+ "div",
1250
+ {
1251
+ className: BLOCK_POSITION,
1252
+ style: {
1253
+ top: p.startMinutes / config.slotDuration * slotHeight,
1254
+ height: Math.max(slotHeight / 2, (p.endMinutes - p.startMinutes) / config.slotDuration * slotHeight),
1255
+ "--cal-inset": `${blockInsetPercent(p.column, p.columns)}%`
1256
+ },
1257
+ children: /* @__PURE__ */ jsx(
1258
+ EventChip,
1259
+ {
1260
+ event: p.event,
1261
+ size,
1262
+ variant: "block",
1263
+ config,
1264
+ onActivate: onEventClick,
1265
+ dragging: drag.draggingId === p.event.id,
1266
+ grabbed: grab.grabbedId === p.event.id,
1267
+ dragHandlers: drag.moveHandlers(p.event),
1268
+ onKeyDown: grab.keyHandler(p.event),
1269
+ onBlur: grab.blurHandler(p.event),
1270
+ children: p.event.disabled === true ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
1271
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(RESIZE_ZONE, "top-0"), ...drag.resizeHandlers(p.event, "start") }),
1272
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(RESIZE_ZONE, "bottom-0"), ...drag.resizeHandlers(p.event, "end") })
1273
+ ] })
1274
+ }
1275
+ )
1276
+ },
1277
+ p.event.id
1278
+ ))
1279
+ ] }, day2.key)
1280
+ );
1281
+ }),
1282
+ draft ? /* @__PURE__ */ jsx(TimeGhost, { draft, config, days, size, slotHeight }) : null,
1283
+ nowPx !== null ? /* @__PURE__ */ jsx("div", { className: NOW_LINE, style: { top: nowPx }, "aria-hidden": "true", children: /* @__PURE__ */ jsx("span", { className: NOW_DOT }) }) : null
1284
+ ] })
1285
+ ] })
1286
+ ] })
1287
+ ] });
1288
+ }
1289
+ function gutterWidth(size) {
1290
+ return { sm: "3rem", md: "3.5rem", lg: "4rem" }[size];
1291
+ }
1292
+ TimeGridView.displayName = "TimeGridView";
1293
+ function Calendar(props) {
1294
+ const { instance, size = "md", showNowLine = true, className } = props;
1295
+ const ariaLabel = props["aria-label"];
1296
+ const rootRef = React.useRef(null);
1297
+ const view = instance.view;
1298
+ const body = view === "month" ? /* @__PURE__ */ jsx(MonthView, { instance, size, showNowLine, focusRef: rootRef }) : view === "agenda" ? /* @__PURE__ */ jsx(AgendaView, { instance, size, showNowLine, focusRef: rootRef }) : (
1299
+ // Week and day are ONE implementation — day is a `dayCount` of 1, not a second grid.
1300
+ /* @__PURE__ */ jsx(TimeGridView, { instance, size, showNowLine, focusRef: rootRef })
1301
+ );
1302
+ return /* @__PURE__ */ jsx("div", { className: cn(CONTAINER, className), children: /* @__PURE__ */ jsx(
1303
+ "section",
1304
+ {
1305
+ "aria-label": ariaLabel ?? `Calendar, ${instance.periodLabel}`,
1306
+ className: cn(ROOT, "h-full"),
1307
+ children: body
1308
+ }
1309
+ ) });
1310
+ }
1311
+ Calendar.displayName = "Calendar";
1312
+
1313
+ export { Calendar, isWireDate, parseEvent, serializeEvent, useCalendar };
1314
+ //# sourceMappingURL=chunk-J36M3KRX.js.map
1315
+ //# sourceMappingURL=chunk-J36M3KRX.js.map