Isometric line figures that answer the pointer. For React and for anything with a DOM.
Skill: look.mjs exports its browser, playwright() and launch(pw), for read.mjs to share
Lucas Marquesdbbc77c191b8
diff --git a/packages/hairline/test/skill/look.test.ts b/packages/hairline/test/skill/look.test.tsindex c487170..d57730d 100644--- a/packages/hairline/test/skill/look.test.ts+++ b/packages/hairline/test/skill/look.test.ts@@ -30,3 +30,26 @@ it("by default reaches 600ms in sixteen frames, most of the way through the 700mexpect(b).toHaveLength(16);expect(b.at(-1)).toBe(600);});++/** launch: the browser order the look uses, shared with read.mjs. A fake Playwright records what it was asked for. */+const fakePw = (chromeWorks: boolean) => {+ const asked: unknown[] = [];+ const chromium = {+ launch: (o?: { channel?: string }) => {+ asked.push(o ?? null);+ return o?.channel && !chromeWorks ? Promise.reject(new Error("no chrome")) : Promise.resolve("browser");+ },+ };+ return { pw: { chromium }, asked };+};++it("launch starts the installed Chrome first, then Playwright's Chromium", async () => {+ const { launch, playwright } = await import("../../../../skills/hairline-create/look.mjs");+ expect(typeof playwright).toBe("function");+ const a = fakePw(true);+ await expect(launch(a.pw)).resolves.toBe("browser");+ expect(a.asked).toEqual([{ channel: "chrome" }]);+ const b = fakePw(false);+ await expect(launch(b.pw)).resolves.toBe("browser");+ expect(b.asked).toEqual([{ channel: "chrome" }, null]);+});diff --git a/skills/hairline-create/look.mjs b/skills/hairline-create/look.mjsindex 49e9fc4..9a32fb5 100644--- a/skills/hairline-create/look.mjs+++ b/skills/hairline-create/look.mjs@@ -106,7 +106,7 @@ export function point(s) {}/** playwright-core from the cache, installed there first when it is not. Throws with a reason when it cannot be had. */-function playwright(dir) {+export function playwright(dir) {const req = createRequire(join(dir, "look.cjs"));const has = () => { try { return req.resolve("playwright-core/package.json"); } catch { return null; } };if (!has()) {@@ -121,6 +121,11 @@ function playwright(dir) {return { chromium: req("playwright-core").chromium, cli: join(dirname(has()), "cli.js") };}+/** Starts the browser: the installed Chrome, or Playwright's own Chromium when there is none. Rejects when neither launches. */+export function launch(pw) {+ return pw.chromium.launch({ channel: "chrome" }).catch(() => pw.chromium.launch());+}+/** Keeps the P the figure makes from its own camera, so a world point can be* turned into an ?at= point, and the `answer` and `edge` points a figure may@@ -271,7 +276,7 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {console.error('Check the network and run this again, or look without a browser: look.md, "Without a browser".');return 2;}- const browser = await pw.chromium.launch({ channel: "chrome" }).catch(() => pw.chromium.launch()).catch(() => null);+ const browser = await launch(pw).catch(() => null);if (!browser) {console.error(`look: no Chrome, and no Chromium of Playwright's. Install one once:\n node "${pw.cli}" install chromium`);console.error('Then run this again. Without a browser, look.md says what to do: "Without a browser".');