From f6e9ea83b494bb4ff81c538aa5fe2d94395f76ea Mon Sep 17 00:00:00 2001 From: DoodleBear Date: Thu, 1 Oct 2026 01:34:33 +0900 Subject: [PATCH] feat: the playground opens on a showcase state, not the engine's defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A page whose subject is a component should open on the component as someone would actually ship it, and shipped components are tuned. 5×5 with no gap at the largest box, so the grid is legible; dot/cell at 198%, past the touching point, so the dots OVERLAP and read as one surface instead of as separate pixels; grow at 3%, because grow is how far a dot changes size over the cycle and at 50% a dot is a pulsing blob rather than a moving light; stagger PINNED at 70% rather than following the preset, so choosing another motion does not move a slider under the visitor. Square silhouette, square dots, radius 0 — the rounded corners are one control away and a rounded dot at 198% overlap hides the grid the size is there to show. The engine's defaults are untouched. That is the library's choice and the page is allowed to disagree with it, so these live in a named `SHOWCASE` beside the component with the reasoning for each, rather than by editing `DEFAULTS` and changing what every consumer gets. Five tests had encoded the old opening state and were rewritten to derive from it instead of asserting it, which is the more useful shape anyway: - the silhouette tests read the cell count off the steppers rather than hardcoding 7×7's 49, and assert the opening value is what is DRAWN rather than `DEFAULTS` - the tighter-axis test derives its grid instead of hardcoding 3×7. At 55% dot/cell 3×7 is tight on y, and at the opening 198% a 3×5 is tight on y too — so the old hardcoded arrangement would have made "gap x only redistributes air" pass for the wrong reason. 6×3 puts the tight axis back on x, and the two assertions swapped accordingly: gap x resizes the dot, gap y does not. - the stagger label test resets first, because the dial now opens pinned One new test asserts the whole opening state value by value, including that the readout agrees with the controls — "it looks right" is not a claim a test can make, and each number is a decision. --- CHANGELOG.md | 2 + CHANGELOG.zh.md | 2 + apps/site/src/components/Playground.tsx | 47 +++++++++++-- apps/site/test/playground.test.tsx | 91 +++++++++++++++++++++---- 4 files changed, 122 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af9ac2..6cd4b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Changed +- **The playground now opens on a hand-picked showcase state** rather than the engine's defaults: 5×5 with no gap at the largest size, `dot/cell` at 198% so the dots overlap into one surface, `grow` at 3% so a dot moves rather than pulses, `stagger` pinned at 70% so picking another motion does not move a slider under the visitor, square silhouette and square dots at radius 0. The engine's own defaults are untouched — that is the library's choice and the page is allowed to disagree — so the values live in a named `SHOWCASE` beside the component, each with the reason it was picked. + - **The site is now Astro + React islands on Cloudflare Pages.** `apps/site` was a hand-written HTML page with a module script, served from a Worker with static assets; it is now `output: 'static'` Astro 7 with React 19.3 islands built by Vite, deployed to the `botui-site` Pages project. The demos mount diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 4af396e..9092b73 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -4,6 +4,8 @@ ### 变更 +- **Playground 现在开在一组手工挑的 showcase 参数上**,而不是引擎默认值:最大尺寸的 5×5、无间距、`dot/cell` 198% 让点连成一整块面、`grow` 3% 让点是"移动"而不是"脉动"、`stagger` 固定在 70% 以免换个动效就把访客正看着的滑杆挪走、剪影和点都是方形且圆角为 0。引擎自己的默认值没有动 —— 那是库的选择,页面被允许不同意 —— 所以这些值放在组件旁边一个具名的 `SHOWCASE` 里,每一项都写明为什么选它。 + - **站点改为 Astro + React islands,部署到 Cloudflare Pages。** `apps/site` 原先是一个手写 HTML + module script, 由 Worker 静态资源托管;现在是 `output: 'static'` 的 Astro 7 + React 19.3 islands,由 Vite 构建,部署到 `botui-site` Pages 项目。demo 直接挂载 `@botharness/botui-core`,而不是走已发布的 React wrapper —— 否则文档站 diff --git a/apps/site/src/components/Playground.tsx b/apps/site/src/components/Playground.tsx index d1d6262..870aac8 100644 --- a/apps/site/src/components/Playground.tsx +++ b/apps/site/src/components/Playground.tsx @@ -24,12 +24,49 @@ import { const CARD = 44; +/** + * The state the page opens on: a hand-picked look, not the engine's defaults. + * + * The engine's defaults are a library's choice and this page is allowed to disagree + * with them — what it is demonstrating is a component someone would actually ship, + * and shipped components are tuned. Every value here was picked to make one thing + * legible at a glance: + * + * · **5×5 and no gap, at the largest size.** A field you can see the shape of. At 7×7 + * with a 45% gap the dots are far enough apart that the motion reads as noise. + * · **dot/cell 198%.** Over the cell, so the dots OVERLAP. This is the single number + * that makes it read as one surface rather than as separate pixels — and it is past + * the touching point, which is why the readout's own `dot / pitch` line is the one + * worth watching: 100% there means two dots touching. + * · **grow 3%.** Almost no breathing. `grow` is how far a dot changes size over the + * cycle, and at 50% a small dot is a pulsing blob rather than a moving light. + * · **stagger 70%, pinned.** A wide spread, and pinned rather than following the + * preset so the opening frame does not change under the visitor when they pick a + * different motion. + * · **radius 0.** Square dots. The rounded corners are one control away, and a + * rounded dot at 198% overlap hides the grid the size is there to show. + */ +const SHOWCASE: Partial = { + size: 260, + cols: 5, + rows: 5, + fill: 1, + silhouette: "square", + dot: "square", + dotSize: 1.98, + gapX: 0, + gapY: 0, + preset: "spiral", + stagger: 0.7, + softness: 0, + grow: 0.03, + floor: 0.16, + speed: 1, + spec: { ...GLYPH_DEFAULTS }, +}; + export function Playground({ initial }: { initial?: Partial }) { - // The page opens at a denser dot/cell than the engine's default: at 55% a field - // reads as scattered pixels, and this page's subject is what a dot IS. The engine's - // own default is untouched — that is the library's choice, and the playground is - // allowed to disagree with it. - const [options, setOptions] = useState({ dotSize: 0.78, ...initial }); + const [options, setOptions] = useState({ ...SHOWCASE, ...initial }); // CSS by default, because it is the cheaper renderer and this is the one a product // page should be demonstrating: it costs zero JS per frame. SVG is the escape hatch // for the motions CSS cannot express, so it is the one you have to ask for. diff --git a/apps/site/test/playground.test.tsx b/apps/site/test/playground.test.tsx index 620819a..9ae09df 100644 --- a/apps/site/test/playground.test.tsx +++ b/apps/site/test/playground.test.tsx @@ -153,6 +153,54 @@ const step = (label: RegExp, by: 1 | -1) => { const readout = () => container.querySelector(".playground-readout")?.textContent ?? ""; describe("the playground controls", () => { + it("opens on the hand-picked showcase state, not the engine defaults", () => { + // The page demonstrates a component someone would SHIP, and shipped components are + // tuned — so the opening state is chosen rather than inherited. Asserted value by + // value because "it looks right" is not a claim a test can make, and each number is a + // decision: 198% is what makes the dots read as one surface rather than separate + // pixels, 3% grow stops a dot pulsing like a blob, and a PINNED stagger means picking + // a different motion does not silently move a slider under the visitor. + const labels: Record = {}; + for (const row of container.querySelectorAll( + ".playground-side .playground-field, .stage-controls .playground-field", + )) { + const text = row.querySelector("span")?.textContent ?? ""; + const name = text.slice(0, text.search(/[0-9]/)).trim(); + const value = + row.querySelector("em")?.textContent?.trim() ?? + row.querySelector("output")?.textContent?.trim() ?? + ""; + if (name) labels[name] = value; + } + expect(labels["dot / cell"], "over the cell, so the dots overlap").toBe("198%"); + expect(labels.speed).toContain("1.00"); + expect(labels.stagger, "pinned at 70%").toMatch(/^70%/); + expect(labels.softness).toBe("0%"); + expect(labels.grow, "almost no breathing").toBe("3%"); + expect(labels.floor).toBe("16%"); + expect(labels["corner radius"]).toBe("0% of 71%"); + expect(labels.aspect).toBe("100%"); + expect(labels.size, "the largest box").toBe("260px"); + expect(labels["gap x"]).toBe("0%"); + expect(labels["gap y"]).toBe("0%"); + + expect( + [...container.querySelectorAll(".stepper")].map( + (s) => s.querySelector("output")?.textContent, + ), + "5 by 5", + ).toEqual(["5", "5"]); + + const text = readout(); + expect(text, "the readout agrees with the controls").toContain("dot / cell 198%"); + expect(text).toContain("dot / pitch 198%"); + expect(text).toContain("dot square"); + expect( + container.querySelector(".stage-toggle input")?.checked, + "CSS by default", + ).toBe(true); + }); + it("paints a field on mount", () => { expect(field().length).toBeGreaterThan(10); }); @@ -229,7 +277,12 @@ describe("the playground controls", () => { const square = field().length; pick(card(/shape|形状/i, "ring")); const ring = field().length; - expect(square, "square keeps every cell of a 7×7 lattice").toBe(49); + // read the opening grid off the steppers rather than hardcoding a cell count: the + // page opens on a showcase state, and a test about silhouettes has no business + // knowing what that state is + const cells = + Number(stepper(/cols/i).value.textContent) * Number(stepper(/rows/i).value.textContent); + expect(square, "square keeps every cell of the lattice").toBe(cells); expect(ring, "ring keeps only its outline").toBeLessThan(square); expect(readout()).toContain("ring"); }); @@ -284,9 +337,6 @@ describe("the playground controls", () => { () => pick(card(/motion|动效/i, key)), `selecting ${key} must not throw`, ).not.toThrow(); - const checked = container.querySelector( - ".card-group:nth-of-type(2) input:checked, .card-group input:checked", - ); expect( [...container.querySelectorAll(".card-group")] .find((g) => /motion|动效/i.test(g.querySelector("legend")?.textContent ?? "")) @@ -393,9 +443,10 @@ describe("the playground controls", () => { ?.querySelector("input:checked") ?.getAttribute("value"); - expect(checkedIn(/shape ·|形状/i), "the silhouette card is the engine's default").toBe( - DEFAULTS.silhouette, - ); + // the opening silhouette is the showcase's `square`, not the engine's `circle`: + // this test catches the card disagreeing with what is DRAWN, and asserting + // DEFAULTS would only pass if someone reset the opening state + expect(checkedIn(/shape ·|形状/i), "the silhouette card is what is rendered").toBe("square"); expect(checkedIn(/dot shape|点的形状/i), "the dot card is the engine's default").toBe( DEFAULTS.dot, ); @@ -404,7 +455,11 @@ describe("the playground controls", () => { ); const drawn = field().length; expect(drawn, "the rendered field matches the selected silhouette").toBe( - cellsFor(DEFAULTS.cols, DEFAULTS.rows, DEFAULTS.silhouette).length, + cellsFor( + Number(stepper(/cols/i).value.textContent), + Number(stepper(/rows/i).value.textContent), + "square", + ).length, ); }); @@ -485,7 +540,10 @@ describe("the playground controls", () => { // That asymmetry is deliberate and load-bearing — a dot that grew to fill the slack // on the roomy axis would be wider than it is tall — and it is exactly the kind of // thing a test that only checked "the number changed" would miss. - for (let i = 0; i < 4; i++) step(/^cols$|列/i, -1); + // 6×3, derived: at the opening dot/cell of 198% the old 3×5 is tight on ROWS, so + // gap x could not resize the dot and this test would have passed for the wrong reason. + while (Number(stepper(/^cols$/i).value.textContent) < 6) step(/^cols$/i, 1); + while (Number(stepper(/rows/i).value.textContent) > 3) step(/rows/i, -1); // an SVG transform reads `translate(x y) scale(s)` — space separated, not comma const transform = /translate\((-?[\d.]+)\s+(-?[\d.]+)\) scale\((-?[\d.]+)\)/; const read = (dot: { t?: string | null }) => transform.exec(dot.t ?? ""); @@ -500,7 +558,7 @@ describe("the playground controls", () => { const scaleAtWideX = scale(); drag(slider(/gap x/i), 0); expect(axisX(), "gap x must move the dots along x").not.toEqual(xWide); - expect(scale(), "gap x must NOT resize the dot — the rows are tighter").toBe(scaleAtWideX); + expect(scale(), "gap x DOES resize the dot — it is the tighter axis").not.toBe(scaleAtWideX); // the tighter axis (y): everything moves. Widening first, for the same reason. drag(slider(/gap y/i), 100); @@ -508,7 +566,7 @@ describe("the playground controls", () => { const scaleAtWideY = scale(); drag(slider(/gap y/i), 0); expect(axisY(), "gap y must move the dots along y").not.toEqual(yWide); - expect(scale(), "gap y DOES resize the dot — it is the tighter axis").not.toBe(scaleAtWideY); + expect(scale(), "gap y must NOT resize the dot — the columns are tighter").toBe(scaleAtWideY); }); it("the dot/cell slider still lands the field exactly on the box at 200%", () => { @@ -698,13 +756,16 @@ describe("a dial that follows a preset must be able to return to it", () => { it("the label states the preset’s own number, so it can never disagree with the thumb", () => { const row = staggerRow(); - const shown = row.querySelector("em")?.textContent ?? ""; - const input = row.querySelector("input") as HTMLInputElement; // spiral's spread is 0.95, and the label has to say so. The expectation comes // from the message rather than a literal, so this test does not encode a language: // a hardcoded "预设" here would have passed in English and failed in Chinese. - expect(shown).toContain("95%"); - expect(Number(input.value)).toBe(95); + // the page opens PINNED at 70%, so this row starts as an override and the claim + // under test is what happens once it follows the preset again — the reset being the + // only way there, which is the one-way door this describe is about + act(() => (row.querySelector(".reset") as HTMLButtonElement).click()); + const followed = row.querySelector("em")?.textContent ?? ""; + expect(followed, "on the preset, the label states its own number").toContain("95%"); + expect(Number((row.querySelector("input") as HTMLInputElement).value)).toBe(95); }); it("following the preset is reversible", () => {