cm-chessboard 6.0.4 → 7.0.2
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/README.md +28 -28
- package/assets/{styles/cm-chessboard.css → chessboard/chessboard.css} +2 -30
- package/assets/chessboard/chessboard.css.map +10 -0
- package/assets/{styles/cm-chessboard.scss → chessboard/chessboard.scss} +2 -43
- package/assets/chessboard/pieces/standard.svg +192 -0
- package/assets/chessboard/pieces/staunty.svg +240 -0
- package/assets/extensions/arrows/arrows.svg +19 -0
- package/assets/extensions/markers/markers.css +26 -0
- package/assets/extensions/markers/markers.css.map +9 -0
- package/assets/extensions/markers/markers.scss +40 -0
- package/assets/extensions/markers/markers.svg +27 -0
- package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.css +1 -1
- package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.css.map +1 -1
- package/{src/cm-chessboard/extensions/promotion-dialog/assets → assets/extensions/promotion-dialog}/promotion-dialog.scss +1 -1
- package/examples/destroy-many-boards.html +5 -3
- package/examples/different-styles.html +34 -23
- package/examples/enable-input.html +14 -7
- package/examples/extensions/{chessboard-accessibility-extension.html → accessibility-extension.html} +6 -4
- package/examples/extensions/{chessboard-arrows-extension.html → arrows-extension.html} +12 -30
- package/examples/{input-callbacks.html → extensions/markers-extension.html} +17 -21
- package/examples/extensions/{chessboard-promotion-dialog-extension.html → promotion-dialog-extension.html} +8 -7
- package/examples/extensions/{chessboard-render-video-extension.html → render-video-extension.html} +3 -8
- package/examples/many-boards.html +5 -5
- package/examples/pieces-animation.html +3 -3
- package/examples/responsive-board.html +3 -5
- package/examples/simple-boards.html +8 -4
- package/examples/test-getPiece.html +3 -3
- package/examples/validate-moves.html +7 -7
- package/index.html +7 -7
- package/package.json +1 -1
- package/src/cm-chessboard/Chessboard.js +19 -25
- package/src/cm-chessboard/extensions/accessibility/Accessibility.js +1 -1
- package/src/cm-chessboard/extensions/arrows/Arrows.js +9 -18
- package/src/cm-chessboard/extensions/markers/Markers.js +28 -17
- package/src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js +4 -6
- package/src/cm-chessboard/extensions/render-video/RenderVideo.js +5 -2
- package/src/cm-chessboard/lib/I18n.js +44 -0
- package/src/cm-chessboard/lib/Svg.js +69 -0
- package/src/cm-chessboard/lib/Utils.js +41 -0
- package/src/cm-chessboard/model/Extension.js +2 -2
- package/src/cm-chessboard/view/ChessboardView.js +47 -173
- package/src/cm-chessboard/view/PositionAnimationsQueue.js +3 -3
- package/src/cm-chessboard/view/VisualMoveInput.js +13 -7
- package/test/TestBoard.js +2 -2
- package/test/TestChessboard.js +4 -4
- package/test/TestMarkers.js +1 -1
- package/test/index.html +1 -1
- package/assets/images/chessboard-sprite-staunty.svg +0 -145
- package/assets/images/chessboard-sprite.svg +0 -144
- package/assets/styles/cm-chessboard.css.map +0 -10
- package/examples/extensions/chessboard-markers-extension.html +0 -52
- package/src/cm-chessboard/extensions/arrows/assets/arrows.svg +0 -31
- /package/assets/{styles/_cm-chessboard-theme.scss → chessboard/_chessboard-theme.scss} +0 -0
- /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.css +0 -0
- /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.css.map +0 -0
- /package/{src/cm-chessboard/extensions/arrows/assets → assets/extensions/arrows}/arrows.scss +0 -0
package/examples/extensions/{chessboard-accessibility-extension.html → accessibility-extension.html}
RENAMED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="../styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../../assets/
|
|
8
|
+
<link rel="stylesheet" href="../../assets/chessboard/chessboard.css"/>
|
|
9
|
+
<link rel="stylesheet" href="../../assets/extensions/markers/markers.css"/>
|
|
9
10
|
</head>
|
|
10
11
|
<body>
|
|
11
12
|
<h1><a href="../..">cm-chessboard</a></h1>
|
|
@@ -31,10 +32,11 @@
|
|
|
31
32
|
<script type="module">
|
|
32
33
|
import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
|
|
33
34
|
import {Accessibility} from "../../src/cm-chessboard/extensions/accessibility/Accessibility.js"
|
|
35
|
+
import {Markers} from "../../src/cm-chessboard/extensions/markers/Markers.js"
|
|
34
36
|
|
|
35
37
|
const chessboard = new Chessboard(document.getElementById("board"), {
|
|
36
38
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
37
|
-
|
|
39
|
+
assetsUrl: "../../assets/",
|
|
38
40
|
// animationDuration: 0, // optional, set to 0 to disable animations
|
|
39
41
|
style: {
|
|
40
42
|
cssClass: "default-contrast" // make the coordinates better visible with the "default-contrast" theme
|
|
@@ -50,9 +52,9 @@
|
|
|
50
52
|
visuallyHidden: false // hide all those extra outputs visually but keep them accessible for screen readers and braille displays
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
}]
|
|
55
|
+
}, {class: Markers}]
|
|
54
56
|
})
|
|
55
|
-
window.
|
|
57
|
+
window.switchOrientation = function () {
|
|
56
58
|
chessboard.setOrientation(chessboard.getOrientation() === 'w' ? 'b' : 'w')
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="../styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../../assets/
|
|
9
|
-
<link rel="stylesheet" href="../../
|
|
8
|
+
<link rel="stylesheet" href="../../assets/chessboard/chessboard.css"/>
|
|
9
|
+
<link rel="stylesheet" href="../../assets/extensions/arrows/arrows.css"/>
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<h1><a href="../..">cm-chessboard</a></h1>
|
|
@@ -15,22 +15,10 @@
|
|
|
15
15
|
<br style="clear: both"/>
|
|
16
16
|
<h2>Example code</h2>
|
|
17
17
|
<pre>
|
|
18
|
-
import {ARROW_TYPE, Arrows} from "../../src/cm-chessboard/extensions/arrows/Arrows.js"
|
|
19
|
-
import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
|
|
20
|
-
|
|
21
18
|
const chessboard = new Chessboard(document.getElementById("board"), {
|
|
22
19
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
23
|
-
|
|
24
|
-
extensions:
|
|
25
|
-
[{
|
|
26
|
-
class: Arrows,
|
|
27
|
-
props: {
|
|
28
|
-
sprite: {
|
|
29
|
-
url: "../../src/cm-chessboard/extensions/arrows/assets/arrows.svg"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}]
|
|
20
|
+
assetsUrl: "../../assets/",
|
|
21
|
+
extensions: [{class: Arrows}]
|
|
34
22
|
})
|
|
35
23
|
chessboard.addArrow(ARROW_TYPE.default, "f3", "d5")
|
|
36
24
|
chessboard.addArrow(ARROW_TYPE.default, "b8", "c6")
|
|
@@ -42,13 +30,16 @@ console.log(chessboard.getArrows())
|
|
|
42
30
|
<h3><code>addArrow(type, from, to)</code></h3>
|
|
43
31
|
<h3><code>removeArrows(type, from, to)</code></h3>
|
|
44
32
|
<p>
|
|
45
|
-
To remove all arrows, call <code>chessboard.removeArrows()</code> without parameters. To remove all arrows of a
|
|
46
|
-
|
|
33
|
+
To remove all arrows, call <code>chessboard.removeArrows()</code> without parameters. To remove all arrows of a
|
|
34
|
+
specific
|
|
35
|
+
type (type "danger"), call <code>chessboard.removeArrows(ARROW_TYPE.danger)</code>. To remove all arrows starting at
|
|
36
|
+
"e2"
|
|
47
37
|
you can call <code>chessboard.removeArrows(undefined, "e2")</code> and so on...
|
|
48
38
|
</p>
|
|
49
39
|
<h3><code>getArrows(type, from, to)</code></h3>
|
|
50
40
|
<p>
|
|
51
|
-
To get all arrows, call <code>chessboard.getArrows()</code> without parameters, as with <code>removeArrows(type,
|
|
41
|
+
To get all arrows, call <code>chessboard.getArrows()</code> without parameters, as with <code>removeArrows(type,
|
|
42
|
+
from, to)</code>.
|
|
52
43
|
</p>
|
|
53
44
|
|
|
54
45
|
<script type="module">
|
|
@@ -57,17 +48,8 @@ console.log(chessboard.getArrows())
|
|
|
57
48
|
|
|
58
49
|
const chessboard = new Chessboard(document.getElementById("board"), {
|
|
59
50
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
60
|
-
|
|
61
|
-
extensions:
|
|
62
|
-
[{
|
|
63
|
-
class: Arrows,
|
|
64
|
-
props: {
|
|
65
|
-
sprite: {
|
|
66
|
-
url: "../../src/cm-chessboard/extensions/arrows/assets/arrows.svg"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}]
|
|
51
|
+
assetsUrl: "../../assets/",
|
|
52
|
+
extensions: [{class: Arrows}]
|
|
71
53
|
})
|
|
72
54
|
chessboard.addArrow(ARROW_TYPE.default, "f3", "d5")
|
|
73
55
|
chessboard.addArrow(ARROW_TYPE.default, "b8", "c6")
|
|
@@ -4,22 +4,24 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
|
-
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="
|
|
7
|
+
<link rel="stylesheet" href="../styles/examples.css"/>
|
|
8
|
+
<link rel="stylesheet" href="../../assets/chessboard/chessboard.css"/>
|
|
9
|
+
<link rel="stylesheet" href="../../assets/extensions/markers/markers.css"/>
|
|
9
10
|
</head>
|
|
10
11
|
<body>
|
|
11
|
-
<h1><a href="
|
|
12
|
-
<h2>Example:
|
|
12
|
+
<h1><a href="../../">cm-chessboard</a></h1>
|
|
13
|
+
<h2>Example: Markers Extension with pointer input</h2>
|
|
14
|
+
<p>The second board shows the usage of autoMarkers, when moving a piece.</p>
|
|
13
15
|
<div class="board" id="board1"></div>
|
|
14
16
|
<div class="board" id="board2"></div>
|
|
15
17
|
<script type="module">
|
|
16
|
-
import {Chessboard,
|
|
17
|
-
import {FEN} from "
|
|
18
|
-
import {MARKER_TYPE, Markers} from "
|
|
18
|
+
import {Chessboard, SQUARE_SELECT_TYPE} from "../../src/cm-chessboard/Chessboard.js"
|
|
19
|
+
import {FEN} from "../../src/cm-chessboard/model/Position.js"
|
|
20
|
+
import {MARKER_TYPE, Markers} from "../../src/cm-chessboard/extensions/markers/Markers.js"
|
|
19
21
|
|
|
20
22
|
const board1 = new Chessboard(document.getElementById("board1"), {
|
|
21
23
|
position: FEN.start,
|
|
22
|
-
|
|
24
|
+
assetsUrl: "../../assets/",
|
|
23
25
|
extensions: [{class: Markers}]
|
|
24
26
|
})
|
|
25
27
|
board1.enableSquareSelect((event) => {
|
|
@@ -45,23 +47,17 @@
|
|
|
45
47
|
|
|
46
48
|
const board2 = new Chessboard(document.getElementById("board2"), {
|
|
47
49
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR",
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
assetsCache: false,
|
|
51
|
+
assetsUrl: "../../assets/",
|
|
52
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
53
|
+
extensions: [{class: Markers, autoMarkers: MARKER_TYPE.frame}]
|
|
50
54
|
})
|
|
51
|
-
board2.enableMoveInput((
|
|
52
|
-
console.log("MoveInput board2", event)
|
|
53
|
-
board2.removeMarkers(MARKER_TYPE.frame)
|
|
54
|
-
if(event.type === INPUT_EVENT_TYPE.moveInputStarted) {
|
|
55
|
-
board2.addMarker(MARKER_TYPE.frame, event.square)
|
|
56
|
-
} else if(event.type === INPUT_EVENT_TYPE.validateMoveInput) {
|
|
57
|
-
board2.addMarker(MARKER_TYPE.frame, event.squareFrom)
|
|
58
|
-
board2.addMarker(MARKER_TYPE.frame, event.squareTo)
|
|
59
|
-
}
|
|
55
|
+
board2.enableMoveInput(() => {
|
|
60
56
|
return true
|
|
61
57
|
})
|
|
62
|
-
const marker = {class: "
|
|
58
|
+
const marker = {class: "marker-circle-red", slice: "markerCircle"}
|
|
63
59
|
board2.enableSquareSelect((event) => {
|
|
64
|
-
if(event.type === SQUARE_SELECT_TYPE.secondary && event.mouseEvent.type === "mousedown") {
|
|
60
|
+
if (event.type === SQUARE_SELECT_TYPE.secondary && event.mouseEvent.type === "mousedown") {
|
|
65
61
|
const markersOnSquare = board2.getMarkers(marker, event.square)
|
|
66
62
|
if (markersOnSquare.length > 0) {
|
|
67
63
|
board2.removeMarkers(marker, event.square)
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
8
8
|
<link rel="stylesheet" href="../styles/examples.css"/>
|
|
9
|
-
<link rel="stylesheet" href="../../assets/
|
|
10
|
-
<link rel="stylesheet" href="../../
|
|
9
|
+
<link rel="stylesheet" href="../../assets/chessboard/chessboard.css">
|
|
10
|
+
<link rel="stylesheet" href="../../assets/extensions/promotion-dialog/promotion-dialog.css"/>
|
|
11
|
+
<link rel="stylesheet" href="../../assets/extensions/markers/markers.css"/>
|
|
11
12
|
<title>cm-chessboard promotion extension</title>
|
|
12
13
|
</head>
|
|
13
14
|
<body>
|
|
@@ -21,15 +22,15 @@
|
|
|
21
22
|
<script type="module">
|
|
22
23
|
import {Chessboard, COLOR, INPUT_EVENT_TYPE} from "../../src/cm-chessboard/Chessboard.js"
|
|
23
24
|
import {PromotionDialog} from "../../src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js"
|
|
25
|
+
import {Markers} from "../../src/cm-chessboard/extensions/markers/Markers.js"
|
|
24
26
|
|
|
25
27
|
const position = "4k3/1P6/8/8/6r1/8/8/2R1K3 w - - 0 1"
|
|
26
28
|
const chessboard = new Chessboard(document.getElementById("chessboard"), {
|
|
27
29
|
position: position,
|
|
28
|
-
|
|
29
|
-
url: "../../assets/images/chessboard-sprite.svg", // pieces and markers are stored in a sprite file
|
|
30
|
-
},
|
|
30
|
+
assetsUrl: "../../assets/",
|
|
31
31
|
extensions: [
|
|
32
|
-
{class: PromotionDialog,
|
|
32
|
+
{class: PromotionDialog},
|
|
33
|
+
{class: Markers}
|
|
33
34
|
]
|
|
34
35
|
})
|
|
35
36
|
chessboard.enableMoveInput((event) => {
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
if (event.squareTo.charAt(1) === "8" && event.piece.charAt(1) === "p") {
|
|
39
40
|
chessboard.showPromotionDialog(event.squareTo, COLOR.white, (event) => {
|
|
40
41
|
console.log("48a99d Piece selected", event.piece)
|
|
41
|
-
if(event.piece) {
|
|
42
|
+
if (event.piece) {
|
|
42
43
|
chessboard.setPiece(event.square, event.piece, true)
|
|
43
44
|
} else {
|
|
44
45
|
chessboard.setPosition(position)
|
package/examples/extensions/{chessboard-render-video-extension.html → render-video-extension.html}
RENAMED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="../styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../../assets/
|
|
8
|
+
<link rel="stylesheet" href="../../assets/chessboard/chessboard.css"/>
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<h1><a href="../..">cm-chessboard</a></h1>
|
|
@@ -24,13 +24,8 @@
|
|
|
24
24
|
const boardElement = document.getElementById("board")
|
|
25
25
|
const chessboard = new Chessboard(boardElement, {
|
|
26
26
|
position: FEN.start,
|
|
27
|
-
|
|
28
|
-
extensions:
|
|
29
|
-
[{
|
|
30
|
-
class: RenderVideo,
|
|
31
|
-
props: {}
|
|
32
|
-
}]
|
|
33
|
-
})
|
|
27
|
+
assetsUrl: "../../assets/",
|
|
28
|
+
extensions: [{class: RenderVideo}]})
|
|
34
29
|
await chessboard.recorderInit()
|
|
35
30
|
await chessboard.recorderStart()
|
|
36
31
|
await chessboard.recorderPause(500)
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../assets/
|
|
8
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
|
|
9
9
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js"></script>
|
|
10
10
|
<!--suppress CssUnusedSymbol -->
|
|
11
|
-
<style
|
|
11
|
+
<style>
|
|
12
12
|
div.board {
|
|
13
13
|
float: left;
|
|
14
14
|
width: 155px;
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
boardDiv.setAttribute("class", "board")
|
|
33
33
|
boardsDiv.appendChild(boardDiv)
|
|
34
34
|
new Chessboard(boardDiv, {
|
|
35
|
-
accessible: true,
|
|
36
35
|
responsive: false,
|
|
37
36
|
position: game.fen(),
|
|
38
|
-
|
|
37
|
+
assetsUrl: "../assets/",
|
|
38
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
39
39
|
})
|
|
40
40
|
makeRandomMove()
|
|
41
41
|
}
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
}
|
|
48
48
|
</script>
|
|
49
49
|
</body>
|
|
50
|
-
</html>
|
|
50
|
+
</html>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../assets/
|
|
8
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<h1><a href="../">cm-chessboard</a></h1>
|
|
@@ -50,8 +50,8 @@ await board.movePiece("d5", "f4")
|
|
|
50
50
|
const board = new Chessboard(document.getElementById("board"),
|
|
51
51
|
{
|
|
52
52
|
position: FEN.start,
|
|
53
|
-
|
|
54
|
-
animationDuration: 500
|
|
53
|
+
assetsUrl: "../assets/",
|
|
54
|
+
style: {pieces: {file: "staunty.svg"}, animationDuration: 500}
|
|
55
55
|
})
|
|
56
56
|
let i = 0
|
|
57
57
|
window.setPosition = (position, animated) => {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../assets/
|
|
8
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<h1><a href="../">cm-chessboard</a></h1>
|
|
@@ -23,10 +23,8 @@ new Chessboard(document.getElementById("board"), {
|
|
|
23
23
|
|
|
24
24
|
new Chessboard(document.getElementById("board"), {
|
|
25
25
|
position: FEN.start,
|
|
26
|
-
|
|
27
|
-
style: {
|
|
28
|
-
aspectRatio: 0.9
|
|
29
|
-
}
|
|
26
|
+
assetsUrl: "../assets/",
|
|
27
|
+
style: {aspectRatio: 0.9, pieces: {file: "staunty.svg"}}
|
|
30
28
|
})
|
|
31
29
|
</script>
|
|
32
30
|
</body>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
|
-
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../assets/
|
|
7
|
+
<link rel="stylesheet" href="./styles/examples.css"/>
|
|
8
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<h1><a href="../">cm-chessboard</a></h1>
|
|
@@ -19,6 +19,8 @@ new Chessboard(document.getElementById("board1"), {
|
|
|
19
19
|
})
|
|
20
20
|
new Chessboard(document.getElementById("board2"), {
|
|
21
21
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
22
|
+
assetsCache: false,
|
|
23
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
22
24
|
orientation: COLOR.black
|
|
23
25
|
})
|
|
24
26
|
</pre>
|
|
@@ -28,11 +30,13 @@ new Chessboard(document.getElementById("board2"), {
|
|
|
28
30
|
|
|
29
31
|
new Chessboard(document.getElementById("board1"), {
|
|
30
32
|
position: FEN.start,
|
|
31
|
-
|
|
33
|
+
assetsUrl: "../assets/"
|
|
32
34
|
})
|
|
33
35
|
new Chessboard(document.getElementById("board2"), {
|
|
34
36
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
|
|
35
|
-
|
|
37
|
+
assetsUrl: "../assets/",
|
|
38
|
+
assetsCache: false,
|
|
39
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
36
40
|
orientation: COLOR.black
|
|
37
41
|
})
|
|
38
42
|
</script>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html>
|
|
2
|
+
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<link rel="stylesheet" href="../assets/
|
|
4
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css">
|
|
5
5
|
<title>frame test</title>
|
|
6
6
|
</head>
|
|
7
7
|
<body>
|
|
@@ -9,7 +9,7 @@ Board:
|
|
|
9
9
|
<div id="board"></div>
|
|
10
10
|
|
|
11
11
|
<script type="module">
|
|
12
|
-
import { Chessboard
|
|
12
|
+
import { Chessboard } from '../src/cm-chessboard/Chessboard.js'
|
|
13
13
|
|
|
14
14
|
const board = new Chessboard(document.getElementById('board'), {
|
|
15
15
|
position: 'start',
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
7
7
|
<link rel="stylesheet" href="styles/examples.css"/>
|
|
8
|
-
<link rel="stylesheet" href="../assets/
|
|
8
|
+
<link rel="stylesheet" href="../assets/chessboard/chessboard.css"/>
|
|
9
|
+
<link rel="stylesheet" href="../assets/extensions/markers/markers.css"/>
|
|
9
10
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js"></script>
|
|
10
11
|
</head>
|
|
11
12
|
<body>
|
|
@@ -58,8 +59,7 @@ function inputHandler(event) {
|
|
|
58
59
|
|
|
59
60
|
const board = new Chessboard(document.getElementById("board"), {
|
|
60
61
|
position: chess.fen(),
|
|
61
|
-
|
|
62
|
-
style: {moveFromMarker: undefined, moveToMarker: undefined}, // disable standard markers
|
|
62
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
63
63
|
orientation: COLOR.white
|
|
64
64
|
})
|
|
65
65
|
board.enableMoveInput(inputHandler, COLOR.white)
|
|
@@ -76,7 +76,7 @@ board.enableMoveInput(inputHandler, COLOR.white)
|
|
|
76
76
|
console.log("event", event)
|
|
77
77
|
event.chessboard.removeMarkers(MARKER_TYPE.dot)
|
|
78
78
|
if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
|
|
79
|
-
const moves = chess.moves({square: event.square, verbose: true})
|
|
79
|
+
const moves = chess.moves({square: event.square, verbose: true})
|
|
80
80
|
for (const move of moves) { // draw dots on possible squares
|
|
81
81
|
event.chessboard.addMarker(MARKER_TYPE.dot, move.to)
|
|
82
82
|
}
|
|
@@ -109,10 +109,10 @@ board.enableMoveInput(inputHandler, COLOR.white)
|
|
|
109
109
|
|
|
110
110
|
const board = new Chessboard(document.getElementById("board"), {
|
|
111
111
|
position: chess.fen(),
|
|
112
|
-
|
|
113
|
-
style: {
|
|
112
|
+
assetsUrl: "../assets/",
|
|
113
|
+
style: {pieces: {file: "staunty.svg"}},
|
|
114
114
|
orientation: COLOR.white,
|
|
115
|
-
extensions: [{class: Markers}]
|
|
115
|
+
extensions: [{class: Markers, props: {autoMarkers: MARKER_TYPE.square}}]
|
|
116
116
|
})
|
|
117
117
|
board.enableMoveInput(inputHandler, COLOR.white)
|
|
118
118
|
</script>
|
package/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<title>cm-chessboard</title>
|
|
6
|
-
<link rel="stylesheet" href="assets/
|
|
6
|
+
<link rel="stylesheet" href="assets/chessboard/chessboard.css"/>
|
|
7
7
|
<link rel="stylesheet" href="examples/styles/examples.css"/>
|
|
8
8
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0"/>
|
|
9
9
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.2/chess.js"></script>
|
|
@@ -22,17 +22,17 @@ It works, it is cool and it is easy to use. 👍</p>
|
|
|
22
22
|
<li><a href="examples/enable-input.html">Input enabled without validation</a></li>
|
|
23
23
|
<li><a href="examples/validate-moves.html">Input enabled, move validation with chess.js</a> 🥸</li>
|
|
24
24
|
<li><a href="examples/pieces-animation.html">Set different positions, with animation</a></li>
|
|
25
|
-
<li><a href="examples/
|
|
25
|
+
<li><a href="examples/extensions/markers-extension.html">Context input, mark squares and detect clicks on fields</a></li>
|
|
26
26
|
<li><a href="examples/different-styles.html">Different styles and piece sets</a> 🎨</li>
|
|
27
27
|
<li><a href="examples/destroy-many-boards.html">Stress test, 5000 boards created and destroyed</a> 🤓 👍</li>
|
|
28
28
|
</ul>
|
|
29
29
|
<h3>Examples using the cm-chessboard extensions</h3>
|
|
30
30
|
<ul>
|
|
31
|
-
<li><a href="examples/extensions/
|
|
32
|
-
<li><a href="examples/extensions/
|
|
33
|
-
<li><a href="examples/extensions/
|
|
34
|
-
<li><a href="examples/extensions/
|
|
35
|
-
<li><a href="examples/extensions/
|
|
31
|
+
<li><a href="examples/extensions/accessibility-extension.html">Accessibility extension</a></li>
|
|
32
|
+
<li><a href="examples/extensions/arrows-extension.html">Arrows extension</a></li>
|
|
33
|
+
<li><a href="examples/extensions/markers-extension.html">Markers extension</a> 🆕</li>
|
|
34
|
+
<li><a href="examples/extensions/promotion-dialog-extension.html">PromotionDialog extension</a></li>
|
|
35
|
+
<li><a href="examples/extensions/render-video-extension.html">RenderVideo extension</a> 🆕</li>
|
|
36
36
|
</ul>
|
|
37
37
|
</div>
|
|
38
38
|
<h2>Chessboard</h2>
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ 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
11
|
import {ChessboardView} from "./view/ChessboardView.js"
|
|
12
|
+
import {Utils} from "./lib/Utils.js"
|
|
12
13
|
|
|
13
14
|
export const COLOR = {
|
|
14
15
|
white: "w",
|
|
@@ -16,8 +17,9 @@ export const COLOR = {
|
|
|
16
17
|
}
|
|
17
18
|
export const INPUT_EVENT_TYPE = {
|
|
18
19
|
moveInputStarted: "moveInputStarted",
|
|
20
|
+
movingOverSquare: "movingOverSquare", // while dragging or hover after click
|
|
19
21
|
validateMoveInput: "validateMoveInput",
|
|
20
|
-
moveInputCanceled: "moveInputCanceled"
|
|
22
|
+
moveInputCanceled: "moveInputCanceled"
|
|
21
23
|
}
|
|
22
24
|
export const SQUARE_SELECT_TYPE = {
|
|
23
25
|
primary: "primary",
|
|
@@ -33,6 +35,10 @@ export const PIECE = {
|
|
|
33
35
|
bp: "bp", bb: "bb", bn: "bn", br: "br", bq: "bq", bk: "bk"
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
export const PIECES_FILE_TYPE = {
|
|
39
|
+
svgSprite: "svgSprite"
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
export class Chessboard {
|
|
37
43
|
|
|
38
44
|
constructor(context, props = {}) {
|
|
@@ -42,43 +48,31 @@ export class Chessboard {
|
|
|
42
48
|
this.context = context
|
|
43
49
|
this.id = (Math.random() + 1).toString(36).substring(2, 8)
|
|
44
50
|
this.extensions = []
|
|
45
|
-
|
|
46
|
-
position: FEN.empty, // set as fen,
|
|
51
|
+
this.props = {
|
|
52
|
+
position: FEN.empty, // set position as fen, use FEN.start or FEN.empty as shortcuts
|
|
47
53
|
orientation: COLOR.white, // white on bottom
|
|
48
54
|
responsive: true, // resize the board automatically to the size of the context element
|
|
49
|
-
animationDuration: 300, // pieces animation duration in milliseconds. Disable all animation with `0`.
|
|
50
55
|
language: navigator.language.substring(0, 2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
|
|
56
|
+
assetsUrl: "./assets/", // put all css and sprites in this folder
|
|
57
|
+
assetsCache: true, // cache sprites
|
|
51
58
|
style: {
|
|
52
59
|
cssClass: "default", // set the css theme of the board, try "green", "blue" or "chess-club"
|
|
53
60
|
showCoordinates: true, // show ranks and files
|
|
54
61
|
borderType: BORDER_TYPE.none, // "thin" thin border, "frame" wide border with coordinates in it, "none" no border
|
|
55
62
|
aspectRatio: 1, // height/width of the board
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
pieces: {
|
|
64
|
+
type: PIECES_FILE_TYPE.svgSprite, // pieces are in a SVG sprite, no other type supported for now
|
|
65
|
+
file: "standard.svg", // the filename of the sprite in `assets/chessboard/pieces/`
|
|
66
|
+
tileSize: 40 // the tile size in the sprite
|
|
67
|
+
},
|
|
68
|
+
animationDuration: 300 // pieces animation duration in milliseconds. Disable all animations with `0`.
|
|
61
69
|
},
|
|
62
70
|
extensions: [ /* {class: ExtensionClass, props: { ... }} */] // add extensions here
|
|
63
71
|
}
|
|
64
|
-
this.props
|
|
65
|
-
Object.assign(this.props, defaultProps)
|
|
66
|
-
Object.assign(this.props, props)
|
|
67
|
-
this.props.sprite = defaultProps.sprite
|
|
68
|
-
this.props.style = defaultProps.style
|
|
69
|
-
if (props.sprite) {
|
|
70
|
-
Object.assign(this.props.sprite, props.sprite)
|
|
71
|
-
}
|
|
72
|
-
if (props.style) {
|
|
73
|
-
Object.assign(this.props.style, props.style)
|
|
74
|
-
}
|
|
75
|
-
if (props.extensions) {
|
|
76
|
-
this.props.extensions = props.extensions
|
|
77
|
-
}
|
|
72
|
+
Utils.mergeObjects(this.props, props)
|
|
78
73
|
if (this.props.language !== "de" && this.props.language !== "en") {
|
|
79
74
|
this.props.language = "en"
|
|
80
75
|
}
|
|
81
|
-
|
|
82
76
|
this.state = new ChessboardState()
|
|
83
77
|
this.view = new ChessboardView(this)
|
|
84
78
|
this.positionAnimationsQueue = new PositionAnimationsQueue(this)
|
|
@@ -112,7 +106,7 @@ export class Chessboard {
|
|
|
112
106
|
async setPosition(fen, animated = false) {
|
|
113
107
|
const positionFrom = this.state.position.clone()
|
|
114
108
|
const positionTo = new Position(fen)
|
|
115
|
-
if(positionFrom.getFen() !== positionTo.getFen()) {
|
|
109
|
+
if (positionFrom.getFen() !== positionTo.getFen()) {
|
|
116
110
|
this.state.position.setFen(fen)
|
|
117
111
|
this.state.invokeExtensionPoints(EXTENSION_POINT.positionChanged)
|
|
118
112
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* License: MIT, see file 'LICENSE'
|
|
5
5
|
*/
|
|
6
6
|
import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
|
|
7
|
-
import {piecesTranslations, renderPieceTitle} from "../../view/ChessboardView.js"
|
|
8
7
|
import {COLOR, INPUT_EVENT_TYPE} from "../../Chessboard.js"
|
|
8
|
+
import {piecesTranslations, renderPieceTitle} from "../../lib/I18n.js"
|
|
9
9
|
|
|
10
10
|
const hlTranslations = {
|
|
11
11
|
de: {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
|
|
8
|
-
import {Svg} from "../../
|
|
8
|
+
import {Svg} from "../../lib/Svg.js"
|
|
9
9
|
|
|
10
10
|
export const ARROW_TYPE = {
|
|
11
11
|
default: {class: "arrow-default", slice: "arrowDefault", headSize: 7},
|
|
@@ -14,27 +14,18 @@ export const ARROW_TYPE = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export class Arrows extends Extension {
|
|
17
|
-
constructor(chessboard, props) {
|
|
17
|
+
constructor(chessboard, props = {}) {
|
|
18
18
|
super(chessboard, props)
|
|
19
19
|
this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, () => {
|
|
20
20
|
this.onRedrawBoard()
|
|
21
21
|
})
|
|
22
|
-
|
|
23
|
-
sprite:
|
|
24
|
-
url: "./assets/images/chessboard-arrows.svg",
|
|
25
|
-
size: 40,
|
|
26
|
-
cache: true
|
|
27
|
-
},
|
|
22
|
+
this.props = {
|
|
23
|
+
sprite: "arrows.svg"
|
|
28
24
|
}
|
|
29
|
-
this.props = {}
|
|
30
|
-
Object.assign(this.props, defaultProps)
|
|
31
25
|
Object.assign(this.props, props)
|
|
32
|
-
this.props.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (this.props.sprite.cache) {
|
|
37
|
-
this.chessboard.view.cacheSpriteToDiv("chessboardArrowSpriteCache", this.props.sprite.url)
|
|
26
|
+
if (this.chessboard.props.assetsCache) {
|
|
27
|
+
this.chessboard.view.cacheSpriteToDiv("cm-chessboard-arrows",
|
|
28
|
+
this.chessboard.props.assetsUrl + "extensions/arrows/" + this.props.sprite)
|
|
38
29
|
}
|
|
39
30
|
this.registerMethod("addArrow", this.addArrow)
|
|
40
31
|
this.registerMethod("getArrows", this.getArrows)
|
|
@@ -56,11 +47,11 @@ export class Arrows extends Extension {
|
|
|
56
47
|
const arrowsGroup = Svg.addElement(this.arrowGroup, "g")
|
|
57
48
|
arrowsGroup.setAttribute("data-arrow", arrow.from + arrow.to)
|
|
58
49
|
arrowsGroup.setAttribute("class", "arrow " + arrow.type.class)
|
|
59
|
-
|
|
60
50
|
const view = this.chessboard.view
|
|
61
51
|
const sqfrom = document.querySelectorAll('[data-square="' + arrow.from + '"]')[0]
|
|
62
52
|
const sqto = document.querySelectorAll('[data-square="' + arrow.to + '"]')[0]
|
|
63
|
-
const spriteUrl = this.chessboard.props.
|
|
53
|
+
const spriteUrl = this.chessboard.props.assetsCache ? "" : this.chessboard.props.assetsUrl +
|
|
54
|
+
"extensions/arrows/" + this.props.sprite
|
|
64
55
|
const defs = Svg.addElement(arrowsGroup, "defs")
|
|
65
56
|
const id = "arrow-" + arrow.from + arrow.to
|
|
66
57
|
const marker = Svg.addElement(defs, "marker", {
|