kokopu-react 1.8.0 → 1.9.1

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 (158) hide show
  1. package/dist/lib/ArrowMarkerIcon.js +1 -29
  2. package/dist/lib/Chessboard.js +152 -298
  3. package/dist/lib/ErrorBox.js +7 -24
  4. package/dist/lib/Movetext.js +74 -178
  5. package/dist/lib/SquareMarkerIcon.js +2 -10
  6. package/dist/lib/TextMarkerIcon.js +0 -11
  7. package/dist/lib/css/movetext.css +4 -0
  8. package/dist/lib/formatmove.js +2 -14
  9. package/dist/lib/i18n.js +1 -1
  10. package/dist/lib/impl/ArrowTip.js +2 -8
  11. package/dist/lib/impl/HtmlSanitizer.js +13 -46
  12. package/dist/lib/impl/Motion.js +107 -0
  13. package/dist/lib/impl/TextSymbol.js +2 -11
  14. package/dist/lib/impl/colorsets.js +0 -2
  15. package/dist/lib/impl/piecesets.js +0 -87
  16. package/dist/lib/impl/util.js +1 -11
  17. package/dist/lib/index.js +0 -10
  18. package/dist/lib/markers.js +18 -38
  19. package/graphic_test_src/05_chessboard_move.js +2 -2
  20. package/graphic_test_src/06a_chessboard_animated_move.js +36 -0
  21. package/graphic_test_src/06b_chessboard_animated_move.js +36 -0
  22. package/graphic_test_src/06c_chessboard_animated_move.js +36 -0
  23. package/graphic_test_src/{06_chessboard_theme.js → 07_chessboard_theme.js} +0 -0
  24. package/graphic_test_src/{07_chessboard_click_squares.js → 08_chessboard_click_squares.js} +0 -0
  25. package/graphic_test_src/{08_chessboard_move_pieces.js → 09_chessboard_move_pieces.js} +0 -0
  26. package/graphic_test_src/{09_chessboard_edit_arrows.js → 10_chessboard_edit_arrows.js} +0 -0
  27. package/graphic_test_src/{10_chessboard_play_moves.js → 11_chessboard_play_moves.js} +0 -0
  28. package/graphic_test_src/{11_chessboard_play_promotions.js → 12_chessboard_play_promotions.js} +0 -0
  29. package/graphic_test_src/{12_movetext_simple.js → 13_movetext_simple.js} +0 -0
  30. package/graphic_test_src/{13_movetext_error.js → 14_movetext_error.js} +0 -0
  31. package/graphic_test_src/{14_movetext_html.js → 15_movetext_html.js} +0 -0
  32. package/graphic_test_src/{15_movetext_options.js → 16_movetext_options.js} +0 -0
  33. package/graphic_test_src/{16_movetext_interaction.js → 17_movetext_interaction.js} +0 -0
  34. package/package.json +19 -21
  35. package/scripts/docker-compose.yml +1 -1
  36. package/src/Chessboard.js +24 -20
  37. package/src/css/movetext.css +4 -0
  38. package/src/impl/ArrowTip.js +2 -2
  39. package/src/impl/Motion.js +99 -0
  40. package/test/4_chessboard_graphic.js +4 -1
  41. package/test/5_chessboard_interaction.js +5 -5
  42. package/test/6_chessboard_play_moves.js +4 -4
  43. package/test/7_movetext_graphic.js +4 -4
  44. package/test/8_movetext_interaction.js +2 -2
  45. package/test/common/graphic.js +6 -0
  46. package/test/references/06a_chessboard_animated_move/0.png +0 -0
  47. package/test/references/06a_chessboard_animated_move/1.png +0 -0
  48. package/test/references/06a_chessboard_animated_move/2.png +0 -0
  49. package/test/references/06a_chessboard_animated_move/3.png +0 -0
  50. package/test/references/06a_chessboard_animated_move/4.png +0 -0
  51. package/test/references/06a_chessboard_animated_move/5.png +0 -0
  52. package/test/references/06b_chessboard_animated_move/0.png +0 -0
  53. package/test/references/06b_chessboard_animated_move/1.png +0 -0
  54. package/test/references/06b_chessboard_animated_move/2.png +0 -0
  55. package/test/references/06b_chessboard_animated_move/3.png +0 -0
  56. package/test/references/06b_chessboard_animated_move/4.png +0 -0
  57. package/test/references/06b_chessboard_animated_move/5.png +0 -0
  58. package/test/references/06c_chessboard_animated_move/0.png +0 -0
  59. package/test/references/06c_chessboard_animated_move/1.png +0 -0
  60. package/test/references/06c_chessboard_animated_move/2.png +0 -0
  61. package/test/references/06c_chessboard_animated_move/3.png +0 -0
  62. package/test/references/06c_chessboard_animated_move/4.png +0 -0
  63. package/test/references/06c_chessboard_animated_move/5.png +0 -0
  64. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/0.png +0 -0
  65. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/1.png +0 -0
  66. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/2.png +0 -0
  67. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/3.png +0 -0
  68. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/4.png +0 -0
  69. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/5.png +0 -0
  70. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/6.png +0 -0
  71. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/7.png +0 -0
  72. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/8.png +0 -0
  73. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/after_move.png +0 -0
  74. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/empty_square.png +0 -0
  75. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/null_vector.png +0 -0
  76. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/out_of_board.png +0 -0
  77. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_arrow_marker.png +0 -0
  78. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_empty.png +0 -0
  79. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_1.png +0 -0
  80. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_2.png +0 -0
  81. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_square_marker.png +0 -0
  82. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_text_marker.png +0 -0
  83. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_1.png +0 -0
  84. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_2.png +0 -0
  85. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/edit_color_not_set.png +0 -0
  86. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/null_vector.png +0 -0
  87. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/out_of_board.png +0 -0
  88. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_arrow_marker.png +0 -0
  89. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_square_marker.png +0 -0
  90. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/castling_move.png +0 -0
  91. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_ambiguous_king_move.png +0 -0
  92. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_1.png +0 -0
  93. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_2.png +0 -0
  94. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_non_kxr_castling.png +0 -0
  95. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_move.png +0 -0
  96. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_position.png +0 -0
  97. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/null_vector.png +0 -0
  98. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/out_of_board.png +0 -0
  99. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_1.png +0 -0
  100. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_2.png +0 -0
  101. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/wrong_color.png +0 -0
  102. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/antichess_promotion.png +0 -0
  103. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/cancel_promotion.png +0 -0
  104. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_1.png +0 -0
  105. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_2.png +0 -0
  106. package/test/references/{12_movetext_simple → 13_movetext_simple}/0.png +0 -0
  107. package/test/references/{12_movetext_simple → 13_movetext_simple}/1.png +0 -0
  108. package/test/references/{12_movetext_simple → 13_movetext_simple}/2.png +0 -0
  109. package/test/references/{12_movetext_simple → 13_movetext_simple}/3.png +0 -0
  110. package/test/references/{13_movetext_error → 14_movetext_error}/0.png +0 -0
  111. package/test/references/{13_movetext_error → 14_movetext_error}/1.png +0 -0
  112. package/test/references/{13_movetext_error → 14_movetext_error}/2.png +0 -0
  113. package/test/references/{13_movetext_error → 14_movetext_error}/3.png +0 -0
  114. package/test/references/{13_movetext_error → 14_movetext_error}/4.png +0 -0
  115. package/test/references/{14_movetext_html → 15_movetext_html}/0.png +0 -0
  116. package/test/references/{14_movetext_html → 15_movetext_html}/1.png +0 -0
  117. package/test/references/{14_movetext_html → 15_movetext_html}/2.png +0 -0
  118. package/test/references/{15_movetext_options → 16_movetext_options}/0.png +0 -0
  119. package/test/references/{15_movetext_options → 16_movetext_options}/1.png +0 -0
  120. package/test/references/{15_movetext_options → 16_movetext_options}/2.png +0 -0
  121. package/test/references/{15_movetext_options → 16_movetext_options}/3.png +0 -0
  122. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/0.png +0 -0
  123. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/1.png +0 -0
  124. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/2.png +0 -0
  125. package/CHANGELOG.md +0 -141
  126. package/graphics/chess_sprites/cburnett/bb.svg +0 -45
  127. package/graphics/chess_sprites/cburnett/bk.svg +0 -47
  128. package/graphics/chess_sprites/cburnett/bn.svg +0 -37
  129. package/graphics/chess_sprites/cburnett/bp.svg +0 -19
  130. package/graphics/chess_sprites/cburnett/bq.svg +0 -58
  131. package/graphics/chess_sprites/cburnett/br.svg +0 -60
  132. package/graphics/chess_sprites/cburnett/bx.svg +0 -56
  133. package/graphics/chess_sprites/cburnett/wb.svg +0 -48
  134. package/graphics/chess_sprites/cburnett/wk.svg +0 -26
  135. package/graphics/chess_sprites/cburnett/wn.svg +0 -37
  136. package/graphics/chess_sprites/cburnett/wp.svg +0 -19
  137. package/graphics/chess_sprites/cburnett/wq.svg +0 -60
  138. package/graphics/chess_sprites/cburnett/wr.svg +0 -44
  139. package/graphics/chess_sprites/cburnett/wx.svg +0 -56
  140. package/graphics/chess_sprites/generate_sprites.sh +0 -135
  141. package/graphics/chess_sprites/mmonge/celtic-bx.svg +0 -112
  142. package/graphics/chess_sprites/mmonge/celtic-wx.svg +0 -111
  143. package/graphics/chess_sprites/mmonge/celtic.svg +0 -1576
  144. package/graphics/chess_sprites/mmonge/eyes-spatial-bx.svg +0 -101
  145. package/graphics/chess_sprites/mmonge/eyes-spatial-wx.svg +0 -100
  146. package/graphics/chess_sprites/mmonge/eyes.svg +0 -2538
  147. package/graphics/chess_sprites/mmonge/fantasy-bx.svg +0 -112
  148. package/graphics/chess_sprites/mmonge/fantasy-wx.svg +0 -111
  149. package/graphics/chess_sprites/mmonge/fantasy.svg +0 -5497
  150. package/graphics/chess_sprites/mmonge/fantasy_alt.svg +0 -3742
  151. package/graphics/chess_sprites/mmonge/freak.svg +0 -3479
  152. package/graphics/chess_sprites/mmonge/prmi.svg +0 -6776
  153. package/graphics/chess_sprites/mmonge/skulls-bx.svg +0 -124
  154. package/graphics/chess_sprites/mmonge/skulls-wx.svg +0 -111
  155. package/graphics/chess_sprites/mmonge/skulls.svg +0 -12978
  156. package/graphics/chess_sprites/mmonge/spatial.svg +0 -1223
  157. package/graphics/logo-small.svg +0 -14
  158. package/graphics/logo.svg +0 -26
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = SquareMarkerIcon;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _util = require("./impl/util");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
11
  /******************************************************************************
17
12
  * *
18
13
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -33,18 +28,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
33
28
  * <http://www.gnu.org/licenses/>. *
34
29
  * *
35
30
  ******************************************************************************/
