@ankhorage/zora 25.11.1 → 26.0.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +6 -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/readerFree.d.ts +2 -2
  26. package/dist/readerFree.d.ts.map +1 -1
  27. package/dist/readerFree.js +1 -1
  28. package/dist/readerFree.js.map +1 -1
  29. package/dist/types/authoring.d.ts +2 -1
  30. package/dist/types/authoring.d.ts.map +1 -1
  31. package/dist/types/authoring.js.map +1 -1
  32. package/dist/types/chess.d.ts +27 -20
  33. package/dist/types/chess.d.ts.map +1 -1
  34. package/dist/types/chess.js.map +1 -1
  35. package/package.json +31 -92
  36. package/src/features/chess/adapters/inbound/ChessBoard.tsx +263 -112
  37. package/src/features/chess/meta.ts +64 -40
  38. package/src/features/chess/public.test.tsx +77 -228
  39. package/src/features/chess/public.ts +2 -9
  40. package/src/features/chess/utils/createChessBoardCellPressHandler.ts +30 -0
  41. package/src/features/chess/utils/createChessBoardCells.ts +54 -0
  42. package/src/features/chessTabletopOwnership.test.ts +3 -7
  43. package/src/features/registry/componentMeta.test.ts +12 -1
  44. package/src/readerFree.ts +3 -15
  45. package/src/types/authoring.ts +2 -1
  46. package/src/types/chess.ts +28 -21
  47. package/web-dist/chunks/Accordion-91sjb3zh.js +453 -0
  48. package/web-dist/components/chess-board/ChessBoard.js +2 -1
  49. package/web-dist/components/opening-book/OpeningBook.js +2 -1
  50. package/web-dist/manifest.json +8 -4
  51. package/dist/features/chess/utils/chessEngine.d.ts +0 -8
  52. package/dist/features/chess/utils/chessEngine.d.ts.map +0 -1
  53. package/dist/features/chess/utils/chessEngine.js +0 -71
  54. package/dist/features/chess/utils/chessEngine.js.map +0 -1
  55. package/dist/features/chess/utils/chessSquares.d.ts +0 -4
  56. package/dist/features/chess/utils/chessSquares.d.ts.map +0 -1
  57. package/dist/features/chess/utils/chessSquares.js +0 -3
  58. package/dist/features/chess/utils/chessSquares.js.map +0 -1
  59. package/dist/features/chess/utils/createBoardSquares.d.ts +0 -4
  60. package/dist/features/chess/utils/createBoardSquares.d.ts.map +0 -1
  61. package/dist/features/chess/utils/createBoardSquares.js +0 -9
  62. package/dist/features/chess/utils/createBoardSquares.js.map +0 -1
  63. package/dist/features/chess/utils/getSquareFile.d.ts +0 -4
  64. package/dist/features/chess/utils/getSquareFile.d.ts.map +0 -1
  65. package/dist/features/chess/utils/getSquareFile.js +0 -5
  66. package/dist/features/chess/utils/getSquareFile.js.map +0 -1
  67. package/dist/features/chess/utils/getSquareRank.d.ts +0 -4
  68. package/dist/features/chess/utils/getSquareRank.d.ts.map +0 -1
  69. package/dist/features/chess/utils/getSquareRank.js +0 -5
  70. package/dist/features/chess/utils/getSquareRank.js.map +0 -1
  71. package/dist/features/chess/utils/isLightSquare.d.ts +0 -4
  72. package/dist/features/chess/utils/isLightSquare.d.ts.map +0 -1
  73. package/dist/features/chess/utils/isLightSquare.js +0 -6
  74. package/dist/features/chess/utils/isLightSquare.js.map +0 -1
  75. package/src/features/chess/utils/chessEngine.test.ts +0 -35
  76. package/src/features/chess/utils/chessEngine.ts +0 -83
  77. package/src/features/chess/utils/chessSquares.ts +0 -6
  78. package/src/features/chess/utils/createBoardSquares.ts +0 -13
  79. package/src/features/chess/utils/getSquareFile.ts +0 -6
  80. package/src/features/chess/utils/getSquareRank.ts +0 -6
  81. package/src/features/chess/utils/isLightSquare.ts +0 -8
  82. package/web-dist/chunks/Accordion-xcm1qc39.js +0 -3813
