kokopu-react 1.9.0 → 1.9.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.
@@ -4,73 +4,39 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _reactDraggable = _interopRequireDefault(require("react-draggable"));
13
-
14
10
  var _kokopu = require("kokopu");
15
-
16
11
  var _colorsets2 = _interopRequireDefault(require("./impl/colorsets"));
17
-
18
12
  var _piecesets2 = _interopRequireDefault(require("./impl/piecesets"));
19
-
20
13
  var _ArrowTip = _interopRequireDefault(require("./impl/ArrowTip"));
21
-
22
14
  var _Motion = _interopRequireDefault(require("./impl/Motion"));
23
-
24
15
  var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
25
-
26
16
  var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
27
-
28
17
  var _i18n = _interopRequireDefault(require("./i18n"));
29
-
30
18
  var _markers = require("./markers");
31
-
32
19
  var _util = require("./impl/util");
33
-
34
20
  require("./css/chessboard.css");
35
-
36
21
  require("./css/arrow.css");
37
-
38
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
39
-
40
23
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
41
-
42
24
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
-
44
25
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
45
-
46
26
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
47
-
48
27
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
49
-
50
28
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
51
-
52
29
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
53
-
54
30
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
-
56
31
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
57
-
58
32
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
59
-
60
33
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
61
-
62
34
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
63
-
64
35
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
65
-
66
36
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
67
-
68
37
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
69
-
70
38
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
71
-
72
39
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
73
-
74
40
  var TURN_FLAG_SPACING_FACTOR = 0.1;
75
41
  var RANK_COORDINATE_WIDTH_FACTOR = 1;
76
42
  var FILE_COORDINATE_HEIGHT_FACTOR = 1.4;
@@ -80,21 +46,17 @@ var ARROW_TIP_OFFSET_FACTOR = 0.3;
80
46
  var MOTION_DURATION = 150;
81
47
  var RANK_LABELS = '12345678';
82
48
  var FILE_LABELS = 'abcdefgh';
49
+
83
50
  /**
84
51
  * SVG image representing a chessboard diagram. Optionally, the user may interact with the board (move pieces, click on squares...).
85
52
  * Annotations such as square markers or arrows can also be added to the board.
86
53
  */
87
-
88
54
  var Chessboard = /*#__PURE__*/function (_React$Component) {
89
55
  _inherits(Chessboard, _React$Component);
90
-
91
56
  var _super = _createSuper(Chessboard);
92
-
93
57
  function Chessboard(props) {
94
58
  var _this;
95
-
96
59
  _classCallCheck(this, Chessboard);
97
-
98
60
  _this = _super.call(this, props);
99
61
  _this.state = {
100
62
  inhibitedSquare: '-',
@@ -106,16 +68,13 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
106
68
  _this.arrowTipIdSuffix = (0, _util.generateRandomId)();
107
69
  return _this;
108
70
  }
109
-
110
71
  _createClass(Chessboard, [{
111
72
  key: "componentDidMount",
112
73
  value: function componentDidMount() {
113
74
  var _this2 = this;
114
-
115
75
  this.windowResizeListener = function () {
116
76
  return _this2.handleWindowResize();
117
77
  };
118
-
119
78
  window.addEventListener('resize', this.windowResizeListener);
120
79
  }
121
80
  }, {
@@ -130,10 +89,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
130
89
  key: "render",
131
90
  value: function render() {
132
91
  var _this3 = this;
133
-
134
92
  // Compute the current position.
135
93
  var info = this.getPositionAndMoveInfo();
136
-
137
94
  if (info.positionError) {
138
95
  return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
139
96
  title: _i18n["default"].INVALID_FEN_ERROR_TITLE,
@@ -145,38 +102,37 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
145
102
  message: info.message
146
103
  });
147
104
  }
148
-
149
105
  var position = info.position,
150
- move = info.move,
151
- positionBefore = info.positionBefore; // Compute the attributes.
106
+ move = info.move,
107
+ positionBefore = info.positionBefore;
152
108
 
109
+ // Compute the attributes.
153
110
  var squareSize = this.getSquareSize();
154
111
  var coordinateVisible = this.isCoordinateVisible();
155
112
  var fontSize = computeCoordinateFontSize(squareSize);
156
113
  var colorset = _colorsets2["default"][this.props.colorset];
157
114
  var pieceset = _piecesets2["default"][this.props.pieceset];
158
-
159
115
  if (isNaN(squareSize) || !colorset || !pieceset) {
160
116
  return undefined;
161
- } // Render the squares.
162
-
117
+ }
163
118
 
119
+ // Render the squares.
164
120
  var squares = [];
165
121
  (0, _kokopu.forEachSquare)(function (sq) {
166
122
  return squares.push(_this3.renderSquare(squareSize, colorset, sq));
167
- }); // Render coordinates.
123
+ });
168
124
 
125
+ // Render coordinates.
169
126
  var rankCoordinates = [];
170
127
  var fileCoordinates = [];
171
-
172
128
  if (coordinateVisible) {
173
129
  for (var c = 0; c < 8; ++c) {
174
130
  rankCoordinates.push(this.renderRankCoordinate(squareSize, fontSize, c));
175
131
  fileCoordinates.push(this.renderFileCoordinate(squareSize, fontSize, c));
176
132
  }
177
- } // Render the whole canvas.
178
-
133
+ }
179
134
 
135
+ // Render the whole canvas.
180
136
  var xmin = coordinateVisible ? Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) : 0;
181
137
  var ymin = 0;
182
138
  var xmax = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
@@ -193,7 +149,6 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
193
149
  key: "renderBoardContent",
