# File drop (Notchset): prompt.md (v1.2.0)

- id: `file-drop` · version 1.2.0 · component · free
- category: Text fields
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/file-drop.json`
- npm dependencies: lucide-react@^1
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json, @notchset/rolling-number, @notchset/tooltip
- docs: https://notchset.dev/components/file-drop
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Choose files, drop them or paste them. Each is checked against the types, size and count it takes, and one that doesn't fit is named with its reason; the rest are listed with their size while the prompt folds to a slim Add more. Uploading and progress are the upload block's, which composes this..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: `lucide-react@^1` beyond `react` and `react-dom`.
- Files: `components/ui/notchset/file-drop.tsx`; shared code: `lib/notchset/feedback.ts`, `lib/notchset/file-size.ts`, `lib/notchset/icons.ts`, `lib/notchset/keep-focus.ts`, `lib/notchset/motion.ts`, `lib/notchset/words.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`, `rolling-number`, `tooltip`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `accepts`, `FILE_DROP_LABELS`, `formatBytes`, `FileDrop`, `splitName`, `useFileTarget`, `FileDropRejected`, `FileDropStatus`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-bad`, `--ns-bad-ink`, `--ns-ease`, `--ns-ease-move`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-ease-spring`, `--ns-field`, `--ns-field-edge`, `--ns-font-display`, `--ns-hover`, `--ns-icon`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-line`, `--ns-line-soft`, `--ns-ok`, `--ns-panel`, `--ns-radius`, `--ns-radius-sm`, `--ns-radius-xs`, `--ns-raised`, `--ns-signal`, `--ns-signal-ink`, `--ns-signal-wash`, `--ns-text-body`, `--ns-text-meta`, `--ns-text-small`, `--ns-time-color`, `--ns-time-menu`, `--ns-time-panel`, `--ns-time-spring`, `--ns-weight-strong`, `--ns-well`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-agent-b`, `--ns-agent-c`, `--ns-agent-d`, `--ns-agent-drift`, `--ns-agent-fill`, `--ns-agent-h1`, `--ns-agent-h2`, `--ns-agent-h3`, `--ns-agent-shift`, `--ns-avatar-card`, `--ns-avatar-lg`, `--ns-avatar-md`, `--ns-avatar-sm`, `--ns-avatar-xs`, `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-banner-beat`, `--ns-banner-radius`, `--ns-beat`, `--ns-beat-ease`, `--ns-bezel`, `--ns-bloom-close`, `--ns-bloom-open`, `--ns-bloom-rise`, `--ns-btn-bad`, `--ns-btn-bad-hover`, `--ns-btn-bad-line`, `--ns-btn-bezel`, `--ns-btn-chosen`, `--ns-btn-gone`, `--ns-btn-morph`, `--ns-btn-ok`, `--ns-btn-press`, `--ns-btn-release`, `--ns-btn-result`, `--ns-btn-roll`, `--ns-btn-stagger`, `--ns-btn-stagger-step`, `--ns-btn-tick`, `--ns-btn-tonal`, `--ns-btn-tonal-edge`, `--ns-btn-tonal-hover`, `--ns-bulk-clear`, `--ns-button`, `--ns-button-field-inset`, `--ns-button-lg`, `--ns-button-sm`, `--ns-canvas`, `--ns-card-tilt`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-check-round`, `--ns-cheer-1`, `--ns-cheer-2`, `--ns-cheer-3`, `--ns-cheer-edge`, `--ns-cheer-fold`, `--ns-cheer-glow`, `--ns-cheer-lift`, `--ns-chip`, `--ns-chip-pick`, `--ns-control`, `--ns-control-lg`, `--ns-control-pad`, `--ns-control-sm`, `--ns-corner`, `--ns-danger`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-depth-card`, `--ns-depth-lift`, `--ns-depth-surface`, `--ns-dialog`, `--ns-dialog-grow`, `--ns-dialog-lg`, `--ns-dialog-max`, `--ns-dialog-shrink`, `--ns-dialog-sm`, `--ns-dialog-top`, `--ns-dock-bottom`, `--ns-drop`, `--ns-ease`, `--ns-ease-arrive`, `--ns-ease-breathe`, `--ns-ease-drum`, `--ns-ease-exit`, `--ns-ease-fling`, `--ns-ease-glide`, `--ns-ease-grow`, `--ns-ease-move`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-ease-press`, `--ns-ease-spring`, `--ns-ebg-arm`, `--ns-ebg-lit`, `--ns-emoji`, `--ns-emoji-md`, `--ns-emoji-sm`, `--ns-field`, `--ns-field-edge`, `--ns-field-h`, `--ns-fill`, `--ns-fill-time`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-glyph-pad`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-help-max`, `--ns-hit`, `--ns-hover`, `--ns-icon`, `--ns-icon-lg`, `--ns-icon-sm`, `--ns-icon-stroke`, `--ns-info`, `--ns-info-ink`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-layer-bar`, `--ns-layer-modal`, `--ns-layer-panel`, `--ns-layer-popup`, `--ns-layer-sticky`, `--ns-layer-tip`, `--ns-layer-toast`, `--ns-layer-zoom`, `--ns-lead-body`, `--ns-lead-figure`, `--ns-lead-large`, `--ns-lead-meta`, `--ns-lead-small`, `--ns-lead-sub`, `--ns-lead-title`, `--ns-leading`, `--ns-leading-prose`, `--ns-leading-title`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-map-grass`, `--ns-map-water`, `--ns-mark-edge`, `--ns-mark-lifted`, `--ns-mark-rest`, `--ns-mark-swap`, `--ns-marker`, `--ns-marker-ink`, `--ns-mc-place`, `--ns-mc-roll`, `--ns-measure`, `--ns-menu-dy`, `--ns-menu-lit`, `--ns-menu-pad`, `--ns-menu-row`, `--ns-menu-rule`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-nest-inset`, `--ns-nest-outer`, `--ns-nest-r`, `--ns-notch-ease`, `--ns-ok`, `--ns-ok-ink`, `--ns-on-fill`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-palette-min`, `--ns-panel`, `--ns-panel-room`, `--ns-panel-w`, `--ns-panel-w-lg`, `--ns-pick-slot`, `--ns-pill-prop`, `--ns-play-fill`, `--ns-play-fill-color`, `--ns-play-lift`, `--ns-play-lift-y`, `--ns-play-open`, `--ns-play-open-content`, `--ns-play-press`, `--ns-play-press-box`, `--ns-play-reduced`, `--ns-play-ring`, `--ns-play-roll`, `--ns-play-shake`, `--ns-play-spring`, `--ns-play-swap`, `--ns-play-swap-blur`, `--ns-press-min`, `--ns-press-scale`, `--ns-press-x`, `--ns-press-y`, `--ns-primary-hover`, `--ns-primary-press`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-2xl`, `--ns-radius-button`, `--ns-radius-button-lg`, `--ns-radius-button-sm`, `--ns-radius-card`, `--ns-radius-check`, `--ns-radius-control`, `--ns-radius-control-sm`, `--ns-radius-float`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-mark`, `--ns-radius-menu-row`, `--ns-radius-modal`, `--ns-radius-pill`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-radius-xs`, `--ns-raised`, `--ns-ramp-1`, `--ns-ramp-2`, `--ns-ramp-3`, `--ns-ramp-4`, `--ns-ramp-5`, `--ns-ramp-shine`, `--ns-range`, `--ns-rest-1`, `--ns-rest-2`, `--ns-rest-3`, `--ns-rise`, `--ns-row`, `--ns-row-compact`, `--ns-row-hue`, `--ns-scrim`, `--ns-search-h`, `--ns-segment`, `--ns-segment-inset`, `--ns-segment-lift`, `--ns-segment-sm`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-glint`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-lift`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-back`, `--ns-sheet-bottom`, `--ns-sheet-drop`, `--ns-sheet-rise`, `--ns-shift`, `--ns-side`, `--ns-signal`, `--ns-signal-ink`, `--ns-signal-wash`, `--ns-sk-figure`, `--ns-sk-land`, `--ns-sk-p`, `--ns-sk-p0`, `--ns-sk-p1`, `--ns-sk-p2`, `--ns-sk-p3`, `--ns-sk-p4`, `--ns-sk-p5`, `--ns-sk-p6`, `--ns-sk-p7`, `--ns-sk-read`, `--ns-sk-sweep`, `--ns-skeleton`, `--ns-skeleton-bone`, `--ns-skeleton-bone-light`, `--ns-skeleton-light`, `--ns-slab`, `--ns-slab-edge`, `--ns-slab-ink`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-fan`, `--ns-stack-fan-gap`, `--ns-stack-fan-lag`, `--ns-stack-on`, `--ns-stagger-item`, `--ns-stagger-mark`, `--ns-stagger-max`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-step`, `--ns-step-from`, `--ns-step-sign`, `--ns-swipe-surface`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-control-lg`, `--ns-text-display`, `--ns-text-editorial`, `--ns-text-empty`, `--ns-text-figure`, `--ns-text-giant`, `--ns-text-heading`, `--ns-text-headline`, `--ns-text-input`, `--ns-text-large`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-record`, `--ns-text-sentence`, `--ns-text-small`, `--ns-text-sub`, `--ns-text-title`, `--ns-theme-fade`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-confirm`, `--ns-time-dialog`, `--ns-time-fling`, `--ns-time-flip`, `--ns-time-glide`, `--ns-time-grow`, `--ns-time-hold`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-quick`, `--ns-time-roll`, `--ns-time-settle`, `--ns-time-snap`, `--ns-time-spin`, `--ns-time-spring`, `--ns-time-sweep`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-c`, `--ns-tint-ease`, `--ns-tint-fill`, `--ns-tint-gap`, `--ns-tint-h1`, `--ns-tint-h2`, `--ns-tint-h3`, `--ns-tint-ink`, `--ns-tint-row`, `--ns-tip-fold`, `--ns-tip-grow`, `--ns-toast-bottom`, `--ns-toast-gap`, `--ns-toast-left`, `--ns-toast-lift`, `--ns-toast-peek`, `--ns-toast-scale`, `--ns-toast-w`, `--ns-touch`, `--ns-tracking-body`, `--ns-tracking-caps`, `--ns-tracking-control`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-tracking-sub`, `--ns-tracking-title`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`, `--ns-width-lg`, `--ns-width-md`, `--ns-width-sm`, `--ns-width-xl`.
- Never add Tailwind colour classes inside the component.

```tsx
import { FileDrop, type FileDropLook } from "@/components/ui/notchset/file-drop";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/file-drop.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- Choosing files from the device.

### Not when
- A link to a file is a Text field; uploading with progress and retry is the upload block (file drop, a file list and a meter).

