Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Tests and docs: ?at= asserts play is on, a tile walks with the pointer parked, and the loop runs while a figure plays

Lucas Marquesfde359976b5c
diff --git a/README.md b/README.md
index 6b6482e..611efde 100644
--- a/README.md
+++ b/README.md
@@ -120,7 +120,7 @@ The figure's styles have no specificity, so any rule of yours wins without `!imp
- **Accessibility.** A figure is an image with a description you can replace with `label`. Riffle is the exception: it is a focusable group, the arrow keys walk its cards, and a live region reads the card out.
- **Reduced motion.** With `prefers-reduced-motion`, the figures that play on their own (Phosphor and Slow) hold still, a figure given `play` rests, and every figure still answers the pointer.
-- **Performance.** Every figure on a page shares one `requestAnimationFrame` loop. A figure off screen, or at rest, does no work, and the loop stops when nothing is moving.
+- **Performance.** Every figure on a page shares one `requestAnimationFrame` loop. A figure off screen, or at rest, does no work, and the loop stops when nothing is moving; a figure given `play` keeps it running while it is on screen.
- **Server rendering.** On the server a component is an empty box with a 5:4 aspect ratio, so nothing shifts when it draws. The functions need a DOM: call them in an effect, in `onMount`, or in a script after the element.
- **Shadow DOM.** A figure mounted inside a shadow root styles itself there.
diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.ts
index e0cbf5e..8759faa 100644
--- a/apps/site/test/figures.spec.ts
+++ b/apps/site/test/figures.spec.ts
@@ -275,6 +275,8 @@ const terrainStage = (page: Page) => tiles(page).filter({ has: page.locator(".fi
test("a tile walks its figure with no hand on the page", async ({ page }) => {
const noise = watch(page);
await page.goto("/figures");
+ /* no hand on the page: the pointer is parked in the corner, off every tile */
+ await page.mouse.move(0, 0);
const svg = terrainStage(page);
await expect(svg).toBeVisible();
const first = await svg.innerHTML();
diff --git a/packages/hairline/test/browser/skill.spec.ts b/packages/hairline/test/browser/skill.spec.ts
index 16655f2..ff77a1d 100644
--- a/packages/hairline/test/browser/skill.spec.ts
+++ b/packages/hairline/test/browser/skill.spec.ts
@@ -245,6 +245,7 @@ test("?at= holds the pointer over ?play=1", async ({ page }) => {
});
});
await page.goto("/bench/terrain?play=1&at=200,160");
+ await expect(page.locator("#play")).toHaveAttribute("aria-pressed", "true");
await expect.poll(() => read(page)).toMatch(/^cell/);
await page.waitForTimeout(3000);
expect(await page.evaluate(() => (window as any).__stops)).toEqual([]);