kokopu-react 1.6.0 → 1.7.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 (102) hide show
  1. package/.nycrc.yml +1 -1
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +2 -2
  4. package/dist/lib/Chessboard.js +21 -13
  5. package/dist/lib/impl/colorsets.js +44 -44
  6. package/dist/lib/impl/util.js +1 -1
  7. package/dist/lib/markers.js +7 -7
  8. package/doc_src/demo/PageChessboardInteraction.js +4 -3
  9. package/doc_src/demo/PageChessboardMove.js +36 -5
  10. package/doc_src/demo/demo.css +4 -0
  11. package/{graphic_test_app → graphic_test_src}/01_marker_icons.js +0 -0
  12. package/{graphic_test_app → graphic_test_src}/02_chessboard_simple.js +0 -0
  13. package/{graphic_test_app → graphic_test_src}/03_chessboard_flipped.js +0 -0
  14. package/{graphic_test_app → graphic_test_src}/04_chessboard_annotations.js +8 -8
  15. package/{graphic_test_app → graphic_test_src}/05_chessboard_move.js +4 -4
  16. package/{graphic_test_app → graphic_test_src}/06_chessboard_theme.js +2 -2
  17. package/{graphic_test_app → graphic_test_src}/07_chessboard_click_squares.js +0 -0
  18. package/{graphic_test_app → graphic_test_src}/08_chessboard_move_pieces.js +1 -1
  19. package/{graphic_test_app → graphic_test_src}/09_chessboard_edit_arrows.js +0 -0
  20. package/{graphic_test_app → graphic_test_src}/10_chessboard_play_moves.js +1 -1
  21. package/{graphic_test_app → graphic_test_src}/11_chessboard_play_promotions.js +0 -0
  22. package/{graphic_test_app → graphic_test_src}/12_movetext_simple.js +0 -0
  23. package/{graphic_test_app → graphic_test_src}/13_movetext_error.js +0 -0
  24. package/{graphic_test_app → graphic_test_src}/14_movetext_html.js +0 -0
  25. package/{graphic_test_app → graphic_test_src}/15_movetext_options.js +0 -4
  26. package/{graphic_test_app → graphic_test_src}/16_movetext_interaction.js +0 -0
  27. package/{graphic_test_app → graphic_test_src}/common/dummy.pgn +0 -0
  28. package/{graphic_test_app → graphic_test_src}/common/games.pgn +0 -0
  29. package/{graphic_test_app → graphic_test_src}/common/heartbeat.txt +0 -0
  30. package/{graphic_test_app → graphic_test_src}/common/smiley.png +0 -0
  31. package/{graphic_test_app → graphic_test_src}/common/test_app.css +0 -0
  32. package/{graphic_test_app → graphic_test_src}/common/test_app.js +3 -2
  33. package/graphics/chess_sprites/cburnett/bb.svg +45 -0
  34. package/graphics/chess_sprites/cburnett/bk.svg +47 -0
  35. package/graphics/chess_sprites/cburnett/bn.svg +37 -0
  36. package/graphics/chess_sprites/cburnett/bp.svg +19 -0
  37. package/graphics/chess_sprites/cburnett/bq.svg +58 -0
  38. package/graphics/chess_sprites/cburnett/br.svg +60 -0
  39. package/graphics/chess_sprites/cburnett/bx.svg +56 -0
  40. package/graphics/chess_sprites/cburnett/wb.svg +48 -0
  41. package/graphics/chess_sprites/cburnett/wk.svg +26 -0
  42. package/graphics/chess_sprites/cburnett/wn.svg +37 -0
  43. package/graphics/chess_sprites/cburnett/wp.svg +19 -0
  44. package/graphics/chess_sprites/cburnett/wq.svg +60 -0
  45. package/graphics/chess_sprites/cburnett/wr.svg +44 -0
  46. package/graphics/chess_sprites/cburnett/wx.svg +56 -0
  47. package/graphics/chess_sprites/generate_sprites.sh +135 -0
  48. package/graphics/chess_sprites/mmonge/celtic-bx.svg +112 -0
  49. package/graphics/chess_sprites/mmonge/celtic-wx.svg +111 -0
  50. package/graphics/chess_sprites/mmonge/celtic.svg +1576 -0
  51. package/graphics/chess_sprites/mmonge/eyes-spatial-bx.svg +101 -0
  52. package/graphics/chess_sprites/mmonge/eyes-spatial-wx.svg +100 -0
  53. package/graphics/chess_sprites/mmonge/eyes.svg +2538 -0
  54. package/graphics/chess_sprites/mmonge/fantasy-bx.svg +112 -0
  55. package/graphics/chess_sprites/mmonge/fantasy-wx.svg +111 -0
  56. package/graphics/chess_sprites/mmonge/fantasy.svg +5497 -0
  57. package/graphics/chess_sprites/mmonge/fantasy_alt.svg +3742 -0
  58. package/graphics/chess_sprites/mmonge/freak.svg +3479 -0
  59. package/graphics/chess_sprites/mmonge/prmi.svg +6776 -0
  60. package/graphics/chess_sprites/mmonge/skulls-bx.svg +124 -0
  61. package/graphics/chess_sprites/mmonge/skulls-wx.svg +111 -0
  62. package/graphics/chess_sprites/mmonge/skulls.svg +12978 -0
  63. package/graphics/chess_sprites/mmonge/spatial.svg +1223 -0
  64. package/package.json +21 -19
  65. package/scripts/{test_graphic/clean-graphic-output.js → clean-graphic-output.js} +1 -1
  66. package/scripts/{test_graphic/docker-compose.yml → docker-compose.yml} +3 -3
  67. package/scripts/{test_graphic/webpack-config.js → test-graphic.webpack.config.js} +7 -6
  68. package/scripts/{test_headless.webpack-config.js → test-headless.webpack.config.js} +2 -1
  69. package/src/Chessboard.js +21 -13
  70. package/src/impl/colorsets.js +44 -44
  71. package/src/impl/util.js +1 -1
  72. package/src/markers.js +7 -7
  73. package/test/1_markers.js +14 -14
  74. package/test/common/graphic.js +2 -2
  75. package/test/references/04_chessboard_annotations/0.png +0 -0
  76. package/test/references/04_chessboard_annotations/1.png +0 -0
  77. package/test/references/04_chessboard_annotations/2.png +0 -0
  78. package/test/references/04_chessboard_annotations/3.png +0 -0
  79. package/test/references/04_chessboard_annotations/4.png +0 -0
  80. package/test/references/04_chessboard_annotations/5.png +0 -0
  81. package/test/references/05_chessboard_move/4.png +0 -0
  82. package/test/references/05_chessboard_move/5.png +0 -0
  83. package/test/references/05_chessboard_move/6.png +0 -0
  84. package/test/references/06_chessboard_theme/0.png +0 -0
  85. package/test/references/06_chessboard_theme/1.png +0 -0
  86. package/test/references/06_chessboard_theme/2.png +0 -0
  87. package/test/references/06_chessboard_theme/3.png +0 -0
  88. package/test/references/06_chessboard_theme/4.png +0 -0
  89. package/test/references/06_chessboard_theme/5.png +0 -0
  90. package/test/references/06_chessboard_theme/6.png +0 -0
  91. package/test/references/06_chessboard_theme/7.png +0 -0
  92. package/test/references/06_chessboard_theme/8.png +0 -0
  93. package/test/references/08_chessboard_move_pieces/over_arrow_marker.png +0 -0
  94. package/test/references/08_chessboard_move_pieces/over_square_marker.png +0 -0
  95. package/test/references/08_chessboard_move_pieces/over_text_marker.png +0 -0
  96. package/test/references/09_chessboard_edit_arrows/base_1.png +0 -0
  97. package/test/references/09_chessboard_edit_arrows/base_2.png +0 -0
  98. package/test/references/09_chessboard_edit_arrows/null_vector.png +0 -0
  99. package/test/references/09_chessboard_edit_arrows/over_arrow_marker.png +0 -0
  100. package/test/references/09_chessboard_edit_arrows/over_square_marker.png +0 -0
  101. package/test/references/10_chessboard_play_moves/castling_move.png +0 -0
  102. package/test/references/10_chessboard_play_moves/regular_move_2.png +0 -0
