kokopu-react 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/lib/Chessboard.js +84 -97
  2. package/dist/lib/ErrorBox.js +3 -1
  3. package/dist/lib/Movetext.js +24 -15
  4. package/dist/lib/i18n.js +2 -1
  5. package/dist/lib/impl/ArrowTip.js +2 -2
  6. package/dist/lib/impl/Motion.js +133 -0
  7. package/dist/lib/impl/util.js +12 -0
  8. package/doc_src/demo/PageChessboardInteraction.js +9 -9
  9. package/doc_src/demo/PageChessboardMove.js +8 -8
  10. package/doc_src/demo/PageMovetextInteraction.js +2 -2
  11. package/graphic_test_src/02_chessboard_simple.js +2 -2
  12. package/graphic_test_src/03_chessboard_flipped.js +2 -2
  13. package/graphic_test_src/05_chessboard_move.js +4 -4
  14. package/graphic_test_src/06a_chessboard_animated_move.js +36 -0
  15. package/graphic_test_src/06b_chessboard_animated_move.js +36 -0
  16. package/graphic_test_src/06c_chessboard_animated_move.js +36 -0
  17. package/graphic_test_src/{06_chessboard_theme.js → 07_chessboard_theme.js} +0 -0
  18. package/graphic_test_src/{07_chessboard_click_squares.js → 08_chessboard_click_squares.js} +0 -0
  19. package/graphic_test_src/{08_chessboard_move_pieces.js → 09_chessboard_move_pieces.js} +0 -0
  20. package/graphic_test_src/{09_chessboard_edit_arrows.js → 10_chessboard_edit_arrows.js} +0 -0
  21. package/graphic_test_src/{10_chessboard_play_moves.js → 11_chessboard_play_moves.js} +0 -0
  22. package/graphic_test_src/{11_chessboard_play_promotions.js → 12_chessboard_play_promotions.js} +0 -0
  23. package/graphic_test_src/{12_movetext_simple.js → 13_movetext_simple.js} +3 -3
  24. package/graphic_test_src/{13_movetext_error.js → 14_movetext_error.js} +4 -3
  25. package/graphic_test_src/{14_movetext_html.js → 15_movetext_html.js} +0 -0
  26. package/graphic_test_src/{15_movetext_options.js → 16_movetext_options.js} +0 -0
  27. package/graphic_test_src/{16_movetext_interaction.js → 17_movetext_interaction.js} +0 -0
  28. package/graphic_test_src/common/games.pgn +3 -3
  29. package/package.json +17 -19
  30. package/scripts/docker-compose.yml +1 -1
  31. package/src/Chessboard.js +42 -42
  32. package/src/ErrorBox.js +2 -1
  33. package/src/Movetext.js +20 -16
  34. package/src/i18n.js +1 -0
  35. package/src/impl/ArrowTip.js +2 -2
  36. package/src/impl/Motion.js +99 -0
  37. package/src/impl/util.js +8 -0
  38. package/test/4_chessboard_graphic.js +4 -1
  39. package/test/5_chessboard_interaction.js +5 -5
  40. package/test/6_chessboard_play_moves.js +4 -4
  41. package/test/7_movetext_graphic.js +4 -4
  42. package/test/8_movetext_interaction.js +2 -2
  43. package/test/common/graphic.js +6 -0
  44. package/test/references/06a_chessboard_animated_move/0.png +0 -0
  45. package/test/references/06a_chessboard_animated_move/1.png +0 -0
  46. package/test/references/06a_chessboard_animated_move/2.png +0 -0
  47. package/test/references/06a_chessboard_animated_move/3.png +0 -0
  48. package/test/references/06a_chessboard_animated_move/4.png +0 -0
  49. package/test/references/06a_chessboard_animated_move/5.png +0 -0
  50. package/test/references/06b_chessboard_animated_move/0.png +0 -0
  51. package/test/references/06b_chessboard_animated_move/1.png +0 -0
  52. package/test/references/06b_chessboard_animated_move/2.png +0 -0
  53. package/test/references/06b_chessboard_animated_move/3.png +0 -0
  54. package/test/references/06b_chessboard_animated_move/4.png +0 -0
  55. package/test/references/06b_chessboard_animated_move/5.png +0 -0
  56. package/test/references/06c_chessboard_animated_move/0.png +0 -0
  57. package/test/references/06c_chessboard_animated_move/1.png +0 -0
  58. package/test/references/06c_chessboard_animated_move/2.png +0 -0
  59. package/test/references/06c_chessboard_animated_move/3.png +0 -0
  60. package/test/references/06c_chessboard_animated_move/4.png +0 -0
  61. package/test/references/06c_chessboard_animated_move/5.png +0 -0
  62. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/0.png +0 -0
  63. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/1.png +0 -0
  64. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/2.png +0 -0
  65. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/3.png +0 -0
  66. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/4.png +0 -0
  67. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/5.png +0 -0
  68. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/6.png +0 -0
  69. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/7.png +0 -0
  70. package/test/references/{06_chessboard_theme → 07_chessboard_theme}/8.png +0 -0
  71. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/after_move.png +0 -0
  72. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/empty_square.png +0 -0
  73. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/null_vector.png +0 -0
  74. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/out_of_board.png +0 -0
  75. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_arrow_marker.png +0 -0
  76. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_empty.png +0 -0
  77. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_1.png +0 -0
  78. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_non_empty_2.png +0 -0
  79. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_square_marker.png +0 -0
  80. package/test/references/{08_chessboard_move_pieces → 09_chessboard_move_pieces}/over_text_marker.png +0 -0
  81. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_1.png +0 -0
  82. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/base_2.png +0 -0
  83. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/edit_color_not_set.png +0 -0
  84. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/null_vector.png +0 -0
  85. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/out_of_board.png +0 -0
  86. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_arrow_marker.png +0 -0
  87. package/test/references/{09_chessboard_edit_arrows → 10_chessboard_edit_arrows}/over_square_marker.png +0 -0
  88. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/castling_move.png +0 -0
  89. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_ambiguous_king_move.png +0 -0
  90. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_1.png +0 -0
  91. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_castling_move_2.png +0 -0
  92. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/chess960_non_kxr_castling.png +0 -0
  93. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_move.png +0 -0
  94. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/illegal_position.png +0 -0
  95. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/null_vector.png +0 -0
  96. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/out_of_board.png +0 -0
  97. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_1.png +0 -0
  98. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/regular_move_2.png +0 -0
  99. package/test/references/{10_chessboard_play_moves → 11_chessboard_play_moves}/wrong_color.png +0 -0
  100. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/antichess_promotion.png +0 -0
  101. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/cancel_promotion.png +0 -0
  102. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_1.png +0 -0
  103. package/test/references/{11_chessboard_play_promotions → 12_chessboard_play_promotions}/regular_promotion_2.png +0 -0
  104. package/test/references/{12_movetext_simple → 13_movetext_simple}/0.png +0 -0
  105. package/test/references/{12_movetext_simple → 13_movetext_simple}/1.png +0 -0
  106. package/test/references/{12_movetext_simple → 13_movetext_simple}/2.png +0 -0
  107. package/test/references/{12_movetext_simple → 13_movetext_simple}/3.png +0 -0
  108. package/test/references/14_movetext_error/0.png +0 -0
  109. package/test/references/14_movetext_error/1.png +0 -0
  110. package/test/references/{13_movetext_error/1.png → 14_movetext_error/2.png} +0 -0
  111. package/test/references/14_movetext_error/3.png +0 -0
  112. package/test/references/14_movetext_error/4.png +0 -0
  113. package/test/references/15_movetext_html/0.png +0 -0
  114. package/test/references/15_movetext_html/1.png +0 -0
  115. package/test/references/{14_movetext_html → 15_movetext_html}/2.png +0 -0
  116. package/test/references/{15_movetext_options → 16_movetext_options}/0.png +0 -0
  117. package/test/references/{15_movetext_options → 16_movetext_options}/1.png +0 -0
  118. package/test/references/{15_movetext_options → 16_movetext_options}/2.png +0 -0
  119. package/test/references/{15_movetext_options → 16_movetext_options}/3.png +0 -0
  120. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/0.png +0 -0
  121. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/1.png +0 -0
  122. package/test/references/{16_movetext_interaction → 17_movetext_interaction}/2.png +0 -0
  123. package/CHANGELOG.md +0 -131
  124. package/graphics/chess_sprites/cburnett/bb.svg +0 -45
  125. package/graphics/chess_sprites/cburnett/bk.svg +0 -47
  126. package/graphics/chess_sprites/cburnett/bn.svg +0 -37
  127. package/graphics/chess_sprites/cburnett/bp.svg +0 -19
  128. package/graphics/chess_sprites/cburnett/bq.svg +0 -58
  129. package/graphics/chess_sprites/cburnett/br.svg +0 -60
  130. package/graphics/chess_sprites/cburnett/bx.svg +0 -56
  131. package/graphics/chess_sprites/cburnett/wb.svg +0 -48
  132. package/graphics/chess_sprites/cburnett/wk.svg +0 -26
  133. package/graphics/chess_sprites/cburnett/wn.svg +0 -37
  134. package/graphics/chess_sprites/cburnett/wp.svg +0 -19
  135. package/graphics/chess_sprites/cburnett/wq.svg +0 -60
  136. package/graphics/chess_sprites/cburnett/wr.svg +0 -44
  137. package/graphics/chess_sprites/cburnett/wx.svg +0 -56
  138. package/graphics/chess_sprites/generate_sprites.sh +0 -135
  139. package/graphics/chess_sprites/mmonge/celtic-bx.svg +0 -112
  140. package/graphics/chess_sprites/mmonge/celtic-wx.svg +0 -111
  141. package/graphics/chess_sprites/mmonge/celtic.svg +0 -1576
  142. package/graphics/chess_sprites/mmonge/eyes-spatial-bx.svg +0 -101
  143. package/graphics/chess_sprites/mmonge/eyes-spatial-wx.svg +0 -100
  144. package/graphics/chess_sprites/mmonge/eyes.svg +0 -2538
  145. package/graphics/chess_sprites/mmonge/fantasy-bx.svg +0 -112
  146. package/graphics/chess_sprites/mmonge/fantasy-wx.svg +0 -111
  147. package/graphics/chess_sprites/mmonge/fantasy.svg +0 -5497
  148. package/graphics/chess_sprites/mmonge/fantasy_alt.svg +0 -3742
  149. package/graphics/chess_sprites/mmonge/freak.svg +0 -3479
  150. package/graphics/chess_sprites/mmonge/prmi.svg +0 -6776
  151. package/graphics/chess_sprites/mmonge/skulls-bx.svg +0 -124
  152. package/graphics/chess_sprites/mmonge/skulls-wx.svg +0 -111
  153. package/graphics/chess_sprites/mmonge/skulls.svg +0 -12978
  154. package/graphics/chess_sprites/mmonge/spatial.svg +0 -1223
  155. package/graphics/logo-small.svg +0 -14
  156. package/graphics/logo.svg +0 -26
  157. package/test/references/13_movetext_error/0.png +0 -0
  158. package/test/references/13_movetext_error/2.png +0 -0
  159. package/test/references/13_movetext_error/3.png +0 -0
  160. package/test/references/14_movetext_html/0.png +0 -0
  161. package/test/references/14_movetext_html/1.png +0 -0
