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 +1 -1
- package/package.json +1 -1
- package/src/cm-chessboard/Chessboard.js +14 -14
- package/src/cm-chessboard/model/ChessboardState.js +1 -1
- package/src/cm-chessboard/view/ChessboardViewAccessible.js +8 -6
- package/src/cm-chessboard/view/PositionAnimationsQueue.js +19 -15
- package/test/TestMarkers.js +9 -0
- package/docs/PositionsAnimation.md +0 -11
- package/docs/PreMoves.md +0 -3
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
|
@@ -166,23 +166,10 @@ export class Chessboard {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
removeMarkers(square = undefined, type = undefined) {
|
|
169
|
-
|
|
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
|
}
|
|
@@ -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) {
|
package/test/TestMarkers.js
CHANGED
|
@@ -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