@pech/chess-board 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # chess-board
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. Built to work with [@pech/chess-core](https://github.com/EduardoPech/chess-core) for rules and move validation.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @pech/chess-board
9
+ # or
10
+ bun add @pech/chess-board
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { ChessBoard, STARTING_FEN } from '@pech/chess-board';
17
+
18
+ const container = document.getElementById('board')!;
19
+ const board = new ChessBoard(container, {
20
+ position: STARTING_FEN,
21
+ orientation: 'white',
22
+ draggable: true,
23
+ onMove(from, to) {
24
+ // Validate with @pech/chess-core and return false to cancel
25
+ return true;
26
+ },
27
+ });
28
+
29
+ // Update position from FEN
30
+ board.setPosition('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1');
31
+ board.setLastMove('e2', 'e4');
32
+ board.setLegalMoves(['e5', 'e6']);
33
+ board.setArrows([{ from: 'e2', to: 'e4', color: '#888' }]);
34
+ board.destroy();
35
+ ```
36
+
37
+ ## Options
38
+
39
+ | Option | Type | Description |
40
+ |--------|------|-------------|
41
+ | `position` | `string` | Initial FEN (default: starting position). |
42
+ | `orientation` | `'white' \| 'black'` | Board orientation. |
43
+ | `draggable` | `boolean` | Allow dragging pieces. |
44
+ | `clickable` | `boolean` | Allow square selection/clicks. |
45
+ | `viewOnly` | `boolean` | No drag or selection. |
46
+ | `coordinates` | `boolean` | Show file/rank labels. |
47
+ | `animationDuration` | `number` | Move animation ms. |
48
+ | `pieceTheme` | `PieceTheme` | Function (piece) => SVG string. |
49
+ | `boardTheme` | `BoardTheme` | `{ lightSquare, darkSquare }` colors. |
50
+ | `onMove` | `(from, to) => boolean \| void` | Called on drop; return `false` to cancel. |
51
+ | `onSelect` | `(square \| null) => void` | Called when selection changes. |
52
+ | `onArrowDrawn` | `(from, to) => void` | Called when user draws arrow (right-drag). |
53
+
54
+ ## API
55
+
56
+ ### Class
57
+
58
+ - **`ChessBoard`** — Main class. `new ChessBoard(container: HTMLElement, options?: ChessBoardOptions)`.
59
+
60
+ ### FEN
61
+
62
+ - **`STARTING_FEN`** — Standard starting position FEN string.
63
+ - **`parseFen(fen: string)`** — Parse FEN into `Map<SquareKey, Piece>`.
64
+ - **`positionToFen(pieces: Map<SquareKey, Piece>)`** — Build FEN from piece map.
65
+
66
+ ### Themes
67
+
68
+ - **`defaultPieceTheme`** — `PieceTheme` using bundled piece SVGs.
69
+ - **`defaultBoardTheme`** — `BoardTheme` (green/brown squares).
70
+
71
+ ### Types
72
+
73
+ - `SquareKey`, `FileChar`, `RankChar`, `Color`, `PieceType`, `Piece`, `Arrow`, `BoardTheme`, `PieceTheme`, `ChessBoardOptions`.
74
+
75
+ ### Board methods
76
+
77
+ - **Position:** `setPosition(fen)`, `getPosition()`.
78
+ - **Orientation:** `setOrientation(color)`, `getOrientation()`, `flip()`.
79
+ - **Selection:** `select(square | null)`.
80
+ - **Highlights:** `setLastMove(from, to)`, `clearLastMove()`, `setCheck(square | null)`, `setLegalMoves(squares)`, `clearLegalMoves()`.
81
+ - **Arrows:** `setArrows(arrows)`, `addArrow(from, to, color?)`, `removeArrow(from, to)`, `clearArrows()`.
82
+ - **Lifecycle:** `destroy()`.
83
+
84
+ ## Integration with @pech/chess-core
85
+
86
+ Use [@pech/chess-core](https://github.com/EduardoPech/chess-core) for legal move generation and game state. In `onMove`, validate the move with the core and call `board.setPosition(game.fen())` (or similar) after applying it; return `false` to reject the move.
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ bun install # install dependencies
92
+ bun run test # run tests
93
+ bun run test:watch # run tests in watch mode
94
+ bun run build # build with tsup
95
+ bun run typecheck # type-check without emitting
96
+ ```
97
+
98
+ ## License
99
+
100
+ MIT