chess2img 0.1.0 → 0.1.1
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/ATTRIBUTION.md +14 -3
- package/README.md +7 -2
- package/assets/themes/alpha/bB.png +0 -0
- package/assets/themes/alpha/bK.png +0 -0
- package/assets/themes/alpha/bN.png +0 -0
- package/assets/themes/alpha/bP.png +0 -0
- package/assets/themes/alpha/bQ.png +0 -0
- package/assets/themes/alpha/bR.png +0 -0
- package/assets/themes/alpha/wB.png +0 -0
- package/assets/themes/alpha/wK.png +0 -0
- package/assets/themes/alpha/wN.png +0 -0
- package/assets/themes/alpha/wP.png +0 -0
- package/assets/themes/alpha/wQ.png +0 -0
- package/assets/themes/alpha/wR.png +0 -0
- package/assets/themes/cburnett/bB.png +0 -0
- package/assets/themes/cburnett/bK.png +0 -0
- package/assets/themes/cburnett/bN.png +0 -0
- package/assets/themes/cburnett/bP.png +0 -0
- package/assets/themes/cburnett/bQ.png +0 -0
- package/assets/themes/cburnett/bR.png +0 -0
- package/assets/themes/cburnett/wB.png +0 -0
- package/assets/themes/cburnett/wK.png +0 -0
- package/assets/themes/cburnett/wN.png +0 -0
- package/assets/themes/cburnett/wP.png +0 -0
- package/assets/themes/cburnett/wQ.png +0 -0
- package/assets/themes/cburnett/wR.png +0 -0
- package/assets/themes/cheq/bB.png +0 -0
- package/assets/themes/cheq/bK.png +0 -0
- package/assets/themes/cheq/bN.png +0 -0
- package/assets/themes/cheq/bP.png +0 -0
- package/assets/themes/cheq/bQ.png +0 -0
- package/assets/themes/cheq/bR.png +0 -0
- package/assets/themes/cheq/wB.png +0 -0
- package/assets/themes/cheq/wK.png +0 -0
- package/assets/themes/cheq/wN.png +0 -0
- package/assets/themes/cheq/wP.png +0 -0
- package/assets/themes/cheq/wQ.png +0 -0
- package/assets/themes/cheq/wR.png +0 -0
- package/assets/themes/leipzig/bB.png +0 -0
- package/assets/themes/leipzig/bK.png +0 -0
- package/assets/themes/leipzig/bN.png +0 -0
- package/assets/themes/leipzig/bP.png +0 -0
- package/assets/themes/leipzig/bQ.png +0 -0
- package/assets/themes/leipzig/bR.png +0 -0
- package/assets/themes/leipzig/wB.png +0 -0
- package/assets/themes/leipzig/wK.png +0 -0
- package/assets/themes/leipzig/wN.png +0 -0
- package/assets/themes/leipzig/wP.png +0 -0
- package/assets/themes/leipzig/wQ.png +0 -0
- package/assets/themes/leipzig/wR.png +0 -0
- package/assets/themes/merida/bB.png +0 -0
- package/assets/themes/merida/bK.png +0 -0
- package/assets/themes/merida/bN.png +0 -0
- package/assets/themes/merida/bP.png +0 -0
- package/assets/themes/merida/bQ.png +0 -0
- package/assets/themes/merida/bR.png +0 -0
- package/assets/themes/merida/wB.png +0 -0
- package/assets/themes/merida/wK.png +0 -0
- package/assets/themes/merida/wN.png +0 -0
- package/assets/themes/merida/wP.png +0 -0
- package/assets/themes/merida/wQ.png +0 -0
- package/assets/themes/merida/wR.png +0 -0
- package/dist/index.cjs +43 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +43 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/assets/themes/alpha/bB.svg +0 -20
- package/assets/themes/alpha/bK.svg +0 -21
- package/assets/themes/alpha/bN.svg +0 -19
- package/assets/themes/alpha/bP.svg +0 -19
- package/assets/themes/alpha/bQ.svg +0 -22
- package/assets/themes/alpha/bR.svg +0 -22
- package/assets/themes/alpha/wB.svg +0 -20
- package/assets/themes/alpha/wK.svg +0 -21
- package/assets/themes/alpha/wN.svg +0 -19
- package/assets/themes/alpha/wP.svg +0 -19
- package/assets/themes/alpha/wQ.svg +0 -22
- package/assets/themes/alpha/wR.svg +0 -22
- package/assets/themes/cburnett/bB.svg +0 -20
- package/assets/themes/cburnett/bK.svg +0 -21
- package/assets/themes/cburnett/bN.svg +0 -19
- package/assets/themes/cburnett/bP.svg +0 -19
- package/assets/themes/cburnett/bQ.svg +0 -22
- package/assets/themes/cburnett/bR.svg +0 -22
- package/assets/themes/cburnett/wB.svg +0 -20
- package/assets/themes/cburnett/wK.svg +0 -21
- package/assets/themes/cburnett/wN.svg +0 -19
- package/assets/themes/cburnett/wP.svg +0 -19
- package/assets/themes/cburnett/wQ.svg +0 -22
- package/assets/themes/cburnett/wR.svg +0 -22
- package/assets/themes/cheq/bB.svg +0 -20
- package/assets/themes/cheq/bK.svg +0 -21
- package/assets/themes/cheq/bN.svg +0 -19
- package/assets/themes/cheq/bP.svg +0 -19
- package/assets/themes/cheq/bQ.svg +0 -22
- package/assets/themes/cheq/bR.svg +0 -22
- package/assets/themes/cheq/wB.svg +0 -20
- package/assets/themes/cheq/wK.svg +0 -21
- package/assets/themes/cheq/wN.svg +0 -19
- package/assets/themes/cheq/wP.svg +0 -19
- package/assets/themes/cheq/wQ.svg +0 -22
- package/assets/themes/cheq/wR.svg +0 -22
- package/assets/themes/leipzig/bB.svg +0 -20
- package/assets/themes/leipzig/bK.svg +0 -21
- package/assets/themes/leipzig/bN.svg +0 -19
- package/assets/themes/leipzig/bP.svg +0 -19
- package/assets/themes/leipzig/bQ.svg +0 -22
- package/assets/themes/leipzig/bR.svg +0 -22
- package/assets/themes/leipzig/wB.svg +0 -20
- package/assets/themes/leipzig/wK.svg +0 -21
- package/assets/themes/leipzig/wN.svg +0 -19
- package/assets/themes/leipzig/wP.svg +0 -19
- package/assets/themes/leipzig/wQ.svg +0 -22
- package/assets/themes/leipzig/wR.svg +0 -22
- package/assets/themes/merida/bB.svg +0 -20
- package/assets/themes/merida/bK.svg +0 -21
- package/assets/themes/merida/bN.svg +0 -19
- package/assets/themes/merida/bP.svg +0 -19
- package/assets/themes/merida/bQ.svg +0 -22
- package/assets/themes/merida/bR.svg +0 -22
- package/assets/themes/merida/wB.svg +0 -20
- package/assets/themes/merida/wK.svg +0 -21
- package/assets/themes/merida/wN.svg +0 -19
- package/assets/themes/merida/wP.svg +0 -19
- package/assets/themes/merida/wQ.svg +0 -22
- package/assets/themes/merida/wR.svg +0 -22
package/ATTRIBUTION.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bundled Theme Attribution
|
|
2
2
|
|
|
3
|
-
This package vendors five built-in
|
|
3
|
+
This package vendors five built-in chess piece theme sets under [`assets/themes`](/root/Chess2img/assets/themes):
|
|
4
4
|
|
|
5
5
|
- `merida`
|
|
6
6
|
- `alpha`
|
|
@@ -8,12 +8,23 @@ This package vendors five built-in SVG theme sets under [`assets/themes`](/root/
|
|
|
8
8
|
- `cheq`
|
|
9
9
|
- `leipzig`
|
|
10
10
|
|
|
11
|
-
These bundled assets are
|
|
11
|
+
These bundled built-in assets are derived from the upstream resource packs in:
|
|
12
|
+
|
|
13
|
+
- `andyruwruw/chess-image-generator`
|
|
14
|
+
- upstream resource path: `src/resources/{merida,alpha,cburnett,cheq,leipzig}`
|
|
15
|
+
|
|
16
|
+
Packaging and conversion notes:
|
|
17
|
+
|
|
18
|
+
- the upstream repository stores these built-in piece packs as PNG raster assets
|
|
19
|
+
- this package vendors those upstream-derived PNG assets in-package under canonical internal filenames such as `wK.png` and `bQ.png`
|
|
20
|
+
- the filename normalization is a packaging conversion only; the piece imagery itself is derived from the upstream resource packs rather than redrawn for this rewrite
|
|
12
21
|
|
|
13
22
|
Theme provenance notes:
|
|
14
23
|
|
|
15
24
|
- no runtime or build-time third-party theme package is required to use the bundled themes
|
|
16
25
|
- theme names preserve the familiar public style options from the original library
|
|
17
|
-
- the
|
|
26
|
+
- the upstream `chess-image-generator` repository is MIT-licensed
|
|
27
|
+
- the upstream README cites [Marcel van Kervinck](https://marcelk.net/chess/pieces/) as the source of the piece images
|
|
28
|
+
- the original license status of the underlying piece-pack sources could not be fully verified from the current environment, so this package does not claim independent license certainty for those underlying assets beyond the upstream repository's published metadata
|
|
18
29
|
|
|
19
30
|
If third-party themes are added later through `registerTheme(theme)`, their licensing and attribution remain the responsibility of the integrating application or package author.
|
package/README.md
CHANGED
|
@@ -170,6 +170,11 @@ Or pass either:
|
|
|
170
170
|
- a registered custom theme name through `theme: "custom-theme"`
|
|
171
171
|
- an inline `ThemeDefinition` object through `theme: { ... }`
|
|
172
172
|
|
|
173
|
+
Custom themes may use either:
|
|
174
|
+
|
|
175
|
+
- `svg` assets
|
|
176
|
+
- `png` assets
|
|
177
|
+
|
|
173
178
|
## Error Model
|
|
174
179
|
|
|
175
180
|
The library exports:
|
|
@@ -184,7 +189,7 @@ The library exports:
|
|
|
184
189
|
|
|
185
190
|
- `core` parses and validates chess position input into a canonical board model
|
|
186
191
|
- `themes` validates, registers, and resolves built-in or custom themes
|
|
187
|
-
- `render` rasterizes SVG
|
|
192
|
+
- `render` rasterizes SVG or PNG theme assets and renders PNG output through `canvas`
|
|
188
193
|
- `api` orchestrates parsing, theme resolution, rendering, and file output
|
|
189
194
|
|
|
190
195
|
## Migration From `chess-image-generator`
|
|
@@ -206,4 +211,4 @@ The library exports:
|
|
|
206
211
|
|
|
207
212
|
## Asset Attribution
|
|
208
213
|
|
|
209
|
-
Bundled
|
|
214
|
+
Bundled built-in themes are derived from the upstream `andyruwruw/chess-image-generator` resource packs and are vendored in-package for deterministic installs. Provenance and licensing notes live in [ATTRIBUTION.md](/root/Chess2img/ATTRIBUTION.md).
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -262,6 +262,7 @@ var import_promises = require("fs/promises");
|
|
|
262
262
|
var import_canvas = require("canvas");
|
|
263
263
|
var import_resvg_js = require("@resvg/resvg-js");
|
|
264
264
|
var svgSourceCache = new SourceAssetCache();
|
|
265
|
+
var imageBufferCache = new SourceAssetCache();
|
|
265
266
|
async function readSvgSource(filePath) {
|
|
266
267
|
const cached = svgSourceCache.get(filePath);
|
|
267
268
|
if (cached) {
|
|
@@ -275,6 +276,19 @@ async function readSvgSource(filePath) {
|
|
|
275
276
|
throw new RenderError(`Failed to read SVG asset: ${filePath}`, { cause: error });
|
|
276
277
|
}
|
|
277
278
|
}
|
|
279
|
+
async function readBinaryAsset(filePath) {
|
|
280
|
+
const cached = imageBufferCache.get(filePath);
|
|
281
|
+
if (cached) {
|
|
282
|
+
return cached;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const source = await (0, import_promises.readFile)(filePath);
|
|
286
|
+
imageBufferCache.set(filePath, source);
|
|
287
|
+
return source;
|
|
288
|
+
} catch (error) {
|
|
289
|
+
throw new RenderError(`Failed to read image asset: ${filePath}`, { cause: error });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
278
292
|
async function rasterizeSvgAsset(filePath, squareSize) {
|
|
279
293
|
try {
|
|
280
294
|
const svgSource = await readSvgSource(filePath);
|
|
@@ -294,6 +308,24 @@ async function rasterizeSvgAsset(filePath, squareSize) {
|
|
|
294
308
|
throw new RenderError(`Failed to rasterize SVG asset: ${filePath}`, { cause: error });
|
|
295
309
|
}
|
|
296
310
|
}
|
|
311
|
+
async function rasterizePngAsset(filePath, squareSize) {
|
|
312
|
+
try {
|
|
313
|
+
const pngSource = await readBinaryAsset(filePath);
|
|
314
|
+
const image = await (0, import_canvas.loadImage)(pngSource);
|
|
315
|
+
const canvas = (0, import_canvas.createCanvas)(squareSize, squareSize);
|
|
316
|
+
const context = canvas.getContext("2d");
|
|
317
|
+
context.drawImage(image, 0, 0, squareSize, squareSize);
|
|
318
|
+
return canvas;
|
|
319
|
+
} catch (error) {
|
|
320
|
+
throw new RenderError(`Failed to rasterize PNG asset: ${filePath}`, { cause: error });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function rasterizeThemeAsset(asset, squareSize) {
|
|
324
|
+
if (asset.kind === "svg") {
|
|
325
|
+
return rasterizeSvgAsset(asset.source, squareSize);
|
|
326
|
+
}
|
|
327
|
+
return rasterizePngAsset(asset.source, squareSize);
|
|
328
|
+
}
|
|
297
329
|
|
|
298
330
|
// src/render/canvas-renderer.ts
|
|
299
331
|
var pieceRasterCache = new RasterAssetCache();
|
|
@@ -302,13 +334,13 @@ function isDarkSquare(square) {
|
|
|
302
334
|
const rankNumber = Number(square[1]);
|
|
303
335
|
return (fileIndex + rankNumber) % 2 === 1;
|
|
304
336
|
}
|
|
305
|
-
async function getPieceRaster(themeName, pieceKey,
|
|
337
|
+
async function getPieceRaster(themeName, pieceKey, asset, squareSize) {
|
|
306
338
|
const cacheKey = createRasterCacheKey(themeName, pieceKey, squareSize, "png-canvas");
|
|
307
339
|
const cached = pieceRasterCache.get(cacheKey);
|
|
308
340
|
if (cached) {
|
|
309
341
|
return cached;
|
|
310
342
|
}
|
|
311
|
-
const raster = await
|
|
343
|
+
const raster = await rasterizeThemeAsset(asset, squareSize);
|
|
312
344
|
pieceRasterCache.set(cacheKey, raster);
|
|
313
345
|
return raster;
|
|
314
346
|
}
|
|
@@ -346,11 +378,10 @@ var CanvasPngRenderer = class {
|
|
|
346
378
|
if (!pieceKey) {
|
|
347
379
|
continue;
|
|
348
380
|
}
|
|
349
|
-
const assetPath2 = request.theme.pieces[pieceKey].source;
|
|
350
381
|
const raster = await getPieceRaster(
|
|
351
382
|
request.theme.name,
|
|
352
383
|
pieceKey,
|
|
353
|
-
|
|
384
|
+
request.theme.pieces[pieceKey],
|
|
354
385
|
Math.round(geometry.squareSize)
|
|
355
386
|
);
|
|
356
387
|
context.drawImage(
|
|
@@ -413,8 +444,8 @@ function validateThemeDefinition(theme) {
|
|
|
413
444
|
}
|
|
414
445
|
for (const pieceKey of REQUIRED_PIECES) {
|
|
415
446
|
const asset = theme.pieces[pieceKey];
|
|
416
|
-
if (!asset || asset.kind !== "svg" || !asset.source.trim()) {
|
|
417
|
-
throw new ThemeError(`Theme "${normalizedName}" is missing
|
|
447
|
+
if (!asset || asset.kind !== "svg" && asset.kind !== "png" || !asset.source.trim()) {
|
|
448
|
+
throw new ThemeError(`Theme "${normalizedName}" is missing asset ${pieceKey}`);
|
|
418
449
|
}
|
|
419
450
|
}
|
|
420
451
|
return {
|
|
@@ -462,9 +493,9 @@ var PIECE_KEYS = [
|
|
|
462
493
|
var initialized = false;
|
|
463
494
|
function assetPath(themeName, pieceKey) {
|
|
464
495
|
const candidates = [
|
|
465
|
-
(0, import_node_path.resolve)(__dirname, "../../assets/themes", themeName, `${pieceKey}.
|
|
466
|
-
(0, import_node_path.resolve)(__dirname, "../assets/themes", themeName, `${pieceKey}.
|
|
467
|
-
(0, import_node_path.resolve)(process.cwd(), "assets/themes", themeName, `${pieceKey}.
|
|
496
|
+
(0, import_node_path.resolve)(__dirname, "../../assets/themes", themeName, `${pieceKey}.png`),
|
|
497
|
+
(0, import_node_path.resolve)(__dirname, "../assets/themes", themeName, `${pieceKey}.png`),
|
|
498
|
+
(0, import_node_path.resolve)(process.cwd(), "assets/themes", themeName, `${pieceKey}.png`)
|
|
468
499
|
];
|
|
469
500
|
const match = candidates.find((candidate) => (0, import_node_fs.existsSync)(candidate));
|
|
470
501
|
return match ?? candidates[0];
|
|
@@ -473,13 +504,13 @@ function createBuiltInTheme(themeName) {
|
|
|
473
504
|
return {
|
|
474
505
|
name: themeName,
|
|
475
506
|
displayName: themeName[0].toUpperCase() + themeName.slice(1),
|
|
476
|
-
license: "
|
|
477
|
-
attribution: "
|
|
507
|
+
license: "Derived from upstream chess-image-generator resource pack; original pack license not fully verified",
|
|
508
|
+
attribution: "Derived from andyruwruw/chess-image-generator bundled resources; upstream README cites Marcel van Kervinck as source",
|
|
478
509
|
pieces: Object.fromEntries(
|
|
479
510
|
PIECE_KEYS.map((pieceKey) => [
|
|
480
511
|
pieceKey,
|
|
481
512
|
{
|
|
482
|
-
kind: "
|
|
513
|
+
kind: "png",
|
|
483
514
|
source: assetPath(themeName, pieceKey)
|
|
484
515
|
}
|
|
485
516
|
])
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/errors.ts","../src/core/parsers.ts","../src/core/board.ts","../src/core/validators.ts","../src/core/highlights.ts","../src/render/canvas-renderer.ts","../src/core/geometry.ts","../src/render/asset-cache.ts","../src/render/rasterizer.ts","../src/utils/io.ts","../src/themes/builtins.ts","../src/themes/validation.ts","../src/themes/registry.ts","../src/themes/resolver.ts","../src/utils/normalization.ts","../src/api/class-api.ts","../src/api/functional-api.ts"],"sourcesContent":["export * from \"./types/errors\";\nexport * from \"./types/types\";\nexport * from \"./api/class-api\";\nexport * from \"./api/functional-api\";\nexport * from \"./api/theme-api\";\n","export class ValidationError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ValidationError\";\n }\n}\n\nexport class ParseError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ParseError\";\n }\n}\n\nexport class ThemeError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ThemeError\";\n }\n}\n\nexport class RenderError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"RenderError\";\n }\n}\n\nexport class IOError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"IOError\";\n }\n}\n","import { Chess } from \"chess.js\";\nimport type { BoardArray, BoardCell, PieceKey } from \"../types/types\";\nimport { ParseError, ValidationError } from \"../types/errors\";\nimport { createEmptyBoardPosition, FILES } from \"./board\";\nimport { validateBoardArray } from \"./validators\";\n\nconst PIECE_SYMBOL_TO_KEY: Record<string, PieceKey> = {\n K: \"wK\",\n Q: \"wQ\",\n R: \"wR\",\n B: \"wB\",\n N: \"wN\",\n P: \"wP\",\n k: \"bK\",\n q: \"bQ\",\n r: \"bR\",\n b: \"bB\",\n n: \"bN\",\n p: \"bP\",\n};\n\nfunction chessBoardToBoardArray(board: ReturnType<Chess[\"board\"]>): BoardArray {\n return board.map((rank) =>\n rank.map((piece): BoardCell => {\n if (!piece) {\n return null;\n }\n\n return piece.color === \"w\" ? piece.type.toUpperCase() : piece.type;\n }),\n );\n}\n\nexport function parseFEN(fen: string) {\n const chess = new Chess();\n\n try {\n chess.load(fen);\n } catch (error) {\n throw new ParseError(\"Invalid FEN\", { cause: error });\n }\n\n return parseBoardArray(chessBoardToBoardArray(chess.board()));\n}\n\nexport function parsePGN(pgn: string) {\n const chess = new Chess();\n\n try {\n chess.loadPgn(pgn);\n } catch (error) {\n throw new ParseError(\"Invalid PGN\", { cause: error });\n }\n\n return parseBoardArray(chessBoardToBoardArray(chess.board()));\n}\n\nexport function parseBoardArray(board: BoardArray) {\n const validatedBoard = validateBoardArray(board);\n const position = createEmptyBoardPosition();\n\n validatedBoard.forEach((rank, rankIndex) => {\n rank.forEach((cell, fileIndex) => {\n if (cell === null) {\n return;\n }\n\n const pieceKey = PIECE_SYMBOL_TO_KEY[cell];\n\n if (!pieceKey) {\n throw new ValidationError(`Invalid board piece: ${cell}`);\n }\n\n const square = `${FILES[fileIndex]}${8 - rankIndex}` as keyof typeof position.squares;\n position.squares[square] = pieceKey;\n });\n });\n\n return position;\n}\n","import type { PieceKey, Square } from \"../types/types\";\n\nexport const FILES = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"] as const;\nexport const RANKS = [\"8\", \"7\", \"6\", \"5\", \"4\", \"3\", \"2\", \"1\"] as const;\n\nexport const SQUARES: Square[] = RANKS.flatMap((rank) =>\n FILES.map((file) => `${file}${rank}`),\n);\n\nexport interface BoardPosition {\n squares: Record<Square, PieceKey | null>;\n}\n\nexport function createEmptyBoardPosition(): BoardPosition {\n return {\n squares: Object.fromEntries(\n SQUARES.map((square) => [square, null]),\n ) as Record<Square, PieceKey | null>,\n };\n}\n","import type { BoardArray, BoardCell, Padding, Square } from \"../types/types\";\nimport { ValidationError } from \"../types/errors\";\n\nconst SQUARE_PATTERN = /^[a-h][1-8]$/;\nconst PIECE_PATTERN = /^[prnbqkPRNBQK]$/;\nconst BUILT_IN_THEME_PATTERN = /^(merida|alpha|cburnett|cheq|leipzig)$/;\n\nexport function validateSize(size: number): number {\n if (!Number.isFinite(size) || size <= 0) {\n throw new ValidationError(`Invalid board size: ${size}`);\n }\n\n return Math.round(size);\n}\n\nexport function normalizePadding(padding?: number[] | Padding): Padding {\n const candidate = padding ?? [0, 0, 0, 0];\n\n if (\n !Array.isArray(candidate) ||\n candidate.length !== 4 ||\n candidate.some((value) => !Number.isFinite(value) || value < 0)\n ) {\n throw new ValidationError(\"Padding must be a 4-item array of non-negative numbers\");\n }\n\n return [\n Math.round(candidate[0]),\n Math.round(candidate[1]),\n Math.round(candidate[2]),\n Math.round(candidate[3]),\n ];\n}\n\nexport function validateSquare(square: string): Square {\n const normalized = square.trim().toLowerCase();\n\n if (!SQUARE_PATTERN.test(normalized)) {\n throw new ValidationError(`Invalid square: ${square}`);\n }\n\n return normalized;\n}\n\nexport function validateBoardCell(cell: BoardCell): BoardCell {\n if (cell === null || cell === \"\" || cell === \" \") {\n return null;\n }\n\n if (typeof cell !== \"string\" || !PIECE_PATTERN.test(cell)) {\n throw new ValidationError(`Invalid board piece: ${String(cell)}`);\n }\n\n return cell;\n}\n\nexport function validateBoardArray(board: BoardArray): BoardArray {\n if (!Array.isArray(board) || board.length !== 8) {\n throw new ValidationError(\"Board array must have exactly 8 ranks\");\n }\n\n return board.map((rank, rankIndex) => {\n if (!Array.isArray(rank) || rank.length !== 8) {\n throw new ValidationError(`Board rank ${rankIndex} must contain exactly 8 files`);\n }\n\n return rank.map(validateBoardCell);\n });\n}\n\nexport function validateStyleName(style: string): string {\n const normalized = style.trim().toLowerCase();\n\n if (!BUILT_IN_THEME_PATTERN.test(normalized)) {\n throw new ValidationError(`Unknown built-in style: ${style}`);\n }\n\n return normalized;\n}\n\nexport function validateThemeName(name: string): string {\n const normalized = name.trim().toLowerCase();\n\n if (!/^[a-z0-9-]+$/.test(normalized)) {\n throw new ValidationError(`Invalid theme name: ${name}`);\n }\n\n return normalized;\n}\n","import type { Square } from \"../types/types\";\nimport { validateSquare } from \"./validators\";\n\nexport function normalizeHighlights(input: string[]): Square[] {\n return [...new Set(input.map(validateSquare))].sort();\n}\n","import { createCanvas } from \"canvas\";\nimport { SQUARES } from \"../core/board\";\nimport { createBoardGeometry } from \"../core/geometry\";\nimport { RenderError } from \"../types/errors\";\nimport { createRasterCacheKey, RasterAssetCache } from \"./asset-cache\";\nimport type { RenderRequest, Renderer } from \"./renderer\";\nimport { rasterizeSvgAsset } from \"./rasterizer\";\n\nconst pieceRasterCache = new RasterAssetCache<Awaited<ReturnType<typeof rasterizeSvgAsset>>>();\n\nfunction isDarkSquare(square: string): boolean {\n const fileIndex = square.charCodeAt(0) - 97;\n const rankNumber = Number(square[1]);\n return (fileIndex + rankNumber) % 2 === 1;\n}\n\nasync function getPieceRaster(themeName: string, pieceKey: string, assetPath: string, squareSize: number) {\n const cacheKey = createRasterCacheKey(themeName, pieceKey, squareSize, \"png-canvas\");\n const cached = pieceRasterCache.get(cacheKey);\n\n if (cached) {\n return cached;\n }\n\n const raster = await rasterizeSvgAsset(assetPath, squareSize);\n pieceRasterCache.set(cacheKey, raster);\n return raster;\n}\n\nexport class CanvasPngRenderer implements Renderer<Buffer> {\n async render(request: RenderRequest): Promise<Buffer> {\n try {\n const geometry = createBoardGeometry({\n size: request.size,\n padding: request.padding,\n flipped: request.flipped,\n });\n\n const canvas = createCanvas(geometry.imageWidth, geometry.imageHeight);\n const context = canvas.getContext(\"2d\");\n\n context.fillStyle = request.colors.lightSquare;\n context.fillRect(0, 0, geometry.imageWidth, geometry.imageHeight);\n\n for (const square of SQUARES) {\n const squareGeometry = geometry.squares[square];\n context.fillStyle = isDarkSquare(square)\n ? request.colors.darkSquare\n : request.colors.lightSquare;\n context.fillRect(\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n\n if (request.highlights.includes(square)) {\n context.fillStyle = request.colors.highlight;\n context.fillRect(\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n }\n\n const pieceKey = request.board.squares[square];\n if (!pieceKey) {\n continue;\n }\n\n const assetPath = request.theme.pieces[pieceKey].source;\n const raster = await getPieceRaster(\n request.theme.name,\n pieceKey,\n assetPath,\n Math.round(geometry.squareSize),\n );\n context.drawImage(\n raster,\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n }\n\n return canvas.toBuffer(\"image/png\");\n } catch (error) {\n if (error instanceof RenderError) {\n throw error;\n }\n\n throw new RenderError(\"Failed to render chess board\", { cause: error });\n }\n }\n}\n","import type { Padding, Square } from \"../types/types\";\nimport { SQUARES } from \"./board\";\n\nexport interface SquareGeometry {\n x: number;\n y: number;\n size: number;\n}\n\nexport interface BoardGeometry {\n imageWidth: number;\n imageHeight: number;\n squareSize: number;\n boardX: number;\n boardY: number;\n boardSize: number;\n squares: Record<Square, SquareGeometry>;\n}\n\ninterface BoardGeometryOptions {\n size: number;\n padding: Padding;\n flipped: boolean;\n}\n\nexport function createBoardGeometry({\n size,\n padding,\n flipped,\n}: BoardGeometryOptions): BoardGeometry {\n const [top, right, bottom, left] = padding;\n const squareSize = size / 8;\n\n const squares = Object.fromEntries(\n SQUARES.map((square, index) => {\n const fileIndex = index % 8;\n const rankIndex = Math.floor(index / 8);\n\n const x = left + (flipped ? 7 - fileIndex : fileIndex) * squareSize;\n const y = top + (flipped ? 7 - rankIndex : rankIndex) * squareSize;\n\n return [square, { x, y, size: squareSize }];\n }),\n ) as Record<Square, SquareGeometry>;\n\n return {\n imageWidth: left + size + right,\n imageHeight: top + size + bottom,\n squareSize,\n boardX: left,\n boardY: top,\n boardSize: size,\n squares,\n };\n}\n","export function createRasterCacheKey(\n themeName: string,\n pieceKey: string,\n squareSize: number,\n backend: string,\n): string {\n return `${themeName}:${pieceKey}:${squareSize}:${backend}`;\n}\n\nexport class RasterAssetCache<T> {\n private readonly cache = new Map<string, T>();\n\n get(key: string): T | undefined {\n return this.cache.get(key);\n }\n\n set(key: string, value: T): void {\n this.cache.set(key, value);\n }\n}\n\nexport class SourceAssetCache<T> {\n private readonly cache = new Map<string, T>();\n\n get(key: string): T | undefined {\n return this.cache.get(key);\n }\n\n set(key: string, value: T): void {\n this.cache.set(key, value);\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { createCanvas, loadImage } from \"canvas\";\nimport { Resvg } from \"@resvg/resvg-js\";\nimport { RenderError } from \"../types/errors\";\nimport { SourceAssetCache } from \"./asset-cache\";\n\nconst svgSourceCache = new SourceAssetCache<string>();\n\nasync function readSvgSource(filePath: string): Promise<string> {\n const cached = svgSourceCache.get(filePath);\n\n if (cached) {\n return cached;\n }\n\n try {\n const source = await readFile(filePath, \"utf8\");\n svgSourceCache.set(filePath, source);\n return source;\n } catch (error) {\n throw new RenderError(`Failed to read SVG asset: ${filePath}`, { cause: error });\n }\n}\n\nexport async function rasterizeSvgAsset(filePath: string, squareSize: number) {\n try {\n const svgSource = await readSvgSource(filePath);\n const resvg = new Resvg(svgSource, {\n fitTo: {\n mode: \"width\",\n value: squareSize,\n },\n });\n const pngBuffer = resvg.render().asPng();\n const image = await loadImage(pngBuffer);\n const canvas = createCanvas(squareSize, squareSize);\n const context = canvas.getContext(\"2d\");\n context.drawImage(image, 0, 0, squareSize, squareSize);\n return canvas;\n } catch (error) {\n throw new RenderError(`Failed to rasterize SVG asset: ${filePath}`, { cause: error });\n }\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { IOError } from \"../types/errors\";\n\nexport async function writeBufferToFile(filePath: string, buffer: Buffer): Promise<void> {\n try {\n await writeFile(filePath, buffer);\n } catch (error) {\n throw new IOError(`Failed to write file: ${filePath}`, { cause: error });\n }\n}\n","import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { PieceKey, PieceStyle, ThemeDefinition } from \"../types/types\";\nimport { registerTheme } from \"./registry\";\n\nexport const builtInThemeNames = [\n \"merida\",\n \"alpha\",\n \"cburnett\",\n \"cheq\",\n \"leipzig\",\n] as const satisfies readonly PieceStyle[];\n\nconst PIECE_KEYS: PieceKey[] = [\n \"wK\",\n \"wQ\",\n \"wR\",\n \"wB\",\n \"wN\",\n \"wP\",\n \"bK\",\n \"bQ\",\n \"bR\",\n \"bB\",\n \"bN\",\n \"bP\",\n];\n\nlet initialized = false;\n\nfunction assetPath(themeName: PieceStyle, pieceKey: PieceKey): string {\n const candidates = [\n resolve(__dirname, \"../../assets/themes\", themeName, `${pieceKey}.svg`),\n resolve(__dirname, \"../assets/themes\", themeName, `${pieceKey}.svg`),\n resolve(process.cwd(), \"assets/themes\", themeName, `${pieceKey}.svg`),\n ];\n\n const match = candidates.find((candidate) => existsSync(candidate));\n return match ?? candidates[0];\n}\n\nfunction createBuiltInTheme(themeName: PieceStyle): ThemeDefinition {\n return {\n name: themeName,\n displayName: themeName[0].toUpperCase() + themeName.slice(1),\n license: \"MIT\",\n attribution: \"Project-authored built-in SVG theme\",\n pieces: Object.fromEntries(\n PIECE_KEYS.map((pieceKey) => [\n pieceKey,\n {\n kind: \"svg\",\n source: assetPath(themeName, pieceKey),\n },\n ]),\n ) as ThemeDefinition[\"pieces\"],\n };\n}\n\nexport function initializeBuiltInThemes(): void {\n if (initialized) {\n return;\n }\n\n for (const themeName of builtInThemeNames) {\n registerTheme(createBuiltInTheme(themeName));\n }\n\n initialized = true;\n}\n\nexport function resetBuiltInThemesForTesting(): void {\n initialized = false;\n}\n","import { validateThemeName } from \"../core/validators\";\nimport { ThemeError, ValidationError } from \"../types/errors\";\nimport type { PieceKey, ThemeDefinition } from \"../types/types\";\n\nconst REQUIRED_PIECES: PieceKey[] = [\n \"wK\",\n \"wQ\",\n \"wR\",\n \"wB\",\n \"wN\",\n \"wP\",\n \"bK\",\n \"bQ\",\n \"bR\",\n \"bB\",\n \"bN\",\n \"bP\",\n];\n\nexport function validateThemeDefinition(theme: ThemeDefinition): ThemeDefinition {\n const normalizedName = validateThemeName(theme.name);\n\n if (!theme.displayName.trim()) {\n throw new ValidationError(\"Theme displayName is required\");\n }\n\n if (!theme.license.trim()) {\n throw new ValidationError(\"Theme license is required\");\n }\n\n if (!theme.attribution.trim()) {\n throw new ValidationError(\"Theme attribution is required\");\n }\n\n for (const pieceKey of REQUIRED_PIECES) {\n const asset = theme.pieces[pieceKey];\n\n if (!asset || asset.kind !== \"svg\" || !asset.source.trim()) {\n throw new ThemeError(`Theme \"${normalizedName}\" is missing SVG asset ${pieceKey}`);\n }\n }\n\n return {\n ...theme,\n name: normalizedName,\n };\n}\n","import type { ThemeDefinition } from \"../types/types\";\nimport { ThemeError } from \"../types/errors\";\nimport { validateThemeDefinition } from \"./validation\";\n\nconst registry = new Map<string, ThemeDefinition>();\n\nexport function registerTheme(theme: ThemeDefinition): ThemeDefinition {\n const validatedTheme = validateThemeDefinition(theme);\n\n if (registry.has(validatedTheme.name)) {\n throw new ThemeError(`Theme \"${validatedTheme.name}\" is already registered`);\n }\n\n registry.set(validatedTheme.name, validatedTheme);\n return validatedTheme;\n}\n\nexport function getTheme(name: string): ThemeDefinition | undefined {\n return registry.get(name.trim().toLowerCase());\n}\n\nexport function clearThemeRegistryForTesting(): void {\n registry.clear();\n}\n","import type { PieceStyle, ThemeDefinition } from \"../types/types\";\nimport { ThemeError, ValidationError } from \"../types/errors\";\nimport { initializeBuiltInThemes } from \"./builtins\";\nimport { getTheme } from \"./registry\";\nimport { validateThemeDefinition } from \"./validation\";\n\ninterface ResolveThemeOptions {\n theme?: string | ThemeDefinition;\n style?: PieceStyle;\n}\n\nexport function resolveTheme({ theme, style }: ResolveThemeOptions): ThemeDefinition {\n initializeBuiltInThemes();\n\n if (typeof theme === \"object\" && theme !== null) {\n try {\n return validateThemeDefinition(theme);\n } catch (error) {\n if (error instanceof ThemeError) {\n throw error;\n }\n\n if (error instanceof ValidationError) {\n throw new ThemeError(error.message, { cause: error });\n }\n\n throw error;\n }\n }\n\n const requestedName = typeof theme === \"string\" ? theme : style ?? \"merida\";\n const resolvedTheme = getTheme(requestedName);\n\n if (!resolvedTheme) {\n throw new ThemeError(`Unknown theme: ${requestedName}`);\n }\n\n return resolvedTheme;\n}\n","import type {\n BoardColors,\n Padding,\n RenderOptions,\n ResolvedColors,\n Square,\n ThemeDefinition,\n} from \"../types/types\";\nimport { normalizeHighlights } from \"../core/highlights\";\nimport { normalizePadding, validateSize } from \"../core/validators\";\nimport { resolveTheme } from \"../themes/resolver\";\n\nexport const DEFAULT_SIZE = 480;\nexport const DEFAULT_PADDING: Padding = [0, 0, 0, 0];\nexport const DEFAULT_COLORS: ResolvedColors = {\n lightSquare: \"#f0d9b5\",\n darkSquare: \"#b58863\",\n highlight: \"rgba(255, 206, 0, 0.45)\",\n};\n\nexport function normalizeColors(colors?: BoardColors): ResolvedColors {\n return {\n lightSquare: colors?.lightSquare ?? DEFAULT_COLORS.lightSquare,\n darkSquare: colors?.darkSquare ?? DEFAULT_COLORS.darkSquare,\n highlight: colors?.highlight ?? DEFAULT_COLORS.highlight,\n };\n}\n\nexport function normalizeRenderInputs(options: RenderOptions & { highlightSquares?: Square[] }): {\n size: number;\n padding: Padding;\n flipped: boolean;\n theme: ThemeDefinition;\n highlightSquares: Square[];\n colors: ResolvedColors;\n} {\n return {\n size: validateSize(options.size ?? DEFAULT_SIZE),\n padding: normalizePadding(options.padding ?? DEFAULT_PADDING),\n flipped: options.flipped ?? false,\n theme: resolveTheme({\n theme: options.theme,\n style: options.style,\n }),\n highlightSquares: normalizeHighlights(options.highlightSquares ?? []),\n colors: normalizeColors(options.colors),\n };\n}\n","import { parseBoardArray, parseFEN, parsePGN } from \"../core/parsers\";\nimport { normalizeHighlights } from \"../core/highlights\";\nimport { ValidationError } from \"../types/errors\";\nimport type {\n BoardArray,\n ChessImageGeneratorOptions,\n RenderOptions,\n} from \"../types/types\";\nimport { CanvasPngRenderer } from \"../render/canvas-renderer\";\nimport { writeBufferToFile } from \"../utils/io\";\nimport { normalizeRenderInputs } from \"../utils/normalization\";\nimport type { BoardPosition } from \"../core/board\";\n\nexport class ChessImageGenerator {\n private position: BoardPosition | null = null;\n\n private readonly defaults: RenderOptions;\n\n private highlights: string[] = [];\n\n constructor(options: ChessImageGeneratorOptions = {}) {\n this.defaults = { ...options };\n normalizeRenderInputs({\n ...this.defaults,\n highlightSquares: [],\n });\n }\n\n async loadFEN(fen: string): Promise<void> {\n this.position = parseFEN(fen);\n this.clearHighlights();\n }\n\n async loadPGN(pgn: string): Promise<void> {\n this.position = parsePGN(pgn);\n this.clearHighlights();\n }\n\n async loadBoard(board: BoardArray): Promise<void> {\n this.position = parseBoardArray(board);\n this.clearHighlights();\n }\n\n setHighlights(squares: string[]): void {\n this.highlights = normalizeHighlights(squares);\n }\n\n clearHighlights(): void {\n this.highlights = [];\n }\n\n async toBuffer(): Promise<Buffer> {\n if (!this.position) {\n throw new ValidationError(\"No board position loaded\");\n }\n\n const renderer = new CanvasPngRenderer();\n const normalized = normalizeRenderInputs({\n ...this.defaults,\n highlightSquares: this.highlights,\n });\n\n return renderer.render({\n board: this.position,\n theme: normalized.theme,\n highlights: normalized.highlightSquares,\n size: normalized.size,\n padding: normalized.padding,\n flipped: normalized.flipped,\n colors: normalized.colors,\n });\n }\n\n async toFile(filePath: string): Promise<void> {\n const buffer = await this.toBuffer();\n await writeBufferToFile(filePath, buffer);\n }\n}\n","import { parseBoardArray, parseFEN, parsePGN } from \"../core/parsers\";\nimport { ValidationError } from \"../types/errors\";\nimport type { RenderChessOptions } from \"../types/types\";\nimport { CanvasPngRenderer } from \"../render/canvas-renderer\";\nimport { normalizeRenderInputs } from \"../utils/normalization\";\n\nfunction parseInputPosition(options: RenderChessOptions) {\n if (typeof options.fen === \"string\") {\n return parseFEN(options.fen);\n }\n\n if (typeof options.pgn === \"string\") {\n return parsePGN(options.pgn);\n }\n\n if (Array.isArray(options.board)) {\n return parseBoardArray(options.board);\n }\n\n throw new ValidationError(\"Exactly one of fen, pgn, or board must be provided\");\n}\n\nexport async function renderChess(options: RenderChessOptions): Promise<Buffer> {\n const provided = [\n typeof options.fen === \"string\" ? options.fen : undefined,\n typeof options.pgn === \"string\" ? options.pgn : undefined,\n Array.isArray(options.board) ? options.board : undefined,\n ].filter((value) => value !== undefined);\n\n if (provided.length !== 1) {\n throw new ValidationError(\"Exactly one of fen, pgn, or board must be provided\");\n }\n\n const position = parseInputPosition(options);\n const renderer = new CanvasPngRenderer();\n const normalized = normalizeRenderInputs(options);\n\n return renderer.render({\n board: position,\n theme: normalized.theme,\n highlights: normalized.highlightSquares,\n size: normalized.size,\n padding: normalized.padding,\n flipped: normalized.flipped,\n colors: normalized.colors,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA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IAAI,kBAAkB;AACvC,QAAM,aAAa,sBAAsB,OAAO;AAEhD,SAAO,SAAS,OAAO;AAAA,IACrB,OAAO;AAAA,IACP,OAAO,WAAW;AAAA,IAClB,YAAY,WAAW;AAAA,IACvB,MAAM,WAAW;AAAA,IACjB,SAAS,WAAW;AAAA,IACpB,SAAS,WAAW;AAAA,IACpB,QAAQ,WAAW;AAAA,EACrB,CAAC;AACH;","names":["import_canvas","assetPath","import_promises"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/errors.ts","../src/core/parsers.ts","../src/core/board.ts","../src/core/validators.ts","../src/core/highlights.ts","../src/render/canvas-renderer.ts","../src/core/geometry.ts","../src/render/asset-cache.ts","../src/render/rasterizer.ts","../src/utils/io.ts","../src/themes/builtins.ts","../src/themes/validation.ts","../src/themes/registry.ts","../src/themes/resolver.ts","../src/utils/normalization.ts","../src/api/class-api.ts","../src/api/functional-api.ts"],"sourcesContent":["export * from \"./types/errors\";\nexport * from \"./types/types\";\nexport * from \"./api/class-api\";\nexport * from \"./api/functional-api\";\nexport * from \"./api/theme-api\";\n","export class ValidationError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ValidationError\";\n }\n}\n\nexport class ParseError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ParseError\";\n }\n}\n\nexport class ThemeError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"ThemeError\";\n }\n}\n\nexport class RenderError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"RenderError\";\n }\n}\n\nexport class IOError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"IOError\";\n }\n}\n","import { Chess } from \"chess.js\";\nimport type { BoardArray, BoardCell, PieceKey } from \"../types/types\";\nimport { ParseError, ValidationError } from \"../types/errors\";\nimport { createEmptyBoardPosition, FILES } from \"./board\";\nimport { validateBoardArray } from \"./validators\";\n\nconst PIECE_SYMBOL_TO_KEY: Record<string, PieceKey> = {\n K: \"wK\",\n Q: \"wQ\",\n R: \"wR\",\n B: \"wB\",\n N: \"wN\",\n P: \"wP\",\n k: \"bK\",\n q: \"bQ\",\n r: \"bR\",\n b: \"bB\",\n n: \"bN\",\n p: \"bP\",\n};\n\nfunction chessBoardToBoardArray(board: ReturnType<Chess[\"board\"]>): BoardArray {\n return board.map((rank) =>\n rank.map((piece): BoardCell => {\n if (!piece) {\n return null;\n }\n\n return piece.color === \"w\" ? piece.type.toUpperCase() : piece.type;\n }),\n );\n}\n\nexport function parseFEN(fen: string) {\n const chess = new Chess();\n\n try {\n chess.load(fen);\n } catch (error) {\n throw new ParseError(\"Invalid FEN\", { cause: error });\n }\n\n return parseBoardArray(chessBoardToBoardArray(chess.board()));\n}\n\nexport function parsePGN(pgn: string) {\n const chess = new Chess();\n\n try {\n chess.loadPgn(pgn);\n } catch (error) {\n throw new ParseError(\"Invalid PGN\", { cause: error });\n }\n\n return parseBoardArray(chessBoardToBoardArray(chess.board()));\n}\n\nexport function parseBoardArray(board: BoardArray) {\n const validatedBoard = validateBoardArray(board);\n const position = createEmptyBoardPosition();\n\n validatedBoard.forEach((rank, rankIndex) => {\n rank.forEach((cell, fileIndex) => {\n if (cell === null) {\n return;\n }\n\n const pieceKey = PIECE_SYMBOL_TO_KEY[cell];\n\n if (!pieceKey) {\n throw new ValidationError(`Invalid board piece: ${cell}`);\n }\n\n const square = `${FILES[fileIndex]}${8 - rankIndex}` as keyof typeof position.squares;\n position.squares[square] = pieceKey;\n });\n });\n\n return position;\n}\n","import type { PieceKey, Square } from \"../types/types\";\n\nexport const FILES = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"] as const;\nexport const RANKS = [\"8\", \"7\", \"6\", \"5\", \"4\", \"3\", \"2\", \"1\"] as const;\n\nexport const SQUARES: Square[] = RANKS.flatMap((rank) =>\n FILES.map((file) => `${file}${rank}`),\n);\n\nexport interface BoardPosition {\n squares: Record<Square, PieceKey | null>;\n}\n\nexport function createEmptyBoardPosition(): BoardPosition {\n return {\n squares: Object.fromEntries(\n SQUARES.map((square) => [square, null]),\n ) as Record<Square, PieceKey | null>,\n };\n}\n","import type { BoardArray, BoardCell, Padding, Square } from \"../types/types\";\nimport { ValidationError } from \"../types/errors\";\n\nconst SQUARE_PATTERN = /^[a-h][1-8]$/;\nconst PIECE_PATTERN = /^[prnbqkPRNBQK]$/;\nconst BUILT_IN_THEME_PATTERN = /^(merida|alpha|cburnett|cheq|leipzig)$/;\n\nexport function validateSize(size: number): number {\n if (!Number.isFinite(size) || size <= 0) {\n throw new ValidationError(`Invalid board size: ${size}`);\n }\n\n return Math.round(size);\n}\n\nexport function normalizePadding(padding?: number[] | Padding): Padding {\n const candidate = padding ?? [0, 0, 0, 0];\n\n if (\n !Array.isArray(candidate) ||\n candidate.length !== 4 ||\n candidate.some((value) => !Number.isFinite(value) || value < 0)\n ) {\n throw new ValidationError(\"Padding must be a 4-item array of non-negative numbers\");\n }\n\n return [\n Math.round(candidate[0]),\n Math.round(candidate[1]),\n Math.round(candidate[2]),\n Math.round(candidate[3]),\n ];\n}\n\nexport function validateSquare(square: string): Square {\n const normalized = square.trim().toLowerCase();\n\n if (!SQUARE_PATTERN.test(normalized)) {\n throw new ValidationError(`Invalid square: ${square}`);\n }\n\n return normalized;\n}\n\nexport function validateBoardCell(cell: BoardCell): BoardCell {\n if (cell === null || cell === \"\" || cell === \" \") {\n return null;\n }\n\n if (typeof cell !== \"string\" || !PIECE_PATTERN.test(cell)) {\n throw new ValidationError(`Invalid board piece: ${String(cell)}`);\n }\n\n return cell;\n}\n\nexport function validateBoardArray(board: BoardArray): BoardArray {\n if (!Array.isArray(board) || board.length !== 8) {\n throw new ValidationError(\"Board array must have exactly 8 ranks\");\n }\n\n return board.map((rank, rankIndex) => {\n if (!Array.isArray(rank) || rank.length !== 8) {\n throw new ValidationError(`Board rank ${rankIndex} must contain exactly 8 files`);\n }\n\n return rank.map(validateBoardCell);\n });\n}\n\nexport function validateStyleName(style: string): string {\n const normalized = style.trim().toLowerCase();\n\n if (!BUILT_IN_THEME_PATTERN.test(normalized)) {\n throw new ValidationError(`Unknown built-in style: ${style}`);\n }\n\n return normalized;\n}\n\nexport function validateThemeName(name: string): string {\n const normalized = name.trim().toLowerCase();\n\n if (!/^[a-z0-9-]+$/.test(normalized)) {\n throw new ValidationError(`Invalid theme name: ${name}`);\n }\n\n return normalized;\n}\n","import type { Square } from \"../types/types\";\nimport { validateSquare } from \"./validators\";\n\nexport function normalizeHighlights(input: string[]): Square[] {\n return [...new Set(input.map(validateSquare))].sort();\n}\n","import { createCanvas } from \"canvas\";\nimport { SQUARES } from \"../core/board\";\nimport { createBoardGeometry } from \"../core/geometry\";\nimport { RenderError } from \"../types/errors\";\nimport type { ThemeAssetSource } from \"../types/types\";\nimport { createRasterCacheKey, RasterAssetCache } from \"./asset-cache\";\nimport type { RenderRequest, Renderer } from \"./renderer\";\nimport { rasterizeThemeAsset } from \"./rasterizer\";\n\nconst pieceRasterCache = new RasterAssetCache<Awaited<ReturnType<typeof rasterizeThemeAsset>>>();\n\nfunction isDarkSquare(square: string): boolean {\n const fileIndex = square.charCodeAt(0) - 97;\n const rankNumber = Number(square[1]);\n return (fileIndex + rankNumber) % 2 === 1;\n}\n\nasync function getPieceRaster(\n themeName: string,\n pieceKey: string,\n asset: ThemeAssetSource,\n squareSize: number,\n) {\n const cacheKey = createRasterCacheKey(themeName, pieceKey, squareSize, \"png-canvas\");\n const cached = pieceRasterCache.get(cacheKey);\n\n if (cached) {\n return cached;\n }\n\n const raster = await rasterizeThemeAsset(asset, squareSize);\n pieceRasterCache.set(cacheKey, raster);\n return raster;\n}\n\nexport class CanvasPngRenderer implements Renderer<Buffer> {\n async render(request: RenderRequest): Promise<Buffer> {\n try {\n const geometry = createBoardGeometry({\n size: request.size,\n padding: request.padding,\n flipped: request.flipped,\n });\n\n const canvas = createCanvas(geometry.imageWidth, geometry.imageHeight);\n const context = canvas.getContext(\"2d\");\n\n context.fillStyle = request.colors.lightSquare;\n context.fillRect(0, 0, geometry.imageWidth, geometry.imageHeight);\n\n for (const square of SQUARES) {\n const squareGeometry = geometry.squares[square];\n context.fillStyle = isDarkSquare(square)\n ? request.colors.darkSquare\n : request.colors.lightSquare;\n context.fillRect(\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n\n if (request.highlights.includes(square)) {\n context.fillStyle = request.colors.highlight;\n context.fillRect(\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n }\n\n const pieceKey = request.board.squares[square];\n if (!pieceKey) {\n continue;\n }\n\n const raster = await getPieceRaster(\n request.theme.name,\n pieceKey,\n request.theme.pieces[pieceKey],\n Math.round(geometry.squareSize),\n );\n context.drawImage(\n raster,\n squareGeometry.x,\n squareGeometry.y,\n squareGeometry.size,\n squareGeometry.size,\n );\n }\n\n return canvas.toBuffer(\"image/png\");\n } catch (error) {\n if (error instanceof RenderError) {\n throw error;\n }\n\n throw new RenderError(\"Failed to render chess board\", { cause: error });\n }\n }\n}\n","import type { Padding, Square } from \"../types/types\";\nimport { SQUARES } from \"./board\";\n\nexport interface SquareGeometry {\n x: number;\n y: number;\n size: number;\n}\n\nexport interface BoardGeometry {\n imageWidth: number;\n imageHeight: number;\n squareSize: number;\n boardX: number;\n boardY: number;\n boardSize: number;\n squares: Record<Square, SquareGeometry>;\n}\n\ninterface BoardGeometryOptions {\n size: number;\n padding: Padding;\n flipped: boolean;\n}\n\nexport function createBoardGeometry({\n size,\n padding,\n flipped,\n}: BoardGeometryOptions): BoardGeometry {\n const [top, right, bottom, left] = padding;\n const squareSize = size / 8;\n\n const squares = Object.fromEntries(\n SQUARES.map((square, index) => {\n const fileIndex = index % 8;\n const rankIndex = Math.floor(index / 8);\n\n const x = left + (flipped ? 7 - fileIndex : fileIndex) * squareSize;\n const y = top + (flipped ? 7 - rankIndex : rankIndex) * squareSize;\n\n return [square, { x, y, size: squareSize }];\n }),\n ) as Record<Square, SquareGeometry>;\n\n return {\n imageWidth: left + size + right,\n imageHeight: top + size + bottom,\n squareSize,\n boardX: left,\n boardY: top,\n boardSize: size,\n squares,\n };\n}\n","export function createRasterCacheKey(\n themeName: string,\n pieceKey: string,\n squareSize: number,\n backend: string,\n): string {\n return `${themeName}:${pieceKey}:${squareSize}:${backend}`;\n}\n\nexport class RasterAssetCache<T> {\n private readonly cache = new Map<string, T>();\n\n get(key: string): T | undefined {\n return this.cache.get(key);\n }\n\n set(key: string, value: T): void {\n this.cache.set(key, value);\n }\n}\n\nexport class SourceAssetCache<T> {\n private readonly cache = new Map<string, T>();\n\n get(key: string): T | undefined {\n return this.cache.get(key);\n }\n\n set(key: string, value: T): void {\n this.cache.set(key, value);\n }\n}\n","import { readFile } from \"node:fs/promises\";\nimport { createCanvas, loadImage } from \"canvas\";\nimport { Resvg } from \"@resvg/resvg-js\";\nimport { RenderError } from \"../types/errors\";\nimport type { ThemeAssetSource } from \"../types/types\";\nimport { SourceAssetCache } from \"./asset-cache\";\n\nconst svgSourceCache = new SourceAssetCache<string>();\nconst imageBufferCache = new SourceAssetCache<Buffer>();\n\nasync function readSvgSource(filePath: string): Promise<string> {\n const cached = svgSourceCache.get(filePath);\n\n if (cached) {\n return cached;\n }\n\n try {\n const source = await readFile(filePath, \"utf8\");\n svgSourceCache.set(filePath, source);\n return source;\n } catch (error) {\n throw new RenderError(`Failed to read SVG asset: ${filePath}`, { cause: error });\n }\n}\n\nasync function readBinaryAsset(filePath: string): Promise<Buffer> {\n const cached = imageBufferCache.get(filePath);\n\n if (cached) {\n return cached;\n }\n\n try {\n const source = await readFile(filePath);\n imageBufferCache.set(filePath, source);\n return source;\n } catch (error) {\n throw new RenderError(`Failed to read image asset: ${filePath}`, { cause: error });\n }\n}\n\nasync function rasterizeSvgAsset(filePath: string, squareSize: number) {\n try {\n const svgSource = await readSvgSource(filePath);\n const resvg = new Resvg(svgSource, {\n fitTo: {\n mode: \"width\",\n value: squareSize,\n },\n });\n const pngBuffer = resvg.render().asPng();\n const image = await loadImage(pngBuffer);\n const canvas = createCanvas(squareSize, squareSize);\n const context = canvas.getContext(\"2d\");\n context.drawImage(image, 0, 0, squareSize, squareSize);\n return canvas;\n } catch (error) {\n throw new RenderError(`Failed to rasterize SVG asset: ${filePath}`, { cause: error });\n }\n}\n\nasync function rasterizePngAsset(filePath: string, squareSize: number) {\n try {\n const pngSource = await readBinaryAsset(filePath);\n const image = await loadImage(pngSource);\n const canvas = createCanvas(squareSize, squareSize);\n const context = canvas.getContext(\"2d\");\n context.drawImage(image, 0, 0, squareSize, squareSize);\n return canvas;\n } catch (error) {\n throw new RenderError(`Failed to rasterize PNG asset: ${filePath}`, { cause: error });\n }\n}\n\nexport async function rasterizeThemeAsset(asset: ThemeAssetSource, squareSize: number) {\n if (asset.kind === \"svg\") {\n return rasterizeSvgAsset(asset.source, squareSize);\n }\n\n return rasterizePngAsset(asset.source, squareSize);\n}\n","import { writeFile } from \"node:fs/promises\";\nimport { IOError } from \"../types/errors\";\n\nexport async function writeBufferToFile(filePath: string, buffer: Buffer): Promise<void> {\n try {\n await writeFile(filePath, buffer);\n } catch (error) {\n throw new IOError(`Failed to write file: ${filePath}`, { cause: error });\n }\n}\n","import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { PieceKey, PieceStyle, ThemeDefinition } from \"../types/types\";\nimport { registerTheme } from \"./registry\";\n\nexport const builtInThemeNames = [\n \"merida\",\n \"alpha\",\n \"cburnett\",\n \"cheq\",\n \"leipzig\",\n] as const satisfies readonly PieceStyle[];\n\nconst PIECE_KEYS: PieceKey[] = [\n \"wK\",\n \"wQ\",\n \"wR\",\n \"wB\",\n \"wN\",\n \"wP\",\n \"bK\",\n \"bQ\",\n \"bR\",\n \"bB\",\n \"bN\",\n \"bP\",\n];\n\nlet initialized = false;\n\nfunction assetPath(themeName: PieceStyle, pieceKey: PieceKey): string {\n const candidates = [\n resolve(__dirname, \"../../assets/themes\", themeName, `${pieceKey}.png`),\n resolve(__dirname, \"../assets/themes\", themeName, `${pieceKey}.png`),\n resolve(process.cwd(), \"assets/themes\", themeName, `${pieceKey}.png`),\n ];\n\n const match = candidates.find((candidate) => existsSync(candidate));\n return match ?? candidates[0];\n}\n\nfunction createBuiltInTheme(themeName: PieceStyle): ThemeDefinition {\n return {\n name: themeName,\n displayName: themeName[0].toUpperCase() + themeName.slice(1),\n license: \"Derived from upstream chess-image-generator resource pack; original pack license not fully verified\",\n attribution:\n \"Derived from andyruwruw/chess-image-generator bundled resources; upstream README cites Marcel van Kervinck as source\",\n pieces: Object.fromEntries(\n PIECE_KEYS.map((pieceKey) => [\n pieceKey,\n {\n kind: \"png\",\n source: assetPath(themeName, pieceKey),\n },\n ]),\n ) as ThemeDefinition[\"pieces\"],\n };\n}\n\nexport function initializeBuiltInThemes(): void {\n if (initialized) {\n return;\n }\n\n for (const themeName of builtInThemeNames) {\n registerTheme(createBuiltInTheme(themeName));\n }\n\n initialized = true;\n}\n\nexport function resetBuiltInThemesForTesting(): void {\n initialized = false;\n}\n","import { validateThemeName } from \"../core/validators\";\nimport { ThemeError, ValidationError } from \"../types/errors\";\nimport type { PieceKey, ThemeDefinition } from \"../types/types\";\n\nconst REQUIRED_PIECES: PieceKey[] = [\n \"wK\",\n \"wQ\",\n \"wR\",\n \"wB\",\n \"wN\",\n \"wP\",\n \"bK\",\n \"bQ\",\n \"bR\",\n \"bB\",\n \"bN\",\n \"bP\",\n];\n\nexport function validateThemeDefinition(theme: ThemeDefinition): ThemeDefinition {\n const normalizedName = validateThemeName(theme.name);\n\n if (!theme.displayName.trim()) {\n throw new ValidationError(\"Theme displayName is required\");\n }\n\n if (!theme.license.trim()) {\n throw new ValidationError(\"Theme license is required\");\n }\n\n if (!theme.attribution.trim()) {\n throw new ValidationError(\"Theme attribution is required\");\n }\n\n for (const pieceKey of REQUIRED_PIECES) {\n const asset = theme.pieces[pieceKey];\n\n if (!asset || (asset.kind !== \"svg\" && asset.kind !== \"png\") || !asset.source.trim()) {\n throw new ThemeError(`Theme \"${normalizedName}\" is missing asset ${pieceKey}`);\n }\n }\n\n return {\n ...theme,\n name: normalizedName,\n };\n}\n","import type { ThemeDefinition } from \"../types/types\";\nimport { ThemeError } from \"../types/errors\";\nimport { validateThemeDefinition } from \"./validation\";\n\nconst registry = new Map<string, ThemeDefinition>();\n\nexport function registerTheme(theme: ThemeDefinition): ThemeDefinition {\n const validatedTheme = validateThemeDefinition(theme);\n\n if (registry.has(validatedTheme.name)) {\n throw new ThemeError(`Theme \"${validatedTheme.name}\" is already registered`);\n }\n\n registry.set(validatedTheme.name, validatedTheme);\n return validatedTheme;\n}\n\nexport function getTheme(name: string): ThemeDefinition | undefined {\n return registry.get(name.trim().toLowerCase());\n}\n\nexport function clearThemeRegistryForTesting(): void {\n registry.clear();\n}\n","import type { PieceStyle, ThemeDefinition } from \"../types/types\";\nimport { ThemeError, ValidationError } from \"../types/errors\";\nimport { initializeBuiltInThemes } from \"./builtins\";\nimport { getTheme } from \"./registry\";\nimport { validateThemeDefinition } from \"./validation\";\n\ninterface ResolveThemeOptions {\n theme?: string | ThemeDefinition;\n style?: PieceStyle;\n}\n\nexport function resolveTheme({ theme, style }: ResolveThemeOptions): ThemeDefinition {\n initializeBuiltInThemes();\n\n if (typeof theme === \"object\" && theme !== null) {\n try {\n return validateThemeDefinition(theme);\n } catch (error) {\n if (error instanceof ThemeError) {\n throw error;\n }\n\n if (error instanceof ValidationError) {\n throw new ThemeError(error.message, { cause: error });\n }\n\n throw error;\n }\n }\n\n const requestedName = typeof theme === \"string\" ? theme : style ?? \"merida\";\n const resolvedTheme = getTheme(requestedName);\n\n if (!resolvedTheme) {\n throw new ThemeError(`Unknown theme: ${requestedName}`);\n }\n\n return resolvedTheme;\n}\n","import type {\n BoardColors,\n Padding,\n RenderOptions,\n ResolvedColors,\n Square,\n ThemeDefinition,\n} from \"../types/types\";\nimport { normalizeHighlights } from \"../core/highlights\";\nimport { normalizePadding, validateSize } from \"../core/validators\";\nimport { resolveTheme } from \"../themes/resolver\";\n\nexport const DEFAULT_SIZE = 480;\nexport const DEFAULT_PADDING: Padding = [0, 0, 0, 0];\nexport const DEFAULT_COLORS: ResolvedColors = {\n lightSquare: \"#f0d9b5\",\n darkSquare: \"#b58863\",\n highlight: \"rgba(255, 206, 0, 0.45)\",\n};\n\nexport function normalizeColors(colors?: BoardColors): ResolvedColors {\n return {\n lightSquare: colors?.lightSquare ?? DEFAULT_COLORS.lightSquare,\n darkSquare: colors?.darkSquare ?? DEFAULT_COLORS.darkSquare,\n highlight: colors?.highlight ?? DEFAULT_COLORS.highlight,\n };\n}\n\nexport function normalizeRenderInputs(options: RenderOptions & { highlightSquares?: Square[] }): {\n size: number;\n padding: Padding;\n flipped: boolean;\n theme: ThemeDefinition;\n highlightSquares: Square[];\n colors: ResolvedColors;\n} {\n return {\n size: validateSize(options.size ?? DEFAULT_SIZE),\n padding: normalizePadding(options.padding ?? DEFAULT_PADDING),\n flipped: options.flipped ?? false,\n theme: resolveTheme({\n theme: options.theme,\n style: options.style,\n }),\n highlightSquares: normalizeHighlights(options.highlightSquares ?? []),\n colors: normalizeColors(options.colors),\n };\n}\n","import { parseBoardArray, parseFEN, parsePGN } from \"../core/parsers\";\nimport { normalizeHighlights } from \"../core/highlights\";\nimport { ValidationError } from \"../types/errors\";\nimport type {\n BoardArray,\n ChessImageGeneratorOptions,\n RenderOptions,\n} from \"../types/types\";\nimport { CanvasPngRenderer } from \"../render/canvas-renderer\";\nimport { writeBufferToFile } from \"../utils/io\";\nimport { normalizeRenderInputs } from \"../utils/normalization\";\nimport type { BoardPosition } from \"../core/board\";\n\nexport class ChessImageGenerator {\n private position: BoardPosition | null = null;\n\n private readonly defaults: RenderOptions;\n\n private highlights: string[] = [];\n\n constructor(options: ChessImageGeneratorOptions = {}) {\n this.defaults = { ...options };\n normalizeRenderInputs({\n ...this.defaults,\n highlightSquares: [],\n });\n }\n\n async loadFEN(fen: string): Promise<void> {\n this.position = parseFEN(fen);\n this.clearHighlights();\n }\n\n async loadPGN(pgn: string): Promise<void> {\n this.position = parsePGN(pgn);\n this.clearHighlights();\n }\n\n async loadBoard(board: BoardArray): Promise<void> {\n this.position = parseBoardArray(board);\n this.clearHighlights();\n }\n\n setHighlights(squares: string[]): void {\n this.highlights = normalizeHighlights(squares);\n }\n\n clearHighlights(): void {\n this.highlights = [];\n }\n\n async toBuffer(): Promise<Buffer> {\n if (!this.position) {\n throw new ValidationError(\"No board position loaded\");\n }\n\n const renderer = new CanvasPngRenderer();\n const normalized = normalizeRenderInputs({\n ...this.defaults,\n highlightSquares: this.highlights,\n });\n\n return renderer.render({\n board: this.position,\n theme: normalized.theme,\n highlights: normalized.highlightSquares,\n size: normalized.size,\n padding: normalized.padding,\n flipped: normalized.flipped,\n colors: normalized.colors,\n });\n }\n\n async toFile(filePath: string): Promise<void> {\n const buffer = await this.toBuffer();\n await writeBufferToFile(filePath, buffer);\n }\n}\n","import { parseBoardArray, parseFEN, parsePGN } from \"../core/parsers\";\nimport { ValidationError } from \"../types/errors\";\nimport type { RenderChessOptions } from \"../types/types\";\nimport { CanvasPngRenderer } from \"../render/canvas-renderer\";\nimport { normalizeRenderInputs } from \"../utils/normalization\";\n\nfunction parseInputPosition(options: RenderChessOptions) {\n if (typeof options.fen === \"string\") {\n return parseFEN(options.fen);\n }\n\n if (typeof options.pgn === \"string\") {\n return parsePGN(options.pgn);\n }\n\n if (Array.isArray(options.board)) {\n return parseBoardArray(options.board);\n }\n\n throw new ValidationError(\"Exactly one of fen, pgn, or board must be provided\");\n}\n\nexport async function renderChess(options: RenderChessOptions): Promise<Buffer> {\n const provided = [\n typeof options.fen === \"string\" ? options.fen : undefined,\n typeof options.pgn === \"string\" ? options.pgn : undefined,\n Array.isArray(options.board) ? options.board : undefined,\n ].filter((value) => value !== undefined);\n\n if (provided.length !== 1) {\n throw new ValidationError(\"Exactly one of fen, pgn, or board must be provided\");\n }\n\n const position = parseInputPosition(options);\n const renderer = new CanvasPngRenderer();\n const normalized = normalizeRenderInputs(options);\n\n return renderer.render({\n board: position,\n theme: normalized.theme,\n highlights: normalized.highlightSquares,\n size: normalized.size,\n padding: normalized.padding,\n flipped: normalized.flipped,\n colors: normalized.colors,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,UAAN,cAAsB,MAAM;AAAA,EACjC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;;;ACjCA,mBAAsB;;;ACEf,IAAM,QAAQ,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AACrD,IAAM,QAAQ,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAErD,IAAM,UAAoB,MAAM;AAAA,EAAQ,CAAC,SAC9C,MAAM,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,EAAE;AACtC;AAMO,SAAS,2BAA0C;AACxD,SAAO;AAAA,IACL,SAAS,OAAO;A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,QAAQ;AAAA,EACjD,EAAE,OAAO,CAAC,UAAU,UAAU,MAAS;AAEvC,MAAI,SAAS,WAAW,GAAG;AACzB,UAAM,IAAI,gBAAgB,oDAAoD;AAAA,EAChF;AAEA,QAAM,WAAW,mBAAmB,OAAO;AAC3C,QAAM,WAAW,IAAI,kBAAkB;AACvC,QAAM,aAAa,sBAAsB,OAAO;AAEhD,SAAO,SAAS,OAAO;AAAA,IACrB,OAAO;AAAA,IACP,OAAO,WAAW;AAAA,IAClB,YAAY,WAAW;AAAA,IACvB,MAAM,WAAW;AAAA,IACjB,SAAS,WAAW;AAAA,IACpB,SAAS,WAAW;AAAA,IACpB,QAAQ,WAAW;AAAA,EACrB,CAAC;AACH;","names":["import_canvas","import_promises"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -34,12 +34,17 @@ interface SvgAssetSource {
|
|
|
34
34
|
kind: "svg";
|
|
35
35
|
source: string;
|
|
36
36
|
}
|
|
37
|
+
interface PngAssetSource {
|
|
38
|
+
kind: "png";
|
|
39
|
+
source: string;
|
|
40
|
+
}
|
|
41
|
+
type ThemeAssetSource = SvgAssetSource | PngAssetSource;
|
|
37
42
|
interface ThemeDefinition {
|
|
38
43
|
name: string;
|
|
39
44
|
displayName: string;
|
|
40
45
|
license: string;
|
|
41
46
|
attribution: string;
|
|
42
|
-
pieces: Record<PieceKey,
|
|
47
|
+
pieces: Record<PieceKey, ThemeAssetSource>;
|
|
43
48
|
}
|
|
44
49
|
interface BoardColors {
|
|
45
50
|
lightSquare?: string;
|
|
@@ -105,4 +110,4 @@ declare function renderChess(options: RenderChessOptions): Promise<Buffer>;
|
|
|
105
110
|
|
|
106
111
|
declare function registerTheme(theme: ThemeDefinition): ThemeDefinition;
|
|
107
112
|
|
|
108
|
-
export { type BoardArray, type BoardCell, type BoardColors, ChessImageGenerator, type ChessImageGeneratorOptions, IOError, type Padding, ParseError, type PieceKey, type PieceStyle, type RenderChessOptions, RenderError, type RenderOptions, type ResolvedColors, type ResolvedRenderOptions, type Square, type SvgAssetSource, type ThemeDefinition, ThemeError, ValidationError, registerTheme, renderChess };
|
|
113
|
+
export { type BoardArray, type BoardCell, type BoardColors, ChessImageGenerator, type ChessImageGeneratorOptions, IOError, type Padding, ParseError, type PieceKey, type PieceStyle, type PngAssetSource, type RenderChessOptions, RenderError, type RenderOptions, type ResolvedColors, type ResolvedRenderOptions, type Square, type SvgAssetSource, type ThemeAssetSource, type ThemeDefinition, ThemeError, ValidationError, registerTheme, renderChess };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,12 +34,17 @@ interface SvgAssetSource {
|
|
|
34
34
|
kind: "svg";
|
|
35
35
|
source: string;
|
|
36
36
|
}
|
|
37
|
+
interface PngAssetSource {
|
|
38
|
+
kind: "png";
|
|
39
|
+
source: string;
|
|
40
|
+
}
|
|
41
|
+
type ThemeAssetSource = SvgAssetSource | PngAssetSource;
|
|
37
42
|
interface ThemeDefinition {
|
|
38
43
|
name: string;
|
|
39
44
|
displayName: string;
|
|
40
45
|
license: string;
|
|
41
46
|
attribution: string;
|
|
42
|
-
pieces: Record<PieceKey,
|
|
47
|
+
pieces: Record<PieceKey, ThemeAssetSource>;
|
|
43
48
|
}
|
|
44
49
|
interface BoardColors {
|
|
45
50
|
lightSquare?: string;
|
|
@@ -105,4 +110,4 @@ declare function renderChess(options: RenderChessOptions): Promise<Buffer>;
|
|
|
105
110
|
|
|
106
111
|
declare function registerTheme(theme: ThemeDefinition): ThemeDefinition;
|
|
107
112
|
|
|
108
|
-
export { type BoardArray, type BoardCell, type BoardColors, ChessImageGenerator, type ChessImageGeneratorOptions, IOError, type Padding, ParseError, type PieceKey, type PieceStyle, type RenderChessOptions, RenderError, type RenderOptions, type ResolvedColors, type ResolvedRenderOptions, type Square, type SvgAssetSource, type ThemeDefinition, ThemeError, ValidationError, registerTheme, renderChess };
|
|
113
|
+
export { type BoardArray, type BoardCell, type BoardColors, ChessImageGenerator, type ChessImageGeneratorOptions, IOError, type Padding, ParseError, type PieceKey, type PieceStyle, type PngAssetSource, type RenderChessOptions, RenderError, type RenderOptions, type ResolvedColors, type ResolvedRenderOptions, type Square, type SvgAssetSource, type ThemeAssetSource, type ThemeDefinition, ThemeError, ValidationError, registerTheme, renderChess };
|