@pech/chess-board 1.0.0 → 1.0.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/README.md +39 -3
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# chess-board
|
|
2
2
|
|
|
3
|
-
Chess board UI library — render and interact with chess positions. Supports FEN, drag-and-drop, custom piece/board themes, arrows, last-move and legal-move highlights.
|
|
3
|
+
Chess board UI library — render and interact with chess positions. Supports FEN, drag-and-drop, custom piece/board themes, arrows, last-move and legal-move highlights. **Use [@pech/chess-core](https://eduardopech.github.io/chess-core/) to implement game logic** (rules, legal moves, validation).
|
|
4
|
+
|
|
5
|
+
**See:** [Documentation and examples](https://eduardopech.github.io/chess-board)
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -81,9 +83,43 @@ board.destroy();
|
|
|
81
83
|
- **Arrows:** `setArrows(arrows)`, `addArrow(from, to, color?)`, `removeArrow(from, to)`, `clearArrows()`.
|
|
82
84
|
- **Lifecycle:** `destroy()`.
|
|
83
85
|
|
|
84
|
-
##
|
|
86
|
+
## Implementing the logic with chess-core
|
|
87
|
+
|
|
88
|
+
We recommend using **[@pech/chess-core](https://eduardopech.github.io/chess-core/)** for all game logic: legal moves, move validation, FEN handling, and check/checkmate. Install it and wire it to the board:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install @pech/chess-core
|
|
92
|
+
# or
|
|
93
|
+
bun add @pech/chess-core
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { ChessBoard, STARTING_FEN } from '@pech/chess-board';
|
|
98
|
+
import { fromFen, toFen, getLegalMoves, makeMove, fromUci, toUci } from '@pech/chess-core';
|
|
99
|
+
|
|
100
|
+
const container = document.getElementById('board')!;
|
|
101
|
+
let position = fromFen(STARTING_FEN);
|
|
102
|
+
|
|
103
|
+
const board = new ChessBoard(container, {
|
|
104
|
+
position: STARTING_FEN,
|
|
105
|
+
orientation: 'white',
|
|
106
|
+
draggable: true,
|
|
107
|
+
onMove(from, to) {
|
|
108
|
+
const move = fromUci(position, from + to);
|
|
109
|
+
if (!move) return false;
|
|
110
|
+
|
|
111
|
+
const newPos = makeMove(position, move);
|
|
112
|
+
board.setPosition(toFen(newPos));
|
|
113
|
+
board.setLastMove(from, to);
|
|
114
|
+
board.setLegalMoves(getLegalMoves(newPos).map((m) => toUci(m).slice(2, 4)));
|
|
115
|
+
position = newPos;
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
board.setLegalMoves(getLegalMoves(position).map((m) => toUci(m).slice(2, 4)));
|
|
120
|
+
```
|
|
85
121
|
|
|
86
|
-
|
|
122
|
+
**Docs:** [chess-core — Getting started & API](https://eduardopech.github.io/chess-core/)
|
|
87
123
|
|
|
88
124
|
## Development
|
|
89
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pech/chess-board",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Chess board UI library — render and interact with chess positions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsup",
|
|
22
22
|
"dev": "tsup --watch",
|
|
23
|
+
"docs:dev": "cd docs && bun run dev",
|
|
24
|
+
"docs:build": "cd docs && bun run build",
|
|
23
25
|
"test": "vitest run",
|
|
24
26
|
"test:watch": "vitest",
|
|
25
27
|
"typecheck": "tsc --noEmit",
|