@@ -1,248 +1,97 @@
1
- import { join } from 'node:path';
2
- import { pathToFileURL } from 'node:url';
3
-
4
1
  import { describe, expect, test } from 'bun:test';
5
- import { Window } from 'happy-dom';
6
- import React, { act } from 'react';
7
- import { createRoot } from 'react-dom/client';
8
- import { renderToStaticMarkup } from 'react-dom/server';
9
2
 
10
3
  import { chessBoardMeta } from './meta';
11
- import type {
12
- ChessBoard as ChessBoardComponent,
13
- OpeningBook as OpeningBookComponent,
14
- } from './public';
15
- import { createBoardSquares } from './utils/createBoardSquares';
16
- import { createChessBoardColorScheme } from './utils/createChessBoardColorScheme';
17
- import { getSquareFile } from './utils/getSquareFile';
18
- import { getSquareRank } from './utils/getSquareRank';
19
- import { isLightSquare } from './utils/isLightSquare';
20
-
21
- const webDistRoot = join(import.meta.dir, '../../../web-dist');
22
- const load = (path: string) => import(pathToFileURL(join(webDistRoot, path)).href);
4
+ import { createChessBoardCellPressHandler } from './utils/createChessBoardCellPressHandler';
5
+ import { createChessBoardCells } from './utils/createChessBoardCells';
23
6
 
