kokopu-react 1.3.1 → 1.5.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/lib/ArrowMarkerIcon.js +5 -7
  4. package/dist/lib/Chessboard.js +23 -33
  5. package/dist/lib/ErrorBox.js +85 -5
  6. package/dist/lib/Movetext.js +839 -0
  7. package/dist/lib/SquareMarkerIcon.js +1 -1
  8. package/dist/lib/TextMarkerIcon.js +12 -11
  9. package/dist/lib/css/arrow.css +1 -1
  10. package/dist/lib/css/chessboard.css +6 -1
  11. package/dist/lib/css/error_box.css +13 -2
  12. package/dist/lib/css/fonts.css +34 -0
  13. package/dist/lib/css/movetext.css +117 -0
  14. package/dist/lib/css/{label.css → symbol.css} +6 -2
  15. package/dist/lib/fonts/chessalpha.woff +0 -0
  16. package/dist/lib/fonts/chessalpha.woff2 +0 -0
  17. package/dist/lib/i18n.js +17 -2
  18. package/dist/lib/impl/ArrowTip.js +3 -8
  19. package/dist/lib/impl/HtmlSanitizer.js +171 -0
  20. package/dist/lib/impl/TextSymbol.js +98 -0
  21. package/dist/lib/impl/colorsets.js +1 -1
  22. package/dist/lib/impl/piecesets.js +1 -1
  23. package/dist/lib/impl/util.js +6 -6
  24. package/dist/lib/index.js +32 -24
  25. package/dist/lib/markers.js +10 -10
  26. package/doc_src/demo/PageChessboardBase.js +1 -1
  27. package/doc_src/demo/{PageChessboardEdition.js → PageChessboardInteraction.js} +4 -5
  28. package/doc_src/demo/PageChessboardMove.js +1 -1
  29. package/doc_src/demo/PageChessboardSmallScreens.js +1 -1
  30. package/doc_src/demo/PageMovetextBase.js +214 -0
  31. package/doc_src/demo/PageMovetextInteraction.js +155 -0
  32. package/doc_src/demo/demo.css +8 -1
  33. package/doc_src/demo/game-1.pgn +23 -0
  34. package/doc_src/demo/game-2.pgn +22 -0
  35. package/doc_src/demo/game-invalid.pgn +10 -0
  36. package/doc_src/demo/util.js +1 -1
  37. package/doc_src/examples/Movetext.md +15 -0
  38. package/doc_src/home.md +2 -0
  39. package/doc_src/theming/LogoRenderer.js +1 -1
  40. package/doc_src/theming/kokopu-react-favicon.png +0 -0
  41. package/doc_src/theming/theming.css +1 -1
  42. package/graphic_test_app/01_marker_icons.js +6 -4
  43. package/graphic_test_app/02_chessboard_simple.js +1 -1
  44. package/graphic_test_app/03_chessboard_flipped.js +1 -1
  45. package/graphic_test_app/04_chessboard_annotations.js +2 -2
  46. package/graphic_test_app/05_chessboard_move.js +1 -1
  47. package/graphic_test_app/06_chessboard_theme.js +1 -1
  48. package/graphic_test_app/07_chessboard_click_squares.js +1 -1
  49. package/graphic_test_app/08_chessboard_move_pieces.js +1 -1
  50. package/graphic_test_app/09_chessboard_edit_arrows.js +1 -1
  51. package/graphic_test_app/10_chessboard_play_moves.js +1 -1
  52. package/graphic_test_app/11_chessboard_play_promotions.js +1 -1
  53. package/graphic_test_app/12_movetext_simple.js +41 -0
  54. package/graphic_test_app/13_movetext_error.js +38 -0
  55. package/graphic_test_app/14_movetext_html.js +40 -0
  56. package/graphic_test_app/15_movetext_options.js +42 -0
  57. package/graphic_test_app/16_movetext_interaction.js +42 -0
  58. package/graphic_test_app/common/dummy.pgn +8 -0
  59. package/graphic_test_app/common/games.pgn +167 -0
  60. package/graphic_test_app/common/heartbeat.txt +1 -0
  61. package/graphic_test_app/common/test_app.css +20 -4
  62. package/graphic_test_app/common/test_app.js +6 -6
  63. package/package.json +26 -25
  64. package/scripts/test_graphic/clean-graphic-output.js +1 -1
  65. package/scripts/test_graphic/docker-compose.yml +1 -1
  66. package/scripts/test_graphic/webpack-config.js +8 -3
  67. package/scripts/test_headless.webpack-config.js +3 -2
  68. package/src/ArrowMarkerIcon.js +2 -2
  69. package/src/Chessboard.js +11 -11
  70. package/src/ErrorBox.js +80 -1
  71. package/src/Movetext.js +616 -0
  72. package/src/SquareMarkerIcon.js +1 -1
  73. package/src/TextMarkerIcon.js +7 -7
  74. package/src/css/arrow.css +1 -1
  75. package/src/css/chessboard.css +6 -1
  76. package/src/css/error_box.css +13 -2
  77. package/src/css/fonts.css +34 -0
  78. package/src/css/movetext.css +117 -0
  79. package/src/css/{label.css → symbol.css} +6 -2
  80. package/src/fonts/chessalpha.woff +0 -0
  81. package/src/fonts/chessalpha.woff2 +0 -0
  82. package/src/i18n.js +12 -1
  83. package/src/impl/ArrowTip.js +3 -7
  84. package/src/impl/HtmlSanitizer.js +120 -0
  85. package/src/impl/TextSymbol.js +76 -0
  86. package/src/impl/colorsets.js +1 -1
  87. package/src/impl/piecesets.js +1 -1
  88. package/src/impl/util.js +2 -2
  89. package/src/index.js +2 -1
  90. package/src/markers.js +8 -7
  91. package/test/1_markers.js +20 -1
  92. package/test/2_chessboard_util.js +1 -1
  93. package/test/3_marker_icons_graphic.js +2 -2
  94. package/test/4_chessboard_graphic.js +1 -1
  95. package/test/5_chessboard_interaction.js +1 -1
  96. package/test/6_chessboard_play_moves.js +1 -1
  97. package/test/7_movetext_graphic.js +43 -0
  98. package/test/8_movetext_interaction.js +99 -0
  99. package/test/common/graphic.js +2 -2
  100. package/test/references/01_marker_icons/10.png +0 -0
  101. package/test/references/01_marker_icons/9.png +0 -0
  102. package/test/references/04_chessboard_annotations/4.png +0 -0
  103. package/test/references/04_chessboard_annotations/5.png +0 -0
  104. package/test/references/05_chessboard_move/3.png +0 -0
  105. package/test/references/12_movetext_simple/0.png +0 -0
  106. package/test/references/12_movetext_simple/1.png +0 -0
  107. package/test/references/12_movetext_simple/2.png +0 -0
  108. package/test/references/12_movetext_simple/3.png +0 -0
  109. package/test/references/13_movetext_error/0.png +0 -0
  110. package/test/references/13_movetext_error/1.png +0 -0
  111. package/test/references/13_movetext_error/2.png +0 -0
  112. package/test/references/13_movetext_error/3.png +0 -0
  113. package/test/references/14_movetext_html/0.png +0 -0
  114. package/test/references/14_movetext_html/1.png +0 -0
  115. package/test/references/14_movetext_html/2.png +0 -0
  116. package/test/references/15_movetext_options/0.png +0 -0
  117. package/test/references/15_movetext_options/1.png +0 -0
  118. package/test/references/15_movetext_options/2.png +0 -0
  119. package/test/references/15_movetext_options/3.png +0 -0
  120. package/test/references/16_movetext_interaction/0.png +0 -0
  121. package/test/references/16_movetext_interaction/1.png +0 -0
  122. package/test/references/16_movetext_interaction/2.png +0 -0
  123. package/graphic_test_app/common/healthcheck.txt +0 -1
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -36,6 +36,17 @@
36
36
  font-style: italic;
