kokopu-react 3.3.4 → 3.4.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 +8 -0
- package/CREDITS.md +5 -1
- package/dist/lib/chessboard/BoardProperties.d.ts +5 -1
- package/dist/lib/chessboard/BoardProperties.js +2 -1
- package/dist/lib/chessboard/BoardProperties.js.map +1 -1
- package/dist/lib/chessboard/Chessboard.css +1 -1
- package/dist/lib/chessboard/Chessboard.d.ts +1 -1
- package/dist/lib/chessboard/Chessboard.js +3 -2
- package/dist/lib/chessboard/Chessboard.js.map +1 -1
- package/dist/lib/chessboard/ChessboardImpl.d.ts +2 -1
- package/dist/lib/chessboard/ChessboardImpl.js +4 -2
- package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
- package/dist/lib/chessboard/Draggable.d.ts +1 -1
- package/dist/lib/chessboard/Draggable.js +1 -1
- package/dist/lib/chessboard/Motion.d.ts +1 -1
- package/dist/lib/chessboard/Motion.js +1 -1
- package/dist/lib/chessboard/Sound.d.ts +29 -0
- package/dist/lib/chessboard/Sound.js +53 -0
- package/dist/lib/chessboard/Sound.js.map +1 -0
- package/dist/lib/chessboard/colorsets.d.ts +1 -1
- package/dist/lib/chessboard/colorsets.js +1 -1
- package/dist/lib/chessboard/piecesets.d.ts +1 -1
- package/dist/lib/chessboard/piecesets.js +1 -1
- package/dist/lib/chessboard/sounds/move.ogg +0 -0
- package/dist/lib/errorbox/ErrorBox.css +1 -1
- package/dist/lib/errorbox/ErrorBox.d.ts +1 -1
- package/dist/lib/errorbox/ErrorBox.js +1 -1
- package/dist/lib/errorbox/parsing.d.ts +1 -1
- package/dist/lib/errorbox/parsing.js +1 -1
- package/dist/lib/exception.d.ts +1 -1
- package/dist/lib/exception.js +1 -1
- package/dist/lib/i18n.d.ts +1 -1
- package/dist/lib/i18n.js +1 -1
- package/dist/lib/icons/AnnotationSymbolShape.css +1 -1
- package/dist/lib/icons/AnnotationSymbolShape.d.ts +1 -1
- package/dist/lib/icons/AnnotationSymbolShape.js +1 -1
- package/dist/lib/icons/ArrowMarkerIcon.d.ts +1 -1
- package/dist/lib/icons/ArrowMarkerIcon.js +1 -1
- package/dist/lib/icons/ArrowTip.d.ts +1 -1
- package/dist/lib/icons/ArrowTip.js +1 -1
- package/dist/lib/icons/ChessPieceIcon.d.ts +1 -1
- package/dist/lib/icons/ChessPieceIcon.js +1 -1
- package/dist/lib/icons/SquareMarkerIcon.d.ts +1 -1
- package/dist/lib/icons/SquareMarkerIcon.js +1 -1
- package/dist/lib/icons/TextMarkerIcon.d.ts +1 -1
- package/dist/lib/icons/TextMarkerIcon.js +1 -1
- package/dist/lib/icons/arrow.css +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/movetext/Movetext.css +1 -1
- package/dist/lib/movetext/Movetext.d.ts +1 -1
- package/dist/lib/movetext/Movetext.js +1 -1
- package/dist/lib/movetext/MovetextImpl.d.ts +1 -1
- package/dist/lib/movetext/MovetextImpl.js +1 -1
- package/dist/lib/movetext/fonts.css +1 -1
- package/dist/lib/movetext/htmlFilter.d.ts +1 -1
- package/dist/lib/movetext/htmlFilter.js +1 -1
- package/dist/lib/movetext/moveFormatter.d.ts +1 -1
- package/dist/lib/movetext/moveFormatter.js +1 -1
- package/dist/lib/navigationboard/NavigationBoard.d.ts +2 -1
- package/dist/lib/navigationboard/NavigationBoard.js +2 -2
- package/dist/lib/navigationboard/NavigationBoard.js.map +1 -1
- package/dist/lib/navigationboard/NavigationButton.d.ts +1 -1
- package/dist/lib/navigationboard/NavigationButton.js +1 -1
- package/dist/lib/navigationboard/NavigationField.css +1 -1
- package/dist/lib/navigationboard/NavigationField.d.ts +1 -1
- package/dist/lib/navigationboard/NavigationField.js +1 -1
- package/dist/lib/navigationboard/NavigationToolbar.css +1 -1
- package/dist/lib/navigationboard/NavigationToolbar.d.ts +1 -1
- package/dist/lib/navigationboard/NavigationToolbar.js +1 -1
- package/dist/lib/navigationboard/iconPaths.d.ts +1 -1
- package/dist/lib/navigationboard/iconPaths.js +1 -1
- package/dist/lib/sanitization.d.ts +1 -1
- package/dist/lib/sanitization.js +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/util.d.ts +1 -1
- package/dist/lib/util.js +1 -1
- package/doc_src/demo/NavigationBoardWithMoveText.txt +1 -1
- package/doc_src/demo/PageChessboardBase.tsx +1 -1
- package/doc_src/demo/PageChessboardInteraction.tsx +1 -1
- package/doc_src/demo/PageChessboardMove.tsx +9 -1
- package/doc_src/demo/PageChessboardSmallScreens.tsx +1 -1
- package/doc_src/demo/PageMovetextBase.tsx +1 -1
- package/doc_src/demo/PageMovetextInteraction.tsx +2 -2
- package/doc_src/demo/PageNavigationBoardBase.tsx +12 -2
- package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +5 -3
- package/doc_src/demo/PageSynchroNavigationBoardMovetext.tsx +2 -2
- package/doc_src/demo/decs.d.ts +1 -1
- package/doc_src/demo/demo.css +1 -1
- package/doc_src/demo/util.ts +1 -1
- package/doc_src/theming/LogoRenderer.js +1 -1
- package/doc_src/theming/theming.css +1 -1
- package/doc_src/webpack_configuration.md +2 -1
- package/package.json +21 -20
- package/scripts/doc.styleguide.config.js +2 -2
- package/scripts/doc.tsconfig.json +1 -1
- package/scripts/test-graphic.webpack.config.js +2 -2
- package/scripts/test-headless.webpack.config.js +2 -2
- package/src/chessboard/BoardProperties.ts +7 -1
- package/src/chessboard/Chessboard.css +1 -1
- package/src/chessboard/Chessboard.tsx +3 -2
- package/src/chessboard/ChessboardImpl.tsx +4 -1
- package/src/chessboard/Draggable.tsx +1 -1
- package/src/chessboard/Motion.tsx +1 -1
- package/src/chessboard/Sound.tsx +71 -0
- package/src/chessboard/colorsets.ts +1 -1
- package/src/chessboard/piecesets.ts +1 -1
- package/src/chessboard/sounds/move.ogg +0 -0
- package/src/decs.d.ts +6 -1
- package/src/errorbox/ErrorBox.css +1 -1
- package/src/errorbox/ErrorBox.tsx +1 -1
- package/src/errorbox/parsing.tsx +1 -1
- package/src/exception.ts +1 -1
- package/src/i18n.ts +1 -1
- package/src/icons/AnnotationSymbolShape.css +1 -1
- package/src/icons/AnnotationSymbolShape.tsx +1 -1
- package/src/icons/ArrowMarkerIcon.tsx +1 -1
- package/src/icons/ArrowTip.tsx +1 -1
- package/src/icons/ChessPieceIcon.tsx +1 -1
- package/src/icons/SquareMarkerIcon.tsx +1 -1
- package/src/icons/TextMarkerIcon.tsx +1 -1
- package/src/icons/arrow.css +1 -1
- package/src/index.ts +1 -1
- package/src/movetext/Movetext.css +1 -1
- package/src/movetext/Movetext.tsx +1 -1
- package/src/movetext/MovetextImpl.tsx +1 -1
- package/src/movetext/fonts.css +1 -1
- package/src/movetext/htmlFilter.tsx +1 -1
- package/src/movetext/moveFormatter.tsx +1 -1
- package/src/navigationboard/NavigationBoard.tsx +2 -2
- package/src/navigationboard/NavigationButton.ts +1 -1
- package/src/navigationboard/NavigationField.css +1 -1
- package/src/navigationboard/NavigationField.tsx +1 -1
- package/src/navigationboard/NavigationToolbar.css +1 -1
- package/src/navigationboard/NavigationToolbar.tsx +1 -1
- package/src/navigationboard/iconPaths.ts +1 -1
- package/src/sanitization.ts +1 -1
- package/src/types.ts +1 -1
- package/src/util.ts +1 -1
- package/test/01_types.js +1 -1
- package/test/02_chessboard_util.js +1 -1
- package/test/03_error_box_graphic.js +1 -1
- package/test/04_icons_graphic.js +1 -1
- package/test/05_chessboard_graphic.js +1 -1
- package/test/06_chessboard_animation.js +22 -4
- package/test/07_chessboard_interaction.js +1 -1
- package/test/08_chessboard_play_moves.js +1 -1
- package/test/09_chessboard_small_screens.js +1 -1
- package/test/10_movetext_graphic.js +1 -1
- package/test/11_movetext_interaction.js +1 -1
- package/test/12_navigation_board_base.js +1 -1
- package/test/13_navigation_board_graphic.js +1 -1
- package/test/14_navigation_board_autoplay.js +1 -1
- package/test/common/graphic.js +10 -1
- package/test/graphic_references/06_chessboard_animation/sound/with_move.png +0 -0
- package/test/graphic_references/06_chessboard_animation/sound/without_move.png +0 -0
- package/test/graphic_test_app/03_error_box_graphic/base.tsx +1 -1
- package/test/graphic_test_app/03_error_box_graphic/localization.tsx +1 -1
- package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +1 -1
- package/test/graphic_test_app/04_icons_graphic/marker.tsx +1 -1
- package/test/graphic_test_app/05_chessboard_graphic/annotations.tsx +5 -5
- package/test/graphic_test_app/05_chessboard_graphic/base.tsx +2 -2
- package/test/graphic_test_app/05_chessboard_graphic/chess_variants.tsx +1 -1
- package/test/graphic_test_app/05_chessboard_graphic/flipped.tsx +6 -6
- package/test/graphic_test_app/05_chessboard_graphic/move.tsx +3 -3
- package/test/graphic_test_app/05_chessboard_graphic/theme.tsx +4 -4
- package/test/graphic_test_app/06_chessboard_animation/base_1.tsx +7 -7
- package/test/graphic_test_app/06_chessboard_animation/base_2.tsx +7 -7
- package/test/graphic_test_app/06_chessboard_animation/base_3.tsx +7 -7
- package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +4 -3
- package/test/graphic_test_app/06_chessboard_animation/sound.tsx +52 -0
- package/test/graphic_test_app/07_chessboard_interaction/click_squares.tsx +1 -1
- package/test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx +1 -1
- package/test/graphic_test_app/07_chessboard_interaction/error.tsx +1 -1
- package/test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx +1 -1
- package/test/graphic_test_app/08_chessboard_play_moves/base.tsx +1 -1
- package/test/graphic_test_app/08_chessboard_play_moves/promotions.tsx +1 -1
- package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +1 -1
- package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/base.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/error.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/html.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/options.tsx +1 -1
- package/test/graphic_test_app/11_movetext_interaction/error.tsx +1 -1
- package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +1 -1
- package/test/graphic_test_app/12_navigation_board_base/controlled.tsx +1 -1
- package/test/graphic_test_app/12_navigation_board_base/uncontrolled.tsx +1 -1
- package/test/graphic_test_app/13_navigation_board_graphic/additional_buttons.tsx +1 -1
- package/test/graphic_test_app/13_navigation_board_graphic/error.tsx +1 -1
- package/test/graphic_test_app/13_navigation_board_graphic/theme.tsx +1 -1
- package/test/graphic_test_app/14_navigation_board_autoplay/controlled.tsx +2 -2
- package/test/graphic_test_app/14_navigation_board_autoplay/uncontrolled.tsx +1 -1
- package/test/graphic_test_app/common/decs.d.ts +1 -1
- package/test/graphic_test_app/common/test_app.css +1 -1
- package/test/graphic_test_app/common/test_app.tsx +6 -5
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -50,6 +50,7 @@ interface PageState {
|
|
|
50
50
|
moveArrowVisible: boolean,
|
|
51
51
|
moveArrowColor: AnnotationColor,
|
|
52
52
|
animated: boolean,
|
|
53
|
+
sound: boolean,
|
|
53
54
|
editedMove: string,
|
|
54
55
|
playedMove: string,
|
|
55
56
|
}
|
|
@@ -69,6 +70,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
69
70
|
moveArrowVisible: true,
|
|
70
71
|
moveArrowColor: 'b',
|
|
71
72
|
animated: true,
|
|
73
|
+
sound: true,
|
|
72
74
|
editedMove: 'Nf6',
|
|
73
75
|
playedMove: 'e4',
|
|
74
76
|
};
|
|
@@ -96,6 +98,10 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
96
98
|
label="Animation" disabled={!this.state.positionAfter}
|
|
97
99
|
control={<Switch checked={this.state.animated} onChange={() => this.setState({ animated: !this.state.animated })} color="primary" />}
|
|
98
100
|
/>
|
|
101
|
+
<FormControlLabel
|
|
102
|
+
label="Sound" disabled={!this.state.positionAfter}
|
|
103
|
+
control={<Switch checked={this.state.sound} onChange={() => this.setState({ sound: !this.state.sound })} color="primary" />}
|
|
104
|
+
/>
|
|
99
105
|
<FormControlLabel
|
|
100
106
|
label="Show move arrow" disabled={!this.state.positionAfter}
|
|
101
107
|
control={<Switch checked={this.state.moveArrowVisible} onChange={() => this.setState({ moveArrowVisible: !this.state.moveArrowVisible })} color="primary" />}
|
|
@@ -139,6 +145,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
139
145
|
moveArrowVisible={this.state.moveArrowVisible}
|
|
140
146
|
moveArrowColor={this.state.moveArrowColor}
|
|
141
147
|
animated={this.state.animated}
|
|
148
|
+
sound={this.state.sound}
|
|
142
149
|
/>
|
|
143
150
|
</Box>
|
|
144
151
|
);
|
|
@@ -154,6 +161,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
154
161
|
attributes.push('flipped');
|
|
155
162
|
}
|
|
156
163
|
attributes.push(`animated={${this.state.animated}}`);
|
|
164
|
+
attributes.push(`sound={${this.state.sound}}`);
|
|
157
165
|
attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
|
|
158
166
|
if (this.state.moveArrowVisible) {
|
|
159
167
|
attributes.push(`moveArrowColor={${this.state.moveArrowColor}}`);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -131,7 +131,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
131
131
|
const button = <Button size="small" onClick={() => this.setState({ withPopup: !this.state.withPopup })}>{this.state.withPopup ? 'Reduce' : 'Open'}</Button>;
|
|
132
132
|
const { position, move, csl, cal } = this.getCurrentPositionAndAnnotations();
|
|
133
133
|
const content = this.state.withPopup ?
|
|
134
|
-
<Stack><Chessboard position={position} move={move} squareMarkers={csl} arrowMarkers={cal} animated
|
|
134
|
+
<Stack><Chessboard position={position} move={move} squareMarkers={csl} arrowMarkers={cal} animated sound />{button}</Stack> :
|
|
135
135
|
button;
|
|
136
136
|
return <Paper className="kokopu-fixedPopup" elevation={3}>{content}</Paper>;
|
|
137
137
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -56,6 +56,7 @@ interface PageState {
|
|
|
56
56
|
moveArrowVisible: boolean,
|
|
57
57
|
moveArrowColor: AnnotationColor,
|
|
58
58
|
animated: boolean,
|
|
59
|
+
sound: boolean,
|
|
59
60
|
playButtonVisible: boolean,
|
|
60
61
|
flipButtonVisible: boolean,
|
|
61
62
|
}
|
|
@@ -74,6 +75,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
74
75
|
moveArrowVisible: true,
|
|
75
76
|
moveArrowColor: 'b',
|
|
76
77
|
animated: true,
|
|
78
|
+
sound: true,
|
|
77
79
|
playButtonVisible: true,
|
|
78
80
|
flipButtonVisible: true,
|
|
79
81
|
};
|
|
@@ -109,10 +111,16 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
109
111
|
label="Show turn"
|
|
110
112
|
control={<Switch checked={this.state.turnVisible} onChange={() => this.setState({ turnVisible: !this.state.turnVisible })} color="primary" />}
|
|
111
113
|
/>
|
|
114
|
+
</Stack>
|
|
115
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
112
116
|
<FormControlLabel
|
|
113
|
-
label="
|
|
117
|
+
label="Animation"
|
|
114
118
|
control={<Switch checked={this.state.animated} onChange={() => this.setState({ animated: !this.state.animated })} color="primary" />}
|
|
115
119
|
/>
|
|
120
|
+
<FormControlLabel
|
|
121
|
+
label="Sound"
|
|
122
|
+
control={<Switch checked={this.state.sound} onChange={() => this.setState({ sound: !this.state.sound })} color="primary" />}
|
|
123
|
+
/>
|
|
116
124
|
</Stack>
|
|
117
125
|
<Box>
|
|
118
126
|
<Typography gutterBottom>Square size</Typography>
|
|
@@ -173,6 +181,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
173
181
|
moveArrowVisible={this.state.moveArrowVisible}
|
|
174
182
|
moveArrowColor={this.state.moveArrowColor}
|
|
175
183
|
animated={this.state.animated}
|
|
184
|
+
sound={this.state.sound}
|
|
176
185
|
playButtonVisible={this.state.playButtonVisible}
|
|
177
186
|
flipButtonVisible={this.state.flipButtonVisible}
|
|
178
187
|
/>
|
|
@@ -194,6 +203,7 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
194
203
|
attributes.push(`moveArrowColor="${this.state.moveArrowColor}"`);
|
|
195
204
|
}
|
|
196
205
|
attributes.push(`animated={${this.state.animated}}`);
|
|
206
|
+
attributes.push(`sound={${this.state.sound}}`);
|
|
197
207
|
attributes.push(`playButtonVisible={${this.state.playButtonVisible}}`);
|
|
198
208
|
attributes.push(`flipButtonVisible={${this.state.flipButtonVisible}}`);
|
|
199
209
|
const pgnDeclaration = 'const pgn = `\n' + pgn.trim() + '`;\n\n';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -83,11 +83,11 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
83
83
|
return (
|
|
84
84
|
<Box display="flex" alignItems="top" justifyContent="space-around">
|
|
85
85
|
<Box>
|
|
86
|
-
<NavigationBoard game={pgn} animated initialNodeId="9b" />
|
|
86
|
+
<NavigationBoard game={pgn} animated sound initialNodeId="9b" />
|
|
87
87
|
<Typography mt={2} textAlign="center">Uncontrolled</Typography>
|
|
88
88
|
</Box>
|
|
89
89
|
<Box>
|
|
90
|
-
<NavigationBoard game={pgn} animated nodeId={this.state.nodeId} onNodeIdChanged={nodeId => this.setState({ nodeId: nodeId })} />
|
|
90
|
+
<NavigationBoard game={pgn} animated sound nodeId={this.state.nodeId} onNodeIdChanged={nodeId => this.setState({ nodeId: nodeId })} />
|
|
91
91
|
<Typography mt={2} textAlign="center">Controlled</Typography>
|
|
92
92
|
<Typography textAlign="center">{`Current node ID: ${this.state.nodeId}`}</Typography>
|
|
93
93
|
</Box>
|
|
@@ -100,11 +100,13 @@ export default class Page extends React.Component<object, PageState> {
|
|
|
100
100
|
const uncontrolledAttributes: string[] = [];
|
|
101
101
|
uncontrolledAttributes.push('game={pgn}');
|
|
102
102
|
uncontrolledAttributes.push('animated');
|
|
103
|
+
uncontrolledAttributes.push('sound');
|
|
103
104
|
uncontrolledAttributes.push('initialNodeId="9b"');
|
|
104
105
|
|
|
105
106
|
const controlledAttributes: string[] = [];
|
|
106
107
|
controlledAttributes.push('game={pgn}');
|
|
107
108
|
controlledAttributes.push('animated');
|
|
109
|
+
controlledAttributes.push('sound');
|
|
108
110
|
controlledAttributes.push(`nodeId="${this.state.nodeId}"`);
|
|
109
111
|
controlledAttributes.push('onNodeIdChanged={nodeId => handleNodeIdChanged(nodeId)}');
|
|
110
112
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -48,7 +48,7 @@ function NavigationBoardWithMoveText({ game }: { game: Game }) {
|
|
|
48
48
|
const [ nodeId, setNodeId ] = React.useState('start');
|
|
49
49
|
return (
|
|
50
50
|
<Stack direction="row" spacing={2}>
|
|
51
|
-
<NavigationBoard animated game={game} nodeId={nodeId} onNodeIdChanged={setNodeId} />
|
|
51
|
+
<NavigationBoard animated sound game={game} nodeId={nodeId} onNodeIdChanged={setNodeId} />
|
|
52
52
|
<Movetext
|
|
53
53
|
game={game} diagramOptions={{ squareSize: 28 }} interactionMode="selectMove" selection={nodeId}
|
|
54
54
|
onMoveSelected={n => {
|
package/doc_src/demo/decs.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
package/doc_src/demo/demo.css
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
package/doc_src/demo/util.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Kokopu-React is not a "pure" JavaScript/TypeScript library, in that it is shipped with other type of files:
|
|
2
2
|
- `*.css` files (stylesheets),
|
|
3
|
+
- `*.ogg` files (sounds),
|
|
3
4
|
- `*.png` files (images),
|
|
4
5
|
- `*.woff` and `*.woff2` files (fonts).
|
|
5
6
|
|
|
@@ -17,7 +18,7 @@ module.exports = {
|
|
|
17
18
|
// ... or any other configuration that loads the matching files as global CSS.
|
|
18
19
|
},
|
|
19
20
|
{
|
|
20
|
-
test: /\.(png|woff|woff2)$/i,
|
|
21
|
+
test: /\.(ogg|png|woff|woff2)$/i,
|
|
21
22
|
type: 'asset/resource',
|
|
22
23
|
// ... or any other configuration that loads the matching files as resources.
|
|
23
24
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokopu-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "A React-based library to create and display chessboard and chess-related components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chess",
|
|
@@ -43,42 +43,43 @@
|
|
|
43
43
|
"htmlparser2": "^9.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/preset-env": "^7.28.
|
|
47
|
-
"@babel/preset-react": "^7.
|
|
46
|
+
"@babel/preset-env": "^7.28.5",
|
|
47
|
+
"@babel/preset-react": "^7.28.5",
|
|
48
48
|
"@emotion/react": "^11.14.0",
|
|
49
49
|
"@emotion/styled": "^11.14.1",
|
|
50
|
-
"@eslint/js": "^9.
|
|
51
|
-
"@mui/material": "^7.3.
|
|
52
|
-
"@stylistic/eslint-plugin": "^5.
|
|
53
|
-
"@types/react": "^19.2.
|
|
54
|
-
"@types/react-dom": "^19.2.
|
|
50
|
+
"@eslint/js": "^9.39.2",
|
|
51
|
+
"@mui/material": "^7.3.7",
|
|
52
|
+
"@stylistic/eslint-plugin": "^5.7.0",
|
|
53
|
+
"@types/react": "^19.2.8",
|
|
54
|
+
"@types/react-dom": "^19.2.3",
|
|
55
55
|
"babel-loader": "^10.0.0",
|
|
56
56
|
"copy-webpack-plugin": "^13.0.1",
|
|
57
57
|
"copyfiles": "^2.4.1",
|
|
58
58
|
"coverage-istanbul-loader": "^3.0.5",
|
|
59
59
|
"css-loader": "^7.1.2",
|
|
60
|
-
"eslint": "^9.
|
|
60
|
+
"eslint": "^9.39.2",
|
|
61
61
|
"eslint-plugin-react": "^7.37.5",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
62
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
63
|
+
"globals": "^17.0.0",
|
|
64
|
+
"html-webpack-plugin": "^5.6.5",
|
|
64
65
|
"img-diff-js": "^0.5.4",
|
|
65
|
-
"kokopu": "^4.
|
|
66
|
-
"mocha": "^11.7.
|
|
66
|
+
"kokopu": "^4.13.1",
|
|
67
|
+
"mocha": "^11.7.5",
|
|
67
68
|
"null-loader": "^4.0.1",
|
|
68
69
|
"nyc": "^17.1.0",
|
|
69
|
-
"react": "^19.2.
|
|
70
|
+
"react": "^19.2.3",
|
|
70
71
|
"react-docgen-typescript": "~2.2.2",
|
|
71
|
-
"react-dom": "^19.2.
|
|
72
|
+
"react-dom": "^19.2.3",
|
|
72
73
|
"react-styleguidist": "^13.1.4",
|
|
73
|
-
"rimraf": "^6.
|
|
74
|
-
"selenium-webdriver": "^4.
|
|
74
|
+
"rimraf": "^6.1.2",
|
|
75
|
+
"selenium-webdriver": "^4.39.0",
|
|
75
76
|
"ssh2-sftp-client": "^12.0.1",
|
|
76
77
|
"style-loader": "^4.0.0",
|
|
77
78
|
"ts-loader": "^9.5.4",
|
|
78
79
|
"typescript": "^5.9.3",
|
|
79
|
-
"typescript-eslint": "^8.
|
|
80
|
+
"typescript-eslint": "^8.52.0",
|
|
80
81
|
"unit.js": "^2.1.1",
|
|
81
|
-
"webpack": "^5.
|
|
82
|
+
"webpack": "^5.104.1",
|
|
82
83
|
"webpack-cli": "^6.0.1"
|
|
83
84
|
},
|
|
84
85
|
"scripts": {
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
"test_env:stop": "docker compose -p kokopu-react-test-env -f scripts/docker-compose.yml down",
|
|
94
95
|
"build": "npm run build:lib && npm run build:doc",
|
|
95
96
|
"build:doc": "rimraf dist/docs && styleguidist build --config scripts/doc.styleguide.config.js && copyfiles -u 2 'doc_src/theming/*.png' dist/docs",
|
|
96
|
-
"build:lib": "rimraf dist/lib && tsc --outDir dist/lib && copyfiles -u 1 'src/**/*.{css,png,woff,woff2}' dist/lib",
|
|
97
|
+
"build:lib": "rimraf dist/lib && tsc --outDir dist/lib && copyfiles -u 1 'src/**/*.{css,ogg,png,woff,woff2}' dist/lib",
|
|
97
98
|
"start": "styleguidist server --open --config scripts/doc.styleguide.config.js",
|
|
98
99
|
"clean": "rimraf build dist"
|
|
99
100
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -134,7 +134,7 @@ module.exports = {
|
|
|
134
134
|
use: [ 'style-loader', 'css-loader' ],
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
|
-
test: /\.(png|woff|woff2)$/i,
|
|
137
|
+
test: /\.(ogg|png|woff|woff2)$/i,
|
|
138
138
|
type: 'asset/resource',
|
|
139
139
|
},
|
|
140
140
|
{
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -85,7 +85,7 @@ module.exports = {
|
|
|
85
85
|
use: [ 'style-loader', 'css-loader' ],
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
test: /\.(png|woff|woff2)$/i,
|
|
88
|
+
test: /\.(ogg|png|woff|woff2)$/i,
|
|
89
89
|
type: 'asset/resource',
|
|
90
90
|
},
|
|
91
91
|
{
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -49,7 +49,7 @@ module.exports = {
|
|
|
49
49
|
use: 'null-loader',
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
test: /\.(png|woff|woff2)$/i,
|
|
52
|
+
test: /\.(ogg|png|woff|woff2)$/i,
|
|
53
53
|
use: 'null-loader',
|
|
54
54
|
},
|
|
55
55
|
],
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -104,6 +104,11 @@ export interface DynamicBoardGraphicProps extends StaticBoardGraphicProps {
|
|
|
104
104
|
* Whether moves are animated or not.
|
|
105
105
|
*/
|
|
106
106
|
animated: boolean,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Whether sound effects are enabled or not.
|
|
110
|
+
*/
|
|
111
|
+
sound: boolean,
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
|
|
@@ -127,5 +132,6 @@ export function defaultDynamicBoardProps(): DynamicBoardGraphicProps {
|
|
|
127
132
|
moveArrowVisible: true,
|
|
128
133
|
moveArrowColor: 'b',
|
|
129
134
|
animated: false,
|
|
135
|
+
sound: false,
|
|
130
136
|
};
|
|
131
137
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -228,6 +228,7 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
|
|
|
228
228
|
throw new IllegalArgument('Chessboard', 'moveArrowColor');
|
|
229
229
|
}
|
|
230
230
|
const animated = sanitizeBoolean(this.props.animated);
|
|
231
|
+
const sound = sanitizeBoolean(this.props.sound);
|
|
231
232
|
const colorset = colorsets[this.props.colorset];
|
|
232
233
|
if (!colorset) {
|
|
233
234
|
throw new IllegalArgument('Chessboard', 'colorset');
|
|
@@ -263,7 +264,7 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
|
|
|
263
264
|
key={key}
|
|
264
265
|
position={position} move={move} squareMarkers={sqm} textMarkers={txtm} arrowMarkers={arm} flipped={flipped}
|
|
265
266
|
squareSize={actualSquareSize} coordinateVisible={actualCoordinateVisible} turnVisible={actualTurnVisible}
|
|
266
|
-
moveArrowVisible={moveArrowVisible} moveArrowColor={this.props.moveArrowColor} animated={animated}
|
|
267
|
+
moveArrowVisible={moveArrowVisible} moveArrowColor={this.props.moveArrowColor} animated={animated} sound={sound}
|
|
267
268
|
colorset={colorset} pieceset={pieceset}
|
|
268
269
|
interactionMode={interactionMode} editedArrowColor={this.props.editedArrowColor}
|
|
269
270
|
onPieceMoved={onPieceMoved} onSquareClicked={onSquareClicked} onArrowEdited={onArrowEdited} onMovePlayed={onMovePlayed}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -33,6 +33,7 @@ import { AnnotationSymbolShape } from '../icons/AnnotationSymbolShape';
|
|
|
33
33
|
import { ArrowTip } from '../icons/ArrowTip';
|
|
34
34
|
import { Draggable } from './Draggable';
|
|
35
35
|
import { Motion } from './Motion';
|
|
36
|
+
import { Sound } from './Sound';
|
|
36
37
|
|
|
37
38
|
import '../icons/arrow.css';
|
|
38
39
|
import './Chessboard.css';
|
|
@@ -66,6 +67,7 @@ interface ChessboardImplProps {
|
|
|
66
67
|
moveArrowVisible: boolean,
|
|
67
68
|
moveArrowColor: AnnotationColor,
|
|
68
69
|
animated: boolean,
|
|
70
|
+
sound: boolean,
|
|
69
71
|
colorset: Colorset,
|
|
70
72
|
pieceset: Pieceset,
|
|
71
73
|
|
|
@@ -145,6 +147,7 @@ export class ChessboardImpl extends React.Component<ChessboardImplProps, Chessbo
|
|
|
145
147
|
{rankCoordinates}
|
|
146
148
|
{fileCoordinates}
|
|
147
149
|
{this.renderBoardContent()}
|
|
150
|
+
{this.props.move && this.props.sound ? <Sound /> : undefined}
|
|
148
151
|
</svg>
|
|
149
152
|
);
|
|
150
153
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -0,0 +1,71 @@
|
|
|
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-2026 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 moveSound from './sounds/move.ogg';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Play a sound.
|
|
32
|
+
*/
|
|
33
|
+
export function Sound() {
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const audio = new Audio(moveSound);
|
|
37
|
+
safePlay(audio);
|
|
38
|
+
return () => audio.pause();
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
declare global {
|
|
46
|
+
|
|
47
|
+
// WARNING: this global variable exists only for testing purposes. DO NOT USE IT IN PRODUCTION.
|
|
48
|
+
var __kokopu_debug_sound: string; // eslint-disable-line camelcase
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async function safePlay(audio: HTMLAudioElement) {
|
|
53
|
+
try {
|
|
54
|
+
|
|
55
|
+
const debugSound = window.__kokopu_debug_sound === '';
|
|
56
|
+
// istanbul ignore else
|
|
57
|
+
if (debugSound) {
|
|
58
|
+
window['__kokopu_debug_sound'] = 'sound-in-progress';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await audio.play();
|
|
62
|
+
|
|
63
|
+
// istanbul ignore else
|
|
64
|
+
if (debugSound) {
|
|
65
|
+
window['__kokopu_debug_sound'] = 'sound-done';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e) { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
69
|
+
// Ignore the errors (can typically happen if the audio is interrupted while fetching the sound file).
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* *
|
|
4
4
|
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
5
|
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
-
* Copyright (C) 2021-
|
|
6
|
+
* Copyright (C) 2021-2026 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
7
|
* *
|
|
8
8
|
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
Binary file
|