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:
1 parent
03e88a03bc
commit
b115072005
8 files changed
+761
-165
No files matched your search
@@ -1,16 +1,26 @@
|
||||
import type {
|
||||
CompetitionTeamView,
|
||||
DoubleEliminationCompetitionProjection,
|
||||
SeriesId,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
||||
import type {
|
||||
BracketConnectorKind,
|
||||
DoubleEliminationBracketLayout,
|
||||
} from "./double-elimination-bracket-layout";
|
||||
import { DOUBLE_ELIMINATION_BRACKET_GEOMETRY } from "./double-elimination-bracket-layout";
|
||||
import {
|
||||
bracketConnectorKey,
|
||||
getBracketConnectorColorClass,
|
||||
getBracketFocusState,
|
||||
getHorizontalOverflowCues,
|
||||
type HorizontalOverflowCues,
|
||||
} from "./double-elimination-bracket-interaction";
|
||||
import { DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS } from "./competition-display-layout";
|
||||
import { DoubleEliminationMobileBracket } from "./DoubleEliminationMobileBracket";
|
||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||
import { getSeriesScoreCardAccessibleLabel } from "./series-score-card-model";
|
||||
|
||||
export function DoubleEliminationBracket({
|
||||
projection,
|
||||
@@ -52,154 +62,256 @@ function DesktopBracket({
|
||||
const nodeById = new Map(layout.nodes.map((node) => [node.seriesId, node]));
|
||||
const finalNodes = layout.nodes.filter(({ lane }) => lane === "final");
|
||||
const hasResetRoute = layout.connectors.some(({ kind }) => kind === "reset");
|
||||
const bracketInstructionsId = useId();
|
||||
const scrollViewportRef = useRef<HTMLDivElement>(null);
|
||||
const [hoveredSeriesId, setHoveredSeriesId] = useState<SeriesId | null>(null);
|
||||
const [focusedSeriesId, setFocusedSeriesId] = useState<SeriesId | null>(null);
|
||||
const [overflowCues, setOverflowCues] = useState<HorizontalOverflowCues>({
|
||||
showStart: false,
|
||||
showEnd: false,
|
||||
});
|
||||
const activeSeriesId = focusedSeriesId ?? hoveredSeriesId;
|
||||
const focusState = getBracketFocusState(layout.connectors, activeSeriesId);
|
||||
const roundGuideXs = Array.from(
|
||||
new Set(layout.rounds.map((round) => round.x)),
|
||||
);
|
||||
const finalZoneLeft = Math.max(
|
||||
0,
|
||||
Math.min(...finalNodes.map(({ x }) => x), layout.width) - 16,
|
||||
);
|
||||
const updateOverflowCues = useCallback((viewport: HTMLDivElement) => {
|
||||
const next = getHorizontalOverflowCues(viewport);
|
||||
setOverflowCues((current) =>
|
||||
current.showStart === next.showStart && current.showEnd === next.showEnd
|
||||
? current
|
||||
: next,
|
||||
);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const viewport = scrollViewportRef.current;
|
||||
if (!viewport) return;
|
||||
const update = () => updateOverflowCues(viewport);
|
||||
update();
|
||||
window.addEventListener("resize", update);
|
||||
return () => window.removeEventListener("resize", update);
|
||||
}, [layout.width, updateOverflowCues]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`hidden xl:block ${DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS}`}
|
||||
>
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-3 text-xs text-content-muted">
|
||||
<p>
|
||||
<p id={bracketInstructionsId}>
|
||||
승자조와 패자조는 같은 시간축을 공유하며 오른쪽 결승에서 합류합니다.
|
||||
<span className="ml-2 text-content-subtle">
|
||||
화면에 모두 보이지 않으면 가로로 스크롤하세요.
|
||||
</span>
|
||||
<span className="ml-2 text-content-subtle">
|
||||
경기 카드에 마우스를 올리거나 Tab 키로 초점을 맞추면 연결 경로가
|
||||
강조됩니다.
|
||||
</span>
|
||||
</p>
|
||||
<ConnectorLegend showReset={hasResetRoute} />
|
||||
</div>
|
||||
<div
|
||||
className="overflow-x-auto border-y border-base-content/10 bg-base-100 pb-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary"
|
||||
role="region"
|
||||
aria-label="더블 엘리미네이션 대진표"
|
||||
tabIndex={0}
|
||||
>
|
||||
<div className="relative">
|
||||
<div
|
||||
className="relative"
|
||||
style={{ width: layout.width, height: layout.height }}
|
||||
ref={scrollViewportRef}
|
||||
className="overflow-x-auto border-y border-base-content/10 bg-base-100 pb-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary"
|
||||
role="region"
|
||||
aria-label="더블 엘리미네이션 대진표"
|
||||
aria-describedby={bracketInstructionsId}
|
||||
tabIndex={0}
|
||||
onScroll={(event) => updateOverflowCues(event.currentTarget)}
|
||||
>
|
||||
<LaneBand
|
||||
label="승자조"
|
||||
description="패배 시 패자조 이동"
|
||||
top={layout.upperLane.top}
|
||||
height={layout.upperLane.height}
|
||||
width={layout.width}
|
||||
/>
|
||||
<LaneBand
|
||||
label="패자조"
|
||||
description="패배 시 탈락"
|
||||
top={layout.lowerLane.top}
|
||||
height={layout.lowerLane.height}
|
||||
width={layout.width}
|
||||
/>
|
||||
{finalNodes.length > 0 && (
|
||||
<div
|
||||
className="absolute border-l border-primary/15 bg-primary/[0.025]"
|
||||
style={{
|
||||
left: finalZoneLeft,
|
||||
top: 0,
|
||||
width: layout.width - finalZoneLeft,
|
||||
height: layout.height,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 z-[1]"
|
||||
width={layout.width}
|
||||
height={layout.height}
|
||||
viewBox={`0 0 ${layout.width} ${layout.height}`}
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
<div
|
||||
className="relative"
|
||||
style={{ width: layout.width, height: layout.height }}
|
||||
>
|
||||
{layout.connectors.map((connector) => (
|
||||
<g
|
||||
key={`${connector.fromSeriesId}:${connector.select}:${connector.toSeriesId}:${connector.toSlot}`}
|
||||
className={connectorClass(connector.kind)}
|
||||
>
|
||||
<path
|
||||
d={connector.path}
|
||||
fill="none"
|
||||
stroke="var(--color-base-100)"
|
||||
strokeWidth="4"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
vectorEffect="non-scaling-stroke"
|
||||
/>
|
||||
<path
|
||||
d={connector.path}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.25"
|
||||
strokeDasharray={connectorDash(connector.kind)}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
vectorEffect="non-scaling-stroke"
|
||||
/>
|
||||
<circle
|
||||
cx={connector.targetX}
|
||||
cy={connector.targetY}
|
||||
r="2.25"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
|
||||
{layout.rounds.map((round) => (
|
||||
<section
|
||||
key={`${round.stage}:${round.roundNumber}`}
|
||||
aria-labelledby={`competition-round-${round.stage}-${round.roundNumber}`}
|
||||
>
|
||||
<h3
|
||||
id={`competition-round-${round.stage}-${round.roundNumber}`}
|
||||
className="absolute z-[2] truncate px-1 text-xs font-bold text-content-muted"
|
||||
<LaneBand
|
||||
label="승자조"
|
||||
description="패배 시 패자조 이동"
|
||||
top={layout.upperLane.top}
|
||||
height={layout.upperLane.height}
|
||||
width={layout.width}
|
||||
/>
|
||||
<LaneBand
|
||||
label="패자조"
|
||||
description="패배 시 탈락"
|
||||
top={layout.lowerLane.top}
|
||||
height={layout.lowerLane.height}
|
||||
width={layout.width}
|
||||
/>
|
||||
{finalNodes.length > 0 && (
|
||||
<div
|
||||
className="absolute border-l border-primary/20 bg-primary/[0.04]"
|
||||
style={{
|
||||
left: round.x,
|
||||
top: round.labelY,
|
||||
width: DOUBLE_ELIMINATION_BRACKET_GEOMETRY.columnWidth,
|
||||
left: finalZoneLeft,
|
||||
top: 0,
|
||||
width: layout.width - finalZoneLeft,
|
||||
height: layout.height,
|
||||
}}
|
||||
>
|
||||
{round.label}
|
||||
</h3>
|
||||
{round.seriesIds.map((seriesId) => {
|
||||
const node = nodeById.get(seriesId);
|
||||
const series = seriesById.get(seriesId);
|
||||
if (!node || !series) return null;
|
||||
const routes = layout.connectors.filter(
|
||||
(connector) => connector.fromSeriesId === node.seriesId,
|
||||
);
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
{roundGuideXs.map((x) => (
|
||||
<div
|
||||
key={x}
|
||||
className="absolute top-0 border-l border-base-content/[0.045]"
|
||||
style={{
|
||||
left: Math.max(
|
||||
0,
|
||||
x - DOUBLE_ELIMINATION_BRACKET_GEOMETRY.columnGap / 2,
|
||||
),
|
||||
height: layout.height,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
))}
|
||||
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 z-[1]"
|
||||
width={layout.width}
|
||||
height={layout.height}
|
||||
viewBox={`0 0 ${layout.width} ${layout.height}`}
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
>
|
||||
{layout.connectors.map((connector) => {
|
||||
const connectorKey = bracketConnectorKey(connector);
|
||||
const isFocused = focusState.connectorKeys.has(connectorKey);
|
||||
return (
|
||||
<div
|
||||
key={node.seriesId}
|
||||
className="absolute z-[3]"
|
||||
style={{
|
||||
left: node.x,
|
||||
top: node.y,
|
||||
width: node.width,
|
||||
minHeight: node.height,
|
||||
}}
|
||||
>
|
||||
<SeriesScoreCard
|
||||
series={series}
|
||||
displayLabel={node.label}
|
||||
teamById={teamById}
|
||||
variant="bracket"
|
||||
/>
|
||||
{routes.length > 0 && (
|
||||
<span className="sr-only">
|
||||
{routes.map(({ label }) => label).join(". ")}
|
||||
</span>
|
||||
<g
|
||||
key={connectorKey}
|
||||
className={getBracketConnectorColorClass(
|
||||
connector.kind,
|
||||
isFocused,
|
||||
)}
|
||||
</div>
|
||||
>
|
||||
<path
|
||||
d={connector.path}
|
||||
fill="none"
|
||||
stroke="var(--color-base-100)"
|
||||
strokeWidth={isFocused ? 5 : 4}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
vectorEffect="non-scaling-stroke"
|
||||
/>
|
||||
<path
|
||||
d={connector.path}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={isFocused ? 2 : 1.5}
|
||||
strokeDasharray={connectorDash(connector.kind)}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
vectorEffect="non-scaling-stroke"
|
||||
/>
|
||||
<circle
|
||||
cx={connector.targetX}
|
||||
cy={connector.targetY}
|
||||
r={isFocused ? 3 : 2.5}
|
||||
fill="currentColor"
|
||||
/>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
</section>
|
||||
))}
|
||||
</svg>
|
||||
|
||||
{layout.rounds.map((round) => (
|
||||
<section
|
||||
key={`${round.stage}:${round.roundNumber}`}
|
||||
aria-labelledby={`${bracketInstructionsId}-round-${round.stage}-${round.roundNumber}`}
|
||||
>
|
||||
<h3
|
||||
id={`${bracketInstructionsId}-round-${round.stage}-${round.roundNumber}`}
|
||||
aria-label={round.accessibleLabel}
|
||||
className={`absolute z-[2] truncate border-l-2 px-2 text-xs font-bold ${round.lane === "final" ? "border-primary/45 text-base-content" : "border-base-content/15 text-content-muted"}`}
|
||||
style={{
|
||||
left: round.x,
|
||||
top: round.labelY,
|
||||
width: DOUBLE_ELIMINATION_BRACKET_GEOMETRY.columnWidth,
|
||||
}}
|
||||
>
|
||||
{round.label}
|
||||
</h3>
|
||||
{round.seriesIds.map((seriesId, seriesIndex) => {
|
||||
const node = nodeById.get(seriesId);
|
||||
const series = seriesById.get(seriesId);
|
||||
if (!node || !series) return null;
|
||||
const relatedRoutes = layout.connectors.filter(
|
||||
(connector) =>
|
||||
connector.fromSeriesId === node.seriesId ||
|
||||
connector.toSeriesId === node.seriesId,
|
||||
);
|
||||
const routeDescriptionId = `${bracketInstructionsId}-${round.stage}-${round.roundNumber}-${seriesIndex}`;
|
||||
const isFocused = activeSeriesId === node.seriesId;
|
||||
const isRelated = focusState.seriesIds.has(node.seriesId);
|
||||
const accessibilityLabel = getSeriesScoreCardAccessibleLabel(
|
||||
series,
|
||||
node.accessibleLabel,
|
||||
teamById,
|
||||
);
|
||||
return (
|
||||
<div
|
||||
key={node.seriesId}
|
||||
className={`absolute z-[3] focus-visible:z-[4] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${isFocused ? "z-[4] ring-2 ring-primary/55" : isRelated ? "z-[4] ring-1 ring-base-content/30" : node.lane === "final" ? "outline outline-1 outline-primary/25" : ""}`}
|
||||
style={{
|
||||
left: node.x,
|
||||
top: node.y,
|
||||
width: node.width,
|
||||
minHeight: node.height,
|
||||
}}
|
||||
role="group"
|
||||
aria-label={accessibilityLabel}
|
||||
aria-describedby={
|
||||
relatedRoutes.length > 0 ? routeDescriptionId : undefined
|
||||
}
|
||||
tabIndex={0}
|
||||
onMouseEnter={() => setHoveredSeriesId(node.seriesId)}
|
||||
onMouseLeave={() =>
|
||||
setHoveredSeriesId((current) =>
|
||||
current === node.seriesId ? null : current,
|
||||
)
|
||||
}
|
||||
onFocus={() => setFocusedSeriesId(node.seriesId)}
|
||||
onBlur={(event) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget)) {
|
||||
setFocusedSeriesId((current) =>
|
||||
current === node.seriesId ? null : current,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SeriesScoreCard
|
||||
series={series}
|
||||
displayLabel={node.label}
|
||||
teamById={teamById}
|
||||
variant="bracket"
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
{relatedRoutes.length > 0 && (
|
||||
<span id={routeDescriptionId} className="sr-only">
|
||||
{relatedRoutes
|
||||
.map(({ accessibleLabel }) => accessibleLabel)
|
||||
.join(". ")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`pointer-events-none absolute inset-y-px left-0 z-[5] w-8 bg-linear-to-r from-base-100 to-transparent transition-opacity duration-150 motion-reduce:transition-none ${overflowCues.showStart ? "opacity-100" : "opacity-0"}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div
|
||||
className={`pointer-events-none absolute inset-y-px right-0 z-[5] w-8 bg-linear-to-l from-base-100 to-transparent transition-opacity duration-150 motion-reduce:transition-none ${overflowCues.showEnd ? "opacity-100" : "opacity-0"}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -221,7 +333,7 @@ function LaneBand({
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="absolute border-y border-base-content/8 bg-base-content/[0.018]"
|
||||
className="absolute border-y border-base-content/10 bg-base-content/[0.03]"
|
||||
style={{ top: top - 6, width, height: height + 12 }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
@@ -240,7 +352,11 @@ function LaneBand({
|
||||
|
||||
function ConnectorLegend({ showReset }: { showReset: boolean }) {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-4" aria-label="연결선 범례">
|
||||
<div
|
||||
className="flex flex-wrap items-center gap-4"
|
||||
role="group"
|
||||
aria-label="연결선 범례"
|
||||
>
|
||||
<LegendItem label="승자 진출" kind="winner" />
|
||||
<LegendItem label="패자조 이동" kind="loser" />
|
||||
{showReset && <LegendItem label="리셋 대진 유지" kind="reset" />}
|
||||
@@ -264,7 +380,7 @@ function LegendItem({
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.25"
|
||||
strokeDasharray={connectorDash(kind)}
|
||||
className={connectorClass(kind)}
|
||||
className={getBracketConnectorColorClass(kind)}
|
||||
/>
|
||||
</svg>
|
||||
{label}
|
||||
@@ -272,12 +388,6 @@ function LegendItem({
|
||||
);
|
||||
}
|
||||
|
||||
function connectorClass(kind: BracketConnectorKind): string {
|
||||
if (kind === "loser") return "text-warning/65";
|
||||
if (kind === "reset") return "text-primary/55";
|
||||
return "text-base-content/30";
|
||||
}
|
||||
|
||||
function connectorDash(kind: BracketConnectorKind): string | undefined {
|
||||
if (kind === "loser") return "6 5";
|
||||
if (kind === "reset") return "2 5";
|
||||
|
||||
@@ -4,8 +4,10 @@ import type {
|
||||
SeriesId,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import { useId } from "react";
|
||||
import type { DoubleEliminationBracketLayout } from "./double-elimination-bracket-layout";
|
||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||
import { getSeriesScoreCardAccessibleLabel } from "./series-score-card-model";
|
||||
|
||||
export function DoubleEliminationMobileBracket({
|
||||
projection,
|
||||
@@ -16,6 +18,7 @@ export function DoubleEliminationMobileBracket({
|
||||
layout: DoubleEliminationBracketLayout;
|
||||
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
||||
}) {
|
||||
const bracketId = useId();
|
||||
const seriesById = new Map(
|
||||
projection.series.map((series) => [series.seriesId, series]),
|
||||
);
|
||||
@@ -53,9 +56,15 @@ export function DoubleEliminationMobileBracket({
|
||||
);
|
||||
if (groups.length === 0) return null;
|
||||
return (
|
||||
<section key={section.key} aria-labelledby={`bracket-${section.key}`}>
|
||||
<section
|
||||
key={section.key}
|
||||
aria-labelledby={`${bracketId}-${section.key}`}
|
||||
>
|
||||
<div className="mb-3 border-b border-base-content/10 pb-2">
|
||||
<h3 id={`bracket-${section.key}`} className="text-sm font-bold">
|
||||
<h3
|
||||
id={`${bracketId}-${section.key}`}
|
||||
className="text-sm font-bold"
|
||||
>
|
||||
{section.title}
|
||||
</h3>
|
||||
<p className="mt-0.5 text-xs text-content-muted">
|
||||
@@ -66,24 +75,40 @@ export function DoubleEliminationMobileBracket({
|
||||
{groups.map((group) => (
|
||||
<section
|
||||
key={`${group.stage}:${group.roundNumber}`}
|
||||
aria-label={group.label}
|
||||
aria-labelledby={`${bracketId}-${group.stage}-${group.roundNumber}`}
|
||||
>
|
||||
<h4 className="mb-2 text-xs font-bold text-content-muted">
|
||||
<h4
|
||||
id={`${bracketId}-${group.stage}-${group.roundNumber}`}
|
||||
className="mb-2 text-xs font-bold text-content-muted"
|
||||
aria-label={group.accessibleLabel}
|
||||
>
|
||||
{group.label}
|
||||
</h4>
|
||||
<div className="space-y-3">
|
||||
{group.seriesIds.map((seriesId) => {
|
||||
const series = seriesById.get(seriesId);
|
||||
if (!series) return null;
|
||||
const node = nodeById.get(seriesId);
|
||||
const accessibilityLabel =
|
||||
getSeriesScoreCardAccessibleLabel(
|
||||
series,
|
||||
node?.accessibleLabel,
|
||||
teamById,
|
||||
);
|
||||
return (
|
||||
<div key={seriesId}>
|
||||
<SeriesScoreCard
|
||||
series={series}
|
||||
displayLabel={nodeById.get(seriesId)?.label}
|
||||
displayLabel={node?.label}
|
||||
teamById={teamById}
|
||||
variant="bracket"
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
<MobileRoutes
|
||||
layout={layout}
|
||||
seriesId={seriesId}
|
||||
seriesLabel={node?.accessibleLabel ?? "경기"}
|
||||
/>
|
||||
<MobileRoutes layout={layout} seriesId={seriesId} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -101,19 +126,25 @@ export function DoubleEliminationMobileBracket({
|
||||
function MobileRoutes({
|
||||
layout,
|
||||
seriesId,
|
||||
seriesLabel,
|
||||
}: {
|
||||
layout: DoubleEliminationBracketLayout;
|
||||
seriesId: SeriesId;
|
||||
seriesLabel: string;
|
||||
}) {
|
||||
const routes = layout.connectors.filter(
|
||||
(connector) => connector.fromSeriesId === seriesId,
|
||||
);
|
||||
if (routes.length === 0) return null;
|
||||
return (
|
||||
<ul className="mt-1.5 space-y-0.5 border-l border-base-content/10 pl-2 text-[11px] text-content-muted">
|
||||
<ul
|
||||
className="mt-1.5 space-y-0.5 border-l border-base-content/10 pl-2 text-[11px] text-content-muted"
|
||||
aria-label={`${seriesLabel} 연결 경로`}
|
||||
>
|
||||
{routes.map((route) => (
|
||||
<li key={`${route.select}:${route.toSeriesId}:${route.toSlot}`}>
|
||||
{route.label}
|
||||
<span aria-hidden="true">{route.label}</span>
|
||||
<span className="sr-only">{route.accessibleLabel}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import type {
|
||||
SeriesConnectorView,
|
||||
SeriesId,
|
||||
SeriesSlot,
|
||||
} from "@lolympus/contracts";
|
||||
import type { BracketConnectorKind } from "./double-elimination-bracket-layout";
|
||||
|
||||
export interface BracketFocusConnector {
|
||||
fromSeriesId: SeriesId;
|
||||
select: SeriesConnectorView["from"]["select"];
|
||||
toSeriesId: SeriesId;
|
||||
toSlot: SeriesSlot;
|
||||
}
|
||||
|
||||
export interface BracketFocusState {
|
||||
seriesIds: ReadonlySet<SeriesId>;
|
||||
connectorKeys: ReadonlySet<string>;
|
||||
}
|
||||
|
||||
export interface HorizontalScrollMetrics {
|
||||
scrollLeft: number;
|
||||
scrollWidth: number;
|
||||
clientWidth: number;
|
||||
}
|
||||
|
||||
export interface HorizontalOverflowCues {
|
||||
showStart: boolean;
|
||||
showEnd: boolean;
|
||||
}
|
||||
|
||||
export function bracketConnectorKey(connector: BracketFocusConnector): string {
|
||||
return `${connector.fromSeriesId}:${connector.select}:${connector.toSeriesId}:${connector.toSlot}`;
|
||||
}
|
||||
|
||||
export function getBracketConnectorColorClass(
|
||||
kind: BracketConnectorKind,
|
||||
focused = false,
|
||||
): string {
|
||||
if (kind === "winner") return "text-bracket-winner";
|
||||
return focused ? "text-base-content" : "text-base-content/55";
|
||||
}
|
||||
|
||||
export function getBracketFocusState(
|
||||
connectors: readonly BracketFocusConnector[],
|
||||
activeSeriesId: SeriesId | null,
|
||||
): BracketFocusState {
|
||||
if (!activeSeriesId) {
|
||||
return {
|
||||
seriesIds: new Set(),
|
||||
connectorKeys: new Set(),
|
||||
};
|
||||
}
|
||||
|
||||
const seriesIds = new Set<SeriesId>([activeSeriesId]);
|
||||
const connectorKeys = new Set<string>();
|
||||
for (const connector of connectors) {
|
||||
if (
|
||||
connector.fromSeriesId !== activeSeriesId &&
|
||||
connector.toSeriesId !== activeSeriesId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
seriesIds.add(connector.fromSeriesId);
|
||||
seriesIds.add(connector.toSeriesId);
|
||||
connectorKeys.add(bracketConnectorKey(connector));
|
||||
}
|
||||
|
||||
return { seriesIds, connectorKeys };
|
||||
}
|
||||
|
||||
export function getHorizontalOverflowCues({
|
||||
scrollLeft,
|
||||
scrollWidth,
|
||||
clientWidth,
|
||||
}: HorizontalScrollMetrics): HorizontalOverflowCues {
|
||||
const threshold = 1;
|
||||
const maxScrollLeft = Math.max(0, scrollWidth - clientWidth);
|
||||
if (maxScrollLeft <= threshold) {
|
||||
return { showStart: false, showEnd: false };
|
||||
}
|
||||
return {
|
||||
showStart: scrollLeft > threshold,
|
||||
showEnd: scrollLeft < maxScrollLeft - threshold,
|
||||
};
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export type BracketConnectorKind = "winner" | "loser" | "reset";
|
||||
export const DOUBLE_ELIMINATION_BRACKET_GEOMETRY = {
|
||||
boardPadding: 12,
|
||||
columnWidth: 228,
|
||||
columnGap: 32,
|
||||
columnGap: 40,
|
||||
cardBorderWidth: SERIES_SCORE_CARD_GEOMETRY.borderWidth,
|
||||
cardHeight: SERIES_SCORE_CARD_GEOMETRY.height,
|
||||
cardHeaderHeight: SERIES_SCORE_CARD_GEOMETRY.headerHeight,
|
||||
@@ -29,6 +29,7 @@ export const DOUBLE_ELIMINATION_BRACKET_GEOMETRY = {
|
||||
export interface BracketNodeLayout {
|
||||
seriesId: SeriesId;
|
||||
label: string;
|
||||
accessibleLabel: string;
|
||||
stage: BracketStage;
|
||||
roundNumber: number;
|
||||
lane: BracketLane;
|
||||
@@ -52,6 +53,7 @@ export interface BracketConnectorLayout {
|
||||
targetY: number;
|
||||
path: string;
|
||||
label: string;
|
||||
accessibleLabel: string;
|
||||
}
|
||||
|
||||
export interface DoubleEliminationBracketConfiguration {
|
||||
@@ -63,6 +65,7 @@ export interface BracketRoundLayout {
|
||||
stage: BracketStage;
|
||||
roundNumber: number;
|
||||
label: string;
|
||||
accessibleLabel: string;
|
||||
lane: BracketLane;
|
||||
column: number;
|
||||
x: number;
|
||||
@@ -74,6 +77,7 @@ export interface MobileBracketGroup {
|
||||
stage: BracketStage;
|
||||
roundNumber: number;
|
||||
label: string;
|
||||
accessibleLabel: string;
|
||||
seriesIds: SeriesId[];
|
||||
}
|
||||
|
||||
@@ -101,6 +105,7 @@ interface NormalizedRound {
|
||||
stage: BracketStage;
|
||||
roundNumber: number;
|
||||
label: string;
|
||||
accessibleLabel: string;
|
||||
seriesIds: SeriesId[];
|
||||
}
|
||||
|
||||
@@ -169,13 +174,30 @@ export function createDoubleEliminationBracketLayout(
|
||||
export function bracketRoundLabel(
|
||||
stage: SeriesStageType,
|
||||
roundNumber?: number,
|
||||
): string {
|
||||
return formatBracketRoundLabel(stage, roundNumber, "R");
|
||||
}
|
||||
|
||||
export function bracketRoundAccessibleLabel(
|
||||
stage: SeriesStageType,
|
||||
roundNumber?: number,
|
||||
): string {
|
||||
return formatBracketRoundLabel(stage, roundNumber, "라운드");
|
||||
}
|
||||
|
||||
function formatBracketRoundLabel(
|
||||
stage: SeriesStageType,
|
||||
roundNumber: number | undefined,
|
||||
roundUnit: "R" | "라운드",
|
||||
): string {
|
||||
const round = roundNumber ?? 1;
|
||||
switch (stage) {
|
||||
case "upper":
|
||||
return round === 1 ? `브래킷 1R` : `브래킷 상위 ${round}R`;
|
||||
return round === 1
|
||||
? `브래킷 1${roundUnit}`
|
||||
: `브래킷 상위 ${round}${roundUnit}`;
|
||||
case "lower":
|
||||
return `브래킷 하위 ${round}R`;
|
||||
return `브래킷 하위 ${round}${roundUnit}`;
|
||||
case "grand-final":
|
||||
return "그랜드 파이널";
|
||||
case "reset-final":
|
||||
@@ -311,6 +333,10 @@ function normalizeRounds(
|
||||
stage: round.stage,
|
||||
roundNumber: round.roundNumber,
|
||||
label: bracketRoundLabel(round.stage, round.roundNumber),
|
||||
accessibleLabel: bracketRoundAccessibleLabel(
|
||||
round.stage,
|
||||
round.roundNumber,
|
||||
),
|
||||
seriesIds: ids,
|
||||
});
|
||||
}
|
||||
@@ -461,7 +487,12 @@ function buildNodes(
|
||||
(laneGeometry.height * (index + 0.5)) / round.seriesIds.length;
|
||||
result.push({
|
||||
seriesId,
|
||||
label: seriesName(graph.seriesById.get(seriesId), round),
|
||||
label: seriesDisplayName(round, seriesId, round.label),
|
||||
accessibleLabel: seriesDisplayName(
|
||||
round,
|
||||
seriesId,
|
||||
round.accessibleLabel,
|
||||
),
|
||||
stage: round.stage,
|
||||
roundNumber: round.roundNumber,
|
||||
lane,
|
||||
@@ -571,7 +602,8 @@ function buildConnectors(
|
||||
targetX,
|
||||
targetY,
|
||||
path: `M ${number(sourceX)} ${number(sourceY)} H ${number(verticalX)} V ${number(targetY)} H ${number(targetX)}`,
|
||||
label: connectorLabel(connector, graph),
|
||||
label: connectorLabel(connector, graph, "label"),
|
||||
accessibleLabel: connectorLabel(connector, graph, "accessibleLabel"),
|
||||
});
|
||||
}
|
||||
return result.sort(
|
||||
@@ -593,13 +625,20 @@ function buildConnectors(
|
||||
function connectorLabel(
|
||||
connector: SeriesConnectorView,
|
||||
graph: ValidatedGraph,
|
||||
labelKey: "label" | "accessibleLabel",
|
||||
): string {
|
||||
const source = graph.seriesById.get(connector.from.seriesId);
|
||||
const target = graph.seriesById.get(connector.to.seriesId);
|
||||
const sourceRound = graph.roundBySeriesId.get(connector.from.seriesId);
|
||||
const targetRound = graph.roundBySeriesId.get(connector.to.seriesId);
|
||||
const sourceName = seriesName(source, sourceRound);
|
||||
const targetName = seriesName(target, targetRound);
|
||||
const sourceName = seriesDisplayName(
|
||||
sourceRound,
|
||||
connector.from.seriesId,
|
||||
sourceRound?.[labelKey],
|
||||
);
|
||||
const targetName = seriesDisplayName(
|
||||
targetRound,
|
||||
connector.to.seriesId,
|
||||
targetRound?.[labelKey],
|
||||
);
|
||||
const selection =
|
||||
connector.from.select === "winner"
|
||||
? "승자"
|
||||
@@ -611,16 +650,16 @@ function connectorLabel(
|
||||
return `${sourceName} ${selection} → ${targetName} ${connector.to.slot} 슬롯`;
|
||||
}
|
||||
|
||||
function seriesName(
|
||||
series: DoubleEliminationCompetitionProjection["series"][number] | undefined,
|
||||
function seriesDisplayName(
|
||||
round: NormalizedRound | undefined,
|
||||
seriesId: SeriesId,
|
||||
roundLabel: string | undefined,
|
||||
): string {
|
||||
if (series?.code) return series.code;
|
||||
if (!series || !round) return "알 수 없는 경기";
|
||||
const index = round.seriesIds.indexOf(series.seriesId);
|
||||
if (!round || !roundLabel) return "알 수 없는 경기";
|
||||
const index = round.seriesIds.indexOf(seriesId);
|
||||
return round.seriesIds.length > 1
|
||||
? `${round.label} ${index + 1}경기`
|
||||
: round.label;
|
||||
? `${roundLabel} · ${index + 1}경기`
|
||||
: roundLabel;
|
||||
}
|
||||
|
||||
function connectorAnchorY(
|
||||
|
||||
Reference in new issue
Block a user