@lichess-org/chessground 9.8.4 → 9.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chessground.min.js +1 -1
- package/dist/util.js +3 -1
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
- package/src/util.ts +7 -1
package/dist/chessground.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Je=["white","black"];var z=["a","b","c","d","e","f","g","h"],j=["1","2","3","4","5","6","7","8"];var oo=[...j].reverse(),Q=z.flatMap(e=>j.map(o=>e+o)),M=e=>e.every(o=>o>=0&&o<=7)?Q[8*e[0]+e[1]]:void 0,F=e=>M(e),f=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var De=Q.map(f),no=Q.map((e,o)=>({key:e,pos:De[o]}));function ro(e){let o,n=()=>(o===void 0&&(o=e()),o);return n.clear=()=>{o=void 0},n}var to=()=>{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",G=(e,o)=>(e[0]-o[0])**2+(e[1]-o[1])**2,$=(e,o)=>e.role===o.role&&e.color===o.color,io=(e,o)=>e[0]===o[0]&&e[1]===o[1],W=e=>(o,n)=>[(n?o[0]:7-o[0])*e.width/8,(n?7-o[1]:o[1])*e.height/8],k=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},Ke=(e,o,n=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${n})`},Y=(e,o)=>{e.style.visibility=o?"visible":"hidden"},B=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 n=document.createElement(e);return o&&(n.className=o),n};function de(e,o,n){let r=f(e);return o||(r[0]=7-r[0],r[1]=7-r[1]),[n.left+n.width*r[0]/8+n.width/16,n.top+n.height*(7-r[1])/8+n.height/16]}var x=(e,o)=>Math.abs(e-o),J=(e,o,n,r)=>x(e,n)*x(o,r)===2,ue=(e,o,n,r)=>e===n!=(o===r),pe=(e,o,n,r)=>x(e,n)===x(o,r)&&e!==n,fe=(e,o,n,r)=>ue(e,o,n,r)||pe(e,o,n,r),xe=(e,o,n,r)=>Math.max(x(e,n),x(o,r))===1,Ee=(e,o,n,r,t)=>x(e,n)===1&&r===o+(t?1:-1),Ae=(e,o,n,r,t)=>{let i=t?1:-1;return e===n&&(r===o+i||r===o+2*i&&(t?o<=1:o>=6))},ee=(e,o,n,r)=>{let t=n-e,i=r-o;if(t&&i&&Math.abs(t)!==Math.abs(i))return[];let a=Math.sign(t),u=Math.sign(i),d=[],s=e+a,c=o+u;for(;s!==n||c!==r;)d.push([s,c]),s+=a,c+=u;return d.map(M).filter(l=>l!==void 0)},ao=e=>{let o=f(e),n=[];return o[0]>0&&n.push([o[0]-1,o[1]]),o[0]<7&&n.push([o[0]+1,o[1]]),n.map(M).filter(r=>r!==void 0)},oe=(e,o)=>{let n=f(e);return n[1]+=o,M(n)};var Z=e=>e.friendlies.has(e.dest.key),ln=e=>e.enemies.has(e.dest.key),so=(e,o,n)=>ee(...e,...o).some(r=>n.has(r)),co=(e,o,n)=>{let r=n.enemies.get(e);if(r?.role!=="pawn")return!1;let t=r.color==="white"?1:-1,i=f(e),a=f(o);return Ae(...i,...a,r.color==="white")&&!so(i,[a[0],a[1]+t],n.allPieces)},dn=(e,o,n)=>{let r=n.enemies.get(e);return r?.role==="pawn"&&Ee(...f(e),...f(o),r.color==="white")&&(n.friendlies.has(o)||me(oe(o,r.color==="white"?-1:1),n.friendlies,n.enemies,n.lastMove))},un=e=>[...e.enemies.keys()].some(o=>co(o,e.dest.key,e)),Ne=(e,o)=>{let n=e.dest.pos;return[...e.enemies].some(([r,t])=>{let i=f(r);return!o?.includes(t.role)&&(t.role==="pawn"&&Ee(...i,...n,t.color==="white")||t.role==="knight"&&J(...i,...n)||t.role==="bishop"&&pe(...i,...n)||t.role==="rook"&&ue(...i,...n)||t.role==="queen"&&fe(...i,...n)||t.role==="king"&&xe(...i,...n))&&(!["bishop","rook","queen"].includes(t.role)||!so(i,n,e.allPieces))})},ge=e=>Z(e)&&(me(e.dest.key,e.friendlies,e.enemies,e.lastMove)||Ne(e)),me=(e,o,n,r)=>{if(!e||r&&e!==r[1])return!1;let t=f(e),i=o.get(e);return i?.role==="pawn"&&t[1]===(i.color==="white"?3:4)&&(!r||x(f(r[0])[1],t[1])===2)&&[1,-1].some(a=>{let u=M([t[0]+a,t[1]]);return!!u&&n.get(u)?.role==="pawn"})},pn=(e,o)=>{if(e.unrestrictedPremoves)return!0;let n=ee(...e.orig.pos,...e.dest.pos);o&&n.push(e.dest.key);let r=n.filter(a=>e.friendlies.has(a));if(!r.length)return!0;let t=r[0],i=oe(t,e.color==="white"?-1:1);return r.length===1&&me(t,e.friendlies,e.enemies,e.lastMove)&&!!i&&!n.includes(i)},fn=(e,o)=>{if(e.unrestrictedPremoves)return!0;let n=ee(...e.orig.pos,...e.dest.pos);o&&n.push(e.dest.key);let r=n.filter(c=>e.enemies.has(c));if(r.length>1)return!1;if(!r.length)return!0;let t=r[0],i=e.enemies.get(t);if(!i||i.role!=="pawn")return!0;let a=i.color==="white"?1:-1,u=oe(t,a),d=u?[...ao(u).filter(c=>dn(t,c,e)),...[u,oe(u,a)].filter(c=>!!c).filter(c=>co(t,c,e))]:[],s=[...n,e.orig.key];return d.some(c=>!s.includes(c))},He=(e,o)=>pn(e,o)&&fn(e,o),gn=e=>{let o=e.color==="white"?1:-1;return x(e.orig.pos[0],e.dest.pos[0])>1?!1:x(e.orig.pos[0],e.dest.pos[0])?e.dest.pos[1]!==e.orig.pos[1]+o?!1:e.unrestrictedPremoves||ln(e)?!0:Z(e)?Ne(e):un(e)||me(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)},mn=e=>J(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),lo=e=>pe(...e.orig.pos,...e.dest.pos)&&He(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),uo=e=>ue(...e.orig.pos,...e.dest.pos)&&He(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),bn=e=>lo(e)||uo(e),hn=e=>xe(...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||$(o,{role:"rook",color:e.color}))),vn={pawn:gn,knight:mn,bishop:lo,rook:uo,queen:bn,king:hn};function qe(e,o){let n=e.pieces,r=e.premovable.castle,t=!!e.premovable.unrestrictedPremoves,i=n.get(o);if(!i||i.color===e.turnColor)return[];let a=i.color,u=new Map([...n].filter(([p,m])=>m.color===a)),d=new Map([...n].filter(([p,m])=>m.color===U(a))),s={key:o,pos:f(o)},c=p=>vn[i.role](p)&&e.premovable.additionalPremoveRequirements(p),l={orig:s,role:i.role,allPieces:n,friendlies:u,enemies:d,unrestrictedPremoves:t,color:a,canCastle:r,rookFilesFriendlies:Array.from(n).filter(([p,m])=>p[1]===(a==="white"?"1":"8")&&m.color===a&&m.role==="rook").map(([p])=>f(p)[0]),lastMove:e.lastMove};return no.filter(p=>c({...l,dest:p})).map(p=>p.key)}function S(e,...o){e&&setTimeout(()=>e(...o),1)}function po(e){e.orientation=U(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function fo(e,o){for(let[n,r]of o)r?e.pieces.set(n,r):e.pieces.delete(n)}function go(e,o){if(e.check=void 0,o===!0&&(o=e.turnColor),o)for(let[n,r]of e.pieces)r.role==="king"&&r.color===o&&(e.check=n)}function yn(e,o,n,r){A(e),e.premovable.current=[o,n],S(e.premovable.events.set,o,n,r)}function E(e){e.premovable.current&&(e.premovable.current=void 0,S(e.premovable.events.unset))}function wn(e,o,n){E(e),e.predroppable.current={role:o,key:n},S(e.predroppable.events.set,o,n)}function A(e){let o=e.predroppable;o.current&&(o.current=void 0,S(o.events.unset))}function Pn(e,o,n){if(!e.autoCastle)return!1;let r=e.pieces.get(o);if(!r||r.role!=="king")return!1;let t=f(o),i=f(n);if(t[1]!==0&&t[1]!==7||t[1]!==i[1])return!1;t[0]===4&&!e.pieces.has(n)&&(i[0]===6?n=F([7,i[1]]):i[0]===2&&(n=F([0,i[1]])));let a=e.pieces.get(n);return!a||a.color!==r.color||a.role!=="rook"?!1:(e.pieces.delete(o),e.pieces.delete(n),t[0]<i[0]?(e.pieces.set(F([6,i[1]]),r),e.pieces.set(F([5,i[1]]),a)):(e.pieces.set(F([2,i[1]]),r),e.pieces.set(F([3,i[1]]),a)),!0)}function Te(e,o,n){let r=e.pieces.get(o),t=e.pieces.get(n);if(o===n||!r)return!1;let i=t&&t.color!==r.color?t:void 0;return n===e.selected&&P(e),S(e.events.move,o,n,i),Pn(e,o,n)||(e.pieces.set(n,r),e.pieces.delete(o)),e.lastMove=[o,n],e.check=void 0,S(e.events.change),i||!0}function be(e,o,n,r){if(e.pieces.has(n))if(r)e.pieces.delete(n);else return!1;return S(e.events.dropNewPiece,o,n),e.pieces.set(n,o),e.lastMove=[n],e.check=void 0,S(e.events.change),e.movable.dests=void 0,e.turnColor=U(e.turnColor),!0}function mo(e,o,n){let r=Te(e,o,n);return r&&(e.movable.dests=void 0,e.turnColor=U(e.turnColor),e.animation.current=void 0),r}function Be(e,o,n){if(ve(e,o,n)){let r=mo(e,o,n);if(r){let t=e.hold.stop();P(e);let i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:t};return r!==!0&&(i.captured=r),S(e.movable.events.after,o,n,i),!0}}else if(Mn(e,o,n))return yn(e,o,n,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function he(e,o,n,r){let t=e.pieces.get(o);t&&(Sn(e,o,n)||r)?(e.pieces.delete(o),be(e,t,n,r),S(e.movable.events.afterNewPiece,t.role,n,{premove:!1,predrop:!1})):t&&kn(e,o,n)?wn(e,t.role,n):(E(e),A(e)),e.pieces.delete(o),P(e)}function re(e,o,n){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||n)&&e.selected!==o&&Be(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(bo(e,o)||Oe(e,o))&&(Re(e,o),e.hold.start())}function Re(e,o){e.selected=o,Oe(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 bo(e,o){let n=e.pieces.get(o);return!!n&&(e.movable.color==="both"||e.movable.color===n.color&&e.turnColor===n.color)}var ve=(e,o,n)=>o!==n&&bo(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(n));function Sn(e,o,n){let r=e.pieces.get(o);return!!r&&(o===n||!e.pieces.has(n))&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}function Oe(e,o){let n=e.pieces.get(o);return!!n&&e.premovable.enabled&&e.movable.color===n.color&&e.turnColor!==n.color}var Mn=(e,o,n)=>o!==n&&Oe(e,o)&&(e.premovable.customDests?.get(o)??qe(e,o)).includes(n);function kn(e,o,n){let r=e.pieces.get(o),t=e.pieces.get(n);return!!r&&(!t||t.color!==e.movable.color)&&e.predroppable.enabled&&(r.role!=="pawn"||n[1]!=="1"&&n[1]!=="8")&&e.movable.color===r.color&&e.turnColor!==r.color}function ho(e,o){let n=e.pieces.get(o);return!!n&&e.draggable.enabled&&(e.movable.color==="both"||e.movable.color===n.color&&(e.turnColor===n.color||e.premovable.enabled))}function vo(e){let o=e.premovable.current;if(!o)return!1;let n=o[0],r=o[1],t=!1;if(ve(e,n,r)){let i=mo(e,n,r);if(i){let a={premove:!0};i!==!0&&(a.captured=i),S(e.movable.events.after,n,r,a),t=!0}}return E(e),t}function yo(e,o){let n=e.predroppable.current,r=!1;if(!n)return!1;if(o(n)){let t={role:n.role,color:e.movable.color};be(e,t,n.key)&&(S(e.movable.events.afterNewPiece,n.role,n.key,{premove:!1,predrop:!0}),r=!0)}return A(e),r}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,n){let r=Math.floor(8*(e[0]-n.left)/n.width);o||(r=7-r);let t=7-Math.floor(8*(e[1]-n.top)/n.height);return o||(t=7-t),r>=0&&r<8&&t>=0&&t<8?M([r,t]):void 0}function wo(e,o,n,r){let t=f(e),i=De.filter(s=>io(t,s)||fe(t[0],t[1],s[0],s[1])||J(t[0],t[1],s[0],s[1])),u=i.map(s=>de(F(s),n,r)).map(s=>G(o,s)),[,d]=u.reduce((s,c,l)=>s[0]<c?s:[c,l],[u[0],0]);return M(i[d])}var v=e=>e.orientation==="white";var Fe="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",Cn={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},Dn={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function ye(e){e==="start"&&(e=Fe);let o=new Map,n=7,r=0;for(let t of e)switch(t){case" ":case"[":return o;case"/":if(--n,n<0)return o;r=0;break;case"~":{let i=M([r-1,n]),a=i&&o.get(i);a&&(a.promoted=!0);break}default:{let i=t.charCodeAt(0);if(i<57)r+=i-48;else{let a=t.toLowerCase(),u=M([r,n]);u&&o.set(u,{role:Cn[a],color:t===a?"black":"white"}),++r}}}return o}function Po(e){return oo.map(o=>z.map(n=>{let r=e.get(n+o);if(r){let t=Dn[r.role];return r.color==="white"&&(t=t.toUpperCase()),r.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 we(e,o){if(o.movable?.dests&&(e.movable.dests=void 0),o.drawable?.autoShapes&&(e.drawable.autoShapes=[]),We(e,o),o.fen&&(e.pieces=ye(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&go(e,o.check||!1),"lastMove"in o&&!o.lastMove?e.lastMove=void 0:o.lastMove&&(e.lastMove=o.lastMove),e.selected&&Re(e,e.selected),Ge(e,o),!e.movable.rookCastle&&e.movable.dests){let n=e.movable.color==="white"?"1":"8",r="e"+n,t=e.movable.dests.get(r),i=e.pieces.get(r);if(!t||!i||i.role!=="king")return;e.movable.dests.set(r,t.filter(a=>!(a==="a"+n&&t.includes("c"+n))&&!(a==="h"+n&&t.includes("g"+n))))}}function We(e,o){for(let n in o)n==="__proto__"||n==="constructor"||!Object.prototype.hasOwnProperty.call(o,n)||(Object.prototype.hasOwnProperty.call(e,n)&&So(e[n])&&So(o[n])?We(e[n],o[n]):e[n]=o[n])}function So(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?An(e,o):V(e,o);function V(e,o){let n=e(o);return o.dom.redraw(),n}var ze=(e,o)=>({key:e,pos:f(e),piece:o}),xn=(e,o)=>o.sort((n,r)=>G(e.pos,n.pos)-G(e.pos,r.pos))[0];function En(e,o){let n=new Map,r=[],t=new Map,i=[],a=[],u=new Map,d,s,c;for(let[l,p]of e)u.set(l,ze(l,p));for(let l of Q)d=o.pieces.get(l),s=u.get(l),d?s?$(d,s.piece)||(i.push(s),a.push(ze(l,d))):a.push(ze(l,d)):s&&i.push(s);for(let l of a)s=xn(l,i.filter(p=>$(l.piece,p.piece))),s&&(c=[s.pos[0]-l.pos[0],s.pos[1]-l.pos[1]],n.set(l.key,c.concat(c)),r.push(s.key));for(let l of i)r.includes(l.key)||t.set(l.key,l.piece);return{anims:n,fadings:t}}function Mo(e,o){let n=e.animation.current;if(n===void 0){e.dom.destroyed||e.dom.redrawNow();return}let r=1-(o-n.start)*n.frequency;if(r<=0)e.animation.current=void 0,e.dom.redrawNow();else{let t=Nn(r);for(let i of n.plan.anims.values())i[2]=i[0]*t,i[3]=i[1]*t;e.dom.redrawNow(!0),requestAnimationFrame((i=performance.now())=>Mo(e,i))}}function An(e,o){let n=new Map(o.pieces),r=e(o),t=En(n,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||Mo(o,performance.now())}else o.dom.redraw();return r}var Nn=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var Hn=["green","red","blue","yellow"];function ko(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):te(e);let n=B(o),r=N(n,v(e),e.dom.bounds());r&&(e.drawable.current={orig:r,pos:n,brush:qn(o),snapToValidMove:e.drawable.defaultSnapToValidMove},Co(e))}function Co(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let n=N(o.pos,v(e),e.dom.bounds());n||(o.snapToValidMove=!1);let r=o.snapToValidMove?wo(o.orig,o.pos,v(e),e.dom.bounds()):n;r!==o.mouseSq&&(o.mouseSq=r,o.dest=r!==o.orig?r:void 0,e.dom.redrawNow()),Co(e)}})}function Do(e,o){e.drawable.current&&(e.drawable.current.pos=B(o))}function Ko(e){let o=e.drawable.current;o&&(o.mouseSq&&Tn(e.drawable,o),$e(e))}function $e(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function xo(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),Eo(e.drawable))}var Pe=(e,o)=>e.orig===o.orig&&e.dest===o.dest,Ie=(e,o)=>e.brush===o.brush;function qn(e){let o=(e.shiftKey||e.ctrlKey)&&le(e),n=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return Hn[(o?1:0)+(n?2:0)]}function Tn(e,o){let n=e.shapes.find(r=>Pe(r,o));n&&(e.shapes=e.shapes.filter(r=>!Pe(r,o))),(!n||!Ie(n,o))&&e.shapes.push({orig:o.orig,dest:o.dest,brush:o.brush}),Eo(e)}function Eo(e){e.onChange&&e.onChange(e.shapes)}function Ao(e,o){if(!(e.trustAllEvents||o.isTrusted)||o.buttons!==void 0&&o.buttons>1||o.touches&&o.touches.length>1)return;let n=e.dom.bounds(),r=B(o),t=N(r,v(e),n);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)&&xo(e),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||Rn(e,r)))o.preventDefault();else if(o.touches)return;let u=!!e.premovable.current,d=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&ve(e,e.selected,t)?O(l=>re(l,t),e):re(e,t);let s=e.selected===t,c=Bo(e,t);if(i&&c&&s&&ho(e,t)){e.draggable.current={orig:t,piece:i,origPos:r,pos:r,started:e.draggable.autoDistance&&e.stats.dragged,element:c,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},c.cgDragging=!0,c.classList.add("dragging");let l=e.dom.elements.ghost;l&&(l.className=`ghost ${i.color} ${i.role}`,k(l,W(n)(f(t),v(e))),Y(l,!0)),je(e)}else u&&E(e),d&&A(e);e.dom.redraw()}function Rn(e,o){let n=v(e),r=e.dom.bounds(),t=Math.pow(e.touchIgnoreRadius*r.width/16,2)*2;for(let i of e.pieces.keys()){let a=de(i,n,r);if(G(a,o)<=t)return!0}return!1}function No(e,o,n,r){let t="a0";e.pieces.set(t,o),e.dom.redraw();let i=B(n);e.draggable.current={orig:t,piece:o,origPos:i,pos:i,started:!0,element:()=>Bo(e,t),originTarget:n.target,newPiece:!0,force:!!r,keyHasChanged:!1},je(e)}function je(e){requestAnimationFrame(()=>{let o=e.draggable.current;if(!o)return;e.animation.current?.plan.anims.has(o.orig)&&(e.animation.current=void 0);let n=e.pieces.get(o.orig);if(!n||!$(n,o.piece))I(e);else if(!o.started&&G(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 r=e.dom.bounds();k(o.element,[o.pos[0]-r.left-r.width/16,o.pos[1]-r.top-r.height/16]),o.keyHasChanged||=o.orig!==N(o.pos,v(e),r)}je(e)})}function Ho(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=B(o))}function qo(e,o){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 r=B(o)||n.pos,t=N(r,v(e),e.dom.bounds());t&&n.started&&n.orig!==t?n.newPiece?he(e,n.orig,t,n.force):(e.stats.ctrlKey=o.ctrlKey,Be(e,n.orig,t)&&(e.stats.dragged=!0)):n.newPiece?e.pieces.delete(n.orig):e.draggable.deleteOnDropOff&&!t&&(e.pieces.delete(n.orig),S(e.events.change)),(n.orig===n.previouslySelected||n.keyHasChanged)&&(n.orig===t||!t)?P(e):e.selectable.enabled||P(e),To(e),e.draggable.current=void 0,e.dom.redraw()}function I(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),To(e),e.dom.redraw())}function To(e){let o=e.dom.elements;o.ghost&&Y(o.ghost,!1)}function Bo(e,o){let n=e.dom.elements.board.firstChild;for(;n;){if(n.cgKey===o&&n.tagName==="PIECE")return n;n=n.nextSibling}}function Oo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{Ro(e,2),setTimeout(()=>Ro(e,void 0),120)},120)}function Ro(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function Vo(e,o){function n(){po(e),o()}return{set(r){r.orientation&&r.orientation!==e.orientation&&n(),Ge(e,r),(r.fen?O:V)(t=>we(t,r),e)},state:e,getFen:()=>Po(e.pieces),toggleOrientation:n,setPieces(r){O(t=>fo(t,r),e)},selectSquare(r,t){r?O(i=>re(i,r,t),e):e.selected&&(P(e),e.dom.redraw())},move(r,t){O(i=>Te(i,r,t),e)},newPiece(r,t){O(i=>be(i,r,t),e)},playPremove(){if(e.premovable.current){if(O(vo,e))return!0;e.dom.redraw()}return!1},playPredrop(r){if(e.predroppable.current){let t=yo(e,r);return e.dom.redraw(),t}return!1},cancelPremove(){V(E,e)},cancelPredrop(){V(A,e)},cancelMove(){V(r=>{te(r),I(r)},e)},stop(){V(r=>{Ve(r),I(r)},e)},explode(r){Oo(e,r)},setAutoShapes(r){V(t=>t.drawable.autoShapes=r,e)},setShapes(r){V(t=>t.drawable.shapes=r.slice(),e)},getKeyAtDomPos(r){return N(r,v(e),e.dom.bounds())},redrawAll:o,dragNewPiece(r,t,i){No(e,r,t,i)},destroy(){Ve(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function Lo(){return{pieces:ye(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:to()}}function Wo(){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 zo(e,o){let n=e.drawable,r=n.current,t=r&&r.mouseSq?r:void 0,i=new Map,a=e.dom.bounds(),u=n.autoShapes.filter(l=>!l.piece);for(let l of n.shapes.concat(u).concat(t?[t]:[])){if(!l.dest)continue;let p=i.get(l.dest)??new Set,m=Me(Se(f(l.orig),e.orientation),a),b=Me(Se(f(l.dest),e.orientation),a);p.add(Ze(m,b)),i.set(l.dest,p)}let d=[],s=t?n.shapes.findIndex(l=>Pe(l,t)&&Ie(l,t)):-1;for(let[l,p]of n.shapes.concat(u).entries()){let m=s!==-1&&s===l;d.push({shape:p,current:!1,pendingErase:m,hash:Fo(p,Ue(p.dest,i),!1,a,m)})}t&&s===-1&&d.push({shape:t,current:!0,hash:Fo(t,Ue(t.dest,i),!0,a,!1),pendingErase:!1});let c=d.map(l=>l.hash).join(";");c!==e.drawable.prevSvgHash&&(e.drawable.prevSvgHash=c,Vn(n,d,o),Ln(d,o,l=>Wn(e,l,n.brushes,i,a)))}function Vn(e,o,n){for(let r of[n.shapes,n.shapesBelow]){let t=r.querySelector("defs"),i=o.filter(s=>r===n.shapesBelow==!!s.shape.below),a=new Map;for(let s of i.filter(c=>c.shape.dest&&c.shape.brush)){let c=$o(e.brushes[s.shape.brush],s.shape.modifiers),{key:l,color:p}=Io(s.shape);l&&p&&a.set(l,{key:l,color:p,opacity:1,lineWidth:1}),a.set(c.key,c)}let u=new Set,d=t.firstElementChild;for(;d;)u.add(d.getAttribute("cgKey")),d=d.nextElementSibling;for(let[s,c]of a.entries())u.has(s)||t.appendChild(In(c))}}function Ln(e,o,n){for(let[r,t]of[[o.shapes,o.custom],[o.shapesBelow,o.customBelow]]){let[i,a]=[r,t].map(s=>s.querySelector("g")),u=e.filter(s=>r===o.shapesBelow==!!s.shape.below),d=new Map;for(let s of u)d.set(s.hash,!1);for(let s of[i,a]){let c=[],l=s.firstElementChild,p;for(;l;)p=l.getAttribute("cgHash"),d.has(p)?d.set(p,!0):c.push(l),l=l.nextElementSibling;for(let m of c)s.removeChild(m)}for(let s of u.filter(c=>!d.get(c.hash)))for(let c of n(s))c.isCustom?a.appendChild(c.el):i.appendChild(c.el)}}function Fo({orig:e,dest:o,brush:n,piece:r,modifiers:t,customSvg:i,label:a,below:u},d,s,c,l){return[c.width,c.height,s,l&&"pendingErase",e,o,n,d&&"-",r&&Fn(r),t&&Gn(t),i&&`custom-${Go(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Go(a.text)}`,u&&"below"].filter(p=>p).join(",")}function Fn(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function Gn(e){return[e.lineWidth,e.hilite].filter(o=>o).join(",")}function Go(e){let o=0;for(let n=0;n<e.length;n++)o=(o<<5)-o+e.charCodeAt(n)>>>0;return o.toString()}function Wn(e,{shape:o,current:n,pendingErase:r,hash:t},i,a,u){let d=Me(Se(f(o.orig),e.orientation),u),s=o.dest?Me(Se(f(o.dest),e.orientation),u):d,c=o.brush&&$o(i[o.brush],o.modifiers),l=a.get(o.dest),p=[];if(c){let m=w(y("g"),{cgHash:t});p.push({el:m}),d[0]!==s[0]||d[1]!==s[1]?m.appendChild($n(o,c,d,s,n,Ue(o.dest,a),r)):m.appendChild(zn(i[o.brush],d,n,u,r))}if(o.label){let m=o.label;m.fill??=o.brush&&i[o.brush].color;let b=o.brush?void 0:"tr";p.push({el:jn(m,t,d,s,l,b),isCustom:!0})}if(o.customSvg){let m=o.customSvg.center??"orig",[b,g]=m==="label"?Uo(d,s,l).map(D=>D-.5):m==="dest"?s:d,R=w(y("g"),{transform:`translate(${b},${g})`,cgHash:t});R.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,p.push({el:R,isCustom:!0})}return p}function zn(e,o,n,r,t){let i=Un(),a=(r.width+r.height)/(4*Math.max(r.width,r.height));return w(y("circle"),{stroke:e.color,"stroke-width":i[n?0:1],fill:"none",opacity:jo(e,n,t),cx:o[0],cy:o[1],r:a-i[1]/2})}function $n(e,o,n,r,t,i,a){function u(c){let l=_n(i&&!t),p=r[0]-n[0],m=r[1]-n[1],b=Math.atan2(m,p),g=Math.cos(b)*l,R=Math.sin(b)*l,D=Io(e);return w(y("line"),{stroke:c?D.color:o.color,"stroke-width":Zn(o,t)*(c?1.14:1),"stroke-linecap":"round","marker-end":`url(#arrowhead-${c?D.key:o.key})`,opacity:e.modifiers?.hilite&&!a?1:jo(o,t,a),x1:n[0],y1:n[1],x2:r[0]-g,y2:r[1]-R})}if(!e.modifiers?.hilite)return u(!1);let d=w(y("g"),{opacity:o.opacity}),s=w(y("g"),{filter:"url(#cg-filter-blur)"});return s.appendChild(Xn(n,r)),s.appendChild(u(!0)),d.appendChild(s),d.appendChild(u(!1)),d}function In(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 jn(e,o,n,r,t,i){let u=.4*.75**e.text.length,d=Uo(n,r,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 l=w(y("text"),{"font-size":u,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return l.innerHTML=e.text,c.appendChild(l),c}function Se(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function Ue(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 n in o)Object.prototype.hasOwnProperty.call(o,n)&&e.setAttribute(n,o[n]);return e}function $o(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(n=>n).join("")}:e}function Un(){return[3/64,4/64]}function Zn(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function Io(e){let o=e.modifiers?.hilite;return{key:o&&`hilite-${o.replace("#","")}`,color:o}}function jo(e,o,n){return(e.opacity||1)*(n?.6:o?.9:1)}function _n(e){return(e?20:10)/64}function Me(e,o){let n=Math.min(1,o.width/o.height),r=Math.min(1,o.height/o.width);return[(e[0]-3.5)*n,(3.5-e[1])*r]}function Xn(e,o){let n={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:n.from[0],y:n.from[1],width:n.to[0]-n.from[0],height:n.to[1]-n.from[1],fill:"none",stroke:"none"})}function Ze(e,o,n=!0){let r=Math.atan2(o[1]-e[1],o[0]-e[0])+Math.PI;return n?(Math.round(r*8/Math.PI)+16)%16:r}function Qn(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((n,r)=>n+r*r,0))}function Uo(e,o,n){let r=Qn(e,o),t=Ze(e,o,!1);if(n&&(r-=33/64,n.size>1)){r-=10/64;let i=Ze(e,o);(n.has((i+1)%16)||n.has((i+15)%16))&&i&1&&(r-=.4)}return[e[0]-Math.cos(t)*r,e[1]-Math.sin(t)*r].map(i=>i+.5)}function _o(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let c of Je)e.classList.toggle("orientation-"+c,o.orientation===c);e.classList.toggle("manipulable",!o.viewOnly);let n=C("cg-container");e.appendChild(n);let r=C("cg-board");n.appendChild(r);let t,i,a,u,d;if(o.drawable.visible&&([t,i]=["cg-shapes-below","cg-shapes"].map(c=>Zo(c,!0)),[a,u]=["cg-custom-below","cg-custom-svgs"].map(c=>Zo(c,!1)),d=C("cg-auto-pieces"),n.appendChild(t),n.appendChild(a),n.appendChild(i),n.appendChild(u),n.appendChild(d)),o.coordinates){let c=o.orientation==="black"?" black":"",l=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let p=o.orientation==="white"?m=>m+1:m=>8-m;z.forEach((m,b)=>n.appendChild(_e(j.map(g=>m+g),"squares rank"+p(b)+c+l)))}else n.appendChild(_e(j,"ranks"+c+l)),n.appendChild(_e(z,"files"+c))}let s;return o.draggable.enabled&&o.draggable.showGhost&&(s=C("piece","ghost"),Y(s,!1),n.appendChild(s)),{board:r,container:n,wrap:e,ghost:s,shapes:i,shapesBelow:t,custom:u,customBelow:a,autoPieces:d}}function Zo(e,o){let n=w(y("svg"),{class:e,viewBox:o?"-4 -4 8 8":"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"});return o&&n.appendChild(Wo()),n.appendChild(y("g")),n}function _e(e,o){let n=C("coords",o),r;for(let t of e)r=C("coord"),r.textContent=t,n.appendChild(r);return n}function Xo(e,o){if(!e.dropmode.active)return;E(e),A(e);let n=e.dropmode.piece;if(n){e.pieces.set("a0",n);let r=B(o),t=r&&N(r,v(e),e.dom.bounds());t&&he(e,"a0",t)}e.dom.redraw()}function Yo(e,o){let n=e.dom.elements.board;if("ResizeObserver"in window&&new ResizeObserver(o).observe(e.dom.elements.wrap),(e.disableContextMenu||e.drawable.enabled)&&n.addEventListener("contextmenu",t=>t.preventDefault()),e.viewOnly)return;let r=Jn(e);n.addEventListener("touchstart",r,{passive:!1}),n.addEventListener("mousedown",r,{passive:!1})}function Jo(e,o){let n=[];if("ResizeObserver"in window||n.push(ie(document.body,"chessground.resize",o)),!e.viewOnly){let r=Qo(e,Ho,Do),t=Qo(e,qo,Ko);for(let a of["touchmove","mousemove"])n.push(ie(document,a,r));for(let a of["touchend","mouseup"])n.push(ie(document,a,t));let i=()=>e.dom.bounds.clear();n.push(ie(document,"scroll",i,{capture:!0,passive:!0})),n.push(ie(window,"resize",i,{passive:!0}))}return()=>n.forEach(r=>r())}function ie(e,o,n,r){return e.addEventListener(o,n,r),()=>e.removeEventListener(o,n,r)}var Jn=e=>o=>{e.draggable.current?I(e):e.drawable.current?$e(e):o.shiftKey||le(o)?e.drawable.enabled&&ko(e,o):e.viewOnly||(e.dropmode.active?Xo(e,o):Ao(e,o))},Qo=(e,o,n)=>r=>{e.drawable.current?e.drawable.enabled&&n(e,r):e.viewOnly||o(e,r)};function on(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.board,t=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,u=i?i.plan.fadings:new Map,d=e.draggable.current,s=or(e),c=new Set,l=new Set,p=new Map,m=new Map,b,g,R,D,K,_,ke,H,Ce,se;for(g=r.firstChild;g;){if(b=g.cgKey,rn(g))if(R=t.get(b),K=a.get(b),_=u.get(b),D=g.cgPiece,g.cgDragging&&(!d||d.orig!==b)&&(g.classList.remove("dragging"),k(g,n(f(b),o)),g.cgDragging=!1),!_&&g.cgFading&&(g.cgFading=!1,g.classList.remove("fading")),R){if(K&&g.cgAnimating&&D===ae(R)){let h=f(b);h[0]+=K[2],h[1]+=K[3],g.classList.add("anim"),k(g,n(h,o))}else g.cgAnimating&&(g.cgAnimating=!1,g.classList.remove("anim"),k(g,n(f(b),o)),e.addPieceZIndex&&(g.style.zIndex=Xe(f(b),o)));D===ae(R)&&(!_||!g.cgFading)?c.add(b):_&&D===ae(_)?(g.classList.add("fading"),g.cgFading=!0):Qe(p,D,g)}else Qe(p,D,g);else if(tn(g)){let h=g.className;s.get(b)===h?l.add(b):Qe(m,h,g)}g=g.nextSibling}for(let[h,X]of s)if(!l.has(h)){Ce=m.get(X),se=Ce&&Ce.pop();let q=n(f(h),o);if(se)se.cgKey=h,k(se,q);else{let T=C("square",X);T.cgKey=h,k(T,q),r.insertBefore(T,r.firstChild)}}for(let[h,X]of t)if(K=a.get(h),!c.has(h))if(ke=p.get(ae(X)),H=ke&&ke.pop(),H){H.cgKey=h,H.cgFading&&(H.classList.remove("fading"),H.cgFading=!1);let q=f(h);e.addPieceZIndex&&(H.style.zIndex=Xe(q,o)),K&&(H.cgAnimating=!0,H.classList.add("anim"),q[0]+=K[2],q[1]+=K[3]),k(H,n(q,o))}else{let q=ae(X),T=C("piece",q),ce=f(h);T.cgPiece=q,T.cgKey=h,K&&(T.cgAnimating=!0,ce[0]+=K[2],ce[1]+=K[3]),k(T,n(ce,o)),e.addPieceZIndex&&(T.style.zIndex=Xe(ce,o)),r.appendChild(T)}for(let h of p.values())en(e,h);for(let h of m.values())en(e,h)}function nn(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.board.firstChild;for(;r;)(rn(r)&&!r.cgAnimating||tn(r))&&k(r,n(f(r.cgKey),o)),r=r.nextSibling}function Ye(e){let o=e.dom.elements.wrap.getBoundingClientRect(),n=e.dom.elements.container,r=o.height/o.width,t=Math.floor(o.width*window.devicePixelRatio/8)*8/window.devicePixelRatio,i=t*r;n.style.width=t+"px",n.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 rn=e=>e.tagName==="PIECE",tn=e=>e.tagName==="SQUARE";function en(e,o){for(let n of o)e.dom.elements.board.removeChild(n)}function Xe(e,o){let r=e[1];return`${o?10-r:3+r}`}var ae=e=>`${e.color} ${e.role}`;function or(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let t of e.lastMove)L(o,t,"last-move");if(e.check&&e.highlight.check&&L(o,e.check,"check"),e.selected&&(L(o,e.selected,"selected"),e.movable.showDests)){let t=e.movable.dests?.get(e.selected);if(t)for(let a of t)L(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)L(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let n=e.premovable.current;if(n)for(let t of n)L(o,t,"current-premove");else e.predroppable.current&&L(o,e.predroppable.current.key,"current-premove");let r=e.exploding;if(r)for(let t of r.keys)L(o,t,"exploding"+r.stage);return e.highlight.custom&&e.highlight.custom.forEach((t,i)=>{L(o,i,t)}),o}function L(e,o,n){let r=e.get(o);r?e.set(o,`${r} ${n}`):e.set(o,n)}function Qe(e,o,n){let r=e.get(o);r?r.push(n):e.set(o,[n])}function an(e,o,n){let r=new Map,t=[];for(let u of e)r.set(u.hash,!1);let i=o.firstElementChild,a;for(;i;)a=i.getAttribute("cgHash"),r.has(a)?r.set(a,!0):t.push(i),i=i.nextElementSibling;for(let u of t)o.removeChild(u);for(let u of e)r.get(u.hash)||o.appendChild(n(u))}function sn(e,o){let r=e.drawable.autoShapes.filter(t=>t.piece).map(t=>({shape:t,hash:rr(t),current:!1,pendingErase:!1}));an(r,o,t=>nr(e,t,e.dom.bounds()))}function cn(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.autoPieces?.firstChild;for(;r;)Ke(r,n(f(r.cgKey),o),r.cgScale),r=r.nextSibling}function nr(e,{shape:o,hash:n},r){let t=o.orig,i=o.piece?.role,a=o.piece?.color,u=o.piece?.scale,d=C("piece",`${i} ${a}`);return d.setAttribute("cgHash",n),d.cgKey=t,d.cgScale=u,Ke(d,W(r)(f(t),v(e)),u),d}var rr=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function dt({el:e,config:o}){return ir(e,o)}function ir(e,o){let n=Lo();we(n,o||{});function r(){let t="dom"in n?n.dom.unbind:void 0,i=_o(e,n),a=ro(()=>i.board.getBoundingClientRect()),u=c=>{on(s),i.autoPieces&&sn(s,i.autoPieces),!c&&i.shapes&&zo(s,i)},d=()=>{Ye(s),nn(s),i.autoPieces&&cn(s)},s=n;return s.dom={elements:i,bounds:a,redraw:ar(u),redrawNow:u,unbind:t},s.drawable.prevSvgHash="",Ye(s),u(!1),Yo(s,d),t||(s.dom.unbind=Jo(s,d)),s.events.insert&&s.events.insert(i),s}return Vo(r(),r)}function ar(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{ir as Chessground,dt as initModule};
|
|
1
|
+
var eo=["white","black"];var z=["a","b","c","d","e","f","g","h"],j=["1","2","3","4","5","6","7","8"];var no=[...j].reverse(),Q=z.flatMap(e=>j.map(o=>e+o)),M=e=>e.every(o=>o>=0&&o<=7)?Q[8*e[0]+e[1]]:void 0,F=e=>M(e),f=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var De=Q.map(f),ro=Q.map((e,o)=>({key:e,pos:De[o]}));function Ke(e){let o,n=()=>(o===void 0&&(o=e()),o);return n.clear=()=>{o=void 0},n}var to=()=>{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",G=(e,o)=>(e[0]-o[0])**2+(e[1]-o[1])**2,$=(e,o)=>e.role===o.role&&e.color===o.color,io=(e,o)=>e[0]===o[0]&&e[1]===o[1],W=e=>(o,n)=>[(n?o[0]:7-o[0])*e.width/8,(n?7-o[1]:o[1])*e.height/8],k=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},xe=(e,o,n=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${n})`},Y=(e,o)=>{e.style.visibility=o?"visible":"hidden"},B=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]},ln=Ke(()=>!("ontouchstart"in window)&&["macintosh","firefox"].every(e=>navigator.userAgent.toLowerCase().includes(e))),le=e=>e.button===2&&!(e.ctrlKey&&ln()),C=(e,o)=>{let n=document.createElement(e);return o&&(n.className=o),n};function de(e,o,n){let r=f(e);return o||(r[0]=7-r[0],r[1]=7-r[1]),[n.left+n.width*r[0]/8+n.width/16,n.top+n.height*(7-r[1])/8+n.height/16]}var x=(e,o)=>Math.abs(e-o),J=(e,o,n,r)=>x(e,n)*x(o,r)===2,ue=(e,o,n,r)=>e===n!=(o===r),pe=(e,o,n,r)=>x(e,n)===x(o,r)&&e!==n,fe=(e,o,n,r)=>ue(e,o,n,r)||pe(e,o,n,r),Ee=(e,o,n,r)=>Math.max(x(e,n),x(o,r))===1,Ae=(e,o,n,r,t)=>x(e,n)===1&&r===o+(t?1:-1),Ne=(e,o,n,r,t)=>{let i=t?1:-1;return e===n&&(r===o+i||r===o+2*i&&(t?o<=1:o>=6))},ee=(e,o,n,r)=>{let t=n-e,i=r-o;if(t&&i&&Math.abs(t)!==Math.abs(i))return[];let a=Math.sign(t),u=Math.sign(i),d=[],s=e+a,c=o+u;for(;s!==n||c!==r;)d.push([s,c]),s+=a,c+=u;return d.map(M).filter(l=>l!==void 0)},ao=e=>{let o=f(e),n=[];return o[0]>0&&n.push([o[0]-1,o[1]]),o[0]<7&&n.push([o[0]+1,o[1]]),n.map(M).filter(r=>r!==void 0)},oe=(e,o)=>{let n=f(e);return n[1]+=o,M(n)};var Z=e=>e.friendlies.has(e.dest.key),dn=e=>e.enemies.has(e.dest.key),so=(e,o,n)=>ee(...e,...o).some(r=>n.has(r)),co=(e,o,n)=>{let r=n.enemies.get(e);if(r?.role!=="pawn")return!1;let t=r.color==="white"?1:-1,i=f(e),a=f(o);return Ne(...i,...a,r.color==="white")&&!so(i,[a[0],a[1]+t],n.allPieces)},un=(e,o,n)=>{let r=n.enemies.get(e);return r?.role==="pawn"&&Ae(...f(e),...f(o),r.color==="white")&&(n.friendlies.has(o)||me(oe(o,r.color==="white"?-1:1),n.friendlies,n.enemies,n.lastMove))},pn=e=>[...e.enemies.keys()].some(o=>co(o,e.dest.key,e)),He=(e,o)=>{let n=e.dest.pos;return[...e.enemies].some(([r,t])=>{let i=f(r);return!o?.includes(t.role)&&(t.role==="pawn"&&Ae(...i,...n,t.color==="white")||t.role==="knight"&&J(...i,...n)||t.role==="bishop"&&pe(...i,...n)||t.role==="rook"&&ue(...i,...n)||t.role==="queen"&&fe(...i,...n)||t.role==="king"&&Ee(...i,...n))&&(!["bishop","rook","queen"].includes(t.role)||!so(i,n,e.allPieces))})},ge=e=>Z(e)&&(me(e.dest.key,e.friendlies,e.enemies,e.lastMove)||He(e)),me=(e,o,n,r)=>{if(!e||r&&e!==r[1])return!1;let t=f(e),i=o.get(e);return i?.role==="pawn"&&t[1]===(i.color==="white"?3:4)&&(!r||x(f(r[0])[1],t[1])===2)&&[1,-1].some(a=>{let u=M([t[0]+a,t[1]]);return!!u&&n.get(u)?.role==="pawn"})},fn=(e,o)=>{if(e.unrestrictedPremoves)return!0;let n=ee(...e.orig.pos,...e.dest.pos);o&&n.push(e.dest.key);let r=n.filter(a=>e.friendlies.has(a));if(!r.length)return!0;let t=r[0],i=oe(t,e.color==="white"?-1:1);return r.length===1&&me(t,e.friendlies,e.enemies,e.lastMove)&&!!i&&!n.includes(i)},gn=(e,o)=>{if(e.unrestrictedPremoves)return!0;let n=ee(...e.orig.pos,...e.dest.pos);o&&n.push(e.dest.key);let r=n.filter(c=>e.enemies.has(c));if(r.length>1)return!1;if(!r.length)return!0;let t=r[0],i=e.enemies.get(t);if(!i||i.role!=="pawn")return!0;let a=i.color==="white"?1:-1,u=oe(t,a),d=u?[...ao(u).filter(c=>un(t,c,e)),...[u,oe(u,a)].filter(c=>!!c).filter(c=>co(t,c,e))]:[],s=[...n,e.orig.key];return d.some(c=>!s.includes(c))},qe=(e,o)=>fn(e,o)&&gn(e,o),mn=e=>{let o=e.color==="white"?1:-1;return x(e.orig.pos[0],e.dest.pos[0])>1?!1:x(e.orig.pos[0],e.dest.pos[0])?e.dest.pos[1]!==e.orig.pos[1]+o?!1:e.unrestrictedPremoves||dn(e)?!0:Z(e)?He(e):pn(e)||me(M([e.dest.pos[0],e.dest.pos[1]+o]),e.friendlies,e.enemies,e.lastMove)||He(e,["pawn"]):Ne(...e.orig.pos,...e.dest.pos,e.color==="white")&&qe(e,!0)},bn=e=>J(...e.orig.pos,...e.dest.pos)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),lo=e=>pe(...e.orig.pos,...e.dest.pos)&&qe(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),uo=e=>ue(...e.orig.pos,...e.dest.pos)&&qe(e,!1)&&(e.unrestrictedPremoves||!Z(e)||ge(e)),hn=e=>lo(e)||uo(e),vn=e=>Ee(...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||$(o,{role:"rook",color:e.color}))),yn={pawn:mn,knight:bn,bishop:lo,rook:uo,queen:hn,king:vn};function Te(e,o){let n=e.pieces,r=e.premovable.castle,t=!!e.premovable.unrestrictedPremoves,i=n.get(o);if(!i||i.color===e.turnColor)return[];let a=i.color,u=new Map([...n].filter(([p,m])=>m.color===a)),d=new Map([...n].filter(([p,m])=>m.color===U(a))),s={key:o,pos:f(o)},c=p=>yn[i.role](p)&&e.premovable.additionalPremoveRequirements(p),l={orig:s,role:i.role,allPieces:n,friendlies:u,enemies:d,unrestrictedPremoves:t,color:a,canCastle:r,rookFilesFriendlies:Array.from(n).filter(([p,m])=>p[1]===(a==="white"?"1":"8")&&m.color===a&&m.role==="rook").map(([p])=>f(p)[0]),lastMove:e.lastMove};return ro.filter(p=>c({...l,dest:p})).map(p=>p.key)}function S(e,...o){e&&setTimeout(()=>e(...o),1)}function po(e){e.orientation=U(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function fo(e,o){for(let[n,r]of o)r?e.pieces.set(n,r):e.pieces.delete(n)}function go(e,o){if(e.check=void 0,o===!0&&(o=e.turnColor),o)for(let[n,r]of e.pieces)r.role==="king"&&r.color===o&&(e.check=n)}function wn(e,o,n,r){A(e),e.premovable.current=[o,n],S(e.premovable.events.set,o,n,r)}function E(e){e.premovable.current&&(e.premovable.current=void 0,S(e.premovable.events.unset))}function Pn(e,o,n){E(e),e.predroppable.current={role:o,key:n},S(e.predroppable.events.set,o,n)}function A(e){let o=e.predroppable;o.current&&(o.current=void 0,S(o.events.unset))}function Sn(e,o,n){if(!e.autoCastle)return!1;let r=e.pieces.get(o);if(!r||r.role!=="king")return!1;let t=f(o),i=f(n);if(t[1]!==0&&t[1]!==7||t[1]!==i[1])return!1;t[0]===4&&!e.pieces.has(n)&&(i[0]===6?n=F([7,i[1]]):i[0]===2&&(n=F([0,i[1]])));let a=e.pieces.get(n);return!a||a.color!==r.color||a.role!=="rook"?!1:(e.pieces.delete(o),e.pieces.delete(n),t[0]<i[0]?(e.pieces.set(F([6,i[1]]),r),e.pieces.set(F([5,i[1]]),a)):(e.pieces.set(F([2,i[1]]),r),e.pieces.set(F([3,i[1]]),a)),!0)}function Be(e,o,n){let r=e.pieces.get(o),t=e.pieces.get(n);if(o===n||!r)return!1;let i=t&&t.color!==r.color?t:void 0;return n===e.selected&&P(e),S(e.events.move,o,n,i),Sn(e,o,n)||(e.pieces.set(n,r),e.pieces.delete(o)),e.lastMove=[o,n],e.check=void 0,S(e.events.change),i||!0}function be(e,o,n,r){if(e.pieces.has(n))if(r)e.pieces.delete(n);else return!1;return S(e.events.dropNewPiece,o,n),e.pieces.set(n,o),e.lastMove=[n],e.check=void 0,S(e.events.change),e.movable.dests=void 0,e.turnColor=U(e.turnColor),!0}function mo(e,o,n){let r=Be(e,o,n);return r&&(e.movable.dests=void 0,e.turnColor=U(e.turnColor),e.animation.current=void 0),r}function Re(e,o,n){if(ve(e,o,n)){let r=mo(e,o,n);if(r){let t=e.hold.stop();P(e);let i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:t};return r!==!0&&(i.captured=r),S(e.movable.events.after,o,n,i),!0}}else if(kn(e,o,n))return wn(e,o,n,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function he(e,o,n,r){let t=e.pieces.get(o);t&&(Mn(e,o,n)||r)?(e.pieces.delete(o),be(e,t,n,r),S(e.movable.events.afterNewPiece,t.role,n,{premove:!1,predrop:!1})):t&&Cn(e,o,n)?Pn(e,t.role,n):(E(e),A(e)),e.pieces.delete(o),P(e)}function re(e,o,n){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||n)&&e.selected!==o&&Re(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(bo(e,o)||Ve(e,o))&&(Oe(e,o),e.hold.start())}function Oe(e,o){e.selected=o,Ve(e,o)?e.premovable.customDests||(e.premovable.dests=Te(e,o)):e.premovable.dests=void 0}function P(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function bo(e,o){let n=e.pieces.get(o);return!!n&&(e.movable.color==="both"||e.movable.color===n.color&&e.turnColor===n.color)}var ve=(e,o,n)=>o!==n&&bo(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(n));function Mn(e,o,n){let r=e.pieces.get(o);return!!r&&(o===n||!e.pieces.has(n))&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}function Ve(e,o){let n=e.pieces.get(o);return!!n&&e.premovable.enabled&&e.movable.color===n.color&&e.turnColor!==n.color}var kn=(e,o,n)=>o!==n&&Ve(e,o)&&(e.premovable.customDests?.get(o)??Te(e,o)).includes(n);function Cn(e,o,n){let r=e.pieces.get(o),t=e.pieces.get(n);return!!r&&(!t||t.color!==e.movable.color)&&e.predroppable.enabled&&(r.role!=="pawn"||n[1]!=="1"&&n[1]!=="8")&&e.movable.color===r.color&&e.turnColor!==r.color}function ho(e,o){let n=e.pieces.get(o);return!!n&&e.draggable.enabled&&(e.movable.color==="both"||e.movable.color===n.color&&(e.turnColor===n.color||e.premovable.enabled))}function vo(e){let o=e.premovable.current;if(!o)return!1;let n=o[0],r=o[1],t=!1;if(ve(e,n,r)){let i=mo(e,n,r);if(i){let a={premove:!0};i!==!0&&(a.captured=i),S(e.movable.events.after,n,r,a),t=!0}}return E(e),t}function yo(e,o){let n=e.predroppable.current,r=!1;if(!n)return!1;if(o(n)){let t={role:n.role,color:e.movable.color};be(e,t,n.key)&&(S(e.movable.events.afterNewPiece,n.role,n.key,{premove:!1,predrop:!0}),r=!0)}return A(e),r}function te(e){E(e),A(e),P(e)}function Le(e){e.movable.color=e.movable.dests=e.animation.current=void 0,te(e)}function N(e,o,n){let r=Math.floor(8*(e[0]-n.left)/n.width);o||(r=7-r);let t=7-Math.floor(8*(e[1]-n.top)/n.height);return o||(t=7-t),r>=0&&r<8&&t>=0&&t<8?M([r,t]):void 0}function wo(e,o,n,r){let t=f(e),i=De.filter(s=>io(t,s)||fe(t[0],t[1],s[0],s[1])||J(t[0],t[1],s[0],s[1])),u=i.map(s=>de(F(s),n,r)).map(s=>G(o,s)),[,d]=u.reduce((s,c,l)=>s[0]<c?s:[c,l],[u[0],0]);return M(i[d])}var v=e=>e.orientation==="white";var Ge="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",Dn={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},Kn={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function ye(e){e==="start"&&(e=Ge);let o=new Map,n=7,r=0;for(let t of e)switch(t){case" ":case"[":return o;case"/":if(--n,n<0)return o;r=0;break;case"~":{let i=M([r-1,n]),a=i&&o.get(i);a&&(a.promoted=!0);break}default:{let i=t.charCodeAt(0);if(i<57)r+=i-48;else{let a=t.toLowerCase(),u=M([r,n]);u&&o.set(u,{role:Dn[a],color:t===a?"black":"white"}),++r}}}return o}function Po(e){return no.map(o=>z.map(n=>{let r=e.get(n+o);if(r){let t=Kn[r.role];return r.color==="white"&&(t=t.toUpperCase()),r.promoted&&(t+="~"),t}else return"1"}).join("")).join("/").replace(/1{2,}/g,o=>o.length.toString())}function We(e,o){o.animation&&(ze(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=[]),ze(e,o),o.fen&&(e.pieces=ye(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&go(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),We(e,o),!e.movable.rookCastle&&e.movable.dests){let n=e.movable.color==="white"?"1":"8",r="e"+n,t=e.movable.dests.get(r),i=e.pieces.get(r);if(!t||!i||i.role!=="king")return;e.movable.dests.set(r,t.filter(a=>!(a==="a"+n&&t.includes("c"+n))&&!(a==="h"+n&&t.includes("g"+n))))}}function ze(e,o){for(let n in o)n==="__proto__"||n==="constructor"||!Object.prototype.hasOwnProperty.call(o,n)||(Object.prototype.hasOwnProperty.call(e,n)&&So(e[n])&&So(o[n])?ze(e[n],o[n]):e[n]=o[n])}function So(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?Nn(e,o):V(e,o);function V(e,o){let n=e(o);return o.dom.redraw(),n}var $e=(e,o)=>({key:e,pos:f(e),piece:o}),En=(e,o)=>o.sort((n,r)=>G(e.pos,n.pos)-G(e.pos,r.pos))[0];function An(e,o){let n=new Map,r=[],t=new Map,i=[],a=[],u=new Map,d,s,c;for(let[l,p]of e)u.set(l,$e(l,p));for(let l of Q)d=o.pieces.get(l),s=u.get(l),d?s?$(d,s.piece)||(i.push(s),a.push($e(l,d))):a.push($e(l,d)):s&&i.push(s);for(let l of a)s=En(l,i.filter(p=>$(l.piece,p.piece))),s&&(c=[s.pos[0]-l.pos[0],s.pos[1]-l.pos[1]],n.set(l.key,c.concat(c)),r.push(s.key));for(let l of i)r.includes(l.key)||t.set(l.key,l.piece);return{anims:n,fadings:t}}function Mo(e,o){let n=e.animation.current;if(n===void 0){e.dom.destroyed||e.dom.redrawNow();return}let r=1-(o-n.start)*n.frequency;if(r<=0)e.animation.current=void 0,e.dom.redrawNow();else{let t=Hn(r);for(let i of n.plan.anims.values())i[2]=i[0]*t,i[3]=i[1]*t;e.dom.redrawNow(!0),requestAnimationFrame((i=performance.now())=>Mo(e,i))}}function Nn(e,o){let n=new Map(o.pieces),r=e(o),t=An(n,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||Mo(o,performance.now())}else o.dom.redraw();return r}var Hn=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var qn=["green","red","blue","yellow"];function ko(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):te(e);let n=B(o),r=N(n,v(e),e.dom.bounds());r&&(e.drawable.current={orig:r,pos:n,brush:Tn(o),snapToValidMove:e.drawable.defaultSnapToValidMove},Co(e))}function Co(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let n=N(o.pos,v(e),e.dom.bounds());n||(o.snapToValidMove=!1);let r=o.snapToValidMove?wo(o.orig,o.pos,v(e),e.dom.bounds()):n;r!==o.mouseSq&&(o.mouseSq=r,o.dest=r!==o.orig?r:void 0,e.dom.redrawNow()),Co(e)}})}function Do(e,o){e.drawable.current&&(e.drawable.current.pos=B(o))}function Ko(e){let o=e.drawable.current;o&&(o.mouseSq&&Bn(e.drawable,o),Ie(e))}function Ie(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function xo(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),Eo(e.drawable))}var Pe=(e,o)=>e.orig===o.orig&&e.dest===o.dest,je=(e,o)=>e.brush===o.brush;function Tn(e){let o=(e.shiftKey||e.ctrlKey)&&le(e),n=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return qn[(o?1:0)+(n?2:0)]}function Bn(e,o){let n=e.shapes.find(r=>Pe(r,o));n&&(e.shapes=e.shapes.filter(r=>!Pe(r,o))),(!n||!je(n,o))&&e.shapes.push({orig:o.orig,dest:o.dest,brush:o.brush}),Eo(e)}function Eo(e){e.onChange&&e.onChange(e.shapes)}function Ao(e,o){if(!(e.trustAllEvents||o.isTrusted)||o.buttons!==void 0&&o.buttons>1||o.touches&&o.touches.length>1)return;let n=e.dom.bounds(),r=B(o),t=N(r,v(e),n);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)&&xo(e),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||On(e,r)))o.preventDefault();else if(o.touches)return;let u=!!e.premovable.current,d=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&ve(e,e.selected,t)?O(l=>re(l,t),e):re(e,t);let s=e.selected===t,c=Bo(e,t);if(i&&c&&s&&ho(e,t)){e.draggable.current={orig:t,piece:i,origPos:r,pos:r,started:e.draggable.autoDistance&&e.stats.dragged,element:c,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},c.cgDragging=!0,c.classList.add("dragging");let l=e.dom.elements.ghost;l&&(l.className=`ghost ${i.color} ${i.role}`,k(l,W(n)(f(t),v(e))),Y(l,!0)),Ue(e)}else u&&E(e),d&&A(e);e.dom.redraw()}function On(e,o){let n=v(e),r=e.dom.bounds(),t=Math.pow(e.touchIgnoreRadius*r.width/16,2)*2;for(let i of e.pieces.keys()){let a=de(i,n,r);if(G(a,o)<=t)return!0}return!1}function No(e,o,n,r){let t="a0";e.pieces.set(t,o),e.dom.redraw();let i=B(n);e.draggable.current={orig:t,piece:o,origPos:i,pos:i,started:!0,element:()=>Bo(e,t),originTarget:n.target,newPiece:!0,force:!!r,keyHasChanged:!1},Ue(e)}function Ue(e){requestAnimationFrame(()=>{let o=e.draggable.current;if(!o)return;e.animation.current?.plan.anims.has(o.orig)&&(e.animation.current=void 0);let n=e.pieces.get(o.orig);if(!n||!$(n,o.piece))I(e);else if(!o.started&&G(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 r=e.dom.bounds();k(o.element,[o.pos[0]-r.left-r.width/16,o.pos[1]-r.top-r.height/16]),o.keyHasChanged||=o.orig!==N(o.pos,v(e),r)}Ue(e)})}function Ho(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=B(o))}function qo(e,o){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 r=B(o)||n.pos,t=N(r,v(e),e.dom.bounds());t&&n.started&&n.orig!==t?n.newPiece?he(e,n.orig,t,n.force):(e.stats.ctrlKey=o.ctrlKey,Re(e,n.orig,t)&&(e.stats.dragged=!0)):n.newPiece?e.pieces.delete(n.orig):e.draggable.deleteOnDropOff&&!t&&(e.pieces.delete(n.orig),S(e.events.change)),(n.orig===n.previouslySelected||n.keyHasChanged)&&(n.orig===t||!t)?P(e):e.selectable.enabled||P(e),To(e),e.draggable.current=void 0,e.dom.redraw()}function I(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),To(e),e.dom.redraw())}function To(e){let o=e.dom.elements;o.ghost&&Y(o.ghost,!1)}function Bo(e,o){let n=e.dom.elements.board.firstChild;for(;n;){if(n.cgKey===o&&n.tagName==="PIECE")return n;n=n.nextSibling}}function Oo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{Ro(e,2),setTimeout(()=>Ro(e,void 0),120)},120)}function Ro(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function Vo(e,o){function n(){po(e),o()}return{set(r){r.orientation&&r.orientation!==e.orientation&&n(),We(e,r),(r.fen?O:V)(t=>we(t,r),e)},state:e,getFen:()=>Po(e.pieces),toggleOrientation:n,setPieces(r){O(t=>fo(t,r),e)},selectSquare(r,t){r?O(i=>re(i,r,t),e):e.selected&&(P(e),e.dom.redraw())},move(r,t){O(i=>Be(i,r,t),e)},newPiece(r,t){O(i=>be(i,r,t),e)},playPremove(){if(e.premovable.current){if(O(vo,e))return!0;e.dom.redraw()}return!1},playPredrop(r){if(e.predroppable.current){let t=yo(e,r);return e.dom.redraw(),t}return!1},cancelPremove(){V(E,e)},cancelPredrop(){V(A,e)},cancelMove(){V(r=>{te(r),I(r)},e)},stop(){V(r=>{Le(r),I(r)},e)},explode(r){Oo(e,r)},setAutoShapes(r){V(t=>t.drawable.autoShapes=r,e)},setShapes(r){V(t=>t.drawable.shapes=r.slice(),e)},getKeyAtDomPos(r){return N(r,v(e),e.dom.bounds())},redrawAll:o,dragNewPiece(r,t,i){No(e,r,t,i)},destroy(){Le(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function Lo(){return{pieces:ye(Ge),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:to()}}function Wo(){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 zo(e,o){let n=e.drawable,r=n.current,t=r&&r.mouseSq?r:void 0,i=new Map,a=e.dom.bounds(),u=n.autoShapes.filter(l=>!l.piece);for(let l of n.shapes.concat(u).concat(t?[t]:[])){if(!l.dest)continue;let p=i.get(l.dest)??new Set,m=Me(Se(f(l.orig),e.orientation),a),b=Me(Se(f(l.dest),e.orientation),a);p.add(_e(m,b)),i.set(l.dest,p)}let d=[],s=t?n.shapes.findIndex(l=>Pe(l,t)&&je(l,t)):-1;for(let[l,p]of n.shapes.concat(u).entries()){let m=s!==-1&&s===l;d.push({shape:p,current:!1,pendingErase:m,hash:Fo(p,Ze(p.dest,i),!1,a,m)})}t&&s===-1&&d.push({shape:t,current:!0,hash:Fo(t,Ze(t.dest,i),!0,a,!1),pendingErase:!1});let c=d.map(l=>l.hash).join(";");c!==e.drawable.prevSvgHash&&(e.drawable.prevSvgHash=c,Ln(n,d,o),Fn(d,o,l=>zn(e,l,n.brushes,i,a)))}function Ln(e,o,n){for(let r of[n.shapes,n.shapesBelow]){let t=r.querySelector("defs"),i=o.filter(s=>r===n.shapesBelow==!!s.shape.below),a=new Map;for(let s of i.filter(c=>c.shape.dest&&c.shape.brush)){let c=$o(e.brushes[s.shape.brush],s.shape.modifiers),{key:l,color:p}=Io(s.shape);l&&p&&a.set(l,{key:l,color:p,opacity:1,lineWidth:1}),a.set(c.key,c)}let u=new Set,d=t.firstElementChild;for(;d;)u.add(d.getAttribute("cgKey")),d=d.nextElementSibling;for(let[s,c]of a.entries())u.has(s)||t.appendChild(jn(c))}}function Fn(e,o,n){for(let[r,t]of[[o.shapes,o.custom],[o.shapesBelow,o.customBelow]]){let[i,a]=[r,t].map(s=>s.querySelector("g")),u=e.filter(s=>r===o.shapesBelow==!!s.shape.below),d=new Map;for(let s of u)d.set(s.hash,!1);for(let s of[i,a]){let c=[],l=s.firstElementChild,p;for(;l;)p=l.getAttribute("cgHash"),d.has(p)?d.set(p,!0):c.push(l),l=l.nextElementSibling;for(let m of c)s.removeChild(m)}for(let s of u.filter(c=>!d.get(c.hash)))for(let c of n(s))c.isCustom?a.appendChild(c.el):i.appendChild(c.el)}}function Fo({orig:e,dest:o,brush:n,piece:r,modifiers:t,customSvg:i,label:a,below:u},d,s,c,l){return[c.width,c.height,s,l&&"pendingErase",e,o,n,d&&"-",r&&Gn(r),t&&Wn(t),i&&`custom-${Go(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Go(a.text)}`,u&&"below"].filter(p=>p).join(",")}function Gn(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function Wn(e){return[e.lineWidth,e.hilite].filter(o=>o).join(",")}function Go(e){let o=0;for(let n=0;n<e.length;n++)o=(o<<5)-o+e.charCodeAt(n)>>>0;return o.toString()}function zn(e,{shape:o,current:n,pendingErase:r,hash:t},i,a,u){let d=Me(Se(f(o.orig),e.orientation),u),s=o.dest?Me(Se(f(o.dest),e.orientation),u):d,c=o.brush&&$o(i[o.brush],o.modifiers),l=a.get(o.dest),p=[];if(c){let m=w(y("g"),{cgHash:t});p.push({el:m}),d[0]!==s[0]||d[1]!==s[1]?m.appendChild(In(o,c,d,s,n,Ze(o.dest,a),r)):m.appendChild($n(i[o.brush],d,n,u,r))}if(o.label){let m=o.label;m.fill??=o.brush&&i[o.brush].color;let b=o.brush?void 0:"tr";p.push({el:Un(m,t,d,s,l,b),isCustom:!0})}if(o.customSvg){let m=o.customSvg.center??"orig",[b,g]=m==="label"?Uo(d,s,l).map(D=>D-.5):m==="dest"?s:d,R=w(y("g"),{transform:`translate(${b},${g})`,cgHash:t});R.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,p.push({el:R,isCustom:!0})}return p}function $n(e,o,n,r,t){let i=Zn(),a=(r.width+r.height)/(4*Math.max(r.width,r.height));return w(y("circle"),{stroke:e.color,"stroke-width":i[n?0:1],fill:"none",opacity:jo(e,n,t),cx:o[0],cy:o[1],r:a-i[1]/2})}function In(e,o,n,r,t,i,a){function u(c){let l=Xn(i&&!t),p=r[0]-n[0],m=r[1]-n[1],b=Math.atan2(m,p),g=Math.cos(b)*l,R=Math.sin(b)*l,D=Io(e);return w(y("line"),{stroke:c?D.color:o.color,"stroke-width":_n(o,t)*(c?1.14:1),"stroke-linecap":"round","marker-end":`url(#arrowhead-${c?D.key:o.key})`,opacity:e.modifiers?.hilite&&!a?1:jo(o,t,a),x1:n[0],y1:n[1],x2:r[0]-g,y2:r[1]-R})}if(!e.modifiers?.hilite)return u(!1);let d=w(y("g"),{opacity:o.opacity}),s=w(y("g"),{filter:"url(#cg-filter-blur)"});return s.appendChild(Qn(n,r)),s.appendChild(u(!0)),d.appendChild(s),d.appendChild(u(!1)),d}function jn(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 Un(e,o,n,r,t,i){let u=.4*.75**e.text.length,d=Uo(n,r,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 l=w(y("text"),{"font-size":u,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return l.innerHTML=e.text,c.appendChild(l),c}function Se(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function Ze(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 n in o)Object.prototype.hasOwnProperty.call(o,n)&&e.setAttribute(n,o[n]);return e}function $o(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(n=>n).join("")}:e}function Zn(){return[3/64,4/64]}function _n(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function Io(e){let o=e.modifiers?.hilite;return{key:o&&`hilite-${o.replace("#","")}`,color:o}}function jo(e,o,n){return(e.opacity||1)*(n?.6:o?.9:1)}function Xn(e){return(e?20:10)/64}function Me(e,o){let n=Math.min(1,o.width/o.height),r=Math.min(1,o.height/o.width);return[(e[0]-3.5)*n,(3.5-e[1])*r]}function Qn(e,o){let n={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:n.from[0],y:n.from[1],width:n.to[0]-n.from[0],height:n.to[1]-n.from[1],fill:"none",stroke:"none"})}function _e(e,o,n=!0){let r=Math.atan2(o[1]-e[1],o[0]-e[0])+Math.PI;return n?(Math.round(r*8/Math.PI)+16)%16:r}function Yn(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((n,r)=>n+r*r,0))}function Uo(e,o,n){let r=Yn(e,o),t=_e(e,o,!1);if(n&&(r-=33/64,n.size>1)){r-=10/64;let i=_e(e,o);(n.has((i+1)%16)||n.has((i+15)%16))&&i&1&&(r-=.4)}return[e[0]-Math.cos(t)*r,e[1]-Math.sin(t)*r].map(i=>i+.5)}function _o(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let c of eo)e.classList.toggle("orientation-"+c,o.orientation===c);e.classList.toggle("manipulable",!o.viewOnly);let n=C("cg-container");e.appendChild(n);let r=C("cg-board");n.appendChild(r);let t,i,a,u,d;if(o.drawable.visible&&([t,i]=["cg-shapes-below","cg-shapes"].map(c=>Zo(c,!0)),[a,u]=["cg-custom-below","cg-custom-svgs"].map(c=>Zo(c,!1)),d=C("cg-auto-pieces"),n.appendChild(t),n.appendChild(a),n.appendChild(i),n.appendChild(u),n.appendChild(d)),o.coordinates){let c=o.orientation==="black"?" black":"",l=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let p=o.orientation==="white"?m=>m+1:m=>8-m;z.forEach((m,b)=>n.appendChild(Xe(j.map(g=>m+g),"squares rank"+p(b)+c+l)))}else n.appendChild(Xe(j,"ranks"+c+l)),n.appendChild(Xe(z,"files"+c))}let s;return o.draggable.enabled&&o.draggable.showGhost&&(s=C("piece","ghost"),Y(s,!1),n.appendChild(s)),{board:r,container:n,wrap:e,ghost:s,shapes:i,shapesBelow:t,custom:u,customBelow:a,autoPieces:d}}function Zo(e,o){let n=w(y("svg"),{class:e,viewBox:o?"-4 -4 8 8":"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"});return o&&n.appendChild(Wo()),n.appendChild(y("g")),n}function Xe(e,o){let n=C("coords",o),r;for(let t of e)r=C("coord"),r.textContent=t,n.appendChild(r);return n}function Xo(e,o){if(!e.dropmode.active)return;E(e),A(e);let n=e.dropmode.piece;if(n){e.pieces.set("a0",n);let r=B(o),t=r&&N(r,v(e),e.dom.bounds());t&&he(e,"a0",t)}e.dom.redraw()}function Yo(e,o){let n=e.dom.elements.board;if("ResizeObserver"in window&&new ResizeObserver(o).observe(e.dom.elements.wrap),(e.disableContextMenu||e.drawable.enabled)&&n.addEventListener("contextmenu",t=>t.preventDefault()),e.viewOnly)return;let r=er(e);n.addEventListener("touchstart",r,{passive:!1}),n.addEventListener("mousedown",r,{passive:!1})}function Jo(e,o){let n=[];if("ResizeObserver"in window||n.push(ie(document.body,"chessground.resize",o)),!e.viewOnly){let r=Qo(e,Ho,Do),t=Qo(e,qo,Ko);for(let a of["touchmove","mousemove"])n.push(ie(document,a,r));for(let a of["touchend","mouseup"])n.push(ie(document,a,t));let i=()=>e.dom.bounds.clear();n.push(ie(document,"scroll",i,{capture:!0,passive:!0})),n.push(ie(window,"resize",i,{passive:!0}))}return()=>n.forEach(r=>r())}function ie(e,o,n,r){return e.addEventListener(o,n,r),()=>e.removeEventListener(o,n,r)}var er=e=>o=>{e.draggable.current?I(e):e.drawable.current?Ie(e):o.shiftKey||le(o)?e.drawable.enabled&&ko(e,o):e.viewOnly||(e.dropmode.active?Xo(e,o):Ao(e,o))},Qo=(e,o,n)=>r=>{e.drawable.current?e.drawable.enabled&&n(e,r):e.viewOnly||o(e,r)};function on(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.board,t=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,u=i?i.plan.fadings:new Map,d=e.draggable.current,s=nr(e),c=new Set,l=new Set,p=new Map,m=new Map,b,g,R,D,K,_,ke,H,Ce,se;for(g=r.firstChild;g;){if(b=g.cgKey,rn(g))if(R=t.get(b),K=a.get(b),_=u.get(b),D=g.cgPiece,g.cgDragging&&(!d||d.orig!==b)&&(g.classList.remove("dragging"),k(g,n(f(b),o)),g.cgDragging=!1),!_&&g.cgFading&&(g.cgFading=!1,g.classList.remove("fading")),R){if(K&&g.cgAnimating&&D===ae(R)){let h=f(b);h[0]+=K[2],h[1]+=K[3],g.classList.add("anim"),k(g,n(h,o))}else g.cgAnimating&&(g.cgAnimating=!1,g.classList.remove("anim"),k(g,n(f(b),o)),e.addPieceZIndex&&(g.style.zIndex=Qe(f(b),o)));D===ae(R)&&(!_||!g.cgFading)?c.add(b):_&&D===ae(_)?(g.classList.add("fading"),g.cgFading=!0):Ye(p,D,g)}else Ye(p,D,g);else if(tn(g)){let h=g.className;s.get(b)===h?l.add(b):Ye(m,h,g)}g=g.nextSibling}for(let[h,X]of s)if(!l.has(h)){Ce=m.get(X),se=Ce&&Ce.pop();let q=n(f(h),o);if(se)se.cgKey=h,k(se,q);else{let T=C("square",X);T.cgKey=h,k(T,q),r.insertBefore(T,r.firstChild)}}for(let[h,X]of t)if(K=a.get(h),!c.has(h))if(ke=p.get(ae(X)),H=ke&&ke.pop(),H){H.cgKey=h,H.cgFading&&(H.classList.remove("fading"),H.cgFading=!1);let q=f(h);e.addPieceZIndex&&(H.style.zIndex=Qe(q,o)),K&&(H.cgAnimating=!0,H.classList.add("anim"),q[0]+=K[2],q[1]+=K[3]),k(H,n(q,o))}else{let q=ae(X),T=C("piece",q),ce=f(h);T.cgPiece=q,T.cgKey=h,K&&(T.cgAnimating=!0,ce[0]+=K[2],ce[1]+=K[3]),k(T,n(ce,o)),e.addPieceZIndex&&(T.style.zIndex=Qe(ce,o)),r.appendChild(T)}for(let h of p.values())en(e,h);for(let h of m.values())en(e,h)}function nn(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.board.firstChild;for(;r;)(rn(r)&&!r.cgAnimating||tn(r))&&k(r,n(f(r.cgKey),o)),r=r.nextSibling}function Je(e){let o=e.dom.elements.wrap.getBoundingClientRect(),n=e.dom.elements.container,r=o.height/o.width,t=Math.floor(o.width*window.devicePixelRatio/8)*8/window.devicePixelRatio,i=t*r;n.style.width=t+"px",n.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 rn=e=>e.tagName==="PIECE",tn=e=>e.tagName==="SQUARE";function en(e,o){for(let n of o)e.dom.elements.board.removeChild(n)}function Qe(e,o){let r=e[1];return`${o?10-r:3+r}`}var ae=e=>`${e.color} ${e.role}`;function nr(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let t of e.lastMove)L(o,t,"last-move");if(e.check&&e.highlight.check&&L(o,e.check,"check"),e.selected&&(L(o,e.selected,"selected"),e.movable.showDests)){let t=e.movable.dests?.get(e.selected);if(t)for(let a of t)L(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)L(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let n=e.premovable.current;if(n)for(let t of n)L(o,t,"current-premove");else e.predroppable.current&&L(o,e.predroppable.current.key,"current-premove");let r=e.exploding;if(r)for(let t of r.keys)L(o,t,"exploding"+r.stage);return e.highlight.custom&&e.highlight.custom.forEach((t,i)=>{L(o,i,t)}),o}function L(e,o,n){let r=e.get(o);r?e.set(o,`${r} ${n}`):e.set(o,n)}function Ye(e,o,n){let r=e.get(o);r?r.push(n):e.set(o,[n])}function an(e,o,n){let r=new Map,t=[];for(let u of e)r.set(u.hash,!1);let i=o.firstElementChild,a;for(;i;)a=i.getAttribute("cgHash"),r.has(a)?r.set(a,!0):t.push(i),i=i.nextElementSibling;for(let u of t)o.removeChild(u);for(let u of e)r.get(u.hash)||o.appendChild(n(u))}function sn(e,o){let r=e.drawable.autoShapes.filter(t=>t.piece).map(t=>({shape:t,hash:tr(t),current:!1,pendingErase:!1}));an(r,o,t=>rr(e,t,e.dom.bounds()))}function cn(e){let o=v(e),n=W(e.dom.bounds()),r=e.dom.elements.autoPieces?.firstChild;for(;r;)xe(r,n(f(r.cgKey),o),r.cgScale),r=r.nextSibling}function rr(e,{shape:o,hash:n},r){let t=o.orig,i=o.piece?.role,a=o.piece?.color,u=o.piece?.scale,d=C("piece",`${i} ${a}`);return d.setAttribute("cgHash",n),d.cgKey=t,d.cgScale=u,xe(d,W(r)(f(t),v(e)),u),d}var tr=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function ut({el:e,config:o}){return ar(e,o)}function ar(e,o){let n=Lo();we(n,o||{});function r(){let t="dom"in n?n.dom.unbind:void 0,i=_o(e,n),a=Ke(()=>i.board.getBoundingClientRect()),u=c=>{on(s),i.autoPieces&&sn(s,i.autoPieces),!c&&i.shapes&&zo(s,i)},d=()=>{Je(s),nn(s),i.autoPieces&&cn(s)},s=n;return s.dom={elements:i,bounds:a,redraw:sr(u),redrawNow:u,unbind:t},s.drawable.prevSvgHash="",Je(s),u(!1),Yo(s,d),t||(s.dom.unbind=Jo(s,d)),s.events.insert&&s.events.insert(i),s}return Vo(r(),r)}function sr(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{ar as Chessground,ut as initModule};
|
package/dist/util.js
CHANGED
|
@@ -67,7 +67,9 @@ export const eventPosition = (e) => {
|
|
|
67
67
|
return [e.targetTouches[0].clientX, e.targetTouches[0].clientY];
|
|
68
68
|
return; // touchend has no position!
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
const isFireMac = memo(() => !('ontouchstart' in window) &&
|
|
71
|
+
['macintosh', 'firefox'].every(x => navigator.userAgent.toLowerCase().includes(x)));
|
|
72
|
+
export const isRightButton = (e) => e.button === 2 && !(e.ctrlKey && isFireMac());
|
|
71
73
|
export const createEl = (tagName, className) => {
|
|
72
74
|
const el = document.createElement(tagName);
|
|
73
75
|
if (className)
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,MAAM,CAAC,MAAM,QAAQ,GAAuB,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;AAEpE,MAAM,CAAC,MAAM,OAAO,GAAsB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC,CAAC,CAAC;AAEtG,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE,CACzD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAE9E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,OAAO,CAAC,GAAG,CAA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CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAc,EAAE,KAAa,EAAsB,EAAE;IAC3F,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;IAChB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/util.ts
CHANGED
|
@@ -86,7 +86,13 @@ export const eventPosition = (e: cg.MouchEvent): cg.NumberPair | undefined => {
|
|
|
86
86
|
return; // touchend has no position!
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
const isFireMac = memo(
|
|
90
|
+
() =>
|
|
91
|
+
!('ontouchstart' in window) &&
|
|
92
|
+
['macintosh', 'firefox'].every(x => navigator.userAgent.toLowerCase().includes(x)),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export const isRightButton = (e: cg.MouchEvent): boolean => e.button === 2 && !(e.ctrlKey && isFireMac());
|
|
90
96
|
|
|
91
97
|
export const createEl = (tagName: string, className?: string): HTMLElement => {
|
|
92
98
|
const el = document.createElement(tagName);
|