cm-chessboard 6.0.3 → 7.0.1

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.
Files changed (56) hide show
  1. package/README.md +29 -27
  2. package/assets/{styles/cm-chessboard.css → chessboard/chessboard.css} +2 -30
  3. package/assets/chessboard/chessboard.css.map +10 -0
  4. package/assets/{styles/cm-chessboard.scss → chessboard/chessboard.scss} +2 -43
  5. package/assets/chessboard/pieces/standard.svg +192 -0
  6. package/assets/chessboard/pieces/staunty.svg +240 -0
  7. package/assets/extensions/arrows/arrows.svg +19 -0
  8. package/assets/extensions/markers/markers.css +26 -0
  9. package/assets/extensions/markers/markers.css.map +9 -0
  10. package/assets/extensions/markers/markers.scss +40 -0
  11. package/assets/extensions/markers/markers.svg +27 -0
  12. package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.css +1 -1
  13. package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.css.map +1 -1
  14. package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.scss +1 -1
  15. package/examples/destroy-many-boards.html +5 -3
  16. package/examples/different-styles.html +34 -23
  17. package/examples/enable-input.html +14 -7
  18. package/examples/extensions/{chessboard-accessibility-extension.html → accessibility-extension.html} +6 -4
  19. package/examples/extensions/{chessboard-arrows-extension.html → arrows-extension.html} +12 -30
  20. package/examples/{input-callbacks.html → extensions/markers-extension.html} +17 -25
  21. package/examples/extensions/{chessboard-promotion-dialog-extension.html → promotion-dialog-extension.html} +8 -7
  22. package/examples/extensions/{chessboard-render-video-extension.html → render-video-extension.html} +5 -9
  23. package/examples/many-boards.html +5 -5
  24. package/examples/pieces-animation.html +3 -3
  25. package/examples/responsive-board.html +3 -5
  26. package/examples/simple-boards.html +8 -4
  27. package/examples/test-getPiece.html +3 -3
  28. package/examples/validate-moves.html +7 -7
  29. package/index.html +7 -7
  30. package/package.json +2 -2
  31. package/src/cm-chessboard/Chessboard.js +19 -25
  32. package/src/cm-chessboard/extensions/accessibility/Accessibility.js +1 -1
  33. package/src/cm-chessboard/extensions/arrows/Arrows.js +9 -18
  34. package/src/cm-chessboard/extensions/markers/Markers.js +28 -17
  35. package/src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js +4 -6
  36. package/src/cm-chessboard/extensions/render-video/RenderVideo.js +5 -2
  37. package/src/cm-chessboard/lib/I18n.js +44 -0
  38. package/src/cm-chessboard/lib/Svg.js +69 -0
  39. package/src/cm-chessboard/lib/Utils.js +41 -0
  40. package/src/cm-chessboard/model/Extension.js +2 -2
  41. package/src/cm-chessboard/view/ChessboardView.js +44 -172
  42. package/src/cm-chessboard/view/PositionAnimationsQueue.js +3 -3
  43. package/src/cm-chessboard/view/VisualMoveInput.js +13 -7
  44. package/test/TestBoard.js +2 -2
  45. package/test/TestChessboard.js +4 -4
  46. package/test/TestMarkers.js +1 -1
  47. package/test/index.html +1 -1
  48. package/assets/images/chessboard-sprite-staunty.svg +0 -145
  49. package/assets/images/chessboard-sprite.svg +0 -144
  50. package/assets/styles/cm-chessboard.css.map +0 -10
  51. package/examples/extensions/chessboard-markers-extension.html +0 -52
  52. package/src/cm-chessboard/extensions/arrows/assets/arrows.svg +0 -31
  53. /package/assets/{styles/_cm-chessboard-theme.scss → chessboard/_chessboard-theme.scss} +0 -0
  54. /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.css +0 -0
  55. /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.css.map +0 -0
  56. /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.scss +0 -0
@@ -8,57 +8,18 @@ import {VisualMoveInput} from "./VisualMoveInput.js"
8
8
  import {BORDER_TYPE, COLOR, INPUT_EVENT_TYPE} from "../Chessboard.js"
