react-chessboard-ui 1.7.4 → 2.1.0

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.
@@ -642,6 +642,7 @@ JSChessEngine.checkPossibleCastling = function (state, kingPos, castlingPath, re
642
642
  });
643
643
  if (castlinPathWithFigures.length > 0) return false;
644
644
  var isPossibleCastling = true;
645
+ if (castlingPathWithoutRook.length > 2) castlingPathWithoutRook.pop();
645
646
  for (var i = 0; i < allAttackedPositionsByEnemys.length; i++) {
646
647
  var attackedPos = allAttackedPositionsByEnemys[i];
647
648
  for (var j = 0; j < castlingPathWithoutRook.length; j++) {
@@ -1672,7 +1673,7 @@ var stateToFEN = function stateToFEN(state, currentColor, countMoves) {
1672
1673
  return positionsFEN + " " + colorFEN + " " + casttlingFEN + " " + beatedFieldFEN + " " + blackMoves + " " + countMoves;
1673
1674
  };
1674
1675
 
1675
- var styles = {"chessBoard":"_3XI6H","figuresLayout":"_2SyRK","controlLayout":"_3OVc8","controlLayoutGrabbing":"_G0IIl","interactiveLayout":"_3THn5","selectedCell":"_3vcXe","controlCell":"_2yJs1","interactiveCell":"_27yHq","possibleMoveMark":"_UYGA_","row":"_2XKSc","cell":"_ssFQn","cellLight":"_1407I","figure":"_19mE-","holdedFigure":"_3u_-s","bluredFigure":"_3SfMJ","hiddenFigureEffect":"_2YKzU","markedCell":"_Zly-L","checkedCell":"_31pmr","arrow":"_12Bbd","arrowEnd":"_1BC3I","figurePicker":"_13OXq","figurePickerItem":"_16zCe","chessBoardFigurePicker":"_1ZGj2","movesTrail":"_1RqCc"};
1676
+ var styles = {"chessBoard":"_3XI6H","figuresLayout":"_2SyRK","controlLayout":"_3OVc8","controlLayoutGrabbing":"_G0IIl","interactiveLayout":"_3THn5","selectedSquare":"_1YsOr","pickedSquare":"_3MMcp","checkedSquare":"_KLkVN","interactiveCell":"_27yHq","possibleMoveMark":"_UYGA_","row":"_2XKSc","piece":"_2QHnf","holdedPiece":"_3z25q","bluredPiece":"_10meo","hiddenFigureEffect":"_2YKzU","arrow":"_12Bbd","arrowEnd":"_1BC3I","piecePicker":"_3gVhA","piecePickerItem":"_3EtmA","chessBoardPiecePicker":"_2xZM1","movesTrail":"_1RqCc","lightSquare":"_1B0qo","darkSquare":"_1NBqS"};
1676
1677
 
1677
1678
  var CHESS_PIECES_MAP = {
1678
1679
  'pawn-white': function pawnWhite(size) {
@@ -1874,36 +1875,41 @@ var CHESS_PIECES_MAP = {
1874
1875
  }
1875
1876
  };
1876
1877
 
1877
- var DEFAULT_CELL_SIZE = 92;
1878
- var DEFAULT_FIGURE_SIZE_PERCENT = 80;
1879
- var FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1878
+ var DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1880
1879
  var DEFAULT_CIRCLE_MARK_COLOR = '#3697ce';
1881
- var DEFAULT_WHITE_CELL_COLOR = '#fafafc';
1882
- var DEFAULT_BLACK_CELL_COLOR = '#d8d9e6';
1883
- var DEFAULT_SELECTED_CELL_COLOR = '#e3f1fe';
1884
- var DEFAULT_SELECTED_CELL_BORDER = '3px solid #6ac2fd';
1885
1880
  var DEFAULT_ARROW_COLOR = '#6ac2fd';
1886
- var DEFAULT_MARKED_CELL_COLOR = '#3697ce';
1887
- var DEFAULT_CHECKED_CELL_COLOR = '#e95b5c';
1888
1881
  var DEFAULT_PIECES_MAP = CHESS_PIECES_MAP;
1889
- var DEFAULT_CSS_HIDE_PIECES_EFFECT = styles.hiddenFigureEffect;
1890
1882
  var DEFAULT_SHOW_MOVES_TRAIL = true;
1891
1883
  var DEFAULT_HIDE_PIECES_HANDLER = function DEFAULT_HIDE_PIECES_HANDLER(figure) {
1892
1884
  figure.color === 'white' ? figure.position = [8, figure.position[1]] : figure.position = [-1, figure.position[1]];
1893
1885
  };
1886
+ var DEFAULT_SQUARE_SIZE = 92;
1887
+ var DEFAULT_PIECE_SIZE_PERCENT = 80;
1888
+ var DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME = styles.hiddenFigureEffect;
1889
+ var DEFAULT_LIGHT_SQUARE_CLASS_NAME = undefined;
1890
+ var DEFAULT_DARK_SQUARE_CLASS_NAME = undefined;
1891
+ var DEFAULT_PICKED_SQUARE_CLASS_NAME = undefined;
1892
+ var DEFAULT_CHECKED_SQUARE_CLASS_NAME = undefined;
1893
+ var DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME = undefined;
1894
+ var DEFAULT_SELECTED_SQUARE_CLASS_NAME = undefined;
1895
+ var DEFAULT_HOLDED_PIECE_CLASS_NAME = undefined;
1896
+ var DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME = undefined;
1894
1897
  var DEFAULT_CHESSBORD_CONFIG = {
1895
- cellSize: DEFAULT_CELL_SIZE,
1896
- figureSizePercent: DEFAULT_FIGURE_SIZE_PERCENT,
1898
+ squareSize: DEFAULT_SQUARE_SIZE,
1899
+ pieceSizePercent: DEFAULT_PIECE_SIZE_PERCENT,
1900
+ lightSquareClassName: DEFAULT_LIGHT_SQUARE_CLASS_NAME,
1901
+ darkSquareClassName: DEFAULT_DARK_SQUARE_CLASS_NAME,
1902
+ pickedSquareClassName: DEFAULT_PICKED_SQUARE_CLASS_NAME,
1903
+ selectedSquareClassName: DEFAULT_SELECTED_SQUARE_CLASS_NAME,
1904
+ holdedPieceClassName: DEFAULT_HOLDED_PIECE_CLASS_NAME,
1905
+ checkedSquareClassName: DEFAULT_CHECKED_SQUARE_CLASS_NAME,
1906
+ squareHighlightClassName: DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME,
1897
1907
  circleMarkColor: DEFAULT_CIRCLE_MARK_COLOR,
1898
- whiteCellColor: DEFAULT_WHITE_CELL_COLOR,
1899
- blackCellColor: DEFAULT_BLACK_CELL_COLOR,
1900
- selectedCellColor: DEFAULT_SELECTED_CELL_COLOR,
1901
- selectedCellBorder: DEFAULT_SELECTED_CELL_BORDER,
1908
+ factorForSizeCircleMark: DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK,
1909
+ possibleMoveMarkClassName: DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME,
1902
1910
  arrowColor: DEFAULT_ARROW_COLOR,
1903
- markedCellColor: DEFAULT_MARKED_CELL_COLOR,
1904
- checkedCellColor: DEFAULT_CHECKED_CELL_COLOR,
1905
1911
  piecesMap: DEFAULT_PIECES_MAP,
1906
- cssHidePieceEffect: DEFAULT_CSS_HIDE_PIECES_EFFECT,
1912
+ hidePieceEffectClassName: DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME,
1907
1913
  showMovesTrail: DEFAULT_SHOW_MOVES_TRAIL,
1908
1914
  onHidePieces: DEFAULT_HIDE_PIECES_HANDLER
1909
1915
  };
@@ -1983,12 +1989,7 @@ var calcAngle = function calcAngle(start, end) {
1983
1989
  };
1984
1990
  var getChessBoardConfig = function getChessBoardConfig(config) {
1985
1991
  if (!config) return DEFAULT_CHESSBORD_CONFIG;
1986
- var configKeyes = Object.keys(DEFAULT_CHESSBORD_CONFIG);
1987
- var buildedConfig = {};
1988
- configKeyes.forEach(function (key) {
1989
- buildedConfig[key] = config[key] || DEFAULT_CHESSBORD_CONFIG[key];
1990
- });
1991
- return buildedConfig;
1992
+ return _extends({}, DEFAULT_CHESSBORD_CONFIG, config);
1992
1993
  };
1993
1994
  var getFiguresByColor = function getFiguresByColor(color, forPawnTransform) {
1994
1995
  if (forPawnTransform === void 0) {
@@ -2018,7 +2019,7 @@ var correctGrabbingPosByScroll = function correctGrabbingPosByScroll(pos) {
2018
2019
  return [pos[0] - window.scrollX, pos[1] - window.scrollY];
2019
2020
  };
2020
2021
  var correctGrabbingPosForArrow = function correctGrabbingPosForArrow(pos, boardConfig) {
2021
- return [pos[0] * boardConfig.cellSize + (boardConfig.cellSize / 2 - 10), pos[1] * boardConfig.cellSize + boardConfig.cellSize / 2];
2022
+ return [pos[0] * boardConfig.squareSize + (boardConfig.squareSize / 2 - 10), pos[1] * boardConfig.squareSize + boardConfig.squareSize / 2];
2022
2023
  };
2023
2024
  var createHtmlReversedStateHolder = function createHtmlReversedStateHolder() {
2024
2025
  if (!window) return;
@@ -2049,17 +2050,18 @@ var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
2049
2050
  className: styles.row,
2050
2051
  key: "cells-layout-" + j
2051
2052
  }, getFilledArrayBySize(size).map(function (_, i) {
2053
+ var _cn;
2052
2054
  return React.createElement("div", {
2053
2055
  style: {
2054
- width: boardConfig.cellSize,
2055
- height: boardConfig.cellSize,
2056
- backgroundColor: getIsLightCell(j, i) ? boardConfig.whiteCellColor : boardConfig.blackCellColor
2056
+ width: boardConfig.squareSize,
2057
+ height: boardConfig.squareSize
2057
2058
  },
2059
+ className: cn((_cn = {}, _cn[styles.lightSquare] = !boardConfig.lightSquareClassName && getIsLightCell(j, i), _cn[styles.darkSquare] = !boardConfig.darkSquareClassName && !getIsLightCell(j, i), _cn[boardConfig.lightSquareClassName] = !!boardConfig.lightSquareClassName && getIsLightCell(j, i), _cn[boardConfig.darkSquareClassName] = !!boardConfig.darkSquareClassName && !getIsLightCell(j, i), _cn)),
2058
2060
  key: "cells-layout-" + i
2059
2061
  }, movesTrail && (movesTrail[0][0] === i && movesTrail[0][1] === j || movesTrail[1][0] === i && movesTrail[1][1] === j) && React.createElement("div", {
2060
- className: styles.movesTrail
2062
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2061
2063
  }), moveHighlight && (moveHighlight[0][0] === i && moveHighlight[0][1] === j || moveHighlight[1][0] === i && moveHighlight[1][1] === j) && React.createElement("div", {
2062
- className: styles.movesTrail
2064
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2063
2065
  }));
2064
2066
  }));
2065
2067
  }));
@@ -2196,20 +2198,20 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2196
2198
  });
