@lichess-org/chessground
Version:
lichess.org chess ui
133 lines (113 loc) • 3.02 kB
text/typescript
export type Color = (typeof colors)[number];
export type Role = (typeof roles)[number];
export type File = (typeof files)[number];
export type Rank = (typeof ranks)[number];
export type Key = 'a0' | `${File}${Rank}`;
export type FEN = string;
export type Pos = [number, number];
export interface PosAndKey {
pos: Pos;
key: Key;
}
export interface Piece {
role: Role;
color: Color;
promoted?: boolean;
}
export interface Drop {
role: Role;
key: Key;
}
export type Pieces = Map<Key, Piece>;
export type PiecesDiff = Map<Key, Piece | undefined>;
export type KeyPair = [Key, Key];
export type NumberPair = [number, number];
export type NumberQuad = [number, number, number, number];
export interface Rect {
left: number;
top: number;
width: number;
height: number;
}
export type Dests = Map<Key, Key[]>;
export interface Elements {
board: HTMLElement;
wrap: HTMLElement;
container: HTMLElement;
ghost?: HTMLElement;
shapes?: SVGElement;
custom?: SVGElement;
shapesBelow?: SVGElement;
customBelow?: SVGElement;
autoPieces?: HTMLElement;
}
export interface Dom {
elements: Elements;
bounds: Memo<DOMRectReadOnly>;
redraw: () => void;
redrawNow: (skipSvg?: boolean) => void;
unbind?: Unbind;
destroyed?: boolean;
}
export interface Exploding {
stage: number;
keys: readonly Key[];
}
export interface MoveMetadata {
premove: boolean;
ctrlKey?: boolean;
holdTime?: number;
captured?: Piece;
predrop?: boolean;
}
export interface SetPremoveMetadata {
ctrlKey?: boolean;
}
export type MouchEvent = Event & Partial<MouseEvent & TouchEvent>;
export interface KeyedNode extends HTMLElement {
cgKey: Key;
}
export interface PieceNode extends KeyedNode {
tagName: 'PIECE';
cgPiece: string;
cgAnimating?: boolean;
cgFading?: boolean;
cgDragging?: boolean;
cgScale?: number;
}
export interface SquareNode extends KeyedNode {
tagName: 'SQUARE';
}
export interface Memo<A> {
(): A;
clear: () => void;
}
export interface Timer {
start: () => void;
cancel: () => void;
stop: () => number;
}
export type Redraw = () => void;
export type Unbind = () => void;
export type Milliseconds = number;
export type KHz = number;
export const colors = ['white', 'black'] as const;
export const roles = ['pawn', 'knight', 'bishop', 'rook', 'queen', 'king'] as const;
export const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] as const;
export const ranks = ['1', '2', '3', '4', '5', '6', '7', '8'] as const;
export type RanksPosition = 'left' | 'right';
export type BrushColor = 'green' | 'red' | 'blue' | 'yellow';
export type SquareClasses = Map<Key, string>;
export type DirectionalCheck = (x1: number, y1: number, x2: number, y2: number) => boolean;
export type MobilityContext = {
orig: PosAndKey;
dest: PosAndKey;
role: Role;
allPieces: Pieces;
friendlies: Pieces;
enemies: Pieces;
color: Color;
rookFilesFriendlies: number[];
lastMove: Key[] | undefined;
};
export type Mobility = (ctx: MobilityContext) => boolean;