194
150
  value: function renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset) {
195
151
  var _this4 = this;
196
-
197
152
  if (move && this.props.animated) {
198
153
  var key = positionBefore.variant() + '|' + positionBefore.fen() + '|' + move.toString();
199
154
  return /*#__PURE__*/_react["default"].createElement(_Motion["default"], {
@@ -206,42 +161,40 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
206
161
  return this.renderBoardContentStill(position, move, squareSize, colorset, pieceset);
207
162
  }
208
163
  }
164
+
209
165
  /**
210
166
  * Render the board content during the animation.
211
167
  */
212
-
213
168
  }, {
214
169
  key: "renderBoardContentAnimated",
215
170
  value: function renderBoardContentAnimated(positionBefore, move, motionCursor, squareSize, colorset, pieceset) {
216
171
  var _this5 = this;
217
-
218
172
  var pieces = [];
219
173
  (0, _kokopu.forEachSquare)(function (sq) {
220
174
  return pieces.push(_this5.renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq));
221
175
  });
222
176
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, pieces, this.renderMoveArrow(move, motionCursor, squareSize, colorset), this.renderTurnFlag((0, _kokopu.oppositeColor)(positionBefore.turn()), squareSize, pieceset));
223
177
  }
178
+
224
179
  /**
225
180
  * Render the board content when the animation has been completed (or if there is no animation).
226
181
  */
