kokopu-react 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/lib/ArrowMarkerIcon.js +5 -7
  4. package/dist/lib/Chessboard.js +23 -33
  5. package/dist/lib/ErrorBox.js +85 -5
  6. package/dist/lib/Movetext.js +839 -0
  7. package/dist/lib/SquareMarkerIcon.js +1 -1
  8. package/dist/lib/TextMarkerIcon.js +12 -11
  9. package/dist/lib/css/arrow.css +1 -1
  10. package/dist/lib/css/chessboard.css +6 -1
  11. package/dist/lib/css/error_box.css +13 -2
  12. package/dist/lib/css/fonts.css +34 -0
  13. package/dist/lib/css/movetext.css +117 -0
  14. package/dist/lib/css/{label.css → symbol.css} +6 -2
  15. package/dist/lib/fonts/chessalpha.woff +0 -0
  16. package/dist/lib/fonts/chessalpha.woff2 +0 -0
  17. package/dist/lib/i18n.js +17 -2
  18. package/dist/lib/impl/ArrowTip.js +3 -8
  19. package/dist/lib/impl/HtmlSanitizer.js +171 -0
  20. package/dist/lib/impl/TextSymbol.js +98 -0
  21. package/dist/lib/impl/colorsets.js +1 -1
  22. package/dist/lib/impl/piecesets.js +1 -1
  23. package/dist/lib/impl/util.js +6 -6
  24. package/dist/lib/index.js +32 -24
  25. package/dist/lib/markers.js +10 -10
  26. package/doc_src/demo/PageChessboardBase.js +1 -1
  27. package/doc_src/demo/{PageChessboardEdition.js → PageChessboardInteraction.js} +4 -5
  28. package/doc_src/demo/PageChessboardMove.js +1 -1
  29. package/doc_src/demo/PageChessboardSmallScreens.js +1 -1
  30. package/doc_src/demo/PageMovetextBase.js +214 -0
  31. package/doc_src/demo/PageMovetextInteraction.js +155 -0
  32. package/doc_src/demo/demo.css +8 -1
  33. package/doc_src/demo/game-1.pgn +23 -0
  34. package/doc_src/demo/game-2.pgn +22 -0
  35. package/doc_src/demo/game-invalid.pgn +10 -0
  36. package/doc_src/demo/util.js +1 -1
  37. package/doc_src/examples/Movetext.md +15 -0
  38. package/doc_src/home.md +2 -0
  39. package/doc_src/theming/LogoRenderer.js +1 -1
  40. package/doc_src/theming/kokopu-react-favicon.png +0 -0
  41. package/doc_src/theming/theming.css +1 -1
  42. package/graphic_test_app/01_marker_icons.js +6 -4
  43. package/graphic_test_app/02_chessboard_simple.js +1 -1
  44. package/graphic_test_app/03_chessboard_flipped.js +1 -1
  45. package/graphic_test_app/04_chessboard_annotations.js +2 -2
  46. package/graphic_test_app/05_chessboard_move.js +1 -1
  47. package/graphic_test_app/06_chessboard_theme.js +1 -1
  48. package/graphic_test_app/07_chessboard_click_squares.js +1 -1
  49. package/graphic_test_app/08_chessboard_move_pieces.js +1 -1
  50. package/graphic_test_app/09_chessboard_edit_arrows.js +1 -1
  51. package/graphic_test_app/10_chessboard_play_moves.js +1 -1
  52. package/graphic_test_app/11_chessboard_play_promotions.js +1 -1
  53. package/graphic_test_app/12_movetext_simple.js +41 -0
  54. package/graphic_test_app/13_movetext_error.js +38 -0
  55. package/graphic_test_app/14_movetext_html.js +40 -0
  56. package/graphic_test_app/15_movetext_options.js +42 -0
  57. package/graphic_test_app/16_movetext_interaction.js +42 -0
  58. package/graphic_test_app/common/dummy.pgn +8 -0
  59. package/graphic_test_app/common/games.pgn +167 -0
  60. package/graphic_test_app/common/heartbeat.txt +1 -0
  61. package/graphic_test_app/common/test_app.css +20 -4
  62. package/graphic_test_app/common/test_app.js +6 -6
  63. package/package.json +26 -25
  64. package/scripts/test_graphic/clean-graphic-output.js +1 -1
  65. package/scripts/test_graphic/docker-compose.yml +1 -1
  66. package/scripts/test_graphic/webpack-config.js +8 -3
  67. package/scripts/test_headless.webpack-config.js +3 -2
  68. package/src/ArrowMarkerIcon.js +2 -2
  69. package/src/Chessboard.js +11 -11
  70. package/src/ErrorBox.js +80 -1
  71. package/src/Movetext.js +616 -0
  72. package/src/SquareMarkerIcon.js +1 -1
  73. package/src/TextMarkerIcon.js +7 -7
  74. package/src/css/arrow.css +1 -1
  75. package/src/css/chessboard.css +6 -1
  76. package/src/css/error_box.css +13 -2
  77. package/src/css/fonts.css +34 -0
  78. package/src/css/movetext.css +117 -0
  79. package/src/css/{label.css → symbol.css} +6 -2
  80. package/src/fonts/chessalpha.woff +0 -0
  81. package/src/fonts/chessalpha.woff2 +0 -0
  82. package/src/i18n.js +12 -1
  83. package/src/impl/ArrowTip.js +3 -7
  84. package/src/impl/HtmlSanitizer.js +120 -0
  85. package/src/impl/TextSymbol.js +76 -0
  86. package/src/impl/colorsets.js +1 -1
  87. package/src/impl/piecesets.js +1 -1
  88. package/src/impl/util.js +2 -2
  89. package/src/index.js +2 -1
  90. package/src/markers.js +8 -7
  91. package/test/1_markers.js +20 -1
  92. package/test/2_chessboard_util.js +1 -1
  93. package/test/3_marker_icons_graphic.js +2 -2
  94. package/test/4_chessboard_graphic.js +1 -1
  95. package/test/5_chessboard_interaction.js +1 -1
  96. package/test/6_chessboard_play_moves.js +1 -1
  97. package/test/7_movetext_graphic.js +43 -0
  98. package/test/8_movetext_interaction.js +99 -0
  99. package/test/common/graphic.js +2 -2
  100. package/test/references/01_marker_icons/10.png +0 -0
  101. package/test/references/01_marker_icons/9.png +0 -0
  102. package/test/references/04_chessboard_annotations/4.png +0 -0
  103. package/test/references/04_chessboard_annotations/5.png +0 -0
  104. package/test/references/05_chessboard_move/3.png +0 -0
  105. package/test/references/12_movetext_simple/0.png +0 -0
  106. package/test/references/12_movetext_simple/1.png +0 -0
  107. package/test/references/12_movetext_simple/2.png +0 -0
  108. package/test/references/12_movetext_simple/3.png +0 -0
  109. package/test/references/13_movetext_error/0.png +0 -0
  110. package/test/references/13_movetext_error/1.png +0 -0
  111. package/test/references/13_movetext_error/2.png +0 -0
  112. package/test/references/13_movetext_error/3.png +0 -0
  113. package/test/references/14_movetext_html/0.png +0 -0
  114. package/test/references/14_movetext_html/1.png +0 -0
  115. package/test/references/14_movetext_html/2.png +0 -0
  116. package/test/references/15_movetext_options/0.png +0 -0
  117. package/test/references/15_movetext_options/1.png +0 -0
  118. package/test/references/15_movetext_options/2.png +0 -0
  119. package/test/references/15_movetext_options/3.png +0 -0
  120. package/test/references/16_movetext_interaction/0.png +0 -0
  121. package/test/references/16_movetext_interaction/1.png +0 -0
  122. package/test/references/16_movetext_interaction/2.png +0 -0
  123. package/graphic_test_app/common/healthcheck.txt +0 -1
