react-chess-core 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,46 +1,48 @@
1
- # react-chess-core
2
-
3
- ```bash
4
- npm install
5
- npm run build
6
- ```
7
-
8
- Shared **chessboard** (theme + `HighlightChessboard`) and **browser Stockfish** utilities. Used by `react-chess-puzzle-kit` and (planned) `react-chess-explorer`.
9
-
10
- Storybook: `npm run storybook` → http://localhost:6007
11
-
12
- ---
13
-
14
- ## Migration phases (Option B)
15
-
16
- | Phase | Status | Work |
17
- |-------|--------|------|
18
- | **1** | Done | Scaffold package, Rollup, Storybook |
19
- | **2** | Done | Board + engine source live in this repo |
20
- | **3** | Done | `react-chess-puzzle-kit` depends on `file:../react-chess-core`, re-export for compatibility |
21
- | **4** | Done | Remove duplicate shim files from puzzle-kit; slim public API (no core re-exports from puzzle-kit) |
22
- | **5** | In progress | `react-chess-explorer` scaffold (core only); requirements `docs/REQUIREMENTS.md` |
23
-
24
- ---
25
-
26
- ## Install (consumers)
27
-
28
- ```bash
29
- npm install react-chess-core
30
- ```
31
-
32
- **Peer dependencies:** `react`, `react-chessboard`, `chess.js`
33
-
34
- For Stockfish in the browser:
35
-
36
- ```bash
37
- npm install stockfish
38
- npm run copy:stockfish # in your app, or copy WASM to public/stockfish/
39
- ```
40
-
41
- ---
42
-
43
- ## Exports
44
-
45
- - **Chessboard:** `ThemeProvider`, `useChessboardTheme`, `HighlightChessboard`, `boardSquareHighlightColors`
46
- - **Engine:** `useAnalysisEngine`, `StockfishBrowserEngine`, `EngineEvaluationPanel`, `isAnalyzableFen`, types/helpers
1
+ # react-chess-core
2
+
3
+ ```bash
4
+ npm install
5
+ npm run build
6
+ ```
7
+
8
+ Shared **chessboard** (theme + `HighlightChessboard`) and **browser Stockfish** utilities. Used by `react-chess-puzzle-kit` and (planned) `react-chess-explorer`.
9
+
10
+ Used in production at [endchess.com](https://endchess.com).
11
+
12
+ Storybook: `npm run storybook` → http://localhost:6007
13
+
14
+ ---
15
+
16
+ ## Migration phases (Option B)
17
+
18
+ | Phase | Status | Work |
19
+ |-------|--------|------|
20
+ | **1** | Done | Scaffold package, Rollup, Storybook |
21
+ | **2** | Done | Board + engine source live in this repo |
22
+ | **3** | Done | `react-chess-puzzle-kit` depends on `file:../react-chess-core`, re-export for compatibility |
23
+ | **4** | Done | Remove duplicate shim files from puzzle-kit; slim public API (no core re-exports from puzzle-kit) |
24
+ | **5** | In progress | `react-chess-explorer` scaffold (core only); requirements → `docs/REQUIREMENTS.md` |
25
+
26
+ ---
27
+
28
+ ## Install (consumers)
29
+
30
+ ```bash
31
+ npm install react-chess-core
32
+ ```
33
+
34
+ **Peer dependencies:** `react`, `react-chessboard`, `chess.js`
35
+
36
+ For Stockfish in the browser:
37
+
38
+ ```bash
39
+ npm install stockfish
40
+ npm run copy:stockfish # in your app, or copy WASM to public/stockfish/
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Exports
46
+
47
+ - **Chessboard:** `ThemeProvider`, `useChessboardTheme`, `HighlightChessboard`, `boardSquareHighlightColors`
48
+ - **Engine:** `useAnalysisEngine`, `StockfishBrowserEngine`, `EngineEvaluationPanel`, `isAnalyzableFen`, types/helpers
@@ -1,4 +1,9 @@
1
1
  import type { ReactNode } from 'react';
2
+ /**
3
+ * HTML5 for mouse (desktop + Chrome device emulation), touch backend for real
4
+ * mobile devices. react-chessboard alone picks TouchBackend whenever
5
+ * `ontouchstart` is in window, which breaks mouse drags in DevTools emulation.
6
+ */
2
7
  export declare const ChessboardDnDProvider: ({ children, }: {
3
8
  children: ReactNode;
4
9
  }) => import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ /** Green circle with a white check, anchored to the bottom-right of a square
2
+ * square (over the piece). */
3
+ export declare const CorrectMoveCheckBadge: () => import("react").JSX.Element;
@@ -2,6 +2,10 @@ export interface HighlightChessboardProps {
2
2
  checkSquare: string;
3
3
  hintSquare: string | null;
4
4
  incorrectMoveSquare: string | null;
5
+ /** Destination square of the last correct training move — shows a green check. */
6
+ correctMoveSquare?: string | null;
7
+ /** Enable click-to-move when `onPieceDrop` is provided. Defaults to true. */
8
+ clickToMove?: boolean;
5
9
  [key: string]: any;
6
10
  }
7
- export declare const HighlightChessboard: ({ checkSquare, hintSquare, incorrectMoveSquare, customSquareStyles: extraSquareStyles, ...props }: HighlightChessboardProps) => import("react").JSX.Element;
11
+ export declare const HighlightChessboard: ({ checkSquare, hintSquare, incorrectMoveSquare, correctMoveSquare, clickToMove, customSquareStyles: extraSquareStyles, customBoardStyle, onPieceDrop, position, arePiecesDraggable, autoPromoteToQueen, isDraggablePiece, onPromotionCheck, onSquareClick, onPromotionPieceSelect, onPieceDragBegin, showPromotionDialog: showPromotionDialogProp, promotionToSquare: promotionToSquareProp, ...props }: HighlightChessboardProps) => import("react").JSX.Element;
@@ -6,4 +6,7 @@ export declare const boardSquareHighlightColors: {
6
6
  readonly hint: "rgba(119, 177, 212, 0.75)";
7
7
  /** Muted red — softer than the in-check highlight. */
8
8
  readonly incorrect: "rgba(140, 38, 38, 0.82)";
9
+ readonly selected: "rgba(255, 255, 0, 0.45)";
10
+ readonly moveTarget: "radial-gradient(circle, rgba(0, 0, 0, 0.18) 22%, transparent 22%)";
11
+ readonly captureTarget: "radial-gradient(circle, rgba(0, 0, 0, 0.18) 72%, transparent 72%)";
9
12
  };
@@ -0,0 +1,3 @@
1
+ import type { FC } from 'react';
2
+ import type { CustomSquareProps } from 'react-chessboard/dist/chessboard/types';
3
+ export declare function createFeedbackSquareRenderer(correctMoveSquare: string): FC<CustomSquareProps>;
@@ -2,4 +2,5 @@ export * from './boardThemes';
2
2
  export * from './chessboardTheme';
3
3
  export * from './ChessboardDnDProvider';
4
4
  export * from './HighlightChessboard';
5
+ export * from './CorrectMoveCheckBadge';
5
6
  export * from './boardSquareHighlightColors';
@@ -0,0 +1,28 @@
1
+ import { type Square } from 'chess.js';
2
+ import { type CSSProperties } from 'react';
3
+ type Piece = string;
4
+ export type ClickToMoveSquareStyles = Record<string, CSSProperties>;
5
+ export type UseClickToMoveOptions = {
6
+ enabled: boolean;
7
+ position: string | undefined;
8
+ arePiecesDraggable?: boolean;
9
+ autoPromoteToQueen?: boolean;
10
+ isDraggablePiece?: (args: {
11
+ piece: Piece;
12
+ sourceSquare: Square;
13
+ }) => boolean;
14
+ onPromotionCheck?: (sourceSquare: Square, targetSquare: Square, piece: Piece) => boolean;
15
+ onPieceDrop?: (sourceSquare: Square, targetSquare: Square, piece: Piece) => boolean;
16
+ onSquareClick?: (square: Square, piece: Piece | undefined) => void;
17
+ onPromotionPieceSelect?: (piece?: Piece, promoteFromSquare?: Square, promoteToSquare?: Square) => boolean;
18
+ onPieceDragBegin?: (piece: Piece, sourceSquare: Square) => void;
19
+ };
20
+ export declare function useClickToMove({ enabled, position, arePiecesDraggable, autoPromoteToQueen, isDraggablePiece, onPromotionCheck, onPieceDrop, onSquareClick, onPromotionPieceSelect, onPieceDragBegin, }: UseClickToMoveOptions): {
21
+ clickSquareStyles: ClickToMoveSquareStyles;
22
+ handleSquareClick: (square: Square, piece: Piece | undefined) => void;
23
+ handlePromotionPieceSelect: (piece?: Piece, promoteFromSquare?: Square, promoteToSquare?: Square) => boolean;
24
+ handlePieceDragBegin: (piece: Piece, sourceSquare: Square) => void;
25
+ showPromotionDialog: boolean;
26
+ promotionToSquare: Square | null;
27
+ };
28
+ export {};
@@ -0,0 +1,2 @@
1
+ /** Pause (ms) to show the correct-move check before advancing the line. */
2
+ export declare const CORRECT_MOVE_FEEDBACK_MS = 450;
@@ -1,4 +1,6 @@
1
1
  export * from './uciFromDrop';
2
2
  export * from './expectedMoveDrop';
3
3
  export * from './useBoardRevision';
4
+ export * from './correctMoveFeedbackMs';
5
+ export * from './useCorrectMoveFeedback';
4
6
  export * from './miss';
@@ -0,0 +1,6 @@
1
+ export declare function useCorrectMoveFeedback(delayMs?: number): {
2
+ correctMoveSquare: string | null;
3
+ showCorrectMove: (targetSquare: string, onComplete?: () => void) => void;
4
+ clearCorrectMoveFeedback: () => void;
5
+ isShowingCorrectMove: boolean;
6
+ };