cm-chessboard 4.5.0 → 4.5.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.
@@ -12,6 +12,31 @@
12
12
  <h1><a href="../..">cm-chessboard</a></h1>
13
13
  <h2>Example: Arrows extension</h2>
14
14
  <div class="board" id="board"></div>
15
+ <br style="clear: both"/>
16
+ <pre>
17
+ import {ARROW_TYPE, Arrows} from "../../src/cm-chessboard/extensions/arrows/Arrows.js"
18
+ import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
19
+
20
+ const chessboard = new Chessboard(document.getElementById("board"), {
21
+ position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
22
+ sprite: {url: "../../assets/images/chessboard-sprite.svg"},
23
+ extensions:
24
+ [{
25
+ class: Arrows,
26
+ props: {
27
+ sprite: {
28
+ url: "../../src/cm-chessboard/extensions/arrows/assets/arrows.svg"
29
+ }
30
+ }
31
+
32
+ }]
33
+ })
34
+ chessboard.addArrow("f3", "d5", ARROW_TYPE.default);
35
+ chessboard.addArrow("b8", "c6", ARROW_TYPE.default);
36
+ chessboard.addArrow("d2", "d3", ARROW_TYPE.pointy);
37
+ chessboard.addArrow("g5", "e6", ARROW_TYPE.danger);
38
+ </pre>
39
+
15
40
  <script type="module">
16
41
  import {ARROW_TYPE, Arrows} from "../../src/cm-chessboard/extensions/arrows/Arrows.js"
17
42
  import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
