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