react-native-chess-kit 0.1.0 → 0.2.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/lib/commonjs/board-annotations.js +131 -0
- package/lib/commonjs/board-annotations.js.map +1 -0
- package/lib/commonjs/board-arrows.js +164 -0
- package/lib/commonjs/board-arrows.js.map +1 -0
- package/lib/commonjs/board-highlights.js +212 -0
- package/lib/commonjs/board-highlights.js.map +1 -0
- package/lib/commonjs/board-piece.js +41 -12
- package/lib/commonjs/board-piece.js.map +1 -1
- package/lib/commonjs/board-pieces.js +2 -0
- package/lib/commonjs/board-pieces.js.map +1 -1
- package/lib/commonjs/board.js +392 -42
- package/lib/commonjs/board.js.map +1 -1
- package/lib/commonjs/constants.js +104 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.js +128 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pieces/default-pieces.js +536 -0
- package/lib/commonjs/pieces/default-pieces.js.map +1 -0
- package/lib/commonjs/pieces/index.js +13 -0
- package/lib/commonjs/pieces/index.js.map +1 -0
- package/lib/commonjs/promotion-picker.js +129 -0
- package/lib/commonjs/promotion-picker.js.map +1 -0
- package/lib/commonjs/static-board.js +150 -0
- package/lib/commonjs/static-board.js.map +1 -0
- package/lib/commonjs/themes.js +175 -0
- package/lib/commonjs/themes.js.map +1 -0
- package/lib/commonjs/use-board-gesture.js +184 -11
- package/lib/commonjs/use-board-gesture.js.map +1 -1
- package/lib/commonjs/use-premove.js +44 -0
- package/lib/commonjs/use-premove.js.map +1 -0
- package/lib/module/board-annotations.js +126 -0
- package/lib/module/board-annotations.js.map +1 -0
- package/lib/module/board-arrows.js +161 -0
- package/lib/module/board-arrows.js.map +1 -0
- package/lib/module/board-highlights.js +206 -0
- package/lib/module/board-highlights.js.map +1 -0
- package/lib/module/board-piece.js +42 -13
- package/lib/module/board-piece.js.map +1 -1
- package/lib/module/board-pieces.js +2 -0
- package/lib/module/board-pieces.js.map +1 -1
- package/lib/module/board.js +395 -44
- package/lib/module/board.js.map +1 -1
- package/lib/module/constants.js +100 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +29 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/pieces/default-pieces.js +530 -0
- package/lib/module/pieces/default-pieces.js.map +1 -0
- package/lib/module/pieces/index.js +4 -0
- package/lib/module/pieces/index.js.map +1 -0
- package/lib/module/promotion-picker.js +124 -0
- package/lib/module/promotion-picker.js.map +1 -0
- package/lib/module/static-board.js +146 -0
- package/lib/module/static-board.js.map +1 -0
- package/lib/module/themes.js +171 -0
- package/lib/module/themes.js.map +1 -0
- package/lib/module/use-board-gesture.js +185 -11
- package/lib/module/use-board-gesture.js.map +1 -1
- package/lib/module/use-premove.js +40 -0
- package/lib/module/use-premove.js.map +1 -0
- package/lib/typescript/board-annotations.d.ts +30 -0
- package/lib/typescript/board-annotations.d.ts.map +1 -0
- package/lib/typescript/board-arrows.d.ts +27 -0
- package/lib/typescript/board-arrows.d.ts.map +1 -0
- package/lib/typescript/board-highlights.d.ts +65 -0
- package/lib/typescript/board-highlights.d.ts.map +1 -0
- package/lib/typescript/board-piece.d.ts +10 -4
- package/lib/typescript/board-piece.d.ts.map +1 -1
- package/lib/typescript/board-pieces.d.ts +2 -1
- package/lib/typescript/board-pieces.d.ts.map +1 -1
- package/lib/typescript/board.d.ts +11 -2
- package/lib/typescript/board.d.ts.map +1 -1
- package/lib/typescript/constants.d.ts +54 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pieces/default-pieces.d.ts +3 -0
- package/lib/typescript/pieces/default-pieces.d.ts.map +1 -0
- package/lib/typescript/pieces/index.d.ts +2 -0
- package/lib/typescript/pieces/index.d.ts.map +1 -0
- package/lib/typescript/promotion-picker.d.ts +30 -0
- package/lib/typescript/promotion-picker.d.ts.map +1 -0
- package/lib/typescript/static-board.d.ts +12 -0
- package/lib/typescript/static-board.d.ts.map +1 -0
- package/lib/typescript/themes.d.ts +15 -0
- package/lib/typescript/themes.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +194 -24
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/use-board-gesture.d.ts +28 -2
- package/lib/typescript/use-board-gesture.d.ts.map +1 -1
- package/lib/typescript/use-premove.d.ts +31 -0
- package/lib/typescript/use-premove.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/board-annotations.tsx +147 -0
- package/src/board-arrows.tsx +197 -0
- package/src/board-highlights.tsx +226 -0
- package/src/board-piece.tsx +50 -12
- package/src/board-pieces.tsx +4 -1
- package/src/board.tsx +462 -46
- package/src/constants.ts +100 -0
- package/src/index.ts +62 -1
- package/src/pieces/default-pieces.tsx +383 -0
- package/src/pieces/index.ts +1 -0
- package/src/promotion-picker.tsx +147 -0
- package/src/static-board.tsx +150 -0
- package/src/themes.ts +129 -0
- package/src/types.ts +251 -25
- package/src/use-board-gesture.ts +219 -8
- package/src/use-premove.ts +59 -0
package/src/types.ts
CHANGED
|
@@ -10,10 +10,21 @@ export type ChessColor = 'white' | 'black';
|
|
|
10
10
|
/** How the user interacts with pieces */
|
|
11
11
|
export type MoveMethod = 'drag' | 'click' | 'both';
|
|
12
12
|
|
|
13
|
+
/** Promotion piece choice */
|
|
14
|
+
export type PromotionPiece = 'q' | 'r' | 'b' | 'n';
|
|
15
|
+
|
|
16
|
+
/** Haptic feedback event types -- consumer wires to their preferred haptics library */
|
|
17
|
+
export type HapticType = 'select' | 'move' | 'capture' | 'error';
|
|
18
|
+
|
|
13
19
|
// ---------------------------------------------------------------------------
|
|
14
20
|
// Piece data
|
|
15
21
|
// ---------------------------------------------------------------------------
|
|
16
22
|
|
|
23
|
+
/** Standard piece codes used throughout the library */
|
|
24
|
+
export type PieceCode =
|
|
25
|
+
| 'wp' | 'wn' | 'wb' | 'wr' | 'wq' | 'wk'
|
|
26
|
+
| 'bp' | 'bn' | 'bb' | 'br' | 'bq' | 'bk';
|
|
27
|
+
|
|
17
28
|
/** A single piece on the board with its position and identity */
|
|
18
29
|
export type BoardPiece = {
|
|
19
30
|
/** Unique stable identifier (survives position changes): e.g. "wp-0", "bk-0" */
|
|
@@ -33,6 +44,114 @@ export type ParsedPiece = {
|
|
|
33
44
|
color: 'w' | 'b';
|
|
34
45
|
};
|
|
35
46
|
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Overlay data types
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
/** A square highlight (colored rectangle on a specific square) */
|
|
52
|
+
export type HighlightData = {
|
|
53
|
+
square: string;
|
|
54
|
+
color: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** An arrow drawn between two squares */
|
|
58
|
+
export type ArrowData = {
|
|
59
|
+
from: string;
|
|
60
|
+
to: string;
|
|
61
|
+
/** Arrow color. Default: theme-dependent */
|
|
62
|
+
color?: string;
|
|
63
|
+
/** Stroke width as percentage of square size. Default: 0.2 */
|
|
64
|
+
width?: number;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** A shape drawn on the board */
|
|
68
|
+
export type ShapeData = {
|
|
69
|
+
type: 'circle';
|
|
70
|
+
square: string;
|
|
71
|
+
color?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** A text annotation on a square (!, ?, !!, ??, etc.) */
|
|
75
|
+
export type AnnotationData = {
|
|
76
|
+
square: string;
|
|
77
|
+
text: string;
|
|
78
|
+
color?: string;
|
|
79
|
+
backgroundColor?: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** A premove queued for execution */
|
|
83
|
+
export type PremoveData = {
|
|
84
|
+
from: string;
|
|
85
|
+
to: string;
|
|
86
|
+
promotion?: PromotionPiece;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Animation configuration
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
export type TimingAnimationConfig = {
|
|
94
|
+
type: 'timing';
|
|
95
|
+
/** Duration in ms. Default: 200 */
|
|
96
|
+
duration?: number;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type SpringAnimationConfig = {
|
|
100
|
+
type: 'spring';
|
|
101
|
+
/** Damping ratio. Default: 0.7 */
|
|
102
|
+
damping?: number;
|
|
103
|
+
/** Stiffness. Default: 200 */
|
|
104
|
+
stiffness?: number;
|
|
105
|
+
/** Mass. Default: 1 */
|
|
106
|
+
mass?: number;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** Animation configuration for piece movement */
|
|
110
|
+
export type AnimationConfig = TimingAnimationConfig | SpringAnimationConfig;
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// Piece set
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
/** Map of piece code to React element renderer */
|
|
117
|
+
export type PieceSetMap = {
|
|
118
|
+
[code in PieceCode]: (size: number) => React.ReactElement;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Board colors / themes
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
export type BoardColors = {
|
|
126
|
+
light: string;
|
|
127
|
+
dark: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** A complete board theme with all configurable colors */
|
|
131
|
+
export type BoardTheme = {
|
|
132
|
+
/** Display name for the theme */
|
|
133
|
+
name: string;
|
|
134
|
+
/** Square colors */
|
|
135
|
+
board: BoardColors;
|
|
136
|
+
/** Last move highlight color */
|
|
137
|
+
lastMove: string;
|
|
138
|
+
/** Check highlight color */
|
|
139
|
+
check: string;
|
|
140
|
+
/** Selected piece square color */
|
|
141
|
+
selected: string;
|
|
142
|
+
/** Legal move dot color */
|
|
143
|
+
legalDot: string;
|
|
144
|
+
/** Premove highlight color */
|
|
145
|
+
premove: string;
|
|
146
|
+
/** Arrow default color */
|
|
147
|
+
arrow: string;
|
|
148
|
+
/** Coordinate text colors */
|
|
149
|
+
coordinates: {
|
|
150
|
+
light: string;
|
|
151
|
+
dark: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
36
155
|
// ---------------------------------------------------------------------------
|
|
37
156
|
// Board ref (exposed to consumers via forwardRef)
|
|
38
157
|
// ---------------------------------------------------------------------------
|
|
@@ -40,7 +159,7 @@ export type ParsedPiece = {
|
|
|
40
159
|
export type BoardRef = {
|
|
41
160
|
/** Pre-apply a move to internal state. Visual animation happens when parent updates the FEN prop. */
|
|
42
161
|
move: (move: { from: string; to: string }) => void;
|
|
43
|
-
/** Highlight a square with a color */
|
|
162
|
+
/** Highlight a square with a color. Adds to existing imperative highlights. */
|
|
44
163
|
highlight: (square: string, color: string) => void;
|
|
45
164
|
/** Clear all imperative highlights */
|
|
46
165
|
clearHighlights: () => void;
|
|
@@ -48,44 +167,149 @@ export type BoardRef = {
|
|
|
48
167
|
resetBoard: (fen: string) => void;
|
|
49
168
|
/** Undo the last visually applied move (snap back to previous position) */
|
|
50
169
|
undo: () => void;
|
|
170
|
+
/** Clear any queued premoves */
|
|
171
|
+
clearPremoves: () => void;
|
|
51
172
|
};
|
|
52
173
|
|
|
53
174
|
// ---------------------------------------------------------------------------
|
|
54
175
|
// Board props
|
|
55
176
|
// ---------------------------------------------------------------------------
|
|
56
177
|
|
|
57
|
-
export type BoardColors = {
|
|
58
|
-
light: string;
|
|
59
|
-
dark: string;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
178
|
export type BoardProps = {
|
|
179
|
+
// --- Required ---
|
|
180
|
+
|
|
63
181
|
/** Current board position in FEN notation */
|
|
64
182
|
fen: string;
|
|
65
183
|
/** Which color is at the bottom of the board */
|
|
66
184
|
orientation: ChessColor;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
185
|
+
|
|
186
|
+
// --- Layout ---
|
|
187
|
+
|
|
188
|
+
/** Board width/height in pixels. If omitted, auto-sizes from parent via onLayout. */
|
|
189
|
+
boardSize?: number;
|
|
190
|
+
|
|
191
|
+
// --- Interaction ---
|
|
192
|
+
|
|
193
|
+
/** Whether gesture interaction is enabled. Default: true */
|
|
194
|
+
gestureEnabled?: boolean;
|
|
195
|
+
/** Which side can interact: 'white', 'black', or 'both'. Default: 'both' */
|
|
196
|
+
player?: ChessColor | 'both';
|
|
197
|
+
/** How the user moves pieces. Default: 'both' */
|
|
198
|
+
moveMethod?: MoveMethod;
|
|
199
|
+
/** Whether to show legal move dots when a piece is selected. Default: true */
|
|
200
|
+
showLegalMoves?: boolean;
|
|
201
|
+
/** Enable premove queuing. Default: false */
|
|
202
|
+
premovesEnabled?: boolean;
|
|
203
|
+
|
|
204
|
+
// --- Appearance ---
|
|
205
|
+
|
|
206
|
+
/** Board square colors. Default: green theme */
|
|
207
|
+
colors?: BoardColors;
|
|
208
|
+
/** Whether to show file labels (a-h). Default: true */
|
|
209
|
+
withLetters?: boolean;
|
|
210
|
+
/** Whether to show rank numbers (1-8). Default: true */
|
|
211
|
+
withNumbers?: boolean;
|
|
212
|
+
/** Custom piece renderer. Receives piece code ('wp', 'bk', etc.) and pixel size. */
|
|
213
|
+
renderPiece?: (pieceCode: string, size: number) => React.ReactElement;
|
|
214
|
+
/** Built-in piece set (alternative to renderPiece). Default: built-in SVG set */
|
|
215
|
+
pieceSet?: PieceSetMap;
|
|
216
|
+
|
|
217
|
+
// --- Overlays ---
|
|
218
|
+
|
|
219
|
+
/** Last move to highlight (yellow on from/to squares) */
|
|
220
|
+
lastMove?: { from: string; to: string } | null;
|
|
221
|
+
/** Custom highlights. Merged with auto-highlights (last move, check). */
|
|
222
|
+
highlights?: HighlightData[];
|
|
223
|
+
/** Arrows to draw on the board */
|
|
224
|
+
arrows?: ArrowData[];
|
|
225
|
+
/** Shapes to draw on the board (circles) */
|
|
226
|
+
shapes?: ShapeData[];
|
|
227
|
+
/** Text annotations on squares (!, ?, etc.) */
|
|
228
|
+
annotations?: AnnotationData[];
|
|
229
|
+
/** Show drag target indicator under finger during drag. Default: true */
|
|
230
|
+
showDragTarget?: boolean;
|
|
231
|
+
|
|
232
|
+
// --- Overlay colors (overrides theme defaults) ---
|
|
233
|
+
|
|
234
|
+
/** Last move highlight color. Default: 'rgba(255,255,0,0.4)' */
|
|
235
|
+
lastMoveColor?: string;
|
|
236
|
+
/** Check highlight color. Default: radial gradient red */
|
|
237
|
+
checkHighlightColor?: string;
|
|
238
|
+
/** Selected piece square color. Default: 'rgba(20,85,200,0.5)' */
|
|
239
|
+
selectedSquareColor?: string;
|
|
240
|
+
/** Premove highlight color. Default: 'rgba(20,85,200,0.3)' */
|
|
241
|
+
premoveColor?: string;
|
|
242
|
+
/** Drag target highlight color. Default: 'rgba(0,0,0,0.1)' */
|
|
243
|
+
dragTargetColor?: string;
|
|
244
|
+
|
|
245
|
+
// --- Animation ---
|
|
246
|
+
|
|
247
|
+
/** Move animation duration in ms (0 = instant). Default: 200 */
|
|
248
|
+
moveDuration?: number;
|
|
249
|
+
/** Animation configuration (timing or spring). Overrides moveDuration if provided. */
|
|
250
|
+
animationConfig?: AnimationConfig;
|
|
251
|
+
/** Animate board rotation on orientation change. Default: true */
|
|
252
|
+
animateFlip?: boolean;
|
|
253
|
+
|
|
254
|
+
// --- Promotion ---
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Called when a pawn promotion occurs. If not provided, auto-promotes to queen.
|
|
258
|
+
* Return the chosen piece to complete the promotion.
|
|
259
|
+
*/
|
|
260
|
+
onPromotion?: (from: string, to: string) => Promise<PromotionPiece> | PromotionPiece;
|
|
261
|
+
|
|
262
|
+
// --- Callbacks ---
|
|
263
|
+
|
|
73
264
|
/** Called after a visual move is applied */
|
|
74
265
|
onMove?: (info: { from: string; to: string }) => void;
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
/**
|
|
266
|
+
/** Called when a piece is tapped */
|
|
267
|
+
onPieceClick?: (square: string, piece: PieceCode) => void;
|
|
268
|
+
/** Called when an empty square or opponent piece is tapped */
|
|
269
|
+
onSquareClick?: (square: string) => void;
|
|
270
|
+
/** Called when a piece drag begins */
|
|
271
|
+
onPieceDragBegin?: (square: string, piece: PieceCode) => void;
|
|
272
|
+
/** Called when a piece drag ends (regardless of move validity) */
|
|
273
|
+
onPieceDragEnd?: (square: string, piece: PieceCode) => void;
|
|
274
|
+
/** Called on long-press of a square */
|
|
275
|
+
onSquareLongPress?: (square: string) => void;
|
|
276
|
+
/** Called when a premove is set */
|
|
277
|
+
onPremove?: (premove: PremoveData) => void;
|
|
278
|
+
/**
|
|
279
|
+
* Haptic feedback callback. Consumer wires to their preferred haptics library.
|
|
280
|
+
* Called with event type: 'select' (piece pickup), 'move' (piece drop),
|
|
281
|
+
* 'capture' (piece takes), 'error' (invalid move).
|
|
282
|
+
*/
|
|
283
|
+
onHaptic?: (type: HapticType) => void;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
// Static board props (non-interactive variant)
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
export type StaticBoardProps = {
|
|
291
|
+
/** Board position in FEN notation */
|
|
292
|
+
fen: string;
|
|
293
|
+
/** Which color is at the bottom. Default: 'white' */
|
|
294
|
+
orientation?: ChessColor;
|
|
295
|
+
/** Board width/height in pixels. If omitted, auto-sizes from parent. */
|
|
296
|
+
boardSize?: number;
|
|
297
|
+
/** Board square colors. Default: green theme */
|
|
298
|
+
colors?: BoardColors;
|
|
299
|
+
/** Whether to show coordinate labels. Default: false */
|
|
300
|
+
withCoordinates?: boolean;
|
|
301
|
+
/** Custom piece renderer */
|
|
84
302
|
renderPiece?: (pieceCode: string, size: number) => React.ReactElement;
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
|
|
303
|
+
/** Built-in piece set */
|
|
304
|
+
pieceSet?: PieceSetMap;
|
|
305
|
+
/** Last move highlight */
|
|
306
|
+
lastMove?: { from: string; to: string } | null;
|
|
307
|
+
/** Custom highlights */
|
|
308
|
+
highlights?: HighlightData[];
|
|
309
|
+
/** Arrows */
|
|
310
|
+
arrows?: ArrowData[];
|
|
311
|
+
/** Annotations */
|
|
312
|
+
annotations?: AnnotationData[];
|
|
89
313
|
};
|
|
90
314
|
|
|
91
315
|
// ---------------------------------------------------------------------------
|
|
@@ -102,6 +326,8 @@ export type GestureState = {
|
|
|
102
326
|
isDragging: SharedValue<boolean>;
|
|
103
327
|
/** The piece code being dragged (for rendering the ghost) */
|
|
104
328
|
dragPieceCode: SharedValue<string | null>;
|
|
329
|
+
/** Square currently under the dragged piece (for drag target highlight) */
|
|
330
|
+
dragTargetSquare: SharedValue<string | null>;
|
|
105
331
|
};
|
|
106
332
|
|
|
107
333
|
// ---------------------------------------------------------------------------
|