Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.
JavaScript ai-codingclaudeclaude-codeclaude-code-pluginclicoding-agentsdeveloper-toolsgitllmtypescript
feat(map): one scroller, content column and readable rows
Eren05541b098f9a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6237e28..7af97b8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Changed+- Map layout and readability: the head and the map share a centred 8-of-12 content column (full width with 16 px gutters below 1100 px), the page itself no longer scrolls so the head stays put and the map fills the rest of the window, and a wheel anywhere on the page — gutters and head included — pans the map (Ctrl+wheel still zooms, Shift+wheel pans horizontally). A message title keeps a minimum width, so the branch and "continues" chips truncate with an ellipsis instead of squeezing it into a one-letter column. Small text (dates, `mN`, counts, "not summarized yet") now reaches WCAG AA contrast, and the map has a light theme for browsers that ask for one.- Renamed the product to **cogit** (*Cogito, ergo commit.*): the npm package and `cogit` bin, the Claude Code plugin and its `cogit:record` skill, the project dir `.cogit/`, the global dir `~/.config/cogit`, the env vars `COGIT_HOME` / `COGIT_DISABLE` (the old names still work for one minor version), the map file `map.html` and the page titles. The first cogit command or hook migrates silently: it renames an existing `.codelineage/`, moves `~/.config/codelineage` and fixes the `.gitignore` lines, or leaves both in place and warns once when both directories exist.## [0.10.0] - 2026-10-26diff --git a/packages/template/src/App.tsx b/packages/template/src/App.tsxindex 4832e08..82804f8 100644--- a/packages/template/src/App.tsx+++ b/packages/template/src/App.tsx@@ -50,7 +50,7 @@ export function App({ model }: { model: LineageViewModel }) {}return (- <main>+ <main className="map-page"><div className="page-head"><div className="page-bar"><ProjectSwitcher model={model} />diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsxindex 565dfaf..ac20caa 100644--- a/packages/template/src/Graph.tsx+++ b/packages/template/src/Graph.tsx@@ -22,6 +22,7 @@ import type { MapSearchState } from "./MapSearch.js";import { Outline, type OutlineTarget } from "./Outline.js";import { OPEN_LINK_DROP, SessionMap } from "./SessionMap.js";import { DrillDown, type Selection } from "./SidePanel.js";+import { usePageWheel } from "./scroll.js";import { layoutSessionGraph, type SessionGraph } from "./sessionLayout.js";/**@@ -195,6 +196,8 @@ function findSession(model: LineageViewModel, id: string): ViewSession | undefin}function Flow({ model, search }: { model: LineageViewModel; search: MapSearchState }) {+ // One scroller (Story 9.2): a wheel outside the map moves the map.+ usePageWheel();// Read once: a live data swap must not move the page back to the hash target.const [initial] = useState(() => readTarget(model));useEffect(() => {@@ -641,6 +644,12 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta);}+/** A theme colour for an SVG attribute (the minimap cannot read CSS variables). */+function cssVar(name: string, fallback: string): string {+ if (typeof window === "undefined") return fallback;+ return getComputedStyle(document.documentElement).getPropertyValue(name).trim() || fallback;+}+/*** One React Flow canvas for the whole map. It frames the map once on load (or* centres a deep-linked message); opening or closing a session and live data@@ -747,10 +756,15 @@ function MapCanvas({nodesDraggable={false}nodesConnectable={false}elementsSelectable={false}- colorMode="dark"+ colorMode="system"><Background gap={24} size={1} color="#242a36" />- <MiniMap pannable zoomable nodeColor={() => "#243040"} />+ <MiniMap+ pannable+ zoomable+ nodeColor={() => cssVar("--active", "#243040")}+ maskColor={`${cssVar("--bg", "#0f1115")}b3`}+ /><Controls showInteractive={false} /></ReactFlow>);diff --git a/packages/template/src/gitLayout.ts b/packages/template/src/gitLayout.tsindex 12de631..ca0c2c9 100644--- a/packages/template/src/gitLayout.ts+++ b/packages/template/src/gitLayout.ts@@ -54,6 +54,13 @@ const LANE_TAIL = 6;/** Width reserved for the row text right of the dots. */export const ROW_WIDTH = 520;const ROW_GAP = 8;+/**+ * The narrowest a title may get (Story 9.2). The chips around it shrink or+ * truncate instead, so a row with a branch label and a "continues" mark never+ * squeezes its title into a one-letter column. `styles.css` pins the same+ * value on `.git-title`; a test keeps the two in step.+ */+export const TITLE_MIN_WIDTH = 180;/** How many lane colours the page defines (`--l0` … `--l5`). */export const LANE_COLORS = 6;@@ -269,7 +276,7 @@ export function rowHeight((message.unsummarized ? 116 : 0) +// The "↑ continues <session> · m67" mark sits in the row, next to the title.(message.continues ? 150 + message.continues.sessionTitle.length * 6.4 : 0);- const room = Math.max(120, rowWidth - fixed);+ const room = Math.max(TITLE_MIN_WIDTH, rowWidth - fixed);const titleLines = Math.max(1, Math.ceil((message.title.length * TITLE_CHAR) / room));const branchLines = row.first? Math.max(1, Math.ceil((row.branchTitle.length * BRANCH_CHAR) / (BRANCH_MAX - 12)))diff --git a/packages/template/src/scroll.ts b/packages/template/src/scroll.tsnew file mode 100644index 0000000..2ac8135--- /dev/null+++ b/packages/template/src/scroll.ts@@ -0,0 +1,71 @@+import { useEffect } from "react";++/**+ * One scroller (Story 9.2). The page itself never scrolls: the head stays put+ * and the map fills the rest of the window. A wheel over the gutters, the head+ * or the toolbar therefore has nothing to scroll, so it is forwarded to the+ * map. Inside the map React Flow already handles the wheel (vertical pan,+ * Shift+wheel horizontal, Ctrl+wheel zoom), and views that scroll on their own+ * (the drill-down, the outline, the files list, the dialogs) keep their wheel.+ */++/** Parts of the page that own their wheel events. */+const OWN_WHEEL_SELECTOR =+ ".react-flow, .settings-overlay, .switcher-overlay, .drilldown, .outline, .files-view";++/** React Flow puts its d3-zoom wheel listener on the renderer element. */+export const PANE_SELECTOR = ".react-flow__renderer";++/**+ * Whether a wheel event over `target` should move the map. Anything inside the+ * map or one of the page's own scrollers decides for itself; the rest of the+ * page is dead space and belongs to the map. A target without `closest` (the+ * document or window) counts as dead space too.+ */+export function shouldForwardWheel(target: EventTarget | null): boolean {+ const element = target as Element | null;+ if (element === null || typeof element.closest !== "function") return true;+ return element.closest(OWN_WHEEL_SELECTOR) === null;+}++/**+ * Re-sends a wheel event to the map. The clone keeps the deltas and the+ * modifier keys, so Ctrl+wheel still zooms and Shift+wheel still pans+ * horizontally; the pointer position is kept for the zoom point. The clone is+ * dispatched on the map, so when it bubbles back to the window listener its+ * target reads as inside the map and it is not forwarded again.+ */+export function forwardWheel(event: WheelEvent, pane: Element): void {+ event.preventDefault();+ pane.dispatchEvent(+ new WheelEvent("wheel", {+ bubbles: true,+ cancelable: true,+ composed: true,+ deltaX: event.deltaX,+ deltaY: event.deltaY,+ deltaMode: event.deltaMode,+ ctrlKey: event.ctrlKey,+ shiftKey: event.shiftKey,+ altKey: event.altKey,+ metaKey: event.metaKey,+ clientX: event.clientX,+ clientY: event.clientY,+ }),+ );+}++/** The page's wheel listener: forwards every wheel outside the map's own scrollers. */+export function onPageWheel(event: WheelEvent): void {+ if (!shouldForwardWheel(event.target)) return;+ const pane = document.querySelector(PANE_SELECTOR);+ if (pane) forwardWheel(event, pane);+}++/** Installs the page-wheel listener for as long as the map is mounted. */+export function usePageWheel(): void {+ useEffect(() => {+ window.addEventListener("wheel", onPageWheel, { passive: false });+ return () => window.removeEventListener("wheel", onPageWheel);+ }, []);+}diff --git a/packages/template/src/styles.css b/packages/template/src/styles.cssindex 729eb4c..1cbf8d2 100644--- a/packages/template/src/styles.css+++ b/packages/template/src/styles.css@@ -4,7 +4,7 @@--panel: #171a21;--line: #2a2f3a;--text: #e6e8ee;- --muted: #8b93a7;+ --muted: #9aa3b7;--accent: #7aa2f7;--warn: #e0af68;/* Branch lanes in the git graph (Story 8.2). */@@ -14,12 +14,88 @@--l3: #bb9af7;--l4: #7dcfff;--l5: #f7768e;+ /* Surfaces (Story 9.2): named once so a light theme can repaint them. */+ --raised: #1a1e27;+ --raised-2: #151922;+ --row-bg: #12151b;+ --hover: #1d222c;+ --active: #243040;+ --chip-bg: #1c222e;+ --chip-line: #323b4d;+ --kind-bg: #242a36;+ --kind-decision-bg: #2b2440;+ --kind-decision-text: #c0a8ff;+ --kind-question-bg: #3a2f1d;+ --kind-message-bg: #23331d;+ --kind-message-text: #9ece6a;+ --missing: #a2abbf;+ --search-hit-bg: #2b2724;+ --search-active-bg: #373129;+ --on-lane: #0f1115;+ --translucent-panel: rgba(20, 23, 30, 0.97);+ --translucent-outline: rgba(17, 20, 26, 0.94);+ --overlay: rgba(5, 7, 10, 0.62);+ --shadow: rgba(0, 0, 0, 0.5);+}++/* The same map in a light browser (Story 9.2). Small text keeps WCAG AA in+ both palettes; `layout.test.ts` computes the ratios. */+@media (prefers-color-scheme: light) {+ :root {+ color-scheme: light;+ --bg: #fbfbfd;+ --panel: #f2f4f8;+ --line: #d5dae4;+ --text: #1b2230;+ --muted: #545e72;+ --accent: #2957c8;+ --warn: #8a5300;+ --l0: #2957c8;+ --l1: #2f7d32;+ --l2: #8a5300;+ --l3: #6f42c1;+ --l4: #0b6e99;+ --l5: #b3261e;+ --raised: #e9edf5;+ --raised-2: #eef1f7;+ --row-bg: #f4f6fa;+ --hover: #e6ebf5;+ --active: #d9e3f7;+ --chip-bg: #e8edf5;+ --chip-line: #c2cbdb;+ --kind-bg: #e4e8f0;+ --kind-decision-bg: #ece4ff;+ --kind-decision-text: #5b3aa8;+ --kind-question-bg: #fbf0dc;+ --kind-message-bg: #e7f3e1;+ --kind-message-text: #2a7430;+ --missing: #4f586b;+ --search-hit-bg: #e7e2dc;+ --search-active-bg: #e1d9cd;+ --on-lane: #ffffff;+ --translucent-panel: rgba(255, 255, 255, 0.97);+ --translucent-outline: rgba(246, 248, 251, 0.96);+ --overlay: rgba(20, 26, 38, 0.35);+ --shadow: rgba(20, 30, 50, 0.18);+ }}* {box-sizing: border-box;}+html,+body,+#root {+ height: 100%;+}++/* One scroller (Story 9.2): on the map page the map is what moves, not the+ document; the panel and report pages still scroll normally. */+body:has(.map-page) {+ overflow: hidden;+}+body {margin: 0;background: var(--bg);@@ -36,6 +112,47 @@ main {padding: 32px 24px 64px;}+/* The map page: head on top, map fills the rest of the window. */+main.map-page {+ display: flex;+ flex-direction: column;+ height: 100%;+ padding: 20px 0 16px;+}++/* An 8-of-12 content column, centred, with empty gutters on both sides. */+.map-page .page-head,+.map-page .lineage-map {+ width: 66.667%;+ margin-right: auto;+ margin-left: auto;+}++.map-page .page-head {+ flex: none;+}++.map-page .lineage-map {+ display: flex;+ flex: 1 1 auto;+ flex-direction: column;+ min-height: 0;+ margin-top: 8px;+ padding: 0;+}++@media (max-width: 1100px) {+ main.map-page {+ padding-right: 16px;+ padding-left: 16px;+ }++ .map-page .page-head,+ .map-page .lineage-map {+ width: 100%;+ }+}+/* The head spans the window like the map below it. */.page-head {margin: 0;@@ -73,7 +190,7 @@ main {color: var(--text);font: inherit;font-size: 13px;- background: #1a1e27;+ background: var(--raised);border: 1px solid var(--line);border-radius: 7px;}@@ -98,7 +215,7 @@ main {color: var(--muted);font: inherit;font-size: 12px;- background: #1a1e27;+ background: var(--raised);border: 1px solid var(--line);border-radius: 6px;cursor: pointer;@@ -138,7 +255,7 @@ main {color: var(--muted);font: inherit;font-size: 13px;- background: #151922;+ background: var(--raised-2);border: 1px solid var(--line);border-radius: 8px;cursor: pointer;@@ -201,19 +318,19 @@ ul {color: var(--muted);font-size: 13px;text-decoration: none;- background: #151922;+ background: var(--raised-2);border: 1px solid var(--line);border-radius: 8px;}.switcher-tab:hover {color: var(--text);- border-color: #3b4557;+ border-color: var(--chip-line);}.switcher-tab.is-current {color: var(--text);- background: #1d2431;+ background: var(--active);border-color: var(--accent);}@@ -263,7 +380,7 @@ ul {align-items: flex-start;justify-content: center;padding: 12vh 16px 32px;- background: rgba(5, 7, 10, 0.62);+ background: var(--overlay);}.switcher-dialog {@@ -272,7 +389,7 @@ ul {background: var(--panel);border: 1px solid var(--line);border-radius: 12px;- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);+ box-shadow: 0 20px 60px var(--shadow);}.switcher-input {@@ -305,7 +422,7 @@ ul {}.switcher-result.is-active {- background: #243040;+ background: var(--active);border-color: var(--accent);}@@ -361,7 +478,7 @@ ul {align-items: flex-start;justify-content: center;padding: 10vh 16px 32px;- background: rgba(5, 7, 10, 0.62);+ background: var(--overlay);}.settings-dialog {@@ -372,7 +489,7 @@ ul {background: var(--panel);border: 1px solid var(--line);border-radius: 12px;- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);+ box-shadow: 0 20px 60px var(--shadow);}.settings-head {@@ -489,12 +606,20 @@ ul {white-space: nowrap;}+.map-shell {+ display: flex;+ flex: 1 1 auto;+ flex-direction: column;+ min-height: 0;+}+.map-toolbar {display: flex;+ flex: none;align-items: center;justify-content: flex-end;gap: 8px;- margin-top: 24px;+ margin-top: 0;}.map-title {@@ -533,7 +658,7 @@ body:has(.map-shell.is-expanded) {.outline-button {padding: 5px 12px;color: var(--muted);- background: #1a1e27;+ background: var(--raised);border: 1px solid var(--line);border-radius: 7px;font: inherit;@@ -550,9 +675,10 @@ body:has(.map-shell.is-expanded) {.graph-wrap {position: relative;display: flex;- height: max(480px, calc(100vh - 96px));+ flex: 1 1 auto;+ min-height: 0;margin-top: 8px;- background: #12151b;+ background: var(--row-bg);border: 1px solid var(--line);border-radius: 12px;overflow: hidden;@@ -581,7 +707,7 @@ body:has(.map-shell.is-expanded) {flex-direction: column;width: 270px;height: 100%;- background: rgba(17, 20, 26, 0.94);+ background: var(--translucent-outline);border-right: 1px solid var(--line);}@@ -679,11 +805,11 @@ body:has(.map-shell.is-expanded) {}.outline-item:hover {- background: #1d222c;+ background: var(--hover);}.outline-item.is-active {- background: #243040;+ background: var(--active);outline: 1px solid var(--accent);}@@ -733,11 +859,11 @@ body:has(.map-shell.is-expanded) {}.file-hit:hover {- background: #1d222c;+ background: var(--hover);}.file-hit.is-active {- background: #243040;+ background: var(--active);outline: 1px solid var(--accent);}@@ -803,16 +929,20 @@ body:has(.map-shell.is-expanded) {}.session-count {- flex: none;+ flex: 0 1 auto;+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;white-space: nowrap;}/* An epoch is a tag on a session dot, not a box around sessions. */.epoch-tag {display: inline-flex;- flex: none;+ flex: 0 1 auto;align-items: center;gap: 4px;+ min-width: 0;max-width: 160px;overflow: hidden;padding: 1px 6px;@@ -855,23 +985,23 @@ body:has(.map-shell.is-expanded) {font-size: 10px;text-transform: uppercase;letter-spacing: 0.04em;- background: #242a36;+ background: var(--kind-bg);color: var(--muted);}.kind.kind-decision {- background: #2b2440;- color: #c0a8ff;+ background: var(--kind-decision-bg);+ color: var(--kind-decision-text);}.kind.kind-question {- background: #3a2f1d;+ background: var(--kind-question-bg);color: var(--warn);}.kind.kind-message {- background: #23331d;- color: #9ece6a;+ background: var(--kind-message-bg);+ color: var(--kind-message-text);}.empty,@@ -890,10 +1020,10 @@ body:has(.map-shell.is-expanded) {display: flex;flex-direction: column;width: min(460px, calc(100% - 24px));- background: rgba(20, 23, 30, 0.97);+ background: var(--translucent-panel);border: 1px solid var(--line);border-radius: 10px;- box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);+ box-shadow: 0 12px 32px var(--shadow);}.drilldown-head {@@ -919,7 +1049,7 @@ body:has(.map-shell.is-expanded) {font-size: 18px;line-height: 1;color: var(--muted);- background: #1d222c;+ background: var(--hover);border: 1px solid var(--line);border-radius: 6px;cursor: pointer;@@ -969,7 +1099,7 @@ body:has(.map-shell.is-expanded) {/* A commit git no longer has stays listed, greyed (Story 8.8). */.drilldown-code code.is-missing {- color: #5f6675;+ color: var(--missing);border-style: dashed;}@@ -1009,7 +1139,7 @@ body:has(.map-shell.is-expanded) {width: 100%;padding: 8px 12px;color: var(--text);- background: #243040;+ background: var(--active);border: 1px solid var(--line);border-radius: 7px;font: inherit;@@ -1034,7 +1164,7 @@ body:has(.map-shell.is-expanded) {margin: 10px 0 0;padding: 8px;overflow-x: auto;- background: #12151b;+ background: var(--row-bg);border: 1px solid var(--line);border-radius: 6px;font-size: 12px;@@ -1168,18 +1298,19 @@ time {.graph-wrap {flex-direction: column;- height: auto;}.outline {width: 100%;- height: 220px;+ height: 180px;border-right: 0;border-bottom: 1px solid var(--line);}.graph-canvas {- height: 480px;+ flex: 1;+ height: auto;+ min-height: 0;}}@@ -1196,7 +1327,7 @@ time {font: inherit;font-size: 12px;color: var(--text);- background: #1f2430;+ background: var(--raised);border: 1px solid var(--line);border-radius: 6px;cursor: pointer;@@ -1228,7 +1359,7 @@ time {.message-hash button {padding: 3px 8px;color: var(--text);- background: #243040;+ background: var(--active);border: 1px solid var(--line);border-radius: 6px;font: inherit;@@ -1245,11 +1376,11 @@ time {padding: 8px 10px;border-radius: 8px;border-left: 3px solid var(--line);- background: #1a1e27;+ background: var(--raised);}.chat-user {- border-left-color: #9ece6a;+ border-left-color: var(--l1);}.chat-agent {@@ -1319,26 +1450,26 @@ time {}.git-row:hover {- background: #1d222c;+ background: var(--hover);}.git-row.in-branch {- background: rgba(122, 162, 247, 0.06);+ background: color-mix(in srgb, var(--accent) 6%, transparent);}.git-row.is-selected {- background: #243040;+ background: var(--active);outline: 1px solid var(--accent);}/* Search hits (Story 8.14): every match is marked, the active one more so. */.git-row.is-search-hit {- background: rgba(224, 175, 104, 0.12);+ background: var(--search-hit-bg);box-shadow: inset 2px 0 0 var(--warn);}.git-row.is-search-active {- background: rgba(224, 175, 104, 0.24);+ background: var(--search-active-bg);outline: 1px solid var(--warn);}@@ -1358,14 +1489,17 @@ time {}.git-branch {- flex: none;+ flex: 0 1 auto;+ min-width: 0;max-width: 150px;overflow: hidden;padding: 1px 6px;- color: #0f1115;+ color: var(--on-lane);font-size: 10px;font-weight: 600;line-height: 14px;+ text-overflow: ellipsis;+ white-space: nowrap;background: var(--accent);border-radius: 4px;}@@ -1377,17 +1511,23 @@ time {font-size: 11px;}+/* The title wins over the chips around it (Story 9.2): it keeps its minimum+ width and the chips truncate with an ellipsis instead of squeezing it into a+ one-letter column. Keep `min-width` equal to `TITLE_MIN_WIDTH` in+ `gitLayout.ts` (a row is laid out tall enough to wrap at that width). */.git-title {- flex: 1;- min-width: 0;+ flex: 1 1 auto;+ min-width: 180px;line-height: 16px;overflow-wrap: anywhere;}.git-returns {display: flex;- flex: none;+ flex: 0 1 auto;gap: 4px;+ min-width: 0;+ overflow: hidden;font-size: 11px;}@@ -1395,8 +1535,10 @@ time {longer knows the commit. */.git-tags {display: flex;- flex: none;+ flex: 0 1 auto;gap: 4px;+ min-width: 0;+ overflow: hidden;}.git-tag {@@ -1405,8 +1547,8 @@ time {font-family: ui-monospace, SFMono-Regular, Menlo, monospace;font-size: 10px;line-height: 15px;- background: #1c222e;- border: 1px solid #323b4d;+ background: var(--chip-bg);+ border: 1px solid var(--chip-line);border-radius: 3px;cursor: pointer;}@@ -1417,13 +1559,14 @@ time {}.git-tag.is-missing {- color: #5f6675;+ color: var(--missing);border-style: dashed;}/* "↑ continues <session> · m67": a jump to the earlier session's message. */.git-continues {- flex: none;+ flex: 0 1 auto;+ min-width: 0;max-width: 220px;overflow: hidden;padding: 1px 6px;@@ -1431,12 +1574,12 @@ time {font-size: 11px;text-overflow: ellipsis;white-space: nowrap;- border: 1px solid rgba(122, 162, 247, 0.45);+ border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);border-radius: 4px;}.git-continues:hover {- background: rgba(122, 162, 247, 0.14);+ background: color-mix(in srgb, var(--accent) 14%, transparent);}.git-row .left-off,@@ -1533,5 +1676,5 @@ time {}.session-row.is-open {- background: rgba(122, 162, 247, 0.08);+ background: color-mix(in srgb, var(--accent) 8%, transparent);}diff --git a/packages/template/test/layout.test.ts b/packages/template/test/layout.test.tsnew file mode 100644index 0000000..d576893--- /dev/null+++ b/packages/template/test/layout.test.ts@@ -0,0 +1,180 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";+import { rowHeight, TITLE_MIN_WIDTH } from "../src/gitLayout.js";+import { shouldForwardWheel } from "../src/scroll.js";++/**+ * Story 9.2 pins the map's layout and readability in CSS. These tests read+ * `styles.css` itself: a rule that quietly loses the content column, the+ * title's minimum width or the contrast of small text fails here instead of+ * only looking wrong in a browser.+ */++const css = readFileSync(new URL("../src/styles.css", import.meta.url), "utf8");++function escape(text: string): string {+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");+}++/** Declaration block of the first rule whose selector (commas and spaces loose) matches. */+function declarations(selector: string): string {+ const pattern = selector+ .split(",")+ .map((part) => part.trim().split(/\s+/).map(escape).join("\\s+"))+ .join("\\s*,\\s*");+ const match = css.match(new RegExp(`(?:^|\\n)\\s*${pattern}\\s*\\{([\\s\\S]*?)\\}`));+ if (match?.[1] === undefined) throw new Error(`no rule for ${selector}`);+ return match[1];+}++function value(selector: string, property: string): string {+ const line = declarations(selector)+ .split(";")+ .map((part) => part.trim())+ .find((part) => part.startsWith(`${property}:`));+ if (line === undefined) throw new Error(`${selector} has no ${property}`);+ return line.slice(property.length + 1).trim();+}++function variables(block: string): Record<string, string> {+ return Object.fromEntries(+ [...block.matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)].map((match) => [+ match[1] as string,+ (match[2] as string).trim(),+ ]),+ );+}++const darkVars = variables(css.match(/:root\s*\{([\s\S]*?)\}/)?.[1] ?? "");+const lightBlock = css.match(+ /@media \(prefers-color-scheme: light\)\s*\{\s*:root\s*\{([\s\S]*?)\}\s*\}/,+);+const lightVars = { ...darkVars, ...variables(lightBlock?.[1] ?? "") };++/** WCAG relative luminance of a `#rrggbb` colour. */+function luminance(hex: string): number {+ const number = Number.parseInt(hex.slice(1), 16);+ const [r, g, b] = [(number >> 16) & 255, (number >> 8) & 255, number & 255].map((channel) => {+ const c = channel / 255;+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;+ }) as [number, number, number];+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;+}++function contrast(foreground: string, background: string): number {+ const [lighter, darker] = [luminance(foreground), luminance(background)].sort(+ (a, b) => b - a,+ ) as [number, number];+ return (lighter + 0.05) / (darker + 0.05);+}++describe("map layout (Story 9.2)", () => {+ it("keeps the content column at 8 of 12 columns and drops it below 1100px", () => {+ expect(value(".map-page .page-head, .map-page .lineage-map", "width")).toBe("66.667%");+ const narrow = css.match(/@media \(max-width: 1100px\)\s*\{([\s\S]*?)\n\}/)?.[1] ?? "";+ expect(narrow).toMatch(/main\.map-page\s*\{[^}]*padding-right:\s*16px/);+ expect(narrow).toMatch(/\.map-page \.page-head,[\s\S]*?width:\s*100%/);+ });++ it("gives the page one scroller: the map fills the rest of the window", () => {+ expect(value("html, body, #root", "height")).toBe("100%");+ expect(declarations("body:has(.map-page)")).toMatch(/overflow:\s*hidden/);+ expect(value("main.map-page", "height")).toBe("100%");+ expect(value("main.map-page", "display")).toBe("flex");+ // The map's height comes from the flex column, not a viewport calculation.+ expect(declarations(".graph-wrap")).toMatch(/flex:\s*1 1 auto/);+ expect(declarations(".graph-wrap")).not.toMatch(/calc\(100vh/);+ });++ it("never squeezes a title into a one-letter column", () => {+ expect(value(".git-title", "min-width")).toBe(`${TITLE_MIN_WIDTH}px`);+ // Every chip beside the title may shrink and truncate instead of pushing it.+ expect(declarations(".git-branch")).toMatch(/flex:\s*0 1 auto/);+ expect(declarations(".git-branch")).toMatch(/text-overflow:\s*ellipsis/);+ expect(declarations(".git-continues")).toMatch(/flex:\s*0 1 auto/);+ expect(declarations(".git-continues")).toMatch(/text-overflow:\s*ellipsis/);+ });++ it("lays a row out tall enough to wrap at the title's minimum width", () => {+ // 120 characters need 5 lines at 180px, but would need 7 at the old 120px+ // floor; the height follows the title, not the chips next to it.+ const message = { id: "x", label: "m1", title: "a".repeat(120) };+ const height = rowHeight(message, {+ first: true,+ branchTitle: "a very long branch label that leaves no room",+ returns: 2,+ tags: 3,+ head: false,+ });+ expect(height).toBeGreaterThanOrEqual(12 + Math.ceil((120 * 6.4) / TITLE_MIN_WIDTH) * 16);+ });+});++describe("small text contrast (Story 9.2)", () => {+ const pairs: [string, string][] = [+ ["muted", "bg"],+ ["muted", "panel"],+ ["muted", "row-bg"],+ ["muted", "hover"],+ ["muted", "active"],+ ["missing", "row-bg"],+ ["missing", "chip-bg"],+ ["muted", "search-hit-bg"],+ ["muted", "search-active-bg"],+ ["accent", "row-bg"],+ ["warn", "kind-question-bg"],+ ["kind-message-text", "kind-message-bg"],+ ["kind-decision-text", "kind-decision-bg"],+ ];++ it("declares a light theme besides the dark default", () => {+ expect(lightBlock).not.toBeNull();+ });++ for (const [name, theme] of [+ ["dark", darkVars],+ ["light", lightVars],+ ] as const) {+ it(`reaches WCAG AA in the ${name} theme`, () => {+ for (const [foreground, background] of pairs) {+ const fg = theme[`--${foreground}`] as string | undefined;+ const bg = theme[`--${background}`] as string | undefined;+ expect(fg, `--${foreground}`).toMatch(/^#[0-9a-f]{6}$/i);+ expect(bg, `--${background}`).toMatch(/^#[0-9a-f]{6}$/i);+ const ratio = contrast(fg as string, bg as string);+ expect(+ ratio,+ `${foreground} on ${background} is ${ratio.toFixed(2)}:1`,+ ).toBeGreaterThanOrEqual(4.5);+ }+ });++ it(`keeps branch labels readable on every lane in the ${name} theme`, () => {+ const onLane = theme["--on-lane"] as string;+ for (let lane = 0; lane < 6; lane += 1) {+ const colour = theme[`--l${lane}`] as string;+ const ratio = contrast(onLane, colour);+ expect(ratio, `--on-lane on --l${lane} is ${ratio.toFixed(2)}:1`).toBeGreaterThanOrEqual(+ 4.5,+ );+ }+ });+ }+});++describe("page wheel forwarding (Story 9.2)", () => {+ const element = (owned: boolean) =>+ ({+ closest: () => (owned ? {} : null),+ }) as unknown as Element;++ it("sends the wheel to the map from the gutters and the head", () => {+ expect(shouldForwardWheel(null)).toBe(true);+ expect(shouldForwardWheel({} as EventTarget)).toBe(true);+ expect(shouldForwardWheel(element(false))).toBe(true);+ });++ it("leaves the map and the page's own scrollers alone", () => {+ expect(shouldForwardWheel(element(true))).toBe(false);+ });+});