UNPKG

react-chess-game-fix

Version:

react-chess-game is a React component bridging chess.js with react-chessboard to offer a full-featured, ready-to-integrate chess board experience.

116 lines (107 loc) 3.43 kB
import * as React$1 from 'react'; import React__default from 'react'; import { Chessboard } from 'react-chessboard'; import * as chess_js from 'chess.js'; import { Color, Chess } from 'chess.js'; type Sound = "check" | "move" | "capture" | "gameOver"; interface ChessGameProps extends React__default.ComponentProps<typeof Chessboard> { } interface RootProps { fen?: string; orientation?: Color; } type useChessGameProps = { fen?: string; orientation?: Color; }; declare const useChessGame: ({ fen, orientation: initialOrientation, }?: useChessGameProps) => { game: Chess; currentFen: string; currentPosition: string; orientation: Color; currentMoveIndex: number; isLatestMove: boolean; info: { turn: Color; isPlayerTurn: boolean; isOpponentTurn: boolean; moveNumber: number; lastMove: chess_js.Move | undefined; isCheck: boolean; isCheckmate: boolean; isDraw: boolean; isStalemate: boolean; isThreefoldRepetition: boolean; isInsufficientMaterial: boolean; isGameOver: boolean; isDrawn: boolean; hasPlayerWon: boolean; hasPlayerLost: boolean; }; methods: { makeMove: (move: Parameters<Chess["move"]>[0]) => boolean; setPosition: (fen: string, orientation: Color) => void; flipBoard: () => void; goToMove: (moveIndex: number) => void; goToStart: () => void; goToEnd: () => void; goToPreviousMove: () => void; goToNextMove: () => void; undoMove: () => boolean; }; }; declare const useChessGameContext: () => { game: chess_js.Chess; currentFen: string; currentPosition: string; orientation: chess_js.Color; currentMoveIndex: number; isLatestMove: boolean; info: { turn: chess_js.Color; isPlayerTurn: boolean; isOpponentTurn: boolean; moveNumber: number; lastMove: chess_js.Move | undefined; isCheck: boolean; isCheckmate: boolean; isDraw: boolean; isStalemate: boolean; isThreefoldRepetition: boolean; isInsufficientMaterial: boolean; isGameOver: boolean; isDrawn: boolean; hasPlayerWon: boolean; hasPlayerLost: boolean; }; methods: { makeMove: (move: string | { from: string; to: string; promotion?: string | undefined; }) => boolean; setPosition: (fen: string, orientation: chess_js.Color) => void; flipBoard: () => void; goToMove: (moveIndex: number) => void; goToStart: () => void; goToEnd: () => void; goToPreviousMove: () => void; goToNextMove: () => void; undoMove: () => boolean; }; }; type ChessGameContextType = ReturnType<typeof useChessGame>; type KeyboardControlsProps = { controls?: KeyboardControls; }; type KeyboardControls = Record<string, (context: ChessGameContextType) => void>; declare const KeyboardControls: React.FC<KeyboardControlsProps>; declare const ChessGame: { Root: React$1.FC<React$1.PropsWithChildren<RootProps>>; Board: React$1.FC<ChessGameProps>; Sounds: React$1.FC<Partial<Record<Sound, string>>>; KeyboardControls: React$1.FC<{ controls?: KeyboardControls | undefined; }>; }; export { ChessGame, useChessGame, useChessGameContext };