227
-
228
182
  }, {
229
183
  key: "renderBoardContentStill",
230
184
  value: function renderBoardContentStill(position, move, squareSize, colorset, pieceset) {
231
185
  var _this6 = this;
232
-
233
186
  // Compute the annotations.
234
187
  var sqm = parseMarkers(this.props.squareMarkers, _markers.parseSquareMarkers, _util.isValidSquare, _util.isValidColor);
235
188
  var txtm = parseMarkers(this.props.textMarkers, _markers.parseTextMarkers, _util.isValidSquare, function (value) {
236
189
  return value && (0, _util.isValidSymbol)(value.symbol) && (0, _util.isValidColor)(value.color);
237
190
  });
238
- var arm = parseMarkers(this.props.arrowMarkers, _markers.parseArrowMarkers, _util.isValidVector, _util.isValidColor); // Render the square-related objects.
191
+ var arm = parseMarkers(this.props.arrowMarkers, _markers.parseArrowMarkers, _util.isValidVector, _util.isValidColor);
239
192
 
193
+ // Render the square-related objects.
240
194
  var pieces = [];
241
195
  var handles = [];
242
196
  (0, _kokopu.forEachSquare)(function (sq) {
243
197
  pieces.push(_this6.renderPiece(position, squareSize, pieceset, sq));
244
-
245
198
  if (_this6.props.interactionMode) {
246
199
  handles.push(_this6.renderSquareHandle(position, squareSize, sq));
247
200
  }
@@ -252,9 +205,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
252
205
  key: "renderSquare",
253
206
  value: function renderSquare(squareSize, colorset, sq) {
254
207
  var _this$getSquareCoordi = this.getSquareCoordinates(squareSize, sq),
255
- x = _this$getSquareCoordi.x,
256
- y = _this$getSquareCoordi.y;
257
-
208
+ x = _this$getSquareCoordi.x,
209
+ y = _this$getSquareCoordi.y;
258
210
  return /*#__PURE__*/_react["default"].createElement("rect", {
259
211
  key: sq,
260
212
  x: x,
@@ -270,11 +222,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
270
222
  if (this.state.hoveredSquare === '-') {
271
223
  return undefined;
272
224
  }
273
-
274
225
  var _this$getSquareCoordi2 = this.getSquareCoordinates(squareSize, this.state.hoveredSquare),
275
- x = _this$getSquareCoordi2.x,
276
- y = _this$getSquareCoordi2.y;
277
-
226
+ x = _this$getSquareCoordi2.x,
227
+ y = _this$getSquareCoordi2.y;
278
228
  var thickness = Math.max(2, Math.round(HOVER_MARKER_THICKNESS_FACTOR * squareSize));
279
229
  var size = squareSize - thickness;
280
230
  var color = this.isEditArrowModeEnabled() ? this.props.editedArrowColor : this.props.moveArrowColor;
@@ -292,15 +242,12 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
292
242
  key: "renderPiece",
293
243
  value: function renderPiece(position, squareSize, pieceset, sq) {
294
244
  var cp = position.square(sq);
295
-
296
245
  if (cp === '-' || this.state.inhibitedSquare === sq) {
297
246
  return undefined;
298
247
  }
299
-
300
248
  var _this$getSquareCoordi3 = this.getSquareCoordinates(squareSize, sq),
301
- x = _this$getSquareCoordi3.x,
302
- y = _this$getSquareCoordi3.y;
303
-
249
+ x = _this$getSquareCoordi3.x,
250
+ y = _this$getSquareCoordi3.y;
304
251
  return /*#__PURE__*/_react["default"].createElement("image", {
305
252
  key: 'piece-' + sq,
306
253
  x: x,
@@ -314,35 +261,28 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
314
261
  key: "renderPieceAnimated",
315
262
  value: function renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq) {
316
263
  var cp = positionBefore.square(sq);
317
-
318
264
  if (cp === '-' || move.to() === sq || move.isEnPassant() && move.enPassantSquare() === sq) {
319
265
  return undefined;
320
266
  }
321
-
322
267
  var _this$getSquareCoordi4 = this.getSquareCoordinates(squareSize, sq),
323
- x = _this$getSquareCoordi4.x,
324
- y = _this$getSquareCoordi4.y;
325
-
268
+ x = _this$getSquareCoordi4.x,
269
+ y = _this$getSquareCoordi4.y;
326
270
  if (sq === move.from()) {
327
271
  var _this$getSquareCoordi5 = this.getSquareCoordinates(squareSize, move.to()),
328
- xTo = _this$getSquareCoordi5.x,
329
- yTo = _this$getSquareCoordi5.y;
330
-
272
+ xTo = _this$getSquareCoordi5.x,
273
+ yTo = _this$getSquareCoordi5.y;
331
274
  x = xTo * motionCursor + x * (1 - motionCursor);
332
275
  y = yTo * motionCursor + y * (1 - motionCursor);
333
-
334
276
  if (move.isPromotion() && motionCursor > 0.8) {
335
277
  cp = move.coloredPromotion();
336
278
  }
337
279
  } else if (move.isCastling() && sq === move.rookFrom()) {
338
280
  var _this$getSquareCoordi6 = this.getSquareCoordinates(squareSize, move.rookTo()),
339
- _xTo = _this$getSquareCoordi6.x,
340
- _yTo = _this$getSquareCoordi6.y;
341
-
281
+ _xTo = _this$getSquareCoordi6.x,
282
+ _yTo = _this$getSquareCoordi6.y;
342
283
  x = _xTo * motionCursor + x * (1 - motionCursor);
343
284
  y = _yTo * motionCursor + y * (1 - motionCursor);
344
285
  }
345
-
346
286
  return /*#__PURE__*/_react["default"].createElement("image", {
347
287
  key: 'piece-' + sq,
348
288
  x: x,
@@ -358,11 +298,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
358
298
  if (!(this.isMovePieceModeEnabled() || this.isPlayMoveModeEnabled()) || this.state.draggedSquare === '-') {
359
299
  return undefined;
360
300
  }
361
-
362
301
  var _this$getSquareCoordi7 = this.getSquareCoordinates(squareSize, this.state.draggedSquare),
363
- x = _this$getSquareCoordi7.x,
364
- y = _this$getSquareCoordi7.y;
365
-
302
+ x = _this$getSquareCoordi7.x,
303
+ y = _this$getSquareCoordi7.y;
366
304
  x = Math.min(Math.max(x + this.state.dragPosition.x, 0), 7 * squareSize);
367
305
  y = Math.min(Math.max(y + this.state.dragPosition.y, 0), 7 * squareSize);
368
306
  var cp = position.square(this.state.draggedSquare);
@@ -381,14 +319,11 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
381
319
  if (!this.isEditArrowModeEnabled() || this.state.draggedSquare === '-') {
382
320
  return undefined;
383
321
  }
384
-
385
322
  var strokeWidth = squareSize * STROKE_THICKNESS_FACTOR;
386
323
  var arrowTipId = this.getArrowTipId(this.props.editedArrowColor);
387
-
388
324
  var _this$getSquareCoordi8 = this.getSquareCoordinates(squareSize, this.state.draggedSquare),
389
- x = _this$getSquareCoordi8.x,
390
- y = _this$getSquareCoordi8.y;
391
-
325
+ x = _this$getSquareCoordi8.x,
326
+ y = _this$getSquareCoordi8.y;
392
327
  var xFrom = x + squareSize / 2;
393
328
  var yFrom = y + squareSize / 2;
394
329
  var xTo = Math.min(Math.max(x + this.state.dragPosition.x + this.state.cursorOffset.x, squareSize / 2), 15 * squareSize / 2);
@@ -408,17 +343,13 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
408
343
  key: "renderPromotionDrawer",
409
344
  value: function renderPromotionDrawer(position, squareSize, colorset, pieceset) {
410
345
  var _this7 = this;
411
-
412
346
  if (!this.state.promotionDrawer) {
413
347
  return undefined;
414
348
  }
415
-
416
349
  var _this$getSquareCoordi9 = this.getSquareCoordinates(squareSize, this.state.promotionDrawer.origin),
417
- x = _this$getSquareCoordi9.x,
418
- y = _this$getSquareCoordi9.y;
419
-
350
+ x = _this$getSquareCoordi9.x,
351
+ y = _this$getSquareCoordi9.y;
420
352
  var inverted = position.turn() === (this.props.flipped ? 'w' : 'b'); // false==top-to-bottom true==bottom-to-top
421
-
422
353
  var y0 = inverted ? y - squareSize * (this.state.promotionDrawer.buttons.length - 1) : y;
423
354
  var buttons = this.state.promotionDrawer.buttons.map(function (p, i) {
424
355
  var cp = position.turn() + p;
@@ -463,15 +394,12 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
463
394
  key: "renderSquareHandle",
464
395
  value: function renderSquareHandle(position, squareSize, sq) {
465
396
  var _this8 = this;
466
-
467
397
  var _this$getSquareCoordi10 = this.getSquareCoordinates(squareSize, sq),
468
- x = _this$getSquareCoordi10.x,
469
- y = _this$getSquareCoordi10.y;
470
-
398
+ x = _this$getSquareCoordi10.x,
399
+ y = _this$getSquareCoordi10.y;
471
400
  var dragEnabledForMovePieces = this.isMovePieceModeEnabled() && position.square(sq) !== '-';
472
401
  var dragEnabledForEditArrows = this.isEditArrowModeEnabled();
473
402
  var dragEnabledForPlayMoves = this.isPlayMoveModeEnabled() && position.isLegal() && position.square(sq).startsWith(position.turn()) && !this.state.promotionDrawer;
474
-
475
403
  if (dragEnabledForMovePieces || dragEnabledForEditArrows || dragEnabledForPlayMoves) {
476
404
  var dragPosition = this.state.draggedSquare === sq ? this.state.dragPosition : {
477
405
  x: 0,
@@ -517,17 +445,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
517
445
  key: "renderSquareMarkers",
518
446
  value: function renderSquareMarkers(sqm, squareSize, colorset) {
519
447
  var _this9 = this;
520
-
521
448
  var result = [];
522
449
  Object.entries(sqm).forEach(function (_ref) {
523
450
  var _ref2 = _slicedToArray(_ref, 2),
524
- sq = _ref2[0],
525
- color = _ref2[1];
526
-
451
+ sq = _ref2[0],
452
+ color = _ref2[1];
527
453
  var _this9$getSquareCoord = _this9.getSquareCoordinates(squareSize, sq),
528
- x = _this9$getSquareCoord.x,
529
- y = _this9$getSquareCoord.y;
530
-
454
+ x = _this9$getSquareCoord.x,
455
+ y = _this9$getSquareCoord.y;
531
456
  result.push( /*#__PURE__*/_react["default"].createElement("rect", {
532
457
  key: 'sqm-' + sq,
533
458
  className: "kokopu-annotation",
@@ -544,17 +469,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
544
469
  key: "renderTextMarkers",
545
470
  value: function renderTextMarkers(txtm, squareSize, colorset) {
546
471
  var _this10 = this;
547
-
548
472
  var result = [];
549
473
  Object.entries(txtm).forEach(function (_ref3) {
550
474
  var _ref4 = _slicedToArray(_ref3, 2),
551
- sq = _ref4[0],
552
- value = _ref4[1];
553
-
475
+ sq = _ref4[0],
476
+ value = _ref4[1];
554
477
  var _this10$getSquareCoor = _this10.getSquareCoordinates(squareSize, sq),
555
- x = _this10$getSquareCoor.x,
556
- y = _this10$getSquareCoor.y;
557
-
478
+ x = _this10$getSquareCoor.x,
479
+ y = _this10$getSquareCoor.y;
558
480
  x += squareSize / 2;
559
481
  y += squareSize / 2;
560
482
  result.push( /*#__PURE__*/_react["default"].createElement("g", {
@@ -574,38 +496,30 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
574
496
  key: "renderArrowMarkers",
575
497
  value: function renderArrowMarkers(arm, squareSize, colorset) {
576
498
  var _this11 = this;
577
-
578
499
  var result = [];
579
500
  var strokeWidth = squareSize * STROKE_THICKNESS_FACTOR;
580
501
  Object.entries(arm).forEach(function (_ref5) {
581
502
  var _ref6 = _slicedToArray(_ref5, 2),
582
- vect = _ref6[0],
583
- color = _ref6[1];
584
-
503
+ vect = _ref6[0],
504
+ color = _ref6[1];
585
505
  var from = vect.substring(0, 2);
586
506
  var to = vect.substring(2, 4);
587
-
588
507
  if (from === to) {
589
508
  return;
590
509
  }
591
-
592
510
  var _this11$getSquareCoor = _this11.getSquareCoordinates(squareSize, from),
593
- xFrom = _this11$getSquareCoor.x,
594
- yFrom = _this11$getSquareCoor.y;
595
-
511
+ xFrom = _this11$getSquareCoor.x,
512
+ yFrom = _this11$getSquareCoor.y;
596
513
  var _this11$getSquareCoor2 = _this11.getSquareCoordinates(squareSize, to),
597
- xTo = _this11$getSquareCoor2.x,
598
- yTo = _this11$getSquareCoor2.y;
599
-
514
+ xTo = _this11$getSquareCoor2.x,
515
+ yTo = _this11$getSquareCoor2.y;
600
516
  xFrom += squareSize / 2;
601
517
  yFrom += squareSize / 2;
602
518
  xTo += squareSize / 2;
603
519
  yTo += squareSize / 2;
604
520
  xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
605
521
  yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
606
-
607
522
  var arrowTipId = _this11.getArrowTipId(color);
608
-
609
523
  result.push( /*#__PURE__*/_react["default"].createElement("line", {
610
524
  key: 'arm-' + vect,
611
525
  className: "kokopu-annotation kokopu-arrow",
@@ -626,18 +540,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
626
540
  if (!move || motionCursor < 0.1 || !this.props.moveArrowVisible || move.from() === move.to()) {
627
541
  return undefined;
628
542
  }
629
-
630
543
  var _this$getSquareCoordi11 = this.getSquareCoordinates(squareSize, move.from()),
631
- xFrom = _this$getSquareCoordi11.x,
632
- yFrom = _this$getSquareCoordi11.y;
633
-
544
+ xFrom = _this$getSquareCoordi11.x,
545
+ yFrom = _this$getSquareCoordi11.y;
634
546
  xFrom += squareSize / 2;
635
547
  yFrom += squareSize / 2;
636
-
637
548
  var _this$getSquareCoordi12 = this.getSquareCoordinates(squareSize, move.to()),
638
- xTo = _this$getSquareCoordi12.x,
639
- yTo = _this$getSquareCoordi12.y;
640
-
549
+ xTo = _this$getSquareCoordi12.x,
550
+ yTo = _this$getSquareCoordi12.y;
641
551
  xTo += squareSize / 2;
642
552
  yTo += squareSize / 2;
643
553
  xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
@@ -735,11 +645,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
735
645
  key: "handleDrag",
736
646
  value: function handleDrag(sq, dragData) {
737
647
  var squareSize = this.getSquareSize();
738
-
739
648
  var _this$getSquareCoordi13 = this.getSquareCoordinates(squareSize, sq),
740
- x = _this$getSquareCoordi13.x,
741
- y = _this$getSquareCoordi13.y;
742
-
649
+ x = _this$getSquareCoordi13.x,
650
+ y = _this$getSquareCoordi13.y;
743
651
  var targetSq = this.getSquareAt(squareSize, x + dragData.x + this.state.cursorOffset.x, y + dragData.y + this.state.cursorOffset.y);
744
652
  this.setState({
745
653
  hoveredSquare: targetSq,
@@ -753,46 +661,38 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
753
661
  key: "handleDragStop",
754
662
  value: function handleDragStop(sq, dragData) {
755
663
  var squareSize = this.getSquareSize();
756
-
757
664
  var _this$getSquareCoordi14 = this.getSquareCoordinates(squareSize, sq),
758
- x = _this$getSquareCoordi14.x,
759
- y = _this$getSquareCoordi14.y;
760
-
665
+ x = _this$getSquareCoordi14.x,
666
+ y = _this$getSquareCoordi14.y;
761
667
  var targetSq = this.getSquareAt(squareSize, x + dragData.x + this.state.cursorOffset.x, y + dragData.y + this.state.cursorOffset.y);
762
668
  this.setState({
763
669
  inhibitedSquare: '-',
764
670
  draggedSquare: '-',
765
671
  hoveredSquare: '-'
766
672
  });
767
-
768
673
  if (sq === targetSq || targetSq === '-') {
769
674
  return;
770
675
  }
771
-
772
676
  if (this.isMovePieceModeEnabled() && this.props.onPieceMoved) {
773
677
  this.props.onPieceMoved(sq, targetSq);
774
678
  } else if (this.isEditArrowModeEnabled() && this.props.onArrowEdited) {
775
679
  this.props.onArrowEdited(sq, targetSq);
776
680
  } else if (this.isPlayMoveModeEnabled()) {
777
681
  var _this$getPositionAndM = this.getPositionAndMoveInfo(),
778
- position = _this$getPositionAndM.position;
779
-
682
+ position = _this$getPositionAndM.position;
780
683
  var info = position.isMoveLegal(sq, targetSq);
781
-
782
684
  if (!info) {
783
685
  return;
784
686
  }
785
-
786
687
  switch (info.status) {
787
688
  // Regular move.
788
689
  case 'regular':
789
690
  if (this.props.onMovePlayed) {
790
691
  this.props.onMovePlayed(position.notation(info()));
791
692
  }
792
-
793
693
  break;
794
- // Promotion move.
795
694
 
695
+ // Promotion move.
796
696
  case 'promotion':
797
697
  this.setState({
798
698
  inhibitedSquare: sq,
@@ -805,9 +705,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
805
705
  }
806
706
  });
807
707
  break;
708
+
808
709
  // Other cases are not supposed to happen.
809
710
  // istanbul ignore next
810
-
811
711
  default:
812
712
  break;
813
713
  }
@@ -829,7 +729,6 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
829
729
  inhibitedSquare: '-',
830
730
  promotionDrawer: false
831
731
  });
832
-
833
732
  if (this.props.onMovePlayed) {
834
733
  this.props.onMovePlayed(builder(piece));
835
734
  }
@@ -841,37 +740,37 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
841
740
  this.props.onSquareClicked(sq);
842
741
  }
843
742
  }
743
+
844
744
  /**
845
745
  * Whether the "move piece" mode is enabled or not.
846
746
  */
847
-
848
747
  }, {
849
748
  key: "isMovePieceModeEnabled",
850
749
  value: function isMovePieceModeEnabled() {
851
750
  return this.props.interactionMode === 'movePieces';
852
751
  }
752
+
853
753
  /**
854
754
  * Whether the "play move" mode is enabled or not.
855
755
  */
856
-
857
756
  }, {
858
757
  key: "isPlayMoveModeEnabled",
859
758
  value: function isPlayMoveModeEnabled() {
860
759
  return this.props.interactionMode === 'playMoves';
861
760
  }
761
+
862
762
  /**
863
763
  * Whether the "edit arrow" mode is enabled or not.
864
764
  */
865
-
866
765
  }, {
867
766
  key: "isEditArrowModeEnabled",
868
767
  value: function isEditArrowModeEnabled() {
869
768
  return this.props.interactionMode === 'editArrows' && (0, _util.isValidColor)(this.props.editedArrowColor);
870
769
  }
770
+
871
771
  /**
872
772
  * Return the (sanitized) square size.
873
773
  */
874
-
875
774
  }, {
876
775
  key: "getSquareSize",
877
776
  value: function getSquareSize() {
@@ -879,27 +778,26 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
879
778
  var limit = computeSmallScreenLimits('squareSize', this.props.smallScreenLimits, this.state.windowWidth);
880
779
  return isNaN(limit) ? squareSize : (0, _util.sanitizeInteger)(limit, _util.MIN_SQUARE_SIZE, squareSize);
881
780
  }
781
+
882
782
  /**
883
783
  * Whether the file/rank coordinates are visible or not.
884
784
  */
885
-
886
785
  }, {
887
786
  key: "isCoordinateVisible",
888
787
  value: function isCoordinateVisible() {
889
788
  var limit = computeSmallScreenLimits('coordinateVisible', this.props.smallScreenLimits, this.state.windowWidth);
890
789
  return this.props.coordinateVisible && (limit === undefined || limit);
891
790
  }
791
+
892
792
  /**
893
793
  * Return the (x,y) coordinates of the given square in the SVG canvas.
894
794
  */
895
-
896
795
  }, {
897
796
  key: "getSquareCoordinates",
898
797
  value: function getSquareCoordinates(squareSize, sq) {
899
798
  var _squareToCoordinates = (0, _kokopu.squareToCoordinates)(sq),
900
- file = _squareToCoordinates.file,
901
- rank = _squareToCoordinates.rank;
902
-
799
+ file = _squareToCoordinates.file,
800
+ rank = _squareToCoordinates.rank;
903
801
  var x = this.props.flipped ? (7 - file) * squareSize : file * squareSize;
904
802
  var y = this.props.flipped ? rank * squareSize : (7 - rank) * squareSize;
905
803
  return {
@@ -907,36 +805,34 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
907
805
  y: y
908
806
  };
909
807
  }
808
+
910
809
  /**
911
810
  * Return information regarding the currently displayed position and move, or parsing error message if something went wrong.
912
811
  */
913
-
914
812
  }, {
915
813
  key: "getPositionAndMoveInfo",
916
814
  value: function getPositionAndMoveInfo() {
917
815
  // Parse the position.
918
816
  var positionInfo = parsePosition(this.props.position);
919
-
920
817
  if (positionInfo.error) {
921
818
  return {
922
819
  positionError: true,
923
820
  moveError: true,
924
821
  message: positionInfo.message
925
822
  };
926
- } // Nothing else to do if no move is defined.
927
-
823
+ }
928
824
 
825
+ // Nothing else to do if no move is defined.
929
826
  if (!this.props.move) {
930
827
  return {
931
828
  positionError: false,
932
829
  moveError: false,
933
830
  position: positionInfo.position
934
831
  };
935
- } // Parse the move.
936
-
832
+ }
937
833
 
834
+ // Parse the move.
938
835
  var moveInfo = parseMove(positionInfo.position, this.props.move);
939
-
940
836
  if (moveInfo.error) {
941
837
  return {
942
838
  positionError: false,
@@ -944,9 +840,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
944
840
  message: moveInfo.message,
945
841
  positionBefore: positionInfo.position
946
842
  };
947
- } // Compute the position after the move and return the result.
948
-
843
+ }
949
844
 
845
+ // Compute the position after the move and return the result.
950
846
  var positionAfter = new _kokopu.Position(positionInfo.position);
951
847
  positionAfter.play(moveInfo.move);
952
848
  return {
@@ -957,10 +853,10 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
957
853
  position: positionAfter
958
854
  };
959
855
  }
856
+
960
857
  /**
961
858
  * Return the square at the given location.
962
859
  */
963
-
964
860
  }, {
965
861
  key: "getSquareAt",
966
862
  value: function getSquareAt(squareSize, x, y) {
@@ -968,15 +864,16 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
968
864
  var rank = this.props.flipped ? Math.floor(y / squareSize) : 7 - Math.floor(y / squareSize);
969
865
  return file >= 0 && file < 8 && rank >= 0 && rank < 8 ? (0, _kokopu.coordinatesToSquare)(file, rank) : '-';
970
866
  }
867
+
971
868
  /**
972
869
  * Return the DOM ID of an arrow tip with the given color.
973
870
  */
974
-
975
871
  }, {
976
872
  key: "getArrowTipId",
977
873
  value: function getArrowTipId(color) {
978
874
  return 'kokopu-arrowTip-' + color + '-' + this.arrowTipIdSuffix;
979
875
  }
876
+
980
877
  /**
981
878
  * Return the size of the chessboard, assuming it is built with the given attributes.
982
879
  *
@@ -986,7 +883,6 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
986
883
  * @returns {{width:number, height:number}}
987
884
  * @public
988
885
  */
989
-
990
886
  }], [{
991
887
  key: "size",
992
888
  value: function size(squareSize, coordinateVisible, smallScreenLimits) {
@@ -994,29 +890,26 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
994
890
  if (typeof window !== 'undefined') {
995
891
  var squareSizeLimit = computeSmallScreenLimits('squareSize', smallScreenLimits, window.innerWidth);
996
892
  var coordinateVisibleLimit = computeSmallScreenLimits('coordinateVisible', smallScreenLimits, window.innerWidth);
997
-
998
893
  if (!isNaN(squareSizeLimit)) {
999
894
  squareSize = (0, _util.sanitizeInteger)(squareSizeLimit, _util.MIN_SQUARE_SIZE, squareSize);
1000
895
  }
1001
-
1002
896
  coordinateVisible = coordinateVisible && (coordinateVisibleLimit === undefined || coordinateVisibleLimit);
1003
- } // Compute the dimensions.
1004
-
897
+ }
1005
898
 
899
+ // Compute the dimensions.
1006
900
  var width = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
1007
901
  var height = 8 * squareSize;
1008
-
1009
902
  if (coordinateVisible) {
1010
903
  var fontSize = computeCoordinateFontSize(squareSize);
1011
904
  width += Math.round(RANK_COORDINATE_WIDTH_FACTOR * fontSize);
1012
905
  height += Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
1013
906
  }
1014
-
1015
907
  return {
1016
908
  width: width,
1017
909
  height: height
1018
910
  };
1019
911
  }
912
+
1020
913
  /**
1021
914
  * Return the maximum square size that would allow the chessboard to fit in a rectangle of size `width x height`.
1022
915
  *
@@ -1027,95 +920,88 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
1027
920
  * @returns {number}
1028
921
  * @public
1029
922
  */
1030
-
1031
923
  }, {
1032
924
  key: "adaptSquareSize",
1033
925
  value: function adaptSquareSize(width, height, coordinateVisible, smallScreenLimits) {
1034
- var maxSquareSize = _util.MAX_SQUARE_SIZE; // Enforce small-screen limits, if any.
926
+ var maxSquareSize = _util.MAX_SQUARE_SIZE;
1035
927
 
928
+ // Enforce small-screen limits, if any.
1036
929
  if (typeof window !== 'undefined') {
1037
930
  var squareSizeLimit = computeSmallScreenLimits('squareSize', smallScreenLimits, window.innerWidth);
1038
931
  var coordinateVisibleLimit = computeSmallScreenLimits('coordinateVisible', smallScreenLimits, window.innerWidth);
1039
-
1040
932
  if (!isNaN(squareSizeLimit)) {
1041
933
  maxSquareSize = (0, _util.sanitizeInteger)(squareSizeLimit, _util.MIN_SQUARE_SIZE, maxSquareSize);
1042
934
  }
1043
-
1044
935
  coordinateVisible = coordinateVisible && (coordinateVisibleLimit === undefined || coordinateVisibleLimit);
1045
936
  }
1046
-
1047
937
  function isAdapted(squareSize) {
1048
938
  var actualWidth = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
1049
939
  var actualHeight = 8 * squareSize;
1050
-
1051
940
  if (coordinateVisible) {
1052
941
  var fontSize = computeCoordinateFontSize(squareSize);
1053
942
  actualWidth += Math.round(RANK_COORDINATE_WIDTH_FACTOR * fontSize);
1054
943
  actualHeight += Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
1055
944
  }
1056
-
1057
945
  return actualWidth <= width && actualHeight <= height;
1058
- } // Check min/max bounds.
1059
-
946
+ }
1060
947
 
948
+ // Check min/max bounds.
1061
949
  if (isAdapted(maxSquareSize)) {
1062
950
  return maxSquareSize;
1063
951
  } else if (!isAdapted(_util.MIN_SQUARE_SIZE)) {
1064
952
  return _util.MIN_SQUARE_SIZE;
1065
- } // Dichotomic search, between a (inclusive) and b (exclusive).
1066
-
953
+ }
1067
954
 
955
+ // Dichotomic search, between a (inclusive) and b (exclusive).
1068
956
  var a = _util.MIN_SQUARE_SIZE;
1069
957
  var b = maxSquareSize;
1070
-
1071
958
  while (a + 1 < b) {
1072
959
  var mid = Math.floor((a + b) / 2);
1073
-
1074
960
  if (isAdapted(mid)) {
1075
961
  a = mid;
1076
962
  } else {
1077
963
  b = mid;
1078
964
  }
1079
965
  }
1080
-
1081
966
  return a;
1082
967
  }
968
+
1083
969
  /**
1084
970
  * Minimum square size (inclusive).
1085
971
  *
1086
972
  * @returns {number}
1087
973
  * @public
1088
974
  */
1089
-
1090
975
  }, {
1091
976
  key: "minSquareSize",
1092
977
  value: function minSquareSize() {
1093
978
  return _util.MIN_SQUARE_SIZE;
1094
979
  }
980
+
1095
981
  /**
1096
982
  * Maximum square size (inclusive).
1097
983
  *
1098
984
  * @returns {number}
1099
985
  * @public
1100
986
  */
1101
-
1102
987
  }, {
1103
988
  key: "maxSquareSize",
1104
989
  value: function maxSquareSize() {
1105
990
  return _util.MAX_SQUARE_SIZE;
1106
991
  }
992
+
1107
993
  /**
1108
994
  * Available colorsets for theming.
1109
995
  *
1110
996
  * @returns {Object.<string, { w: string, b: string, cb: string, cg: string, cr: string, cy: string }>}
1111
997
  * @public
1112
998
  */
1113
-
1114
999
  }, {
1115
1000
  key: "colorsets",
1116
1001
  value: function colorsets() {
1117
1002
  return _colorsets2["default"];
1118
1003
  }
1004
+
1119
1005
  /**
1120
1006
  * Available piecesets for theming.
1121
1007
  *
@@ -1123,17 +1009,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
1123
1009
  * wb: string, wk: string, wn: string, wp: string, wq: string, wr: string, wx: string }>}
1124
1010
  * @public
1125
1011
  */
1126
-
1127
1012
  }, {
1128
1013
  key: "piecesets",
1129
1014
  value: function piecesets() {
1130
1015
  return _piecesets2["default"];
1131
1016
  }
1132
1017
  }]);
1133
-
1134
1018
  return Chessboard;
1135
1019
  }(_react["default"].Component);
1136
-
1137
1020
  exports["default"] = Chessboard;
1138
1021
  Chessboard.propTypes = {
1139
1022
  /**
@@ -1146,19 +1029,16 @@ Chessboard.propTypes = {
1146
1029
  * `'chess960:nrkbqrbn/pppppppp/8/8/8/8/PPPPPPPP/NRKBQRBN w KQkq - 0 1'`.
1147
1030
  */
1148
1031
  position: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.Position), _propTypes["default"].string]),
1149
-
1150
1032
  /**
1151
1033
  * Displayed move (optional), defined either as a [kokopu.MoveDescriptor](https://kokopu.yo35.org/docs/current/classes/MoveDescriptor.html) object
1152
1034
  * or as a [SAN string](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) (e.g. `'Nf3'`). In both cases, it must represent
1153
1035
  * a legal move in position defined in attribute `position`.
1154
1036
  */
1155
1037
  move: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.MoveDescriptor), _propTypes["default"].string]),
1156
-
1157
1038
  /**
1158
1039
  * Square markers, defined as a "square -> color" struct (e.g. `{ e4: 'g', d5: 'r' }`) or as a comma-separated CSL string (e.g. `'Rd5,Ge4'`).
1159
1040
  */
1160
1041
  squareMarkers: _propTypes["default"].oneOfType([_propTypes["default"].objectOf(_propTypes["default"].oneOf(['b', 'g', 'r', 'y'])), _propTypes["default"].string]),
1161
-
1162
1042
  /**
1163
1043
  * Text markers, defined as a "square -> (symbol, color)" struct (e.g. `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`)
1164
1044
  * or as a comma-separated CTL string (e.g. `'Rzd5,GAe4'`).
@@ -1167,53 +1047,43 @@ Chessboard.propTypes = {
1167
1047
  symbol: _propTypes["default"].string.isRequired,
1168
1048
  color: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']).isRequired
1169
1049
  })), _propTypes["default"].string]),
1170
-
1171
1050
  /**
1172
1051
  * Arrow markers, defined as a "squareFromSquareTo -> color" struct (e.g. `{ e2e4: 'g', g8f6: 'r', g8h6: 'y' }`)
1173
1052
  * or as a comma-separated CAL string (e.g. `'Ge2e4,Rg8f6,Yg8h6'`).
1174
1053
  */
1175
1054
  arrowMarkers: _propTypes["default"].oneOfType([_propTypes["default"].objectOf(_propTypes["default"].oneOf(['b', 'g', 'r', 'y'])), _propTypes["default"].string]),
1176
-
1177
1055
  /**
1178
1056
  * Whether the board is flipped (i.e. seen from Black's point of view) or not.
1179
1057
  */
1180
1058
  flipped: _propTypes["default"].bool,
1181
-
1182
1059
  /**
1183
1060
  * Size of the squares (in pixels). Must be an integer between `Chessboard.minSquareSize()` and `Chessboard.maxSquareSize()`.
1184
1061
  */
1185
1062
  squareSize: _propTypes["default"].number,
1186
-
1187
1063
  /**
1188
1064
  * Whether the row and column coordinates are visible or not.
1189
1065
  */
1190
1066
  coordinateVisible: _propTypes["default"].bool,
1191
-
1192
1067
  /**
1193
1068
  * Whether moves are highlighted with an arrow or not.
1194
1069
  */
1195
1070
  moveArrowVisible: _propTypes["default"].bool,
1196
-
1197
1071
  /**
1198
1072
  * Color of the move arrow.
1199
1073
  */
1200
1074
  moveArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
1201
-
1202
1075
  /**
1203
1076
  * Whether moves are animated or not.
1204
1077
  */
1205
1078
  animated: _propTypes["default"].bool,
1206
-
1207
1079
  /**
1208
1080
  * Color theme ID.
1209
1081
  */
1210
1082
  colorset: _propTypes["default"].oneOf(Object.keys(_colorsets2["default"])),
1211
-
1212
1083
  /**
1213
1084
  * Piece theme ID.
1214
1085
  */
1215
1086
  pieceset: _propTypes["default"].oneOf(Object.keys(_piecesets2["default"])),
1216
-
1217
1087
  /**
1218
1088
  * Limits applicable on small-screen devices. For instance, if set to
1219
1089
  * ```
@@ -1232,7 +1102,6 @@ Chessboard.propTypes = {
1232
1102
  squareSize: _propTypes["default"].number,
1233
1103
  coordinateVisible: _propTypes["default"].bool
1234
1104
  })),
1235
-
1236
1105
  /**
1237
1106
  * Type of action allowed with the mouse on the chessboard. If undefined, then the user cannot interact with the component.
1238
1107
  *
@@ -1242,12 +1111,10 @@ Chessboard.propTypes = {
1242
1111
  * - `'playMoves'` allows the user to play legal chess moves (thus no interaction is possible if the displayed position is not legal).
1243
1112
  */
1244
1113
  interactionMode: _propTypes["default"].oneOf(['movePieces', 'clickSquares', 'editArrows', 'playMoves']),
1245
-
1246
1114
  /**
1247
1115
  * Color of the edited arrow (only used if `interactionMode` is set to `'editArrows'`).
1248
1116
  */
1249
1117
  editedArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
1250
-
1251
1118
  /**
1252
1119
  * Callback invoked when a piece is moved through drag&drop (only if `interactionMode` is set to `'movePieces'`).
1253
1120
  *
@@ -1255,14 +1122,12 @@ Chessboard.propTypes = {
1255
1122
  * @param {string} to Target square (e.g. `'f3'`).
1256
1123
  */
1257
1124
  onPieceMoved: _propTypes["default"].func,
1258
-
1259
1125
  /**
1260
1126
  * Callback invoked when the user clicks on a square (only if `interactionMode` is set to `'clickSquares'`).
1261
1127
  *
1262
1128
  * @param {string} square Clicked square (e.g. `e4`).
1263
1129
  */
1264
1130
  onSquareClicked: _propTypes["default"].func,
1265
-
1266
1131
  /**
1267
1132
  * Callback invoked when an arrow is dragged (only if `interactionMode` is set to `'editArrows'`).
1268
1133
  *
@@ -1270,7 +1135,6 @@ Chessboard.propTypes = {
1270
1135
  * @param {string} to Target square (e.g. `'f3'`).
1271
1136
  */
1272
1137
  onArrowEdited: _propTypes["default"].func,
1273
-
1274
1138
  /**
1275
1139
  * Callback invoked when a move is played (only if `interactionMode` is set to `'playMoves'`).
1276
1140
  *
@@ -1289,15 +1153,14 @@ Chessboard.defaultProps = {
1289
1153
  colorset: 'original',
1290
1154
  pieceset: 'cburnett'
1291
1155
  };
1156
+
1292
1157
  /**
1293
1158
  * Compute the limit applicable to the given window width.
1294
1159
  */
1295
-
1296
1160
  function computeSmallScreenLimits(key, smallScreenLimits, windowWidth) {
1297
1161
  if (!(smallScreenLimits instanceof Array)) {
1298
1162
  return undefined;
1299
1163
  }
1300
-
1301
1164
  var applicableLimits = smallScreenLimits.filter(function (limit) {
1302
1165
  return limit && key in limit && windowWidth <= limit.width;
1303
1166
  }).sort(function (la, lb) {
@@ -1305,19 +1168,17 @@ function computeSmallScreenLimits(key, smallScreenLimits, windowWidth) {
1305
1168
  });
1306
1169
  return applicableLimits.length > 0 ? applicableLimits[0][key] : undefined;
1307
1170
  }
1171
+
1308
1172
  /**
1309
1173
  * Return the font size to use for coordinates assuming the given square size.
1310
1174
  */
1311
-
1312
-
1313
1175
  function computeCoordinateFontSize(squareSize) {
1314
1176
  return squareSize <= 32 ? 8 : 8 + (squareSize - 32) * 0.2;
1315
1177
  }
1178
+
1316
1179
  /**
1317
1180
  * Try to interpret the given object as a chess position.
1318
1181
  */
1319
-
1320
-
1321
1182
  function parsePosition(position) {
1322
1183
  if (position instanceof _kokopu.Position) {
1323
1184
  return {
@@ -1348,11 +1209,10 @@ function parsePosition(position) {
1348
1209
  };
1349
1210
  }
1350
1211
  }
1212
+
1351
1213
  /**
1352
1214
  * Try to interpret the given object `move` as a move descriptor based on the given position.
1353
1215
  */
1354
-
1355
-
1356
1216
  function parseMove(position, move) {
1357
1217
  if (move instanceof _kokopu.MoveDescriptor) {
1358
1218
  return {
@@ -1383,11 +1243,10 @@ function parseMove(position, move) {
1383
1243
  };
1384
1244
  }
1385
1245
  }
1246
+
1386
1247
  /**
1387
1248
  * Try to interpret the given object as a list of markers.
1388
1249
  */
1389
-
1390
-
1391
1250
  function parseMarkers(markers, parse, isValidKey, isValidValue) {
1392
1251
  if (typeof markers === 'string') {
1393
1252
  return parse(markers);
@@ -1395,15 +1254,13 @@ function parseMarkers(markers, parse, isValidKey, isValidValue) {
1395
1254
  var result = {};
1396
1255
  Object.entries(markers).filter(function (_ref7) {
1397
1256
  var _ref8 = _slicedToArray(_ref7, 2),
1398
- key = _ref8[0],
1399
- value = _ref8[1];
1400
-
1257
+ key = _ref8[0],
1258
+ value = _ref8[1];
1401
1259
  return isValidKey(key) && isValidValue(value);
1402
1260
  }).forEach(function (_ref9) {
1403
1261
  var _ref10 = _slicedToArray(_ref9, 2),
1404
- key = _ref10[0],
1405
- value = _ref10[1];
1406
-
1262
+ key = _ref10[0],
1263
+ value = _ref10[1];
1407
1264
  result[key] = value;
1408
1265
  });
1409
1266
  return result;