37
37
  }
38
38
 
39
- .kokopu-errorMessage {
39
+ .kokopu-errorMessage,
40
+ .kokopu-errorExcerpt {
40
41
  margin-top: 0.4em;
41
42
  }
43
+
44
+ .kokopu-errorExcerpt {
45
+ white-space: pre-wrap;
46
+ font-family: monospace;
47
+ line-height: 1.5em;
48
+ color: #400;
49
+ background-color: #ffd;
50
+ border: solid 1px #aa0;
51
+ padding: 0.75em 1em 0.15em;
52
+ }
@@ -0,0 +1,34 @@
1
+ /******************************************************************************
2
+ * *
3
+ * This file is part of Kokopu-React, a JavaScript chess library. *
4
+ * Copyright (C) 2021-2022 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
+ @font-face {
24
+ font-family: 'Chess Alpha';
25
+ src:
26
+ url('../fonts/chessalpha.woff2') format('woff2'),
27
+ url('../fonts/chessalpha.woff') format('woff');
28
+ font-weight: normal;
29
+ font-style: normal;
30
+ }
31
+
32
+ .kokopu-font-alpha {
33
+ font-family: 'Chess Alpha', sans-serif;
34
+ }
@@ -0,0 +1,117 @@
1
+ /******************************************************************************
2
+ * *
3
+ * This file is part of Kokopu-React, a JavaScript chess library. *
4
+ * Copyright (C) 2021-2022 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-colorTag {
24
+ width : 1.2em;
25
+ height: 1.2em;
26
+ vertical-align: middle;
27
+ display: inline-block;
28
+ border: 1px solid black;
29
+ margin-right: 0.25em;
30
+ }
31
+
32
+ .kokopu-headerGroup-whitePlayer .kokopu-colorTag {
33
+ background-color: white;
34
+ }
35
+
36
+ .kokopu-headerGroup-blackPlayer .kokopu-colorTag {
37
+ background-color: black;
38
+ }
39
+
40
+ .kokopu-headerGroup-titleRating:before,
41
+ .kokopu-header-round:before {
42
+ content: "\a0("; /* \a0 == &nbsp; */
43
+ }
44
+
45
+ .kokopu-headerGroup-titleRating:after,
46
+ .kokopu-header-round:after {
47
+ content: ")";
48
+ }
49
+
50
+ .kokopu-header-round,
51
+ .kokopu-header-annotator {
52
+ font-style: italic;
53
+ }
54
+
55
+ * + .kokopu-move:before,
56
+ * + .kokopu-gameResult:before,
57
+ * + span.kokopu-comment:before {
58
+ content: " ";
59
+ }
60
+
61
+ span.kokopu-variation:before {
62
+ content: " (";
63
+ }
64
+
65
+ span.kokopu-variation:after {
66
+ content: ")";
67
+ }
68
+
69
+ * + .kokopu-nag:before {
70
+ content: "\a0"; /* \a0 == &nbsp; */
71
+ }
72
+
73
+ div.kokopu-subVariation {
74
+ margin-left: 1.5em;
75
+ }
76
+
77
+ .kokopu-move,
78
+ .kokopu-gameResult {
79
+ font-weight: bold;
80
+ }
81
+
82
+ .kokopu-subVariation .kokopu-move {
83
+ font-weight: inherit;
84
+ }
85
+
86
+ .kokopu-diagram {
87
+ text-align: center;
88
+ line-height: 0px;
89
+ }
90
+
91
+ .kokopu-moveContent {
92
+ display: inline-block;
93
+ padding-left: 1px;
94
+ padding-right: 1px;
95
+ }
96
+
97
+ .kokopu-selectedMove .kokopu-moveContent {
98
+ background-color: currentcolor;
99
+ }
100
+
101
+ .kokopu-selectedMove .kokopu-moveContent > * {
102
+ filter: invert(1);
103
+ }
104
+
105
+ .kokopu-clickableMove .kokopu-moveContent:hover {
106
+ text-decoration: underline;
107
+ cursor: pointer;
108
+ }
109
+
110
+ .kokopu-focusFieldContainer {
111
+ position: fixed;
112
+ bottom: 0px;
113
+ right: 0px;
114
+ width: 0px;
115
+ height: 0px;
116
+ overflow: hidden;
117
+ }
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -20,7 +20,11 @@
20
20
  ******************************************************************************/