## Built from
- rolling-number (`rolling-number`), installed with it: reuse it, don't rebuild it
- tooltip (`tooltip`), installed with it: reuse it, don't rebuild it
- Feedback (shared helper, ships with it)
- File size (shared helper, ships with it)
- Icons (shared helper, ships with it)
- Keep focus (shared helper, ships with it)
- Motion (shared helper, ships with it)
- Words (shared helper, ships with it)

## Mistakes
- Expecting it to upload: it holds File objects and reports rejections, the upload is yours
- Setting accept to extensions the picker ignores: use MIME types as well
- Showing progress in it: use the upload block (file drop, file list, meter)

## Usage

```tsx
"use client";
import * as React from "react";
import { FileDrop, type FileDropLook } from "@/components/ui/notchset/file-drop";
import { MousePointer2 } from "@/lib/notchset/icons";
import { useLessMotion } from "@/lib/notchset/motion";
import { PlayOnce, useSelfPlay } from "./self-play";

/*
 * Three looks of one file drop, each on its own job. "The well breathes" and "Paper stack" are a careers page's
 * "drop your CV": on arrival a hand carries the CV in (the well's edges lean out to meet it and bow in round it; it
 * falls in, its row's rule fills and a tick lands; the stack takes the CV, then a portfolio image, then a 24.6 MB print
 * that bounces back out with its reason in rose). "Plain" is a support form's attachments: a file is dropped, uploads in
 * its row and settles with a tick on its mark; then a 14 MB scan is named in rose. Real files work on every look: drop,
 * paste or choose. The quiet "Uploads fail" chip is a switch: while it is on, every file's upload stops part way and
 * its row says so in rose with Retry (the hand carries one in when it is turned on); off, Retry sends it through.
 */
const MB = 1_000_000;
const LIMIT = "PDF, Word or images, up to 10 MB";
const ACCEPT = ".pdf,.doc,.docx,image/*";
const WORDS = { role: "Careers · Product Designer · Remote", title: "Drop your CV here", cv: "Ana Ruiz, CV.pdf", portfolio: "Portfolio, 2026.png", big: "Portfolio, print.pdf", notes: "Screen recording notes.pdf", scan: "Scan.png", attachments: "Attachments", failed: "Upload failed. Check the connection and retry." };

/* the stage's own files carry their stated size (no real bytes are made) */
const sized = (name: string, bytes: number, type: string, parts: BlobPart[] = []) => {
  const f = new File(parts, name, { type, lastModified: 0 });
  if (!parts.length) Object.defineProperty(f, "size", { value: bytes });
  return f;
};

/* where a failing upload stops: part way, so its rule has visibly filled before the row turns rose */
const FAILS_AT = 0.6;
/* a failed upload's progress (below 0: it reads as the error) */
const FAILED = -1;

/** An upload host: each new file climbs to done over about 1.3 s, eased (instant under less motion). While `failing`
    is on, every upload sent stops part way and fails; Retry sends it again (and fails again while it is still on). */
function useHost(instant: boolean, failing: boolean, failed: string) {
  const [progress, setProgress] = React.useState(() => new Map<File, number>());
  const doomed = React.useRef(new Set<File>());
  const fails = React.useRef(failing);
  React.useEffect(() => {
    fails.current = failing;
  }, [failing]);
  const busy = [...progress.values()].some((p) => p >= 0 && p < 1);
  React.useEffect(() => {
    if (!busy) return;
    let raf = 0;
    const step = () => {
      setProgress((m) => new Map([...m].map(([f, p]) => [f, p < 0 || p >= 1 ? p : doomed.current.has(f) && p >= FAILS_AT ? FAILED : Math.min(1, p + 0.012 + (1 - p) * 0.02)])));
      raf = requestAnimationFrame(step);
    };
    raf = requestAnimationFrame(step);
    return () => cancelAnimationFrame(raf);
  }, [busy]);
  const [files, setFiles] = React.useState<File[]>([]);
  const send = (f: File) => {
    if (fails.current) doomed.current.add(f);
    else doomed.current.delete(f);
    return instant ? (fails.current ? FAILED : 1) : 0.02;
  };
  const change = (next: File[]) => {
    setFiles(next);
    setProgress((m) => {
      const out = new Map(m);
      next.forEach((f) => !out.has(f) && out.set(f, send(f)));
      return out;
    });
  };
  const retry = (f: File) => setProgress((m) => new Map(m).set(f, send(f)));
  const status = (f: File) => {
    const p = progress.get(f);
    return p === undefined ? undefined : p < 0 ? { error: failed } : p >= 1 ? { done: true } : { progress: p };
  };
  return { files, change, retry, status };
}

type Ghost = { x: number; y: number; r: number; o: number; s: number; name: string; down: boolean };

/** The stage's own hand: it carries a file across the stage and lets it go over the zone, through the zone's own drag events. */
function useHand(box: React.RefObject<HTMLDivElement | null>) {
  const [ghost, setGhost] = React.useState<Ghost | null>(null);
  const timers = React.useRef<number[]>([]);
  const frames = React.useRef<number[]>([]);
  const stop = React.useCallback(() => {
    timers.current.forEach((t) => window.clearTimeout(t));
    frames.current.forEach((f) => cancelAnimationFrame(f));
    timers.current = [];
    frames.current = [];
    setGhost(null);
  }, []);
  React.useEffect(() => stop, [stop]);
  const after = (ms: number, fn: () => void) => void timers.current.push(window.setTimeout(fn, ms));
  const tween = (ms: number, frame: (t: number) => void) => {
    const t0 = performance.now();
    const step = (now: number) => {
      const k = Math.min(1, (now - t0) / ms);
      frame(k < 0.5 ? 4 * k * k * k : 1 - (-2 * k + 2) ** 3 / 2);
      if (k < 1) frames.current.push(requestAnimationFrame(step));
    };
    frames.current.push(requestAnimationFrame(step));
  };
  const zone = () => box.current?.querySelector<HTMLElement>("[data-slot=file-drop-panel] [role=button]") ?? null;
  const fire = (type: string, f: File, x: number, y: number) => {
    const z = zone();
    const b = box.current?.getBoundingClientRect();
    if (!z || !b || typeof DataTransfer === "undefined") return;
    const dt = new DataTransfer();
    dt.items.add(f);
    z.dispatchEvent(new DragEvent(type, { bubbles: true, cancelable: true, dataTransfer: dt, clientX: b.left + x, clientY: b.top + y }));
  };
  /* from the right of the zone, to its edge, then in; `edge` lingers on the near side so the well can lean out to it */
  const carry = (f: File, at: number, { edge = false, lane = 0, back = false } = {}) => {
    after(at, () => {
      const z = zone()?.getBoundingClientRect();
      const b = box.current?.getBoundingClientRect();
      if (!z || !b) return;
      const zx = z.left - b.left;
      const zy = z.top - b.top;
      const start = { x: Math.min(b.width - 40, zx + z.width + 120), y: zy + 30 + lane * 16 };
      const near = { x: zx + z.width + 30, y: zy + z.height * 0.45 };
      const inside = { x: zx + z.width * (edge ? 0.56 : 0.36), y: zy + Math.min(z.height * 0.5, 90) };
      const place = (x: number, y: number, r: number, o = 1) => setGhost({ x, y, r, o, s: 1, name: f.name, down: true });
      let entered = false;
      const go = (from: { x: number; y: number }, to: { x: number; y: number }, ms: number, r0: number, r1: number) =>
        tween(ms, (t) => {
          const x = from.x + (to.x - from.x) * t;
          const y = from.y + (to.y - from.y) * t;
          place(x, y, r0 + (r1 - r0) * t);
          const inZone = x > zx - 40 && x < zx + z.width + 40;
          if (inZone && !entered) {
            entered = true;
            fire("dragenter", f, x, y);
          }
          if (entered) fire("dragover", f, x, y);
        });
      place(start.x, start.y, 8);
      if (edge) {
        go(start, near, 620, 8, 4);
        after(920, () => go(near, inside, 700, 4, -2));
        after(1700, () => {
          fire("drop", f, inside.x, inside.y);
          if (back) tween(520, (t) => setGhost((g) => (g ? { ...g, x: inside.x + (start.x - inside.x) * t, y: inside.y - 40 * Math.sin(Math.PI * t) + (start.y - inside.y) * t, o: 1 - t * t, r: -2 + 14 * t, down: false } : g)));
          else tween(360, (t) => setGhost((g) => (g ? { ...g, s: 1 - 0.5 * t, o: 1 - t, y: inside.y + 18 * t, down: false } : g)));
        });
        after(2240, () => setGhost(null));
      } else {
        go(start, inside, 640, 10, 2);
        after(700, () => {
          setGhost(null);
          fire("drop", f, inside.x, inside.y);
        });
      }
    });
  };
  return { ghost, carry, stop };
}

/** The file in the hand, and the hand. */
function Carried({ ghost }: { ghost: Ghost | null }) {
  if (!ghost) return null;
  const dot = ghost.name.lastIndexOf(".");
  const tag = ghost.name.slice(dot + 1).toUpperCase();
  return (
    <div aria-hidden className="pointer-events-none absolute top-0 left-0 z-30" style={{ translate: `${ghost.x}px ${ghost.y}px` }}>
      <span className="absolute block h-[96px] w-[74px] -translate-x-1/2 -translate-y-1/2 rounded-[8px] bg-[var(--ns-raised)] shadow-[0_0_0_1px_var(--ns-line),0_14px_28px_-12px_rgb(0_0_0/0.4)]" style={{ rotate: `${ghost.r}deg`, scale: String(ghost.s), opacity: ghost.o }}>
        <span className="absolute inset-x-[14%] top-[16%] flex flex-col gap-[6px]">
          <span className="h-[4px] w-[70%] rounded-full bg-[var(--ns-ink-3)] opacity-40" />
          {[92, 84, 60].map((w) => (
            <span key={w} className="h-[3px] rounded-full bg-[var(--ns-line)]" style={{ width: `${w}%` }} />
          ))}
        </span>
        <span className="absolute bottom-[8%] left-[10%] rounded-[3px] bg-[var(--ns-signal-wash)] px-1 text-[9px] leading-[14px] font-semibold text-[var(--ns-signal-ink)]">{tag}</span>
      </span>
      <MousePointer2 className="absolute top-[30px] left-[22px] size-6 fill-[var(--ns-ink)] text-[var(--ns-raised)] drop-shadow-[0_2px_3px_rgb(0_0_0/0.3)] [transition:scale_120ms]" style={{ scale: ghost.down ? "0.9" : "1" }} />
    </div>
  );
}

function Look({ look, fail }: { look: FileDropLook; fail: boolean }) {
  const words = WORDS;
  const cvName = WORDS.cv;
  const less = useLessMotion();
  const settle = React.useContext(PlayOnce)?.settle ?? false;
  const quick = less || settle;
  const host = useHost(quick, fail, words.failed);
  const root = React.useRef<HTMLDivElement>(null);
  const hand = useHand(root);
  const play = useSelfPlay(root, { beats: [400], off: less });
  const big = React.useMemo(() => (look === "plain" ? sized(words.scan, 14 * MB, "image/png") : sized(words.big, 24.6 * MB, "application/pdf")), [look, words]);

  /* the arrival: once, then the visitor's; at once (the end) under less motion or a settled stage */
  const ran = React.useRef(false);
  React.useEffect(() => {
    if (play.step !== 0 || ran.current) return;
    ran.current = true;
    const cv = look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(cvName, 1.84 * MB, "application/pdf");
    if (quick) {
      host.change([cv]);
      return;
    }
    if (look === "well") hand.carry(cv, 0, { edge: true });
    if (look === "plain") {
      hand.carry(cv, 0);
      hand.carry(big, 2600);
    }
    if (look === "stack") {
      hand.carry(cv, 0, { lane: 0 });
      void fetch("https://notchset.dev/media/petals.webp")
        .then((r) => r.blob())
        .then((b) => hand.carry(sized(words.portfolio, b.size, "image/png", [b]), 850, { lane: 1 }))
        .catch(() => hand.carry(sized(words.portfolio, 3.2 * MB, "image/png"), 850, { lane: 1 }));
      hand.carry(big, 1700, { lane: 2 });
    }
  });
  /* the first touch is the visitor's: the hand lets go */
  React.useEffect(() => {
    if (play.mine) hand.stop();
  }, [play.mine, hand]);
  /* the quiet switch: turned on, the hand carries a file in and its upload fails part way (as every upload does while
     it is on) */
  const failed = React.useRef(fail);
  const sample = React.useMemo(() => (look === "plain" ? sized(words.notes, 1.8 * MB, "application/pdf") : sized(words.portfolio, 3.2 * MB, "image/png")), [look, words]);
  React.useEffect(() => {
    if (fail && !failed.current) {
      if (quick) hand.stop();
      hand.carry(sample, 0, { edge: look === "well", lane: 1 });
    }
    failed.current = fail;
  }, [fail, sample, hand, look, quick]);

  const drop = (
    <FileDrop
      look={look}
      label={look === "plain" ? words.attachments : undefined}
      hint={look === "plain" ? "PDF or images, up to 10 MB each" : LIMIT}
      accept={look === "plain" ? ".pdf,image/*" : ACCEPT}
      maxSize={10 * MB}
      multiple
      maxFiles={3}
      value={host.files}
      onValueChange={host.change}
      status={host.status}
      onRetry={host.retry}
    />
  );
  return (
    <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="relative flex w-full justify-center">
      {look === "plain" ? (
        <div className="w-full max-w-[400px]">
          <section className="flex h-[312px] w-full flex-col rounded-[var(--ns-radius-xl)] bg-[var(--ns-raised)] p-4 shadow-[var(--ns-bezel)]">{drop}</section>
        </div>
      ) : (
        <section className="flex w-[640px] max-w-full flex-col gap-5 rounded-[28px] bg-[var(--ns-raised)] p-7 shadow-[var(--ns-bezel),0_30px_60px_-40px_rgb(0_0_0/0.35)] max-sm:rounded-[22px] max-sm:p-4">
          <header className="flex flex-col gap-1.5">
            <p className="m-0 text-[13px] text-[var(--ns-ink-3)]">{words.role}</p>
            <h3 className="m-0 font-[family-name:var(--ns-font-display)] text-[30px] leading-[1.1] font-[number:var(--ns-weight-strong)] tracking-[-0.025em] text-[var(--ns-ink)] max-sm:text-[24px]">{words.title}</h3>
          </header>
          <div className={look === "well" ? "h-[300px] max-sm:h-[290px]" : "h-[300px] max-sm:h-[244px]"}>{drop}</div>
        </section>
      )}
      <Carried ghost={hand.ghost} />
    </div>
  );
}

export default function FileDropDemo() {
  const look = "well" as FileDropLook;
  const fail = false;
  return <Look key={look} look={look} fail={fail} />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `onFeedback` | `(e: FeedbackEvent) => void` |  | called once per move, for your sound or haptics |
| `label` | `React.ReactNode` |  | what the files are, heading the panel ("Attachments") |
| `hint` | `React.ReactNode` |  | what it takes ("PDF or images, up to 10 MB") |
| `value` | `File[]` |  | the chosen files (controlled, with onValueChange) |
| `defaultValue` | `File[]` | `[]` | the files at first (uncontrolled) |
| `onValueChange` | `(files: File[]) => void` |  | the files after each change |
| `onReject` | `(rejected: Rejected[]) => void` |  | the files left out of the last add, with why |
| `accept` | `string` |  | types and extensions (".csv", "image/*") |
| `maxSize` | `number` |  | the largest file, in bytes |
| `multiple` | `boolean` | `false` | take several files (one by default) |
| `maxFiles` | `number` |  | the most files, with `multiple` |
| `disabled` | `boolean` |  | refuses drops and the picker |
| `status` | `(file: File) => FileStatus \| undefined` |  | each file's upload, if the host uploads them |
| `onRetry` | `(file: File) => void` |  | a failed file's Retry |
| `locale` | `string` | `DEFAULT_LOCALE` | the locale sizes are written in |
| `look` | `FileDropLook` | `"plain"` | "plain" (the form default), or a public form's showpiece: "well" (its edges bend to a held file) or "stack" (a pile of cards) |
| `labels` | `Partial<FileDropLabels>` |  | its words ({name}, {size}, {max}, {accept}, {percent} blanks) |

Full docs: https://notchset.dev/components/file-drop

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Keyboard

| Keys | Action |
|---|---|
| Enter or Space | open the file picker |
| Ctrl V or ⌘V | with the zone focused, paste files |
| Tab | each listed file's Remove button |

## Performance

- Checks each file against accept and size by name and size only; it never reads file contents.
- Installs with lucide-react (2 files, about 14 kB).
- Previews, hashing and upload belong to your code; run them outside render.

## Responsive

- phone: the system picker (camera, photos, files)
- desktop: drop and paste
- dark (tokens)

## Motion inventory

| Interaction | What moves |
|---|---|
| a refused file's line and a failed row shake once | ns-play-shake 360ms on --ns-ease. Reduced motion: a fade (data-ns-moves). |
| the slim bar's words fade in | ns-fade on --ns-time-panel, --ns-ease. Reduced motion: already only a fade; it stays. |
| a done or failed file's mark springs in | ns-play-spring on --ns-time-spring, --ns-ease-pop. Reduced motion: the list's mark fades (data-ns-play); the well's and the tray's still spring (no reduced form there yet). |
| the drop zone's wash and edge change as a file comes over | background-color and box-shadow on --ns-time-menu. Reduced motion: the same colour change (nothing moves). |
| the prompt folds to a slim bar once files are chosen | --ns-time-panel on --ns-ease-panel. Reduced motion: same height change, no glide. |

## Accessibility contract (preserve when editing)
- The zone is one button named by its label and prompt, described by the hint; each listed file has a Remove button named for it; rejections are read once from a status list.

## Install

```bash
# npm
npx shadcn@latest add https://notchset.dev/r/file-drop.json
# pnpm
pnpm dlx shadcn@latest add https://notchset.dev/r/file-drop.json
# yarn
yarn dlx shadcn@latest add https://notchset.dev/r/file-drop.json
# bun
bunx --bun shadcn@latest add https://notchset.dev/r/file-drop.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/file-drop`. Every components.json style gets the same files.

