kokopu-react 2.0.1 → 3.0.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 (136) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/lib/chessboard/Chessboard.d.ts +7 -2
  3. package/dist/lib/chessboard/Chessboard.js +43 -21
  4. package/dist/lib/chessboard/Chessboard.js.map +1 -1
  5. package/dist/lib/chessboard/ChessboardImpl.d.ts +2 -1
  6. package/dist/lib/chessboard/ChessboardImpl.js +9 -3
  7. package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
  8. package/dist/lib/chessboard/Draggable.d.ts +7 -1
  9. package/dist/lib/chessboard/Draggable.js +21 -29
  10. package/dist/lib/chessboard/Draggable.js.map +1 -1
  11. package/dist/lib/chessboard/colorsets.d.ts +4 -0
  12. package/dist/lib/chessboard/colorsets.js +4 -0
  13. package/dist/lib/chessboard/colorsets.js.map +1 -1
  14. package/dist/lib/chessboard/piecesets.d.ts +4 -0
  15. package/dist/lib/chessboard/piecesets.js +4 -0
  16. package/dist/lib/chessboard/piecesets.js.map +1 -1
  17. package/dist/lib/icons/ChessPieceIcon.d.ts +23 -0
  18. package/dist/lib/icons/ChessPieceIcon.js +65 -0
  19. package/dist/lib/icons/ChessPieceIcon.js.map +1 -0
  20. package/dist/lib/index.d.ts +2 -1
  21. package/dist/lib/index.js +2 -1
  22. package/dist/lib/index.js.map +1 -1
  23. package/dist/lib/movetext/Movetext.d.ts +3 -1
  24. package/dist/lib/movetext/Movetext.js.map +1 -1
  25. package/dist/lib/movetext/MovetextImpl.d.ts +3 -1
  26. package/dist/lib/movetext/MovetextImpl.js +15 -14
  27. package/dist/lib/movetext/MovetextImpl.js.map +1 -1
  28. package/dist/lib/sanitization.d.ts +1 -0
  29. package/dist/lib/sanitization.js +11 -0
  30. package/dist/lib/sanitization.js.map +1 -1
  31. package/dist/lib/types.d.ts +11 -1
  32. package/dist/lib/types.js +7 -1
  33. package/dist/lib/types.js.map +1 -1
  34. package/doc_src/demo/PageChessboardBase.tsx +7 -0
  35. package/doc_src/demo/PageChessboardSmallScreens.tsx +10 -3
  36. package/doc_src/demo/PageMovetextBase.tsx +8 -0
  37. package/doc_src/examples/ChessPieceIcon.md +3 -0
  38. package/doc_src/home.md +11 -0
  39. package/doc_src/migrate_to_3.md +51 -0
  40. package/package.json +16 -16
  41. package/scripts/doc.styleguide.config.js +6 -1
  42. package/scripts/docker-compose.yml +1 -1
  43. package/src/chessboard/Chessboard.tsx +56 -23
  44. package/src/chessboard/ChessboardImpl.tsx +10 -3
  45. package/src/chessboard/Draggable.tsx +22 -41
  46. package/src/chessboard/colorsets.ts +6 -0
  47. package/src/chessboard/piecesets.ts +6 -0
  48. package/src/icons/ChessPieceIcon.tsx +99 -0
  49. package/src/index.ts +4 -2
  50. package/src/movetext/Movetext.tsx +3 -1
  51. package/src/movetext/MovetextImpl.tsx +18 -14
  52. package/src/sanitization.ts +13 -0
  53. package/src/types.ts +17 -1
  54. package/test/02_chessboard_util.js +104 -36
  55. package/test/{04_marker_icons_graphic.js → 04_icons_graphic.js} +14 -2
  56. package/test/09_chessboard_small_screens.js +50 -0
  57. package/test/{09_movetext_graphic.js → 10_movetext_graphic.js} +5 -4
  58. package/test/{10_movetext_interaction.js → 11_movetext_interaction.js} +38 -14
  59. package/test/common/graphic.js +9 -0
  60. package/test/graphic_references/04_icons_graphic/chess_piece/customized_pieceset.png +0 -0
  61. package/test/graphic_references/04_icons_graphic/chess_piece/multiple_pieces.png +0 -0
  62. package/test/graphic_references/04_icons_graphic/chess_piece/single_piece.png +0 -0
  63. package/test/graphic_references/04_icons_graphic/marker/invalid_arrow_size.png +0 -0
  64. package/test/graphic_references/04_icons_graphic/marker/invalid_square_size.png +0 -0
  65. package/test/graphic_references/04_icons_graphic/marker/invalid_symbol.png +0 -0
  66. package/test/graphic_references/04_icons_graphic/marker/invalid_text_size.png +0 -0
  67. package/test/graphic_references/05_chessboard_graphic/base/from_fen.png +0 -0
  68. package/test/graphic_references/05_chessboard_graphic/flipped/default.png +0 -0
  69. package/test/graphic_references/06_chessboard_animation/base_1/capture.png +0 -0
  70. package/test/graphic_references/06_chessboard_animation/base_1/promotion.png +0 -0
  71. package/test/graphic_references/06_chessboard_animation/base_2/capture.png +0 -0
  72. package/test/graphic_references/06_chessboard_animation/base_2/promotion.png +0 -0
  73. package/test/graphic_references/06_chessboard_animation/base_3/capture.png +0 -0
  74. package/test/graphic_references/06_chessboard_animation/base_3/promotion.png +0 -0
  75. package/test/graphic_references/09_chessboard_small_screens/base/default.png +0 -0
  76. package/test/graphic_references/09_chessboard_small_screens/base/invalid_limits.png +0 -0
  77. package/test/graphic_references/09_chessboard_small_screens/base/width_690.png +0 -0
  78. package/test/graphic_references/09_chessboard_small_screens/base/width_700.png +0 -0
  79. package/test/graphic_references/09_chessboard_small_screens/base/width_710.png +0 -0
  80. package/test/graphic_references/09_chessboard_small_screens/base/width_720.png +0 -0
  81. package/test/graphic_references/09_chessboard_small_screens/base/width_730.png +0 -0
  82. package/test/graphic_references/09_chessboard_small_screens/base/width_740.png +0 -0
  83. package/test/graphic_references/09_chessboard_small_screens/base/width_750.png +0 -0
  84. package/test/graphic_references/10_movetext_graphic/options/other_diagram_options.png +0 -0
  85. package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +38 -0
  86. package/test/graphic_test_app/05_chessboard_graphic/base.tsx +2 -2
  87. package/test/graphic_test_app/05_chessboard_graphic/flipped.tsx +2 -2
  88. package/test/graphic_test_app/06_chessboard_animation/base_1.tsx +2 -2
  89. package/test/graphic_test_app/06_chessboard_animation/base_2.tsx +2 -2
  90. package/test/graphic_test_app/06_chessboard_animation/base_3.tsx +2 -2
  91. package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +41 -0
  92. package/test/graphic_test_app/{09_movetext_graphic → 10_movetext_graphic}/options.tsx +1 -0
  93. /package/test/graphic_references/{04_marker_icons_graphic/base/invalid_symbol.png → 04_icons_graphic/chess_piece/invalid_multiple_pieces.png} +0 -0
  94. /package/test/graphic_references/{04_marker_icons_graphic/base/invalid_arrow_size.png → 04_icons_graphic/chess_piece/invalid_pieceset.png} +0 -0
  95. /package/test/graphic_references/{04_marker_icons_graphic/base/invalid_text_size.png → 04_icons_graphic/chess_piece/invalid_single_piece.png} +0 -0
  96. /package/test/graphic_references/{04_marker_icons_graphic/base/invalid_square_size.png → 04_icons_graphic/chess_piece/invalid_size.png} +0 -0
  97. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/colorized_arrow.png +0 -0
  98. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/colorized_square.png +0 -0
  99. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/colorized_symbol.png +0 -0
  100. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/colorized_text.png +0 -0
  101. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/default_arrow.png +0 -0
  102. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/default_square.png +0 -0
  103. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/default_text.png +0 -0
  104. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/wrapped_arrow.png +0 -0
  105. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/wrapped_square.png +0 -0
  106. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/wrapped_symbol.png +0 -0
  107. /package/test/graphic_references/{04_marker_icons_graphic/base → 04_icons_graphic/marker}/wrapped_text.png +0 -0
  108. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/base/game_1.png +0 -0
  109. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/base/game_2.png +0 -0
  110. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/base/game_3.png +0 -0
  111. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/base/game_4.png +0 -0
  112. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/pgn_parsing_error_1.png +0 -0
  113. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/pgn_parsing_error_2.png +0 -0
  114. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/wrong_game_index_1.png +0 -0
  115. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/wrong_game_index_2.png +0 -0
  116. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/wrong_game_index_type.png +0 -0
  117. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/error/wrong_game_type.png +0 -0
  118. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/html/filtered_tags_and_attributes.png +0 -0
  119. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/html/html_in_comments.png +0 -0
  120. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/html/html_in_headers.png +0 -0
  121. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/custom_piece_symbols.png +0 -0
  122. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/figurine_piece_symbols_and_diagram_options.png +0 -0
  123. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/hidden_diagrams.png +0 -0
  124. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/localized_piece_symbols.png +0 -0
  125. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/wrong_diagram_options_1.png +0 -0
  126. /package/test/graphic_references/{09_movetext_graphic → 10_movetext_graphic}/options/wrong_diagram_options_2.png +0 -0
  127. /package/test/graphic_references/{10_movetext_interaction → 11_movetext_interaction}/error/wrong_interaction_mode.png +0 -0
  128. /package/test/graphic_references/{10_movetext_interaction → 11_movetext_interaction}/select_moves/click_on_disabled.png +0 -0
  129. /package/test/graphic_references/{10_movetext_interaction → 11_movetext_interaction}/select_moves/click_on_unselected.png +0 -0
  130. /package/test/graphic_references/{10_movetext_interaction → 11_movetext_interaction}/select_moves/click_on_with_variations.png +0 -0
  131. /package/test/graphic_test_app/{04_marker_icons_graphic/base.tsx → 04_icons_graphic/marker.tsx} +0 -0
  132. /package/test/graphic_test_app/{09_movetext_graphic → 10_movetext_graphic}/base.tsx +0 -0
  133. /package/test/graphic_test_app/{09_movetext_graphic → 10_movetext_graphic}/error.tsx +0 -0
  134. /package/test/graphic_test_app/{09_movetext_graphic → 10_movetext_graphic}/html.tsx +0 -0
  135. /package/test/graphic_test_app/{10_movetext_interaction → 11_movetext_interaction}/error.tsx +0 -0
  136. /package/test/graphic_test_app/{10_movetext_interaction → 11_movetext_interaction}/select_moves.tsx +0 -0
