A chessboard that stays smooth on every phone.
A phone in Low Power Mode lets a page's script run about 30 times a second, unevenly. A board that moves its pieces from script, frame by frame, is held to that. Lightsquare writes the new place of a piece once and hands the slide to the browser. The design as one picture.
The position, the marks and what may move are one plain object. Your app and the player's finger both change it.
The new state is compared with what is on screen. A piece that stays is not touched; a piece that moved keeps its element.
A move is five small writes to the page, whatever the position. No measuring, no timers, no animation loop.
The piece gets a new transform and a CSS transition. From there no script runs until it has arrived.
Lightsquare next to the boards most used on the web. The browser's own counters are read, and where another board does better, the table says so.
No results yet. Run npm run measure in compare/. |
import { lightsquare } from "@kibitzo/lightsquare"; import { shapes } from "@kibitzo/lightsquare/shapes"; import "@kibitzo/lightsquare/lightsquare.css"; import "@kibitzo/lightsquare/pieces/kibitzo.css"; const board = lightsquare(element, { movable: "white", targets, // Map: where each piece may go onMove({ from, to }) { // your chess rules decide; then confirm or take back board.set({ position: fenAfterTheMove }); }, }); board.use(shapes({ arrows: [{ from: "e2", to: "e4" }], draw: true }));
npm install @kibitzo/lightsquare. MIT, no dependencies. It draws every board of Kibitzo.
@kibitzo/lightsquare5.2 kBpieces, marks, coordinates, tap and drag, premove, what each change was@kibitzo/lightsquare/shapes2.0 kBarrows and circles, drawn by the app or the user@kibitzo/lightsquare/promotion0.7 kBthe promotion picker@kibitzo/lightsquare/a11y1.2 kBscreen readers and moves by keyboard@kibitzo/lightsquare/premove0.8 kBwhere a piece could premove to@kibitzo/lightsquare/theme0.7 kBlooks as data, for one board or a whole page@kibitzo/lightsquare/editor1.7 kBa position editor: move, remove and add pieces@kibitzo/lightsquare/overlay0.4 kByour own HTML on a square@kibitzo/lightsquare/react0.5 kBa React component