cm-chessboard 8.6.1 → 8.7.1
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/package.json
CHANGED
package/src/Chessboard.js
CHANGED
|
@@ -15,6 +15,9 @@ export const PIECE = {
|
|
|
15
15
|
wp: "wp", wb: "wb", wn: "wn", wr: "wr", wq: "wq", wk: "wk",
|
|
16
16
|
bp: "bp", bb: "bb", bn: "bn", br: "br", bq: "bq", bk: "bk"
|
|
17
17
|
}
|
|
18
|
+
export const PIECE_TYPE = {
|
|
19
|
+
pawn: "p", knight: "n", bishop: "b", rook: "r", queen: "q", king: "k"
|
|
20
|
+
}
|
|
18
21
|
export const PIECES_FILE_TYPE = {
|
|
19
22
|
svgSprite: "svgSprite"
|
|
20
23
|
}
|
|
@@ -112,8 +115,9 @@ export class Chessboard {
|
|
|
112
115
|
return this.state.position.getPiece(square)
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
/** return the position object since 2024-04-20 (8.7.0) */
|
|
115
119
|
getPosition() {
|
|
116
|
-
return this.state.position
|
|
120
|
+
return this.state.position
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
getOrientation() {
|
|
@@ -92,7 +92,7 @@ class BrailleNotationInAlt {
|
|
|
92
92
|
let listW = piecesTranslations[this.extension.lang].colors.w.toUpperCase() + ":"
|
|
93
93
|
let listB = piecesTranslations[this.extension.lang].colors.b.toUpperCase() + ":"
|
|
94
94
|
for (const piece of pieces) {
|
|
95
|
-
const pieceName = piece.
|
|
95
|
+
const pieceName = piece.type === "p" ? "" : piecesTranslations[this.extension.lang].pieces[piece.type].toUpperCase()
|
|
96
96
|
if (piece.color === "w") {
|
|
97
97
|
listW += " " + pieceName + piece.position
|
|
98
98
|
} else {
|
|
@@ -226,9 +226,9 @@ class PiecesAsList {
|
|
|
226
226
|
let listB = ""
|
|
227
227
|
for (const piece of pieces) {
|
|
228
228
|
if (piece.color === "w") {
|
|
229
|
-
listW += `<li class="list-inline-item">${renderPieceTitle(this.extension.lang, piece.
|
|
229
|
+
listW += `<li class="list-inline-item">${renderPieceTitle(this.extension.lang, piece.type)} ${piece.position}</li>`
|
|
230
230
|
} else {
|
|
231
|
-
listB += `<li class="list-inline-item">${renderPieceTitle(this.extension.lang, piece.
|
|
231
|
+
listB += `<li class="list-inline-item">${renderPieceTitle(this.extension.lang, piece.type)} ${piece.position}</li>`
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
this.piecesList.innerHTML = `
|
package/src/model/Position.js
CHANGED
|
@@ -71,7 +71,7 @@ export class Position {
|
|
|
71
71
|
return parts.join("/")
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
getPieces(sortBy = ['k', 'q', 'r', 'b', 'n', 'p']) {
|
|
74
|
+
getPieces(pieceType = undefined, pieceColor = undefined, sortBy = ['k', 'q', 'r', 'b', 'n', 'p']) {
|
|
75
75
|
const pieces = []
|
|
76
76
|
const sort = (a, b) => {
|
|
77
77
|
return sortBy.indexOf(a.name) - sortBy.indexOf(b.name)
|
|
@@ -79,10 +79,18 @@ export class Position {
|
|
|
79
79
|
for (let i = 0; i < 64; i++) {
|
|
80
80
|
const piece = this.squares[i]
|
|
81
81
|
if (piece) {
|
|
82
|
+
const type = piece.charAt(1)
|
|
83
|
+
const color = piece.charAt(0)
|
|
84
|
+
const square = Position.indexToSquare(i)
|
|
85
|
+
if(pieceType && pieceType !== type || pieceColor && pieceColor !== color) {
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
82
88
|
pieces.push({
|
|
83
|
-
name:
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
name: type, // deprecated, use type
|
|
90
|
+
type: type,
|
|
91
|
+
color: color,
|
|
92
|
+
position: square, // deprecated, use square
|
|
93
|
+
square: square
|
|
86
94
|
})
|
|
87
95
|
}
|
|
88
96
|
}
|
|
@@ -130,6 +138,10 @@ export class Position {
|
|
|
130
138
|
return file + rank
|
|
131
139
|
}
|
|
132
140
|
|
|
141
|
+
toString() {
|
|
142
|
+
return this.getFen()
|
|
143
|
+
}
|
|
144
|
+
|
|
133
145
|
clone() {
|
|
134
146
|
const cloned = new Position()
|
|
135
147
|
cloned.squares = this.squares.slice(0)
|
|
@@ -61,7 +61,6 @@ export class ChessboardView {
|
|
|
61
61
|
}
|
|
62
62
|
this.positionsAnimationTask = Promise.resolve()
|
|
63
63
|
this.pointerDownListener = this.pointerDownHandler.bind(this)
|
|
64
|
-
this.pointerDownListener = this.pointerDownHandler.bind(this)
|
|
65
64
|
this.container.addEventListener("mousedown", this.pointerDownListener)
|
|
66
65
|
this.container.addEventListener("touchstart", this.pointerDownListener, {passive: false})
|
|
67
66
|
this.createSvgAndGroups()
|