21
21
 
22
22
 
23
- .kokopu-label {
23
+ .kokopu-symbolCircle {
24
+ fill: transparent;
25
+ }
26
+
27
+ .kokopu-symbolText {
24
28
  font-style: normal;
25
29
  font-family: sans-serif;
26
30
  text-anchor: middle;
Binary file
Binary file
package/src/i18n.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -21,10 +21,21 @@
21
21
 
22
22
 
23
23
  const i18n = {
24
+
25
+ // Error box
26
+ LINE: 'line {0}',
27
+
28
+ // Chessboard
24
29
  INVALID_FEN_ERROR_TITLE: 'Invalid FEN string.',
25
30
  INVALID_NOTATION_ERROR_TITLE: 'Invalid move notation.',
26
31
  INVALID_POSITION_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "position" attribute.',
27
32
  INVALID_MOVE_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "move" attribute.',
33
+
34
+ // Movetext
35
+ PIECE_SYMBOLS: { 'K':'K', 'Q':'Q', 'R':'R', 'B':'B', 'N':'N', 'P':'P' },
36
+ ANNOTATED_BY: 'Annotated by {0}',
37
+ INVALID_PGN_ERROR_TITLE: 'Invalid PGN string.',
38
+ INVALID_GAME_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "game" attribute.',
28
39
  };
29
40
 
30
41
  export default i18n;
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -29,7 +29,7 @@ import React from 'react';
29
29
  */
30
30
  export default function ArrowTip(props) {
31
31
  return (
32
- <marker id={props.id} markerWidth={4} markerHeight={4} refX={2.5} refY={2} orient="auto" style={{ fill: props.color }}>
32
+ <marker id={props.id} markerWidth={4} markerHeight={4} refX={2.5} refY={2} orient="auto" fill={props.color}>
33
33
  <path d="M 4,2 L 0,4 L 1,2 L 0,0 Z" />
34
34
  </marker>
35
35
  );
@@ -45,9 +45,5 @@ ArrowTip.propTypes = {
45
45
  /**
46
46
  * Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
47
47
  */
48
- color: PropTypes.string,
49
- };
50
-
51
- ArrowTip.defaultProps = {
52
- color: 'currentcolor',
48
+ color: PropTypes.string.isRequired,
53
49
  };
@@ -0,0 +1,120 @@
1
+ /******************************************************************************
2
+ * *
3
+ * This file is part of Kokopu-React, a JavaScript chess library. *
4
+ * Copyright (C) 2021-2022 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
+ import React from 'react';
24
+ import * as htmlparser2 from 'htmlparser2';
25
+
26
+
27
+ /**
28
+ * HTML sanitizer: parse HTML string, keeping only the allowed HTML nodes, and the corresponding React object.
29
+ */
30
+ export default class HtmlSanitizer {
31
+
32
+ constructor({ allowedTags, allowedAttributes }) {
33
+ this._allowedTags = allowedTags ? new Set(allowedTags) : new Set();
34
+ this._allowedAttributes = allowedAttributes ? new Map(Object.entries(allowedAttributes).map(([k, v]) => [k, new Set(v)])) : new Map();
35
+ this._keyCounter = 0;
36
+ }
37
+
38
+ /**
39
+ * @param {string} text HTML string to be parsed.
40
+ * @returns {*} React object corresponding to the given HTML string. Can also be a fragment, or just a simple string if the given HTML string
41
+ * does not contain any HTML tag.
42
+ */
43
+ parse(text) {
44
+ let dom = htmlparser2.parseDocument(text);
45
+
46
+ // Ensure that the returned object is a non-empty node type.
47
+ if (dom.type !== 'root') {
48
+ return undefined;
49
+ }
50
+
51
+ // Process the children of the root node.
52
+ let result = [];
53
+ dom.children.forEach(child => {
54
+ let childElement = this._processNode(child);
55
+ if (childElement) {
56
+ result.push(childElement);
57
+ }
58
+ });
59
+
60
+ // Return the result.
61
+ if (result.length === 0) {
62
+ return undefined;
63
+ }
64
+ else if (result.length === 1) {
65
+ return result[0];
66
+ }
67
+ else {
68
+ return <React.Fragment key={this._allocateKey()}>{result}</React.Fragment>;
69
+ }
70
+ }
71
+
72
+ _processNode(node) {
73
+ if (node.type === 'text') {
74
+ return node.data;
75
+ }
76
+ else if (node.type === 'tag') {
77
+ let children = node.children.map(child => this._processNode(child));
78
+ if (this._allowedTags.has(node.name)) {
79
+ let attributes = this._filterAttributes(node.name, node.attribs);
80
+ attributes['key'] = this._allocateKey();
81
+ return React.createElement(node.name, attributes, children);
82
+ }
83
+ else {
84
+ return <React.Fragment key={this._allocateKey()}>{children}</React.Fragment>;
85
+ }
86
+ }
87
+ else {
88
+ return undefined;
89
+ }
90
+ }
91
+
92
+ _filterAttributes(nodeName, attributes) {
93
+ let result = {};
94
+ for (let [attribute, value] of Object.entries(attributes)) {
95
+ if (this._isAttributeAllowed(nodeName, attribute)) {
96
+ result[attribute === 'class' ? 'className' : attribute] = value;
97
+ }
98
+ }
99
+ return result;
100
+ }
101
+
102
+ _isAttributeAllowed(nodeName, attribute) {
103
+ if (attribute === 'key' && attribute === 'ref' && attribute === 'className') { // Those attributes are always forbidden.
104
+ return false;
105
+ }
106
+ let allowedAttributesForCurrent = this._allowedAttributes.get(nodeName);
107
+ if (allowedAttributesForCurrent && allowedAttributesForCurrent.has(attribute)) {
108
+ return true;
109
+ }
110
+ let allowedAttributesForAll = this._allowedAttributes.get('*');
111
+ if (allowedAttributesForAll && allowedAttributesForAll.has(attribute)) {
112
+ return true;
113
+ }
114
+ return false;
115
+ }
116
+
117
+ _allocateKey() {
118
+ return 'auto-' + (this._keyCounter++);
119
+ }
120
+ }
@@ -0,0 +1,76 @@
1
+ /******************************************************************************
2
+ * *
3
+ * This file is part of Kokopu-React, a JavaScript chess library. *
4
+ * Copyright (C) 2021-2022 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
+ import PropTypes from 'prop-types';
24
+ import React from 'react';
25
+
26
+ import '../css/symbol.css';
27
+
28
+ const SHAPE_THICKNESS_FACTOR = 0.1;
29
+ const DOT_RADIUS_FACTOR = 0.15;
30
+ const CIRCLE_RADIUS_FACTOR = 0.425;
31
+
32
+
33
+ /**
34
+ * Symbol of a text marker.
35
+ */
36
+ export default function TextSymbol(props) {
37
+ if (props.symbol === 'dot') {
38
+ return <circle cx={props.x} cy={props.y} r={props.size * DOT_RADIUS_FACTOR} fill={props.color} />;
39
+ }
40
+ else if (props.symbol === 'circle') {
41
+ let thickness = props.size * SHAPE_THICKNESS_FACTOR;
42
+ return <circle className="kokopu-symbolCircle" cx={props.x} cy={props.y} r={props.size * CIRCLE_RADIUS_FACTOR} stroke={props.color} strokeWidth={thickness} />;
43
+ }
44
+ else {
45
+ let symbol = props.symbol === 'plus' ? '+' : props.symbol === 'times' ? '\u00d7' : props.symbol;
46
+ return <text className="kokopu-symbolText" x={props.x} y={props.y} fill={props.color} fontSize={props.size}>{symbol}</text>;
47
+ }
48
+ }
49
+
50
+ TextSymbol.propTypes = {
51
+
52
+ /**
53
+ * X-coordinate of the center of the symbol.
54
+ */
55
+ x: PropTypes.number.isRequired,
56
+
57
+ /**
58
+ * Y-coordinate of the center of the symbol.
59
+ */
60
+ y: PropTypes.number.isRequired,
61
+
62
+ /**
63
+ * Size of the symbol (i.e. size of square in which the symbol is rendered).
64
+ */
65
+ size: PropTypes.number.isRequired,
66
+
67
+ /**
68
+ * Symbol code.
69
+ */
70
+ symbol: PropTypes.string.isRequired,
71
+
72
+ /**
73
+ * Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
74
+ */
75
+ color: PropTypes.string.isRequired,
76
+ };
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
package/src/impl/util.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -56,5 +56,5 @@ export function isValidColor(color) {
56
56
 
57
57
 
58
58
  export function isValidSymbol(symbol) {
59
- return /^[A-Za-z0-9]$/.test(symbol);
59
+ return /^(?:[A-Za-z0-9]|plus|times|dot|circle)$/.test(symbol);
60
60
  }
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -24,6 +24,7 @@ export { flattenSquareMarkers, parseSquareMarkers, flattenTextMarkers, parseText
24
24
  export { default as i18n } from './i18n';
25
25
  export { default as Chessboard } from './Chessboard';
26
26
  export { default as ErrorBox } from './ErrorBox';
27
+ export { default as Movetext } from './Movetext';
27
28
  export { default as SquareMarkerIcon } from './SquareMarkerIcon';
28
29
  export { default as TextMarkerIcon } from './TextMarkerIcon';
29
30
  export { default as ArrowMarkerIcon } from './ArrowMarkerIcon';
package/src/markers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -41,14 +41,14 @@ export function flattenSquareMarkers(markers) {
41
41
  /**
42
42
  * Transform a set of text markers defined as a "square -> (symbol, color)" struct into a comma-separated string.
43
43
  *
44
- * @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
45
- * @returns {string} For example: `'Rzd5,GAe4'`
44
+ * @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
45
+ * @returns {string} For example: `'Rzd5,GAe4,Y(plus)h3'`
46
46
  */
47
47
  export function flattenTextMarkers(markers) {
48
48
  return Object.entries(markers)
49
49
  .filter(([ sq, desc ]) => isValidSquare(sq) && desc && isValidColor(desc.color) && isValidSymbol(desc.symbol))
50
50
  .sort((a, b) => a[0].localeCompare(b[0]))
51
- .map(([ sq, desc ]) => desc.color.toUpperCase() + desc.symbol + sq)
51
+ .map(([ sq, desc ]) => desc.color.toUpperCase() + (desc.symbol.length === 1 ? desc.symbol : '(' + desc.symbol + ')') + sq)
52
52
  .join(',');
53
53
  }
54
54
 
@@ -91,12 +91,13 @@ export function parseSquareMarkers(markers) {
91
91
  /**
92
92
  * Parse a set of text markers defined as a comma-separated string into a "square -> (symbol, color)" struct.
93
93
  *
94
- * @param {string} markers For example: `'Rzd5,GAe4'`
95
- * @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
94
+ * @param {string} markers For example: `'Rzd5,GAe4,Y(plus)h3'`
95
+ * @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
96
96
  */
97
97
  export function parseTextMarkers(markers) {
98
98
  return parseMarkers(markers, token => {
99
- return /^([GRY])([A-Za-z0-9])([a-h][1-8])$/.test(token) ? { key: RegExp.$3, value: { symbol: RegExp.$2, color: RegExp.$1.toLowerCase() } } : undefined;
99
+ return /^([GRY])(?:([A-Za-z0-9])|\((plus|times|dot|circle)\))([a-h][1-8])$/.test(token) ?
100
+ { key: RegExp.$4, value: { symbol: RegExp.$2 || RegExp.$3, color: RegExp.$1.toLowerCase() } } : undefined;
100
101
  });
101
102
  }
102
103
 
package/test/1_markers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -65,6 +65,13 @@ describe('Flatten text markers', () => {
65
65
  h7: { symbol: 'x', color: 'r' },
66
66
  d2: { symbol: 'L', color: 'r' },
67
67
  })).is('G2a1,YMc5,RLd2,Rxh7,Ywh8'); });
68
+ it('Multi-character symbols', () => { test.value(flattenTextMarkers({
69
+ a1: { symbol: 'A', color: 'y' },
70
+ a7: { symbol: 'plus', color: 'g' },
71
+ b3: { symbol: 'times', color: 'r' },
72
+ g5: { symbol: 'dot', color: 'y' },
73
+ h3: { symbol: 'circle', color: 'g' },
74
+ })).is('YAa1,G(plus)a7,R(times)b3,Y(dot)g5,G(circle)h3'); });
68
75
  it('<empty>', () => { test.value(flattenTextMarkers({})).is(''); });
69
76
 
70
77
  it('Wrong square', () => { test.value(flattenTextMarkers({
@@ -83,6 +90,10 @@ describe('Flatten text markers', () => {
83
90
  d8: { symbol: '-', color: 'r' },
84
91
  c1: { symbol: 'abcd', color: 'r' },
85
92
  })).is('G0a2'); });
93
+ it('Wrong multi-character symbol', () => { test.value(flattenTextMarkers({
94
+ a2: { symbol: '0', color: 'g' },
95
+ b5: { symbol: 'whatever', color: 'r' },
96
+ })).is('G0a2'); });
86
97
  });
87
98
 
88
99
 
@@ -100,6 +111,13 @@ describe('Parse text markers', () => {
100
111
  h7: { symbol: 'x', color: 'r' },
101
112
  d2: { symbol: 'L', color: 'r' },
102
113
  }); });
114
+ it('Multi-character symbols', () => { test.value(parseTextMarkers('YAa1,G(plus)a7, R(times)b3 ,Y(dot)g5,G(circle)h3')).is({
115
+ a1: { symbol: 'A', color: 'y' },
116
+ a7: { symbol: 'plus', color: 'g' },
117
+ b3: { symbol: 'times', color: 'r' },
118
+ g5: { symbol: 'dot', color: 'y' },
119
+ h3: { symbol: 'circle', color: 'g' },
120
+ }); });
103
121
  it('<empty>', () => { test.value(parseTextMarkers('')).is({}); });
104
122
  it('<blank>', () => { test.value(parseTextMarkers(' ')).is({}); });
105
123
 
@@ -107,6 +125,7 @@ describe('Parse text markers', () => {
107
125
  it('Duplicated square', () => { test.value(parseTextMarkers('Rka3,Gba3')).is({ a3: { symbol: 'b', color: 'g' } }); });
108
126
  it('Wrong color', () => { test.value(parseTextMarkers('G3a6,BAg5')).is({ a6: { symbol: '3', color: 'g' } }); });
109
127
  it('Wrong symbol', () => { test.value(parseTextMarkers('Rb2,RAg5,G.d3,Yabcde7')).is({ g5: { symbol: 'A', color: 'r' } }); });
128
+ it('Wrong multi-character symbol', () => { test.value(parseTextMarkers('RZb2,Y(whatever)e4')).is({ b2: { symbol: 'Z', color: 'r' } }); });
110
129
  it('Wrong format', () => { test.value(parseTextMarkers('Something RHa2 invalid, Yqe4, G g3')).is({ e4: { symbol: 'q', color: 'y' } }); });
111
130
  });
112
131
 
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -36,5 +36,5 @@ describe('Marker icons graphic', function() {
36
36
  });
37
37
 
38
38
  itChecksScreenshots(browserContext, '01_marker_icons', [ 'default square', 'colorized square', 'wrapped square', 'default text', 'colorized text', 'wrapped text',
39
- 'default arrow', 'colorized arrow', 'wrapped arrow' ]);
39
+ 'default arrow', 'colorized arrow', 'wrapped arrow', 'colorized symbol', 'wrapped symbol' ]);
40
40
  });
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *