@dxos/plugin-chess 0.10.0 → 0.11.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 (163) hide show
  1. package/dist/lib/ChessPlugin.mjs +2 -0
  2. package/dist/lib/ChessPlugin.node.mjs +19 -0
  3. package/dist/lib/ChessPlugin.node.mjs.map +1 -0
  4. package/dist/lib/ChessPlugin.workerd.mjs +15 -0
  5. package/dist/lib/ChessPlugin.workerd.mjs.map +1 -0
  6. package/dist/lib/capabilities/node.mjs +8 -0
  7. package/dist/lib/capabilities/node.mjs.map +1 -0
  8. package/dist/lib/capabilities.mjs +9 -0
  9. package/dist/lib/capabilities.mjs.map +1 -0
  10. package/dist/lib/chunk-ChessArticle.mjs +89 -0
  11. package/dist/lib/chunk-ChessArticle.mjs.map +1 -0
  12. package/dist/lib/chunk-ChessCard.mjs +25 -0
  13. package/dist/lib/chunk-ChessCard.mjs.map +1 -0
  14. package/dist/lib/chunk-ChessPlugin.mjs +26 -0
  15. package/dist/lib/chunk-ChessPlugin.mjs.map +1 -0
  16. package/dist/lib/chunk-game-variant.mjs +34 -0
  17. package/dist/lib/chunk-game-variant.mjs.map +1 -0
  18. package/dist/lib/chunk-meta.mjs +29 -0
  19. package/dist/lib/chunk-meta.mjs.map +1 -0
  20. package/dist/lib/chunk-move.mjs +23 -0
  21. package/dist/lib/chunk-move.mjs.map +1 -0
  22. package/dist/lib/chunk-operation-handler.mjs +11 -0
  23. package/dist/lib/chunk-operation-handler.mjs.map +1 -0
  24. package/dist/lib/chunk-play.mjs +32 -0
  25. package/dist/lib/chunk-play.mjs.map +1 -0
  26. package/dist/lib/chunk-print.mjs +18 -0
  27. package/dist/lib/chunk-print.mjs.map +1 -0
  28. package/dist/lib/chunk-rebuild-position-index.mjs +126 -0
  29. package/dist/lib/chunk-rebuild-position-index.mjs.map +1 -0
  30. package/dist/lib/chunk-skill-definition.mjs +10 -0
  31. package/dist/lib/chunk-skill-definition.mjs.map +1 -0
  32. package/dist/lib/{neutral/chunk-IKWULCKX.mjs → chunk-skills.mjs} +14 -20
  33. package/dist/lib/chunk-skills.mjs.map +1 -0
  34. package/dist/lib/chunk-types.mjs +202 -0
  35. package/dist/lib/chunk-types.mjs.map +1 -0
  36. package/dist/lib/components.mjs +224 -0
  37. package/dist/lib/components.mjs.map +1 -0
  38. package/dist/lib/containers.mjs +8 -0
  39. package/dist/lib/containers.mjs.map +1 -0
  40. package/dist/lib/index.mjs +4 -0
  41. package/dist/lib/meta.mjs +2 -0
  42. package/dist/lib/operations.mjs +7 -0
  43. package/dist/lib/operations.mjs.map +1 -0
  44. package/dist/lib/plugin.mjs +9 -0
  45. package/dist/lib/plugin.mjs.map +1 -0
  46. package/dist/lib/skills.mjs +2 -0
  47. package/dist/lib/testing.mjs +2 -0
  48. package/dist/lib/translations.mjs +51 -0
  49. package/dist/lib/translations.mjs.map +1 -0
  50. package/dist/lib/types.mjs +2 -0
  51. package/dist/types/src/capabilities/game-variant.d.ts +1 -1
  52. package/dist/types/src/capabilities/node.d.ts +5 -0
  53. package/dist/types/src/capabilities/node.d.ts.map +1 -0
  54. package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
  55. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +52 -4
  56. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
  57. package/dist/types/src/components/Chessboard/types.d.ts +1 -1
  58. package/dist/types/src/components/Chessboard/types.d.ts.map +1 -1
  59. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +4 -1
  60. package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -1
  61. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +52 -4
  62. package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -1
  63. package/dist/types/src/containers/ChessCard/ChessCard.d.ts +4 -1
  64. package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -1
  65. package/dist/types/src/internal/position-index.d.ts +34 -0
  66. package/dist/types/src/internal/position-index.d.ts.map +1 -0
  67. package/dist/types/src/operations/index.d.ts.map +1 -1
  68. package/dist/types/src/operations/move.d.ts.map +1 -1
  69. package/dist/types/src/operations/play.d.ts.map +1 -1
  70. package/dist/types/src/operations/rebuild-position-index.d.ts +4 -0
  71. package/dist/types/src/operations/rebuild-position-index.d.ts.map +1 -0
  72. package/dist/types/src/operations/rebuild-position-index.test.d.ts +2 -0
  73. package/dist/types/src/operations/rebuild-position-index.test.d.ts.map +1 -0
  74. package/dist/types/src/translations.d.ts +52 -4
  75. package/dist/types/src/translations.d.ts.map +1 -1
  76. package/dist/types/src/types/ChessOperation.d.ts +11 -3
  77. package/dist/types/src/types/ChessOperation.d.ts.map +1 -1
  78. package/dist/types/src/types/ChessPositionIndex.d.ts +50 -0
  79. package/dist/types/src/types/ChessPositionIndex.d.ts.map +1 -0
  80. package/dist/types/src/types/PlayerReview.d.ts +23 -0
  81. package/dist/types/src/types/PlayerReview.d.ts.map +1 -0
  82. package/dist/types/src/types/index.d.ts +2 -0
  83. package/dist/types/src/types/index.d.ts.map +1 -1
  84. package/dist/types/tsconfig.tsbuildinfo +1 -1
  85. package/dx.config.ts +1 -1
  86. package/package.json +50 -43
  87. package/src/ChessPlugin.node.ts +2 -2
  88. package/src/ChessPlugin.tsx +2 -2
  89. package/src/ChessPlugin.workerd.ts +2 -2
  90. package/src/capabilities/node.ts +16 -0
  91. package/src/components/Chessboard/Info.tsx +2 -2
  92. package/src/components/Chessboard/types.ts +1 -1
  93. package/src/containers/ChessArticle/ChessArticle.stories.tsx +2 -2
  94. package/src/containers/ChessArticle/ChessArticle.tsx +19 -13
  95. package/src/containers/ChessCard/ChessCard.stories.tsx +2 -2
  96. package/src/containers/ChessCard/ChessCard.tsx +2 -0
  97. package/src/internal/position-index.ts +148 -0
  98. package/src/operations/index.ts +1 -0
  99. package/src/operations/move.ts +1 -2
  100. package/src/operations/play.ts +1 -2
  101. package/src/operations/rebuild-position-index.test.ts +118 -0
  102. package/src/operations/rebuild-position-index.ts +73 -0
  103. package/src/translations.ts +19 -1
  104. package/src/types/ChessOperation.ts +25 -4
  105. package/src/types/ChessPositionIndex.ts +53 -0
  106. package/src/types/PlayerReview.ts +48 -0
  107. package/src/types/index.ts +2 -0
  108. package/dist/lib/neutral/ChessArticle-MPRT54KQ.mjs +0 -89
  109. package/dist/lib/neutral/ChessArticle-MPRT54KQ.mjs.map +0 -7
  110. package/dist/lib/neutral/ChessCard-VJ3I6MIB.mjs +0 -24
  111. package/dist/lib/neutral/ChessCard-VJ3I6MIB.mjs.map +0 -7
  112. package/dist/lib/neutral/ChessPlugin.mjs +0 -10
  113. package/dist/lib/neutral/ChessPlugin.mjs.map +0 -7
  114. package/dist/lib/neutral/ChessPlugin.node.mjs +0 -23
  115. package/dist/lib/neutral/ChessPlugin.node.mjs.map +0 -7
  116. package/dist/lib/neutral/ChessPlugin.workerd.mjs +0 -21
  117. package/dist/lib/neutral/ChessPlugin.workerd.mjs.map +0 -7
  118. package/dist/lib/neutral/capabilities/index.mjs +0 -13
  119. package/dist/lib/neutral/capabilities/index.mjs.map +0 -7
  120. package/dist/lib/neutral/chunk-AMXVX7V2.mjs +0 -8
  121. package/dist/lib/neutral/chunk-AMXVX7V2.mjs.map +0 -7
  122. package/dist/lib/neutral/chunk-DXIET5G2.mjs +0 -148
  123. package/dist/lib/neutral/chunk-DXIET5G2.mjs.map +0 -7
  124. package/dist/lib/neutral/chunk-EXZ3XFEG.mjs +0 -41
  125. package/dist/lib/neutral/chunk-EXZ3XFEG.mjs.map +0 -7
  126. package/dist/lib/neutral/chunk-IKWULCKX.mjs.map +0 -7
  127. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  128. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  129. package/dist/lib/neutral/chunk-YZTKZ5F7.mjs +0 -42
  130. package/dist/lib/neutral/chunk-YZTKZ5F7.mjs.map +0 -7
  131. package/dist/lib/neutral/components/index.mjs +0 -240
  132. package/dist/lib/neutral/components/index.mjs.map +0 -7
  133. package/dist/lib/neutral/containers/index.mjs +0 -11
  134. package/dist/lib/neutral/containers/index.mjs.map +0 -7
  135. package/dist/lib/neutral/game-variant-ZLPEN2QK.mjs +0 -41
  136. package/dist/lib/neutral/game-variant-ZLPEN2QK.mjs.map +0 -7
  137. package/dist/lib/neutral/index.mjs +0 -18
  138. package/dist/lib/neutral/index.mjs.map +0 -7
  139. package/dist/lib/neutral/meta.json +0 -1
  140. package/dist/lib/neutral/meta.mjs +0 -8
  141. package/dist/lib/neutral/meta.mjs.map +0 -7
  142. package/dist/lib/neutral/move-UMDTQST4.mjs +0 -37
  143. package/dist/lib/neutral/move-UMDTQST4.mjs.map +0 -7
  144. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs +0 -13
  145. package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs.map +0 -7
  146. package/dist/lib/neutral/operations/index.mjs +0 -8
  147. package/dist/lib/neutral/operations/index.mjs.map +0 -7
  148. package/dist/lib/neutral/play-7XTJZ4N6.mjs +0 -46
  149. package/dist/lib/neutral/play-7XTJZ4N6.mjs.map +0 -7
  150. package/dist/lib/neutral/plugin.mjs +0 -16
  151. package/dist/lib/neutral/plugin.mjs.map +0 -7
  152. package/dist/lib/neutral/print-JR4VB3UX.mjs +0 -29
  153. package/dist/lib/neutral/print-JR4VB3UX.mjs.map +0 -7
  154. package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs +0 -15
  155. package/dist/lib/neutral/skill-definition-ZGQBUE4R.mjs.map +0 -7
  156. package/dist/lib/neutral/skills/index.mjs +0 -8
  157. package/dist/lib/neutral/skills/index.mjs.map +0 -7
  158. package/dist/lib/neutral/testing.mjs +0 -8
  159. package/dist/lib/neutral/testing.mjs.map +0 -7
  160. package/dist/lib/neutral/translations.mjs +0 -39
  161. package/dist/lib/neutral/translations.mjs.map +0 -7
  162. package/dist/lib/neutral/types/index.mjs +0 -10
  163. package/dist/lib/neutral/types/index.mjs.map +0 -7
