react-chessboard-ui 1.7.4 → 2.0.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.
@@ -1672,7 +1672,7 @@ var stateToFEN = function stateToFEN(state, currentColor, countMoves) {
1672
1672
  return positionsFEN + " " + colorFEN + " " + casttlingFEN + " " + beatedFieldFEN + " " + blackMoves + " " + countMoves;
1673
1673
  };
1674
1674
 
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"};
1675
+ 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
1676
 
1677
1677
  var CHESS_PIECES_MAP = {
1678
1678
  'pawn-white': function pawnWhite(size) {
@@ -1874,36 +1874,41 @@ var CHESS_PIECES_MAP = {
1874
1874
  }
1875
1875
  };
1876
1876
 
1877
- var DEFAULT_CELL_SIZE = 92;
1878
- var DEFAULT_FIGURE_SIZE_PERCENT = 80;
1879
- var FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1877
+ var DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1880
1878
  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
1879
  var DEFAULT_ARROW_COLOR = '#6ac2fd';
1886
- var DEFAULT_MARKED_CELL_COLOR = '#3697ce';
1887
- var DEFAULT_CHECKED_CELL_COLOR = '#e95b5c';
1888
1880
  var DEFAULT_PIECES_MAP = CHESS_PIECES_MAP;
1889
- var DEFAULT_CSS_HIDE_PIECES_EFFECT = styles.hiddenFigureEffect;
1890
1881
  var DEFAULT_SHOW_MOVES_TRAIL = true;
1891
1882
  var DEFAULT_HIDE_PIECES_HANDLER = function DEFAULT_HIDE_PIECES_HANDLER(figure) {
1892
1883
  figure.color === 'white' ? figure.position = [8, figure.position[1]] : figure.position = [-1, figure.position[1]];
1893
1884
  };
1885
+ var DEFAULT_SQUARE_SIZE = 92;
1886
+ var DEFAULT_PIECE_SIZE_PERCENT = 80;
1887
+ var DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME = styles.hiddenFigureEffect;
1888
+ var DEFAULT_LIGHT_SQUARE_CLASS_NAME = undefined;
1889
+ var DEFAULT_DARK_SQUARE_CLASS_NAME = undefined;
1890
+ var DEFAULT_PICKED_SQUARE_CLASS_NAME = undefined;
1891
+ var DEFAULT_CHECKED_SQUARE_CLASS_NAME = undefined;
1892
+ var DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME = undefined;
1893
+ var DEFAULT_SELECTED_SQUARE_CLASS_NAME = undefined;
1894
+ var DEFAULT_HOLDED_PIECE_CLASS_NAME = undefined;
1895
+ var DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME = undefined;
1894
1896
  var DEFAULT_CHESSBORD_CONFIG = {
1895
- cellSize: DEFAULT_CELL_SIZE,
1896
- figureSizePercent: DEFAULT_FIGURE_SIZE_PERCENT,
1897
+ squareSize: DEFAULT_SQUARE_SIZE,
1898
+ pieceSizePercent: DEFAULT_PIECE_SIZE_PERCENT,
1899
+ lightSquareClassName: DEFAULT_LIGHT_SQUARE_CLASS_NAME,
1900
+ darkSquareClassName: DEFAULT_DARK_SQUARE_CLASS_NAME,
1901
+ pickedSquareClassName: DEFAULT_PICKED_SQUARE_CLASS_NAME,
1902
+ selectedSquareClassName: DEFAULT_SELECTED_SQUARE_CLASS_NAME,
1903
+ holdedPieceClassName: DEFAULT_HOLDED_PIECE_CLASS_NAME,
1904
+ checkedSquareClassName: DEFAULT_CHECKED_SQUARE_CLASS_NAME,
1905
+ squareHighlightClassName: DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME,
1897
1906
  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,
1907
+ factorForSizeCircleMark: DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK,
1908
+ possibleMoveMarkClassName: DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME,
1902
1909
  arrowColor: DEFAULT_ARROW_COLOR,
1903
- markedCellColor: DEFAULT_MARKED_CELL_COLOR,
1904
- checkedCellColor: DEFAULT_CHECKED_CELL_COLOR,
1905
1910
  piecesMap: DEFAULT_PIECES_MAP,
1906
- cssHidePieceEffect: DEFAULT_CSS_HIDE_PIECES_EFFECT,
1911
+ hidePieceEffectClassName: DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME,
1907
1912
  showMovesTrail: DEFAULT_SHOW_MOVES_TRAIL,
1908
1913
  onHidePieces: DEFAULT_HIDE_PIECES_HANDLER
1909
1914
  };
@@ -1983,12 +1988,7 @@ var calcAngle = function calcAngle(start, end) {
1983
1988
  };
1984
1989
  var getChessBoardConfig = function getChessBoardConfig(config) {
1985
1990
  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;
1991
+ return _extends({}, DEFAULT_CHESSBORD_CONFIG, config);
1992
1992
  };
1993
1993
  var getFiguresByColor = function getFiguresByColor(color, forPawnTransform) {
1994
1994
  if (forPawnTransform === void 0) {
@@ -2018,7 +2018,7 @@ var correctGrabbingPosByScroll = function correctGrabbingPosByScroll(pos) {
2018
2018
  return [pos[0] - window.scrollX, pos[1] - window.scrollY];
2019
2019
  };
2020
2020
  var correctGrabbingPosForArrow = function correctGrabbingPosForArrow(pos, boardConfig) {
2021
- return [pos[0] * boardConfig.cellSize + (boardConfig.cellSize / 2 - 10), pos[1] * boardConfig.cellSize + boardConfig.cellSize / 2];
2021
+ return [pos[0] * boardConfig.squareSize + (boardConfig.squareSize / 2 - 10), pos[1] * boardConfig.squareSize + boardConfig.squareSize / 2];
2022
2022
  };
2023
2023
  var createHtmlReversedStateHolder = function createHtmlReversedStateHolder() {
2024
2024
  if (!window) return;
@@ -2049,17 +2049,18 @@ var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
2049
2049
  className: styles.row,
2050
2050
  key: "cells-layout-" + j
2051
2051
  }, getFilledArrayBySize(size).map(function (_, i) {
2052
+ var _cn;
2052
2053
  return React.createElement("div", {
2053
2054
  style: {
2054
- width: boardConfig.cellSize,
2055
- height: boardConfig.cellSize,
2056
- backgroundColor: getIsLightCell(j, i) ? boardConfig.whiteCellColor : boardConfig.blackCellColor
2055
+ width: boardConfig.squareSize,
2056
+ height: boardConfig.squareSize
2057
2057
  },
2058
+ 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
2059
  key: "cells-layout-" + i
2059
2060
  }, movesTrail && (movesTrail[0][0] === i && movesTrail[0][1] === j || movesTrail[1][0] === i && movesTrail[1][1] === j) && React.createElement("div", {
2060
- className: styles.movesTrail
2061
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2061
2062
  }), moveHighlight && (moveHighlight[0][0] === i && moveHighlight[0][1] === j || moveHighlight[1][0] === i && moveHighlight[1][1] === j) && React.createElement("div", {
2062
- className: styles.movesTrail
2063
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2063
2064
  }));
2064
2065
  }));
2065
2066
  }));
