cm-chessboard 7.3.4 → 7.3.6

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.
@@ -16,6 +16,10 @@
16
16
  It allows a better usage of the board for visually impaired
17
17
  people.
18
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>
19
23
  <h3>Features of the Accessibility extension</h3>
20
24
  <ul>
21
25
  <li>Enable Braille notation in the alt text of the chessboard image</li>
@@ -19,13 +19,12 @@ 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
+ style: {pieces: {file: "staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
24
23
  orientation: COLOR.black
25
24
  })
26
25
  </pre>
27
26
  <script type="module">
28
- import {COLOR, Chessboard} from "../src/cm-chessboard/Chessboard.js"
27
+ import {COLOR, Chessboard, BORDER_TYPE} from "../src/cm-chessboard/Chessboard.js"
29
28
  import {FEN} from "../src/cm-chessboard/model/Position.js"
30
29
 
31
30
  new Chessboard(document.getElementById("board1"), {
@@ -36,7 +35,7 @@ new Chessboard(document.getElementById("board2"), {
36
35
  position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
37
36
  assetsUrl: "../assets/",
38
37
  assetsCache: false,
39
- style: {pieces: {file: "staunty.svg"}},
38
+ style: {pieces: {file: "staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
40
39
  orientation: COLOR.black
41
40
  })
42
41
  </script>
@@ -14,7 +14,7 @@
14
14
  <h2>Example: Input enabled, move validation with chess.js</h2>
15
15
  <p>Input enabled for white. <a href="https://github.com/jhlywa/chess.js">chess.js</a> does the validation and answers
16
16
  with random moves.</p>
17
- <h2 class="cm-visually-hidden">The Board</h2>
17
+ <h2 class="cm-visually-hidden">The chessboard widget</h2>
18
18
  <div class="board board-large" id="board"></div>
19
19
  <h2 class="cm-visually-hidden">The Sourcecode of the example</h2>
20
20
  <div id="output"></div>
@@ -23,6 +23,7 @@
23
23
  import {INPUT_EVENT_TYPE, COLOR, Chessboard, BORDER_TYPE} from "../src/cm-chessboard/Chessboard.js"
24
24
  import {MARKER_TYPE, Markers} from "../src/cm-chessboard/extensions/markers/Markers.js"
25
25
  import {PromotionDialog} from "../src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js"
26
+ import {Accessibility} from "../src/cm-chessboard/extensions/accessibility/Accessibility.js"
26
27
 
27
28
  const chess = new Chess()
28
29
 
@@ -77,7 +78,8 @@
77
78
  orientation: COLOR.white,
78
79
  extensions: [
79
80
  {class: Markers, props: {autoMarkers: MARKER_TYPE.square}},
80
- {class: PromotionDialog}
81
+ {class: PromotionDialog},
82
+ {class: Accessibility, props: {visuallyHidden: true}}
81
83
  ]
82
84
  })
83
85
  board.enableMoveInput(inputHandler, COLOR.white)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "7.3.4",
3
+ "version": "7.3.6",
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,26 +9,30 @@ import {piecesTranslations, renderPieceTitle} from "../../lib/I18n.js"
9
9
 
10
10
  const hlTranslations = {
11
11
  de: {
12
+ chessboard: "Schachbrett",
12
13
  pieces_lists: "Figurenlisten",
13
14
  board_as_table: "Schachbrett als Tabelle",
14
15
  move_piece: "Figur bewegen",
15
- from: "von",
16
- to: "nach",
17
- move: "bewegen",
16
+ from: "Zug von",
17
+ to: "Zug nach",
18
+ move: "Zug ausführen",
18
19
  input_white_enabled: "Eingabe Weiß aktiviert",
19
20
  input_black_enabled: "Eingabe Schwarz aktiviert",
20
- input_disabled: "Eingabe deaktiviert"
21
+ input_disabled: "Eingabe deaktiviert",
22
+ pieces: "Figuren",
21
23
  },
22
24
  en: {
25
+ chessboard: "Chessboard",
23
26
  pieces_lists: "Pieces lists",
24
27
  board_as_table: "Chessboard as table",
25
28
  move_piece: "Move piece",
26
- from: "from",
27
- to: "to",
28
- move: "move",
29
+ from: "Move from",
30
+ to: "Move to",
31
+ move: "Make move",
29
32
  input_white_enabled: "Input white enabled",
30
33
  input_black_enabled: "Input black enabled",
31
- input_disabled: "Input disabled"
34
+ input_disabled: "Input disabled",
35
+ pieces: "Pieces"
32
36
  }
33
37
  }
34
38
 
@@ -38,9 +42,9 @@ export class Accessibility extends Extension {
38
42
  super(chessboard, props)
39
43
  this.props = {
40
44
  brailleNotationInAlt: true, // show the braille notation of the position in the alt attribute of the SVG image
41
- boardAsTable: false, // display the board additionally as HTML table
42
- movePieceForm: false, // display a form to move a piece (from, to, move)
43
- piecesAsList: false, // display the pieces additionally as List
45
+ boardAsTable: true, // display the board additionally as HTML table
46
+ movePieceForm: true, // display a form to move a piece (from, to, move)
47
+ piecesAsList: true, // display the pieces additionally as List
44
48
  visuallyHidden: true // hide all those extra outputs visually but keep them accessible for screen readers and braille displays
45
49
  }
46
50
  Object.assign(this.props, props)
@@ -49,7 +53,7 @@ export class Accessibility extends Extension {
49
53
  this.t = this.translations[this.lang]
50
54
  this.th = hlTranslations[this.lang]
51
55
  if (this.props.movePieceForm) {
52
- this.movePieceFormContainer = this.createElement(`<div><h3>${this.th.move_piece}</h3><form>
56
+ this.movePieceFormContainer = this.createElement(`<div><h3 id="hl_form_${this.chessboard.id}">${this.th.move_piece}</h3><form aria-labelledby="hl_form_${this.chessboard.id}">
53
57
  <label for="move_piece_input_from_${chessboard.id}">${this.th.from}</label><input class="input-from" type="text" size="2" id="move_piece_input_from_${chessboard.id}"/>
54
58
  <label for="move_piece_input_to_${chessboard.id}">${this.th.to}</label><input class="input-to" type="text" size="2" id="move_piece_input_to_${chessboard.id}"/>
55
59
  <button type="submit" class="button-move">${this.th.move}</button>
@@ -79,7 +83,7 @@ export class Accessibility extends Extension {
79
83
  this.chessboard.context.appendChild(this.movePieceFormContainer)
80
84
  }
81
85
  if (this.props.boardAsTable) {
82
- this.boardAsTableContainer = this.createElement(`<div><h3>${this.th.board_as_table}</h3><div class="table"></div></div>`)
86
+ this.boardAsTableContainer = this.createElement(`<div><h3 id="hl_table_${this.chessboard.id}">${this.th.board_as_table}</h3><div class="table"></div></div>`)
83
87
  this.boardAsTable = this.boardAsTableContainer.querySelector(".table")
84
88
  this.chessboard.context.appendChild(this.boardAsTableContainer)
85
89
  if (this.props.visuallyHidden) {
@@ -87,7 +91,7 @@ export class Accessibility extends Extension {
87
91
  }
88
92
  }
89
93
  if (this.props.piecesAsList) {
90
- this.piecesListContainer = this.createElement(`<div><h3>${this.th.pieces_lists}</h3><div class="list"></div></div>`)
94
+ this.piecesListContainer = this.createElement(`<div><h3 id="hl_lists_${this.chessboard.id}">${this.th.pieces_lists}</h3><div class="list"></div></div>`)
91
95
  this.piecesList = this.piecesListContainer.querySelector(".list")
92
96
  this.chessboard.context.appendChild(this.piecesListContainer)
93
97
  if (this.props.visuallyHidden) {
@@ -169,9 +173,9 @@ ${listB}`
169
173
  }
170
174
  }
171
175
  this.piecesList.innerHTML = `
172
- <h4 id="white_${this.chessboard.id}">${this.t.colors_long.w}</h4>
176
+ <h4 id="white_${this.chessboard.id}">${this.th.pieces} ${this.t.colors_long.w}</h4>
173
177
  <ul aria-labelledby="white_${this.chessboard.id}" class="list-inline">${listW}</ul>
174
- <h4 id="black_${this.chessboard.id}">${this.t.colors_long.b}</h4>
178
+ <h4 id="black_${this.chessboard.id}">${this.th.pieces} ${this.t.colors_long.b}</h4>
175
179
  <ul aria-labelledby="black_${this.chessboard.id}" class="list-inline">${listB}</ul>`
176
180
  }
177
181
 
@@ -184,7 +188,7 @@ ${listB}`
184
188
  files.reverse()
185
189
  squares.reverse()
186
190
  }
187
- let html = `<table><!--<caption>${this.th.board_as_table}</caption>--><tr><th></th>`
191
+ let html = `<table aria-labelledby="hl_table_${this.chessboard.id}"><tr><th></th>`
188
192
  for (const rank of ranks) {
189
193
  html += `<th scope='col'>${rank}</th>`
190
194
  }
@@ -38,4 +38,15 @@ export class Utils {
38
38
  return target
39
39
  }
40
40
 
41
+ static createTask() {
42
+ let resolve, reject
43
+ const promise = new Promise(function (_resolve, _reject) {
44
+ resolve = _resolve
45
+ reject = _reject
46
+ })
47
+ promise.resolve = resolve
48
+ promise.reject = reject
49
+ return promise
50
+ }
51
+
41
52
  }
@@ -5,17 +5,6 @@
5
5
  */
6
6
  import {Position} from "./Position.js"
7
7
 
8
- export function createTask() {
9
- let resolve, reject
10
- const promise = new Promise(function (_resolve, _reject) {
11
- resolve = _resolve
12
- reject = _reject
13
- })
14
- promise.resolve = resolve
15
- promise.reject = reject
16
- return promise
17
- }
18
-
19
8
  export class ChessboardState {
20
9
 
21
10
  constructor() {
@@ -27,30 +16,7 @@ export class ChessboardState {
27
16
  this.inputEnabled = false
28
17
  this.squareSelectEnabled = false
29
18
  this.extensionPoints = {}
30
- this.moveInputProcess = createTask().resolve()
31
- }
32
-
33
- setPosition(fen, animated = false) {
34
- this.position = new Position(fen, animated)
35
- }
36
-
37
- movePiece(fromSquare, toSquare, animated = false) {
38
- const position = this._position.clone()
39
- position.animated = animated
40
- const piece = position.getPiece(fromSquare)
41
- if (!piece) {
42
- console.error("no piece on", fromSquare)
43
- }
44
- position.setPiece(fromSquare, undefined)
45
- position.setPiece(toSquare, piece)
46
- this._position = position
47
- }
48
-
49
- setPiece(square, piece, animated = false) {
50
- const position = this._position.clone()
51
- position.animated = animated
52
- position.setPiece(square, piece)
53
- this._position = position
19
+ this.moveInputProcess = Promise.resolve()
54
20
  }
55
21
 
56
22
  invokeExtensionPoints(name, data = {}) {
@@ -96,7 +96,7 @@ export class ChessboardView {
96
96
  this.svg.setAttribute("role", "img")
97
97
  this.updateMetrics()
98
98
  this.boardGroup = Svg.addElement(this.svg, "g", {class: "board"})
99
- this.coordinatesGroup = Svg.addElement(this.svg, "g", {class: "coordinates"})
99
+ this.coordinatesGroup = Svg.addElement(this.svg, "g", {class: "coordinates", "aria-hidden": "true"})
100
100
  this.markersLayer = Svg.addElement(this.svg, "g", {class: "markers-layer"})
101
101
  this.piecesLayer = Svg.addElement(this.svg, "g", {class: "pieces-layer"})
102
102
  this.piecesGroup = Svg.addElement(this.piecesLayer, "g", {class: "pieces"})
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {Svg} from "../lib/Svg.js"
8
- import {createTask} from "../model/ChessboardState.js"
8
+ import {Utils} from "../lib/Utils.js"
9
9
 
10
10
  const STATE = {
11
11
  waitForInputStart: 0,
@@ -36,7 +36,7 @@ export class VisualMoveInput {
36
36
  this.moveInputStartedCallback = (square) => {
37
37
  const result = moveInputStartedCallback(square)
38
38
  if (result) {
39
- this.chessboard.state.moveInputProcess = createTask()
39
+ this.chessboard.state.moveInputProcess = Utils.createTask()
40
40
  }
41
41
  return result
42
42
  }
@@ -7,6 +7,7 @@
7
7
  import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
8
8
  import {ChessboardState} from "../src/cm-chessboard/model/ChessboardState.js"
9
9
  import {PositionsAnimation} from "../src/cm-chessboard/view/PositionAnimationsQueue.js"
10
+ import {Position} from "../src/cm-chessboard/model/Position.js"
10
11
 
11
12
  describe("TestPiecesAnimation", () => {
12
13
  it("should calculate square distances", () => {
@@ -22,9 +23,9 @@ describe("TestPiecesAnimation", () => {
22
23
 
23
24
  it("should seek changes", () => {
24
25
  const state1 = new ChessboardState()
25
- state1.setPosition("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
26
+ state1.position = new Position("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
26
27
  const state2 = new ChessboardState()
27
- state2.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
28
+ state2.position = new Position("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
28
29
  const previousBoard1 = state1.position.squares
29
30
  const newBoard1 = state2.position.squares
30
31
  const changes = PositionsAnimation.seekChanges(previousBoard1, newBoard1)