Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill: the bench takes ?intensity= and ?theme= in the address, so a browser without a mouse can show either end of the slider and either theme
Lucas Marquesd541dd9a0bd3
diff --git a/packages/hairline/test/browser/skill.spec.ts b/packages/hairline/test/browser/skill.spec.tsindex 17e6d29..7ff83f6 100644--- a/packages/hairline/test/browser/skill.spec.ts+++ b/packages/hairline/test/browser/skill.spec.ts@@ -130,6 +130,49 @@ test("the theme switch changes the palette, and wins over the system's theme botawait expect(page.locator("body")).toHaveCSS("background-color", "rgb(255, 255, 255)");});+test("?theme= in the address wins over the system's theme, as the switch does, and any other value is ignored", async ({ page }) => {+ const ground = page.locator("body");+ await page.emulateMedia({ colorScheme: "dark" });+ await page.goto("/bench/terrain?theme=light");+ await expect(ground).toHaveCSS("background-color", "rgb(255, 255, 255)");+ await expect(page.locator("#theme")).toHaveText("light");++ await page.emulateMedia({ colorScheme: "light" });+ await page.goto("/bench/terrain?theme=dark");+ await expect(ground).toHaveCSS("background-color", "rgb(8, 9, 10)");+ await expect(page.locator("#theme")).toHaveText("dark");++ await page.emulateMedia({ colorScheme: "dark" });+ await page.goto("/bench/terrain?theme=blue");+ await expect(ground).toHaveCSS("background-color", "rgb(8, 9, 10)");+ await expect(page.locator("#theme")).toHaveText("dark");+});++for (const [id, ex] of Object.entries(EXAMPLES)) {+ test(`${id}: ?intensity= in the address sets the slider before the figure mounts`, async ({ context, page }) => {+ await context.addInitScript(clock);+ /* the page at an address, answering the pointer: the slider's value, what it shows, and the drawing */+ const load = async (query: string) => {+ await page.goto(`/bench/${id}${query}`);+ await page.locator("#stage svg > *").first().waitFor();+ await settle(page);+ const [cp] = await play(page, {+ stage: page.locator("#stage"),+ snap: async () => ({ svg: await svg(page), read: await read(page) }),+ set: async () => {},+ }, [{ move: ex.at }, { adv: 12 }, { cp: "answering" }]) as Checkpoint[];+ return { svg: cp.svg, value: await page.locator("#value").innerText(), slider: await page.locator("#intensity").inputValue() };+ };+ const plain = await load(""), low = await load("?intensity=0"), high = await load("?intensity=1");+ expect([low.value, high.value]).toEqual(ex.ends);+ expect([low.slider, high.slider]).toEqual(["0", "1"]);+ expect(low.svg).not.toBe(plain.svg);+ expect(high.svg).not.toBe(plain.svg);+ expect(await load("?intensity=abc")).toEqual(plain);+ expect(plain.slider).toBe("0.5");+ });+}+test("the page fits a 240px screen without scrolling sideways", async ({ page }) => {await page.setViewportSize({ width: 240, height: 700 });await page.goto("/bench/terrain");diff --git a/skills/hairline-create/bench.html b/skills/hairline-create/bench.htmlindex 29a6192..ee3ed9a 100644--- a/skills/hairline-create/bench.html+++ b/skills/hairline-create/bench.html@@ -82,8 +82,14 @@const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches);const label = () => { $("theme").textContent = dark() ? "dark" : "light"; };$("theme").addEventListener("click", () => { root.dataset.theme = dark() ? "light" : "dark"; label(); });+ /* ?theme=light or ?theme=dark wins over the system's, as pressing the switch does */+ if (["light", "dark"].includes(params.get("theme"))) root.dataset.theme = params.get("theme");label();+ /* ?intensity=0 sets the slider before the figure mounts, for a look at either end */+ const i = (params.get("intensity") || "").trim();+ if (i && Number.isFinite(Number(i))) $("intensity").value = String(Math.min(1, Math.max(0, Number(i))));+/* ?w=240 narrows the page, for a look at the size of a thumbnail */const w = Number(params.get("w"));if (w > 0) document.querySelector("main").style.maxWidth = w + "px";@@ -123,7 +129,7 @@const show = () => { $("value").textContent = String(at(Number(slider.value))); };show();- const handle = figure.mount({ stage, svg, read }, at(0.5));+ const handle = figure.mount({ stage, svg, read }, at(Number(slider.value)));if (text === null) read.textContent = "rest";slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });window.hairline.figure = handle;