UNPKG

chessground

Version:

Multipurpose chess UI, for lichess.org web and mobile

85 lines (81 loc) 3.17 kB
var fen = require('./fen'); var configure = require('./configure'); module.exports = function(cfg) { var defaults = { pieces: fen.read(fen.initial), orientation: 'white', // board orientation. white | black turnColor: 'white', // turn to play. white | black check: null, // square currently in check "a2" | null lastMove: null, // squares part of the last move ["c3", "c4"] | null selected: null, // square currently selected "a1" | null render: null, // function that rerenders the board bounds: null, // function that calculates the board bounds highlight: { lastMove: true, // add last-move class to squares check: true, // add check class to squares dragOver: true // add drag-over class to square when dragging over it }, animation: { enabled: true, duration: 200, /*{ // current * start: timestamp, * duration: ms, * anims: { * a2: [ * [-30, 50], // animation goal * [-20, 37] // animation current status * ], ... * }, * fading: [ * { * pos: [80, 120], // position relative to the board * opacity: 0.34, * role: 'rook', * color: 'black' * } * } *}*/ current: {} }, movable: { free: true, // all moves are valid - board editor color: 'both', // color that can move. white | black | both | null dests: {}, // valid moves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]} | null dropOff: 'revert', // when a piece is dropped outside the board. "revert" | "trash" dropped: [], // last dropped [orig, dest], not to be animated showDests: true, // whether to add the move-dest class on squares events: { after: function(orig, dest) {} // called after the move has been played } }, premovable: { enabled: true, // allow premoves for color that can not move showDests: true, // whether to add the premove-dest class on squares dests: [], // premove destinations for the current selection current: null // keys of the current saved premove ["e2" "e4"] | null }, draggable: { enabled: true, // allow moves & premoves to use drag'n drop distance: 3, // minimum distance to initiate a drag, in pixels squareTarget: false, // display big square target intended for mobile centerPiece: true, // center the piece on cursor at drag start showGhost: true, // show ghost of piece being dragged /*{ // current * orig: "a2", // orig key of dragging piece * rel: [100, 170] // x, y of the piece at original position * pos: [20, -12] // relative current position * dec: [4, -8] // piece center decay * over: "b3" // square being moused over * bounds: current cached board bounds * started: whether the drag has started, as per the distance setting *}*/ current: {} }, events: { change: function() {} // called after the situation changes on the board } }; configure(defaults, cfg || {}); return defaults; };