31
+
36
32
  var SQUARE_MARGIN_FACTOR = 0.1;
33
+
37
34
  /**
38
35
  * SVG icon representing a square marker.
39
36
  */
40
-
41
37
  function SquareMarkerIcon(props) {
42
38
  var size = (0, _util.sanitizeInteger)(props.size, _util.MIN_SQUARE_SIZE, _util.MAX_SQUARE_SIZE);
43
-
44
39
  if (isNaN(size)) {
45
40
  return undefined;
46
41
  }
47
-
48
42
  var margin = Math.round(size * SQUARE_MARGIN_FACTOR);
49
43
  var viewBox = "0 0 ".concat(size, " ").concat(size);
50
44
  return /*#__PURE__*/_react["default"].createElement("svg", {
@@ -60,13 +54,11 @@ function SquareMarkerIcon(props) {
60
54
  fill: props.color
61
55
  }));
62
56
  }
63
-
64
57
  SquareMarkerIcon.propTypes = {
65
58
  /**
66
59
  * Width and height (in pixels) of the icon.
67
60
  */
68
61
  size: _propTypes["default"].number.isRequired,
69
-
70
62
  /**
71
63
  * Color to use to colorize the icon (for example: `'green'`, `'#ff0000'`...).
72
64
  */
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = TextMarkerIcon;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _util = require("./impl/util");
13
-
14
10
  var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
-
18
12
  /******************************************************************************
19
13
  * *
20
14
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -41,11 +35,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
41
35
  */
42
36
  function TextMarkerIcon(props) {
43
37
  var size = (0, _util.sanitizeInteger)(props.size, _util.MIN_SQUARE_SIZE, _util.MAX_SQUARE_SIZE);
44
-
45
38
  if (isNaN(size) || !(0, _util.isValidSymbol)(props.symbol)) {
46
39
  return undefined;
47
40
  }
48
-
49
41
  var viewBox = "0 0 ".concat(size, " ").concat(size);
50
42
  return /*#__PURE__*/_react["default"].createElement("svg", {
51
43
  className: "kokopu-textMarkerIcon",
@@ -60,13 +52,11 @@ function TextMarkerIcon(props) {
60
52
  color: props.color
61
53
  }));
62
54
  }
63
-
64
55
  TextMarkerIcon.propTypes = {
65
56
  /**
66
57
  * Width and height (in pixels) of the icon.
67
58
  */
68
59
  size: _propTypes["default"].number.isRequired,
69
-
70
60
  /**
71
61
  * Symbol to represent on the icon. Must be one of:
72
62
  * - any letter from A to Z (either upper-case or lower-case),
@@ -74,7 +64,6 @@ TextMarkerIcon.propTypes = {
74
64
  * - any symbol code among `'plus'`, `'times'`, `'dot'`, or `'circle'`.
75
65
  */
76
66
  symbol: _propTypes["default"].string.isRequired,
77
-
78
67
  /**
79
68
  * Color to use to colorize the icon (for example: `'green'`, `'#ff0000'`...).
80
69
  */
@@ -115,3 +115,7 @@ div.kokopu-subVariation {
115
115
  height: 0px;
116
116
  overflow: hidden;
117
117
  }
118
+
119
+ .kokopu-focusField {
120
+ position: absolute; /* see #1 */
121
+ }
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.formatMove = formatMove;
7
7
  exports.moveFormatter = moveFormatter;
8
-
9
8
  var _react = _interopRequireDefault(require("react"));
10
-
11
9
  var _i18n = _interopRequireDefault(require("./i18n"));
12
-
13
10
  require("./css/fonts.css");
14
-
15
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
-
17
12
  /******************************************************************************
18
13
  * *
19
14
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -46,6 +41,7 @@ function formatMove(pieceSymbols, notation) {
46
41
  var formatter = moveFormatter(pieceSymbols);
47
42
  return formatter(notation);
48
43
  }
44
+
49
45
  /**
50
46
  * Return a callback capable of rendering a SAN notation using the given piece symbol style.
51
47
  *
@@ -53,8 +49,6 @@ function formatMove(pieceSymbols, notation) {
53
49
  * for each English piece symbol.
54
50
  * @returns {function(string)} Callback returning either a string or a React fragment.
55
51
  */
56
-
57
-
58
52
  function moveFormatter(pieceSymbols) {
59
53
  if (pieceSymbols === 'localized') {
60
54
  var mapping = _i18n["default"].PIECE_SYMBOLS;
@@ -81,27 +75,23 @@ function moveFormatter(pieceSymbols) {
81
75
  };
82
76
  }
83
77
  }
78
+
84
79
  /**
85
80
  * Decompose the given string into piece symbol characters and sections of non piece symbol characters, and transform the piece symbols into
86
81
  * React objects represented with the given chess font.
87
82
  *
88
83
  * @ignore
89
84
  */
90
-
91
-
92
85
  function figurineNotation(fontName, text) {
93
86
  var result = [];
94
87
  var beginOfText = 0;
95
88
  var pieceSymbolIndex = 0;
96
-
97
89
  for (var pos = 0; pos < text.length; ++pos) {
98
90
  var currentChar = text.charAt(pos);
99
-
100
91
  if (currentChar === 'K' || currentChar === 'Q' || currentChar === 'R' || currentChar === 'B' || currentChar === 'N' || currentChar === 'P') {
101
92
  if (pos > beginOfText) {
102
93
  result.push(text.substring(beginOfText, pos));
103
94
  }
104
-
105
95
  beginOfText = pos + 1;
106
96
  var key = 'symbol-' + pieceSymbolIndex++;
107
97
  result.push( /*#__PURE__*/_react["default"].createElement("span", {
@@ -110,10 +100,8 @@ function figurineNotation(fontName, text) {
110
100
  }, currentChar));
111
101
  }
112
102
  }
113
-
114
103
  if (beginOfText < text.length) {
115
104
  result.push(text.substring(beginOfText));
116
105
  }
117
-
118
106
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, result);
119
107
  }
package/dist/lib/i18n.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  /******************************************************************************
9
8
  * *
10
9
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -25,6 +24,7 @@ exports["default"] = void 0;
25
24
  * <http://www.gnu.org/licenses/>. *
26
25
  * *
27
26
  ******************************************************************************/
27
+
28
28
  var i18n = {
29
29
  // Error box
30
30
  LINE: 'line {0}',
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = ArrowTip;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
10
  /******************************************************************************
15
11
  * *
16
12
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -42,19 +38,17 @@ function ArrowTip(props) {
42
38
  markerHeight: 4,
43
39
  refX: 2.5,
44
40
  refY: 2,
45
- orient: "auto",
46
- fill: props.color
41
+ orient: "auto"
47
42
  }, /*#__PURE__*/_react["default"].createElement("path", {
43
+ fill: props.color,
48
44
  d: "M 4,2 L 0,4 L 1,2 L 0,0 Z"
49
45
  }));
50
46
  }
51
-
52
47
  ArrowTip.propTypes = {
53
48
  /**
54
49
  * ID of the element.
55
50
  */
56
51
  id: _propTypes["default"].string.isRequired,
57
-
58
52
  /**
59
53
  * Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
60
54
  */
@@ -1,93 +1,73 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var htmlparser2 = _interopRequireWildcard(require("htmlparser2"));
13
-
14
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
-
20
13
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
-
22
14
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
-
24
15
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
-
26
16
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
27
-
28
17
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
29
-
30
18
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
-
32
19
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
-
34
20
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
35
-
36
21
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
-
38
22
  /**
39
23
  * Those tags cannot have any children.
40
24
  */
41
25
  var NO_CHILDREN_TAGS = new Set(['br', 'hr', 'img']);
26
+
42
27
  /**
43
28
  * HTML sanitizer: parse HTML string, keeping only the allowed HTML nodes, and the corresponding React object.
44
29
  */
45
-
46
30
  var HtmlSanitizer = /*#__PURE__*/function () {
47
31
  function HtmlSanitizer(_ref) {
48
32
  var allowedTags = _ref.allowedTags,
49
- allowedAttributes = _ref.allowedAttributes;
50
-
33
+ allowedAttributes = _ref.allowedAttributes;
51
34
  _classCallCheck(this, HtmlSanitizer);
52
-
53
35
  this._allowedTags = allowedTags ? new Set(allowedTags) : new Set();
54
36
  this._allowedAttributes = allowedAttributes ? new Map(Object.entries(allowedAttributes).map(function (_ref2) {
55
37
  var _ref3 = _slicedToArray(_ref2, 2),
56
- k = _ref3[0],
57
- v = _ref3[1];
58
-
38
+ k = _ref3[0],
39
+ v = _ref3[1];
59
40
  return [k, new Set(v)];
60
41
  })) : new Map();
61
42
  this._keyCounter = 0;
62
43
  }
44
+
63
45
  /**
64
46
  * @param {string} text HTML string to be parsed.
65
47
  * @returns {*} React object corresponding to the given HTML string. Can also be a fragment, or just a simple string if the given HTML string
66
48
  * does not contain any HTML tag.
67
49
  */
68
-
69
-
70
50
  _createClass(HtmlSanitizer, [{
71
51
  key: "parse",
72
52
  value: function parse(text) {
73
53
  var _this = this;
54
+ var dom = htmlparser2.parseDocument(text);
74
55
 
75
- var dom = htmlparser2.parseDocument(text); // Ensure that the returned object is a non-empty node type.
76
-
56
+ // Ensure that the returned object is a non-empty node type.
77
57
  if (dom.type !== 'root') {
78
58
  return undefined;
79
- } // Process the children of the root node.
80
-
59
+ }
81
60
 
61
+ // Process the children of the root node.
82
62
  var result = [];
83
63
  dom.children.forEach(function (child) {
84
64
  var childElement = _this._processNode(child);
85
-
86
65
  if (childElement) {
87
66
  result.push(childElement);
88
67
  }
89
- }); // Return the result.
68
+ });
90
69
 
70
+ // Return the result.
91
71
  if (result.length === 0) {
92
72
  return undefined;
93
73
  } else if (result.length === 1) {
@@ -102,17 +82,14 @@ var HtmlSanitizer = /*#__PURE__*/function () {
102
82
  key: "_processNode",
103
83
  value: function _processNode(node) {
104
84
  var _this2 = this;
105
-
106
85
  if (node.type === 'text') {
107
86
  return node.data;
108
87
  } else if (node.type === 'tag') {
109
88
  var children = NO_CHILDREN_TAGS.has(node.name) ? undefined : node.children.map(function (child) {
110
89
  return _this2._processNode(child);
111
90
  });
112
-
113
91
  if (this._allowedTags.has(node.name)) {
114
92
  var attributes = this._filterAttributes(node.name, node.attribs);
115
-
116
93
  attributes['key'] = this._allocateKey();
117
94
  return /*#__PURE__*/_react["default"].createElement(node.name, attributes, children);
118
95
  } else {
@@ -128,17 +105,14 @@ var HtmlSanitizer = /*#__PURE__*/function () {
128
105
  key: "_filterAttributes",
129
106
  value: function _filterAttributes(nodeName, attributes) {
130
107
  var result = {};
131
-
132
108
  for (var _i2 = 0, _Object$entries = Object.entries(attributes); _i2 < _Object$entries.length; _i2++) {
133
109
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
134
- attribute = _Object$entries$_i[0],
135
- value = _Object$entries$_i[1];
136
-
110
+ attribute = _Object$entries$_i[0],
111
+ value = _Object$entries$_i[1];
137
112
  if (this._isAttributeAllowed(nodeName, attribute)) {
138
113
  result[attribute === 'class' ? 'className' : attribute] = value;
139
114
  }
140
115
  }
141
-
142
116
  return result;
143
117
  }
144
118
  }, {
@@ -148,19 +122,14 @@ var HtmlSanitizer = /*#__PURE__*/function () {
148
122
  // Those attributes are always forbidden.
149
123
  return false;
150
124
  }
151
-
152
125
  var allowedAttributesForCurrent = this._allowedAttributes.get(nodeName);
153
-
154
126
  if (allowedAttributesForCurrent && allowedAttributesForCurrent.has(attribute)) {
155
127
  return true;
156
128
  }
157
-
158
129
  var allowedAttributesForAll = this._allowedAttributes.get('*');
159
-
160
130
  if (allowedAttributesForAll && allowedAttributesForAll.has(attribute)) {
161
131
  return true;
162
132
  }
163
-
164
133
  return false;
165
134
  }
166
135
  }, {
@@ -169,8 +138,6 @@ var HtmlSanitizer = /*#__PURE__*/function () {
169
138
  return 'auto-' + this._keyCounter++;
170
139
  }
171
140
  }]);
172
-
173
141
  return HtmlSanitizer;
174
142
  }();
175
-
176
143
  exports["default"] = HtmlSanitizer;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ 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); }; }
17
+ 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); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ var DEBUG_KEY = '__kokopu_debug_freeze_motion';
22
+
23
+ /**
24
+ * Wrap some animated content.
25
+ */
26
+ var Motion = /*#__PURE__*/function (_React$Component) {
27
+ _inherits(Motion, _React$Component);
28
+ var _super = _createSuper(Motion);
29
+ function Motion(props) {
30
+ var _this;
31
+ _classCallCheck(this, Motion);
32
+ _this = _super.call(this, props);
33
+ _this.state = {
34
+ cursor: 0
35
+ };
36
+ _this.animationFrameId = null;
37
+ _this.cursorStop = 1;
38
+
39
+ // WARNING: this hack exists only for testing purposes. DO NOT USE IT IN PRODUCTION.
40
+ if (typeof window[DEBUG_KEY] === 'number' && window[DEBUG_KEY] >= 0 && window[DEBUG_KEY] <= 1) {
41
+ _this.cursorStop = window[DEBUG_KEY];
42
+ }
43
+ return _this;
44
+ }
45
+ _createClass(Motion, [{
46
+ key: "componentDidMount",
47
+ value: function componentDidMount() {
48
+ var _this2 = this;
49
+ this.animationFrameId = window.requestAnimationFrame(function (ts) {
50
+ return _this2.handleAnimationStep(ts);
51
+ });
52
+ }
53
+ }, {
54
+ key: "componentWillUnmount",
55
+ value: function componentWillUnmount() {
56
+ if (this.animationFrameId !== null) {
57
+ window.cancelAnimationFrame(this.animationFrameId);
58
+ this.animationFrameId = null;
59
+ }
60
+ }
61
+ }, {
62
+ key: "handleAnimationStep",
63
+ value: function handleAnimationStep(timestamp) {
64
+ var _this3 = this;
65
+ if (this.initialTimestamp === undefined) {
66
+ this.initialTimestamp = timestamp;
67
+ }
68
+
69
+ // Compute the animation cursor and update the state.
70
+ var cursor = (timestamp - this.initialTimestamp) / this.props.duration;
71
+ if (cursor < 0) {
72
+ cursor = 0;
73
+ } else if (cursor > this.cursorStop) {
74
+ cursor = this.cursorStop;
75
+ }
76
+ this.setState({
77
+ cursor: cursor
78
+ });
79
+
80
+ // Schedule the next animation frame if necessary.
81
+ if (cursor === this.cursorStop) {
82
+ this.animationFrameId = null;
83
+ } else {
84
+ this.animationFrameId = window.requestAnimationFrame(function (ts) {
85
+ return _this3.handleAnimationStep(ts);
86
+ });
87
+ }
88
+ }
89
+ }, {
90
+ key: "render",
91
+ value: function render() {
92
+ return this.props.children(this.state.cursor);
93
+ }
94
+ }]);
95
+ return Motion;
96
+ }(_react["default"].Component);
97
+ exports["default"] = Motion;
98
+ Motion.propTypes = {
99
+ /**
100
+ * Duration of the animation. Must be > 0.
101
+ */
102
+ duration: _propTypes["default"].number.isRequired,
103
+ /**
104
+ * Factory for the content being animated. The animation cursor is guaranteed to be valued between 0 and 1 inclusive.
105
+ */
106
+ children: _propTypes["default"].func.isRequired
107
+ };
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = TextSymbol;
7
-
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  require("../css/symbol.css");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
11
  /******************************************************************************
17
12
  * *
18
13
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -33,13 +28,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
33
28
  * <http://www.gnu.org/licenses/>. *
34
29
  * *
35
30
  ******************************************************************************/
31
+
36
32
  var SHAPE_THICKNESS_FACTOR = 0.1;
37
33
  var DOT_RADIUS_FACTOR = 0.15;
38
34
  var CIRCLE_RADIUS_FACTOR = 0.425;
35
+
39
36
  /**
40
37
  * Symbol of a text marker.
41
38
  */
42
-
43
39
  function TextSymbol(props) {
44
40
  if (props.symbol === 'dot') {
45
41
  return /*#__PURE__*/_react["default"].createElement("circle", {
@@ -69,28 +65,23 @@ function TextSymbol(props) {
69
65
  }, symbol);
70
66
  }
71
67
  }
72
-
73
68
  TextSymbol.propTypes = {
74
69
  /**
75
70
  * X-coordinate of the center of the symbol.
76
71
  */
77
72
  x: _propTypes["default"].number.isRequired,
78
-
79
73
  /**
80
74
  * Y-coordinate of the center of the symbol.
81
75
  */
82
76
  y: _propTypes["default"].number.isRequired,
83
-
84
77
  /**
85
78
  * Size of the symbol (i.e. size of square in which the symbol is rendered).
86
79
  */
87
80
  size: _propTypes["default"].number.isRequired,
88
-
89
81
  /**
90
82
  * Symbol code.
91
83
  */
92
84
  symbol: _propTypes["default"].string.isRequired,
93
-
94
85
  /**
95
86
  * Color to use to colorize the shape (for example: `'green'`, `'#ff0000'`...).
96
87
  */
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  /******************************************************************************
9
8
  * *
10
9
  * This file is part of Kokopu-React, a JavaScript chess library. *
@@ -66,7 +65,6 @@ var _default = {
66
65
  cr: '#d00',
67
66
  cy: '#ff0'
68
67
  },
69
-
70
68
  /*
71
69
  * Source: http://omgchess.blogspot.fr/2015/09/chess-board-color-schemes.html
72
70
  * Author: Gorgonian <http://omgchess.blogspot.fr/>