性能
需注意帧率: 平均 60 fps,p5 59.9 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 9.0 KB · 运行时 286 KB
Context meterMIT加载动画Bencho
由 Lorenzo Cabra 制作的加载动画 React 组件。依据 MIT 许可从 Bencho 原样收录,此处为实时预览。
质量报告
等级和分数来自构建或测试时跑过的自动检查。没跑过的项目会标成「未检测」,不会填假数据。
帧率: 平均 60 fps,p5 59.9 · 长任务: 0 个,共 0 毫秒,最长 0 毫秒 · 源码 gzip 9.0 KB · 运行时 286 KB
问题 1 · 读屏: 通过
没有持续动效
无溢出
帧率和长任务是在无界面的 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;
}
}
/* ContextMeter.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.
*/
/* ══ Context meter ════════════════════════════════════════
lab/ContextMeter.tsx. A slab card: a head, a rolling figure, a
field of dots filled column by column, chips for the kinds, and a
foot with the room left and Compact. Each kind is a strength of
the ink, strongest first; the empty room is a faint wash */
.ctx {
--ctx-empty: color-mix(in srgb, var(--fill-on, #17181a) 8%, var(--fill-slab, #fff));
/* the cool half of the wheel only, rose round through blue to green:
no orange or yellow, so the set stays one family, but each step is
a clear jump in hue so no two kinds can be mistaken */
--k-sys: #ec4f8c;
--k-tools: #9a5cf6;
--k-files: #3d7ef5;
--k-chat: #1db4cc;
--k-mem: #2ccb7e;
/* 20 dots of 11 on a 3px gap, plus the padding */
width: 309px;
box-sizing: border-box;
padding: 16px;
border-radius: 20px;
background: var(--fill-slab, var(--card, #fff));
color: var(--fill-on, var(--ink, #17181a));
font-family: var(--font-ui);
user-select: none;
-webkit-user-select: none;}
[data-stroke="on"] .ctx { box-shadow: 0 0 0 1px var(--pane-edge); }
.ctx-head { display: flex; justify-content: space-between; align-items: center; }
.ctx-title { font-size: 16px; line-height: 20px; font-weight: 500; letter-spacing: -0.01em; }
.ctx-figure { display: flex; align-items: baseline; gap: 6px; margin: 12px 0 16px; }
.ctx-num { position: relative; font-size: 30px; line-height: 32px; font-weight: 500; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
/* the odometer: each digit a wheel, a window one line tall */
.ctx-roll { display: flex; line-height: 1; }
.ctx-wheel { position: relative; display: inline-block; height: 1.15em; overflow: hidden; }
.ctx-digit { display: block; line-height: 1.15em; }
.ctx-sym { line-height: 1.15em; }
/* the figure in words, for anyone not watching it roll */
.ctx-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ctx-of { font-size: 13px; color: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #fff)); }
/* the field: filled down each column, then across */
.ctx-grid {
display: grid;
grid-auto-flow: column;
justify-content: center;}
.ctx-dot {
display: block;
border-radius: 2px;
background: var(--ctx-empty);
transition: background-color 260ms ease, opacity 220ms ease, scale 260ms cubic-bezier(0.22, 1, 0.36, 1);}
/* a dot changing kind never blends two colours: one solid colour grows
over the other, from nothing to the full dot. Filling, the new colour
grows in over the old; draining, the old colour shrinks away and leaves
the empty dot behind it */
.ctx-dot[data-swap] { position: relative; }
.ctx-dot[data-swap]::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
/* short, so the whole swap is done by the sound's knock */
animation: 340ms cubic-bezier(0.34, 1.2, 0.64, 1) both;
animation-delay: inherit;}
.ctx .ctx-dot[data-swap="fill"] { background: var(--was); }
.ctx-dot[data-swap="fill"]::after { background: var(--now); animation-name: ctx-grow; }
.ctx-dot[data-swap="drain"]::after { background: var(--was); animation-name: ctx-shrink; animation-timing-function: cubic-bezier(0.55, 0, 0.75, 0.4); animation-duration: 240ms; }
/* the field gives under the press, the bar's squeeze in both axes:
down to its floor at 38% of 760, on the sound's knock, a touch past
on the way back. a/b flips per press so the keyframes restart */
.ctx-grid[data-wave="a"] { animation: ctx-press-a 760ms cubic-bezier(0.33, 0, 0.2, 1) both; }
.ctx-grid[data-wave="b"] { animation: ctx-press-b 760ms cubic-bezier(0.33, 0, 0.2, 1) both; }
/* mono: the kinds as strengths of the ink, strongest first */
.ctx[data-mono] {
--k-sys: var(--fill-on, #17181a);
--k-tools: color-mix(in srgb, var(--fill-on, #17181a) 76%, var(--fill-slab, #fff));
--k-files: color-mix(in srgb, var(--fill-on, #17181a) 54%, var(--fill-slab, #fff));
--k-chat: color-mix(in srgb, var(--fill-on, #17181a) 36%, var(--fill-slab, #fff));
--k-mem: color-mix(in srgb, var(--fill-on, #17181a) 22%, var(--fill-slab, #fff));}
.ctx-dot[data-kind="sys"] { background: var(--k-sys); }
.ctx-dot[data-kind="tools"] { background: var(--k-tools); }
.ctx-dot[data-kind="files"] { background: var(--k-files); }
.ctx-dot[data-kind="chat"] { background: var(--k-chat); }
.ctx-dot[data-kind="mem"] { background: var(--k-mem); }
/* the bar style: one stacked bar, a segment per kind and the room
left as a faint tail; widths ease, so Compact slides the chat down */
.ctx-bar { display: flex; gap: 3px; height: 40px; }
.ctx-seg {
display: block;
min-width: 3px;
flex-basis: 0;
border-radius: 6px;
/* the width is a real flex-grow transition, so the corners stay
true; slow out of the gate and long to settle, a fold not a cut */
transition:
flex-grow 820ms cubic-bezier(0.65, 0, 0.2, 1),
opacity 220ms ease;}
/* the squeeze: the chat gives as it folds, and a softer give runs
down the bar after it. Two names so each press restarts it */
.ctx-bar[data-wave="a"] .ctx-seg:not(.ctx-seg-room) { animation: ctx-give-a 760ms var(--ctx-wave, 0ms) cubic-bezier(0.33, 0, 0.2, 1) both; }
.ctx-bar[data-wave="b"] .ctx-seg:not(.ctx-seg-room) { animation: ctx-give-b 760ms var(--ctx-wave, 0ms) cubic-bezier(0.33, 0, 0.2, 1) both; }
@media (prefers-reduced-motion: reduce) {
.ctx-seg { transition-duration: 1ms; }
}
@media (prefers-reduced-motion: reduce) {
.ctx-bar[data-wave] .ctx-seg { animation: none; }
}
.ctx-seg[data-kind="sys"] { background: var(--k-sys); }
.ctx-seg[data-kind="tools"] { background: var(--k-tools); }
.ctx-seg[data-kind="files"] { background: var(--k-files); }
.ctx-seg[data-kind="chat"] { background: var(--k-chat); }
.ctx-seg[data-kind="mem"] { background: var(--k-mem); }
.ctx-seg-room { background: color-mix(in srgb, var(--fill-on, #17181a) 8%, var(--fill-slab, #fff)); }
.ctx-seg[data-dim] { opacity: 0.22; }
/* pointing at a kind: it holds, the rest fall back */
/* only the fade: growing the lit dots ate into the 3px gaps and the
grid stopped being an even grid */
.ctx-dot[data-dim] { opacity: 0.22; }
.ctx-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.ctx-chip {
display: inline-flex;
align-items: center;
gap: 8px;
height: 32px;
padding: 0 12px;
border: 0;
border-radius: 999px;
background: color-mix(in srgb, var(--fill-on, #17181a) 6%, var(--fill-slab, #fff));
color: var(--fill-on, #17181a);
font: inherit;
font-size: 13px;
cursor: default;
transition: background-color 160ms ease, scale 260ms cubic-bezier(0.34, 1.56, 0.64, 1);}
/* the chip gives a little under the pointer; keyed to data-on rather than
:hover, so hovering a kind in the field presses its chip too */
.ctx-chip[data-on] { background: color-mix(in srgb, var(--fill-on, #17181a) 12%, var(--fill-slab, #fff)); scale: 0.975; }
.ctx-chip:focus-visible { outline: 2px solid var(--signal, #2231dd); outline-offset: 1px; }
.ctx-swatch { display: block; width: 8px; height: 8px; border-radius: 2px; }
.ctx-swatch[data-kind="sys"] { background: var(--k-sys); }
.ctx-swatch[data-kind="tools"] { background: var(--k-tools); }
.ctx-swatch[data-kind="files"] { background: var(--k-files); }
.ctx-swatch[data-kind="chat"] { background: var(--k-chat); }
.ctx-swatch[data-kind="mem"] { background: var(--k-mem); }
.ctx-act {
height: 28px;
padding: 0 12px;
border: 0;
border-radius: 999px;
/* on a light card a solid black pill shouts over the meter it acts
on: a firm grey wash with ink words instead. A dark card keeps
the solid pill, where white on near-black reads calm */
background: color-mix(in srgb, var(--fill-on, #17181a) 10%, var(--fill-slab, #fff));
color: var(--fill-on, #17181a);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: scale 240ms cubic-bezier(0.22, 1, 0.36, 1), background-color 220ms ease, color 220ms ease;}
[data-fill="dark"] .ctx-act:not([data-quiet]) { background: var(--fill-on, #17181a); color: var(--fill-slab, #fff); }
/* Undo is the way back, not the action: quieter than Compact in either
fill — a fainter wash, and on a light card muted words */
.ctx-act[data-quiet] {
background: color-mix(in srgb, var(--fill-on, #17181a) 5%, var(--fill-slab, #fff));
color: color-mix(in srgb, var(--fill-on, #17181a) 64%, var(--fill-slab, #fff));}
[data-fill="dark"] .ctx-act[data-quiet] {
background: color-mix(in srgb, var(--fill-on, #17181a) 8%, var(--fill-slab, #fff));
color: var(--fill-on, #17181a);}
.ctx-act:active { scale: 0.96; }
.ctx-act:focus-visible { outline: 2px solid var(--signal, #2231dd); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
.ctx-dot { transition-duration: 1ms; transition-delay: 0ms !important; }
}
@media (prefers-reduced-motion: reduce) {
.ctx-grid[data-wave] { animation: none; }
}
@keyframes ctx-grow { from { scale: 0; } to { scale: 1; } }
@keyframes ctx-press-a { 0%, 100% { scale: 1; } 38% { scale: 0.965; } 72% { scale: 1.01; } }
@keyframes ctx-press-b { 0%, 100% { scale: 1; } 38% { scale: 0.965; } 72% { scale: 1.01; } }
@keyframes ctx-shrink { from { scale: 1; } to { scale: 0; } }
@keyframes ctx-give-a { 0%, 100% { scale: 1 1; } 38% { scale: 1 var(--ctx-give, 0.93); } 72% { scale: 1 1.03; } }
@keyframes ctx-give-b { 0%, 100% { scale: 1 1; } 38% { scale: 1 var(--ctx-give, 0.93); } 72% { scale: 1 1.03; } }
// bencho source (MIT). npm i motion react · Tailwind CSS v4
// ── blocks/context-meter/ContextMeter.tsx (https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/context-meter/ContextMeter.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";
import { AnimatePresence, motion } from "motion/react";
/* ══ Context meter ════════════════════════════════════════
A model's context window as a field of dots, one per thousand
tokens. Each kind of content fills its own band, column by column,
in its own strength of ink, and the empty room is a faint grid.
Point at a chip, or at any dot, and that kind lights while the rest
fall back, and the big number rolls to its share. Compact folds the
conversation down: its dots go out in a ripple from the far end,
the bands after it close up, and the count rolls down with them.
── EVERY DOT IS AN INDEX ───────────────────────────────
Dot i belongs to whichever kind's running total it falls inside,
so a dot never moves: compacting changes which kind each index
belongs to, and the colour change is the animation. A delay that
grows along the indices that changed makes it a ripple rather
than a cut.
── THE FIGURE POPS IN ──────────────────────────────────
The Price flow block's number pop-in, recycled: a digit that
changes rises a hair out of a 2px blur and lands a touch past
its mark, left to right 70ms apart — from below when the figure
grows, from above when it shrinks. Every digit is keyed by its
place and its value, so one that did not change never moves. */
type Kind = { id: string; name: string; k: number };
const KINDS: Kind[] = [
{ id: "sys", name: "System", k: 4.2 },
{ id: "tools", name: "Tools", k: 12.8 },
{ id: "files", name: "Files", k: 46.1 },
{ id: "chat", name: "Chat", k: 108.6 },
{ id: "mem", name: "Memory", k: 3.9 },
];
const CHAT_COMPACT = 30.4;
const WINDOW = 200;
/* 200 dots, one per thousand: 20 across, 10 down, each an exact
11 by 11 on a 3px gap, so every one is the same true square */
const COLS = 20;
const ROWS = 10;
const DOT_W = 11;
const DOT_H = 11;
const GAP = 3;
export type MeterStyle = "Field" | "Bar";
const fmt = (k: number) => `${k.toFixed(1)}K`;
function Roll({ text, up }: { text: string; up: boolean }) {
const chars = text.split("");
/* places counted from the right, so a new leading digit does not
shift the keys of the ones already there */
return (
<span className="ctx-roll" aria-hidden="true">
{chars.map((c, i) => {
const place = chars.length - 1 - i;
if (!/[0-9]/.test(c)) return <span key={`s${place}`} className="ctx-sym">{c}</span>;
return (
<span key={`p${place}`} className="ctx-wheel">
<AnimatePresence initial={false} mode="popLayout">
<motion.span
key={c}
className="ctx-digit"
initial={{ y: up ? "0.18em" : "-0.18em", opacity: 0, filter: "blur(2px)" }}
animate={{ y: "0em", opacity: 1, filter: "blur(0px)" }}
exit={{ opacity: 0, filter: "blur(2px)", transition: { duration: 0.16 } }}
transition={{ duration: 0.5, ease: [0.34, 1.45, 0.64, 1], delay: i * 0.07 }}
>
{c}
</motion.span>
</AnimatePresence>
</span>
);
})}
</span>
);
}
/* biggest first, as it stands before compacting: the order of the
field, the bar and the chips alike. Fixed, so Compact shrinks the
chat in place rather than reshuffling the bands */
const ORDER = KINDS.map((_, i) => i).sort((a, b) => KINDS[b].k - KINDS[a].k);
/* which kind each dot is, before and after compacting: running
totals, a dot per thousand. Both are fixed, so the dots that
differ between them — and so the ripple's delays — are too */
const ownersFor = (sizes: number[]) => {
const out: (number | null)[] = [];
ORDER.forEach((ci) => {
for (let j = 0; j < Math.round(sizes[ci]) && out.length < WINDOW; j++) out.push(ci);
});
while (out.length < WINDOW) out.push(null);
return out;
};
const OWNERS = [
ownersFor(KINDS.map((c) => c.k)),
ownersFor(KINDS.map((c) => (c.id === "chat" ? CHAT_COMPACT : c.k))),
];
const FIRST = OWNERS[0].findIndex((o, i) => o !== OWNERS[1][i]);
const LAST = OWNERS[0].reduce<number>((l, o, i) => (o !== OWNERS[1][i] ? i : l), FIRST);
/* the whole ripple fits inside the compact sound's squeeze: every dot
that changes has started by RIPPLE ms, so the swap lands with the
knock at ~280 rather than trailing on for a second after it.
1 rather than 0 for the first, since 0 reads as "unchanged" */
const RIPPLE = 220;
const DELAY = OWNERS[0].map((o, i) => (o !== OWNERS[1][i] ? 1 + Math.round(((i - FIRST) / (LAST - FIRST || 1)) * RIPPLE) : 0));
/* the bar's corners: OUTER at its two ends, INNER where pieces meet */
const OUTER = 6;
const INNER = 2;
const corners = (first: boolean, last: boolean) => ({
borderTopLeftRadius: first ? OUTER : INNER,
borderBottomLeftRadius: first ? OUTER : INNER,
borderTopRightRadius: last ? OUTER : INNER,
borderBottomRightRadius: last ? OUTER : INNER,
});
export function ContextMeter({
/* a field of dots, or one stacked bar */
style = "Bar",
/* the five hues, or strengths of the ink */
colour = "Colour",
}: {
style?: MeterStyle;
colour?: "Colour" | "Mono";
} = {}) {
const [compact, setCompact] = useState(false);
const [hot, setHot] = useState<string | null>(null);
const sizes = KINDS.map((c) => (c.id === "chat" && compact ? CHAT_COMPACT : c.k));
const used = sizes.reduce((a, b) => a + b, 0);
const owner = OWNERS[compact ? 1 : 0];
const was = OWNERS[compact ? 0 : 1];
/* the swap only plays once Compact has been pressed: on first paint
there is nothing to swap from */
const [moved, setMoved] = useState(false);
/* the big number rolls toward whatever it is showing */
const hotKind = hot ? KINDS.findIndex((c) => c.id === hot) : -1;
const target = hotKind >= 0 ? sizes[hotKind] : used;
/* which way the wheels turn: up for more, down for less */
const last = useRef(target);
const up = useRef(true);
if (target !== last.current) { up.current = target > last.current; last.current = target; }
return (
<div
className="ctx"
data-hot={hot || undefined}
data-mono={colour === "Mono" || undefined}
onPointerLeave={() => setHot(null)}
>
{/* only what reads at a glance: the name, and the one action */}
<div className="ctx-head">
<span className="ctx-title">Context</span>
<button type="button" className="ctx-act" data-quiet={compact || undefined} onClick={() => { setMoved(true); setCompact((v) => !v); }}>
{compact ? "Undo" : "Compact"}
</button>
</div>
<div className="ctx-figure" aria-live="polite">
<span className="ctx-num">
<span className="ctx-sr">{fmt(target)}</span>
<Roll text={fmt(target)} up={up.current} />
</span>
<span className="ctx-of">{hotKind >= 0 ? KINDS[hotKind].name : `of ${WINDOW}K`}</span>
</div>
{style === "Bar" ? (
/* the bar: one segment per kind, as wide as its share, and the
room left as a faint tail. Compact eases the chat's width */
/* leaving the field, not the card, is what puts the total back */
/* ── COMPACT SQUEEZES, IT DOES NOT RESHUFFLE ──────────
The order is the uncompacted one, biggest first, and it
never changes: re-sorting made the chat and the files
cross each other mid-move. The widths are real flex-grow
transitions rather than a layout scale, so the corners
stay true every frame; the chat gives a squeeze as it
folds, and a softer one runs down the bar after it.
`data-wave` flips a/b on every press, which is what
restarts the keyframes. */
<div
className="ctx-bar"
aria-hidden="true"
data-wave={moved ? (compact ? "a" : "b") : undefined}
onPointerLeave={() => setHot(null)}
>
{ORDER.map((ci, n) => {
const c = KINDS[ci];
return (
<i
key={c.id}
className="ctx-seg"
data-kind={c.id}
data-dim={hot !== null && c.id !== hot || undefined}
/* the bar is one rounded shape cut into pieces: round at
its two ends, nearly square where two pieces meet */
style={{
flexGrow: sizes[ci],
...corners(n === 0, false),
"--ctx-wave": `${n * 55}ms`,
"--ctx-give": c.id === "chat" ? 0.78 : 0.93,
} as React.CSSProperties}
onPointerEnter={() => setHot(c.id)}
/>
);
})}
<i
className="ctx-seg ctx-seg-room"
style={{ flexGrow: WINDOW - used, ...corners(false, true) }}
data-dim={hot !== null || undefined}
onPointerEnter={() => setHot(null)}
/>
</div>
) : (
<div
className="ctx-grid"
/* the field gives under the press as the bar does, its
floor on the sound's knock */
data-wave={moved ? (compact ? "a" : "b") : undefined}
style={{
/* fixed tracks, not fractions: a fraction lands each column on
its own sub-pixel, and neighbouring squares round to
different sizes */
gridTemplateRows: `repeat(${ROWS}, ${DOT_H}px)`,
gridTemplateColumns: `repeat(${COLS}, ${DOT_W}px)`,
gap: GAP,
}}
aria-hidden="true"
onPointerLeave={() => setHot(null)}
>
{owner.map((o, i) => (
<i
/* a dot that changes kind is a new element, so its swap
animation starts again; the rest keep theirs */
key={moved && DELAY[i] ? `${i}${compact ? "+" : "-"}` : i}
className="ctx-dot"
data-kind={o === null ? undefined : KINDS[o].id}
data-swap={moved && DELAY[i] ? (o === null ? "drain" : "fill") : undefined}
data-dim={hot !== null && (o === null || KINDS[o].id !== hot) || undefined}
style={DELAY[i] ? ({
transitionDelay: `${DELAY[i]}ms`,
animationDelay: `${DELAY[i]}ms`,
"--was": was[i] === null ? "var(--ctx-empty)" : `var(--k-${KINDS[was[i]!].id})`,
"--now": o === null ? "var(--ctx-empty)" : `var(--k-${KINDS[o].id})`,
} as React.CSSProperties) : undefined}
onPointerEnter={() => setHot(o === null ? null : KINDS[o].id)}
/>
))}
</div>
)}
<div className="ctx-chips" onPointerLeave={() => setHot(null)}>
{ORDER.map((ci) => KINDS[ci]).map((c) => (
<button
key={c.id}
type="button"
className="ctx-chip"
data-on={hot === c.id || undefined}
onPointerEnter={() => setHot(c.id)}
onFocus={() => setHot(c.id)}
onBlur={() => setHot(null)}
>
<i className="ctx-swatch" data-kind={c.id} />
{c.name}
</button>
))}
</div>
</div>
);
}控件 · HTML · CSS · JS
直接改代码,再用控件微调,预览会随输入实时更新。

在线编辑每个组件,用控件微调,下载完整源码,复制进阶提示词。
一次性 $49占位价格
测试模式:不会真实扣款。
免费:预览、复制按钮和课程说明。
节奏均匀的小循环读起来是进度,而不是噪音。
两秒以内的等待、按钮里和空面板。
改尺寸、颜色和一次循环的时长。
把 Bencho (github.com/cabralorenzo/bencho)(MIT)中的「上下文计量」组件加入我的 React + Tailwind CSS 应用。源文件:https://github.com/cabralorenzo/bencho/blob/c65992417427bb09e661674ffa800bef29adef49/blocks/context-meter/ContextMeter.tsx。节奏均匀的小循环读起来是进度,而不是噪音。 适用场景:两秒以内的等待、按钮里和空面板。 可调参数:改尺寸、颜色和一次循环的时长。 支持浅色与深色主题,遵循 prefers-reduced-motion。保留 MIT 许可声明。
更完整的提示词,包含调参、无障碍和接入步骤。