@lichess-org/chessground 9.8.2 → 9.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var Ye=["white","black"];var W=["a","b","c","d","e","f","g","h"],j=["1","2","3","4","5","6","7","8"];var eo=[...j].reverse(),Q=W.flatMap(e=>j.map(o=>e+o)),M=e=>e.every(o=>o>=0&&o<=7)?Q[8*e[0]+e[1]]:void 0,L=e=>M(e),f=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var De=Q.map(f),oo=Q.map((e,o)=>({key:e,pos:De[o]}));function ro(e){let o,r=()=>(o===void 0&&(o=e()),o);return r.clear=()=>{o=void 0},r}var no=()=>{let e;return{start(){e=performance.now()},cancel(){e=void 0},stop(){if(!e)return 0;let o=performance.now()-e;return e=void 0,o}}},U=e=>e==="white"?"black":"white",F=(e,o)=>(e[0]-o[0])**2+(e[1]-o[1])**2,z=(e,o)=>e.role===o.role&&e.color===o.color,le=(e,o)=>e[0]===o[0]&&e[1]===o[1],G=e=>(o,r)=>[(r?o[0]:7-o[0])*e.width/8,(r?7-o[1]:o[1])*e.height/8],C=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},Ke=(e,o,r=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${r})`},Y=(e,o)=>{e.style.visibility=o?"visible":"hidden"},x=e=>{if(e.clientX||e.clientX===0)return[e.clientX,e.clientY];if(e.targetTouches?.[0])return[e.targetTouches[0].clientX,e.targetTouches[0].clientY]},de=e=>e.button===2,k=(e,o)=>{let r=document.createElement(e);return o&&(r.className=o),r};function ue(e,o,r){let n=f(e);return o||(n[0]=7-n[0],n[1]=7-n[1]),[r.left+r.width*n[0]/8+r.width/16,r.top+r.height*(7-n[1])/8+r.height/16]}var K=(e,o)=>Math.abs(e-o),J=(e,o,r,n)=>K(e,r)*K(o,n)===2,pe=(e,o,r,n)=>e===r!=(o===n),fe=(e,o,r,n)=>K(e,r)===K(o,n)&&e!==r,ge=(e,o,r,n)=>pe(e,o,r,n)||fe(e,o,r,n),xe=(e,o,r,n)=>Math.max(K(e,r),K(o,n))===1,Ee=(e,o,r,n,t)=>K(e,r)===1&&n===o+(t?1:-1),Ae=(e,o,r,n,t)=>{let i=t?1:-1;return e===r&&(n===o+i||n===o+2*i&&(t?o<=1:o>=6))},ee=(e,o,r,n)=>{let t=r-e,i=n-o;if(t&&i&&Math.abs(t)!==Math.abs(i))return[];let a=Math.sign(t),l=Math.sign(i),d=[],s=e+a,c=o+l;for(;s!==r||c!==n;)d.push([s,c]),s+=a,c+=l;return d.map(M).filter(u=>u!==void 0)},to=e=>{let o=f(e),r=[];return o[0]>0&&r.push([o[0]-1,o[1]]),o[0]<7&&r.push([o[0]+1,o[1]]),r.map(M).filter(n=>n!==void 0)},oe=(e,o)=>{let r=f(e);return r[1]+=o,M(r)};var Z=e=>e.friendlies.has(e.dest.key),ar=e=>e.enemies.has(e.dest.key),io=(e,o,r)=>ee(...e,...o).some(n=>r.has(n)),ao=(e,o,r)=>{let n=r.enemies.get(e);if(n?.role!=="pawn")return!1;let t=n.color==="white"?1:-1,i=f(e),a=f(o);return Ae(...i,...a,n.color==="white")&&!io(i,[a[0],a[1]+t],r.allPieces)},sr=(e,o,r)=>{let n=r.enemies.get(e);return n?.role==="pawn"&&Ee(...f(e),...f(o),n.color==="white")&&(r.friendlies.has(o)||be(oe(o,n.color==="white"?-1:1),r.friendlies,r.enemies,r.lastMove))},cr=e=>[...e.enemies.keys()].some(o=>ao(o,e.dest.key,e)),Ne=(e,o)=>{let r=e.dest.pos;return[...e.enemies].some(([n,t])=>{let i=f(n);return!o?.includes(t.role)&&(t.role==="pawn"&&Ee(...i,...r,t.color==="white")||t.role==="knight"&&J(...i,...r)||t.role==="bishop"&&fe(...i,...r)||t.role==="rook"&&pe(...i,...r)||t.role==="queen"&&ge(...i,...r)||t.role==="king"&&xe(...i,...r))&&(!["bishop","rook","queen"].includes(t.role)||!io(i,r,e.allPieces))})},me=e=>Z(e)&&(be(e.dest.key,e.friendlies,e.enemies,e.lastMove)||Ne(e)),be=(e,o,r,n)=>{if(!e||n&&e!==n[1])return!1;let t=f(e),i=o.get(e);return i?.role==="pawn"&&t[1]===(i.color==="white"?3:4)&&(!n||K(f(n[0])[1],t[1])===2)&&[1,-1].some(a=>{let l=M([t[0]+a,t[1]]);return!!l&&r.get(l)?.role==="pawn"})},lr=(e,o)=>{if(e.unrestrictedPremoves)return!0;let r=ee(...e.orig.pos,...e.dest.pos);o&&r.push(e.dest.key);let n=r.filter(a=>e.friendlies.has(a));if(!n.length)return!0;let t=n[0],i=oe(t,e.color==="white"?-1:1);return n.length===1&&be(t,e.friendlies,e.enemies,e.lastMove)&&!!i&&!r.includes(i)},dr=(e,o)=>{if(e.unrestrictedPremoves)return!0;let r=ee(...e.orig.pos,...e.dest.pos);o&&r.push(e.dest.key);let n=r.filter(c=>e.enemies.has(c));if(n.length>1)return!1;if(!n.length)return!0;let t=n[0],i=e.enemies.get(t);if(!i||i.role!=="pawn")return!0;let a=i.color==="white"?1:-1,l=oe(t,a),d=l?[...to(l).filter(c=>sr(t,c,e)),...[l,oe(l,a)].filter(c=>!!c).filter(c=>ao(t,c,e))]:[],s=[...r,e.orig.key];return d.some(c=>!s.includes(c))},He=(e,o)=>lr(e,o)&&dr(e,o),ur=e=>{let o=e.color==="white"?1:-1;return K(e.orig.pos[0],e.dest.pos[0])>1?!1:K(e.orig.pos[0],e.dest.pos[0])?e.dest.pos[1]!==e.orig.pos[1]+o?!1:e.unrestrictedPremoves||ar(e)?!0:Z(e)?Ne(e):cr(e)||be(M([e.dest.pos[0],e.dest.pos[1]+o]),e.friendlies,e.enemies,e.lastMove)||Ne(e,["pawn"]):Ae(...e.orig.pos,...e.dest.pos,e.color==="white")&&He(e,!0)},pr=e=>J(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||me(e)),so=e=>fe(...e.orig.pos,...e.dest.pos)&&He(e,!1)&&(e.unrestrictedPremoves||!Z(e)||me(e)),co=e=>pe(...e.orig.pos,...e.dest.pos)&&He(e,!1)&&(e.unrestrictedPremoves||!Z(e)||me(e)),fr=e=>so(e)||co(e),gr=e=>xe(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||me(e))||e.canCastle&&e.orig.pos[1]===e.dest.pos[1]&&e.orig.pos[1]===(e.color==="white"?0:7)&&(e.orig.pos[0]===4&&(e.dest.pos[0]===2&&e.rookFilesFriendlies.includes(0)||e.dest.pos[0]===6&&e.rookFilesFriendlies.includes(7))||e.rookFilesFriendlies.includes(e.dest.pos[0]))&&(e.unrestrictedPremoves||ee(...e.orig.pos,e.dest.pos[0]>e.orig.pos[0]?7:1,e.dest.pos[1]).map(o=>e.allPieces.get(o)).every(o=>!o||z(o,{role:"rook",color:e.color}))),mr={pawn:ur,knight:pr,bishop:so,rook:co,queen:fr,king:gr};function qe(e,o){let r=e.pieces,n=e.premovable.castle,t=!!e.premovable.unrestrictedPremoves,i=r.get(o);if(!i||i.color===e.turnColor)return[];let a=i.color,l=new Map([...r].filter(([p,m])=>m.color===a)),d=new Map([...r].filter(([p,m])=>m.color===U(a))),s={key:o,pos:f(o)},c=p=>mr[i.role](p)&&e.premovable.additionalPremoveRequirements(p),u={orig:s,role:i.role,allPieces:r,friendlies:l,enemies:d,unrestrictedPremoves:t,color:a,canCastle:n,rookFilesFriendlies:Array.from(r).filter(([p,m])=>p[1]===(a==="white"?"1":"8")&&m.color===a&&m.role==="rook").map(([p])=>f(p)[0]),lastMove:e.lastMove};return oo.filter(p=>c({...u,dest:p})).map(p=>p.key)}function S(e,...o){e&&setTimeout(()=>e(...o),1)}function lo(e){e.orientation=U(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function uo(e,o){for(let[r,n]of o)n?e.pieces.set(r,n):e.pieces.delete(r)}function po(e,o){if(e.check=void 0,o===!0&&(o=e.turnColor),o)for(let[r,n]of e.pieces)n.role==="king"&&n.color===o&&(e.check=r)}function br(e,o,r,n){A(e),e.premovable.current=[o,r],S(e.premovable.events.set,o,r,n)}function E(e){e.premovable.current&&(e.premovable.current=void 0,S(e.premovable.events.unset))}function hr(e,o,r){E(e),e.predroppable.current={role:o,key:r},S(e.predroppable.events.set,o,r)}function A(e){let o=e.predroppable;o.current&&(o.current=void 0,S(o.events.unset))}function yr(e,o,r){if(!e.autoCastle)return!1;let n=e.pieces.get(o);if(!n||n.role!=="king")return!1;let t=f(o),i=f(r);if(t[1]!==0&&t[1]!==7||t[1]!==i[1])return!1;t[0]===4&&!e.pieces.has(r)&&(i[0]===6?r=L([7,i[1]]):i[0]===2&&(r=L([0,i[1]])));let a=e.pieces.get(r);return!a||a.color!==n.color||a.role!=="rook"?!1:(e.pieces.delete(o),e.pieces.delete(r),t[0]<i[0]?(e.pieces.set(L([6,i[1]]),n),e.pieces.set(L([5,i[1]]),a)):(e.pieces.set(L([2,i[1]]),n),e.pieces.set(L([3,i[1]]),a)),!0)}function Te(e,o,r){let n=e.pieces.get(o),t=e.pieces.get(r);if(o===r||!n)return!1;let i=t&&t.color!==n.color?t:void 0;return r===e.selected&&P(e),S(e.events.move,o,r,i),yr(e,o,r)||(e.pieces.set(r,n),e.pieces.delete(o)),e.lastMove=[o,r],e.check=void 0,S(e.events.change),i||!0}function he(e,o,r,n){if(e.pieces.has(r))if(n)e.pieces.delete(r);else return!1;return S(e.events.dropNewPiece,o,r),e.pieces.set(r,o),e.lastMove=[r],e.check=void 0,S(e.events.change),e.movable.dests=void 0,e.turnColor=U(e.turnColor),!0}function fo(e,o,r){let n=Te(e,o,r);return n&&(e.movable.dests=void 0,e.turnColor=U(e.turnColor),e.animation.current=void 0),n}function Be(e,o,r){if(ve(e,o,r)){let n=fo(e,o,r);if(n){let t=e.hold.stop();P(e);let i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:t};return n!==!0&&(i.captured=n),S(e.movable.events.after,o,r,i),!0}}else if(wr(e,o,r))return br(e,o,r,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function ye(e,o,r,n){let t=e.pieces.get(o);t&&(vr(e,o,r)||n)?(e.pieces.delete(o),he(e,t,r,n),S(e.movable.events.afterNewPiece,t.role,r,{premove:!1,predrop:!1})):t&&Pr(e,o,r)?hr(e,t.role,r):(E(e),A(e)),e.pieces.delete(o),P(e)}function ne(e,o,r){if(S(e.events.select,o),e.selected){if(e.selected===o&&!e.draggable.enabled){P(e),e.hold.cancel();return}else if((e.selectable.enabled||r)&&e.selected!==o&&Be(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(go(e,o)||Re(e,o))&&(Oe(e,o),e.hold.start())}function Oe(e,o){e.selected=o,Re(e,o)?e.premovable.customDests||(e.premovable.dests=qe(e,o)):e.premovable.dests=void 0}function P(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function go(e,o){let r=e.pieces.get(o);return!!r&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}var ve=(e,o,r)=>o!==r&&go(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(r));function vr(e,o,r){let n=e.pieces.get(o);return!!n&&(o===r||!e.pieces.has(r))&&(e.movable.color==="both"||e.movable.color===n.color&&e.turnColor===n.color)}function Re(e,o){let r=e.pieces.get(o);return!!r&&e.premovable.enabled&&e.movable.color===r.color&&e.turnColor!==r.color}var wr=(e,o,r)=>o!==r&&Re(e,o)&&(e.premovable.customDests?.get(o)??qe(e,o)).includes(r);function Pr(e,o,r){let n=e.pieces.get(o),t=e.pieces.get(r);return!!n&&(!t||t.color!==e.movable.color)&&e.predroppable.enabled&&(n.role!=="pawn"||r[1]!=="1"&&r[1]!=="8")&&e.movable.color===n.color&&e.turnColor!==n.color}function mo(e,o){let r=e.pieces.get(o);return!!r&&e.draggable.enabled&&(e.movable.color==="both"||e.movable.color===r.color&&(e.turnColor===r.color||e.premovable.enabled))}function bo(e){let o=e.premovable.current;if(!o)return!1;let r=o[0],n=o[1],t=!1;if(ve(e,r,n)){let i=fo(e,r,n);if(i){let a={premove:!0};i!==!0&&(a.captured=i),S(e.movable.events.after,r,n,a),t=!0}}return E(e),t}function ho(e,o){let r=e.predroppable.current,n=!1;if(!r)return!1;if(o(r)){let t={role:r.role,color:e.movable.color};he(e,t,r.key)&&(S(e.movable.events.afterNewPiece,r.role,r.key,{premove:!1,predrop:!0}),n=!0)}return A(e),n}function te(e){E(e),A(e),P(e)}function Ve(e){e.movable.color=e.movable.dests=e.animation.current=void 0,te(e)}function N(e,o,r){let n=Math.floor(8*(e[0]-r.left)/r.width);o||(n=7-n);let t=7-Math.floor(8*(e[1]-r.top)/r.height);return o||(t=7-t),n>=0&&n<8&&t>=0&&t<8?M([n,t]):void 0}function yo(e,o,r,n){let t=f(e),i=De.filter(s=>le(t,s)||ge(t[0],t[1],s[0],s[1])||J(t[0],t[1],s[0],s[1])),l=i.map(s=>ue(L(s),r,n)).map(s=>F(o,s)),[,d]=l.reduce((s,c,u)=>s[0]<c?s:[c,u],[l[0],0]);return M(i[d])}var h=e=>e.orientation==="white";var Fe="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",Sr={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},Mr={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function we(e){e==="start"&&(e=Fe);let o=new Map,r=7,n=0;for(let t of e)switch(t){case" ":case"[":return o;case"/":if(--r,r<0)return o;n=0;break;case"~":{let i=M([n-1,r]),a=i&&o.get(i);a&&(a.promoted=!0);break}default:{let i=t.charCodeAt(0);if(i<57)n+=i-48;else{let a=t.toLowerCase(),l=M([n,r]);l&&o.set(l,{role:Sr[a],color:t===a?"black":"white"}),++n}}}return o}function vo(e){return eo.map(o=>W.map(r=>{let n=e.get(r+o);if(n){let t=Mr[n.role];return n.color==="white"&&(t=t.toUpperCase()),n.promoted&&(t+="~"),t}else return"1"}).join("")).join("/").replace(/1{2,}/g,o=>o.length.toString())}function Ge(e,o){o.animation&&(We(e.animation,o.animation),(e.animation.duration||0)<70&&(e.animation.enabled=!1))}function Pe(e,o){if(o.movable?.dests&&(e.movable.dests=void 0),o.drawable?.autoShapes&&(e.drawable.autoShapes=[]),We(e,o),o.fen&&(e.pieces=we(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&po(e,o.check||!1),"lastMove"in o&&!o.lastMove?e.lastMove=void 0:o.lastMove&&(e.lastMove=o.lastMove),e.selected&&Oe(e,e.selected),Ge(e,o),!e.movable.rookCastle&&e.movable.dests){let r=e.movable.color==="white"?"1":"8",n="e"+r,t=e.movable.dests.get(n),i=e.pieces.get(n);if(!t||!i||i.role!=="king")return;e.movable.dests.set(n,t.filter(a=>!(a==="a"+r&&t.includes("c"+r))&&!(a==="h"+r&&t.includes("g"+r))))}}function We(e,o){for(let r in o)r==="__proto__"||r==="constructor"||!Object.prototype.hasOwnProperty.call(o,r)||(Object.prototype.hasOwnProperty.call(e,r)&&wo(e[r])&&wo(o[r])?We(e[r],o[r]):e[r]=o[r])}function wo(e){if(typeof e!="object"||e===null)return!1;let o=Object.getPrototypeOf(e);return o===Object.prototype||o===null}var O=(e,o)=>o.animation.enabled?Kr(e,o):R(e,o);function R(e,o){let r=e(o);return o.dom.redraw(),r}var ze=(e,o)=>({key:e,pos:f(e),piece:o}),kr=(e,o)=>o.sort((r,n)=>F(e.pos,r.pos)-F(e.pos,n.pos))[0];function Dr(e,o){let r=new Map,n=[],t=new Map,i=[],a=[],l=new Map,d,s,c;for(let[u,p]of e)l.set(u,ze(u,p));for(let u of Q)d=o.pieces.get(u),s=l.get(u),d?s?z(d,s.piece)||(i.push(s),a.push(ze(u,d))):a.push(ze(u,d)):s&&i.push(s);for(let u of a)s=kr(u,i.filter(p=>z(u.piece,p.piece))),s&&(c=[s.pos[0]-u.pos[0],s.pos[1]-u.pos[1]],r.set(u.key,c.concat(c)),n.push(s.key));for(let u of i)n.includes(u.key)||t.set(u.key,u.piece);return{anims:r,fadings:t}}function Po(e,o){let r=e.animation.current;if(r===void 0){e.dom.destroyed||e.dom.redrawNow();return}let n=1-(o-r.start)*r.frequency;if(n<=0)e.animation.current=void 0,e.dom.redrawNow();else{let t=xr(n);for(let i of r.plan.anims.values())i[2]=i[0]*t,i[3]=i[1]*t;e.dom.redrawNow(!0),requestAnimationFrame((i=performance.now())=>Po(e,i))}}function Kr(e,o){let r=new Map(o.pieces),n=e(o),t=Dr(r,o);if(t.anims.size||t.fadings.size){let i=o.animation.current&&o.animation.current.start;o.animation.current={start:performance.now(),frequency:1/o.animation.duration,plan:t},i||Po(o,performance.now())}else o.dom.redraw();return n}var xr=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var Er=["green","red","blue","yellow"];function So(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):te(e);let r=x(o),n=N(r,h(e),e.dom.bounds());n&&(e.drawable.current={orig:n,pos:r,brush:Ar(o),snapToValidMove:e.drawable.defaultSnapToValidMove},Mo(e))}function Mo(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let r=N(o.pos,h(e),e.dom.bounds());r||(o.snapToValidMove=!1);let n=o.snapToValidMove?yo(o.orig,o.pos,h(e),e.dom.bounds()):r;n!==o.mouseSq&&(o.mouseSq=n,o.dest=n!==o.orig?n:void 0,e.dom.redrawNow()),Mo(e)}})}function Co(e,o){e.drawable.current&&(e.drawable.current.pos=x(o))}function ko(e){let o=e.drawable.current;o&&(o.mouseSq&&Nr(e.drawable,o),$e(e))}function $e(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function Do(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),Ko(e.drawable))}function Ar(e){let o=(e.shiftKey||e.ctrlKey)&&de(e),r=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return Er[(o?1:0)+(r?2:0)]}function Nr(e,o){let r=t=>t.orig===o.orig&&t.dest===o.dest,n=e.shapes.find(r);n&&(e.shapes=e.shapes.filter(t=>!r(t))),(!n||n.brush!==o.brush)&&e.shapes.push({orig:o.orig,dest:o.dest,brush:o.brush}),Ko(e)}function Ko(e){e.onChange&&e.onChange(e.shapes)}function xo(e,o){if(!(e.trustAllEvents||o.isTrusted)||o.buttons!==void 0&&o.buttons>1||o.touches&&o.touches.length>1)return;let r=e.dom.bounds(),n=x(o),t=N(n,h(e),r);if(!t)return;let i=e.pieces.get(t),a=e.selected;if(!a&&e.drawable.enabled&&(e.drawable.eraseOnMovablePieceClick||!i||i.color!==e.turnColor)&&(e.pixelCoordsOfMouchDownToMaybeClearShapes=n),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||qr(e,n)))o.preventDefault();else if(o.touches)return;let l=!!e.premovable.current,d=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&ve(e,e.selected,t)?O(u=>ne(u,t),e):ne(e,t);let s=e.selected===t,c=qo(e,t);if(i&&c&&s&&mo(e,t)){e.draggable.current={orig:t,piece:i,origPos:n,pos:n,started:e.draggable.autoDistance&&e.stats.dragged,element:c,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},c.cgDragging=!0,c.classList.add("dragging");let u=e.dom.elements.ghost;u&&(u.className=`ghost ${i.color} ${i.role}`,C(u,G(r)(f(t),h(e))),Y(u,!0)),Ie(e)}else l&&E(e),d&&A(e);e.dom.redraw()}function qr(e,o){let r=h(e),n=e.dom.bounds(),t=Math.pow(e.touchIgnoreRadius*n.width/16,2)*2;for(let i of e.pieces.keys()){let a=ue(i,r,n);if(F(a,o)<=t)return!0}return!1}function Eo(e,o,r,n){let t="a0";e.pieces.set(t,o),e.dom.redraw();let i=x(r);e.draggable.current={orig:t,piece:o,origPos:i,pos:i,started:!0,element:()=>qo(e,t),originTarget:r.target,newPiece:!0,force:!!n,keyHasChanged:!1},Ie(e)}function Ie(e){requestAnimationFrame(()=>{let o=e.draggable.current;if(!o)return;e.animation.current?.plan.anims.has(o.orig)&&(e.animation.current=void 0);let r=e.pieces.get(o.orig);if(!r||!z(r,o.piece))$(e);else if(!o.started&&F(o.pos,o.origPos)>=Math.pow(e.draggable.distance,2)&&(o.started=!0),o.started){if(typeof o.element=="function"){let t=o.element();if(!t)return;t.cgDragging=!0,t.classList.add("dragging"),o.element=t}let n=e.dom.bounds();C(o.element,[o.pos[0]-n.left-n.width/16,o.pos[1]-n.top-n.height/16]),o.keyHasChanged||=o.orig!==N(o.pos,h(e),n)}Ie(e)})}function Ao(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=x(o))}function No(e,o){let r=x(o);r&&e.pixelCoordsOfMouchDownToMaybeClearShapes&&le(r,e.pixelCoordsOfMouchDownToMaybeClearShapes)&&Do(e),e.pixelCoordsOfMouchDownToMaybeClearShapes=void 0;let n=e.draggable.current;if(!n)return;if(o.type==="touchend"&&o.cancelable!==!1&&o.preventDefault(),o.type==="touchend"&&n.originTarget!==o.target&&!n.newPiece){e.draggable.current=void 0;return}E(e),A(e);let t=x(o)||n.pos,i=N(t,h(e),e.dom.bounds());i&&n.started&&n.orig!==i?n.newPiece?ye(e,n.orig,i,n.force):(e.stats.ctrlKey=o.ctrlKey,Be(e,n.orig,i)&&(e.stats.dragged=!0)):n.newPiece?e.pieces.delete(n.orig):e.draggable.deleteOnDropOff&&!i&&(e.pieces.delete(n.orig),S(e.events.change)),(n.orig===n.previouslySelected||n.keyHasChanged)&&(n.orig===i||!i)?P(e):e.selectable.enabled||P(e),Ho(e),e.draggable.current=void 0,e.dom.redraw()}function $(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),Ho(e),e.dom.redraw())}function Ho(e){let o=e.dom.elements;o.ghost&&Y(o.ghost,!1)}function qo(e,o){let r=e.dom.elements.board.firstChild;for(;r;){if(r.cgKey===o&&r.tagName==="PIECE")return r;r=r.nextSibling}}function Bo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{To(e,2),setTimeout(()=>To(e,void 0),120)},120)}function To(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function Oo(e,o){function r(){lo(e),o()}return{set(n){n.orientation&&n.orientation!==e.orientation&&r(),Ge(e,n),(n.fen?O:R)(t=>Pe(t,n),e)},state:e,getFen:()=>vo(e.pieces),toggleOrientation:r,setPieces(n){O(t=>uo(t,n),e)},selectSquare(n,t){n?O(i=>ne(i,n,t),e):e.selected&&(P(e),e.dom.redraw())},move(n,t){O(i=>Te(i,n,t),e)},newPiece(n,t){O(i=>he(i,n,t),e)},playPremove(){if(e.premovable.current){if(O(bo,e))return!0;e.dom.redraw()}return!1},playPredrop(n){if(e.predroppable.current){let t=ho(e,n);return e.dom.redraw(),t}return!1},cancelPremove(){R(E,e)},cancelPredrop(){R(A,e)},cancelMove(){R(n=>{te(n),$(n)},e)},stop(){R(n=>{Ve(n),$(n)},e)},explode(n){Bo(e,n)},setAutoShapes(n){R(t=>t.drawable.autoShapes=n,e)},setShapes(n){R(t=>t.drawable.shapes=n.slice(),e)},getKeyAtDomPos(n){return N(n,h(e),e.dom.bounds())},redrawAll:o,dragNewPiece(n,t,i){Eo(e,n,t,i)},destroy(){Ve(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function Ro(){return{pieces:we(Fe),orientation:"white",turnColor:"white",coordinates:!0,coordinatesOnSquares:!1,ranksPosition:"right",autoCastle:!0,viewOnly:!1,disableContextMenu:!1,addPieceZIndex:!1,blockTouchScroll:!1,touchIgnoreRadius:1,pieceKey:!1,trustAllEvents:!1,highlight:{lastMove:!0,check:!0},animation:{enabled:!0,duration:200},movable:{free:!0,color:"both",showDests:!0,events:{},rookCastle:!0},premovable:{enabled:!0,showDests:!0,castle:!0,additionalPremoveRequirements:e=>!0,events:{}},predroppable:{enabled:!1,events:{}},draggable:{enabled:!0,distance:3,autoDistance:!0,showGhost:!0,deleteOnDropOff:!1},dropmode:{active:!1},selectable:{enabled:!0},stats:{dragged:!("ontouchstart"in window)},events:{},drawable:{enabled:!0,visible:!0,defaultSnapToValidMove:!0,eraseOnMovablePieceClick:!0,shapes:[],autoShapes:[],brushes:{green:{key:"g",color:"#15781B",opacity:1,lineWidth:10},red:{key:"r",color:"#882020",opacity:1,lineWidth:10},blue:{key:"b",color:"#003088",opacity:1,lineWidth:10},yellow:{key:"y",color:"#e68f00",opacity:1,lineWidth:10},paleBlue:{key:"pb",color:"#003088",opacity:.4,lineWidth:15},paleGreen:{key:"pg",color:"#15781B",opacity:.4,lineWidth:15},paleRed:{key:"pr",color:"#882020",opacity:.4,lineWidth:15},paleGrey:{key:"pgr",color:"#4a4a4a",opacity:.35,lineWidth:15},purple:{key:"purple",color:"#68217a",opacity:.65,lineWidth:10},pink:{key:"pink",color:"#ee2080",opacity:.5,lineWidth:10},white:{key:"white",color:"white",opacity:1,lineWidth:10},paleWhite:{key:"pwhite",color:"white",opacity:.6,lineWidth:10}},prevSvgHash:""},hold:no()}}function Fo(){let e=v("defs"),o=w(v("filter"),{id:"cg-filter-blur"});return o.appendChild(w(v("feGaussianBlur"),{stdDeviation:"0.013"})),e.appendChild(o),e}function Go(e,o){let r=e.drawable,n=r.current,t=n&&n.mouseSq?n:void 0,i=new Map,a=e.dom.bounds(),l=r.autoShapes.filter(c=>!c.piece);for(let c of r.shapes.concat(l).concat(t?[t]:[])){if(!c.dest)continue;let u=i.get(c.dest)??new Set,p=Me(Se(f(c.orig),e.orientation),a),m=Me(Se(f(c.dest),e.orientation),a);u.add(Ue(p,m)),i.set(c.dest,u)}let d=[];for(let c of r.shapes.concat(l))d.push({shape:c,current:!1,hash:Vo(c,je(c.dest,i),!1,a)});t&&d.push({shape:t,current:!0,hash:Vo(t,je(t.dest,i),!0,a)});let s=d.map(c=>c.hash).join(";");s!==e.drawable.prevSvgHash&&(e.drawable.prevSvgHash=s,Br(r,d,o),Or(d,o,c=>Lr(e,c,r.brushes,i,a)))}function Br(e,o,r){for(let n of[r.shapes,r.shapesBelow]){let t=n.querySelector("defs"),i=o.filter(s=>n===r.shapesBelow==!!s.shape.below),a=new Map;for(let s of i.filter(c=>c.shape.dest&&c.shape.brush)){let c=Wo(e.brushes[s.shape.brush],s.shape.modifiers),{key:u,color:p}=zo(s.shape);u&&p&&a.set(u,{key:u,color:p,opacity:1,lineWidth:1}),a.set(c.key,c)}let l=new Set,d=t.firstElementChild;for(;d;)l.add(d.getAttribute("cgKey")),d=d.nextElementSibling;for(let[s,c]of a.entries())l.has(s)||t.appendChild(Wr(c))}}function Or(e,o,r){for(let[n,t]of[[o.shapes,o.custom],[o.shapesBelow,o.customBelow]]){let[i,a]=[n,t].map(s=>s.querySelector("g")),l=e.filter(s=>n===o.shapesBelow==!!s.shape.below),d=new Map;for(let s of l)d.set(s.hash,!1);for(let s of[i,a]){let c=[],u=s.firstElementChild,p;for(;u;)p=u.getAttribute("cgHash"),d.has(p)?d.set(p,!0):c.push(u),u=u.nextElementSibling;for(let m of c)s.removeChild(m)}for(let s of l.filter(c=>!d.get(c.hash)))for(let c of r(s))c.isCustom?a.appendChild(c.el):i.appendChild(c.el)}}function Vo({orig:e,dest:o,brush:r,piece:n,modifiers:t,customSvg:i,label:a,below:l},d,s,c){return[c.width,c.height,s,e,o,r,d&&"-",n&&Rr(n),t&&Vr(t),i&&`custom-${Lo(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Lo(a.text)}`,l&&"below"].filter(u=>u).join(",")}function Rr(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function Vr(e){return[e.lineWidth,e.hilite].filter(o=>o).join(",")}function Lo(e){let o=0;for(let r=0;r<e.length;r++)o=(o<<5)-o+e.charCodeAt(r)>>>0;return o.toString()}function Lr(e,{shape:o,current:r,hash:n},t,i,a){let l=Me(Se(f(o.orig),e.orientation),a),d=o.dest?Me(Se(f(o.dest),e.orientation),a):l,s=o.brush&&Wo(t[o.brush],o.modifiers),c=i.get(o.dest),u=[];if(s){let p=w(v("g"),{cgHash:n});u.push({el:p}),l[0]!==d[0]||l[1]!==d[1]?p.appendChild(Gr(o,s,l,d,r,je(o.dest,i))):p.appendChild(Fr(t[o.brush],l,r,a))}if(o.label){let p=o.label;p.fill??=o.brush&&t[o.brush].color;let m=o.brush?void 0:"tr";u.push({el:zr(p,n,l,d,c,m),isCustom:!0})}if(o.customSvg){let p=o.customSvg.center??"orig",[m,y]=p==="label"?Io(l,d,c).map(B=>B-.5):p==="dest"?d:l,g=w(v("g"),{transform:`translate(${m},${y})`,cgHash:n});g.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,u.push({el:g,isCustom:!0})}return u}function Fr(e,o,r,n){let t=$r(),i=(n.width+n.height)/(4*Math.max(n.width,n.height));return w(v("circle"),{stroke:e.color,"stroke-width":t[r?0:1],fill:"none",opacity:$o(e,r),cx:o[0],cy:o[1],r:i-t[1]/2})}function Gr(e,o,r,n,t,i){function a(s){let c=jr(i&&!t),u=n[0]-r[0],p=n[1]-r[1],m=Math.atan2(p,u),y=Math.cos(m)*c,g=Math.sin(m)*c,B=zo(e);return w(v("line"),{stroke:s?B.color:o.color,"stroke-width":Ir(o,t)*(s?1.14:1),"stroke-linecap":"round","marker-end":`url(#arrowhead-${s?B.key:o.key})`,opacity:e.modifiers?.hilite?1:$o(o,t),x1:r[0],y1:r[1],x2:n[0]-y,y2:n[1]-g})}if(!e.modifiers?.hilite)return a(!1);let l=w(v("g"),{opacity:o.opacity}),d=w(v("g"),{filter:"url(#cg-filter-blur)"});return d.appendChild(Ur(r,n)),d.appendChild(a(!0)),l.appendChild(d),l.appendChild(a(!1)),l}function Wr(e){let o=w(v("marker"),{id:"arrowhead-"+e.key,orient:"auto",overflow:"visible",markerWidth:4,markerHeight:4,refX:e.key.startsWith("hilite")?1.86:2.05,refY:2});return o.appendChild(w(v("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),o.setAttribute("cgKey",e.key),o}function zr(e,o,r,n,t,i){let l=.4*.75**e.text.length,d=Io(r,n,t),s=i==="tr"?.4:0,c=w(v("g"),{transform:`translate(${d[0]+s},${d[1]-s})`,cgHash:o});c.appendChild(w(v("circle"),{r:.4/2,"fill-opacity":i?1:.8,"stroke-opacity":i?1:.7,"stroke-width":.03,fill:e.fill??"#666",stroke:"white"}));let u=w(v("text"),{"font-size":l,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return u.innerHTML=e.text,c.appendChild(u),c}function Se(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function je(e,o){return(e&&o.has(e)&&o.get(e).size>1)===!0}function v(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function w(e,o){for(let r in o)Object.prototype.hasOwnProperty.call(o,r)&&e.setAttribute(r,o[r]);return e}function Wo(e,o){return o?{color:e.color,opacity:Math.round(e.opacity*10)/10,lineWidth:Math.round(o.lineWidth||e.lineWidth),key:[e.key,o.lineWidth].filter(r=>r).join("")}:e}function $r(){return[3/64,4/64]}function Ir(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function zo(e){let o=e.modifiers?.hilite;return{key:o&&`hilite-${o.replace("#","")}`,color:o}}function $o(e,o){return(e.opacity||1)*(o?.9:1)}function jr(e){return(e?20:10)/64}function Me(e,o){let r=Math.min(1,o.width/o.height),n=Math.min(1,o.height/o.width);return[(e[0]-3.5)*r,(3.5-e[1])*n]}function Ur(e,o){let r={from:[Math.floor(Math.min(e[0],o[0])),Math.floor(Math.min(e[1],o[1]))],to:[Math.ceil(Math.max(e[0],o[0])),Math.ceil(Math.max(e[1],o[1]))]};return w(v("rect"),{x:r.from[0],y:r.from[1],width:r.to[0]-r.from[0],height:r.to[1]-r.from[1],fill:"none",stroke:"none"})}function Ue(e,o,r=!0){let n=Math.atan2(o[1]-e[1],o[0]-e[0])+Math.PI;return r?(Math.round(n*8/Math.PI)+16)%16:n}function Zr(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((r,n)=>r+n*n,0))}function Io(e,o,r){let n=Zr(e,o),t=Ue(e,o,!1);if(r&&(n-=33/64,r.size>1)){n-=10/64;let i=Ue(e,o);(r.has((i+1)%16)||r.has((i+15)%16))&&i&1&&(n-=.4)}return[e[0]-Math.cos(t)*n,e[1]-Math.sin(t)*n].map(i=>i+.5)}function Uo(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let c of Ye)e.classList.toggle("orientation-"+c,o.orientation===c);e.classList.toggle("manipulable",!o.viewOnly);let r=k("cg-container");e.appendChild(r);let n=k("cg-board");r.appendChild(n);let t,i,a,l,d;if(o.drawable.visible&&([t,i]=["cg-shapes-below","cg-shapes"].map(c=>jo(c,!0)),[a,l]=["cg-custom-below","cg-custom-svgs"].map(c=>jo(c,!1)),d=k("cg-auto-pieces"),r.appendChild(t),r.appendChild(a),r.appendChild(i),r.appendChild(l),r.appendChild(d)),o.coordinates){let c=o.orientation==="black"?" black":"",u=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let p=o.orientation==="white"?m=>m+1:m=>8-m;W.forEach((m,y)=>r.appendChild(Ze(j.map(g=>m+g),"squares rank"+p(y)+c+u)))}else r.appendChild(Ze(j,"ranks"+c+u)),r.appendChild(Ze(W,"files"+c))}let s;return o.draggable.enabled&&o.draggable.showGhost&&(s=k("piece","ghost"),Y(s,!1),r.appendChild(s)),{board:n,container:r,wrap:e,ghost:s,shapes:i,shapesBelow:t,custom:l,customBelow:a,autoPieces:d}}function jo(e,o){let r=w(v("svg"),{class:e,viewBox:o?"-4 -4 8 8":"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"});return o&&r.appendChild(Fo()),r.appendChild(v("g")),r}function Ze(e,o){let r=k("coords",o),n;for(let t of e)n=k("coord"),n.textContent=t,r.appendChild(n);return r}function Zo(e,o){if(!e.dropmode.active)return;E(e),A(e);let r=e.dropmode.piece;if(r){e.pieces.set("a0",r);let n=x(o),t=n&&N(n,h(e),e.dom.bounds());t&&ye(e,"a0",t)}e.dom.redraw()}function Xo(e,o){let r=e.dom.elements.board;if("ResizeObserver"in window&&new ResizeObserver(o).observe(e.dom.elements.wrap),(e.disableContextMenu||e.drawable.enabled)&&r.addEventListener("contextmenu",t=>t.preventDefault()),e.viewOnly)return;let n=Xr(e);r.addEventListener("touchstart",n,{passive:!1}),r.addEventListener("mousedown",n,{passive:!1})}function Qo(e,o){let r=[];if("ResizeObserver"in window||r.push(ie(document.body,"chessground.resize",o)),!e.viewOnly){let n=_o(e,Ao,Co),t=_o(e,No,ko);for(let a of["touchmove","mousemove"])r.push(ie(document,a,n));for(let a of["touchend","mouseup"])r.push(ie(document,a,t));let i=()=>e.dom.bounds.clear();r.push(ie(document,"scroll",i,{capture:!0,passive:!0})),r.push(ie(window,"resize",i,{passive:!0}))}return()=>r.forEach(n=>n())}function ie(e,o,r,n){return e.addEventListener(o,r,n),()=>e.removeEventListener(o,r,n)}var Xr=e=>o=>{e.draggable.current?$(e):e.drawable.current?$e(e):o.shiftKey||de(o)?e.drawable.enabled&&So(e,o):e.viewOnly||(e.dropmode.active?Zo(e,o):xo(e,o))},_o=(e,o,r)=>n=>{e.drawable.current?e.drawable.enabled&&r(e,n):e.viewOnly||o(e,n)};function Jo(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.board,t=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,l=i?i.plan.fadings:new Map,d=e.draggable.current,s=Yr(e),c=new Set,u=new Set,p=new Map,m=new Map,y,g,B,I,D,_,Ce,H,ke,se;for(g=n.firstChild;g;){if(y=g.cgKey,or(g))if(B=t.get(y),D=a.get(y),_=l.get(y),I=g.cgPiece,g.cgDragging&&(!d||d.orig!==y)&&(g.classList.remove("dragging"),C(g,r(f(y),o)),g.cgDragging=!1),!_&&g.cgFading&&(g.cgFading=!1,g.classList.remove("fading")),B){if(D&&g.cgAnimating&&I===ae(B)){let b=f(y);b[0]+=D[2],b[1]+=D[3],g.classList.add("anim"),C(g,r(b,o))}else g.cgAnimating&&(g.cgAnimating=!1,g.classList.remove("anim"),C(g,r(f(y),o)),e.addPieceZIndex&&(g.style.zIndex=_e(f(y),o)));I===ae(B)&&(!_||!g.cgFading)?c.add(y):_&&I===ae(_)?(g.classList.add("fading"),g.cgFading=!0):Xe(p,I,g)}else Xe(p,I,g);else if(rr(g)){let b=g.className;s.get(y)===b?u.add(y):Xe(m,b,g)}g=g.nextSibling}for(let[b,X]of s)if(!u.has(b)){ke=m.get(X),se=ke&&ke.pop();let q=r(f(b),o);if(se)se.cgKey=b,C(se,q);else{let T=k("square",X);T.cgKey=b,C(T,q),n.insertBefore(T,n.firstChild)}}for(let[b,X]of t)if(D=a.get(b),!c.has(b))if(Ce=p.get(ae(X)),H=Ce&&Ce.pop(),H){H.cgKey=b,H.cgFading&&(H.classList.remove("fading"),H.cgFading=!1);let q=f(b);e.addPieceZIndex&&(H.style.zIndex=_e(q,o)),D&&(H.cgAnimating=!0,H.classList.add("anim"),q[0]+=D[2],q[1]+=D[3]),C(H,r(q,o))}else{let q=ae(X),T=k("piece",q),ce=f(b);T.cgPiece=q,T.cgKey=b,D&&(T.cgAnimating=!0,ce[0]+=D[2],ce[1]+=D[3]),C(T,r(ce,o)),e.addPieceZIndex&&(T.style.zIndex=_e(ce,o)),n.appendChild(T)}for(let b of p.values())Yo(e,b);for(let b of m.values())Yo(e,b)}function er(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.board.firstChild;for(;n;)(or(n)&&!n.cgAnimating||rr(n))&&C(n,r(f(n.cgKey),o)),n=n.nextSibling}function Qe(e){let o=e.dom.elements.wrap.getBoundingClientRect(),r=e.dom.elements.container,n=o.height/o.width,t=Math.floor(o.width*window.devicePixelRatio/8)*8/window.devicePixelRatio,i=t*n;r.style.width=t+"px",r.style.height=i+"px",e.dom.bounds.clear(),e.addDimensionsCssVarsTo?.style.setProperty("---cg-width",t+"px"),e.addDimensionsCssVarsTo?.style.setProperty("---cg-height",i+"px")}var or=e=>e.tagName==="PIECE",rr=e=>e.tagName==="SQUARE";function Yo(e,o){for(let r of o)e.dom.elements.board.removeChild(r)}function _e(e,o){let n=e[1];return`${o?10-n:3+n}`}var ae=e=>`${e.color} ${e.role}`;function Yr(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let t of e.lastMove)V(o,t,"last-move");if(e.check&&e.highlight.check&&V(o,e.check,"check"),e.selected&&(V(o,e.selected,"selected"),e.movable.showDests)){let t=e.movable.dests?.get(e.selected);if(t)for(let a of t)V(o,a,"move-dest"+(e.pieces.has(a)?" oc":""));let i=e.premovable.customDests?.get(e.selected)??e.premovable.dests;if(i)for(let a of i)V(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let r=e.premovable.current;if(r)for(let t of r)V(o,t,"current-premove");else e.predroppable.current&&V(o,e.predroppable.current.key,"current-premove");let n=e.exploding;if(n)for(let t of n.keys)V(o,t,"exploding"+n.stage);return e.highlight.custom&&e.highlight.custom.forEach((t,i)=>{V(o,i,t)}),o}function V(e,o,r){let n=e.get(o);n?e.set(o,`${n} ${r}`):e.set(o,r)}function Xe(e,o,r){let n=e.get(o);n?n.push(r):e.set(o,[r])}function nr(e,o,r){let n=new Map,t=[];for(let l of e)n.set(l.hash,!1);let i=o.firstElementChild,a;for(;i;)a=i.getAttribute("cgHash"),n.has(a)?n.set(a,!0):t.push(i),i=i.nextElementSibling;for(let l of t)o.removeChild(l);for(let l of e)n.get(l.hash)||o.appendChild(r(l))}function tr(e,o){let n=e.drawable.autoShapes.filter(t=>t.piece).map(t=>({shape:t,hash:en(t),current:!1}));nr(n,o,t=>Jr(e,t,e.dom.bounds()))}function ir(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.autoPieces?.firstChild;for(;n;)Ke(n,r(f(n.cgKey),o),n.cgScale),n=n.nextSibling}function Jr(e,{shape:o,hash:r},n){let t=o.orig,i=o.piece?.role,a=o.piece?.color,l=o.piece?.scale,d=k("piece",`${i} ${a}`);return d.setAttribute("cgHash",r),d.cgKey=t,d.cgScale=l,Ke(d,G(n)(f(t),h(e)),l),d}var en=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function ot({el:e,config:o}){return rn(e,o)}function rn(e,o){let r=Ro();Pe(r,o||{});function n(){let t="dom"in r?r.dom.unbind:void 0,i=Uo(e,r),a=ro(()=>i.board.getBoundingClientRect()),l=c=>{Jo(s),i.autoPieces&&tr(s,i.autoPieces),!c&&i.shapes&&Go(s,i)},d=()=>{Qe(s),er(s),i.autoPieces&&ir(s)},s=r;return s.dom={elements:i,bounds:a,redraw:nn(l),redrawNow:l,unbind:t},s.drawable.prevSvgHash="",Qe(s),l(!1),Xo(s,d),t||(s.dom.unbind=Qo(s,d)),s.events.insert&&s.events.insert(i),s}return Oo(n(),n)}function nn(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{rn as Chessground,ot as initModule};
1
+ var Qe=["white","black"];var W=["a","b","c","d","e","f","g","h"],j=["1","2","3","4","5","6","7","8"];var Je=[...j].reverse(),Q=W.flatMap(e=>j.map(o=>e+o)),M=e=>e.every(o=>o>=0&&o<=7)?Q[8*e[0]+e[1]]:void 0,L=e=>M(e),f=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var Ce=Q.map(f),eo=Q.map((e,o)=>({key:e,pos:Ce[o]}));function oo(e){let o,r=()=>(o===void 0&&(o=e()),o);return r.clear=()=>{o=void 0},r}var ro=()=>{let e;return{start(){e=performance.now()},cancel(){e=void 0},stop(){if(!e)return 0;let o=performance.now()-e;return e=void 0,o}}},U=e=>e==="white"?"black":"white",F=(e,o)=>(e[0]-o[0])**2+(e[1]-o[1])**2,z=(e,o)=>e.role===o.role&&e.color===o.color,no=(e,o)=>e[0]===o[0]&&e[1]===o[1],G=e=>(o,r)=>[(r?o[0]:7-o[0])*e.width/8,(r?7-o[1]:o[1])*e.height/8],k=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},De=(e,o,r=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${r})`},Y=(e,o)=>{e.style.visibility=o?"visible":"hidden"},T=e=>{if(e.clientX||e.clientX===0)return[e.clientX,e.clientY];if(e.targetTouches?.[0])return[e.targetTouches[0].clientX,e.targetTouches[0].clientY]},le=e=>e.button===2,C=(e,o)=>{let r=document.createElement(e);return o&&(r.className=o),r};function de(e,o,r){let n=f(e);return o||(n[0]=7-n[0],n[1]=7-n[1]),[r.left+r.width*n[0]/8+r.width/16,r.top+r.height*(7-n[1])/8+r.height/16]}var K=(e,o)=>Math.abs(e-o),J=(e,o,r,n)=>K(e,r)*K(o,n)===2,ue=(e,o,r,n)=>e===r!=(o===n),pe=(e,o,r,n)=>K(e,r)===K(o,n)&&e!==r,fe=(e,o,r,n)=>ue(e,o,r,n)||pe(e,o,r,n),Ke=(e,o,r,n)=>Math.max(K(e,r),K(o,n))===1,xe=(e,o,r,n,t)=>K(e,r)===1&&n===o+(t?1:-1),Ee=(e,o,r,n,t)=>{let i=t?1:-1;return e===r&&(n===o+i||n===o+2*i&&(t?o<=1:o>=6))},ee=(e,o,r,n)=>{let t=r-e,i=n-o;if(t&&i&&Math.abs(t)!==Math.abs(i))return[];let a=Math.sign(t),l=Math.sign(i),d=[],s=e+a,c=o+l;for(;s!==r||c!==n;)d.push([s,c]),s+=a,c+=l;return d.map(M).filter(u=>u!==void 0)},to=e=>{let o=f(e),r=[];return o[0]>0&&r.push([o[0]-1,o[1]]),o[0]<7&&r.push([o[0]+1,o[1]]),r.map(M).filter(n=>n!==void 0)},oe=(e,o)=>{let r=f(e);return r[1]+=o,M(r)};var Z=e=>e.friendlies.has(e.dest.key),ar=e=>e.enemies.has(e.dest.key),io=(e,o,r)=>ee(...e,...o).some(n=>r.has(n)),ao=(e,o,r)=>{let n=r.enemies.get(e);if(n?.role!=="pawn")return!1;let t=n.color==="white"?1:-1,i=f(e),a=f(o);return Ee(...i,...a,n.color==="white")&&!io(i,[a[0],a[1]+t],r.allPieces)},sr=(e,o,r)=>{let n=r.enemies.get(e);return n?.role==="pawn"&&xe(...f(e),...f(o),n.color==="white")&&(r.friendlies.has(o)||me(oe(o,n.color==="white"?-1:1),r.friendlies,r.enemies,r.lastMove))},cr=e=>[...e.enemies.keys()].some(o=>ao(o,e.dest.key,e)),Ae=(e,o)=>{let r=e.dest.pos;return[...e.enemies].some(([n,t])=>{let i=f(n);return!o?.includes(t.role)&&(t.role==="pawn"&&xe(...i,...r,t.color==="white")||t.role==="knight"&&J(...i,...r)||t.role==="bishop"&&pe(...i,...r)||t.role==="rook"&&ue(...i,...r)||t.role==="queen"&&fe(...i,...r)||t.role==="king"&&Ke(...i,...r))&&(!["bishop","rook","queen"].includes(t.role)||!io(i,r,e.allPieces))})},ge=e=>Z(e)&&(me(e.dest.key,e.friendlies,e.enemies,e.lastMove)||Ae(e)),me=(e,o,r,n)=>{if(!e||n&&e!==n[1])return!1;let t=f(e),i=o.get(e);return i?.role==="pawn"&&t[1]===(i.color==="white"?3:4)&&(!n||K(f(n[0])[1],t[1])===2)&&[1,-1].some(a=>{let l=M([t[0]+a,t[1]]);return!!l&&r.get(l)?.role==="pawn"})},lr=(e,o)=>{if(e.unrestrictedPremoves)return!0;let r=ee(...e.orig.pos,...e.dest.pos);o&&r.push(e.dest.key);let n=r.filter(a=>e.friendlies.has(a));if(!n.length)return!0;let t=n[0],i=oe(t,e.color==="white"?-1:1);return n.length===1&&me(t,e.friendlies,e.enemies,e.lastMove)&&!!i&&!r.includes(i)},dr=(e,o)=>{if(e.unrestrictedPremoves)return!0;let r=ee(...e.orig.pos,...e.dest.pos);o&&r.push(e.dest.key);let n=r.filter(c=>e.enemies.has(c));if(n.length>1)return!1;if(!n.length)return!0;let t=n[0],i=e.enemies.get(t);if(!i||i.role!=="pawn")return!0;let a=i.color==="white"?1:-1,l=oe(t,a),d=l?[...to(l).filter(c=>sr(t,c,e)),...[l,oe(l,a)].filter(c=>!!c).filter(c=>ao(t,c,e))]:[],s=[...r,e.orig.key];return d.some(c=>!s.includes(c))},Ne=(e,o)=>lr(e,o)&&dr(e,o),ur=e=>{let o=e.color==="white"?1:-1;return K(e.orig.pos[0],e.dest.pos[0])>1?!1:K(e.orig.pos[0],e.dest.pos[0])?e.dest.pos[1]!==e.orig.pos[1]+o?!1:e.unrestrictedPremoves||ar(e)?!0:Z(e)?Ae(e):cr(e)||me(M([e.dest.pos[0],e.dest.pos[1]+o]),e.friendlies,e.enemies,e.lastMove)||Ae(e,["pawn"]):Ee(...e.orig.pos,...e.dest.pos,e.color==="white")&&Ne(e,!0)},pr=e=>J(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),so=e=>pe(...e.orig.pos,...e.dest.pos)&&Ne(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),co=e=>ue(...e.orig.pos,...e.dest.pos)&&Ne(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),fr=e=>so(e)||co(e),gr=e=>Ke(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||ge(e))||e.canCastle&&e.orig.pos[1]===e.dest.pos[1]&&e.orig.pos[1]===(e.color==="white"?0:7)&&(e.orig.pos[0]===4&&(e.dest.pos[0]===2&&e.rookFilesFriendlies.includes(0)||e.dest.pos[0]===6&&e.rookFilesFriendlies.includes(7))||e.rookFilesFriendlies.includes(e.dest.pos[0]))&&(e.unrestrictedPremoves||ee(...e.orig.pos,e.dest.pos[0]>e.orig.pos[0]?7:1,e.dest.pos[1]).map(o=>e.allPieces.get(o)).every(o=>!o||z(o,{role:"rook",color:e.color}))),mr={pawn:ur,knight:pr,bishop:so,rook:co,queen:fr,king:gr};function He(e,o){let r=e.pieces,n=e.premovable.castle,t=!!e.premovable.unrestrictedPremoves,i=r.get(o);if(!i||i.color===e.turnColor)return[];let a=i.color,l=new Map([...r].filter(([p,m])=>m.color===a)),d=new Map([...r].filter(([p,m])=>m.color===U(a))),s={key:o,pos:f(o)},c=p=>mr[i.role](p)&&e.premovable.additionalPremoveRequirements(p),u={orig:s,role:i.role,allPieces:r,friendlies:l,enemies:d,unrestrictedPremoves:t,color:a,canCastle:n,rookFilesFriendlies:Array.from(r).filter(([p,m])=>p[1]===(a==="white"?"1":"8")&&m.color===a&&m.role==="rook").map(([p])=>f(p)[0]),lastMove:e.lastMove};return eo.filter(p=>c({...u,dest:p})).map(p=>p.key)}function S(e,...o){e&&setTimeout(()=>e(...o),1)}function lo(e){e.orientation=U(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function uo(e,o){for(let[r,n]of o)n?e.pieces.set(r,n):e.pieces.delete(r)}function po(e,o){if(e.check=void 0,o===!0&&(o=e.turnColor),o)for(let[r,n]of e.pieces)n.role==="king"&&n.color===o&&(e.check=r)}function br(e,o,r,n){E(e),e.premovable.current=[o,r],S(e.premovable.events.set,o,r,n)}function x(e){e.premovable.current&&(e.premovable.current=void 0,S(e.premovable.events.unset))}function hr(e,o,r){x(e),e.predroppable.current={role:o,key:r},S(e.predroppable.events.set,o,r)}function E(e){let o=e.predroppable;o.current&&(o.current=void 0,S(o.events.unset))}function vr(e,o,r){if(!e.autoCastle)return!1;let n=e.pieces.get(o);if(!n||n.role!=="king")return!1;let t=f(o),i=f(r);if(t[1]!==0&&t[1]!==7||t[1]!==i[1])return!1;t[0]===4&&!e.pieces.has(r)&&(i[0]===6?r=L([7,i[1]]):i[0]===2&&(r=L([0,i[1]])));let a=e.pieces.get(r);return!a||a.color!==n.color||a.role!=="rook"?!1:(e.pieces.delete(o),e.pieces.delete(r),t[0]<i[0]?(e.pieces.set(L([6,i[1]]),n),e.pieces.set(L([5,i[1]]),a)):(e.pieces.set(L([2,i[1]]),n),e.pieces.set(L([3,i[1]]),a)),!0)}function qe(e,o,r){let n=e.pieces.get(o),t=e.pieces.get(r);if(o===r||!n)return!1;let i=t&&t.color!==n.color?t:void 0;return r===e.selected&&P(e),S(e.events.move,o,r,i),vr(e,o,r)||(e.pieces.set(r,n),e.pieces.delete(o)),e.lastMove=[o,r],e.check=void 0,S(e.events.change),i||!0}function be(e,o,r,n){if(e.pieces.has(r))if(n)e.pieces.delete(r);else return!1;return S(e.events.dropNewPiece,o,r),e.pieces.set(r,o),e.lastMove=[r],e.check=void 0,S(e.events.change),e.movable.dests=void 0,e.turnColor=U(e.turnColor),!0}function fo(e,o,r){let n=qe(e,o,r);return n&&(e.movable.dests=void 0,e.turnColor=U(e.turnColor),e.animation.current=void 0),n}function Te(e,o,r){if(ve(e,o,r)){let n=fo(e,o,r);if(n){let t=e.hold.stop();P(e);let i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:t};return n!==!0&&(i.captured=n),S(e.movable.events.after,o,r,i),!0}}else if(wr(e,o,r))return br(e,o,r,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function he(e,o,r,n){let t=e.pieces.get(o);t&&(yr(e,o,r)||n)?(e.pieces.delete(o),be(e,t,r,n),S(e.movable.events.afterNewPiece,t.role,r,{premove:!1,predrop:!1})):t&&Pr(e,o,r)?hr(e,t.role,r):(x(e),E(e)),e.pieces.delete(o),P(e)}function ne(e,o,r){if(S(e.events.select,o),e.selected){if(e.selected===o&&!e.draggable.enabled){P(e),e.hold.cancel();return}else if((e.selectable.enabled||r)&&e.selected!==o&&Te(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(go(e,o)||Re(e,o))&&(Be(e,o),e.hold.start())}function Be(e,o){e.selected=o,Re(e,o)?e.premovable.customDests||(e.premovable.dests=He(e,o)):e.premovable.dests=void 0}function P(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function go(e,o){let r=e.pieces.get(o);return!!r&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}var ve=(e,o,r)=>o!==r&&go(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(r));function yr(e,o,r){let n=e.pieces.get(o);return!!n&&(o===r||!e.pieces.has(r))&&(e.movable.color==="both"||e.movable.color===n.color&&e.turnColor===n.color)}function Re(e,o){let r=e.pieces.get(o);return!!r&&e.premovable.enabled&&e.movable.color===r.color&&e.turnColor!==r.color}var wr=(e,o,r)=>o!==r&&Re(e,o)&&(e.premovable.customDests?.get(o)??He(e,o)).includes(r);function Pr(e,o,r){let n=e.pieces.get(o),t=e.pieces.get(r);return!!n&&(!t||t.color!==e.movable.color)&&e.predroppable.enabled&&(n.role!=="pawn"||r[1]!=="1"&&r[1]!=="8")&&e.movable.color===n.color&&e.turnColor!==n.color}function mo(e,o){let r=e.pieces.get(o);return!!r&&e.draggable.enabled&&(e.movable.color==="both"||e.movable.color===r.color&&(e.turnColor===r.color||e.premovable.enabled))}function bo(e){let o=e.premovable.current;if(!o)return!1;let r=o[0],n=o[1],t=!1;if(ve(e,r,n)){let i=fo(e,r,n);if(i){let a={premove:!0};i!==!0&&(a.captured=i),S(e.movable.events.after,r,n,a),t=!0}}return x(e),t}function ho(e,o){let r=e.predroppable.current,n=!1;if(!r)return!1;if(o(r)){let t={role:r.role,color:e.movable.color};be(e,t,r.key)&&(S(e.movable.events.afterNewPiece,r.role,r.key,{premove:!1,predrop:!0}),n=!0)}return E(e),n}function te(e){x(e),E(e),P(e)}function Oe(e){e.movable.color=e.movable.dests=e.animation.current=void 0,te(e)}function A(e,o,r){let n=Math.floor(8*(e[0]-r.left)/r.width);o||(n=7-n);let t=7-Math.floor(8*(e[1]-r.top)/r.height);return o||(t=7-t),n>=0&&n<8&&t>=0&&t<8?M([n,t]):void 0}function vo(e,o,r,n){let t=f(e),i=Ce.filter(s=>no(t,s)||fe(t[0],t[1],s[0],s[1])||J(t[0],t[1],s[0],s[1])),l=i.map(s=>de(L(s),r,n)).map(s=>F(o,s)),[,d]=l.reduce((s,c,u)=>s[0]<c?s:[c,u],[l[0],0]);return M(i[d])}var h=e=>e.orientation==="white";var Le="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",Sr={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},Mr={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function ye(e){e==="start"&&(e=Le);let o=new Map,r=7,n=0;for(let t of e)switch(t){case" ":case"[":return o;case"/":if(--r,r<0)return o;n=0;break;case"~":{let i=M([n-1,r]),a=i&&o.get(i);a&&(a.promoted=!0);break}default:{let i=t.charCodeAt(0);if(i<57)n+=i-48;else{let a=t.toLowerCase(),l=M([n,r]);l&&o.set(l,{role:Sr[a],color:t===a?"black":"white"}),++n}}}return o}function yo(e){return Je.map(o=>W.map(r=>{let n=e.get(r+o);if(n){let t=Mr[n.role];return n.color==="white"&&(t=t.toUpperCase()),n.promoted&&(t+="~"),t}else return"1"}).join("")).join("/").replace(/1{2,}/g,o=>o.length.toString())}function Fe(e,o){o.animation&&(Ge(e.animation,o.animation),(e.animation.duration||0)<70&&(e.animation.enabled=!1))}function we(e,o){if(o.movable?.dests&&(e.movable.dests=void 0),o.drawable?.autoShapes&&(e.drawable.autoShapes=[]),Ge(e,o),o.fen&&(e.pieces=ye(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&po(e,o.check||!1),"lastMove"in o&&!o.lastMove?e.lastMove=void 0:o.lastMove&&(e.lastMove=o.lastMove),e.selected&&Be(e,e.selected),Fe(e,o),!e.movable.rookCastle&&e.movable.dests){let r=e.movable.color==="white"?"1":"8",n="e"+r,t=e.movable.dests.get(n),i=e.pieces.get(n);if(!t||!i||i.role!=="king")return;e.movable.dests.set(n,t.filter(a=>!(a==="a"+r&&t.includes("c"+r))&&!(a==="h"+r&&t.includes("g"+r))))}}function Ge(e,o){for(let r in o)r==="__proto__"||r==="constructor"||!Object.prototype.hasOwnProperty.call(o,r)||(Object.prototype.hasOwnProperty.call(e,r)&&wo(e[r])&&wo(o[r])?Ge(e[r],o[r]):e[r]=o[r])}function wo(e){if(typeof e!="object"||e===null)return!1;let o=Object.getPrototypeOf(e);return o===Object.prototype||o===null}var R=(e,o)=>o.animation.enabled?Kr(e,o):O(e,o);function O(e,o){let r=e(o);return o.dom.redraw(),r}var We=(e,o)=>({key:e,pos:f(e),piece:o}),Cr=(e,o)=>o.sort((r,n)=>F(e.pos,r.pos)-F(e.pos,n.pos))[0];function Dr(e,o){let r=new Map,n=[],t=new Map,i=[],a=[],l=new Map,d,s,c;for(let[u,p]of e)l.set(u,We(u,p));for(let u of Q)d=o.pieces.get(u),s=l.get(u),d?s?z(d,s.piece)||(i.push(s),a.push(We(u,d))):a.push(We(u,d)):s&&i.push(s);for(let u of a)s=Cr(u,i.filter(p=>z(u.piece,p.piece))),s&&(c=[s.pos[0]-u.pos[0],s.pos[1]-u.pos[1]],r.set(u.key,c.concat(c)),n.push(s.key));for(let u of i)n.includes(u.key)||t.set(u.key,u.piece);return{anims:r,fadings:t}}function Po(e,o){let r=e.animation.current;if(r===void 0){e.dom.destroyed||e.dom.redrawNow();return}let n=1-(o-r.start)*r.frequency;if(n<=0)e.animation.current=void 0,e.dom.redrawNow();else{let t=xr(n);for(let i of r.plan.anims.values())i[2]=i[0]*t,i[3]=i[1]*t;e.dom.redrawNow(!0),requestAnimationFrame((i=performance.now())=>Po(e,i))}}function Kr(e,o){let r=new Map(o.pieces),n=e(o),t=Dr(r,o);if(t.anims.size||t.fadings.size){let i=o.animation.current&&o.animation.current.start;o.animation.current={start:performance.now(),frequency:1/o.animation.duration,plan:t},i||Po(o,performance.now())}else o.dom.redraw();return n}var xr=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var Er=["green","red","blue","yellow"];function So(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):te(e);let r=T(o),n=A(r,h(e),e.dom.bounds());n&&(e.drawable.current={orig:n,pos:r,brush:Ar(o),snapToValidMove:e.drawable.defaultSnapToValidMove},Mo(e))}function Mo(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let r=A(o.pos,h(e),e.dom.bounds());r||(o.snapToValidMove=!1);let n=o.snapToValidMove?vo(o.orig,o.pos,h(e),e.dom.bounds()):r;n!==o.mouseSq&&(o.mouseSq=n,o.dest=n!==o.orig?n:void 0,e.dom.redrawNow()),Mo(e)}})}function ko(e,o){e.drawable.current&&(e.drawable.current.pos=T(o))}function Co(e){let o=e.drawable.current;o&&(o.mouseSq&&Nr(e.drawable,o),ze(e))}function ze(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function Do(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),Ko(e.drawable))}function Ar(e){let o=(e.shiftKey||e.ctrlKey)&&le(e),r=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return Er[(o?1:0)+(r?2:0)]}function Nr(e,o){let r=t=>t.orig===o.orig&&t.dest===o.dest,n=e.shapes.find(r);n&&(e.shapes=e.shapes.filter(t=>!r(t))),(!n||n.brush!==o.brush)&&e.shapes.push({orig:o.orig,dest:o.dest,brush:o.brush}),Ko(e)}function Ko(e){e.onChange&&e.onChange(e.shapes)}function xo(e,o){if(!(e.trustAllEvents||o.isTrusted)||o.buttons!==void 0&&o.buttons>1||o.touches&&o.touches.length>1)return;let r=e.dom.bounds(),n=T(o),t=A(n,h(e),r);if(!t)return;let i=e.pieces.get(t),a=e.selected;if(!a&&e.drawable.enabled&&(e.drawable.eraseOnMovablePieceClick||!i||i.color!==e.turnColor)&&Do(e),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||qr(e,n)))o.preventDefault();else if(o.touches)return;let l=!!e.premovable.current,d=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&ve(e,e.selected,t)?R(u=>ne(u,t),e):ne(e,t);let s=e.selected===t,c=qo(e,t);if(i&&c&&s&&mo(e,t)){e.draggable.current={orig:t,piece:i,origPos:n,pos:n,started:e.draggable.autoDistance&&e.stats.dragged,element:c,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},c.cgDragging=!0,c.classList.add("dragging");let u=e.dom.elements.ghost;u&&(u.className=`ghost ${i.color} ${i.role}`,k(u,G(r)(f(t),h(e))),Y(u,!0)),$e(e)}else l&&x(e),d&&E(e);e.dom.redraw()}function qr(e,o){let r=h(e),n=e.dom.bounds(),t=Math.pow(e.touchIgnoreRadius*n.width/16,2)*2;for(let i of e.pieces.keys()){let a=de(i,r,n);if(F(a,o)<=t)return!0}return!1}function Eo(e,o,r,n){let t="a0";e.pieces.set(t,o),e.dom.redraw();let i=T(r);e.draggable.current={orig:t,piece:o,origPos:i,pos:i,started:!0,element:()=>qo(e,t),originTarget:r.target,newPiece:!0,force:!!n,keyHasChanged:!1},$e(e)}function $e(e){requestAnimationFrame(()=>{let o=e.draggable.current;if(!o)return;e.animation.current?.plan.anims.has(o.orig)&&(e.animation.current=void 0);let r=e.pieces.get(o.orig);if(!r||!z(r,o.piece))$(e);else if(!o.started&&F(o.pos,o.origPos)>=Math.pow(e.draggable.distance,2)&&(o.started=!0),o.started){if(typeof o.element=="function"){let t=o.element();if(!t)return;t.cgDragging=!0,t.classList.add("dragging"),o.element=t}let n=e.dom.bounds();k(o.element,[o.pos[0]-n.left-n.width/16,o.pos[1]-n.top-n.height/16]),o.keyHasChanged||=o.orig!==A(o.pos,h(e),n)}$e(e)})}function Ao(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=T(o))}function No(e,o){let r=e.draggable.current;if(!r)return;if(o.type==="touchend"&&o.cancelable!==!1&&o.preventDefault(),o.type==="touchend"&&r.originTarget!==o.target&&!r.newPiece){e.draggable.current=void 0;return}x(e),E(e);let n=T(o)||r.pos,t=A(n,h(e),e.dom.bounds());t&&r.started&&r.orig!==t?r.newPiece?he(e,r.orig,t,r.force):(e.stats.ctrlKey=o.ctrlKey,Te(e,r.orig,t)&&(e.stats.dragged=!0)):r.newPiece?e.pieces.delete(r.orig):e.draggable.deleteOnDropOff&&!t&&(e.pieces.delete(r.orig),S(e.events.change)),(r.orig===r.previouslySelected||r.keyHasChanged)&&(r.orig===t||!t)?P(e):e.selectable.enabled||P(e),Ho(e),e.draggable.current=void 0,e.dom.redraw()}function $(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),Ho(e),e.dom.redraw())}function Ho(e){let o=e.dom.elements;o.ghost&&Y(o.ghost,!1)}function qo(e,o){let r=e.dom.elements.board.firstChild;for(;r;){if(r.cgKey===o&&r.tagName==="PIECE")return r;r=r.nextSibling}}function Bo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{To(e,2),setTimeout(()=>To(e,void 0),120)},120)}function To(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function Ro(e,o){function r(){lo(e),o()}return{set(n){n.orientation&&n.orientation!==e.orientation&&r(),Fe(e,n),(n.fen?R:O)(t=>we(t,n),e)},state:e,getFen:()=>yo(e.pieces),toggleOrientation:r,setPieces(n){R(t=>uo(t,n),e)},selectSquare(n,t){n?R(i=>ne(i,n,t),e):e.selected&&(P(e),e.dom.redraw())},move(n,t){R(i=>qe(i,n,t),e)},newPiece(n,t){R(i=>be(i,n,t),e)},playPremove(){if(e.premovable.current){if(R(bo,e))return!0;e.dom.redraw()}return!1},playPredrop(n){if(e.predroppable.current){let t=ho(e,n);return e.dom.redraw(),t}return!1},cancelPremove(){O(x,e)},cancelPredrop(){O(E,e)},cancelMove(){O(n=>{te(n),$(n)},e)},stop(){O(n=>{Oe(n),$(n)},e)},explode(n){Bo(e,n)},setAutoShapes(n){O(t=>t.drawable.autoShapes=n,e)},setShapes(n){O(t=>t.drawable.shapes=n.slice(),e)},getKeyAtDomPos(n){return A(n,h(e),e.dom.bounds())},redrawAll:o,dragNewPiece(n,t,i){Eo(e,n,t,i)},destroy(){Oe(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function Oo(){return{pieces:ye(Le),orientation:"white",turnColor:"white",coordinates:!0,coordinatesOnSquares:!1,ranksPosition:"right",autoCastle:!0,viewOnly:!1,disableContextMenu:!1,addPieceZIndex:!1,blockTouchScroll:!1,touchIgnoreRadius:1,pieceKey:!1,trustAllEvents:!1,highlight:{lastMove:!0,check:!0},animation:{enabled:!0,duration:200},movable:{free:!0,color:"both",showDests:!0,events:{},rookCastle:!0},premovable:{enabled:!0,showDests:!0,castle:!0,additionalPremoveRequirements:e=>!0,events:{}},predroppable:{enabled:!1,events:{}},draggable:{enabled:!0,distance:3,autoDistance:!0,showGhost:!0,deleteOnDropOff:!1},dropmode:{active:!1},selectable:{enabled:!0},stats:{dragged:!("ontouchstart"in window)},events:{},drawable:{enabled:!0,visible:!0,defaultSnapToValidMove:!0,eraseOnMovablePieceClick:!0,shapes:[],autoShapes:[],brushes:{green:{key:"g",color:"#15781B",opacity:1,lineWidth:10},red:{key:"r",color:"#882020",opacity:1,lineWidth:10},blue:{key:"b",color:"#003088",opacity:1,lineWidth:10},yellow:{key:"y",color:"#e68f00",opacity:1,lineWidth:10},paleBlue:{key:"pb",color:"#003088",opacity:.4,lineWidth:15},paleGreen:{key:"pg",color:"#15781B",opacity:.4,lineWidth:15},paleRed:{key:"pr",color:"#882020",opacity:.4,lineWidth:15},paleGrey:{key:"pgr",color:"#4a4a4a",opacity:.35,lineWidth:15},purple:{key:"purple",color:"#68217a",opacity:.65,lineWidth:10},pink:{key:"pink",color:"#ee2080",opacity:.5,lineWidth:10},white:{key:"white",color:"white",opacity:1,lineWidth:10},paleWhite:{key:"pwhite",color:"white",opacity:.6,lineWidth:10}},prevSvgHash:""},hold:ro()}}function Fo(){let e=y("defs"),o=w(y("filter"),{id:"cg-filter-blur"});return o.appendChild(w(y("feGaussianBlur"),{stdDeviation:"0.013"})),e.appendChild(o),e}function Go(e,o){let r=e.drawable,n=r.current,t=n&&n.mouseSq?n:void 0,i=new Map,a=e.dom.bounds(),l=r.autoShapes.filter(c=>!c.piece);for(let c of r.shapes.concat(l).concat(t?[t]:[])){if(!c.dest)continue;let u=i.get(c.dest)??new Set,p=Se(Pe(f(c.orig),e.orientation),a),m=Se(Pe(f(c.dest),e.orientation),a);u.add(je(p,m)),i.set(c.dest,u)}let d=[];for(let c of r.shapes.concat(l))d.push({shape:c,current:!1,hash:Vo(c,Ie(c.dest,i),!1,a)});t&&d.push({shape:t,current:!0,hash:Vo(t,Ie(t.dest,i),!0,a)});let s=d.map(c=>c.hash).join(";");s!==e.drawable.prevSvgHash&&(e.drawable.prevSvgHash=s,Br(r,d,o),Rr(d,o,c=>Lr(e,c,r.brushes,i,a)))}function Br(e,o,r){for(let n of[r.shapes,r.shapesBelow]){let t=n.querySelector("defs"),i=o.filter(s=>n===r.shapesBelow==!!s.shape.below),a=new Map;for(let s of i.filter(c=>c.shape.dest&&c.shape.brush)){let c=Wo(e.brushes[s.shape.brush],s.shape.modifiers),{key:u,color:p}=zo(s.shape);u&&p&&a.set(u,{key:u,color:p,opacity:1,lineWidth:1}),a.set(c.key,c)}let l=new Set,d=t.firstElementChild;for(;d;)l.add(d.getAttribute("cgKey")),d=d.nextElementSibling;for(let[s,c]of a.entries())l.has(s)||t.appendChild(Wr(c))}}function Rr(e,o,r){for(let[n,t]of[[o.shapes,o.custom],[o.shapesBelow,o.customBelow]]){let[i,a]=[n,t].map(s=>s.querySelector("g")),l=e.filter(s=>n===o.shapesBelow==!!s.shape.below),d=new Map;for(let s of l)d.set(s.hash,!1);for(let s of[i,a]){let c=[],u=s.firstElementChild,p;for(;u;)p=u.getAttribute("cgHash"),d.has(p)?d.set(p,!0):c.push(u),u=u.nextElementSibling;for(let m of c)s.removeChild(m)}for(let s of l.filter(c=>!d.get(c.hash)))for(let c of r(s))c.isCustom?a.appendChild(c.el):i.appendChild(c.el)}}function Vo({orig:e,dest:o,brush:r,piece:n,modifiers:t,customSvg:i,label:a,below:l},d,s,c){return[c.width,c.height,s,e,o,r,d&&"-",n&&Or(n),t&&Vr(t),i&&`custom-${Lo(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Lo(a.text)}`,l&&"below"].filter(u=>u).join(",")}function Or(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function Vr(e){return[e.lineWidth,e.hilite].filter(o=>o).join(",")}function Lo(e){let o=0;for(let r=0;r<e.length;r++)o=(o<<5)-o+e.charCodeAt(r)>>>0;return o.toString()}function Lr(e,{shape:o,current:r,hash:n},t,i,a){let l=Se(Pe(f(o.orig),e.orientation),a),d=o.dest?Se(Pe(f(o.dest),e.orientation),a):l,s=o.brush&&Wo(t[o.brush],o.modifiers),c=i.get(o.dest),u=[];if(s){let p=w(y("g"),{cgHash:n});u.push({el:p}),l[0]!==d[0]||l[1]!==d[1]?p.appendChild(Gr(o,s,l,d,r,Ie(o.dest,i))):p.appendChild(Fr(t[o.brush],l,r,a))}if(o.label){let p=o.label;p.fill??=o.brush&&t[o.brush].color;let m=o.brush?void 0:"tr";u.push({el:zr(p,n,l,d,c,m),isCustom:!0})}if(o.customSvg){let p=o.customSvg.center??"orig",[m,v]=p==="label"?Io(l,d,c).map(B=>B-.5):p==="dest"?d:l,g=w(y("g"),{transform:`translate(${m},${v})`,cgHash:n});g.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,u.push({el:g,isCustom:!0})}return u}function Fr(e,o,r,n){let t=$r(),i=(n.width+n.height)/(4*Math.max(n.width,n.height));return w(y("circle"),{stroke:e.color,"stroke-width":t[r?0:1],fill:"none",opacity:$o(e,r),cx:o[0],cy:o[1],r:i-t[1]/2})}function Gr(e,o,r,n,t,i){function a(s){let c=jr(i&&!t),u=n[0]-r[0],p=n[1]-r[1],m=Math.atan2(p,u),v=Math.cos(m)*c,g=Math.sin(m)*c,B=zo(e);return w(y("line"),{stroke:s?B.color:o.color,"stroke-width":Ir(o,t)*(s?1.14:1),"stroke-linecap":"round","marker-end":`url(#arrowhead-${s?B.key:o.key})`,opacity:e.modifiers?.hilite?1:$o(o,t),x1:r[0],y1:r[1],x2:n[0]-v,y2:n[1]-g})}if(!e.modifiers?.hilite)return a(!1);let l=w(y("g"),{opacity:o.opacity}),d=w(y("g"),{filter:"url(#cg-filter-blur)"});return d.appendChild(Ur(r,n)),d.appendChild(a(!0)),l.appendChild(d),l.appendChild(a(!1)),l}function Wr(e){let o=w(y("marker"),{id:"arrowhead-"+e.key,orient:"auto",overflow:"visible",markerWidth:4,markerHeight:4,refX:e.key.startsWith("hilite")?1.86:2.05,refY:2});return o.appendChild(w(y("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),o.setAttribute("cgKey",e.key),o}function zr(e,o,r,n,t,i){let l=.4*.75**e.text.length,d=Io(r,n,t),s=i==="tr"?.4:0,c=w(y("g"),{transform:`translate(${d[0]+s},${d[1]-s})`,cgHash:o});c.appendChild(w(y("circle"),{r:.4/2,"fill-opacity":i?1:.8,"stroke-opacity":i?1:.7,"stroke-width":.03,fill:e.fill??"#666",stroke:"white"}));let u=w(y("text"),{"font-size":l,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return u.innerHTML=e.text,c.appendChild(u),c}function Pe(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function Ie(e,o){return(e&&o.has(e)&&o.get(e).size>1)===!0}function y(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function w(e,o){for(let r in o)Object.prototype.hasOwnProperty.call(o,r)&&e.setAttribute(r,o[r]);return e}function Wo(e,o){return o?{color:e.color,opacity:Math.round(e.opacity*10)/10,lineWidth:Math.round(o.lineWidth||e.lineWidth),key:[e.key,o.lineWidth].filter(r=>r).join("")}:e}function $r(){return[3/64,4/64]}function Ir(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function zo(e){let o=e.modifiers?.hilite;return{key:o&&`hilite-${o.replace("#","")}`,color:o}}function $o(e,o){return(e.opacity||1)*(o?.9:1)}function jr(e){return(e?20:10)/64}function Se(e,o){let r=Math.min(1,o.width/o.height),n=Math.min(1,o.height/o.width);return[(e[0]-3.5)*r,(3.5-e[1])*n]}function Ur(e,o){let r={from:[Math.floor(Math.min(e[0],o[0])),Math.floor(Math.min(e[1],o[1]))],to:[Math.ceil(Math.max(e[0],o[0])),Math.ceil(Math.max(e[1],o[1]))]};return w(y("rect"),{x:r.from[0],y:r.from[1],width:r.to[0]-r.from[0],height:r.to[1]-r.from[1],fill:"none",stroke:"none"})}function je(e,o,r=!0){let n=Math.atan2(o[1]-e[1],o[0]-e[0])+Math.PI;return r?(Math.round(n*8/Math.PI)+16)%16:n}function Zr(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((r,n)=>r+n*n,0))}function Io(e,o,r){let n=Zr(e,o),t=je(e,o,!1);if(r&&(n-=33/64,r.size>1)){n-=10/64;let i=je(e,o);(r.has((i+1)%16)||r.has((i+15)%16))&&i&1&&(n-=.4)}return[e[0]-Math.cos(t)*n,e[1]-Math.sin(t)*n].map(i=>i+.5)}function Uo(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let c of Qe)e.classList.toggle("orientation-"+c,o.orientation===c);e.classList.toggle("manipulable",!o.viewOnly);let r=C("cg-container");e.appendChild(r);let n=C("cg-board");r.appendChild(n);let t,i,a,l,d;if(o.drawable.visible&&([t,i]=["cg-shapes-below","cg-shapes"].map(c=>jo(c,!0)),[a,l]=["cg-custom-below","cg-custom-svgs"].map(c=>jo(c,!1)),d=C("cg-auto-pieces"),r.appendChild(t),r.appendChild(a),r.appendChild(i),r.appendChild(l),r.appendChild(d)),o.coordinates){let c=o.orientation==="black"?" black":"",u=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let p=o.orientation==="white"?m=>m+1:m=>8-m;W.forEach((m,v)=>r.appendChild(Ue(j.map(g=>m+g),"squares rank"+p(v)+c+u)))}else r.appendChild(Ue(j,"ranks"+c+u)),r.appendChild(Ue(W,"files"+c))}let s;return o.draggable.enabled&&o.draggable.showGhost&&(s=C("piece","ghost"),Y(s,!1),r.appendChild(s)),{board:n,container:r,wrap:e,ghost:s,shapes:i,shapesBelow:t,custom:l,customBelow:a,autoPieces:d}}function jo(e,o){let r=w(y("svg"),{class:e,viewBox:o?"-4 -4 8 8":"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"});return o&&r.appendChild(Fo()),r.appendChild(y("g")),r}function Ue(e,o){let r=C("coords",o),n;for(let t of e)n=C("coord"),n.textContent=t,r.appendChild(n);return r}function Zo(e,o){if(!e.dropmode.active)return;x(e),E(e);let r=e.dropmode.piece;if(r){e.pieces.set("a0",r);let n=T(o),t=n&&A(n,h(e),e.dom.bounds());t&&he(e,"a0",t)}e.dom.redraw()}function Xo(e,o){let r=e.dom.elements.board;if("ResizeObserver"in window&&new ResizeObserver(o).observe(e.dom.elements.wrap),(e.disableContextMenu||e.drawable.enabled)&&r.addEventListener("contextmenu",t=>t.preventDefault()),e.viewOnly)return;let n=Xr(e);r.addEventListener("touchstart",n,{passive:!1}),r.addEventListener("mousedown",n,{passive:!1})}function Qo(e,o){let r=[];if("ResizeObserver"in window||r.push(ie(document.body,"chessground.resize",o)),!e.viewOnly){let n=_o(e,Ao,ko),t=_o(e,No,Co);for(let a of["touchmove","mousemove"])r.push(ie(document,a,n));for(let a of["touchend","mouseup"])r.push(ie(document,a,t));let i=()=>e.dom.bounds.clear();r.push(ie(document,"scroll",i,{capture:!0,passive:!0})),r.push(ie(window,"resize",i,{passive:!0}))}return()=>r.forEach(n=>n())}function ie(e,o,r,n){return e.addEventListener(o,r,n),()=>e.removeEventListener(o,r,n)}var Xr=e=>o=>{e.draggable.current?$(e):e.drawable.current?ze(e):o.shiftKey||le(o)?e.drawable.enabled&&So(e,o):e.viewOnly||(e.dropmode.active?Zo(e,o):xo(e,o))},_o=(e,o,r)=>n=>{e.drawable.current?e.drawable.enabled&&r(e,n):e.viewOnly||o(e,n)};function Jo(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.board,t=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,l=i?i.plan.fadings:new Map,d=e.draggable.current,s=Yr(e),c=new Set,u=new Set,p=new Map,m=new Map,v,g,B,I,D,_,Me,N,ke,se;for(g=n.firstChild;g;){if(v=g.cgKey,or(g))if(B=t.get(v),D=a.get(v),_=l.get(v),I=g.cgPiece,g.cgDragging&&(!d||d.orig!==v)&&(g.classList.remove("dragging"),k(g,r(f(v),o)),g.cgDragging=!1),!_&&g.cgFading&&(g.cgFading=!1,g.classList.remove("fading")),B){if(D&&g.cgAnimating&&I===ae(B)){let b=f(v);b[0]+=D[2],b[1]+=D[3],g.classList.add("anim"),k(g,r(b,o))}else g.cgAnimating&&(g.cgAnimating=!1,g.classList.remove("anim"),k(g,r(f(v),o)),e.addPieceZIndex&&(g.style.zIndex=Ze(f(v),o)));I===ae(B)&&(!_||!g.cgFading)?c.add(v):_&&I===ae(_)?(g.classList.add("fading"),g.cgFading=!0):_e(p,I,g)}else _e(p,I,g);else if(rr(g)){let b=g.className;s.get(v)===b?u.add(v):_e(m,b,g)}g=g.nextSibling}for(let[b,X]of s)if(!u.has(b)){ke=m.get(X),se=ke&&ke.pop();let H=r(f(b),o);if(se)se.cgKey=b,k(se,H);else{let q=C("square",X);q.cgKey=b,k(q,H),n.insertBefore(q,n.firstChild)}}for(let[b,X]of t)if(D=a.get(b),!c.has(b))if(Me=p.get(ae(X)),N=Me&&Me.pop(),N){N.cgKey=b,N.cgFading&&(N.classList.remove("fading"),N.cgFading=!1);let H=f(b);e.addPieceZIndex&&(N.style.zIndex=Ze(H,o)),D&&(N.cgAnimating=!0,N.classList.add("anim"),H[0]+=D[2],H[1]+=D[3]),k(N,r(H,o))}else{let H=ae(X),q=C("piece",H),ce=f(b);q.cgPiece=H,q.cgKey=b,D&&(q.cgAnimating=!0,ce[0]+=D[2],ce[1]+=D[3]),k(q,r(ce,o)),e.addPieceZIndex&&(q.style.zIndex=Ze(ce,o)),n.appendChild(q)}for(let b of p.values())Yo(e,b);for(let b of m.values())Yo(e,b)}function er(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.board.firstChild;for(;n;)(or(n)&&!n.cgAnimating||rr(n))&&k(n,r(f(n.cgKey),o)),n=n.nextSibling}function Xe(e){let o=e.dom.elements.wrap.getBoundingClientRect(),r=e.dom.elements.container,n=o.height/o.width,t=Math.floor(o.width*window.devicePixelRatio/8)*8/window.devicePixelRatio,i=t*n;r.style.width=t+"px",r.style.height=i+"px",e.dom.bounds.clear(),e.addDimensionsCssVarsTo?.style.setProperty("---cg-width",t+"px"),e.addDimensionsCssVarsTo?.style.setProperty("---cg-height",i+"px")}var or=e=>e.tagName==="PIECE",rr=e=>e.tagName==="SQUARE";function Yo(e,o){for(let r of o)e.dom.elements.board.removeChild(r)}function Ze(e,o){let n=e[1];return`${o?10-n:3+n}`}var ae=e=>`${e.color} ${e.role}`;function Yr(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let t of e.lastMove)V(o,t,"last-move");if(e.check&&e.highlight.check&&V(o,e.check,"check"),e.selected&&(V(o,e.selected,"selected"),e.movable.showDests)){let t=e.movable.dests?.get(e.selected);if(t)for(let a of t)V(o,a,"move-dest"+(e.pieces.has(a)?" oc":""));let i=e.premovable.customDests?.get(e.selected)??e.premovable.dests;if(i)for(let a of i)V(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let r=e.premovable.current;if(r)for(let t of r)V(o,t,"current-premove");else e.predroppable.current&&V(o,e.predroppable.current.key,"current-premove");let n=e.exploding;if(n)for(let t of n.keys)V(o,t,"exploding"+n.stage);return e.highlight.custom&&e.highlight.custom.forEach((t,i)=>{V(o,i,t)}),o}function V(e,o,r){let n=e.get(o);n?e.set(o,`${n} ${r}`):e.set(o,r)}function _e(e,o,r){let n=e.get(o);n?n.push(r):e.set(o,[r])}function nr(e,o,r){let n=new Map,t=[];for(let l of e)n.set(l.hash,!1);let i=o.firstElementChild,a;for(;i;)a=i.getAttribute("cgHash"),n.has(a)?n.set(a,!0):t.push(i),i=i.nextElementSibling;for(let l of t)o.removeChild(l);for(let l of e)n.get(l.hash)||o.appendChild(r(l))}function tr(e,o){let n=e.drawable.autoShapes.filter(t=>t.piece).map(t=>({shape:t,hash:en(t),current:!1}));nr(n,o,t=>Jr(e,t,e.dom.bounds()))}function ir(e){let o=h(e),r=G(e.dom.bounds()),n=e.dom.elements.autoPieces?.firstChild;for(;n;)De(n,r(f(n.cgKey),o),n.cgScale),n=n.nextSibling}function Jr(e,{shape:o,hash:r},n){let t=o.orig,i=o.piece?.role,a=o.piece?.color,l=o.piece?.scale,d=C("piece",`${i} ${a}`);return d.setAttribute("cgHash",r),d.cgKey=t,d.cgScale=l,De(d,G(n)(f(t),h(e)),l),d}var en=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function ot({el:e,config:o}){return rn(e,o)}function rn(e,o){let r=Oo();we(r,o||{});function n(){let t="dom"in r?r.dom.unbind:void 0,i=Uo(e,r),a=oo(()=>i.board.getBoundingClientRect()),l=c=>{Jo(s),i.autoPieces&&tr(s,i.autoPieces),!c&&i.shapes&&Go(s,i)},d=()=>{Xe(s),er(s),i.autoPieces&&ir(s)},s=r;return s.dom={elements:i,bounds:a,redraw:nn(l),redrawNow:l,unbind:t},s.drawable.prevSvgHash="",Xe(s),l(!1),Xo(s,d),t||(s.dom.unbind=Qo(s,d)),s.events.insert&&s.events.insert(i),s}return Ro(n(),n)}function nn(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{rn as Chessground,ot as initModule};
package/dist/drag.js CHANGED
@@ -17,7 +17,7 @@ export function start(s, e) {
17
17
  if (!previouslySelected &&
18
18
  s.drawable.enabled &&
19
19
  (s.drawable.eraseOnMovablePieceClick || !piece || piece.color !== s.turnColor))
20
- s.pixelCoordsOfMouchDownToMaybeClearShapes = position;
20
+ drawClear(s);
21
21
  // Prevent touch scroll and create no corresponding mouse event, if there
22
22
  // is an intent to interact with the board.
23
23
  if (e.cancelable !== false &&
@@ -138,12 +138,6 @@ export function move(s, e) {
138
138
  }
139
139
  }
140
140
  export function end(s, e) {
141
- const position = util.eventPosition(e);
142
- if (position &&
143
- s.pixelCoordsOfMouchDownToMaybeClearShapes &&
144
- util.samePos(position, s.pixelCoordsOfMouchDownToMaybeClearShapes))
145
- drawClear(s);
146
- s.pixelCoordsOfMouchDownToMaybeClearShapes = undefined;
147
141
  const cur = s.draggable.current;
148
142
  if (!cur)
149
143
  return;
package/dist/drag.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"drag.js","sourceRoot":"","sources":["../src/drag.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAgBjC,MAAM,UAAU,KAAK,CAAC,CAAQ,EAAE,CAAgB;IAC9C,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,SAAS,CAAC;QAAE,OAAO,CAAC,4CAA4C;IAC5F,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC;QAAE,OAAO,CAAC,2BAA2B;IACjF,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,gCAAgC;IAC/E,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,EAC3B,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAE,EACjC,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,kBAAkB,GAAG,CAAC,CAAC,QAAQ,CAAC;IACtC,IACE,CAAC,kBAAkB;QACnB,CAAC,CAAC,QAAQ,CAAC,OAAO;QAClB,CAAC,CAAC,CAAC,QAAQ,CA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,CAAC;QACR,IAAI,GAAG,CAAC,QAAQ;YAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC,CAAC,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC;QAChC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAClB,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAQ;IAClC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;IACzB,IAAI,CAAC,CAAC,KAAK;QAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAQ,EAAE,GAAW;IAC9C,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;IACzC,OAAO,EAAE,EAAE,CAAC;QACV,IAAK,EAAmB,CAAC,KAAK,KAAK,GAAG,IAAK,EAAmB,CAAC,OAAO,KAAK,OAAO;YAChF,OAAO,EAAkB,CAAC;QAC5B,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC;IACtB,CAAC;IACD,OAAO;AACT,CAAC"}
package/dist/state.d.ts CHANGED
@@ -20,7 +20,6 @@ export interface HeadlessState {
20
20
  blockTouchScroll: boolean;
21
21
  touchIgnoreRadius: number;
22
22
  pieceKey: boolean;
23
- pixelCoordsOfMouchDownToMaybeClearShapes?: cg.NumberPair;
24
23
  trustAllEvents?: boolean;
25
24
  highlight: {
26
25
  lastMove: boolean;
package/dist/state.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC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,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;aAC1E;YACD,WAAW,EAAE,EAAE;SAChB;QACD,IAAI,EAAE,KAAK,EAAE;KACd,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lichess-org/chessground",
3
- "version": "9.8.2",
3
+ "version": "9.8.3",
4
4
  "//": "version is managed by the build system",
5
5
  "description": "lichess.org chess ui",
6
6
  "type": "module",
package/src/drag.ts CHANGED
@@ -34,7 +34,7 @@ export function start(s: State, e: cg.MouchEvent): void {
34
34
  s.drawable.enabled &&
35
35
  (s.drawable.eraseOnMovablePieceClick || !piece || piece.color !== s.turnColor)
36
36
  )
37
- s.pixelCoordsOfMouchDownToMaybeClearShapes = position;
37
+ drawClear(s);
38
38
  // Prevent touch scroll and create no corresponding mouse event, if there
39
39
  // is an intent to interact with the board.
40
40
  if (
@@ -159,14 +159,6 @@ export function move(s: State, e: cg.MouchEvent): void {
159
159
  }
160
160
 
161
161
  export function end(s: State, e: cg.MouchEvent): void {
162
- const position = util.eventPosition(e);
163
- if (
164
- position &&
165
- s.pixelCoordsOfMouchDownToMaybeClearShapes &&
166
- util.samePos(position, s.pixelCoordsOfMouchDownToMaybeClearShapes)
167
- )
168
- drawClear(s);
169
- s.pixelCoordsOfMouchDownToMaybeClearShapes = undefined;
170
162
  const cur = s.draggable.current;
171
163
  if (!cur) return;
172
164
  // create no corresponding mouse event
package/src/state.ts CHANGED
@@ -23,7 +23,6 @@ export interface HeadlessState {
23
23
  blockTouchScroll: boolean; // block scrolling via touch dragging on the board
24
24
  touchIgnoreRadius: number; // ignore touches within a radius of an occupied square, in units of its circumradius
25
25
  pieceKey: boolean; // add a data-key attribute to piece elements
26
- pixelCoordsOfMouchDownToMaybeClearShapes?: cg.NumberPair;
27
26
  trustAllEvents?: boolean; // disable checking for human only input (e.isTrusted)
28
27
  highlight: {
29
28
  lastMove: boolean; // add last-move class to squares