@dxos/plugin-chess 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d

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 (107) hide show
  1. package/dist/lib/browser/{ChessboardContainer-HBHUXBG3.mjs → ChessboardContainer-5YXEM4VR.mjs} +20 -20
  2. package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-Y5Y4YGNL.mjs +11 -0
  4. package/dist/lib/browser/{chunk-VTIITHYS.mjs → chunk-3LPE2B5J.mjs} +30 -14
  5. package/dist/lib/browser/chunk-3LPE2B5J.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-UDWRTBWA.mjs → chunk-5DOZV3PW.mjs} +113 -143
  7. package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-T275KG4U.mjs → chunk-CCF24VRU.mjs} +13 -14
  9. package/dist/lib/browser/chunk-CCF24VRU.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-PE3IWOFR.mjs → chunk-DUO4WTAM.mjs} +5 -5
  11. package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-H65TQTPW.mjs → chunk-Q5TZCIH7.mjs} +2 -2
  13. package/dist/lib/browser/index.mjs +30 -29
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-resolver-DA5H5633.mjs → intent-resolver-KPGHK5JU.mjs} +5 -5
  16. package/dist/lib/browser/{intent-resolver-DA5H5633.mjs.map → intent-resolver-KPGHK5JU.mjs.map} +1 -1
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/{react-surface-FSDNVKZN.mjs → react-surface-3YST34QI.mjs} +7 -7
  19. package/dist/lib/browser/{react-surface-FSDNVKZN.mjs.map → react-surface-3YST34QI.mjs.map} +1 -1
  20. package/dist/lib/browser/types/index.mjs +2 -2
  21. package/dist/lib/node-esm/{ChessboardContainer-PF75AEMW.mjs → ChessboardContainer-7OQ6TOKB.mjs} +20 -20
  22. package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +7 -0
  23. package/dist/lib/node-esm/blueprint-definition-GR6OLMB6.mjs +12 -0
  24. package/dist/lib/node-esm/{chunk-3NZRGOSV.mjs → chunk-F3HFLDV5.mjs} +30 -14
  25. package/dist/lib/node-esm/chunk-F3HFLDV5.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-PIRITYWV.mjs → chunk-F4C2HVZL.mjs} +113 -143
  27. package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-6OWCPDUA.mjs → chunk-KNOOJFIR.mjs} +5 -5
  29. package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-5DYLCQBR.mjs → chunk-QKXLEJNZ.mjs} +13 -14
  31. package/dist/lib/node-esm/chunk-QKXLEJNZ.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-IFDV434X.mjs → chunk-VVXTAVIS.mjs} +2 -2
  33. package/dist/lib/node-esm/index.mjs +30 -29
  34. package/dist/lib/node-esm/index.mjs.map +3 -3
  35. package/dist/lib/node-esm/{intent-resolver-PODONUD3.mjs → intent-resolver-ZAELGF7I.mjs} +5 -5
  36. package/dist/lib/node-esm/{intent-resolver-PODONUD3.mjs.map → intent-resolver-ZAELGF7I.mjs.map} +1 -1
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/{react-surface-2TW3PIGQ.mjs → react-surface-KV2KBSIU.mjs} +7 -7
  39. package/dist/lib/node-esm/{react-surface-2TW3PIGQ.mjs.map → react-surface-KV2KBSIU.mjs.map} +1 -1
  40. package/dist/lib/node-esm/types/index.mjs +2 -2
  41. package/dist/types/src/ChessPlugin.d.ts +1 -1
  42. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  43. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
  44. package/dist/types/src/capabilities/blueprint-definition.d.ts +2 -2
  45. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  46. package/dist/types/src/components/Card.stories.d.ts +11 -3
  47. package/dist/types/src/components/Card.stories.d.ts.map +1 -1
  48. package/dist/types/src/components/Chessboard.d.ts +11 -12
  49. package/dist/types/src/components/Chessboard.d.ts.map +1 -1
  50. package/dist/types/src/components/Chessboard.stories.d.ts +14 -9
  51. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
  52. package/dist/types/src/components/ChessboardArticle.d.ts +2 -1
  53. package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -1
  54. package/dist/types/src/components/{ChessboardInfo.d.ts → Info.d.ts} +5 -5
  55. package/dist/types/src/components/Info.d.ts.map +1 -0
  56. package/dist/types/src/functions/create.d.ts +2 -2
  57. package/dist/types/src/functions/create.d.ts.map +1 -1
  58. package/dist/types/src/functions/move.d.ts +1 -1
  59. package/dist/types/src/functions/move.d.ts.map +1 -1
  60. package/dist/types/src/functions/play.d.ts +2 -1
  61. package/dist/types/src/functions/play.d.ts.map +1 -1
  62. package/dist/types/src/meta.d.ts +0 -1
  63. package/dist/types/src/meta.d.ts.map +1 -1
  64. package/dist/types/src/translations.d.ts +9 -6
  65. package/dist/types/src/translations.d.ts.map +1 -1
  66. package/dist/types/src/types/Chess.d.ts +3 -3
  67. package/dist/types/src/types/Chess.d.ts.map +1 -1
  68. package/dist/types/src/types/ChessAction.d.ts +1 -1
  69. package/dist/types/src/types/ChessAction.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +42 -36
  72. package/src/ChessPlugin.tsx +45 -51
  73. package/src/capabilities/artifact-definition.ts +3 -2
  74. package/src/capabilities/blueprint-definition.ts +3 -3
  75. package/src/components/Card.stories.tsx +3 -5
  76. package/src/components/Chessboard.stories.tsx +3 -4
  77. package/src/components/Chessboard.tsx +79 -55
  78. package/src/components/ChessboardArticle.tsx +22 -18
  79. package/src/components/ChessboardContainer.tsx +1 -1
  80. package/src/components/{ChessboardInfo.tsx → Info.tsx} +103 -40
  81. package/src/functions/create.ts +4 -2
  82. package/src/functions/move.ts +4 -2
  83. package/src/functions/play.ts +13 -3
  84. package/src/meta.ts +4 -4
  85. package/src/translations.ts +9 -6
  86. package/src/types/Chess.ts +20 -28
  87. package/src/types/ChessAction.ts +1 -1
  88. package/dist/lib/browser/ChessboardContainer-HBHUXBG3.mjs.map +0 -7
  89. package/dist/lib/browser/blueprint-definition-W5PLLXPP.mjs +0 -11
  90. package/dist/lib/browser/chunk-PE3IWOFR.mjs.map +0 -7
  91. package/dist/lib/browser/chunk-T275KG4U.mjs.map +0 -7
  92. package/dist/lib/browser/chunk-UDWRTBWA.mjs.map +0 -7
  93. package/dist/lib/browser/chunk-VTIITHYS.mjs.map +0 -7
  94. package/dist/lib/node-esm/ChessboardContainer-PF75AEMW.mjs.map +0 -7
  95. package/dist/lib/node-esm/blueprint-definition-PR5YZC6M.mjs +0 -12
  96. package/dist/lib/node-esm/chunk-3NZRGOSV.mjs.map +0 -7
  97. package/dist/lib/node-esm/chunk-5DYLCQBR.mjs.map +0 -7
  98. package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +0 -7
  99. package/dist/lib/node-esm/chunk-PIRITYWV.mjs.map +0 -7
  100. package/dist/types/src/components/ChessboardInfo.d.ts.map +0 -1
  101. package/dist/types/src/components/ChessboardPlayers.d.ts +0 -8
  102. package/dist/types/src/components/ChessboardPlayers.d.ts.map +0 -1
  103. package/src/components/ChessboardPlayers.tsx +0 -98
  104. /package/dist/lib/browser/{blueprint-definition-W5PLLXPP.mjs.map → blueprint-definition-Y5Y4YGNL.mjs.map} +0 -0
  105. /package/dist/lib/browser/{chunk-H65TQTPW.mjs.map → chunk-Q5TZCIH7.mjs.map} +0 -0
  106. /package/dist/lib/node-esm/{blueprint-definition-PR5YZC6M.mjs.map → blueprint-definition-GR6OLMB6.mjs.map} +0 -0
  107. /package/dist/lib/node-esm/{chunk-IFDV434X.mjs.map → chunk-VVXTAVIS.mjs.map} +0 -0
