kokopu-react 1.1.0 → 1.4.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/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/dist/lib/ArrowMarkerIcon.js +3 -5
- package/dist/lib/Chessboard.js +25 -32
- package/dist/lib/{impl/ErrorBox.js → ErrorBox.js} +1 -1
- package/dist/lib/TextMarkerIcon.js +11 -10
- package/dist/lib/css/symbol.css +25 -0
- package/dist/lib/i18n.js +35 -0
- package/dist/lib/impl/ArrowTip.js +2 -7
- package/dist/lib/impl/TextSymbol.js +100 -0
- package/dist/lib/impl/util.js +5 -5
- package/dist/lib/index.js +34 -18
- package/dist/lib/markers.js +10 -10
- package/doc_src/{demo/.eslintrc.yml → .eslintrc.yml} +0 -0
- package/doc_src/demo/PageChessboardBase.js +35 -40
- package/doc_src/demo/PageChessboardEdition.js +58 -70
- package/doc_src/demo/PageChessboardMove.js +20 -27
- package/doc_src/demo/PageChessboardSmallScreens.js +15 -16
- package/doc_src/examples/ErrorBox.md +3 -0
- package/doc_src/theming/LogoRenderer.js +50 -0
- package/doc_src/theming/kokopu-react-favicon.png +0 -0
- package/doc_src/theming/kokopu-react-logo.png +0 -0
- package/doc_src/theming/theming.css +29 -0
- package/graphic_test_app/01_marker_icons.js +5 -3
- package/graphic_test_app/04_chessboard_annotations.js +1 -1
- package/graphic_test_app/10_chessboard_play_moves.js +2 -0
- package/graphics/logo-small.svg +14 -0
- package/graphics/logo.svg +26 -0
- package/package.json +23 -21
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +1 -0
- package/scripts/test_headless.webpack-config.js +1 -0
- package/src/ArrowMarkerIcon.js +1 -1
- package/src/Chessboard.js +15 -15
- package/src/{impl/ErrorBox.js → ErrorBox.js} +1 -1
- package/src/TextMarkerIcon.js +6 -6
- package/src/css/symbol.css +25 -0
- package/src/i18n.js +30 -0
- package/src/impl/ArrowTip.js +2 -6
- package/src/impl/TextSymbol.js +77 -0
- package/src/impl/util.js +1 -1
- package/src/index.js +2 -0
- package/src/markers.js +7 -6
- package/test/1_markers.js +19 -0
- package/test/3_marker_icons_graphic.js +1 -1
- package/test/6_chessboard_play_moves.js +4 -0
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/02_chessboard_simple/2.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/03_chessboard_flipped/2.png +0 -0
- package/test/references/04_chessboard_annotations/4.png +0 -0
- package/test/references/04_chessboard_annotations/5.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_ambiguous_king_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_non_kxr_castling.png +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
ChangeLog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
1.4.0 (October 21, 2021)
|
|
5
|
+
------------------------
|
|
6
|
+
* Add support for plus/times/dot/circle in text markers.
|
|
7
|
+
|
|
8
|
+
1.3.1 (September 27, 2021)
|
|
9
|
+
--------------------------
|
|
10
|
+
* Fix missing export for `ErrorBox`.
|
|
11
|
+
|
|
12
|
+
1.3.0 (September 26, 2021)
|
|
13
|
+
--------------------------
|
|
14
|
+
* Expose component `ErrorBox`.
|
|
15
|
+
* Minor fixes in documentation.
|
|
16
|
+
|
|
17
|
+
1.2.0 (September 13, 2021)
|
|
18
|
+
--------------------------
|
|
19
|
+
* Fix ambiguous castling move issue at Chess960.
|
|
20
|
+
|
|
4
21
|
1.1.0 (August 15, 2021)
|
|
5
22
|
-----------------------
|
|
6
23
|
* Provide interaction mode `playMoves`.
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Kokopu-React
|
|
2
2
|
============
|
|
3
3
|
|
|
4
|
+
<img align="right" width="96" height="96" src="graphics/logo.svg" />
|
|
5
|
+
|
|
4
6
|
Kokopu-React is a [React](https://reactjs.org/)-based library to create and display chessboard components.
|
|
5
7
|
Kokopu-React is built on top of [Kokopu](https://www.npmjs.com/package/kokopu), a headless library that
|
|
6
8
|
implements all the chess logic (game rules, parsing of [FEN](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation)
|
|
@@ -31,7 +31,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
31
31
|
|
|
32
32
|
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); }; }
|
|
33
33
|
|
|
34
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
34
|
+
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); }
|
|
35
35
|
|
|
36
36
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
37
|
|
|
@@ -85,10 +85,8 @@ var ArrowMarkerIcon = /*#__PURE__*/function (_React$Component) {
|
|
|
85
85
|
x2: size - halfThickness * 3,
|
|
86
86
|
y2: size / 2,
|
|
87
87
|
stroke: this.props.color,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'markerEnd': "url(#".concat(this.arrowTipId, ")")
|
|
91
|
-
}
|
|
88
|
+
strokeWidth: halfThickness * 2,
|
|
89
|
+
markerEnd: "url(#".concat(this.arrowTipId, ")")
|
|
92
90
|
}));
|
|
93
91
|
}
|
|
94
92
|
}]);
|
package/dist/lib/Chessboard.js
CHANGED
|
@@ -21,7 +21,11 @@ var _piecesets2 = _interopRequireDefault(require("./impl/piecesets"));
|
|
|
21
21
|
|
|
22
22
|
var _ArrowTip = _interopRequireDefault(require("./impl/ArrowTip"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
|
|
25
|
+
|
|
26
|
+
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
27
|
+
|
|
28
|
+
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
25
29
|
|
|
26
30
|
var _markers = require("./markers");
|
|
27
31
|
|
|
@@ -61,7 +65,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
61
65
|
|
|
62
66
|
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); }; }
|
|
63
67
|
|
|
64
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
68
|
+
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); }
|
|
65
69
|
|
|
66
70
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
67
71
|
|
|
@@ -133,12 +137,12 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
133
137
|
|
|
134
138
|
if (info.positionError) {
|
|
135
139
|
return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
|
|
136
|
-
title: "
|
|
140
|
+
title: _i18n["default"].INVALID_FEN_ERROR_TITLE,
|
|
137
141
|
message: info.message
|
|
138
142
|
});
|
|
139
143
|
} else if (info.moveError) {
|
|
140
144
|
return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
|
|
141
|
-
title: "
|
|
145
|
+
title: _i18n["default"].INVALID_NOTATION_ERROR_TITLE,
|
|
142
146
|
message: info.message
|
|
143
147
|
});
|
|
144
148
|
}
|
|
@@ -406,10 +410,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
406
410
|
x2: xTo,
|
|
407
411
|
y2: yTo,
|
|
408
412
|
stroke: colorset[this.props.editedArrowColor],
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
'markerEnd': "url(#".concat(arrowTipId, ")")
|
|
412
|
-
}
|
|
413
|
+
strokeWidth: strokeWidth,
|
|
414
|
+
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
413
415
|
});
|
|
414
416
|
}
|
|
415
417
|
}, {
|
|
@@ -565,16 +567,16 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
565
567
|
|
|
566
568
|
x += squareSize / 2;
|
|
567
569
|
y += squareSize / 2;
|
|
568
|
-
result.push( /*#__PURE__*/_react["default"].createElement("
|
|
570
|
+
result.push( /*#__PURE__*/_react["default"].createElement("g", {
|
|
569
571
|
key: 'txtm-' + sq,
|
|
570
|
-
className: "kokopu-annotation
|
|
572
|
+
className: "kokopu-annotation"
|
|
573
|
+
}, /*#__PURE__*/_react["default"].createElement(_TextSymbol["default"], {
|
|
571
574
|
x: x,
|
|
572
575
|
y: y,
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}, value.symbol));
|
|
576
|
+
size: squareSize,
|
|
577
|
+
symbol: value.symbol,
|
|
578
|
+
color: colorset[value.color]
|
|
579
|
+
})));
|
|
578
580
|
});
|
|
579
581
|
return result;
|
|
580
582
|
}
|
|
@@ -622,10 +624,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
622
624
|
x2: xTo,
|
|
623
625
|
y2: yTo,
|
|
624
626
|
stroke: colorset[color],
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
'markerEnd': "url(#".concat(arrowTipId, ")")
|
|
628
|
-
}
|
|
627
|
+
strokeWidth: strokeWidth,
|
|
628
|
+
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
629
629
|
}));
|
|
630
630
|
});
|
|
631
631
|
return result;
|
|
@@ -661,10 +661,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
661
661
|
x2: x,
|
|
662
662
|
y2: y,
|
|
663
663
|
stroke: colorset['highlight'],
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
'markerEnd': "url(#".concat(this.getArrowTipId('highlight'), ")")
|
|
667
|
-
}
|
|
664
|
+
strokeWidth: squareSize * STROKE_THICKNESS_FACTOR,
|
|
665
|
+
markerEnd: "url(#".concat(this.getArrowTipId('highlight'), ")")
|
|
668
666
|
});
|
|
669
667
|
}
|
|
670
668
|
}, {
|
|
@@ -700,9 +698,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
700
698
|
className: "kokopu-coordinate kokopu-label",
|
|
701
699
|
x: x,
|
|
702
700
|
y: y,
|
|
703
|
-
|
|
704
|
-
'fontSize': fontSize
|
|
705
|
-
}
|
|
701
|
+
fontSize: fontSize
|
|
706
702
|
}, label);
|
|
707
703
|
}
|
|
708
704
|
}, {
|
|
@@ -716,9 +712,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
716
712
|
className: "kokopu-coordinate kokopu-label",
|
|
717
713
|
x: x,
|
|
718
714
|
y: y,
|
|
719
|
-
|
|
720
|
-
'fontSize': fontSize
|
|
721
|
-
}
|
|
715
|
+
fontSize: fontSize
|
|
722
716
|
}, label);
|
|
723
717
|
}
|
|
724
718
|
}, {
|
|
@@ -820,7 +814,6 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
|
820
814
|
}
|
|
821
815
|
});
|
|
822
816
|
break;
|
|
823
|
-
// TODO fix chess960 castling
|
|
824
817
|
// Other cases are not supposed to happen.
|
|
825
818
|
// istanbul ignore next
|
|
826
819
|
|
|
@@ -1318,7 +1311,7 @@ function parsePosition(position) {
|
|
|
1318
1311
|
} else {
|
|
1319
1312
|
return {
|
|
1320
1313
|
error: true,
|
|
1321
|
-
message:
|
|
1314
|
+
message: _i18n["default"].INVALID_POSITION_ATTRIBUTE_ERROR_MESSAGE
|
|
1322
1315
|
};
|
|
1323
1316
|
}
|
|
1324
1317
|
}
|
|
@@ -1353,7 +1346,7 @@ function parseMove(position, move) {
|
|
|
1353
1346
|
} else {
|
|
1354
1347
|
return {
|
|
1355
1348
|
error: true,
|
|
1356
|
-
message:
|
|
1349
|
+
message: _i18n["default"].INVALID_MOVE_ATTRIBUTE_ERROR_MESSAGE
|
|
1357
1350
|
};
|
|
1358
1351
|
}
|
|
1359
1352
|
}
|
|
@@ -9,7 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
require("
|
|
12
|
+
require("./css/error_box.css");
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
15
|
|
|
@@ -9,10 +9,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
require("./css/label.css");
|
|
13
|
-
|
|
14
12
|
var _util = require("./impl/util");
|
|
15
13
|
|
|
14
|
+
var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
|
|
15
|
+
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
17
|
|
|
18
18
|
/******************************************************************************
|
|
@@ -52,15 +52,13 @@ function TextMarkerIcon(props) {
|
|
|
52
52
|
viewBox: viewBox,
|
|
53
53
|
width: size,
|
|
54
54
|
height: size
|
|
55
|
-
}, /*#__PURE__*/_react["default"].createElement("
|
|
56
|
-
className: "kokopu-label",
|
|
55
|
+
}, /*#__PURE__*/_react["default"].createElement(_TextSymbol["default"], {
|
|
57
56
|
x: size / 2,
|
|
58
57
|
y: size / 2,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}, props.symbol));
|
|
58
|
+
size: size,
|
|
59
|
+
symbol: props.symbol,
|
|
60
|
+
color: props.color
|
|
61
|
+
}));
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
TextMarkerIcon.propTypes = {
|
|
@@ -70,7 +68,10 @@ TextMarkerIcon.propTypes = {
|
|
|
70
68
|
size: _propTypes["default"].number.isRequired,
|
|
71
69
|
|
|
72
70
|
/**
|
|
73
|
-
* Symbol to represent on the icon. Must be
|
|
71
|
+
* Symbol to represent on the icon. Must be one of:
|
|
72
|
+
* - any letter from A to Z (either upper-case or lower-case),
|
|
73
|
+
* - any digit from 0 to 9,
|
|
74
|
+
* - any symbol code among `'plus'`, `'times'`, `'dot'`, or `'circle'`.
|
|
74
75
|
*/
|
|
75
76
|
symbol: _propTypes["default"].string.isRequired,
|
|
76
77
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
|
+
* *
|
|
6
|
+
* This program is free software: you can redistribute it and/or *
|
|
7
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
9
|
+
* the License, or (at your option) any later version. *
|
|
10
|
+
* *
|
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
|
+
* GNU Lesser General Public License for more details. *
|
|
15
|
+
* *
|
|
16
|
+
* You should have received a copy of the GNU Lesser General *
|
|
17
|
+
* Public License along with this program. If not, see *
|
|
18
|
+
* <http://www.gnu.org/licenses/>. *
|
|
19
|
+
* *
|
|
20
|
+
******************************************************************************/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
.kokopu-symbolCircle {
|
|
24
|
+
fill: transparent;
|
|
25
|
+
}
|
package/dist/lib/i18n.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
* *
|
|
10
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
11
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
12
|
+
* *
|
|
13
|
+
* This program is free software: you can redistribute it and/or *
|
|
14
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
15
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
16
|
+
* the License, or (at your option) any later version. *
|
|
17
|
+
* *
|
|
18
|
+
* This program is distributed in the hope that it will be useful, *
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
21
|
+
* GNU Lesser General Public License for more details. *
|
|
22
|
+
* *
|
|
23
|
+
* You should have received a copy of the GNU Lesser General *
|
|
24
|
+
* Public License along with this program. If not, see *
|
|
25
|
+
* <http://www.gnu.org/licenses/>. *
|
|
26
|
+
* *
|
|
27
|
+
******************************************************************************/
|
|
28
|
+
var i18n = {
|
|
29
|
+
INVALID_FEN_ERROR_TITLE: 'Invalid FEN string.',
|
|
30
|
+
INVALID_NOTATION_ERROR_TITLE: 'Invalid move notation.',
|
|
31
|
+
INVALID_POSITION_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "position" attribute.',
|
|
32
|
+
INVALID_MOVE_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "move" attribute.'
|
|
33
|
+
};
|
|
34
|
+
var _default = i18n;
|
|
35
|
+
exports["default"] = _default;
|
|
@@ -43,9 +43,7 @@ function ArrowTip(props) {
|
|
|
43
43
|
refX: 2.5,
|
|
44
44
|
refY: 2,
|
|
45
45
|
orient: "auto",
|
|
46
|
-
|
|
47
|
-
fill: props.color
|
|
48
|
-
}
|
|
46
|
+
fill: props.color
|
|
49
47
|
}, /*#__PURE__*/_react["default"].createElement("path", {
|
|
50
48
|
d: "M 4,2 L 0,4 L 1,2 L 0,0 Z"
|
|
51
49
|
}));
|
|
@@ -60,8 +58,5 @@ ArrowTip.propTypes = {
|
|
|
60
58
|
/**
|
|
61
59
|
* Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
|
|
62
60
|
*/
|
|
63
|
-
color: _propTypes["default"].string
|
|
64
|
-
};
|
|
65
|
-
ArrowTip.defaultProps = {
|
|
66
|
-
color: 'currentcolor'
|
|
61
|
+
color: _propTypes["default"].string.isRequired
|
|
67
62
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = TextSymbol;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
require("../css/label.css");
|
|
13
|
+
|
|
14
|
+
require("../css/symbol.css");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
+
|
|
18
|
+
/******************************************************************************
|
|
19
|
+
* *
|
|
20
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
21
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
22
|
+
* *
|
|
23
|
+
* This program is free software: you can redistribute it and/or *
|
|
24
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
25
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
26
|
+
* the License, or (at your option) any later version. *
|
|
27
|
+
* *
|
|
28
|
+
* This program is distributed in the hope that it will be useful, *
|
|
29
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
30
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
31
|
+
* GNU Lesser General Public License for more details. *
|
|
32
|
+
* *
|
|
33
|
+
* You should have received a copy of the GNU Lesser General *
|
|
34
|
+
* Public License along with this program. If not, see *
|
|
35
|
+
* <http://www.gnu.org/licenses/>. *
|
|
36
|
+
* *
|
|
37
|
+
******************************************************************************/
|
|
38
|
+
var SHAPE_THICKNESS_FACTOR = 0.1;
|
|
39
|
+
var DOT_RADIUS_FACTOR = 0.15;
|
|
40
|
+
var CIRCLE_RADIUS_FACTOR = 0.425;
|
|
41
|
+
/**
|
|
42
|
+
* Symbol of a text marker.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
function TextSymbol(props) {
|
|
46
|
+
if (props.symbol === 'dot') {
|
|
47
|
+
return /*#__PURE__*/_react["default"].createElement("circle", {
|
|
48
|
+
cx: props.x,
|
|
49
|
+
cy: props.y,
|
|
50
|
+
r: props.size * DOT_RADIUS_FACTOR,
|
|
51
|
+
fill: props.color
|
|
52
|
+
});
|
|
53
|
+
} else if (props.symbol === 'circle') {
|
|
54
|
+
var thickness = props.size * SHAPE_THICKNESS_FACTOR;
|
|
55
|
+
return /*#__PURE__*/_react["default"].createElement("circle", {
|
|
56
|
+
className: "kokopu-symbolCircle",
|
|
57
|
+
cx: props.x,
|
|
58
|
+
cy: props.y,
|
|
59
|
+
r: props.size * CIRCLE_RADIUS_FACTOR,
|
|
60
|
+
stroke: props.color,
|
|
61
|
+
strokeWidth: thickness
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
var symbol = props.symbol === 'plus' ? '+' : props.symbol === 'times' ? "\xD7" : props.symbol;
|
|
65
|
+
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
66
|
+
className: "kokopu-label",
|
|
67
|
+
x: props.x,
|
|
68
|
+
y: props.y,
|
|
69
|
+
fill: props.color,
|
|
70
|
+
fontSize: props.size
|
|
71
|
+
}, symbol);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
TextSymbol.propTypes = {
|
|
76
|
+
/**
|
|
77
|
+
* X-coordinate of the center of the symbol.
|
|
78
|
+
*/
|
|
79
|
+
x: _propTypes["default"].number.isRequired,
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Y-coordinate of the center of the symbol.
|
|
83
|
+
*/
|
|
84
|
+
y: _propTypes["default"].number.isRequired,
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Size of the symbol (i.e. size of square in which the symbol is rendered).
|
|
88
|
+
*/
|
|
89
|
+
size: _propTypes["default"].number.isRequired,
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Symbol code.
|
|
93
|
+
*/
|
|
94
|
+
symbol: _propTypes["default"].string.isRequired,
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
|
|
98
|
+
*/
|
|
99
|
+
color: _propTypes["default"].string.isRequired
|
|
100
|
+
};
|
package/dist/lib/impl/util.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.MIN_SQUARE_SIZE = exports.MAX_SQUARE_SIZE = void 0;
|
|
6
7
|
exports.generateRandomId = generateRandomId;
|
|
7
|
-
exports.sanitizeInteger = sanitizeInteger;
|
|
8
|
-
exports.isValidSquare = isValidSquare;
|
|
9
|
-
exports.isValidVector = isValidVector;
|
|
10
8
|
exports.isValidColor = isValidColor;
|
|
9
|
+
exports.isValidSquare = isValidSquare;
|
|
11
10
|
exports.isValidSymbol = isValidSymbol;
|
|
12
|
-
exports.
|
|
11
|
+
exports.isValidVector = isValidVector;
|
|
12
|
+
exports.sanitizeInteger = sanitizeInteger;
|
|
13
13
|
|
|
14
14
|
/******************************************************************************
|
|
15
15
|
* *
|
|
@@ -65,5 +65,5 @@ function isValidColor(color) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function isValidSymbol(symbol) {
|
|
68
|
-
return /^[A-Za-z0-9]$/.test(symbol);
|
|
68
|
+
return /^(?:[A-Za-z0-9]|plus|times|dot|circle)$/.test(symbol);
|
|
69
69
|
}
|
package/dist/lib/index.js
CHANGED
|
@@ -3,28 +3,34 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "ArrowMarkerIcon", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return
|
|
9
|
+
return _ArrowMarkerIcon["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "Chessboard", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return
|
|
15
|
+
return _Chessboard["default"];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "ErrorBox", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return
|
|
21
|
+
return _ErrorBox["default"];
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "SquareMarkerIcon", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function get() {
|
|
27
|
-
return
|
|
27
|
+
return _SquareMarkerIcon["default"];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "TextMarkerIcon", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _TextMarkerIcon["default"];
|
|
28
34
|
}
|
|
29
35
|
});
|
|
30
36
|
Object.defineProperty(exports, "flattenArrowMarkers", {
|
|
@@ -33,41 +39,51 @@ Object.defineProperty(exports, "flattenArrowMarkers", {
|
|
|
33
39
|
return _markers.flattenArrowMarkers;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "flattenSquareMarkers", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function get() {
|
|
39
|
-
return _markers.
|
|
45
|
+
return _markers.flattenSquareMarkers;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "flattenTextMarkers", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
get: function get() {
|
|
45
|
-
return
|
|
51
|
+
return _markers.flattenTextMarkers;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "i18n", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function get() {
|
|
51
|
-
return
|
|
57
|
+
return _i18n["default"];
|
|
52
58
|
}
|
|
53
59
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "parseArrowMarkers", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function get() {
|
|
57
|
-
return
|
|
63
|
+
return _markers.parseArrowMarkers;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
60
|
-
Object.defineProperty(exports, "
|
|
66
|
+
Object.defineProperty(exports, "parseSquareMarkers", {
|
|
61
67
|
enumerable: true,
|
|
62
68
|
get: function get() {
|
|
63
|
-
return
|
|
69
|
+
return _markers.parseSquareMarkers;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "parseTextMarkers", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _markers.parseTextMarkers;
|
|
64
76
|
}
|
|
65
77
|
});
|
|
66
78
|
|
|
67
79
|
var _markers = require("./markers");
|
|
68
80
|
|
|
81
|
+
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
82
|
+
|
|
69
83
|
var _Chessboard = _interopRequireDefault(require("./Chessboard"));
|
|
70
84
|
|
|
85
|
+
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
86
|
+
|
|
71
87
|
var _SquareMarkerIcon = _interopRequireDefault(require("./SquareMarkerIcon"));
|
|
72
88
|
|
|
73
89
|
var _TextMarkerIcon = _interopRequireDefault(require("./TextMarkerIcon"));
|
package/dist/lib/markers.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.flattenArrowMarkers = flattenArrowMarkers;
|
|
6
7
|
exports.flattenSquareMarkers = flattenSquareMarkers;
|
|
7
8
|
exports.flattenTextMarkers = flattenTextMarkers;
|
|
8
|
-
exports.
|
|
9
|
+
exports.parseArrowMarkers = parseArrowMarkers;
|
|
9
10
|
exports.parseSquareMarkers = parseSquareMarkers;
|
|
10
11
|
exports.parseTextMarkers = parseTextMarkers;
|
|
11
|
-
exports.parseArrowMarkers = parseArrowMarkers;
|
|
12
12
|
|
|
13
13
|
var _util = require("./impl/util");
|
|
14
14
|
|
|
@@ -50,8 +50,8 @@ function flattenSquareMarkers(markers) {
|
|
|
50
50
|
/**
|
|
51
51
|
* Transform a set of text markers defined as a "square -> (symbol, color)" struct into a comma-separated string.
|
|
52
52
|
*
|
|
53
|
-
* @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
|
|
54
|
-
* @returns {string} For example: `'Rzd5,GAe4'`
|
|
53
|
+
* @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
|
|
54
|
+
* @returns {string} For example: `'Rzd5,GAe4,Y(plus)h3'`
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
|
|
@@ -69,7 +69,7 @@ function flattenTextMarkers(markers) {
|
|
|
69
69
|
sq = _ref8[0],
|
|
70
70
|
desc = _ref8[1];
|
|
71
71
|
|
|
72
|
-
return desc.color.toUpperCase() + desc.symbol + sq;
|
|
72
|
+
return desc.color.toUpperCase() + (desc.symbol.length === 1 ? desc.symbol : '(' + desc.symbol + ')') + sq;
|
|
73
73
|
}).join(',');
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -130,17 +130,17 @@ function parseSquareMarkers(markers) {
|
|
|
130
130
|
/**
|
|
131
131
|
* Parse a set of text markers defined as a comma-separated string into a "square -> (symbol, color)" struct.
|
|
132
132
|
*
|
|
133
|
-
* @param {string} markers For example: `'Rzd5,GAe4'`
|
|
134
|
-
* @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
|
|
133
|
+
* @param {string} markers For example: `'Rzd5,GAe4,Y(plus)h3'`
|
|
134
|
+
* @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
|
|
135
135
|
*/
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
function parseTextMarkers(markers) {
|
|
139
139
|
return parseMarkers(markers, function (token) {
|
|
140
|
-
return /^([GRY])([A-Za-z0-9])([a-h][1-8])$/.test(token) ? {
|
|
141
|
-
key: RegExp.$
|
|
140
|
+
return /^([GRY])(?:([A-Za-z0-9])|\((plus|times|dot|circle)\))([a-h][1-8])$/.test(token) ? {
|
|
141
|
+
key: RegExp.$4,
|
|
142
142
|
value: {
|
|
143
|
-
symbol: RegExp.$2,
|
|
143
|
+
symbol: RegExp.$2 || RegExp.$3,
|
|
144
144
|
color: RegExp.$1.toLowerCase()
|
|
145
145
|
}
|
|
146
146
|
} : undefined;
|
|
File without changes
|