react-chessboard-ui 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/ChessBoard/Arrow.d.ts +8 -0
- package/dist/ChessBoard/ArrowLayout.d.ts +11 -0
- package/dist/ChessBoard/ChessBoard.d.ts +13 -0
- package/dist/ChessBoard/ChessBoardCellsLayout.d.ts +8 -0
- package/dist/ChessBoard/ChessBoardControlLayout.d.ts +16 -0
- package/dist/ChessBoard/ChessBoardFiguresLayout.d.ts +11 -0
- package/dist/ChessBoard/ChessBoardInteractiveLayout.d.ts +15 -0
- package/dist/ChessBoard/FigurePicker.d.ts +11 -0
- package/dist/ChessBoard/HoldedFigure.d.ts +10 -0
- package/dist/ChessBoard/chessPieciesMap.d.ts +2 -0
- package/dist/ChessBoard/constants.d.ts +13 -0
- package/dist/ChessBoard/index.d.ts +1 -0
- package/dist/ChessBoard/models.d.ts +27 -0
- package/dist/ChessBoard/useChessBoardInteractive.d.ts +41 -0
- package/dist/ChessBoard/utils.d.ts +51 -0
- package/dist/JSChessEngine/FEN.utils.d.ts +51 -0
- package/dist/JSChessEngine/JSChessEngine.d.ts +383 -0
- package/dist/JSChessEngine/__tests__/FEN.utils.test.d.ts +1 -0
- package/dist/JSChessEngine/__tests__/chessState.mock.d.ts +3 -0
- package/dist/JSChessEngine/chess.consts.d.ts +49 -0
- package/dist/JSChessEngine/index.d.ts +3 -0
- package/dist/index.css +132 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2835 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +2817 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# rechess
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/rechess) [](https://standardjs.com)
|
|
4
|
+
|
|
5
|
+
## ❗️ ATTENTION ❗️
|
|
6
|
+
This is a package that is currently in active development.
|
|
7
|
+
|
|
8
|
+
<img src="./blob/ChessBoard.png?raw=true" width="400px">
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install rechess
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
or
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add rechess
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
```tsx
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { ChessBoard } from 'rechess'; // ChessBoard is a base component of rechess
|
|
26
|
+
|
|
27
|
+
import 'rechess/dist/index.css'; // required import css for ChessBoard
|
|
28
|
+
|
|
29
|
+
export const App = () => {
|
|
30
|
+
|
|
31
|
+
// This handler for example
|
|
32
|
+
const handleChangePosition = (data) => {
|
|
33
|
+
console.log(data);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div>
|
|
38
|
+
<ChessBoard
|
|
39
|
+
FEN="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
|
40
|
+
onChange={handleChangePosition}
|
|
41
|
+
color="white"
|
|
42
|
+
reversed={reversed} // For black
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Designer
|
|
50
|
+
[LinkedIn: Tatiana Utbanova](https://www.linkedin.com/in/tatiana-utbanova-6415b8271/)
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT © [](https://github.com/)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { CellPos } from "../JSChessEngine";
|
|
3
|
+
import { ArrowCoords, ChessBoardConfig } from "./models";
|
|
4
|
+
declare type ArrowLayoutType = {
|
|
5
|
+
startArrowCoord: CellPos;
|
|
6
|
+
arrowsCoords: ArrowCoords[];
|
|
7
|
+
grabbingPos: CellPos;
|
|
8
|
+
boardConfig: ChessBoardConfig;
|
|
9
|
+
};
|
|
10
|
+
export declare const ArrowLayout: FC<ArrowLayoutType>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GameResult, MoveData } from "../JSChessEngine";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
import { ChangeMove, ChessBoardConfig } from "./models";
|
|
4
|
+
declare type ChessBoardProps = {
|
|
5
|
+
FEN: string;
|
|
6
|
+
onChange: (moveData: MoveData) => void;
|
|
7
|
+
onEndGame: (result: GameResult) => void;
|
|
8
|
+
change?: ChangeMove;
|
|
9
|
+
reversed?: boolean;
|
|
10
|
+
config?: Partial<ChessBoardConfig>;
|
|
11
|
+
};
|
|
12
|
+
export declare const ChessBoard: FC<ChessBoardProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { ChessBoardConfig } from "./models";
|
|
3
|
+
declare type ChessBoardCellsLayoutProps = {
|
|
4
|
+
size?: number;
|
|
5
|
+
boardConfig: ChessBoardConfig;
|
|
6
|
+
};
|
|
7
|
+
export declare const ChessBoardCellsLayout: FC<ChessBoardCellsLayoutProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { CellPos } from "../JSChessEngine";
|
|
3
|
+
import { ChessBoardConfig } from "./models";
|
|
4
|
+
declare type ChessBoardControlLayoutProps = {
|
|
5
|
+
size?: number;
|
|
6
|
+
boardConfig: ChessBoardConfig;
|
|
7
|
+
onClick: (position: CellPos) => void;
|
|
8
|
+
onGrabStart: (position: CellPos) => void;
|
|
9
|
+
onGrabStartRight: (position: CellPos) => void;
|
|
10
|
+
onGrabEnd: (position: CellPos) => void;
|
|
11
|
+
onGrabEndRight: (position: CellPos) => void;
|
|
12
|
+
onGrabbing: (x: number, y: number) => void;
|
|
13
|
+
onRightClick: (position: CellPos) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const ChessBoardControlLayout: FC<ChessBoardControlLayoutProps>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cell } from "../JSChessEngine";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
import { ChangeMove, ChessBoardConfig } from "./models";
|
|
4
|
+
declare type ChessBoardFiguresLayoutProps = {
|
|
5
|
+
initialState: Cell[][];
|
|
6
|
+
change?: ChangeMove;
|
|
7
|
+
reversed?: boolean;
|
|
8
|
+
boardConfig: ChessBoardConfig;
|
|
9
|
+
};
|
|
10
|
+
export declare const ChessBoardFiguresLayout: FC<ChessBoardFiguresLayoutProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { CellPos, Figure } from "../JSChessEngine";
|
|
3
|
+
import { ChessBoardConfig } from "./models";
|
|
4
|
+
declare type ChessBoardInteractiveLayoutProps = {
|
|
5
|
+
size?: number;
|
|
6
|
+
boardConfig: ChessBoardConfig;
|
|
7
|
+
selectedPos: CellPos;
|
|
8
|
+
possibleMoves: CellPos[];
|
|
9
|
+
markedCells: CellPos[];
|
|
10
|
+
holdedFigure?: Figure;
|
|
11
|
+
grabbingPos: CellPos;
|
|
12
|
+
onHasCheck: (cellPos: CellPos) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const ChessBoardInteractiveLayout: FC<ChessBoardInteractiveLayoutProps>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Figure, FigureColor } from '../JSChessEngine';
|
|
3
|
+
import { ChessBoardConfig } from './models';
|
|
4
|
+
interface FigurePickerProps {
|
|
5
|
+
boardConfig: ChessBoardConfig;
|
|
6
|
+
color: FigureColor;
|
|
7
|
+
forPawnTransform?: boolean;
|
|
8
|
+
onSelect: (figure: Figure) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const FigurePicker: FC<FigurePickerProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CellPos, Figure } from "../JSChessEngine";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
import { ChessBoardConfig } from "./models";
|
|
4
|
+
declare type HoldedFigureProps = {
|
|
5
|
+
holdedFigure?: Figure;
|
|
6
|
+
grabbingPos: CellPos;
|
|
7
|
+
boardConfig: ChessBoardConfig;
|
|
8
|
+
};
|
|
9
|
+
export declare const HoldedFigure: FC<HoldedFigureProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChessBoardConfig } from "./models";
|
|
2
|
+
export declare const DEFAULT_CELL_SIZE = 92;
|
|
3
|
+
export declare const FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
|
|
4
|
+
export declare const DEFAULT_CIRCLE_MARK_COLOR = "#3697ce";
|
|
5
|
+
export declare const DEFAULT_WHITE_CELL_COLOR = "#fafafc";
|
|
6
|
+
export declare const DEFAULT_BLACK_CELL_COLOR = "#d8d9e6";
|
|
7
|
+
export declare const DEFAULT_SELECTED_CELL_COLOR = "#e3f1fe";
|
|
8
|
+
export declare const DEFAULT_SELECTED_CELL_BORDER = "3px solid #6ac2fd";
|
|
9
|
+
export declare const DEFAULT_ARROW_COLOR = "#6ac2fd";
|
|
10
|
+
export declare const DEFAULT_MARKED_CELL_COLOR = "#3697ce";
|
|
11
|
+
export declare const DEFAULT_CHECKED_CELL_COLOR = "#e95b5c";
|
|
12
|
+
export declare const DEFAULT_PIECES_MAP: import("./models").ChessPiecesMap;
|
|
13
|
+
export declare const DEFAULT_CHESSBORD_CONFIG: ChessBoardConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChessBoard';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CellPos, Figure, MoveData } from "../JSChessEngine";
|
|
3
|
+
export interface ChessPiecesMap {
|
|
4
|
+
[key: string]: (size: string) => JSX.Element;
|
|
5
|
+
}
|
|
6
|
+
export declare type ChessBoardConfig = {
|
|
7
|
+
cellSize: number;
|
|
8
|
+
whiteCellColor: string;
|
|
9
|
+
blackCellColor: string;
|
|
10
|
+
selectedCellColor: string;
|
|
11
|
+
selectedCellBorder: string;
|
|
12
|
+
markedCellColor: string;
|
|
13
|
+
circleMarkColor: string;
|
|
14
|
+
arrowColor: string;
|
|
15
|
+
checkedCellColor: string;
|
|
16
|
+
piecesMap: ChessPiecesMap;
|
|
17
|
+
};
|
|
18
|
+
export declare type ChangeMove = {
|
|
19
|
+
move: MoveData;
|
|
20
|
+
withTransition?: boolean;
|
|
21
|
+
attackedPos?: CellPos;
|
|
22
|
+
transformTo?: Figure;
|
|
23
|
+
};
|
|
24
|
+
export declare type ArrowCoords = {
|
|
25
|
+
start: number[];
|
|
26
|
+
end: number[];
|
|
27
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Cell, CellPos, Figure, FigureColor, GameResult, MoveData } from "../JSChessEngine";
|
|
3
|
+
import { ArrowCoords, ChangeMove, ChessBoardConfig } from "./models";
|
|
4
|
+
declare type UseChessBoardInteractiveProps = {
|
|
5
|
+
config?: Partial<ChessBoardConfig>;
|
|
6
|
+
onChange: (moveData: MoveData) => void;
|
|
7
|
+
onEndGame: (result: GameResult) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const useChessBoardInteractive: (props: UseChessBoardInteractiveProps) => {
|
|
10
|
+
fromPos: CellPos;
|
|
11
|
+
newMove: ChangeMove;
|
|
12
|
+
boardConfig: ChessBoardConfig;
|
|
13
|
+
markedCells: CellPos[];
|
|
14
|
+
grabbingPos: CellPos;
|
|
15
|
+
actualState: Cell[][];
|
|
16
|
+
currentColor: FigureColor;
|
|
17
|
+
arrowsCoords: ArrowCoords[];
|
|
18
|
+
initialState: Cell[][];
|
|
19
|
+
holdedFigure: Figure;
|
|
20
|
+
possibleMoves: CellPos[];
|
|
21
|
+
linesWithCheck: CellPos[][];
|
|
22
|
+
startArrowCoord: CellPos;
|
|
23
|
+
showFigurePicker: boolean;
|
|
24
|
+
markCell: (cellPos: CellPos) => void;
|
|
25
|
+
setNewMove: import("react").Dispatch<import("react").SetStateAction<ChangeMove>>;
|
|
26
|
+
handleClick: (cellPos: CellPos) => void;
|
|
27
|
+
clearFromPos: () => void;
|
|
28
|
+
handleGrabEnd: (cellPos: CellPos, withTransition?: boolean) => void;
|
|
29
|
+
handleGrabbing: (x: number, y: number) => void;
|
|
30
|
+
endRenderArrow: ([x, y]: CellPos) => void;
|
|
31
|
+
setActualState: import("react").Dispatch<import("react").SetStateAction<Cell[][]>>;
|
|
32
|
+
setCurrentColor: import("react").Dispatch<import("react").SetStateAction<FigureColor>>;
|
|
33
|
+
selectClickFrom: (cellPos: CellPos) => void;
|
|
34
|
+
selectHoverFrom: (cellPos: CellPos) => void;
|
|
35
|
+
setInitialState: import("react").Dispatch<import("react").SetStateAction<Cell[][]>>;
|
|
36
|
+
startRenderArrow: (pos: CellPos) => void;
|
|
37
|
+
reverseChessBoard: () => void;
|
|
38
|
+
getHasCheckByCellPos: ([x, y]: CellPos) => boolean;
|
|
39
|
+
handleSelectFigurePicker: (figure: Figure) => void;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Cell, CellPos, Figure, FigureColor, MoveData } from "../JSChessEngine";
|
|
2
|
+
import { ChessBoardConfig } from "./models";
|
|
3
|
+
/**
|
|
4
|
+
* Возвращает класс для фигуры в клетке
|
|
5
|
+
*/
|
|
6
|
+
export declare const getFigureCSS: (figure: Figure) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Возвращает белая ли клетка
|
|
9
|
+
*/
|
|
10
|
+
export declare const getIsLightCell: (rowId: number, cellId: number) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Функция, которая просто создает массив размером size
|
|
13
|
+
*/
|
|
14
|
+
export declare const getFilledArrayBySize: (size: number) => number[];
|
|
15
|
+
/**
|
|
16
|
+
* Возвращает только массив фигурам у которых
|
|
17
|
+
* есть поле position
|
|
18
|
+
*/
|
|
19
|
+
export declare const mapCellsToFiguresArray: (boardState: Cell[][]) => Figure[];
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param possibleMoves Список возможных ходов
|
|
23
|
+
* @param position позиция для проверки
|
|
24
|
+
*/
|
|
25
|
+
export declare const checkIsPossibleMove: (possibleMoves: CellPos[], position: CellPos) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Проверяет находится ли проверяемая позиция в
|
|
28
|
+
* наборе позиций
|
|
29
|
+
* @param positions набор позиций
|
|
30
|
+
* @param pos позиция
|
|
31
|
+
*/
|
|
32
|
+
export declare const checkPositionsHas: (positions: CellPos[] | undefined, pos: CellPos) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Проверяет, является ли ход рокеровкой
|
|
35
|
+
* @param moveData
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare const checkIsCastlingMove: (moveData: MoveData) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Проверка клетки, на то есть ли шах
|
|
41
|
+
*/
|
|
42
|
+
export declare const hasCheck: (cell: Cell, currentColor: FigureColor, linesWithCheck: CellPos[][]) => boolean;
|
|
43
|
+
export declare const degrees: (a: number, b: number) => number;
|
|
44
|
+
export declare const calcAngle: (start: number[], end: number[]) => number;
|
|
45
|
+
export declare const getChessBoardConfig: (config: Partial<ChessBoardConfig> | undefined) => ChessBoardConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Возвращает массив фигур по заданому цвету
|
|
48
|
+
* @param color цвет фигур
|
|
49
|
+
* @param forPawnTransform только фигуры для превращения пешки
|
|
50
|
+
*/
|
|
51
|
+
export declare const getFiguresByColor: (color: FigureColor, forPawnTransform?: boolean) => Figure[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { FigureColor, Cell } from './JSChessEngine';
|
|
2
|
+
/**
|
|
3
|
+
* Вовзвращет позицию клетки по состоянию fen
|
|
4
|
+
* @param positionFEN позиция из FEN вида e4
|
|
5
|
+
* @returns координаты для определения клетки на доске
|
|
6
|
+
*/
|
|
7
|
+
export declare const getPositionByFEN: (positionFEN: string) => number[];
|
|
8
|
+
/**
|
|
9
|
+
* Проверяет по части FEN возможность рокировки
|
|
10
|
+
* и обновляет состояние доски для рокировки
|
|
11
|
+
* @param castlingNotation часть FEN-нотации описывающая рокировку
|
|
12
|
+
* @param state состояние доски
|
|
13
|
+
* @returns обновленное состояние доски
|
|
14
|
+
*/
|
|
15
|
+
export declare const prepareCastlingByFEN: (castlingNotation: string, state: Cell[][]) => Cell[][];
|
|
16
|
+
/**
|
|
17
|
+
* Конвертирует часть FEN-нотации с фигурами в состояние доски
|
|
18
|
+
* @param state состояние доски
|
|
19
|
+
*/
|
|
20
|
+
export declare const partFENtoState: (notation: string) => Cell[][];
|
|
21
|
+
/**
|
|
22
|
+
* Создает состояние доски
|
|
23
|
+
* по FEN-нотации
|
|
24
|
+
* rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
|
|
25
|
+
* @param notation Описание текущего состояния от Stockfish https://hxim.github.io/Stockfish-Evaluation-Guide/
|
|
26
|
+
*/
|
|
27
|
+
export declare const FENtoGameState: (FEN: string) => {
|
|
28
|
+
boardState: Cell[][];
|
|
29
|
+
currentColor: FigureColor;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Возвращает FEN битое поле из состояние доски
|
|
33
|
+
* @param state состояние доски
|
|
34
|
+
*/
|
|
35
|
+
export declare const getBeatedCellFENfromState: (state: Cell[][]) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Возвращает FEN положение фигур на доске
|
|
38
|
+
* @param state состояние доски
|
|
39
|
+
*/
|
|
40
|
+
export declare const getFENpositionsFromState: (state: Cell[][]) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Возвращает FEN-рокеровку из состояния доски
|
|
43
|
+
* @param state состояние доски
|
|
44
|
+
*/
|
|
45
|
+
export declare const getFENcastlingFromState: (state: Cell[][]) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Преобразует состояние доски в FEN
|
|
48
|
+
* @param state
|
|
49
|
+
* @param countMoves
|
|
50
|
+
*/
|
|
51
|
+
export declare const stateToFEN: (state: Cell[][], currentColor: FigureColor, countMoves?: number) => string;
|