cm-chessboard 4.1.6 → 4.1.10

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
@@ -34,7 +34,7 @@ aspects of chess games.
34
34
 
35
35
  **Option 2:** Download the code from [GitHub](https://github.com/shaack/cm-chessboard).
36
36
 
37
- **Option 3:** Use it via CDN https://cdn.jsdelivr.net/npm/cm-chessboard@4/src/cm-chessboard/Chessboard.js
37
+ **Option 3:** Use it via CDN https://cdn.jsdelivr.net/npm/cm-chessboard@4.1/src/cm-chessboard/Chessboard.js
38
38
 
39
39
  After installation, copy the sprite in `cm-chessboard/assets/images/` to your projects `assets/images/`
40
40
  folder. If you put the sprite somewhere else you have to configure the location
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "4.1.6",
3
+ "version": "4.1.10",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -166,23 +166,10 @@ export class Chessboard {
166
166
  }
167
167
 
168
168
  removeMarkers(square = undefined, type = undefined) {
169
- const index = square ? this.state.squareToIndex(square) : undefined
170
- this.state.removeMarkers(index, type)
169
+ this.state.removeMarkers(square, type)
171
170
  this.view.drawMarkers()
172
171
  }
173
172
 
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
173
  enableMoveInput(eventHandler, color = undefined) {
187
174
  this.view.enableMoveInput(eventHandler, color)
188
175
  }
@@ -225,4 +212,17 @@ export class Chessboard {
225
212
  this.view.visualizeInputState()
226
213
  }
227
214
 
215
+ destroy() {
216
+ this.positionAnimationsQueue.destroy()
217
+ this.view.destroy()
218
+ this.view = undefined
219
+ this.state = undefined
220
+ if (this.squareSelectListener) {
221
+ this.context.removeEventListener("contextmenu", this.squareSelectListener)
222
+ this.context.removeEventListener("mouseup", this.squareSelectListener)
223
+ this.context.removeEventListener("touchend", this.squareSelectListener)
224
+ }
225
+ this.destroyed = true
226
+ }
227
+
228
228
  }
@@ -49,7 +49,7 @@ export class ChessboardState {
49
49
  this.markers = []
50
50
  } else {
51
51
  this.markers = this.markers.filter((marker) => {
52
- if (!marker.type) {
52
+ if (!type) {
53
53
  if (square === marker.square) {
54
54
  return false
55
55
  }
@@ -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) {
@@ -26,6 +26,15 @@ describe("TestMarkers", () => {
26
26
  assert.equals(chessboard.getMarkers("a4").length, 0)
27
27
  assert.equals(chessboard.getMarkers(undefined, MARKER_TYPE.frame).length, 2)
28
28
  assert.equals(chessboard.getMarkers("b6", MARKER_TYPE.frame).length, 1)
29
+ assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
30
+ chessboard.removeMarkers("h6")
31
+ assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
32
+ chessboard.addMarker("h6", MARKER_TYPE.frame)
33
+ assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
34
+ chessboard.removeMarkers("h6", MARKER_TYPE.square)
35
+ assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
36
+ chessboard.removeMarkers("h6", MARKER_TYPE.frame)
37
+ assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
29
38
  chessboard.destroy()
30
39
  })
31
40
 
@@ -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