Isometric line figures that answer the pointer. For React and for anything with a DOM.
Package: a figure that throws under the tour no longer stops every other figure
Lucas Marqueseb57532745fa
diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.tsindex 8c0d642..a57db3e 100644--- a/apps/site/lib/skill.ts+++ b/apps/site/lib/skill.ts@@ -19,13 +19,13 @@ export type Example = { idea: string; file: string; sha256: string; followUp?: s/** What was typed after the command, and the page the skill wrote for it. The pages are never edited. */export const EXAMPLES: Example[] = [- { idea: "a sales funnel", file: "hairline-funnel.html", sha256: "37c9cab4dff1434b75cd4ebad0e91a1861f381a5c4e88200754b6d988989bc54" },- { idea: "a rate limiter", file: "hairline-clearance.html", sha256: "566d0c61c49080f64984bc6321f1c6f70d4a67085104f99a9cc2ab4146a38605" },- { idea: "git branches", file: "hairline-sidings.html", sha256: "58f8e7136f25fd10f7ca1b1f775d6d76e7b7f7dccd34b7efebb9b672707c284a", followUp: "The rails almost disappear and the trains read as loose blocks. Make it read as a railway at a glance." },- { idea: "weather over a city", file: "hairline-storm.html", sha256: "3ce151e6eb753320379a60688db92d13d8b312cf729998721366761c9757b660", followUp: "The cloud looks like a stack of cylinders. Make it read as a cloud at a glance." },- { idea: "an empty state for \"No deployments yet\", from Vercel's mark: the triangle as an upright slab hovering over a pad with its slot marked dim; the nearer the pointer, the lower it settles, until it seats. Name it vercel.", file: "hairline-vercel.html", sha256: "713dd36620c7361c8ec545d258b9a06f0608220ee8fb56ea87cac7e0ee0b8e40" },- { idea: "an empty state for \"No agents connected\", from Mastra's mark: the spheres of the M joined by necks on a board, the lone sphere standing apart; the pointer draws it toward the others, a neck forms, stretches and lets go. Name it mastra.", file: "hairline-mastra.html", sha256: "85c6cfe0981cb40ea39d410803f116d98e6765f3776e1fd3f911b124328aceb4" },- { idea: "an empty state for \"No pages inside\", from Notion's mark: the cube as a box with a lid, the N a relief on its front face; the pointer's height opens the lid on a spring, and the box is empty. Name it notion.", file: "hairline-notion.html", sha256: "3e7f77870cc8041773e21c02266a2939c35b70f7afad091c4b628102a4d1f928" },+ { idea: "a sales funnel", file: "hairline-funnel.html", sha256: "1c2ad4fb6305da1ceda532da6d96f1cd3060c67d588dec2db6043920e33fc044" },+ { idea: "a rate limiter", file: "hairline-clearance.html", sha256: "36935c2412526af4331070e5a2d350f6c0a8071156b59955e815175b7a88b34d" },+ { idea: "git branches", file: "hairline-sidings.html", sha256: "c6844a3c0dc684237508644ef677ae8905b120b73c2af74d7abf5990775106ae", followUp: "The rails almost disappear and the trains read as loose blocks. Make it read as a railway at a glance." },+ { idea: "weather over a city", file: "hairline-storm.html", sha256: "fe23e7a760c742bf0c68401bb2d3544f700af36865f720b39214ebde237507c0", followUp: "The cloud looks like a stack of cylinders. Make it read as a cloud at a glance." },+ { idea: "an empty state for \"No deployments yet\", from Vercel's mark: the triangle as an upright slab hovering over a pad with its slot marked dim; the nearer the pointer, the lower it settles, until it seats. Name it vercel.", file: "hairline-vercel.html", sha256: "781db9ab5891183261c3ed03e1050d9fabbc9b95a2a9333425706135953dc839" },+ { idea: "an empty state for \"No agents connected\", from Mastra's mark: the spheres of the M joined by necks on a board, the lone sphere standing apart; the pointer draws it toward the others, a neck forms, stretches and lets go. Name it mastra.", file: "hairline-mastra.html", sha256: "fa4f03c971f626296cd3a720aed23b81beeda0221652b1c560820a9c3858876a" },+ { idea: "an empty state for \"No pages inside\", from Notion's mark: the cube as a box with a lid, the N a relief on its front face; the pointer's height opens the lid on a spring, and the box is empty. Name it notion.", file: "hairline-notion.html", sha256: "4ba5f67ee4a4c7d0a0a46757889c8264af3c6a21d285e81e6aa02e65e23f68d7" },];export type Shown = Example & { name: string; means: string; prompt: string; href: string };diff --git a/apps/site/public/skill/hairline-clearance.html b/apps/site/public/skill/hairline-clearance.htmlindex d2077c8..f95c8f6 100644--- a/apps/site/public/skill/hairline-clearance.html+++ b/apps/site/public/skill/hairline-clearance.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-funnel.html b/apps/site/public/skill/hairline-funnel.htmlindex 1117372..3fc8c9f 100644--- a/apps/site/public/skill/hairline-funnel.html+++ b/apps/site/public/skill/hairline-funnel.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-mastra.html b/apps/site/public/skill/hairline-mastra.htmlindex e15715e..51c1498 100644--- a/apps/site/public/skill/hairline-mastra.html+++ b/apps/site/public/skill/hairline-mastra.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-notion.html b/apps/site/public/skill/hairline-notion.htmlindex 4dcabf1..70b2363 100644--- a/apps/site/public/skill/hairline-notion.html+++ b/apps/site/public/skill/hairline-notion.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-sidings.html b/apps/site/public/skill/hairline-sidings.htmlindex 3dcdaf9..61b9350 100644--- a/apps/site/public/skill/hairline-sidings.html+++ b/apps/site/public/skill/hairline-sidings.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-storm.html b/apps/site/public/skill/hairline-storm.htmlindex 0a73c04..771b2fd 100644--- a/apps/site/public/skill/hairline-storm.html+++ b/apps/site/public/skill/hairline-storm.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/apps/site/public/skill/hairline-vercel.html b/apps/site/public/skill/hairline-vercel.htmlindex 986c4bd..f20be4c 100644--- a/apps/site/public/skill/hairline-vercel.html+++ b/apps/site/public/skill/hairline-vercel.html@@ -70,7 +70,7 @@<p id="error" role="alert" hidden></p></main><script id="hl-kernel">-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -472,7 +472,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;diff --git a/packages/hairline/package.json b/packages/hairline/package.jsonindex 54cb2ed..4bacdf1 100644--- a/packages/hairline/package.json+++ b/packages/hairline/package.json@@ -83,18 +83,18 @@{"name": "vanilla, every figure","path": "dist/index.js",- "limit": "35.1 kB"+ "limit": "35.3 kB"},{"name": "vanilla, one figure","path": "dist/index.js","import": "{ terrain }",- "limit": "6.3 kB"+ "limit": "6.4 kB"},{"name": "react, every component","path": "dist/react.js",- "limit": "35.5 kB",+ "limit": "35.7 kB","ignore": ["react","react/jsx-runtime"diff --git a/packages/hairline/src/core/stage.ts b/packages/hairline/src/core/stage.tsindex 63d9bf2..a61bc31 100644--- a/packages/hairline/src/core/stage.ts+++ b/packages/hairline/src/core/stage.ts@@ -100,7 +100,11 @@ function frame(now: number) {const dt = Math.min(0.05, Math.max(0, (now - last) / 1000));last = now;let any = false;- for (const b of boards.slice()) if (b.vis && b.awake) { b.awake = !!b.tick(dt, now); any = any || b.awake; }+ for (const b of boards.slice()) if (b.vis && b.awake) {+ /* a tick that throws, or a handler the tour calls from one, sleeps alone: the error is reported as uncaught and every other board keeps its frames */+ try { b.awake = !!b.tick(dt, now); } catch (err) { b.awake = false; setTimeout(() => { throw err; }); }+ any = any || b.awake;+ }raf = any ? requestAnimationFrame(frame) : 0;}diff --git a/packages/hairline/test/stage.test.ts b/packages/hairline/test/stage.test.tsindex a765962..b9c40f3 100644--- a/packages/hairline/test/stage.test.ts+++ b/packages/hairline/test/stage.test.ts@@ -42,6 +42,24 @@ describe("register", () => {expect(o.targets.has(el)).toBe(false);keep.unregister();});++ it("a tick that throws sleeps alone: the error is reported, and every other board keeps its frames", () => {+ const thrown: Array<() => void> = [];+ vi.spyOn(globalThis, "setTimeout").mockImplementation(((fn: () => void) => { thrown.push(fn); return 0; }) as typeof setTimeout);+ const el = host(), other = host();+ const boom = new Error("boom");+ let n = 0;+ const bad = register(el, () => { if (n++ > 0) throw boom; return true; });+ const good = vi.fn(() => true), ok = register(other, good);+ expect(() => frames(5)).not.toThrow();+ expect(n).toBe(2);+ expect(good.mock.calls.length).toBeGreaterThanOrEqual(6);+ expect(pending()).toBe(1);+ expect(thrown).toHaveLength(1);+ expect(thrown[0]).toThrow(boom);+ bad.unregister();+ ok.unregister();+ });});type Call = { kind: "move" | "leave"; type: string; p?: Vec2 };@@ -216,6 +234,33 @@ describe("tour", () => {h.stop();});+ it("a move that throws under the ghost stops that tour alone: the error is reported, and the other figures keep their frames", () => {+ const thrown: Array<() => void> = [];+ vi.spyOn(globalThis, "setTimeout").mockImplementation(((fn: () => void) => { thrown.push(fn); return 0; }) as typeof setTimeout);+ const el = host(), other = host();+ const boom = new Error("boom");+ let moves = 0;+ pointer(el, { move: () => { moves++; throw boom; }, leave: () => {} });+ const h = tour(el, [[200, 100], null]);+ const good = vi.fn(() => true), ok = register(other, good);+ expect(() => until(() => moves > 0, 200)).not.toThrow();+ expect(moves).toBe(1);+ expect(thrown).toHaveLength(1);+ expect(thrown[0]).toThrow(boom);+ const n = good.mock.calls.length;+ frames(10);+ expect(good.mock.calls.length).toBe(n + 10);+ expect(pending()).toBe(1);+ /* a board registered afterwards is ticked by the loop too, not only at register */+ const late = vi.fn(() => true), l = register(host(), late);+ frames(3);+ expect(late.mock.calls.length).toBe(4);+ expect(moves).toBe(1);+ l.unregister();+ ok.unregister();+ h.stop();+ });+it("the disposer forgets the handlers, and a new pointer() takes over", () => {const el = host(), a = stub(el);const h = tour(el, [[200, 100], null]);diff --git a/skills/hairline-create/kernel.js b/skills/hairline-create/kernel.jsindex ad471d8..dfc8da3 100644--- a/skills/hairline-create/kernel.js+++ b/skills/hairline-create/kernel.js@@ -1,4 +1,4 @@-/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */+/* hairline kernel sha256:3a19aa2640ba8c6c306184d05fddfbd4f3323a6ebd9217dd3cbb38e9db74991c *//** HL: everything a figure may call. Read this index; the code under it is the* package's src/core, unchanged, and a figure should not need to read it.@@ -400,7 +400,14 @@ var HL = (() => {last = now;let any = false;for (const b of boards.slice()) if (b.vis && b.awake) {- b.awake = !!b.tick(dt, now);+ try {+ b.awake = !!b.tick(dt, now);+ } catch (err) {+ b.awake = false;+ setTimeout(() => {+ throw err;+ });+ }any = any || b.awake;}raf = any ? requestAnimationFrame(frame) : 0;