9
9
  import {Position} from "../model/Position.js"
10
10
  import {EXTENSION_POINT} from "../model/Extension.js"
11
-
12
- export const piecesTranslations = {
13
- en: {
14
- colors: {
15
- w: "w", b: "b"
16
- },
17
- colors_long: {
18
- w: "White", b: "Black"
19
- },
20
- pieces: {
21
- p: "p", n: "n", b: "b", r: "r", q: "q", k: "k"
22
- },
23
- pieces_long: {
24
- p: "Pawn", n: "Knight", b: "Bishop", r: "Rook", q: "Queen", k: "King"
25
- }
26
- },
27
- de: {
28
- colors: {
29
- w: "w", b: "s"
30
- },
31
- colors_long: {
32
- w: "Weiß", b: "Schwarz"
33
- },
34
- pieces: {
35
- p: "b", n: "s", b: "l", r: "t", q: "d", k: "k"
36
- },
37
- pieces_long: {
38
- p: "Bauer", n: "Springer", b: "Läufer", r: "Turm", q: "Dame", k: "König"
39
- }
40
- }
41
- }
42
-
43
- export function renderPieceTitle(lang, name, color = undefined) {
44
- let title = piecesTranslations[lang].pieces_long[name]
45
- if (color) {
46
- title += " " + piecesTranslations[lang].colors_long[color]
47
- }
48
- return title
49
- }
11
+ import {Svg} from "../lib/Svg.js"
50
12
 
