@justanarthur/modo-ui 0.0.0-stage → 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 (172) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.beui +21 -0
  3. package/LICENSE.fluid-functionalism +21 -0
  4. package/LICENSE.motion-primitives +21 -0
  5. package/LICENSE.sileo +21 -0
  6. package/README.md +608 -2
  7. package/dist/base.css +994 -0
  8. package/dist/blocks/sidebar-app/index.d.ts +34 -0
  9. package/dist/blocks/sidebar-app/index.js +34 -0
  10. package/dist/components/badge/index.d.ts +59 -0
  11. package/dist/components/badge/index.js +18 -0
  12. package/dist/components/button/index.d.ts +59 -0
  13. package/dist/components/button/index.js +16 -0
  14. package/dist/components/card/index.d.ts +141 -0
  15. package/dist/components/card/index.js +44 -0
  16. package/dist/components/inputs/checkbox-group/index.d.ts +50 -0
  17. package/dist/components/inputs/checkbox-group/index.js +23 -0
  18. package/dist/components/inputs/color-picker/index.d.ts +137 -0
  19. package/dist/components/inputs/color-picker/index.js +37 -0
  20. package/dist/components/inputs/combobox/index.d.ts +161 -0
  21. package/dist/components/inputs/combobox/index.js +41 -0
  22. package/dist/components/inputs/date-time/calendar/index.d.ts +45 -0
  23. package/dist/components/inputs/date-time/calendar/index.js +20 -0
  24. package/dist/components/inputs/date-time/date-picker/index.d.ts +82 -0
  25. package/dist/components/inputs/date-time/date-picker/index.js +34 -0
  26. package/dist/components/inputs/date-time/date-range-picker/index.d.ts +64 -0
  27. package/dist/components/inputs/date-time/date-range-picker/index.js +33 -0
  28. package/dist/components/inputs/date-time/duration-picker/index.d.ts +57 -0
  29. package/dist/components/inputs/date-time/duration-picker/index.js +33 -0
  30. package/dist/components/inputs/date-time/month-picker/index.d.ts +57 -0
  31. package/dist/components/inputs/date-time/month-picker/index.js +32 -0
  32. package/dist/components/inputs/date-time/time-picker/index.d.ts +59 -0
  33. package/dist/components/inputs/date-time/time-picker/index.js +33 -0
  34. package/dist/components/inputs/input/index.d.ts +84 -0
  35. package/dist/components/inputs/input/index.js +20 -0
  36. package/dist/components/inputs/input-copy/index.d.ts +44 -0
  37. package/dist/components/inputs/input-copy/index.js +18 -0
  38. package/dist/components/inputs/input-message/index.d.ts +125 -0
  39. package/dist/components/inputs/input-message/index.js +27 -0
  40. package/dist/components/inputs/radio-group/index.d.ts +58 -0
  41. package/dist/components/inputs/radio-group/index.js +22 -0
  42. package/dist/components/inputs/search/index.d.ts +83 -0
  43. package/dist/components/inputs/search/index.js +28 -0
  44. package/dist/components/inputs/select/index.d.ts +105 -0
  45. package/dist/components/inputs/select/index.js +37 -0
  46. package/dist/components/inputs/slider/index.d.ts +108 -0
  47. package/dist/components/inputs/slider/index.js +16 -0
  48. package/dist/components/inputs/switch/index.d.ts +43 -0
  49. package/dist/components/inputs/switch/index.js +16 -0
  50. package/dist/components/navigation/accordion/index.d.ts +117 -0
  51. package/dist/components/navigation/accordion/index.js +30 -0
  52. package/dist/components/navigation/sidebar/index.d.ts +388 -0
  53. package/dist/components/navigation/sidebar/index.js +101 -0
  54. package/dist/components/navigation/tabs/index.d.ts +70 -0
  55. package/dist/components/navigation/tabs/index.js +25 -0
  56. package/dist/components/navigation/tabs-subtle/index.d.ts +73 -0
  57. package/dist/components/navigation/tabs-subtle/index.js +23 -0
  58. package/dist/components/overlays/alert-dialog/index.d.ts +67 -0
  59. package/dist/components/overlays/alert-dialog/index.js +24 -0
  60. package/dist/components/overlays/command/index.d.ts +121 -0
  61. package/dist/components/overlays/command/index.js +39 -0
  62. package/dist/components/overlays/context-menu/index.d.ts +97 -0
  63. package/dist/components/overlays/context-menu/index.js +32 -0
  64. package/dist/components/overlays/dialog/index.d.ts +130 -0
  65. package/dist/components/overlays/dialog/index.js +39 -0
  66. package/dist/components/overlays/dropdown/index.d.ts +222 -0
  67. package/dist/components/overlays/dropdown/index.js +47 -0
  68. package/dist/components/overlays/popover/index.d.ts +87 -0
  69. package/dist/components/overlays/popover/index.js +28 -0
  70. package/dist/components/overlays/preview-card/index.d.ts +75 -0
  71. package/dist/components/overlays/preview-card/index.js +21 -0
  72. package/dist/components/overlays/sheet/index.d.ts +67 -0
  73. package/dist/components/overlays/sheet/index.js +26 -0
  74. package/dist/components/overlays/toast/index.d.ts +107 -0
  75. package/dist/components/overlays/toast/index.js +23 -0
  76. package/dist/components/overlays/tooltip/index.d.ts +75 -0
  77. package/dist/components/overlays/tooltip/index.js +19 -0
  78. package/dist/components/table/index.d.ts +44 -0
  79. package/dist/components/table/index.js +28 -0
  80. package/dist/components/thinking-indicator/index.d.ts +32 -0
  81. package/dist/components/thinking-indicator/index.js +15 -0
  82. package/dist/index.d.ts +3926 -0
  83. package/dist/index.js +513 -0
  84. package/dist/preset.d.ts +104 -0
  85. package/dist/preset.js +124 -0
  86. package/dist/primitives/code/index.d.ts +23 -0
  87. package/dist/primitives/code/index.js +12 -0
  88. package/dist/primitives/craft/index.d.ts +31 -0
  89. package/dist/primitives/craft/index.js +13 -0
  90. package/dist/primitives/fluid-hover/index.d.ts +233 -0
  91. package/dist/primitives/fluid-hover/index.js +27 -0
  92. package/dist/primitives/morph/index.d.ts +127 -0
  93. package/dist/primitives/morph/index.js +21 -0
  94. package/dist/primitives/motion/index.d.ts +115 -0
  95. package/dist/primitives/motion/index.js +20 -0
  96. package/dist/primitives/scroll-area/index.d.ts +41 -0
  97. package/dist/primitives/scroll-area/index.js +13 -0
  98. package/dist/primitives/sizes/index.d.ts +128 -0
  99. package/dist/primitives/sizes/index.js +22 -0
  100. package/dist/primitives/surface/index.d.ts +69 -0
  101. package/dist/primitives/surface/index.js +18 -0
  102. package/dist/shared/components-0f0as45n.js +17 -0
  103. package/dist/shared/components-40j34hdb.js +986 -0
  104. package/dist/shared/components-4hh0gm0v.js +292 -0
  105. package/dist/shared/components-4xxddc44.js +15 -0
  106. package/dist/shared/components-4xxtggzp.js +110 -0
  107. package/dist/shared/components-54nf2x99.js +293 -0
  108. package/dist/shared/components-5pkcfprd.js +232 -0
  109. package/dist/shared/components-5vxtcp88.js +9 -0
  110. package/dist/shared/components-5zry9te1.js +152 -0
  111. package/dist/shared/components-61ckf42z.js +220 -0
  112. package/dist/shared/components-6hzwfmfd.js +58 -0
  113. package/dist/shared/components-6phwsry6.js +361 -0
  114. package/dist/shared/components-6t6nr33r.js +86 -0
  115. package/dist/shared/components-6y1th6k4.js +111 -0
  116. package/dist/shared/components-74c20v2f.js +32 -0
  117. package/dist/shared/components-7cqq1sqy.js +193 -0
  118. package/dist/shared/components-7gv95yfy.js +496 -0
  119. package/dist/shared/components-7nww01w4.js +375 -0
  120. package/dist/shared/components-7zp99w5d.js +62 -0
  121. package/dist/shared/components-8hk9ve3r.js +1200 -0
  122. package/dist/shared/components-8hzbsfbd.js +123 -0
  123. package/dist/shared/components-9p8s8n5q.js +171 -0
  124. package/dist/shared/components-aaq3yk4f.js +304 -0
  125. package/dist/shared/components-bf2d9k02.js +484 -0
  126. package/dist/shared/components-bkvb6nem.js +63 -0
  127. package/dist/shared/components-brnzrp2t.js +262 -0
  128. package/dist/shared/components-csxz9f52.js +42 -0
  129. package/dist/shared/components-de8xsm9y.js +22 -0
  130. package/dist/shared/components-dg0w8g5p.js +26 -0
  131. package/dist/shared/components-dphg9gjr.js +42 -0
  132. package/dist/shared/components-e46kf6cp.js +298 -0
  133. package/dist/shared/components-ed7cmssr.js +105 -0
  134. package/dist/shared/components-ess3ch6w.js +137 -0
  135. package/dist/shared/components-gjfrycb5.js +984 -0
  136. package/dist/shared/components-gndm6am4.js +128 -0
  137. package/dist/shared/components-hjkrv00c.js +191 -0
  138. package/dist/shared/components-hzfp4tjb.js +270 -0
  139. package/dist/shared/components-j65qt1mq.js +719 -0
  140. package/dist/shared/components-jw16snbn.js +19 -0
  141. package/dist/shared/components-jxgznftn.js +146 -0
  142. package/dist/shared/components-kf2ehztc.js +216 -0
  143. package/dist/shared/components-kpbcms10.js +9 -0
  144. package/dist/shared/components-m5br529r.js +141 -0
  145. package/dist/shared/components-nn6xezy2.js +1828 -0
  146. package/dist/shared/components-nnnd2xef.js +9 -0
  147. package/dist/shared/components-p2vmyfe1.js +345 -0
  148. package/dist/shared/components-peg09pzs.js +79 -0
  149. package/dist/shared/components-r22vtgqc.js +45 -0
  150. package/dist/shared/components-r2gke5p6.js +1759 -0
  151. package/dist/shared/components-r43mqnd6.js +160 -0
  152. package/dist/shared/components-r4jt6hgd.js +58 -0
  153. package/dist/shared/components-rc63qsy6.js +159 -0
  154. package/dist/shared/components-s3yfvfkr.js +149 -0
  155. package/dist/shared/components-s5pkbjx1.js +445 -0
  156. package/dist/shared/components-tad5h7ta.js +346 -0
  157. package/dist/shared/components-taxmgbnh.js +120 -0
  158. package/dist/shared/components-tm88ghva.js +215 -0
  159. package/dist/shared/components-v7es8aan.js +144 -0
  160. package/dist/shared/components-vb033rns.js +28 -0
  161. package/dist/shared/components-vc1k7yv2.js +30 -0
  162. package/dist/shared/components-vktws5r6.js +667 -0
  163. package/dist/shared/components-x2xyckd5.js +198 -0
  164. package/dist/shared/components-x3rz4cyn.js +61 -0
  165. package/dist/shared/components-xszag63d.js +141 -0
  166. package/dist/shared/components-y3cqdrgy.js +291 -0
  167. package/dist/shared/components-zvb11ker.js +288 -0
  168. package/dist/shared/components-zx2hr57f.js +124 -0
  169. package/dist/styles.css +1949 -0
  170. package/dist/tailwind.css +219 -0
  171. package/dist/tokens.css +345 -0
  172. package/package.json +102 -3
