Skip to content

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

Keyboard: a sixty-key board whose key under the pointer sinks, and its neighbours follow it down

Lucas Marques9f462ee6924d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7877b21..71bb463 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,14 @@ Every release of `@lucasmarkes/hairline`. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
[semver](https://semver.org/).
+## 0.2.0 - Unreleased
+
+### Added
+
+- `keyboard` and `Keyboard`: a sixty-key board. The key under the pointer
+ sinks, and its neighbours follow it down, less the further away. A stronger
+ `intensity` sinks a wider patch of keys.
+
## 0.1.0 - 2026-10-01
First release.
diff --git a/README.md b/README.md
index 66a590a..bdb468b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# hairline
-Six isometric line figures that answer the pointer. For React and for anything with a DOM.
+Seven isometric line figures that answer the pointer. For React and for anything with a DOM.
[![npm](https://img.shields.io/npm/v/@lucasmarkes/hairline)](https://www.npmjs.com/package/@lucasmarkes/hairline)
[![CI](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml/badge.svg)](https://github.com/lucasmarkes/hairline/actions/workflows/ci.yml)
@@ -61,6 +61,7 @@ A figure draws into the element you give it, at the element's width and a 5:4 as
| `phosphor` | `Phosphor` | A dot matrix that plays a loop, and fades like phosphor where the pointer paints it. | The trail lingers longer. |
| `slow` | `Slow` | Crates riding a belt through a gate. Hovering slows the clock without stopping it. | Time slows down more. |
| `turntable` | `Turntable` | Blocks on a turntable. A flick spins it; it settles on the nearest quarter turn. | The spin coasts longer. |
+| `keyboard` | `Keyboard` | A sixty-key board. The key under the pointer sinks, and its neighbours follow it down. | A wider patch of keys sinks. |
## Options
@@ -104,7 +105,7 @@ The figure's styles have no specificity, so any rule of yours wins without `!imp
## Make your own
-`hairline-create` is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the six above, as one HTML file.
+`hairline-create` is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the seven above, as one HTML file.
```sh
npx skills add lucasmarkes/hairline
diff --git a/apps/site/app/docs/page.tsx b/apps/site/app/docs/page.tsx
index 048430a..dc84f96 100644
--- a/apps/site/app/docs/page.tsx
+++ b/apps/site/app/docs/page.tsx
@@ -3,11 +3,12 @@ import type { CSSProperties } from "react";
import { Footer, Topbar } from "@/components/chrome";
import { Rail, type RailGroup } from "@/components/rail";
import { SECTIONS, type Group } from "@/lib/docs";
-import { LINKS } from "@/lib/figures";
+import { COUNT, LINKS } from "@/lib/figures";
import { highlight } from "@/lib/highlight";
import { share } from "@/lib/share";
import { tiny } from "@/lib/size";
import { CDN, CSS, QUICKSTART, REACT, REACT_SIGNATURE, VANILLA, VANILLA_SIGNATURE, install } from "@/lib/snippets";
+import { cap } from "@/lib/words";
import { Api, GettingStarted, Reference } from "./sections";
const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
@@ -47,7 +48,7 @@ export default async function Docs() {
<Rail label="Docs" groups={RAIL} />
<main className="col">
<header className="hero-rise">
- <h1 className="col-h1" style={at(0)}>Six figures, one set of options.</h1>
+ <h1 className="col-h1" style={at(0)}>{cap(COUNT)} figures, one set of options.</h1>
<p className="col-lede" style={at(1)}>
Every figure takes the same four options and draws itself in SVG, with no dependencies. Install the package, paste a figure, and turn <code className="doc-code">intensity</code> up or down.
</p>
diff --git a/apps/site/app/docs/sections.tsx b/apps/site/app/docs/sections.tsx
index 3663320..02530e2 100644
--- a/apps/site/app/docs/sections.tsx
+++ b/apps/site/app/docs/sections.tsx
@@ -1,14 +1,14 @@
import type { ReactNode } from "react";
-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { Anchor } from "@/components/anchor";
import { CodeBlock } from "@/components/code-block";
import { Install } from "@/components/install";
import { Tabs, type Tab } from "@/components/tabs";
import { SECTIONS } from "@/lib/docs";
-import { FIGURES, INTENSITY, OPTIONS, THEME, measure } from "@/lib/figures";
+import { COUNT, FIGURES, INTENSITY, OPTIONS, THEME, measure } from "@/lib/figures";
import { PACKAGE } from "@/lib/snippets";
-const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };
+const SMALL = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard };
/** A section takes its title from SECTIONS, the list the rail reads, so the two always agree. Its link copies from beside its title. */
function Section({ id, children }: { id: string; children: ReactNode }) {
@@ -33,7 +33,7 @@ export function GettingStarted({ commands, size, quickstart }: { commands: { lab
<p className="doc-p">Install the package, then import a figure wherever your interface runs.</p>
<div className="max-w-[460px]"><Install commands={commands} /></div>
<p className="doc-note">
- Click the command to switch package manager. ESM only, no dependencies, <span data-size>{size}</span> gzipped for all six; a bundle that imports one carries one.
+ Click the command to switch package manager. ESM only, no dependencies, <span data-size>{size}</span> gzipped for all {COUNT}; a bundle that imports one carries one.
</p>
</Section>
<Section id="quick-start">
@@ -67,7 +67,7 @@ export function Api({ code }: { code: { reactSignature: string; react: string; v
<Section id="react">
<CodeBlock title="Signature" html={code.reactSignature} plain />
<p className="doc-p">
- Import any of the six from <C>{PACKAGE}/react</C>. Each renders a <C>&lt;div&gt;</C>, takes any <C>&lt;div&gt;</C> attribute and forwards its ref. The entry is a client module, so a Server Component renders it without writing <C>&quot;use client&quot;</C>.
+ Import any of the {COUNT} from <C>{PACKAGE}/react</C>. Each renders a <C>&lt;div&gt;</C>, takes any <C>&lt;div&gt;</C> attribute and forwards its ref. The entry is a client module, so a Server Component renders it without writing <C>&quot;use client&quot;</C>.
</p>
<CodeBlock title="app/page.tsx" html={code.react} />
</Section>
diff --git a/apps/site/app/globals.css b/apps/site/app/globals.css
index 396cd9b..02eaa12 100644
--- a/apps/site/app/globals.css
+++ b/apps/site/app/globals.css
@@ -281,7 +281,7 @@ footer a::after { content: ""; position: absolute; inset: -12px -8px; }
.skill-link:focus-visible .skill-link-hex { stroke: var(--color-ink); }
.skill-link:focus-visible .skill-link-edge { stroke-dashoffset: 0; }
-/* The reel: the figure on the page itself and six ticks under it. Every figure is 5:4 and the layers of a change
+/* The reel: the figure on the page itself and a tick per figure under it. Every figure is 5:4 and the layers of a change
stack in one box, so a change of figure never moves the page. */
.hero-reel { width: 100%; margin-top: 14px; scroll-margin-top: calc(var(--topbar) + 24px); }
.reel { display: grid; justify-items: center; }
diff --git a/apps/site/app/page.tsx b/apps/site/app/page.tsx
index 663303a..6516714 100644
--- a/apps/site/app/page.tsx
+++ b/apps/site/app/page.tsx
@@ -3,7 +3,9 @@ import { Footer, Topbar } from "@/components/chrome";
import { Install } from "@/components/install";
import { Reel } from "@/components/reel";
import { SkillLink } from "@/components/skill-link";
+import { COUNT } from "@/lib/figures";
import { install } from "@/lib/snippets";
+import { cap } from "@/lib/words";
const SITE = process.env.NEXT_PUBLIC_SITE_URL!;
@@ -12,7 +14,7 @@ const at = (i: number) => ({ "--i": i }) as CSSProperties;
/**
* The home, as one column: the pitch, the command with the way in, the way to the
- * skill, then the six figures playing by themselves. A Server Component, so the figures
+ * skill, then the figures playing by themselves. A Server Component, so the figures
* are the package's React components rendered from here, and every deploy
* runs them through server rendering and hydration. The rest lives on /docs.
*/
@@ -25,7 +27,7 @@ export default function Page() {
<h1 id="hairline" className="hero-title" style={at(0)}>
Line drawings that <em>answer</em> the pointer.
</h1>
- <p className="hero-sub" style={at(1)}>Six isometric figures for the web. SVG, no dependencies, React or plain DOM.</p>
+ <p className="hero-sub" style={at(1)}>{cap(COUNT)} isometric figures for the web. SVG, no dependencies, React or plain DOM.</p>
<div className="hero-get" style={at(2)}>
<Install commands={install(SITE)} />
<a className="btn btn-primary press" href="/docs">Get started</a>
diff --git a/apps/site/app/skill/page.tsx b/apps/site/app/skill/page.tsx
index 67d5fdd..fd99051 100644
--- a/apps/site/app/skill/page.tsx
+++ b/apps/site/app/skill/page.tsx
@@ -5,7 +5,7 @@ import { Footer, Topbar } from "@/components/chrome";
import { Command } from "@/components/command";
import { ExampleFrame } from "@/components/example-frame";
import { Rail } from "@/components/rail";
-import { LINKS } from "@/lib/figures";
+import { COUNT, LINKS } from "@/lib/figures";
import { share } from "@/lib/share";
import { COMMAND, FOLDER, INSTALL, STEPS, SUMMARY, USE, examples } from "@/lib/skill";
@@ -113,7 +113,7 @@ export default function Skill() {
</Section>
<p className="col-end">
- The six figures and their options are in <a className="doc-more" href="/docs">the docs</a>. The skill&rsquo;s files are in <a className="doc-more" href={`${LINKS.github}/tree/main/skills/hairline-create`}>its folder on GitHub</a>.
+ The {COUNT} figures and their options are in <a className="doc-more" href="/docs">the docs</a>. The skill&rsquo;s files are in <a className="doc-more" href={`${LINKS.github}/tree/main/skills/hairline-create`}>its folder on GitHub</a>.
</p>
</main>
<Footer />
diff --git a/apps/site/components/catalogue.tsx b/apps/site/components/catalogue.tsx
index d62bdc7..4c48fdf 100644
--- a/apps/site/components/catalogue.tsx
+++ b/apps/site/components/catalogue.tsx
@@ -1,12 +1,12 @@
"use client";
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { ENTRIES, SHELVES, type Entry, type Shelf, type ShelfId } from "@/lib/catalogue";
import { LINKS, type FigureId } from "@/lib/figures";
import { Tabs, type Tab } from "./tabs";
-const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };
+const COMPONENTS: Record<FigureId, typeof Riffle> = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard };
type Filter = "all" | ShelfId;
diff --git a/apps/site/components/reel.tsx b/apps/site/components/reel.tsx
index fab7428..9187410 100644
--- a/apps/site/components/reel.tsx
+++ b/apps/site/components/reel.tsx
@@ -1,10 +1,10 @@
"use client";
import { useEffect, useRef, useState, type CSSProperties } from "react";
-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
+import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "@lucasmarkes/hairline/react";
import { FIGURES } from "@/lib/figures";
-const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable };
+const COMPONENTS = { riffle: Riffle, terrain: Terrain, exploded: Exploded, phosphor: Phosphor, slow: Slow, turntable: Turntable, keyboard: Keyboard };
/**
* One pass of a pointer over each figure, in its viewBox (400 × 320): [x, y, ms]. Each path does the
@@ -17,6 +17,7 @@ const DEMO: Record<keyof typeof COMPONENTS, [number, number, number][]> = {
phosphor: [[130, 100, 0], [270, 100, 700], [140, 160, 1400], [275, 165, 2100]],
slow: [[120, 250, 0], [200, 165, 700], [206, 160, 2600]],
turntable: [[100, 170, 0], [125, 168, 400], [310, 160, 620], [320, 158, 900]],
+ keyboard: [[126, 116, 0], [290, 198, 2000], [172, 165, 3000]],
};
/** Long enough for the slowest dissolve (the reel's own, 520ms) to finish before its leaver goes. */
@@ -25,7 +26,7 @@ const LEAVE_MS = 640;
type Layer = { key: number; at: number; leaving: boolean };
/**
- * The six figures, one at a time, standing on the page with no controls. Each
+ * The figures, one at a time, standing on the page with no controls. Each
* plays for six seconds while its tick fills, then the next dissolves in over
* it. A pointer on the figure pauses the reel, and so does a hidden tab;
* picking a tick shows that figure and stops the reel for good. Under reduced
diff --git a/apps/site/lib/catalogue.ts b/apps/site/lib/catalogue.ts
index aff1785..6b7028e 100644
--- a/apps/site/lib/catalogue.ts
+++ b/apps/site/lib/catalogue.ts
@@ -1,4 +1,7 @@
import { FIGURES, type FigureId } from "./figures";
+import { cap, spell } from "./words";
+
+export { spell };
/**
* /figures: every figure on its shelf, by what it draws. A drawn figure takes
@@ -24,7 +27,7 @@ export const SHELVES: Shelf[] = [
id: "interfaces", title: "Interfaces", color: "#3b82f6", figures: [
drawn("exploded"),
drawn("riffle"),
- planned("keyboard", "Keyboard", "Sixty keys in a block. The key under the pointer sinks and its neighbours follow it down, less the further away.", "A wider patch of keys sinks."),
+ drawn("keyboard"),
],
},
{
@@ -73,17 +76,6 @@ export const SHELVES: Shelf[] = [
export const ENTRIES: Entry[] = SHELVES.flatMap((s) => s.figures);
-const ONES = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
-const TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
-
-/** A count as the page's prose writes it, "twenty-one", so the lede is read from the shelves and cannot fall behind them. Up to 99. */
-export function spell(n: number): string {
- if (n < 20) return ONES[n];
- return TENS[Math.floor(n / 10)] + (n % 10 ? `-${ONES[n % 10]}` : "");
-}
-
-const cap = (s: string) => s[0].toUpperCase() + s.slice(1);
-
/** "Seven shelves, twenty-one figures" */
export function tally(): string {
return `${cap(spell(SHELVES.length))} shelves, ${spell(ENTRIES.length)} figures`;
diff --git a/apps/site/lib/figures.ts b/apps/site/lib/figures.ts
index dbf1dfe..c4a01c8 100644
--- a/apps/site/lib/figures.ts
+++ b/apps/site/lib/figures.ts
@@ -6,7 +6,9 @@
* cannot describe a map the figures do not use.
*/
-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable";
+import { spell } from "./words";
+
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard";
export type FigureDoc = {
id: FigureId;
@@ -62,8 +64,18 @@ export const FIGURES: FigureDoc[] = [
stronger: "The spin coasts longer.",
parameter: { name: "coast", unit: "ms" },
},
+ {
+ id: "keyboard",
+ name: "Keyboard",
+ summary: "Sixty keys in a block. The key under the pointer sinks and its neighbours follow it down, less the further away.",
+ stronger: "A wider patch of keys sinks.",
+ parameter: { name: "radius", unit: "keys" },
+ },
];
+/** How many figures the package has, as the prose writes it: "seven". */
+export const COUNT = spell(FIGURES.length);
+
/** Each figure's number at intensity 0, 0.5 and 1: a copy of the package's table. */
export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {
riffle: [0, 40, 90],
@@ -72,6 +84,7 @@ export const INTENSITY: Record<FigureId, readonly [number, number, number]> = {
phosphor: [150, 520, 1500],
slow: [0.6, 0.2, 0.05],
turntable: [200, 650, 1500],
+ keyboard: [1, 2, 3.5],
};
/** A number with its unit, as the docs' table and /llms.txt write it: "40 ms", "0.2× normal speed". */
diff --git a/apps/site/lib/llms.ts b/apps/site/lib/llms.ts
index 741f8fc..73edb8d 100644
--- a/apps/site/lib/llms.ts
+++ b/apps/site/lib/llms.ts
@@ -1,4 +1,4 @@
-import { FIGURES, INTENSITY, LINKS, OPTIONS, THEME, measure, type Row } from "./figures";
+import { COUNT, FIGURES, INTENSITY, LINKS, OPTIONS, THEME, measure, type Row } from "./figures";
import { CDN, PACKAGE, REACT, VANILLA, install } from "./snippets";
import { COMMAND, EXAMPLES, INSTALL, SUMMARY } from "./skill";
@@ -17,7 +17,7 @@ export function llms(base: string): string {
const out: string[] = [
"# hairline",
"",
- `> ${PACKAGE}: six isometric line figures that answer the pointer. SVG, no dependencies, ESM only. A function per figure, and a React component per figure. Every figure takes the same four options.`,
+ `> ${PACKAGE}: ${COUNT} isometric line figures that answer the pointer. SVG, no dependencies, ESM only. A function per figure, and a React component per figure. Every figure takes the same four options.`,
"",
"## Install",
"",
diff --git a/apps/site/lib/share.ts b/apps/site/lib/share.ts
index c730878..998d324 100644
--- a/apps/site/lib/share.ts
+++ b/apps/site/lib/share.ts
@@ -1,8 +1,9 @@
import type { Metadata } from "next";
-import { LINKS } from "./figures";
+import { COUNT, LINKS } from "./figures";
+import { cap } from "./words";
/** What a page says of itself where it has nothing closer to say. */
-export const DESCRIPTION = "Six isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.";
+export const DESCRIPTION = `${cap(COUNT)} isometric line figures that answer the pointer. SVG, no dependencies, for React and for everything else.`;
/** The pages a reader can land on, in the top bar's order: the sitemap lists these. /og is left out, a picture to photograph. */
export const PAGES = ["/", "/figures", "/docs", "/skill", "/inspo"] as const;
diff --git a/apps/site/lib/size.ts b/apps/site/lib/size.ts
index a084366..b0f849c 100644
--- a/apps/site/lib/size.ts
+++ b/apps/site/lib/size.ts
@@ -3,7 +3,7 @@ import { join } from "node:path";
import { gzipSync } from "node:zlib";
/**
- * The vanilla entry's gzip size with all six figures, as the Tiny card says
+ * The vanilla entry's gzip size with every figure, as the Tiny card says
* it: "16.3 kB". Measured at build from the package's own dist, which turbo
* builds before the site. Next runs the build from apps/site.
*/
diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.ts
index a2f3d88..31922d9 100644
--- a/apps/site/lib/skill.ts
+++ b/apps/site/lib/skill.ts
@@ -1,5 +1,6 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
+import { COUNT } from "./figures";
/**
* The skill, as the site tells it: the two commands, the examples, and the
@@ -49,7 +50,7 @@ export function examples(): Shown[] {
});
}
-export const SUMMARY = "hairline-create is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the six in the docs, as one HTML file.";
+export const SUMMARY = `hairline-create is a skill for coding agents. Give it an idea and it draws a new figure to Hairline's ten rules, on the same engine as the ${COUNT} in the docs, as one HTML file.`;
export const STEPS: { title: string; text: string }[] = [
{ title: "Concepts", text: "It offers two or three concepts, one line each: the object, what the pointer does, what the read-out says. You pick one." },
diff --git a/apps/site/lib/words.ts b/apps/site/lib/words.ts
new file mode 100644
index 0000000..749aa32
--- /dev/null
+++ b/apps/site/lib/words.ts
@@ -0,0 +1,10 @@
+const ONES = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
+const TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
+
+/** A count as the site's prose writes it, "twenty-one", so a sentence is read from a list and cannot fall behind it. Up to 99. */
+export function spell(n: number): string {
+ if (n < 20) return ONES[n];
+ return TENS[Math.floor(n / 10)] + (n % 10 ? `-${ONES[n % 10]}` : "");
+}
+
+export const cap = (s: string) => s[0].toUpperCase() + s.slice(1);
diff --git a/apps/site/test/docs.test.ts b/apps/site/test/docs.test.ts
index 32ff6d3..401a2c5 100644
--- a/apps/site/test/docs.test.ts
+++ b/apps/site/test/docs.test.ts
@@ -19,7 +19,7 @@ import { CDN, CSS, QUICKSTART, REACT, REACT_SIGNATURE, VANILLA, VANILLA_SIGNATUR
const KEYS = { intensity: true, theme: true, label: true, onRead: true } satisfies Record<keyof HairlineOptions, true>;
describe("the figures", () => {
- it("are the package's six, each with a function and a component", () => {
+ it("are the package's, each with a function and a component", () => {
expect(FIGURES.map((f) => f.id).sort()).toEqual(Object.keys(figures).sort());
for (const doc of FIGURES) expect(components).toHaveProperty(doc.name);
});
diff --git a/apps/site/test/figures.spec.ts b/apps/site/test/figures.spec.ts
index 99bbc91..821b62d 100644
--- a/apps/site/test/figures.spec.ts
+++ b/apps/site/test/figures.spec.ts
@@ -16,21 +16,21 @@ function watch(page: Page): string[] {
const tiles = (page: Page) => page.locator(".fig-tile");
const shelf = (page: Page, name: string) => page.locator(".shelves .shelf", { hasText: name });
-test("/figures prerenders six empty boxes among twenty-one tiles, then draws them with a clean console", async ({ page, request }) => {
+test("/figures prerenders seven empty boxes among twenty-one tiles, then draws them with a clean console", async ({ page, request }) => {
const html = await (await request.get("/figures")).text();
- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(6);
+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(7);
expect(html.match(/class="fig-tile"/g)).toHaveLength(21);
- expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(15);
+ expect(html.match(/class="fig-tile" data-planned=""/g)).toHaveLength(14);
const noise = watch(page);
await page.goto("/figures");
await expect(tiles(page)).toHaveCount(21);
- await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(6);
- await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(15);
+ await expect(page.locator(".fig-tile [data-hairline] > svg")).toHaveCount(7);
+ await expect(page.locator(".fig-tile .fig-ghost")).toHaveCount(14);
await expect(page.locator("h1")).toHaveText("Every figure, by what it draws.");
await expect(page.locator(".doc-section h2")).toHaveText(SHELVES);
await expect(page.locator(".fig-name").first()).toHaveAccessibleName("Exploded");
- await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Keyboard, planned");
+ await expect(page.locator(".fig-tile[data-planned] .fig-name").first()).toHaveAccessibleName("Funnel, planned");
expect(noise).toEqual([]);
});
diff --git a/apps/site/test/site.spec.ts b/apps/site/test/site.spec.ts
index 352e21b..6e9c46d 100644
--- a/apps/site/test/site.spec.ts
+++ b/apps/site/test/site.spec.ts
@@ -1,6 +1,6 @@
import { expect, test, type Page } from "@playwright/test";
-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable"];
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard"];
const MANAGERS = [
["npm", "npm i @lucasmarkes/hairline"],
["pnpm", "pnpm add @lucasmarkes/hairline"],
@@ -64,14 +64,14 @@ test("the top bar's links sit as one row: one height, one centre line, one type,
for (const s of spaces) expect(Math.abs(s - spaces[0])).toBeLessThan(1.5);
});
-test("the docs prerender six empty boxes, then draw one figure per row with a clean console", async ({ page, request }) => {
+test("the docs prerender an empty box per figure, then draw one figure per row with a clean console", async ({ page, request }) => {
const html = await (await request.get("/docs")).text();
- expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(6);
+ expect(html.match(/<div style="aspect-ratio:5 \/ 4"><\/div>/g)).toHaveLength(IDS.length);
expect(html).not.toMatch(/aspect-ratio:5 \/ 4"[^>]*><svg/);
const noise = watch(page);
await page.goto("/docs");
- await expect(page.locator("[data-hairline] > svg")).toHaveCount(6);
+ await expect(page.locator("[data-hairline] > svg")).toHaveCount(IDS.length);
for (const id of IDS) await expect(page.locator(`[data-row="${id}"] [data-hairline] > svg > *`).first()).toBeAttached();
await expect(page.locator("[data-size]")).toHaveText(/^\d+\.\d kB$/);
expect(noise).toEqual([]);
@@ -105,12 +105,12 @@ test("the home's entrance settles within 1.4s, with its hero blocks 70ms apart",
expect(timing.end).toBeLessThanOrEqual(1400);
});
-test("the reel plays the six figures in turn, holds under the pointer, and stops on a picked tick", async ({ page }) => {
+test("the reel plays the figures in turn, holds under the pointer, and stops on a picked tick", async ({ page }) => {
await page.goto("/");
const reel = page.locator("[data-reel]");
const figure = reel.locator(".reel-stage");
const ticks = reel.getByRole("group", { name: "Figures" }).getByRole("button");
- await expect(ticks).toHaveCount(6);
+ await expect(ticks).toHaveCount(IDS.length);
await expect(figure).toHaveAttribute("data-figure", "riffle");
await expect(ticks.first()).toHaveAttribute("aria-current", "true");
// the figure stands alone: no caption under it
@@ -146,13 +146,13 @@ test("under reduced motion the reel never starts", async ({ page }) => {
await expect(page.locator(".reel-stage")).toHaveAttribute("data-figure", "riffle");
});
-test("a change of figure never moves the page: the reel and the page hold their height through all six", async ({ page }) => {
+test("a change of figure never moves the page: the reel and the page hold their height through every figure", async ({ page }) => {
for (const width of [1440, 390, 320]) {
await page.setViewportSize({ width, height: 800 });
await page.goto("/");
const ticks = page.locator(".reel-tick");
const heights = new Set<string>();
- for (let i = 0; i < 6; i++) {
+ for (let i = 0; i < IDS.length; i++) {
await ticks.nth(i).click();
await expect(page.locator(".reel-stage [data-hairline] > svg")).toHaveCount(1);
heights.add(await page.evaluate(() => `${document.documentElement.scrollHeight} ${Math.round(document.querySelector(".reel")!.getBoundingClientRect().height)}`));
@@ -286,9 +286,9 @@ const BASE = "http://localhost:3000";
test("a pasted link shows the page it leads to: each page's card has its own title, text and address", async ({ request }) => {
const CARDS = [
- ["/", "hairline", /^Six isometric line figures/],
+ ["/", "hairline", /^Seven isometric line figures/],
["/figures", "Figures", /^Seven shelves, twenty-one figures, grouped by what they draw/],
- ["/docs", "Docs", /^Six isometric line figures/],
+ ["/docs", "Docs", /^Seven isometric line figures/],
["/skill", "Make your own figure", /^hairline-create is a skill/],
["/inspo", "How Hairline was made", /^A long brief/],
] as const;
@@ -327,13 +327,13 @@ test("the page fits a phone, with the longest install command, its buttons and t
expect(await width()).toBeLessThanOrEqual(390);
const controls = page.locator(".hero-get .btn, .reel-tick");
- await expect(controls).toHaveCount(7);
+ await expect(controls).toHaveCount(1 + IDS.length);
for (const control of await controls.all()) {
const box = (await control.boundingBox())!;
expect(box.x).toBeGreaterThanOrEqual(0);
expect(box.x + box.width).toBeLessThanOrEqual(390);
}
- await page.getByRole("button", { name: "Turntable" }).click();
+ await page.getByRole("button", { name: "Keyboard" }).click();
expect(await width()).toBeLessThanOrEqual(390);
});
diff --git a/fixtures/vite-vanilla/index.html b/fixtures/vite-vanilla/index.html
index 3d05232..ab9ef27 100644
--- a/fixtures/vite-vanilla/index.html
+++ b/fixtures/vite-vanilla/index.html
@@ -17,6 +17,7 @@
<div id="phosphor"></div>
<div id="slow"></div>
<div id="turntable"></div>
+ <div id="keyboard"></div>
</main>
<output id="read"></output>
<script type="module" src="/src/main.ts"></script>
diff --git a/fixtures/vite-vanilla/src/main.ts b/fixtures/vite-vanilla/src/main.ts
index ee3059d..d96d3bd 100644
--- a/fixtures/vite-vanilla/src/main.ts
+++ b/fixtures/vite-vanilla/src/main.ts
@@ -1,6 +1,6 @@
-import { exploded, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";
+import { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure } from "@lucasmarkes/hairline";
-/** No framework: six elements, six calls. */
+/** No framework: seven elements, seven calls. */
const el = (id: string) => document.getElementById(id)!;
const read = el("read");
@@ -13,5 +13,6 @@ exploded(el("exploded"));
phosphor(el("phosphor"), { theme: "dark" });
slow(el("slow"));
turntable(el("turntable"));
+keyboard(el("keyboard"));
cards.update({ intensity: 0.8 });
diff --git a/package.json b/package.json
index a1fca50..05b9e20 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "hairline-monorepo",
"version": "0.0.0",
"private": true,
- "description": "Six isometric line figures that answer the pointer",
+ "description": "Seven isometric line figures that answer the pointer",
"packageManager": "[email protected]",
"engines": {
"node": ">=22"
diff --git a/packages/hairline/package.json b/packages/hairline/package.json
index 5f7f0ee..fe0bd22 100644
--- a/packages/hairline/package.json
+++ b/packages/hairline/package.json
@@ -1,7 +1,7 @@
{
"name": "@lucasmarkes/hairline",
- "version": "0.1.0",
- "description": "Six isometric line figures that answer the pointer. For React and for anything with a DOM.",
+ "version": "0.2.0",
+ "description": "Seven isometric line figures that answer the pointer. For React and for anything with a DOM.",
"license": "MIT",
"type": "module",
"sideEffects": false,
@@ -81,7 +81,7 @@
},
"size-limit": [
{
- "name": "vanilla, all six figures",
+ "name": "vanilla, every figure",
"path": "dist/index.js",
"limit": "12.8 kB"
},
@@ -92,7 +92,7 @@
"limit": "5.4 kB"
},
{
- "name": "react, all six components",
+ "name": "react, every component",
"path": "dist/react.js",
"limit": "13.2 kB",
"ignore": [
diff --git a/packages/hairline/src/figures/keyboard.ts b/packages/hairline/src/figures/keyboard.ts
new file mode 100644
index 0000000..f106c9d
--- /dev/null
+++ b/packages/hairline/src/figures/keyboard.ts
@@ -0,0 +1,142 @@
+import { Cam, clamp, facing, fit, hull, open, poly, prism, proj, ringAt, rings, rrect, run, seg, unproj, type Ring, type Vec2 } from "../core/iso";
+import { spring, stepS, type Spring } from "../core/motion";
+import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+
+/**
+ * Keyboard: a sixty-key board, rows staggered as a real one's are, with the
+ * long keys a hand finds without looking: backspace, enter, the two shifts,
+ * the space bar. Each cap is narrower at its top than at its foot, and each row
+ * stands at its own height, the sculpted profile. The pointer is put on the
+ * tops of the rows at rest, front row first; the key under it sinks all the
+ * way and its neighbours follow it down, less the further away, each on its own
+ * spring. At rest, enter is caught half-way down, bright. The slider is the
+ * radius, in keys.
+ *
+ * The pattern: a continuous field, as Terrain's, over discrete parts: a spring
+ * per key, a falloff by distance, a hit test on each row's rest top.
+ */
+
+const U = 14, PAD = 0.8, TAPER = 1.8, Z0 = 1, TRAVEL = 8, BZ = 6, CASE = 8, W = 15;
+/** Each row's rest height, back to front: the sculpted profile, lowest on the home row. */
+const ROW_H = [12.6, 11.3, 10.4, 11, 11.8];
+/** Each row's keys, as [width in keys, read-out]. Fifteen keys wide; sixty keys in all. */
+const L = (s: string) => s.split(" ").map((c): [number, string] => [1, "key " + c]);
+const ROWS: Array<Array<[number, string]>> = [
+ [[1, "esc"], ...L("1 2 3 4 5 6 7 8 9 0 - ="), [2, "bksp"]],
+ [[1.5, "tab"], ...L("q w e r t y u i o p [ ]"), [1.5, "key \\"]],
+ [[1.75, "caps"], ...L("a s d f g h j k l ; '"), [2.25, "enter"]],
+ [[2.25, "shift l"], ...L("z x c v b n m , . /"), [2.75, "shift r"]],
+ [[1.5, "ctrl l"], [1, "super"], [1.5, "alt l"], [7, "space"], [1.5, "alt r"], [1, "fn"], [1.5, "ctrl r"]],
+];
+const HOMING = ["key f", "key j"];
+
+/** The share of full travel a neighbour sinks, u radii from the pointer: all of it at the pressed key's edge, nothing past one radius. */
+const falloff = (u: number) => clamp(1 - u, 0, 1);
+
+type Key = {
+ r: number; name: string; x0: number; x1: number; y0: number; y1: number; h: number;
+ foot: Ring; top: Ring; inner: Ring; el: Solid; sp: Spring; drawn: number; bump: SVGPathElement | null;
+};
+type Over = { at: Vec2; key: Key };
+
+export const mount: FigureMount = ({ stage, svg, read }, value) => {
+ const bag = disposer();
+ const C = Cam(45, 0.5, 1.42);
+ fit(C, [[-BZ, -BZ, -CASE], [W * U + BZ, 5 * U + BZ, -CASE], [W * U + BZ, -BZ, -CASE], [-BZ, 5 * U + BZ, -CASE], [0, 0, ROW_H[0]]], 200, 166);
+ const P = proj(C), front = facing(C);
+ let R = value, over: Over | null = null, lit: Key | null = null;
+
+ const g = mk("g", {}, svg);
+ const [cr, ci] = rings(-BZ, -BZ, W * U + BZ, 5 * U + BZ, 9, 2.2);
+ put(solid(g), prism(P, front, cr, ci, -CASE, 0));
+
+ // Row by row from the back, and left to right in a row: each key is cut from
+ // the ones behind it and to its left by a vertical plane, so this is back to front.
+ const keys: Key[] = [];
+ ROWS.forEach((row, r) => {
+ let x = 0;
+ for (const [w, name] of row) {
+ const x0 = x * U, x1 = (x + w) * U, y0 = r * U, y1 = (r + 1) * U, t = PAD + TAPER;
+ const el = solid(g);
+ keys.push({
+ r, name, x0, x1, y0, y1, h: ROW_H[r],
+ foot: rrect(x0 + PAD, y0 + PAD, x1 - PAD, y1 - PAD, 2.6, 4),
+ top: rrect(x0 + t, y0 + t, x1 - t, y1 - t, 2, 4),
+ inner: rrect(x0 + t + 0.9, y0 + t + 0.9, x1 - t - 0.9, y1 - t - 0.9, 1.2, 4),
+ el, sp: spring(ROW_H[r], { eps: 0.02 }), drawn: NaN,
+ bump: HOMING.includes(name) ? mk("path", { class: "lo nf" }, el.g) : null,
+ });
+ x += w;
+ }
+ });
+ const enter = keys.find((k) => k.name === "enter")!;
+
+ /** Each key's target depth, from a point on the board, the key pressed, a radius in keys and a share of full travel. */
+ function sink(at: Vec2, pressed: Key, radius: number, depth: number) {
+ for (const k of keys) {
+ const dx = Math.max(k.x0 - at[0], 0, at[0] - k.x1), dy = Math.max(k.y0 - at[1], 0, at[1] - k.y1);
+ const f = k === pressed ? 1 : falloff(Math.hypot(dx, dy) / (radius * U));
+ k.sp.t = k.h - TRAVEL * depth * f;
+ }
+ }
+ const restAt: Vec2 = [(enter.x0 + enter.x1) / 2, (enter.y0 + enter.y1) / 2];
+ sink(restAt, enter, 1.6, 0.6);
+ for (const k of keys) k.sp.x = k.sp.t;
+
+ function drawKey(k: Key) {
+ const h = k.sp.x;
+ if (h === k.drawn) return;
+ k.drawn = h;
+ put(k.el, { sil: poly(hull(ringAt(P, k.foot, Z0).concat(ringAt(P, k.top, h)))), crease: open(ringAt(P, run(k.inner, front), h)) });
+ if (k.bump) {
+ const cx = (k.x0 + k.x1) / 2, cy = k.y1 - PAD - TAPER - 2.4;
+ k.bump.setAttribute("d", seg(P(cx - 2.2, cy, h), P(cx + 2.2, cy, h)));
+ }
+ }
+ function light(k: Key) {
+ if (k === lit) return;
+ lit?.el.sil.classList.remove("hi");
+ lit = k;
+ k.el.sil.classList.add("hi");
+ }
+
+ const B = register(stage, (dt) => {
+ let m = false;
+ for (const k of keys) { if (stepS(k.sp, dt)) m = true; drawKey(k); }
+ return m;
+ });
+ bag.add(B.unregister);
+
+ const keyAt = (r: number, x: number) => keys.find((k) => k.r === r && x >= k.x0 && x < k.x1)!;
+ /** The key under a screen point, tested against each row's rest top, front row first, as a nearer row covers a farther one. */
+ function hit(p: Vec2): Over | null {
+ for (let r = ROWS.length - 1; r >= 0; r--) {
+ const q = unproj(C, p[0], p[1], ROW_H[r]);
+ if (q[1] < r * U || q[1] >= (r + 1) * U || q[0] < 0 || q[0] >= W * U) continue;
+ return { at: q, key: keyAt(r, q[0]) };
+ }
+ // in a gap between two rows' tops, or over the bezel: the nearest key on the board
+ const q = unproj(C, p[0], p[1], ROW_H[2]);
+ if (q[0] < -BZ || q[0] > W * U + BZ || q[1] < -BZ || q[1] > 5 * U + BZ) return null;
+ const at: Vec2 = [clamp(q[0], 0, W * U - 0.01), clamp(q[1], 0, 5 * U - 0.01)];
+ return { at, key: keyAt(Math.floor(at[1] / U), at[0]) };
+ }
+
+ function retarget() {
+ if (over) { sink(over.at, over.key, R, 1); light(over.key); read.textContent = over.key.name; }
+ else { sink(restAt, enter, 1.6, 0.6); light(enter); read.textContent = "rest"; }
+ B.wake();
+ }
+ light(enter);
+
+ bag.add(pointer(stage, {
+ move: (p) => { over = hit(p); retarget(); },
+ leave: () => { over = null; retarget(); },
+ }));
+ bag.add(() => svg.replaceChildren());
+
+ return {
+ set: (v) => { R = v; if (over) retarget(); },
+ destroy: bag.dispose,
+ };
+};
diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.ts
index 9f5fd32..4585264 100644
--- a/packages/hairline/src/index.ts
+++ b/packages/hairline/src/index.ts
@@ -1,5 +1,6 @@
import { create, type Figure, type HairlineOptions } from "./mount";
import { mount as explodedEngine } from "./figures/exploded";
+import { mount as keyboardEngine } from "./figures/keyboard";
import { mount as phosphorEngine } from "./figures/phosphor";
import { mount as riffleEngine } from "./figures/riffle";
import { mount as slowEngine } from "./figures/slow";
@@ -7,7 +8,7 @@ import { mount as terrainEngine } from "./figures/terrain";
import { mount as turntableEngine } from "./figures/turntable";
/**
- * @lucasmarkes/hairline — six isometric line figures that answer the pointer.
+ * @lucasmarkes/hairline — seven isometric line figures that answer the pointer.
*
* One function per figure. Each takes an element and the same options, draws
* into the element, and returns `{ update, destroy }`. Each function names
@@ -76,3 +77,13 @@ export function turntable(el: HTMLElement, options?: HairlineOptions): Figure {
engine: turntableEngine,
}, el, options);
}
+
+/** A sixty-key board. The key under the pointer sinks, and its neighbours follow it down, less the further away. `intensity` widens how far the press reaches. */
+export function keyboard(el: HTMLElement, options?: HairlineOptions): Figure {
+ return create({
+ id: "keyboard",
+ label: "A sixty-key board. The key under the pointer sinks, and its neighbours follow it down, less the further away.",
+ rest: "rest",
+ engine: keyboardEngine,
+ }, el, options);
+}
diff --git a/packages/hairline/src/intensity.ts b/packages/hairline/src/intensity.ts
index e77389a..20be915 100644
--- a/packages/hairline/src/intensity.ts
+++ b/packages/hairline/src/intensity.ts
@@ -7,7 +7,7 @@
* copy and its tests hold the two together.
*/
-export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable";
+export type FigureId = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard";
/** Each figure's number at intensity 0, 0.5 and 1. Slow's falls: a slower clock is a stronger answer. */
export const TABLE: Record<FigureId, readonly [number, number, number]> = {
@@ -17,6 +17,7 @@ export const TABLE: Record<FigureId, readonly [number, number, number]> = {
phosphor: [150, 520, 1500], // afterglow, ms
slow: [0.6, 0.2, 0.05], // rate, × normal speed
turntable: [200, 650, 1500], // coast, ms
+ keyboard: [1, 2, 3.5], // radius, keys
};
export const DEFAULT = 0.5;
diff --git a/packages/hairline/src/react.tsx b/packages/hairline/src/react.tsx
index 1c4cc89..3f760b4 100644
--- a/packages/hairline/src/react.tsx
+++ b/packages/hairline/src/react.tsx
@@ -2,10 +2,10 @@ import {
forwardRef, useCallback, useEffect, useLayoutEffect, useRef,
type ComponentPropsWithoutRef, type ForwardRefExoticComponent, type RefAttributes,
} from "react";
-import { exploded, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";
+import { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "./index";
/**
- * @lucasmarkes/hairline/react — the six figures as components.
+ * @lucasmarkes/hairline/react — the seven figures as components.
*
* A component renders one empty `<div>` and mounts the figure on it in a
* layout effect, so on the server the box is there and the drawing is not.
@@ -65,3 +65,5 @@ export const Phosphor = make("Phosphor", phosphor);
export const Slow = make("Slow", slow);
/** Blocks on a turntable. A flick across it spins it; it settles on the nearest quarter turn. `intensity` makes the spin coast longer. */
export const Turntable = make("Turntable", turntable);
+/** A sixty-key board. The key under the pointer sinks, and its neighbours follow it down, less the further away. `intensity` widens how far the press reaches. */
+export const Keyboard = make("Keyboard", keyboard);
diff --git a/packages/hairline/test/browser/entry.ts b/packages/hairline/test/browser/entry.ts
index 02c97e4..94e1d88 100644
--- a/packages/hairline/test/browser/entry.ts
+++ b/packages/hairline/test/browser/entry.ts
@@ -4,7 +4,7 @@ import * as hairline from "../../src/index";
* The harness page's script: the package, on `window`, with one figure at a
* time on #host. Tests drive it through page.evaluate.
*/
-type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable";
+type Id = "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard";
type Loose = Record<string, unknown>;
type Mount = (el: HTMLElement, options?: Loose) => { update(o: Loose): void; destroy(): void };
diff --git a/packages/hairline/test/browser/figures.spec.ts b/packages/hairline/test/browser/figures.spec.ts
index eefe7c1..08b71fc 100644
--- a/packages/hairline/test/browser/figures.spec.ts
+++ b/packages/hairline/test/browser/figures.spec.ts
@@ -2,7 +2,7 @@ import { expect, test, type Page } from "@playwright/test";
/** The figures in a real browser: input, focus, reduced motion, shadow roots, a clean console. */
-const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable"] as const;
+const IDS = ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard"] as const;
type Id = (typeof IDS)[number];
const mount = (page: Page, id: Id, options: Record<string, unknown> = {}) =>
diff --git a/packages/hairline/test/intensity.test.ts b/packages/hairline/test/intensity.test.ts
index d299109..97f5b76 100644
--- a/packages/hairline/test/intensity.test.ts
+++ b/packages/hairline/test/intensity.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { DEFAULT, TABLE, intensity, parameter, type FigureId } from "../src/intensity";
-import { INTENSITY, OPTION } from "./parity/scripts.mjs";
+import { FIGURES, INTENSITY, OPTION } from "./parity/scripts.mjs";
const IDS = Object.keys(TABLE) as FigureId[];
@@ -47,8 +47,8 @@ describe("parameter", () => {
expect(parameter("terrain", "fast")).toBe(3);
});
- /* the parity goldens were captured with raw values; these intensities must land on them exactly */
- it.each(IDS)("lands %s on the golden's value at its parity intensity", (id) => {
+ /* the parity goldens were captured with raw values; these intensities must land on them exactly. Only the six the site drew have one */
+ it.each(FIGURES as Array<keyof typeof OPTION>)("lands %s on the golden's value at its parity intensity", (id) => {
const raw = OPTION[id][1];
expect(parameter(id, INTENSITY[id])).toBe(raw);
});
diff --git a/packages/hairline/test/mount.test.ts b/packages/hairline/test/mount.test.ts
index ea67b96..362cedb 100644
--- a/packages/hairline/test/mount.test.ts
+++ b/packages/hairline/test/mount.test.ts
@@ -1,10 +1,10 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from "vitest";
import { frames, host, observers, pending } from "./dom";
-import { exploded, phosphor, riffle, slow, terrain, turntable } from "../src/index";
+import { exploded, keyboard, phosphor, riffle, slow, terrain, turntable } from "../src/index";
import { css } from "../src/core/styles";
-const ALL = { riffle, terrain, exploded, phosphor, slow, turntable };
+const ALL = { riffle, terrain, exploded, phosphor, slow, turntable, keyboard };
const key = (el: Element, k: string) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true }));
describe("mount", () => {
@@ -142,6 +142,7 @@ describe("intensity", () => {
phosphor: [[240, 140], 2, [260, 145], 2, [280, 150], 15],
slow: [[200, 160], 60],
turntable: [[50, 176], 1, [120, 176], 1, [200, 176], 1, [280, 176], 1, [350, 176], 40],
+ keyboard: [[200, 160], 20],
};
const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d+/g, "hl-fd");
diff --git a/packages/hairline/test/react.test.tsx b/packages/hairline/test/react.test.tsx
index 32b75d1..6de6917 100644
--- a/packages/hairline/test/react.test.tsx
+++ b/packages/hairline/test/react.test.tsx
@@ -3,7 +3,7 @@ import { StrictMode, createRef } from "react";
import { cleanup, render } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { frames, observers, pending } from "./dom";
-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";
+import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable } from "../src/react";
afterEach(cleanup);
@@ -17,9 +17,9 @@ const svg = (el: Element) => el.querySelector("svg")!.innerHTML.replace(/hl-fd\d
describe("components", () => {
it("renders each figure into one div", () => {
- const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /></>);
+ const { container } = render(<><Riffle /><Terrain /><Exploded /><Phosphor /><Slow /><Turntable /><Keyboard /></>);
const ids = [...container.children].map((el) => el.getAttribute("data-hairline"));
- expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable"]);
+ expect(ids).toEqual(["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard"]);
for (const el of container.children) expect(el.querySelectorAll(":scope > svg")).toHaveLength(1);
});
@@ -118,7 +118,7 @@ describe("components", () => {
});
it("names the components for the dev tools", () => {
- expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable].map((c) => c.displayName))
- .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable"]);
+ expect([Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard].map((c) => c.displayName))
+ .toEqual(["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard"]);
});
});
diff --git a/packages/hairline/test/types.test-d.tsx b/packages/hairline/test/types.test-d.tsx
index 1108c89..6a74241 100644
--- a/packages/hairline/test/types.test-d.tsx
+++ b/packages/hairline/test/types.test-d.tsx
@@ -4,10 +4,10 @@
* an error. Vitest does not pick it up (it is not a `.test.` file).
*/
import { createRef } from "react";
-import { exploded, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";
+import { exploded, keyboard, phosphor, riffle, slow, terrain, turntable, type Figure, type HairlineOptions } from "../src/index";
import * as vanilla from "../src/index";
import * as components from "../src/react";
-import { Exploded, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";
+import { Exploded, Keyboard, Phosphor, Riffle, Slow, Terrain, Turntable, type HairlineProps } from "../src/react";
declare const el: HTMLElement;
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
@@ -16,7 +16,7 @@ const yes = <T extends true>() => {};
/* every figure takes the same options */
riffle(el, { intensity: 0.8, theme: "dark", label: "Cards", onRead: (t: string) => t });
riffle(el);
-for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable]) {
+for (const mount of [riffle, terrain, exploded, phosphor, slow, turntable, keyboard]) {
yes<Equal<typeof mount, (el: HTMLElement, options?: HairlineOptions) => Figure>>();
// @ts-expect-error the old per-figure options are gone
mount(el, { stagger: 60 });
@@ -46,8 +46,8 @@ f.update({ stagger: 60 });
f.update({ bands: true });
/* the entries export the functions, the components and three types, and nothing of the old API */
-yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable">>();
-yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable">>();
+yes<Equal<keyof typeof vanilla, "riffle" | "terrain" | "exploded" | "phosphor" | "slow" | "turntable" | "keyboard">>();
+yes<Equal<keyof typeof components, "Riffle" | "Terrain" | "Exploded" | "Phosphor" | "Slow" | "Turntable" | "Keyboard">>();
// @ts-expect-error ranges is gone
void vanilla.ranges;
// @ts-expect-error the per-figure option types are gone
@@ -60,7 +60,7 @@ const ref = createRef<HTMLDivElement>();
<Riffle ref={ref} intensity={0.8} theme="dark" className="w-80" id="cards" onClick={() => {}} onRead={(text) => text.length} />;
<Terrain style={{ width: 320 }} aria-label="Dunes" data-x="1" />;
<Riffle />;
-for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable]) {
+for (const C of [Riffle, Terrain, Exploded, Phosphor, Slow, Turntable, Keyboard]) {
// @ts-expect-error the old per-figure options are gone
<C stagger={60} />;
// @ts-expect-error the old per-figure options are gone
diff --git a/registry/src/hairline.tsx b/registry/src/hairline.tsx
index 2f96204..c7bf01c 100644
--- a/registry/src/hairline.tsx
+++ b/registry/src/hairline.tsx
@@ -41,3 +41,7 @@ export function Slow({ style, ...props }: ComponentProps<typeof Hairline.Slow>)
export function Turntable({ style, ...props }: ComponentProps<typeof Hairline.Turntable>) {
return <Hairline.Turntable style={{ ...tokens, ...style }} {...props} />;
}
+
+export function Keyboard({ style, ...props }: ComponentProps<typeof Hairline.Keyboard>) {
+ return <Hairline.Keyboard style={{ ...tokens, ...style }} {...props} />;
+}
diff --git a/registry/validate.mjs b/registry/validate.mjs
index 6693b94..a0387ff 100644
--- a/registry/validate.mjs
+++ b/registry/validate.mjs
@@ -29,7 +29,7 @@ const [source] = item.files ?? [];
if (item.dependencies?.join() !== "@lucasmarkes/hairline") problems.push("dependencies must be exactly @lucasmarkes/hairline");
if (source?.path !== "components/ui/hairline.tsx") problems.push("the file must be components/ui/hairline.tsx");
if (!source?.content?.startsWith('"use client";')) problems.push('the file must start with "use client"');
-for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable"]) {
+for (const name of ["Riffle", "Terrain", "Exploded", "Phosphor", "Slow", "Turntable", "Keyboard"]) {
if (!source?.content?.includes(`export function ${name}(`)) problems.push(`the file does not export ${name}`);
}
if (/localhost/.test(JSON.stringify(item)) && process.env.VERCEL) problems.push("the item points at localhost in a deployed build");
diff --git a/scripts/consumers.mjs b/scripts/consumers.mjs
index 3bcde1e..121208b 100644
--- a/scripts/consumers.mjs
+++ b/scripts/consumers.mjs
@@ -22,7 +22,7 @@ const { chromium } = createRequire(join(PKG, "package.json"))("@playwright/test"
const FIXTURES = {
next: { dir: "fixtures/next-app", port: 4311, serve: (port) => ["npx", ["next", "start", "-p", String(port)]], figures: ["riffle", "slow", "phosphor"] },
- vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable"] },
+ vite: { dir: "fixtures/vite-vanilla", port: 4312, serve: (port) => ["npx", ["vite", "preview", "--port", String(port), "--strictPort"]], figures: ["riffle", "terrain", "exploded", "phosphor", "slow", "turntable", "keyboard"] },
};
const only = process.argv[2];
if (only && !FIXTURES[only]) { console.error(`Unknown fixture "${only}". Use: ${Object.keys(FIXTURES).join(" | ")}`); process.exit(2); }