A page cut into parts by length is now arranged into titled sections by a model when it is first read, through the same gates as s (a model, the daily budget, the plan's limits, one request per text), once per text per server run. EX_PAGES_ARRANGE=manual keeps it to s. The pane shows the parts at once, says that it is arranging or why it did not, and swaps the sections in when they arrive. A bare http(s) address typed into a node's text is linked when the edit ends, then replaced by the page's title once that is read; u brings the address back. A node whose whole text is one address becomes a section that is only a link. See docs/pages.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
450 lines
26 KiB
TypeScript
450 lines
26 KiB
TypeScript
/**
|
|
* What the browser tests share: driving the page from the keyboard, reading the store the page
|
|
* exposes as globalThis.__ie, waiting for it to settle, going to a node's address by its titles, and
|
|
* the links written into the shared library over the op API, as an outside agent would (every kind
|
|
* of target, a note that also links, a node link from one top-level tree into another, two trees
|
|
* mentioning one article, a link and a note on the same
|
|
* words, links on the screenshot's cells; the articles are the mock
|
|
* Wikipedia's fixtures in server/wikiMock.ts).
|
|
*/
|
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { inflateSync } from "node:zlib";
|
|
import { expect, type APIRequestContext, type Page } from "@playwright/test";
|
|
|
|
/** A keypress → paint timing, as the page records it. */
|
|
export interface Sample {
|
|
what: string;
|
|
ms: number;
|
|
}
|
|
|
|
/** Run a function on the page's store and return what it returns. */
|
|
export const state = <T>(page: Page, fn: (s: any) => T): Promise<T> => page.evaluate(`(${fn})(globalThis.__ie)`) as Promise<T>;
|
|
|
|
/**
|
|
* Let this page's layout follow the window, as a reader's does (`/view auto`), from its first load:
|
|
* the tests start in the column (playwright.config.ts). Later loads keep what the page has set.
|
|
*/
|
|
export const autoLayout = (page: Page) =>
|
|
page.addInitScript(() => {
|
|
if (sessionStorage.getItem("e2e:auto")) return;
|
|
sessionStorage.setItem("e2e:auto", "1");
|
|
localStorage.removeItem("ie:settings");
|
|
});
|
|
|
|
/** Press space-separated keys, in order. */
|
|
export const keys = async (page: Page, seq: string) => {
|
|
for (const k of seq.split(" ")) await page.keyboard.press(k);
|
|
};
|
|
|
|
/** The id of the section at these titles from the library root, asked of the server as an outside agent would (none: the root). */
|
|
export async function nodeAt(page: Page, ...path: string[]): Promise<string> {
|
|
const s: Snap = await (await page.request.get("/api/tree")).json();
|
|
return find(s, ...path);
|
|
}
|
|
|
|
/** The id of the library the tests share: the server's first (what the unprefixed routes act on). */
|
|
export async function libraryId(page: Page): Promise<string> {
|
|
return (await (await page.request.get("/api/state")).json()).library;
|
|
}
|
|
|
|
/** An address in the shared library: `/l/<id>` for its root, then a path within it (`/n/<node id>`, `/w/en/Octopus`). */
|
|
async function libraryPath(page: Page, part = "/"): Promise<string> {
|
|
const base = `/l/${await libraryId(page)}`;
|
|
return part === "/" ? base : base + part;
|
|
}
|
|
|
|
/** Go to the address of the section at these titles from the library root (none: the library, `/l/<id>`), and wait for the page. */
|
|
export async function openAt(page: Page, ...path: string[]) {
|
|
await page.goto(await libraryPath(page, path.length ? `/n/${encodeURIComponent(await nodeAt(page, ...path))}` : "/"));
|
|
await page.waitForSelector("article");
|
|
}
|
|
|
|
/** In the column, make the focused node the page, as z does (without a key, which would end a first visit's hint); in panes, nothing. */
|
|
const hoistHere = (page: Page) => state(page, (s) => void (!s.panes && s.setHoist(s.focus.node)));
|
|
|
|
/**
|
|
* The section at these titles as the page: in the column hoisted to it (as z does), with the
|
|
* library one step out; in panes, in its own pane beside the library's.
|
|
*/
|
|
export async function openPage(page: Page, ...path: string[]) {
|
|
await openAt(page, ...path);
|
|
await hoistHere(page);
|
|
}
|
|
|
|
/**
|
|
* Go somewhere: an address in the shared library (`/` its root, `/w/en/Octopus`), or a top-level
|
|
* section by its title, opened as the page (openPage). Does not wait for the page.
|
|
*/
|
|
export async function visit(page: Page, where: string) {
|
|
if (where.startsWith("/")) return void (await page.goto(await libraryPath(page, where)));
|
|
await page.goto(await libraryPath(page, `/n/${encodeURIComponent(await nodeAt(page, where))}`));
|
|
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
|
await hoistHere(page);
|
|
}
|
|
|
|
/**
|
|
* A new top-level section with this text, typed from the keyboard on the library page (`a` on the
|
|
* root, its title, then `c` and its text); it is the page afterwards (hoisted, in the column) and
|
|
* has the focus.
|
|
*/
|
|
export async function addTop(page: Page, title: string, text: string) {
|
|
await page.goto(await libraryPath(page));
|
|
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
|
await page.keyboard.press("a");
|
|
await page.keyboard.type(title);
|
|
await page.keyboard.press("Enter");
|
|
if (!(await state(page, (s) => s.panes))) await page.keyboard.press("z");
|
|
await page.locator(".title, h1, h2", { hasText: title }).first().waitFor();
|
|
await page.keyboard.press("c");
|
|
await page.keyboard.type(text);
|
|
await page.keyboard.press("Escape");
|
|
}
|
|
|
|
/** / then a title then Enter: jump to a section. */
|
|
export const jump = async (page: Page, title: string) => {
|
|
await page.keyboard.press("/");
|
|
await page.keyboard.type(title);
|
|
await page.keyboard.press("Enter");
|
|
};
|
|
|
|
/** : then text then Enter. */
|
|
export const command = async (page: Page, text: string) => {
|
|
await page.keyboard.press(":");
|
|
await page.keyboard.type(text);
|
|
await page.keyboard.press("Enter");
|
|
};
|
|
|
|
/** Wait until no generation, reconciliation or link scan is running. */
|
|
export const idle = (page: Page) =>
|
|
page.waitForFunction(() => {
|
|
const s = (globalThis as any).__ie;
|
|
return s.busy === 0 && s.pending.size === 0 && s.links.busy === 0;
|
|
});
|
|
|
|
/** Wait until the server has every edit the page made. */
|
|
export const synced = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie.synced());
|
|
|
|
/** The tests share one server-side library: let each test's work reach it before the page closes. */
|
|
export async function settle(page: Page) {
|
|
if (!(await page.evaluate(() => !!(globalThis as any).__ie?.ready).catch(() => false))) return;
|
|
await idle(page);
|
|
await synced(page);
|
|
}
|
|
|
|
export const focusedTitle = (page: Page) => state(page, (s) => s.snap.nodes[s.focus.node].title);
|
|
/** The selected words. */
|
|
export const selected = (page: Page) => state(page, (s) => (s.focus.range ? s.snap.nodes[s.focus.node].body.slice(s.focus.range[0], s.focus.range[1]) : "") as string);
|
|
|
|
/** Write a latency report to test-results/latency-<name>.json. */
|
|
export const writeReport = (name: string, report: unknown) => writeFileSync(`test-results/latency-${name}.json`, JSON.stringify(report, null, 2));
|
|
|
|
/** Press space-separated keys one per frame, as a person types: each is painted before the next. */
|
|
export async function paced(page: Page, seq: string) {
|
|
for (const k of seq.split(" ")) {
|
|
await page.keyboard.press(k);
|
|
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => r(null))));
|
|
}
|
|
}
|
|
|
|
/** The links on the focused node: quote → target title (`node:<title>` for a node, the address for the web). */
|
|
export const linksHere = (page: Page) =>
|
|
state(page, (s) => {
|
|
const snap = s.snap;
|
|
const out: Record<string, string> = {};
|
|
for (const c of snap.nodes[s.focus.node].children) {
|
|
const n = snap.nodes[c];
|
|
if (n.kind === "note" && n.ref) out[n.anchors[0].text] = n.ref.kind === "wiki" ? n.ref.title : n.ref.kind === "node" ? `node:${snap.nodes[n.ref.id]?.title}` : n.ref.url;
|
|
}
|
|
return out;
|
|
});
|
|
|
|
// ---- the panes view ----
|
|
|
|
/** A pane of the strip by its title, exact, or matching a pattern. */
|
|
export const pane = (page: Page, title: string | RegExp) =>
|
|
typeof title === "string" ? page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first() : page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1)`, { hasText: title }) }).first();
|
|
/** A pane's id in the forest of panes, by its title. */
|
|
export const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
|
|
/** Two animation frames: what was laid out has been painted. */
|
|
export const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
|
/** Wait until the strip, its columns and its panes have stopped scrolling, and the curves have been drawn after. */
|
|
export async function still(page: Page) {
|
|
await page.waitForFunction(
|
|
() =>
|
|
new Promise((r) => {
|
|
const at = () => [document.querySelector(".strip")!, ...document.querySelectorAll(".strip > .col, .strip .pane-scroll")].map((el) => `${el.scrollLeft},${el.scrollTop}`).join();
|
|
const x = at();
|
|
setTimeout(() => r(at() === x), 250);
|
|
}),
|
|
);
|
|
await frames(page);
|
|
}
|
|
/** The library's panes at the site's root, laid out by the window, the fonts loaded. */
|
|
export async function library(page: Page) {
|
|
await autoLayout(page);
|
|
await page.goto("/");
|
|
await page.waitForSelector(".strip .pane");
|
|
await page.evaluate(() => document.fonts.ready);
|
|
}
|
|
/** A window wide enough for panes, at a section (or an address, visit), the panes laid out by the window, the fonts loaded. */
|
|
export async function wide(page: Page, path = "Fixed points") {
|
|
await page.setViewportSize({ width: 1920, height: 1080 });
|
|
await autoLayout(page);
|
|
await visit(page, path);
|
|
await page.waitForSelector(".strip .pane");
|
|
await page.evaluate(() => document.fonts.ready);
|
|
}
|
|
/** Click a row (or the words `sel` matches) containing this text in a pane, as the mouse would, wherever the pane is (a covered one too); then wait until still. */
|
|
export async function clickOpen(page: Page, inPane: string, text: string, sel = ".row") {
|
|
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
|
|
await still(page);
|
|
}
|
|
/** Once still, no curve fails its invariant (curveFaults). */
|
|
export const noFaults = async (page: Page, when: string) => {
|
|
await still(page);
|
|
expect(await curveFaults(page), when).toEqual([]);
|
|
};
|
|
|
|
// ---- links written into the shared library ----
|
|
|
|
interface Snap {
|
|
root: string;
|
|
nodes: Record<string, { id: string; parent: string | null; kind: string; title: string; body: string; ref?: unknown; anchors: { text: string }[]; children: string[] }>;
|
|
}
|
|
|
|
const W = (title: string) => ({ kind: "wiki", title, lang: "en" });
|
|
|
|
/** Find a section by its titles from the library root. */
|
|
function find(s: Snap, ...path: string[]): string {
|
|
let at = s.root;
|
|
for (const t of path) at = s.nodes[at]?.children.find((c) => s.nodes[c].kind === "section" && s.nodes[c].title === t) as string;
|
|
if (!at) throw new Error(`no /${path.join("/")}`);
|
|
return at;
|
|
}
|
|
const noteOn = (s: Snap, parent: string, quote: string) => s.nodes[parent].children.find((c) => s.nodes[c].kind === "note" && s.nodes[c].anchors[0]?.text === quote)!;
|
|
|
|
export async function seedLinks(request: APIRequestContext) {
|
|
const s: Snap = await (await request.get("/api/tree")).json();
|
|
const recursion = find(s, "Fixed points", "Recursion without names");
|
|
if (s.nodes[recursion].children.some((c) => s.nodes[c].ref)) return; // already seeded by an earlier test
|
|
const howY = find(s, "Fixed points", "Recursion without names", "How Y works");
|
|
const triple = find(s, "Where the elements come from", "Fusion in ordinary stars", "The triple-alpha process");
|
|
const separate = find(s, "Octopus minds", "A separate experiment");
|
|
const ancestor = find(s, "Octopus minds", "A separate experiment", "The common ancestor");
|
|
const programs = find(s, "What a proof is", "Proof assistants", "Proofs as programs");
|
|
const kinds = find(s, "The one merger", "Two kinds of cell");
|
|
const ops = [
|
|
{ op: "create", parent: recursion, kind: "note", quote: "fixed-point combinator", ref: W("Fixed-point combinator") },
|
|
{ op: "update", id: noteOn(s, recursion, "lambda calculus"), ref: W("Lambda calculus") },
|
|
{ op: "create", parent: recursion, kind: "note", quote: "Y combinator", ref: { kind: "node", id: howY, path: ["Fixed points", "Recursion without names", "How Y works"] } },
|
|
{ op: "create", parent: recursion, kind: "note", quote: "self-reference", ref: { kind: "url", url: "https://plato.stanford.edu/entries/self-reference/", title: "Self-Reference (Stanford Encyclopedia of Philosophy)" } },
|
|
{ op: "update", id: noteOn(s, triple, "an excited state at almost exactly the energy"), ref: W("Hoyle state") },
|
|
{ op: "create", parent: triple, kind: "note", quote: "Fred Hoyle", ref: W("Fred Hoyle") },
|
|
{ op: "create", parent: separate, kind: "note", quote: "octopus", ref: W("Octopus") },
|
|
{ op: "update", id: noteOn(s, separate, "cephalopod"), ref: W("Cephalopod") },
|
|
// A link on words that already carry a note of their own: two notes on one span.
|
|
{ op: "create", parent: ancestor, kind: "note", quote: "The camera-like eye", ref: W("Cephalopod") },
|
|
{ op: "create", parent: programs, kind: "note", quote: "a function turning proofs", ref: W("Lambda calculus") },
|
|
{ op: "create", parent: programs, kind: "note", quote: "Several of the leading systems", ref: { kind: "node", id: recursion, path: ["Fixed points", "Recursion without names"] } },
|
|
{ op: "create", parent: kinds, kind: "note", quote: "Eukaryotes", ref: W("Eukaryote") },
|
|
{ op: "create", parent: kinds, kind: "note", quote: "Bacteria", ref: W("Bacteria") },
|
|
];
|
|
const res = await request.post("/api/ops", { data: { author: "linker", message: "Seed links for the link tests", ops } });
|
|
if (!res.ok()) throw new Error(`seeding links failed: ${res.status()} ${await res.text()}`);
|
|
}
|
|
|
|
/**
|
|
* The web pages the tests open (server/pageMock.ts's fixtures, EX_PAGES=mock): each kind of page
|
|
* linked from words of "Error-correcting codes", a tree no other test reads, and one of its
|
|
* sections given a page as its own target. Written once, over the op API.
|
|
*/
|
|
export const WEB = {
|
|
tracing: "https://tracing.example.org/posts/following-a-request",
|
|
essay: "https://essays.example.com/hundred.html",
|
|
/** Headingless, and the mock model fails to arrange it ("mockfail" in its title). */
|
|
drift: "https://notes.example.net/field/unsorted",
|
|
/** Headingless, and the mock model takes 1.5 s to arrange it ("mockslow"). */
|
|
slow: "https://tides.example.net/slow-water",
|
|
letters: "https://letters.example.net/p/on-maps",
|
|
rules: "https://software.example.com/2003/10/twelve-rules/",
|
|
phare: "https://encyclopedie.example.org/fr/Phare_de_la_Pointe",
|
|
robots: "https://qa.example.com/questions/42/how-do-tides-work",
|
|
challenge: "https://news.example.com/world/2026/11/harbour",
|
|
pdf: "https://papers.example.org/whitepaper.pdf",
|
|
shell: "https://app.example.net/profile/someone",
|
|
figures: "https://figures.example.org/2026/birds",
|
|
videos: "https://videos.example.org/2026/weir-films",
|
|
hostile: "https://hostile.example.org/post",
|
|
octopus: "https://en.wikipedia.org/wiki/Octopus",
|
|
/** Answers once, then 410 Gone (Reload keeps the copy, stale). */
|
|
vanishing: "https://gone.example.org/notes/harbour-wall",
|
|
} as const;
|
|
|
|
export async function seedWeb(request: APIRequestContext) {
|
|
const s: Snap = await (await request.get("/api/tree")).json();
|
|
const top = find(s, "Error-correcting codes");
|
|
if (s.nodes[top].children.some((c) => s.nodes[c].ref)) return; // already seeded by an earlier test
|
|
const problem = find(s, "Error-correcting codes", "The problem");
|
|
const repetition = find(s, "Error-correcting codes", "The problem", "Repetition");
|
|
const distance = find(s, "Error-correcting codes", "The problem", "Distance");
|
|
const limit = find(s, "Error-correcting codes", "Shannon's limit");
|
|
const url = (u: string) => ({ kind: "url", url: u });
|
|
const ops = [
|
|
{ op: "create", parent: top, kind: "note", quote: "radio fades", ref: url(WEB.octopus) },
|
|
{ op: "create", parent: top, kind: "note", quote: "discs scratch", ref: url(WEB.robots) },
|
|
{ op: "create", parent: top, kind: "note", quote: "memory cells flip", ref: url(WEB.hostile) },
|
|
{ op: "create", parent: problem, kind: "note", quote: "how little extra you can send", ref: url(WEB.tracing) },
|
|
{ op: "create", parent: problem, kind: "note", quote: "ruinously wasteful", ref: url(WEB.figures) },
|
|
{ op: "create", parent: repetition, kind: "note", quote: "take a majority vote", ref: url(WEB.letters) },
|
|
{ op: "update", id: distance, ref: url(WEB.phare) },
|
|
{ op: "create", parent: limit, kind: "note", quote: "a rate in bits per use", ref: url(WEB.essay) },
|
|
];
|
|
const res = await request.post("/api/ops", { data: { author: "linker", message: "Seed links to web pages", ops } });
|
|
if (!res.ok()) throw new Error(`seeding web links failed: ${res.status()} ${await res.text()}`);
|
|
}
|
|
|
|
/** Model calls made today to arrange pages, as the e2e server counts them (<EX_DATA>/page-calls.json). */
|
|
export function pageCalls(): number {
|
|
const file = join(process.env.EX_E2E_DATA ?? "", "page-calls.json");
|
|
return existsSync(file) ? (JSON.parse(readFileSync(file, "utf8")) as { used: number }).used : 0;
|
|
}
|
|
|
|
/** A screenshot's pixels (a PNG of 8-bit RGB or RGBA, as Playwright writes them): px(x, y) is [r, g, b]. */
|
|
export function pixels(buf: Buffer): { w: number; h: number; px: (x: number, y: number) => [number, number, number] } {
|
|
let at = 8;
|
|
let w = 0;
|
|
let h = 0;
|
|
let type = 6;
|
|
const data: Buffer[] = [];
|
|
while (at < buf.length) {
|
|
const len = buf.readUInt32BE(at);
|
|
const kind = buf.toString("ascii", at + 4, at + 8);
|
|
const body = buf.subarray(at + 8, at + 8 + len);
|
|
if (kind === "IHDR") {
|
|
w = body.readUInt32BE(0);
|
|
h = body.readUInt32BE(4);
|
|
type = body[9];
|
|
} else if (kind === "IDAT") data.push(body);
|
|
at += 12 + len;
|
|
}
|
|
const bpp = type === 6 ? 4 : 3;
|
|
const raw = inflateSync(Buffer.concat(data));
|
|
const stride = w * bpp;
|
|
const out = Buffer.alloc(h * stride);
|
|
for (let y = 0; y < h; y++) {
|
|
const f = raw[y * (stride + 1)];
|
|
for (let i = 0; i < stride; i++) {
|
|
const x = raw[y * (stride + 1) + 1 + i];
|
|
const a = i >= bpp ? out[y * stride + i - bpp] : 0;
|
|
const b = y ? out[(y - 1) * stride + i] : 0;
|
|
const c = y && i >= bpp ? out[(y - 1) * stride + i - bpp] : 0;
|
|
const p = a + b - c;
|
|
const pr = Math.abs(p - a) <= Math.abs(p - b) && Math.abs(p - a) <= Math.abs(p - c) ? a : Math.abs(p - b) <= Math.abs(p - c) ? b : c;
|
|
out[y * stride + i] = (x + [0, a, b, (a + b) >> 1, pr][f]) & 255;
|
|
}
|
|
}
|
|
return { w, h, px: (x, y) => [out[y * stride + x * bpp], out[y * stride + x * bpp + 1], out[y * stride + x * bpp + 2]] };
|
|
}
|
|
|
|
/**
|
|
* The curves' invariant, measured from the page: every curve drawn starts at what its pane was
|
|
* opened from (the row, the words, or a link: within a few pixels of it), or, when that is out of
|
|
* sight, on its pane's edge over it (dotted), or at the end of its folded pane's tab foot; and ends
|
|
* in its pane's landing line: the rule under its title, along to the rule's end, or its tab's foot,
|
|
* or just before its title. Returns what fails, as text (empty when all hold).
|
|
*/
|
|
export const curveFaults = (page: Page) =>
|
|
page.evaluate(() => {
|
|
const ie = (globalThis as any).__ie;
|
|
const norm = (u: string) => {
|
|
const x = new URL(u);
|
|
x.hash = "";
|
|
return !x.search && x.href.endsWith("/") ? x.href.slice(0, -1) : x.href;
|
|
};
|
|
const refKey = (p: any) => (p.kind === "node" ? `n:${p.id}` : p.kind === "web" ? `u:${norm(p.url)}${p.sec ? `#${p.sec}` : ""}` : `w:${p.title}${p.sec !== undefined ? `#${p.sec}` : ""}`);
|
|
const kidClass = (key: string) => {
|
|
let h = 5381;
|
|
for (let i = 0; i < key.length; i++) h = ((h * 33) ^ key.charCodeAt(i)) >>> 0;
|
|
return `k${h.toString(36)}`;
|
|
};
|
|
const TAB = 30;
|
|
const faults: string[] = [];
|
|
const svg = document.querySelector<SVGSVGElement>(".curves")!.getBoundingClientRect();
|
|
const box = { left: Math.round(svg.left), top: Math.round(svg.top) };
|
|
const placed = new Map<number, any>(ie.panesPlaced.map((x: any) => [x.node.id, x]));
|
|
for (const p of document.querySelectorAll<SVGPathElement>(".curves path:not(.foot):not(.frame)")) {
|
|
const to = Number(p.dataset.to);
|
|
const from = Number(p.dataset.from);
|
|
const ce = document.querySelector<HTMLElement>(`.pane[data-tid="${to}"]`);
|
|
const pe = document.querySelector<HTMLElement>(`.pane[data-tid="${from}"]`);
|
|
const x = placed.get(to);
|
|
if (!ce || !pe || !x) {
|
|
faults.push(`${from}>${to}: no pane`);
|
|
continue;
|
|
}
|
|
const a0 = p.getPointAtLength(0);
|
|
const b0 = p.getPointAtLength(p.getTotalLength());
|
|
const a = { x: a0.x + box.left, y: a0.y + box.top };
|
|
const b = { x: b0.x + box.left, y: b0.y + box.top };
|
|
const lost = p.classList.contains("lost");
|
|
const name = `${from}>${to} ${ce.querySelector(".pane-head h2, .top h1, .wiki-head h2")?.textContent?.trim()}`;
|
|
const cr = ce.getBoundingClientRect();
|
|
const col = ce.parentElement!.getBoundingClientRect();
|
|
const nextCol = (ce.parentElement!.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().left ?? Infinity;
|
|
// The end.
|
|
const ruled = ce.dataset.ruled ?? "";
|
|
if (ruled.includes("head")) {
|
|
const head = ce.querySelector<HTMLElement>(":scope > .pane-scroll > .pane-body > .pane-head, :scope > .pane-scroll > .pane-body > .top h1, :scope > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head")!;
|
|
const r = head.getBoundingClientRect();
|
|
if (Math.abs(b.y - (r.bottom - 0.5)) > 1.2) faults.push(`${name}: ends at y ${b.y}, its title's rule at ${r.bottom - 0.5}`);
|
|
if (Math.abs(b.x - Math.min(r.right, nextCol, cr.right)) > 1.6) faults.push(`${name}: ends at x ${b.x}, its rule's end at ${Math.min(r.right, nextCol)}`);
|
|
} else if (ruled.includes("tab") && !lost) {
|
|
if (Math.abs(b.y - (cr.top + TAB - 0.5)) > 1.2) faults.push(`${name}: ends at y ${b.y}, its tab's foot at ${cr.top + TAB - 0.5}`);
|
|
} else if (!lost) {
|
|
if (b.x < col.left - 1 || b.x > col.left + 60 || b.y < cr.top - 1 || b.y > Math.min(cr.bottom, col.bottom) + 1) faults.push(`${name}: ends at ${b.x},${b.y}, outside its pane's head (${cr.top}..${cr.bottom})`);
|
|
}
|
|
// The start.
|
|
const pr = pe.getBoundingClientRect();
|
|
if (a.x < pr.left - 1 || a.x > pr.right + 1) faults.push(`${name}: starts at x ${a.x}, outside its source pane ${pr.left}..${pr.right}`);
|
|
const footStart = Math.abs(a.y - (pr.top + TAB - 0.5)) <= 1.2 && Math.abs(a.x - Math.min(pr.right - 1, col.left)) <= 2;
|
|
if (lost || footStart) continue;
|
|
const cands = [...pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`)];
|
|
const near = cands.some((c) => {
|
|
const el = c.matches("li") ? (c.querySelector<HTMLElement>(":scope > .row") ?? c) : c;
|
|
return [...el.getClientRects()].some((r) => a.x >= r.left - 2 && a.x <= r.right + 10 && a.y >= r.top - 4 && a.y <= r.bottom + 6);
|
|
});
|
|
if (!near) faults.push(`${name}: starts at ${a.x},${a.y}, not at its source (${cands.length} candidates)`);
|
|
}
|
|
// What peeks: its place left clear of every curve but its own; nothing left over once it is back.
|
|
const peeked = [...document.querySelectorAll<HTMLElement>("[data-peek]")];
|
|
const holes = [...document.querySelectorAll<SVGRectElement>("#ie-curve-holes rect.hole")].map((r) => ({ x: +r.getAttribute("x")! + box.left, y: +r.getAttribute("y")! + box.top, w: +r.getAttribute("width")!, h: +r.getAttribute("height")! }));
|
|
const under = document.querySelector<SVGGElement>(".curves g.under");
|
|
const over = [...document.querySelectorAll<SVGPathElement>(".curves g.over path")];
|
|
for (const p of peeked) {
|
|
const r = p.getBoundingClientRect();
|
|
if (!holes.some((h) => Math.abs(h.x - r.left) < 1.5 && Math.abs(h.y - r.top) < 1.5 && Math.abs(h.w - r.width) < 1.5 && Math.abs(h.h - r.height) < 1.5)) faults.push(`peeking ${p.className}: its place is not clear of the curves`);
|
|
if (under && under.getAttribute("mask") !== "url(#ie-curve-holes)") faults.push("peeking: the curves under it are not masked");
|
|
}
|
|
const owns = (id: string | undefined) => peeked.some((q) => q.contains(document.querySelector(`.pane[data-tid="${id}"]`)));
|
|
// A pane peeking out of a column that peeks too: the column's other panes' curves are over the column, under that pane (it may cover their tabs).
|
|
const paneOwns = (id: string | undefined) => peeked.some((q) => q.classList.contains("pane") && q.contains(document.querySelector(`.pane[data-tid="${id}"]`)));
|
|
for (const p of document.querySelectorAll<SVGPathElement>(".curves g.under path")) if (owns(p.dataset.from) || owns(p.dataset.to)) faults.push(`${p.dataset.key}: belongs to what peeks, but is under it`);
|
|
for (const p of over) if (!paneOwns(p.dataset.from) && !paneOwns(p.dataset.to)) faults.push(`${p.dataset.key}: over what peeks, but not its own`);
|
|
const mid = document.querySelector<SVGGElement>(".curves g.mid");
|
|
for (const p of document.querySelectorAll<SVGPathElement>(".curves g.mid path")) if (paneOwns(p.dataset.from) || paneOwns(p.dataset.to) || (!owns(p.dataset.from) && !owns(p.dataset.to))) faults.push(`${p.dataset.key}: over the peeking column and under the pane peeking in it, but not only the column's`);
|
|
const paneHoles = [...document.querySelectorAll<SVGRectElement>("#ie-curve-mid rect.hole")].map((r) => ({ x: +r.getAttribute("x")! + box.left, y: +r.getAttribute("y")! + box.top }));
|
|
for (const p of peeked.filter((q) => q.classList.contains("pane") && peeked.some((c) => c !== q && c.contains(q)))) {
|
|
const r = p.getBoundingClientRect();
|
|
if (!paneHoles.some((h) => Math.abs(h.x - r.left) < 1.5 && Math.abs(h.y - r.top) < 1.5) || mid?.getAttribute("mask") !== "url(#ie-curve-mid)") faults.push(`peeking ${p.className}: its column's other curves are not kept off it`);
|
|
}
|
|
const bar = document.querySelector<HTMLElement>(".pane > .selbar");
|
|
const barShown = !!bar && bar.style.visibility !== "hidden";
|
|
if (!peeked.length && holes.length > (barShown ? 1 : 0)) faults.push(`nothing peeks, but ${holes.length} holes are left in the curves`);
|
|
if (barShown) {
|
|
const r = bar!.getBoundingClientRect();
|
|
if (!holes.some((h) => Math.abs(h.x - r.left) < 1.5 && Math.abs(h.y - r.top) < 1.5)) faults.push("the selection bar's place is not clear of the curves");
|
|
}
|
|
return faults;
|
|
});
|