kokopu-react 1.4.0 → 1.5.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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/lib/ArrowMarkerIcon.js +3 -3
- package/dist/lib/Chessboard.js +6 -8
- package/dist/lib/ErrorBox.js +85 -5
- package/dist/lib/Movetext.js +851 -0
- package/dist/lib/SquareMarkerIcon.js +1 -1
- package/dist/lib/TextMarkerIcon.js +1 -1
- package/dist/lib/css/arrow.css +1 -1
- package/dist/lib/css/chessboard.css +6 -1
- package/dist/lib/css/error_box.css +13 -2
- package/dist/lib/css/{label.css → fonts.css} +11 -6
- package/dist/lib/css/movetext.css +117 -0
- package/dist/lib/css/symbol.css +9 -1
- package/dist/lib/fonts/chessalpha.woff +0 -0
- package/dist/lib/fonts/chessalpha.woff2 +0 -0
- package/dist/lib/i18n.js +17 -2
- package/dist/lib/impl/ArrowTip.js +1 -1
- package/dist/lib/impl/HtmlSanitizer.js +171 -0
- package/dist/lib/impl/TextSymbol.js +2 -4
- package/dist/lib/impl/colorsets.js +1 -1
- package/dist/lib/impl/piecesets.js +1 -1
- package/dist/lib/impl/util.js +1 -1
- package/dist/lib/index.js +8 -0
- package/doc_src/demo/PageChessboardBase.js +1 -1
- package/doc_src/demo/{PageChessboardEdition.js → PageChessboardInteraction.js} +2 -4
- package/doc_src/demo/PageChessboardMove.js +1 -1
- package/doc_src/demo/PageChessboardSmallScreens.js +1 -1
- package/doc_src/demo/PageMovetextBase.js +214 -0
- package/doc_src/demo/PageMovetextInteraction.js +159 -0
- package/doc_src/demo/demo.css +8 -1
- package/doc_src/demo/game-1.pgn +23 -0
- package/doc_src/demo/game-2.pgn +22 -0
- package/doc_src/demo/game-invalid.pgn +10 -0
- package/doc_src/demo/util.js +1 -1
- package/doc_src/examples/Movetext.md +15 -0
- package/doc_src/home.md +2 -0
- package/doc_src/theming/LogoRenderer.js +1 -1
- package/doc_src/theming/theming.css +1 -1
- package/graphic_test_app/01_marker_icons.js +1 -1
- package/graphic_test_app/02_chessboard_simple.js +1 -1
- package/graphic_test_app/03_chessboard_flipped.js +1 -1
- package/graphic_test_app/04_chessboard_annotations.js +1 -1
- package/graphic_test_app/05_chessboard_move.js +1 -1
- package/graphic_test_app/06_chessboard_theme.js +1 -1
- package/graphic_test_app/07_chessboard_click_squares.js +1 -1
- package/graphic_test_app/08_chessboard_move_pieces.js +1 -1
- package/graphic_test_app/09_chessboard_edit_arrows.js +1 -1
- package/graphic_test_app/10_chessboard_play_moves.js +1 -1
- package/graphic_test_app/11_chessboard_play_promotions.js +1 -1
- package/graphic_test_app/12_movetext_simple.js +41 -0
- package/graphic_test_app/13_movetext_error.js +38 -0
- package/graphic_test_app/14_movetext_html.js +40 -0
- package/graphic_test_app/15_movetext_options.js +42 -0
- package/graphic_test_app/16_movetext_interaction.js +42 -0
- package/graphic_test_app/common/dummy.pgn +8 -0
- package/graphic_test_app/common/games.pgn +167 -0
- package/graphic_test_app/common/heartbeat.txt +1 -0
- package/graphic_test_app/common/test_app.css +20 -4
- package/graphic_test_app/common/test_app.js +6 -6
- package/package.json +26 -25
- package/scripts/test_graphic/clean-graphic-output.js +1 -1
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +7 -3
- package/scripts/test_headless.webpack-config.js +2 -2
- package/src/ArrowMarkerIcon.js +1 -1
- package/src/Chessboard.js +6 -7
- package/src/ErrorBox.js +80 -1
- package/src/Movetext.js +627 -0
- package/src/SquareMarkerIcon.js +1 -1
- package/src/TextMarkerIcon.js +1 -1
- package/src/css/arrow.css +1 -1
- package/src/css/chessboard.css +6 -1
- package/src/css/error_box.css +13 -2
- package/src/css/{label.css → fonts.css} +11 -6
- package/src/css/movetext.css +117 -0
- package/src/css/symbol.css +9 -1
- package/src/fonts/chessalpha.woff +0 -0
- package/src/fonts/chessalpha.woff2 +0 -0
- package/src/i18n.js +12 -1
- package/src/impl/ArrowTip.js +1 -1
- package/src/impl/HtmlSanitizer.js +120 -0
- package/src/impl/TextSymbol.js +2 -3
- package/src/impl/colorsets.js +1 -1
- package/src/impl/piecesets.js +1 -1
- package/src/impl/util.js +1 -1
- package/src/index.js +2 -1
- package/src/markers.js +1 -1
- package/test/1_markers.js +1 -1
- package/test/2_chessboard_util.js +1 -1
- package/test/3_marker_icons_graphic.js +1 -1
- package/test/4_chessboard_graphic.js +1 -1
- package/test/5_chessboard_interaction.js +1 -1
- package/test/6_chessboard_play_moves.js +1 -1
- package/test/7_movetext_graphic.js +43 -0
- package/test/8_movetext_interaction.js +103 -0
- package/test/common/graphic.js +2 -2
- package/test/references/01_marker_icons/0.png +0 -0
- package/test/references/01_marker_icons/1.png +0 -0
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/2.png +0 -0
- package/test/references/01_marker_icons/3.png +0 -0
- package/test/references/01_marker_icons/4.png +0 -0
- package/test/references/01_marker_icons/5.png +0 -0
- package/test/references/01_marker_icons/6.png +0 -0
- package/test/references/01_marker_icons/7.png +0 -0
- package/test/references/01_marker_icons/8.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/02_chessboard_simple/0.png +0 -0
- package/test/references/02_chessboard_simple/1.png +0 -0
- package/test/references/02_chessboard_simple/2.png +0 -0
- package/test/references/02_chessboard_simple/3.png +0 -0
- package/test/references/02_chessboard_simple/4.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/03_chessboard_flipped/0.png +0 -0
- package/test/references/03_chessboard_flipped/1.png +0 -0
- package/test/references/03_chessboard_flipped/2.png +0 -0
- package/test/references/03_chessboard_flipped/3.png +0 -0
- package/test/references/03_chessboard_flipped/4.png +0 -0
- package/test/references/04_chessboard_annotations/0.png +0 -0
- package/test/references/04_chessboard_annotations/1.png +0 -0
- package/test/references/04_chessboard_annotations/2.png +0 -0
- package/test/references/04_chessboard_annotations/3.png +0 -0
- package/test/references/04_chessboard_annotations/4.png +0 -0
- package/test/references/04_chessboard_annotations/5.png +0 -0
- package/test/references/05_chessboard_move/0.png +0 -0
- package/test/references/05_chessboard_move/1.png +0 -0
- package/test/references/05_chessboard_move/2.png +0 -0
- package/test/references/05_chessboard_move/3.png +0 -0
- package/test/references/05_chessboard_move/4.png +0 -0
- package/test/references/05_chessboard_move/5.png +0 -0
- package/test/references/05_chessboard_move/6.png +0 -0
- package/test/references/05_chessboard_move/7.png +0 -0
- package/test/references/05_chessboard_move/8.png +0 -0
- package/test/references/06_chessboard_theme/0.png +0 -0
- package/test/references/06_chessboard_theme/1.png +0 -0
- package/test/references/06_chessboard_theme/2.png +0 -0
- package/test/references/06_chessboard_theme/3.png +0 -0
- package/test/references/06_chessboard_theme/4.png +0 -0
- package/test/references/06_chessboard_theme/5.png +0 -0
- package/test/references/06_chessboard_theme/6.png +0 -0
- package/test/references/06_chessboard_theme/7.png +0 -0
- package/test/references/06_chessboard_theme/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
- package/test/references/12_movetext_simple/0.png +0 -0
- package/test/references/12_movetext_simple/1.png +0 -0
- package/test/references/12_movetext_simple/2.png +0 -0
- package/test/references/12_movetext_simple/3.png +0 -0
- package/test/references/13_movetext_error/0.png +0 -0
- package/test/references/13_movetext_error/1.png +0 -0
- package/test/references/13_movetext_error/2.png +0 -0
- package/test/references/13_movetext_error/3.png +0 -0
- package/test/references/14_movetext_html/0.png +0 -0
- package/test/references/14_movetext_html/1.png +0 -0
- package/test/references/14_movetext_html/2.png +0 -0
- package/test/references/15_movetext_options/0.png +0 -0
- package/test/references/15_movetext_options/1.png +0 -0
- package/test/references/15_movetext_options/2.png +0 -0
- package/test/references/15_movetext_options/3.png +0 -0
- package/test/references/16_movetext_interaction/0.png +0 -0
- package/test/references/16_movetext_interaction/1.png +0 -0
- package/test/references/16_movetext_interaction/2.png +0 -0
- package/graphic_test_app/common/healthcheck.txt +0 -1
package/src/Chessboard.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -37,7 +37,6 @@ import { MIN_SQUARE_SIZE, MAX_SQUARE_SIZE, sanitizeInteger, generateRandomId, is
|
|
|
37
37
|
|
|
38
38
|
import './css/chessboard.css';
|
|
39
39
|
import './css/arrow.css';
|
|
40
|
-
import './css/label.css';
|
|
41
40
|
|
|
42
41
|
const TURN_FLAG_SPACING_FACTOR = 0.1;
|
|
43
42
|
const RANK_COORDINATE_WIDTH_FACTOR = 1;
|
|
@@ -84,10 +83,10 @@ export default class Chessboard extends React.Component {
|
|
|
84
83
|
// Compute the current position.
|
|
85
84
|
let info = this.getPositionAndMoveInfo();
|
|
86
85
|
if (info.positionError) {
|
|
87
|
-
return <ErrorBox title={i18n.INVALID_FEN_ERROR_TITLE} message={info.message}
|
|
86
|
+
return <ErrorBox title={i18n.INVALID_FEN_ERROR_TITLE} message={info.message} />;
|
|
88
87
|
}
|
|
89
88
|
else if (info.moveError) {
|
|
90
|
-
return <ErrorBox title={i18n.INVALID_NOTATION_ERROR_TITLE} message={info.message}
|
|
89
|
+
return <ErrorBox title={i18n.INVALID_NOTATION_ERROR_TITLE} message={info.message} />;
|
|
91
90
|
}
|
|
92
91
|
let { position, move, positionBefore } = info;
|
|
93
92
|
|
|
@@ -420,14 +419,14 @@ export default class Chessboard extends React.Component {
|
|
|
420
419
|
let x = Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) / 2;
|
|
421
420
|
let y = (this.props.flipped ? rank + 0.5 : 7.5 - rank) * squareSize;
|
|
422
421
|
let label = RANK_LABELS[rank];
|
|
423
|
-
return <text key={'rank-' + label} className="kokopu-coordinate
|
|
422
|
+
return <text key={'rank-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
424
423
|
}
|
|
425
424
|
|
|
426
425
|
renderFileCoordinate(squareSize, fontSize, file) {
|
|
427
426
|
let x = (this.props.flipped ? 7.5 - file : 0.5 + file) * squareSize;
|
|
428
427
|
let y = 8 * squareSize + Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize) / 2;
|
|
429
428
|
let label = FILE_LABELS[file];
|
|
430
|
-
return <text key={'file-' + label} className="kokopu-coordinate
|
|
429
|
+
return <text key={'file-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
431
430
|
}
|
|
432
431
|
|
|
433
432
|
handleWindowResize() {
|
|
@@ -581,7 +580,7 @@ export default class Chessboard extends React.Component {
|
|
|
581
580
|
}
|
|
582
581
|
|
|
583
582
|
/**
|
|
584
|
-
* Return information regarding the
|
|
583
|
+
* Return information regarding the currently displayed position and move, or parsing error message if something went wrong.
|
|
585
584
|
*/
|
|
586
585
|
getPositionAndMoveInfo() {
|
|
587
586
|
|
package/src/ErrorBox.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -23,21 +23,31 @@
|
|
|
23
23
|
import PropTypes from 'prop-types';
|
|
24
24
|
import React from 'react';
|
|
25
25
|
|
|
26
|
+
import i18n from './i18n';
|
|
27
|
+
|
|
26
28
|
import './css/error_box.css';
|
|
27
29
|
|
|
30
|
+
const BACKWARD_CHARACTERS = 5;
|
|
31
|
+
const FORWARD_CHARACTERS = 36;
|
|
32
|
+
|
|
33
|
+
|
|
28
34
|
|
|
29
35
|
/**
|
|
30
36
|
* Display an error message.
|
|
31
37
|
*/
|
|
32
38
|
export default function ErrorBox(props) {
|
|
39
|
+
let excerpt = typeof props.text === 'string' && props.errorIndex >= 0 && props.errorIndex < props.text.length ?
|
|
40
|
+
<div className="kokopu-errorExcerpt">{ellipsisAt(props.text, props.errorIndex, BACKWARD_CHARACTERS, FORWARD_CHARACTERS, props.lineNumber)}</div> : undefined;
|
|
33
41
|
return (
|
|
34
42
|
<div className="kokopu-errorBox">
|
|
35
43
|
<div className="kokopu-errorTitle">{props.title}</div>
|
|
36
44
|
<div className="kokopu-errorMessage">{props.message}</div>
|
|
45
|
+
{excerpt}
|
|
37
46
|
</div>
|
|
38
47
|
);
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
|
|
41
51
|
ErrorBox.propTypes = {
|
|
42
52
|
|
|
43
53
|
/**
|
|
@@ -49,4 +59,73 @@ ErrorBox.propTypes = {
|
|
|
49
59
|
* Additional message providing details about the error.
|
|
50
60
|
*/
|
|
51
61
|
message: PropTypes.string.isRequired,
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Raw text whose processing results in the error.
|
|
65
|
+
*/
|
|
66
|
+
text: PropTypes.string,
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Index of the character within `text` that results in the error.
|
|
70
|
+
*/
|
|
71
|
+
errorIndex: PropTypes.number,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Index (1-based) of the line in which is the character that results in the error.
|
|
75
|
+
*/
|
|
76
|
+
lineNumber: PropTypes.number,
|
|
52
77
|
};
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Ellipsis function.
|
|
82
|
+
*
|
|
83
|
+
* Example: if `text` is `0123456789`, then `ellipsis(text, 5, 1, 3)` returns
|
|
84
|
+
* the following string:
|
|
85
|
+
*
|
|
86
|
+
* ```
|
|
87
|
+
* ...45678...
|
|
88
|
+
* ^
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param {string} text Text from a substring must be extracted.
|
|
92
|
+
* @param {number} pos Index of the character in `text` around which the substring must be extracted.
|
|
93
|
+
* @param {number} backwardCharacters Number of characters to keep before `pos`.
|
|
94
|
+
* @param {number} forwardCharacters Number of characters to keep after `pos`.
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
function ellipsisAt(text, pos, backwardCharacters, forwardCharacters, lineNumber) {
|
|
98
|
+
|
|
99
|
+
// p1 => begin of the extracted sub-string
|
|
100
|
+
let p1 = pos;
|
|
101
|
+
let e1 = '... ';
|
|
102
|
+
while (p1 > pos - backwardCharacters) {
|
|
103
|
+
--p1;
|
|
104
|
+
if (p1 < 0 || text.charAt(p1) === '\n' || text.charAt(p1) === '\r') {
|
|
105
|
+
++p1;
|
|
106
|
+
e1 = '';
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// p2 => one character after the end of the extracted sub-string
|
|
112
|
+
let p2 = pos;
|
|
113
|
+
let e2 = ' ...';
|
|
114
|
+
while (p2 < pos + forwardCharacters) {
|
|
115
|
+
++p2;
|
|
116
|
+
if (p2 >= text.length || text.charAt(p2) === '\n' || text.charAt(p2) === '\r') {
|
|
117
|
+
--p2;
|
|
118
|
+
e2 = '';
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Extract the sub-string around the requested position.
|
|
124
|
+
let excerpt = e1 + text.substring(p1, p2 + 1) + e2;
|
|
125
|
+
excerpt = excerpt.replace(/\n|\r|\t/g, ' ');
|
|
126
|
+
let secondLine = Array(1 + e1.length + pos - p1).join(' ') + '^';
|
|
127
|
+
if (lineNumber) {
|
|
128
|
+
secondLine += ' (' + i18n.LINE.replace(/\{0\}/g, lineNumber) + ')';
|
|
129
|
+
}
|
|
130
|
+
return excerpt + '\n' + secondLine;
|
|
131
|
+
}
|