@dxos/react-ui-gameboard 0.7.5-labs.071a3e2
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/LICENSE +8 -0
- package/README.md +21 -0
- package/dist/lib/browser/index.mjs +903 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +908 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +904 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/Board/Board.d.ts +15 -0
- package/dist/types/src/Board/Board.d.ts.map +1 -0
- package/dist/types/src/Board/Container.d.ts +14 -0
- package/dist/types/src/Board/Container.d.ts.map +1 -0
- package/dist/types/src/Board/Piece.d.ts +13 -0
- package/dist/types/src/Board/Piece.d.ts.map +1 -0
- package/dist/types/src/Board/Square.d.ts +11 -0
- package/dist/types/src/Board/Square.d.ts.map +1 -0
- package/dist/types/src/Board/context.d.ts +10 -0
- package/dist/types/src/Board/context.d.ts.map +1 -0
- package/dist/types/src/Board/index.d.ts +8 -0
- package/dist/types/src/Board/index.d.ts.map +1 -0
- package/dist/types/src/Board/types.d.ts +35 -0
- package/dist/types/src/Board/types.d.ts.map +1 -0
- package/dist/types/src/Board/util.d.ts +3 -0
- package/dist/types/src/Board/util.d.ts.map +1 -0
- package/dist/types/src/Chessboard/Chessboard.d.ts +14 -0
- package/dist/types/src/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts +16 -0
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/Chessboard/chess.d.ts +40 -0
- package/dist/types/src/Chessboard/chess.d.ts.map +1 -0
- package/dist/types/src/Chessboard/index.d.ts +3 -0
- package/dist/types/src/Chessboard/index.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bB.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bB.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bK.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bK.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bN.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bN.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bP.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bP.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bQ.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bQ.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bR.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/bR.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/index.d.ts +13 -0
- package/dist/types/src/gen/pieces/chess/alpha/index.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wB.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wB.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wK.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wK.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wN.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wN.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wP.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wP.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wQ.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wQ.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/wR.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/alpha/wR.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bB.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bB.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bK.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bK.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bN.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bN.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bP.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bP.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bQ.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bQ.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bR.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/bR.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/index.d.ts +13 -0
- package/dist/types/src/gen/pieces/chess/cburnett/index.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wB.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wB.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wK.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wK.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wN.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wN.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wP.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wP.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wQ.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wQ.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wR.d.ts +5 -0
- package/dist/types/src/gen/pieces/chess/cburnett/wR.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +61 -0
- package/src/Board/Board.tsx +86 -0
- package/src/Board/Container.tsx +25 -0
- package/src/Board/Piece.tsx +135 -0
- package/src/Board/Square.tsx +74 -0
- package/src/Board/context.ts +22 -0
- package/src/Board/index.ts +12 -0
- package/src/Board/types.ts +58 -0
- package/src/Board/util.ts +16 -0
- package/src/Chessboard/Chessboard.stories.tsx +108 -0
- package/src/Chessboard/Chessboard.tsx +190 -0
- package/src/Chessboard/chess.ts +213 -0
- package/src/Chessboard/index.ts +7 -0
- package/src/gen/pieces/chess/alpha/bB.tsx +12 -0
- package/src/gen/pieces/chess/alpha/bK.tsx +15 -0
- package/src/gen/pieces/chess/alpha/bN.tsx +15 -0
- package/src/gen/pieces/chess/alpha/bP.tsx +11 -0
- package/src/gen/pieces/chess/alpha/bQ.tsx +12 -0
- package/src/gen/pieces/chess/alpha/bR.tsx +12 -0
- package/src/gen/pieces/chess/alpha/index.ts +12 -0
- package/src/gen/pieces/chess/alpha/wB.tsx +15 -0
- package/src/gen/pieces/chess/alpha/wK.tsx +15 -0
- package/src/gen/pieces/chess/alpha/wN.tsx +15 -0
- package/src/gen/pieces/chess/alpha/wP.tsx +15 -0
- package/src/gen/pieces/chess/alpha/wQ.tsx +15 -0
- package/src/gen/pieces/chess/alpha/wR.tsx +15 -0
- package/src/gen/pieces/chess/cburnett/bB.tsx +15 -0
- package/src/gen/pieces/chess/cburnett/bK.tsx +26 -0
- package/src/gen/pieces/chess/cburnett/bN.tsx +24 -0
- package/src/gen/pieces/chess/cburnett/bP.tsx +13 -0
- package/src/gen/pieces/chess/cburnett/bQ.tsx +30 -0
- package/src/gen/pieces/chess/cburnett/bR.tsx +19 -0
- package/src/gen/pieces/chess/cburnett/index.ts +12 -0
- package/src/gen/pieces/chess/cburnett/wB.tsx +15 -0
- package/src/gen/pieces/chess/cburnett/wK.tsx +21 -0
- package/src/gen/pieces/chess/cburnett/wN.tsx +18 -0
- package/src/gen/pieces/chess/cburnett/wP.tsx +14 -0
- package/src/gen/pieces/chess/cburnett/wQ.tsx +16 -0
- package/src/gen/pieces/chess/cburnett/wR.tsx +14 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,903 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// packages/ui/react-ui-gameboard/src/Board/context.ts
|
|
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
|
|
16
|
+
var locationToString = (location) => location.join("-");
|
|
17
|
+
var stringToLocation = (str) => str.split("-").map(Number);
|
|
18
|
+
var isPiece = (piece) => piece != null && typeof piece === "object" && "id" in piece && "type" in piece && "location" in piece && isLocation(piece.location);
|
|
19
|
+
var isLocation = (token) => Array.isArray(token) && token.length === 2 && token.every((val) => typeof val === "number");
|
|
20
|
+
var isEqualLocation = (l1, l2) => l1[0] === l2[0] && l1[1] === l2[1];
|
|
21
|
+
|
|
22
|
+
// packages/ui/react-ui-gameboard/src/Board/util.ts
|
|
23
|
+
var getRelativeBounds = (container, element) => {
|
|
24
|
+
const containerRect = container.getBoundingClientRect();
|
|
25
|
+
const elementRect = element.getBoundingClientRect();
|
|
26
|
+
return {
|
|
27
|
+
top: elementRect.top - containerRect.top,
|
|
28
|
+
left: elementRect.left - containerRect.left,
|
|
29
|
+
width: elementRect.width,
|
|
30
|
+
height: elementRect.height
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// packages/ui/react-ui-gameboard/src/Board/Board.tsx
|
|
35
|
+
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
36
|
+
import React2, { useCallback, useEffect, useState } from "react";
|
|
37
|
+
import { log } from "@dxos/log";
|
|
38
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
39
|
+
|
|
40
|
+
// packages/ui/react-ui-gameboard/src/Board/Container.tsx
|
|
41
|
+
import React, { forwardRef } from "react";
|
|
42
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
43
|
+
var Container = /* @__PURE__ */ forwardRef(({ children, classNames, style }, forwardedRef) => {
|
|
44
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
45
|
+
ref: forwardedRef,
|
|
46
|
+
style,
|
|
47
|
+
className: "flex w-full h-full justify-center overflow-hidden"
|
|
48
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
49
|
+
className: mx("max-w-full max-h-full content-center", classNames)
|
|
50
|
+
}, children));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// packages/ui/react-ui-gameboard/src/Board/Board.tsx
|
|
54
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Board/Board.tsx";
|
|
55
|
+
var Root = ({ children, classNames, model, onDrop }) => {
|
|
56
|
+
const [dragging, setDragging] = useState(false);
|
|
57
|
+
const [promoting, setPromoting] = useState();
|
|
58
|
+
const onPromotion = useCallback((move) => {
|
|
59
|
+
log("onPromotion", {
|
|
60
|
+
move
|
|
61
|
+
}, {
|
|
62
|
+
F: __dxlog_file,
|
|
63
|
+
L: 32,
|
|
64
|
+
S: void 0,
|
|
65
|
+
C: (f, a) => f(...a)
|
|
66
|
+
});
|
|
67
|
+
setPromoting(void 0);
|
|
68
|
+
onDrop?.(move);
|
|
69
|
+
}, []);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!model) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return monitorForElements({
|
|
75
|
+
onDragStart: ({ source }) => {
|
|
76
|
+
log("onDragStart", {
|
|
77
|
+
source
|
|
78
|
+
}, {
|
|
79
|
+
F: __dxlog_file,
|
|
80
|
+
L: 45,
|
|
81
|
+
S: void 0,
|
|
82
|
+
C: (f, a) => f(...a)
|
|
83
|
+
});
|
|
84
|
+
setDragging(true);
|
|
85
|
+
},
|
|
86
|
+
onDrop: ({ source, location }) => {
|
|
87
|
+
log("onDrop", {
|
|
88
|
+
source,
|
|
89
|
+
location
|
|
90
|
+
}, {
|
|
91
|
+
F: __dxlog_file,
|
|
92
|
+
L: 49,
|
|
93
|
+
S: void 0,
|
|
94
|
+
C: (f, a) => f(...a)
|
|
95
|
+
});
|
|
96
|
+
const target = location.current.dropTargets[0];
|
|
97
|
+
if (!target) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const targetLocation = target.data.location;
|
|
101
|
+
const piece = source.data.piece;
|
|
102
|
+
if (!isLocation(targetLocation) || !isPiece(piece)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const move = {
|
|
106
|
+
from: piece.location,
|
|
107
|
+
to: targetLocation,
|
|
108
|
+
piece: piece.type
|
|
109
|
+
};
|
|
110
|
+
if (model.canPromote?.(move)) {
|
|
111
|
+
setPromoting({
|
|
112
|
+
...piece,
|
|
113
|
+
location: targetLocation
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
onDrop?.(move);
|
|
117
|
+
}
|
|
118
|
+
setDragging(false);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}, [
|
|
122
|
+
model
|
|
123
|
+
]);
|
|
124
|
+
return /* @__PURE__ */ React2.createElement(BoardContext.Provider, {
|
|
125
|
+
value: {
|
|
126
|
+
model,
|
|
127
|
+
dragging,
|
|
128
|
+
promoting,
|
|
129
|
+
onPromotion
|
|
130
|
+
}
|
|
131
|
+
}, /* @__PURE__ */ React2.createElement(Container, {
|
|
132
|
+
classNames: mx2("aspect-square", classNames)
|
|
133
|
+
}, children));
|
|
134
|
+
};
|
|
135
|
+
Root.displayName = "Board.Root";
|
|
136
|
+
var Board = {
|
|
137
|
+
Root
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// packages/ui/react-ui-gameboard/src/Board/Square.tsx
|
|
141
|
+
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
142
|
+
import React3, { useRef, useState as useState2, useEffect as useEffect2, memo } from "react";
|
|
143
|
+
import { invariant } from "@dxos/invariant";
|
|
144
|
+
import { log as log2 } from "@dxos/log";
|
|
145
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
146
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Board/Square.tsx";
|
|
147
|
+
var Square = /* @__PURE__ */ memo(({ location, bounds, label, classNames }) => {
|
|
148
|
+
const ref = useRef(null);
|
|
149
|
+
const [state, setState] = useState2("idle");
|
|
150
|
+
const { model } = useBoardContext();
|
|
151
|
+
useEffect2(() => {
|
|
152
|
+
const el = ref.current;
|
|
153
|
+
invariant(el, void 0, {
|
|
154
|
+
F: __dxlog_file2,
|
|
155
|
+
L: 32,
|
|
156
|
+
S: void 0,
|
|
157
|
+
A: [
|
|
158
|
+
"el",
|
|
159
|
+
""
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
return dropTargetForElements({
|
|
163
|
+
element: el,
|
|
164
|
+
getData: () => ({
|
|
165
|
+
location
|
|
166
|
+
}),
|
|
167
|
+
canDrop: ({ source }) => {
|
|
168
|
+
log2("canDrop", {
|
|
169
|
+
source: source.data
|
|
170
|
+
}, {
|
|
171
|
+
F: __dxlog_file2,
|
|
172
|
+
L: 38,
|
|
173
|
+
S: void 0,
|
|
174
|
+
C: (f, a) => f(...a)
|
|
175
|
+
});
|
|
176
|
+
return true;
|
|
177
|
+
},
|
|
178
|
+
onDragEnter: ({ source }) => {
|
|
179
|
+
log2("onDragEnter", {
|
|
180
|
+
source: source.data
|
|
181
|
+
}, {
|
|
182
|
+
F: __dxlog_file2,
|
|
183
|
+
L: 42,
|
|
184
|
+
S: void 0,
|
|
185
|
+
C: (f, a) => f(...a)
|
|
186
|
+
});
|
|
187
|
+
const piece = source.data.piece;
|
|
188
|
+
if (!isPiece(piece)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (model?.isValidMove({
|
|
192
|
+
from: piece.location,
|
|
193
|
+
to: location,
|
|
194
|
+
piece: piece.type
|
|
195
|
+
})) {
|
|
196
|
+
setState("validMove");
|
|
197
|
+
} else {
|
|
198
|
+
setState("invalidMove");
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
onDragLeave: () => setState("idle"),
|
|
202
|
+
onDrop: () => setState("idle")
|
|
203
|
+
});
|
|
204
|
+
}, [
|
|
205
|
+
model,
|
|
206
|
+
location
|
|
207
|
+
]);
|
|
208
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
209
|
+
ref,
|
|
210
|
+
style: bounds,
|
|
211
|
+
className: mx3("absolute flex justify-center items-center border-2 box-border select-none", classNames, state === "validMove" ? "border-neutral-800" : "border-transparent")
|
|
212
|
+
}, label && /* @__PURE__ */ React3.createElement("div", {
|
|
213
|
+
className: mx3("absolute bottom-1 left-1 text-xs text-neutral-500")
|
|
214
|
+
}, label));
|
|
215
|
+
});
|
|
216
|
+
Square.displayName = "Square";
|
|
217
|
+
|
|
218
|
+
// packages/ui/react-ui-gameboard/src/Board/Piece.tsx
|
|
219
|
+
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
220
|
+
import { centerUnderPointer } from "@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer";
|
|
221
|
+
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
222
|
+
import React4, { useState as useState3, useRef as useRef2, useEffect as useEffect3, memo as memo2 } from "react";
|
|
223
|
+
import { createPortal } from "react-dom";
|
|
224
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
225
|
+
import { log as log3 } from "@dxos/log";
|
|
226
|
+
import { useDynamicRef, useTrackProps } from "@dxos/react-ui";
|
|
227
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
228
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Board/Piece.tsx";
|
|
229
|
+
var Piece = /* @__PURE__ */ memo2(({ classNames, piece, orientation, bounds, label, Component }) => {
|
|
230
|
+
useTrackProps({
|
|
231
|
+
classNames,
|
|
232
|
+
piece,
|
|
233
|
+
orientation,
|
|
234
|
+
bounds,
|
|
235
|
+
label,
|
|
236
|
+
Component
|
|
237
|
+
}, Piece.displayName, false);
|
|
238
|
+
const { model } = useBoardContext();
|
|
239
|
+
const { dragging: isDragging, promoting } = useBoardContext();
|
|
240
|
+
const promotingRef = useDynamicRef(promoting);
|
|
241
|
+
const [dragging, setDragging] = useState3(false);
|
|
242
|
+
const [preview, setPreview] = useState3();
|
|
243
|
+
const [current, setCurrent] = useState3({});
|
|
244
|
+
const ref = useRef2(null);
|
|
245
|
+
useEffect3(() => {
|
|
246
|
+
const el = ref.current;
|
|
247
|
+
invariant2(el, void 0, {
|
|
248
|
+
F: __dxlog_file3,
|
|
249
|
+
L: 44,
|
|
250
|
+
S: void 0,
|
|
251
|
+
A: [
|
|
252
|
+
"el",
|
|
253
|
+
""
|
|
254
|
+
]
|
|
255
|
+
});
|
|
256
|
+
return draggable({
|
|
257
|
+
element: el,
|
|
258
|
+
getInitialData: () => ({
|
|
259
|
+
piece
|
|
260
|
+
}),
|
|
261
|
+
onGenerateDragPreview: ({ nativeSetDragImage, location, source }) => {
|
|
262
|
+
log3("onGenerateDragPreview", {
|
|
263
|
+
source: source.data
|
|
264
|
+
}, {
|
|
265
|
+
F: __dxlog_file3,
|
|
266
|
+
L: 50,
|
|
267
|
+
S: void 0,
|
|
268
|
+
C: (f, a) => f(...a)
|
|
269
|
+
});
|
|
270
|
+
setCustomNativeDragPreview({
|
|
271
|
+
getOffset: centerUnderPointer,
|
|
272
|
+
// getOffset: preserveOffsetOnSource({
|
|
273
|
+
// element: source.element,
|
|
274
|
+
// input: location.current.input,
|
|
275
|
+
// }),
|
|
276
|
+
render: ({ container }) => {
|
|
277
|
+
setPreview(container);
|
|
278
|
+
const { width, height } = el.getBoundingClientRect();
|
|
279
|
+
container.style.width = width + "px";
|
|
280
|
+
container.style.height = height + "px";
|
|
281
|
+
return () => {
|
|
282
|
+
setPreview(void 0);
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
nativeSetDragImage
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
canDrag: () => !promotingRef.current && model?.turn === piece.side,
|
|
289
|
+
onDragStart: () => setDragging(true),
|
|
290
|
+
onDrop: ({ location: { current: current2 } }) => {
|
|
291
|
+
const location = current2.dropTargets[0].data.location;
|
|
292
|
+
if (isLocation(location)) {
|
|
293
|
+
setCurrent((current3) => ({
|
|
294
|
+
...current3,
|
|
295
|
+
location
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
setDragging(false);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}, [
|
|
302
|
+
model,
|
|
303
|
+
piece
|
|
304
|
+
]);
|
|
305
|
+
useEffect3(() => {
|
|
306
|
+
requestAnimationFrame(() => {
|
|
307
|
+
if (!ref.current || !bounds) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (!current.location || !isEqualLocation(current.location, piece.location)) {
|
|
311
|
+
ref.current.style.transition = "top 400ms ease-out, left 400ms ease-out";
|
|
312
|
+
ref.current.style.top = bounds.top + "px";
|
|
313
|
+
ref.current.style.left = bounds.left + "px";
|
|
314
|
+
setCurrent({
|
|
315
|
+
location: piece.location,
|
|
316
|
+
bounds
|
|
317
|
+
});
|
|
318
|
+
} else if (current.bounds !== bounds) {
|
|
319
|
+
ref.current.style.transition = "none";
|
|
320
|
+
ref.current.style.top = bounds.top + "px";
|
|
321
|
+
ref.current.style.left = bounds.left + "px";
|
|
322
|
+
setCurrent({
|
|
323
|
+
location: piece.location,
|
|
324
|
+
bounds
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}, [
|
|
329
|
+
current,
|
|
330
|
+
piece.location,
|
|
331
|
+
bounds
|
|
332
|
+
]);
|
|
333
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("div", {
|
|
334
|
+
ref,
|
|
335
|
+
style: {
|
|
336
|
+
width: bounds?.width,
|
|
337
|
+
height: bounds?.height
|
|
338
|
+
},
|
|
339
|
+
className: mx4(
|
|
340
|
+
"absolute",
|
|
341
|
+
classNames,
|
|
342
|
+
// orientation === 'black' && '_rotate-180',
|
|
343
|
+
dragging && "opacity-20",
|
|
344
|
+
isDragging && "pointer-events-none"
|
|
345
|
+
)
|
|
346
|
+
}, /* @__PURE__ */ React4.createElement(Component, {
|
|
347
|
+
className: "grow"
|
|
348
|
+
}), label && /* @__PURE__ */ React4.createElement("div", {
|
|
349
|
+
className: "absolute inset-1 text-xs text-black"
|
|
350
|
+
}, label)), preview && /* @__PURE__ */ createPortal(/* @__PURE__ */ React4.createElement("div", {
|
|
351
|
+
className: mx4(classNames)
|
|
352
|
+
}, /* @__PURE__ */ React4.createElement(Component, {
|
|
353
|
+
className: "grow"
|
|
354
|
+
})), preview));
|
|
355
|
+
});
|
|
356
|
+
Piece.displayName = "Piece";
|
|
357
|
+
|
|
358
|
+
// packages/ui/react-ui-gameboard/src/Chessboard/chess.ts
|
|
359
|
+
import { signal } from "@preact/signals-core";
|
|
360
|
+
import { Chess, validateFen } from "chess.js";
|
|
361
|
+
import { log as log4 } from "@dxos/log";
|
|
362
|
+
|
|
363
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/index.ts
|
|
364
|
+
var alpha_exports = {};
|
|
365
|
+
__export(alpha_exports, {
|
|
366
|
+
BB: () => bB_default,
|
|
367
|
+
BK: () => bK_default,
|
|
368
|
+
BN: () => bN_default,
|
|
369
|
+
BP: () => bP_default,
|
|
370
|
+
BQ: () => bQ_default,
|
|
371
|
+
BR: () => bR_default,
|
|
372
|
+
WB: () => wB_default,
|
|
373
|
+
WK: () => wK_default,
|
|
374
|
+
WN: () => wN_default,
|
|
375
|
+
WP: () => wP_default,
|
|
376
|
+
WQ: () => wQ_default,
|
|
377
|
+
WR: () => wR_default
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bB.tsx
|
|
381
|
+
import * as React5 from "react";
|
|
382
|
+
var SvgBB = (props) => /* @__PURE__ */ React5.createElement("svg", {
|
|
383
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
384
|
+
viewBox: "0 0 2048 2048",
|
|
385
|
+
...props
|
|
386
|
+
}, /* @__PURE__ */ React5.createElement("path", {
|
|
387
|
+
fill: "#f9f9f9",
|
|
388
|
+
d: "M732 1290 628 993l386-417 421 375-132 380 49 152-658-9z"
|
|
389
|
+
}), /* @__PURE__ */ React5.createElement("path", {
|
|
390
|
+
fill: "#101010",
|
|
391
|
+
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"
|
|
392
|
+
}));
|
|
393
|
+
var bB_default = SvgBB;
|
|
394
|
+
|
|
395
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bK.tsx
|
|
396
|
+
import * as React6 from "react";
|
|
397
|
+
var SvgBK = (props) => /* @__PURE__ */ React6.createElement("svg", {
|
|
398
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
399
|
+
viewBox: "0 0 2048 2048",
|
|
400
|
+
...props
|
|
401
|
+
}, /* @__PURE__ */ React6.createElement("path", {
|
|
402
|
+
fill: "#f9f9f9",
|
|
403
|
+
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"
|
|
404
|
+
}), /* @__PURE__ */ React6.createElement("path", {
|
|
405
|
+
fill: "#101010",
|
|
406
|
+
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"
|
|
407
|
+
}));
|
|
408
|
+
var bK_default = SvgBK;
|
|
409
|
+
|
|
410
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bN.tsx
|
|
411
|
+
import * as React7 from "react";
|
|
412
|
+
var SvgBN = (props) => /* @__PURE__ */ React7.createElement("svg", {
|
|
413
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
414
|
+
viewBox: "0 0 2048 2048",
|
|
415
|
+
...props
|
|
416
|
+
}, /* @__PURE__ */ React7.createElement("path", {
|
|
417
|
+
fill: "#f9f9f9",
|
|
418
|
+
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"
|
|
419
|
+
}), /* @__PURE__ */ React7.createElement("path", {
|
|
420
|
+
fill: "#101010",
|
|
421
|
+
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"
|
|
422
|
+
}));
|
|
423
|
+
var bN_default = SvgBN;
|
|
424
|
+
|
|
425
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bP.tsx
|
|
426
|
+
import * as React8 from "react";
|
|
427
|
+
var SvgBP = (props) => /* @__PURE__ */ React8.createElement("svg", {
|
|
428
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
429
|
+
viewBox: "0 0 2048 2048",
|
|
430
|
+
...props
|
|
431
|
+
}, /* @__PURE__ */ React8.createElement("path", {
|
|
432
|
+
fill: "#101010",
|
|
433
|
+
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"
|
|
434
|
+
}));
|
|
435
|
+
var bP_default = SvgBP;
|
|
436
|
+
|
|
437
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bQ.tsx
|
|
438
|
+
import * as React9 from "react";
|
|
439
|
+
var SvgBQ = (props) => /* @__PURE__ */ React9.createElement("svg", {
|
|
440
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
441
|
+
viewBox: "0 0 2048 2048",
|
|
442
|
+
...props
|
|
443
|
+
}, /* @__PURE__ */ React9.createElement("path", {
|
|
444
|
+
fill: "#f9f9f9",
|
|
445
|
+
d: "m520 1801.8 41.5-448.7 474-128.9 458 133.5 34.4 446.4z"
|
|
446
|
+
}), /* @__PURE__ */ React9.createElement("path", {
|
|
447
|
+
fill: "#101010",
|
|
448
|
+
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"
|
|
449
|
+
}));
|
|
450
|
+
var bQ_default = SvgBQ;
|
|
451
|
+
|
|
452
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/bR.tsx
|
|
453
|
+
import * as React10 from "react";
|
|
454
|
+
var SvgBR = (props) => /* @__PURE__ */ React10.createElement("svg", {
|
|
455
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
456
|
+
viewBox: "0 0 2048 2048",
|
|
457
|
+
...props
|
|
458
|
+
}, /* @__PURE__ */ React10.createElement("path", {
|
|
459
|
+
fill: "#f9f9f9",
|
|
460
|
+
d: "m674 732-76 807 851 14-75-833z"
|
|
461
|
+
}), /* @__PURE__ */ React10.createElement("path", {
|
|
462
|
+
fill: "#101010",
|
|
463
|
+
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"
|
|
464
|
+
}));
|
|
465
|
+
var bR_default = SvgBR;
|
|
466
|
+
|
|
467
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wB.tsx
|
|
468
|
+
import * as React11 from "react";
|
|
469
|
+
var SvgWB = (props) => /* @__PURE__ */ React11.createElement("svg", {
|
|
470
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
471
|
+
viewBox: "0 0 2048 2048",
|
|
472
|
+
...props
|
|
473
|
+
}, /* @__PURE__ */ React11.createElement("path", {
|
|
474
|
+
fill: "#f9f9f9",
|
|
475
|
+
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"
|
|
476
|
+
}), /* @__PURE__ */ React11.createElement("path", {
|
|
477
|
+
fill: "#101010",
|
|
478
|
+
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"
|
|
479
|
+
}));
|
|
480
|
+
var wB_default = SvgWB;
|
|
481
|
+
|
|
482
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wK.tsx
|
|
483
|
+
import * as React12 from "react";
|
|
484
|
+
var SvgWK = (props) => /* @__PURE__ */ React12.createElement("svg", {
|
|
485
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
486
|
+
viewBox: "0 0 2048 2048",
|
|
487
|
+
...props
|
|
488
|
+
}, /* @__PURE__ */ React12.createElement("path", {
|
|
489
|
+
fill: "#f9f9f9",
|
|
490
|
+
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"
|
|
491
|
+
}), /* @__PURE__ */ React12.createElement("path", {
|
|
492
|
+
fill: "#101010",
|
|
493
|
+
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"
|
|
494
|
+
}));
|
|
495
|
+
var wK_default = SvgWK;
|
|
496
|
+
|
|
497
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wN.tsx
|
|
498
|
+
import * as React13 from "react";
|
|
499
|
+
var SvgWN = (props) => /* @__PURE__ */ React13.createElement("svg", {
|
|
500
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
501
|
+
viewBox: "0 0 2048 2048",
|
|
502
|
+
...props
|
|
503
|
+
}, /* @__PURE__ */ React13.createElement("path", {
|
|
504
|
+
fill: "#f9f9f9",
|
|
505
|
+
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"
|
|
506
|
+
}), /* @__PURE__ */ React13.createElement("path", {
|
|
507
|
+
fill: "#101010",
|
|
508
|
+
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"
|
|
509
|
+
}));
|
|
510
|
+
var wN_default = SvgWN;
|
|
511
|
+
|
|
512
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wP.tsx
|
|
513
|
+
import * as React14 from "react";
|
|
514
|
+
var SvgWP = (props) => /* @__PURE__ */ React14.createElement("svg", {
|
|
515
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
516
|
+
viewBox: "0 0 2048 2048",
|
|
517
|
+
...props
|
|
518
|
+
}, /* @__PURE__ */ React14.createElement("path", {
|
|
519
|
+
fill: "#f9f9f9",
|
|
520
|
+
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"
|
|
521
|
+
}), /* @__PURE__ */ React14.createElement("path", {
|
|
522
|
+
fill: "#101010",
|
|
523
|
+
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"
|
|
524
|
+
}));
|
|
525
|
+
var wP_default = SvgWP;
|
|
526
|
+
|
|
527
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wQ.tsx
|
|
528
|
+
import * as React15 from "react";
|
|
529
|
+
var SvgWQ = (props) => /* @__PURE__ */ React15.createElement("svg", {
|
|
530
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
531
|
+
viewBox: "0 0 2048 2048",
|
|
532
|
+
...props
|
|
533
|
+
}, /* @__PURE__ */ React15.createElement("path", {
|
|
534
|
+
fill: "#f9f9f9",
|
|
535
|
+
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"
|
|
536
|
+
}), /* @__PURE__ */ React15.createElement("path", {
|
|
537
|
+
fill: "#101010",
|
|
538
|
+
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"
|
|
539
|
+
}));
|
|
540
|
+
var wQ_default = SvgWQ;
|
|
541
|
+
|
|
542
|
+
// packages/ui/react-ui-gameboard/src/gen/pieces/chess/alpha/wR.tsx
|
|
543
|
+
import * as React16 from "react";
|
|
544
|
+
var SvgWR = (props) => /* @__PURE__ */ React16.createElement("svg", {
|
|
545
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
546
|
+
viewBox: "0 0 2048 2048",
|
|
547
|
+
...props
|
|
548
|
+
}, /* @__PURE__ */ React16.createElement("path", {
|
|
549
|
+
fill: "#f9f9f9",
|
|
550
|
+
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"
|
|
551
|
+
}), /* @__PURE__ */ React16.createElement("path", {
|
|
552
|
+
fill: "#101010",
|
|
553
|
+
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"
|
|
554
|
+
}));
|
|
555
|
+
var wR_default = SvgWR;
|
|
556
|
+
|
|
557
|
+
// packages/ui/react-ui-gameboard/src/Chessboard/chess.ts
|
|
558
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-gameboard/src/Chessboard/chess.ts";
|
|
559
|
+
var ChessPieces = alpha_exports;
|
|
560
|
+
var posToLocation = (pos) => {
|
|
561
|
+
const col = pos.charCodeAt(0) - "a".charCodeAt(0);
|
|
562
|
+
const row = parseInt(pos[1]) - 1;
|
|
563
|
+
return [
|
|
564
|
+
row,
|
|
565
|
+
col
|
|
566
|
+
];
|
|
567
|
+
};
|
|
568
|
+
var locationToPos = ([row, col]) => {
|
|
569
|
+
return String.fromCharCode(col + "a".charCodeAt(0)) + (row + 1);
|
|
570
|
+
};
|
|
571
|
+
var styles = {
|
|
572
|
+
neutral: {
|
|
573
|
+
black: "bg-neutral-50",
|
|
574
|
+
white: "bg-neutral-200",
|
|
575
|
+
promotion: "bg-neutral-200 hover:bg-neutral-300 opacity-70 hover:opacity-100"
|
|
576
|
+
},
|
|
577
|
+
original: {
|
|
578
|
+
black: "bg-[#6C95B9]",
|
|
579
|
+
white: "bg-[#CCD3DB]",
|
|
580
|
+
promotion: "duration-500 bg-[#CCD3DB] opacity-70 hover:opacity-100"
|
|
581
|
+
},
|
|
582
|
+
blue: {
|
|
583
|
+
black: "bg-[#608BC1]",
|
|
584
|
+
white: "bg-[#CBDCEB]",
|
|
585
|
+
promotion: "duration-500 bg-[#CBDCEB] opacity-70 hover:opacity-100"
|
|
586
|
+
},
|
|
587
|
+
green: {
|
|
588
|
+
black: "bg-[#8EB486]",
|
|
589
|
+
white: "bg-[#FDF7F4]",
|
|
590
|
+
promotion: "duration-500 bg-[#FDF7F4] opacity-70 hover:opacity-100"
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
var boardStyles = styles.original;
|
|
594
|
+
var getSquareColor = ([row, col]) => {
|
|
595
|
+
return (col + row) % 2 === 0 ? boardStyles.white : boardStyles.black;
|
|
596
|
+
};
|
|
597
|
+
var makeMove = (game, move) => {
|
|
598
|
+
const from = locationToPos(move.from);
|
|
599
|
+
const to = locationToPos(move.to);
|
|
600
|
+
try {
|
|
601
|
+
log4("makeMove", {
|
|
602
|
+
move
|
|
603
|
+
}, {
|
|
604
|
+
F: __dxlog_file4,
|
|
605
|
+
L: 72,
|
|
606
|
+
S: void 0,
|
|
607
|
+
C: (f, a) => f(...a)
|
|
608
|
+
});
|
|
609
|
+
const promotion = move.promotion ? move.promotion[1].toLowerCase() : "q";
|
|
610
|
+
game.move({
|
|
611
|
+
from,
|
|
612
|
+
to,
|
|
613
|
+
promotion
|
|
614
|
+
}, {
|
|
615
|
+
strict: false
|
|
616
|
+
});
|
|
617
|
+
return game;
|
|
618
|
+
} catch (err) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
var ChessModel = class {
|
|
623
|
+
constructor(fen) {
|
|
624
|
+
this._pieces = signal({});
|
|
625
|
+
this.initialize(fen);
|
|
626
|
+
}
|
|
627
|
+
get turn() {
|
|
628
|
+
return this._game.turn() === "w" ? "white" : "black";
|
|
629
|
+
}
|
|
630
|
+
get pieces() {
|
|
631
|
+
return this._pieces;
|
|
632
|
+
}
|
|
633
|
+
get game() {
|
|
634
|
+
return this._game;
|
|
635
|
+
}
|
|
636
|
+
get fen() {
|
|
637
|
+
return this._game.fen();
|
|
638
|
+
}
|
|
639
|
+
initialize(fen) {
|
|
640
|
+
this._pieces.value = {};
|
|
641
|
+
this._game = new Chess(fen ? validateFen(fen).ok ? fen : void 0 : void 0);
|
|
642
|
+
this._update();
|
|
643
|
+
}
|
|
644
|
+
isValidMove(move) {
|
|
645
|
+
return makeMove(new Chess(this._game.fen()), move) !== null;
|
|
646
|
+
}
|
|
647
|
+
canPromote(move) {
|
|
648
|
+
const isPawnMove = move.piece === "BP" || move.piece === "WP";
|
|
649
|
+
const isToLastRank = move.to[0] === 0 || move.to[0] === 7;
|
|
650
|
+
return isPawnMove && isToLastRank;
|
|
651
|
+
}
|
|
652
|
+
makeMove(move) {
|
|
653
|
+
const game = makeMove(this._game, move);
|
|
654
|
+
if (!game) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
this._game = game;
|
|
658
|
+
this._update();
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
makeRandomMove() {
|
|
662
|
+
const moves = this._game.moves();
|
|
663
|
+
if (!moves.length) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
667
|
+
this._game.move(move);
|
|
668
|
+
this._update();
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Update pieces preserving identity.
|
|
673
|
+
*/
|
|
674
|
+
_update() {
|
|
675
|
+
const pieces = {};
|
|
676
|
+
this._game.board().flatMap((row) => row.forEach((record) => {
|
|
677
|
+
if (!record) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const { square, type, color } = record;
|
|
681
|
+
const pieceType = `${color.toUpperCase()}${type.toUpperCase()}`;
|
|
682
|
+
const location = posToLocation(square);
|
|
683
|
+
pieces[locationToString(location)] = {
|
|
684
|
+
id: `${square}-${pieceType}`,
|
|
685
|
+
type: pieceType,
|
|
686
|
+
side: color === "w" ? "white" : "black",
|
|
687
|
+
location
|
|
688
|
+
};
|
|
689
|
+
}));
|
|
690
|
+
this._pieces.value = mapPieces(this._pieces.value, pieces);
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
var mapPieces = (before, after) => {
|
|
694
|
+
const difference = {
|
|
695
|
+
removed: {},
|
|
696
|
+
added: {}
|
|
697
|
+
};
|
|
698
|
+
Object.keys(before).forEach((square) => {
|
|
699
|
+
if (after[square]?.type !== before[square]?.type) {
|
|
700
|
+
difference.removed[square] = before[square];
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
Object.keys(after).forEach((square) => {
|
|
704
|
+
if (before[square]?.type !== after[square]?.type) {
|
|
705
|
+
difference.added[square] = after[square];
|
|
706
|
+
} else {
|
|
707
|
+
after[square] = before[square];
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
for (const piece of Object.values(difference.added)) {
|
|
711
|
+
const previous = Object.values(difference.removed).find((p) => p.type === piece.type);
|
|
712
|
+
if (previous) {
|
|
713
|
+
piece.id = previous.id;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
log4("delta", {
|
|
717
|
+
before: Object.keys(before).length,
|
|
718
|
+
after: Object.keys(after).length,
|
|
719
|
+
removed: Object.keys(difference.removed).length,
|
|
720
|
+
added: Object.keys(difference.added).length
|
|
721
|
+
}, {
|
|
722
|
+
F: __dxlog_file4,
|
|
723
|
+
L: 205,
|
|
724
|
+
S: void 0,
|
|
725
|
+
C: (f, a) => f(...a)
|
|
726
|
+
});
|
|
727
|
+
return after;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// packages/ui/react-ui-gameboard/src/Chessboard/Chessboard.tsx
|
|
731
|
+
import React17, { useRef as useRef3, useMemo, useEffect as useEffect4, useState as useState4, memo as memo3 } from "react";
|
|
732
|
+
import { useResizeDetector } from "react-resize-detector";
|
|
733
|
+
import { useTrackProps as useTrackProps2 } from "@dxos/react-ui";
|
|
734
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
|
735
|
+
import { isNotFalsy } from "@dxos/util";
|
|
736
|
+
var Chessboard = /* @__PURE__ */ memo3(({ orientation, showLabels, debug, rows = 8, cols = 8 }) => {
|
|
737
|
+
useTrackProps2({
|
|
738
|
+
orientation,
|
|
739
|
+
showLabels,
|
|
740
|
+
debug
|
|
741
|
+
}, Chessboard.displayName, false);
|
|
742
|
+
const { ref: containerRef, width, height } = useResizeDetector({
|
|
743
|
+
refreshRate: 200
|
|
744
|
+
});
|
|
745
|
+
const { model, promoting, onPromotion } = useBoardContext();
|
|
746
|
+
const locations = useMemo(() => {
|
|
747
|
+
return Array.from({
|
|
748
|
+
length: rows
|
|
749
|
+
}, (_, i) => orientation === "black" ? i : rows - 1 - i).flatMap((row) => Array.from({
|
|
750
|
+
length: cols
|
|
751
|
+
}).map((_, col) => [
|
|
752
|
+
row,
|
|
753
|
+
col
|
|
754
|
+
]));
|
|
755
|
+
}, [
|
|
756
|
+
orientation,
|
|
757
|
+
rows,
|
|
758
|
+
cols
|
|
759
|
+
]);
|
|
760
|
+
const layout = useMemo(() => {
|
|
761
|
+
return locations.map((location) => {
|
|
762
|
+
return /* @__PURE__ */ React17.createElement("div", {
|
|
763
|
+
key: locationToString(location),
|
|
764
|
+
["data-location"]: locationToString(location)
|
|
765
|
+
});
|
|
766
|
+
});
|
|
767
|
+
}, [
|
|
768
|
+
locations
|
|
769
|
+
]);
|
|
770
|
+
const [grid, setGrid] = useState4({});
|
|
771
|
+
const gridRef = useRef3(null);
|
|
772
|
+
useEffect4(() => {
|
|
773
|
+
setGrid(locations.reduce((acc, location) => {
|
|
774
|
+
const square = getSquareLocation(gridRef.current, location);
|
|
775
|
+
const bounds = getRelativeBounds(gridRef.current, square);
|
|
776
|
+
return {
|
|
777
|
+
...acc,
|
|
778
|
+
[locationToString(location)]: bounds
|
|
779
|
+
};
|
|
780
|
+
}, {}));
|
|
781
|
+
}, [
|
|
782
|
+
locations,
|
|
783
|
+
width,
|
|
784
|
+
height
|
|
785
|
+
]);
|
|
786
|
+
const positions = useMemo(() => {
|
|
787
|
+
if (!gridRef.current) {
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
return Object.values(model?.pieces.value ?? {}).map((piece) => {
|
|
791
|
+
if (piece.id === promoting?.id) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
const bounds = grid[locationToString(piece.location)];
|
|
795
|
+
return {
|
|
796
|
+
piece,
|
|
797
|
+
bounds
|
|
798
|
+
};
|
|
799
|
+
}).filter(isNotFalsy);
|
|
800
|
+
}, [
|
|
801
|
+
grid,
|
|
802
|
+
model?.pieces.value,
|
|
803
|
+
promoting
|
|
804
|
+
]);
|
|
805
|
+
return /* @__PURE__ */ React17.createElement("div", {
|
|
806
|
+
ref: containerRef,
|
|
807
|
+
className: "relative"
|
|
808
|
+
}, /* @__PURE__ */ React17.createElement("div", {
|
|
809
|
+
ref: gridRef,
|
|
810
|
+
className: "grid grid-rows-8 grid-cols-8 aspect-square select-none"
|
|
811
|
+
}, layout), /* @__PURE__ */ React17.createElement("div", null, locations.map((location) => /* @__PURE__ */ React17.createElement(Square, {
|
|
812
|
+
key: locationToString(location),
|
|
813
|
+
location,
|
|
814
|
+
label: showLabels ? locationToPos(location) : void 0,
|
|
815
|
+
bounds: grid[locationToString(location)],
|
|
816
|
+
classNames: getSquareColor(location)
|
|
817
|
+
}))), /* @__PURE__ */ React17.createElement("div", {
|
|
818
|
+
className: mx5(promoting && "opacity-50")
|
|
819
|
+
}, positions.map(({ bounds, piece }) => /* @__PURE__ */ React17.createElement(Piece, {
|
|
820
|
+
key: piece.id,
|
|
821
|
+
piece,
|
|
822
|
+
bounds,
|
|
823
|
+
label: debug ? piece.id : void 0,
|
|
824
|
+
orientation,
|
|
825
|
+
Component: ChessPieces[piece.type]
|
|
826
|
+
}))), /* @__PURE__ */ React17.createElement("div", null, promoting && /* @__PURE__ */ React17.createElement(PromotionSelector, {
|
|
827
|
+
grid,
|
|
828
|
+
piece: promoting,
|
|
829
|
+
onSelect: (piece) => {
|
|
830
|
+
onPromotion({
|
|
831
|
+
from: Object.values(model.pieces.value).find((p) => p.id === promoting.id).location,
|
|
832
|
+
to: piece.location,
|
|
833
|
+
piece: promoting.type,
|
|
834
|
+
promotion: piece.type
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
})));
|
|
838
|
+
});
|
|
839
|
+
Chessboard.displayName = "Chessboard";
|
|
840
|
+
var getSquareLocation = (container, location) => {
|
|
841
|
+
return container.querySelector(`[data-location="${locationToString(location)}"]`);
|
|
842
|
+
};
|
|
843
|
+
var PromotionSelector = ({ grid, piece, onSelect }) => {
|
|
844
|
+
const positions = [
|
|
845
|
+
"Q",
|
|
846
|
+
"N",
|
|
847
|
+
"R",
|
|
848
|
+
"B"
|
|
849
|
+
].map((pieceType, i) => {
|
|
850
|
+
const location = [
|
|
851
|
+
piece.location[0] + (piece.location[0] === 0 ? i : -i),
|
|
852
|
+
piece.location[1]
|
|
853
|
+
];
|
|
854
|
+
return {
|
|
855
|
+
piece: {
|
|
856
|
+
id: `promotion-${pieceType}`,
|
|
857
|
+
type: (piece.side === "black" ? "B" : "W") + pieceType,
|
|
858
|
+
side: piece.side,
|
|
859
|
+
location
|
|
860
|
+
},
|
|
861
|
+
bounds: grid[locationToString(location)]
|
|
862
|
+
};
|
|
863
|
+
});
|
|
864
|
+
const handleSelect = (selected) => {
|
|
865
|
+
onSelect({
|
|
866
|
+
...piece,
|
|
867
|
+
type: selected.type
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
return /* @__PURE__ */ React17.createElement("div", null, positions.map(({ piece: piece2, bounds }) => /* @__PURE__ */ React17.createElement("div", {
|
|
871
|
+
key: piece2.id,
|
|
872
|
+
style: bounds,
|
|
873
|
+
onClick: () => handleSelect(piece2)
|
|
874
|
+
}, /* @__PURE__ */ React17.createElement(Piece, {
|
|
875
|
+
piece: piece2,
|
|
876
|
+
bounds,
|
|
877
|
+
Component: ChessPieces[piece2.type],
|
|
878
|
+
classNames: mx5("border-2 border-neutral-700 rounded-full", boardStyles.promotion)
|
|
879
|
+
}))));
|
|
880
|
+
};
|
|
881
|
+
export {
|
|
882
|
+
Board,
|
|
883
|
+
BoardContext,
|
|
884
|
+
ChessModel,
|
|
885
|
+
ChessPieces,
|
|
886
|
+
Chessboard,
|
|
887
|
+
Container,
|
|
888
|
+
Piece,
|
|
889
|
+
Square,
|
|
890
|
+
boardStyles,
|
|
891
|
+
getRelativeBounds,
|
|
892
|
+
getSquareColor,
|
|
893
|
+
isEqualLocation,
|
|
894
|
+
isLocation,
|
|
895
|
+
isPiece,
|
|
896
|
+
locationToPos,
|
|
897
|
+
locationToString,
|
|
898
|
+
mapPieces,
|
|
899
|
+
posToLocation,
|
|
900
|
+
stringToLocation,
|
|
901
|
+
useBoardContext
|
|
902
|
+
};
|
|
903
|
+
//# sourceMappingURL=index.mjs.map
|