@naanouff/w3dts-chess 0.0.0-stage → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +18 -3
  2. package/dist/board/bookMoveSpline.d.ts +19 -0
  3. package/dist/board/bookMoveSpline.d.ts.map +1 -0
  4. package/dist/board/cemeterySlots.d.ts +14 -0
  5. package/dist/board/cemeterySlots.d.ts.map +1 -0
  6. package/dist/board/chessBoard.d.ts +36 -0
  7. package/dist/board/chessBoard.d.ts.map +1 -0
  8. package/dist/board/fileRankGlyph.d.ts +12 -0
  9. package/dist/board/fileRankGlyph.d.ts.map +1 -0
  10. package/dist/board/fileRankLabels.d.ts +33 -0
  11. package/dist/board/fileRankLabels.d.ts.map +1 -0
  12. package/dist/board/pieceTravel.d.ts +8 -0
  13. package/dist/board/pieceTravel.d.ts.map +1 -0
  14. package/dist/ecs/ChessPieceComponent.d.ts +14 -0
  15. package/dist/ecs/ChessPieceComponent.d.ts.map +1 -0
  16. package/dist/geometry/boardBody.d.ts +12 -0
  17. package/dist/geometry/boardBody.d.ts.map +1 -0
  18. package/dist/geometry/cylindricalPieceUv.d.ts +7 -0
  19. package/dist/geometry/cylindricalPieceUv.d.ts.map +1 -0
  20. package/dist/geometry/meshBuilder.d.ts +32 -0
  21. package/dist/geometry/meshBuilder.d.ts.map +1 -0
  22. package/dist/geometry/pieceColliders.d.ts +10 -0
  23. package/dist/geometry/pieceColliders.d.ts.map +1 -0
  24. package/dist/geometry/stauntonPieces.d.ts +11 -0
  25. package/dist/geometry/stauntonPieces.d.ts.map +1 -0
  26. package/dist/geometry/stauntonProfiles.d.ts +25 -0
  27. package/dist/geometry/stauntonProfiles.d.ts.map +1 -0
  28. package/dist/gproc/chessBoardGraph.d.ts +4 -0
  29. package/dist/gproc/chessBoardGraph.d.ts.map +1 -0
  30. package/dist/gproc/chessPieceGraphs.d.ts +11 -0
  31. package/dist/gproc/chessPieceGraphs.d.ts.map +1 -0
  32. package/dist/gproc/executeChessGProc.d.ts +7 -0
  33. package/dist/gproc/executeChessGProc.d.ts.map +1 -0
  34. package/dist/grab/MouseGrabController.d.ts +27 -0
  35. package/dist/grab/MouseGrabController.d.ts.map +1 -0
  36. package/dist/grab/grabMath.d.ts +28 -0
  37. package/dist/grab/grabMath.d.ts.map +1 -0
  38. package/dist/grab/pickRay.d.ts +20 -0
  39. package/dist/grab/pickRay.d.ts.map +1 -0
  40. package/dist/index.d.ts +53 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/learn/OpeningTrainer.d.ts +28 -0
  43. package/dist/learn/OpeningTrainer.d.ts.map +1 -0
  44. package/dist/learn/ecoOpenings.d.ts +18 -0
  45. package/dist/learn/ecoOpenings.d.ts.map +1 -0
  46. package/dist/look/chessAlbedo.d.ts +23 -0
  47. package/dist/look/chessAlbedo.d.ts.map +1 -0
  48. package/dist/look/chessProceduralShaderGraphs.d.ts +6 -0
  49. package/dist/look/chessProceduralShaderGraphs.d.ts.map +1 -0
  50. package/dist/net/chessWire.d.ts +30 -0
  51. package/dist/net/chessWire.d.ts.map +1 -0
  52. package/dist/physics/chessGroups.d.ts +14 -0
  53. package/dist/physics/chessGroups.d.ts.map +1 -0
  54. package/dist/physics/piecePose.d.ts +8 -0
  55. package/dist/physics/piecePose.d.ts.map +1 -0
  56. package/dist/play/chessHudState.d.ts +69 -0
  57. package/dist/play/chessHudState.d.ts.map +1 -0
  58. package/dist/play/chessTableSfx.d.ts +19 -0
  59. package/dist/play/chessTableSfx.d.ts.map +1 -0
  60. package/dist/play/parseChessDemoQuery.d.ts +17 -0
  61. package/dist/play/parseChessDemoQuery.d.ts.map +1 -0
  62. package/dist/rules/ChessMatch.d.ts +37 -0
  63. package/dist/rules/ChessMatch.d.ts.map +1 -0
  64. package/dist/rules/HeuristicChessEngine.d.ts +15 -0
  65. package/dist/rules/HeuristicChessEngine.d.ts.map +1 -0
  66. package/dist/rules/IChessEngine.d.ts +12 -0
  67. package/dist/rules/IChessEngine.d.ts.map +1 -0
  68. package/dist/rules/chessTypes.d.ts +37 -0
  69. package/dist/rules/chessTypes.d.ts.map +1 -0
  70. package/dist/scene/chessSceneExtension.d.ts +30 -0
  71. package/dist/scene/chessSceneExtension.d.ts.map +1 -0
  72. package/dist/w3dts-chess.es.js +3662 -0
  73. package/dist/w3dts-chess.umd.js +1 -0
  74. package/package.json +44 -3
