@nucleux/visual-input 0.0.0-stage → 0.6.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.
@@ -0,0 +1,85 @@
1
+ import * as React from 'react';
2
+
3
+ type VisualInputVariant = "drag-drop" | "paste-chip" | "camera-capture";
4
+ /** Where a visual can come from. Only the sources you list are offered. */
5
+ type VisualInputSource = "upload" | "paste" | "camera";
6
+ /** Per-file state, set by the app while it reads or uploads the visual. */
7
+ type VisualInputFileStatus = "ready" | "reading" | "error";
8
+ interface VisualInputFile {
9
+ /** Stable id, generated when the file is added. */
10
+ id: string;
11
+ /** The underlying file. */
12
+ file: File;
13
+ /** Object URL used for the thumbnail (images only, browser only). */
14
+ previewUrl?: string;
15
+ /** How the file arrived. */
16
+ source?: VisualInputSource;
17
+ /** `"reading"` shows a quiet working treatment; `"error"` shows `error` in the destructive tone. */
18
+ status?: VisualInputFileStatus;
19
+ /** Message shown when `status` is `"error"`, e.g. `"Couldn't read this image."`. */
20
+ error?: string;
21
+ }
22
+ type VisualInputRejectionReason = "type" | "size" | "count";
23
+ interface VisualInputRejection {
24
+ file: File;
25
+ reason: VisualInputRejectionReason;
26
+ /** The human-readable message shown in the error list. */
27
+ message: string;
28
+ }
29
+ interface VisualInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> {
30
+ /** `"drag-drop"` (default) dashed drop zone, `"paste-chip"` chips above a composer, `"camera-capture"` viewfinder with a shutter. */
31
+ variant?: VisualInputVariant;
32
+ /** Sources offered. Defaults to upload + paste (+ camera for `"camera-capture"`). */
33
+ sources?: VisualInputSource[];
34
+ /** Accepted types, in `<input accept>` syntax. Defaults to `"image/*"`. */
35
+ accept?: string;
36
+ /** Largest accepted file in bytes. Defaults to 20 MB. */
37
+ maxSize?: number;
38
+ /** Most files held at once. Defaults to 4 (1 for `"camera-capture"`). */
39
+ maxFiles?: number;
40
+ /** Allow more than one file. Defaults to `true` except for `"camera-capture"`. */
41
+ multiple?: boolean;
42
+ /** Which camera `capture` asks for on mobile. Defaults to `"environment"`. */
43
+ capture?: "user" | "environment";
44
+ /** The attached files (controlled). */
45
+ files?: VisualInputFile[];
46
+ /** Initial files (uncontrolled). */
47
+ defaultFiles?: VisualInputFile[];
48
+ /** Called with the next list whenever files are added or removed. Nothing is ever sent. */
49
+ onFilesChange?: (files: VisualInputFile[]) => void;
50
+ /** Called with files that were refused (wrong type, too large, too many). */
51
+ onReject?: (rejections: VisualInputRejection[]) => void;
52
+ /** Main line of the drop zone. */
53
+ label?: React.ReactNode;
54
+ /** Secondary line, e.g. `"PNG, JPG, PDF · up to 20 MB"`. Derived from `accept`/`maxSize` when omitted. */
55
+ hint?: React.ReactNode;
56
+ /** Accessible name of the whole region. Defaults to `"Image input"`. */
57
+ regionLabel?: string;
58
+ /** Line shown once something is attached, e.g. `"Aria will see this when you send"`. */
59
+ seeText?: React.ReactNode;
60
+ /** Explains camera access before anything is captured (camera variant). */
61
+ cameraText?: React.ReactNode;
62
+ /** Says what can be used when a type is refused, e.g. `"Aria can read PNG, JPG and HEIC."`. */
63
+ unsupportedText?: string;
64
+ /** Label of the browse button. */
65
+ browseLabel?: string;
66
+ /** Label of the camera button. */
67
+ cameraLabel?: string;
68
+ /** Disable every source. */
69
+ disabled?: boolean;
70
+ /** Slot rendered under the previews — typically the composer the visual is paired with. */
71
+ children?: React.ReactNode;
72
+ }
73
+ /** Whether `file` matches an `<input accept>` string. */
74
+ declare function fileMatchesAccept(file: File, accept: string): boolean;
75
+ /**
76
+ * Visual input: lets people add images, screenshots or photos as context to their
77
+ * ask — drag-and-drop, paste from the clipboard, browse, or camera capture
78
+ * (`<input capture>`). Each visual lands as a removable chip with a real preview,
79
+ * type/size/count limits are checked with plain-language errors in a live region,
80
+ * and nothing is ever sent: the app pairs the files with the text prompt and
81
+ * sends on the person's command. Variants: drag-drop, paste-chip, camera-capture.
82
+ */
83
+ declare const VisualInput: React.ForwardRefExoticComponent<VisualInputProps & React.RefAttributes<HTMLDivElement>>;
84
+
85
+ export { VisualInput, type VisualInputFile, type VisualInputFileStatus, type VisualInputProps, type VisualInputRejection, type VisualInputRejectionReason, type VisualInputSource, type VisualInputVariant, fileMatchesAccept };
@@ -0,0 +1,85 @@
1
+ import * as React from 'react';
2
+
3
+ type VisualInputVariant = "drag-drop" | "paste-chip" | "camera-capture";
4
+ /** Where a visual can come from. Only the sources you list are offered. */
5
+ type VisualInputSource = "upload" | "paste" | "camera";
6
+ /** Per-file state, set by the app while it reads or uploads the visual. */
7
+ type VisualInputFileStatus = "ready" | "reading" | "error";
8
+ interface VisualInputFile {
9
+ /** Stable id, generated when the file is added. */
10
+ id: string;
11
+ /** The underlying file. */
12
+ file: File;
13
+ /** Object URL used for the thumbnail (images only, browser only). */
14
+ previewUrl?: string;
15
+ /** How the file arrived. */
16
+ source?: VisualInputSource;
17
+ /** `"reading"` shows a quiet working treatment; `"error"` shows `error` in the destructive tone. */
18
+ status?: VisualInputFileStatus;
19
+ /** Message shown when `status` is `"error"`, e.g. `"Couldn't read this image."`. */
20
+ error?: string;
21
+ }
22
+ type VisualInputRejectionReason = "type" | "size" | "count";
23
+ interface VisualInputRejection {
24
+ file: File;
25
+ reason: VisualInputRejectionReason;
26
+ /** The human-readable message shown in the error list. */
27
+ message: string;
28
+ }
29
+ interface VisualInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> {
30
+ /** `"drag-drop"` (default) dashed drop zone, `"paste-chip"` chips above a composer, `"camera-capture"` viewfinder with a shutter. */
31
+ variant?: VisualInputVariant;
32
+ /** Sources offered. Defaults to upload + paste (+ camera for `"camera-capture"`). */
33
+ sources?: VisualInputSource[];
34
+ /** Accepted types, in `<input accept>` syntax. Defaults to `"image/*"`. */
35
+ accept?: string;
36
+ /** Largest accepted file in bytes. Defaults to 20 MB. */
37
+ maxSize?: number;
38
+ /** Most files held at once. Defaults to 4 (1 for `"camera-capture"`). */
39
+ maxFiles?: number;
40
+ /** Allow more than one file. Defaults to `true` except for `"camera-capture"`. */
41
+ multiple?: boolean;
42
+ /** Which camera `capture` asks for on mobile. Defaults to `"environment"`. */
43
+ capture?: "user" | "environment";
44
+ /** The attached files (controlled). */
45
+ files?: VisualInputFile[];
46
+ /** Initial files (uncontrolled). */
47
+ defaultFiles?: VisualInputFile[];
48
+ /** Called with the next list whenever files are added or removed. Nothing is ever sent. */
49
+ onFilesChange?: (files: VisualInputFile[]) => void;
50
+ /** Called with files that were refused (wrong type, too large, too many). */
51
+ onReject?: (rejections: VisualInputRejection[]) => void;
52
+ /** Main line of the drop zone. */
53
+ label?: React.ReactNode;
54
+ /** Secondary line, e.g. `"PNG, JPG, PDF · up to 20 MB"`. Derived from `accept`/`maxSize` when omitted. */
55
+ hint?: React.ReactNode;
56
+ /** Accessible name of the whole region. Defaults to `"Image input"`. */
57
+ regionLabel?: string;
58
+ /** Line shown once something is attached, e.g. `"Aria will see this when you send"`. */
59
+ seeText?: React.ReactNode;
60
+ /** Explains camera access before anything is captured (camera variant). */
61
+ cameraText?: React.ReactNode;
62
+ /** Says what can be used when a type is refused, e.g. `"Aria can read PNG, JPG and HEIC."`. */
63
+ unsupportedText?: string;
64
+ /** Label of the browse button. */
65
+ browseLabel?: string;
66
+ /** Label of the camera button. */
67
+ cameraLabel?: string;
68
+ /** Disable every source. */
69
+ disabled?: boolean;
70
+ /** Slot rendered under the previews — typically the composer the visual is paired with. */
71
+ children?: React.ReactNode;
72
+ }
73
+ /** Whether `file` matches an `<input accept>` string. */
74
+ declare function fileMatchesAccept(file: File, accept: string): boolean;
75
+ /**
76
+ * Visual input: lets people add images, screenshots or photos as context to their
77
+ * ask — drag-and-drop, paste from the clipboard, browse, or camera capture
78
+ * (`<input capture>`). Each visual lands as a removable chip with a real preview,
79
+ * type/size/count limits are checked with plain-language errors in a live region,
80
+ * and nothing is ever sent: the app pairs the files with the text prompt and
81
+ * sends on the person's command. Variants: drag-drop, paste-chip, camera-capture.
82
+ */
83
+ declare const VisualInput: React.ForwardRefExoticComponent<VisualInputProps & React.RefAttributes<HTMLDivElement>>;
84
+
85
+ export { VisualInput, type VisualInputFile, type VisualInputFileStatus, type VisualInputProps, type VisualInputRejection, type VisualInputRejectionReason, type VisualInputSource, type VisualInputVariant, fileMatchesAccept };
package/dist/index.js ADDED
@@ -0,0 +1,438 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { cn } from '@nucleux/utils';
4
+ import { Button } from '@nucleux/button';
5
+ import { AttachmentGroup, Attachment } from '@nucleux/attachment';
6
+ import { ImageIcon, AlertCircle, X, Paperclip, Camera, RotateCcw, Trash2, ImageUp } from 'lucide-react';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+
9
+ // src/index.tsx
10
+ var MB = 1024 * 1024;
11
+ function formatFileSize(bytes) {
12
+ if (bytes < 1024) return `${bytes} B`;
13
+ if (bytes < MB) return `${Math.round(bytes / 1024)} KB`;
14
+ const mb = bytes / MB;
15
+ return `${mb >= 10 ? Math.round(mb) : Math.round(mb * 10) / 10} MB`;
16
+ }
17
+ function fileMatchesAccept(file, accept) {
18
+ const rules = accept.split(",").map((r) => r.trim().toLowerCase()).filter(Boolean);
19
+ if (rules.length === 0) return true;
20
+ const name = file.name.toLowerCase();
21
+ const type = (file.type || "").toLowerCase();
22
+ return rules.some((rule) => {
23
+ if (rule.startsWith(".")) return name.endsWith(rule);
24
+ if (rule.endsWith("/*")) return type.startsWith(rule.slice(0, -1));
25
+ return type === rule;
26
+ });
27
+ }
28
+ var fileCounter = 0;
29
+ var canPreview = () => typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
30
+ var VisualInput = React.forwardRef(
31
+ ({
32
+ variant = "drag-drop",
33
+ sources,
34
+ accept = "image/*",
35
+ maxSize = 20 * MB,
36
+ maxFiles,
37
+ multiple,
38
+ capture = "environment",
39
+ files: filesProp,
40
+ defaultFiles,
41
+ onFilesChange,
42
+ onReject,
43
+ label,
44
+ hint,
45
+ regionLabel = "Image input",
46
+ seeText = "Attached to your next message \u2014 nothing is sent until you send.",
47
+ cameraText,
48
+ unsupportedText,
49
+ browseLabel = "Browse files",
50
+ cameraLabel = "Take photo",
51
+ disabled = false,
52
+ className,
53
+ children,
54
+ onPaste,
55
+ onDragEnter,
56
+ onDragOver,
57
+ onDragLeave,
58
+ onDrop,
59
+ ...props
60
+ }, ref) => {
61
+ const isCamera = variant === "camera-capture";
62
+ const allowed = sources ?? (isCamera ? ["camera", "upload"] : ["upload", "paste"]);
63
+ const canUpload = allowed.includes("upload");
64
+ const canPaste = allowed.includes("paste");
65
+ const canCamera = allowed.includes("camera");
66
+ const isMultiple = multiple ?? !isCamera;
67
+ const limit = isMultiple ? maxFiles ?? 4 : 1;
68
+ const [internal, setInternal] = React.useState(defaultFiles ?? []);
69
+ const files = filesProp ?? internal;
70
+ const [errors, setErrors] = React.useState([]);
71
+ const [announcement, setAnnouncement] = React.useState("");
72
+ const [dragging, setDragging] = React.useState(false);
73
+ const dragDepth = React.useRef(0);
74
+ const uploadRef = React.useRef(null);
75
+ const cameraRef = React.useRef(null);
76
+ const rootRef = React.useRef(null);
77
+ const created = React.useRef(/* @__PURE__ */ new Set());
78
+ const errorsId = React.useId();
79
+ React.useEffect(() => {
80
+ const live = new Set(files.map((f) => f.previewUrl));
81
+ created.current.forEach((url) => {
82
+ if (!live.has(url)) {
83
+ URL.revokeObjectURL(url);
84
+ created.current.delete(url);
85
+ }
86
+ });
87
+ }, [files]);
88
+ React.useEffect(
89
+ () => () => {
90
+ created.current.forEach((url) => URL.revokeObjectURL(url));
91
+ created.current.clear();
92
+ },
93
+ []
94
+ );
95
+ const commit = (next) => {
96
+ if (filesProp === void 0) setInternal(next);
97
+ onFilesChange?.(next);
98
+ };
99
+ const describeRejection = (file, reason) => {
100
+ if (reason === "type")
101
+ return `${file.name} can\u2019t be attached. ${unsupportedText ?? "Choose an image file instead."}`;
102
+ if (reason === "size") return `${file.name} is larger than ${formatFileSize(maxSize)}.`;
103
+ return `Only ${limit} ${limit === 1 ? "file" : "files"} can be attached \u2014 ${file.name} was left out.`;
104
+ };
105
+ const addFiles = (list, source) => {
106
+ if (disabled || list.length === 0) return;
107
+ const rejected = [];
108
+ const accepted = [];
109
+ const room = isMultiple ? limit - files.length : 1;
110
+ for (const file of list) {
111
+ let reason = null;
112
+ if (!fileMatchesAccept(file, accept)) reason = "type";
113
+ else if (file.size > maxSize) reason = "size";
114
+ else if (accepted.length >= room) reason = "count";
115
+ if (reason) {
116
+ rejected.push({ file, reason, message: describeRejection(file, reason) });
117
+ continue;
118
+ }
119
+ let previewUrl;
120
+ if (file.type.startsWith("image/") && canPreview()) {
121
+ previewUrl = URL.createObjectURL(file);
122
+ created.current.add(previewUrl);
123
+ }
124
+ fileCounter += 1;
125
+ accepted.push({ id: `nx-visual-${fileCounter}`, file, previewUrl, source, status: "ready" });
126
+ }
127
+ setErrors(rejected);
128
+ if (rejected.length) onReject?.(rejected);
129
+ if (accepted.length) {
130
+ commit(isMultiple ? [...files, ...accepted] : accepted);
131
+ setAnnouncement(`${accepted.map((f) => f.file.name).join(", ")} attached.`);
132
+ }
133
+ };
134
+ const removeFile = (id) => {
135
+ const target = files.find((f) => f.id === id);
136
+ commit(files.filter((f) => f.id !== id));
137
+ if (target) setAnnouncement(`${target.file.name} removed.`);
138
+ requestAnimationFrame(() => {
139
+ const root = rootRef.current;
140
+ const next = root?.querySelector("[data-visual-input-focus]") ?? root;
141
+ next?.focus();
142
+ });
143
+ };
144
+ const openUpload = () => !disabled && uploadRef.current?.click();
145
+ const openCamera = () => !disabled && cameraRef.current?.click();
146
+ const onInputChange = (source) => (e) => {
147
+ addFiles(Array.from(e.target.files ?? []), source);
148
+ e.target.value = "";
149
+ };
150
+ const hasFiles = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
151
+ const dropHandlers = canUpload ? {
152
+ onDragEnter: (e) => {
153
+ onDragEnter?.(e);
154
+ if (disabled || !hasFiles(e)) return;
155
+ e.preventDefault();
156
+ dragDepth.current += 1;
157
+ setDragging(true);
158
+ },
159
+ onDragOver: (e) => {
160
+ onDragOver?.(e);
161
+ if (disabled || !hasFiles(e)) return;
162
+ e.preventDefault();
163
+ e.dataTransfer.dropEffect = "copy";
164
+ },
165
+ onDragLeave: (e) => {
166
+ onDragLeave?.(e);
167
+ dragDepth.current = Math.max(0, dragDepth.current - 1);
168
+ if (dragDepth.current === 0) setDragging(false);
169
+ },
170
+ onDrop: (e) => {
171
+ onDrop?.(e);
172
+ dragDepth.current = 0;
173
+ setDragging(false);
174
+ if (disabled) return;
175
+ e.preventDefault();
176
+ addFiles(Array.from(e.dataTransfer?.files ?? []), "upload");
177
+ }
178
+ } : { onDragEnter, onDragOver, onDragLeave, onDrop };
179
+ const handlePaste = (e) => {
180
+ onPaste?.(e);
181
+ if (e.defaultPrevented || !canPaste || disabled) return;
182
+ const pasted = Array.from(e.clipboardData?.files ?? []);
183
+ if (pasted.length === 0) return;
184
+ e.preventDefault();
185
+ addFiles(pasted, "paste");
186
+ };
187
+ const hintText = hint ?? `${accept === "image/*" ? "Images" : accept.replace(/,/g, ", ")} \xB7 up to ${formatFileSize(maxSize)}`;
188
+ const chips = files.length > 0 && /* @__PURE__ */ jsx(AttachmentGroup, { role: "list", "aria-label": "Attached visuals", children: files.map((f) => /* @__PURE__ */ jsx("div", { role: "listitem", children: /* @__PURE__ */ jsx(
189
+ Attachment,
190
+ {
191
+ name: f.file.name,
192
+ meta: f.status === "error" ? /* @__PURE__ */ jsx("span", { className: "text-destructive", children: f.error ?? "Couldn\u2019t use this file." }) : f.status === "reading" ? "Reading\u2026" : formatFileSize(f.file.size),
193
+ icon: f.previewUrl ? /* @__PURE__ */ jsx("img", { src: f.previewUrl, alt: "", className: "size-full rounded-md object-cover" }) : /* @__PURE__ */ jsx(ImageIcon, { "aria-hidden": "true" }),
194
+ onRemove: () => removeFile(f.id),
195
+ "data-status": f.status ?? "ready",
196
+ className: cn(
197
+ variant === "paste-chip" && "rounded-full py-1 pl-1",
198
+ f.status === "error" && "border-destructive/60",
199
+ f.status === "reading" && "animate-pulse motion-reduce:animate-none"
200
+ )
201
+ }
202
+ ) }, f.id)) });
203
+ const status = /* @__PURE__ */ jsxs(Fragment, { children: [
204
+ files.length > 0 && seeText && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: seeText }),
205
+ errors.length > 0 && /* @__PURE__ */ jsxs(
206
+ "div",
207
+ {
208
+ id: errorsId,
209
+ role: "alert",
210
+ className: "flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",
211
+ children: [
212
+ /* @__PURE__ */ jsx(AlertCircle, { className: "mt-0.5 size-4 shrink-0", "aria-hidden": "true" }),
213
+ /* @__PURE__ */ jsx("ul", { className: "flex-1 space-y-0.5", children: errors.map((err, i) => /* @__PURE__ */ jsx("li", { children: err.message }, i)) }),
214
+ /* @__PURE__ */ jsx(
215
+ "button",
216
+ {
217
+ type: "button",
218
+ "aria-label": "Dismiss errors",
219
+ onClick: () => setErrors([]),
220
+ className: "inline-flex size-5 shrink-0 items-center justify-center rounded-full transition-colors hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5",
221
+ children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true" })
222
+ }
223
+ )
224
+ ]
225
+ }
226
+ ),
227
+ /* @__PURE__ */ jsx("p", { role: "status", "aria-live": "polite", className: "sr-only", children: announcement })
228
+ ] });
229
+ const hiddenInputs = /* @__PURE__ */ jsxs(Fragment, { children: [
230
+ canUpload && /* @__PURE__ */ jsx(
231
+ "input",
232
+ {
233
+ ref: uploadRef,
234
+ type: "file",
235
+ accept,
236
+ multiple: isMultiple,
237
+ hidden: true,
238
+ tabIndex: -1,
239
+ disabled,
240
+ onChange: onInputChange("upload")
241
+ }
242
+ ),
243
+ canCamera && /* @__PURE__ */ jsx(
244
+ "input",
245
+ {
246
+ ref: cameraRef,
247
+ type: "file",
248
+ accept: accept.includes("image") ? "image/*" : accept,
249
+ capture,
250
+ hidden: true,
251
+ tabIndex: -1,
252
+ disabled,
253
+ onChange: onInputChange("camera")
254
+ }
255
+ )
256
+ ] });
257
+ const setRoot = (node) => {
258
+ rootRef.current = node;
259
+ if (typeof ref === "function") ref(node);
260
+ else if (ref) ref.current = node;
261
+ };
262
+ const rootProps = {
263
+ ref: setRoot,
264
+ role: "group",
265
+ "aria-label": regionLabel,
266
+ "aria-disabled": disabled || void 0,
267
+ "data-variant": variant,
268
+ "data-dragging": dragging || void 0,
269
+ tabIndex: -1,
270
+ onPaste: handlePaste,
271
+ ...dropHandlers,
272
+ ...props
273
+ };
274
+ if (variant === "paste-chip") {
275
+ return /* @__PURE__ */ jsxs("div", { ...rootProps, className: cn("flex flex-col gap-2 outline-none", className), children: [
276
+ chips,
277
+ children,
278
+ /* @__PURE__ */ jsxs(
279
+ "div",
280
+ {
281
+ className: cn(
282
+ "flex items-center gap-1 rounded-lg text-xs text-muted-foreground transition-colors",
283
+ dragging && "bg-brand-muted/50 text-foreground ring-2 ring-brand"
284
+ ),
285
+ children: [
286
+ canUpload && /* @__PURE__ */ jsx(
287
+ Button,
288
+ {
289
+ variant: "ghost",
290
+ size: "icon-sm",
291
+ "aria-label": "Attach image",
292
+ onClick: openUpload,
293
+ disabled,
294
+ "data-visual-input-focus": "",
295
+ children: /* @__PURE__ */ jsx(Paperclip, { className: "size-4", "aria-hidden": "true" })
296
+ }
297
+ ),
298
+ canCamera && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": cameraLabel, onClick: openCamera, disabled, children: /* @__PURE__ */ jsx(Camera, { className: "size-4", "aria-hidden": "true" }) }),
299
+ /* @__PURE__ */ jsx("span", { children: label ?? (dragging ? "Drop to attach" : canPaste ? "Paste or drop a screenshot" : "Attach an image") })
300
+ ]
301
+ }
302
+ ),
303
+ status,
304
+ hiddenInputs
305
+ ] });
306
+ }
307
+ if (isCamera) {
308
+ const photo = files[0];
309
+ return /* @__PURE__ */ jsxs("div", { ...rootProps, className: cn("flex flex-col gap-3 outline-none", className), children: [
310
+ /* @__PURE__ */ jsx(
311
+ "div",
312
+ {
313
+ className: cn(
314
+ "relative aspect-[4/3] overflow-hidden rounded-xl border border-border bg-muted",
315
+ dragging && "ring-2 ring-brand"
316
+ ),
317
+ children: photo?.previewUrl ? /* @__PURE__ */ jsx(
318
+ "img",
319
+ {
320
+ src: photo.previewUrl,
321
+ alt: `Captured photo: ${photo.file.name}`,
322
+ className: "size-full object-cover"
323
+ }
324
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
325
+ /* @__PURE__ */ jsx(
326
+ "span",
327
+ {
328
+ "aria-hidden": "true",
329
+ className: "absolute inset-[22%] rounded-lg border-2 border-brand/80"
330
+ }
331
+ ),
332
+ /* @__PURE__ */ jsx("p", { className: "absolute inset-x-0 bottom-3 px-4 text-center text-xs text-muted-foreground", children: photo ? photo.file.name : label ?? "Point your camera at what you want to ask about" })
333
+ ] })
334
+ }
335
+ ),
336
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-3", children: photo ? /* @__PURE__ */ jsxs(Fragment, { children: [
337
+ canCamera && /* @__PURE__ */ jsx(
338
+ Button,
339
+ {
340
+ variant: "secondary",
341
+ size: "sm",
342
+ leftIcon: /* @__PURE__ */ jsx(RotateCcw, { className: "size-4", "aria-hidden": "true" }),
343
+ onClick: openCamera,
344
+ disabled,
345
+ "data-visual-input-focus": "",
346
+ children: "Retake"
347
+ }
348
+ ),
349
+ /* @__PURE__ */ jsx(
350
+ Button,
351
+ {
352
+ variant: "ghost",
353
+ size: "sm",
354
+ leftIcon: /* @__PURE__ */ jsx(Trash2, { className: "size-4", "aria-hidden": "true" }),
355
+ onClick: () => removeFile(photo.id),
356
+ disabled,
357
+ children: "Remove"
358
+ }
359
+ )
360
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
361
+ canCamera && /* @__PURE__ */ jsx(
362
+ Button,
363
+ {
364
+ variant: "secondary",
365
+ "aria-label": cameraLabel,
366
+ onClick: openCamera,
367
+ disabled,
368
+ "data-visual-input-focus": "",
369
+ className: "size-14 rounded-full border-4 border-brand p-0",
370
+ children: /* @__PURE__ */ jsx(Camera, { className: "size-5", "aria-hidden": "true" })
371
+ }
372
+ ),
373
+ canUpload && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: openUpload, disabled, children: "Upload instead" })
374
+ ] }) }),
375
+ cameraText && !photo && /* @__PURE__ */ jsx("p", { className: "text-center text-xs text-muted-foreground", children: cameraText }),
376
+ photo?.status === "error" && /* @__PURE__ */ jsx("p", { className: "text-center text-xs text-destructive", children: photo.error ?? "Couldn\u2019t use this photo." }),
377
+ children,
378
+ status,
379
+ hiddenInputs
380
+ ] });
381
+ }
382
+ return /* @__PURE__ */ jsxs("div", { ...rootProps, className: cn("flex flex-col gap-3 outline-none", className), children: [
383
+ /* @__PURE__ */ jsxs(
384
+ "div",
385
+ {
386
+ onClick: (e) => {
387
+ if (e.target.closest("button")) return;
388
+ if (canUpload) openUpload();
389
+ },
390
+ className: cn(
391
+ "flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-border bg-muted/40 px-6 py-6 text-center transition-colors",
392
+ canUpload && !disabled && "cursor-pointer hover:bg-muted/70",
393
+ dragging && "border-brand bg-brand-muted/50",
394
+ disabled && "opacity-50"
395
+ ),
396
+ children: [
397
+ /* @__PURE__ */ jsx("span", { className: "inline-flex size-10 items-center justify-center rounded-full bg-background text-muted-foreground shadow-sm [&_svg]:size-5", children: /* @__PURE__ */ jsx(ImageUp, { "aria-hidden": "true" }) }),
398
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-foreground", children: dragging ? "Drop to attach" : label ?? (canPaste ? "Drop an image or paste a screenshot" : "Drop an image") }),
399
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: hintText }),
400
+ (canUpload || canCamera) && /* @__PURE__ */ jsxs("div", { className: "mt-1 flex flex-wrap items-center justify-center gap-2", children: [
401
+ canUpload && /* @__PURE__ */ jsx(
402
+ Button,
403
+ {
404
+ variant: "secondary",
405
+ size: "sm",
406
+ onClick: openUpload,
407
+ disabled,
408
+ "data-visual-input-focus": "",
409
+ children: browseLabel
410
+ }
411
+ ),
412
+ canCamera && /* @__PURE__ */ jsx(
413
+ Button,
414
+ {
415
+ variant: "ghost",
416
+ size: "sm",
417
+ leftIcon: /* @__PURE__ */ jsx(Camera, { className: "size-4", "aria-hidden": "true" }),
418
+ onClick: openCamera,
419
+ disabled,
420
+ children: cameraLabel
421
+ }
422
+ )
423
+ ] })
424
+ ]
425
+ }
426
+ ),
427
+ chips,
428
+ children,
429
+ status,
430
+ hiddenInputs
431
+ ] });
432
+ }
433
+ );
434
+ VisualInput.displayName = "VisualInput";
435
+
436
+ export { VisualInput, fileMatchesAccept };
437
+ //# sourceMappingURL=index.js.map
438
+ //# sourceMappingURL=index.js.map