@ankhorage/zora 25.11.1 → 26.0.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -4
  3. package/dist/capabilities/index.js +65 -41
  4. package/dist/capabilities/index.js.map +3 -3
  5. package/dist/features/chess/adapters/inbound/ChessBoard.d.ts +1 -1
  6. package/dist/features/chess/adapters/inbound/ChessBoard.d.ts.map +1 -1
  7. package/dist/features/chess/adapters/inbound/ChessBoard.js +130 -83
  8. package/dist/features/chess/adapters/inbound/ChessBoard.js.map +1 -1
  9. package/dist/features/chess/meta.d.ts +97 -72
  10. package/dist/features/chess/meta.d.ts.map +1 -1
  11. package/dist/features/chess/meta.js +64 -40
  12. package/dist/features/chess/meta.js.map +1 -1
  13. package/dist/features/chess/public.d.ts +1 -7
  14. package/dist/features/chess/public.d.ts.map +1 -1
  15. package/dist/features/chess/public.js +0 -6
  16. package/dist/features/chess/public.js.map +1 -1
  17. package/dist/features/chess/utils/createChessBoardCellPressHandler.d.ts +6 -0
  18. package/dist/features/chess/utils/createChessBoardCellPressHandler.d.ts.map +1 -0
  19. package/dist/features/chess/utils/createChessBoardCellPressHandler.js +17 -0
  20. package/dist/features/chess/utils/createChessBoardCellPressHandler.js.map +1 -0
  21. package/dist/features/chess/utils/createChessBoardCells.d.ts +12 -0
  22. package/dist/features/chess/utils/createChessBoardCells.d.ts.map +1 -0
  23. package/dist/features/chess/utils/createChessBoardCells.js +28 -0
  24. package/dist/features/chess/utils/createChessBoardCells.js.map +1 -0
  25. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphController.js +2 -3
  26. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphController.js.map +1 -1
  27. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js +3 -1
  28. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js.map +1 -1
  29. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.d.ts +5 -5
  30. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.d.ts.map +1 -1
  31. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.js +13 -7
  32. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.js.map +1 -1
  33. package/dist/readerFree.d.ts +2 -2
  34. package/dist/readerFree.d.ts.map +1 -1
  35. package/dist/readerFree.js +1 -1
  36. package/dist/readerFree.js.map +1 -1
  37. package/dist/types/authoring.d.ts +2 -1
  38. package/dist/types/authoring.d.ts.map +1 -1
  39. package/dist/types/authoring.js.map +1 -1
  40. package/dist/types/chess.d.ts +27 -20
  41. package/dist/types/chess.d.ts.map +1 -1
  42. package/dist/types/chess.js.map +1 -1
  43. package/package.json +34 -94
  44. package/src/features/chess/adapters/inbound/ChessBoard.tsx +263 -112
  45. package/src/features/chess/meta.ts +64 -40
  46. package/src/features/chess/public.test.tsx +77 -228
  47. package/src/features/chess/public.ts +2 -9
  48. package/src/features/chess/utils/createChessBoardCellPressHandler.ts +30 -0
  49. package/src/features/chess/utils/createChessBoardCells.ts +54 -0
  50. package/src/features/chessTabletopOwnership.test.ts +3 -7
  51. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphController.test.ts +1 -2
  52. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphController.ts +2 -3
  53. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.test.ts +45 -0
  54. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts +3 -1
  55. package/src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.test.ts +65 -3
  56. package/src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts +13 -7
  57. package/src/features/registry/componentMeta.test.ts +12 -1
  58. package/src/readerFree.ts +3 -15
  59. package/src/types/authoring.ts +2 -1
  60. package/src/types/chess.ts +28 -21
  61. package/web-dist/chunks/Accordion-91sjb3zh.js +453 -0
  62. package/web-dist/components/chess-board/ChessBoard.js +2 -1
  63. package/web-dist/components/graph-view/GraphView.js +878 -317
  64. package/web-dist/components/opening-book/OpeningBook.js +2 -1
  65. package/web-dist/manifest.json +8 -4
  66. package/dist/features/chess/utils/chessEngine.d.ts +0 -8
  67. package/dist/features/chess/utils/chessEngine.d.ts.map +0 -1
  68. package/dist/features/chess/utils/chessEngine.js +0 -71
  69. package/dist/features/chess/utils/chessEngine.js.map +0 -1
  70. package/dist/features/chess/utils/chessSquares.d.ts +0 -4
  71. package/dist/features/chess/utils/chessSquares.d.ts.map +0 -1
  72. package/dist/features/chess/utils/chessSquares.js +0 -3
  73. package/dist/features/chess/utils/chessSquares.js.map +0 -1
  74. package/dist/features/chess/utils/createBoardSquares.d.ts +0 -4
  75. package/dist/features/chess/utils/createBoardSquares.d.ts.map +0 -1
  76. package/dist/features/chess/utils/createBoardSquares.js +0 -9
  77. package/dist/features/chess/utils/createBoardSquares.js.map +0 -1
  78. package/dist/features/chess/utils/getSquareFile.d.ts +0 -4
  79. package/dist/features/chess/utils/getSquareFile.d.ts.map +0 -1
  80. package/dist/features/chess/utils/getSquareFile.js +0 -5
  81. package/dist/features/chess/utils/getSquareFile.js.map +0 -1
  82. package/dist/features/chess/utils/getSquareRank.d.ts +0 -4
  83. package/dist/features/chess/utils/getSquareRank.d.ts.map +0 -1
  84. package/dist/features/chess/utils/getSquareRank.js +0 -5
  85. package/dist/features/chess/utils/getSquareRank.js.map +0 -1
  86. package/dist/features/chess/utils/isLightSquare.d.ts +0 -4
  87. package/dist/features/chess/utils/isLightSquare.d.ts.map +0 -1
  88. package/dist/features/chess/utils/isLightSquare.js +0 -6
  89. package/dist/features/chess/utils/isLightSquare.js.map +0 -1
  90. package/src/features/chess/utils/chessEngine.test.ts +0 -35
  91. package/src/features/chess/utils/chessEngine.ts +0 -83
  92. package/src/features/chess/utils/chessSquares.ts +0 -6
  93. package/src/features/chess/utils/createBoardSquares.ts +0 -13
  94. package/src/features/chess/utils/getSquareFile.ts +0 -6
  95. package/src/features/chess/utils/getSquareRank.ts +0 -6
  96. package/src/features/chess/utils/isLightSquare.ts +0 -8
  97. package/web-dist/chunks/Accordion-xcm1qc39.js +0 -3813
