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.
Files changed (91) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +187 -187
  3. package/lib/commonjs/board-annotations.js +8 -8
  4. package/lib/commonjs/board-annotations.js.map +1 -1
  5. package/lib/commonjs/board-arrows.js +7 -7
  6. package/lib/commonjs/board-arrows.js.map +1 -1
  7. package/lib/commonjs/board-background.js +5 -5
  8. package/lib/commonjs/board-background.js.map +1 -1
  9. package/lib/commonjs/board-coordinates.js.map +1 -1
  10. package/lib/commonjs/board-drag-ghost.js +10 -10
  11. package/lib/commonjs/board-drag-ghost.js.map +1 -1
  12. package/lib/commonjs/board-highlights.js +15 -15
  13. package/lib/commonjs/board-highlights.js.map +1 -1
  14. package/lib/commonjs/board-legal-dots.js +5 -5
  15. package/lib/commonjs/board-legal-dots.js.map +1 -1
  16. package/lib/commonjs/board-piece.js +25 -25
  17. package/lib/commonjs/board-piece.js.map +1 -1
  18. package/lib/commonjs/board-pieces.js +6 -6
  19. package/lib/commonjs/board-pieces.js.map +1 -1
  20. package/lib/commonjs/board.js +32 -28
  21. package/lib/commonjs/board.js.map +1 -1
  22. package/lib/commonjs/constants.js.map +1 -1
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/pieces/default-pieces.js.map +1 -1
  25. package/lib/commonjs/pieces/index.js.map +1 -1
  26. package/lib/commonjs/promotion-picker.js.map +1 -1
  27. package/lib/commonjs/static-board.js.map +1 -1
  28. package/lib/commonjs/themes.js.map +1 -1
  29. package/lib/commonjs/types.js.map +1 -1
  30. package/lib/commonjs/use-board-gesture.js.map +1 -1
  31. package/lib/commonjs/use-board-pieces.js +15 -15
  32. package/lib/commonjs/use-board-pieces.js.map +1 -1
  33. package/lib/commonjs/use-board-state.js +8 -8
  34. package/lib/commonjs/use-board-state.js.map +1 -1
  35. package/lib/commonjs/use-premove.js +12 -12
  36. package/lib/commonjs/use-premove.js.map +1 -1
  37. package/lib/module/board-annotations.js +8 -8
  38. package/lib/module/board-annotations.js.map +1 -1
  39. package/lib/module/board-arrows.js +7 -7
  40. package/lib/module/board-arrows.js.map +1 -1
  41. package/lib/module/board-background.js +5 -5
  42. package/lib/module/board-background.js.map +1 -1
  43. package/lib/module/board-coordinates.js.map +1 -1
  44. package/lib/module/board-drag-ghost.js +10 -10
  45. package/lib/module/board-drag-ghost.js.map +1 -1
  46. package/lib/module/board-highlights.js +15 -15
  47. package/lib/module/board-highlights.js.map +1 -1
  48. package/lib/module/board-legal-dots.js +5 -5
  49. package/lib/module/board-legal-dots.js.map +1 -1
  50. package/lib/module/board-piece.js +25 -25
  51. package/lib/module/board-piece.js.map +1 -1
  52. package/lib/module/board-pieces.js +6 -6
  53. package/lib/module/board-pieces.js.map +1 -1
  54. package/lib/module/board.js +32 -28
  55. package/lib/module/board.js.map +1 -1
  56. package/lib/module/constants.js.map +1 -1
  57. package/lib/module/index.js.map +1 -1
  58. package/lib/module/pieces/default-pieces.js.map +1 -1
  59. package/lib/module/pieces/index.js.map +1 -1
  60. package/lib/module/promotion-picker.js.map +1 -1
  61. package/lib/module/static-board.js.map +1 -1
  62. package/lib/module/themes.js.map +1 -1
  63. package/lib/module/types.js.map +1 -1
  64. package/lib/module/use-board-gesture.js.map +1 -1
  65. package/lib/module/use-board-pieces.js +15 -15
  66. package/lib/module/use-board-pieces.js.map +1 -1
  67. package/lib/module/use-board-state.js +8 -8
  68. package/lib/module/use-board-state.js.map +1 -1
  69. package/lib/module/use-premove.js +12 -12
  70. package/lib/module/use-premove.js.map +1 -1
  71. package/lib/typescript/types.d.ts +2 -1
  72. package/lib/typescript/types.d.ts.map +1 -1
  73. package/package.json +95 -95
  74. package/src/board-annotations.tsx +147 -147
  75. package/src/board-arrows.tsx +197 -197
  76. package/src/board-background.tsx +46 -46
  77. package/src/board-drag-ghost.tsx +132 -132
  78. package/src/board-highlights.tsx +226 -226
  79. package/src/board-legal-dots.tsx +73 -73
  80. package/src/board-piece.tsx +160 -160
  81. package/src/board-pieces.tsx +63 -63
  82. package/src/board.tsx +688 -688
  83. package/src/constants.ts +103 -103
  84. package/src/index.ts +101 -101
  85. package/src/pieces/default-pieces.tsx +383 -383
  86. package/src/pieces/index.ts +1 -1
  87. package/src/themes.ts +129 -129
  88. package/src/types.ts +394 -394
  89. package/src/use-board-pieces.ts +158 -158
  90. package/src/use-board-state.ts +120 -120
  91. package/src/use-premove.ts +59 -59
@@ -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'];