magic-pill 9.0.0 → 9.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 (149) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +259 -15
  3. package/dist/MagicPill/MagicPill.d.mts +7 -1
  4. package/dist/MagicPill/MagicPill.d.ts +7 -1
  5. package/dist/MagicPill/MagicPill.js +40 -17
  6. package/dist/MagicPill/MagicPill.mjs +42 -19
  7. package/dist/MagicPill/choreography.js +1 -1
  8. package/dist/MagicPill/choreography.mjs +1 -1
  9. package/dist/Pill/Pill.js +53 -17
  10. package/dist/Pill/Pill.mjs +54 -18
  11. package/dist/Pill/PillContext.js +3 -1
  12. package/dist/Pill/PillContext.mjs +3 -1
  13. package/dist/Pill/PillPanel.d.mts +5 -5
  14. package/dist/Pill/PillPanel.d.ts +5 -5
  15. package/dist/Pill/PillPanel.js +28 -20
  16. package/dist/Pill/PillPanel.mjs +28 -20
  17. package/dist/Pill/morph.js +25 -7
  18. package/dist/Pill/morph.mjs +22 -8
  19. package/dist/Pill/scene.js +90 -0
  20. package/dist/Pill/scene.mjs +89 -0
  21. package/dist/Pill/themed.js +36 -0
  22. package/dist/Pill/themed.mjs +34 -0
  23. package/dist/Pill/types.d.mts +50 -0
  24. package/dist/Pill/types.d.ts +50 -0
  25. package/dist/Pill/zone.js +160 -0
  26. package/dist/Pill/zone.mjs +159 -0
  27. package/dist/PillForm/Calendar.d.mts +15 -0
  28. package/dist/PillForm/Calendar.d.ts +16 -0
  29. package/dist/PillForm/Calendar.js +371 -0
  30. package/dist/PillForm/Calendar.mjs +370 -0
  31. package/dist/PillForm/FormContext.d.mts +2 -0
  32. package/dist/PillForm/FormContext.d.ts +2 -0
  33. package/dist/PillForm/FormContext.js +8 -0
  34. package/dist/PillForm/FormContext.mjs +8 -0
  35. package/dist/PillForm/PillCheckbox.d.mts +8 -0
  36. package/dist/PillForm/PillCheckbox.d.ts +8 -0
  37. package/dist/PillForm/PillCheckbox.js +45 -0
  38. package/dist/PillForm/PillCheckbox.mjs +45 -0
  39. package/dist/PillForm/PillChoices.d.mts +39 -0
  40. package/dist/PillForm/PillChoices.d.ts +39 -0
  41. package/dist/PillForm/PillChoices.js +103 -0
  42. package/dist/PillForm/PillChoices.mjs +103 -0
  43. package/dist/PillForm/PillCode.d.mts +12 -0
  44. package/dist/PillForm/PillCode.d.ts +12 -0
  45. package/dist/PillForm/PillCode.js +60 -0
  46. package/dist/PillForm/PillCode.mjs +60 -0
  47. package/dist/PillForm/PillColor.d.mts +10 -0
  48. package/dist/PillForm/PillColor.d.ts +10 -0
  49. package/dist/PillForm/PillColor.js +56 -0
  50. package/dist/PillForm/PillColor.mjs +56 -0
  51. package/dist/PillForm/PillDate.d.mts +44 -0
  52. package/dist/PillForm/PillDate.d.ts +44 -0
  53. package/dist/PillForm/PillDate.js +193 -0
  54. package/dist/PillForm/PillDate.mjs +193 -0
  55. package/dist/PillForm/PillField.d.mts +38 -0
  56. package/dist/PillForm/PillField.d.ts +38 -0
  57. package/dist/PillForm/PillField.js +81 -0
  58. package/dist/PillForm/PillField.mjs +80 -0
  59. package/dist/PillForm/PillFields.d.mts +11 -0
  60. package/dist/PillForm/PillFields.d.ts +11 -0
  61. package/dist/PillForm/PillFields.js +21 -0
  62. package/dist/PillForm/PillFields.mjs +21 -0
  63. package/dist/PillForm/PillFile.d.mts +8 -0
  64. package/dist/PillForm/PillFile.d.ts +8 -0
  65. package/dist/PillForm/PillFile.js +55 -0
  66. package/dist/PillForm/PillFile.mjs +55 -0
  67. package/dist/PillForm/PillForm.d.mts +29 -0
  68. package/dist/PillForm/PillForm.d.ts +29 -0
  69. package/dist/PillForm/PillForm.js +66 -0
  70. package/dist/PillForm/PillForm.mjs +65 -0
  71. package/dist/PillForm/PillFormPanel.d.mts +24 -0
  72. package/dist/PillForm/PillFormPanel.d.ts +24 -0
  73. package/dist/PillForm/PillFormPanel.js +53 -0
  74. package/dist/PillForm/PillFormPanel.mjs +53 -0
  75. package/dist/PillForm/PillInput.d.mts +20 -0
  76. package/dist/PillForm/PillInput.d.ts +20 -0
  77. package/dist/PillForm/PillInput.js +84 -0
  78. package/dist/PillForm/PillInput.mjs +84 -0
  79. package/dist/PillForm/PillSelect.d.mts +23 -0
  80. package/dist/PillForm/PillSelect.d.ts +23 -0
  81. package/dist/PillForm/PillSelect.js +87 -0
  82. package/dist/PillForm/PillSelect.mjs +87 -0
  83. package/dist/PillForm/PillSlider.d.mts +17 -0
  84. package/dist/PillForm/PillSlider.d.ts +17 -0
  85. package/dist/PillForm/PillSlider.js +61 -0
  86. package/dist/PillForm/PillSlider.mjs +61 -0
  87. package/dist/PillForm/PillStepper.d.mts +13 -0
  88. package/dist/PillForm/PillStepper.d.ts +13 -0
  89. package/dist/PillForm/PillStepper.js +84 -0
  90. package/dist/PillForm/PillStepper.mjs +84 -0
  91. package/dist/PillForm/PillSubmit.d.mts +14 -0
  92. package/dist/PillForm/PillSubmit.d.ts +14 -0
  93. package/dist/PillForm/PillSubmit.js +90 -0
  94. package/dist/PillForm/PillSubmit.mjs +89 -0
  95. package/dist/PillForm/PillSwitch.d.mts +5 -0
  96. package/dist/PillForm/PillSwitch.d.ts +5 -0
  97. package/dist/PillForm/PillSwitch.js +38 -0
  98. package/dist/PillForm/PillSwitch.mjs +38 -0
  99. package/dist/PillForm/PillTextarea.d.mts +5 -0
  100. package/dist/PillForm/PillTextarea.d.ts +5 -0
  101. package/dist/PillForm/PillTextarea.js +49 -0
  102. package/dist/PillForm/PillTextarea.mjs +49 -0
  103. package/dist/PillForm/dates.d.mts +1 -0
  104. package/dist/PillForm/dates.d.ts +1 -0
  105. package/dist/PillForm/dates.js +155 -0
  106. package/dist/PillForm/dates.mjs +139 -0
  107. package/dist/PillForm/glyphs.js +65 -0
  108. package/dist/PillForm/glyphs.mjs +56 -0
  109. package/dist/PillForm/keyboard.js +34 -0
  110. package/dist/PillForm/keyboard.mjs +34 -0
  111. package/dist/PillForm/popover.js +84 -0
  112. package/dist/PillForm/popover.mjs +83 -0
  113. package/dist/PillForm/send.d.mts +6 -0
  114. package/dist/PillForm/send.d.ts +6 -0
  115. package/dist/PillForm/send.js +44 -0
  116. package/dist/PillForm/send.mjs +44 -0
  117. package/dist/PillForm/validity.js +74 -0
  118. package/dist/PillForm/validity.mjs +72 -0
  119. package/dist/PillNavbar/PillNavbar.d.mts +29 -6
  120. package/dist/PillNavbar/PillNavbar.d.ts +29 -6
  121. package/dist/PillNavbar/PillNavbar.js +35 -11
  122. package/dist/PillNavbar/PillNavbar.mjs +36 -12
  123. package/dist/PillNavbar/room.js +84 -0
  124. package/dist/PillNavbar/room.mjs +83 -0
  125. package/dist/PillNotification/PillNotification.d.mts +6 -0
  126. package/dist/PillNotification/PillNotification.d.ts +6 -0
  127. package/dist/PillNotification/PillNotification.js +3 -0
  128. package/dist/PillNotification/PillNotification.mjs +3 -0
  129. package/dist/PillOptics/PillOptics.d.mts +8 -0
  130. package/dist/PillOptics/PillOptics.d.ts +8 -0
  131. package/dist/PillOptics/PillOptics.js +195 -0
  132. package/dist/PillOptics/PillOptics.mjs +195 -0
  133. package/dist/PillOptics/adaptive.js +212 -0
  134. package/dist/PillOptics/adaptive.mjs +208 -0
  135. package/dist/PillOptics/lens.js +77 -0
  136. package/dist/PillOptics/lens.mjs +73 -0
  137. package/dist/PillOptics/light.js +37 -0
  138. package/dist/PillOptics/light.mjs +36 -0
  139. package/dist/calendar.css +499 -0
  140. package/dist/forms.css +1452 -0
  141. package/dist/index.d.mts +24 -3
  142. package/dist/index.d.ts +24 -3
  143. package/dist/index.js +36 -0
  144. package/dist/index.mjs +19 -1
  145. package/dist/styles.css +169 -19
  146. package/dist/themes.css +449 -0
  147. package/dist/utils/visuallyHidden.js +18 -0
  148. package/dist/utils/visuallyHidden.mjs +18 -0
  149. package/package.json +4 -1