@@ -19,18 +44,12 @@
19
44
  const chessboard = new Chessboard(document.getElementById("board"), {
20
45
  position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
21
46
  sprite: {url: "../../assets/images/chessboard-sprite.svg"},
22
- // animationDuration: 0, // optional, set to 0 to disable animations
23
- style: {
24
- cssClass: "default-contrast" // make the coordinates better visible with the "default-contrast" theme
25
- },
26
47
  extensions:
27
48
  [{
28
49
  class: Arrows,
29
50
  props: {
30
51
  sprite: {
31
- url: "../../src/cm-chessboard/extensions/arrows/assets/arrows.svg",
32
- size: 40,
33
- cache: true
52
+ url: "../../src/cm-chessboard/extensions/arrows/assets/arrows.svg"
34
53
  }
35
54
  }
36
55
 
@@ -38,7 +57,8 @@
38
57
  })
39
58
  chessboard.addArrow("f3", "d5", ARROW_TYPE.default);
40
59
  chessboard.addArrow("b8", "c6", ARROW_TYPE.default);
41
- chessboard.addArrow("d2", "d3", ARROW_TYPE.default);
60
+ chessboard.addArrow("d2", "d3", ARROW_TYPE.pointy);
61
+ chessboard.addArrow("g5", "e6", ARROW_TYPE.danger);
42
62
  </script>
43
63
  </body>
44
64
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "4.5.0",
3
+ "version": "4.5.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",
@@ -9,6 +9,7 @@ import {Svg} from "../../view/ChessboardView.js"
9
9
 
10
10
  export const ARROW_TYPE = {
11
11
  default: {class: "arrow-default", slice: "arrowDefault", headSize: 7},
12
+ danger: {class: "arrow-danger", slice: "arrowDefault", headSize: 7},
12
13
  pointy: {class: "arrow-pointy", slice: "arrowPointy", headSize: 7},
13
14
  }
14
15
 
@@ -28,6 +29,10 @@ export class Arrows extends Extension {
28
29
  this.props = {}
29
30
  Object.assign(this.props, defaultProps)
30
31
  Object.assign(this.props, props)
32
+ this.props.sprite = defaultProps.sprite
33
+ if (props.sprite) {
34
+ Object.assign(this.props.sprite, props.sprite)
35
+ }
31
36
  if (this.props.sprite.cache) {
32
37
  this.chessboard.view.cacheSpriteToDiv("chessboardArrowSpriteCache", this.props.sprite.url)
33
38
  }
@@ -1,11 +1,31 @@
1
- .cm-chessboard .arrows .arrow-head {
1
+ .cm-chessboard .arrow-default .arrow-head {
2
2
  fill: blue;
3
3
  fill-rule: nonzero;
4
4
  fill-opacity: 1; }
5
5
 
6
- .cm-chessboard .arrows .arrow-line {
6
+ .cm-chessboard .arrow-default .arrow-line {
7
7
  stroke: blue;
8
8
  stroke-linecap: round;
9
9
  opacity: 0.5; }
10
10
 
11
+ .cm-chessboard .arrow-danger .arrow-head {
12
+ fill: red;
13
+ fill-rule: nonzero;
14
+ fill-opacity: 1; }
15
+
16
+ .cm-chessboard .arrow-danger .arrow-line {
17
+ stroke: red;
18
+ stroke-linecap: round;
19
+ opacity: 0.5; }
20
+
21
+ .cm-chessboard .arrow-pointy .arrow-head {
22
+ fill: black;
23
+ fill-rule: nonzero;
24
+ fill-opacity: 1; }
25
+
26
+ .cm-chessboard .arrow-pointy .arrow-line {
27
+ stroke: black;
28
+ stroke-linecap: round;
29
+ opacity: 0.5; }
30
+
11
31
  /*# sourceMappingURL=arrows.css.map */
@@ -5,5 +5,5 @@
5
5
  "arrows.scss"
6
6
  ],
7
7
  "names": [],
8
- "mappings": "AAAA,AAEI,cAFU,CACZ,OAAO,CACL,WAAW,CAAC;EACV,IAAI,EAAE,IAAI;EACV,SAAS,EAAE,OAAO;EAClB,YAAY,EAAE,CAAC,GAChB;;AANL,AAQI,cARU,CACZ,OAAO,CAOL,WAAW,CAAC;EACV,MAAM,EAAE,IAAI;EACZ,cAAc,EAAE,KAAK;EACrB,OAAO,EAAE,GAAG,GACb"
8
+ "mappings": "AAAA,AAEI,cAFU,CACZ,cAAc,CACZ,WAAW,CAAC;EACV,IAAI,EAAE,IAAI;EACV,SAAS,EAAE,OAAO;EAClB,YAAY,EAAE,CAAC,GAChB;;AANL,AAOI,cAPU,CACZ,cAAc,CAMZ,WAAW,CAAC;EACV,MAAM,EAAE,IAAI;EACZ,cAAc,EAAE,KAAK;EACrB,OAAO,EAAE,GAAG,GACb;;AAXL,AAcI,cAdU,CAaZ,aAAa,CACX,WAAW,CAAC;EACV,IAAI,EAAE,GAAG;EACT,SAAS,EAAE,OAAO;EAClB,YAAY,EAAE,CAAC,GAChB;;AAlBL,AAmBI,cAnBU,CAaZ,aAAa,CAMX,WAAW,CAAC;EACV,MAAM,EAAE,GAAG;EACX,cAAc,EAAE,KAAK;EACrB,OAAO,EAAE,GAAG,GACb;;AAvBL,AA0BI,cA1BU,CAyBZ,aAAa,CACX,WAAW,CAAC;EACV,IAAI,EAAE,KAAK;EACX,SAAS,EAAE,OAAO;EAClB,YAAY,EAAE,CAAC,GAChB;;AA9BL,AA+BI,cA/BU,CAyBZ,aAAa,CAMX,WAAW,CAAC;EACV,MAAM,EAAE,KAAK;EACb,cAAc,EAAE,KAAK;EACrB,OAAO,EAAE,GAAG,GACb"
9
9
  }
@@ -1,15 +1,38 @@
1
1
  .cm-chessboard {
2
- .arrows {
2
+ .arrow-default {
3
3
  .arrow-head {
4
4
  fill: blue;
5
5
  fill-rule: nonzero;
6
6
  fill-opacity: 1;
7
7
  }
8
-
9
8
  .arrow-line {
10
9
  stroke: blue;
11
10
  stroke-linecap: round;
12
11
  opacity: 0.5;
13
12
  }
14
13
  }
14
+ .arrow-danger {
15
+ .arrow-head {
16
+ fill: red;
17
+ fill-rule: nonzero;
18
+ fill-opacity: 1;
19
+ }
20
+ .arrow-line {
21
+ stroke: red;
22
+ stroke-linecap: round;
23
+ opacity: 0.5;
24
+ }
25
+ }
26
+ .arrow-pointy {
27
+ .arrow-head {
28
+ fill: black;
29
+ fill-rule: nonzero;
30
+ fill-opacity: 1;
31
+ }
32
+ .arrow-line {
33
+ stroke: black;
34
+ stroke-linecap: round;
35
+ opacity: 0.5;
36
+ }
37
+ }
15
38
  }
package/test/TestBoard.js CHANGED
@@ -23,9 +23,9 @@ describe("TestBoard", () => {
23
23
  sprite: {url: "../assets/images/chessboard-sprite.svg"},
24
24
  position: "start"
25
25
  })
26
- assert.equals(chessboard.view.context.childNodes.length, 1)
26
+ assert.equal(chessboard.view.context.childNodes.length, 1)
27
27
  chessboard.destroy()
28
- assert.equals(chessboard.state, undefined)
28
+ assert.equal(chessboard.state, undefined)
29
29
  })
30
30
 
31
31
  })
@@ -14,7 +14,7 @@ describe("TestChessboard", () => {
14
14
  sprite: {url: "../assets/images/chessboard-sprite.svg"},
15
15
  position: "start"
16
16
  })
