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