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.
- package/examples/extensions/chessboard-arrows-extension.html +28 -8
- package/package.json +1 -1
- package/src/cm-chessboard/extensions/arrows/Arrows.js +5 -0
- package/src/cm-chessboard/extensions/arrows/assets/arrows.css +22 -2
- package/src/cm-chessboard/extensions/arrows/assets/arrows.css.map +1 -1
- package/src/cm-chessboard/extensions/arrows/assets/arrows.scss +25 -2
- package/test/TestBoard.js +2 -2
- package/test/TestChessboard.js +7 -7
- package/test/TestMarkers.js +13 -13
- package/test/TestPiecesAnimation.js +23 -23
- package/test/TestPosition.js +10 -10
|
@@ -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.
|
|
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
|
@@ -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 .
|
|
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 .
|
|
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,
|
|
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
|
-
.
|
|
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.
|
|
26
|
+
assert.equal(chessboard.view.context.childNodes.length, 1)
|
|
27
27
|
chessboard.destroy()
|
|
28
|
-
assert.
|
|
28
|
+
assert.equal(chessboard.state, undefined)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
})
|
package/test/TestChessboard.js
CHANGED
|
@@ -14,7 +14,7 @@ describe("TestChessboard", () => {
|
|
|
14
14
|
sprite: {url: "../assets/images/chessboard-sprite.svg"},
|
|
15
15
|
position: "start"
|
|
16
16
|
})
|
|
17
|
-
assert.
|
|
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.
|
|
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.
|
|
36
|
-
assert.
|
|
37
|
-
assert.
|
|
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.
|
|
47
|
+
assert.equal(chessboard.getPiece("a1"), "bk")
|
|
48
48
|
chessboard.setPiece("e5", PIECE.wk)
|
|
49
|
-
assert.
|
|
49
|
+
assert.equal(chessboard.getPiece("e5"), "wk")
|
|
50
50
|
chessboard.destroy()
|
|
51
51
|
})
|
|
52
52
|
|
package/test/TestMarkers.js
CHANGED
|
@@ -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.
|
|
20
|
+
assert.equal(chessboard.getMarkers().length,3)
|
|
21
21
|
const markersE5 = chessboard.getMarkers("e5")
|
|
22
|
-
assert.
|
|
23
|
-
assert.
|
|
24
|
-
assert.
|
|
25
|
-
assert.
|
|
26
|
-
assert.
|
|
27
|
-
assert.
|
|
28
|
-
assert.
|
|
29
|
-
assert.
|
|
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.
|
|
31
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
|
|
32
32
|
chessboard.addMarker("h6", MARKER_TYPE.frame)
|
|
33
|
-
assert.
|
|
33
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
|
|
34
34
|
chessboard.removeMarkers("h6", MARKER_TYPE.square)
|
|
35
|
-
assert.
|
|
35
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
|
|
36
36
|
chessboard.removeMarkers("h6", MARKER_TYPE.frame)
|
|
37
|
-
assert.
|
|
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.
|
|
14
|
-
assert.
|
|
15
|
-
assert.
|
|
16
|
-
assert.
|
|
17
|
-
assert.
|
|
18
|
-
assert.
|
|
19
|
-
assert.
|
|
20
|
-
assert.
|
|
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.
|
|
33
|
-
assert.
|
|
34
|
-
assert.
|
|
35
|
-
assert.
|
|
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.
|
|
38
|
-
assert.
|
|
39
|
-
assert.
|
|
40
|
-
assert.
|
|
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.
|
|
43
|
-
assert.
|
|
44
|
-
assert.
|
|
45
|
-
assert.
|
|
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.
|
|
48
|
-
assert.
|
|
49
|
-
assert.
|
|
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
|
})
|
package/test/TestPosition.js
CHANGED
|
@@ -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.
|
|
13
|
-
assert.
|
|
14
|
-
assert.
|
|
15
|
-
assert.
|
|
16
|
-
assert.
|
|
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.
|
|
20
|
-
assert.
|
|
21
|
-
assert.
|
|
22
|
-
assert.
|
|
23
|
-
assert.
|
|
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
|
})
|