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
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View, Text } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import type { ChessColor, AnnotationData } from './types';
|
|
5
|
-
import { squareToXY } from './use-board-pieces';
|
|
6
|
-
import { DEFAULT_ANNOTATION_BG, DEFAULT_ANNOTATION_TEXT, ANNOTATION_SCALE } from './constants';
|
|
7
|
-
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// Props
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
type BoardAnnotationsProps = {
|
|
13
|
-
boardSize: number;
|
|
14
|
-
orientation: ChessColor;
|
|
15
|
-
squareSize: number;
|
|
16
|
-
annotations: AnnotationData[];
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Annotations layer
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Text annotation badges on chess squares (!, ?, !!, ??, etc.).
|
|
25
|
-
*
|
|
26
|
-
* Each annotation appears as a small colored badge at the top-right
|
|
27
|
-
* corner of the target square. Positioned absolutely, pointer-events none.
|
|
28
|
-
*/
|
|
29
|
-
export const BoardAnnotations = React.memo(function BoardAnnotations({
|
|
30
|
-
boardSize,
|
|
31
|
-
orientation,
|
|
32
|
-
squareSize,
|
|
33
|
-
annotations,
|
|
34
|
-
}: BoardAnnotationsProps) {
|
|
35
|
-
if (annotations.length === 0) return null;
|
|
36
|
-
|
|
37
|
-
const badgeSize = squareSize * ANNOTATION_SCALE;
|
|
38
|
-
const fontSize = badgeSize * 0.65;
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<View
|
|
42
|
-
style={{ position: 'absolute', width: boardSize, height: boardSize }}
|
|
43
|
-
pointerEvents="none"
|
|
44
|
-
>
|
|
45
|
-
{annotations.map((ann, i) => {
|
|
46
|
-
const { x, y } = squareToXY(ann.square, squareSize, orientation);
|
|
47
|
-
const bgColor = ann.backgroundColor ?? DEFAULT_ANNOTATION_BG;
|
|
48
|
-
const textColor = ann.color ?? DEFAULT_ANNOTATION_TEXT;
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<View
|
|
52
|
-
key={`ann-${ann.square}-${i}`}
|
|
53
|
-
style={{
|
|
54
|
-
position: 'absolute',
|
|
55
|
-
// Position at top-right corner of the square
|
|
56
|
-
left: x + squareSize - badgeSize - 1,
|
|
57
|
-
top: y + 1,
|
|
58
|
-
minWidth: badgeSize,
|
|
59
|
-
height: badgeSize,
|
|
60
|
-
borderRadius: badgeSize / 2,
|
|
61
|
-
backgroundColor: bgColor,
|
|
62
|
-
alignItems: 'center',
|
|
63
|
-
justifyContent: 'center',
|
|
64
|
-
paddingHorizontal: 2,
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
67
|
-
<Text
|
|
68
|
-
style={{
|
|
69
|
-
color: textColor,
|
|
70
|
-
fontSize,
|
|
71
|
-
fontWeight: '700',
|
|
72
|
-
lineHeight: badgeSize * 0.85,
|
|
73
|
-
textAlign: 'center',
|
|
74
|
-
}}
|
|
75
|
-
numberOfLines={1}
|
|
76
|
-
>
|
|
77
|
-
{ann.text}
|
|
78
|
-
</Text>
|
|
79
|
-
</View>
|
|
80
|
-
);
|
|
81
|
-
})}
|
|
82
|
-
</View>
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
// Standalone export for advanced consumers
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
|
|
90
|
-
type AnnotationBadgeProps = {
|
|
91
|
-
square: string;
|
|
92
|
-
text: string;
|
|
93
|
-
squareSize: number;
|
|
94
|
-
orientation: ChessColor;
|
|
95
|
-
color?: string;
|
|
96
|
-
backgroundColor?: string;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Single annotation badge component.
|
|
101
|
-
* Exported for consumers who build their own overlay layers.
|
|
102
|
-
*/
|
|
103
|
-
export const Annotation = React.memo(function Annotation({
|
|
104
|
-
square,
|
|
105
|
-
text,
|
|
106
|
-
squareSize,
|
|
107
|
-
orientation,
|
|
108
|
-
color,
|
|
109
|
-
backgroundColor,
|
|
110
|
-
}: AnnotationBadgeProps) {
|
|
111
|
-
const { x, y } = squareToXY(square, squareSize, orientation);
|
|
112
|
-
const badgeSize = squareSize * ANNOTATION_SCALE;
|
|
113
|
-
const fontSize = badgeSize * 0.65;
|
|
114
|
-
const bgColor = backgroundColor ?? DEFAULT_ANNOTATION_BG;
|
|
115
|
-
const textColor = color ?? DEFAULT_ANNOTATION_TEXT;
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<View
|
|
119
|
-
style={{
|
|
120
|
-
position: 'absolute',
|
|
121
|
-
left: x + squareSize - badgeSize - 1,
|
|
122
|
-
top: y + 1,
|
|
123
|
-
minWidth: badgeSize,
|
|
124
|
-
height: badgeSize,
|
|
125
|
-
borderRadius: badgeSize / 2,
|
|
126
|
-
backgroundColor: bgColor,
|
|
127
|
-
alignItems: 'center',
|
|
128
|
-
justifyContent: 'center',
|
|
129
|
-
paddingHorizontal: 2,
|
|
130
|
-
}}
|
|
131
|
-
pointerEvents="none"
|
|
132
|
-
>
|
|
133
|
-
<Text
|
|
134
|
-
style={{
|
|
135
|
-
color: textColor,
|
|
136
|
-
fontSize,
|
|
137
|
-
fontWeight: '700',
|
|
138
|
-
lineHeight: badgeSize * 0.85,
|
|
139
|
-
textAlign: 'center',
|
|
140
|
-
}}
|
|
141
|
-
numberOfLines={1}
|
|
142
|
-
>
|
|
143
|
-
{text}
|
|
144
|
-
</Text>
|
|
145
|
-
</View>
|
|
146
|
-
);
|
|
147
|
-
});
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { ChessColor, AnnotationData } from './types';
|
|
5
|
+
import { squareToXY } from './use-board-pieces';
|
|
6
|
+
import { DEFAULT_ANNOTATION_BG, DEFAULT_ANNOTATION_TEXT, ANNOTATION_SCALE } from './constants';
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Props
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
type BoardAnnotationsProps = {
|
|
13
|
+
boardSize: number;
|
|
14
|
+
orientation: ChessColor;
|
|
15
|
+
squareSize: number;
|
|
16
|
+
annotations: AnnotationData[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Annotations layer
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Text annotation badges on chess squares (!, ?, !!, ??, etc.).
|
|
25
|
+
*
|
|
26
|
+
* Each annotation appears as a small colored badge at the top-right
|
|
27
|
+
* corner of the target square. Positioned absolutely, pointer-events none.
|
|
28
|
+
*/
|
|
29
|
+
export const BoardAnnotations = React.memo(function BoardAnnotations({
|
|
30
|
+
boardSize,
|
|
31
|
+
orientation,
|
|
32
|
+
squareSize,
|
|
33
|
+
annotations,
|
|
34
|
+
}: BoardAnnotationsProps) {
|
|
35
|
+
if (annotations.length === 0) return null;
|
|
36
|
+
|
|
37
|
+
const badgeSize = squareSize * ANNOTATION_SCALE;
|
|
38
|
+
const fontSize = badgeSize * 0.65;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<View
|
|
42
|
+
style={{ position: 'absolute', width: boardSize, height: boardSize }}
|
|
43
|
+
pointerEvents="none"
|
|
44
|
+
>
|
|
45
|
+
{annotations.map((ann, i) => {
|
|
46
|
+
const { x, y } = squareToXY(ann.square, squareSize, orientation);
|
|
47
|
+
const bgColor = ann.backgroundColor ?? DEFAULT_ANNOTATION_BG;
|
|
48
|
+
const textColor = ann.color ?? DEFAULT_ANNOTATION_TEXT;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<View
|
|
52
|
+
key={`ann-${ann.square}-${i}`}
|
|
53
|
+
style={{
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
// Position at top-right corner of the square
|
|
56
|
+
left: x + squareSize - badgeSize - 1,
|
|
57
|
+
top: y + 1,
|
|
58
|
+
minWidth: badgeSize,
|
|
59
|
+
height: badgeSize,
|
|
60
|
+
borderRadius: badgeSize / 2,
|
|
61
|
+
backgroundColor: bgColor,
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
justifyContent: 'center',
|
|
64
|
+
paddingHorizontal: 2,
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<Text
|
|
68
|
+
style={{
|
|
69
|
+
color: textColor,
|
|
70
|
+
fontSize,
|
|
71
|
+
fontWeight: '700',
|
|
72
|
+
lineHeight: badgeSize * 0.85,
|
|
73
|
+
textAlign: 'center',
|
|
74
|
+
}}
|
|
75
|
+
numberOfLines={1}
|
|
76
|
+
>
|
|
77
|
+
{ann.text}
|
|
78
|
+
</Text>
|
|
79
|
+
</View>
|
|
80
|
+
);
|
|
81
|
+
})}
|
|
82
|
+
</View>
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Standalone export for advanced consumers
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
type AnnotationBadgeProps = {
|
|
91
|
+
square: string;
|
|
92
|
+
text: string;
|
|
93
|
+
squareSize: number;
|
|
94
|
+
orientation: ChessColor;
|
|
95
|
+
color?: string;
|
|
96
|
+
backgroundColor?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Single annotation badge component.
|
|
101
|
+
* Exported for consumers who build their own overlay layers.
|
|
102
|
+
*/
|
|
103
|
+
export const Annotation = React.memo(function Annotation({
|
|
104
|
+
square,
|
|
105
|
+
text,
|
|
106
|
+
squareSize,
|
|
107
|
+
orientation,
|
|
108
|
+
color,
|
|
109
|
+
backgroundColor,
|
|
110
|
+
}: AnnotationBadgeProps) {
|
|
111
|
+
const { x, y } = squareToXY(square, squareSize, orientation);
|
|
112
|
+
const badgeSize = squareSize * ANNOTATION_SCALE;
|
|
113
|
+
const fontSize = badgeSize * 0.65;
|
|
114
|
+
const bgColor = backgroundColor ?? DEFAULT_ANNOTATION_BG;
|
|
115
|
+
const textColor = color ?? DEFAULT_ANNOTATION_TEXT;
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<View
|
|
119
|
+
style={{
|
|
120
|
+
position: 'absolute',
|
|
121
|
+
left: x + squareSize - badgeSize - 1,
|
|
122
|
+
top: y + 1,
|
|
123
|
+
minWidth: badgeSize,
|
|
124
|
+
height: badgeSize,
|
|
125
|
+
borderRadius: badgeSize / 2,
|
|
126
|
+
backgroundColor: bgColor,
|
|
127
|
+
alignItems: 'center',
|
|
128
|
+
justifyContent: 'center',
|
|
129
|
+
paddingHorizontal: 2,
|
|
130
|
+
}}
|
|
131
|
+
pointerEvents="none"
|
|
132
|
+
>
|
|
133
|
+
<Text
|
|
134
|
+
style={{
|
|
135
|
+
color: textColor,
|
|
136
|
+
fontSize,
|
|
137
|
+
fontWeight: '700',
|
|
138
|
+
lineHeight: badgeSize * 0.85,
|
|
139
|
+
textAlign: 'center',
|
|
140
|
+
}}
|
|
141
|
+
numberOfLines={1}
|
|
142
|
+
>
|
|
143
|
+
{text}
|
|
144
|
+
</Text>
|
|
145
|
+
</View>
|
|
146
|
+
);
|
|
147
|
+
});
|
package/src/board-arrows.tsx
CHANGED
|
@@ -178,8 +178,8 @@ const ArrowSvg = React.memo(function ArrowSvg({
|
|
|
178
178
|
<Line
|
|
179
179
|
x1={path.x1}
|
|
180
180
|
y1={path.y1}
|
|
181
|
-
x2={path.x2}
|
|
182
|
-
y2={path.y2}
|
|
181
|
+
x2={path.x2 - ux * headSize * 2}
|
|
182
|
+
y2={path.y2 - uy * headSize * 2}
|
|
183
183
|
stroke={color}
|
|
184
184
|
strokeWidth={width}
|
|
185
185
|
strokeLinecap="round"
|
package/src/board-background.tsx
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
3
|
-
|
|
4
|
-
type BoardBackgroundProps = {
|
|
5
|
-
boardSize: number;
|
|
6
|
-
lightColor: string;
|
|
7
|
-
darkColor: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 64 static colored squares forming the chess board grid.
|
|
12
|
-
*
|
|
13
|
-
* These are plain Views with backgroundColor — no animations, no gesture
|
|
14
|
-
* handlers. They never re-render after mount unless the board theme changes.
|
|
15
|
-
*/
|
|
16
|
-
export const BoardBackground = React.memo(function BoardBackground({
|
|
17
|
-
boardSize,
|
|
18
|
-
lightColor,
|
|
19
|
-
darkColor,
|
|
20
|
-
}: BoardBackgroundProps) {
|
|
21
|
-
const squareSize = boardSize / 8;
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<View style={{ width: boardSize, height: boardSize, flexDirection: 'row', flexWrap: 'wrap' }}>
|
|
25
|
-
{SQUARE_INDICES.map((i) => {
|
|
26
|
-
const row = Math.floor(i / 8);
|
|
27
|
-
const col = i % 8;
|
|
28
|
-
const isLight = (row + col) % 2 === 0;
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<View
|
|
32
|
-
key={i}
|
|
33
|
-
style={{
|
|
34
|
-
width: squareSize,
|
|
35
|
-
height: squareSize,
|
|
36
|
-
backgroundColor: isLight ? lightColor : darkColor,
|
|
37
|
-
}}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
})}
|
|
41
|
-
</View>
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Pre-computed array of 0-63 to avoid allocation on every render
|
|
46
|
-
const SQUARE_INDICES = Array.from({ length: 64 }, (_, i) => i);
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type BoardBackgroundProps = {
|
|
5
|
+
boardSize: number;
|
|
6
|
+
lightColor: string;
|
|
7
|
+
darkColor: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 64 static colored squares forming the chess board grid.
|
|
12
|
+
*
|
|
13
|
+
* These are plain Views with backgroundColor — no animations, no gesture
|
|
14
|
+
* handlers. They never re-render after mount unless the board theme changes.
|
|
15
|
+
*/
|
|
16
|
+
export const BoardBackground = React.memo(function BoardBackground({
|
|
17
|
+
boardSize,
|
|
18
|
+
lightColor,
|
|
19
|
+
darkColor,
|
|
20
|
+
}: BoardBackgroundProps) {
|
|
21
|
+
const squareSize = boardSize / 8;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<View style={{ width: boardSize, height: boardSize, flexDirection: 'row', flexWrap: 'wrap' }}>
|
|
25
|
+
{SQUARE_INDICES.map((i) => {
|
|
26
|
+
const row = Math.floor(i / 8);
|
|
27
|
+
const col = i % 8;
|
|
28
|
+
const isLight = (row + col) % 2 === 0;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<View
|
|
32
|
+
key={i}
|
|
33
|
+
style={{
|
|
34
|
+
width: squareSize,
|
|
35
|
+
height: squareSize,
|
|
36
|
+
backgroundColor: isLight ? lightColor : darkColor,
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
})}
|
|
41
|
+
</View>
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Pre-computed array of 0-63 to avoid allocation on every render
|
|
46
|
+
const SQUARE_INDICES = Array.from({ length: 64 }, (_, i) => i);
|