• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple PGN viewer with the necessary features to display chess games

GitHub Workflow Status GitHub Languages Languages Languages

PgnViewerJS

PgnViewerJS (as npm package named pgn-viewer) is a simple JavaScript implementation to show PGN files (Portable Game Notation == Chess) in a web page. PgnViewerJS does not write everything anew, but it uses the following libraries:

  • chess.js Base library to model chess in JavaScript
  • Chessground The chessboard used by lichess.org
  • pgn-reader Backend for the viewer (part of this repository, but separately published)
  • pgn-parser My own parser based on peggy (formerly pegjs)

See the section Acknowledgments for more supporting libraries.

See the working examples on my new GitHub Pages site PgnViewerJS, especially the Configuration Builder that demonstrates all parameters in a running example.

Getting Started

The easiest way to use it is to install it by using NPM: npm install @mliebelt/pgn-viewer. You will find there the diretory lib that contains everything. Copy that onto your webserver.

Example Screenshots

The following are example screenshots with the configuration set below, to show the rich possibilities of PgnViewerJS.

Theme Sportverlag Edit with variations Viewer

The screenshots show from left to right:

  • mode: board; theme: sportverlag
  • mode: edit; headers: false; theme: 'brown' with comments
  • mode: view; layout: 'left', pieceStyle: 'leipzig', theme: 'zeit' with comments

Go to the github.io pages (documentation), where the viewer is documented and shown.

Features

This implementation has the following features:

  • Allows to show one or many chess games complete, with a lot of different styles, themes, tuning, ...
  • Allows to play through the games forward and backward, including variations.
  • Allows to play from a legal position only legal moves.
  • Knows all PGN notation elements, and knows how to render them.

UI modes

There are four different kind of usages:

  • PGNV.pgnView renders the whole game, and allows to play it through, jump to any position.
  • PGNV.pgnEdit is a superset of pgnView, that allows to additional add variations, change the order of main line and variations, and other kind of interactions like adding comments, PGN notation elements, ...
  • PGNV.pgnBoard will just show a position without any interaction possible.
  • PGNV.pgnPrint will just show a whole chess game, without any interaction possible.

There is at the moment no way to save a game that was edited in pgnEdit mode. But you may at least copy the whole notation, and insert it again in the HTML code of your web page.

Running the tests

  • Run npm test in directory modules/pgn-reader. This runs the tests for the module pgn-reader.

Running the examples

  • Start a local webserver (like http-server) inside directory modules/pgn-viewer, and visit the page http://localhost:<port>/examples.
  • Browse through the many examples in the sub-directories, or visit the configuration builder in directory examples/configuration/config.html.

Deployment

From Release

  • Copy the files from directory modules/pgn-viewer/lib into a web server.
  • Create new HTML files with the corresponding head and body.

From Clone

  • Clone the repository.
  • Run npm install from the root, to ensure that all tools are installed.
  • Run npm install in modules/pgn-viewer directory.
  • Run npm run build in modules/pgn-viewer) directory.
  • Copy the files from the directory modules/pgn-viewer/lib.
  • Create new HTML files with the corresponding head and body.

Using the viewer

Standalone script

To use the viewer in an HTML page, you have to do the following steps:

  • Include the necessary library pgnv.js.
  • Include the necessary div container for rendering of the board and the moves.
  • Include JavaScript code inside your HTML page to call the viewer.

So a rough template will look like:

<!DOCTYPE html>
    <head>
        <script src="lib/dist.js" type="text/javascript" ></script>
    </head>
    <body>
        <div id="board"></div>
        <script>
    	PGNV.pgnView('board',{ pgn: '1. e4 e5 2. Nf3 Nc6 3. Bb5', pieceStyle: 'merida' });
        </script>
    </body>
</html>

See the example in react.md how to run the viewer in a react application.

Built With

  • NPM For libraries, building, ...
  • Webpack For building optimized bundle.

Contributing

If you find something strange (bug), expect some feature (feature) or just want to comment on anything, please file first a ticket in Github.

If you want to help in implementing something, clone the repository, change whatever you want to, and provide a pull request that I can look at.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

From the version 1.0.0 on, the whole package can be downloaded / installed by using NPM:

  • Download: npm pack @mliebelt/[email protected] Results in download of a file mliebelt-pgn-viewer-1.5.9.tgz, that contains in the directory package/lib all resources needed.
  • Install: npm install @mliebelt/[email protected] as part of some other application. You will find then the files in the directory node_modules/@mliebelt/pgn-viewer/lib.

Authors

License

pgn-viewer is distributed under the GPL-3.0 license (or any later version, at your option), due to its use of Chessground. When you use pgn-viewer 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.

Acknowledgments

We use the following libraries in the implementation:

Thank you a lot to all contributors of issues.

Known Usage

  • PgnJS Plugin for Mediawiki that uses PgnViewerJS to display chess games.
  • PgnViewerJS-WP Plugin for Wordpress to show games with the help of PgnViewerJS
  • The Chess Centre Replaying games produced by DGT live boards following OTB events.

More Repositories

1

pgn-parser

Javascript library to allow reading of a PGN (Portable Game Notation) chess game notation, and providing the result as JSON.
JavaScript
50
star
2

jquery-autocomplete-inner

Shows in an example how to use autocomplete of JQuery inside a textarea, so that the word before the cursor will used for the lookup.
JavaScript
11
star
3

pgn-spec-commented

Collects information about pgn (portable game notation), and explains typical usage of it.
8
star
4

rails-generator-scaffold_hmt

Provides a rails 3.1.x generator that allows to scaffold has_many :through relations.
Ruby
5
star
5

pgn-writer

Provides base functionality (implemented in Javascript) to write PGN to a string. The input is the one produced by pgn-parser, and used as well by pgn-reader.
TypeScript
4
star
6

PgnViewerJS-WP

Integration of PgnViewerJS into WordPress
PHP
3
star
7

schach-selbsttraining

Publikation zum Training im Herbst 2023 über Online Training im Schach
JavaScript
2
star
8

use-different-module-types

Playground to build a build process that allows different modules and usages of those modules.
JavaScript
1
star
9

PgnViewerTS

Reimplementation of PgnViewerJS with Typescript as implementation language.
TypeScript
1
star
10

pgn-tools

Collection of useful functions / commands that combine different functions from pgn-parser, pgn-reader, pgn-writer.
TypeScript
1
star
11

schachtraining-lichess-discord

Vorbereitung des Workshops zu "Online Training mit Lichess und Discord", der im Rahmen des Schachverbands Württemberg im Juni 2022 angeboten werden wird.
JavaScript
1
star
12

pgn-reader

Reader for PGN files, to read and play through the games without a viewer.
TypeScript
1
star
13

py-chess

Library with some python code to script interesting things.
Python
1
star