package/.nycrc.yml CHANGED
@@ -9,5 +9,5 @@ check-coverage: true
9
9
 
10
10
  exclude:
11
11
  - build/**
12
- - graphic_test_app/**
12
+ - graphic_test_src/**
13
13
  - test/**
package/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  ChangeLog
2
2
  =========
3
3
 
4
+ 1.7.0 (June 22, 2022)
5
+ ---------------------
6
+ * Upgrade React to React 18.
7
+ * Add support for color blue for markers.
8
+ * Allow customization of the move arrow color in the `Chessboard` component.
9
+ * Change the property names used to define the marker colors in the objects returned by `Chessboard.colorsets()`:
10
+ `g`, `r`, `y` and `highlight` have become respectively `cg`, `cr`, `cy` and `cb`.
11
+
4
12
  1.6.0 (June 1, 2022)
5
13
  --------------------
6
14
  * Allow block-formatting HTML tags in PGN comments.
package/README.md CHANGED
@@ -27,10 +27,10 @@ Example
27
27
 
28
28
  ```javascript
29
29
  import React from 'react';
30
- import ReactDOM from 'react-dom';
30
+ import { createRoot } from 'react-dom/client';
31
31
  import { Chessboard } from 'kokopu-react';
32
32
 
33
- ReactDOM.render(<Chessboard />, document.body);
33
+ createRoot(document.body).render(<Chessboard />);
34
34
  ```
35
35
 
36
36
  ![Chessboard component](test/references/02_chessboard_simple/0.png)
@@ -188,7 +188,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
188
188
  viewBox: viewBox,
189
189
  width: xmax - xmin,
190
190
  height: ymax - ymin
191
- }, /*#__PURE__*/_react["default"].createElement("defs", null, this.renderArrowTip(colorset, 'g'), this.renderArrowTip(colorset, 'r'), this.renderArrowTip(colorset, 'y'), this.renderArrowTip(colorset, 'highlight')), squares, rankCoordinates, fileCoordinates, this.renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset));
191
+ }, /*#__PURE__*/_react["default"].createElement("defs", null, this.renderArrowTip(colorset, 'b'), this.renderArrowTip(colorset, 'g'), this.renderArrowTip(colorset, 'r'), this.renderArrowTip(colorset, 'y')), squares, rankCoordinates, fileCoordinates, this.renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset));
192
192
  }
