Prestasi
Perlu perhatianKadar bingkai: purata 60 fps, p5 59.5 · Tugas panjang: 0 tugas, jumlah 0 ms, terpanjang 0 ms · Sumber gzip 16 KB · Masa jalan 164 KB
CarouselMITKadBencho
Komponen React Kad oleh Lorenzo Cabra. Dikumpul tanpa ubahan daripada Bencho di bawah lesen MIT dan dipaparkan secara langsung di sini.
Laporan kualiti
Gred dan skor datang daripada pemeriksaan automatik semasa binaan atau ujian. Jika suatu pemeriksaan tidak dijalankan, ia ditanda Belum diuji — nombor tidak pernah direka.
Kadar bingkai: purata 60 fps, p5 59.5 · Tugas panjang: 0 tugas, jumlah 0 ms, terpanjang 0 ms · Sumber gzip 16 KB · Masa jalan 164 KB
Isu 0 · Pembaca skrin: Lulus
Menghormati gerakan dikurangkan
Tidak melimpah · 1
Angka kadar bingkai dan tugas panjang diukur dalam Chromium tanpa paparan dengan WebGL perisian. Ia hanya boleh dibandingkan antara komponen di laman ini, dan tidak mewakili peranti sebenar.
Tiada pelanggaran axe-core.