@@ -2,9 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
5
+ import React, { type JSX, type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
6
6
 
7
- import { Icon, IconButton, type ThemedClassName, useTranslation } from '@dxos/react-ui';
7
+ import { generateName } from '@dxos/display-name';
8
+ import { type SpaceMember, getSpace, useMembers } from '@dxos/react-client/echo';
9
+ import { Icon, IconButton, Select, type ThemedClassName, useTranslation } from '@dxos/react-ui';
8
10
  import { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';
9
11
  import { mx } from '@dxos/react-ui-theme';
10
12
 
@@ -12,7 +14,7 @@ import { meta } from '../meta';
12
14
 
13
15
  import { type ExtendedChessModel } from './Chessboard';
14
16
 
15
- export type ChessboardInfoProps = ThemedClassName<
17
+ export type InfoProps = ThemedClassName<
16
18
  {
17
19
  orientation?: Player;
18
20
  onOrientationChange?: (orientation: Player) => void;
@@ -20,50 +22,71 @@ export type ChessboardInfoProps = ThemedClassName<
20
22
  } & Pick<HistoryProps, 'min' | 'max' | 'onSelect'>
21
23
  >;
22
24
 
23
- export const ChessboardInfo = ({
24
- classNames,
25
- orientation = 'white',
26
- onOrientationChange,
27
- onClose,
28
- ...props
29
- }: ChessboardInfoProps) => {
25
+ export const Info = ({ classNames, orientation = 'white', onOrientationChange, onClose, ...props }: InfoProps) => {
30
26
  const { t } = useTranslation(meta.id);
31
- const { model } = useGameboardContext<ExtendedChessModel>(ChessboardInfo.displayName);
27
+ const { model } = useGameboardContext<ExtendedChessModel>(Info.displayName);
28
+ const members = useMembers(getSpace(model.object)?.key);
32
29
 
33
30
  return (
34
31
  <div
35
32
  className={mx(
36
- 'grid grid-rows-[min-content_1fr_min-content] is-full min-is-[16rem] p-2 overflow-hidden bg-inputSurface rounded',
33
+ 'grid grid-rows-[min-content_1fr_min-content] is-full min-is-[18rem] p-2 overflow-hidden bg-groupSurface rounded-sm',
37
34
  classNames,
38
35
  )}
39
36
  >
40
37
  <PlayerIndicator
41
38
  model={model}
42
39
  player={orientation === 'white' ? 'black' : 'white'}
43
- title={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
40
+ icon={
41
+ onClose && (
42
+ <IconButton icon='ph--x--regular' iconOnly label={t('close info button')} size={4} onClick={onClose} />
43
+ )
44
+ }
44
45
  >
45
- {onClose && <IconButton icon='ph--x--regular' iconOnly label={t('button flip')} size={4} onClick={onClose} />}
46
+ <PlayerSelector
47
+ value={model.object.players?.[orientation === 'white' ? 'black' : 'white']}
48
+ onValueChange={(value) => {
49
+ model.object.players![orientation === 'white' ? 'black' : 'white'] = value;
50
+ }}
51
+ members={members}
52
+ />
46
53
  </PlayerIndicator>
47
54
 
48
55
  <History model={model} {...props} />
49
56
 
50
- <PlayerIndicator model={model} player={orientation} title={model.object.players?.[orientation]}>
51
- {onOrientationChange && (
52
- <IconButton
53
- icon='ph--arrows-down-up--regular'
54
- iconOnly
55
- label={t('button flip')}
56
- size={6}
57
- classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}
58
- onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}
59
- />
60
- )}
57
+ <PlayerIndicator
58
+ model={model}
59
+ player={orientation}
60
+ icon={
61
+ onOrientationChange && (
62
+ <IconButton
63
+ classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}
64
+ icon='ph--arrows-clockwise--regular'
65
+ iconOnly
66
+ label={t('flip board button')}
67
+ size={4}
68
+ onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}
69
+ />
70
+ )
71
+ }
72
+ >
73
+ <PlayerSelector
74
+ value={model.object.players?.[orientation]}
75
+ onValueChange={(value) => {
76
+ model.object.players![orientation] = value;
77
+ }}
78
+ members={members}
79
+ />
61
80
  </PlayerIndicator>
62
81
  </div>
63
82
  );
64
83
  };
65
84
 
66
- ChessboardInfo.displayName = 'Chessboard.Info';
85
+ Info.displayName = 'Chessboard.Info';
86
+
87
+ //
88
+ // History
89
+ //
67
90
 