@@ -27,9 +27,9 @@ import { Chessboard } from '../../../dist/lib/index';
27
27
 
28
28
  testApp([ /* eslint-disable react/jsx-key */
29
29
  <Chessboard />,
30
- <Chessboard position="empty" />,
30
+ <Chessboard position="empty" turnVisible={true} />,
31
31
  <Chessboard position="something invalid" />,
32
- <Chessboard position="r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3" />,
32
+ <Chessboard position="r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3" turnVisible={false} />,
33
33
  <Chessboard position={new Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
34
34
  <Chessboard position={ /* eslint-disable @typescript-eslint/no-explicit-any */ 42 as any /* eslint-enable @typescript-eslint/no-explicit-any */ } />,
35
35
  ]); /* eslint-enable react/jsx-key */
@@ -26,9 +26,9 @@ import { testApp } from '../common/test_app';
26
26
  import { Chessboard } from '../../../dist/lib/index';
27
27
 
28
28
  testApp([ /* eslint-disable react/jsx-key */
29
- <Chessboard flipped={true} />,
29
+ <Chessboard flipped={true} turnVisible={false} />,
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 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')} turnVisible={true} />,
34
34
  ]); /* eslint-enable react/jsx-key */
@@ -29,8 +29,8 @@ window['__kokopu_debug_freeze_motion'] = 0.09;
29
29
  testApp([ /* eslint-disable react/jsx-key */
30
30
  <Chessboard move="e4" animated={true} />,
31
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 />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped turnVisible={false} />,
33
33
  <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
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} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} turnVisible={false} />,
36
36
  ]); /* eslint-enable react/jsx-key */
