Curves draw the rules they land in; tabs for folded and scrolled panes; peek on both axes
- A curve runs on along the rule under its pane's title (any kind of pane: section, page, article, article section) and draws it, the pane's own rule left out, so the two are one stroke, set on device pixels (the curves' layer measured from its whole pixel; a hairline is one device pixel). - The landing: the title's rule when it shows, else the tab's foot, whether the pane is folded down its column or scrolled past its title. A pane scrolled past its title shows its tab at its top (an observer on the rule, nothing per scroll or key). - A curve out of a folded pane whose source is out of sight leaves from the end of its tab's foot, solid, the foot drawn with it; the stacked pane's own top edge under it is left out. - Colours: the panes' and curves' colour came out as the neutral ink on every curve (a selector outweighed the colour's); the neutral is nearer the text's ink. Colour depends on the tree only. - A covered pane peeks out across and down at once, and stays out while the wheel scrolls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
66d25eea7f
commit
8f6afaecdd
6 files changed
+643
-94
No files matched your search
@@ -107,20 +107,28 @@ Press `?` for every key. The short version:
|
||||
them, a short pane taking only what its text needs. When they do not all fit, the column stacks
|
||||
them the way the strip stacks columns: each pane stuck a tab below the one before, the pane on the
|
||||
focused branch shown whole and the others slid under it, partly and at the limit down to a
|
||||
one-line tab, just as earlier columns slide under later ones down to a spine. Mouse resting on a
|
||||
covered pane, tab or spine: after a moment it peeks out over its neighbours; a click makes it the
|
||||
active pane. A pane's grip (the band above its title, by the pin and x, shown when pointed at) or
|
||||
one-line tab, just as earlier columns slide under later ones down to a spine. A pane scrolled
|
||||
past its own title shows the same tab at its top, over its text. Mouse resting on a covered pane,
|
||||
tab or spine: after a moment it peeks out over its neighbours, its column across and the pane down
|
||||
its column at once, and stays out while the pointer is on it (the wheel scrolls it); a click makes
|
||||
it the active pane. A pane's grip (the band above its title, by the pin and x, shown when pointed at) or
|
||||
its tab drags it up or down its column; Esc cancels; the column keeps that order. `[` and `]` go to
|
||||
the pane above and below in the column, back where you were in it; at the top or bottom they stay.
|
||||
`h` and `l` move along the focused branch.
|
||||
- **Curves.** A faint curve runs from the words, row or link each pane was opened from (joined to
|
||||
their underline) to its title; the focused branch's is drawn stronger. Curves down one gutter run
|
||||
side by side, ordered to cross as little as they can. `/curves off` hides them.
|
||||
- **Curves.** A curve runs from the words, row or link each pane was opened from (joined to their
|
||||
underline) into the rule under the pane's title, and draws that rule, so the two are one hairline
|
||||
on device pixels; the focused branch's is drawn stronger. Where the title does not show (the pane
|
||||
folded to its tab, or scrolled past it), the curve runs into the tab's foot instead; out of a
|
||||
folded pane whose source is out of sight, it leaves from the end of that pane's tab foot. A source
|
||||
scrolled out of a pane it is still in is held at the pane's edge and the curve dotted. Curves down
|
||||
one gutter run side by side, ordered to cross as little as they can. `/curves off` hides them.
|
||||
- **Fork colours.** Each fork has a colour of its own, quiet and the same lightness for all: a
|
||||
pane opened as the first from its pane goes on in that pane's colour, any other starts the next
|
||||
of seven, so a plain trail is one colour and the first trail plain ink. The colour runs along the
|
||||
curve into the rule under the pane's title (a tab's foot, a dash on a spine), at full strength on
|
||||
the focused branch; a pane keeps its colour while it is open, through a reorder, or as an orphan.
|
||||
of seven, so a plain trail is one colour. The top node (the library) has none to hand down: each
|
||||
pane opened from it starts its own. The colour runs along the curve into the rule under the
|
||||
pane's title (a tab's foot, a dash on a spine), at full strength on the focused branch and
|
||||
fainter off it; a pane keeps its colour while it is open, through a reorder, or as an orphan, and
|
||||
nothing but the panes' tree decides it (not the focus, a scroll or a fold).
|
||||
`/colors line|top|edge|off` (or the menu) puts it there, in a band across each pane's top, down
|
||||
its left edge, or nowhere.
|
||||
- **The active pane**, where the keys act, has a heavy rule across its top; the rest of the focused
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* Fork colours and the lines they run along, in the panes view: every kind of pane's title rule is
|
||||
* drawn by the curve into it, in the pane's colour, as one stroke (measured in the pixels, at several
|
||||
* device pixel ratios); a pane folded or scrolled past its title shows its tab and the curve lands in
|
||||
* the tab's foot, and a curve out of a folded pane leaves from that foot; a pane's colour depends on
|
||||
* the forest only; a covered pane peeks out across and down at once, and the wheel scrolls it; the
|
||||
* selection bar sits at its pane's level. Same build, mock model and mock Wikipedia as the others.
|
||||
*/
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { autoLayout, pixels, seedLinks, settle, state } from "./helpers";
|
||||
|
||||
const pane = (page: Page, title: string) => page.locator(".strip .pane", { has: page.locator(`:is(.wiki-head h2, .pane-head h2, .top h1):text-is("${title}")`) }).first();
|
||||
const tid = (page: Page, title: string) => pane(page, title).evaluate((el) => Number((el as HTMLElement).dataset.tid));
|
||||
const frames = (page: Page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
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);
|
||||
}
|
||||
/** Click a row (or words) in a pane, as the mouse would, wherever the pane is (a covered one too). */
|
||||
async function open(page: Page, inPane: string, text: string, sel = ".row") {
|
||||
await pane(page, inPane).locator(sel, { hasText: text }).first().dispatchEvent("click");
|
||||
await still(page);
|
||||
}
|
||||
async function library(page: Page) {
|
||||
await autoLayout(page);
|
||||
await page.goto("/");
|
||||
await page.waitForSelector(".strip .pane");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every curve, with where it ends and what it lands in: its stroke's colour (RGB), its pane's
|
||||
* colour (RGB of the pane's --hue), whether the pane's own rule is left to the curve, and the rule's
|
||||
* and the tab foot's place on screen.
|
||||
*/
|
||||
const lines = (page: Page) =>
|
||||
page.evaluate(() => {
|
||||
const cx = document.createElement("canvas").getContext("2d")!;
|
||||
const rgb = (c: string) => {
|
||||
cx.clearRect(0, 0, 1, 1);
|
||||
cx.fillStyle = "#000";
|
||||
cx.fillStyle = c;
|
||||
cx.fillRect(0, 0, 1, 1);
|
||||
return [...cx.getImageData(0, 0, 1, 1).data.slice(0, 3)];
|
||||
};
|
||||
const svg = document.querySelector<SVGSVGElement>(".curves")!.getBoundingClientRect();
|
||||
const box = { left: Math.round(svg.left), top: Math.round(svg.top) };
|
||||
return [...document.querySelectorAll<SVGPathElement>(".curves path:not(.foot)")].map((p) => {
|
||||
const pe = document.querySelector<HTMLElement>(`.pane[data-tid="${p.dataset.to}"]`)!;
|
||||
const a = p.getPointAtLength(0);
|
||||
const b = p.getPointAtLength(p.getTotalLength());
|
||||
const head = pe.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 hr = head?.getBoundingClientRect();
|
||||
const pr = pe.getBoundingClientRect();
|
||||
const from = document.querySelector<HTMLElement>(`.pane[data-tid="${p.dataset.from}"]`)!.getBoundingClientRect();
|
||||
return {
|
||||
from: Number(p.dataset.from),
|
||||
to: Number(p.dataset.to),
|
||||
cls: p.getAttribute("class") ?? "",
|
||||
hue: p.dataset.hue ?? null,
|
||||
paneHue: pe.dataset.hue ?? null,
|
||||
kind: pe.classList.contains("wiki-pane") ? (pe.querySelector(".wiki-head .wsub") ? "article section" : "article") : pe.querySelector(":scope > .pane-scroll > .pane-body > .top") ? "page" : "section",
|
||||
stroke: rgb(getComputedStyle(p).stroke),
|
||||
colour: rgb(getComputedStyle(pe).getPropertyValue("--hue")),
|
||||
ownRule: head ? rgb(getComputedStyle(head).borderBottomColor) : null,
|
||||
ownRuleAlpha: head ? getComputedStyle(head).borderBottomColor : null,
|
||||
ruled: pe.dataset.ruled ?? "",
|
||||
focused: !!head?.closest(".focused"),
|
||||
scrolled: pe.hasAttribute("data-scrolled"),
|
||||
folded: pe.hasAttribute("data-covered"),
|
||||
start: { x: a.x + box.left, y: a.y + box.top },
|
||||
end: { x: b.x + box.left, y: b.y + box.top },
|
||||
rule: hr && { left: hr.left, right: hr.right, y: hr.bottom - 0.5 },
|
||||
foot: { y: pr.top + 29.5, left: pr.left, right: pr.right },
|
||||
fromFoot: { y: from.top + 29.5, right: from.right },
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test.use({ viewport: { width: 1920, height: 1080 }, colorScheme: "dark" });
|
||||
test.describe.configure({ mode: "serial" });
|
||||
test.beforeAll(async ({ request }) => {
|
||||
await seedLinks(request);
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
await context.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
});
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
const near = (a: number, b: number, d = 1) => Math.abs(a - b) <= d;
|
||||
/** Two colours alike, but for rounding (a colour at part strength, un-premultiplied, may differ by a unit or two). */
|
||||
const alike = (a: number[] | null, b: number[] | null) => !!a && !!b && a.every((v, i) => Math.abs(v - b[i]) <= 3);
|
||||
|
||||
test("every kind of pane's title rule is drawn by the curve into it, in the pane's colour: pages, sections, articles and their sections", async ({ page }) => {
|
||||
await library(page);
|
||||
for (const t of ["The tides", "Fixed points"]) await open(page, "Library", t);
|
||||
const seen = new Set<string>();
|
||||
const check = async () => {
|
||||
for (const l of await lines(page)) {
|
||||
if (!l.ruled.includes("head")) continue;
|
||||
seen.add(l.kind);
|
||||
expect(l.hue, `${l.kind} ${l.to}`).toBe(l.paneHue);
|
||||
expect(alike(l.stroke, l.colour), `${l.kind} ${l.to}: ${l.stroke} ${l.colour}`).toBe(true);
|
||||
// The curve runs on along the rule to its end, at its height; the pane's own rule is left out.
|
||||
expect(near(l.end.y, l.rule!.y), `${l.kind} y`).toBe(true);
|
||||
expect(near(l.end.x, l.rule!.right, 1.5), `${l.kind} x ${l.end.x} ${l.rule!.right}`).toBe(true);
|
||||
expect(l.ownRuleAlpha).toMatch(/rgba\(.*, 0\)|transparent/);
|
||||
}
|
||||
};
|
||||
await check();
|
||||
await open(page, "Fixed points", "Recursion without names");
|
||||
await check();
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
// The article's head holds the focus now (its rule is then the text's ink): put the focus back in the section.
|
||||
await pane(page, "Recursion without names").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
await check();
|
||||
await open(page, "Fixed-point combinator", "Y combinator", ".wrow .row");
|
||||
await expect(page.locator(".wiki-pane .wiki-head .wsub")).toHaveCount(1);
|
||||
await still(page);
|
||||
await check();
|
||||
expect([...seen].sort(), JSON.stringify((await lines(page)).map((l) => [l.kind, l.ruled, l.cls, l.folded, l.scrolled]))).toEqual(["article", "article section", "page", "section"]);
|
||||
// The two forks out of the library are two colours; the top node has none.
|
||||
expect(await pane(page, "Library").getAttribute("data-hue")).toBeNull();
|
||||
expect(await pane(page, "The tides").getAttribute("data-hue")).not.toBe(await pane(page, "Fixed points").getAttribute("data-hue"));
|
||||
expect(await pane(page, "Fixed points").getAttribute("data-hue")).not.toBeNull();
|
||||
});
|
||||
|
||||
test("a pane's colour is a function of the forest: unchanged by focus, a source scrolled out of sight, folding to a tab, or which way its rule is drawn", async ({ page }) => {
|
||||
await library(page);
|
||||
for (const t of ["Infinispand", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "Infinispand", "Expansion by depth");
|
||||
await open(page, "Fixed points", "The idea itself");
|
||||
const colourOf = async () => Object.fromEntries((await lines(page)).map((l) => [l.to, { stroke: l.stroke, colour: l.colour, hue: l.paneHue }]));
|
||||
const before = await colourOf();
|
||||
const same = async (what: string) => {
|
||||
for (const l of await lines(page)) {
|
||||
if (!before[l.to]) continue;
|
||||
expect(l.paneHue, `${what}: ${l.to}`).toBe(before[l.to].hue);
|
||||
expect(alike(l.stroke, before[l.to].colour), `${what}: ${l.to} curve`).toBe(true);
|
||||
// A rule the pane draws itself (no curve lands in it) is in the same colour.
|
||||
if (!l.ruled.includes("head") && l.ownRule && !l.ownRuleAlpha!.startsWith("rgb(241")) expect(alike(l.ownRule, before[l.to].colour), `${what}: ${l.to} own rule ${l.ownRule}`).toBe(true);
|
||||
}
|
||||
};
|
||||
for (const l of await lines(page)) expect(alike(l.stroke, l.colour)).toBe(true);
|
||||
// Focus on the other fork.
|
||||
await pane(page, "Expansion by depth").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
await same("focus moved");
|
||||
// The source row scrolled out of its pane: the curve is held at the pane's edge, dotted, and the pane draws its own rule.
|
||||
const fixed = pane(page, "Fixed points").locator(".pane-scroll");
|
||||
await fixed.evaluate((el) => (el.scrollTop = el.scrollHeight));
|
||||
await still(page);
|
||||
const idea = await tid(page, "The idea itself");
|
||||
const lost = (await lines(page)).find((l) => l.to === idea)!;
|
||||
expect(lost.cls).toContain("lost");
|
||||
expect(lost.ruled).toBe("");
|
||||
await same("source scrolled out");
|
||||
await fixed.evaluate((el) => (el.scrollTop = 0));
|
||||
await still(page);
|
||||
await same("source back");
|
||||
// Folded to tabs in a short window, and back.
|
||||
await page.setViewportSize({ width: 1920, height: 520 });
|
||||
await still(page);
|
||||
await same("folded");
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await still(page);
|
||||
await same("unfolded");
|
||||
});
|
||||
|
||||
test("the join of a curve and the rule it runs into is one stroke, on device pixels, at ratios 1, 1.25, 1.5, 2 and zoom 90 and 110 %", async ({ browser, request }) => {
|
||||
void request;
|
||||
for (const dpr of [1, 1.25, 1.5, 2, 0.9, 1.1]) {
|
||||
const ctx = await browser.newContext({ viewport: { width: 1920, height: 760 }, deviceScaleFactor: dpr, colorScheme: "dark" });
|
||||
await ctx.route(/wikipedia\.org|wikimedia\.org|stanford\.edu|example\.org/, (r) => r.abort());
|
||||
const page = await ctx.newPage();
|
||||
await library(page);
|
||||
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "The tides", "The force");
|
||||
// The focus to the last document, so The tides folds to its tab with its source out of sight.
|
||||
await pane(page, "Fixed points").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
const ls = await lines(page);
|
||||
const shot = pixels(await page.screenshot());
|
||||
const wd = Math.max(1, Math.floor(dpr + 0.01));
|
||||
const bg = (x: number, y: number) => shot.px(Math.round(x * dpr), Math.round((y - 8) * dpr));
|
||||
/** The device rows the line covers at x, near y: [row, brightness above the ground]. */
|
||||
const column = (x: number, y: number) => {
|
||||
const g = bg(x, y);
|
||||
const out: [number, number][] = [];
|
||||
for (let r = Math.floor((y - 3) * dpr); r <= Math.ceil((y + 3) * dpr); r++) {
|
||||
const p = shot.px(Math.round(x * dpr), r);
|
||||
const d = p.reduce((s, v, i) => s + Math.abs(v - g[i]), 0);
|
||||
if (d > 9) out.push([r, Math.round(d / 3)]);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
/** The same rows, as bright but for a unit or two of rounding. */
|
||||
const sameLine = (a: [number, number][], b: [number, number][]) => a.length === b.length && a.every(([r, v], i) => r === b[i][0] && Math.abs(v - b[i][1]) <= 2);
|
||||
const joins = ls.filter((l) => l.ruled.includes("head"));
|
||||
expect(joins.length, `dpr ${dpr}`).toBeGreaterThan(0);
|
||||
for (const l of joins) {
|
||||
const x0 = Math.max(l.rule!.left, l.end.x - 400);
|
||||
// Just inside the rule and further along it: the same rows, the same colour, and as many rows as a hairline has.
|
||||
const a = column(l.rule!.left + 3, l.rule!.y);
|
||||
const b = column((x0 + l.end.x) / 2, l.rule!.y);
|
||||
expect(sameLine(a, b), `dpr ${dpr} rule of ${l.to}: ${JSON.stringify([a, b])}`).toBe(true);
|
||||
expect(a.length, `dpr ${dpr} rows ${JSON.stringify(a)}`).toBe(wd);
|
||||
}
|
||||
// Out of a folded pane's tab: its foot and the curve on from it are one line.
|
||||
const out = ls.find((l) => near(l.start.y, l.fromFoot.y, 1) && l.start.x >= l.fromFoot.right - 3);
|
||||
expect(out, `dpr ${dpr}: a curve out of a tab's foot`).toBeTruthy();
|
||||
const f = column(out!.start.x - 6, out!.start.y);
|
||||
const c = column(out!.start.x + 2, out!.start.y);
|
||||
expect(sameLine(f, c), `dpr ${dpr} foot: ${JSON.stringify([f, c])}`).toBe(true);
|
||||
expect(f.length).toBe(wd);
|
||||
await ctx.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("a pane folded or scrolled past its title shows its tab, and its curve lands in the tab's foot; with its title in sight, in the title's rule", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 760 });
|
||||
await library(page);
|
||||
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "The tides", "The force");
|
||||
await pane(page, "Fixed points").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
let ls = await lines(page);
|
||||
let checked = 0;
|
||||
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) {
|
||||
const id = await tid(page, t);
|
||||
const l = ls.find((x) => x.to === id && x.from !== id);
|
||||
// Below the column's foot, a curve stops there, dotted.
|
||||
if (!l || l.cls.includes("lost") || l.focused) continue;
|
||||
checked++;
|
||||
const visible = await pane(page, t).evaluate((p) => {
|
||||
const h = p.querySelector<HTMLElement>(".top h1")!.getBoundingClientRect();
|
||||
const r = p.getBoundingClientRect();
|
||||
const next = (p.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity;
|
||||
const covered = p.hasAttribute("data-covered") || p.hasAttribute("data-scrolled");
|
||||
return h.bottom > r.top + (covered ? 30 : 0) + 4 && h.bottom < Math.min(next, p.parentElement!.getBoundingClientRect().bottom);
|
||||
});
|
||||
const info = JSON.stringify({ end: l.end, rule: l.rule, foot: l.foot, ruled: l.ruled, folded: l.folded, cls: l.cls, visible });
|
||||
if (visible) expect(near(l.end.y, l.rule!.y), `${t} into its title's rule ${info}`).toBe(true);
|
||||
else expect(near(l.end.y, l.foot.y), `${t} into its tab's foot ${info}`).toBe(true);
|
||||
}
|
||||
expect(checked).toBeGreaterThan(1);
|
||||
// A curve out of a folded pane leaves from the right end of its tab's foot, solid.
|
||||
const force = await tid(page, "The force");
|
||||
await expect(pane(page, "The tides")).toHaveAttribute("data-covered", "");
|
||||
ls = await lines(page);
|
||||
const out = ls.find((l) => l.to === force)!;
|
||||
expect(out.cls).not.toContain("lost");
|
||||
expect(near(out.start.y, out.fromFoot.y)).toBe(true);
|
||||
expect(near(out.start.x, out.fromFoot.right, 1.5)).toBe(true);
|
||||
|
||||
// A plain pane scrolled past its title: its tab at its top, the curve into its foot; back up, into the rule again.
|
||||
const sc = pane(page, "The force").locator(".pane-scroll");
|
||||
await sc.evaluate((el) => (el.scrollTop = 300));
|
||||
await expect(pane(page, "The force")).toHaveAttribute("data-scrolled", "");
|
||||
await still(page);
|
||||
expect(await pane(page, "The force").locator(".tabline").evaluate((el) => getComputedStyle(el).opacity)).toBe("1");
|
||||
let l = (await lines(page)).find((x) => x.to === force)!;
|
||||
expect(near(l.end.y, l.foot.y), `scrolled: ${l.end.y} ${l.foot.y}`).toBe(true);
|
||||
expect(l.ruled).toContain("tab");
|
||||
await sc.evaluate((el) => (el.scrollTop = 0));
|
||||
await expect(pane(page, "The force")).not.toHaveAttribute("data-scrolled", "");
|
||||
await still(page);
|
||||
l = (await lines(page)).find((x) => x.to === force)!;
|
||||
expect(near(l.end.y, l.rule!.y)).toBe(true);
|
||||
});
|
||||
|
||||
test("a pane covered across and down peeks out whole on both axes; the wheel scrolls it and it stays out; the selection bar of a pane under it is covered", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 760 });
|
||||
await library(page);
|
||||
for (const t of ["The tides", "What a proof is", "The invention of writing", "Fixed points"]) await open(page, "Library", t);
|
||||
await open(page, "Fixed points", "Recursion without names");
|
||||
await open(page, "Recursion without names", "fixed-point combinator", ".lnk, .anchor");
|
||||
await expect(pane(page, "Fixed-point combinator").locator(".wrow").first()).toBeVisible();
|
||||
await still(page);
|
||||
// The documents' column is covered to spines, and folded down: hover the spine of a folded pane in it.
|
||||
const col = pane(page, "The tides").locator("xpath=..");
|
||||
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
||||
const tides = pane(page, "The tides");
|
||||
await expect(tides).toHaveAttribute("data-covered", "");
|
||||
const tb = (await tides.boundingBox())!;
|
||||
const sp = { x: tb.x + 4, y: tb.y - 45, width: 20 };
|
||||
await page.mouse.move(sp.x + sp.width / 2, sp.y + 60);
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
const vp = page.viewportSize()!;
|
||||
const r = (await tides.boundingBox())!;
|
||||
const c = (await col.boundingBox())!;
|
||||
expect(r.width).toBeGreaterThan(600);
|
||||
expect(c.width).toBeGreaterThan(600);
|
||||
expect(r.y).toBeGreaterThanOrEqual(c.y - 1);
|
||||
expect(r.y + r.height).toBeLessThanOrEqual(Math.min(c.y + c.height, vp.height) + 1);
|
||||
// What is under the pointer is that pane, whole: the wheel scrolls its text, and it stays out.
|
||||
await page.mouse.move(r.x + r.width / 2, r.y + r.height / 2);
|
||||
await page.waitForTimeout(250);
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
const before = await tides.locator(".pane-scroll").evaluate((el) => el.scrollTop);
|
||||
await page.mouse.wheel(0, 240);
|
||||
await expect.poll(() => tides.locator(".pane-scroll").evaluate((el) => el.scrollTop)).toBeGreaterThan(before);
|
||||
await frames(page);
|
||||
await expect(tides).toHaveAttribute("data-peek", "");
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
// Away: back.
|
||||
await page.mouse.move(vp.width - 10, vp.height / 2);
|
||||
await expect(col).not.toHaveAttribute("data-peek", "");
|
||||
|
||||
// The selection bar: shown in its pane; a pane peeking over it covers it.
|
||||
const rec = pane(page, "Recursion without names");
|
||||
// A couple of words at the start of its text, dragged over: the bar sits by them, near the pane's left.
|
||||
const para = (await rec.locator(".pane-body .para").first().boundingBox())!;
|
||||
await page.mouse.move(para.x + 2, para.y + 10);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(para.x + 30, para.y + 10, { steps: 4 });
|
||||
await page.mouse.move(para.x + 60, para.y + 10, { steps: 4 });
|
||||
await page.mouse.up();
|
||||
const bar = page.locator(".selbar");
|
||||
await expect(bar).toBeVisible();
|
||||
expect(await bar.evaluate((el) => !!el.closest(".pane"))).toBe(true);
|
||||
const b = (await bar.boundingBox())!;
|
||||
const at = { x: b.x + b.width / 2, y: b.y + b.height / 2 };
|
||||
expect(await page.evaluate(({ x, y }) => !!document.elementFromPoint(x, y)?.closest(".selbar"), at)).toBe(true);
|
||||
// Peek the documents' column (to the left, covered): it slides out over the pane with the bar.
|
||||
await page.mouse.move(sp.x + sp.width / 2, sp.y + 60);
|
||||
await expect(col).toHaveAttribute("data-peek", "");
|
||||
const over = await page.evaluate(({ x, y }) => {
|
||||
const el = document.elementFromPoint(x, y);
|
||||
return { bar: !!el?.closest(".selbar"), peeked: !!el?.closest("[data-peek]") };
|
||||
}, at);
|
||||
const cb = (await col.boundingBox())!;
|
||||
expect(at.x).toBeLessThan(cb.x + cb.width);
|
||||
expect(over).toEqual({ bar: false, peeked: true });
|
||||
expect(await state(page, (s) => s.selectedText())).not.toBeNull();
|
||||
});
|
||||
+15
-12
@@ -301,11 +301,12 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
expect(start.y).toBeLessThan(link.y + link.height);
|
||||
await nearIn(kinds.locator(".node.forked > .row", { hasText: "Simple cells" }), edge("Two kinds of cell", "Simple cells")[0].a);
|
||||
const title = (t: string) => pane(page, t).locator(".wiki-head h2, .pane-head h2").first();
|
||||
// Each runs on into the rule under its pane's title: one line.
|
||||
// Each runs on into the rule under its pane's title and along it (drawing it): one line.
|
||||
for (const t of ["Eukaryote", "Simple cells", "Complex cells"]) {
|
||||
const end = edge("Two kinds of cell", t)[0].b;
|
||||
const r = (await pane(page, t).locator(".wiki-head, .pane-head").first().boundingBox())!;
|
||||
expect(Math.abs(end.x - r.x), t).toBeLessThan(2);
|
||||
expect(end.x, t).toBeGreaterThan(r.x + 100);
|
||||
expect(end.x, t).toBeLessThanOrEqual(r.x + r.width + 1);
|
||||
expect(Math.abs(end.y - (r.y + r.height - 0.5)), t).toBeLessThan(1.5);
|
||||
}
|
||||
await near('.wiki-pane .wiki-text a[data-wiki="Bacteria"]', edge("Eukaryote", "Bacteria")[0].a);
|
||||
@@ -334,8 +335,7 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
const now = edge("Two kinds of cell", "Simple cells")[0].b;
|
||||
const r = (await title("Simple cells").boundingBox())!;
|
||||
expect(Math.abs(now.x - was.x)).toBeGreaterThan(20);
|
||||
expect(now.x).toBeGreaterThan(r.x - 30);
|
||||
expect(now.x).toBeLessThanOrEqual(r.x + 2);
|
||||
expect(now.x).toBeGreaterThan(r.x);
|
||||
// And they can be turned off, and on again.
|
||||
await page.keyboard.press(":");
|
||||
await page.keyboard.type("/curves off");
|
||||
@@ -347,7 +347,7 @@ test("a curve per open edge, from where each pane was opened to its title; it fo
|
||||
await expect.poll(async () => (await curves(page)).length).toBeGreaterThan(3);
|
||||
});
|
||||
|
||||
test("each fork has a colour, shared by its curve and the rule under its title; the first trail is plain ink; /colors off takes them away", async ({ page }) => {
|
||||
test("each fork has a colour, shared by its curve and the rule under its title; a trail keeps its colour, the top node has none; /colors off takes them away", async ({ page }) => {
|
||||
await cells(page);
|
||||
const ids: Record<string, number> = {};
|
||||
for (const t of ["Two kinds of cell", "Eukaryote", "Simple cells", "Complex cells", "Bacteria"]) ids[t] = await tid(page, t);
|
||||
@@ -356,17 +356,20 @@ test("each fork has a colour, shared by its curve and the rule under its title;
|
||||
page.locator(`.curves path[data-to="${ids[to]}"]`).evaluate((el) => ({ stroke: getComputedStyle(el).stroke, hue: (el as SVGElement).dataset.hue }));
|
||||
const rule = (t: string) => pane(page, t).locator(".wiki-head, .pane-head").first().evaluate((el) => getComputedStyle(el).borderBottomColor);
|
||||
const hue = (t: string) => pane(page, t).getAttribute("data-hue");
|
||||
// Eukaryote went on from Two kinds of cell, Bacteria from it: the first trail, uncoloured. Simple and Complex cells are forks, each its own colour.
|
||||
for (const t of ["Two kinds of cell", "Eukaryote", "Bacteria"]) expect(await hue(t), t).toBeNull();
|
||||
expect((await curve("Eukaryote")).hue).toBeUndefined();
|
||||
expect(await hue("Simple cells")).not.toBeNull();
|
||||
// The library (the top node) has no colour; the trail down from it one, Eukaryote and Bacteria going on in it. Simple and Complex cells are forks, each its own colour.
|
||||
expect(await pane(page, "Library").getAttribute("data-hue")).toBeNull();
|
||||
for (const t of ["Eukaryote", "Bacteria"]) expect(await hue(t), t).toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Two kinds of cell")).not.toBeNull();
|
||||
expect((await curve("Eukaryote")).hue).toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Simple cells")).not.toBe(await hue("Two kinds of cell"));
|
||||
expect(await hue("Complex cells")).not.toBe(await hue("Simple cells"));
|
||||
// A curve and its pane's title rule: one colour, off the focused branch (Simple cells) or on it (Complex cells), and the two forks' differ.
|
||||
// The curve draws the rule under its pane's title (the pane's own is left out): one stroke, in the pane's colour.
|
||||
for (const t of ["Simple cells", "Complex cells"]) {
|
||||
expect((await curve(t)).hue).toBe(await hue(t));
|
||||
expect((await curve(t)).stroke, t).toBe(await rule(t));
|
||||
expect(await pane(page, t).getAttribute("data-ruled")).toBe("head");
|
||||
expect(await rule(t)).toBe("rgba(0, 0, 0, 0)");
|
||||
}
|
||||
expect(await rule("Simple cells")).not.toBe(await rule("Complex cells"));
|
||||
expect((await curve("Simple cells")).stroke).not.toBe((await curve("Complex cells")).stroke);
|
||||
expect((await curve("Simple cells")).stroke).not.toBe((await curve("Eukaryote")).stroke);
|
||||
// The active pane's heavy ink rule is as it was.
|
||||
expect(await page.locator(".pane.active").evaluate((el) => getComputedStyle(el, "::after").height)).toBe("3px");
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Wikipedia's fixtures in server/wikiMock.ts).
|
||||
*/
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { inflateSync } from "node:zlib";
|
||||
import type { APIRequestContext, Page } from "@playwright/test";
|
||||
|
||||
/** A keypress → paint timing, as the page records it. */
|
||||
@@ -119,3 +120,40 @@ export async function seedLinks(request: APIRequestContext) {
|
||||
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()}`);
|
||||
}
|
||||
|
||||
/** 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]] };
|
||||
}
|
||||
+192
-59
@@ -57,12 +57,50 @@ class Pane extends Component<PaneProps> {
|
||||
if (next.p.kind === "wiki") return true;
|
||||
return store.paneDirty(next.p.id) || !!store.targetOf(next.p.id) || store.linkedFrom(next.p.id).length > 0;
|
||||
}
|
||||
componentDidMount() {
|
||||
watchHead(this.props.t.id);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
watchHead(this.props.t.id);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
watched.get(this.props.t.id)?.io.disconnect();
|
||||
watched.delete(this.props.t.id);
|
||||
}
|
||||
render() {
|
||||
const p = this.props.p;
|
||||
return <PaneCtx.Provider value={this.props.t.id}>{p.kind === "node" ? <NodePane {...this.props} id={p.id} /> : <WikiPane {...this.props} />}</PaneCtx.Provider>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A pane scrolled past its title shows its tab at its top, as a folded one does (data-scrolled): an
|
||||
* observer on the title's rule, against the pane's own scroll box less the tab, so nothing is done
|
||||
* per scroll or per key, and the tab comes exactly as the rule goes under it.
|
||||
*/
|
||||
const watched = new Map<number, { io: IntersectionObserver; target: Element }>();
|
||||
function watchHead(tid: number) {
|
||||
const pane = document.querySelector<HTMLElement>(`.strip .pane[data-tid="${tid}"]`);
|
||||
if (!pane || typeof IntersectionObserver === "undefined") return;
|
||||
const scroll = pane.querySelector<HTMLElement>(":scope > .pane-scroll");
|
||||
const head = pane.querySelector<HTMLElement>(HEADS);
|
||||
const target = head?.matches(".top") ? head.querySelector("h1") : head;
|
||||
const w = watched.get(tid);
|
||||
if (w && w.target === target) return;
|
||||
w?.io.disconnect();
|
||||
watched.delete(tid);
|
||||
if (!target || !scroll) return void pane.removeAttribute("data-scrolled");
|
||||
const io = new IntersectionObserver(
|
||||
(es) => {
|
||||
const e = es[es.length - 1];
|
||||
setAttr(pane, "data-scrolled", !e.isIntersecting && !!e.rootBounds && e.boundingClientRect.height > 0 && e.boundingClientRect.bottom <= e.rootBounds.top + 1);
|
||||
},
|
||||
{ root: scroll, rootMargin: `-${TAB}px 0px 0px 0px` },
|
||||
);
|
||||
io.observe(target);
|
||||
watched.set(tid, { io, target });
|
||||
}
|
||||
|
||||
/** The attributes every pane has: which it is, its place in its tree, its id there, and its branch's colour (forks.ts; style.css draws it). */
|
||||
const paneAttrs = (props: PaneProps, name: string) => ({
|
||||
"data-pane": name,
|
||||
@@ -468,8 +506,8 @@ export function Panes() {
|
||||
const onScroll = (e: Event) => {
|
||||
const t = e.target as HTMLElement;
|
||||
if (t === el || t.classList?.contains("col")) measure();
|
||||
// What peeks is placed for where things were: put it back (one waiting to peek still may).
|
||||
if (peeked) hide();
|
||||
// A scroll inside what peeks (the wheel over it) keeps it out; any other moves things from under it.
|
||||
if (peeked.length && !peeked.some((p) => p !== t && p.contains(t)) && !(t === peeked[0] && peeked.length === 1 && !t.classList.contains("pane"))) hide();
|
||||
schedule();
|
||||
};
|
||||
const onResize = () => {
|
||||
@@ -493,53 +531,72 @@ export function Panes() {
|
||||
* foot, lifted into view; nothing else moves. A click makes it the active pane, which uncovers
|
||||
* it for good. Not for touch, the keyboard, or while dragging.
|
||||
*/
|
||||
let peeked: HTMLElement | null = null;
|
||||
/** What peeks (its column across, the pane down its column, or both) and the pane it is for. */
|
||||
let peeked: HTMLElement[] = [];
|
||||
let peekedFor: HTMLElement | null = null;
|
||||
let pending: HTMLElement | null = null;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const lower = (it: HTMLElement) => {
|
||||
it.removeAttribute("data-peek");
|
||||
it.style.transform = "";
|
||||
};
|
||||
function hide() {
|
||||
if (!peeked) return;
|
||||
peeked.removeAttribute("data-peek");
|
||||
peeked.style.transform = "";
|
||||
peeked = null;
|
||||
for (const it of peeked) lower(it);
|
||||
peeked = [];
|
||||
peekedFor = null;
|
||||
}
|
||||
function unpeek() {
|
||||
clearTimeout(timer);
|
||||
pending = null;
|
||||
hide();
|
||||
}
|
||||
const peekable = (pane: HTMLElement): HTMLElement | null => {
|
||||
/** What must come out for a pane to show whole: its column, if later columns cover it; the pane, if later panes in a crowded column do, or the column's foot cuts it. */
|
||||
const peekable = (pane: HTMLElement): HTMLElement[] => {
|
||||
const col = pane.parentElement as HTMLElement;
|
||||
if (col.hasAttribute("data-covered") || (col.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over")) return col;
|
||||
if (!col.classList.contains("crowded")) return null;
|
||||
const r = pane.getBoundingClientRect();
|
||||
const c = col.getBoundingClientRect();
|
||||
if (pane.hasAttribute("data-covered") || (pane.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over") || r.bottom > c.bottom + 1) return pane;
|
||||
return null;
|
||||
const out: HTMLElement[] = [];
|
||||
if (col.hasAttribute("data-covered") || (col.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over")) out.push(col);
|
||||
if (col.classList.contains("crowded")) {
|
||||
const r = pane.getBoundingClientRect();
|
||||
const c = col.getBoundingClientRect();
|
||||
if (pane.hasAttribute("data-covered") || (pane.nextElementSibling as HTMLElement | null)?.hasAttribute("data-over") || r.bottom > c.bottom + 1) out.push(pane);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const peek = (it: HTMLElement) => {
|
||||
peeked = it;
|
||||
it.setAttribute("data-peek", "");
|
||||
if (it.classList.contains("pane")) {
|
||||
const r = it.getBoundingClientRect();
|
||||
const c = (it.parentElement as HTMLElement).getBoundingClientRect();
|
||||
const dy = Math.max(c.top - r.top, Math.min(0, c.bottom - r.bottom));
|
||||
if (dy) it.style.transform = `translateY(${Math.round(dy)}px)`;
|
||||
const peek = (pane: HTMLElement, its: HTMLElement[]) => {
|
||||
peekedFor = pane;
|
||||
for (const it of its) {
|
||||
if (peeked.includes(it)) continue;
|
||||
peeked.push(it);
|
||||
it.setAttribute("data-peek", "");
|
||||
if (it === pane) {
|
||||
const r = it.getBoundingClientRect();
|
||||
const c = (it.parentElement as HTMLElement).getBoundingClientRect();
|
||||
const dy = Math.max(c.top - r.top, Math.min(0, c.bottom - r.bottom));
|
||||
if (dy) it.style.transform = `translateY(${Math.round(dy)}px)`;
|
||||
}
|
||||
}
|
||||
};
|
||||
const onMove = (e: PointerEvent) => {
|
||||
if (e.pointerType !== "mouse" || e.buttons || drag) return;
|
||||
const pane = (e.target as HTMLElement).closest<HTMLElement>(".pane");
|
||||
const it = pane && (pane === peeked || pane.parentElement === peeked ? peeked : peekable(pane));
|
||||
if (it === peeked && it) return;
|
||||
if (it === pending && it) return;
|
||||
unpeek();
|
||||
if (!it) return;
|
||||
pending = it;
|
||||
if (pane && (pane === peekedFor || pane === pending)) return;
|
||||
clearTimeout(timer);
|
||||
pending = null;
|
||||
const its = pane ? peekable(pane) : [];
|
||||
// Within a column that is out already: only the pane part changes.
|
||||
const col = pane?.parentElement as HTMLElement | undefined;
|
||||
if (col && peeked.includes(col)) {
|
||||
for (const it of peeked.filter((x) => x !== col)) lower(it);
|
||||
peeked = [col];
|
||||
peekedFor = pane;
|
||||
} else hide();
|
||||
if (!pane || !its.some((x) => !peeked.includes(x))) return;
|
||||
pending = pane;
|
||||
timer = setTimeout(() => {
|
||||
if (pending !== it) return;
|
||||
if (pending !== pane) return;
|
||||
pending = null;
|
||||
const pane = it.classList.contains("pane") ? it : it.querySelector<HTMLElement>(".pane");
|
||||
if (pane && peekable(pane)) peek(it);
|
||||
const now = peekable(pane);
|
||||
if (now.length) peek(pane, now);
|
||||
}, PEEK_MS);
|
||||
};
|
||||
el.addEventListener("pointermove", onMove);
|
||||
@@ -622,8 +679,8 @@ export function Panes() {
|
||||
e.preventDefault();
|
||||
};
|
||||
// A press elsewhere puts a peeking pane back; on it, the click goes through to it (and makes it the active pane), and then it goes back.
|
||||
const onPress = (e: PointerEvent) => !(peeked && peeked.contains(e.target as Node)) && unpeek();
|
||||
const afterClick = () => peeked && requestAnimationFrame(unpeek);
|
||||
const onPress = (e: PointerEvent) => !peeked.some((p) => p.contains(e.target as Node)) && unpeek();
|
||||
const afterClick = () => peeked.length && requestAnimationFrame(unpeek);
|
||||
el.addEventListener("pointerdown", onDown);
|
||||
el.addEventListener("pointerdown", onPress);
|
||||
el.addEventListener("click", afterClick);
|
||||
@@ -705,6 +762,8 @@ interface Edge {
|
||||
lost: boolean;
|
||||
/** The child's branch colour (forks.ts). */
|
||||
hue?: number;
|
||||
/** Where the curve runs on into the rule under the child's title (or its tab's foot), drawn here as part of the curve: from x0 to x1 at the arrival's height. */
|
||||
rule?: { x0: number; x1: number };
|
||||
}
|
||||
|
||||
/** A font's descent, by its CSS font string: where its baseline sits above the bottom of an inline box. */
|
||||
@@ -749,14 +808,29 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
if (!el || !svg) return;
|
||||
if (!store.settings.curves) {
|
||||
if (svg.firstChild) svg.replaceChildren();
|
||||
markRuled(paneEls(el), new Map());
|
||||
return;
|
||||
}
|
||||
const box = svg.getBoundingClientRect();
|
||||
// The curves' layer is painted from its box's whole pixel: positions are measured from there, so that a hairline set on device pixels lands on them.
|
||||
const sb = svg.getBoundingClientRect();
|
||||
const box = { left: Math.round(sb.left), top: Math.round(sb.top) };
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const els = paneEls(el);
|
||||
const colEls = [...el.children] as HTMLElement[];
|
||||
const branch = new Set(store.branchNodes.map((n) => n.id));
|
||||
// Coloured lines: a curve runs on into the rule under its pane's title (or its tab's), one line.
|
||||
// Coloured lines: a curve runs on into the rule under its pane's title (or its tab's foot), one line, the rule drawn here
|
||||
// with it (the pane's own rule left out, data-ruled) so that the two cannot differ by a pixel.
|
||||
const ruled = store.settings.colors === "line";
|
||||
// A hairline: one device pixel (two from a ratio of 2), its level runs on device pixels, as the page's borders are.
|
||||
const wd = Math.max(1, Math.floor(dpr + 0.01));
|
||||
const hair = `${wd / dpr}px`;
|
||||
if (svg.style.getPropertyValue("--hair") !== hair) svg.style.setProperty("--hair", hair);
|
||||
const level = (y: number) => (Math.round(y * dpr - wd / 2) + wd / 2) / dpr;
|
||||
const rules = new Map<number, string>();
|
||||
/** Tabs' feet that curves leave from, drawn with them. */
|
||||
const feet = new Map<number, { x0: number; x1: number; y: number; hue?: number; on: boolean }>();
|
||||
/** The panes whose tab's foot a curve into them draws already. */
|
||||
const tabbed = new Set<number>();
|
||||
const edges: Edge[] = [];
|
||||
for (const x of store.panesPlaced) {
|
||||
const parent = x.parent;
|
||||
@@ -773,15 +847,44 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
let ey: number;
|
||||
let ex = left + ARRIVE;
|
||||
let lost = false;
|
||||
if (ce.hasAttribute("data-covered")) ey = ruled ? cbox.top + TAB - 0.5 : cbox.top + TAB / 2;
|
||||
let rule: Edge["rule"];
|
||||
// What of the child shows: up to the next column where it covers it, down to the pane after it in a crowded column.
|
||||
const nextCol = colEls[colEls.indexOf(ccol) + 1]?.getBoundingClientRect().left ?? Infinity;
|
||||
const shownRight = Math.min(cbox.right, nextCol);
|
||||
// A pane folded down a crowded column shows its tab, and may still show its title under it.
|
||||
// A pane folded down a crowded column, or scrolled past its title, shows its tab (data-covered, data-scrolled).
|
||||
let folded = ce.hasAttribute("data-covered");
|
||||
if (ce.hasAttribute("data-buried")) ey = cbox.top + TAB / 2;
|
||||
else {
|
||||
const scroll = ce.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
// Under the tab, a rule does not show.
|
||||
const top = Math.max(cbox.top, scroll.top) + TAB;
|
||||
const t = ce.querySelector<HTMLElement>(".pane-head h2, .top h1, .wiki-head h2");
|
||||
const tr = t?.getBoundingClientRect();
|
||||
ey = tr && tr.bottom > scroll.top + 4 ? Math.max(scroll.top + 6, tr.top + Math.min(tr.height, 32) / 2) : scroll.top + 14;
|
||||
// The rule: a page title's own underline, a heading's under its head.
|
||||
const rr = ruled && t ? (t.matches("h1") ? tr : t.parentElement?.getBoundingClientRect()) : undefined;
|
||||
if (rr && rr.bottom > scroll.top + 4 && rr.bottom < scroll.bottom) (ey = rr.bottom - 0.5), (ex = Math.max(left + ARRIVE, rr.left));
|
||||
ey = folded ? cbox.top + TAB / 2 : tr && tr.bottom > scroll.top + 4 ? Math.max(scroll.top + 6, tr.top + Math.min(tr.height, 32) / 2) : scroll.top + 14;
|
||||
// The rule: under the pane's own head (a section's, a page's title, an article's), not an article's set under a node; and not while that head holds the focus (its rule is then the text's ink).
|
||||
const head = ruled ? ce.querySelector<HTMLElement>(HEADS) : null;
|
||||
const ruleEl = head?.matches(".top") ? head.querySelector<HTMLElement>("h1") : head;
|
||||
const rs = (ruleEl ?? ce.querySelector<HTMLElement>(".pane-head, .top h1, .wiki-head"))?.getBoundingClientRect();
|
||||
if (rs && rs.bottom <= top) {
|
||||
folded = true;
|
||||
ey = cbox.top + TAB / 2;
|
||||
}
|
||||
const rr = ruleEl && !head!.classList.contains("focused") ? rs : undefined;
|
||||
const below = ccol.classList.contains("crowded") ? ((ce.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top ?? Infinity) : Infinity;
|
||||
if (rr && rr.bottom > top + 4 && rr.bottom < Math.min(scroll.bottom, below) && rr.left < shownRight) {
|
||||
ey = level(rr.bottom - 0.5);
|
||||
ex = Math.max(left + ARRIVE, rr.left);
|
||||
rule = { x0: ex, x1: Math.min(rr.right, shownRight) };
|
||||
rules.set(x.node.id, "head");
|
||||
}
|
||||
}
|
||||
// Folded or scrolled so far that its title's rule does not show: into its tab's foot.
|
||||
if (folded && !rule && ruled) {
|
||||
ey = level(cbox.top + TAB - 0.5);
|
||||
rule = { x0: cbox.left, x1: Math.round(Math.min(cbox.right - 1, nextCol) * dpr) / dpr };
|
||||
rules.set(x.node.id, "tab");
|
||||
tabbed.add(x.node.id);
|
||||
}
|
||||
if (ey > ccolBox.bottom - 4) {
|
||||
ey = ccolBox.bottom - 4;
|
||||
@@ -789,27 +892,33 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
}
|
||||
// Where it starts: the words, row or link it was opened from. The text's edge: the pane's right padding, or the next column where it covers the pane.
|
||||
const pbox = pe.getBoundingClientRect();
|
||||
const textRight = Math.min(pbox.right - 33, left - 2);
|
||||
let textRight = Math.min(pbox.right - 33, left - 2);
|
||||
let sx = textRight;
|
||||
let sy: number;
|
||||
let under: { x: number; y: number } | undefined;
|
||||
if (pe.hasAttribute("data-covered")) {
|
||||
sy = pbox.top + TAB / 2;
|
||||
lost = true;
|
||||
} else {
|
||||
// What of the pane shows: its own scroll box, less what the pane after it in a crowded column covers, down to the column's foot.
|
||||
const box = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const nextTop = pcol.classList.contains("crowded") ? (pe.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top : undefined;
|
||||
const sc = { top: box.top, bottom: Math.min(box.bottom, nextTop ?? Infinity, pcol.getBoundingClientRect().bottom) };
|
||||
const cands = pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
let src: HTMLElement | undefined;
|
||||
for (const c of cands) {
|
||||
const r = c.getBoundingClientRect();
|
||||
if (r.height && r.bottom > sc.top && r.top < sc.bottom) {
|
||||
src = c;
|
||||
break;
|
||||
}
|
||||
// What of the pane shows: its own scroll box (below its tab, if folded), less what the pane after it in a crowded column covers, down to the column's foot.
|
||||
const pfolded = pe.hasAttribute("data-covered");
|
||||
const pscroll = pe.querySelector<HTMLElement>(".pane-scroll")!.getBoundingClientRect();
|
||||
const nextTop = pcol.classList.contains("crowded") ? (pe.nextElementSibling as HTMLElement | null)?.getBoundingClientRect().top : undefined;
|
||||
const sc = { top: pfolded ? Math.max(pscroll.top, pbox.top + TAB) : pscroll.top, bottom: Math.min(pscroll.bottom, nextTop ?? Infinity, pcol.getBoundingClientRect().bottom) };
|
||||
const cands = pe.hasAttribute("data-buried") ? [] : pe.querySelectorAll<HTMLElement>(`.${kidClass(refKey(x.node.ref))}`);
|
||||
let src: HTMLElement | undefined;
|
||||
for (const c of cands) {
|
||||
const r = c.getBoundingClientRect();
|
||||
if (r.height && r.bottom > sc.top + 2 && r.top < sc.bottom - 2) {
|
||||
src = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pfolded && !src) {
|
||||
// Folded with its source out of sight: out of the right end of its tab's foot, carrying that line on (its foot drawn here too, so they join exactly).
|
||||
const footRight = Math.round(Math.min(pbox.right - 1, left) * dpr) / dpr;
|
||||
sy = level(pbox.top + TAB - 0.5);
|
||||
sx = footRight;
|
||||
// A few pixels straight on before it turns, so the foot runs on visibly.
|
||||
textRight = footRight + 6;
|
||||
if (ruled) feet.set(parent.id, { x0: pbox.left - box.left, x1: footRight - box.left, y: sy - box.top, hue: parent.hue, on: branch.has(parent.id) });
|
||||
} else {
|
||||
src ??= cands[0];
|
||||
const head = pe.querySelector<HTMLElement>(".pane-head h2, .top h1, .wiki-head h2");
|
||||
const s = src ?? head;
|
||||
@@ -835,9 +944,18 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
sx = textRight;
|
||||
sy = Math.max(sc.top + 2, Math.min(sc.bottom - 2, sy));
|
||||
}
|
||||
sy = level(sy);
|
||||
if (under) under.y = level(under.y);
|
||||
}
|
||||
if (ruled && feet.has(parent.id) && !rules.get(parent.id)?.includes("tab")) rules.set(parent.id, rules.has(parent.id) ? "head tab" : "tab");
|
||||
// A curve that cannot reach its pane (dotted) leaves the pane's own rule as it is.
|
||||
if (lost && rule) {
|
||||
rule = undefined;
|
||||
rules.delete(x.node.id);
|
||||
tabbed.delete(x.node.id);
|
||||
}
|
||||
const gutter = colEls.indexOf(ccol);
|
||||
edges.push({ from: parent.id, to: x.node.id, gutter, left: left - box.left, sx: sx - box.left, sy: sy - box.top, under: under && { x: under.x - box.left, y: under.y - box.top }, textRight: textRight - box.left, ex: ex - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost, hue: x.node.hue });
|
||||
edges.push({ from: parent.id, to: x.node.id, gutter, left: left - box.left, sx: sx - box.left, sy: sy - box.top, under: under && { x: under.x - box.left, y: under.y - box.top }, textRight: textRight - box.left, ex: ex - box.left, ey: ey - box.top, on: branch.has(x.node.id) && branch.has(parent.id), lost, hue: x.node.hue, rule: rule && { x0: rule.x0 - box.left, x1: rule.x1 - box.left } });
|
||||
}
|
||||
// Lanes, gutter by gutter.
|
||||
const lane = new Map<Edge, number>();
|
||||
@@ -853,8 +971,9 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
order.forEach((o, i) => lane.set(o.e, Math.min(i, LANES - 1)));
|
||||
}
|
||||
for (const g of [...lanesUsed.keys()]) if (!gutters.has(g)) lanesUsed.delete(g);
|
||||
const fx = (n: number) => Math.round(n * 2) / 2;
|
||||
const fx = (n: number) => Math.round(n * 1000) / 1000;
|
||||
const out: { key: string; from: number; to: number; lane: number; cls: string; d: string; hue: string }[] = [];
|
||||
for (const [id, f] of feet) if (!tabbed.has(id)) out.push({ key: `foot:${id}`, from: id, to: -1, lane: -1, cls: f.on ? "foot on" : "foot", d: `M${fx(f.x0)} ${fx(f.y)}H${fx(f.x1)}`, hue: f.hue === undefined ? "" : String(f.hue) });
|
||||
edges.sort((a, b) => Number(a.on) - Number(b.on));
|
||||
for (const e of edges) {
|
||||
const i = lane.get(e)!;
|
||||
@@ -877,6 +996,8 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
`C${fx(g)} ${fx(e.ey - sg * r2 * (1 - k))} ${fx(g + r2 - k * r2)} ${fx(e.ey)} ${fx(g + r2)} ${fx(e.ey)}` +
|
||||
`H${fx(e.ex)}`;
|
||||
}
|
||||
// On into the rule: one path, so one stroke (where its foot runs back under the turn, a stroke covers once).
|
||||
if (e.rule) d += e.rule.x0 < e.ex - 0.01 ? `M${fx(e.rule.x0)} ${fx(e.ey)}H${fx(e.rule.x1)}` : `H${fx(e.rule.x1)}`;
|
||||
out.push({ key: `${e.from}>${e.to}`, from: e.from, to: e.to, lane: i, cls: `${e.on ? "on" : ""}${e.lost ? " lost" : ""}`, d, hue: e.hue === undefined ? "" : String(e.hue) });
|
||||
}
|
||||
// Each curve keeps its element, changed only where it changed, so only what moved is painted again.
|
||||
@@ -899,4 +1020,16 @@ function curves(el: HTMLElement | null, svg: SVGSVGElement | null) {
|
||||
if (svg.children[k] !== p) svg.insertBefore(p, svg.children[k] ?? null);
|
||||
});
|
||||
for (const p of had.values()) p.remove();
|
||||
markRuled(els, rules);
|
||||
}
|
||||
|
||||
/** A pane's own head, whose rule a curve into it lands in: a section's, a page's title, an article's (not an article set under a node). */
|
||||
const HEADS = ":scope > .pane-scroll > .pane-body > .pane-head, :scope > .pane-scroll > .pane-body > .top, :scope > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head";
|
||||
|
||||
/** Which panes' rules a curve draws (head or tab), so that their own are left out. */
|
||||
function markRuled(els: Map<number, HTMLElement>, rules: Map<number, string>) {
|
||||
for (const [id, p] of els) {
|
||||
const v = rules.get(id);
|
||||
if ((p.getAttribute("data-ruled") ?? undefined) !== v) v ? p.setAttribute("data-ruled", v) : p.removeAttribute("data-ruled");
|
||||
}
|
||||
}
|
||||
+35
-14
@@ -417,6 +417,10 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
.tabline .tabtitle { overflow: hidden; text-overflow: ellipsis; }
|
||||
.tabline:hover { color: var(--fg); }
|
||||
.col.crowded > .pane[data-covered] > .tabline { opacity: 1; pointer-events: auto; }
|
||||
/* A pane scrolled past its own title shows its tab at its top as well, over its text (Panes.tsx watchHead). */
|
||||
.pane[data-scrolled] > .tabline { opacity: 1; pointer-events: auto; }
|
||||
.pane[data-scrolled] > .pane-ctl { top: 2px; }
|
||||
.pane[data-scrolled] > .grip { display: none; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tabline { transition: none; }
|
||||
}
|
||||
@@ -427,6 +431,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
/* Peeking: a covered pane or column, the mouse resting on it, raised over its neighbours whole. */
|
||||
.col[data-peek], .pane[data-peek] { z-index: 6; box-shadow: 0 3px 18px 0 var(--shade); }
|
||||
.col[data-peek] .spine, .col.crowded > .pane[data-peek] > .tabline { opacity: 0; pointer-events: none; }
|
||||
/* The wheel over what peeks scrolls its text, not the column under it. */
|
||||
.col[data-peek] .pane-scroll, .pane[data-peek] > .pane-scroll { overscroll-behavior: contain; }
|
||||
|
||||
/* Dragging a pane in its column: its grip, quiet until pointed at; the line where it will go. */
|
||||
.grip { position: absolute; z-index: 3; top: 0; left: var(--spine); right: 4.6rem; height: 1.15rem; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
|
||||
@@ -458,7 +464,7 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
|
||||
/* The curves: from what each pane was opened from to its title, behind nothing but in the gaps between lines. */
|
||||
/* A layer of its own, so that drawing a curve again does not paint the panes under it again. */
|
||||
.curves { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: hidden; will-change: transform; }
|
||||
.curves { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: hidden; }
|
||||
.curves path { fill: none; stroke: var(--curve); stroke-width: 1; }
|
||||
.curves path.on { stroke: var(--curve-on); }
|
||||
.curves path.lost { stroke-dasharray: 1 3; }
|
||||
@@ -479,7 +485,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
--hue-4: oklch(60% 0.1 210);
|
||||
--hue-5: oklch(60% 0.1 120);
|
||||
--hue-6: oklch(60% 0.1 255);
|
||||
--curve-ink: rgb(0 0 0 / 0.42);
|
||||
/* The first trail's, near the text's ink. */
|
||||
--hue-none: oklch(50% 0 0);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
@@ -490,9 +497,10 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
--hue-4: oklch(74% 0.085 210);
|
||||
--hue-5: oklch(74% 0.085 120);
|
||||
--hue-6: oklch(74% 0.085 255);
|
||||
--curve-ink: rgb(255 255 255 / 0.42);
|
||||
--hue-none: oklch(80% 0 0);
|
||||
}
|
||||
}
|
||||
:where(.pane, .curves path) { --hue: var(--hue-none); }
|
||||
[data-hue="0"] { --hue: var(--hue-0); }
|
||||
[data-hue="1"] { --hue: var(--hue-1); }
|
||||
[data-hue="2"] { --hue: var(--hue-2); }
|
||||
@@ -501,15 +509,28 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
[data-hue="5"] { --hue: var(--hue-5); }
|
||||
[data-hue="6"] { --hue: var(--hue-6); }
|
||||
/* Fainter off the focused branch. Both are fixed per pane, so moving the branch changes no custom property (which every element in the pane would inherit). */
|
||||
[data-hue] { --hue-faint: color-mix(in oklab, var(--hue) 70%, transparent); }
|
||||
.panes:not([data-colors="off"]) .curves path[data-hue] { stroke: var(--hue-faint); }
|
||||
.panes:not([data-colors="off"]) .curves path.on[data-hue] { stroke: var(--hue); }
|
||||
.panes:not([data-colors="off"]) .curves path.on:not([data-hue]) { stroke: var(--curve-ink); }
|
||||
/* line */
|
||||
[data-colors="line"] .pane[data-hue] > .pane-scroll > .pane-body > :is(.pane-head:not(.focused), .top:not(.focused) h1, .wiki:not(.embedded) > .wiki-head:not(.focused)),
|
||||
[data-colors="line"] .pane[data-hue] > .tabline { border-bottom-color: var(--hue-faint); }
|
||||
[data-colors="line"] .pane.on-branch[data-hue] > .pane-scroll > .pane-body > :is(.pane-head:not(.focused), .top:not(.focused) h1, .wiki:not(.embedded) > .wiki-head:not(.focused)),
|
||||
[data-colors="line"] .pane.on-branch[data-hue] > .tabline { border-bottom-color: var(--hue); }
|
||||
.pane, .curves path { --hue-faint: color-mix(in oklab, var(--hue) 70%, transparent); }
|
||||
.panes:not([data-colors="off"]) .curves path { stroke: var(--hue-faint); stroke-width: var(--hair, 1px); }
|
||||
.panes:not([data-colors="off"]) .curves path.on { stroke: var(--hue); }
|
||||
/*
|
||||
* line: the curve runs on into the rule under the pane's title, or its tab's foot, and draws that
|
||||
* rule itself (Panes.tsx curves; the pane's own is left out, data-ruled), so the two are one stroke.
|
||||
* Where no curve lands (curves off, a covered source), the pane's own rule takes its colour.
|
||||
*/
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .pane-head:not(.focused),
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .top:not(.focused) h1,
|
||||
:where([data-colors="line"] .pane[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head:not(.focused),
|
||||
:where([data-colors="line"] .pane[data-hue]) > .tabline { border-bottom-color: var(--hue-faint); }
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .pane-head:not(.focused),
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .top:not(.focused) h1,
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head:not(.focused),
|
||||
:where([data-colors="line"] .pane.on-branch[data-hue]) > .tabline { border-bottom-color: var(--hue); }
|
||||
.pane[data-ruled~="head"] > .pane-scroll > .pane-body > .pane-head,
|
||||
.pane[data-ruled~="head"] > .pane-scroll > .pane-body > .top h1,
|
||||
.pane[data-ruled~="head"] > .pane-scroll > .pane-body > .wiki:not(.embedded) > .wiki-head,
|
||||
.pane[data-ruled~="tab"] > .tabline { border-bottom-color: transparent; }
|
||||
/* Under a tab's foot drawn by a curve, the stacked pane's own top edge would double it. */
|
||||
.col.crowded > .pane[data-ruled~="tab"] + .pane[data-over]::before { background: transparent; }
|
||||
[data-colors="line"] .pane[data-hue] > .spine::before { content: ""; position: absolute; top: 1.72rem; left: 50%; width: 0.9rem; margin-left: -0.45rem; height: 1px; background: var(--hue-faint); }
|
||||
[data-colors="line"] .pane.on-branch[data-hue] > .spine::before { background: var(--hue); }
|
||||
.col.crowded > .pane[data-covered] > .spine::before { display: none; }
|
||||
@@ -795,6 +816,8 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
background: var(--bg); border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); transform: rotate(45deg);
|
||||
}
|
||||
.selbar.below::after { bottom: auto; top: -5px; transform: rotate(225deg); }
|
||||
/* In the panes view the bar is set in its pane, so a pane or column over that pane covers it too. */
|
||||
.pane > .selbar { position: absolute; }
|
||||
|
||||
/* The ⋯ by a row, a pane's head, a page's head or a note: invisible until wanted, never moving the text. */
|
||||
.more {
|
||||
@@ -816,8 +839,6 @@ kbd, .help code { font-family: var(--mono); font-size: 0.86em; border: 1px solid
|
||||
:is(.sidenote, .inset) > .more { position: absolute; top: 0.15rem; right: 0.15rem; margin: 0; font-size: 0.82rem; }
|
||||
.inset { position: relative; }
|
||||
/* A pane's own ⋯ stands for its page's. */
|
||||
/* In the panes view the bar is set in its pane, so a pane or column over that pane covers it too. */
|
||||
.pane > .selbar { position: absolute; }
|
||||
.pane .top .more { display: none; }
|
||||
.pane-btn.more { display: flex; align-items: center; justify-content: center; padding: 0; font-family: var(--sans); font-size: 0.8rem; line-height: 1; letter-spacing: 0.04em; }
|
||||
.pane-btn.more[aria-expanded="true"] { color: var(--fg); background: var(--sel); }
|
||||
|
||||
Reference in new issue
Block a user