2197
2199
  }, [reversed, initialState]);
2198
2200
  return React.createElement("div", {
2199
- className: styles.figuresLayout
2201
+ className: styles.piecesLayout
2200
2202
  }, actualState.map(function (figure, i) {
2201
2203
  var _cn;
2202
2204
  return React.createElement("div", {
2203
2205
  key: i,
2204
- className: cn([styles.figure], (_cn = {}, _cn[boardConfig.cssHidePieceEffect] = figure.beated, _cn)),
2206
+ className: cn([styles.piece], (_cn = {}, _cn[boardConfig.hidePieceEffectClassName] = figure.beated, _cn)),
2205
2207
  style: {
2206
- top: boardConfig.cellSize * figure.position[1] + "px",
2207
- left: boardConfig.cellSize * figure.position[0] + "px",
2208
+ top: boardConfig.squareSize * figure.position[1] + "px",
2209
+ left: boardConfig.squareSize * figure.position[0] + "px",
2208
2210
  transition: !!change && animated ? 'all .15s ease-out' : 'none',
2209
- width: boardConfig.cellSize,
2210
- height: boardConfig.cellSize
2211
+ width: boardConfig.squareSize,
2212
+ height: boardConfig.squareSize
2211
2213
  }
2212
- }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2214
+ }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2213
2215
  }));