### Manual

1. Install the packages: `npm install lucide-react@^1`.
2. Copy `components/ui/notchset/file-drop.tsx`, `lib/notchset/feedback.ts`, `lib/notchset/file-size.ts`, `lib/notchset/icons.ts`, `lib/notchset/keep-focus.ts`, `lib/notchset/motion.ts`, `lib/notchset/words.ts` from https://notchset.dev/r/file-drop.json (each file's `content`, at its `target`), keeping the `@/` path alias of your tsconfig.
3. Add what it builds on: shadcn `utils` (cn), `notchset-foundation`, `rolling-number`, `tooltip`.

## Continue the workflow

- [Code input](https://notchset.dev/components/code-input)
- [Expanding search](https://notchset.dev/components/expanding-search)
- [Field](https://notchset.dev/components/field)

## Source

### components/ui/notchset/file-drop.tsx

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { Check, CircleAlert, File as FileIcon, FileImage, FileUp, Plus, X } from "@/lib/notchset/icons";
import { cn } from "@/lib/utils";
import { landFocus } from "@/lib/notchset/keep-focus";
import { useLessMotion } from "@/lib/notchset/motion";
import { RollingNumber } from "@/components/ui/notchset/rolling-number";
import { DEFAULT_LOCALE, fill } from "@/lib/notchset/words";
import { Tooltip } from "@/components/ui/notchset/tooltip";
import type { FeedbackProps } from "@/lib/notchset/feedback";
import { formatBytes } from "@/lib/notchset/file-size";

const useIsomorphicLayoutEffect = typeof window === "undefined" ? React.useEffect : React.useLayoutEffect;

/*
 * File drop: choose, drop or paste (⌘V) files. Each is checked against `accept`, `maxSize` and `maxFiles` first; one
 * left out is named with why ("report.pdf is 14 MB; the limit is 10 MB"), the rest go to `onValueChange`. Uploading is
 * the host's `status`: progress, `done` (a green tick settles on the file's own mark, its size beside it) or `error`
 * (red, a cross, one shake, a Retry calling `onRetry`). A long name is cut in the middle, so its end and extension stay.
 * Three looks, one behaviour:
 * - plain (the form default): the label heads the panel; a dashed zone (it lights and its mark lifts while files are
 *   held over), then a row per file; with files the zone folds to a quiet solid "Add more" row.
 * - well (a public form): the well's edges bend toward a file held over it, on a spring; a taken file swells it once,
 *   its row grows in under the well with its rule as the progress, a green tick lands, and the well tidies to "Add
 *   more". A refused file shakes the well; its reason is said in rose.
 * - stack (a public form): files land as a fanned pile of typed cards (a page with its tag, or the image's own
 *   thumbnail); the count rolls; a refused file lands on the pile and bounces back out, its reason said in rose.
 * The zone is one button, named by its prompt. Less motion: nothing bends, falls or bounces; the result is there.
 */
type FileDropLabels = {
  prompt: string;
  browse: string;
  more: string;
  retry: string;
  dragging: string;
  remove: string;
  done: string;
  type: string;
  size: string;
  count: string;
  /** several refused at once, summed on one line ({count}; and {max} or {accept} when they share one reason) */
  countSome: string;
  sizeSome: string;
  typeSome: string;
  refusedSome: string;
  /** the stack's count, one file and several */
  one: string;
  many: string;
  /** a file still going up, in the well's row ({percent}) */
  sending: string;
};
const FILE_DROP_LABELS: FileDropLabels = {
  prompt: "Drop files here, or",
  browse: "choose files",
  more: "Add more",
  retry: "Retry",
  dragging: "Let go to add",
  done: "Added",
  remove: "Remove {name}",
  type: "{name} isn’t a file this takes. Choose {accept}.",
  size: "{name} is {size}; the limit is {max}.",
  count: "{name} wasn’t added: up to {max} files.",
  countSome: "{count} files weren’t added: up to {max} files.",
  sizeSome: "{count} files weren’t added: the limit is {max}.",
  typeSome: "{count} files weren’t added. Choose {accept}.",
  refusedSome: "{count} files weren’t added.",
  one: "file",
  many: "files",
  sending: "Uploading · {percent}%",
};

type FileDropLook = "plain" | "well" | "stack";
type Rejected = { file: File; reason: string };
/* a refusal as drawn: which reason, and the words its sentence is filled with */
type Refused = Rejected & { kind: "type" | "size" | "count"; vars: Record<string, string | number> };
/** One file's upload: `progress` 0 to 1, `done` (or progress 1), `error` (why it failed). */
type FileStatus = { progress?: number | undefined; done?: boolean | undefined; error?: string | undefined };

type FileDropProps = FeedbackProps & {
  /** what the files are, heading the panel ("Attachments") */
  label?: React.ReactNode;
  /** what it takes ("PDF or images, up to 10 MB") */
  hint?: React.ReactNode;
  /** the chosen files (controlled, with onValueChange) */
  value?: File[] | undefined;
  /** the files at first (uncontrolled) */
  defaultValue?: File[] | undefined;
  /** the files after each change */
  onValueChange?: ((files: File[]) => void) | undefined;
  /** the files left out of the last add, with why */
  onReject?: ((rejected: Rejected[]) => void) | undefined;
  /** types and extensions (".csv", "image/*") */
  accept?: string | undefined;
  /** the largest file, in bytes */
  maxSize?: number | undefined;
  /** take several files (one by default) */
  multiple?: boolean | undefined;
  /** the most files, with `multiple` */
  maxFiles?: number | undefined;
  /** refuses drops and the picker */
  disabled?: boolean | undefined;
  /** each file's upload, if the host uploads them */
  status?: ((file: File) => FileStatus | undefined) | undefined;
  /** a failed file's Retry */
  onRetry?: ((file: File) => void) | undefined;
  /** the locale sizes are written in */
  locale?: string | undefined;
  /** "plain" (the form default), or a public form's showpiece: "well" (its edges bend to a held file) or "stack" (a pile of cards) */
  look?: FileDropLook | undefined;
  /** its words ({name}, {size}, {max}, {accept}, {percent} blanks) */
  labels?: Partial<FileDropLabels> | undefined;
  className?: string | undefined;
};

/** Whether a file matches an accept list. */
function accepts(file: File, accept: string | undefined): boolean {
  if (!accept) return true;
  const name = file.name.toLowerCase();
  const type = file.type.toLowerCase();
  return accept.split(",").some((raw) => {
    const a = raw.trim().toLowerCase();
    if (!a) return false;
    if (a.startsWith(".")) return name.endsWith(a);
    if (a.endsWith("/*")) return type.startsWith(a.slice(0, -1));
    return type === a;
  });
}

/**
 * Where a long name is cut: the head gives way first, the tail (its last word with the extension, or the extension and
 * four letters before it when that word is long) is kept whole: "Portfol… 2026.png".
 */
function splitName(name: string): [head: string, tail: string] {
  const dot = name.lastIndexOf(".");
  const ext = dot > 0 ? name.length - dot : 0;
  const space = name.lastIndexOf(" ");
  const keep = space > 0 && name.length - space <= ext + 9 ? name.length - space : Math.min(name.length, ext + 4);
  return [name.slice(0, name.length - keep), name.slice(name.length - keep)];
}

/** Several refusals as one sentence: their shared reason when they have one, else only how many. */
function refusedLine(all: Refused[], L: FileDropLabels): string {
  const kind = all.every((r) => r.kind === all[0]!.kind) ? all[0]!.kind : null;
  const vars = { count: all.length, ...(kind ? all[0]!.vars : {}) };
  return fill(kind === "count" ? L.countSome : kind === "size" ? L.sizeSome : kind === "type" ? L.typeSome : L.refusedSome, vars);
}

/** A file's name, cut in the middle when it runs long; the whole name is read out and shown on hover. */
function MiddleName({ name, className }: { name: string; className?: string }) {
  const [head, tail] = splitName(name);
  return (
    <Tooltip label={name} truncated>
      <span data-slot="file-drop-name" className={cn("flex min-w-0", className)}>
        <span className="min-w-0 overflow-hidden text-ellipsis whitespace-pre">{head}</span>
        <span className="shrink-0 whitespace-pre">{tail}</span>
      </span>
    </Tooltip>
  );
}

const useControlledFiles = (value: File[] | undefined, initial: File[]) => {
  const [own, setOwn] = React.useState(initial);
  return [value ?? own, setOwn] as const;
};

/** Each file's progress, done and error, read once from the host. */
function readStatus(st: FileStatus | undefined) {
  const error = st?.error;
  const done = !error && Boolean(st?.done || (st?.progress ?? 0) >= 1);
  const up = !done && !error && st?.progress !== undefined;
  return { error, done, up, progress: up ? st!.progress! : done ? 1 : 0 };
}

/** An image file's own thumbnail, made once and let go with the piece. */
function useThumbs() {
  const made = React.useRef(new Map<File, string>());
  React.useEffect(() => {
    const own = made.current;
    return () => {
      own.forEach((u) => URL.revokeObjectURL(u));
      own.clear();
    };
  }, []);
  return (f: File) => {
    if (!f.type.startsWith("image/") || typeof URL.createObjectURL !== "function" || f.size === 0) return undefined;
    let u = made.current.get(f);
    if (!u) {
      try {
        u = URL.createObjectURL(f);
      } catch {
        return undefined;
      }
      made.current.set(f, u);
    }
    return u;
  };
}

const SHAKE: Keyframe[] = [{ translate: "0 0" }, { translate: "-6px 0" }, { translate: "6px 0" }, { translate: "-4px 0" }, { translate: "3px 0" }, { translate: "0 0" }];
const EASE_OUT = "cubic-bezier(0.22, 1, 0.36, 1)";
/* the stack's cards each sit on their own turn */
const TURN = [-8, 6, -3, 9, -6, 4];

const FileDrop = React.forwardRef<HTMLDivElement, FileDropProps>(function FileDrop(
  { label, hint, value, defaultValue = [], onValueChange, onReject, status, onRetry, accept, maxSize, multiple = false, maxFiles, disabled, locale = DEFAULT_LOCALE, look = "plain", labels, className, onFeedback },
  ref,
) {
  const L = { ...FILE_DROP_LABELS, ...labels };
  const [files, setOwn] = useControlledFiles(value, defaultValue);
  const [over, setOver] = React.useState(false);
  const [rejected, setRejected] = React.useState<Refused[]>([]);
  const input = React.useRef<HTMLInputElement>(null);
  const zone = React.useRef<HTMLDivElement>(null);
  const id = React.useId();
  const less = useLessMotion();
  const limit = multiple ? (maxFiles ?? Infinity) : 1;
  const acceptWords = (accept ?? "").split(",").map((a) => a.trim()).filter(Boolean).join(", ");
  /* the well: where a held file is (the zone's box), and a swell to give it as a file is taken */
  const pointer = React.useRef<{ x: number; y: number } | null>(null);
  const well = React.useRef<WellHandle>(null);
  /* the stack: where each new file was let go (the zone's box), and the file bouncing back out */
  const [landed] = React.useState(() => new WeakMap<File, { x: number; y: number }>());
  const [bounce, setBounce] = React.useState<{ file: File; x: number; y: number; n: number } | null>(null);

  const take = (list: FileList | File[] | null, at?: { x: number; y: number }) => {
    if (!list || disabled) return;
    const out: Refused[] = [];
    const next = multiple ? [...files] : [];
    const refuse = (file: File, kind: Refused["kind"], vars: Record<string, string | number>) => out.push({ file, kind, vars, reason: fill(L[kind], { name: file.name, ...vars }) });
    for (const file of Array.from(list)) {
      if (!accepts(file, accept)) refuse(file, "type", { accept: acceptWords });
      else if (maxSize !== undefined && file.size > maxSize) refuse(file, "size", { size: formatBytes(file.size, locale), max: formatBytes(maxSize, locale) });
      else if (next.length >= limit) refuse(file, "count", { max: limit });
      else {
        next.push(file);
        if (at) landed.set(file, at);
      }
    }
    setRejected(out);
    if (out.length) {
      onFeedback?.("error");
      onReject?.(out.map(({ file, reason }) => ({ file, reason })));
      if (look === "well" && !less) zone.current?.animate?.(SHAKE, { duration: 300, easing: "ease-out" });
      if (look === "stack" && at && !less) setBounce((b) => ({ file: out[0]!.file, x: at.x, y: at.y, n: (b?.n ?? 0) + 1 }));
    }
    /* a refused replacement keeps the single file already chosen */
    if (!multiple && !next.length) return;
    if (next.length !== files.length || next.some((f, i) => f !== files[i])) {
      onFeedback?.("add");
      if (look === "well" && !less) well.current?.swell();
      setOwn(next);
      onValueChange?.(next);
    }
  };
  const remove = (file: File, row: HTMLElement | null) => {
    const next = files.filter((f) => f !== file);
    onFeedback?.("remove");
    setOwn(next);
    onValueChange?.(next);
    /* focus goes to the next row's Remove, else the one before, else the zone */
    const list = row?.parentElement;
    const at = row ? Array.from(list?.children ?? []).indexOf(row) : -1;
    landFocus(() => {
      const rows = Array.from(list?.querySelectorAll<HTMLElement>(":scope > li") ?? []).filter((r) => r.isConnected);
      const goes = rows[at] ?? rows[at - 1];
      return goes?.querySelector<HTMLElement>("[data-slot=file-drop-remove]") ?? zone.current;
    });
  };
  /* focus stays in the row, on its Remove */
  const retry = (file: File, row: HTMLElement | null) => {
    onFeedback?.("press");
    onRetry?.(file);
    landFocus(() => row?.querySelector<HTMLElement>("[data-slot=file-drop-remove]"));
  };
  const slim = files.length > 0;
  const open = () => !disabled && input.current?.click();
  const point = (e: React.DragEvent) => {
    const r = e.currentTarget.getBoundingClientRect();
    return { x: e.clientX - r.left, y: e.clientY - r.top };
  };
  const thumb = useThumbs();

  const zoneProps = {
    ref: zone,
    role: "button",
    tabIndex: disabled ? -1 : 0,
    "aria-disabled": disabled || undefined,
    "aria-labelledby": label ? `${id}-l ${id}-p` : `${id}-p`,
    "aria-describedby": hint ? `${id}-h` : undefined,
    "data-dragging": over ? "" : undefined,
    "data-slim": slim ? "" : undefined,
    onClick: open,
    onKeyDown: (e: React.KeyboardEvent) => {
      if (e.key === "Enter" || e.key === " ") {
        e.preventDefault();
        open();
      }
    },
    onPaste: (e: React.ClipboardEvent) => {
      if (e.clipboardData.files.length) {
        e.preventDefault();
        take(e.clipboardData.files);
      }
    },
    onDragEnter: (e: React.DragEvent) => {
      e.preventDefault();
      if (!disabled) setOver(true);
    },
    onDragOver: (e: React.DragEvent) => {
      e.preventDefault();
      if (look === "well" && !disabled) {
        pointer.current = point(e);
        well.current?.wake();
      }
    },
    onDragLeave: (e: React.DragEvent) => {
      if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
      setOver(false);
      pointer.current = null;
      well.current?.wake();
    },
    onDrop: (e: React.DragEvent) => {
      e.preventDefault();
      setOver(false);
      pointer.current = null;
      well.current?.wake();
      take(e.dataTransfer.files, point(e));
    },
  } as const;
  const picker = (
    <input
      ref={input}
      type="file"
      hidden
      accept={accept}
      multiple={multiple}
      disabled={disabled}
      onChange={(e) => {
        take(e.target.files);
        e.target.value = "";
      }}
    />
  );
  const prompt = (
    <>
      {L.prompt} <span className="text-[var(--ns-ink)] underline decoration-[var(--ns-line)] underline-offset-4">{L.browse}</span>
    </>
  );
  const heading = label && (
    <span id={`${id}-l`} data-slot="file-drop-label" className="w-fit text-[length:var(--ns-text-body)] font-[number:var(--ns-weight-strong)] text-[var(--ns-ink)]">
      {label}
    </span>
  );
  const reasons = (
    <>
      {rejected.length > 0 ? (
        /* one line inside the card, however many were refused: one names its file (cut in the middle like the rows),
           several are summed; the whole list stays a hover away and goes to the host through onReject */
        <p role="status" data-slot="file-drop-rejected" data-ns-moves="" title={rejected.length > 1 ? rejected.map((r) => r.reason).join("\n") : undefined}
          className="[animation:ns-play-shake_360ms_var(--ns-ease)] m-0 flex min-w-0 items-center gap-1 overflow-hidden text-[length:var(--ns-text-meta)] leading-4 whitespace-nowrap text-[var(--ns-bad-ink)]">
          <CircleAlert aria-hidden className="size-3 shrink-0" />
          {rejected.length === 1 ? (
            L[rejected[0]!.kind].split(/(\{name\})/).map((part, i) =>
              part === "{name}" ? (
                <MiddleName key={i} name={rejected[0]!.file.name} className="min-w-0 shrink" />
              ) : part ? (
                <span key={i} className="shrink-0 whitespace-pre">{fill(part, rejected[0]!.vars)}</span>
              ) : null,
            )
          ) : (
            <span className="min-w-0 truncate">{refusedLine(rejected, L)}</span>
          )}
        </p>
      ) : hint ? (
        <p id={`${id}-h`} className="m-0 text-[length:var(--ns-text-meta)] leading-4 text-[var(--ns-ink-3)]">
          {hint}
        </p>
      ) : null}
    </>
  );

  if (look === "well")
    return (
      <div ref={ref} data-slot="file-drop" data-look="well" className={cn("flex min-w-0 flex-col gap-3 text-[length:var(--ns-text-small)] text-[var(--ns-ink-2)]", className)}>
        {heading}
        <div data-slot="file-drop-panel" data-disabled={disabled ? "" : undefined} className={cn("flex flex-col", disabled && "opacity-45")}>
          <div
            {...zoneProps}
            data-swipe-off=""
            className={cn(
              "relative flex cursor-pointer items-center justify-center gap-3 rounded-[18px] text-center outline-hidden [transition:height_420ms_var(--ns-ease-move),background-color_var(--ns-time-menu)] focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[var(--ns-signal)] motion-reduce:transition-none",
              slim ? "h-16" : "h-[220px] max-sm:h-[180px]",
              over && "bg-[color-mix(in_oklab,var(--ns-signal)_5%,transparent)]",
              disabled && "cursor-default",
            )}
          >
            <WellEdge ref={well} zone={zone} pointer={pointer} over={over} still={less} />
            {slim ? (
              <span key="more" id={`${id}-p`} className="flex items-center gap-2 text-[15px] text-[var(--ns-ink)] [animation:ns-fade_var(--ns-time-panel)_var(--ns-ease)]">
                <Plus aria-hidden className="size-4 text-[var(--ns-ink-2)]" />
                {over ? L.dragging : L.more}
              </span>
            ) : (
              <span key="open" className="flex flex-col items-center gap-3">
                <span aria-hidden className={cn("grid size-12 place-items-center rounded-full bg-[var(--ns-well)] text-[var(--ns-ink-2)] [transition:scale_var(--ns-time-panel)_var(--ns-ease-spring),background-color_var(--ns-time-menu)] [&_svg]:size-5", over && "scale-110 bg-[color-mix(in_oklab,var(--ns-signal)_12%,transparent)] text-[var(--ns-signal-ink)]")}>
                  <FileUp />
                </span>
                <span id={`${id}-p`} className="text-[16px] text-[var(--ns-ink-2)]">
                  {over ? L.dragging : prompt}
                </span>
              </span>
            )}
            {picker}
          </div>
          {slim && (
            <ul data-slot="file-drop-files" className="m-0 mt-3 flex list-none flex-col p-0">
              {files.map((f, i) => (
                <WellRow key={`${f.name}-${i}`} file={f} st={readStatus(status?.(f))} L={L} locale={locale} disabled={disabled} still={less} onRemove={(row) => remove(f, row)} onRetry={(row) => retry(f, row)} />
              ))}
            </ul>
          )}
        </div>
        {reasons}
      </div>
    );

  if (look === "stack") {
    const shown = files.slice(-6);
    return (
      <div ref={ref} data-slot="file-drop" data-look="stack" className={cn("flex min-w-0 flex-col gap-3 text-[length:var(--ns-text-small)] text-[var(--ns-ink-2)]", className)}>
        {heading}
        <div data-slot="file-drop-panel" data-disabled={disabled ? "" : undefined} className={cn("flex flex-col", disabled && "opacity-45")}>
          <div
            {...zoneProps}
            data-swipe-off=""
            className={cn(
              "group/tray relative flex h-[256px] cursor-pointer items-center gap-6 rounded-[18px] px-5 outline-hidden [transition:background-color_var(--ns-time-menu),box-shadow_var(--ns-time-menu)] focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[var(--ns-signal)] max-sm:h-[200px] max-sm:gap-3 max-sm:px-3",
              slim ? "bg-[var(--ns-well)]" : "shadow-[inset_0_0_0_1.25px_var(--ns-field-edge)]",
              over && "bg-[color-mix(in_oklab,var(--ns-signal)_6%,var(--ns-well))] shadow-[inset_0_0_0_1.5px_var(--ns-signal)]",
              disabled && "cursor-default",
            )}
          >
            <div aria-hidden className={cn("relative h-[214px] shrink-0 max-sm:h-[160px]", slim ? "w-[320px] max-sm:w-[132px]" : "w-0")}>
              {shown.map((f, i) => (
                <StackCard key={`${f.name}-${files.indexOf(f)}`} file={f} i={i} thumb={thumb(f)} st={readStatus(status?.(f))} from={landed.get(f)} zone={zone} still={less} />
              ))}
            </div>
            {slim ? (
              <div className="flex min-w-0 flex-1 flex-col gap-2">
                <p className="m-0 flex items-baseline gap-2 text-[var(--ns-ink)]">
                  <span className="font-[family-name:var(--ns-font-display)] text-[44px] leading-none font-[number:var(--ns-weight-strong)] tracking-[-0.03em] tabular-nums max-sm:text-[34px]">
                    <RollingNumber value={String(files.length)} />
                  </span>
                  <span className="text-[15px] text-[var(--ns-ink-2)]">{files.length === 1 ? L.one : L.many}</span>
                </p>
                <ul data-slot="file-drop-files" className="m-0 flex list-none flex-col gap-0.5 p-0" onClick={(e) => e.stopPropagation()} onKeyDown={(e) => e.stopPropagation()}>
                  {files.slice(-3).map((f) => {
                    const st = readStatus(status?.(f));
                    return (
                      <li key={`${f.name}-${files.indexOf(f)}`} className="group/name flex min-w-0 items-center gap-1 text-[13px] text-[var(--ns-ink-2)]">
                        <MiddleName name={f.name} className={cn(st.error && "text-[var(--ns-bad-ink)]")} />
                        {st.error && onRetry ? (
                          <button type="button" onClick={(e) => retry(f, e.currentTarget.closest("li"))} className="relative shrink-0 cursor-pointer text-[var(--ns-ink)] underline decoration-[var(--ns-line)] underline-offset-2 outline-hidden pointer-coarse:after:absolute pointer-coarse:after:-inset-3 pointer-coarse:after:content-[''] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)]">
                            {L.retry}
                          </button>
                        ) : null}
                        <button
                          type="button"
                          data-slot="file-drop-remove"
                          aria-label={fill(L.remove, { name: f.name })}
                          disabled={disabled}
                          onClick={(e) => remove(f, e.currentTarget.closest("li"))}
                          className="relative grid size-6 shrink-0 cursor-pointer place-items-center rounded-[var(--ns-radius-sm)] text-[var(--ns-ink-3)] opacity-0 outline-hidden group-hover/name:opacity-100 hover:bg-[var(--ns-hover)] hover:text-[var(--ns-ink)] focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] pointer-coarse:opacity-100 pointer-coarse:after:absolute pointer-coarse:after:-inset-2.5 pointer-coarse:after:content-[''] [&_svg]:size-3"
                        >
                          <X aria-hidden />
                        </button>
                      </li>
                    );
                  })}
                </ul>
                <span id={`${id}-p`} className="w-fit text-[13px] text-[var(--ns-ink)] underline decoration-[var(--ns-line)] underline-offset-4">
                  {over ? L.dragging : L.more}
                </span>
              </div>
            ) : (
              <span className="flex flex-1 flex-col items-center gap-3 text-center">
                <span aria-hidden className={cn("grid size-12 place-items-center rounded-full bg-[var(--ns-well)] text-[var(--ns-ink-2)] [transition:scale_var(--ns-time-panel)_var(--ns-ease-spring)] [&_svg]:size-5", over && "scale-110")}>
                  <FileUp />
                </span>
                <span id={`${id}-p`} className="text-[16px] text-[var(--ns-ink-2)]">
                  {over ? L.dragging : prompt}
                </span>
              </span>
            )}
            {bounce ? <Bounce key={bounce.n} file={bounce.file} thumb={thumb(bounce.file)} at={bounce} onDone={() => setBounce(null)} /> : null}
            {picker}
          </div>
        </div>
        {reasons}
      </div>
    );
  }

  return (
    <div ref={ref} data-slot="file-drop" data-look="plain" className={cn("flex min-w-0 flex-col gap-1.5 text-[length:var(--ns-text-small)] text-[var(--ns-ink-2)]", className)}>
      <div data-slot="file-drop-panel" data-disabled={disabled ? "" : undefined} className={cn("flex flex-col gap-2", disabled && "opacity-45")}>
        {heading}
        <div
          {...zoneProps}
          className={cn(
            "group flex cursor-pointer items-center justify-center gap-2 rounded-[var(--ns-radius)] border-[1.5px] px-4 text-center text-[var(--ns-ink-3)] outline-hidden [transition:border-color_var(--ns-time-color),background-color_var(--ns-time-color),scale_var(--ns-time-color),min-height_var(--ns-time-panel)_var(--ns-ease-panel)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ns-signal)]",
            slim ? "min-h-10 border-transparent bg-[var(--ns-well)]" : "min-h-28 flex-col border-dashed border-[var(--ns-field-edge)] bg-[var(--ns-field)] py-4",
            over && "scale-[1.015] border-dashed border-[var(--ns-signal)] bg-[var(--ns-signal-wash)] text-[var(--ns-ink-2)] motion-reduce:scale-100",
            !over && !disabled && (slim ? "hover:bg-[var(--ns-hover)]" : "hover:border-[var(--ns-ink-2)]"),
            disabled && "cursor-default",
          )}
        >
          {slim ? (
            <Plus aria-hidden className="size-[var(--ns-icon)] shrink-0 text-[var(--ns-ink-2)]" />
          ) : (
            <span aria-hidden data-ns-glide="" className={cn("grid size-10 shrink-0 place-items-center rounded-full bg-[var(--ns-panel)] text-[var(--ns-signal-ink)] shadow-[0_0_0_1px_var(--ns-line-soft)] [transition:translate_var(--ns-time-color)_var(--ns-ease)]", over && "-translate-y-[3px]")}>
              <FileUp className="size-[18px]" />
            </span>
          )}
          <span id={`${id}-p`} className={cn("min-w-0", !slim && "text-[var(--ns-ink)]")}>
            {over ? (
              L.dragging
            ) : slim ? (
              <span className="text-[var(--ns-ink)]">{L.more}</span>
            ) : (
              <>
                {L.prompt} <span className="text-[var(--ns-signal-ink)] underline decoration-[var(--ns-line)] underline-offset-2">{L.browse}</span>
              </>
            )}
          </span>
          {picker}
        </div>
        {slim && (
          <ul data-slot="file-drop-files" className="m-0 flex list-none flex-col p-0">
            {files.map((f, i) => {
              const st = readStatus(status?.(f));
              const Glyph = f.type.startsWith("image/") ? FileImage : FileIcon;
              const tone = st.error ? "var(--ns-bad)" : st.up ? "var(--ns-signal)" : undefined;
              return (
                <li key={`${f.name}-${i}`} data-ns-moves="" className={cn("flex min-h-14 items-center gap-3 border-t border-[var(--ns-line)] px-0.5 py-2 text-[var(--ns-ink)]", st.error && "[animation:ns-play-shake_360ms_var(--ns-ease)]")}>
                  <span aria-hidden className="relative grid size-8 shrink-0 place-items-center rounded-[var(--ns-radius)] bg-[var(--ns-well)] text-[var(--ns-ink-2)] transition-colors [&>svg]:size-4" style={tone ? { background: `color-mix(in oklab, ${tone} 14%, transparent)`, color: tone } : undefined}>
                    {st.error ? (
                      <span key="x" data-ns-play="" className="grid size-6 place-items-center rounded-full text-[var(--ns-panel)] [animation:ns-play-spring_380ms_var(--ns-ease)] [&>svg]:size-3.5" style={{ background: tone }}>
                        <X strokeWidth={3} />
                      </span>
                    ) : (
                      <Glyph />
                    )}
                    {st.done ? (
                      <span data-slot="file-drop-tick" data-ns-play="" className="absolute -end-[5px] -bottom-[5px] grid size-4 place-items-center rounded-full bg-[var(--ns-ok)] text-white shadow-[0_0_0_2px_var(--ns-raised)] [animation:ns-play-spring_var(--ns-time-spring)_var(--ns-ease-pop)_both] [&>svg]:size-2.5">
                        <Check strokeWidth={4} />
                      </span>
                    ) : null}
                  </span>
                  <span className="flex min-w-0 flex-1 flex-col gap-0.5">
                    <MiddleName name={f.name} />
                    {st.error ? (
                      <span role="status" className="flex items-center gap-1.5 text-[length:var(--ns-text-meta)] text-[var(--ns-bad-ink)]">
                        <span className="min-w-0 truncate">{st.error}</span>
                        <button type="button" onClick={(e) => retry(f, e.currentTarget.closest("li"))} className="relative shrink-0 cursor-pointer rounded-[var(--ns-radius-xs)] pointer-coarse:after:absolute pointer-coarse:after:-inset-3 pointer-coarse:after:content-[''] text-[var(--ns-ink)] underline decoration-[var(--ns-line)] underline-offset-2 outline-hidden hover:decoration-[var(--ns-ink-2)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)]">
                          {L.retry}
                        </button>
                      </span>
                    ) : st.up ? (
                      <span className="flex items-center gap-2 text-[length:var(--ns-text-meta)] text-[var(--ns-ink-3)] tabular-nums">
                        <span role="progressbar" aria-label={f.name} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(st.progress * 100)} className="h-1.5 min-w-12 flex-1 overflow-hidden rounded-full bg-[var(--ns-well)]">
                          {/* the fill follows the host's progress as it comes, with no transition of its own: a host that reports every
                            frame would restart a transition each frame, and the fill would never leave its start */}
                          <span className="block h-full rounded-full bg-[linear-gradient(90deg,transparent,var(--ns-signal))] shadow-[0_0_10px_var(--ns-signal)]" style={{ width: `${st.progress * 100}%` }} />
                        </span>
                        {Math.round(st.progress * 100)}% · {formatBytes(f.size, locale)}
                      </span>
                    ) : (
                      <span className="text-[length:var(--ns-text-meta)] text-[var(--ns-ink-3)] tabular-nums">
                        {st.done && <span className="sr-only">{L.done} · </span>}
                        {formatBytes(f.size, locale)}
                      </span>
                    )}
                  </span>
                  <button
                    type="button"
                    data-slot="file-drop-remove"
                    aria-label={fill(L.remove, { name: f.name })}
                    disabled={disabled}
                    onClick={(e) => remove(f, e.currentTarget.closest("li"))}
                    className="relative grid size-6 shrink-0 cursor-pointer place-items-center rounded-[var(--ns-radius-sm)] text-[var(--ns-ink-3)] outline-hidden pointer-coarse:after:absolute pointer-coarse:after:-inset-2.5 pointer-coarse:after:content-[''] hover:bg-[var(--ns-hover)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)]"
                  >
                    <X aria-hidden className="size-3.5" />
                  </button>
                </li>
              );
            })}
          </ul>
        )}
      </div>
      {reasons}
    </div>
  );
});

type WellHandle = { wake: () => void; swell: () => void };
type Edge = { a: number; v: number; at: number };
const MAXPULL = 32;

/**
 * The well's edge, drawn live: each side bends toward a file held over the well (outside, the near side leans out to
 * meet it; inside, all four bow in round it), on a spring loose enough to swell once when it lets go.
 */
const WellEdge = React.forwardRef<WellHandle, { zone: React.RefObject<HTMLDivElement | null>; pointer: React.RefObject<{ x: number; y: number } | null>; over: boolean; still: boolean }>(function WellEdge({ zone, pointer, over, still }, ref) {
  const path = React.useRef<SVGPathElement>(null);
  const edges = React.useRef<Edge[]>([0, 1, 2, 3].map(() => ({ a: 0, v: 0, at: 0.5 })));
  const loop = React.useRef(0);
  const draw = React.useCallback(() => {
    const el = zone.current;
    const p = path.current;
    if (!el || !p) return false;
    const W = el.offsetWidth;
    const H = el.offsetHeight;
    const r = 18;
    const q = still ? null : pointer.current;
    let moving = false;
    edges.current.forEach((e, i) => {
      let target = 0;
      if (q) {
        const [d, along, out] = i === 0 ? [Math.abs(q.y), q.x / W, q.y < 0] : i === 1 ? [Math.abs(q.x - W), q.y / H, q.x > W] : i === 2 ? [Math.abs(q.y - H), q.x / W, q.y > H] : [Math.abs(q.x), q.y / H, q.x < 0];
        target = (out ? 1 : -0.55) * MAXPULL * Math.exp(-d / 110);
        e.at += (Math.min(0.8, Math.max(0.2, along)) - e.at) * 0.25;
      } else e.at += (0.5 - e.at) * 0.1;
      if (still) {
        e.a = 0;
        e.v = 0;
      } else {
        e.v = (e.v + (target - e.a) * 0.14) * 0.8;
        e.a += e.v;
      }
      if (Math.abs(e.v) > 0.02 || Math.abs(target - e.a) > 0.05) moving = true;
    });
    const [t, rt, b, l] = edges.current as [Edge, Edge, Edge, Edge];
    const q2 = (cx: number, cy: number, x: number, y: number) => `Q ${cx.toFixed(1)} ${cy.toFixed(1)} ${x.toFixed(1)} ${y.toFixed(1)}`;
    p.setAttribute(
      "d",
      [
        `M ${r} 0`,
        q2(r + (W - 2 * r) * t.at, -2 * t.a, W - r, 0),
        `Q ${W} 0 ${W} ${r}`,
        q2(W + 2 * rt.a, r + (H - 2 * r) * rt.at, W, H - r),
        `Q ${W} ${H} ${W - r} ${H}`,
        q2(r + (W - 2 * r) * b.at, H + 2 * b.a, r, H),
        `Q 0 ${H} 0 ${H - r}`,
        q2(-2 * l.a, r + (H - 2 * r) * l.at, 0, r),
        `Q 0 0 ${r} 0 Z`,
      ].join(" "),
    );
    p.parentElement?.setAttribute("viewBox", `-30 -30 ${W + 60} ${H + 60}`);
    return moving;
  }, [zone, pointer, still]);
  const wake = React.useCallback(() => {
    if (loop.current) return;
    if (typeof requestAnimationFrame === "undefined") return void draw();
    let rest = 0;
    const step = () => {
      const moving = draw();
      const el = zone.current;
      const resizing = el ? el.dataset.h !== String(el.offsetHeight) : false;
      if (el) el.dataset.h = String(el.offsetHeight);
      rest = moving || resizing ? 0 : rest + 1;
      loop.current = rest > 12 ? 0 : requestAnimationFrame(step);
    };
    loop.current = requestAnimationFrame(step);
  }, [draw, zone]);
  React.useImperativeHandle(ref, () => ({ wake, swell: () => (edges.current.forEach((e) => (e.v += 3.2)), wake()) }), [wake]);
  React.useEffect(() => {
    wake();
    const el = zone.current;
    const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => wake());
    if (el) ro?.observe(el);
    return () => {
      ro?.disconnect();
      if (loop.current) cancelAnimationFrame(loop.current);
      loop.current = 0;
    };
  }, [wake, zone]);
  return (
    <svg aria-hidden className="pointer-events-none absolute -inset-[30px] size-[calc(100%+60px)] overflow-visible">
      <path ref={path} fill="none" strokeWidth={over ? 1.75 : 1.25} strokeDasharray={over ? "0" : "6 6"} stroke={over ? "var(--ns-signal)" : "var(--ns-field-edge)"} style={{ transition: "stroke 160ms, stroke-width 160ms" }} />
    </svg>
  );
});

type Read = ReturnType<typeof readStatus>;

/** One of the well's rows: it grows in, its rule fills as the upload's progress, a green tick lands when it is done. */
function WellRow({ file, st, L, locale, disabled, still, onRemove, onRetry }: { file: File; st: Read; L: FileDropLabels; locale: string; disabled: boolean | undefined; still: boolean; onRemove: (row: HTMLElement | null) => void; onRetry: (row: HTMLElement | null) => void }) {
  const row = React.useRef<HTMLLIElement>(null);
  useIsomorphicLayoutEffect(() => {
    if (still) return;
    row.current?.animate?.([{ gridTemplateRows: "0fr", opacity: 0 }, { gridTemplateRows: "1fr", opacity: 1 }], { duration: 380, easing: "cubic-bezier(.5, 0, .2, 1)" });
    // eslint-disable-next-line react-hooks/exhaustive-deps -- once, as it arrives
  }, []);
  const Glyph = file.type.startsWith("image/") ? FileImage : FileIcon;
  return (
    <li ref={row} data-ns-moves="" className="grid">
      <div className="relative flex min-h-0 items-center gap-3 overflow-hidden py-3 text-[var(--ns-ink)]">
        <span aria-hidden className="grid size-8 shrink-0 place-items-center rounded-[var(--ns-radius)] bg-[var(--ns-well)] text-[var(--ns-ink-2)] [&>svg]:size-4">
          <Glyph />
        </span>
        <span className="flex min-w-0 flex-1 flex-col">
          <MiddleName name={file.name} className="text-[15px]" />
          {st.error ? (
            <span role="status" className="flex items-center gap-1.5 text-[13px] text-[var(--ns-bad-ink)]">
              <span className="min-w-0 truncate">{st.error}</span>
              <button type="button" onClick={(e) => onRetry(e.currentTarget.closest("li"))} className="relative shrink-0 cursor-pointer text-[var(--ns-ink)] underline decoration-[var(--ns-line)] underline-offset-2 outline-hidden pointer-coarse:after:absolute pointer-coarse:after:-inset-3 pointer-coarse:after:content-[''] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)]">
                {L.retry}
              </button>
            </span>
          ) : (
            <span className="text-[13px] text-[var(--ns-ink-3)] tabular-nums">
              {st.up ? fill(L.sending, { percent: Math.round(st.progress * 100) }) : <>{st.done && <span className="sr-only">{L.done} · </span>}{formatBytes(file.size, locale)}</>}
            </span>
          )}
        </span>
        <span aria-hidden className="grid size-6 shrink-0 place-items-center">
          {st.done ? (
            <span data-slot="file-drop-tick" className="grid size-6 place-items-center rounded-full bg-[var(--ns-ok)] text-white [animation:ns-play-spring_var(--ns-time-spring)_var(--ns-ease-pop)_both] [&_svg]:size-3.5">
              <Check strokeWidth={3} />
            </span>
          ) : st.error ? (
            <span className="grid size-6 place-items-center rounded-full bg-[var(--ns-bad)] text-white [&_svg]:size-3.5">
              <X strokeWidth={3} />
            </span>
          ) : null}
        </span>
        <button
          type="button"
          data-slot="file-drop-remove"
          aria-label={fill(L.remove, { name: file.name })}
          disabled={disabled}
          onClick={(e) => onRemove(e.currentTarget.closest("li"))}
          className="relative grid size-7 shrink-0 cursor-pointer place-items-center rounded-[8px] text-[var(--ns-ink-3)] outline-hidden pointer-coarse:after:absolute pointer-coarse:after:-inset-2 pointer-coarse:after:content-[''] hover:bg-[var(--ns-hover)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] [&_svg]:size-4"
        >
          <X aria-hidden />
        </button>
        <span aria-hidden className="absolute inset-x-0 bottom-0 h-px bg-[var(--ns-line)]" />
        {st.up ? (
          <span role="progressbar" aria-label={file.name} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(st.progress * 100)} className="absolute bottom-0 start-0 h-[2px] rounded-full bg-[var(--ns-ink-2)]" style={{ width: `${st.progress * 100}%` }} />
        ) : null}
      </div>
    </li>
  );
}

