kokopu-react 1.0.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nycrc.yml +13 -0
- package/CHANGELOG.md +18 -0
- package/README.md +3 -0
- package/dist/lib/ArrowMarkerIcon.js +1 -1
- package/dist/lib/Chessboard.js +267 -89
- package/dist/lib/{impl/ErrorBox.js → ErrorBox.js} +6 -7
- package/dist/lib/css/chessboard.css +4 -0
- package/dist/lib/i18n.js +35 -0
- package/dist/lib/index.js +16 -0
- package/doc_src/{demo/.eslintrc.yml → .eslintrc.yml} +0 -0
- package/doc_src/demo/PageChessboardBase.js +35 -40
- package/doc_src/demo/PageChessboardEdition.js +70 -70
- package/doc_src/demo/PageChessboardMove.js +20 -27
- package/doc_src/demo/PageChessboardSmallScreens.js +15 -16
- package/doc_src/examples/ErrorBox.md +3 -0
- package/doc_src/theming/LogoRenderer.js +50 -0
- package/doc_src/theming/kokopu-react-logo.png +0 -0
- package/doc_src/theming/theming.css +29 -0
- package/graphic_test_app/02_chessboard_simple.js +1 -0
- package/graphic_test_app/04_chessboard_annotations.js +1 -1
- package/graphic_test_app/05_chessboard_move.js +1 -0
- package/graphic_test_app/07_chessboard_click_squares.js +36 -0
- package/graphic_test_app/08_chessboard_move_pieces.js +36 -0
- package/graphic_test_app/09_chessboard_edit_arrows.js +36 -0
- package/graphic_test_app/10_chessboard_play_moves.js +39 -0
- package/graphic_test_app/11_chessboard_play_promotions.js +35 -0
- package/graphic_test_app/common/test_app.js +14 -0
- package/graphics/logo-small.svg +14 -0
- package/graphics/logo.svg +26 -0
- package/package.json +26 -20
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +6 -1
- package/scripts/test_headless.webpack-config.js +6 -1
- package/src/Chessboard.js +156 -40
- package/src/{impl/ErrorBox.js → ErrorBox.js} +4 -5
- package/src/css/chessboard.css +4 -0
- package/src/i18n.js +30 -0
- package/src/index.js +2 -0
- package/test/4_chessboard_graphic.js +2 -2
- package/test/5_chessboard_interaction.js +135 -0
- package/test/6_chessboard_play_moves.js +107 -0
- package/test/common/graphic.js +75 -15
- package/test/references/02_chessboard_simple/2.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/03_chessboard_flipped/2.png +0 -0
- package/test/references/05_chessboard_move/8.png +0 -0
- package/test/references/08_chessboard_move_pieces/after_move.png +0 -0
- package/test/references/08_chessboard_move_pieces/empty_square.png +0 -0
- package/test/references/08_chessboard_move_pieces/null_vector.png +0 -0
- package/test/references/08_chessboard_move_pieces/out_of_board.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_arrow_marker.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_empty.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_non_empty_1.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_non_empty_2.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_square_marker.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_text_marker.png +0 -0
- package/test/references/09_chessboard_edit_arrows/base_1.png +0 -0
- package/test/references/09_chessboard_edit_arrows/base_2.png +0 -0
- package/test/references/09_chessboard_edit_arrows/edit_color_not_set.png +0 -0
- package/test/references/09_chessboard_edit_arrows/null_vector.png +0 -0
- package/test/references/09_chessboard_edit_arrows/out_of_board.png +0 -0
- package/test/references/09_chessboard_edit_arrows/over_arrow_marker.png +0 -0
- package/test/references/09_chessboard_edit_arrows/over_square_marker.png +0 -0
- package/test/references/10_chessboard_play_moves/castling_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_ambiguous_king_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_non_kxr_castling.png +0 -0
- package/test/references/10_chessboard_play_moves/illegal_move.png +0 -0
- package/test/references/10_chessboard_play_moves/illegal_position.png +0 -0
- package/test/references/10_chessboard_play_moves/null_vector.png +0 -0
- package/test/references/10_chessboard_play_moves/out_of_board.png +0 -0
- package/test/references/10_chessboard_play_moves/regular_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/regular_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/wrong_color.png +0 -0
- package/test/references/11_chessboard_play_promotions/antichess_promotion.png +0 -0
- package/test/references/11_chessboard_play_promotions/cancel_promotion.png +0 -0
- package/test/references/11_chessboard_play_promotions/regular_promotion_1.png +0 -0
- package/test/references/11_chessboard_play_promotions/regular_promotion_2.png +0 -0
|
@@ -25,8 +25,9 @@ import React from 'react';
|
|
|
25
25
|
import { Chessboard } from '../../src/index';
|
|
26
26
|
import { buildComponentDemoCode } from './util';
|
|
27
27
|
|
|
28
|
-
import Box from '@material
|
|
29
|
-
import
|
|
28
|
+
import Box from '@mui/material/Box';
|
|
29
|
+
import Stack from '@mui/material/Stack';
|
|
30
|
+
import Typography from '@mui/material/Typography';
|
|
30
31
|
|
|
31
32
|
import './demo.css';
|
|
32
33
|
|
|
@@ -63,17 +64,17 @@ export default class Page extends React.Component {
|
|
|
63
64
|
|
|
64
65
|
render() {
|
|
65
66
|
return (
|
|
66
|
-
<
|
|
67
|
+
<Stack spacing={2} mt={2}>
|
|
67
68
|
{this.renderControls()}
|
|
68
69
|
{this.renderChessboard()}
|
|
69
70
|
{this.renderCode()}
|
|
70
|
-
</
|
|
71
|
+
</Stack>
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
renderControls() {
|
|
75
76
|
return (
|
|
76
|
-
<Box
|
|
77
|
+
<Box>
|
|
77
78
|
<Typography>Resize the browser to see the chessboard adapt its size...</Typography>
|
|
78
79
|
<Typography>{`Current browser width: ${this.state.windowWidth} px`}</Typography>
|
|
79
80
|
</Box>
|
|
@@ -82,7 +83,7 @@ export default class Page extends React.Component {
|
|
|
82
83
|
|
|
83
84
|
renderChessboard() {
|
|
84
85
|
return (
|
|
85
|
-
<Box
|
|
86
|
+
<Box>
|
|
86
87
|
<Chessboard squareSize={this.state.squareSize} smallScreenLimits={this.state.limits} />
|
|
87
88
|
</Box>
|
|
88
89
|
);
|
|
@@ -102,16 +103,14 @@ export default class Page extends React.Component {
|
|
|
102
103
|
attributes.push(`squareSize={${this.state.squareSize}}`);
|
|
103
104
|
attributes.push('smallScreenLimits={limits}');
|
|
104
105
|
return (
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
</pre>
|
|
114
|
-
</Box>
|
|
106
|
+
<pre className="kokopu-demoCode">
|
|
107
|
+
{
|
|
108
|
+
'let limits = [\n' +
|
|
109
|
+
limits.join('') +
|
|
110
|
+
'];\n' +
|
|
111
|
+
buildComponentDemoCode('Chessboard', attributes)
|
|
112
|
+
}
|
|
113
|
+
</pre>
|
|
115
114
|
);
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 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 Styled from 'react-styleguidist/lib/client/rsg-components/Styled';
|
|
25
|
+
|
|
26
|
+
import logo from './kokopu-react-logo.png';
|
|
27
|
+
|
|
28
|
+
import './theming.css';
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const styles = ({ color, fontFamily, fontSize }) => ({
|
|
32
|
+
logo: {
|
|
33
|
+
color: color.base,
|
|
34
|
+
margin: 0,
|
|
35
|
+
fontFamily: fontFamily.base,
|
|
36
|
+
fontSize: fontSize.h4,
|
|
37
|
+
fontWeight: 'normal',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function LogoRenderer({ classes, children }) {
|
|
42
|
+
return (<>
|
|
43
|
+
<div className="kokopu-logo">
|
|
44
|
+
<img src={logo} />
|
|
45
|
+
</div>
|
|
46
|
+
<h1 className={classes.logo}>{children}</h1>
|
|
47
|
+
</>);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default Styled(styles)(LogoRenderer);
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 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
|
+
.kokopu-logo {
|
|
24
|
+
text-align: center;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
footer {
|
|
28
|
+
display: none !important;
|
|
29
|
+
}
|
|
@@ -31,4 +31,5 @@ testApp([ /* eslint-disable react/jsx-key */
|
|
|
31
31
|
<Chessboard position="something invalid" />,
|
|
32
32
|
<Chessboard position="r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3" />,
|
|
33
33
|
<Chessboard position={new kokopu.Position('8/8/1r6/8/5k1K/8/8/8 b - - 0 1')} />,
|
|
34
|
+
<Chessboard position={42} />,
|
|
34
35
|
]); /* eslint-enable react/jsx-key */
|
|
@@ -33,7 +33,7 @@ let arrowMarkers2 = { c3a2: 'y', c4a4: 'g', c5a6: 'r', c6a8: 'y', d6c8: 'g', e6e
|
|
|
33
33
|
let textMarkers2 = { g3: { symbol: 'H', color: 'r' }, g5: { symbol: 'M', color: 'g' } };
|
|
34
34
|
|
|
35
35
|
let squareMarkers3 = { b5: 'r', e4: 'g', h5: 'y' };
|
|
36
|
-
let arrowMarkers3 = { d1h5: 'g', a5f4: 'r', c7c3: 'y' };
|
|
36
|
+
let arrowMarkers3 = { d1h5: 'g', a5f4: 'r', c7c3: 'y', g7g7: 'g' };
|
|
37
37
|
let textMarkers3 = 'G5c6';
|
|
38
38
|
|
|
39
39
|
testApp([ /* eslint-disable react/jsx-key */
|
|
@@ -37,4 +37,5 @@ testApp([ /* eslint-disable react/jsx-key */
|
|
|
37
37
|
<Chessboard position="r3k2r/pppppppp/8/8/8/8/PPPPPPPP/R3K2R b KQkq - 0 1" move="O-O-O" animated={false} />,
|
|
38
38
|
<Chessboard position="rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3" move="exf6" animated={false} />,
|
|
39
39
|
<Chessboard position="8/8/8/1K6/8/4k3/1p6/8 b - - 0 1" move="b1=R+" animated={false} />,
|
|
40
|
+
<Chessboard move={42} animated={false} />,
|
|
40
41
|
]); /* 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 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 { Chessboard } from '../src/index';
|
|
26
|
+
|
|
27
|
+
function onSquareClicked(sq) {
|
|
28
|
+
setSandbox(`square clicked: ${sq}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
testApp([ /* eslint-disable react/jsx-key */
|
|
32
|
+
<Chessboard squareSize={50} interactionMode="clickSquares" onSquareClicked={onSquareClicked} />,
|
|
33
|
+
<Chessboard squareSize={50} interactionMode="clickSquares" onSquareClicked={onSquareClicked} flipped coordinateVisible={false} />,
|
|
34
|
+
<Chessboard squareSize={50} interactionMode="clickSquares" onSquareClicked={onSquareClicked} position="empty"
|
|
35
|
+
squareMarkers="Ga8" arrowMarkers="Ra6d6" textMarkers="YAb4" />,
|
|
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 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 { Chessboard } from '../src/index';
|
|
26
|
+
|
|
27
|
+
function onPieceMoved(from, to) {
|
|
28
|
+
setSandbox(`piece moved: ${from} -> ${to}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
testApp([ /* eslint-disable react/jsx-key */
|
|
32
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} />,
|
|
33
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} flipped
|
|
34
|
+
squareMarkers="Gc4" textMarkers="RAh3" arrowMarkers="Gc8a4" />,
|
|
35
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="movePieces" onPieceMoved={onPieceMoved} move="e4" animated={false} />,
|
|
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 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 { Chessboard } from '../src/index';
|
|
26
|
+
|
|
27
|
+
function onArrowEdited(from, to) {
|
|
28
|
+
setSandbox(`arrow edited: ${from} -> ${to}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
testApp([ /* eslint-disable react/jsx-key */
|
|
32
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="editArrows" onArrowEdited={onArrowEdited} editedArrowColor="g" />,
|
|
33
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="editArrows" onArrowEdited={onArrowEdited} editedArrowColor="r" flipped
|
|
34
|
+
squareMarkers="Gc5" arrowMarkers="Yh3f6" />,
|
|
35
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="editArrows" onArrowEdited={onArrowEdited} />,
|
|
36
|
+
]); /* eslint-enable react/jsx-key */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 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 { Chessboard } from '../src/index';
|
|
26
|
+
|
|
27
|
+
function onMovePlayed(move) {
|
|
28
|
+
setSandbox(`move played: ${move}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
testApp([ /* eslint-disable react/jsx-key */
|
|
32
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed} />,
|
|
33
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
|
|
34
|
+
flipped position="rnbqk2r/ppp2ppp/3p1n2/2b1p3/4P3/2NP1N2/PPP2PPP/R1BQKB1R w KQkq - 0 1" move="Bg5" animated={false} />,
|
|
35
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
|
|
36
|
+
position="rnbq1bnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1" />,
|
|
37
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed}
|
|
38
|
+
position="chess960:1r3k1r/pppppppp/8/8/8/8/PPPPPPPP/1R3K1R w BHbh - 0 1" />,
|
|
39
|
+
]); /* eslint-enable react/jsx-key */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021 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 { Chessboard } from '../src/index';
|
|
26
|
+
|
|
27
|
+
function onMovePlayed(move) {
|
|
28
|
+
setSandbox(`promotion move played: ${move}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
testApp([ /* eslint-disable react/jsx-key */
|
|
32
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed} position="8/1P6/8/8/7k/8/5K2/8 w - - 0 1" />,
|
|
33
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed} position="8/8/8/8/7k/8/1p3K2/R7 b - - 0 1" />,
|
|
34
|
+
<Chessboard squareSize={50} coordinateVisible={false} interactionMode="playMoves" onMovePlayed={onMovePlayed} flipped position="antichess:8/1P6/8/8/7r/8/5K2/8 w - - 0 1" />,
|
|
35
|
+
]); /* eslint-enable react/jsx-key */
|
|
@@ -47,4 +47,18 @@ export default function(elements) {
|
|
|
47
47
|
// Render the content.
|
|
48
48
|
let content = Array.isArray(elements) ? flattenMultiElements(elements) : elements;
|
|
49
49
|
ReactDOM.render(content, anchor);
|
|
50
|
+
|
|
51
|
+
// Append a text area
|
|
52
|
+
let sandbox = document.createElement('pre');
|
|
53
|
+
sandbox.id = 'sandbox';
|
|
54
|
+
document.body.appendChild(sandbox);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set the content of the sandbox.
|
|
60
|
+
*/
|
|
61
|
+
export function setSandbox(text) {
|
|
62
|
+
let sandbox = document.getElementById('sandbox');
|
|
63
|
+
sandbox.innerText = text;
|
|
50
64
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
|
3
|
+
<rect x="0" y="0" width="24" height="24" fill="#282c34" />
|
|
4
|
+
<g transform="matrix(0.04515812,0,0,0.04515812,-7.0115685,-1.3871247)">
|
|
5
|
+
<path fill="#61DAFB" d="M666.3,296.5c0-32.5-40.7-63.3-103.1-82.4c14.4-63.6,8-114.2-20.2-130.4c-6.5-3.8-14.1-5.6-22.4-5.6v22.3 c4.6,0,8.3,0.9,11.4,2.6c13.6,7.8,19.5,37.5,14.9,75.7c-1.1,9.4-2.9,19.3-5.1,29.4c-19.6-4.8-41-8.5-63.5-10.9 c-13.5-18.5-27.5-35.3-41.6-50c32.6-30.3,63.2-46.9,84-46.9l0-22.3c0,0,0,0,0,0c-27.5,0-63.5,19.6-99.9,53.6 c-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7,0,51.4,16.5,84,46.6c-14,14.7-28,31.4-41.3,49.9c-22.6,2.4-44,6.1-63.6,11 c-2.3-10-4-19.7-5.2-29c-4.7-38.2,1.1-67.9,14.6-75.8c3-1.8,6.9-2.6,11.5-2.6l0-22.3c0,0,0,0,0,0c-8.4,0-16,1.8-22.6,5.6 c-28.1,16.2-34.4,66.7-19.9,130.1c-62.2,19.2-102.7,49.9-102.7,82.3c0,32.5,40.7,63.3,103.1,82.4c-14.4,63.6-8,114.2,20.2,130.4 c6.5,3.8,14.1,5.6,22.5,5.6c27.5,0,63.5-19.6,99.9-53.6c36.4,33.8,72.4,53.2,99.9,53.2c8.4,0,16-1.8,22.6-5.6 c28.1-16.2,34.4-66.7,19.9-130.1C625.8,359.7,666.3,328.9,666.3,296.5z M536.1,229.8c-3.7,12.9-8.3,26.2-13.5,39.5 c-4.1-8-8.4-16-13.1-24c-4.6-8-9.5-15.8-14.4-23.4C509.3,224,523,226.6,536.1,229.8z M490.3,336.3c-7.8,13.5-15.8,26.3-24.1,38.2 c-14.9,1.3-30,2-45.2,2c-15.1,0-30.2-0.7-45-1.9c-8.3-11.9-16.4-24.6-24.2-38c-7.6-13.1-14.5-26.4-20.8-39.8 c6.2-13.4,13.2-26.8,20.7-39.9c7.8-13.5,15.8-26.3,24.1-38.2c14.9-1.3,30-2,45.2-2c15.1,0,30.2,0.7,45,1.9 c8.3,11.9,16.4,24.6,24.2,38c7.6,13.1,14.5,26.4,20.8,39.8C504.7,309.8,497.8,323.2,490.3,336.3z M522.6,323.3 c5.4,13.4,10,26.8,13.8,39.8c-13.1,3.2-26.9,5.9-41.2,8c4.9-7.7,9.8-15.6,14.4-23.7C514.2,339.4,518.5,331.3,522.6,323.3z M421.2,430c-9.3-9.6-18.6-20.3-27.8-32c9,0.4,18.2,0.7,27.5,0.7c9.4,0,18.7-0.2,27.8-0.7C439.7,409.7,430.4,420.4,421.2,430z M346.8,371.1c-14.2-2.1-27.9-4.7-41-7.9c3.7-12.9,8.3-26.2,13.5-39.5c4.1,8,8.4,16,13.1,24C337.1,355.7,341.9,363.5,346.8,371.1z M420.7,163c9.3,9.6,18.6,20.3,27.8,32c-9-0.4-18.2-0.7-27.5-0.7c-9.4,0-18.7,0.2-27.8,0.7C402.2,183.3,411.5,172.6,420.7,163z M346.7,221.9c-4.9,7.7-9.8,15.6-14.4,23.7c-4.6,8-8.9,16-13,24c-5.4-13.4-10-26.8-13.8-39.8C318.6,226.7,332.4,224,346.7,221.9z M256.2,347.1c-35.4-15.1-58.3-34.9-58.3-50.6c0-15.7,22.9-35.6,58.3-50.6c8.6-3.7,18-7,27.7-10.1c5.7,19.6,13.2,40,22.5,60.9 c-9.2,20.8-16.6,41.1-22.2,60.6C274.3,354.2,264.9,350.8,256.2,347.1z M310,490c-13.6-7.8-19.5-37.5-14.9-75.7 c1.1-9.4,2.9-19.3,5.1-29.4c19.6,4.8,41,8.5,63.5,10.9c13.5,18.5,27.5,35.3,41.6,50c-32.6,30.3-63.2,46.9-84,46.9 C316.8,492.6,313,491.7,310,490z M547.2,413.8c4.7,38.2-1.1,67.9-14.6,75.8c-3,1.8-6.9,2.6-11.5,2.6c-20.7,0-51.4-16.5-84-46.6 c14-14.7,28-31.4,41.3-49.9c22.6-2.4,44-6.1,63.6-11C544.3,394.8,546.1,404.5,547.2,413.8z M585.7,347.1c-8.6,3.7-18,7-27.7,10.1 c-5.7-19.6-13.2-40-22.5-60.9c9.2-20.8,16.6-41.1,22.2-60.6c9.9,3.1,19.3,6.5,28.1,10.2c35.4,15.1,58.3,34.9,58.3,50.6 C644,312.2,621.1,332.1,585.7,347.1z"/>
|
|
6
|
+
<polygon fill="#61DAFB" points="320.8,78.4 320.8,78.4 320.8,78.4 "/>
|
|
7
|
+
<circle fill="#61DAFB" cx="420.9" cy="296.5" r="45.7"/>
|
|
8
|
+
<polygon fill="#61DAFB" points="520.5,78.1 520.5,78.1 520.5,78.1 "/>
|
|
9
|
+
</g>
|
|
10
|
+
<rect x="12" y="12" width="5" height="5" fill="#fff" />
|
|
11
|
+
<rect x="17" y="12" width="5" height="5" fill="#000" />
|
|
12
|
+
<rect x="12" y="17" width="5" height="5" fill="#000" />
|
|
13
|
+
<rect x="17" y="17" width="5" height="5" fill="#fff" />
|
|
14
|
+
</svg>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
|
|
3
|
+
<rect x="4" y="4" width="56" height="56" fill="#282c34" rx="2" ry="2" />
|
|
4
|
+
<g transform="matrix(0.10805931,0,0,0.10805931,-13.49297,-0.03418245)">
|
|
5
|
+
<path fill="#61DAFB" d="M666.3,296.5c0-32.5-40.7-63.3-103.1-82.4c14.4-63.6,8-114.2-20.2-130.4c-6.5-3.8-14.1-5.6-22.4-5.6v22.3 c4.6,0,8.3,0.9,11.4,2.6c13.6,7.8,19.5,37.5,14.9,75.7c-1.1,9.4-2.9,19.3-5.1,29.4c-19.6-4.8-41-8.5-63.5-10.9 c-13.5-18.5-27.5-35.3-41.6-50c32.6-30.3,63.2-46.9,84-46.9l0-22.3c0,0,0,0,0,0c-27.5,0-63.5,19.6-99.9,53.6 c-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7,0,51.4,16.5,84,46.6c-14,14.7-28,31.4-41.3,49.9c-22.6,2.4-44,6.1-63.6,11 c-2.3-10-4-19.7-5.2-29c-4.7-38.2,1.1-67.9,14.6-75.8c3-1.8,6.9-2.6,11.5-2.6l0-22.3c0,0,0,0,0,0c-8.4,0-16,1.8-22.6,5.6 c-28.1,16.2-34.4,66.7-19.9,130.1c-62.2,19.2-102.7,49.9-102.7,82.3c0,32.5,40.7,63.3,103.1,82.4c-14.4,63.6-8,114.2,20.2,130.4 c6.5,3.8,14.1,5.6,22.5,5.6c27.5,0,63.5-19.6,99.9-53.6c36.4,33.8,72.4,53.2,99.9,53.2c8.4,0,16-1.8,22.6-5.6 c28.1-16.2,34.4-66.7,19.9-130.1C625.8,359.7,666.3,328.9,666.3,296.5z M536.1,229.8c-3.7,12.9-8.3,26.2-13.5,39.5 c-4.1-8-8.4-16-13.1-24c-4.6-8-9.5-15.8-14.4-23.4C509.3,224,523,226.6,536.1,229.8z M490.3,336.3c-7.8,13.5-15.8,26.3-24.1,38.2 c-14.9,1.3-30,2-45.2,2c-15.1,0-30.2-0.7-45-1.9c-8.3-11.9-16.4-24.6-24.2-38c-7.6-13.1-14.5-26.4-20.8-39.8 c6.2-13.4,13.2-26.8,20.7-39.9c7.8-13.5,15.8-26.3,24.1-38.2c14.9-1.3,30-2,45.2-2c15.1,0,30.2,0.7,45,1.9 c8.3,11.9,16.4,24.6,24.2,38c7.6,13.1,14.5,26.4,20.8,39.8C504.7,309.8,497.8,323.2,490.3,336.3z M522.6,323.3 c5.4,13.4,10,26.8,13.8,39.8c-13.1,3.2-26.9,5.9-41.2,8c4.9-7.7,9.8-15.6,14.4-23.7C514.2,339.4,518.5,331.3,522.6,323.3z M421.2,430c-9.3-9.6-18.6-20.3-27.8-32c9,0.4,18.2,0.7,27.5,0.7c9.4,0,18.7-0.2,27.8-0.7C439.7,409.7,430.4,420.4,421.2,430z M346.8,371.1c-14.2-2.1-27.9-4.7-41-7.9c3.7-12.9,8.3-26.2,13.5-39.5c4.1,8,8.4,16,13.1,24C337.1,355.7,341.9,363.5,346.8,371.1z M420.7,163c9.3,9.6,18.6,20.3,27.8,32c-9-0.4-18.2-0.7-27.5-0.7c-9.4,0-18.7,0.2-27.8,0.7C402.2,183.3,411.5,172.6,420.7,163z M346.7,221.9c-4.9,7.7-9.8,15.6-14.4,23.7c-4.6,8-8.9,16-13,24c-5.4-13.4-10-26.8-13.8-39.8C318.6,226.7,332.4,224,346.7,221.9z M256.2,347.1c-35.4-15.1-58.3-34.9-58.3-50.6c0-15.7,22.9-35.6,58.3-50.6c8.6-3.7,18-7,27.7-10.1c5.7,19.6,13.2,40,22.5,60.9 c-9.2,20.8-16.6,41.1-22.2,60.6C274.3,354.2,264.9,350.8,256.2,347.1z M310,490c-13.6-7.8-19.5-37.5-14.9-75.7 c1.1-9.4,2.9-19.3,5.1-29.4c19.6,4.8,41,8.5,63.5,10.9c13.5,18.5,27.5,35.3,41.6,50c-32.6,30.3-63.2,46.9-84,46.9 C316.8,492.6,313,491.7,310,490z M547.2,413.8c4.7,38.2-1.1,67.9-14.6,75.8c-3,1.8-6.9,2.6-11.5,2.6c-20.7,0-51.4-16.5-84-46.6 c14-14.7,28-31.4,41.3-49.9c22.6-2.4,44-6.1,63.6-11C544.3,394.8,546.1,404.5,547.2,413.8z M585.7,347.1c-8.6,3.7-18,7-27.7,10.1 c-5.7-19.6-13.2-40-22.5-60.9c9.2-20.8,16.6-41.1,22.2-60.6c9.9,3.1,19.3,6.5,28.1,10.2c35.4,15.1,58.3,34.9,58.3,50.6 C644,312.2,621.1,332.1,585.7,347.1z"/>
|
|
6
|
+
<polygon fill="#61DAFB" points="320.8,78.4 320.8,78.4 320.8,78.4 "/>
|
|
7
|
+
<circle fill="#61DAFB" cx="420.9" cy="296.5" r="45.7"/>
|
|
8
|
+
<polygon fill="#61DAFB" points="520.5,78.1 520.5,78.1 520.5,78.1 "/>
|
|
9
|
+
</g>
|
|
10
|
+
<rect x="32" y="32" width="6" height="6" fill="#fff" />
|
|
11
|
+
<rect x="38" y="32" width="6" height="6" fill="#000" />
|
|
12
|
+
<rect x="44" y="32" width="6" height="6" fill="#fff" />
|
|
13
|
+
<rect x="50" y="32" width="6" height="6" fill="#000" />
|
|
14
|
+
<rect x="32" y="38" width="6" height="6" fill="#000" />
|
|
15
|
+
<rect x="38" y="38" width="6" height="6" fill="#fff" />
|
|
16
|
+
<rect x="44" y="38" width="6" height="6" fill="#000" />
|
|
17
|
+
<rect x="50" y="38" width="6" height="6" fill="#fff" />
|
|
18
|
+
<rect x="32" y="44" width="6" height="6" fill="#fff" />
|
|
19
|
+
<rect x="38" y="44" width="6" height="6" fill="#000" />
|
|
20
|
+
<rect x="44" y="44" width="6" height="6" fill="#fff" />
|
|
21
|
+
<rect x="50" y="44" width="6" height="6" fill="#000" />
|
|
22
|
+
<rect x="32" y="50" width="6" height="6" fill="#000" />
|
|
23
|
+
<rect x="38" y="50" width="6" height="6" fill="#fff" />
|
|
24
|
+
<rect x="44" y="50" width="6" height="6" fill="#000" />
|
|
25
|
+
<rect x="50" y="50" width="6" height="6" fill="#fff" />
|
|
26
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokopu-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A React-based library to create and display chessboard components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chess",
|
|
@@ -19,52 +19,58 @@
|
|
|
19
19
|
"dist/lib",
|
|
20
20
|
"doc_src",
|
|
21
21
|
"graphic_test_app",
|
|
22
|
+
"graphics",
|
|
22
23
|
"scripts/test_graphic",
|
|
23
24
|
"scripts/test_headless.webpack-config.js",
|
|
24
25
|
"src",
|
|
25
26
|
"test",
|
|
26
27
|
".babelrc",
|
|
27
|
-
".eslint.yml"
|
|
28
|
+
".eslint.yml",
|
|
29
|
+
".nycrc.yml"
|
|
28
30
|
],
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"kokopu": "^
|
|
32
|
+
"kokopu": "^2.2.0",
|
|
31
33
|
"prop-types": "^15.7.2",
|
|
32
34
|
"react": "^17.0.2",
|
|
33
|
-
"react-draggable": "^4.4.
|
|
35
|
+
"react-draggable": "^4.4.4",
|
|
34
36
|
"react-motion": "^0.5.2"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.
|
|
38
|
-
"@babel/core": "^7.15.
|
|
39
|
-
"@babel/preset-env": "^7.15.
|
|
39
|
+
"@babel/cli": "^7.15.7",
|
|
40
|
+
"@babel/core": "^7.15.5",
|
|
41
|
+
"@babel/preset-env": "^7.15.6",
|
|
40
42
|
"@babel/preset-react": "^7.14.5",
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
+
"@emotion/react": "^11.4.1",
|
|
44
|
+
"@emotion/styled": "^11.3.0",
|
|
45
|
+
"@mui/material": "^5.0.1",
|
|
43
46
|
"babel-loader": "^8.2.2",
|
|
47
|
+
"babel-plugin-istanbul": "^6.0.0",
|
|
44
48
|
"copy-webpack-plugin": "^9.0.1",
|
|
45
|
-
"
|
|
49
|
+
"coveralls": "^3.1.1",
|
|
50
|
+
"css-loader": "^6.3.0",
|
|
46
51
|
"eslint": "^7.32.0",
|
|
47
|
-
"eslint-plugin-react": "^7.
|
|
52
|
+
"eslint-plugin-react": "^7.26.0",
|
|
48
53
|
"html-webpack-plugin": "^5.3.2",
|
|
49
54
|
"img-diff-js": "^0.5.2",
|
|
50
|
-
"mocha": "^9.
|
|
55
|
+
"mocha": "^9.1.2",
|
|
51
56
|
"null-loader": "^4.0.1",
|
|
52
|
-
"
|
|
57
|
+
"nyc": "^15.1.0",
|
|
58
|
+
"prompt": "^1.2.0",
|
|
53
59
|
"react-dom": "^17.0.2",
|
|
54
60
|
"react-styleguidist": "^11.1.7",
|
|
55
|
-
"selenium-webdriver": "^4.0.0-
|
|
56
|
-
"ssh2-sftp-client": "^7.0.
|
|
57
|
-
"style-loader": "^3.
|
|
61
|
+
"selenium-webdriver": "^4.0.0-rc-1",
|
|
62
|
+
"ssh2-sftp-client": "^7.0.4",
|
|
63
|
+
"style-loader": "^3.3.0",
|
|
58
64
|
"unit.js": "^2.1.1",
|
|
59
|
-
"webpack": "^5.
|
|
60
|
-
"webpack-cli": "^4.
|
|
61
|
-
"webpack-dev-server": "^3.11.2"
|
|
65
|
+
"webpack": "^5.54.0",
|
|
66
|
+
"webpack-cli": "^4.8.0"
|
|
62
67
|
},
|
|
63
68
|
"scripts": {
|
|
64
69
|
"lint": "eslint doc_src graphic_test_app src test",
|
|
65
70
|
"preunit": "webpack --config scripts/test_headless.webpack-config.js && webpack --config scripts/test_graphic/webpack-config.js && node scripts/test_graphic/clean-graphic-output.js",
|
|
66
|
-
"unit": "mocha --bail --sort",
|
|
71
|
+
"unit": "nyc mocha --bail --sort",
|
|
67
72
|
"test": "npm run lint && npm run unit",
|
|
73
|
+
"publish_coverage": "nyc report --reporter=text-lcov | coveralls",
|
|
68
74
|
"start_test_env": "docker-compose -f scripts/test_graphic/docker-compose.yml up -d",
|
|
69
75
|
"stop_test_env": "docker-compose -f scripts/test_graphic/docker-compose.yml down",
|
|
70
76
|
"build": "make -f scripts/build.mk",
|