UNPKG

chess-analysis-board

Version:

A comprehensive chess analysis board React component with move navigation, variation support, PGN import/export, and customizable keyboard shortcuts

1,931 lines 341 kB
var xv = Object.defineProperty; var Tv = (i, t, s) => t in i ? xv(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s; var Re = (i, t, s) => Tv(i, typeof t != "symbol" ? t + "" : t, s); import * as Nn from "react"; import Dv, { useState as ve, useCallback as lr, createContext as qs, forwardRef as ul, useRef as It, useImperativeHandle as kv, useEffect as je, useMemo as dt, useContext as Hs, memo as Nv, Fragment as jv, useLayoutEffect as Av, isValidElement as Pv, cloneElement as xa } from "react"; var On = { exports: {} }, Mr = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Ta; function Iv() { if (Ta) return Mr; Ta = 1; var i = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment"); function s(a, l, u) { var p = null; if (u !== void 0 && (p = "" + u), l.key !== void 0 && (p = "" + l.key), "key" in l) { u = {}; for (var g in l) g !== "key" && (u[g] = l[g]); } else u = l; return l = u.ref, { $$typeof: i, type: a, key: p, ref: l !== void 0 ? l : null, props: u }; } return Mr.Fragment = t, Mr.jsx = s, Mr.jsxs = s, Mr; } var Fr = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Da; function Rv() { return Da || (Da = 1, process.env.NODE_ENV !== "production" && (function() { function i(M) { if (M == null) return null; if (typeof M == "function") return M.$$typeof === de ? null : M.displayName || M.name || null; if (typeof M == "string") return M; switch (M) { case L: return "Fragment"; case U: return "Profiler"; case K: return "StrictMode"; case X: return "Suspense"; case d: return "SuspenseList"; case we: return "Activity"; } if (typeof M == "object") switch (typeof M.tag == "number" && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), M.$$typeof) { case k: return "Portal"; case W: return (M.displayName || "Context") + ".Provider"; case z: return (M._context.displayName || "Context") + ".Consumer"; case oe: var ae = M.render; return M = M.displayName, M || (M = ae.displayName || ae.name || "", M = M !== "" ? "ForwardRef(" + M + ")" : "ForwardRef"), M; case re: return ae = M.displayName || null, ae !== null ? ae : i(M.type) || "Memo"; case r: ae = M._payload, M = M._init; try { return i(M(ae)); } catch { } } return null; } function t(M) { return "" + M; } function s(M) { try { t(M); var ae = !1; } catch { ae = !0; } if (ae) { ae = console; var Oe = ae.error, ke = typeof Symbol == "function" && Symbol.toStringTag && M[Symbol.toStringTag] || M.constructor.name || "Object"; return Oe.call( ae, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", ke ), t(M); } } function a(M) { if (M === L) return "<>"; if (typeof M == "object" && M !== null && M.$$typeof === r) return "<...>"; try { var ae = i(M); return ae ? "<" + ae + ">" : "<...>"; } catch { return "<...>"; } } function l() { var M = ye.A; return M === null ? null : M.getOwner(); } function u() { return Error("react-stack-top-frame"); } function p(M) { if (he.call(M, "key")) { var ae = Object.getOwnPropertyDescriptor(M, "key").get; if (ae && ae.isReactWarning) return !1; } return M.key !== void 0; } function g(M, ae) { function Oe() { Y || (Y = !0, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", ae )); } Oe.isReactWarning = !0, Object.defineProperty(M, "key", { get: Oe, configurable: !0 }); } function b() { var M = i(this.type); return Z[M] || (Z[M] = !0, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )), M = this.props.ref, M !== void 0 ? M : null; } function _(M, ae, Oe, ke, Be, Fe, Xe, le) { return Oe = Fe.ref, M = { $$typeof: P, type: M, key: ae, props: Fe, _owner: Be }, (Oe !== void 0 ? Oe : null) !== null ? Object.defineProperty(M, "ref", { enumerable: !1, get: b }) : Object.defineProperty(M, "ref", { enumerable: !1, value: null }), M._store = {}, Object.defineProperty(M._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: 0 }), Object.defineProperty(M, "_debugInfo", { configurable: !1, enumerable: !1, writable: !0, value: null }), Object.defineProperty(M, "_debugStack", { configurable: !1, enumerable: !1, writable: !0, value: Xe }), Object.defineProperty(M, "_debugTask", { configurable: !1, enumerable: !1, writable: !0, value: le }), Object.freeze && (Object.freeze(M.props), Object.freeze(M)), M; } function O(M, ae, Oe, ke, Be, Fe, Xe, le) { var Ee = ae.children; if (Ee !== void 0) if (ke) if (_e(Ee)) { for (ke = 0; ke < Ee.length; ke++) N(Ee[ke]); Object.freeze && Object.freeze(Ee); } else console.error( "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead." ); else N(Ee); if (he.call(ae, "key")) { Ee = i(M); var Ue = Object.keys(ae).filter(function(Pe) { return Pe !== "key"; }); ke = 0 < Ue.length ? "{key: someKey, " + Ue.join(": ..., ") + ": ...}" : "{key: someKey}", Me[Ee + ke] || (Ue = 0 < Ue.length ? "{" + Ue.join(": ..., ") + ": ...}" : "{}", console.error( `A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, ke, Ee, Ue, Ee ), Me[Ee + ke] = !0); } if (Ee = null, Oe !== void 0 && (s(Oe), Ee = "" + Oe), p(ae) && (s(ae.key), Ee = "" + ae.key), "key" in ae) { Oe = {}; for (var xe in ae) xe !== "key" && (Oe[xe] = ae[xe]); } else Oe = ae; return Ee && g( Oe, typeof M == "function" ? M.displayName || M.name || "Unknown" : M ), _( M, Ee, Fe, Be, l(), Oe, Xe, le ); } function N(M) { typeof M == "object" && M !== null && M.$$typeof === P && M._store && (M._store.validated = 1); } var S = Dv, P = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), L = Symbol.for("react.fragment"), K = Symbol.for("react.strict_mode"), U = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), W = Symbol.for("react.context"), oe = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), d = Symbol.for("react.suspense_list"), re = Symbol.for("react.memo"), r = Symbol.for("react.lazy"), we = Symbol.for("react.activity"), de = Symbol.for("react.client.reference"), ye = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, he = Object.prototype.hasOwnProperty, _e = Array.isArray, me = console.createTask ? console.createTask : function() { return null; }; S = { react_stack_bottom_frame: function(M) { return M(); } }; var Y, Z = {}, be = S.react_stack_bottom_frame.bind( S, u )(), Ie = me(a(u)), Me = {}; Fr.Fragment = L, Fr.jsx = function(M, ae, Oe, ke, Be) { var Fe = 1e4 > ye.recentlyCreatedOwnerStacks++; return O( M, ae, Oe, !1, ke, Be, Fe ? Error("react-stack-top-frame") : be, Fe ? me(a(M)) : Ie ); }, Fr.jsxs = function(M, ae, Oe, ke, Be) { var Fe = 1e4 > ye.recentlyCreatedOwnerStacks++; return O( M, ae, Oe, !0, ke, Be, Fe ? Error("react-stack-top-frame") : be, Fe ? me(a(M)) : Ie ); }; })()), Fr; } var ka; function Lv() { return ka || (ka = 1, process.env.NODE_ENV === "production" ? On.exports = Iv() : On.exports = Rv()), On.exports; } var m = Lv(), dl = Symbol.for("immer-nothing"), Na = Symbol.for("immer-draftable"), vt = Symbol.for("immer-state"), Mv = process.env.NODE_ENV !== "production" ? [ // All error codes, starting by 0: function(i) { return `The plugin for '${i}' has not been loaded into Immer. To enable the plugin, import and call \`enable${i}()\` when initializing your application.`; }, function(i) { return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${i}'`; }, "This object has been frozen and should not be mutated", function(i) { return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + i; }, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function(i) { return `'current' expects a draft, got: ${i}`; }, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function(i) { return `'original' expects a draft, got: ${i}`; } // Note: if more errors are added, the errorOffset in Patches.ts should be increased // See Patches.ts for additional errors ] : []; function ut(i, ...t) { if (process.env.NODE_ENV !== "production") { const s = Mv[i], a = typeof s == "function" ? s.apply(null, t) : s; throw new Error(`[Immer] ${a}`); } throw new Error( `[Immer] minified error nr: ${i}. Full error at: https://bit.ly/3cXEKWf` ); } var _r = Object.getPrototypeOf; function Er(i) { return !!i && !!i[vt]; } function fr(i) { var t; return i ? hl(i) || Array.isArray(i) || !!i[Na] || !!((t = i.constructor) != null && t[Na]) || Un(i) || Wn(i) : !1; } var Fv = Object.prototype.constructor.toString(); function hl(i) { if (!i || typeof i != "object") return !1; const t = _r(i); if (t === null) return !0; const s = Object.hasOwnProperty.call(t, "constructor") && t.constructor; return s === Object ? !0 : typeof s == "function" && Function.toString.call(s) === Fv; } function Rn(i, t) { Bn(i) === 0 ? Reflect.ownKeys(i).forEach((s) => { t(s, i[s], i); }) : i.forEach((s, a) => t(a, s, i)); } function Bn(i) { const t = i[vt]; return t ? t.type_ : Array.isArray(i) ? 1 : Un(i) ? 2 : Wn(i) ? 3 : 0; } function Ns(i, t) { return Bn(i) === 2 ? i.has(t) : Object.prototype.hasOwnProperty.call(i, t); } function gl(i, t, s) { const a = Bn(i); a === 2 ? i.set(t, s) : a === 3 ? i.add(s) : i[t] = s; } function Bv(i, t) { return i === t ? i !== 0 || 1 / i === 1 / t : i !== i && t !== t; } function Un(i) { return i instanceof Map; } function Wn(i) { return i instanceof Set; } function ar(i) { return i.copy_ || i.base_; } function js(i, t) { if (Un(i)) return new Map(i); if (Wn(i)) return new Set(i); if (Array.isArray(i)) return Array.prototype.slice.call(i); const s = hl(i); if (t === !0 || t === "class_only" && !s) { const a = Object.getOwnPropertyDescriptors(i); delete a[vt]; let l = Reflect.ownKeys(a); for (let u = 0; u < l.length; u++) { const p = l[u], g = a[p]; g.writable === !1 && (g.writable = !0, g.configurable = !0), (g.get || g.set) && (a[p] = { configurable: !0, writable: !0, // could live with !!desc.set as well here... enumerable: g.enumerable, value: i[p] }); } return Object.create(_r(i), a); } else { const a = _r(i); if (a !== null && s) return { ...i }; const l = Object.create(a); return Object.assign(l, i); } } function Hr(i, t = !1) { return Kn(i) || Er(i) || !fr(i) || (Bn(i) > 1 && (i.set = i.add = i.clear = i.delete = Uv), Object.freeze(i), t && Object.entries(i).forEach(([s, a]) => Hr(a, !0))), i; } function Uv() { ut(2); } function Kn(i) { return Object.isFrozen(i); } var Wv = {}; function ur(i) { const t = Wv[i]; return t || ut(0, i), t; } var Vr; function pl() { return Vr; } function Kv(i, t) { return { drafts_: [], parent_: i, immer_: t, // Whenever the modified draft contains a draft from another scope, we // need to prevent auto-freezing so the unowned draft can be finalized. canAutoFreeze_: !0, unfinalizedDrafts_: 0 }; } function ja(i, t) { t && (ur("Patches"), i.patches_ = [], i.inversePatches_ = [], i.patchListener_ = t); } function As(i) { Ps(i), i.drafts_.forEach(zv), i.drafts_ = null; } function Ps(i) { i === Vr && (Vr = i.parent_); } function Aa(i) { return Vr = Kv(Vr, i); } function zv(i) { const t = i[vt]; t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0; } function Pa(i, t) { t.unfinalizedDrafts_ = t.drafts_.length; const s = t.drafts_[0]; return i !== void 0 && i !== s ? (s[vt].modified_ && (As(t), ut(4)), fr(i) && (i = Ln(t, i), t.parent_ || Mn(t, i)), t.patches_ && ur("Patches").generateReplacementPatches_( s[vt].base_, i, t.patches_, t.inversePatches_ )) : i = Ln(t, s, []), As(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), i !== dl ? i : void 0; } function Ln(i, t, s) { if (Kn(t)) return t; const a = t[vt]; if (!a) return Rn( t, (l, u) => Ia(i, a, t, l, u, s) ), t; if (a.scope_ !== i) return t; if (!a.modified_) return Mn(i, a.base_, !0), a.base_; if (!a.finalized_) { a.finalized_ = !0, a.scope_.unfinalizedDrafts_--; const l = a.copy_; let u = l, p = !1; a.type_ === 3 && (u = new Set(l), l.clear(), p = !0), Rn( u, (g, b) => Ia(i, a, l, g, b, s, p) ), Mn(i, l, !1), s && i.patches_ && ur("Patches").generatePatches_( a, s, i.patches_, i.inversePatches_ ); } return a.copy_; } function Ia(i, t, s, a, l, u, p) { if (process.env.NODE_ENV !== "production" && l === s && ut(5), Er(l)) { const g = u && t && t.type_ !== 3 && // Set objects are atomic since they have no keys. !Ns(t.assigned_, a) ? u.concat(a) : void 0, b = Ln(i, l, g); if (gl(s, a, b), Er(b)) i.canAutoFreeze_ = !1; else return; } else p && s.add(l); if (fr(l) && !Kn(l)) { if (!i.immer_.autoFreeze_ && i.unfinalizedDrafts_ < 1) return; Ln(i, l), (!t || !t.scope_.parent_) && typeof a != "symbol" && Object.prototype.propertyIsEnumerable.call(s, a) && Mn(i, l); } } function Mn(i, t, s = !1) { !i.parent_ && i.immer_.autoFreeze_ && i.canAutoFreeze_ && Hr(t, s); } function qv(i, t) { const s = Array.isArray(i), a = { type_: s ? 1 : 0, // Track which produce call this is associated with. scope_: t ? t.scope_ : pl(), // True for both shallow and deep changes. modified_: !1, // Used during finalization. finalized_: !1, // Track which properties have been assigned (true) or deleted (false). assigned_: {}, // The parent draft state. parent_: t, // The base state. base_: i, // The base proxy. draft_: null, // set below // The base copy with any updated values. copy_: null, // Called by the `produce` function. revoke_: null, isManual_: !1 }; let l = a, u = Vs; s && (l = [a], u = Gr); const { revoke: p, proxy: g } = Proxy.revocable(l, u); return a.draft_ = g, a.revoke_ = p, g; } var Vs = { get(i, t) { if (t === vt) return i; const s = ar(i); if (!Ns(s, t)) return Hv(i, s, t); const a = s[t]; return i.finalized_ || !fr(a) ? a : a === ps(i.base_, t) ? (vs(i), i.copy_[t] = Rs(a, i)) : a; }, has(i, t) { return t in ar(i); }, ownKeys(i) { return Reflect.ownKeys(ar(i)); }, set(i, t, s) { const a = vl(ar(i), t); if (a != null && a.set) return a.set.call(i.draft_, s), !0; if (!i.modified_) { const l = ps(ar(i), t), u = l == null ? void 0 : l[vt]; if (u && u.base_ === s) return i.copy_[t] = s, i.assigned_[t] = !1, !0; if (Bv(s, l) && (s !== void 0 || Ns(i.base_, t))) return !0; vs(i), Is(i); } return i.copy_[t] === s && // special case: handle new props with value 'undefined' (s !== void 0 || t in i.copy_) || // special case: NaN Number.isNaN(s) && Number.isNaN(i.copy_[t]) || (i.copy_[t] = s, i.assigned_[t] = !0), !0; }, deleteProperty(i, t) { return ps(i.base_, t) !== void 0 || t in i.base_ ? (i.assigned_[t] = !1, vs(i), Is(i)) : delete i.assigned_[t], i.copy_ && delete i.copy_[t], !0; }, // Note: We never coerce `desc.value` into an Immer draft, because we can't make // the same guarantee in ES5 mode. getOwnPropertyDescriptor(i, t) { const s = ar(i), a = Reflect.getOwnPropertyDescriptor(s, t); return a && { writable: !0, configurable: i.type_ !== 1 || t !== "length", enumerable: a.enumerable, value: s[t] }; }, defineProperty() { ut(11); }, getPrototypeOf(i) { return _r(i.base_); }, setPrototypeOf() { ut(12); } }, Gr = {}; Rn(Vs, (i, t) => { Gr[i] = function() { return arguments[0] = arguments[0][0], t.apply(this, arguments); }; }); Gr.deleteProperty = function(i, t) { return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && ut(13), Gr.set.call(this, i, t, void 0); }; Gr.set = function(i, t, s) { return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && ut(14), Vs.set.call(this, i[0], t, s, i[0]); }; function ps(i, t) { const s = i[vt]; return (s ? ar(s) : i)[t]; } function Hv(i, t, s) { var l; const a = vl(t, s); return a ? "value" in a ? a.value : ( // This is a very special case, if the prop is a getter defined by the // prototype, we should invoke it with the draft as context! (l = a.get) == null ? void 0 : l.call(i.draft_) ) : void 0; } function vl(i, t) { if (!(t in i)) return; let s = _r(i); for (; s; ) { const a = Object.getOwnPropertyDescriptor(s, t); if (a) return a; s = _r(s); } } function Is(i) { i.modified_ || (i.modified_ = !0, i.parent_ && Is(i.parent_)); } function vs(i) { i.copy_ || (i.copy_ = js( i.base_, i.scope_.immer_.useStrictShallowCopy_ )); } var Vv = class { constructor(i) { this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.produce = (t, s, a) => { if (typeof t == "function" && typeof s != "function") { const u = s; s = t; const p = this; return function(b = u, ..._) { return p.produce(b, (O) => s.call(this, O, ..._)); }; } typeof s != "function" && ut(6), a !== void 0 && typeof a != "function" && ut(7); let l; if (fr(t)) { const u = Aa(this), p = Rs(t, void 0); let g = !0; try { l = s(p), g = !1; } finally { g ? As(u) : Ps(u); } return ja(u, a), Pa(l, u); } else if (!t || typeof t != "object") { if (l = s(t), l === void 0 && (l = t), l === dl && (l = void 0), this.autoFreeze_ && Hr(l, !0), a) { const u = [], p = []; ur("Patches").generateReplacementPatches_(t, l, u, p), a(u, p); } return l; } else ut(1, t); }, this.produceWithPatches = (t, s) => { if (typeof t == "function") return (p, ...g) => this.produceWithPatches(p, (b) => t(b, ...g)); let a, l; return [this.produce(t, s, (p, g) => { a = p, l = g; }), a, l]; }, typeof (i == null ? void 0 : i.autoFreeze) == "boolean" && this.setAutoFreeze(i.autoFreeze), typeof (i == null ? void 0 : i.useStrictShallowCopy) == "boolean" && this.setUseStrictShallowCopy(i.useStrictShallowCopy); } createDraft(i) { fr(i) || ut(8), Er(i) && (i = Gv(i)); const t = Aa(this), s = Rs(i, void 0); return s[vt].isManual_ = !0, Ps(t), s; } finishDraft(i, t) { const s = i && i[vt]; (!s || !s.isManual_) && ut(9); const { scope_: a } = s; return ja(a, t), Pa(void 0, a); } /** * Pass true to automatically freeze all copies created by Immer. * * By default, auto-freezing is enabled. */ setAutoFreeze(i) { this.autoFreeze_ = i; } /** * Pass true to enable strict shallow copy. * * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties. */ setUseStrictShallowCopy(i) { this.useStrictShallowCopy_ = i; } applyPatches(i, t) { let s; for (s = t.length - 1; s >= 0; s--) { const l = t[s]; if (l.path.length === 0 && l.op === "replace") { i = l.value; break; } } s > -1 && (t = t.slice(s + 1)); const a = ur("Patches").applyPatches_; return Er(i) ? a(i, t) : this.produce( i, (l) => a(l, t) ); } }; function Rs(i, t) { const s = Un(i) ? ur("MapSet").proxyMap_(i, t) : Wn(i) ? ur("MapSet").proxySet_(i, t) : qv(i, t); return (t ? t.scope_ : pl()).drafts_.push(s), s; } function Gv(i) { return Er(i) || ut(10, i), ml(i); } function ml(i) { if (!fr(i) || Kn(i)) return i; const t = i[vt]; let s; if (t) { if (!t.modified_) return t.base_; t.finalized_ = !0, s = js(i, t.scope_.immer_.useStrictShallowCopy_); } else s = js(i, !0); return Rn(s, (a, l) => { gl(s, a, ml(l)); }), t && (t.finalized_ = !1), s; } var mt = new Vv(), Yv = mt.produce; mt.produceWithPatches.bind( mt ); mt.setAutoFreeze.bind(mt); mt.setUseStrictShallowCopy.bind(mt); mt.applyPatches.bind(mt); mt.createDraft.bind(mt); mt.finishDraft.bind(mt); function Qv(i) { var t = ve(function() { return Hr(typeof i == "function" ? i() : i, !0); }), s = t[1]; return [t[0], lr(function(a) { s(typeof a == "function" ? Yv(a) : Hr(a)); }, [])]; } function Xv(i) { return i !== null ? { comment: i, variations: [] } : { variations: [] }; } function Jv(i, t, s, a, l) { const u = { move: i, variations: l }; return t && (u.suffix = t), s && (u.nag = s), a !== null && (u.comment = a), u; } function Zv(...i) { const [t, ...s] = i; let a = t; for (const l of s) l !== null && (a.variations = [l, ...l.variations], l.variations = [], a = l); return t; } function e1(i, t) { if (t.marker && t.marker.comment) { let s = t.root; for (; ; ) { const a = s.variations[0]; if (!a) { s.comment = t.marker.comment; break; } s = a; } } return { headers: i, root: t.root, result: (t.marker && t.marker.result) ?? void 0 }; } function t1(i, t) { function s() { this.constructor = i; } s.prototype = t.prototype, i.prototype = new s(); } function Sr(i, t, s, a) { var l = Error.call(this, i); return Object.setPrototypeOf && Object.setPrototypeOf(l, Sr.prototype), l.expected = t, l.found = s, l.location = a, l.name = "SyntaxError", l; } t1(Sr, Error); function ms(i, t, s) { return s = s || " ", i.length > t ? i : (t -= i.length, s += s.repeat(t), i + s.slice(0, t)); } Sr.prototype.format = function(i) { var t = "Error: " + this.message; if (this.location) { var s = null, a; for (a = 0; a < i.length; a++) if (i[a].source === this.location.source) { s = i[a].text.split(/\r\n|\n|\r/g); break; } var l = this.location.start, u = this.location.source && typeof this.location.source.offset == "function" ? this.location.source.offset(l) : l, p = this.location.source + ":" + u.line + ":" + u.column; if (s) { var g = this.location.end, b = ms("", u.line.toString().length, " "), _ = s[l.line - 1], O = l.line === g.line ? g.column : _.length + 1, N = O - l.column || 1; t += ` --> ` + p + ` ` + b + ` | ` + u.line + " | " + _ + ` ` + b + " | " + ms("", l.column - 1, " ") + ms("", N, "^"); } else t += ` at ` + p; } return t; }; Sr.buildMessage = function(i, t) { var s = { literal: function(_) { return '"' + l(_.text) + '"'; }, class: function(_) { var O = _.parts.map(function(N) { return Array.isArray(N) ? u(N[0]) + "-" + u(N[1]) : u(N); }); return "[" + (_.inverted ? "^" : "") + O.join("") + "]"; }, any: function() { return "any character"; }, end: function() { return "end of input"; }, other: function(_) { return _.description; } }; function a(_) { return _.charCodeAt(0).toString(16).toUpperCase(); } function l(_) { return _.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(O) { return "\\x0" + a(O); }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(O) { return "\\x" + a(O); }); } function u(_) { return _.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function(O) { return "\\x0" + a(O); }).replace(/[\x10-\x1F\x7F-\x9F]/g, function(O) { return "\\x" + a(O); }); } function p(_) { return s[_.type](_); } function g(_) { var O = _.map(p), N, S; if (O.sort(), O.length > 0) { for (N = 1, S = 1; N < O.length; N++) O[N - 1] !== O[N] && (O[S] = O[N], S++); O.length = S; } switch (O.length) { case 1: return O[0]; case 2: return O[0] + " or " + O[1]; default: return O.slice(0, -1).join(", ") + ", or " + O[O.length - 1]; } } function b(_) { return _ ? '"' + l(_) + '"' : "end of input"; } return "Expected " + g(i) + " but " + b(t) + " found."; }; function r1(i, t) { t = t !== void 0 ? t : {}; var s = {}, a = t.grammarSource, l = { pgn: Tr }, u = Tr, p = "[", g = '"', b = "]", _ = ".", O = "O-O-O", N = "O-O", S = "0-0-0", P = "0-0", k = "$", L = "{", K = "}", U = ";", z = "(", W = ")", oe = "1-0", X = "0-1", d = "1/2-1/2", re = "*", r = /^[a-zA-Z]/, we = /^[^"]/, de = /^[0-9]/, ye = /^[.]/, he = /^[a-zA-Z1-8\-=]/, _e = /^[+#]/, me = /^[!?]/, Y = /^[^}]/, Z = /^[^\r\n]/, be = /^[ \t\r\n]/, Ie = Ye("tag pair"), Me = ce("[", !1), M = ce('"', !1), ae = ce("]", !1), Oe = Ye("tag name"), ke = Ae([["a", "z"], ["A", "Z"]], !1, !1), Be = Ye("tag value"), Fe = Ae(['"'], !0, !1), Xe = Ye("move number"), le = Ae([["0", "9"]], !1, !1), Ee = ce(".", !1), Ue = Ae(["."], !1, !1), xe = Ye("standard algebraic notation"), Pe = ce("O-O-O", !1), Le = ce("O-O", !1), tt = ce("0-0-0", !1), rt = ce("0-0", !1), Ct = Ae([["a", "z"], ["A", "Z"], ["1", "8"], "-", "="], !1, !1), nt = Ae(["+", "#"], !1, !1), Rt = Ye("suffix annotation"), wt = Ae(["!", "?"], !1, !1), Je = Ye("NAG"), Lt = ce("$", !1), _t = Ye("brace comment"), kt = ce("{", !1), Nt = Ae(["}"], !0, !1), jt = ce("}", !1), st = Ye("rest of line comment"), Et = ce(";", !1), it = Ae(["\r", ` `], !0, !1), Ft = Ye("variation"), Bt = ce("(", !1), Ut = ce(")", !1), ze = Ye("game termination marker"), at = ce("1-0", !1), St = ce("0-1", !1), Ot = ce("1/2-1/2", !1), Wt = ce("*", !1), er = Ye("whitespace"), Kt = Ae([" ", " ", "\r", ` `], !1, !1), xt = function(E, x) { return e1(E, x); }, lt = function(E) { return Object.fromEntries(E); }, At = function(E, x) { return [E, x]; }, zt = function(E, x) { return { root: E, marker: x }; }, A = function(E, x) { return Zv(Xv(E), ...x.flat()); }, I = function(E, x, T, ee, ne) { return Jv(E, x, T, ee, ne); }, B = function(E) { return E; }, V = function(E) { return E.replace(/[\r\n]+/g, " "); }, G = function(E) { return E.trim(); }, Q = function(E) { return E; }, se = function(E, x) { return { result: E, comment: x }; }, w = t.peg$currPos | 0, H = [{ line: 1, column: 1 }], $e = w, ie = t.peg$maxFailExpected || [], j = t.peg$silentFails | 0, Se; if (t.startRule) { if (!(t.startRule in l)) throw new Error(`Can't start parsing from rule "` + t.startRule + '".'); u = l[t.startRule]; } function ce(E, x) { return { type: "literal", text: E, ignoreCase: x }; } function Ae(E, x, T) { return { type: "class", parts: E, inverted: x, ignoreCase: T }; } function Ze() { return { type: "end" }; } function Ye(E) { return { type: "other", description: E }; } function Or(E) { var x = H[E], T; if (x) return x; if (E >= H.length) T = H.length - 1; else for (T = E; !H[--T]; ) ; for (x = H[T], x = { line: x.line, column: x.column }; T < E; ) i.charCodeAt(T) === 10 ? (x.line++, x.column = 1) : x.column++, T++; return H[E] = x, x; } function xr(E, x, T) { var ee = Or(E), ne = Or(x), De = { source: a, start: { offset: E, line: ee.line, column: ee.column }, end: { offset: x, line: ne.line, column: ne.column } }; return De; } function J(E) { w < $e || (w > $e && ($e = w, ie = []), ie.push(E)); } function Xr(E, x, T) { return new Sr( Sr.buildMessage(E, x), E, x, T ); } function Tr() { var E, x, T; return E = w, x = Jr(), T = tn(), E = xt(x, T), E; } function Jr() { var E, x, T; for (E = w, x = [], T = Dr(); T !== s; ) x.push(T), T = Dr(); return T = He(), E = lt(x), E; } function Dr() { var E, x, T, ee, ne, De, Pt; return j++, E = w, He(), i.charCodeAt(w) === 91 ? (x = p, w++) : (x = s, j === 0 && J(Me)), x !== s ? (He(), T = Zr(), T !== s ? (He(), i.charCodeAt(w) === 34 ? (ee = g, w++) : (ee = s, j === 0 && J(M)), ee !== s ? (ne = en(), i.charCodeAt(w) === 34 ? (De = g, w++) : (De = s, j === 0 && J(M)), De !== s ? (He(), i.charCodeAt(w) === 93 ? (Pt = b, w++) : (Pt = s, j === 0 && J(ae)), Pt !== s ? E = At(T, ne) : (w = E, E = s)) : (w = E, E = s)) : (w = E, E = s)) : (w = E, E = s)) : (w = E, E = s), j--, E === s && j === 0 && J(Ie), E; } function Zr() { var E, x, T; if (j++, E = w, x = [], T = i.charAt(w), r.test(T) ? w++ : (T = s, j === 0 && J(ke)), T !== s) for (; T !== s; ) x.push(T), T = i.charAt(w), r.test(T) ? w++ : (T = s, j === 0 && J(ke)); else x = s; return x !== s ? E = i.substring(E, w) : E = x, j--, E === s && (x = s, j === 0 && J(Oe)), E; } function en() { var E, x, T; for (j++, E = w, x = [], T = i.charAt(w), we.test(T) ? w++ : (T = s, j === 0 && J(Fe)); T !== s; ) x.push(T), T = i.charAt(w), we.test(T) ? w++ : (T = s, j === 0 && J(Fe)); return E = i.substring(E, w), j--, x = s, j === 0 && J(Be), E; } function tn() { var E, x, T; return E = w, x = kr(), He(), T = ln(), T === s && (T = null), He(), E = zt(x, T), E; } function kr() { var E, x, T, ee; for (E = w, x = gr(), x === s && (x = null), T = [], ee = Nr(); ee !== s; ) T.push(ee), ee = Nr(); return E = A(x, T), E; } function Nr() { var E, x, T, ee, ne, De, Pt, tr; if (E = w, He(), rn(), He(), x = nn(), x !== s) { for (T = sn(), T === s && (T = null), ee = [], ne = jr(); ne !== s; ) ee.push(ne), ne = jr(); for (ne = He(), De = gr(), De === s && (De = null), Pt = [], tr = Ar(); tr !== s; ) Pt.push(tr), tr = Ar(); E = I(x, T, ee, De, Pt); } else w = E, E = s; return E; } function rn() { var E, x, T, ee, ne, De; for (j++, E = w, x = [], T = i.charAt(w), de.test(T) ? w++ : (T = s, j === 0 && J(le)); T !== s; ) x.push(T), T = i.charAt(w), de.test(T) ? w++ : (T = s, j === 0 && J(le)); if (i.charCodeAt(w) === 46 ? (T = _, w++) : (T = s, j === 0 && J(Ee)), T !== s) { for (ee = He(), ne = [], De = i.charAt(w), ye.test(De) ? w++ : (De = s, j === 0 && J(Ue)); De !== s; ) ne.push(De), De = i.charAt(w), ye.test(De) ? w++ : (De = s, j === 0 && J(Ue)); x = [x, T, ee, ne], E = x; } else w = E, E = s; return j--, E === s && (x = s, j === 0 && J(Xe)), E; } function nn() { var E, x, T, ee, ne, De; if (j++, E = w, x = w, i.substr(w, 5) === O ? (T = O, w += 5) : (T = s, j === 0 && J(Pe)), T === s && (i.substr(w, 3) === N ? (T = N, w += 3) : (T = s, j === 0 && J(Le)), T === s && (i.substr(w, 5) === S ? (T = S, w += 5) : (T = s, j === 0 && J(tt)), T === s && (i.substr(w, 3) === P ? (T = P, w += 3) : (T = s, j === 0 && J(rt)), T === s)))) if (T = w, ee = i.charAt(w), r.test(ee) ? w++ : (ee = s, j === 0 && J(ke)), ee !== s) { if (ne = [], De = i.charAt(w), he.test(De) ? w++ : (De = s, j === 0 && J(Ct)), De !== s) for (; De !== s; ) ne.push(De), De = i.charAt(w), he.test(De) ? w++ : (De = s, j === 0 && J(Ct)); else ne = s; ne !== s ? (ee = [ee, ne], T = ee) : (w = T, T = s); } else w = T, T = s; return T !== s ? (ee = i.charAt(w), _e.test(ee) ? w++ : (ee = s, j === 0 && J(nt)), ee === s && (ee = null), T = [T, ee], x = T) : (w = x, x = s), x !== s ? E = i.substring(E, w) : E = x, j--, E === s && (x = s, j === 0 && J(xe)), E; } function sn() { var E, x, T; for (j++, E = w, x = [], T = i.charAt(w), me.test(T) ? w++ : (T = s, j === 0 && J(wt)); T !== s; ) x.push(T), x.length >= 2 ? T = s : (T = i.charAt(w), me.test(T) ? w++ : (T = s, j === 0 && J(wt))); return x.length < 1 ? (w = E, E = s) : E = x, j--, E === s && (x = s, j === 0 && J(Rt)), E; } function jr() { var E, x, T, ee, ne; if (j++, E = w, He(), i.charCodeAt(w) === 36 ? (x = k, w++) : (x = s, j === 0 && J(Lt)), x !== s) { if (T = w, ee = [], ne = i.charAt(w), de.test(ne) ? w++ : (ne = s, j === 0 && J(le)), ne !== s) for (; ne !== s; ) ee.push(ne), ne = i.charAt(w), de.test(ne) ? w++ : (ne = s, j === 0 && J(le)); else ee = s; ee !== s ? T = i.substring(T, w) : T = ee, T !== s ? E = B(T) : (w = E, E = s); } else w = E, E = s; return j--, E === s && j === 0 && J(Je), E; } function gr() { var E; return E = on(), E === s && (E = an()), E; } function on() { var E, x, T, ee, ne; if (j++, E = w, i.charCodeAt(w) === 123 ? (x = L, w++) : (x = s, j === 0 && J(kt)), x !== s) { for (T = w, ee = [], ne = i.charAt(w), Y.test(ne) ? w++ : (ne = s, j === 0 && J(Nt)); ne !== s; ) ee.push(ne), ne = i.charAt(w), Y.test(ne) ? w++ : (ne = s, j === 0 && J(Nt)); T = i.substring(T, w), i.charCodeAt(w) === 125 ? (ee = K, w++) : (ee = s, j === 0 && J(jt)), ee !== s ? E = V(T) : (w = E, E = s); } else w = E, E = s; return j--, E === s && (x = s, j === 0 && J(_t)), E; } function an() { var E, x, T, ee, ne; if (j++, E = w, i.charCodeAt(w) === 59 ? (x = U, w++) : (x = s, j === 0 && J(Et)), x !== s) { for (T = w, ee = [], ne = i.charAt(w), Z.test(ne) ? w++ : (ne = s, j === 0 && J(it)); ne !== s; ) ee.push(ne), ne = i.charAt(w), Z.test(ne) ? w++ : (ne = s, j === 0 && J(it)); T = i.substring(T, w), E = G(T); } else w = E, E = s; return j--, E === s && (x = s, j === 0 && J(st)), E; } function Ar() { var E, x, T, ee; return j++, E = w, He(), i.charCodeAt(w) === 40 ? (x = z, w++) : (x = s, j === 0 && J(Bt)), x !== s ? (T = kr(), T !== s ? (He(), i.charCodeAt(w) === 41 ? (ee = W, w++) : (ee = s, j === 0 && J(Ut)), ee !== s ? E = Q(T) : (w = E, E = s)) : (w = E, E = s)) : (w = E, E = s), j--, E === s && j === 0 && J(Ft), E; } function ln() { var E, x, T; return j++, E = w, i.substr(w, 3) === oe ? (x = oe, w += 3) : (x = s, j === 0 && J(at)), x === s && (i.substr(w, 3) === X ? (x = X, w += 3) : (x = s, j === 0 && J(St)), x === s && (i.substr(w, 7) === d ? (x = d, w += 7) : (x = s, j === 0 && J(Ot)), x === s && (i.charCodeAt(w) === 42 ? (x = re, w++) : (x = s, j === 0 && J(Wt))))), x !== s ? (He(), T = gr(), T === s && (T = null), E = se(x, T)) : (w = E, E = s), j--, E === s && (x = s, j === 0 && J(ze)), E; } function He() { var E, x; for (j++, E = [], x = i.charAt(w), be.test(x) ? w++ : (x = s, j === 0 && J(Kt)); x !== s; ) E.push(x), x = i.charAt(w), be.test(x) ? w++ : (x = s, j === 0 && J(Kt)); return j--, x = s, j === 0 && J(er), E; } if (Se = u(), t.peg$library) return ( /** @type {any} */ { peg$result: Se, peg$currPos: w, peg$FAILED: s, peg$maxFailExpected: ie, peg$maxFailPos: $e } ); if (Se !== s && w === i.length) return Se; throw Se !== s && w < i.length && J(Ze()), Xr( ie, $e < i.length ? i.charAt($e) : null, $e < i.length ? xr($e, $e + 1) : xr($e, $e) ); } /** * @license * Copyright (c) 2025, Jeff Hlywa (jhlywa@gmail.com) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ const jn = 0xffffffffffffffffn; function bs(i, t) { return (i << t | i >> 64n - t) & 0xffffffffffffffffn; } function Ra(i, t) { return i * t & jn; } function n1(i) { return function() { let t = BigInt(i & jn), s = BigInt(i >> 64n & jn); const a = Ra(bs(Ra(t, 5n), 7n), 9n); return s ^= t, t = (bs(t, 24n) ^ s ^ s << 16n) & jn, s = bs(s, 37n), i = s << 64n | t, a; }; } const zn = n1(0xa187eb39cdcaed8f31c4b365b102e01en), s1 = Array.from({ length: 2 }, () => Array.from({ length: 6 }, () => Array.from({ length: 128 }, () => zn()))), i1 = Array.from({ length: 8 }, () => zn()), o1 = Array.from({ length: 16 }, () => zn()), ys = zn(), et = "w", pt = "b", Ke = "p", Ls = "n", An = "b", Wr = "r", Jt = "q", qe = "k", $s = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; class xn { constructor(t, s) { Re(this, "color"); Re(this, "from"); Re(this, "to"); Re(this, "piece"); Re(this, "captured"); Re(this, "promotion"); /** * @deprecated This field is deprecated and will be removed in version 2.0.0. * Please use move descriptor functions instead: `isCapture`, `isPromotion`, * `isEnPassant`, `isKingsideCastle`, `isQueensideCastle`, `isCastle`, and * `isBigPawn` */ Re(this, "flags"); Re(this, "san"); Re(this, "lan"); Re(this, "before"); Re(this, "after"); const { color: a, piece: l, from: u, to: p, flags: g, captured: b, promotion: _ } = s, O = Ge(u), N = Ge(p); this.color = a, this.piece = l, this.from = O, this.to = N, this.san = t._moveToSan(s, t._moves({ legal: !0 })), this.lan = O + N, this.before = t.fen(), t._makeMove(s), this.after = t.fen(), t._undoMove(), this.flags = ""; for (const S in ue) ue[S] & g && (this.flags += or[S]); b && (this.captured = b), _ && (this.promotion = _, this.lan += _); } isCapture() { return this.flags.indexOf(or.CAPTURE) > -1; } isPromotion() { return this.flags.indexOf(or.PROMOTION) > -1; } isEnPassant() { return this.flags.indexOf(or.EP_CAPTURE) > -1; } isKingsideCastle() { return this.flags.indexOf(or.KSIDE_CASTLE) > -1; } isQueensideCastle() { return this.flags.indexOf(or.QSIDE_CASTLE) > -1; } isBigPawn() { return this.flags.indexOf(or.BIG_PAWN) > -1; } } const Qe = -1, or = { NORMAL: "n", CAPTURE: "c", BIG_PAWN: "b", EP_CAPTURE: "e", PROMOTION: "p", KSIDE_CASTLE: "k", QSIDE_CASTLE: "q", NULL_MOVE: "-" }, ue = { NORMAL: 1, CAPTURE: 2, BIG_PAWN: 4, EP_CAPTURE: 8, PROMOTION: 16, KSIDE_CASTLE: 32, QSIDE_CASTLE: 64, NULL_MOVE: 128 }, Ms = { Event: "?", Site: "?", Date: "????.??.??", Round: "?", White: "?", Black: "?", Result: "*" }, a1 = { WhiteTitle: null, BlackTitle: null, WhiteElo: null, BlackElo: null, WhiteUSCF: null, BlackUSCF: null, WhiteNA: null, BlackNA: null, WhiteType: null, BlackType: null, EventDate: null, EventSponsor: null, Section: null, Stage: null, Board: null, Opening: null, Variation: null, SubVariation: null, ECO: null, NIC: null, Time: null, UTCTime: null, UTCDate: null, TimeControl: null, SetUp: null, FEN: null, Termination: null, Annotator: null, Mode: null, PlyCount: null }, l1 = { ...Ms, ...a1 }, fe = { a8: 0, b8: 1, c8: 2, d8: 3, e8: 4, f8: 5, g8: 6, h8: 7, a7: 16, b7: 17, c7: 18, d7: 19, e7: 20, f7: 21, g7: 22, h7: 23, a6: 32, b6: 33, c6: 34, d6: 35, e6: 36, f6: 37, g6: 38, h6: 39, a5: 48, b5: 49, c5: 50, d5: 51, e5: 52, f5: 53, g5: 54, h5: 55, a4: 64, b4: 65, c4: 66, d4: 67, e4: 68, f4: 69, g4: 70, h4: 71, a3: 80, b3: 81, c3: 82, d3: 83, e3: 84, f3: 85, g3: 86, h3: 87, a2: 96, b2: 97, c2: 98, d2: 99, e2: 100, f2: 101, g2: 102, h2: 103, a1: 112, b1: 113, c1: 114, d1: 115, e1: 116, f1: 117, g1: 118, h1: 119 }, Cs = { b: [16, 32, 17, 15], w: [-16, -32, -17, -15] }, La = { n: [-18, -33, -31, -14, 18, 33, 31, 14], b: [-17, -15, 17, 15], r: [-16, 1, 16, -1], q: [-17, -16, -15, 1, 17, 16, 15, -1], k: [-17, -16, -15, 1, 17, 16, 15, -1] }, c1 = [ 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 20, 0, 0, 20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 20, 0, 0, 0, 0, 24, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 24, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 24, 2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 53, 56, 53, 2, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24, 56, 0, 56, 24, 24, 24, 24, 24, 24, 0, 0, 0, 0, 0, 0, 2, 53, 56, 53, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 2, 24, 2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 24, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 24, 0, 0, 0, 0, 20, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 20, 0, 0, 20, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 20 ], f1 = [ 17, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 15, 0, 0, 17, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 17, 0, 0, 0, 0, 16, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 16, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 16, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 16, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 16, 15, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -15, -16, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, 0, -16, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -15, 0, 0, -16, 0, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, -16, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, -16, 0, 0, 0, 0, -17, 0, 0, 0, 0, -15, 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, -17, 0, 0, -15, 0, 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, -17 ], u1 = { p: 1, n: 2, b: 4, r: 8, q: 16, k: 32 }, d1 = "pnbrqkPNBRQK", Ma = [Ls, An, Wr, Jt], h1 = 7, g1 = 6, p1 = 1, v1 = 0, Tn = { [qe]: ue.KSIDE_CASTLE, [Jt]: ue.QSIDE_CASTLE }, Qt = { w: [ { square: fe.a1, flag: ue.QSIDE_CASTLE }, { square: fe.h1, flag: ue.KSIDE_CASTLE } ], b: [ { square: fe.a8, flag: ue.QSIDE_CASTLE }, { square: fe.h8, flag: ue.KSIDE_CASTLE } ] }, m1 = { b: p1, w: g1 }, ws = "--"; function cr(i) { return i >> 4; } function Yr(i) { return i & 15; } function bl(i) { return "0123456789".indexOf(i) !== -1; } function Ge(i) { const t = Yr(i), s = cr(i); return "abcdefgh".substring(t, t + 1) + "87654321".substring(s, s + 1); } function Br(i) { return i === et ? pt : et; } function b1(i) { const t = i.split(/\s+/); if (t.length !== 6) return { ok: !1, error: "Invalid FEN: must contain six space-delimited fields" }; const s = parseInt(t[5], 10); if (isNaN(s) || s <= 0) return { ok: !1, error: "Invalid FEN: move number must be a positive integer" }; const a = parseInt(t[4], 10); if (isNaN(a) || a < 0) return { ok: !1, error: "Invalid FEN: half move counter number must be a non-negative integer" }; if (!/^(-|[abcdefgh][36])$/.test(t[3])) return { ok: !1, error: "Invalid FEN: en-passant square is invalid" }; if (/[^kKqQ-]/.test(t[2])) return { ok: !1, error: "Invalid FEN: castling availability is invalid" }; if (!/^(w|b)$/.test(t[1])) return { ok: !1, error: "Invalid FEN: side-to-move is invalid" }; const l = t[0].split("/"); if (l.length !== 8) return { ok: !1, error: "Invalid FEN: piece data does not contain 8 '/'-delimited rows" }; for (let p = 0; p < l.length; p++) { let g = 0, b = !1; for (let _ = 0; _ < l[p].length; _++) if (bl(l[p][_])) { if (b) return { ok: !1, error: "Invalid FEN: piece data is invalid (consecutive number)" }; g += parseInt(l[p][_], 10), b = !0; } else { if (!/^[prnbqkPRNBQK]$/.test(l[p][_])) return { ok: !1, error: "Invalid FEN: piece data is invalid (invalid piece)" }; g += 1, b = !1; } if (g !== 8) return { ok: !1, error: "Invalid FEN: piece data is invalid (too many squares in rank)" }; } if (t[3][1] == "3" && t[1] == "w" || t[3][1] == "6" && t[1] == "b") return { ok: !1, error: "Invalid FEN: illegal en-passant square" }; const u = [ { color: "white", regex: /K/g }, { color: "black", regex: /k/g } ]; for (const { color: p, regex: g } of u) { if (!g.test(t[0])) return { ok: !1, error: `Invalid FEN: missing ${p} king` }; if ((t[0].match(g) || []).length > 1) return { ok: !1, error: `Invalid FEN: too many ${p} kings` }; } return Array.from(l[0] + l[7]).some((p) => p.toUpperCase() === "P") ? { ok: !1, error: "Invalid FEN: some pawns are on the edge rows" } : { ok: !0 }; } function y1(i, t) { const s = i.from, a = i.to, l = i.piece; let u = 0, p = 0, g = 0; for (let b = 0, _ = t.length; b < _; b++) { const O = t[b].from, N = t[b].to, S = t[b].piece; l === S && s !