@@ -29,8 +29,8 @@ window['__kokopu_debug_freeze_motion'] = 0.7;
29
29
  testApp([ /* eslint-disable react/jsx-key */
30
30
  <Chessboard move="e4" animated={true} />,
31
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 />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped turnVisible={false} />,
33
33
  <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
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} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} turnVisible={false} />,
36
36
  ]); /* eslint-enable react/jsx-key */
@@ -29,8 +29,8 @@ window['__kokopu_debug_freeze_motion'] = 0.91;
29
29
  testApp([ /* eslint-disable react/jsx-key */
30
30
  <Chessboard move="e4" animated={true} />,
31
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 />,
32
+ <Chessboard position="r1bqkbnr/pppppppp/n7/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 1 2" move="Bxa6" animated={true} flipped turnVisible={false} />,
33
33
  <Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={true} />,
34
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} />,
35
+ <Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={true} turnVisible={false} />,
36
36
  ]); /* eslint-enable react/jsx-key */
@@ -0,0 +1,41 @@
1
+ /* -------------------------------------------------------------------------- *
2
+ * *
3
+ * This file is part of Kokopu-React, a JavaScript chess library. *
4
+ * Copyright (C) 2021-2023 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 * as React from 'react';
24
+ import { testApp } from '../common/test_app';
25
+ import { Chessboard } from '../../../dist/lib/index';
26
+
27
+ // WARNING: avoid window width < 600 (the selenium-controlled window has some issues in this case).
28
+ const limits = [
29
+ { width: 690, squareSize: 16 },
30
+ { width: 700, turnVisible: false },
31
+ { width: 710, squareSize: 24, coordinateVisible: false },
32
+ { width: 720, squareSize: 44 },
33
+ { width: 730, squareSize: 48, coordinateVisible: true },
34
+ { width: 740, squareSize: 24, coordinateVisible: false },
35
+ { width: 750, squareSize: 32 },
36
+ ];
37
+
38
+ testApp([ /* eslint-disable react/jsx-key */
39
+ <Chessboard squareSize={50} smallScreenLimits={limits} />,
40
+ <Chessboard smallScreenLimits={ /* eslint-disable @typescript-eslint/no-explicit-any */ 42 as any /* eslint-enable @typescript-eslint/no-explicit-any */ } />,
41
+ ]); /* eslint-enable react/jsx-key */
@@ -34,6 +34,7 @@ testApp([ /* eslint-disable react/jsx-key */
34
34
  <Movetext game={pgn} gameIndex={2} pieceSymbols={{ K: 'Ki_', Q: 'Qu_', R: 'Rk_', B: 'Bi_', N: 'Kn_', P: 'Pw_' }} />,
35
35
  <Movetext game={pgn} gameIndex={3} pieceSymbols="figurines" headerVisible={false}
36
36
  diagramOptions={{ flipped: true, coordinateVisible: false, squareSize: 32, colorset: 'scid', pieceset: 'eyes' }} />,
37
+ <Movetext game={pgn} gameIndex={3} diagramOptions={{ turnVisible: false, squareSize: 32 }} />,
37
38
  <Movetext game={pgn} gameIndex={9} diagramVisible={false} />,
38
39
  <Movetext game={pgn} gameIndex={3} diagramOptions={ /* eslint-disable @typescript-eslint/no-explicit-any */ null as any /* eslint-enable @typescript-eslint/no-explicit-any */ } />,
39
40
  <Movetext game={pgn} gameIndex={3}