193
193
  }, {
194
194
  key: "renderBoardContent",
@@ -286,13 +286,14 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
286
286
 
287
287
  var thickness = Math.max(2, Math.round(HOVER_MARKER_THICKNESS_FACTOR * squareSize));
288
288
  var size = squareSize - thickness;
289
+ var color = this.props.interactionMode === 'editArrows' ? this.props.editedArrowColor : this.props.moveArrowColor;
289
290
  return /*#__PURE__*/_react["default"].createElement("rect", {
290
291
  className: "kokopu-hoveredSquare",
291
292
  x: x + thickness / 2,
292
293
  y: y + thickness / 2,
293
294
  width: size,
294
295
  height: size,
295
- stroke: colorset.highlight,
296
+ stroke: colorset['c' + color],
296
297
  strokeWidth: thickness
297
298
  });
298
299
  }
@@ -407,7 +408,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
407
408
  y1: yFrom,
408
409
  x2: xTo,
409
410
  y2: yTo,
410
- stroke: colorset[this.props.editedArrowColor],
411
+ stroke: colorset['c' + this.props.editedArrowColor],
411
412
  strokeWidth: strokeWidth,
412
413
  markerEnd: "url(#".concat(arrowTipId, ")")
413
414
  });
@@ -543,7 +544,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
543
544
  y: y,
544
545
  width: squareSize,
545
546
  height: squareSize,
546
- fill: colorset[color]
547
+ fill: colorset['c' + color]
547
548
  }));
548
549
  });
549
550
  return result;
@@ -573,7 +574,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
573
574
  y: y,
574
575
  size: squareSize,
575
576
  symbol: value.symbol,
576
- color: colorset[value.color]
577
+ color: colorset['c' + value.color]
577
578
  })));
578
579
  });
579
580
  return result;
@@ -621,7 +622,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
621
622
  y1: yFrom,
622
623
  x2: xTo,
623
624
  y2: yTo,
624
- stroke: colorset[color],
625
+ stroke: colorset['c' + color],
625
626
  strokeWidth: strokeWidth,
626
627
  markerEnd: "url(#".concat(arrowTipId, ")")
627
628
  }));
@@ -652,15 +653,16 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
652
653
  yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
653
654
  var x = xTo * alpha + xFrom * (1 - alpha);
654
655
  var y = yTo * alpha + yFrom * (1 - alpha);
656
+ var color = this.props.moveArrowColor;
655
657
  return /*#__PURE__*/_react["default"].createElement("line", {
656
658
  className: "kokopu-annotation kokopu-arrow",
657
659
  x1: xFrom,
658
660
  y1: yFrom,
659
661
  x2: x,
660
662
  y2: y,
661
- stroke: colorset['highlight'],
663
+ stroke: colorset['c' + color],
662
664
  strokeWidth: squareSize * STROKE_THICKNESS_FACTOR,
663
- markerEnd: "url(#".concat(this.getArrowTipId('highlight'), ")")
665
+ markerEnd: "url(#".concat(this.getArrowTipId(color), ")")
664
666
  });
665
667
  }