17
- assert.equals(chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
17
+ assert.equal(chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
18
18
  chessboard.destroy()
19
19
  })
20
20
 
@@ -22,7 +22,7 @@ describe("TestChessboard", () => {
22
22
  const chessboard = new Chessboard(document.getElementById("TestPosition"),
23
23
  {sprite: {url: "../assets/images/chessboard-sprite.svg"},})
24
24
  chessboard.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11", false).then(() => {
25
- assert.equals(chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
25
+ assert.equal(chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
26
26
  chessboard.destroy()
27
27
  })
28
28
  })
@@ -32,9 +32,9 @@ describe("TestChessboard", () => {
32
32
  sprite: {url: "../assets/images/chessboard-sprite.svg"},
33
33
  position: "start"
34
34
  })
35
- assert.equals(chessboard.getPiece("d1"), "wq")
36
- assert.equals(chessboard.getPiece("d8"), "bq")
37
- assert.equals(chessboard.getPiece("a2"), "wp")
35
+ assert.equal(chessboard.getPiece("d1"), "wq")
36
+ assert.equal(chessboard.getPiece("d8"), "bq")
37
+ assert.equal(chessboard.getPiece("a2"), "wp")
38
38
  chessboard.destroy()
39
39
  })
40
40
 
@@ -44,9 +44,9 @@ describe("TestChessboard", () => {
44
44
  sprite: {url: "../assets/images/chessboard-sprite.svg"},
45
45
  })
46
46
  chessboard.setPiece("a1", PIECE.bk)
47
- assert.equals(chessboard.getPiece("a1"), "bk")
47
+ assert.equal(chessboard.getPiece("a1"), "bk")
48
48
  chessboard.setPiece("e5", PIECE.wk)
49
- assert.equals(chessboard.getPiece("e5"), "wk")
49
+ assert.equal(chessboard.getPiece("e5"), "wk")
50
50
  chessboard.destroy()
51
51
  })
52
52
 
