cm-chessboard 8.14.2 → 8.15.0

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.
Files changed (38) hide show
  1. package/package.json +9 -2
  2. package/src/extensions/promotion-dialog/PromotionDialog.js +8 -34
  3. package/.claude/settings.local.json +0 -28
  4. package/assets/extensions/arrows/arrows.sketch +0 -0
  5. package/examples/destroy-many-boards.html +0 -80
  6. package/examples/different-styles.html +0 -109
  7. package/examples/enable-input.html +0 -97
  8. package/examples/extensions/accessibility-extension.html +0 -78
  9. package/examples/extensions/arrows-extension.html +0 -63
  10. package/examples/extensions/html-layer-extension.html +0 -66
  11. package/examples/extensions/markers-extension.html +0 -79
  12. package/examples/extensions/persistence-extension.html +0 -29
  13. package/examples/extensions/piece-rotation-extension.html +0 -53
  14. package/examples/extensions/promotion-dialog-extension.html +0 -61
  15. package/examples/extensions/right-click-annotator.html +0 -39
  16. package/examples/many-boards.html +0 -50
  17. package/examples/pieces-animation.html +0 -89
  18. package/examples/pointer-events.html +0 -32
  19. package/examples/responsive-board.html +0 -45
  20. package/examples/sandbox/arrows-extension-multiple.html +0 -59
  21. package/examples/simple-boards.html +0 -45
  22. package/examples/styles/examples.css +0 -79
  23. package/examples/styles/examples.css.map +0 -9
  24. package/examples/styles/examples.scss +0 -107
  25. package/examples/validate-moves-chess960.html +0 -121
  26. package/examples/validate-moves.html +0 -114
  27. package/favicon.ico +0 -0
  28. package/index.html +0 -84
  29. package/test/TestArrows.js +0 -33
  30. package/test/TestChessboard.js +0 -183
  31. package/test/TestMarkers.js +0 -57
  32. package/test/TestPieceRotation.js +0 -138
  33. package/test/TestPiecesAnimation.js +0 -53
  34. package/test/TestPosition.js +0 -79
  35. package/test/TestVisualMoveInput.js +0 -413
  36. package/test/headless.mjs +0 -109
  37. package/test/index.html +0 -37
  38. package/test/mocks/ViewMock.js +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.14.2",
3
+ "version": "8.15.0",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -15,9 +15,16 @@
15
15
  "type": "module",
16
16
  "module": "./src/Chessboard.js",
17
17
  "browser": "./src/Chessboard.js",
18
+ "files": [
19
+ "src",
20
+ "assets",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
18
24
  "scripts": {
19
25
  "test": "tput setaf 4;echo 'Run test/index.html in your browser for unit testing, or `npm run test:headless` (needs a global puppeteer).'; echo ''; exit 0",
20
- "test:headless": "node test/headless.mjs"
26
+ "test:headless": "node test/headless.mjs",
27
+ "test:package": "node test/package.mjs"
21
28
  },
22
29
  "repository": {
23
30
  "type": "git",
@@ -167,41 +167,15 @@ export class PromotionDialog extends Extension {
167
167
  class: "promotion-dialog"
168
168
  })
169
169
  const dialogParams = this.state.dialogParams
170
- if (turned) {
171
- this.drawPieceButton(PIECE[dialogParams.color + "q"], {
170
+ // The buttons share their order with `this.pieceOrder`, which `focusButton()`
171
+ // uses for the screen reader announcement, so both must stay in sync.
172
+ this.pieceOrder.forEach((pieceType, index) => {
173
+ const rowOffset = turned ? -(index + 1) : index
174
+ this.drawPieceButton(PIECE[dialogParams.color + pieceType], {
172
175
  x: squareCenterPoint.x + offsetX,
173
- y: squareCenterPoint.y - squareHeight
174
- }, 0)
175
- this.drawPieceButton(PIECE[dialogParams.color + "r"], {
176
- x: squareCenterPoint.x + offsetX,
177
- y: squareCenterPoint.y - squareHeight * 2
178
- }, 1)
179
- this.drawPieceButton(PIECE[dialogParams.color + "b"], {
180
- x: squareCenterPoint.x + offsetX,
181
- y: squareCenterPoint.y - squareHeight * 3
182
- }, 2)
183
- this.drawPieceButton(PIECE[dialogParams.color + "n"], {
184
- x: squareCenterPoint.x + offsetX,
185
- y: squareCenterPoint.y - squareHeight * 4
186
- }, 3)
187
- } else {
188
- this.drawPieceButton(PIECE[dialogParams.color + "q"], {
189
- x: squareCenterPoint.x + offsetX,
190
- y: squareCenterPoint.y
191
- }, 0)
192
- this.drawPieceButton(PIECE[dialogParams.color + "r"], {
193
- x: squareCenterPoint.x + offsetX,
194
- y: squareCenterPoint.y + squareHeight
195
- }, 1)
196
- this.drawPieceButton(PIECE[dialogParams.color + "b"], {
197
- x: squareCenterPoint.x + offsetX,
198
- y: squareCenterPoint.y + squareHeight * 2
199
- }, 2)
200
- this.drawPieceButton(PIECE[dialogParams.color + "n"], {
201
- x: squareCenterPoint.x + offsetX,
202
- y: squareCenterPoint.y + squareHeight * 3
203
- }, 3)
204
- }
176
+ y: squareCenterPoint.y + rowOffset * squareHeight
177
+ }, index)
178
+ })
205
179
  }
