cm-chessboard 4.1.4 → 4.1.9
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 +3 -2
- package/package.json +1 -1
- package/src/cm-chessboard/Chessboard.js +14 -13
- package/src/cm-chessboard/view/ChessboardViewAccessible.js +8 -6
- package/src/cm-chessboard/view/PositionAnimationsQueue.js +19 -15
- package/docs/PositionsAnimation.md +0 -11
- package/docs/PreMoves.md +0 -3
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ aspects of chess games.
|
|
|
16
16
|
- [Can handle moves input via click or drag](https://shaack.com/projekte/cm-chessboard/examples/validate-moves.html)
|
|
17
17
|
- [Styleable via css](https://shaack.com/projekte/cm-chessboard/examples/different-styles.html)
|
|
18
18
|
- [Supports multiple piece sets](https://shaack.com/projekte/cm-chessboard/examples/different-styles.html)
|
|
19
|
+
- [Supports an optimized usage for visually impaired people](https://shaack.com/projekte/cm-chessboard/examples/accessible-chessboard.html) 🆕
|
|
19
20
|
- Uses SVG for rendering
|
|
20
21
|
- Vanilla JavaScript modules in ECMAScript 6 syntax
|
|
21
22
|
- **No dependencies**
|
|
@@ -53,7 +54,7 @@ The pieces animations are now smoother and less error-prone for race conditions.
|
|
|
53
54
|
As of version 4.x, the API functions `setPosition()`, `setPiece()` and `movePiece()` are **not animated** as default.
|
|
54
55
|
If you want some pieces animations you have to give the parameter `animated = true`.
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
And with 4.x the chessboard has become more accessible for visually impaired people.
|
|
57
58
|
|
|
58
59
|
## Usage
|
|
59
60
|
|
|
@@ -85,7 +86,7 @@ Below is the default configuration
|
|
|
85
86
|
let defaultProps = {
|
|
86
87
|
position: "empty", // set as fen, "start" or "empty"
|
|
87
88
|
orientation: COLOR.white, // white on bottom
|
|
88
|
-
responsive: true, //
|
|
89
|
+
responsive: true, // resize the board automatically to the size of the context element
|
|
89
90
|
animationDuration: 300, // pieces animation duration in milliseconds. Disable all animation with `0`.
|
|
90
91
|
language: navigator.language.substring(0,2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
|
|
91
92
|
style: {
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@ export class Chessboard {
|
|
|
49
49
|
let defaultProps = {
|
|
50
50
|
position: "empty", // set as fen, "start" or "empty"
|
|
51
51
|
orientation: COLOR.white, // white on bottom
|
|
52
|
-
responsive: true, //
|
|
52
|
+
responsive: true, // resize the board automatically to the size of the context element
|
|
53
53
|
animationDuration: 300, // pieces animation duration in milliseconds. Disable all animation with `0`.
|
|
54
54
|
language: navigator.language.substring(0,2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
|
|
55
55
|
style: {
|
|
@@ -171,18 +171,6 @@ export class Chessboard {
|
|
|
171
171
|
this.view.drawMarkers()
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
destroy() {
|
|
175
|
-
this.positionAnimationsQueue.destroy()
|
|
176
|
-
this.view.destroy()
|
|
177
|
-
this.view = undefined
|
|
178
|
-
this.state = undefined
|
|
179
|
-
if (this.squareSelectListener) {
|
|
180
|
-
this.context.removeEventListener("contextmenu", this.squareSelectListener)
|
|
181
|
-
this.context.removeEventListener("mouseup", this.squareSelectListener)
|
|
182
|
-
this.context.removeEventListener("touchend", this.squareSelectListener)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
174
|
enableMoveInput(eventHandler, color = undefined) {
|
|
187
175
|
this.view.enableMoveInput(eventHandler, color)
|
|
188
176
|
}
|
|
@@ -225,4 +213,17 @@ export class Chessboard {
|
|
|
225
213
|
this.view.visualizeInputState()
|
|
226
214
|
}
|
|
227
215
|
|
|
216
|
+
destroy() {
|
|
217
|
+
this.positionAnimationsQueue.destroy()
|
|
218
|
+
this.view.destroy()
|
|
219
|
+
this.view = undefined
|
|
220
|
+
this.state = undefined
|
|
221
|
+
if (this.squareSelectListener) {
|
|
222
|
+
this.context.removeEventListener("contextmenu", this.squareSelectListener)
|
|
223
|
+
this.context.removeEventListener("mouseup", this.squareSelectListener)
|
|
224
|
+
this.context.removeEventListener("touchend", this.squareSelectListener)
|
|
225
|
+
}
|
|
226
|
+
this.destroyed = true
|
|
227
|
+
}
|
|
228
|
+
|
|
228
229
|
}
|
|
@@ -113,12 +113,14 @@ export class ChessboardViewAccessible extends ChessboardView {
|
|
|
113
113
|
redrawPieces(squares = this.chessboard.state.position.squares) {
|
|
114
114
|
super.redrawPieces(squares)
|
|
115
115
|
setTimeout(() => {
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.
|
|
116
|
+
if(!this.chessboard.destroyed) {
|
|
117
|
+
this.redrawPositionInAltAttribute()
|
|
118
|
+
if (this.chessboard.props.accessibility.boardAsTable) {
|
|
119
|
+
this.redrawBoardAsTable()
|
|
120
|
+
}
|
|
121
|
+
if (this.chessboard.props.accessibility.piecesAsList) {
|
|
122
|
+
this.redrawPiecesLists()
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
})
|
|
124
126
|
}
|
|
@@ -226,22 +226,26 @@ export class PositionAnimationsQueue extends PromiseQueue {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
async enqueuePositionChange(positionFrom, positionTo, animated) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
positionFrom, positionTo, animated ? duration : 0,
|
|
237
|
-
() => {
|
|
238
|
-
if(this.chessboard.view) { // if destroyed, no view anymore
|
|
239
|
-
this.chessboard.view.redrawPieces(positionTo.squares)
|
|
240
|
-
}
|
|
241
|
-
resolve()
|
|
229
|
+
if(positionFrom.getFen() === positionTo.getFen()) {
|
|
230
|
+
return Promise.resolve()
|
|
231
|
+
} else {
|
|
232
|
+
return super.enqueue(() => new Promise((resolve) => {
|
|
233
|
+
let duration = animated ? this.chessboard.props.animationDuration : 0
|
|
234
|
+
if (this.queue.length > 0) {
|
|
235
|
+
duration = duration / (1 + Math.pow(this.queue.length / 5, 2))
|
|
242
236
|
}
|
|
243
|
-
|
|
244
|
-
|
|
237
|
+
// console.log("duration", duration, animated, "this.chessboard.props.animationDuration", this.chessboard.props.animationDuration)
|
|
238
|
+
new PositionsAnimation(this.chessboard.view,
|
|
239
|
+
positionFrom, positionTo, animated ? duration : 0,
|
|
240
|
+
() => {
|
|
241
|
+
if (this.chessboard.view) { // if destroyed, no view anymore
|
|
242
|
+
this.chessboard.view.redrawPieces(positionTo.squares)
|
|
243
|
+
}
|
|
244
|
+
resolve()
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
}))
|
|
248
|
+
}
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
async enqueueTurnBoard(position, color, animated) {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Positions Queue
|
|
2
|
-
|
|
3
|
-
- Extra Class
|
|
4
|
-
- Holds the Queue
|
|
5
|
-
- API
|
|
6
|
-
- `isRunning(): boolean`
|
|
7
|
-
- `pushPosition(position, animated)`
|
|
8
|
-
- `run(): Promise` // starts the animation, callback when finished, if running : Promis
|
|
9
|
-
- `skip(callback): Promise` // skips all running steps, displays the last position and returns to callback
|
|
10
|
-
- Positions are set immediately in the Model
|
|
11
|
-
- Then they are pushed into an Animations queue and run (if not running)
|
package/docs/PreMoves.md
DELETED