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 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
- Also in 4.x the chessboard will become more accessible for visually impaired people but this is in alpha stage for now.
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, // resizes the board based on element size
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "4.1.4",
3
+ "version": "4.1.9",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -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, // resizes the board based on element size
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.redrawPositionInAltAttribute()
117
- if (this.chessboard.props.accessibility.boardAsTable) {
118
- this.redrawBoardAsTable()
119
- }
120
- if (this.chessboard.props.accessibility.piecesAsList) {
121
- this.redrawPiecesLists()
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
- return super.enqueue(() => new Promise((resolve) => {
230
- let duration = animated ? this.chessboard.props.animationDuration : 0
231
- if(this.queue.length > 0) {
232
- duration = duration / (1 + Math.pow(this.queue.length / 5, 2))
233
- }
234
- // console.log("duration", duration, animated, "this.chessboard.props.animationDuration", this.chessboard.props.animationDuration)
235
- new PositionsAnimation(this.chessboard.view,
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
@@ -1,3 +0,0 @@
1
- # Pre Moves
2
-
3
- - TODO