Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
feat(engine): overlay engine/src and example/src at build time (esbuild plugin + tsconfig rootDirs) so launch films import the committed butterfly; tsc covers the example
Alex Greenshpun1fc4af35fbf8
diff --git a/skills/anidoodle/engine/tools/adapters/remotion.mjs b/skills/anidoodle/engine/tools/adapters/remotion.mjsindex 5779d5d..dc4b261 100644--- a/skills/anidoodle/engine/tools/adapters/remotion.mjs+++ b/skills/anidoodle/engine/tools/adapters/remotion.mjs@@ -13,6 +13,7 @@ import { createHash } from "node:crypto";import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";import { createRequire } from "node:module";import { join, resolve } from "node:path";+import { overlay } from "../overlay.mjs";const require = createRequire(import.meta.url);const tryRequire = (id) => { try { return require(id); } catch { return null; } };@@ -35,7 +36,7 @@ export const probe = () => {// build-page.mjs reads it: bundled on its own, with no host attached, so nothing can disagree.const loadFilm = async (film) => {const { build } = await import("esbuild");- const out = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text;+ const out = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay] })).outputFiles[0].text;return (await import("data:text/javascript;base64," + Buffer.from(out).toString("base64"))).film;};diff --git a/skills/anidoodle/engine/tools/build-page.mjs b/skills/anidoodle/engine/tools/build-page.mjsindex 0ca66c3..3ab0876 100644--- a/skills/anidoodle/engine/tools/build-page.mjs+++ b/skills/anidoodle/engine/tools/build-page.mjs@@ -1,11 +1,14 @@// Build ONE self-contained HTML file: the art core + film, bundled, with every asset in the// manifest inlined as a data URI. No network, no server, no sibling files.import { build } from "esbuild";-import { readFileSync, writeFileSync, mkdirSync } from "node:fs";+import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";import { extname, join } from "node:path";+import { overlay, resolveOverlay } from "./overlay.mjs";const MIME = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp", ".woff2": "font/woff2" };-export const buildPage = async ({ entry, out, title, plugins = [] }) => {+export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {+ const plugins = [...extra, overlay]; // extra first: a caller's shim (snap --only) outranks the overlay+ if (!existsSync(entry)) entry = resolveOverlay("./" + entry, process.cwd()) ?? entry; // e.g. the example's own host pageconst js = (await build({ entryPoints: [entry], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", plugins })).outputFiles[0].text;// read the manifest out of the film module itself, so the page and the film can never disagreeconst probe = (await build({ stdin: { contents: `export { ${title} as film } from "./src/canvas-core/${title}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins })).outputFiles[0].text;diff --git a/skills/anidoodle/engine/tools/emit-interactive.mjs b/skills/anidoodle/engine/tools/emit-interactive.mjsindex 5d270b3..8503526 100644--- a/skills/anidoodle/engine/tools/emit-interactive.mjs+++ b/skills/anidoodle/engine/tools/emit-interactive.mjs@@ -22,6 +22,7 @@ import { dirname, resolve } from "node:path";import { pathToFileURL } from "node:url";import { gzipSync } from "node:zlib";import { detect } from "./detect.mjs";+import { overlay } from "./overlay.mjs";const VAL = new Set(["out", "module", "page", "title", "shot"]);const pos = [], opt = {};@@ -35,7 +36,7 @@ const out = resolve(opt.out ?? `out/${kebab}.html`), modOut = resolve(opt.module// ---------------------------------------------------------------- buildconst buildModule = async (piece, tag = piece.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()) => (await build({stdin: { contents: `import { mount, define } from "./src/hosts/interactive"; import { ${piece} } from "./src/canvas-core/${piece}"; export const piece = ${piece}; export { mount, define }; define({ ${JSON.stringify(tag)}: ${piece} });`, resolveDir: process.cwd(), loader: "ts" },- bundle: true, format: "esm", target: "es2020", minify: true, write: false, legalComments: "none",+ bundle: true, format: "esm", target: "es2020", minify: true, write: false, legalComments: "none", plugins: [overlay],})).outputFiles[0].text;const js = await buildModule(name, kebab);const defaultPage = () => `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${opt.title ?? name}</title>diff --git a/skills/anidoodle/engine/tools/gallery.mjs b/skills/anidoodle/engine/tools/gallery.mjsindex 90073dc..ee3f956 100644--- a/skills/anidoodle/engine/tools/gallery.mjs+++ b/skills/anidoodle/engine/tools/gallery.mjs@@ -12,6 +12,7 @@ import { buildPage } from "./build-page.mjs";import { detect } from "./detect.mjs";import * as playwright from "./adapters/playwright.mjs";import { loadRegistry, ENGINE, ROOT } from "./registry.mjs";+import { overlay } from "./overlay.mjs";process.chdir(ENGINE); // buildPage and the host pages resolve src/ against cwd, like every tool hereconst GALLERY = resolve(ROOT, "assets/gallery");@@ -40,7 +41,7 @@ const findFont = (ff) => {// A still.mjs-style probe: bundle the film, read meta, no browser. Enough for --dry to say which// frame is the last.-const metaOf = async (film) => (await import("data:text/javascript;base64," + Buffer.from((await (await import("esbuild")).build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text).toString("base64"))).film.meta;+const metaOf = async (film) => (await import("data:text/javascript;base64," + Buffer.from((await (await import("esbuild")).build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay] })).outputFiles[0].text).toString("base64"))).film.meta;const cols = Math.ceil(Math.sqrt(tiles.length)), rows = Math.ceil(tiles.length / cols);const plan = (font) => `grid ${cols}x${rows} of ${CELL}px tiles, ${font.ok ? `labels in ${font.font}` : `no labels (${font.why}) -> LEGEND.md`}`;diff --git a/skills/anidoodle/engine/tools/lesson.mjs b/skills/anidoodle/engine/tools/lesson.mjsindex 632d0fd..436dff6 100644--- a/skills/anidoodle/engine/tools/lesson.mjs+++ b/skills/anidoodle/engine/tools/lesson.mjs@@ -18,6 +18,7 @@ import { pathToFileURL } from "node:url";import { build } from "esbuild";import { buildPage } from "./build-page.mjs";import { detect } from "./detect.mjs";+import { overlay } from "./overlay.mjs";const VAL = new Set(["out", "ref", "ref-crop", "workers"]);const pos = [], opt = {};@@ -28,7 +29,7 @@ const outDir = resolve(opt.out ?? `out/${name}`); mkdirSync(outDir, { recursive:const log = []; const say = (s = "") => { console.log(s); log.push(s); };// ---------------------------------------------------------------- 1. the score, in node-const probe = (await build({ stdin: { contents: `export { LESSON, ${name} as film } from "./src/canvas-core/${name}"; export { validate, PHASE_NAME } from "./src/canvas-core/drawingScore";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text;+const probe = (await build({ stdin: { contents: `export { LESSON, ${name} as film } from "./src/canvas-core/${name}"; export { validate, PHASE_NAME } from "./src/canvas-core/drawingScore";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay] })).outputFiles[0].text;const M = await import("data:text/javascript;base64," + Buffer.from(probe).toString("base64"));const S = M.LESSON.score(), V = M.validate(S), plan = M.film.plan(), fps = M.film.meta.fps, N = M.film.meta.durationFrames;say(`LESSON ${S.title} (${S.medium})`);diff --git a/skills/anidoodle/engine/tools/overlay.mjs b/skills/anidoodle/engine/tools/overlay.mjsnew file mode 100644index 0000000..14ba363--- /dev/null+++ b/skills/anidoodle/engine/tools/overlay.mjs@@ -0,0 +1,36 @@+// OVERLAY. The engine's src/ and the worked example's example/src/ are ONE tree at build time,+// exactly as scaffold.mjs --example lays them out on disk: a relative import that is not found+// next to its importer is looked for at the same relative place under the other root. The+// example keeps importing "../core"; a launch film can import "./mechanicalLepidoptera" and get+// the committed example. Order matters: engine/src first, so the engine always wins a name clash.+// tsconfig.json says the same thing to tsc with "rootDirs", so the checker and the bundler agree.+import { existsSync, statSync } from "node:fs";+import { dirname, join, relative, resolve, sep } from "node:path";+import { fileURLToPath } from "node:url";++const ENGINE = resolve(dirname(fileURLToPath(import.meta.url)), "..");+export const ROOTS = [join(ENGINE, "src"), resolve(ENGINE, "../example/src")];+const EXT = ["", ".ts", ".tsx", ".js", ".mjs", "/index.ts", "/index.js"];+const file = (p) => { for (const e of EXT) { const f = p + e; if (existsSync(f) && statSync(f).isFile()) return f; } return null; };+const rootOf = (p) => ROOTS.find((r) => p === r || p.startsWith(r + sep));++// Resolve a relative specifier asked from directory `dir` across the roots; null when it is not+// ours to answer. `dir` may sit outside the roots (a probe's stdin resolves from engine/).+export const resolveOverlay = (spec, dir) => {+ const want = resolve(dir, spec), root = rootOf(want); if (!root) return null;+ if (file(want)) return null; // found where it was asked for: esbuild's own resolver handles it+ const rel = relative(root, want);+ if (rel.startsWith("..")) return null; // left the tree: not an overlay question+ for (const r of ROOTS) { if (r === root) continue; const f = file(join(r, rel)); if (f) return f; }+ return null;+};++export const overlay = {+ name: "anidoodle-overlay",+ setup(b) {+ b.onResolve({ filter: /^\.\.?\// }, (a) => {+ const f = resolveOverlay(a.path, a.resolveDir);+ return f ? { path: f } : undefined;+ });+ },+};diff --git a/skills/anidoodle/engine/tools/snap.mjs b/skills/anidoodle/engine/tools/snap.mjsindex e2232a8..c0fe9e8 100644--- a/skills/anidoodle/engine/tools/snap.mjs+++ b/skills/anidoodle/engine/tools/snap.mjs@@ -10,6 +10,7 @@ import { dirname, join, resolve } from "node:path";import { buildPage } from "./build-page.mjs";import { detect } from "./detect.mjs";import * as playwright from "./adapters/playwright.mjs";+import { overlay } from "./overlay.mjs";const VAL = new Set(["shot", "samples", "scale", "out"]);const pos = [], opt = {};@@ -40,7 +41,7 @@ const onlyPlugin = opt.only ? (() => {})() : [];// the film's own shots and meta, read through the same shim in --only mode-const probe = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: onlyPlugin })).outputFiles[0].text;+const probe = (await build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [...onlyPlugin, overlay] })).outputFiles[0].text;const f = (await import("data:text/javascript;base64," + Buffer.from(probe).toString("base64"))).film;const targets = shotId ? [f.shots.find((s) => s.id === shotId) ?? die(`film '${film}' has no shot '${shotId}' (has: ${f.shots.map((s) => s.id).join(", ")})`)] : f.shots;diff --git a/skills/anidoodle/engine/tools/still.mjs b/skills/anidoodle/engine/tools/still.mjsindex fc5f5b3..53affe1 100644--- a/skills/anidoodle/engine/tools/still.mjs+++ b/skills/anidoodle/engine/tools/still.mjs@@ -9,6 +9,7 @@ import { dirname, resolve } from "node:path";import { buildPage } from "./build-page.mjs";import { detect } from "./detect.mjs";import * as playwright from "./adapters/playwright.mjs";+import { overlay } from "./overlay.mjs";const VAL = new Set(["shot", "out", "scale", "frame"]);const pos = [], opt = {};@@ -23,7 +24,7 @@ if (!env.pw.ok || !env.browser.ok) die(`no browser to draw in.\n playwright: ${const page = await buildPage({ entry: `src/hosts/page-${film}.ts`, out: resolve(`dist/${film}.html`), title: film });const session = await playwright.open(env, page.out, { scale, workers: 1 });const meta = await session.info();-const probe = (await import("data:text/javascript;base64," + Buffer.from((await (await import("esbuild")).build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral" })).outputFiles[0].text).toString("base64"))).film;+const probe = (await import("data:text/javascript;base64," + Buffer.from((await (await import("esbuild")).build({ stdin: { contents: `export { ${film} as film } from "./src/canvas-core/${film}";`, resolveDir: process.cwd(), loader: "ts" }, bundle: true, format: "esm", write: false, platform: "neutral", plugins: [overlay] })).outputFiles[0].text).toString("base64"))).film;const shots = opt.shot ? [probe.shots.find((s) => s.id === opt.shot) ?? die(`no shot '${opt.shot}' (has: ${probe.shots.map((s) => s.id).join(", ")})`)] : probe.shots;console.log(`film: "${meta.title}" ${meta.W}x${meta.H}, scale ${scale}`);diff --git a/skills/anidoodle/engine/tsconfig.json b/skills/anidoodle/engine/tsconfig.jsonindex 1fe1ad9..d85c7e5 100644--- a/skills/anidoodle/engine/tsconfig.json+++ b/skills/anidoodle/engine/tsconfig.json@@ -1,7 +1,8 @@{"compilerOptions": {"target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", "jsx": "react-jsx",- "strict": true, "noEmit": true, "skipLibCheck": true, "esModuleInterop": true, "lib": ["DOM", "ES2022"]+ "strict": true, "noEmit": true, "skipLibCheck": true, "esModuleInterop": true, "lib": ["DOM", "ES2022"],+ "rootDirs": ["src", "../example/src"]},- "include": ["src"]+ "include": ["src", "../example/src"]}