check-board 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +0 -0
- package/dist/assets/BlackBishop.svg +1 -0
- package/dist/assets/BlackKing.svg +1 -0
- package/dist/assets/BlackKnight.svg +1 -0
- package/dist/assets/BlackPawn.svg +1 -0
- package/dist/assets/BlackQueen.svg +1 -0
- package/dist/assets/BlackRook.svg +1 -0
- package/dist/assets/WhiteBishop.svg +1 -0
- package/dist/assets/WhiteKing.svg +1 -0
- package/dist/assets/WhiteKnight.svg +1 -0
- package/dist/assets/WhitePawn.svg +1 -0
- package/dist/assets/WhiteQueen.svg +1 -0
- package/dist/assets/WhiteRook.svg +1 -0
- package/dist/assets/clock.svg +42 -0
- package/dist/assets/index.d.ts +12 -0
- package/dist/assets/index.ts +12 -0
- package/dist/check-board.cjs.js +23 -0
- package/dist/check-board.cjs.js.map +1 -0
- package/dist/check-board.es.js +3664 -0
- package/dist/check-board.es.js.map +1 -0
- package/dist/check-board.umd.js +23 -0
- package/dist/check-board.umd.js.map +1 -0
- package/dist/components/board.d.ts +3 -0
- package/dist/components/boardEngine.d.ts +5 -0
- package/dist/engine/boardRuntime/boardEvents.d.ts +11 -0
- package/dist/engine/boardRuntime/boardRuntime.d.ts +17439 -0
- package/dist/engine/boardRuntime/pipelineRender.d.ts +20 -0
- package/dist/engine/client/client.d.ts +65 -0
- package/dist/engine/client/imperativeHandle.d.ts +6 -0
- package/dist/engine/client/interface.d.ts +35 -0
- package/dist/engine/eventEmitter/eventEmitter.d.ts +10 -0
- package/dist/engine/eventEmitter/interface.d.ts +4 -0
- package/dist/engine/helpers/engineHelpers.d.ts +41 -0
- package/dist/engine/helpers/pieceHelpers.d.ts +26 -0
- package/dist/engine/helpers/pointerEventsHelpers.d.ts +36 -0
- package/dist/engine/iterators/iterators.d.ts +16 -0
- package/dist/engine/layers/baseLayer.d.ts +74 -0
- package/dist/engine/layers/boardLayer.d.ts +8 -0
- package/dist/engine/layers/canvasLayers.d.ts +44 -0
- package/dist/engine/layers/dynamicPiecesLayer.d.ts +16 -0
- package/dist/engine/layers/events.d.ts +29 -0
- package/dist/engine/layers/interface.d.ts +16 -0
- package/dist/engine/layers/layerManager.d.ts +45 -0
- package/dist/engine/layers/overlayLayer.d.ts +8 -0
- package/dist/engine/layers/spatialIndex.d.ts +23 -0
- package/dist/engine/layers/spatialNode.d.ts +8 -0
- package/dist/engine/layers/staticPieces.d.ts +14 -0
- package/dist/engine/layers/underlayLayer.d.ts +8 -0
- package/dist/engine/render/interface.d.ts +12 -0
- package/dist/engine/render/pipelineRender.d.ts +20 -0
- package/dist/engine/render/renderer2D.d.ts +19 -0
- package/dist/engine/render/renderer3D.d.ts +15 -0
- package/dist/index.d.ts +3 -0
- package/dist/types/board.d.ts +83 -0
- package/dist/types/draw.d.ts +78 -0
- package/dist/types/events.d.ts +142 -0
- package/dist/types/helpers.d.ts +20 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/piece.d.ts +29 -0
- package/dist/types/square.d.ts +9 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/utils/utils.d.ts +46 -0
- package/package.json +39 -0
|
@@ -0,0 +1,3664 @@
|
|
|
1
|
+
import oe, { useCallback as K, useRef as O, useMemo as le, useEffect as ue, useImperativeHandle as he } from "react";
|
|
2
|
+
var G = { exports: {} }, F = {};
|
|
3
|
+
/**
|
|
4
|
+
* @license React
|
|
5
|
+
* react-jsx-runtime.production.js
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the MIT license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
var ne;
|
|
13
|
+
function de() {
|
|
14
|
+
if (ne) return F;
|
|
15
|
+
ne = 1;
|
|
16
|
+
var d = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
17
|
+
function t(r, n, i) {
|
|
18
|
+
var s = null;
|
|
19
|
+
if (i !== void 0 && (s = "" + i), n.key !== void 0 && (s = "" + n.key), "key" in n) {
|
|
20
|
+
i = {};
|
|
21
|
+
for (var a in n)
|
|
22
|
+
a !== "key" && (i[a] = n[a]);
|
|
23
|
+
} else i = n;
|
|
24
|
+
return n = i.ref, {
|
|
25
|
+
$$typeof: d,
|
|
26
|
+
type: r,
|
|
27
|
+
key: s,
|
|
28
|
+
ref: n !== void 0 ? n : null,
|
|
29
|
+
props: i
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return F.Fragment = e, F.jsx = t, F.jsxs = t, F;
|
|
33
|
+
}
|
|
34
|
+
var V = {};
|
|
35
|
+
/**
|
|
36
|
+
* @license React
|
|
37
|
+
* react-jsx-runtime.development.js
|
|
38
|
+
*
|
|
39
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
40
|
+
*
|
|
41
|
+
* This source code is licensed under the MIT license found in the
|
|
42
|
+
* LICENSE file in the root directory of this source tree.
|
|
43
|
+
*/
|
|
44
|
+
var ie;
|
|
45
|
+
function fe() {
|
|
46
|
+
return ie || (ie = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
+
function d(l) {
|
|
48
|
+
if (l == null) return null;
|
|
49
|
+
if (typeof l == "function")
|
|
50
|
+
return l.$$typeof === I ? null : l.displayName || l.name || null;
|
|
51
|
+
if (typeof l == "string") return l;
|
|
52
|
+
switch (l) {
|
|
53
|
+
case v:
|
|
54
|
+
return "Fragment";
|
|
55
|
+
case p:
|
|
56
|
+
return "Profiler";
|
|
57
|
+
case C:
|
|
58
|
+
return "StrictMode";
|
|
59
|
+
case x:
|
|
60
|
+
return "Suspense";
|
|
61
|
+
case M:
|
|
62
|
+
return "SuspenseList";
|
|
63
|
+
case A:
|
|
64
|
+
return "Activity";
|
|
65
|
+
}
|
|
66
|
+
if (typeof l == "object")
|
|
67
|
+
switch (typeof l.tag == "number" && console.error(
|
|
68
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
69
|
+
), l.$$typeof) {
|
|
70
|
+
case P:
|
|
71
|
+
return "Portal";
|
|
72
|
+
case w:
|
|
73
|
+
return l.displayName || "Context";
|
|
74
|
+
case m:
|
|
75
|
+
return (l._context.displayName || "Context") + ".Consumer";
|
|
76
|
+
case R:
|
|
77
|
+
var S = l.render;
|
|
78
|
+
return l = l.displayName, l || (l = S.displayName || S.name || "", l = l !== "" ? "ForwardRef(" + l + ")" : "ForwardRef"), l;
|
|
79
|
+
case E:
|
|
80
|
+
return S = l.displayName || null, S !== null ? S : d(l.type) || "Memo";
|
|
81
|
+
case T:
|
|
82
|
+
S = l._payload, l = l._init;
|
|
83
|
+
try {
|
|
84
|
+
return d(l(S));
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function e(l) {
|
|
91
|
+
return "" + l;
|
|
92
|
+
}
|
|
93
|
+
function t(l) {
|
|
94
|
+
try {
|
|
95
|
+
e(l);
|
|
96
|
+
var S = !1;
|
|
97
|
+
} catch {
|
|
98
|
+
S = !0;
|
|
99
|
+
}
|
|
100
|
+
if (S) {
|
|
101
|
+
S = console;
|
|
102
|
+
var k = S.error, D = typeof Symbol == "function" && Symbol.toStringTag && l[Symbol.toStringTag] || l.constructor.name || "Object";
|
|
103
|
+
return k.call(
|
|
104
|
+
S,
|
|
105
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
|
+
D
|
|
107
|
+
), e(l);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function r(l) {
|
|
111
|
+
if (l === v) return "<>";
|
|
112
|
+
if (typeof l == "object" && l !== null && l.$$typeof === T)
|
|
113
|
+
return "<...>";
|
|
114
|
+
try {
|
|
115
|
+
var S = d(l);
|
|
116
|
+
return S ? "<" + S + ">" : "<...>";
|
|
117
|
+
} catch {
|
|
118
|
+
return "<...>";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function n() {
|
|
122
|
+
var l = z.A;
|
|
123
|
+
return l === null ? null : l.getOwner();
|
|
124
|
+
}
|
|
125
|
+
function i() {
|
|
126
|
+
return Error("react-stack-top-frame");
|
|
127
|
+
}
|
|
128
|
+
function s(l) {
|
|
129
|
+
if (q.call(l, "key")) {
|
|
130
|
+
var S = Object.getOwnPropertyDescriptor(l, "key").get;
|
|
131
|
+
if (S && S.isReactWarning) return !1;
|
|
132
|
+
}
|
|
133
|
+
return l.key !== void 0;
|
|
134
|
+
}
|
|
135
|
+
function a(l, S) {
|
|
136
|
+
function k() {
|
|
137
|
+
W || (W = !0, console.error(
|
|
138
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
139
|
+
S
|
|
140
|
+
));
|
|
141
|
+
}
|
|
142
|
+
k.isReactWarning = !0, Object.defineProperty(l, "key", {
|
|
143
|
+
get: k,
|
|
144
|
+
configurable: !0
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function o() {
|
|
148
|
+
var l = d(this.type);
|
|
149
|
+
return Q[l] || (Q[l] = !0, console.error(
|
|
150
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
151
|
+
)), l = this.props.ref, l !== void 0 ? l : null;
|
|
152
|
+
}
|
|
153
|
+
function c(l, S, k, D, X, J) {
|
|
154
|
+
var L = k.ref;
|
|
155
|
+
return l = {
|
|
156
|
+
$$typeof: g,
|
|
157
|
+
type: l,
|
|
158
|
+
key: S,
|
|
159
|
+
props: k,
|
|
160
|
+
_owner: D
|
|
161
|
+
}, (L !== void 0 ? L : null) !== null ? Object.defineProperty(l, "ref", {
|
|
162
|
+
enumerable: !1,
|
|
163
|
+
get: o
|
|
164
|
+
}) : Object.defineProperty(l, "ref", { enumerable: !1, value: null }), l._store = {}, Object.defineProperty(l._store, "validated", {
|
|
165
|
+
configurable: !1,
|
|
166
|
+
enumerable: !1,
|
|
167
|
+
writable: !0,
|
|
168
|
+
value: 0
|
|
169
|
+
}), Object.defineProperty(l, "_debugInfo", {
|
|
170
|
+
configurable: !1,
|
|
171
|
+
enumerable: !1,
|
|
172
|
+
writable: !0,
|
|
173
|
+
value: null
|
|
174
|
+
}), Object.defineProperty(l, "_debugStack", {
|
|
175
|
+
configurable: !1,
|
|
176
|
+
enumerable: !1,
|
|
177
|
+
writable: !0,
|
|
178
|
+
value: X
|
|
179
|
+
}), Object.defineProperty(l, "_debugTask", {
|
|
180
|
+
configurable: !1,
|
|
181
|
+
enumerable: !1,
|
|
182
|
+
writable: !0,
|
|
183
|
+
value: J
|
|
184
|
+
}), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l;
|
|
185
|
+
}
|
|
186
|
+
function u(l, S, k, D, X, J) {
|
|
187
|
+
var L = S.children;
|
|
188
|
+
if (L !== void 0)
|
|
189
|
+
if (D)
|
|
190
|
+
if (j(L)) {
|
|
191
|
+
for (D = 0; D < L.length; D++)
|
|
192
|
+
h(L[D]);
|
|
193
|
+
Object.freeze && Object.freeze(L);
|
|
194
|
+
} else
|
|
195
|
+
console.error(
|
|
196
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
197
|
+
);
|
|
198
|
+
else h(L);
|
|
199
|
+
if (q.call(S, "key")) {
|
|
200
|
+
L = d(l);
|
|
201
|
+
var _ = Object.keys(S).filter(function(ce) {
|
|
202
|
+
return ce !== "key";
|
|
203
|
+
});
|
|
204
|
+
D = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", re[L + D] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
205
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
206
|
+
let props = %s;
|
|
207
|
+
<%s {...props} />
|
|
208
|
+
React keys must be passed directly to JSX without using spread:
|
|
209
|
+
let props = %s;
|
|
210
|
+
<%s key={someKey} {...props} />`,
|
|
211
|
+
D,
|
|
212
|
+
L,
|
|
213
|
+
_,
|
|
214
|
+
L
|
|
215
|
+
), re[L + D] = !0);
|
|
216
|
+
}
|
|
217
|
+
if (L = null, k !== void 0 && (t(k), L = "" + k), s(S) && (t(S.key), L = "" + S.key), "key" in S) {
|
|
218
|
+
k = {};
|
|
219
|
+
for (var Z in S)
|
|
220
|
+
Z !== "key" && (k[Z] = S[Z]);
|
|
221
|
+
} else k = S;
|
|
222
|
+
return L && a(
|
|
223
|
+
k,
|
|
224
|
+
typeof l == "function" ? l.displayName || l.name || "Unknown" : l
|
|
225
|
+
), c(
|
|
226
|
+
l,
|
|
227
|
+
L,
|
|
228
|
+
k,
|
|
229
|
+
n(),
|
|
230
|
+
X,
|
|
231
|
+
J
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
function h(l) {
|
|
235
|
+
y(l) ? l._store && (l._store.validated = 1) : typeof l == "object" && l !== null && l.$$typeof === T && (l._payload.status === "fulfilled" ? y(l._payload.value) && l._payload.value._store && (l._payload.value._store.validated = 1) : l._store && (l._store.validated = 1));
|
|
236
|
+
}
|
|
237
|
+
function y(l) {
|
|
238
|
+
return typeof l == "object" && l !== null && l.$$typeof === g;
|
|
239
|
+
}
|
|
240
|
+
var f = oe, g = Symbol.for("react.transitional.element"), P = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), p = Symbol.for("react.profiler"), m = Symbol.for("react.consumer"), w = Symbol.for("react.context"), R = Symbol.for("react.forward_ref"), x = Symbol.for("react.suspense"), M = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), A = Symbol.for("react.activity"), I = Symbol.for("react.client.reference"), z = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, j = Array.isArray, B = console.createTask ? console.createTask : function() {
|
|
241
|
+
return null;
|
|
242
|
+
};
|
|
243
|
+
f = {
|
|
244
|
+
react_stack_bottom_frame: function(l) {
|
|
245
|
+
return l();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var W, Q = {}, U = f.react_stack_bottom_frame.bind(
|
|
249
|
+
f,
|
|
250
|
+
i
|
|
251
|
+
)(), Y = B(r(i)), re = {};
|
|
252
|
+
V.Fragment = v, V.jsx = function(l, S, k) {
|
|
253
|
+
var D = 1e4 > z.recentlyCreatedOwnerStacks++;
|
|
254
|
+
return u(
|
|
255
|
+
l,
|
|
256
|
+
S,
|
|
257
|
+
k,
|
|
258
|
+
!1,
|
|
259
|
+
D ? Error("react-stack-top-frame") : U,
|
|
260
|
+
D ? B(r(l)) : Y
|
|
261
|
+
);
|
|
262
|
+
}, V.jsxs = function(l, S, k) {
|
|
263
|
+
var D = 1e4 > z.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return u(
|
|
265
|
+
l,
|
|
266
|
+
S,
|
|
267
|
+
k,
|
|
268
|
+
!0,
|
|
269
|
+
D ? Error("react-stack-top-frame") : U,
|
|
270
|
+
D ? B(r(l)) : Y
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
})()), V;
|
|
274
|
+
}
|
|
275
|
+
var se;
|
|
276
|
+
function ge() {
|
|
277
|
+
return se || (se = 1, process.env.NODE_ENV === "production" ? G.exports = de() : G.exports = fe()), G.exports;
|
|
278
|
+
}
|
|
279
|
+
var H = ge();
|
|
280
|
+
class b {
|
|
281
|
+
static files = "abcdefgh";
|
|
282
|
+
static P1 = 73856093;
|
|
283
|
+
static P2 = 19349663;
|
|
284
|
+
static P3 = 83492791;
|
|
285
|
+
static P4 = 1640531513;
|
|
286
|
+
constructor() {
|
|
287
|
+
}
|
|
288
|
+
static getHashingNumbers() {
|
|
289
|
+
const { P1: e, P2: t, P3: r, P4: n } = this;
|
|
290
|
+
return { P1: e, P2: t, P3: r, P4: n };
|
|
291
|
+
}
|
|
292
|
+
static squareToCoords(e, t, r) {
|
|
293
|
+
if (e) {
|
|
294
|
+
const n = this.files.indexOf(e.file), i = e.rank - 1;
|
|
295
|
+
return r ? {
|
|
296
|
+
x: Math.floor((7 - n) * t),
|
|
297
|
+
y: Math.floor(i * t)
|
|
298
|
+
} : {
|
|
299
|
+
x: Math.floor(n * t),
|
|
300
|
+
y: Math.floor((7 - i) * t)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
static coordsToSquare = (e, t, r, n) => {
|
|
305
|
+
let i = Math.floor(e / r), s = 7 - Math.floor(t / r);
|
|
306
|
+
if (i < 0 || i > 7 || s < 0 || s > 8) return null;
|
|
307
|
+
n && (i = 7 - Math.floor(e / r), s = Math.floor(t / r));
|
|
308
|
+
const a = this.files[i], o = s + 1;
|
|
309
|
+
return a && o ? { file: a, rank: o, notation: `${a}${o}` } : null;
|
|
310
|
+
};
|
|
311
|
+
static notationToSquare(e) {
|
|
312
|
+
if (e.length !== 2) return null;
|
|
313
|
+
const t = e.charAt(0), r = parseInt(e.charAt(1));
|
|
314
|
+
if (/^[a-h]$/.test(t)) {
|
|
315
|
+
if (r < 1 || r > 8) return null;
|
|
316
|
+
} else return null;
|
|
317
|
+
return { file: t, rank: r, notation: e };
|
|
318
|
+
}
|
|
319
|
+
static getCanvasCoords = (e) => {
|
|
320
|
+
const t = e.target.getBoundingClientRect(), r = e.clientX - t.left, n = e.clientY - t.top;
|
|
321
|
+
return { offsetX: r, offsetY: n };
|
|
322
|
+
};
|
|
323
|
+
static async asyncHandler(e) {
|
|
324
|
+
return new Promise((t) => {
|
|
325
|
+
e(t);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
static deepFreeze(e) {
|
|
329
|
+
const t = structuredClone(e);
|
|
330
|
+
if (t === null || typeof t != "object" || Object.isFrozen(t))
|
|
331
|
+
return t;
|
|
332
|
+
if (t instanceof Array)
|
|
333
|
+
t.forEach((r, n) => {
|
|
334
|
+
t[n] = this.deepFreeze(r);
|
|
335
|
+
});
|
|
336
|
+
else if (t instanceof Map)
|
|
337
|
+
t.forEach((r, n) => {
|
|
338
|
+
t.set(this.deepFreeze(n), this.deepFreeze(r));
|
|
339
|
+
});
|
|
340
|
+
else if (t instanceof Set) {
|
|
341
|
+
const r = Array.from(t).map(this.deepFreeze);
|
|
342
|
+
t.clear(), r.forEach((n) => t.add(n));
|
|
343
|
+
} else
|
|
344
|
+
Object.getOwnPropertyNames(t).forEach((r) => {
|
|
345
|
+
const n = t[r];
|
|
346
|
+
t[r] = this.deepFreeze(n);
|
|
347
|
+
});
|
|
348
|
+
return Object.freeze(t);
|
|
349
|
+
}
|
|
350
|
+
static parseFen(e) {
|
|
351
|
+
if (e = e.trim(), !this.validateFen(e).status) return {};
|
|
352
|
+
const r = e.split("/"), n = /^[1-8]$/, i = /^[PNBRQK]$/, s = "abcdefgh", a = {};
|
|
353
|
+
let o = 8;
|
|
354
|
+
for (const c of r) {
|
|
355
|
+
let u = 0;
|
|
356
|
+
for (const h of c) {
|
|
357
|
+
if (n.test(h)) {
|
|
358
|
+
u += Number(h);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const y = i.test(h), f = s[u], g = o, P = `${y ? "w" : "b"}${h.toUpperCase()}`, v = `${f}${g}`;
|
|
362
|
+
a[P] || (a[P] = []), a[P].push(v), u++;
|
|
363
|
+
}
|
|
364
|
+
o--;
|
|
365
|
+
}
|
|
366
|
+
return a;
|
|
367
|
+
}
|
|
368
|
+
static parseBoard(e) {
|
|
369
|
+
const t = "abcdefgh";
|
|
370
|
+
let r = "";
|
|
371
|
+
for (let n = 8; n >= 1; n--) {
|
|
372
|
+
let i = 0;
|
|
373
|
+
for (const s of t) {
|
|
374
|
+
const a = `${s}${n}`, o = e[a];
|
|
375
|
+
if (o) {
|
|
376
|
+
i > 0 && (r += i, i = 0);
|
|
377
|
+
const u = o.type.startsWith("w") ? o.type[1] : o.type[1].toLowerCase();
|
|
378
|
+
r += u;
|
|
379
|
+
} else i++;
|
|
380
|
+
}
|
|
381
|
+
i > 0 && (r += i), n !== 1 && (r += "/");
|
|
382
|
+
}
|
|
383
|
+
return r;
|
|
384
|
+
}
|
|
385
|
+
static validateFen(e) {
|
|
386
|
+
if (e = e.trim(), !/^(?:[pnbrqkPNBRQK1-8]+\/){7}[pnbrqkPNBRQK1-8]+$/.test(e))
|
|
387
|
+
return { status: !1, error: "Invalid format or characters" };
|
|
388
|
+
const t = e.split("/");
|
|
389
|
+
if (t.length !== 8)
|
|
390
|
+
return { status: !1, error: "Must contain exactly 8 ranks" };
|
|
391
|
+
const r = /^[1-8]$/, n = /^[pnbrqkPNBRQK]$/;
|
|
392
|
+
for (const i of t) {
|
|
393
|
+
let s = 0;
|
|
394
|
+
for (const a of i)
|
|
395
|
+
if (r.test(a)) s += Number(a);
|
|
396
|
+
else if (n.test(a)) s += 1;
|
|
397
|
+
else return { status: !1, error: `Invalid char '${a}'` };
|
|
398
|
+
if (s !== 8)
|
|
399
|
+
return { status: !1, error: `Rank '${i}' does not sum to 8` };
|
|
400
|
+
}
|
|
401
|
+
return { status: !0 };
|
|
402
|
+
}
|
|
403
|
+
static createBaseCtx(e) {
|
|
404
|
+
const t = /* @__PURE__ */ new Map();
|
|
405
|
+
let r = [];
|
|
406
|
+
const n = [], i = [];
|
|
407
|
+
function s(f, g, P, v) {
|
|
408
|
+
const C = e.shadowBlur || 0, p = e.shadowOffsetX || 0, m = e.shadowOffsetY || 0, w = Math.abs(p) + C, R = Math.abs(m) + C;
|
|
409
|
+
return {
|
|
410
|
+
x: f - w,
|
|
411
|
+
y: g - R,
|
|
412
|
+
w: P + w * 2,
|
|
413
|
+
h: v + R * 2
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function a(f, g, P, v, C) {
|
|
417
|
+
if (!Number.isFinite(g) || !Number.isFinite(P) || v <= 0 || C <= 0)
|
|
418
|
+
return;
|
|
419
|
+
const p = s(g, P, v, C);
|
|
420
|
+
n.push({
|
|
421
|
+
x: p.x,
|
|
422
|
+
y: p.y,
|
|
423
|
+
w: p.w,
|
|
424
|
+
h: p.h,
|
|
425
|
+
type: f
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
function o(f, g, P, v) {
|
|
429
|
+
!Number.isFinite(f) || !Number.isFinite(g) || P <= 0 || v <= 0 || i.push({
|
|
430
|
+
x: f,
|
|
431
|
+
y: g,
|
|
432
|
+
w: P,
|
|
433
|
+
h: v
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function c(f, g, P, v = 0.05) {
|
|
437
|
+
const C = [];
|
|
438
|
+
for (let p = 0; p <= 1.001; p += v) {
|
|
439
|
+
const m = (1 - p) * (1 - p) * f.x + 2 * (1 - p) * p * g.x + p * p * P.x, w = (1 - p) * (1 - p) * f.y + 2 * (1 - p) * p * g.y + p * p * P.y;
|
|
440
|
+
C.push({ x: m, y: w });
|
|
441
|
+
}
|
|
442
|
+
return C;
|
|
443
|
+
}
|
|
444
|
+
function u(f, g, P, v, C = 0.05) {
|
|
445
|
+
const p = [];
|
|
446
|
+
for (let m = 0; m <= 1.001; m += C) {
|
|
447
|
+
const w = Math.pow(1 - m, 3) * f.x + 3 * Math.pow(1 - m, 2) * m * g.x + 3 * (1 - m) * Math.pow(m, 2) * P.x + Math.pow(m, 3) * v.x, R = Math.pow(1 - m, 3) * f.y + 3 * Math.pow(1 - m, 2) * m * g.y + 3 * (1 - m) * Math.pow(m, 2) * P.y + Math.pow(m, 3) * v.y;
|
|
448
|
+
p.push({ x: w, y: R });
|
|
449
|
+
}
|
|
450
|
+
return p;
|
|
451
|
+
}
|
|
452
|
+
function h(f) {
|
|
453
|
+
const P = f.font.match(/(\d+(?:\.\d+)?)px/);
|
|
454
|
+
return P ? parseFloat(P[1]) : 16;
|
|
455
|
+
}
|
|
456
|
+
const y = new Proxy(e, {
|
|
457
|
+
get(f, g) {
|
|
458
|
+
if (t.has(g)) return t.get(g);
|
|
459
|
+
const P = f[g];
|
|
460
|
+
if (typeof P != "function")
|
|
461
|
+
return t.set(g, P), P;
|
|
462
|
+
const C = ((...p) => {
|
|
463
|
+
try {
|
|
464
|
+
switch (g) {
|
|
465
|
+
case "beginPath":
|
|
466
|
+
r = [];
|
|
467
|
+
break;
|
|
468
|
+
case "moveTo":
|
|
469
|
+
case "lineTo": {
|
|
470
|
+
const [m, w] = p;
|
|
471
|
+
Number.isFinite(m) && Number.isFinite(w) && r.push({ x: m, y: w });
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
case "rect": {
|
|
475
|
+
const [m, w, R, x] = p;
|
|
476
|
+
a(g, m, w, R, x), r.push({ x: m, y: w }, { x: m + R, y: w + x });
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
case "arc": {
|
|
480
|
+
const [m, w, R] = p;
|
|
481
|
+
Number.isFinite(m) && Number.isFinite(w) && Number.isFinite(R) && (a(g, m - R, w - R, R * 2, R * 2), r.push(
|
|
482
|
+
{ x: m - R, y: w - R },
|
|
483
|
+
{ x: m + R, y: w + R }
|
|
484
|
+
));
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
case "ellipse": {
|
|
488
|
+
const [m, w, R, x] = p;
|
|
489
|
+
Number.isFinite(m) && Number.isFinite(w) && R && x && (a(g, m - R, w - x, R * 2, x * 2), r.push(
|
|
490
|
+
{ x: m - R, y: w - x },
|
|
491
|
+
{ x: m + R, y: w + x }
|
|
492
|
+
));
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
case "quadraticCurveTo": {
|
|
496
|
+
const [m, w, R, x] = p, M = r[r.length - 1];
|
|
497
|
+
if (M && Number.isFinite(m) && Number.isFinite(w)) {
|
|
498
|
+
const E = c(M, { x: m, y: w }, { x: R, y: x });
|
|
499
|
+
r.push(...E);
|
|
500
|
+
} else
|
|
501
|
+
r.push({ x: R, y: x });
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
case "bezierCurveTo": {
|
|
505
|
+
const [m, w, R, x, M, E] = p, T = r[r.length - 1];
|
|
506
|
+
if (T && [m, w, R, x, M, E].every(Number.isFinite)) {
|
|
507
|
+
const A = u(
|
|
508
|
+
T,
|
|
509
|
+
{ x: m, y: w },
|
|
510
|
+
{ x: R, y: x },
|
|
511
|
+
{ x: M, y: E }
|
|
512
|
+
);
|
|
513
|
+
r.push(...A);
|
|
514
|
+
} else
|
|
515
|
+
r.push({ x: M, y: E });
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
case "fill":
|
|
519
|
+
case "stroke": {
|
|
520
|
+
if (p[0] instanceof Path2D)
|
|
521
|
+
a(g, 0, 0, e.canvas.width, e.canvas.height);
|
|
522
|
+
else if (r.length) {
|
|
523
|
+
const w = r.map((I) => I.x), R = r.map((I) => I.y), x = Math.min(...w), M = Math.min(...R), E = Math.max(...w), T = Math.max(...R), A = Math.max((e.lineWidth ?? 1) * 0.95, 1);
|
|
524
|
+
a(
|
|
525
|
+
g,
|
|
526
|
+
x - A,
|
|
527
|
+
M - A,
|
|
528
|
+
E - x + A * 2,
|
|
529
|
+
T - M + A * 2
|
|
530
|
+
), r = [];
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
case "fillRect":
|
|
535
|
+
case "strokeRect": {
|
|
536
|
+
const [m, w, R, x] = p, M = e.lineWidth ?? 2;
|
|
537
|
+
a(g, m - M, w - M, R + M * 2, x + M * 2);
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
case "fillText":
|
|
541
|
+
case "strokeText": {
|
|
542
|
+
const [m, w, R] = p;
|
|
543
|
+
if (typeof m != "string" || !Number.isFinite(w) || !Number.isFinite(R))
|
|
544
|
+
break;
|
|
545
|
+
const x = h(e), M = e.measureText(m), E = M.actualBoundingBoxAscent || x * 0.8, T = M.actualBoundingBoxDescent || x * 0.2, A = M.width || m.length * x * 0.5, I = x * 0.35, z = x * 0.15, q = x * 0.2;
|
|
546
|
+
let j = w, B = R - E;
|
|
547
|
+
switch (e.textAlign) {
|
|
548
|
+
case "center":
|
|
549
|
+
j = w - A / 2;
|
|
550
|
+
break;
|
|
551
|
+
case "right":
|
|
552
|
+
case "end":
|
|
553
|
+
j = w - A;
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
switch (e.textBaseline) {
|
|
557
|
+
case "top":
|
|
558
|
+
B = R;
|
|
559
|
+
break;
|
|
560
|
+
case "middle":
|
|
561
|
+
B = R - E * 0.6;
|
|
562
|
+
break;
|
|
563
|
+
case "bottom":
|
|
564
|
+
B = R - E - T;
|
|
565
|
+
break;
|
|
566
|
+
case "alphabetic":
|
|
567
|
+
default:
|
|
568
|
+
B = R - E;
|
|
569
|
+
}
|
|
570
|
+
const W = j - q, Q = B - I, U = A + q * 2, Y = E + T + I + z;
|
|
571
|
+
a(g, W, Q, U, Y), o(j, B, A, E + T);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case "drawImage": {
|
|
575
|
+
let m = null, w = 0, R = 0, x = 0, M = 0;
|
|
576
|
+
if (p.length === 3 ? ([m, w, R] = p, x = m?.width ?? 32, M = m?.height ?? 32) : p.length === 5 ? [m, w, R, x, M] = p : p.length === 9 && ([, , , , , w, R, x, M] = p, m = p[0]), m instanceof HTMLVideoElement) {
|
|
577
|
+
console.warn(
|
|
578
|
+
"⚠️ [SafeCtx] drawImage with video is blocked for safety reasons."
|
|
579
|
+
);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const E = 0;
|
|
583
|
+
a(
|
|
584
|
+
"drawImage",
|
|
585
|
+
w - E,
|
|
586
|
+
R - E,
|
|
587
|
+
x + E * 2,
|
|
588
|
+
M + E * 2
|
|
589
|
+
), o(w, R, x, M);
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
} catch (m) {
|
|
594
|
+
console.warn(`[SafeCtx:${g}]`, m);
|
|
595
|
+
}
|
|
596
|
+
return P.apply(f, p);
|
|
597
|
+
}).bind(f);
|
|
598
|
+
return t.set(g, C), C;
|
|
599
|
+
},
|
|
600
|
+
set(f, g, P) {
|
|
601
|
+
return f[g] = P, !0;
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
return y.__drawRegions = n, y.__currentPath = r, y.__clearRegions = () => {
|
|
605
|
+
n.length = 0, i.length = 0;
|
|
606
|
+
}, y.__actualRegions = i, y;
|
|
607
|
+
}
|
|
608
|
+
static createSafeCtx(e) {
|
|
609
|
+
const t = /* @__PURE__ */ new Set([
|
|
610
|
+
"clearRect",
|
|
611
|
+
"reset",
|
|
612
|
+
"resetTransform",
|
|
613
|
+
"restore",
|
|
614
|
+
"save",
|
|
615
|
+
"scale",
|
|
616
|
+
"rotate",
|
|
617
|
+
"translate",
|
|
618
|
+
"transform",
|
|
619
|
+
"setTransform",
|
|
620
|
+
"clip",
|
|
621
|
+
"arcTo"
|
|
622
|
+
]), r = /* @__PURE__ */ new Set([
|
|
623
|
+
"canvas",
|
|
624
|
+
"filter",
|
|
625
|
+
"globalAlpha",
|
|
626
|
+
"globalCompositeOperation"
|
|
627
|
+
]), n = /* @__PURE__ */ new Map();
|
|
628
|
+
return new Proxy(e, {
|
|
629
|
+
get(s, a, o) {
|
|
630
|
+
if (n.has(a)) return n.get(a);
|
|
631
|
+
if (t.has(a)) {
|
|
632
|
+
const u = () => console.warn(`⚠️ [SafeCtx] Access to ${a}() is restricted.`);
|
|
633
|
+
return n.set(a, u), u;
|
|
634
|
+
}
|
|
635
|
+
const c = s[a];
|
|
636
|
+
return n.set(a, c), c;
|
|
637
|
+
},
|
|
638
|
+
set(s, a, o) {
|
|
639
|
+
return r.has(a) ? (console.warn(
|
|
640
|
+
`⚠️ [SafeCtx] Modification to ${String(a)} is restricted.`
|
|
641
|
+
), !1) : (s[a] = o, !0);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
class me {
|
|
647
|
+
staticPiecesCanvas;
|
|
648
|
+
boardCanvas;
|
|
649
|
+
overlayCanvas;
|
|
650
|
+
underlayCanvas;
|
|
651
|
+
dynamicPiecesCanvas;
|
|
652
|
+
staticPiecesCtx = null;
|
|
653
|
+
boardCtx = null;
|
|
654
|
+
overlayCtx = null;
|
|
655
|
+
underlayCtx = null;
|
|
656
|
+
dynamicPiecesCtx = null;
|
|
657
|
+
clientStaticPiecesCtx = null;
|
|
658
|
+
clientBoardCtx = null;
|
|
659
|
+
clientOverlayCtx = null;
|
|
660
|
+
clientUnderlayCtx = null;
|
|
661
|
+
clientDynamicPiecesCtx = null;
|
|
662
|
+
clientCtxMap = {
|
|
663
|
+
staticPieces: this.clientStaticPiecesCtx,
|
|
664
|
+
board: this.clientBoardCtx,
|
|
665
|
+
overlay: this.clientOverlayCtx,
|
|
666
|
+
underlay: this.clientUnderlayCtx,
|
|
667
|
+
dynamicPieces: this.clientDynamicPiecesCtx
|
|
668
|
+
};
|
|
669
|
+
overlayOffscreen;
|
|
670
|
+
underlayOffscreen;
|
|
671
|
+
dynamicPiecesOffscreen;
|
|
672
|
+
overlayOffscreenCtx = null;
|
|
673
|
+
underlayOffscreenCtx = null;
|
|
674
|
+
dynamicPiecesOffscreenCtx = null;
|
|
675
|
+
size;
|
|
676
|
+
dpr = 1;
|
|
677
|
+
constructor(e, t, r, n, i, s) {
|
|
678
|
+
this.staticPiecesCanvas = t, this.boardCanvas = e, this.overlayCanvas = r, this.underlayCanvas = n, this.dynamicPiecesCanvas = i, this.size = s, this.disableTouchAction(), this.setContext(), this.setQuality();
|
|
679
|
+
}
|
|
680
|
+
destroy() {
|
|
681
|
+
this.clearAllRect(), this.clearCanvas();
|
|
682
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
683
|
+
this[e] = null;
|
|
684
|
+
}
|
|
685
|
+
disableTouchAction() {
|
|
686
|
+
[
|
|
687
|
+
"board",
|
|
688
|
+
"staticPieces",
|
|
689
|
+
"overlay",
|
|
690
|
+
"underlay",
|
|
691
|
+
"dynamicPieces"
|
|
692
|
+
].forEach((e) => this.setCanvasStyle(e, { touchAction: "none" }));
|
|
693
|
+
}
|
|
694
|
+
getContext(e) {
|
|
695
|
+
return this[`${e}Ctx`] === null && this[`${e}Canvas`].current && this.setContext(), this[`${e}Ctx`];
|
|
696
|
+
}
|
|
697
|
+
getClientContext(e) {
|
|
698
|
+
return this.clientCtxMap[e];
|
|
699
|
+
}
|
|
700
|
+
getCanvas(e) {
|
|
701
|
+
return this[`${e}Canvas`];
|
|
702
|
+
}
|
|
703
|
+
keepQuality(e, t) {
|
|
704
|
+
const r = this[`${e}Canvas`].current;
|
|
705
|
+
if (!r) return;
|
|
706
|
+
const n = window.devicePixelRatio || 1;
|
|
707
|
+
this.dpr = n;
|
|
708
|
+
const i = t * n, s = t * n;
|
|
709
|
+
if (r.width === i && r.height === s) return;
|
|
710
|
+
r.width = i, r.height = s, r.style.width = t + "px", r.style.height = t + "px";
|
|
711
|
+
const a = this.getContext(e);
|
|
712
|
+
a && (a.setTransform(1, 0, 0, 1, 0, 0), a.scale(n, n), a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "high");
|
|
713
|
+
}
|
|
714
|
+
getDpr() {
|
|
715
|
+
return this.dpr;
|
|
716
|
+
}
|
|
717
|
+
setCanvasStyle(e, t) {
|
|
718
|
+
const r = this[`${e}Canvas`].current;
|
|
719
|
+
if (r)
|
|
720
|
+
for (const [n, i] of Object.entries(t))
|
|
721
|
+
i && (r.style[n] = i);
|
|
722
|
+
}
|
|
723
|
+
setOffscreen() {
|
|
724
|
+
if (typeof OffscreenCanvas !== void 0)
|
|
725
|
+
try {
|
|
726
|
+
this.overlayOffscreen = new OffscreenCanvas(this.size, this.size), this.underlayOffscreen = new OffscreenCanvas(this.size, this.size), this.dynamicPiecesOffscreen = new OffscreenCanvas(this.size, this.size), this.overlayOffscreenCtx = this.overlayOffscreen.getContext("2d"), this.underlayOffscreenCtx = this.underlayOffscreen.getContext("2d"), this.dynamicPiecesOffscreenCtx = this.dynamicPiecesOffscreen.getContext("2d");
|
|
727
|
+
} catch {
|
|
728
|
+
console.warn(
|
|
729
|
+
"OffscreenCanvas not supported, using normal canvas rendering."
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
setContext() {
|
|
734
|
+
const e = this.staticPiecesCanvas.current?.getContext("2d"), t = this.boardCanvas.current?.getContext("2d"), r = this.overlayCanvas.current?.getContext("2d"), n = this.underlayCanvas.current?.getContext("2d"), i = this.dynamicPiecesCanvas.current?.getContext("2d");
|
|
735
|
+
this.staticPiecesCtx = e ? b.createBaseCtx(e) : null, this.boardCtx = t ? b.createBaseCtx(t) : null, this.overlayCtx = r ? b.createBaseCtx(r) : null, this.underlayCtx = n ? b.createBaseCtx(n) : null, this.dynamicPiecesCtx = i ? b.createBaseCtx(i) : null, this.clientStaticPiecesCtx = this.staticPiecesCtx ? b.createSafeCtx(this.staticPiecesCtx) : null, this.clientBoardCtx = this.boardCtx ? b.createSafeCtx(this.boardCtx) : null, this.clientOverlayCtx = this.overlayCtx ? b.createSafeCtx(this.overlayCtx) : null, this.clientUnderlayCtx = this.underlayCtx ? b.createSafeCtx(this.underlayCtx) : null, this.clientDynamicPiecesCtx = this.dynamicPiecesCtx ? b.createSafeCtx(this.dynamicPiecesCtx) : null, this.clientCtxMap = {
|
|
736
|
+
staticPieces: this.clientStaticPiecesCtx,
|
|
737
|
+
board: this.clientBoardCtx,
|
|
738
|
+
overlay: this.clientOverlayCtx,
|
|
739
|
+
underlay: this.clientUnderlayCtx,
|
|
740
|
+
dynamicPieces: this.clientDynamicPiecesCtx
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
setQuality() {
|
|
744
|
+
[
|
|
745
|
+
"board",
|
|
746
|
+
"staticPieces",
|
|
747
|
+
"overlay",
|
|
748
|
+
"underlay",
|
|
749
|
+
"dynamicPieces"
|
|
750
|
+
].forEach((e) => this.keepQuality(e, this.size));
|
|
751
|
+
}
|
|
752
|
+
blitOffscreenToMain() {
|
|
753
|
+
const e = this.overlayCtx, t = this.underlayCtx, r = this.dynamicPiecesCtx;
|
|
754
|
+
e && this.overlayOffscreen && e.drawImage(this.overlayOffscreen, 0, 0), t && this.underlayOffscreen && t.drawImage(this.underlayOffscreen, 0, 0), r && this.dynamicPiecesOffscreen && r.drawImage(this.dynamicPiecesOffscreen, 0, 0);
|
|
755
|
+
}
|
|
756
|
+
resize(e) {
|
|
757
|
+
this.size = e, this.setQuality();
|
|
758
|
+
}
|
|
759
|
+
clearAllRect(e) {
|
|
760
|
+
if (e) {
|
|
761
|
+
for (const [t, r] of Object.entries(e)) {
|
|
762
|
+
if (!r) continue;
|
|
763
|
+
this[`${t}Ctx`]?.clearRect(0, 0, this.size, this.size);
|
|
764
|
+
}
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
[
|
|
768
|
+
this.staticPiecesCtx,
|
|
769
|
+
this.boardCtx,
|
|
770
|
+
this.overlayCtx,
|
|
771
|
+
this.underlayCtx,
|
|
772
|
+
this.dynamicPiecesCtx
|
|
773
|
+
].forEach((t) => t?.clearRect(0, 0, this.size, this.size));
|
|
774
|
+
}
|
|
775
|
+
clearCanvas() {
|
|
776
|
+
[
|
|
777
|
+
this.boardCanvas,
|
|
778
|
+
this.overlayCanvas,
|
|
779
|
+
this.staticPiecesCanvas,
|
|
780
|
+
this.underlayCanvas,
|
|
781
|
+
this.dynamicPiecesCanvas
|
|
782
|
+
].forEach((t) => {
|
|
783
|
+
const r = t.current;
|
|
784
|
+
if (r) {
|
|
785
|
+
const n = r.getContext("2d");
|
|
786
|
+
n?.setTransform(1, 0, 0, 1, 0, 0), n?.clearRect(0, 0, r.width, r.height);
|
|
787
|
+
}
|
|
788
|
+
t.current = null;
|
|
789
|
+
}), this.boardCtx = null, this.overlayCtx = null, this.staticPiecesCtx = null, this.underlayCtx = null, this.dynamicPiecesCtx = null;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const ye = ({
|
|
793
|
+
boardRuntime: d,
|
|
794
|
+
boardRef: e,
|
|
795
|
+
staticPiecesRef: t,
|
|
796
|
+
overlayRef: r,
|
|
797
|
+
underlayRef: n,
|
|
798
|
+
dynamicPiecesRef: i,
|
|
799
|
+
size: s
|
|
800
|
+
}) => {
|
|
801
|
+
const a = K(
|
|
802
|
+
(h) => {
|
|
803
|
+
d.current?.boardEvents.OnPointerDown(h);
|
|
804
|
+
},
|
|
805
|
+
[d]
|
|
806
|
+
), o = K(
|
|
807
|
+
(h) => {
|
|
808
|
+
d.current?.boardEvents.onPointerMove(h);
|
|
809
|
+
},
|
|
810
|
+
[d]
|
|
811
|
+
), c = K(
|
|
812
|
+
(h) => {
|
|
813
|
+
d.current?.boardEvents.onPointerUp(h);
|
|
814
|
+
},
|
|
815
|
+
[d]
|
|
816
|
+
), u = K(
|
|
817
|
+
(h) => {
|
|
818
|
+
d.current?.boardEvents.onPointerLeave(h);
|
|
819
|
+
},
|
|
820
|
+
[d]
|
|
821
|
+
);
|
|
822
|
+
return /* @__PURE__ */ H.jsxs(
|
|
823
|
+
"div",
|
|
824
|
+
{
|
|
825
|
+
style: {
|
|
826
|
+
position: "relative",
|
|
827
|
+
width: s,
|
|
828
|
+
height: s
|
|
829
|
+
},
|
|
830
|
+
children: [
|
|
831
|
+
/* @__PURE__ */ H.jsx(
|
|
832
|
+
"canvas",
|
|
833
|
+
{
|
|
834
|
+
ref: e,
|
|
835
|
+
width: s,
|
|
836
|
+
height: s,
|
|
837
|
+
style: {
|
|
838
|
+
display: "block",
|
|
839
|
+
position: "absolute",
|
|
840
|
+
top: 0,
|
|
841
|
+
left: 0,
|
|
842
|
+
pointerEvents: "none",
|
|
843
|
+
zIndex: 1
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
),
|
|
847
|
+
/* @__PURE__ */ H.jsx(
|
|
848
|
+
"canvas",
|
|
849
|
+
{
|
|
850
|
+
ref: t,
|
|
851
|
+
width: s,
|
|
852
|
+
height: s,
|
|
853
|
+
style: {
|
|
854
|
+
position: "absolute",
|
|
855
|
+
top: 0,
|
|
856
|
+
left: 0,
|
|
857
|
+
background: "transparent",
|
|
858
|
+
zIndex: 2
|
|
859
|
+
},
|
|
860
|
+
onPointerDown: a,
|
|
861
|
+
onPointerMove: o,
|
|
862
|
+
onPointerUp: c,
|
|
863
|
+
onPointerLeave: u
|
|
864
|
+
}
|
|
865
|
+
),
|
|
866
|
+
/* @__PURE__ */ H.jsx(
|
|
867
|
+
"canvas",
|
|
868
|
+
{
|
|
869
|
+
ref: r,
|
|
870
|
+
style: {
|
|
871
|
+
position: "absolute",
|
|
872
|
+
top: 0,
|
|
873
|
+
left: 0,
|
|
874
|
+
background: "transparent",
|
|
875
|
+
pointerEvents: "none",
|
|
876
|
+
zIndex: 1
|
|
877
|
+
},
|
|
878
|
+
width: s,
|
|
879
|
+
height: s
|
|
880
|
+
}
|
|
881
|
+
),
|
|
882
|
+
/* @__PURE__ */ H.jsx(
|
|
883
|
+
"canvas",
|
|
884
|
+
{
|
|
885
|
+
ref: n,
|
|
886
|
+
width: s,
|
|
887
|
+
height: s,
|
|
888
|
+
style: {
|
|
889
|
+
position: "absolute",
|
|
890
|
+
top: 0,
|
|
891
|
+
left: 0,
|
|
892
|
+
background: "transparent",
|
|
893
|
+
zIndex: 3,
|
|
894
|
+
pointerEvents: "none"
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
),
|
|
898
|
+
/* @__PURE__ */ H.jsx(
|
|
899
|
+
"canvas",
|
|
900
|
+
{
|
|
901
|
+
ref: i,
|
|
902
|
+
width: s,
|
|
903
|
+
height: s,
|
|
904
|
+
style: {
|
|
905
|
+
position: "absolute",
|
|
906
|
+
top: 0,
|
|
907
|
+
left: 0,
|
|
908
|
+
background: "transparent",
|
|
909
|
+
zIndex: 4,
|
|
910
|
+
pointerEvents: "none"
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
)
|
|
914
|
+
]
|
|
915
|
+
}
|
|
916
|
+
);
|
|
917
|
+
}, ae = [
|
|
918
|
+
"wP",
|
|
919
|
+
"wB",
|
|
920
|
+
"wR",
|
|
921
|
+
"wN",
|
|
922
|
+
"wQ",
|
|
923
|
+
"wK",
|
|
924
|
+
"bP",
|
|
925
|
+
"bB",
|
|
926
|
+
"bR",
|
|
927
|
+
"bN",
|
|
928
|
+
"bQ",
|
|
929
|
+
"bK"
|
|
930
|
+
];
|
|
931
|
+
class ve {
|
|
932
|
+
constructor(e) {
|
|
933
|
+
this.boardRuntime = e, this.boardRuntime = e;
|
|
934
|
+
}
|
|
935
|
+
destroy() {
|
|
936
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
937
|
+
this[e] = null;
|
|
938
|
+
}
|
|
939
|
+
OnPointerDown(e) {
|
|
940
|
+
this.boardRuntime.getIsMoving() || (this.boardRuntime.getEventEmitter().emit("onPointerDown"), this.boardRuntime.helpers.pointerEventsHelper.startPress(e));
|
|
941
|
+
}
|
|
942
|
+
onPointerMove(e) {
|
|
943
|
+
this.boardRuntime.getIsMoving() || (this.boardRuntime.getEventEmitter().emit("onPointerMove"), this.boardRuntime.helpers.pointerEventsHelper.handlePieceHover(e), this.boardRuntime.helpers.pointerEventsHelper.handleGrab(e));
|
|
944
|
+
}
|
|
945
|
+
onPointerUp(e) {
|
|
946
|
+
this.boardRuntime.helpers.pointerEventsHelper.handlePointerUp(e), !this.boardRuntime.getIsMoving() && this.boardRuntime.getEventEmitter().emit("onPointerUp");
|
|
947
|
+
}
|
|
948
|
+
onPointerLeave(e) {
|
|
949
|
+
this.boardRuntime.getIsMoving() || this.boardRuntime.helpers.pointerEventsHelper.handlePointerLeave(e);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const pe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cpath%20fill='%23fff'%20stroke='%23000'%20stroke-linecap='round'%20stroke-width='1.5'%20d='M22.5%209c-2.21%200-4%201.79-4%204%200%20.89.29%201.71.78%202.38C17.33%2016.5%2016%2018.59%2016%2021c0%202.03.94%203.84%202.41%205.03-3%201.06-7.41%205.55-7.41%2013.47h23c0-7.92-4.41-12.41-7.41-13.47%201.47-1.19%202.41-3%202.41-5.03%200-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38%200-2.21-1.79-4-4-4z'/%3e%3c/svg%3e", Pe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cg%20fill='%23fff'%20stroke-linecap='butt'%3e%3cpath%20d='M9%2036c3.39-.97%2010.11.43%2013.5-2%203.39%202.43%2010.11%201.03%2013.5%202%200%200%201.65.54%203%202-.68.97-1.65.99-3%20.5-3.39-.97-10.11.46-13.5-1-3.39%201.46-10.11.03-13.5%201-1.35.49-2.32.47-3-.5%201.35-1.94%203-2%203-2z'/%3e%3cpath%20d='M15%2032c2.5%202.5%2012.5%202.5%2015%200%20.5-1.5%200-2%200-2%200-2.5-2.5-4-2.5-4%205.5-1.5%206-11.5-5-15.5-11%204-10.5%2014-5%2015.5%200%200-2.5%201.5-2.5%204%200%200-.5.5%200%202z'/%3e%3cpath%20d='M25%208a2.5%202.5%200%201%201-5%200%202.5%202.5%200%201%201%205%200z'/%3e%3c/g%3e%3cpath%20stroke-linejoin='miter'%20d='M17.5%2026h10M15%2030h15m-7.5-14.5v5M20%2018h5'/%3e%3c/g%3e%3c/svg%3e", we = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20fill='%23fff'%20d='M22%2010c10.5%201%2016.5%208%2016%2029H15c0-9%2010-6.5%208-21'/%3e%3cpath%20fill='%23fff'%20d='M24%2018c.38%202.91-5.55%207.37-8%209-3%202-2.82%204.34-5%204-1.042-.94%201.41-3.04%200-3-1%200%20.19%201.23-1%202-1%200-4.003%201-4-4%200-2%206-12%206-12s1.89-1.9%202-3.5c-.73-.994-.5-2-.5-3%201-1%203%202.5%203%202.5h2s.78-1.992%202.5-3c1%200%201%203%201%203'/%3e%3cpath%20fill='%23000'%20d='M9.5%2025.5a.5.5%200%201%201-1%200%20.5.5%200%201%201%201%200zm5.433-9.75a.5%201.5%2030%201%201-.866-.5.5%201.5%2030%201%201%20.866.5z'/%3e%3c/g%3e%3c/svg%3e", be = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='%23fff'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20stroke-linecap='butt'%20d='M9%2039h27v-3H9v3zm3-3v-4h21v4H12zm-1-22V9h4v2h5V9h5v2h5V9h4v5'/%3e%3cpath%20d='m34%2014-3%203H14l-3-3'/%3e%3cpath%20stroke-linecap='butt'%20stroke-linejoin='miter'%20d='M31%2017v12.5H14V17'/%3e%3cpath%20d='m31%2029.5%201.5%202.5h-20l1.5-2.5'/%3e%3cpath%20fill='none'%20stroke-linejoin='miter'%20d='M11%2014h23'/%3e%3c/g%3e%3c/svg%3e", Re = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='%23fff'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20d='M8%2012a2%202%200%201%201-4%200%202%202%200%201%201%204%200zm16.5-4.5a2%202%200%201%201-4%200%202%202%200%201%201%204%200zM41%2012a2%202%200%201%201-4%200%202%202%200%201%201%204%200zM16%208.5a2%202%200%201%201-4%200%202%202%200%201%201%204%200zM33%209a2%202%200%201%201-4%200%202%202%200%201%201%204%200z'/%3e%3cpath%20stroke-linecap='butt'%20d='M9%2026c8.5-1.5%2021-1.5%2027%200l2-12-7%2011V11l-5.5%2013.5-3-15-3%2015-5.5-14V25L7%2014l2%2012z'/%3e%3cpath%20stroke-linecap='butt'%20d='M9%2026c0%202%201.5%202%202.5%204%201%201.5%201%201%20.5%203.5-1.5%201-1.5%202.5-1.5%202.5-1.5%201.5.5%202.5.5%202.5%206.5%201%2016.5%201%2023%200%200%200%201.5-1%200-2.5%200%200%20.5-1.5-1-2.5-.5-2.5-.5-2%20.5-3.5%201-2%202.5-2%202.5-4-8.5-1.5-18.5-1.5-27%200z'/%3e%3cpath%20fill='none'%20d='M11.5%2030c3.5-1%2018.5-1%2022%200M12%2033.5c6-1%2015-1%2021%200'/%3e%3c/g%3e%3c/svg%3e", Ce = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20stroke-linejoin='miter'%20d='M22.5%2011.63V6M20%208h5'/%3e%3cpath%20fill='%23fff'%20stroke-linecap='butt'%20stroke-linejoin='miter'%20d='M22.5%2025s4.5-7.5%203-10.5c0%200-1-2.5-3-2.5s-3%202.5-3%202.5c-1.5%203%203%2010.5%203%2010.5'/%3e%3cpath%20fill='%23fff'%20d='M11.5%2037c5.5%203.5%2015.5%203.5%2021%200v-7s9-4.5%206-10.5c-4-6.5-13.5-3.5-16%204V27v-3.5c-3.5-7.5-13-10.5-16-4-3%206%205%2010%205%2010V37z'/%3e%3cpath%20d='M11.5%2030c5.5-3%2015.5-3%2021%200m-21%203.5c5.5-3%2015.5-3%2021%200m-21%203.5c5.5-3%2015.5-3%2021%200'/%3e%3c/g%3e%3c/svg%3e", xe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cpath%20stroke='%23000'%20stroke-linecap='round'%20stroke-width='1.5'%20d='M22.5%209a4%204%200%200%200-3.22%206.38%206.48%206.48%200%200%200-.87%2010.65c-3%201.06-7.41%205.55-7.41%2013.47h23c0-7.92-4.41-12.41-7.41-13.47a6.46%206.46%200%200%200-.87-10.65A4.01%204.01%200%200%200%2022.5%209z'/%3e%3c/svg%3e", Se = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cg%20fill='%23000'%20stroke-linecap='butt'%3e%3cpath%20d='M9%2036c3.4-1%2010.1.4%2013.5-2%203.4%202.4%2010.1%201%2013.5%202%200%200%201.6.5%203%202-.7%201-1.6%201-3%20.5-3.4-1-10.1.5-13.5-1-3.4%201.5-10.1%200-13.5%201-1.4.5-2.3.5-3-.5%201.4-2%203-2%203-2z'/%3e%3cpath%20d='M15%2032c2.5%202.5%2012.5%202.5%2015%200%20.5-1.5%200-2%200-2%200-2.5-2.5-4-2.5-4%205.5-1.5%206-11.5-5-15.5-11%204-10.5%2014-5%2015.5%200%200-2.5%201.5-2.5%204%200%200-.5.5%200%202z'/%3e%3cpath%20d='M25%208a2.5%202.5%200%201%201-5%200%202.5%202.5%200%201%201%205%200z'/%3e%3c/g%3e%3cpath%20stroke='%23ececec'%20stroke-linejoin='miter'%20d='M17.5%2026h10M15%2030h15m-7.5-14.5v5M20%2018h5'/%3e%3c/g%3e%3c/svg%3e", Me = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20fill='%23000'%20d='M22%2010c10.5%201%2016.5%208%2016%2029H15c0-9%2010-6.5%208-21'/%3e%3cpath%20fill='%23000'%20d='M24%2018c.38%202.91-5.55%207.37-8%209-3%202-2.82%204.34-5%204-1.04-.94%201.41-3.04%200-3-1%200%20.19%201.23-1%202-1%200-4%201-4-4%200-2%206-12%206-12s1.89-1.9%202-3.5c-.73-1-.5-2-.5-3%201-1%203%202.5%203%202.5h2s.78-2%202.5-3c1%200%201%203%201%203'/%3e%3cpath%20fill='%23ececec'%20stroke='%23ececec'%20d='M9.5%2025.5a.5.5%200%201%201-1%200%20.5.5%200%201%201%201%200zm5.43-9.75a.5%201.5%2030%201%201-.86-.5.5%201.5%2030%201%201%20.86.5z'/%3e%3cpath%20fill='%23ececec'%20stroke='none'%20d='m24.55%2010.4-.45%201.45.5.15c3.15%201%205.65%202.49%207.9%206.75S35.75%2029.06%2035.25%2039l-.05.5h2.25l.05-.5c.5-10.06-.88-16.85-3.25-21.34-2.37-4.49-5.79-6.64-9.19-7.16l-.51-.1z'/%3e%3c/g%3e%3c/svg%3e", ke = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20stroke-linecap='butt'%20d='M9%2039h27v-3H9v3zm3.5-7%201.5-2.5h17l1.5%202.5h-20zm-.5%204v-4h21v4H12z'/%3e%3cpath%20stroke-linecap='butt'%20stroke-linejoin='miter'%20d='M14%2029.5v-13h17v13H14z'/%3e%3cpath%20stroke-linecap='butt'%20d='M14%2016.5%2011%2014h23l-3%202.5H14zM11%2014V9h4v2h5V9h5v2h5V9h4v5H11z'/%3e%3cpath%20fill='none'%20stroke='%23ececec'%20stroke-linejoin='miter'%20stroke-width='1'%20d='M12%2035.5h21m-20-4h19m-18-2h17m-17-13h17M11%2014h23'/%3e%3c/g%3e%3c/svg%3e", Ee = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cg%20stroke='none'%3e%3ccircle%20cx='6'%20cy='12'%20r='2.75'/%3e%3ccircle%20cx='14'%20cy='9'%20r='2.75'/%3e%3ccircle%20cx='22.5'%20cy='8'%20r='2.75'/%3e%3ccircle%20cx='31'%20cy='9'%20r='2.75'/%3e%3ccircle%20cx='39'%20cy='12'%20r='2.75'/%3e%3c/g%3e%3cpath%20stroke-linecap='butt'%20d='M9%2026c8.5-1.5%2021-1.5%2027%200l2.5-12.5L31%2025l-.3-14.1-5.2%2013.6-3-14.5-3%2014.5-5.2-13.6L14%2025%206.5%2013.5%209%2026z'/%3e%3cpath%20stroke-linecap='butt'%20d='M9%2026c0%202%201.5%202%202.5%204%201%201.5%201%201%20.5%203.5-1.5%201-1.5%202.5-1.5%202.5-1.5%201.5.5%202.5.5%202.5%206.5%201%2016.5%201%2023%200%200%200%201.5-1%200-2.5%200%200%20.5-1.5-1-2.5-.5-2.5-.5-2%20.5-3.5%201-2%202.5-2%202.5-4-8.5-1.5-18.5-1.5-27%200z'/%3e%3cpath%20fill='none'%20stroke-linecap='butt'%20d='M11%2038.5a35%2035%201%200%200%2023%200'/%3e%3cpath%20fill='none'%20stroke='%23ececec'%20d='M11%2029a35%2035%201%200%201%2023%200m-21.5%202.5h20m-21%203a35%2035%201%200%200%2022%200m-23%203a35%2035%201%200%200%2024%200'/%3e%3c/g%3e%3c/svg%3e", De = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2045'%3e%3cg%20fill='none'%20fill-rule='evenodd'%20stroke='%23000'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1.5'%3e%3cpath%20stroke-linejoin='miter'%20d='M22.5%2011.6V6'/%3e%3cpath%20fill='%23000'%20stroke-linecap='butt'%20stroke-linejoin='miter'%20d='M22.5%2025s4.5-7.5%203-10.5c0%200-1-2.5-3-2.5s-3%202.5-3%202.5c-1.5%203%203%2010.5%203%2010.5'/%3e%3cpath%20fill='%23000'%20d='M11.5%2037a22.3%2022.3%200%200%200%2021%200v-7s9-4.5%206-10.5c-4-6.5-13.5-3.5-16%204V27v-3.5c-3.5-7.5-13-10.5-16-4-3%206%205%2010%205%2010V37z'/%3e%3cpath%20stroke-linejoin='miter'%20d='M20%208h5'/%3e%3cpath%20stroke='%23ececec'%20d='M32%2029.5s8.5-4%206-9.7C34.1%2014%2025%2018%2022.5%2024.6v2.1-2.1C20%2018%209.9%2014%207%2019.9c-2.5%205.6%204.8%209%204.8%209'/%3e%3cpath%20stroke='%23ececec'%20d='M11.5%2030c5.5-3%2015.5-3%2021%200m-21%203.5c5.5-3%2015.5-3%2021%200m-21%203.5c5.5-3%2015.5-3%2021%200'/%3e%3c/g%3e%3c/svg%3e";
|
|
953
|
+
class Le {
|
|
954
|
+
imagesSrc = {
|
|
955
|
+
wP: pe,
|
|
956
|
+
wB: Pe,
|
|
957
|
+
wN: we,
|
|
958
|
+
wR: be,
|
|
959
|
+
wQ: Re,
|
|
960
|
+
wK: Ce,
|
|
961
|
+
bP: xe,
|
|
962
|
+
bB: Se,
|
|
963
|
+
bN: Me,
|
|
964
|
+
bR: ke,
|
|
965
|
+
bQ: Ee,
|
|
966
|
+
bK: De
|
|
967
|
+
};
|
|
968
|
+
cache = /* @__PURE__ */ new Map();
|
|
969
|
+
destroy() {
|
|
970
|
+
this.clearCache();
|
|
971
|
+
const e = this.getPieceImages?.image;
|
|
972
|
+
if (e)
|
|
973
|
+
for (const t in e) {
|
|
974
|
+
const r = e[t];
|
|
975
|
+
r instanceof HTMLImageElement && (r.src = "", r.onload = null, r.onerror = null), e[t] = null;
|
|
976
|
+
}
|
|
977
|
+
for (const t of Object.getOwnPropertyNames(this))
|
|
978
|
+
this[t] = null;
|
|
979
|
+
}
|
|
980
|
+
getPieceAt(e, t, r, n, i) {
|
|
981
|
+
const s = i;
|
|
982
|
+
if (!s) return;
|
|
983
|
+
const a = b.coordsToSquare(e, t, r, n);
|
|
984
|
+
if (!a) return;
|
|
985
|
+
const o = this.cache.get(a.notation);
|
|
986
|
+
if (o) return { piece: { ...o.piece }, id: o.id };
|
|
987
|
+
const c = Object.entries(s).find(([y, f]) => f.square?.notation === a.notation);
|
|
988
|
+
if (!c) return;
|
|
989
|
+
const [u, h] = c;
|
|
990
|
+
return this.cache.set(a.notation, {
|
|
991
|
+
piece: h,
|
|
992
|
+
id: u
|
|
993
|
+
}), { id: u, piece: h };
|
|
994
|
+
}
|
|
995
|
+
clearCache() {
|
|
996
|
+
return this.cache.clear();
|
|
997
|
+
}
|
|
998
|
+
updateCache(e, t, r) {
|
|
999
|
+
this.cache.delete(e), this.cache.set(t, r);
|
|
1000
|
+
}
|
|
1001
|
+
removeCache(e) {
|
|
1002
|
+
this.cache.delete(e);
|
|
1003
|
+
}
|
|
1004
|
+
getPieceImages = {
|
|
1005
|
+
string: {
|
|
1006
|
+
wK: "♔",
|
|
1007
|
+
wQ: "♕",
|
|
1008
|
+
wR: "♖",
|
|
1009
|
+
wB: "♗",
|
|
1010
|
+
wN: "♘",
|
|
1011
|
+
wP: "♙",
|
|
1012
|
+
bK: "♔",
|
|
1013
|
+
bQ: "♕",
|
|
1014
|
+
bR: "♖",
|
|
1015
|
+
bB: "♗",
|
|
1016
|
+
bN: "♘",
|
|
1017
|
+
bP: "♙"
|
|
1018
|
+
},
|
|
1019
|
+
image: (() => {
|
|
1020
|
+
const e = (t) => {
|
|
1021
|
+
const r = new URL(t, import.meta.url).href, n = new Image();
|
|
1022
|
+
return n.src = r, n;
|
|
1023
|
+
};
|
|
1024
|
+
return {
|
|
1025
|
+
wP: e(this.imagesSrc.wP),
|
|
1026
|
+
wB: e(this.imagesSrc.wB),
|
|
1027
|
+
wR: e(this.imagesSrc.wR),
|
|
1028
|
+
wN: e(this.imagesSrc.wN),
|
|
1029
|
+
wQ: e(this.imagesSrc.wQ),
|
|
1030
|
+
wK: e(this.imagesSrc.wK),
|
|
1031
|
+
bP: e(this.imagesSrc.bP),
|
|
1032
|
+
bB: e(this.imagesSrc.bB),
|
|
1033
|
+
bR: e(this.imagesSrc.bR),
|
|
1034
|
+
bN: e(this.imagesSrc.bN),
|
|
1035
|
+
bQ: e(this.imagesSrc.bQ),
|
|
1036
|
+
bK: e(this.imagesSrc.bK)
|
|
1037
|
+
};
|
|
1038
|
+
})()
|
|
1039
|
+
};
|
|
1040
|
+
async preloadImages(e) {
|
|
1041
|
+
const t = Object.values(e).map((r) => new Promise((n) => {
|
|
1042
|
+
r instanceof HTMLImageElement ? r.complete && r.naturalWidth > 0 ? n() : (r.onload = () => n(), r.onerror = () => n()) : n();
|
|
1043
|
+
}));
|
|
1044
|
+
await Promise.all(t);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
class Ae {
|
|
1048
|
+
constructor(e) {
|
|
1049
|
+
this.boardRuntime = e;
|
|
1050
|
+
}
|
|
1051
|
+
triggerUp = !0;
|
|
1052
|
+
pointerSession = 0;
|
|
1053
|
+
activeSession = null;
|
|
1054
|
+
destroy() {
|
|
1055
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
1056
|
+
this[e] = null;
|
|
1057
|
+
}
|
|
1058
|
+
detectMove(e) {
|
|
1059
|
+
const { offsetX: t, offsetY: r } = b.getCanvasCoords(e), n = this.boardRuntime.getSelected(), i = this.boardRuntime.getSize() / 8, s = this.boardRuntime.getIsBlackView(), a = n && this.boardRuntime.getInternalRefVal(n.id);
|
|
1060
|
+
this.boardRuntime.renderer.pipelineRender.setNextEvent("onPointerHover", [
|
|
1061
|
+
null
|
|
1062
|
+
]);
|
|
1063
|
+
const o = b.coordsToSquare(
|
|
1064
|
+
t,
|
|
1065
|
+
r,
|
|
1066
|
+
i,
|
|
1067
|
+
s
|
|
1068
|
+
);
|
|
1069
|
+
if (n && o?.notation === n.square?.notation)
|
|
1070
|
+
return { from: null, to: null, piece: null };
|
|
1071
|
+
if (!n || !o || !a)
|
|
1072
|
+
return { from: null, to: null, piece: null };
|
|
1073
|
+
const c = n.square ? this.boardRuntime.getBoard()[n.square.notation] : null;
|
|
1074
|
+
return c ? { from: n.square, to: o, piece: c } : { from: null, to: null, piece: null };
|
|
1075
|
+
}
|
|
1076
|
+
handlePieceHover(e) {
|
|
1077
|
+
const { offsetX: t, offsetY: r } = b.getCanvasCoords(e), n = this.boardRuntime.getSelected(), i = this.boardRuntime.getSize() / 8;
|
|
1078
|
+
if (n && n?.isDragging || this.boardRuntime.getIsMoving() || e.pressure > 0)
|
|
1079
|
+
return;
|
|
1080
|
+
const s = this.boardRuntime.helpers.pieceHelper.getPieceAt(
|
|
1081
|
+
t,
|
|
1082
|
+
r,
|
|
1083
|
+
i,
|
|
1084
|
+
this.boardRuntime.getIsBlackView(),
|
|
1085
|
+
this.boardRuntime.getInternalRefObj()
|
|
1086
|
+
);
|
|
1087
|
+
if (s && this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1088
|
+
cursor: "grab"
|
|
1089
|
+
}), n && s?.id === n?.id) {
|
|
1090
|
+
this.boardRuntime.getPieceHover() !== null && this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1091
|
+
"onPointerHover",
|
|
1092
|
+
[null]
|
|
1093
|
+
);
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
if (!s) {
|
|
1097
|
+
this.boardRuntime.getPieceHover() && this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1098
|
+
"onPointerHover",
|
|
1099
|
+
[null]
|
|
1100
|
+
), this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1101
|
+
cursor: "default"
|
|
1102
|
+
});
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
this.boardRuntime.renderer.pipelineRender.setNextEvent("onPointerHover", [
|
|
1106
|
+
s.id
|
|
1107
|
+
]);
|
|
1108
|
+
}
|
|
1109
|
+
handleGrab(e) {
|
|
1110
|
+
const { offsetX: t, offsetY: r } = b.getCanvasCoords(e), n = this.boardRuntime.getSize() / 8, i = this.boardRuntime.getSelected(), s = this.activeSession;
|
|
1111
|
+
if (s === null || s !== this.pointerSession || i === null || i.startX === null || i?.startY === null || e.pressure <= 0 || this.boardRuntime.getIsMoving())
|
|
1112
|
+
return;
|
|
1113
|
+
const a = t - i.startX, o = r - i.startY;
|
|
1114
|
+
if (Math.sqrt(a * a + o * o) > 3 && i.id) {
|
|
1115
|
+
const c = this.boardRuntime.getInternalRefVal(i.id), u = n / 2;
|
|
1116
|
+
if (c && !i.isDragging) {
|
|
1117
|
+
i.isDragging = !0, c.x = t - u, c.y = r - u, this.boardRuntime.renderer.getLayerManager().addDraw("onPointerDragStart"), this.boardRuntime.getPieceHover() && this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1118
|
+
"onPointerHover",
|
|
1119
|
+
[null]
|
|
1120
|
+
), this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1121
|
+
"onToggleCanvas",
|
|
1122
|
+
["staticPieces", "dynamicPieces", i.id]
|
|
1123
|
+
);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const h = t - u, y = r - u;
|
|
1127
|
+
c.x = Math.max(
|
|
1128
|
+
0,
|
|
1129
|
+
Math.min(h, this.boardRuntime.getSize() - n)
|
|
1130
|
+
), c.y = Math.max(
|
|
1131
|
+
0,
|
|
1132
|
+
Math.min(y, this.boardRuntime.getSize() - n)
|
|
1133
|
+
), this.boardRuntime.renderer.getLayerManager().addDraw("onPointerDrag"), this.boardRuntime.renderer.pipelineRender.setNextEvent("onRender", [
|
|
1134
|
+
{
|
|
1135
|
+
board: !1,
|
|
1136
|
+
staticPieces: !0,
|
|
1137
|
+
overlay: !0,
|
|
1138
|
+
underlay: !0,
|
|
1139
|
+
dynamicPieces: !0
|
|
1140
|
+
}
|
|
1141
|
+
]);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
handlePointerUp(e) {
|
|
1145
|
+
if (++this.pointerSession, this.activeSession = null, this.boardRuntime.getIsMoving()) return;
|
|
1146
|
+
const { offsetX: t, offsetY: r } = b.getCanvasCoords(e), n = this.boardRuntime.getSize(), i = this.boardRuntime.getSelected();
|
|
1147
|
+
if (t < 0 || r < 0 || t >= n || r >= n) {
|
|
1148
|
+
this.handlePointerLeave(e);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1152
|
+
cursor: "default"
|
|
1153
|
+
}), this.boardRuntime.renderer.pipelineRender.setNextEvent("onPointerHover", [
|
|
1154
|
+
null,
|
|
1155
|
+
!0
|
|
1156
|
+
]);
|
|
1157
|
+
const s = i?.isDragging;
|
|
1158
|
+
if (this.triggerUp) {
|
|
1159
|
+
const { from: a, to: o, piece: c } = this.boardRuntime.helpers.pointerEventsHelper.detectMove(e);
|
|
1160
|
+
if (a !== null && a.notation !== o.notation) {
|
|
1161
|
+
this.boardRuntime.helpers.setNextMove({
|
|
1162
|
+
from: a.notation,
|
|
1163
|
+
to: o.notation,
|
|
1164
|
+
piece: c,
|
|
1165
|
+
click: !1,
|
|
1166
|
+
offset: { x: t, y: r }
|
|
1167
|
+
});
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
} else this.triggerUp = !0;
|
|
1171
|
+
s && this.endDrag(t, r, !1, !0), i?.secondClick || s ? this.boardRuntime.helpers.toggleSelected(!1) : this.boardRuntime.helpers.toggleSelected(!0), this.boardRuntime.renderer.pipelineRender.setNextEvent("onRender", [
|
|
1172
|
+
{
|
|
1173
|
+
board: !1,
|
|
1174
|
+
staticPieces: !0,
|
|
1175
|
+
overlay: !0,
|
|
1176
|
+
underlay: !0,
|
|
1177
|
+
dynamicPieces: !0
|
|
1178
|
+
}
|
|
1179
|
+
]);
|
|
1180
|
+
}
|
|
1181
|
+
handlePointerLeave(e) {
|
|
1182
|
+
const t = this.boardRuntime.getSelected(), r = !(t && t.secondClick);
|
|
1183
|
+
this.endDrag(-1, -1, !1, !0), this.boardRuntime.helpers.toggleSelected(r), this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1184
|
+
cursor: "default"
|
|
1185
|
+
}), this.boardRuntime.renderer.pipelineRender.setNextEvent("onPointerHover", [
|
|
1186
|
+
null,
|
|
1187
|
+
!0
|
|
1188
|
+
]), this.boardRuntime.renderer.pipelineRender.setNextEvent("onRender", [
|
|
1189
|
+
{
|
|
1190
|
+
board: !1,
|
|
1191
|
+
staticPieces: !0,
|
|
1192
|
+
overlay: !0,
|
|
1193
|
+
underlay: !0,
|
|
1194
|
+
dynamicPieces: !0
|
|
1195
|
+
}
|
|
1196
|
+
]);
|
|
1197
|
+
}
|
|
1198
|
+
startPress(e) {
|
|
1199
|
+
const { offsetX: t, offsetY: r } = b.getCanvasCoords(e), n = this.boardRuntime.getSize() / 8, i = this.boardRuntime.getSelected();
|
|
1200
|
+
if (t === null || r === null) return;
|
|
1201
|
+
this.activeSession = this.pointerSession;
|
|
1202
|
+
const s = b.coordsToSquare(
|
|
1203
|
+
t,
|
|
1204
|
+
r,
|
|
1205
|
+
n,
|
|
1206
|
+
this.boardRuntime.getIsBlackView()
|
|
1207
|
+
);
|
|
1208
|
+
if (!s || i?.isDragging) return;
|
|
1209
|
+
const a = this.boardRuntime.helpers.pieceHelper.getPieceAt(
|
|
1210
|
+
t,
|
|
1211
|
+
r,
|
|
1212
|
+
n,
|
|
1213
|
+
this.boardRuntime.getIsBlackView(),
|
|
1214
|
+
this.boardRuntime.getInternalRefObj()
|
|
1215
|
+
);
|
|
1216
|
+
a ? i ? s.notation !== i.square?.notation ? (this.triggerUp = !1, this.moveOnClick(e, i, { x: t, y: r })) : (i.startX = t, i.startY = r, i.secondClick = !0) : this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1217
|
+
"onPointerSelect",
|
|
1218
|
+
[
|
|
1219
|
+
{
|
|
1220
|
+
id: a.id,
|
|
1221
|
+
x: a.piece.x,
|
|
1222
|
+
y: a.piece.y,
|
|
1223
|
+
square: a.piece.square,
|
|
1224
|
+
isDragging: !1,
|
|
1225
|
+
isPending: !1,
|
|
1226
|
+
startX: t,
|
|
1227
|
+
startY: r,
|
|
1228
|
+
secondClick: !1
|
|
1229
|
+
}
|
|
1230
|
+
]
|
|
1231
|
+
) : i && (this.triggerUp = !1, this.moveOnClick(e, i, { x: t, y: r }));
|
|
1232
|
+
}
|
|
1233
|
+
moveOnClick(e, t, r) {
|
|
1234
|
+
if (t) {
|
|
1235
|
+
const { from: n, to: i, piece: s } = this.boardRuntime.helpers.pointerEventsHelper.detectMove(e);
|
|
1236
|
+
n !== null && this.boardRuntime.helpers.setNextMove({
|
|
1237
|
+
from: n.notation,
|
|
1238
|
+
to: i.notation,
|
|
1239
|
+
piece: s,
|
|
1240
|
+
click: !0,
|
|
1241
|
+
offset: r
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
toggleLayer(e, t) {
|
|
1246
|
+
const r = this.boardRuntime.getSelected(), n = r && this.boardRuntime.getInternalRefVal(r.id);
|
|
1247
|
+
r && r.isDragging && n && (n.x = r.x, n.y = r.y, n.square = structuredClone(r.square), this.boardRuntime.renderer.pipelineRender.setNextEvent("onToggleCanvas", [
|
|
1248
|
+
e,
|
|
1249
|
+
t,
|
|
1250
|
+
r.id,
|
|
1251
|
+
!0
|
|
1252
|
+
]));
|
|
1253
|
+
}
|
|
1254
|
+
endDrag(e, t, r, n) {
|
|
1255
|
+
const i = this.boardRuntime.getSelected(), s = this.boardRuntime.getSize() / 8, a = this.boardRuntime.getIsBlackView(), o = i && this.boardRuntime.getInternalRefVal(i.id), c = b.coordsToSquare(e, t, s, a), u = b.squareToCoords(c, s, a);
|
|
1256
|
+
if (!(!i || !i.isDragging || !o)) {
|
|
1257
|
+
if (!r)
|
|
1258
|
+
o.square = structuredClone(i.square), o.x = i.x, o.y = i.y;
|
|
1259
|
+
else if (c && u) {
|
|
1260
|
+
const { x: h, y } = u;
|
|
1261
|
+
o.square = structuredClone(c), o.x = h, o.y = y;
|
|
1262
|
+
}
|
|
1263
|
+
n && this.toggleLayer("dynamicPieces", "staticPieces"), i.isDragging = !1;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
class Te {
|
|
1268
|
+
constructor(e) {
|
|
1269
|
+
this.boardRuntime = e, this.pointerEventsHelper = new Ae(this.boardRuntime);
|
|
1270
|
+
}
|
|
1271
|
+
pointerEventsHelper;
|
|
1272
|
+
pieceHelper = new Le();
|
|
1273
|
+
pipelineMove = [];
|
|
1274
|
+
moveToken = 0;
|
|
1275
|
+
isMoving = !1;
|
|
1276
|
+
destroy() {
|
|
1277
|
+
this.pieceHelper.destroy(), this.pointerEventsHelper.destroy();
|
|
1278
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
1279
|
+
this[e] = null;
|
|
1280
|
+
}
|
|
1281
|
+
createLazyEventContext(e, t, r) {
|
|
1282
|
+
const n = /* @__PURE__ */ new Map(), i = { ...e }, s = r?.cache ?? !0;
|
|
1283
|
+
for (const a of Object.keys(t))
|
|
1284
|
+
i[a] = (...o) => {
|
|
1285
|
+
if (s && n.has(a))
|
|
1286
|
+
return n.get(a);
|
|
1287
|
+
const c = t[a](...o);
|
|
1288
|
+
return s && n.set(a, c), c;
|
|
1289
|
+
};
|
|
1290
|
+
return i.toPlain = () => {
|
|
1291
|
+
const a = { ...e };
|
|
1292
|
+
for (const o of Object.keys(t))
|
|
1293
|
+
a[o] = t[o]();
|
|
1294
|
+
return a;
|
|
1295
|
+
}, i.clearCache = () => n.clear(), i.destroy = () => {
|
|
1296
|
+
n.clear();
|
|
1297
|
+
for (const a of Object.keys(i))
|
|
1298
|
+
delete i[a];
|
|
1299
|
+
}, i;
|
|
1300
|
+
}
|
|
1301
|
+
triggerEvent(e, t, r, n) {
|
|
1302
|
+
let i = null;
|
|
1303
|
+
try {
|
|
1304
|
+
const s = e?.[t];
|
|
1305
|
+
if (!s) return;
|
|
1306
|
+
r.__event = t, n !== void 0 ? i = s(
|
|
1307
|
+
r,
|
|
1308
|
+
n
|
|
1309
|
+
) : i = s(r);
|
|
1310
|
+
} finally {
|
|
1311
|
+
"destroy" in r && typeof r.destroy == "function" && r.destroy();
|
|
1312
|
+
}
|
|
1313
|
+
return i;
|
|
1314
|
+
}
|
|
1315
|
+
async movePromiseCancel() {
|
|
1316
|
+
return new Promise((e) => {
|
|
1317
|
+
setTimeout(() => {
|
|
1318
|
+
e();
|
|
1319
|
+
}, 8e3);
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
async move(e, t, r, n, i) {
|
|
1323
|
+
if (e === t) return !1;
|
|
1324
|
+
const s = this.boardRuntime.getSelected(), a = s?.id, o = this.boardRuntime.getMove();
|
|
1325
|
+
if (o) {
|
|
1326
|
+
const c = await this.pendingDrag(i.x, i.y), u = await Promise.race([
|
|
1327
|
+
o({ from: e, to: t, piece: r }),
|
|
1328
|
+
this.movePromiseCancel().then(() => (this.boardRuntime.getEventEmitter().emit("onMoveAbort", []), { status: !1, result: [] }))
|
|
1329
|
+
]);
|
|
1330
|
+
if (s) {
|
|
1331
|
+
if (!n && c && u.status) {
|
|
1332
|
+
const h = this.boardRuntime.getInternalRefVal(s.id);
|
|
1333
|
+
h.square = c;
|
|
1334
|
+
}
|
|
1335
|
+
s.isPending && (this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1336
|
+
"onToggleCanvas",
|
|
1337
|
+
["dynamicPieces", "staticPieces", a, !0]
|
|
1338
|
+
), s.isPending = !1, await b.asyncHandler(
|
|
1339
|
+
(h) => this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1340
|
+
"onRender",
|
|
1341
|
+
[
|
|
1342
|
+
{
|
|
1343
|
+
board: !1,
|
|
1344
|
+
staticPieces: !0,
|
|
1345
|
+
overlay: !0,
|
|
1346
|
+
underlay: !0,
|
|
1347
|
+
dynamicPieces: !0
|
|
1348
|
+
}
|
|
1349
|
+
],
|
|
1350
|
+
h
|
|
1351
|
+
)
|
|
1352
|
+
));
|
|
1353
|
+
}
|
|
1354
|
+
return u.status ? (await this.boardRuntime.updateBoardState(u.result, n), !0) : !1;
|
|
1355
|
+
} else
|
|
1356
|
+
return this.pointerEventsHelper.endDrag(i.x, i.y, !0, !1), this.boardRuntime.renderer.pipelineRender.setNextEvent("onToggleCanvas", [
|
|
1357
|
+
"dynamicPieces",
|
|
1358
|
+
"staticPieces",
|
|
1359
|
+
a,
|
|
1360
|
+
!0
|
|
1361
|
+
]), await this.boardRuntime.updateBoardState(
|
|
1362
|
+
[{ from: e, to: t, captured: [t] }],
|
|
1363
|
+
n
|
|
1364
|
+
), !0;
|
|
1365
|
+
}
|
|
1366
|
+
toggleSelected(e) {
|
|
1367
|
+
const t = this.boardRuntime.getSelected();
|
|
1368
|
+
t && (e ? this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1369
|
+
"onPointerSelect",
|
|
1370
|
+
[
|
|
1371
|
+
{
|
|
1372
|
+
...t,
|
|
1373
|
+
isDragging: !1,
|
|
1374
|
+
startX: null,
|
|
1375
|
+
startY: null,
|
|
1376
|
+
secondClick: !1
|
|
1377
|
+
},
|
|
1378
|
+
!0
|
|
1379
|
+
]
|
|
1380
|
+
) : this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1381
|
+
"onPointerSelect",
|
|
1382
|
+
[null, !0]
|
|
1383
|
+
));
|
|
1384
|
+
}
|
|
1385
|
+
setNextMove(e) {
|
|
1386
|
+
const t = ++this.moveToken;
|
|
1387
|
+
this.pipelineMove.push({ ...e, token: t }), this.isMoving || this.handleMove();
|
|
1388
|
+
}
|
|
1389
|
+
async pendingDrag(e, t) {
|
|
1390
|
+
const r = this.boardRuntime.getSelected();
|
|
1391
|
+
this.boardRuntime.renderer.getLayerManager().removeEvent("onPointerSelect");
|
|
1392
|
+
const n = (h) => this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1393
|
+
"onRender",
|
|
1394
|
+
[
|
|
1395
|
+
{
|
|
1396
|
+
board: !1,
|
|
1397
|
+
staticPieces: !0,
|
|
1398
|
+
overlay: !0,
|
|
1399
|
+
underlay: !0,
|
|
1400
|
+
dynamicPieces: !0
|
|
1401
|
+
}
|
|
1402
|
+
],
|
|
1403
|
+
h
|
|
1404
|
+
);
|
|
1405
|
+
if (!r || !r.isDragging) {
|
|
1406
|
+
await b.asyncHandler(n);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
const i = this.boardRuntime.getSize() / 8, s = this.boardRuntime.getIsBlackView(), a = b.coordsToSquare(e, t, i, s), o = this.boardRuntime.renderer.getLayerManager().getLayer("dynamicPieces");
|
|
1410
|
+
if (!a) return;
|
|
1411
|
+
const c = b.squareToCoords(a, i, s);
|
|
1412
|
+
r.isPending = !0;
|
|
1413
|
+
const u = o.getPiece(r.id);
|
|
1414
|
+
return u && (u.x = c ? c.x : e, u.y = c ? c.y : t), r.x = c ? c.x : e, r.y = c ? c.y : t, r.square = a, r.startX = null, r.startY = null, r.isDragging = !1, o.addToRender(r.id), await b.asyncHandler(n), o.removeToRender(r.id), a;
|
|
1415
|
+
}
|
|
1416
|
+
async handleMove() {
|
|
1417
|
+
if (!this.isMoving) {
|
|
1418
|
+
this.isMoving = !0, this.boardRuntime.setIsMoving(!0);
|
|
1419
|
+
try {
|
|
1420
|
+
for (; this.pipelineMove.length; ) {
|
|
1421
|
+
const e = this.boardRuntime.getSelected(), t = this.pipelineMove.shift();
|
|
1422
|
+
if (!t) continue;
|
|
1423
|
+
const { from: r, to: n, piece: i, click: s, offset: a, token: o } = t;
|
|
1424
|
+
if (o !== this.moveToken) continue;
|
|
1425
|
+
let c = !1;
|
|
1426
|
+
const u = e?.x, h = e?.y, y = e && e.square !== null ? { ...e.square } : null;
|
|
1427
|
+
this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1428
|
+
cursor: "progress"
|
|
1429
|
+
}), c = await this.move(r, n, i, s, a), this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
1430
|
+
cursor: "default"
|
|
1431
|
+
}), c && this.boardRuntime.clearRedo();
|
|
1432
|
+
const f = this.boardRuntime.getBoard()[n], g = f ? this.boardRuntime.getInternalRefVal(f.id) : null, P = f ? b.squareToCoords(
|
|
1433
|
+
f.square,
|
|
1434
|
+
this.boardRuntime.getSize() / 8,
|
|
1435
|
+
this.boardRuntime.getIsBlackView()
|
|
1436
|
+
) : null;
|
|
1437
|
+
if (s && (c || (f && g ? P && this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1438
|
+
"onPointerSelect",
|
|
1439
|
+
[
|
|
1440
|
+
{
|
|
1441
|
+
id: f.id,
|
|
1442
|
+
x: P.x,
|
|
1443
|
+
y: P.y,
|
|
1444
|
+
square: g.square,
|
|
1445
|
+
isDragging: !1,
|
|
1446
|
+
startX: a.x,
|
|
1447
|
+
startY: a.y,
|
|
1448
|
+
secondClick: !1
|
|
1449
|
+
},
|
|
1450
|
+
!0
|
|
1451
|
+
]
|
|
1452
|
+
) : this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1453
|
+
"onPointerSelect",
|
|
1454
|
+
[null, !0]
|
|
1455
|
+
))), !c) {
|
|
1456
|
+
if (!s) {
|
|
1457
|
+
if (e && u !== void 0 && h !== void 0) {
|
|
1458
|
+
const v = this.boardRuntime.getInternalRefVal(e.id);
|
|
1459
|
+
v.x = u, v.y = h, v.square = structuredClone(y);
|
|
1460
|
+
}
|
|
1461
|
+
this.boardRuntime.renderer.pipelineRender.setNextEvent(
|
|
1462
|
+
"onPointerSelect",
|
|
1463
|
+
[null, !0]
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
this.boardRuntime.renderer.pipelineRender.setNextEvent("onRender", [
|
|
1467
|
+
{
|
|
1468
|
+
board: !1,
|
|
1469
|
+
staticPieces: !0,
|
|
1470
|
+
overlay: !0,
|
|
1471
|
+
underlay: !0,
|
|
1472
|
+
dynamicPieces: !0
|
|
1473
|
+
}
|
|
1474
|
+
]);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
} finally {
|
|
1478
|
+
this.isMoving = !1, this.boardRuntime.setIsMoving(!1), this.pipelineMove.length && queueMicrotask(() => this.handleMove());
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
class N {
|
|
1484
|
+
capacity = 4;
|
|
1485
|
+
boundary;
|
|
1486
|
+
objects = [];
|
|
1487
|
+
child = {
|
|
1488
|
+
NE: null,
|
|
1489
|
+
NW: null,
|
|
1490
|
+
SE: null,
|
|
1491
|
+
SW: null
|
|
1492
|
+
};
|
|
1493
|
+
destroyed = !1;
|
|
1494
|
+
constructor(e) {
|
|
1495
|
+
this.boundary = e;
|
|
1496
|
+
}
|
|
1497
|
+
destroy() {
|
|
1498
|
+
this.destroyed || (this.destroyed = !0, this.objects = [], this.child.NE?.destroy(), this.child.NW?.destroy(), this.child.SE?.destroy(), this.child.SW?.destroy(), this.child = { NE: null, NW: null, SE: null, SW: null }, this.boundary = { x: 0, y: 0, w: 0, h: 0 });
|
|
1499
|
+
}
|
|
1500
|
+
insert(e) {
|
|
1501
|
+
if (this.destroyed || !this.intersect(e.box, this.boundary)) return !1;
|
|
1502
|
+
if (this.boundary.w <= 1 || this.boundary.h <= 1)
|
|
1503
|
+
return this.objects.push(e), !0;
|
|
1504
|
+
if (this.objects.length < this.capacity && this.child.NE === null)
|
|
1505
|
+
return this.objects.push(e), !0;
|
|
1506
|
+
this.child.NE === null && this.subdivide();
|
|
1507
|
+
const t = [];
|
|
1508
|
+
for (const r of this.objects) this.insertChild(r) || t.push(r);
|
|
1509
|
+
return this.objects = t, this.insertChild(e) || this.objects.push(e), !0;
|
|
1510
|
+
}
|
|
1511
|
+
intersect(e, t) {
|
|
1512
|
+
if (!this.destroyed)
|
|
1513
|
+
return e.x < t.x + t.w && e.x + e.w > t.x && e.y < t.y + t.h && e.y + e.h > t.y;
|
|
1514
|
+
}
|
|
1515
|
+
contains(e, t) {
|
|
1516
|
+
if (!this.destroyed)
|
|
1517
|
+
return e.x >= t.x && e.x + e.w <= t.x + t.w && e.y >= t.y && e.y + e.h <= t.y + t.h;
|
|
1518
|
+
}
|
|
1519
|
+
insertChild(e) {
|
|
1520
|
+
if (this.destroyed) return !1;
|
|
1521
|
+
let t = null;
|
|
1522
|
+
for (const r of Object.values(this.child))
|
|
1523
|
+
if (!(!r || !r.contains(e.box, r.boundary)))
|
|
1524
|
+
if (!t) t = r;
|
|
1525
|
+
else return !1;
|
|
1526
|
+
return t === null ? !1 : t.insert(e);
|
|
1527
|
+
}
|
|
1528
|
+
subdivide() {
|
|
1529
|
+
if (this.destroyed) return;
|
|
1530
|
+
const e = this.boundary.w / 2, t = this.boundary.h / 2;
|
|
1531
|
+
this.child.NW = new N({
|
|
1532
|
+
x: this.boundary.x,
|
|
1533
|
+
y: this.boundary.y,
|
|
1534
|
+
w: e,
|
|
1535
|
+
h: t
|
|
1536
|
+
}), this.child.NE = new N({
|
|
1537
|
+
x: this.boundary.x + e,
|
|
1538
|
+
y: this.boundary.y,
|
|
1539
|
+
w: e,
|
|
1540
|
+
h: t
|
|
1541
|
+
}), this.child.SW = new N({
|
|
1542
|
+
x: this.boundary.x,
|
|
1543
|
+
y: this.boundary.y + t,
|
|
1544
|
+
w: e,
|
|
1545
|
+
h: t
|
|
1546
|
+
}), this.child.SE = new N({
|
|
1547
|
+
x: this.boundary.x + e,
|
|
1548
|
+
y: this.boundary.y + t,
|
|
1549
|
+
w: e,
|
|
1550
|
+
h: t
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
search(e, t = []) {
|
|
1554
|
+
if (this.destroyed || !this.intersect(e, this.boundary)) return t;
|
|
1555
|
+
for (const r of this.objects)
|
|
1556
|
+
this.intersect(r.box, e) && t.push(r);
|
|
1557
|
+
if (!this.child.NE) return t;
|
|
1558
|
+
for (const r of Object.values(this.child))
|
|
1559
|
+
r && this.intersect(e, r.boundary) && r.search(e, t);
|
|
1560
|
+
return t;
|
|
1561
|
+
}
|
|
1562
|
+
searchById(e) {
|
|
1563
|
+
if (this.destroyed) return null;
|
|
1564
|
+
for (const t of this.objects)
|
|
1565
|
+
if (t.id === e) return t;
|
|
1566
|
+
if (!this.child.NE) return null;
|
|
1567
|
+
for (const t of Object.values(this.child)) {
|
|
1568
|
+
if (!t) continue;
|
|
1569
|
+
const r = t.searchById(e);
|
|
1570
|
+
if (r) return r;
|
|
1571
|
+
}
|
|
1572
|
+
return null;
|
|
1573
|
+
}
|
|
1574
|
+
remove(e, t) {
|
|
1575
|
+
if (this.destroyed) return !1;
|
|
1576
|
+
let r = -1;
|
|
1577
|
+
if (t) {
|
|
1578
|
+
const { P1: n, P2: i, P3: s, P4: a } = b.getHashingNumbers(), o = n * t.x ^ i * t.y ^ s * t.w ^ a * t.h;
|
|
1579
|
+
r = this.objects.findIndex((c) => c.id === e && c.hash === o);
|
|
1580
|
+
}
|
|
1581
|
+
if (r === -1 && (r = this.objects.findIndex((n) => n.id === e)), r !== -1)
|
|
1582
|
+
return this.objects.splice(r, 1), !0;
|
|
1583
|
+
if (this.child.NE === null) return !1;
|
|
1584
|
+
for (const n of Object.values(this.child))
|
|
1585
|
+
if (n && (t ? n.remove(e, t) : n.remove(e)))
|
|
1586
|
+
return this.tryMerge(), !0;
|
|
1587
|
+
return !1;
|
|
1588
|
+
}
|
|
1589
|
+
update(e, t) {
|
|
1590
|
+
const r = this.searchById(e);
|
|
1591
|
+
return r ? (this.remove(e), r.box = t, this.insert(r), !0) : !1;
|
|
1592
|
+
}
|
|
1593
|
+
tryMerge() {
|
|
1594
|
+
this.destroyed || !this.child.NE || !Object.values(this.child).every(
|
|
1595
|
+
(t) => t && t.objects.length === 0 && !t.child.NE
|
|
1596
|
+
) || (this.child = { NE: null, NW: null, SE: null, SW: null });
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
class Be {
|
|
1600
|
+
constructor(e, t) {
|
|
1601
|
+
this.id = e, this.box = t;
|
|
1602
|
+
const { P1: r, P2: n, P3: i, P4: s } = b.getHashingNumbers();
|
|
1603
|
+
this.hash = r * t.x ^ n * t.y ^ i * t.w ^ s * t.h;
|
|
1604
|
+
}
|
|
1605
|
+
hash;
|
|
1606
|
+
}
|
|
1607
|
+
class $ {
|
|
1608
|
+
name;
|
|
1609
|
+
boardRuntime;
|
|
1610
|
+
pieces = /* @__PURE__ */ new Map();
|
|
1611
|
+
coordsMap = /* @__PURE__ */ new Map();
|
|
1612
|
+
clearMap = /* @__PURE__ */ new Map();
|
|
1613
|
+
renderMap = /* @__PURE__ */ new Set();
|
|
1614
|
+
clearQueue = [];
|
|
1615
|
+
clearQueueHash = /* @__PURE__ */ new Set();
|
|
1616
|
+
eventsMap = {};
|
|
1617
|
+
pendingResolvers = /* @__PURE__ */ new Map();
|
|
1618
|
+
animationGen = 0;
|
|
1619
|
+
animationRef = null;
|
|
1620
|
+
animation = [];
|
|
1621
|
+
ctx = null;
|
|
1622
|
+
delayedPieceClear = /* @__PURE__ */ new Map();
|
|
1623
|
+
destroyed = !1;
|
|
1624
|
+
spatialIndex;
|
|
1625
|
+
constructor(e, t) {
|
|
1626
|
+
this.name = e, this.boardRuntime = t, this.ctx = t.getCanvasLayers().getContext(e);
|
|
1627
|
+
const r = this.boardRuntime.getSize();
|
|
1628
|
+
this.spatialIndex = new N({ x: 0, y: 0, w: r, h: r });
|
|
1629
|
+
}
|
|
1630
|
+
destroy() {
|
|
1631
|
+
this.clearAnimation();
|
|
1632
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
1633
|
+
this[e] = null;
|
|
1634
|
+
this.destroyed = !0;
|
|
1635
|
+
}
|
|
1636
|
+
update(e) {
|
|
1637
|
+
throw new Error("Method not implemented.");
|
|
1638
|
+
}
|
|
1639
|
+
clearPieces(e) {
|
|
1640
|
+
throw new Error("Method not implemented.");
|
|
1641
|
+
}
|
|
1642
|
+
clear() {
|
|
1643
|
+
const t = this.boardRuntime.getCanvasLayers().getDpr();
|
|
1644
|
+
for (const r of this.clearQueue)
|
|
1645
|
+
this.ctx?.save(), this.ctx?.setTransform(1, 0, 0, 1, 0, 0), this.ctx?.clearRect(r.x * t, r.y * t, r.w * t, r.h * t), this.ctx?.restore();
|
|
1646
|
+
this.resetClearQueue();
|
|
1647
|
+
}
|
|
1648
|
+
async draw() {
|
|
1649
|
+
throw new Error("Method not implemented.");
|
|
1650
|
+
}
|
|
1651
|
+
addPiece(e, t) {
|
|
1652
|
+
this.pieces.set(e, t);
|
|
1653
|
+
}
|
|
1654
|
+
removePiece(e) {
|
|
1655
|
+
this.pieces.delete(e);
|
|
1656
|
+
}
|
|
1657
|
+
addAll(e, t, r, n) {
|
|
1658
|
+
if (!(this.pieces.has(e) || !this.boardRuntime.isActivePiece(e))) {
|
|
1659
|
+
if (t.square?.notation && this.boardRuntime.getBoard()[t.square.notation]) {
|
|
1660
|
+
const i = this.boardRuntime.getBoard()[t.square.notation];
|
|
1661
|
+
i.id, this.removeAll?.(i.id);
|
|
1662
|
+
}
|
|
1663
|
+
this.addCoords(e, r), this.addPiece?.(e, t), this.addClearCoords(e, n), this.addToRender(e);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
removeAll(e) {
|
|
1667
|
+
if (!this.pieces.has(e)) return;
|
|
1668
|
+
const t = this.getClearCoords(e);
|
|
1669
|
+
t && this.addClearQueue(t), this.removePiece?.(e), this.removeToRender(e), this.removeCoords(e), this.removeClearCoords(e);
|
|
1670
|
+
}
|
|
1671
|
+
handleEvent(e, t) {
|
|
1672
|
+
this.eventsMap[e] || (this.eventsMap[e] = []), this.eventsMap[e].push(t);
|
|
1673
|
+
}
|
|
1674
|
+
addCoords(e, t) {
|
|
1675
|
+
this.spatialIndex.update(e, t) || this.spatialIndex.insert(new Be(e, t)), this.coordsMap.set(e, { ...t, id: e });
|
|
1676
|
+
}
|
|
1677
|
+
removeCoords(e) {
|
|
1678
|
+
const t = this.getCoords(e);
|
|
1679
|
+
t && (this.spatialIndex.remove(e, t), this.coordsMap.delete(e));
|
|
1680
|
+
}
|
|
1681
|
+
addClearCoords(e, t) {
|
|
1682
|
+
this.clearMap.set(e, { ...t, id: e });
|
|
1683
|
+
}
|
|
1684
|
+
removeClearCoords(e) {
|
|
1685
|
+
this.clearMap.delete(e);
|
|
1686
|
+
}
|
|
1687
|
+
addToRender(e) {
|
|
1688
|
+
this.renderMap.add(e);
|
|
1689
|
+
}
|
|
1690
|
+
removeToRender(e) {
|
|
1691
|
+
this.renderMap.delete(e);
|
|
1692
|
+
}
|
|
1693
|
+
addClearQueue(e) {
|
|
1694
|
+
const { P1: t, P2: r, P3: n, P4: i } = b.getHashingNumbers(), s = t * e.x ^ r * e.y ^ n * e.w ^ i * e.h;
|
|
1695
|
+
this.clearQueueHash.has(s) || (this.clearQueueHash.add(s), this.clearQueue.push(e));
|
|
1696
|
+
}
|
|
1697
|
+
resetClearQueue() {
|
|
1698
|
+
this.clearQueue = [], this.clearQueueHash.clear();
|
|
1699
|
+
}
|
|
1700
|
+
addEvent(e, t) {
|
|
1701
|
+
this.eventsMap[e] || (this.eventsMap[e] = []), t = Array.isArray(t) ? t : [t], this.eventsMap[e].push(...t);
|
|
1702
|
+
}
|
|
1703
|
+
removeEvent(e) {
|
|
1704
|
+
const t = this.eventsMap[e];
|
|
1705
|
+
if (!t) return;
|
|
1706
|
+
const r = [];
|
|
1707
|
+
for (const i of t)
|
|
1708
|
+
this.addClearQueue(i), r.push(i);
|
|
1709
|
+
delete this.eventsMap[e];
|
|
1710
|
+
const n = this.boardRuntime.renderer.getLayerManager();
|
|
1711
|
+
for (const [i, s] of Object.entries(this.eventsMap))
|
|
1712
|
+
for (const a of s)
|
|
1713
|
+
for (const o of r)
|
|
1714
|
+
if (this.intersects(a, o)) {
|
|
1715
|
+
n.addDraw(i), n.removeEvent(i);
|
|
1716
|
+
break;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
intersects(e, t) {
|
|
1720
|
+
return !(e.x + e.w <= t.x || t.x + t.w <= e.x || e.y + e.h <= t.y || t.y + t.h <= e.y);
|
|
1721
|
+
}
|
|
1722
|
+
pieceIntersects(e, t) {
|
|
1723
|
+
const r = Math.max(e.x, t.x), n = Math.min(e.x + e.w, t.x + t.w), i = Math.max(e.y, t.y), s = Math.min(e.y + e.h, t.y + t.h), a = n - r, o = s - i;
|
|
1724
|
+
return a <= 0 || o <= 0 ? !1 : a >= 2 && o >= 2;
|
|
1725
|
+
}
|
|
1726
|
+
getCtx() {
|
|
1727
|
+
return this.ctx;
|
|
1728
|
+
}
|
|
1729
|
+
hasPiece(e) {
|
|
1730
|
+
return this.pieces.has(e);
|
|
1731
|
+
}
|
|
1732
|
+
getPiece(e) {
|
|
1733
|
+
return this.pieces.get(e);
|
|
1734
|
+
}
|
|
1735
|
+
getCoords(e) {
|
|
1736
|
+
return this.coordsMap.get(e);
|
|
1737
|
+
}
|
|
1738
|
+
getClearCoords(e) {
|
|
1739
|
+
return this.clearMap.get(e);
|
|
1740
|
+
}
|
|
1741
|
+
getToRender() {
|
|
1742
|
+
return Array.from(this.renderMap.keys());
|
|
1743
|
+
}
|
|
1744
|
+
hasToRender(e) {
|
|
1745
|
+
return this.renderMap.has(e);
|
|
1746
|
+
}
|
|
1747
|
+
clearRenderMap() {
|
|
1748
|
+
this.renderMap.clear();
|
|
1749
|
+
}
|
|
1750
|
+
resetLayer() {
|
|
1751
|
+
const e = this.boardRuntime.getSize();
|
|
1752
|
+
this.pieces.clear(), this.coordsMap.clear(), this.renderMap.clear(), this.clearMap.clear(), this.spatialIndex.destroy(), this.spatialIndex = new N({
|
|
1753
|
+
x: 0,
|
|
1754
|
+
y: 0,
|
|
1755
|
+
w: e,
|
|
1756
|
+
h: e
|
|
1757
|
+
}), this.clearQueue.length = 0, this.eventsMap = {};
|
|
1758
|
+
}
|
|
1759
|
+
redrawPieces() {
|
|
1760
|
+
for (const e of this.pieces.keys()) this.addToRender(e);
|
|
1761
|
+
}
|
|
1762
|
+
updateClear() {
|
|
1763
|
+
}
|
|
1764
|
+
postRender() {
|
|
1765
|
+
}
|
|
1766
|
+
setAnimationRef(e) {
|
|
1767
|
+
this.animationRef = e;
|
|
1768
|
+
}
|
|
1769
|
+
clearAnimation() {
|
|
1770
|
+
if (this.animationRef && (cancelAnimationFrame(this.animationRef), this.setAnimationRef(null)), this.incrementAnimationGen(), this.pendingResolvers.size > 0) {
|
|
1771
|
+
for (const [, e] of this.pendingResolvers)
|
|
1772
|
+
try {
|
|
1773
|
+
e();
|
|
1774
|
+
} catch {
|
|
1775
|
+
}
|
|
1776
|
+
this.pendingResolvers.clear();
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
setPendingResolvers(e, t) {
|
|
1780
|
+
this.pendingResolvers.set(e, t);
|
|
1781
|
+
}
|
|
1782
|
+
getPendingResolvers() {
|
|
1783
|
+
return this.pendingResolvers;
|
|
1784
|
+
}
|
|
1785
|
+
getAnimationGen() {
|
|
1786
|
+
return this.animationGen;
|
|
1787
|
+
}
|
|
1788
|
+
setResolverGen(e) {
|
|
1789
|
+
this.animationGen = e;
|
|
1790
|
+
}
|
|
1791
|
+
incrementAnimationGen() {
|
|
1792
|
+
this.animationGen++;
|
|
1793
|
+
}
|
|
1794
|
+
getAnimation() {
|
|
1795
|
+
return this.animation;
|
|
1796
|
+
}
|
|
1797
|
+
getAnimationRef() {
|
|
1798
|
+
return this.animationRef;
|
|
1799
|
+
}
|
|
1800
|
+
addAnimation(e) {
|
|
1801
|
+
this.animation.push(e);
|
|
1802
|
+
}
|
|
1803
|
+
updateAnimation() {
|
|
1804
|
+
this.animation = this.animation.filter((e) => e.piece.anim), this.animation.length <= 0 && this.boardRuntime.setIsMoving(!1);
|
|
1805
|
+
}
|
|
1806
|
+
getEvents(e) {
|
|
1807
|
+
return e ? this.eventsMap[e] : this.eventsMap;
|
|
1808
|
+
}
|
|
1809
|
+
drawEvent(e, t) {
|
|
1810
|
+
this.ctx && (e(this.ctx), this.boardRuntime.renderer.getLayerManager().applyDrawResult(this.ctx, this.name, t));
|
|
1811
|
+
}
|
|
1812
|
+
async render(e) {
|
|
1813
|
+
this.updateClear(), this.update?.(e), this.clear(), this.draw(), this.postRender();
|
|
1814
|
+
}
|
|
1815
|
+
async renderAsync() {
|
|
1816
|
+
await this.render(0);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
class Oe extends $ {
|
|
1820
|
+
constructor(e) {
|
|
1821
|
+
super("board", e);
|
|
1822
|
+
}
|
|
1823
|
+
update(e) {
|
|
1824
|
+
}
|
|
1825
|
+
async draw() {
|
|
1826
|
+
const e = this.ctx;
|
|
1827
|
+
if (!e) return;
|
|
1828
|
+
const t = this.boardRuntime.getSize(), r = this.boardRuntime.getIsBlackView(), n = this.boardRuntime.getLightTile(), i = this.boardRuntime.getDarkTile();
|
|
1829
|
+
e.clearRect(0, 0, t, t);
|
|
1830
|
+
const s = t / 8, a = r ? i : n, o = r ? n : i;
|
|
1831
|
+
for (let c = 0; c < 8; ++c)
|
|
1832
|
+
for (let u = 0; u < 8; ++u) {
|
|
1833
|
+
const h = (c + u) % 2 === 0, y = r ? 7 - c : c, f = r ? 7 - u : u;
|
|
1834
|
+
e.fillStyle = h ? a : o, e.fillRect(
|
|
1835
|
+
f * s,
|
|
1836
|
+
y * s,
|
|
1837
|
+
s,
|
|
1838
|
+
s
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
class Ie extends $ {
|
|
1844
|
+
constructor(e) {
|
|
1845
|
+
super("underlay", e);
|
|
1846
|
+
}
|
|
1847
|
+
update(e) {
|
|
1848
|
+
}
|
|
1849
|
+
async draw() {
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
class He extends $ {
|
|
1853
|
+
constructor(e) {
|
|
1854
|
+
super("staticPieces", e);
|
|
1855
|
+
}
|
|
1856
|
+
updateClear() {
|
|
1857
|
+
const e = /* @__PURE__ */ new Set();
|
|
1858
|
+
for (const t of this.clearQueue) {
|
|
1859
|
+
const r = this.spatialIndex.search(t);
|
|
1860
|
+
for (const n of r) {
|
|
1861
|
+
const i = n.id, { P1: s, P2: a, P3: o, P4: c } = b.getHashingNumbers(), u = s * n.box.x ^ a * n.box.y ^ o * n.box.w ^ c * n.box.h;
|
|
1862
|
+
e.has(i) || this.renderMap.has(i) || t.id === i || this.clearQueueHash.has(u) || (this.addClearQueue({ ...n.box, id: i }), this.renderMap.add(i), e.add(i), this.ctx && (this.ctx.strokeStyle = "rgba(251, 0, 0, 1)", this.ctx.lineWidth = 8), this.ctx?.strokeRect(t.x, t.y, t.w, t.h), console.log(t.id, " --- ", n.id, n.box, t));
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
update(e) {
|
|
1867
|
+
}
|
|
1868
|
+
async draw() {
|
|
1869
|
+
const e = this.getToRender(), t = this.boardRuntime.getPieceStyle(), r = this.boardRuntime.getPieceHover(), n = Math.ceil(this.boardRuntime.getSize() / 8), i = this.ctx;
|
|
1870
|
+
if (!(!t || !e || !e.length) && !(typeof t.bB != "string" && !(t.bB instanceof HTMLImageElement)) && i) {
|
|
1871
|
+
for (const s of e) {
|
|
1872
|
+
const a = this.getPiece(s);
|
|
1873
|
+
if (a) {
|
|
1874
|
+
if (i.save(), t && s !== r) {
|
|
1875
|
+
let o = t[a.type];
|
|
1876
|
+
o instanceof HTMLImageElement ? this.DrawHTMLPiece(o, i, a, n) : typeof o == "string" && this.DrawTextPiece(o, i, a, n);
|
|
1877
|
+
}
|
|
1878
|
+
i.restore(), this.boardRuntime.renderer.getLayerManager().applyDrawResult(i, "staticPieces", void 0, s);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
this.clearRenderMap();
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
clearPieces(e) {
|
|
1885
|
+
const t = Math.ceil(this.boardRuntime.getSize() / 8), r = /* @__PURE__ */ new Set();
|
|
1886
|
+
for (const n of e)
|
|
1887
|
+
this.hasPiece(n.id) && r.add(n.id);
|
|
1888
|
+
for (const [n, i] of this.pieces)
|
|
1889
|
+
if (!r.has(n) && !this.boardRuntime.renderer.getLayerManager().isDelayedPieceClear(n)) {
|
|
1890
|
+
const s = {
|
|
1891
|
+
x: i.x,
|
|
1892
|
+
y: i.y,
|
|
1893
|
+
w: t,
|
|
1894
|
+
h: t
|
|
1895
|
+
};
|
|
1896
|
+
this.addClearQueue({ ...s, id: n }), this.removeAll?.(n);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
DrawHTMLPiece(e, t, r, n) {
|
|
1900
|
+
const i = b.squareToCoords(
|
|
1901
|
+
r.square,
|
|
1902
|
+
n,
|
|
1903
|
+
this.boardRuntime.getIsBlackView()
|
|
1904
|
+
);
|
|
1905
|
+
i && e && e.complete && e.naturalWidth > 0 && t.drawImage(e, i.x, i.y, n, n);
|
|
1906
|
+
}
|
|
1907
|
+
DrawTextPiece(e, t, r, n) {
|
|
1908
|
+
const i = b.squareToCoords(
|
|
1909
|
+
r.square,
|
|
1910
|
+
n,
|
|
1911
|
+
this.boardRuntime.getIsBlackView()
|
|
1912
|
+
);
|
|
1913
|
+
if (!i) return;
|
|
1914
|
+
const s = e.length > 1 ? e[0] : e;
|
|
1915
|
+
t.fillStyle = r.type[0] === "w" ? "#ffffffff" : "#000000ff", t.font = `${n * 0.7}px monospace`;
|
|
1916
|
+
let a = n * 0.7;
|
|
1917
|
+
t.font = `${a}px monospace`;
|
|
1918
|
+
const o = t.measureText(s).width;
|
|
1919
|
+
o > n * 0.9 && (a *= n * 0.9 / o, t.font = `${a}px monospace`), t.textAlign = "center", t.textBaseline = "middle", t.fillText(s, i.x + n / 2, i.y + n / 2);
|
|
1920
|
+
}
|
|
1921
|
+
DrawPathPiece(e, t, r, n) {
|
|
1922
|
+
t.save(), t.translate(r.x + n / 2, r.y + n / 2);
|
|
1923
|
+
const i = n / 100;
|
|
1924
|
+
t.scale(i, i), t.fillStyle = r.type.startsWith("w") ? "#fff" : "#000", t.fill(e), t.restore();
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
class Ne extends $ {
|
|
1928
|
+
scale = 1.1;
|
|
1929
|
+
toggleCanvas = [];
|
|
1930
|
+
constructor(e) {
|
|
1931
|
+
super("dynamicPieces", e);
|
|
1932
|
+
}
|
|
1933
|
+
updateClear() {
|
|
1934
|
+
const e = ["onPointerDrag"];
|
|
1935
|
+
for (const t of e) this.removeEvent(t);
|
|
1936
|
+
}
|
|
1937
|
+
defaultPieceAnimation(e) {
|
|
1938
|
+
const t = this.getAnimation();
|
|
1939
|
+
for (let r = 0; r < t.length; r++) {
|
|
1940
|
+
const n = t[r], i = Math.hypot(
|
|
1941
|
+
n.to.x - n.from.x,
|
|
1942
|
+
n.to.y - n.from.y
|
|
1943
|
+
), s = Math.min(
|
|
1944
|
+
400,
|
|
1945
|
+
Math.max(
|
|
1946
|
+
150,
|
|
1947
|
+
this.boardRuntime.getAnimationDuration() + i * 0.08
|
|
1948
|
+
)
|
|
1949
|
+
), a = (y) => 1 - Math.pow(1 - y, 3), o = Math.max(
|
|
1950
|
+
0,
|
|
1951
|
+
Math.min((e - n.start) / s, 1)
|
|
1952
|
+
), c = n.piece, u = a(o), h = this.getClearCoords(n.id);
|
|
1953
|
+
h && this.addClearQueue(h), c.x = n.from.x + (n.to.x - n.from.x) * u, c.y = n.from.y + (n.to.y - n.from.y) * u, u < 1 ? (this.addPiece?.(n.id, c), this.addToRender(n.id)) : (c.anim = !1, this.toggleCanvas.push(n.id));
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
update(e) {
|
|
1957
|
+
this.boardRuntime.getDefaultAnimation() && this.defaultPieceAnimation(e);
|
|
1958
|
+
}
|
|
1959
|
+
async draw() {
|
|
1960
|
+
const e = this.boardRuntime.getPieceStyle(), t = this.getToRender(), r = this.boardRuntime.getPieceHover(), n = Math.ceil(this.boardRuntime.getSize() / 8), i = this.boardRuntime.getSelected(), s = this.ctx, a = this.boardRuntime.renderer.getLayerManager();
|
|
1961
|
+
if (!(!e || !t || !t.length) && !(typeof e.bB != "string" && !(e.bB instanceof HTMLImageElement)) && s) {
|
|
1962
|
+
for (const o of t) {
|
|
1963
|
+
const c = this.getPiece(o);
|
|
1964
|
+
if (!c || o === r && !c.anim) continue;
|
|
1965
|
+
s.save();
|
|
1966
|
+
const u = e && e[c.type];
|
|
1967
|
+
i?.isPending && i.id === o && (s.globalAlpha = 0.5), u instanceof HTMLImageElement ? this.DrawHTMLPiece(
|
|
1968
|
+
u,
|
|
1969
|
+
s,
|
|
1970
|
+
c,
|
|
1971
|
+
n,
|
|
1972
|
+
!!(i?.isPending && i.id === o)
|
|
1973
|
+
) : typeof u == "string" && this.DrawTextPiece(
|
|
1974
|
+
u,
|
|
1975
|
+
s,
|
|
1976
|
+
c,
|
|
1977
|
+
n,
|
|
1978
|
+
!!(i?.isPending && i.id === o)
|
|
1979
|
+
), s.restore(), i?.isDragging && i.id === o ? a.applyDrawResult(s, "dynamicPieces", "onPointerDrag", o) : a.applyDrawResult(s, "dynamicPieces", void 0, o);
|
|
1980
|
+
}
|
|
1981
|
+
for (const o of this.toggleCanvas)
|
|
1982
|
+
a.clearDelayedPiece(o, "staticPieces"), await this.boardRuntime.renderer.getLayerManager().togglePieceLayer("dynamicPieces", "staticPieces", o, !0);
|
|
1983
|
+
this.toggleCanvas.length > 0 && await this.boardRuntime.renderer.render({
|
|
1984
|
+
board: !1,
|
|
1985
|
+
staticPieces: !0,
|
|
1986
|
+
overlay: !0,
|
|
1987
|
+
underlay: !0,
|
|
1988
|
+
dynamicPieces: !0
|
|
1989
|
+
}), this.toggleCanvas.length = 0;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
postRender() {
|
|
1993
|
+
this.animation.length > 0 && this.updateAnimation();
|
|
1994
|
+
}
|
|
1995
|
+
DrawHTMLPiece(e, t, r, n, i) {
|
|
1996
|
+
const s = i ? r.x : r.x - n * (this.scale - 1) / 2, a = i ? r.y : r.y - n * (this.scale - 1) / 2, o = i ? n : n * this.scale;
|
|
1997
|
+
e && e.complete && e.naturalWidth > 0 && t.drawImage(e, s, a, o, o);
|
|
1998
|
+
}
|
|
1999
|
+
DrawTextPiece(e, t, r, n, i) {
|
|
2000
|
+
const s = e.length > 1 ? e[0] : e;
|
|
2001
|
+
t.save(), t.fillStyle = r.type[0] === "w" ? "#ffffffff" : "#000", t.font = i ? `${n * 0.7}px monospace` : `${n * 0.8 * this.scale}px monospace`;
|
|
2002
|
+
let a = i ? n * 0.7 : n * 0.8;
|
|
2003
|
+
t.font = `${a}px monospace`;
|
|
2004
|
+
const o = t.measureText(s).width;
|
|
2005
|
+
o > n * 0.9 && (a *= n * 0.9 / o, t.font = `${a}px monospace`), t.textAlign = "center", t.textBaseline = "middle", t.fillText(s, r.x + n / 2, r.y + n / 2), t.restore();
|
|
2006
|
+
}
|
|
2007
|
+
async renderAsync() {
|
|
2008
|
+
if (this.getAnimation().length === 0) {
|
|
2009
|
+
this.clearAnimation(), await this.render(0);
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
this.incrementAnimationGen();
|
|
2013
|
+
const t = this.getAnimationGen();
|
|
2014
|
+
return new Promise((r) => {
|
|
2015
|
+
const n = () => {
|
|
2016
|
+
this.getPendingResolvers().delete(t);
|
|
2017
|
+
try {
|
|
2018
|
+
r();
|
|
2019
|
+
} catch {
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
this.setPendingResolvers(t, n);
|
|
2023
|
+
const i = (a) => {
|
|
2024
|
+
if (t !== this.getAnimationGen()) return;
|
|
2025
|
+
if (this.getAnimation().length === 0) {
|
|
2026
|
+
n(), this.setAnimationRef(null);
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
this.render(a);
|
|
2030
|
+
const c = requestAnimationFrame(i);
|
|
2031
|
+
this.setAnimationRef(c);
|
|
2032
|
+
}, s = requestAnimationFrame(i);
|
|
2033
|
+
this.setAnimationRef(s);
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
class je extends $ {
|
|
2038
|
+
constructor(e) {
|
|
2039
|
+
super("overlay", e);
|
|
2040
|
+
}
|
|
2041
|
+
update(e) {
|
|
2042
|
+
}
|
|
2043
|
+
async draw() {
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
class _e {
|
|
2047
|
+
constructor(e) {
|
|
2048
|
+
this.boardRuntime = e;
|
|
2049
|
+
}
|
|
2050
|
+
ITERATORS = {
|
|
2051
|
+
onPointerSelect: "defaultOnSelect",
|
|
2052
|
+
onPointerHover: "defaultOnHover",
|
|
2053
|
+
onPointerDragStart: null,
|
|
2054
|
+
onPointerDrag: null,
|
|
2055
|
+
onPointerDrop: null,
|
|
2056
|
+
onAnimationFrame: null,
|
|
2057
|
+
onDrawPiece: null,
|
|
2058
|
+
onDrawBoard: null,
|
|
2059
|
+
onDrawOverlay: null,
|
|
2060
|
+
onDrawUnderlay: null
|
|
2061
|
+
};
|
|
2062
|
+
destroy() {
|
|
2063
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
2064
|
+
this[e] = null;
|
|
2065
|
+
}
|
|
2066
|
+
defaultOnSelect(e) {
|
|
2067
|
+
const { squareSize: t, x: r, y: n } = e, i = (s) => {
|
|
2068
|
+
const a = "#ffc400ff", o = "rgba(255, 196, 0, 0.75)";
|
|
2069
|
+
s.save(), s.beginPath(), s.arc(
|
|
2070
|
+
r + t / 2,
|
|
2071
|
+
n + t / 2,
|
|
2072
|
+
t * 0.35,
|
|
2073
|
+
0,
|
|
2074
|
+
Math.PI * 2
|
|
2075
|
+
), s.strokeStyle = a, s.lineWidth = 3, s.fillStyle = o, s.stroke(), s.fill(), s.restore();
|
|
2076
|
+
};
|
|
2077
|
+
this.boardRuntime.renderer.getLayerManager().getLayer("underlay").drawEvent(i, "onPointerSelect"), "clearCache" in e && typeof e.clearCache == "function" && e.clearCache();
|
|
2078
|
+
}
|
|
2079
|
+
defaultOnHover(e) {
|
|
2080
|
+
const { squareSize: t, piece: r, piecesImage: n } = e, i = this.boardRuntime.getHoverConfig();
|
|
2081
|
+
if (!r) return;
|
|
2082
|
+
const s = n?.[r.type];
|
|
2083
|
+
if (i.highlight && this.boardRuntime.getSelected()?.id !== this.boardRuntime.getPieceHover()) {
|
|
2084
|
+
const a = (o) => {
|
|
2085
|
+
o.save(), o.shadowColor = "rgba(255, 204, 0, 0.8)", o.shadowBlur = 10, o.shadowOffsetX = 0, o.shadowOffsetY = 0, o.lineWidth = 3.5, o.strokeStyle = "#ffcc00", o.lineJoin = "round", o.beginPath(), o.strokeRect(
|
|
2086
|
+
r.x + 1,
|
|
2087
|
+
r.y + 1,
|
|
2088
|
+
t - 2,
|
|
2089
|
+
t - 2
|
|
2090
|
+
), o.restore();
|
|
2091
|
+
};
|
|
2092
|
+
this.boardRuntime.renderer.getLayerManager().getLayer("overlay").drawEvent(a, "onPointerHover");
|
|
2093
|
+
}
|
|
2094
|
+
if (i.scaling && r) {
|
|
2095
|
+
const a = (o) => {
|
|
2096
|
+
o.save(), o.shadowColor = "rgba(0, 0, 0, 0.5)", o.shadowBlur = 10, o.shadowOffsetX = 5, o.shadowOffsetY = 5, s instanceof HTMLImageElement ? this.drawOnHoverHTML(
|
|
2097
|
+
s,
|
|
2098
|
+
o,
|
|
2099
|
+
r,
|
|
2100
|
+
t,
|
|
2101
|
+
i.scaleAmount
|
|
2102
|
+
) : typeof s == "string" && this.drawOnHoverText(
|
|
2103
|
+
s,
|
|
2104
|
+
o,
|
|
2105
|
+
r,
|
|
2106
|
+
t,
|
|
2107
|
+
i.scaleAmount
|
|
2108
|
+
), o.restore();
|
|
2109
|
+
};
|
|
2110
|
+
this.boardRuntime.renderer.getLayerManager().getLayer("dynamicPieces").drawEvent(a, "onPointerHover");
|
|
2111
|
+
}
|
|
2112
|
+
"clearCache" in e && typeof e.clearCache == "function" && e.clearCache();
|
|
2113
|
+
}
|
|
2114
|
+
drawOnHoverHTML(e, t, r, n, i) {
|
|
2115
|
+
const s = b.squareToCoords(
|
|
2116
|
+
r.square,
|
|
2117
|
+
n,
|
|
2118
|
+
this.boardRuntime.getIsBlackView()
|
|
2119
|
+
);
|
|
2120
|
+
s && e && e.complete && e.naturalWidth > 0 && t.drawImage(
|
|
2121
|
+
e,
|
|
2122
|
+
s.x - n * (i - 1) / 2,
|
|
2123
|
+
s.y - n * (i - 1) / 2,
|
|
2124
|
+
n * i,
|
|
2125
|
+
n * i
|
|
2126
|
+
);
|
|
2127
|
+
}
|
|
2128
|
+
drawOnHoverText(e, t, r, n, i) {
|
|
2129
|
+
const s = b.squareToCoords(
|
|
2130
|
+
r.square,
|
|
2131
|
+
n,
|
|
2132
|
+
this.boardRuntime.getIsBlackView()
|
|
2133
|
+
);
|
|
2134
|
+
if (!s) return;
|
|
2135
|
+
const a = e.length > 1 ? e[0] : e;
|
|
2136
|
+
t.save(), t.fillStyle = r.type[0] === "w" ? "#ffffffff" : "#000", t.font = `${n * 0.8 * i}px monospace`;
|
|
2137
|
+
let o = n * 0.8;
|
|
2138
|
+
t.font = `${o}px monospace`;
|
|
2139
|
+
const c = t.measureText(a).width;
|
|
2140
|
+
c > n * 0.9 && (o *= n * 0.9 / c, t.font = `${o}px monospace`), t.textAlign = "center", t.textBaseline = "middle", t.fillText(a, s.x + n / 2, s.y + n / 2), t.restore();
|
|
2141
|
+
}
|
|
2142
|
+
drawOnHoverPath() {
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
class ze {
|
|
2146
|
+
constructor(e) {
|
|
2147
|
+
this.boardRuntime = e;
|
|
2148
|
+
}
|
|
2149
|
+
eventsLayerMap = {
|
|
2150
|
+
onPointerSelect: "underlay",
|
|
2151
|
+
onPointerHover: "dynamicPieces",
|
|
2152
|
+
onPointerDragStart: "dynamicPieces",
|
|
2153
|
+
onPointerDrag: "dynamicPieces",
|
|
2154
|
+
onPointerDrop: null,
|
|
2155
|
+
onAnimationFrame: null,
|
|
2156
|
+
onDrawPiece: null,
|
|
2157
|
+
onDrawBoard: null,
|
|
2158
|
+
onDrawOverlay: null,
|
|
2159
|
+
onDrawUnderlay: null
|
|
2160
|
+
};
|
|
2161
|
+
eventsRunMap = {
|
|
2162
|
+
onPointerSelect: this.onPointerSelect.bind(this),
|
|
2163
|
+
onPointerHover: this.onPointerHover.bind(this),
|
|
2164
|
+
onPointerDragStart: this.onPointerDragStart.bind(this),
|
|
2165
|
+
onPointerDrag: this.onPointerDrag.bind(this),
|
|
2166
|
+
onPointerDrop: this.onPointerDrop.bind(this),
|
|
2167
|
+
onAnimationFrame: this.onAnimationFrame.bind(this),
|
|
2168
|
+
onDrawPiece: this.onDrawPiece.bind(this),
|
|
2169
|
+
onDrawBoard: this.onDrawBoard.bind(this),
|
|
2170
|
+
onDrawOverlay: this.onDrawOverlay.bind(this),
|
|
2171
|
+
onDrawUnderlay: this.onDrawUnderlay.bind(this)
|
|
2172
|
+
};
|
|
2173
|
+
getEventLayer(e) {
|
|
2174
|
+
return this.eventsLayerMap[e];
|
|
2175
|
+
}
|
|
2176
|
+
onPointerHover(e) {
|
|
2177
|
+
const t = this.boardRuntime.getSize(), r = this.boardRuntime.getPieceStyle(), n = this.boardRuntime.getInternalRefObj(), i = this.boardRuntime.getPieceHover(), s = this.boardRuntime.getSelected(), a = this.boardRuntime.getEvents(), o = Math.ceil(t / 8), c = this.boardRuntime.getInjection();
|
|
2178
|
+
if (i && !s?.isDragging) {
|
|
2179
|
+
const u = n[i], h = this.boardRuntime.getCanvasLayers().getCanvas("dynamicPieces").current ? this.boardRuntime.getCanvasLayers().getCanvas("dynamicPieces").current : void 0;
|
|
2180
|
+
if (u && !u.anim && (this.boardRuntime.getDefault().onPointerHover && this.boardRuntime.renderer.getLayerManager().getIterator().defaultOnHover({
|
|
2181
|
+
ctx: e,
|
|
2182
|
+
size: t,
|
|
2183
|
+
squareSize: o,
|
|
2184
|
+
x: u.x,
|
|
2185
|
+
y: u.y,
|
|
2186
|
+
canvas: h || void 0,
|
|
2187
|
+
piece: u,
|
|
2188
|
+
square: u.square,
|
|
2189
|
+
piecesImage: r
|
|
2190
|
+
}), a?.onPointerHover)) {
|
|
2191
|
+
let y = this.boardRuntime.getContext(!0, {
|
|
2192
|
+
squareSize: o,
|
|
2193
|
+
x: u.x,
|
|
2194
|
+
y: u.y,
|
|
2195
|
+
size: t,
|
|
2196
|
+
piece: u,
|
|
2197
|
+
square: u.square
|
|
2198
|
+
});
|
|
2199
|
+
y.__event = "onPointerHover", this.boardRuntime.helpers.triggerEvent(
|
|
2200
|
+
a,
|
|
2201
|
+
"onPointerHover",
|
|
2202
|
+
c ? c(y) : y
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
onPointerSelect(e) {
|
|
2208
|
+
const t = this.boardRuntime.getIsBlackView(), r = Math.ceil(this.boardRuntime.getSize()), n = this.boardRuntime.getPieceStyle(), i = this.boardRuntime.getInternalRefObj(), s = this.boardRuntime.getSelected(), a = this.boardRuntime.getEvents(), o = this.boardRuntime.getInjection(), c = r / 8;
|
|
2209
|
+
if (!s?.id || !e) return;
|
|
2210
|
+
const u = i[s.id] ? b.squareToCoords(s.square, c, t) : null;
|
|
2211
|
+
if (u) {
|
|
2212
|
+
const { x: h, y } = u, f = this.boardRuntime.helpers.pieceHelper.getPieceAt(
|
|
2213
|
+
h,
|
|
2214
|
+
y,
|
|
2215
|
+
c,
|
|
2216
|
+
t,
|
|
2217
|
+
i
|
|
2218
|
+
)?.piece;
|
|
2219
|
+
if (this.boardRuntime.getDefault().onPointerSelect && this.boardRuntime.renderer.getLayerManager().getIterator().defaultOnSelect({
|
|
2220
|
+
ctx: e,
|
|
2221
|
+
x: h,
|
|
2222
|
+
y,
|
|
2223
|
+
size: r,
|
|
2224
|
+
squareSize: c,
|
|
2225
|
+
getPiece: f,
|
|
2226
|
+
getPiecesImage: n,
|
|
2227
|
+
getSquare: s.square
|
|
2228
|
+
}), a?.onPointerSelect) {
|
|
2229
|
+
const g = this.boardRuntime.getContext(!0, {
|
|
2230
|
+
squareSize: c,
|
|
2231
|
+
x: h,
|
|
2232
|
+
y,
|
|
2233
|
+
size: r,
|
|
2234
|
+
piece: f,
|
|
2235
|
+
square: s.square
|
|
2236
|
+
});
|
|
2237
|
+
g.__event = "onPointerSelect", this.boardRuntime.helpers.triggerEvent(
|
|
2238
|
+
a,
|
|
2239
|
+
"onPointerSelect",
|
|
2240
|
+
o ? o(g) : g
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
onPointerDragStart() {
|
|
2246
|
+
const e = this.boardRuntime.getSelected();
|
|
2247
|
+
!e || !e.isDragging || this.boardRuntime.getCanvasLayers().setCanvasStyle("staticPieces", {
|
|
2248
|
+
cursor: "grabbing"
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
onPointerDrag() {
|
|
2252
|
+
const e = this.boardRuntime.getSelected(), t = Math.ceil(this.boardRuntime.getSize() / 8);
|
|
2253
|
+
if (!e || !e.isDragging) return;
|
|
2254
|
+
const r = this.boardRuntime.getInternalRefVal(e.id);
|
|
2255
|
+
if (!r) return;
|
|
2256
|
+
this.boardRuntime.renderer.getLayerManager().getLayer("dynamicPieces").addCoords(e.id, {
|
|
2257
|
+
x: r.x,
|
|
2258
|
+
y: r.y,
|
|
2259
|
+
w: t,
|
|
2260
|
+
h: t
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
onPointerDrop() {
|
|
2264
|
+
}
|
|
2265
|
+
onAnimationFrame() {
|
|
2266
|
+
}
|
|
2267
|
+
onDrawPiece() {
|
|
2268
|
+
}
|
|
2269
|
+
onDrawBoard() {
|
|
2270
|
+
}
|
|
2271
|
+
onDrawOverlay() {
|
|
2272
|
+
}
|
|
2273
|
+
onDrawUnderlay() {
|
|
2274
|
+
}
|
|
2275
|
+
run(e) {
|
|
2276
|
+
const t = this.eventsRunMap[e];
|
|
2277
|
+
if (!t) return;
|
|
2278
|
+
const r = this.getEventLayer(e), n = r ? this.boardRuntime.getCanvasLayers().getContext(r) : null;
|
|
2279
|
+
t(n);
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
class qe {
|
|
2283
|
+
layers;
|
|
2284
|
+
iterator;
|
|
2285
|
+
events;
|
|
2286
|
+
interaction = {
|
|
2287
|
+
onPointerSelect: !0,
|
|
2288
|
+
onPointerHover: !0,
|
|
2289
|
+
onPointerDragStart: !0,
|
|
2290
|
+
onPointerDrag: !0,
|
|
2291
|
+
onPointerDrop: !0,
|
|
2292
|
+
onAnimationFrame: !0,
|
|
2293
|
+
onDrawPiece: !0,
|
|
2294
|
+
onDrawBoard: !0,
|
|
2295
|
+
onDrawOverlay: !0,
|
|
2296
|
+
onDrawUnderlay: !0
|
|
2297
|
+
};
|
|
2298
|
+
boardRuntime;
|
|
2299
|
+
drawList = /* @__PURE__ */ new Set();
|
|
2300
|
+
firstDrawList = /* @__PURE__ */ new Set();
|
|
2301
|
+
list = {
|
|
2302
|
+
onPointerSelect: this.drawList,
|
|
2303
|
+
onPointerHover: this.drawList,
|
|
2304
|
+
onPointerDragStart: this.firstDrawList,
|
|
2305
|
+
onPointerDrag: this.firstDrawList,
|
|
2306
|
+
onPointerDrop: this.drawList,
|
|
2307
|
+
onAnimationFrame: this.drawList,
|
|
2308
|
+
onDrawPiece: this.drawList,
|
|
2309
|
+
onDrawBoard: this.drawList,
|
|
2310
|
+
onDrawOverlay: this.drawList,
|
|
2311
|
+
onDrawUnderlay: this.drawList
|
|
2312
|
+
};
|
|
2313
|
+
delayedPieceClear = /* @__PURE__ */ new Map();
|
|
2314
|
+
constructor(e) {
|
|
2315
|
+
this.boardRuntime = e, this.layers = {
|
|
2316
|
+
board: new Oe(e),
|
|
2317
|
+
overlay: new je(e),
|
|
2318
|
+
underlay: new Ie(e),
|
|
2319
|
+
staticPieces: new He(e),
|
|
2320
|
+
dynamicPieces: new Ne(e)
|
|
2321
|
+
}, this.iterator = new _e(e), this.events = new ze(e);
|
|
2322
|
+
}
|
|
2323
|
+
getLayer(e) {
|
|
2324
|
+
return this.layers[e];
|
|
2325
|
+
}
|
|
2326
|
+
getAllLayers() {
|
|
2327
|
+
return Object.keys(this.layers);
|
|
2328
|
+
}
|
|
2329
|
+
getIterator() {
|
|
2330
|
+
return this.iterator;
|
|
2331
|
+
}
|
|
2332
|
+
getPieceLayer(e) {
|
|
2333
|
+
for (const [t, r] of Object.entries(this.layers))
|
|
2334
|
+
if (r.hasPiece(e)) return t;
|
|
2335
|
+
return null;
|
|
2336
|
+
}
|
|
2337
|
+
removeFromAllLayers(e) {
|
|
2338
|
+
for (const t of Object.values(this.layers)) t.removeAll?.(e);
|
|
2339
|
+
}
|
|
2340
|
+
removeEvent(e) {
|
|
2341
|
+
for (const t of Object.values(this.layers)) t.removeEvent(e);
|
|
2342
|
+
}
|
|
2343
|
+
async togglePieceLayer(e, t, r, n) {
|
|
2344
|
+
if (e === t) return;
|
|
2345
|
+
const i = this.getLayer(e), s = this.getLayer(t), a = Math.floor(this.boardRuntime.getSize() / 8), o = this.boardRuntime.isActivePiece(r);
|
|
2346
|
+
if (!i || !s)
|
|
2347
|
+
return;
|
|
2348
|
+
const c = i.getPiece(r), u = i.getCoords(r);
|
|
2349
|
+
if (!c || !u)
|
|
2350
|
+
return;
|
|
2351
|
+
const h = b.squareToCoords(
|
|
2352
|
+
c.square,
|
|
2353
|
+
a,
|
|
2354
|
+
this.boardRuntime.getIsBlackView()
|
|
2355
|
+
);
|
|
2356
|
+
if (!h) return;
|
|
2357
|
+
const y = t === "staticPieces" ? {
|
|
2358
|
+
x: Math.floor(h.x),
|
|
2359
|
+
y: Math.floor(h.y),
|
|
2360
|
+
w: Math.ceil(a),
|
|
2361
|
+
h: Math.ceil(a)
|
|
2362
|
+
} : {
|
|
2363
|
+
x: Math.floor(c.x),
|
|
2364
|
+
y: Math.floor(c.y),
|
|
2365
|
+
w: Math.ceil(a),
|
|
2366
|
+
h: Math.ceil(a)
|
|
2367
|
+
};
|
|
2368
|
+
i.removeAll?.(r), o && s.addAll?.(r, c, y, y), !n && this.boardRuntime.renderer.pipelineRender.setNextEvent("onRender", [
|
|
2369
|
+
{
|
|
2370
|
+
board: !1,
|
|
2371
|
+
staticPieces: !0,
|
|
2372
|
+
overlay: !0,
|
|
2373
|
+
underlay: !0,
|
|
2374
|
+
dynamicPieces: !0
|
|
2375
|
+
}
|
|
2376
|
+
]);
|
|
2377
|
+
}
|
|
2378
|
+
applyDrawResult(e, t, r, n) {
|
|
2379
|
+
const i = e.__drawRegions, s = e.__actualRegions;
|
|
2380
|
+
for (const a of i) {
|
|
2381
|
+
const o = {
|
|
2382
|
+
x: Math.floor(a.x),
|
|
2383
|
+
y: Math.floor(a.y),
|
|
2384
|
+
w: Math.ceil(a.w),
|
|
2385
|
+
h: Math.ceil(a.h)
|
|
2386
|
+
};
|
|
2387
|
+
n && this.getLayer(t).addClearCoords(n, o), r && this.getLayer(t).addEvent(r, o);
|
|
2388
|
+
}
|
|
2389
|
+
for (const a of s) {
|
|
2390
|
+
const o = {
|
|
2391
|
+
x: Math.floor(a.x),
|
|
2392
|
+
y: Math.floor(a.y),
|
|
2393
|
+
w: Math.ceil(a.w),
|
|
2394
|
+
h: Math.ceil(a.h)
|
|
2395
|
+
};
|
|
2396
|
+
n && this.getLayer(t).addCoords(n, o);
|
|
2397
|
+
}
|
|
2398
|
+
e.__clearRegions();
|
|
2399
|
+
}
|
|
2400
|
+
drawEvent(e) {
|
|
2401
|
+
this.removeEvent(e), this.addDraw(e);
|
|
2402
|
+
}
|
|
2403
|
+
addDraw(e) {
|
|
2404
|
+
this.list[e].add(e);
|
|
2405
|
+
}
|
|
2406
|
+
removeDraw(e) {
|
|
2407
|
+
this.list[e].delete(e);
|
|
2408
|
+
}
|
|
2409
|
+
getEventEnabled() {
|
|
2410
|
+
return this.interaction;
|
|
2411
|
+
}
|
|
2412
|
+
isSelectionEnabled() {
|
|
2413
|
+
return this.interaction.onPointerSelect;
|
|
2414
|
+
}
|
|
2415
|
+
isHoverEnabled() {
|
|
2416
|
+
return this.interaction.onPointerHover;
|
|
2417
|
+
}
|
|
2418
|
+
setHoverEnabled(e) {
|
|
2419
|
+
return this.interaction.onPointerHover = e;
|
|
2420
|
+
}
|
|
2421
|
+
setSelectionEnabled(e) {
|
|
2422
|
+
return this.interaction.onPointerSelect = e;
|
|
2423
|
+
}
|
|
2424
|
+
resetAllLayers() {
|
|
2425
|
+
for (const e of Object.values(this.layers)) e.resetLayer();
|
|
2426
|
+
}
|
|
2427
|
+
renderEvents(e) {
|
|
2428
|
+
const t = e ? this.firstDrawList.values() : this.drawList.values();
|
|
2429
|
+
for (const r of t)
|
|
2430
|
+
this.interaction[r] = !1, this.events.run(r), this.interaction[r] = !0;
|
|
2431
|
+
e ? this.firstDrawList.clear() : this.drawList.clear();
|
|
2432
|
+
}
|
|
2433
|
+
addDelayedPieceClear(e, t) {
|
|
2434
|
+
this.delayedPieceClear.set(e, t);
|
|
2435
|
+
}
|
|
2436
|
+
getDelayedPieceClear(e) {
|
|
2437
|
+
return this.delayedPieceClear.get(e);
|
|
2438
|
+
}
|
|
2439
|
+
deleteDelayedPieceClear(e) {
|
|
2440
|
+
this.delayedPieceClear.delete(e);
|
|
2441
|
+
}
|
|
2442
|
+
resetDelayedPieceClear() {
|
|
2443
|
+
this.delayedPieceClear.clear();
|
|
2444
|
+
}
|
|
2445
|
+
isDelayedPieceClear(e) {
|
|
2446
|
+
return Array.from(this.delayedPieceClear.values()).includes(e);
|
|
2447
|
+
}
|
|
2448
|
+
clearDelayedPiece(e, t) {
|
|
2449
|
+
const r = this.getDelayedPieceClear(e);
|
|
2450
|
+
if (r) {
|
|
2451
|
+
const n = this.getLayer(t), i = n.getCoords(r);
|
|
2452
|
+
i && (n.addClearQueue(i), n.removeAll?.(r), n.clear()), this.deleteDelayedPieceClear(e);
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
class Fe {
|
|
2457
|
+
constructor(e) {
|
|
2458
|
+
this.boardRuntime = e;
|
|
2459
|
+
}
|
|
2460
|
+
eventsNext = {
|
|
2461
|
+
onPointerSelect: [],
|
|
2462
|
+
onPointerHover: [],
|
|
2463
|
+
onPointerDragStart: [],
|
|
2464
|
+
onPointerDrag: [],
|
|
2465
|
+
onPointerDrop: [],
|
|
2466
|
+
onAnimationFrame: [],
|
|
2467
|
+
onDrawPiece: [],
|
|
2468
|
+
onDrawBoard: [],
|
|
2469
|
+
onDrawOverlay: [],
|
|
2470
|
+
onDrawUnderlay: [],
|
|
2471
|
+
onToggleCanvas: [],
|
|
2472
|
+
onRender: []
|
|
2473
|
+
};
|
|
2474
|
+
eventsToken = {
|
|
2475
|
+
onPointerSelect: 0,
|
|
2476
|
+
onPointerHover: 0,
|
|
2477
|
+
onPointerDragStart: 0,
|
|
2478
|
+
onPointerDrag: 0,
|
|
2479
|
+
onPointerDrop: 0,
|
|
2480
|
+
onAnimationFrame: 0,
|
|
2481
|
+
onDrawPiece: 0,
|
|
2482
|
+
onDrawBoard: 0,
|
|
2483
|
+
onDrawOverlay: 0,
|
|
2484
|
+
onDrawUnderlay: 0,
|
|
2485
|
+
onToggleCanvas: 0,
|
|
2486
|
+
onRender: 0
|
|
2487
|
+
};
|
|
2488
|
+
loading = !1;
|
|
2489
|
+
destroyed = !1;
|
|
2490
|
+
stream = [];
|
|
2491
|
+
destroy() {
|
|
2492
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
2493
|
+
this[e] = null;
|
|
2494
|
+
this.destroyed = !0;
|
|
2495
|
+
}
|
|
2496
|
+
setNextEvent(e, t, r) {
|
|
2497
|
+
const n = ++this.eventsToken[e];
|
|
2498
|
+
this.eventsNext[e].push({ args: [...t], token: n, resolve: r }), this.stream.push(e), this.loading || this.loadEvents();
|
|
2499
|
+
}
|
|
2500
|
+
getNextEvent(e) {
|
|
2501
|
+
return this.eventsNext[e].shift();
|
|
2502
|
+
}
|
|
2503
|
+
async loadEvents() {
|
|
2504
|
+
if (!(this.loading || this.destroyed)) {
|
|
2505
|
+
this.loading = !0;
|
|
2506
|
+
try {
|
|
2507
|
+
for (; !this.destroyed && this.stream.length > 0; ) {
|
|
2508
|
+
const e = this.stream.shift(), t = this.getNextEvent(e);
|
|
2509
|
+
if (!t) continue;
|
|
2510
|
+
const { args: r, token: n, resolve: i } = t;
|
|
2511
|
+
if (n !== this.eventsToken[e]) {
|
|
2512
|
+
i?.();
|
|
2513
|
+
continue;
|
|
2514
|
+
}
|
|
2515
|
+
const s = this.boardRuntime.renderer.eventsRuntime[e];
|
|
2516
|
+
!s || !r || (await s(...r), i?.());
|
|
2517
|
+
}
|
|
2518
|
+
} finally {
|
|
2519
|
+
if (this.destroyed) return;
|
|
2520
|
+
this.stream.length ? this.loadEvents() : this.loading = !1;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
class Ve {
|
|
2526
|
+
constructor(e) {
|
|
2527
|
+
this.boardRuntime = e, this.layerManager = new qe(e), this.eventsRuntime = {
|
|
2528
|
+
onPointerSelect: this.boardRuntime.setSelected.bind(this.boardRuntime),
|
|
2529
|
+
onPointerHover: this.boardRuntime.setPieceHover.bind(this.boardRuntime),
|
|
2530
|
+
onPointerDragStart: null,
|
|
2531
|
+
onPointerDrag: null,
|
|
2532
|
+
onPointerDrop: null,
|
|
2533
|
+
onAnimationFrame: null,
|
|
2534
|
+
onDrawPiece: null,
|
|
2535
|
+
onDrawBoard: null,
|
|
2536
|
+
onDrawOverlay: null,
|
|
2537
|
+
onDrawUnderlay: null,
|
|
2538
|
+
onToggleCanvas: this.toggleCanvas.bind(this),
|
|
2539
|
+
onRender: this.render.bind(this)
|
|
2540
|
+
}, this.pipelineRender = new Fe(e);
|
|
2541
|
+
}
|
|
2542
|
+
layerManager;
|
|
2543
|
+
eventsRuntime;
|
|
2544
|
+
pipelineRender;
|
|
2545
|
+
destroy() {
|
|
2546
|
+
this.pipelineRender.destroy();
|
|
2547
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
2548
|
+
this[e] = null;
|
|
2549
|
+
}
|
|
2550
|
+
async render(e) {
|
|
2551
|
+
this.layerManager.renderEvents(!0);
|
|
2552
|
+
for (const [t, r] of Object.entries(e))
|
|
2553
|
+
r && await this.layerManager.getLayer(t).renderAsync();
|
|
2554
|
+
this.layerManager.renderEvents(!1);
|
|
2555
|
+
}
|
|
2556
|
+
getLayerManager() {
|
|
2557
|
+
return this.layerManager;
|
|
2558
|
+
}
|
|
2559
|
+
async toggleCanvas(e, t, r, n) {
|
|
2560
|
+
await this.layerManager.togglePieceLayer(e, t, r, n);
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
class $e {
|
|
2564
|
+
constructor(e) {
|
|
2565
|
+
this.boardRuntime = e;
|
|
2566
|
+
}
|
|
2567
|
+
pipelineRender;
|
|
2568
|
+
eventsRuntime = {};
|
|
2569
|
+
destroy() {
|
|
2570
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
2571
|
+
this[e] = null;
|
|
2572
|
+
}
|
|
2573
|
+
getLayerManager() {
|
|
2574
|
+
throw new Error("Method not implemented.");
|
|
2575
|
+
}
|
|
2576
|
+
async render(e) {
|
|
2577
|
+
throw new Error("Method not implemented.");
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
class We {
|
|
2581
|
+
events = /* @__PURE__ */ new Map();
|
|
2582
|
+
on(e, t) {
|
|
2583
|
+
const r = this.events.get(e) ?? [];
|
|
2584
|
+
return r.includes(t) ? () => {
|
|
2585
|
+
} : (r.push(t), this.events.set(e, r), () => this.off(e, t));
|
|
2586
|
+
}
|
|
2587
|
+
off(e, t) {
|
|
2588
|
+
const r = this.events.get(e);
|
|
2589
|
+
if (!r) return;
|
|
2590
|
+
const n = r.indexOf(t);
|
|
2591
|
+
n !== -1 && (r.splice(n, 1), r.length || this.events.delete(e));
|
|
2592
|
+
}
|
|
2593
|
+
emit(e, ...t) {
|
|
2594
|
+
const r = this.events.get(e);
|
|
2595
|
+
if (r)
|
|
2596
|
+
for (const n of [...r])
|
|
2597
|
+
n(...t);
|
|
2598
|
+
}
|
|
2599
|
+
once(e, t) {
|
|
2600
|
+
const r = (...i) => {
|
|
2601
|
+
n(), t(...i);
|
|
2602
|
+
}, n = this.on(e, r);
|
|
2603
|
+
return n;
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
class te {
|
|
2607
|
+
constructor(e) {
|
|
2608
|
+
this.args = e, Object.assign(this, e), e.hoverConfig && (this.hoverConfig = e.hoverConfig), this.renderer = e.mode === "2d" ? new Ve(this) : new $e(this), this.setInactivePieces(), b.validateFen(e.board) ? this.setBoard(b.parseFen(e.board)) : this.setBoard(
|
|
2609
|
+
b.parseFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
|
|
2610
|
+
);
|
|
2611
|
+
}
|
|
2612
|
+
internalRef = {};
|
|
2613
|
+
selected = null;
|
|
2614
|
+
pieceHover = null;
|
|
2615
|
+
isImagesLoaded = !1;
|
|
2616
|
+
destroyed = !1;
|
|
2617
|
+
animationDuration = 300;
|
|
2618
|
+
piecesToRender = [];
|
|
2619
|
+
isMoving = !1;
|
|
2620
|
+
board;
|
|
2621
|
+
hoverConfig = {
|
|
2622
|
+
highlight: !0,
|
|
2623
|
+
scaling: !1,
|
|
2624
|
+
scaleAmount: 1.05
|
|
2625
|
+
};
|
|
2626
|
+
boardEvents = new ve(this);
|
|
2627
|
+
helpers = new Te(this);
|
|
2628
|
+
renderer;
|
|
2629
|
+
mounted = !1;
|
|
2630
|
+
default = {
|
|
2631
|
+
onPointerSelect: !0,
|
|
2632
|
+
onPointerHover: !0,
|
|
2633
|
+
moveAnimation: !0
|
|
2634
|
+
};
|
|
2635
|
+
activePiecesPool = {
|
|
2636
|
+
wP: /* @__PURE__ */ new Map(),
|
|
2637
|
+
wR: /* @__PURE__ */ new Map(),
|
|
2638
|
+
wN: /* @__PURE__ */ new Map(),
|
|
2639
|
+
wB: /* @__PURE__ */ new Map(),
|
|
2640
|
+
wQ: /* @__PURE__ */ new Map(),
|
|
2641
|
+
wK: /* @__PURE__ */ new Map(),
|
|
2642
|
+
bP: /* @__PURE__ */ new Map(),
|
|
2643
|
+
bR: /* @__PURE__ */ new Map(),
|
|
2644
|
+
bN: /* @__PURE__ */ new Map(),
|
|
2645
|
+
bB: /* @__PURE__ */ new Map(),
|
|
2646
|
+
bQ: /* @__PURE__ */ new Map(),
|
|
2647
|
+
bK: /* @__PURE__ */ new Map()
|
|
2648
|
+
};
|
|
2649
|
+
inactivePiecesPool = {
|
|
2650
|
+
wP: [],
|
|
2651
|
+
wR: [],
|
|
2652
|
+
wN: [],
|
|
2653
|
+
wB: [],
|
|
2654
|
+
wQ: [],
|
|
2655
|
+
wK: [],
|
|
2656
|
+
bP: [],
|
|
2657
|
+
bR: [],
|
|
2658
|
+
bN: [],
|
|
2659
|
+
bB: [],
|
|
2660
|
+
bQ: [],
|
|
2661
|
+
bK: []
|
|
2662
|
+
};
|
|
2663
|
+
piecesBoard = /* @__PURE__ */ new Map();
|
|
2664
|
+
undoStack = [];
|
|
2665
|
+
redoStack = [];
|
|
2666
|
+
eventEmitter = new We();
|
|
2667
|
+
static async create(e) {
|
|
2668
|
+
const t = new te(e);
|
|
2669
|
+
return await t.init(), t;
|
|
2670
|
+
}
|
|
2671
|
+
destroy() {
|
|
2672
|
+
this.mounted && (this.destroyed = !0, this.args.canvasLayers.destroy(), this.helpers.destroy(), this.boardEvents.destroy(), this.args.canvasLayers = null, this.helpers = null, this.boardEvents = null, this.args.pieceStyle && Object.entries(this.args.pieceStyle).map(([e, t]) => {
|
|
2673
|
+
t instanceof HTMLImageElement && (t.src = "", t.onload = null, t.onerror = null), t = null;
|
|
2674
|
+
}));
|
|
2675
|
+
}
|
|
2676
|
+
addPieceBoard(e, t) {
|
|
2677
|
+
this.piecesBoard.set(e, t);
|
|
2678
|
+
}
|
|
2679
|
+
deletePieceBoard(e) {
|
|
2680
|
+
this.piecesBoard.delete(e);
|
|
2681
|
+
}
|
|
2682
|
+
getPieceBoard(e) {
|
|
2683
|
+
return this.piecesBoard.get(e);
|
|
2684
|
+
}
|
|
2685
|
+
getSize() {
|
|
2686
|
+
return this.args.size;
|
|
2687
|
+
}
|
|
2688
|
+
mount() {
|
|
2689
|
+
this.mounted = !0;
|
|
2690
|
+
}
|
|
2691
|
+
getIsBlackView() {
|
|
2692
|
+
return this.args.isBlackView;
|
|
2693
|
+
}
|
|
2694
|
+
getSelected() {
|
|
2695
|
+
return this.selected;
|
|
2696
|
+
}
|
|
2697
|
+
getInternalRefObj() {
|
|
2698
|
+
return this.internalRef;
|
|
2699
|
+
}
|
|
2700
|
+
getPieceHover() {
|
|
2701
|
+
return this.pieceHover;
|
|
2702
|
+
}
|
|
2703
|
+
getBoardCanvas() {
|
|
2704
|
+
return this.args.canvasLayers.getCanvas("board");
|
|
2705
|
+
}
|
|
2706
|
+
getStaticPiecesCanvas() {
|
|
2707
|
+
return this.args.canvasLayers.getCanvas("staticPieces");
|
|
2708
|
+
}
|
|
2709
|
+
getDynamicPiecesCanvas() {
|
|
2710
|
+
return this.args.canvasLayers.getCanvas("dynamicPieces");
|
|
2711
|
+
}
|
|
2712
|
+
getUnderlaycanvas() {
|
|
2713
|
+
return this.args.canvasLayers.getCanvas("underlay");
|
|
2714
|
+
}
|
|
2715
|
+
getOverlaycanvas() {
|
|
2716
|
+
return this.args.canvasLayers.getCanvas("overlay");
|
|
2717
|
+
}
|
|
2718
|
+
getInternalRefVal(e) {
|
|
2719
|
+
return this.internalRef[e];
|
|
2720
|
+
}
|
|
2721
|
+
getLightTile() {
|
|
2722
|
+
return this.args.lightTile || "#9a8b6dff";
|
|
2723
|
+
}
|
|
2724
|
+
getDarkTile() {
|
|
2725
|
+
return this.args.darkTile || "#3E2723";
|
|
2726
|
+
}
|
|
2727
|
+
getPieceStyle() {
|
|
2728
|
+
return this.args.pieceStyle;
|
|
2729
|
+
}
|
|
2730
|
+
getEvents() {
|
|
2731
|
+
return this.args.events;
|
|
2732
|
+
}
|
|
2733
|
+
getInjection() {
|
|
2734
|
+
return this.args.injection;
|
|
2735
|
+
}
|
|
2736
|
+
getBoard() {
|
|
2737
|
+
return this.board;
|
|
2738
|
+
}
|
|
2739
|
+
getMove() {
|
|
2740
|
+
return this.args.onMove;
|
|
2741
|
+
}
|
|
2742
|
+
getCanvasLayers() {
|
|
2743
|
+
return this.args.canvasLayers;
|
|
2744
|
+
}
|
|
2745
|
+
getAnimationDuration() {
|
|
2746
|
+
return this.animationDuration;
|
|
2747
|
+
}
|
|
2748
|
+
getDefault() {
|
|
2749
|
+
return this.args.default ? this.args.default : this.default;
|
|
2750
|
+
}
|
|
2751
|
+
getReadonlyInternalRef() {
|
|
2752
|
+
return b.deepFreeze(this.internalRef);
|
|
2753
|
+
}
|
|
2754
|
+
getReadonlySelectedRef() {
|
|
2755
|
+
return this.selected ? b.deepFreeze(this.selected) : null;
|
|
2756
|
+
}
|
|
2757
|
+
getReadonlyPiece(e, t) {
|
|
2758
|
+
return e ? b.deepFreeze(e) : null;
|
|
2759
|
+
}
|
|
2760
|
+
getReadonlySquare(e) {
|
|
2761
|
+
return e ? b.deepFreeze(e) : null;
|
|
2762
|
+
}
|
|
2763
|
+
getReadonlyAnimation() {
|
|
2764
|
+
const e = [];
|
|
2765
|
+
for (const t of this.renderer.getLayerManager().getAllLayers())
|
|
2766
|
+
e.push(
|
|
2767
|
+
...this.renderer.getLayerManager().getLayer(t).getAnimation()
|
|
2768
|
+
);
|
|
2769
|
+
return b.deepFreeze(e);
|
|
2770
|
+
}
|
|
2771
|
+
getReadonlyBoard() {
|
|
2772
|
+
return b.deepFreeze(this.getBoard());
|
|
2773
|
+
}
|
|
2774
|
+
getDefaultAnimation() {
|
|
2775
|
+
return this.args.default.moveAnimation;
|
|
2776
|
+
}
|
|
2777
|
+
getContext(e, t) {
|
|
2778
|
+
const { squareSize: r, size: n, x: i, y: s, piece: a, square: o } = t, c = this.helpers.createLazyEventContext(
|
|
2779
|
+
{ squareSize: r, size: n, x: i, y: s },
|
|
2780
|
+
{
|
|
2781
|
+
getPiece: () => this.getReadonlyPiece(a || void 0),
|
|
2782
|
+
getPiecesImage: () => this.getPieceStyle(),
|
|
2783
|
+
getSquare: () => this.getReadonlySquare(o || void 0),
|
|
2784
|
+
getPieces: () => this.getReadonlyInternalRef(),
|
|
2785
|
+
getPieceHover: () => this.getPieceHover(),
|
|
2786
|
+
getSelected: () => this.getReadonlySelectedRef(),
|
|
2787
|
+
getIsBlackView: () => this.getIsBlackView(),
|
|
2788
|
+
getLightTile: () => this.getLightTile(),
|
|
2789
|
+
getDarkTile: () => this.getDarkTile(),
|
|
2790
|
+
getAnimation: () => this.getReadonlyAnimation(),
|
|
2791
|
+
getDraw: () => {
|
|
2792
|
+
const u = c.__event, h = (y) => {
|
|
2793
|
+
const { onDraw: f, layer: g } = y, P = this.getCanvasLayers().getClientContext(g);
|
|
2794
|
+
if (!P) return;
|
|
2795
|
+
f(P);
|
|
2796
|
+
const v = P;
|
|
2797
|
+
this.renderer.getLayerManager().applyDrawResult(v, g, u);
|
|
2798
|
+
};
|
|
2799
|
+
return h.batch = (y) => {
|
|
2800
|
+
const f = {};
|
|
2801
|
+
let g = 0;
|
|
2802
|
+
for (const { layer: v, onDraw: C } of y)
|
|
2803
|
+
f[v] || (f[v] = []), f[v].push({ fn: C, index: g++ });
|
|
2804
|
+
const P = Object.values(f).flat().sort((v, C) => v.index - C.index);
|
|
2805
|
+
for (const { fn: v, index: C } of P) {
|
|
2806
|
+
const p = y[C].layer;
|
|
2807
|
+
h.group(p, (m, w) => {
|
|
2808
|
+
w.draw(v);
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2811
|
+
}, h.group = (y, f) => {
|
|
2812
|
+
const g = this.getCanvasLayers().getClientContext(y);
|
|
2813
|
+
if (!g) return;
|
|
2814
|
+
f(g, {
|
|
2815
|
+
draw: (C) => C(g)
|
|
2816
|
+
});
|
|
2817
|
+
const v = g;
|
|
2818
|
+
this.renderer.getLayerManager().applyDrawResult(v, y, u);
|
|
2819
|
+
}, h;
|
|
2820
|
+
}
|
|
2821
|
+
},
|
|
2822
|
+
{ cache: e }
|
|
2823
|
+
);
|
|
2824
|
+
return c;
|
|
2825
|
+
}
|
|
2826
|
+
getIsMoving() {
|
|
2827
|
+
return this.isMoving;
|
|
2828
|
+
}
|
|
2829
|
+
getHoverConfig() {
|
|
2830
|
+
return (this.hoverConfig.scaleAmount < 0.75 || this.hoverConfig.scaleAmount > 1.15) && (this.hoverConfig.scaleAmount = Math.min(
|
|
2831
|
+
1.15,
|
|
2832
|
+
Math.max(0.75, this.hoverConfig.scaleAmount)
|
|
2833
|
+
)), this.hoverConfig;
|
|
2834
|
+
}
|
|
2835
|
+
getEventEmitter() {
|
|
2836
|
+
return this.eventEmitter;
|
|
2837
|
+
}
|
|
2838
|
+
isActivePiece(e) {
|
|
2839
|
+
return !!this.piecesBoard.get(e)?.square;
|
|
2840
|
+
}
|
|
2841
|
+
setHoverConfig(e) {
|
|
2842
|
+
this.hoverConfig = e;
|
|
2843
|
+
}
|
|
2844
|
+
setIsMoving(e) {
|
|
2845
|
+
this.isMoving = e;
|
|
2846
|
+
}
|
|
2847
|
+
setInactivePieces() {
|
|
2848
|
+
for (let e = 1; e <= 64; e++)
|
|
2849
|
+
for (const t of ae) {
|
|
2850
|
+
const r = `${t}${e}`;
|
|
2851
|
+
this.inactivePiecesPool[t].push(r);
|
|
2852
|
+
const n = {
|
|
2853
|
+
square: null,
|
|
2854
|
+
type: t,
|
|
2855
|
+
id: r
|
|
2856
|
+
};
|
|
2857
|
+
this.piecesBoard.set(r, n);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
getInactivePiece(e) {
|
|
2861
|
+
return this.inactivePiecesPool[e].shift();
|
|
2862
|
+
}
|
|
2863
|
+
addInactivePiece(e, t) {
|
|
2864
|
+
this.inactivePiecesPool[e].unshift(t);
|
|
2865
|
+
}
|
|
2866
|
+
toggleHoverScale(e) {
|
|
2867
|
+
this.hoverConfig.scaleAmount = e;
|
|
2868
|
+
}
|
|
2869
|
+
toggleHoverScaling() {
|
|
2870
|
+
this.hoverConfig.scaling = !this.hoverConfig.scaling;
|
|
2871
|
+
}
|
|
2872
|
+
toggleHoverHighlight() {
|
|
2873
|
+
this.hoverConfig.highlight = !this.hoverConfig.highlight;
|
|
2874
|
+
}
|
|
2875
|
+
async setSize(e) {
|
|
2876
|
+
this.args.size = Math.floor(e / 8) * 8, this.getCanvasLayers().clearAllRect(), this.getCanvasLayers().resize(Math.floor(e / 8) * 8), this.setInternalRefObj({}), this.renderer.getLayerManager().resetAllLayers(), await this.refreshCanvases({
|
|
2877
|
+
board: !0,
|
|
2878
|
+
staticPieces: !0,
|
|
2879
|
+
overlay: !0,
|
|
2880
|
+
underlay: !0,
|
|
2881
|
+
dynamicPieces: !0
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
setAnimationDuration(e) {
|
|
2885
|
+
e < 150 || e > 500 || (this.animationDuration = e);
|
|
2886
|
+
}
|
|
2887
|
+
async setBoardByFen(e) {
|
|
2888
|
+
b.validateFen(e).status && (this.setIsMoving(!0), this.setBoard(b.parseFen(e)), this.clearRedo(), this.clearUndo(), await this.refreshCanvases({
|
|
2889
|
+
board: !1,
|
|
2890
|
+
staticPieces: !0,
|
|
2891
|
+
overlay: !0,
|
|
2892
|
+
underlay: !0,
|
|
2893
|
+
dynamicPieces: !0
|
|
2894
|
+
}), this.setIsMoving(!1));
|
|
2895
|
+
}
|
|
2896
|
+
setBoard(e) {
|
|
2897
|
+
for (const t of ae) {
|
|
2898
|
+
const r = [], n = e[t] ? e[t] : [], i = this.activePiecesPool[t], s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
2899
|
+
for (let y = 0; y < n.length; y++) {
|
|
2900
|
+
const f = n[y];
|
|
2901
|
+
i.get(f) && (a.add(f), s.add(f));
|
|
2902
|
+
}
|
|
2903
|
+
const o = [], c = Array.from(i.keys());
|
|
2904
|
+
let u = 0;
|
|
2905
|
+
for (let y = 0; y < n.length; y++) {
|
|
2906
|
+
const f = n[y];
|
|
2907
|
+
if (!a.has(f))
|
|
2908
|
+
for (; u < c.length; ) {
|
|
2909
|
+
const g = c[u++];
|
|
2910
|
+
if (g && !s.has(g)) {
|
|
2911
|
+
r.push({ from: g, to: f }), s.add(g), a.add(f);
|
|
2912
|
+
break;
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
for (let y = 0; y < n.length; y++) {
|
|
2917
|
+
const f = n[y];
|
|
2918
|
+
a.has(f) || o.push(f);
|
|
2919
|
+
}
|
|
2920
|
+
const h = /* @__PURE__ */ new Set();
|
|
2921
|
+
for (const y of c)
|
|
2922
|
+
s.has(y) || h.add(y);
|
|
2923
|
+
this.updateBoardPieces(r, h, o, t);
|
|
2924
|
+
}
|
|
2925
|
+
this.createBoard();
|
|
2926
|
+
}
|
|
2927
|
+
createBoard() {
|
|
2928
|
+
const e = {};
|
|
2929
|
+
for (const [t, r] of Object.entries(this.activePiecesPool))
|
|
2930
|
+
for (const n of r.keys()) {
|
|
2931
|
+
const i = r.get(n);
|
|
2932
|
+
if (!i) continue;
|
|
2933
|
+
const s = this.piecesBoard.get(i);
|
|
2934
|
+
s && (e[n] = {
|
|
2935
|
+
id: i,
|
|
2936
|
+
square: s.square,
|
|
2937
|
+
type: t
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
this.board = e;
|
|
2941
|
+
}
|
|
2942
|
+
updateBoardPieces(e, t, r, n) {
|
|
2943
|
+
for (const i of e) {
|
|
2944
|
+
const s = this.activePiecesPool[n].get(i.from);
|
|
2945
|
+
if (!s) continue;
|
|
2946
|
+
this.activePiecesPool[n].delete(i.from), this.activePiecesPool[n].set(i.to, s);
|
|
2947
|
+
const a = this.piecesBoard.get(s);
|
|
2948
|
+
a && (a.square = {
|
|
2949
|
+
file: i.to[0],
|
|
2950
|
+
rank: parseInt(i.to[1]),
|
|
2951
|
+
notation: i.to
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
for (const i of t.values()) {
|
|
2955
|
+
const s = this.activePiecesPool[n].get(i);
|
|
2956
|
+
if (!s) continue;
|
|
2957
|
+
this.inactivePiecesPool[n].push(s), this.activePiecesPool[n].delete(i);
|
|
2958
|
+
const a = this.piecesBoard.get(s);
|
|
2959
|
+
a && (a.square = null);
|
|
2960
|
+
}
|
|
2961
|
+
for (let i = 0; i < r.length; i++) {
|
|
2962
|
+
const s = this.inactivePiecesPool[n].shift();
|
|
2963
|
+
if (!s) continue;
|
|
2964
|
+
const a = r[i];
|
|
2965
|
+
this.activePiecesPool[n].set(a, s);
|
|
2966
|
+
const o = this.piecesBoard.get(s);
|
|
2967
|
+
o && (o.square = {
|
|
2968
|
+
file: a.charAt(0),
|
|
2969
|
+
rank: parseInt(a.charAt(1)),
|
|
2970
|
+
notation: a
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
async refreshCanvases(e) {
|
|
2975
|
+
await this.resetEvents(!0), this.renderer.getLayerManager().setHoverEnabled(!1), this.helpers.pieceHelper.clearCache(), await this.initInternalRef();
|
|
2976
|
+
const t = (r) => this.renderer.pipelineRender.setNextEvent(
|
|
2977
|
+
"onRender",
|
|
2978
|
+
[e],
|
|
2979
|
+
r
|
|
2980
|
+
);
|
|
2981
|
+
await b.asyncHandler(t), this.renderer.getLayerManager().setHoverEnabled(!0);
|
|
2982
|
+
try {
|
|
2983
|
+
this.args.onUpdate && this.args.onUpdate();
|
|
2984
|
+
} catch (r) {
|
|
2985
|
+
console.log(r);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
async resetEvents(e) {
|
|
2989
|
+
let t = !1;
|
|
2990
|
+
if (this.selected !== null && (this.selected.isDragging && this.helpers.pointerEventsHelper.endDrag(-1, -1, !1, !0), this.renderer.pipelineRender.setNextEvent("onPointerSelect", [
|
|
2991
|
+
null,
|
|
2992
|
+
!0
|
|
2993
|
+
]), t = !0), this.pieceHover !== null && (this.renderer.pipelineRender.setNextEvent("onPointerHover", [null, !0]), t = !0), !e || !t) return;
|
|
2994
|
+
const r = (n) => this.renderer.pipelineRender.setNextEvent(
|
|
2995
|
+
"onRender",
|
|
2996
|
+
[
|
|
2997
|
+
{
|
|
2998
|
+
board: !1,
|
|
2999
|
+
staticPieces: !0,
|
|
3000
|
+
overlay: !0,
|
|
3001
|
+
underlay: !0,
|
|
3002
|
+
dynamicPieces: !0
|
|
3003
|
+
}
|
|
3004
|
+
],
|
|
3005
|
+
n
|
|
3006
|
+
);
|
|
3007
|
+
await b.asyncHandler(r);
|
|
3008
|
+
}
|
|
3009
|
+
updateBoard(e) {
|
|
3010
|
+
e.square && (this.board[e.square.notation] = e);
|
|
3011
|
+
}
|
|
3012
|
+
setInternalRefVal(e, t) {
|
|
3013
|
+
this.internalRef[e] = t;
|
|
3014
|
+
}
|
|
3015
|
+
setInternalRefObj(e) {
|
|
3016
|
+
this.internalRef = e;
|
|
3017
|
+
}
|
|
3018
|
+
async setSelected(e, t) {
|
|
3019
|
+
if (e === null && this.selected === null) {
|
|
3020
|
+
this.selected = e;
|
|
3021
|
+
return;
|
|
3022
|
+
} else if (e?.id === this.selected?.id) {
|
|
3023
|
+
this.selected = e;
|
|
3024
|
+
return;
|
|
3025
|
+
} else if (!this.renderer.getLayerManager().isSelectionEnabled()) return;
|
|
3026
|
+
const r = this.renderer.getLayerManager();
|
|
3027
|
+
this.selected = e, r.drawEvent("onPointerSelect"), t || this.renderer.pipelineRender.setNextEvent("onRender", [
|
|
3028
|
+
{
|
|
3029
|
+
board: !1,
|
|
3030
|
+
staticPieces: !0,
|
|
3031
|
+
overlay: !0,
|
|
3032
|
+
underlay: !0,
|
|
3033
|
+
dynamicPieces: !0
|
|
3034
|
+
}
|
|
3035
|
+
]);
|
|
3036
|
+
}
|
|
3037
|
+
async setPieceHover(e, t) {
|
|
3038
|
+
const r = this.getPieceHover(), n = this.renderer.getLayerManager();
|
|
3039
|
+
r !== e && this.renderer.getLayerManager().isHoverEnabled() && (this.pieceHover = e, n.drawEvent("onPointerHover"), this.hoverConfig.scaling ? e === null && r !== null ? await n.togglePieceLayer(
|
|
3040
|
+
"dynamicPieces",
|
|
3041
|
+
"staticPieces",
|
|
3042
|
+
r,
|
|
3043
|
+
t
|
|
3044
|
+
) : r === null && e !== null ? await n.togglePieceLayer(
|
|
3045
|
+
"staticPieces",
|
|
3046
|
+
"dynamicPieces",
|
|
3047
|
+
e,
|
|
3048
|
+
t
|
|
3049
|
+
) : r !== null && e !== null && (await n.togglePieceLayer(
|
|
3050
|
+
"dynamicPieces",
|
|
3051
|
+
"staticPieces",
|
|
3052
|
+
r,
|
|
3053
|
+
t
|
|
3054
|
+
), await n.togglePieceLayer(
|
|
3055
|
+
"staticPieces",
|
|
3056
|
+
"dynamicPieces",
|
|
3057
|
+
e,
|
|
3058
|
+
t
|
|
3059
|
+
)) : t || this.renderer.pipelineRender.setNextEvent("onRender", [
|
|
3060
|
+
{
|
|
3061
|
+
board: !1,
|
|
3062
|
+
staticPieces: !0,
|
|
3063
|
+
overlay: !0,
|
|
3064
|
+
underlay: !0,
|
|
3065
|
+
dynamicPieces: !0
|
|
3066
|
+
}
|
|
3067
|
+
]));
|
|
3068
|
+
}
|
|
3069
|
+
async setBlackView(e) {
|
|
3070
|
+
this.getIsBlackView() !== e && (this.args.isBlackView = e, this.setInternalRefObj({}), this.getCanvasLayers().clearAllRect(), this.renderer.getLayerManager().resetAllLayers(), await this.refreshCanvases({
|
|
3071
|
+
board: !0,
|
|
3072
|
+
staticPieces: !0,
|
|
3073
|
+
overlay: !0,
|
|
3074
|
+
underlay: !0,
|
|
3075
|
+
dynamicPieces: !0
|
|
3076
|
+
}));
|
|
3077
|
+
}
|
|
3078
|
+
deleteIntervalRefVal(e) {
|
|
3079
|
+
delete this.internalRef[e];
|
|
3080
|
+
}
|
|
3081
|
+
async loadImages() {
|
|
3082
|
+
this.destroyed || !this.isImagesLoaded && this.args.pieceStyle && (await this.helpers.pieceHelper.preloadImages(this.args.pieceStyle), this.isImagesLoaded = !0);
|
|
3083
|
+
}
|
|
3084
|
+
async init() {
|
|
3085
|
+
return await new Promise(requestAnimationFrame), await this.initPieceImages(), await this.initInternalRef(), new Promise((e) => {
|
|
3086
|
+
this.renderer.pipelineRender.setNextEvent(
|
|
3087
|
+
"onRender",
|
|
3088
|
+
[
|
|
3089
|
+
{
|
|
3090
|
+
board: !0,
|
|
3091
|
+
staticPieces: !0,
|
|
3092
|
+
overlay: !0,
|
|
3093
|
+
underlay: !0,
|
|
3094
|
+
dynamicPieces: !0
|
|
3095
|
+
}
|
|
3096
|
+
],
|
|
3097
|
+
e
|
|
3098
|
+
);
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
async initPieceImages() {
|
|
3102
|
+
(!this.args || !this.args.pieceStyle) && (this.args.pieceStyle = this.helpers.pieceHelper.getPieceImages[this.args.pieceConfig?.type]), await this.loadImages();
|
|
3103
|
+
}
|
|
3104
|
+
async setPieceImages(e) {
|
|
3105
|
+
if (this.destroyed || this.args.pieceConfig.type === e || this.isMoving)
|
|
3106
|
+
return;
|
|
3107
|
+
!this.isImagesLoaded && e === "image" && await this.loadImages(), this.args.pieceConfig.type = e, this.args.pieceStyle = this.helpers.pieceHelper.getPieceImages[e];
|
|
3108
|
+
const t = this.renderer.getLayerManager();
|
|
3109
|
+
this.getCanvasLayers().clearAllRect({
|
|
3110
|
+
board: !1,
|
|
3111
|
+
staticPieces: !0,
|
|
3112
|
+
overlay: !0,
|
|
3113
|
+
underlay: !0,
|
|
3114
|
+
dynamicPieces: !0
|
|
3115
|
+
}), t.getLayer("staticPieces").redrawPieces(), t.getLayer("dynamicPieces").redrawPieces(), await this.refreshCanvases({
|
|
3116
|
+
board: !1,
|
|
3117
|
+
staticPieces: !0,
|
|
3118
|
+
overlay: !0,
|
|
3119
|
+
underlay: !0,
|
|
3120
|
+
dynamicPieces: !0
|
|
3121
|
+
});
|
|
3122
|
+
}
|
|
3123
|
+
async updateBoardState(e, t) {
|
|
3124
|
+
const r = this.renderer.getLayerManager(), n = e, i = [];
|
|
3125
|
+
for (const s of n) {
|
|
3126
|
+
const { from: a, to: o, promotion: c, captured: u } = s;
|
|
3127
|
+
let h = this.board[s.from];
|
|
3128
|
+
const y = {
|
|
3129
|
+
from: o,
|
|
3130
|
+
to: a,
|
|
3131
|
+
captured: [],
|
|
3132
|
+
moved: h.type,
|
|
3133
|
+
promoted: !!c
|
|
3134
|
+
}, f = {
|
|
3135
|
+
file: s.to.charAt(0),
|
|
3136
|
+
rank: parseInt(s.to.charAt(1)),
|
|
3137
|
+
notation: s.to
|
|
3138
|
+
};
|
|
3139
|
+
if (c) {
|
|
3140
|
+
const P = `${h.type[0]}${c.toUpperCase()}`, v = this.inactivePiecesPool[P].shift();
|
|
3141
|
+
if (v) {
|
|
3142
|
+
const C = this.piecesBoard.get(v);
|
|
3143
|
+
if (C) {
|
|
3144
|
+
const p = {
|
|
3145
|
+
square: t ? h.square : f,
|
|
3146
|
+
type: P,
|
|
3147
|
+
x: this.getInternalRefVal(h.id).x,
|
|
3148
|
+
y: this.getInternalRefVal(h.id).y
|
|
3149
|
+
};
|
|
3150
|
+
this.setInternalRefVal(v, p);
|
|
3151
|
+
const m = r.getLayer("staticPieces"), w = m.getCoords(h.id), R = b.squareToCoords(
|
|
3152
|
+
f,
|
|
3153
|
+
this.getSize() / 8,
|
|
3154
|
+
this.getIsBlackView()
|
|
3155
|
+
);
|
|
3156
|
+
h.square = null, C.square = f, this.piecesBoard.set(h.id, h), this.inactivePiecesPool[h.type].push(h.id), this.activePiecesPool[h.type].delete(s.from), this.activePiecesPool[P].set(s.to, C.id), this.piecesBoard.set(v, C), this.deleteIntervalRefVal(h.id), m.removeAll?.(h.id);
|
|
3157
|
+
const x = w || (R ? {
|
|
3158
|
+
x: R.x,
|
|
3159
|
+
y: R.y,
|
|
3160
|
+
w: this.getSize() / 8,
|
|
3161
|
+
h: this.getSize() / 8
|
|
3162
|
+
} : null);
|
|
3163
|
+
x && m.addAll?.(v, p, x, x), h = C;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
for (const P of u) {
|
|
3168
|
+
const v = this.board[P];
|
|
3169
|
+
if (v) {
|
|
3170
|
+
if (y.captured.push({
|
|
3171
|
+
square: P,
|
|
3172
|
+
type: v.type
|
|
3173
|
+
}), t && this.getDefaultAnimation() ? r.addDelayedPieceClear(h.id, v.id) : r.getLayer("staticPieces").removeAll?.(v.id), v.square) {
|
|
3174
|
+
const C = this.activePiecesPool[v.type].get(
|
|
3175
|
+
v.square.notation
|
|
3176
|
+
);
|
|
3177
|
+
this.helpers.pieceHelper.removeCache(P), this.activePiecesPool[v.type].delete(v.square.notation), C && this.inactivePiecesPool[v.type].push(C);
|
|
3178
|
+
const p = this.piecesBoard.get(v.id);
|
|
3179
|
+
p && (p.square = null);
|
|
3180
|
+
}
|
|
3181
|
+
this.deleteIntervalRefVal(v.id);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
c || (h.square = f, this.activePiecesPool[h.type].set(o, h.id), this.piecesBoard.set(h.id, h)), this.activePiecesPool[h.type].delete(a), this.board[o] = h, delete this.board[a];
|
|
3185
|
+
const g = this.getInternalRefVal(h.id);
|
|
3186
|
+
this.helpers.pieceHelper.updateCache(a, o, {
|
|
3187
|
+
id: h.id,
|
|
3188
|
+
piece: g
|
|
3189
|
+
}), i.push(y);
|
|
3190
|
+
}
|
|
3191
|
+
this.undoStack.push({ undo: i, redo: n }), await this.refreshCanvases({
|
|
3192
|
+
board: !1,
|
|
3193
|
+
staticPieces: !0,
|
|
3194
|
+
overlay: !0,
|
|
3195
|
+
underlay: !0,
|
|
3196
|
+
dynamicPieces: !0
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
async undo() {
|
|
3200
|
+
const e = this.undoStack.pop();
|
|
3201
|
+
if (!e) return !1;
|
|
3202
|
+
const t = this.renderer.getLayerManager();
|
|
3203
|
+
for (const r of e.undo) {
|
|
3204
|
+
const { from: n, to: i, moved: s, promoted: a, captured: o } = r;
|
|
3205
|
+
let c = this.board[r.from];
|
|
3206
|
+
const u = {
|
|
3207
|
+
file: r.to.charAt(0),
|
|
3208
|
+
rank: parseInt(r.to.charAt(1)),
|
|
3209
|
+
notation: r.to
|
|
3210
|
+
};
|
|
3211
|
+
if (a) {
|
|
3212
|
+
const y = s, f = this.inactivePiecesPool[y].shift();
|
|
3213
|
+
if (f) {
|
|
3214
|
+
const g = this.piecesBoard.get(f);
|
|
3215
|
+
if (g) {
|
|
3216
|
+
const P = {
|
|
3217
|
+
square: c.square,
|
|
3218
|
+
type: y,
|
|
3219
|
+
x: this.getInternalRefVal(c.id).x,
|
|
3220
|
+
y: this.getInternalRefVal(c.id).y
|
|
3221
|
+
};
|
|
3222
|
+
this.setInternalRefVal(f, P);
|
|
3223
|
+
const v = t.getLayer("staticPieces"), C = v.getCoords(c.id), p = b.squareToCoords(
|
|
3224
|
+
u,
|
|
3225
|
+
this.getSize() / 8,
|
|
3226
|
+
this.getIsBlackView()
|
|
3227
|
+
);
|
|
3228
|
+
c.square = null, g.square = u, this.piecesBoard.set(c.id, c), this.inactivePiecesPool[c.type].push(c.id), this.activePiecesPool[c.type].delete(r.from), this.activePiecesPool[y].set(r.to, g.id), this.piecesBoard.set(f, g), this.deleteIntervalRefVal(c.id), v.removeAll?.(c.id);
|
|
3229
|
+
const m = C || (p ? {
|
|
3230
|
+
x: p.x,
|
|
3231
|
+
y: p.y,
|
|
3232
|
+
w: this.getSize() / 8,
|
|
3233
|
+
h: this.getSize() / 8
|
|
3234
|
+
} : null);
|
|
3235
|
+
m && v.addAll?.(f, P, m, m), c = g;
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
a || (c.square = u, this.activePiecesPool[c.type].set(i, c.id), this.piecesBoard.set(c.id, c)), this.activePiecesPool[c.type].delete(n), this.board[i] = c, delete this.board[n];
|
|
3240
|
+
const h = this.getInternalRefVal(c.id);
|
|
3241
|
+
this.helpers.pieceHelper.updateCache(n, i, {
|
|
3242
|
+
id: c.id,
|
|
3243
|
+
piece: h
|
|
3244
|
+
});
|
|
3245
|
+
for (const y of o) {
|
|
3246
|
+
const { square: f, type: g } = y, P = {
|
|
3247
|
+
file: f.charAt(0),
|
|
3248
|
+
rank: parseInt(f.charAt(1)),
|
|
3249
|
+
notation: f
|
|
3250
|
+
}, v = this.inactivePiecesPool[g].shift();
|
|
3251
|
+
if (!v) continue;
|
|
3252
|
+
const C = this.piecesBoard.get(v);
|
|
3253
|
+
C && (C.square = P, this.activePiecesPool[C.type].set(f, C.id), this.piecesBoard.set(C.id, C), this.board[f] = C);
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
return this.redoStack.push([...e.redo]), await this.refreshCanvases({
|
|
3257
|
+
board: !1,
|
|
3258
|
+
staticPieces: !0,
|
|
3259
|
+
overlay: !0,
|
|
3260
|
+
underlay: !0,
|
|
3261
|
+
dynamicPieces: !0
|
|
3262
|
+
}), !0;
|
|
3263
|
+
}
|
|
3264
|
+
async redo() {
|
|
3265
|
+
const e = this.redoStack.pop();
|
|
3266
|
+
return e ? (await this.updateBoardState(e, !0), !0) : !1;
|
|
3267
|
+
}
|
|
3268
|
+
clearRedo() {
|
|
3269
|
+
this.redoStack = [];
|
|
3270
|
+
}
|
|
3271
|
+
clearUndo() {
|
|
3272
|
+
this.undoStack = [];
|
|
3273
|
+
}
|
|
3274
|
+
async initInternalRef() {
|
|
3275
|
+
const e = Math.floor(this.args.size / 8), t = Object.values(this.board), r = this.renderer.getLayerManager();
|
|
3276
|
+
this.renderer.getLayerManager().getLayer("staticPieces").clearPieces?.(t);
|
|
3277
|
+
for (const n of Object.values(this.board)) {
|
|
3278
|
+
const i = this.internalRef[n.id];
|
|
3279
|
+
if (i && i.square?.notation === n.square?.notation)
|
|
3280
|
+
continue;
|
|
3281
|
+
const s = n.square && b.squareToCoords(n.square, e, this.args.isBlackView);
|
|
3282
|
+
if (!s) continue;
|
|
3283
|
+
const a = s.x, o = s.y, c = {
|
|
3284
|
+
x: Math.floor(a),
|
|
3285
|
+
y: Math.floor(o),
|
|
3286
|
+
w: Math.ceil(e),
|
|
3287
|
+
h: Math.ceil(e)
|
|
3288
|
+
}, u = {
|
|
3289
|
+
square: n.square,
|
|
3290
|
+
type: n.type,
|
|
3291
|
+
x: a,
|
|
3292
|
+
y: o
|
|
3293
|
+
};
|
|
3294
|
+
if (this.setInternalRefVal(n.id, u), !i) {
|
|
3295
|
+
r.getLayer("staticPieces").addAll?.(n.id, u, c, c);
|
|
3296
|
+
continue;
|
|
3297
|
+
}
|
|
3298
|
+
if (n.square?.notation !== i.square?.notation)
|
|
3299
|
+
if (!this.getEvents()?.onDrawPiece && this.getDefaultAnimation() && (u.anim = !0, this.setIsMoving(!0)), r.getLayer("dynamicPieces").addAnimation({
|
|
3300
|
+
from: { x: i.x, y: i.y },
|
|
3301
|
+
to: { x: s.x, y: s.y },
|
|
3302
|
+
piece: u,
|
|
3303
|
+
start: performance.now(),
|
|
3304
|
+
id: n.id
|
|
3305
|
+
}), this.getDefaultAnimation())
|
|
3306
|
+
await r.togglePieceLayer(
|
|
3307
|
+
"staticPieces",
|
|
3308
|
+
"dynamicPieces",
|
|
3309
|
+
n.id,
|
|
3310
|
+
!0
|
|
3311
|
+
);
|
|
3312
|
+
else {
|
|
3313
|
+
const h = r.getLayer("staticPieces");
|
|
3314
|
+
h.removeAll?.(n.id), h.addAll?.(n.id, u, c, c);
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
this.deleteInternalRef(t);
|
|
3318
|
+
}
|
|
3319
|
+
deleteInternalRef(e) {
|
|
3320
|
+
const t = new Set(e.map((r) => r.id));
|
|
3321
|
+
for (const r in this.internalRef)
|
|
3322
|
+
t.has(r) || delete this.internalRef[r];
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
const ee = /* @__PURE__ */ new WeakMap();
|
|
3326
|
+
class Qe {
|
|
3327
|
+
destroyed = !1;
|
|
3328
|
+
fenStream = [];
|
|
3329
|
+
fenStreamDelay = 0;
|
|
3330
|
+
loading = !1;
|
|
3331
|
+
toFlip = !1;
|
|
3332
|
+
toChangeStreamDelay = null;
|
|
3333
|
+
currFlip = !1;
|
|
3334
|
+
pauseFenStream = !1;
|
|
3335
|
+
resizeStream = [];
|
|
3336
|
+
resizing = !1;
|
|
3337
|
+
toResize = !1;
|
|
3338
|
+
debugCountFenStream = 0;
|
|
3339
|
+
isSettingPieceType = !1;
|
|
3340
|
+
toSetPieceType = null;
|
|
3341
|
+
undoing = !1;
|
|
3342
|
+
redoing = !1;
|
|
3343
|
+
isMoving = !1;
|
|
3344
|
+
togglingPause = !1;
|
|
3345
|
+
cachedSize = null;
|
|
3346
|
+
mounted = !1;
|
|
3347
|
+
constructor(e) {
|
|
3348
|
+
ee.set(this, e);
|
|
3349
|
+
}
|
|
3350
|
+
destroy() {
|
|
3351
|
+
ee.delete(this);
|
|
3352
|
+
for (const e of Object.getOwnPropertyNames(this))
|
|
3353
|
+
this[e] = null;
|
|
3354
|
+
this.destroyed = !0;
|
|
3355
|
+
}
|
|
3356
|
+
mount(e) {
|
|
3357
|
+
this.mounted || (this.mounted = !0, e());
|
|
3358
|
+
}
|
|
3359
|
+
getRuntime() {
|
|
3360
|
+
if (this.destroyed) throw new Error("Client destroyed");
|
|
3361
|
+
const e = ee.get(this);
|
|
3362
|
+
if (!e) throw new Error("Runtime not found");
|
|
3363
|
+
return e;
|
|
3364
|
+
}
|
|
3365
|
+
getPieces() {
|
|
3366
|
+
return this.getRuntime()?.getReadonlyInternalRef();
|
|
3367
|
+
}
|
|
3368
|
+
async setBoard(e, t) {
|
|
3369
|
+
t && (this.clearFenStream(), this.pauseFenStream = !1), this.fenStream.push(e), this.loading || (await this.getRuntime()?.resetEvents(!0), this.loadPosition());
|
|
3370
|
+
}
|
|
3371
|
+
clearFenStream() {
|
|
3372
|
+
this.fenStream.splice(0, this.fenStream.length);
|
|
3373
|
+
}
|
|
3374
|
+
loadFenStream(e) {
|
|
3375
|
+
this.destroyed || (this.fenStream.push(...e), !this.loading && !this.pauseFenStream && this.loadPosition());
|
|
3376
|
+
}
|
|
3377
|
+
async loadPosition() {
|
|
3378
|
+
const e = this.getRuntime();
|
|
3379
|
+
if (this.loading || this.destroyed || !e) return;
|
|
3380
|
+
const t = e.getEventEmitter();
|
|
3381
|
+
this.loading = !0;
|
|
3382
|
+
try {
|
|
3383
|
+
for (; !this.pauseFenStream && !this.destroyed && this.fenStream.length; ) {
|
|
3384
|
+
const r = this.fenStream.shift();
|
|
3385
|
+
r && (await this.getRuntime()?.setBoardByFen(r), this.toFlip && (await this.getRuntime()?.setBlackView(
|
|
3386
|
+
!this.getRuntime().getIsBlackView()
|
|
3387
|
+
), this.toFlip = !1), this.toResize && (await this.sizeStream(), this.toResize = !1), this.toSetPieceType !== null && (await this.setPieceType(this.toSetPieceType, !0), this.toSetPieceType = null), this.fenStreamDelay > 0 && await this.delay(this.fenStreamDelay), this.toChangeStreamDelay !== null && (this.fenStreamDelay = this.toChangeStreamDelay, this.toChangeStreamDelay = null));
|
|
3388
|
+
}
|
|
3389
|
+
} finally {
|
|
3390
|
+
this.destroyed || (this.fenStream.length <= 0 && (this.debugCountFenStream = 0), this.loading = !1, this.fenStream.length && !this.pauseFenStream ? queueMicrotask(() => this.loadPosition()) : this.fenStream.length || t?.emit("onFenStreamLoaded"));
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
getIsLoadingFenStream() {
|
|
3394
|
+
return this.fenStream.length > 0;
|
|
3395
|
+
}
|
|
3396
|
+
setFenStreamDelay(e) {
|
|
3397
|
+
this.loading ? this.toChangeStreamDelay = e : this.fenStreamDelay = e;
|
|
3398
|
+
}
|
|
3399
|
+
delay(e) {
|
|
3400
|
+
return new Promise((t) => setTimeout(t, e));
|
|
3401
|
+
}
|
|
3402
|
+
async togglePause() {
|
|
3403
|
+
const e = this.getRuntime();
|
|
3404
|
+
if (!e || this.togglingPause) return this.pauseFenStream;
|
|
3405
|
+
try {
|
|
3406
|
+
return this.togglingPause = !0, this.pauseFenStream = !this.pauseFenStream, !this.pauseFenStream && !this.loading && (await e.resetEvents(!0), this.loadPosition()), !this.pauseFenStream;
|
|
3407
|
+
} finally {
|
|
3408
|
+
this.togglingPause = !1;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
getBoard() {
|
|
3412
|
+
return b.parseBoard(this.getRuntime().getBoard());
|
|
3413
|
+
}
|
|
3414
|
+
async flip() {
|
|
3415
|
+
!this.fenStream.length || this.pauseFenStream ? await this.getRuntime()?.setBlackView(
|
|
3416
|
+
!this.getRuntime().getIsBlackView()
|
|
3417
|
+
) : this.toFlip = !0, this.cachedSize = null;
|
|
3418
|
+
}
|
|
3419
|
+
updateSize(e) {
|
|
3420
|
+
if (this.resizeStream.push(e), !this.resizing) {
|
|
3421
|
+
if (this.loading) {
|
|
3422
|
+
this.toResize = !0;
|
|
3423
|
+
return;
|
|
3424
|
+
}
|
|
3425
|
+
this.sizeStream();
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
async sizeStream() {
|
|
3429
|
+
if (!this.resizing) {
|
|
3430
|
+
this.resizing = !0;
|
|
3431
|
+
try {
|
|
3432
|
+
for (; !this.destroyed && this.resizeStream.length; ) {
|
|
3433
|
+
const e = this.resizeStream.shift();
|
|
3434
|
+
if (e != null)
|
|
3435
|
+
try {
|
|
3436
|
+
await this.getRuntime?.().setSize(e);
|
|
3437
|
+
} catch (t) {
|
|
3438
|
+
console.error("Resize failed:", e, t);
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
} finally {
|
|
3442
|
+
if (this.destroyed) return;
|
|
3443
|
+
this.resizing = !1, this.cachedSize = null, this.resizeStream.length && queueMicrotask(() => this.sizeStream());
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
getPieceAt(e) {
|
|
3448
|
+
const t = this.getRuntime();
|
|
3449
|
+
if (!t) return null;
|
|
3450
|
+
const r = t.getInternalRefObj(), n = Object.entries(r).find(
|
|
3451
|
+
([a, o]) => o.square?.notation === e
|
|
3452
|
+
);
|
|
3453
|
+
if (!n) return null;
|
|
3454
|
+
const [i, s] = n;
|
|
3455
|
+
return { id: i, piece: s };
|
|
3456
|
+
}
|
|
3457
|
+
async undo() {
|
|
3458
|
+
const e = this.getRuntime();
|
|
3459
|
+
if (!e || this.undoing) return !1;
|
|
3460
|
+
this.undoing = !0;
|
|
3461
|
+
try {
|
|
3462
|
+
return await e.undo();
|
|
3463
|
+
} finally {
|
|
3464
|
+
this.undoing = !1;
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
async redo() {
|
|
3468
|
+
const e = this.getRuntime();
|
|
3469
|
+
if (!e || this.redoing) return !1;
|
|
3470
|
+
this.redoing = !0;
|
|
3471
|
+
try {
|
|
3472
|
+
return await e.redo();
|
|
3473
|
+
} finally {
|
|
3474
|
+
this.redoing = !1;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
getSquareCoords(e) {
|
|
3478
|
+
const t = this.getRuntime();
|
|
3479
|
+
if (!t) return null;
|
|
3480
|
+
const r = b.notationToSquare(e);
|
|
3481
|
+
if (!r) return null;
|
|
3482
|
+
const n = b.squareToCoords(
|
|
3483
|
+
r,
|
|
3484
|
+
t.getSize() / 8,
|
|
3485
|
+
t.getIsBlackView()
|
|
3486
|
+
);
|
|
3487
|
+
return n || null;
|
|
3488
|
+
}
|
|
3489
|
+
toggleHoverScaling() {
|
|
3490
|
+
const e = this.getRuntime();
|
|
3491
|
+
e && e.toggleHoverScaling();
|
|
3492
|
+
}
|
|
3493
|
+
toggleHoverScale(e) {
|
|
3494
|
+
const t = this.getRuntime();
|
|
3495
|
+
t && t.toggleHoverScale(e);
|
|
3496
|
+
}
|
|
3497
|
+
toggleHoverHighlight() {
|
|
3498
|
+
const e = this.getRuntime();
|
|
3499
|
+
e && e.toggleHoverHighlight();
|
|
3500
|
+
}
|
|
3501
|
+
getSize() {
|
|
3502
|
+
const e = this.getRuntime();
|
|
3503
|
+
if (!e) return null;
|
|
3504
|
+
if (this.cachedSize !== null) return this.cachedSize;
|
|
3505
|
+
const t = e.getSize(), r = { size: t, squareSize: t / 8 };
|
|
3506
|
+
return this.cachedSize = r, r;
|
|
3507
|
+
}
|
|
3508
|
+
async makeMove(e) {
|
|
3509
|
+
const t = this.getRuntime();
|
|
3510
|
+
if (!t || this.isMoving) return !1;
|
|
3511
|
+
this.isMoving = !0;
|
|
3512
|
+
try {
|
|
3513
|
+
return await t.resetEvents(!1), await t.updateBoardState(e, !0), !0;
|
|
3514
|
+
} finally {
|
|
3515
|
+
this.isMoving = !1;
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
async setPieceType(e, t) {
|
|
3519
|
+
const r = this.getRuntime();
|
|
3520
|
+
if (this.loading && !t) {
|
|
3521
|
+
this.toSetPieceType = e;
|
|
3522
|
+
return;
|
|
3523
|
+
}
|
|
3524
|
+
if (!(!r || this.isSettingPieceType || r.getIsMoving())) {
|
|
3525
|
+
this.isSettingPieceType = !0;
|
|
3526
|
+
try {
|
|
3527
|
+
await r.setPieceImages(e);
|
|
3528
|
+
} finally {
|
|
3529
|
+
this.isSettingPieceType = !1;
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
getEventEmitter() {
|
|
3534
|
+
const e = this.getRuntime();
|
|
3535
|
+
return e ? e.getEventEmitter() : null;
|
|
3536
|
+
}
|
|
3537
|
+
getPiecesImage() {
|
|
3538
|
+
const e = this.getRuntime();
|
|
3539
|
+
if (!e) return null;
|
|
3540
|
+
const t = e.getPieceStyle();
|
|
3541
|
+
return t || null;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
function Ue(d, e) {
|
|
3545
|
+
return {
|
|
3546
|
+
loadPosition: (t, r) => {
|
|
3547
|
+
d.current && d.current.setBoard(t, r);
|
|
3548
|
+
},
|
|
3549
|
+
flip: () => {
|
|
3550
|
+
d.current && d.current.flip();
|
|
3551
|
+
},
|
|
3552
|
+
getBoard: () => d.current ? d.current.getBoard() : null,
|
|
3553
|
+
getSquareCoords: (t) => d.current ? d.current.getSquareCoords(t) : null,
|
|
3554
|
+
togglePause: async () => d.current ? await d.current.togglePause() : null,
|
|
3555
|
+
loadFenStream: (t) => {
|
|
3556
|
+
d.current && d.current.loadFenStream(t);
|
|
3557
|
+
},
|
|
3558
|
+
setfenStreamDelay: (t) => {
|
|
3559
|
+
d.current && d.current.setFenStreamDelay(t);
|
|
3560
|
+
},
|
|
3561
|
+
updateSize: (t) => {
|
|
3562
|
+
d.current && d.current.updateSize(t);
|
|
3563
|
+
},
|
|
3564
|
+
getPieceAt: (t) => d.current ? d.current.getPieceAt(t) : null,
|
|
3565
|
+
setPieceType: (t) => {
|
|
3566
|
+
d.current && d.current.setPieceType(t);
|
|
3567
|
+
},
|
|
3568
|
+
undo: async () => d.current ? await d.current.undo() : !1,
|
|
3569
|
+
redo: async () => d.current ? await d.current.redo() : !1,
|
|
3570
|
+
toggleHoverScaling: () => {
|
|
3571
|
+
d.current && d.current.toggleHoverScaling();
|
|
3572
|
+
},
|
|
3573
|
+
toggleHoverScale: (t) => {
|
|
3574
|
+
d.current && d.current.toggleHoverScale(t);
|
|
3575
|
+
},
|
|
3576
|
+
toggleHoverHighlight: () => {
|
|
3577
|
+
d.current && d.current.toggleHoverHighlight();
|
|
3578
|
+
},
|
|
3579
|
+
getSize: () => d.current ? d.current.getSize() : null,
|
|
3580
|
+
makeMove: (t) => d.current ? d.current.makeMove(t) : !1,
|
|
3581
|
+
getEventEmitter: () => d.current ? d.current.getEventEmitter() : null,
|
|
3582
|
+
getPiecesImage: () => d.current ? d.current.getPiecesImage() : null,
|
|
3583
|
+
mount: (t) => {
|
|
3584
|
+
if (!d.current) {
|
|
3585
|
+
e.current = t ?? null;
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
d.current.mount(t), e.current = null;
|
|
3589
|
+
},
|
|
3590
|
+
getIsLoadingFenStream: () => d.current ? d.current.getIsLoadingFenStream() : null,
|
|
3591
|
+
flushPendingMount: () => {
|
|
3592
|
+
!d.current || e.current === null || d.current.mount(e.current);
|
|
3593
|
+
}
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
const Xe = oe.forwardRef(
|
|
3597
|
+
({ config: d, onMove: e, onUpdate: t }, r) => {
|
|
3598
|
+
const { pieceConfig: n, size: i } = d, s = O(null), a = O(null), o = O(null), c = O(null), u = O(null), h = O(null), y = O(null), f = O(null), g = le(
|
|
3599
|
+
() => Ue(y, f),
|
|
3600
|
+
[]
|
|
3601
|
+
), P = O(0);
|
|
3602
|
+
return ue(() => {
|
|
3603
|
+
let v = null, C = null;
|
|
3604
|
+
const p = ++P.current;
|
|
3605
|
+
if (s.current && a.current && o.current && c.current && u.current) {
|
|
3606
|
+
const m = {
|
|
3607
|
+
...d,
|
|
3608
|
+
size: Math.floor(i / 8) * 8,
|
|
3609
|
+
onMove: e,
|
|
3610
|
+
onUpdate: t,
|
|
3611
|
+
canvasLayers: new me(
|
|
3612
|
+
s,
|
|
3613
|
+
a,
|
|
3614
|
+
c,
|
|
3615
|
+
o,
|
|
3616
|
+
u,
|
|
3617
|
+
Math.floor(i / 8) * 8
|
|
3618
|
+
),
|
|
3619
|
+
pieceStyle: n.piecesImage,
|
|
3620
|
+
mode: "2d"
|
|
3621
|
+
};
|
|
3622
|
+
(async () => {
|
|
3623
|
+
const w = await te.create(m);
|
|
3624
|
+
if (P.current !== p) {
|
|
3625
|
+
w.destroy();
|
|
3626
|
+
return;
|
|
3627
|
+
}
|
|
3628
|
+
w.mount(), v = w, h.current = v, C = new Qe(v), y.current = C, g.flushPendingMount?.();
|
|
3629
|
+
})();
|
|
3630
|
+
}
|
|
3631
|
+
return () => {
|
|
3632
|
+
P.current++, v?.destroy(), C?.destroy(), v = null, C = null, h.current = null, y.current = null, f.current = null;
|
|
3633
|
+
};
|
|
3634
|
+
}, []), he(r, () => g), /* @__PURE__ */ H.jsx(
|
|
3635
|
+
ye,
|
|
3636
|
+
{
|
|
3637
|
+
boardRuntime: h,
|
|
3638
|
+
boardRef: s,
|
|
3639
|
+
staticPiecesRef: a,
|
|
3640
|
+
overlayRef: o,
|
|
3641
|
+
underlayRef: c,
|
|
3642
|
+
dynamicPiecesRef: u,
|
|
3643
|
+
size: Math.floor(i / 8) * 8
|
|
3644
|
+
}
|
|
3645
|
+
);
|
|
3646
|
+
}
|
|
3647
|
+
), Ke = {
|
|
3648
|
+
onPointerSelect: "onPointerSelect",
|
|
3649
|
+
onPointerHover: "onPointerHover",
|
|
3650
|
+
onPointerDragStart: "onPointerDragStart",
|
|
3651
|
+
onPointerDrag: "onPointerDrag",
|
|
3652
|
+
onPointerDrop: "onPointerDrop",
|
|
3653
|
+
onAnimationFrame: "onAnimationFrame",
|
|
3654
|
+
onDrawPiece: "onDrawPiece",
|
|
3655
|
+
onDrawBoard: "onDrawBoard",
|
|
3656
|
+
onDrawOverlay: "onDrawOverlay",
|
|
3657
|
+
onDrawUnderlay: "onDrawUnderlay"
|
|
3658
|
+
};
|
|
3659
|
+
export {
|
|
3660
|
+
Xe as Board,
|
|
3661
|
+
Ke as EVENTS,
|
|
3662
|
+
ae as pieceKey
|
|
3663
|
+
};
|
|
3664
|
+
//# sourceMappingURL=check-board.es.js.map
|