Created
August 12, 2021 02:32
-
-
Save 370417/b238b563a1cb88de6307f8f3a24e8152 to your computer and use it in GitHub Desktop.
Types for chessground 4.4.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Chessground = { | |
/** reconfigure the instance */ | |
set( | |
options: Exclude< | |
Options, | |
{ | |
viewOnly: boolean; | |
minimalDom: boolean; | |
} | |
> | |
): void; | |
/** sets the king of this color in check. if no color is provided, the current turn color is used */ | |
setCheck(color: Color): void; | |
/** change the view angle */ | |
toggleViewOrientation(): void; | |
/** perform a move programmatically */ | |
move(orig: Key, dest: Key): void; | |
/** add and/or remove arbitrary pieces on the board */ | |
setPieces( | |
pieces: { | |
[K in Key]: Piece | null; | |
} | |
): void; | |
/** play the current premove, if any */ | |
playPremove(): void; | |
/** cancel the current premove, if any */ | |
cancelPremove(): void; | |
/** cancel the current move being made */ | |
cancelMove(): void; | |
/** cancels current move and prevent further ones */ | |
stop(): void; | |
/** get the view angle */ | |
getOrientation(): Color; | |
/** get pieces on the board */ | |
getPieces(): { | |
[K in Key]: Piece; | |
}; | |
/** get the material difference between white and black */ | |
getMaterialDiff(): { | |
[K in Color]: { | |
[K in Role]: number; | |
}; | |
}; | |
/** get the current FEN position */ | |
getFen(): string; | |
}; | |
type Role = 'king' | 'queen' | 'bishop' | 'knight' | 'rook' | 'pawn'; | |
type Piece = { | |
color?: Color; | |
role?: Role; | |
}; | |
type Color = 'white' | 'black'; | |
type chessground = (container: HTMLElement, options: Options) => Chessground; | |
type Key = string; | |
type Options = { | |
/** or leave null for initial positio */ | |
fen?: string | null; | |
/** board orientation (or view angle) */ | |
orientation?: Color; | |
/** turn to play */ | |
turnColor?: Color; | |
/** square currently in check */ | |
check?: Key | null; | |
/** squares part of the last move */ | |
lastMove?: [Key, Key] | null; | |
/** square currently selected */ | |
selected?: Key | null; | |
/** display board coordinates as square ::after elements */ | |
coordinates?: boolean; | |
/** don't bind events: the user will never be able to move pieces around */ | |
viewOnly?: boolean; | |
/** don't use square elements. Optimization to use only with viewOnly */ | |
minimalDom?: boolean; | |
disableContextMenu?: boolean; | |
highlight?: { | |
/** add last-move class to squares */ | |
lastMove?: boolean; | |
/** add check class to squares */ | |
check?: boolean; | |
/** add drag-over class to square when dragging over it */ | |
dragOver?: boolean; | |
}; | |
animation?: { | |
/** enable piece animations, moving and fading */ | |
enabled?: boolean; | |
/** animation duration in milliseconds */ | |
duration?: number; | |
}; | |
movable?: { | |
/** all moves are valid - board editor */ | |
free?: boolean; | |
/** color that can move */ | |
color?: Color | 'both' | null; | |
/** valid moves */ | |
dests?: | |
| { | |
[K in Key]: [Key, Key]; | |
} | |
| null; | |
/** when a piece is dropped outside the board */ | |
dropOff?: 'revert' | 'trash'; | |
/** add the move-dest class to squares */ | |
showDests?: boolean; | |
events?: { | |
/** called after the move has been played */ | |
after?: (orig: Key, dest: Key, metadata: any) => void; | |
}; | |
}; | |
premovable?: { | |
/** allow premoves for color that can not move */ | |
enabled?: boolean; | |
/** add the premove-dest class to squares */ | |
showDests?: boolean; | |
/** keys of the current saved premove */ | |
current?: [Key, Key] | null; | |
events?: { | |
/** called after the premove has been set */ | |
set?: (orig: Key, dest: Key) => void; | |
// called after the premove has been unset | |
unset?: () => void; | |
}; | |
}; | |
draggable?: { | |
/** allow moves & premoves to use drag'n drop */ | |
enabled?: boolean; | |
/** minimum distance to initiate a drag, in pixels */ | |
distance?: number; | |
/** display big square target; intended for mobile */ | |
squareTarget?: boolean; | |
/** center the piece on cursor at drag start */ | |
centerPiece?: boolean; | |
/** show ghost of piece being dragged */ | |
showGhost?: boolean; | |
}; | |
selectable?: { | |
/** disable to enforce dragging over click-click move */ | |
enabled?: boolean; | |
}; | |
drawable?: { | |
/** enable SVG circle and arrow drawing on the board */ | |
enabled?: boolean; | |
}; | |
events?: { | |
/** called after the situation changes on the board */ | |
change?: () => void; | |
/** called after a piece has been moved */ | |
move?: (orig: Key, dest: Key, capturedPiece: Piece | null) => void; | |
/** called when a square is selected */ | |
select?: (key: Key) => void; | |
}; | |
}; | |
export = chessground; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment