chess2img 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
  <img src="./assets/themes/cburnett/wK.png" alt="chess2img king icon" width="88" />
5
- <p>Generate PNG chessboard images from FEN, PGN, or board arrays in Node.js.</p>
5
+ <p>Generate PNG, SVG, and JPEG chessboard images from FEN, PGN, or board arrays in Node.js.</p>
6
6
  <p>
7
7
  <a href="https://www.npmjs.com/package/chess2img"><img src="https://img.shields.io/npm/v/chess2img" alt="npm version" /></a>
8
8
  <a href="https://www.npmjs.com/package/chess2img"><img src="https://img.shields.io/npm/dm/chess2img" alt="npm downloads" /></a>
@@ -13,11 +13,11 @@
13
13
 
14
14
  ## Overview
15
15
 
16
- `chess2img` renders chessboard PNGs from FEN, PGN, or board-array inputs with a small Promise-based API for JavaScript and TypeScript users on Node.js.
16
+ `chess2img` renders chessboard PNG, SVG, and JPEG images from FEN, PGN, or board-array inputs with a small Promise-based API for JavaScript and TypeScript users on Node.js.
17
17
 
18
18
  ## Features
19
19
 
20
- - Render PNG chessboard images from `fen`, `pgn`, or `board` input.
20
+ - Render PNG, SVG, or JPEG chessboard images from `fen`, `pgn`, or `board` input.
21
21
  - Use five bundled built-in themes: `merida`, `alpha`, `cburnett`, `cheq`, and `leipzig`.
22
22
  - Highlight squares such as the last move or key tactical ideas.
23
23
  - Customize board colors, size, padding, border sizing, coordinates, and board orientation.
@@ -58,6 +58,36 @@ await writeFile("board.png", png);
58
58
 
59
59
  `renderChess(...)` returns a `Promise<Buffer>` containing PNG data.
60
60
 
61
+ ### SVG Output
62
+
63
+ ```ts
64
+ import { writeFile } from "node:fs/promises";
65
+ import { renderSvg } from "chess2img";
66
+
67
+ const svg = await renderSvg({
68
+ fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
69
+ size: 480,
70
+ style: "merida",
71
+ });
72
+
73
+ await writeFile("board.svg", svg, "utf8");
74
+ ```
75
+
76
+ ### JPEG Output
77
+
78
+ ```ts
79
+ import { writeFile } from "node:fs/promises";
80
+ import { renderJpeg } from "chess2img";
81
+
82
+ const jpeg = await renderJpeg({
83
+ fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
84
+ size: 480,
85
+ style: "merida",
86
+ });
87
+
88
+ await writeFile("board.jpg", jpeg);
89
+ ```
90
+
61
91
  ## Installation
62
92
 
63
93
  ```bash
@@ -77,16 +107,33 @@ If `canvas` fails to install, verify your system packages first. The library shi
77
107
  ### Functional API
78
108
 
79
109
  ```ts
80
- import { writeFile } from "node:fs/promises";
81
- import { renderChess } from "chess2img";
110
+ import { renderFile } from "chess2img";
82
111
 
83
- const png = await renderChess({
112
+ await renderFile("board.png", {
84
113
  fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
85
114
  size: 480,
86
115
  style: "merida",
87
116
  });
117
+ ```
88
118
 
89
- await writeFile("board.png", png);
119
+ `renderChess(...)` and `renderFile(...)` are the explicit PNG APIs.
120
+
121
+ ### SVG And JPEG File Helpers
122
+
123
+ ```ts
124
+ import { renderJpegFile, renderSvgFile } from "chess2img";
125
+
126
+ await renderSvgFile("board.svg", {
127
+ fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
128
+ size: 480,
129
+ style: "merida",
130
+ });
131
+
132
+ await renderJpegFile("board.jpg", {
133
+ fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
134
+ size: 480,
135
+ style: "merida",
136
+ });
90
137
  ```
91
138
 
92
139
  ### Automatic Coordinates
@@ -190,6 +237,8 @@ await generator.loadPGN("1. e4 e5 2. Nf3 Nc6 3. Bb5 a6");
190
237
  generator.setHighlights(["e4", "e5"]);
191
238
 
192
239
  await generator.toFile("board.png");
240
+ await generator.toSvgFile("board.svg");
241
+ await generator.toJpegFile("board.jpg");
193
242
  ```
194
243
 
195
244
  ### JavaScript Usage
@@ -256,16 +305,33 @@ Custom themes may use either:
256
305
 
257
306
  - `new ChessImageGenerator(options?)`
258
307
  - `renderChess(options)`
308
+ - `renderSvg(options)`
309
+ - `renderJpeg(options)`
310
+ - `renderFile(path, options)`
311
+ - `renderSvgFile(path, options)`
312
+ - `renderJpegFile(path, options)`
259
313
  - `registerTheme(theme)`
260
314
 
261
315
  ### Functional API
262
316
 
263
- `renderChess(...)` accepts exactly one position source:
317
+ `renderChess(...)`, `renderSvg(...)`, and `renderJpeg(...)` accept exactly one position source:
264
318
 
265
319
  - `fen`
266
320
  - `pgn`
267
321
  - `board`
268
322
 
323
+ Return values:
324
+
325
+ - `renderChess(...)` -> `Promise<Buffer>` containing PNG data
326
+ - `renderSvg(...)` -> `Promise<string>` containing SVG markup
327
+ - `renderJpeg(...)` -> `Promise<Buffer>` containing JPEG data
328
+
329
+ File helpers:
330
+
331
+ - `renderFile(path, options)` -> writes PNG only
332
+ - `renderSvgFile(path, options)` -> writes SVG only
333
+ - `renderJpegFile(path, options)` -> writes JPEG only
334
+
269
335
  ### Class API
270
336
 
271
337
  Methods:
@@ -277,6 +343,10 @@ Methods:
277
343
  - `clearHighlights(): void`
278
344
  - `toBuffer(): Promise<Buffer>`
279
345
  - `toFile(filePath: string): Promise<void>`
346
+ - `toSvg(): Promise<string>`
347
+ - `toSvgFile(filePath: string): Promise<void>`
348
+ - `toJpeg(): Promise<Buffer>`
349
+ - `toJpegFile(filePath: string): Promise<void>`
280
350
 
281
351
  Semantics:
282
352
 
@@ -302,7 +372,7 @@ Semantics:
302
372
 
303
373
  `coordinates: false` or omitting the option disables labels. `coordinates: true` enables labels and chooses `border` mode when `borderSize > 0`, otherwise `inside` mode. Explicit `coordinates: "inside"` is always valid. Explicit `coordinates: "border"` requires `borderSize > 0` and throws `ValidationError` otherwise.
304
374
 
305
- `highlights` is the preferred API. Each entry may be a square string for a filled highlight, or an object with `square`, `style`, `color`, `opacity`, and `lineWidth`. `highlightSquares` remains available for backward compatibility, but should not be used together with `highlights` in the same call.
375
+ `highlights` is the preferred API. Each entry may be a square string for a filled highlight, or an object with `square`, `style`, `color`, `opacity`, `lineWidth`, and `radius`. `highlightSquares` remains available for backward compatibility, but should not be used together with `highlights` in the same call.
306
376
 
307
377
  Inside coordinates use automatic light/dark contrast by default, similar to chess.com. If `coordinates.color` is provided, that exact color is used instead. Border coordinates keep a single-color label style with `#333` as the default.
308
378