react-native-chess-kit 0.5.3 → 0.5.4
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 +187 -187
- package/lib/commonjs/board-annotations.js +8 -8
- package/lib/commonjs/board-annotations.js.map +1 -1
- package/lib/commonjs/board-arrows.js +7 -7
- package/lib/commonjs/board-arrows.js.map +1 -1
- package/lib/commonjs/board-background.js +5 -5
- package/lib/commonjs/board-background.js.map +1 -1
- package/lib/commonjs/board-coordinates.js.map +1 -1
- package/lib/commonjs/board-drag-ghost.js +10 -10
- package/lib/commonjs/board-drag-ghost.js.map +1 -1
- package/lib/commonjs/board-highlights.js +15 -15
- package/lib/commonjs/board-highlights.js.map +1 -1
- package/lib/commonjs/board-legal-dots.js +5 -5
- package/lib/commonjs/board-legal-dots.js.map +1 -1
- package/lib/commonjs/board-piece.js +25 -25
- package/lib/commonjs/board-piece.js.map +1 -1
- package/lib/commonjs/board-pieces.js +6 -6
- package/lib/commonjs/board-pieces.js.map +1 -1
- package/lib/commonjs/board.js +32 -28
- package/lib/commonjs/board.js.map +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pieces/default-pieces.js.map +1 -1
- package/lib/commonjs/pieces/index.js.map +1 -1
- package/lib/commonjs/promotion-picker.js.map +1 -1
- package/lib/commonjs/static-board.js.map +1 -1
- package/lib/commonjs/themes.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/use-board-gesture.js.map +1 -1
- package/lib/commonjs/use-board-pieces.js +15 -15
- package/lib/commonjs/use-board-pieces.js.map +1 -1
- package/lib/commonjs/use-board-state.js +8 -8
- package/lib/commonjs/use-board-state.js.map +1 -1
- package/lib/commonjs/use-premove.js +12 -12
- package/lib/commonjs/use-premove.js.map +1 -1
- package/lib/module/board-annotations.js +8 -8
- package/lib/module/board-annotations.js.map +1 -1
- package/lib/module/board-arrows.js +7 -7
- package/lib/module/board-arrows.js.map +1 -1
- package/lib/module/board-background.js +5 -5
- package/lib/module/board-background.js.map +1 -1
- package/lib/module/board-coordinates.js.map +1 -1
- package/lib/module/board-drag-ghost.js +10 -10
- package/lib/module/board-drag-ghost.js.map +1 -1
- package/lib/module/board-highlights.js +15 -15
- package/lib/module/board-highlights.js.map +1 -1
- package/lib/module/board-legal-dots.js +5 -5
- package/lib/module/board-legal-dots.js.map +1 -1
- package/lib/module/board-piece.js +25 -25
- package/lib/module/board-piece.js.map +1 -1
- package/lib/module/board-pieces.js +6 -6
- package/lib/module/board-pieces.js.map +1 -1
- package/lib/module/board.js +32 -28
- package/lib/module/board.js.map +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/pieces/default-pieces.js.map +1 -1
- package/lib/module/pieces/index.js.map +1 -1
- package/lib/module/promotion-picker.js.map +1 -1
- package/lib/module/static-board.js.map +1 -1
- package/lib/module/themes.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/use-board-gesture.js.map +1 -1
- package/lib/module/use-board-pieces.js +15 -15
- package/lib/module/use-board-pieces.js.map +1 -1
- package/lib/module/use-board-state.js +8 -8
- package/lib/module/use-board-state.js.map +1 -1
- package/lib/module/use-premove.js +12 -12
- package/lib/module/use-premove.js.map +1 -1
- package/lib/typescript/types.d.ts +2 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +95 -95
- package/src/board-annotations.tsx +147 -147
- package/src/board-arrows.tsx +197 -197
- package/src/board-background.tsx +46 -46
- 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 +688 -688
- 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/themes.ts +129 -129
- package/src/types.ts +394 -394
- package/src/use-board-pieces.ts +158 -158
- package/src/use-board-state.ts +120 -120
- package/src/use-premove.ts +59 -59
package/src/board-drag-ghost.tsx
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Animated, {
|
|
3
|
-
useAnimatedStyle,
|
|
4
|
-
type SharedValue,
|
|
5
|
-
} from 'react-native-reanimated';
|
|
6
|
-
|
|
7
|
-
type BoardDragGhostProps = {
|
|
8
|
-
squareSize: number;
|
|
9
|
-
isDragging: SharedValue<boolean>;
|
|
10
|
-
dragX: SharedValue<number>;
|
|
11
|
-
dragY: SharedValue<number>;
|
|
12
|
-
dragPieceCode: SharedValue<string | null>;
|
|
13
|
-
/** Render the piece image for a given piece code */
|
|
14
|
-
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Floating piece that follows the user's finger during drag.
|
|
19
|
-
*
|
|
20
|
-
* Only ONE instance exists — not one per piece. It reads drag position
|
|
21
|
-
* from shared values on the UI thread, so zero JS bridge calls and
|
|
22
|
-
* zero re-renders while dragging.
|
|
23
|
-
*/
|
|
24
|
-
export const BoardDragGhost = React.memo(function BoardDragGhost({
|
|
25
|
-
squareSize,
|
|
26
|
-
isDragging,
|
|
27
|
-
dragX,
|
|
28
|
-
dragY,
|
|
29
|
-
dragPieceCode,
|
|
30
|
-
renderPiece,
|
|
31
|
-
}: BoardDragGhostProps) {
|
|
32
|
-
const animatedStyle = useAnimatedStyle(() => {
|
|
33
|
-
if (!isDragging.value || !dragPieceCode.value) {
|
|
34
|
-
return { opacity: 0, transform: [{ translateX: 0 }, { translateY: 0 }] };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
opacity: 1,
|
|
39
|
-
// Center the piece on the finger, slightly above for visibility
|
|
40
|
-
transform: [
|
|
41
|
-
{ translateX: dragX.value - squareSize / 2 },
|
|
42
|
-
{ translateY: dragY.value - squareSize },
|
|
43
|
-
{ scale: 1.1 },
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Animated.View
|
|
50
|
-
style={[
|
|
51
|
-
{
|
|
52
|
-
position: 'absolute',
|
|
53
|
-
width: squareSize,
|
|
54
|
-
height: squareSize,
|
|
55
|
-
zIndex: 100,
|
|
56
|
-
},
|
|
57
|
-
animatedStyle,
|
|
58
|
-
]}
|
|
59
|
-
pointerEvents="none"
|
|
60
|
-
>
|
|
61
|
-
<DragGhostContent
|
|
62
|
-
renderPiece={renderPiece}
|
|
63
|
-
squareSize={squareSize}
|
|
64
|
-
dragPieceCode={dragPieceCode}
|
|
65
|
-
/>
|
|
66
|
-
</Animated.View>
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Inner content that renders the actual piece image.
|
|
72
|
-
* Separate component so the Animated.View wrapper doesn't need
|
|
73
|
-
* to re-render when the piece code changes — it uses shared value.
|
|
74
|
-
*/
|
|
75
|
-
const DragGhostContent = React.memo(function DragGhostContent({
|
|
76
|
-
renderPiece,
|
|
77
|
-
squareSize,
|
|
78
|
-
dragPieceCode,
|
|
79
|
-
}: {
|
|
80
|
-
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
81
|
-
squareSize: number;
|
|
82
|
-
dragPieceCode: SharedValue<string | null>;
|
|
83
|
-
}) {
|
|
84
|
-
// We render all 12 possible piece types and show/hide based on dragPieceCode.
|
|
85
|
-
// This avoids re-mounting the Image component during drag.
|
|
86
|
-
// Only the opacity changes — pure worklet animation.
|
|
87
|
-
const codes = PIECE_CODES;
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<>
|
|
91
|
-
{codes.map((code) => (
|
|
92
|
-
<GhostPieceSlot
|
|
93
|
-
key={code}
|
|
94
|
-
code={code}
|
|
95
|
-
squareSize={squareSize}
|
|
96
|
-
dragPieceCode={dragPieceCode}
|
|
97
|
-
renderPiece={renderPiece}
|
|
98
|
-
/>
|
|
99
|
-
))}
|
|
100
|
-
</>
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const GhostPieceSlot = React.memo(function GhostPieceSlot({
|
|
105
|
-
code,
|
|
106
|
-
squareSize,
|
|
107
|
-
dragPieceCode,
|
|
108
|
-
renderPiece,
|
|
109
|
-
}: {
|
|
110
|
-
code: string;
|
|
111
|
-
squareSize: number;
|
|
112
|
-
dragPieceCode: SharedValue<string | null>;
|
|
113
|
-
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
114
|
-
}) {
|
|
115
|
-
const animatedStyle = useAnimatedStyle(() => ({
|
|
116
|
-
opacity: dragPieceCode.value === code ? 1 : 0,
|
|
117
|
-
}));
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<Animated.View
|
|
121
|
-
style={[
|
|
122
|
-
{ position: 'absolute', width: squareSize, height: squareSize },
|
|
123
|
-
animatedStyle,
|
|
124
|
-
]}
|
|
125
|
-
>
|
|
126
|
-
{renderPiece(code, squareSize)}
|
|
127
|
-
</Animated.View>
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// All 12 piece codes — pre-computed to avoid allocation
|
|
132
|
-
const PIECE_CODES = ['wp', 'wn', 'wb', 'wr', 'wq', 'wk', 'bp', 'bn', 'bb', 'br', 'bq', 'bk'];
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Animated, {
|
|
3
|
+
useAnimatedStyle,
|
|
4
|
+
type SharedValue,
|
|
5
|
+
} from 'react-native-reanimated';
|
|
6
|
+
|
|
7
|
+
type BoardDragGhostProps = {
|
|
8
|
+
squareSize: number;
|
|
9
|
+
isDragging: SharedValue<boolean>;
|
|
10
|
+
dragX: SharedValue<number>;
|
|
11
|
+
dragY: SharedValue<number>;
|
|
12
|
+
dragPieceCode: SharedValue<string | null>;
|
|
13
|
+
/** Render the piece image for a given piece code */
|
|
14
|
+
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Floating piece that follows the user's finger during drag.
|
|
19
|
+
*
|
|
20
|
+
* Only ONE instance exists — not one per piece. It reads drag position
|
|
21
|
+
* from shared values on the UI thread, so zero JS bridge calls and
|
|
22
|
+
* zero re-renders while dragging.
|
|
23
|
+
*/
|
|
24
|
+
export const BoardDragGhost = React.memo(function BoardDragGhost({
|
|
25
|
+
squareSize,
|
|
26
|
+
isDragging,
|
|
27
|
+
dragX,
|
|
28
|
+
dragY,
|
|
29
|
+
dragPieceCode,
|
|
30
|
+
renderPiece,
|
|
31
|
+
}: BoardDragGhostProps) {
|
|
32
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
33
|
+
if (!isDragging.value || !dragPieceCode.value) {
|
|
34
|
+
return { opacity: 0, transform: [{ translateX: 0 }, { translateY: 0 }] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
opacity: 1,
|
|
39
|
+
// Center the piece on the finger, slightly above for visibility
|
|
40
|
+
transform: [
|
|
41
|
+
{ translateX: dragX.value - squareSize / 2 },
|
|
42
|
+
{ translateY: dragY.value - squareSize },
|
|
43
|
+
{ scale: 1.1 },
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Animated.View
|
|
50
|
+
style={[
|
|
51
|
+
{
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
width: squareSize,
|
|
54
|
+
height: squareSize,
|
|
55
|
+
zIndex: 100,
|
|
56
|
+
},
|
|
57
|
+
animatedStyle,
|
|
58
|
+
]}
|
|
59
|
+
pointerEvents="none"
|
|
60
|
+
>
|
|
61
|
+
<DragGhostContent
|
|
62
|
+
renderPiece={renderPiece}
|
|
63
|
+
squareSize={squareSize}
|
|
64
|
+
dragPieceCode={dragPieceCode}
|
|
65
|
+
/>
|
|
66
|
+
</Animated.View>
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Inner content that renders the actual piece image.
|
|
72
|
+
* Separate component so the Animated.View wrapper doesn't need
|
|
73
|
+
* to re-render when the piece code changes — it uses shared value.
|
|
74
|
+
*/
|
|
75
|
+
const DragGhostContent = React.memo(function DragGhostContent({
|
|
76
|
+
renderPiece,
|
|
77
|
+
squareSize,
|
|
78
|
+
dragPieceCode,
|
|
79
|
+
}: {
|
|
80
|
+
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
81
|
+
squareSize: number;
|
|
82
|
+
dragPieceCode: SharedValue<string | null>;
|
|
83
|
+
}) {
|
|
84
|
+
// We render all 12 possible piece types and show/hide based on dragPieceCode.
|
|
85
|
+
// This avoids re-mounting the Image component during drag.
|
|
86
|
+
// Only the opacity changes — pure worklet animation.
|
|
87
|
+
const codes = PIECE_CODES;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
{codes.map((code) => (
|
|
92
|
+
<GhostPieceSlot
|
|
93
|
+
key={code}
|
|
94
|
+
code={code}
|
|
95
|
+
squareSize={squareSize}
|
|
96
|
+
dragPieceCode={dragPieceCode}
|
|
97
|
+
renderPiece={renderPiece}
|
|
98
|
+
/>
|
|
99
|
+
))}
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const GhostPieceSlot = React.memo(function GhostPieceSlot({
|
|
105
|
+
code,
|
|
106
|
+
squareSize,
|
|
107
|
+
dragPieceCode,
|
|
108
|
+
renderPiece,
|
|
109
|
+
}: {
|
|
110
|
+
code: string;
|
|
111
|
+
squareSize: number;
|
|
112
|
+
dragPieceCode: SharedValue<string | null>;
|
|
113
|
+
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
114
|
+
}) {
|
|
115
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
116
|
+
opacity: dragPieceCode.value === code ? 1 : 0,
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Animated.View
|
|
121
|
+
style={[
|
|
122
|
+
{ position: 'absolute', width: squareSize, height: squareSize },
|
|
123
|
+
animatedStyle,
|
|
124
|
+
]}
|
|
125
|
+
>
|
|
126
|
+
{renderPiece(code, squareSize)}
|
|
127
|
+
</Animated.View>
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// All 12 piece codes — pre-computed to avoid allocation
|
|
132
|
+
const PIECE_CODES = ['wp', 'wn', 'wb', 'wr', 'wq', 'wk', 'bp', 'bn', 'bb', 'br', 'bq', 'bk'];
|