Disemak 15 Nov 2026 · Angka datang daripada skrip automatik, bukan sampel tulisan tangan.
Dipaparkan pada saiz sebenar.
Salinan bermula dengan notis lesen. Kekalkannya apabila anda menggunakan kod.
<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;
}
}
/* Carousel.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.
*/
/* ══ Carousel ═══════════════════════════════════════════════
A row of cards that drift at rest, give under the pointer,
and can be thrown. Three motions on three nested elements,
one transform each — see the note in Carousel.tsx for why
they cannot share a node. */
.car {
position: relative;
font-family: var(--font-ui);}
/* ── the frame is only a frame ─────────────────────────────
No background, no clip, no mask. This was a box that cut
the cards at its edges, and before that a mask that faded
them out there, and both were answers to the question of
what happens to a card when it runs out of block. The cards
are on a ring now and never reach an edge, so the question
is gone and so is everything that was answering it.
Which also means nothing here forces `transform-style:
flat` any more — overflow and mask both did, and both were
safe only because the perspective sits two levels down on
`.car-float`. It no longer has to be. */
.car-track {
position: absolute;
inset: 0;
touch-action: pan-y;
cursor: grab;}
.car-track[data-held="true"] {
cursor: grabbing;}
.car-track:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px rgba(var(--ink-rgb), 0.4);}
/* the slot holds WHERE on the ring and the card's own resting
ANGLE, written per frame by the component — so it carries no
transition of its own, or the easing and the drag would
re-interpolate against each other and what you would see is
the transition rather than the finger */
.car-slot {
position: absolute;
left: 50%;
top: 50%;
transform-origin: center;}
/* ── the drift ──────────────────────────────────────────────
Keyframes rather than a loop: a rAF per card would be a
permanent loop for motion nobody is watching, and a wall
holding several of these blocks would run a dozen. This
runs on the compositor and pauses itself when the tab
hides. The period is set per card and deliberately does not
divide into its neighbours' — that is what stops the row
breathing in unison.
The perspective lives HERE, not on the track: on the track
a card at the edge of the row would tilt toward the middle
of the stage rather than toward the finger on it. Each card
is its own object being touched and wants its own vanishing
point. */
.car-float {
width: 100%;
height: 100%;
perspective: 760px;
animation: car-bob 5s ease-in-out infinite;}
.car-card {
position: relative;
width: 100%;
height: 100%;
background-size: cover;
background-position: center;
/* no transition: the tilt is sprung in the component, and a
transition on top would be a second opinion about how this
card settles */}
.car-sheen {
position: absolute;
inset: 0;
display: block;
pointer-events: none;}
@media (prefers-reduced-motion: reduce) {
.car-float { animation: none; }
}
@keyframes car-bob {
0%, 100% {
transform: translateY(calc(var(--lift, 4px) * -1)) rotate(calc(var(--sway, 1deg) * -1));
}
50% {
transform: translateY(var(--lift, 4px)) rotate(var(--sway, 1deg));
}}
// bencho source (MIT). npm i motion react · Tailwind CSS v4
// ── blocks/carousel/Carousel.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/carousel/Carousel.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 { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
/* ── 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. */
/* 0..100 into the two numbers a spring actually has.
50 is what Humidity and Brightness were tuned at, which is
the rule every elastic knob on this bench follows — see
lab/motion. Turn the panel to the middle and nothing has
changed.
Both ends have to be usable, which is what fixes the range:
at 0 it is slow and heavy and still arrives, at 100 it is
quick with a visible overshoot, and nowhere in between does
it ring for longer than it takes to read. */
/* The pair is chosen by DAMPING RATIO and then written back
as stiffness and decay, because the ratio is the thing a
person is actually setting and the two numbers on their own
do not say what they add up to.
zeta = -ln(d) / (2 * sqrt(k))
The first version of this ran 0.06..0.26 stiffness against
0.93..0.74 decay, which reads as a sensible spread and is
not one: it puts zeta between 0.15 and 0.16 across the
WHOLE range, so every setting overshot by about sixty per
cent and the knob only changed how fast it did it. Pull's
return went 130px past its own resting position and lifted
the content off the top of the card.
0 → zeta ~0.85, heavy, arrives without a ring
50 → zeta ~0.41, near where Humidity and Brightness sit
100 → zeta ~0.20, lively, two visible rebounds
Both ends shippable, which is the constraint that fixed the
numbers rather than taste. */
const springOf = (tune: number) => ({
/* stiffness: how hard it is pulled toward the target */
k: 0.08 + (tune / 100) * 0.16,
/* decay, per frame: how much of the velocity survives */
d: 0.62 + (tune / 100) * 0.2,
});
/* Units matter. The snap threshold is absolute, so a caller
works in pixels or in 0..100 — a spring driven over 0..1
would be "settled" before it had visibly moved. */
function useSpring(target: number, tune = 50, instant = false) {
const [at, setAt] = useState(target);
const cur = useRef(target);
const vel = useRef(0);
const raf = useRef(0);
useEffect(() => {
if (instant) {
cur.current = target;
vel.current = 0;
setAt(target);
return;
}
const { k, d } = springOf(tune);
let prev = 0;
const tick = (t: number) => {
const dt = prev ? clamp((t - prev) / 16.67, 0, 2.5) : 1;
prev = t;
vel.current += (target - cur.current) * k * dt;
vel.current *= Math.pow(d, dt);
cur.current += vel.current * dt;
if (Math.abs(target - cur.current) < 0.02 && Math.abs(vel.current) < 0.02) {
cur.current = target;
vel.current = 0;
setAt(target);
raf.current = 0;
return;
}
setAt(cur.current);
raf.current = requestAnimationFrame(tick);
};
raf.current = requestAnimationFrame(tick);
return () => {
cancelAnimationFrame(raf.current);
raf.current = 0;
};
/* `tune` sits here beside `target` for the reason
Brightness spells out: the loop closes over it, so
without it a knob turned mid-flight would do nothing
until something else restarted the effect. Restarting
picks up from the refs, so it continues rather than
snapping. */
}, [target, tune, instant]);
return at;
}
/* 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;
/* ── inlined from lab/motion ──────────────────────── */
/* ── elastic, as numbers a person can hold ─────────────────
Several blocks here are the same idea in different clothes:
something travels, stretches on the way, and overshoots
when it lands. Their character lives in a duration and in
one control point of a bezier — which is exactly the kind
of thing nobody should have to name in order to tune.
So the outside of every elastic knob is 0..100 and the
inside is real units, and **50 is always what the component
was already tuned to**. Turn every knob on the bench to the
middle and nothing has changed. That is what makes these
safe to expose: the default is not a number somebody has to
remember, it is the middle of the slider.
Both ends have to be shippable, which is the constraint
that actually shapes these curves. The ranges below stop
where the effect stops being the thing it is — a bar that
moves in 40ms still reads as a bar snapping to a slot; one
that moves in 20ms reads as broken. */
/* How long it takes, slower to faster, as a multiplier on
whatever the component's own tuned duration is. 0 is a
little over half again as slow, 100 is two and a half times
as fast, 50 is exactly 1. */
const rate = (speed: number) => 1.6 - (speed / 100) * 1.2;
/* A drawn placeholder: Bencho's photographs are licensed to
the site and do not travel. Point this at your own. */
const SHOTS: { name: string; src: string }[] = [
{ name: "bird", src: "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%201200%22%20width%3D%22800%22%20height%3D%221200%22%20preserveAspectRatio%3D%22xMidYMid%20slice%22%3E%0A%3Cdefs%3E%3ClinearGradient%20id%3D%22s%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%220%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22rgb%28228%2C228%2C230%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28193%2C193%2C195%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22800%22%20height%3D%221200%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22243%22%20cy%3D%22309%22%20r%3D%2272%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C678.1%20L100%2C638.9%20L200%2C715.1%20L300%2C752.7%20L400%2C675.8%20L500%2C639.7%20L600%2C717.4%20L700%2C751.8%20L800%2C673.4%20L800%2C1200%20Z%22%20fill%3D%22rgb%28161%2C161%2C163%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C848.5%20L100%2C816.2%20L200%2C856.9%20L300%2C908.4%20L400%2C892.1%20L500%2C832.8%20L600%2C821.2%20L700%2C874.9%20L800%2C912.0%20L800%2C1200%20Z%22%20fill%3D%22rgb%28124%2C124%2C126%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C1049.7%20L100%2C1068.0%20L200%2C1050.9%20L300%2C1015.2%20L400%2C996.0%20L500%2C1012.3%20L600%2C1048.0%20L700%2C1067.9%20L800%2C1052.5%20L800%2C1200%20Z%22%20fill%3D%22rgb%2880%2C80%2C82%29%22%2F%3E%0A%3C%2Fsvg%3E" },
{ name: "cow", src: "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%201200%22%20width%3D%22800%22%20height%3D%221200%22%20preserveAspectRatio%3D%22xMidYMid%20slice%22%3E%0A%3Cdefs%3E%3ClinearGradient%20id%3D%22s%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%220%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22rgb%28237%2C237%2C239%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28196%2C196%2C198%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22800%22%20height%3D%221200%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22338%22%20cy%3D%22400%22%20r%3D%2272%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C636.0%20L100%2C678.1%20L200%2C745.7%20L300%2C742.5%20L400%2C673.1%20L500%2C636.3%20L600%2C684.6%20L700%2C749.1%20L800%2C738.0%20L800%2C1200%20Z%22%20fill%3D%22rgb%28166%2C166%2C168%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C908.0%20L100%2C863.4%20L200%2C819.5%20L300%2C830.1%20L400%2C882.2%20L500%2C912.0%20L600%2C883.0%20L700%2C830.8%20L800%2C819.2%20L800%2C1200%20Z%22%20fill%3D%22rgb%28119%2C119%2C121%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C998.3%20L100%2C1000.7%20L200%2C1025.8%20L300%2C1055.3%20L400%2C1068.0%20L500%2C1054.7%20L600%2C1025.1%20L700%2C1000.4%20L800%2C998.5%20L800%2C1200%20Z%22%20fill%3D%22rgb%2891%2C91%2C93%29%22%2F%3E%0A%3C%2Fsvg%3E" },
{ name: "house", src: "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%201200%22%20width%3D%22800%22%20height%3D%221200%22%20preserveAspectRatio%3D%22xMidYMid%20slice%22%3E%0A%3Cdefs%3E%3ClinearGradient%20id%3D%22s%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%220%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22rgb%28223%2C223%2C225%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28193%2C193%2C195%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22800%22%20height%3D%221200%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22452%22%20cy%3D%22314%22%20r%3D%2272%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C753.4%20L100%2C725.1%20L200%2C650.7%20L300%2C648.1%20L400%2C721.3%20L500%2C754.5%20L600%2C695.0%20L700%2C637.1%20L800%2C672.5%20L800%2C1200%20Z%22%20fill%3D%22rgb%28154%2C154%2C156%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C881.3%20L100%2C828.0%20L200%2C821.7%20L300%2C870.6%20L400%2C910.9%20L500%2C889.9%20L600%2C835.1%20L700%2C818.0%20L800%2C861.0%20L800%2C1200%20Z%22%20fill%3D%22rgb%28121%2C121%2C123%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C997.4%20L100%2C1007.9%20L200%2C1045.4%20L300%2C1067.9%20L400%2C1050.3%20L500%2C1012.2%20L600%2C996.3%20L700%2C1020.3%20L800%2C1057.4%20L800%2C1200%20Z%22%20fill%3D%22rgb%2891%2C91%2C93%29%22%2F%3E%0A%3C%2Fsvg%3E" },
{ name: "man", src: "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%201200%22%20width%3D%22800%22%20height%3D%221200%22%20preserveAspectRatio%3D%22xMidYMid%20slice%22%3E%0A%3Cdefs%3E%3ClinearGradient%20id%3D%22s%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%220%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22rgb%28223%2C223%2C225%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28181%2C181%2C183%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22800%22%20height%3D%221200%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22219%22%20cy%3D%22318%22%20r%3D%2272%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C734.1%20L100%2C664.9%20L200%2C637.3%20L300%2C688.3%20L400%2C749.6%20L500%2C739.2%20L600%2C671.1%20L700%2C636.2%20L800%2C681.4%20L800%2C1200%20Z%22%20fill%3D%22rgb%28158%2C158%2C160%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C861.3%20L100%2C816.1%20L200%2C856.9%20L300%2C910.5%20L400%2C880.7%20L500%2C821.0%20L600%2C838.4%20L700%2C901.7%20L800%2C897.4%20L800%2C1200%20Z%22%20fill%3D%22rgb%28123%2C123%2C125%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C1065.8%20L100%2C1064.9%20L200%2C1045.3%20L300%2C1018.2%20L400%2C998.9%20L500%2C998.4%20L600%2C1016.9%20L700%2C1044.0%20L800%2C1064.3%20L800%2C1200%20Z%22%20fill%3D%22rgb%2882%2C82%2C84%29%22%2F%3E%0A%3C%2Fsvg%3E" },
{ name: "queue", src: "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%201200%22%20width%3D%22800%22%20height%3D%221200%22%20preserveAspectRatio%3D%22xMidYMid%20slice%22%3E%0A%3Cdefs%3E%3ClinearGradient%20id%3D%22s%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%220%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22rgb%28223%2C223%2C225%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28174%2C174%2C176%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22800%22%20height%3D%221200%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22301%22%20cy%3D%22405%22%20r%3D%2272%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C735.3%20L100%2C651.0%20L200%2C655.9%20L300%2C740.3%20L400%2C736.9%20L500%2C652.5%20L600%2C654.3%20L700%2C738.8%20L800%2C738.5%20L800%2C1200%20Z%22%20fill%3D%22rgb%28158%2C158%2C160%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C903.3%20L100%2C846.3%20L200%2C816.5%20L300%2C859.7%20L400%2C909.5%20L500%2C889.4%20L600%2C830.3%20L700%2C823.0%20L800%2C878.7%20L800%2C1200%20Z%22%20fill%3D%22rgb%28119%2C119%2C121%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C1200%20L0%2C1062.6%20L100%2C1037.2%20L200%2C1008.1%20L300%2C996.0%20L400%2C1009.5%20L500%2C1038.9%20L600%2C1063.5%20L700%2C1065.7%20L800%2C1043.9%20L800%2C1200%20Z%22%20fill%3D%22rgb%2884%2C84%2C86%29%22%2F%3E%0A%3C%2Fsvg%3E" },
];
/* ══ Carousel ═════════════════════════════════════════════
Cards on a turntable that drift at rest, give under the
pointer, and can be swiped round.
NOTHING EVER LEAVES THE FRAME, and that is the whole
arrangement. This was a row twice — cards in a line, with
the ones at the ends either dissolving into a mask or being
cut by the edge of a box — and both are answers to the same
question: what happens to a card when it runs out of block?
A ring does not ask it. The cards go ROUND: out to one
side, back and small, round to the other side, forward
again. The furthest a card ever gets is the radius, which
is a number this component chose, so there is no edge to
treat and no box to put it in.
IT IS THEREFORE ENDLESS. A row has a first card and a last
one and has to decide what to do at each; a ring has
neither, so the swipe never runs out and never rubber-bands.
Swipe once and the front card shrinks and goes to the back
while the next one comes forward — which is the motion he
described, and it falls out of the geometry rather than
being animated on top of it.
THE ANGLE IS NOT TAKEN MODULO ANYTHING. `turn` counts up
and down without limit and the angle is `(i - turn) * step`.
Wrapping it to 0..360 would send a card the long way round
the moment it crossed the seam, which is the one visible bug
this arrangement can have — the same note the Pro sheet's
reel carries, for the same reason.
THREE MOTIONS, THREE ELEMENTS, ONE TRANSFORM EACH. The slot
carries where the card is on the ring, the floater carries
the drift, the card carries the tilt. They are nested rather
than composed into one string because they are owned by
three different things — the drag, a CSS animation and a
pair of springs — and a single element cannot be written by
three authors without one of them losing. */
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
const mix = (a: number, b: number, t: number) => a + (b - a) * t;
/* the card is the PICTURES' own ratio, near enough — 160x226
is 0.708 against their 2:3, so `cover` trims about six per
cent off the height. These are photographs with nothing at
their top or bottom edge, and the card reading as a card
rather than as a slat is worth the last few rows. */
const CARD_W = 206;
const CARD_H = 292;
/* ── the frame, and it is only a frame ─────────────────────
No box, no clip, no mask. Nothing here hides its overflow,
which is what makes the next decision affordable.
── SIZED FOR THE DEFAULT, NOT FOR THE EXTREMES ───────────
This is the decision that matters on the wall. Sized to
hold Spread 150 with Depth 0 and Float 100 — the widest the
knobs can make the ring — the frame came to 520x404, and at
the arrangement it actually SHIPS at that left 40px of air
either side and 50 top and bottom. Measured. That is dead
space the wall pays for on every card: a block is fitted to
its column by its bounding BOX, so air inside the box is
the block being drawn smaller.
476x340 is the shipping ring plus about eighteen pixels of
margin. The card is 37% of the frame where it was 28.6%,
and the overlay draws it 9% bigger as well, because the fit
there is LOCK over the larger side.
What it costs: at the far corners of the knobs the ring
paints a little outside the frame. Nothing clips, so it
simply overlaps the padding the wall card keeps around a
block, and only when Spread, Depth and Float are all at
once at settings nobody ships. The same trade the Balance
card makes when it stretches past its own measured box.
The cards also keep growing faster than the frame, for the
same reason: 160x226 in 440x340 was 24% of the frame in
card, 188x266 in 474x384 was 27%, 206x292 in 476x340 is
37%.
Fixed at these two numbers, because a frame that grew with
a knob would rescale the whole block every time one moved —
which is the thing the ResizeObserver on the wall and the
overlay would both do. */
const STAGE_W = 476;
const STAGE_H = 340;
const ORBIT = 138;
/* ── how much smaller the back of the ring is ──────────────
Read as a percentage of the way to half size: 100 puts the
card at the back at 0.5, which is where this sits. The knob
runs to 150 — 0.25 — because the ceiling was the default's
own value and that is a knob with nothing above it, so
every setting was a step DOWN from where it shipped.
`1 - depth / 200` rather than the arithmetic it replaced,
which said the same thing with a 0.5 buried in it. */
const DEPTH = 100;
const DEPTH_MAX = 150;
const CORNER = 20;
const FLOAT = 15;
const SINK = 50;
const SETTLE = 50;
/* ── how far back the ring leans ───────────────────────────
A card at the back sits this much higher than one at the
front. Scale alone says smaller, which the eye can read as
further away OR as literally smaller; a card that also
rides UP as it recedes is unmistakably going back, because
that is what a ring seen from slightly above does. It costs
one term and it is most of what makes the depth read.
38 rather than 22 for a second reason: at 22 the card at
the very back was invisible — 226 tall drawn at 0.75 and
lifted 22 puts its top edge 6px BELOW the front card's, so
one of the four was hidden completely at rest. At 38 it
clears by ten, and seeing something behind is what tells
you the ring goes round. */
const LEAN = 38;
/* how many px of drag turn the ring one position */
const PULL = 140;
/* how far ahead of the release the throw looks, in ms of
travel. It is what makes a short fast flick move a card:
without it a swipe is judged on distance alone and a quick
one that barely moved counts for nothing. */
const TOSS = 150;
/* and how many it may skip. A flick can carry two; past that
the ring blurs and you have lost your place on it. */
const MOST = 2;
const BASE = 620;
/* ── the pictures ARE the count ────────────────────────────
It was a 3..6 knob while the cards were coloured faces,
which is a knob you can only have when the cards carry
nothing: with photographs, one more card than pictures has
to be one of them a second time, and the same picture twice
on one ring reads as a bug rather than as a setting. So the
number of cards is `SHOTS.length` and nothing else —
add a file, run the script, and the ring has another
position. Five today.
Five is also the better ring. With four, one card sits at
180 degrees, which is directly behind the front one and out
of sight; at 72-degree steps nothing is ever exactly
behind anything, so every card is at least partly visible
at rest and the ring reads as a ring rather than as three
cards and a rumour.
They are inlined by scripts/carousel.sh — drop new files in
src/assets/carousel and run it. The order is the filenames
sorted, so renaming one moves it. */
const N = SHOTS.length;
/* ── which one is at the front when it opens ───────────────
BY NAME, not by index. The order is whatever the filenames
sort to, so an index here would be a number that silently
means a different picture the day somebody adds a file —
and "the card it opens on" is a decision, not an accident
of the alphabet. Falls back to the middle of the ring if
the name is not there, which is where it used to open. */
const FRONT = "man";
const OPENS_ON = (() => {
const i = SHOTS.findIndex((s) => s.name === FRONT);
return i < 0 ? Math.floor((N - 1) / 2) : i;
})();
/* ── every card sits at its own angle ──────────────────────
Numbers that are not a pattern: no two the same, no
symmetry to spot, and they do not alternate. A ring where
the angles went -4, +4, -4, +4 is an arrangement somebody
made; numbers that are merely different are a handful of
photographs somebody put down.
There is one per picture. It has to be — `i % ANGLE.length`
would wrap a fifth card onto the first card's angle, and
two of five sharing an angle is the pattern this list
exists to avoid.
They can be this generous again now the cards are on a
ring. On a row an angle cost width — a turned card sweeps
its corner sideways into its neighbour's air — and the
spread knob's floor had to pay for it. Cards at different
depths are allowed to overlap; that is what depth looks
like. */
const ANGLE = [-4.2, 2.6, -1.4, 3.8, 1.7];
/* the drift's periods, deliberately awkward so no two cards
are ever doing the same thing. See the note in index.css. */
const PERIOD = [4.7, 5.9, 6.7, 5.3, 7.1, 6.1];
type Spot = { x: number; y: number; s: number; z: number };
/* ── where a card sits, given where the ring is ────────────
ONE function, read by the first paint and by the drag both.
The drag writes transforms straight to the nodes — a render
per pointermove and the ring visibly trails the finger — so
there are two callers, and if they were two pieces of code
they would drift apart the first time the geometry changed.
`f` is the whole of it: 1 at the front, 0 at the back, and
it drives the size, the lean and the paint order together.
Position from the ANGLE rather than from a table of four
places is what makes the transitions free — the card
leaving swings out and back, the card arriving swings in
and forward, and the one behind crosses without any of them
knowing about the others. */
const spotOf = (i: number, turn: number, orbit: number, depth: number): Spot => {
const th = (i - turn) * ((Math.PI * 2) / N);
const f = (Math.cos(th) + 1) / 2;
return {
x: Math.sin(th) * orbit,
y: -(1 - f) * LEAN,
s: mix(1 - clamp(depth, 0, DEPTH_MAX) / 200, 1, f),
/* ── paint order is a z-index, by hand ──────────────
Everything here is 2D — scale and offset, not
translateZ — so nothing sorts itself and a card would
otherwise paint in DOM order and sit over the one in
front of it. `f` already knows which is nearer. */
z: Math.round(f * 100),
};
};
const write = (el: HTMLElement, sp: Spot, angle: number) => {
/* NO OPACITY IS WRITTEN HERE. The cards used to fade with
distance, which meant dragging dimmed and lit every one of
them — the whole block pulsed on a gesture that should
only move things round. Size, lean and paint order say
which is in front; none of them touch the picture. */
el.style.transform = `translate(-50%, -50%) translate(${sp.x.toFixed(2)}px, ${sp.y.toFixed(2)}px) rotate(${angle}deg) scale(${sp.s.toFixed(4)})`;
el.style.zIndex = String(sp.z);
};
const out = (t: number) => 1 - (1 - t) ** 4;
export function Carousel({
/* how far out to the sides the ring reaches, in px */
orbit = ORBIT,
/* how much smaller the back of the ring is, 0..100 */
depth = DEPTH,
corner = CORNER,
/* how much they drift at rest, 0..100 — 0 is a still ring,
which is a real setting and not a broken one */
float = FLOAT,
/* how deep the pointer presses, 0..100 */
sink = SINK,
/* how quickly a swipe settles, 0..100 */
settle = SETTLE,
/* ── seconds for one whole turn of the ring ──────────────
0 is off, and off is the default: on the bench this ring
is a thing you push, and one that also drifts round on its
own would be answering a gesture nobody made. It is here
for the places the carousel is a PICTURE rather than a
control — the Pro sheet, today — where it has to carry
itself because nobody is going to touch it. */
spin = 0,
}: {
orbit?: number;
depth?: number;
corner?: number;
float?: number;
sink?: number;
settle?: number;
spin?: number;
} = {}) {
const still = stillness();
const slots = useRef<(HTMLDivElement | null)[]>([]);
/* ── where the ring is, and it is a REF ──────────────────
A continuous position in card-steps: 0 puts the first
card at the front, 1.5 is halfway between the second and
third. It changes every frame of a drag, which is exactly
the value that must not be state — React renders when a
knob moves, the ring is painted.
It is NOT clamped and NOT wrapped. See the note at the
top: this is the number a modulo would ruin. */
const turn = useRef(OPENS_ON);
const raf = useRef(0);
const drag = useRef<{
x0: number; t0: number; last: number; t: number; vx: number; moved: boolean;
} | null>(null);
const [held, setHeld] = useState(false);
const paint = useCallback(() => {
slots.current.forEach((el, i) =>
el && write(el, spotOf(i, turn.current, orbit, depth), ANGLE[i % ANGLE.length]));
}, [orbit, depth]);
/* placed on mount, and again whenever a knob changes the
arithmetic under it */
useLayoutEffect(paint, [paint]);
useEffect(() => () => cancelAnimationFrame(raf.current), []);
/* ── the ring turning itself ─────────────────────────────
Its own frame loop and its own handle, deliberately not
`raf` — that one belongs to the settle after a swipe, and
the two sharing it would mean whichever started last
cancelled the other.
It advances `turn` by time rather than stepping between
whole positions: a ring that clicks from card to card is
reading as a slideshow, and the whole point of this one is
that it is a continuous ring you are looking at side on.
Held pauses it. Nothing on the Pro sheet can grab it —
that reel is pointer-events: none — but the pause costs a
line and means the prop is safe anywhere. */
useEffect(() => {
if (!spin || still || held) return;
let id = 0;
let prev = 0;
const step = (t: number) => {
/* N cards over `spin` seconds is one whole revolution */
if (prev) turn.current += ((t - prev) / 1000) * (N / spin);
prev = t;
paint();
id = requestAnimationFrame(step);
};
id = requestAnimationFrame(step);
return () => cancelAnimationFrame(id);
}, [spin, still, held, paint]);
/* ── the settle ──────────────────────────────────────────
Quart-out from wherever the ring currently is to a whole
position. It reads its start from the live value rather
than from where the drag began, so a second swipe during
one turns the ring further instead of snapping it back. */
const glide = (to: number) => {
cancelAnimationFrame(raf.current);
const from = turn.current;
if (still || from === to) {
turn.current = to;
paint();
return;
}
const ms = BASE * rate(clamp(settle, 0, 100));
const t0 = performance.now();
const tick = (now: number) => {
const p = Math.min(1, (now - t0) / ms);
turn.current = mix(from, to, out(p));
paint();
if (p < 1) raf.current = requestAnimationFrame(tick);
};
raf.current = requestAnimationFrame(tick);
};
const go = (d: number) => glide(Math.round(turn.current) + d);
const down = (e: React.PointerEvent) => {
cancelAnimationFrame(raf.current);
drag.current = {
x0: e.clientX, t0: turn.current, last: e.clientX,
t: e.timeStamp, vx: 0, moved: false,
};
setHeld(true);
try { e.currentTarget.setPointerCapture(e.pointerId); } catch { /* not a live pointer */ }
};
const move = (e: React.PointerEvent) => {
const g = drag.current;
if (!g) return;
const dx = e.clientX - g.x0;
if (!g.moved && Math.abs(dx) > 3) g.moved = true;
/* px per ms, smoothed against the previous reading so one
jittery frame cannot fake a flick — and measured from
the LAST position rather than from the grab, because the
speed at release is the only part of a swipe that says
how far it meant to go */
const dt = Math.max(1, e.timeStamp - g.t);
g.vx = (g.vx + (e.clientX - g.last) / dt) / 2;
g.last = e.clientX;
g.t = e.timeStamp;
/* ── no rubber band, because there is no end ─────────
A row had to give at its first and last card, or it read
as broken input. A ring has neither, so the drag is a
plain one-to-one and keeps going as long as you do. */
turn.current = g.t0 - dx / PULL;
paint();
};
const up = () => {
const g = drag.current;
if (!g) return;
drag.current = null;
setHeld(false);
/* where it would come to rest if it kept going, capped so
a hard flick cannot spin the ring past where you can
follow it */
const carry = clamp((-g.vx * TOSS) / PULL, -MOST, MOST);
const to = Math.round(turn.current + carry);
glide(to);
};
const key = (e: React.KeyboardEvent) => {
const d = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
if (!d) return;
e.preventDefault();
go(d);
};
const r = clamp(corner, 0, 40);
return (
<div className="car" style={{ width: STAGE_W, height: STAGE_H }}>
<div
className="car-track"
data-held={held}
role="group"
aria-label="Card carousel"
aria-roledescription="carousel"
tabIndex={0}
onKeyDown={key}
onPointerDown={down}
onPointerMove={move}
onPointerUp={up}
onPointerCancel={up}
>
{SHOTS.map((shot, i) => (
<div
key={shot.name}
ref={(el) => { slots.current[i] = el; }}
className="car-slot"
style={{ width: CARD_W, height: CARD_H }}
>
{/* ── the drift ─────────────────────────────────
Its own element, so the keyframes own this
transform outright and neither the ring nor the
tilt ever writes it. The period is per card and
the amplitudes are the knob. */}
<div
className="car-float"
style={{
/* at Float 0 the keyframes come off rather than
running at zero amplitude. Identical to look
at, and one of them holds a compositor layer
per card for a motion the knob has just
turned off. */
animationName: float <= 0 ? "none" : undefined,
animationDuration: `${PERIOD[i % PERIOD.length]}s`,
["--lift" as string]: `${((clamp(float, 0, 100) / 100) * 16).toFixed(2)}px`,
["--sway" as string]: `${((clamp(float, 0, 100) / 100) * 1.4).toFixed(2)}deg`,
}}
>
<Card
shot={shot.src}
corner={r}
sink={sink}
/* a card under a finger that is turning the
ring is not being pressed, it is being
carried — and two gestures fighting for one
transform is the one way this can look
broken */
off={held || still}
/>
</div>
</div>
))}
</div>
</div>
);
}
/* ── one card, and the press is its own ───────────────────
A component per card rather than a loop, because the tilt is
a pair of springs and a hook cannot be called n times from
the parent. It costs nothing at rest: a spring at its target
runs no loop at all. */
function Card({
shot,
corner,
sink,
off,
}: {
shot: string;
corner: number;
sink: number;
off: boolean;
}) {
const skin = useRef<HTMLDivElement | null>(null);
const [pt, setPt] = useState({ x: 0, y: 0 });
const [on, setOn] = useState(false);
const still = stillness();
/* ── the state, and there is only this ───────────────────
Where the pointer is, as -1..1 on each axis, sprung. The
spring is on the POSITION rather than on the rotation, so
the transform and both gradients are three readings of one
number instead of three things animating toward the same
place. */
const live = on && !off;
const sx = useSpring(live ? pt.x : 0, 50, still);
const sy = useSpring(live ? pt.y : 0, 50, still);
const lit = useSpring(live ? 1 : 0, 50, still);
const deep = clamp(sink, 0, 100) / 100;
const max = deep * 13;
/* IT SINKS, IT DOES NOT LIFT — the tilt card's rule. The
point you are over goes AWAY and the far side comes up, so
the card is being touched rather than displayed. */
const rx = -sy * max;
const ry = sx * max;
/* the pointer in the card's own terms, as a PERCENTAGE. The
wall, the overlay and the Pro sheet all draw this card at
their own scale, and a gradient placed in pixels would
land somewhere else in each of them. */
const px = ((sx + 1) / 2) * 100;
const py = ((sy + 1) / 2) * 100;
const dark = deep * 0.5 * lit;
/* the rim is a hint, not a highlight: at the tilt card's own
0.34 a white wash slides across the photograph and reads
as a sheen laid ON the picture rather than as the far edge
of a dented surface catching light */
const rim = deep * 0.16 * lit;
const track = (e: React.PointerEvent) => {
const el = skin.current;
if (!el) return;
const b = el.getBoundingClientRect();
setPt({
x: clamp(((e.clientX - b.left) / b.width) * 2 - 1, -1, 1),
y: clamp(((e.clientY - b.top) / b.height) * 2 - 1, -1, 1),
});
setOn(true);
};
return (
<div
ref={skin}
className="car-card"
onPointerMove={track}
/* `out` with a containment test rather than `leave` — the
rehearsal's scripted pointer walks off carrying
`relatedTarget: null`, which React does not synthesise
a leave from, and the card would finish the demo still
sunk under a cursor that had gone. */
onPointerOut={(e) => {
const el = skin.current;
const to = e.relatedTarget as Node | null;
if (!el || !to || !el.contains(to)) setOn(false);
}}
onPointerCancel={() => setOn(false)}
style={{
borderRadius: corner,
backgroundImage: `url(${shot})`,
/* translateZ FIRST, so the retreat is measured in the
room's axes rather than in the card's own — after a
rotation the card's z points off to one side and
"back" stops meaning back */
transform: `translateZ(${(-10 * deep * lit).toFixed(2)}px) rotateX(${rx.toFixed(2)}deg) rotateY(${ry.toFixed(2)}deg)`,
/* ── ONE SHADOW, AND IT DOES NOT MOVE ─────────────
It tightened as the card sank, which is the honest
physics, and on four cards it was four shadows
resizing as the pointer crossed them — the ring
flickering rather than one card being touched. The
dent and the rim say the card went back; the shadow
only has to say it is off the ground. */
boxShadow: "0 12px 28px -10px rgba(var(--shadow-rgb), 0.28)",
}}
>
{/* the dent, and the rim opposite it. The shadow pools
where the surface is deepest, which is under the
pointer, and the light catches the far edge that has
risen — so the two are placed at mirrored points and
neither is centred on anything. This layer is what
makes the transform read as a press. */}
<span
className="car-sheen"
aria-hidden="true"
style={{
borderRadius: corner,
backgroundImage: `radial-gradient(44% 36% at ${px.toFixed(1)}% ${py.toFixed(1)}%, rgba(9, 14, 28, ${dark.toFixed(3)}) 0%, rgba(9, 14, 28, 0) 100%), radial-gradient(54% 44% at ${(100 - px).toFixed(1)}% ${(100 - py).toFixed(1)}%, rgba(255, 255, 255, ${rim.toFixed(3)}) 0%, rgba(255, 255, 255, 0) 100%)`,
}}
/>
</div>
);
}Kawalan · HTML · CSS · JS
Sunting kod dan laraskan dengan kawalan. Pratonton dikemas kini semasa anda menaip.