/** A file as a typed paper card: a page with its type tag and a few lines, or an image as its own thumbnail. */
function Paper({ file, thumb, w = 124 }: { file: File; thumb: string | undefined; w?: number }) {
  const image = file.type.startsWith("image/");
  const dot = file.name.lastIndexOf(".");
  const tag = (dot > 0 ? file.name.slice(dot + 1) : image ? "img" : "file").slice(0, 4).toUpperCase();
  return (
    <span className="relative block overflow-hidden rounded-[10px] bg-[var(--ns-raised)] shadow-[0_0_0_1px_var(--ns-line),0_10px_24px_-12px_rgb(0_0_0/0.35)]" style={{ width: w, height: Math.round(w * 1.3) }}>
      {image && thumb ? (
        <img src={thumb} alt="" draggable={false} className="absolute inset-0 size-full object-cover" />
      ) : (
        <span className="absolute inset-x-[14%] top-[16%] flex flex-col gap-[7%]">
          <span className="h-[5px] w-[70%] rounded-full bg-[var(--ns-ink-3)] opacity-40" />
          {[92, 84, 88, 60, 90, 76].map((x, i) => (
            <span key={i} className="h-[4px] rounded-full bg-[var(--ns-line)]" style={{ width: `${x}%` }} />
          ))}
        </span>
      )}
      {!image ? <span className="absolute top-0 end-0 size-[18%] rounded-es-[6px] bg-[linear-gradient(225deg,var(--ns-panel)_50%,var(--ns-line)_50%)]" /> : null}
      <span className={cn("absolute bottom-[7%] start-[10%] rounded-[4px] px-1.5 py-px text-[10px] leading-4 font-semibold tracking-[0.04em]", image ? "bg-black/55 text-white" : "bg-[var(--ns-signal-wash)] text-[var(--ns-signal-ink)]")}>{tag}</span>
    </span>
  );
}