@@ -0,0 +1,220 @@
1
+ import {
2
+ slotRender
3
+ } from "./components-5vxtcp88.js";
4
+ import {
5
+ Button
6
+ } from "./components-5pkcfprd.js";
7
+ import {
8
+ useIcon
9
+ } from "./components-m5br529r.js";
10
+ import {
11
+ SURFACE_BG,
12
+ SURFACE_SHADOW,
13
+ SurfaceProvider,
14
+ useSurface
15
+ } from "./components-csxz9f52.js";
16
+ import {
17
+ MorphPartScope,
18
+ MorphSurface
19
+ } from "./components-jxgznftn.js";
20
+ import {
21
+ useShape
22
+ } from "./components-7zp99w5d.js";
23
+ import {
24
+ useControllableState
25
+ } from "./components-dg0w8g5p.js";
26
+ import {
27
+ useMorph,
28
+ useMorphOrigin
29
+ } from "./components-7nww01w4.js";
30
+ import {
31
+ useSize,
32
+ useSizeVariant
33
+ } from "./components-x3rz4cyn.js";
34
+ import {
35
+ cn
36
+ } from "./components-0f0as45n.js";
37
+
38
+ // components/overlays/dialog/index.tsx
39
+ import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
40
+ import { motion } from "motion/react";
41
+ import {
42
+ createContext,
43
+ forwardRef,
44
+ useContext,
45
+ useId,
46
+ useImperativeHandle,
47
+ useMemo
48
+ } from "react";
49
+ import { jsx, jsxs } from "react/jsx-runtime";
50
+ var DIALOG_OFFSET = 4;
51
+ var DialogContext = createContext({
52
+ open: false,
53
+ origin: { current: {} }
54
+ });
55
+ var useDialogState = () => useContext(DialogContext);
56
+ var DialogTrigger = forwardRef(({ render, asChild, children, ...props }, ref) => {
57
+ const el = slotRender(render, asChild, children);
58
+ return el ? /* @__PURE__ */ jsx(DialogPrimitive.Trigger, {
59
+ ref,
60
+ render: el,
61
+ ...props
62
+ }) : /* @__PURE__ */ jsx(DialogPrimitive.Trigger, {
63
+ ref,
64
+ ...props,
65
+ children
66
+ });
67
+ });
68
+ DialogTrigger.displayName = "DialogTrigger";
69
+ var DialogClose = forwardRef(({ render, asChild, children, ...props }, ref) => {
70
+ const el = slotRender(render, asChild, children);
71
+ return el ? /* @__PURE__ */ jsx(DialogPrimitive.Close, {
72
+ ref,
73
+ render: el,
74
+ ...props
75
+ }) : /* @__PURE__ */ jsx(DialogPrimitive.Close, {
76
+ ref,
77
+ ...props,
78
+ children
79
+ });
80
+ });
81
+ DialogClose.displayName = "DialogClose";
82
+ var DialogContent = forwardRef(({
83
+ className,
84
+ children,
85
+ size = "sm",
86
+ container,
87
+ showCloseButton = true,
88
+ position = "center",
89
+ from,
90
+ effect,
91
+ hideSource,
92
+ tier,
93
+ ...props
94
+ }, ref) => {
95
+ const XIcon = useIcon("x");
96
+ const shape = useShape();
97
+ const substrate = useSurface();
98
+ const dialogLevel = Math.min(substrate + DIALOG_OFFSET, 8);
99
+ const compact = useSize().variant === "compact";
100
+ const { open, origin } = useDialogState();
101
+ const morph = useMorph(open, origin, { from, effect, hideSource, tier });
102
+ useImperativeHandle(ref, () => morph.popup, [morph.popup]);
103
+ return /* @__PURE__ */ jsxs(DialogPrimitive.Portal, {
104
+ container: container ?? undefined,
105
+ children: [
106
+ /* @__PURE__ */ jsx(DialogPrimitive.Backdrop, {
107
+ render: /* @__PURE__ */ jsx(motion.div, {
108
+ style: { opacity: morph.progress }
109
+ }),
110
+ className: cn(container ? "absolute" : "fixed", "inset-0 z-50 bg-scrim")
111
+ }),
112
+ /* @__PURE__ */ jsx(DialogPrimitive.Popup, {
113
+ ref: morph.popupRef,
114
+ ...props,
115
+ className: cn(container ? "absolute" : "fixed", "left-1/2 z-50 w-[calc(100%-2rem)] -translate-x-1/2 focus:outline-none", position === "top" ? "top-[12dvh]" : "top-1/2 -translate-y-1/2", size === "sm" && (compact ? "max-w-[360px]" : "max-w-[400px]"), size === "lg" && (compact ? "max-w-[480px]" : "max-w-[540px]"), size === "xl" && (compact ? "max-w-[800px]" : "max-w-[880px]")),
116
+ children: /* @__PURE__ */ jsx(SurfaceProvider, {
117
+ value: dialogLevel,
118
+ children: /* @__PURE__ */ jsxs(MorphSurface, {
119
+ morph,
120
+ bg: SURFACE_BG[dialogLevel],
121
+ shadow: SURFACE_SHADOW[dialogLevel],
122
+ radius: shape.container,
123
+ className: cn("p-6", className),
124
+ children: [
125
+ children,
126
+ showCloseButton && /* @__PURE__ */ jsx(DialogPrimitive.Close, {
127
+ render: /* @__PURE__ */ jsxs(Button, {
128
+ variant: "ghost",
129
+ size: "icon-sm",
130
+ className: "absolute right-3 top-3",
131
+ children: [
132
+ /* @__PURE__ */ jsx(XIcon, {}),
133
+ /* @__PURE__ */ jsx("span", {
134
+ className: "sr-only",
135
+ children: "Close"
136
+ })
137
+ ]
138
+ })
139
+ })
140
+ ]
141
+ })
142
+ })
143
+ })
144
+ ]
145
+ });
146
+ });
147
+ DialogContent.displayName = "DialogContent";
148
+ function DialogHeader({ className, ...props }) {
149
+ return /* @__PURE__ */ jsx("div", {
150
+ className: cn("flex flex-col gap-1.5 mb-4", className),
151
+ ...props
152
+ });
153
+ }
154
+ function DialogFooter({ className, ...props }) {
155
+ return /* @__PURE__ */ jsx("div", {
156
+ className: cn("flex justify-end gap-2 mt-6", className),
157
+ ...props
158
+ });
159
+ }
160
+ var DialogTitle = forwardRef(({ className, ...props }, ref) => {
161
+ const compact = useSizeVariant() === "compact";
162
+ return /* @__PURE__ */ jsx(DialogPrimitive.Title, {
163
+ ref,
164
+ className: cn(compact ? "text-title-compact" : "text-title", "weight-bold text-foreground leading-tight", className),
165
+ ...props
166
+ });
167
+ });
168
+ DialogTitle.displayName = "DialogTitle";
169
+ var DialogDescription = forwardRef(({ className, ...props }, ref) => {
170
+ const compact = useSizeVariant() === "compact";
171
+ return /* @__PURE__ */ jsx(DialogPrimitive.Description, {
172
+ ref,
173
+ className: cn(compact ? "text-body-compact" : "text-body", "text-muted-foreground", className),
174
+ ...props
175
+ });
176
+ });
177
+ DialogDescription.displayName = "DialogDescription";
178
+ function DialogState({ open, defaultOpen = false, onOpenChange, children }) {
179
+ const [current, setCurrent] = useControllableState(open, defaultOpen, onOpenChange);
180
+ const { origin, capture } = useMorphOrigin();
181
+ const id = useId();
182
+ const ctx = useMemo(() => ({ open: current, origin }), [current, origin]);
183
+ const parts = useMemo(() => ({ id, open: current }), [id, current]);
184
+ return /* @__PURE__ */ jsx(DialogContext.Provider, {
185
+ value: ctx,
186
+ children: /* @__PURE__ */ jsx(MorphPartScope.Provider, {
187
+ value: parts,
188
+ children: children({
189
+ open: current,
190
+ onOpenChange: (next, details) => {
191
+ if (next)
192
+ capture(details);
193
+ setCurrent(next);
194
+ }
195
+ })
196
+ })
197
+ });
198
+ }
199
+ function Dialog({ children, open, defaultOpen, onOpenChange, modal }) {
200
+ return /* @__PURE__ */ jsx(DialogState, {
201
+ open,
202
+ defaultOpen,
203
+ onOpenChange,
204
+ children: (root) => /* @__PURE__ */ jsx(DialogPrimitive.Root, {
205
+ ...root,
206
+ modal,
207
+ children
208
+ })
209
+ });
210
+ }
211
+ Dialog.Trigger = DialogTrigger;
212
+ Dialog.Content = DialogContent;
213
+ Dialog.Header = DialogHeader;
214
+ Dialog.Footer = DialogFooter;
215
+ Dialog.Title = DialogTitle;
216
+ Dialog.Description = DialogDescription;
217
+ Dialog.Close = DialogClose;
218
+ var dialog_default = Dialog;
219
+
220
+ export { useDialogState, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, DialogState, Dialog, dialog_default };
@@ -0,0 +1,58 @@
1
+ import {
2
+ badge_default
3
+ } from "./components-9p8s8n5q.js";
4
+ import {
5
+ useShape
6
+ } from "./components-7zp99w5d.js";
7
+ import {
8
+ cn
9
+ } from "./components-0f0as45n.js";
10
+
11
+ // primitives/craft/index.tsx
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ function Pane({ verdict, note, children }) {
14
+ const shape = useShape();
15
+ return /* @__PURE__ */ jsxs("figure", {
16
+ className: cn("row-span-2 m-0 grid min-w-0 grid-rows-subgrid gap-0 ring-1 ring-border", shape.container),
17
+ children: [
18
+ /* @__PURE__ */ jsx("div", {
19
+ className: "flex min-h-40 items-center justify-center p-4",
20
+ children
21
+ }),
22
+ /* @__PURE__ */ jsxs("figcaption", {
23
+ className: "flex items-start gap-2 border-t border-border px-4 py-3",
24
+ children: [
25
+ /* @__PURE__ */ jsx(badge_default, {
26
+ variant: "dot",
27
+ size: "compact",
28
+ color: verdict === "bad" ? "red" : "green",
29
+ children: verdict === "bad" ? "Bad" : "Good"
30
+ }),
31
+ note && /* @__PURE__ */ jsx("span", {
32
+ className: "text-caption text-muted-foreground",
33
+ children: note
34
+ })
35
+ ]
36
+ })
37
+ ]
38
+ });
39
+ }
40
+ function Craft({ bad, good, badNote, goodNote, className }) {
41
+ return /* @__PURE__ */ jsxs("div", {
42
+ className: cn("grid w-full gap-3 sm:grid-cols-2", className),
43
+ children: [
44
+ /* @__PURE__ */ jsx(Pane, {
45
+ verdict: "bad",
46
+ note: badNote,
47
+ children: bad
48
+ }),
49
+ /* @__PURE__ */ jsx(Pane, {
50
+ verdict: "good",
51
+ note: goodNote,
52
+ children: good
53
+ })
54
+ ]
55
+ });
56
+ }
57
+
58
+ export { Craft };
@@ -0,0 +1,361 @@
1
+ import {
2
+ ScrollColumn,
3
+ defaultLocale,
4
+ dividedColumns,
5
+ fieldLabel
6
+ } from "./components-x2xyckd5.js";
7
+ import {
8
+ SizeProvider
9
+ } from "./components-vb033rns.js";
10
+ import {
11
+ useShape
12
+ } from "./components-7zp99w5d.js";
13
+ import {
14
+ useSize
15
+ } from "./components-x3rz4cyn.js";
16
+ import {
17
+ cn
18
+ } from "./components-0f0as45n.js";
19
+
20
+ // components/inputs/date-time/calendar/index.tsx
21
+ import {
22
+ addDays,
23
+ addYears,
24
+ endOfYear,
25
+ format as format2,
26
+ isSameYear,
27
+ startOfMonth as startOfMonth2,
28
+ startOfWeek,
29
+ startOfYear
30
+ } from "date-fns";
31
+ import { useCallback as useCallback2, useEffect, useLayoutEffect as useLayoutEffect2, useMemo, useRef as useRef2, useState as useState2 } from "react";
32
+ import { DayPicker } from "react-day-picker";
33
+
34
+ // components/inputs/date-time/calendar/use-month-window.ts
35
+ import { addMonths, differenceInCalendarMonths, format, startOfMonth } from "date-fns";
36
+ import { useCallback, useLayoutEffect, useRef, useState } from "react";
37
+ var WINDOW = 25;
38
+ var SHIFT = 12;
39
+ var monthKey = (date) => format(date, "yyyy-MM");
40
+ var findMonth = (scroller, key) => scroller.querySelector(`[data-calendar-month="${key}"]`);
41
+ function useMonthWindow(start, end, anchor) {
42
+ const total = differenceInCalendarMonths(end, start) + 1;
43
+ const count = Math.min(WINDOW, total);
44
+ const startTime = start.getTime();
45
+ const clamp = useCallback((first2) => {
46
+ const from = new Date(startTime);
47
+ const last = addMonths(from, total - count);
48
+ return first2 < from ? from : first2 > last ? last : startOfMonth(first2);
49
+ }, [startTime, total, count]);
50
+ const [first, setFirst] = useState(() => clamp(addMonths(startOfMonth(anchor), -Math.floor(WINDOW / 2))));
51
+ const [visible, setVisible] = useState([]);
52
+ const [current, setCurrent] = useState();
53
+ const scrollerRef = useRef(null);
54
+ const firstRef = useRef(first);
55
+ firstRef.current = first;
56
+ const pending = useRef({ day: anchor });
57
+ const settling = useRef(false);
58
+ const topMonth = useCallback(() => {
59
+ const scroller = scrollerRef.current;
60
+ if (!scroller)
61
+ return;
62
+ const top = scroller.scrollTop;
63
+ return [...scroller.querySelectorAll("[data-calendar-month]")].find((el) => el.offsetTop + el.offsetHeight > top);
64
+ }, []);
65
+ const moveWindow = useCallback((nextFirst, target) => {
66
+ const next = clamp(nextFirst);
67
+ if (next.getTime() === firstRef.current.getTime())
68
+ return;
69
+ const scroller = scrollerRef.current;
70
+ const top = topMonth();
71
+ pending.current = {
72
+ month: target,
73
+ keep: scroller && top ? { key: top.dataset.calendarMonth ?? "", delta: top.offsetTop - scroller.scrollTop } : undefined
74
+ };
75
+ setFirst(next);
76
+ }, [clamp, topMonth]);
77
+ const centreDay = useCallback((date) => {
78
+ const scroller = scrollerRef.current;
79
+ const day = scroller?.querySelector(`[data-day="${format(date, "yyyy-MM-dd")}"]`);
80
+ if (!scroller || !day)
81
+ return;
82
+ const s = scroller.getBoundingClientRect();
83
+ const d = day.getBoundingClientRect();
84
+ const scale = s.height / scroller.offsetHeight || 1;
85
+ scroller.scrollTop += (d.top - s.top) / scale - (scroller.clientHeight - day.offsetHeight) / 2;
86
+ }, []);
87
+ const measure = useCallback(() => {
88
+ const scroller = scrollerRef.current;
89
+ if (!scroller)
90
+ return;
91
+ const top = scroller.scrollTop;
92
+ const bottom = top + scroller.clientHeight;
93
+ const shown = [...scroller.querySelectorAll("[data-calendar-month]")].map((el) => ({
94
+ key: el.dataset.calendarMonth ?? "",
95
+ height: Math.min(bottom, el.offsetTop + el.offsetHeight) - Math.max(top, el.offsetTop)
96
+ })).filter((m) => m.height > 0);
97
+ const inView = shown.map((m) => m.key);
98
+ setVisible((prev) => prev.join() === inView.join() ? prev : inView);
99
+ setCurrent(shown.reduce((a, m) => a && a.height >= m.height ? a : m, undefined)?.key);
100
+ if (settling.current)
101
+ return;
102
+ const margin = scroller.clientHeight;
103
+ if (top < margin)
104
+ moveWindow(addMonths(firstRef.current, -SHIFT));
105
+ else if (scroller.scrollHeight - bottom < margin)
106
+ moveWindow(addMonths(firstRef.current, SHIFT));
107
+ }, [moveWindow]);
108
+ useLayoutEffect(() => {
109
+ const scroller = scrollerRef.current;
110
+ const p = pending.current;
111
+ pending.current = null;
112
+ if (!scroller || !p)
113
+ return;
114
+ const target = p.month && findMonth(scroller, p.month);
115
+ const kept = p.keep && findMonth(scroller, p.keep.key);
116
+ if (target)
117
+ scroller.scrollTop = target.offsetTop;
118
+ else if (kept && p.keep)
119
+ scroller.scrollTop = kept.offsetTop - p.keep.delta;
120
+ else if (p.day)
121
+ centreDay(p.day);
122
+ measure();
123
+ }, [first]);
124
+ const jumpTo = useCallback((month, behavior = "smooth") => {
125
+ const scroller = scrollerRef.current;
126
+ const key = monthKey(month);
127
+ const el = scroller && findMonth(scroller, key);
128
+ if (!scroller || !el) {
129
+ moveWindow(addMonths(startOfMonth(month), -Math.floor(WINDOW / 2)), key);
130
+ return;
131
+ }
132
+ if (behavior === "smooth") {
133
+ settling.current = true;
134
+ const done = () => {
135
+ settling.current = false;
136
+ scroller.removeEventListener("scrollend", done);
137
+ measure();
138
+ };
139
+ scroller.addEventListener("scrollend", done);
140
+ setTimeout(done, 600);
141
+ }
142
+ scroller.scrollTo({ top: el.offsetTop, behavior });
143
+ }, [measure, moveWindow]);
144
+ const recentre = useCallback((month) => moveWindow(addMonths(startOfMonth(month), -Math.floor(WINDOW / 2))), [moveWindow]);
145
+ return { first, count, visible, current, scrollerRef, measure, jumpTo, recentre, centreDay };
146
+ }
147
+
148
+ // components/inputs/date-time/calendar/index.tsx
149
+ import { jsx, jsxs } from "react/jsx-runtime";
150
+ var WEEKEND = { dayOfWeek: [0, 6] };
151
+ function pickedDate(props) {
152
+ if (props.mode === "single")
153
+ return props.selected;
154
+ if (props.mode === "range")
155
+ return props.selected?.from;
156
+ return;
157
+ }
158
+ function Month({ calendarMonth, displayIndex: _, ...props }) {
159
+ return /* @__PURE__ */ jsx("div", {
160
+ ...props,
161
+ "data-calendar-month": monthKey(calendarMonth.date)
162
+ });
163
+ }
164
+ function Day({ day: _, modifiers, className, ...props }) {
165
+ const start = modifiers.range_start && !modifiers.range_end;
166
+ const end = modifiers.range_end && !modifiers.range_start;
167
+ return /* @__PURE__ */ jsx("td", {
168
+ ...props,
169
+ className: cn("relative p-0", !modifiers.hidden && modifiers.range_middle && "bg-active", !modifiers.hidden && modifiers.preview && !modifiers.selected && "bg-hover", (start || end) && "before:absolute before:inset-y-0 before:bg-active", start && "before:start-1/2 before:end-0", end && "before:start-0 before:end-1/2", className)
170
+ });
171
+ }
172
+ function DayButton({ day: _, modifiers, className, ...props }) {
173
+ const ref = useRef2(null);
174
+ useEffect(() => {
175
+ if (modifiers.focused)
176
+ ref.current?.focus();
177
+ }, [modifiers.focused]);
178
+ const shape = useShape();
179
+ const sizeClasses = useSize();
180
+ const pill = modifiers.selected && !modifiers.range_middle;
181
+ return /* @__PURE__ */ jsx("button", {
182
+ ref,
183
+ ...props,
184
+ className: cn("relative flex items-center justify-center tabular-nums outline-none cursor-pointer", "transition-[color,background-color] duration-fast focus-visible:ring-1 focus-visible:ring-focus-ring", "disabled:opacity-50 disabled:cursor-default", sizeClasses.variant === "compact" ? "size-7" : "size-9", sizeClasses.text, shape.item, modifiers.weekend && "text-muted-foreground", modifiers.today && "after:absolute after:bottom-1 after:left-1/2 after:size-1 after:-translate-x-1/2 after:rounded-full after:bg-current", pill ? "bg-foreground text-background weight-semibold hover:bg-foreground/90" : "enabled:hover:bg-hover", className)
185
+ });
186
+ }
187
+ function Calendar({
188
+ locale = defaultLocale,
189
+ size,
190
+ columnsSide = "end",
191
+ extraColumns,
192
+ extraColumnsSide = "end",
193
+ className,
194
+ ...props
195
+ }) {
196
+ const sizeClasses = useSize(size);
197
+ const picked = pickedDate(props);
198
+ const today = useMemo(() => new Date, []);
199
+ const start = startOfMonth2(props.startMonth ?? startOfYear(addYears(today, -100)));
200
+ const end = startOfMonth2(props.endMonth ?? endOfYear(addYears(today, 50)));
201
+ const anchor = picked ?? props.month ?? props.defaultMonth ?? today;
202
+ const scroll = useMonthWindow(start, end, anchor);
203
+ const { jumpTo, visible } = scroll;
204
+ const currentKey = scroll.current ?? monthKey(anchor);
205
+ const yearInView = Number(currentKey.slice(0, 4));
206
+ const monthInView = Number(currentKey.slice(5, 7)) - 1;
207
+ const pickedTime = picked?.getTime();
208
+ const pickedRef = useRef2(pickedTime);
209
+ useEffect(() => {
210
+ if (pickedTime === pickedRef.current)
211
+ return;
212
+ pickedRef.current = pickedTime;
213
+ if (pickedTime !== undefined && !visible.includes(monthKey(new Date(pickedTime))))
214
+ jumpTo(new Date(pickedTime));
215
+ }, [pickedTime, jumpTo, visible]);
216
+ const rootRef = useRef2(null);
217
+ const [wide, setWide] = useState2(true);
218
+ const needed = useRef2(0);
219
+ useLayoutEffect2(() => {
220
+ const root = rootRef.current;
221
+ if (!root)
222
+ return;
223
+ const check = () => {
224
+ if (wide && root.scrollWidth > root.clientWidth + 1) {
225
+ needed.current = root.scrollWidth;
226
+ setWide(false);
227
+ } else if (!wide && root.clientWidth >= needed.current)
228
+ setWide(true);
229
+ };
230
+ check();
231
+ const observer = new ResizeObserver(check);
232
+ observer.observe(root);
233
+ return () => observer.disconnect();
234
+ }, [wide]);
235
+ const turned = useRef2(wide);
236
+ useLayoutEffect2(() => {
237
+ if (turned.current === wide)
238
+ return;
239
+ turned.current = wide;
240
+ scroll.centreDay(picked ?? today);
241
+ });
242
+ const [hovered, setHovered] = useState2();
243
+ const from = props.mode === "range" ? props.selected?.from : undefined;
244
+ const previewing = from && props.mode === "range" && !props.selected?.to && hovered;
245
+ const preview = previewing ? hovered < from ? { from: hovered, to: from } : { from, to: hovered } : false;
246
+ const weekStartsOn = props.weekStartsOn ?? locale.options?.weekStartsOn ?? 0;
247
+ const weekdays = useMemo(() => {
248
+ const first = startOfWeek(today, { weekStartsOn });
249
+ return Array.from({ length: 7 }, (_, i) => addDays(first, i));
250
+ }, [today, weekStartsOn]);
251
+ const months = useMemo(() => Array.from({ length: 12 }, (_, m) => ({
252
+ value: m,
253
+ label: format2(new Date(2000, m, 1), "LLL", { locale }),
254
+ disabled: new Date(yearInView, m, 1) < start || new Date(yearInView, m, 1) > end
255
+ })), [locale, yearInView, start.getTime(), end.getTime()]);
256
+ const years = useMemo(() => Array.from({ length: end.getFullYear() - start.getFullYear() + 1 }, (_, i) => {
257
+ const year = start.getFullYear() + i;
258
+ return { value: year, label: String(year) };
259
+ }), [start.getFullYear(), end.getFullYear()]);
260
+ const jumpToYear = useCallback2((year) => jumpTo(new Date(year, monthInView, 1)), [jumpTo, monthInView]);
261
+ const orientation = wide ? "vertical" : "horizontal";
262
+ const column = wide ? "w-16 shrink-0" : "w-full";
263
+ const monthColumn = /* @__PURE__ */ jsx(ScrollColumn, {
264
+ label: fieldLabel(locale, "month"),
265
+ options: months,
266
+ value: picked && isSameYear(picked, new Date(yearInView, 0, 1)) ? picked.getMonth() : null,
267
+ follow: monthInView,
268
+ inView: (m) => m === monthInView,
269
+ onValueChange: (m) => jumpTo(new Date(yearInView, m, 1)),
270
+ orientation,
271
+ className: column
272
+ }, "month");
273
+ const yearColumn = /* @__PURE__ */ jsx(ScrollColumn, {
274
+ label: fieldLabel(locale, "year"),
275
+ options: years,
276
+ value: picked?.getFullYear() ?? null,
277
+ follow: yearInView,
278
+ inView: (y) => y === yearInView,
279
+ onValueChange: jumpToYear,
280
+ orientation,
281
+ className: column
282
+ }, "year");
283
+ const extras = extraColumns?.(orientation);
284
+ const before = [extraColumnsSide === "start" && extras, columnsSide === "start" && [yearColumn, monthColumn]];
285
+ const after = [columnsSide === "end" && [monthColumn, yearColumn], extraColumnsSide === "end" && extras];
286
+ const side = (place) => wide ? cn(dividedColumns, "h-full shrink-0 border-border", place === "start" ? "border-e" : "border-s") : "order-first flex w-full flex-col [&>*]:border-b [&>*]:border-border";
287
+ const grid = /* @__PURE__ */ jsxs("div", {
288
+ className: cn("flex min-h-0 shrink-0 flex-col", wide ? "h-full" : "flex-1 self-center"),
289
+ children: [
290
+ /* @__PURE__ */ jsx("div", {
291
+ "aria-hidden": true,
292
+ className: "flex border-b border-border px-1 pb-1",
293
+ children: weekdays.map((day) => /* @__PURE__ */ jsx("span", {
294
+ className: cn("flex items-center justify-center text-caption", sizeClasses.variant === "compact" ? "w-7" : "w-9", "text-muted-foreground"),
295
+ children: format2(day, "EEEEEE", { locale })
296
+ }, day.getDay()))
297
+ }),
298
+ /* @__PURE__ */ jsx("div", {
299
+ ref: scroll.scrollerRef,
300
+ onScroll: scroll.measure,
301
+ className: "relative min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1 scrollbar-hide scroll-fade [--scroll-fade-size:16px] [overflow-anchor:none]",
302
+ children: /* @__PURE__ */ jsx(DayPicker, {
303
+ ...props,
304
+ locale,
305
+ month: scroll.first,
306
+ numberOfMonths: scroll.count,
307
+ startMonth: start,
308
+ endMonth: end,
309
+ onMonthChange: scroll.recentre,
310
+ hideNavigation: true,
311
+ hideWeekdays: true,
312
+ showOutsideDays: false,
313
+ modifiers: { weekend: WEEKEND, preview, ...props.modifiers },
314
+ onDayMouseEnter: (date, modifiers, e) => {
315
+ setHovered(date);
316
+ props.onDayMouseEnter?.(date, modifiers, e);
317
+ },
318
+ onDayMouseLeave: (date, modifiers, e) => {
319
+ setHovered(undefined);
320
+ props.onDayMouseLeave?.(date, modifiers, e);
321
+ },
322
+ formatters: {
323
+ formatCaption: (month) => format2(month, isSameYear(month, today) ? "LLLL" : "LLLL y", { locale }),
324
+ ...props.formatters
325
+ },
326
+ components: { Month, Day, DayButton, ...props.components },
327
+ classNames: {
328
+ months: "flex flex-col",
329
+ month: "pb-2",
330
+ month_caption: cn("px-2 pt-2 pb-1 text-subtitle weight-semibold", sizeClasses.variant === "compact" && "text-subtitle-compact"),
331
+ month_grid: "border-collapse",
332
+ ...props.classNames
333
+ }
334
+ })
335
+ })
336
+ ]
337
+ });
338
+ const content = /* @__PURE__ */ jsxs("div", {
339
+ ref: rootRef,
340
+ dir: props.dir,
341
+ className: cn("flex w-max max-w-full overflow-hidden", wide ? "h-80 flex-row" : "h-[min(30rem,65dvh)] flex-col", className),
342
+ children: [
343
+ before.some(Boolean) ? /* @__PURE__ */ jsx("div", {
344
+ className: side("start"),
345
+ children: before
346
+ }) : null,
347
+ grid,
348
+ after.some(Boolean) ? /* @__PURE__ */ jsx("div", {
349
+ className: side("end"),
350
+ children: after
351
+ }) : null
352
+ ]
353
+ });
354
+ return size ? /* @__PURE__ */ jsx(SizeProvider, {
355
+ size,
356
+ children: content
357
+ }) : content;
358
+ }
359
+ var calendar_default = Calendar;
360
+
361
+ export { Calendar, calendar_default };