@dxos/react-ui-gameboard 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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