cm-chessboard 7.3.3 → 7.3.5
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/README.md +2 -1
- package/examples/extensions/accessibility-extension.html +4 -0
- package/examples/simple-boards.html +3 -4
- package/examples/validate-moves.html +4 -2
- package/package.json +1 -1
- package/src/cm-chessboard/extensions/accessibility/Accessibility.js +9 -9
- package/src/cm-chessboard/lib/Utils.js +11 -0
- package/src/cm-chessboard/model/ChessboardState.js +1 -35
- package/src/cm-chessboard/view/ChessboardView.js +1 -1
- package/src/cm-chessboard/view/VisualMoveInput.js +2 -2
- package/test/TestPiecesAnimation.js +3 -2
package/README.md
CHANGED
|
@@ -356,8 +356,9 @@ export const EXTENSION_POINT = {
|
|
|
356
356
|
positionChanged: "positionChanged", // the positions of the pieces was changed
|
|
357
357
|
boardChanged: "boardChanged", // the board (orientation) was changed
|
|
358
358
|
moveInputToggled: "moveInputToggled", // move input was enabled or disabled
|
|
359
|
-
moveInput: "moveInput", //
|
|
359
|
+
moveInput: "moveInput", // move started, moving over a square, validating or canceled
|
|
360
360
|
redrawBoard: "redrawBoard", // called after redrawing the board
|
|
361
|
+
animation: "animation", // called on animation start, end and on every animation frame
|
|
361
362
|
destroy: "destroy" // called, before the board is destroyed
|
|
362
363
|
}
|
|
363
364
|
```
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
It allows a better usage of the board for visually impaired
|
|
17
17
|
people.
|
|
18
18
|
</p>
|
|
19
|
+
<p>
|
|
20
|
+
The <a href="../validate-moves.html">validate moves</a> example has also
|
|
21
|
+
accessibility features enabled, but visually hidden.
|
|
22
|
+
</p>
|
|
19
23
|
<h3>Features of the Accessibility extension</h3>
|
|
20
24
|
<ul>
|
|
21
25
|
<li>Enable Braille notation in the alt text of the chessboard image</li>
|
|
@@ -19,13 +19,12 @@ new Chessboard(document.getElementById("board1"), {
|
|
|
19
19
|
})
|
|
20
20
|
new Chessboard(document.getElementById("board2"), {
|
|
21
21
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
22
|
-
|
|
23
|
-
style: {pieces: {file: "staunty.svg"}},
|
|
22
|
+
style: {pieces: {file: "staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
|
|
24
23
|
orientation: COLOR.black
|
|
25
24
|
})
|
|
26
25
|
</pre>
|
|
27
26
|
<script type="module">
|
|
28
|
-
import {COLOR, Chessboard} from "../src/cm-chessboard/Chessboard.js"
|
|
27
|
+
import {COLOR, Chessboard, BORDER_TYPE} from "../src/cm-chessboard/Chessboard.js"
|
|
29
28
|
import {FEN} from "../src/cm-chessboard/model/Position.js"
|
|
30
29
|
|
|
31
30
|
new Chessboard(document.getElementById("board1"), {
|
|
@@ -36,7 +35,7 @@ new Chessboard(document.getElementById("board2"), {
|
|
|
36
35
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
37
36
|
assetsUrl: "../assets/",
|
|
38
37
|
assetsCache: false,
|
|
39
|
-
style: {pieces: {file: "staunty.svg"}},
|
|
38
|
+
style: {pieces: {file: "staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
|
|
40
39
|
orientation: COLOR.black
|
|
41
40
|
})
|
|
42
41
|
</script>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<h2>Example: Input enabled, move validation with chess.js</h2>
|
|
15
15
|
<p>Input enabled for white. <a href="https://github.com/jhlywa/chess.js">chess.js</a> does the validation and answers
|
|
16
16
|
with random moves.</p>
|
|
17
|
-
<h2 class="cm-visually-hidden">
|
|
17
|
+
<h2 class="cm-visually-hidden">Chessboard</h2>
|
|
18
18
|
<div class="board board-large" id="board"></div>
|
|
19
19
|
<h2 class="cm-visually-hidden">The Sourcecode of the example</h2>
|
|
20
20
|
<div id="output"></div>
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import {INPUT_EVENT_TYPE, COLOR, Chessboard, BORDER_TYPE} from "../src/cm-chessboard/Chessboard.js"
|
|
24
24
|
import {MARKER_TYPE, Markers} from "../src/cm-chessboard/extensions/markers/Markers.js"
|
|
25
25
|
import {PromotionDialog} from "../src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js"
|
|
26
|
+
import {Accessibility} from "../src/cm-chessboard/extensions/accessibility/Accessibility.js"
|
|
26
27
|
|
|
27
28
|
const chess = new Chess()
|
|
28
29
|
|
|
@@ -77,7 +78,8 @@
|
|
|
77
78
|
orientation: COLOR.white,
|
|
78
79
|
extensions: [
|
|
79
80
|
{class: Markers, props: {autoMarkers: MARKER_TYPE.square}},
|
|
80
|
-
{class: PromotionDialog}
|
|
81
|
+
{class: PromotionDialog},
|
|
82
|
+
{class: Accessibility, props: {visuallyHidden: true}}
|
|
81
83
|
]
|
|
82
84
|
})
|
|
83
85
|
board.enableMoveInput(inputHandler, COLOR.white)
|
package/package.json
CHANGED
|
@@ -12,9 +12,9 @@ const hlTranslations = {
|
|
|
12
12
|
pieces_lists: "Figurenlisten",
|
|
13
13
|
board_as_table: "Schachbrett als Tabelle",
|
|
14
14
|
move_piece: "Figur bewegen",
|
|
15
|
-
from: "von",
|
|
16
|
-
to: "nach",
|
|
17
|
-
move: "
|
|
15
|
+
from: "Zug von",
|
|
16
|
+
to: "Zug nach",
|
|
17
|
+
move: "Zug ausführen",
|
|
18
18
|
input_white_enabled: "Eingabe Weiß aktiviert",
|
|
19
19
|
input_black_enabled: "Eingabe Schwarz aktiviert",
|
|
20
20
|
input_disabled: "Eingabe deaktiviert"
|
|
@@ -23,9 +23,9 @@ const hlTranslations = {
|
|
|
23
23
|
pieces_lists: "Pieces lists",
|
|
24
24
|
board_as_table: "Chessboard as table",
|
|
25
25
|
move_piece: "Move piece",
|
|
26
|
-
from: "from",
|
|
27
|
-
to: "to",
|
|
28
|
-
move: "move",
|
|
26
|
+
from: "Move from",
|
|
27
|
+
to: "Move to",
|
|
28
|
+
move: "Make move",
|
|
29
29
|
input_white_enabled: "Input white enabled",
|
|
30
30
|
input_black_enabled: "Input black enabled",
|
|
31
31
|
input_disabled: "Input disabled"
|
|
@@ -38,9 +38,9 @@ export class Accessibility extends Extension {
|
|
|
38
38
|
super(chessboard, props)
|
|
39
39
|
this.props = {
|
|
40
40
|
brailleNotationInAlt: true, // show the braille notation of the position in the alt attribute of the SVG image
|
|
41
|
-
boardAsTable:
|
|
42
|
-
movePieceForm:
|
|
43
|
-
piecesAsList:
|
|
41
|
+
boardAsTable: true, // display the board additionally as HTML table
|
|
42
|
+
movePieceForm: true, // display a form to move a piece (from, to, move)
|
|
43
|
+
piecesAsList: true, // display the pieces additionally as List
|
|
44
44
|
visuallyHidden: true // hide all those extra outputs visually but keep them accessible for screen readers and braille displays
|
|
45
45
|
}
|
|
46
46
|
Object.assign(this.props, props)
|
|
@@ -38,4 +38,15 @@ export class Utils {
|
|
|
38
38
|
return target
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
static createTask() {
|
|
42
|
+
let resolve, reject
|
|
43
|
+
const promise = new Promise(function (_resolve, _reject) {
|
|
44
|
+
resolve = _resolve
|
|
45
|
+
reject = _reject
|
|
46
|
+
})
|
|
47
|
+
promise.resolve = resolve
|
|
48
|
+
promise.reject = reject
|
|
49
|
+
return promise
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
}
|
|
@@ -5,17 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import {Position} from "./Position.js"
|
|
7
7
|
|
|
8
|
-
export function createTask() {
|
|
9
|
-
let resolve, reject
|
|
10
|
-
const promise = new Promise(function (_resolve, _reject) {
|
|
11
|
-
resolve = _resolve
|
|
12
|
-
reject = _reject
|
|
13
|
-
})
|
|
14
|
-
promise.resolve = resolve
|
|
15
|
-
promise.reject = reject
|
|
16
|
-
return promise
|
|
17
|
-
}
|
|
18
|
-
|
|
19
8
|
export class ChessboardState {
|
|
20
9
|
|
|
21
10
|
constructor() {
|
|
@@ -27,30 +16,7 @@ export class ChessboardState {
|
|
|
27
16
|
this.inputEnabled = false
|
|
28
17
|
this.squareSelectEnabled = false
|
|
29
18
|
this.extensionPoints = {}
|
|
30
|
-
this.moveInputProcess =
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setPosition(fen, animated = false) {
|
|
34
|
-
this.position = new Position(fen, animated)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
movePiece(fromSquare, toSquare, animated = false) {
|
|
38
|
-
const position = this._position.clone()
|
|
39
|
-
position.animated = animated
|
|
40
|
-
const piece = position.getPiece(fromSquare)
|
|
41
|
-
if (!piece) {
|
|
42
|
-
console.error("no piece on", fromSquare)
|
|
43
|
-
}
|
|
44
|
-
position.setPiece(fromSquare, undefined)
|
|
45
|
-
position.setPiece(toSquare, piece)
|
|
46
|
-
this._position = position
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setPiece(square, piece, animated = false) {
|
|
50
|
-
const position = this._position.clone()
|
|
51
|
-
position.animated = animated
|
|
52
|
-
position.setPiece(square, piece)
|
|
53
|
-
this._position = position
|
|
19
|
+
this.moveInputProcess = Promise.resolve()
|
|
54
20
|
}
|
|
55
21
|
|
|
56
22
|
invokeExtensionPoints(name, data = {}) {
|
|
@@ -96,7 +96,7 @@ export class ChessboardView {
|
|
|
96
96
|
this.svg.setAttribute("role", "img")
|
|
97
97
|
this.updateMetrics()
|
|
98
98
|
this.boardGroup = Svg.addElement(this.svg, "g", {class: "board"})
|
|
99
|
-
this.coordinatesGroup = Svg.addElement(this.svg, "g", {class: "coordinates"})
|
|
99
|
+
this.coordinatesGroup = Svg.addElement(this.svg, "g", {class: "coordinates", "aria-hidden": "true"})
|
|
100
100
|
this.markersLayer = Svg.addElement(this.svg, "g", {class: "markers-layer"})
|
|
101
101
|
this.piecesLayer = Svg.addElement(this.svg, "g", {class: "pieces-layer"})
|
|
102
102
|
this.piecesGroup = Svg.addElement(this.piecesLayer, "g", {class: "pieces"})
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {Svg} from "../lib/Svg.js"
|
|
8
|
-
import {
|
|
8
|
+
import {Utils} from "../lib/Utils.js"
|
|
9
9
|
|
|
10
10
|
const STATE = {
|
|
11
11
|
waitForInputStart: 0,
|
|
@@ -36,7 +36,7 @@ export class VisualMoveInput {
|
|
|
36
36
|
this.moveInputStartedCallback = (square) => {
|
|
37
37
|
const result = moveInputStartedCallback(square)
|
|
38
38
|
if (result) {
|
|
39
|
-
this.chessboard.state.moveInputProcess = createTask()
|
|
39
|
+
this.chessboard.state.moveInputProcess = Utils.createTask()
|
|
40
40
|
}
|
|
41
41
|
return result
|
|
42
42
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
|
|
8
8
|
import {ChessboardState} from "../src/cm-chessboard/model/ChessboardState.js"
|
|
9
9
|
import {PositionsAnimation} from "../src/cm-chessboard/view/PositionAnimationsQueue.js"
|
|
10
|
+
import {Position} from "../src/cm-chessboard/model/Position.js"
|
|
10
11
|
|
|
11
12
|
describe("TestPiecesAnimation", () => {
|
|
12
13
|
it("should calculate square distances", () => {
|
|
@@ -22,9 +23,9 @@ describe("TestPiecesAnimation", () => {
|
|
|
22
23
|
|
|
23
24
|
it("should seek changes", () => {
|
|
24
25
|
const state1 = new ChessboardState()
|
|
25
|
-
state1.
|
|
26
|
+
state1.position = new Position("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
|
|
26
27
|
const state2 = new ChessboardState()
|
|
27
|
-
state2.
|
|
28
|
+
state2.position = new Position("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
|
|
28
29
|
const previousBoard1 = state1.position.squares
|
|
29
30
|
const newBoard1 = state2.position.squares
|
|
30
31
|
const changes = PositionsAnimation.seekChanges(previousBoard1, newBoard1)
|