cm-chessboard 8.5.5 → 8.5.7

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.
@@ -49,21 +49,12 @@
49
49
  return // ignore this event
50
50
  }
51
51
  if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
52
- event.chessboard.removeMarkers(MARKER_TYPE.dot)
53
- event.chessboard.removeMarkers(MARKER_TYPE.bevel)
52
+ event.chessboard.removeLegalMovesMarkers()
54
53
  }
55
54
  if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
55
+ // mark legal moves
56
56
  const moves = chess.moves({square: event.squareFrom, verbose: true})
57
- for (const move of moves) { // draw dots on possible squares
58
- if (move.promotion && move.promotion !== "q") {
59
- continue
60
- }
61
- if (event.chessboard.getPiece(move.to)) {
62
- event.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
63
- } else {
64
- event.chessboard.addMarker(MARKER_TYPE.dot, move.to)
65
- }
66
- }
57
+ event.chessboard.addLegalMovesMarkers(moves)
67
58
  return moves.length > 0
68
59
  } else if (event.type === INPUT_EVENT_TYPE.validateMoveInput) {
69
60
  const move = {from: event.squareFrom, to: event.squareTo, promotion: event.promotion}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.5.5",
3
+ "version": "8.5.7",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
package/src/Chessboard.js CHANGED
@@ -8,39 +8,19 @@ import {ChessboardState} from "./model/ChessboardState.js"
8
8
  import {FEN, Position} from "./model/Position.js"
9
9
  import {PositionAnimationsQueue} from "./view/PositionAnimationsQueue.js"
10
10
  import {EXTENSION_POINT} from "./model/Extension.js"
11
- import {ChessboardView} from "./view/ChessboardView.js"
11
+ import {ChessboardView, COLOR, INPUT_EVENT_TYPE, BORDER_TYPE} from "./view/ChessboardView.js"
12
12
  import {Utils} from "./lib/Utils.js"
13
13
 
14
- export const COLOR = {
15
- white: "w",
16
- black: "b"
17
- }
18
- export const INPUT_EVENT_TYPE = {
19
- moveInputStarted: "moveInputStarted",
20
- movingOverSquare: "movingOverSquare", // while dragging or hover after click
21
- validateMoveInput: "validateMoveInput",
22
- moveInputCanceled: "moveInputCanceled",
23
- moveInputFinished: "moveInputFinished"
24
- }
25
- /** @deprecated */
26
- export const SQUARE_SELECT_TYPE = {
27
- primary: "primary",
28
- secondary: "secondary"
29
- }
30
- export const BORDER_TYPE = {
31
- none: "none", // no border
32
- thin: "thin", // thin border
33
- frame: "frame" // wide border with coordinates in it
34
- }
35
14
  export const PIECE = {
36
15
  wp: "wp", wb: "wb", wn: "wn", wr: "wr", wq: "wq", wk: "wk",
37
16
  bp: "bp", bb: "bb", bn: "bn", br: "br", bq: "bq", bk: "bk"
38
17
  }
39
-
40
18
  export const PIECES_FILE_TYPE = {
41
19
  svgSprite: "svgSprite"
42
20
  }
43
-
21
+ export {COLOR}
22
+ export {INPUT_EVENT_TYPE}
23
+ export {BORDER_TYPE}
44
24
  export {FEN}
45
25
 
46
26
  export class Chessboard {
@@ -39,6 +39,8 @@ export class Markers extends Extension {
39
39
  chessboard.addMarker = this.addMarker.bind(this)
40
40
  chessboard.getMarkers = this.getMarkers.bind(this)
41
41
  chessboard.removeMarkers = this.removeMarkers.bind(this)
42
+ chessboard.addLegalMovesMarkers = this.addLegalMovesMarkers.bind(this)
43
+ chessboard.removeLegalMovesMarkers = this.removeLegalMovesMarkers.bind(this)
42
44
  this.markerGroupDown = Svg.addElement(chessboard.view.markersLayer, "g", {class: "markers"})
43
45
  this.markerGroupUp = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "markers"})
44
46
  this.markers = []
@@ -82,6 +84,24 @@ export class Markers extends Extension {
82
84
  )
83
85
  }
84
86
 
87
+ addLegalMovesMarkers(moves) {
88
+ for (const move of moves) {
89
+ if (move.promotion && move.promotion !== "q") {
90
+ continue
91
+ }
92
+ if (this.chessboard.getPiece(move.to)) {
93
+ this.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
94
+ } else {
95
+ this.chessboard.addMarker(MARKER_TYPE.dot, move.to)
96
+ }
97
+ }
98
+ }
99
+
100
+ removeLegalMovesMarkers() {
101
+ this.chessboard.removeMarkers(MARKER_TYPE.bevel)
102
+ this.chessboard.removeMarkers(MARKER_TYPE.dot)
103
+ }
104
+
85
105
  drawMarker(marker) {
86
106
  let markerGroup
87
107
  if (marker.type.position === 'above') {
@@ -5,12 +5,28 @@
5
5
  */
6
6
 
7
7
  import {VisualMoveInput} from "./VisualMoveInput.js"
8
- import {BORDER_TYPE, COLOR, INPUT_EVENT_TYPE} from "../Chessboard.js"
9
8
  import {Position} from "../model/Position.js"
10
9
  import {EXTENSION_POINT} from "../model/Extension.js"
11
10
  import {Svg} from "../lib/Svg.js"
12
11
  import {Utils} from "../lib/Utils.js"
13
12
 
13
+ export const COLOR = {
14
+ white: "w",
15
+ black: "b"
16
+ }
17
+ export const INPUT_EVENT_TYPE = {
18
+ moveInputStarted: "moveInputStarted",
19
+ movingOverSquare: "movingOverSquare", // while dragging or hover after click
20
+ validateMoveInput: "validateMoveInput",
21
+ moveInputCanceled: "moveInputCanceled",
22
+ moveInputFinished: "moveInputFinished"
23
+ }
24
+ export const BORDER_TYPE = {
25
+ none: "none", // no border
26
+ thin: "thin", // thin border
27
+ frame: "frame" // wide border with coordinates in it
28
+ }
29
+
14
30
  export class ChessboardView {
15
31
  constructor(chessboard) {
16
32
  this.chessboard = chessboard