@@ -0,0 +1,3662 @@
1
+ var Ao = Object.defineProperty;
2
+ var xo = (e, t, o) => t in e ? Ao(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var F = (e, t, o) => xo(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { vec3 as M, quat as gt, mat4 as G, vec4 as Z, mat3 as Ae } from "gl-matrix";
5
+ import { Mesh as Lt, STANDARD_MESH_VERTEX_FLOATS as me, TransformComponent as Dt } from "@naanouff/w3dts-core";
6
+ import { meshToGeometrySet as Po, bakeMeshMapsOnGeometrySet as Ro, geometrySetToEngineMesh as ro, engineMeshToPreviewBuffers as so, GProcExecutor as Oo, bootstrapGProcRuntime as To } from "@naanouff/w3dts-gproc";
7
+ import { ColliderComponent as xe, RigidBodyComponent as Pe, JointComponent as $t } from "@naanouff/w3dts-physics";
8
+ class io {
9
+ unwrap(t, o) {
10
+ const n = this._chain((r) => v.ok(t ? t(r) : r), (r) => o ? v.ok(o(r)) : v.err(r));
11
+ if (n.isErr) throw n.error;
12
+ return n.value;
13
+ }
14
+ map(t, o) {
15
+ return this._chain((n) => v.ok(t(n)), (n) => v.err(o ? o(n) : n));
16
+ }
17
+ chain(t, o) {
18
+ return this._chain(t, o || ((n) => v.err(n)));
19
+ }
20
+ }
21
+ class No extends io {
22
+ constructor(t) {
23
+ super(), this.value = void 0, this.isOk = !0, this.isErr = !1, this.value = t;
24
+ }
25
+ _chain(t, o) {
26
+ return t(this.value);
27
+ }
28
+ }
29
+ class Io extends io {
30
+ constructor(t) {
31
+ super(), this.error = void 0, this.isOk = !1, this.isErr = !0, this.error = t;
32
+ }
33
+ _chain(t, o) {
34
+ return o(this.error);
35
+ }
36
+ }
37
+ var v;
38
+ (function(e) {
39
+ e.ok = function(t) {
40
+ return new No(t);
41
+ }, e.err = function(t) {
42
+ return new Io(t || new Error());
43
+ }, e.all = function(t) {
44
+ if (Array.isArray(t)) {
45
+ const r = [];
46
+ for (let s = 0; s < t.length; s++) {
47
+ const i = t[s];
48
+ if (i.isErr) return i;
49
+ r.push(i.value);
50
+ }
51
+ return e.ok(r);
52
+ }
53
+ const o = {}, n = Object.keys(t);
54
+ for (let r = 0; r < n.length; r++) {
55
+ const s = t[n[r]];
56
+ if (s.isErr) return s;
57
+ o[n[r]] = s.value;
58
+ }
59
+ return e.ok(o);
60
+ };
61
+ })(v || (v = {}));
62
+ const Re = (e) => (e = e - (e >>> 1 & 1431655765), e = (e & 858993459) + (e >>> 2 & 858993459), Math.imul(e + (e >>> 4) & 252645135, 16843009) >> 24), re = (e) => (e = e >>> 8 & 16711935 | (e & 16711935) << 8, e >>> 16 & 65535 | (e & 65535) << 16), Oe = (e) => (e = e >>> 1 & 1431655765 | (e & 1431655765) << 1, e = e >>> 2 & 858993459 | (e & 858993459) << 2, e = e >>> 4 & 252645135 | (e & 252645135) << 4, re(e));
63
+ class d {
64
+ constructor(t, o) {
65
+ this.lo = t | 0, this.hi = o | 0;
66
+ }
67
+ static fromSquare(t) {
68
+ return t >= 32 ? new d(0, 1 << t - 32) : new d(1 << t, 0);
69
+ }
70
+ static fromRank(t) {
71
+ return new d(255, 0).shl64(8 * t);
72
+ }
73
+ static fromFile(t) {
74
+ return new d(16843009 << t, 16843009 << t);
75
+ }
76
+ static empty() {
77
+ return new d(0, 0);
78
+ }
79
+ static full() {
80
+ return new d(4294967295, 4294967295);
81
+ }
82
+ static corners() {
83
+ return new d(129, 2164260864);
84
+ }
85
+ static center() {
86
+ return new d(402653184, 24);
87
+ }
88
+ static backranks() {
89
+ return new d(255, 4278190080);
90
+ }
91
+ static backrank(t) {
92
+ return t === "white" ? new d(255, 0) : new d(0, 4278190080);
93
+ }
94
+ static lightSquares() {
95
+ return new d(1437226410, 1437226410);
96
+ }
97
+ static darkSquares() {
98
+ return new d(2857740885, 2857740885);
99
+ }
100
+ complement() {
101
+ return new d(~this.lo, ~this.hi);
102
+ }
103
+ xor(t) {
104
+ return new d(this.lo ^ t.lo, this.hi ^ t.hi);
105
+ }
106
+ union(t) {
107
+ return new d(this.lo | t.lo, this.hi | t.hi);
108
+ }
109
+ intersect(t) {
110
+ return new d(this.lo & t.lo, this.hi & t.hi);
111
+ }
112
+ diff(t) {
113
+ return new d(this.lo & ~t.lo, this.hi & ~t.hi);
114
+ }
115
+ intersects(t) {
116
+ return this.intersect(t).nonEmpty();
117
+ }
118
+ isDisjoint(t) {
119
+ return this.intersect(t).isEmpty();
120
+ }
121
+ supersetOf(t) {
122
+ return t.diff(this).isEmpty();
123
+ }
124
+ subsetOf(t) {
125
+ return this.diff(t).isEmpty();
126
+ }
127
+ shr64(t) {
128
+ return t >= 64 ? d.empty() : t >= 32 ? new d(this.hi >>> t - 32, 0) : t > 0 ? new d(this.lo >>> t ^ this.hi << 32 - t, this.hi >>> t) : this;
129
+ }
130
+ shl64(t) {
131
+ return t >= 64 ? d.empty() : t >= 32 ? new d(0, this.lo << t - 32) : t > 0 ? new d(this.lo << t, this.hi << t ^ this.lo >>> 32 - t) : this;
132
+ }
133
+ bswap64() {
134
+ return new d(re(this.hi), re(this.lo));
135
+ }
136
+ rbit64() {
137
+ return new d(Oe(this.hi), Oe(this.lo));
138
+ }
139
+ minus64(t) {
140
+ const o = this.lo - t.lo, n = (o & t.lo & 1) + (t.lo >>> 1) + (o >>> 1) >>> 31;
141
+ return new d(o, this.hi - (t.hi + n));
142
+ }
143
+ equals(t) {
144
+ return this.lo === t.lo && this.hi === t.hi;
145
+ }
146
+ size() {
147
+ return Re(this.lo) + Re(this.hi);
148
+ }
149
+ isEmpty() {
150
+ return this.lo === 0 && this.hi === 0;
151
+ }
152
+ nonEmpty() {
153
+ return this.lo !== 0 || this.hi !== 0;
154
+ }
155
+ has(t) {
156
+ return (t >= 32 ? this.hi & 1 << t - 32 : this.lo & 1 << t) !== 0;
157
+ }
158
+ set(t, o) {
159
+ return o ? this.with(t) : this.without(t);
160
+ }
161
+ with(t) {
162
+ return t >= 32 ? new d(this.lo, this.hi | 1 << t - 32) : new d(this.lo | 1 << t, this.hi);
163
+ }
164
+ without(t) {
165
+ return t >= 32 ? new d(this.lo, this.hi & ~(1 << t - 32)) : new d(this.lo & ~(1 << t), this.hi);
166
+ }
167
+ toggle(t) {
168
+ return t >= 32 ? new d(this.lo, this.hi ^ 1 << t - 32) : new d(this.lo ^ 1 << t, this.hi);
169
+ }
170
+ last() {
171
+ if (this.hi !== 0)
172
+ return 63 - Math.clz32(this.hi);
173
+ if (this.lo !== 0)
174
+ return 31 - Math.clz32(this.lo);
175
+ }
176
+ first() {
177
+ if (this.lo !== 0)
178
+ return 31 - Math.clz32(this.lo & -this.lo);
179
+ if (this.hi !== 0)
180
+ return 63 - Math.clz32(this.hi & -this.hi);
181
+ }
182
+ withoutFirst() {
183
+ return this.lo !== 0 ? new d(this.lo & this.lo - 1, this.hi) : new d(0, this.hi & this.hi - 1);
184
+ }
185
+ moreThanOne() {
186
+ return this.hi !== 0 && this.lo !== 0 || (this.lo & this.lo - 1) !== 0 || (this.hi & this.hi - 1) !== 0;
187
+ }
188
+ singleSquare() {
189
+ return this.moreThanOne() ? void 0 : this.last();
190
+ }
191
+ *[Symbol.iterator]() {
192
+ let t = this.lo, o = this.hi;
193
+ for (; t !== 0; ) {
194
+ const n = 31 - Math.clz32(t & -t);
195
+ t ^= 1 << n, yield n;
196
+ }
197
+ for (; o !== 0; ) {
198
+ const n = 31 - Math.clz32(o & -o);
199
+ o ^= 1 << n, yield 32 + n;
200
+ }
201
+ }
202
+ *reversed() {
203
+ let t = this.lo, o = this.hi;
204
+ for (; o !== 0; ) {
205
+ const n = 31 - Math.clz32(o);
206
+ o ^= 1 << n, yield 32 + n;
207
+ }
208
+ for (; t !== 0; ) {
209
+ const n = 31 - Math.clz32(t);
210
+ t ^= 1 << n, yield n;
211
+ }
212
+ }
213
+ }
214
+ const Rt = ["a", "b", "c", "d", "e", "f", "g", "h"], ao = ["1", "2", "3", "4", "5", "6", "7", "8"], st = ["white", "black"], V = ["pawn", "knight", "bishop", "rook", "queen", "king"], Bo = ["a", "h"], Ot = (e) => "role" in e, C = (e) => e !== void 0, B = (e) => e === "white" ? "black" : "white", it = (e) => e >> 3, L = (e) => e & 7, se = (e, t) => 0 <= e && e < 8 && 0 <= t && t < 8 ? e + 8 * t : void 0, bt = (e) => {
215
+ switch (e) {
216
+ case "pawn":
217
+ return "p";
218
+ case "knight":
219
+ return "n";
220
+ case "bishop":
221
+ return "b";
222
+ case "rook":
223
+ return "r";
224
+ case "queen":
225
+ return "q";
226
+ case "king":
227
+ return "k";
228
+ }
229
+ };
230
+ function Fo(e) {
231
+ switch (e.toLowerCase()) {
232
+ case "p":
233
+ return "pawn";
234
+ case "n":
235
+ return "knight";
236
+ case "b":
237
+ return "bishop";
238
+ case "r":
239
+ return "rook";
240
+ case "q":
241
+ return "queen";
242
+ case "k":
243
+ return "king";
244
+ default:
245
+ return;
246
+ }
247
+ }
248
+ function ft(e) {
249
+ if (e.length === 2)
250
+ return se(e.charCodeAt(0) - 97, e.charCodeAt(1) - 49);
251
+ }
252
+ const Tt = (e) => Rt[L(e)] + ao[it(e)], ge = (e, t) => e === "white" ? t === "a" ? 2 : 6 : t === "a" ? 58 : 62, ye = (e, t) => e === "white" ? t === "a" ? 3 : 5 : t === "a" ? 59 : 61, Nt = (e, t) => {
253
+ let o = d.empty();
254
+ for (const n of t) {
255
+ const r = e + n;
256
+ 0 <= r && r < 64 && Math.abs(L(e) - L(r)) <= 2 && (o = o.with(r));
257
+ }
258
+ return o;
259
+ }, J = (e) => {
260
+ const t = [];
261
+ for (let o = 0; o < 64; o++)
262
+ t[o] = e(o);
263
+ return t;
264
+ }, Lo = J((e) => Nt(e, [-9, -8, -7, -1, 1, 7, 8, 9])), Go = J((e) => Nt(e, [-17, -15, -10, -6, 6, 10, 15, 17])), Ho = {
265
+ white: J((e) => Nt(e, [7, 9])),
266
+ black: J((e) => Nt(e, [-7, -9]))
267
+ }, be = (e) => Lo[e], ke = (e) => Go[e], Gt = (e, t) => Ho[e][t], ie = J((e) => d.fromFile(L(e)).without(e)), ae = J((e) => d.fromRank(it(e)).without(e)), ce = J((e) => {
268
+ const t = new d(134480385, 2151686160), o = 8 * (it(e) - L(e));
269
+ return (o >= 0 ? t.shl64(o) : t.shr64(-o)).without(e);
270
+ }), ue = J((e) => {
271
+ const t = new d(270549120, 16909320), o = 8 * (it(e) + L(e) - 7);
272
+ return (o >= 0 ? t.shl64(o) : t.shr64(-o)).without(e);
273
+ }), le = (e, t, o) => {
274
+ let n = o.intersect(t), r = n.bswap64();
275
+ return n = n.minus64(e), r = r.minus64(e.bswap64()), n.xor(r.bswap64()).intersect(t);
276
+ }, Vo = (e, t) => le(d.fromSquare(e), ie[e], t), Do = (e, t) => {
277
+ const o = ae[e];
278
+ let n = t.intersect(o), r = n.rbit64();
279
+ return n = n.minus64(d.fromSquare(e)), r = r.minus64(d.fromSquare(63 - e)), n.xor(r.rbit64()).intersect(o);
280
+ }, _t = (e, t) => {
281
+ const o = d.fromSquare(e);
282
+ return le(o, ce[e], t).xor(le(o, ue[e], t));
283
+ }, wt = (e, t) => Vo(e, t).xor(Do(e, t)), co = (e, t) => _t(e, t).xor(wt(e, t)), uo = (e, t) => {
284
+ const o = d.fromSquare(t);
285
+ return ae[e].intersects(o) ? ae[e].with(e) : ue[e].intersects(o) ? ue[e].with(e) : ce[e].intersects(o) ? ce[e].with(e) : ie[e].intersects(o) ? ie[e].with(e) : d.empty();
286
+ }, vt = (e, t) => uo(e, t).intersect(d.full().shl64(e).xor(d.full().shl64(t))).withoutFirst();
287
+ class dt {
288
+ constructor() {
289
+ }
290
+ static default() {
291
+ const t = new dt();
292
+ return t.reset(), t;
293
+ }
294
+ /**
295
+ * Resets all pieces to the default starting position for standard chess.
296
+ */
297
+ reset() {
298
+ this.occupied = new d(65535, 4294901760), this.promoted = d.empty(), this.white = new d(65535, 0), this.black = new d(0, 4294901760), this.pawn = new d(65280, 16711680), this.knight = new d(66, 1107296256), this.bishop = new d(36, 603979776), this.rook = new d(129, 2164260864), this.queen = new d(8, 134217728), this.king = new d(16, 268435456);
299
+ }
300
+ static empty() {
301
+ const t = new dt();
302
+ return t.clear(), t;
303
+ }
304
+ clear() {
305
+ this.occupied = d.empty(), this.promoted = d.empty();
306
+ for (const t of st)
307
+ this[t] = d.empty();
308
+ for (const t of V)
309
+ this[t] = d.empty();
310
+ }
311
+ clone() {
312
+ const t = new dt();
313
+ t.occupied = this.occupied, t.promoted = this.promoted;
314
+ for (const o of st)
315
+ t[o] = this[o];
316
+ for (const o of V)
317
+ t[o] = this[o];
318
+ return t;
319
+ }
320
+ getColor(t) {
321
+ if (this.white.has(t))
322
+ return "white";
323
+ if (this.black.has(t))
324
+ return "black";
325
+ }
326
+ getRole(t) {
327
+ for (const o of V)
328
+ if (this[o].has(t))
329
+ return o;
330
+ }
331
+ get(t) {
332
+ const o = this.getColor(t);
333
+ if (!o)
334
+ return;
335
+ const n = this.getRole(t), r = this.promoted.has(t);
336
+ return { color: o, role: n, promoted: r };
337
+ }
338
+ /**
339
+ * Removes and returns the piece from the given `square`, if any.
340
+ */
341
+ take(t) {
342
+ const o = this.get(t);
343
+ return o && (this.occupied = this.occupied.without(t), this[o.color] = this[o.color].without(t), this[o.role] = this[o.role].without(t), o.promoted && (this.promoted = this.promoted.without(t))), o;
344
+ }
345
+ /**
346
+ * Put `piece` onto `square`, potentially replacing an existing piece.
347
+ * Returns the existing piece, if any.
348
+ */
349
+ set(t, o) {
350
+ const n = this.take(t);
351
+ return this.occupied = this.occupied.with(t), this[o.color] = this[o.color].with(t), this[o.role] = this[o.role].with(t), o.promoted && (this.promoted = this.promoted.with(t)), n;
352
+ }
353
+ has(t) {
354
+ return this.occupied.has(t);
355
+ }
356
+ *[Symbol.iterator]() {
357
+ for (const t of this.occupied)
358
+ yield [t, this.get(t)];
359
+ }
360
+ pieces(t, o) {
361
+ return this[t].intersect(this[o]);
362
+ }
363
+ rooksAndQueens() {
364
+ return this.rook.union(this.queen);
365
+ }
366
+ bishopsAndQueens() {
367
+ return this.bishop.union(this.queen);
368
+ }
369
+ /**
370
+ * Finds the unique king of the given `color`, if any.
371
+ */
372
+ kingOf(t) {
373
+ return this.pieces(t, "king").singleSquare();
374
+ }
375
+ }
376
+ var Y;
377
+ (function(e) {
378
+ e.Empty = "ERR_EMPTY", e.OppositeCheck = "ERR_OPPOSITE_CHECK", e.PawnsOnBackrank = "ERR_PAWNS_ON_BACKRANK", e.Kings = "ERR_KINGS", e.Variant = "ERR_VARIANT";
379
+ })(Y || (Y = {}));
380
+ class ut extends Error {
381
+ }
382
+ const $o = (e, t, o, n) => o[t].intersect(wt(e, n).intersect(o.rooksAndQueens()).union(_t(e, n).intersect(o.bishopsAndQueens())).union(ke(e).intersect(o.knight)).union(be(e).intersect(o.king)).union(Gt(B(t), e).intersect(o.pawn)));
383
+ class et {
384
+ constructor() {
385
+ }
386
+ static default() {
387
+ const t = new et();
388
+ return t.castlingRights = d.corners(), t.rook = {
389
+ white: { a: 0, h: 7 },
390
+ black: { a: 56, h: 63 }
391
+ }, t.path = {
392
+ white: { a: new d(14, 0), h: new d(96, 0) },
393
+ black: { a: new d(0, 234881024), h: new d(0, 1610612736) }
394
+ }, t;
395
+ }
396
+ static empty() {
397
+ const t = new et();
398
+ return t.castlingRights = d.empty(), t.rook = {
399
+ white: { a: void 0, h: void 0 },
400
+ black: { a: void 0, h: void 0 }
401
+ }, t.path = {
402
+ white: { a: d.empty(), h: d.empty() },
403
+ black: { a: d.empty(), h: d.empty() }
404
+ }, t;
405
+ }
406
+ clone() {
407
+ const t = new et();
408
+ return t.castlingRights = this.castlingRights, t.rook = {
409
+ white: { a: this.rook.white.a, h: this.rook.white.h },
410
+ black: { a: this.rook.black.a, h: this.rook.black.h }
411
+ }, t.path = {
412
+ white: { a: this.path.white.a, h: this.path.white.h },
413
+ black: { a: this.path.black.a, h: this.path.black.h }
414
+ }, t;
415
+ }
416
+ add(t, o, n, r) {
417
+ const s = ge(t, o), i = ye(t, o);
418
+ this.castlingRights = this.castlingRights.with(r), this.rook[t][o] = r, this.path[t][o] = vt(r, i).with(i).union(vt(n, s).with(s)).without(n).without(r);
419
+ }
420
+ static fromSetup(t) {
421
+ const o = et.empty(), n = t.castlingRights.intersect(t.board.rook);
422
+ for (const r of st) {
423
+ const s = d.backrank(r), i = t.board.kingOf(r);
424
+ if (!C(i) || !s.has(i))
425
+ continue;
426
+ const a = n.intersect(t.board[r]).intersect(s), p = a.first();
427
+ C(p) && p < i && o.add(r, "a", i, p);
428
+ const h = a.last();
429
+ C(h) && i < h && o.add(r, "h", i, h);
430
+ }
431
+ return o;
432
+ }
433
+ discardRook(t) {
434
+ if (this.castlingRights.has(t)) {
435
+ this.castlingRights = this.castlingRights.without(t);
436
+ for (const o of st)
437
+ for (const n of Bo)
438
+ this.rook[o][n] === t && (this.rook[o][n] = void 0);
439
+ }
440
+ }
441
+ discardColor(t) {
442
+ this.castlingRights = this.castlingRights.diff(d.backrank(t)), this.rook[t].a = void 0, this.rook[t].h = void 0;
443
+ }
444
+ }
445
+ class Uo {
446
+ constructor(t) {
447
+ this.rules = t;
448
+ }
449
+ reset() {
450
+ this.board = dt.default(), this.pockets = void 0, this.turn = "white", this.castles = et.default(), this.epSquare = void 0, this.remainingChecks = void 0, this.halfmoves = 0, this.fullmoves = 1;
451
+ }
452
+ setupUnchecked(t) {
453
+ this.board = t.board.clone(), this.board.promoted = d.empty(), this.pockets = void 0, this.turn = t.turn, this.castles = et.fromSetup(t), this.epSquare = jo(this, t.epSquare), this.remainingChecks = void 0, this.halfmoves = t.halfmoves, this.fullmoves = t.fullmoves;
454
+ }
455
+ // When subclassing overwrite at least:
456
+ //
457
+ // - static default()
458
+ // - static fromSetup()
459
+ // - static clone()
460
+ //
461
+ // - dests()
462
+ // - isVariantEnd()
463
+ // - variantOutcome()
464
+ // - hasInsufficientMaterial()
465
+ // - isStandardMaterial()
466
+ kingAttackers(t, o, n) {
467
+ return $o(t, o, this.board, n);
468
+ }
469
+ playCaptureAt(t, o) {
470
+ this.halfmoves = 0, o.role === "rook" && this.castles.discardRook(t), this.pockets && this.pockets[B(o.color)][o.promoted ? "pawn" : o.role]++;
471
+ }
472
+ ctx() {
473
+ const t = this.isVariantEnd(), o = this.board.kingOf(this.turn);
474
+ if (!C(o))
475
+ return { king: o, blockers: d.empty(), checkers: d.empty(), variantEnd: t, mustCapture: !1 };
476
+ const n = wt(o, d.empty()).intersect(this.board.rooksAndQueens()).union(_t(o, d.empty()).intersect(this.board.bishopsAndQueens())).intersect(this.board[B(this.turn)]);
477
+ let r = d.empty();
478
+ for (const i of n) {
479
+ const a = vt(o, i).intersect(this.board.occupied);
480
+ a.moreThanOne() || (r = r.union(a));
481
+ }
482
+ const s = this.kingAttackers(o, B(this.turn), this.board.occupied);
483
+ return {
484
+ king: o,
485
+ blockers: r,
486
+ checkers: s,
487
+ variantEnd: t,
488
+ mustCapture: !1
489
+ };
490
+ }
491
+ clone() {
492
+ var t, o;
493
+ const n = new this.constructor();
494
+ return n.board = this.board.clone(), n.pockets = (t = this.pockets) === null || t === void 0 ? void 0 : t.clone(), n.turn = this.turn, n.castles = this.castles.clone(), n.epSquare = this.epSquare, n.remainingChecks = (o = this.remainingChecks) === null || o === void 0 ? void 0 : o.clone(), n.halfmoves = this.halfmoves, n.fullmoves = this.fullmoves, n;
495
+ }
496
+ validate() {
497
+ if (this.board.occupied.isEmpty())
498
+ return v.err(new ut(Y.Empty));
499
+ if (this.board.king.size() !== 2)
500
+ return v.err(new ut(Y.Kings));
501
+ if (!C(this.board.kingOf(this.turn)))
502
+ return v.err(new ut(Y.Kings));
503
+ const t = this.board.kingOf(B(this.turn));
504
+ return C(t) ? this.kingAttackers(t, this.turn, this.board.occupied).nonEmpty() ? v.err(new ut(Y.OppositeCheck)) : d.backranks().intersects(this.board.pawn) ? v.err(new ut(Y.PawnsOnBackrank)) : v.ok(void 0) : v.err(new ut(Y.Kings));
505
+ }
506
+ dropDests(t) {
507
+ return d.empty();
508
+ }
509
+ dests(t, o) {
510
+ if (o = o || this.ctx(), o.variantEnd)
511
+ return d.empty();
512
+ const n = this.board.get(t);
513
+ if (!n || n.color !== this.turn)
514
+ return d.empty();
515
+ let r, s;
516
+ if (n.role === "pawn") {
517
+ r = Gt(this.turn, t).intersect(this.board[B(this.turn)]);
518
+ const i = this.turn === "white" ? 8 : -8, a = t + i;
519
+ if (0 <= a && a < 64 && !this.board.occupied.has(a)) {
520
+ r = r.with(a);
521
+ const p = this.turn === "white" ? t < 16 : t >= 48, h = a + i;
522
+ p && !this.board.occupied.has(h) && (r = r.with(h));
523
+ }
524
+ C(this.epSquare) && qo(this, t, o) && (s = d.fromSquare(this.epSquare));
525
+ } else n.role === "bishop" ? r = _t(t, this.board.occupied) : n.role === "knight" ? r = ke(t) : n.role === "rook" ? r = wt(t, this.board.occupied) : n.role === "queen" ? r = co(t, this.board.occupied) : r = be(t);
526
+ if (r = r.diff(this.board[this.turn]), C(o.king)) {
527
+ if (n.role === "king") {
528
+ const i = this.board.occupied.without(t);
529
+ for (const a of r)
530
+ this.kingAttackers(a, B(this.turn), i).nonEmpty() && (r = r.without(a));
531
+ return r.union(Te(this, "a", o)).union(Te(this, "h", o));
532
+ }
533
+ if (o.checkers.nonEmpty()) {
534
+ const i = o.checkers.singleSquare();
535
+ if (!C(i))
536
+ return d.empty();
537
+ r = r.intersect(vt(i, o.king).with(i));
538
+ }
539
+ o.blockers.has(t) && (r = r.intersect(uo(t, o.king)));
540
+ }
541
+ return s && (r = r.union(s)), r;
542
+ }
543
+ isVariantEnd() {
544
+ return !1;
545
+ }
546
+ variantOutcome(t) {
547
+ }
548
+ hasInsufficientMaterial(t) {
549
+ return this.board[t].intersect(this.board.pawn.union(this.board.rooksAndQueens())).nonEmpty() ? !1 : this.board[t].intersects(this.board.knight) ? this.board[t].size() <= 2 && this.board[B(t)].diff(this.board.king).diff(this.board.queen).isEmpty() : this.board[t].intersects(this.board.bishop) ? (!this.board.bishop.intersects(d.darkSquares()) || !this.board.bishop.intersects(d.lightSquares())) && this.board.pawn.isEmpty() && this.board.knight.isEmpty() : !0;
550
+ }
551
+ // The following should be identical in all subclasses
552
+ toSetup() {
553
+ var t, o;
554
+ return {
555
+ board: this.board.clone(),
556
+ pockets: (t = this.pockets) === null || t === void 0 ? void 0 : t.clone(),
557
+ turn: this.turn,
558
+ castlingRights: this.castles.castlingRights,
559
+ epSquare: Ko(this),
560
+ remainingChecks: (o = this.remainingChecks) === null || o === void 0 ? void 0 : o.clone(),
561
+ halfmoves: Math.min(this.halfmoves, 150),
562
+ fullmoves: Math.min(Math.max(this.fullmoves, 1), 9999)
563
+ };
564
+ }
565
+ isInsufficientMaterial() {
566
+ return st.every((t) => this.hasInsufficientMaterial(t));
567
+ }
568
+ hasDests(t) {
569
+ t = t || this.ctx();
570
+ for (const o of this.board[this.turn])
571
+ if (this.dests(o, t).nonEmpty())
572
+ return !0;
573
+ return this.dropDests(t).nonEmpty();
574
+ }
575
+ isLegal(t, o) {
576
+ if (Ot(t))
577
+ return !this.pockets || this.pockets[this.turn][t.role] <= 0 || t.role === "pawn" && d.backranks().has(t.to) ? !1 : this.dropDests(o).has(t.to);
578
+ {
579
+ if (t.promotion === "pawn" || t.promotion === "king" && this.rules !== "antichess" || !!t.promotion !== (this.board.pawn.has(t.from) && d.backranks().has(t.to)))
580
+ return !1;
581
+ const n = this.dests(t.from, o);
582
+ return n.has(t.to) || n.has(Wo(this, t).to);
583
+ }
584
+ }
585
+ isCheck() {
586
+ const t = this.board.kingOf(this.turn);
587
+ return C(t) && this.kingAttackers(t, B(this.turn), this.board.occupied).nonEmpty();
588
+ }
589
+ isEnd(t) {
590
+ return (t ? t.variantEnd : this.isVariantEnd()) ? !0 : this.isInsufficientMaterial() || !this.hasDests(t);
591
+ }
592
+ isCheckmate(t) {
593
+ return t = t || this.ctx(), !t.variantEnd && t.checkers.nonEmpty() && !this.hasDests(t);
594
+ }
595
+ isStalemate(t) {
596
+ return t = t || this.ctx(), !t.variantEnd && t.checkers.isEmpty() && !this.hasDests(t);
597
+ }
598
+ outcome(t) {
599
+ const o = this.variantOutcome(t);
600
+ return o || (t = t || this.ctx(), this.isCheckmate(t) ? { winner: B(this.turn) } : this.isInsufficientMaterial() || this.isStalemate(t) ? { winner: void 0 } : void 0);
601
+ }
602
+ allDests(t) {
603
+ t = t || this.ctx();
604
+ const o = /* @__PURE__ */ new Map();
605
+ if (t.variantEnd)
606
+ return o;
607
+ for (const n of this.board[this.turn])
608
+ o.set(n, this.dests(n, t));
609
+ return o;
610
+ }
611
+ play(t) {
612
+ const o = this.turn, n = this.epSquare, r = lo(this, t);
613
+ if (this.epSquare = void 0, this.halfmoves += 1, o === "black" && (this.fullmoves += 1), this.turn = B(o), Ot(t))
614
+ this.board.set(t.to, { role: t.role, color: o }), this.pockets && this.pockets[o][t.role]--, t.role === "pawn" && (this.halfmoves = 0);
615
+ else {
616
+ const s = this.board.take(t.from);
617
+ if (!s)
618
+ return;
619
+ let i;
620
+ if (s.role === "pawn") {
621
+ this.halfmoves = 0, t.to === n && (i = this.board.take(t.to + (o === "white" ? -8 : 8)));
622
+ const a = t.from - t.to;
623
+ Math.abs(a) === 16 && 8 <= t.from && t.from <= 55 && (this.epSquare = t.from + t.to >> 1), t.promotion && (s.role = t.promotion, s.promoted = !!this.pockets);
624
+ } else if (s.role === "rook")
625
+ this.castles.discardRook(t.from);
626
+ else if (s.role === "king") {
627
+ if (r) {
628
+ const a = this.castles.rook[o][r];
629
+ if (C(a)) {
630
+ const p = this.board.take(a);
631
+ this.board.set(ge(o, r), s), p && this.board.set(ye(o, r), p);
632
+ }
633
+ }
634
+ this.castles.discardColor(o);
635
+ }
636
+ if (!r) {
637
+ const a = this.board.set(t.to, s) || i;
638
+ a && this.playCaptureAt(t.to, a);
639
+ }
640
+ }
641
+ this.remainingChecks && this.isCheck() && (this.remainingChecks[o] = Math.max(this.remainingChecks[o] - 1, 0));
642
+ }
643
+ }
644
+ class Et extends Uo {
645
+ constructor() {
646
+ super("chess");
647
+ }
648
+ static default() {
649
+ const t = new this();
650
+ return t.reset(), t;
651
+ }
652
+ static fromSetup(t) {
653
+ const o = new this();
654
+ return o.setupUnchecked(t), o.validate().map((n) => o);
655
+ }
656
+ clone() {
657
+ return super.clone();
658
+ }
659
+ }
660
+ const jo = (e, t) => {
661
+ if (!C(t))
662
+ return;
663
+ const o = e.turn === "white" ? 5 : 2, n = e.turn === "white" ? 8 : -8;
664
+ if (it(t) !== o || e.board.occupied.has(t + n))
665
+ return;
666
+ const r = t - n;
667
+ if (!(!e.board.pawn.has(r) || !e.board[B(e.turn)].has(r)))
668
+ return t;
669
+ }, Ko = (e) => {
670
+ if (!C(e.epSquare))
671
+ return;
672
+ const t = e.ctx(), n = e.board.pieces(e.turn, "pawn").intersect(Gt(B(e.turn), e.epSquare));
673
+ for (const r of n)
674
+ if (e.dests(r, t).has(e.epSquare))
675
+ return e.epSquare;
676
+ }, qo = (e, t, o) => {
677
+ if (!C(e.epSquare) || !Gt(e.turn, t).has(e.epSquare))
678
+ return !1;
679
+ if (!C(o.king))
680
+ return !0;
681
+ const n = e.turn === "white" ? 8 : -8, r = e.epSquare - n;
682
+ return e.kingAttackers(o.king, B(e.turn), e.board.occupied.toggle(t).toggle(r).with(e.epSquare)).without(r).isEmpty();
683
+ }, Te = (e, t, o) => {
684
+ if (!C(o.king) || o.checkers.nonEmpty())
685
+ return d.empty();
686
+ const n = e.castles.rook[e.turn][t];
687
+ if (!C(n) || e.castles.path[e.turn][t].intersects(e.board.occupied))
688
+ return d.empty();
689
+ const r = ge(e.turn, t), s = vt(o.king, r), i = e.board.occupied.without(o.king);
690
+ for (const h of s)
691
+ if (e.kingAttackers(h, B(e.turn), i).nonEmpty())
692
+ return d.empty();
693
+ const a = ye(e.turn, t), p = e.board.occupied.toggle(o.king).toggle(n).toggle(a);
694
+ return e.kingAttackers(r, B(e.turn), p).nonEmpty() ? d.empty() : d.fromSquare(n);
695
+ }, lo = (e, t) => {
696
+ if (Ot(t))
697
+ return;
698
+ const o = t.to - t.from;
699
+ if (!(Math.abs(o) !== 2 && !e.board[e.turn].has(t.to)) && e.board.king.has(t.from))
700
+ return o > 0 ? "h" : "a";
701
+ }, Wo = (e, t) => {
702
+ const o = lo(e, t);
703
+ if (!o)
704
+ return t;
705
+ const n = e.castles.rook[e.turn][o];
706
+ return {
707
+ from: t.from,
708
+ to: C(n) ? n : t.to
709
+ };
710
+ };
711
+ class $ {
712
+ constructor() {
713
+ }
714
+ static empty() {
715
+ const t = new $();
716
+ for (const o of V)
717
+ t[o] = 0;
718
+ return t;
719
+ }
720
+ static fromBoard(t, o) {
721
+ const n = new $();
722
+ for (const r of V)
723
+ n[r] = t.pieces(o, r).size();
724
+ return n;
725
+ }
726
+ clone() {
727
+ const t = new $();
728
+ for (const o of V)
729
+ t[o] = this[o];
730
+ return t;
731
+ }
732
+ equals(t) {
733
+ return V.every((o) => this[o] === t[o]);
734
+ }
735
+ add(t) {
736
+ const o = new $();
737
+ for (const n of V)
738
+ o[n] = this[n] + t[n];
739
+ return o;
740
+ }
741
+ subtract(t) {
742
+ const o = new $();
743
+ for (const n of V)
744
+ o[n] = this[n] - t[n];
745
+ return o;
746
+ }
747
+ nonEmpty() {
748
+ return V.some((t) => this[t] > 0);
749
+ }
750
+ isEmpty() {
751
+ return !this.nonEmpty();
752
+ }
753
+ hasPawns() {
754
+ return this.pawn > 0;
755
+ }
756
+ hasNonPawns() {
757
+ return this.knight > 0 || this.bishop > 0 || this.rook > 0 || this.queen > 0 || this.king > 0;
758
+ }
759
+ size() {
760
+ return this.pawn + this.knight + this.bishop + this.rook + this.queen + this.king;
761
+ }
762
+ }
763
+ class tt {
764
+ constructor(t, o) {
765
+ this.white = t, this.black = o;
766
+ }
767
+ static empty() {
768
+ return new tt($.empty(), $.empty());
769
+ }
770
+ static fromBoard(t) {
771
+ return new tt($.fromBoard(t, "white"), $.fromBoard(t, "black"));
772
+ }
773
+ clone() {
774
+ return new tt(this.white.clone(), this.black.clone());
775
+ }
776
+ equals(t) {
777
+ return this.white.equals(t.white) && this.black.equals(t.black);
778
+ }
779
+ add(t) {
780
+ return new tt(this.white.add(t.white), this.black.add(t.black));
781
+ }
782
+ subtract(t) {
783
+ return new tt(this.white.subtract(t.white), this.black.subtract(t.black));
784
+ }
785
+ count(t) {
786
+ return this.white[t] + this.black[t];
787
+ }
788
+ size() {
789
+ return this.white.size() + this.black.size();
790
+ }
791
+ isEmpty() {
792
+ return this.white.isEmpty() && this.black.isEmpty();
793
+ }
794
+ nonEmpty() {
795
+ return !this.isEmpty();
796
+ }
797
+ hasPawns() {
798
+ return this.white.hasPawns() || this.black.hasPawns();
799
+ }
800
+ hasNonPawns() {
801
+ return this.white.hasNonPawns() || this.black.hasNonPawns();
802
+ }
803
+ }
804
+ class Ct {
805
+ constructor(t, o) {
806
+ this.white = t, this.black = o;
807
+ }
808
+ static default() {
809
+ return new Ct(3, 3);
810
+ }
811
+ clone() {
812
+ return new Ct(this.white, this.black);
813
+ }
814
+ equals(t) {
815
+ return this.white === t.white && this.black === t.black;
816
+ }
817
+ }
818
+ var T;
819
+ (function(e) {
820
+ e.Fen = "ERR_FEN", e.Board = "ERR_BOARD", e.Pockets = "ERR_POCKETS", e.Turn = "ERR_TURN", e.Castling = "ERR_CASTLING", e.EpSquare = "ERR_EP_SQUARE", e.RemainingChecks = "ERR_REMAINING_CHECKS", e.Halfmoves = "ERR_HALFMOVES", e.Fullmoves = "ERR_FULLMOVES";
821
+ })(T || (T = {}));
822
+ class I extends Error {
823
+ }
824
+ const Yo = (e, t, o) => {
825
+ let n = e.indexOf(t);
826
+ for (; o-- > 0 && n !== -1; )
827
+ n = e.indexOf(t, n + t.length);
828
+ return n;
829
+ }, pt = (e) => /^\d{1,4}$/.test(e) ? parseInt(e, 10) : void 0, ho = (e) => {
830
+ const t = Fo(e);
831
+ return t && { role: t, color: e.toLowerCase() === e ? "black" : "white" };
832
+ }, Ut = (e) => {
833
+ const t = dt.empty();
834
+ let o = 7, n = 0;
835
+ for (let r = 0; r < e.length; r++) {
836
+ const s = e[r];
837
+ if (s === "/" && n === 8)
838
+ n = 0, o--;
839
+ else {
840
+ const i = parseInt(s, 10);
841
+ if (i > 0)
842
+ n += i;
843
+ else {
844
+ if (n >= 8 || o < 0)
845
+ return v.err(new I(T.Board));
846
+ const a = n + o * 8, p = ho(s);
847
+ if (!p)
848
+ return v.err(new I(T.Board));
849
+ e[r + 1] === "~" && (p.promoted = !0, r++), t.set(a, p), n++;
850
+ }
851
+ }
852
+ }
853
+ return o !== 0 || n !== 8 ? v.err(new I(T.Board)) : v.ok(t);
854
+ }, Ne = (e) => {
855
+ if (e.length > 64)
856
+ return v.err(new I(T.Pockets));
857
+ const t = tt.empty();
858
+ for (const o of e) {
859
+ const n = ho(o);
860
+ if (!n)
861
+ return v.err(new I(T.Pockets));
862
+ t[n.color][n.role]++;
863
+ }
864
+ return v.ok(t);
865
+ }, Qo = (e, t) => {
866
+ let o = d.empty();
867
+ if (t === "-")
868
+ return v.ok(o);
869
+ for (const n of t) {
870
+ const r = n.toLowerCase(), s = n === r ? "black" : "white", i = s === "white" ? 0 : 7;
871
+ if ("a" <= r && r <= "h")
872
+ o = o.with(se(r.charCodeAt(0) - 97, i));
873
+ else if (r === "k" || r === "q") {
874
+ const a = e[s].intersect(d.backrank(s)).intersect(e.rook.union(e.king)), p = r === "k" ? a.last() : a.first();
875
+ o = o.with(C(p) && e.rook.has(p) ? p : se(r === "k" ? 7 : 0, i));
876
+ } else
877
+ return v.err(new I(T.Castling));
878
+ }
879
+ return st.some((n) => d.backrank(n).intersect(o).size() > 2) ? v.err(new I(T.Castling)) : v.ok(o);
880
+ }, Ie = (e) => {
881
+ const t = e.split("+");
882
+ if (t.length === 3 && t[0] === "") {
883
+ const o = pt(t[1]), n = pt(t[2]);
884
+ return !C(o) || o > 3 || !C(n) || n > 3 ? v.err(new I(T.RemainingChecks)) : v.ok(new Ct(3 - o, 3 - n));
885
+ } else if (t.length === 2) {
886
+ const o = pt(t[0]), n = pt(t[1]);
887
+ return !C(o) || o > 3 || !C(n) || n > 3 ? v.err(new I(T.RemainingChecks)) : v.ok(new Ct(o, n));
888
+ } else
889
+ return v.err(new I(T.RemainingChecks));
890
+ }, he = (e) => {
891
+ const t = e.split(/[\s_]+/), o = t.shift();
892
+ let n, r = v.ok(void 0);
893
+ if (o.endsWith("]")) {
894
+ const a = o.indexOf("[");
895
+ if (a === -1)
896
+ return v.err(new I(T.Fen));
897
+ n = Ut(o.slice(0, a)), r = Ne(o.slice(a + 1, -1));
898
+ } else {
899
+ const a = Yo(o, "/", 7);
900
+ a === -1 ? n = Ut(o) : (n = Ut(o.slice(0, a)), r = Ne(o.slice(a + 1)));
901
+ }
902
+ let s;
903
+ const i = t.shift();
904
+ if (!C(i) || i === "w")
905
+ s = "white";
906
+ else if (i === "b")
907
+ s = "black";
908
+ else
909
+ return v.err(new I(T.Turn));
910
+ return n.chain((a) => {
911
+ const p = t.shift(), h = C(p) ? Qo(a, p) : v.ok(d.empty()), c = t.shift();
912
+ let f;
913
+ if (C(c) && c !== "-" && (f = ft(c), !C(f)))
914
+ return v.err(new I(T.EpSquare));
915
+ let l = t.shift(), y;
916
+ C(l) && l.includes("+") && (y = Ie(l), l = t.shift());
917
+ const k = C(l) ? pt(l) : 0;
918
+ if (!C(k))
919
+ return v.err(new I(T.Halfmoves));
920
+ const _ = t.shift(), b = C(_) ? pt(_) : 1;
921
+ if (!C(b))
922
+ return v.err(new I(T.Fullmoves));
923
+ const E = t.shift();
924
+ let S = v.ok(void 0);
925
+ if (C(E)) {
926
+ if (C(y))
927
+ return v.err(new I(T.RemainingChecks));
928
+ S = Ie(E);
929
+ } else C(y) && (S = y);
930
+ return t.length > 0 ? v.err(new I(T.Fen)) : r.chain((w) => h.chain((x) => S.map((R) => ({
931
+ board: a,
932
+ pockets: w,
933
+ turn: s,
934
+ castlingRights: x,
935
+ remainingChecks: R,
936
+ epSquare: f,
937
+ halfmoves: k,
938
+ fullmoves: Math.max(1, b)
939
+ }))));
940
+ });
941
+ }, Xo = (e) => {
942
+ let t = bt(e.role);
943
+ return e.color === "white" && (t = t.toUpperCase()), e.promoted && (t += "~"), t;
944
+ }, Zo = (e) => {
945
+ let t = "", o = 0;
946
+ for (let n = 7; n >= 0; n--)
947
+ for (let r = 0; r < 8; r++) {
948
+ const s = r + n * 8, i = e.get(s);
949
+ i ? (o > 0 && (t += o, o = 0), t += Xo(i)) : o++, r === 7 && (o > 0 && (t += o, o = 0), n !== 0 && (t += "/"));
950
+ }
951
+ return t;
952
+ }, Be = (e) => V.map((t) => bt(t).repeat(e[t])).join(""), Jo = (e) => Be(e.white).toUpperCase() + Be(e.black), zo = (e, t) => {
953
+ let o = "";
954
+ for (const n of st) {
955
+ const r = d.backrank(n);
956
+ let s = e.kingOf(n);
957
+ C(s) && !r.has(s) && (s = void 0);
958
+ const i = e.pieces(n, "rook").intersect(r);
959
+ for (const a of t.intersect(r).reversed())
960
+ if (a === i.first() && C(s) && a < s)
961
+ o += n === "white" ? "Q" : "q";
962
+ else if (a === i.last() && C(s) && s < a)
963
+ o += n === "white" ? "K" : "k";
964
+ else {
965
+ const p = Rt[L(a)];
966
+ o += n === "white" ? p.toUpperCase() : p;
967
+ }
968
+ }
969
+ return o || "-";
970
+ }, tn = (e) => `${e.white}+${e.black}`, en = (e, t) => [
971
+ Zo(e.board) + (e.pockets ? `[${Jo(e.pockets)}]` : ""),
972
+ e.turn[0],
973
+ zo(e.board, e.castlingRights),
974
+ C(e.epSquare) ? Tt(e.epSquare) : "-",
975
+ ...e.remainingChecks ? [tn(e.remainingChecks)] : [],
976
+ Math.max(0, Math.min(e.halfmoves, 9999)),
977
+ Math.max(1, Math.min(e.fullmoves, 9999))
978
+ ].join(" "), on = (e, t) => {
979
+ let o = "";
980
+ if (Ot(t))
981
+ t.role !== "pawn" && (o = bt(t.role).toUpperCase()), o += "@" + Tt(t.to);
982
+ else {
983
+ const n = e.board.getRole(t.from);
984
+ if (!n)
985
+ return "--";
986
+ if (n === "king" && (e.board[e.turn].has(t.to) || Math.abs(t.to - t.from) === 2))
987
+ o = t.to > t.from ? "O-O" : "O-O-O";
988
+ else {
989
+ const r = e.board.occupied.has(t.to) || n === "pawn" && L(t.from) !== L(t.to);
990
+ if (n !== "pawn") {
991
+ o = bt(n).toUpperCase();
992
+ let s;
993
+ if (n === "king" ? s = be(t.to).intersect(e.board.king) : n === "queen" ? s = co(t.to, e.board.occupied).intersect(e.board.queen) : n === "rook" ? s = wt(t.to, e.board.occupied).intersect(e.board.rook) : n === "bishop" ? s = _t(t.to, e.board.occupied).intersect(e.board.bishop) : s = ke(t.to).intersect(e.board.knight), s = s.intersect(e.board[e.turn]).without(t.from), s.nonEmpty()) {
994
+ const i = e.ctx();
995
+ for (const a of s)
996
+ e.dests(a, i).has(t.to) || (s = s.without(a));
997
+ if (s.nonEmpty()) {
998
+ let a = !1, p = s.intersects(d.fromRank(it(t.from)));
999
+ s.intersects(d.fromFile(L(t.from))) ? a = !0 : p = !0, p && (o += Rt[L(t.from)]), a && (o += ao[it(t.from)]);
1000
+ }
1001
+ }
1002
+ } else r && (o = Rt[L(t.from)]);
1003
+ r && (o += "x"), o += Tt(t.to), t.promotion && (o += "=" + bt(t.promotion).toUpperCase());
1004
+ }
1005
+ }
1006
+ return o;
1007
+ }, nn = (e, t) => {
1008
+ var o;
1009
+ const n = on(e, t);
1010
+ return e.play(t), !((o = e.outcome()) === null || o === void 0) && o.winner ? n + "#" : e.isCheck() ? n + "+" : n;
1011
+ }, rn = (e, t) => nn(e.clone(), t);
1012
+ function xt(e) {
1013
+ return /^[a-h][1-8]$/.test(e);
1014
+ }
1015
+ function It(e) {
1016
+ const t = Tt(e);
1017
+ if (!xt(t))
1018
+ throw new Error(`ChessMatch: unexpected square encoding ${e}`);
1019
+ return t;
1020
+ }
1021
+ function Fe(e, t) {
1022
+ return {
1023
+ square: It(t),
1024
+ role: e.role,
1025
+ color: e.color
1026
+ };
1027
+ }
1028
+ function sn(e, t, o) {
1029
+ const n = e & 7, r = t & 7;
1030
+ if (Math.abs(r - n) !== 2) return null;
1031
+ const s = o === "white" ? "1" : "8";
1032
+ return r > n ? {
1033
+ rookFrom: `h${s}`,
1034
+ rookTo: `f${s}`
1035
+ } : { rookFrom: `a${s}`, rookTo: `d${s}` };
1036
+ }
1037
+ function an(e, t, o) {
1038
+ if (e.board.get(t)) return It(t);
1039
+ if (o.role !== "pawn" || e.epSquare === void 0 || e.epSquare !== t) return null;
1040
+ const n = o.color === "white" ? t - 8 : t + 8;
1041
+ return It(n);
1042
+ }
1043
+ function cn(e, t, o) {
1044
+ const n = ft(t), r = ft(o);
1045
+ if (n === void 0 || r === void 0) return null;
1046
+ const s = e.board.get(n);
1047
+ if (!s || s.color !== e.turn) return null;
1048
+ const i = { from: n, to: r }, a = r >> 3;
1049
+ return s.role === "pawn" && (a === 0 || a === 7) && (i.promotion = "queen"), e.isLegal(i) ? i : null;
1050
+ }
1051
+ class rt {
1052
+ constructor(t) {
1053
+ F(this, "position");
1054
+ this.position = t;
1055
+ }
1056
+ static starting() {
1057
+ return new rt(Et.default());
1058
+ }
1059
+ static fromFen(t) {
1060
+ const o = he(t);
1061
+ if (o.isErr)
1062
+ throw new Error(`ChessMatch.fromFen: invalid FEN (${t})`);
1063
+ const n = Et.fromSetup(o.value);
1064
+ if (n.isErr)
1065
+ throw new Error(`ChessMatch.fromFen: illegal setup (${t})`);
1066
+ return new rt(n.value);
1067
+ }
1068
+ fen() {
1069
+ return en(this.position.toSetup());
1070
+ }
1071
+ sideToMove() {
1072
+ return this.position.turn;
1073
+ }
1074
+ isCheck() {
1075
+ return this.position.isCheck();
1076
+ }
1077
+ isCheckmate() {
1078
+ return this.position.isCheckmate();
1079
+ }
1080
+ isStalemate() {
1081
+ return this.position.isStalemate();
1082
+ }
1083
+ isEnd() {
1084
+ return this.position.isEnd();
1085
+ }
1086
+ pieceAt(t) {
1087
+ const o = ft(t);
1088
+ if (o === void 0) return null;
1089
+ const n = this.position.board.get(o);
1090
+ return n ? Fe(n, o) : null;
1091
+ }
1092
+ pieces() {
1093
+ const t = [];
1094
+ for (const [o, n] of this.position.board)
1095
+ t.push(Fe(n, o));
1096
+ return t;
1097
+ }
1098
+ legalSquares(t) {
1099
+ const o = ft(t);
1100
+ if (o === void 0) return [];
1101
+ const n = this.position.board.get(o);
1102
+ if (!n || n.color !== this.position.turn) return [];
1103
+ const r = /* @__PURE__ */ new Set();
1104
+ for (const s of this.position.dests(o))
1105
+ r.add(It(s));
1106
+ if (n.role === "king") {
1107
+ const s = n.color === "white" ? "1" : "8";
1108
+ for (const i of ["c", "g"]) {
1109
+ const a = `${i}${s}`;
1110
+ if (!xt(a)) continue;
1111
+ const p = ft(a);
1112
+ p !== void 0 && this.position.isLegal({ from: o, to: p }) && r.add(a);
1113
+ }
1114
+ }
1115
+ return [...r];
1116
+ }
1117
+ /** All legal destinations for the side to move (auto-queen promotions included). */
1118
+ legalMoves() {
1119
+ const t = this.sideToMove(), o = [];
1120
+ for (const n of this.pieces())
1121
+ if (n.color === t)
1122
+ for (const r of this.legalSquares(n.square))
1123
+ o.push({ from: n.square, to: r });
1124
+ return o;
1125
+ }
1126
+ tryMove(t, o) {
1127
+ if (!xt(t) || !xt(o))
1128
+ return { ok: !1, reason: "invalid-square" };
1129
+ if (this.position.isEnd())
1130
+ return { ok: !1, reason: "game-over" };
1131
+ const n = cn(this.position, t, o);
1132
+ if (!n)
1133
+ return { ok: !1, reason: "illegal" };
1134
+ const r = n.from, s = n.to, i = this.position.board.get(r);
1135
+ if (!i)
1136
+ return { ok: !1, reason: "illegal" };
1137
+ const a = an(this.position, s, i), p = i.role === "king" ? sn(r, s, i.color) : null, h = n.promotion ? n.promotion : null, c = rn(this.position, n);
1138
+ return this.position.play(n), {
1139
+ ok: !0,
1140
+ from: t,
1141
+ to: o,
1142
+ san: c,
1143
+ capturedSquare: a,
1144
+ castle: p,
1145
+ promotion: h
1146
+ };
1147
+ }
1148
+ reset() {
1149
+ this.position = Et.default();
1150
+ }
1151
+ /** Replace the position from FEN. Returns false if the string is not a legal setup. */
1152
+ loadFen(t) {
1153
+ const o = he(t);
1154
+ if (o.isErr) return !1;
1155
+ const n = Et.fromSetup(o.value);
1156
+ return n.isErr ? !1 : (this.position = n.value, !0);
1157
+ }
1158
+ /**
1159
+ * Resolve a SAN string against the current position (auto-queen promotions).
1160
+ * `+` / `#` suffixes are ignored.
1161
+ */
1162
+ moveFromSan(t) {
1163
+ const o = t.trim().replace(/[+#]$/, "");
1164
+ if (!o) return null;
1165
+ const n = this.fen();
1166
+ for (const r of this.legalMoves()) {
1167
+ const i = rt.fromFen(n).tryMove(r.from, r.to);
1168
+ if (i.ok && i.san.replace(/[+#]$/, "") === o)
1169
+ return r;
1170
+ }
1171
+ return null;
1172
+ }
1173
+ }
1174
+ const un = {
1175
+ pawn: 100,
1176
+ knight: 320,
1177
+ bishop: 330,
1178
+ rook: 500,
1179
+ queen: 900,
1180
+ king: 0
1181
+ };
1182
+ function ln(e) {
1183
+ if (e.isCheckmate()) return -1e4;
1184
+ if (e.isStalemate()) return 0;
1185
+ let t = 0;
1186
+ for (const o of e.pieces()) {
1187
+ const n = un[o.role];
1188
+ t += o.color === "white" ? n : -n;
1189
+ }
1190
+ return e.isCheck() && (t += e.sideToMove() === "white" ? -25 : 25), e.sideToMove() === "white" ? t : -t;
1191
+ }
1192
+ function po(e, t) {
1193
+ const o = e.legalMoves();
1194
+ if (t <= 0 || o.length === 0 || e.isEnd())
1195
+ return { score: ln(e), move: null };
1196
+ let n = -1 / 0, r = o[0] ?? null;
1197
+ const s = e.fen();
1198
+ for (const i of o) {
1199
+ const a = rt.fromFen(s);
1200
+ if (!a.tryMove(i.from, i.to).ok) continue;
1201
+ const p = -po(a, t - 1).score;
1202
+ p > n && (n = p, r = i);
1203
+ }
1204
+ return { score: n, move: r };
1205
+ }
1206
+ class Fr {
1207
+ constructor(t = {}) {
1208
+ F(this, "depth");
1209
+ F(this, "thinkMs");
1210
+ this.depth = Math.max(1, Math.floor(t.depth ?? 2)), this.thinkMs = Math.max(0, t.thinkMs ?? 280);
1211
+ }
1212
+ async chooseMove(t) {
1213
+ this.thinkMs > 0 && await new Promise((n) => {
1214
+ setTimeout(n, this.thinkMs);
1215
+ });
1216
+ const o = rt.fromFen(t);
1217
+ return o.isEnd() ? null : po(o, this.depth).move;
1218
+ }
1219
+ }
1220
+ function Le(e) {
1221
+ return typeof e == "string" && /^[a-h][1-8]$/.test(e);
1222
+ }
1223
+ function Lr(e) {
1224
+ return new TextEncoder().encode(JSON.stringify(e));
1225
+ }
1226
+ function Gr(e) {
1227
+ let t;
1228
+ try {
1229
+ t = JSON.parse(new TextDecoder().decode(e));
1230
+ } catch {
1231
+ return null;
1232
+ }
1233
+ if (!t || typeof t != "object") return null;
1234
+ const o = t;
1235
+ return o.v !== 1 || typeof o.fen != "string" ? null : o.t === "reset" || o.t === "sync" ? { v: 1, t: o.t, fen: o.fen } : o.t === "move" && Le(o.from) && Le(o.to) ? { v: 1, t: "move", from: o.from, to: o.to, fen: o.fen } : null;
1236
+ }
1237
+ function Ge(e) {
1238
+ const t = he(e);
1239
+ if (t.isErr) return null;
1240
+ const o = t.value.fullmoves;
1241
+ return !Number.isFinite(o) || o < 1 ? null : (o - 1) * 2 + (t.value.turn === "black" ? 1 : 0);
1242
+ }
1243
+ function Hr(e, t) {
1244
+ const o = Ge(t);
1245
+ if (o === null) return "ignore";
1246
+ const n = Ge(e);
1247
+ return n === null || o > n ? "apply" : o < n ? "reply" : "ignore";
1248
+ }
1249
+ function Vr(e) {
1250
+ const t = new URLSearchParams(e.startsWith("?") ? e.slice(1) : e), o = (t.get("chess") ?? "cpu").toLowerCase(), n = o === "hotseat" || o === "local" ? "hotseat" : o === "p2p" ? "p2p" : o === "learn" || o === "eco" || o === "train" ? "learn" : "cpu", s = (t.get("chessColor") ?? "white").toLowerCase() === "black" ? "black" : "white", i = (t.get("chessEco") ?? t.get("eco") ?? "").trim(), a = (t.get("chessQuiz") ?? "").toLowerCase();
1251
+ return {
1252
+ mode: n,
1253
+ localColor: s,
1254
+ ...i ? { eco: i } : {},
1255
+ quiz: a === "1" || a === "true" || a === "yes"
1256
+ };
1257
+ }
1258
+ const hn = ["chess", "chessColor", "chessEco", "eco", "chessQuiz"];
1259
+ function _e(e) {
1260
+ if (typeof e != "object" || e === null || Array.isArray(e)) return null;
1261
+ const t = e, o = typeof t.mode == "string" ? t.mode.toLowerCase() : "", n = o === "hotseat" || o === "local" ? "hotseat" : o === "p2p" ? "p2p" : o === "learn" || o === "eco" || o === "train" ? "learn" : o === "cpu" ? "cpu" : null;
1262
+ if (!n) return null;
1263
+ const s = (typeof t.localColor == "string" ? t.localColor.toLowerCase() : "white") === "black" ? "black" : "white", i = typeof t.eco == "string" ? t.eco.trim() : "";
1264
+ return {
1265
+ mode: n,
1266
+ localColor: s,
1267
+ ...i ? { eco: i } : {},
1268
+ quiz: t.quiz === !0
1269
+ };
1270
+ }
1271
+ function pn(e) {
1272
+ const t = {};
1273
+ return e.mode !== "cpu" && (t.chess = e.mode), e.localColor !== "white" && (t.chessColor = e.localColor), e.mode === "learn" && (e.eco && (t.chessEco = e.eco), e.quiz && (t.chessQuiz = "1")), t;
1274
+ }
1275
+ function fn(e, t) {
1276
+ const o = new URLSearchParams(e.startsWith("?") ? e.slice(1) : e);
1277
+ for (const n of hn) o.delete(n);
1278
+ for (const [n, r] of Object.entries(pn(t)))
1279
+ o.set(n, r);
1280
+ return o.toString();
1281
+ }
1282
+ function Dr(e) {
1283
+ if (typeof window > "u") return;
1284
+ const t = fn(window.location.search, e), o = t.length > 0 ? `?${t}` : "";
1285
+ window.history.replaceState(null, "", `${window.location.pathname}${o}${window.location.hash}`);
1286
+ }
1287
+ function $r(e) {
1288
+ const t = Math.max(0, Math.ceil(e)), o = Math.floor(t / 60), n = t % 60;
1289
+ return `${o}:${n.toString().padStart(2, "0")}`;
1290
+ }
1291
+ const Ur = "w3dts-chess-hud-state", jr = "w3dts-chess-hud-command";
1292
+ function Ht(e) {
1293
+ return typeof e == "object" && e !== null && !Array.isArray(e);
1294
+ }
1295
+ function jt(e) {
1296
+ return e === "white" || e === "black" ? e : null;
1297
+ }
1298
+ function dn(e) {
1299
+ return e === "cpu" || e === "hotseat" || e === "p2p" ? e : null;
1300
+ }
1301
+ function mn(e) {
1302
+ return e === null ? null : kn(e);
1303
+ }
1304
+ function ot(e) {
1305
+ return typeof e == "string" && e.length > 0 ? e : null;
1306
+ }
1307
+ function Bt(e, t = 0) {
1308
+ return typeof e == "number" && Number.isFinite(e) ? e : t;
1309
+ }
1310
+ function gn(e) {
1311
+ return e === "done" || e === "current" || e === "future" ? e : null;
1312
+ }
1313
+ function yn(e) {
1314
+ if (!Ht(e)) return null;
1315
+ const t = ot(e.san), o = gn(e.status);
1316
+ return !t || !o ? null : { san: t, status: o, hidden: e.hidden === !0 };
1317
+ }
1318
+ function bn(e) {
1319
+ return e.replace(/[+#]$/, "");
1320
+ }
1321
+ function kn(e) {
1322
+ return e === "waiting" || e === "connecting" || e === "connected" || e === "disconnected" ? e : e === "degraded" ? "connected" : "waiting";
1323
+ }
1324
+ function Kr(e) {
1325
+ return `You are ${e}. Second tab: chess=p2p&chessColor=${e === "white" ? "black" : "white"}`;
1326
+ }
1327
+ function qr(e, t, o) {
1328
+ const n = Math.max(0, Math.min(t, e.length));
1329
+ return e.map((r, s) => {
1330
+ const i = s < n ? "done" : s === n ? "current" : "future";
1331
+ return {
1332
+ san: bn(r),
1333
+ status: i,
1334
+ hidden: o && i !== "done"
1335
+ };
1336
+ });
1337
+ }
1338
+ function _n(e) {
1339
+ const t = dn(e.mode), o = ot(e.label), n = ot(e.title), r = typeof e.description == "string" ? e.description : "", s = jt(e.localColor), i = jt(e.sideToMove);
1340
+ if (!t || !o || !n || !s || !i) return null;
1341
+ const a = Ht(e.clocks) ? e.clocks : {}, p = e.flag === null || e.flag === void 0 ? null : jt(e.flag);
1342
+ return e.flag !== null && e.flag !== void 0 && p === null ? null : {
1343
+ kind: "play",
1344
+ mode: t,
1345
+ label: o,
1346
+ title: n,
1347
+ description: r,
1348
+ localColor: s,
1349
+ sideToMove: i,
1350
+ cpuThinking: e.cpuThinking === !0,
1351
+ p2pStatus: t === "p2p" ? mn(e.p2pStatus) : null,
1352
+ clocks: {
1353
+ whiteSeconds: Math.max(0, Bt(a.whiteSeconds)),
1354
+ blackSeconds: Math.max(0, Bt(a.blackSeconds))
1355
+ },
1356
+ flag: p,
1357
+ session: _e(e.session) ?? { mode: t, localColor: s, quiz: !1 }
1358
+ };
1359
+ }
1360
+ function wn(e) {
1361
+ const t = ot(e.label), o = ot(e.title), n = ot(e.eco), r = ot(e.openingName);
1362
+ if (!t || !o || !n || !r) return null;
1363
+ const s = e.plies, i = Array.isArray(s) ? s.map(yn).filter((a) => a !== null) : [];
1364
+ return {
1365
+ kind: "learn",
1366
+ label: t,
1367
+ title: o,
1368
+ description: typeof e.description == "string" ? e.description : "",
1369
+ eco: n,
1370
+ openingName: r,
1371
+ plyIndex: Math.max(0, Bt(e.plyIndex)),
1372
+ plyCount: Math.max(0, Bt(e.plyCount)),
1373
+ quiz: e.quiz === !0,
1374
+ miss: e.miss === !0,
1375
+ complete: e.complete === !0,
1376
+ coachBusy: e.coachBusy === !0,
1377
+ plies: i,
1378
+ session: _e(e.session) ?? {
1379
+ mode: "learn",
1380
+ localColor: "white",
1381
+ eco: n,
1382
+ quiz: e.quiz === !0
1383
+ }
1384
+ };
1385
+ }
1386
+ function Wr(e) {
1387
+ return Ht(e) ? e.kind === "play" ? _n(e) : e.kind === "learn" ? wn(e) : null : null;
1388
+ }
1389
+ function Yr(e) {
1390
+ if (!Ht(e)) return null;
1391
+ if (e.type === "mode-picker")
1392
+ return { type: "mode-picker", open: e.open === !0 };
1393
+ if (e.type === "apply-session") {
1394
+ const t = _e(e.session);
1395
+ return t ? { type: "apply-session", session: t } : null;
1396
+ }
1397
+ return e.type === "request-state" ? { type: "request-state" } : null;
1398
+ }
1399
+ const vn = [
1400
+ { eco: "C50", name: "Italian Game", sans: ["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5"] },
1401
+ { eco: "C60", name: "Ruy Lopez", sans: ["e4", "e5", "Nf3", "Nc6", "Bb5", "a6"] },
1402
+ { eco: "C44", name: "Scotch Game", sans: ["e4", "e5", "Nf3", "Nc6", "d4", "exd4"] },
1403
+ { eco: "B20", name: "Sicilian Defence", sans: ["e4", "c5", "Nf3", "d6", "d4", "cxd4"] },
1404
+ { eco: "C00", name: "French Defence", sans: ["e4", "e6", "d4", "d5"] },
1405
+ { eco: "B10", name: "Caro-Kann Defence", sans: ["e4", "c6", "d4", "d5"] },
1406
+ { eco: "D06", name: "Queen's Gambit", sans: ["d4", "d5", "c4", "e6"] },
1407
+ { eco: "E60", name: "King's Indian Defence", sans: ["d4", "Nf6", "c4", "g6"] }
1408
+ ];
1409
+ function He(e) {
1410
+ return e.toLowerCase().replace(/['’]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
1411
+ }
1412
+ function Cn(e, t) {
1413
+ if (!t) return 0;
1414
+ const o = t.trim().toLowerCase();
1415
+ if (!o) return 0;
1416
+ const n = e.findIndex((i) => i.eco.toLowerCase() === o);
1417
+ if (n >= 0) return n;
1418
+ const r = e.findIndex((i) => He(i.name) === He(o));
1419
+ if (r >= 0) return r;
1420
+ const s = e.findIndex((i) => i.name.toLowerCase().includes(o));
1421
+ return s >= 0 ? s : 0;
1422
+ }
1423
+ function Sn(e) {
1424
+ const t = rt.starting(), o = [];
1425
+ for (const n of e.sans) {
1426
+ const r = t.moveFromSan(n);
1427
+ if (!r)
1428
+ throw new Error(`OpeningTrainer: cannot play ${n} in ${e.eco} ${e.name}`);
1429
+ const s = t.tryMove(r.from, r.to);
1430
+ if (!s.ok)
1431
+ throw new Error(`OpeningTrainer: illegal ${n} in ${e.eco} ${e.name}`);
1432
+ o.push({ from: r.from, to: r.to, san: s.san });
1433
+ }
1434
+ return o;
1435
+ }
1436
+ class Qr {
1437
+ constructor(t, o = vn) {
1438
+ F(this, "catalog");
1439
+ F(this, "index");
1440
+ F(this, "plies", []);
1441
+ F(this, "ply", 0);
1442
+ this.catalog = o, this.index = Cn(o, t), this.reload();
1443
+ }
1444
+ opening() {
1445
+ return this.catalog[this.index] ?? this.catalog[0];
1446
+ }
1447
+ plyIndex() {
1448
+ return this.ply;
1449
+ }
1450
+ plyCount() {
1451
+ return this.plies.length;
1452
+ }
1453
+ isComplete() {
1454
+ return this.ply >= this.plies.length;
1455
+ }
1456
+ expected() {
1457
+ return this.plies[this.ply] ?? null;
1458
+ }
1459
+ isBookMove(t, o) {
1460
+ const n = this.expected();
1461
+ return !!(n && n.from === t && n.to === o);
1462
+ }
1463
+ /** Advance if `from`/`to` is the next book ply. */
1464
+ accept(t, o) {
1465
+ return this.isBookMove(t, o) ? (this.ply += 1, !0) : !1;
1466
+ }
1467
+ restart() {
1468
+ this.ply = 0;
1469
+ }
1470
+ nextOpening() {
1471
+ return this.index = (this.index + 1) % this.catalog.length, this.reload(), this.opening();
1472
+ }
1473
+ reload() {
1474
+ const t = this.opening();
1475
+ this.plies = Sn(t), this.ply = 0;
1476
+ }
1477
+ }
1478
+ const U = 0.06, St = U * 8, z = 0.06, pe = 1 - 2 * z, K = St / pe, ht = 2e-3, Pt = 0.024, D = 1e-3, Ve = 3.5, En = "abcdefgh";
1479
+ function Mn(e) {
1480
+ return /^[a-h][1-8]$/.test(e);
1481
+ }
1482
+ function at(e, t = D) {
1483
+ const o = e.charCodeAt(0) - 97, n = e.charCodeAt(1) - 49, r = (o - Ve) * U, s = (n - Ve) * U;
1484
+ return M.fromValues(r, t, s);
1485
+ }
1486
+ function fo(e, t) {
1487
+ const o = St / 2;
1488
+ if (e < -o || e >= o || t < -o || t >= o) return null;
1489
+ const n = Math.floor((e + o) / U), r = Math.floor((t + o) / U);
1490
+ if (n < 0 || n > 7 || r < 0 || r > 7) return null;
1491
+ const s = `${En[n]}${r + 1}`;
1492
+ return Mn(s) ? s : null;
1493
+ }
1494
+ function Xr(e, t, o = D) {
1495
+ const n = fo(e, t);
1496
+ return n ? at(n, o) : null;
1497
+ }
1498
+ const An = "abcdefgh", xn = "12345678";
1499
+ function Pn() {
1500
+ return (St + K) / 4;
1501
+ }
1502
+ function Zr() {
1503
+ return (K - St) / 2 * (2 / 3);
1504
+ }
1505
+ const De = D + 16e-4;
1506
+ function Jr(e) {
1507
+ const t = Pn(), o = -t, n = t, r = e === "white" ? [o, n] : [n, o], s = -t, i = t, a = e === "white" ? [s, i] : [i, s], p = [];
1508
+ for (const h of r) {
1509
+ const c = h < 0 ? 180 : 0;
1510
+ for (let f = 0; f < 8; f++) {
1511
+ const l = An[f], y = at(`${l}1`);
1512
+ p.push({
1513
+ glyph: l,
1514
+ kind: "file",
1515
+ x: y[0],
1516
+ y: De,
1517
+ z: h,
1518
+ yawDeg: c
1519
+ });
1520
+ }
1521
+ }
1522
+ for (const h of a) {
1523
+ const c = h < 0 ? -90 : 90;
1524
+ for (let f = 0; f < 8; f++) {
1525
+ const l = xn[f], y = at(`a${l}`);
1526
+ p.push({
1527
+ glyph: l,
1528
+ kind: "rank",
1529
+ x: h,
1530
+ y: De,
1531
+ z: y[2],
1532
+ yawDeg: c
1533
+ });
1534
+ }
1535
+ }
1536
+ return p;
1537
+ }
1538
+ function zr(e, t = M.create()) {
1539
+ return M.set(t, e.x, e.y, e.z);
1540
+ }
1541
+ function ts(e, t = gt.create()) {
1542
+ return gt.fromEuler(t, -90, e.yawDeg, 0);
1543
+ }
1544
+ const Rn = 5, On = 7, Tn = {
1545
+ a: [".###.", "#...#", "#####", "#...#", "#...#", "#...#", "#...#"],
1546
+ b: ["####.", "#...#", "####.", "#...#", "#...#", "#...#", "####."],
1547
+ c: [".####", "#....", "#....", "#....", "#....", "#....", ".####"],
1548
+ d: ["####.", "#...#", "#...#", "#...#", "#...#", "#...#", "####."],
1549
+ e: ["#####", "#....", "####.", "#....", "#....", "#....", "#####"],
1550
+ f: ["#####", "#....", "####.", "#....", "#....", "#....", "#...."],
1551
+ g: [".####", "#....", "#....", "#.###", "#...#", "#...#", ".####"],
1552
+ h: ["#...#", "#...#", "#####", "#...#", "#...#", "#...#", "#...#"],
1553
+ 1: ["..#..", ".##..", "..#..", "..#..", "..#..", "..#..", ".###."],
1554
+ 2: [".###.", "#...#", "....#", "..##.", ".#...", "#....", "#####"],
1555
+ 3: [".###.", "#...#", "....#", "..##.", "....#", "#...#", ".###."],
1556
+ 4: ["#...#", "#...#", "#...#", "#####", "....#", "....#", "....#"],
1557
+ 5: ["#####", "#....", "####.", "....#", "....#", "#...#", ".###."],
1558
+ 6: [".###.", "#....", "#....", "####.", "#...#", "#...#", ".###."],
1559
+ 7: ["#####", "....#", "...#.", "..#..", "..#..", "..#..", "..#.."],
1560
+ 8: [".###.", "#...#", "#...#", ".###.", "#...#", "#...#", ".###."]
1561
+ }, Kt = { r: 14, g: 10, b: 8 }, qt = { r: 228, g: 214, b: 176 }, Wt = { r: 248, g: 238, b: 214 }, Nn = 128, In = '"Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", Georgia, "Times New Roman", serif';
1562
+ function Bn(e, t) {
1563
+ var i, a, p, h;
1564
+ const o = new Float32Array(t * t), n = Tn[e];
1565
+ if (!n) return o;
1566
+ const r = t * 0.18, s = t - r * 2;
1567
+ for (let c = 0; c < t; c++)
1568
+ for (let f = 0; f < t; f++) {
1569
+ const l = (f + 0.5 - r) / s, y = (c + 0.5 - r) / s;
1570
+ if (l < 0 || y < 0 || l >= 1 || y >= 1) continue;
1571
+ const k = l * Rn - 0.5, _ = y * On - 0.5, b = Math.floor(k), E = Math.floor(_), S = k - b, w = _ - E, x = ((i = n[E]) == null ? void 0 : i[b]) === "#" ? 1 : 0, R = ((a = n[E]) == null ? void 0 : a[b + 1]) === "#" ? 1 : 0, H = ((p = n[E + 1]) == null ? void 0 : p[b]) === "#" ? 1 : 0, j = ((h = n[E + 1]) == null ? void 0 : h[b + 1]) === "#" ? 1 : 0;
1572
+ o[c * t + f] = x * (1 - S) * (1 - w) + R * S * (1 - w) + H * (1 - S) * w + j * S * w;
1573
+ }
1574
+ return o;
1575
+ }
1576
+ function Fn(e, t) {
1577
+ try {
1578
+ const o = typeof OffscreenCanvas < "u" ? new OffscreenCanvas(t, t) : typeof document < "u" ? document.createElement("canvas") : null;
1579
+ if (!o) return null;
1580
+ o.width = t, o.height = t;
1581
+ const n = o.getContext("2d", { willReadFrequently: !0 });
1582
+ if (!n) return null;
1583
+ n.clearRect(0, 0, t, t), n.fillStyle = "#000", n.strokeStyle = "#000", n.textAlign = "center", n.textBaseline = "alphabetic";
1584
+ const r = Math.round(t * 0.58);
1585
+ n.font = `600 ${r}px ${In}`;
1586
+ const s = n.measureText(e), i = s.actualBoundingBoxAscent || r * 0.7, a = s.actualBoundingBoxDescent || r * 0.2, p = (t + i - a) * 0.5, h = t * 0.5;
1587
+ n.lineJoin = "round", n.lineCap = "round", n.lineWidth = Math.max(2, t * 0.055), n.strokeText(e, h, p), n.fillText(e, h, p);
1588
+ const c = n.getImageData(0, 0, t, t), f = new Float32Array(t * t), l = c.data;
1589
+ for (let y = 0; y < t * t; y++)
1590
+ f[y] = (l[y * 4 + 3] ?? 0) / 255;
1591
+ return f;
1592
+ } catch {
1593
+ return null;
1594
+ }
1595
+ }
1596
+ function Q(e, t, o, n) {
1597
+ return o < 0 || n < 0 || o >= t || n >= t ? 0 : e[n * t + o] ?? 0;
1598
+ }
1599
+ function $e(e, t) {
1600
+ const o = new Float32Array(t * t);
1601
+ for (let n = 0; n < t; n++)
1602
+ for (let r = 0; r < t; r++) {
1603
+ let s = 0;
1604
+ for (let i = -1; i <= 1; i++)
1605
+ for (let a = -1; a <= 1; a++)
1606
+ s += Q(e, t, r + a, n + i);
1607
+ o[n * t + r] = s / 9;
1608
+ }
1609
+ return o;
1610
+ }
1611
+ function Ln(e, t, o) {
1612
+ const n = new Float32Array(t * t);
1613
+ for (let r = 0; r < t; r++)
1614
+ for (let s = 0; s < t; s++) {
1615
+ let i = 0;
1616
+ for (let a = -o; a <= o; a++)
1617
+ for (let p = -o; p <= o; p++) {
1618
+ const h = Q(e, t, s + p, r + a);
1619
+ h > i && (i = h);
1620
+ }
1621
+ n[r * t + s] = i;
1622
+ }
1623
+ return n;
1624
+ }
1625
+ function fe(e) {
1626
+ return e < 0 ? 0 : e > 1 ? 1 : e;
1627
+ }
1628
+ function Yt(e, t, o) {
1629
+ const n = fe((o - e) / (t - e));
1630
+ return n * n * (3 - 2 * n);
1631
+ }
1632
+ function Gn(e, t) {
1633
+ const o = new Uint8ClampedArray(t * t * 4), n = $e(e, t), r = $e(
1634
+ Ln(e, t, Math.max(1, Math.round(t * 0.028))),
1635
+ t
1636
+ );
1637
+ for (let s = 0; s < t; s++)
1638
+ for (let i = 0; i < t; i++) {
1639
+ const a = Q(r, t, i, s);
1640
+ if (a < 0.03) continue;
1641
+ const p = Q(n, t, i, s), h = Q(r, t, i + 1, s) - Q(r, t, i - 1, s), c = Q(r, t, i, s + 1) - Q(r, t, i, s - 1), f = Math.hypot(h, c), l = f > 1e-5 ? h / f : 0, y = f > 1e-5 ? c / f : 0, k = -(l * 0.42 + y * 0.9), _ = Yt(0.04, 0.28, a), b = Yt(0.12, 0.55, p), E = _ * (1 - b), S = Yt(0.04, 0.5, f), w = fe(k) * S * E, x = Math.max(E * (0.4 + 0.4 * fe(-k)), E * (1 - b) * 0.22), R = (s * t + i) * 4, H = Kt.r * x + qt.r * b * (1 - w) + Wt.r * w, j = Kt.g * x + qt.g * b * (1 - w) + Wt.g * w, ct = Kt.b * x + qt.b * b * (1 - w) + Wt.b * w;
1642
+ o[R] = Math.round(Math.min(255, H)), o[R + 1] = Math.round(Math.min(255, j)), o[R + 2] = Math.round(Math.min(255, ct)), o[R + 3] = Math.round(Math.min(255, _ * 255));
1643
+ }
1644
+ return o;
1645
+ }
1646
+ function es(e, t = Nn) {
1647
+ const o = Fn(e, t) ?? Bn(e, t);
1648
+ return Gn(o, t);
1649
+ }
1650
+ function Ue(e) {
1651
+ return e.charCodeAt(0) - 97;
1652
+ }
1653
+ function je(e) {
1654
+ return e.charCodeAt(1) - 49;
1655
+ }
1656
+ function Hn(e, t, o) {
1657
+ return [(e - 3.5) * U, o, (t - 3.5) * U];
1658
+ }
1659
+ function Vn(e, t) {
1660
+ const o = Ue(e), n = je(e), r = Ue(t) - o, s = je(t) - n;
1661
+ return Math.abs(r) === 2 ? { file: o + r, rank: n } : { file: o, rank: n + s };
1662
+ }
1663
+ function mo(e, t, o, n) {
1664
+ const r = Math.sin(Math.PI * o);
1665
+ return [e[0] + (t[0] - e[0]) * o, D + n * r, e[2] + (t[2] - e[2]) * o];
1666
+ }
1667
+ function Ke(e, t, o, n, r) {
1668
+ const s = [], i = r ? 1 : 0;
1669
+ for (let a = i; a < o; a++)
1670
+ s.push(mo(e, t, a / (o - 1), n));
1671
+ return s;
1672
+ }
1673
+ function os(e, t, o = {}) {
1674
+ const n = o.liftY ?? 0.028, r = Math.max(8, o.samples ?? 20), s = at(e, D), i = at(t, D), a = [s[0], s[1], s[2]], p = [i[0], i[1], i[2]];
1675
+ if (!o.knight) {
1676
+ const l = [];
1677
+ for (let y = 0; y < r; y++)
1678
+ l.push(mo(a, p, y / (r - 1), n));
1679
+ return l;
1680
+ }
1681
+ const h = Vn(e, t), c = Hn(h.file, h.rank, D), f = Math.max(5, Math.ceil(r / 2));
1682
+ return [
1683
+ ...Ke(a, c, f, n * 0.75, !1),
1684
+ ...Ke(c, p, f, n * 0.75, !0)
1685
+ ];
1686
+ }
1687
+ function ns(e) {
1688
+ let t = 0;
1689
+ for (let o = 1; o < e.length; o++) {
1690
+ const n = e[o], r = e[o - 1];
1691
+ t += Math.hypot(n[0] - r[0], n[1] - r[1], n[2] - r[2]);
1692
+ }
1693
+ return t;
1694
+ }
1695
+ function go(e) {
1696
+ const t = Math.min(1, Math.max(0, e));
1697
+ return t * t * (3 - 2 * t);
1698
+ }
1699
+ const yo = 0.042;
1700
+ function rs(e, t, o, n = yo) {
1701
+ const r = at(e, D), s = at(t, D), i = go(o), a = Math.sin(Math.PI * i);
1702
+ return [
1703
+ r[0] + (s[0] - r[0]) * i,
1704
+ D + n * a,
1705
+ r[2] + (s[2] - r[2]) * i
1706
+ ];
1707
+ }
1708
+ function ss(e, t, o) {
1709
+ const n = go(o), r = Math.sin(Math.PI * n), s = Math.max(0.012, Math.abs(t[1] - e[1]) + yo * 0.35);
1710
+ return [
1711
+ e[0] + (t[0] - e[0]) * n,
1712
+ e[1] + (t[1] - e[1]) * n + s * r,
1713
+ e[2] + (t[2] - e[2]) * n
1714
+ ];
1715
+ }
1716
+ const Dn = U * 0.7, $n = U * 0.52;
1717
+ function is(e, t) {
1718
+ const o = K / 2, r = (e === "white" ? -1 : 1) * (o + Dn), s = -St / 2 + U * 0.15;
1719
+ return {
1720
+ x: r,
1721
+ y: D,
1722
+ z: s + t * $n
1723
+ };
1724
+ }
1725
+ function as(e) {
1726
+ return fo(e.x, e.z) === null;
1727
+ }
1728
+ function cs(e) {
1729
+ const t = [];
1730
+ return t.push(e.captured ? "capture" : "drop"), e.mate ? (t.push(e.localWon ? "win" : "lose"), t) : (e.check && t.push("check"), t);
1731
+ }
1732
+ const Un = 1, we = 2, us = we, jn = Un | we, Kn = 0, ve = 96, bo = [
1733
+ [0, 0.018],
1734
+ [5e-3, 0.018],
1735
+ [7e-3, 0.012],
1736
+ [0.02, 75e-4],
1737
+ [0.026, 0.01],
1738
+ [0.03, 8e-3],
1739
+ [0.034, 0.012],
1740
+ [0.042, 0.014],
1741
+ [0.05, 0.01],
1742
+ [0.054, 2e-3]
1743
+ ], qn = [
1744
+ [0, 0.019],
1745
+ [6e-3, 0.019],
1746
+ [0.01, 0.014],
1747
+ [0.038, 0.013],
1748
+ [0.042, 0.017],
1749
+ [0.05, 0.017]
1750
+ ], Wn = [
1751
+ [0, 0.018],
1752
+ [5e-3, 0.018],
1753
+ [8e-3, 0.011],
1754
+ [0.028, 8e-3],
1755
+ [0.036, 0.013],
1756
+ [0.05, 0.011],
1757
+ [0.058, 6e-3],
1758
+ [0.062, 1e-3]
1759
+ ], Yn = [
1760
+ [0, 0.02],
1761
+ [6e-3, 0.02],
1762
+ [0.01, 0.012],
1763
+ [0.034, 9e-3],
1764
+ [0.042, 0.015],
1765
+ [0.058, 0.013],
1766
+ [0.066, 8e-3],
1767
+ [0.07, 2e-3]
1768
+ ], Qn = [
1769
+ [0, 0.021],
1770
+ [6e-3, 0.021],
1771
+ [0.01, 0.013],
1772
+ [0.036, 0.01],
1773
+ [0.044, 0.016],
1774
+ [0.062, 0.014],
1775
+ [0.07, 0.01],
1776
+ [0.074, 4e-3]
1777
+ ], Xn = [
1778
+ [0.014, -0.012],
1779
+ [0.014, 6e-3],
1780
+ [0.022, 0.012],
1781
+ [0.03, 0.015],
1782
+ [0.034, 0.02],
1783
+ [0.038, 0.018],
1784
+ [0.036, 0.012],
1785
+ [0.032, 8e-3],
1786
+ [0.04, 6e-3],
1787
+ [0.05, 8e-3],
1788
+ [0.056, 4e-3],
1789
+ [0.06, 2e-3],
1790
+ [0.054, -4e-3],
1791
+ [0.048, -0.01],
1792
+ [0.036, -0.014],
1793
+ [0.024, -0.014]
1794
+ ], Zn = [
1795
+ [0, 0.018],
1796
+ [6e-3, 0.018],
1797
+ [0.01, 0.012],
1798
+ [0.014, 0.01]
1799
+ ];
1800
+ function X(e, t, o) {
1801
+ return [e[0] + (t[0] - e[0]) * o, e[1] + (t[1] - e[1]) * o];
1802
+ }
1803
+ function Qt(e, t) {
1804
+ return Math.hypot(t[0] - e[0], t[1] - e[1]);
1805
+ }
1806
+ function ko(e, t) {
1807
+ let o = e.map((r) => [r[0], r[1]]);
1808
+ const n = Math.max(0, Math.floor(t));
1809
+ for (let r = 0; r < n && !(o.length < 2); r++) {
1810
+ const s = [o[0]];
1811
+ for (let i = 0; i < o.length - 1; i++) {
1812
+ const a = o[i], p = o[i + 1];
1813
+ s.push(X(a, p, 0.25)), s.push(X(a, p, 0.75));
1814
+ }
1815
+ s.push(o[o.length - 1]), o = s;
1816
+ }
1817
+ return o;
1818
+ }
1819
+ function Jn(e, t, o, n, r) {
1820
+ const a = 0 + Math.pow(Qt(e, t), 0.5), p = a + Math.pow(Qt(t, o), 0.5), h = p + Math.pow(Qt(o, n), 0.5), c = p - a;
1821
+ if (c < 1e-12) return [t[0], t[1]];
1822
+ const f = a + r * c, l = X(e, t, (f - 0) / Math.max(a - 0, 1e-12)), y = X(t, o, (f - a) / Math.max(p - a, 1e-12)), k = X(o, n, (f - p) / Math.max(h - p, 1e-12)), _ = X(l, y, (f - 0) / Math.max(p - 0, 1e-12)), b = X(y, k, (f - a) / Math.max(h - a, 1e-12));
1823
+ return X(_, b, (f - a) / Math.max(p - a, 1e-12));
1824
+ }
1825
+ function zn(e, t) {
1826
+ const o = e.length;
1827
+ if (o < 3) return e.map((s) => [s[0], s[1]]);
1828
+ const n = Math.max(1, Math.floor(t)), r = [];
1829
+ for (let s = 0; s < o; s++) {
1830
+ const i = e[(s + o - 1) % o], a = e[s], p = e[(s + 1) % o], h = e[(s + 2) % o];
1831
+ for (let c = 0; c < n; c++)
1832
+ r.push(Jn(i, a, p, h, c / n));
1833
+ }
1834
+ return r;
1835
+ }
1836
+ function _o(e) {
1837
+ return ko(e, 2).map(([t, o]) => [o, t, 0]);
1838
+ }
1839
+ function tr(e) {
1840
+ let t = 0;
1841
+ for (let o = 0; o < e.length; o++) {
1842
+ const n = (o + 1) % e.length;
1843
+ t += e[o][0] * e[n][1] - e[n][0] * e[o][1];
1844
+ }
1845
+ return t;
1846
+ }
1847
+ function er(e = 6) {
1848
+ const t = zn(Xn, e);
1849
+ return (tr(t) >= 0 ? t : [...t].reverse()).map(([n, r]) => [0, n, r]);
1850
+ }
1851
+ const or = 0.022;
1852
+ function P(e, t, o, n, r) {
1853
+ return { id: e, type: t, position: { x: o, y: n }, ...r };
1854
+ }
1855
+ function A(e, t, o, n, r) {
1856
+ return { id: e, fromNodeId: t, fromSocketId: o, toNodeId: n, toSocketId: r };
1857
+ }
1858
+ function N() {
1859
+ return [{ id: "geometry", name: "geometry", type: "geometry" }];
1860
+ }
1861
+ function nr(e) {
1862
+ switch (e) {
1863
+ case "pawn":
1864
+ return bo;
1865
+ case "rook":
1866
+ return qn;
1867
+ case "bishop":
1868
+ return Wn;
1869
+ case "queen":
1870
+ return Yn;
1871
+ case "king":
1872
+ return Qn;
1873
+ }
1874
+ }
1875
+ function rr(e) {
1876
+ switch (e) {
1877
+ case "pawn":
1878
+ return [];
1879
+ case "rook":
1880
+ return [
1881
+ { size: [0.012, 0.012, 0.012], center: [0.015, 0.054, 0] },
1882
+ { size: [0.012, 0.012, 0.012], center: [-0.015, 0.054, 0] },
1883
+ { size: [0.012, 0.012, 0.012], center: [0, 0.054, 0.015] },
1884
+ { size: [0.012, 0.012, 0.012], center: [0, 0.054, -0.015] }
1885
+ ];
1886
+ case "bishop":
1887
+ return [{ size: [3e-3, 0.02, 0.02], center: [0, 0.05, 0] }];
1888
+ case "queen": {
1889
+ const o = [];
1890
+ for (let n = 0; n < 8; n++) {
1891
+ const r = n / 8 * Math.PI * 2;
1892
+ o.push({
1893
+ size: [4e-3, 0.012, 4e-3],
1894
+ center: [Math.cos(r) * 0.011, 0.072, Math.sin(r) * 0.011]
1895
+ });
1896
+ }
1897
+ return o;
1898
+ }
1899
+ case "king":
1900
+ return [
1901
+ { size: [4e-3, 0.02, 4e-3], center: [0, 0.082, 0] },
1902
+ { size: [0.016, 4e-3, 4e-3], center: [0, 0.086, 0] }
1903
+ ];
1904
+ }
1905
+ }
1906
+ function ls(e) {
1907
+ return e !== "knight";
1908
+ }
1909
+ function sr(e) {
1910
+ const t = rr(e), o = [
1911
+ P("in", "GroupInput", 40, 80, {
1912
+ inputs: [],
1913
+ outputs: [{ id: "scale", name: "Scale", type: "float" }],
1914
+ properties: { Scale: 1 }
1915
+ }),
1916
+ P("poly", "PrimitivePolyline", 280, 80, {
1917
+ inputs: [],
1918
+ outputs: N(),
1919
+ properties: { points: _o(nr(e)) }
1920
+ }),
1921
+ P("lathe", "Lathe", 520, 80, {
1922
+ inputs: [{ id: "curve", name: "curve", type: "geometry" }],
1923
+ outputs: N(),
1924
+ properties: {
1925
+ segments: ve,
1926
+ axis: [0, 1, 0],
1927
+ origin: [0, 0, 0],
1928
+ startAngle: 0,
1929
+ endAngle: Math.PI * 2,
1930
+ fillCaps: !0
1931
+ }
1932
+ })
1933
+ ], n = [A("l_poly", "poly", "geometry", "lathe", "curve")];
1934
+ t.forEach((s, i) => {
1935
+ const a = `cube${i}`;
1936
+ o.push(
1937
+ P(a, "PrimitiveCube", 520, 200 + i * 80, {
1938
+ inputs: [],
1939
+ outputs: N(),
1940
+ properties: { size: s.size, center: s.center }
1941
+ })
1942
+ );
1943
+ });
1944
+ let r = "lathe";
1945
+ if (t.length > 0) {
1946
+ const s = [
1947
+ { id: "g0", name: "g0", type: "geometry" },
1948
+ ...t.map((i, a) => ({
1949
+ id: `g${a + 1}`,
1950
+ name: `g${a + 1}`,
1951
+ type: "geometry"
1952
+ }))
1953
+ ];
1954
+ o.push(
1955
+ P("join", "JoinGeometry", 760, 80, {
1956
+ inputs: s,
1957
+ outputs: N(),
1958
+ properties: {}
1959
+ })
1960
+ ), n.push(A("l_join0", "lathe", "geometry", "join", "g0")), t.forEach((i, a) => {
1961
+ n.push(A(`l_join${a + 1}`, `cube${a}`, "geometry", "join", `g${a + 1}`));
1962
+ }), r = "join";
1963
+ }
1964
+ return o.push(
1965
+ P("shade", "SetShadeSmooth", 1e3, 80, {
1966
+ inputs: [
1967
+ { id: "geo", name: "geometry", type: "geometry" },
1968
+ { id: "angle", name: "angle", type: "float" }
1969
+ ],
1970
+ outputs: N(),
1971
+ properties: { angle: 60 }
1972
+ }),
1973
+ P("bake", "BakeMeshMaps", 1120, 80, {
1974
+ inputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
1975
+ outputs: N(),
1976
+ properties: {
1977
+ bakeCurvature: !0,
1978
+ bakeAO: !0,
1979
+ bakeHeight: !0,
1980
+ curvatureContrast: 3.2,
1981
+ aoRadius: 0.012,
1982
+ aoSamples: 8,
1983
+ heightScale: 1
1984
+ }
1985
+ }),
1986
+ P("scale3", "CombineVector", 280, 240, {
1987
+ inputs: [
1988
+ { id: "x", name: "x", type: "float" },
1989
+ { id: "y", name: "y", type: "float" },
1990
+ { id: "z", name: "z", type: "float" }
1991
+ ],
1992
+ outputs: [{ id: "vector", name: "vector", type: "vec3" }],
1993
+ properties: { x: 1, y: 1, z: 1 }
1994
+ }),
1995
+ P("xform", "TransformGeometry", 1360, 80, {
1996
+ inputs: [
1997
+ { id: "geo", name: "geometry", type: "geometry" },
1998
+ { id: "t", name: "translation", type: "vec3" },
1999
+ { id: "r", name: "rotation", type: "vec3" },
2000
+ { id: "s", name: "scale", type: "vec3" }
2001
+ ],
2002
+ outputs: N(),
2003
+ properties: { translation: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] }
2004
+ }),
2005
+ P("out", "GroupOutput", 1600, 80, {
2006
+ inputs: [{ id: "geo_in", name: "geometry", type: "geometry" }],
2007
+ outputs: []
2008
+ })
2009
+ ), n.push(
2010
+ A("l_shade", r, "geometry", "shade", "geo"),
2011
+ A("l_bake", "shade", "geometry", "bake", "geometry"),
2012
+ A("l_sx", "in", "scale", "scale3", "x"),
2013
+ A("l_sy", "in", "scale", "scale3", "y"),
2014
+ A("l_sz", "in", "scale", "scale3", "z"),
2015
+ A("l_xf_geo", "bake", "geometry", "xform", "geo"),
2016
+ A("l_xf_s", "scale3", "vector", "xform", "s"),
2017
+ A("l_out", "xform", "geometry", "out", "geo_in")
2018
+ ), {
2019
+ id: `chess_${e}`,
2020
+ version: 1,
2021
+ metadata: { category: "prop", subcategory: "chess" },
2022
+ parameters: { Scale: { type: "float", value: 1 } },
2023
+ nodes: o,
2024
+ links: n
2025
+ };
2026
+ }
2027
+ const ir = [7e-3, 0.014, 7e-3], ar = [
2028
+ [5e-3, 0.058, 0],
2029
+ [-5e-3, 0.058, 0]
2030
+ ];
2031
+ function cr() {
2032
+ const e = [
2033
+ P("in", "GroupInput", 40, 80, {
2034
+ inputs: [],
2035
+ outputs: [{ id: "scale", name: "Scale", type: "float" }],
2036
+ properties: { Scale: 1 }
2037
+ }),
2038
+ P("pedestal", "PrimitivePolyline", 280, 40, {
2039
+ inputs: [],
2040
+ outputs: N(),
2041
+ properties: { points: _o(Zn) }
2042
+ }),
2043
+ P("lathe", "Lathe", 520, 40, {
2044
+ inputs: [{ id: "curve", name: "curve", type: "geometry" }],
2045
+ outputs: N(),
2046
+ properties: {
2047
+ segments: ve,
2048
+ axis: [0, 1, 0],
2049
+ origin: [0, 0, 0],
2050
+ startAngle: 0,
2051
+ endAngle: Math.PI * 2,
2052
+ fillCaps: !0
2053
+ }
2054
+ }),
2055
+ P("silhouette", "PrimitivePolyline", 280, 220, {
2056
+ inputs: [],
2057
+ outputs: N(),
2058
+ properties: { points: er(), fill: !0 }
2059
+ }),
2060
+ P("extrude", "ExtrudeMesh", 520, 220, {
2061
+ inputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
2062
+ outputs: N(),
2063
+ properties: { offset: or, scale: 1 }
2064
+ }),
2065
+ P("center", "TransformGeometry", 760, 220, {
2066
+ inputs: [
2067
+ { id: "geo", name: "geometry", type: "geometry" },
2068
+ { id: "t", name: "translation", type: "vec3" },
2069
+ { id: "r", name: "rotation", type: "vec3" },
2070
+ { id: "s", name: "scale", type: "vec3" }
2071
+ ],
2072
+ outputs: N(),
2073
+ properties: { translation: [-0.011, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] }
2074
+ })
2075
+ ], t = [
2076
+ A("l_ped", "pedestal", "geometry", "lathe", "curve"),
2077
+ A("l_sil", "silhouette", "geometry", "extrude", "geometry"),
2078
+ A("l_ctr", "extrude", "geometry", "center", "geo")
2079
+ ];
2080
+ return ar.forEach((o, n) => {
2081
+ const r = `ear${n}`;
2082
+ e.push(
2083
+ P(r, "PrimitiveCube", 520, 360 + n * 80, {
2084
+ inputs: [],
2085
+ outputs: N(),
2086
+ properties: { size: ir, center: o }
2087
+ })
2088
+ );
2089
+ }), e.push(
2090
+ P("join", "JoinGeometry", 1e3, 80, {
2091
+ inputs: [
2092
+ { id: "g0", name: "g0", type: "geometry" },
2093
+ { id: "g1", name: "g1", type: "geometry" },
2094
+ { id: "g2", name: "g2", type: "geometry" },
2095
+ { id: "g3", name: "g3", type: "geometry" }
2096
+ ],
2097
+ outputs: N(),
2098
+ properties: {}
2099
+ }),
2100
+ P("shade", "SetShadeSmooth", 1240, 80, {
2101
+ inputs: [
2102
+ { id: "geo", name: "geometry", type: "geometry" },
2103
+ { id: "angle", name: "angle", type: "float" }
2104
+ ],
2105
+ outputs: N(),
2106
+ properties: { angle: 60 }
2107
+ }),
2108
+ P("bake", "BakeMeshMaps", 1360, 80, {
2109
+ inputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
2110
+ outputs: N(),
2111
+ properties: {
2112
+ bakeCurvature: !0,
2113
+ bakeAO: !0,
2114
+ bakeHeight: !0,
2115
+ curvatureContrast: 3.2,
2116
+ aoRadius: 0.012,
2117
+ aoSamples: 8,
2118
+ heightScale: 1
2119
+ }
2120
+ }),
2121
+ P("scale3", "CombineVector", 280, 400, {
2122
+ inputs: [
2123
+ { id: "x", name: "x", type: "float" },
2124
+ { id: "y", name: "y", type: "float" },
2125
+ { id: "z", name: "z", type: "float" }
2126
+ ],
2127
+ outputs: [{ id: "vector", name: "vector", type: "vec3" }],
2128
+ properties: { x: 1, y: 1, z: 1 }
2129
+ }),
2130
+ P("xform", "TransformGeometry", 1600, 80, {
2131
+ inputs: [
2132
+ { id: "geo", name: "geometry", type: "geometry" },
2133
+ { id: "t", name: "translation", type: "vec3" },
2134
+ { id: "r", name: "rotation", type: "vec3" },
2135
+ { id: "s", name: "scale", type: "vec3" }
2136
+ ],
2137
+ outputs: N(),
2138
+ properties: { translation: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] }
2139
+ }),
2140
+ P("out", "GroupOutput", 1840, 80, {
2141
+ inputs: [{ id: "geo_in", name: "geometry", type: "geometry" }],
2142
+ outputs: []
2143
+ })
2144
+ ), t.push(
2145
+ A("l_join0", "lathe", "geometry", "join", "g0"),
2146
+ A("l_join1", "center", "geometry", "join", "g1"),
2147
+ A("l_join2", "ear0", "geometry", "join", "g2"),
2148
+ A("l_join3", "ear1", "geometry", "join", "g3"),
2149
+ A("l_shade", "join", "geometry", "shade", "geo"),
2150
+ A("l_bake", "shade", "geometry", "bake", "geometry"),
2151
+ A("l_sx", "in", "scale", "scale3", "x"),
2152
+ A("l_sy", "in", "scale", "scale3", "y"),
2153
+ A("l_sz", "in", "scale", "scale3", "z"),
2154
+ A("l_xf_geo", "bake", "geometry", "xform", "geo"),
2155
+ A("l_xf_s", "scale3", "vector", "xform", "s"),
2156
+ A("l_out", "xform", "geometry", "out", "geo_in")
2157
+ ), {
2158
+ id: "chess_knight",
2159
+ version: 1,
2160
+ metadata: { category: "prop", subcategory: "chess" },
2161
+ parameters: { Scale: { type: "float", value: 1 } },
2162
+ nodes: e,
2163
+ links: t
2164
+ };
2165
+ }
2166
+ let qe = !1;
2167
+ function wo() {
2168
+ qe || (To({ initCsg: !1 }), qe = !0);
2169
+ }
2170
+ function de(e, t, o) {
2171
+ wo();
2172
+ const n = Oo.executeDetailed(e, t);
2173
+ if (!n.ok || !n.geometry) {
2174
+ const i = n.errors.map((a) => a.message).join("; ") || "no geometry";
2175
+ throw new Error(`GPROC ${e.id}: ${i}`);
2176
+ }
2177
+ const r = ro(n.geometry, 1), s = r ? so(r) : null;
2178
+ if (!s)
2179
+ throw new Error(`GPROC ${e.id}: empty engine mesh`);
2180
+ return new Lt(s.vertices, s.indices, o);
2181
+ }
2182
+ function hs(e, t = 0.012) {
2183
+ wo();
2184
+ const o = Po(e);
2185
+ if (!o) return e;
2186
+ const n = Ro(o, {
2187
+ aoRadius: t,
2188
+ aoSamples: 8,
2189
+ curvatureContrast: 3.2,
2190
+ bakeCurvature: !0,
2191
+ bakeAO: !0,
2192
+ bakeHeight: !0
2193
+ }), r = ro(n, 1), s = r ? so(r) : null;
2194
+ return s ? new Lt(s.vertices, s.indices, e.name) : e;
2195
+ }
2196
+ const ur = me, lr = M.fromValues(0, 1, 0), hr = M.fromValues(1, 0, 0);
2197
+ function vo(e) {
2198
+ let t = 0;
2199
+ for (let o = 0; o < e.length; o++) {
2200
+ const n = (o + 1) % e.length;
2201
+ t += e[o][0] * e[n][1] - e[n][0] * e[o][1];
2202
+ }
2203
+ return t * 0.5;
2204
+ }
2205
+ function kt(e, t, o, n, r, s) {
2206
+ return (o - e) * (s - t) - (n - t) * (r - e);
2207
+ }
2208
+ function pr(e, t, o, n) {
2209
+ const r = kt(t[0], t[1], o[0], o[1], e[0], e[1]), s = kt(o[0], o[1], n[0], n[1], e[0], e[1]), i = kt(n[0], n[1], t[0], t[1], e[0], e[1]), a = r < 0 || s < 0 || i < 0, p = r > 0 || s > 0 || i > 0;
2210
+ return !(a && p);
2211
+ }
2212
+ function fr(e) {
2213
+ const t = e.length;
2214
+ if (t < 3) return [];
2215
+ const o = Array.from({ length: t }, (i, a) => a), n = vo(e) >= 0, r = [];
2216
+ let s = 0;
2217
+ for (; o.length > 3 && s++ < t * t; ) {
2218
+ let i = !1;
2219
+ for (let a = 0; a < o.length; a++) {
2220
+ const p = o[(a + o.length - 1) % o.length], h = o[a], c = o[(a + 1) % o.length], f = e[p], l = e[h], y = e[c], k = kt(f[0], f[1], l[0], l[1], y[0], y[1]);
2221
+ if (n ? k <= 0 : k >= 0) continue;
2222
+ let _ = !1;
2223
+ for (const b of o)
2224
+ if (!(b === p || b === h || b === c) && pr(e[b], f, l, y)) {
2225
+ _ = !0;
2226
+ break;
2227
+ }
2228
+ if (!_) {
2229
+ r.push(n ? [p, h, c] : [p, c, h]), o.splice(a, 1), i = !0;
2230
+ break;
2231
+ }
2232
+ }
2233
+ if (!i) break;
2234
+ }
2235
+ if (o.length === 3) {
2236
+ const [i, a, p] = o;
2237
+ if (i !== void 0 && a !== void 0 && p !== void 0) {
2238
+ const h = e[i], c = e[a], f = e[p], l = kt(h[0], h[1], c[0], c[1], f[0], f[1]);
2239
+ r.push(l >= 0 ? [i, a, p] : [i, p, a]);
2240
+ }
2241
+ }
2242
+ return r;
2243
+ }
2244
+ class dr {
2245
+ constructor() {
2246
+ F(this, "verts", []);
2247
+ F(this, "indices", []);
2248
+ }
2249
+ get vertexCount() {
2250
+ return this.verts.length / ur;
2251
+ }
2252
+ addVertex(t, o, n, r, s, i, a, p, h) {
2253
+ const c = M.fromValues(i, a, p), f = M.length(c) || 1;
2254
+ M.scale(c, c, 1 / f);
2255
+ const l = M.create();
2256
+ h ? M.set(l, h[0], h[1], h[2]) : M.cross(l, Math.abs(c[1]) > 0.95 ? hr : lr, c), M.normalize(l, l);
2257
+ const y = M.create();
2258
+ M.cross(y, c, l);
2259
+ const k = this.vertexCount;
2260
+ return this.verts.push(
2261
+ t,
2262
+ o,
2263
+ n,
2264
+ r,
2265
+ s,
2266
+ r,
2267
+ s,
2268
+ c[0],
2269
+ c[1],
2270
+ c[2],
2271
+ l[0],
2272
+ l[1],
2273
+ l[2],
2274
+ y[0],
2275
+ y[1],
2276
+ y[2],
2277
+ 1,
2278
+ 1,
2279
+ 1,
2280
+ 1
2281
+ ), k;
2282
+ }
2283
+ addTri(t, o, n) {
2284
+ this.indices.push(t, o, n);
2285
+ }
2286
+ /**
2287
+ * Fan from `pts[0]`. Winding is flipped when the first triangle's normal
2288
+ * points against `outward` so callers can list vertices in either order.
2289
+ */
2290
+ addConvexPolygon(t, o) {
2291
+ if (t.length < 3) return;
2292
+ const n = t[0], r = t[1], s = t[2], i = r[0] - n[0], a = r[1] - n[1], p = r[2] - n[2], h = s[0] - n[0], c = s[1] - n[1], f = s[2] - n[2], l = a * f - p * c, y = p * h - i * f, k = i * c - a * h, _ = l * o[0] + y * o[1] + k * o[2] < 0, b = Math.hypot(l, y, k) || 1, E = _ ? [-l / b, -y / b, -k / b] : [l / b, y / b, k / b], S = t.map((w, x) => {
2293
+ const R = t.length === 4 ? x === 1 || x === 2 ? 1 : 0 : x / t.length, H = t.length === 4 && x >= 2 ? 1 : 0;
2294
+ return this.addVertex(w[0], w[1], w[2], R, H, E[0], E[1], E[2]);
2295
+ });
2296
+ for (let w = 1; w < S.length - 1; w++)
2297
+ _ ? this.addTri(S[0], S[w + 1], S[w]) : this.addTri(S[0], S[w], S[w + 1]);
2298
+ }
2299
+ /**
2300
+ * AABB with a uniform edge chamfer. Original faces stay on the AABB planes
2301
+ * and shrink by `bevel`; 12 edge quads + 8 corner triangles fill the cuts.
2302
+ */
2303
+ addChamferedBox(t, o, n, r, s, i, a) {
2304
+ const p = Math.min(a, r * 0.45, s * 0.45, i * 0.45), h = r - p, c = s - p, f = i - p, l = (y, k, _) => [
2305
+ t + y,
2306
+ o + k,
2307
+ n + _
2308
+ ];
2309
+ this.addConvexPolygon(
2310
+ [l(-h, s, f), l(h, s, f), l(h, s, -f), l(-h, s, -f)],
2311
+ [0, 1, 0]
2312
+ ), this.addConvexPolygon(
2313
+ [l(-h, -s, -f), l(h, -s, -f), l(h, -s, f), l(-h, -s, f)],
2314
+ [0, -1, 0]
2315
+ ), this.addConvexPolygon(
2316
+ [l(r, -c, f), l(r, -c, -f), l(r, c, -f), l(r, c, f)],
2317
+ [1, 0, 0]
2318
+ ), this.addConvexPolygon(
2319
+ [l(-r, -c, -f), l(-r, -c, f), l(-r, c, f), l(-r, c, -f)],
2320
+ [-1, 0, 0]
2321
+ ), this.addConvexPolygon(
2322
+ [l(-h, -c, i), l(h, -c, i), l(h, c, i), l(-h, c, i)],
2323
+ [0, 0, 1]
2324
+ ), this.addConvexPolygon(
2325
+ [l(h, -c, -i), l(-h, -c, -i), l(-h, c, -i), l(h, c, -i)],
2326
+ [0, 0, -1]
2327
+ ), this.addConvexPolygon(
2328
+ [l(-h, s, f), l(h, s, f), l(h, c, i), l(-h, c, i)],
2329
+ [0, 1, 1]
2330
+ ), this.addConvexPolygon(
2331
+ [l(h, s, -f), l(-h, s, -f), l(-h, c, -i), l(h, c, -i)],
2332
+ [0, 1, -1]
2333
+ ), this.addConvexPolygon(
2334
+ [l(-h, -c, i), l(h, -c, i), l(h, -s, f), l(-h, -s, f)],
2335
+ [0, -1, 1]
2336
+ ), this.addConvexPolygon(
2337
+ [l(h, -c, -i), l(-h, -c, -i), l(-h, -s, -f), l(h, -s, -f)],
2338
+ [0, -1, -1]
2339
+ ), this.addConvexPolygon(
2340
+ [l(h, s, f), l(h, s, -f), l(r, c, -f), l(r, c, f)],
2341
+ [1, 1, 0]
2342
+ ), this.addConvexPolygon(
2343
+ [l(-h, s, -f), l(-h, s, f), l(-r, c, f), l(-r, c, -f)],
2344
+ [-1, 1, 0]
2345
+ ), this.addConvexPolygon(
2346
+ [l(h, -s, -f), l(h, -s, f), l(r, -c, f), l(r, -c, -f)],
2347
+ [1, -1, 0]
2348
+ ), this.addConvexPolygon(
2349
+ [l(-h, -s, f), l(-h, -s, -f), l(-r, -c, -f), l(-r, -c, f)],
2350
+ [-1, -1, 0]
2351
+ ), this.addConvexPolygon(
2352
+ [l(r, c, f), l(r, -c, f), l(h, -c, i), l(h, c, i)],
2353
+ [1, 0, 1]
2354
+ ), this.addConvexPolygon(
2355
+ [l(r, -c, -f), l(r, c, -f), l(h, c, -i), l(h, -c, -i)],
2356
+ [1, 0, -1]
2357
+ ), this.addConvexPolygon(
2358
+ [l(-r, -c, f), l(-r, c, f), l(-h, c, i), l(-h, -c, i)],
2359
+ [-1, 0, 1]
2360
+ ), this.addConvexPolygon(
2361
+ [l(-r, c, -f), l(-r, -c, -f), l(-h, -c, -i), l(-h, c, -i)],
2362
+ [-1, 0, -1]
2363
+ ), this.addConvexPolygon([l(h, s, f), l(r, c, f), l(h, c, i)], [1, 1, 1]), this.addConvexPolygon([l(h, s, -f), l(h, c, -i), l(r, c, -f)], [1, 1, -1]), this.addConvexPolygon([l(-h, s, f), l(-h, c, i), l(-r, c, f)], [-1, 1, 1]), this.addConvexPolygon([l(-h, s, -f), l(-r, c, -f), l(-h, c, -i)], [-1, 1, -1]), this.addConvexPolygon([l(h, -s, f), l(h, -c, i), l(r, -c, f)], [1, -1, 1]), this.addConvexPolygon([l(h, -s, -f), l(r, -c, -f), l(h, -c, -i)], [1, -1, -1]), this.addConvexPolygon([l(-h, -s, f), l(-r, -c, f), l(-h, -c, i)], [-1, -1, 1]), this.addConvexPolygon([l(-h, -s, -f), l(-h, -c, -i), l(-r, -c, -f)], [-1, -1, -1]);
2364
+ }
2365
+ /** Axis-aligned box. Half-extents hx,hy,hz. Origin at centre. */
2366
+ addBox(t, o, n, r, s, i) {
2367
+ const a = [
2368
+ {
2369
+ n: [0, 0, 1],
2370
+ corners: [
2371
+ [t - r, o - s, n + i],
2372
+ [t + r, o - s, n + i],
2373
+ [t + r, o + s, n + i],
2374
+ [t - r, o + s, n + i]
2375
+ ]
2376
+ },
2377
+ {
2378
+ n: [0, 0, -1],
2379
+ corners: [
2380
+ [t + r, o - s, n - i],
2381
+ [t - r, o - s, n - i],
2382
+ [t - r, o + s, n - i],
2383
+ [t + r, o + s, n - i]
2384
+ ]
2385
+ },
2386
+ {
2387
+ n: [1, 0, 0],
2388
+ corners: [
2389
+ [t + r, o - s, n + i],
2390
+ [t + r, o - s, n - i],
2391
+ [t + r, o + s, n - i],
2392
+ [t + r, o + s, n + i]
2393
+ ]
2394
+ },
2395
+ {
2396
+ n: [-1, 0, 0],
2397
+ corners: [
2398
+ [t - r, o - s, n - i],
2399
+ [t - r, o - s, n + i],
2400
+ [t - r, o + s, n + i],
2401
+ [t - r, o + s, n - i]
2402
+ ]
2403
+ },
2404
+ {
2405
+ n: [0, 1, 0],
2406
+ corners: [
2407
+ [t - r, o + s, n + i],
2408
+ [t + r, o + s, n + i],
2409
+ [t + r, o + s, n - i],
2410
+ [t - r, o + s, n - i]
2411
+ ]
2412
+ },
2413
+ {
2414
+ n: [0, -1, 0],
2415
+ corners: [
2416
+ [t - r, o - s, n - i],
2417
+ [t + r, o - s, n - i],
2418
+ [t + r, o - s, n + i],
2419
+ [t - r, o - s, n + i]
2420
+ ]
2421
+ }
2422
+ ];
2423
+ for (const p of a) {
2424
+ const h = [
2425
+ [0, 0],
2426
+ [1, 0],
2427
+ [1, 1],
2428
+ [0, 1]
2429
+ ], c = p.corners.map(
2430
+ (f, l) => this.addVertex(f[0], f[1], f[2], h[l][0], h[l][1], p.n[0], p.n[1], p.n[2])
2431
+ );
2432
+ this.addTri(c[0], c[1], c[2]), this.addTri(c[0], c[2], c[3]);
2433
+ }
2434
+ }
2435
+ /**
2436
+ * Revolution of a (y, radius) profile around Y. First ring at profile[0].y.
2437
+ * Winding is CCW from outside (WebGPU back-face cull, same convention as engine cylinders).
2438
+ */
2439
+ addLathe(t, o = 20) {
2440
+ if (t.length < 2) return;
2441
+ const n = [];
2442
+ for (let s = 0; s < t.length; s++) {
2443
+ const i = t[s][0], a = t[s][1], p = t[Math.max(0, s - 1)], h = t[Math.min(t.length - 1, s + 1)], c = h[0] - p[0];
2444
+ let l = -(h[1] - p[1]), y = c;
2445
+ const k = Math.hypot(l, y) || 1;
2446
+ l /= k, y /= k;
2447
+ const _ = [], b = s / (t.length - 1);
2448
+ for (let E = 0; E <= o; E++) {
2449
+ const S = E / o, w = S * Math.PI * 2, x = Math.cos(w) * a, R = Math.sin(w) * a, H = a > 1e-6 ? Math.cos(w) * y : 0, j = a > 1e-6 ? Math.sin(w) * y : 0, ct = Math.hypot(-R, x) || 1;
2450
+ _.push(this.addVertex(x, i, R, S, b, H, l, j, [-R / ct, 0, x / ct]));
2451
+ }
2452
+ n.push(_);
2453
+ }
2454
+ for (let s = 0; s < n.length - 1; s++) {
2455
+ const i = n[s], a = n[s + 1];
2456
+ for (let p = 0; p < o; p++)
2457
+ this.addTri(i[p], a[p], a[p + 1]), this.addTri(i[p], a[p + 1], i[p + 1]);
2458
+ }
2459
+ const r = (s, i, a, p) => {
2460
+ if (a < 1e-5) return;
2461
+ const h = this.addVertex(0, i, 0, 0.5, 0.5, 0, p ? 1 : -1, 0);
2462
+ for (let c = 0; c < o; c++)
2463
+ p ? this.addTri(h, s[c + 1], s[c]) : this.addTri(h, s[c], s[c + 1]);
2464
+ };
2465
+ r(n[0], t[0][0], t[0][1], !1), r(
2466
+ n[n.length - 1],
2467
+ t[t.length - 1][0],
2468
+ t[t.length - 1][1],
2469
+ !0
2470
+ );
2471
+ }
2472
+ /**
2473
+ * Extrudes a YZ polyline (y, z) along ±X by halfThickness.
2474
+ * Belt vertices use silhouette normals; cap vertices use ±X so the flat sides light correctly.
2475
+ */
2476
+ addExtrudedYz(t, o) {
2477
+ if (t.length < 3) return;
2478
+ const n = vo(t) >= 0 ? [...t] : [...t].reverse(), r = n.length, s = [], i = [], a = [], p = [];
2479
+ for (let c = 0; c < r; c++) {
2480
+ const f = n[c][0], l = n[c][1], y = n[(c + r - 1) % r], k = n[(c + 1) % r], _ = k[0] - y[0], E = k[1] - y[1], S = -_, w = c / r;
2481
+ s.push(this.addVertex(-o, f, l, 0, w, 0, E, S)), i.push(this.addVertex(o, f, l, 1, w, 0, E, S)), a.push(this.addVertex(-o, f, l, 0.25, w, -1, 0, 0)), p.push(this.addVertex(o, f, l, 0.75, w, 1, 0, 0));
2482
+ }
2483
+ for (let c = 0; c < r; c++) {
2484
+ const f = (c + 1) % r;
2485
+ this.addTri(s[c], s[f], i[f]), this.addTri(s[c], i[f], i[c]);
2486
+ }
2487
+ const h = fr(n);
2488
+ for (const [c, f, l] of h)
2489
+ this.addTri(p[c], p[f], p[l]), this.addTri(a[c], a[l], a[f]);
2490
+ }
2491
+ toMesh(t) {
2492
+ const o = new Float32Array(this.verts), n = this.indices.length > 65535 ? new Uint32Array(this.indices) : new Uint16Array(this.indices);
2493
+ return new Lt(o, n, t);
2494
+ }
2495
+ }
2496
+ function ps() {
2497
+ const e = new dr();
2498
+ return e.addLathe(ko(bo, 2), ve), e.toMesh("chess-pawn-uv");
2499
+ }
2500
+ function fs(e) {
2501
+ return e === "knight" ? de(cr(), { Scale: 1 }, "chess-knight") : de(sr(e), { Scale: 1 }, `chess-${e}`);
2502
+ }
2503
+ function ds(e) {
2504
+ switch (e) {
2505
+ case "pawn":
2506
+ return 0.054;
2507
+ case "rook":
2508
+ return 0.06;
2509
+ case "knight":
2510
+ return 0.062;
2511
+ case "bishop":
2512
+ return 0.062;
2513
+ case "queen":
2514
+ return 0.078;
2515
+ case "king":
2516
+ return 0.092;
2517
+ default:
2518
+ return 0.054;
2519
+ }
2520
+ }
2521
+ const yt = me, Xt = 7, Zt = 10, Jt = 13;
2522
+ function ms(e) {
2523
+ const t = e.vertices, o = e.indices, n = e.aabb.min[1] ?? 0, r = e.aabb.max[1] ?? 1, s = Math.max(1e-6, r - n), i = new Float32Array(o.length * yt), a = o.length > 65535 ? new Uint32Array(o.length) : new Uint16Array(o.length);
2524
+ for (let p = 0; p < o.length; p += 3) {
2525
+ const h = [o[p], o[p + 1], o[p + 2]], c = [];
2526
+ for (const y of h) {
2527
+ const k = y * yt, _ = t[k], b = t[k + 1], E = t[k + 2];
2528
+ let S = Math.atan2(E, _) / (Math.PI * 2);
2529
+ S < 0 && (S += 1), _ * _ + E * E < 1e-10 && (S = 0.5), c.push([S, (b - n) / s]);
2530
+ }
2531
+ const f = Math.min(c[0][0], c[1][0], c[2][0]);
2532
+ if (Math.max(c[0][0], c[1][0], c[2][0]) - f > 0.5)
2533
+ for (const y of c)
2534
+ y[0] < 0.5 && (y[0] += 1);
2535
+ for (let y = 0; y < 3; y++) {
2536
+ const k = h[y] * yt, _ = p + y, b = _ * yt;
2537
+ i.set(t.subarray(k, k + yt), b);
2538
+ const E = c[y][0], S = c[y][1];
2539
+ i[b + 3] = E, i[b + 4] = S, i[b + 5] = E, i[b + 6] = S;
2540
+ const w = t[k], x = t[k + 2], R = Math.hypot(-x, w);
2541
+ if (R > 1e-6) {
2542
+ const H = -x / R, j = w / R;
2543
+ i[b + Zt] = H, i[b + Zt + 1] = 0, i[b + Zt + 2] = j;
2544
+ const ct = i[b + Xt], Ce = i[b + Xt + 1], Mo = i[b + Xt + 2];
2545
+ let Se = Ce * j, Ee = Mo * H - ct * j, Me = -Ce * H;
2546
+ const Vt = Math.hypot(Se, Ee, Me) || 1;
2547
+ i[b + Jt] = Se / Vt, i[b + Jt + 1] = Ee / Vt, i[b + Jt + 2] = Me / Vt;
2548
+ }
2549
+ a[_] = _;
2550
+ }
2551
+ }
2552
+ return new Lt(i, a, e.name);
2553
+ }
2554
+ function mr() {
2555
+ return {
2556
+ id: "chess_board",
2557
+ version: 1,
2558
+ metadata: {
2559
+ category: "prop",
2560
+ subcategory: "chess"
2561
+ },
2562
+ parameters: {
2563
+ ExtentXz: { type: "float", value: K },
2564
+ Height: { type: "float", value: Pt },
2565
+ Bevel: { type: "float", value: ht }
2566
+ },
2567
+ nodes: [
2568
+ {
2569
+ id: "in",
2570
+ type: "GroupInput",
2571
+ position: { x: 40, y: 80 },
2572
+ inputs: [],
2573
+ outputs: [
2574
+ { id: "extentXz", name: "ExtentXz", type: "float" },
2575
+ { id: "height", name: "Height", type: "float" },
2576
+ { id: "bevel", name: "Bevel", type: "float" }
2577
+ ],
2578
+ properties: {
2579
+ ExtentXz: K,
2580
+ Height: Pt,
2581
+ Bevel: ht
2582
+ }
2583
+ },
2584
+ {
2585
+ id: "bevel2",
2586
+ type: "Math",
2587
+ position: { x: 280, y: 200 },
2588
+ inputs: [
2589
+ { id: "a", name: "a", type: "float" },
2590
+ { id: "b", name: "b", type: "float" }
2591
+ ],
2592
+ outputs: [{ id: "value", name: "value", type: "float" }],
2593
+ properties: { operation: "MUL", a: 0, b: 2 }
2594
+ },
2595
+ {
2596
+ id: "outer",
2597
+ type: "Math",
2598
+ position: { x: 480, y: 80 },
2599
+ inputs: [
2600
+ { id: "a", name: "a", type: "float" },
2601
+ { id: "b", name: "b", type: "float" }
2602
+ ],
2603
+ outputs: [{ id: "value", name: "value", type: "float" }],
2604
+ properties: { operation: "ADD", a: 0, b: 0 }
2605
+ },
2606
+ {
2607
+ id: "size",
2608
+ type: "CombineVector",
2609
+ position: { x: 680, y: 80 },
2610
+ inputs: [
2611
+ { id: "x", name: "x", type: "float" },
2612
+ { id: "y", name: "y", type: "float" },
2613
+ { id: "z", name: "z", type: "float" }
2614
+ ],
2615
+ outputs: [{ id: "vector", name: "vector", type: "vec3" }],
2616
+ properties: { x: 0, y: 0, z: 0 }
2617
+ },
2618
+ {
2619
+ id: "box",
2620
+ type: "PrimitiveChamferedBox",
2621
+ position: { x: 900, y: 80 },
2622
+ inputs: [
2623
+ { id: "size", name: "size", type: "vec3" },
2624
+ { id: "center", name: "center", type: "vec3" },
2625
+ { id: "bevel", name: "bevel", type: "float" }
2626
+ ],
2627
+ outputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
2628
+ properties: {
2629
+ size: [
2630
+ K + 2 * ht,
2631
+ Pt,
2632
+ K + 2 * ht
2633
+ ],
2634
+ center: [0, 0, 0],
2635
+ bevel: ht
2636
+ }
2637
+ },
2638
+ {
2639
+ id: "bake",
2640
+ type: "BakeMeshMaps",
2641
+ position: { x: 1140, y: 80 },
2642
+ inputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
2643
+ outputs: [{ id: "geometry", name: "geometry", type: "geometry" }],
2644
+ properties: {
2645
+ bakeCurvature: !0,
2646
+ bakeAO: !0,
2647
+ bakeHeight: !0,
2648
+ curvatureContrast: 2.8,
2649
+ aoRadius: 0.04,
2650
+ aoSamples: 8,
2651
+ heightScale: 1
2652
+ }
2653
+ },
2654
+ {
2655
+ id: "out",
2656
+ type: "GroupOutput",
2657
+ position: { x: 1380, y: 80 },
2658
+ inputs: [{ id: "geo_in", name: "geometry", type: "geometry" }],
2659
+ outputs: []
2660
+ }
2661
+ ],
2662
+ links: [
2663
+ {
2664
+ id: "l_bevel",
2665
+ fromNodeId: "in",
2666
+ fromSocketId: "bevel",
2667
+ toNodeId: "bevel2",
2668
+ toSocketId: "a"
2669
+ },
2670
+ {
2671
+ id: "l_extent",
2672
+ fromNodeId: "in",
2673
+ fromSocketId: "extentXz",
2674
+ toNodeId: "outer",
2675
+ toSocketId: "a"
2676
+ },
2677
+ {
2678
+ id: "l_bevel2",
2679
+ fromNodeId: "bevel2",
2680
+ fromSocketId: "value",
2681
+ toNodeId: "outer",
2682
+ toSocketId: "b"
2683
+ },
2684
+ {
2685
+ id: "l_outer_x",
2686
+ fromNodeId: "outer",
2687
+ fromSocketId: "value",
2688
+ toNodeId: "size",
2689
+ toSocketId: "x"
2690
+ },
2691
+ {
2692
+ id: "l_height",
2693
+ fromNodeId: "in",
2694
+ fromSocketId: "height",
2695
+ toNodeId: "size",
2696
+ toSocketId: "y"
2697
+ },
2698
+ {
2699
+ id: "l_outer_z",
2700
+ fromNodeId: "outer",
2701
+ fromSocketId: "value",
2702
+ toNodeId: "size",
2703
+ toSocketId: "z"
2704
+ },
2705
+ {
2706
+ id: "l_size",
2707
+ fromNodeId: "size",
2708
+ fromSocketId: "vector",
2709
+ toNodeId: "box",
2710
+ toSocketId: "size"
2711
+ },
2712
+ {
2713
+ id: "l_box_bevel",
2714
+ fromNodeId: "in",
2715
+ fromSocketId: "bevel",
2716
+ toNodeId: "box",
2717
+ toSocketId: "bevel"
2718
+ },
2719
+ {
2720
+ id: "l_bake",
2721
+ fromNodeId: "box",
2722
+ fromSocketId: "geometry",
2723
+ toNodeId: "bake",
2724
+ toSocketId: "geometry"
2725
+ },
2726
+ {
2727
+ id: "l_out",
2728
+ fromNodeId: "bake",
2729
+ fromSocketId: "geometry",
2730
+ toNodeId: "out",
2731
+ toSocketId: "geo_in"
2732
+ }
2733
+ ]
2734
+ };
2735
+ }
2736
+ const gr = me;
2737
+ function yr(e) {
2738
+ const t = e.vertices;
2739
+ for (let o = 0; o < t.length; o += gr) {
2740
+ const n = t[o], r = t[o + 1], s = t[o + 2], i = t[o + 7], a = t[o + 8], p = t[o + 9], h = Math.abs(i), c = Math.abs(a), f = Math.abs(p);
2741
+ let l, y, k, _, b;
2742
+ c >= h && c >= f ? (l = n, y = s, k = 1, _ = 0, b = 0) : h >= f ? (l = s, y = r, k = 0, _ = 0, b = 1) : (l = n, y = r, k = 1, _ = 0, b = 0), t[o + 3] = l, t[o + 4] = y, t[o + 5] = l, t[o + 6] = y;
2743
+ const E = k * i + _ * a + b * p;
2744
+ let S = k - E * i, w = _ - E * a, x = b - E * p;
2745
+ const R = Math.hypot(S, w, x) || 1;
2746
+ S /= R, w /= R, x /= R, t[o + 10] = S, t[o + 11] = w, t[o + 12] = x, t[o + 13] = a * x - p * w, t[o + 14] = p * S - i * x, t[o + 15] = i * w - a * S;
2747
+ }
2748
+ return e;
2749
+ }
2750
+ function gs(e = K, t = Pt, o = ht) {
2751
+ return yr(
2752
+ de(
2753
+ mr(),
2754
+ { ExtentXz: e, Height: t, Bevel: o },
2755
+ "ChessBoardBody"
2756
+ )
2757
+ );
2758
+ }
2759
+ const br = "MarbleProceduralPBR", kr = "BrushedSteelProceduralPBR";
2760
+ function u(e, t, o) {
2761
+ return { id: e, name: t, dataType: o };
2762
+ }
2763
+ function g(e, t, o, n, r) {
2764
+ return { id: e, type: t, stage: "fragment", position: { x: o, y: n }, ...r };
2765
+ }
2766
+ function m(e, t, o, n) {
2767
+ return { fromNodeId: e, fromSocketId: t, toNodeId: o, toSocketId: n };
2768
+ }
2769
+ function ys() {
2770
+ return _r();
2771
+ }
2772
+ function _r() {
2773
+ const e = {
2774
+ seed: { name: "Seed", type: "f32", defaultValue: 11 },
2775
+ triplanarScale: { name: "Triplanar Scale", type: "f32", defaultValue: 2.4 },
2776
+ aoStrength: { name: "AO Strength", type: "f32", defaultValue: 0.22 },
2777
+ heightInfluence: { name: "Height Roughness", type: "f32", defaultValue: 0.02 },
2778
+ normalDetailScale: { name: "Normal Detail Scale", type: "f32", defaultValue: 0 },
2779
+ baseColor: {
2780
+ name: "Marble Color",
2781
+ type: "vec3f",
2782
+ defaultValue: [0.84, 0.78, 0.68]
2783
+ },
2784
+ accentColor: {
2785
+ name: "Rust Vein",
2786
+ type: "vec3f",
2787
+ defaultValue: [0.45, 0.28, 0.2]
2788
+ },
2789
+ wearColor: {
2790
+ name: "Grey Vein",
2791
+ type: "vec3f",
2792
+ defaultValue: [0.4, 0.38, 0.36]
2793
+ },
2794
+ edgeWear: { name: "Edge Wear", type: "f32", defaultValue: 0.04 },
2795
+ roughness: { name: "Roughness", type: "f32", defaultValue: 0.22 },
2796
+ metallic: { name: "Metallic", type: "f32", defaultValue: 0 },
2797
+ opacity: { name: "Opacity", type: "f32", defaultValue: 1 }
2798
+ }, t = [
2799
+ g("pbr_master", "PBRMasterNode", 1680, 200, {
2800
+ inputs: [
2801
+ u("albedo", "Albedo", "vec4f"),
2802
+ u("opacity", "Opacity", "f32"),
2803
+ u("normal", "Normal", "vec3f"),
2804
+ u("roughness_factor", "Roughness F", "f32"),
2805
+ u("metallic_factor", "Metallic F", "f32")
2806
+ ],
2807
+ outputs: []
2808
+ }),
2809
+ g("obj_pos", "GetObjectPosition", 0, 0, {
2810
+ inputs: [],
2811
+ outputs: [u("pos", "Position", "vec3f")]
2812
+ }),
2813
+ g("prop_scale", "Property", 180, 80, {
2814
+ data: { propertyName: "triplanarScale" },
2815
+ inputs: [],
2816
+ outputs: [u("out", "Out", "f32")]
2817
+ }),
2818
+ g("prop_seed", "Property", 180, 160, {
2819
+ data: { propertyName: "seed" },
2820
+ inputs: [],
2821
+ outputs: [u("out", "Out", "f32")]
2822
+ }),
2823
+ g("marble_fn", "CustomFunction", 380, 40, {
2824
+ data: { functionName: "marble_look" },
2825
+ inputs: [
2826
+ u("pos", "Position", "vec3f"),
2827
+ u("seed", "Seed", "f32"),
2828
+ u("scale", "Scale", "f32")
2829
+ ],
2830
+ outputs: [u("out", "Look", "vec4f")]
2831
+ }),
2832
+ g("split_mar", "SplitVec4", 560, 40, {
2833
+ inputs: [u("in", "In", "vec4f")],
2834
+ outputs: [
2835
+ u("x", "Rust", "f32"),
2836
+ u("y", "Grey", "f32"),
2837
+ u("z", "Cloud", "f32"),
2838
+ u("w", "Rough", "f32")
2839
+ ]
2840
+ }),
2841
+ g("vertex_color", "VertexColor", 0, 280, {
2842
+ inputs: [],
2843
+ outputs: [u("color", "Color", "vec4f")]
2844
+ }),
2845
+ g("mesh_maps", "MeshMaps", 220, 280, {
2846
+ inputs: [u("color", "Vertex Color", "vec4f")],
2847
+ outputs: [
2848
+ u("concavity", "Concavity", "f32"),
2849
+ u("convexity", "Convexity", "f32"),
2850
+ u("ao", "AO", "f32"),
2851
+ u("height", "Height", "f32")
2852
+ ]
2853
+ }),
2854
+ g("world_n", "GetWorldNormal", 0, 520, {
2855
+ inputs: [],
2856
+ outputs: [u("norm", "Normal", "vec3f")]
2857
+ }),
2858
+ g("prop_base", "Property", 760, 160, {
2859
+ data: { propertyName: "baseColor" },
2860
+ inputs: [],
2861
+ outputs: [u("out", "Out", "vec3f")]
2862
+ }),
2863
+ g("prop_accent", "Property", 760, 240, {
2864
+ data: { propertyName: "accentColor" },
2865
+ inputs: [],
2866
+ outputs: [u("out", "Out", "vec3f")]
2867
+ }),
2868
+ g("prop_wear", "Property", 760, 320, {
2869
+ data: { propertyName: "wearColor" },
2870
+ inputs: [],
2871
+ outputs: [u("out", "Out", "vec3f")]
2872
+ }),
2873
+ g("cloud_k", "ConstantFloat", 760, 400, {
2874
+ data: { value: 0.22 },
2875
+ inputs: [],
2876
+ outputs: [u("out", "Out", "f32")]
2877
+ }),
2878
+ g("cloud_amt", "Multiply", 980, 120, {
2879
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
2880
+ outputs: [u("out", "Out", "f32")]
2881
+ }),
2882
+ g("lerp_cloud", "Lerp", 1140, 80, {
2883
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
2884
+ outputs: [u("out", "Out", "vec3f")]
2885
+ }),
2886
+ g("lerp_grey", "Lerp", 1140, 200, {
2887
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
2888
+ outputs: [u("out", "Out", "vec3f")]
2889
+ }),
2890
+ g("lerp_rust", "Lerp", 1140, 320, {
2891
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
2892
+ outputs: [u("out", "Out", "vec3f")]
2893
+ }),
2894
+ g("prop_ao_str", "Property", 1140, 440, {
2895
+ data: { propertyName: "aoStrength" },
2896
+ inputs: [],
2897
+ outputs: [u("out", "Out", "f32")]
2898
+ }),
2899
+ g("one", "ConstantFloat", 1140, 520, {
2900
+ data: { value: 1 },
2901
+ inputs: [],
2902
+ outputs: [u("out", "Out", "f32")]
2903
+ }),
2904
+ g("ao_mix", "Lerp", 1320, 400, {
2905
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32"), u("t", "T", "f32")],
2906
+ outputs: [u("out", "Out", "f32")]
2907
+ }),
2908
+ g("mul_ao_color", "Multiply", 1480, 200, {
2909
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "f32")],
2910
+ outputs: [u("out", "Out", "vec3f")]
2911
+ }),
2912
+ g("prop_edge", "Property", 1140, 600, {
2913
+ data: { propertyName: "edgeWear" },
2914
+ inputs: [],
2915
+ outputs: [u("out", "Out", "f32")]
2916
+ }),
2917
+ g("wear_amt", "Multiply", 1320, 560, {
2918
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
2919
+ outputs: [u("out", "Out", "f32")]
2920
+ }),
2921
+ g("lerp_wear", "Lerp", 1480, 320, {
2922
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
2923
+ outputs: [u("out", "Out", "vec3f")]
2924
+ }),
2925
+ g("split_alb", "SplitVec3", 1480, 80, {
2926
+ inputs: [u("in", "In", "vec3f")],
2927
+ outputs: [u("x", "X", "f32"), u("y", "Y", "f32"), u("z", "Z", "f32")]
2928
+ }),
2929
+ g("prop_opacity", "Property", 1480, 640, {
2930
+ data: { propertyName: "opacity" },
2931
+ inputs: [],
2932
+ outputs: [u("out", "Out", "f32")]
2933
+ }),
2934
+ g("alb_rgba", "Combine", 1600, 80, {
2935
+ inputs: [
2936
+ u("r", "R", "f32"),
2937
+ u("g", "G", "f32"),
2938
+ u("b", "B", "f32"),
2939
+ u("a", "A", "f32")
2940
+ ],
2941
+ outputs: [u("out", "Out", "vec4f")]
2942
+ }),
2943
+ g("prop_rough", "Property", 1140, 720, {
2944
+ data: { propertyName: "roughness" },
2945
+ inputs: [],
2946
+ outputs: [u("out", "Out", "f32")]
2947
+ }),
2948
+ g("add_rough", "Add", 1320, 720, {
2949
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
2950
+ outputs: [u("out", "Out", "f32")]
2951
+ }),
2952
+ g("cavity_k", "ConstantFloat", 1140, 840, {
2953
+ data: { value: 0.08 },
2954
+ inputs: [],
2955
+ outputs: [u("out", "Out", "f32")]
2956
+ }),
2957
+ g("cavity_rough", "Multiply", 1320, 800, {
2958
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
2959
+ outputs: [u("out", "Out", "f32")]
2960
+ }),
2961
+ g("add_cavity_r", "Add", 1480, 720, {
2962
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
2963
+ outputs: [u("out", "Out", "f32")]
2964
+ }),
2965
+ g("clamp_rough", "Clamp", 1600, 720, {
2966
+ inputs: [u("in", "In", "f32"), u("min", "Min", "f32"), u("max", "Max", "f32")],
2967
+ outputs: [u("out", "Out", "f32")]
2968
+ }),
2969
+ g("zero", "ConstantFloat", 1480, 880, {
2970
+ data: { value: 0 },
2971
+ inputs: [],
2972
+ outputs: [u("out", "Out", "f32")]
2973
+ }),
2974
+ g("prop_metal", "Property", 1480, 960, {
2975
+ data: { propertyName: "metallic" },
2976
+ inputs: [],
2977
+ outputs: [u("out", "Out", "f32")]
2978
+ })
2979
+ ], o = [
2980
+ m("obj_pos", "pos", "marble_fn", "pos"),
2981
+ m("prop_seed", "out", "marble_fn", "seed"),
2982
+ m("prop_scale", "out", "marble_fn", "scale"),
2983
+ m("marble_fn", "out", "split_mar", "in"),
2984
+ m("vertex_color", "color", "mesh_maps", "color"),
2985
+ m("split_mar", "z", "cloud_amt", "a"),
2986
+ m("cloud_k", "out", "cloud_amt", "b"),
2987
+ m("prop_base", "out", "lerp_cloud", "a"),
2988
+ m("prop_wear", "out", "lerp_cloud", "b"),
2989
+ m("cloud_amt", "out", "lerp_cloud", "t"),
2990
+ m("lerp_cloud", "out", "lerp_grey", "a"),
2991
+ m("prop_wear", "out", "lerp_grey", "b"),
2992
+ m("split_mar", "y", "lerp_grey", "t"),
2993
+ m("lerp_grey", "out", "lerp_rust", "a"),
2994
+ m("prop_accent", "out", "lerp_rust", "b"),
2995
+ m("split_mar", "x", "lerp_rust", "t"),
2996
+ m("one", "out", "ao_mix", "a"),
2997
+ m("mesh_maps", "ao", "ao_mix", "b"),
2998
+ m("prop_ao_str", "out", "ao_mix", "t"),
2999
+ m("lerp_rust", "out", "mul_ao_color", "a"),
3000
+ m("ao_mix", "out", "mul_ao_color", "b"),
3001
+ m("mesh_maps", "convexity", "wear_amt", "a"),
3002
+ m("prop_edge", "out", "wear_amt", "b"),
3003
+ m("mul_ao_color", "out", "lerp_wear", "a"),
3004
+ m("prop_base", "out", "lerp_wear", "b"),
3005
+ m("wear_amt", "out", "lerp_wear", "t"),
3006
+ m("lerp_wear", "out", "split_alb", "in"),
3007
+ m("split_alb", "x", "alb_rgba", "r"),
3008
+ m("split_alb", "y", "alb_rgba", "g"),
3009
+ m("split_alb", "z", "alb_rgba", "b"),
3010
+ m("prop_opacity", "out", "alb_rgba", "a"),
3011
+ m("prop_rough", "out", "add_rough", "a"),
3012
+ m("split_mar", "w", "add_rough", "b"),
3013
+ m("mesh_maps", "concavity", "cavity_rough", "a"),
3014
+ m("cavity_k", "out", "cavity_rough", "b"),
3015
+ m("add_rough", "out", "add_cavity_r", "a"),
3016
+ m("cavity_rough", "out", "add_cavity_r", "b"),
3017
+ m("add_cavity_r", "out", "clamp_rough", "in"),
3018
+ m("zero", "out", "clamp_rough", "min"),
3019
+ m("one", "out", "clamp_rough", "max"),
3020
+ m("alb_rgba", "out", "pbr_master", "albedo"),
3021
+ m("prop_opacity", "out", "pbr_master", "opacity"),
3022
+ m("world_n", "norm", "pbr_master", "normal"),
3023
+ m("clamp_rough", "out", "pbr_master", "roughness_factor"),
3024
+ m("prop_metal", "out", "pbr_master", "metallic_factor")
3025
+ ];
3026
+ return { id: br, properties: e, nodes: t, connections: o };
3027
+ }
3028
+ function wr() {
3029
+ const e = {
3030
+ seed: { name: "Seed", type: "f32", defaultValue: 7 },
3031
+ triplanarScale: { name: "Triplanar Scale", type: "f32", defaultValue: 1.4 },
3032
+ aoStrength: { name: "AO Strength", type: "f32", defaultValue: 0.32 },
3033
+ heightInfluence: { name: "Height Roughness", type: "f32", defaultValue: 0.02 },
3034
+ normalDetailScale: { name: "Normal Detail Scale", type: "f32", defaultValue: 0 },
3035
+ baseColor: {
3036
+ name: "Steel Color",
3037
+ type: "vec3f",
3038
+ defaultValue: [0.17, 0.185, 0.2]
3039
+ },
3040
+ accentColor: {
3041
+ name: "Brush Highlight",
3042
+ type: "vec3f",
3043
+ defaultValue: [0.4, 0.42, 0.45]
3044
+ },
3045
+ wearColor: {
3046
+ name: "Blotch Color",
3047
+ type: "vec3f",
3048
+ defaultValue: [0.1, 0.105, 0.115]
3049
+ },
3050
+ edgeWear: { name: "Edge Wear", type: "f32", defaultValue: 0.05 },
3051
+ roughness: { name: "Roughness", type: "f32", defaultValue: 0.42 },
3052
+ metallic: { name: "Metallic", type: "f32", defaultValue: 0.96 },
3053
+ opacity: { name: "Opacity", type: "f32", defaultValue: 1 },
3054
+ anisotropy: { name: "Anisotropy", type: "f32", defaultValue: 0.88 },
3055
+ anisotropyRotation: { name: "Anisotropy Rotation", type: "f32", defaultValue: 0 }
3056
+ }, t = [
3057
+ g("pbr_master", "PBRMasterNode", 1680, 200, {
3058
+ inputs: [
3059
+ u("albedo", "Albedo", "vec4f"),
3060
+ u("opacity", "Opacity", "f32"),
3061
+ u("normal", "Normal", "vec3f"),
3062
+ u("roughness_factor", "Roughness F", "f32"),
3063
+ u("metallic_factor", "Metallic F", "f32"),
3064
+ u("anisotropy", "Anisotropy", "f32"),
3065
+ u("anisotropy_rotation", "Anisotropy Rot", "f32")
3066
+ ],
3067
+ outputs: []
3068
+ }),
3069
+ g("obj_pos", "GetObjectPosition", 0, 0, {
3070
+ inputs: [],
3071
+ outputs: [u("pos", "Position", "vec3f")]
3072
+ }),
3073
+ g("prop_scale", "Property", 180, 80, {
3074
+ data: { propertyName: "triplanarScale" },
3075
+ inputs: [],
3076
+ outputs: [u("out", "Out", "f32")]
3077
+ }),
3078
+ g("prop_seed", "Property", 180, 160, {
3079
+ data: { propertyName: "seed" },
3080
+ inputs: [],
3081
+ outputs: [u("out", "Out", "f32")]
3082
+ }),
3083
+ g("steel_look", "CustomFunction", 380, 40, {
3084
+ data: { functionName: "brushed_steel_look" },
3085
+ inputs: [
3086
+ u("pos", "Position", "vec3f"),
3087
+ u("seed", "Seed", "f32"),
3088
+ u("scale", "Scale", "f32")
3089
+ ],
3090
+ outputs: [u("out", "Look", "vec4f")]
3091
+ }),
3092
+ g("split_steel", "SplitVec4", 560, 40, {
3093
+ inputs: [u("in", "In", "vec4f")],
3094
+ outputs: [
3095
+ u("x", "Grain", "f32"),
3096
+ u("y", "Blotch", "f32"),
3097
+ u("z", "Bump", "f32"),
3098
+ u("w", "Rough", "f32")
3099
+ ]
3100
+ }),
3101
+ g("vertex_color", "VertexColor", 0, 280, {
3102
+ inputs: [],
3103
+ outputs: [u("color", "Color", "vec4f")]
3104
+ }),
3105
+ g("mesh_maps", "MeshMaps", 220, 280, {
3106
+ inputs: [u("color", "Vertex Color", "vec4f")],
3107
+ outputs: [
3108
+ u("concavity", "Concavity", "f32"),
3109
+ u("convexity", "Convexity", "f32"),
3110
+ u("ao", "AO", "f32"),
3111
+ u("height", "Height", "f32")
3112
+ ]
3113
+ }),
3114
+ g("world_n", "GetWorldNormal", 0, 520, {
3115
+ inputs: [],
3116
+ outputs: [u("norm", "Normal", "vec3f")]
3117
+ }),
3118
+ g("prop_base", "Property", 760, 200, {
3119
+ data: { propertyName: "baseColor" },
3120
+ inputs: [],
3121
+ outputs: [u("out", "Out", "vec3f")]
3122
+ }),
3123
+ g("prop_accent", "Property", 760, 280, {
3124
+ data: { propertyName: "accentColor" },
3125
+ inputs: [],
3126
+ outputs: [u("out", "Out", "vec3f")]
3127
+ }),
3128
+ g("prop_wear", "Property", 760, 360, {
3129
+ data: { propertyName: "wearColor" },
3130
+ inputs: [],
3131
+ outputs: [u("out", "Out", "vec3f")]
3132
+ }),
3133
+ g("lerp_grain", "Lerp", 980, 160, {
3134
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
3135
+ outputs: [u("out", "Out", "vec3f")]
3136
+ }),
3137
+ g("blotch_k", "ConstantFloat", 760, 440, {
3138
+ data: { value: 0.38 },
3139
+ inputs: [],
3140
+ outputs: [u("out", "Out", "f32")]
3141
+ }),
3142
+ g("blotch_amt", "Multiply", 980, 360, {
3143
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
3144
+ outputs: [u("out", "Out", "f32")]
3145
+ }),
3146
+ g("lerp_blotch", "Lerp", 1140, 200, {
3147
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
3148
+ outputs: [u("out", "Out", "vec3f")]
3149
+ }),
3150
+ g("prop_ao_str", "Property", 1140, 320, {
3151
+ data: { propertyName: "aoStrength" },
3152
+ inputs: [],
3153
+ outputs: [u("out", "Out", "f32")]
3154
+ }),
3155
+ g("one", "ConstantFloat", 1140, 400, {
3156
+ data: { value: 1 },
3157
+ inputs: [],
3158
+ outputs: [u("out", "Out", "f32")]
3159
+ }),
3160
+ g("ao_mix", "Lerp", 1320, 280, {
3161
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32"), u("t", "T", "f32")],
3162
+ outputs: [u("out", "Out", "f32")]
3163
+ }),
3164
+ g("mul_ao_color", "Multiply", 1480, 200, {
3165
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "f32")],
3166
+ outputs: [u("out", "Out", "vec3f")]
3167
+ }),
3168
+ g("prop_edge", "Property", 1140, 480, {
3169
+ data: { propertyName: "edgeWear" },
3170
+ inputs: [],
3171
+ outputs: [u("out", "Out", "f32")]
3172
+ }),
3173
+ g("wear_amt", "Multiply", 1320, 440, {
3174
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
3175
+ outputs: [u("out", "Out", "f32")]
3176
+ }),
3177
+ g("lerp_wear", "Lerp", 1480, 320, {
3178
+ inputs: [u("a", "A", "vec3f"), u("b", "B", "vec3f"), u("t", "T", "f32")],
3179
+ outputs: [u("out", "Out", "vec3f")]
3180
+ }),
3181
+ g("split_alb", "SplitVec3", 1480, 80, {
3182
+ inputs: [u("in", "In", "vec3f")],
3183
+ outputs: [u("x", "X", "f32"), u("y", "Y", "f32"), u("z", "Z", "f32")]
3184
+ }),
3185
+ g("prop_opacity", "Property", 1480, 560, {
3186
+ data: { propertyName: "opacity" },
3187
+ inputs: [],
3188
+ outputs: [u("out", "Out", "f32")]
3189
+ }),
3190
+ g("alb_rgba", "Combine", 1600, 80, {
3191
+ inputs: [
3192
+ u("r", "R", "f32"),
3193
+ u("g", "G", "f32"),
3194
+ u("b", "B", "f32"),
3195
+ u("a", "A", "f32")
3196
+ ],
3197
+ outputs: [u("out", "Out", "vec4f")]
3198
+ }),
3199
+ g("prop_rough", "Property", 1140, 640, {
3200
+ data: { propertyName: "roughness" },
3201
+ inputs: [],
3202
+ outputs: [u("out", "Out", "f32")]
3203
+ }),
3204
+ g("add_rough", "Add", 1320, 640, {
3205
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
3206
+ outputs: [u("out", "Out", "f32")]
3207
+ }),
3208
+ g("cavity_k", "ConstantFloat", 1140, 800, {
3209
+ data: { value: 0.1 },
3210
+ inputs: [],
3211
+ outputs: [u("out", "Out", "f32")]
3212
+ }),
3213
+ g("cavity_rough", "Multiply", 1320, 760, {
3214
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
3215
+ outputs: [u("out", "Out", "f32")]
3216
+ }),
3217
+ g("add_cavity_r", "Add", 1480, 640, {
3218
+ inputs: [u("a", "A", "f32"), u("b", "B", "f32")],
3219
+ outputs: [u("out", "Out", "f32")]
3220
+ }),
3221
+ g("clamp_rough", "Clamp", 1600, 640, {
3222
+ inputs: [u("in", "In", "f32"), u("min", "Min", "f32"), u("max", "Max", "f32")],
3223
+ outputs: [u("out", "Out", "f32")]
3224
+ }),
3225
+ g("zero", "ConstantFloat", 1480, 800, {
3226
+ data: { value: 0 },
3227
+ inputs: [],
3228
+ outputs: [u("out", "Out", "f32")]
3229
+ }),
3230
+ g("prop_metal", "Property", 1480, 880, {
3231
+ data: { propertyName: "metallic" },
3232
+ inputs: [],
3233
+ outputs: [u("out", "Out", "f32")]
3234
+ }),
3235
+ g("prop_aniso", "Property", 1480, 960, {
3236
+ data: { propertyName: "anisotropy" },
3237
+ inputs: [],
3238
+ outputs: [u("out", "Out", "f32")]
3239
+ }),
3240
+ g("prop_aniso_rot", "Property", 1480, 1040, {
3241
+ data: { propertyName: "anisotropyRotation" },
3242
+ inputs: [],
3243
+ outputs: [u("out", "Out", "f32")]
3244
+ })
3245
+ ], o = [
3246
+ m("obj_pos", "pos", "steel_look", "pos"),
3247
+ m("prop_seed", "out", "steel_look", "seed"),
3248
+ m("prop_scale", "out", "steel_look", "scale"),
3249
+ m("steel_look", "out", "split_steel", "in"),
3250
+ m("vertex_color", "color", "mesh_maps", "color"),
3251
+ m("prop_base", "out", "lerp_grain", "a"),
3252
+ m("prop_accent", "out", "lerp_grain", "b"),
3253
+ m("split_steel", "x", "lerp_grain", "t"),
3254
+ m("split_steel", "y", "blotch_amt", "a"),
3255
+ m("blotch_k", "out", "blotch_amt", "b"),
3256
+ m("lerp_grain", "out", "lerp_blotch", "a"),
3257
+ m("prop_wear", "out", "lerp_blotch", "b"),
3258
+ m("blotch_amt", "out", "lerp_blotch", "t"),
3259
+ m("one", "out", "ao_mix", "a"),
3260
+ m("mesh_maps", "ao", "ao_mix", "b"),
3261
+ m("prop_ao_str", "out", "ao_mix", "t"),
3262
+ m("lerp_blotch", "out", "mul_ao_color", "a"),
3263
+ m("ao_mix", "out", "mul_ao_color", "b"),
3264
+ m("mesh_maps", "convexity", "wear_amt", "a"),
3265
+ m("prop_edge", "out", "wear_amt", "b"),
3266
+ m("mul_ao_color", "out", "lerp_wear", "a"),
3267
+ m("prop_wear", "out", "lerp_wear", "b"),
3268
+ m("wear_amt", "out", "lerp_wear", "t"),
3269
+ m("lerp_wear", "out", "split_alb", "in"),
3270
+ m("split_alb", "x", "alb_rgba", "r"),
3271
+ m("split_alb", "y", "alb_rgba", "g"),
3272
+ m("split_alb", "z", "alb_rgba", "b"),
3273
+ m("prop_opacity", "out", "alb_rgba", "a"),
3274
+ m("prop_rough", "out", "add_rough", "a"),
3275
+ m("split_steel", "w", "add_rough", "b"),
3276
+ m("mesh_maps", "concavity", "cavity_rough", "a"),
3277
+ m("cavity_k", "out", "cavity_rough", "b"),
3278
+ m("add_rough", "out", "add_cavity_r", "a"),
3279
+ m("cavity_rough", "out", "add_cavity_r", "b"),
3280
+ m("add_cavity_r", "out", "clamp_rough", "in"),
3281
+ m("zero", "out", "clamp_rough", "min"),
3282
+ m("one", "out", "clamp_rough", "max"),
3283
+ m("alb_rgba", "out", "pbr_master", "albedo"),
3284
+ m("prop_opacity", "out", "pbr_master", "opacity"),
3285
+ m("world_n", "norm", "pbr_master", "normal"),
3286
+ m("clamp_rough", "out", "pbr_master", "roughness_factor"),
3287
+ m("prop_metal", "out", "pbr_master", "metallic_factor"),
3288
+ m("prop_aniso", "out", "pbr_master", "anisotropy"),
3289
+ m("prop_aniso_rot", "out", "pbr_master", "anisotropy_rotation")
3290
+ ];
3291
+ return { id: kr, properties: e, nodes: t, connections: o };
3292
+ }
3293
+ function bs() {
3294
+ return wr();
3295
+ }
3296
+ function O(e, t, o, n, r, s) {
3297
+ return {
3298
+ type: "AABB",
3299
+ size: [e, t, o],
3300
+ offset: [n, r, s],
3301
+ collisionGroup: we,
3302
+ collisionMask: jn
3303
+ };
3304
+ }
3305
+ function ks(e) {
3306
+ switch (e) {
3307
+ case "pawn":
3308
+ return [
3309
+ O(0.018, 6e-3, 0.018, 0, 6e-3, 0),
3310
+ O(9e-3, 0.012, 9e-3, 0, 0.024, 0),
3311
+ O(0.014, 0.012, 0.014, 0, 0.042, 0)
3312
+ ];
3313
+ case "rook":
3314
+ return [
3315
+ O(0.019, 8e-3, 0.019, 0, 8e-3, 0),
3316
+ O(0.014, 0.018, 0.014, 0, 0.03, 0),
3317
+ O(0.017, 0.01, 0.017, 0, 0.052, 0)
3318
+ ];
3319
+ case "knight":
3320
+ return [
3321
+ O(0.018, 8e-3, 0.018, 0, 8e-3, 0),
3322
+ O(0.012, 0.016, 0.012, 0, 0.028, 0),
3323
+ O(0.012, 0.014, 0.014, 0, 0.05, 2e-3)
3324
+ ];
3325
+ case "bishop":
3326
+ return [
3327
+ O(0.018, 7e-3, 0.018, 0, 7e-3, 0),
3328
+ O(0.01, 0.016, 0.01, 0, 0.028, 0),
3329
+ O(0.012, 0.016, 0.012, 0, 0.048, 0)
3330
+ ];
3331
+ case "queen":
3332
+ return [
3333
+ O(0.02, 8e-3, 0.02, 0, 8e-3, 0),
3334
+ O(0.011, 0.02, 0.011, 0, 0.032, 0),
3335
+ O(0.014, 0.018, 0.014, 0, 0.06, 0)
3336
+ ];
3337
+ case "king":
3338
+ return [
3339
+ O(0.021, 8e-3, 0.021, 0, 8e-3, 0),
3340
+ O(0.012, 0.022, 0.012, 0, 0.034, 0),
3341
+ O(0.015, 0.02, 0.015, 0, 0.068, 0)
3342
+ ];
3343
+ default:
3344
+ return [O(0.016, 0.02, 0.016, 0, 0.02, 0)];
3345
+ }
3346
+ }
3347
+ function _s(e = 0.012) {
3348
+ const t = K / 2;
3349
+ return {
3350
+ type: "AABB",
3351
+ size: [t, e, t],
3352
+ offset: [0, 0, 0]
3353
+ };
3354
+ }
3355
+ function nt(e, t) {
3356
+ const o = Math.sin(e * 127.1 + t * 311.7) * 43758.5453;
3357
+ return o - Math.floor(o);
3358
+ }
3359
+ function We(e) {
3360
+ return e * e * (3 - 2 * e);
3361
+ }
3362
+ function vr(e, t) {
3363
+ const o = Math.floor(e), n = Math.floor(t), r = We(e - o), s = We(t - n), i = nt(o, n), a = nt(o + 1, n), p = nt(o, n + 1), h = nt(o + 1, n + 1);
3364
+ return i + (a - i) * r + (p - i) * s + (i - a - p + h) * r * s;
3365
+ }
3366
+ function Mt(e, t) {
3367
+ let o = 0, n = 0.5, r = 1;
3368
+ for (let s = 0; s < 4; s++)
3369
+ o += vr(e * r, t * r) * n, r *= 2, n *= 0.5;
3370
+ return o;
3371
+ }
3372
+ function zt(e) {
3373
+ return Math.min(1, Math.max(0, e));
3374
+ }
3375
+ function mt(e, t, o) {
3376
+ return e + (t - e) * o;
3377
+ }
3378
+ function Ye(e, t, o) {
3379
+ return [mt(e[0], t[0], o), mt(e[1], t[1], o), mt(e[2], t[2], o)];
3380
+ }
3381
+ function Ft(e, t, o, n, r, s, i) {
3382
+ const a = (n * t + o) * 4;
3383
+ e[a] = r, e[a + 1] = s, e[a + 2] = i, e[a + 3] = 255;
3384
+ }
3385
+ function te(e, t, o, n) {
3386
+ const r = n === "light" ? 5.4 : 8.8, s = n === "light" ? 1.12 : 1.28, i = e * r + o * 17.3, a = t * s + o * 4.1, p = Mt(i * 0.42, a * 0.52) * (n === "light" ? 2.05 : 1.28), h = n === "light" ? 1.7 : 0.82, c = Math.sin(a * Math.PI * 1.32 + Mt(a * 0.68, o * 5.1) * 1.7) * h, f = i + p + c, y = 0.5 + 0.5 * Math.sin(f * (n === "light" ? 11.2 : 18.4)), k = Mt(i * 3.6, a * 16);
3387
+ let _ = mt(y, k, n === "light" ? 0.34 : 0.26);
3388
+ if (_ = Math.pow(zt(_), n === "light" ? 0.7 : 0.88), n === "light") {
3389
+ const b = Math.pow(Mt(i * 0.85 + 9.2, a * 24), 10);
3390
+ _ = mt(_, 0.1, zt(b * 3.4));
3391
+ }
3392
+ return zt(_);
3393
+ }
3394
+ function Qe(e, t) {
3395
+ return t === "light" ? Ye([216, 188, 154], [168, 124, 91], e) : Ye([74, 54, 46], [36, 24, 20], mt(0.22, 0.82, e));
3396
+ }
3397
+ function Cr(e, t) {
3398
+ if (e < z || t < z || e >= 1 - z || t >= 1 - z)
3399
+ return { kind: "frame" };
3400
+ const o = (e - z) / pe * 8, n = (t - z) / pe * 8, r = Math.min(7, Math.floor(o)), s = Math.min(7, Math.floor(n)), i = o - r, a = n - s, p = (r + (7 - s)) % 2 === 0;
3401
+ return { kind: "square", fx: r, fy: s, lu: i, lv: a, light: p };
3402
+ }
3403
+ function ws(e, t) {
3404
+ for (let o = 0; o < t; o++)
3405
+ for (let n = 0; n < t; n++) {
3406
+ const r = (n + 0.5) / t, s = (o + 0.5) / t, i = Cr(r, s);
3407
+ if (i.kind === "frame") {
3408
+ const c = te(r * 8.5, s * 1.15, 0.41, "dark"), f = Qe(c, "dark");
3409
+ Ft(e, t, n, o, f[0], f[1], f[2]);
3410
+ continue;
3411
+ }
3412
+ const a = nt(i.fx * 1.73, i.fy * 3.11), p = i.light ? te(i.lu + a, i.lv, a, "light") : te(i.lv + a * 0.5, i.lu, a + 0.37, "dark"), h = Qe(p, i.light ? "light" : "dark");
3413
+ Ft(e, t, n, o, h[0], h[1], h[2]);
3414
+ }
3415
+ }
3416
+ function vs(e, t) {
3417
+ for (let o = 0; o < t; o++)
3418
+ for (let n = 0; n < t; n++) {
3419
+ const r = nt(n * 0.2, o * 0.2) * 16;
3420
+ Ft(e, t, n, o, 232 + r, 224 + r * 0.7, 208 + r * 0.4);
3421
+ }
3422
+ }
3423
+ function Cs(e, t) {
3424
+ for (let o = 0; o < t; o++)
3425
+ for (let n = 0; n < t; n++) {
3426
+ const r = nt(n * 0.18, o * 0.22) * 18;
3427
+ Ft(e, t, n, o, 28 + r, 24 + r, 22 + r);
3428
+ }
3429
+ }
3430
+ const Co = 8, So = 0.55, Ss = 0.025;
3431
+ function Es(e, t, o) {
3432
+ if (o.width <= 0 || o.height <= 0) return null;
3433
+ const n = (e - o.left) / o.width, r = (t - o.top) / o.height;
3434
+ return { ndcX: n * 2 - 1, ndcY: 1 - r * 2 };
3435
+ }
3436
+ function Ms(e, t, o) {
3437
+ const n = t[1];
3438
+ if (Math.abs(n) < 1e-8) return null;
3439
+ const r = (o - e[1]) / n;
3440
+ return r < 0 ? null : M.fromValues(e[0] + t[0] * r, o, e[2] + t[2] * r);
3441
+ }
3442
+ const Sr = 1 / 30;
3443
+ function Er(e, t, o, n, r = Co, s = So) {
3444
+ const i = Math.max(0, Math.min(n, Sr));
3445
+ if (i <= 0) return;
3446
+ const a = 2 * Math.PI * Math.max(1e-3, r), p = 2 * s * a, h = a * a;
3447
+ for (let c = 0; c < 3; c++) {
3448
+ const f = h * (o[c] - e[c]) - p * t[c];
3449
+ t[c] += f * i, e[c] += t[c] * i;
3450
+ }
3451
+ }
3452
+ const ee = G.create(), Xe = Z.create(), Ze = Z.create(), q = Z.create(), W = Z.create(), Je = G.create(), ze = G.create(), oe = M.create(), to = gt.create(), At = M.create(), eo = M.create(), Mr = M.fromValues(0, 1, 0);
3453
+ function Ar(e, t, o, n, r, s, i = G.create()) {
3454
+ const a = Number.isFinite(n) && n > 1e-6 ? n : 1;
3455
+ return G.lookAt(Je, e, t, Mr), G.perspective(ze, o, a, r, s), G.multiply(i, ze, Je);
3456
+ }
3457
+ function As(e, t, o, n, r, s = G.create()) {
3458
+ return G.getTranslation(oe, e), G.getRotation(to, e), M.set(At, 0, 0, -1), M.transformQuat(At, At, to), M.add(eo, oe, At), Ar(oe, eo, t, o, n, r, s);
3459
+ }
3460
+ function xs(e, t, o) {
3461
+ if (!G.invert(ee, e) || (Z.set(Xe, t, o, -1, 1), Z.set(Ze, t, o, 1, 1), Z.transformMat4(q, Xe, ee), Z.transformMat4(W, Ze, ee), Math.abs(q[3]) < 1e-8 || Math.abs(W[3]) < 1e-8)) return null;
3462
+ const n = q[0] / q[3], r = q[1] / q[3], s = q[2] / q[3], i = W[0] / W[3], a = W[1] / W[3], p = W[2] / W[3], h = M.fromValues(i - n, a - r, p - s);
3463
+ return M.length(h) < 1e-8 ? null : (M.normalize(h, h), { origin: [n, r, s], direction: [h[0], h[1], h[2]] });
3464
+ }
3465
+ function Eo(e) {
3466
+ Ae.set(e.inverseInertiaTensor, 0, 0, 0, 0, 0, 0, 0, 0, 0), Ae.copy(e.inverseInertiaTensorWorld, e.inverseInertiaTensor), M.set(e.angularVelocity, 0, 0, 0), M.set(e.biasAngularVelocity, 0, 0, 0);
3467
+ }
3468
+ function xr(e, t) {
3469
+ gt.identity(e.rotation), e.updateLocalTransform(), t && Eo(t);
3470
+ }
3471
+ function oo(e, t, o) {
3472
+ e.isKinematic = !0, e.useGravity = !o, M.set(e.velocity, 0, 0, 0), Eo(e), o ? e.wakeUp() : (e.updateInertia(t), e.isSleeping = !0);
3473
+ }
3474
+ const no = gt.create(), lt = M.create();
3475
+ function ne(e) {
3476
+ e.updateLocalTransform(), G.copy(e.worldTransform, e.localTransform);
3477
+ }
3478
+ class Ps {
3479
+ constructor() {
3480
+ F(this, "state", null);
3481
+ }
3482
+ get grabbed() {
3483
+ return this.state;
3484
+ }
3485
+ /** Cursor / drop target XZ on the grab plane (not the lagged piece pose). */
3486
+ dropXZ() {
3487
+ return this.state ? [this.state.targetX, this.state.targetZ] : null;
3488
+ }
3489
+ begin(t, o, n, r) {
3490
+ this.end(t);
3491
+ const s = t.getComponent(o, Dt), i = t.getComponent(o, xe), a = t.getComponent(o, Pe);
3492
+ if (!s || !i || !a) return !1;
3493
+ oo(a, i, !0), xr(s, a), M.set(
3494
+ lt,
3495
+ n[0] - s.position[0],
3496
+ n[1] - s.position[1],
3497
+ n[2] - s.position[2]
3498
+ ), gt.invert(no, s.rotation), M.transformQuat(lt, lt, no), ne(s), t.addComponent(
3499
+ o,
3500
+ new $t({
3501
+ type: "DISTANCE",
3502
+ connectedEntity: null,
3503
+ localAnchorA: [lt[0], lt[1], lt[2]],
3504
+ localAnchorB: [n[0], r, n[2]],
3505
+ minDistance: 0,
3506
+ maxDistance: 0.04,
3507
+ frequency: Co,
3508
+ dampingRatio: So
3509
+ })
3510
+ );
3511
+ const p = i.collisionMask;
3512
+ return i.collisionMask = Kn, this.state = {
3513
+ entity: o,
3514
+ previousMask: p,
3515
+ grabHeightY: r,
3516
+ targetX: n[0],
3517
+ targetY: r,
3518
+ targetZ: n[2],
3519
+ velX: 0,
3520
+ velY: 0,
3521
+ velZ: 0
3522
+ }, !0;
3523
+ }
3524
+ updateWorldAnchor(t, o, n, r) {
3525
+ if (!this.state) return;
3526
+ const { entity: s, grabHeightY: i } = this.state;
3527
+ this.state.targetX = o, this.state.targetY = i, this.state.targetZ = n;
3528
+ const a = t.getComponent(s, $t);
3529
+ a && M.set(a.localAnchorB, o, i, n);
3530
+ const p = t.getComponent(s, Dt);
3531
+ if (!p) return;
3532
+ const h = M.fromValues(this.state.velX, this.state.velY, this.state.velZ);
3533
+ Er(p.position, h, [o, i, n], r), this.state.velX = h[0], this.state.velY = h[1], this.state.velZ = h[2], ne(p);
3534
+ }
3535
+ end(t) {
3536
+ if (!this.state) return null;
3537
+ const { entity: o, previousMask: n, targetX: r, targetY: s, targetZ: i } = this.state, a = t.getComponent(o, Dt);
3538
+ a && (M.set(a.position, r, s, i), ne(a)), t.removeComponent(o, $t);
3539
+ const p = t.getComponent(o, xe), h = t.getComponent(o, Pe);
3540
+ return p && (p.collisionMask = n), h && p && oo(h, p, !1), this.state = null, o;
3541
+ }
3542
+ }
3543
+ class Pr {
3544
+ constructor(t = "white", o = "pawn", n = "") {
3545
+ F(this, "color");
3546
+ F(this, "role");
3547
+ /** Algebraic square e.g. `e2`, or empty when off-board / cemetery. */
3548
+ F(this, "square");
3549
+ this.color = t, this.role = o, this.square = n;
3550
+ }
3551
+ }
3552
+ F(Pr, "componentName", "ChessPieceComponent");
3553
+ const Rr = "@naanouff/w3dts-chess";
3554
+ function Rs() {
3555
+ return {
3556
+ id: Rr,
3557
+ serialize() {
3558
+ },
3559
+ deserialize() {
3560
+ }
3561
+ };
3562
+ }
3563
+ export {
3564
+ ht as CHESS_BOARD_BEVEL_M,
3565
+ Pt as CHESS_BOARD_BODY_HEIGHT,
3566
+ z as CHESS_BOARD_BORDER_FRAC,
3567
+ St as CHESS_BOARD_EXTENT,
3568
+ pe as CHESS_BOARD_INNER_FRAC,
3569
+ K as CHESS_BOARD_MESH_EXTENT,
3570
+ D as CHESS_BOARD_SURFACE_Y,
3571
+ Nn as CHESS_GLYPH_TEXTURE_SIZE,
3572
+ So as CHESS_GRAB_DAMPING_RATIO,
3573
+ Co as CHESS_GRAB_FREQUENCY_HZ,
3574
+ Ss as CHESS_GRAB_LIFT_M,
3575
+ Un as CHESS_GROUP_BOARD,
3576
+ we as CHESS_GROUP_PIECE,
3577
+ jr as CHESS_HUD_COMMAND_EVENT,
3578
+ Ur as CHESS_HUD_STATE_EVENT,
3579
+ or as CHESS_KNIGHT_HEAD_THICKNESS,
3580
+ us as CHESS_MASK_BOARD,
3581
+ jn as CHESS_MASK_PIECE,
3582
+ Kn as CHESS_MASK_PIECE_GRABBED,
3583
+ yo as CHESS_PIECE_TRAVEL_LIFT_Y,
3584
+ U as CHESS_SQUARE_SIZE,
3585
+ rt as ChessMatch,
3586
+ Pr as ChessPieceComponent,
3587
+ vn as ECO_OPENINGS,
3588
+ Fr as HeuristicChessEngine,
3589
+ br as MARBLE_PBR_SHADER_ID,
3590
+ dr as MeshBuilder,
3591
+ Ps as MouseGrabController,
3592
+ Qr as OpeningTrainer,
3593
+ kr as STEEL_PBR_SHADER_ID,
3594
+ Rr as W3DTS_CHESS_EXTENSION_ID,
3595
+ yr as applyChessBoardWorldUvs,
3596
+ ms as applyCylindricalPieceUvs,
3597
+ is as assignCemeterySlot,
3598
+ hs as bakeChessMeshMaps,
3599
+ Cr as boardAlbedoCell,
3600
+ _s as boardColliderShape,
3601
+ ns as bookMoveSplineLength,
3602
+ gs as buildChessBoardBodyMesh,
3603
+ qr as buildChessHudLearnPlies,
3604
+ ps as buildStauntonPawnUvMesh,
3605
+ fs as buildStauntonPieceMesh,
3606
+ as as cemeterySlotIsOffBoard,
3607
+ zr as chessBoardLabelPoseVec,
3608
+ Jr as chessBoardLabelPoses,
3609
+ ts as chessBoardLabelQuat,
3610
+ Zr as chessBoardLabelSize,
3611
+ Pn as chessBoardRimRadius,
3612
+ pn as chessDemoQueryToParams,
3613
+ Kr as chessPlayP2pHint,
3614
+ Ge as chessPlyFromFen,
3615
+ cs as chessTableSfxForPly,
3616
+ Es as clientPointToNdc,
3617
+ bs as createBrushedSteelProceduralPBRGraph,
3618
+ mr as createChessBoardGraph,
3619
+ cr as createChessKnightGraph,
3620
+ sr as createChessPieceGraph,
3621
+ Rs as createChessSceneExtensionHandler,
3622
+ ys as createMarbleProceduralPBRGraph,
3623
+ Hr as decideChessFenSync,
3624
+ Gr as decodeChessWire,
3625
+ go as easeSmoothstep,
3626
+ Lr as encodeChessWire,
3627
+ de as executeChessGProcToMesh,
3628
+ ws as fillBoardAlbedo,
3629
+ es as fillChessGlyphAlbedo,
3630
+ Cs as fillEbonyAlbedo,
3631
+ vs as fillIvoryAlbedo,
3632
+ Cn as findEcoOpeningIndex,
3633
+ $r as formatChessClock,
3634
+ Ms as intersectRayHorizontalPlane,
3635
+ ls as isChessLatheRole,
3636
+ Vn as knightElbowIndices,
3637
+ Eo as lockChessPieceTilt,
3638
+ fn as mergeChessDemoQueryIntoSearch,
3639
+ kn as normalizeChessHudP2pStatus,
3640
+ He as openingSlug,
3641
+ Vr as parseChessDemoQuery,
3642
+ _e as parseChessDemoSession,
3643
+ Yr as parseChessHudCommand,
3644
+ Wr as parseChessHudState,
3645
+ xs as pickRayFromViewProjection,
3646
+ Dr as replaceChessDemoQueryInLocation,
3647
+ Sn as resolveEcoLine,
3648
+ os as sampleBookMoveSpline,
3649
+ rs as samplePieceTravel,
3650
+ ss as samplePieceTravelWorld,
3651
+ xr as seatChessPieceUpright,
3652
+ oo as setChessPieceHeld,
3653
+ Xr as snapWorldToSquareCenter,
3654
+ at as squareToWorld,
3655
+ ks as stauntonPieceColliderShapes,
3656
+ ds as stauntonPieceHeight,
3657
+ Er as stepChessGrabSpring,
3658
+ bn as stripChessSanSuffix,
3659
+ As as viewProjectionFromWorldTransform,
3660
+ Ar as viewProjectionLookAt,
3661
+ fo as worldToSquare
3662
+ };