kokopu-react 1.7.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/Chessboard.js +84 -97
- package/dist/lib/ErrorBox.js +3 -1
- package/dist/lib/Movetext.js +24 -15
- package/dist/lib/i18n.js +2 -1
- package/dist/lib/impl/ArrowTip.js +2 -2
- package/dist/lib/impl/Motion.js +133 -0
- package/dist/lib/impl/util.js +12 -0
- package/doc_src/demo/PageChessboardInteraction.js +9 -9
- package/doc_src/demo/PageChessboardMove.js +8 -8
- package/doc_src/demo/PageMovetextInteraction.js +2 -2
- package/graphic_test_src/02_chessboard_simple.js +2 -2
- package/graphic_test_src/03_chessboard_flipped.js +2 -2
- package/graphic_test_src/05_chessboard_move.js +4 -4
- package/graphic_test_src/06a_chessboard_animated_move.js +36 -0
- package/graphic_test_src/06b_chessboard_animated_move.js +36 -0
- package/graphic_test_src/06c_chessboard_animated_move.js +36 -0
- package/graphic_test_src/{06_chessboard_theme.js → 07_chessboard_theme.js} +0 -0
- package/graphic_test_src/{07_chessboard_click_squares.js → 08_chessboard_click_squares.js} +0 -0
- package/graphic_test_src/{08_chessboard_move_pieces.js → 09_chessboard_move_pieces.js} +0 -0
- package/graphic_test_src/{09_chessboard_edit_arrows.js → 10_chessboard_edit_arrows.js} +0 -0
- package/graphic_test_src/{10_chessboard_play_moves.js → 11_chessboard_play_moves.js} +0 -0
- package/graphic_test_src/{11_chessboard_play_promotions.js → 12_chessboard_play_promotions.js} +0 -0
- package/graphic_test_src/{12_movetext_simple.js → 13_movetext_simple.js} +3 -3
- package/graphic_test_src/{13_movetext_error.js → 14_movetext_error.js} +4 -3
- package/graphic_test_src/{14_movetext_html.js → 15_movetext_html.js} +0 -0
- package/graphic_test_src/{15_movetext_options.js → 16_movetext_options.js} +0 -0
- package/graphic_test_src/{16_movetext_interaction.js → 17_movetext_interaction.js} +0 -0
- package/graphic_test_src/common/games.pgn +3 -3
- package/package.json +17 -19
- package/scripts/docker-compose.yml +1 -1
- package/src/Chessboard.js +42 -42
- package/src/ErrorBox.js +2 -1
- package/src/Movetext.js +20 -16
- package/src/i18n.js +1 -0
- package/src/impl/ArrowTip.js +2 -2
- package/src/impl/Motion.js +99 -0
- package/src/impl/util.js +8 -0
- package/test/4_chessboard_graphic.js +4 -1
- package/test/5_chessboard_interaction.js +5 -5
- package/test/6_chessboard_play_moves.js +4 -4
- package/test/7_movetext_graphic.js +4 -4
- package/test/8_movetext_interaction.js +2 -2
- package/test/common/graphic.js +6 -0
- package/test/references/06a_chessboard_animated_move/0.png +0 -0
- package/test/references/06a_chessboard_animated_move/1.png +0 -0
- package/test/references/06a_chessboard_animated_move/2.png +0 -0
- package/test/references/06a_chessboard_animated_move/3.png +0 -0
- package/test/references/06a_chessboard_animated_move/4.png +0 -0
- package/test/references/06a_chessboard_animated_move/5.png +0 -0
- package/test/references/06b_chessboard_animated_move/0.png +0 -0
- package/test/references/06b_chessboard_animated_move/1.png +0 -0
- package/test/references/06b_chessboard_animated_move/2.png +0 -0
- package/test/references/06b_chessboard_animated_move/3.png +0 -0
- package/test/references/06b_chessboard_animated_move/4.png +0 -0
- package/test/references/06b_chessboard_animated_move/5.png +0 -0
- package/test/references/06c_chessboard_animated_move/0.png +0 -0
- package/test/references/06c_chessboard_animated_move/1.png +0 -0
- package/test/references/06c_chessboard_animated_move/2.png +0 -0
- package/test/references/06c_chessboard_animated_move/3.png +0 -0
- package/test/references/06c_chessboard_animated_move/4.png +0 -0
- package/test/references/06c_chessboard_animated_move/5.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/0.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/1.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/2.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/3.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/4.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/5.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/6.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/7.png +0 -0
- package/test/references/{06_chessboard_theme → 07_chessboard_theme}/8.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/after_move.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/empty_square.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/null_vector.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/out_of_board.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_arrow_marker.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_empty.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_1.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_2.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_square_marker.png +0 -0
- package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_text_marker.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_1.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_2.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/edit_color_not_set.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/null_vector.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/out_of_board.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_arrow_marker.png +0 -0
- package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_square_marker.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/castling_move.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_ambiguous_king_move.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_1.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_2.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_non_kxr_castling.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_move.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_position.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/null_vector.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/out_of_board.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_1.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_2.png +0 -0
- package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/wrong_color.png +0 -0
- package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/antichess_promotion.png +0 -0
- package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/cancel_promotion.png +0 -0
- package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_1.png +0 -0
- package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_2.png +0 -0
- package/test/references/{12_movetext_simple → 13_movetext_simple}/0.png +0 -0
- package/test/references/{12_movetext_simple → 13_movetext_simple}/1.png +0 -0
- package/test/references/{12_movetext_simple → 13_movetext_simple}/2.png +0 -0
- package/test/references/{12_movetext_simple → 13_movetext_simple}/3.png +0 -0
- package/test/references/14_movetext_error/0.png +0 -0
- package/test/references/14_movetext_error/1.png +0 -0
- package/test/references/{13_movetext_error/1.png → 14_movetext_error/2.png} +0 -0
- package/test/references/14_movetext_error/3.png +0 -0
- package/test/references/14_movetext_error/4.png +0 -0
- package/test/references/15_movetext_html/0.png +0 -0
- package/test/references/15_movetext_html/1.png +0 -0
- package/test/references/{14_movetext_html → 15_movetext_html}/2.png +0 -0
- package/test/references/{15_movetext_options → 16_movetext_options}/0.png +0 -0
- package/test/references/{15_movetext_options → 16_movetext_options}/1.png +0 -0
- package/test/references/{15_movetext_options → 16_movetext_options}/2.png +0 -0
- package/test/references/{15_movetext_options → 16_movetext_options}/3.png +0 -0
- package/test/references/{16_movetext_interaction → 17_movetext_interaction}/0.png +0 -0
- package/test/references/{16_movetext_interaction → 17_movetext_interaction}/1.png +0 -0
- package/test/references/{16_movetext_interaction → 17_movetext_interaction}/2.png +0 -0
- package/CHANGELOG.md +0 -131
- package/graphics/chess_sprites/cburnett/bb.svg +0 -45
- package/graphics/chess_sprites/cburnett/bk.svg +0 -47
- package/graphics/chess_sprites/cburnett/bn.svg +0 -37
- package/graphics/chess_sprites/cburnett/bp.svg +0 -19
- package/graphics/chess_sprites/cburnett/bq.svg +0 -58
- package/graphics/chess_sprites/cburnett/br.svg +0 -60
- package/graphics/chess_sprites/cburnett/bx.svg +0 -56
- package/graphics/chess_sprites/cburnett/wb.svg +0 -48
- package/graphics/chess_sprites/cburnett/wk.svg +0 -26
- package/graphics/chess_sprites/cburnett/wn.svg +0 -37
- package/graphics/chess_sprites/cburnett/wp.svg +0 -19
- package/graphics/chess_sprites/cburnett/wq.svg +0 -60
- package/graphics/chess_sprites/cburnett/wr.svg +0 -44
- package/graphics/chess_sprites/cburnett/wx.svg +0 -56
- package/graphics/chess_sprites/generate_sprites.sh +0 -135
- package/graphics/chess_sprites/mmonge/celtic-bx.svg +0 -112
- package/graphics/chess_sprites/mmonge/celtic-wx.svg +0 -111
- package/graphics/chess_sprites/mmonge/celtic.svg +0 -1576
- package/graphics/chess_sprites/mmonge/eyes-spatial-bx.svg +0 -101
- package/graphics/chess_sprites/mmonge/eyes-spatial-wx.svg +0 -100
- package/graphics/chess_sprites/mmonge/eyes.svg +0 -2538
- package/graphics/chess_sprites/mmonge/fantasy-bx.svg +0 -112
- package/graphics/chess_sprites/mmonge/fantasy-wx.svg +0 -111
- package/graphics/chess_sprites/mmonge/fantasy.svg +0 -5497
- package/graphics/chess_sprites/mmonge/fantasy_alt.svg +0 -3742
- package/graphics/chess_sprites/mmonge/freak.svg +0 -3479
- package/graphics/chess_sprites/mmonge/prmi.svg +0 -6776
- package/graphics/chess_sprites/mmonge/skulls-bx.svg +0 -124
- package/graphics/chess_sprites/mmonge/skulls-wx.svg +0 -111
- package/graphics/chess_sprites/mmonge/skulls.svg +0 -12978
- package/graphics/chess_sprites/mmonge/spatial.svg +0 -1223
- package/graphics/logo-small.svg +0 -14
- package/graphics/logo.svg +0 -26
- package/test/references/13_movetext_error/0.png +0 -0
- package/test/references/13_movetext_error/2.png +0 -0
- package/test/references/13_movetext_error/3.png +0 -0
- package/test/references/14_movetext_html/0.png +0 -0
- package/test/references/14_movetext_html/1.png +0 -0
package/dist/lib/Chessboard.js
CHANGED
|
@@ -11,9 +11,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _reactDraggable = _interopRequireDefault(require("react-draggable"));
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _kokopu = _interopRequireDefault(require("kokopu"));
|
|
14
|
+
var _kokopu = require("kokopu");
|
|
17
15
|
|
|
18
16
|
var _colorsets2 = _interopRequireDefault(require("./impl/colorsets"));
|
|
19
17
|
|
|
@@ -21,6 +19,8 @@ var _piecesets2 = _interopRequireDefault(require("./impl/piecesets"));
|
|
|
21
19
|
|
|
22
20
|
var _ArrowTip = _interopRequireDefault(require("./impl/ArrowTip"));
|
|
23
21
|
|
|
22
|
+
var _Motion = _interopRequireDefault(require("./impl/Motion"));
|
|
23
|
+
|
|
24
24
|
var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
|
|
25
25
|
|
|
26
26
|
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
@@ -77,10 +77,7 @@ var FILE_COORDINATE_HEIGHT_FACTOR = 1.4;
|
|
|
77
77
|
var HOVER_MARKER_THICKNESS_FACTOR = 0.1;
|
|
78
78
|
var STROKE_THICKNESS_FACTOR = 0.15;
|
|
79
79
|
var ARROW_TIP_OFFSET_FACTOR = 0.3;
|
|
80
|
-
var
|
|
81
|
-
stiffness: 700,
|
|
82
|
-
damping: 40
|
|
83
|
-
};
|
|
80
|
+
var MOTION_DURATION = 150;
|
|
84
81
|
var RANK_LABELS = '12345678';
|
|
85
82
|
var FILE_LABELS = 'abcdefgh';
|
|
86
83
|
/**
|
|
@@ -107,28 +104,32 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
107
104
|
windowWidth: window.innerWidth
|
|
108
105
|
};
|
|
109
106
|
_this.arrowTipIdSuffix = (0, _util.generateRandomId)();
|
|
110
|
-
|
|
111
|
-
_this.windowResizeListener = function () {
|
|
112
|
-
return _this.handleWindowResize();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
107
|
return _this;
|
|
116
108
|
}
|
|
117
109
|
|
|
118
110
|
_createClass(Chessboard, [{
|
|
119
111
|
key: "componentDidMount",
|
|
120
112
|
value: function componentDidMount() {
|
|
113
|
+
var _this2 = this;
|
|
114
|
+
|
|
115
|
+
this.windowResizeListener = function () {
|
|
116
|
+
return _this2.handleWindowResize();
|
|
117
|
+
};
|
|
118
|
+
|
|
121
119
|
window.addEventListener('resize', this.windowResizeListener);
|
|
122
120
|
}
|
|
123
121
|
}, {
|
|
124
122
|
key: "componentWillUnmount",
|
|
125
123
|
value: function componentWillUnmount() {
|
|
126
|
-
|
|
124
|
+
if (this.windowResizeListener) {
|
|
125
|
+
window.removeEventListener('resize', this.windowResizeListener);
|
|
126
|
+
this.windowResizeListener = null;
|
|
127
|
+
}
|
|
127
128
|
}
|
|
128
129
|
}, {
|
|
129
130
|
key: "render",
|
|
130
131
|
value: function render() {
|
|
131
|
-
var
|
|
132
|
+
var _this3 = this;
|
|
132
133
|
|
|
133
134
|
// Compute the current position.
|
|
134
135
|
var info = this.getPositionAndMoveInfo();
|
|
@@ -161,12 +162,10 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
161
162
|
|
|
162
163
|
|
|
163
164
|
var squares = [];
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return squares.push(_this2.renderSquare(squareSize, colorset, sq));
|
|
165
|
+
(0, _kokopu.forEachSquare)(function (sq) {
|
|
166
|
+
return squares.push(_this3.renderSquare(squareSize, colorset, sq));
|
|
167
167
|
}); // Render coordinates.
|
|
168
168
|
|
|
169
|
-
|
|
170
169
|
var rankCoordinates = [];
|
|
171
170
|
var fileCoordinates = [];
|
|
172
171
|
|
|
@@ -193,19 +192,15 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
193
192
|
}, {
|
|
194
193
|
key: "renderBoardContent",
|
|
195
194
|
value: function renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset) {
|
|
196
|
-
var
|
|
195
|
+
var _this4 = this;
|
|
197
196
|
|
|
198
197
|
if (move && this.props.animated) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
alpha: (0, _reactMotion.spring)(1, ANIMATION_SPEED)
|
|
206
|
-
}
|
|
207
|
-
}, function (currentStyle) {
|
|
208
|
-
return currentStyle.alpha >= 1 ? _this3.renderBoardContentStill(position, move, squareSize, colorset, pieceset) : _this3.renderBoardContentAnimated(positionBefore, move, currentStyle.alpha, squareSize, colorset, pieceset);
|
|
198
|
+
var key = positionBefore.variant() + '|' + positionBefore.fen() + '|' + move.toString();
|
|
199
|
+
return /*#__PURE__*/_react["default"].createElement(_Motion["default"], {
|
|
200
|
+
key: key,
|
|
201
|
+
duration: MOTION_DURATION
|
|
202
|
+
}, function (motionCursor) {
|
|
203
|
+
return motionCursor === 1 ? _this4.renderBoardContentStill(position, move, squareSize, colorset, pieceset) : _this4.renderBoardContentAnimated(positionBefore, move, motionCursor, squareSize, colorset, pieceset);
|
|
209
204
|
});
|
|
210
205
|
} else {
|
|
211
206
|
return this.renderBoardContentStill(position, move, squareSize, colorset, pieceset);
|
|
@@ -217,16 +212,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
217
212
|
|
|
218
213
|
}, {
|
|
219
214
|
key: "renderBoardContentAnimated",
|
|
220
|
-
value: function renderBoardContentAnimated(positionBefore, move,
|
|
221
|
-
var
|
|
215
|
+
value: function renderBoardContentAnimated(positionBefore, move, motionCursor, squareSize, colorset, pieceset) {
|
|
216
|
+
var _this5 = this;
|
|
222
217
|
|
|
223
218
|
var pieces = [];
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return pieces.push(_this4.renderPieceAnimated(positionBefore, move, alpha, squareSize, pieceset, sq));
|
|
219
|
+
(0, _kokopu.forEachSquare)(function (sq) {
|
|
220
|
+
return pieces.push(_this5.renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq));
|
|
227
221
|
});
|
|
228
|
-
|
|
229
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, pieces, this.renderMoveArrow(move, alpha, squareSize, colorset), this.renderTurnFlag(_kokopu["default"].oppositeColor(positionBefore.turn()), squareSize, pieceset));
|
|
222
|
+
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));
|
|
230
223
|
}
|
|
231
224
|
/**
|
|
232
225
|
* Render the board content when the animation has been completed (or if there is no animation).
|
|
@@ -235,7 +228,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
235
228
|
}, {
|
|
236
229
|
key: "renderBoardContentStill",
|
|
237
230
|
value: function renderBoardContentStill(position, move, squareSize, colorset, pieceset) {
|
|
238
|
-
var
|
|
231
|
+
var _this6 = this;
|
|
239
232
|
|
|
240
233
|
// Compute the annotations.
|
|
241
234
|
var sqm = parseMarkers(this.props.squareMarkers, _markers.parseSquareMarkers, _util.isValidSquare, _util.isValidColor);
|
|
@@ -246,15 +239,13 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
246
239
|
|
|
247
240
|
var pieces = [];
|
|
248
241
|
var handles = [];
|
|
242
|
+
(0, _kokopu.forEachSquare)(function (sq) {
|
|
243
|
+
pieces.push(_this6.renderPiece(position, squareSize, pieceset, sq));
|
|
249
244
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (_this5.props.interactionMode) {
|
|
254
|
-
handles.push(_this5.renderSquareHandle(position, squareSize, sq));
|
|
245
|
+
if (_this6.props.interactionMode) {
|
|
246
|
+
handles.push(_this6.renderSquareHandle(position, squareSize, sq));
|
|
255
247
|
}
|
|
256
248
|
});
|
|
257
|
-
|
|
258
249
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderSquareMarkers(sqm, squareSize, colorset), this.renderHoveredSquare(squareSize, colorset), pieces, this.renderTextMarkers(txtm, squareSize, colorset), this.renderArrowMarkers(arm, squareSize, colorset), this.renderMoveArrow(move, 1, squareSize, colorset), handles, this.renderPromotionDrawer(position, squareSize, colorset, pieceset), this.renderDraggedPiece(position, squareSize, pieceset), this.renderDraggedArrow(squareSize, colorset), this.renderTurnFlag(position.turn(), squareSize, pieceset));
|
|
259
250
|
}
|
|
260
251
|
}, {
|
|
@@ -270,7 +261,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
270
261
|
y: y,
|
|
271
262
|
width: squareSize,
|
|
272
263
|
height: squareSize,
|
|
273
|
-
fill: colorset[_kokopu
|
|
264
|
+
fill: colorset[(0, _kokopu.squareColor)(sq)]
|
|
274
265
|
});
|
|
275
266
|
}
|
|
276
267
|
}, {
|
|
@@ -321,7 +312,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
321
312
|
}
|
|
322
313
|
}, {
|
|
323
314
|
key: "renderPieceAnimated",
|
|
324
|
-
value: function renderPieceAnimated(positionBefore, move,
|
|
315
|
+
value: function renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq) {
|
|
325
316
|
var cp = positionBefore.square(sq);
|
|
326
317
|
|
|
327
318
|
if (cp === '-' || move.to() === sq || move.isEnPassant() && move.enPassantSquare() === sq) {
|
|
@@ -337,10 +328,10 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
337
328
|
xTo = _this$getSquareCoordi5.x,
|
|
338
329
|
yTo = _this$getSquareCoordi5.y;
|
|
339
330
|
|
|
340
|
-
x = xTo *
|
|
341
|
-
y = yTo *
|
|
331
|
+
x = xTo * motionCursor + x * (1 - motionCursor);
|
|
332
|
+
y = yTo * motionCursor + y * (1 - motionCursor);
|
|
342
333
|
|
|
343
|
-
if (move.isPromotion() &&
|
|
334
|
+
if (move.isPromotion() && motionCursor > 0.8) {
|
|
344
335
|
cp = move.coloredPromotion();
|
|
345
336
|
}
|
|
346
337
|
} else if (move.isCastling() && sq === move.rookFrom()) {
|
|
@@ -348,8 +339,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
348
339
|
_xTo = _this$getSquareCoordi6.x,
|
|
349
340
|
_yTo = _this$getSquareCoordi6.y;
|
|
350
341
|
|
|
351
|
-
x = _xTo *
|
|
352
|
-
y = _yTo *
|
|
342
|
+
x = _xTo * motionCursor + x * (1 - motionCursor);
|
|
343
|
+
y = _yTo * motionCursor + y * (1 - motionCursor);
|
|
353
344
|
}
|
|
354
345
|
|
|
355
346
|
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
@@ -416,7 +407,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
416
407
|
}, {
|
|
417
408
|
key: "renderPromotionDrawer",
|
|
418
409
|
value: function renderPromotionDrawer(position, squareSize, colorset, pieceset) {
|
|
419
|
-
var
|
|
410
|
+
var _this7 = this;
|
|
420
411
|
|
|
421
412
|
if (!this.state.promotionDrawer) {
|
|
422
413
|
return undefined;
|
|
@@ -440,7 +431,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
440
431
|
height: squareSize,
|
|
441
432
|
href: pieceset[cp],
|
|
442
433
|
onClick: function onClick() {
|
|
443
|
-
return
|
|
434
|
+
return _this7.handleDrawerButtonClicked(p);
|
|
444
435
|
}
|
|
445
436
|
});
|
|
446
437
|
});
|
|
@@ -451,7 +442,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
451
442
|
width: squareSize * 8,
|
|
452
443
|
height: squareSize * 8,
|
|
453
444
|
onClick: function onClick() {
|
|
454
|
-
return
|
|
445
|
+
return _this7.handleDrawerCancelButtonClicked();
|
|
455
446
|
}
|
|
456
447
|
}), /*#__PURE__*/_react["default"].createElement("rect", {
|
|
457
448
|
x: x,
|
|
@@ -471,7 +462,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
471
462
|
}, {
|
|
472
463
|
key: "renderSquareHandle",
|
|
473
464
|
value: function renderSquareHandle(position, squareSize, sq) {
|
|
474
|
-
var
|
|
465
|
+
var _this8 = this;
|
|
475
466
|
|
|
476
467
|
var _this$getSquareCoordi10 = this.getSquareCoordinates(squareSize, sq),
|
|
477
468
|
x = _this$getSquareCoordi10.x,
|
|
@@ -491,13 +482,13 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
491
482
|
key: 'handle-' + sq,
|
|
492
483
|
position: dragPosition,
|
|
493
484
|
onStart: function onStart(evt) {
|
|
494
|
-
return
|
|
485
|
+
return _this8.handleDragStart(sq, evt);
|
|
495
486
|
},
|
|
496
487
|
onDrag: function onDrag(_, dragData) {
|
|
497
|
-
return
|
|
488
|
+
return _this8.handleDrag(sq, dragData);
|
|
498
489
|
},
|
|
499
490
|
onStop: function onStop(_, dragData) {
|
|
500
|
-
return
|
|
491
|
+
return _this8.handleDragStop(sq, dragData);
|
|
501
492
|
}
|
|
502
493
|
}, /*#__PURE__*/_react["default"].createElement("rect", {
|
|
503
494
|
className: classNames.join(' '),
|
|
@@ -515,7 +506,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
515
506
|
width: squareSize,
|
|
516
507
|
height: squareSize,
|
|
517
508
|
onClick: function onClick() {
|
|
518
|
-
return
|
|
509
|
+
return _this8.handleSquareClicked(sq);
|
|
519
510
|
}
|
|
520
511
|
});
|
|
521
512
|
} else {
|
|
@@ -525,7 +516,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
525
516
|
}, {
|
|
526
517
|
key: "renderSquareMarkers",
|
|
527
518
|
value: function renderSquareMarkers(sqm, squareSize, colorset) {
|
|
528
|
-
var
|
|
519
|
+
var _this9 = this;
|
|
529
520
|
|
|
530
521
|
var result = [];
|
|
531
522
|
Object.entries(sqm).forEach(function (_ref) {
|
|
@@ -533,9 +524,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
533
524
|
sq = _ref2[0],
|
|
534
525
|
color = _ref2[1];
|
|
535
526
|
|
|
536
|
-
var
|
|
537
|
-
x =
|
|
538
|
-
y =
|
|
527
|
+
var _this9$getSquareCoord = _this9.getSquareCoordinates(squareSize, sq),
|
|
528
|
+
x = _this9$getSquareCoord.x,
|
|
529
|
+
y = _this9$getSquareCoord.y;
|
|
539
530
|
|
|
540
531
|
result.push( /*#__PURE__*/_react["default"].createElement("rect", {
|
|
541
532
|
key: 'sqm-' + sq,
|
|
@@ -552,7 +543,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
552
543
|
}, {
|
|
553
544
|
key: "renderTextMarkers",
|
|
554
545
|
value: function renderTextMarkers(txtm, squareSize, colorset) {
|
|
555
|
-
var
|
|
546
|
+
var _this10 = this;
|
|
556
547
|
|
|
557
548
|
var result = [];
|
|
558
549
|
Object.entries(txtm).forEach(function (_ref3) {
|
|
@@ -560,9 +551,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
560
551
|
sq = _ref4[0],
|
|
561
552
|
value = _ref4[1];
|
|
562
553
|
|
|
563
|
-
var
|
|
564
|
-
x =
|
|
565
|
-
y =
|
|
554
|
+
var _this10$getSquareCoor = _this10.getSquareCoordinates(squareSize, sq),
|
|
555
|
+
x = _this10$getSquareCoor.x,
|
|
556
|
+
y = _this10$getSquareCoor.y;
|
|
566
557
|
|
|
567
558
|
x += squareSize / 2;
|
|
568
559
|
y += squareSize / 2;
|
|
@@ -582,7 +573,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
582
573
|
}, {
|
|
583
574
|
key: "renderArrowMarkers",
|
|
584
575
|
value: function renderArrowMarkers(arm, squareSize, colorset) {
|
|
585
|
-
var
|
|
576
|
+
var _this11 = this;
|
|
586
577
|
|
|
587
578
|
var result = [];
|
|
588
579
|
var strokeWidth = squareSize * STROKE_THICKNESS_FACTOR;
|
|
@@ -598,13 +589,13 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
598
589
|
return;
|
|
599
590
|
}
|
|
600
591
|
|
|
601
|
-
var
|
|
602
|
-
xFrom =
|
|
603
|
-
yFrom =
|
|
592
|
+
var _this11$getSquareCoor = _this11.getSquareCoordinates(squareSize, from),
|
|
593
|
+
xFrom = _this11$getSquareCoor.x,
|
|
594
|
+
yFrom = _this11$getSquareCoor.y;
|
|
604
595
|
|
|
605
|
-
var
|
|
606
|
-
xTo =
|
|
607
|
-
yTo =
|
|
596
|
+
var _this11$getSquareCoor2 = _this11.getSquareCoordinates(squareSize, to),
|
|
597
|
+
xTo = _this11$getSquareCoor2.x,
|
|
598
|
+
yTo = _this11$getSquareCoor2.y;
|
|
608
599
|
|
|
609
600
|
xFrom += squareSize / 2;
|
|
610
601
|
yFrom += squareSize / 2;
|
|
@@ -613,7 +604,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
613
604
|
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
614
605
|
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
615
606
|
|
|
616
|
-
var arrowTipId =
|
|
607
|
+
var arrowTipId = _this11.getArrowTipId(color);
|
|
617
608
|
|
|
618
609
|
result.push( /*#__PURE__*/_react["default"].createElement("line", {
|
|
619
610
|
key: 'arm-' + vect,
|
|
@@ -631,8 +622,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
631
622
|
}
|
|
632
623
|
}, {
|
|
633
624
|
key: "renderMoveArrow",
|
|
634
|
-
value: function renderMoveArrow(move,
|
|
635
|
-
if (!move ||
|
|
625
|
+
value: function renderMoveArrow(move, motionCursor, squareSize, colorset) {
|
|
626
|
+
if (!move || motionCursor < 0.1 || !this.props.moveArrowVisible || move.from() === move.to()) {
|
|
636
627
|
return undefined;
|
|
637
628
|
}
|
|
638
629
|
|
|
@@ -651,8 +642,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
651
642
|
yTo += squareSize / 2;
|
|
652
643
|
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
653
644
|
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
654
|
-
var x = xTo *
|
|
655
|
-
var y = yTo *
|
|
645
|
+
var x = xTo * motionCursor + xFrom * (1 - motionCursor);
|
|
646
|
+
var y = yTo * motionCursor + yFrom * (1 - motionCursor);
|
|
656
647
|
var color = this.props.moveArrowColor;
|
|
657
648
|
return /*#__PURE__*/_react["default"].createElement("line", {
|
|
658
649
|
className: "kokopu-annotation kokopu-arrow",
|
|
@@ -905,9 +896,9 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
905
896
|
}, {
|
|
906
897
|
key: "getSquareCoordinates",
|
|
907
898
|
value: function getSquareCoordinates(squareSize, sq) {
|
|
908
|
-
var
|
|
909
|
-
file =
|
|
910
|
-
rank =
|
|
899
|
+
var _squareToCoordinates = (0, _kokopu.squareToCoordinates)(sq),
|
|
900
|
+
file = _squareToCoordinates.file,
|
|
901
|
+
rank = _squareToCoordinates.rank;
|
|
911
902
|
|
|
912
903
|
var x = this.props.flipped ? (7 - file) * squareSize : file * squareSize;
|
|
913
904
|
var y = this.props.flipped ? rank * squareSize : (7 - rank) * squareSize;
|
|
@@ -956,7 +947,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
956
947
|
} // Compute the position after the move and return the result.
|
|
957
948
|
|
|
958
949
|
|
|
959
|
-
var positionAfter = new _kokopu
|
|
950
|
+
var positionAfter = new _kokopu.Position(positionInfo.position);
|
|
960
951
|
positionAfter.play(moveInfo.move);
|
|
961
952
|
return {
|
|
962
953
|
positionError: false,
|
|
@@ -975,7 +966,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
975
966
|
value: function getSquareAt(squareSize, x, y) {
|
|
976
967
|
var file = this.props.flipped ? 7 - Math.floor(x / squareSize) : Math.floor(x / squareSize);
|
|
977
968
|
var rank = this.props.flipped ? Math.floor(y / squareSize) : 7 - Math.floor(y / squareSize);
|
|
978
|
-
return file >= 0 && file < 8 && rank >= 0 && rank < 8 ? _kokopu
|
|
969
|
+
return file >= 0 && file < 8 && rank >= 0 && rank < 8 ? (0, _kokopu.coordinatesToSquare)(file, rank) : '-';
|
|
979
970
|
}
|
|
980
971
|
/**
|
|
981
972
|
* Return the DOM ID of an arrow tip with the given color.
|
|
@@ -1146,26 +1137,22 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
1146
1137
|
exports["default"] = Chessboard;
|
|
1147
1138
|
Chessboard.propTypes = {
|
|
1148
1139
|
/**
|
|
1149
|
-
* Displayed position. Can be a [kokopu.Position](https://kokopu.yo35.org/docs/Position.html) object,
|
|
1140
|
+
* Displayed position. Can be a [kokopu.Position](https://kokopu.yo35.org/docs/current/classes/Position.html) object,
|
|
1150
1141
|
* a [FEN string](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation),
|
|
1151
1142
|
* `'start'` (usual starting position), or `'empty'` (empty board).
|
|
1152
1143
|
*
|
|
1153
1144
|
* Optionally, the FEN string can be prefixed with `'variant:'`, `variant` corresponding to one of the
|
|
1154
|
-
* [game variant](https://kokopu.yo35.org/docs/
|
|
1145
|
+
* [game variant](https://kokopu.yo35.org/docs/current/types/GameVariant.html) supported by Kokopu. For instance:
|
|
1155
1146
|
* `'chess960:nrkbqrbn/pppppppp/8/8/8/8/PPPPPPPP/NRKBQRBN w KQkq - 0 1'`.
|
|
1156
1147
|
*/
|
|
1157
|
-
position: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu
|
|
1148
|
+
position: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.Position), _propTypes["default"].string]),
|
|
1158
1149
|
|
|
1159
1150
|
/**
|
|
1160
|
-
* Displayed move (optional), defined either as a [kokopu.MoveDescriptor](https://kokopu.yo35.org/docs/MoveDescriptor.html) object
|
|
1151
|
+
* Displayed move (optional), defined either as a [kokopu.MoveDescriptor](https://kokopu.yo35.org/docs/current/classes/MoveDescriptor.html) object
|
|
1161
1152
|
* or as a [SAN string](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) (e.g. `'Nf3'`). In both cases, it must represent
|
|
1162
1153
|
* a legal move in position defined in attribute `position`.
|
|
1163
1154
|
*/
|
|
1164
|
-
move: _propTypes["default"].oneOfType([
|
|
1165
|
-
if (!_kokopu["default"].isMoveDescriptor(props[propName])) {
|
|
1166
|
-
return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". Validation failed."));
|
|
1167
|
-
}
|
|
1168
|
-
}, _propTypes["default"].string]),
|
|
1155
|
+
move: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.MoveDescriptor), _propTypes["default"].string]),
|
|
1169
1156
|
|
|
1170
1157
|
/**
|
|
1171
1158
|
* 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'`).
|
|
@@ -1332,7 +1319,7 @@ function computeCoordinateFontSize(squareSize) {
|
|
|
1332
1319
|
|
|
1333
1320
|
|
|
1334
1321
|
function parsePosition(position) {
|
|
1335
|
-
if (position instanceof _kokopu
|
|
1322
|
+
if (position instanceof _kokopu.Position) {
|
|
1336
1323
|
return {
|
|
1337
1324
|
error: false,
|
|
1338
1325
|
position: position
|
|
@@ -1341,11 +1328,11 @@ function parsePosition(position) {
|
|
|
1341
1328
|
try {
|
|
1342
1329
|
return {
|
|
1343
1330
|
error: false,
|
|
1344
|
-
position: new _kokopu
|
|
1331
|
+
position: new _kokopu.Position(position)
|
|
1345
1332
|
};
|
|
1346
1333
|
} catch (e) {
|
|
1347
1334
|
// istanbul ignore else
|
|
1348
|
-
if (e instanceof _kokopu
|
|
1335
|
+
if (e instanceof _kokopu.exception.InvalidFEN) {
|
|
1349
1336
|
return {
|
|
1350
1337
|
error: true,
|
|
1351
1338
|
message: e.message
|
|
@@ -1367,7 +1354,7 @@ function parsePosition(position) {
|
|
|
1367
1354
|
|
|
1368
1355
|
|
|
1369
1356
|
function parseMove(position, move) {
|
|
1370
|
-
if (_kokopu
|
|
1357
|
+
if (move instanceof _kokopu.MoveDescriptor) {
|
|
1371
1358
|
return {
|
|
1372
1359
|
error: false,
|
|
1373
1360
|
move: move
|
|
@@ -1380,7 +1367,7 @@ function parseMove(position, move) {
|
|
|
1380
1367
|
};
|
|
1381
1368
|
} catch (e) {
|
|
1382
1369
|
// istanbul ignore else
|
|
1383
|
-
if (e instanceof _kokopu
|
|
1370
|
+
if (e instanceof _kokopu.exception.InvalidNotation) {
|
|
1384
1371
|
return {
|
|
1385
1372
|
error: true,
|
|
1386
1373
|
message: e.message
|
package/dist/lib/ErrorBox.js
CHANGED
|
@@ -11,6 +11,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
13
13
|
|
|
14
|
+
var _util = require("./impl/util");
|
|
15
|
+
|
|
14
16
|
require("./css/error_box.css");
|
|
15
17
|
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -133,7 +135,7 @@ function ellipsisAt(text, pos, backwardCharacters, forwardCharacters, lineNumber
|
|
|
133
135
|
var secondLine = Array(1 + e1.length + pos - p1).join(' ') + '^';
|
|
134
136
|
|
|
135
137
|
if (lineNumber) {
|
|
136
|
-
secondLine +=
|
|
138
|
+
secondLine += " (".concat((0, _util.fillPlaceholder)(_i18n["default"].LINE, lineNumber), ")");
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
return excerpt + '\n' + secondLine;
|
package/dist/lib/Movetext.js
CHANGED
|
@@ -11,10 +11,12 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _react = _interopRequireDefault(require("react"));
|
|
13
13
|
|
|
14
|
-
var _kokopu =
|
|
14
|
+
var _kokopu = require("kokopu");
|
|
15
15
|
|
|
16
16
|
var _HtmlSanitizer = _interopRequireDefault(require("./impl/HtmlSanitizer"));
|
|
17
17
|
|
|
18
|
+
var _util = require("./impl/util");
|
|
19
|
+
|
|
18
20
|
var _Chessboard = _interopRequireDefault(require("./Chessboard"));
|
|
19
21
|
|
|
20
22
|
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
@@ -147,7 +149,7 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
147
149
|
}, sanitizeHtml(title));
|
|
148
150
|
var ratingElement = rating === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
149
151
|
className: "kokopu-header-playerRating"
|
|
150
|
-
},
|
|
152
|
+
}, rating);
|
|
151
153
|
var separator = title === undefined || rating === undefined ? undefined : "\xA0"; // \u00a0 ==
|
|
152
154
|
|
|
153
155
|
var titleRatingGroup = title === undefined && rating === undefined ? undefined : /*#__PURE__*/_react["default"].createElement("span", {
|
|
@@ -225,7 +227,7 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
225
227
|
return undefined;
|
|
226
228
|
}
|
|
227
229
|
|
|
228
|
-
annotator = _i18n["default"].ANNOTATED_BY
|
|
230
|
+
annotator = (0, _util.fillPlaceholder)(_i18n["default"].ANNOTATED_BY, annotator);
|
|
229
231
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
230
232
|
className: "kokopu-header-annotator",
|
|
231
233
|
key: "annotator"
|
|
@@ -405,7 +407,7 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
405
407
|
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
406
408
|
className: "kokopu-nag",
|
|
407
409
|
key: nag
|
|
408
|
-
}, _kokopu
|
|
410
|
+
}, (0, _kokopu.nagSymbol)(nag));
|
|
409
411
|
}); // Class
|
|
410
412
|
|
|
411
413
|
var nodeId = node.id();
|
|
@@ -706,14 +708,14 @@ var Movetext = /*#__PURE__*/function (_React$Component) {
|
|
|
706
708
|
exports["default"] = Movetext;
|
|
707
709
|
Movetext.propTypes = {
|
|
708
710
|
/**
|
|
709
|
-
* Displayed position. Can be a [kokopu.Game](https://kokopu.yo35.org/docs/Game.html) object,
|
|
710
|
-
* a [kokopu.Database](https://kokopu.yo35.org/docs/Database.html) object,
|
|
711
|
+
* Displayed position. Can be a [kokopu.Game](https://kokopu.yo35.org/docs/current/classes/Game.html) object,
|
|
712
|
+
* a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html) object,
|
|
711
713
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation).
|
|
712
714
|
*/
|
|
713
|
-
game: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu
|
|
715
|
+
game: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.Game), _propTypes["default"].instanceOf(_kokopu.Database), _propTypes["default"].string]),
|
|
714
716
|
|
|
715
717
|
/**
|
|
716
|
-
* Index of the game to display (only if attribute `game` is a [kokopu.Database](https://kokopu.yo35.org/docs/Database.html)
|
|
718
|
+
* Index of the game to display (only if attribute `game` is a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html)
|
|
717
719
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation)): `0` for the first game of the database/PGN, `1` for the second one, etc.
|
|
718
720
|
* If omitted, the first game of the database/PGN is displayed.
|
|
719
721
|
*/
|
|
@@ -759,7 +761,7 @@ Movetext.propTypes = {
|
|
|
759
761
|
|
|
760
762
|
/**
|
|
761
763
|
* ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
762
|
-
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/Node.html#id) to get the ID of a game move.
|
|
764
|
+
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id) to get the ID of a game move.
|
|
763
765
|
*/
|
|
764
766
|
selection: _propTypes["default"].string,
|
|
765
767
|
|
|
@@ -773,7 +775,7 @@ Movetext.propTypes = {
|
|
|
773
775
|
/**
|
|
774
776
|
* Callback invoked when the user selects a move (only if `interactionMode` is set to `'selectMove'`).
|
|
775
777
|
*
|
|
776
|
-
* @param {string?} nodeId ID of the selected move (as returned by [kokopu.Node#id](https://kokopu.yo35.org/docs/Node.html#id)),
|
|
778
|
+
* @param {string?} nodeId ID of the selected move (as returned by [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id)),
|
|
777
779
|
* `'start'` for the beginning of the main variation, or `undefined` if the user unselects the previously selected move.
|
|
778
780
|
* @param {string} evtOrigin Origin of the event. Can be:
|
|
779
781
|
* - `'key-first'`: the event has been triggered by the "go-to-first-move" key (aka. the home key),
|
|
@@ -785,7 +787,7 @@ Movetext.propTypes = {
|
|
|
785
787
|
onMoveSelected: _propTypes["default"].func
|
|
786
788
|
};
|
|
787
789
|
Movetext.defaultProps = {
|
|
788
|
-
game: new _kokopu
|
|
790
|
+
game: new _kokopu.Game(),
|
|
789
791
|
gameIndex: 0,
|
|
790
792
|
diagramOptions: {},
|
|
791
793
|
pieceSymbols: 'native',
|
|
@@ -863,21 +865,28 @@ function sanitizeHtml(text, sanitizer) {
|
|
|
863
865
|
|
|
864
866
|
|
|
865
867
|
function parseGame(game, gameIndex) {
|
|
866
|
-
if (game instanceof _kokopu
|
|
868
|
+
if (game instanceof _kokopu.Game) {
|
|
867
869
|
return {
|
|
868
870
|
error: false,
|
|
869
871
|
game: game
|
|
870
872
|
};
|
|
871
|
-
} else if (game instanceof _kokopu
|
|
873
|
+
} else if (game instanceof _kokopu.Database || typeof game === 'string') {
|
|
874
|
+
if (!Number.isInteger(gameIndex) || gameIndex < 0) {
|
|
875
|
+
return {
|
|
876
|
+
error: true,
|
|
877
|
+
message: _i18n["default"].INVALID_GAME_INDEX_ATTRIBUTE_ERROR_MESSAGE
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
872
881
|
try {
|
|
873
|
-
var result = game instanceof _kokopu
|
|
882
|
+
var result = game instanceof _kokopu.Database ? game.game(gameIndex) : (0, _kokopu.pgnRead)(game, gameIndex);
|
|
874
883
|
return {
|
|
875
884
|
error: false,
|
|
876
885
|
game: result
|
|
877
886
|
};
|
|
878
887
|
} catch (e) {
|
|
879
888
|
// istanbul ignore else
|
|
880
|
-
if (e instanceof _kokopu
|
|
889
|
+
if (e instanceof _kokopu.exception.InvalidPGN) {
|
|
881
890
|
return {
|
|
882
891
|
error: true,
|
|
883
892
|
message: e.message,
|
package/dist/lib/i18n.js
CHANGED
|
@@ -44,7 +44,8 @@ var i18n = {
|
|
|
44
44
|
},
|
|
45
45
|
ANNOTATED_BY: 'Annotated by {0}',
|
|
46
46
|
INVALID_PGN_ERROR_TITLE: 'Invalid PGN string.',
|
|
47
|
-
INVALID_GAME_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "game" attribute.'
|
|
47
|
+
INVALID_GAME_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "game" attribute.',
|
|
48
|
+
INVALID_GAME_INDEX_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "game index" attribute.'
|
|
48
49
|
};
|
|
49
50
|
var _default = i18n;
|
|
50
51
|
exports["default"] = _default;
|
|
@@ -42,9 +42,9 @@ function ArrowTip(props) {
|
|
|
42
42
|
markerHeight: 4,
|
|
43
43
|
refX: 2.5,
|
|
44
44
|
refY: 2,
|
|
45
|
-
orient: "auto"
|
|
46
|
-
fill: props.color
|
|
45
|
+
orient: "auto"
|
|
47
46
|
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
47
|
+
fill: props.color,
|
|
48
48
|
d: "M 4,2 L 0,4 L 1,2 L 0,0 Z"
|
|
49
49
|
}));
|
|
50
50
|
}
|