/** One card on the stack: it falls onto the pile from where it was let go and settles on its turn; its foot fills as it uploads. */
function StackCard({ file, i, thumb, st, from, zone, still }: { file: File; i: number; thumb: string | undefined; st: Read; from: { x: number; y: number } | undefined; zone: React.RefObject<HTMLDivElement | null>; still: boolean }) {
  const el = React.useRef<HTMLSpanElement>(null);
  const turn = TURN[i % TURN.length]!;
  useIsomorphicLayoutEffect(() => {
    const e = el.current;
    const z = zone.current?.getBoundingClientRect();
    if (!e || !z || !from || still || !e.animate) return;
    const r = e.getBoundingClientRect();
    const dx = from.x - (r.left - z.left + r.width / 2);
    const dy = from.y - (r.top - z.top + r.height / 2);
    e.animate(
      [
        { translate: `${dx}px ${dy}px`, rotate: "2deg", scale: "1.06" },
        { translate: `${dx * 0.1}px ${dy * 0.1 + 6}px`, rotate: `${turn - 4}deg`, scale: "1", offset: 0.62 },
        { translate: "0 0", rotate: `${turn}deg`, scale: "1" },
      ],
      { duration: 560, easing: EASE_OUT },
    );
    // eslint-disable-next-line react-hooks/exhaustive-deps -- once, as it lands
  }, []);
  return (
    <span
      ref={el}
      className="absolute top-[22px] left-[var(--l)] origin-center [transition:translate_320ms_var(--ns-ease-spring)] group-hover/tray:[translate:calc(var(--i)*14px)_calc(var(--i)*-4px)] max-sm:top-[16px] max-sm:left-[var(--lp)] max-sm:origin-top-left max-sm:scale-[.82] motion-reduce:transition-none"
      style={{ ["--l" as string]: `${30 + i * 44 - (i > 2 ? (i - 2) * 12 : 0)}px`, ["--lp" as string]: `${4 + i * 18 - (i > 2 ? (i - 2) * 6 : 0)}px`, ["--i" as string]: i, rotate: `${turn}deg`, zIndex: i }}
    >
      <Paper file={file} thumb={thumb} />
      <span className="absolute inset-x-[10%] bottom-[3%] h-[3px] overflow-hidden rounded-full bg-[var(--ns-line)] [transition:opacity_300ms]" style={{ opacity: st.up ? 1 : 0 }}>
        <span className="block h-full rounded-full bg-[var(--ns-signal)]" style={{ width: `${st.progress * 100}%` }} />
      </span>
      {st.done || st.error ? (
        <span data-slot={st.done ? "file-drop-tick" : undefined} className={cn("absolute -top-2 -end-2 grid size-6 place-items-center rounded-full text-white shadow-[0_0_0_2px_var(--ns-well)] [animation:ns-play-spring_var(--ns-time-spring)_var(--ns-ease-pop)_both] [&_svg]:size-3.5", st.done ? "bg-[var(--ns-ok)]" : "bg-[var(--ns-bad)]")}>
          {st.done ? <Check strokeWidth={3} /> : <X strokeWidth={3} />}
        </span>
      ) : null}
    </span>
  );
}

