gigaboard 1.6.0 → 1.7.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/dist/{chunk-FUP2LDMO.cjs → chunk-MCD4AIR2.cjs} +11 -3
- package/dist/chunk-MCD4AIR2.cjs.map +1 -0
- package/dist/{chunk-6F3FZAG7.js → chunk-SOM6XGJO.js} +11 -3
- package/dist/chunk-SOM6XGJO.js.map +1 -0
- package/dist/core.cjs +51 -51
- package/dist/core.js +1 -1
- package/dist/index.cjs +161 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +101 -24
- package/dist/index.js.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/{types-Dox7oLof.d.cts → types-nvS4NLgA.d.cts} +49 -9
- package/dist/{types-4W8ULiE2.d.ts → types-pfl2aAFu.d.ts} +49 -9
- package/package.json +1 -1
- package/dist/chunk-6F3FZAG7.js.map +0 -1
- package/dist/chunk-FUP2LDMO.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import react, { CSSProperties, RefObject, ReactNode } from 'react';
|
|
3
3
|
import { S as SquareIndex, u as BoardCell, v as BoardModel, x as BoardSnapshot, w as BoardModelOptions, P as PackedMove } from './board-model-BIVxSCWC.cjs';
|
|
4
4
|
export { D as Color, E as EngineAdapter, W as NULL_MOVE_SAN, X as NULL_MOVE_SANS, Y as NULL_MOVE_UCI, Z as NULL_MOVE_WORD, a as PieceType, a1 as ZobristKey, a2 as createBoardModel, a8 as isNullMove, a9 as isNullMoveSan, aa as isNullMoveUci, ac as packMove, ae as unpackMove } from './board-model-BIVxSCWC.cjs';
|
|
5
|
-
import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-
|
|
6
|
-
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-
|
|
5
|
+
import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-nvS4NLgA.cjs';
|
|
6
|
+
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-nvS4NLgA.cjs';
|
|
7
7
|
export { c as createGigachessAdapter, p as preloadGigachessAdapter } from './gigachess-XpNGPM2m.cjs';
|
|
8
8
|
export { HapticInput, TriggerOptions } from 'web-haptics';
|
|
9
9
|
|
|
@@ -338,7 +338,9 @@ interface UseDragOptions {
|
|
|
338
338
|
readonly dragLayerRef: RefObject<DragLayerHandle | null>;
|
|
339
339
|
readonly enabled: boolean;
|
|
340
340
|
/** The activation distance (pixels) for `pending → dragging`. */
|
|
341
|
-
readonly activationDistance?: number;
|
|
341
|
+
readonly activationDistance?: number | "adaptive";
|
|
342
|
+
/** Show piece on initial press, while preserving click vs drag semantics. */
|
|
343
|
+
readonly pickupOnPointerDown?: boolean;
|
|
342
344
|
/** Callbacks — see hook docs above. */
|
|
343
345
|
readonly onDragStart: (from: SquareIndex, cell: BoardCell) => void;
|
|
344
346
|
readonly onDragEnd: () => void;
|
|
@@ -488,7 +490,13 @@ declare const defaultPieces: PieceRenderer;
|
|
|
488
490
|
* Server-only entry (static SSR board, zero client JS): `gigaboard/server`.
|
|
489
491
|
*/
|
|
490
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Capability marker for apps migrating from app-owned SAN sounds to
|
|
495
|
+
* GigaBoard-confirmed board cues. Older package versions do not export it,
|
|
496
|
+
* so a runtime feature test can retain legacy audio with no silent moves.
|
|
497
|
+
*/
|
|
498
|
+
declare const SUPPORTS_CONFIRMED_BOARD_SOUND: true;
|
|
491
499
|
/** Package version — keep in sync with `package.json`. */
|
|
492
|
-
declare const PACKAGE_VERSION = "1.
|
|
500
|
+
declare const PACKAGE_VERSION = "1.7.0";
|
|
493
501
|
|
|
494
|
-
export { AnimationOptions, AnimationRunner, BoardCell, BoardEditor, type BoardEditorProps, BoardModel, BoardSnapshot, CSS_VARS, Chessboard, ChessboardProps, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, type HoverSquareContext, Orientation, PACKAGE_VERSION, PackedMove, PieceRenderer, ResolvedArrowPalette, SquareIndex, Theme, UseChessGameOptions, algebraicOf, defaultArrowColors, defaultPieces, defaultTheme, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useSquareCell };
|
|
502
|
+
export { AnimationOptions, AnimationRunner, BoardCell, BoardEditor, type BoardEditorProps, BoardModel, BoardSnapshot, CSS_VARS, Chessboard, ChessboardProps, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, type HoverSquareContext, Orientation, PACKAGE_VERSION, PackedMove, PieceRenderer, ResolvedArrowPalette, SUPPORTS_CONFIRMED_BOARD_SOUND, SquareIndex, Theme, UseChessGameOptions, algebraicOf, defaultArrowColors, defaultPieces, defaultTheme, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useSquareCell };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import react, { CSSProperties, RefObject, ReactNode } from 'react';
|
|
3
3
|
import { S as SquareIndex, u as BoardCell, v as BoardModel, x as BoardSnapshot, w as BoardModelOptions, P as PackedMove } from './board-model-BIVxSCWC.js';
|
|
4
4
|
export { D as Color, E as EngineAdapter, W as NULL_MOVE_SAN, X as NULL_MOVE_SANS, Y as NULL_MOVE_UCI, Z as NULL_MOVE_WORD, a as PieceType, a1 as ZobristKey, a2 as createBoardModel, a8 as isNullMove, a9 as isNullMoveSan, aa as isNullMoveUci, ac as packMove, ae as unpackMove } from './board-model-BIVxSCWC.js';
|
|
5
|
-
import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-
|
|
6
|
-
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-
|
|
5
|
+
import { O as Orientation, T as Theme, P as PieceRenderer, C as ChessboardProps, A as AnimationOptions, R as ResolvedArrowPalette, U as UseChessGameOptions } from './types-pfl2aAFu.js';
|
|
6
|
+
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-pfl2aAFu.js';
|
|
7
7
|
export { c as createGigachessAdapter, p as preloadGigachessAdapter } from './gigachess-DN-ncmAU.js';
|
|
8
8
|
export { HapticInput, TriggerOptions } from 'web-haptics';
|
|
9
9
|
|
|
@@ -338,7 +338,9 @@ interface UseDragOptions {
|
|
|
338
338
|
readonly dragLayerRef: RefObject<DragLayerHandle | null>;
|
|
339
339
|
readonly enabled: boolean;
|
|
340
340
|
/** The activation distance (pixels) for `pending → dragging`. */
|
|
341
|
-
readonly activationDistance?: number;
|
|
341
|
+
readonly activationDistance?: number | "adaptive";
|
|
342
|
+
/** Show piece on initial press, while preserving click vs drag semantics. */
|
|
343
|
+
readonly pickupOnPointerDown?: boolean;
|
|
342
344
|
/** Callbacks — see hook docs above. */
|
|
343
345
|
readonly onDragStart: (from: SquareIndex, cell: BoardCell) => void;
|
|
344
346
|
readonly onDragEnd: () => void;
|
|
@@ -488,7 +490,13 @@ declare const defaultPieces: PieceRenderer;
|
|
|
488
490
|
* Server-only entry (static SSR board, zero client JS): `gigaboard/server`.
|
|
489
491
|
*/
|
|
490
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Capability marker for apps migrating from app-owned SAN sounds to
|
|
495
|
+
* GigaBoard-confirmed board cues. Older package versions do not export it,
|
|
496
|
+
* so a runtime feature test can retain legacy audio with no silent moves.
|
|
497
|
+
*/
|
|
498
|
+
declare const SUPPORTS_CONFIRMED_BOARD_SOUND: true;
|
|
491
499
|
/** Package version — keep in sync with `package.json`. */
|
|
492
|
-
declare const PACKAGE_VERSION = "1.
|
|
500
|
+
declare const PACKAGE_VERSION = "1.7.0";
|
|
493
501
|
|
|
494
|
-
export { AnimationOptions, AnimationRunner, BoardCell, BoardEditor, type BoardEditorProps, BoardModel, BoardSnapshot, CSS_VARS, Chessboard, ChessboardProps, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, type HoverSquareContext, Orientation, PACKAGE_VERSION, PackedMove, PieceRenderer, ResolvedArrowPalette, SquareIndex, Theme, UseChessGameOptions, algebraicOf, defaultArrowColors, defaultPieces, defaultTheme, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useSquareCell };
|
|
502
|
+
export { AnimationOptions, AnimationRunner, BoardCell, BoardEditor, type BoardEditorProps, BoardModel, BoardSnapshot, CSS_VARS, Chessboard, ChessboardProps, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, type HoverSquareContext, Orientation, PACKAGE_VERSION, PackedMove, PieceRenderer, ResolvedArrowPalette, SUPPORTS_CONFIRMED_BOARD_SOUND, SquareIndex, Theme, UseChessGameOptions, algebraicOf, defaultArrowColors, defaultPieces, defaultTheme, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useSquareCell };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PieceType, Color, createDragController, createGigachessAdapter, createBoardModel, BOARD_CELL_BK, BOARD_CELL_BQ, BOARD_CELL_BR, BOARD_CELL_BB, BOARD_CELL_BN, BOARD_CELL_BP, BOARD_CELL_WK, BOARD_CELL_WQ, BOARD_CELL_WR, BOARD_CELL_WB, BOARD_CELL_WN, BOARD_CELL_WP, isEmptyCell, pieceTypeOf, colorOf, encodeBoardCell, isNullMove, decodePackedMove, isNullMoveUci } from './chunk-
|
|
2
|
-
export { Color, NULL_MOVE_SAN, NULL_MOVE_SANS, NULL_MOVE_UCI, NULL_MOVE_WORD, PieceType, createBoardModel, createGigachessAdapter, isNullMove, isNullMoveSan, isNullMoveUci, packMove, preloadGigachessAdapter, unpackMove } from './chunk-
|
|
1
|
+
import { PieceType, Color, createDragController, createGigachessAdapter, createBoardModel, BOARD_CELL_BK, BOARD_CELL_BQ, BOARD_CELL_BR, BOARD_CELL_BB, BOARD_CELL_BN, BOARD_CELL_BP, BOARD_CELL_WK, BOARD_CELL_WQ, BOARD_CELL_WR, BOARD_CELL_WB, BOARD_CELL_WN, BOARD_CELL_WP, isEmptyCell, pieceTypeOf, colorOf, encodeBoardCell, isNullMove, decodePackedMove, isNullMoveUci } from './chunk-SOM6XGJO.js';
|
|
2
|
+
export { Color, NULL_MOVE_SAN, NULL_MOVE_SANS, NULL_MOVE_UCI, NULL_MOVE_WORD, PieceType, createBoardModel, createGigachessAdapter, isNullMove, isNullMoveSan, isNullMoveUci, packMove, preloadGigachessAdapter, unpackMove } from './chunk-SOM6XGJO.js';
|
|
3
3
|
import { CSS_VARS, parseFenPlacement, STARTING_FEN, defaultTheme, defaultPieces, defaultArrowColors, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT } from './chunk-53XWDREK.js';
|
|
4
4
|
export { CSS_VARS, DEFAULT_ILLEGAL_FLASH_TINT, DEFAULT_PREMOVE_TINT, defaultArrowColors, defaultPieces, defaultTheme } from './chunk-53XWDREK.js';
|
|
5
5
|
import './chunk-OQLY5GJF.js';
|
|
@@ -2499,6 +2499,7 @@ function useDrag(options) {
|
|
|
2499
2499
|
dragLayerRef,
|
|
2500
2500
|
enabled,
|
|
2501
2501
|
activationDistance,
|
|
2502
|
+
pickupOnPointerDown = false,
|
|
2502
2503
|
onDragStart,
|
|
2503
2504
|
onDragEnd,
|
|
2504
2505
|
onDrop,
|
|
@@ -2512,8 +2513,8 @@ function useDrag(options) {
|
|
|
2512
2513
|
if (!enabled) return;
|
|
2513
2514
|
const container = containerRef.current;
|
|
2514
2515
|
if (container === null || game === null) return;
|
|
2515
|
-
|
|
2516
|
-
activationDistance ===
|
|
2516
|
+
let controller = createDragController(
|
|
2517
|
+
typeof activationDistance === "number" ? { activationDistance } : {}
|
|
2517
2518
|
);
|
|
2518
2519
|
let originEl = null;
|
|
2519
2520
|
let active = false;
|
|
@@ -2540,6 +2541,16 @@ function useDrag(options) {
|
|
|
2540
2541
|
activePointerId = null;
|
|
2541
2542
|
onDragEnd();
|
|
2542
2543
|
};
|
|
2544
|
+
const showDragGhost = (from, cell, x, y) => {
|
|
2545
|
+
const originLabel = algebraicOf2(from);
|
|
2546
|
+
originEl = container.querySelector(`[data-piece-square="${originLabel}"]`);
|
|
2547
|
+
if (originEl !== null) {
|
|
2548
|
+
originEl.style.opacity = `var(${GHOST_OPACITY_VAR}, 0.35)`;
|
|
2549
|
+
}
|
|
2550
|
+
active = true;
|
|
2551
|
+
dragLayerRef.current?.show(cell);
|
|
2552
|
+
writeTransform(x, y);
|
|
2553
|
+
};
|
|
2543
2554
|
const onPointerDown = (e) => {
|
|
2544
2555
|
if (e.button !== 0) return;
|
|
2545
2556
|
const sq = getSquareAtPoint(container, e.clientX, e.clientY, orientation);
|
|
@@ -2550,30 +2561,40 @@ function useDrag(options) {
|
|
|
2550
2561
|
if (canDrag !== void 0 && !canDrag({ square: sq, cell })) {
|
|
2551
2562
|
return;
|
|
2552
2563
|
}
|
|
2564
|
+
if (activationDistance === "adaptive" && controller.state.kind === "idle") {
|
|
2565
|
+
controller = createDragController({
|
|
2566
|
+
activationDistance: e.pointerType === "touch" ? 6 : 2
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2553
2569
|
const consumed = controller.pointerDown(sq, e.pointerId, e.clientX, e.clientY);
|
|
2554
|
-
if (consumed)
|
|
2570
|
+
if (consumed) {
|
|
2571
|
+
activePointerId = e.pointerId;
|
|
2572
|
+
if (pickupOnPointerDown) {
|
|
2573
|
+
showDragGhost(sq, cell, e.clientX, e.clientY);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2555
2576
|
};
|
|
2556
2577
|
const onPointerMove = (e) => {
|
|
2557
2578
|
const evt = controller.pointerMove(e.pointerId, e.clientX, e.clientY);
|
|
2558
|
-
if (evt === null)
|
|
2579
|
+
if (evt === null) {
|
|
2580
|
+
if (active && pickupOnPointerDown && activePointerId === e.pointerId) {
|
|
2581
|
+
writeTransform(e.clientX, e.clientY);
|
|
2582
|
+
}
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2559
2585
|
if (evt.kind === "drag-start") {
|
|
2560
2586
|
const cell = game.getSnapshot().board[evt.from] ?? 0;
|
|
2561
2587
|
if (cell === 0) {
|
|
2562
2588
|
controller.cancel();
|
|
2589
|
+
if (active) cleanup();
|
|
2563
2590
|
return;
|
|
2564
2591
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
if (originEl !== null) {
|
|
2568
|
-
originEl.style.opacity = `var(${GHOST_OPACITY_VAR}, 0.35)`;
|
|
2569
|
-
}
|
|
2570
|
-
active = true;
|
|
2592
|
+
if (!active) showDragGhost(evt.from, cell, e.clientX, e.clientY);
|
|
2593
|
+
else writeTransform(e.clientX, e.clientY);
|
|
2571
2594
|
try {
|
|
2572
2595
|
container.setPointerCapture(e.pointerId);
|
|
2573
2596
|
} catch {
|
|
2574
2597
|
}
|
|
2575
|
-
dragLayerRef.current?.show(cell);
|
|
2576
|
-
writeTransform(e.clientX, e.clientY);
|
|
2577
2598
|
onDragStart(evt.from, cell);
|
|
2578
2599
|
return;
|
|
2579
2600
|
}
|
|
@@ -2615,6 +2636,7 @@ function useDrag(options) {
|
|
|
2615
2636
|
dragLayerRef,
|
|
2616
2637
|
enabled,
|
|
2617
2638
|
activationDistance,
|
|
2639
|
+
pickupOnPointerDown,
|
|
2618
2640
|
onDragStart,
|
|
2619
2641
|
onDragEnd,
|
|
2620
2642
|
onDrop
|
|
@@ -2903,8 +2925,8 @@ var DEFAULT_MOVE_HAPTIC_PATTERNS = Object.freeze({
|
|
|
2903
2925
|
promote: "success",
|
|
2904
2926
|
gameEnd: "success"
|
|
2905
2927
|
});
|
|
2906
|
-
function classifyMoveFeedback(animations, snapshot, perspective) {
|
|
2907
|
-
if (snapshot.isGameOver) return "gameEnd";
|
|
2928
|
+
function classifyMoveFeedback(animations, snapshot, perspective, cuePolicy = "default") {
|
|
2929
|
+
if (cuePolicy === "default" && snapshot.isGameOver) return "gameEnd";
|
|
2908
2930
|
let sawPromotion = false;
|
|
2909
2931
|
let sawCastle = false;
|
|
2910
2932
|
let sawCapture = false;
|
|
@@ -2913,6 +2935,7 @@ function classifyMoveFeedback(animations, snapshot, perspective) {
|
|
|
2913
2935
|
else if (d.kind === "castle") sawCastle = true;
|
|
2914
2936
|
else if (d.kind === "capture" || d.kind === "en-passant") sawCapture = true;
|
|
2915
2937
|
}
|
|
2938
|
+
if (cuePolicy === "san-priority" && sawCapture) return "capture";
|
|
2916
2939
|
if (sawPromotion) return "promote";
|
|
2917
2940
|
if (sawCastle) return "castle";
|
|
2918
2941
|
if (snapshot.inCheck) return "moveCheck";
|
|
@@ -3050,10 +3073,22 @@ function createPools(sources, preload) {
|
|
|
3050
3073
|
return pools;
|
|
3051
3074
|
}
|
|
3052
3075
|
function useMoveSound(model, options = {}) {
|
|
3053
|
-
const {
|
|
3076
|
+
const {
|
|
3077
|
+
enabled = true,
|
|
3078
|
+
volume = 1,
|
|
3079
|
+
preload = "none",
|
|
3080
|
+
prewarm = false,
|
|
3081
|
+
onCue,
|
|
3082
|
+
trigger = "model",
|
|
3083
|
+
cuePolicy = "default",
|
|
3084
|
+
sources,
|
|
3085
|
+
perspective
|
|
3086
|
+
} = options;
|
|
3054
3087
|
const poolsRef = useRef(null);
|
|
3055
3088
|
const sourcesRef = useRef(DEFAULT_MOVE_SOUND_SOURCES);
|
|
3056
3089
|
const preloadRef = useRef(preload);
|
|
3090
|
+
const onCueRef = useRef(onCue);
|
|
3091
|
+
onCueRef.current = onCue;
|
|
3057
3092
|
const volumeRef = useRef(volume);
|
|
3058
3093
|
useEffect(() => {
|
|
3059
3094
|
volumeRef.current = volume;
|
|
@@ -3078,10 +3113,25 @@ function useMoveSound(model, options = {}) {
|
|
|
3078
3113
|
poolsRef.current = null;
|
|
3079
3114
|
}
|
|
3080
3115
|
}, [enabled]);
|
|
3116
|
+
useEffect(() => {
|
|
3117
|
+
if (!enabled || !prewarm || onCue) return;
|
|
3118
|
+
if (typeof window === "undefined" || typeof Audio === "undefined") return;
|
|
3119
|
+
if (poolsRef.current === null) {
|
|
3120
|
+
poolsRef.current = createPools(
|
|
3121
|
+
{ ...DEFAULT_MOVE_SOUND_SOURCES, ...sources ?? {} },
|
|
3122
|
+
preload
|
|
3123
|
+
);
|
|
3124
|
+
}
|
|
3125
|
+
}, [enabled, prewarm, onCue, preload, sources]);
|
|
3081
3126
|
const triggerMoveSound = useCallback(
|
|
3082
3127
|
(key) => {
|
|
3083
3128
|
if (!enabled) return;
|
|
3084
3129
|
if (typeof window === "undefined") return;
|
|
3130
|
+
const effectiveVolume = Math.max(0, Math.min(1, volumeRef.current));
|
|
3131
|
+
if (onCueRef.current) {
|
|
3132
|
+
onCueRef.current(key, effectiveVolume);
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3085
3135
|
if (typeof Audio === "undefined") return;
|
|
3086
3136
|
const pools = poolsRef.current ?? createPools(sourcesRef.current, preloadRef.current);
|
|
3087
3137
|
poolsRef.current = pools;
|
|
@@ -3090,7 +3140,7 @@ function useMoveSound(model, options = {}) {
|
|
|
3090
3140
|
pool.cursor = (pool.cursor + 1) % pool.elements.length;
|
|
3091
3141
|
const el = pool.elements[pool.cursor];
|
|
3092
3142
|
if (el === void 0) return;
|
|
3093
|
-
el.volume =
|
|
3143
|
+
el.volume = effectiveVolume;
|
|
3094
3144
|
el.currentTime = 0;
|
|
3095
3145
|
void el.play().catch(() => {
|
|
3096
3146
|
});
|
|
@@ -3098,7 +3148,7 @@ function useMoveSound(model, options = {}) {
|
|
|
3098
3148
|
[enabled]
|
|
3099
3149
|
);
|
|
3100
3150
|
useEffect(() => {
|
|
3101
|
-
if (!enabled || model === null) return;
|
|
3151
|
+
if (!enabled || model === null || trigger === "position") return;
|
|
3102
3152
|
let prevPly = model.getSnapshot().historyPly;
|
|
3103
3153
|
return model.subscribe(() => {
|
|
3104
3154
|
const snap = model.getSnapshot();
|
|
@@ -3107,10 +3157,15 @@ function useMoveSound(model, options = {}) {
|
|
|
3107
3157
|
return;
|
|
3108
3158
|
}
|
|
3109
3159
|
prevPly = snap.historyPly;
|
|
3110
|
-
const key = classifyMoveFeedback(
|
|
3160
|
+
const key = classifyMoveFeedback(
|
|
3161
|
+
model.lastAnimations,
|
|
3162
|
+
snap,
|
|
3163
|
+
perspectiveRef.current,
|
|
3164
|
+
cuePolicy
|
|
3165
|
+
);
|
|
3111
3166
|
triggerMoveSound(key);
|
|
3112
3167
|
});
|
|
3113
|
-
}, [enabled, model, triggerMoveSound]);
|
|
3168
|
+
}, [enabled, model, trigger, cuePolicy, triggerMoveSound]);
|
|
3114
3169
|
return triggerMoveSound;
|
|
3115
3170
|
}
|
|
3116
3171
|
var STYLE_ID3 = "gb-selection-styles";
|
|
@@ -3407,6 +3462,8 @@ function Chessboard(props) {
|
|
|
3407
3462
|
ariaLabel,
|
|
3408
3463
|
animation,
|
|
3409
3464
|
allowDrag = true,
|
|
3465
|
+
dragActivationDistance,
|
|
3466
|
+
dragPickupOnPointerDown = false,
|
|
3410
3467
|
allowDrawingArrows = true,
|
|
3411
3468
|
clearArrowsOnMove = true,
|
|
3412
3469
|
clearArrowsOnClick = true,
|
|
@@ -3471,6 +3528,16 @@ function Chessboard(props) {
|
|
|
3471
3528
|
const previousSnapshot = game.getSnapshot();
|
|
3472
3529
|
if (game.engine.fen() === positionFen && managedArrows === void 0) {
|
|
3473
3530
|
lastControlledFeedbackFenRef.current = positionFen;
|
|
3531
|
+
if (soundOptions.trigger === "position" && previousFeedbackFen !== null && previousFeedbackFen !== positionFen) {
|
|
3532
|
+
triggerMoveSound(
|
|
3533
|
+
classifyMoveFeedback(
|
|
3534
|
+
game.lastAnimations,
|
|
3535
|
+
previousSnapshot,
|
|
3536
|
+
soundOptions.perspective,
|
|
3537
|
+
soundOptions.cuePolicy
|
|
3538
|
+
)
|
|
3539
|
+
);
|
|
3540
|
+
}
|
|
3474
3541
|
return;
|
|
3475
3542
|
}
|
|
3476
3543
|
const positionChanged = syncPositionFen(
|
|
@@ -3491,7 +3558,12 @@ function Chessboard(props) {
|
|
|
3491
3558
|
const feedbackDescriptors = controlledFeedbackDescriptors(positionTransition, previousSnapshot.board, snapshot.board) ?? game.lastAnimations;
|
|
3492
3559
|
const feedbackSnapshot = positionTransition?.direction === "backward" ? previousSnapshot : snapshot;
|
|
3493
3560
|
triggerMoveSound(
|
|
3494
|
-
classifyMoveFeedback(
|
|
3561
|
+
classifyMoveFeedback(
|
|
3562
|
+
feedbackDescriptors,
|
|
3563
|
+
feedbackSnapshot,
|
|
3564
|
+
soundOptions.perspective,
|
|
3565
|
+
soundOptions.cuePolicy
|
|
3566
|
+
)
|
|
3495
3567
|
);
|
|
3496
3568
|
triggerMoveHaptic2(
|
|
3497
3569
|
classifyMoveFeedback(feedbackDescriptors, feedbackSnapshot, hapticOptions.perspective)
|
|
@@ -3506,6 +3578,8 @@ function Chessboard(props) {
|
|
|
3506
3578
|
preserveUserArrowsOnPositionSync,
|
|
3507
3579
|
orientation,
|
|
3508
3580
|
soundOptions.perspective,
|
|
3581
|
+
soundOptions.cuePolicy,
|
|
3582
|
+
soundOptions.trigger,
|
|
3509
3583
|
triggerMoveHaptic2,
|
|
3510
3584
|
triggerMoveSound
|
|
3511
3585
|
]);
|
|
@@ -3697,6 +3771,8 @@ function Chessboard(props) {
|
|
|
3697
3771
|
containerRef,
|
|
3698
3772
|
dragLayerRef,
|
|
3699
3773
|
enabled: dragEnabled && game !== null,
|
|
3774
|
+
...dragActivationDistance !== void 0 ? { activationDistance: dragActivationDistance } : {},
|
|
3775
|
+
pickupOnPointerDown: dragPickupOnPointerDown,
|
|
3700
3776
|
onDragStart,
|
|
3701
3777
|
onDragEnd,
|
|
3702
3778
|
onDrop,
|
|
@@ -3857,8 +3933,9 @@ function useChessGame(options = {}) {
|
|
|
3857
3933
|
}
|
|
3858
3934
|
|
|
3859
3935
|
// src/index.ts
|
|
3860
|
-
var
|
|
3936
|
+
var SUPPORTS_CONFIRMED_BOARD_SOUND = true;
|
|
3937
|
+
var PACKAGE_VERSION = "1.7.0";
|
|
3861
3938
|
|
|
3862
|
-
export { AnimationRunner, BoardEditor, Chessboard, DEFAULT_MOVE_HAPTIC_PATTERNS, DEFAULT_MOVE_SOUND_SOURCES, PACKAGE_VERSION, algebraicOf2 as algebraicOf, classifyMoveFeedback, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, triggerHaptic, triggerMoveHaptic, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useMoveHaptics, useMoveSound, useSquareCell, warmupHaptics };
|
|
3939
|
+
export { AnimationRunner, BoardEditor, Chessboard, DEFAULT_MOVE_HAPTIC_PATTERNS, DEFAULT_MOVE_SOUND_SOURCES, PACKAGE_VERSION, SUPPORTS_CONFIRMED_BOARD_SOUND, algebraicOf2 as algebraicOf, classifyMoveFeedback, formatFenPlacement, getPointAtSquareCentre, getSquareAtPoint, squareOf, triggerHaptic, triggerMoveHaptic, useArrowGesture, useBoardSlice, useBoardSnapshot, useChessGame, useClickToMove, useDrag, useHoverSquare, useKeyboardNav, useMoveHaptics, useMoveSound, useSquareCell, warmupHaptics };
|
|
3863
3940
|
//# sourceMappingURL=index.js.map
|
|
3864
3941
|
//# sourceMappingURL=index.js.map
|