性能
需注意帧率: 平均 60 fps,p5 59.9 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 10 KB · 运行时 285 KB
Upload dropzoneMIT表单Bencho
由 Lorenzo Cabra 制作的表单 React 组件。依据 MIT 许可从 Bencho 原样收录,此处为实时预览。
质量报告
等级和分数来自构建或测试时跑过的自动检查。没跑过的项目会标成「未检测」,不会填假数据。
帧率: 平均 60 fps,p5 59.9 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 10 KB · 运行时 285 KB
问题 2 · 读屏: 需注意
没有持续动效
无溢出
帧率和长任务是在无界面的 Chromium 里用软件 WebGL 测的,只适合在本站组件之间比较,不代表真机表现。
不适用:静止时没有可见动画;由悬停触发的动画没有测试。

检测于 2026年11月15日 · 数据来自自动脚本,不是手工填写。
按实际尺寸显示。
复制内容以许可声明开头,使用代码时请保留。
<div id="root"></div>:root{--bg:#f6f4f0;--ink:#17181a;--background:40 20% 96%;--foreground:24 10% 8%;--card:0 0% 100%}html,body{min-height:100%;margin:0;background:var(--bg);color:var(--ink)}html,body{height:100%;overflow:hidden}body{display:grid;place-items:center}#root{display:grid;place-items:center;max-width:100%;max-height:100%;box-sizing:border-box;padding:16px;color:hsl(var(--foreground))}#root.full{width:100%;height:100%;padding:0}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-play-state:paused!important;transition-duration:0s!important}}
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
/* ── Bencho tokens ─────────────────────────────────────────
The custom properties the free blocks read, at the values
bencho.dev draws them with. Light by default; dark under
[data-theme="dark"] on any ancestor, or automatically with
the system setting unless [data-theme="light"] says otherwise.
Map these to your own theme rather than keeping two: a block
only ever reads the names, never the values. */
:root {
--font-ui: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
--bg: #ffffff;
--board: #ffffff;
--card: #f7f7f6;
--surface: #f7f7f6;
--surface-2: #f1f1f0;
--surface-3: #ecebe7;
--ink: #17181a;
--ink-rgb: 23, 24, 26;
--ink-2: #3c3b37;
--ink-3: #5c5b56;
--ink-4: #6f6e68;
--ink-5: #85847e;
--on-ink: #ffffff;
--on-ink-rgb: 255, 255, 255;
--slab: #17181a;
--on-slab: #ffffff;
--slab-dark: #0e0f11;
--fill-slab: #ffffff;
--fill-on: #17181a;
--fill-on-rgb: 23, 24, 26;
--pane: var(--fill-slab);
--pane-edge: rgba(23, 24, 26, 0.08);
--pane-thumb: rgba(23, 24, 26, 0.07);
--inlay: rgba(255, 255, 255, 0.55);
--inlay-hi: rgba(23, 24, 26, 0.09);
--elev-rgb: 255, 255, 255;
--glass-rgb: 255, 255, 255;
--shadow-rgb: 23, 24, 26;
--wash: 0.06;
--pick: #0d99ff;
--signal: #2231dd;
--focus: #2231dd;
--ok: #15803d;
--ember: #b8431c;
color-scheme: light;
}
[data-theme="dark"] {
--bg: #000000;
--board: #1a1a1a;
--card: #0a0a0a;
--surface: #0f0f0f;
--surface-2: #181818;
--surface-3: #202020;
--ink: #ffffff;
--ink-rgb: 255, 255, 255;
--ink-2: #b4b4b4;
--ink-3: #9a9a9a;
--ink-4: #828282;
--ink-5: #6b6b6b;
--on-ink: #000000;
--on-ink-rgb: 0, 0, 0;
--slab: #1a1a1a;
--on-slab: #ffffff;
--slab-dark: #262626;
--fill-slab: #262626;
--fill-on: #ffffff;
--fill-on-rgb: 255, 255, 255;
--pane-edge: rgba(255, 255, 255, 0.08);
--pane-thumb: rgba(255, 255, 255, 0.07);
--inlay: rgba(255, 255, 255, 0.1);
--inlay-hi: rgba(255, 255, 255, 0.09);
--elev-rgb: 32, 32, 32;
--shadow-rgb: 0, 0, 0;
--wash: 0.09;
--pick: #3aa9ff;
--ok: #34d17a;
color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--bg: #000000;
--board: #1a1a1a;
--card: #0a0a0a;
--surface: #0f0f0f;
--surface-2: #181818;
--surface-3: #202020;
--ink: #ffffff;
--ink-rgb: 255, 255, 255;
--ink-2: #b4b4b4;
--ink-3: #9a9a9a;
--ink-4: #828282;
--ink-5: #6b6b6b;
--on-ink: #000000;
--on-ink-rgb: 0, 0, 0;
--slab: #1a1a1a;
--on-slab: #ffffff;
--slab-dark: #262626;
--fill-slab: #262626;
--fill-on: #ffffff;
--fill-on-rgb: 255, 255, 255;
--pane-edge: rgba(255, 255, 255, 0.08);
--pane-thumb: rgba(255, 255, 255, 0.07);
--inlay: rgba(255, 255, 255, 0.1);
--inlay-hi: rgba(255, 255, 255, 0.09);
--elev-rgb: 32, 32, 32;
--shadow-rgb: 0, 0, 0;
--wash: 0.09;
--pick: #3aa9ff;
--ok: #34d17a;
color-scheme: dark;
}
}
/* Upload.css */
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
/* ══ Upload dropzone ═════════════════════════════════════ */
.upl {
display: flex;
flex-direction: column;
gap: 12px;
width: 300px;
font-family: var(--font-ui);
color: var(--fill-on, var(--ink));
user-select: none;
-webkit-user-select: none;}
/* a slot of fixed size, so the box can close in round an upload
without moving anything below it */
.upl-zone-wrap {
flex: none;
display: flex;
align-items: center;
justify-content: center;
height: 176px;}
.upl-zone {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
width: 100%;
/* 176, up from 128: the drop target is the block, and a short
one read as a banner rather than a place to put something */
height: 176px;
padding: 0 16px;
overflow: hidden;
border-radius: var(--upl-r);
background: var(--fill-slab, var(--card));
/* a file over it and it grows, with a bounce; an upload and it
closes in round it */
transition:
scale 420ms cubic-bezier(0.24, 1.34, 0.38, 1),
width 420ms cubic-bezier(0.24, 1.34, 0.38, 1),
height 420ms cubic-bezier(0.24, 1.34, 0.38, 1),
background-color 220ms ease;}
.upl-zone[data-over] { scale: 1.02; }
/* the gulp: in a little as the file goes down, out past its size,
and settle */
.upl-zone[data-gulp] { animation: upl-gulp 460ms cubic-bezier(0.3, 1.2, 0.4, 1); }
.upl-zone[data-gulp] .upl-icon { animation: upl-open 460ms cubic-bezier(0.3, 1.4, 0.4, 1); }
[data-stroke="on"] .upl-zone { box-shadow: 0 0 0 1px var(--pane-edge); }
.upl-icon {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 10px;
/* a light grey tile, no edge — the fill's own ink walked most
of the way to its slab, so it is a pale grey on the light fill
and a lifted grey on the dark one */
background: color-mix(in srgb, var(--fill-on, #17181a) 6%, var(--fill-slab, #ffffff));
color: color-mix(in srgb, var(--fill-on, #17181a) 72%, var(--fill-slab, #ffffff));
transition: translate 420ms cubic-bezier(0.24, 1.34, 0.38, 1), background-color 220ms ease, color 220ms ease;}
/* over the box the tile only lifts, and its arrow goes to full
ink — no colour of its own */
.upl-zone[data-over] .upl-icon {
translate: 0 -4px;
color: var(--fill-on, var(--ink));}
.upl-say {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
font-size: 13px;
text-align: center;
letter-spacing: 0em;}
.upl-say b { font-weight: 500; }
.upl-say span {
font-size: 12px;
color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff));
letter-spacing: 0em;}
.upl-zone[data-refuse] .upl-say b { color: #e5484d; }
/* the file, arrived in the box */
.upl-now {
display: flex;
align-items: center;
gap: 12px;
width: max-content;
flex: none;
animation: upl-land 420ms var(--upl-spring) both;}
.upl-text {
display: flex;
flex-direction: column;
gap: 4px;
width: 150px;}
.upl-name {
overflow: hidden;
font-size: 13px;
font-weight: 500;
white-space: nowrap;
text-overflow: ellipsis;
letter-spacing: 0em;}
.upl-meta {
display: flex;
align-items: center;
gap: 4px;
height: 14px;
font-size: 12px;
font-variant-numeric: tabular-nums;
color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff));
letter-spacing: 0em;}
.upl-track {
position: relative;
height: 4px;
margin-top: 4px;
overflow: hidden;
border-radius: 2px;
background: color-mix(in srgb, var(--fill-on, #17181a) 6%, var(--fill-slab, #ffffff));}
.upl-bar {
position: absolute;
inset: 0;
border-radius: inherit;
background: var(--signal, #2231dd);
transform-origin: left center;}
.upl-roll { display: inline-flex; line-height: 1em; height: 1em; overflow: hidden; }
.upl-roll-col { display: inline-block; height: 1em; overflow: hidden; }
.upl-roll-strip {
display: flex;
flex-direction: column;
transition: transform 220ms cubic-bezier(0.24, 1.34, 0.38, 1);}
.upl-roll-strip > span { height: 1em; }
.upl-end {
display: grid;
place-items: center;
flex: none;
width: 22px;
height: 22px;}
.upl-tick {
display: grid;
place-items: center;
flex: none;
width: 22px;
height: 22px;
border-radius: 50%;
background: var(--ok, #15803d);
color: #fff;
animation: upl-pop 380ms cubic-bezier(0.3, 1.6, 0.4, 1) both;}
/* the tray: three files lying under the box */
.upl-tray {
display: flex;
justify-content: center;
gap: 20px;}
.upl-slot {
position: relative;
width: 76px;
height: 75px;}
.upl-file {
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
padding-top: 4px;
cursor: grab;
touch-action: none;
outline: none;
/* home is a spring; the Bounce knob sets its overshoot */
transition: transform 420ms var(--upl-spring), opacity 220ms ease;}
.upl-file[data-held] {
z-index: 5;
cursor: grabbing;
transition: none;}
.upl-file[data-gone] { opacity: 0; pointer-events: none; transition: none; }
.upl-file:not([data-gone]) { animation: upl-back 360ms var(--upl-spring) both; }
.upl-file:focus-visible .upl-page { outline: 2px solid var(--signal, #2231dd); outline-offset: 3px; border-radius: 6px; }
.upl-page { overflow: visible; }
.upl-page-line {
stroke: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));
stroke-width: 1.5;
/* outline only: the page is drawn, not filled */
fill: none;}
.upl-page-ext {
fill: #fff;
font-family: var(--font-ui);
/* size is the <text>'s own fontSize, in the icon's units */
font-weight: 500;
letter-spacing: 0em;}
.upl-label {
max-width: 76px;
overflow: hidden;
font-size: 11px;
white-space: nowrap;
text-overflow: ellipsis;
color: color-mix(in srgb, var(--fill-on, #17181a) 72%, var(--fill-slab, #ffffff));
letter-spacing: 0em;}
/* the tray sits on the STAGE, not on the block, so when Fill
takes the block the other way from the page its names would be
coloured for the wrong ground — light grey on a light stage.
Across that split they take the page's own ink instead. */
/* the page's outline goes with its name, the same colour */
:root:not([data-theme="dark"]) [data-fill="dark"] .upl-label { color: color-mix(in srgb, var(--fill-on, var(--ink)) 70%, #ffffff); }
:root:not([data-theme="dark"]) [data-fill="dark"] .upl-page-line { stroke: color-mix(in srgb, var(--fill-on, var(--ink)) 70%, #ffffff); }
:root[data-theme="dark"] [data-fill="light"] .upl-label { color: color-mix(in srgb, #f4f3f1 70%, var(--fill-on, var(--ink))); }
:root[data-theme="dark"] [data-fill="light"] .upl-page-line { stroke: color-mix(in srgb, #f4f3f1 70%, var(--fill-on, var(--ink))); }
@keyframes upl-gulp {
0% { scale: 1.02; }
35% { scale: 0.985; }
70% { scale: 1.006; }
100% { scale: 1; }}
@keyframes upl-open { 40% { scale: 1.08; } }
@keyframes upl-land { from { opacity: 0; scale: 0.85; translate: 0 10px; } }
@keyframes upl-pop { from { scale: 0; } }
@keyframes upl-back { from { scale: 0.7; opacity: 0; } }
// bencho source (MIT). npm i @tabler/icons-react motion react · Tailwind CSS v4
// ── blocks/upload-dropzone/Upload.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/upload-dropzone/Upload.tsx)
/*
MIT License
Copyright (c) 2026 Lorenzo Cabra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Not covered by this licence: the Bencho name and the goat mark, and the
photographs shown on bencho.dev (none are included here). Third-party
material keeps its own licence; see THIRD_PARTY.md.
Icon substitution (this copy only): lucide-react (ISC) was replaced with @tabler/icons-react (MIT).
Sample photographs were replaced with Incidental AI assets. The Bencho name and goat mark are not licensed for marketing use.
*/
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import { motion, useAnimationControls } from "motion/react";
import { IconCheck as Check, IconUpload as UpIcon } from "@tabler/icons-react";
/* ══ Upload dropzone ══════════════════════════════════════
A drop box, and three files lying on a tray under it. Pick
one up and carry it into the box: it uploads there — name,
a rolling percentage, a bar — ticks, and goes back to the
tray so you can do it again.
── NO REAL FILES ───────────────────────────────────────
The files are part of the block. Nothing is read from the
desktop and nothing is sent anywhere; the drag is an ordinary
pointer drag inside the block, which is also what lets the
wall's scripted cursor demonstrate it.
── THE BOX INHALES, AND SWALLOWS ───────────────────────
A plain filled box, no edge. A file carried over it is
answered before it is let go: the box grows with a small
bounce and the arrow lifts toward the hand. Let go and the
file is SUCKED in — it accelerates toward the box's middle,
shrinking and drawing out long as it goes — and the box gives
a little gulp before the upload appears in it. Let go
anywhere else and the file springs home.
── ONE OF THEM IS TOO BIG ──────────────────────────────
The limit is fixed at 5 MB and the video is always over it,
so dropping it shakes the box, says so in red and the file
springs home. The picture always goes. */
/* ── inlined from lab/spring ──────────────────────── */
/* ── one spring, for everything that settles ───────────────
The maths was already on this bench twice, copied by hand:
Humidity's wheel and Brightness's column both accumulate
velocity toward a target, damp it, and snap when both the
delta and the velocity fall under 0.02. Two copies is a
coincidence; five would be a policy, so it comes out here
before the elastic blocks are written against it.
The two shipped copies are deliberately NOT refactored onto
this. They work, they are tuned, and rewriting the innards
of two live components to prove a point about duplication
is how a good afternoon becomes a bad one. This is the one
new code uses.
Frames, not milliseconds. `dt` is expressed in sixtieths of
a second and the damping is RAISED to it rather than
multiplied by it, so a dropped frame decays the same amount
of energy as the two frames it replaced. Multiplying is the
version that makes a spring behave differently on a busy
page, which is the hardest kind of bug to see.
The loop parks itself the moment the value has settled.
CLAUDE.md is not complimentary about the one permanent
requestAnimationFrame already on this bench and there is no
case for five more. */
/* Read once, the way the wheel and the pill nav do. A
preference, not a live input. */
const stillness = () =>
typeof window !== "undefined" &&
!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
const MAX = 5;
/* what it says the second time, and after */
const SNARK = [
"Still 12.6 MB. It didn't shrink.",
"Pushing harder won't help",
"Have you tried compressing it?",
"The box is full of excuses now",
"No.",
];
type F = { id: string; name: string; ext: string; size: number; tint: string };
const FILES: F[] = [
{ id: "img", name: "mood.png", ext: "PNG", size: 2.4e6, tint: "#079455" },
{ id: "vid", name: "demo.mp4", ext: "MP4", size: 12.6e6, tint: "#155EEF" },
];
const fmt = (b: number) => (b >= 1e6 ? `${(b / 1e6).toFixed(1)} MB` : `${Math.round(b / 1e3)} KB`);
const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
/* ── the file icon ─────────────────────────────────────────
After Untitled UI's: a rounded page on a 40 grid with a thin
grey outline and a folded corner, and the extension on a
coloured label that sticks out past the page's left edge —
the colour carries the kind before the word is read. */
function Page({ f, size = 40 }: { f: F; size?: number }) {
return (
<svg className="upl-page" width={size} height={size} viewBox="0 0 40 40" fill="none" aria-hidden="true">
<path
className="upl-page-line"
d="M7.75 4A3.25 3.25 0 0 1 11 .75h16c.121 0 .238.048.323.134l10.793 10.793a.46.46 0 0 1 .134.323v24A3.25 3.25 0 0 1 35 39.25H11A3.25 3.25 0 0 1 7.75 36z"
/>
<path className="upl-page-line" d="M27 .5V8a4 4 0 0 0 4 4h7.5" />
<rect width="29" height="16" x="1" y="18" rx="8" fill={f.tint} />
{/* 9 units on the 40 grid: the mark is part of the drawing and
scales with it, so its size lives here, not in the stylesheet */}
<text x="15.5" y="29.1" textAnchor="middle" fontSize="9" className="upl-page-ext">{f.ext}</text>
</svg>
);
}
function Roll({ value }: { value: number }) {
const s = String(Math.round(value));
return (
<span className="upl-roll" aria-label={`${s}%`}>
{s.split("").map((d, i) => (
<span key={s.length - i} className="upl-roll-col">
<span className="upl-roll-strip" style={{ transform: `translateY(${-Number(d)}em)` }}>
{"0123456789".split("").map((n) => <span key={n}>{n}</span>)}
</span>
</span>
))}
%
</span>
);
}
type Phase = { kind: "idle" } | { kind: "up"; f: F; p: number } | { kind: "done"; f: F };
export function Upload({
/* how fast a file sends, 0..100 */
speed = 50,
/* how springy a file flies home, 0..100 */
bounce = 40,
corner = 20,
}: {
speed?: number;
bounce?: number;
corner?: number;
} = {}) {
const still = stillness();
const [phase, setPhase] = useState<Phase>({ kind: "idle" });
const [inBox, setInBox] = useState<string | null>(null);
const [held, setHeld] = useState<string | null>(null);
const [over, setOver] = useState(false);
/* what the box says when it refuses — null while it is not */
const [refuse, setRefuse] = useState<string | null>(null);
const tries = useRef(0);
const cool = useRef(0);
const [gulp, setGulp] = useState(false);
const zone = useRef<HTMLDivElement>(null);
const now = useRef<HTMLSpanElement>(null);
const tiles = useRef<Record<string, HTMLDivElement | null>>({});
const shake = useAnimationControls();
const raf = useRef(0);
const timers = useRef<number[]>([]);
const knobs = useRef({ speed });
knobs.current = { speed };
useEffect(() => () => {
cancelAnimationFrame(raf.current);
raf.current = 0;
timers.current.forEach(clearTimeout);
clearTimeout(cool.current);
}, []);
const later = (fn: () => void, ms: number) => { timers.current.push(window.setTimeout(fn, ms)); };
/* ── the pretend wire ──────────────────────────────────── */
const send = (f: F) => {
setInBox(f.id);
if (still) { finish(f); return; }
setPhase({ kind: "up", f, p: 0 });
let p = 0;
let prev = 0;
const secs = (4 - (clamp(knobs.current.speed, 0, 100) / 100) * 3.2) * (0.7 + Math.min(1, f.size / 5e6) * 0.6);
const tick = (t: number) => {
const dt = prev ? Math.min(0.05, (t - prev) / 1000) : 0;
prev = t;
/* uneven on purpose: a steady climb reads as a timer */
p = Math.min(1, p + (dt / secs) * (0.4 + Math.random() * 1.2));
if (p >= 1) { raf.current = 0; finish(f); return; }
setPhase({ kind: "up", f, p });
raf.current = requestAnimationFrame(tick);
};
raf.current = requestAnimationFrame(tick);
};
const finish = (f: F) => {
tries.current = 0;
setPhase({ kind: "done", f });
/* the file goes back to the tray, ready to go again */
later(() => { setPhase({ kind: "idle" }); setInBox(null); }, 1500);
};
/* ── trying again ─────────────────────────────────────────
The first refusal is plain. Try the same file again and the
box starts to answer back, a new line each time, the last one
repeating — until a file that fits goes through, which puts it
back to being polite. */
const refuseIt = () => {
const n = tries.current++;
setRefuse(n === 0 ? `Too big — up to ${MAX} MB` : SNARK[Math.min(n - 1, SNARK.length - 1)]);
shake.start({ x: [0, -7, 6, -4, 2, 0], transition: { duration: 0.42 } });
later(() => setRefuse(null), 1800);
/* "in a row" means close together: leave it alone a while and
the next refusal is the polite one again */
clearTimeout(cool.current);
cool.current = window.setTimeout(() => { tries.current = 0; }, 8000);
};
/* ── carrying a file ───────────────────────────────────── */
const drag = useRef<null | { id: string; x0: number; y0: number; k: number }>(null);
const place = (id: string, dx: number, dy: number, lift: boolean) => {
const el = tiles.current[id];
if (!el) return;
el.style.transform = `translate(${dx}px, ${dy}px) scale(${lift ? 1.08 : 1}) rotate(${lift ? clamp(dx * 0.04, -6, 6) : 0}deg)`;
};
const hits = (e: React.PointerEvent) => {
const r = zone.current?.getBoundingClientRect();
return !!r && e.clientX > r.left && e.clientX < r.right && e.clientY > r.top && e.clientY < r.bottom;
};
const onDown = (f: F) => (e: React.PointerEvent<HTMLDivElement>) => {
if (inBox === f.id) return;
try { e.currentTarget.setPointerCapture(e.pointerId); } catch { /* a scripted pointer */ }
const k = e.currentTarget.getBoundingClientRect().width / e.currentTarget.offsetWidth || 1;
drag.current = { id: f.id, x0: e.clientX, y0: e.clientY, k };
setHeld(f.id);
place(f.id, 0, 0, true);
};
const onMove = (e: React.PointerEvent) => {
const g = drag.current;
if (!g) return;
place(g.id, (e.clientX - g.x0) / g.k, (e.clientY - g.y0) / g.k, true);
const on = hits(e) && phase.kind === "idle";
if (on !== over) {
setOver(on);
}
};
const onUp = (f: F) => (e: React.PointerEvent<HTMLDivElement>) => {
const g = drag.current;
drag.current = null;
try { e.currentTarget.releasePointerCapture(e.pointerId); } catch { /* never captured */ }
setHeld(null);
setOver(false);
if (!g) return;
const inside = hits(e);
if (inside && phase.kind === "idle") {
if (f.size > MAX * 1e6) refuseIt();
else {
suck(f, (e.clientX - g.x0) / g.k, (e.clientY - g.y0) / g.k, g.k);
return;
}
}
/* springs home */
place(f.id, 0, 0, false);
};
/* ── the suction ──────────────────────────────────────────
From where it was let go to the box's middle, on an ease-IN:
slow to leave and faster the nearer it gets, which is what
reads as being pulled rather than as flying. It shrinks as it
goes and draws out long in the direction of travel, then the
box gulps and the upload takes its place. */
const suck = (f: F, dx: number, dy: number, k: number) => {
const el = tiles.current[f.id];
const z = zone.current;
if (!el || !z || still) { place(f.id, 0, 0, false); send(f); return; }
const a = el.getBoundingClientRect();
const b = z.getBoundingClientRect();
const tx = dx + (b.left + b.width / 2 - (a.left + a.width / 2)) / k;
const ty = dy + (b.top + b.height / 2 - (a.top + a.height / 2)) / k;
/* drawn out along the pull, never turned: a tile rotated to
face its travel went upside down on the way up and spun on
a short pull. Up or down it goes tall, sideways it goes
wide, and a pull too short to have a direction only shrinks */
const ux = Math.abs(tx - dx);
const uy = Math.abs(ty - dy);
const squeeze = Math.hypot(ux, uy) < 24 ? "scale(0.16)" : uy >= ux ? "scale(0.14, 0.34)" : "scale(0.34, 0.14)";
el.style.transition = "transform 380ms cubic-bezier(0.55, 0, 0.85, 0.3), opacity 300ms ease-in 80ms";
el.style.transform = `translate(${tx}px, ${ty}px) ${squeeze}`;
el.style.opacity = "0";
/* the upload starts as the tile goes down the hole, not after
it has finished vanishing: waiting out the whole pull left a
beat where the box sat empty, reading as a freeze */
later(() => { setGulp(true); later(() => setGulp(false), 460); }, 200);
later(() => send(f), 220);
later(() => {
/* put the tile home unseen, ready to pop back later */
el.style.transition = "none";
el.style.transform = "";
el.style.opacity = "";
}, 390);
};
/* ── the box hugs the upload ─────────────────────────────
While a file is in it the box closes in round the upload row
— measured, because the row is as wide as its name — and
grows a little when the tick arrives; back to idle it opens
out to the full drop box again. Width and height, never a
scale, so its corner stays the corner. It shrinks inside a
slot of fixed size, so nothing below it moves. */
useLayoutEffect(() => {
const z = zone.current;
const n = now.current;
if (!z) return;
if (phase.kind === "idle" || !n) {
z.style.width = "";
z.style.height = "";
return;
}
z.style.width = `${n.offsetWidth + 32}px`;
z.style.height = `${n.offsetHeight + 28}px`;
}, [phase.kind]);
const r = Math.max(0, corner);
const up = phase.kind !== "idle";
const f = phase.kind !== "idle" ? phase.f : null;
return (
<div
className="upl"
data-held={held ? true : undefined}
style={{ "--upl-r": `${r}px`, "--upl-spring": `cubic-bezier(0.3, ${1 + (bounce / 100) * 0.9}, 0.4, 1)` } as React.CSSProperties}
>
<motion.div animate={shake} className="upl-zone-wrap">
<div
ref={zone}
className="upl-zone"
data-over={over || undefined}
data-refuse={refuse ? true : undefined}
data-busy={up || undefined}
data-gulp={gulp || undefined}
aria-live="polite"
>
{!f ? (
<>
<span className="upl-icon"><UpIcon size={18} strokeWidth={2} /></span>
<span className="upl-say">
<b>{refuse ?? (over ? "Drop to upload" : "Drag a file here")}</b>
<span>Up to {MAX} MB</span>
</span>
</>
) : (
<span className="upl-now" key={f.id} ref={now}>
<Page f={f} size={36} />
<span className="upl-text">
<span className="upl-name">{f.name}</span>
<span className="upl-meta">
{fmt(f.size)} · {phase.kind === "done" ? "Uploaded" : <Roll value={phase.kind === "up" ? phase.p * 100 : 0} />}
</span>
<span className="upl-track">
<span className="upl-bar" style={{ transform: `scaleX(${phase.kind === "up" ? phase.p : 1})` }} />
</span>
</span>
{/* the tick's room is kept from the start, so the box
is its final size before the tick arrives */}
<span className="upl-end">
{phase.kind === "done" && <span className="upl-tick"><Check size={14} strokeWidth={2} /></span>}
</span>
</span>
)}
</div>
</motion.div>
<div className="upl-tray">
{FILES.map((file) => (
<div key={file.id} className="upl-slot" data-empty={inBox === file.id || undefined}>
<div
ref={(el) => { tiles.current[file.id] = el; }}
className="upl-file"
data-held={held === file.id || undefined}
data-gone={inBox === file.id || undefined}
role="button"
tabIndex={0}
aria-label={`${file.name}, ${fmt(file.size)}. Drag into the box to upload, or press Enter.`}
onPointerDown={onDown(file)}
onPointerMove={onMove}
onPointerUp={onUp(file)}
onPointerCancel={onUp(file)}
onKeyDown={(e) => {
if ((e.key === "Enter" || e.key === " ") && phase.kind === "idle" && inBox !== file.id) {
e.preventDefault();
if (file.size > MAX * 1e6) refuseIt();
else send(file);
}
}}
>
<Page f={file} />
<span className="upl-label">{file.name}</span>
</div>
</div>
))}
</div>
</div>
);
}控件 · HTML · CSS · JS
直接改代码,再用控件微调,预览会随输入实时更新。

在线编辑每个组件,用控件微调,下载完整源码,复制进阶提示词。
一次性 $49占位价格
测试模式:不会真实扣款。
免费:预览、复制按钮和课程说明。
分组的字段和一个主按钮,让下一步很清楚。
注册、联系和结账步骤。
调字段间距、按钮颜色和报错样式。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「上传投放区」组件加入我的 React + Tailwind CSS 应用。源文件:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/upload-dropzone/Upload.tsx。分组的字段和一个主按钮,让下一步很清楚。 适用场景:注册、联系和结账步骤。 可调参数:调字段间距、按钮颜色和报错样式。 支持浅色与深色主题,遵循 prefers-reduced-motion。保留 MIT 许可声明。
更完整的提示词,包含调参、无障碍和接入步骤。