效能
需注意幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 7.6 KB · 執行時 156 KB
Aspect ratioMIT卡片Bencho
由 Lorenzo Cabra 製作的卡片 React 元件。依據 MIT 授權從 Bencho 原樣收錄,此處為即時預覽。
品質報告
等級和分數來自建置或測試時跑過的自動檢查。沒跑過的項目會標成「未檢測」,不會填假資料。
幀率: 平均 60 fps,p5 59.5 · 長任務: 0 個,共 0 毫秒,最長 0 毫秒 · 原始碼 gzip 7.6 KB · 執行時 156 KB
問題 0 · 讀屏: 通過
沒有持續動效
無溢出
幀率和長任務是在無介面的 Chromium 裡用軟體 WebGL 測的,只適合在本站元件之間比較,不代表實機表現。
不適用:靜止時沒有可見動畫;由懸停觸發的動畫沒有測試。
沒有 axe-core 違規。

檢測於 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;
}
}
/* Aspect.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.
*/
/* No stroke rule here on purpose — see the note on the
catalog entry. `--pane-edge` is 8% ink, which reads against
a pane and disappears against a photograph, so the block
does not offer the switch rather than offering one that
reports a state it is not producing. */
/* ══ Aspect ═════════════════════════════════════════════════
A picture and three shapes to put it in. Almost everything
that moves is written in the markup from the chosen shape;
what is here is the transition itself and the chrome. */
.asp {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
font-family: var(--font-ui);}
/* the full square, and it never changes size — the picture is
centred in a box that is not moving, so the tabs below do
not climb and drop as the shape changes */
.asp-stage {
display: grid;
place-items: center;
width: 100%;}
.asp-pic {
background-color: var(--surface-2);
background-size: cover;
background-position: center;
/* `cover` and a frame that moves: the picture stays
undistorted and the CROP changes, which is what a format
switch actually is. Contain would letterbox and fit would
squash. */
transition:
width var(--asp-ms, 600ms) cubic-bezier(0.22, 1, 0.36, 1),
height var(--asp-ms, 600ms) cubic-bezier(0.22, 1, 0.36, 1);}
/* ── the tab strip ──────────────────────────────────────────
.dtl-seg's numbers, which is the segmented control the
panel beside this block is already wearing: 36 tall, 2 of
padding, a 6% ink track and 999 on both. Copied by value
rather than by class because that one belongs to the site's
chrome and this is a component — but a block that invented
its own segmented control would be a third opinion about
what one looks like, sitting six inches from the second.
The tabs are 40 wide, against .dtl-seg's 58 for a word.
That is what a 18px glyph needs to stop being a hit target
you have to aim at — they were 18 wide, which is the icon
and no more. */
.asp-tabs {
position: relative;
display: grid;
grid-template-columns: repeat(3, 40px);
padding: 2px;
border-radius: 999px;
background: rgba(var(--ink-rgb), var(--wash));}
.asp-thumb {
position: absolute;
top: 2px; left: 2px;
width: calc((100% - 4px) / 3);
height: calc(100% - 4px);
border-radius: 999px;
background: var(--card);
box-shadow: 0 1px 2px rgba(var(--ink-rgb), 0.1);
/* ── it LEADS the picture ──────────────────────────────
Both are the same event and both answer the one knob, so
the thumb is not on a duration of its own — it is a
fraction of the picture's. A control that takes as long
as the thing it controls feels like it did not hear you;
one that arrives first reads as the cause of what
follows. */
transition: transform calc(var(--asp-ms, 600ms) * 0.55)
cubic-bezier(0.22, 1, 0.36, 1);
pointer-events: none;}
.asp-tab {
position: relative;
display: grid;
place-items: center;
height: 32px;
padding: 0;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--ink-3);
cursor: pointer;
transition: color 160ms ease, scale 160ms cubic-bezier(0.22, 1, 0.36, 1);}
.asp-tab:hover { color: var(--ink); }
.asp-tab[aria-checked="true"] { color: var(--ink); }
/* the same give every other control on this bench has */
.asp-tab:active { scale: 0.96; }
.asp-tab:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--card), 0 0 0 4px rgba(var(--ink-rgb), 0.35);}
@media (prefers-reduced-motion: reduce) {
.asp-pic, .asp-thumb, .asp-tab { transition-duration: 160ms; }
}
// bencho source (MIT). npm i motion react · Tailwind CSS v4
// ── blocks/aspect/Aspect.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/aspect/Aspect.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 { useRef, useState } from "react";
/* ── 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 SHEEP: string = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20600%20800%22%20width%3D%22600%22%20height%3D%22800%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%28227%2C227%2C229%29%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22rgb%28177%2C177%2C179%29%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%0A%3Crect%20width%3D%22600%22%20height%3D%22800%22%20fill%3D%22url%28%23s%29%22%2F%3E%0A%3Ccircle%20cx%3D%22342%22%20cy%3D%22257%22%20r%3D%2254%22%20fill%3D%22rgb%28246%2C246%2C248%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C800%20L0%2C453.0%20L75%2C429.8%20L150%2C424.8%20L225%2C440.5%20L300%2C468.7%20L375%2C494.4%20L450%2C504.0%20L525%2C492.4%20L600%2C465.7%20L600%2C800%20Z%22%20fill%3D%22rgb%28161%2C161%2C163%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C800%20L0%2C579.7%20L75%2C606.0%20L150%2C599.4%20L225%2C567.0%20L300%2C544.5%20L375%2C556.6%20L450%2C590.0%20L525%2C608.0%20L600%2C590.9%20L600%2C800%20Z%22%20fill%3D%22rgb%28112%2C112%2C114%29%22%2F%3E%0A%3Cpath%20d%3D%22M0%2C800%20L0%2C665.3%20L75%2C681.9%20L150%2C703.8%20L225%2C711.8%20L300%2C698.8%20L375%2C676.3%20L450%2C664.1%20L525%2C672.9%20L600%2C695.0%20L600%2C800%20Z%22%20fill%3D%22rgb%2893%2C93%2C95%29%22%2F%3E%0A%3C%2Fsvg%3E";
/* ══ Aspect ═══════════════════════════════════════════════
A picture and three shapes to put it in.
THE THREE FORMATS HAVE THE SAME AREA. That is the whole
idea and it is not how most crop switchers are built —
the common version fixes the width and lets the height do
whatever the ratio says, which means the landscape is a
third of the portrait and switching feels like the picture
grew rather than like it was cropped. Equal area is what a
crop actually is: the same amount of picture, held a
different way. 276x207, 239x239 and 207x276 are within
0.02% of each other.
It also decides the frame. Every shape fits inside one
276x276 square, so the block's bounding box is the biggest
any of them gets and the wall never rescales it mid-move.
NO CROP IN THE FILE. The source is 3:4 and stays that way
— see scripts/sheep.sh — so `cover` does all three crops
from one picture, and the portrait tab is the whole
illustration rather than a slice of it. */
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
/* the square the three shapes fit inside, and the block's
own width */
const W = 276;
const GAP = 16;
const BAR = 36;
const SHAPES = [
{ id: "land", w: 276, h: 207, label: "Landscape, 4 by 3" },
{ id: "square", w: 239, h: 239, label: "Square, 1 by 1" },
{ id: "tall", w: 207, h: 276, label: "Portrait, 3 by 4" },
] as const;
/* ── the icons are the shapes ──────────────────────────────
Drawn rather than imported, and lucide does ship a
rectangle in each orientation. The reason not to use them
is that here the icon is not a symbol FOR the format, it
IS the format — so it has to be at the real ratio, and
lucide's rectangles are at whatever ratio looked right in
a 24 grid.
Same constant area as the pictures, for the same reason:
three marks of visibly different size would say the
formats are different sizes, which is the thing the block
is at pains to say they are not. 13 square, and the other
two are that area at 4:3 and 3:4. */
const MARK = {
land: { x: 1.5, y: 3.38, w: 15, h: 11.25 },
square: { x: 2.5, y: 2.5, w: 13, h: 13 },
tall: { x: 3.38, y: 1.5, w: 11.25, h: 15 },
} as const;
const BASE = 520;
export function Aspect({
corner = 20,
/* how quickly the frame changes shape, 0..100 — 50 is the
tuned 520ms */
morph = 50,
}: { corner?: number; morph?: number } = {}) {
const [at, setAt] = useState(1);
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const ms = Math.round(BASE * rate(clamp(morph, 0, 100)));
const shape = SHAPES[at];
const pick = (i: number, focus = false) => {
if (i === at) return;
setAt(i);
if (focus) tabs.current[i]?.focus();
};
/* ── arrows move the choice ──────────────────────────────
One of the three is always chosen, which makes this a
radio group rather than a row of buttons — and a radio
group is driven with the arrow keys, with only the
chosen one in the tab order. Tab reaches the control,
arrows choose inside it. */
const key = (e: React.KeyboardEvent) => {
const d = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1
: e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1
: 0;
if (!d) return;
e.preventDefault();
pick((at + d + SHAPES.length) % SHAPES.length, true);
};
return (
<div
className="asp"
style={{ width: W, height: W + GAP + BAR, ["--asp-ms" as string]: `${ms}ms` }}
>
{/* The stage is the full square and never changes, so
the picture is centred in a box that is not moving.
Sizing the stage to the picture instead would make
the tabs below it climb and drop as the shape
changed — the one thing on this block that has no
business moving. */}
<div className="asp-stage" style={{ height: W }}>
{/* ── width and height, NEVER a scale ─────────────
The same rule the detail overlay's block follows,
for the same reason: a scaled box drags its corner
radius with it, and the corner has to read as the
same rounded frame throughout rather than as a
rectangle being stretched. `cover` is what keeps
the picture itself undistorted while the frame
moves — so this reads as a crop changing, which is
what it is, rather than as an image being
squashed. */}
<div
className="asp-pic"
style={{
width: shape.w,
height: shape.h,
borderRadius: clamp(corner, 0, 40),
backgroundImage: `url(${SHEEP})`,
}}
/>
</div>
<div className="asp-tabs" role="radiogroup" aria-label="Aspect ratio" onKeyDown={key}>
{/* ── the thumb ───────────────────────────────────
One element sliding, not three backgrounds fading.
A fill that appears under the new tab while
another disappears is two events; a thumb that
travels is one, and it is the one that says these
three are positions of the same control. */}
<span
className="asp-thumb"
aria-hidden="true"
style={{ transform: `translateX(${at * 100}%)` }}
/>
{SHAPES.map((s, i) => {
const m = MARK[s.id];
return (
<button
key={s.id}
ref={(el) => { tabs.current[i] = el; }}
className="asp-tab"
role="radio"
aria-checked={i === at}
aria-label={s.label}
/* the chosen one is the only one in the tab
order — see the note on `key` */
tabIndex={i === at ? 0 : -1}
onClick={() => pick(i)}
>
<svg width={18} height={18} viewBox="0 0 18 18" aria-hidden="true">
<rect
x={m.x}
y={m.y}
width={m.w}
height={m.h}
rx={2}
fill="none"
stroke="currentColor"
strokeWidth={1.5}
/>
</svg>
</button>
);
})}
</div>
</div>
);
}控制項 · HTML · CSS · JS
直接改程式碼,再用控制項微調,預覽會隨輸入即時更新。

線上編輯每個元件,用控制項微調,下載完整原始碼,複製進階提示詞。
一次性 $49暫定價格
測試模式:不會真的扣款。
免費:預覽、複製按鈕和課程說明。
寬鬆的內邊距、柔和的圓角和單一強調色,讓內容站在前面。
功能列表、個人資料、商品卡和儀表盤。
調內邊距、陰影深度和強調色。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「寬高比」元件加入我的 React + Tailwind CSS 應用程式。原始檔:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/aspect/Aspect.tsx。寬鬆的內邊距、柔和的圓角和單一強調色,讓內容站在前面。 適用情境:功能列表、個人資料、商品卡和儀表盤。 可調參數:調內邊距、陰影深度和強調色。 支援淺色與深色主題,遵循 prefers-reduced-motion。保留 MIT 授權聲明。
更完整的提示詞,包含調參、無障礙和接入步驟。