51
13
  export class ChessboardView {
52
-
53
14
  constructor(chessboard) {
54
15
  this.chessboard = chessboard
55
16
  this.moveInput = new VisualMoveInput(this,
56
17
  this.moveInputStartedCallback.bind(this),
18
+ this.movingOverSquareCallback.bind(this),
57
19
  this.validateMoveInputCallback.bind(this),
58
- this.moveInputCanceledCallback.bind(this)
59
- )
60
- if (chessboard.props.sprite.cache) {
61
- this.cacheSpriteToDiv("chessboardSpriteCache", this.chessboard.props.sprite.url)
20
+ this.moveInputCanceledCallback.bind(this))
21
+ if (chessboard.props.assetsCache) {
22
+ this.cacheSpriteToDiv("cm-chessboard-sprite", this.getSpriteUrl())
62
23
  }
63
24
  this.context = document.createElement("div")
64
25
  this.chessboard.context.appendChild(this.context)
@@ -143,6 +104,7 @@ export class ChessboardView {
143
104
  }
144
105
 
145
106
  updateMetrics() {
107
+ const piecesTileSize = this.chessboard.props.style.pieces.tileSize
146
108
  this.width = this.context.clientWidth
147
109
  this.height = this.context.clientWidth * (this.chessboard.props.style.aspectRatio || 1)
148
110
  if (this.chessboard.props.style.borderType === BORDER_TYPE.frame) {
@@ -156,16 +118,15 @@ export class ChessboardView {
156
118
  this.innerHeight = this.height - 2 * this.borderSize
157
119
  this.squareWidth = this.innerWidth / 8
158
120
  this.squareHeight = this.innerHeight / 8
159
- this.scalingX = this.squareWidth / this.chessboard.props.sprite.size
160
- this.scalingY = this.squareHeight / this.chessboard.props.sprite.size
161
- this.pieceXTranslate = (this.squareWidth / 2 - this.chessboard.props.sprite.size * this.scalingY / 2)
121
+ this.scalingX = this.squareWidth / piecesTileSize
122
+ this.scalingY = this.squareHeight / piecesTileSize
123
+ this.pieceXTranslate = (this.squareWidth / 2 - piecesTileSize * this.scalingY / 2)
162
124
  }
163
125
 
164
126
  handleResize() {
165
127
  this.context.style.width = this.chessboard.context.clientWidth + "px"
166
128
  this.context.style.height = (this.chessboard.context.clientWidth * this.chessboard.props.style.aspectRatio) + "px"
167
- if (this.context.clientWidth !== this.width ||
168
- this.context.clientHeight !== this.height) {
129
+ if (this.context.clientWidth !== this.width || this.context.clientHeight !== this.height) {
169
130
  this.updateMetrics()
170
131
  this.redrawBoard()
171
132
  this.redrawPieces()
@@ -193,10 +154,7 @@ export class ChessboardView {
193
154
  if (this.chessboard.props.style.borderType === BORDER_TYPE.frame) {
194
155
  const innerPos = this.borderSize
195
156
  let borderInner = Svg.addElement(this.boardGroup, "rect", {
196
- x: innerPos,
197
- y: innerPos,
198
- width: this.width - innerPos * 2,
199
- height: this.height - innerPos * 2
157
+ x: innerPos, y: innerPos, width: this.width - innerPos * 2, height: this.height - innerPos * 2
200
158
  })
201
159
  borderInner.setAttribute("class", "border-inner")
202
160
  }
@@ -223,7 +181,7 @@ export class ChessboardView {
223
181
  }
224
182
  const inline = this.chessboard.props.style.borderType !== BORDER_TYPE.frame
225
183
  for (let file = 0; file < 8; file++) {
226
- let x = this.borderSize + (17 + this.chessboard.props.sprite.size * file) * this.scalingX
184
+ let x = this.borderSize + (17 + this.chessboard.props.style.pieces.tileSize * file) * this.scalingX
227
185
  let y = this.height - this.scalingY * 3.5
228
186
  let cssClass = "coordinate file"
229
187
  if (inline) {
@@ -231,10 +189,7 @@ export class ChessboardView {
231
189
  cssClass += file % 2 ? " white" : " black"
232
190
  }
233
191
  const textElement = Svg.addElement(this.coordinatesGroup, "text", {
234
- class: cssClass,
235
- x: x,
236
- y: y,
237
- style: `font-size: ${this.scalingY * 10}px`
192
+ class: cssClass, x: x, y: y, style: `font-size: ${this.scalingY * 10}px`
238
193
  })
239
194
  if (this.chessboard.state.orientation === COLOR.white) {
240
195
  textElement.textContent = String.fromCharCode(97 + file)
@@ -257,10 +212,7 @@ export class ChessboardView {
257
212
  }
258
213
  }
259
214
  const textElement = Svg.addElement(this.coordinatesGroup, "text", {
260
- class: cssClass,
261
- x: x,
262
- y: y,
263
- style: `font-size: ${this.scalingY * 10}px`
215
+ class: cssClass, x: x, y: y, style: `font-size: ${this.scalingY * 10}px`
264
216
  })
265
217
  if (this.chessboard.state.orientation === COLOR.white) {
266
218
  textElement.textContent = "" + (8 - rank)
@@ -288,31 +240,20 @@ export class ChessboardView {
288
240
  drawPiece(parentGroup, pieceName, point) {
289
241
  const pieceGroup = Svg.addElement(parentGroup, "g", {})
290
242
  pieceGroup.setAttribute("data-piece", pieceName)
291
- pieceGroup.setAttribute("class", "piece-group")
292
243
  const transform = (this.svg.createSVGTransform())
293
244
  transform.setTranslate(point.x, point.y)
294
245
  pieceGroup.transform.baseVal.appendItem(transform)
295
- const spriteUrl = this.chessboard.props.sprite.cache ? "" : this.chessboard.props.sprite.url
246
+ const spriteUrl = this.chessboard.props.assetsCache ? "" : this.getSpriteUrl()
296
247
  const pieceUse = Svg.addElement(pieceGroup, "use", {
297
- href: `${spriteUrl}#${pieceName}`,
298
- class: "piece"
248
+ href: `${spriteUrl}#${pieceName}`, class: "piece"
299
249
  })
300
250
  const transformScale = (this.svg.createSVGTransform())
301
251
  transformScale.setScale(this.scalingY, this.scalingY)
302
252
  pieceUse.transform.baseVal.appendItem(transformScale)
303
- const transformTranslate = (this.svg.createSVGTransform())
304
- transformTranslate.setTranslate(this.pieceXTranslate, 0)
305
- pieceUse.transform.baseVal.appendItem(transformTranslate)
306
253
  return pieceGroup
307
254
  }
308
255
 
309
256
  drawPieceOnSquare(square, pieceName) {
310
- const point = this.squareToPoint(square)
311
- const pieceGroup = this.drawPiece(this.piecesGroup, pieceName, point)
312
- pieceGroup.setAttribute("data-square", square)
313
- return pieceGroup
314
-
315
- /*
316
257
  const pieceGroup = Svg.addElement(this.piecesGroup, "g", {})
317
258
  pieceGroup.setAttribute("data-piece", pieceName)
318
259
  pieceGroup.setAttribute("data-square", square)
@@ -320,24 +261,24 @@ export class ChessboardView {
320
261
  const transform = (this.svg.createSVGTransform())
321
262
  transform.setTranslate(point.x, point.y)
322
263
  pieceGroup.transform.baseVal.appendItem(transform)
323
- const spriteUrl = this.chessboard.props.sprite.cache ? "" : this.chessboard.props.sprite.url
264
+ const spriteUrl = this.chessboard.props.assetsCache ? "" : this.getSpriteUrl()
324
265
  const pieceUse = Svg.addElement(pieceGroup, "use", {
325
- href: `${spriteUrl}#${pieceName}`,
326
- class: "piece"
266
+ href: `${spriteUrl}#${pieceName}`, class: "piece"
327
267
  })
328
268
  // center on square
329
269
  const transformTranslate = (this.svg.createSVGTransform())
330
270
  transformTranslate.setTranslate(this.pieceXTranslate, 0)
331
271
  pieceUse.transform.baseVal.appendItem(transformTranslate)
332
-
333
- */
334
-
335
- // return pieceGroup
272
+ // scale
273
+ const transformScale = (this.svg.createSVGTransform())
274
+ transformScale.setScale(this.scalingY, this.scalingY)
275
+ pieceUse.transform.baseVal.appendItem(transformScale)
276
+ return pieceGroup
336
277
  }
337
278
 
338
279
  setPieceVisibility(square, visible = true) {
339
280
  const piece = this.getPieceElement(square)
340
- if(piece) {
281
+ if (piece) {
341
282
  if (visible) {
342
283
  piece.setAttribute("visibility", "visible")
343
284
  } else {
@@ -391,17 +332,29 @@ export class ChessboardView {
391
332
  const data = {
392
333
  chessboard: this.chessboard,
393
334
  type: INPUT_EVENT_TYPE.moveInputStarted,
394
- square: square,
335
+ square: square, // TODO this one is deprecated 2023-03-18
336
+ squareFrom: square,
395
337
  piece: this.chessboard.getPiece(square)
396
338
  }
397
339
  if (this.moveInputCallback) {
398
340
  // the "oldschool" move input validator
399
- data.moveInputCallbackResult = this.moveInputCallback(data)
341
+ data.moveInputCallbackResult = this.moveInputCallback(data)
400
342
  }
401
343
  // the new extension points
402
344
  const extensionPointsResult = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
403
- // validates, when moveInputCallbackResult and extensionPointsResult are true
404
- return !(extensionPointsResult === false || !data.moveInputCallbackResult);
345
+ // validates, when moveInputCallbackResult and extensionPointsResults are true
346
+ return !(extensionPointsResult === false || !data.moveInputCallbackResult)
347
+ }
348
+
349
+ movingOverSquareCallback(squareFrom, squareTo) {
350
+ const data = {
351
+ chessboard: this.chessboard,
352
+ type: INPUT_EVENT_TYPE.movingOverSquare,
353
+ squareFrom: squareFrom,
354
+ squareTo: squareTo,
355
+ piece: this.chessboard.getPiece(squareFrom)
356
+ }
357
+ this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
405
358
  }
406
359
 
407
360
  validateMoveInputCallback(squareFrom, squareTo) {
@@ -419,10 +372,10 @@ export class ChessboardView {
419
372
  // the new extension points
420
373
  const extensionPointsResult = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
421
374
  // validates, when moveInputCallbackResult and extensionPointsResult are true
422
- return !(extensionPointsResult === false || !data.moveInputCallbackResult);
375
+ return !(extensionPointsResult === false || !data.moveInputCallbackResult)
423
376
  }
424
377
 
425
- moveInputCanceledCallback(reason, squareFrom, squareTo) {
378
+ moveInputCanceledCallback(squareFrom, squareTo, reason) {
426
379
  const data = {
427
380
  chessboard: this.chessboard,
428
381
  type: INPUT_EVENT_TYPE.moveInputCanceled,
@@ -465,88 +418,7 @@ export class ChessboardView {
465
418
  return this.indexToPoint(index)
466
419
  }
467
420
 
468
- }
469
-
470
- const SVG_NAMESPACE = "http://www.w3.org/2000/svg"
471
-
472
- export class Svg {
473
-
474
- /**
475
- * create the Svg in the HTML DOM
476
- * @param containerElement
477
- * @returns {Element}
478
- */
479
- static createSvg(containerElement = undefined) {
480
- let svg = document.createElementNS(SVG_NAMESPACE, "svg")
481
- if (containerElement) {
482
- svg.setAttribute("width", "100%")
483
- svg.setAttribute("height", "100%")
484
- containerElement.appendChild(svg)
485
- }
486
- return svg
487
- }
488
-
489
- /**
490
- * Add an Element to a SVG DOM
491
- * @param parent
492
- * @param name
493
- * @param attributes
494
- * @param sibling
495
- * @returns {Element}
496
- */
497
- static addElement(parent, name, attributes, sibling = undefined) {
498
- let element = document.createElementNS(SVG_NAMESPACE, name)
499
- if (name === "use") {
500
- attributes["xlink:href"] = attributes["href"] // fix for safari
501
- }
502
- for (let attribute in attributes) {
503
- if (attributes.hasOwnProperty(attribute)) {
504
- if (attribute.indexOf(":") !== -1) {
505
- const value = attribute.split(":")
506
- element.setAttributeNS("http://www.w3.org/1999/" + value[0], value[1], attributes[attribute])
507
- } else {
508
- element.setAttribute(attribute, attributes[attribute])
509
- }
510
- }
511
- }
512
- if (sibling !== undefined) {
513
- parent.appendChild(element)
514
- } else {
515
- parent.insertBefore(element, sibling)
516
- }
517
- return element
518
- }
519
-
520
- /**
521
- * Remove an Element from a SVG DOM
522
- * @param element
523
- */
524
- static removeElement(element) {
525
- if(element.parentNode) {
526
- element.parentNode.removeChild(element)
527
- } else {
528
- console.warn(element, "without parentNode")
529
- }
530
- }
531
-
532
- }
533
-
534
- export class DomUtils {
535
- static delegate(element, eventName, selector, handler) {
536
- const eventListener = function (event) {
537
- let target = event.target
538
- while (target && target !== this) {
539
- if (target.matches(selector)) {
540
- handler.call(target, event)
541
- }
542
- target = target.parentNode
543
- }
544
- }
545
- element.addEventListener(eventName, eventListener)
546
- return {
547
- remove: function () {
548
- element.removeEventListener(eventName, eventListener)
549
- }
550
- }
421
+ getSpriteUrl() {
422
+ return this.chessboard.props.assetsUrl + "chessboard/pieces/" + this.chessboard.props.style.pieces.file
551
423
  }
552
424
  }
@@ -4,7 +4,7 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
  import {FEN, Position} from "../model/Position.js"
7
- import {Svg} from "./ChessboardView.js"
7
+ import {Svg} from "../lib/Svg.js"
8
8
  import {EXTENSION_POINT} from "../model/Extension.js"
9
9
 
10
10
  /*
@@ -250,7 +250,7 @@ export class PositionAnimationsQueue extends PromiseQueue {
250
250
  return Promise.resolve()
251
251
  } else {
252
252
  return super.enqueue(() => new Promise((resolve) => {
253
- let duration = animated ? this.chessboard.props.animationDuration : 0
253
+ let duration = animated ? this.chessboard.props.style.animationDuration : 0
254
254
  if (this.queue.length > 0) {
255
255
  duration = duration / (1 + Math.pow(this.queue.length / 5, 2))
256
256
  }
@@ -271,7 +271,7 @@ export class PositionAnimationsQueue extends PromiseQueue {
271
271
  async enqueueTurnBoard(position, color, animated) {
272
272
  return super.enqueue(() => new Promise((resolve) => {
273
273
  const emptyPosition = new Position(FEN.empty)
274
- let duration = animated ? this.chessboard.props.animationDuration : 0
274
+ let duration = animated ? this.chessboard.props.style.animationDuration : 0
275
275
  if(this.queue.length > 0) {
276
276
  duration = duration / (1 + Math.pow(this.queue.length / 5, 2))
277
277
  }
@@ -4,7 +4,7 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
 
7
- import {Svg} from "./ChessboardView.js"
7
+ import {Svg} from "../lib/Svg.js"
8
8
  import {createTask} from "../model/ChessboardState.js"
9
9
 
10
10
  const STATE = {
@@ -29,23 +29,26 @@ const DRAG_THRESHOLD = 4
29
29
 
30
30
  export class VisualMoveInput {
31
31
 
32
- constructor(view, moveInputStartedCallback, validateMoveInputCallback, moveInputCanceledCallback) {
32
+ constructor(view, moveInputStartedCallback, movingOverSquareCallback, validateMoveInputCallback, moveInputCanceledCallback) {
33
33
  this.view = view
34
34
  this.chessboard = view.chessboard
35
35
  this.moveInputStartedCallback = (square) => {
36
36
  const result = moveInputStartedCallback(square)
37
- if(result) {
37
+ if (result) {
38
38
  this.chessboard.state.moveInputProcess = createTask()
39
39
  }
40
40
  return result
41
41
  }
42
+ this.movingOverSquareCallback = (fromSquare, toSquare) => {
43
+ movingOverSquareCallback(fromSquare, toSquare)
44
+ }
42
45
  this.validateMoveInputCallback = (fromSquare, toSquare) => {
43
46
  const result = validateMoveInputCallback(fromSquare, toSquare)
44
47
  this.chessboard.state.moveInputProcess.resolve(result)
45
48
  return result
46
49
  }
47
- this.moveInputCanceledCallback = (reason, fromSquare, toSquare) => {
48
- moveInputCanceledCallback(reason, fromSquare, toSquare)
50
+ this.moveInputCanceledCallback = (fromSquare, toSquare, reason) => {
51
+ moveInputCanceledCallback(fromSquare, toSquare, reason)
49
52
  this.chessboard.state.moveInputProcess.resolve()
50
53
  }
51
54
  this.setMoveInputState(STATE.waitForInputStart)
@@ -205,11 +208,11 @@ export class VisualMoveInput {
205
208
  this.draggablePiece.setAttribute("height", this.view.squareHeight)
206
209
  this.draggablePiece.setAttribute("style", "pointer-events: none")
207
210
  this.draggablePiece.name = pieceName
208
- const spriteUrl = this.chessboard.props.sprite.cache ? "" : this.chessboard.props.sprite.url
211
+ const spriteUrl = this.chessboard.props.assetsCache ? "" : this.view.getSpriteUrl()
209
212
  const piece = Svg.addElement(this.draggablePiece, "use", {
210
213
  href: `${spriteUrl}#${pieceName}`
211
214
  })
212
- const scaling = this.view.squareHeight / this.chessboard.props.sprite.size
215
+ const scaling = this.view.squareHeight / this.chessboard.props.style.pieces.tileSize
213
216
  const transformScale = (this.draggablePiece.createSVGTransform())
214
217
  transformScale.setScale(scaling, scaling)
215
218
  piece.transform.baseVal.appendItem(transformScale)
@@ -317,12 +320,15 @@ export class VisualMoveInput {
317
320
  const square = target.getAttribute("data-square")
318
321
  if (square !== this.fromSquare && square !== this.toSquare) {
319
322
  this.toSquare = square
323
+ this.movingOverSquareCallback(this.fromSquare, this.toSquare)
320
324
  } else if (square === this.fromSquare && this.toSquare !== undefined) {
321
325
  this.toSquare = undefined
326
+ this.movingOverSquareCallback(this.fromSquare, null)
322
327
  }
323
328
  } else {
324
329
  if (this.toSquare !== undefined) {
325
330
  this.toSquare = undefined
331
+ this.movingOverSquareCallback(this.fromSquare, null)
326
332
  }
327
333
  }
328
334
  if (this.view.chessboard.state.inputEnabled && (this.moveInputState === STATE.dragTo || this.moveInputState === STATE.clickDragTo)) {
package/test/TestBoard.js CHANGED
@@ -13,7 +13,7 @@ describe("TestBoard", () => {
13
13
  // https://github.com/shaack/cm-chessboard/issues/47
14
14
  it("should create and immediately destroy a board without failure", () => {
15
15
  const chessboard = new Chessboard(document.getElementById("TestBoard"), {
16
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
16
+ assetsUrl: "../assets/",
17
17
  position: FEN.start
18
18
  })
19
19
  chessboard.destroy()
@@ -21,7 +21,7 @@ describe("TestBoard", () => {
21
21
 
22
22
  it("should create and destroy a board", () => {
23
23
  const chessboard = new Chessboard(document.getElementById("TestBoard"), {
24
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
24
+ assetsUrl: "../assets/",
25
25
  position: FEN.start
26
26
  })
27
27
  assert.equal(chessboard.view.context.childNodes.length, 1)
@@ -12,7 +12,7 @@ describe("TestChessboard", () => {
12
12
 
13
13
  it("should create and destroy a chessboard", () => {
14
14
  const chessboard = new Chessboard(document.getElementById("TestPosition"), {
15
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
15
+ assetsUrl: "../assets/",
16
16
  position: FEN.start
17
17
  })
18
18
  assert.equal(chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
@@ -21,7 +21,7 @@ describe("TestChessboard", () => {
21
21
 
22
22
  it("should set and get the position", () => {
23
23
  const chessboard = new Chessboard(document.getElementById("TestPosition"),
24
- {sprite: {url: "../assets/images/chessboard-sprite.svg"},})
24
+ {assetsUrl: "../assets/"})
25
25
  chessboard.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11", false).then(() => {
26
26
  assert.equal(chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
27
27
  chessboard.destroy()
@@ -30,7 +30,7 @@ describe("TestChessboard", () => {
30
30
 
31
31
  it("should get pieces on squares", () => {
32
32
  const chessboard = new Chessboard(document.getElementById("TestPosition"), {
33
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
33
+ assetsUrl: "../assets/",
34
34
  position: FEN.start
35
35
  })
36
36
  assert.equal(chessboard.getPiece("d1"), "wq")
@@ -41,7 +41,7 @@ describe("TestChessboard", () => {
41
41
 
42
42
  it("should set pieces on squares", () => {
43
43
  const chessboard = new Chessboard(document.getElementById("TestPosition"), {
44
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
44
+ assetsUrl: "../assets/",
45
45
  })
46
46
  chessboard.setPiece("a1", PIECE.bk)
47
47
  assert.equal(chessboard.getPiece("a1"), "bk")
@@ -12,7 +12,7 @@ describe("TestMarkers", () => {
12
12
 
13
13
  it("should set and get markers", () => {
14
14
  const chessboard = new Chessboard(document.getElementById("TestMarkers"), {
15
- sprite: {url: "../assets/images/chessboard-sprite.svg"},
15
+ assetsUrl: "../assets/",
16
16
  extensions: [{class: Markers}]
17
17
  })
18
18
  chessboard.addMarker(MARKER_TYPE.square, "e5")
package/test/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8">
5
5
  <title>Test cm-chessboard</title>
6
6
  <link rel="stylesheet" href="../examples/styles/examples.css"/>
7
- <link rel="stylesheet" href="../assets/styles/cm-chessboard.css"/>
7
+ <link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
8
8
  <style>
9
9
  .board {
10
10
  position: absolute;