24
7
  describe('Chess presentation', () => {
25
- test('keeps square order and theme-derived presentation independent of chess rules', () => {
26
- expect(createBoardSquares('white').at(0)).toBe('a8');
27
- expect(createBoardSquares('black').at(0)).toBe('h1');
28
- expect(getSquareFile('e4')).toBe('e');
29
- expect(getSquareRank('e4')).toBe('4');
30
- expect(isLightSquare('a1')).toBe(false);
31
- expect(typeof createChessBoardColorScheme).toBe('function');
32
- });
33
-
34
- test('preserves FEN and validated-move authoring metadata', () => {
35
- expect(chessBoardMeta.props.fen.type).toBe('string');
36
- expect(chessBoardMeta.props.validateMoves.default).toBe(true);
37
- expect(chessBoardMeta.events.legalMove.payloadFields.map((field) => field.path)).toEqual([
38
- 'from',
39
- 'to',
40
- 'fen',
41
- 'san',
42
- 'lan',
43
- 'promotion',
44
- ]);
45
- expect(chessBoardMeta.events.invalidMove.payloadFields.map((field) => field.path)).toEqual([
46
- 'from',
47
- 'to',
48
- 'promotion',
8
+ test('declares caller-owned dimensions, cells, and move intents without rule-engine events', () => {
9
+ expect(chessBoardMeta.blueprint.defaultProps).toMatchObject({ columns: 8, rows: 8 });
10
+ expect(chessBoardMeta.props.columns.default).toBe(8);
11
+ expect(chessBoardMeta.props.rows.default).toBe(8);
12
+ expect(chessBoardMeta.events.cellPress.payloadFields).toEqual([
13
+ { path: 'column', type: 'number', label: 'Column' },
14
+ { path: 'row', type: 'number', label: 'Row' },
49
15
  ]);
16
+ expect(chessBoardMeta.events).not.toHaveProperty('legalMove');
17
+ expect(chessBoardMeta.events).not.toHaveProperty('invalidMove');
50
18
  });
51
19
 
52
- test('renders custom React nodes, square IDs, and opening metadata through independent artifacts', async () => {
53
- const { ChessBoard } = (await load('components/chess-board/index.js')) as {
54
- ChessBoard: typeof ChessBoardComponent;
55
- };
56
- const { OpeningBook } = (await load('components/opening-book/index.js')) as {
57
- OpeningBook: typeof OpeningBookComponent;
58
- };
59
- const markup = renderToStaticMarkup(
60
- <>
61
- <ChessBoard
62
- colorScheme={{ selectedSquare: '#123456', legalTarget: '#234567' }}
63
- legalTargets={['e4']}
64
- pieces={[{ color: 'white', piece: 'p', square: 'e2' }]}
65
- renderPiece={() => <div data-testid="custom-piece" />}
66
- selectedSquare="e2"
67
- showCoordinates
68
- testID="board"
69
- />
70
- <OpeningBook
71
- moves={[
72
- {
73
- san: 'Nf3',
74
- eco: 'A04',
75
- name: 'Reti Opening',
76
- games: 42,
77
- whiteWinRate: 0.52,
78
- drawRate: 0.2,
79
- blackWinRate: 0.28,
80
- },
81
- ]}
82
- testID="book"
83
- />
84
- </>,
85
- );
86
- const browser = new Window();
87
- browser.document.body.innerHTML = markup;
88
- expect(browser.document.querySelectorAll('[data-testid^="board-square-"]')).toHaveLength(64);
89
- expect(
90
- browser.document.querySelector('[data-testid="board-square-e2"]')?.textContent,
91
- ).toContain('e2');
92
- expect(
93
- browser.document.querySelector('[data-testid="custom-piece"]')?.parentElement?.className,
94
- ).toContain('css-view');
95
- expect(
96
- browser.document.querySelector('[data-testid="board-square-e2"]')?.getAttribute('style'),
97
- ).toContain('background-color:rgba(18,52,86,1.00)');
98
- expect(
99
- browser.document.querySelector('[data-testid="board-square-e4"]')?.getAttribute('style'),
100
- ).toContain('background-color:rgba(35,69,103,1.00)');
101
- expect(browser.document.querySelector('[data-testid="book-move-Nf3"]')?.textContent).toContain(
102
- 'A04 · Reti Opening · 42 games',
103
- );
104
- expect(browser.document.querySelector('[data-testid="book-move-Nf3"]')?.textContent).toContain(
105
- 'W 52% D 20% B 28%',
106
- );
107
- browser.close();
20
+ test('uses the shared GridView presentation boundary rather than a chess rules engine', async () => {
21
+ const source = await Bun.file('src/features/chess/adapters/inbound/ChessBoard.tsx').text();
22
+
23
+ expect(source).toContain("import { GridView } from '../../../grid-view/public';");
24
+ expect(source).not.toContain('chess.js');
25
+ expect(source).not.toContain('fen');
108
26
  });
109
27
 
110
- test('preserves FEN-backed pieces, legal targets, and legal/invalid move callbacks', async () => {
111
- const { ChessBoard } = (await load('components/chess-board/index.js')) as {
112
- ChessBoard: typeof ChessBoardComponent;
113
- };
114
- const browser = new Window();
115
- const keys = ['window', 'document', 'Node', 'navigator', 'IS_REACT_ACT_ENVIRONMENT'] as const;
116
- const previous = keys.map(
117
- (key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)] as const,
118
- );
119
- Object.assign(globalThis, {
120
- window: browser,
121
- document: browser.document,
122
- Node: browser.Node,
123
- navigator: browser.navigator,
124
- IS_REACT_ACT_ENVIRONMENT: true,
28
+ test('maps non-square boards into opposite GridView coordinates for white and black orientation', () => {
29
+ const white = createChessBoardCells(3, 2, 'white');
30
+ const black = createChessBoardCells(3, 2, 'black');
31
+
32
+ expect(white.find((cell) => cell.column === 1 && cell.row === 2)).toMatchObject({
33
+ x: 0,
34
+ y: 0,
35
+ });
36
+ expect(white.find((cell) => cell.column === 3 && cell.row === 1)).toMatchObject({
37
+ x: 2,
38
+ y: 1,
125
39
  });
126
- const host = document.createElement('div');
127
- document.body.appendChild(host);
128
- const legal: string[] = [];
129
- const invalid: string[] = [];
130
- const root = createRoot(host);
40
+ expect(black.find((cell) => cell.column === 3 && cell.row === 1)).toMatchObject({
41
+ x: 0,
42
+ y: 0,
43
+ });
44
+ expect(black.find((cell) => cell.column === 1 && cell.row === 2)).toMatchObject({
45
+ x: 2,
46
+ y: 1,
47
+ });
48
+ });
131
49
 
132
- try {
133
- act(() =>
134
- root.render(
135
- <ChessBoard
136
- fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
137
- onInvalidMove={(move) => invalid.push(`${move.from}-${move.to}`)}
138
- onLegalMove={(move) => legal.push(`${move.lan}:${move.san}`)}
139
- selectedSquare="e2"
140
- showCoordinates
141
- testID="fen-board"
142
- />,
143
- ),
144
- );
50
+ test('accepts only the documented 2 through 24 presentation dimensions', () => {
51
+ expect(createChessBoardCells(2, 24, 'white')).toHaveLength(48);
52
+ expect(() => createChessBoardCells(1, 8, 'white')).toThrow(RangeError);
53
+ expect(() => createChessBoardCells(8, 25, 'black')).toThrow(RangeError);
54
+ expect(() => createChessBoardCells(2.5, 8, 'white')).toThrow(RangeError);
55
+ });
145
56
 
146
- expect(host.querySelector('[data-testid="fen-board-square-e1"]')?.textContent).toContain('♔');
147
- expect(
148
- host.querySelector('[data-testid="fen-board-square-e4"]')?.getAttribute('style'),
149
- ).toContain('background-color');
57
+ test('emits caller-owned press and move intents without acting in passive mode', () => {
58
+ const presses: unknown[] = [];
59
+ const attempts: unknown[] = [];
60
+ const active = createChessBoardCellPressHandler({
61
+ onCellPress: (cell) => presses.push(cell),
62
+ onMoveAttempt: (attempt) => attempts.push(attempt),
63
+ selectedCell: { column: 2, row: 2 },
64
+ });
150
65
 
151
- act(() => {
152
- host
153
- .querySelector('[data-testid="fen-board-square-e4"]')
154
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
155
- });
156
- expect(legal).toEqual(['e2e4:e4']);
66
+ active({ column: 3, row: 4 });
67
+ createChessBoardCellPressHandler({
68
+ interactionPolicy: 'passive',
69
+ onCellPress: (cell) => presses.push(cell),
70
+ onMoveAttempt: (attempt) => attempts.push(attempt),
71
+ selectedCell: { column: 2, row: 2 },
72
+ })({ column: 4, row: 4 });
157
73
 
158
- act(() => {
159
- host
160
- .querySelector('[data-testid="fen-board-square-e5"]')
161
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
162
- });
163
- expect(invalid).toEqual(['e2-e5']);
164
- } finally {
165
- act(() => root.unmount());
166
- browser.close();
167
- for (const [key, descriptor] of previous) {
168
- if (descriptor) Object.defineProperty(globalThis, key, descriptor);
169
- else Reflect.deleteProperty(globalThis, key);
170
- }
171
- }
74
+ expect(presses).toEqual([{ column: 3, row: 4 }]);
75
+ expect(attempts).toEqual([{ from: { column: 2, row: 2 }, to: { column: 3, row: 4 } }]);
172
76
  });
173
77
 
174
- test('emits only caller-owned intents in active mode and suppresses them in passive mode', async () => {
175
- const { ChessBoard } = (await load('components/chess-board/index.js')) as {
176
- ChessBoard: typeof ChessBoardComponent;
177
- };
178
- const { OpeningBook } = (await load('components/opening-book/index.js')) as {
179
- OpeningBook: typeof OpeningBookComponent;
180
- };
181
- const browser = new Window();
182
- const keys = ['window', 'document', 'Node', 'navigator', 'IS_REACT_ACT_ENVIRONMENT'] as const;
183
- const previous = keys.map(
184
- (key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)] as const,
185
- );
186
- Object.assign(globalThis, {
187
- window: browser,
188
- document: browser.document,
189
- Node: browser.Node,
190
- navigator: browser.navigator,
191
- IS_REACT_ACT_ENVIRONMENT: true,
78
+ test('describes selected cells and legal targets as cell objects in manifest metadata', () => {
79
+ expect(chessBoardMeta.props.selectedCell).toMatchObject({
80
+ type: 'object',
81
+ itemSchema: [{ key: 'column' }, { key: 'row' }],
82
+ });
83
+ expect(chessBoardMeta.props.legalTargets).toMatchObject({
84
+ type: 'array',
85
+ itemSchema: [{ key: 'column' }, { key: 'row' }],
86
+ });
87
+ expect(chessBoardMeta.bindings.props.selectedCell.value).toMatchObject({
88
+ type: 'object',
89
+ fields: [{ path: 'column' }, { path: 'row' }],
90
+ });
91
+ expect(chessBoardMeta.bindings.props.legalTargets.value).toMatchObject({
92
+ type: 'array',
93
+ itemType: 'object',
94
+ fields: [{ path: '[].column' }, { path: '[].row' }],
192
95
  });
193
- const host = document.createElement('div');
194
- document.body.appendChild(host);
195
- const squares: string[] = [];
196
- const moves: string[] = [];
197
- const book: string[] = [];
198
- const root = createRoot(host);
199
- const render = (interactionPolicy: 'active' | 'passive') => (
200
- <>
201
- <ChessBoard
202
- interactionPolicy={interactionPolicy}
203
- selectedSquare="e2"
204
- testID="board"
205
- onSquarePress={(square) => squares.push(square)}
206
- onMoveAttempt={(move) => moves.push(`${move.from}-${move.to}`)}
207
- />
208
- <OpeningBook
209
- interactionPolicy={interactionPolicy}
210
- moves={[{ san: 'e4' }]}
211
- onMovePress={(move) => book.push(move.san)}
212
- testID="book"
213
- />
214
- </>
215
- );
216
- try {
217
- act(() => root.render(render('passive')));
218
- act(() => {
219
- host
220
- .querySelector('[data-testid="board-square-e4"]')
221
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
222
- host
223
- .querySelector('[data-testid="book-move-e4"]')
224
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
225
- });
226
- expect([squares, moves, book]).toEqual([[], [], []]);
227
- act(() => root.render(render('active')));
228
- act(() => {
229
- host
230
- .querySelector('[data-testid="board-square-e4"]')
231
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
232
- host
233
- .querySelector('[data-testid="book-move-e4"]')
234
- ?.dispatchEvent(new browser.MouseEvent('click', { bubbles: true }));
235
- });
236
- expect(squares).toEqual(['e4']);
237
- expect(moves).toEqual(['e2-e4']);
238
- expect(book).toEqual(['e4']);
239
- } finally {
240
- act(() => root.unmount());
241
- browser.close();
242
- for (const [key, descriptor] of previous) {
243
- if (descriptor) Object.defineProperty(globalThis, key, descriptor);
244
- else Reflect.deleteProperty(globalThis, key);
245
- }
246
- }
247
96
  });
248
97
  });
@@ -1,16 +1,15 @@
1
1
  export type {
2
+ ChessBoardCell,
2
3
  ChessBoardColorOverrides,
3
4
  ChessBoardColorScheme,
5
+ ChessBoardDimensions,
4
6
  ChessBoardOrientation,
5
7
  ChessBoardProps,
6
8
  ChessMoveAttempt,
7
- ChessMoveResult,
8
9
  ChessPieceCode,
9
10
  ChessPieceRenderContext,
10
11
  ChessPieceRenderer,
11
12
  ChessPieceState,
12
- ChessPromotionPiece,
13
- ChessSquareId,
14
13
  OpeningBookColorOverrides,
15
14
  OpeningBookColorScheme,
16
15
  OpeningBookMove,
@@ -19,12 +18,6 @@ export type {
19
18
  export { ChessBoard } from './adapters/inbound/ChessBoard';
20
19
  export { OpeningBook } from './adapters/inbound/OpeningBook';
21
20
  export { chessBoardMeta, openingBookMeta } from './meta';
22
- export { getLegalTargets, readChessPieces, tryMove } from './utils/chessEngine';
23
- export { chessSquares } from './utils/chessSquares';
24
- export { createBoardSquares } from './utils/createBoardSquares';
25
21
  export type { ChessColorThemeShape } from './utils/createChessBoardColorScheme';
26
22
  export { createChessBoardColorScheme } from './utils/createChessBoardColorScheme';
27
23
  export { createOpeningBookColorScheme } from './utils/createOpeningBookColorScheme';
28
- export { getSquareFile } from './utils/getSquareFile';
29
- export { getSquareRank } from './utils/getSquareRank';
30
- export { isLightSquare } from './utils/isLightSquare';
@@ -0,0 +1,30 @@
1
+ import type { ChessBoardCell, ChessBoardProps } from '../../../types/chess';
2
+
3
+ type ChessBoardCellPressHandlerOptions = Pick<
4
+ ChessBoardProps,
5
+ 'disabled' | 'interactionPolicy' | 'onCellPress' | 'onMoveAttempt' | 'selectedCell'
6
+ >;
7
+
8
+ /*** Creates the caller-owned cell and move intent boundary for an interactive chess presentation. */
9
+ export function createChessBoardCellPressHandler({
10
+ disabled,
11
+ interactionPolicy,
12
+ onCellPress,
13
+ onMoveAttempt,
14
+ selectedCell,
15
+ }: ChessBoardCellPressHandlerOptions): (cell: ChessBoardCell) => void {
16
+ return (cell) => {
17
+ if (disabled || interactionPolicy === 'passive') return;
18
+
19
+ onCellPress?.(cell);
20
+ if (selectedCell === null || selectedCell === undefined || cellsEqual(selectedCell, cell)) {
21
+ return;
22
+ }
23
+ onMoveAttempt?.({ from: selectedCell, to: cell });
24
+ };
25
+ }
26
+
27
+ /*** Compares caller-owned coordinates without adding chess-rule semantics. */
28
+ function cellsEqual(left: ChessBoardCell, right: ChessBoardCell): boolean {
29
+ return left.column === right.column && left.row === right.row;
30
+ }
@@ -0,0 +1,54 @@
1
+ import type { ChessBoardCell, ChessBoardOrientation } from '../../../types/chess';
2
+
3
+ const minimumDimension = 2;
4
+ const maximumDimension = 24;
5
+
6
+ type ChessBoardGridCell = ChessBoardCell & {
7
+ readonly height: 1;
8
+ readonly id: string;
9
+ readonly width: 1;
10
+ readonly x: number;
11
+ readonly y: number;
12
+ };
13
+
14
+ /*** Creates bounded GridView cells whose coordinates represent the requested chess orientation. */
15
+ export function createChessBoardCells(
16
+ columns: number,
17
+ rows: number,
18
+ orientation: ChessBoardOrientation,
19
+ ): readonly ChessBoardGridCell[] {
20
+ validateChessBoardDimensions(columns, rows);
21
+
22
+ return Array.from({ length: rows }, (_, rowIndex) =>
23
+ Array.from({ length: columns }, (_, columnIndex) => {
24
+ const column = columnIndex + 1;
25
+ const row = rowIndex + 1;
26
+
27
+ return {
28
+ column,
29
+ height: 1 as const,
30
+ id: `${column}:${row}`,
31
+ row,
32
+ width: 1 as const,
33
+ x: orientation === 'white' ? columnIndex : columns - column,
34
+ y: orientation === 'white' ? rows - row : rowIndex,
35
+ };
36
+ }),
37
+ ).flat();
38
+ }
39
+
40
+ /*** Rejects dimensions outside the presentation contract before GridView receives them. */
41
+ function validateChessBoardDimensions(columns: number, rows: number): void {
42
+ if (
43
+ ![columns, rows].every(
44
+ (dimension) =>
45
+ Number.isInteger(dimension) &&
46
+ dimension >= minimumDimension &&
47
+ dimension <= maximumDimension,
48
+ )
49
+ ) {
50
+ throw new RangeError(
51
+ `ChessBoard dimensions must be whole numbers from ${minimumDimension} through ${maximumDimension}.`,
52
+ );
53
+ }
54
+ }
@@ -32,17 +32,13 @@ test('Chess and Tabletop implementation modules own one matching runtime export
32
32
  );
33
33
  return [];
34
34
  });
35
- const expectedExports =
36
- name === 'chessEngine.ts'
37
- ? ['getLegalTargets', 'readChessPieces', 'tryMove']
38
- : [parse(name).name];
39
- expect(runtimeExports.sort(), join(directory, name)).toEqual(expectedExports.sort());
35
+ expect(runtimeExports.sort(), join(directory, name)).toEqual([parse(name).name]);
40
36
  }
41
37
  }
42
38
  }
43
39
  });
44
40
 
45
- test('Chess and Tabletop source graphs depend only on their intentional runtime owners', () => {
41
+ test('Chess and Tabletop source graphs depend only on their intentional presentation owners', () => {
46
42
  const sourcePaths = featureRoots.flatMap((featureRoot) => {
47
43
  const visit = (directory: string): string[] =>
48
44
  readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
@@ -67,7 +63,7 @@ test('Chess and Tabletop source graphs depend only on their intentional runtime
67
63
  for (const specifier of imports) {
68
64
  if (specifier.startsWith('.')) continue;
69
65
  expect(
70
- ['react', 'react-native', 'chess.js', '@ankhorage/color-theory'],
66
+ ['react', 'react-native', '@ankhorage/color-theory'],
71
67
  `${path}: ${specifier}`,
72
68
  ).toContain(specifier);
73
69
  }
@@ -382,7 +382,18 @@ describe('ZORA_COMPONENT_META invariants', () => {
382
382
  });
383
383
  expect(ZORA_COMPONENT_META.ChessBoard.bindings?.props?.legalTargets?.value).toEqual({
384
384
  type: 'array',
385
- itemType: 'string',
385
+ itemType: 'object',
386
+ fields: [
387
+ { path: '[].column', type: 'number', label: 'Column' },
388
+ { path: '[].row', type: 'number', label: 'Row' },
389
+ ],
390
+ });
391
+ expect(ZORA_COMPONENT_META.ChessBoard.bindings?.props?.selectedCell?.value).toEqual({
392
+ type: 'object',
393
+ fields: [
394
+ { path: 'column', type: 'number', label: 'Column' },
395
+ { path: 'row', type: 'number', label: 'Row' },
396
+ ],
386
397
  });
387
398
  expect(ZORA_COMPONENT_META.OpeningBook.bindings?.props?.moves?.value).toEqual({
388
399
  type: 'array',
package/src/readerFree.ts CHANGED
@@ -119,18 +119,17 @@ export type {
119
119
  } from './features/chat/public';
120
120
  export { ChatListItem, MessageBubble } from './features/chat/public';
121
121
  export type {
122
+ ChessBoardCell,
122
123
  ChessBoardColorOverrides,
123
124
  ChessBoardColorScheme,
125
+ ChessBoardDimensions,
124
126
  ChessBoardOrientation,
125
127
  ChessBoardProps,
126
128
  ChessMoveAttempt,
127
- ChessMoveResult,
128
129
  ChessPieceCode,
129
130
  ChessPieceRenderContext,
130
131
  ChessPieceRenderer,
131
132
  ChessPieceState,
132
- ChessPromotionPiece,
133
- ChessSquareId,
134
133
  OpeningBookColorOverrides,
135
134
  OpeningBookColorScheme,
136
135
  OpeningBookMove,
@@ -138,18 +137,7 @@ export type {
138
137
  } from './features/chess/public';
139
138
  export type { ChessColorThemeShape } from './features/chess/public';
140
139
  export { ChessBoard, chessBoardMeta, OpeningBook, openingBookMeta } from './features/chess/public';
141
- export {
142
- chessSquares,
143
- createBoardSquares,
144
- createChessBoardColorScheme,
145
- createOpeningBookColorScheme,
146
- getLegalTargets,
147
- getSquareFile,
148
- getSquareRank,
149
- isLightSquare,
150
- readChessPieces,
151
- tryMove,
152
- } from './features/chess/public';
140
+ export { createChessBoardColorScheme, createOpeningBookColorScheme } from './features/chess/public';
153
141
  export type { ChipProps } from './features/chip/public';
154
142
  export type { ChipGroupItem, ChipGroupProps } from './features/chip/public';
155
143
  export { Chip } from './features/chip/public';
@@ -8,7 +8,8 @@ import type {
8
8
 
9
9
  export type ZoraComponentCategory = 'foundation' | 'component' | 'pattern' | 'layout';
10
10
 
11
- export type ZoraComponentPropType = UiComponentPropType;
11
+ /** ZORA authoring additionally describes serializable object-shaped values. */
12
+ export type ZoraComponentPropType = UiComponentPropType | 'object';
12
13
 
13
14
  export type ZoraComponentPropValue =
14
15
  | string
@@ -4,33 +4,36 @@ import type { ZoraBaseProps } from './base';
4
4
 
5
5
  export type ChessBoardOrientation = 'white' | 'black';
6
6
  export type ChessPieceCode = string;
7
- export type ChessSquareId =
8
- `${'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h'}${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8}`;
9
- export type ChessPromotionPiece = 'q' | 'r' | 'b' | 'n';
10
7
 
11
- export interface ChessMoveAttempt {
12
- readonly from: ChessSquareId;
13
- readonly to: ChessSquareId;
14
- readonly promotion?: ChessPromotionPiece;
8
+ /** A caller-owned cell location in a rectangular chess presentation board. */
9
+ export interface ChessBoardCell {
10
+ readonly column: number;
11
+ readonly row: number;
15
12
  }
16
13
 
17
- export interface ChessMoveResult extends Omit<ChessMoveAttempt, 'promotion'> {
18
- readonly fen: string;
19
- readonly lan: string;
20
- readonly promotion?: ChessPromotionPiece;
21
- readonly san: string;
14
+ /** The bounded presentation dimensions supported by ChessBoard. */
15
+ export interface ChessBoardDimensions {
16
+ readonly columns: number;
17
+ readonly rows: number;
18
+ }
19
+
20
+ export interface ChessMoveAttempt {
21
+ readonly from: ChessBoardCell;
22
+ readonly to: ChessBoardCell;
22
23
  }
23
24
 
24
25
  export interface ChessPieceState {
25
26
  readonly color: 'black' | 'white';
26
27
  readonly piece: ChessPieceCode;
27
- readonly square: ChessSquareId;
28
+ readonly cell: ChessBoardCell;
28
29
  }
29
30
 
30
31
  export interface ChessPieceRenderContext {
31
32
  readonly color: string;
32
33
  readonly piece: ChessPieceCode;
33
- readonly square: ChessSquareId;
34
+ readonly cell: ChessBoardCell;
35
+ /** Available cell edge length in pixels. */
36
+ readonly size: number;
34
37
  }
35
38
 
36
39
  export type ChessPieceRenderer = (context: ChessPieceRenderContext) => React.ReactNode;
@@ -65,20 +68,24 @@ export interface OpeningBookColorScheme {
65
68
  export type OpeningBookColorOverrides = Partial<OpeningBookColorScheme>;
66
69
 
67
70
  export interface ChessBoardProps extends ZoraBaseProps {
68
- readonly fen?: string;
71
+ /** Number of displayed columns, from 2 through 24. */
72
+ readonly columns?: number;
73
+ /** Number of displayed rows, from 2 through 24. */
74
+ readonly rows?: number;
69
75
  readonly pieces?: readonly ChessPieceState[];
70
76
  readonly orientation?: ChessBoardOrientation;
71
- readonly selectedSquare?: ChessSquareId | null;
72
- readonly legalTargets?: readonly ChessSquareId[];
77
+ readonly selectedCell?: ChessBoardCell | null;
78
+ readonly legalTargets?: readonly ChessBoardCell[];
73
79
  readonly lastMove?: ChessMoveAttempt | null;
74
80
  readonly disabled?: boolean;
75
81
  readonly showCoordinates?: boolean;
76
- readonly validateMoves?: boolean;
82
+ /** Enables explicit editor resize controls when a dimensions callback is supplied. */
83
+ readonly resizable?: boolean;
77
84
  readonly colorScheme?: ChessBoardColorOverrides;
78
- readonly onSquarePress?: (square: ChessSquareId) => void;
85
+ readonly onCellPress?: (cell: ChessBoardCell) => void;
79
86
  readonly onMoveAttempt?: (move: ChessMoveAttempt) => void;
80
- readonly onLegalMove?: (move: ChessMoveResult) => void;
81
- readonly onInvalidMove?: (move: ChessMoveAttempt) => void;
87
+ /** Receives a caller-owned resize proposal; ZORA never mutates board dimensions. */
88
+ readonly onDimensionsChange?: (dimensions: ChessBoardDimensions) => void;
82
89
  readonly renderPiece?: ChessPieceRenderer;
83
90
  }
84
91