@@ -2196,20 +2197,20 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2196
2197
  });
2197
2198
  }, [reversed, initialState]);
2198
2199
  return React.createElement("div", {
2199
- className: styles.figuresLayout
2200
+ className: styles.piecesLayout
2200
2201
  }, actualState.map(function (figure, i) {
2201
2202
  var _cn;
2202
2203
  return React.createElement("div", {
2203
2204
  key: i,
2204
- className: cn([styles.figure], (_cn = {}, _cn[boardConfig.cssHidePieceEffect] = figure.beated, _cn)),
2205
+ className: cn([styles.piece], (_cn = {}, _cn[boardConfig.hidePieceEffectClassName] = figure.beated, _cn)),
2205
2206
  style: {
2206
- top: boardConfig.cellSize * figure.position[1] + "px",
2207
- left: boardConfig.cellSize * figure.position[0] + "px",
2207
+ top: boardConfig.squareSize * figure.position[1] + "px",
2208
+ left: boardConfig.squareSize * figure.position[0] + "px",
2208
2209
  transition: !!change && animated ? 'all .15s ease-out' : 'none',
2209
- width: boardConfig.cellSize,
2210
- height: boardConfig.cellSize
2210
+ width: boardConfig.squareSize,
2211
+ height: boardConfig.squareSize
2211
2212
  }
2212
- }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2213
+ }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2213
2214
  }));
2214
2215
  };
2215
2216
 
@@ -2283,8 +2284,8 @@ var ChessBoardControlLayout = function ChessBoardControlLayout(props) {
2283
2284
  key: "control-layout-" + i,
2284
2285
  className: styles.controlCell,
2285
2286
  style: {
2286
- width: boardConfig.cellSize,
2287
- height: boardConfig.cellSize
2287
+ width: boardConfig.squareSize,
2288
+ height: boardConfig.squareSize
2288
2289
  },
2289
2290
  onClick: function onClick() {
2290
2291
  return handleClick([i, j]);
@@ -2738,7 +2739,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2738
2739
  return hasCheck(cell, currentColor, linesWithCheck);
2739
2740
  };
2740
2741
  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];
