Highlight connected routes, add readable round labels and accessible path descriptions, widen routing gaps, and centralize brand colors for winner progression.
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
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,
|
|
};
|
|
}
|