Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

shogiground

WandererXII501GPL-3.0-or-later0.10.3TypeScript support: included

lishogi.org shogi ui

shogi, 将棋, 将棋板, shogiboard, lishogi, lishogi.org, typescript

readme

Shogiground

Continuous Integration npm jsdelivr

Shogiground

Shogiground is a free/libre open source shogi UI forked from Chessground rewritten for lishogi.org. It targets modern browsers, as well as mobile development using Cordova.

License

Shogiground is distributed under the GPL-3.0 license (or any later version, at your option). When you use Shogiground for your website, your combined work may be distributed only under the GPL. You must release your source code to the users of your website.

Please read more about GPL for JavaScript on greendrake.info/#nfy0.

Demos

Features

Shogiground

Shogiground is designed to fulfill all lishogi.org web and mobile apps needs, so it is pretty featureful.

  • Well typed with TypeScript
  • Fast. Uses a custom DOM diff algorithm to reduce DOM writes to the absolute minimum.
  • Small footprint: cca 40K unzipped. No dependencies.
  • SVG drawing of circles and arrows on the board and hands
  • Individual square elements for styling
  • Entirely configurable and reconfigurable at any time
  • Styling with CSS only: board, pieces and drawn shapes can be changed by simply switching a class
  • Fluid layout: board can be resized at any time
  • Full mobile support (touchstart, touchmove, touchend)
  • Move or drop pieces by click
  • Move or drop pieces by drag & drop
    • Minimum distance before drag
    • Centralisation of the piece under the cursor
    • Piece ghost element
    • Drop off revert or trash
  • Supports shogi-like promotions
  • Premove or predrop by click or drag
  • Animation of pieces: moving and fading away both on board and from hands
  • Display last move, check, move destinations, and premove destinations (hover effects possible)
  • Import and export positions in SFEN notation, custom sfen parser/renderer
  • User callbacks
  • Supports board dimensions up to 16x16
  • No shogi logic inside: can be used for shogi variants

Installation

npm install --save shogiground

Usage

import { Shogiground } from 'shogiground';

const config = {
  sfen: {
    board: 'lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL',
  },
};
const ground = Shogiground(config, { board: document.body });

Non-module environments

Or you can simply pull the latest version from jsdelivr.

<script src="https://cdn.jsdelivr.net/npm/shogiground@latest/dist/shogiground.min.js"></script>

CSS

To actually see and use the board you need some CSS. You can use the CSS in examples/assets as a starting point. But it will take some work to get it exactly how you want it.

Documentation

Development

Install build dependencies:

npm install

To build the node module:

npm run compile -- --watch

To build the standalone:

npm run dist -- --watch

changelog

v0.10.3

  • Highlight pieces in 'last-dest' only if s.highlight.lastDests is enabled.
  • Fix removing pieces from hand when dropping spare pieces.

v0.10.2

  • Fixed confusing and wrong behavior of state.droppable.spare.
  • Pieces in hand now can also have 'last-dest' highlight using lastPiece in state.

v0.10.1

  • Added dizhi notation system (max 12 ranks/files).
  • Charset of dist files is now utf-8 - relevant for kanji coords.

v0.10.0

  • Notation is now a string - 'numeric' | 'japanese' | 'engine' | 'hex', not a const enum.
  • notation.ts no longer exists, coords function is now in coords.ts and Notation type is in types.ts.

v0.9.0

  • Files are now built to esm directory.
  • Constants were moved from types.ts into constants.ts.
  • Notation was moved from types.ts into notation.ts.
  • Type guards were moved from types.ts into util.ts.
  • allKeys was moved from util.ts into constants.ts.

v0.8.6

  • Fixed possible division by zero resulting in NaN positions, while calculating positions of outside elements, that have no width/height.

v0.8.5

  • Added to drawable.forced to config. When set to true moving/dropping is not possible and only shapes will be drawn.
  • Dependencies bumped.

v0.8.4

  • Added unpromotesTo to promotion in config. If a piece can't be added to or removed from hand, due to not being in hands.roles, unpromotion will be attempted. Return undefined by default.
  • Calling selectPiece in api now correctly always selects specified piece and unselects only when null is provided.
  • Added addSparesToHand to selectable in config. If true - clicking on a piece in hand while having a spare piece selected will result in adding the spare piece's role to hand. Defaults to false.
  • Dependencies bumped.

v0.8.3

v0.8.2

  • Added shogiground.js and shogiground.min.js in dist to npm.

v0.8.1

  • Fix redrawing with multiple instances of shogiground.

v0.8.0

  • Renamed cancelMove to cancelMoveOrDrop to better reflect what it actually does.
  • Added an option to drop spare pieces (selectabled.forceSpares) by selecting a square even with selectable disabled.

v0.7.1

  • Inlined hand wrapper element (sg-hand-wrap) now has inlined class.

v0.7.0

  • Brush is also added as class to custom svgs.
  • 'primary' brush class is added for arrows containing empty brush name.
  • Each shape is now inside g element. Brush names (classes) and sgHash are assigned to these g elements - you need to update css.

v0.6.2

  • Fix highlight.checkRoles not being optional in config

v0.6.1

  • config.checks can now also takes Color or boolean - roles to highlight can be set inhighlight.checkRoles
  • Don't add hover class to squares, when not necessary
  • Export canPremove and canPredrop
  • Fix checks in config

v0.6.0

  • Remove premove and predrop included functions, now you have to pass a function that will be called, this truly removes shogi logic from shogiground.
  • Remove Role type, now it's just string, again - removes shogi logic from shogiground, custom parsers for sfen must be used, but default is provided for standard shogi.
  • Max size of the board extended to 16x16.
  • DropDests use PieceName as a key, not role.
  • check changed to checks, takes only Key[] now.
  • Callback event - unselect and unselectPiece - triggered only when we unselect directly on the orig square/piece.
  • Hex notation for coords added.
  • Files and ranks notation are now set separately.
  • Add description option to shapes - mainly for promotion ('+').
  • Rename Dests to MoveDests.
  • Changelog started.