@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nucleux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # @nucleux/visual-input
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Visual Input — attach images, screenshots, or videos as part of the ask — Nucleux agentic UI for React.
4
+
5
+ Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @nucleux/visual-input @nucleux/tokens
11
+ ```
12
+
13
+ `react` / `react-dom` are peer dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { VisualInput, type VisualInputFile } from "@nucleux/visual-input";
19
+
20
+ const [files, setFiles] = useState<VisualInputFile[]>([]);
21
+
22
+ <VisualInput
23
+ variant="paste-chip" // "drag-drop" | "paste-chip" | "camera-capture"
24
+ files={files}
25
+ onFilesChange={setFiles}
26
+ maxSize={20 * 1024 * 1024}
27
+ maxFiles={4}
28
+ seeText="Aria will see this when you send"
29
+ unsupportedText="Aria can read images (PNG, JPG, HEIC)."
30
+ >
31
+ <OpenInput … /> {/* the composer the visual is paired with */}
32
+ </VisualInput>
33
+ ```
34
+
35
+ - **Sources:** `sources={["upload", "paste", "camera"]}` — only what the product allows. Upload covers the
36
+ browse button and drag-and-drop; paste picks up images pasted anywhere inside the component (plain-text
37
+ paste is untouched); camera uses `<input type="file" accept="image/*" capture>`.
38
+ - **Limits:** `accept`, `maxSize`, `maxFiles`, `multiple`. Refused files are listed in an alert that says
39
+ why and what can be used, and reported through `onReject`.
40
+ - **Never auto-sends.** The component only manages files; your app sends them with the prompt.
41
+ - **Per-file state:** set `status: "reading" | "error"` and `error` on a file to show a working or failed chip.
42
+
43
+ Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
44
+ and the Tailwind preset from `@nucleux/tokens/preset`.
45
+
46
+ ## License
47
+
48
+ MIT © Nucleux
package/dist/index.cjs ADDED
@@ -0,0 +1,461 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var utils = require('@nucleux/utils');
6
+ var button = require('@nucleux/button');
7
+ var attachment = require('@nucleux/attachment');
8
+ var lucideReact = require('lucide-react');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
30
+
31
+ // src/index.tsx
32
+ var MB = 1024 * 1024;
33
+ function formatFileSize(bytes) {
34
+ if (bytes < 1024) return `${bytes} B`;
35
+ if (bytes < MB) return `${Math.round(bytes / 1024)} KB`;
36
+ const mb = bytes / MB;
37
+ return `${mb >= 10 ? Math.round(mb) : Math.round(mb * 10) / 10} MB`;
38
+ }
39
+ function fileMatchesAccept(file, accept) {
40
+ const rules = accept.split(",").map((r) => r.trim().toLowerCase()).filter(Boolean);
41
+ if (rules.length === 0) return true;
42
+ const name = file.name.toLowerCase();
43
+ const type = (file.type || "").toLowerCase();
44
+ return rules.some((rule) => {
45
+ if (rule.startsWith(".")) return name.endsWith(rule);
46
+ if (rule.endsWith("/*")) return type.startsWith(rule.slice(0, -1));
47
+ return type === rule;
48
+ });
49
+ }
50
+ var fileCounter = 0;
51
+ var canPreview = () => typeof URL !== "undefined" && typeof URL.createObjectURL === "function";
52
+ var VisualInput = React__namespace.forwardRef(
53
+ ({
54
+ variant = "drag-drop",
55
+ sources,
56
+ accept = "image/*",
57
+ maxSize = 20 * MB,
58
+ maxFiles,
59
+ multiple,
60
+ capture = "environment",
61
+ files: filesProp,
62
+ defaultFiles,
63
+ onFilesChange,
64
+ onReject,
65
+ label,
66
+ hint,
67
+ regionLabel = "Image input",
68
+ seeText = "Attached to your next message \u2014 nothing is sent until you send.",
69
+ cameraText,
70
+ unsupportedText,
71
+ browseLabel = "Browse files",
72
+ cameraLabel = "Take photo",
73
+ disabled = false,
74
+ className,
75
+ children,
76
+ onPaste,
77
+ onDragEnter,
78
+ onDragOver,
79
+ onDragLeave,
80
+ onDrop,
81
+ ...props
82
+ }, ref) => {
83
+ const isCamera = variant === "camera-capture";
84
+ const allowed = sources ?? (isCamera ? ["camera", "upload"] : ["upload", "paste"]);
85
+ const canUpload = allowed.includes("upload");
86
+ const canPaste = allowed.includes("paste");
87
+ const canCamera = allowed.includes("camera");
88
+ const isMultiple = multiple ?? !isCamera;
89
+ const limit = isMultiple ? maxFiles ?? 4 : 1;
90
+ const [internal, setInternal] = React__namespace.useState(defaultFiles ?? []);
91
+ const files = filesProp ?? internal;
92
+ const [errors, setErrors] = React__namespace.useState([]);
93
+ const [announcement, setAnnouncement] = React__namespace.useState("");
94
+ const [dragging, setDragging] = React__namespace.useState(false);
95
+ const dragDepth = React__namespace.useRef(0);
96
+ const uploadRef = React__namespace.useRef(null);
97
+ const cameraRef = React__namespace.useRef(null);
98
+ const rootRef = React__namespace.useRef(null);
99
+ const created = React__namespace.useRef(/* @__PURE__ */ new Set());
100
+ const errorsId = React__namespace.useId();
101
+ React__namespace.useEffect(() => {
102
+ const live = new Set(files.map((f) => f.previewUrl));
103
+ created.current.forEach((url) => {
104
+ if (!live.has(url)) {
105
+ URL.revokeObjectURL(url);
106
+ created.current.delete(url);
107
+ }
108
+ });
109
+ }, [files]);
110
+ React__namespace.useEffect(
111
+ () => () => {
112
+ created.current.forEach((url) => URL.revokeObjectURL(url));
113
+ created.current.clear();
114
+ },
115
+ []
116
+ );
117
+ const commit = (next) => {
118
+ if (filesProp === void 0) setInternal(next);
119
+ onFilesChange?.(next);
120
+ };
121
+ const describeRejection = (file, reason) => {
122
+ if (reason === "type")
123
+ return `${file.name} can\u2019t be attached. ${unsupportedText ?? "Choose an image file instead."}`;
124
+ if (reason === "size") return `${file.name} is larger than ${formatFileSize(maxSize)}.`;
125
+ return `Only ${limit} ${limit === 1 ? "file" : "files"} can be attached \u2014 ${file.name} was left out.`;
126
+ };
127
+ const addFiles = (list, source) => {
128
+ if (disabled || list.length === 0) return;
129
+ const rejected = [];
130
+ const accepted = [];
131
+ const room = isMultiple ? limit - files.length : 1;
132
+ for (const file of list) {
133
+ let reason = null;
134
+ if (!fileMatchesAccept(file, accept)) reason = "type";
135
+ else if (file.size > maxSize) reason = "size";
136
+ else if (accepted.length >= room) reason = "count";
137
+ if (reason) {
138
+ rejected.push({ file, reason, message: describeRejection(file, reason) });
139
+ continue;
140
+ }
141
+ let previewUrl;
142
+ if (file.type.startsWith("image/") && canPreview()) {
143
+ previewUrl = URL.createObjectURL(file);
144
+ created.current.add(previewUrl);
145
+ }
146
+ fileCounter += 1;
147
+ accepted.push({ id: `nx-visual-${fileCounter}`, file, previewUrl, source, status: "ready" });
148
+ }
149
+ setErrors(rejected);
150
+ if (rejected.length) onReject?.(rejected);
151
+ if (accepted.length) {
152
+ commit(isMultiple ? [...files, ...accepted] : accepted);
153
+ setAnnouncement(`${accepted.map((f) => f.file.name).join(", ")} attached.`);
154
+ }
155
+ };
156
+ const removeFile = (id) => {
157
+ const target = files.find((f) => f.id === id);
158
+ commit(files.filter((f) => f.id !== id));
159
+ if (target) setAnnouncement(`${target.file.name} removed.`);
160
+ requestAnimationFrame(() => {
161
+ const root = rootRef.current;
162
+ const next = root?.querySelector("[data-visual-input-focus]") ?? root;
163
+ next?.focus();
164
+ });
165
+ };
166
+ const openUpload = () => !disabled && uploadRef.current?.click();
167
+ const openCamera = () => !disabled && cameraRef.current?.click();
168
+ const onInputChange = (source) => (e) => {
169
+ addFiles(Array.from(e.target.files ?? []), source);
170
+ e.target.value = "";
171
+ };
172
+ const hasFiles = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
173
+ const dropHandlers = canUpload ? {
174
+ onDragEnter: (e) => {
175
+ onDragEnter?.(e);
176
+ if (disabled || !hasFiles(e)) return;
177
+ e.preventDefault();
178
+ dragDepth.current += 1;
179
+ setDragging(true);
180
+ },
181
+ onDragOver: (e) => {
182
+ onDragOver?.(e);
183
+ if (disabled || !hasFiles(e)) return;
184
+ e.preventDefault();
185
+ e.dataTransfer.dropEffect = "copy";
186
+ },
187
+ onDragLeave: (e) => {
188
+ onDragLeave?.(e);
189
+ dragDepth.current = Math.max(0, dragDepth.current - 1);
190
+ if (dragDepth.current === 0) setDragging(false);
191
+ },
192
+ onDrop: (e) => {
193
+ onDrop?.(e);
194
+ dragDepth.current = 0;
195
+ setDragging(false);
196
+ if (disabled) return;
197
+ e.preventDefault();
198
+ addFiles(Array.from(e.dataTransfer?.files ?? []), "upload");
199
+ }
200
+ } : { onDragEnter, onDragOver, onDragLeave, onDrop };
201
+ const handlePaste = (e) => {
202
+ onPaste?.(e);
203
+ if (e.defaultPrevented || !canPaste || disabled) return;
204
+ const pasted = Array.from(e.clipboardData?.files ?? []);
205
+ if (pasted.length === 0) return;
206
+ e.preventDefault();
207
+ addFiles(pasted, "paste");
208
+ };
209
+ const hintText = hint ?? `${accept === "image/*" ? "Images" : accept.replace(/,/g, ", ")} \xB7 up to ${formatFileSize(maxSize)}`;
210
+ const chips = files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(attachment.AttachmentGroup, { role: "list", "aria-label": "Attached visuals", children: files.map((f) => /* @__PURE__ */ jsxRuntime.jsx("div", { role: "listitem", children: /* @__PURE__ */ jsxRuntime.jsx(
211
+ attachment.Attachment,
212
+ {
213
+ name: f.file.name,
214
+ meta: f.status === "error" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: f.error ?? "Couldn\u2019t use this file." }) : f.status === "reading" ? "Reading\u2026" : formatFileSize(f.file.size),
215
+ icon: f.previewUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: f.previewUrl, alt: "", className: "size-full rounded-md object-cover" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ImageIcon, { "aria-hidden": "true" }),
216
+ onRemove: () => removeFile(f.id),
217
+ "data-status": f.status ?? "ready",
218
+ className: utils.cn(
219
+ variant === "paste-chip" && "rounded-full py-1 pl-1",
220
+ f.status === "error" && "border-destructive/60",
221
+ f.status === "reading" && "animate-pulse motion-reduce:animate-none"
222
+ )
223
+ }
224
+ ) }, f.id)) });
225
+ const status = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
226
+ files.length > 0 && seeText && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: seeText }),
227
+ errors.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
228
+ "div",
229
+ {
230
+ id: errorsId,
231
+ role: "alert",
232
+ className: "flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",
233
+ children: [
234
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircle, { className: "mt-0.5 size-4 shrink-0", "aria-hidden": "true" }),
235
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex-1 space-y-0.5", children: errors.map((err, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: err.message }, i)) }),
236
+ /* @__PURE__ */ jsxRuntime.jsx(
237
+ "button",
238
+ {
239
+ type: "button",
240
+ "aria-label": "Dismiss errors",
241
+ onClick: () => setErrors([]),
242
+ 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",
243
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { "aria-hidden": "true" })
244
+ }
245
+ )
246
+ ]
247
+ }
248
+ ),
249
+ /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", "aria-live": "polite", className: "sr-only", children: announcement })
250
+ ] });
251
+ const hiddenInputs = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
252
+ canUpload && /* @__PURE__ */ jsxRuntime.jsx(
253
+ "input",
254
+ {
255
+ ref: uploadRef,
256
+ type: "file",
257
+ accept,
258
+ multiple: isMultiple,
259
+ hidden: true,
260
+ tabIndex: -1,
261
+ disabled,
262
+ onChange: onInputChange("upload")
263
+ }
264
+ ),
265
+ canCamera && /* @__PURE__ */ jsxRuntime.jsx(
266
+ "input",
267
+ {
268
+ ref: cameraRef,
269
+ type: "file",
270
+ accept: accept.includes("image") ? "image/*" : accept,
271
+ capture,
272
+ hidden: true,
273
+ tabIndex: -1,
274
+ disabled,
275
+ onChange: onInputChange("camera")
276
+ }
277
+ )
278
+ ] });
279
+ const setRoot = (node) => {
280
+ rootRef.current = node;
281
+ if (typeof ref === "function") ref(node);
282
+ else if (ref) ref.current = node;
283
+ };
284
+ const rootProps = {
285
+ ref: setRoot,
286
+ role: "group",
287
+ "aria-label": regionLabel,
288
+ "aria-disabled": disabled || void 0,
289
+ "data-variant": variant,
290
+ "data-dragging": dragging || void 0,
291
+ tabIndex: -1,
292
+ onPaste: handlePaste,
293
+ ...dropHandlers,
294
+ ...props
295
+ };
296
+ if (variant === "paste-chip") {
297
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...rootProps, className: utils.cn("flex flex-col gap-2 outline-none", className), children: [
298
+ chips,
299
+ children,
300
+ /* @__PURE__ */ jsxRuntime.jsxs(
301
+ "div",
302
+ {
303
+ className: utils.cn(
304
+ "flex items-center gap-1 rounded-lg text-xs text-muted-foreground transition-colors",
305
+ dragging && "bg-brand-muted/50 text-foreground ring-2 ring-brand"
306
+ ),
307
+ children: [
308
+ canUpload && /* @__PURE__ */ jsxRuntime.jsx(
309
+ button.Button,
310
+ {
311
+ variant: "ghost",
312
+ size: "icon-sm",
313
+ "aria-label": "Attach image",
314
+ onClick: openUpload,
315
+ disabled,
316
+ "data-visual-input-focus": "",
317
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Paperclip, { className: "size-4", "aria-hidden": "true" })
318
+ }
319
+ ),
320
+ canCamera && /* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon-sm", "aria-label": cameraLabel, onClick: openCamera, disabled, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Camera, { className: "size-4", "aria-hidden": "true" }) }),
321
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: label ?? (dragging ? "Drop to attach" : canPaste ? "Paste or drop a screenshot" : "Attach an image") })
322
+ ]
323
+ }
324
+ ),
325
+ status,
326
+ hiddenInputs
327
+ ] });
328
+ }
329
+ if (isCamera) {
330
+ const photo = files[0];
331
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...rootProps, className: utils.cn("flex flex-col gap-3 outline-none", className), children: [
332
+ /* @__PURE__ */ jsxRuntime.jsx(
333
+ "div",
334
+ {
335
+ className: utils.cn(
336
+ "relative aspect-[4/3] overflow-hidden rounded-xl border border-border bg-muted",
337
+ dragging && "ring-2 ring-brand"
338
+ ),
339
+ children: photo?.previewUrl ? /* @__PURE__ */ jsxRuntime.jsx(
340
+ "img",
341
+ {
342
+ src: photo.previewUrl,
343
+ alt: `Captured photo: ${photo.file.name}`,
344
+ className: "size-full object-cover"
345
+ }
346
+ ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
347
+ /* @__PURE__ */ jsxRuntime.jsx(
348
+ "span",
349
+ {
350
+ "aria-hidden": "true",
351
+ className: "absolute inset-[22%] rounded-lg border-2 border-brand/80"
352
+ }
353
+ ),
354
+ /* @__PURE__ */ jsxRuntime.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" })
355
+ ] })
356
+ }
357
+ ),
358
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center gap-3", children: photo ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
359
+ canCamera && /* @__PURE__ */ jsxRuntime.jsx(
360
+ button.Button,
361
+ {
362
+ variant: "secondary",
363
+ size: "sm",
364
+ leftIcon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { className: "size-4", "aria-hidden": "true" }),
365
+ onClick: openCamera,
366
+ disabled,
367
+ "data-visual-input-focus": "",
368
+ children: "Retake"
369
+ }
370
+ ),
371
+ /* @__PURE__ */ jsxRuntime.jsx(
372
+ button.Button,
373
+ {
374
+ variant: "ghost",
375
+ size: "sm",
376
+ leftIcon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "size-4", "aria-hidden": "true" }),
377
+ onClick: () => removeFile(photo.id),
378
+ disabled,
379
+ children: "Remove"
380
+ }
381
+ )
382
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
383
+ canCamera && /* @__PURE__ */ jsxRuntime.jsx(
384
+ button.Button,
385
+ {
386
+ variant: "secondary",
387
+ "aria-label": cameraLabel,
388
+ onClick: openCamera,
389
+ disabled,
390
+ "data-visual-input-focus": "",
391
+ className: "size-14 rounded-full border-4 border-brand p-0",
392
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Camera, { className: "size-5", "aria-hidden": "true" })
393
+ }
394
+ ),
395
+ canUpload && /* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "ghost", size: "sm", onClick: openUpload, disabled, children: "Upload instead" })
396
+ ] }) }),
397
+ cameraText && !photo && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-center text-xs text-muted-foreground", children: cameraText }),
398
+ photo?.status === "error" && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-center text-xs text-destructive", children: photo.error ?? "Couldn\u2019t use this photo." }),
399
+ children,
400
+ status,
401
+ hiddenInputs
402
+ ] });
403
+ }
404
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...rootProps, className: utils.cn("flex flex-col gap-3 outline-none", className), children: [
405
+ /* @__PURE__ */ jsxRuntime.jsxs(
406
+ "div",
407
+ {
408
+ onClick: (e) => {
409
+ if (e.target.closest("button")) return;
410
+ if (canUpload) openUpload();
411
+ },
412
+ className: utils.cn(
413
+ "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",
414
+ canUpload && !disabled && "cursor-pointer hover:bg-muted/70",
415
+ dragging && "border-brand bg-brand-muted/50",
416
+ disabled && "opacity-50"
417
+ ),
418
+ children: [
419
+ /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(lucideReact.ImageUp, { "aria-hidden": "true" }) }),
420
+ /* @__PURE__ */ jsxRuntime.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") }),
421
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: hintText }),
422
+ (canUpload || canCamera) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1 flex flex-wrap items-center justify-center gap-2", children: [
423
+ canUpload && /* @__PURE__ */ jsxRuntime.jsx(
424
+ button.Button,
425
+ {
426
+ variant: "secondary",
427
+ size: "sm",
428
+ onClick: openUpload,
429
+ disabled,
430
+ "data-visual-input-focus": "",
431
+ children: browseLabel
432
+ }
433
+ ),
434
+ canCamera && /* @__PURE__ */ jsxRuntime.jsx(
435
+ button.Button,
436
+ {
437
+ variant: "ghost",
438
+ size: "sm",
439
+ leftIcon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Camera, { className: "size-4", "aria-hidden": "true" }),
440
+ onClick: openCamera,
441
+ disabled,
442
+ children: cameraLabel
443
+ }
444
+ )
445
+ ] })
446
+ ]
447
+ }
448
+ ),
449
+ chips,
450
+ children,
451
+ status,
452
+ hiddenInputs
453
+ ] });
454
+ }
455
+ );
456
+ VisualInput.displayName = "VisualInput";
457
+
458
+ exports.VisualInput = VisualInput;
459
+ exports.fileMatchesAccept = fileMatchesAccept;
460
+ //# sourceMappingURL=index.cjs.map
461
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["React","jsx","AttachmentGroup","Attachment","ImageIcon","cn","jsxs","Fragment","AlertCircle","X","Button","Paperclip","Camera","RotateCcw","Trash2","ImageUp"],"mappings":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AAA,EAAQ,aAAA,EAAY,QAAO,CAAA,EAC9B,CAAA;AAAA,4BACAd,cAAA,CAAC,OAAE,SAAA,EAAU,uCAAA,EACV,qBAAW,gBAAA,GAAoB,KAAA,KAAU,QAAA,GAAW,qCAAA,GAAwC,eAAA,CAAA,EAC/F,CAAA;AAAA,4BACAA,cAAA,CAAC,GAAA,EAAA,EAAE,SAAA,EAAU,+BAAA,EAAiC,QAAA,EAAA,QAAA,EAAS,CAAA;AAAA,YAAA,CACrD,SAAA,IAAa,SAAA,qBACbK,eAAA,CAAC,KAAA,EAAA,EAAI,WAAU,uDAAA,EACZ,QAAA,EAAA;AAAA,cAAA,SAAA,oBACCL,cAAA;AAAA,gBAACS,aAAA;AAAA,gBAAA;AAAA,kBACC,OAAA,EAAQ,WAAA;AAAA,kBACR,IAAA,EAAK,IAAA;AAAA,kBACL,OAAA,EAAS,UAAA;AAAA,kBACT,QAAA;AAAA,kBACA,yBAAA,EAAwB,EAAA;AAAA,kBAEvB,QAAA,EAAA;AAAA;AAAA,eACH;AAAA,cAED,SAAA,oBACCT,cAAA;AAAA,gBAACS,aAAA;AAAA,gBAAA;AAAA,kBACC,OAAA,EAAQ,OAAA;AAAA,kBACR,IAAA,EAAK,IAAA;AAAA,kBACL,0BAAUT,cAAA,CAACW,kBAAA,EAAA,EAAO,SAAA,EAAU,QAAA,EAAS,eAAY,MAAA,EAAO,CAAA;AAAA,kBACxD,OAAA,EAAS,UAAA;AAAA,kBACT,QAAA;AAAA,kBAEC,QAAA,EAAA;AAAA;AAAA;AACH,aAAA,EAEJ;AAAA;AAAA;AAAA,OAEJ;AAAA,MACC,KAAA;AAAA,MACA,QAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KAAA,EACH,CAAA;AAAA,EAEJ;AACF;AACA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\nimport { Button } from \"@nucleux/button\";\nimport { Attachment, AttachmentGroup } from \"@nucleux/attachment\";\nimport { AlertCircle, Camera, ImageIcon, ImageUp, Paperclip, RotateCcw, Trash2, X } from \"lucide-react\";\n\nexport type VisualInputVariant = \"drag-drop\" | \"paste-chip\" | \"camera-capture\";\n\n/** Where a visual can come from. Only the sources you list are offered. */\nexport type VisualInputSource = \"upload\" | \"paste\" | \"camera\";\n\n/** Per-file state, set by the app while it reads or uploads the visual. */\nexport type VisualInputFileStatus = \"ready\" | \"reading\" | \"error\";\n\nexport interface VisualInputFile {\n /** Stable id, generated when the file is added. */\n id: string;\n /** The underlying file. */\n file: File;\n /** Object URL used for the thumbnail (images only, browser only). */\n previewUrl?: string;\n /** How the file arrived. */\n source?: VisualInputSource;\n /** `\"reading\"` shows a quiet working treatment; `\"error\"` shows `error` in the destructive tone. */\n status?: VisualInputFileStatus;\n /** Message shown when `status` is `\"error\"`, e.g. `\"Couldn't read this image.\"`. */\n error?: string;\n}\n\nexport type VisualInputRejectionReason = \"type\" | \"size\" | \"count\";\n\nexport interface VisualInputRejection {\n file: File;\n reason: VisualInputRejectionReason;\n /** The human-readable message shown in the error list. */\n message: string;\n}\n\nexport interface VisualInputProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n /** `\"drag-drop\"` (default) dashed drop zone, `\"paste-chip\"` chips above a composer, `\"camera-capture\"` viewfinder with a shutter. */\n variant?: VisualInputVariant;\n /** Sources offered. Defaults to upload + paste (+ camera for `\"camera-capture\"`). */\n sources?: VisualInputSource[];\n /** Accepted types, in `<input accept>` syntax. Defaults to `\"image/*\"`. */\n accept?: string;\n /** Largest accepted file in bytes. Defaults to 20 MB. */\n maxSize?: number;\n /** Most files held at once. Defaults to 4 (1 for `\"camera-capture\"`). */\n maxFiles?: number;\n /** Allow more than one file. Defaults to `true` except for `\"camera-capture\"`. */\n multiple?: boolean;\n /** Which camera `capture` asks for on mobile. Defaults to `\"environment\"`. */\n capture?: \"user\" | \"environment\";\n /** The attached files (controlled). */\n files?: VisualInputFile[];\n /** Initial files (uncontrolled). */\n defaultFiles?: VisualInputFile[];\n /** Called with the next list whenever files are added or removed. Nothing is ever sent. */\n onFilesChange?: (files: VisualInputFile[]) => void;\n /** Called with files that were refused (wrong type, too large, too many). */\n onReject?: (rejections: VisualInputRejection[]) => void;\n /** Main line of the drop zone. */\n label?: React.ReactNode;\n /** Secondary line, e.g. `\"PNG, JPG, PDF · up to 20 MB\"`. Derived from `accept`/`maxSize` when omitted. */\n hint?: React.ReactNode;\n /** Accessible name of the whole region. Defaults to `\"Image input\"`. */\n regionLabel?: string;\n /** Line shown once something is attached, e.g. `\"Aria will see this when you send\"`. */\n seeText?: React.ReactNode;\n /** Explains camera access before anything is captured (camera variant). */\n cameraText?: React.ReactNode;\n /** Says what can be used when a type is refused, e.g. `\"Aria can read PNG, JPG and HEIC.\"`. */\n unsupportedText?: string;\n /** Label of the browse button. */\n browseLabel?: string;\n /** Label of the camera button. */\n cameraLabel?: string;\n /** Disable every source. */\n disabled?: boolean;\n /** Slot rendered under the previews — typically the composer the visual is paired with. */\n children?: React.ReactNode;\n}\n\nconst MB = 1024 * 1024;\n\n/** Format a byte count as `\"240 KB\"` / `\"2.4 MB\"`. */\nfunction formatFileSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < MB) return `${Math.round(bytes / 1024)} KB`;\n const mb = bytes / MB;\n return `${mb >= 10 ? Math.round(mb) : Math.round(mb * 10) / 10} MB`;\n}\n\n/** Whether `file` matches an `<input accept>` string. */\nexport function fileMatchesAccept(file: File, accept: string): boolean {\n const rules = accept\n .split(\",\")\n .map((r) => r.trim().toLowerCase())\n .filter(Boolean);\n if (rules.length === 0) return true;\n const name = file.name.toLowerCase();\n const type = (file.type || \"\").toLowerCase();\n return rules.some((rule) => {\n if (rule.startsWith(\".\")) return name.endsWith(rule);\n if (rule.endsWith(\"/*\")) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n\nlet fileCounter = 0;\nconst canPreview = () => typeof URL !== \"undefined\" && typeof URL.createObjectURL === \"function\";\n\n/**\n * Visual input: lets people add images, screenshots or photos as context to their\n * ask — drag-and-drop, paste from the clipboard, browse, or camera capture\n * (`<input capture>`). Each visual lands as a removable chip with a real preview,\n * type/size/count limits are checked with plain-language errors in a live region,\n * and nothing is ever sent: the app pairs the files with the text prompt and\n * sends on the person's command. Variants: drag-drop, paste-chip, camera-capture.\n */\nexport const VisualInput = React.forwardRef<HTMLDivElement, VisualInputProps>(\n (\n {\n variant = \"drag-drop\",\n sources,\n accept = \"image/*\",\n maxSize = 20 * MB,\n maxFiles,\n multiple,\n capture = \"environment\",\n files: filesProp,\n defaultFiles,\n onFilesChange,\n onReject,\n label,\n hint,\n regionLabel = \"Image input\",\n seeText = \"Attached to your next message — nothing is sent until you send.\",\n cameraText,\n unsupportedText,\n browseLabel = \"Browse files\",\n cameraLabel = \"Take photo\",\n disabled = false,\n className,\n children,\n onPaste,\n onDragEnter,\n onDragOver,\n onDragLeave,\n onDrop,\n ...props\n },\n ref,\n ) => {\n const isCamera = variant === \"camera-capture\";\n const allowed = sources ?? (isCamera ? [\"camera\", \"upload\"] : [\"upload\", \"paste\"]);\n const canUpload = allowed.includes(\"upload\");\n const canPaste = allowed.includes(\"paste\");\n const canCamera = allowed.includes(\"camera\");\n const isMultiple = multiple ?? !isCamera;\n const limit = isMultiple ? (maxFiles ?? 4) : 1;\n\n const [internal, setInternal] = React.useState<VisualInputFile[]>(defaultFiles ?? []);\n const files = filesProp ?? internal;\n const [errors, setErrors] = React.useState<VisualInputRejection[]>([]);\n const [announcement, setAnnouncement] = React.useState(\"\");\n const [dragging, setDragging] = React.useState(false);\n const dragDepth = React.useRef(0);\n const uploadRef = React.useRef<HTMLInputElement>(null);\n const cameraRef = React.useRef<HTMLInputElement>(null);\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const created = React.useRef(new Set<string>());\n const errorsId = React.useId();\n\n // Revoke object URLs we created once their file is gone, and on unmount.\n React.useEffect(() => {\n const live = new Set(files.map((f) => f.previewUrl));\n created.current.forEach((url) => {\n if (!live.has(url)) {\n URL.revokeObjectURL(url);\n created.current.delete(url);\n }\n });\n }, [files]);\n React.useEffect(\n () => () => {\n created.current.forEach((url) => URL.revokeObjectURL(url));\n created.current.clear();\n },\n [],\n );\n\n const commit = (next: VisualInputFile[]) => {\n if (filesProp === undefined) setInternal(next);\n onFilesChange?.(next);\n };\n\n const describeRejection = (file: File, reason: VisualInputRejectionReason) => {\n if (reason === \"type\")\n return `${file.name} can’t be attached. ${unsupportedText ?? \"Choose an image file instead.\"}`;\n if (reason === \"size\") return `${file.name} is larger than ${formatFileSize(maxSize)}.`;\n return `Only ${limit} ${limit === 1 ? \"file\" : \"files\"} can be attached — ${file.name} was left out.`;\n };\n\n const addFiles = (list: File[], source: VisualInputSource) => {\n if (disabled || list.length === 0) return;\n const rejected: VisualInputRejection[] = [];\n const accepted: VisualInputFile[] = [];\n const room = isMultiple ? limit - files.length : 1;\n for (const file of list) {\n let reason: VisualInputRejectionReason | null = null;\n if (!fileMatchesAccept(file, accept)) reason = \"type\";\n else if (file.size > maxSize) reason = \"size\";\n else if (accepted.length >= room) reason = \"count\";\n if (reason) {\n rejected.push({ file, reason, message: describeRejection(file, reason) });\n continue;\n }\n let previewUrl: string | undefined;\n if (file.type.startsWith(\"image/\") && canPreview()) {\n previewUrl = URL.createObjectURL(file);\n created.current.add(previewUrl);\n }\n fileCounter += 1;\n accepted.push({ id: `nx-visual-${fileCounter}`, file, previewUrl, source, status: \"ready\" });\n }\n setErrors(rejected);\n if (rejected.length) onReject?.(rejected);\n if (accepted.length) {\n commit(isMultiple ? [...files, ...accepted] : accepted);\n setAnnouncement(`${accepted.map((f) => f.file.name).join(\", \")} attached.`);\n }\n };\n\n const removeFile = (id: string) => {\n const target = files.find((f) => f.id === id);\n commit(files.filter((f) => f.id !== id));\n if (target) setAnnouncement(`${target.file.name} removed.`);\n // Focus would be lost with the removed chip — move it to a stable control.\n requestAnimationFrame(() => {\n const root = rootRef.current;\n const next = root?.querySelector<HTMLElement>(\"[data-visual-input-focus]\") ?? root;\n next?.focus();\n });\n };\n\n const openUpload = () => !disabled && uploadRef.current?.click();\n const openCamera = () => !disabled && cameraRef.current?.click();\n\n const onInputChange = (source: VisualInputSource) => (e: React.ChangeEvent<HTMLInputElement>) => {\n addFiles(Array.from(e.target.files ?? []), source);\n e.target.value = \"\";\n };\n\n const hasFiles = (e: React.DragEvent) => Array.from(e.dataTransfer?.types ?? []).includes(\"Files\");\n\n const dropHandlers = canUpload\n ? {\n onDragEnter: (e: React.DragEvent<HTMLDivElement>) => {\n onDragEnter?.(e);\n if (disabled || !hasFiles(e)) return;\n e.preventDefault();\n dragDepth.current += 1;\n setDragging(true);\n },\n onDragOver: (e: React.DragEvent<HTMLDivElement>) => {\n onDragOver?.(e);\n if (disabled || !hasFiles(e)) return;\n e.preventDefault();\n e.dataTransfer.dropEffect = \"copy\";\n },\n onDragLeave: (e: React.DragEvent<HTMLDivElement>) => {\n onDragLeave?.(e);\n dragDepth.current = Math.max(0, dragDepth.current - 1);\n if (dragDepth.current === 0) setDragging(false);\n },\n onDrop: (e: React.DragEvent<HTMLDivElement>) => {\n onDrop?.(e);\n dragDepth.current = 0;\n setDragging(false);\n if (disabled) return;\n e.preventDefault();\n addFiles(Array.from(e.dataTransfer?.files ?? []), \"upload\");\n },\n }\n : { onDragEnter, onDragOver, onDragLeave, onDrop };\n\n const handlePaste = (e: React.ClipboardEvent<HTMLDivElement>) => {\n onPaste?.(e);\n if (e.defaultPrevented || !canPaste || disabled) return;\n const pasted = Array.from(e.clipboardData?.files ?? []);\n if (pasted.length === 0) return; // plain text paste continues as normal\n e.preventDefault();\n addFiles(pasted, \"paste\");\n };\n\n const hintText =\n hint ?? `${accept === \"image/*\" ? \"Images\" : accept.replace(/,/g, \", \")} · up to ${formatFileSize(maxSize)}`;\n\n const chips = files.length > 0 && (\n <AttachmentGroup role=\"list\" aria-label=\"Attached visuals\">\n {files.map((f) => (\n <div role=\"listitem\" key={f.id}>\n <Attachment\n name={f.file.name}\n meta={\n f.status === \"error\" ? (\n <span className=\"text-destructive\">{f.error ?? \"Couldn’t use this file.\"}</span>\n ) : f.status === \"reading\" ? (\n \"Reading…\"\n ) : (\n formatFileSize(f.file.size)\n )\n }\n icon={\n f.previewUrl ? (\n <img src={f.previewUrl} alt=\"\" className=\"size-full rounded-md object-cover\" />\n ) : (\n <ImageIcon aria-hidden=\"true\" />\n )\n }\n onRemove={() => removeFile(f.id)}\n data-status={f.status ?? \"ready\"}\n className={cn(\n variant === \"paste-chip\" && \"rounded-full py-1 pl-1\",\n f.status === \"error\" && \"border-destructive/60\",\n f.status === \"reading\" && \"animate-pulse motion-reduce:animate-none\",\n )}\n />\n </div>\n ))}\n </AttachmentGroup>\n );\n\n const status = (\n <>\n {files.length > 0 && seeText && <p className=\"text-xs text-muted-foreground\">{seeText}</p>}\n {errors.length > 0 && (\n <div\n id={errorsId}\n role=\"alert\"\n className=\"flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive\"\n >\n <AlertCircle className=\"mt-0.5 size-4 shrink-0\" aria-hidden=\"true\" />\n <ul className=\"flex-1 space-y-0.5\">\n {errors.map((err, i) => (\n <li key={i}>{err.message}</li>\n ))}\n </ul>\n <button\n type=\"button\"\n aria-label=\"Dismiss errors\"\n onClick={() => setErrors([])}\n 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\"\n >\n <X aria-hidden=\"true\" />\n </button>\n </div>\n )}\n <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {announcement}\n </p>\n </>\n );\n\n const hiddenInputs = (\n <>\n {canUpload && (\n <input\n ref={uploadRef}\n type=\"file\"\n accept={accept}\n multiple={isMultiple}\n hidden\n tabIndex={-1}\n disabled={disabled}\n onChange={onInputChange(\"upload\")}\n />\n )}\n {canCamera && (\n <input\n ref={cameraRef}\n type=\"file\"\n accept={accept.includes(\"image\") ? \"image/*\" : accept}\n capture={capture}\n hidden\n tabIndex={-1}\n disabled={disabled}\n onChange={onInputChange(\"camera\")}\n />\n )}\n </>\n );\n\n const setRoot = (node: HTMLDivElement | null) => {\n rootRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n };\n\n const rootProps = {\n ref: setRoot,\n role: \"group\" as const,\n \"aria-label\": regionLabel,\n \"aria-disabled\": disabled || undefined,\n \"data-variant\": variant,\n \"data-dragging\": dragging || undefined,\n tabIndex: -1,\n onPaste: handlePaste,\n ...dropHandlers,\n ...props,\n };\n\n if (variant === \"paste-chip\") {\n return (\n <div {...rootProps} className={cn(\"flex flex-col gap-2 outline-none\", className)}>\n {chips}\n {children}\n <div\n className={cn(\n \"flex items-center gap-1 rounded-lg text-xs text-muted-foreground transition-colors\",\n dragging && \"bg-brand-muted/50 text-foreground ring-2 ring-brand\",\n )}\n >\n {canUpload && (\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n aria-label=\"Attach image\"\n onClick={openUpload}\n disabled={disabled}\n data-visual-input-focus=\"\"\n >\n <Paperclip className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n )}\n {canCamera && (\n <Button variant=\"ghost\" size=\"icon-sm\" aria-label={cameraLabel} onClick={openCamera} disabled={disabled}>\n <Camera className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n )}\n <span>{label ?? (dragging ? \"Drop to attach\" : canPaste ? \"Paste or drop a screenshot\" : \"Attach an image\")}</span>\n </div>\n {status}\n {hiddenInputs}\n </div>\n );\n }\n\n if (isCamera) {\n const photo = files[0];\n return (\n <div {...rootProps} className={cn(\"flex flex-col gap-3 outline-none\", className)}>\n <div\n className={cn(\n \"relative aspect-[4/3] overflow-hidden rounded-xl border border-border bg-muted\",\n dragging && \"ring-2 ring-brand\",\n )}\n >\n {photo?.previewUrl ? (\n <img\n src={photo.previewUrl}\n alt={`Captured photo: ${photo.file.name}`}\n className=\"size-full object-cover\"\n />\n ) : (\n <>\n <span\n aria-hidden=\"true\"\n className=\"absolute inset-[22%] rounded-lg border-2 border-brand/80\"\n />\n <p className=\"absolute inset-x-0 bottom-3 px-4 text-center text-xs text-muted-foreground\">\n {photo ? photo.file.name : (label ?? \"Point your camera at what you want to ask about\")}\n </p>\n </>\n )}\n </div>\n <div className=\"flex items-center justify-center gap-3\">\n {photo ? (\n <>\n {canCamera && (\n <Button\n variant=\"secondary\"\n size=\"sm\"\n leftIcon={<RotateCcw className=\"size-4\" aria-hidden=\"true\" />}\n onClick={openCamera}\n disabled={disabled}\n data-visual-input-focus=\"\"\n >\n Retake\n </Button>\n )}\n <Button\n variant=\"ghost\"\n size=\"sm\"\n leftIcon={<Trash2 className=\"size-4\" aria-hidden=\"true\" />}\n onClick={() => removeFile(photo.id)}\n disabled={disabled}\n >\n Remove\n </Button>\n </>\n ) : (\n <>\n {canCamera && (\n <Button\n variant=\"secondary\"\n aria-label={cameraLabel}\n onClick={openCamera}\n disabled={disabled}\n data-visual-input-focus=\"\"\n className=\"size-14 rounded-full border-4 border-brand p-0\"\n >\n <Camera className=\"size-5\" aria-hidden=\"true\" />\n </Button>\n )}\n {canUpload && (\n <Button variant=\"ghost\" size=\"sm\" onClick={openUpload} disabled={disabled}>\n Upload instead\n </Button>\n )}\n </>\n )}\n </div>\n {cameraText && !photo && <p className=\"text-center text-xs text-muted-foreground\">{cameraText}</p>}\n {photo?.status === \"error\" && (\n <p className=\"text-center text-xs text-destructive\">{photo.error ?? \"Couldn’t use this photo.\"}</p>\n )}\n {children}\n {status}\n {hiddenInputs}\n </div>\n );\n }\n\n return (\n <div {...rootProps} className={cn(\"flex flex-col gap-3 outline-none\", className)}>\n <div\n onClick={(e) => {\n if ((e.target as HTMLElement).closest(\"button\")) return;\n if (canUpload) openUpload();\n }}\n className={cn(\n \"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\",\n canUpload && !disabled && \"cursor-pointer hover:bg-muted/70\",\n dragging && \"border-brand bg-brand-muted/50\",\n disabled && \"opacity-50\",\n )}\n >\n <span className=\"inline-flex size-10 items-center justify-center rounded-full bg-background text-muted-foreground shadow-sm [&_svg]:size-5\">\n <ImageUp aria-hidden=\"true\" />\n </span>\n <p className=\"text-sm font-semibold text-foreground\">\n {dragging ? \"Drop to attach\" : (label ?? (canPaste ? \"Drop an image or paste a screenshot\" : \"Drop an image\"))}\n </p>\n <p className=\"text-xs text-muted-foreground\">{hintText}</p>\n {(canUpload || canCamera) && (\n <div className=\"mt-1 flex flex-wrap items-center justify-center gap-2\">\n {canUpload && (\n <Button\n variant=\"secondary\"\n size=\"sm\"\n onClick={openUpload}\n disabled={disabled}\n data-visual-input-focus=\"\"\n >\n {browseLabel}\n </Button>\n )}\n {canCamera && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n leftIcon={<Camera className=\"size-4\" aria-hidden=\"true\" />}\n onClick={openCamera}\n disabled={disabled}\n >\n {cameraLabel}\n </Button>\n )}\n </div>\n )}\n </div>\n {chips}\n {children}\n {status}\n {hiddenInputs}\n </div>\n );\n },\n);\nVisualInput.displayName = \"VisualInput\";\n"]}