/** A refused file: it lands on the pile where it was let go, then bounces back up and out, turning, and fades. */
function Bounce({ file, thumb, at, onDone }: { file: File; thumb: string | undefined; at: { x: number; y: number }; onDone: () => void }) {
  const el = React.useRef<HTMLSpanElement>(null);
  const done = React.useRef(onDone);
  React.useEffect(() => {
    done.current = onDone;
  });
  useIsomorphicLayoutEffect(() => {
    const a = el.current?.animate?.(
      [
        { translate: "0 0", rotate: "2deg", opacity: 1 },
        { translate: "-24px 30px", rotate: "-2deg", opacity: 1, offset: 0.35 },
        { translate: "60px -60px", rotate: "14deg", opacity: 0.85, offset: 0.62 },
        { translate: "190px 10px", rotate: "34deg", opacity: 0 },
      ],
      { duration: 720, easing: "linear", fill: "forwards" },
    );
    if (!a) return void done.current();
    a.onfinish = () => done.current();
    return () => a.cancel();
  }, []);
  return (
    <span ref={el} aria-hidden className="pointer-events-none absolute z-20" style={{ left: at.x - 62, top: at.y - 81 }}>
      <Paper file={file} thumb={thumb} />
    </span>
  );
}

/**
 * Dropped files for a surface with no box of its own: spread `target` on it, put `picker` inside, call `open()` from its
 * Add button; `over` is how many files are held over it (null when none). Files outside `accept` are left out.
 */
