From a31aa8ac933311a25931b386e55b55f4da9920c1 Mon Sep 17 00:00:00 2001 From: David Paz Date: Thu, 8 Feb 2018 00:01:41 +0100 Subject: [PATCH 1/3] Add types definitions for chessboardjs --- types/chessboardjs/chessboardjs-tests.ts | 92 ++++++++++++++++++++++++ types/chessboardjs/index.d.ts | 89 +++++++++++++++++++++++ types/chessboardjs/tsconfig.json | 25 +++++++ types/chessboardjs/tslint.json | 79 ++++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 types/chessboardjs/chessboardjs-tests.ts create mode 100644 types/chessboardjs/index.d.ts create mode 100644 types/chessboardjs/tsconfig.json create mode 100644 types/chessboardjs/tslint.json diff --git a/types/chessboardjs/chessboardjs-tests.ts b/types/chessboardjs/chessboardjs-tests.ts new file mode 100644 index 0000000000..b2750b0473 --- /dev/null +++ b/types/chessboardjs/chessboardjs-tests.ts @@ -0,0 +1,92 @@ +import chessboardjs = require('chessboardjs'); + +/** + * Basic Usage + */ + +// empty position +var board = chessboardjs.ChessBoard('board'); + +// Start position +var board = chessboardjs.ChessBoard('board', 'start'); + +// FEN string +var ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R'; +var board = chessboardjs.ChessBoard('board', ruyLopez); + +// Position Object +var position: chessboardjs.BoardPositionType = { + d6: chessboardjs.Piece.bK, + d4: chessboardjs.Piece.wP, + e4: chessboardjs.Piece.wK +}; +var board = chessboardjs.ChessBoard('board', position); + +// Multiple boards +var config1: chessboardjs.BoardConfig = { + position: 'start', + showNotation: false +}; +var board1 = chessboardjs.ChessBoard('board1', config1); + +var board2 = chessboardjs.ChessBoard('board2', { + position: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R', + showNotation: false +}); + +var board3 = chessboardjs.ChessBoard('board3', { + position: 'r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1', + showNotation: false +}); + +/** + * Methods + */ + +// Get Position +var cfg: chessboardjs.BoardConfig = { + draggable: true, + position: 'start' +}; +var board = chessboardjs.ChessBoard('board', cfg); +var pos: chessboardjs.BoardPositionType = board.position(); + +var posFEN: string = board.position('fen'); + +// Set position + +// FEN +board.position('r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1'); + +// animated +board.position(ruyLopez, true); + +// instantly +board.position(ruyLopez, false); + +var position: chessboardjs.BoardPositionType = { + a4: chessboardjs.Piece.bK, + c4: chessboardjs.Piece.wK, + a7: chessboardjs.Piece.wR +}; +board.position(position); + +// Clear +board.clear(false); + +// Move +board.start(); +board.move('e2-e4'); + +// Orientation +var oritentation = board.orientation(); + +// change orientation +board.orientation('black'); + +// Recalculates board and square sizes based on the parent element and redraws +// the board accordingly. +board.resize(); + +// Destroy +board.destroy(); \ No newline at end of file diff --git a/types/chessboardjs/index.d.ts b/types/chessboardjs/index.d.ts new file mode 100644 index 0000000000..4f63d6f471 --- /dev/null +++ b/types/chessboardjs/index.d.ts @@ -0,0 +1,89 @@ +// Type definitions for chessboardjs 0.3 +// Project: https://github.com/oakmac/chessboardjs/ +// Definitions by: Bayo Olatunji +// David Paz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +declare namespace chessboardjs { + + enum Square { + a8 = 'a8', b8 = 'b8', c8 = 'c8', d8 = 'd8', e8 = 'e8', f8 = 'f8', g8 = 'g7', h8 = 'h8', + a7 = 'a7', b7 = 'b7', c7 = 'c7', d7 = 'd7', e7 = 'e7', f7 = 'f7', g7 = 'g7', h7 = 'h7', + a6 = 'a6', b6 = 'b6', c6 = 'c6', d6 = 'd6', e6 = 'e6', f6 = 'f6', g6 = 'g7', h6 = 'h6', + a5 = 'a5', b5 = 'b5', c5 = 'c5', d5 = 'd5', e5 = 'e5', f5 = 'f5', g5 = 'g7', h5 = 'h5', + a4 = 'a4', b4 = 'b4', c4 = 'c4', d4 = 'd4', e4 = 'e4', f4 = 'f4', g4 = 'g7', h4 = 'h4', + a3 = 'a3', b3 = 'b3', c3 = 'c3', d3 = 'd3', e3 = 'e3', f3 = 'f3', g3 = 'g7', h3 = 'h3', + a2 = 'a2', b2 = 'b2', c2 = 'c2', d2 = 'd2', e2 = 'e2', f2 = 'f2', g2 = 'g7', h2 = 'h2', + a1 = 'a1', b1 = 'b1', c1 = 'c1', d1 = 'd1', e1 = 'e1', f1 = 'f1', g1 = 'g7', h1 = 'h1', + } + + enum Piece { + bK = 'bK', bQ = 'bQ', bR = 'bR', bN = 'bN', bB = 'bB', bP = 'bP', + wK = 'wK', wQ = 'wQ', wR = 'wR', wN = 'wN', wB = 'wB', wP = 'wP' + } + + type BoardPositionType = { + [P in Square]?: Piece; + } + + type PositionType = 'start' | string | BoardPositionType; + type PositionFenType = 'fen'; + type SpeedType = 'slow' | 'fast'; + type OrientationFlipType = 'flip'; + type OrientationType = 'white' | 'black'; + type DropOffBoardType = 'snapback' | 'trash'; + + export interface BoardConfig { + onDrop?: Function; + draggable?: boolean; + onChange?: Function; + onMoveEnd?: Function; + onSnapEnd?: Function; + sparePieces?: boolean; + onDragMove?: Function; + showNotation?: boolean; + onDragStart?: Function; + onSnapbackEnd?: Function; + onMouseoutSquare?: Function; + onMouseoverSquare?: Function; + pieceTheme?: string | Function; + orientation?: OrientationType; + showErrors?: boolean | string | Function; + moveSpeed?: number | SpeedType; + snapSpeed?: number | SpeedType; + trashSpeed?: number | SpeedType; + dropOffBoard?: DropOffBoardType; + appearSpeed?: number | SpeedType; + snapbackSpeed?: number | SpeedType; + position?: PositionType; + } + + interface ChessBoardInstance { + clear(useAnimation?: boolean): void; + destroy(): void; + fen(): string; + flip(): void; + move(...args: string[]): BoardPositionType; + position(): BoardPositionType; + position(fen: PositionFenType): string; + position(newPosition: PositionType, useAnimation?: boolean): void + orientation(side?: OrientationType | OrientationFlipType): string; + resize(): void; + start(useAnimation?: boolean): void; + } + + interface ChessBoardFactory { + (containerElOrId: any, config?: BoardConfig): ChessBoardInstance + (containerElOrId: any, position: string): ChessBoardInstance + (containerElOrId: any, position: BoardPositionType): ChessBoardInstance + (containerElOrId: any): ChessBoardInstance + fenToObj(fen: string): boolean | BoardPositionType; + objToFen(obj: BoardPositionType): boolean | string; + } + + export var ChessBoard: ChessBoardFactory; +} + +export = chessboardjs; +export as namespace chessboardjs; diff --git a/types/chessboardjs/tsconfig.json b/types/chessboardjs/tsconfig.json new file mode 100644 index 0000000000..30bcf0849a --- /dev/null +++ b/types/chessboardjs/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "chessboardjs-tests.ts" + ] +} \ No newline at end of file diff --git a/types/chessboardjs/tslint.json b/types/chessboardjs/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/chessboardjs/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} From 9288744583488dd9cf84b34d91487e5cdbd3b19c Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 9 Feb 2018 21:20:38 +0100 Subject: [PATCH 2/3] Fix configuration files --- types/chessboardjs/tsconfig.json | 4 +- types/chessboardjs/tslint.json | 78 +------------------------------- 2 files changed, 3 insertions(+), 79 deletions(-) diff --git a/types/chessboardjs/tsconfig.json b/types/chessboardjs/tsconfig.json index 30bcf0849a..bc6246b6e9 100644 --- a/types/chessboardjs/tsconfig.json +++ b/types/chessboardjs/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -22,4 +22,4 @@ "index.d.ts", "chessboardjs-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/chessboardjs/tslint.json b/types/chessboardjs/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/chessboardjs/tslint.json +++ b/types/chessboardjs/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From 90cc97cd3d6587d24ba9b68dd944b47ff4ea952f Mon Sep 17 00:00:00 2001 From: David Paz Date: Fri, 9 Feb 2018 21:55:09 +0100 Subject: [PATCH 3/3] Fix errors in source code --- types/chessboardjs/chessboardjs-tests.ts | 34 ++--- types/chessboardjs/index.d.ts | 153 +++++++++++------------ 2 files changed, 90 insertions(+), 97 deletions(-) diff --git a/types/chessboardjs/chessboardjs-tests.ts b/types/chessboardjs/chessboardjs-tests.ts index b2750b0473..37c797037c 100644 --- a/types/chessboardjs/chessboardjs-tests.ts +++ b/types/chessboardjs/chessboardjs-tests.ts @@ -5,36 +5,36 @@ import chessboardjs = require('chessboardjs'); */ // empty position -var board = chessboardjs.ChessBoard('board'); +let board = chessboardjs.ChessBoard('board'); // Start position -var board = chessboardjs.ChessBoard('board', 'start'); +board = chessboardjs.ChessBoard('board', 'start'); // FEN string -var ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R'; -var board = chessboardjs.ChessBoard('board', ruyLopez); +const ruyLopez = 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R'; +board = chessboardjs.ChessBoard('board', ruyLopez); // Position Object -var position: chessboardjs.BoardPositionType = { +let position: chessboardjs.BoardPositionType = { d6: chessboardjs.Piece.bK, d4: chessboardjs.Piece.wP, e4: chessboardjs.Piece.wK }; -var board = chessboardjs.ChessBoard('board', position); +board = chessboardjs.ChessBoard('board', position); // Multiple boards -var config1: chessboardjs.BoardConfig = { +const config1: chessboardjs.BoardConfig = { position: 'start', showNotation: false }; -var board1 = chessboardjs.ChessBoard('board1', config1); +const board1 = chessboardjs.ChessBoard('board1', config1); -var board2 = chessboardjs.ChessBoard('board2', { +const board2 = chessboardjs.ChessBoard('board2', { position: 'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R', showNotation: false }); -var board3 = chessboardjs.ChessBoard('board3', { +const board3 = chessboardjs.ChessBoard('board3', { position: 'r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1', showNotation: false }); @@ -44,14 +44,14 @@ var board3 = chessboardjs.ChessBoard('board3', { */ // Get Position -var cfg: chessboardjs.BoardConfig = { +const cfg: chessboardjs.BoardConfig = { draggable: true, position: 'start' }; -var board = chessboardjs.ChessBoard('board', cfg); -var pos: chessboardjs.BoardPositionType = board.position(); +board = chessboardjs.ChessBoard('board', cfg); +const pos: chessboardjs.BoardPositionType = board.position(); -var posFEN: string = board.position('fen'); +const posFEN: string = board.position('fen'); // Set position @@ -64,7 +64,7 @@ board.position(ruyLopez, true); // instantly board.position(ruyLopez, false); -var position: chessboardjs.BoardPositionType = { +position = { a4: chessboardjs.Piece.bK, c4: chessboardjs.Piece.wK, a7: chessboardjs.Piece.wR @@ -79,7 +79,7 @@ board.start(); board.move('e2-e4'); // Orientation -var oritentation = board.orientation(); +const oritentation = board.orientation(); // change orientation board.orientation('black'); @@ -89,4 +89,4 @@ board.orientation('black'); board.resize(); // Destroy -board.destroy(); \ No newline at end of file +board.destroy(); diff --git a/types/chessboardjs/index.d.ts b/types/chessboardjs/index.d.ts index 4f63d6f471..f6228f748e 100644 --- a/types/chessboardjs/index.d.ts +++ b/types/chessboardjs/index.d.ts @@ -5,85 +5,78 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 -declare namespace chessboardjs { - - enum Square { - a8 = 'a8', b8 = 'b8', c8 = 'c8', d8 = 'd8', e8 = 'e8', f8 = 'f8', g8 = 'g7', h8 = 'h8', - a7 = 'a7', b7 = 'b7', c7 = 'c7', d7 = 'd7', e7 = 'e7', f7 = 'f7', g7 = 'g7', h7 = 'h7', - a6 = 'a6', b6 = 'b6', c6 = 'c6', d6 = 'd6', e6 = 'e6', f6 = 'f6', g6 = 'g7', h6 = 'h6', - a5 = 'a5', b5 = 'b5', c5 = 'c5', d5 = 'd5', e5 = 'e5', f5 = 'f5', g5 = 'g7', h5 = 'h5', - a4 = 'a4', b4 = 'b4', c4 = 'c4', d4 = 'd4', e4 = 'e4', f4 = 'f4', g4 = 'g7', h4 = 'h4', - a3 = 'a3', b3 = 'b3', c3 = 'c3', d3 = 'd3', e3 = 'e3', f3 = 'f3', g3 = 'g7', h3 = 'h3', - a2 = 'a2', b2 = 'b2', c2 = 'c2', d2 = 'd2', e2 = 'e2', f2 = 'f2', g2 = 'g7', h2 = 'h2', - a1 = 'a1', b1 = 'b1', c1 = 'c1', d1 = 'd1', e1 = 'e1', f1 = 'f1', g1 = 'g7', h1 = 'h1', - } - - enum Piece { - bK = 'bK', bQ = 'bQ', bR = 'bR', bN = 'bN', bB = 'bB', bP = 'bP', - wK = 'wK', wQ = 'wQ', wR = 'wR', wN = 'wN', wB = 'wB', wP = 'wP' - } - - type BoardPositionType = { - [P in Square]?: Piece; - } - - type PositionType = 'start' | string | BoardPositionType; - type PositionFenType = 'fen'; - type SpeedType = 'slow' | 'fast'; - type OrientationFlipType = 'flip'; - type OrientationType = 'white' | 'black'; - type DropOffBoardType = 'snapback' | 'trash'; - - export interface BoardConfig { - onDrop?: Function; - draggable?: boolean; - onChange?: Function; - onMoveEnd?: Function; - onSnapEnd?: Function; - sparePieces?: boolean; - onDragMove?: Function; - showNotation?: boolean; - onDragStart?: Function; - onSnapbackEnd?: Function; - onMouseoutSquare?: Function; - onMouseoverSquare?: Function; - pieceTheme?: string | Function; - orientation?: OrientationType; - showErrors?: boolean | string | Function; - moveSpeed?: number | SpeedType; - snapSpeed?: number | SpeedType; - trashSpeed?: number | SpeedType; - dropOffBoard?: DropOffBoardType; - appearSpeed?: number | SpeedType; - snapbackSpeed?: number | SpeedType; - position?: PositionType; - } - - interface ChessBoardInstance { - clear(useAnimation?: boolean): void; - destroy(): void; - fen(): string; - flip(): void; - move(...args: string[]): BoardPositionType; - position(): BoardPositionType; - position(fen: PositionFenType): string; - position(newPosition: PositionType, useAnimation?: boolean): void - orientation(side?: OrientationType | OrientationFlipType): string; - resize(): void; - start(useAnimation?: boolean): void; - } - - interface ChessBoardFactory { - (containerElOrId: any, config?: BoardConfig): ChessBoardInstance - (containerElOrId: any, position: string): ChessBoardInstance - (containerElOrId: any, position: BoardPositionType): ChessBoardInstance - (containerElOrId: any): ChessBoardInstance - fenToObj(fen: string): boolean | BoardPositionType; - objToFen(obj: BoardPositionType): boolean | string; - } - - export var ChessBoard: ChessBoardFactory; +export enum Square { + a8 = 'a8', b8 = 'b8', c8 = 'c8', d8 = 'd8', e8 = 'e8', f8 = 'f8', g8 = 'g7', h8 = 'h8', + a7 = 'a7', b7 = 'b7', c7 = 'c7', d7 = 'd7', e7 = 'e7', f7 = 'f7', g7 = 'g7', h7 = 'h7', + a6 = 'a6', b6 = 'b6', c6 = 'c6', d6 = 'd6', e6 = 'e6', f6 = 'f6', g6 = 'g7', h6 = 'h6', + a5 = 'a5', b5 = 'b5', c5 = 'c5', d5 = 'd5', e5 = 'e5', f5 = 'f5', g5 = 'g7', h5 = 'h5', + a4 = 'a4', b4 = 'b4', c4 = 'c4', d4 = 'd4', e4 = 'e4', f4 = 'f4', g4 = 'g7', h4 = 'h4', + a3 = 'a3', b3 = 'b3', c3 = 'c3', d3 = 'd3', e3 = 'e3', f3 = 'f3', g3 = 'g7', h3 = 'h3', + a2 = 'a2', b2 = 'b2', c2 = 'c2', d2 = 'd2', e2 = 'e2', f2 = 'f2', g2 = 'g7', h2 = 'h2', + a1 = 'a1', b1 = 'b1', c1 = 'c1', d1 = 'd1', e1 = 'e1', f1 = 'f1', g1 = 'g7', h1 = 'h1', } -export = chessboardjs; -export as namespace chessboardjs; +export enum Piece { + bK = 'bK', bQ = 'bQ', bR = 'bR', bN = 'bN', bB = 'bB', bP = 'bP', + wK = 'wK', wQ = 'wQ', wR = 'wR', wN = 'wN', wB = 'wB', wP = 'wP' +} + +export type BoardPositionType = { + [P in Square]?: Piece; +}; + +export type PositionType = 'start' | string | BoardPositionType; +export type PositionFenType = 'fen'; +export type SpeedType = 'slow' | 'fast'; +export type OrientationFlipType = 'flip'; +export type OrientationType = 'white' | 'black'; +export type DropOffBoardType = 'snapback' | 'trash'; +export type Callback = () => void; + +export interface BoardConfig { + onDrop?: Callback; + draggable?: boolean; + onChange?: Callback; + onMoveEnd?: Callback; + onSnapEnd?: Callback; + sparePieces?: boolean; + onDragMove?: Callback; + showNotation?: boolean; + onDragStart?: Callback; + onSnapbackEnd?: Callback; + onMouseoutSquare?: Callback; + onMouseoverSquare?: Callback; + pieceTheme?: string | Callback; + orientation?: OrientationType; + showErrors?: boolean | string | Callback; + moveSpeed?: number | SpeedType; + snapSpeed?: number | SpeedType; + trashSpeed?: number | SpeedType; + dropOffBoard?: DropOffBoardType; + appearSpeed?: number | SpeedType; + snapbackSpeed?: number | SpeedType; + position?: PositionType; +} + +export interface ChessBoardInstance { + clear(useAnimation?: boolean): void; + destroy(): void; + fen(): string; + flip(): void; + move(...args: string[]): BoardPositionType; + position(): BoardPositionType; + position(fen: PositionFenType): string; + position(newPosition: PositionType, useAnimation?: boolean): void; + orientation(side?: OrientationType | OrientationFlipType): string; + resize(): void; + start(useAnimation?: boolean): void; +} + +export interface ChessBoardFactory { + (containerElOrId: any, config?: BoardConfig): ChessBoardInstance; + (containerElOrId: any, position: string | BoardPositionType): ChessBoardInstance; + fenToObj(fen: string): boolean | BoardPositionType; + objToFen(obj: BoardPositionType): boolean | string; +} + +export const ChessBoard: ChessBoardFactory;