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
|
@@ -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
|
+
});
|