gigaboard 1.2.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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/board-model-BvJOtwQ3.d.cts +675 -0
- package/dist/board-model-BvJOtwQ3.d.ts +675 -0
- package/dist/canvas.cjs +8 -0
- package/dist/canvas.cjs.map +1 -0
- package/dist/canvas.d.cts +14 -0
- package/dist/canvas.d.ts +14 -0
- package/dist/canvas.js +6 -0
- package/dist/canvas.js.map +1 -0
- package/dist/chunk-3HNIF4ZE.js +3 -0
- package/dist/chunk-3HNIF4ZE.js.map +1 -0
- package/dist/chunk-44YKPXXT.js +63 -0
- package/dist/chunk-44YKPXXT.js.map +1 -0
- package/dist/chunk-5WAOEWKS.js +16 -0
- package/dist/chunk-5WAOEWKS.js.map +1 -0
- package/dist/chunk-AYVQCHSG.cjs +10 -0
- package/dist/chunk-AYVQCHSG.cjs.map +1 -0
- package/dist/chunk-B26QLI2K.cjs +18 -0
- package/dist/chunk-B26QLI2K.cjs.map +1 -0
- package/dist/chunk-B2TBDDJN.cjs +10 -0
- package/dist/chunk-B2TBDDJN.cjs.map +1 -0
- package/dist/chunk-BFN5JI3T.js +8 -0
- package/dist/chunk-BFN5JI3T.js.map +1 -0
- package/dist/chunk-BWNBPN3P.cjs +10 -0
- package/dist/chunk-BWNBPN3P.cjs.map +1 -0
- package/dist/chunk-CXDGJMYL.js +105 -0
- package/dist/chunk-CXDGJMYL.js.map +1 -0
- package/dist/chunk-EOSX5UX3.js +8 -0
- package/dist/chunk-EOSX5UX3.js.map +1 -0
- package/dist/chunk-FNRS6YJI.cjs +67 -0
- package/dist/chunk-FNRS6YJI.cjs.map +1 -0
- package/dist/chunk-G6ZFOJZR.cjs +18 -0
- package/dist/chunk-G6ZFOJZR.cjs.map +1 -0
- package/dist/chunk-HSMILJKQ.cjs +18 -0
- package/dist/chunk-HSMILJKQ.cjs.map +1 -0
- package/dist/chunk-I4BQGFP5.cjs +113 -0
- package/dist/chunk-I4BQGFP5.cjs.map +1 -0
- package/dist/chunk-J6GGNP5S.js +1104 -0
- package/dist/chunk-J6GGNP5S.js.map +1 -0
- package/dist/chunk-JQSBAWIZ.cjs +4 -0
- package/dist/chunk-JQSBAWIZ.cjs.map +1 -0
- package/dist/chunk-KW56FEBY.js +8 -0
- package/dist/chunk-KW56FEBY.js.map +1 -0
- package/dist/chunk-N7ED2MZS.cjs +10 -0
- package/dist/chunk-N7ED2MZS.cjs.map +1 -0
- package/dist/chunk-NAA5O4BT.js +16 -0
- package/dist/chunk-NAA5O4BT.js.map +1 -0
- package/dist/chunk-OQLY5GJF.js +16 -0
- package/dist/chunk-OQLY5GJF.js.map +1 -0
- package/dist/chunk-P72B3YTG.js +16 -0
- package/dist/chunk-P72B3YTG.js.map +1 -0
- package/dist/chunk-U6WAD322.js +8 -0
- package/dist/chunk-U6WAD322.js.map +1 -0
- package/dist/chunk-UUTEFNFO.cjs +1148 -0
- package/dist/chunk-UUTEFNFO.cjs.map +1 -0
- package/dist/chunk-VYSVIIZA.cjs +18 -0
- package/dist/chunk-VYSVIIZA.cjs.map +1 -0
- package/dist/core.cjs +180 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +164 -0
- package/dist/core.d.ts +164 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/create-image-piece-set-BcmRKGql.d.cts +100 -0
- package/dist/create-image-piece-set-BcmRKGql.d.ts +100 -0
- package/dist/gigachess-3BDD--yT.d.cts +22 -0
- package/dist/gigachess-DolQlR82.d.ts +22 -0
- package/dist/index.cjs +2972 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +435 -0
- package/dist/index.d.ts +435 -0
- package/dist/index.js +2898 -0
- package/dist/index.js.map +1 -0
- package/dist/pieces/alpha.cjs +13 -0
- package/dist/pieces/alpha.cjs.map +1 -0
- package/dist/pieces/alpha.d.cts +17 -0
- package/dist/pieces/alpha.d.ts +17 -0
- package/dist/pieces/alpha.js +4 -0
- package/dist/pieces/alpha.js.map +1 -0
- package/dist/pieces/cburnett.cjs +13 -0
- package/dist/pieces/cburnett.cjs.map +1 -0
- package/dist/pieces/cburnett.d.cts +19 -0
- package/dist/pieces/cburnett.d.ts +19 -0
- package/dist/pieces/cburnett.js +4 -0
- package/dist/pieces/cburnett.js.map +1 -0
- package/dist/pieces/chesscom.cjs +14 -0
- package/dist/pieces/chesscom.cjs.map +1 -0
- package/dist/pieces/chesscom.d.cts +3 -0
- package/dist/pieces/chesscom.d.ts +3 -0
- package/dist/pieces/chesscom.js +5 -0
- package/dist/pieces/chesscom.js.map +1 -0
- package/dist/pieces/merida.cjs +13 -0
- package/dist/pieces/merida.cjs.map +1 -0
- package/dist/pieces/merida.d.cts +17 -0
- package/dist/pieces/merida.d.ts +17 -0
- package/dist/pieces/merida.js +4 -0
- package/dist/pieces/merida.js.map +1 -0
- package/dist/pieces/neo.cjs +13 -0
- package/dist/pieces/neo.cjs.map +1 -0
- package/dist/pieces/neo.d.cts +18 -0
- package/dist/pieces/neo.d.ts +18 -0
- package/dist/pieces/neo.js +4 -0
- package/dist/pieces/neo.js.map +1 -0
- package/dist/pieces.cjs +55 -0
- package/dist/pieces.cjs.map +1 -0
- package/dist/pieces.d.cts +21 -0
- package/dist/pieces.d.ts +21 -0
- package/dist/pieces.js +24 -0
- package/dist/pieces.js.map +1 -0
- package/dist/server.cjs +207 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +60 -0
- package/dist/server.d.ts +60 -0
- package/dist/server.js +205 -0
- package/dist/server.js.map +1 -0
- package/dist/sounds/capture.mp3 +0 -0
- package/dist/sounds/castle.mp3 +0 -0
- package/dist/sounds/game-end.mp3 +0 -0
- package/dist/sounds/move-check.mp3 +0 -0
- package/dist/sounds/move-opponent.mp3 +0 -0
- package/dist/sounds/move-self.mp3 +0 -0
- package/dist/sounds/promote.mp3 +0 -0
- package/dist/themes/blue.cjs +12 -0
- package/dist/themes/blue.cjs.map +1 -0
- package/dist/themes/blue.d.cts +102 -0
- package/dist/themes/blue.d.ts +102 -0
- package/dist/themes/blue.js +3 -0
- package/dist/themes/blue.js.map +1 -0
- package/dist/themes/brown.cjs +12 -0
- package/dist/themes/brown.cjs.map +1 -0
- package/dist/themes/brown.d.cts +1 -0
- package/dist/themes/brown.d.ts +1 -0
- package/dist/themes/brown.js +3 -0
- package/dist/themes/brown.js.map +1 -0
- package/dist/themes/green.cjs +12 -0
- package/dist/themes/green.cjs.map +1 -0
- package/dist/themes/green.d.cts +1 -0
- package/dist/themes/green.d.ts +1 -0
- package/dist/themes/green.js +3 -0
- package/dist/themes/green.js.map +1 -0
- package/dist/themes/wood.cjs +12 -0
- package/dist/themes/wood.cjs.map +1 -0
- package/dist/themes/wood.d.cts +1 -0
- package/dist/themes/wood.d.ts +1 -0
- package/dist/themes/wood.js +3 -0
- package/dist/themes/wood.js.map +1 -0
- package/dist/themes.cjs +36 -0
- package/dist/themes.cjs.map +1 -0
- package/dist/themes.d.cts +1 -0
- package/dist/themes.d.ts +1 -0
- package/dist/themes.js +21 -0
- package/dist/themes.js.map +1 -0
- package/dist/types-Bg2xiUHE.d.cts +501 -0
- package/dist/types-D5eBJGzj.d.ts +501 -0
- package/package.json +210 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { C as ChessboardProps, T as Theme, O as Orientation, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions, P as PieceRenderer } from './types-D5eBJGzj.js';
|
|
3
|
+
export { a as ArrowColors, D as DEFAULT_MOVE_HAPTIC_PATTERNS, b as DEFAULT_MOVE_SOUND_SOURCES, H as HapticFeedbackOptions, L as LegalTargetStyle, M as MoveFeedbackKey, c as MoveHapticKey, d as MoveHapticOptions, e as MoveHapticPatterns, f as MoveSoundKey, g as MoveSoundOptions, h as MoveSoundSources, i as PositionTransition, j as PromotionContext, k as RanksPosition, S as SquareContext, l as TriggerMoveHaptic, m as TriggerMoveSound, n as classifyMoveFeedback, t as triggerHaptic, o as triggerMoveHaptic, u as useMoveHaptics, p as useMoveSound, w as warmupHaptics } from './types-D5eBJGzj.js';
|
|
4
|
+
export { c as createGigachessAdapter, p as preloadGigachessAdapter } from './gigachess-DolQlR82.js';
|
|
5
|
+
import { u as BoardModel, w as BoardSnapshot, S as SquareIndex, v as BoardModelOptions, P as PackedMove, t as BoardCell } from './board-model-BvJOtwQ3.js';
|
|
6
|
+
export { z as Color, E as EngineAdapter, a as PieceType, Z as ZobristKey, Y as createBoardModel, a4 as packMove, a6 as unpackMove } from './board-model-BvJOtwQ3.js';
|
|
7
|
+
import { RefObject, ReactNode } from 'react';
|
|
8
|
+
export { HapticInput, TriggerOptions } from 'web-haptics';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interactive chess board.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* "use client";
|
|
16
|
+
* import { Chessboard, useChessGame } from "gigaboard";
|
|
17
|
+
*
|
|
18
|
+
* export default function Board() {
|
|
19
|
+
* const game = useChessGame();
|
|
20
|
+
* return <Chessboard game={game} />;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function Chessboard(props: ChessboardProps): react_jsx_runtime.JSX.Element;
|
|
25
|
+
|
|
26
|
+
/** Keys every Gigaboard board understands. */
|
|
27
|
+
declare const CSS_VARS: {
|
|
28
|
+
readonly SQ_LIGHT: "--gb-sq-light";
|
|
29
|
+
readonly SQ_DARK: "--gb-sq-dark";
|
|
30
|
+
readonly LAST_MOVE: "--gb-last-move";
|
|
31
|
+
readonly SELECTED: "--gb-selected";
|
|
32
|
+
readonly LEGAL_TARGET: "--gb-legal-target";
|
|
33
|
+
readonly LEGAL_TARGET_CAPTURE: "--gb-legal-target-capture";
|
|
34
|
+
readonly CHECK: "--gb-check";
|
|
35
|
+
readonly COORDINATE_LIGHT: "--gb-coord-light";
|
|
36
|
+
readonly COORDINATE_DARK: "--gb-coord-dark";
|
|
37
|
+
/**
|
|
38
|
+
* Opacity of the piece left behind at the drag origin while the ghost
|
|
39
|
+
* is in flight. Default `0.35` (lichess parity). Themes may override
|
|
40
|
+
* to `0` for a chess.com-style "piece vanishes" effect.
|
|
41
|
+
*/
|
|
42
|
+
readonly DRAG_GHOST_OPACITY: "--gb-drag-ghost-opacity";
|
|
43
|
+
};
|
|
44
|
+
declare const defaultTheme: Theme;
|
|
45
|
+
/**
|
|
46
|
+
* Default arrow-channel colours. Close to lichess's palette so arrows feel
|
|
47
|
+
* familiar to players migrating over.
|
|
48
|
+
*/
|
|
49
|
+
declare const defaultArrowColors: Readonly<{
|
|
50
|
+
default: "rgba(21, 120, 27, 0.8)";
|
|
51
|
+
shift: "rgba(153, 40, 40, 0.8)";
|
|
52
|
+
alt: "rgba(230, 160, 0, 0.8)";
|
|
53
|
+
ctrl: "rgba(0, 60, 130, 0.8)";
|
|
54
|
+
}>;
|
|
55
|
+
/** Distinct blue tint used to preview pending premoves. */
|
|
56
|
+
declare const DEFAULT_PREMOVE_TINT = "rgba(30, 98, 255, 0.4)";
|
|
57
|
+
/** Red tint used to announce rejected moves. */
|
|
58
|
+
declare const DEFAULT_ILLEGAL_FLASH_TINT = "rgba(220, 40, 40, 0.55)";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* WAAPI-driven FLIP animations for piece glides.
|
|
62
|
+
*
|
|
63
|
+
* ### Strategy
|
|
64
|
+
*
|
|
65
|
+
* After every model commit we know, via `model.lastAnimations`, what
|
|
66
|
+
* visually changed: a set of {@link AnimDescriptor}s describing `move`,
|
|
67
|
+
* `capture`, `en-passant`, `castle`, `promotion`, `appear`, or `disappear`.
|
|
68
|
+
*
|
|
69
|
+
* For each descriptor that has a source and a destination, we:
|
|
70
|
+
*
|
|
71
|
+
* 1. Compute the pixel displacement between the `from` and `to` squares.
|
|
72
|
+
* 2. Locate the destination `PieceSlot` DOM node (by `data-piece-square`).
|
|
73
|
+
* 3. Cancel any in-flight animation on that node.
|
|
74
|
+
* 4. Kick off a WAAPI animation whose first keyframe translates it back
|
|
75
|
+
* to the source and whose last keyframe returns to identity.
|
|
76
|
+
*
|
|
77
|
+
* The animation runs entirely on the compositor — React never re-renders
|
|
78
|
+
* during the glide.
|
|
79
|
+
*
|
|
80
|
+
* ### FLIP invariants
|
|
81
|
+
*
|
|
82
|
+
* - Run inside `useLayoutEffect` so the transform is applied **before**
|
|
83
|
+
* the browser paints, preventing a one-frame flash at the destination.
|
|
84
|
+
* - Skip animation when `prefers-reduced-motion: reduce` is set, or when
|
|
85
|
+
* the caller's duration is zero.
|
|
86
|
+
* - Fall back silently if the destination DOM node is missing (e.g. the
|
|
87
|
+
* piece-layer was reparented mid-animation) — never throw.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/** Runtime hooks exposed to {@link useAnimation}'s caller. */
|
|
91
|
+
interface UseAnimationRuntime {
|
|
92
|
+
/**
|
|
93
|
+
* Ref to a boolean flag. If `true` at commit time the next animation is
|
|
94
|
+
* skipped and the flag is reset to `false` automatically. Used by the
|
|
95
|
+
* drag handler to suppress the FLIP glide — for a drag-initiated move,
|
|
96
|
+
* the user has already placed the piece at the target, so animating
|
|
97
|
+
* from source → target reverses their action and looks jarring.
|
|
98
|
+
*/
|
|
99
|
+
readonly skipNextRef?: RefObject<boolean>;
|
|
100
|
+
}
|
|
101
|
+
/** Props for {@link AnimationRunner}. */
|
|
102
|
+
interface AnimationRunnerProps {
|
|
103
|
+
readonly model: BoardModel;
|
|
104
|
+
readonly containerRef: RefObject<HTMLElement | null>;
|
|
105
|
+
readonly orientation: Orientation;
|
|
106
|
+
readonly options?: AnimationOptions;
|
|
107
|
+
readonly runtime?: UseAnimationRuntime;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Sibling component that owns the animation subscription. Renders `null`;
|
|
111
|
+
* its only job is to translate a scalar slice change (`historyPly`) into
|
|
112
|
+
* a `useLayoutEffect` firing with the descriptors from the just-committed
|
|
113
|
+
* move. Because the subscription lives here — not in `<Chessboard/>` —
|
|
114
|
+
* the root board component no longer re-renders once per move.
|
|
115
|
+
*/
|
|
116
|
+
declare function AnimationRunner({ model, containerRef, orientation, options, runtime, }: AnimationRunnerProps): ReactNode;
|
|
117
|
+
|
|
118
|
+
/** Shape rendered mid-gesture, before the user releases the button. */
|
|
119
|
+
interface PreviewArrow {
|
|
120
|
+
readonly from: number;
|
|
121
|
+
readonly to: number;
|
|
122
|
+
readonly color: string;
|
|
123
|
+
}
|
|
124
|
+
/** Imperative API exposed by `<ArrowsLayer/>` to `useArrowGesture`. */
|
|
125
|
+
interface ArrowsLayerHandle {
|
|
126
|
+
/** Update the preview arrow (null to clear) and redraw. */
|
|
127
|
+
setPreview(preview: PreviewArrow | null): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Right-click drawing gesture.
|
|
132
|
+
*
|
|
133
|
+
* Mirrors the left-click drag hook but listens only for the secondary
|
|
134
|
+
* button. On `pointerdown` we record the origin square. Each `pointermove`
|
|
135
|
+
* updates an in-flight preview arrow via `arrowsLayerRef.setPreview` —
|
|
136
|
+
* **zero React re-renders** per frame, the canvas repaints imperatively.
|
|
137
|
+
* On `pointerup` we commit the arrow through the board model's
|
|
138
|
+
* `toggleArrow` (identical start/end toggles the same-square mark).
|
|
139
|
+
*
|
|
140
|
+
* Also intercepts the browser context menu so right-click doesn't pop the
|
|
141
|
+
* OS menu.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
interface UseArrowGestureOptions {
|
|
145
|
+
readonly game: BoardModel | null;
|
|
146
|
+
readonly orientation: Orientation;
|
|
147
|
+
readonly containerRef: RefObject<HTMLElement | null>;
|
|
148
|
+
readonly arrowsLayerRef: RefObject<ArrowsLayerHandle | null>;
|
|
149
|
+
readonly enabled: boolean;
|
|
150
|
+
/** Fully-resolved colour palette (caller merges prop with defaults). */
|
|
151
|
+
readonly palette: ResolvedArrowPalette;
|
|
152
|
+
/**
|
|
153
|
+
* When `true`, an arrow endpoint that lies on a legal move target
|
|
154
|
+
* from the origin snaps to that target. Typical usage: analysis
|
|
155
|
+
* boards where the user wants to draw future-move hints that align
|
|
156
|
+
* with the rules. Default `false`.
|
|
157
|
+
*/
|
|
158
|
+
readonly snapToValidMove?: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Install right-click pointer listeners. Returns nothing — the side effect
|
|
162
|
+
* is the listener registration. Gesture state lives entirely inside the
|
|
163
|
+
* effect's closure and is torn down on unmount / dep change.
|
|
164
|
+
*/
|
|
165
|
+
declare function useArrowGesture(options: UseArrowGestureOptions): void;
|
|
166
|
+
|
|
167
|
+
/** Subscribe to the entire board snapshot. Wakes up on every commit. */
|
|
168
|
+
declare function useBoardSnapshot(model: BoardModel): BoardSnapshot;
|
|
169
|
+
/**
|
|
170
|
+
* Subscribe to a slice derived from the snapshot. Re-renders only when the
|
|
171
|
+
* selector's return value changes by `Object.is`.
|
|
172
|
+
*
|
|
173
|
+
* The selector is called on every `getSnapshot` tick, so it should be cheap
|
|
174
|
+
* (a field access) and must return a stable reference when the underlying
|
|
175
|
+
* data didn't change. Our snapshot store guarantees stability for primitive
|
|
176
|
+
* fields and for the `legalTargets` / `arrows` / `premoves` collections.
|
|
177
|
+
*/
|
|
178
|
+
declare function useBoardSlice<T>(model: BoardModel, selector: (snapshot: BoardSnapshot) => T): T;
|
|
179
|
+
/**
|
|
180
|
+
* Subscribe to a single board byte via `subscribeSquare`. The component
|
|
181
|
+
* receives the byte's current value (0 for empty, 1–12 for a piece) and
|
|
182
|
+
* wakes up only when that byte changes.
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* The returned value is a primitive number, so React's default `Object.is`
|
|
186
|
+
* bailout handles equality. The `useCallback` pins the subscribe function
|
|
187
|
+
* to `(model, index)` — a Square that re-renders for unrelated reasons
|
|
188
|
+
* doesn't force a re-subscription.
|
|
189
|
+
*/
|
|
190
|
+
declare function useSquareCell(model: BoardModel | null | undefined, index: SquareIndex): number;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Allocate a board model bound to a fresh `gigachess` engine. The model
|
|
194
|
+
* is created synchronously on the initial render, lives for the lifetime of
|
|
195
|
+
* the calling component, and is disposed on unmount.
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* Synchronous initialization on frame 0 ensures zero layout shift and 0 ms
|
|
199
|
+
* long tasks during mount. Changing `options.fen` disposes the current model
|
|
200
|
+
* and allocates a fresh one.
|
|
201
|
+
*/
|
|
202
|
+
declare function useChessGame(options?: UseChessGameOptions & BoardModelOptions): BoardModel;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param model The board model, or `null` while the engine is loading.
|
|
206
|
+
* @param onMove Optional callback fired on every successful move.
|
|
207
|
+
* @param onPromotionNeeded Optional deferred-promotion handler. When
|
|
208
|
+
* provided, `tryMove` is not called — the caller resolves the promotion
|
|
209
|
+
* piece and invokes `model.tryMove` itself.
|
|
210
|
+
* @param enabled Gate click-to-move. When `false` the returned callback
|
|
211
|
+
* is a no-op — used by `viewOnly` boards and anywhere the caller needs
|
|
212
|
+
* a stable identity while suppressing input. Defaults to `true`.
|
|
213
|
+
*/
|
|
214
|
+
declare function useClickToMove(model: BoardModel | null, onMove?: (m: PackedMove) => void, onPromotionNeeded?: (from: SquareIndex, to: SquareIndex) => void, enabled?: boolean): (index: SquareIndex) => void;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Imperative handle exposed by {@link DragLayer}. `useDrag` uses these
|
|
218
|
+
* methods in its pointer handlers to show the ghost, move it, and hide
|
|
219
|
+
* it — all without triggering a React render.
|
|
220
|
+
*/
|
|
221
|
+
interface DragLayerHandle {
|
|
222
|
+
/** Reveal the ghost for the given piece cell (1..12). */
|
|
223
|
+
show(cell: BoardCell): void;
|
|
224
|
+
/** Hide the ghost. Safe to call while already hidden. */
|
|
225
|
+
hide(): void;
|
|
226
|
+
/** Write the ghost's transform. Called every pointer-move during a drag. */
|
|
227
|
+
setTransform(x: number, y: number): void;
|
|
228
|
+
/** Raw wrapper element — kept for legacy callers that measure geometry. */
|
|
229
|
+
element(): HTMLDivElement | null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Pointer-driven drag orchestration.
|
|
234
|
+
*
|
|
235
|
+
* The hook attaches `pointerdown`/`pointermove`/`pointerup`/`pointercancel`
|
|
236
|
+
* listeners to a container ref and threads them through the drag state
|
|
237
|
+
* machine from `gigaboard/core`.
|
|
238
|
+
*
|
|
239
|
+
* ### Why event listeners on the container (not per square)
|
|
240
|
+
*
|
|
241
|
+
* We need a single source of truth for every pointer sample during a drag:
|
|
242
|
+
* the pointer naturally crosses square boundaries many times in a single
|
|
243
|
+
* drag. Attaching per-square `onPointerMove` handlers would register 64
|
|
244
|
+
* React listeners and re-subscribe every render. A single container
|
|
245
|
+
* listener is one registration that never re-subscribes.
|
|
246
|
+
*
|
|
247
|
+
* ### Zero React renders per frame during drag
|
|
248
|
+
*
|
|
249
|
+
* During the `dragging` state we never call `setState`. Instead the hook
|
|
250
|
+
* writes to `dragLayerRef.current.style.transform` in the pointer-move
|
|
251
|
+
* handler. React sees nothing change until drag-end, at which point one
|
|
252
|
+
* commit finishes the interaction (and the model's own commit renders the
|
|
253
|
+
* new position).
|
|
254
|
+
*
|
|
255
|
+
* ### Contract with the caller
|
|
256
|
+
*
|
|
257
|
+
* - Provide a `containerRef` to the outermost board container (has 1:1
|
|
258
|
+
* geometry with the 8×8 grid).
|
|
259
|
+
* - Provide a `dragLayerRef` to the single absolutely-positioned element
|
|
260
|
+
* that represents the floating piece; the hook writes its `transform`.
|
|
261
|
+
* - `onDragStart(from, cell)` is called once when the drag crosses the
|
|
262
|
+
* activation threshold. The caller should render the piece into the
|
|
263
|
+
* drag layer (via React state) and imperatively hide the origin.
|
|
264
|
+
* - `onDrop(from, to)` is called when a drop lands on a different square.
|
|
265
|
+
* Illegal moves are the caller's problem — the hook merely reports the
|
|
266
|
+
* user's intent.
|
|
267
|
+
* - `onDragEnd()` is called on every terminal transition (drop, cancel,
|
|
268
|
+
* same-square drop). The caller restores DOM opacity and clears the
|
|
269
|
+
* drag-layer render state.
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
/** Options passed to {@link useDrag}. */
|
|
273
|
+
interface UseDragOptions {
|
|
274
|
+
readonly game: BoardModel | null;
|
|
275
|
+
readonly orientation: Orientation;
|
|
276
|
+
readonly containerRef: RefObject<HTMLElement | null>;
|
|
277
|
+
/**
|
|
278
|
+
* Imperative handle to the always-mounted drag overlay. `useDrag`
|
|
279
|
+
* calls `show`, `setTransform`, and `hide` here from its pointer
|
|
280
|
+
* handlers — zero React state changes during the drag loop (and
|
|
281
|
+
* crucially, none at drag-start either).
|
|
282
|
+
*/
|
|
283
|
+
readonly dragLayerRef: RefObject<DragLayerHandle | null>;
|
|
284
|
+
readonly enabled: boolean;
|
|
285
|
+
/** The activation distance (pixels) for `pending → dragging`. */
|
|
286
|
+
readonly activationDistance?: number;
|
|
287
|
+
/** Callbacks — see hook docs above. */
|
|
288
|
+
readonly onDragStart: (from: SquareIndex, cell: BoardCell) => void;
|
|
289
|
+
readonly onDragEnd: () => void;
|
|
290
|
+
readonly onDrop: (from: SquareIndex, to: SquareIndex) => void;
|
|
291
|
+
/**
|
|
292
|
+
* Optional per-piece gate. If provided and it returns `false` for the
|
|
293
|
+
* would-be drag source, pointer-down is silently ignored and no drag
|
|
294
|
+
* initiates. Called once per attempt, never during a drag.
|
|
295
|
+
*/
|
|
296
|
+
readonly canDragPiece?: (ctx: {
|
|
297
|
+
readonly square: SquareIndex;
|
|
298
|
+
readonly cell: BoardCell;
|
|
299
|
+
}) => boolean;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Install pointer listeners for drag-and-drop. Listeners stay registered for
|
|
303
|
+
* the lifetime of the containing component.
|
|
304
|
+
*/
|
|
305
|
+
declare function useDrag(options: UseDragOptions): void;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Per-square pointer-hover tracker.
|
|
309
|
+
*
|
|
310
|
+
* One `pointermove` + `pointerleave` listener on the container diffs the
|
|
311
|
+
* current square against the previous, firing `onEnter`/`onLeave` once
|
|
312
|
+
* per transition. Attaching handlers per-square would cost 64 React
|
|
313
|
+
* listeners and break the "0 re-renders per hover" budget
|
|
314
|
+
* (STANDARDS.md §4.2).
|
|
315
|
+
*
|
|
316
|
+
* Callbacks read through latest-refs so a fresh arrow function each
|
|
317
|
+
* render doesn't re-install the effect.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
/** Context passed to hover callbacks. */
|
|
321
|
+
interface HoverSquareContext {
|
|
322
|
+
readonly square: SquareIndex;
|
|
323
|
+
readonly cell: BoardCell;
|
|
324
|
+
}
|
|
325
|
+
/** Options for {@link useHoverSquare}. */
|
|
326
|
+
interface UseHoverSquareOptions {
|
|
327
|
+
readonly game: BoardModel | null;
|
|
328
|
+
readonly orientation: Orientation;
|
|
329
|
+
readonly containerRef: RefObject<HTMLElement | null>;
|
|
330
|
+
readonly enabled: boolean;
|
|
331
|
+
readonly onEnter?: (ctx: HoverSquareContext) => void;
|
|
332
|
+
readonly onLeave?: (ctx: HoverSquareContext) => void;
|
|
333
|
+
}
|
|
334
|
+
declare function useHoverSquare(options: UseHoverSquareOptions): void;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Keyboard navigation for the 8×8 grid.
|
|
338
|
+
*
|
|
339
|
+
* Implements the WAI-ARIA "Grid" authoring pattern:
|
|
340
|
+
*
|
|
341
|
+
* - Tab brings focus to the board via a roving tabindex — only the
|
|
342
|
+
* currently-focused square has `tabindex=0`; every other cell has
|
|
343
|
+
* `tabindex=-1`, so Tab moves straight out of the grid once the user
|
|
344
|
+
* is done.
|
|
345
|
+
* - Arrow keys move the focus between squares (visual up/down/left/right,
|
|
346
|
+
* orientation-aware).
|
|
347
|
+
* - Enter / Space activate the focused square (same path as a mouse click).
|
|
348
|
+
* - Escape clears the selection + any drawn arrows.
|
|
349
|
+
* - Home / End jump to the first / last square in the focused rank.
|
|
350
|
+
* - Ctrl+Home / Ctrl+End jump to the first / last square on the board.
|
|
351
|
+
*
|
|
352
|
+
* The hook is controlled: the caller owns `focusedSquare` state. This
|
|
353
|
+
* lets {@link Chessboard} integrate the keyboard focus with other
|
|
354
|
+
* board-level state (selection, drag, promotion dialog).
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
/** Options accepted by {@link useKeyboardNav}. */
|
|
358
|
+
interface UseKeyboardNavOptions {
|
|
359
|
+
readonly containerRef: RefObject<HTMLElement | null>;
|
|
360
|
+
readonly orientation: Orientation;
|
|
361
|
+
readonly focusedSquare: SquareIndex | null;
|
|
362
|
+
readonly setFocusedSquare: (square: SquareIndex) => void;
|
|
363
|
+
readonly onActivate: (square: SquareIndex) => void;
|
|
364
|
+
readonly onEscape: () => void;
|
|
365
|
+
readonly enabled: boolean;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Attach keyboard navigation listeners to the board container. All motion
|
|
369
|
+
* is expressed via `setFocusedSquare` — the render layer is responsible
|
|
370
|
+
* for applying `tabindex` and programmatic focus based on that state.
|
|
371
|
+
*/
|
|
372
|
+
declare function useKeyboardNav(options: UseKeyboardNavOptions): void;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Board geometry helpers.
|
|
376
|
+
*
|
|
377
|
+
* Pure, framework-agnostic utilities for mapping between viewport pixel
|
|
378
|
+
* coordinates and `SquareIndex` (LERF 0..63). Single source of truth
|
|
379
|
+
* consumed by {@link useDrag}, {@link useArrowGesture}, the spare-piece
|
|
380
|
+
* drag hook, and any consumer who wants to hit-test the board from
|
|
381
|
+
* custom React code (analysis overlays, piece tooltips, screenshots).
|
|
382
|
+
*
|
|
383
|
+
* No DOM mutation; no side effects. Each call reads
|
|
384
|
+
* `container.getBoundingClientRect()` once — cheap but not free, so
|
|
385
|
+
* hot-path callers should batch calls per pointer event.
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Resolve a viewport point to the `SquareIndex` it lies inside, or
|
|
390
|
+
* `null` when the point is outside the board rect.
|
|
391
|
+
*
|
|
392
|
+
* The hit-test assumes the container has 1:1 geometry with the 8×8 grid
|
|
393
|
+
* — i.e. the outer `<div>` of `<Chessboard/>`. Coordinates/edge padding
|
|
394
|
+
* layers do **not** sit inside a smaller sub-rect; they're overlays on
|
|
395
|
+
* the same box.
|
|
396
|
+
*
|
|
397
|
+
* @param container The board container element.
|
|
398
|
+
* @param clientX `MouseEvent.clientX` / `PointerEvent.clientX`.
|
|
399
|
+
* @param clientY `MouseEvent.clientY` / `PointerEvent.clientY`.
|
|
400
|
+
* @param orientation Board orientation (flips file/rank derivation).
|
|
401
|
+
* @returns The square under the point, or `null` if out of bounds.
|
|
402
|
+
*/
|
|
403
|
+
declare function getSquareAtPoint(container: HTMLElement, clientX: number, clientY: number, orientation: Orientation): SquareIndex | null;
|
|
404
|
+
/**
|
|
405
|
+
* Inverse of {@link getSquareAtPoint}: the viewport point at the centre
|
|
406
|
+
* of a given square, expressed in client (viewport) coordinates.
|
|
407
|
+
*
|
|
408
|
+
* Useful for drawing tooltips, floating annotations, or anchoring DOM
|
|
409
|
+
* nodes against a specific square without sampling the actual DOM child.
|
|
410
|
+
*
|
|
411
|
+
* @param container The board container element.
|
|
412
|
+
* @param square Square index in LERF order.
|
|
413
|
+
* @param orientation Board orientation.
|
|
414
|
+
* @returns `{ x, y }` in viewport pixel coordinates.
|
|
415
|
+
*/
|
|
416
|
+
declare function getPointAtSquareCentre(container: HTMLElement, square: SquareIndex, orientation: Orientation): {
|
|
417
|
+
readonly x: number;
|
|
418
|
+
readonly y: number;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
declare const defaultPieces: PieceRenderer;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* `gigaboard` — ultra-fast interactive React chessboard.
|
|
425
|
+
*
|
|
426
|
+
* Hand-curated barrel; sub-modules are never re-exported wholesale so
|
|
427
|
+
* consumers can tree-shake aggressively.
|
|
428
|
+
*
|
|
429
|
+
* Server-only entry (static SSR board, zero client JS): `gigaboard/server`.
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
/** Package version — keep in sync with `package.json`. */
|
|
433
|
+
declare const PACKAGE_VERSION = "0.1.0-alpha";
|
|
434
|
+
|
|
435
|
+
export { AnimationOptions, AnimationRunner, BoardCell, BoardModel, BoardSnapshot, CSS_VARS, Chessboard, ChessboardProps, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, type HoverSquareContext, Orientation, PACKAGE_VERSION, PackedMove, PieceRenderer, ResolvedArrowPalette, SquareIndex, Theme, UseChessGameOptions, defaultArrowColors, defaultPieces, defaultTheme, getPointAtSquareCentre, getSquareAtPoint, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useSquareCell };
|