Skip to content

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

Skill: the kernel carries tour() and LAP, the bench a play button and ?play=1, and every made page declares its tour

Lucas Marques350a2952b2ee
diff --git a/apps/site/lib/skill.ts b/apps/site/lib/skill.ts
index 38cd19b..219aa4b 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: "0cc23d6ae3e40a7d424e56b25f5c318760e8ae5abe82a0cafb7631c86391d982" },
- { idea: "a rate limiter", file: "hairline-clearance.html", sha256: "bcad4048389d9049880263ad113900cc6728f6bc5770880c7524a8836728bdce" },
- { idea: "git branches", file: "hairline-sidings.html", sha256: "de5ad4411e1b7a97049c6b74e9f4ffdb8a9dfc32b0c5367dddd585cd7dac5bf7", 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: "af8e3e85414d2a38421cf98b858ce1a4c1f9138cc5ba7bbf6c5b42b0205c0e60", 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: "66f4577ec763f5ea45983cdff12ec5fdd6a6d1be7ff427023a8d35271af43d94" },
- { 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: "6a7c5d3f4942428b4ce6ce02c6667eb80503ea58bd501891e3b5f9f7eeb02f5a" },
- { 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: "0027a7ea3a463638d60e7d0cc3cd94402862d68895a4c9b5e036a1a3c2163583" },
+ { 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" },
];
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.html
index e10c9e6..d2077c8 100644
--- a/apps/site/public/skill/hairline-clearance.html
+++ b/apps/site/public/skill/hairline-clearance.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -827,6 +977,7 @@ hairline({
means: "Each second is a column of requests: a burst lifts the ones near the pointer, and none of them gets past the bar.",
rules: [1, 3, 5, 9],
range: [1.5, 3, 5],
+ tour: [[140, 140], [220, 180], [280, 220], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-funnel.html b/apps/site/public/skill/hairline-funnel.html
index dc6fbe3..1117372 100644
--- a/apps/site/public/skill/hairline-funnel.html
+++ b/apps/site/public/skill/hairline-funnel.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -842,6 +992,7 @@ hairline({
means: "Four trays step down, each narrower with fewer beads: the stage under the pointer lifts, its neighbours rising less in turn.",
rules: [1, 2, 5, 10],
range: [0, 45, 90],
+ tour: [[100, 100], [200, 160], [300, 230], [320, 270], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-mastra.html b/apps/site/public/skill/hairline-mastra.html
index 3cdaef0..e15715e 100644
--- a/apps/site/public/skill/hairline-mastra.html
+++ b/apps/site/public/skill/hairline-mastra.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -902,6 +1052,7 @@ hairline({
means: "No agents connected: the pointer draws the lone sphere to the M, a neck forms, stretches, and lets go.",
rules: [3, 4, 5, 8],
range: [4, 9, 14],
+ tour: [[80, 160], [240, 160], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-notion.html b/apps/site/public/skill/hairline-notion.html
index 17bbdfa..4dcabf1 100644
--- a/apps/site/public/skill/hairline-notion.html
+++ b/apps/site/public/skill/hairline-notion.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -849,6 +999,7 @@ hairline({
means: "Notion's cube as a box: the pointer's height lifts the lid on a spring, and inside there are no pages.",
rules: [1, 5, 6, 9],
range: [75, 100, 125],
+ tour: [[200, 40], [200, 120], [200, 160], [200, 200], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-sidings.html b/apps/site/public/skill/hairline-sidings.html
index 5c5a847..3dcdaf9 100644
--- a/apps/site/public/skill/hairline-sidings.html
+++ b/apps/site/public/skill/hairline-sidings.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -892,6 +1042,7 @@ hairline({
means: "A trunk line and three sidings: the track under the pointer is checked out, its wagons rising in turn to a bright head.",
rules: [1, 2, 5, 10],
range: [10, 16, 22],
+ tour: [[200, 120], [220, 180], [200, 200], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-storm.html b/apps/site/public/skill/hairline-storm.html
index 4366591..0a73c04 100644
--- a/apps/site/public/skill/hairline-storm.html
+++ b/apps/site/public/skill/hairline-storm.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -899,6 +1049,7 @@ hairline({
means: "A cloud you steer over a district rains on the roofs under it; only the rain from its middle reaches them.",
rules: [1, 3, 5, 6],
range: [14, 19, 24],
+ tour: [[80, 80], [200, 120], [160, 160], [320, 80], null],
mount,
});
</script>
diff --git a/apps/site/public/skill/hairline-vercel.html b/apps/site/public/skill/hairline-vercel.html
index f308582..986c4bd 100644
--- a/apps/site/public/skill/hairline-vercel.html
+++ b/apps/site/public/skill/hairline-vercel.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,13 +62,15 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
<p id="error" role="alert" hidden></p>
</main>
<script id="hl-kernel">
-/* hairline kernel sha256:8e2abcbdf63c7755195ee942c39e9c8ea6a539d1147e986dd1c153559121f075 */
+/* hairline kernel sha256:a0e1deb5b5f20bfb1424b477e60b2f8e9d8e10cf480bf64c028b4da0142e34cb */
/*
* 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.
@@ -138,6 +141,8 @@
* The bench's business, not a figure's
* css(lightDark)
* inject(root)
+ * tour(stage, stops, onStop) an unseen pointer that walks the stops, [x, y] in viewBox units or null to leave, and gives way to a real one; onStop(i) on each arrival; returns {stop}
+ * LAP the default stops: a diamond around the centre, then a leave
*
* Classes, on path, polygon, ellipse and line. They are the whole palette; a
* figure sets no colour, width or fill of its own.
@@ -171,6 +176,7 @@ var HL = (() => {
__export(kernel_exports, {
Cam: () => Cam,
EASE_LIFT: () => EASE_LIFT,
+ LAP: () => LAP,
bezier: () => bezier,
circ: () => circ,
clamp: () => clamp,
@@ -209,6 +215,7 @@ var HL = (() => {
spring: () => spring,
stepS: () => stepS,
tdone: () => tdone,
+ tour: () => tour,
tset: () => tset,
tval: () => tval,
tween: () => tween,
@@ -485,10 +492,12 @@ var HL = (() => {
if (io) return;
io = new IntersectionObserver((es) => {
for (const e of es) {
- const b = byStage.get(e.target);
- if (!b) continue;
- b.vis = e.isIntersecting;
- if (b.vis) wake(b);
+ const set = byStage.get(e.target);
+ if (!set) continue;
+ for (const b of set) {
+ b.vis = e.isIntersecting;
+ if (b.vis) wake(b);
+ }
}
}, { rootMargin: "80px" });
rm = matchMedia("(prefers-reduced-motion: reduce)");
@@ -507,8 +516,15 @@ var HL = (() => {
start();
const b = { stage, tick, vis: false, awake: true };
boards.push(b);
- byStage.set(stage, b);
- io.observe(stage);
+ const peers = byStage.get(stage);
+ if (peers) {
+ for (const p of peers) b.vis = p.vis;
+ peers.add(b);
+ if (b.vis) wake(b);
+ } else {
+ byStage.set(stage, /* @__PURE__ */ new Set([b]));
+ io.observe(stage);
+ }
tick(0, performance.now());
let gone = false;
return {
@@ -519,15 +535,22 @@ var HL = (() => {
if (gone) return;
gone = true;
boards = boards.filter((x) => x !== b);
- if (byStage.get(stage) === b) {
- byStage.delete(stage);
- io?.unobserve(stage);
+ const set = byStage.get(stage);
+ if (set) {
+ set.delete(b);
+ if (!set.size) {
+ byStage.delete(stage);
+ io?.unobserve(stage);
+ }
}
if (!boards.length) stop();
}
};
}
+ var handlers = /* @__PURE__ */ new WeakMap();
+ var touring = /* @__PURE__ */ new WeakMap();
function pointer(stage, on) {
+ handlers.set(stage, on);
let tm = 0;
const pt = (e) => {
const r = stage.getBoundingClientRect();
@@ -535,28 +558,144 @@ var HL = (() => {
};
const move = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
on.move(pt(e), e);
};
const down = (e) => {
clearTimeout(tm);
+ touring.get(stage)?.hold();
if (e.pointerType !== "mouse") stage.releasePointerCapture?.(e.pointerId);
if (on.down) on.down(pt(e), e);
else on.move(pt(e), e);
};
const leave = (e) => {
clearTimeout(tm);
- tm = window.setTimeout(() => on.leave(e), e.pointerType === "mouse" ? 0 : 1400);
+ tm = window.setTimeout(() => {
+ on.leave(e);
+ touring.get(stage)?.release();
+ }, e.pointerType === "mouse" ? 0 : 1400);
};
stage.addEventListener("pointermove", move);
stage.addEventListener("pointerdown", down);
stage.addEventListener("pointerleave", leave);
return () => {
clearTimeout(tm);
+ if (handlers.get(stage) === on) handlers.delete(stage);
stage.removeEventListener("pointermove", move);
stage.removeEventListener("pointerdown", down);
stage.removeEventListener("pointerleave", leave);
};
}
+ var LAP = [[128, 150], [200, 118], [272, 150], [200, 206], null];
+ var TRAVEL = 900;
+ var DWELL = 1200;
+ var REST = 1800;
+ var RESUME = 1200;
+ var STAGGER = 450;
+ var GHOST = { pointerType: "ghost" };
+ var started = 0;
+ function entry([x, y]) {
+ const dx = x - 200, dy = y - 160;
+ if (!dx && !dy) return [200, 320];
+ const k = Math.min(dx ? (dx > 0 ? 200 : -200) / dx : Infinity, dy ? (dy > 0 ? 160 : -160) / dy : Infinity);
+ return [200 + dx * k, 160 + dy * k];
+ }
+ function tour(stage, stops, onStop) {
+ let i = 0;
+ let wait = RESUME + STAGGER * (started++ % 4);
+ let t = -1;
+ let at = null;
+ let origin = [200, 320];
+ let hand = false, keys = stage.contains(stage.ownerDocument.activeElement);
+ let gone = false;
+ const leave = () => {
+ at = null;
+ t = -1;
+ handlers.get(stage)?.leave(GHOST);
+ };
+ const tick = (dt) => {
+ if (hand || keys || !stops.length) return false;
+ if (reducedMotion()) {
+ if (at) leave();
+ return false;
+ }
+ if (wait > 0) {
+ wait -= dt * 1e3;
+ return true;
+ }
+ const stop2 = stops[i];
+ if (stop2 === null) {
+ if (at) leave();
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ wait = REST;
+ return true;
+ }
+ const h = handlers.get(stage);
+ if (!h) return true;
+ if (t < 0) {
+ origin = at ?? entry(stop2);
+ t = 0;
+ }
+ t = Math.min(TRAVEL, t + dt * 1e3);
+ const k = EASE_LIFT(t / TRAVEL);
+ at = [origin[0] + (stop2[0] - origin[0]) * k, origin[1] + (stop2[1] - origin[1]) * k];
+ h.move(at, GHOST);
+ if (t < TRAVEL) return true;
+ onStop?.(i);
+ i = (i + 1) % stops.length;
+ t = -1;
+ wait = DWELL;
+ return true;
+ };
+ const take = () => {
+ at = null;
+ t = -1;
+ };
+ const give = () => {
+ if (hand || keys) return;
+ i = 0;
+ t = -1;
+ wait = RESUME;
+ board.wake();
+ };
+ const me = {
+ hold: () => {
+ hand = true;
+ take();
+ },
+ release: () => {
+ if (!hand) return;
+ hand = false;
+ give();
+ }
+ };
+ const focusIn = () => {
+ keys = true;
+ take();
+ };
+ const focusOut = (e) => {
+ if (keys && !stage.contains(e.relatedTarget)) {
+ keys = false;
+ give();
+ }
+ };
+ stage.addEventListener("focusin", focusIn);
+ stage.addEventListener("focusout", focusOut);
+ touring.set(stage, me);
+ const board = register(stage, tick);
+ return {
+ stop: () => {
+ if (gone) return;
+ gone = true;
+ board.unregister();
+ stage.removeEventListener("focusin", focusIn);
+ stage.removeEventListener("focusout", focusOut);
+ if (touring.get(stage) === me) touring.delete(stage);
+ if (at) leave();
+ }
+ };
+ }
function disposer() {
let fns = [];
return {
@@ -705,6 +844,17 @@ var HL = (() => {
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
@@ -841,6 +991,7 @@ hairline({
means: "No deployments yet: the triangle hovers over its empty slot, and the nearer the pointer, the lower it settles, until it seats.",
rules: [1, 3, 5, 9],
range: [70, 110, 160],
+ tour: [[80, 120], [160, 120], [200, 120], [200, 160], null],
mount,
});
</script>
diff --git a/packages/hairline/test/browser/skill.spec.ts b/packages/hairline/test/browser/skill.spec.ts
index 7ff83f6..16655f2 100644
--- a/packages/hairline/test/browser/skill.spec.ts
+++ b/packages/hairline/test/browser/skill.spec.ts
@@ -206,3 +206,47 @@ test("the built file draws when opened from disk, narrowed and with the pointer
await expect(page).toHaveTitle("Hairline · terrain");
expect(problems).toEqual([]);
});
+
+test("the play button walks the tour and stops back at rest", async ({ page }) => {
+ await page.goto("/bench/terrain");
+ const play = page.locator("#play");
+ await expect(play).toHaveAttribute("aria-pressed", "false");
+ await play.click();
+ await expect(play).toHaveAttribute("aria-pressed", "true");
+ await expect.poll(() => read(page), { timeout: 15000 }).not.toBe("rest");
+ await play.click();
+ await expect(play).toHaveAttribute("aria-pressed", "false");
+ await expect.poll(() => read(page), { timeout: 5000 }).toBe("rest");
+});
+
+test("?play=1 starts it, and each stop is reported in order", async ({ page }) => {
+ await page.addInitScript(() => {
+ (window as any).__stops = [];
+ let call: any;
+ Object.defineProperty(window, "hairline", {
+ configurable: true,
+ get: () => call,
+ set: (v) => { call = v; v.onStop = (i: number) => (window as any).__stops.push(i); },
+ });
+ });
+ await page.goto("/bench/terrain?play=1");
+ await expect(page.locator("#play")).toHaveAttribute("aria-pressed", "true");
+ await expect.poll(() => page.evaluate(() => (window as any).__stops.slice(0, 4)), { timeout: 20000 }).toEqual([0, 1, 2, 3]);
+});
+
+test("?at= holds the pointer over ?play=1", async ({ page }) => {
+ await page.addInitScript(() => {
+ (window as any).__stops = [];
+ let call: any;
+ Object.defineProperty(window, "hairline", {
+ configurable: true,
+ get: () => call,
+ set: (v) => { call = v; v.onStop = (i: number) => (window as any).__stops.push(i); },
+ });
+ });
+ await page.goto("/bench/terrain?play=1&at=200,160");
+ await expect.poll(() => read(page)).toMatch(/^cell/);
+ await page.waitForTimeout(3000);
+ expect(await page.evaluate(() => (window as any).__stops)).toEqual([]);
+ expect(await read(page)).toMatch(/^cell/);
+});
diff --git a/skills/hairline-create/bench.html b/skills/hairline-create/bench.html
index ee3ed9a..d650374 100644
--- a/skills/hairline-create/bench.html
+++ b/skills/hairline-create/bench.html
@@ -43,6 +43,7 @@
height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; color: var(--ink); cursor: pointer;
}
+ #play[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
#means { margin: 14px 0 0; text-wrap: pretty; }
#rules { margin: 6px 0 0; line-height: 1.6; }
#error { margin: 12px 0 0; padding-left: 10px; border-left: 1px solid var(--ink); }
@@ -61,6 +62,8 @@
<output id="value" for="intensity"></output>
<span class="label">theme</span>
<button id="theme" type="button" aria-label="Switch between the light and the dark theme"></button>
+ <span class="label">play</span>
+ <button id="play" type="button" aria-pressed="false">play</button>
</div>
<p id="means"></p>
<p id="rules" class="label"></p>
@@ -134,6 +137,17 @@
slider.addEventListener("input", () => { show(); handle.set(at(Number(slider.value))); });
window.hairline.figure = handle;
+ /* play: an unseen pointer walks the figure's tour (or HL.LAP) until a hand arrives; ?play=1 starts it on load */
+ const play = $("play");
+ window.hairline.playing = null;
+ play.addEventListener("click", () => {
+ const was = play.getAttribute("aria-pressed") === "true";
+ if (was) { window.hairline.playing.stop(); window.hairline.playing = null; }
+ else window.hairline.playing = HL.tour(stage, figure.tour || HL.LAP, (i) => { if (window.hairline.onStop) window.hairline.onStop(i); });
+ play.setAttribute("aria-pressed", String(!was));
+ });
+ if (params.get("play") === "1") play.click();
+
/* ?at=200,160 holds the pointer at a viewBox point, for a picture of the answer without a mouse */
const p = (params.get("at") || "").split(",").map(Number);
if (p.length === 2 && p.every(Number.isFinite)) {
diff --git a/skills/hairline-create/examples/riffle.js b/skills/hairline-create/examples/riffle.js
index 8308a59..ba6ff5a 100644
--- a/skills/hairline-create/examples/riffle.js
+++ b/skills/hairline-create/examples/riffle.js
@@ -160,5 +160,6 @@ hairline({
means: "Eight cards in a tray: the one under the pointer stands up, and its neighbours lean away in turn.",
rules: [1, 2, 8, 10],
range: [0, 40, 90],
+ tour: [[160, 160], [200, 120], [280, 120], null],
mount,
});
diff --git a/skills/hairline-create/examples/terrain.js b/skills/hairline-create/examples/terrain.js
index 651382e..3fdcd5c 100644
--- a/skills/hairline-create/examples/terrain.js
+++ b/skills/hairline-create/examples/terrain.js
@@ -103,5 +103,6 @@ hairline({
means: "A field of pillars rises under the pointer and falls off with distance.",
rules: [1, 3, 5, 9],
range: [1.5, 3, 5],
+ tour: [[128, 150], [272, 150], [200, 206], null],
mount,
});