@dxos/react-ui-gameboard 0.8.4-main.fd6878d → 0.8.4-staging.ac66bdf99f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/lib/browser/index.mjs +643 -730
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +643 -730
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +9 -4
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +21 -18
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/chess.d.ts +15 -8
- package/dist/types/src/components/Chessboard/chess.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/chess.test.d.ts +2 -0
- package/dist/types/src/components/Chessboard/chess.test.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/Gameboard.d.ts +6 -6
- package/dist/types/src/components/Gameboard/Gameboard.d.ts.map +1 -1
- package/dist/types/src/components/Gameboard/Piece.d.ts +1 -1
- package/dist/types/src/components/Gameboard/Piece.d.ts.map +1 -1
- package/dist/types/src/components/Gameboard/Square.d.ts.map +1 -1
- package/dist/types/src/components/Gameboard/types.d.ts +3 -3
- package/dist/types/src/components/Gameboard/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -23
- package/src/components/Chessboard/Chessboard.stories.tsx +20 -18
- package/src/components/Chessboard/Chessboard.tsx +44 -30
- package/src/components/Chessboard/chess.test.ts +19 -0
- package/src/components/Chessboard/chess.ts +111 -59
- package/src/components/Gameboard/Gameboard.tsx +8 -8
- package/src/components/Gameboard/Piece.tsx +13 -8
- package/src/components/Gameboard/Square.tsx +5 -3
- package/src/components/Gameboard/types.ts +3 -3
|
@@ -24,15 +24,13 @@ var getRelativeBounds = (container, element) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// src/components/Gameboard/Gameboard.tsx
|
|
27
|
-
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
28
27
|
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
29
28
|
import { createContext } from "@radix-ui/react-context";
|
|
30
29
|
import React3, { forwardRef, useCallback, useEffect as useEffect3, useState as useState3 } from "react";
|
|
31
30
|
import { log as log3 } from "@dxos/log";
|
|
32
|
-
import { mx as mx3 } from "@dxos/
|
|
31
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
33
32
|
|
|
34
33
|
// src/components/Gameboard/Piece.tsx
|
|
35
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
36
34
|
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
37
35
|
import { centerUnderPointer } from "@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer";
|
|
38
36
|
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
@@ -40,219 +38,205 @@ import React, { memo, useEffect, useRef, useState } from "react";
|
|
|
40
38
|
import { createPortal } from "react-dom";
|
|
41
39
|
import { invariant } from "@dxos/invariant";
|
|
42
40
|
import { log } from "@dxos/log";
|
|
43
|
-
import { useDynamicRef
|
|
44
|
-
import { mx } from "@dxos/
|
|
41
|
+
import { useDynamicRef } from "@dxos/react-ui";
|
|
42
|
+
import { mx } from "@dxos/ui-theme";
|
|
45
43
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Piece.tsx";
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const location = current2.dropTargets[0]?.data.location;
|
|
107
|
-
if (isLocation(location)) {
|
|
108
|
-
setCurrent((current3) => ({
|
|
109
|
-
...current3,
|
|
110
|
-
location
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
} catch {
|
|
44
|
+
var PIECE_NAME = "Piece";
|
|
45
|
+
var Piece = /* @__PURE__ */ memo(({ classNames, Component, piece, bounds, label, onClick }) => {
|
|
46
|
+
const { model, dragging: isDragging, promoting } = useGameboardContext(PIECE_NAME);
|
|
47
|
+
const promotingRef = useDynamicRef(promoting);
|
|
48
|
+
const [dragging, setDragging] = useState(false);
|
|
49
|
+
const [preview, setPreview] = useState();
|
|
50
|
+
const [current, setCurrent] = useState({});
|
|
51
|
+
const ref = useRef(null);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!model) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const el = ref.current;
|
|
57
|
+
invariant(el, void 0, {
|
|
58
|
+
F: __dxlog_file,
|
|
59
|
+
L: 47,
|
|
60
|
+
S: void 0,
|
|
61
|
+
A: [
|
|
62
|
+
"el",
|
|
63
|
+
""
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
return draggable({
|
|
67
|
+
element: el,
|
|
68
|
+
getInitialData: () => ({
|
|
69
|
+
piece
|
|
70
|
+
}),
|
|
71
|
+
onGenerateDragPreview: ({ nativeSetDragImage, source }) => {
|
|
72
|
+
log("onGenerateDragPreview", {
|
|
73
|
+
source: source.data
|
|
74
|
+
}, {
|
|
75
|
+
F: __dxlog_file,
|
|
76
|
+
L: 53,
|
|
77
|
+
S: void 0,
|
|
78
|
+
C: (f, a) => f(...a)
|
|
79
|
+
});
|
|
80
|
+
setCustomNativeDragPreview({
|
|
81
|
+
getOffset: centerUnderPointer,
|
|
82
|
+
render: ({ container }) => {
|
|
83
|
+
setPreview(container);
|
|
84
|
+
const { width, height } = el.getBoundingClientRect();
|
|
85
|
+
container.style.width = width + "px";
|
|
86
|
+
container.style.height = height + "px";
|
|
87
|
+
return () => {
|
|
88
|
+
setPreview(void 0);
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
nativeSetDragImage
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
canDrag: () => !promotingRef.current && !model.readonly && model.turn === piece.side,
|
|
95
|
+
onDragStart: () => setDragging(true),
|
|
96
|
+
onDrop: ({ location: { current: current2 } }) => {
|
|
97
|
+
try {
|
|
98
|
+
const location = current2.dropTargets[0]?.data.location;
|
|
99
|
+
if (isLocation(location)) {
|
|
100
|
+
setCurrent((current3) => ({
|
|
101
|
+
...current3,
|
|
102
|
+
location
|
|
103
|
+
}));
|
|
114
104
|
}
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}, [
|
|
119
|
-
model,
|
|
120
|
-
piece
|
|
121
|
-
]);
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
requestAnimationFrame(() => {
|
|
124
|
-
if (!ref.current || !bounds) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (!current.location || !isEqualLocation(current.location, piece.location)) {
|
|
128
|
-
ref.current.style.transition = "top 400ms ease-out, left 400ms ease-out";
|
|
129
|
-
ref.current.style.top = bounds.top + "px";
|
|
130
|
-
ref.current.style.left = bounds.left + "px";
|
|
131
|
-
setCurrent({
|
|
132
|
-
location: piece.location,
|
|
133
|
-
bounds
|
|
134
|
-
});
|
|
135
|
-
} else if (current.bounds !== bounds) {
|
|
136
|
-
ref.current.style.transition = "none";
|
|
137
|
-
ref.current.style.top = bounds.top + "px";
|
|
138
|
-
ref.current.style.left = bounds.left + "px";
|
|
139
|
-
setCurrent({
|
|
140
|
-
location: piece.location,
|
|
141
|
-
bounds
|
|
142
|
-
});
|
|
105
|
+
} catch {
|
|
143
106
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
107
|
+
setDragging(false);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}, [
|
|
111
|
+
model,
|
|
112
|
+
piece
|
|
113
|
+
]);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
requestAnimationFrame(() => {
|
|
116
|
+
if (!ref.current || !bounds) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!current.location || !isEqualLocation(current.location, piece.location)) {
|
|
120
|
+
ref.current.style.transition = "top 250ms ease-out, left 250ms ease-out";
|
|
121
|
+
ref.current.style.top = bounds.top + "px";
|
|
122
|
+
ref.current.style.left = bounds.left + "px";
|
|
123
|
+
setCurrent({
|
|
124
|
+
location: piece.location,
|
|
125
|
+
bounds
|
|
126
|
+
});
|
|
127
|
+
} else if (current.bounds !== bounds) {
|
|
128
|
+
ref.current.style.transition = "none";
|
|
129
|
+
ref.current.style.top = bounds.top + "px";
|
|
130
|
+
ref.current.style.left = bounds.left + "px";
|
|
131
|
+
setCurrent({
|
|
132
|
+
location: piece.location,
|
|
133
|
+
bounds
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}, [
|
|
138
|
+
current,
|
|
139
|
+
piece.location,
|
|
140
|
+
bounds
|
|
141
|
+
]);
|
|
142
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
143
|
+
ref,
|
|
144
|
+
style: {
|
|
145
|
+
width: bounds?.width,
|
|
146
|
+
height: bounds?.height
|
|
147
|
+
},
|
|
148
|
+
className: mx("absolute", classNames, dragging && "opacity-20", isDragging && "pointer-events-none"),
|
|
149
|
+
onClick
|
|
150
|
+
}, /* @__PURE__ */ React.createElement(Component, {
|
|
151
|
+
className: "grow"
|
|
152
|
+
}), label && /* @__PURE__ */ React.createElement("div", {
|
|
153
|
+
className: "absolute inset-1 text-xs text-black"
|
|
154
|
+
}, label)), preview && /* @__PURE__ */ createPortal(/* @__PURE__ */ React.createElement("div", {
|
|
155
|
+
className: mx(classNames)
|
|
156
|
+
}, /* @__PURE__ */ React.createElement(Component, {
|
|
157
|
+
className: "grow"
|
|
158
|
+
})), preview));
|
|
170
159
|
});
|
|
171
|
-
Piece.displayName =
|
|
160
|
+
Piece.displayName = PIECE_NAME;
|
|
172
161
|
|
|
173
162
|
// src/components/Gameboard/Square.tsx
|
|
174
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
175
163
|
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
176
164
|
import React2, { memo as memo2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
177
165
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
178
166
|
import { log as log2 } from "@dxos/log";
|
|
179
|
-
import { mx as mx2 } from "@dxos/
|
|
167
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
180
168
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Square.tsx";
|
|
169
|
+
var SQUARE_NAME = "Square";
|
|
181
170
|
var Square = /* @__PURE__ */ memo2(({ location, bounds, label, classNames }) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
className: mx2("absolute bottom-1 left-1 text-xs text-neutral-500")
|
|
250
|
-
}, label));
|
|
251
|
-
} finally {
|
|
252
|
-
_effect.f();
|
|
253
|
-
}
|
|
171
|
+
const ref = useRef2(null);
|
|
172
|
+
const [state, setState] = useState2("idle");
|
|
173
|
+
const { model } = useGameboardContext(SQUARE_NAME);
|
|
174
|
+
useEffect2(() => {
|
|
175
|
+
const el = ref.current;
|
|
176
|
+
invariant2(el, void 0, {
|
|
177
|
+
F: __dxlog_file2,
|
|
178
|
+
L: 34,
|
|
179
|
+
S: void 0,
|
|
180
|
+
A: [
|
|
181
|
+
"el",
|
|
182
|
+
""
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
return dropTargetForElements({
|
|
186
|
+
element: el,
|
|
187
|
+
getData: () => ({
|
|
188
|
+
location
|
|
189
|
+
}),
|
|
190
|
+
canDrop: ({ source }) => {
|
|
191
|
+
log2("canDrop", {
|
|
192
|
+
source: source.data
|
|
193
|
+
}, {
|
|
194
|
+
F: __dxlog_file2,
|
|
195
|
+
L: 40,
|
|
196
|
+
S: void 0,
|
|
197
|
+
C: (f, a) => f(...a)
|
|
198
|
+
});
|
|
199
|
+
return true;
|
|
200
|
+
},
|
|
201
|
+
onDragEnter: ({ source }) => {
|
|
202
|
+
log2("onDragEnter", {
|
|
203
|
+
source: source.data
|
|
204
|
+
}, {
|
|
205
|
+
F: __dxlog_file2,
|
|
206
|
+
L: 44,
|
|
207
|
+
S: void 0,
|
|
208
|
+
C: (f, a) => f(...a)
|
|
209
|
+
});
|
|
210
|
+
const piece = source.data.piece;
|
|
211
|
+
if (!isPiece(piece)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (model?.isValidMove({
|
|
215
|
+
from: piece.location,
|
|
216
|
+
to: location,
|
|
217
|
+
piece: piece.type
|
|
218
|
+
})) {
|
|
219
|
+
setState("validMove");
|
|
220
|
+
} else {
|
|
221
|
+
setState("invalidMove");
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
onDragLeave: () => setState("idle"),
|
|
225
|
+
onDrop: () => setState("idle")
|
|
226
|
+
});
|
|
227
|
+
}, [
|
|
228
|
+
model,
|
|
229
|
+
location
|
|
230
|
+
]);
|
|
231
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
232
|
+
ref,
|
|
233
|
+
style: bounds,
|
|
234
|
+
className: mx2("absolute flex justify-center items-center border-2 box-border select-none", classNames, state === "validMove" ? "border-neutral-800" : "border-transparent")
|
|
235
|
+
}, label && /* @__PURE__ */ React2.createElement("div", {
|
|
236
|
+
className: mx2("absolute bottom-1 left-1 text-xs text-neutral-500")
|
|
237
|
+
}, label));
|
|
254
238
|
});
|
|
255
|
-
Square.displayName =
|
|
239
|
+
Square.displayName = SQUARE_NAME;
|
|
256
240
|
|
|
257
241
|
// src/components/Gameboard/Gameboard.tsx
|
|
258
242
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Gameboard.tsx";
|
|
@@ -261,102 +245,92 @@ var useGameboardContext = (consumerName) => {
|
|
|
261
245
|
return useRadixGameboardContext(consumerName);
|
|
262
246
|
};
|
|
263
247
|
var GameboardRoot = ({ children, model, onDrop }) => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
} else {
|
|
327
|
-
onDrop?.(move);
|
|
328
|
-
}
|
|
248
|
+
const [dragging, setDragging] = useState3(false);
|
|
249
|
+
const [promoting, setPromoting] = useState3();
|
|
250
|
+
const handlePromotion = useCallback((move) => {
|
|
251
|
+
log3("onPromotion", {
|
|
252
|
+
move
|
|
253
|
+
}, {
|
|
254
|
+
F: __dxlog_file3,
|
|
255
|
+
L: 47,
|
|
256
|
+
S: void 0,
|
|
257
|
+
C: (f, a) => f(...a)
|
|
258
|
+
});
|
|
259
|
+
setPromoting(void 0);
|
|
260
|
+
onDrop?.(move);
|
|
261
|
+
}, []);
|
|
262
|
+
useEffect3(() => {
|
|
263
|
+
if (!model) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
return monitorForElements({
|
|
267
|
+
onDragStart: ({ source }) => {
|
|
268
|
+
log3("onDragStart", {
|
|
269
|
+
source
|
|
270
|
+
}, {
|
|
271
|
+
F: __dxlog_file3,
|
|
272
|
+
L: 60,
|
|
273
|
+
S: void 0,
|
|
274
|
+
C: (f, a) => f(...a)
|
|
275
|
+
});
|
|
276
|
+
setDragging(true);
|
|
277
|
+
},
|
|
278
|
+
onDrop: ({ source, location }) => {
|
|
279
|
+
log3("onDrop", {
|
|
280
|
+
source,
|
|
281
|
+
location
|
|
282
|
+
}, {
|
|
283
|
+
F: __dxlog_file3,
|
|
284
|
+
L: 64,
|
|
285
|
+
S: void 0,
|
|
286
|
+
C: (f, a) => f(...a)
|
|
287
|
+
});
|
|
288
|
+
const target = location.current.dropTargets[0];
|
|
289
|
+
if (!target) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const targetLocation = target.data.location;
|
|
293
|
+
const piece = source.data.piece;
|
|
294
|
+
if (!isLocation(targetLocation) || !isPiece(piece)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const move = {
|
|
298
|
+
from: piece.location,
|
|
299
|
+
to: targetLocation,
|
|
300
|
+
piece: piece.type
|
|
301
|
+
};
|
|
302
|
+
if (model.isValidMove(move)) {
|
|
303
|
+
if (model.canPromote?.(move)) {
|
|
304
|
+
setPromoting({
|
|
305
|
+
...piece,
|
|
306
|
+
location: targetLocation
|
|
307
|
+
});
|
|
308
|
+
} else {
|
|
309
|
+
onDrop?.(move);
|
|
329
310
|
}
|
|
330
|
-
setDragging(false);
|
|
331
311
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
312
|
+
setDragging(false);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}, [
|
|
316
|
+
model
|
|
317
|
+
]);
|
|
318
|
+
return /* @__PURE__ */ React3.createElement(GameboardContextProvider, {
|
|
319
|
+
model,
|
|
320
|
+
dragging,
|
|
321
|
+
promoting,
|
|
322
|
+
onPromotion: handlePromotion
|
|
323
|
+
}, children);
|
|
345
324
|
};
|
|
346
325
|
GameboardRoot.displayName = "Gameboard.Root";
|
|
347
326
|
var GameboardContent = /* @__PURE__ */ forwardRef(({ children, classNames, grow, contain }, forwardedRef) => {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
className: "is-[min(100cqw,100cqh)] bs-[min(100cqw,100cqh)]"
|
|
356
|
-
}, children) : children);
|
|
357
|
-
} finally {
|
|
358
|
-
_effect.f();
|
|
359
|
-
}
|
|
327
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
328
|
+
role: "none",
|
|
329
|
+
className: mx3(grow && "dx-size-container dx-expander grid place-content-center", classNames),
|
|
330
|
+
ref: forwardedRef
|
|
331
|
+
}, contain ? /* @__PURE__ */ React3.createElement("div", {
|
|
332
|
+
className: "w-[min(100cqw,100cqh)] h-[min(100cqw,100cqh)]"
|
|
333
|
+
}, children) : children);
|
|
360
334
|
});
|
|
361
335
|
GameboardContent.displayName = "Gameboard.Content";
|
|
362
336
|
var Gameboard = {
|
|
@@ -367,8 +341,9 @@ var Gameboard = {
|
|
|
367
341
|
};
|
|
368
342
|
|
|
369
343
|
// src/components/Chessboard/chess.ts
|
|
370
|
-
import {
|
|
344
|
+
import { Atom } from "@effect-atom/atom-react";
|
|
371
345
|
import { Chess as ChessJS } from "chess.js";
|
|
346
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
372
347
|
import { log as log4 } from "@dxos/log";
|
|
373
348
|
|
|
374
349
|
// src/gen/pieces/chess/alpha/index.ts
|
|
@@ -389,276 +364,180 @@ __export(alpha_exports, {
|
|
|
389
364
|
});
|
|
390
365
|
|
|
391
366
|
// src/gen/pieces/chess/alpha/bB.tsx
|
|
392
|
-
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
393
367
|
import * as React4 from "react";
|
|
394
|
-
var SvgBB = (props) => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
fill: "#101010",
|
|
406
|
-
d: "M768 1365q-5 39-26 82h564q-18-36-26-82zm495-73 46-73q-142-49-285-47-144-2-285 47l46 73q118-40 239-38 120-2 239 38m-432 227H624q67-116 72-229-114-119-162-223t-6-224q33-96 118-189t312-247q-17-11-46-36t-29-79q0-58 41-96t100-38q58 0 100 38t41 96q0 54-29 79t-46 36q226 153 311 247t119 189q42 119-6 224t-162 223q4 113 72 229h-207l10 16q33 53 70 60t89 7h250q76 0 142 62t65 179h-495q-123 0-223-84t-101-199q0 114-101 199t-223 84H205q0-117 65-179t142-62h250q51 0 88-7t71-60zm146-701h-95v89h95v165h94V907h95v-89h-95V714h-94z"
|
|
407
|
-
}));
|
|
408
|
-
} finally {
|
|
409
|
-
_effect.f();
|
|
410
|
-
}
|
|
411
|
-
};
|
|
368
|
+
var SvgBB = (props) => /* @__PURE__ */ React4.createElement("svg", {
|
|
369
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
370
|
+
viewBox: "0 0 2048 2048",
|
|
371
|
+
...props
|
|
372
|
+
}, /* @__PURE__ */ React4.createElement("path", {
|
|
373
|
+
fill: "#f9f9f9",
|
|
374
|
+
d: "M732 1290 628 993l386-417 421 375-132 380 49 152-658-9z"
|
|
375
|
+
}), /* @__PURE__ */ React4.createElement("path", {
|
|
376
|
+
fill: "#101010",
|
|
377
|
+
d: "M768 1365q-5 39-26 82h564q-18-36-26-82zm495-73 46-73q-142-49-285-47-144-2-285 47l46 73q118-40 239-38 120-2 239 38m-432 227H624q67-116 72-229-114-119-162-223t-6-224q33-96 118-189t312-247q-17-11-46-36t-29-79q0-58 41-96t100-38q58 0 100 38t41 96q0 54-29 79t-46 36q226 153 311 247t119 189q42 119-6 224t-162 223q4 113 72 229h-207l10 16q33 53 70 60t89 7h250q76 0 142 62t65 179h-495q-123 0-223-84t-101-199q0 114-101 199t-223 84H205q0-117 65-179t142-62h250q51 0 88-7t71-60zm146-701h-95v89h95v165h94V907h95v-89h-95V714h-94z"
|
|
378
|
+
}));
|
|
412
379
|
var bB_default = SvgBB;
|
|
413
380
|
|
|
414
381
|
// src/gen/pieces/chess/alpha/bK.tsx
|
|
415
|
-
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
|
416
382
|
import * as React5 from "react";
|
|
417
|
-
var SvgBK = (props) => {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
fill: "#101010",
|
|
429
|
-
d: "M1024 1769h489l-12-73H547l-12 73zm0-921q-25-60-62-111 31-48 62-65 30 17 62 65-38 51-62 111m-97 454q-154 11-303 58-123-108-200-213t-77-202q0-89 74-159t148-70q67 0 135 63t102 130q30 54 75 175t46 218m-350 217-26 156 145-84zm447-907q-47 0-136 121-31-36-50-55 93-140 186-140 92 0 186 140-20 19-50 55-90-121-136-121m0 775q-1-126-42-267t-84-227l-14-27-12-23q-28-43-48-69-51-63-120-105t-134-42q-103 0-208 93T257 949q0 120 99 255t249 259q201-74 419-76m0 456H448l61-365q-325-280-326-535-1-159 125-274t267-116q78 0 159 47t142 119q61 74 99 165t49 150q12-60 49-150t99-165q61-72 142-119t159-47q140 0 266 116t126 274q-2 255-326 535l61 365zm97-541q0-97 45-218t76-175q34-68 102-130t135-63q74 0 148 70t74 159q0 96-77 202t-200 213q-150-47-303-58m350 217-119 72 145 84zm-447-132q217 2 419 76 150-125 249-259t99-255q0-136-105-229t-208-93q-66 0-135 42t-119 105q-21 26-48 69l-12 23-14 27q-44 85-85 227t-41 267m-139 159 139 86 139-84-139-86zm92-1248v-95h94v95h107v95h-107v153q-48-16-94 0V393H870v-95z"
|
|
430
|
-
}));
|
|
431
|
-
} finally {
|
|
432
|
-
_effect.f();
|
|
433
|
-
}
|
|
434
|
-
};
|
|
383
|
+
var SvgBK = (props) => /* @__PURE__ */ React5.createElement("svg", {
|
|
384
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
385
|
+
viewBox: "0 0 2048 2048",
|
|
386
|
+
...props
|
|
387
|
+
}, /* @__PURE__ */ React5.createElement("path", {
|
|
388
|
+
fill: "#f9f9f9",
|
|
389
|
+
d: "m553 1485-55 320 1048 5-48-335s324-313 330-467c7-153-35-331-241-406-183-67-372 121-372 121l-182-161-190 160S658 586 587 592a373 373 0 0 0-362 333c10 331 328 560 328 560"
|
|
390
|
+
}), /* @__PURE__ */ React5.createElement("path", {
|
|
391
|
+
fill: "#101010",
|
|
392
|
+
d: "M1024 1769h489l-12-73H547l-12 73zm0-921q-25-60-62-111 31-48 62-65 30 17 62 65-38 51-62 111m-97 454q-154 11-303 58-123-108-200-213t-77-202q0-89 74-159t148-70q67 0 135 63t102 130q30 54 75 175t46 218m-350 217-26 156 145-84zm447-907q-47 0-136 121-31-36-50-55 93-140 186-140 92 0 186 140-20 19-50 55-90-121-136-121m0 775q-1-126-42-267t-84-227l-14-27-12-23q-28-43-48-69-51-63-120-105t-134-42q-103 0-208 93T257 949q0 120 99 255t249 259q201-74 419-76m0 456H448l61-365q-325-280-326-535-1-159 125-274t267-116q78 0 159 47t142 119q61 74 99 165t49 150q12-60 49-150t99-165q61-72 142-119t159-47q140 0 266 116t126 274q-2 255-326 535l61 365zm97-541q0-97 45-218t76-175q34-68 102-130t135-63q74 0 148 70t74 159q0 96-77 202t-200 213q-150-47-303-58m350 217-119 72 145 84zm-447-132q217 2 419 76 150-125 249-259t99-255q0-136-105-229t-208-93q-66 0-135 42t-119 105q-21 26-48 69l-12 23-14 27q-44 85-85 227t-41 267m-139 159 139 86 139-84-139-86zm92-1248v-95h94v95h107v95h-107v153q-48-16-94 0V393H870v-95z"
|
|
393
|
+
}));
|
|
435
394
|
var bK_default = SvgBK;
|
|
436
395
|
|
|
437
396
|
// src/gen/pieces/chess/alpha/bN.tsx
|
|
438
|
-
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
439
397
|
import * as React6 from "react";
|
|
440
|
-
var SvgBN = (props) => {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
fill: "#101010",
|
|
452
|
-
d: "m502 868-52 1-26 64 69 21 46-55zm536-187q34 1-16-68t-80-42L826 680zm-338-98q6-39 116-107t220-144l115-154 96 217q342 172 433 418t47 603q-18 128 5 236t57 190l-1242 1q-9-178 39-301t183-238q50-11 83-39t53-59l63-1 138-29 139-97 66-207q0-17-8-34t-12-37q-62 228-161 289t-191 58q-236-42-292 60l-56 102-217-121 115-82-51-50-122 86-12-297zm981 1192q-102-130-85-308t27-363-50-351-316-276q220 164 253 342t16 351-12 329 167 276"
|
|
453
|
-
}));
|
|
454
|
-
} finally {
|
|
455
|
-
_effect.f();
|
|
456
|
-
}
|
|
457
|
-
};
|
|
398
|
+
var SvgBN = (props) => /* @__PURE__ */ React6.createElement("svg", {
|
|
399
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
400
|
+
viewBox: "0 0 2048 2048",
|
|
401
|
+
...props
|
|
402
|
+
}, /* @__PURE__ */ React6.createElement("path", {
|
|
403
|
+
fill: "#f9f9f9",
|
|
404
|
+
d: "M1658 1806c-408-301-71-920-452-1343l60-16s296 167 320 257c182 468 41 691 135 1077zM972 523l120 176-312-3zM498 981l-93-41 42-93 127 28z"
|
|
405
|
+
}), /* @__PURE__ */ React6.createElement("path", {
|
|
406
|
+
fill: "#101010",
|
|
407
|
+
d: "m502 868-52 1-26 64 69 21 46-55zm536-187q34 1-16-68t-80-42L826 680zm-338-98q6-39 116-107t220-144l115-154 96 217q342 172 433 418t47 603q-18 128 5 236t57 190l-1242 1q-9-178 39-301t183-238q50-11 83-39t53-59l63-1 138-29 139-97 66-207q0-17-8-34t-12-37q-62 228-161 289t-191 58q-236-42-292 60l-56 102-217-121 115-82-51-50-122 86-12-297zm981 1192q-102-130-85-308t27-363-50-351-316-276q220 164 253 342t16 351-12 329 167 276"
|
|
408
|
+
}));
|
|
458
409
|
var bN_default = SvgBN;
|
|
459
410
|
|
|
460
411
|
// src/gen/pieces/chess/alpha/bP.tsx
|
|
461
|
-
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
462
412
|
import * as React7 from "react";
|
|
463
|
-
var SvgBP = (props) => {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
fill: "#101010",
|
|
472
|
-
d: "M1024 1843H446v-74q-4-80 42-137t125-108q117-91 172-217t78-268H576l284-239q-86-74-86-188 0-103 73-177t177-74q103 0 177 74t73 177q0 114-86 188l284 239h-287q23 141 78 268t172 217q79 51 125 108t42 137v74z"
|
|
473
|
-
}));
|
|
474
|
-
} finally {
|
|
475
|
-
_effect.f();
|
|
476
|
-
}
|
|
477
|
-
};
|
|
413
|
+
var SvgBP = (props) => /* @__PURE__ */ React7.createElement("svg", {
|
|
414
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
415
|
+
viewBox: "0 0 2048 2048",
|
|
416
|
+
...props
|
|
417
|
+
}, /* @__PURE__ */ React7.createElement("path", {
|
|
418
|
+
fill: "#101010",
|
|
419
|
+
d: "M1024 1843H446v-74q-4-80 42-137t125-108q117-91 172-217t78-268H576l284-239q-86-74-86-188 0-103 73-177t177-74q103 0 177 74t73 177q0 114-86 188l284 239h-287q23 141 78 268t172 217q79 51 125 108t42 137v74z"
|
|
420
|
+
}));
|
|
478
421
|
var bP_default = SvgBP;
|
|
479
422
|
|
|
480
423
|
// src/gen/pieces/chess/alpha/bQ.tsx
|
|
481
|
-
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
482
424
|
import * as React8 from "react";
|
|
483
|
-
var SvgBQ = (props) => {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
fill: "#101010",
|
|
495
|
-
d: "M590 1519q4 72-15 158l134-86zm434 324H441q114-231 57.5-456.5T296 937q-12 2-19 2-54 0-92.5-38.5T146 808t38.5-92.5T277 677t92.5 38.5T408 808q0 20-6 38-4 14-15 33l196 139 100-486q-64-31-72-103-5-44 29-91t88-53q54-5 96 29t48 88q7 68-46 114l198 412 198-412q-54-46-46-114 6-54 48-88t96-29q54 6 87.5 53t29.5 91q-9 72-72 103l100 486 196-139q-12-19-15-33-6-18-6-38 0-54 38.5-92.5T1771 677t92.5 38.5T1902 808t-38.5 92.5T1771 939q-7 0-19-2-147 224-203 449.5t58 456.5zm0-450q109 0 222 28.5t213 67.5q2-41 11-89-108-42-221.5-68t-224.5-26-225 26-221 68q8 48 11 89 99-39 212-67.5t223-28.5m0 376h478q-15-34-24-73H570q-10 39-24 73zm434-250-119 72 134 86q-20-86-15-158m-573 47 139 87 139-84-139-86z"
|
|
496
|
-
}));
|
|
497
|
-
} finally {
|
|
498
|
-
_effect.f();
|
|
499
|
-
}
|
|
500
|
-
};
|
|
425
|
+
var SvgBQ = (props) => /* @__PURE__ */ React8.createElement("svg", {
|
|
426
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
427
|
+
viewBox: "0 0 2048 2048",
|
|
428
|
+
...props
|
|
429
|
+
}, /* @__PURE__ */ React8.createElement("path", {
|
|
430
|
+
fill: "#f9f9f9",
|
|
431
|
+
d: "m520 1801.8 41.5-448.7 474-128.9 458 133.5 34.4 446.4z"
|
|
432
|
+
}), /* @__PURE__ */ React8.createElement("path", {
|
|
433
|
+
fill: "#101010",
|
|
434
|
+
d: "M590 1519q4 72-15 158l134-86zm434 324H441q114-231 57.5-456.5T296 937q-12 2-19 2-54 0-92.5-38.5T146 808t38.5-92.5T277 677t92.5 38.5T408 808q0 20-6 38-4 14-15 33l196 139 100-486q-64-31-72-103-5-44 29-91t88-53q54-5 96 29t48 88q7 68-46 114l198 412 198-412q-54-46-46-114 6-54 48-88t96-29q54 6 87.5 53t29.5 91q-9 72-72 103l100 486 196-139q-12-19-15-33-6-18-6-38 0-54 38.5-92.5T1771 677t92.5 38.5T1902 808t-38.5 92.5T1771 939q-7 0-19-2-147 224-203 449.5t58 456.5zm0-450q109 0 222 28.5t213 67.5q2-41 11-89-108-42-221.5-68t-224.5-26-225 26-221 68q8 48 11 89 99-39 212-67.5t223-28.5m0 376h478q-15-34-24-73H570q-10 39-24 73zm434-250-119 72 134 86q-20-86-15-158m-573 47 139 87 139-84-139-86z"
|
|
435
|
+
}));
|
|
501
436
|
var bQ_default = SvgBQ;
|
|
502
437
|
|
|
503
438
|
// src/gen/pieces/chess/alpha/bR.tsx
|
|
504
|
-
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
505
439
|
import * as React9 from "react";
|
|
506
|
-
var SvgBR = (props) => {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
fill: "#101010",
|
|
518
|
-
d: "M1024 1843H383l29-264 159-118 50-659-149-107-17-341h289v147h137V354h286v147h137V354h289l-17 341-149 107 50 659 159 118 29 264zm0-989h333l-6-88H697l-6 88zm0 647h381l-6-87H649l-6 87z"
|
|
519
|
-
}));
|
|
520
|
-
} finally {
|
|
521
|
-
_effect.f();
|
|
522
|
-
}
|
|
523
|
-
};
|
|
440
|
+
var SvgBR = (props) => /* @__PURE__ */ React9.createElement("svg", {
|
|
441
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
442
|
+
viewBox: "0 0 2048 2048",
|
|
443
|
+
...props
|
|
444
|
+
}, /* @__PURE__ */ React9.createElement("path", {
|
|
445
|
+
fill: "#f9f9f9",
|
|
446
|
+
d: "m674 732-76 807 851 14-75-833z"
|
|
447
|
+
}), /* @__PURE__ */ React9.createElement("path", {
|
|
448
|
+
fill: "#101010",
|
|
449
|
+
d: "M1024 1843H383l29-264 159-118 50-659-149-107-17-341h289v147h137V354h286v147h137V354h289l-17 341-149 107 50 659 159 118 29 264zm0-989h333l-6-88H697l-6 88zm0 647h381l-6-87H649l-6 87z"
|
|
450
|
+
}));
|
|
524
451
|
var bR_default = SvgBR;
|
|
525
452
|
|
|
526
453
|
// src/gen/pieces/chess/alpha/wB.tsx
|
|
527
|
-
import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
|
|
528
454
|
import * as React10 from "react";
|
|
529
|
-
var SvgWB = (props) => {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
fill: "#101010",
|
|
541
|
-
d: "M1024 356q66 0 64-66 1-55-64-55-66 0-64 55-3 66 64 66m0 1204q0 114-101 199t-223 84H205q0-117 65-179t142-62h250q51 0 88-7t71-60l10-16h76q-7 21-3 13-45 105-109 125t-146 19H409q-52 0-86 40t-34 53h424q66 0 159-65t93-185H624q67-116 72-229-114-119-162-223t-6-224q33-96 118-189t312-247q-17-11-46-36t-29-79q0-58 41-96t100-38q58 0 100 38t41 96q0 54-29 79t-46 36q226 153 311 247t119 189q42 119-6 224t-162 223q4 113 72 229h-341q0 120 93 185t159 65h424q0-13-34-53t-86-40h-240q-83 0-146-19t-109-125q4 8-3-13h76l10 16q33 53 70 60t89 7h250q76 0 142 62t65 179h-495q-123 0-223-84t-101-199m0-114h283q-28-84-29-154-120-41-254-38-135-3-254 38-2 70-29 154zm0-267q159-1 285 42 189-180 142-346-60-193-427-431-368 238-427 431-48 166 142 346 125-43 285-42m-47-361V714h94v104h95v89h-95v165h-94V907h-95v-89z"
|
|
542
|
-
}));
|
|
543
|
-
} finally {
|
|
544
|
-
_effect.f();
|
|
545
|
-
}
|
|
546
|
-
};
|
|
455
|
+
var SvgWB = (props) => /* @__PURE__ */ React10.createElement("svg", {
|
|
456
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
457
|
+
viewBox: "0 0 2048 2048",
|
|
458
|
+
...props
|
|
459
|
+
}, /* @__PURE__ */ React10.createElement("path", {
|
|
460
|
+
fill: "#f9f9f9",
|
|
461
|
+
d: "m948 366 1-139 148-7 1 147zM564 860c114-267 456-443 456-443s392 176 476 502c-9 209-183 332-183 332l27 221-653 6 46-233s-230-171-169-385m-101 790c175 6 355 23 425-142h92s0 190-88 246c-163 103-625 38-625 38s-15-146 196-142m631 37-36-185 102 5s22 153 315 131c381-17 318 153 318 153l-483 5z"
|
|
462
|
+
}), /* @__PURE__ */ React10.createElement("path", {
|
|
463
|
+
fill: "#101010",
|
|
464
|
+
d: "M1024 356q66 0 64-66 1-55-64-55-66 0-64 55-3 66 64 66m0 1204q0 114-101 199t-223 84H205q0-117 65-179t142-62h250q51 0 88-7t71-60l10-16h76q-7 21-3 13-45 105-109 125t-146 19H409q-52 0-86 40t-34 53h424q66 0 159-65t93-185H624q67-116 72-229-114-119-162-223t-6-224q33-96 118-189t312-247q-17-11-46-36t-29-79q0-58 41-96t100-38q58 0 100 38t41 96q0 54-29 79t-46 36q226 153 311 247t119 189q42 119-6 224t-162 223q4 113 72 229h-341q0 120 93 185t159 65h424q0-13-34-53t-86-40h-240q-83 0-146-19t-109-125q4 8-3-13h76l10 16q33 53 70 60t89 7h250q76 0 142 62t65 179h-495q-123 0-223-84t-101-199m0-114h283q-28-84-29-154-120-41-254-38-135-3-254 38-2 70-29 154zm0-267q159-1 285 42 189-180 142-346-60-193-427-431-368 238-427 431-48 166 142 346 125-43 285-42m-47-361V714h94v104h95v89h-95v165h-94V907h-95v-89z"
|
|
465
|
+
}));
|
|
547
466
|
var wB_default = SvgWB;
|
|
548
467
|
|
|
549
468
|
// src/gen/pieces/chess/alpha/wK.tsx
|
|
550
|
-
import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
|
|
551
469
|
import * as React11 from "react";
|
|
552
|
-
var SvgWK = (props) => {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
fill: "#101010",
|
|
564
|
-
d: "M977 298v-95h94v95h107v95h-107v153q-48-16-94 0V393H870v-95zm47 314q-47 0-136 121-31-36-50-55 93-140 186-140 92 0 186 140-20 19-50 55-90-121-136-121m-447 907-26 156 145-84zm410-206q-1-147-36.5-274.5T870 845q-45-88-131.5-153T570 627q-103 0-208 93T257 949q0 109 86.5 236T546 1408q212-88 441-95m37 530H448l61-365q-325-280-326-535-1-159 125-274.5T575 553q78 0 158.5 47T876 719q61 74 98.5 164.5T1024 1034q12-60 49-150.5t99-164.5q61-72 142-119t159-47q140 0 266 115.5T1865 943q-2 255-326 535l61 365zm0-74h489l-50-298q-216-84-439-84t-439 84l-50 298zm447-250 26 156-145-84zm-410-206q229 7 441 95 115-96 202-223t87-236q0-136-105.5-229T1478 627q-83 0-169.5 65T1178 845q-46 66-81.5 193.5T1061 1313m-176 233 141-84 137 86-141 84z"
|
|
565
|
-
}));
|
|
566
|
-
} finally {
|
|
567
|
-
_effect.f();
|
|
568
|
-
}
|
|
569
|
-
};
|
|
470
|
+
var SvgWK = (props) => /* @__PURE__ */ React11.createElement("svg", {
|
|
471
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
472
|
+
viewBox: "0 0 2048 2048",
|
|
473
|
+
...props
|
|
474
|
+
}, /* @__PURE__ */ React11.createElement("path", {
|
|
475
|
+
fill: "#f9f9f9",
|
|
476
|
+
d: "m501.6 1811 48.4-354.4-260-269.2s-166.4-288.2 29.9-481C582.2 448.7 826 727.2 826 727.2l195.6-165.7 184 165.7s216.4-232.5 430.4-76 255.4 317.6 117.4 531.6c-138.1 214-250.9 280.7-250.9 280.7L1558 1811z"
|
|
477
|
+
}), /* @__PURE__ */ React11.createElement("path", {
|
|
478
|
+
fill: "#101010",
|
|
479
|
+
d: "M977 298v-95h94v95h107v95h-107v153q-48-16-94 0V393H870v-95zm47 314q-47 0-136 121-31-36-50-55 93-140 186-140 92 0 186 140-20 19-50 55-90-121-136-121m-447 907-26 156 145-84zm410-206q-1-147-36.5-274.5T870 845q-45-88-131.5-153T570 627q-103 0-208 93T257 949q0 109 86.5 236T546 1408q212-88 441-95m37 530H448l61-365q-325-280-326-535-1-159 125-274.5T575 553q78 0 158.5 47T876 719q61 74 98.5 164.5T1024 1034q12-60 49-150.5t99-164.5q61-72 142-119t159-47q140 0 266 115.5T1865 943q-2 255-326 535l61 365zm0-74h489l-50-298q-216-84-439-84t-439 84l-50 298zm447-250 26 156-145-84zm-410-206q229 7 441 95 115-96 202-223t87-236q0-136-105.5-229T1478 627q-83 0-169.5 65T1178 845q-46 66-81.5 193.5T1061 1313m-176 233 141-84 137 86-141 84z"
|
|
480
|
+
}));
|
|
570
481
|
var wK_default = SvgWK;
|
|
571
482
|
|
|
572
483
|
// src/gen/pieces/chess/alpha/wN.tsx
|
|
573
|
-
import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
|
|
574
484
|
import * as React12 from "react";
|
|
575
|
-
var SvgWN = (props) => {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
fill: "#101010",
|
|
587
|
-
d: "m1151 178-115 154c-74 50-147 98-220 144-73 45-112 81-116 107L304 846l12 297 122-86 51 50-115 82 217 121 56-102c37-68 135-88 292-60l-55 85c-25 37-63 60-115 71a608 608 0 0 0-183 238c-32 82-45 182-39 301h1242c-23-55-42-118-57-190-15-73-17-152-5-237 29-239 13-440-47-603-61-164-205-303-433-418zm-17 145 59 133a664 664 0 0 1 262 188c55 72 100 150 134 234 27 97 40 181 41 253 0 71-3 140-9 205-7 65-11 131-13 199-2 67 9 145 32 234H621c-4-84 12-158 48-223s85-124 146-177c78-22 129-56 152-102s53-90 90-131c13-10 27-15 38-15 10-1 21 0 33-2 52-7 95-36 129-85 33-49 51-104 52-165l-19-67c-37 159-99 245-188 257l-45 6c-16 1-33 10-52 26-41-25-87-35-138-31q-111 9-165 27l-108 73-39 45-47-28 78-65-138-144-64 41-4-125 366-241c15-34 58-74 131-120l208-131zM960 564c-6 0-12 2-18 7L826 671l212 2c23 0 17-21-16-63-24-31-44-46-62-46M502 868l-33 4-33 56 57 26 46-55z"
|
|
588
|
-
}));
|
|
589
|
-
} finally {
|
|
590
|
-
_effect.f();
|
|
591
|
-
}
|
|
592
|
-
};
|
|
485
|
+
var SvgWN = (props) => /* @__PURE__ */ React12.createElement("svg", {
|
|
486
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
487
|
+
viewBox: "0 0 2048 2048",
|
|
488
|
+
...props
|
|
489
|
+
}, /* @__PURE__ */ React12.createElement("path", {
|
|
490
|
+
fill: "#f9f9f9",
|
|
491
|
+
d: "m352 861 787-569 94 148s336 103 398 388c63 286 51 974 51 974l-1088 9s-37-290 184-460c221-171 221-212 221-212s-226-71-295-16-117 138-117 138l-129-67 74-85-88-97-94 56z"
|
|
492
|
+
}), /* @__PURE__ */ React12.createElement("path", {
|
|
493
|
+
fill: "#101010",
|
|
494
|
+
d: "m1151 178-115 154c-74 50-147 98-220 144-73 45-112 81-116 107L304 846l12 297 122-86 51 50-115 82 217 121 56-102c37-68 135-88 292-60l-55 85c-25 37-63 60-115 71a608 608 0 0 0-183 238c-32 82-45 182-39 301h1242c-23-55-42-118-57-190-15-73-17-152-5-237 29-239 13-440-47-603-61-164-205-303-433-418zm-17 145 59 133a664 664 0 0 1 262 188c55 72 100 150 134 234 27 97 40 181 41 253 0 71-3 140-9 205-7 65-11 131-13 199-2 67 9 145 32 234H621c-4-84 12-158 48-223s85-124 146-177c78-22 129-56 152-102s53-90 90-131c13-10 27-15 38-15 10-1 21 0 33-2 52-7 95-36 129-85 33-49 51-104 52-165l-19-67c-37 159-99 245-188 257l-45 6c-16 1-33 10-52 26-41-25-87-35-138-31q-111 9-165 27l-108 73-39 45-47-28 78-65-138-144-64 41-4-125 366-241c15-34 58-74 131-120l208-131zM960 564c-6 0-12 2-18 7L826 671l212 2c23 0 17-21-16-63-24-31-44-46-62-46M502 868l-33 4-33 56 57 26 46-55z"
|
|
495
|
+
}));
|
|
593
496
|
var wN_default = SvgWN;
|
|
594
497
|
|
|
595
498
|
// src/gen/pieces/chess/alpha/wP.tsx
|
|
596
|
-
import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
|
|
597
499
|
import * as React13 from "react";
|
|
598
|
-
var SvgWP = (props) => {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
fill: "#101010",
|
|
610
|
-
d: "M520 1769h1008q8-97-132-182-132-101-196-239t-80-309H928q-15 170-79 309t-197 239q-141 85-132 182m504 74H446v-74q-4-80 42-137t125-108q117-91 172-217t78-268H576l284-239q-86-74-86-188 0-103 73-177t177-74q103 0 177 74t73 177q0 114-86 188l284 239h-287q23 141 78 268t172 217q79 51 125 108t42 137v74zM756 974h536l-225-191q134-31 134-171 0-76-52-126t-125-51q-73 0-125 51t-52 126q0 140 134 171z"
|
|
611
|
-
}));
|
|
612
|
-
} finally {
|
|
613
|
-
_effect.f();
|
|
614
|
-
}
|
|
615
|
-
};
|
|
500
|
+
var SvgWP = (props) => /* @__PURE__ */ React13.createElement("svg", {
|
|
501
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
502
|
+
viewBox: "0 0 2048 2048",
|
|
503
|
+
...props
|
|
504
|
+
}, /* @__PURE__ */ React13.createElement("path", {
|
|
505
|
+
fill: "#f9f9f9",
|
|
506
|
+
d: "m734 981 196-193s-189-82-79-288c79-149 303-114 361 50 63 179-113 240-113 240l226 197Zm-235 799s-8-107 50-154c196-173 338-386 371-599l210 2c33 206 182 447 321 561 101 59 99 199 99 199z"
|
|
507
|
+
}), /* @__PURE__ */ React13.createElement("path", {
|
|
508
|
+
fill: "#101010",
|
|
509
|
+
d: "M520 1769h1008q8-97-132-182-132-101-196-239t-80-309H928q-15 170-79 309t-197 239q-141 85-132 182m504 74H446v-74q-4-80 42-137t125-108q117-91 172-217t78-268H576l284-239q-86-74-86-188 0-103 73-177t177-74q103 0 177 74t73 177q0 114-86 188l284 239h-287q23 141 78 268t172 217q79 51 125 108t42 137v74zM756 974h536l-225-191q134-31 134-171 0-76-52-126t-125-51q-73 0-125 51t-52 126q0 140 134 171z"
|
|
510
|
+
}));
|
|
616
511
|
var wP_default = SvgWP;
|
|
617
512
|
|
|
618
513
|
// src/gen/pieces/chess/alpha/wQ.tsx
|
|
619
|
-
import { useSignals as _useSignals14 } from "@preact-signals/safe-react/tracking";
|
|
620
514
|
import * as React14 from "react";
|
|
621
|
-
var SvgWQ = (props) => {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
fill: "#101010",
|
|
633
|
-
d: "M1024 1769h478q-53-130-43-280-100-39-213-67.5t-222-28.5q-110 0-223 28.5T589 1489q9 150-43 280zm0-450q111 0 223.5 26.5T1468 1413q17-105 60.5-212.5T1634 988l-220 155-123-601-267 555-267-555-123 601-220-155q61 105 104.5 212.5T580 1413q108-41 220.5-67.5T1024 1319m0 524H441q114-231 57.5-456.5T296 937q-12 2-19 2-54 0-92.5-38.5T146 808t38.5-92.5T277 677t92.5 38.5T408 808q0 20-6 38-4 14-15 33l196 139 100-486q-64-31-72-103-5-44 29-91t88-53q54-5 96 29t48 88q7 68-46 114l198 412 198-412q-54-46-46-114 6-54 48-88t96-29q54 6 87.5 53t29.5 91q-9 72-72 103l100 486 196-139q-12-19-15-33-6-18-6-38 0-54 38.5-92.5T1771 677t92.5 38.5T1902 808t-38.5 92.5T1771 939q-7 0-19-2-147 224-203 449.5t58 456.5zM276 746q-62 0-62 62t62 62q63 0 63-62t-63-62m466-394q-62 0-62 62t62 62 62-62-62-62M590 1519l119 72-134 86q19-86 15-158m1182-773q-63 0-63 62t63 62q62 0 62-62t-62-62m-466-394q-62 0-62 62t62 62 62-62-62-62m152 1167-119 72 134 86q-20-86-15-158m-573 47 139-83 139 86-139 84z"
|
|
634
|
-
}));
|
|
635
|
-
} finally {
|
|
636
|
-
_effect.f();
|
|
637
|
-
}
|
|
638
|
-
};
|
|
515
|
+
var SvgWQ = (props) => /* @__PURE__ */ React14.createElement("svg", {
|
|
516
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
517
|
+
viewBox: "0 0 2048 2048",
|
|
518
|
+
...props
|
|
519
|
+
}, /* @__PURE__ */ React14.createElement("path", {
|
|
520
|
+
fill: "#f9f9f9",
|
|
521
|
+
d: "m508.5 1815.6 48.4-356.7-216.3-554.6-135.8-20.7-16.1-126.5 112.7-43.8 78.3 73.7-18.4 99 246.2 197.8 112.8-568.3L635 428l78.3-108 112.8 43.7-23 161 223.2 474 244-490-66.8-105.9 92-92 105.9 73.6L1337 534l103.5 529.2 260-161-16-142.7 131-46 57.6 131.1-207 103.6-175 529.2 48.4 308.4z"
|
|
522
|
+
}), /* @__PURE__ */ React14.createElement("path", {
|
|
523
|
+
fill: "#101010",
|
|
524
|
+
d: "M1024 1769h478q-53-130-43-280-100-39-213-67.5t-222-28.5q-110 0-223 28.5T589 1489q9 150-43 280zm0-450q111 0 223.5 26.5T1468 1413q17-105 60.5-212.5T1634 988l-220 155-123-601-267 555-267-555-123 601-220-155q61 105 104.5 212.5T580 1413q108-41 220.5-67.5T1024 1319m0 524H441q114-231 57.5-456.5T296 937q-12 2-19 2-54 0-92.5-38.5T146 808t38.5-92.5T277 677t92.5 38.5T408 808q0 20-6 38-4 14-15 33l196 139 100-486q-64-31-72-103-5-44 29-91t88-53q54-5 96 29t48 88q7 68-46 114l198 412 198-412q-54-46-46-114 6-54 48-88t96-29q54 6 87.5 53t29.5 91q-9 72-72 103l100 486 196-139q-12-19-15-33-6-18-6-38 0-54 38.5-92.5T1771 677t92.5 38.5T1902 808t-38.5 92.5T1771 939q-7 0-19-2-147 224-203 449.5t58 456.5zM276 746q-62 0-62 62t62 62q63 0 63-62t-63-62m466-394q-62 0-62 62t62 62 62-62-62-62M590 1519l119 72-134 86q19-86 15-158m1182-773q-63 0-63 62t63 62q62 0 62-62t-62-62m-466-394q-62 0-62 62t62 62 62-62-62-62m152 1167-119 72 134 86q-20-86-15-158m-573 47 139-83 139 86-139 84z"
|
|
525
|
+
}));
|
|
639
526
|
var wQ_default = SvgWQ;
|
|
640
527
|
|
|
641
528
|
// src/gen/pieces/chess/alpha/wR.tsx
|
|
642
|
-
import { useSignals as _useSignals15 } from "@preact-signals/safe-react/tracking";
|
|
643
529
|
import * as React15 from "react";
|
|
644
|
-
var SvgWR = (props) => {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
fill: "#101010",
|
|
656
|
-
d: "M1024 1501H643l5-74h752l5 74zm0-661H692l5-74h654l5 74zm0 1003H383l29-264 159-118 50-659-149-107-17-341h289v147h137V354h286v147h137V354h289l-17 341-149 107 50 659 159 118 29 264zm0-74h557l-15-149-161-119-54-735 152-109 13-230h-138v148h-285V427H955v148H670V427H532l13 230 152 109-54 735-161 119-15 149z"
|
|
657
|
-
}));
|
|
658
|
-
} finally {
|
|
659
|
-
_effect.f();
|
|
660
|
-
}
|
|
661
|
-
};
|
|
530
|
+
var SvgWR = (props) => /* @__PURE__ */ React15.createElement("svg", {
|
|
531
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
532
|
+
viewBox: "0 0 2048 2048",
|
|
533
|
+
...props
|
|
534
|
+
}, /* @__PURE__ */ React15.createElement("path", {
|
|
535
|
+
fill: "#f9f9f9",
|
|
536
|
+
d: "m435 1804 16-212 152-115 51-688-148-115-7-276 210-2 4 138 198 2 7-140 212-3 14 145 193-4 5-138h204l-7 285-145 106 42 693 172 124 19 207z"
|
|
537
|
+
}), /* @__PURE__ */ React15.createElement("path", {
|
|
538
|
+
fill: "#101010",
|
|
539
|
+
d: "M1024 1501H643l5-74h752l5 74zm0-661H692l5-74h654l5 74zm0 1003H383l29-264 159-118 50-659-149-107-17-341h289v147h137V354h286v147h137V354h289l-17 341-149 107 50 659 159 118 29 264zm0-74h557l-15-149-161-119-54-735 152-109 13-230h-138v148h-285V427H955v148H670V427H532l13 230 152 109-54 735-161 119-15 149z"
|
|
540
|
+
}));
|
|
662
541
|
var wR_default = SvgWR;
|
|
663
542
|
|
|
664
543
|
// src/components/Chessboard/chess.ts
|
|
@@ -675,6 +554,9 @@ var posToLocation = (pos) => {
|
|
|
675
554
|
var locationToPos = ([row, col]) => {
|
|
676
555
|
return String.fromCharCode(col + "a".charCodeAt(0)) + (row + 1);
|
|
677
556
|
};
|
|
557
|
+
var getRawPgn = (pgn) => {
|
|
558
|
+
return pgn.replace(/\[.*?\]/g, "").trim();
|
|
559
|
+
};
|
|
678
560
|
var styles = {
|
|
679
561
|
neutral: {
|
|
680
562
|
black: "bg-neutral-50",
|
|
@@ -709,7 +591,7 @@ var createChess = (pgn) => {
|
|
|
709
591
|
} catch {
|
|
710
592
|
log4.warn(pgn, void 0, {
|
|
711
593
|
F: __dxlog_file4,
|
|
712
|
-
L:
|
|
594
|
+
L: 76,
|
|
713
595
|
S: void 0,
|
|
714
596
|
C: (f, a) => f(...a)
|
|
715
597
|
});
|
|
@@ -717,37 +599,32 @@ var createChess = (pgn) => {
|
|
|
717
599
|
}
|
|
718
600
|
return chess;
|
|
719
601
|
};
|
|
720
|
-
var tryMove = (chess, move) => {
|
|
721
|
-
const from = locationToPos(move.from);
|
|
722
|
-
const to = locationToPos(move.to);
|
|
723
|
-
try {
|
|
724
|
-
const promotion = move.promotion ? move.promotion[1].toLowerCase() : "q";
|
|
725
|
-
chess.move({
|
|
726
|
-
from,
|
|
727
|
-
to,
|
|
728
|
-
promotion
|
|
729
|
-
}, {
|
|
730
|
-
strict: false
|
|
731
|
-
});
|
|
732
|
-
return chess;
|
|
733
|
-
} catch {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
602
|
var ChessModel = class {
|
|
603
|
+
_registry;
|
|
738
604
|
_chess = new ChessJS();
|
|
739
|
-
_pieces =
|
|
740
|
-
|
|
605
|
+
_pieces = Atom.make({});
|
|
606
|
+
_moveIndex = Atom.make(0);
|
|
607
|
+
constructor(_registry, pgn) {
|
|
608
|
+
this._registry = _registry;
|
|
741
609
|
this.update(pgn);
|
|
742
610
|
}
|
|
611
|
+
get readonly() {
|
|
612
|
+
return this._registry.get(this._moveIndex) !== this._chess.history().length;
|
|
613
|
+
}
|
|
743
614
|
get turn() {
|
|
744
615
|
return this._chess.turn() === "w" ? "white" : "black";
|
|
745
616
|
}
|
|
617
|
+
get game() {
|
|
618
|
+
return this._chess;
|
|
619
|
+
}
|
|
746
620
|
get pieces() {
|
|
747
621
|
return this._pieces;
|
|
748
622
|
}
|
|
749
|
-
get
|
|
750
|
-
return this.
|
|
623
|
+
get moveIndex() {
|
|
624
|
+
return this._moveIndex;
|
|
625
|
+
}
|
|
626
|
+
get fen() {
|
|
627
|
+
return this._chess.fen();
|
|
751
628
|
}
|
|
752
629
|
/**
|
|
753
630
|
* PGN with headers.
|
|
@@ -762,10 +639,17 @@ var ChessModel = class {
|
|
|
762
639
|
*/
|
|
763
640
|
// TODO(burdon): Update headers.
|
|
764
641
|
get pgn() {
|
|
765
|
-
return this._chess.pgn();
|
|
642
|
+
return getRawPgn(this._chess.pgn());
|
|
766
643
|
}
|
|
767
|
-
|
|
768
|
-
|
|
644
|
+
setMoveIndex(index) {
|
|
645
|
+
const temp = new ChessJS();
|
|
646
|
+
const history = this._chess.history({
|
|
647
|
+
verbose: true
|
|
648
|
+
});
|
|
649
|
+
for (let i = 0; i < index && i < history.length; i++) {
|
|
650
|
+
temp.move(history[i]);
|
|
651
|
+
}
|
|
652
|
+
this._updateBoard(temp);
|
|
769
653
|
}
|
|
770
654
|
update(pgn = "") {
|
|
771
655
|
const previous = this._chess.history();
|
|
@@ -777,9 +661,9 @@ var ChessModel = class {
|
|
|
777
661
|
}
|
|
778
662
|
const current = this._chess.history();
|
|
779
663
|
if (!isValidNextMove(previous, current)) {
|
|
780
|
-
this._pieces
|
|
664
|
+
this._registry.set(this._pieces, {});
|
|
781
665
|
}
|
|
782
|
-
this.
|
|
666
|
+
this._updateBoard(this._chess);
|
|
783
667
|
}
|
|
784
668
|
isValidMove(move) {
|
|
785
669
|
return tryMove(new ChessJS(this._chess.fen()), move) !== null;
|
|
@@ -794,7 +678,7 @@ var ChessModel = class {
|
|
|
794
678
|
if (!game) {
|
|
795
679
|
return false;
|
|
796
680
|
}
|
|
797
|
-
this.
|
|
681
|
+
this._updateBoard(this._chess);
|
|
798
682
|
return true;
|
|
799
683
|
}
|
|
800
684
|
makeRandomMove() {
|
|
@@ -804,29 +688,32 @@ var ChessModel = class {
|
|
|
804
688
|
}
|
|
805
689
|
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
806
690
|
this._chess.move(move);
|
|
807
|
-
this.
|
|
691
|
+
this._updateBoard(this._chess);
|
|
808
692
|
return true;
|
|
809
693
|
}
|
|
810
694
|
/**
|
|
811
695
|
* Update pieces preserving identity.
|
|
812
696
|
*/
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
this.
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
697
|
+
_updateBoard(chess) {
|
|
698
|
+
this._registry.set(this._pieces, createPieceMap(chess));
|
|
699
|
+
this._registry.set(this._moveIndex, chess.history().length);
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
var tryMove = (chess, move) => {
|
|
703
|
+
const from = locationToPos(move.from);
|
|
704
|
+
const to = locationToPos(move.to);
|
|
705
|
+
try {
|
|
706
|
+
const promotion = move.promotion ? move.promotion[1].toLowerCase() : "q";
|
|
707
|
+
chess.move({
|
|
708
|
+
from,
|
|
709
|
+
to,
|
|
710
|
+
promotion
|
|
711
|
+
}, {
|
|
712
|
+
strict: false
|
|
713
|
+
});
|
|
714
|
+
return chess;
|
|
715
|
+
} catch {
|
|
716
|
+
return null;
|
|
830
717
|
}
|
|
831
718
|
};
|
|
832
719
|
var isValidNextMove = (previous, current) => {
|
|
@@ -840,7 +727,51 @@ var isValidNextMove = (previous, current) => {
|
|
|
840
727
|
}
|
|
841
728
|
return true;
|
|
842
729
|
};
|
|
843
|
-
var
|
|
730
|
+
var createPieceMap = (chess) => {
|
|
731
|
+
const temp = new ChessJS();
|
|
732
|
+
let pieces = _createPieceMap(temp);
|
|
733
|
+
const history = chess.history({
|
|
734
|
+
verbose: true
|
|
735
|
+
});
|
|
736
|
+
for (let i = 0; i < history.length; i++) {
|
|
737
|
+
const move = history[i];
|
|
738
|
+
temp.move(move);
|
|
739
|
+
pieces = _diffPieces(pieces, _createPieceMap(temp));
|
|
740
|
+
const test = /* @__PURE__ */ new Set();
|
|
741
|
+
Object.values(pieces).forEach((piece) => {
|
|
742
|
+
invariant3(!test.has(piece.id), "Duplicate: " + piece.id, {
|
|
743
|
+
F: __dxlog_file4,
|
|
744
|
+
L: 255,
|
|
745
|
+
S: void 0,
|
|
746
|
+
A: [
|
|
747
|
+
"!test.has(piece.id)",
|
|
748
|
+
"'Duplicate: ' + piece.id"
|
|
749
|
+
]
|
|
750
|
+
});
|
|
751
|
+
test.add(piece.id);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
return pieces;
|
|
755
|
+
};
|
|
756
|
+
var _createPieceMap = (chess) => {
|
|
757
|
+
const pieces = {};
|
|
758
|
+
chess.board().flatMap((row) => row.forEach((record) => {
|
|
759
|
+
if (!record) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const { square, type, color } = record;
|
|
763
|
+
const pieceType = `${color.toUpperCase()}${type.toUpperCase()}`;
|
|
764
|
+
const location = posToLocation(square);
|
|
765
|
+
pieces[locationToString(location)] = {
|
|
766
|
+
id: `${square}-${pieceType}`,
|
|
767
|
+
type: pieceType,
|
|
768
|
+
side: color === "w" ? "white" : "black",
|
|
769
|
+
location
|
|
770
|
+
};
|
|
771
|
+
}));
|
|
772
|
+
return pieces;
|
|
773
|
+
};
|
|
774
|
+
var _diffPieces = (before, after) => {
|
|
844
775
|
const difference = {
|
|
845
776
|
removed: {},
|
|
846
777
|
added: {}
|
|
@@ -863,180 +794,161 @@ var mapPieces = (before, after) => {
|
|
|
863
794
|
piece.id = previous.id;
|
|
864
795
|
}
|
|
865
796
|
}
|
|
866
|
-
log4("delta", {
|
|
867
|
-
before: Object.keys(before).length,
|
|
868
|
-
after: Object.keys(after).length,
|
|
869
|
-
removed: Object.keys(difference.removed).length,
|
|
870
|
-
added: Object.keys(difference.added).length
|
|
871
|
-
}, {
|
|
872
|
-
F: __dxlog_file4,
|
|
873
|
-
L: 263,
|
|
874
|
-
S: void 0,
|
|
875
|
-
C: (f, a) => f(...a)
|
|
876
|
-
});
|
|
877
797
|
return after;
|
|
878
798
|
};
|
|
879
799
|
var createDate = (date = /* @__PURE__ */ new Date()) => date.toISOString().slice(0, 10).replace(/-/g, ".");
|
|
880
800
|
|
|
881
801
|
// src/components/Chessboard/Chessboard.tsx
|
|
882
|
-
import {
|
|
883
|
-
import React16, { memo as memo3, useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState4 } from "react";
|
|
802
|
+
import { Atom as Atom2, useAtomValue } from "@effect-atom/atom-react";
|
|
803
|
+
import React16, { forwardRef as forwardRef2, memo as memo3, useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState4 } from "react";
|
|
884
804
|
import { useResizeDetector } from "react-resize-detector";
|
|
885
|
-
import {
|
|
886
|
-
import { mx as mx4 } from "@dxos/
|
|
887
|
-
import {
|
|
888
|
-
var
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
key: locationToString(location),
|
|
918
|
-
["data-location"]: locationToString(location)
|
|
919
|
-
});
|
|
805
|
+
import { useForwardedRef } from "@dxos/react-ui";
|
|
806
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
807
|
+
import { isNonNullable } from "@dxos/util";
|
|
808
|
+
var EMPTY_PIECES_ATOM = Atom2.make({});
|
|
809
|
+
var CHESSBOARD_NAME = "Chessboard";
|
|
810
|
+
var ChessboardComponent = /* @__PURE__ */ forwardRef2(({ classNames, orientation, showLabels, debug, rows = 8, cols = 8 }, forwardedRef) => {
|
|
811
|
+
const targetRef = useForwardedRef(forwardedRef);
|
|
812
|
+
const { width, height } = useResizeDetector({
|
|
813
|
+
targetRef,
|
|
814
|
+
refreshRate: 200
|
|
815
|
+
});
|
|
816
|
+
const { model, promoting, onPromotion } = useGameboardContext(CHESSBOARD_NAME);
|
|
817
|
+
const pieces = useAtomValue(model?.pieces ?? EMPTY_PIECES_ATOM);
|
|
818
|
+
const squares = useMemo(() => {
|
|
819
|
+
return Array.from({
|
|
820
|
+
length: rows
|
|
821
|
+
}, (_, i) => orientation === "black" ? i : rows - 1 - i).flatMap((row) => Array.from({
|
|
822
|
+
length: cols
|
|
823
|
+
}).map((_, col) => [
|
|
824
|
+
row,
|
|
825
|
+
col
|
|
826
|
+
]));
|
|
827
|
+
}, [
|
|
828
|
+
orientation,
|
|
829
|
+
rows,
|
|
830
|
+
cols
|
|
831
|
+
]);
|
|
832
|
+
const layout = useMemo(() => {
|
|
833
|
+
return squares.map((location) => {
|
|
834
|
+
return /* @__PURE__ */ React16.createElement("div", {
|
|
835
|
+
key: locationToString(location),
|
|
836
|
+
"data-location": locationToString(location)
|
|
920
837
|
});
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
}
|
|
935
|
-
},
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
const bounds = grid[locationToString(piece.location)];
|
|
949
|
-
return {
|
|
950
|
-
piece,
|
|
951
|
-
bounds
|
|
952
|
-
};
|
|
953
|
-
}).filter(isNotFalsy);
|
|
954
|
-
}, [
|
|
955
|
-
grid,
|
|
956
|
-
model?.pieces.value,
|
|
957
|
-
promoting
|
|
958
|
-
]);
|
|
959
|
-
return /* @__PURE__ */ React16.createElement("div", {
|
|
960
|
-
ref: containerRef,
|
|
961
|
-
className: mx4("relative", classNames)
|
|
962
|
-
}, /* @__PURE__ */ React16.createElement("div", {
|
|
963
|
-
ref: gridRef,
|
|
964
|
-
className: "grid grid-rows-8 grid-cols-8 aspect-square select-none"
|
|
965
|
-
}, layout), /* @__PURE__ */ React16.createElement("div", null, locations.map((location) => /* @__PURE__ */ React16.createElement(Gameboard.Square, {
|
|
966
|
-
key: locationToString(location),
|
|
967
|
-
location,
|
|
968
|
-
label: showLabels ? locationToPos(location) : void 0,
|
|
969
|
-
bounds: grid[locationToString(location)],
|
|
970
|
-
classNames: getSquareColor(location)
|
|
971
|
-
}))), /* @__PURE__ */ React16.createElement("div", {
|
|
972
|
-
className: mx4(promoting && "opacity-50")
|
|
973
|
-
}, positions.map(({ bounds, piece }) => /* @__PURE__ */ React16.createElement(Gameboard.Piece, {
|
|
974
|
-
key: piece.id,
|
|
975
|
-
piece,
|
|
976
|
-
bounds,
|
|
977
|
-
label: debug ? piece.id : void 0,
|
|
978
|
-
orientation,
|
|
979
|
-
Component: ChessPieces[piece.type]
|
|
980
|
-
}))), promoting && /* @__PURE__ */ React16.createElement(PromotionSelector, {
|
|
981
|
-
grid,
|
|
982
|
-
piece: promoting,
|
|
983
|
-
onSelect: (piece) => {
|
|
984
|
-
onPromotion({
|
|
985
|
-
from: Object.values(model.pieces.value).find((p) => p.id === promoting.id).location,
|
|
986
|
-
to: piece.location,
|
|
987
|
-
piece: promoting.type,
|
|
988
|
-
promotion: piece.type
|
|
989
|
-
});
|
|
838
|
+
});
|
|
839
|
+
}, [
|
|
840
|
+
squares
|
|
841
|
+
]);
|
|
842
|
+
const [grid, setGrid] = useState4({});
|
|
843
|
+
const gridRef = useRef3(null);
|
|
844
|
+
useEffect4(() => {
|
|
845
|
+
setGrid(squares.reduce((acc, location) => {
|
|
846
|
+
const square = getSquareLocation(gridRef.current, location);
|
|
847
|
+
const bounds = getRelativeBounds(gridRef.current, square);
|
|
848
|
+
return {
|
|
849
|
+
...acc,
|
|
850
|
+
[locationToString(location)]: bounds
|
|
851
|
+
};
|
|
852
|
+
}, {}));
|
|
853
|
+
}, [
|
|
854
|
+
squares,
|
|
855
|
+
width,
|
|
856
|
+
height
|
|
857
|
+
]);
|
|
858
|
+
const positions = useMemo(() => {
|
|
859
|
+
if (!gridRef.current) {
|
|
860
|
+
return [];
|
|
861
|
+
}
|
|
862
|
+
return Object.values(pieces).map((piece) => {
|
|
863
|
+
if (piece.id === promoting?.id) {
|
|
864
|
+
return null;
|
|
990
865
|
}
|
|
991
|
-
|
|
992
|
-
} finally {
|
|
993
|
-
_effect.f();
|
|
994
|
-
}
|
|
995
|
-
});
|
|
996
|
-
Chessboard.displayName = "Chessboard";
|
|
997
|
-
var getSquareLocation = (container, location) => {
|
|
998
|
-
return container.querySelector(`[data-location="${locationToString(location)}"]`);
|
|
999
|
-
};
|
|
1000
|
-
var PromotionSelector = ({ grid, piece, onSelect }) => {
|
|
1001
|
-
var _effect = _useSignals16();
|
|
1002
|
-
try {
|
|
1003
|
-
const positions = [
|
|
1004
|
-
"Q",
|
|
1005
|
-
"N",
|
|
1006
|
-
"R",
|
|
1007
|
-
"B"
|
|
1008
|
-
].map((pieceType, i) => {
|
|
1009
|
-
const location = [
|
|
1010
|
-
piece.location[0] + (piece.location[0] === 0 ? i : -i),
|
|
1011
|
-
piece.location[1]
|
|
1012
|
-
];
|
|
866
|
+
const bounds = grid[locationToString(piece.location)];
|
|
1013
867
|
return {
|
|
1014
|
-
piece
|
|
1015
|
-
|
|
1016
|
-
type: (piece.side === "black" ? "B" : "W") + pieceType,
|
|
1017
|
-
side: piece.side,
|
|
1018
|
-
location
|
|
1019
|
-
},
|
|
1020
|
-
bounds: grid[locationToString(location)]
|
|
868
|
+
piece,
|
|
869
|
+
bounds
|
|
1021
870
|
};
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
871
|
+
}).filter(isNonNullable);
|
|
872
|
+
}, [
|
|
873
|
+
grid,
|
|
874
|
+
pieces,
|
|
875
|
+
promoting
|
|
876
|
+
]);
|
|
877
|
+
return /* @__PURE__ */ React16.createElement("div", {
|
|
878
|
+
ref: targetRef,
|
|
879
|
+
tabIndex: 0,
|
|
880
|
+
className: mx4("dx-expander relative outline-hidden", classNames)
|
|
881
|
+
}, /* @__PURE__ */ React16.createElement("div", {
|
|
882
|
+
ref: gridRef,
|
|
883
|
+
className: "grid grid-rows-8 grid-cols-8 aspect-square select-none"
|
|
884
|
+
}, layout), /* @__PURE__ */ React16.createElement("div", null, squares.map((location) => /* @__PURE__ */ React16.createElement(Gameboard.Square, {
|
|
885
|
+
key: locationToString(location),
|
|
886
|
+
location,
|
|
887
|
+
label: showLabels ? locationToPos(location) : void 0,
|
|
888
|
+
bounds: grid[locationToString(location)],
|
|
889
|
+
classNames: getSquareColor(location)
|
|
890
|
+
}))), /* @__PURE__ */ React16.createElement("div", {
|
|
891
|
+
className: mx4(promoting && "opacity-50")
|
|
892
|
+
}, positions.map(({ bounds, piece }) => /* @__PURE__ */ React16.createElement(Gameboard.Piece, {
|
|
893
|
+
key: piece.id,
|
|
894
|
+
piece,
|
|
895
|
+
bounds,
|
|
896
|
+
label: debug ? piece.id : void 0,
|
|
897
|
+
orientation,
|
|
898
|
+
Component: ChessPieces[piece.type]
|
|
899
|
+
}))), promoting && /* @__PURE__ */ React16.createElement(PromotionSelector, {
|
|
900
|
+
grid,
|
|
901
|
+
piece: promoting,
|
|
902
|
+
onSelect: (piece) => {
|
|
903
|
+
onPromotion({
|
|
904
|
+
from: Object.values(pieces).find((p) => p.id === promoting.id).location,
|
|
905
|
+
to: piece.location,
|
|
906
|
+
piece: promoting.type,
|
|
907
|
+
promotion: piece.type
|
|
1027
908
|
});
|
|
909
|
+
}
|
|
910
|
+
}));
|
|
911
|
+
});
|
|
912
|
+
ChessboardComponent.displayName = CHESSBOARD_NAME;
|
|
913
|
+
var Chessboard = /* @__PURE__ */ memo3(ChessboardComponent);
|
|
914
|
+
var PromotionSelector = ({ grid, piece, onSelect }) => {
|
|
915
|
+
const positions = [
|
|
916
|
+
"Q",
|
|
917
|
+
"N",
|
|
918
|
+
"R",
|
|
919
|
+
"B"
|
|
920
|
+
].map((pieceType, i) => {
|
|
921
|
+
const location = [
|
|
922
|
+
piece.location[0] + (piece.location[0] === 0 ? i : -i),
|
|
923
|
+
piece.location[1]
|
|
924
|
+
];
|
|
925
|
+
return {
|
|
926
|
+
piece: {
|
|
927
|
+
id: `promotion-${pieceType}`,
|
|
928
|
+
type: (piece.side === "black" ? "B" : "W") + pieceType,
|
|
929
|
+
side: piece.side,
|
|
930
|
+
location
|
|
931
|
+
},
|
|
932
|
+
bounds: grid[locationToString(location)]
|
|
1028
933
|
};
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
934
|
+
});
|
|
935
|
+
const handleSelect = (selected) => {
|
|
936
|
+
onSelect({
|
|
937
|
+
...piece,
|
|
938
|
+
type: selected.type
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, positions.map(({ piece: piece2, bounds }) => /* @__PURE__ */ React16.createElement(Gameboard.Piece, {
|
|
942
|
+
key: piece2.id,
|
|
943
|
+
classNames: mx4("border-2 border-neutral-700 rounded-full", boardStyles.promotion),
|
|
944
|
+
piece: piece2,
|
|
945
|
+
bounds,
|
|
946
|
+
Component: ChessPieces[piece2.type],
|
|
947
|
+
onClick: () => handleSelect(piece2)
|
|
948
|
+
})));
|
|
949
|
+
};
|
|
950
|
+
var getSquareLocation = (container, location) => {
|
|
951
|
+
return container.querySelector(`[data-location="${locationToString(location)}"]`);
|
|
1040
952
|
};
|
|
1041
953
|
export {
|
|
1042
954
|
ChessModel,
|
|
@@ -1045,6 +957,8 @@ export {
|
|
|
1045
957
|
Gameboard,
|
|
1046
958
|
boardStyles,
|
|
1047
959
|
createChess,
|
|
960
|
+
createPieceMap,
|
|
961
|
+
getRawPgn,
|
|
1048
962
|
getRelativeBounds,
|
|
1049
963
|
getSquareColor,
|
|
1050
964
|
isEqualLocation,
|
|
@@ -1052,7 +966,6 @@ export {
|
|
|
1052
966
|
isPiece,
|
|
1053
967
|
locationToPos,
|
|
1054
968
|
locationToString,
|
|
1055
|
-
mapPieces,
|
|
1056
969
|
posToLocation,
|
|
1057
970
|
stringToLocation,
|
|
1058
971
|
useGameboardContext
|