@@ -0,0 +1,133 @@
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
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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); } }
19
+
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+
22
+ 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); }
23
+
24
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
+
26
+ 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); }; }
27
+
28
+ 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); }
29
+
30
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
+
32
+ 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; } }
33
+
34
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
35
+
36
+ var DEBUG_KEY = '__kokopu_debug_freeze_motion';
37
+ /**
38
+ * Wrap some animated content.
39
+ */
40
+
41
+ var Motion = /*#__PURE__*/function (_React$Component) {
42
+ _inherits(Motion, _React$Component);
43
+
44
+ var _super = _createSuper(Motion);
45
+
46
+ function Motion(props) {
47
+ var _this;
48
+
49
+ _classCallCheck(this, Motion);
50
+
51
+ _this = _super.call(this, props);
52
+ _this.state = {
53
+ cursor: 0
54
+ };
55
+ _this.animationFrameId = null;
56
+ _this.cursorStop = 1; // WARNING: this hack exists only for testing purposes. DO NOT USE IT IN PRODUCTION.
57
+
58
+ if (typeof window[DEBUG_KEY] === 'number' && window[DEBUG_KEY] >= 0 && window[DEBUG_KEY] <= 1) {
59
+ _this.cursorStop = window[DEBUG_KEY];
60
+ }
61
+
62
+ return _this;
63
+ }
64
+
65
+ _createClass(Motion, [{
66
+ key: "componentDidMount",
67
+ value: function componentDidMount() {
68
+ var _this2 = this;
69
+
70
+ this.animationFrameId = window.requestAnimationFrame(function (ts) {
71
+ return _this2.handleAnimationStep(ts);
72
+ });
73
+ }
74
+ }, {
75
+ key: "componentWillUnmount",
76
+ value: function componentWillUnmount() {
77
+ if (this.animationFrameId !== null) {
78
+ window.cancelAnimationFrame(this.animationFrameId);
79
+ this.animationFrameId = null;
80
+ }
81
+ }
82
+ }, {
83
+ key: "handleAnimationStep",
84
+ value: function handleAnimationStep(timestamp) {
85
+ var _this3 = this;
86
+
87
+ if (this.initialTimestamp === undefined) {
88
+ this.initialTimestamp = timestamp;
89
+ } // Compute the animation cursor and update the state.
90
+
91
+
92
+ var cursor = (timestamp - this.initialTimestamp) / this.props.duration;
93
+
94
+ if (cursor < 0) {
95
+ cursor = 0;
96
+ } else if (cursor > this.cursorStop) {
97
+ cursor = this.cursorStop;
98
+ }
99
+
100
+ this.setState({
101
+ cursor: cursor
102
+ }); // Schedule the next animation frame if necessary.
103
+
104
+ if (cursor === this.cursorStop) {
105
+ this.animationFrameId = null;
106
+ } else {
107
+ this.animationFrameId = window.requestAnimationFrame(function (ts) {
108
+ return _this3.handleAnimationStep(ts);
109
+ });
110
+ }
111
+ }
112
+ }, {
113
+ key: "render",
114
+ value: function render() {
115
+ return this.props.children(this.state.cursor);
116
+ }
117
+ }]);
118
+
119
+ return Motion;
120
+ }(_react["default"].Component);
121
+
122
+ exports["default"] = Motion;
123
+ Motion.propTypes = {
124
+ /**
125
+ * Duration of the animation. Must be > 0.
126
+ */
127
+ duration: _propTypes["default"].number.isRequired,
128
+
129
+ /**
130
+ * Factory for the content being animated. The animation cursor is guaranteed to be valued between 0 and 1 inclusive.
131
+ */
132
+ children: _propTypes["default"].func.isRequired
133
+ };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MIN_SQUARE_SIZE = exports.MAX_SQUARE_SIZE = void 0;
7
+ exports.fillPlaceholder = fillPlaceholder;
7
8
  exports.generateRandomId = generateRandomId;