@@ -0,0 +1,23 @@
1
+ [Event "1<sup>st</sup> American Chess Congress"]
2
+ [Site "?"]
3
+ [Date "1857.11.03"]
4
+ [Round "4.6"]
5
+ [White "Paulsen, Louis"]
6
+ [Black "Morphy, Paul"]
7
+ [Result "0-1"]
8
+
9
+ 1. e4 e5 2. Nf3 Nc6 3. Nc3 Nf6 4. Bb5 Bc5 5. O-O O-O 6. Nxe5 Re8 7. Nxc6 dxc6
10
+ 8. Bc4 b5 9. Be2 Nxe4 10. Nxe4 Rxe4 11. Bf3 Re6 12. c3 Qd3 13. b4 Bb6 14. a4 bxa4
11
+ 15. Qxa4 Bd7 16. Ra2 Rae8 17. Qa6
12
+
13
+ {[#] Morphy took twelve minutes over his next move, probably to assure himself
14
+ that the combination was sound and that he had a forced win in every variation.}
15
+
16
+ 17... Qxf3 !! 18. gxf3 Rg6+ 19. Kh1 Bh3 20. Rd1
17
+ ({Not} 20. Rg1 Rxg1+ 21. Kxg1 Re1+ -+)
18
+ 20... Bg2+ 21. Kg1 Bxf3+ 22. Kf1 Bg2+
19
+
20
+ (22...Rg2 ! {would have won more quickly. For instance:} 23. Qd3 Rxf2+ 24. Kg1 Rg2+ 25. Kh1 Rg1#)
21
+
22
+ 23. Kg1 Bh3+ 24. Kh1 Bxf2 25. Qf1 {Absolutely forced.} 25... Bxf1 26. Rxf1 Re2
23
+ 27. Ra1 Rh6 28. d4 Be3 0-1
@@ -0,0 +1,22 @@
1
+ [Event "Checkmate with Bishop + Knight"]
2
+ [Site "?"]
3
+ [Date "????.??.??"]
4
+ [Round "?"]
5
+ [White "?"]
6
+ [Black "?"]
7
+ [Result "*"]
8
+ [FEN "1k6/2N5/2K5/8/8/8/5B2/8 w - - 0 1"]
9
+
10
+ {[#][%cal Gc6g6,Rc7d5,Rd5e7,Re7f5,Rf5g7] How to checkmate in this situation?
11
+ The key point is to remember that the knight follows a W-shaped path between
12
+ ranks 5 and 7, while the white king stays on rank 6.}
13
+
14
+ 1.Be3 Kc8 2.Ba7 Kd8 3.Nd5 Ke8 4.Kd6 Kf7 5.Ne7 Kf6 6.Be3
15
+
16
+ {The black king is trapped behind the squares controlled by the white pieces.
17
+ [#][%csl Re5,Rf5,Rg5,Rg6,Rh6]}
18
+
19
+ 6...Kf7 7.Bd4 Ke8 8.Ke6 Kd8 9.Bb6+ Ke8 10.Nf5 Kf8 11.Ba5 Ke8 12.Ng7+ Kf8
20
+ 13.Kf6 Kg8 14.Kg6 Kf8 15.Bb4+ Kg8 +-
21
+
22
+ {[#] ... and checkmate in four moves.} *
@@ -0,0 +1,10 @@
1
+ [Event "Scholar's mate"]
2
+ [Site "?"]
3
+ [Date "????.??.??"]
4
+ [Round "?"]
5
+ [White "?"]
6
+ [Black "?"]
7
+ [Result "1-0"]
8
+
9
+ 1.e4 e5 2.Bc3 Nc6 3.Qh5 Nf6 4.Qxf7# 1-0
10
+
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -0,0 +1,15 @@
1
+ ```js
2
+ let pgn = `
3
+ [Event "Television Exhibition"]
4
+ [Site "London ENG"]
5
+ [Date "2014.01.23"]
6
+ [Round "?"]
7
+ [White "Bill Gates"]
8
+ [Black "Magnus Carlsen"]
9
+ [Result "0-1"]
10
+
11
+ 1.e4 Nc6 2.Nf3 d5 3.Bd3 Nf6 4.exd5 Qxd5 5.Nc3 Qh5 6.O-O Bg4
12
+ 7.h3 Ne5 8.hxg4 Nfxg4 {[#]} 9.Nxe5 Qh2# 0-1`;
13
+
14
+ <Movetext game={pgn} pieceSymbols="figurines" />
15
+ ```
package/doc_src/home.md CHANGED
@@ -21,6 +21,8 @@ Main components
21
21
 
22
22
  - [Chessboard](#/Components/Chessboard): SVG image representing a chessboard diagram. Optionally, the user may interact with the board
23
23
  (move pieces, click on squares...). Annotations such as square markers or arrows can also be added to the board.
24
+ - [Movetext](#/Components/Movetext): represents a chess game, i.e. the headers (name of the players, event, etc.), the moves,
25
+ and all the related annotations if any (comments, variations, NAGs...).
24
26
 
25
27
 
26
28
 
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -27,11 +27,13 @@ import { SquareMarkerIcon, TextMarkerIcon, ArrowMarkerIcon } from '../src/index'
27
27
  testApp([ /* eslint-disable react/jsx-key */
28
28
  <SquareMarkerIcon size={40} />,
29
29
  <SquareMarkerIcon size={45} color="green" />,
30
- <div style={{ color: 'purple' }} ><SquareMarkerIcon size={31} /></div>,
30
+ <div style={{ color: 'purple' }}><SquareMarkerIcon size={31} /></div>,
31
31
  <TextMarkerIcon size={41} symbol="A" />,
32
32
  <TextMarkerIcon size={29} symbol="b" color="#0ff" />,
33
- <div style={{ color: 'red' }} ><TextMarkerIcon size={53} symbol="5" /></div>,
33
+ <div style={{ color: 'red' }}><TextMarkerIcon size={53} symbol="5" /></div>,
34
34
  <ArrowMarkerIcon size={40} />,
35
35
  <ArrowMarkerIcon size={24} color="#888" />,
36
- <div style={{ color: '#f70' }} ><ArrowMarkerIcon size={48} /></div>,
36
+ <div style={{ color: '#f70' }}><ArrowMarkerIcon size={48} /></div>,
37
+ <TextMarkerIcon size={47} symbol="dot" color="#00f" />,
38
+ <div style={{ color: 'pink' }}><TextMarkerIcon size={48} symbol="circle" /></div>,
37
39
  ]); /* eslint-enable react/jsx-key */
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -34,7 +34,7 @@ let textMarkers2 = { g3: { symbol: 'H', color: 'r' }, g5: { symbol: 'M', color:
34
34
 
35
35
  let squareMarkers3 = { b5: 'r', e4: 'g', h5: 'y' };
36
36
  let arrowMarkers3 = { d1h5: 'g', a5f4: 'r', c7c3: 'y', g7g7: 'g' };
37
- let textMarkers3 = 'G5c6';
37
+ let textMarkers3 = 'G5c6,R(plus)a1,G(times)b1,R(dot)a2,Y(circle)b2';
38
38
 
39
39
  testApp([ /* eslint-disable react/jsx-key */
40
40
  <Chessboard squareMarkers={squareMarkers1} arrowMarkers={arrowMarkers1} textMarkers={textMarkers1} flipped={false} coordinateVisible={true} />,
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -1,7 +1,7 @@
1
1
  /******************************************************************************
2
2
  * *
3
3
  * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
4
+ * Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
5
5
  * *
6
6
  * This program is free software: you can redistribute it and/or *
7
7
  * modify it under the terms of the GNU Lesser General Public License *
@@ -0,0 +1,41 @@
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 kokopu from 'kokopu';
25
+ import testApp from './common/test_app';
26
+ import { Movetext } from '../src/index';
27
+
28
+ import pgn from './common/games.pgn';
29
+
30
+ let game = new kokopu.Game();
31
+ game.mainVariation().play('e4').play('e5').play('Bc4').play('Nc6').play('Qh5').play('Nf6').play('Qxf7#');
32
+ game.result('1-0');
33
+
34
+ let database = kokopu.pgnRead(pgn);
35
+
36
+ testApp([ /* eslint-disable react/jsx-key */
37
+ <Movetext game={game} />,
38
+ <Movetext game={database} />,
39
+ <Movetext game={pgn} gameIndex={1} />,
40
+ <Movetext game={database} gameIndex={3} />,
41
+ ], 'width-600'); /* eslint-enable react/jsx-key */
@@ -0,0 +1,38 @@
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 kokopu from 'kokopu';
25
+ import testApp from './common/test_app';
26
+ import { Movetext } from '../src/index';
27
+
28
+ import pgn from './common/games.pgn';
29
+ import dummyPgn from './common/dummy.pgn';
30
+
31
+ let database = kokopu.pgnRead(pgn);
32
+
33
+ testApp([ /* eslint-disable react/jsx-key */
34
+ <Movetext game={database} gameIndex={99} />,
35
+ <Movetext game={dummyPgn} />,
36
+ <Movetext game={kokopu.pgnRead(dummyPgn)} gameIndex={1} />,
37
+ <Movetext game={42} />,
38
+ ], 'width-600'); /* eslint-enable react/jsx-key */
@@ -0,0 +1,40 @@
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 { Movetext } from '../src/index';
26
+
27
+ import pgn from './common/games.pgn';
28
+
29
+ testApp([ /* eslint-disable react/jsx-key */
30
+ <Movetext game={pgn} gameIndex={4} />,
31
+ <Movetext game={pgn} gameIndex={5} />,
32
+ <Movetext game={pgn} gameIndex={6} />,
33
+ ], 'width-600'); /* eslint-enable react/jsx-key */
34
+
35
+ let customCSS = document.createElement('style');
36
+ customCSS.innerText = `
37
+ .myClass { font-weight: bold; color: green; }
38
+ #myId { font-weight: bold; color: red; }
39
+ `;
40
+ document.head.appendChild(customCSS);
@@ -0,0 +1,42 @@
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 { Movetext, i18n } from '../src/index';
26
+
27
+ import pgn from './common/games.pgn';
28
+
29
+ let legacyPieceSymbols = i18n.PIECE_SYMBOLS;
30
+
31
+ // Localization for French
32
+ i18n.PIECE_SYMBOLS = { K: 'R', Q: 'D', R: 'T', B: 'F', N: 'C', P: 'P' };
33
+
34
+ testApp([ /* eslint-disable react/jsx-key */
35
+ <Movetext game={pgn} pieceSymbols="localized" />,
36
+ <Movetext game={pgn} gameIndex={2} pieceSymbols={{ K: 'Ki_', Q: 'Qu_', R: 'Rk_', B: 'Bi_', N: 'Kn_', P: 'Pw_' }} />,
37
+ <Movetext game={pgn} gameIndex={3} pieceSymbols="figurines" headerVisible={false}
38
+ diagramOptions={{ flipped: true, coordinateVisible: false, squareSize: 32, colorset: 'scid', pieceset: 'eyes' }} />,
39
+ <Movetext game={pgn} gameIndex={9} diagramVisible={false} />,
40
+ ], 'width-600'); /* eslint-enable react/jsx-key */
41
+
42
+ i18n.PIECE_SYMBOLS = legacyPieceSymbols;
@@ -0,0 +1,42 @@
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, { setSandbox } from './common/test_app';
25
+ import { Movetext } from '../src/index';
26
+
27
+ import pgn from './common/games.pgn';
28
+
29
+ function onMoveSelected(nodeId) {
30
+ setSandbox(`move selected: ${nodeId}`);
31
+ }
32
+
33
+ testApp([ /* eslint-disable react/jsx-key */
34
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} selection="4w" />,
35
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" />,
36
+ <Movetext game={pgn} gameIndex={8} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="1b-v0-3w-v0-3w" />,
37
+ <Movetext game={pgn} gameIndex={8} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="1b-v0-2b" />,
38
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="start" />,
39
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="1w" />,
40
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="6b" />,
41
+ <Movetext game={pgn} gameIndex={7} headerVisible={false} onMoveSelected={onMoveSelected} interactionMode="selectMove" selection="invalid-id" />,
42
+ ], 'width-600'); /* eslint-enable react/jsx-key */
@@ -0,0 +1,8 @@
1
+ [Event "Game with error 1"]
2
+
3
+ 1.e4 e5 2.Nf3 d6 3.Bb5+ Nf6 *
4
+
5
+
6
+ [Event "Game with error 2"]
7
+
8
+ xyz 1.e4 Nc6 2.Nf3 d5 3.Bd3 Nf6 4.exd5 Qxd5 5.Nc3 Qh5 6.O-O Bg4 7.h3 Ne5 8.hxg4 Nfxg4 9.Nxe5 Qh2# 0-1
@@ -0,0 +1,167 @@
1
+ [Event "Linares 16<sup>th</sup>"]
2
+ [Site "Linares, ESP"]
3
+ [Date "1999.02.25"]
4
+ [Round "4"]
5
+ [White "Kasparov, Garry"]
6
+ [Black "Kramnik, Vladimir"]
7
+ [Result "1/2-1/2"]
8
+ [WhiteElo "2812"]
9
+ [BlackElo "2751"]
10
+ [WhiteTitle "WCH"]
11
+ [BlackTitle "GM"]
12
+
13
+ 1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. Qc2 d5 5. cxd5 Qxd5 6. Nf3 Qf5 7. Qxf5 exf5
14
+ 8. a3 Be7 9. Bg5 Be6 10. e3 c6 11. Bd3 Nbd7 12. O-O h6 13. Bh4 a5 14. Rac1 O-O
15
+ 15. Ne2 g5 16. Bg3 Ne4 17. Nc3 Nxc3 18. Rxc3 Nf6 19. Rcc1 Rfd8 20. Rfd1 Rac8
16
+ 1/2-1/2
17
+
18
+
19
+
20
+ [Event "1<sup>st</sup> American Chess Congress"]
21
+ [Site "?"]
22
+ [Date "1857.11.??"]
23
+ [Round "4.6"]
24
+ [White "Paulsen, Louis"]
25
+ [Black "Morphy, Paul"]
26
+ [Result "0-1"]
27
+ [Annotator "Unknown"]
28
+
29
+ 1. e4 e5 2. Nf3 Nc6 3. Nc3 Nf6 4. Bb5 Bc5 5. O-O O-O 6. Nxe5 Re8 $99 7. Nxc6 dxc6
30
+ 8. Bc4 b5 9. Be2 Nxe4 10. Nxe4 Rxe4 11. Bf3 Re6 12. c3 Qd3 13. b4 Bb6 14. a4 bxa4
31
+ 15. Qxa4 Bd7 16. Ra2 Rae8 17. Qa6
32
+
33
+ {[#] [%cal Rd3f3,Re6g6][%csl Gg6][%ctl G(circle)f3] Morphy took twelve minutes over his next move,
34
+ probably to assure himself that the combination was sound and that he had a forced win in every variation.}
35
+
36
+ 17... Qxf3 $3 18. gxf3 Rg6+ 19. Kh1 Bh3 20. Rd1
37
+ ({Not} 20. Rg1 Rxg1+ 21. Kxg1 Re1+ $19)
38
+ 20... Bg2+ 21. Kg1 Bxf3+ 22. Kf1 Bg2+
39
+
40
+ (22...Rg2 $1 {would have won more quickly. For instance:} 23. Qd3 Rxf2+ 24. Kg1 Rg2+ 25. Kh1 Rg1#)
41
+
42
+ 23. Kg1 Bh3+ 24. Kh1 Bxf2 25. Qf1 {Absolutely forced.} 25... Bxf1 26. Rxf1 Re2
43
+ 27. Ra1 Rh6 28. d4 Be3 0-1
44
+
45
+
46
+
47
+ [Event "Sample game"]
48
+ [Site "?"]
49
+ [Date "????.??.??"]
50
+ [Round "?"]
51
+ [White "Player 1"]
52
+ [Black "Player 2"]
53
+ [Result "1-0"]
54
+ [WhiteElo "2007"]
55
+ [BlackTitle "IM"]
56
+
57
+ 1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6 4. Qxf7# 1-0
58
+
59
+
60
+
61
+ [Event "Casual Horde game"]
62
+ [Site "lichess"]
63
+ [Date "????.??.??"]
64
+ [Round "?"]
65
+ [White "?"]
66
+ [Black "?"]
67
+ [Result "*"]
68
+ [Variant "Horde"]
69
+
70
+ {Starting position at Horde: [#]}
71
+
72
+ 1. e5 c6 2. d5 cxb5 3. axb5 b6 4. d4 a5 5. c6 e6 6. e4 dxc6 7. bxc6 axb4 8. axb4 b5 9. d3 exd5
73
+ 10. cxd5 Ne7 11. f6 gxf6 12. gxf6 Nxd5 13. exd5 Qxd5 14. e4 Qxc6 15. d2 Bxb4 16. d5 Qc7
74
+ 17. d4 Rxa2 18. bxa2 Qa7 19. a3 Bxa3 20. f5 Bf8 21. a3 Bxa3 22. bxa3 Qxa3 23. e6 Qxc1 24. e5 Qxc2
75
+ 25. exf7+ Kxf7 26. e6+ Kxf6 27. g5+ Kxf5 28. g4+ Kg6 29. f4 Qxb3 30. f5+ Kg7 31. f6+ Kg6 32. f4 Bxe6
76
+ 33. dxe6 Qxe6 34. f5+ Qxf5 35. gxf5+ Kxf5 36. e3 Nd7 37. f3 Nxf6 38. g4+ Kg6 39. gxf6 Kxf6
77
+ 40. g3 Ra8 41. f4 Ra2 42. e4 Rxd2 43. e5+ Ke7 44. f5 Rd3 45. g5 Rxc3 46. f6+ Kf7 47. d5 Re3
78
+ 48. e6+ Rxe6 49. dxe6+ Kxe6 50. h5 b4 51. h4 b3 52. g4 b2 53. g6 hxg6 54. h6 Kxf6 55. h5 b1=Q
79
+ 56. g5+ Kxg5 57. hxg6 Kxh6 58. g7 Kxg7 *
80
+
81
+
82
+
83
+ [Event "HTML in <b>all</b> headers"]
84
+ [Site "Maybe on <a href=\"https://www.wikipedia.org/\">Wikipedia</a>, maybe somewhere else..."]
85
+ [Date "????.??.??"]
86
+ [Round "<strong>3</strong>.2"]
87
+ [White "1<sup>st</sup> <em>player</em>"]
88
+ [Black "2<sub>nd</sub> <em>player</em>"]
89
+ [Result "*"]
90
+ [WhiteElo "<ins>2800</ins>"]
91
+ [BlackElo "<del>1010</del>"]
92
+ [WhiteTitle "<span class=\"myClass\">GM</span>"]
93
+ [BlackTitle "<span id=\"myId\">no-GM</span>"]
94
+
95
+ *
96
+
97
+
98
+
99
+ [Event "HTML in comments"]
100
+ [Site "?"]
101
+ [Date "????.??.??"]
102
+ [Round "?"]
103
+ [White "?"]
104
+ [Black "?"]
105
+ [Result "*"]
106
+
107
+ {I'm a <strong><ins>comment</ins></strong> with some <em class="myClass">HTML content</em> in it.}
108
+
109
+ *
110
+
111
+
112
+
113
+ [Event "Forbidden HTML tags and attributes"]
114
+ [Site "?"]
115
+ [Date "????.??.??"]
116
+ [Round "?"]
117
+ [White "?"]
118
+ [Black "?"]
119
+ [Result "*"]
120
+
121
+ {
122
+ Using <div class="myClass">div tags</div> is not allowed.
123
+ ... but <div class="myClass"><em>legit HTML elements</em> within forbidden HTML tags</div> are rendered.
124
+ Using <span style="color: cyan;">style attributes</span> is not allowed.
125
+ Using scripts is not allowed. <script>alert('You should not see this either.');</script>
126
+ }
127
+
128
+ *
129
+
130
+
131
+
132
+ [Event "Short game"]
133
+ [Site "?"]
134
+ [Date "????.??.??"]
135
+ [Round "?"]
136
+ [White "?"]
137
+ [Black "?"]
138
+ [Result "*"]
139
+
140
+ 1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. Qc2 d5 5. cxd5 Qxd5 6. Nf3 Qf5 *
141
+
142
+
143
+
144
+ [Event "Short game with variations"]
145
+ [Site "?"]
146
+ [Date "????.??.??"]
147
+ [Round "?"]
148
+ [White "?"]
149
+ [Black "?"]
150
+ [Result "*"]
151
+
152
+ 1. e4 e6 (1... e5 2. Nf3 Nc6 3. Nc3 (3. Bb5 ! a6 4. Ba4)) 2. d4 *
153
+
154
+
155
+
156
+ [Event "Game with several diagrams"]
157
+ [Site "?"]
158
+ [Date "????.??.??"]
159
+ [Round "?"]
160
+ [White "?"]
161
+ [Black "?"]
162
+ [Result "*"]
163
+
164
+ {[#]}
165
+
166
+ 1. e4 {A diagram is here. [#] But it should not be visible in the test-case.}
167
+ 1... e5 2. d4 {[#]} 2... d5 *
@@ -0,0 +1 @@
1
+ I'm OK...