@@ -1,10 +1,11 @@
1
1
  'use client';
2
+ import"../../chunks/Accordion-t0k1cjca.js";
2
3
  import"../../chunks/Accordion-6wrr910w.js";
3
4
  import"../../chunks/Accordion-vj1m2wck.js";
4
5
  import {
5
6
  ChessBoard2,
6
7
  OpeningBook2
7
- } from "../../chunks/Accordion-xcm1qc39.js";
8
+ } from "../../chunks/Accordion-91sjb3zh.js";
8
9
  import"../../chunks/Accordion-srjya6dz.js";
9
10
  import"../../chunks/Accordion-xgpzh4wq.js";
10
11
  export {
@@ -870,12 +870,14 @@
870
870
  "components/chess-board/index.js",
871
871
  "components/chess-board/index.d.ts",
872
872
  "chunks/Accordion-6wrr910w.js",
873
+ "chunks/Accordion-91sjb3zh.js",
873
874
  "chunks/Accordion-fcczvwgg.js",
874
875
  "chunks/Accordion-nh0cs9hq.js",
875
876
  "chunks/Accordion-srjya6dz.js",
877
+ "chunks/Accordion-t0k1cjca.js",
876
878
  "chunks/Accordion-vj1m2wck.js",
877
- "chunks/Accordion-xcm1qc39.js",
878
- "chunks/Accordion-xgpzh4wq.js"
879
+ "chunks/Accordion-xgpzh4wq.js",
880
+ "chunks/Accordion-zypyr9xw.js"
879
881
  ],