function useFileTarget({ onFiles, accept, multiple = true, disabled }: { onFiles: (files: File[]) => void; accept?: string | undefined; multiple?: boolean | undefined; disabled?: boolean | undefined }) {
  const [over, setOver] = React.useState<number | null>(null);
  const depth = React.useRef(0);
  const input = React.useRef<HTMLInputElement>(null);
  const files = (e: React.DragEvent) => !disabled && [...e.dataTransfer.types].some((t) => t.toLowerCase() === "files");
  const take = (list: File[]) => {
    const ok = list.filter((f) => accepts(f, accept));
    if (ok.length) onFiles(multiple ? ok : ok.slice(0, 1));
  };
  const target = {
    onDragEnter: (e: React.DragEvent) => {
      if (!files(e)) return;
      e.preventDefault();
      depth.current++;
      setOver(e.dataTransfer.items?.length || 1);
    },
    onDragOver: (e: React.DragEvent) => {
      if (!files(e)) return;
      e.preventDefault();
      e.dataTransfer.dropEffect = "copy";
    },
    onDragLeave: (e: React.DragEvent) => {
      if (!files(e) || --depth.current > 0) return;
      depth.current = 0;
      setOver(null);
    },
    onDrop: (e: React.DragEvent) => {
      if (!files(e)) return;
      e.preventDefault();
      depth.current = 0;
      setOver(null);
      take([...e.dataTransfer.files]);
    },
  };
  const picker = <input ref={input} type="file" hidden multiple={multiple} accept={accept} onChange={(e) => (take([...(e.target.files ?? [])]), (e.target.value = ""))} />;
  return { over, target, picker, open: () => input.current?.click() };
}

