cm-chessboard 4.1.0 → 4.1.3

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.
@@ -82,11 +82,9 @@ board.enableMoveInput(inputHandler, COLOR.white)
82
82
  function inputHandler(event) {
83
83
  console.log("event", event)
84
84
  event.chessboard.removeMarkers(undefined, MARKER_TYPE.dot)
85
- event.chessboard.removeMarkers(undefined, MARKER_TYPE.square)
86
85
  if (event.type === INPUT_EVENT_TYPE.moveStart) {
87
86
  const moves = chess.moves({square: event.square, verbose: true});
88
- event.chessboard.addMarker(event.square, MARKER_TYPE.square)
89
- for (const move of moves) { // draw dots on possible moves
87
+ for (const move of moves) { // draw dots on possible squares
90
88
  event.chessboard.addMarker(move.to, MARKER_TYPE.dot)
91
89
  }
92
90
  return moves.length > 0
@@ -115,7 +113,7 @@ board.enableMoveInput(inputHandler, COLOR.white)
115
113
  const board = new Chessboard(document.getElementById("board"), {
116
114
  position: chess.fen(),
117
115
  sprite: {url: "../assets/images/chessboard-sprite-staunty.svg"},
118
- style: {moveFromMarker: undefined, moveToMarker: undefined}, // disable standard markers
116
+ style: {moveFromMarker: MARKER_TYPE.square, moveToMarker: MARKER_TYPE.square},
119
117
  orientation: COLOR.white,
120
118
  accessibility: {
121
119
  brailleNotationInAlt: true, // show the braille notation of the game in the alt attribute of the svg
package/index.html CHANGED
@@ -37,15 +37,18 @@ It works, it is cool and it is easy to use. 👍</p>
37
37
  const board = new Chessboard(document.getElementById("board"), {
38
38
  position: "start"
39
39
  })
40
- setInterval(() => {
40
+ const interval = setInterval(() => {
41
41
  makeRandomMove()
42
42
  board.setPosition(chess.fen(), true)
43
43
  }, 250)
44
44
  function makeRandomMove() {
45
- const possibleMoves = chess.moves();
46
- if (possibleMoves.length === 0) return;
47
- const randomIndex = Math.floor(Math.random() * possibleMoves.length);
48
- chess.move(possibleMoves[randomIndex]);
45
+ const possibleMoves = chess.moves()
46
+ if (possibleMoves.length === 0) {
47
+ clearInterval(interval)
48
+ return
49
+ }
50
+ const randomIndex = Math.floor(Math.random() * possibleMoves.length)
51
+ chess.move(possibleMoves[randomIndex])
49
52
  }
50
53
  </script>
51
54
  <div class="clearfix"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "4.1.0",
3
+ "version": "4.1.3",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -4,10 +4,10 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
 
7
- import {State} from "./core/State.js"
8
- import {ViewAccessible} from "./core/ViewAccessible.js"
9
- import {PositionAnimationsQueue} from "./core/PositionAnimationsQueue.js"
10
- import {Position} from "./core/Position.js"
7
+ import {ChessboardState} from "./model/ChessboardState.js"
8
+ import {Position} from "./model/Position.js"
9
+ import {ChessboardViewAccessible} from "./view/ChessboardViewAccessible.js"
10
+ import {PositionAnimationsQueue} from "./view/PositionAnimationsQueue.js"
11
11
 
12
12
  export const COLOR = {
13
13
  white: "w",
@@ -88,8 +88,8 @@ export class Chessboard {
88
88
  Object.assign(this.props.accessibility, props.accessibility)
89
89
  }
90
90
 
91
- this.state = new State()
92
- this.view = new ViewAccessible(this)
91
+ this.state = new ChessboardState()
92
+ this.view = new ChessboardViewAccessible(this)
93
93
  this.positionAnimationsQueue = new PositionAnimationsQueue(this)
94
94
  this.state.orientation = this.props.orientation
95
95
  this.view.redraw()
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import {Position} from "./Position.js"
7
7
 
8
- export class State {
8
+ export class ChessboardState {
9
9
 
10
10
  constructor() {
11
11
  this.position = new Position()
File without changes
@@ -4,9 +4,9 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
 
7
- import {MoveInput} from "./MoveInput.js"
7
+ import {VisualMoveInput} from "./VisualMoveInput.js"
8
8
  import {COLOR, INPUT_EVENT_TYPE, BORDER_TYPE} from "../Chessboard.js"
9
- import {Position} from "./Position.js"
9
+ import {Position} from "../model/Position.js"
10
10
 
11
11
  export const piecesTranslations = {
12
12
  en: {
@@ -47,11 +47,11 @@ export function renderPieceTitle(lang, name, color = undefined) {
47
47
  return title
48
48
  }
49
49
 
50
- export class View {
50
+ export class ChessboardView {
51
51
 
52
52
  constructor(chessboard) {
53
53
  this.chessboard = chessboard
54
- this.moveInput = new MoveInput(this,
54
+ this.moveInput = new VisualMoveInput(this,
55
55
  this.moveStartCallback.bind(this),
56
56
  this.moveDoneCallback.bind(this),
57
57
  this.moveCanceledCallback.bind(this)
@@ -3,9 +3,9 @@
3
3
  * Repository: https://github.com/shaack/cm-chessboard
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
- import {View, renderPieceTitle} from "./View.js"
6
+ import {ChessboardView, renderPieceTitle} from "./ChessboardView.js"
7
7
  import {COLOR, INPUT_EVENT_TYPE} from "../Chessboard.js"
8
- import {piecesTranslations} from "./View.js"
8
+ import {piecesTranslations} from "./ChessboardView.js"
9
9
 
10
10
  const hlTranslations = {
11
11
  de: {
@@ -32,7 +32,7 @@ const hlTranslations = {
32
32
  }
33
33
  }
34
34
 
35
- export class ViewAccessible extends View {
35
+ export class ChessboardViewAccessible extends ChessboardView {
36
36
 
37
37
  constructor(chessboard, callbackAfterCreation) {
38
38
  super(chessboard, callbackAfterCreation)
@@ -3,8 +3,8 @@
3
3
  * Repository: https://github.com/shaack/cm-chessboard
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
- import {FEN_EMPTY_POSITION, Position} from "./Position.js"
7
- import {Svg} from "./View.js"
6
+ import {FEN_EMPTY_POSITION, Position} from "../model/Position.js"
7
+ import {Svg} from "./ChessboardView.js"
8
8
 
9
9
  /*
10
10
  * Thanks to markosyan for the idea to the PromiseQueue
@@ -4,7 +4,7 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
 
7
- import {Svg} from "./View.js"
7
+ import {Svg} from "./ChessboardView.js"
8
8
 
9
9
  const STATE = {
10
10
  waitForInputStart: 0,
@@ -26,7 +26,7 @@ export const MOVE_CANCELED_REASON = {
26
26
 
27
27
  const DRAG_THRESHOLD = 4
28
28
 
29
- export class MoveInput {
29
+ export class VisualMoveInput {
30
30
 
31
31
  constructor(view, moveStartCallback, moveDoneCallback, moveCanceledCallback) {
32
32
  this.view = view
@@ -5,8 +5,8 @@
5
5
  */
6
6
 
7
7
  import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
8
- import {State} from "../src/cm-chessboard/core/State.js"
9
- import {PositionsAnimation} from "../src/cm-chessboard/core/PositionAnimationsQueue.js"
8
+ import {ChessboardState} from "../src/cm-chessboard/model/ChessboardState.js"
9
+ import {PositionsAnimation} from "../src/cm-chessboard/view/PositionAnimationsQueue.js"
10
10
 
11
11
  describe("TestPiecesAnimation", () => {
12
12
  it("should calculate square distances", () => {
@@ -21,9 +21,9 @@ describe("TestPiecesAnimation", () => {
21
21
  })
22
22
 
23
23
  it("should seek changes", () => {
24
- const state1 = new State()
24
+ const state1 = new ChessboardState()
25
25
  state1.setPosition("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
26
- const state2 = new State()
26
+ const state2 = new ChessboardState()
27
27
  state2.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
28
28
  const previousBoard1 = state1.position.squares
29
29
  const newBoard1 = state2.position.squares
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
8
- import {Position} from "../src/cm-chessboard/core/Position.js"
8
+ import {Position} from "../src/cm-chessboard/model/Position.js"
9
9
 
10
10
  describe("TestPosition", () => {
11
11
  it("should convert square to index", () => {