Skip to content

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

Skill: the validator names a tset given no delay, before a browser is opened

Lucas Marquese9ec3e6f837f
diff --git a/packages/hairline/test/skill/shape.test.ts b/packages/hairline/test/skill/shape.test.ts
index 3b25f82..0a0447d 100644
--- a/packages/hairline/test/skill/shape.test.ts
+++ b/packages/hairline/test/skill/shape.test.ts
@@ -43,7 +43,7 @@ it("look.md and SKILL.md name the validator's checks and the bench's parameters
expect(text("look.md")).toContain("at=");
for (const param of ["?intensity=0", "?intensity=1", "?theme=dark", "?theme=light"]) expect(text("look.md"), param).toContain(param);
for (const param of ["intensity", "theme"]) expect(text("bench.html"), param).toContain(`params.get("${param}")`);
- for (const id of ["kernel", "parse", "bench", "text", "paint", "outside", "clock", "hit", "readout", "handle", "declare", "length"]) {
+ for (const id of ["kernel", "parse", "bench", "text", "paint", "outside", "clock", "tween", "hit", "readout", "handle", "declare", "length"]) {
expect(text("validate.mjs"), id).toMatch(new RegExp(`^ \\* {3}${id} `, "m"));
}
});
diff --git a/packages/hairline/test/skill/validate.test.ts b/packages/hairline/test/skill/validate.test.ts
index 1ea58c8..358697a 100644
--- a/packages/hairline/test/skill/validate.test.ts
+++ b/packages/hairline/test/skill/validate.test.ts
@@ -64,6 +64,9 @@ const HONEST: [why: string, figure: string][] = [
["the word import inside a longer name", plus("const important = true;")],
["a name that starts with import, before a comma", plus("const [important, b] = [1, 2];")],
["a name that starts with import, as an argument", plus("f(imported, 1);")],
+ ["a tset given a delay of 0, with a call among its values", plus("HL.tset(HL.tween(0), Math.max(1, 2), performance.now(), 0);")],
+ ["a name that ends in tset", plus("const offset = (a, b) => a + b;\noffset(1, 2);")],
+ ["a tset written in a string", plus('const note = "tset(a, b)";')],
["a handle returned in shorthand, { set, destroy }", terrain.replace(
/return \{\n {4}set: (\(v\) => \{[^\n]*\}),\n {4}destroy: bag\.dispose,\n {2}\};/,
(_, set) => `const set = ${set};\n const destroy = bag.dispose;\n return { set, destroy };`,
@@ -112,6 +115,8 @@ const BROKEN: [id: string, why: string, figure: string, change?: (page: string)
["clock", "an SMIL animateMotion element", plus("mk('animateMotion', { dur: \"1s\", repeatCount: \"indefinite\" });")],
["clock", "a timer after a // in a string", plus('const s = "a // b"; setTimeout(() => {}, 1);')],
["clock", "no kernel loop", terrain.replace("register(stage,", "((s, t) => ({ wake() {}, unregister() {} }))(stage,")],
+ ["tween", "a tset without its delay", plus("HL.tset(HL.tween(0), 1, performance.now());")],
+ ["tween", "a tset without its delay, with a call among its values", plus("HL.tset(HL.tween(0), Math.max(1, 2), performance.now());")],
["hit", "a box measured on screen", plus("stage.getBoundingClientRect();")],
["hit", "its own listener", plus('stage.addEventListener("pointermove", () => {});')],
["hit", "no pointer", terrain.replace("bag.add(pointer(stage,", "bag.add(((s, h) => () => {})(stage,")],
diff --git a/skills/hairline-create/validate.mjs b/skills/hairline-create/validate.mjs
index c38c189..2bebd53 100644
--- a/skills/hairline-create/validate.mjs
+++ b/skills/hairline-create/validate.mjs
@@ -12,6 +12,7 @@
* paint no stroke width, colour, fill, opacity, filter or shadow of its own (rule 04)
* outside nothing loaded or reached outside the file; every node from HL.mk
* clock no timers, frames or SMIL animation of its own; it joins HL.register (rule 07)
+ * tween every tset is given its four values, the delay last
* hit input only through HL.pointer; nothing measured on screen (rule 01)
* readout it writes read.textContent
* handle mount returns { set, destroy }
@@ -109,6 +110,28 @@ const NEED = [
["handle", /(?<![.\w$])destroy\s*[:(,}]/, "mount must return { set(value), destroy() }, and destroy is missing. It undoes everything mount did: bag.dispose."],
];
+/**
+ * Each `tset` given fewer than its four values. Without its delay a tween
+ * starts at no time at all: its value is NaN, and so is every path drawn from it.
+ */
+function tweens(shape) {
+ const out = [];
+ for (const m of shape.matchAll(/(?<![\w$])tset\s*\(/g)) {
+ let i = m.index + m[0].length, depth = 1, given = 1;
+ for (; i < shape.length && depth; i++) {
+ const c = shape[i];
+ if ("([{".includes(c)) depth++;
+ else if (")]}".includes(c)) depth--;
+ else if (c === "," && depth === 1) given++;
+ }
+ const call = shape.slice(m.index, i).replace(/\s+/g, " ");
+ if (given < 4 && !call.includes("...")) {
+ out.push(`tween: \`${call}\` is given ${given} of tset's four values: tset(tw, to, now, delay). Without the delay the tween's value is NaN and nothing is drawn. Give it 0 to start at once.`);
+ }
+ }
+ return out;
+}
+
/** The declaration at the end of the file, read as text. */
function declared(code) {
const say = (what) => `declare: the file must end with hairline({ name, means, rules, range, mount }). ${what}`;
@@ -171,6 +194,7 @@ export function validate(input) {
out.push(...parse(src));
for (const [id, re, say, empty] of BAD) if (re.test(code) || empty?.test(shape)) out.push(`${id}: ${say}`);
for (const [id, re, say] of NEED) if (!re.test(code)) out.push(`${id}: ${say}`);
+ out.push(...tweens(shape));
out.push(...declared(code));
const lines = src.split("\n").length;
if (lines > LIMIT) out.push(`length: the figure is ${lines} lines and the limit is ${LIMIT}. A figure this long is usually two ideas: cut the concept down to one.`);