@dxos/react-ui-gameboard 0.8.3 → 0.8.4-main.1da679c
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/dist/lib/browser/index.mjs +522 -435
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +522 -435
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +20 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +31 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/chess.d.ts +59 -0
- package/dist/types/src/components/Chessboard/chess.d.ts.map +1 -0
- 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/Chessboard/index.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/Gameboard.d.ts +38 -0
- package/dist/types/src/components/Gameboard/Gameboard.d.ts.map +1 -0
- package/dist/types/src/{Board → components/Gameboard}/Piece.d.ts +3 -2
- package/dist/types/src/components/Gameboard/Piece.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/Square.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/index.d.ts +4 -0
- package/dist/types/src/components/Gameboard/index.d.ts.map +1 -0
- package/dist/types/src/{Board → components/Gameboard}/types.d.ts +3 -1
- package/dist/types/src/components/Gameboard/types.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/util.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -15
- package/src/{Chessboard → components/Chessboard}/Chessboard.stories.tsx +30 -27
- package/src/components/Chessboard/Chessboard.tsx +199 -0
- package/src/components/Chessboard/chess.test.ts +19 -0
- package/src/components/Chessboard/chess.ts +322 -0
- package/src/components/Gameboard/Gameboard.tsx +140 -0
- package/src/{Board → components/Gameboard}/Piece.tsx +25 -22
- package/src/{Board → components/Gameboard}/Square.tsx +4 -4
- package/src/components/Gameboard/index.ts +8 -0
- package/src/{Board → components/Gameboard}/types.ts +4 -1
- package/src/components/index.ts +6 -0
- package/src/index.ts +1 -2
- package/dist/lib/node/index.cjs +0 -1039
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/types/src/Board/Board.d.ts +0 -15
- package/dist/types/src/Board/Board.d.ts.map +0 -1
- package/dist/types/src/Board/Container.d.ts +0 -14
- package/dist/types/src/Board/Container.d.ts.map +0 -1
- package/dist/types/src/Board/Piece.d.ts.map +0 -1
- package/dist/types/src/Board/Square.d.ts.map +0 -1
- package/dist/types/src/Board/context.d.ts +0 -10
- package/dist/types/src/Board/context.d.ts.map +0 -1
- package/dist/types/src/Board/index.d.ts +0 -8
- package/dist/types/src/Board/index.d.ts.map +0 -1
- package/dist/types/src/Board/types.d.ts.map +0 -1
- package/dist/types/src/Board/util.d.ts.map +0 -1
- package/dist/types/src/Chessboard/Chessboard.d.ts +0 -14
- package/dist/types/src/Chessboard/Chessboard.d.ts.map +0 -1
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts +0 -16
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/Chessboard/chess.d.ts +0 -40
- package/dist/types/src/Chessboard/chess.d.ts.map +0 -1
- package/dist/types/src/Chessboard/index.d.ts.map +0 -1
- package/src/Board/Board.tsx +0 -86
- package/src/Board/Container.tsx +0 -25
- package/src/Board/context.ts +0 -22
- package/src/Board/index.ts +0 -12
- package/src/Chessboard/Chessboard.tsx +0 -190
- package/src/Chessboard/chess.ts +0 -213
- /package/dist/types/src/{Chessboard → components/Chessboard}/index.d.ts +0 -0
- /package/dist/types/src/{Board → components/Gameboard}/Square.d.ts +0 -0
- /package/dist/types/src/{Board → components/Gameboard}/util.d.ts +0 -0
- /package/src/{Chessboard → components/Chessboard}/index.ts +0 -0
- /package/src/{Board → components/Gameboard}/util.ts +0 -0
|
@@ -4,22 +4,14 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
import { createContext, useContext } from "react";
|
|
9
|
-
import { raise } from "@dxos/debug";
|
|
10
|
-
var BoardContext = createContext(void 0);
|
|
11
|
-
var useBoardContext = () => {
|
|
12
|
-
return useContext(BoardContext) ?? raise(new Error("Missing BoardContext"));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// packages/ui/react-ui-gameboard/src/Board/types.ts
|
|
7
|
+
// src/components/Gameboard/types.ts
|
|
16
8
|
var locationToString = (location) => location.join("-");
|
|
17
9
|
var stringToLocation = (str) => str.split("-").map(Number);
|
|
18
10
|
var isPiece = (piece) => piece != null && typeof piece === "object" && "id" in piece && "type" in piece && "location" in piece && isLocation(piece.location);
|
|
19
11
|
var isLocation = (token) => Array.isArray(token) && token.length === 2 && token.every((val) => typeof val === "number");
|
|
20
12
|
var isEqualLocation = (l1, l2) => l1[0] === l2[0] && l1[1] === l2[1];
|
|
21
13
|
|
|
22
|
-
//
|
|
14
|
+
// src/components/Gameboard/util.ts
|
|
23
15
|
var getRelativeBounds = (container, element) => {
|
|
24
16
|
const containerRect = container.getBoundingClientRect();
|
|
25
17
|
const elementRect = element.getBoundingClientRect();
|
|
@@ -31,141 +23,173 @@ var getRelativeBounds = (container, element) => {
|
|
|
31
23
|
};
|
|
32
24
|
};
|
|
33
25
|
|
|
34
|
-
//
|
|
35
|
-
import { useSignals as
|
|
26
|
+
// src/components/Gameboard/Gameboard.tsx
|
|
27
|
+
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
36
28
|
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
37
|
-
import
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
29
|
+
import { createContext } from "@radix-ui/react-context";
|
|
30
|
+
import React3, { forwardRef, useCallback, useEffect as useEffect3, useState as useState3 } from "react";
|
|
31
|
+
import { log as log3 } from "@dxos/log";
|
|
32
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
40
33
|
|
|
41
|
-
//
|
|
34
|
+
// src/components/Gameboard/Piece.tsx
|
|
42
35
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
43
|
-
import
|
|
36
|
+
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
37
|
+
import { centerUnderPointer } from "@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer";
|
|
38
|
+
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
39
|
+
import React, { memo, useEffect, useRef, useState } from "react";
|
|
40
|
+
import { createPortal } from "react-dom";
|
|
41
|
+
import { invariant } from "@dxos/invariant";
|
|
42
|
+
import { log } from "@dxos/log";
|
|
43
|
+
import { useDynamicRef, useTrackProps } from "@dxos/react-ui";
|
|
44
44
|
import { mx } from "@dxos/react-ui-theme";
|
|
45
|
-
var
|
|
45
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Piece.tsx";
|
|
46
|
+
var Piece = /* @__PURE__ */ memo(({ classNames, Component, piece, orientation, bounds, label, onClick }) => {
|
|
46
47
|
var _effect = _useSignals();
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// packages/ui/react-ui-gameboard/src/Board/Board.tsx
|
|
61
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Board/Board.tsx";
|
|
62
|
-
var Root = ({ children, classNames, model, onDrop }) => {
|
|
63
|
-
var _effect = _useSignals2();
|
|
64
|
-
try {
|
|
49
|
+
useTrackProps({
|
|
50
|
+
classNames,
|
|
51
|
+
Component,
|
|
52
|
+
piece,
|
|
53
|
+
orientation,
|
|
54
|
+
bounds,
|
|
55
|
+
label
|
|
56
|
+
}, Piece.displayName, false);
|
|
57
|
+
const { model, dragging: isDragging, promoting } = useGameboardContext(Piece.displayName);
|
|
58
|
+
const promotingRef = useDynamicRef(promoting);
|
|
65
59
|
const [dragging, setDragging] = useState(false);
|
|
66
|
-
const [
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
move
|
|
70
|
-
}, {
|
|
71
|
-
F: __dxlog_file,
|
|
72
|
-
L: 32,
|
|
73
|
-
S: void 0,
|
|
74
|
-
C: (f, a) => f(...a)
|
|
75
|
-
});
|
|
76
|
-
setPromoting(void 0);
|
|
77
|
-
onDrop?.(move);
|
|
78
|
-
}, []);
|
|
60
|
+
const [preview, setPreview] = useState();
|
|
61
|
+
const [current, setCurrent] = useState({});
|
|
62
|
+
const ref = useRef(null);
|
|
79
63
|
useEffect(() => {
|
|
80
64
|
if (!model) {
|
|
81
65
|
return;
|
|
82
66
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
const el = ref.current;
|
|
68
|
+
invariant(el, void 0, {
|
|
69
|
+
F: __dxlog_file,
|
|
70
|
+
L: 46,
|
|
71
|
+
S: void 0,
|
|
72
|
+
A: [
|
|
73
|
+
"el",
|
|
74
|
+
""
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
return draggable({
|
|
78
|
+
element: el,
|
|
79
|
+
getInitialData: () => ({
|
|
80
|
+
piece
|
|
81
|
+
}),
|
|
82
|
+
onGenerateDragPreview: ({ nativeSetDragImage, source }) => {
|
|
83
|
+
log("onGenerateDragPreview", {
|
|
84
|
+
source: source.data
|
|
87
85
|
}, {
|
|
88
86
|
F: __dxlog_file,
|
|
89
|
-
L:
|
|
87
|
+
L: 52,
|
|
90
88
|
S: void 0,
|
|
91
89
|
C: (f, a) => f(...a)
|
|
92
90
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
setCustomNativeDragPreview({
|
|
92
|
+
getOffset: centerUnderPointer,
|
|
93
|
+
render: ({ container }) => {
|
|
94
|
+
setPreview(container);
|
|
95
|
+
const { width, height } = el.getBoundingClientRect();
|
|
96
|
+
container.style.width = width + "px";
|
|
97
|
+
container.style.height = height + "px";
|
|
98
|
+
return () => {
|
|
99
|
+
setPreview(void 0);
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
nativeSetDragImage
|
|
104
103
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
if (model.canPromote?.(move)) {
|
|
120
|
-
setPromoting({
|
|
121
|
-
...piece,
|
|
122
|
-
location: targetLocation
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
onDrop?.(move);
|
|
104
|
+
},
|
|
105
|
+
canDrag: () => !promotingRef.current && !model.readonly && model.turn === piece.side,
|
|
106
|
+
onDragStart: () => setDragging(true),
|
|
107
|
+
onDrop: ({ location: { current: current2 } }) => {
|
|
108
|
+
try {
|
|
109
|
+
const location = current2.dropTargets[0]?.data.location;
|
|
110
|
+
if (isLocation(location)) {
|
|
111
|
+
setCurrent((current3) => ({
|
|
112
|
+
...current3,
|
|
113
|
+
location
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
126
117
|
}
|
|
127
118
|
setDragging(false);
|
|
128
119
|
}
|
|
129
120
|
});
|
|
130
121
|
}, [
|
|
131
|
-
model
|
|
122
|
+
model,
|
|
123
|
+
piece
|
|
132
124
|
]);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
requestAnimationFrame(() => {
|
|
127
|
+
if (!ref.current || !bounds) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!current.location || !isEqualLocation(current.location, piece.location)) {
|
|
131
|
+
ref.current.style.transition = "top 250ms ease-out, left 250ms ease-out";
|
|
132
|
+
ref.current.style.top = bounds.top + "px";
|
|
133
|
+
ref.current.style.left = bounds.left + "px";
|
|
134
|
+
setCurrent({
|
|
135
|
+
location: piece.location,
|
|
136
|
+
bounds
|
|
137
|
+
});
|
|
138
|
+
} else if (current.bounds !== bounds) {
|
|
139
|
+
ref.current.style.transition = "none";
|
|
140
|
+
ref.current.style.top = bounds.top + "px";
|
|
141
|
+
ref.current.style.left = bounds.left + "px";
|
|
142
|
+
setCurrent({
|
|
143
|
+
location: piece.location,
|
|
144
|
+
bounds
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}, [
|
|
149
|
+
current,
|
|
150
|
+
piece.location,
|
|
151
|
+
bounds
|
|
152
|
+
]);
|
|
153
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
154
|
+
ref,
|
|
155
|
+
style: {
|
|
156
|
+
width: bounds?.width,
|
|
157
|
+
height: bounds?.height
|
|
158
|
+
},
|
|
159
|
+
className: mx("absolute", classNames, dragging && "opacity-20", isDragging && "pointer-events-none"),
|
|
160
|
+
onClick
|
|
161
|
+
}, /* @__PURE__ */ React.createElement(Component, {
|
|
162
|
+
className: "grow"
|
|
163
|
+
}), label && /* @__PURE__ */ React.createElement("div", {
|
|
164
|
+
className: "absolute inset-1 text-xs text-black"
|
|
165
|
+
}, label)), preview && /* @__PURE__ */ createPortal(/* @__PURE__ */ React.createElement("div", {
|
|
166
|
+
className: mx(classNames)
|
|
167
|
+
}, /* @__PURE__ */ React.createElement(Component, {
|
|
168
|
+
className: "grow"
|
|
169
|
+
})), preview));
|
|
143
170
|
} finally {
|
|
144
171
|
_effect.f();
|
|
145
172
|
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
var Board = {
|
|
149
|
-
Root
|
|
150
|
-
};
|
|
173
|
+
});
|
|
174
|
+
Piece.displayName = "Piece";
|
|
151
175
|
|
|
152
|
-
//
|
|
153
|
-
import { useSignals as
|
|
176
|
+
// src/components/Gameboard/Square.tsx
|
|
177
|
+
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
154
178
|
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
155
|
-
import
|
|
156
|
-
import { invariant } from "@dxos/invariant";
|
|
179
|
+
import React2, { memo as memo2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
180
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
157
181
|
import { log as log2 } from "@dxos/log";
|
|
158
|
-
import { mx as
|
|
159
|
-
var __dxlog_file2 = "/
|
|
160
|
-
var Square = /* @__PURE__ */
|
|
161
|
-
var _effect =
|
|
182
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
183
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Square.tsx";
|
|
184
|
+
var Square = /* @__PURE__ */ memo2(({ location, bounds, label, classNames }) => {
|
|
185
|
+
var _effect = _useSignals2();
|
|
162
186
|
try {
|
|
163
|
-
const ref =
|
|
187
|
+
const ref = useRef2(null);
|
|
164
188
|
const [state, setState] = useState2("idle");
|
|
165
|
-
const { model } =
|
|
189
|
+
const { model } = useGameboardContext(Square.displayName);
|
|
166
190
|
useEffect2(() => {
|
|
167
191
|
const el = ref.current;
|
|
168
|
-
|
|
192
|
+
invariant2(el, void 0, {
|
|
169
193
|
F: __dxlog_file2,
|
|
170
194
|
L: 32,
|
|
171
195
|
S: void 0,
|
|
@@ -220,12 +244,12 @@ var Square = /* @__PURE__ */ memo(({ location, bounds, label, classNames }) => {
|
|
|
220
244
|
model,
|
|
221
245
|
location
|
|
222
246
|
]);
|
|
223
|
-
return /* @__PURE__ */
|
|
247
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
224
248
|
ref,
|
|
225
249
|
style: bounds,
|
|
226
|
-
className:
|
|
227
|
-
}, label && /* @__PURE__ */
|
|
228
|
-
className:
|
|
250
|
+
className: mx2("absolute flex justify-center items-center border-2 box-border select-none", classNames, state === "validMove" ? "border-neutral-800" : "border-transparent")
|
|
251
|
+
}, label && /* @__PURE__ */ React2.createElement("div", {
|
|
252
|
+
className: mx2("absolute bottom-1 left-1 text-xs text-neutral-500")
|
|
229
253
|
}, label));
|
|
230
254
|
} finally {
|
|
231
255
|
_effect.f();
|
|
@@ -233,158 +257,125 @@ var Square = /* @__PURE__ */ memo(({ location, bounds, label, classNames }) => {
|
|
|
233
257
|
});
|
|
234
258
|
Square.displayName = "Square";
|
|
235
259
|
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
import { log as log3 } from "@dxos/log";
|
|
245
|
-
import { useDynamicRef, useTrackProps } from "@dxos/react-ui";
|
|
246
|
-
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
247
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Board/Piece.tsx";
|
|
248
|
-
var Piece = /* @__PURE__ */ memo2(({ classNames, piece, orientation, bounds, label, Component }) => {
|
|
249
|
-
var _effect = _useSignals4();
|
|
260
|
+
// src/components/Gameboard/Gameboard.tsx
|
|
261
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Gameboard/Gameboard.tsx";
|
|
262
|
+
var [GameboardContextProvider, useRadixGameboardContext] = createContext("Gameboard");
|
|
263
|
+
var useGameboardContext = (consumerName) => {
|
|
264
|
+
return useRadixGameboardContext(consumerName);
|
|
265
|
+
};
|
|
266
|
+
var GameboardRoot = ({ children, model, moveNumber, onDrop }) => {
|
|
267
|
+
var _effect = _useSignals3();
|
|
250
268
|
try {
|
|
251
|
-
useTrackProps({
|
|
252
|
-
classNames,
|
|
253
|
-
piece,
|
|
254
|
-
orientation,
|
|
255
|
-
bounds,
|
|
256
|
-
label,
|
|
257
|
-
Component
|
|
258
|
-
}, Piece.displayName, false);
|
|
259
|
-
const { model } = useBoardContext();
|
|
260
|
-
const { dragging: isDragging, promoting } = useBoardContext();
|
|
261
|
-
const promotingRef = useDynamicRef(promoting);
|
|
262
269
|
const [dragging, setDragging] = useState3(false);
|
|
263
|
-
const [
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
invariant2(el, void 0, {
|
|
270
|
+
const [promoting, setPromoting] = useState3();
|
|
271
|
+
const handlePromotion = useCallback((move) => {
|
|
272
|
+
log3("onPromotion", {
|
|
273
|
+
move
|
|
274
|
+
}, {
|
|
269
275
|
F: __dxlog_file3,
|
|
270
|
-
L:
|
|
276
|
+
L: 48,
|
|
271
277
|
S: void 0,
|
|
272
|
-
|
|
273
|
-
"el",
|
|
274
|
-
""
|
|
275
|
-
]
|
|
278
|
+
C: (f, a) => f(...a)
|
|
276
279
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
280
|
+
setPromoting(void 0);
|
|
281
|
+
onDrop?.(move);
|
|
282
|
+
}, []);
|
|
283
|
+
useEffect3(() => {
|
|
284
|
+
if (!model) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
return monitorForElements({
|
|
288
|
+
onDragStart: ({ source }) => {
|
|
289
|
+
log3("onDragStart", {
|
|
290
|
+
source
|
|
285
291
|
}, {
|
|
286
292
|
F: __dxlog_file3,
|
|
287
|
-
L:
|
|
293
|
+
L: 61,
|
|
288
294
|
S: void 0,
|
|
289
295
|
C: (f, a) => f(...a)
|
|
290
296
|
});
|
|
291
|
-
|
|
292
|
-
getOffset: centerUnderPointer,
|
|
293
|
-
// getOffset: preserveOffsetOnSource({
|
|
294
|
-
// element: source.element,
|
|
295
|
-
// input: location.current.input,
|
|
296
|
-
// }),
|
|
297
|
-
render: ({ container }) => {
|
|
298
|
-
setPreview(container);
|
|
299
|
-
const { width, height } = el.getBoundingClientRect();
|
|
300
|
-
container.style.width = width + "px";
|
|
301
|
-
container.style.height = height + "px";
|
|
302
|
-
return () => {
|
|
303
|
-
setPreview(void 0);
|
|
304
|
-
};
|
|
305
|
-
},
|
|
306
|
-
nativeSetDragImage
|
|
307
|
-
});
|
|
297
|
+
setDragging(true);
|
|
308
298
|
},
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
299
|
+
onDrop: ({ source, location }) => {
|
|
300
|
+
log3("onDrop", {
|
|
301
|
+
source,
|
|
302
|
+
location
|
|
303
|
+
}, {
|
|
304
|
+
F: __dxlog_file3,
|
|
305
|
+
L: 65,
|
|
306
|
+
S: void 0,
|
|
307
|
+
C: (f, a) => f(...a)
|
|
308
|
+
});
|
|
309
|
+
const target = location.current.dropTargets[0];
|
|
310
|
+
if (!target) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const targetLocation = target.data.location;
|
|
314
|
+
const piece = source.data.piece;
|
|
315
|
+
if (!isLocation(targetLocation) || !isPiece(piece)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const move = {
|
|
319
|
+
from: piece.location,
|
|
320
|
+
to: targetLocation,
|
|
321
|
+
piece: piece.type
|
|
322
|
+
};
|
|
323
|
+
if (model.isValidMove(move)) {
|
|
324
|
+
if (model.canPromote?.(move)) {
|
|
325
|
+
setPromoting({
|
|
326
|
+
...piece,
|
|
327
|
+
location: targetLocation
|
|
328
|
+
});
|
|
329
|
+
} else {
|
|
330
|
+
onDrop?.(move);
|
|
331
|
+
}
|
|
318
332
|
}
|
|
319
333
|
setDragging(false);
|
|
320
334
|
}
|
|
321
335
|
});
|
|
322
336
|
}, [
|
|
323
|
-
model
|
|
324
|
-
piece
|
|
325
|
-
]);
|
|
326
|
-
useEffect3(() => {
|
|
327
|
-
requestAnimationFrame(() => {
|
|
328
|
-
if (!ref.current || !bounds) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
if (!current.location || !isEqualLocation(current.location, piece.location)) {
|
|
332
|
-
ref.current.style.transition = "top 400ms ease-out, left 400ms ease-out";
|
|
333
|
-
ref.current.style.top = bounds.top + "px";
|
|
334
|
-
ref.current.style.left = bounds.left + "px";
|
|
335
|
-
setCurrent({
|
|
336
|
-
location: piece.location,
|
|
337
|
-
bounds
|
|
338
|
-
});
|
|
339
|
-
} else if (current.bounds !== bounds) {
|
|
340
|
-
ref.current.style.transition = "none";
|
|
341
|
-
ref.current.style.top = bounds.top + "px";
|
|
342
|
-
ref.current.style.left = bounds.left + "px";
|
|
343
|
-
setCurrent({
|
|
344
|
-
location: piece.location,
|
|
345
|
-
bounds
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
}, [
|
|
350
|
-
current,
|
|
351
|
-
piece.location,
|
|
352
|
-
bounds
|
|
337
|
+
model
|
|
353
338
|
]);
|
|
354
|
-
return /* @__PURE__ */
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
className: "
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
})), preview));
|
|
339
|
+
return /* @__PURE__ */ React3.createElement(GameboardContextProvider, {
|
|
340
|
+
model,
|
|
341
|
+
dragging,
|
|
342
|
+
promoting,
|
|
343
|
+
onPromotion: handlePromotion
|
|
344
|
+
}, children);
|
|
345
|
+
} finally {
|
|
346
|
+
_effect.f();
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
GameboardRoot.displayName = "Gameboard.Root";
|
|
350
|
+
var GameboardContent = /* @__PURE__ */ forwardRef(({ children, classNames, grow, contain }, forwardedRef) => {
|
|
351
|
+
var _effect = _useSignals3();
|
|
352
|
+
try {
|
|
353
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
354
|
+
role: "none",
|
|
355
|
+
className: mx3(grow && "grid is-full bs-full size-container place-content-center", classNames),
|
|
356
|
+
ref: forwardedRef
|
|
357
|
+
}, contain ? /* @__PURE__ */ React3.createElement("div", {
|
|
358
|
+
className: "is-[min(100cqw,100cqh)] bs-[min(100cqw,100cqh)]"
|
|
359
|
+
}, children) : children);
|
|
376
360
|
} finally {
|
|
377
361
|
_effect.f();
|
|
378
362
|
}
|
|
379
363
|
});
|
|
380
|
-
|
|
364
|
+
GameboardContent.displayName = "Gameboard.Content";
|
|
365
|
+
var Gameboard = {
|
|
366
|
+
Root: GameboardRoot,
|
|
367
|
+
Content: GameboardContent,
|
|
368
|
+
Piece,
|
|
369
|
+
Square
|
|
370
|
+
};
|
|
381
371
|
|
|
382
|
-
//
|
|
372
|
+
// src/components/Chessboard/chess.ts
|
|
383
373
|
import { signal } from "@preact/signals-core";
|
|
384
|
-
import { Chess
|
|
374
|
+
import { Chess as ChessJS } from "chess.js";
|
|
375
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
385
376
|
import { log as log4 } from "@dxos/log";
|
|
386
377
|
|
|
387
|
-
//
|
|
378
|
+
// src/gen/pieces/chess/alpha/index.ts
|
|
388
379
|
var alpha_exports = {};
|
|
389
380
|
__export(alpha_exports, {
|
|
390
381
|
BB: () => bB_default,
|
|
@@ -401,10 +392,33 @@ __export(alpha_exports, {
|
|
|
401
392
|
WR: () => wR_default
|
|
402
393
|
});
|
|
403
394
|
|
|
404
|
-
//
|
|
395
|
+
// src/gen/pieces/chess/alpha/bB.tsx
|
|
396
|
+
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
397
|
+
import * as React4 from "react";
|
|
398
|
+
var SvgBB = (props) => {
|
|
399
|
+
var _effect = _useSignals4();
|
|
400
|
+
try {
|
|
401
|
+
return /* @__PURE__ */ React4.createElement("svg", {
|
|
402
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
403
|
+
viewBox: "0 0 2048 2048",
|
|
404
|
+
...props
|
|
405
|
+
}, /* @__PURE__ */ React4.createElement("path", {
|
|
406
|
+
fill: "#f9f9f9",
|
|
407
|
+
d: "M732 1290 628 993l386-417 421 375-132 380 49 152-658-9z"
|
|
408
|
+
}), /* @__PURE__ */ React4.createElement("path", {
|
|
409
|
+
fill: "#101010",
|
|
410
|
+
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"
|
|
411
|
+
}));
|
|
412
|
+
} finally {
|
|
413
|
+
_effect.f();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var bB_default = SvgBB;
|
|
417
|
+
|
|
418
|
+
// src/gen/pieces/chess/alpha/bK.tsx
|
|
405
419
|
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
|
406
420
|
import * as React5 from "react";
|
|
407
|
-
var
|
|
421
|
+
var SvgBK = (props) => {
|
|
408
422
|
var _effect = _useSignals5();
|
|
409
423
|
try {
|
|
410
424
|
return /* @__PURE__ */ React5.createElement("svg", {
|
|
@@ -413,21 +427,21 @@ var SvgBB = (props) => {
|
|
|
413
427
|
...props
|
|
414
428
|
}, /* @__PURE__ */ React5.createElement("path", {
|
|
415
429
|
fill: "#f9f9f9",
|
|
416
|
-
d: "
|
|
430
|
+
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"
|
|
417
431
|
}), /* @__PURE__ */ React5.createElement("path", {
|
|
418
432
|
fill: "#101010",
|
|
419
|
-
d: "
|
|
433
|
+
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"
|
|
420
434
|
}));
|
|
421
435
|
} finally {
|
|
422
436
|
_effect.f();
|
|
423
437
|
}
|
|
424
438
|
};
|
|
425
|
-
var
|
|
439
|
+
var bK_default = SvgBK;
|
|
426
440
|
|
|
427
|
-
//
|
|
441
|
+
// src/gen/pieces/chess/alpha/bN.tsx
|
|
428
442
|
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
429
443
|
import * as React6 from "react";
|
|
430
|
-
var
|
|
444
|
+
var SvgBN = (props) => {
|
|
431
445
|
var _effect = _useSignals6();
|
|
432
446
|
try {
|
|
433
447
|
return /* @__PURE__ */ React6.createElement("svg", {
|
|
@@ -436,21 +450,21 @@ var SvgBK = (props) => {
|
|
|
436
450
|
...props
|
|
437
451
|
}, /* @__PURE__ */ React6.createElement("path", {
|
|
438
452
|
fill: "#f9f9f9",
|
|
439
|
-
d: "
|
|
453
|
+
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"
|
|
440
454
|
}), /* @__PURE__ */ React6.createElement("path", {
|
|
441
455
|
fill: "#101010",
|
|
442
|
-
d: "
|
|
456
|
+
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"
|
|
443
457
|
}));
|
|
444
458
|
} finally {
|
|
445
459
|
_effect.f();
|
|
446
460
|
}
|
|
447
461
|
};
|
|
448
|
-
var
|
|
462
|
+
var bN_default = SvgBN;
|
|
449
463
|
|
|
450
|
-
//
|
|
464
|
+
// src/gen/pieces/chess/alpha/bP.tsx
|
|
451
465
|
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
452
466
|
import * as React7 from "react";
|
|
453
|
-
var
|
|
467
|
+
var SvgBP = (props) => {
|
|
454
468
|
var _effect = _useSignals7();
|
|
455
469
|
try {
|
|
456
470
|
return /* @__PURE__ */ React7.createElement("svg", {
|
|
@@ -458,22 +472,19 @@ var SvgBN = (props) => {
|
|
|
458
472
|
viewBox: "0 0 2048 2048",
|
|
459
473
|
...props
|
|
460
474
|
}, /* @__PURE__ */ React7.createElement("path", {
|
|
461
|
-
fill: "#f9f9f9",
|
|
462
|
-
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"
|
|
463
|
-
}), /* @__PURE__ */ React7.createElement("path", {
|
|
464
475
|
fill: "#101010",
|
|
465
|
-
d: "
|
|
476
|
+
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"
|
|
466
477
|
}));
|
|
467
478
|
} finally {
|
|
468
479
|
_effect.f();
|
|
469
480
|
}
|
|
470
481
|
};
|
|
471
|
-
var
|
|
482
|
+
var bP_default = SvgBP;
|
|
472
483
|
|
|
473
|
-
//
|
|
484
|
+
// src/gen/pieces/chess/alpha/bQ.tsx
|
|
474
485
|
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
475
486
|
import * as React8 from "react";
|
|
476
|
-
var
|
|
487
|
+
var SvgBQ = (props) => {
|
|
477
488
|
var _effect = _useSignals8();
|
|
478
489
|
try {
|
|
479
490
|
return /* @__PURE__ */ React8.createElement("svg", {
|
|
@@ -481,19 +492,22 @@ var SvgBP = (props) => {
|
|
|
481
492
|
viewBox: "0 0 2048 2048",
|
|
482
493
|
...props
|
|
483
494
|
}, /* @__PURE__ */ React8.createElement("path", {
|
|
495
|
+
fill: "#f9f9f9",
|
|
496
|
+
d: "m520 1801.8 41.5-448.7 474-128.9 458 133.5 34.4 446.4z"
|
|
497
|
+
}), /* @__PURE__ */ React8.createElement("path", {
|
|
484
498
|
fill: "#101010",
|
|
485
|
-
d: "
|
|
499
|
+
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"
|
|
486
500
|
}));
|
|
487
501
|
} finally {
|
|
488
502
|
_effect.f();
|
|
489
503
|
}
|
|
490
504
|
};
|
|
491
|
-
var
|
|
505
|
+
var bQ_default = SvgBQ;
|
|
492
506
|
|
|
493
|
-
//
|
|
507
|
+
// src/gen/pieces/chess/alpha/bR.tsx
|
|
494
508
|
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
495
509
|
import * as React9 from "react";
|
|
496
|
-
var
|
|
510
|
+
var SvgBR = (props) => {
|
|
497
511
|
var _effect = _useSignals9();
|
|
498
512
|
try {
|
|
499
513
|
return /* @__PURE__ */ React9.createElement("svg", {
|
|
@@ -502,21 +516,21 @@ var SvgBQ = (props) => {
|
|
|
502
516
|
...props
|
|
503
517
|
}, /* @__PURE__ */ React9.createElement("path", {
|
|
504
518
|
fill: "#f9f9f9",
|
|
505
|
-
d: "
|
|
519
|
+
d: "m674 732-76 807 851 14-75-833z"
|
|
506
520
|
}), /* @__PURE__ */ React9.createElement("path", {
|
|
507
521
|
fill: "#101010",
|
|
508
|
-
d: "
|
|
522
|
+
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"
|
|
509
523
|
}));
|
|
510
524
|
} finally {
|
|
511
525
|
_effect.f();
|
|
512
526
|
}
|
|
513
527
|
};
|
|
514
|
-
var
|
|
528
|
+
var bR_default = SvgBR;
|
|
515
529
|
|
|
516
|
-
//
|
|
530
|
+
// src/gen/pieces/chess/alpha/wB.tsx
|
|
517
531
|
import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
|
|
518
532
|
import * as React10 from "react";
|
|
519
|
-
var
|
|
533
|
+
var SvgWB = (props) => {
|
|
520
534
|
var _effect = _useSignals10();
|
|
521
535
|
try {
|
|
522
536
|
return /* @__PURE__ */ React10.createElement("svg", {
|
|
@@ -525,21 +539,21 @@ var SvgBR = (props) => {
|
|
|
525
539
|
...props
|
|
526
540
|
}, /* @__PURE__ */ React10.createElement("path", {
|
|
527
541
|
fill: "#f9f9f9",
|
|
528
|
-
d: "
|
|
542
|
+
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"
|
|
529
543
|
}), /* @__PURE__ */ React10.createElement("path", {
|
|
530
544
|
fill: "#101010",
|
|
531
|
-
d: "M1024
|
|
545
|
+
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"
|
|
532
546
|
}));
|
|
533
547
|
} finally {
|
|
534
548
|
_effect.f();
|
|
535
549
|
}
|
|
536
550
|
};
|
|
537
|
-
var
|
|
551
|
+
var wB_default = SvgWB;
|
|
538
552
|
|
|
539
|
-
//
|
|
553
|
+
// src/gen/pieces/chess/alpha/wK.tsx
|
|
540
554
|
import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
|
|
541
555
|
import * as React11 from "react";
|
|
542
|
-
var
|
|
556
|
+
var SvgWK = (props) => {
|
|
543
557
|
var _effect = _useSignals11();
|
|
544
558
|
try {
|
|
545
559
|
return /* @__PURE__ */ React11.createElement("svg", {
|
|
@@ -548,21 +562,21 @@ var SvgWB = (props) => {
|
|
|
548
562
|
...props
|
|
549
563
|
}, /* @__PURE__ */ React11.createElement("path", {
|
|
550
564
|
fill: "#f9f9f9",
|
|
551
|
-
d: "
|
|
565
|
+
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"
|
|
552
566
|
}), /* @__PURE__ */ React11.createElement("path", {
|
|
553
567
|
fill: "#101010",
|
|
554
|
-
d: "
|
|
568
|
+
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"
|
|
555
569
|
}));
|
|
556
570
|
} finally {
|
|
557
571
|
_effect.f();
|
|
558
572
|
}
|
|
559
573
|
};
|
|
560
|
-
var
|
|
574
|
+
var wK_default = SvgWK;
|
|
561
575
|
|
|
562
|
-
//
|
|
576
|
+
// src/gen/pieces/chess/alpha/wN.tsx
|
|
563
577
|
import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
|
|
564
578
|
import * as React12 from "react";
|
|
565
|
-
var
|
|
579
|
+
var SvgWN = (props) => {
|
|
566
580
|
var _effect = _useSignals12();
|
|
567
581
|
try {
|
|
568
582
|
return /* @__PURE__ */ React12.createElement("svg", {
|
|
@@ -571,21 +585,21 @@ var SvgWK = (props) => {
|
|
|
571
585
|
...props
|
|
572
586
|
}, /* @__PURE__ */ React12.createElement("path", {
|
|
573
587
|
fill: "#f9f9f9",
|
|
574
|
-
d: "
|
|
588
|
+
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"
|
|
575
589
|
}), /* @__PURE__ */ React12.createElement("path", {
|
|
576
590
|
fill: "#101010",
|
|
577
|
-
d: "
|
|
591
|
+
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"
|
|
578
592
|
}));
|
|
579
593
|
} finally {
|
|
580
594
|
_effect.f();
|
|
581
595
|
}
|
|
582
596
|
};
|
|
583
|
-
var
|
|
597
|
+
var wN_default = SvgWN;
|
|
584
598
|
|
|
585
|
-
//
|
|
599
|
+
// src/gen/pieces/chess/alpha/wP.tsx
|
|
586
600
|
import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
|
|
587
601
|
import * as React13 from "react";
|
|
588
|
-
var
|
|
602
|
+
var SvgWP = (props) => {
|
|
589
603
|
var _effect = _useSignals13();
|
|
590
604
|
try {
|
|
591
605
|
return /* @__PURE__ */ React13.createElement("svg", {
|
|
@@ -594,21 +608,21 @@ var SvgWN = (props) => {
|
|
|
594
608
|
...props
|
|
595
609
|
}, /* @__PURE__ */ React13.createElement("path", {
|
|
596
610
|
fill: "#f9f9f9",
|
|
597
|
-
d: "
|
|
611
|
+
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"
|
|
598
612
|
}), /* @__PURE__ */ React13.createElement("path", {
|
|
599
613
|
fill: "#101010",
|
|
600
|
-
d: "
|
|
614
|
+
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"
|
|
601
615
|
}));
|
|
602
616
|
} finally {
|
|
603
617
|
_effect.f();
|
|
604
618
|
}
|
|
605
619
|
};
|
|
606
|
-
var
|
|
620
|
+
var wP_default = SvgWP;
|
|
607
621
|
|
|
608
|
-
//
|
|
622
|
+
// src/gen/pieces/chess/alpha/wQ.tsx
|
|
609
623
|
import { useSignals as _useSignals14 } from "@preact-signals/safe-react/tracking";
|
|
610
624
|
import * as React14 from "react";
|
|
611
|
-
var
|
|
625
|
+
var SvgWQ = (props) => {
|
|
612
626
|
var _effect = _useSignals14();
|
|
613
627
|
try {
|
|
614
628
|
return /* @__PURE__ */ React14.createElement("svg", {
|
|
@@ -617,21 +631,21 @@ var SvgWP = (props) => {
|
|
|
617
631
|
...props
|
|
618
632
|
}, /* @__PURE__ */ React14.createElement("path", {
|
|
619
633
|
fill: "#f9f9f9",
|
|
620
|
-
d: "
|
|
634
|
+
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"
|
|
621
635
|
}), /* @__PURE__ */ React14.createElement("path", {
|
|
622
636
|
fill: "#101010",
|
|
623
|
-
d: "
|
|
637
|
+
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"
|
|
624
638
|
}));
|
|
625
639
|
} finally {
|
|
626
640
|
_effect.f();
|
|
627
641
|
}
|
|
628
642
|
};
|
|
629
|
-
var
|
|
643
|
+
var wQ_default = SvgWQ;
|
|
630
644
|
|
|
631
|
-
//
|
|
645
|
+
// src/gen/pieces/chess/alpha/wR.tsx
|
|
632
646
|
import { useSignals as _useSignals15 } from "@preact-signals/safe-react/tracking";
|
|
633
647
|
import * as React15 from "react";
|
|
634
|
-
var
|
|
648
|
+
var SvgWR = (props) => {
|
|
635
649
|
var _effect = _useSignals15();
|
|
636
650
|
try {
|
|
637
651
|
return /* @__PURE__ */ React15.createElement("svg", {
|
|
@@ -639,32 +653,9 @@ var SvgWQ = (props) => {
|
|
|
639
653
|
viewBox: "0 0 2048 2048",
|
|
640
654
|
...props
|
|
641
655
|
}, /* @__PURE__ */ React15.createElement("path", {
|
|
642
|
-
fill: "#f9f9f9",
|
|
643
|
-
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"
|
|
644
|
-
}), /* @__PURE__ */ React15.createElement("path", {
|
|
645
|
-
fill: "#101010",
|
|
646
|
-
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"
|
|
647
|
-
}));
|
|
648
|
-
} finally {
|
|
649
|
-
_effect.f();
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
var wQ_default = SvgWQ;
|
|
653
|
-
|
|
654
|
-
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wR.tsx
|
|
655
|
-
import { useSignals as _useSignals16 } from "@preact-signals/safe-react/tracking";
|
|
656
|
-
import * as React16 from "react";
|
|
657
|
-
var SvgWR = (props) => {
|
|
658
|
-
var _effect = _useSignals16();
|
|
659
|
-
try {
|
|
660
|
-
return /* @__PURE__ */ React16.createElement("svg", {
|
|
661
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
662
|
-
viewBox: "0 0 2048 2048",
|
|
663
|
-
...props
|
|
664
|
-
}, /* @__PURE__ */ React16.createElement("path", {
|
|
665
656
|
fill: "#f9f9f9",
|
|
666
657
|
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"
|
|
667
|
-
}), /* @__PURE__ */
|
|
658
|
+
}), /* @__PURE__ */ React15.createElement("path", {
|
|
668
659
|
fill: "#101010",
|
|
669
660
|
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"
|
|
670
661
|
}));
|
|
@@ -674,8 +665,21 @@ var SvgWR = (props) => {
|
|
|
674
665
|
};
|
|
675
666
|
var wR_default = SvgWR;
|
|
676
667
|
|
|
677
|
-
//
|
|
678
|
-
|
|
668
|
+
// src/components/Chessboard/chess.ts
|
|
669
|
+
function _define_property(obj, key, value) {
|
|
670
|
+
if (key in obj) {
|
|
671
|
+
Object.defineProperty(obj, key, {
|
|
672
|
+
value,
|
|
673
|
+
enumerable: true,
|
|
674
|
+
configurable: true,
|
|
675
|
+
writable: true
|
|
676
|
+
});
|
|
677
|
+
} else {
|
|
678
|
+
obj[key] = value;
|
|
679
|
+
}
|
|
680
|
+
return obj;
|
|
681
|
+
}
|
|
682
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-gameboard/src/components/Chessboard/chess.ts";
|
|
679
683
|
var ChessPieces = alpha_exports;
|
|
680
684
|
var posToLocation = (pos) => {
|
|
681
685
|
const col = pos.charCodeAt(0) - "a".charCodeAt(0);
|
|
@@ -688,6 +692,9 @@ var posToLocation = (pos) => {
|
|
|
688
692
|
var locationToPos = ([row, col]) => {
|
|
689
693
|
return String.fromCharCode(col + "a".charCodeAt(0)) + (row + 1);
|
|
690
694
|
};
|
|
695
|
+
var getRawPgn = (pgn) => {
|
|
696
|
+
return pgn.replace(/\[.*?\]/g, "").trim();
|
|
697
|
+
};
|
|
691
698
|
var styles = {
|
|
692
699
|
neutral: {
|
|
693
700
|
black: "bg-neutral-50",
|
|
@@ -714,55 +721,82 @@ var boardStyles = styles.original;
|
|
|
714
721
|
var getSquareColor = ([row, col]) => {
|
|
715
722
|
return (col + row) % 2 === 0 ? boardStyles.black : boardStyles.white;
|
|
716
723
|
};
|
|
717
|
-
var
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
game.move({
|
|
731
|
-
from,
|
|
732
|
-
to,
|
|
733
|
-
promotion
|
|
734
|
-
}, {
|
|
735
|
-
strict: false
|
|
736
|
-
});
|
|
737
|
-
return game;
|
|
738
|
-
} catch (err) {
|
|
739
|
-
return null;
|
|
724
|
+
var createChess = (pgn) => {
|
|
725
|
+
const chess = new ChessJS();
|
|
726
|
+
if (pgn) {
|
|
727
|
+
try {
|
|
728
|
+
chess.loadPgn(pgn);
|
|
729
|
+
} catch {
|
|
730
|
+
log4.warn(pgn, void 0, {
|
|
731
|
+
F: __dxlog_file4,
|
|
732
|
+
L: 76,
|
|
733
|
+
S: void 0,
|
|
734
|
+
C: (f, a) => f(...a)
|
|
735
|
+
});
|
|
736
|
+
}
|
|
740
737
|
}
|
|
738
|
+
return chess;
|
|
741
739
|
};
|
|
742
740
|
var ChessModel = class {
|
|
743
|
-
|
|
744
|
-
this.
|
|
745
|
-
this.initialize(fen);
|
|
741
|
+
get readonly() {
|
|
742
|
+
return this._moveIndex.value !== this._chess.history().length;
|
|
746
743
|
}
|
|
747
744
|
get turn() {
|
|
748
|
-
return this.
|
|
745
|
+
return this._chess.turn() === "w" ? "white" : "black";
|
|
746
|
+
}
|
|
747
|
+
get game() {
|
|
748
|
+
return this._chess;
|
|
749
749
|
}
|
|
750
750
|
get pieces() {
|
|
751
751
|
return this._pieces;
|
|
752
752
|
}
|
|
753
|
-
get
|
|
754
|
-
return this.
|
|
753
|
+
get moveIndex() {
|
|
754
|
+
return this._moveIndex;
|
|
755
755
|
}
|
|
756
756
|
get fen() {
|
|
757
|
-
return this.
|
|
757
|
+
return this._chess.fen();
|
|
758
758
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
759
|
+
/**
|
|
760
|
+
* PGN with headers.
|
|
761
|
+
*
|
|
762
|
+
* [Event "?"]
|
|
763
|
+
* [Site "?"]
|
|
764
|
+
* [Date "2025.08.05"]
|
|
765
|
+
* [Round "?"]
|
|
766
|
+
* [White "?"]
|
|
767
|
+
* [Black "?"]
|
|
768
|
+
* [Result "*"]
|
|
769
|
+
*/
|
|
770
|
+
// TODO(burdon): Update headers.
|
|
771
|
+
get pgn() {
|
|
772
|
+
return getRawPgn(this._chess.pgn());
|
|
773
|
+
}
|
|
774
|
+
setMoveIndex(index) {
|
|
775
|
+
const temp = new ChessJS();
|
|
776
|
+
const history = this._chess.history({
|
|
777
|
+
verbose: true
|
|
778
|
+
});
|
|
779
|
+
for (let i = 0; i < index && i < history.length; i++) {
|
|
780
|
+
temp.move(history[i]);
|
|
781
|
+
}
|
|
782
|
+
this._updateBoard(temp);
|
|
783
|
+
}
|
|
784
|
+
update(pgn = "") {
|
|
785
|
+
const previous = this._chess.history();
|
|
786
|
+
try {
|
|
787
|
+
this._chess.loadPgn(pgn);
|
|
788
|
+
this._chess.setHeader("Date", createDate());
|
|
789
|
+
this._chess.setHeader("Site", "dxos.org");
|
|
790
|
+
} catch {
|
|
791
|
+
}
|
|
792
|
+
const current = this._chess.history();
|
|
793
|
+
if (!isValidNextMove(previous, current)) {
|
|
794
|
+
this._pieces.value = {};
|
|
795
|
+
}
|
|
796
|
+
this._updateBoard(this._chess);
|
|
763
797
|
}
|
|
764
798
|
isValidMove(move) {
|
|
765
|
-
return
|
|
799
|
+
return tryMove(new ChessJS(this._chess.fen()), move) !== null;
|
|
766
800
|
}
|
|
767
801
|
canPromote(move) {
|
|
768
802
|
const isPawnMove = move.piece === "BP" || move.piece === "WP";
|
|
@@ -770,47 +804,110 @@ var ChessModel = class {
|
|
|
770
804
|
return isPawnMove && isToLastRank;
|
|
771
805
|
}
|
|
772
806
|
makeMove(move) {
|
|
773
|
-
const game =
|
|
807
|
+
const game = tryMove(this._chess, move);
|
|
774
808
|
if (!game) {
|
|
775
809
|
return false;
|
|
776
810
|
}
|
|
777
|
-
this.
|
|
778
|
-
this._update();
|
|
811
|
+
this._updateBoard(this._chess);
|
|
779
812
|
return true;
|
|
780
813
|
}
|
|
781
814
|
makeRandomMove() {
|
|
782
|
-
const moves = this.
|
|
815
|
+
const moves = this._chess.moves();
|
|
783
816
|
if (!moves.length) {
|
|
784
817
|
return false;
|
|
785
818
|
}
|
|
786
819
|
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
787
|
-
this.
|
|
788
|
-
this.
|
|
820
|
+
this._chess.move(move);
|
|
821
|
+
this._updateBoard(this._chess);
|
|
789
822
|
return true;
|
|
790
823
|
}
|
|
791
824
|
/**
|
|
792
825
|
* Update pieces preserving identity.
|
|
793
826
|
*/
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
this.
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
827
|
+
_updateBoard(chess) {
|
|
828
|
+
this._pieces.value = createPieceMap(chess);
|
|
829
|
+
this._moveIndex.value = chess.history().length;
|
|
830
|
+
}
|
|
831
|
+
constructor(pgn) {
|
|
832
|
+
_define_property(this, "_chess", new ChessJS());
|
|
833
|
+
_define_property(this, "_pieces", signal({}));
|
|
834
|
+
_define_property(this, "_moveIndex", signal(0));
|
|
835
|
+
this.update(pgn);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
var tryMove = (chess, move) => {
|
|
839
|
+
const from = locationToPos(move.from);
|
|
840
|
+
const to = locationToPos(move.to);
|
|
841
|
+
try {
|
|
842
|
+
const promotion = move.promotion ? move.promotion[1].toLowerCase() : "q";
|
|
843
|
+
chess.move({
|
|
844
|
+
from,
|
|
845
|
+
to,
|
|
846
|
+
promotion
|
|
847
|
+
}, {
|
|
848
|
+
strict: false
|
|
849
|
+
});
|
|
850
|
+
return chess;
|
|
851
|
+
} catch {
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
var isValidNextMove = (previous, current) => {
|
|
856
|
+
if (current.length > previous.length + 1) {
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
for (let i = 0; i < previous.length; i++) {
|
|
860
|
+
if (previous[i] !== current[i]) {
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
811
863
|
}
|
|
864
|
+
return true;
|
|
812
865
|
};
|
|
813
|
-
var
|
|
866
|
+
var createPieceMap = (chess) => {
|
|
867
|
+
const temp = new ChessJS();
|
|
868
|
+
let pieces = _createPieceMap(temp);
|
|
869
|
+
const history = chess.history({
|
|
870
|
+
verbose: true
|
|
871
|
+
});
|
|
872
|
+
for (let i = 0; i < history.length; i++) {
|
|
873
|
+
const move = history[i];
|
|
874
|
+
temp.move(move);
|
|
875
|
+
pieces = _diffPieces(pieces, _createPieceMap(temp));
|
|
876
|
+
const test = /* @__PURE__ */ new Set();
|
|
877
|
+
Object.values(pieces).forEach((piece) => {
|
|
878
|
+
invariant3(!test.has(piece.id), "Duplicate: " + piece.id, {
|
|
879
|
+
F: __dxlog_file4,
|
|
880
|
+
L: 252,
|
|
881
|
+
S: void 0,
|
|
882
|
+
A: [
|
|
883
|
+
"!test.has(piece.id)",
|
|
884
|
+
"'Duplicate: ' + piece.id"
|
|
885
|
+
]
|
|
886
|
+
});
|
|
887
|
+
test.add(piece.id);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
return pieces;
|
|
891
|
+
};
|
|
892
|
+
var _createPieceMap = (chess) => {
|
|
893
|
+
const pieces = {};
|
|
894
|
+
chess.board().flatMap((row) => row.forEach((record) => {
|
|
895
|
+
if (!record) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const { square, type, color } = record;
|
|
899
|
+
const pieceType = `${color.toUpperCase()}${type.toUpperCase()}`;
|
|
900
|
+
const location = posToLocation(square);
|
|
901
|
+
pieces[locationToString(location)] = {
|
|
902
|
+
id: `${square}-${pieceType}`,
|
|
903
|
+
type: pieceType,
|
|
904
|
+
side: color === "w" ? "white" : "black",
|
|
905
|
+
location
|
|
906
|
+
};
|
|
907
|
+
}));
|
|
908
|
+
return pieces;
|
|
909
|
+
};
|
|
910
|
+
var _diffPieces = (before, after) => {
|
|
814
911
|
const difference = {
|
|
815
912
|
removed: {},
|
|
816
913
|
added: {}
|
|
@@ -833,40 +930,32 @@ var mapPieces = (before, after) => {
|
|
|
833
930
|
piece.id = previous.id;
|
|
834
931
|
}
|
|
835
932
|
}
|
|
836
|
-
log4("delta", {
|
|
837
|
-
before: Object.keys(before).length,
|
|
838
|
-
after: Object.keys(after).length,
|
|
839
|
-
removed: Object.keys(difference.removed).length,
|
|
840
|
-
added: Object.keys(difference.added).length
|
|
841
|
-
}, {
|
|
842
|
-
F: __dxlog_file4,
|
|
843
|
-
L: 205,
|
|
844
|
-
S: void 0,
|
|
845
|
-
C: (f, a) => f(...a)
|
|
846
|
-
});
|
|
847
933
|
return after;
|
|
848
934
|
};
|
|
935
|
+
var createDate = (date = /* @__PURE__ */ new Date()) => date.toISOString().slice(0, 10).replace(/-/g, ".");
|
|
849
936
|
|
|
850
|
-
//
|
|
851
|
-
import { useSignals as
|
|
852
|
-
import
|
|
937
|
+
// src/components/Chessboard/Chessboard.tsx
|
|
938
|
+
import { useSignals as _useSignals16 } from "@preact-signals/safe-react/tracking";
|
|
939
|
+
import React16, { forwardRef as forwardRef2, memo as memo3, useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState4 } from "react";
|
|
853
940
|
import { useResizeDetector } from "react-resize-detector";
|
|
854
|
-
import { useTrackProps as useTrackProps2 } from "@dxos/react-ui";
|
|
855
|
-
import { mx as
|
|
941
|
+
import { useForwardedRef, useTrackProps as useTrackProps2 } from "@dxos/react-ui";
|
|
942
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
856
943
|
import { isNotFalsy } from "@dxos/util";
|
|
857
|
-
var
|
|
858
|
-
var _effect =
|
|
944
|
+
var ChessboardComponent = /* @__PURE__ */ forwardRef2(({ classNames, orientation, showLabels, debug, rows = 8, cols = 8 }, forwardedRef) => {
|
|
945
|
+
var _effect = _useSignals16();
|
|
859
946
|
try {
|
|
860
947
|
useTrackProps2({
|
|
861
948
|
orientation,
|
|
862
949
|
showLabels,
|
|
863
950
|
debug
|
|
864
951
|
}, Chessboard.displayName, false);
|
|
865
|
-
const
|
|
952
|
+
const targetRef = useForwardedRef(forwardedRef);
|
|
953
|
+
const { width, height } = useResizeDetector({
|
|
954
|
+
targetRef,
|
|
866
955
|
refreshRate: 200
|
|
867
956
|
});
|
|
868
|
-
const { model, promoting, onPromotion } =
|
|
869
|
-
const
|
|
957
|
+
const { model, promoting, onPromotion } = useGameboardContext(Chessboard.displayName);
|
|
958
|
+
const squares = useMemo(() => {
|
|
870
959
|
return Array.from({
|
|
871
960
|
length: rows
|
|
872
961
|
}, (_, i) => orientation === "black" ? i : rows - 1 - i).flatMap((row) => Array.from({
|
|
@@ -881,19 +970,19 @@ var Chessboard = /* @__PURE__ */ memo3(({ orientation, showLabels, debug, rows =
|
|
|
881
970
|
cols
|
|
882
971
|
]);
|
|
883
972
|
const layout = useMemo(() => {
|
|
884
|
-
return
|
|
885
|
-
return /* @__PURE__ */
|
|
973
|
+
return squares.map((location) => {
|
|
974
|
+
return /* @__PURE__ */ React16.createElement("div", {
|
|
886
975
|
key: locationToString(location),
|
|
887
976
|
["data-location"]: locationToString(location)
|
|
888
977
|
});
|
|
889
978
|
});
|
|
890
979
|
}, [
|
|
891
|
-
|
|
980
|
+
squares
|
|
892
981
|
]);
|
|
893
982
|
const [grid, setGrid] = useState4({});
|
|
894
983
|
const gridRef = useRef3(null);
|
|
895
984
|
useEffect4(() => {
|
|
896
|
-
setGrid(
|
|
985
|
+
setGrid(squares.reduce((acc, location) => {
|
|
897
986
|
const square = getSquareLocation(gridRef.current, location);
|
|
898
987
|
const bounds = getRelativeBounds(gridRef.current, square);
|
|
899
988
|
return {
|
|
@@ -902,7 +991,7 @@ var Chessboard = /* @__PURE__ */ memo3(({ orientation, showLabels, debug, rows =
|
|
|
902
991
|
};
|
|
903
992
|
}, {}));
|
|
904
993
|
}, [
|
|
905
|
-
|
|
994
|
+
squares,
|
|
906
995
|
width,
|
|
907
996
|
height
|
|
908
997
|
]);
|
|
@@ -925,28 +1014,29 @@ var Chessboard = /* @__PURE__ */ memo3(({ orientation, showLabels, debug, rows =
|
|
|
925
1014
|
model?.pieces.value,
|
|
926
1015
|
promoting
|
|
927
1016
|
]);
|
|
928
|
-
return /* @__PURE__ */
|
|
929
|
-
ref:
|
|
930
|
-
|
|
931
|
-
|
|
1017
|
+
return /* @__PURE__ */ React16.createElement("div", {
|
|
1018
|
+
ref: targetRef,
|
|
1019
|
+
tabIndex: 0,
|
|
1020
|
+
className: mx4("relative outline-none", classNames)
|
|
1021
|
+
}, /* @__PURE__ */ React16.createElement("div", {
|
|
932
1022
|
ref: gridRef,
|
|
933
1023
|
className: "grid grid-rows-8 grid-cols-8 aspect-square select-none"
|
|
934
|
-
}, layout), /* @__PURE__ */
|
|
1024
|
+
}, layout), /* @__PURE__ */ React16.createElement("div", null, squares.map((location) => /* @__PURE__ */ React16.createElement(Gameboard.Square, {
|
|
935
1025
|
key: locationToString(location),
|
|
936
1026
|
location,
|
|
937
1027
|
label: showLabels ? locationToPos(location) : void 0,
|
|
938
1028
|
bounds: grid[locationToString(location)],
|
|
939
1029
|
classNames: getSquareColor(location)
|
|
940
|
-
}))), /* @__PURE__ */
|
|
941
|
-
className:
|
|
942
|
-
}, positions.map(({ bounds, piece }) => /* @__PURE__ */
|
|
1030
|
+
}))), /* @__PURE__ */ React16.createElement("div", {
|
|
1031
|
+
className: mx4(promoting && "opacity-50")
|
|
1032
|
+
}, positions.map(({ bounds, piece }) => /* @__PURE__ */ React16.createElement(Gameboard.Piece, {
|
|
943
1033
|
key: piece.id,
|
|
944
1034
|
piece,
|
|
945
1035
|
bounds,
|
|
946
1036
|
label: debug ? piece.id : void 0,
|
|
947
1037
|
orientation,
|
|
948
1038
|
Component: ChessPieces[piece.type]
|
|
949
|
-
}))),
|
|
1039
|
+
}))), promoting && /* @__PURE__ */ React16.createElement(PromotionSelector, {
|
|
950
1040
|
grid,
|
|
951
1041
|
piece: promoting,
|
|
952
1042
|
onSelect: (piece) => {
|
|
@@ -957,17 +1047,15 @@ var Chessboard = /* @__PURE__ */ memo3(({ orientation, showLabels, debug, rows =
|
|
|
957
1047
|
promotion: piece.type
|
|
958
1048
|
});
|
|
959
1049
|
}
|
|
960
|
-
}))
|
|
1050
|
+
}));
|
|
961
1051
|
} finally {
|
|
962
1052
|
_effect.f();
|
|
963
1053
|
}
|
|
964
1054
|
});
|
|
965
|
-
|
|
966
|
-
var
|
|
967
|
-
return container.querySelector(`[data-location="${locationToString(location)}"]`);
|
|
968
|
-
};
|
|
1055
|
+
ChessboardComponent.displayName = "Chessboard";
|
|
1056
|
+
var Chessboard = /* @__PURE__ */ memo3(ChessboardComponent);
|
|
969
1057
|
var PromotionSelector = ({ grid, piece, onSelect }) => {
|
|
970
|
-
var _effect =
|
|
1058
|
+
var _effect = _useSignals16();
|
|
971
1059
|
try {
|
|
972
1060
|
const positions = [
|
|
973
1061
|
"Q",
|
|
@@ -995,30 +1083,30 @@ var PromotionSelector = ({ grid, piece, onSelect }) => {
|
|
|
995
1083
|
type: selected.type
|
|
996
1084
|
});
|
|
997
1085
|
};
|
|
998
|
-
return /* @__PURE__ */
|
|
1086
|
+
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, positions.map(({ piece: piece2, bounds }) => /* @__PURE__ */ React16.createElement(Gameboard.Piece, {
|
|
999
1087
|
key: piece2.id,
|
|
1000
|
-
|
|
1001
|
-
onClick: () => handleSelect(piece2)
|
|
1002
|
-
}, /* @__PURE__ */ React17.createElement(Piece, {
|
|
1088
|
+
classNames: mx4("border-2 border-neutral-700 rounded-full", boardStyles.promotion),
|
|
1003
1089
|
piece: piece2,
|
|
1004
1090
|
bounds,
|
|
1005
1091
|
Component: ChessPieces[piece2.type],
|
|
1006
|
-
|
|
1007
|
-
})))
|
|
1092
|
+
onClick: () => handleSelect(piece2)
|
|
1093
|
+
})));
|
|
1008
1094
|
} finally {
|
|
1009
1095
|
_effect.f();
|
|
1010
1096
|
}
|
|
1011
1097
|
};
|
|
1098
|
+
var getSquareLocation = (container, location) => {
|
|
1099
|
+
return container.querySelector(`[data-location="${locationToString(location)}"]`);
|
|
1100
|
+
};
|
|
1012
1101
|
export {
|
|
1013
|
-
Board,
|
|
1014
|
-
BoardContext,
|
|
1015
1102
|
ChessModel,
|
|
1016
1103
|
ChessPieces,
|
|
1017
1104
|
Chessboard,
|
|
1018
|
-
|
|
1019
|
-
Piece,
|
|
1020
|
-
Square,
|
|
1105
|
+
Gameboard,
|
|
1021
1106
|
boardStyles,
|
|
1107
|
+
createChess,
|
|
1108
|
+
createPieceMap,
|
|
1109
|
+
getRawPgn,
|
|
1022
1110
|
getRelativeBounds,
|
|
1023
1111
|
getSquareColor,
|
|
1024
1112
|
isEqualLocation,
|
|
@@ -1026,9 +1114,8 @@ export {
|
|
|
1026
1114
|
isPiece,
|
|
1027
1115
|
locationToPos,
|
|
1028
1116
|
locationToString,
|
|
1029
|
-
mapPieces,
|
|
1030
1117
|
posToLocation,
|
|
1031
1118
|
stringToLocation,
|
|
1032
|
-
|
|
1119
|
+
useGameboardContext
|
|
1033
1120
|
};
|
|
1034
1121
|
//# sourceMappingURL=index.mjs.map
|