@@ -1,8 +0,0 @@
1
- // src/operations/index.ts
2
- import { OperationHandlerSet } from "@dxos/compute";
3
- var ChessOperationHandlerSet = OperationHandlerSet.lazy(() => import("./move-UMDTQST4.mjs"), () => import("./play-7XTJZ4N6.mjs"), () => import("./print-JR4VB3UX.mjs"));
4
-
5
- export {
6
- ChessOperationHandlerSet
7
- };
8
- //# sourceMappingURL=chunk-AMXVX7V2.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/operations/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { OperationHandlerSet } from '@dxos/compute';\n\nexport const ChessOperationHandlerSet = OperationHandlerSet.lazy(\n () => import('./move'),\n () => import('./play'),\n () => import('./print'),\n);\n"],
5
- "mappings": ";AAIA,SAASA,2BAA2B;AAE7B,IAAMC,2BAA2BD,oBAAoBE,KAC1D,MAAM,OAAO,qBAAA,GACb,MAAM,OAAO,qBAAA,GACb,MAAM,OAAO,sBAAA,CAAA;",
6
- "names": ["OperationHandlerSet", "ChessOperationHandlerSet", "lazy"]
7
- }
@@ -1,148 +0,0 @@
1
- import {
2
- __export
3
- } from "./chunk-J5LGTIGS.mjs";
4
-
5
- // src/types/Chess.ts
6
- var Chess_exports = {};
7
- __export(Chess_exports, {
8
- SKILL_KEY: () => SKILL_KEY,
9
- State: () => State,
10
- make: () => make
11
- });
12
- import { Chess as ChessJS } from "chess.js";
13
- import * as Schema from "effect/Schema";
14
- import { AppAnnotation } from "@dxos/app-toolkit";
15
- import { Annotation, DXN, Obj, Type } from "@dxos/echo";
16
- import { FormInputAnnotation, HiddenAnnotation } from "@dxos/echo/Annotation";
17
- import { log } from "@dxos/log";
18
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-chess/src/types/Chess.ts";
19
- var SKILL_KEY = "org.dxos.skill.chess";
20
- var State = class extends Type.makeObject(DXN.make("org.dxos.type.chess.state", "0.1.0"))(Schema.Struct({
21
- pgn: Schema.String.annotations({
22
- description: "Portable Game Notation."
23
- }).pipe(FormInputAnnotation.set(false), Schema.optional),
24
- fen: Schema.String.annotations({
25
- description: "Forsyth-Edwards Notation."
26
- }).pipe(FormInputAnnotation.set(false), Schema.optional)
27
- }).pipe(
28
- Annotation.IconAnnotation.set({
29
- icon: "ph--shield-chevron--regular",
30
- hue: "amber"
31
- }),
32
- AppAnnotation.SkillsAnnotation.set([
33
- SKILL_KEY
34
- ]),
35
- // Implementation detail of the unified `Game` schema. The user-facing object is `Game`;
36
- // this state is only ever referenced via `Game.variant`. HiddenAnnotation keeps it out of the
37
- // navtree's typed branches so an orphaned state object doesn't reappear after the
38
- // wrapping Game is deleted.
39
- HiddenAnnotation.set(true)
40
- )) {
41
- };
42
- var make = ({ pgn, fen } = {}) => {
43
- const chess = new ChessJS();
44
- if (pgn) {
45
- try {
46
- chess.loadPgn(pgn);
47
- } catch {
48
- log.warn(pgn, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 38, S: void 0 });
49
- }
50
- }
51
- return Obj.make(State, {
52
- pgn,
53
- fen
54
- });
55
- };
56
-
57
- // src/types/ChessOperation.ts
58
- var ChessOperation_exports = {};
59
- __export(ChessOperation_exports, {
60
- Move: () => Move,
61
- Play: () => Play,
62
- Print: () => Print
63
- });
64
- import * as Schema2 from "effect/Schema";
65
- import { Operation } from "@dxos/compute";
66
- import { Database, DXN as DXN2 } from "@dxos/echo";
67
- import { GameRef } from "@dxos/plugin-game/types";
68
- var Move = Operation.make({
69
- meta: {
70
- key: DXN2.make("org.dxos.function.chess.move"),
71
- name: "Move",
72
- description: "Makes a move in the given chess game.",
73
- icon: "ph--play--regular"
74
- },
75
- input: Schema2.Struct({
76
- game: GameRef(State).annotations({
77
- description: "The ID of the game object (variant must be Chess)."
78
- }),
79
- move: Schema2.String.annotations({
80
- description: "The move to make in the chess game.",
81
- examples: [
82
- "e4",
83
- "Bf3"
84
- ]
85
- })
86
- }),
87
- output: Schema2.Struct({
88
- pgn: Schema2.String.annotations({
89
- description: "The PGN of the game after the move was played."
90
- })
91
- }),
92
- services: [
93
- Database.Service
94
- ]
95
- });
96
- var Play = Operation.make({
97
- meta: {
98
- key: DXN2.make("org.dxos.function.chess.play"),
99
- name: "Play",
100
- description: "Uses the chess engine to play the next move.",
101
- icon: "ph--play--regular"
102
- },
103
- input: Schema2.Struct({
104
- game: GameRef(State).annotations({
105
- description: "The ID of the game object (variant must be Chess)."
106
- }),
107
- side: Schema2.optional(Schema2.Literal("white", "black", "any")).annotations({
108
- description: "The side to play.",
109
- defaultValue: "any"
110
- })
111
- }),
112
- output: Schema2.Struct({
113
- pgn: Schema2.String.annotations({
114
- description: "The PGN of the game after the move was played."
115
- }),
116
- move: Schema2.optional(Schema2.String).annotations({
117
- description: "The move that was played."
118
- })
119
- }),
120
- services: [
121
- Database.Service
122
- ]
123
- });
124
- var Print = Operation.make({
125
- meta: {
126
- key: DXN2.make("org.dxos.function.chess.print"),
127
- name: "Print game",
128
- description: "Prints the chess game to ASCII.",
129
- icon: "ph--clipboard-text--regular"
130
- },
131
- input: Schema2.Struct({
132
- pgn: Schema2.optional(Schema2.String.annotations({
133
- description: "Portable Game Notation."
134
- })),
135
- fen: Schema2.optional(Schema2.String.annotations({
136
- description: "Forsyth-Edwards Notation."
137
- }))
138
- }),
139
- output: Schema2.Struct({
140
- ascii: Schema2.String
141
- })
142
- });
143
-
144
- export {
145
- Chess_exports,
146
- ChessOperation_exports
147
- };
148
- //# sourceMappingURL=chunk-DXIET5G2.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/Chess.ts", "../../../src/types/ChessOperation.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Chess as ChessJS } from 'chess.js';\nimport * as Schema from 'effect/Schema';\n\nimport { AppAnnotation } from '@dxos/app-toolkit';\nimport { Annotation, DXN, Obj, Type } from '@dxos/echo';\nimport { FormInputAnnotation, HiddenAnnotation } from '@dxos/echo/Annotation';\nimport { log } from '@dxos/log';\n\nexport const SKILL_KEY = 'org.dxos.skill.chess';\n\n/**\n * Chess variant state. Referenced by the base `Game` object via `Game.variant`.\n * Players, name, and other game-shared fields live on the base `Game`.\n */\nexport class State extends Type.makeObject<State>(DXN.make('org.dxos.type.chess.state', '0.1.0'))(\n Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'Portable Game Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n fen: Schema.String.annotations({\n description: 'Forsyth-Edwards Notation.',\n }).pipe(FormInputAnnotation.set(false), Schema.optional),\n }).pipe(\n Annotation.IconAnnotation.set({ icon: 'ph--shield-chevron--regular', hue: 'amber' }),\n AppAnnotation.SkillsAnnotation.set([SKILL_KEY]),\n // Implementation detail of the unified `Game` schema. The user-facing object is `Game`;\n // this state is only ever referenced via `Game.variant`. HiddenAnnotation keeps it out of the\n // navtree's typed branches so an orphaned state object doesn't reappear after the\n // wrapping Game is deleted.\n HiddenAnnotation.set(true),\n ),\n) {}\n\nexport const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {\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(State, {\n pgn,\n fen,\n });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { Database, DXN } from '@dxos/echo';\nimport { GameRef } from '@dxos/plugin-game/types';\n\nimport * as Chess from './Chess';\n\nexport const Move = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.move'),\n name: 'Move',\n description: 'Makes a move in the given chess game.',\n icon: 'ph--play--regular',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The ID of the game object (variant must be Chess).',\n }),\n move: Schema.String.annotations({\n description: 'The move to make in the chess game.',\n examples: ['e4', 'Bf3'],\n }),\n }),\n output: Schema.Struct({\n pgn: Schema.String.annotations({\n description: 'The PGN of the game after the move was played.',\n }),\n }),\n services: [Database.Service],\n});\n\nexport const Play = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.play'),\n name: 'Play',\n description: 'Uses the chess engine to play the next move.',\n icon: 'ph--play--regular',\n },\n input: Schema.Struct({\n game: GameRef(Chess.State).annotations({\n description: 'The ID of the game object (variant must be Chess).',\n }),\n side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({\n description: 'The side to play.',\n defaultValue: 'any',\n }),\n }),\n output: 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 services: [Database.Service],\n});\n\nexport const Print = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.chess.print'),\n name: 'Print game',\n description: 'Prints the chess game to ASCII.',\n icon: 'ph--clipboard-text--regular',\n },\n input: 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 output: Schema.Struct({\n ascii: Schema.String,\n }),\n});\n"],
5
- "mappings": ";;;;;AAAA;;;;;;AAIA,SAASA,SAASC,eAAe;AACjC,YAAYC,YAAY;AAExB,SAASC,qBAAqB;AAC9B,SAASC,YAAYC,KAAKC,KAAKC,YAAY;AAC3C,SAASC,qBAAqBC,wBAAwB;AACtD,SAASC,WAAW;AAEpB,IAAA,eAAaC;;AASPC,IAAAA,QAAAA,cAAa,KAAA,WAAA,IAAA,KAAA,6BAAA,OAAA,CAAA,EAAA,cAAA;EACf,KAAQJ,cAAAA,YAAuB;IAC/BK,aAAYC;UACVF,oBAAa,IAAA,KAAA,GAAA,eAAA;EACf,KAAQJ,cAAAA,YAAuB;IAE/BJ,aAAWW;EAAqBC,CAAAA,EAAAA,KAAM,oBAAA,IAAA,KAAA,GAAA,eAAA;;EAA+BC,WAAK,eAAA,IAAA;IAC1Ed,MAAAA;IAAoCQ,KAAAA;GAAU;EAC9C,cAAA,iBAAA,IAAA;IACA;EACA,CAAA;;;;;EAMJ,iBAAaO,IAAQ,IAAEC;AAAG,CAAA,EAAEN;;AAE1B,IAAS,OAAA,CAAA,EAAA,KAAA,IAAA,IAAA,CAAA,MAAA;QACP,QAAI,IAAA,QAAA;WACFO;AACF,QAAE;AACAV,YAAIW,QAAKF,GAAAA;IACX,QAAA;AACF,UAAA,KAAA,KAAA,QAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,OAAA,CAAA;IAEA;;SAEEN,IAAAA,KAAAA,OAAAA;IACF;IACA;;;;;ACnDF;;;;;;AAMA,YAAYS,aAAY;AAExB,SAASC,iBAAiB;AAC1B,SAASC,UAAUC,OAAAA,YAAW;AAC9B,SAASC,eAAe;AAIjB,IAAMC,OAAOC,UAAUC,KAAK;EACjCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,8BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBC,MAAMC,QAAcC,KAAK,EAAEC,YAAY;MACrCP,aAAa;IACf,CAAA;IACAQ,MAAaC,eAAOF,YAAY;MAC9BP,aAAa;MACbU,UAAU;QAAC;QAAM;;IACnB,CAAA;EACF,CAAA;EACAC,QAAeR,eAAO;IACpBS,KAAYH,eAAOF,YAAY;MAC7BP,aAAa;IACf,CAAA;EACF,CAAA;EACAa,UAAU;IAACC,SAASC;;AACtB,CAAA;AAEO,IAAMC,OAAOtB,UAAUC,KAAK;EACjCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,8BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBC,MAAMC,QAAcC,KAAK,EAAEC,YAAY;MACrCP,aAAa;IACf,CAAA;IACAiB,MAAaC,iBAAgBC,gBAAQ,SAAS,SAAS,KAAA,CAAA,EAAQZ,YAAY;MACzEP,aAAa;MACboB,cAAc;IAChB,CAAA;EACF,CAAA;EACAT,QAAeR,eAAO;IACpBS,KAAYH,eAAOF,YAAY;MAC7BP,aAAa;IACf,CAAA;IACAQ,MAAaU,iBAAgBT,cAAM,EAAEF,YAAY;MAC/CP,aAAa;IACf,CAAA;EACF,CAAA;EACAa,UAAU;IAACC,SAASC;;AACtB,CAAA;AAEO,IAAMM,QAAQ3B,UAAUC,KAAK;EAClCC,MAAM;IACJC,KAAKC,KAAIH,KAAK,+BAAA;IACdI,MAAM;IACNC,aAAa;IACbC,MAAM;EACR;EACAC,OAAcC,eAAO;IACnBS,KAAYM,iBACHT,eAAOF,YAAY;MACxBP,aAAa;IACf,CAAA,CAAA;IAEFsB,KAAYJ,iBACHT,eAAOF,YAAY;MACxBP,aAAa;IACf,CAAA,CAAA;EAEJ,CAAA;EACAW,QAAeR,eAAO;IACpBoB,OAAcd;EAChB,CAAA;AACF,CAAA;",
6
- "names": ["Chess", "ChessJS", "Schema", "AppAnnotation", "Annotation", "DXN", "Obj", "Type", "FormInputAnnotation", "HiddenAnnotation", "log", "SKILL_KEY", "description", "fen", "String", "IconAnnotation", "icon", "hue", "make", "pgn", "chess", "warn", "Schema", "Operation", "Database", "DXN", "GameRef", "Move", "Operation", "make", "meta", "key", "DXN", "name", "description", "icon", "input", "Struct", "game", "GameRef", "State", "annotations", "move", "String", "examples", "output", "pgn", "services", "Database", "Service", "Play", "side", "optional", "Literal", "defaultValue", "Print", "fen", "ascii"]
7
- }
@@ -1,41 +0,0 @@
1
- // src/ChessPlugin.tsx
2
- import { Plugin } from "@dxos/app-framework";
3
- import { AppActivationEvents, AppPlugin } from "@dxos/app-toolkit";
4
- import { GameVariant, OperationHandler, SkillDefinition } from "#capabilities";
5
- import { meta } from "#meta";
6
- import { translations } from "#translations";
7
- import { Chess } from "#types";
8
-
9
- // raw-loader:/__w/dxos/dxos/packages/plugins/plugin-chess/PLUGIN.mdl
10
- var PLUGIN_default = "---\nid: org.dxos.plugin.chess\nname: ChessPlugin\nversion: 0.1.0\n---\n\nA two-player chess game plugin for `DXOS` Composer.\n\n## Extensions\n\nThe following extension dialects are used in this document.\nEach extension is defined in the Appendix or resolved via its URI.\n\n| Term | URI |\n|-------------|--------------------------------|\n| `type` | `org.dxos.mdl.type@1.0` |\n| `feat` | `org.dxos.mdl.feat@1.0` |\n| `test` | `org.dxos.mdl.test@1.0` |\n| `component` | `org.dxos.mdl.component@1.0` |\n| `op` | `org.dxos.mdl.op@1.0` |\n| `service` | `org.dxos.mdl.service@1.0` |\n\n## Types\n\n```mdl\ntype Color\n literals: white | black\n```\n\n```mdl\ntype PieceKind\n literals: pawn | rook | knight | bishop | queen | king\n```\n\n```mdl\ntype Piece\n fields:\n kind: PieceKind\n color: Color\n```\n\n```mdl\ntype Square\n fields:\n file: a | b | c | d | e | f | g | h\n rank: 1..8\n piece?: Piece\n```\n\n```mdl\ntype Move\n fields:\n from: Square\n to: Square\n promotion?: PieceKind # only valid for pawn reaching back rank\n```\n\n```mdl\ntype Board\n fields:\n squares: Square[8][8]\n turn: Color\n status: playing | check | checkmate | stalemate\n moves: Move[] # full move history\n```\n\n```mdl\ntype Player\n fields:\n id: string\n name: string\n color: Color\n```\n\n```mdl\ntype GameStatus\n literals: waiting | active | finished\n```\n\n```mdl\ntype Game\n fields:\n id: string\n players: Player[2]\n board: Board\n status: GameStatus\n winner?: Player\n```\n\n## Components\n\n```mdl\ncomponent Lobby\n desc: Entry point where players create or join a game.\n props:\n playerId: string\n state:\n games: Game[] # list of open/active games\n selected?: Game\n slots:\n header?: ReactNode\n empty?: ReactNode # shown when games list is empty\n actions:\n createGame() \u2192 Game\n joinGame(game: Game) \u2192 Game\n spectate(game: Game)\n emits:\n onJoin(game: Game)\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [header slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 Game list \u2502\n \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502\n \u2502 \u2502 game row \u2502 \u2502\n \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n \u2502 [empty slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [Create Game] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n```mdl\ncomponent Gameboard\n desc: Interactive chess board for an active game.\n props:\n game: Game\n playerId: string # identifies which side the viewer plays\n state:\n selected?: Square # currently selected square\n highlights: Square[] # legal move targets for selected piece\n perspective: Color # which side is at the bottom (default: player's color)\n slots:\n toolbar?: ReactNode\n sidebar?: ReactNode\n overlay?: ReactNode # e.g. checkmate / promotion dialogs\n actions:\n selectSquare(square: Square)\n submitMove(move: Move)\n flipBoard()\n emits:\n onMove(move: Move)\n onResign()\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [toolbar slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 \u2502 [sidebar] \u2502\n \u2502 8\xD78 \u2502 \u2502\n \u2502 board \u2502 move history \u2502\n \u2502 \u2502 \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [overlay slot] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n## Services\n\n```mdl\nservice ChessEngine\n desc: Validates moves and computes game state. May be local (WASM) or remote.\n loading: lazy\n ops:\n validate(board: Board, move: Move) \u2192 Move\n legalMoves(board: Board, square: Square) \u2192 Square[]\n applyMove(board: Board, move: Move) \u2192 Board\n errors:\n EngineNotReady: engine has not finished loading\n```\n\n```mdl\nservice GameStore\n desc: Persists and replicates Game state via ECHO.\n ops:\n create(white: Player, black: Player) \u2192 Game\n load(id: string) \u2192 Game\n save(game: Game) \u2192 Game\n list() \u2192 Game[]\n effects: [echo:write, echo:read]\n```\n\n## Operations\n\nPure operations (no effects, no service dependencies) \u2014 safe to call anywhere.\n\n```mdl\nop getLegalMoves\n desc: Returns legal target squares for the piece on the given square.\n input:\n board: Board\n square: Square\n output: Square[]\n errors:\n EmptySquare: no piece on square\n WrongSide: piece does not belong to the active side\n requires: [ChessEngine]\n```\n\n```mdl\nop validateMove\n desc: Checks a move against chess rules without mutating state.\n input:\n board: Board\n move: Move\n output: Move\n errors:\n IllegalMove: move violates chess rules\n WrongTurn: piece does not belong to the active side\n GameOver: game has already ended\n requires: [ChessEngine]\n```\n\n```mdl\nop applyMove\n desc: Applies a validated move and returns the next board state.\n input:\n board: Board\n move: Move # must be pre-validated\n output: Board\n requires: [ChessEngine]\n note: does not persist; use submitMove for the full transactional flow\n```\n\nEffectful operations \u2014 mutate persistent state.\n\n```mdl\nop startGame\n desc: Creates a new Game with two players and an initial Board.\n input:\n white: Player\n black: Player\n output: Game\n effects: [echo:write]\n requires: [GameStore]\n```\n\n```mdl\nop submitMove\n desc: Validates and applies a move, then persists the updated Game.\n input:\n game: Game\n player: Player\n move: Move\n output: Game\n errors:\n WrongTurn: player is not the active side\n IllegalMove: move violates chess rules\n GameOver: game has already ended\n effects: [echo:write]\n requires: [ChessEngine, GameStore]\n note: |\n Composes validateMove \u2192 applyMove \u2192 GameStore.save.\n Atomic: Game is not persisted if validation fails.\n```\n\n```mdl\nop resignGame\n desc: Player forfeits; opponent wins.\n input:\n game: Game\n player: Player\n output: Game # Game.status === finished, Game.winner set\n errors:\n GameOver: game has already ended\n effects: [echo:write]\n requires: [GameStore]\n```\n\n## Features\n\n```mdl\nfeat F-1: Start Game\n\n req F-1.1: New Board created with pieces in standard starting positions.\n req F-1.2: White moves first.\n```\n\n```mdl\nfeat F-2: Make Move\n\n req F-2.1:\n when: player submits a Move on their turn\n then: Move validated against chess rules\n errors: [InvalidMove, WrongTurn, GameOver]\n\n req F-2.2:\n when: Move is valid\n then: Board updated; turn advances to opponent\n\n req F-2.3:\n when: resulting position leaves opponent's king in check\n then: Board.status set to check\n\n req F-2.4:\n when: no legal moves remain for the side to move\n then: Board.status set to checkmate (if in check) or stalemate\n```\n\n```mdl\nfeat F-3: Lobby\n\n req F-3.1: Player sees list of open games on entering the Lobby.\n req F-3.2:\n when: player creates a game\n then: new Game created with status waiting; player assigned white\n\n req F-3.3:\n when: second player joins an open game\n then: Game.status transitions to active; joining player assigned black\n\n req F-3.4:\n when: Game.status becomes active\n then: both players navigated to Gameboard\n```\n\n```mdl\nfeat F-4: Gameboard\n\n req F-4.1:\n when: player selects a square containing their piece\n then: legal move targets highlighted on board\n\n req F-4.2:\n when: player selects a highlighted target square\n then: Move submitted via submitMove(); board updated on success\n\n req F-4.3:\n when: pawn reaches the back rank\n then: promotion dialog shown via overlay slot; player selects piece kind\n\n req F-4.4:\n when: Game.status is finished\n then: result overlay shown (winner or draw); further moves disabled\n```\n\n```mdl\nfeat F-5: Move Validation\n\n req F-5.1:\n when: Gameboard calls submitMove\n then: op:validateMove runs before any state change\n\n req F-5.2:\n when: validation fails\n then: error returned to caller; Game state unchanged\n\n req F-5.3:\n when: square is selected on Gameboard\n then: op:getLegalMoves called; results drive component:Gameboard.highlights\n```\n\n```mdl\nfeat F-6: Game Persistence\n\n req F-6.1:\n when: op:startGame completes\n then: Game written to ECHO and visible in component:Lobby game list\n\n req F-6.2:\n when: op:submitMove completes\n then: updated Game replicated to all peers via ECHO\n\n req F-6.3:\n when: peer receives a Game update\n then: component:Gameboard re-renders with new Board state\n tags: [collaborative]\n```\n\n## Acceptance\n\n```mdl\ntest T-1: New game starting position\n given: a new game is started\n then:\n - Board.turn === white\n - Board.status === playing\n - each player has 16 pieces in standard positions\n```\n\n```mdl\ntest T-2: Illegal move rejected\n given: it is white's turn\n when: white attempts to move a black piece\n then: WrongTurn error; Board unchanged\n```\n\n```mdl\ntest T-3: Create and join game\n given: two players are in the Lobby\n when: player A creates a game, player B joins it\n then:\n - Game.status === active\n - Game.players[0].color === white # creator\n - Game.players[1].color === black # joiner\n - both players see the Gameboard\n```\n\n```mdl\ntest T-4: Legal move highlight\n given: Gameboard is shown, it is white's turn\n when: white selects the e2 pawn\n then:\n - squares e3 and e4 are highlighted\n - no other squares are highlighted\n```\n\n```mdl\ntest T-5: Pawn promotion\n given: white pawn is on e7, it is white's turn\n when: white moves pawn to e8\n then:\n - promotion overlay appears\n - after player selects queen, Move recorded with promotion: queen\n - board shows white queen on e8\n```\n\n```mdl\ntest T-6: Submit valid move\n given: active game, white's turn, white player logged in\n when: white submits pawn e2\u2192e4\n then:\n - op:validateMove returns move without error\n - Board updated: e4 occupied by white pawn, e2 empty\n - Game.board.turn === black\n - Game persisted to ECHO\n```\n\n```mdl\ntest T-7: Submit invalid move rejected atomically\n given: active game, white's turn\n when: white submits an illegal move (e2\u2192e5)\n then:\n - IllegalMove error returned\n - Game.board unchanged\n - no ECHO write occurs\n```\n\n```mdl\ntest T-8: Legal moves highlighted\n given: new game, white's turn, Gameboard shown\n when: player selects e2\n then:\n - op:getLegalMoves returns [e3, e4]\n - Gameboard.highlights === [e3, e4]\n```\n\n---\n\n## Appendix: Extension Definitions\n\nExtension block types used in this document are defined below using\nthe core `ext` primitive \u2014 the only construct the base language provides.\n\n```mdl\next type\n uri: dxos.spec/ext/type@1.0\n desc: A named data structure with typed fields and optional literals.\n fields:\n desc?: Prose\n fields?: FieldMap # name[?]: TypeExpr (# inline comment)\n literals?: UnionList # a | b | c\n extends?: TypeRef[]\n```\n\n```mdl\next feat\n uri: dxos.spec/ext/feat@1.0\n desc: A named feature grouping one or more requirements.\n fields:\n desc?: Prose\n req: RequirementList\n nesting: self # feat blocks may contain feat blocks\n```\n\n```mdl\next test\n uri: dxos.spec/ext/test@1.0\n desc: An acceptance scenario expressed as given / when / then steps.\n fields:\n given?: Step | Step[]\n when?: Step | Step[]\n then: Step | Step[]\n tags?: TagList\n```\n\n```mdl\next component\n uri: org.dxos.mdl.component@1.0\n desc: A UI component with props, internal state, slots, actions, and events.\n fields:\n desc?: Prose\n props?: FieldMap # external inputs (immutable inside component)\n state?: FieldMap # internal reactive state\n slots?: FieldMap # named ReactNode injection points\n actions?: ActionMap # methods the component exposes or handles\n emits?: EventMap # events the component raises to its parent\n layout?: CodeBlock # ASCII sketch of visual structure (non-normative)\n```\n\n```mdl\next op\n uri: org.dxos.mdl.op@1.0\n desc: |\n A named operation with typed inputs, outputs, and declared errors.\n Pure ops have no effects or requires. Effectful ops declare both.\n fields:\n desc?: Prose\n input?: FieldMap # named input parameters\n output?: TypeExpr # return type\n errors?: ErrorMap # name: Prose (when this error occurs)\n effects?: EffectList # echo:read | echo:write | http | fs | ...\n requires?: ServiceList # injected service dependencies\n note?: Prose # implementation guidance (non-normative)\n```\n\n```mdl\next service\n uri: org.dxos.mdl.service@1.0\n desc: An external or system-level dependency providing named operations.\n fields:\n desc?: Prose\n loading?: eager | lazy\n ops?: OpMap # name(params) \u2192 ReturnType\n errors?: ErrorMap\n note?: Prose\n```\n";
11
-
12
- // src/ChessPlugin.tsx
13
- var ChessPlugin = Plugin.define(meta).pipe(Plugin.addModule({
14
- id: "game-variant",
15
- activatesOn: AppActivationEvents.SetupSchema,
16
- activate: GameVariant
17
- }), AppPlugin.addSkillDefinitionModule({
18
- activate: SkillDefinition
19
- }), AppPlugin.addOperationHandlerModule({
20
- activate: OperationHandler
21
- }), AppPlugin.addPluginAssetModule({
22
- asset: {
23
- pluginId: meta.profile.key,
24
- path: "PLUGIN.mdl",
25
- content: PLUGIN_default,
26
- mimeType: "application/x-mdl"
27
- }
28
- }), AppPlugin.addSchemaModule({
29
- schema: [
30
- Chess.State
31
- ]
32
- }), AppPlugin.addTranslationsModule({
33
- translations
34
- }), Plugin.make);
35
- var ChessPlugin_default = ChessPlugin;
36
-
37
- export {
38
- ChessPlugin,
39
- ChessPlugin_default
40
- };
41
- //# sourceMappingURL=chunk-EXZ3XFEG.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/ChessPlugin.tsx", "raw-loader:/__w/dxos/dxos/packages/plugins/plugin-chess/PLUGIN.mdl"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppActivationEvents, AppPlugin } from '@dxos/app-toolkit';\n\nimport { GameVariant, OperationHandler, SkillDefinition } from '#capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\nimport { Chess } from '#types';\n\n// eslint-disable-next-line import/no-relative-packages\nimport pluginSpec from '../PLUGIN.mdl?raw';\n\nexport const ChessPlugin = Plugin.define(meta).pipe(\n Plugin.addModule({\n id: 'game-variant',\n activatesOn: AppActivationEvents.SetupSchema,\n activate: GameVariant,\n }),\n AppPlugin.addSkillDefinitionModule({ activate: SkillDefinition }),\n AppPlugin.addOperationHandlerModule({ activate: OperationHandler }),\n AppPlugin.addPluginAssetModule({\n asset: { pluginId: meta.profile.key, path: 'PLUGIN.mdl', content: pluginSpec, mimeType: 'application/x-mdl' },\n }),\n AppPlugin.addSchemaModule({ schema: [Chess.State] }),\n AppPlugin.addTranslationsModule({ translations }),\n Plugin.make,\n);\n\nexport default ChessPlugin;\n", "---\nid: org.dxos.plugin.chess\nname: ChessPlugin\nversion: 0.1.0\n---\n\nA two-player chess game plugin for `DXOS` Composer.\n\n## Extensions\n\nThe following extension dialects are used in this document.\nEach extension is defined in the Appendix or resolved via its URI.\n\n| Term | URI |\n|-------------|--------------------------------|\n| `type` | `org.dxos.mdl.type@1.0` |\n| `feat` | `org.dxos.mdl.feat@1.0` |\n| `test` | `org.dxos.mdl.test@1.0` |\n| `component` | `org.dxos.mdl.component@1.0` |\n| `op` | `org.dxos.mdl.op@1.0` |\n| `service` | `org.dxos.mdl.service@1.0` |\n\n## Types\n\n```mdl\ntype Color\n literals: white | black\n```\n\n```mdl\ntype PieceKind\n literals: pawn | rook | knight | bishop | queen | king\n```\n\n```mdl\ntype Piece\n fields:\n kind: PieceKind\n color: Color\n```\n\n```mdl\ntype Square\n fields:\n file: a | b | c | d | e | f | g | h\n rank: 1..8\n piece?: Piece\n```\n\n```mdl\ntype Move\n fields:\n from: Square\n to: Square\n promotion?: PieceKind # only valid for pawn reaching back rank\n```\n\n```mdl\ntype Board\n fields:\n squares: Square[8][8]\n turn: Color\n status: playing | check | checkmate | stalemate\n moves: Move[] # full move history\n```\n\n```mdl\ntype Player\n fields:\n id: string\n name: string\n color: Color\n```\n\n```mdl\ntype GameStatus\n literals: waiting | active | finished\n```\n\n```mdl\ntype Game\n fields:\n id: string\n players: Player[2]\n board: Board\n status: GameStatus\n winner?: Player\n```\n\n## Components\n\n```mdl\ncomponent Lobby\n desc: Entry point where players create or join a game.\n props:\n playerId: string\n state:\n games: Game[] # list of open/active games\n selected?: Game\n slots:\n header?: ReactNode\n empty?: ReactNode # shown when games list is empty\n actions:\n createGame() \u2192 Game\n joinGame(game: Game) \u2192 Game\n spectate(game: Game)\n emits:\n onJoin(game: Game)\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [header slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 Game list \u2502\n \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502\n \u2502 \u2502 game row \u2502 \u2502\n \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n \u2502 [empty slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [Create Game] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n```mdl\ncomponent Gameboard\n desc: Interactive chess board for an active game.\n props:\n game: Game\n playerId: string # identifies which side the viewer plays\n state:\n selected?: Square # currently selected square\n highlights: Square[] # legal move targets for selected piece\n perspective: Color # which side is at the bottom (default: player's color)\n slots:\n toolbar?: ReactNode\n sidebar?: ReactNode\n overlay?: ReactNode # e.g. checkmate / promotion dialogs\n actions:\n selectSquare(square: Square)\n submitMove(move: Move)\n flipBoard()\n emits:\n onMove(move: Move)\n onResign()\n layout: |\n \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 [toolbar slot] \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 \u2502 [sidebar] \u2502\n \u2502 8\u00D78 \u2502 \u2502\n \u2502 board \u2502 move history \u2502\n \u2502 \u2502 \u2502\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 [overlay slot] \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n## Services\n\n```mdl\nservice ChessEngine\n desc: Validates moves and computes game state. May be local (WASM) or remote.\n loading: lazy\n ops:\n validate(board: Board, move: Move) \u2192 Move\n legalMoves(board: Board, square: Square) \u2192 Square[]\n applyMove(board: Board, move: Move) \u2192 Board\n errors:\n EngineNotReady: engine has not finished loading\n```\n\n```mdl\nservice GameStore\n desc: Persists and replicates Game state via ECHO.\n ops:\n create(white: Player, black: Player) \u2192 Game\n load(id: string) \u2192 Game\n save(game: Game) \u2192 Game\n list() \u2192 Game[]\n effects: [echo:write, echo:read]\n```\n\n## Operations\n\nPure operations (no effects, no service dependencies) \u2014 safe to call anywhere.\n\n```mdl\nop getLegalMoves\n desc: Returns legal target squares for the piece on the given square.\n input:\n board: Board\n square: Square\n output: Square[]\n errors:\n EmptySquare: no piece on square\n WrongSide: piece does not belong to the active side\n requires: [ChessEngine]\n```\n\n```mdl\nop validateMove\n desc: Checks a move against chess rules without mutating state.\n input:\n board: Board\n move: Move\n output: Move\n errors:\n IllegalMove: move violates chess rules\n WrongTurn: piece does not belong to the active side\n GameOver: game has already ended\n requires: [ChessEngine]\n```\n\n```mdl\nop applyMove\n desc: Applies a validated move and returns the next board state.\n input:\n board: Board\n move: Move # must be pre-validated\n output: Board\n requires: [ChessEngine]\n note: does not persist; use submitMove for the full transactional flow\n```\n\nEffectful operations \u2014 mutate persistent state.\n\n```mdl\nop startGame\n desc: Creates a new Game with two players and an initial Board.\n input:\n white: Player\n black: Player\n output: Game\n effects: [echo:write]\n requires: [GameStore]\n```\n\n```mdl\nop submitMove\n desc: Validates and applies a move, then persists the updated Game.\n input:\n game: Game\n player: Player\n move: Move\n output: Game\n errors:\n WrongTurn: player is not the active side\n IllegalMove: move violates chess rules\n GameOver: game has already ended\n effects: [echo:write]\n requires: [ChessEngine, GameStore]\n note: |\n Composes validateMove \u2192 applyMove \u2192 GameStore.save.\n Atomic: Game is not persisted if validation fails.\n```\n\n```mdl\nop resignGame\n desc: Player forfeits; opponent wins.\n input:\n game: Game\n player: Player\n output: Game # Game.status === finished, Game.winner set\n errors:\n GameOver: game has already ended\n effects: [echo:write]\n requires: [GameStore]\n```\n\n## Features\n\n```mdl\nfeat F-1: Start Game\n\n req F-1.1: New Board created with pieces in standard starting positions.\n req F-1.2: White moves first.\n```\n\n```mdl\nfeat F-2: Make Move\n\n req F-2.1:\n when: player submits a Move on their turn\n then: Move validated against chess rules\n errors: [InvalidMove, WrongTurn, GameOver]\n\n req F-2.2:\n when: Move is valid\n then: Board updated; turn advances to opponent\n\n req F-2.3:\n when: resulting position leaves opponent's king in check\n then: Board.status set to check\n\n req F-2.4:\n when: no legal moves remain for the side to move\n then: Board.status set to checkmate (if in check) or stalemate\n```\n\n```mdl\nfeat F-3: Lobby\n\n req F-3.1: Player sees list of open games on entering the Lobby.\n req F-3.2:\n when: player creates a game\n then: new Game created with status waiting; player assigned white\n\n req F-3.3:\n when: second player joins an open game\n then: Game.status transitions to active; joining player assigned black\n\n req F-3.4:\n when: Game.status becomes active\n then: both players navigated to Gameboard\n```\n\n```mdl\nfeat F-4: Gameboard\n\n req F-4.1:\n when: player selects a square containing their piece\n then: legal move targets highlighted on board\n\n req F-4.2:\n when: player selects a highlighted target square\n then: Move submitted via submitMove(); board updated on success\n\n req F-4.3:\n when: pawn reaches the back rank\n then: promotion dialog shown via overlay slot; player selects piece kind\n\n req F-4.4:\n when: Game.status is finished\n then: result overlay shown (winner or draw); further moves disabled\n```\n\n```mdl\nfeat F-5: Move Validation\n\n req F-5.1:\n when: Gameboard calls submitMove\n then: op:validateMove runs before any state change\n\n req F-5.2:\n when: validation fails\n then: error returned to caller; Game state unchanged\n\n req F-5.3:\n when: square is selected on Gameboard\n then: op:getLegalMoves called; results drive component:Gameboard.highlights\n```\n\n```mdl\nfeat F-6: Game Persistence\n\n req F-6.1:\n when: op:startGame completes\n then: Game written to ECHO and visible in component:Lobby game list\n\n req F-6.2:\n when: op:submitMove completes\n then: updated Game replicated to all peers via ECHO\n\n req F-6.3:\n when: peer receives a Game update\n then: component:Gameboard re-renders with new Board state\n tags: [collaborative]\n```\n\n## Acceptance\n\n```mdl\ntest T-1: New game starting position\n given: a new game is started\n then:\n - Board.turn === white\n - Board.status === playing\n - each player has 16 pieces in standard positions\n```\n\n```mdl\ntest T-2: Illegal move rejected\n given: it is white's turn\n when: white attempts to move a black piece\n then: WrongTurn error; Board unchanged\n```\n\n```mdl\ntest T-3: Create and join game\n given: two players are in the Lobby\n when: player A creates a game, player B joins it\n then:\n - Game.status === active\n - Game.players[0].color === white # creator\n - Game.players[1].color === black # joiner\n - both players see the Gameboard\n```\n\n```mdl\ntest T-4: Legal move highlight\n given: Gameboard is shown, it is white's turn\n when: white selects the e2 pawn\n then:\n - squares e3 and e4 are highlighted\n - no other squares are highlighted\n```\n\n```mdl\ntest T-5: Pawn promotion\n given: white pawn is on e7, it is white's turn\n when: white moves pawn to e8\n then:\n - promotion overlay appears\n - after player selects queen, Move recorded with promotion: queen\n - board shows white queen on e8\n```\n\n```mdl\ntest T-6: Submit valid move\n given: active game, white's turn, white player logged in\n when: white submits pawn e2\u2192e4\n then:\n - op:validateMove returns move without error\n - Board updated: e4 occupied by white pawn, e2 empty\n - Game.board.turn === black\n - Game persisted to ECHO\n```\n\n```mdl\ntest T-7: Submit invalid move rejected atomically\n given: active game, white's turn\n when: white submits an illegal move (e2\u2192e5)\n then:\n - IllegalMove error returned\n - Game.board unchanged\n - no ECHO write occurs\n```\n\n```mdl\ntest T-8: Legal moves highlighted\n given: new game, white's turn, Gameboard shown\n when: player selects e2\n then:\n - op:getLegalMoves returns [e3, e4]\n - Gameboard.highlights === [e3, e4]\n```\n\n---\n\n## Appendix: Extension Definitions\n\nExtension block types used in this document are defined below using\nthe core `ext` primitive \u2014 the only construct the base language provides.\n\n```mdl\next type\n uri: dxos.spec/ext/type@1.0\n desc: A named data structure with typed fields and optional literals.\n fields:\n desc?: Prose\n fields?: FieldMap # name[?]: TypeExpr (# inline comment)\n literals?: UnionList # a | b | c\n extends?: TypeRef[]\n```\n\n```mdl\next feat\n uri: dxos.spec/ext/feat@1.0\n desc: A named feature grouping one or more requirements.\n fields:\n desc?: Prose\n req: RequirementList\n nesting: self # feat blocks may contain feat blocks\n```\n\n```mdl\next test\n uri: dxos.spec/ext/test@1.0\n desc: An acceptance scenario expressed as given / when / then steps.\n fields:\n given?: Step | Step[]\n when?: Step | Step[]\n then: Step | Step[]\n tags?: TagList\n```\n\n```mdl\next component\n uri: org.dxos.mdl.component@1.0\n desc: A UI component with props, internal state, slots, actions, and events.\n fields:\n desc?: Prose\n props?: FieldMap # external inputs (immutable inside component)\n state?: FieldMap # internal reactive state\n slots?: FieldMap # named ReactNode injection points\n actions?: ActionMap # methods the component exposes or handles\n emits?: EventMap # events the component raises to its parent\n layout?: CodeBlock # ASCII sketch of visual structure (non-normative)\n```\n\n```mdl\next op\n uri: org.dxos.mdl.op@1.0\n desc: |\n A named operation with typed inputs, outputs, and declared errors.\n Pure ops have no effects or requires. Effectful ops declare both.\n fields:\n desc?: Prose\n input?: FieldMap # named input parameters\n output?: TypeExpr # return type\n errors?: ErrorMap # name: Prose (when this error occurs)\n effects?: EffectList # echo:read | echo:write | http | fs | ...\n requires?: ServiceList # injected service dependencies\n note?: Prose # implementation guidance (non-normative)\n```\n\n```mdl\next service\n uri: org.dxos.mdl.service@1.0\n desc: An external or system-level dependency providing named operations.\n fields:\n desc?: Prose\n loading?: eager | lazy\n ops?: OpMap # name(params) \u2192 ReturnType\n errors?: ErrorMap\n note?: Prose\n```\n"],
5
- "mappings": ";AAIA,SAASA,cAAc;AACvB,SAASC,qBAAqBC,iBAAiB;AAE/C,SAASC,aAAaC,kBAAkBC,uBAAuB;AAC/D,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAC7B,SAASC,aAAa;;;ACVtB;;;ADeO,IAAMC,cAAcC,OAAOC,OAAOC,IAAAA,EAAMC,KAC7CH,OAAOI,UAAU;EACfC,IAAI;EACJC,aAAaC,oBAAoBC;EACjCC,UAAUC;AACZ,CAAA,GACAC,UAAUC,yBAAyB;EAAEH,UAAUI;AAAgB,CAAA,GAC/DF,UAAUG,0BAA0B;EAAEL,UAAUM;AAAiB,CAAA,GACjEJ,UAAUK,qBAAqB;EAC7BC,OAAO;IAAEC,UAAUhB,KAAKiB,QAAQC;IAAKC,MAAM;IAAcC,SAASC;IAAYC,UAAU;EAAoB;AAC9G,CAAA,GACAb,UAAUc,gBAAgB;EAAEC,QAAQ;IAACC,MAAMC;;AAAO,CAAA,GAClDjB,UAAUkB,sBAAsB;EAAEC;AAAa,CAAA,GAC/C9B,OAAO+B,IAAI;AAGb,IAAA,sBAAehC;",
6
- "names": ["Plugin", "AppActivationEvents", "AppPlugin", "GameVariant", "OperationHandler", "SkillDefinition", "meta", "translations", "Chess", "ChessPlugin", "Plugin", "define", "meta", "pipe", "addModule", "id", "activatesOn", "AppActivationEvents", "SetupSchema", "activate", "GameVariant", "AppPlugin", "addSkillDefinitionModule", "SkillDefinition", "addOperationHandlerModule", "OperationHandler", "addPluginAssetModule", "asset", "pluginId", "profile", "key", "path", "content", "pluginSpec", "mimeType", "addSchemaModule", "schema", "Chess", "State", "addTranslationsModule", "translations", "make"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/skills/chess-skill.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Skill, Template } from '@dxos/compute';\nimport { trim } from '@dxos/util';\n\nimport { Chess, ChessOperation } from '#types';\n\nconst operations = [ChessOperation.Move, ChessOperation.Play, ChessOperation.Print];\n\nconst make = () =>\n Skill.make({\n key: Chess.SKILL_KEY,\n name: 'Chess',\n tools: Skill.toolDefinitions({ operations }),\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 When setting a chess position, always set the \"pgn\" field (move list in standard PGN notation) on the org.dxos.type.chess.state object.\n The \"fen\" field is not used by the UI for display — the board is driven exclusively from \"pgn\".\n Setting \"fen\" alone or leaving \"pgn\" empty will result in the initial position being shown.\n `,\n }),\n });\n\nconst skill: Skill.Definition = {\n key: Chess.SKILL_KEY,\n make,\n};\n\nexport default skill;\n"],
5
- "mappings": ";AAIA,SAASA,OAAOC,gBAAgB;AAChC,SAASC,YAAY;AAErB,SAASC,OAAOC,sBAAsB;AAEtC,IAAMC,aAAa;EAACD,eAAeE;EAAMF,eAAeG;EAAMH,eAAeI;;AAE7E,IAAMC,OAAO,MACXT,MAAMS,KAAK;EACTC,KAAKP,MAAMQ;EACXC,MAAM;EACNC,OAAOb,MAAMc,gBAAgB;IAAET;EAAW,CAAA;EAC1CU,cAAcd,SAASQ,KAAK;IAC1BO,QAAQd;;;;;;;;;;EAUV,CAAA;AACF,CAAA;AAEF,IAAMe,QAA0B;EAC9BP,KAAKP,MAAMQ;EACXF;AACF;AAEA,IAAA,sBAAeQ;",
6
- "names": ["Skill", "Template", "trim", "Chess", "ChessOperation", "operations", "Move", "Play", "Print", "make", "key", "SKILL_KEY", "name", "tools", "toolDefinitions", "instructions", "source", "skill"]
7
- }
@@ -1,10 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- export {
8
- __export
9
- };
10
- //# sourceMappingURL=chunk-J5LGTIGS.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,42 +0,0 @@
1
- // src/meta.ts
2
- import { Plugin } from "@dxos/app-framework";
3
-
4
- // dx.config.ts
5
- import { Config2 } from "@dxos/app-framework/config";
6
- import { trim } from "@dxos/util";
7
- var dx_config_default = Config2.make({
8
- plugin: {
9
- key: "org.dxos.plugin.chess",
10
- name: "Chess",
11
- author: "DXOS",
12
- description: trim`
13
- Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
14
- Track game history and analyze moves in real-time.
15
- `,
16
- source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess",
17
- icon: {
18
- key: "ph--shield-chevron--regular",
19
- hue: "amber"
20
- },
21
- spec: "PLUGIN.mdl",
22
- tags: [
23
- "game"
24
- ],
25
- screenshots: [
26
- {
27
- dark: "https://dxos.network/plugin-details-chess-dark.png"
28
- }
29
- ],
30
- dependsOn: [
31
- "org.dxos.plugin.game"
32
- ]
33
- }
34
- });
35
-
36
- // src/meta.ts
37
- var meta = Plugin.getMetaFromConfig(dx_config_default);
38
-
39
- export {
40
- meta
41
- };
42
- //# sourceMappingURL=chunk-YZTKZ5F7.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts", "../../../dx.config.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\n\nimport config from '../dx.config';\n\nexport const meta = Plugin.getMetaFromConfig(config);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Config2 } from '@dxos/app-framework/config';\nimport { trim } from '@dxos/util';\n\nexport default Config2.make({\n plugin: {\n key: 'org.dxos.plugin.chess',\n name: 'Chess',\n author: 'DXOS',\n description: trim`\n Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.\n Track game history and analyze moves in real-time.\n `,\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',\n icon: { key: 'ph--shield-chevron--regular', hue: 'amber' },\n spec: 'PLUGIN.mdl',\n tags: ['game'],\n screenshots: [{ dark: 'https://dxos.network/plugin-details-chess-dark.png' }],\n dependsOn: ['org.dxos.plugin.game'],\n },\n});\n"],
5
- "mappings": ";AAIA,SAASA,cAAc;;;ACAvB,SAASC,eAAe;AACxB,SAASC,YAAY;AAErB,IAAA,oBAAeD,QAAQE,KAAK;EAC1BC,QAAQ;IACNC,KAAK;IACLC,MAAM;IACNC,QAAQ;IACRC,aAAaN;;;;IAIbO,QAAQ;IACRC,MAAM;MAAEL,KAAK;MAA+BM,KAAK;IAAQ;IACzDC,MAAM;IACNC,MAAM;MAAC;;IACPC,aAAa;MAAC;QAAEC,MAAM;MAAqD;;IAC3EC,WAAW;MAAC;;EACd;AACF,CAAA;;;ADfO,IAAMC,OAAOC,OAAOC,kBAAkBC,iBAAAA;",
6
- "names": ["Plugin", "Config2", "trim", "make", "plugin", "key", "name", "author", "description", "source", "icon", "hue", "spec", "tags", "screenshots", "dark", "dependsOn", "meta", "Plugin", "getMetaFromConfig", "config"]
7
- }
@@ -1,240 +0,0 @@
1
- import "../chunk-J5LGTIGS.mjs";
2
-
3
- // src/components/Chessboard/Chessboard.tsx
4
- import { RegistryContext } from "@effect-atom/atom-react";
5
- import React2, { forwardRef, useCallback, useContext, useEffect as useEffect2, useImperativeHandle, useMemo as useMemo2 } from "react";
6
- import { useObject } from "@dxos/echo-react";
7
- import { useSoundEffect } from "@dxos/react-ui-audio";
8
- import { Gameboard, Chessboard as NaturalChessboard, getRawPgn } from "@dxos/react-ui-gameboard";
9
-
10
- // src/components/Chessboard/Info.tsx
11
- import { useAtomValue } from "@effect-atom/atom-react";
12
- import React, { useEffect, useMemo, useRef } from "react";
13
- import { Icon, IconButton, useTranslation } from "@dxos/react-ui";
14
- import { useGameboardContext } from "@dxos/react-ui-gameboard";
15
- import { mx } from "@dxos/ui-theme";
16
- import { meta } from "#meta";
17
- var INFO_NAME = "Chessboard.Info";
18
- var Info = ({ classNames, orientation = "white", onOrientationChange, onClose, ...props }) => {
19
- const { t } = useTranslation(meta.profile.key);
20
- const { model } = useGameboardContext(INFO_NAME);
21
- return /* @__PURE__ */ React.createElement("div", {
22
- className: mx("grid grid-rows-[min-content_1fr_min-content] w-full min-w-[18rem] p-2 overflow-hidden bg-group-surface rounded-xs", classNames)
23
- }, /* @__PURE__ */ React.createElement(PlayerIndicator, {
24
- model,
25
- player: orientation === "white" ? "black" : "white",
26
- icon: onClose && /* @__PURE__ */ React.createElement(IconButton, {
27
- variant: "ghost",
28
- icon: "ph--x--regular",
29
- iconOnly: true,
30
- label: t("close-info.button"),
31
- size: 4,
32
- onClick: onClose
33
- })
34
- }), /* @__PURE__ */ React.createElement(History, {
35
- model,
36
- ...props
37
- }), /* @__PURE__ */ React.createElement(PlayerIndicator, {
38
- model,
39
- player: orientation,
40
- icon: onOrientationChange && /* @__PURE__ */ React.createElement(IconButton, {
41
- classNames: mx("transition duration-200 ease-linear", orientation === "white" && "rotate-180"),
42
- icon: "ph--arrows-clockwise--regular",
43
- iconOnly: true,
44
- label: t("flip-board.button"),
45
- size: 4,
46
- onClick: () => onOrientationChange(orientation === "white" ? "black" : "white")
47
- })
48
- }));
49
- };
50
- Info.displayName = INFO_NAME;
51
- var History = ({ classNames, model, min, max, onSelect }) => {
52
- const { t } = useTranslation(meta.profile.key);
53
- const moveIndex = useAtomValue(model.moveIndex);
54
- const label = model.game.isGameOver() ? model.game.isCheckmate() ? t("game.checkmate.label") : model.game.isStalemate() ? t("game.stalemate.label") : t("game.draw.label") : model.game.isCheck() ? t("game.check.label") : void 0;
55
- const history = model.game.history();
56
- const moves = useMemo(() => history.reduce((acc, move, index) => {
57
- if (index % 2 === 0) {
58
- acc.push([
59
- {
60
- index,
61
- move
62
- }
63
- ]);
64
- } else {
65
- acc[acc.length - 1].push({
66
- index,
67
- move
68
- });
69
- }
70
- return acc;
71
- }, []), [
72
- history.length
73
- ]);
74
- const scrollerRef = useRef(null);
75
- useEffect(() => {
76
- scrollerRef.current?.scrollTo({
77
- top: scrollerRef.current.scrollHeight
78
- });
79
- }, [
80
- history.length
81
- ]);
82
- useEffect(() => {
83
- const div = scrollerRef.current?.querySelector(`[data-index="${moveIndex - 1}"]`);
84
- scrollerRef.current?.classList.add("scrollbar-none");
85
- div?.scrollIntoView({
86
- behavior: "smooth"
87
- });
88
- scrollerRef.current?.classList.remove("scrollbar-none");
89
- }, [
90
- moveIndex
91
- ]);
92
- return /* @__PURE__ */ React.createElement("div", {
93
- ref: scrollerRef,
94
- tabIndex: 0,
95
- "data-chessboard-arrow-navigation": true,
96
- className: mx("overflow-y-auto outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500", classNames),
97
- style: {
98
- minHeight: min === void 0 ? "auto" : `${min * 24}px`,
99
- maxHeight: max === void 0 ? "auto" : `${max * 24}px`
100
- }
101
- }, moves.map(([a, b], index) => /* @__PURE__ */ React.createElement("div", {
102
- key: index,
103
- className: "grid grid-cols-[3rem_1fr_1fr_1rem] gap-2 ps-4"
104
- }, /* @__PURE__ */ React.createElement("div", {
105
- className: "content-center text-xs text-subdued"
106
- }, index + 1), a && /* @__PURE__ */ React.createElement("div", {
107
- "data-index": a.index,
108
- className: mx("ps-2 text-sm cursor-pointer", a.index === moveIndex - 1 && "bg-primary-500"),
109
- onClick: () => onSelect?.(a.index + 1)
110
- }, a.move), b && /* @__PURE__ */ React.createElement("div", {
111
- "data-index": b.index,
112
- className: mx("ps-2 text-sm cursor-pointer", b.index === moveIndex - 1 && "bg-primary-500"),
113
- onClick: () => onSelect?.(b.index + 1)
114
- }, b.move))), label && /* @__PURE__ */ React.createElement("div", {
115
- className: "text-center"
116
- }, label));
117
- };
118
- var PlayerIndicator = ({ children, model, player, icon }) => {
119
- const turn = player === (model.game.turn() === "w" ? "white" : "black");
120
- return /* @__PURE__ */ React.createElement("div", {
121
- className: "grid grid-cols-[2rem_1fr_2rem] gap-2 h-(--dx-rail-size) px-1 flex items-center overflow-hidden"
122
- }, /* @__PURE__ */ React.createElement("div", {
123
- className: "place-items-center"
124
- }, /* @__PURE__ */ React.createElement(Icon, {
125
- icon: turn ? "ph--circle--fill" : "ph--circle--thin",
126
- size: 6,
127
- classNames: mx(turn && (model.game.isCheckmate() ? "text-error-500" : "text-success-text"))
128
- })), /* @__PURE__ */ React.createElement("div", {
129
- className: "truncate overflow-hidden items-center"
130
- }, children), icon);
131
- };
132
-
133
- // src/components/Chessboard/types.ts
134
- import { ChessModel } from "@dxos/react-ui-gameboard";
135
- var ExtendedChessModel = class extends ChessModel {
136
- object;
137
- constructor(registry, object) {
138
- super(registry), this.object = object;
139
- }
140
- };
141
-
142
- // src/components/Chessboard/Chessboard.tsx
143
- var Root = /* @__PURE__ */ forwardRef(({ state, children }, forwardedRef) => {
144
- const registry = useContext(RegistryContext);
145
- const model = useMemo2(() => new ExtendedChessModel(registry, state), [
146
- registry
147
- ]);
148
- const click = useSoundEffect("Click");
149
- const [pgn, updatePgn] = useObject(state, "pgn");
150
- useImperativeHandle(forwardedRef, () => {
151
- return {
152
- setMoveNumber: (index) => model.setMoveIndex(index)
153
- };
154
- }, [
155
- model
156
- ]);
157
- useEffect2(() => {
158
- if (model.pgn !== getRawPgn(pgn ?? "")) {
159
- const silent = model.pgn === "*";
160
- model.update(pgn);
161
- if (!silent) {
162
- void click.play();
163
- }
164
- }
165
- }, [
166
- pgn
167
- ]);
168
- const handleDrop = useCallback((move) => {
169
- if (!model.makeMove(move)) {
170
- return false;
171
- }
172
- void click.play();
173
- updatePgn(() => model.pgn);
174
- return true;
175
- }, [
176
- model
177
- ]);
178
- const handleKeyDown = useCallback((ev) => {
179
- const target = ev.target instanceof HTMLElement ? ev.target : void 0;
180
- if (!target?.closest("[data-chessboard-arrow-navigation]")) {
181
- return;
182
- }
183
- const moveIndex = registry.get(model.moveIndex);
184
- switch (ev.key) {
185
- case "ArrowUp":
186
- ev.preventDefault();
187
- model.setMoveIndex(0);
188
- break;
189
- case "ArrowDown":
190
- ev.preventDefault();
191
- model.setMoveIndex(model.game.history().length);
192
- break;
193
- case "ArrowLeft":
194
- if (moveIndex > 0) {
195
- ev.preventDefault();
196
- model.setMoveIndex(moveIndex - 1);
197
- }
198
- break;
199
- case "ArrowRight":
200
- if (moveIndex < model.game.history().length) {
201
- ev.preventDefault();
202
- model.setMoveIndex(moveIndex + 1);
203
- }
204
- break;
205
- }
206
- }, [
207
- registry,
208
- model
209
- ]);
210
- return /* @__PURE__ */ React2.createElement(Gameboard.Root, {
211
- model,
212
- onDrop: handleDrop
213
- }, /* @__PURE__ */ React2.createElement("div", {
214
- className: "contents",
215
- onKeyDown: handleKeyDown
216
- }, children));
217
- });
218
- var Content = ({ classNames, children }) => {
219
- return /* @__PURE__ */ React2.createElement(Gameboard.Content, {
220
- grow: true,
221
- contain: true,
222
- classNames
223
- }, children);
224
- };
225
- var BOARD_NAME = "Chessboard.Board";
226
- var Board = (props) => /* @__PURE__ */ React2.createElement("div", {
227
- className: "contents",
228
- "data-chessboard-arrow-navigation": true
229
- }, /* @__PURE__ */ React2.createElement(NaturalChessboard, props));
230
- Board.displayName = BOARD_NAME;
231
- var Chessboard = {
232
- Root,
233
- Content,
234
- Board,
235
- Info
236
- };
237
- export {
238
- Chessboard
239
- };
240
- //# sourceMappingURL=index.mjs.map