UNPKG

next-chessground

Version:

React and Next wrapper for Chessground with chessboard and pieces out of the box

35 lines 176 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("react-dom");function A(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=A(t),r=A(n);const i=t.createContext({theme:{board:"green",pieces:"neo",playSounds:!0,sounds:"robot",highlight:!0,coordinates:!0},setTheme:()=>{}}),s=({children:t})=>e.jsx(o.default.Fragment,{children:"undefined"==typeof window?null:t});var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var u=l(function(e){!function(t,n){var A={version:"2.14.4",areas:{},apis:{},nsdelim:".",inherit:function(e,t){for(var n in e)t.hasOwnProperty(n)||Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n));return t},stringify:function(e,t){return void 0===e||"function"==typeof e?e+"":JSON.stringify(e,t||A.replace)},parse:function(e,t){try{return JSON.parse(e,t||A.revive)}catch(t){return e}},fn:function(e,t){for(var n in A.storeAPI[e]=t,A.apis)A.apis[n][e]=t},get:function(e,t){return e.getItem(t)},set:function(e,t,n){e.setItem(t,n)},remove:function(e,t){e.removeItem(t)},key:function(e,t){return e.key(t)},length:function(e){return e.length},clear:function(e){e.clear()},Store:function(e,t,n){var o=A.inherit(A.storeAPI,function(e,t,n){return 0===arguments.length?o.getAll():"function"==typeof t?o.transact(e,t,n):void 0!==t?o.set(e,t,n):"string"==typeof e||"number"==typeof e?o.get(e):"function"==typeof e?o.each(e):e?o.setAll(e,t):o.clear()});o._id=e;try{var r="__store2_test";t.setItem(r,"ok"),o._area=t,t.removeItem(r)}catch(e){o._area=A.storage("fake")}return o._ns=n||"",A.areas[e]||(A.areas[e]=o._area),A.apis[o._ns+o._id]||(A.apis[o._ns+o._id]=o),o},storeAPI:{area:function(e,t){var n=this[e];return n&&n.area||(n=A.Store(e,t,this._ns),this[e]||(this[e]=n)),n},namespace:function(e,t,n){if(n=n||this._delim||A.nsdelim,!e)return this._ns?this._ns.substring(0,this._ns.length-n.length):"";var o=e,r=this[o];if(!(r&&r.namespace||((r=A.Store(this._id,this._area,this._ns+o+n))._delim=n,this[o]||(this[o]=r),t)))for(var i in A.areas)r.area(i,A.areas[i]);return r},isFake:function(e){return e?(this._real=this._area,this._area=A.storage("fake")):!1===e&&(this._area=this._real||this._area),"fake"===this._area.name},toString:function(){return"store"+(this._ns?"."+this.namespace():"")+"["+this._id+"]"},has:function(e){return this._area.has?this._area.has(this._in(e)):!!(this._in(e)in this._area)},size:function(){return this.keys().length},each:function(e,t){for(var n=0,o=A.length(this._area);n<o;n++){var r=this._out(A.key(this._area,n));if(void 0!==r&&!1===e.call(this,r,this.get(r),t))break;o>A.length(this._area)&&(o--,n--)}return t||this},keys:function(e){return this.each(function(e,t,n){n.push(e)},e||[])},get:function(e,t){var n,o=A.get(this._area,this._in(e));return"function"==typeof t&&(n=t,t=null),null!==o?A.parse(o,n):null!=t?t:o},getAll:function(e){return this.each(function(e,t,n){n[e]=t},e||{})},transact:function(e,t,n){var A=this.get(e,n),o=t(A);return this.set(e,void 0===o?A:o),this},set:function(e,t,n){var o,r=this.get(e);return null!=r&&!1===n?t:("function"==typeof n&&(o=n,n=void 0),A.set(this._area,this._in(e),A.stringify(t,o),n)||r)},setAll:function(e,t){var n,A;for(var o in e)A=e[o],this.set(o,A,t)!==A&&(n=!0);return n},add:function(e,t,n){var o=this.get(e);if(o instanceof Array)t=o.concat(t);else if(null!==o){var r=typeof o;if(r===typeof t&&"object"===r){for(var i in t)o[i]=t[i];t=o}else t=o+t}return A.set(this._area,this._in(e),A.stringify(t,n)),t},remove:function(e,t){var n=this.get(e,t);return A.remove(this._area,this._in(e)),n},clear:function(){return this._ns?this.each(function(e){A.remove(this._area,this._in(e))},1):A.clear(this._area),this},clearAll:function(){var e=this._area;for(var t in A.areas)A.areas.hasOwnProperty(t)&&(this._area=A.areas[t],this.clear());return this._area=e,this},_in:function(e){return"string"!=typeof e&&(e=A.stringify(e)),this._ns?this._ns+e:e},_out:function(e){return this._ns?e&&0===e.indexOf(this._ns)?e.substring(this._ns.length):void 0:e}},storage:function(e){return A.inherit(A.storageAPI,{items:{},name:e})},storageAPI:{length:0,has:function(e){return this.items.hasOwnProperty(e)},key:function(e){var t=0;for(var n in this.items)if(this.has(n)&&e===t++)return n},setItem:function(e,t){this.has(e)||this.length++,this.items[e]=t},removeItem:function(e){this.has(e)&&(delete this.items[e],this.length--)},getItem:function(e){return this.has(e)?this.items[e]:null},clear:function(){for(var e in this.items)this.removeItem(e)}}},o=A.Store("local",function(){try{return localStorage}catch(e){}}());o.local=o,o._=A,o.area("session",function(){try{return sessionStorage}catch(e){}}()),o.area("page",A.storage("page")),"function"==typeof n&&void 0!==n.amd?n("store2",[],function(){return o}):e.exports?e.exports=o:(t.store&&(A.conflict=t.store),t.store=o)}(a,a&&a.define)});const h=({children:n})=>{const[A,o]=t.useState((()=>{const e={board:"green",pieces:"cburnett",playSounds:!0,sounds:"robot",highlight:!0,coordinates:!0},t={board:u.local.get("chessground.board"),pieces:u.local.get("chessground.pieces"),playSounds:u.local.get("chessground.playSounds"),sounds:u.local.get("chessground.sounds"),highlight:u.local.get("chessground.highlight"),coordinates:u.local.get("chessground.coordinates")};for(const n of Object.keys(t))null!=t[n]&&(e[n]=t[n]);return e})());return e.jsx(s,{children:e.jsx(i.Provider,{value:{theme:A,setTheme:o},children:n})})};function p(){return Array.prototype.slice.call(arguments).reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return"string"==typeof e}).join(" ")}function g(e,t,n,A){var o=Error.call(this,e);return Object.setPrototypeOf&&Object.setPrototypeOf(o,g.prototype),o.expected=t,o.found=n,o.location=A,o.name="SyntaxError",o}function d(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,e+(n+=n.repeat(t)).slice(0,t))}function m(e,t){var n,A,o,r,i={},s=(t=void 0!==t?t:{}).grammarSource,a={pgn:ze},c=ze,l="[",u='"',h="]",p=".",d="O-O-O",m="O-O",f="0-0-0",b="0-0",y="$",I="{",k="}",w=";",C="(",v=")",S="1-0",E="0-1",x="1/2-1/2",V="*",N=/^[a-zA-Z]/,M=/^[^"]/,B=/^[0-9]/,j=/^[.]/,D=/^[a-zA-Z1-8\-=]/,T=/^[+#]/,Q=/^[!?]/,Z=/^[^}]/,P=/^[^\r\n]/,O=/^[ \t\r\n]/,U=Ge("tag pair"),q=Je("[",!1),J=Je('"',!1),K=Je("]",!1),G=Ge("tag name"),R=Ke([["a","z"],["A","Z"]],!1,!1),F=Ge("tag value"),L=Ke(['"'],!0,!1),z=Ge("move number"),W=Ke([["0","9"]],!1,!1),Y=Je(".",!1),_=Ke(["."],!1,!1),H=Ge("standard algebraic notation"),X=Je("O-O-O",!1),$=Je("O-O",!1),ee=Je("0-0-0",!1),te=Je("0-0",!1),ne=Ke([["a","z"],["A","Z"],["1","8"],"-","="],!1,!1),Ae=Ke(["+","#"],!1,!1),oe=Ge("suffix annotation"),re=Ke(["!","?"],!1,!1),ie=Ge("NAG"),se=Je("$",!1),ae=Ge("brace comment"),ce=Je("{",!1),le=Ke(["}"],!0,!1),ue=Je("}",!1),he=Ge("rest of line comment"),pe=Je(";",!1),ge=Ke(["\r","\n"],!0,!1),de=Ge("variation"),me=Je("(",!1),fe=Je(")",!1),be=Ge("game termination marker"),ye=Je("1-0",!1),Ie=Je("0-1",!1),ke=Je("1/2-1/2",!1),we=Je("*",!1),Ce=Ge("whitespace"),ve=Ke([" ","\t","\r","\n"],!1,!1),Se=function(e,t){return function(e,t){if(t.marker&&t.marker.comment){let e=t.root;for(;;){const n=e.variations[0];if(!n){e.comment=t.marker.comment;break}e=n}}return{headers:e,root:t.root,result:(t.marker&&t.marker.result)??void 0}}(e,t)},Ee=function(e){return Object.fromEntries(e)},xe=function(e,t){return[e,t]},Ve=function(e,t){return{root:e,marker:t}},Ne=function(e,t){return function(...e){const[t,...n]=e;let A=t;for(const e of n)null!==e&&(A.variations=[e,...e.variations],e.variations=[],A=e);return t}(function(e){return null!==e?{comment:e,variations:[]}:{variations:[]}}(e),...t.flat())},Me=function(e,t,n,A,o){return function(e,t,n,A,o){const r={move:e,variations:o};return t&&(r.suffix=t),n&&(r.nag=n),null!==A&&(r.comment=A),r}(e,t,n,A,o)},Be=function(e){return e},je=function(e){return e.replace(/[\r\n]+/g," ")},De=function(e){return e.trim()},Te=function(e){return e},Qe=function(e,t){return{result:e,comment:t}},Ze=0|t.peg$currPos,Pe=[{line:1,column:1}],Oe=Ze,Ue=t.peg$maxFailExpected||[],qe=0|t.peg$silentFails;if(t.startRule){if(!(t.startRule in a))throw new Error("Can't start parsing from rule \""+t.startRule+'".');c=a[t.startRule]}function Je(e,t){return{type:"literal",text:e,ignoreCase:t}}function Ke(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function Ge(e){return{type:"other",description:e}}function Re(t){var n,A=Pe[t];if(A)return A;if(t>=Pe.length)n=Pe.length-1;else for(n=t;!Pe[--n];);for(A={line:(A=Pe[n]).line,column:A.column};n<t;)10===e.charCodeAt(n)?(A.line++,A.column=1):A.column++,n++;return Pe[t]=A,A}function Fe(e,t,n){var A=Re(e),o=Re(t);return{source:s,start:{offset:e,line:A.line,column:A.column},end:{offset:t,line:o.line,column:o.column}}}function Le(e){Ze<Oe||(Ze>Oe&&(Oe=Ze,Ue=[]),Ue.push(e))}function ze(){var t,n;return t=function(){var e,t,n;e=Ze,t=[],n=We();for(;n!==i;)t.push(n),n=We();return n=et(),e=Ee(t),e}(),n=function(){var t,n,A;t=Ze,n=Ye(),et(),A=function(){var t,n,A;qe++,t=Ze,e.substr(Ze,3)===S?(n=S,Ze+=3):(n=i,0===qe&&Le(ye));n===i&&(e.substr(Ze,3)===E?(n=E,Ze+=3):(n=i,0===qe&&Le(Ie)),n===i&&(e.substr(Ze,7)===x?(n=x,Ze+=7):(n=i,0===qe&&Le(ke)),n===i&&(42===e.charCodeAt(Ze)?(n=V,Ze++):(n=i,0===qe&&Le(we)))));n!==i?(et(),(A=Xe())===i&&(A=null),t=Qe(n,A)):(Ze=t,t=i);qe--,t===i&&(n=i,0===qe&&Le(be));return t}(),A===i&&(A=null);return et(),t=Ve(n,A),t}(),Se(t,n)}function We(){var t,n,A,o,r,s,a;return qe++,t=Ze,et(),91===e.charCodeAt(Ze)?(n=l,Ze++):(n=i,0===qe&&Le(q)),n!==i?(et(),A=function(){var t,n,A;qe++,t=Ze,n=[],A=e.charAt(Ze),N.test(A)?Ze++:(A=i,0===qe&&Le(R));if(A!==i)for(;A!==i;)n.push(A),A=e.charAt(Ze),N.test(A)?Ze++:(A=i,0===qe&&Le(R));else n=i;t=n!==i?e.substring(t,Ze):n;qe--,t===i&&(n=i,0===qe&&Le(G));return t}(),A!==i?(et(),34===e.charCodeAt(Ze)?(o=u,Ze++):(o=i,0===qe&&Le(J)),o!==i?(r=function(){var t,n,A;qe++,t=Ze,n=[],A=e.charAt(Ze),M.test(A)?Ze++:(A=i,0===qe&&Le(L));for(;A!==i;)n.push(A),A=e.charAt(Ze),M.test(A)?Ze++:(A=i,0===qe&&Le(L));t=e.substring(t,Ze),qe--,n=i,0===qe&&Le(F);return t}(),34===e.charCodeAt(Ze)?(s=u,Ze++):(s=i,0===qe&&Le(J)),s!==i?(et(),93===e.charCodeAt(Ze)?(a=h,Ze++):(a=i,0===qe&&Le(K)),a!==i?t=xe(A,r):(Ze=t,t=i)):(Ze=t,t=i)):(Ze=t,t=i)):(Ze=t,t=i)):(Ze=t,t=i),qe--,t===i&&0===qe&&Le(U),t}function Ye(){var e,t,n;for((e=Xe())===i&&(e=null),t=[],n=_e();n!==i;)t.push(n),n=_e();return Ne(e,t)}function _e(){var t,n,A,o,r,s,a,c;if(t=Ze,et(),function(){var t,n,A,o,r,s;qe++,t=Ze,n=[],A=e.charAt(Ze),B.test(A)?Ze++:(A=i,0===qe&&Le(W));for(;A!==i;)n.push(A),A=e.charAt(Ze),B.test(A)?Ze++:(A=i,0===qe&&Le(W));46===e.charCodeAt(Ze)?(A=p,Ze++):(A=i,0===qe&&Le(Y));if(A!==i){for(o=et(),r=[],s=e.charAt(Ze),j.test(s)?Ze++:(s=i,0===qe&&Le(_));s!==i;)r.push(s),s=e.charAt(Ze),j.test(s)?Ze++:(s=i,0===qe&&Le(_));t=n=[n,A,o,r]}else Ze=t,t=i;qe--,t===i&&(n=i,0===qe&&Le(z))}(),et(),n=function(){var t,n,A,o,r,s;qe++,t=Ze,n=Ze,e.substr(Ze,5)===d?(A=d,Ze+=5):(A=i,0===qe&&Le(X));if(A===i&&(e.substr(Ze,3)===m?(A=m,Ze+=3):(A=i,0===qe&&Le($)),A===i&&(e.substr(Ze,5)===f?(A=f,Ze+=5):(A=i,0===qe&&Le(ee)),A===i&&(e.substr(Ze,3)===b?(A=b,Ze+=3):(A=i,0===qe&&Le(te)),A===i))))if(A=Ze,o=e.charAt(Ze),N.test(o)?Ze++:(o=i,0===qe&&Le(R)),o!==i){if(r=[],s=e.charAt(Ze),D.test(s)?Ze++:(s=i,0===qe&&Le(ne)),s!==i)for(;s!==i;)r.push(s),s=e.charAt(Ze),D.test(s)?Ze++:(s=i,0===qe&&Le(ne));else r=i;r!==i?A=o=[o,r]:(Ze=A,A=i)}else Ze=A,A=i;A!==i?(o=e.charAt(Ze),T.test(o)?Ze++:(o=i,0===qe&&Le(Ae)),o===i&&(o=null),n=A=[A,o]):(Ze=n,n=i);t=n!==i?e.substring(t,Ze):n;qe--,t===i&&(n=i,0===qe&&Le(H));return t}(),n!==i){for(A=function(){var t,n,A;qe++,t=Ze,n=[],A=e.charAt(Ze),Q.test(A)?Ze++:(A=i,0===qe&&Le(re));for(;A!==i;)n.push(A),n.length>=2?A=i:(A=e.charAt(Ze),Q.test(A)?Ze++:(A=i,0===qe&&Le(re)));n.length<1?(Ze=t,t=i):t=n;qe--,t===i&&(n=i,0===qe&&Le(oe));return t}(),A===i&&(A=null),o=[],r=He();r!==i;)o.push(r),r=He();for(r=et(),(s=Xe())===i&&(s=null),a=[],c=$e();c!==i;)a.push(c),c=$e();t=Me(n,A,o,s,a)}else Ze=t,t=i;return t}function He(){var t,n,A,o,r;if(qe++,t=Ze,et(),36===e.charCodeAt(Ze)?(n=y,Ze++):(n=i,0===qe&&Le(se)),n!==i){if(A=Ze,o=[],r=e.charAt(Ze),B.test(r)?Ze++:(r=i,0===qe&&Le(W)),r!==i)for(;r!==i;)o.push(r),r=e.charAt(Ze),B.test(r)?Ze++:(r=i,0===qe&&Le(W));else o=i;(A=o!==i?e.substring(A,Ze):o)!==i?t=Be(A):(Ze=t,t=i)}else Ze=t,t=i;return qe--,t===i&&0===qe&&Le(ie),t}function Xe(){var t;return(t=function(){var t,n,A,o,r;qe++,t=Ze,123===e.charCodeAt(Ze)?(n=I,Ze++):(n=i,0===qe&&Le(ce));if(n!==i){for(A=Ze,o=[],r=e.charAt(Ze),Z.test(r)?Ze++:(r=i,0===qe&&Le(le));r!==i;)o.push(r),r=e.charAt(Ze),Z.test(r)?Ze++:(r=i,0===qe&&Le(le));A=e.substring(A,Ze),125===e.charCodeAt(Ze)?(o=k,Ze++):(o=i,0===qe&&Le(ue)),o!==i?t=je(A):(Ze=t,t=i)}else Ze=t,t=i;qe--,t===i&&(n=i,0===qe&&Le(ae));return t}())===i&&(t=function(){var t,n,A,o,r;qe++,t=Ze,59===e.charCodeAt(Ze)?(n=w,Ze++):(n=i,0===qe&&Le(pe));if(n!==i){for(A=Ze,o=[],r=e.charAt(Ze),P.test(r)?Ze++:(r=i,0===qe&&Le(ge));r!==i;)o.push(r),r=e.charAt(Ze),P.test(r)?Ze++:(r=i,0===qe&&Le(ge));A=e.substring(A,Ze),t=De(A)}else Ze=t,t=i;qe--,t===i&&(n=i,0===qe&&Le(he));return t}()),t}function $e(){var t,n,A,o;return qe++,t=Ze,et(),40===e.charCodeAt(Ze)?(n=C,Ze++):(n=i,0===qe&&Le(me)),n!==i&&(A=Ye())!==i?(et(),41===e.charCodeAt(Ze)?(o=v,Ze++):(o=i,0===qe&&Le(fe)),o!==i?t=Te(A):(Ze=t,t=i)):(Ze=t,t=i),qe--,t===i&&0===qe&&Le(de),t}function et(){var t,n;for(qe++,t=[],n=e.charAt(Ze),O.test(n)?Ze++:(n=i,0===qe&&Le(ve));n!==i;)t.push(n),n=e.charAt(Ze),O.test(n)?Ze++:(n=i,0===qe&&Le(ve));return qe--,n=i,0===qe&&Le(Ce),t}if(n=c(),t.peg$library)return{peg$result:n,peg$currPos:Ze,peg$FAILED:i,peg$maxFailExpected:Ue,peg$maxFailPos:Oe};if(n!==i&&Ze===e.length)return n;throw n!==i&&Ze<e.length&&Le({type:"end"}),A=Ue,o=Oe<e.length?e.charAt(Oe):null,r=Oe<e.length?Fe(Oe,Oe+1):Fe(Oe,Oe),new g(g.buildMessage(A,o),A,o,r)} /** * @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. */!function(e,t){function n(){this.constructor=e}n.prototype=t.prototype,e.prototype=new n}(g,Error),g.prototype.format=function(e){var t="Error: "+this.message;if(this.location){var n,A=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){A=e[n].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,r=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(o):o,i=this.location.source+":"+r.line+":"+r.column;if(A){var s=this.location.end,a=d("",r.line.toString().length," "),c=A[o.line-1],l=(o.line===s.line?s.column:c.length+1)-o.column||1;t+="\n --\x3e "+i+"\n"+a+" |\n"+r.line+" | "+c+"\n"+a+" | "+d("",o.column-1," ")+d("",l,"^")}else t+="\n at "+i}return t},g.buildMessage=function(e,t){var n={literal:function(e){return'"'+o(e.text)+'"'},class:function(e){var t=e.parts.map(function(e){return Array.isArray(e)?r(e[0])+"-"+r(e[1]):r(e)});return"["+(e.inverted?"^":"")+t.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function A(e){return e.charCodeAt(0).toString(16).toUpperCase()}function o(e){return e.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(e){return"\\x0"+A(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+A(e)})}function r(e){return e.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(e){return"\\x0"+A(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+A(e)})}function i(e){return n[e.type](e)}return"Expected "+function(e){var t,n,A=e.map(i);if(A.sort(),A.length>0){for(t=1,n=1;t<A.length;t++)A[t-1]!==A[t]&&(A[n]=A[t],n++);A.length=n}switch(A.length){case 1:return A[0];case 2:return A[0]+" or "+A[1];default:return A.slice(0,-1).join(", ")+", or "+A[A.length-1]}}(e)+" but "+function(e){return e?'"'+o(e)+'"':"end of input"}(t)+" found."};const f=0xffffffffffffffffn;function b(e,t){return 0xffffffffffffffffn&(e<<t|e>>64n-t)}function y(e,t){return e*t&f}const I=(k=0xa187eb39cdcaed8f31c4b365b102e01en,function(){let e=BigInt(k&f),t=BigInt(k>>64n&f);const n=y(b(y(e,5n),7n),9n);return t^=e,e=(b(e,24n)^t^t<<16n)&f,t=b(t,37n),k=t<<64n|e,n});var k;const w=Array.from({length:2},()=>Array.from({length:6},()=>Array.from({length:128},()=>I()))),C=Array.from({length:8},()=>I()),v=Array.from({length:16},()=>I()),S=I(),E="w",x="b",V="p",N="b",M="r",B="q",j="k",D="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";class T{color;from;to;piece;captured;promotion;flags;san;lan;before;after;constructor(e,t){const{color:n,piece:A,from:o,to:r,flags:i,captured:s,promotion:a}=t,c=te(o),l=te(r);this.color=n,this.piece=A,this.from=c,this.to=l,this.san=e._moveToSan(t,e._moves({legal:!0})),this.lan=c+l,this.before=e.fen(),e._makeMove(t),this.after=e.fen(),e._undoMove(),this.flags="";for(const e in O)O[e]&i&&(this.flags+=Z[e]);s&&(this.captured=s),a&&(this.promotion=a,this.lan+=a)}isCapture(){return this.flags.indexOf(Z.CAPTURE)>-1}isPromotion(){return this.flags.indexOf(Z.PROMOTION)>-1}isEnPassant(){return this.flags.indexOf(Z.EP_CAPTURE)>-1}isKingsideCastle(){return this.flags.indexOf(Z.KSIDE_CASTLE)>-1}isQueensideCastle(){return this.flags.indexOf(Z.QSIDE_CASTLE)>-1}isBigPawn(){return this.flags.indexOf(Z.BIG_PAWN)>-1}}const Q=-1,Z={NORMAL:"n",CAPTURE:"c",BIG_PAWN:"b",EP_CAPTURE:"e",PROMOTION:"p",KSIDE_CASTLE:"k",QSIDE_CASTLE:"q",NULL_MOVE:"-"},P=["a8","b8","c8","d8","e8","f8","g8","h8","a7","b7","c7","d7","e7","f7","g7","h7","a6","b6","c6","d6","e6","f6","g6","h6","a5","b5","c5","d5","e5","f5","g5","h5","a4","b4","c4","d4","e4","f4","g4","h4","a3","b3","c3","d3","e3","f3","g3","h3","a2","b2","c2","d2","e2","f2","g2","h2","a1","b1","c1","d1","e1","f1","g1","h1"],O={NORMAL:1,CAPTURE:2,BIG_PAWN:4,EP_CAPTURE:8,PROMOTION:16,KSIDE_CASTLE:32,QSIDE_CASTLE:64,NULL_MOVE:128},U={Event:"?",Site:"?",Date:"????.??.??",Round:"?",White:"?",Black:"?",Result:"*"},q={...U,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},J={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},K={b:[16,32,17,15],w:[-16,-32,-17,-15]},G={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]},R=[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],F=[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],L={p:1,n:2,b:4,r:8,q:16,k:32},z=["n",N,M,B],W={[j]:O.KSIDE_CASTLE,[B]:O.QSIDE_CASTLE},Y={w:[{square:J.a1,flag:O.QSIDE_CASTLE},{square:J.h1,flag:O.KSIDE_CASTLE}],b:[{square:J.a8,flag:O.QSIDE_CASTLE},{square:J.h8,flag:O.KSIDE_CASTLE}]},_={b:1,w:6},H="--";function X(e){return e>>4}function $(e){return 15&e}function ee(e){return-1!=="0123456789".indexOf(e)}function te(e){const t=$(e),n=X(e);return"abcdefgh".substring(t,t+1)+"87654321".substring(n,n+1)}function ne(e){return e===E?x:E}function Ae(e){const t=e.split(/\s+/);if(6!==t.length)return{ok:!1,error:"Invalid FEN: must contain six space-delimited fields"};const n=parseInt(t[5],10);if(isNaN(n)||n<=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 o=t[0].split("/");if(8!==o.length)return{ok:!1,error:"Invalid FEN: piece data does not contain 8 '/'-delimited rows"};for(let e=0;e<o.length;e++){let t=0,n=!1;for(let A=0;A<o[e].length;A++)if(ee(o[e][A])){if(n)return{ok:!1,error:"Invalid FEN: piece data is invalid (consecutive number)"};t+=parseInt(o[e][A],10),n=!0}else{if(!/^[prnbqkPRNBQK]$/.test(o[e][A]))return{ok:!1,error:"Invalid FEN: piece data is invalid (invalid piece)"};t+=1,n=!1}if(8!==t)return{ok:!1,error:"Invalid FEN: piece data is invalid (too many squares in rank)"}}if("3"==t[3][1]&&"w"==t[1]||"6"==t[3][1]&&"b"==t[1])return{ok:!1,error:"Invalid FEN: illegal en-passant square"};const r=[{color:"white",regex:/K/g},{color:"black",regex:/k/g}];for(const{color:e,regex:n}of r){if(!n.test(t[0]))return{ok:!1,error:`Invalid FEN: missing ${e} king`};if((t[0].match(n)||[]).length>1)return{ok:!1,error:`Invalid FEN: too many ${e} kings`}}return Array.from(o[0]+o[7]).some(e=>"P"===e.toUpperCase())?{ok:!1,error:"Invalid FEN: some pawns are on the edge rows"}:{ok:!0}}function oe(e,t,n,A,o,r=void 0,i=O.NORMAL){const s=X(A);if(o!==V||7!==s&&0!==s)e.push({color:t,from:n,to:A,piece:o,captured:r,flags:i});else for(let s=0;s<z.length;s++){const a=z[s];e.push({color:t,from:n,to:A,piece:o,captured:r,promotion:a,flags:i|O.PROMOTION})}}function re(e){let t=e.charAt(0);if(t>="a"&&t<="h"){if(e.match(/[a-h]\d.*[a-h]\d/))return;return V}return t=t.toLowerCase(),"o"===t?j:t}function ie(e){return e.replace(/=/,"").replace(/[+#]?[?!]*$/,"")}class se{_board=new Array(128);_turn=E;_header={};_kings={w:Q,b:Q};_epSquare=-1;_halfMoves=0;_moveNumber=0;_history=[];_comments={};_castling={w:0,b:0};_hash=0n;_positionCount=new Map;constructor(e=D,{skipValidation:t=!1}={}){this.load(e,{skipValidation:t})}clear({preserveHeaders:e=!1}={}){this._board=new Array(128),this._kings={w:Q,b:Q},this._turn=E,this._castling={w:0,b:0},this._epSquare=Q,this._halfMoves=0,this._moveNumber=1,this._history=[],this._comments={},this._header=e?this._header:{...q},this._hash=this._computeHash(),this._positionCount=new Map,this._header.SetUp=null,this._header.FEN=null}load(e,{skipValidation:t=!1,preserveHeaders:n=!1}={}){let A=e.split(/\s+/);if(A.length>=2&&A.length<6){const t=["-","-","0","1"];e=A.concat(t.slice(-(6-A.length))).join(" ")}if(A=e.split(/\s+/),!t){const{ok:t,error:n}=Ae(e);if(!t)throw new Error(n)}const o=A[0];let r=0;this.clear({preserveHeaders:n});for(let e=0;e<o.length;e++){const t=o.charAt(e);if("/"===t)r+=8;else if(ee(t))r+=parseInt(t,10);else{const e=t<"a"?E:x;this._put({type:t.toLowerCase(),color:e},te(r)),r++}}this._turn=A[1],A[2].indexOf("K")>-1&&(this._castling.w|=O.KSIDE_CASTLE),A[2].indexOf("Q")>-1&&(this._castling.w|=O.QSIDE_CASTLE),A[2].indexOf("k")>-1&&(this._castling.b|=O.KSIDE_CASTLE),A[2].indexOf("q")>-1&&(this._castling.b|=O.QSIDE_CASTLE),this._epSquare="-"===A[3]?Q:J[A[3]],this._halfMoves=parseInt(A[4],10),this._moveNumber=parseInt(A[5],10),this._hash=this._computeHash(),this._updateSetup(e),this._incPositionCount()}fen({forceEnpassantSquare:e=!1}={}){let t=0,n="";for(let e=J.a8;e<=J.h1;e++){if(this._board[e]){t>0&&(n+=t,t=0);const{color:A,type:o}=this._board[e];n+=A===E?o.toUpperCase():o.toLowerCase()}else t++;e+1&136&&(t>0&&(n+=t),e!==J.h1&&(n+="/"),t=0,e+=8)}let A="";this._castling[E]&O.KSIDE_CASTLE&&(A+="K"),this._castling[E]&O.QSIDE_CASTLE&&(A+="Q"),this._castling[x]&O.KSIDE_CASTLE&&(A+="k"),this._castling[x]&O.QSIDE_CASTLE&&(A+="q"),A=A||"-";let o="-";if(this._epSquare!==Q)if(e)o=te(this._epSquare);else{const e=this._epSquare+(this._turn===E?16:-16),t=[e+1,e-1];for(const e of t){if(136&e)continue;const t=this._turn;if(this._board[e]?.color===t&&this._board[e]?.type===V){this._makeMove({color:t,from:e,to:this._epSquare,piece:V,captured:V,flags:O.EP_CAPTURE});const n=!this._isKingAttacked(t);if(this._undoMove(),n){o=te(this._epSquare);break}}}}return[n,this._turn,A,o,this._halfMoves,this._moveNumber].join(" ")}_pieceKey(e){if(!this._board[e])return 0n;const{color:t,type:n}=this._board[e],A={p:0,n:1,b:2,r:3,q:4,k:5}[n];return w[{w:0,b:1}[t]][A][e]}_epKey(){return this._epSquare===Q?0n:C[7&this._epSquare]}_castlingKey(){const e=this._castling.w>>5|this._castling.b>>3;return v[e]}_computeHash(){let e=0n;for(let t=J.a8;t<=J.h1;t++)136&t?t+=7:this._board[t]&&(e^=this._pieceKey(t));return e^=this._epKey(),e^=this._castlingKey(),"b"===this._turn&&(e^=S),e}_updateSetup(e){this._history.length>0||(e!==D?(this._header.SetUp="1",this._header.FEN=e):(this._header.SetUp=null,this._header.FEN=null))}reset(){this.load(D)}get(e){return this._board[J[e]]}findPiece(e){const t=[];for(let n=J.a8;n<=J.h1;n++)136&n?n+=7:this._board[n]&&this._board[n]?.color===e.color&&this._board[n].color===e.color&&this._board[n].type===e.type&&t.push(te(n));return t}put({type:e,color:t},n){return!!this._put({type:e,color:t},n)&&(this._updateCastlingRights(),this._updateEnPassantSquare(),this._updateSetup(this.fen()),!0)}_set(e,t){this._hash^=this._pieceKey(e),this._board[e]=t,this._hash^=this._pieceKey(e)}_put({type:e,color:t},n){if(-1==="pnbrqkPNBRQK".indexOf(e.toLowerCase()))return!1;if(!(n in J))return!1;const A=J[n];if(e==j&&this._kings[t]!=Q&&this._kings[t]!=A)return!1;const o=this._board[A];return o&&o.type===j&&(this._kings[o.color]=Q),this._set(A,{type:e,color:t}),e===j&&(this._kings[t]=A),!0}_clear(e){this._hash^=this._pieceKey(e),delete this._board[e]}remove(e){const t=this.get(e);return this._clear(J[e]),t&&t.type===j&&(this._kings[t.color]=Q),this._updateCastlingRights(),this._updateEnPassantSquare(),this._updateSetup(this.fen()),t}_updateCastlingRights(){this._hash^=this._castlingKey();const e=this._board[J.e1]?.type===j&&this._board[J.e1]?.color===E,t=this._board[J.e8]?.type===j&&this._board[J.e8]?.color===x;e&&this._board[J.a1]?.type===M&&this._board[J.a1]?.color===E||(this._castling.w&=-65),e&&this._board[J.h1]?.type===M&&this._board[J.h1]?.color===E||(this._castling.w&=-33),t&&this._board[J.a8]?.type===M&&this._board[J.a8]?.color===x||(this._castling.b&=-65),t&&this._board[J.h8]?.type===M&&this._board[J.h8]?.color===x||(this._castling.b&=-33),this._hash^=this._castlingKey()}_updateEnPassantSquare(){if(this._epSquare===Q)return;const e=this._epSquare+(this._turn===E?-16:16),t=this._epSquare+(this._turn===E?16:-16),n=[t+1,t-1];if(null!==this._board[e]||null!==this._board[this._epSquare]||this._board[t]?.color!==ne(this._turn)||this._board[t]?.type!==V)return this._hash^=this._epKey(),void(this._epSquare=Q);n.some(e=>!(136&e)&&this._board[e]?.color===this._turn&&this._board[e]?.type===V)||(this._hash^=this._epKey(),this._epSquare=Q)}_attacked(e,t,n){const A=[];for(let o=J.a8;o<=J.h1;o++){if(136&o){o+=7;continue}if(void 0===this._board[o]||this._board[o].color!==e)continue;const r=this._board[o],i=o-t;if(0===i)continue;const s=i+119;if(R[s]&L[r.type]){if(r.type===V){if(i>0&&r.color===E||i<=0&&r.color===x){if(!n)return!0;A.push(te(o))}continue}if("n"===r.type||"k"===r.type){if(n){A.push(te(o));continue}return!0}const e=F[s];let a=o+e,c=!1;for(;a!==t;){if(null!=this._board[a]){c=!0;break}a+=e}if(!c){if(n){A.push(te(o));continue}return!0}}}return!!n&&A}attackers(e,t){return t?this._attacked(t,J[e],!0):this._attacked(this._turn,J[e],!0)}_isKingAttacked(e){const t=this._kings[e];return-1!==t&&this._attacked(ne(e),t)}hash(){return this._hash.toString(16)}isAttacked(e,t){return this._attacked(t,J[e])}isCheck(){return this._isKingAttacked(this._turn)}inCheck(){return this.isCheck()}isCheckmate(){return this.isCheck()&&0===this._moves().length}isStalemate(){return!this.isCheck()&&0===this._moves().length}isInsufficientMaterial(){const e={b:0,n:0,r:0,q:0,k:0,p:0},t=[];let n=0,A=0;for(let o=J.a8;o<=J.h1;o++){if(A=(A+1)%2,136&o){o+=7;continue}const r=this._board[o];r&&(e[r.type]=r.type in e?e[r.type]+1:1,r.type===N&&t.push(A),n++)}if(2===n)return!0;if(3===n&&(1===e[N]||1===e.n))return!0;if(n===e[N]+2){let e=0;const n=t.length;for(let A=0;A<n;A++)e+=t[A];if(0===e||e===n)return!0}return!1}isThreefoldRepetition(){return this._getPositionCount(this._hash)>=3}isDrawByFiftyMoves(){return this._halfMoves>=100}isDraw(){return this.isDrawByFiftyMoves()||this.isStalemate()||this.isInsufficientMaterial()||this.isThreefoldRepetition()}isGameOver(){return this.isCheckmate()||this.isDraw()}moves({verbose:e=!1,square:t,piece:n}={}){const A=this._moves({square:t,piece:n});return e?A.map(e=>new T(this,e)):A.map(e=>this._moveToSan(e,A))}_moves({legal:e=!0,piece:t,square:n}={}){const A=n?n.toLowerCase():void 0,o=t?.toLowerCase(),r=[],i=this._turn,s=ne(i);let a=J.a8,c=J.h1,l=!1;if(A){if(!(A in J))return[];a=c=J[A],l=!0}for(let e=a;e<=c;e++){if(136&e){e+=7;continue}if(!this._board[e]||this._board[e].color===s)continue;const{type:t}=this._board[e];let n;if(t===V){if(o&&o!==t)continue;n=e+K[i][0],this._board[n]||(oe(r,i,e,n,V),n=e+K[i][1],_[i]!==X(e)||this._board[n]||oe(r,i,e,n,V,void 0,O.BIG_PAWN));for(let t=2;t<4;t++)n=e+K[i][t],136&n||(this._board[n]?.color===s?oe(r,i,e,n,V,this._board[n].type,O.CAPTURE):n===this._epSquare&&oe(r,i,e,n,V,V,O.EP_CAPTURE))}else{if(o&&o!==t)continue;for(let A=0,o=G[t].length;A<o;A++){const o=G[t][A];for(n=e;n+=o,!(136&n);){if(this._board[n]){if(this._board[n].color===i)break;oe(r,i,e,n,t,this._board[n].type,O.CAPTURE);break}if(oe(r,i,e,n,t),"n"===t||t===j)break}}}}if(!(void 0!==o&&o!==j||l&&c!==this._kings[i])){if(this._castling[i]&O.KSIDE_CASTLE){const e=this._kings[i],t=e+2;this._board[e+1]||this._board[t]||this._attacked(s,this._kings[i])||this._attacked(s,e+1)||this._attacked(s,t)||oe(r,i,this._kings[i],t,j,void 0,O.KSIDE_CASTLE)}if(this._castling[i]&O.QSIDE_CASTLE){const e=this._kings[i],t=e-2;this._board[e-1]||this._board[e-2]||this._board[e-3]||this._attacked(s,this._kings[i])||this._attacked(s,e-1)||this._attacked(s,t)||oe(r,i,this._kings[i],t,j,void 0,O.QSIDE_CASTLE)}}if(!e||-1===this._kings[i])return r;const u=[];for(let e=0,t=r.length;e<t;e++)this._makeMove(r[e]),this._isKingAttacked(i)||u.push(r[e]),this._undoMove();return u}move(e,{strict:t=!1}={}){let n=null;if("string"==typeof e)n=this._moveFromSan(e,t);else if(null===e)n=this._moveFromSan(H,t);else if("object"==typeof e){const t=this._moves();for(let A=0,o=t.length;A<o;A++)if(e.from===te(t[A].from)&&e.to===te(t[A].to)&&(!("promotion"in t[A])||e.promotion===t[A].promotion)){n=t[A];break}}if(!n)throw"string"==typeof e?new Error(`Invalid move: ${e}`):new Error(`Invalid move: ${JSON.stringify(e)}`);if(this.isCheck()&&n.flags&O.NULL_MOVE)throw new Error("Null move not allowed when in check");const A=new T(this,n);return this._makeMove(n),this._incPositionCount(),A}_push(e){this._history.push({move:e,kings:{b:this._kings.b,w:this._kings.w},turn:this._turn,castling:{b:this._castling.b,w:this._castling.w},epSquare:this._epSquare,halfMoves:this._halfMoves,moveNumber:this._moveNumber})}_movePiece(e,t){this._hash^=this._pieceKey(e),this._board[t]=this._board[e],delete this._board[e],this._hash^=this._pieceKey(t)}_makeMove(e){const t=this._turn,n=ne(t);if(this._push(e),e.flags&O.NULL_MOVE)return t===x&&this._moveNumber++,this._halfMoves++,this._turn=n,void(this._epSquare=Q);if(this._hash^=this._epKey(),this._hash^=this._castlingKey(),e.captured&&(this._hash^=this._pieceKey(e.to)),this._movePiece(e.from,e.to),e.flags&O.EP_CAPTURE&&(this._turn===x?this._clear(e.to-16):this._clear(e.to+16)),e.promotion&&(this._clear(e.to),this._set(e.to,{type:e.promotion,color:t})),this._board[e.to].type===j){if(this._kings[t]=e.to,e.flags&O.KSIDE_CASTLE){const t=e.to-1,n=e.to+1;this._movePiece(n,t)}else if(e.flags&O.QSIDE_CASTLE){const t=e.to+1,n=e.to-2;this._movePiece(n,t)}this._castling[t]=0}if(this._castling[t])for(let n=0,A=Y[t].length;n<A;n++)if(e.from===Y[t][n].square&&this._castling[t]&Y[t][n].flag){this._castling[t]^=Y[t][n].flag;break}if(this._castling[n])for(let t=0,A=Y[n].length;t<A;t++)if(e.to===Y[n][t].square&&this._castling[n]&Y[n][t].flag){this._castling[n]^=Y[n][t].flag;break}if(this._hash^=this._castlingKey(),e.flags&O.BIG_PAWN){let A;A=t===x?e.to-16:e.to+16,(e.to-1&136||this._board[e.to-1]?.type!==V||this._board[e.to-1]?.color!==n)&&(e.to+1&136||this._board[e.to+1]?.type!==V||this._board[e.to+1]?.color!==n)?this._epSquare=Q:(this._epSquare=A,this._hash^=this._epKey())}else this._epSquare=Q;e.piece===V||e.flags&(O.CAPTURE|O.EP_CAPTURE)?this._halfMoves=0:this._halfMoves++,t===x&&this._moveNumber++,this._turn=n,this._hash^=S}undo(){const e=this._hash,t=this._undoMove();if(t){const n=new T(this,t);return this._decPositionCount(e),n}return null}_undoMove(){const e=this._history.pop();if(void 0===e)return null;this._hash^=this._epKey(),this._hash^=this._castlingKey();const t=e.move;this._kings=e.kings,this._turn=e.turn,this._castling=e.castling,this._epSquare=e.epSquare,this._halfMoves=e.halfMoves,this._moveNumber=e.moveNumber,this._hash^=this._epKey(),this._hash^=this._castlingKey(),this._hash^=S;const n=this._turn,A=ne(n);if(t.flags&O.NULL_MOVE)return t;if(this._movePiece(t.to,t.from),t.piece&&(this._clear(t.from),this._set(t.from,{type:t.piece,color:n})),t.captured)if(t.flags&O.EP_CAPTURE){let e;e=n===x?t.to-16:t.to+16,this._set(e,{type:V,color:A})}else this._set(t.to,{type:t.captured,color:A});if(t.flags&(O.KSIDE_CASTLE|O.QSIDE_CASTLE)){let e,n;t.flags&O.KSIDE_CASTLE?(e=t.to+1,n=t.to-1):(e=t.to-2,n=t.to+1),this._movePiece(n,e)}return t}pgn({newline:e="\n",maxWidth:t=0}={}){const n=[];let A=!1;for(const t in this._header){this._header[t]&&n.push(`[${t} "${this._header[t]}"]`+e),A=!0}A&&this._history.length&&n.push(e);const o=e=>{const t=this._comments[this.fen()];if(void 0!==t){e=`${e}${e.length>0?" ":""}{${t}}`}return e},r=[];for(;this._history.length>0;)r.push(this._undoMove());const i=[];let s="";for(0===r.length&&i.push(o(""));r.length>0;){s=o(s);const e=r.pop();if(!e)break;if(this._history.length||"b"!==e.color)"w"===e.color&&(s.length&&i.push(s),s=this._moveNumber+".");else{const e=`${this._moveNumber}. ...`;s=s?`${s} ${e}`:e}s=s+" "+this._moveToSan(e,this._moves({legal:!0})),this._makeMove(e)}if(s.length&&i.push(o(s)),i.push(this._header.Result||"*"),0===t)return n.join("")+i.join(" ");const a=function(){return n.length>0&&" "===n[n.length-1]&&(n.pop(),!0)},c=function(A,o){for(const r of o.split(" "))if(r){if(A+r.length>t){for(;a();)A--;n.push(e),A=0}n.push(r),A+=r.length,n.push(" "),A++}return a()&&A--,A};let l=0;for(let A=0;A<i.length;A++)l+i[A].length>t&&i[A].includes("{")?l=c(l,i[A]):(l+i[A].length>t&&0!==A?(" "===n[n.length-1]&&n.pop(),n.push(e),l=0):0!==A&&(n.push(" "),l++),n.push(i[A]),l+=i[A].length);return n.join("")}header(...e){for(let t=0;t<e.length;t+=2)"string"==typeof e[t]&&"string"==typeof e[t+1]&&(this._header[e[t]]=e[t+1]);return this._header}setHeader(e,t){return this._header[e]=t??U[e]??null,this.getHeaders()}removeHeader(e){return e in this._header&&(this._header[e]=U[e]||null,!0)}getHeaders(){const e={};for(const[t,n]of Object.entries(this._header))null!==n&&(e[t]=n);return e}loadPgn(e,{strict:t=!1,newlineChar:n="\r?\n"}={}){"\r?\n"!==n&&(e=e.replace(new RegExp(n,"g"),"\n"));const A=m(e);this.reset();const o=A.headers;let r="";for(const e in o)"fen"===e.toLowerCase()&&(r=o[e]),this.header(e,o[e]);if(t){if("1"===o.SetUp){if(!("FEN"in o))throw new Error("Invalid PGN: FEN tag must be supplied with SetUp tag");this.load(o.FEN,{preserveHeaders:!0})}}else r&&this.load(r,{preserveHeaders:!0});let i=A.root;for(;i;){if(i.move){const e=this._moveFromSan(i.move,t);if(null==e)throw new Error(`Invalid move in PGN: ${i.move}`);this._makeMove(e),this._incPositionCount()}void 0!==i.comment&&(this._comments[this.fen()]=i.comment),i=i.variations[0]}const s=A.result;s&&Object.keys(this._header).length&&this._header.Result!==s&&this.setHeader("Result",s)}_moveToSan(e,t){let n="";if(e.flags&O.KSIDE_CASTLE)n="O-O";else if(e.flags&O.QSIDE_CASTLE)n="O-O-O";else{if(e.flags&O.NULL_MOVE)return H;if(e.piece!==V){const A=function(e,t){const n=e.from,A=e.to,o=e.piece;let r=0,i=0,s=0;for(let e=0,a=t.length;e<a;e++){const a=t[e].from,c=t[e].to;o===t[e].piece&&n!==a&&A===c&&(r++,X(n)===X(a)&&i++,$(n)===$(a)&&s++)}return r>0?i>0&&s>0?te(n):s>0?te(n).charAt(1):te(n).charAt(0):""}(e,t);n+=e.piece.toUpperCase()+A}e.flags&(O.CAPTURE|O.EP_CAPTURE)&&(e.piece===V&&(n+=te(e.from)[0]),n+="x"),n+=te(e.to),e.promotion&&(n+="="+e.promotion.toUpperCase())}return this._makeMove(e),this.isCheck()&&(this.isCheckmate()?n+="#":n+="+"),this._undoMove(),n}_moveFromSan(e,t=!1){let n=ie(e);if(t||("0-0"===n?n="O-O":"0-0-0"===n&&(n="O-O-O")),n==H){return{color:this._turn,from:0,to:0,piece:"k",flags:O.NULL_MOVE}}let A,o,r,i,s,a=re(n),c=this._moves({legal:!0,piece:a});for(let e=0,t=c.length;e<t;e++)if(n===ie(this._moveToSan(c[e],c)))return c[e];if(t)return null;let l=!1;if(o=n.match(/([pnbrqkPNBRQK])?([a-h][1-8])x?-?([a-h][1-8])([qrbnQRBN])?/),o?(A=o[1],r=o[2],i=o[3],s=o[4],1==r.length&&(l=!0)):(o=n.match(/([pnbrqkPNBRQK])?([a-h]?[1-8]?)x?-?([a-h][1-8])([qrbnQRBN])?/),o&&(A=o[1],r=o[2],i=o[3],s=o[4],1==r.length&&(l=!0))),a=re(n),c=this._moves({legal:!0,piece:A||a}),!i)return null;for(let e=0,t=c.length;e<t;e++)if(r){if(!(A&&A.toLowerCase()!=c[e].piece||J[r]!=c[e].from||J[i]!=c[e].to||s&&s.toLowerCase()!=c[e].promotion))return c[e];if(l){const t=te(c[e].from);if(!(A&&A.toLowerCase()!=c[e].piece||J[i]!=c[e].to||r!=t[0]&&r!=t[1]||s&&s.toLowerCase()!=c[e].promotion))return c[e]}}else if(n===ie(this._moveToSan(c[e],c)).replace("x",""))return c[e];return null}ascii(){let e=" +------------------------+\n";for(let t=J.a8;t<=J.h1;t++){if(0===$(t)&&(e+=" "+"87654321"[X(t)]+" |"),this._board[t]){const n=this._board[t].type;e+=" "+(this._board[t].color===E?n.toUpperCase():n.toLowerCase())+" "}else e+=" . ";t+1&136&&(e+="|\n",t+=8)}return e+=" +------------------------+\n",e+=" a b c d e f g h",e}perft(e){const t=this._moves({legal:!1});let n=0;const A=this._turn;for(let o=0,r=t.length;o<r;o++)this._makeMove(t[o]),this._isKingAttacked(A)||(e-1>0?n+=this.perft(e-1):n++),this._undoMove();return n}setTurn(e){return this._turn!=e&&(this.move("--"),!0)}turn(){return this._turn}board(){const e=[];let t=[];for(let n=J.a8;n<=J.h1;n++)null==this._board[n]?t.push(null):t.push({square:te(n),type:this._board[n].type,color:this._board[n].color}),n+1&136&&(e.push(t),t=[],n+=8);return e}squareColor(e){if(e in J){const t=J[e];return(X(t)+$(t))%2==0?"light":"dark"}return null}history({verbose:e=!1}={}){const t=[],n=[];for(;this._history.length>0;)t.push(this._undoMove());for(;;){const A=t.pop();if(!A)break;e?n.push(new T(this,A)):n.push(this._moveToSan(A,this._moves())),this._makeMove(A)}return n}_getPositionCount(e){return this._positionCount.get(e)??0}_incPositionCount(){this._positionCount.set(this._hash,(this._positionCount.get(this._hash)??0)+1)}_decPositionCount(e){const t=this._positionCount.get(e)??0;1===t?this._positionCount.delete(e):this._positionCount.set(e,t-1)}_pruneComments(){const e=[],t={},n=e=>{e in this._comments&&(t[e]=this._comments[e])};for(;this._history.length>0;)e.push(this._undoMove());for(n(this.fen());;){const t=e.pop();if(!t)break;this._makeMove(t),n(this.fen())}this._comments=t}getComment(){return this._comments[this.fen()]}setComment(e){this._comments[this.fen()]=e.replace("{","[").replace("}","]")}deleteComment(){return this.removeComment()}removeComment(){const e=this._comments[this.fen()];return delete this._comments[this.fen()],e}getComments(){return this._pruneComments(),Object.keys(this._comments).map(e=>({fen:e,comment:this._comments[e]}))}deleteComments(){return this.removeComments()}removeComments(){return this._pruneComments(),Object.keys(this._comments).map(e=>{const t=this._comments[e];return delete this._comments[e],{fen:e,comment:t}})}setCastlingRights(e,t){for(const n of[j,B])void 0!==t[n]&&(t[n]?this._castling[e]|=W[n]:this._castling[e]&=~W[n]);this._updateCastlingRights();const n=this.getCastlingRights(e);return!(void 0!==t[j]&&t[j]!==n[j]||void 0!==t[B]&&t[B]!==n[B])}getCastlingRights(e){return{[j]:0!==(this._castling[e]&W[j]),[B]:0!==(this._castling[e]&W[B])}}moveNumber(){return this._moveNumber}}const ae={initial:"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",empty:"8/8/8/8/8/8/8/8 w - - 0 1"},ce=ae.initial,le={fen:ae,initialFen:ce,emptyFen:ae.empty},ue=e=>{const[n,A]=t.useState(e.fen||ce),o=e?.skipValidation||!1,[r,i]=t.useState(new se(n,{skipValidation:o}));t.useEffect(()=>{e.fen&&(A(e.fen),i(new se(e.fen,{skipValidation:o})),a([]))},[e.fen,e.reset]);const[s,a]=t.useState([]),c=e.lastMove&&e.lastMove.promotion,l="w"===r.turn()?"white":"black",[u]=t.useState(e.orientation||l),h=(e,t,n)=>{a([e,t]);try{const o=r.move({from:e,to:t,promotion:n});return A(r.fen()),o}catch{return!1}};return{chess:r,fen:n,turnColor:l,lastMove:s,orientation:u,promotion:c,onMove:h,onPromote:e=>h(s[0],s[1],e),onUndo:()=>{const e=r.undo();return e?(A(r.fen()),a([]),e):null}}},he=()=>{const{theme:e,setTheme:n}=t.useContext(i);return{theme:e,setTheme:n,handleChecked:e=>{const t=e.target.name,A=e.target.checked;u.local.set(`chessground.${t}`,A),n(e=>({...e,[t]:A}))},handleChange:e=>{const t=e.target.name,A=e.target.value;u.local.set(`chessground.${t}`,A),n(e=>({...e,[t]:A}))}}},pe=(e=!1)=>{const[n,A]=t.useState(e);return{isOpen:n,show:()=>{A(!0)},hide:()=>{A(!1)},toggle:()=>{A(!n)}}};function ge(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var A=n.call(e,t||"default");if("object"!=typeof A)return A;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""} /** @license React v16.13.1 * react-is.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var de="function"==typeof Symbol&&Symbol.for,me=de?Symbol.for("react.element"):60103,fe=de?Symbol.for("react.portal"):60106,be=de?Symbol.for("react.fragment"):60107,ye=de?Symbol.for("react.strict_mode"):60108,Ie=de?Symbol.for("react.profiler"):60114,ke=de?Symbol.for("react.provider"):60109,we=de?Symbol.for("react.context"):60110,Ce=de?Symbol.for("react.async_mode"):60111,ve=de?Symbol.for("react.concurrent_mode"):60111,Se=de?Symbol.for("react.forward_ref"):60112,Ee=de?Symbol.for("react.suspense"):60113,xe=de?Symbol.for("react.suspense_list"):60120,Ve=de?Symbol.for("react.memo"):60115,Ne=de?Symbol.for("react.lazy"):60116,Me=de?Symbol.for("react.block"):60121,Be=de?Symbol.for("react.fundamental"):60117,je=de?Symbol.for("react.responder"):60118,De=de?Symbol.for("react.scope"):60119;function Te(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case me:switch(e=e.type){case Ce:case ve:case be:case Ie:case ye:case Ee:return e;default:switch(e=e&&e.$$typeof){case we:case Se:case Ne:case Ve:case ke:return e;default:return t}}case fe:return t}}}function Qe(e){return Te(e)===ve}var Ze={AsyncMode:Ce,ConcurrentMode:ve,ContextConsumer:we,ContextProvider:ke,Element:me,ForwardRef:Se,Fragment:be,Lazy:Ne,Memo:Ve,Portal:fe,Profiler:Ie,StrictMode:ye,Suspense:Ee,isAsyncMode:function(e){return Qe(e)||Te(e)===Ce},isConcurrentMode:Qe,isContextConsumer:function(e){return Te(e)===we},isContextProvider:function(e){return Te(e)===ke},isElement:function(e){return"object"==typeof e&&null!==e&&e.$$typeof===me},isForwardRef:function(e){return Te(e)===Se},isFragment:function(e){return Te(e)===be},isLazy:function(e){return Te(e)===Ne},isMemo:function(e){return Te(e)===Ve},isPortal:function(e){return Te(e)===fe},isProfiler:function(e){return Te(e)===Ie},isStrictMode:function(e){return Te(e)===ye},isSuspense:function(e){return Te(e)===Ee},isValidElementType:function(e){return"string"==typeof e||"function"==typeof e||e===be||e===ve||e===Ie||e===ye||e===Ee||e===xe||"object"==typeof e&&null!==e&&(e.$$typeof===Ne||e.$$typeof===Ve||e.$$typeof===ke||e.$$typeof===we||e.$$typeof===Se||e.$$typeof===Be||e.$$typeof===je||e.$$typeof===De||e.$$typeof===Me)},typeOf:Te},Pe=l(function(e,t){"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,n=e?Symbol.for("react.element"):60103,A=e?Symbol.for("react.portal"):60106,o=e?Symbol.for("react.fragment"):60107,r=e?Symbol.for("react.strict_mode"):60108,i=e?Symbol.for("react.profiler"):60114,s=e?Symbol.for("react.provider"):60109,a=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,h=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,g=e?Symbol.for("react.memo"):60115,d=e?Symbol.for("react.lazy"):60116,m=e?Symbol.for("react.block"):60121,f=e?Symbol.for("react.fundamental"):60117,b=e?Symbol.for("react.responder"):60118,y=e?Symbol.for("react.scope"):60119;function I(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case n:var p=e.type;switch(p){case c:case l:case o:case i:case r:case h:return p;default:var m=p&&p.$$typeof;switch(m){case a:case u:case d:case g:case s:return m;default:return t}}case A:return t}}}var k=c,w=l,C=a,v=s,S=n,E=u,x=o,V=d,N=g,M=A,B=i,j=r,D=h,T=!1;function Q(e){return I(e)===l}t.AsyncMode=k,t.ConcurrentMode=w,t.ContextConsumer=C,t.ContextProvider=v,t.Element=S,t.ForwardRef=E,t.Fragment=x,t.Lazy=V,t.Memo=N,t.Portal=M,t.Profiler=B,t.StrictMode=j,t.Suspense=D,t.isAsyncMode=function(e){return T||(T=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),Q(e)||I(e)===c},t.isConcurrentMode=Q,t.isContextConsumer=function(e){return I(e)===a},t.isContextProvider=function(e){return I(e)===s},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},t.isForwardRef=function(e){return I(e)===u},t.isFragment=function(e){return I(e)===o},t.isLazy=function(e){return I(e)===d},t.isMemo=function(e){return I(e)===g},t.isPortal=function(e){return I(e)===A},t.isProfiler=function(e){return I(e)===i},t.isStrictMode=function(e){return I(e)===r},t.isSuspense=function(e){return I(e)===h},t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===o||e===l||e===i||e===r||e===h||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===d||e.$$typeof===g||e.$$typeof===s||e.$$typeof===a||e.$$typeof===u||e.$$typeof===f||e.$$typeof===b||e.$$typeof===y||e.$$typeof===m)},t.typeOf=I}()}),Oe=l(function(e){"production"===process.env.NODE_ENV?e.exports=Ze:e.exports=Pe}),Ue=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable;var Ke=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var A=Object.getOwnPropertyNames(t).map(function(e){return t[e]});if("0123456789"!==A.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(e){o[e]=e}),"abcdefghijklmnopqrst"===Object