206
180
  }
207
181
 
@@ -1,28 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(tree:*)",
5
- "Bash(gh pr:*)",
6
- "Bash(gh issue:*)",
7
- "Bash(npm version:*)",
8
- "Bash(npm publish:*)",
9
- "Bash(gh search:*)",
10
- "Skill(schedule)",
11
- "Bash(npm whoami *)",
12
- "Bash(cat)",
13
- "Bash(rm /tmp/pr165-comment.md)",
14
- "Read(//Users/shaack/Development/repositories/MyProjects/**)",
15
- "Bash(gh release *)",
16
- "Bash(gh api *)",
17
- "Bash(pkill -f \"http.server 8731\")",
18
- "Bash(rm -f /tmp/bis-server.log)",
19
- "Bash(rm /tmp/issue56.md)",
20
- "Bash([ -d \"$d\" ])",
21
- "Bash(pkill -f \"http.server 8732\")",
22
- "Bash(rm -f /tmp/bsm-server.log)",
23
- "Bash(rm -f c26.md c19.md)"
24
- ],
25
- "deny": [],
26
- "ask": []
27
- }
28
- }
@@ -1,80 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- <!--suppress CssUnusedSymbol -->
10
- <style>
11
- div.board {
12
- float: left;
13
- width: 4.2vw;
14
- height: 4.2vw;
15
- margin-right: 0.2vw;
16
- margin-bottom: 0.2vw;
17
- }
18
-
19
- div.board1 {
20
- float: left;
21
- width: 43.1vw;
22
- margin-right: 0.9vw;
23
- margin-bottom: 0.5vw;
24
- }
25
- </style>
26
- </head>
27
- <body>
28
- <h1><a href="../">cm-chessboard</a></h1>
29
- <h2>Stress Test: Create and destroy 5,000 boards ⇨ <span id="counter"></span></h2>
30
- <div id="boards"></div>
31
- <script type="module">
32
- import {Chessboard} from "../src/Chessboard.js"
33
- import {FEN} from "../src/model/Position.js"
34
- import {Chess} from "https://cdn.jsdelivr.net/npm/chess.mjs@1/src/chess.mjs/Chess.js"
35
-
36
- const boardsDiv = document.getElementById("boards")
37
- const boardDiv = document.createElement("div")
38
- boardDiv.setAttribute("class", "board1")
39
- boardsDiv.appendChild(boardDiv)
40
- const largeBoard = new Chessboard(boardDiv, {
41
- position: FEN.start,
42
- assetsUrl: "../assets/",
43
- style: {pieces: {file: "pieces/staunty.svg"}}
44
- })
45
- const chess = new Chess()
46
- let count = 0;
47
- for (let i = 0; i < 5000; i++) {
48
- setTimeout(() => {
49
- count++
50
- document.getElementById("counter").innerText = "" + count
51
- const boardDiv = document.createElement("div")
52
- boardDiv.setAttribute("class", "board")
53
- boardsDiv.appendChild(boardDiv)
54
- const board = new Chessboard(boardDiv, {
55
- position: chess.fen(),
56
- assetsUrl: "../assets/",
57
- style: {pieces: {file: "pieces/staunty.svg"}}
58
- })
59
- makeRandomMove()
60
- largeBoard.setPosition(chess.fen(), true)
61
- setTimeout(() => {
62
- board.destroy()
63
- boardsDiv.removeChild(boardDiv)
64
- }, 10000)
65
- }, i * 100)
66
- }
67
-
68
- function makeRandomMove() {
69
- if(chess.game_over()) {
70
- chess.reset()
71
- }
72
- const possibleMoves = chess.moves()
73
- if (possibleMoves.length === 0) return
74
- const randomIndex = Math.floor(Math.random() * possibleMoves.length)
75
- chess.move(possibleMoves[randomIndex])
76
- }
77
-
78
- </script>
79
- </body>
80
- </html>
@@ -1,109 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- </head>
10
- <body>
11
- <h1><a href="../">cm-chessboard</a></h1>
12
- <h2>Example: Different styles and piece sets</h2>
13
- <div class="board" id="board1"></div>
14
- <div class="board" id="board2"></div>
15
- <div class="board" id="board3"></div>
16
- <div class="board" id="board4"></div>
17
- <div class="board" id="board5"></div>
18
- <div class="board" id="board6"></div>
19
- <div class="board" id="board7"></div>
20
- <div class="board" id="board8"></div>
21
- <div class="board" id="board9"></div>
22
- <script type="module">
23
- import {Chessboard, BORDER_TYPE} from "../src/Chessboard.js"
24
- import {FEN} from "../src/model/Position.js"
25
-
26
- new Chessboard(document.getElementById("board1"), {
27
- position: FEN.start,
28
- assetsUrl: "../assets/",
29
- assetsCache: false,
30
- style: {
31
- cssClass: "green",
32
- borderType: BORDER_TYPE.frame,
33
- pieces: {
34
- file: "pieces/staunty.svg"
35
- }
36
- }
37
- })
38
- new Chessboard(document.getElementById("board2"), {
39
- position: FEN.start,
40
- assetsUrl: "../assets/",
41
- assetsCache: false,
42
- style: {
43
- cssClass: "chessboard-js",
44
- borderType: BORDER_TYPE.thin
45
- }
46
- })
47
- new Chessboard(document.getElementById("board3"), {
48
- position: FEN.start,
49
- assetsUrl: "../assets/",
50
- assetsCache: false,
51
- style: {
52
- cssClass: "chess-club",
53
- borderType: BORDER_TYPE.frame,
54
- pieces: {file: "pieces/staunty.svg"}
55
- }
56
- })
57
- new Chessboard(document.getElementById("board4"), {
58
- position: FEN.start,
59
- assetsUrl: "../assets/",
60
- assetsCache: false,
61
- style: {
62
- cssClass: "blue",
63
- borderType: BORDER_TYPE.thin,
64
- showCoordinates: false,
65
- }
66
- })
67
- new Chessboard(document.getElementById("board5"), {
68
- position: FEN.start,
69
- assetsUrl: "../assets/",
70
- assetsCache: false,
71
- style: {borderType: BORDER_TYPE.none, pieces: {file: "pieces/staunty.svg"}},
72
- })
73
- new Chessboard(document.getElementById("board6"), {
74
- position: FEN.start,
75
- assetsUrl: "../assets/",
76
- assetsCache: false,
77
- style: {
78
- pieces: {file: "pieces/staunty.svg"}, cssClass: "blue",
79
- borderType: BORDER_TYPE.frame
80
- },
81
- })
82
- new Chessboard(document.getElementById("board7"), {
83
- position: FEN.start,
84
- assetsUrl: "../assets/",
85
- assetsCache: false,
86
- style: {
87
- cssClass: "green"
88
- }
89
- })
90
- new Chessboard(document.getElementById("board8"), {
91
- position: FEN.start,
92
- assetsUrl: "../assets/",
93
- assetsCache: false,
94
- style: {
95
- cssClass: "black-and-white"
96
- }
97
- })
98
- new Chessboard(document.getElementById("board9"), {
99
- position: FEN.start,
100
- assetsUrl: "../assets/",
101
- assetsCache: false,
102
- style: {
103
- cssClass: "chessboard-js",
104
- borderType: BORDER_TYPE.frame
105
- }
106
- })
107
- </script>
108
- </body>
109
- </html>
@@ -1,97 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- <link rel="stylesheet" href="../assets/extensions/markers/markers.css"/>
10
- </head>
11
- <body>
12
- <h1><a href="../">cm-chessboard</a></h1>
13
- <h2>Example: Input enabled without validation</h2>
14
- <p>Input enabled on both sides, without move validation.
15
- </p>
16
- <p>Additionally, the <b>Markers</b> extension is used with its
17
- autoMarkers ability.</p>
18
- <div class="board" id="board"></div>
19
- <pre>
20
- const board = new Chessboard(document.getElementById("board"), {
21
- position: FEN.start,
22
- assetsUrl: "../assets/",
23
- style: {pieces: {file: "pieces/staunty.svg"}},
24
- extensions: [{class: Markers}]
25
- })
26
-
27
- board.enableMoveInput(inputHandler)
28
- function inputHandler(event) {
29
- console.log(event)
30
- switch (event.type) {
31
- case INPUT_EVENT_TYPE.moveInputStarted:
32
- log(`moveInputStarted: ${event.squareFrom}`)
33
- return true // false cancels move
34
- case INPUT_EVENT_TYPE.validateMoveInput:
35
- log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
36
- return true // false cancels move
37
- case INPUT_EVENT_TYPE.moveInputCanceled:
38
- log(`moveInputCanceled`)
39
- break
40
- case INPUT_EVENT_TYPE.moveInputFinished:
41
- log(`moveInputFinished`)
42
- break
43
- case INPUT_EVENT_TYPE.movingOverSquare:
44
- log(`movingOverSquare: ${event.squareTo}`)
45
- break
46
- }
47
- }
48
- </pre>
49
- <button style="margin-bottom: 10px"
50
- onclick="window.board.setOrientation(window.board.getOrientation() === 'w' ? 'b' : 'w')">Switch Orientation
51
- </button>
52
- <div id="output" style="width: 100%; overflow: hidden"></div>
53
- <script type="module">
54
- import {INPUT_EVENT_TYPE, Chessboard} from "../src/Chessboard.js"
55
- import {FEN} from "../src/model/Position.js"
56
- import {Markers} from "../src/extensions/markers/Markers.js"
57
-
58
- window.board = new Chessboard(document.getElementById("board"), {
59
- position: FEN.start,
60
- assetsUrl: "../assets/",
61
- style: {pieces: {file: "pieces/staunty.svg"}},
62
- extensions: [{class: Markers}]
63
- })
64
-
65
- window.board.enableMoveInput(inputHandler)
66
-
67
- function inputHandler(event) {
68
- console.log(event)
69
- switch (event.type) {
70
- case INPUT_EVENT_TYPE.moveInputStarted:
71
- log(`moveInputStarted: ${event.squareFrom}`)
72
- return true // false cancels move
73
- case INPUT_EVENT_TYPE.validateMoveInput:
74
- log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
75
- return true // false cancels move
76
- case INPUT_EVENT_TYPE.moveInputCanceled:
77
- log(`moveInputCanceled`)
78
- break
79
- case INPUT_EVENT_TYPE.moveInputFinished:
80
- log(`moveInputFinished`)
81
- break
82
- case INPUT_EVENT_TYPE.movingOverSquare:
83
- log(`movingOverSquare: ${event.squareTo}`)
84
- break
85
- }
86
- }
87
-
88
- const output = document.getElementById("output")
89
-
90
- function log(text) {
91
- const log = document.createElement("div")
92
- log.innerText = text
93
- output.appendChild(log)
94
- }
95
- </script>
96
- </body>
97
- </html>
@@ -1,78 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- <link rel="stylesheet" href="../../assets/extensions/markers/markers.css"/>
10
- </head>
11
- <body>
12
- <h1><a href="../..">cm-chessboard</a></h1>
13
- <h2>Example: Accessibility extension</h2>
14
- <p>
15
- This example shows, how the accessibility extension from cm-chessboard works.
16
- It allows a better usage of the board for visually impaired
17
- people.
18
- </p>
19
- <p>
20
- The <a href="../validate-moves.html">validate moves</a> example has also
21
- accessibility features enabled, but visually hidden.
22
- </p>
23
- <h3>Features of the Accessibility extension</h3>
24
- <ul>
25
- <li>Enable Braille notation in the alt text of the chessboard image</li>
26
- <li>Display the chessboard additionally as HTML table</li>
27
- <li>Display a form to move a piece (from, to, move)</li>
28
- <li>Display the pieces additionally as List</li>
29
- <li>Keyboard navigation on the board (arrow keys to navigate, Enter/Space to select, Escape to cancel)</li>
30
- <li>Display these features visually hidden or not</li>
31
- </ul>
32
- <h3>Keyboard Navigation</h3>
33
- <p>Click the board or press Tab to focus it, then use:</p>
34
- <ul>
35
- <li><strong>Arrow keys</strong> - Navigate between squares</li>
36
- <li><strong>Enter / Space</strong> - Select a piece (first press) or target square (second press)</li>
37
- <li><strong>Escape</strong> - Cancel the current move</li>
38
- </ul>
39
- <h3>The chessboard</h3>
40
- <div class="board" id="board"></div>
41
- <button style="margin-bottom: 10px"
42
- onclick="window.switchOrientation()">Switch Orientation
43
- </button>
44
- <script type="module">
45
- import {Chessboard} from "../../src/Chessboard.js"
46
- import {Accessibility} from "../../src/extensions/accessibility/Accessibility.js"
47
- import {Markers} from "../../src/extensions/markers/Markers.js"
48
-
49
- const chessboard = new Chessboard(document.getElementById("board"), {
50
- position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
51
- assetsUrl: "../../assets/",
52
- // animationDuration: 0, // optional, set to 0 to disable animations
53
- style: {
54
- cssClass: "default-contrast" // make the coordinates better visible with the "default-contrast" theme
55
- },
56
- extensions:
57
- [{
58
- class: Accessibility,
59
- props: {
60
- brailleNotationInAlt: true, // show the braille notation of the game in the alt attribute of the SVG
61
- boardAsTable: true, // display the board additionally as HTML table
62
- movePieceForm: true, // display a form to move a piece (from, to, move)
63
- piecesAsList: true, // display the pieces additionally as List
64
- keyboardMoveInput: true, // enable keyboard navigation on the board with arrow keys
65
- visuallyHidden: false // hide all those extra outputs visually but keep them accessible for screen readers and braille displays
66
- }
67
-
68
- }, {class: Markers}]
69
- })
70
- window.switchOrientation = function () {
71
- chessboard.setOrientation(chessboard.getOrientation() === 'w' ? 'b' : 'w')
72
- }
73
-
74
- chessboard.enableMoveInput(() => true)
75
-
76
- </script>
77
- </body>
78
- </html>
@@ -1,63 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- <link rel="stylesheet" href="../../assets/extensions/arrows/arrows.css"/>
10
- </head>
11
- <body>
12
- <h1><a href="../..">cm-chessboard</a></h1>
13
- <h2>Example: Arrows extension</h2>
14
- <div class="board" id="board"></div>
15
- <br style="clear: both"/>
16
- <h2>Example code</h2>
17
- <pre>
18
- const chessboard = new Chessboard(document.getElementById("board"), {
19
- position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
20
- assetsUrl: "../../assets/",
21
- extensions: [{class: Arrows}]
22
- })
23
- chessboard.addArrow(ARROW_TYPE.default, "f3", "d5")
24
- chessboard.addArrow(ARROW_TYPE.default, "b8", "c6")
25
- chessboard.addArrow(ARROW_TYPE.pointy, "d2", "d3")
26
- chessboard.addArrow(ARROW_TYPE.danger, "g5", "e6")
27
- console.log(chessboard.getArrows())
28
- </pre>
29
- <h2>Methods</h2>
30
- <h3><code>addArrow(type, from, to)</code></h3>
31
- <h3><code>removeArrows(type, from, to)</code></h3>
32
- <p>
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"
37
- you can call <code>chessboard.removeArrows(undefined, "e2")</code> and so on...
38
- </p>
39
- <h3><code>getArrows(type, from, to)</code></h3>
40
- <p>
41
- To get all arrows, call <code>chessboard.getArrows()</code> without parameters, as with <code>removeArrows(type,
42
- from, to)</code>.
43
- </p>
44
-
45
- <script type="module">
46
- import {ARROW_TYPE, Arrows} from "../../src/extensions/arrows/Arrows.js"
47
- import {Chessboard} from "../../src/Chessboard.js"
48
-
49
- const chessboard = new Chessboard(document.getElementById("board"), {
50
- position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
51
- assetsUrl: "../../assets/",
52
- extensions: [{class: Arrows}]
53
- })
54
- chessboard.addArrow(ARROW_TYPE.danger, "f3", "d5")
55
- chessboard.addArrow(ARROW_TYPE.info, "b8", "c6")
56
- chessboard.addArrow(ARROW_TYPE.success, "d2", "d3")
57
- chessboard.addArrow(ARROW_TYPE.warning, "g5", "e6")
58
- chessboard.addArrow(ARROW_TYPE.secondary, "a1", "c3")
59
- console.log(chessboard.getArrows())
60
-
61
- </script>
62
- </body>
63
- </html>
@@ -1,66 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>cm-chessboard</title>
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/chessboard.css"/>
9
- <link rel="stylesheet" href="../../assets/extensions/markers/markers.css"/>
10
- <style>
11
- /*noinspection CssUnusedSymbol*/
12
- .board .html-layer {
13
- background-color: rgba(0, 0, 0, 0.4);
14
- cursor: pointer;
15
- }
16
- .board .html-layer div {
17
- position: absolute;
18
- top: 30%;
19
- left: 1rem;
20
- right: 1rem;
21
- background-color: rgba(0, 0, 0, 0.5);
22
- padding: 1rem;
23
- font-size: 30px;
24
- border-radius: 0.5rem;
25
- text-align: center;
26
- }
27
- </style>
28
- </head>
29
- <body>
30
- <h1><a href="../../">cm-chessboard</a></h1>
31
- <h2>Example: HtmlLayer Extension</h2>
32
- <p>Use this extension to add a layer over the board which contains HTML.</p>
33
- <div class="board" id="board"></div>
34
- <div>
35
- <button onclick="window.addLayer()">Add HTML Layer</button>
36
- <button onclick="removeLayer()">Remove HTML Layer</button>
37
- </div>
38
- <script type="module">
39
- import {Chessboard, FEN} from "../../src/Chessboard.js"
40
- import {HtmlLayer} from "../../src/extensions/html-layer/HtmlLayer.js"
41
- import {Markers} from "../../src/extensions/markers/Markers.js"
42
-
43
- const board = new Chessboard(document.getElementById("board"), {
44
- position: FEN.start,
45
- assetsUrl: "../../assets/",
46
- extensions: [{class: HtmlLayer}, {class: Markers}]
47
- })
48
- board.enableMoveInput(() => true)
49
- let layer = null
50
- window.addLayer = () => {
51
- if(!layer) {
52
- layer = board.addHtmlLayer("<div>Welcome to cm-chessboard!</div>")
53
- layer.addEventListener("click", () => {
54
- window.removeLayer()
55
- })
56
- }
57
- }
58
- window.removeLayer = () => {
59
- if(layer) {
60
- board.removeHtmlLayer(layer)
61
- layer = null
62
- }
63
- }
64
- </script>
65
- </body>
66
- </html>