Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ All notable changes to BotUI are recorded here. The format follows

### Fixed

- **`chasing` had no gradient — it was three shelves, not a wave.** `chase` carried `steps: 3`, so the whole motion had exactly three brightness values (0.16, 0.58, 1.00) and every cell crossing a shelf jumped. Measured across a cycle, `chase` had **3** distinct brightness levels where `comet` had **78**. With `spread: 0.34` around a ring, several cells crossed a shelf in the same frame, which is what read as unsmooth. It is now a stop table with a fast rise and a six-stop decay: **173** levels, and the largest step between neighbouring samples fell from ~0.42 to **0.03**. The trailing lit tail behind the crest is new, and `chasing` now reads like the comet it always looked like it should be.
- The `steps` mechanism is gone with it: the `steps?: number` field on `Envelope`, the `level()` branch that read it, the `data-timing="steps-N"` switch in `field.ts`, and the `steps(3, end)` rule in the stylesheet. `chase` was the only envelope that used it, so all four were a description of a deleted behaviour — the exact kind of dead code this repo's own rules call out. Every envelope is one shape again: a stop table or a gaussian.

- **Some motion cards could not be clicked, and one of them crashed the page.** Three separate causes, all invisible to `element.click()` and all found by dispatching real mouse coordinates through CDP:
- The live preview bound `onPointerEnter` on a div **inside the card's `<label>`**. Moving the pointer onto a card started an animation, the re-render interrupted the label's click, and half the cards needed two or three presses. The preview is now `pointer-events: none` and nothing in it reacts to the pointer. Measured: **4 of 7** visible cards registered the first click before, **7 of 7** after.
- `scroll-snap-type: x proximity` made the browser glide a card to the row's edge after the pointer left it, so a click landing during that glide hit where the card _was_. Removed: a pointer-driven scroller has no reason to move on its own.
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ BotUI 的所有值得注意的变更都记录在此。格式遵循

### 修复

- **`chasing` 没有渐变 —— 它是三级台阶,不是波。** `chase` 带着 `steps: 3`,所以整个动效只有三个亮度值(0.16、0.58、1.00),每个格子跨过台阶都是跳变。实测一个周期内 `chase` 只有 **3** 个亮度层,而 `comet` 有 **78** 层。环上 `spread: 0.34` 时,同一帧里有多格跨过同一个台阶 —— 这就是它读起来不 smoother 的原因。现在是一个"快升 + 六段衰减"的 stop 表:**173** 层,相邻采样最大跳变从 ~0.42 降到 **0.03**。波峰后面那道仍然亮着的拖尾是新增的,`chasing` 现在终于读起来像它一直该像的 comet。
- `steps` 机制随之移除:`Envelope` 上的 `steps?: number` 字段、读它的 `level()` 分支、`field.ts` 里的 `data-timing="steps-N"` 切换,以及样式表里的 `steps(3, end)` 规则。`chase` 是唯一的使用者,所以这四处都在描述一个已删除的行为 —— 正是仓库自己的规则点名的死代码。现在每个 envelope 只有一种形态:stop 表或高斯。