2214
2216
  };
2215
2217
 
@@ -2283,8 +2285,8 @@ var ChessBoardControlLayout = function ChessBoardControlLayout(props) {
2283
2285
  key: "control-layout-" + i,
2284
2286
  className: styles.controlCell,
2285
2287
  style: {
2286
- width: boardConfig.cellSize,
2287
- height: boardConfig.cellSize
2288
+ width: boardConfig.squareSize,
2289
+ height: boardConfig.squareSize
2288
2290
  },
2289
2291
  onClick: function onClick() {
2290
2292
  return handleClick([i, j]);
@@ -2738,7 +2740,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2738
2740
  return hasCheck(cell, currentColor, linesWithCheck);
2739
2741
  };
2740
2742
  var startRenderArrow = function startRenderArrow(pos) {
2741
- var startPos = [(pos[0] + 1) * boardConfig.cellSize - boardConfig.cellSize / 2 - 10, (pos[1] + 1) * boardConfig.cellSize - boardConfig.cellSize / 2];
2743
+ var startPos = [(pos[0] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2 - 10, (pos[1] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2];
2742
2744
  setStartArrowCoord(startPos);
2743
2745
  };
2744
2746
  var endRenderArrow = function endRenderArrow(_ref3) {
@@ -2841,16 +2843,16 @@ var HoldedFigure = function HoldedFigure(props) {
2841
2843
  boardConfig = props.boardConfig;
2842
2844
  var isCanShowFigure = holdedFigure && grabbingPos[0] > -1 && grabbingPos[1] > -1;
2843
2845
  return isCanShowFigure && React.createElement("div", {
2844
- className: cn([styles.figure, styles.holdedFigure]),
2846
+ className: cn([styles.piece, styles.holdedPiece]),
2845
2847
  style: {
2846
2848
  position: 'fixed',
2847
2849
  zIndex: 6,
2848
- top: grabbingPos[1] - boardConfig.cellSize / 2 + "px",
2849
- left: grabbingPos[0] - boardConfig.cellSize / 2 + "px",
2850
- width: boardConfig.cellSize,
2851
- height: boardConfig.cellSize
2850
+ top: grabbingPos[1] - boardConfig.squareSize / 2 + "px",
2851
+ left: grabbingPos[0] - boardConfig.squareSize / 2 + "px",
2852
+ width: boardConfig.squareSize,
2853
+ height: boardConfig.squareSize
2852
2854
  }
2853
- }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%"));
2855
+ }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%"));
2854
2856
  };
2855
2857
 
2856
2858
  var BASE_BOARD_SIZE$2 = 8;
@@ -2877,27 +2879,23 @@ var ChessBoardInteractiveLayout = function ChessBoardInteractiveLayout(props) {
2877
2879
  }, getFilledArrayBySize(size).map(function (_, i) {
2878
2880
  var _cn, _cn2;
2879
2881
  return React.createElement("div", {
2880
- className: cn(styles.interactiveCell, (_cn = {}, _cn[styles.selectedCell] = selectedPos[0] === i && selectedPos[1] === j, _cn[styles.markedCell] = checkIsPossibleMove(markedCells, [i, j]), _cn[styles.checkedCell] = onHasCheck([i, j]), _cn)),
2882
+ className: cn(styles.interactiveCell, (_cn = {}, _cn[styles.selectedSquare + " " + boardConfig.selectedSquareClassName] = selectedPos[0] === i && selectedPos[1] === j, _cn[styles.pickedSquare + " " + boardConfig.pickedSquareClassName] = checkIsPossibleMove(markedCells, [i, j]), _cn[styles.checkedSquare + " " + boardConfig.checkedSquareClassName] = onHasCheck([i, j]), _cn)),
2881
2883
  key: "interactive-layout-" + i,
2882
2884
  style: {
2883
- width: boardConfig.cellSize,
2884
- height: boardConfig.cellSize,
2885
- backgroundColor: selectedPos[0] === i && selectedPos[1] === j ? boardConfig.selectedCellColor : 'transparent',
2886
- border: selectedPos[0] === i && selectedPos[1] === j ? boardConfig.selectedCellBorder : 'none',
2887
- boxShadow: checkIsPossibleMove(markedCells, [i, j]) ? "inset 0 0 30px " + boardConfig.markedCellColor : onHasCheck([i, j]) ? "inset 0 0 30px " + boardConfig.checkedCellColor : 'none'
2885
+ width: boardConfig.squareSize,
2886
+ height: boardConfig.squareSize
2888
2887
  }
2889
2888
  }, selectedPos[0] === i && selectedPos[1] === j && holdedFigure && React.createElement("div", {
2890
- className: cn([styles.figure, styles.holdedFigure], (_cn2 = {}, _cn2[styles.bluredFigure] = grabbingPos[0] !== -1, _cn2)),
2889
+ className: cn([styles.piece, styles.holdedPiece], (_cn2 = {}, _cn2[styles.bluredPiece] = grabbingPos[0] !== -1, _cn2)),
2891
2890
  style: {
2892
- width: boardConfig.cellSize,
2893
- height: boardConfig.cellSize
2891
+ width: boardConfig.squareSize,
2892
+ height: boardConfig.squareSize
2894
2893
  }
2895
- }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2896
- className: styles.possibleMoveMark,
2894
+ }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2895
+ className: cn([styles.possibleMoveMark, boardConfig.possibleMoveMarkClassName]),
2897
2896
  style: {
2898
- width: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2899
- height: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2900
- backgroundColor: boardConfig.circleMarkColor
2897
+ width: boardConfig.squareSize / boardConfig.factorForSizeCircleMark,
2898
+ height: boardConfig.squareSize / boardConfig.factorForSizeCircleMark
2901
2899
  }
2902
2900
  }));
2903
2901
  }));
@@ -2963,19 +2961,19 @@ var FigurePicker = function FigurePicker(props) {
2963
2961
  onSelect(figure);
2964
2962
  }, [onSelect]);