666
668
  }, {
@@ -668,7 +670,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
668
670
  value: function renderArrowTip(colorset, color) {
669
671
  return /*#__PURE__*/_react["default"].createElement(_ArrowTip["default"], {
670
672
  id: this.getArrowTipId(color),
671
- color: colorset[color]
673
+ color: colorset['c' + color]
672
674
  });
673
675
  }
674
676
  }, {
@@ -1114,7 +1116,7 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
1114
1116
  /**
1115
1117
  * Available colorsets for theming.
1116
1118
  *
1117
- * @returns {Object.<string, {w: string, b: string, g: string, r: string, y: string, highlight: string}>}
1119
+ * @returns {Object.<string, { w: string, b: string, cb: string, cg: string, cr: string, cy: string }>}
1118
1120
  * @public
1119
1121
  */
1120
1122
 
@@ -1126,8 +1128,8 @@ var Chessboard = /*#__PURE__*/function (_React$Component) {
1126
1128
  /**
1127
1129
  * Available piecesets for theming.
1128
1130
  *
1129
- * @returns {Object.<string, {bb: string, bk: string, bn: string, bp: string, bq: string, br: string, bx: string,
1130
- * wb: string, wk: string, wn: string, wp: string, wq: string, wr: string, wx: string}>}
1131
+ * @returns {Object.<string, { bb: string, bk: string, bn: string, bp: string, bq: string, br: string, bx: string,
1132
+ * wb: string, wk: string, wn: string, wp: string, wq: string, wr: string, wx: string }>}
1131
1133
  * @public
1132
1134
  */
1133
1135
 
@@ -1205,6 +1207,11 @@ Chessboard.propTypes = {
1205
1207
  */
1206
1208
  moveArrowVisible: _propTypes["default"].bool,
1207
1209
 
1210
+ /**
1211
+ * Color of the move arrow.
1212
+ */
1213
+ moveArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
1214
+
1208
1215
  /**
1209
1216
  * Whether moves are animated or not.
1210
1217
  */
@@ -1252,7 +1259,7 @@ Chessboard.propTypes = {
1252
1259
  /**
1253
1260
  * Color of the edited arrow (only used if `interactionMode` is set to `'editArrows'`).
1254
1261
  */
1255
- editedArrowColor: _propTypes["default"].oneOf(['g', 'r', 'y']),
1262
+ editedArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
1256
1263
 
1257
1264
  /**
1258
1265
  * Callback invoked when a piece is moved through drag&drop (only if `interactionMode` is set to `'movePieces'`).
@@ -1290,6 +1297,7 @@ Chessboard.defaultProps = {
1290
1297
  squareSize: 40,
1291
1298
  coordinateVisible: true,
1292
1299
  moveArrowVisible: true,
1300
+ moveArrowColor: 'b',
1293
1301
  animated: false,
1294
1302
  colorset: 'original',
1295
1303
  pieceset: 'cburnett'
@@ -29,42 +29,42 @@ var _default = {
29
29
  original: {
30
30
  b: '#b5876b',
31
31
  w: '#f0dec7',
32
- g: '#0e0',
33
- r: '#d00',
34
- y: '#db0',
35
- highlight: '#04f'
32
+ cb: '#04f',
33
+ cg: '#0e0',
34
+ cr: '#d00',
35
+ cy: '#db0'
36
36
  },
37
37
  gray: {
38
38
  b: '#bbbbbb',
39
39
  w: '#f8f8f8',
40
- g: '#0a0',
41
- r: '#d00',
42
- y: '#a90',
43
- highlight: '#04f'
40
+ cb: '#04f',
41
+ cg: '#0a0',
42
+ cr: '#d00',
43
+ cy: '#a90'
44
44
  },
45
45
  scid: {
46
46
  b: '#7389b6',
47
47
  w: '#f3f3f3',
48
- g: '#0e0',
49
- r: '#d00',
50
- y: '#db0',
51
- highlight: '#04f'
48
+ cb: '#04f',
49
+ cg: '#0e0',
50
+ cr: '#d00',
51
+ cy: '#db0'
52
52
  },
53
53
  wikipedia: {
54
54
  b: '#d18b47',
55
55
  w: '#ffce9e',
56
- g: '#0e0',
57
- r: '#d00',
58
- y: '#db0',
59
- highlight: '#04f'
56
+ cb: '#04f',
57
+ cg: '#0e0',
58
+ cr: '#d00',
59
+ cy: '#db0'
60
60
  },
61
61
  xboard: {
62
62
  b: '#77a26d',
63
63
  w: '#c8c365',
64
- g: '#0f0',
65
- r: '#d00',
66
- y: '#ff0',
67
- highlight: '#04f'
64
+ cb: '#04f',
65
+ cg: '#0f0',
66
+ cr: '#d00',
67
+ cy: '#ff0'
68
68
  },
69
69
 
70
70
  /*
@@ -74,50 +74,50 @@ var _default = {
74
74
  coral: {
75
75
  b: 'rgb(112,162,163)',
76
76
  w: 'rgb(177,228,185)',
77
- g: '#080',
78
- r: '#d00',
79
- y: '#ff0',
80
- highlight: '#04f'
77
+ cb: '#04f',
78
+ cg: '#080',
79
+ cr: '#d00',
80
+ cy: '#ff0'
81
81
  },
82
82
  dusk: {
83
83
  b: 'rgb(112,102,119)',
84
84
  w: 'rgb(204,183,174)',
85
- g: '#3f3',
86
- r: '#f20',
87
- y: '#ff0',
88
- highlight: '#04f'
85
+ cb: '#04f',
86
+ cg: '#3f3',
87
+ cr: '#f20',
88
+ cy: '#ff0'
89
89
  },
90
90
  emerald: {
91
91
  b: 'rgb(111,143,114)',
92
92
  w: 'rgb(173,189,143)',
93
- g: '#6f6',
94
- r: '#d00',
95
- y: '#ff0',
96
- highlight: '#04f'
93
+ cb: '#04f',
94
+ cg: '#6f6',
95
+ cr: '#d00',
96
+ cy: '#ff0'
97
97
  },
98
98
  marine: {
99
99
  b: 'rgb(111,115,210)',
100
100
  w: 'rgb(157,172,255)',
101
- g: '#6f6',
102
- r: '#f50',
103
- y: '#ff0',
104
- highlight: '#04f'
101
+ cb: '#04f',
102
+ cg: '#6f6',
103
+ cr: '#f50',
104
+ cy: '#ff0'
105
105
  },
106
106
  sandcastle: {
107
107
  b: 'rgb(184,139,74)',
108
108
  w: 'rgb(227,193,111)',
109
- g: '#0c3',
110
- r: '#d02',
111
- y: '#ff0',
112
- highlight: '#04f'
109
+ cb: '#04f',
110
+ cg: '#0c3',
111
+ cr: '#d02',
112
+ cy: '#ff0'
113
113
  },
114
114
  wheat: {
115
115
  b: 'rgb(187,190,100)',
116
116
  w: 'rgb(234,240,206)',
117
- g: '#0c3',
118
- r: '#d00',
119
- y: '#ff3',
120
- highlight: '#04f'
117
+ cb: '#04f',
118
+ cg: '#0c3',
119
+ cr: '#d00',
120
+ cy: '#ff3'
121
121
  }
122
122
  };
123
123
  exports["default"] = _default;
@@ -61,7 +61,7 @@ function isValidVector(vect) {
61
61
  }
62
62
 
63
63
  function isValidColor(color) {
64
- return color === 'g' || color === 'r' || color === 'y';
64
+ return color === 'b' || color === 'g' || color === 'r' || color === 'y';
65
65
  }
66
66
 
67
67
  function isValidSymbol(symbol) {
@@ -75,8 +75,8 @@ function flattenTextMarkers(markers) {
75
75
  /**
76
76
  * Transform a set of arrow markers defined as a "squareFromSquareTo -> color" struct into a comma-separated string.
77
77
  *
78
- * @param {object} markers For example: `{ e2e4: 'g', g8f6: 'r', g8h6: 'y' }`
79
- * @returns {string} For example: `'Ge2e4,Rg8f6,Yg8h6'`
78
+ * @param {object} markers For example: `{ e2e4: 'g', g8f6: 'r', g8h6: 'b' }`
79
+ * @returns {string} For example: `'Ge2e4,Rg8f6,Bg8h6'`
80
80
  */
81
81
 
82
82
 
@@ -121,7 +121,7 @@ function parseMarkers(markers, tokenParser) {
121
121
 
122
122
  function parseSquareMarkers(markers) {
123
123
  return parseMarkers(markers, function (token) {
124
- return /^([GRY])([a-h][1-8])$/.test(token) ? {
124
+ return /^([BGRY])([a-h][1-8])$/.test(token) ? {
125
125
  key: RegExp.$2,
126
126
  value: RegExp.$1.toLowerCase()
127
127
  } : undefined;
@@ -137,7 +137,7 @@ function parseSquareMarkers(markers) {
137
137
 
138
138
  function parseTextMarkers(markers) {
139
139
  return parseMarkers(markers, function (token) {
140
- return /^([GRY])(?:([A-Za-z0-9])|\((plus|times|dot|circle)\))([a-h][1-8])$/.test(token) ? {
140
+ return /^([BGRY])(?:([A-Za-z0-9])|\((plus|times|dot|circle)\))([a-h][1-8])$/.test(token) ? {
141
141
  key: RegExp.$4,
142
142
  value: {
143
143
  symbol: RegExp.$2 || RegExp.$3,
@@ -149,14 +149,14 @@ function parseTextMarkers(markers) {
149
149
  /**
150
150
  * Parse a set of arrow markers defined as a comma-separated string into a "squareFromSquareTo -> color" struct.
151
151
  *
152
- * @param {string} markers For example: `'Ge2e4,Rg8f6,Yg8h6'`
153
- * @returns {object} For example: `{ e2e4: 'g', g8f6: 'r', g8h6: 'y' }`
152
+ * @param {string} markers For example: `'Ge2e4,Rg8f6,Bg8h6'`
153
+ * @returns {object} For example: `{ e2e4: 'g', g8f6: 'r', g8h6: 'b' }`
154
154
  */
155
155
 
156
156
 
157
157
  function parseArrowMarkers(markers) {
158
158
  return parseMarkers(markers, function (token) {
159
- return /^([GRY])([a-h][1-8][a-h][1-8])$/.test(token) ? {
159
+ return /^([BGRY])([a-h][1-8][a-h][1-8])$/.test(token) ? {
160
160
  key: RegExp.$2,
161
161
  value: RegExp.$1.toLowerCase()
162
162
  } : undefined;
@@ -165,9 +165,10 @@ export default class Page extends React.Component {
165
165
  let colorset = Chessboard.colorsets()['original'];
166
166
  return (
167
167
  <ToggleButtonGroup value={this.state[attributeName]} exclusive size="small" onChange={(_, newColor) => this.setIfNonNull(attributeName, newColor)}>
168
- <ToggleButton className="kokopu-fixTextTransform" value="g">{this.renderColorButtonLabel(colorset.g)}</ToggleButton>
169
- <ToggleButton className="kokopu-fixTextTransform" value="r">{this.renderColorButtonLabel(colorset.r)}</ToggleButton>
170
- <ToggleButton className="kokopu-fixTextTransform" value="y">{this.renderColorButtonLabel(colorset.y)}</ToggleButton>
168
+ <ToggleButton className="kokopu-fixTextTransform" value="b">{this.renderColorButtonLabel(colorset.cb)}</ToggleButton>
169
+ <ToggleButton className="kokopu-fixTextTransform" value="g">{this.renderColorButtonLabel(colorset.cg)}</ToggleButton>
170
+ <ToggleButton className="kokopu-fixTextTransform" value="r">{this.renderColorButtonLabel(colorset.cr)}</ToggleButton>
171
+ <ToggleButton className="kokopu-fixTextTransform" value="y">{this.renderColorButtonLabel(colorset.cy)}</ToggleButton>
171
172
  </ToggleButtonGroup>
172
173
  );
173
174
  }
@@ -23,7 +23,7 @@
23
23
  import React from 'react';
24
24
  import kokopu from 'kokopu';
25
25
 
26
- import { Chessboard } from '../../src/index';
26
+ import { Chessboard, ArrowMarkerIcon } from '../../src/index';
27
27
  import { buildComponentDemoCode } from './util';
28
28
 
29
29
  import Box from '@mui/material/Box';
@@ -33,9 +33,13 @@ import FormControlLabel from '@mui/material/FormControlLabel';
33
33
  import Stack from '@mui/material/Stack';
34
34
  import Switch from '@mui/material/Switch';
35
35
  import TextField from '@mui/material/TextField';
36
+ import ToggleButton from '@mui/material/ToggleButton';
37
+ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
36
38
 
37
39
  import './demo.css';
38
40
 
41
+ const COLOR_ICON_SIZE = 16;
42
+
39
43
 
40
44
  export default class Page extends React.Component {
41
45
 
@@ -49,6 +53,7 @@ export default class Page extends React.Component {
49
53
  positionAfter: positionAfter, // non-null only if a valid move has been played
50
54
  flipped: false,
51
55
  moveArrowVisible: true,
56
+ moveArrowColor: 'b',
52
57
  animated: true,
53
58
  editedMove: 'Nf6',
54
59
  playedMove: 'e4',
@@ -71,12 +76,13 @@ export default class Page extends React.Component {
71
76
  <FormControlLabel label="Flip"
72
77
  control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
73
78
  />
74
- <FormControlLabel label="Show move arrow" disabled={!this.state.positionAfter}
75
- control={<Switch checked={this.state.moveArrowVisible} onChange={() => this.set('moveArrowVisible', !this.state.moveArrowVisible)} color="primary" />}
76
- />
77
79
  <FormControlLabel label="Animation" disabled={!this.state.positionAfter}
78
80
  control={<Switch checked={this.state.animated} onChange={() => this.set('animated', !this.state.animated)} color="primary" />}
79
81
  />
82
+ <FormControlLabel label="Show move arrow" disabled={!this.state.positionAfter}
83
+ control={<Switch checked={this.state.moveArrowVisible} onChange={() => this.set('moveArrowVisible', !this.state.moveArrowVisible)} color="primary" />}
84
+ />
85
+ {this.renderColorSelector()}
80
86
  </Stack>
81
87
  <Stack direction="row" spacing={2} alignItems="center">
82
88
  <TextField label="Move" variant="standard" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
@@ -89,6 +95,21 @@ export default class Page extends React.Component {
89
95
  </>);
90
96
  }
91
97
 
98
+ renderColorSelector() {
99
+ if (!this.state.moveArrowVisible) {
100
+ return undefined;
101
+ }
102
+ let colorset = Chessboard.colorsets()['original'];
103
+ return (
104
+ <ToggleButtonGroup value={this.state.moveArrowColor} exclusive size="small" disabled={!this.state.positionAfter} onChange={(_, newColor) => this.setMoveColor(newColor)}>
105
+ <ToggleButton className="kokopu-fixOpacity" value="b"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cb} /></ToggleButton>
106
+ <ToggleButton className="kokopu-fixOpacity" value="g"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cg} /></ToggleButton>
107
+ <ToggleButton className="kokopu-fixOpacity" value="r"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cr} /></ToggleButton>
108
+ <ToggleButton className="kokopu-fixOpacity" value="y"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cy} /></ToggleButton>
109
+ </ToggleButtonGroup>
110
+ );
111
+ }
112
+
92
113
  renderChessboard() {
93
114
  return (
94
115
  <Box>
@@ -97,6 +118,7 @@ export default class Page extends React.Component {
97
118
  move={this.state.playedMove}
98
119
  flipped={this.state.flipped}
99
120
  moveArrowVisible={this.state.moveArrowVisible}
121
+ moveArrowColor={this.state.moveArrowColor}
100
122
  animated={this.state.animated}
101
123
  />
102
124
  </Box>
@@ -112,8 +134,11 @@ export default class Page extends React.Component {
112
134
  if (this.state.flipped) {
113
135
  attributes.push('flipped');
114
136
  }
115
- attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
116
137
  attributes.push(`animated={${this.state.animated}}`);
138
+ attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
139
+ if (this.state.moveArrowVisible) {
140
+ attributes.push(`moveArrowColor={${this.state.moveArrowColor}}`);
141
+ }
117
142
  return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
118
143
  }
119
144
 
@@ -123,6 +148,12 @@ export default class Page extends React.Component {
123
148
  this.setState(newState);
124
149
  }
125
150
 
151
+ setMoveColor(newValue) {
152
+ if (newValue !== null) {
153
+ this.set('moveArrowColor', newValue);
154
+ }
155
+ }
156
+
126
157
  setPosition(newPosition) {
127
158
  let newState = {};
128
159
  newState.position = newPosition;
@@ -33,6 +33,10 @@
33
33
  text-transform: none;
34
34
  }
35
35
 
36
+ .MuiToggleButton-root.Mui-disabled.kokopu-fixOpacity .kokopu-arrowMarkerIcon {
37
+ opacity: 0.3;
38
+ }
39
+
36
40
  .kokopu-fixedPopup {
37
41
  position: fixed;
38
42
  bottom: 20px;
@@ -24,17 +24,17 @@ import React from 'react';
24
24
  import testApp from './common/test_app';
25
25
  import { Chessboard } from '../src/index';
26
26
 
27
- let squareMarkers1 = 'Ga1,Ga2,Rb1,Rb2,Yc1,Yc2';
28
- let arrowMarkers1 = 'Gb8c6,Re8f6,Yf8g6';
29
- let textMarkers1 = 'GAf1,Gaf2,RZg1,Rzg2,Y2h1,Y8h2';
27
+ let squareMarkers1 = 'Ba1,Ba2,Gb1,Gb2,Rc1,Rc2,Yd1,Yd2';
28
+ let arrowMarkers1 = 'Ba8b6,Gb8c6,Re8f6,Yf8g6';
29
+ let textMarkers1 = 'B(circle)e1,B(plus)e2,GAf1,Gaf2,RZg1,Rzg2,Y2h1,Y8h2';
30
30
 
31
- let squareMarkers2 = { e4: 'g', g5: 'r', g1: 'y' };
32
- let arrowMarkers2 = { c3a2: 'y', c4a4: 'g', c5a6: 'r', c6a8: 'y', d6c8: 'g', e6e8: 'r', f6g8: 'y' };
33
- let textMarkers2 = { g3: { symbol: 'H', color: 'r' }, g5: { symbol: 'M', color: 'g' } };
31
+ let squareMarkers2 = { e4: 'g', g5: 'r', g1: 'y', h4: 'b' };
32
+ let arrowMarkers2 = { c3a2: 'b', c4a4: 'g', c5a6: 'r', c6a8: 'y', d6c8: 'b', e6e8: 'g', f6g8: 'r' };
33
+ let textMarkers2 = { g3: { symbol: 'H', color: 'r' }, g5: { symbol: 'M', color: 'g' }, h4: { symbol: 'times', color: 'y' } };
34
34
 
35
- let squareMarkers3 = { b5: 'r', e4: 'g', h5: 'y' };
35
+ let squareMarkers3 = { b5: 'r', e4: 'g', h5: 'y', e2: 'b' };
36
36
  let arrowMarkers3 = { d1h5: 'g', a5f4: 'r', c7c3: 'y', g7g7: 'g' };
37
- let textMarkers3 = 'G5c6,R(plus)a1,G(times)b1,R(dot)a2,Y(circle)b2';
37
+ let textMarkers3 = 'G5c6,R(plus)a1,G(times)b1,B(dot)a2,Y(circle)b2';
38
38
 
39
39
  testApp([ /* eslint-disable react/jsx-key */
40
40
  <Chessboard squareMarkers={squareMarkers1} arrowMarkers={arrowMarkers1} textMarkers={textMarkers1} flipped={false} coordinateVisible={true} />,
@@ -33,9 +33,9 @@ testApp([ /* eslint-disable react/jsx-key */
33
33
  <Chessboard move="Nf3" moveArrowVisible={false} animated={false} />,
34
34
  <Chessboard move="Nf4" animated={false} />,
35
35
  <Chessboard position="rnbqkbnr/pppp1ppp/4p3/8/3PP3/8/PPP2PPP/RNBQKBNR b KQkq - 0 2" move="Bb4+" moveArrowVisible={true} flipped={true} animated={false} />,
36
- <Chessboard position={pos} move={move} animated={false} />,
37
- <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={false} />,
38
- <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={false} />,
39
- <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={false} />,
36
+ <Chessboard position={pos} move={move} animated={false} moveArrowColor="g" />,
37
+ <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={false} moveArrowColor="r" />,
38
+ <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={false} moveArrowColor="y" />,
39
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={false} moveArrowColor="b" />,
40
40
  <Chessboard move={42} animated={false} />,
41
41
  ]); /* eslint-enable react/jsx-key */
@@ -30,8 +30,8 @@ let mv1 = 'Ba5';
30
30
  let pos2 = 'start';
31
31
  let mv2 = 'e4';
32
32
 
33
- let sm = 'Ga8,Ga7,Rb8,Rb7,Yc8,Yc7';
34
- let am = 'Gb1b3,Rc1c3,Yd1d3';
33
+ let sm = 'Ba8,Ba7,Gb8,Gb7,Rc8,Rc7,Yd8,Yd7';
34
+ let am = 'Ba1a3,Gb1b3,Rc1c3,Yd1d3';
35
35
 
36
36
  testApp([ /* eslint-disable react/jsx-key */
37
37
  <Chessboard position={pos1} move={mv1} squareMarkers={sm} arrowMarkers={am} animated={false} />,
@@ -31,6 +31,6 @@ function onPieceMoved(from, to) {
31
31
  testApp([ /* eslint-disable react/jsx-key */
32
32
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} />,
33
33
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} flipped
34
- squareMarkers="Gc4" textMarkers="RAh3" arrowMarkers="Gc8a4" />,
34
+ squareMarkers="Gc4" textMarkers="BAh3" arrowMarkers="Gc8a4" moveArrowColor="r" />,
35
35
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} move="e4" animated={false} />,
36
36
  ]); /* eslint-enable react/jsx-key */
@@ -31,7 +31,7 @@ function onMovePlayed(move) {
31
31
  testApp([ /* eslint-disable react/jsx-key */
32
32
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed} />,
33
33
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
34
- flipped position="rnbqk2r/ppp2ppp/3p1n2/2b1p3/4P3/2NP1N2/PPP2PPP/R1BQKB1R w KQkq - 0 1" move="Bg5" animated={false} />,
34
+ flipped position="rnbqk2r/ppp2ppp/3p1n2/2b1p3/4P3/2NP1N2/PPP2PPP/R1BQKB1R w KQkq - 0 1" move="Bg5" animated={false} moveArrowColor="g" />,
35
35
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
36
36
  position="rnbq1bnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1" />,
37
37
  <Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
@@ -26,8 +26,6 @@ import { Movetext, i18n } from '../src/index';
26
26
 
27
27
  import pgn from './common/games.pgn';
28
28
 
29
- let legacyPieceSymbols = i18n.PIECE_SYMBOLS;
30
-
31
29
  // Localization for French
32
30
  i18n.PIECE_SYMBOLS = { K: 'R', Q: 'D', R: 'T', B: 'F', N: 'C', P: 'P' };
33
31
 
@@ -38,5 +36,3 @@ testApp([ /* eslint-disable react/jsx-key */
38
36
  diagramOptions={{ flipped: true, coordinateVisible: false, squareSize: 32, colorset: 'scid', pieceset: 'eyes' }} />,
39
37
  <Movetext game={pgn} gameIndex={9} diagramVisible={false} />,
40
38
  ], 'width-600'); /* eslint-enable react/jsx-key */
41
-
42
- i18n.PIECE_SYMBOLS = legacyPieceSymbols;
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import ReactDOM from 'react-dom';
24
+ import { createRoot } from 'react-dom/client';
25
25
  import './test_app.css';
26
26
 
27
27
 
@@ -45,8 +45,9 @@ export default function(elements, containerClassName) {
45
45
  document.body.appendChild(anchor);
46
46
 
47
47
  // Render the content.
48
+ let root = createRoot(anchor);
48
49
  let content = flattenMultiElements(elements, containerClassName);
49
- ReactDOM.render(content, anchor);
50
+ root.render(content);
50
51
 
51
52
  // Append a text area
52
53
  let sandbox = document.createElement('pre');