cupertino-datetime-picker 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.
package/dist/index.js ADDED
@@ -0,0 +1,832 @@
1
+ import { Popover as e } from "@base-ui/react/popover";
2
+ import * as t from "react";
3
+ import { clsx as n } from "clsx";
4
+ import { twMerge as r } from "tailwind-merge";
5
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ //#region src/calendar.ts
7
+ function o(e) {
8
+ return new Date(e.getFullYear(), e.getMonth(), e.getDate());
9
+ }
10
+ function s(e, t) {
11
+ return !!e && !!t && e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate();
12
+ }
13
+ function c(e, t) {
14
+ return new Date(e, t + 1, 0).getDate();
15
+ }
16
+ function l(e) {
17
+ return {
18
+ year: e.getFullYear(),
19
+ month: e.getMonth()
20
+ };
21
+ }
22
+ function u(e, t) {
23
+ return (t.year - e.year) * 12 + (t.month - e.month);
24
+ }
25
+ function d(e, t) {
26
+ let n = e.month + t;
27
+ return {
28
+ year: e.year + Math.floor(n / 12),
29
+ month: (n % 12 + 12) % 12
30
+ };
31
+ }
32
+ function f(e, t, n, r) {
33
+ let i = new Date(e);
34
+ return i.setFullYear(t, n, Math.min(r, c(t, n))), i;
35
+ }
36
+ function p(e, t, n) {
37
+ let r = new Date(e);
38
+ return r.setHours(t, n, 0, 0), r;
39
+ }
40
+ function m(e, t) {
41
+ let n = new Date(e);
42
+ return n.setDate(n.getDate() + t), n;
43
+ }
44
+ function h(e, t) {
45
+ let n = d(l(e), t);
46
+ return f(e, n.year, n.month, e.getDate());
47
+ }
48
+ function g(e, t, n) {
49
+ let r = o(e).getTime();
50
+ return !!(t && r < o(t).getTime() || n && r > o(n).getTime());
51
+ }
52
+ function _(e, t, n) {
53
+ let r = (new Date(e, t, 1).getDay() - n + 7) % 7, i = Math.ceil((r + c(e, t)) / 7);
54
+ return Array.from({ length: i }, (n, i) => Array.from({ length: 7 }, (n, a) => {
55
+ let o = new Date(e, t, i * 7 + a - r + 1);
56
+ return {
57
+ date: o,
58
+ inMonth: o.getMonth() === t
59
+ };
60
+ }));
61
+ }
62
+ function v(e) {
63
+ let t = y(e);
64
+ return t === void 0 ? +!/^(en-(US|CA|AU)|ja|ko|zh-(TW|HK)|he|pt-BR|es-(MX|US))\b/i.test(e) : t % 7;
65
+ }
66
+ function y(e) {
67
+ let t;
68
+ try {
69
+ t = new Intl.Locale(e);
70
+ } catch {
71
+ return;
72
+ }
73
+ let n = "getWeekInfo" in t && typeof t.getWeekInfo == "function" ? t.getWeekInfo() : "weekInfo" in t ? t.weekInfo : void 0;
74
+ return typeof n == "object" && n && "firstDay" in n && typeof n.firstDay == "number" ? n.firstDay : void 0;
75
+ }
76
+ //#endregion
77
+ //#region src/time.ts
78
+ function b(e) {
79
+ let t = new Intl.DateTimeFormat(e, { hour: "numeric" }).resolvedOptions().hourCycle;
80
+ return t === "h11" || t === "h12" ? "h12" : "h23";
81
+ }
82
+ function x(e) {
83
+ return {
84
+ hour: e % 12 == 0 ? 12 : e % 12,
85
+ pm: e >= 12
86
+ };
87
+ }
88
+ function S(e, t) {
89
+ return e % 12 + (t ? 12 : 0);
90
+ }
91
+ function C(e) {
92
+ let t = new Intl.DateTimeFormat(e, {
93
+ hour: "numeric",
94
+ hourCycle: "h12"
95
+ }), n = (e) => t.formatToParts(new Date(2e3, 0, 1, e)).find((e) => e.type === "dayPeriod")?.value ?? (e < 12 ? "AM" : "PM");
96
+ return {
97
+ am: n(1),
98
+ pm: n(13)
99
+ };
100
+ }
101
+ function w(e, t = "long") {
102
+ let n = new Intl.DateTimeFormat(e, { month: t });
103
+ return Array.from({ length: 12 }, (e, t) => n.format(new Date(2e3, t, 1)));
104
+ }
105
+ function T(e, t, n = "narrow") {
106
+ let r = new Intl.DateTimeFormat(e, { weekday: n });
107
+ return Array.from({ length: 7 }, (e, n) => r.format(new Date(2023, 0, 1 + (t + n) % 7)));
108
+ }
109
+ function E(e, t) {
110
+ return new Intl.DateTimeFormat(t, { dateStyle: "medium" }).format(e);
111
+ }
112
+ function D(e, t, n) {
113
+ return new Intl.DateTimeFormat(t, {
114
+ hour: n === "h12" ? "numeric" : "2-digit",
115
+ minute: "2-digit",
116
+ hourCycle: n
117
+ }).format(e);
118
+ }
119
+ function O(e, t) {
120
+ return new Intl.DateTimeFormat(t, {
121
+ month: "long",
122
+ year: "numeric"
123
+ }).format(e);
124
+ }
125
+ function k(e, t) {
126
+ return new Intl.DateTimeFormat(t, {
127
+ weekday: "long",
128
+ year: "numeric",
129
+ month: "long",
130
+ day: "numeric"
131
+ }).format(e);
132
+ }
133
+ //#endregion
134
+ //#region src/utils.ts
135
+ function A(...e) {
136
+ return r(n(e));
137
+ }
138
+ function j(e, t, n) {
139
+ return Math.min(n, Math.max(t, e));
140
+ }
141
+ function M(e, t) {
142
+ return (e % t + t) % t;
143
+ }
144
+ function N(e) {
145
+ return e < 10 ? `0${e}` : String(e);
146
+ }
147
+ //#endregion
148
+ //#region src/hooks.ts
149
+ function P(e, n, r) {
150
+ let [i, a] = t.useState(n);
151
+ return [e === void 0 ? i : e, (t) => {
152
+ e === void 0 && a(t), r?.(t);
153
+ }];
154
+ }
155
+ function F() {
156
+ return t.useSyncExternalStore((e) => {
157
+ let t = window.matchMedia("(prefers-reduced-motion: reduce)");
158
+ return t.addEventListener("change", e), () => t.removeEventListener("change", e);
159
+ }, () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, () => !1);
160
+ }
161
+ //#endregion
162
+ //#region src/wheel-math.ts
163
+ function I(e, t) {
164
+ return Math.round(e / t);
165
+ }
166
+ function L(e, t, n, r) {
167
+ return j(I(e + t * 380, n), 0, r);
168
+ }
169
+ function R(e, t, n, r) {
170
+ let i = e;
171
+ for (let a = 0; a < r; a++) {
172
+ let r = a * n + e;
173
+ Math.abs(r - t) < Math.abs(i - t) && (i = r);
174
+ }
175
+ return i;
176
+ }
177
+ function z(e) {
178
+ return 1 - (1 - e) ** 3;
179
+ }
180
+ //#endregion
181
+ //#region src/wheel.tsx
182
+ var B = 7, V = 700;
183
+ function H({ options: e, value: n, onChange: r, loop: a = !1, itemHeight: o = 32, visibleRows: s = 5, "aria-label": c, className: l }) {
184
+ let u = t.useRef(null), d = F(), f = e.length, p = a ? B : 1, m = a ? Math.floor(B / 2) * f : 0, h = f * p - 1, g = Math.max(0, e.findIndex((e) => e.value === n)), _ = (s - 1) / 2 * o, v = t.useRef(m + g), y = t.useRef(null), b = t.useRef(0), x = t.useRef(0), S = t.useRef({
185
+ buffer: "",
186
+ timer: 0
187
+ }), C = t.useRef(!1), w = t.useRef(r), T = t.useRef(n);
188
+ t.useLayoutEffect(() => {
189
+ w.current = r, T.current = n;
190
+ });
191
+ let E = (e) => {
192
+ let t = D(e);
193
+ t && t.value !== T.current && w.current(t.value);
194
+ }, D = (t) => e.at(M(t, f)), O = () => {
195
+ let e = u.current;
196
+ if (!e) return;
197
+ let t = e.scrollTop / o, n = e.firstElementChild?.children;
198
+ if (!n) return;
199
+ let r = Math.max(0, Math.floor(t) - s), i = Math.min(n.length - 1, Math.ceil(t) + s), a = I(e.scrollTop, o);
200
+ for (let e = r; e <= i; e++) {
201
+ let r = n[e], i = e - t, o = j(i * 22, -85, 85);
202
+ r.style.transform = `perspective(600px) rotateX(${-o}deg)`, r.style.opacity = String(j(1 - Math.abs(i) * .28, .12, 1)), e === a ? r.dataset.active = "" : delete r.dataset.active;
203
+ }
204
+ }, k = (e, t) => {
205
+ let n = u.current;
206
+ n && n.scrollTo({
207
+ top: j(e, 0, h) * o,
208
+ behavior: t && !d ? "smooth" : "auto"
209
+ });
210
+ }, N = () => {
211
+ let e = u.current;
212
+ if (!e || y.current || b.current) return;
213
+ let t = I(e.scrollTop, o);
214
+ if (a) {
215
+ let n = m + M(t, f);
216
+ t !== n && (t = n, e.scrollTop = t * o);
217
+ }
218
+ v.current = t, E(t);
219
+ }, P = (e, t = !0) => {
220
+ let n = j(e, 0, h);
221
+ v.current = n, E(n), k(n, t);
222
+ }, H = t.useRef(!1);
223
+ t.useLayoutEffect(() => {
224
+ H.current || (H.current = !0, u.current?.scrollTo({ top: v.current * o }), O());
225
+ }), t.useEffect(() => {
226
+ if (y.current || b.current || e.at(M(v.current, f))?.value === n) return;
227
+ let t = a ? R(g, v.current, f, p) : g;
228
+ v.current = t, u.current?.scrollTo({
229
+ top: t * o,
230
+ behavior: d ? "auto" : "smooth"
231
+ });
232
+ }, [
233
+ n,
234
+ e,
235
+ f,
236
+ a,
237
+ g,
238
+ p,
239
+ o,
240
+ d,
241
+ v,
242
+ u
243
+ ]);
244
+ let U = () => {
245
+ O(), window.clearTimeout(x.current), x.current = window.setTimeout(N, 120);
246
+ }, W = () => {
247
+ window.clearTimeout(x.current), N();
248
+ }, G = (e) => {
249
+ if (e.pointerType !== "mouse" || e.button !== 0) return;
250
+ let t = e.currentTarget;
251
+ cancelAnimationFrame(b.current), b.current = 0, t.setPointerCapture(e.pointerId), t.style.scrollSnapType = "none", y.current = {
252
+ startY: e.clientY,
253
+ startTop: t.scrollTop,
254
+ lastTop: t.scrollTop,
255
+ lastT: e.timeStamp,
256
+ v: 0,
257
+ moved: !1
258
+ };
259
+ }, ee = (e) => {
260
+ let t = y.current;
261
+ if (!t) return;
262
+ let n = e.currentTarget, r = j(t.startTop - (e.clientY - t.startY), 0, h * o), i = Math.max(1, e.timeStamp - t.lastT);
263
+ t.v = t.v * .5 + (r - t.lastTop) / i * .5, t.lastTop = r, t.lastT = e.timeStamp, Math.abs(e.clientY - t.startY) > 3 && (t.moved = !0), n.scrollTop = r;
264
+ }, K = (e) => {
265
+ let t = y.current;
266
+ if (!t) return;
267
+ y.current = null;
268
+ let n = e.currentTarget;
269
+ if (n.releasePointerCapture(e.pointerId), !t.moved) {
270
+ n.style.scrollSnapType = "";
271
+ let t = e.clientY - n.getBoundingClientRect().top;
272
+ P(Math.floor((n.scrollTop + t - _) / o)), C.current = !0;
273
+ return;
274
+ }
275
+ C.current = !0;
276
+ let r = L(n.scrollTop, e.timeStamp - t.lastT > 80 ? 0 : t.v, o, h), i = n.scrollTop, a = r * o, s = d ? 0 : j(Math.abs(a - i) * 1.2, 180, 720), c = e.timeStamp, l = (e) => {
277
+ let t = s === 0 ? 1 : Math.min(1, (e - c) / s);
278
+ n.scrollTop = i + (a - i) * z(t), t < 1 ? b.current = requestAnimationFrame(l) : (b.current = 0, n.style.scrollSnapType = "", N());
279
+ };
280
+ b.current = requestAnimationFrame(l);
281
+ }, q = (t) => {
282
+ let n = v.current, r = a ? m : 0, i = a ? m + f - 1 : f - 1;
283
+ switch (t.key) {
284
+ case "ArrowUp":
285
+ P(n - 1);
286
+ break;
287
+ case "ArrowDown":
288
+ P(n + 1);
289
+ break;
290
+ case "PageUp":
291
+ P(n - 5);
292
+ break;
293
+ case "PageDown":
294
+ P(n + 5);
295
+ break;
296
+ case "Home":
297
+ P(r);
298
+ break;
299
+ case "End":
300
+ P(i);
301
+ break;
302
+ default: {
303
+ if (t.key.length !== 1 || t.metaKey || t.ctrlKey || t.altKey) return;
304
+ let r = S.current;
305
+ window.clearTimeout(r.timer), r.buffer += t.key.toLowerCase(), r.timer = window.setTimeout(() => r.buffer = "", V);
306
+ let i = e.findIndex((e) => String(e.value) === r.buffer || e.label.toLowerCase().startsWith(r.buffer));
307
+ if (i === -1) {
308
+ r.buffer = t.key.toLowerCase();
309
+ let i = e.findIndex((e) => String(e.value) === r.buffer || e.label.toLowerCase().startsWith(r.buffer));
310
+ if (i === -1) return;
311
+ P(a ? R(i, n, f, p) : i);
312
+ } else P(a ? R(i, n, f, p) : i);
313
+ break;
314
+ }
315
+ }
316
+ t.preventDefault();
317
+ }, J = e.at(g);
318
+ return /* @__PURE__ */ i("div", {
319
+ ref: u,
320
+ role: "spinbutton",
321
+ tabIndex: 0,
322
+ "aria-label": c,
323
+ "aria-valuenow": J?.value,
324
+ "aria-valuetext": J?.label,
325
+ "aria-valuemin": e.at(0)?.value,
326
+ "aria-valuemax": e.at(-1)?.value,
327
+ "data-slot": "wheel",
328
+ onScroll: U,
329
+ onScrollEnd: W,
330
+ onPointerDown: G,
331
+ onPointerMove: ee,
332
+ onPointerUp: K,
333
+ onPointerCancel: K,
334
+ onKeyDown: q,
335
+ className: A("cdp-wheel relative snap-y snap-mandatory overflow-y-scroll overscroll-contain rounded-lg outline-none select-none focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)]", l),
336
+ style: {
337
+ height: s * o,
338
+ scrollbarWidth: "none",
339
+ touchAction: "pan-y"
340
+ },
341
+ children: /* @__PURE__ */ i("div", {
342
+ "aria-hidden": !0,
343
+ style: { paddingBlock: _ },
344
+ children: Array.from({ length: f * p }, (t, n) => {
345
+ let r = e.at(n % f);
346
+ return /* @__PURE__ */ i("div", {
347
+ role: "presentation",
348
+ className: "flex snap-center items-center justify-center text-[22px] leading-none text-[var(--cdp-secondary)] tabular-nums transition-colors data-active:text-[var(--cdp-label)]",
349
+ style: { height: o },
350
+ onClick: () => {
351
+ if (C.current) {
352
+ C.current = !1;
353
+ return;
354
+ }
355
+ P(n);
356
+ },
357
+ children: r?.label
358
+ }, n);
359
+ })
360
+ })
361
+ });
362
+ }
363
+ function U({ itemHeight: e = 32, className: t }) {
364
+ return /* @__PURE__ */ i("div", {
365
+ "aria-hidden": !0,
366
+ className: A("pointer-events-none absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-lg bg-[var(--cdp-fill)]", t),
367
+ style: { height: e }
368
+ });
369
+ }
370
+ //#endregion
371
+ //#region src/calendar-panel.tsx
372
+ var W = {
373
+ previousMonth: "Previous month",
374
+ nextMonth: "Next month",
375
+ month: "Month",
376
+ year: "Year"
377
+ }, G = 100, ee = 40;
378
+ function K({ className: e }) {
379
+ return /* @__PURE__ */ i("svg", {
380
+ viewBox: "0 0 20 20",
381
+ className: A("size-5", e),
382
+ "aria-hidden": !0,
383
+ fill: "none",
384
+ children: /* @__PURE__ */ i("path", {
385
+ d: "M7.5 4.5 13 10l-5.5 5.5",
386
+ stroke: "currentColor",
387
+ strokeWidth: "2.25",
388
+ strokeLinecap: "round",
389
+ strokeLinejoin: "round"
390
+ })
391
+ });
392
+ }
393
+ function q({ value: e, onChange: n, locale: r = navigator.language, min: c, max: p, labels: y, today: b, className: x }) {
394
+ let S = {
395
+ ...W,
396
+ ...y
397
+ }, C = b ?? o(/* @__PURE__ */ new Date()), E = v(r), [D, j] = t.useState(() => l(e ?? C)), [M, N] = t.useState(0), [P, F] = t.useState(!1), [I, L] = t.useState(e ?? C), R = t.useRef(!1), z = t.useRef(null), B = t.useRef(null), [V, q] = t.useState(e);
398
+ e !== V && (q(e), e && u(D, l(e)) !== 0 && (N(0), j(l(e)), L(e)));
399
+ let J = (e, t) => {
400
+ N(t), j(e);
401
+ }, Y = (e) => J(d(D, e), e > 0 ? 1 : -1), X = (e) => {
402
+ let t = d(D, e);
403
+ return !(e < 0 && c && u(l(c), t) < 0 || e > 0 && p && u(t, l(p)) < 0);
404
+ }, Z = (t) => {
405
+ L(t), n(f(e ?? C, t.getFullYear(), t.getMonth(), t.getDate()));
406
+ }, Q = (e) => {
407
+ if (g(e, c, p)) return;
408
+ R.current = !0, L(e);
409
+ let t = u(D, l(e));
410
+ t !== 0 && J(l(e), t > 0 ? 1 : -1);
411
+ };
412
+ t.useEffect(() => {
413
+ R.current && (R.current = !1, z.current?.querySelector(`[data-date="${o(I).getTime()}"]`)?.focus());
414
+ }, [I]);
415
+ let $ = (e) => {
416
+ let t = I, n = (/* @__PURE__ */ new Map([
417
+ ["ArrowLeft", () => m(t, -1)],
418
+ ["ArrowRight", () => m(t, 1)],
419
+ ["ArrowUp", () => m(t, -7)],
420
+ ["ArrowDown", () => m(t, 7)],
421
+ ["Home", () => m(t, -((t.getDay() - E + 7) % 7))],
422
+ ["End", () => m(t, 6 - (t.getDay() - E + 7) % 7)],
423
+ ["PageUp", () => h(t, e.shiftKey ? -12 : -1)],
424
+ ["PageDown", () => h(t, e.shiftKey ? 12 : 1)]
425
+ ])).get(e.key);
426
+ n && (e.preventDefault(), Q(n()));
427
+ }, te = (e) => {
428
+ e.pointerType !== "mouse" && (B.current = {
429
+ x: e.clientX,
430
+ y: e.clientY
431
+ });
432
+ }, ne = (e) => {
433
+ let t = B.current;
434
+ if (B.current = null, !t) return;
435
+ let n = e.clientX - t.x;
436
+ if (Math.abs(n) < ee || Math.abs(n) < Math.abs(e.clientY - t.y)) return;
437
+ let r = n < 0 ? 1 : -1;
438
+ X(r) && Y(r);
439
+ }, re = _(D.year, D.month, E), ie = new Date(D.year, D.month, 1), ae = w(r).map((e, t) => ({
440
+ value: t,
441
+ label: e
442
+ })), oe = Array.from({ length: 201 }, (e, t) => {
443
+ let n = C.getFullYear() - G + t;
444
+ return {
445
+ value: n,
446
+ label: String(n)
447
+ };
448
+ });
449
+ return /* @__PURE__ */ a("div", {
450
+ className: A("cdp flex w-[312px] flex-col select-none", x),
451
+ "data-slot": "calendar",
452
+ children: [/* @__PURE__ */ a("div", {
453
+ className: "flex h-11 items-center justify-between pr-1 pl-2.5",
454
+ children: [/* @__PURE__ */ a("button", {
455
+ type: "button",
456
+ "aria-expanded": P,
457
+ onClick: () => F((e) => !e),
458
+ className: "flex h-9 items-center gap-1 rounded-lg px-1.5 text-[17px] font-semibold tracking-[-0.01em] text-[var(--cdp-label)] transition-opacity outline-none active:opacity-50 focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)]",
459
+ children: [/* @__PURE__ */ i("span", { children: O(ie, r) }), /* @__PURE__ */ i(K, { className: A("size-4 text-[var(--cdp-tint)] transition-transform duration-200", P && "rotate-90") })]
460
+ }), /* @__PURE__ */ a("div", {
461
+ className: A("flex items-center transition-opacity duration-150", P && "pointer-events-none opacity-0"),
462
+ children: [/* @__PURE__ */ i("button", {
463
+ type: "button",
464
+ "aria-label": S.previousMonth,
465
+ disabled: !X(-1),
466
+ onClick: () => Y(-1),
467
+ className: "flex size-11 items-center justify-center rounded-full text-[var(--cdp-tint)] transition-opacity outline-none active:opacity-40 disabled:opacity-30 focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)]",
468
+ children: /* @__PURE__ */ i(K, { className: "rotate-180" })
469
+ }), /* @__PURE__ */ i("button", {
470
+ type: "button",
471
+ "aria-label": S.nextMonth,
472
+ disabled: !X(1),
473
+ onClick: () => Y(1),
474
+ className: "flex size-11 items-center justify-center rounded-full text-[var(--cdp-tint)] transition-opacity outline-none active:opacity-40 disabled:opacity-30 focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)]",
475
+ children: /* @__PURE__ */ i(K, {})
476
+ })]
477
+ })]
478
+ }), /* @__PURE__ */ a("div", {
479
+ className: "relative grid px-1.5 pb-1.5",
480
+ children: [/* @__PURE__ */ a("div", {
481
+ className: A("col-start-1 row-start-1 transition-[opacity,transform] duration-200", P && "pointer-events-none scale-95 opacity-0"),
482
+ "aria-hidden": P,
483
+ children: [/* @__PURE__ */ i("div", {
484
+ className: "grid grid-cols-7",
485
+ "aria-hidden": !0,
486
+ children: T(r, E).map((e, t) => /* @__PURE__ */ i("div", {
487
+ className: "flex h-8 items-center justify-center text-[13px] font-semibold text-[var(--cdp-tertiary)]",
488
+ children: e
489
+ }, t))
490
+ }), /* @__PURE__ */ i("div", {
491
+ ref: z,
492
+ role: "grid",
493
+ tabIndex: -1,
494
+ "aria-label": O(ie, r),
495
+ "data-dir": M,
496
+ onKeyDown: $,
497
+ onPointerDown: te,
498
+ onPointerUp: ne,
499
+ className: "grid grid-cols-7 gap-y-0.5 data-[dir=-1]:animate-[cdp-slide-from-left_240ms_cubic-bezier(0.2,0.9,0.3,1)] data-[dir=1]:animate-[cdp-slide-from-right_240ms_cubic-bezier(0.2,0.9,0.3,1)]",
500
+ style: { touchAction: "pan-y" },
501
+ children: re.flat().map(({ date: t, inMonth: n }, a) => {
502
+ if (!n) return /* @__PURE__ */ i("div", {
503
+ role: "gridcell",
504
+ "aria-hidden": !0
505
+ }, a);
506
+ let l = s(t, e), u = s(t, C), d = g(t, c, p);
507
+ return /* @__PURE__ */ i("button", {
508
+ type: "button",
509
+ role: "gridcell",
510
+ "aria-selected": l,
511
+ "aria-label": k(t, r),
512
+ "aria-current": u ? "date" : void 0,
513
+ "data-date": o(t).getTime(),
514
+ "data-today": u || void 0,
515
+ "data-selected": l || void 0,
516
+ tabIndex: s(t, I) ? 0 : -1,
517
+ disabled: d,
518
+ onClick: () => Z(t),
519
+ onFocus: () => L(t),
520
+ className: A("mx-auto flex size-10 items-center justify-center rounded-full text-[20px] leading-none tabular-nums transition-transform duration-150 outline-none active:scale-90 focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--cdp-bg)] disabled:opacity-30", l ? u ? "bg-[var(--cdp-tint)] font-semibold text-[var(--cdp-on-tint)]" : "bg-[var(--cdp-tint-fill)] font-semibold text-[var(--cdp-tint)]" : u ? "text-[var(--cdp-tint)] hover:bg-[var(--cdp-fill)]" : "text-[var(--cdp-label)] hover:bg-[var(--cdp-fill)]"),
521
+ children: t.getDate()
522
+ }, a);
523
+ })
524
+ }, `${D.year}-${D.month}`)]
525
+ }), /* @__PURE__ */ a("div", {
526
+ className: A("cdp-wheel-mask relative col-start-1 row-start-1 flex items-center justify-center gap-2 px-2 transition-[opacity,transform] duration-200", !P && "pointer-events-none scale-95 opacity-0"),
527
+ "aria-hidden": !P,
528
+ "data-slot": "month-year",
529
+ children: [
530
+ /* @__PURE__ */ i(U, { className: "inset-x-2" }),
531
+ /* @__PURE__ */ i(H, {
532
+ "aria-label": S.month,
533
+ options: ae,
534
+ value: D.month,
535
+ loop: !0,
536
+ visibleRows: 7,
537
+ onChange: (e) => J({
538
+ year: D.year,
539
+ month: e
540
+ }, 0),
541
+ className: "w-40"
542
+ }),
543
+ /* @__PURE__ */ i(H, {
544
+ "aria-label": S.year,
545
+ options: oe,
546
+ value: D.year,
547
+ visibleRows: 7,
548
+ onChange: (e) => J({
549
+ year: e,
550
+ month: D.month
551
+ }, 0),
552
+ className: "w-24"
553
+ })
554
+ ]
555
+ })]
556
+ })]
557
+ });
558
+ }
559
+ //#endregion
560
+ //#region src/segmented-control.tsx
561
+ function J({ options: e, value: n, onChange: r, "aria-label": o, className: s }) {
562
+ let c = t.useId(), l = Math.max(0, e.findIndex((e) => e.value === n));
563
+ return /* @__PURE__ */ a("div", {
564
+ role: "radiogroup",
565
+ "aria-label": o,
566
+ "data-slot": "segmented-control",
567
+ className: A("relative inline-grid h-8 auto-cols-fr grid-flow-col rounded-[9px] bg-[var(--cdp-fill)] p-0.5", s),
568
+ children: [/* @__PURE__ */ i("div", {
569
+ "aria-hidden": !0,
570
+ className: "pointer-events-none absolute inset-y-0.5 left-0.5 rounded-[7px] bg-[var(--cdp-thumb)] shadow-[0_3px_8px_rgba(0,0,0,0.12),0_3px_1px_rgba(0,0,0,0.04)] transition-transform duration-200 ease-[cubic-bezier(0.2,0,0,1)]",
571
+ style: {
572
+ width: `calc((100% - 4px) / ${e.length})`,
573
+ transform: `translateX(${l * 100}%)`
574
+ }
575
+ }), e.map((e) => {
576
+ let t = e.value === n;
577
+ return /* @__PURE__ */ a("label", {
578
+ className: A("relative z-10 flex min-w-12 cursor-pointer items-center justify-center rounded-[7px] px-3 text-[13px] font-semibold transition-colors select-none has-focus-visible:ring-2 has-focus-visible:ring-[var(--cdp-tint)]", t ? "text-[var(--cdp-label)]" : "text-[var(--cdp-label)]/80 active:opacity-60"),
579
+ children: [/* @__PURE__ */ i("input", {
580
+ type: "radio",
581
+ name: c,
582
+ checked: t,
583
+ onChange: () => r(e.value),
584
+ className: "absolute inset-0 cursor-pointer appearance-none opacity-0"
585
+ }), e.label]
586
+ }, String(e.value));
587
+ })]
588
+ });
589
+ }
590
+ //#endregion
591
+ //#region src/segments.ts
592
+ function Y(e, t, n, r) {
593
+ let i = e.length >= 2 ? t : e + t, a = Number(i);
594
+ if (a > r) {
595
+ let e = Number(t);
596
+ return e > r || e < n ? {
597
+ buffer: "",
598
+ value: null,
599
+ done: !1
600
+ } : {
601
+ buffer: t,
602
+ value: e,
603
+ done: e * 10 > r
604
+ };
605
+ }
606
+ return {
607
+ buffer: i,
608
+ value: a >= n ? a : null,
609
+ done: i.length === 2 || a * 10 > r
610
+ };
611
+ }
612
+ function X(e, t, n, r) {
613
+ let i = r - n + 1;
614
+ return n + ((e - n + t) % i + i) % i;
615
+ }
616
+ //#endregion
617
+ //#region src/time-panel.tsx
618
+ var Z = {
619
+ time: "Time",
620
+ hour: "Hour",
621
+ minute: "Minute",
622
+ dayPeriod: "Day period"
623
+ };
624
+ function Q({ value: e, onChange: n, locale: r = navigator.language, hourCycle: o, minuteInterval: s = 1, wheels: c = !0, labels: l, className: u }) {
625
+ let d = {
626
+ ...Z,
627
+ ...l
628
+ }, f = (o ?? b(r)) === "h12", m = e.getHours(), h = e.getMinutes(), { hour: g, pm: _ } = x(m), v = f ? g : m, y = +!!f, w = f ? 12 : 23, T = C(r), [E, D] = t.useState(null), O = t.useRef(null), k = t.useRef(null), j = (t) => n(p(e, f ? S(t, _) : t, h)), M = (t) => n(p(e, m, t)), P = (t) => n(p(e, S(g, t), h)), F = (e) => {
629
+ let t = e === "hour" ? O.current : k.current;
630
+ t?.focus(), t?.select();
631
+ }, I = (e, t) => {
632
+ let n = E?.segment === e ? E.buffer : "", r = e === "hour" ? Y(n, t, y, w) : Y(n, t, 0, 59);
633
+ r.value !== null && (e === "hour" ? j : M)(r.value), r.done ? (D(null), e === "hour" && F("minute")) : D({
634
+ segment: e,
635
+ buffer: r.buffer
636
+ });
637
+ }, L = (e) => (t) => {
638
+ let n = t.key;
639
+ if (/^\d$/.test(n)) {
640
+ t.preventDefault(), I(e, n);
641
+ return;
642
+ }
643
+ let r = n === "ArrowUp" ? 1 : n === "ArrowDown" ? -1 : 0;
644
+ if (r) {
645
+ t.preventDefault(), D(null), e === "hour" ? j(X(v, r, y, w)) : M(X(h, r * s, 0, 59));
646
+ return;
647
+ }
648
+ n === "ArrowLeft" && e === "minute" ? (t.preventDefault(), F("hour")) : n === "ArrowRight" && e === "hour" ? (t.preventDefault(), F("minute")) : n === "Backspace" || n === "Delete" ? (t.preventDefault(), D({
649
+ segment: e,
650
+ buffer: ""
651
+ })) : f && (n === "a" || n === "A" || n === "p" || n === "P") ? (t.preventDefault(), P(n === "p" || n === "P")) : n === "Enter" ? t.currentTarget.blur() : n.length === 1 && !t.metaKey && !t.ctrlKey && t.preventDefault();
652
+ }, R = (e) => (t) => {
653
+ t.preventDefault();
654
+ let n = t.nativeEvent.data ?? "";
655
+ for (let t of n) /\d/.test(t) && I(e, t);
656
+ }, z = (e) => (t) => {
657
+ let n = t.target.value.replace(B(e), "");
658
+ for (let t of n) /\d/.test(t) && I(e, t);
659
+ }, B = (e) => E?.segment === e ? E.buffer : e === "hour" ? f ? String(v) : N(v) : N(h), V = "box-content h-10 rounded-md bg-transparent px-1 text-center text-[32px] leading-none font-light tabular-nums text-[var(--cdp-label)] caret-transparent outline-none selection:bg-transparent focus:bg-[var(--cdp-tint-fill)] focus:text-[var(--cdp-tint)]", W = Array.from({ length: w - y + 1 }, (e, t) => {
660
+ let n = y + t;
661
+ return {
662
+ value: n,
663
+ label: f ? String(n) : N(n)
664
+ };
665
+ }), G = Array.from({ length: Math.ceil(60 / s) }, (e, t) => ({
666
+ value: t * s,
667
+ label: N(t * s)
668
+ }));
669
+ return /* @__PURE__ */ a("div", {
670
+ className: A("cdp flex w-[280px] flex-col gap-2 p-3 select-none", u),
671
+ "data-slot": "time",
672
+ children: [/* @__PURE__ */ a("div", {
673
+ className: "flex items-center justify-between gap-3",
674
+ children: [/* @__PURE__ */ a("div", {
675
+ role: "group",
676
+ "aria-label": d.time,
677
+ className: "flex h-11 items-center rounded-lg bg-[var(--cdp-fill)] px-1.5",
678
+ "data-slot": "time-field",
679
+ children: [
680
+ /* @__PURE__ */ i("input", {
681
+ ref: O,
682
+ "aria-label": d.hour,
683
+ inputMode: "numeric",
684
+ autoComplete: "off",
685
+ value: B("hour"),
686
+ onChange: z("hour"),
687
+ onBeforeInput: R("hour"),
688
+ onKeyDown: L("hour"),
689
+ onFocus: (e) => e.currentTarget.select(),
690
+ onBlur: () => D(null),
691
+ className: V,
692
+ style: { width: `${Math.max(1, B("hour").length || 1)}ch` },
693
+ "data-segment": "hour"
694
+ }),
695
+ /* @__PURE__ */ i("span", {
696
+ className: "-mx-0.5 text-[32px] leading-none font-light text-[var(--cdp-label)]",
697
+ "aria-hidden": !0,
698
+ children: ":"
699
+ }),
700
+ /* @__PURE__ */ i("input", {
701
+ ref: k,
702
+ "aria-label": d.minute,
703
+ inputMode: "numeric",
704
+ autoComplete: "off",
705
+ value: B("minute"),
706
+ onChange: z("minute"),
707
+ onBeforeInput: R("minute"),
708
+ onKeyDown: L("minute"),
709
+ onFocus: (e) => e.currentTarget.select(),
710
+ onBlur: () => D(null),
711
+ className: V,
712
+ style: { width: "2ch" },
713
+ "data-segment": "minute"
714
+ })
715
+ ]
716
+ }), f && /* @__PURE__ */ i(J, {
717
+ "aria-label": d.dayPeriod,
718
+ options: [{
719
+ value: !1,
720
+ label: T.am
721
+ }, {
722
+ value: !0,
723
+ label: T.pm
724
+ }],
725
+ value: _,
726
+ onChange: P
727
+ })]
728
+ }), c && /* @__PURE__ */ a("div", {
729
+ className: "cdp-wheel-mask relative flex justify-center",
730
+ "data-slot": "time-wheels",
731
+ children: [
732
+ /* @__PURE__ */ i(U, {}),
733
+ /* @__PURE__ */ i(H, {
734
+ "aria-label": d.hour,
735
+ options: W,
736
+ value: v,
737
+ loop: !0,
738
+ onChange: j,
739
+ className: "w-16"
740
+ }),
741
+ /* @__PURE__ */ i(H, {
742
+ "aria-label": d.minute,
743
+ options: G,
744
+ value: h - h % s,
745
+ loop: !0,
746
+ onChange: M,
747
+ className: "w-16"
748
+ }),
749
+ f && /* @__PURE__ */ i(H, {
750
+ "aria-label": d.dayPeriod,
751
+ options: [{
752
+ value: 0,
753
+ label: T.am
754
+ }, {
755
+ value: 1,
756
+ label: T.pm
757
+ }],
758
+ value: +!!_,
759
+ onChange: (e) => P(e === 1),
760
+ className: "w-16"
761
+ })
762
+ ]
763
+ })]
764
+ });
765
+ }
766
+ //#endregion
767
+ //#region src/date-time-picker.tsx
768
+ var $ = "inline-flex h-[34px] items-center rounded-lg bg-[var(--cdp-fill)] px-3 text-[17px] leading-none text-[var(--cdp-label)] transition-[background-color,color] outline-none hover:bg-[var(--cdp-fill-hover)] focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)] active:opacity-60 disabled:opacity-40 data-popup-open:text-[var(--cdp-tint)]", te = "cdp origin-(--transform-origin) rounded-[13px] bg-[var(--cdp-bg)] shadow-[var(--cdp-shadow)] outline-none data-open:animate-[cdp-pop-in_260ms_cubic-bezier(0.18,0.9,0.32,1.15)] data-closed:animate-[cdp-pop-out_140ms_ease-in]";
769
+ function ne({ value: t, defaultValue: n = null, onChange: r, mode: o = "dateTime", display: s = "compact", locale: c = navigator.language, hourCycle: l, minuteInterval: u = 1, min: d, max: f, disabled: p = !1, className: m, labels: h }) {
770
+ let [g, _] = P(t, n, r), v = l ?? b(c), y = o !== "time", x = o !== "date", S = g ?? /* @__PURE__ */ new Date(), C = /* @__PURE__ */ i(q, {
771
+ value: g,
772
+ onChange: _,
773
+ locale: c,
774
+ min: d,
775
+ max: f
776
+ }), w = /* @__PURE__ */ i(Q, {
777
+ value: S,
778
+ onChange: _,
779
+ locale: c,
780
+ hourCycle: v,
781
+ minuteInterval: u
782
+ }), T = /* @__PURE__ */ a(e.Root, { children: [/* @__PURE__ */ i(e.Trigger, {
783
+ className: $,
784
+ disabled: p,
785
+ "data-slot": "time-trigger",
786
+ children: g ? D(g, c, v) : h?.time ?? "Time"
787
+ }), /* @__PURE__ */ i(e.Portal, { children: /* @__PURE__ */ i(e.Positioner, {
788
+ sideOffset: 8,
789
+ align: "center",
790
+ className: "isolate z-50",
791
+ children: /* @__PURE__ */ i(e.Popup, {
792
+ className: te,
793
+ "data-slot": "time-popup",
794
+ children: w
795
+ })
796
+ }) })] });
797
+ return s === "inline" ? /* @__PURE__ */ a("div", {
798
+ className: A("cdp inline-flex flex-col items-stretch rounded-[13px] bg-[var(--cdp-bg)]", m),
799
+ "data-slot": "date-time-picker",
800
+ "data-display": "inline",
801
+ children: [y && C, x && (y ? /* @__PURE__ */ a("div", {
802
+ className: "mx-3 flex h-[52px] items-center justify-between border-t border-[var(--cdp-fill)]",
803
+ children: [/* @__PURE__ */ i("span", {
804
+ className: "text-[17px] text-[var(--cdp-label)]",
805
+ children: h?.time ?? "Time"
806
+ }), T]
807
+ }) : w)]
808
+ }) : /* @__PURE__ */ a("div", {
809
+ className: A("cdp inline-flex items-center gap-2", m),
810
+ "data-slot": "date-time-picker",
811
+ "data-display": "compact",
812
+ children: [y && /* @__PURE__ */ a(e.Root, { children: [/* @__PURE__ */ i(e.Trigger, {
813
+ className: "inline-flex h-[34px] items-center rounded-lg bg-[var(--cdp-fill)] px-3 text-[17px] leading-none text-[var(--cdp-label)] transition-[background-color,color] outline-none hover:bg-[var(--cdp-fill-hover)] focus-visible:ring-2 focus-visible:ring-[var(--cdp-tint)] active:opacity-60 disabled:opacity-40 data-popup-open:text-[var(--cdp-tint)]",
814
+ disabled: p,
815
+ "data-slot": "date-trigger",
816
+ children: g ? E(g, c) : h?.date ?? "Date"
817
+ }), /* @__PURE__ */ i(e.Portal, { children: /* @__PURE__ */ i(e.Positioner, {
818
+ sideOffset: 8,
819
+ align: "center",
820
+ className: "isolate z-50",
821
+ children: /* @__PURE__ */ i(e.Popup, {
822
+ className: "cdp origin-(--transform-origin) rounded-[13px] bg-[var(--cdp-bg)] shadow-[var(--cdp-shadow)] outline-none data-open:animate-[cdp-pop-in_260ms_cubic-bezier(0.18,0.9,0.32,1.15)] data-closed:animate-[cdp-pop-out_140ms_ease-in]",
823
+ "data-slot": "date-popup",
824
+ children: C
825
+ })
826
+ }) })] }), x && T]
827
+ });
828
+ }
829
+ //#endregion
830
+ export { W as CALENDAR_LABELS, q as CalendarPanel, ne as DateTimePicker, J as SegmentedControl, Z as TIME_LABELS, Q as TimePanel, H as Wheel, U as WheelHighlight, m as addDays, h as addMonths, C as dayPeriodLabels, c as daysInMonth, D as formatClock, E as formatDay, k as formatFullDate, O as formatMonthYear, b as hourCycleFor, g as isDayDisabled, s as isSameDay, u as monthDiff, _ as monthGrid, w as monthNames, $ as pillClass, te as popupClass, d as shiftMonth, o as startOfDay, X as stepValue, x as to12, S as to24, Y as typeDigit, v as weekStartFor, T as weekdayNames, f as withDay, p as withTime, l as yearMonthOf };
831
+
832
+ //# sourceMappingURL=index.js.map