gigachess 0.4.2 → 0.5.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/dist/board.d.ts +38 -0
- package/dist/board.d.ts.map +1 -1
- package/dist/board.js +37 -1
- package/dist/chesstree.d.ts +9 -0
- package/dist/chesstree.d.ts.map +1 -1
- package/dist/chesstree.js +85 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/pgn.d.ts +4 -0
- package/dist/pgn.d.ts.map +1 -1
- package/dist/pgn.js +7 -2
- package/dist/san.d.ts +23 -0
- package/dist/san.d.ts.map +1 -1
- package/dist/san.js +70 -17
- package/package.json +2 -2
package/dist/board.d.ts
CHANGED
|
@@ -135,7 +135,45 @@ export declare class Board implements BoardLike {
|
|
|
135
135
|
toUci(moveWord: number): string;
|
|
136
136
|
toFen(): string;
|
|
137
137
|
parseSan(san: string): number | null;
|
|
138
|
+
/**
|
|
139
|
+
* `parseSan` with the failure reason kept.
|
|
140
|
+
*
|
|
141
|
+
* `parseSan` maps every error — `san/ambiguous`, `san/noLegalMove`,
|
|
142
|
+
* `san/invalidSan` — onto the same `null`, so a caller cannot tell "no such
|
|
143
|
+
* move" from "several moves answer to this and you must disambiguate". Those
|
|
144
|
+
* are different answers for a UI: one is an error, the other needs the
|
|
145
|
+
* candidates named (BlindBase ADR-042, field report #11).
|
|
146
|
+
*
|
|
147
|
+
* The error code is returned rather than a richer object because the codes
|
|
148
|
+
* are the library's own error vocabulary (`SanError["code"]`), already
|
|
149
|
+
* documented and already i18n-keyed upstream.
|
|
150
|
+
*/
|
|
151
|
+
parseSanResult(san: string): {
|
|
152
|
+
ok: true;
|
|
153
|
+
moveWord: number;
|
|
154
|
+
} | {
|
|
155
|
+
ok: false;
|
|
156
|
+
code: string;
|
|
157
|
+
};
|
|
138
158
|
parseUci(uci: string): number | null;
|
|
159
|
+
/**
|
|
160
|
+
* Every packed move word `san` could denote here, or the reason it names none.
|
|
161
|
+
*
|
|
162
|
+
* `parseSan` reports `san/ambiguous` and discards the matches, so a caller
|
|
163
|
+
* can tell the user the input was ambiguous but not which moves it meant.
|
|
164
|
+
* This returns them, letting a caller present the disambiguated spellings
|
|
165
|
+
* rather than making the user guess (BlindBase ADR-042, field report #11).
|
|
166
|
+
*
|
|
167
|
+
* A resolved move comes back as a one-element array, so this can replace
|
|
168
|
+
* `parseSan` wherever the caller only needs "one move, or a reason".
|
|
169
|
+
*/
|
|
170
|
+
parseSanCandidates(san: string): {
|
|
171
|
+
ok: true;
|
|
172
|
+
moveWords: number[];
|
|
173
|
+
} | {
|
|
174
|
+
ok: false;
|
|
175
|
+
code: string;
|
|
176
|
+
};
|
|
139
177
|
perft(depth: number): number;
|
|
140
178
|
}
|
|
141
179
|
export type WritableBoard = {
|
package/dist/board.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../src/board.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAS,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAkBxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAWlD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,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,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAO7E;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAElE;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAMrE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAa/D"}
|
package/dist/board.js
CHANGED
|
@@ -8,7 +8,7 @@ import { zobristTablesLoaded, calculateZobrist, zobristHex, pieceKeyIdx, castlin
|
|
|
8
8
|
import { CASTLE_CLEAR_STD, CASTLING_RIGHTS_TABLE, getCastlingMask, detectCastling, } from "./castling.js";
|
|
9
9
|
import { packOf, unpackToMove, promoCodeToRole, isNull, } from "./packedMove.js";
|
|
10
10
|
import { parseFen, makeFen } from "./fen.js";
|
|
11
|
-
import { parseSan, makeSan, parseUci, makeUci } from "./san.js";
|
|
11
|
+
import { parseSan, parseSanCandidates, makeSan, parseUci, makeUci } from "./san.js";
|
|
12
12
|
import { legalMovesInto, forEachLegalMove, countLegalMoves, isLegal, INITIAL_FEN } from "./chess.js";
|
|
13
13
|
export class Board {
|
|
14
14
|
constructor(input) {
|
|
@@ -785,10 +785,46 @@ export class Board {
|
|
|
785
785
|
const res = parseSan(san, this);
|
|
786
786
|
return res.ok ? packOf(res.value) : null;
|
|
787
787
|
}
|
|
788
|
+
/**
|
|
789
|
+
* `parseSan` with the failure reason kept.
|
|
790
|
+
*
|
|
791
|
+
* `parseSan` maps every error — `san/ambiguous`, `san/noLegalMove`,
|
|
792
|
+
* `san/invalidSan` — onto the same `null`, so a caller cannot tell "no such
|
|
793
|
+
* move" from "several moves answer to this and you must disambiguate". Those
|
|
794
|
+
* are different answers for a UI: one is an error, the other needs the
|
|
795
|
+
* candidates named (BlindBase ADR-042, field report #11).
|
|
796
|
+
*
|
|
797
|
+
* The error code is returned rather than a richer object because the codes
|
|
798
|
+
* are the library's own error vocabulary (`SanError["code"]`), already
|
|
799
|
+
* documented and already i18n-keyed upstream.
|
|
800
|
+
*/
|
|
801
|
+
parseSanResult(san) {
|
|
802
|
+
const res = parseSan(san, this);
|
|
803
|
+
return res.ok
|
|
804
|
+
? { ok: true, moveWord: packOf(res.value) }
|
|
805
|
+
: { ok: false, code: res.error.code };
|
|
806
|
+
}
|
|
788
807
|
parseUci(uci) {
|
|
789
808
|
const res = parseUci(uci);
|
|
790
809
|
return res.ok && isLegal(this, res.value) ? packOf(res.value) : null;
|
|
791
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Every packed move word `san` could denote here, or the reason it names none.
|
|
813
|
+
*
|
|
814
|
+
* `parseSan` reports `san/ambiguous` and discards the matches, so a caller
|
|
815
|
+
* can tell the user the input was ambiguous but not which moves it meant.
|
|
816
|
+
* This returns them, letting a caller present the disambiguated spellings
|
|
817
|
+
* rather than making the user guess (BlindBase ADR-042, field report #11).
|
|
818
|
+
*
|
|
819
|
+
* A resolved move comes back as a one-element array, so this can replace
|
|
820
|
+
* `parseSan` wherever the caller only needs "one move, or a reason".
|
|
821
|
+
*/
|
|
822
|
+
parseSanCandidates(san) {
|
|
823
|
+
const res = parseSanCandidates(san, this);
|
|
824
|
+
return res.ok
|
|
825
|
+
? { ok: true, moveWords: res.value.map(packOf) }
|
|
826
|
+
: { ok: false, code: res.error.code };
|
|
827
|
+
}
|
|
792
828
|
perft(depth) {
|
|
793
829
|
if (depth <= 0)
|
|
794
830
|
return 1;
|
package/dist/chesstree.d.ts
CHANGED
|
@@ -6,7 +6,16 @@ export interface Comment {
|
|
|
6
6
|
export interface Glyph {
|
|
7
7
|
symbol: string;
|
|
8
8
|
name: string;
|
|
9
|
+
/** The PGN NAG number (`$14`), when the glyph has one. */
|
|
10
|
+
id?: number;
|
|
9
11
|
}
|
|
12
|
+
/** The standard annotation glyphs, by NAG: move assessments (1–7) and
|
|
13
|
+
* position assessments (10–19 and the rest). Symbols and names follow the
|
|
14
|
+
* lichess tree, so a glyph reads the same in either tree. */
|
|
15
|
+
export declare const NAG_GLYPHS: Readonly<Record<number, Readonly<Glyph>>>;
|
|
16
|
+
/** The glyph for a NAG. A NAG without a standard glyph keeps its number as
|
|
17
|
+
* `$n`, so it survives import and export unchanged. */
|
|
18
|
+
export declare function glyphForNag(nag: number): Glyph;
|
|
10
19
|
export interface Clock {
|
|
11
20
|
white: number;
|
|
12
21
|
black: number;
|
package/dist/chesstree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chesstree.d.ts","sourceRoot":"","sources":["../src/chesstree.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"chesstree.d.ts","sourceRoot":"","sources":["../src/chesstree.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;6DAE6D;AAC7D,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAwB/D,CAAC;AAEH;uDACuD;AACvD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAG9C;AAED,MAAM,WAAW,KAAK;IACpB,KAAK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|
|
|
12
12
|
import { Color } from "./types.js";
|
|
13
13
|
const START_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
|
14
14
|
const ID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
15
|
+
/** The standard annotation glyphs, by NAG: move assessments (1–7) and
|
|
16
|
+
* position assessments (10–19 and the rest). Symbols and names follow the
|
|
17
|
+
* lichess tree, so a glyph reads the same in either tree. */
|
|
18
|
+
export const NAG_GLYPHS = Object.freeze({
|
|
19
|
+
1: { id: 1, symbol: "!", name: "Good move" },
|
|
20
|
+
2: { id: 2, symbol: "?", name: "Mistake" },
|
|
21
|
+
3: { id: 3, symbol: "!!", name: "Brilliant move" },
|
|
22
|
+
4: { id: 4, symbol: "??", name: "Blunder" },
|
|
23
|
+
5: { id: 5, symbol: "!?", name: "Interesting move" },
|
|
24
|
+
6: { id: 6, symbol: "?!", name: "Dubious move" },
|
|
25
|
+
7: { id: 7, symbol: "□", name: "Only move" },
|
|
26
|
+
10: { id: 10, symbol: "=", name: "Equal position" },
|
|
27
|
+
13: { id: 13, symbol: "∞", name: "Unclear position" },
|
|
28
|
+
14: { id: 14, symbol: "⩲", name: "White is slightly better" },
|
|
29
|
+
15: { id: 15, symbol: "⩱", name: "Black is slightly better" },
|
|
30
|
+
16: { id: 16, symbol: "±", name: "White is better" },
|
|
31
|
+
17: { id: 17, symbol: "∓", name: "Black is better" },
|
|
32
|
+
18: { id: 18, symbol: "+−", name: "White is winning" },
|
|
33
|
+
19: { id: 19, symbol: "−+", name: "Black is winning" },
|
|
34
|
+
22: { id: 22, symbol: "⨀", name: "Zugzwang" },
|
|
35
|
+
32: { id: 32, symbol: "↑↑", name: "Development" },
|
|
36
|
+
36: { id: 36, symbol: "↑", name: "Initiative" },
|
|
37
|
+
40: { id: 40, symbol: "→", name: "Attack" },
|
|
38
|
+
132: { id: 132, symbol: "⇆", name: "Counterplay" },
|
|
39
|
+
138: { id: 138, symbol: "⊕", name: "Time trouble" },
|
|
40
|
+
140: { id: 140, symbol: "∆", name: "With the idea" },
|
|
41
|
+
146: { id: 146, symbol: "N", name: "Novelty" },
|
|
42
|
+
});
|
|
43
|
+
/** The glyph for a NAG. A NAG without a standard glyph keeps its number as
|
|
44
|
+
* `$n`, so it survives import and export unchanged. */
|
|
45
|
+
export function glyphForNag(nag) {
|
|
46
|
+
const known = NAG_GLYPHS[nag];
|
|
47
|
+
return known ? { ...known } : { id: nag, symbol: `$${nag}`, name: `NAG ${nag}` };
|
|
48
|
+
}
|
|
15
49
|
/** Deterministic unique 2-char node id (same alphabet/contract the
|
|
16
50
|
* workstation's `createUniqueMoveNodeId` relies on). */
|
|
17
51
|
function nextNodeId(siblings) {
|
|
@@ -48,15 +82,26 @@ function mergeTree(existing, incoming) {
|
|
|
48
82
|
ex.push(c);
|
|
49
83
|
}
|
|
50
84
|
}
|
|
85
|
+
if (incoming.startingComments !== undefined && incoming.startingComments.length > 0) {
|
|
86
|
+
const ex = existing.startingComments ?? (existing.startingComments = []);
|
|
87
|
+
for (const c of incoming.startingComments) {
|
|
88
|
+
if (!ex.some((e) => e.text === c.text))
|
|
89
|
+
ex.push(c);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
51
92
|
if (existing.glyphs === undefined && incoming.glyphs !== undefined)
|
|
52
93
|
existing.glyphs = incoming.glyphs;
|
|
53
94
|
}
|
|
54
|
-
|
|
95
|
+
/** `root` is set for the game's own section: comments before its first move
|
|
96
|
+
* belong to the root node (`{intro} 1. e4`), as in the baseline. In a
|
|
97
|
+
* variation they are the first move's `startingComments`. */
|
|
98
|
+
function replaySection(moves, ctx, out, root) {
|
|
55
99
|
// Mainline nesting: the parser emits a flat mainline list, so each
|
|
56
100
|
// successive move nests under the previous node's children. A PGN variation
|
|
57
101
|
// replaces the move it follows — it starts from the position BEFORE that
|
|
58
102
|
// move and its nodes are siblings of it (children[0] = mainline).
|
|
59
103
|
let target = out;
|
|
104
|
+
let first = true;
|
|
60
105
|
for (const m of moves) {
|
|
61
106
|
const snapshot = { ...ctx };
|
|
62
107
|
const id = nextNodeId(target);
|
|
@@ -93,12 +138,28 @@ function replaySection(moves, ctx, out) {
|
|
|
93
138
|
advance = { pos: makeMove(ctx.pos, move) };
|
|
94
139
|
node.fen = fenWithEpPolicy(advance.pos);
|
|
95
140
|
}
|
|
96
|
-
|
|
97
|
-
|
|
141
|
+
const lead = m.startingComments ?? [];
|
|
142
|
+
const after = first ? m.comments : [...lead, ...m.comments];
|
|
143
|
+
if (first && lead.length > 0) {
|
|
144
|
+
if (root) {
|
|
145
|
+
root.comments = lead.map((text, i) => ({ id: `pgn-comment-comment-root-${i}`, text }));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
node.startingComments = lead.map((text, i) => ({
|
|
149
|
+
id: `pgn-starting-comment-${ctx.path}${id}-${i}`,
|
|
150
|
+
text,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
first = false;
|
|
155
|
+
if (after.length > 0) {
|
|
156
|
+
node.comments = after.map((text, i) => ({
|
|
98
157
|
id: commentId(`${ctx.path}${id}`, i),
|
|
99
158
|
text,
|
|
100
159
|
}));
|
|
101
160
|
}
|
|
161
|
+
if (m.nags.length > 0)
|
|
162
|
+
node.glyphs = m.nags.map(glyphForNag);
|
|
102
163
|
// baseline pgnImport merges duplicate sibling moves (same SAN) into one
|
|
103
164
|
// node, recursively merging their subtrees
|
|
104
165
|
const existing = target.find((c) => c.san !== undefined && c.san === node.san);
|
|
@@ -234,7 +295,7 @@ export function pgnImport(pgn) {
|
|
|
234
295
|
const start = startRes.ok ? startRes.value : parseFen(START_FEN).value;
|
|
235
296
|
const root = { id: "", ply: 0, fen: rootFen, uci: "", children: [] };
|
|
236
297
|
const ctx = { pos: start, ply: 0, path: "", moveNo: 1 };
|
|
237
|
-
replaySection(parsed.value.moves, ctx, root.children);
|
|
298
|
+
replaySection(parsed.value.moves, ctx, root.children, root);
|
|
238
299
|
const game = defaultGame(rootFen, headers);
|
|
239
300
|
const white = headers.get("White");
|
|
240
301
|
const black = headers.get("Black");
|
|
@@ -395,7 +456,20 @@ export function build(root) {
|
|
|
395
456
|
}
|
|
396
457
|
// ---------- PGN export ----------
|
|
397
458
|
const STRO_KEYS = new Set(["Event", "Site", "Date", "Round", "White", "Black", "Result"]);
|
|
398
|
-
const GLYPH_TO_NAG =
|
|
459
|
+
const GLYPH_TO_NAG = Object.fromEntries(Object.values(NAG_GLYPHS).map((g) => [g.symbol, g.id]));
|
|
460
|
+
// ASCII spellings of the winning glyphs
|
|
461
|
+
GLYPH_TO_NAG["+-"] = 18;
|
|
462
|
+
GLYPH_TO_NAG["-+"] = 19;
|
|
463
|
+
/** The NAG for a glyph: its `id`, its standard symbol, or a `$n` symbol. */
|
|
464
|
+
function nagOfGlyph(g) {
|
|
465
|
+
if (typeof g.id === "number" && Number.isInteger(g.id) && g.id > 0)
|
|
466
|
+
return g.id;
|
|
467
|
+
const known = GLYPH_TO_NAG[g.symbol];
|
|
468
|
+
if (known !== undefined)
|
|
469
|
+
return known;
|
|
470
|
+
const m = /^\$(\d+)$/.exec(g.symbol);
|
|
471
|
+
return m ? parseInt(m[1], 10) : undefined;
|
|
472
|
+
}
|
|
399
473
|
const Q = '"';
|
|
400
474
|
const headerLine = (k, v) => "[" + k + " " + Q + (v ?? "?") + Q + "]";
|
|
401
475
|
function renderHeaders(game, rootFen) {
|
|
@@ -445,6 +519,8 @@ function emitFrom(list, idx, state, tokens) {
|
|
|
445
519
|
const isNull = san !== undefined && isNullMoveSan(san);
|
|
446
520
|
// A pass is emitted as `--` — it is a real ply, so dropping it (the old
|
|
447
521
|
// behavior) desynchronized the numbering of every following token.
|
|
522
|
+
for (const c of node.startingComments ?? [])
|
|
523
|
+
tokens.push("{" + c.text + "}");
|
|
448
524
|
if (san !== undefined) {
|
|
449
525
|
if (state.turn === "w")
|
|
450
526
|
tokens.push(state.moveNo + ".");
|
|
@@ -453,7 +529,7 @@ function emitFrom(list, idx, state, tokens) {
|
|
|
453
529
|
tokens.push(san);
|
|
454
530
|
state.needNumber = false;
|
|
455
531
|
for (const g of node.glyphs ?? []) {
|
|
456
|
-
const nag =
|
|
532
|
+
const nag = nagOfGlyph(g);
|
|
457
533
|
if (nag !== undefined)
|
|
458
534
|
tokens.push("$" + nag);
|
|
459
535
|
}
|
|
@@ -485,7 +561,9 @@ function numberingFromFen(fen) {
|
|
|
485
561
|
}
|
|
486
562
|
function renderMovetext(root, game) {
|
|
487
563
|
const state = numberingFromFen(root.fen);
|
|
488
|
-
const
|
|
564
|
+
const intro = (root.comments ?? []).map((c) => "{" + c.text + "}");
|
|
565
|
+
const body = renderSection(root.children, state);
|
|
566
|
+
const moves = [...intro, body].filter(Boolean).join(" ");
|
|
489
567
|
const result = game.result ?? "*";
|
|
490
568
|
return moves.length > 0 ? moves + " " + result : result;
|
|
491
569
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export { kingAttackers } from "./attacks.js";
|
|
|
13
13
|
export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js";
|
|
14
14
|
export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, makeNullMove, play, INITIAL_FEN, } from "./chess.js";
|
|
15
15
|
export type { CastlingPlan, NullUndo } from "./chess.js";
|
|
16
|
-
export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
|
|
16
|
+
export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, NAG_GLYPHS, glyphForNag, } from "./chesstree.js";
|
|
17
17
|
export type { TreeWrapper, TreeNode, Path, Comment, Glyph, Clock, Shape, Eval as TreeEval, Game, Player, AnalyseData, } from "./chesstree.js";
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,OAAO,EACP,eAAe,EACf,KAAK,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzD,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,EACL,SAAS,EACT,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,OAAO,EACP,eAAe,EACf,KAAK,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzD,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,EACL,SAAS,EACT,eAAe,EACf,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,IAAI,QAAQ,EAChB,IAAI,EACJ,MAAM,EACN,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,4 +18,4 @@ export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js
|
|
|
18
18
|
// chess core (avoid duplicate Position and kingAttackers)
|
|
19
19
|
export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, makeNullMove, play, INITIAL_FEN, } from "./chess.js";
|
|
20
20
|
// chesstree integration (tree shapes + analysis API, folded into the root)
|
|
21
|
-
export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
|
|
21
|
+
export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, NAG_GLYPHS, glyphForNag, } from "./chesstree.js";
|
package/dist/pgn.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export type PgnMove = {
|
|
|
3
3
|
san: string;
|
|
4
4
|
nags: number[];
|
|
5
5
|
comments: string[];
|
|
6
|
+
/** Comments written before this move — only the first move of a section
|
|
7
|
+
* (the game or a variation) has them: `{intro} 1. e4`, `({lead} 2. f4)`.
|
|
8
|
+
* Absent when there are none. */
|
|
9
|
+
startingComments?: string[];
|
|
6
10
|
variations: GameTree[];
|
|
7
11
|
};
|
|
8
12
|
export type GameTree = {
|
package/dist/pgn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgn.d.ts","sourceRoot":"","sources":["../src/pgn.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,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AK,EAAE,MAAM,GAAG,IAAI;IAMzB,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAOpC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAGtD;AAGD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,+BAAkB,CAAC"}
|
package/dist/pgn.js
CHANGED
|
@@ -269,8 +269,9 @@ function parseMovetext(text) {
|
|
|
269
269
|
// Create move node
|
|
270
270
|
const moveNode = { san: token, nags: [], comments: [], variations: [] };
|
|
271
271
|
if (pending.length > 0) {
|
|
272
|
-
// comments that appeared before this move
|
|
273
|
-
|
|
272
|
+
// comments that appeared before this move stay before it, so
|
|
273
|
+
// makePgn(parsePgn(pgn)) keeps their place
|
|
274
|
+
moveNode.startingComments = pending.slice();
|
|
274
275
|
pending = [];
|
|
275
276
|
}
|
|
276
277
|
currentMoves.push(moveNode);
|
|
@@ -306,6 +307,10 @@ function makeMovetext(moves, result) {
|
|
|
306
307
|
// For mainline, white moves are even idx (0,2,4...), black odd
|
|
307
308
|
// We'll emit numbers for white only, as "1. e4 e5 2. Nf3"
|
|
308
309
|
// This is more standard and still tolerant when re-parsed
|
|
310
|
+
if (mv.startingComments && mv.startingComments.length > 0) {
|
|
311
|
+
for (const c of mv.startingComments)
|
|
312
|
+
s += `{${c}} `;
|
|
313
|
+
}
|
|
309
314
|
if (idx % 2 === 0) {
|
|
310
315
|
const num = Math.floor(idx / 2) + 1;
|
|
311
316
|
s += `${num}. `;
|
package/dist/san.d.ts
CHANGED
|
@@ -10,6 +10,29 @@ export declare const NULL_MOVE_SANS: readonly string[];
|
|
|
10
10
|
export declare function isNullMoveSan(san: string): boolean;
|
|
11
11
|
export declare function makeSan(move: Move, pos: Position): string;
|
|
12
12
|
export declare function parseSan(san: string, pos: Position): Result<Move, SanError>;
|
|
13
|
+
/**
|
|
14
|
+
* `parseSan` with the matching moves retained.
|
|
15
|
+
*
|
|
16
|
+
* A multi-match parse ends in `san/ambiguous` and `parseSan` throws the matches
|
|
17
|
+
* away, so a caller can report *that* the input was ambiguous but never *what*
|
|
18
|
+
* it could have meant. `candidates` carries that list so a UI can name the
|
|
19
|
+
* disambiguated spellings instead of guessing (BlindBase ADR-042, report #11).
|
|
20
|
+
*
|
|
21
|
+
* `result` is exactly what `parseSan` returns for the same input; this exists so
|
|
22
|
+
* the two cannot drift, not as a second parse path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseSanDetailed(san: string, pos: Position): {
|
|
25
|
+
result: Result<Move, SanError>;
|
|
26
|
+
candidates: Move[] | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Every legal move `san` could denote, or the error when it names none.
|
|
30
|
+
*
|
|
31
|
+
* The counterpart to `parseSan` for callers that must react to ambiguity rather
|
|
32
|
+
* than accept it: `length === 1` means resolved, `length > 1` means the caller
|
|
33
|
+
* should ask which of these it meant.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseSanCandidates(san: string, pos: Position): Result<Move[], SanError>;
|
|
13
36
|
export declare function parseUci(uci: string): Result<Move, UciError>;
|
|
14
37
|
export declare function makeUci(move: Move): string;
|
|
15
38
|
//# sourceMappingURL=san.d.ts.map
|
package/dist/san.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"san.d.ts","sourceRoot":"","sources":["../src/san.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQ7E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAA0B,CAAC;AAGvE,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAYD,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,G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206,6 +206,60 @@ export function makeSan(move, pos) {
|
|
|
206
206
|
}
|
|
207
207
|
// ---------- parseSan ----------
|
|
208
208
|
export function parseSan(san, pos) {
|
|
209
|
+
return parseSanDetailed(san, pos).result;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* `parseSan` with the matching moves retained.
|
|
213
|
+
*
|
|
214
|
+
* A multi-match parse ends in `san/ambiguous` and `parseSan` throws the matches
|
|
215
|
+
* away, so a caller can report *that* the input was ambiguous but never *what*
|
|
216
|
+
* it could have meant. `candidates` carries that list so a UI can name the
|
|
217
|
+
* disambiguated spellings instead of guessing (BlindBase ADR-042, report #11).
|
|
218
|
+
*
|
|
219
|
+
* `result` is exactly what `parseSan` returns for the same input; this exists so
|
|
220
|
+
* the two cannot drift, not as a second parse path.
|
|
221
|
+
*/
|
|
222
|
+
export function parseSanDetailed(san, pos) {
|
|
223
|
+
const traced = parseSanTraced(san, pos);
|
|
224
|
+
const candidates = traced.candidates;
|
|
225
|
+
if (candidates === null) {
|
|
226
|
+
// Rejected before any move could match — nothing to disambiguate.
|
|
227
|
+
return { result: traced.result, candidates: null };
|
|
228
|
+
}
|
|
229
|
+
if (candidates.length === 0) {
|
|
230
|
+
return { result: Err({ code: "san/noLegalMove" }), candidates };
|
|
231
|
+
}
|
|
232
|
+
if (candidates.length > 1) {
|
|
233
|
+
return { result: Err({ code: "san/ambiguous" }), candidates };
|
|
234
|
+
}
|
|
235
|
+
return { result: Ok(candidates[0]), candidates };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Every legal move `san` could denote, or the error when it names none.
|
|
239
|
+
*
|
|
240
|
+
* The counterpart to `parseSan` for callers that must react to ambiguity rather
|
|
241
|
+
* than accept it: `length === 1` means resolved, `length > 1` means the caller
|
|
242
|
+
* should ask which of these it meant.
|
|
243
|
+
*/
|
|
244
|
+
export function parseSanCandidates(san, pos) {
|
|
245
|
+
const { result, candidates } = parseSanDetailed(san, pos);
|
|
246
|
+
if (candidates === null || candidates.length === 0) {
|
|
247
|
+
return result.ok ? Ok([result.value]) : Err(result.error);
|
|
248
|
+
}
|
|
249
|
+
return Ok(candidates);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The parse body, keeping the collected candidates.
|
|
253
|
+
*
|
|
254
|
+
* Every early refusal before candidate collection returns `candidates: null`,
|
|
255
|
+
* which is what distinguishes "this string is not a SAN at all" from "this SAN
|
|
256
|
+
* is ambiguous" — a distinction `parseSan`'s single error channel previously
|
|
257
|
+
* lost.
|
|
258
|
+
*/
|
|
259
|
+
function parseSanTraced(san, pos) {
|
|
260
|
+
// A refusal raised before any move could match: nothing to disambiguate, which
|
|
261
|
+
// is what separates "not a SAN at all" from "an ambiguous SAN".
|
|
262
|
+
const fail = (code) => ({ result: Err({ code }), candidates: null });
|
|
209
263
|
const orig = san;
|
|
210
264
|
let s = normalizeCastlingSan(san.trim());
|
|
211
265
|
// Null move (pass) — exactly `--` or `Z0`, matched BEFORE any check-suffix
|
|
@@ -214,8 +268,8 @@ export function parseSan(san, pos) {
|
|
|
214
268
|
// the attack tables, never from the cached `checkers` bitboard.
|
|
215
269
|
if (isNullMoveSan(s)) {
|
|
216
270
|
if (!chess.isNullMoveLegal(pos))
|
|
217
|
-
return
|
|
218
|
-
return Ok(nullMove());
|
|
271
|
+
return fail("san/illegal");
|
|
272
|
+
return { result: Ok(nullMove()), candidates: [nullMove()] };
|
|
219
273
|
}
|
|
220
274
|
// Handle check suffix for later, but keep for validation
|
|
221
275
|
let checkSuffix = "";
|
|
@@ -228,7 +282,7 @@ export function parseSan(san, pos) {
|
|
|
228
282
|
const isKingSide = s === "O-O";
|
|
229
283
|
const kingSq = board.kingSquare(pos.board, pos.turn);
|
|
230
284
|
if (kingSq === undefined)
|
|
231
|
-
return
|
|
285
|
+
return fail("san/noKing");
|
|
232
286
|
// Find if castling is legal via dests. The generated dest is the
|
|
233
287
|
// representation's castling square: normalized landing (6/2/62/58) or the
|
|
234
288
|
// right's rook square (baseline/960 form). Both are accepted.
|
|
@@ -249,12 +303,12 @@ export function parseSan(san, pos) {
|
|
|
249
303
|
}
|
|
250
304
|
}
|
|
251
305
|
if (dest === undefined)
|
|
252
|
-
return
|
|
306
|
+
return fail("san/illegal");
|
|
253
307
|
const move = { from: kingSq, to: dest, isCastling: true, isEnPassant: false, isPromotion: false, promotion: null };
|
|
254
308
|
// Optionally validate check suffix matches actual
|
|
255
309
|
// We ignore mismatch for parsing tolerance, but we could validate
|
|
256
310
|
// If checkSuffix present, we could verify after play, but not required to error
|
|
257
|
-
return Ok(move);
|
|
311
|
+
return { result: Ok(move), candidates: [move] };
|
|
258
312
|
}
|
|
259
313
|
// Promotion handling
|
|
260
314
|
let promotion = undefined;
|
|
@@ -262,20 +316,20 @@ export function parseSan(san, pos) {
|
|
|
262
316
|
if (eqIdx !== -1) {
|
|
263
317
|
const promoChar = s[eqIdx + 1];
|
|
264
318
|
if (!promoChar)
|
|
265
|
-
return
|
|
319
|
+
return fail("san/invalidPromotion");
|
|
266
320
|
const role = promoCharToRole(promoChar);
|
|
267
321
|
if (role === undefined)
|
|
268
|
-
return
|
|
322
|
+
return fail("san/invalidPromotion");
|
|
269
323
|
promotion = role;
|
|
270
324
|
s = s.slice(0, eqIdx);
|
|
271
325
|
}
|
|
272
326
|
// Destination
|
|
273
327
|
if (s.length < 2)
|
|
274
|
-
return
|
|
328
|
+
return fail("san/invalidSan");
|
|
275
329
|
const toStr = s.slice(-2);
|
|
276
330
|
const to = parseSquare(toStr);
|
|
277
331
|
if (to === undefined)
|
|
278
|
-
return
|
|
332
|
+
return fail("san/invalidSquare");
|
|
279
333
|
let rest = s.slice(0, -2);
|
|
280
334
|
// Capture
|
|
281
335
|
let isCapture = false;
|
|
@@ -303,7 +357,7 @@ export function parseSan(san, pos) {
|
|
|
303
357
|
else if (ch >= "1" && ch <= "8")
|
|
304
358
|
disambRank = ch;
|
|
305
359
|
else
|
|
306
|
-
return
|
|
360
|
+
return fail("san/invalidSan");
|
|
307
361
|
}
|
|
308
362
|
else if (rest.length === 2) {
|
|
309
363
|
if (rest[0] >= "a" && rest[0] <= "h" && rest[1] >= "1" && rest[1] <= "8") {
|
|
@@ -311,10 +365,10 @@ export function parseSan(san, pos) {
|
|
|
311
365
|
disambRank = rest[1];
|
|
312
366
|
}
|
|
313
367
|
else
|
|
314
|
-
return
|
|
368
|
+
return fail("san/invalidSan");
|
|
315
369
|
}
|
|
316
370
|
else if (rest.length > 2) {
|
|
317
|
-
return
|
|
371
|
+
return fail("san/invalidSan");
|
|
318
372
|
}
|
|
319
373
|
// For pawn, pieceRole is pawn, but rest may be file for capture (like "e" in exd5)
|
|
320
374
|
// Our disamb handling already captured that: for "exd5", rest after removing piece (none) and capture, rest = "e" => disambFile = 'e' . Good.
|
|
@@ -391,7 +445,7 @@ export function parseSan(san, pos) {
|
|
|
391
445
|
filteredFroms = filteredFroms.filter(f => squareRank(f) === reqRank);
|
|
392
446
|
}
|
|
393
447
|
if (filteredFroms.length === 0)
|
|
394
|
-
return
|
|
448
|
+
return fail("san/noLegalMove");
|
|
395
449
|
// Legality filtering with single shared check context
|
|
396
450
|
const ctx = chess.analyzeCheckContext(pos);
|
|
397
451
|
const candidates = [];
|
|
@@ -425,11 +479,10 @@ export function parseSan(san, pos) {
|
|
|
425
479
|
});
|
|
426
480
|
}
|
|
427
481
|
if (candidates.length === 0)
|
|
428
|
-
return Err({ code: "san/noLegalMove" });
|
|
482
|
+
return { result: Err({ code: "san/noLegalMove" }), candidates };
|
|
429
483
|
if (candidates.length > 1)
|
|
430
|
-
return Err({ code: "san/ambiguous" });
|
|
431
|
-
|
|
432
|
-
return Ok(chosen);
|
|
484
|
+
return { result: Err({ code: "san/ambiguous" }), candidates };
|
|
485
|
+
return { result: Ok(candidates[0]), candidates };
|
|
433
486
|
}
|
|
434
487
|
// ---------- UCI ----------
|
|
435
488
|
export function parseUci(uci) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gigachess",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "The fastest chess library and engine in TypeScript. 45x faster than chess.js, 18.7M nodes/s perft, zero dependencies, 100% MIT.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"typecheck": "tsc --noEmit",
|
|
109
|
-
"test": "npm run typecheck && node tests/native-board.mjs && node tests/perft.mjs && node tests/castling.mjs && node tests/parity.mjs && node tests/purity.mjs && node tests/compat-chessops.mjs && node tests/chessjs-parity.mjs && node tests/chesstree-parity.mjs && node tests/zobrist-parity.mjs && node tests/packed-moves.mjs && node tests/zero-copy-moves.mjs && node tests/null-move.mjs && node tests/fuzz-differential.mjs",
|
|
109
|
+
"test": "npm run typecheck && npm run build && node tests/native-board.mjs && node tests/perft.mjs && node tests/castling.mjs && node tests/parity.mjs && node tests/purity.mjs && node tests/compat-chessops.mjs && node tests/chessjs-parity.mjs && node tests/chesstree-parity.mjs && node tests/chesstree-glyphs.mjs && node tests/zobrist-parity.mjs && node tests/packed-moves.mjs && node tests/zero-copy-moves.mjs && node tests/null-move.mjs && node tests/san-ambiguity.mjs && node tests/fuzz-differential.mjs",
|
|
110
110
|
"test:fuzz": "node tests/fuzz-differential.mjs",
|
|
111
111
|
"bench": "node bench/bench-sliding.mjs --iters 1000000 && node bench/bench-perft.mjs --depth 5 && node bench/bench-pgn.mjs --games 1000 && node bench/bench-fen-san.mjs --iters 1000 && node bench/bench-bundle.mjs --entry core",
|
|
112
112
|
"bench:sliding": "node bench/bench-sliding.mjs",
|