8
9
  exports.isValidColor = isValidColor;
9
10
  exports.isValidSquare = isValidSquare;
@@ -48,6 +49,17 @@ function generateRandomId() {
48
49
  return result;
49
50
  }
50
51
 
52
+ function fillPlaceholder(message) {
53
+ for (var _len = arguments.length, placeholderValues = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
54
+ placeholderValues[_key - 1] = arguments[_key];
55
+ }
56
+
57
+ return message.replace(/{(\d+)}/g, function (match, placeholder) {
58
+ var placeholderIndex = Number(placeholder);
59
+ return placeholderIndex < placeholderValues.length ? placeholderValues[placeholderIndex] : match;
60
+ });
61
+ }
62
+
51
63
  function sanitizeInteger(input, min, max) {
52
64
  return Math.min(Math.max(Math.round(input), min), max);
53
65
  }
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { Position, oppositeColor } from 'kokopu';
25
25
 
26
26
  import { Chessboard, SquareMarkerIcon, TextMarkerIcon, ArrowMarkerIcon, flattenSquareMarkers, flattenTextMarkers, flattenArrowMarkers } from '../../src/index';
27
27
  import { buildComponentDemoCode } from './util';
@@ -53,7 +53,7 @@ export default class Page extends React.Component {
53
53
  constructor(props) {
54
54
  super(props);
55
55
  this.state = {
56
- position: new kokopu.Position(),
56
+ position: new Position(),
57
57
  flipped: false,
58
58
  interactionMode: 'movePieces',
59
59
  pieceEditMode: 'wp',
@@ -83,12 +83,12 @@ export default class Page extends React.Component {
83
83
  <FormControlLabel label="Flip"
84
84
  control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
85
85
  />
86
- <Button color="primary" size="small" variant="contained" onClick={() => this.handleTurnClicked(kokopu.oppositeColor(this.state.position.turn()))}>
86
+ <Button color="primary" size="small" variant="contained" onClick={() => this.handleTurnClicked(oppositeColor(this.state.position.turn()))}>
87
87
  Change turn
88
88
  </Button>
89
89
  <ButtonGroup color="primary" size="small">
90
- <Button onClick={() => this.set('position', new kokopu.Position('empty'))}>Clear</Button>
91
- <Button onClick={() => this.set('position', new kokopu.Position())}>Reset</Button>
90
+ <Button onClick={() => this.set('position', new Position('empty'))}>Clear</Button>
91
+ <Button onClick={() => this.set('position', new Position())}>Reset</Button>
92
92
  </ButtonGroup>
93
93
  </Stack>
94
94
  <Box>
@@ -266,20 +266,20 @@ export default class Page extends React.Component {
266
266
  }
267
267
 
268
268
  handleTurnClicked(newTurn) {
269
- let newPosition = new kokopu.Position(this.state.position);
269
+ let newPosition = new Position(this.state.position);
270
270
  newPosition.turn(newTurn);
271
271
  this.set('position', newPosition);
272
272
  }
273
273
 
274
274
  handlePieceMoved(from, to) {
275
- let newPosition = new kokopu.Position(this.state.position);
275
+ let newPosition = new Position(this.state.position);
276
276
  newPosition.square(to, newPosition.square(from));
277
277
  newPosition.square(from, '-');
278
278
  this.set('position', newPosition);
279
279
  }
280
280
 
281
281
  handleMovePlayed(move) {
282
- let newPosition = new kokopu.Position(this.state.position);
282
+ let newPosition = new Position(this.state.position);
283
283
  newPosition.play(move);
284
284
  this.set('position', newPosition);
285
285
  }
@@ -318,7 +318,7 @@ export default class Page extends React.Component {
318
318
  this.set('textMarkers', newTextMarkers);
319
319
  }
320
320
  else if (this.state.interactionMode === 'addRemovePieces') {
321
- let newPosition = new kokopu.Position(this.state.position);
321
+ let newPosition = new Position(this.state.position);
322
322
  newPosition.square(sq, newPosition.square(sq) === this.state.pieceEditMode ? '-' : this.state.pieceEditMode);
323
323
  this.set('position', newPosition);
324
324
  }
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { exception, Position } from 'kokopu';
25
25
 
26
26
  import { Chessboard, ArrowMarkerIcon } from '../../src/index';
27
27
  import { buildComponentDemoCode } from './util';
@@ -45,8 +45,8 @@ export default class Page extends React.Component {
45
45
 
46
46
  constructor(props) {
47
47
  super(props);
48
- let position = new kokopu.Position();
49
- let positionAfter = new kokopu.Position(position);
48
+ let position = new Position();
49
+ let positionAfter = new Position(position);
50
50
  positionAfter.play('e4');
51
51
  this.state = {
52
52
  position: position,
@@ -88,8 +88,8 @@ export default class Page extends React.Component {
88
88
  <TextField label="Move" variant="standard" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
89
89
  <Button color="primary" size="small" variant="contained" onClick={() => this.handlePlayClicked()}>Play</Button>
90
90
  <ButtonGroup color="primary" size="small">
91
- <Button onClick={() => this.setPosition(new kokopu.Position('empty'))}>Clear</Button>
92
- <Button onClick={() => this.setPosition(new kokopu.Position())}>Reset</Button>
91
+ <Button onClick={() => this.setPosition(new Position('empty'))}>Clear</Button>
92
+ <Button onClick={() => this.setPosition(new Position())}>Reset</Button>
93
93
  </ButtonGroup>
94
94
  </Stack>
95
95
  </>);
@@ -164,7 +164,7 @@ export default class Page extends React.Component {
164
164
 
165
165
  handlePlayClicked() {
166
166
  let newState = {};
167
- let currentPosition = new kokopu.Position(this.state.positionAfter ? this.state.positionAfter : this.state.position);
167
+ let currentPosition = new Position(this.state.positionAfter ? this.state.positionAfter : this.state.position);
168
168
  let move = this.state.editedMove.trim();
169
169
  if (move === '') {
170
170
  newState.position = currentPosition;
@@ -176,11 +176,11 @@ export default class Page extends React.Component {
176
176
  let moveDescriptor = currentPosition.notation(move);
177
177
  newState.position = currentPosition;
178
178
  newState.playedMove = currentPosition.notation(moveDescriptor);
179
- newState.positionAfter = new kokopu.Position(currentPosition);
179
+ newState.positionAfter = new Position(currentPosition);
180
180
  newState.positionAfter.play(moveDescriptor);
181
181
  }
182
182
  catch (e) {
183
- if (e instanceof kokopu.exception.InvalidNotation) {
183
+ if (e instanceof exception.InvalidNotation) {
184
184
  newState.position = currentPosition;
185
185
  newState.playedMove = move;
186
186
  newState.positionAfter = null;
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { pgnRead } from 'kokopu';
25
25
 
26
26
  import { Chessboard, Movetext } from '../../src/index';
27
27
  import { buildComponentDemoCode } from './util';
@@ -143,7 +143,7 @@ export default class Page extends React.Component {
143
143
  }
144
144
 
145
145
  getCurrentPositionAndAnnotations() {
146
- let game = kokopu.pgnRead(this.state.pgn, 0);
146
+ let game = pgnRead(this.state.pgn, 0);
147
147
  if (this.state.selection === 'start') {
148
148
  let mainVariation = game.mainVariation();
149
149
  return { position: mainVariation.initialPosition(), csl: mainVariation.tag('csl'), cal: mainVariation.tag('cal') };
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { Position } from 'kokopu';
25
25
  import testApp from './common/test_app';
26
26
  import { Chessboard } from '../src/index';
27
27
 
@@ -30,6 +30,6 @@ testApp([ /* eslint-disable react/jsx-key */
30
30
  <Chessboard position="empty" />,
31
31
  <Chessboard position="something invalid" />,
32
32
  <Chessboard position="r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3" />,
33
- <Chessboard position={new kokopu.Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
33
+ <Chessboard position={new Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
34
34
  <Chessboard position={42} />,
35
35
  ]); /* eslint-enable react/jsx-key */
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { Position } from 'kokopu';
25
25
  import testApp from './common/test_app';
26
26
  import { Chessboard } from '../src/index';
27
27
 
@@ -30,5 +30,5 @@ testApp([ /* eslint-disable react/jsx-key */
30
30
  <Chessboard flipped={true} position="empty" />,
31
31
  <Chessboard flipped={true} position="something invalid" />,
32
32
  <Chessboard flipped={true} position="r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3" />,
33
- <Chessboard flipped={true} position={new kokopu.Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
33
+ <Chessboard flipped={true} position={new Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
34
34
  ]); /* eslint-enable react/jsx-key */
@@ -21,19 +21,19 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { Position } from 'kokopu';
25
25
  import testApp from './common/test_app';
26
26
  import { Chessboard } from '../src/index';
27
27
 
28
- let pos = new kokopu.Position('r1bqkbnr/1ppp1ppp/p1n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 4');
28
+ let pos = new Position('r1bqkbnr/1ppp1ppp/p1n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 4');
29
29
  let move = pos.notation('Bxc6');
30
30
 
31
31
  testApp([ /* eslint-disable react/jsx-key */
32
32
  <Chessboard move="e4" animated={false} />,
33
33
  <Chessboard move="Nf3" moveArrowVisible={false} animated={false} />,
34
34
  <Chessboard move="Nf4" animated={false} />,
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} moveArrowColor="g" />,
35
+ <Chessboard position="rnbqkbnr/pppp1ppp/4p3/8/3PP3/8/PPP2PPP/RNBQKBNR b KQkq - 0 2" move="Bb4+" moveArrowVisible={true} flipped={true} animated={true} />,
36
+ <Chessboard position={pos} move={move} animated={true} moveArrowColor="g" />,
37
37
  <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={false} moveArrowColor="r" />,
38
38
  <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={false} moveArrowColor="y" />,
39
39
  <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={false} moveArrowColor="b" />,
@@ -0,0 +1,36 @@
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 testApp from './common/test_app';
25
+ import { Chessboard } from '../src/index';
26
+
27
+ window['__kokopu_debug_freeze_motion'] = 0.09;
28
+
29
+ testApp([ /* eslint-disable react/jsx-key */
30
+ <Chessboard move="e4" animated={true} />,
31
+ <Chessboard move="Nf3" animated={true} moveArrowVisible={false} />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped />,
33
+ <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
+ <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={true} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} />,
36
+ ]); /* eslint-enable react/jsx-key */
@@ -0,0 +1,36 @@
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 testApp from './common/test_app';
25
+ import { Chessboard } from '../src/index';
26
+
27
+ window['__kokopu_debug_freeze_motion'] = 0.7;
28
+
29
+ testApp([ /* eslint-disable react/jsx-key */
30
+ <Chessboard move="e4" animated={true} />,
31
+ <Chessboard move="Nf3" animated={true} moveArrowVisible={false} />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped />,
33
+ <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
+ <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={true} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} />,
36
+ ]); /* eslint-enable react/jsx-key */
@@ -0,0 +1,36 @@
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 testApp from './common/test_app';
25
+ import { Chessboard } from '../src/index';
26
+
27
+ window['__kokopu_debug_freeze_motion'] = 0.91;
28
+
29
+ testApp([ /* eslint-disable react/jsx-key */
30
+ <Chessboard move="e4" animated={true} />,
31
+ <Chessboard move="Nf3" animated={true} moveArrowVisible={false} />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped />,
33
+ <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
+ <Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={true} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} />,
36
+ ]); /* eslint-enable react/jsx-key */
@@ -21,17 +21,17 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { Game, pgnRead } from 'kokopu';
25
25
  import testApp from './common/test_app';
26
26
  import { Movetext } from '../src/index';
27
27
 
28
28
  import pgn from './common/games.pgn';
29
29
 
30
- let game = new kokopu.Game();
30
+ let game = new Game();
31
31
  game.mainVariation().play('e4').play('e5').play('Bc4').play('Nc6').play('Qh5').play('Nf6').play('Qxf7#');
32
32
  game.result('1-0');
33
33
 
34
- let database = kokopu.pgnRead(pgn);
34
+ let database = pgnRead(pgn);
35
35
 
36
36
  testApp([ /* eslint-disable react/jsx-key */
37
37
  <Movetext game={game} />,
@@ -21,18 +21,19 @@
21
21
 
22
22
 
23
23
  import React from 'react';
24
- import kokopu from 'kokopu';
24
+ import { pgnRead } from 'kokopu';
25
25
  import testApp from './common/test_app';
26
26
  import { Movetext } from '../src/index';
27
27
 
28
28
  import pgn from './common/games.pgn';
29
29
  import dummyPgn from './common/dummy.pgn';
30
30
 
31
- let database = kokopu.pgnRead(pgn);
31
+ let database = pgnRead(pgn);
32
32
 
33
33
  testApp([ /* eslint-disable react/jsx-key */
34
+ <Movetext game={pgn} gameIndex={99} />,
34
35
  <Movetext game={database} gameIndex={99} />,
35
36
  <Movetext game={dummyPgn} />,
36
- <Movetext game={kokopu.pgnRead(dummyPgn)} gameIndex={1} />,
37
+ <Movetext game={pgnRead(dummyPgn)} gameIndex={1} />,
37
38
  <Movetext game={42} />,
38
39
  ], 'width-600'); /* eslint-enable react/jsx-key */
@@ -87,8 +87,8 @@ probably to assure himself that the combination was sound and that he had a forc
87
87
  [White "1<sup>st</sup> <em>player</em>"]
88
88
  [Black "2<sub>nd</sub> <i>player</i>"]
89
89
  [Result "*"]
90
- [WhiteElo "<ins>2800</ins>"]
91
- [BlackElo "<del>1010</del>"]
90
+ [WhiteElo "2800"]
91
+ [BlackElo "1010"]
92
92
  [WhiteTitle "<span class=\"myClass\">GM</span>"]
93
93
  [BlackTitle "<span id=\"myId\">no-GM</span>"]
94
94
 
@@ -104,7 +104,7 @@ probably to assure himself that the combination was sound and that he had a forc
104
104
  [Black "?"]
105
105
  [Result "*"]
106
106
 
107
- {I'm a <strong><ins>comment</ins></strong> with some <em class="myClass">HTML content</em> in it.<br/>
107
+ {I'm a <strong><ins>comment</ins></strong> with <del>some</del> <em class="myClass">HTML content</em> in it.<br/>
108
108
  Lists are supported:
109
109
  <ul>
110
110
  <li>1<sup>st</sup> point</li>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokopu-react",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "A React-based library to create and display chessboard and chess-related components.",
5
5
  "keywords": [
6
6
  "chess",
@@ -19,7 +19,6 @@
19
19
  "dist/lib",
20
20
  "doc_src",
21
21
  "graphic_test_src",
22
- "graphics",
23
22
  "scripts/clean-graphic-output.js",
24
23
  "scripts/docker-compose.yml",
25
24
  "scripts/test-graphic.webpack.config.js",
@@ -31,44 +30,43 @@
31
30
  ".nycrc.yml"
32
31
  ],
33
32
  "peerDependencies": {
34
- "kokopu": "^2.6.0",
33
+ "kokopu": "^3.0.0",
35
34
  "react": "17.x.x || 18.x.x"
36
35
  },
37
36
  "dependencies": {
38
37
  "htmlparser2": "^8.0.1",
39
38
  "prop-types": "^15.8.1",
40
- "react-draggable": "^4.4.5",
41
- "react-motion": "^0.5.2"
39
+ "react-draggable": "^4.4.5"
42
40
  },
43
41
  "devDependencies": {
44
- "@babel/cli": "^7.17.10",
45
- "@babel/core": "^7.18.5",
46
- "@babel/preset-env": "^7.18.2",
47
- "@babel/preset-react": "^7.17.12",
48
- "@emotion/react": "^11.9.3",
49
- "@emotion/styled": "^11.9.3",
50
- "@mui/material": "^5.8.5",
42
+ "@babel/cli": "^7.18.10",
43
+ "@babel/core": "^7.19.0",
44
+ "@babel/preset-env": "^7.19.0",
45
+ "@babel/preset-react": "^7.18.6",
46
+ "@emotion/react": "^11.10.0",
47
+ "@emotion/styled": "^11.10.0",
48
+ "@mui/material": "^5.10.2",
51
49
  "babel-loader": "^8.2.5",
52
50
  "babel-plugin-istanbul": "^6.1.1",
53
51
  "copy-webpack-plugin": "^11.0.0",
54
52
  "coveralls": "^3.1.1",
55
53
  "css-loader": "^6.7.1",
56
- "eslint": "^8.18.0",
57
- "eslint-plugin-react": "^7.30.0",
54
+ "eslint": "^8.22.0",
55
+ "eslint-plugin-react": "^7.31.7",
58
56
  "html-webpack-plugin": "^5.5.0",
59
57
  "img-diff-js": "^0.5.2",
60
- "kokopu": "^2.9.0",
58
+ "kokopu": "^3.0.0",
61
59
  "mocha": "^10.0.0",
62
60
  "null-loader": "^4.0.1",
63
61
  "nyc": "^15.1.0",
64
62
  "react": "^18.2.0",
65
63
  "react-dom": "^18.2.0",
66
- "react-styleguidist": "^11.2.0",
67
- "selenium-webdriver": "^4.2.0",
68
- "ssh2-sftp-client": "^9.0.1",
64
+ "react-styleguidist": "^12.0.0",
65
+ "selenium-webdriver": "^4.3.1",
66
+ "ssh2-sftp-client": "^9.0.3",
69
67
  "style-loader": "^3.3.1",
70
68
  "unit.js": "^2.1.1",
71
- "webpack": "^5.73.0",
69
+ "webpack": "^5.74.0",
72
70
  "webpack-cli": "^4.10.0"
73
71
  },
74
72
  "scripts": {
@@ -2,7 +2,7 @@ version: "3.7"
2
2
 
3
3
  services:
4
4
  web-client:
5
- image: selenium/standalone-firefox:4.2.2-20220622
5
+ image: selenium/standalone-firefox:4.3.0-20220726
6
6
  shm_size: '2gb'
7
7
  ports:
8
8
  - 4444:4444 # http://localhost:4444 (driver)