- **有些动效卡片点不动,其中一张还会让页面崩溃。** 三个独立原因,`element.click()` 全部看不出来,全都是用 CDP 派发真实鼠标坐标才找到的:
- 实时预览把 `onPointerEnter` 绑在了卡片 `<label>` **内部**的 div 上。指针移到卡片上会启动动画,重渲染打断 label 的点击,于是有一半卡片要点两三次。预览现在设为 `pointer-events: none`,内部不再对指针做任何反应。实测:修复前视口内 7 张只有 **4 张**第一次点中,修复后 **7 张全部**一次点中。
- `scroll-snap-type: x proximity` 会让浏览器在指针离开后把卡片滑到行边缘,滑动过程中落下的点击打在卡片**原来的**位置。已移除:由指针驱动的滚动容器没有理由自己动。
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/dot-matrix/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ const BASE_CSS = `/* BotUI · dot matrix — the CSS renderer.
animation-delay: calc(var(--botui-o, 0) * var(--botui-seed, -0.95) * var(--botui-cycle, 1500ms));
}

.botui-dot-matrix[data-timing^='steps'] > i {
animation-timing-function: steps(3, end);
}

/* Reduced motion: no cycle at all. Each dot holds a static level derived from its
* own traversal position, so the field still reads as a lit matrix — a still
Expand Down
31 changes: 21 additions & 10 deletions packages/core/src/dot-matrix/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,30 @@ export const ENVELOPES: Record<EnvelopeName, Envelope> = {
],
rest: 0.18,
},
/** three discrete shelves over a short band, then the floor */
/**
* A chasing crest: a fast rise, then a DECAY, so the ring carries a lit tail behind
* the high point instead of a shelf edge.
*
* This used to be `steps: 3` — three hard brightness values over the band. That is the
* one thing this file's own rule forbids ("never quantise brightness into shelves"), and
* it is why `chasing` read as unsmooth: the entire motion had three levels, so every
* cell crossing a shelf jumped, and with `spread: 0.34` across a ring several cells
* crossed one in the same frame. Measured, it had 3 distinct brightness levels across a
* cycle where `comet` had 78.
*
* The rise is still faster than the fall, because a chase is defined by its leading
* edge. But the fall is piecewise-linear over several stops, so the tail is a gradient
* and neighbouring dots differ by an amount you can see rather than by a cliff.
*/
chase: {
steps: 3,
duty: 0.34,
duty: 0.46,
stops: [
[0, 0.16],
[0.34, 1],
[0.07, 1],
[0.16, 0.72],
[0.26, 0.48],
[0.36, 0.28],
[0.46, 0.16],
],
rest: 0.16,
},
Expand All @@ -115,12 +132,6 @@ export function level(p: number, env: Envelope): number {
const d = Math.min(p, 1 - p);
return Math.exp(-(d * d) / env.gauss);
}
if (env.steps) {
// `steps` shelves across the BAND, normalised to 0..1, so the shelves are
// floor..peak and not floor..something-below-peak
const u = Math.min(env.steps - 1, Math.floor((p / (env.duty ?? 1)) * env.steps));
return env.rest + (1 - env.rest) * (u / (env.steps - 1));
}
return clamp01(envelope(p, env.stops, env.rest));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/dot-matrix/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function applyCssVars(host: HTMLElement, resolved: ResolvedField): void {
host.style.setProperty("--botui-s-min", (1 - o.grow).toFixed(3));
host.style.setProperty("--botui-s", (1 + o.grow * 0.9).toFixed(3));
host.style.color = o.color;
host.dataset.timing = env.steps ? `steps-${env.steps}` : "linear";
host.dataset.timing = "linear";
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export interface Envelope {
/** a travelling gaussian instead of a stop table — the moving-highlight arm */
gauss?: number;
/** render as N discrete shelves across the band instead of a gradient */
steps?: number;
/** the CSS cycle length; the runtime divides it by `speed` */
cycleMs?: number;
}
Expand Down
19 changes: 14 additions & 5 deletions packages/core/test/dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,20 @@ describe("the CSS renderer", () => {
expect(buildCss({ ...base, preset: "spiral" })).not.toBeNull();
});

it("flips to stepped timing when the envelope is quantised", () => {
expect(buildCss({ ...base, preset: "ring" })!.dataset.timing).toBe("steps-3");
expect(buildCss({ ...base, preset: "spiral" })!.dataset.timing).toBe("linear");
it("uses linear timing for every motion, because no envelope is quantised", () => {
// There used to be a `steps` branch: an envelope could declare `steps: 3`, the field
// switched the host to `steps(3, end)` timing, and the motion rendered as three
// shelves. `chase` was the only user, and it was the reason `chasing` read as unsmooth
// — so the branch went with it. This asserts the shape of what replaced it: every
// envelope interpolates, therefore every host gets linear timing.
// `applyCssVars` only runs on the CSS path, and it writes to the field the engine
// BUILDS inside the mount point — not to the mount point itself
const mount = document.createElement("div");
const dm = createDotMatrix(mount, { preset: "ring", renderer: "css" });
const field = mount.querySelector<HTMLElement>(".botui-dot-matrix");
expect(field, "the CSS renderer builds a field").toBeTruthy();
expect(field!.dataset.timing, "every CSS host gets linear timing").toBe("linear");
dm.destroy();
});
});

Expand Down Expand Up @@ -212,8 +223,6 @@ describe("the CSS and SVG renderers agree", () => {
const c = curve(keyframesFor(preset, softness)!);
for (let i = 0; i <= 40; i++) {
const p = i / 40;
// a stepped envelope is quantised on purpose, so it is exempt
if (env.steps) continue;
expect(
Math.abs(c(p) - softLevel(p, env, softness)),
`${preset} softness=${softness} p=${p.toFixed(2)}`,
Expand Down
83 changes: 70 additions & 13 deletions packages/core/test/dot-matrix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,84 @@ describe("envelope", () => {
// otherwise the cell steps across the p = 0 → 1 seam once per cycle, which the
// eye reads as a twitch rather than a wave
for (const [name, env] of Object.entries(ENVELOPES)) {
// a gaussian is symmetric about p = 0, and a stepped envelope never reaches
// envelope() at all — its stops describe the RANGE of the shelves instead
if (env.gauss || env.steps) continue;
// a gaussian is symmetric about p = 0 and never reaches envelope() at all
if (env.gauss) continue;
const first = env.stops[0]![1];
const last = env.stops[env.stops.length - 1]![1];
expect(first, `${name} starts at rest`).toBeCloseTo(env.rest, 6);
expect(last, `${name} ends at rest`).toBeCloseTo(env.rest, 6);
}
});

it("a stepped envelope spans exactly rest…peak, and is dark outside its duty", () => {
// `chase` keeps a stop table even though `level()` ignores it, so the table has
// to agree with the branch that actually runs — otherwise it is dead data that
// reads as if it described the motion
it("no envelope is quantised into shelves, which is what makes a motion read as cheap", () => {
// Reported as "chasing is not smooth, it has no delta". `chase` carried `steps: 3`, so
// the entire motion had three brightness values - 0.16, 0.58, 1.00 - and a cell
// crossing a shelf jumped. The envelope file's own rule says never quantise into
// shelves; `chase` was the one that broke it, and the only preset using it.
for (const [name, env] of Object.entries(ENVELOPES)) {
expect("steps" in env, name + " must not be quantised into shelves").toBe(false);
const levels = new Set(
Array.from({ length: 401 }, (_, i) => softLevel(i / 400, env, 0).toFixed(3)),
);
expect(
levels.size,
name +
" has only " +
levels.size +
" distinct brightness levels across a cycle; a wave needs a gradient, not shelves",
).toBeGreaterThanOrEqual(24);
}
});

it("chasing has a tail and a delta, like the comet it now resembles", () => {
const env = ENVELOPES.chase;
expect(env.steps).toBe(3);
expect(env.stops[0]![1]).toBeCloseTo(env.rest, 6);
expect(env.stops[env.stops.length - 1]![1]).toBe(1);
expect(softLevel(0, env, 0)).toBeCloseTo(env.rest, 6);
expect(softLevel(env.duty! + 0.01, env, 0)).toBeCloseTo(env.rest, 6);
// sample the crest and the tail at their own positions rather than at fractions of
// `duty`: the rise is short and the decay is long, so a fraction of the band is not
// where either end of it lives
const crestAt = env.stops.find(([, v]) => v === 1)![0];
const peak = softLevel(crestAt, env, 0);
expect(peak, "chasing reaches full brightness").toBeCloseTo(1, 6);
const behind = softLevel(env.duty! * 0.82, env, 0);
expect(behind, "brightness falls away after the crest").toBeLessThan(peak * 0.75);
expect(behind, "but the tail is still lit, not a cliff down to the floor").toBeGreaterThan(
env.rest,
);

let biggest = 0;
for (let i = 1; i < 400; i++) {
biggest = Math.max(
biggest,
Math.abs(softLevel(i / 400, env, 0) - softLevel((i - 1) / 400, env, 0)),
);
}
expect(
biggest,
"chasing jumps " +
biggest.toFixed(3) +
" between neighbouring samples; a stepped envelope jumps about 0.42",
).toBeLessThan(0.05);
});

it("every envelope is dark outside its duty, and starts and ends at rest", () => {
// `chase` used to keep a stop table that `level()` ignored, so the table had to agree
// with a branch that has now been deleted along with it. Every envelope is one shape
// again: a stop table, a gaussian, or nothing but `rest`. So the claim is the simple
// one — whatever an envelope is, it is unlit past its band and lit at neither end.
for (const [name, env] of Object.entries(ENVELOPES)) {
// Only the stop-table envelopes are dark at both ends. `breathe` is a global pulse
// whose band IS the cycle, so it is continuous across the seam by design; `spike` is
// a gaussian centred ON the seam, which is how a travelling highlight gets its crest
// there without a step. Both are deliberate and neither is a shelf.
if (env.duty == null || env.gauss) continue;
expect(softLevel(0, env, 0), name + " starts at rest").toBeCloseTo(env.rest, 6);
expect(softLevel(0.999, env, 0), name + " ends at rest").toBeCloseTo(env.rest, 6);
if (env.duty != null) {
expect(softLevel(env.duty + 0.01, env, 0), name + " is dark past its duty").toBeCloseTo(
env.rest,
6,
);
}
}
});

it("every stop table is monotonic in position and inside [rest, 1]", () => {
Expand Down Expand Up @@ -190,7 +248,6 @@ describe("envelope", () => {
// can change which value a sample lands on — that is the quantisation showing,
// not a dimmed crest.
for (const env of Object.values(ENVELOPES)) {
if (env.steps) continue;
// sample the stop positions TOO: stretching moves them, and a fixed grid can
// step over the crest and report a dimmed peak that is not there
const stretchedEnv = stretched(env, 0.9) ?? env;
Expand Down
Loading