npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gchessboard

v1.2.0

Published

An accessible, customizable and dependency-free chessboard web component.

Downloads

50

Readme

gchessboard

gchessboard is an accessible, customizable and dependency-free chess board web component that can be easily embedded into both vanilla JS and framework-based web applications.

Features:

  • Accessible: Supports multiple input modes: click, drag, and keyboard interaction, as well as rudimentary screenreader support.

  • Customizable: Almost all styles can be styled using CSS custom properties. This includes piece sets, which can be changed via CSS from the included SVG set. Squares can also show custom content (such as SVGs) using web component slots.

Read more documentation on the website.

Installing

gchessboard is packaged as a Web Component and should be usable directly in most modern browsers. It bundles its own (configurable) styles, inline assets (for chess pieces), and code.

In HTML (using unpkg)

<script type="module" src="https://unpkg.com/gchessboard"></script>

As a module import

First, install from NPM:

npm install gchessboard

Then, in application JS:

import "gchessboard";

Basic usage

<g-chess-board></g-chess-board>

The above example will simply render an empty board. Realistically, though, you would want to use it with some additional attributes set:

<g-chess-board fen="start" interactive></g-chess-board>

The above example sets up a board with the standard chess game start position, and enables interaction using click, drag, and keyboard (by tabbing into the board).

Tutorial and Advanced Examples

  • View the tutorial to learn how to use the library and integrate it with chess logic.
  • View an example of a computer playing random moves in response to player input, see this Pen.
  • The development page (index.html) for this library also includes some advanced setup, including the use of custom slots, event handling, and changing various properties and attributes of the board. See the Developing section for more details.
  • The library can be easily wrapped with React. A demo using @lit-labs/react for wrapping is in the mganjoo/react-gchessboard-chessjs-demo repository.
  • Another example of an advanced React app leveraging this library is https://knights-tour-game.vercel.app/ (this one uses @microsoft/fast-react-wrapper to wrap the component).

Customizing

More details on properties and attributes of the element, events fired, and various customizable CSS properties are available in the API documentation.

Developing

To start a server that builds the library and serves the demo page index.html and watches for any changes to the filesystem:

npm start

This will create a server and serve on http://localhost:8000/.

Attribution

Chess piece SVG images included in this library were adapted from Category:SVG chess pieces on Wikmedia, with slight optimizations using SVGO.

Original images created by User:Cburnett - Own work, licensed under CC BY-SA 3.0.

Acknowledgements

Some other excellent chessboard libraries that this project is inspired by:

  • shaack/cm-chessboard: An ES6 chessboard library, using SVG for rendering. Allows customizing styles and colors of board using CSS.
  • justinfagnani/chessboard-element: A web components-based port of the popular chessboardjs library. Uses web component idioms like CustomEvent for various lifecycle events in a move interaction (move start, end, etc).