2965
2963
  return React.createElement("div", {
2966
- className: styles.figurePicker
2964
+ className: styles.piecePicker
2967
2965
  }, getFiguresByColor(color, forPawnTransform).map(function (figure) {
2968
2966
  return React.createElement("div", {
2969
2967
  key: figure.type,
2970
- className: styles.figurePickerItem,
2968
+ className: styles.piecePickerItem,
2971
2969
  style: {
2972
- width: boardConfig.cellSize,
2973
- height: boardConfig.cellSize
2970
+ width: boardConfig.squareSize,
2971
+ height: boardConfig.squareSize
2974
2972
  },
2975
2973
  onClick: function onClick() {
2976
2974
  return handleChange(figure);
2977
2975
  }
2978
- }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2976
+ }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2979
2977
  }));
2980
2978
  };
2981
2979
 
@@ -3090,7 +3088,7 @@ var ChessBoard = function ChessBoard(props) {
3090
3088
  onRightClick: markCell,
3091
3089
  onGrabbingCell: handleGrabbingCell
3092
3090
  }), showFigurePicker && React.createElement("div", {
3093
- className: styles.chessBoardFigurePicker
3091
+ className: styles.chessBoardPiecePicker
3094
3092
  }, React.createElement(FigurePicker, {
3095
3093
  boardConfig: boardConfig,
3096
3094
  color: currentColor,