kokopu-react 3.0.2 → 3.1.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.
- package/CHANGELOG.md +7 -1
- package/dist/lib/chessboard/BoardProperties.d.ts +91 -0
- package/dist/lib/chessboard/BoardProperties.js +43 -0
- package/dist/lib/chessboard/BoardProperties.js.map +1 -0
- package/dist/lib/chessboard/Chessboard.d.ts +14 -58
- package/dist/lib/chessboard/Chessboard.js +26 -92
- package/dist/lib/chessboard/Chessboard.js.map +1 -1
- package/dist/lib/errorbox/parsing.d.ts +57 -0
- package/dist/lib/errorbox/parsing.js +140 -0
- package/dist/lib/errorbox/parsing.js.map +1 -0
- package/dist/lib/i18n.d.ts +5 -0
- package/dist/lib/i18n.js +6 -0
- package/dist/lib/i18n.js.map +1 -1
- package/dist/lib/index.d.ts +4 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/movetext/Movetext.css +0 -13
- package/dist/lib/movetext/Movetext.d.ts +9 -43
- package/dist/lib/movetext/Movetext.js +15 -67
- package/dist/lib/movetext/Movetext.js.map +1 -1
- package/dist/lib/movetext/MovetextImpl.d.ts +7 -28
- package/dist/lib/movetext/MovetextImpl.js +15 -94
- package/dist/lib/movetext/MovetextImpl.js.map +1 -1
- package/dist/lib/navigationboard/NavigationBoard.d.ts +118 -0
- package/dist/lib/navigationboard/NavigationBoard.js +112 -0
- package/dist/lib/navigationboard/NavigationBoard.js.map +1 -0
- package/dist/lib/navigationboard/NavigationField.css +36 -0
- package/dist/lib/navigationboard/NavigationField.d.ts +81 -0
- package/dist/lib/navigationboard/NavigationField.js +154 -0
- package/dist/lib/navigationboard/NavigationField.js.map +1 -0
- package/dist/lib/navigationboard/NavigationToolbar.css +51 -0
- package/dist/lib/navigationboard/NavigationToolbar.d.ts +41 -0
- package/dist/lib/navigationboard/NavigationToolbar.js +124 -0
- package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -0
- package/doc_src/demo/PageChessboardMove.tsx +17 -0
- package/doc_src/demo/PageNavigationBoardBase.tsx +194 -0
- package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +114 -0
- package/doc_src/demo/game-3.pgn +10 -0
- package/doc_src/examples/Movetext.md +1 -1
- package/doc_src/examples/NavigationBoard.md +15 -0
- package/package.json +16 -16
- package/scripts/doc.styleguide.config.js +12 -2
- package/scripts/docker-compose.yml +1 -1
- package/src/chessboard/BoardProperties.ts +131 -0
- package/src/chessboard/Chessboard.tsx +41 -170
- package/src/errorbox/parsing.tsx +158 -0
- package/src/i18n.ts +7 -0
- package/src/index.ts +5 -1
- package/src/movetext/Movetext.css +0 -13
- package/src/movetext/Movetext.tsx +20 -85
- package/src/movetext/MovetextImpl.tsx +28 -115
- package/src/navigationboard/NavigationBoard.tsx +231 -0
- package/src/navigationboard/NavigationField.css +36 -0
- package/src/navigationboard/NavigationField.tsx +185 -0
- package/src/navigationboard/NavigationToolbar.css +51 -0
- package/src/navigationboard/NavigationToolbar.tsx +174 -0
- package/test/05_chessboard_graphic.js +2 -0
- package/test/09_chessboard_small_screens.js +21 -0
- package/test/10_movetext_graphic.js +5 -0
- package/test/11_movetext_interaction.js +12 -8
- package/test/12_navigation_board.js +168 -0
- package/test/graphic_references/05_chessboard_graphic/move/illegal_null-move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/null-move.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_bottom_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_top_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_bottom_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_top_component.png +0 -0
- package/test/graphic_references/10_movetext_graphic/format_move/format_text.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/wrong_piece_symbol_value.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected_without_callback.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/default.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/invalid_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/overriding_initial_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board/error/pgn_parsing_error.png +0 -0
- package/test/graphic_references/12_navigation_board/error/wrong_game_type.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/custom_1.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/custom_2.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/large.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/small.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_end.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_specific_id.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default_with_game_index.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_on_null-move.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_3.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_4.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_4.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_5.png +0 -0
- package/test/graphic_test_app/05_chessboard_graphic/move.tsx +2 -0
- package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +48 -0
- package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +31 -0
- package/test/graphic_test_app/10_movetext_graphic/options.tsx +1 -0
- package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +1 -0
- package/test/graphic_test_app/12_navigation_board/controlled.tsx +43 -0
- package/test/graphic_test_app/12_navigation_board/error.tsx +34 -0
- package/test/graphic_test_app/12_navigation_board/theme.tsx +38 -0
- package/test/graphic_test_app/12_navigation_board/uncontrolled.tsx +56 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
3
|
+
* *
|
|
4
|
+
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
|
+
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
+
* Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
|
+
* *
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
10
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
11
|
+
* the License, or (at your option) any later version. *
|
|
12
|
+
* *
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
16
|
+
* GNU Lesser General Public License for more details. *
|
|
17
|
+
* *
|
|
18
|
+
* You should have received a copy of the GNU Lesser General *
|
|
19
|
+
* Public License along with this program. If not, see *
|
|
20
|
+
* <http://www.gnu.org/licenses/>. *
|
|
21
|
+
* *
|
|
22
|
+
* -------------------------------------------------------------------------- */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import * as React from 'react';
|
|
26
|
+
|
|
27
|
+
import { NavigationBoard } from '../../src/index';
|
|
28
|
+
import { buildComponentDemoCode } from './util';
|
|
29
|
+
|
|
30
|
+
import Box from '@mui/material/Box';
|
|
31
|
+
import Stack from '@mui/material/Stack';
|
|
32
|
+
import Typography from '@mui/material/Typography';
|
|
33
|
+
|
|
34
|
+
import './demo.css';
|
|
35
|
+
import pgn from './game-3.pgn';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
interface PageState {
|
|
39
|
+
nodeId: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export default class Page extends React.Component<object, PageState> {
|
|
44
|
+
|
|
45
|
+
constructor(props: object) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.state = {
|
|
48
|
+
nodeId: '9b',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
return (
|
|
54
|
+
<Stack spacing={2} mt={2}>
|
|
55
|
+
{this.renderControls()}
|
|
56
|
+
{this.renderNavigationBoards()}
|
|
57
|
+
{this.renderCode()}
|
|
58
|
+
</Stack>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private renderControls() {
|
|
63
|
+
return (<>
|
|
64
|
+
<Typography>
|
|
65
|
+
In uncontrolled mode, the current node ID (aka. the current move) of the <code>NavigationBoard</code> component is managed internally.
|
|
66
|
+
No additional code is needed to make the navigation buttons work.
|
|
67
|
+
</Typography>
|
|
68
|
+
<Typography>
|
|
69
|
+
In controlled mode, the current node ID is defined by the <code>nodeId</code> attribute, and a callback must be set
|
|
70
|
+
on the <code>onNodeIdChanged</code> attribute to respond to clicks on the navigation buttons.
|
|
71
|
+
This mode requires more code, as a state variable holding the current node ID must be explicitely managed out of the component,
|
|
72
|
+
but it allows to define more complex behaviors (e.g. synchronizing the node ID on the <code>NavigationBoard</code> with another component).
|
|
73
|
+
</Typography>
|
|
74
|
+
<Typography>
|
|
75
|
+
Whether the component is in uncontrolled mode or controlled mode depends on the presence of the <code>nodeId</code> attribute.
|
|
76
|
+
</Typography>
|
|
77
|
+
</>);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private renderNavigationBoards() {
|
|
81
|
+
return (
|
|
82
|
+
<Box display="flex" alignItems="top" justifyContent="space-around">
|
|
83
|
+
<Box>
|
|
84
|
+
<NavigationBoard game={pgn} animated initialNodeId="9b" />
|
|
85
|
+
<Typography mt={2} textAlign="center">Uncontrolled</Typography>
|
|
86
|
+
</Box>
|
|
87
|
+
<Box>
|
|
88
|
+
<NavigationBoard game={pgn} animated nodeId={this.state.nodeId} onNodeIdChanged={nodeId => this.setState({ nodeId: nodeId })} />
|
|
89
|
+
<Typography mt={2} textAlign="center">Controlled</Typography>
|
|
90
|
+
<Typography textAlign="center">{`Current node ID: ${this.state.nodeId}`}</Typography>
|
|
91
|
+
</Box>
|
|
92
|
+
</Box>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private renderCode() {
|
|
97
|
+
|
|
98
|
+
const uncontrolledAttributes: string[] = [];
|
|
99
|
+
uncontrolledAttributes.push('game={pgn}');
|
|
100
|
+
uncontrolledAttributes.push('animated');
|
|
101
|
+
uncontrolledAttributes.push('initialNodeId="9b"');
|
|
102
|
+
|
|
103
|
+
const controlledAttributes: string[] = [];
|
|
104
|
+
controlledAttributes.push('game={pgn}');
|
|
105
|
+
controlledAttributes.push('animated');
|
|
106
|
+
controlledAttributes.push(`nodeId="${this.state.nodeId}"`);
|
|
107
|
+
controlledAttributes.push('onNodeIdChanged={nodeId => handleNodeIdChanged(nodeId)}');
|
|
108
|
+
|
|
109
|
+
const pgnDeclaration = 'const pgn = `\n' + pgn.trim() + '`;\n\n';
|
|
110
|
+
return <pre className="kokopu-demoCode">{pgnDeclaration + '// Uncontrolled\n' + buildComponentDemoCode('NavigationBoard', uncontrolledAttributes)
|
|
111
|
+
+ '\n\n// Controlled\n' + buildComponentDemoCode('NavigationBoard', controlledAttributes)}</pre>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[Event "Television Exhibition"]
|
|
2
|
+
[Site "London ENG"]
|
|
3
|
+
[Date "2014.01.23"]
|
|
4
|
+
[Round "?"]
|
|
5
|
+
[White "Bill Gates"]
|
|
6
|
+
[Black "Magnus Carlsen"]
|
|
7
|
+
[Result "0-1"]
|
|
8
|
+
|
|
9
|
+
1.e4 Nc6 2.Nf3 d5 3.Bd3 Nf6 4.exd5 Qxd5 5.Nc3 Qh5 6.O-O Bg4
|
|
10
|
+
7.h3 Ne5 8.hxg4 Nfxg4 9.Nxe5 Qh2# 0-1
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
```js
|
|
2
|
+
const 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
|
+
<NavigationBoard game={pgn} initialNodeId="end" />
|
|
15
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokopu-react",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A React-based library to create and display chessboard and chess-related components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chess",
|
|
@@ -36,33 +36,33 @@
|
|
|
36
36
|
"tsconfig.json"
|
|
37
37
|
],
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"kokopu": "^4.
|
|
39
|
+
"kokopu": "^4.9.1",
|
|
40
40
|
"react": "17.x.x || 18.x.x"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"htmlparser2": "^9.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/preset-env": "^7.
|
|
46
|
+
"@babel/preset-env": "^7.24.0",
|
|
47
47
|
"@babel/preset-react": "^7.23.3",
|
|
48
|
-
"@emotion/react": "^11.11.
|
|
48
|
+
"@emotion/react": "^11.11.4",
|
|
49
49
|
"@emotion/styled": "^11.11.0",
|
|
50
|
-
"@mui/material": "^5.15.
|
|
51
|
-
"@types/react": "^18.2.
|
|
52
|
-
"@types/react-dom": "^18.2.
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
50
|
+
"@mui/material": "^5.15.11",
|
|
51
|
+
"@types/react": "^18.2.61",
|
|
52
|
+
"@types/react-dom": "^18.2.19",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
54
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
55
55
|
"babel-loader": "^9.1.3",
|
|
56
56
|
"copy-webpack-plugin": "^12.0.2",
|
|
57
57
|
"copyfiles": "^2.4.1",
|
|
58
58
|
"coverage-istanbul-loader": "^3.0.5",
|
|
59
|
-
"css-loader": "^6.
|
|
60
|
-
"eslint": "^8.
|
|
59
|
+
"css-loader": "^6.10.0",
|
|
60
|
+
"eslint": "^8.57.0",
|
|
61
61
|
"eslint-plugin-react": "^7.33.2",
|
|
62
62
|
"html-webpack-plugin": "^5.6.0",
|
|
63
63
|
"img-diff-js": "^0.5.2",
|
|
64
|
-
"kokopu": "^4.
|
|
65
|
-
"mocha": "^10.
|
|
64
|
+
"kokopu": "^4.9.1",
|
|
65
|
+
"mocha": "^10.3.0",
|
|
66
66
|
"null-loader": "^4.0.1",
|
|
67
67
|
"nyc": "^15.1.0",
|
|
68
68
|
"react": "^18.2.0",
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
"react-dom": "^18.2.0",
|
|
71
71
|
"react-styleguidist": "^13.1.2",
|
|
72
72
|
"rimraf": "^5.0.5",
|
|
73
|
-
"selenium-webdriver": "^4.
|
|
74
|
-
"ssh2-sftp-client": "^10.0.
|
|
73
|
+
"selenium-webdriver": "^4.18.1",
|
|
74
|
+
"ssh2-sftp-client": "^10.0.3",
|
|
75
75
|
"style-loader": "^3.3.4",
|
|
76
76
|
"ts-loader": "^9.5.1",
|
|
77
77
|
"typescript": "^5.3.3",
|
|
78
78
|
"unit.js": "^2.1.1",
|
|
79
|
-
"webpack": "^5.
|
|
79
|
+
"webpack": "^5.90.3",
|
|
80
80
|
"webpack-cli": "^5.1.4"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
@@ -39,8 +39,16 @@ fs.mkdirSync(path.resolve(__dirname, tmpDir), { recursive: true });
|
|
|
39
39
|
// -------------------------------
|
|
40
40
|
|
|
41
41
|
const componentSectionTitle = 'Components';
|
|
42
|
-
const components = [
|
|
43
|
-
'
|
|
42
|
+
const components = [
|
|
43
|
+
'errorbox/ErrorBox',
|
|
44
|
+
'icons/SquareMarkerIcon',
|
|
45
|
+
'icons/TextMarkerIcon',
|
|
46
|
+
'icons/ArrowMarkerIcon',
|
|
47
|
+
'icons/ChessPieceIcon',
|
|
48
|
+
'chessboard/Chessboard',
|
|
49
|
+
'navigationboard/NavigationBoard',
|
|
50
|
+
'movetext/Movetext',
|
|
51
|
+
];
|
|
44
52
|
|
|
45
53
|
|
|
46
54
|
// Demo section configuration
|
|
@@ -52,6 +60,8 @@ const demoPages = [
|
|
|
52
60
|
{ id: 'ChessboardInteraction', title: 'Chessboard - Interactions' },
|
|
53
61
|
{ id: 'ChessboardMove', title: 'Chessboard - Display moves' },
|
|
54
62
|
{ id: 'ChessboardSmallScreens', title: 'Chessboard - Small screens' },
|
|
63
|
+
{ id: 'NavigationBoardBase', title: 'NavigationBoard - Basic features' },
|
|
64
|
+
{ id: 'NavigationBoardUncontrolledVsControlled', title: 'NavigationBoard - Uncontrolled vs. controlled' },
|
|
55
65
|
{ id: 'MovetextBase', title: 'Movetext - Basic features' },
|
|
56
66
|
{ id: 'MovetextInteraction', title: 'Movetext - Interactions' },
|
|
57
67
|
];
|
|
@@ -2,7 +2,7 @@ version: "3.7"
|
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
4
|
web-client:
|
|
5
|
-
image: selenium/standalone-firefox:4.
|
|
5
|
+
image: selenium/standalone-firefox:4.18.1-20240224 # https://github.com/SeleniumHQ/docker-selenium to get the latest version
|
|
6
6
|
shm_size: '2gb'
|
|
7
7
|
ports:
|
|
8
8
|
- 4444:4444 # http://localhost:4444/ (driver)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
3
|
+
* *
|
|
4
|
+
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
|
+
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
+
* Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
|
+
* *
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
10
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
11
|
+
* the License, or (at your option) any later version. *
|
|
12
|
+
* *
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
16
|
+
* GNU Lesser General Public License for more details. *
|
|
17
|
+
* *
|
|
18
|
+
* You should have received a copy of the GNU Lesser General *
|
|
19
|
+
* Public License along with this program. If not, see *
|
|
20
|
+
* <http://www.gnu.org/licenses/>. *
|
|
21
|
+
* *
|
|
22
|
+
* -------------------------------------------------------------------------- */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import { AnnotationColor } from '../types';
|
|
26
|
+
import { DEFAULT_COLORSET } from './colorsets';
|
|
27
|
+
import { DEFAULT_PIECESET } from './piecesets';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Define a limit applicable to the parameters of a {@link Chessboard} on small-screen devices.
|
|
32
|
+
*/
|
|
33
|
+
export interface SmallScreenLimit {
|
|
34
|
+
width: number;
|
|
35
|
+
squareSize?: number;
|
|
36
|
+
coordinateVisible?: boolean;
|
|
37
|
+
turnVisible?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Properties in relation to the appearance of a `Chessboard` component (excluding properties related to move display).
|
|
43
|
+
*/
|
|
44
|
+
export interface StaticBoardGraphicProps {
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Size of the squares (in pixels). Must be an integer between `Chessboard.minSquareSize()` and `Chessboard.maxSquareSize()`.
|
|
48
|
+
*/
|
|
49
|
+
squareSize: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the row and column coordinates are visible or not.
|
|
53
|
+
*/
|
|
54
|
+
coordinateVisible: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether the turn flag is visible or not.
|
|
58
|
+
*/
|
|
59
|
+
turnVisible: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Color theme ID. Must be a property of `Chessboard.colorsets()`.
|
|
63
|
+
*/
|
|
64
|
+
colorset: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Piece theme ID. Must be a property of `Chessboard.piecesets()`.
|
|
68
|
+
*/
|
|
69
|
+
pieceset: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Limits applicable on small-screen devices. For instance, if set to
|
|
73
|
+
* ```
|
|
74
|
+
* [
|
|
75
|
+
* { width: 768, squareSize: 40 },
|
|
76
|
+
* { width: 375, squareSize: 24, coordinateVisible: false }
|
|
77
|
+
* ]
|
|
78
|
+
* ```
|
|
79
|
+
* then on screens with resolution ≤768 pixels, the square size will be limited to 40 (whatever the value
|
|
80
|
+
* of the `squareSize` attribute); in addition, on screens with resolution ≤375 pixels, the square size
|
|
81
|
+
* will be limited to 24 and the row and column coordinates will always be hidden (whatever the value of the
|
|
82
|
+
* `coordinateVisible` attribute).
|
|
83
|
+
*/
|
|
84
|
+
smallScreenLimits?: SmallScreenLimit[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Properties in relation to the appearance of a `Chessboard` component (including properties related to move display).
|
|
90
|
+
*/
|
|
91
|
+
export interface DynamicBoardGraphicProps extends StaticBoardGraphicProps {
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Whether moves are highlighted with an arrow or not.
|
|
95
|
+
*/
|
|
96
|
+
moveArrowVisible: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Color of the move arrow.
|
|
100
|
+
*/
|
|
101
|
+
moveArrowColor: AnnotationColor;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Whether moves are animated or not.
|
|
105
|
+
*/
|
|
106
|
+
animated: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
export const DEFAULT_SQUARE_SIZE = 40;
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
export function defaultStaticBoardProps(): StaticBoardGraphicProps {
|
|
114
|
+
return {
|
|
115
|
+
squareSize: DEFAULT_SQUARE_SIZE,
|
|
116
|
+
coordinateVisible: true,
|
|
117
|
+
turnVisible: true,
|
|
118
|
+
colorset: DEFAULT_COLORSET,
|
|
119
|
+
pieceset: DEFAULT_PIECESET,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
export function defaultDynamicBoardProps(): DynamicBoardGraphicProps {
|
|
125
|
+
return {
|
|
126
|
+
...defaultStaticBoardProps(),
|
|
127
|
+
moveArrowVisible: true,
|
|
128
|
+
moveArrowColor: 'b',
|
|
129
|
+
animated: false,
|
|
130
|
+
};
|
|
131
|
+
}
|