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