A chess board web component
Usage
npm init
if needednpm i @loloof64/chessboard-component
node_modules/@loloof64/chessboard-component/dist
(just load it, as it will define the web component loloof64-chessboard
).<loloof64-chessboard
size="300"
background="crimson"
coordinates_color="yellow"
white_cell_color="navajowhite"
black_cell_color="peru"
reversed="true"
origin_cell_color="red"
target_cell_color="green"
dnd_cross_color="purple"
white_player_human="true"
black_player_human="false"
move_highlight_color="red"
last_move_visible="false"
coordinates_visible="false"
></loloof64-chessboard>
Name | Purpose | Type | Default |
---|---|---|---|
size | Common size (width/height) of the board in pixels | number | 100.0 |
background | Background color of the board outside zone | string | #124589 |
coordinatesColor | Color of the coordinates around the board | string | yellow |
whiteCellColor | Background color of the white cells of the board | string | navajowhite |
blackCellColor | Background color of the black cells of the board | string | peru |
reversed | Whether black side is on top or not | boolean | false |
origin_cell_color | Color of the origin cell of the Drag and Drop | string | crimson |
target_cell_color | Color of the current target cell of the Drag and Drop | string | ForestGreen |
dnd_cross_color | Color of the Drag and Drop cross indicator | string | DimGrey |
promotion_dialog_title | Title of the promotion selection dialog | string | Select the promotion piece |
white_player_human | True if the white player is human, false for external (1) | boolean | true |
black_player_human | True if the black player is human, false for external (1) | boolean | true |
move_highlight_color | Color of the last move highlight arrow | string | CadetBlue |
coordinates_visible | True if the coordinates should be visible, false otherwise | boolean | true |
last_move_visible | True if the last move arrow should be visible, false otherwise | boolean | true |
(1) External player means that, instead of playing its move with interaction on the board, call the method playMove
in order to commit its move. A simple use case would be to let an engine play.
When chaining methods/events, you may experience some update issues. Indeed, often the cpu needs some time in order to update the component state. If you run into such issues, don't hesitate to use setTimeout with some milliseconds or hundreds of milliseconds
detail.whiteTurnBeforeMove
of the event tells if the side that checkmated were White or Black.detail.moveObject
is an object with all the details : moveNumber, whiteTurn, moveFan, moveSan, fromFileIndex, fromRankIndex, toFileIndex, toRankIndex.You can build with the command (in the terminal) $ yarn build
from the root of the project. Result will be in the dist
folder.
But don't forget first to install all dependencies, with NodeJS : yarn
.
Pieces vectors definitions from CBurnett and found on Wikimedia commons.
Using ChessJS library, which is bundled in the produced script.