880
882
  "sourceKind": "public"
881
883
  },
@@ -2372,12 +2374,14 @@
2372
2374
  "components/opening-book/index.js",
2373
2375
  "components/opening-book/index.d.ts",
2374
2376
  "chunks/Accordion-6wrr910w.js",
2377
+ "chunks/Accordion-91sjb3zh.js",
2375
2378
  "chunks/Accordion-fcczvwgg.js",
2376
2379
  "chunks/Accordion-nh0cs9hq.js",
2377
2380
  "chunks/Accordion-srjya6dz.js",
2381
+ "chunks/Accordion-t0k1cjca.js",
2378
2382
  "chunks/Accordion-vj1m2wck.js",
2379
- "chunks/Accordion-xcm1qc39.js",
2380
- "chunks/Accordion-xgpzh4wq.js"
2383
+ "chunks/Accordion-xgpzh4wq.js",
2384
+ "chunks/Accordion-zypyr9xw.js"
2381
2385
  ],
2382
2386
  "sourceKind": "public"
2383
2387
  },
@@ -1,8 +0,0 @@
1
- import type { ChessMoveAttempt, ChessMoveResult, ChessPieceState, ChessSquareId } from '../../../types/chess';
2
- /*** Read all pieces from a FEN-backed position. Invalid FEN produces an empty position. */
3
- export declare function readChessPieces(fen: string): ReadonlyMap<ChessSquareId, ChessPieceState>;
4
- /*** Resolve legal destination squares from one FEN position and source square. */
5
- export declare function getLegalTargets(fen: string, from: ChessSquareId): readonly ChessSquareId[];
6
- /*** Attempt one legal chess move against FEN and return the resulting position/move notation. */
7
- export declare function tryMove(fen: string, attempt: ChessMoveAttempt): ChessMoveResult | null;
8
- //# sourceMappingURL=chessEngine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chessEngine.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/chessEngine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,eAAe,EAEf,aAAa,EACd,MAAM,sBAAsB,CAAC;AAiC9B,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,aAAa,EAAE,eAAe,CAAC,CAgBxF;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,SAAS,aAAa,EAAE,CAG1F;AAED,iGAAiG;AACjG,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe,GAAG,IAAI,CActF"}
@@ -1,71 +0,0 @@
1
- import { Chess } from 'chess.js';
2
- /*** Create a chess.js position from FEN without leaking invalid-position exceptions. */
3
- function createChess(fen) {
4
- try {
5
- return new Chess(fen);
6
- }
7
- catch {
8
- return null;
9
- }
10
- }
11
- /*** Convert a chess.js piece into the public ZORA piece code. */
12
- function toPieceCode(piece) {
13
- return piece.color === 'w' ? piece.type.toUpperCase() : piece.type.toLowerCase();
14
- }
15
- /*** Normalize a chess.js promotion marker into the public promotion union. */
16
- function toPromotionPiece(piece) {
17
- return piece === 'q' || piece === 'r' || piece === 'b' || piece === 'n' ? piece : undefined;
18
- }
19
- /*** Convert one successful chess.js move into the public result contract. */
20
- function toMoveResult(move, fen) {
21
- return {
22
- fen,
23
- from: move.from,
24
- lan: move.lan,
25
- promotion: toPromotionPiece(move.promotion),
26
- san: move.san,
27
- to: move.to,
28
- };
29
- }
30
- /*** Read all pieces from a FEN-backed position. Invalid FEN produces an empty position. */
31
- export function readChessPieces(fen) {
32
- const chess = createChess(fen);
33
- const pieces = new Map();
34
- if (!chess)
35
- return pieces;
36
- for (const rank of chess.board()) {
37
- for (const piece of rank) {
38
- if (!piece)
39
- continue;
40
- pieces.set(piece.square, {
41
- color: piece.color === 'w' ? 'white' : 'black',
42
- piece: toPieceCode(piece),
43
- square: piece.square,
44
- });
45
- }
46
- }
47
- return pieces;
48
- }
49
- /*** Resolve legal destination squares from one FEN position and source square. */
50
- export function getLegalTargets(fen, from) {
51
- const chess = createChess(fen);
52
- return chess ? chess.moves({ square: from, verbose: true }).map((move) => move.to) : [];
53
- }
54
- /*** Attempt one legal chess move against FEN and return the resulting position/move notation. */
55
- export function tryMove(fen, attempt) {
56
- const chess = createChess(fen);
57
- if (!chess)
58
- return null;
59
- try {
60
- const move = chess.move({
61
- from: attempt.from,
62
- promotion: attempt.promotion,
63
- to: attempt.to,
64
- });
65
- return toMoveResult(move, chess.fen());
66
- }
67
- catch {
68
- return null;
69
- }
70
- }
71
- //# sourceMappingURL=chessEngine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chessEngine.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/chessEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,UAAU,CAAC;AAW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'chess.js';\n\nimport type {\n ChessMoveAttempt,\n ChessMoveResult,\n ChessPieceCode,\n ChessPieceState,\n ChessPromotionPiece,\n ChessSquareId,\n} from '../../../types/chess';\n\n/*** Create a chess.js position from FEN without leaking invalid-position exceptions. */\nfunction createChess(fen: string): Chess | null {\n try {\n return new Chess(fen);\n } catch {\n return null;\n }\n}\n\n/*** Convert a chess.js piece into the public ZORA piece code. */\nfunction toPieceCode(piece: { readonly color: 'b' | 'w'; readonly type: string }): ChessPieceCode {\n return piece.color === 'w' ? piece.type.toUpperCase() : piece.type.toLowerCase();\n}\n\n/*** Normalize a chess.js promotion marker into the public promotion union. */\nfunction toPromotionPiece(piece: string | undefined): ChessPromotionPiece | undefined {\n return piece === 'q' || piece === 'r' || piece === 'b' || piece === 'n' ? piece : undefined;\n}\n\n/*** Convert one successful chess.js move into the public result contract. */\nfunction toMoveResult(move: Move, fen: string): ChessMoveResult {\n return {\n fen,\n from: move.from,\n lan: move.lan,\n promotion: toPromotionPiece(move.promotion),\n san: move.san,\n to: move.to,\n };\n}\n\n/*** Read all pieces from a FEN-backed position. Invalid FEN produces an empty position. */\nexport function readChessPieces(fen: string): ReadonlyMap<ChessSquareId, ChessPieceState> {\n const chess = createChess(fen);\n const pieces = new Map<ChessSquareId, ChessPieceState>();\n if (!chess) return pieces;\n\n for (const rank of chess.board()) {\n for (const piece of rank) {\n if (!piece) continue;\n pieces.set(piece.square, {\n color: piece.color === 'w' ? 'white' : 'black',\n piece: toPieceCode(piece),\n square: piece.square,\n });\n }\n }\n return pieces;\n}\n\n/*** Resolve legal destination squares from one FEN position and source square. */\nexport function getLegalTargets(fen: string, from: ChessSquareId): readonly ChessSquareId[] {\n const chess = createChess(fen);\n return chess ? chess.moves({ square: from, verbose: true }).map((move) => move.to) : [];\n}\n\n/*** Attempt one legal chess move against FEN and return the resulting position/move notation. */\nexport function tryMove(fen: string, attempt: ChessMoveAttempt): ChessMoveResult | null {\n const chess = createChess(fen);\n if (!chess) return null;\n\n try {\n const move = chess.move({\n from: attempt.from,\n promotion: attempt.promotion,\n to: attempt.to,\n });\n return toMoveResult(move, chess.fen());\n } catch {\n return null;\n }\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
- /*** Lists every board square in ascending rank and file order. */
3
- export declare const chessSquares: readonly ChessSquareId[];
4
- //# sourceMappingURL=chessSquares.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chessSquares.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/chessSquares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kEAAkE;AAClE,eAAO,MAAM,YAAY,EAAE,SAAS,aAAa,EAEhD,CAAC"}
@@ -1,3 +0,0 @@
1
- /*** Lists every board square in ascending rank and file order. */
2
- export const chessSquares = [1, 2, 3, 4, 5, 6, 7, 8].flatMap((rank) => [...'abcdefgh'].map((file) => `${file}${rank}`));
3
- //# sourceMappingURL=chessSquares.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chessSquares.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/chessSquares.ts"],"names":[],"mappings":"AAEA,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAC9F,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,EAAmB,CAAC,CACjE,CAAC","sourcesContent":["import type { ChessSquareId } from '../../../types/chess';\n\n/*** Lists every board square in ascending rank and file order. */\nexport const chessSquares: readonly ChessSquareId[] = [1, 2, 3, 4, 5, 6, 7, 8].flatMap((rank) =>\n [...'abcdefgh'].map((file) => `${file}${rank}` as ChessSquareId),\n);\n"]}
@@ -1,4 +0,0 @@
1
- import type { ChessBoardOrientation, ChessSquareId } from '../../../types/chess';
2
- /*** Orders the 64 displayed squares for the selected player orientation. */
3
- export declare function createBoardSquares(orientation: ChessBoardOrientation): readonly ChessSquareId[];
4
- //# sourceMappingURL=createBoardSquares.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBoardSquares.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/createBoardSquares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAKjF,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,GAAG,SAAS,aAAa,EAAE,CAM/F"}
@@ -1,9 +0,0 @@
1
- const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
2
- const ranks = ['1', '2', '3', '4', '5', '6', '7', '8'];
3
- /*** Orders the 64 displayed squares for the selected player orientation. */
4
- export function createBoardSquares(orientation) {
5
- const displayedRanks = orientation === 'white' ? [...ranks].reverse() : [...ranks];
6
- const displayedFiles = orientation === 'white' ? [...files] : [...files].reverse();
7
- return displayedRanks.flatMap((rank) => displayedFiles.map((file) => `${file}${rank}`));
8
- }
9
- //# sourceMappingURL=createBoardSquares.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBoardSquares.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/createBoardSquares.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAChE,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAEhE,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB,CAAC,WAAkC;IACnE,MAAM,cAAc,GAAG,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IACnF,MAAM,cAAc,GAAG,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACnF,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACrC,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAiB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAC9D,CAAC;AACJ,CAAC","sourcesContent":["import type { ChessBoardOrientation, ChessSquareId } from '../../../types/chess';\n\nconst files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] as const;\nconst ranks = ['1', '2', '3', '4', '5', '6', '7', '8'] as const;\n\n/*** Orders the 64 displayed squares for the selected player orientation. */\nexport function createBoardSquares(orientation: ChessBoardOrientation): readonly ChessSquareId[] {\n const displayedRanks = orientation === 'white' ? [...ranks].reverse() : [...ranks];\n const displayedFiles = orientation === 'white' ? [...files] : [...files].reverse();\n return displayedRanks.flatMap((rank) =>\n displayedFiles.map((file): ChessSquareId => `${file}${rank}`),\n );\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
- /*** Returns the file letter of a chess square. */
3
- export declare function getSquareFile(square: ChessSquareId): string;
4
- //# sourceMappingURL=getSquareFile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSquareFile.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/getSquareFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE3D"}
@@ -1,5 +0,0 @@
1
- /*** Returns the file letter of a chess square. */
2
- export function getSquareFile(square) {
3
- return square[0] ?? '';
4
- }
5
- //# sourceMappingURL=getSquareFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSquareFile.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/getSquareFile.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { ChessSquareId } from '../../../types/chess';\n\n/*** Returns the file letter of a chess square. */\nexport function getSquareFile(square: ChessSquareId): string {\n return square[0] ?? '';\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
- /*** Returns the rank number of a chess square. */
3
- export declare function getSquareRank(square: ChessSquareId): string;
4
- //# sourceMappingURL=getSquareRank.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSquareRank.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/getSquareRank.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE3D"}
@@ -1,5 +0,0 @@
1
- /*** Returns the rank number of a chess square. */
2
- export function getSquareRank(square) {
3
- return square[1] ?? '';
4
- }
5
- //# sourceMappingURL=getSquareRank.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSquareRank.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/getSquareRank.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { ChessSquareId } from '../../../types/chess';\n\n/*** Returns the rank number of a chess square. */\nexport function getSquareRank(square: ChessSquareId): string {\n return square[1] ?? '';\n}\n"]}
@@ -1,4 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
- /*** Determines whether a chess square uses the light presentation color. */
3
- export declare function isLightSquare(square: ChessSquareId): boolean;
4
- //# sourceMappingURL=isLightSquare.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isLightSquare.d.ts","sourceRoot":"","sources":["../../../../src/features/chess/utils/isLightSquare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAE5D"}
@@ -1,6 +0,0 @@
1
- const files = 'abcdefgh';
2
- /*** Determines whether a chess square uses the light presentation color. */
3
- export function isLightSquare(square) {
4
- return (files.indexOf(square[0] ?? '') + Number(square[1]) - 1) % 2 === 1;
5
- }
6
- //# sourceMappingURL=isLightSquare.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isLightSquare.js","sourceRoot":"","sources":["../../../../src/features/chess/utils/isLightSquare.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,UAAU,CAAC;AAEzB,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import type { ChessSquareId } from '../../../types/chess';\n\nconst files = 'abcdefgh';\n\n/*** Determines whether a chess square uses the light presentation color. */\nexport function isLightSquare(square: ChessSquareId): boolean {\n return (files.indexOf(square[0] ?? '') + Number(square[1]) - 1) % 2 === 1;\n}\n"]}
@@ -1,35 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
-
3
- import { getLegalTargets, readChessPieces, tryMove } from './chessEngine';
4
-
5
- const START_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
6
-
7
- describe('core chess engine', () => {
8
- it('reads pieces from FEN and preserves piece codes', () => {
9
- const pieces = readChessPieces(START_FEN);
10
-
11
- expect(pieces.size).toBe(32);
12
- expect(pieces.get('e1')?.piece).toBe('K');
13
- expect(pieces.get('e8')?.piece).toBe('k');
14
- });
15
-
16
- it('returns an empty map for invalid FEN', () => {
17
- expect(readChessPieces('invalid').size).toBe(0);
18
- });
19
-
20
- it('returns legal target squares', () => {
21
- expect(getLegalTargets(START_FEN, 'e2')).toEqual(['e3', 'e4']);
22
- });
23
-
24
- it('returns resulting move details for legal moves', () => {
25
- const result = tryMove(START_FEN, { from: 'e2', to: 'e4' });
26
-
27
- expect(result?.san).toBe('e4');
28
- expect(result?.lan).toBe('e2e4');
29
- expect(result?.fen).toContain(' b ');
30
- });
31
-
32
- it('returns null for invalid moves', () => {
33
- expect(tryMove(START_FEN, { from: 'e2', to: 'e5' })).toBeNull();
34
- });
35
- });
@@ -1,83 +0,0 @@
1
- import { Chess, type Move } from 'chess.js';
2
-
3
- import type {
4
- ChessMoveAttempt,
5
- ChessMoveResult,
6
- ChessPieceCode,
7
- ChessPieceState,
8
- ChessPromotionPiece,
9
- ChessSquareId,
10
- } from '../../../types/chess';
11
-
12
- /*** Create a chess.js position from FEN without leaking invalid-position exceptions. */
13
- function createChess(fen: string): Chess | null {
14
- try {
15
- return new Chess(fen);
16
- } catch {
17
- return null;
18
- }
19
- }
20
-
21
- /*** Convert a chess.js piece into the public ZORA piece code. */
22
- function toPieceCode(piece: { readonly color: 'b' | 'w'; readonly type: string }): ChessPieceCode {
23
- return piece.color === 'w' ? piece.type.toUpperCase() : piece.type.toLowerCase();
24
- }
25
-
26
- /*** Normalize a chess.js promotion marker into the public promotion union. */
27
- function toPromotionPiece(piece: string | undefined): ChessPromotionPiece | undefined {
28
- return piece === 'q' || piece === 'r' || piece === 'b' || piece === 'n' ? piece : undefined;
29
- }
30
-
31
- /*** Convert one successful chess.js move into the public result contract. */
32
- function toMoveResult(move: Move, fen: string): ChessMoveResult {
33
- return {
34
- fen,
35
- from: move.from,
36
- lan: move.lan,
37
- promotion: toPromotionPiece(move.promotion),
38
- san: move.san,
39
- to: move.to,
40
- };
41
- }
42
-
43
- /*** Read all pieces from a FEN-backed position. Invalid FEN produces an empty position. */
44
- export function readChessPieces(fen: string): ReadonlyMap<ChessSquareId, ChessPieceState> {
45
- const chess = createChess(fen);
46
- const pieces = new Map<ChessSquareId, ChessPieceState>();
47
- if (!chess) return pieces;
48
-
49
- for (const rank of chess.board()) {
50
- for (const piece of rank) {
51
- if (!piece) continue;
52
- pieces.set(piece.square, {
53
- color: piece.color === 'w' ? 'white' : 'black',
54
- piece: toPieceCode(piece),
55
- square: piece.square,
56
- });
57
- }
58
- }
59
- return pieces;
60
- }
61
-
62
- /*** Resolve legal destination squares from one FEN position and source square. */
63
- export function getLegalTargets(fen: string, from: ChessSquareId): readonly ChessSquareId[] {
64
- const chess = createChess(fen);
65
- return chess ? chess.moves({ square: from, verbose: true }).map((move) => move.to) : [];
66
- }
67
-
68
- /*** Attempt one legal chess move against FEN and return the resulting position/move notation. */
69
- export function tryMove(fen: string, attempt: ChessMoveAttempt): ChessMoveResult | null {
70
- const chess = createChess(fen);
71
- if (!chess) return null;
72
-
73
- try {
74
- const move = chess.move({
75
- from: attempt.from,
76
- promotion: attempt.promotion,
77
- to: attempt.to,
78
- });
79
- return toMoveResult(move, chess.fen());
80
- } catch {
81
- return null;
82
- }
83
- }
@@ -1,6 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
-
3
- /*** Lists every board square in ascending rank and file order. */
4
- export const chessSquares: readonly ChessSquareId[] = [1, 2, 3, 4, 5, 6, 7, 8].flatMap((rank) =>
5
- [...'abcdefgh'].map((file) => `${file}${rank}` as ChessSquareId),
6
- );
@@ -1,13 +0,0 @@
1
- import type { ChessBoardOrientation, ChessSquareId } from '../../../types/chess';
2
-
3
- const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] as const;
4
- const ranks = ['1', '2', '3', '4', '5', '6', '7', '8'] as const;
5
-
6
- /*** Orders the 64 displayed squares for the selected player orientation. */
7
- export function createBoardSquares(orientation: ChessBoardOrientation): readonly ChessSquareId[] {
8
- const displayedRanks = orientation === 'white' ? [...ranks].reverse() : [...ranks];
9
- const displayedFiles = orientation === 'white' ? [...files] : [...files].reverse();
10
- return displayedRanks.flatMap((rank) =>
11
- displayedFiles.map((file): ChessSquareId => `${file}${rank}`),
12
- );
13
- }
@@ -1,6 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
-
3
- /*** Returns the file letter of a chess square. */
4
- export function getSquareFile(square: ChessSquareId): string {
5
- return square[0] ?? '';
6
- }
@@ -1,6 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
-
3
- /*** Returns the rank number of a chess square. */
4
- export function getSquareRank(square: ChessSquareId): string {
5
- return square[1] ?? '';
6
- }
@@ -1,8 +0,0 @@
1
- import type { ChessSquareId } from '../../../types/chess';
2
-
3
- const files = 'abcdefgh';
4
-
5
- /*** Determines whether a chess square uses the light presentation color. */
6
- export function isLightSquare(square: ChessSquareId): boolean {
7
- return (files.indexOf(square[0] ?? '') + Number(square[1]) - 1) % 2 === 1;
8
- }