export { accepts, FILE_DROP_LABELS, formatBytes, FileDrop, splitName, useFileTarget, type FileDropLabels, type FileDropLook, type FileDropProps, type Rejected as FileDropRejected, type FileStatus as FileDropStatus };
```

### lib/notchset/feedback.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
export type FeedbackEvent = "press" | "toggle-on" | "toggle-off" | "open" | "close" | "select" | "success" | "error" | "add" | "remove" | "send";
export type FeedbackProps = {
  /** called once per move, for your sound or haptics */
  onFeedback?: ((e: FeedbackEvent) => void) | undefined;
};
```

### lib/notchset/file-size.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
/** A file's size in the reader's locale, decimal units: "820 kB", "14 MB". */
export function formatBytes(bytes: number, locale: string): string {
  const units = ["byte", "kilobyte", "megabyte", "gigabyte"] as const;
  let n = bytes;
  let u = 0;
  while (n >= 1000 && u < units.length - 1) {
    n /= 1000;
    u++;
  }
  return new Intl.NumberFormat(locale, { style: "unit", unit: units[u], unitDisplay: "short", maximumFractionDigits: n < 10 && u > 0 ? 1 : 0 }).format(n);
}
```

### lib/notchset/icons.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
/** Every piece imports its icons from here: swap the icon set in this one file. */
export * from "lucide-react";
```

### lib/notchset/keep-focus.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
/* Focus never drops to the page when a press removes its own control: call this in the handler with the control that now does the job; once drawn, focus moves there only if it was lost. */
export function landFocus(pick: () => HTMLElement | null | undefined): void {
  if (typeof requestAnimationFrame === "undefined") return;
  requestAnimationFrame(() => {
    const a = document.activeElement;
    if (!a || a === document.body || !a.isConnected) pick()?.focus({ preventScroll: true });
  });
}
```

### lib/notchset/motion.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
"use client";
/*
 * Less motion, the one switch every piece reads, and a motion role's timing for a Web Animation. Split from
 * physics.ts so a piece that needs only these does not carry the springs.
 */
import * as React from "react";

/**
 * Less motion where `el` sits: the device's setting, then a data-motion="reduced" on `el` or any ancestor, falling
 * back to <html>'s when there is no element. The one copy: every piece reads this.
 */
const REDUCED = '[data-motion="reduced"],[data-motion="off"]';
export function lessMotion(el?: Element | null): boolean {
  if (typeof document === "undefined") return true;
  if (typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches) return true;
  return !!(el?.closest?.(REDUCED) ?? document.documentElement.matches(REDUCED));
}

/** Less motion, kept current as the setting changes; true on a server, so a piece starts in its still. */
export function useLessMotion(): boolean {
  return React.useSyncExternalStore(
    (f) => {
      if (typeof matchMedia === "undefined") return () => {};
      const q = matchMedia("(prefers-reduced-motion: reduce)");
      q.addEventListener("change", f);
      const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(f);
      mo?.observe(document.documentElement, { attributes: true, attributeFilter: ["data-motion"] });
      return () => {
        q.removeEventListener("change", f);
        mo?.disconnect();
      };
    },
    () => lessMotion(),
    () => true,
  );
}

/** A motion role's duration and curve (0 under less motion: the result at once), read from the foundation where `el` sits, for a Web Animation that glides
    something CSS can't transition (a width to `auto`, a node on its way out): `roleTiming(el, "--ns-time-menu")`. */
export function roleTiming(el: Element, time: string, ease = "--ns-ease"): KeyframeAnimationOptions {
  if (lessMotion(el)) return { duration: 0, easing: "linear" };
  const cs = getComputedStyle(el);
  const t = cs.getPropertyValue(time).trim();
  const ms = t.endsWith("ms") ? parseFloat(t) : parseFloat(t) * 1000;
  return { duration: Number.isFinite(ms) ? ms : 0, easing: cs.getPropertyValue(ease).trim() || "linear" };
}

/** The foundation's curves as literal strings, for a Web Animation (`element.animate`, `KeyframeEffect`,
    `updateTiming`): those take a literal easing and throw on a CSS var. Copied from foundation.css's `--ns-ease-*`;
    CSS transitions and keyframes keep the vars. */
export const EASE = {
  enter: "cubic-bezier(0.22, 1, 0.36, 1)",
  move: "cubic-bezier(.5, 0, .2, 1)",
  exit: "cubic-bezier(.6, 0, .9, .5)",
  panel: "cubic-bezier(0.32, 0.72, 0, 1)",
  press: "cubic-bezier(0.2, 0, 0, 1)",
  spring: "cubic-bezier(0.16, 1, 0.3, 1)",
  arrive: "cubic-bezier(.3, 1.22, .5, 1)",
  breathe: "cubic-bezier(.45, 0, .55, 1)",
} as const;
```

### lib/notchset/words.ts

```tsx
// Notchset file-drop 1.2.0 · https://notchset.dev/changelog
import * as React from "react";

/* Built-in words and figures, one way for every piece. */

/** The locale a piece writes in when the app passes none: English at launch, the same on the server and in the browser. */
export const DEFAULT_LOCALE = "en-US";

/** A count's words by the locale's plural rule: `other` always, any of the locale's other forms as it needs them. */
export type Plural = { other: string } & Partial<Record<Intl.LDMLPluralRule, string>>;

/** A whole number (or any figure) in the locale's digits and grouping. */
export function formatCount(n: number, locale: string = DEFAULT_LOCALE, options?: Intl.NumberFormatOptions): string {
  return new Intl.NumberFormat(locale, options).format(n);
}

/** A sentence with its `{name}` blanks filled; a blank with no value is left as written. */
export function fill(sentence: string, vars: Readonly<Record<string, string | number>>): string {
  return sentence.replace(/\{(\w+)\}/g, (blank, name: string) => (name in vars ? String(vars[name]) : blank));
}

/** The same, where a blank is a node (a name in ink): the sentence's own words stay in order around it. */
export function fillNodes(sentence: string, vars: Readonly<Record<string, React.ReactNode>>): React.ReactNode {
  return sentence.split(/(\{\w+\})/).map((part, i) => {
    const name = /^\{(\w+)\}$/.exec(part)?.[1];
    return name !== undefined && name in vars ? React.createElement(React.Fragment, { key: i }, vars[name]) : part;
  });
}

/** A count's sentence by the locale's plural rule, `{count}` written in the locale ("1 message", "4 messages"). */
export function plural(locale: string | undefined, n: number, forms: Plural, vars: Readonly<Record<string, string | number>> = {}): string {
  const loc = locale ?? DEFAULT_LOCALE;
  const rule = new Intl.PluralRules(loc).select(n);
  return fill(forms[rule] ?? forms.other, { count: formatCount(n, loc), ...vars });
}
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