68
91
  type HistoryProps = ThemedClassName<{
69
92
  model: ExtendedChessModel;
@@ -76,12 +99,12 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
76
99
  const { t } = useTranslation(meta.id);
77
100
  const label = model.game.isGameOver()
78
101
  ? model.game.isCheckmate()
79
- ? t('game.checkmate')
102
+ ? t('game.checkmate label')
80
103
  : model.game.isStalemate()
81
- ? t('game.stalemate')
82
- : t('game.draw')
104
+ ? t('game.stalemate label')
105
+ : t('game.draw label')
83
106
  : model.game.isCheck()
84
- ? t('game.check')
107
+ ? t('game.check label')
85
108
  : undefined;
86
109
 
87
110
  const history = model.game.history();
@@ -116,7 +139,7 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
116
139
  return (
117
140
  <div
118
141
  ref={scrollerRef}
119
- className={mx('overflow-y-scroll', classNames)}
142
+ className={mx('overflow-y-auto', classNames)}
120
143
  style={{
121
144
  minHeight: min === undefined ? 'auto' : `${min * 24}px`,
122
145
  maxHeight: max === undefined ? 'auto' : `${max * 24}px`,
@@ -150,15 +173,20 @@ const History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {
150
173
  );
151
174
  };
152
175
 
153
- const PlayerIndicator = ({
154
- children,
155
- model,
156
- player,
157
- title,
158
- }: PropsWithChildren<{ model: ExtendedChessModel; player: Player; title?: string }>) => {
176
+ //
177
+ // PlayerIndicator
178
+ //
179
+
180
+ type PlayerIndicatorProps = PropsWithChildren<{
181
+ model: ExtendedChessModel;
182
+ player: Player;
183
+ icon?: JSX.Element;
184
+ }>;
185
+
186
+ const PlayerIndicator = ({ children, model, player, icon }: PlayerIndicatorProps) => {
159
187
  const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');
160
188
  return (
161
- <div className='grid grid-cols-[2rem_1fr_2rem] gap-1 bs-[--rail-size] pis-1 pie-1 flex items-center overflow-hidden'>
189
+ <div className='grid grid-cols-[2rem_1fr_2rem] gap-2 bs-[--rail-size] pli-1 flex items-center overflow-hidden'>
162
190
  <div className='place-items-center'>
163
191
  <Icon
164
192
  icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}
@@ -166,8 +194,43 @@ const PlayerIndicator = ({
166
194
  classNames={mx(turn && (model.game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}
167
195
  />
168
196
  </div>
169
- <div className='truncate'>{title}</div>
170
- {children}
197
+ <div className='truncate overflow-hidden items-center'>{children}</div>
198
+ {icon}
171
199
  </div>
172
200
  );
173
201
  };
202
+
203
+ //
204
+ // PlayerSelector
205
+ //
206
+
207
+ type PlayerSelectorProps = {
208
+ value?: string;
209
+ onValueChange: (player: string) => void;
210
+ members: SpaceMember[];
211
+ };
212
+
213
+ const PlayerSelector = ({ value, onValueChange, members }: PlayerSelectorProps) => {
214
+ const { t } = useTranslation(meta.id);
215
+ return (
216
+ <Select.Root value={value} onValueChange={onValueChange}>
217
+ <Select.TriggerButton placeholder={t('select player button')} />
218
+ <Select.Portal>
219
+ <Select.Content>
220
+ <Select.Viewport>
221
+ {members.map((member) => {
222
+ const memberKey = member.identity.identityKey.toHex();
223
+ const displayName = member.identity?.profile?.displayName || generateName(memberKey);
224
+ return (
225
+ <Select.Option key={memberKey} value={memberKey}>
226
+ {displayName}
227
+ </Select.Option>
228
+ );
229
+ })}
230
+ </Select.Viewport>
231
+ <Select.Arrow />
232
+ </Select.Content>
233
+ </Select.Portal>
234
+ </Select.Root>
235
+ );
236
+ };
@@ -2,14 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Effect, Schema } from 'effect';
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
6
7
 
7
8
  import { DatabaseService, defineFunction } from '@dxos/functions';
8
9
 
9
10
  import { Chess } from '../types';
10
11
 
11
12
  export default defineFunction({
12
- name: 'dxos.org/function/chess/create',
13
+ key: 'dxos.org/function/chess/create',
14
+ name: 'Create Chess',
13
15
  description: 'Creates a new chess game.',
14
16
  inputSchema: Schema.Struct({
15
17
  pgn: Schema.optional(
@@ -3,7 +3,8 @@
3
3
  //
4
4
 
5
5
  import { Chess as ChessJS } from 'chess.js';
6
- import { Effect, Schema } from 'effect';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Schema from 'effect/Schema';
7
8
 
8
9
  import { ArtifactId } from '@dxos/assistant';
9
10
  import { DatabaseService, defineFunction } from '@dxos/functions';
@@ -11,7 +12,8 @@ import { DatabaseService, defineFunction } from '@dxos/functions';
11
12
  import { Chess } from '../types';
12
13
 
13
14
  export default defineFunction({
14
- name: 'dxos.org/function/chess/move',
15
+ key: 'dxos.org/function/chess/move',
16
+ name: 'Move',
15
17
  description: 'Makes a move in the given chess game.',
16
18
  inputSchema: Schema.Struct({
17
19
  id: ArtifactId.annotations({
@@ -3,7 +3,8 @@
3
3
  //
4
4
 
5
5
  import { Chess as ChessJS } from 'chess.js';
6
- import { Effect, Schema } from 'effect';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Schema from 'effect/Schema';
7
8
 
8
9
  import { ArtifactId } from '@dxos/assistant';
9
10
  import { DatabaseService, defineFunction } from '@dxos/functions';
@@ -11,12 +12,17 @@ import { DatabaseService, defineFunction } from '@dxos/functions';
11
12
  import { Chess } from '../types';
12
13
 
13
14
  export default defineFunction({
14
- name: 'dxos.org/function/chess/play',
15
+ key: 'dxos.org/function/chess/play',
16
+ name: 'Play',
15
17
  description: 'Uses the chess engine to play the next move.',
16
18
  inputSchema: Schema.Struct({
17
19
  id: ArtifactId.annotations({
18
20
  description: 'The ID of the chess object.',
19
21
  }),
22
+ side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
23
+ description: 'The side to play.',
24
+ defaultValue: 'any',
25
+ }),
20
26
  }),
21
27
  outputSchema: Schema.Struct({
22
28
  pgn: Schema.String.annotations({
@@ -26,7 +32,7 @@ export default defineFunction({
26
32
  description: 'The move that was played.',
27
33
  }),
28
34
  }),
29
- handler: Effect.fn(function* ({ data: { id } }) {
35
+ handler: Effect.fn(function* ({ data: { id, side = 'any' } }) {
30
36
  const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);
31
37
  const chess = new ChessJS();
32
38
  if (object.pgn) {
@@ -35,6 +41,10 @@ export default defineFunction({
35
41
  chess.load(object.fen);
36
42
  }
37
43
 
44
+ if (!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))) {
45
+ return { move: undefined, pgn: object.pgn! };
46
+ }
47
+
38
48
  const moves = chess.moves();
39
49
  const move = moves[Math.floor(Math.random() * moves.length)];
40
50
 
package/src/meta.ts CHANGED
@@ -5,15 +5,15 @@
5
5
  import { type PluginMeta } from '@dxos/app-framework';
6
6
  import { trim } from '@dxos/util';
7
7
 
8
- export const CHESS_PLUGIN = 'dxos.org/plugin/chess';
9
-
10
8
  export const meta: PluginMeta = {
11
- id: CHESS_PLUGIN,
9
+ id: 'dxos.org/plugin/chess',
12
10
  name: 'Chess',
13
11
  description: trim`
14
- Play chess with friends or practice with the AI.
12
+ Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
13
+ Track game history and analyze moves in real-time.
15
14
  `,
16
15
  icon: 'ph--shield-chevron--regular',
16
+ iconHue: 'amber',
17
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',
18
18
  screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],
19
19
  };
@@ -18,16 +18,19 @@ export const translations = [
18
18
  'object name placeholder': 'New game',
19
19
  'rename object label': 'Rename game',
20
20
  'delete object label': 'Delete game',
21
- 'button toggle info': 'Toggle info',
22
- 'button flip': 'Flip board',
21
+ 'object deleted label': 'Game deleted',
23
22
  },
24
23
  [meta.id]: {
25
24
  'plugin name': 'Chess',
26
25
  'delete game label': 'Delete',
27
- 'game.checkmate': 'Checkmate',
28
- 'game.stalemate': 'Stalemate',
29
- 'game.draw': 'Draw',
30
- 'game.check': 'Check',
26
+ 'game.checkmate label': 'Checkmate',
27
+ 'game.stalemate label': 'Stalemate',
28
+ 'game.draw label': 'Draw',
29
+ 'game.check label': 'Check',
30
+ 'select player button': 'Select player',
31
+ 'toggle info button': 'Toggle info',
32
+ 'close info button': 'Close info',
33
+ 'flip board button': 'Flip board',
31
34
  },
32
35
  },
33
36
  },
@@ -3,46 +3,38 @@
3
3
  //
4
4
 
5
5
  import { Chess as ChessJS } from 'chess.js';
6
- import { Schema } from 'effect';
6
+ import * as Schema from 'effect/Schema';
7
7
 
8
8
  import { Obj, Type } from '@dxos/echo';
9
- import { LabelAnnotation } from '@dxos/echo-schema';
9
+ import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
10
10
  import { log } from '@dxos/log';
11
- import { ItemAnnotation } from '@dxos/schema';
12
11
 
13
12
  export const Game = Schema.Struct({
14
13
  name: Schema.optional(Schema.String),
15
- players: Schema.optional(
16
- Schema.Struct({
17
- white: Schema.optional(
18
- Schema.String.annotations({
19
- description: 'DID of white player',
20
- }),
21
- ),
22
- black: Schema.optional(
23
- Schema.String.annotations({
24
- description: 'DID of black player',
25
- }),
26
- ),
27
- }).pipe(Schema.mutable),
28
- ),
29
- pgn: Schema.optional(
30
- Schema.String.annotations({
31
- description: 'Portable Game Notation.',
32
- }),
33
- ),
34
- fen: Schema.optional(
35
- Schema.String.annotations({
36
- description: 'Forsyth-Edwards Notation.',
37
- }),
38
- ),
14
+ players: Schema.Struct({
15
+ white: Schema.optional(
16
+ Schema.String.annotations({
17
+ description: 'DID of white player',
18
+ }),
19
+ ),
20
+ black: Schema.optional(
21
+ Schema.String.annotations({
22
+ description: 'DID of black player',
23
+ }),
24
+ ),
25
+ }).pipe(Schema.mutable, FormInputAnnotation.set(false), Schema.optional),
26
+ pgn: Schema.String.annotations({
27
+ description: 'Portable Game Notation.',
28
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
29
+ fen: Schema.String.annotations({
30
+ description: 'Forsyth-Edwards Notation.',
31
+ }).pipe(FormInputAnnotation.set(false), Schema.optional),
39
32
  }).pipe(
40
33
  Type.Obj({
41
34
  typename: 'dxos.org/type/Chess',
42
35
  version: '0.2.0',
43
36
  }),
44
37
  LabelAnnotation.set(['name']),
45
- ItemAnnotation.set(true),
46
38
  );
47
39
 
48
40
  export interface Game extends Schema.Schema.Type<typeof Game> {}
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
7
  import { meta } from '../meta';
8
8
 
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ChessboardContainer.tsx", "../../../src/components/ChessboardArticle.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { type Chess } from '../types';\n\nimport { Chessboard } from './Chessboard';\nimport { ChessboardArticle } from './ChessboardArticle';\n\nexport type ChessboardContainerProps = {\n game: Chess.Game;\n role?: string;\n};\n\nexport const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n switch (role) {\n case 'card--popover':\n case 'card--intrinsic':\n case 'card--extrinsic': {\n return (\n <Chessboard.Root game={game}>\n <Chessboard.Content role={role}>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n }\n\n default: {\n return <ChessboardArticle game={game} />;\n }\n }\n};\n\nexport default ChessboardContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { IconButton, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { meta } from '../meta';\nimport { type Chess } from '../types';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';\n\nexport const ChessboardArticle = ({ game }: { game: Chess.Game }) => {\n const { t } = useTranslation(meta.id);\n const [orientation, setOrientation] = useState<Player>('white');\n const [open, setOpen] = useState(true);\n const controller = useRef<ChessboardController>(null);\n\n // TODO(burdon): Keyboard handler.\n const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {\n controller.current?.setMoveNumber(index);\n }, []);\n\n return (\n <StackItem.Content classNames='@container bs-full is-full overflow-hidden'>\n <Chessboard.Root game={game} ref={controller}>\n <div className={mx('grid grid-rows-[1fr_4rem] bs-full is-full gap-2', open && '@3xl:grid-cols-[1fr_320px]')}>\n <Chessboard.Content>\n <Chessboard.Board orientation={orientation} />\n </Chessboard.Content>\n {open && (\n <div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>\n <Chessboard.Info\n orientation={orientation}\n min={8}\n max={8}\n onOrientationChange={setOrientation}\n onClose={() => setOpen(false)}\n onSelect={handleSelect}\n />\n </div>\n )}\n <div className='flex justify-center items-center'>\n <Chessboard.Players>\n <IconButton\n variant='ghost'\n icon='ph--info--regular'\n iconOnly\n label={t('button toggle info')}\n size={6}\n classNames={mx('invisible', !open && '@3xl:visible')}\n onClick={() => setOpen((open) => !open)}\n />\n </Chessboard.Players>\n </div>\n </div>\n </Chessboard.Root>\n </StackItem.Content>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,gBAAgB;;;;ACFzB,OAAOC,SAASC,aAAaC,QAAQC,gBAAgB;AAErD,SAASC,YAAYC,sBAAsB;AAE3C,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAOZ,IAAMC,oBAAoB,CAAC,EAAEC,KAAI,MAAwB;;;AAC9D,UAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,UAAM,CAACC,aAAaC,cAAAA,IA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ClB,gBAAAG,OAAA,cAACC,WAAWG,OAAK,IAAA,CAAA,CAAA;MAIzB;MAEA,SAAS;AACP,eAAO,gBAAAJ,OAAA,cAACK,mBAAAA;UAAkBT;;MAC5B;IACF;;;;AACF;AAEA,IAAA,8BAAeD;",
6
- "names": ["React", "getSpace", "React", "useCallback", "useRef", "useState", "IconButton", "useTranslation", "StackItem", "mx", "ChessboardArticle", "game", "t", "useTranslation", "meta", "id", "orientation", "setOrientation", "useState", "open", "setOpen", "controller", "useRef", "handleSelect", "useCallback", "index", "current", "setMoveNumber", "StackItem", "Content", "classNames", "Chessboard", "Root", "ref", "div", "className", "mx", "Board", "Info", "min", "max", "onOrientationChange", "onClose", "onSelect", "Players", "IconButton", "variant", "icon", "iconOnly", "label", "size", "onClick", "ChessboardContainer", "game", "role", "space", "getSpace", "React", "Chessboard", "Root", "Content", "Board", "ChessboardArticle"]
7
- }
@@ -1,11 +0,0 @@
1
- import {
2
- BLUEPRINT_KEY,
3
- blueprint_definition_default
4
- } from "./chunk-VTIITHYS.mjs";
5
- import "./chunk-T275KG4U.mjs";
6
- import "./chunk-PE3IWOFR.mjs";
7
- export {
8
- BLUEPRINT_KEY,
9
- blueprint_definition_default as default
10
- };
11
- //# sourceMappingURL=blueprint-definition-W5PLLXPP.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const CHESS_PLUGIN = 'dxos.org/plugin/chess';\n\nexport const meta: PluginMeta = {\n id: CHESS_PLUGIN,\n name: 'Chess',\n description: trim`\n Play chess with friends or practice with the AI.\n `,\n icon: 'ph--shield-chevron--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',\n screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],\n};\n"],
5
- "mappings": ";;;;;;;AAKA,SAASA,YAAY;AAEd,IAAMC,eAAe;AAErB,IAAMC,OAAmB;EAC9BC,IAAIF;EACJG,MAAM;EACNC,aAAaC;;;EAGbC,MAAM;EACNC,QAAQ;EACRC,aAAa;IAAC;;AAChB;",
6
- "names": ["trim", "CHESS_PLUGIN", "meta", "id", "name", "description", "trim", "icon", "source", "screenshots"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/Chess.ts", "../../../src/types/ChessAction.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport { Schema } from 'effect';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { LabelAnnotation } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { ItemAnnotation } from '@dxos/schema';\n\nexport const Game = Schema.Struct({\n name: Schema.optional(Schema.String),\n players: Schema.optional(\n Schema.Struct({\n white: Schema.optional(\n Schema.String.annotations({\n description: 'DID of white player',\n }),\n ),\n black: Schema.optional(\n Schema.String.annotations({\n description: 'DID of black player',\n }),\n ),\n }).pipe(Schema.mutable),\n ),\n pgn: Schema.optional(\n Schema.String.annotations({\n description: 'Portable Game Notation.',\n }),\n ),\n fen: Schema.optional(\n Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }),\n ),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Chess',\n version: '0.2.0',\n }),\n LabelAnnotation.set(['name']),\n ItemAnnotation.set(true),\n);\n\nexport interface Game extends Schema.Schema.Type<typeof Game> {}\n\nexport const makeGame = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: string } = {}) => {\n const chess = new ChessJS();\n if (pgn) {\n try {\n chess.loadPgn(pgn);\n } catch {\n log.warn(pgn);\n }\n }\n\n return Obj.make(Game, {\n name,\n players: {},\n pgn,\n fen,\n });\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { meta } from '../meta';\n\nimport { Game } from './Chess';\n\nexport class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {\n input: Schema.Struct({\n name: Schema.optional(Schema.String),\n pgn: Schema.optional(Schema.String),\n }),\n output: Schema.Struct({\n object: Game,\n }),\n}) {}\n"],
5
- "mappings": ";;;;;;AAAA;;;;;AAIA,SAASA,SAASC,eAAe;AACjC,SAASC,cAAc;AAEvB,SAASC,KAAKC,YAAY;AAC1B,SAASC,uBAAuB;AAChC,SAASC,WAAW;AACpB,SAASC,sBAAsB;;AAExB,IAAMC,OAAON,OAAOO,OAAO;EAChCC,MAAMR,OAAOS,SAAST,OAAOU,MAAM;EACnCC,SAASX,OAAOS,SACdT,OAAOO,OAAO;IACZK,OAAOZ,OAAOS,SACZT,OAAOU,OAAOG,YAAY;MACxBC,aAAa;IACf,CAAA,CAAA;IAEFC,OAAOf,OAAOS,SACZT,OAAOU,OAAOG,YAAY;MACxBC,aAAa;IACf,CAAA,CAAA;EAEJ,CAAA,EAAGE,KAAKhB,OAAOiB,OAAO,CAAA;EAExBC,KAAKlB,OAAOS,SACVT,OAAOU,OAAOG,YAAY;IACxBC,aAAa;EACf,CAAA,CAAA;EAEFK,KAAKnB,OAAOS,SACVT,OAAOU,OAAOG,YAAY;IACxBC,aAAa;EACf,CAAA,CAAA;AAEJ,CAAA,EAAGE,KACDd,KAAKD,IAAI;EACPmB,UAAU;EACVC,SAAS;AACX,CAAA,GACAlB,gBAAgBmB,IAAI;EAAC;CAAO,GAC5BjB,eAAeiB,IAAI,IAAA,CAAA;AAKd,IAAMC,WAAW,CAAC,EAAEf,MAAMU,KAAKC,IAAG,IAAoD,CAAC,MAAC;AAC7F,QAAMK,QAAQ,IAAIzB,QAAAA;AAClB,MAAImB,KAAK;AACP,QAAI;AACFM,YAAMC,QAAQP,GAAAA;IAChB,QAAQ;AACNd,UAAIsB,KAAKR,KAAAA,QAAAA;;;;;;IACX;EACF;AAEA,SAAOjB,IAAI0B,KAAKrB,MAAM;IACpBE;IACAG,SAAS,CAAC;IACVO;IACAC;EACF,CAAA;AACF;;;ACjEA;;;;AAIA,SAASS,UAAAA,eAAc;AAMhB,IAAMC,SAAN,cAAqBC,QAAOC,YAAW,EAAW,GAAGC,KAAKC,EAAE,kBAAkB;EACnFC,OAAOJ,QAAOK,OAAO;IACnBC,MAAMN,QAAOO,SAASP,QAAOQ,MAAM;IACnCC,KAAKT,QAAOO,SAASP,QAAOQ,MAAM;EACpC,CAAA;EACAE,QAAQV,QAAOK,OAAO;IACpBM,QAAQC;EACV,CAAA;AACF,CAAA,EAAA;AAAI;",
6
- "names": ["Chess", "ChessJS", "Schema", "Obj", "Type", "LabelAnnotation", "log", "ItemAnnotation", "Game", "Struct", "name", "optional", "String", "players", "white", "annotations", "description", "black", "pipe", "mutable", "pgn", "fen", "typename", "version", "set", "makeGame", "chess", "loadPgn", "warn", "make", "Schema", "Create", "Schema", "TaggedClass", "meta", "id", "input", "Struct", "name", "optional", "String", "pgn", "output", "object", "Game"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/Chessboard.tsx", "../../../src/components/ChessboardInfo.tsx", "../../../src/components/ChessboardPlayers.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, {\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\n\nimport { addEventListener } from '@dxos/async';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport {\n ChessModel,\n Gameboard,\n type GameboardRootProps,\n Chessboard as NativeChessboard,\n type ChessboardProps as NativeChessboardProps,\n} from '@dxos/react-ui-gameboard';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { type Chess } from '../types';\n\nimport { ChessboardInfo, type ChessboardInfoProps } from './ChessboardInfo';\nimport { ChessboardPlayers, type ChessboardPlayersProps } from './ChessboardPlayers';\n\nexport interface ChessboardController {\n setMoveNumber(index: number): void;\n}\n\nexport class ExtendedChessModel extends ChessModel {\n constructor(readonly object: Chess.Game) {\n super();\n }\n}\n\n//\n// Root\n//\n\ntype ChessboardRootProps = PropsWithChildren<{\n game: Chess.Game;\n}>;\n\nconst ChessboardRoot = forwardRef<ChessboardController, ChessboardRootProps>(({ game, children }, forwardedRef) => {\n const model = useMemo(() => new ExtendedChessModel(game), []);\n\n // Controller.\n useImperativeHandle(forwardedRef, () => {\n return {\n setMoveNumber: (index) => model.setMoveIndex(index),\n };\n }, [model]);\n\n // External change.\n useEffect(() => {\n model.update(game.pgn);\n }, [game.pgn]);\n\n // Keyboard navigation.\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n if (!ref.current) {\n return;\n }\n\n return addEventListener(ref.current, 'keydown', (ev) => {\n switch (ev.key) {\n case 'ArrowUp':\n model.setMoveIndex(0);\n break;\n case 'ArrowDown':\n model.setMoveIndex(model.game.history().length);\n break;\n case 'ArrowLeft':\n if (model.moveIndex.value > 0) {\n model.setMoveIndex(model.moveIndex.value - 1);\n }\n break;\n case 'ArrowRight':\n if (model.moveIndex.value < model.game.history().length) {\n model.setMoveIndex(model.moveIndex.value + 1);\n }\n break;\n }\n });\n }, [model]);\n\n // Move.\n const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(\n (move) => {\n if (model.makeMove(move)) {\n game.pgn = model.pgn;\n return true;\n }\n\n return false;\n },\n [model],\n );\n\n return (\n <Gameboard.Root model={model} onDrop={handleDrop}>\n <div ref={ref} role='none' tabIndex={0} className='grid grow outline-none'>\n {children}\n </div>\n </Gameboard.Root>\n );\n});\n\n//\n// Content\n//\n\ntype Role = 'card--popover' | 'card--intrinsic' | 'card--extrinsic';\n\ntype ChessboardContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;\n\nconst ChessboardContent = ({ classNames, children, role }: ChessboardContentProps) => {\n return (\n <Gameboard.Content\n classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}\n grow={!role || role === 'card--extrinsic'}\n contain={!role || role === 'card--extrinsic' || role === 'card--popover'}\n >\n {children}\n </Gameboard.Content>\n );\n};\n\n//\n// Chessboard\n//\n\nexport const Chessboard = {\n Root: ChessboardRoot,\n Content: ChessboardContent,\n Board: NativeChessboard,\n Info: ChessboardInfo,\n Players: ChessboardPlayers,\n};\n\nexport type {\n ChessboardRootProps,\n ChessboardContentProps,\n NativeChessboardProps as ChessboardBoardProps,\n ChessboardInfoProps,\n ChessboardPlayersProps,\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';\n\nimport { Icon, IconButton, type ThemedClassName, useTranslation } from '@dxos/react-ui';\nimport { type Player, useGameboardContext } from '@dxos/react-ui-gameboard';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { meta } from '../meta';\n\nimport { type ExtendedChessModel } from './Chessboard';\n\nexport type ChessboardInfoProps = ThemedClassName<\n {\n orientation?: Player;\n onOrientationChange?: (orientation: Player) => void;\n onClose?: () => void;\n } & Pick<HistoryProps, 'min' | 'max' | 'onSelect'>\n>;\n\nexport const ChessboardInfo = ({\n classNames,\n orientation = 'white',\n onOrientationChange,\n onClose,\n ...props\n}: ChessboardInfoProps) => {\n const { t } = useTranslation(meta.id);\n const { model } = useGameboardContext<ExtendedChessModel>(ChessboardInfo.displayName);\n\n return (\n <div\n className={mx(\n 'grid grid-rows-[min-content_1fr_min-content] is-full min-is-[16rem] p-2 overflow-hidden bg-inputSurface rounded',\n classNames,\n )}\n >\n <PlayerIndicator\n model={model}\n player={orientation === 'white' ? 'black' : 'white'}\n title={model.object.players?.[orientation === 'white' ? 'black' : 'white']}\n >\n {onClose && <IconButton icon='ph--x--regular' iconOnly label={t('button flip')} size={4} onClick={onClose} />}\n </PlayerIndicator>\n\n <History model={model} {...props} />\n\n <PlayerIndicator model={model} player={orientation} title={model.object.players?.[orientation]}>\n {onOrientationChange && (\n <IconButton\n icon='ph--arrows-down-up--regular'\n iconOnly\n label={t('button flip')}\n size={6}\n classNames={mx('transition duration-200 ease-linear', orientation === 'white' && 'rotate-180')}\n onClick={() => onOrientationChange(orientation === 'white' ? 'black' : 'white')}\n />\n )}\n </PlayerIndicator>\n </div>\n );\n};\n\nChessboardInfo.displayName = 'Chessboard.Info';\n\ntype HistoryProps = ThemedClassName<{\n model: ExtendedChessModel;\n min?: number;\n max?: number;\n onSelect?: (index: number) => void;\n}>;\n\nconst History = ({ classNames, model, min, max, onSelect }: HistoryProps) => {\n const { t } = useTranslation(meta.id);\n const label = model.game.isGameOver()\n ? model.game.isCheckmate()\n ? t('game.checkmate')\n : model.game.isStalemate()\n ? t('game.stalemate')\n : t('game.draw')\n : model.game.isCheck()\n ? t('game.check')\n : undefined;\n\n const history = model.game.history();\n const moves = useMemo(\n () =>\n history.reduce(\n (acc, move, index) => {\n if (index % 2 === 0) {\n acc.push([{ index, move }]);\n } else {\n acc[acc.length - 1].push({ index, move });\n }\n return acc;\n },\n [] as { index: number; move: string }[][],\n ),\n [history.length],\n );\n\n const scrollerRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n scrollerRef.current?.scrollTo({ top: scrollerRef.current.scrollHeight });\n }, [history.length]);\n\n useEffect(() => {\n const div = scrollerRef.current?.querySelector(`[data-index=\"${model.moveIndex.value - 1}\"]`);\n scrollerRef.current?.classList.add('scrollbar-none');\n div?.scrollIntoView({ behavior: 'smooth' });\n scrollerRef.current?.classList.remove('scrollbar-none');\n }, [model.moveIndex.value]);\n\n return (\n <div\n ref={scrollerRef}\n className={mx('overflow-y-scroll', classNames)}\n style={{\n minHeight: min === undefined ? 'auto' : `${min * 24}px`,\n maxHeight: max === undefined ? 'auto' : `${max * 24}px`,\n }}\n >\n {moves.map(([a, b], index) => (\n <div key={index} className='grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 pis-4 leading-1'>\n <div className='content-center text-xs text-subdued'>{index + 1}</div>\n {a && (\n <div\n data-index={a.index}\n className={mx('pis-2 cursor-pointer', a.index === model.moveIndex.value - 1 && 'bg-primary-500')}\n onClick={() => onSelect?.(a.index + 1)}\n >\n {a.move}\n </div>\n )}\n {b && (\n <div\n data-index={b.index}\n className={mx('pis-2 cursor-pointer', b.index === model.moveIndex.value - 1 && 'bg-primary-500')}\n onClick={() => onSelect?.(b.index + 1)}\n >\n {b.move}\n </div>\n )}\n </div>\n ))}\n {label && <div className='text-center'>{label}</div>}\n </div>\n );\n};\n\nconst PlayerIndicator = ({\n children,\n model,\n player,\n title,\n}: PropsWithChildren<{ model: ExtendedChessModel; player: Player; title?: string }>) => {\n const turn = player === (model.game.turn() === 'w' ? 'white' : 'black');\n return (\n <div className='grid grid-cols-[2rem_1fr_2rem] gap-1 bs-[--rail-size] pis-1 pie-1 flex items-center overflow-hidden'>\n <div className='place-items-center'>\n <Icon\n icon={turn ? 'ph--circle--fill' : 'ph--circle--thin'}\n size={6}\n classNames={mx(turn && (model.game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}\n />\n </div>\n <div className='truncate'>{title}</div>\n {children}\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { type PropsWithChildren } from 'react';\n\nimport { generateName } from '@dxos/display-name';\nimport { type SpaceMember, getSpace, useMembers } from '@dxos/react-client/echo';\nimport { Icon, Input, Select, useThemeContext } from '@dxos/react-ui';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { useGameboardContext } from '@dxos/react-ui-gameboard';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { type Chess } from '../types';\n\nimport { type ExtendedChessModel } from './Chessboard';\n\nexport type ChessboardPlayersProps = ThemedClassName<PropsWithChildren>;\n\nexport const ChessboardPlayers = ({ classNames, children }: ChessboardPlayersProps) => {\n const { model } = useGameboardContext<ExtendedChessModel>(ChessboardPlayers.displayName);\n const members = useMembers(getSpace(model.object)?.key);\n const players: Chess.Game['players'] = model.object.players;\n if (!players) {\n return null;\n }\n\n return (\n <div role='none' className={mx('grid grid-cols-[1fr_min-content_1fr] pis-2 pie-2 overflow-hidden', classNames)}>\n <div role='none' className='flex flex-row-reverse items-center gap-2'>\n <PlayerSelect\n side='white'\n value={players.white}\n onValueChange={(player) => (players.white = player)}\n members={members}\n />\n </div>\n <div className='flex flex-row justify-center items-center'>{children}</div>\n <div role='none' className='flex flex-row items-center gap-2'>\n <PlayerSelect\n side='black'\n value={players.black}\n onValueChange={(player) => (players.black = player)}\n members={members}\n />\n </div>\n </div>\n );\n};\n\nChessboardPlayers.displayName = 'Chessboard.Players';\n\nconst PlayerSelect = ({\n side,\n value,\n onValueChange,\n members,\n}: {\n side: 'white' | 'black';\n value: string | undefined;\n onValueChange: (player: string) => void;\n members: SpaceMember[];\n}) => {\n const { themeMode } = useThemeContext();\n const iconFillMode =\n (side === 'black' && themeMode === 'light') || (side === 'white' && themeMode === 'dark') ? 'fill' : undefined;\n\n return (\n <Input.Root>\n <Input.Label>\n <Icon\n aria-label={`Chess icon for side ${side}`}\n icon={`ph--crown-cross--${iconFillMode || 'regular'}`}\n size={6}\n />\n </Input.Label>\n <Select.Root value={value} onValueChange={onValueChange}>\n <Select.TriggerButton placeholder={'Select player'} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {members.map((member) => {\n const memberKey = member.identity.identityKey.toHex();\n const displayName = member.identity?.profile?.displayName || generateName(memberKey);\n return (\n <Select.Option key={memberKey} value={memberKey}>\n {displayName}\n </Select.Option>\n );\n })}\n </Select.Viewport>\n <Select.Arrow />\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </Input.Root>\n );\n};\n"],
5
- "mappings": ";;;;;;AAIA,OAAOA,UAELC,YACAC,aACAC,aAAAA,YACAC,qBACAC,WAAAA,UACAC,UAAAA,eACK;AAEP,SAASC,wBAAwB;AAEjC,SACEC,YACAC,WAEAC,cAAcC,wBAET;AACP,SAASC,MAAAA,WAAU;;;;ACnBnB,OAAOC,SAAiCC,WAAWC,SAASC,cAAc;AAE1E,SAASC,MAAMC,YAAkCC,sBAAsB;AACvE,SAAsBC,2BAA2B;AACjD,SAASC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AAMH,KAAKkB,QAAO,EAAGC,MAAM;AAC9C;UACF,KAAK;AACH,gBAAIhB,MAAMiB,UAAUC,QAAQ,GAAG;AAC7BlB,oBAAMK,aAAaL,MAAMiB,UAAUC,QAAQ,CAAA;YAC7C;AACA;UACF,KAAK;AACH,gBAAIlB,MAAMiB,UAAUC,QAAQlB,MAAMH,KAAKkB,QAAO,EAAGC,QAAQ;AACvDhB,oBAAMK,aAAaL,MAAMiB,UAAUC,QAAQ,CAAA;YAC7C;AACA;QACJ;MACF,CAAA;IACF,GAAG;MAAClB;KAAM;AAGV,UAAMmB,aAAaC,YACjB,CAACC,SAAAA;AACC,UAAIrB,MAAMsB,SAASD,IAAAA,GAAO;AACxBxB,aAAKW,MAAMR,MAAMQ;AACjB,eAAO;MACT;AAEA,aAAO;IACT,GACA;MAACR;KAAM;AAGT,WACE,gBAAAuB,OAAA,cAACC,UAAUC,MAAI;MAACzB;MAAc0B,QAAQP;OACpC,gBAAAI,OAAA,cAACI,OAAAA;MAAIlB;MAAUmB,MAAK;MAAOC,UAAU;MAAGC,WAAU;OAC/ChC,QAAAA,CAAAA;;;;AAIT,CAAA;AAUA,IAAMiC,oBAAoB,CAAC,EAAEC,YAAYlC,UAAU8B,KAAI,MAA0B;;;AAC/E,WACE,gBAAAL,OAAA,cAACC,UAAUS,SAAO;MAChBD,YAAYE,IAAGF,YAAYJ,SAAS,mBAAmB,+BAAA;MACvDO,MAAM,CAACP,QAAQA,SAAS;MACxBQ,SAAS,CAACR,QAAQA,SAAS,qBAAqBA,SAAS;OAExD9B,QAAAA;;;;AAGP;AAMO,IAAMuC,aAAa;EACxBZ,MAAM9B;EACNsC,SAASF;EACTO,OAAOC;EACPC,MAAMC;EACNC,SAASC;AACX;",
6
- "names": ["React", "forwardRef", "useCallback", "useEffect", "useImperativeHandle", "useMemo", "useRef", "addEventListener", "ChessModel", "Gameboard", "Chessboard", "NativeChessboard", "mx", "React", "useEffect", "useMemo", "useRef", "Icon", "IconButton", "useTranslation", "useGameboardContext", "mx", "ChessboardInfo", "classNames", "orientation", "onOrientationChange", "onClose", "props", "t", "useTranslation", "meta", "id", "model", "useGameboardContext", "displayName", "div", "className", "mx", "PlayerIndicator", "player", "title", "object", "players", "IconButton", "icon", "iconOnly", "label", "size", "onClick", "History", "min", "max", "onSelect", "game", "isGameOver", "isCheckmate", "isStalemate", "isCheck", "undefined", "history", "moves", "useMemo", "reduce", "acc", "move", "index", "push", "length", "scrollerRef", "useRef", "useEffect", "current", "scrollTo", "top", "scrollHeight", "querySelector", "moveIndex", "value", "classList", "add", "scrollIntoView", "behavior", "remove", "ref", "style", "minHeight", "maxHeight", "map", "a", "b", "key", "data-index", "children", "turn", "Icon", "React", "generateName", "getSpace", "useMembers", "Icon", "Input", "Select", "useThemeContext", "useGameboardContext", "mx", "ChessboardPlayers", "classNames", "children", "model", "useGameboardContext", "displayName", "members", "useMembers", "getSpace", "object", "key", "players", "React", "div", "role", "className", "mx", "PlayerSelect", "side", "value", "white", "onValueChange", "player", "black", "themeMode", "useThemeContext", "iconFillMode", "undefined", "Input", "Root", "Label", "Icon", "aria-label", "icon", "size", "Select", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "map", "member", "memberKey", "identity", "identityKey", "toHex", "profile", "generateName", "Option", "Arrow", "ExtendedChessModel", "ChessModel", "object", "ChessboardRoot", "forwardRef", "game", "children", "forwardedRef", "model", "useMemo", "useImperativeHandle", "setMoveNumber", "index", "setMoveIndex", "useEffect", "update", "pgn", "ref", "useRef", "current", "addEventListener", "ev", "key", "history", "length", "moveIndex", "value", "handleDrop", "useCallback", "move", "makeMove", "React", "Gameboard", "Root", "onDrop", "div", "role", "tabIndex", "className", "ChessboardContent", "classNames", "Content", "mx", "grow", "contain", "Chessboard", "Board", "NativeChessboard", "Info", "ChessboardInfo", "Players", "ChessboardPlayers"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/capabilities/blueprint-definition.ts", "../../../src/functions/create.ts", "../../../src/functions/move.ts", "../../../src/functions/play.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, contributes } from '@dxos/app-framework';\nimport { Blueprint, Template } from '@dxos/blueprints';\nimport { type FunctionDefinition } from '@dxos/functions';\nimport { trim } from '@dxos/util';\n\nimport { create, move, play } from '../functions';\n\nexport const BLUEPRINT_KEY = 'dxos.org/blueprint/chess';\n\nconst functions: FunctionDefinition[] = [create, move, play];\n\nexport default () => {\n return [\n contributes(Capabilities.Functions, functions),\n contributes(\n Capabilities.BlueprintDefinition,\n Blueprint.make({\n key: BLUEPRINT_KEY,\n name: 'Chess',\n tools: Blueprint.toolDefinitions({ functions }),\n instructions: Template.make({\n source: trim`\n You are an expert chess player.\n To analyze a game you can access the \"pgn\" property by loading the context object that represents the current game.\n You could suggest a good next move or offer to play a move.\n Don't actually make a move unless you are asked to.\n `,\n }),\n }),\n ),\n ];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Effect, Schema } from 'effect';\n\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n name: 'dxos.org/function/chess/create',\n description: 'Creates a new chess game.',\n inputSchema: Schema.Struct({\n pgn: Schema.optional(\n Schema.String.annotations({\n description: 'Portable Game Notation.',\n }),\n ),\n fen: Schema.optional(\n Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }),\n ),\n }),\n outputSchema: Chess.Game,\n handler: Effect.fn(function* ({ data: { pgn, fen } }) {\n return yield* DatabaseService.add(Chess.makeGame({ pgn, fen }));\n }),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport { Effect, Schema } from 'effect';\n\nimport { ArtifactId } from '@dxos/assistant';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n name: 'dxos.org/function/chess/move',\n description: 'Makes a move in the given chess game.',\n inputSchema: Schema.Struct({\n id: ArtifactId.annotations({\n description: 'The ID of the chess object.',\n }),\n move: Schema.String.annotations({\n description: 'The move to make in the chess game.',\n examples: ['e4', 'Bf3'],\n }),\n }),\n outputSchema: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n }),\n handler: Effect.fn(function* ({ data: { id, move } }) {\n const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);\n const chess = new ChessJS();\n if (object.pgn) {\n chess.loadPgn(object.pgn);\n } else if (object.fen) {\n chess.load(object.fen);\n }\n\n chess.move(move, { strict: false });\n object.pgn = chess.pgn();\n return { pgn: object.pgn };\n }),\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport { Effect, Schema } from 'effect';\n\nimport { ArtifactId } from '@dxos/assistant';\nimport { DatabaseService, defineFunction } from '@dxos/functions';\n\nimport { Chess } from '../types';\n\nexport default defineFunction({\n name: 'dxos.org/function/chess/play',\n description: 'Uses the chess engine to play the next move.',\n inputSchema: Schema.Struct({\n id: ArtifactId.annotations({\n description: 'The ID of the chess object.',\n }),\n }),\n outputSchema: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n move: Schema.optional(Schema.String).annotations({\n description: 'The move that was played.',\n }),\n }),\n handler: Effect.fn(function* ({ data: { id } }) {\n const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);\n const chess = new ChessJS();\n if (object.pgn) {\n chess.loadPgn(object.pgn);\n } else if (object.fen) {\n chess.load(object.fen);\n }\n\n const moves = chess.moves();\n const move = moves[Math.floor(Math.random() * moves.length)];\n\n chess.move(move, { strict: false });\n object.pgn = chess.pgn();\n return { move, pgn: object.pgn };\n }),\n});\n"],
5
- "mappings": ";;;;;AAIA,SAASA,cAAcC,mBAAmB;AAC1C,SAASC,WAAWC,gBAAgB;AAEpC,SAASC,YAAY;;;ACHrB,SAASC,QAAQC,c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,KAAKQ,OAAOR;IAAI;EACjC,CAAA;AACF,CAAA;;;AHjCO,IAAMyB,gBAAgB;AAE7B,IAAMC,YAAkC;EAACC;EAAQC;EAAMC;;AAEvD,IAAA,+BAAe,MAAA;AACb,SAAO;IACLC,YAAYC,aAAaC,WAAWN,SAAAA;IACpCI,YACEC,aAAaE,qBACbC,UAAUC,KAAK;MACbC,KAAKX;MACLY,MAAM;MACNC,OAAOJ,UAAUK,gBAAgB;QAAEb;MAAU,CAAA;MAC7Cc,cAAcC,SAASN,KAAK;QAC1BO,QAAQC;;;;;;MAMV,CAAA;IACF,CAAA,CAAA;;AAGN;",
6
- "names": ["Capabilities", "contributes", "Blueprint", "Template", "trim", "Effect", "Schema", "DatabaseService", "defineFunction", "defineFunction", "name", "description", "inputSchema", "Schema", "Struct", "pgn", "optional", "String", "annotations", "fen", "outputSchema", "Chess", "Game", "handler", "Effect", "fn", "data", "DatabaseService", "add", "makeGame", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "DatabaseService", "defineFunction", "defineFunction", "name", "description", "inputSchema", "Schema", "Struct", "id", "ArtifactId", "annotations", "move", "String", "examples", "outputSchema", "pgn", "handler", "Effect", "fn", "data", "object", "DatabaseService", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "strict", "Chess", "ChessJS", "Effect", "Schema", "ArtifactId", "DatabaseService", "defineFunction", "defineFunction", "name", "description", "inputSchema", "Schema", "Struct", "id", "ArtifactId", "annotations", "outputSchema", "pgn", "String", "move", "optional", "handler", "Effect", "fn", "data", "object", "DatabaseService", "resolve", "toDXN", "Chess", "Game", "chess", "ChessJS", "loadPgn", "fen", "load", "moves", "Math", "floor", "random", "length", "strict", "BLUEPRINT_KEY", "functions", "create", "move", "play", "contributes", "Capabilities", "Functions", "BlueprintDefinition", "Blueprint", "make", "key", "name", "tools", "toolDefinitions", "instructions", "Template", "source", "trim"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/ChessboardContainer.tsx", "../../../src/components/ChessboardArticle.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\n\nimport { type Chess } from '../types';\n\nimport { Chessboard } from './Chessboard';\nimport { ChessboardArticle } from './ChessboardArticle';\n\nexport type ChessboardContainerProps = {\n game: Chess.Game;\n role?: string;\n};\n\nexport const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n switch (role) {\n case 'card--popover':\n case 'card--intrinsic':\n case 'card--extrinsic': {\n return (\n <Chessboard.Root game={game}>\n <Chessboard.Content role={role}>\n <Chessboard.Board />\n </Chessboard.Content>\n </Chessboard.Root>\n );\n }\n\n default: {\n return <ChessboardArticle game={game} />;\n }\n }\n};\n\nexport default ChessboardContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useRef, useState } from 'react';\n\nimport { IconButton, useTranslation } from '@dxos/react-ui';\nimport { type Player } from '@dxos/react-ui-gameboard';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { meta } from '../meta';\nimport { type Chess } from '../types';\n\nimport { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';\n\nexport const ChessboardArticle = ({ game }: { game: Chess.Game }) => {\n const { t } = useTranslation(meta.id);\n const [orientation, setOrientation] = useState<Player>('white');\n const [open, setOpen] = useState(true);\n const controller = useRef<ChessboardController>(null);\n\n // TODO(burdon): Keyboard handler.\n const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {\n controller.current?.setMoveNumber(index);\n }, []);\n\n return (\n <StackItem.Content classNames='@container bs-full is-full overflow-hidden'>\n <Chessboard.Root game={game} ref={controller}>\n <div className={mx('grid grid-rows-[1fr_4rem] bs-full is-full gap-2', open && '@3xl:grid-cols-[1fr_320px]')}>\n <Chessboard.Content>\n <Chessboard.Board orientation={orientation} />\n </Chessboard.Content>\n {open && (\n <div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>\n <Chessboard.Info\n orientation={orientation}\n min={8}\n max={8}\n onOrientationChange={setOrientation}\n onClose={() => setOpen(false)}\n onSelect={handleSelect}\n />\n </div>\n )}\n <div className='flex justify-center items-center'>\n <Chessboard.Players>\n <IconButton\n variant='ghost'\n icon='ph--info--regular'\n iconOnly\n label={t('button toggle info')}\n size={6}\n classNames={mx('invisible', !open && '@3xl:visible')}\n onClick={() => setOpen((open) => !open)}\n />\n </Chessboard.Players>\n </div>\n </div>\n </Chessboard.Root>\n </StackItem.Content>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,gBAAgB;;;;ACFzB,OAAOC,SAASC,aAAaC,QAAQC,gBAAgB;AAErD,SAASC,YAAYC,sBAAsB;AAE3C,SAASC,iBAAiB;AAC1B,SAASC,UAAU;AAOZ,IAAMC,oBAAoB,CAAC,EAAEC,KAAI,MAAwB;;;AAC9D,UAAM,EAAEC,EAAC,IAAKC,eAAeC,KAAKC,EAAE;AACpC,UAAM,CAACC,aAAaC,cAAAA,IAAkBC,SAAiB,OAAA;AACvD,UAAM,CAACC,MAAMC,OAAAA,IAAWF,SAAS,IAAA;AACjC,UAAMG,aAAaC,OAA6B,IAAA;AAGhD,UAAMC,eAAeC,YAA0D,CAACC,UAAAA;AAC9EJ,iBAAWK,SAASC,cAAcF,KAAAA;IACpC,GAAG,CAAA,CAAE;AAEL,WACE,sBAAA,cAACG,UAAUC,SAAO;MAACC,YAAW;OAC5B,sBAAA,cAACC,WAAWC,MAAI;MAACrB;MAAYsB,KAAKZ;OAChC,sBAAA,cAACa,OAAAA;MAAIC,WAAWC,GAAG,mDAAmDjB,QAAQ,4BAAA;OAC5E,sBAAA,cAACY,WAAWF,SAAO,MACjB,sBAAA,cAACE,WAAWM,OAAK;MAACrB;SAEnBG,QACC,sBAAA,cAACe,OAAAA;MAAIC,WAAU;OACb,sBAAA,cAACJ,WAAWO,MAAI;MACdtB;MACAuB,KAAK;MACLC,KAAK;MACLC,qBAAqBxB;MACrByB,SAAS,MAAMtB,QAAQ,KAAA;MACvBuB,UAAUpB;SAIhB,sBAAA,cAACW,OAAAA;MAAIC,WAAU;OACb,sBAAA,cAACJ,WAAWa,SAAO,MACjB,sBAAA,cAACC,YAAAA;MACCC,SAAQ;MACRC,MAAK;MACLC,UAAAA;MACAC,OAAOrC,EAAE,oBAAA;MACTsC,MAAM;MACNpB,YAAYM,GAAG,aAAa,CAACjB,QAAQ,cAAA;MACrCgC,SAAS,MAAM/B,QAAQ,CAACD,UAAS,CAACA,KAAAA;;;;;AAQlD;;;AD7CO,IAAMiC,sBAAsB,CAAC,EAAEC,MAAMC,KAAI,MAA4B;;;AAC1E,UAAMC,QAAQC,SAASH,IAAAA;AACvB,QAAI,CAACE,OAAO;AACV,aAAO;IACT;AAEA,YAAQD,MAAAA;MACN,KAAK;MACL,KAAK;MACL,KAAK,mBAAmB;AACtB,eACE,gBAAAG,OAAA,cAACC,WAAWC,MAAI;UAACN;WACf,gBAAAI,OAAA,cAACC,WAAWE,SAAO;UAACN;WAClB,gBAAAG,OAAA,cAACC,WAAWG,OAAK,IAAA,CAAA,CAAA;MAIzB;MAEA,SAAS;AACP,eAAO,gBAAAJ,OAAA,cAACK,mBAAAA;UAAkBT;;MAC5B;IACF;;;;AACF;AAEA,IAAA,8BAAeD;",
6
- "names": ["React", "getSpace", "React", "useCallback", "useRef", "useState", "IconButton", "useTranslation", "StackItem", "mx", "ChessboardArticle", "game", "t", "useTranslation", "meta", "id", "orientation", "setOrientation", "useState", "open", "setOpen", "controller", "useRef", "handleSelect", "useCallback", "index", "current", "setMoveNumber", "StackItem", "Content", "classNames", "Chessboard", "Root", "ref", "div", "className", "mx", "Board", "Info", "min", "max", "onOrientationChange", "onClose", "onSelect", "Players", "IconButton", "variant", "icon", "iconOnly", "label", "size", "onClick", "ChessboardContainer", "game", "role", "space", "getSpace", "React", "Chessboard", "Root", "Content", "Board", "ChessboardArticle"]
7
- }
@@ -1,12 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- BLUEPRINT_KEY,
4
- blueprint_definition_default
5
- } from "./chunk-3NZRGOSV.mjs";
6
- import "./chunk-5DYLCQBR.mjs";
7
- import "./chunk-6OWCPDUA.mjs";
8
- export {
9
- BLUEPRINT_KEY,
10
- blueprint_definition_default as default
11
- };
12
- //# sourceMappingURL=blueprint-definition-PR5YZC6M.mjs.map