@@ -0,0 +1,371 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_dates = require("./dates.js");
5
+ const require_glyphs = require("./glyphs.js");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+
8
+ // src/PillForm/Calendar.tsx
9
+ const CALENDAR_LABELS = {
10
+ previous: "Previous",
11
+ next: "Next",
12
+ zoomOut: "Choose a month",
13
+ today: "Today",
14
+ now: "Now",
15
+ clear: "Clear",
16
+ done: "Done",
17
+ hours: "Hours",
18
+ minutes: "Minutes",
19
+ period: "AM or PM",
20
+ week: "Week"
21
+ };
22
+ const YEARS = 12;
23
+ const range = (length) => Array.from({ length }, (_, index) => index);
24
+ const startOfYears = (year) => year - (year % YEARS + YEARS) % YEARS;
25
+ /** Where a grid's focus goes with a key, in items; `undefined` for any other key. */
26
+ function gridStep(key, columns, isRtl) {
27
+ switch (key) {
28
+ case "ArrowLeft": return isRtl ? 1 : -1;
29
+ case "ArrowRight": return isRtl ? -1 : 1;
30
+ case "ArrowUp": return -columns;
31
+ case "ArrowDown": return columns;
32
+ default: return;
33
+ }
34
+ }
35
+ const isRtl = (element) => getComputedStyle(element).direction === "rtl";
36
+ /** A month of days, a year of months, a page of years, and the time: the part that's drawn. */
37
+ function Calendar({ type, day, time, min = "", max = "", step, locale, firstDay, disabledDate, labels, canClear, autoFocus, onChoose, onDone }) {
38
+ const now = (0, react.useMemo)(() => require_dates.today(), []);
39
+ const hasDays = type !== "time";
40
+ const hasTime = type === "time" || type === "datetime-local";
41
+ const [view, setView] = (0, react.useState)(type === "month" ? "months" : "days");
42
+ const [cursor, setCursor] = (0, react.useState)(day || (require_dates.isOutside(now.day, min.slice(0, 10), max.slice(0, 10)) && require_dates.parseDay(min.slice(0, 10)) ? min.slice(0, 10) : now.day));
43
+ const [direction, setDirection] = (0, react.useState)(0);
44
+ const gridRef = (0, react.useRef)(null);
45
+ const moveFocus = (0, react.useRef)(autoFocus);
46
+ (0, react.useEffect)(() => {
47
+ if (day) setCursor(day);
48
+ }, [day]);
49
+ (0, react.useEffect)(() => {
50
+ if (!moveFocus.current) return;
51
+ moveFocus.current = false;
52
+ gridRef.current?.querySelector("[tabindex=\"0\"]")?.focus({ preventScroll: true });
53
+ });
54
+ const goTo = (next, focus = true) => {
55
+ setDirection(Math.sign(next.slice(0, 7).localeCompare(cursor.slice(0, 7))));
56
+ setCursor(next);
57
+ moveFocus.current = focus;
58
+ };
59
+ const choose = (chosen) => {
60
+ setCursor(chosen);
61
+ onChoose(chosen, time || (type === "datetime-local" ? roundTime(now.time, step) : ""), !hasTime);
62
+ };
63
+ const isDisabled = (candidate) => require_dates.isDayOutside(candidate, type, min, max) || disabledDate?.(candidate) === true;
64
+ const year = Number(cursor.slice(0, 4));
65
+ const month = require_dates.monthOf(cursor);
66
+ const first = type === "week" ? 1 : firstDay ?? require_dates.localFirstDay(locale);
67
+ const name = (candidate, options) => require_dates.formatValue(candidate, "date", locale, options);
68
+ const pageBy = (count) => goTo(require_dates.addMonths(cursor, count * (view === "days" ? 1 : view === "months" ? 12 : 144)), false);
69
+ const firstYear = startOfYears(year);
70
+ const heading = view === "days" ? name(`${month}-01`, {
71
+ month: "long",
72
+ year: "numeric"
73
+ }) : view === "months" ? String(year) : `${firstYear} – ${firstYear + YEARS - 1}`;
74
+ const handleKeys = (event) => {
75
+ const rtl = isRtl(event.currentTarget);
76
+ const columns = view === "days" ? 7 : 3;
77
+ const stepBy = gridStep(event.key, columns, rtl);
78
+ const pages = view === "days" ? event.shiftKey ? 12 : 1 : view === "months" ? 12 : 144;
79
+ let next;
80
+ if (stepBy !== void 0) next = view === "days" ? require_dates.addDays(cursor, stepBy) : require_dates.addMonths(cursor, stepBy * (view === "months" ? 1 : 12));
81
+ else if (event.key === "PageUp") next = require_dates.addMonths(cursor, -pages);
82
+ else if (event.key === "PageDown") next = require_dates.addMonths(cursor, pages);
83
+ else if (view === "days" && (event.key === "Home" || event.key === "End")) {
84
+ const weekday = ((require_dates.parseDay(cursor)?.getUTCDay() ?? 0) - first + 7) % 7;
85
+ next = require_dates.addDays(cursor, event.key === "Home" ? -weekday : 6 - weekday);
86
+ }
87
+ if (next === void 0) return;
88
+ event.preventDefault();
89
+ goTo(next);
90
+ };
91
+ const cell = (key, content, { isChosen, isNow, isCursor, disabled, isOther, label, onClick }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
92
+ role: "gridcell",
93
+ "aria-selected": isChosen,
94
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
95
+ type: "button",
96
+ "data-mp": "calendar-cell",
97
+ "data-chosen": isChosen ? "" : void 0,
98
+ "data-other": isOther ? "" : void 0,
99
+ "aria-current": isNow ? "date" : void 0,
100
+ "aria-label": label,
101
+ "aria-disabled": disabled || void 0,
102
+ tabIndex: isCursor ? 0 : -1,
103
+ onClick: disabled ? void 0 : onClick,
104
+ children: content
105
+ })
106
+ }, key);
107
+ const renderDays = () => {
108
+ const weeks = require_dates.monthGrid(month, first);
109
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", { children: [type === "week" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
110
+ scope: "col",
111
+ "aria-label": labels.week
112
+ }), weeks[0].map((weekday) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
113
+ scope: "col",
114
+ abbr: name(weekday, { weekday: "long" }),
115
+ children: name(weekday, { weekday: "narrow" })
116
+ }, weekday))] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: weeks.map((week) => {
117
+ const isChosenWeek = type === "week" && day !== "" && require_dates.weekOf(week[0]) === require_dates.weekOf(day);
118
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", {
119
+ "data-chosen": isChosenWeek ? "" : void 0,
120
+ children: [type === "week" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
121
+ scope: "row",
122
+ "data-mp": "calendar-week",
123
+ children: Number(require_dates.weekOf(week[0]).slice(6))
124
+ }), week.map((candidate) => cell(candidate, Number(candidate.slice(8)), {
125
+ isChosen: type === "week" ? isChosenWeek : candidate === day,
126
+ isNow: candidate === now.day,
127
+ isCursor: candidate === cursor,
128
+ disabled: isDisabled(candidate),
129
+ isOther: require_dates.monthOf(candidate) !== month,
130
+ label: name(candidate, { dateStyle: "full" }),
131
+ onClick: () => choose(candidate)
132
+ }))]
133
+ }, week[0]);
134
+ }) })] });
135
+ };
136
+ const renderTiles = (tiles) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: range(tiles.length / 3).map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: tiles.slice(row * 3, row * 3 + 3).map(({ key, content, target, isChosen, isNow, disabled }) => cell(key, content, {
137
+ isChosen,
138
+ isNow,
139
+ isCursor: key === (view === "months" ? month : String(year)),
140
+ disabled,
141
+ onClick: () => {
142
+ if (view === "months" && type === "month") choose(target);
143
+ else {
144
+ setView(view === "years" ? "months" : "days");
145
+ goTo(target);
146
+ }
147
+ }
148
+ })) }, row)) });
149
+ const renderMonths = () => renderTiles(range(12).map((index) => {
150
+ const key = `${cursor.slice(0, 4)}-${String(index + 1).padStart(2, "0")}`;
151
+ return {
152
+ key,
153
+ content: name(`${key}-01`, { month: "short" }),
154
+ target: require_dates.addMonths(cursor, index + 1 - Number(cursor.slice(5, 7))),
155
+ isChosen: type === "month" && day !== "" && require_dates.monthOf(day) === key,
156
+ isNow: require_dates.monthOf(now.day) === key,
157
+ disabled: require_dates.isOutside(key, min.slice(0, 7), max.slice(0, 7)) && type !== "week"
158
+ };
159
+ }));
160
+ const renderYears = () => renderTiles(range(YEARS).map((index) => {
161
+ const key = String(firstYear + index);
162
+ return {
163
+ key,
164
+ content: key,
165
+ target: require_dates.addMonths(cursor, (firstYear + index - year) * 12),
166
+ isChosen: day !== "" && day.slice(0, 4) === key.padStart(4, "0"),
167
+ isNow: now.day.slice(0, 4) === key,
168
+ disabled: require_dates.isOutside(key.padStart(4, "0"), min.slice(0, 4), max.slice(0, 4))
169
+ };
170
+ }));
171
+ const isTodayDisabled = hasDays ? isDisabled(now.day) : require_dates.isOutside(now.time, min, max);
172
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
173
+ "data-mp": "calendar-body",
174
+ "data-type": type,
175
+ children: [
176
+ hasDays && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
177
+ "data-mp": "calendar-days",
178
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
179
+ "data-mp": "calendar-head",
180
+ children: [
181
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
182
+ type: "button",
183
+ "data-mp": "calendar-button",
184
+ "aria-label": labels.previous,
185
+ onClick: () => pageBy(-1),
186
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.ChevronGlyph, {})
187
+ }),
188
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
189
+ type: "button",
190
+ "data-mp": "calendar-heading",
191
+ "aria-live": "polite",
192
+ disabled: view === "years",
193
+ title: view === "years" ? void 0 : labels.zoomOut,
194
+ onClick: () => {
195
+ setDirection(0);
196
+ setView(view === "days" ? "months" : "years");
197
+ moveFocus.current = true;
198
+ },
199
+ children: heading
200
+ }),
201
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
202
+ type: "button",
203
+ "data-mp": "calendar-button",
204
+ "data-next": "",
205
+ "aria-label": labels.next,
206
+ onClick: () => pageBy(1),
207
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_glyphs.ChevronGlyph, {})
208
+ })
209
+ ]
210
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
211
+ ref: gridRef,
212
+ role: "grid",
213
+ "aria-label": heading,
214
+ "data-mp": "calendar-grid",
215
+ "data-view": view,
216
+ "data-direction": direction || void 0,
217
+ onKeyDown: handleKeys,
218
+ children: view === "days" ? renderDays() : view === "months" ? renderMonths() : renderYears()
219
+ }, `${view} ${view === "days" ? month : view === "months" ? year : firstYear}`)]
220
+ }),
221
+ hasTime && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TimeColumns, {
222
+ time,
223
+ step,
224
+ locale,
225
+ labels,
226
+ autoFocus: autoFocus && !hasDays,
227
+ isDisabled: (candidate) => type === "time" ? require_dates.isOutside(candidate, min, max) : day !== "" && require_dates.isOutside(`${day}T${candidate}`, min, max),
228
+ onChoose: (chosen) => onChoose(day || (hasDays ? cursor : ""), chosen, false)
229
+ }),
230
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
231
+ "data-mp": "calendar-foot",
232
+ children: [
233
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
234
+ type: "button",
235
+ "data-mp": "calendar-button",
236
+ disabled: isTodayDisabled,
237
+ onClick: () => {
238
+ if (hasDays) goTo(now.day, false);
239
+ onChoose(hasDays ? now.day : "", hasTime ? now.time : "", !hasTime);
240
+ },
241
+ children: hasDays ? labels.today : labels.now
242
+ }),
243
+ canClear && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
244
+ type: "button",
245
+ "data-mp": "calendar-button",
246
+ onClick: () => onChoose("", "", true),
247
+ children: labels.clear
248
+ }),
249
+ hasTime && onDone && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
250
+ type: "button",
251
+ "data-mp": "calendar-button",
252
+ "data-main": "",
253
+ onClick: onDone,
254
+ children: labels.done
255
+ })
256
+ ]
257
+ })
258
+ ]
259
+ });
260
+ }
261
+ /** Minutes between two choices: every five, unless the step asks for another. */
262
+ const minuteStep = (step) => step && step >= 60 ? Math.max(1, Math.round(step / 60)) : 5;
263
+ /** A time one can choose, at or before this one. */
264
+ function roundTime(time, step) {
265
+ const [hours, minutes] = time.split(":").map(Number);
266
+ const by = minuteStep(step);
267
+ return `${String(hours).padStart(2, "0")}:${String(minutes - minutes % by).padStart(2, "0")}`;
268
+ }
269
+ function TimeColumns({ time, step, locale, labels, autoFocus, isDisabled, onChoose }) {
270
+ const isTwelve = (0, react.useMemo)(() => require_dates.usesTwelveHours(locale), [locale]);
271
+ const [hours, minutes] = time ? time.split(":").map(Number) : [void 0, void 0];
272
+ const by = minuteStep(step);
273
+ const at = (hour, minute) => `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
274
+ const isAfternoon = (hours ?? 0) >= 12;
275
+ const twoDigits = (value) => String(value).padStart(2, "0");
276
+ const periods = (0, react.useMemo)(() => [9, 15].map((hour) => new Intl.DateTimeFormat(locale, {
277
+ hour: "numeric",
278
+ hour12: true,
279
+ timeZone: "UTC"
280
+ }).formatToParts(new Date(Date.UTC(2e3, 0, 1, hour))).find((part) => part.type === "dayPeriod")?.value ?? (hour < 12 ? "AM" : "PM")), [locale]);
281
+ const minuteChoices = [.../* @__PURE__ */ new Set([...range(Math.ceil(60 / by)).map((index) => index * by), ...minutes === void 0 ? [] : [minutes]])].sort((a, b) => a - b);
282
+ const hourChoices = isTwelve ? range(12).map((index) => index + (isAfternoon ? 12 : 0)) : range(24);
283
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
284
+ "data-mp": "calendar-time",
285
+ children: [
286
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Column, {
287
+ label: labels.hours,
288
+ autoFocus,
289
+ chosen: hours,
290
+ choices: hourChoices.map((hour) => ({
291
+ value: hour,
292
+ text: isTwelve ? String(hour % 12 || 12) : twoDigits(hour),
293
+ disabled: minuteChoices.every((minute) => isDisabled(at(hour, minute)))
294
+ })),
295
+ onChoose: (hour) => onChoose(at(hour, minutes ?? 0))
296
+ }),
297
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Column, {
298
+ label: labels.minutes,
299
+ chosen: minutes,
300
+ choices: minuteChoices.map((minute) => ({
301
+ value: minute,
302
+ text: twoDigits(minute),
303
+ disabled: hours !== void 0 && isDisabled(at(hours, minute))
304
+ })),
305
+ onChoose: (minute) => onChoose(at(hours ?? 0, minute))
306
+ }),
307
+ isTwelve && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Column, {
308
+ label: labels.period,
309
+ chosen: hours === void 0 ? void 0 : isAfternoon ? 1 : 0,
310
+ choices: periods.map((text, value) => ({
311
+ value,
312
+ text,
313
+ disabled: hours !== void 0 && isDisabled(at(hours % 12 + value * 12, minutes ?? 0))
314
+ })),
315
+ onChoose: (period) => onChoose(at((hours ?? 0) % 12 + period * 12, minutes ?? 0))
316
+ })
317
+ ]
318
+ });
319
+ }
320
+ /** A list to scroll, or to go through with the arrows. */
321
+ function Column({ label, chosen, choices, autoFocus, onChoose }) {
322
+ const id = (0, react.useId)();
323
+ const listRef = (0, react.useRef)(null);
324
+ (0, react.useEffect)(() => {
325
+ const list = listRef.current;
326
+ const option = list?.querySelector("[aria-selected=\"true\"]");
327
+ if (list && option) list.scrollTop = option.offsetTop - (list.clientHeight - option.offsetHeight) / 2;
328
+ }, [chosen, choices.length]);
329
+ (0, react.useEffect)(() => {
330
+ if (autoFocus) listRef.current?.focus({ preventScroll: true });
331
+ }, [autoFocus]);
332
+ const handleKeys = (event) => {
333
+ const enabled = choices.filter((choice) => !choice.disabled);
334
+ const index = enabled.findIndex((choice) => choice.value === chosen);
335
+ const target = {
336
+ ArrowDown: enabled[index + 1],
337
+ ArrowUp: enabled[index < 0 ? enabled.length - 1 : index - 1],
338
+ Home: enabled[0],
339
+ End: enabled[enabled.length - 1]
340
+ }[event.key];
341
+ if (![
342
+ "ArrowDown",
343
+ "ArrowUp",
344
+ "Home",
345
+ "End"
346
+ ].includes(event.key)) return;
347
+ event.preventDefault();
348
+ if (target) onChoose(target.value);
349
+ };
350
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
351
+ ref: listRef,
352
+ role: "listbox",
353
+ "aria-label": label,
354
+ "aria-activedescendant": chosen === void 0 ? void 0 : id + chosen,
355
+ tabIndex: 0,
356
+ "data-mp": "calendar-column",
357
+ onKeyDown: handleKeys,
358
+ children: choices.map(({ value, text, disabled }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
359
+ id: id + value,
360
+ role: "option",
361
+ "aria-selected": value === chosen,
362
+ "aria-disabled": disabled || void 0,
363
+ "data-mp": "calendar-option",
364
+ onClick: disabled ? void 0 : () => onChoose(value),
365
+ children: text
366
+ }, value))
367
+ });
368
+ }
369
+
370
+ exports.CALENDAR_LABELS = CALENDAR_LABELS;
371
+ exports.Calendar = Calendar;