import * as _angular_core from '@angular/core';
import { AfterViewInit, ElementRef, OnDestroy } from '@angular/core';
import { Api } from 'chessground/api';
import { Key, Color } from 'chessground/types';
import { MatDialogRef } from '@angular/material/dialog';
import { Chess } from 'chess.js';
/**
* Core chessboard component wrapping the chessground library via snabbdom.
*
* Accepts a `runFunction` signal-model input that receives the mounted DOM element
* and must return a chessground `Api` instance. The component manages lifecycle:
* - Uses an Angular `effect()` to watch `runFunction` changes and redraw the board.
* - Calls `redraw()` on `ngAfterViewInit` so the board appears as soon as the view is ready.
* - Provides a `toggleOrientation()` method to flip the board.
*
* Uses {@link NgxChessgroundService} (provided at component level) for snabbdom patching
* and chessground instance management.
*
* @example
* ```html
*
* ```
*
* @example
* ```typescript
* myRunFn = signal<(el: HTMLElement) => Api>((el) => {
* return Chessground(el, { fen: 'start' });
* });
* ```
*/
declare class NgxChessgroundComponent implements AfterViewInit {
/**
* Signal-based view query for the board container element.
*
* References the DOM element with template variable `#chessboard`.
* Used by {@link redraw} to pass the native element to chessground.
*/
readonly elementView: _angular_core.Signal>;
/**
* Signal-model function that constructs the chessground instance on a given element.
*
* This is the primary input mechanism of the component. Changes to this signal
* trigger a board redraw via the internal `effect()`.
*
* @param el — The board container `HTMLElement` mounted in the DOM.
* @returns A chessground `Api` instance configured as desired.
*/
runFunction: _angular_core.ModelSignal<((el: HTMLElement) => Api) | undefined>;
/** Service managing the chessground instance and snabbdom patching lifecycle. */
private readonly ngxChessgroundService;
/**
* Sets up a reactive effect that redraws the board whenever {@link runFunction} changes.
*
* This is the wiring that makes dynamic board configuration (switching FEN, orientation, etc.)
* work seamlessly — just update the signal and the board reacts.
*/
constructor();
/**
* Redraws the board once the view is initialized.
*
* Ensures the board is rendered on first load. Subsequent redraws
* are handled by the `effect()` watching `runFunction`.
*/
ngAfterViewInit(): void;
/**
* Flips the board orientation (white ↔ black).
*
* Delegates to {@link NgxChessgroundService.toggleOrientation}.
*/
toggleOrientation(): void;
/**
* Re-renders the chessboard via the snabbdom patching service.
*
* Retrieves the board element and current run function, then delegates
* to {@link NgxChessgroundService.redraw}.
*/
private redraw;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵcmp: _angular_core.ɵɵComponentDeclaration;
}
/**
* A table-style chessboard demo component.
*
* Displays a single chessboard initialized with the "Play legal moves from initial position"
* unit preset, enhanced with dialog-based pawn promotion via {@link PromotionService}.
*
* Implements {@link AfterViewInit} to set the run function on the child
* {@link NgxChessgroundComponent} once the view is ready.
*
* @example
* ```html
*
* ```
*/
declare class NgxChessgroundTableComponent implements AfterViewInit {
/**
* Signal-based view query for the child chessboard component.
*
* References the `NgxChessgroundComponent` with template variable `#chess`.
* Used in {@link ngAfterViewInit} to set the initial board configuration.
*/
readonly ngxChessgroundComponent: _angular_core.Signal;
/** Injected promotion dialog service for pawn promotion UX. */
private readonly promotionService;
/**
* Initializes the chessboard after the view is rendered.
*
* Creates unit presets enhanced with dialog-based promotion and assigns
* the "initial" unit's run function to the child chessground component.
*/
ngAfterViewInit(): void;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵcmp: _angular_core.ɵɵComponentDeclaration;
}
/**
* Criteria for filtering a parsed game collection in the PGN processor worker.
*
* All string fields are matched case-insensitively as substrings.
* Rating fields default to 0 (no lower bound) or Infinity (no upper bound) when unset.
*
* @example
* ```typescript
* const criteria: FilterCriteria = {
* white: 'carlsen',
* black: '',
* result: '1-0',
* moves: true,
* ignoreColor: false,
* targetMoves: ['e4', 'e5', 'Nf3'],
* minWhiteRating: 2500,
* minBlackRating: 2400,
* maxWhiteRating: Infinity,
* maxBlackRating: Infinity,
* eco: 'B33',
* timeControl: '180+2',
* event: '',
* };
* ```
*/
interface FilterCriteria {
/** Filter by white player name (case-insensitive substring match). */
white: string;
/** Filter by black player name (case-insensitive substring match). */
black: string;
/** Comma-separated result strings: `"1-0"`, `"0-1"`, `"draw"`, or `"*"` for unfinished. */
result: string;
/** When `true`, filter games by the {@link targetMoves} opening sequence. */
moves: boolean;
/** When `true`, treat {@link white} and {@link black} fields as matching either color. */
ignoreColor: boolean;
/** SAN move sequence the game must be prefixed with (only used when {@link moves} is `true`). */
targetMoves: string[];
/** Minimum white Elo rating (inclusive). Default 0. */
minWhiteRating: number;
/** Minimum black Elo rating (inclusive). Default 0. */
minBlackRating: number;
/** Maximum white Elo rating (inclusive). Use `Infinity` for no upper bound. */
maxWhiteRating: number;
/** Maximum black Elo rating (inclusive). Use `Infinity` for no upper bound. */
maxBlackRating: number;
/** ECO code filter (case-insensitive substring, e.g. `"B33"`). */
eco: string;
/** Time control filter (case-insensitive substring, e.g. `"180+2"`). */
timeControl: string;
/** Event/tournament name filter (case-insensitive substring). */
event: string;
}
/**
* Discriminated union of responses sent from the PGN processor worker to the main thread.
*
* The `id` field matches the correlation ID from the originating {@link WorkerMessage}.
*/
type WorkerResponse =
/** Response to a `'load'` message with game count and metadata. */
{
type: 'load';
payload: {
count: number;
metadata: GameMetadata[];
};
id: number;
}
/** Response to a `'filter'` message with matching game indices. */
| {
type: 'filter';
payload: number[];
id: number;
}
/** Response to a `'loadGame'` message with moves, cleaned PGN, evaluations, and optional error. */
| {
type: 'loadGame';
payload: {
moves: string[];
pgn: string;
evaluations: (string | null)[];
error?: string;
};
id: number;
}
/** Error response for any message type. */
| {
type: 'error';
payload: string;
id: number;
};
/**
* Metadata extracted from a single PGN game header.
*
* Used for displaying game lists, filtering, and sorting without parsing full move data.
* The `timeControlNormalized` field converts human-readable time controls
* (e.g. `"90+30"`, `"3:0"`) into a uniform `"baseSeconds+incrementSeconds"` format.
*/
interface GameMetadata {
/** 1-based game number within the loaded PGN collection. */
number: number;
/** White player display name (includes title and Elo if present, e.g. `"GM Carlsen (2850)"`). */
white: string;
/** Black player display name (includes title and Elo if present). */
black: string;
/** Normalized result: `"1-0"`, `"0-1"`, `"½-½"`, or `"*"`. */
result: string;
/** White player Elo rating (0 if missing). */
whiteElo: number;
/** Black player Elo rating (0 if missing). */
blackElo: number;
/** ECO (Encyclopedia of Chess Openings) code (e.g. `"B33"`). */
eco?: string;
/** Raw time control string from the PGN header. */
timeControl?: string;
/** Normalized time control in `"seconds+increment"` format, or `undefined` if unparseable. */
timeControlNormalized?: string;
/** Event/tournament name from the PGN header. */
event?: string;
}
/**
* A full-featured PGN viewer component for Angular applications.
*
* Supports loading single or multi-game PGN files, navigating moves, auto-replay
* with configurable timing modes, Stockfish-powered position analysis ("stop on error"),
* filtering by player/ECO/opening moves, and batch replay across multiple games.
*
* All components used are standalone. Import this component directly:
* ```typescript
* imports: [NgxPgnViewerComponent]
* ```
*
* @example Basic usage
* ```html
*
* ```
*/
declare class NgxPgnViewerComponent implements OnDestroy {
/** Service managing the PGN processor and Stockfish Web Workers. */
private readonly pgnViewerEngine;
/** Material snackbar service for user notifications. */
private readonly snackBar;
/**
* PGN string to load and display.
* Supports plain PGN, multi-game PGN, gzip-compressed (`.pgn.gz`), and ZIP archives.
*/
pgn: _angular_core.InputSignal;
/**
* Whether to highlight the last played move on the board with colored squares.
* @default true
*/
highlightLastMove: _angular_core.InputSignal;
/**
* Updates the white player name filter from an input event.
* @param event — Input event from the white filter text field.
*/
updateFilterWhite(event: Event): void;
/**
* Updates the black player name filter from an input event.
* @param event — Input event from the black filter text field.
*/
updateFilterBlack(event: Event): void;
/**
* Opens the white player typeahead dropdown and resets the selection index.
*/
openWhiteTypeahead(): void;
/**
* Opens the black player typeahead dropdown and resets the selection index.
*/
openBlackTypeahead(): void;
/**
* Closes the white player typeahead dropdown after a 200ms delay
* (allows mousedown on dropdown items to fire before close).
*/
closeWhiteTypeahead(): void;
/**
* Closes the black player typeahead dropdown after a 200ms delay
* (allows mousedown on dropdown items to fire before close).
*/
closeBlackTypeahead(): void;
/**
* Handles input events on the white player typeahead, updating the filter
* and keeping the dropdown open.
* @param event — Input event from the white filter typeahead field.
*/
onWhiteTypeaheadInput(event: Event): void;
/**
* Handles input events on the black player typeahead.
* @param event — Input event from the black filter typeahead field.
*/
onBlackTypeaheadInput(event: Event): void;
/**
* Selects a player from the white typeahead dropdown and closes it.
* @param player — The selected player name.
*/
selectWhiteTypeahead(player: string): void;
/**
* Selects a player from the black typeahead dropdown and closes it.
* @param player — The selected player name.
*/
selectBlackTypeahead(player: string): void;
/**
* Handles keyboard navigation in the white player typeahead dropdown.
*
* Arrow keys navigate the list, Enter selects, Escape closes.
* If the dropdown is closed, ArrowDown/ArrowUp reopen it.
*
* @param event — Keyboard event from the white typeahead input field.
*/
onWhiteTypeaheadKeydown(event: KeyboardEvent): void;
/**
* Handles keyboard navigation in the black player typeahead dropdown.
*
* Arrow keys navigate the list, Enter selects, Escape closes.
* If the dropdown is closed, ArrowDown/ArrowUp reopen it.
*
* @param event — Keyboard event from the black typeahead input field.
*/
onBlackTypeaheadKeydown(event: KeyboardEvent): void;
/**
* Splits text into match/non-match segments for typeahead highlighting.
*
* Used to render bold matching portions of player names in the typeahead dropdown.
*
* @param text — Full text to segment (e.g. a player name).
* @param query — Search query string to match against.
* @returns Array of `{ text, match }` objects for template rendering.
*/
highlightText(text: string, query: string): {
text: string;
match: boolean;
}[];
/**
* Updates the result filter from a multi-select dropdown change event.
*
* @param event — Change event from the result `` element.
*/
updateFilterResult(event: Event): void;
/**
* Updates the ECO code filter from a dropdown change event.
*
* @param event — Change event from the ECO `` element.
*/
updateFilterEco(event: Event): void;
/**
* Updates the time control filter from a dropdown change event.
*
* @param event — Change event from the time control `` element.
*/
updateFilterTimeControl(event: Event): void;
/**
* Updates the minimum white rating filter from an input event.
*
* @param event — Input event from the white rating ` ` field.
*/
updateFilterWhiteRating(event: Event): void;
/**
* Updates the maximum white rating filter from an input event.
*
* @param event — Input event from the white rating max ` ` field.
*/
updateFilterWhiteRatingMax(event: Event): void;
/**
* Updates the minimum black rating filter from an input event.
*
* @param event — Input event from the black rating ` ` field.
*/
updateFilterBlackRating(event: Event): void;
/**
* Updates the maximum black rating filter from an input event.
*
* @param event — Input event from the black rating max ` ` field.
*/
updateFilterBlackRatingMax(event: Event): void;
/**
* Toggles the "ignore color" checkbox — when enabled, player name filters
* match either white or black fields interchangeably.
*
* @param event — Change event from the ignore-color checkbox.
*/
toggleIgnoreColor(event: Event): void;
/**
* Toggles interactive opening-move filtering mode.
*
* When enabled, the board becomes editable so the user can play moves
* to define an opening sequence filter. The current game position is
* saved and restored when the mode is exited.
*
* @param event — Change event from the filter-moves checkbox.
*/
toggleFilterMoves(event: Event): void;
/**
* Looks up the defining move sequence for an ECO opening code.
*
* @param code — ECO code (e.g. `"B33"`).
* @returns Pipe-separated SAN move sequence, or empty string if not found.
*/
getOpeningMoves(code: string): string;
/** Parsed game metadata for all games in the loaded PGN. */
gamesMetadata: _angular_core.WritableSignal;
/** Zero-based index of the currently active game. */
currentGameIndex: _angular_core.WritableSignal;
/** Array of SAN move strings for the loaded game. */
moves: _angular_core.WritableSignal;
/** Zero-based index of the current move (-1 means start position, before any move). */
currentMoveIndex: _angular_core.WritableSignal;
/** Current board position in FEN notation. */
currentFen: _angular_core.WritableSignal;
/** Whether PGN data is being loaded/parsed. */
isLoading: _angular_core.WritableSignal;
/** Loading progress percentage (0–100). */
loadingProgress: _angular_core.WritableSignal;
/** Human-readable loading status message. */
loadingStatus: _angular_core.WritableSignal;
/** Set of selected game indices for batch operations like replay-all. */
selectedGames: _angular_core.WritableSignal>;
/** Current white player filter text. */
filterWhite: _angular_core.WritableSignal;
/** Current black player filter text. */
filterBlack: _angular_core.WritableSignal;
/** Selected result filters (e.g. `["1-0", "draw"]`). */
filterResult: _angular_core.WritableSignal;
/** Whether opening-move filtering is active. */
filterMoves: _angular_core.WritableSignal;
/** Whether to swap white/black when filtering (match either color). */
ignoreColor: _angular_core.WritableSignal;
/** Whether Elo rating filter fields are enabled. */
filterRatingEnabled: _angular_core.WritableSignal;
/** Minimum white Elo rating filter value (as string for input binding). */
filterWhiteRating: _angular_core.WritableSignal;
/** Minimum black Elo rating filter value (as string for input binding). */
filterBlackRating: _angular_core.WritableSignal;
/** Maximum white Elo rating filter value (as string for input binding). */
filterWhiteRatingMax: _angular_core.WritableSignal;
/** Maximum black Elo rating filter value (as string for input binding). */
filterBlackRatingMax: _angular_core.WritableSignal;
/** ECO code filter value. */
filterEco: _angular_core.WritableSignal;
/** Time control filter value (e.g. `"180+2"`). */
filterTimeControl: _angular_core.WritableSignal;
/** Event/tournament name filter value. */
filterEvent: _angular_core.WritableSignal;
/** Unique white player names from the loaded PGN (for typeahead). */
uniqueWhitePlayers: _angular_core.WritableSignal;
/** Unique black player names from the loaded PGN (for typeahead). */
uniqueBlackPlayers: _angular_core.WritableSignal;
/** Whether the white player typeahead dropdown is open. */
whiteTypeaheadOpen: _angular_core.WritableSignal;
/** Whether the black player typeahead dropdown is open. */
blackTypeaheadOpen: _angular_core.WritableSignal;
/** Currently highlighted index in the white typeahead dropdown. */
whiteTypeaheadIndex: _angular_core.WritableSignal;
/** Currently highlighted index in the black typeahead dropdown. */
blackTypeaheadIndex: _angular_core.WritableSignal;
/** Timeout handle for delayed closing of the white typeahead dropdown. */
private whiteTypeaheadCloseTimeout;
/** Timeout handle for delayed closing of the black typeahead dropdown. */
private blackTypeaheadCloseTimeout;
/** Filtered white player suggestions based on current filter text. */
filteredWhiteSuggestions: _angular_core.Signal;
/** Filtered black player suggestions based on current filter text. */
filteredBlackSuggestions: _angular_core.Signal;
/** Unique ECO codes mapped to occurrence counts in the loaded PGN. */
uniqueEcoCodes: _angular_core.WritableSignal>;
/** Unique time controls mapped to occurrence counts and original format strings. */
uniqueTimeControls: _angular_core.WritableSignal;
}>>;
/** Unique event/tournament names mapped to occurrence counts. */
uniqueEvents: _angular_core.WritableSignal>;
/** ECO codes sorted by popularity (most frequent first). */
sortedEcoCodes: _angular_core.Signal<{
code: string;
count: number;
}[]>;
/** Time controls sorted by popularity with human-readable labels and original summaries. */
sortedTimeControls: _angular_core.Signal<{
key: string;
count: number;
label: string;
originalsSummary: string;
}[]>;
/** Events sorted by popularity (most frequent first). */
sortedEvents: _angular_core.Signal<{
event: string;
count: number;
}[]>;
/** Indices of games matching the current filter criteria. */
filteredGamesIndices: _angular_core.WritableSignal;
/** Whether a filter operation is in progress. */
isFiltering: _angular_core.WritableSignal;
/** Monotonic counter used as correlation ID for filter requests to the worker. */
private currentFilterId;
/** When `true`, auto-select the first matching game after filtering completes. */
private autoSelectOnFinish;
/** View query for the move list scroll container. */
readonly moveList: _angular_core.Signal | undefined>;
/** Currently active opening move sequence for interactive mode filtering. */
private activeFilterMoves;
/** Saved move index before entering filter-moves mode (restored when exiting). */
private savedGameMoveIndex;
/** Active deferred timeout handles that should be cancelled on destroy. */
private readonly pendingTimeouts;
/** Moves made by the user during interactive opening-move filtering mode. */
private interactiveMoves;
/** Flag to uncheck the filter-moves toggle after a filter operation completes. */
private shouldUncheckFilterMoves;
/** Number of currently selected games for batch operations. */
selectedGamesCount: _angular_core.Signal;
/** Whether the replay-all button should be visible (multiple games + selection). */
canShowReplayAll: _angular_core.Signal;
/** Display string: "Game X of Y". */
currentGameInfo: _angular_core.Signal;
/** Display name of the white player for the current game. */
currentWhitePlayer: _angular_core.Signal;
/** Display name of the black player for the current game. */
currentBlackPlayer: _angular_core.Signal;
/** Formatted result string for the current game. */
currentGameResult: _angular_core.Signal;
/**
* Computed from-to squares of the last move for board highlighting.
* Returns `undefined` when highlighting is disabled or no move has been played.
*/
lastMoveSquares: _angular_core.Signal<[Key, Key] | undefined>;
/** Filtered game metadata for the current filter results. */
filteredGameInfos: _angular_core.Signal;
/** Replay timing mode: fixed, realtime (clock-based), or proportional scaling. */
replayMode: _angular_core.WritableSignal<"realtime" | "proportional" | "fixed">;
/** Total duration in minutes when `replayMode` is `'proportional'`. */
proportionalDuration: _angular_core.WritableSignal;
/** Minimum seconds between moves in `'proportional'` and `'realtime'` modes. */
minSecondsBetweenMoves: _angular_core.WritableSignal;
/** Fixed seconds between moves when `replayMode` is `'fixed'`. */
fixedTime: _angular_core.WritableSignal;
/** Whether to pause replay when a large evaluation change is detected. */
stopOnError: _angular_core.WritableSignal;
/** Evaluation change threshold (in pawns) that triggers a stop. */
stopOnErrorThreshold: _angular_core.WritableSignal;
/** Display string for white's remaining clock time. */
whiteTimeRemaining: _angular_core.WritableSignal;
/** Display string for black's remaining clock time. */
blackTimeRemaining: _angular_core.WritableSignal;
/** Whether either clock has been populated (controls clock display visibility). */
showClocks: _angular_core.Signal;
/** Whether a replay is currently in progress. */
isReplaying: _angular_core.WritableSignal;
/** Whether the replay can be continued from the current move. */
canContinueReplay: _angular_core.Signal;
/** Whether Stockfish is currently analyzing a position. */
isAnalyzing: _angular_core.WritableSignal;
/** Stockfish analysis result: best move, PV line, and optional score. */
bestMoveInfo: _angular_core.WritableSignal<{
move: string;
pv: {
san: string;
fen: string;
}[];
score?: string;
} | null>;
/** Whether to show the "Show Better Move" button after a stop-on-error event. */
showBetterMoveBtn: _angular_core.WritableSignal;
/** Whether the Stockfish analysis panel is currently visible. */
analysisVisible: _angular_core.WritableSignal;
/**
* Converts UCI move strings to SAN notation with resulting FENs.
*
* Used by Stockfish message handling to convert the engine's UCI PV line
* into human-readable SAN for display.
*
* @param fen — Starting FEN position.
* @param uciMoves — Array of UCI move strings (e.g. `["e2e4", "e7e5"]`).
* @returns Array of `{ san, fen }` objects, one per successful move.
*/
private uciToSan;
/**
* Handles UCI protocol messages from the Stockfish Web Worker.
*
* Parses `info ... pv ...` lines to extract the best move, PV line,
* and score (centipawns or mate). Updates {@link bestMoveInfo} and
* sets {@link isAnalyzing} to `false` on `bestmove`.
*
* @param event — Message event from the Stockfish worker.
*/
private handleStockfishMessage;
/**
* Jumps the board display to a given FEN (used for PV preview in analysis).
*
* @param fen — FEN string to display on the board.
*/
previewPvMove(fen: string): void;
/** FEN position currently being analyzed by Stockfish. */
private analyzedFen;
/** Stockfish search depth in plies. */
stockfishDepth: _angular_core.WritableSignal;
/**
* Sends a FEN position to Stockfish for analysis at the configured depth.
*
* Stops any in-progress analysis before starting. Sets {@link isAnalyzing}
* and clears any previous {@link bestMoveInfo}.
*
* @param fen — FEN string of the position to analyze.
*/
analyzePosition(fen: string): void;
/**
* Auto-plays the Stockfish best line on the board with 1-second delays.
*
* Iterates through the PV (principal variation) moves stored in
* {@link bestMoveInfo} and displays each resulting FEN.
*/
autoplayBestLine(): Promise;
/** Raw PGN text bound to the PGN textarea. */
pgnInput: _angular_core.WritableSignal;
/** URL input for fetching remote PGN files. */
urlInput: _angular_core.WritableSignal;
/** Per-move evaluation strings from `[%eval ...]` PGN comments. */
evaluations: _angular_core.WritableSignal<(string | null)[]>;
/** Evaluation string at the current move index, or `null` at start position. */
currentEvaluation: _angular_core.Signal;
/**
* Computed height percentage (0–100) for the evaluation bar.
*
* Maps centipawn scores linearly from -5.0 (0%) to +5.0 (100%).
* Mate scores force 0% or 100%.
*/
evaluationBarHeight: _angular_core.Signal;
/** Active side to move: `'w'` or `'b'` parsed from the current FEN. */
activeColor: _angular_core.Signal;
/** Selected year for Lichess database queries (two-way bound via `model`). */
lichessYear: _angular_core.ModelSignal;
/** Selected month (1–12) for Lichess database queries (two-way bound via `model`). */
lichessMonth: _angular_core.ModelSignal;
/** chess.js instance used for move validation and board state management. */
private chess;
/** Active replay timeout handles (cleared when replay stops). */
private replayTimeouts;
/** Resolve function for the replay-async Promise (called when replay completes). */
private replayResolve;
/** Whether a batch replay sequence across multiple games is in progress. */
private isReplayingSequence;
/**
* Computed run function for the child {@link NgxChessgroundComponent}.
*
* Reacts to changes in FEN, filter-moves mode, and last-move squares.
* In filter-moves mode the board is editable with legal-move highlighting;
* otherwise it is view-only. This is the primary binding between the
* PGN viewer state and the chessboard display.
*/
runFunction: _angular_core.Signal<(el: HTMLElement) => Api>;
/**
* Computes legal move destinations for the current chess.js position.
*
* Returns a `Map` suitable for chessground's
* `movable.dests` configuration in interactive filter-moves mode.
*
* @returns Map of legal destination squares keyed by origin square.
*/
private getMovableDests;
/**
* Processes a move made by the user on the interactive board during filter-moves mode.
*
* If the move is legal, it's appended to {@link interactiveMoves} and the
* board is updated via chess.js. The move is added to {@link activeFilterMoves}
* if it belongs to the opening line being filtered.
*
* @param orig — Origin square (e.g. `"e2"`).
* @param dest — Destination square (e.g. `"e4"`).
*/
private handleBoardMove;
/**
* Initializes the PGN viewer engine workers and sets up reactive effects.
*
* Three effects are registered:
* 1. Auto-updates the Lichess URL when year/month selection changes.
* 2. Loads the initial PGN from the bound input when provided.
* 3. Auto-scrolls the move list when the current move index changes.
*/
constructor();
/**
* Cleans up replay timeouts, workers, and all pending deferred timeouts.
*
* Called automatically by Angular when the component is destroyed.
*/
ngOnDestroy(): void;
/**
* Updates the Stockfish search depth from an input event.
*
* @param event — Input event from the depth slider/number input.
*/
onStockfishDepthChange(event: Event): void;
/**
* Creates a tracked `setTimeout` that is automatically cancelled on destroy.
*
* All timeout handles are stored in {@link pendingTimeouts} and cleared
* in {@link ngOnDestroy} to prevent memory leaks.
*
* @param callback — Function to execute after the delay.
* @param delay — Delay in milliseconds (default 0).
* @returns The timeout handle.
*/
private setDeferredTimeout;
/**
* Shows a Material snackbar notification to the user.
*
* @param message — Text to display in the snackbar.
* @param duration — Auto-dismiss duration in milliseconds (default 4000).
*/
private showMessage;
/**
* Routes PGN processor worker responses to the appropriate handler logic.
*
* Handles `'load'` (populate metadata, unique players, ECO codes),
* `'filter'` (update filtered indices, auto-select game),
* `'loadGame'` (display moves, evaluations, clocks), and `'error'` messages.
*
* @param data — Response from the PGN processor worker.
*/
private handleWorkerMessage;
/**
* Formats a normalized time control key for display.
*
* Converts `"seconds+increment"` (e.g. `"5400+30"`) to a human-readable
* form using minutes when divisible by 60 and ≤ 180 (e.g. `"90+30"`).
*
* @param key — Normalized time control string like `"5400+30"`.
* @returns Display-friendly time control string.
*/
private formatTimeControlKey;
/**
* Builds a summary string of the most common original time control formats.
*
* @param originals — Map of original format strings to occurrence counts.
* @param maxItems — Maximum number of entries to include (default 6).
* @returns Summary string like `"Originals: 90+30 (500), 180+2 (300) +3 more"`.
*/
private formatOriginalsSummary;
/**
* Applies the current filter criteria and re-runs game filtering.
*
* Stops any in-progress replay and delegates to {@link runFilterLogic}
* with the values from the filter signal state. Auto-selects the first
* matching game when filtering completes.
*/
applyFilter(): void;
/**
* Resets all filter fields to their default values and stops any in-progress replay.
*
* If the filter-moves mode was active, it's exited and the saved position is restored.
*/
clearFilters(): void;
/**
* Sends filter criteria to the PGN processor worker and tracks the request.
*
* Increments a monotonic filter ID to detect stale responses.
* Called by {@link applyFilter} after collecting current signal values.
*
* @param fWhite — White player filter text.
* @param fBlack — Black player filter text.
* @param fResult — Comma-separated result filter string.
* @param fMoves — Whether opening-move filtering is enabled.
* @param fIgnoreColor — Whether to swap white/black matching.
* @param fWhiteRating — Minimum white Elo.
* @param fBlackRating — Minimum black Elo.
* @param fWhiteRatingMax — Maximum white Elo.
* @param fBlackRatingMax — Maximum black Elo.
* @param fEco — ECO code filter.
* @param fTimeControl — Time control filter.
* @param fEvent — Event name filter.
* @param targetMoves — SAN move sequence to match.
*/
private runFilterLogic;
/**
* Loads a raw PGN string into the viewer, resetting current game state.
*
* Delegates to {@link PgnViewerEngineService.loadPgn} for background parsing.
* The worker response (via {@link handleWorkerMessage}) populates metadata
* and triggers the first game load.
*
* @param pgn — Raw PGN text (supports multi-game, compressed formats).
*/
loadPgnString(pgn: string): void;
/**
* Reads PGN text from the system clipboard and loads it into the viewer.
*
* Uses the Clipboard API. On failure, shows an error snackbar.
*/
loadFromClipboard(): Promise;
/**
* Copies the current PGN text to the system clipboard.
*
* Uses the Clipboard API. On failure, shows an error snackbar.
*/
copyToClipboard(): Promise;
/**
* Updates the proportional replay duration from an input event.
*
* @param event — Change event from the proportional duration input.
*/
onProportionalDurationChange(event: Event): void;
/**
* Updates the minimum-seconds-between-moves setting from an input event.
*
* @param event — Change event from the minimum seconds input.
*/
onMinSecondsBetweenMovesChange(event: Event): void;
/**
* Updates the fixed-time replay setting from an input event.
*
* @param event — Change event from the fixed time input.
*/
onFixedTimeChange(event: Event): void;
/**
* Updates the PGN input text from a textarea change event.
*
* @param event — Change event from the PGN textarea input.
*/
onPgnInputChange(event: Event): void;
/**
* Updates the URL input from a text input change event.
*
* @param event — Change event from the URL text input.
*/
onUrlInputChange(event: Event): void;
/**
* Updates the event filter from a select element change event.
*
* @param event — Change event from the event filter `` element.
*/
updateFilterEvent(event: Event): void;
/**
* Returns the list of years available in the Lichess database picker.
*
* Years range from 2020 to the current year.
*
* @returns Array of available year numbers.
*/
getLichessYears(): number[];
/**
* Returns the list of months available for the currently selected Lichess year.
*
* For past years, all 12 months are available. For the current year,
* only months up to (current month - 1) are available.
*
* @returns Array of available month numbers (1–12).
*/
getLichessMonths(): number[];
/**
* Updates the Lichess year selection and adjusts the month if needed.
*
* If the currently selected month is not available for the new year,
* it falls back to the last available month.
*
* @param event — Change event from the year `` element.
*/
onLichessYearChange(event: Event): void;
/**
* Updates the Lichess month selection from a select element change event.
*
* @param event — Change event from the month `` element.
*/
onLichessMonthChange(event: Event): void;
/**
* Loads a PGN file from the Lichess broadcast database.
*
* Constructs the URL from the selected year and month
* (`lichess_db_broadcast_YYYY-MM.pgn.zst`) and delegates to {@link loadFromUrl}.
*/
loadFromLichess(): void;
/**
* Fetches a PGN file from the URL in {@link urlInput} and loads it into the viewer.
*
* Supports plain `.pgn`, gzip-compressed `.pgn.gz`, and zstd-compressed `.pgn.zst`.
* Shows a progress bar during download and delegates decompression/parsing.
*/
loadFromUrl(): Promise;
/**
* Reads a user-selected ZIP file containing PGN files and loads the first
* `.pgn` entry found.
*
* Uses jszip to extract the archive.
*
* @param event — Change event from the ZIP file ` ` element.
*/
onPgnZipSelected(event: Event): Promise;
/**
* Reads a user-selected PGN file from a file input and loads it into the viewer.
*
* Handles `.pgn` and `.pgn.gz` files via the browser's FileReader API.
*
* @param event — Change event from the file ` ` element.
*/
onPgnFileSelected(event: Event): void;
/**
* Loads a specific game by its index in the parsed game list.
*
* Delegates parsing to the PGN processor worker. The response
* (via {@link handleWorkerMessage}) updates moves, evaluations, and clocks.
*
* @param index — Zero-based game index.
*/
loadGame(index: number): void;
/**
* Toggles a game's selection state for batch replay operations.
*
* @param index — Zero-based game index to toggle.
*/
toggleGameSelection(index: number): void;
/** Selects all games in the current filtered list for batch replay. */
selectAllGames(): void;
/** Clears all game selections. */
clearSelection(): void;
/** Advances to the next game in the list, if available. */
nextGame(): void;
/** Moves to the previous game in the list, if available. */
prevGame(): void;
/**
* Jumps the board to a specific move index, replaying all moves up to that point.
*
* `-1` resets to the starting position before any moves.
*
* @param index — The target move index (-1 for start position).
*/
jumpToMove(index: number): void;
/** Scrolls the move list container to keep the active move visible. */
private scrollToActiveMove;
/**
* Advances to the next move in the current game.
*
* Updates the board, move index, and clock display.
*/
next(): void;
/**
* Goes back one move in the current game.
*
* Undoes the last move on the board and updates the clock display.
*/
prev(): void;
/** Stops any in-progress replay sequence and cancels pending timeouts. */
stopSequence(): void;
/**
* Toggles the rating filter enable/disable checkbox.
*
* @param event — Change event from the rating-filter checkbox.
*/
toggleFilterRatingEnabled(event: Event): void;
/**
* Applies a rating preset (e.g. "2000+", "2500+", "3000+") from a dropdown.
*
* Sets the minimum rating to the selected value and the maximum to 3000
* (or 4000 for the "3000+" tier).
*
* @param event — Change event from the rating preset `` element.
*/
applyRatingPreset(event: Event): void;
/**
* Toggles the "stop on error" replay option.
*
* @param event — Change event from the stop-on-error checkbox.
*/
toggleStopOnError(event: Event): void;
/**
* Updates the stop-on-error evaluation threshold from an input event.
*
* @param event — Input event from the threshold number field.
*/
updateStopOnErrorThreshold(event: Event): void;
/**
* Resets the board to the starting position (before any moves).
*
* Also restores initial clock times if clock history data is available.
*/
start(): void;
/**
* Jumps to the final position of the current game.
*
* Replays all moves from the start to reach the end-of-game position.
*/
end(): void;
/**
* Starts an auto-replay of the current game from the beginning.
*
* Stops any in-progress replay, resets to the start position,
* then runs the replay logic with timing based on the selected mode.
*/
replayGame(): void;
/**
* Continues an auto-replay from the current move position.
*
* Preserves the replay Promise (doesn't resolve it prematurely)
* so batch replay sequences can resume from where they left off.
*/
continueReplay(): void;
/**
* Executes the replay logic for the currently loaded game.
*
* Parses the game PGN, calculates move timing based on the selected
* {@link replayMode}, and schedules the replay via {@link scheduleReplay}.
*/
private runReplayLogic;
/**
* Sequentially replays all selected games in the filtered game list.
*
* Each game is loaded, replayed from start to finish, then a 2-second pause
* is inserted before the next game. Respects the current filter sort order.
*/
replayAllSelectedGames(): Promise;
/**
* Returns a Promise that resolves when the current game's replay completes.
*
* Used by batch replay sequences to await each game's auto-play before
* moving to the next selected game.
*
* @returns Promise resolved by {@link scheduleReplay} via {@link replayResolve}.
*/
private replayGameAsync;
/**
* Stops any in-progress replay, clears scheduled timeouts, and optionally
* resolves the replay Promise used by batch replay sequences.
*
* @param resolvePromise — When `true` (default), resolve any pending replay Promise.
*/
stopReplay(resolvePromise?: boolean): void;
/**
* Calculates replay timeouts by parsing clock comments from the PGN via chessops.
*
* Fallback used when chess.js parsing fails. Reads `[%clk h:m:s]` comments
* to determine think time per move in `'realtime'` and `'proportional'` modes.
*
* @param pgn — Raw PGN string for the game.
* @returns Array of seconds delays, one per move.
*/
private calculateReplayTimeoutsChessops;
/**
* Clock state at each half-move: remaining seconds for white and black.
* Index 0 is the initial clock state. Populated by {@link calculateReplayTimeouts}.
*/
private clockHistory;
/**
* Calculates per-move replay delays from game history and clock comments.
*
* Parses `[%clk h:m:s]` comments to compute think times. Supports three modes:
* `'fixed'` (constant delay), `'realtime'` (actual think time), and
* `'proportional'` (scaled to fit {@link proportionalDuration}).
*
* @param history — Verbose move history from chess.js.
* @returns Array of seconds delays, one per move.
*/
private calculateReplayTimeouts;
/**
* Formats a duration in seconds as a clock display string.
*
* @param seconds — Duration in seconds.
* @returns Formatted string: `"h:mm:ss"` or `"m:ss"`.
*/
private formatTime;
/**
* Parses a `[%eval ...]` PGN comment value into a numeric score.
*
* Mate scores (`#3`, `#-2`) are converted to large values near ±20.
* Centipawn scores are parsed as floats.
*
* @param evalStr — Raw evaluation string, or `null`.
* @returns Numeric evaluation score, or `null` if unparseable.
*/
private parseEval;
/**
* Schedules timed callbacks to auto-play moves during replay.
*
* Uses the selected replay mode timing, handles the "stop on error" feature
* (pauses when evaluation change exceeds {@link stopOnErrorThreshold}),
* and calls the optional `onComplete` callback after the last move.
*
* @param timeOuts — Per-move delays in seconds.
* @param totalMoves — Total number of moves in the game.
* @param onComplete — Optional callback when replay finishes.
*/
private scheduleReplay;
/**
* Returns the FEN string representing the position before a given move.
*
* Used by the "stop on error" feature to determine the position where
* a large evaluation swing occurred.
*
* @param moveIndex — The 0-based move index. Returns the FEN before this move.
* @returns FEN string, or `null` on error.
*/
private getFenBeforeMove;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵcmp: _angular_core.ɵɵComponentDeclaration;
}
/**
* Callback interface for PGN viewer engine events.
* Consumer components implement these handlers to react to worker messages.
*/
interface PgnViewerEngineCallbacks {
/** Called when the PGN processor worker sends a response (parse, filter, load results). */
onPgnMessage: (data: WorkerResponse) => void;
/** Called when the Stockfish worker sends analysis output (UCI protocol messages). */
onStockfishMessage: (event: MessageEvent) => void;
/** Optional error handler for worker initialization failures. */
onError?: (message: string, error?: unknown) => void;
}
/**
* Service that manages Web Workers for background PGN processing and Stockfish analysis.
*
* Maintains two workers:
* - **PGN processor** — parses/filters PGN data off the main thread using `pgn-processor.worker`.
* - **Stockfish** — runs the Stockfish chess engine for position analysis via UCI protocol.
*
* Provided at root level so a single instance is shared across the application.
* Callers must call {@link initialize} before using the service and {@link dispose} when done.
*/
declare class PgnViewerEngineService {
/** Web Worker for PGN parsing and filtering. */
private pgnWorker;
/** Web Worker running the Stockfish chess engine. */
private stockfishWorker;
/**
* Creates and initializes both Web Workers.
*
* Disposes any existing workers first, then spawns new ones.
* The Stockfish worker is started in UCI mode immediately.
*
* @param callbacks — Event handlers for worker messages and errors.
* @returns `true` if workers were created successfully, `false` if Web Workers are unsupported.
*/
initialize(callbacks: PgnViewerEngineCallbacks): boolean;
/**
* Sends raw PGN text to the parser worker for processing.
*
* @param pgn — Raw PGN string (supports multi-game, compressed formats).
* @param id — Correlation ID echoed back in the worker response for matching requests.
*/
loadPgn(pgn: string, id: number): void;
/**
* Filters the parsed game list by the given criteria.
*
* @param payload — Filter criteria (player names, ECO, draw inclusion, opening moves, ratings).
* @param id — Correlation ID echoed back in the worker response.
*/
filterGames(payload: FilterCriteria, id: number): void;
/**
* Loads the full move data for a specific game by its index in the parsed list.
*
* @param index — Zero-based index of the game to load.
* @param id — Correlation ID echoed back in the worker response.
*/
loadGame(index: number, id: number): void;
/**
* Sends a FEN position to Stockfish for analysis at the given search depth.
*
* Stops any in-progress analysis before starting the new one.
*
* @param fen — FEN string of the position to analyze.
* @param depth — Search depth in plies.
* @returns `false` if the Stockfish worker is not available, `true` otherwise.
*/
analyzePosition(fen: string, depth: number): boolean;
/**
* Terminates both workers and releases resources.
*
* Sends a 'quit' command to Stockfish before terminating to allow
* the engine to shut down gracefully.
*/
dispose(): void;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵprov: _angular_core.ɵɵInjectableDeclaration;
}
/**
* Data passed to the promotion dialog.
*/
interface PromotionDialogData {
/** The color of the promoting pawn — determines piece set rendering. */
color: 'white' | 'black';
}
/**
* Legal promotion piece choices.
* - `'q'` — Queen
* - `'r'` — Rook
* - `'b'` — Bishop
* - `'n'` — Knight
*/
type PromotionPiece = 'q' | 'r' | 'b' | 'n';
/**
* A Material dialog that lets the user choose a piece for pawn promotion.
*
* Displays four buttons (Queen, Rook, Bishop, Knight) styled with Unicode
* chess piece characters. On selection, the dialog closes with the chosen
* {@link PromotionPiece} string. If dismissed without selection, defaults to `'q'`.
*
* @remarks The component uses `ChangeDetectionStrategy.Default` for zoneless compatibility
* but has been partially migrated and may be switched to `OnPush` after testing.
*/
declare class PromotionDialogComponent {
/** Reference to this dialog instance, used to close it with the selection result. */
readonly dialogRef: MatDialogRef;
/** Dialog input data (reactive signal) containing the promoting pawn's color. */
readonly data: _angular_core.WritableSignal;
/**
* Closes the dialog with the user's chosen promotion piece.
*
* @param piece — The selected piece: `'q'`, `'r'`, `'b'`, or `'n'`.
*/
selectPiece(piece: PromotionPiece): void;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵcmp: _angular_core.ɵɵComponentDeclaration;
}
/**
* Service that opens a Material dialog for pawn promotion selection.
*
* Used by chess units and components when a pawn reaches the eighth rank.
* The dialog presents Queen, Rook, Bishop, and Knight options.
*
* Provided at root level so any component can inject it.
*
* @example
* ```typescript
* const promotionService = inject(PromotionService);
* const piece = await promotionService.showPromotionDialog('white');
* // piece is 'q', 'r', 'b', or 'n'
* ```
*/
declare class PromotionService {
/** Material dialog service used to open the promotion dialog. */
private readonly dialog;
/**
* Opens the promotion dialog and returns the user's selection.
*
* The dialog is modal (disableClose) with a backdrop.
* Defaults to Queen ('q') if the dialog is dismissed without selection.
*
* @param color — The color of the promoting pawn ('white' or 'black').
* @returns A Promise resolving to the chosen piece: `'q'` (Queen), `'r'` (Rook),
* `'b'` (Bishop), or `'n'` (Knight).
*/
showPromotionDialog(color: 'white' | 'black'): Promise;
static ɵfac: _angular_core.ɵɵFactoryDeclaration;
static ɵprov: _angular_core.ɵɵInjectableDeclaration;
}
/**
* Represents a unit with a name and a run method.
*/
interface Unit {
/**
* The name of the unit.
*/
name: string;
/**
* Executes the unit's functionality.
*
* @param el - The HTML element to run the unit on.
* @returns An instance of Api.
*/
run: (el: HTMLElement) => Api;
}
/**
* Represents a unit of animation for a chess conflict scenario.
*
* @constant
* @type {Unit}
* @name conflictingAnim
*
* @property {string} name - The name of the animation unit.
* @property {Function} run - The function to execute the animation.
* @param {HTMLElement} el - The HTML element to attach the Chessground instance to.
* @returns {Chessground} The Chessground instance with the specified configuration.
*
* The animation runs with the following configuration:
* - Duration: 500ms
* - Initial FEN: "8/8/5p2/4P3/4K3/8/8/8"
* - Turn color: Black
* - Movable color: White
* - Movable pieces are not free to move initially
*
* After 2 seconds, the black pawn on f6 moves to e5, and the turn color changes to white.
* The white king on e4 can then move to e5, d5, or f5.
*/
declare const conflictingAnim: Unit;
/**
* Represents a unit test for animating chess moves with the same role.
*
* This unit test initializes a Chessground instance with a specific FEN position
* and animates two moves sequentially with a delay between them.
*
* @constant
* @type {Unit}
* @name withSameRole
* @property {string} name - The name of the unit test.
* @property {function} run - The function that runs the unit test.
* @param {HTMLElement} el - The HTML element to initialize the Chessground instance on.
* @returns {Chessground} The initialized Chessground instance.
*/
declare const withSameRole: Unit;
/**
* Represents a unit test for an animation where pieces of different roles are moved.
*
* @constant
* @type {Unit}
* @name notSameRole
* @property {string} name - The name of the unit test.
* @property {function} run - The function that runs the unit test.
* @param {HTMLElement} el - The HTML element where the Chessground instance will be initialized.
* @returns {Chessground} - The Chessground instance after performing the moves.
*
* The test initializes a Chessground instance with a specific FEN position and turn color.
* It then performs a sequence of moves with a delay to test the animation of pieces with different roles.
*/
declare const notSameRole: Unit;
/**
* Represents a unit that performs an animation while holding a piece on a chessboard.
*
* @constant
* @type {Unit}
* @name whileHolding
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that executes the animation.
*
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
*
* @returns {Chessground} - The Chessground instance with the specified configuration.
*
* The `run` function initializes a Chessground instance with a specific FEN position and configuration.
* It sets the turn color to black and specifies an animation duration of 5000 milliseconds.
* After a timeout of 3000 milliseconds, it moves a piece from f6 to e5, changes the turn color to white,
* and sets the movable destinations for the white piece on e4. Finally, it plays any premoves.
*/
declare const whileHolding: Unit;
/**
* Default configuration for a unit.
*
* @constant
* @type {Unit}
* @property {string} name - The name of the configuration.
* @property {function} run - Function to initialize Chessground with the given element.
* @param {HTMLElement} el - The HTML element to initialize Chessground on.
* @returns {Chessground} - The initialized Chessground instance.
*/
declare const defaults: Unit;
/**
* Represents a unit that initializes a chessboard from a FEN string with the black player's perspective.
*
* @constant
* @type {Unit}
* @name fromFen
*
* @property {string} name - The name of the unit.
* @property {function} run - The function that initializes the chessboard.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance.
*/
declare const fromFen: Unit;
/**
* Represents a unit that simulates the last move in a Crazyhouse chess game.
*
* @constant
* @type {Unit}
* @name lastMoveCrazyhouse
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the Chessground instance and sets the last moves.
* @param {HTMLElement} el - The HTML element to initialize the Chessground on.
* @returns {Chessground} The initialized Chessground instance with the last moves set.
*/
declare const lastMoveCrazyhouse: Unit;
/**
* Represents a unit that highlights the king in check on a chessboard.
*
* @constant
* @type {Unit}
* @name checkHighlight
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the chessboard with the specified FEN and highlights the king in check.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance with the king in check highlighted.
*/
declare const checkHighlight: Unit;
/**
* Represents a unit that automatically switches between different FEN configurations
* to demonstrate a puzzle bug in a chess game.
*
* @constant
* @type {Unit}
* @name autoSwitch
*
* @property {string} name - The name of the unit.
* @property {function} run - The function that runs the unit.
*
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance.
*
* The `run` function initializes a Chessground instance with the first configuration
* and then switches between the configurations every 2000 milliseconds.
*
* The configurations are defined as an array of functions, each returning an object
* with the following properties:
* - `orientation`: The orientation of the board ("black" or "white").
* - `fen`: The FEN string representing the board position.
* - `lastMove`: An array of keys representing the last move made.
*/
declare const autoSwitch: Unit;
/**
* Default configuration for the 3D theme unit.
*
* @constant
* @type {Unit}
* @name in3dDefaults
*
* @property {string} name - The name of the unit.
* @property {function} run - The function to initialize and run the 3D theme.
*
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance with 3D theme settings.
*/
declare const in3dDefaults: Unit;
/**
* Represents a unit for a 3D chess theme where the player plays against a random AI.
*
* @constant
* @type {Unit}
* @name vsRandom
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function to initialize and run the unit.
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance.
*/
declare const vsRandom: Unit;
/**
* Represents a 3D theme where two random AIs play against each other.
*
* @constant
* @type {Unit}
* @name fullRandom
*
* @property {string} name - The name of the unit.
* @property {function} run - The function to execute the unit.
*
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance.
*
* The `run` function initializes a Chessground instance with a 3D theme and sets up a game
* where two random AIs play against each other. Moves are made at a fixed delay interval.
*/
declare const fullRandom: Unit;
/**
* Represents a unit test for the performance of a piece move in a chess game.
*
* @constant
* @type {Unit}
* @name move
*
* @property {string} name - The name of the performance test.
* @property {function} run - The function that runs the performance test.
*
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
*
* @returns {Chessground} - The Chessground instance used for the performance test.
*
* The `run` function initializes a Chessground instance with a specified animation duration.
* It then defines a recursive function `run` that moves a piece from "e2" to "a8" and back
* to "e2" with a delay between moves. The recursive function continues to run as long as
* the chessboard is visible.
*/
declare const move: Unit;
/**
* Represents a unit test for the performance of square selection in a chessboard.
*
* @constant
* @type {Unit}
* @name select
* @property {string} name - The name of the performance test.
* @property {function} run - The function that runs the performance test.
* @param {HTMLElement} cont - The container element for the chessboard.
* @returns {Chessground} - The Chessground instance.
*
* The `run` function initializes a Chessground instance with specific movable
* destinations for the square "e2". It then repeatedly selects the square "e2"
* and "d4" with a delay of 500 milliseconds between each selection.
*/
declare const select: Unit;
/**
* Unit to replay a PGN (Portable Game Notation) game in real time.
*
* @constant
* @type {Unit}
* @name loadPgnRealTime
* @property {string} name - The name of the unit.
* @property {Function} run - Function to execute the replay of the PGN game.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance used to render the chessboard and replay the game.
*
* The function performs the following steps:
* 1. Initializes a new Chess instance and loads the PGN data.
* 2. Creates a new Chessground instance with specific animation and movement settings.
* 3. Retrieves the move history and comments from the PGN.
* 4. Calculates the time control and think times for each move.
* 5. Sets timeouts to replay each move on the chessboard in real time.
*/
declare const loadPgnRealTime: Unit;
/**
* Represents a unit that replays a PGN (Portable Game Notation) game with one second per move.
*
* @constant
* @type {Unit}
* @name loadPgnOneSecondPerMove
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that executes the unit.
*
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance with the replayed game.
*
* The `run` function performs the following steps:
* 1. Initializes a new Chess instance and loads the PGN.
* 2. Creates a new Chessground instance with specific animation and movement settings.
* 3. Retrieves the move history and comments from the Chess instance.
* 4. Iterates through the move history and replays each move on the Chessground board with a one-second interval.
*/
declare const loadPgnOneSecondPerMove: Unit;
/**
* Unit to replay a PGN game in proportional time of 1 minute.
*
* @constant
* @type {Unit}
* @name loadPgnProportionalTime
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function to execute the unit.
*
* @param {HTMLElement} el - The HTML element to attach the chessboard to.
*
* @returns {Chessground} - The Chessground instance with the replayed game.
*
* The `run` function performs the following steps:
* 1. Initializes a new Chess instance and loads the PGN.
* 2. Creates a new Chessground instance with specific animation and movement settings.
* 3. Retrieves the move history and comments from the chess instance.
* 4. Calculates the think time for each move based on the comments.
* 5. Sets timeouts to replay each move on the Chessground instance in proportional time.
*/
declare const loadPgnProportionalTime: Unit;
/**
* Factory function to create units that use dialog-based promotion.
* This allows the components to pass in the PromotionService dependency.
*/
declare function createPlayUnitsWithDialog(promotionService?: PromotionService): {
initial: Unit;
castling: Unit;
playVsRandom: Unit;
playFullRandom: Unit;
slowAnim: Unit;
conflictingHold: Unit;
};
/**
* The `initial` constant represents a unit that sets up a chessboard with the initial position
* and allows playing legal moves from that position.
*
* @constant
* @type {Unit}
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the chessboard and sets up the game.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance.
*
* The `run` function performs the following tasks:
* - Creates a new instance of the Chess game.
* - Initializes the Chessground with the given HTML element and configuration options.
* - Sets up the chessboard to allow only legal moves for the white player.
* - Enables draggable pieces with ghost images.
* - Defines an event handler for the move event.
* - Updates the Chessground configuration to handle moves for the other side after a move is made.
*/
declare const initial: Unit;
/**
* Represents the castling unit in a chess game.
*
* @constant
* @type {Unit}
* @name castling
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function to execute the castling logic.
*
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance with the castling configuration.
*
* The `run` function initializes a chessboard with a given FEN string representing the board state.
* It sets up the Chessground instance with the appropriate configuration for castling moves.
* The function also sets up an event to handle moves after the current move.
*/
declare const castling: Unit;
/**
* Represents a unit that allows playing against a random AI.
*
* @constant
* @type {Unit}
* @name playVsRandom
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function to initialize the chess game against the random AI.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} - The initialized Chessground instance.
*/
declare const playVsRandom: Unit;
/**
* Represents a unit that simulates a chess game between two random AIs.
* The game is displayed on a Chessground board with animations.
*
* @constant
* @type {Unit}
* @name playFullRandom
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes and runs the unit.
* @param {HTMLElement} el - The HTML element where the Chessground board will be rendered.
* @returns {Chessground} - The Chessground instance displaying the game.
*/
declare const playFullRandom: Unit;
/**
* Represents a unit configuration for playing against a random AI with slow animations.
*
* @constant
* @type {Unit}
* @name slowAnim
*
* @property {string} name - The name of the unit configuration.
* @property {Function} run - The function to execute the unit configuration.
*
* @param {HTMLElement} el - The HTML element to initialize the chessground on.
*
* @returns {Chessground} - The initialized chessground instance.
*/
declare const slowAnim: Unit;
/**
* Represents a unit that demonstrates a conflicting hold/premove scenario in a chess game.
*
* This unit sets up a chessboard with a specific FEN position and simulates a move conflict
* where a black pawn moves to a square that a white pawn is attempting to move to.
*
* @constant
* @type {Unit}
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the chessboard and runs the scenario.
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
* @returns {Chessground} The Chessground instance representing the chessboard.
*/
declare const conflictingHold: Unit;
/**
* Represents a unit test case for preset user shapes in Chessground.
* This unit initializes a Chessground instance with predefined drawable shapes.
*
* @type {Unit}
* @property {string} name - The name of the unit test case
* @property {(el: HTMLElement) => Api} run - Function that initializes Chessground with preset shapes
*/
declare const presetUserShapes: Unit;
/**
* Unit test for automatically changing shapes with high difference between states
* Creates a Chessground instance that cycles through different shape sets at regular intervals
*
* @property {string} name - The name of the unit test
* @property {function} run - Function that executes the shape changing logic
* @param {HTMLElement} el - The DOM element where Chessground will be mounted
* @returns {Api} The Chessground API instance
*
* @remarks
* The function cycles through three predefined shape sets (shapeSet1, shapeSet2, shapeSet3)
* with a delay of 1000ms between changes. The cycling continues until the board
* is no longer in the DOM (checked via offsetParent).
*/
declare const changingShapesHigh: Unit;
/**
* Represents a unit that automatically changes shapes with a low difficulty level.
*
* @constant
* @type {Unit}
* @name changingShapesLow
*
* @property {string} name - The name of the unit.
* @property {function} run - The function that initializes the Chessground instance and starts the automatic shape changing.
*
* @param {HTMLElement} el - The HTML element where the Chessground instance will be initialized.
*
* @returns {Chessground} The initialized Chessground instance.
*/
declare const changingShapesLow: Unit;
/**
* Represents a unit that applies brush modifiers to drawable shapes on a chessboard.
*
* @constant
* @type {Unit}
* @name brushModifiers
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the brush modifiers on the given element.
*
* @param {HTMLElement} el - The HTML element to which the brush modifiers will be applied.
*
* @returns {Chessground} - The Chessground instance with the applied brush modifiers.
*
* The `run` function:
* - Generates sets of drawable shapes with random brush modifiers.
* - Initializes a Chessground instance with the first set of shapes.
* - Continuously updates the shapes on the chessboard at a specified interval.
*/
declare const brushModifiers: Unit;
/**
* Represents a unit that automatically generates and sets shapes on a chessboard.
*
* @constant
* @type {Unit}
* @name autoShapes
*
* @property {string} name - The name of the unit.
* @property {function} run - The function that initializes and runs the auto shape generation.
*
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
*
* @returns {Chessground} - The Chessground instance with auto shapes functionality.
*/
declare const autoShapes: Unit;
/**
* A unit configuration for creating a Chessground instance with shapes not visible.
*
* @constant
* @type {Unit}
* @name visibleFalse
*
* @property {string} name - The name of the unit.
* @property {Function} run - A function that initializes a Chessground instance with the specified element.
* @param {HTMLElement} el - The HTML element to initialize the Chessground instance on.
*
* @example
* // Usage example:
* visibleFalse.run(document.getElementById('chessboard'));
*/
declare const visibleFalse: Unit;
/**
* A unit configuration object for a chessboard with shapes that are not enabled but still visible.
*
* @constant
* @type {Unit}
* @property {string} name - The name of the unit.
* @property {function} run - A function that initializes a Chessground instance with the given element.
* @param {HTMLElement} el - The HTML element to initialize the Chessground instance on.
* @returns {void}
*/
declare const enabledFalse: Unit;
/**
* Generates a map of possible destination squares for each piece on the board.
*
* @param chess - An instance of the Chess game.
* @returns A map where the keys are the squares with pieces that have legal moves,
* and the values are arrays of destination squares for those pieces.
*/
declare function toDests(chess: Chess): Map;
/**
* Converts the current turn of a chess game to a color string.
*
* @param chess - An instance of a chess game.
* @returns The color string "white" if it's white's turn, otherwise "black".
*/
declare function toColor(chess: Chess): Color;
/**
* Creates a function that makes a move on the chessboard and updates the state of the chess game.
* Uses window.prompt for pawn promotion (legacy method).
*
* @param cg - The chessground API instance.
* @param chess - The chess.js instance representing the current state of the chess game.
* @returns A function that takes the origin and destination squares of a move, makes the move on the chessboard,
* and updates the turn color and movable destinations in the chessground instance.
*/
declare function playOtherSide(cg: Api, chess: Chess): (orig: Key, dest: Key) => void;
/**
* Creates an async function that makes a move on the chessboard and updates the state of the chess game.
* Uses a promotion service for pawn promotion (modern method with dialog).
*
* @param cg - The chessground API instance.
* @param chess - The chess.js instance representing the current state of the chess game.
* @param promotionService - The promotion service to handle pawn promotion dialog.
* @returns A function that takes the origin and destination squares of a move, makes the move on the chessboard,
* and updates the turn color and movable destinations in the chessground instance.
*/
declare function playOtherSideWithDialog(cg: Api, chess: Chess, promotionService: PromotionService): (orig: Key, dest: Key) => Promise;
/**
* Executes an AI move in a chess game after a specified delay.
*
* @param cg - The chessground API instance.
* @param chess - The chess.js instance.
* @param delay - The delay in milliseconds before the AI makes a move.
* @param firstMove - A boolean indicating if this is the first move of the game.
* @returns A function that takes the origin and destination squares of the player's move.
*/
declare function aiPlay(cg: Api, chess: Chess, delay: number, firstMove: boolean): (orig: Key, dest: Key) => void;
/**
* Represents a unit configuration for a chessboard that is view-only and
* features two random AIs making moves.
*
* @constant
* @type {Unit}
* @name viewOnlyFullRandom
*
* @property {string} name - The name of the unit.
* @property {Function} run - The function that initializes the chessboard
* and starts the random AI moves.
*
* @param {HTMLElement} el - The HTML element where the chessboard will be rendered.
*
* @returns {Chessground} - The initialized Chessground instance.
*/
declare const viewOnlyFullRandom: Unit;
/**
* Represents a unit for the Crazyhouse variant where the last move is a drop.
* This unit runs a sequence of configurations on a chessboard, each with a specific FEN and last move.
* The configurations are cycled through with a delay between each change.
*
* @constant
* @type {Unit}
* @name lastMoveDrop
*
* @property {string} name - The name of the unit.
* @property {function} run - The function that runs the unit.
* @param {HTMLElement} cont - The container element where the chessboard will be rendered.
* @returns {Chessground} - The Chessground instance.
*/
declare const lastMoveDrop: Unit;
export { NgxChessgroundComponent, NgxChessgroundTableComponent, NgxPgnViewerComponent, PgnViewerEngineService, PromotionDialogComponent, PromotionService, aiPlay, autoShapes, autoSwitch, brushModifiers, castling, changingShapesHigh, changingShapesLow, checkHighlight, conflictingAnim, conflictingHold, createPlayUnitsWithDialog, defaults, enabledFalse, fromFen, fullRandom, in3dDefaults, initial, lastMoveCrazyhouse, lastMoveDrop, loadPgnOneSecondPerMove, loadPgnProportionalTime, loadPgnRealTime, move, notSameRole, playFullRandom, playOtherSide, playOtherSideWithDialog, playVsRandom, presetUserShapes, select, slowAnim, toColor, toDests, viewOnlyFullRandom, visibleFalse, vsRandom, whileHolding, withSameRole };
export type { PromotionDialogData, PromotionPiece, Unit };