feat: polish double-elimination bracket navigation

Highlight connected routes, add readable round labels and accessible path descriptions, widen routing gaps, and centralize brand colors for winner progression.
This commit is contained in:
dahyeon committed 2026-07-13 23:17:19 -07:00
1 parent 03e88a03bc
commit b115072005
8 files changed
+761 -165

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const stylesheet = await readFile(
new URL("../src/index.css", import.meta.url),
"utf8",
);
const BRAND_COLORS = {
coral: "oklch(0.708008 0.234375 24)",
violet: "oklch(0.481934 0.285938 285)",
gold: "oklch(0.853027 0.2 90)",
cyan: "oklch(70% 0.14523 200)",
} as const;
test("defines each brand color once as a primitive token", () => {
for (const [name, value] of Object.entries(BRAND_COLORS)) {
assert.match(
stylesheet,
new RegExp(`--color-brand-${name}: ${escapeRegExp(value)};`),
);
assert.equal(
stylesheet.split(value).length - 1,
1,
`${name} should have one literal source`,
);
}
});
test("maps the light theme semantic roles to the brand primitives", () => {
const lightTheme = cssBlocksForSelector('[data-theme="light"]');
const mappings = [
["--color-primary", "--color-brand-coral"],
["--color-secondary", "--color-brand-violet"],
["--color-accent", "--color-brand-gold"],
["--color-info", "--color-brand-cyan"],
] as const;
for (const [semanticToken, primitiveToken] of mappings) {
assert.match(
lightTheme,
new RegExp(
`${escapeRegExp(semanticToken)}: var\\(${escapeRegExp(primitiveToken)}\\);`,
),
);
}
});
test("keeps coral scopes without overriding the global dark primary", () => {
assert.match(
stylesheet,
/--color-bracket-winner: var\(--color-brand-coral\);/,
);
assert.match(
stylesheet,
/\.competition-series-history\s*{\s*--color-primary: var\(--color-brand-coral\);\s*}/,
);
const darkTheme = cssBlocksForSelector('[data-theme="dark"]');
assert.doesNotMatch(darkTheme, /--color-primary/);
});
function cssBlocksForSelector(selector: string): string {
const blocks = stylesheet.matchAll(
new RegExp(`${escapeRegExp(selector)}\\s*{([^}]*)}`, "g"),
);
const contents = [...blocks].map((match) => match[1] ?? "").join("\n");
assert.notEqual(contents, "", `${selector} should have a CSS block`);
return contents;
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
@@ -0,0 +1,146 @@
import assert from "node:assert/strict";
import test from "node:test";
import type { SeriesId } from "@lolympus/contracts";
import {
bracketConnectorKey,
getBracketConnectorColorClass,
getBracketFocusState,
getHorizontalOverflowCues,
type BracketFocusConnector,
} from "../src/components/competition/double-elimination-bracket-interaction.ts";
const A = seriesId("a");
const B = seriesId("b");
const C = seriesId("c");
const D = seriesId("d");
const E = seriesId("e");
const CONNECTORS: BracketFocusConnector[] = [
connector(A, "winner", B, "A"),
connector(B, "winner", C, "A"),
connector(B, "loser", D, "B"),
connector(D, "winner", E, "A"),
];
test("focuses directly incoming and outgoing routes plus adjacent matches", () => {
const focus = getBracketFocusState(CONNECTORS, B);
assert.deepEqual([...focus.seriesIds].sort(), [A, B, C, D].sort());
assert.deepEqual(
[...focus.connectorKeys].sort(),
CONNECTORS.slice(0, 3).map(bracketConnectorKey).sort(),
);
assert.equal(focus.connectorKeys.has(bracketConnectorKey(CONNECTORS[3])), false);
});
test("returns a neutral focus state when no match is active", () => {
const focus = getBracketFocusState(CONNECTORS, null);
assert.equal(focus.seriesIds.size, 0);
assert.equal(focus.connectorKeys.size, 0);
});
test("keeps both grand-final carry-over routes focused", () => {
const grandFinal = seriesId("grand-final");
const resetFinal = seriesId("reset-final");
const resetConnectors = [
connector(grandFinal, "slot-a", resetFinal, "A"),
connector(grandFinal, "slot-b", resetFinal, "B"),
];
const focus = getBracketFocusState(resetConnectors, grandFinal);
assert.deepEqual([...focus.seriesIds].sort(), [grandFinal, resetFinal].sort());
assert.equal(focus.connectorKeys.size, 2);
});
test("keeps both grand-final carry-over routes focused from the reset final", () => {
const grandFinal = seriesId("grand-final");
const resetFinal = seriesId("reset-final");
const resetConnectors = [
connector(grandFinal, "slot-b", resetFinal, "B"),
connector(grandFinal, "slot-a", resetFinal, "A"),
];
const focus = getBracketFocusState(resetConnectors, resetFinal);
assert.deepEqual([...focus.seriesIds].sort(), [grandFinal, resetFinal].sort());
assert.deepEqual(
[...focus.connectorKeys].sort(),
resetConnectors.map(bracketConnectorKey).sort(),
);
});
test("uses the brand coral for winner routes without losing patterned route semantics", () => {
assert.equal(getBracketConnectorColorClass("winner"), "text-bracket-winner");
assert.equal(
getBracketConnectorColorClass("winner", true),
"text-bracket-winner",
);
assert.equal(getBracketConnectorColorClass("loser"), "text-base-content/55");
assert.equal(
getBracketConnectorColorClass("loser", true),
"text-base-content",
);
assert.equal(getBracketConnectorColorClass("reset"), "text-base-content/55");
});
test("derives truthful horizontal overflow cues at each scroll position", () => {
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 0, scrollWidth: 1600, clientWidth: 1200 }),
{ showStart: false, showEnd: true },
);
assert.deepEqual(
getHorizontalOverflowCues({
scrollLeft: 200,
scrollWidth: 1600,
clientWidth: 1200,
}),
{ showStart: true, showEnd: true },
);
assert.deepEqual(
getHorizontalOverflowCues({
scrollLeft: 400,
scrollWidth: 1600,
clientWidth: 1200,
}),
{ showStart: true, showEnd: false },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 0, scrollWidth: 1200, clientWidth: 1200 }),
{ showStart: false, showEnd: false },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 1, scrollWidth: 1600, clientWidth: 1200 }),
{ showStart: false, showEnd: true },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 1.01, scrollWidth: 1600, clientWidth: 1200 }),
{ showStart: true, showEnd: true },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 399, scrollWidth: 1600, clientWidth: 1200 }),
{ showStart: true, showEnd: false },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 398.99, scrollWidth: 1600, clientWidth: 1200 }),
{ showStart: true, showEnd: true },
);
assert.deepEqual(
getHorizontalOverflowCues({ scrollLeft: 0, scrollWidth: 1201, clientWidth: 1200 }),
{ showStart: false, showEnd: false },
);
});
function connector(
fromSeriesId: SeriesId,
select: BracketFocusConnector["select"],
toSeriesId: SeriesId,
toSlot: BracketFocusConnector["toSlot"],
): BracketFocusConnector {
return { fromSeriesId, select, toSeriesId, toSlot };
}
function seriesId(value: string): SeriesId {
return value as SeriesId;
}
@@ -15,6 +15,8 @@ import {
createCompetitionBracketLayout,
} from "../src/components/competition/competition-display-layout.ts";
import {
bracketRoundAccessibleLabel,
bracketRoundLabel,
createDoubleEliminationBracketLayout,
DOUBLE_ELIMINATION_BRACKET_GEOMETRY,
} from "../src/components/competition/double-elimination-bracket-layout.ts";
@@ -84,6 +86,52 @@ test("places the canonical four-team DAG in shared time columns", () => {
assert.equal(nodeFor(layout, ids.GF).lane, "final");
});
test("uses compact bracket vocabulary with expanded accessible round names", () => {
assert.equal(bracketRoundLabel("upper", 1), "브래킷 1R");
assert.equal(bracketRoundLabel("upper", 2), "브래킷 상위 2R");
assert.equal(bracketRoundLabel("lower", 1), "브래킷 하위 1R");
assert.equal(bracketRoundLabel("lower", 4), "브래킷 하위 4R");
assert.equal(bracketRoundLabel("grand-final", 1), "그랜드 파이널");
assert.equal(bracketRoundLabel("reset-final", 1), "리셋 파이널");
assert.equal(bracketRoundLabel("round-robin", 3), "3라운드");
assert.equal(
bracketRoundAccessibleLabel("upper", 1),
"브래킷 1라운드",
);
assert.equal(
bracketRoundAccessibleLabel("upper", 2),
"브래킷 상위 2라운드",
);
assert.equal(
bracketRoundAccessibleLabel("lower", 1),
"브래킷 하위 1라운드",
);
assert.equal(
bracketRoundAccessibleLabel("grand-final", 1),
"그랜드 파이널",
);
assert.equal(
bracketRoundAccessibleLabel("round-robin", 3),
"3라운드",
);
const { projection } = eightTeamProjection();
const layout = requireLayout(projection, EIGHT_TEAM_LAYOUT);
const upperOpening = layout.rounds.find(
({ stage, roundNumber }) => stage === "upper" && roundNumber === 1,
);
const lowerOpening = layout.mobileGroups.find(
({ stage, roundNumber }) => stage === "lower" && roundNumber === 1,
);
assert.ok(upperOpening);
assert.ok(lowerOpening);
assert.equal(upperOpening.label, "브래킷 1R");
assert.equal(upperOpening.accessibleLabel, "브래킷 1라운드");
assert.equal(lowerOpening.label, "브래킷 하위 1R");
assert.equal(lowerOpening.accessibleLabel, "브래킷 하위 1라운드");
});
test("keeps the match page narrow and gives only the desktop bracket a wide viewport", () => {
assert.equal(MATCH_PAGE_MAX_WIDTH_CLASS, "max-w-5xl");
assert.match(DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS, /max-w-\[1600px\]/);
@@ -93,6 +141,15 @@ test("keeps the match page narrow and gives only the desktop bracket a wide view
);
});
test("uses a 40px routing gap while keeping the canonical bracket inside its viewport", () => {
const { projection } = eightTeamProjection();
const layout = requireLayout(projection, EIGHT_TEAM_LAYOUT);
assert.equal(DOUBLE_ELIMINATION_BRACKET_GEOMETRY.columnGap, 40);
assert.equal(layout.columnCount, 6);
assert.equal(layout.width, 1592);
});
test("selects the bracket only for a coherent double-elimination snapshot", () => {
const { projection } = eightTeamProjection();
const competition = competitionDetail(projection);
@@ -200,6 +257,40 @@ test("places every code-less eight-team Series once regardless of input order",
);
});
test("uses human-readable match names while preserving technical Series codes", () => {
const ordered = eightTeamProjection();
const shuffled = eightTeamProjection({ shuffled: true });
for (const fixture of [ordered, shuffled]) {
for (const series of fixture.projection.series) {
series.code = `CODE-${series.seriesId}`;
}
}
const codedSeries = shuffled.projection.series.find(
(series) => series.seriesId === shuffled.ids.WB_R2_M2,
);
assert.ok(codedSeries);
codedSeries.code = "WB_R2_M2";
const orderedLayout = requireLayout(ordered.projection, EIGHT_TEAM_LAYOUT);
const shuffledLayout = requireLayout(shuffled.projection, EIGHT_TEAM_LAYOUT);
const node = nodeFor(shuffledLayout, shuffled.ids.WB_R2_M2);
const winnerRoute = shuffledLayout.connectors.find(
(route) =>
route.fromSeriesId === shuffled.ids.WB_R2_M2 && route.select === "winner",
);
assert.ok(winnerRoute);
assert.equal(node.label, "브래킷 상위 2R · 2경기");
assert.equal(node.accessibleLabel, "브래킷 상위 2라운드 · 2경기");
assert.deepEqual(labelsBySeriesId(shuffledLayout), labelsBySeriesId(orderedLayout));
assert.match(winnerRoute.label, /^브래킷 상위 2R · 2경기 승자 →/);
assert.match(
winnerRoute.accessibleLabel,
/^브래킷 상위 2라운드 · 2경기 승자 →/,
);
assert.doesNotMatch(winnerRoute.label, /WB_R2_M2/);
});
test("keeps the known WB_R2_M2 winner and loser routes keyed by opaque Series identity", () => {
const { projection, ids } = eightTeamProjection({ shuffled: true });
const layout = requireLayout(projection, EIGHT_TEAM_LAYOUT);
@@ -401,7 +492,10 @@ test("keeps connector rails distinct and outside intervening card rectangles", (
assert.equal(route.path.includes("Infinity"), false);
assert.notEqual(route.label.trim(), "");
assert.ok(target.column > source.column);
assert.ok(route.verticalX > target.x - 32);
assert.ok(
route.verticalX >
target.x - DOUBLE_ELIMINATION_BRACKET_GEOMETRY.columnGap,
);
assert.ok(route.verticalX < target.x);
for (const intermediate of layout.nodes) {
@@ -896,6 +990,16 @@ function columnsBySeriesId(
);
}
function labelsBySeriesId(
layout: NonNullable<ReturnType<typeof createDoubleEliminationBracketLayout>>,
) {
return Object.fromEntries(
layout.nodes
.map((node) => [node.seriesId, node.label] as const)
.sort(([left], [right]) => left.localeCompare(right)),
);
}
function nodeFor(
layout: NonNullable<ReturnType<typeof createDoubleEliminationBracketLayout>>,
id: SeriesId,