@zonsh/ui 0.2.0 → 0.4.1

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -0,0 +1,100 @@
1
+ import { Button as BaseButton } from "@base-ui/react/button";
2
+ import * as React from "react";
3
+ export interface LightboxMessages {
4
+ /** The viewer's accessible name. */
5
+ title: string;
6
+ close: string;
7
+ previous: string;
8
+ next: string;
9
+ zoomIn: string;
10
+ zoomOut: string;
11
+ download: string;
12
+ /** Said while the large image loads. */
13
+ loading: string;
14
+ /** "Image 3 of 12", read out on every change, before the image's alt text. */
15
+ position: (index: number, count: number) => string;
16
+ }
17
+ declare module "./locale" {
18
+ interface Messages {
19
+ lightbox: LightboxMessages;
20
+ }
21
+ }
22
+ export interface LightboxImage {
23
+ /** The large image. */
24
+ src: string;
25
+ /** What the image shows — its name in the grid and in the viewer. Required: describe it. */
26
+ alt: string;
27
+ /** A smaller file for the grid; the large one is loaded only when it is opened. */
28
+ thumbnail?: string;
29
+ /** A line or two under the image in the viewer. */
30
+ caption?: React.ReactNode;
31
+ /** The large image's `srcSet` and `sizes`, for screens of every density. */
32
+ srcSet?: string;
33
+ sizes?: string;
34
+ /** What Download saves — another file, the original say. Defaults to `src`. `false` hides it for this image. */
35
+ download?: string | false;
36
+ }
37
+ export interface LightboxProps {
38
+ /** The images, in order. */
39
+ images: LightboxImage[];
40
+ /** The image shown, 0-based. */
41
+ index?: number;
42
+ defaultIndex?: number;
43
+ onIndexChange?: (index: number) => void;
44
+ /** Whether the viewer is open. */
45
+ open?: boolean;
46
+ defaultOpen?: boolean;
47
+ onOpenChange?: (open: boolean) => void;
48
+ /** Next on the last image goes to the first, and back. */
49
+ loop?: boolean;
50
+ /** Show a Download button for each image (an image can opt out with `download: false`). */
51
+ download?: boolean;
52
+ /**
53
+ * Classes for the large image in the viewer: `invert` for black line art on a transparent
54
+ * ground, `bg-white` under a logo — either would otherwise vanish on the black.
55
+ */
56
+ imageClassName?: string;
57
+ /** Interface text; a LocaleProvider sets it for every Lightbox. */
58
+ labels?: Partial<LightboxMessages>;
59
+ /** The thumbnails: a `LightboxGrid`, or your own `LightboxTrigger`s. */
60
+ children?: React.ReactNode;
61
+ }
62
+ /**
63
+ * Lightbox — images opened large over the page, one at a time: the photos of a listing, the
64
+ * figures of an article, the attachments of a report.
65
+ *
66
+ * Thumbnails (`LightboxGrid`, or `LightboxTrigger`s around your own) open a full-screen viewer on
67
+ * a black ground in either theme, with a mono "03 / 12" counter, previous and next buttons, the
68
+ * arrow keys and a swipe, zoom by double click or tap, wheel or pinch with a drag to pan, a
69
+ * caption and an optional download. It is a modal Dialog: focus stays inside, Escape closes it,
70
+ * and focus returns to the thumbnail of the image last shown.
71
+ *
72
+ * The rule people break: an empty `alt`. Every image is named, in the grid and in the viewer.
73
+ */
74
+ export declare function Lightbox({ images, index: indexProp, defaultIndex, onIndexChange, open: openProp, defaultOpen, onOpenChange, loop, download, imageClassName, labels, children, }: LightboxProps): React.JSX.Element;
75
+ export interface LightboxTriggerProps extends BaseButton.Props {
76
+ /** The image it opens, 0-based. */
77
+ index: number;
78
+ }
79
+ /**
80
+ * Opens the viewer at one image. Put the thumbnail inside, with its `alt`: it names the button.
81
+ * Compose with `render` to draw it as something else.
82
+ */
83
+ export declare function LightboxTrigger({ index, className, onClick, ref, ...props }: LightboxTriggerProps): React.JSX.Element;
84
+ declare const gridColumns: {
85
+ readonly 2: "grid-cols-2";
86
+ readonly 3: "grid-cols-2 sm:grid-cols-3";
87
+ readonly 4: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4";
88
+ readonly 5: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5";
89
+ readonly 6: "grid-cols-3 sm:grid-cols-4 md:grid-cols-6";
90
+ };
91
+ export interface LightboxGridProps extends React.ComponentProps<"ul"> {
92
+ /** Columns at full width; fewer on a phone. */
93
+ columns?: keyof typeof gridColumns;
94
+ }
95
+ /**
96
+ * The thumbnails of every image as a grid of square buttons, each cropped to fill its square and
97
+ * edged with a `--field-edge` hairline at 12px.
98
+ */
99
+ export declare function LightboxGrid({ columns, className, ...props }: LightboxGridProps): React.JSX.Element;
100
+ export {};
@@ -0,0 +1,439 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Button as BaseButton } from "@base-ui/react/button";
4
+ import { Dialog as BaseDialog } from "@base-ui/react/dialog";
5
+ import { ChevronLeftIcon, ChevronRightIcon, DownloadIcon, XIcon, ZoomInIcon, ZoomOutIcon, } from "lucide-react";
6
+ import * as React from "react";
7
+ import { cn, sx } from "../lib/cn.js";
8
+ import { mergeRefs } from "../lib/merge-refs.js";
9
+ import { usePopupDir } from "./_overlay.js";
10
+ import { Button } from "./button.js";
11
+ import { useMessages } from "./locale.js";
12
+ import { Spinner } from "./spinner.js";
13
+ const defaultMessages = {
14
+ title: "Image viewer",
15
+ close: "Close",
16
+ previous: "Previous image",
17
+ next: "Next image",
18
+ zoomIn: "Zoom in",
19
+ zoomOut: "Zoom out",
20
+ download: "Download",
21
+ loading: "Loading image",
22
+ position: (index, count) => `Image ${index} of ${count}`,
23
+ };
24
+ const LightboxContext = React.createContext(null);
25
+ function useLightboxContext(part) {
26
+ const context = React.useContext(LightboxContext);
27
+ if (!context)
28
+ throw new Error(`${part} must be used within a <Lightbox />`);
29
+ return context;
30
+ }
31
+ /**
32
+ * Lightbox — images opened large over the page, one at a time: the photos of a listing, the
33
+ * figures of an article, the attachments of a report.
34
+ *
35
+ * Thumbnails (`LightboxGrid`, or `LightboxTrigger`s around your own) open a full-screen viewer on
36
+ * a black ground in either theme, with a mono "03 / 12" counter, previous and next buttons, the
37
+ * arrow keys and a swipe, zoom by double click or tap, wheel or pinch with a drag to pan, a
38
+ * caption and an optional download. It is a modal Dialog: focus stays inside, Escape closes it,
39
+ * and focus returns to the thumbnail of the image last shown.
40
+ *
41
+ * The rule people break: an empty `alt`. Every image is named, in the grid and in the viewer.
42
+ */
43
+ export function Lightbox({ images, index: indexProp, defaultIndex = 0, onIndexChange, open: openProp, defaultOpen = false, onOpenChange, loop = false, download = false, imageClassName, labels, children, }) {
44
+ const text = useMessages("lightbox", defaultMessages, labels);
45
+ const [ownIndex, setOwnIndex] = React.useState(defaultIndex);
46
+ const [ownOpen, setOwnOpen] = React.useState(defaultOpen);
47
+ const count = images.length;
48
+ const raw = indexProp ?? ownIndex;
49
+ const index = count ? Math.min(Math.max(Math.floor(raw) || 0, 0), count - 1) : 0;
50
+ const open = (openProp ?? ownOpen) && count > 0;
51
+ const triggers = React.useRef(new Map());
52
+ /** Whatever opened the viewer, if it was not one of the thumbnails. */
53
+ const opener = React.useRef(null);
54
+ const setIndex = React.useCallback((next) => {
55
+ if (indexProp === undefined)
56
+ setOwnIndex(next);
57
+ onIndexChange?.(next);
58
+ }, [indexProp, onIndexChange]);
59
+ const setOpen = React.useCallback((next) => {
60
+ if (openProp === undefined)
61
+ setOwnOpen(next);
62
+ onOpenChange?.(next);
63
+ }, [openProp, onOpenChange]);
64
+ const context = {
65
+ images,
66
+ index,
67
+ open,
68
+ loop,
69
+ download,
70
+ imageClassName,
71
+ text,
72
+ setIndex,
73
+ openAt: (at, from) => {
74
+ opener.current = from ?? document.activeElement;
75
+ if (at !== index)
76
+ setIndex(at);
77
+ setOpen(true);
78
+ },
79
+ close: () => setOpen(false),
80
+ registerTrigger: (at, el) => {
81
+ if (el)
82
+ triggers.current.set(at, el);
83
+ return () => {
84
+ if (triggers.current.get(at) === el)
85
+ triggers.current.delete(at);
86
+ };
87
+ },
88
+ triggerFor: (at) => {
89
+ const el = triggers.current.get(at);
90
+ return el?.isConnected ? el : opener.current?.isConnected ? opener.current : null;
91
+ },
92
+ };
93
+ return (_jsx(LightboxContext.Provider, { value: context, children: _jsxs(BaseDialog.Root, { open: open, onOpenChange: (next) => setOpen(next), children: [children, _jsx(LightboxViewer, {})] }) }));
94
+ }
95
+ /**
96
+ * Opens the viewer at one image. Put the thumbnail inside, with its `alt`: it names the button.
97
+ * Compose with `render` to draw it as something else.
98
+ */
99
+ export function LightboxTrigger({ index, className, onClick, ref, ...props }) {
100
+ const context = useLightboxContext("LightboxTrigger");
101
+ const own = React.useRef(null);
102
+ const { registerTrigger } = context;
103
+ React.useLayoutEffect(() => registerTrigger(index, own.current), [registerTrigger, index]);
104
+ const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
105
+ return (_jsx(BaseButton, { ref: refs, "data-slot": "lightbox-trigger", "aria-haspopup": "dialog", onClick: (event) => {
106
+ onClick?.(event);
107
+ if (!event.defaultPrevented)
108
+ context.openAt(index, event.currentTarget);
109
+ }, className: sx("cursor-zoom-in focus-ring", className), ...props }));
110
+ }
111
+ const gridColumns = {
112
+ 2: "grid-cols-2",
113
+ 3: "grid-cols-2 sm:grid-cols-3",
114
+ 4: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4",
115
+ 5: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5",
116
+ 6: "grid-cols-3 sm:grid-cols-4 md:grid-cols-6",
117
+ };
118
+ /**
119
+ * The thumbnails of every image as a grid of square buttons, each cropped to fill its square and
120
+ * edged with a `--field-edge` hairline at 12px.
121
+ */
122
+ export function LightboxGrid({ columns = 4, className, ...props }) {
123
+ const { images } = useLightboxContext("LightboxGrid");
124
+ return (_jsx("ul", { "data-slot": "lightbox-grid", className: cn("m-0 grid w-full list-none gap-2 p-0", gridColumns[columns], className), ...props, children: images.map((image, i) => (_jsx("li", { className: "min-w-0", children: _jsx(LightboxTrigger, { index: i, className: "group/thumb block w-full overflow-hidden rounded-button border border-field-edge bg-control-surface p-0", children: _jsx("img", { src: image.thumbnail ?? image.src, alt: image.alt, loading: "lazy", decoding: "async", draggable: false, className: "aspect-square w-full object-cover transition-[scale] duration-[calc(var(--duration)*2)] ease-(--ease) group-hover/thumb:scale-[1.03]" }) }) }, `${image.src}-${i}`))) }));
125
+ }
126
+ /* ── The viewer ────────────────────────────────────────────────────────────── */
127
+ /** The furthest zoom, and the one a double click goes to when the image is no larger than its place. */
128
+ const MAX_ZOOM = 4;
129
+ const STEP_ZOOM = 2;
130
+ /** A swipe that goes further than this, or flicks faster, turns the page. */
131
+ const SWIPE = 60;
132
+ const FLICK = 0.5;
133
+ /** Two taps this close in time and place are a double tap. */
134
+ const DOUBLE_TAP = 300;
135
+ const REST = { scale: 1, x: 0, y: 0 };
136
+ const pad = (n) => String(n).padStart(2, "0");
137
+ function LightboxViewer() {
138
+ const context = useLightboxContext("LightboxViewer");
139
+ const { images, index, open, loop, text, setIndex, close } = context;
140
+ const count = images.length;
141
+ const image = images[index];
142
+ const dir = usePopupDir();
143
+ const popupRef = React.useRef(null);
144
+ const frameRef = React.useRef(null);
145
+ const imgRef = React.useRef(null);
146
+ const [view, setViewState] = React.useState(REST);
147
+ const viewRef = React.useRef(view);
148
+ const setView = (next) => {
149
+ viewRef.current = next;
150
+ setViewState(next);
151
+ };
152
+ const [swipe, setSwipe] = React.useState(0);
153
+ const [gesturing, setGesturing] = React.useState(false);
154
+ const [loaded, setLoaded] = React.useState(false);
155
+ const canPrev = loop ? count > 1 : index > 0;
156
+ const canNext = loop ? count > 1 : index < count - 1;
157
+ const zoomed = view.scale > 1.01;
158
+ const go = (delta) => {
159
+ if (count < 2)
160
+ return;
161
+ let next = index + delta;
162
+ if (loop)
163
+ next = (next + count) % count;
164
+ else
165
+ next = Math.min(Math.max(next, 0), count - 1);
166
+ if (next !== index)
167
+ setIndex(next);
168
+ };
169
+ // A new image starts at rest; it is shown once it has loaded (at once from the cache).
170
+ React.useLayoutEffect(() => {
171
+ setView(REST);
172
+ setSwipe(0);
173
+ const img = imgRef.current;
174
+ setLoaded(!!img && img.complete && img.naturalWidth > 0);
175
+ }, [index, open]);
176
+ // The neighbours load in the background, so previous and next show at once.
177
+ React.useEffect(() => {
178
+ if (!open)
179
+ return;
180
+ for (const at of [index - 1, index + 1]) {
181
+ const neighbour = images[loop ? (at + count) % count : at];
182
+ if (neighbour) {
183
+ const pre = new Image();
184
+ if (neighbour.srcSet)
185
+ pre.srcset = neighbour.srcSet;
186
+ if (neighbour.sizes)
187
+ pre.sizes = neighbour.sizes;
188
+ pre.src = neighbour.src;
189
+ }
190
+ }
191
+ }, [open, index, images, loop, count]);
192
+ /** Keep a zoomed image over its place: no gap opens at an edge while there is more of it beyond. */
193
+ const clamp = (next) => {
194
+ const img = imgRef.current;
195
+ const frame = frameRef.current;
196
+ const scale = Math.min(Math.max(next.scale, 1), MAX_ZOOM);
197
+ if (!img || !frame || scale <= 1.01)
198
+ return REST;
199
+ const maxX = Math.max(0, (img.offsetWidth * scale - frame.clientWidth) / 2);
200
+ const maxY = Math.max(0, (img.offsetHeight * scale - frame.clientHeight) / 2);
201
+ return {
202
+ scale,
203
+ x: Math.min(Math.max(next.x, -maxX), maxX),
204
+ y: Math.min(Math.max(next.y, -maxY), maxY),
205
+ };
206
+ };
207
+ /** Zoom to `scale`, keeping the point under (clientX, clientY) — the middle by default — in place. */
208
+ const zoomTo = (scale, point, from = viewRef.current) => {
209
+ const frame = frameRef.current;
210
+ if (!frame)
211
+ return;
212
+ const rect = frame.getBoundingClientRect();
213
+ const cx = rect.left + rect.width / 2;
214
+ const cy = rect.top + rect.height / 2;
215
+ const dx = (point?.x ?? cx) - cx;
216
+ const dy = (point?.y ?? cy) - cy;
217
+ const next = Math.min(Math.max(scale, 1), MAX_ZOOM);
218
+ const k = next / from.scale;
219
+ setView(clamp({ scale: next, x: dx - k * (dx - from.x), y: dy - k * (dy - from.y) }));
220
+ };
221
+ /** A double click or tap: in to the image's own pixels (at least twice), or back out. */
222
+ const toggleZoom = (point) => {
223
+ if (viewRef.current.scale > 1.01)
224
+ return setView(REST);
225
+ const img = imgRef.current;
226
+ const natural = img && img.offsetWidth ? img.naturalWidth / img.offsetWidth : 1;
227
+ zoomTo(Math.min(Math.max(natural, STEP_ZOOM), MAX_ZOOM), point);
228
+ };
229
+ /* Gestures: one pointer pans a zoomed image or swipes to the next; two pinch. */
230
+ const pointers = React.useRef(new Map());
231
+ const gesture = React.useRef(null);
232
+ const lastTap = React.useRef(null);
233
+ const lastPointerType = React.useRef("mouse");
234
+ /** Whether the press began on the image, or on the black around it. */
235
+ const pressedImage = React.useRef(false);
236
+ /** A tap on the black closes the viewer on the click that follows it (see `onPointerUp`). */
237
+ const tapClose = React.useRef(false);
238
+ const rtl = () => (popupRef.current ? getComputedStyle(popupRef.current).direction === "rtl" : false);
239
+ const beginGesture = () => {
240
+ const points = [...pointers.current.values()];
241
+ const from = viewRef.current;
242
+ if (points.length >= 2) {
243
+ const [a, b] = points;
244
+ gesture.current = {
245
+ kind: "pinch",
246
+ startX: 0,
247
+ startY: 0,
248
+ time: performance.now(),
249
+ from,
250
+ distance: Math.hypot(a.x - b.x, a.y - b.y) || 1,
251
+ mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
252
+ moved: true,
253
+ };
254
+ }
255
+ else if (points.length === 1) {
256
+ const [p] = points;
257
+ gesture.current = {
258
+ kind: from.scale > 1.01 ? "pan" : "swipe",
259
+ startX: p.x,
260
+ startY: p.y,
261
+ time: performance.now(),
262
+ from,
263
+ distance: 0,
264
+ mid: p,
265
+ moved: gesture.current?.moved ?? false,
266
+ };
267
+ }
268
+ };
269
+ const onPointerDown = (event) => {
270
+ lastPointerType.current = event.pointerType;
271
+ if (event.pointerType === "mouse" && event.button !== 0)
272
+ return;
273
+ if (event.target.closest("button, a"))
274
+ return;
275
+ event.currentTarget.setPointerCapture(event.pointerId);
276
+ pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
277
+ if (pointers.current.size === 1) {
278
+ gesture.current = null;
279
+ pressedImage.current = event.target === imgRef.current;
280
+ tapClose.current = false;
281
+ }
282
+ beginGesture();
283
+ setGesturing(true);
284
+ };
285
+ const onPointerMove = (event) => {
286
+ if (!pointers.current.has(event.pointerId))
287
+ return;
288
+ pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY });
289
+ const g = gesture.current;
290
+ if (!g)
291
+ return;
292
+ if (g.kind === "pinch") {
293
+ const [a, b] = [...pointers.current.values()];
294
+ if (!a || !b)
295
+ return;
296
+ const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
297
+ const scale = g.from.scale * (Math.hypot(a.x - b.x, a.y - b.y) / g.distance);
298
+ // Zoom about where the fingers started, then follow them as they move together.
299
+ const moved = { ...g.from, x: g.from.x + mid.x - g.mid.x, y: g.from.y + mid.y - g.mid.y };
300
+ zoomTo(scale, mid, moved);
301
+ return;
302
+ }
303
+ const dx = event.clientX - g.startX;
304
+ const dy = event.clientY - g.startY;
305
+ if (Math.hypot(dx, dy) > 6)
306
+ g.moved = true;
307
+ if (g.kind === "pan") {
308
+ setView(clamp({ scale: g.from.scale, x: g.from.x + dx, y: g.from.y + dy }));
309
+ }
310
+ else {
311
+ // Past the first or last image the picture gives a little, and springs back.
312
+ const forward = rtl() ? dx > 0 : dx < 0;
313
+ setSwipe((forward ? canNext : canPrev) ? dx : dx * 0.3);
314
+ }
315
+ };
316
+ const onPointerUp = (event) => {
317
+ if (!pointers.current.has(event.pointerId))
318
+ return;
319
+ pointers.current.delete(event.pointerId);
320
+ const g = gesture.current;
321
+ if (pointers.current.size > 0) {
322
+ // One finger of a pinch lifted: the other pans on from here.
323
+ beginGesture();
324
+ return;
325
+ }
326
+ gesture.current = null;
327
+ setGesturing(false);
328
+ if (!g || event.type === "pointercancel") {
329
+ setSwipe(0);
330
+ return;
331
+ }
332
+ if (g.kind === "swipe") {
333
+ const dx = event.clientX - g.startX;
334
+ const speed = Math.abs(dx) / Math.max(performance.now() - g.time, 1);
335
+ setSwipe(0);
336
+ if (Math.abs(dx) > SWIPE || (Math.abs(dx) > 20 && speed > FLICK)) {
337
+ const forward = rtl() ? dx > 0 : dx < 0;
338
+ if (forward ? canNext : canPrev)
339
+ go(forward ? 1 : -1);
340
+ return;
341
+ }
342
+ }
343
+ if (g.moved)
344
+ return;
345
+ const point = { x: event.clientX, y: event.clientY };
346
+ if (event.pointerType === "touch") {
347
+ const tap = lastTap.current;
348
+ if (tap &&
349
+ event.timeStamp - tap.time < DOUBLE_TAP &&
350
+ Math.hypot(tap.x - point.x, tap.y - point.y) < 30) {
351
+ lastTap.current = null;
352
+ toggleZoom(point);
353
+ }
354
+ else if (!pressedImage.current && viewRef.current.scale <= 1.01) {
355
+ // A tap on the black closes the viewer, as a click there does: at once, since a double
356
+ // tap zooms only on the image (or out of a zoomed one). It closes on the click the tap
357
+ // makes, not here, so that click lands on the viewer and not on what is under it.
358
+ lastTap.current = null;
359
+ tapClose.current = true;
360
+ }
361
+ else
362
+ lastTap.current = { time: event.timeStamp, ...point };
363
+ return;
364
+ }
365
+ // A click on the black around the image closes the viewer, as a click outside a dialog would.
366
+ if (!pressedImage.current && viewRef.current.scale <= 1.01)
367
+ close();
368
+ };
369
+ // Wheel and trackpad pinch zoom (a pinch arrives as a wheel with Ctrl). Not passive: the page
370
+ // must not scroll or zoom under the viewer.
371
+ React.useEffect(() => {
372
+ const frame = frameRef.current;
373
+ if (!open || !frame)
374
+ return;
375
+ const onWheel = (event) => {
376
+ event.preventDefault();
377
+ const factor = Math.exp(-event.deltaY * (event.ctrlKey ? 0.01 : 0.002));
378
+ zoomTo(viewRef.current.scale * factor, { x: event.clientX, y: event.clientY });
379
+ };
380
+ frame.addEventListener("wheel", onWheel, { passive: false });
381
+ return () => frame.removeEventListener("wheel", onWheel);
382
+ // eslint-disable-next-line react-hooks/exhaustive-deps
383
+ }, [open, index]);
384
+ const onKeyDown = (event) => {
385
+ if (event.altKey || event.ctrlKey || event.metaKey)
386
+ return;
387
+ const back = rtl() ? "ArrowRight" : "ArrowLeft";
388
+ const forward = rtl() ? "ArrowLeft" : "ArrowRight";
389
+ switch (event.key) {
390
+ case back:
391
+ go(-1);
392
+ break;
393
+ case forward:
394
+ go(1);
395
+ break;
396
+ case "Home":
397
+ if (index !== 0)
398
+ setIndex(0);
399
+ break;
400
+ case "End":
401
+ if (index !== count - 1)
402
+ setIndex(count - 1);
403
+ break;
404
+ case "+":
405
+ case "=":
406
+ zoomTo(viewRef.current.scale * 1.5);
407
+ break;
408
+ case "-":
409
+ zoomTo(viewRef.current.scale / 1.5);
410
+ break;
411
+ case "0":
412
+ setView(REST);
413
+ break;
414
+ default:
415
+ return;
416
+ }
417
+ event.preventDefault();
418
+ };
419
+ if (!image)
420
+ return null;
421
+ const downloadHref = context.download && image.download !== false ? (image.download ?? image.src) : null;
422
+ const fileName = downloadHref
423
+ ? decodeURIComponent(downloadHref.split(/[?#]/)[0].split("/").pop() || "")
424
+ : "";
425
+ return (_jsxs(BaseDialog.Portal, { children: [_jsx(BaseDialog.Backdrop, { "data-slot": "lightbox-backdrop", className: "fixed inset-0 z-50 min-h-dvh bg-black transition-opacity duration-(--duration) ease-(--ease) data-ending-style:opacity-0 data-starting-style:opacity-0" }), _jsxs(BaseDialog.Popup, { ref: popupRef, "data-slot": "lightbox-content", dir: dir, initialFocus: popupRef, finalFocus: () => context.triggerFor(index) ?? true, onKeyDown: onKeyDown, className: cn(
426
+ // Dark tokens in either theme: the controls sit on the black ground like a video's.
427
+ "theme-dark fixed inset-0 z-50 flex flex-col bg-transparent font-body text-foreground outline-none",
428
+ // The controls and the image stay clear of the notch, the status bar and the home
429
+ // indicator; the black ground behind still fills the screen.
430
+ "pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)] pb-[env(safe-area-inset-bottom,0px)] pl-[env(safe-area-inset-left,0px)]", "transition-opacity duration-(--duration) ease-(--ease) data-ending-style:opacity-0 data-starting-style:opacity-0"), children: [_jsx(BaseDialog.Title, { className: "sr-only", children: text.title }), _jsxs("div", { "data-slot": "lightbox-header", className: "relative z-10 flex shrink-0 items-center gap-1 px-3 pt-3 sm:px-5 sm:pt-4", children: [_jsxs("div", { "data-slot": "lightbox-counter", dir: "ltr", "aria-hidden": true, className: "ps-2 font-mono text-[13px] leading-none text-muted-foreground tabular-nums", children: [_jsx("span", { className: "text-foreground", children: pad(index + 1) }), " / ", pad(count)] }), _jsxs("div", { className: "ms-auto flex items-center gap-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "lightbox-zoom", "aria-label": zoomed ? text.zoomOut : text.zoomIn, disabled: !loaded, onClick: () => (zoomed ? setView(REST) : toggleZoom()), children: zoomed ? _jsx(ZoomOutIcon, {}) : _jsx(ZoomInIcon, {}) }), downloadHref && (_jsx(Button, { variant: "ghost", size: "icon", "data-slot": "lightbox-download", "aria-label": text.download, nativeButton: false, render: _jsx("a", { href: downloadHref, download: fileName || true }), children: _jsx(DownloadIcon, {}) })), _jsx(BaseDialog.Close, { "data-slot": "lightbox-close", "aria-label": text.close, render: _jsx(Button, { variant: "ghost", size: "icon" }), children: _jsx(XIcon, {}) })] })] }), _jsxs("div", { ref: frameRef, "data-slot": "lightbox-stage", "data-zoomed": zoomed ? "" : undefined, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: onPointerUp, onClick: () => {
431
+ if (!tapClose.current)
432
+ return;
433
+ tapClose.current = false;
434
+ close();
435
+ }, onDoubleClick: (event) => {
436
+ if (lastPointerType.current !== "touch")
437
+ toggleZoom({ x: event.clientX, y: event.clientY });
438
+ }, className: cn("relative flex min-h-0 flex-1 touch-none items-center justify-center overflow-hidden px-4 py-3 select-none sm:px-20", zoomed && (gesturing ? "cursor-grabbing" : "cursor-grab")), children: [!loaded && (_jsx(Spinner, { label: text.loading, className: "absolute top-1/2 left-1/2 -translate-1/2 text-muted-foreground" })), _jsx("img", { ref: imgRef, "data-slot": "lightbox-image", src: image.src, srcSet: image.srcSet, sizes: image.sizes, alt: image.alt, draggable: false, onLoad: () => setLoaded(true), onError: () => setLoaded(true), style: { transform: `translate(${view.x + swipe}px, ${view.y}px) scale(${view.scale})` }, className: cn("max-h-full max-w-full object-contain", !zoomed && "cursor-zoom-in", "transition-[opacity,transform] duration-(--duration) ease-(--ease) will-change-transform", gesturing && "transition-none", loaded ? "opacity-100" : "opacity-0", context.imageClassName) }, index), count > 1 && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "secondary", size: "icon", "data-slot": "lightbox-previous", "aria-label": text.previous, disabled: !canPrev, focusableWhenDisabled: true, onClick: () => go(-1), className: "absolute start-3 top-1/2 z-10 -translate-y-1/2 sm:start-5", children: _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }) }), _jsx(Button, { variant: "secondary", size: "icon", "data-slot": "lightbox-next", "aria-label": text.next, disabled: !canNext, focusableWhenDisabled: true, onClick: () => go(1), className: "absolute end-3 top-1/2 z-10 -translate-y-1/2 sm:end-5", children: _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }) })] }))] }), _jsx("div", { "data-slot": "lightbox-caption", className: "relative z-10 mx-auto min-h-14 w-full max-w-2xl shrink-0 px-6 pt-2 pb-5 text-center text-[15px] leading-relaxed text-pretty text-foreground-soft", children: image.caption }), _jsx("div", { "data-slot": "lightbox-status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: open ? `${text.position(index + 1, count)}${image.alt ? `: ${image.alt}` : ""}` : "" })] })] }));
439
+ }
@@ -0,0 +1,44 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Every component's interface text, by component. Each component adds its own entry next to its
4
+ * code (declaration merging), with its English defaults there too:
5
+ *
6
+ * declare module "./locale" {
7
+ * interface Messages { pagination: PaginationMessages }
8
+ * }
9
+ *
10
+ * so `LocaleProvider messages` is typed for every component in the library.
11
+ */
12
+ export interface Messages {
13
+ }
14
+ /** Messages for some components, and some strings of each: what is left out stays English. */
15
+ export type PartialMessages = {
16
+ [K in keyof Messages]?: Partial<Messages[K]>;
17
+ };
18
+ export interface LocaleProviderProps {
19
+ /**
20
+ * A BCP 47 language tag ("de-DE", "ar-EG"). Numbers, dates, times and sizes inside are
21
+ * formatted for it; without one, components use the browser's language.
22
+ */
23
+ locale?: string;
24
+ /** The interface text to replace, by component; nested providers merge into the outer one. */
25
+ messages?: PartialMessages;
26
+ children?: React.ReactNode;
27
+ }
28
+ /**
29
+ * LocaleProvider — the language of every component inside it: the interface text people read
30
+ * and hear ("Previous page", "Copied", "No results") and the locale numbers and dates are
31
+ * formatted in.
32
+ *
33
+ * Wrap the app once. A component's own `labels` prop still wins over the provider, for the one
34
+ * place that needs other words. The rule people break: translating the visible text and leaving
35
+ * the accessible names English — they come from here too, so pass the whole message set.
36
+ */
37
+ export declare function LocaleProvider({ locale, messages, children }: LocaleProviderProps): React.JSX.Element;
38
+ /** The locale set by the nearest LocaleProvider, or undefined for the browser's own. */
39
+ export declare function useLocale(): string | undefined;
40
+ /**
41
+ * A component's interface text: its English `defaults`, then what a LocaleProvider sets for it,
42
+ * then the component's own `labels` prop.
43
+ */
44
+ export declare function useMessages<K extends keyof Messages>(key: K, defaults: Messages[K], labels?: Partial<Messages[K]>): Messages[K];
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ const LocaleContext = React.createContext({ locale: undefined, messages: {} });
5
+ /**
6
+ * LocaleProvider — the language of every component inside it: the interface text people read
7
+ * and hear ("Previous page", "Copied", "No results") and the locale numbers and dates are
8
+ * formatted in.
9
+ *
10
+ * Wrap the app once. A component's own `labels` prop still wins over the provider, for the one
11
+ * place that needs other words. The rule people break: translating the visible text and leaving
12
+ * the accessible names English — they come from here too, so pass the whole message set.
13
+ */
14
+ export function LocaleProvider({ locale, messages, children }) {
15
+ const outer = React.useContext(LocaleContext);
16
+ const value = React.useMemo(() => {
17
+ if (!messages)
18
+ return { locale: locale ?? outer.locale, messages: outer.messages };
19
+ const merged = { ...outer.messages };
20
+ for (const [key, entry] of Object.entries(messages))
21
+ merged[key] = { ...merged[key], ...entry };
22
+ return { locale: locale ?? outer.locale, messages: merged };
23
+ }, [locale, messages, outer]);
24
+ return _jsx(LocaleContext.Provider, { value: value, children: children });
25
+ }
26
+ /** The locale set by the nearest LocaleProvider, or undefined for the browser's own. */
27
+ export function useLocale() {
28
+ return React.useContext(LocaleContext).locale;
29
+ }
30
+ /**
31
+ * A component's interface text: its English `defaults`, then what a LocaleProvider sets for it,
32
+ * then the component's own `labels` prop.
33
+ */
34
+ export function useMessages(key, defaults, labels) {
35
+ const fromProvider = React.useContext(LocaleContext).messages[key];
36
+ return React.useMemo(() => (fromProvider || labels ? { ...defaults, ...fromProvider, ...labels } : defaults), [defaults, fromProvider, labels]);
37
+ }
@@ -63,7 +63,7 @@ export function LogoRight({ size = 24, ...props }) {
63
63
  export function Logo({ variant = "default", size = 20, product, open = false, render, ref, className, style, ...props }) {
64
64
  const compact = variant === "compact";
65
65
  const vars = { "--logo-gap": `${px(size * GAP)}px`, ...style };
66
- const reveal = "duration-(--duration-reveal) ease-(--ease) motion-reduce:transition-none";
66
+ const reveal = "duration-[calc(var(--duration)*1.6)] ease-(--ease) motion-reduce:transition-none";
67
67
  const children = (_jsxs(_Fragment, { children: [_jsx(LogoMark, { size: size }), _jsx("span", { "data-slot": "logo-wordmark-track", className: cn("grid", compact
68
68
  ? [
69
69
  "grid-cols-[0fr] transition-[grid-template-columns,padding]",
@@ -8,6 +8,7 @@ import { mergeRefs } from "../lib/merge-refs.js";
8
8
  import { formatShortcut, useShortcutKeys } from "../lib/platform.js";
9
9
  import { TriggerRoomContext, useTriggerRoom } from "../lib/room.js";
10
10
  import { MenuFrame } from "./_overlay.js";
11
+ import { useKeyNames } from "./kbd.js";
11
12
  /**
12
13
  * Menu — a list of actions opened from a button: "Rename", "Duplicate", "Delete project".
13
14
  * Menu material at 12px, items at 7px and 38px tall, the highlighted item raised like `SelectItem`.
@@ -116,11 +117,12 @@ export function MenuSeparator({ className, ...props }) {
116
117
  }
117
118
  export function MenuShortcut({ keys, className, children, ...props }) {
118
119
  const { mod, hasKeyboard } = useShortcutKeys();
120
+ const names = useKeyNames();
119
121
  if (keys && !hasKeyboard)
120
122
  return null;
121
123
  return (_jsx("span", { "data-slot": "menu-shortcut", "aria-hidden": true, className: cn(
122
124
  // Its own text decides its direction: ⌘D stays ⌘D in a right-to-left menu.
123
- "ms-auto ps-4 font-mono text-xs tracking-normal whitespace-nowrap text-muted-foreground [unicode-bidi:plaintext]", className), ...props, children: keys ? formatShortcut(keys, mod) : children }));
125
+ "ms-auto ps-4 font-mono text-xs tracking-normal whitespace-nowrap text-muted-foreground [unicode-bidi:plaintext]", className), ...props, children: keys ? formatShortcut(keys, mod, names) : children }));
124
126
  }
125
127
  /* ── Submenus ──────────────────────────────────────────────────────────────── */
126
128
  /** A nested menu. Holds a `MenuSubTrigger` and a `MenuSubContent`. */