@@ -17,24 +17,24 @@ describe("TestMarkers", () => {
17
17
  chessboard.addMarker("e5", MARKER_TYPE.square)
18
18
  chessboard.addMarker("b6", MARKER_TYPE.frame)
19
19
  chessboard.addMarker("h6", MARKER_TYPE.frame)
20
- assert.equals(chessboard.getMarkers().length,3)
20
+ assert.equal(chessboard.getMarkers().length,3)
21
21
  const markersE5 = chessboard.getMarkers("e5")
22
- assert.equals(markersE5.length, 1)
23
- assert.equals(markersE5[0].square, "e5")
24
- assert.equals(markersE5[0].type.slice, "markerSquare")
25
- assert.equals(chessboard.getMarkers(undefined, MARKER_TYPE.square).length, 1)
26
- assert.equals(chessboard.getMarkers("a4").length, 0)
27
- assert.equals(chessboard.getMarkers(undefined, MARKER_TYPE.frame).length, 2)
28
- assert.equals(chessboard.getMarkers("b6", MARKER_TYPE.frame).length, 1)
29
- assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
22
+ assert.equal(markersE5.length, 1)
23
+ assert.equal(markersE5[0].square, "e5")
24
+ assert.equal(markersE5[0].type.slice, "markerSquare")
25
+ assert.equal(chessboard.getMarkers(undefined, MARKER_TYPE.square).length, 1)
26
+ assert.equal(chessboard.getMarkers("a4").length, 0)
27
+ assert.equal(chessboard.getMarkers(undefined, MARKER_TYPE.frame).length, 2)
28
+ assert.equal(chessboard.getMarkers("b6", MARKER_TYPE.frame).length, 1)
29
+ assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
30
30
  chessboard.removeMarkers("h6")
31
- assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
31
+ assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
32
32
  chessboard.addMarker("h6", MARKER_TYPE.frame)
33
- assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
33
+ assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
34
34
  chessboard.removeMarkers("h6", MARKER_TYPE.square)
35
- assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
35
+ assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
36
36
  chessboard.removeMarkers("h6", MARKER_TYPE.frame)
37
- assert.equals(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
37
+ assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
38
38
  chessboard.destroy()
39
39
  })
40
40
 
@@ -10,14 +10,14 @@ import {PositionsAnimation} from "../src/cm-chessboard/view/PositionAnimationsQu
10
10
 
11
11
  describe("TestPiecesAnimation", () => {
12
12
  it("should calculate square distances", () => {
13
- assert.equals(PositionsAnimation.squareDistance(0, 0), 0)
14
- assert.equals(PositionsAnimation.squareDistance(0, 1), 1)
15
- assert.equals(PositionsAnimation.squareDistance(0, 7), 7)
16
- assert.equals(PositionsAnimation.squareDistance(0, 8), 1)
17
- assert.equals(PositionsAnimation.squareDistance(10, 20), 2)
18
- assert.equals(PositionsAnimation.squareDistance(0, 63), 7)
19
- assert.equals(PositionsAnimation.squareDistance(8, 24), 2)
20
- assert.equals(PositionsAnimation.squareDistance(14, 24), 6)
13
+ assert.equal(PositionsAnimation.squareDistance(0, 0), 0)
14
+ assert.equal(PositionsAnimation.squareDistance(0, 1), 1)
15
+ assert.equal(PositionsAnimation.squareDistance(0, 7), 7)
16
+ assert.equal(PositionsAnimation.squareDistance(0, 8), 1)
17
+ assert.equal(PositionsAnimation.squareDistance(10, 20), 2)
18
+ assert.equal(PositionsAnimation.squareDistance(0, 63), 7)
19
+ assert.equal(PositionsAnimation.squareDistance(8, 24), 2)
20
+ assert.equal(PositionsAnimation.squareDistance(14, 24), 6)
21
21
  })
22
22
 
23
23
  it("should seek changes", () => {
@@ -29,24 +29,24 @@ describe("TestPiecesAnimation", () => {
29
29
  const newBoard1 = state2.position.squares
30
30
  const changes = PositionsAnimation.seekChanges(previousBoard1, newBoard1)
31
31
 
32
- assert.equals(changes[0].type,0 )
33
- assert.equals(changes[0].piece, "wn")
34
- assert.equals(changes[0].atIndex, 1)
35
- assert.equals(changes[0].toIndex,3)
32
+ assert.equal(changes[0].type,0 )
33
+ assert.equal(changes[0].piece, "wn")
34
+ assert.equal(changes[0].atIndex, 1)
35
+ assert.equal(changes[0].toIndex,3)
36
36
 
37
- assert.equals(changes[2].type, 0)
38
- assert.equals(changes[2].piece, "wn")
39
- assert.equals(changes[2].atIndex, 6)
40
- assert.equals(changes[2].toIndex, 18)
37
+ assert.equal(changes[2].type, 0)
38
+ assert.equal(changes[2].piece, "wn")
39
+ assert.equal(changes[2].atIndex, 6)
40
+ assert.equal(changes[2].toIndex, 18)
41
41
 
42
- assert.equals(changes[4].type,0 )
43
- assert.equals(changes[4].piece, "wp")
44
- assert.equals(changes[4].atIndex, 8)
45
- assert.equals(changes[4].toIndex, 24)
42
+ assert.equal(changes[4].type,0 )
43
+ assert.equal(changes[4].piece, "wp")
44
+ assert.equal(changes[4].atIndex, 8)
45
+ assert.equal(changes[4].toIndex, 24)
46
46
 
47
- assert.equals(changes[13].type, 2)
48
- assert.equals(changes[13].piece, "bq")
49
- assert.equals(changes[13].atIndex, 59)
47
+ assert.equal(changes[13].type, 2)
48
+ assert.equal(changes[13].piece, "bq")
49
+ assert.equal(changes[13].atIndex, 59)
50
50
  })
51
51
 
52
52
  })
@@ -9,17 +9,17 @@ import {Position} from "../src/cm-chessboard/model/Position.js"
9
9
 
10
10
  describe("TestPosition", () => {
11
11
  it("should convert square to index", () => {
12
- assert.equals(Position.squareToIndex("a1"), 0)
13
- assert.equals(Position.squareToIndex("h1"), 7)
14
- assert.equals(Position.squareToIndex("a8"), 56)
15
- assert.equals(Position.squareToIndex("g5"), 38)
16
- assert.equals(Position.squareToIndex("h8"), 63)
12
+ assert.equal(Position.squareToIndex("a1"), 0)
13
+ assert.equal(Position.squareToIndex("h1"), 7)
14
+ assert.equal(Position.squareToIndex("a8"), 56)
15
+ assert.equal(Position.squareToIndex("g5"), 38)
16
+ assert.equal(Position.squareToIndex("h8"), 63)
17
17
  })
18
18
  it("should convert index to square", () => {
19
- assert.equals(Position.indexToSquare(0), "a1")
20
- assert.equals(Position.indexToSquare(7), "h1")
21
- assert.equals(Position.indexToSquare(56), "a8")
22
- assert.equals(Position.indexToSquare(38), "g5")
23
- assert.equals(Position.indexToSquare(63), "h8")
19
+ assert.equal(Position.indexToSquare(0), "a1")
20
+ assert.equal(Position.indexToSquare(7), "h1")
21
+ assert.equal(Position.indexToSquare(56), "a8")
22
+ assert.equal(Position.indexToSquare(38), "g5")
23
+ assert.equal(Position.indexToSquare(63), "h8")
24
24
  })
25
25
  })