2742
+ var startPos = [(pos[0] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2 - 10, (pos[1] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2];
2742
2743
  setStartArrowCoord(startPos);
2743
2744
  };
2744
2745
  var endRenderArrow = function endRenderArrow(_ref3) {
@@ -2841,16 +2842,16 @@ var HoldedFigure = function HoldedFigure(props) {
2841
2842
  boardConfig = props.boardConfig;
2842
2843
  var isCanShowFigure = holdedFigure && grabbingPos[0] > -1 && grabbingPos[1] > -1;
2843
2844
  return isCanShowFigure && React.createElement("div", {
2844
- className: cn([styles.figure, styles.holdedFigure]),
2845
+ className: cn([styles.piece, styles.holdedPiece]),
2845
2846
  style: {
2846
2847
  position: 'fixed',
2847
2848
  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
2849
+ top: grabbingPos[1] - boardConfig.squareSize / 2 + "px",
2850
+ left: grabbingPos[0] - boardConfig.squareSize / 2 + "px",
2851
+ width: boardConfig.squareSize,
2852
+ height: boardConfig.squareSize
2852
2853
  }
2853
- }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%"));
2854
+ }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%"));
2854
2855
  };
2855
2856
 
2856
2857
  var BASE_BOARD_SIZE$2 = 8;
@@ -2877,27 +2878,23 @@ var ChessBoardInteractiveLayout = function ChessBoardInteractiveLayout(props) {
2877
2878
  }, getFilledArrayBySize(size).map(function (_, i) {
2878
2879
  var _cn, _cn2;
2879
2880
  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)),
2881
+ 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
2882
  key: "interactive-layout-" + i,
2882
2883
  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'
2884
+ width: boardConfig.squareSize,
2885
+ height: boardConfig.squareSize
2888
2886
  }
2889
2887
  }, 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)),
2888
+ className: cn([styles.piece, styles.holdedPiece], (_cn2 = {}, _cn2[styles.bluredPiece] = grabbingPos[0] !== -1, _cn2)),
2891
2889
  style: {
2892
- width: boardConfig.cellSize,
2893
- height: boardConfig.cellSize
2890
+ width: boardConfig.squareSize,
2891
+ height: boardConfig.squareSize
2894
2892
  }
2895
- }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2896
- className: styles.possibleMoveMark,
2893
+ }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2894
+ className: cn([styles.possibleMoveMark, boardConfig.possibleMoveMarkClassName]),
2897
2895
  style: {
2898
- width: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2899
- height: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2900
- backgroundColor: boardConfig.circleMarkColor
2896
+ width: boardConfig.squareSize / boardConfig.factorForSizeCircleMark,
2897
+ height: boardConfig.squareSize / boardConfig.factorForSizeCircleMark
2901
2898
  }
2902
2899
  }));
2903
2900
  }));
@@ -2963,19 +2960,19 @@ var FigurePicker = function FigurePicker(props) {
2963
2960
  onSelect(figure);
2964
2961
  }, [onSelect]);
2965
2962
  return React.createElement("div", {
2966
- className: styles.figurePicker
2963
+ className: styles.piecePicker
2967
2964
  }, getFiguresByColor(color, forPawnTransform).map(function (figure) {
2968
2965
  return React.createElement("div", {
2969
2966
  key: figure.type,
2970
- className: styles.figurePickerItem,
2967
+ className: styles.piecePickerItem,
2971
2968
  style: {
2972
- width: boardConfig.cellSize,
2973
- height: boardConfig.cellSize
2969
+ width: boardConfig.squareSize,
2970
+ height: boardConfig.squareSize
2974
2971
  },
2975
2972
  onClick: function onClick() {
2976
2973
  return handleChange(figure);
2977
2974
  }
2978
- }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2975
+ }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2979
2976
  }));
2980
2977
  };
2981
2978
 
@@ -3090,7 +3087,7 @@ var ChessBoard = function ChessBoard(props) {
3090
3087
  onRightClick: markCell,
3091
3088
  onGrabbingCell: handleGrabbingCell
3092
3089
  }), showFigurePicker && React.createElement("div", {
3093
- className: styles.chessBoardFigurePicker
3090
+ className: styles.chessBoardPiecePicker
3094
3091
  }, React.createElement(FigurePicker, {
3095
3092
  boardConfig: boardConfig,
3096
3093
  color: currentColor,