Komponen ini berjalan daripada binaan berpakej, jadi skripnya baca sahaja di sini. Sunting HTML dan CSS; sumber penuh ada dalam tab Kod.
Sunting setiap komponen secara langsung, laraskan dengan kawalan, muat turun sumber penuh dan salin prompt lanjutan.
$49 sekali bayarHarga sementara
Mod ujian: tiada bayaran sebenar dikenakan.
Percuma: pratonton, butang salin dan nota pelajaran.
Ruang yang lapang, bucu lembut dan satu warna aksen meletakkan kandungan di hadapan.
Senarai ciri, profil, jubin produk dan papan pemuka.
Laras padding, kedalaman bayang dan warna aksen.
Tambahkan komponen "Carousel" daripada Bencho (github.com/cabralorenzo/bencho) (MIT) ke aplikasi React + Tailwind CSS saya. Fail sumber: https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/carousel/Carousel.tsx. Ruang yang lapang, bucu lembut dan satu warna aksen meletakkan kandungan di hadapan. Gunakan untuk: Senarai ciri, profil, jubin produk dan papan pemuka. Tetapan untuk dilaras: Laras padding, kedalaman bayang dan warna aksen. Sokong tema cerah dan gelap serta hormati prefers-reduced-motion. Kekalkan notis lesen MIT.
Prompt lebih panjang dengan langkah pelarasan, kebolehcapaian dan integrasi.