UNPKG

chessground12

Version:
100 lines 3.46 kB
import { configure, applyAnimation } from './config'; import { anim, render } from './anim'; import { cancel as dragCancel, dragNewPiece } from './drag'; import { baseMove, baseNewPiece, cancelMove, getKeyAtDomPos, playPredrop, playPremove, selectSquare, setLastMove, setPieces, setPlinths, unselect, unsetPredrop, unsetPremove, whitePov, } from './board'; import { toggleOrientation as toggleOrientation2, stop as stop2 } from './board'; // see API types and documentations in dts/api.d.ts export function start(state, redrawAll) { function toggleOrientation() { state.plinthsPlaced = false; toggleOrientation2(state); redrawAll(); } return { set(config) { if (config.orientation && config.orientation !== state.orientation) toggleOrientation(); applyAnimation(state, config); (config.fen ? anim : render)(state => configure(state, config), state); }, state, toggleOrientation, setPieces(pieces) { anim(state => setPieces(state, pieces), state); }, setPlinths(pieces) { anim(state => setPlinths(state, pieces), state); }, setLastMove(from, to) { anim(state => setLastMove(state, from, to), state); }, selectSquare(key, force) { if (key) anim(state => selectSquare(state, key, force), state); else if (state.selected) { unselect(state); state.dom.redraw(); } }, move(orig, dest) { anim(state => baseMove(state, orig, dest), state); }, newPiece(piece, key) { anim(state => baseNewPiece(state, piece, key), state); }, playPremove() { if (state.premovable.current) { if (anim(playPremove, state)) return true; // if the premove couldn't be played, redraw to clear it up state.dom.redraw(); } return false; }, playPredrop() { if (state.predroppable.current) { const result = playPredrop(state); state.dom.redraw(); return result; } return false; }, cancelPremove() { render(unsetPremove, state); }, cancelPredrop() { render(unsetPredrop, state); }, cancelMove() { render(state => { cancelMove(state); dragCancel(state); }, state); }, stop() { render(state => { stop2(state); dragCancel(state); }, state); }, setAutoShapes(shapes) { render(state => (state.drawable.autoShapes = shapes), state); }, setShapes(shapes) { render(state => (state.drawable.shapes = shapes), state); }, getKeyAtDomPos(pos) { return getKeyAtDomPos(pos, whitePov(state), state.dom.bounds(), state.geometry); }, redrawAll, dragNewPiece(piece, event, force) { dragNewPiece(state, piece, event, force); }, destroy() { stop2(state); state.dom.unbind && state.dom.unbind(); state.dom.destroyed = true; }, }; } //# sourceMappingURL=api.js.map