react-native-chess-kit 0.1.0 → 0.2.0
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/lib/commonjs/board-annotations.js +131 -0
- package/lib/commonjs/board-annotations.js.map +1 -0
- package/lib/commonjs/board-arrows.js +164 -0
- package/lib/commonjs/board-arrows.js.map +1 -0
- package/lib/commonjs/board-highlights.js +212 -0
- package/lib/commonjs/board-highlights.js.map +1 -0
- package/lib/commonjs/board-piece.js +41 -12
- package/lib/commonjs/board-piece.js.map +1 -1
- package/lib/commonjs/board-pieces.js +2 -0
- package/lib/commonjs/board-pieces.js.map +1 -1
- package/lib/commonjs/board.js +392 -42
- package/lib/commonjs/board.js.map +1 -1
- package/lib/commonjs/constants.js +104 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.js +128 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pieces/default-pieces.js +536 -0
- package/lib/commonjs/pieces/default-pieces.js.map +1 -0
- package/lib/commonjs/pieces/index.js +13 -0
- package/lib/commonjs/pieces/index.js.map +1 -0
- package/lib/commonjs/promotion-picker.js +129 -0
- package/lib/commonjs/promotion-picker.js.map +1 -0
- package/lib/commonjs/static-board.js +150 -0
- package/lib/commonjs/static-board.js.map +1 -0
- package/lib/commonjs/themes.js +175 -0
- package/lib/commonjs/themes.js.map +1 -0
- package/lib/commonjs/use-board-gesture.js +184 -11
- package/lib/commonjs/use-board-gesture.js.map +1 -1
- package/lib/commonjs/use-premove.js +44 -0
- package/lib/commonjs/use-premove.js.map +1 -0
- package/lib/module/board-annotations.js +126 -0
- package/lib/module/board-annotations.js.map +1 -0
- package/lib/module/board-arrows.js +161 -0
- package/lib/module/board-arrows.js.map +1 -0
- package/lib/module/board-highlights.js +206 -0
- package/lib/module/board-highlights.js.map +1 -0
- package/lib/module/board-piece.js +42 -13
- package/lib/module/board-piece.js.map +1 -1
- package/lib/module/board-pieces.js +2 -0
- package/lib/module/board-pieces.js.map +1 -1
- package/lib/module/board.js +395 -44
- package/lib/module/board.js.map +1 -1
- package/lib/module/constants.js +100 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +29 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/pieces/default-pieces.js +530 -0
- package/lib/module/pieces/default-pieces.js.map +1 -0
- package/lib/module/pieces/index.js +4 -0
- package/lib/module/pieces/index.js.map +1 -0
- package/lib/module/promotion-picker.js +124 -0
- package/lib/module/promotion-picker.js.map +1 -0
- package/lib/module/static-board.js +146 -0
- package/lib/module/static-board.js.map +1 -0
- package/lib/module/themes.js +171 -0
- package/lib/module/themes.js.map +1 -0
- package/lib/module/use-board-gesture.js +185 -11
- package/lib/module/use-board-gesture.js.map +1 -1
- package/lib/module/use-premove.js +40 -0
- package/lib/module/use-premove.js.map +1 -0
- package/lib/typescript/board-annotations.d.ts +30 -0
- package/lib/typescript/board-annotations.d.ts.map +1 -0
- package/lib/typescript/board-arrows.d.ts +27 -0
- package/lib/typescript/board-arrows.d.ts.map +1 -0
- package/lib/typescript/board-highlights.d.ts +65 -0
- package/lib/typescript/board-highlights.d.ts.map +1 -0
- package/lib/typescript/board-piece.d.ts +10 -4
- package/lib/typescript/board-piece.d.ts.map +1 -1
- package/lib/typescript/board-pieces.d.ts +2 -1
- package/lib/typescript/board-pieces.d.ts.map +1 -1
- package/lib/typescript/board.d.ts +11 -2
- package/lib/typescript/board.d.ts.map +1 -1
- package/lib/typescript/constants.d.ts +54 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pieces/default-pieces.d.ts +3 -0
- package/lib/typescript/pieces/default-pieces.d.ts.map +1 -0
- package/lib/typescript/pieces/index.d.ts +2 -0
- package/lib/typescript/pieces/index.d.ts.map +1 -0
- package/lib/typescript/promotion-picker.d.ts +30 -0
- package/lib/typescript/promotion-picker.d.ts.map +1 -0
- package/lib/typescript/static-board.d.ts +12 -0
- package/lib/typescript/static-board.d.ts.map +1 -0
- package/lib/typescript/themes.d.ts +15 -0
- package/lib/typescript/themes.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +194 -24
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/use-board-gesture.d.ts +28 -2
- package/lib/typescript/use-board-gesture.d.ts.map +1 -1
- package/lib/typescript/use-premove.d.ts +31 -0
- package/lib/typescript/use-premove.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/board-annotations.tsx +147 -0
- package/src/board-arrows.tsx +197 -0
- package/src/board-highlights.tsx +226 -0
- package/src/board-piece.tsx +50 -12
- package/src/board-pieces.tsx +4 -1
- package/src/board.tsx +462 -46
- package/src/constants.ts +100 -0
- package/src/index.ts +62 -1
- package/src/pieces/default-pieces.tsx +383 -0
- package/src/pieces/index.ts +1 -0
- package/src/promotion-picker.tsx +147 -0
- package/src/static-board.tsx +150 -0
- package/src/themes.ts +129 -0
- package/src/types.ts +251 -25
- package/src/use-board-gesture.ts +219 -8
- package/src/use-premove.ts +59 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { BoardColors } from './types';
|
|
2
|
+
/** Default board colors (chess.com green) */
|
|
3
|
+
export declare const DEFAULT_BOARD_COLORS: BoardColors;
|
|
4
|
+
/** Default last-move highlight color */
|
|
5
|
+
export declare const DEFAULT_LAST_MOVE_COLOR = "rgba(255, 255, 0, 0.4)";
|
|
6
|
+
/** Default check highlight color (red radial feel) */
|
|
7
|
+
export declare const DEFAULT_CHECK_COLOR = "rgba(235, 97, 80, 0.8)";
|
|
8
|
+
/** Default selected piece square color */
|
|
9
|
+
export declare const DEFAULT_SELECTED_COLOR = "rgba(20, 85, 200, 0.5)";
|
|
10
|
+
/** Default premove highlight color */
|
|
11
|
+
export declare const DEFAULT_PREMOVE_COLOR = "rgba(20, 85, 200, 0.3)";
|
|
12
|
+
/** Default drag target highlight color */
|
|
13
|
+
export declare const DEFAULT_DRAG_TARGET_COLOR = "rgba(0, 0, 0, 0.1)";
|
|
14
|
+
/** Default arrow color */
|
|
15
|
+
export declare const DEFAULT_ARROW_COLOR = "rgba(243, 166, 50, 0.85)";
|
|
16
|
+
/** Default shape (circle) color */
|
|
17
|
+
export declare const DEFAULT_SHAPE_COLOR = "rgba(21, 120, 27, 0.7)";
|
|
18
|
+
/** Default annotation background color */
|
|
19
|
+
export declare const DEFAULT_ANNOTATION_BG = "rgba(235, 97, 80, 0.9)";
|
|
20
|
+
/** Default annotation text color */
|
|
21
|
+
export declare const DEFAULT_ANNOTATION_TEXT = "#ffffff";
|
|
22
|
+
/** Default move animation duration in ms */
|
|
23
|
+
export declare const DEFAULT_MOVE_DURATION = 200;
|
|
24
|
+
/** Duration for capture fade-out animation in ms */
|
|
25
|
+
export declare const CAPTURE_FADE_DURATION = 150;
|
|
26
|
+
/** Legal move dot size as fraction of square size */
|
|
27
|
+
export declare const DOT_SCALE = 0.28;
|
|
28
|
+
/** Legal move capture ring size as fraction of square size */
|
|
29
|
+
export declare const RING_SCALE = 0.85;
|
|
30
|
+
/** Legal move capture ring border as fraction of square size */
|
|
31
|
+
export declare const RING_BORDER_RATIO = 0.08;
|
|
32
|
+
/** Arrow stroke width as fraction of square size (percentage-based viewBox) */
|
|
33
|
+
export declare const ARROW_STROKE_WIDTH = 2.5;
|
|
34
|
+
/** Arrow head size */
|
|
35
|
+
export declare const ARROW_HEAD_SIZE = 2.5;
|
|
36
|
+
/** Arrow shorten amount (to avoid overlapping squares) */
|
|
37
|
+
export declare const ARROW_SHORTEN_BY = 4;
|
|
38
|
+
/** Annotation badge size as fraction of square size */
|
|
39
|
+
export declare const ANNOTATION_SCALE = 0.35;
|
|
40
|
+
/** Coordinate font size as fraction of square size */
|
|
41
|
+
export declare const COORDINATE_FONT_SCALE = 0.22;
|
|
42
|
+
/** Drag ghost scale factor (1.1x larger than normal piece) */
|
|
43
|
+
export declare const DRAG_GHOST_SCALE = 1.1;
|
|
44
|
+
/** Promotion picker piece padding as fraction of square size */
|
|
45
|
+
export declare const PROMOTION_PIECE_PADDING = 0.1;
|
|
46
|
+
export declare const PIECE_CODES: readonly ["wp", "wn", "wb", "wr", "wq", "wk", "bp", "bn", "bb", "br", "bq", "bk"];
|
|
47
|
+
/** Board square indices 0-63 (pre-computed) */
|
|
48
|
+
export declare const SQUARE_INDICES: number[];
|
|
49
|
+
/** File letters in order */
|
|
50
|
+
export declare const FILES_WHITE: readonly ["a", "b", "c", "d", "e", "f", "g", "h"];
|
|
51
|
+
export declare const FILES_BLACK: readonly ["h", "g", "f", "e", "d", "c", "b", "a"];
|
|
52
|
+
export declare const RANKS_WHITE: readonly ["8", "7", "6", "5", "4", "3", "2", "1"];
|
|
53
|
+
export declare const RANKS_BLACK: readonly ["1", "2", "3", "4", "5", "6", "7", "8"];
|
|
54
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM3C,6CAA6C;AAC7C,eAAO,MAAM,oBAAoB,EAAE,WAGlC,CAAC;AAEF,wCAAwC;AACxC,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAEhE,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D,sCAAsC;AACtC,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAE9D,0CAA0C;AAC1C,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAE9D,0BAA0B;AAC1B,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAE9D,mCAAmC;AACnC,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAE9D,oCAAoC;AACpC,eAAO,MAAM,uBAAuB,YAAY,CAAC;AAMjD,4CAA4C;AAC5C,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,oDAAoD;AACpD,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAMzC,qDAAqD;AACrD,eAAO,MAAM,SAAS,OAAO,CAAC;AAE9B,8DAA8D;AAC9D,eAAO,MAAM,UAAU,OAAO,CAAC;AAE/B,gEAAgE;AAChE,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,sBAAsB;AACtB,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,gEAAgE;AAChE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAM3C,eAAO,MAAM,WAAW,mFAGd,CAAC;AAEX,+CAA+C;AAC/C,eAAO,MAAM,cAAc,UAA0C,CAAC;AAEtE,4BAA4B;AAC5B,eAAO,MAAM,WAAW,mDAAoD,CAAC;AAC7E,eAAO,MAAM,WAAW,mDAAoD,CAAC;AAC7E,eAAO,MAAM,WAAW,mDAAoD,CAAC;AAC7E,eAAO,MAAM,WAAW,mDAAoD,CAAC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export { Board } from './board';
|
|
2
|
-
export
|
|
2
|
+
export { StaticBoard } from './static-board';
|
|
3
|
+
export { SquareHighlight } from './board-highlights';
|
|
4
|
+
export { Arrow } from './board-arrows';
|
|
5
|
+
export { Annotation } from './board-annotations';
|
|
6
|
+
export { PromotionPicker } from './promotion-picker';
|
|
7
|
+
export { DefaultPieceSet } from './pieces';
|
|
8
|
+
export { BOARD_THEMES, BOARD_COLORS } from './themes';
|
|
9
|
+
export { DEFAULT_BOARD_COLORS, DEFAULT_LAST_MOVE_COLOR, DEFAULT_CHECK_COLOR, DEFAULT_SELECTED_COLOR, DEFAULT_PREMOVE_COLOR, DEFAULT_DRAG_TARGET_COLOR, DEFAULT_ARROW_COLOR, DEFAULT_SHAPE_COLOR, DEFAULT_ANNOTATION_BG, DEFAULT_ANNOTATION_TEXT, DEFAULT_MOVE_DURATION, CAPTURE_FADE_DURATION, } from './constants';
|
|
10
|
+
export type { ChessColor, MoveMethod, PromotionPiece, HapticType, PieceCode, BoardRef, BoardProps, BoardColors, StaticBoardProps, BoardPiece, ParsedPiece, PieceSetMap, HighlightData, ArrowData, ShapeData, AnnotationData, PremoveData, AnimationConfig, TimingAnimationConfig, SpringAnimationConfig, BoardTheme, GestureState, LegalMoveTarget, } from './types';
|
|
3
11
|
export { squareToXY, xyToSquare } from './use-board-pieces';
|
|
4
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAM7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMrD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMtD,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAMrB,YAAY,EAEV,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EAGT,QAAQ,EACR,UAAU,EACV,WAAW,EACX,gBAAgB,EAGhB,UAAU,EACV,WAAW,EACX,WAAW,EAGX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,WAAW,EAGX,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EAGrB,UAAU,EAGV,YAAY,EAGZ,eAAe,GAChB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-pieces.d.ts","sourceRoot":"","sources":["../../../src/pieces/default-pieces.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA+W5C,eAAO,MAAM,eAAe,EAAE,WAa7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pieces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChessColor, PromotionPiece } from './types';
|
|
3
|
+
type PromotionPickerProps = {
|
|
4
|
+
/** Square the pawn is promoting on */
|
|
5
|
+
square: string;
|
|
6
|
+
/** Color of the promoting pawn */
|
|
7
|
+
pieceColor: 'w' | 'b';
|
|
8
|
+
/** Board size in pixels */
|
|
9
|
+
boardSize: number;
|
|
10
|
+
squareSize: number;
|
|
11
|
+
orientation: ChessColor;
|
|
12
|
+
/** Piece renderer (from renderPiece prop or pieceSet) */
|
|
13
|
+
renderPiece: (code: string, size: number) => React.ReactElement;
|
|
14
|
+
/** Called when user picks a promotion piece */
|
|
15
|
+
onSelect: (piece: PromotionPiece) => void;
|
|
16
|
+
/** Called when user cancels (taps outside) */
|
|
17
|
+
onCancel: () => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Promotion piece picker overlay.
|
|
21
|
+
*
|
|
22
|
+
* Appears as a vertical column of 4 pieces (Q, R, B, N) anchored to the
|
|
23
|
+
* promotion square. Expands downward when promoting on the top edge,
|
|
24
|
+
* upward when promoting on the bottom edge.
|
|
25
|
+
*
|
|
26
|
+
* A semi-transparent backdrop covers the board. Tapping outside cancels.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PromotionPicker: React.NamedExoticComponent<PromotionPickerProps>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=promotion-picker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion-picker.d.ts","sourceRoot":"","sources":["../../src/promotion-picker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAe,MAAM,SAAS,CAAC;AAQvE,KAAK,oBAAoB,GAAG;IAC1B,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,UAAU,EAAE,GAAG,GAAG,GAAG,CAAC;IACtB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,UAAU,CAAC;IACxB,yDAAyD;IACzD,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,YAAY,CAAC;IAChE,+CAA+C;IAC/C,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAgBF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,kDAwF1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StaticBoardProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Non-interactive chess board — optimized for lists, thumbnails, and analysis previews.
|
|
5
|
+
*
|
|
6
|
+
* No gesture handler, no drag ghost, no legal move dots.
|
|
7
|
+
* Just: background + coordinates + highlights + pieces + arrows + annotations.
|
|
8
|
+
*
|
|
9
|
+
* Significantly lighter than the full Board component.
|
|
10
|
+
*/
|
|
11
|
+
export declare const StaticBoard: React.NamedExoticComponent<StaticBoardProps>;
|
|
12
|
+
//# sourceMappingURL=static-board.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-board.d.ts","sourceRoot":"","sources":["../../src/static-board.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAG9D,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,SAAS,CAAC;AAUvE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,8CAgItB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BoardTheme, BoardColors } from './types';
|
|
2
|
+
/** All built-in board themes */
|
|
3
|
+
export declare const BOARD_THEMES: {
|
|
4
|
+
readonly green: BoardTheme;
|
|
5
|
+
readonly brown: BoardTheme;
|
|
6
|
+
readonly blue: BoardTheme;
|
|
7
|
+
readonly purple: BoardTheme;
|
|
8
|
+
readonly gray: BoardTheme;
|
|
9
|
+
readonly wood: BoardTheme;
|
|
10
|
+
readonly ice: BoardTheme;
|
|
11
|
+
readonly tournament: BoardTheme;
|
|
12
|
+
};
|
|
13
|
+
/** Shorthand board color presets (just light/dark, no overlay colors) */
|
|
14
|
+
export declare const BOARD_COLORS: Record<keyof typeof BOARD_THEMES, BoardColors>;
|
|
15
|
+
//# sourceMappingURL=themes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themes.d.ts","sourceRoot":"","sources":["../../src/themes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA0GvD,gCAAgC;AAChC,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAC;AAEX,yEAAyE;AACzE,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,OAAO,YAAY,EAAE,WAAW,CASvE,CAAC"}
|
|
@@ -3,6 +3,12 @@ import type { SharedValue } from 'react-native-reanimated';
|
|
|
3
3
|
export type ChessColor = 'white' | 'black';
|
|
4
4
|
/** How the user interacts with pieces */
|
|
5
5
|
export type MoveMethod = 'drag' | 'click' | 'both';
|
|
6
|
+
/** Promotion piece choice */
|
|
7
|
+
export type PromotionPiece = 'q' | 'r' | 'b' | 'n';
|
|
8
|
+
/** Haptic feedback event types -- consumer wires to their preferred haptics library */
|
|
9
|
+
export type HapticType = 'select' | 'move' | 'capture' | 'error';
|
|
10
|
+
/** Standard piece codes used throughout the library */
|
|
11
|
+
export type PieceCode = 'wp' | 'wn' | 'wb' | 'wr' | 'wq' | 'wk' | 'bp' | 'bn' | 'bb' | 'br' | 'bq' | 'bk';
|
|
6
12
|
/** A single piece on the board with its position and identity */
|
|
7
13
|
export type BoardPiece = {
|
|
8
14
|
/** Unique stable identifier (survives position changes): e.g. "wp-0", "bk-0" */
|
|
@@ -20,13 +26,94 @@ export type ParsedPiece = {
|
|
|
20
26
|
square: string;
|
|
21
27
|
color: 'w' | 'b';
|
|
22
28
|
};
|
|
29
|
+
/** A square highlight (colored rectangle on a specific square) */
|
|
30
|
+
export type HighlightData = {
|
|
31
|
+
square: string;
|
|
32
|
+
color: string;
|
|
33
|
+
};
|
|
34
|
+
/** An arrow drawn between two squares */
|
|
35
|
+
export type ArrowData = {
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
/** Arrow color. Default: theme-dependent */
|
|
39
|
+
color?: string;
|
|
40
|
+
/** Stroke width as percentage of square size. Default: 0.2 */
|
|
41
|
+
width?: number;
|
|
42
|
+
};
|
|
43
|
+
/** A shape drawn on the board */
|
|
44
|
+
export type ShapeData = {
|
|
45
|
+
type: 'circle';
|
|
46
|
+
square: string;
|
|
47
|
+
color?: string;
|
|
48
|
+
};
|
|
49
|
+
/** A text annotation on a square (!, ?, !!, ??, etc.) */
|
|
50
|
+
export type AnnotationData = {
|
|
51
|
+
square: string;
|
|
52
|
+
text: string;
|
|
53
|
+
color?: string;
|
|
54
|
+
backgroundColor?: string;
|
|
55
|
+
};
|
|
56
|
+
/** A premove queued for execution */
|
|
57
|
+
export type PremoveData = {
|
|
58
|
+
from: string;
|
|
59
|
+
to: string;
|
|
60
|
+
promotion?: PromotionPiece;
|
|
61
|
+
};
|
|
62
|
+
export type TimingAnimationConfig = {
|
|
63
|
+
type: 'timing';
|
|
64
|
+
/** Duration in ms. Default: 200 */
|
|
65
|
+
duration?: number;
|
|
66
|
+
};
|
|
67
|
+
export type SpringAnimationConfig = {
|
|
68
|
+
type: 'spring';
|
|
69
|
+
/** Damping ratio. Default: 0.7 */
|
|
70
|
+
damping?: number;
|
|
71
|
+
/** Stiffness. Default: 200 */
|
|
72
|
+
stiffness?: number;
|
|
73
|
+
/** Mass. Default: 1 */
|
|
74
|
+
mass?: number;
|
|
75
|
+
};
|
|
76
|
+
/** Animation configuration for piece movement */
|
|
77
|
+
export type AnimationConfig = TimingAnimationConfig | SpringAnimationConfig;
|
|
78
|
+
/** Map of piece code to React element renderer */
|
|
79
|
+
export type PieceSetMap = {
|
|
80
|
+
[code in PieceCode]: (size: number) => React.ReactElement;
|
|
81
|
+
};
|
|
82
|
+
export type BoardColors = {
|
|
83
|
+
light: string;
|
|
84
|
+
dark: string;
|
|
85
|
+
};
|
|
86
|
+
/** A complete board theme with all configurable colors */
|
|
87
|
+
export type BoardTheme = {
|
|
88
|
+
/** Display name for the theme */
|
|
89
|
+
name: string;
|
|
90
|
+
/** Square colors */
|
|
91
|
+
board: BoardColors;
|
|
92
|
+
/** Last move highlight color */
|
|
93
|
+
lastMove: string;
|
|
94
|
+
/** Check highlight color */
|
|
95
|
+
check: string;
|
|
96
|
+
/** Selected piece square color */
|
|
97
|
+
selected: string;
|
|
98
|
+
/** Legal move dot color */
|
|
99
|
+
legalDot: string;
|
|
100
|
+
/** Premove highlight color */
|
|
101
|
+
premove: string;
|
|
102
|
+
/** Arrow default color */
|
|
103
|
+
arrow: string;
|
|
104
|
+
/** Coordinate text colors */
|
|
105
|
+
coordinates: {
|
|
106
|
+
light: string;
|
|
107
|
+
dark: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
23
110
|
export type BoardRef = {
|
|
24
111
|
/** Pre-apply a move to internal state. Visual animation happens when parent updates the FEN prop. */
|
|
25
112
|
move: (move: {
|
|
26
113
|
from: string;
|
|
27
114
|
to: string;
|
|
28
115
|
}) => void;
|
|
29
|
-
/** Highlight a square with a color */
|
|
116
|
+
/** Highlight a square with a color. Adds to existing imperative highlights. */
|
|
30
117
|
highlight: (square: string, color: string) => void;
|
|
31
118
|
/** Clear all imperative highlights */
|
|
32
119
|
clearHighlights: () => void;
|
|
@@ -34,41 +121,122 @@ export type BoardRef = {
|
|
|
34
121
|
resetBoard: (fen: string) => void;
|
|
35
122
|
/** Undo the last visually applied move (snap back to previous position) */
|
|
36
123
|
undo: () => void;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
light: string;
|
|
40
|
-
dark: string;
|
|
124
|
+
/** Clear any queued premoves */
|
|
125
|
+
clearPremoves: () => void;
|
|
41
126
|
};
|
|
42
127
|
export type BoardProps = {
|
|
43
128
|
/** Current board position in FEN notation */
|
|
44
129
|
fen: string;
|
|
45
130
|
/** Which color is at the bottom of the board */
|
|
46
131
|
orientation: ChessColor;
|
|
47
|
-
/** Board width/height in pixels */
|
|
48
|
-
boardSize
|
|
49
|
-
/** Whether gesture interaction is enabled */
|
|
50
|
-
gestureEnabled
|
|
51
|
-
/** Which side can interact: 'white', 'black', or 'both' */
|
|
52
|
-
player
|
|
132
|
+
/** Board width/height in pixels. If omitted, auto-sizes from parent via onLayout. */
|
|
133
|
+
boardSize?: number;
|
|
134
|
+
/** Whether gesture interaction is enabled. Default: true */
|
|
135
|
+
gestureEnabled?: boolean;
|
|
136
|
+
/** Which side can interact: 'white', 'black', or 'both'. Default: 'both' */
|
|
137
|
+
player?: ChessColor | 'both';
|
|
138
|
+
/** How the user moves pieces. Default: 'both' */
|
|
139
|
+
moveMethod?: MoveMethod;
|
|
140
|
+
/** Whether to show legal move dots when a piece is selected. Default: true */
|
|
141
|
+
showLegalMoves?: boolean;
|
|
142
|
+
/** Enable premove queuing. Default: false */
|
|
143
|
+
premovesEnabled?: boolean;
|
|
144
|
+
/** Board square colors. Default: green theme */
|
|
145
|
+
colors?: BoardColors;
|
|
146
|
+
/** Whether to show file labels (a-h). Default: true */
|
|
147
|
+
withLetters?: boolean;
|
|
148
|
+
/** Whether to show rank numbers (1-8). Default: true */
|
|
149
|
+
withNumbers?: boolean;
|
|
150
|
+
/** Custom piece renderer. Receives piece code ('wp', 'bk', etc.) and pixel size. */
|
|
151
|
+
renderPiece?: (pieceCode: string, size: number) => React.ReactElement;
|
|
152
|
+
/** Built-in piece set (alternative to renderPiece). Default: built-in SVG set */
|
|
153
|
+
pieceSet?: PieceSetMap;
|
|
154
|
+
/** Last move to highlight (yellow on from/to squares) */
|
|
155
|
+
lastMove?: {
|
|
156
|
+
from: string;
|
|
157
|
+
to: string;
|
|
158
|
+
} | null;
|
|
159
|
+
/** Custom highlights. Merged with auto-highlights (last move, check). */
|
|
160
|
+
highlights?: HighlightData[];
|
|
161
|
+
/** Arrows to draw on the board */
|
|
162
|
+
arrows?: ArrowData[];
|
|
163
|
+
/** Shapes to draw on the board (circles) */
|
|
164
|
+
shapes?: ShapeData[];
|
|
165
|
+
/** Text annotations on squares (!, ?, etc.) */
|
|
166
|
+
annotations?: AnnotationData[];
|
|
167
|
+
/** Show drag target indicator under finger during drag. Default: true */
|
|
168
|
+
showDragTarget?: boolean;
|
|
169
|
+
/** Last move highlight color. Default: 'rgba(255,255,0,0.4)' */
|
|
170
|
+
lastMoveColor?: string;
|
|
171
|
+
/** Check highlight color. Default: radial gradient red */
|
|
172
|
+
checkHighlightColor?: string;
|
|
173
|
+
/** Selected piece square color. Default: 'rgba(20,85,200,0.5)' */
|
|
174
|
+
selectedSquareColor?: string;
|
|
175
|
+
/** Premove highlight color. Default: 'rgba(20,85,200,0.3)' */
|
|
176
|
+
premoveColor?: string;
|
|
177
|
+
/** Drag target highlight color. Default: 'rgba(0,0,0,0.1)' */
|
|
178
|
+
dragTargetColor?: string;
|
|
179
|
+
/** Move animation duration in ms (0 = instant). Default: 200 */
|
|
180
|
+
moveDuration?: number;
|
|
181
|
+
/** Animation configuration (timing or spring). Overrides moveDuration if provided. */
|
|
182
|
+
animationConfig?: AnimationConfig;
|
|
183
|
+
/** Animate board rotation on orientation change. Default: true */
|
|
184
|
+
animateFlip?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Called when a pawn promotion occurs. If not provided, auto-promotes to queen.
|
|
187
|
+
* Return the chosen piece to complete the promotion.
|
|
188
|
+
*/
|
|
189
|
+
onPromotion?: (from: string, to: string) => Promise<PromotionPiece> | PromotionPiece;
|
|
53
190
|
/** Called after a visual move is applied */
|
|
54
191
|
onMove?: (info: {
|
|
55
192
|
from: string;
|
|
56
193
|
to: string;
|
|
57
194
|
}) => void;
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
/**
|
|
195
|
+
/** Called when a piece is tapped */
|
|
196
|
+
onPieceClick?: (square: string, piece: PieceCode) => void;
|
|
197
|
+
/** Called when an empty square or opponent piece is tapped */
|
|
198
|
+
onSquareClick?: (square: string) => void;
|
|
199
|
+
/** Called when a piece drag begins */
|
|
200
|
+
onPieceDragBegin?: (square: string, piece: PieceCode) => void;
|
|
201
|
+
/** Called when a piece drag ends (regardless of move validity) */
|
|
202
|
+
onPieceDragEnd?: (square: string, piece: PieceCode) => void;
|
|
203
|
+
/** Called on long-press of a square */
|
|
204
|
+
onSquareLongPress?: (square: string) => void;
|
|
205
|
+
/** Called when a premove is set */
|
|
206
|
+
onPremove?: (premove: PremoveData) => void;
|
|
207
|
+
/**
|
|
208
|
+
* Haptic feedback callback. Consumer wires to their preferred haptics library.
|
|
209
|
+
* Called with event type: 'select' (piece pickup), 'move' (piece drop),
|
|
210
|
+
* 'capture' (piece takes), 'error' (invalid move).
|
|
211
|
+
*/
|
|
212
|
+
onHaptic?: (type: HapticType) => void;
|
|
213
|
+
};
|
|
214
|
+
export type StaticBoardProps = {
|
|
215
|
+
/** Board position in FEN notation */
|
|
216
|
+
fen: string;
|
|
217
|
+
/** Which color is at the bottom. Default: 'white' */
|
|
218
|
+
orientation?: ChessColor;
|
|
219
|
+
/** Board width/height in pixels. If omitted, auto-sizes from parent. */
|
|
220
|
+
boardSize?: number;
|
|
221
|
+
/** Board square colors. Default: green theme */
|
|
222
|
+
colors?: BoardColors;
|
|
223
|
+
/** Whether to show coordinate labels. Default: false */
|
|
224
|
+
withCoordinates?: boolean;
|
|
225
|
+
/** Custom piece renderer */
|
|
67
226
|
renderPiece?: (pieceCode: string, size: number) => React.ReactElement;
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
227
|
+
/** Built-in piece set */
|
|
228
|
+
pieceSet?: PieceSetMap;
|
|
229
|
+
/** Last move highlight */
|
|
230
|
+
lastMove?: {
|
|
231
|
+
from: string;
|
|
232
|
+
to: string;
|
|
233
|
+
} | null;
|
|
234
|
+
/** Custom highlights */
|
|
235
|
+
highlights?: HighlightData[];
|
|
236
|
+
/** Arrows */
|
|
237
|
+
arrows?: ArrowData[];
|
|
238
|
+
/** Annotations */
|
|
239
|
+
annotations?: AnnotationData[];
|
|
72
240
|
};
|
|
73
241
|
export type GestureState = {
|
|
74
242
|
/** Square the active piece started from (null if no drag/selection) */
|
|
@@ -80,6 +248,8 @@ export type GestureState = {
|
|
|
80
248
|
isDragging: SharedValue<boolean>;
|
|
81
249
|
/** The piece code being dragged (for rendering the ghost) */
|
|
82
250
|
dragPieceCode: SharedValue<string | null>;
|
|
251
|
+
/** Square currently under the dragged piece (for drag target highlight) */
|
|
252
|
+
dragTargetSquare: SharedValue<string | null>;
|
|
83
253
|
};
|
|
84
254
|
export type LegalMoveTarget = {
|
|
85
255
|
square: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAM3D,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3C,yCAAyC;AACzC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAM3D,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3C,yCAAyC;AACzC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEnD,6BAA6B;AAC7B,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEnD,uFAAuF;AACvF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,G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E,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC/C,wBAAwB;IACxB,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,aAAa;IACb,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,kBAAkB;IAClB,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;CAChC,CAAC;AAMF,MAAM,MAAM,YAAY,GAAG;IACzB,uEAAuE;IACvE,YAAY,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,kDAAkD;IAClD,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,iDAAiD;IACjD,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,6DAA6D;IAC7D,aAAa,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC1C,2EAA2E;IAC3E,gBAAgB,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9C,CAAC;AAMF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { Gesture } from 'react-native-gesture-handler';
|
|
2
|
-
import type { ChessColor, MoveMethod, BoardPiece, LegalMoveTarget, GestureState } from './types';
|
|
2
|
+
import type { ChessColor, MoveMethod, BoardPiece, LegalMoveTarget, GestureState, PieceCode, HapticType, PremoveData } from './types';
|
|
3
3
|
type GestureCallbacks = {
|
|
4
4
|
onPieceSelected: (square: string) => void;
|
|
5
5
|
onPieceMoved: (from: string, to: string) => void;
|
|
6
6
|
onSelectionCleared: () => void;
|
|
7
7
|
};
|
|
8
|
+
/** Rich callbacks exposed to consumers (all optional) */
|
|
9
|
+
type RichCallbacks = {
|
|
10
|
+
onPieceClick?: (square: string, piece: PieceCode) => void;
|
|
11
|
+
onSquareClick?: (square: string) => void;
|
|
12
|
+
onPieceDragBegin?: (square: string, piece: PieceCode) => void;
|
|
13
|
+
onPieceDragEnd?: (square: string, piece: PieceCode) => void;
|
|
14
|
+
onSquareLongPress?: (square: string) => void;
|
|
15
|
+
onHaptic?: (type: HapticType) => void;
|
|
16
|
+
};
|
|
17
|
+
/** Premove-related callbacks from board.tsx */
|
|
18
|
+
type PremoveCallbacks = {
|
|
19
|
+
onPremoveSet?: (premove: PremoveData) => void;
|
|
20
|
+
};
|
|
8
21
|
type UseBoardGestureParams = {
|
|
9
22
|
squareSize: number;
|
|
10
23
|
orientation: ChessColor;
|
|
@@ -13,10 +26,16 @@ type UseBoardGestureParams = {
|
|
|
13
26
|
moveMethod: MoveMethod;
|
|
14
27
|
pieces: BoardPiece[];
|
|
15
28
|
callbacks: GestureCallbacks;
|
|
29
|
+
richCallbacks?: RichCallbacks;
|
|
30
|
+
premoveCallbacks?: PremoveCallbacks;
|
|
31
|
+
/** Whether premoves are enabled */
|
|
32
|
+
premovesEnabled?: boolean;
|
|
16
33
|
/** Currently selected square (for tap-to-move second tap) */
|
|
17
34
|
selectedSquare: string | null;
|
|
18
35
|
/** Legal move targets from the currently selected piece */
|
|
19
36
|
legalMoves: LegalMoveTarget[];
|
|
37
|
+
/** Whose turn it is ('w' or 'b') — used for premove detection */
|
|
38
|
+
currentTurn?: 'w' | 'b';
|
|
20
39
|
};
|
|
21
40
|
type UseBoardGestureReturn = {
|
|
22
41
|
gesture: ReturnType<typeof Gesture.Pan>;
|
|
@@ -40,7 +59,14 @@ type UseBoardGestureReturn = {
|
|
|
40
59
|
* gestureEnabled, player, or moveMethod change). Frequently-changing data
|
|
41
60
|
* (pieces, selectedSquare, legalMoves) is read from refs via runOnJS bridge
|
|
42
61
|
* functions, avoiding costly gesture teardown/rebuild on every move.
|
|
62
|
+
*
|
|
63
|
+
* v0.2.0 additions:
|
|
64
|
+
* - Rich callbacks (onPieceClick, onSquareClick, onPieceDragBegin, onPieceDragEnd)
|
|
65
|
+
* - Drag target square tracking (shared value for DragTargetHighlight)
|
|
66
|
+
* - Premove support (queue move when not your turn)
|
|
67
|
+
* - Haptic feedback via callback
|
|
68
|
+
* - Long press detection for onSquareLongPress
|
|
43
69
|
*/
|
|
44
|
-
export declare function useBoardGesture({ squareSize, orientation, gestureEnabled, player, moveMethod, pieces, callbacks, selectedSquare, legalMoves, }: UseBoardGestureParams): UseBoardGestureReturn;
|
|
70
|
+
export declare function useBoardGesture({ squareSize, orientation, gestureEnabled, player, moveMethod, pieces, callbacks, richCallbacks, premoveCallbacks, premovesEnabled, selectedSquare, legalMoves, currentTurn, }: UseBoardGestureParams): UseBoardGestureReturn;
|
|
45
71
|
export {};
|
|
46
72
|
//# sourceMappingURL=use-board-gesture.d.ts.map
|
|
@@ -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,
|
|
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,K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G;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,CAwR/C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PremoveData } from './types';
|
|
2
|
+
type UsePremoveReturn = {
|
|
3
|
+
/** The currently queued premove (only one at a time, like lichess) */
|
|
4
|
+
premove: PremoveData | null;
|
|
5
|
+
/** Queue a premove. Replaces any existing premove. */
|
|
6
|
+
setPremove: (premove: PremoveData) => void;
|
|
7
|
+
/** Clear the queued premove */
|
|
8
|
+
clearPremove: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* Try to execute the queued premove.
|
|
11
|
+
* Returns the premove if one was queued (so the caller can apply it),
|
|
12
|
+
* then clears the queue. Returns null if no premove was queued.
|
|
13
|
+
*/
|
|
14
|
+
consumePremove: () => PremoveData | null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Manages a single premove queue (one premove at a time).
|
|
18
|
+
*
|
|
19
|
+
* Premoves work like lichess:
|
|
20
|
+
* 1. When it's not your turn, you can drag/click a move — it queues as a premove
|
|
21
|
+
* 2. The premove squares are highlighted with a distinct color
|
|
22
|
+
* 3. When your turn begins (FEN changes and it's now your turn), the premove
|
|
23
|
+
* is automatically attempted via the board's internal chess.js
|
|
24
|
+
* 4. If the premove is legal, it's applied; if not, it's silently discarded
|
|
25
|
+
*
|
|
26
|
+
* The board.tsx orchestrates this: it calls consumePremove() in a useEffect
|
|
27
|
+
* that watches the FEN (turn change), then attempts the move.
|
|
28
|
+
*/
|
|
29
|
+
export declare function usePremove(): UsePremoveReturn;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=use-premove.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-premove.d.ts","sourceRoot":"","sources":["../../src/use-premove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,gBAAgB,GAAG;IACtB,sEAAsE;IACtE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,sDAAsD;IACtD,UAAU,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC3C,+BAA+B;IAC/B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB;;;;OAIG;IACH,cAAc,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CA0B7C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-chess-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"react": ">=18.0.0",
|
|
45
45
|
"react-native": ">=0.70.0",
|
|
46
46
|
"react-native-gesture-handler": ">=2.0.0",
|
|
47
|
-
"react-native-reanimated": ">=3.0.0"
|
|
47
|
+
"react-native-reanimated": ">=3.0.0",
|
|
48
|
+
"react-native-svg": ">=13.0.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@types/react": "~19.1.0",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"react-native-builder-bob": "^0.35.0",
|
|
55
56
|
"react-native-gesture-handler": "~2.28.0",
|
|
56
57
|
"react-native-reanimated": "~4.1.1",
|
|
58
|
+
"react-native-svg": "~15.11.2",
|
|
57
59
|
"typescript": "~5.9.2"
|
|
58
60
|
},
|
|
59
61
|
"react-native-builder-bob": {
|