react-native-chess-kit 0.5.0 → 0.5.2
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 +2 -2
- package/lib/commonjs/board-arrows.js.map +1 -1
- package/lib/commonjs/board-background.js +5 -5
- package/lib/commonjs/board-coordinates.js +8 -8
- 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 +24 -24
- package/lib/commonjs/promotion-picker.js +8 -8
- package/lib/commonjs/static-board.js +7 -7
- 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 +2 -2
- package/lib/module/board-arrows.js.map +1 -1
- package/lib/module/board-background.js +5 -5
- package/lib/module/board-coordinates.js +8 -8
- 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 +24 -24
- package/lib/module/promotion-picker.js +8 -8
- package/lib/module/static-board.js +7 -7
- 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/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 +2 -2
- package/src/board-background.tsx +46 -46
- package/src/board-coordinates.tsx +192 -192
- 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 -685
- package/src/constants.ts +103 -103
- package/src/index.ts +101 -101
- 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 -187
- package/src/themes.ts +129 -129
- package/src/types.ts +373 -373
- 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
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
5
5
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
-
/**
|
|
7
|
-
* Floating piece that follows the user's finger during drag.
|
|
8
|
-
*
|
|
9
|
-
* Only ONE instance exists — not one per piece. It reads drag position
|
|
10
|
-
* from shared values on the UI thread, so zero JS bridge calls and
|
|
11
|
-
* zero re-renders while dragging.
|
|
6
|
+
/**
|
|
7
|
+
* Floating piece that follows the user's finger during drag.
|
|
8
|
+
*
|
|
9
|
+
* Only ONE instance exists — not one per piece. It reads drag position
|
|
10
|
+
* from shared values on the UI thread, so zero JS bridge calls and
|
|
11
|
+
* zero re-renders while dragging.
|
|
12
12
|
*/
|
|
13
13
|
export const BoardDragGhost = /*#__PURE__*/React.memo(function BoardDragGhost({
|
|
14
14
|
squareSize,
|
|
@@ -57,10 +57,10 @@ export const BoardDragGhost = /*#__PURE__*/React.memo(function BoardDragGhost({
|
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* Inner content that renders the actual piece image.
|
|
62
|
-
* Separate component so the Animated.View wrapper doesn't need
|
|
63
|
-
* to re-render when the piece code changes — it uses shared value.
|
|
60
|
+
/**
|
|
61
|
+
* Inner content that renders the actual piece image.
|
|
62
|
+
* Separate component so the Animated.View wrapper doesn't need
|
|
63
|
+
* to re-render when the piece code changes — it uses shared value.
|
|
64
64
|
*/
|
|
65
65
|
const DragGhostContent = /*#__PURE__*/React.memo(function DragGhostContent({
|
|
66
66
|
renderPiece,
|
|
@@ -13,15 +13,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
// Static highlights (View-based, no animation needed)
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Renders all board square highlights as a single layer.
|
|
18
|
-
*
|
|
19
|
-
* Combines multiple highlight sources (last move, check, selected piece,
|
|
20
|
-
* premoves, custom, and imperative) into one flat list of colored rectangles.
|
|
21
|
-
* Rendered between the background and pieces layers.
|
|
22
|
-
*
|
|
23
|
-
* Uses plain Views (not Animated) because highlights change discretely
|
|
24
|
-
* on move events, not during animation frames.
|
|
16
|
+
/**
|
|
17
|
+
* Renders all board square highlights as a single layer.
|
|
18
|
+
*
|
|
19
|
+
* Combines multiple highlight sources (last move, check, selected piece,
|
|
20
|
+
* premoves, custom, and imperative) into one flat list of colored rectangles.
|
|
21
|
+
* Rendered between the background and pieces layers.
|
|
22
|
+
*
|
|
23
|
+
* Uses plain Views (not Animated) because highlights change discretely
|
|
24
|
+
* on move events, not during animation frames.
|
|
25
25
|
*/
|
|
26
26
|
export const BoardHighlights = /*#__PURE__*/React.memo(function BoardHighlights({
|
|
27
27
|
boardSize,
|
|
@@ -125,9 +125,9 @@ export const BoardHighlights = /*#__PURE__*/React.memo(function BoardHighlights(
|
|
|
125
125
|
// Drag target highlight (Animated, updates on UI thread during drag)
|
|
126
126
|
// ---------------------------------------------------------------------------
|
|
127
127
|
|
|
128
|
-
/**
|
|
129
|
-
* Highlight on the square currently under the dragged piece.
|
|
130
|
-
* Uses Reanimated shared values for zero-JS-bridge updates during drag.
|
|
128
|
+
/**
|
|
129
|
+
* Highlight on the square currently under the dragged piece.
|
|
130
|
+
* Uses Reanimated shared values for zero-JS-bridge updates during drag.
|
|
131
131
|
*/
|
|
132
132
|
export const DragTargetHighlight = /*#__PURE__*/React.memo(function DragTargetHighlight({
|
|
133
133
|
squareSize,
|
|
@@ -177,9 +177,9 @@ export const DragTargetHighlight = /*#__PURE__*/React.memo(function DragTargetHi
|
|
|
177
177
|
// Standalone SquareHighlight (exported for advanced consumers)
|
|
178
178
|
// ---------------------------------------------------------------------------
|
|
179
179
|
|
|
180
|
-
/**
|
|
181
|
-
* Single square highlight component.
|
|
182
|
-
* Exported for consumers who build their own overlay layers.
|
|
180
|
+
/**
|
|
181
|
+
* Single square highlight component.
|
|
182
|
+
* Exported for consumers who build their own overlay layers.
|
|
183
183
|
*/
|
|
184
184
|
export const SquareHighlight = /*#__PURE__*/React.memo(function SquareHighlight({
|
|
185
185
|
square,
|
|
@@ -4,11 +4,11 @@ import React from 'react';
|
|
|
4
4
|
import { View } from 'react-native';
|
|
5
5
|
import { squareToXY } from './use-board-pieces';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
/**
|
|
8
|
-
* Legal move indicator dots, rendered only when a piece is selected.
|
|
9
|
-
*
|
|
10
|
-
* Dots are CONDITIONALLY rendered (only for actual legal move squares,
|
|
11
|
-
* typically 5-15) instead of always mounting 64 invisible dot views.
|
|
7
|
+
/**
|
|
8
|
+
* Legal move indicator dots, rendered only when a piece is selected.
|
|
9
|
+
*
|
|
10
|
+
* Dots are CONDITIONALLY rendered (only for actual legal move squares,
|
|
11
|
+
* typically 5-15) instead of always mounting 64 invisible dot views.
|
|
12
12
|
*/
|
|
13
13
|
export const BoardLegalDots = /*#__PURE__*/React.memo(function BoardLegalDots({
|
|
14
14
|
legalMoves,
|
|
@@ -4,9 +4,9 @@ import React, { useEffect } from 'react';
|
|
|
4
4
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming, withSpring } from 'react-native-reanimated';
|
|
5
5
|
import { DEFAULT_MOVE_DURATION } from './constants';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
/**
|
|
8
|
-
* Animate a shared value using the provided AnimationConfig.
|
|
9
|
-
* Falls back to withTiming with moveDuration for backwards compatibility.
|
|
7
|
+
/**
|
|
8
|
+
* Animate a shared value using the provided AnimationConfig.
|
|
9
|
+
* Falls back to withTiming with moveDuration for backwards compatibility.
|
|
10
10
|
*/
|
|
11
11
|
function animateValue(target, config, moveDuration) {
|
|
12
12
|
if (config) {
|
|
@@ -29,28 +29,28 @@ function animateValue(target, config, moveDuration) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* A single animated chess piece.
|
|
34
|
-
*
|
|
35
|
-
* Uses two nested Animated.Views to avoid the Reanimated warning
|
|
36
|
-
* "Property opacity may be overwritten by a layout animation":
|
|
37
|
-
*
|
|
38
|
-
* Outer view: position (transform) + exiting layout animation (FadeOut)
|
|
39
|
-
* Inner view: drag-hide opacity
|
|
40
|
-
*
|
|
41
|
-
* Only `transform` and `opacity` are animated — Reanimated's fast path
|
|
42
|
-
* on Android. No layout properties (top/left/width/height), avoiding
|
|
43
|
-
* costly layout recalculations on low-end devices.
|
|
44
|
-
*
|
|
45
|
-
* During drag:
|
|
46
|
-
* - Inner view hides (opacity: 0) — the drag ghost shows instead
|
|
47
|
-
*
|
|
48
|
-
* After a move:
|
|
49
|
-
* - Outer view snaps to new position via withTiming/withSpring
|
|
50
|
-
*
|
|
51
|
-
* On capture (unmount):
|
|
52
|
-
* - Outer view plays the exitingAnimation (default: FadeOut, no conflict with inner opacity)
|
|
53
|
-
* - Pass exitingAnimation={undefined} to disable (instant disappear on full board remount)
|
|
32
|
+
/**
|
|
33
|
+
* A single animated chess piece.
|
|
34
|
+
*
|
|
35
|
+
* Uses two nested Animated.Views to avoid the Reanimated warning
|
|
36
|
+
* "Property opacity may be overwritten by a layout animation":
|
|
37
|
+
*
|
|
38
|
+
* Outer view: position (transform) + exiting layout animation (FadeOut)
|
|
39
|
+
* Inner view: drag-hide opacity
|
|
40
|
+
*
|
|
41
|
+
* Only `transform` and `opacity` are animated — Reanimated's fast path
|
|
42
|
+
* on Android. No layout properties (top/left/width/height), avoiding
|
|
43
|
+
* costly layout recalculations on low-end devices.
|
|
44
|
+
*
|
|
45
|
+
* During drag:
|
|
46
|
+
* - Inner view hides (opacity: 0) — the drag ghost shows instead
|
|
47
|
+
*
|
|
48
|
+
* After a move:
|
|
49
|
+
* - Outer view snaps to new position via withTiming/withSpring
|
|
50
|
+
*
|
|
51
|
+
* On capture (unmount):
|
|
52
|
+
* - Outer view plays the exitingAnimation (default: FadeOut, no conflict with inner opacity)
|
|
53
|
+
* - Pass exitingAnimation={undefined} to disable (instant disappear on full board remount)
|
|
54
54
|
*/
|
|
55
55
|
export const BoardPieceView = /*#__PURE__*/React.memo(function BoardPieceView({
|
|
56
56
|
targetX,
|
|
@@ -4,12 +4,12 @@ import React from 'react';
|
|
|
4
4
|
import { BoardPieceView } from './board-piece';
|
|
5
5
|
import { squareToXY } from './use-board-pieces';
|
|
6
6
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
|
-
/**
|
|
8
|
-
* Renders all pieces on the board.
|
|
9
|
-
*
|
|
10
|
-
* Each piece gets a stable key (from useBoardPieces) so React doesn't
|
|
11
|
-
* unmount/remount pieces that moved — it updates their position props
|
|
12
|
-
* and the BoardPieceView animates the transition.
|
|
7
|
+
/**
|
|
8
|
+
* Renders all pieces on the board.
|
|
9
|
+
*
|
|
10
|
+
* Each piece gets a stable key (from useBoardPieces) so React doesn't
|
|
11
|
+
* unmount/remount pieces that moved — it updates their position props
|
|
12
|
+
* and the BoardPieceView animates the transition.
|
|
13
13
|
*/
|
|
14
14
|
export const BoardPiecesLayer = /*#__PURE__*/React.memo(function BoardPiecesLayer({
|
|
15
15
|
pieces,
|
package/lib/module/board.js
CHANGED
|
@@ -24,9 +24,9 @@ import { PromotionPicker } from './promotion-picker';
|
|
|
24
24
|
// Check detection helper
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Find the king square for the side currently in check.
|
|
29
|
-
* Returns null if not in check.
|
|
27
|
+
/**
|
|
28
|
+
* Find the king square for the side currently in check.
|
|
29
|
+
* Returns null if not in check.
|
|
30
30
|
*/
|
|
31
31
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
32
|
function detectCheckSquare(fen, isInCheck, getTurn) {
|
|
@@ -57,27 +57,27 @@ function detectCheckSquare(fen, isInCheck, getTurn) {
|
|
|
57
57
|
// Board component
|
|
58
58
|
// ---------------------------------------------------------------------------
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* High-performance custom chess board built on Reanimated + Gesture Handler.
|
|
62
|
-
*
|
|
63
|
-
* Architecture:
|
|
64
|
-
* - 1 gesture handler (vs 32 in typical implementations)
|
|
65
|
-
* - ~40 components mounted (vs ~281)
|
|
66
|
-
* - ~75 native views (vs ~470)
|
|
67
|
-
* - 0 React Context providers
|
|
68
|
-
* - 0 re-renders during drag (pure worklet — only 2 shared value writes per frame)
|
|
69
|
-
*
|
|
70
|
-
* v0.2.0 layer stack (10 layers):
|
|
71
|
-
* 1. BoardBackground (64 squares)
|
|
72
|
-
* 2. BoardCoordinates (a-h, 1-8)
|
|
73
|
-
* 3. BoardHighlights (last move, check, selected, premove, custom, imperative)
|
|
74
|
-
* 4. DragTargetHighlight (animated, worklet-driven)
|
|
75
|
-
* 5. BoardLegalDots (legal move indicators)
|
|
76
|
-
* 6. BoardPiecesLayer (all pieces)
|
|
77
|
-
* 7. BoardArrows (SVG arrows + circles)
|
|
78
|
-
* 8. BoardAnnotations (text badges)
|
|
79
|
-
* 9. BoardDragGhost (floating piece)
|
|
80
|
-
* 10. PromotionPicker (modal, conditional)
|
|
60
|
+
/**
|
|
61
|
+
* High-performance custom chess board built on Reanimated + Gesture Handler.
|
|
62
|
+
*
|
|
63
|
+
* Architecture:
|
|
64
|
+
* - 1 gesture handler (vs 32 in typical implementations)
|
|
65
|
+
* - ~40 components mounted (vs ~281)
|
|
66
|
+
* - ~75 native views (vs ~470)
|
|
67
|
+
* - 0 React Context providers
|
|
68
|
+
* - 0 re-renders during drag (pure worklet — only 2 shared value writes per frame)
|
|
69
|
+
*
|
|
70
|
+
* v0.2.0 layer stack (10 layers):
|
|
71
|
+
* 1. BoardBackground (64 squares)
|
|
72
|
+
* 2. BoardCoordinates (a-h, 1-8)
|
|
73
|
+
* 3. BoardHighlights (last move, check, selected, premove, custom, imperative)
|
|
74
|
+
* 4. DragTargetHighlight (animated, worklet-driven)
|
|
75
|
+
* 5. BoardLegalDots (legal move indicators)
|
|
76
|
+
* 6. BoardPiecesLayer (all pieces)
|
|
77
|
+
* 7. BoardArrows (SVG arrows + circles)
|
|
78
|
+
* 8. BoardAnnotations (text badges)
|
|
79
|
+
* 9. BoardDragGhost (floating piece)
|
|
80
|
+
* 10. PromotionPicker (modal, conditional)
|
|
81
81
|
*/
|
|
82
82
|
export const Board = /*#__PURE__*/forwardRef(function Board({
|
|
83
83
|
fen,
|
|
@@ -22,14 +22,14 @@ function promotionPieceCode(color, piece) {
|
|
|
22
22
|
// Component
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Promotion piece picker overlay.
|
|
27
|
-
*
|
|
28
|
-
* Appears as a vertical column of 4 pieces (Q, R, B, N) anchored to the
|
|
29
|
-
* promotion square. Expands downward when promoting on the top edge,
|
|
30
|
-
* upward when promoting on the bottom edge.
|
|
31
|
-
*
|
|
32
|
-
* A semi-transparent backdrop covers the board. Tapping outside cancels.
|
|
25
|
+
/**
|
|
26
|
+
* Promotion piece picker overlay.
|
|
27
|
+
*
|
|
28
|
+
* Appears as a vertical column of 4 pieces (Q, R, B, N) anchored to the
|
|
29
|
+
* promotion square. Expands downward when promoting on the top edge,
|
|
30
|
+
* upward when promoting on the bottom edge.
|
|
31
|
+
*
|
|
32
|
+
* A semi-transparent backdrop covers the board. Tapping outside cancels.
|
|
33
33
|
*/
|
|
34
34
|
export const PromotionPicker = /*#__PURE__*/React.memo(function PromotionPicker({
|
|
35
35
|
square,
|
|
@@ -11,13 +11,13 @@ import { BoardHighlights } from './board-highlights';
|
|
|
11
11
|
import { BoardArrows } from './board-arrows';
|
|
12
12
|
import { BoardAnnotations } from './board-annotations';
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Non-interactive chess board — optimized for lists, thumbnails, and analysis previews.
|
|
16
|
-
*
|
|
17
|
-
* No gesture handler, no drag ghost, no legal move dots.
|
|
18
|
-
* Just: background + coordinates + highlights + pieces + arrows + annotations.
|
|
19
|
-
*
|
|
20
|
-
* Significantly lighter than the full Board component.
|
|
14
|
+
/**
|
|
15
|
+
* Non-interactive chess board — optimized for lists, thumbnails, and analysis previews.
|
|
16
|
+
*
|
|
17
|
+
* No gesture handler, no drag ghost, no legal move dots.
|
|
18
|
+
* Just: background + coordinates + highlights + pieces + arrows + annotations.
|
|
19
|
+
*
|
|
20
|
+
* Significantly lighter than the full Board component.
|
|
21
21
|
*/
|
|
22
22
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
23
|
export const StaticBoard = /*#__PURE__*/React.memo(function StaticBoard({
|
|
@@ -35,31 +35,31 @@ function pieceColorToPlayer(color) {
|
|
|
35
35
|
// Hook
|
|
36
36
|
// ---------------------------------------------------------------------------
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Single centralized gesture handler for the entire board.
|
|
40
|
-
*
|
|
41
|
-
* Instead of 32 separate Gesture.Pan() handlers (one per piece), we use ONE
|
|
42
|
-
* handler on the board container. Touch -> coordinate math -> which piece.
|
|
43
|
-
*
|
|
44
|
-
* Supports three modes:
|
|
45
|
-
* - 'drag': drag piece to target square
|
|
46
|
-
* - 'click': tap source piece, then tap target square
|
|
47
|
-
* - 'both': drag or click (default)
|
|
48
|
-
*
|
|
49
|
-
* All drag position tracking uses shared values — zero JS bridge calls,
|
|
50
|
-
* zero re-renders during drag. Only the final move triggers JS via runOnJS.
|
|
51
|
-
*
|
|
52
|
-
* The gesture object is STABLE (only recreated when squareSize, orientation,
|
|
53
|
-
* gestureEnabled, player, or moveMethod change). Frequently-changing data
|
|
54
|
-
* (pieces, selectedSquare, legalMoves) is read from refs via runOnJS bridge
|
|
55
|
-
* functions, avoiding costly gesture teardown/rebuild on every move.
|
|
56
|
-
*
|
|
57
|
-
* v0.2.0 additions:
|
|
58
|
-
* - Rich callbacks (onPieceClick, onSquareClick, onPieceDragBegin, onPieceDragEnd)
|
|
59
|
-
* - Drag target square tracking (shared value for DragTargetHighlight)
|
|
60
|
-
* - Premove support (queue move when not your turn)
|
|
61
|
-
* - Haptic feedback via callback
|
|
62
|
-
* - Long press detection for onSquareLongPress
|
|
38
|
+
/**
|
|
39
|
+
* Single centralized gesture handler for the entire board.
|
|
40
|
+
*
|
|
41
|
+
* Instead of 32 separate Gesture.Pan() handlers (one per piece), we use ONE
|
|
42
|
+
* handler on the board container. Touch -> coordinate math -> which piece.
|
|
43
|
+
*
|
|
44
|
+
* Supports three modes:
|
|
45
|
+
* - 'drag': drag piece to target square
|
|
46
|
+
* - 'click': tap source piece, then tap target square
|
|
47
|
+
* - 'both': drag or click (default)
|
|
48
|
+
*
|
|
49
|
+
* All drag position tracking uses shared values — zero JS bridge calls,
|
|
50
|
+
* zero re-renders during drag. Only the final move triggers JS via runOnJS.
|
|
51
|
+
*
|
|
52
|
+
* The gesture object is STABLE (only recreated when squareSize, orientation,
|
|
53
|
+
* gestureEnabled, player, or moveMethod change). Frequently-changing data
|
|
54
|
+
* (pieces, selectedSquare, legalMoves) is read from refs via runOnJS bridge
|
|
55
|
+
* functions, avoiding costly gesture teardown/rebuild on every move.
|
|
56
|
+
*
|
|
57
|
+
* v0.2.0 additions:
|
|
58
|
+
* - Rich callbacks (onPieceClick, onSquareClick, onPieceDragBegin, onPieceDragEnd)
|
|
59
|
+
* - Drag target square tracking (shared value for DragTargetHighlight)
|
|
60
|
+
* - Premove support (queue move when not your turn)
|
|
61
|
+
* - Haptic feedback via callback
|
|
62
|
+
* - Long press detection for onSquareLongPress
|
|
63
63
|
*/
|
|
64
64
|
export function useBoardGesture({
|
|
65
65
|
squareSize,
|
|
@@ -136,6 +136,7 @@ export function useBoardGesture({
|
|
|
136
136
|
const legalSquares = new Set(currentLegalMoves.map(m => m.square));
|
|
137
137
|
if (canClick && currentSelected && legalSquares.has(square)) {
|
|
138
138
|
cbs.onPieceMoved(currentSelected, square);
|
|
139
|
+
// Clear optimistic worklet value — move is complete
|
|
139
140
|
activeSquare.value = null;
|
|
140
141
|
isDragging.value = false;
|
|
141
142
|
dragPieceCode.value = null;
|
|
@@ -143,6 +144,15 @@ export function useBoardGesture({
|
|
|
143
144
|
rich?.onHaptic?.('move');
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
147
|
+
|
|
148
|
+
// Chess.com-style deselect: tapping the already-selected piece toggles it off
|
|
149
|
+
if (canClick && currentSelected === square) {
|
|
150
|
+
cbs.onSelectionCleared();
|
|
151
|
+
activeSquare.value = null;
|
|
152
|
+
dragPieceCode.value = null;
|
|
153
|
+
dragTargetSquare.value = null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
146
156
|
if (isPlayerPiece && piece) {
|
|
147
157
|
// Premove: player piece but not their turn
|
|
148
158
|
if (premovesEnabled && !isOwnTurn) {
|
|
@@ -159,9 +169,7 @@ export function useBoardGesture({
|
|
|
159
169
|
return;
|
|
160
170
|
}
|
|
161
171
|
// First tap: select the piece for premove
|
|
162
|
-
activeSquare.value
|
|
163
|
-
dragX.value = touchX;
|
|
164
|
-
dragY.value = touchY;
|
|
172
|
+
// activeSquare.value / dragX.value / dragY.value already set by onBegin worklet
|
|
165
173
|
dragPieceCode.value = piece.code;
|
|
166
174
|
cbs.onPieceSelected(square);
|
|
167
175
|
rich?.onPieceClick?.(square, piece.code);
|
|
@@ -170,9 +178,7 @@ export function useBoardGesture({
|
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
// Normal case: tapped/started dragging a player piece on their turn
|
|
173
|
-
activeSquare.value
|
|
174
|
-
dragX.value = touchX;
|
|
175
|
-
dragY.value = touchY;
|
|
181
|
+
// activeSquare.value / dragX.value / dragY.value already set by onBegin worklet
|
|
176
182
|
dragPieceCode.value = piece.code;
|
|
177
183
|
draggedPieceRef.current = {
|
|
178
184
|
square,
|
|
@@ -198,6 +204,8 @@ export function useBoardGesture({
|
|
|
198
204
|
dragTargetSquare.value = null;
|
|
199
205
|
return;
|
|
200
206
|
}
|
|
207
|
+
|
|
208
|
+
// Clear the optimistic worklet value — no valid piece here
|
|
201
209
|
activeSquare.value = null;
|
|
202
210
|
dragPieceCode.value = null;
|
|
203
211
|
dragTargetSquare.value = null;
|
|
@@ -252,9 +260,13 @@ export function useBoardGesture({
|
|
|
252
260
|
} else {
|
|
253
261
|
callbacksRef.current.onPieceMoved(fromSquare, toSquare);
|
|
254
262
|
}
|
|
263
|
+
|
|
264
|
+
// Move completed — clear selection
|
|
265
|
+
activeSquare.value = null;
|
|
266
|
+
dragPieceCode.value = null;
|
|
255
267
|
}
|
|
256
|
-
|
|
257
|
-
|
|
268
|
+
// When fromSquare === toSquare (tap with no movement), keep selection alive
|
|
269
|
+
// so the user can complete a click-to-move on the next tap.
|
|
258
270
|
}, [squareSize, orientation, activeSquare, isDragging, dragPieceCode, dragTargetSquare, premovesEnabled]);
|
|
259
271
|
|
|
260
272
|
// Long press handler (separate gesture, composed with pan)
|
|
@@ -274,6 +286,13 @@ export function useBoardGesture({
|
|
|
274
286
|
.onBegin(e => {
|
|
275
287
|
'worklet';
|
|
276
288
|
|
|
289
|
+
// Set shared values IMMEDIATELY on the UI thread so onStart can read them
|
|
290
|
+
// synchronously. xyToSquare is tagged 'worklet' — safe to call here.
|
|
291
|
+
// handleBegin (JS thread) will CLEAR activeSquare if the square is invalid.
|
|
292
|
+
const sq = xyToSquare(e.x, e.y, squareSize, orientation);
|
|
293
|
+
activeSquare.value = sq;
|
|
294
|
+
dragX.value = e.x;
|
|
295
|
+
dragY.value = e.y;
|
|
277
296
|
// Bridge to JS for piece lookup + selection logic
|
|
278
297
|
runOnJS(handleBegin)(e.x, e.y);
|
|
279
298
|
}).onStart(e => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useCallback","useRef","Gesture","useSharedValue","runOnJS","xyToSquare","isPieceTurn","pieceColor","currentTurn","pieceColorToPlayer","color","useBoardGesture","squareSize","orientation","gestureEnabled","player","moveMethod","pieces","callbacks","richCallbacks","premoveCallbacks","premovesEnabled","selectedSquare","legalMoves","activeSquare","dragX","dragY","isDragging","dragPieceCode","dragTargetSquare","gestureState","piecesRef","current","selectedSquareRef","legalMovesRef","callbacksRef","richCallbacksRef","premoveCallbacksRef","currentTurnRef","draggedPieceRef","handleBegin","touchX","touchY","square","currentPieces","currentSelected","currentLegalMoves","cbs","rich","canClick","piece","find","p","isPlayerPiece","turn","isOwnTurn","legalSquares","Set","map","m","has","onPieceMoved","value","onHaptic","onPremoveSet","from","to","onSelectionCleared","code","onPieceSelected","onPieceClick","onSquareClick","handleDragStart","dragged","onPieceDragBegin","handleDragUpdate","handleEnd","fromSquare","toSquare","onPieceDragEnd","handleLongPress","onSquareLongPress","canDrag","lastDragTargetCol","lastDragTargetRow","gesture","Pan","enabled","minDistance","onBegin","e","x","y","onStart","onUpdate","col","Math","max","min","floor","row","onEnd","onFinalize"],"sourceRoot":"..\\..\\src","sources":["use-board-gesture.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AACpD,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,cAAc,EACdC,OAAO,QACF,yBAAyB;AAYhC,SAASC,UAAU,QAAQ,oBAAoB;;AA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,KAAK,GAAG,CAAC,CAAC;IAC9B,CAAC,CAAC;EACN,CAAC,EAAE,CACDhD,cAAc,EACdoE,OAAO,EACPtE,UAAU,EACV4B,WAAW,EACXgC,eAAe,EACfG,gBAAgB,EAChBC,SAAS;EACT;EACApD,YAAY,EACZC,KAAK,EACLC,KAAK,EACLC,UAAU,EACVE,gBAAgB,EAChBsD,iBAAiB,EACjBC,iBAAiB,CAClB,CAAC;;EAEF;EACA;EACA;;EAEA,OAAO;IAAEC,OAAO;IAAEvD;EAAa,CAAC;AAClC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useMemo","useCallback","useRef","Gesture","useSharedValue","runOnJS","xyToSquare","isPieceTurn","pieceColor","currentTurn","pieceColorToPlayer","color","useBoardGesture","squareSize","orientation","gestureEnabled","player","moveMethod","pieces","callbacks","richCallbacks","premoveCallbacks","premovesEnabled","selectedSquare","legalMoves","activeSquare","dragX","dragY","isDragging","dragPieceCode","dragTargetSquare","gestureState","piecesRef","current","selectedSquareRef","legalMovesRef","callbacksRef","richCallbacksRef","premoveCallbacksRef","currentTurnRef","draggedPieceRef","handleBegin","touchX","touchY","square","currentPieces","currentSelected","currentLegalMoves","cbs","rich","canClick","piece","find","p","isPlayerPiece","turn","isOwnTurn","legalSquares","Set","map","m","has","onPieceMoved","value","onHaptic","onSelectionCleared","onPremoveSet","from","to","code","onPieceSelected","onPieceClick","onSquareClick","handleDragStart","dragged","onPieceDragBegin","handleDragUpdate","handleEnd","fromSquare","toSquare","onPieceDragEnd","handleLongPress","onSquareLongPress","canDrag","lastDragTargetCol","lastDragTargetRow","gesture","Pan","enabled","minDistance","onBegin","e","sq","x","y","onStart","onUpdate","col","Math","max","min","floor","row","onEnd","onFinalize"],"sourceRoot":"..\\..\\src","sources":["use-board-gesture.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AACpD,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,cAAc,EACdC,O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AAU,CAACmC,KAAK,IAAI,CAACtC,YAAY,CAACsC,KAAK,EAAE;MAC9C1D,OAAO,CAACwE,SAAS,CAAC,CAACc,CAAC,CAACE,CAAC,EAAEF,CAAC,CAACG,CAAC,CAAC;IAC9B,CAAC,CAAC,CACDU,UAAU,CAAC,MAAM;MAChB,SAAS;;MACT;MACA5E,UAAU,CAACmC,KAAK,GAAG,KAAK;MACxBjC,gBAAgB,CAACiC,KAAK,GAAG,IAAI;MAC7BqB,iBAAiB,CAACrB,KAAK,GAAG,CAAC,CAAC;MAC5BsB,iBAAiB,CAACtB,KAAK,GAAG,CAAC,CAAC;IAC9B,CAAC,CAAC;EACN,CAAC,EAAE,CACDhD,cAAc,EACdoE,OAAO,EACPtE,UAAU,EACV4B,WAAW,EACXgC,eAAe,EACfG,gBAAgB,EAChBC,SAAS;EACT;EACApD,YAAY,EACZC,KAAK,EACLC,KAAK,EACLC,UAAU,EACVE,gBAAgB,EAChBsD,iBAAiB,EACjBC,iBAAiB,CAClB,CAAC;;EAEF;EACA;EACA;;EAEA,OAAO;IAAEC,OAAO;IAAEvD;EAAa,CAAC;AAClC","ignoreList":[]}
|
|
@@ -53,9 +53,9 @@ const FEN_PIECE_MAP = {
|
|
|
53
53
|
};
|
|
54
54
|
const FILES = 'abcdefgh';
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* Parse the piece-placement part of a FEN string into an array of pieces.
|
|
58
|
-
* Pure function — no React dependencies, suitable for worklets if needed.
|
|
56
|
+
/**
|
|
57
|
+
* Parse the piece-placement part of a FEN string into an array of pieces.
|
|
58
|
+
* Pure function — no React dependencies, suitable for worklets if needed.
|
|
59
59
|
*/
|
|
60
60
|
function parseFenPieces(fen) {
|
|
61
61
|
const placement = fen.split(' ')[0];
|
|
@@ -85,9 +85,9 @@ function parseFenPieces(fen) {
|
|
|
85
85
|
return pieces;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
* Convert square notation to pixel coordinates (top-left corner).
|
|
90
|
-
* Orientation-aware: flips the board when playing as black.
|
|
88
|
+
/**
|
|
89
|
+
* Convert square notation to pixel coordinates (top-left corner).
|
|
90
|
+
* Orientation-aware: flips the board when playing as black.
|
|
91
91
|
*/
|
|
92
92
|
export function squareToXY(square, squareSize, orientation) {
|
|
93
93
|
'worklet';
|
|
@@ -103,9 +103,9 @@ export function squareToXY(square, squareSize, orientation) {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
* Convert pixel coordinates to a square notation string.
|
|
108
|
-
* Clamps to board bounds. Orientation-aware.
|
|
106
|
+
/**
|
|
107
|
+
* Convert pixel coordinates to a square notation string.
|
|
108
|
+
* Clamps to board bounds. Orientation-aware.
|
|
109
109
|
*/
|
|
110
110
|
export function xyToSquare(x, y, squareSize, orientation) {
|
|
111
111
|
'worklet';
|
|
@@ -120,12 +120,12 @@ export function xyToSquare(x, y, squareSize, orientation) {
|
|
|
120
120
|
return `${files[fileIdx]}${rankIdx + 1}`;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/**
|
|
124
|
-
* Manages the piece list derived from FEN, with stable IDs for React keys.
|
|
125
|
-
*
|
|
126
|
-
* Stable IDs prevent unmount/remount cycles when pieces change position.
|
|
127
|
-
* A piece keeps its ID as long as it exists on the board — only capture
|
|
128
|
-
* (removal) or promotion (code change) creates a new ID.
|
|
123
|
+
/**
|
|
124
|
+
* Manages the piece list derived from FEN, with stable IDs for React keys.
|
|
125
|
+
*
|
|
126
|
+
* Stable IDs prevent unmount/remount cycles when pieces change position.
|
|
127
|
+
* A piece keeps its ID as long as it exists on the board — only capture
|
|
128
|
+
* (removal) or promotion (code change) creates a new ID.
|
|
129
129
|
*/
|
|
130
130
|
export function useBoardPieces(fen) {
|
|
131
131
|
// Track piece-code counters across renders for stable ID assignment
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { useRef, useCallback, useMemo } from 'react';
|
|
4
4
|
import { Chess } from 'chess.js';
|
|
5
|
-
/**
|
|
6
|
-
* Manages the internal chess.js instance for legal move validation.
|
|
7
|
-
*
|
|
8
|
-
* This mirrors the visual board state. When the parent passes a new FEN,
|
|
9
|
-
* the internal chess.js is synced. Legal move queries and move application
|
|
10
|
-
* happen against this instance.
|
|
11
|
-
*
|
|
12
|
-
* The chess.js instance lives in a ref — no React state, no re-renders.
|
|
5
|
+
/**
|
|
6
|
+
* Manages the internal chess.js instance for legal move validation.
|
|
7
|
+
*
|
|
8
|
+
* This mirrors the visual board state. When the parent passes a new FEN,
|
|
9
|
+
* the internal chess.js is synced. Legal move queries and move application
|
|
10
|
+
* happen against this instance.
|
|
11
|
+
*
|
|
12
|
+
* The chess.js instance lives in a ref — no React state, no re-renders.
|
|
13
13
|
*/
|
|
14
14
|
export function useBoardState(initialFen) {
|
|
15
15
|
const chessRef = useRef(null);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useState, useCallback } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* Manages a single premove queue (one premove at a time).
|
|
6
|
-
*
|
|
7
|
-
* Premoves work like lichess:
|
|
8
|
-
* 1. When it's not your turn, you can drag/click a move — it queues as a premove
|
|
9
|
-
* 2. The premove squares are highlighted with a distinct color
|
|
10
|
-
* 3. When your turn begins (FEN changes and it's now your turn), the premove
|
|
11
|
-
* is automatically attempted via the board's internal chess.js
|
|
12
|
-
* 4. If the premove is legal, it's applied; if not, it's silently discarded
|
|
13
|
-
*
|
|
14
|
-
* The board.tsx orchestrates this: it calls consumePremove() in a useEffect
|
|
15
|
-
* that watches the FEN (turn change), then attempts the move.
|
|
4
|
+
/**
|
|
5
|
+
* Manages a single premove queue (one premove at a time).
|
|
6
|
+
*
|
|
7
|
+
* Premoves work like lichess:
|
|
8
|
+
* 1. When it's not your turn, you can drag/click a move — it queues as a premove
|
|
9
|
+
* 2. The premove squares are highlighted with a distinct color
|
|
10
|
+
* 3. When your turn begins (FEN changes and it's now your turn), the premove
|
|
11
|
+
* is automatically attempted via the board's internal chess.js
|
|
12
|
+
* 4. If the premove is legal, it's applied; if not, it's silently discarded
|
|
13
|
+
*
|
|
14
|
+
* The board.tsx orchestrates this: it calls consumePremove() in a useEffect
|
|
15
|
+
* that watches the FEN (turn change), then attempts the move.
|
|
16
16
|
*/
|
|
17
17
|
export function usePremove() {
|
|
18
18
|
const [premove, setPremoveState] = useState(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-board-gesture.d.ts","sourceRoot":"","sources":["../../src/use-board-gesture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAMvD,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACZ,MAAM,SAAS,CAAC;AAOjB,KAAK,gBAAgB,GAAG;IACtB,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,kBAAkB,EAAE,MAAM,IAAI,CAAC;CAChC,CAAC;AAEF,yDAAyD;AACzD,KAAK,aAAa,GAAG;IACnB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1D,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAC9D,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAC5D,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,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AAE,UAAU,GAAG,MAAM,CAAC;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,mCAAmC;IACnC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,6DAA6D;IAC7D,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,2DAA2D;IAC3D,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,iEAAiE;IACjE,WAAW,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;CACzB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAoBF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,WAAW,EACX,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,eAAuB,EACvB,cAAc,EACd,UAAU,EACV,WAAW,GACZ,EAAE,qBAAqB,GAAG,qBAAqB,CAyS/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-chess-kit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "High-performance chess board for React Native. Single gesture handler, ~40 components, 0 re-renders during drag. Built on Reanimated + Gesture Handler.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|