@lichess-org/chessground 9.2.3 → 9.3.1

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/README.md CHANGED
@@ -108,3 +108,9 @@ To build the standalone:
108
108
  ```sh
109
109
  pnpm run dist
110
110
  ```
111
+
112
+ To run tests:
113
+
114
+ ```sh
115
+ pnpm test
116
+ ```
package/dist/board.js CHANGED
@@ -1,5 +1,5 @@
1
- import { pos2key, key2pos, opposite, distanceSq, allPos, computeSquareCenter } from './util.js';
2
- import { premove, queen, knight } from './premove.js';
1
+ import { pos2key, key2pos, opposite, distanceSq, allPos, computeSquareCenter, queenDir, knightDir, } from './util.js';
2
+ import { premove } from './premove.js';
3
3
  export function callUserFunction(f, ...args) {
4
4
  if (f)
5
5
  setTimeout(() => f(...args), 1);
@@ -199,14 +199,11 @@ export function selectSquare(state, key, force) {
199
199
  }
200
200
  export function setSelected(state, key) {
201
201
  state.selected = key;
202
- if (isPremovable(state, key)) {
203
- // calculate chess premoves if custom premoves are not passed
204
- if (!state.premovable.customDests) {
205
- state.premovable.dests = premove(state.pieces, key, state.premovable.castle);
206
- }
207
- }
208
- else
202
+ if (!isPremovable(state, key))
209
203
  state.premovable.dests = undefined;
204
+ else if (!state.premovable.customDests)
205
+ state.premovable.dests = premove(state, key);
206
+ // calculate chess premoves if custom premoves are not passed
210
207
  }
211
208
  export function unselect(state) {
212
209
  state.selected = undefined;
@@ -239,11 +236,12 @@ function isPremovable(state, orig) {
239
236
  state.movable.color === piece.color &&
240
237
  state.turnColor !== piece.color);
241
238
  }
242
- function canPremove(state, orig, dest) {
239
+ const canPremove = (state, orig, dest) => {
243
240
  var _a, _b;
244
- const validPremoves = (_b = (_a = state.premovable.customDests) === null || _a === void 0 ? void 0 : _a.get(orig)) !== null && _b !== void 0 ? _b : premove(state.pieces, orig, state.premovable.castle);
245
- return orig !== dest && isPremovable(state, orig) && validPremoves.includes(dest);
246
- }
241
+ return orig !== dest &&
242
+ isPremovable(state, orig) &&
243
+ ((_b = (_a = state.premovable.customDests) === null || _a === void 0 ? void 0 : _a.get(orig)) !== null && _b !== void 0 ? _b : premove(state, orig)).includes(dest);
244
+ };
247
245
  function canPredrop(state, orig, dest) {
248
246
  const piece = state.pieces.get(orig);
249
247
  const destPiece = state.pieces.get(dest);
@@ -321,7 +319,8 @@ export function getKeyAtDomPos(pos, asWhite, bounds) {
321
319
  }
322
320
  export function getSnappedKeyAtDomPos(orig, pos, asWhite, bounds) {
323
321
  const origPos = key2pos(orig);
324
- const validSnapPos = allPos.filter(pos2 => queen(origPos[0], origPos[1], pos2[0], pos2[1]) || knight(origPos[0], origPos[1], pos2[0], pos2[1]));
322
+ const validSnapPos = allPos.filter(pos2 => queenDir(origPos[0], origPos[1], pos2[0], pos2[1]) ||
323
+ knightDir(origPos[0], origPos[1], pos2[0], pos2[1]));
325
324
  const validSnapCenters = validSnapPos.map(pos2 => computeSquareCenter(pos2key(pos2), asWhite, bounds));
326
325
  const validSnapDistances = validSnapCenters.map(pos2 => distanceSq(pos, pos2));
327
326
  const [, closestSnapIndex] = validSnapDistances.reduce((a, b, index) => (a[0] < b ? a : [b, index]), [validSnapDistances[0], 0]);
package/dist/board.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"board.js","sourceRoot":"","sources":["../src/board.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtD,MAAM,UAAU,gBAAgB,CAC9B,CAAgB,EAChB,GAAG,IAAmB;IAEtB,IAAI,CAAC;QAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,iBAAiB,CA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o=>e+o))),w=e=>re[8*e[0]+e[1]],g=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var te=re.map(g);function Fe(e){let o,r=()=>(o===void 0&&(o=e()),o);return r.clear=()=>{o=void 0},r}var ze=()=>{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}}},ne=e=>e==="white"?"black":"white",B=(e,o)=>{let r=e[0]-o[0],t=e[1]-o[1];return r*r+t*t},U=(e,o)=>e.role===o.role&&e.color===o.color,V=e=>(o,r)=>[(r?o[0]:7-o[0])*e.width/8,(r?7-o[1]:o[1])*e.height/8],x=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},be=(e,o,r=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${r})`},Z=(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]},ie=e=>e.button===2,K=(e,o)=>{let r=document.createElement(e);return o&&(r.className=o),r};function ae(e,o,r){let t=g(e);return o||(t[0]=7-t[0],t[1]=7-t[1]),[r.left+r.width*t[0]/8+r.width/16,r.top+r.height*(7-t[1])/8+r.height/16]}var G=(e,o)=>Math.abs(e-o),Fo=e=>(o,r,t,n)=>G(o,t)<2&&(e==="white"?n===r+1||r<=1&&n===r+2&&o===t:n===r-1||r>=6&&n===r-2&&o===t),ve=(e,o,r,t)=>{let n=G(e,r),i=G(o,t);return n===1&&i===2||n===2&&i===1},$e=(e,o,r,t)=>G(e,r)===G(o,t),Ie=(e,o,r,t)=>e===r||o===t,ye=(e,o,r,t)=>$e(e,o,r,t)||Ie(e,o,r,t),zo=(e,o,r)=>(t,n,i,a)=>G(t,i)<2&&G(n,a)<2||r&&n===a&&n===(e==="white"?0:7)&&(t===4&&(i===2&&o.includes(0)||i===6&&o.includes(7))||o.includes(i));function $o(e,o){let r=o==="white"?"1":"8",t=[];for(let[n,i]of e)n[1]===r&&i.color===o&&i.role==="rook"&&t.push(g(n)[0]);return t}function Se(e,o,r){let t=e.get(o);if(!t)return[];let n=g(o),i=t.role,a=i==="pawn"?Fo(t.color):i==="knight"?ve:i==="bishop"?$e:i==="rook"?Ie:i==="queen"?ye:zo(t.color,$o(e,t.color),r);return te.filter(c=>(n[0]!==c[0]||n[1]!==c[1])&&a(n[0],n[1],c[0],c[1])).map(w)}function M(e,...o){e&&setTimeout(()=>e(...o),1)}function je(e){e.orientation=ne(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function Ue(e,o){for(let[r,t]of o)t?e.pieces.set(r,t):e.pieces.delete(r)}function Ze(e,o){if(e.check=void 0,o===!0&&(o=e.turnColor),o)for(let[r,t]of e.pieces)t.role==="king"&&t.color===o&&(e.check=r)}function Io(e,o,r,t){D(e),e.premovable.current=[o,r],M(e.premovable.events.set,o,r,t)}function C(e){e.premovable.current&&(e.premovable.current=void 0,M(e.premovable.events.unset))}function jo(e,o,r){C(e),e.predroppable.current={role:o,key:r},M(e.predroppable.events.set,o,r)}function D(e){let o=e.predroppable;o.current&&(o.current=void 0,M(o.events.unset))}function Uo(e,o,r){if(!e.autoCastle)return!1;let t=e.pieces.get(o);if(!t||t.role!=="king")return!1;let n=g(o),i=g(r);if(n[1]!==0&&n[1]!==7||n[1]!==i[1])return!1;n[0]===4&&!e.pieces.has(r)&&(i[0]===6?r=w([7,i[1]]):i[0]===2&&(r=w([0,i[1]])));let a=e.pieces.get(r);return!a||a.color!==t.color||a.role!=="rook"?!1:(e.pieces.delete(o),e.pieces.delete(r),n[0]<i[0]?(e.pieces.set(w([6,i[1]]),t),e.pieces.set(w([5,i[1]]),a)):(e.pieces.set(w([2,i[1]]),t),e.pieces.set(w([3,i[1]]),a)),!0)}function we(e,o,r){let t=e.pieces.get(o),n=e.pieces.get(r);if(o===r||!t)return!1;let i=n&&n.color!==t.color?n:void 0;return r===e.selected&&P(e),M(e.events.move,o,r,i),Uo(e,o,r)||(e.pieces.set(r,t),e.pieces.delete(o)),e.lastMove=[o,r],e.check=void 0,M(e.events.change),i||!0}function ce(e,o,r,t){if(e.pieces.has(r))if(t)e.pieces.delete(r);else return!1;return M(e.events.dropNewPiece,o,r),e.pieces.set(r,o),e.lastMove=[r],e.check=void 0,M(e.events.change),e.movable.dests=void 0,e.turnColor=ne(e.turnColor),!0}function Qe(e,o,r){let t=we(e,o,r);return t&&(e.movable.dests=void 0,e.turnColor=ne(e.turnColor),e.animation.current=void 0),t}function Pe(e,o,r){if(le(e,o,r)){let t=Qe(e,o,r);if(t){let n=e.hold.stop();P(e);let i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:n};return t!==!0&&(i.captured=t),M(e.movable.events.after,o,r,i),!0}}else if(Qo(e,o,r))return Io(e,o,r,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function se(e,o,r,t){let n=e.pieces.get(o);n&&(Zo(e,o,r)||t)?(e.pieces.delete(o),ce(e,n,r,t),M(e.movable.events.afterNewPiece,n.role,r,{premove:!1,predrop:!1})):n&&Xo(e,o,r)?jo(e,n.role,r):(C(e),D(e)),e.pieces.delete(o),P(e)}function X(e,o,r){if(M(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&&Pe(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(Xe(e,o)||xe(e,o))&&(Me(e,o),e.hold.start())}function Me(e,o){e.selected=o,xe(e,o)?e.premovable.customDests||(e.premovable.dests=Se(e.pieces,o,e.premovable.castle)):e.premovable.dests=void 0}function P(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function Xe(e,o){let r=e.pieces.get(o);return!!r&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}var le=(e,o,r)=>o!==r&&Xe(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(r));function Zo(e,o,r){let t=e.pieces.get(o);return!!t&&(o===r||!e.pieces.has(r))&&(e.movable.color==="both"||e.movable.color===t.color&&e.turnColor===t.color)}function xe(e,o){let r=e.pieces.get(o);return!!r&&e.premovable.enabled&&e.movable.color===r.color&&e.turnColor!==r.color}function Qo(e,o,r){let t=e.premovable.customDests?.get(o)??Se(e.pieces,o,e.premovable.castle);return o!==r&&xe(e,o)&&t.includes(r)}function Xo(e,o,r){let t=e.pieces.get(o),n=e.pieces.get(r);return!!t&&(!n||n.color!==e.movable.color)&&e.predroppable.enabled&&(t.role!=="pawn"||r[1]!=="1"&&r[1]!=="8")&&e.movable.color===t.color&&e.turnColor!==t.color}function Ye(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 _e(e){let o=e.premovable.current;if(!o)return!1;let r=o[0],t=o[1],n=!1;if(le(e,r,t)){let i=Qe(e,r,t);if(i){let a={premove:!0};i!==!0&&(a.captured=i),M(e.movable.events.after,r,t,a),n=!0}}return C(e),n}function Je(e,o){let r=e.predroppable.current,t=!1;if(!r)return!1;if(o(r)){let n={role:r.role,color:e.movable.color};ce(e,n,r.key)&&(M(e.movable.events.afterNewPiece,r.role,r.key,{premove:!1,predrop:!0}),t=!0)}return D(e),t}function Y(e){C(e),D(e),P(e)}function Ke(e){e.movable.color=e.movable.dests=e.animation.current=void 0,Y(e)}function E(e,o,r){let t=Math.floor(8*(e[0]-r.left)/r.width);o||(t=7-t);let n=7-Math.floor(8*(e[1]-r.top)/r.height);return o||(n=7-n),t>=0&&t<8&&n>=0&&n<8?w([t,n]):void 0}function eo(e,o,r,t){let n=g(e),i=te.filter(s=>ye(n[0],n[1],s[0],s[1])||ve(n[0],n[1],s[0],s[1])),c=i.map(s=>ae(w(s),r,t)).map(s=>B(o,s)),[,l]=c.reduce((s,f,d)=>s[0]<f?s:[f,d],[c[0],0]);return w(i[l])}var h=e=>e.orientation==="white";var Ce="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",Yo={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},_o={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function de(e){e==="start"&&(e=Ce);let o=new Map,r=7,t=0;for(let n of e)switch(n){case" ":case"[":return o;case"/":if(--r,r<0)return o;t=0;break;case"~":{let i=o.get(w([t-1,r]));i&&(i.promoted=!0);break}default:{let i=n.charCodeAt(0);if(i<57)t+=i-48;else{let a=n.toLowerCase();o.set(w([t,r]),{role:Yo[a],color:n===a?"black":"white"}),++t}}}return o}function oo(e){return We.map(o=>L.map(r=>{let t=e.get(r+o);if(t){let n=_o[t.role];return t.color==="white"&&(n=n.toUpperCase()),t.promoted&&(n+="~"),n}else return"1"}).join("")).join("/").replace(/1{2,}/g,o=>o.length.toString())}function De(e,o){o.animation&&(Ee(e.animation,o.animation),(e.animation.duration||0)<70&&(e.animation.enabled=!1))}function ue(e,o){if(o.movable?.dests&&(e.movable.dests=void 0),o.drawable?.autoShapes&&(e.drawable.autoShapes=[]),Ee(e,o),o.fen&&(e.pieces=de(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&Ze(e,o.check||!1),"lastMove"in o&&!o.lastMove?e.lastMove=void 0:o.lastMove&&(e.lastMove=o.lastMove),e.selected&&Me(e,e.selected),De(e,o),!e.movable.rookCastle&&e.movable.dests){let r=e.movable.color==="white"?"1":"8",t="e"+r,n=e.movable.dests.get(t),i=e.pieces.get(t);if(!n||!i||i.role!=="king")return;e.movable.dests.set(t,n.filter(a=>!(a==="a"+r&&n.includes("c"+r))&&!(a==="h"+r&&n.includes("g"+r))))}}function Ee(e,o){for(let r in o)r==="__proto__"||r==="constructor"||!Object.prototype.hasOwnProperty.call(o,r)||(Object.prototype.hasOwnProperty.call(e,r)&&ro(e[r])&&ro(o[r])?Ee(e[r],o[r]):e[r]=o[r])}function ro(e){if(typeof e!="object"||e===null)return!1;let o=Object.getPrototypeOf(e);return o===Object.prototype||o===null}var q=(e,o)=>o.animation.enabled?rr(e,o):R(e,o);function R(e,o){let r=e(o);return o.dom.redraw(),r}var Ae=(e,o)=>({key:e,pos:g(e),piece:o}),er=(e,o)=>o.sort((r,t)=>B(e.pos,r.pos)-B(e.pos,t.pos))[0];function or(e,o){let r=new Map,t=[],n=new Map,i=[],a=[],c=new Map,l,s,f;for(let[d,u]of e)c.set(d,Ae(d,u));for(let d of re)l=o.pieces.get(d),s=c.get(d),l?s?U(l,s.piece)||(i.push(s),a.push(Ae(d,l))):a.push(Ae(d,l)):s&&i.push(s);for(let d of a)s=er(d,i.filter(u=>U(d.piece,u.piece))),s&&(f=[s.pos[0]-d.pos[0],s.pos[1]-d.pos[1]],r.set(d.key,f.concat(f)),t.push(s.key));for(let d of i)t.includes(d.key)||n.set(d.key,d.piece);return{anims:r,fadings:n}}function to(e,o){let r=e.animation.current;if(r===void 0){e.dom.destroyed||e.dom.redrawNow();return}let t=1-(o-r.start)*r.frequency;if(t<=0)e.animation.current=void 0,e.dom.redrawNow();else{let n=tr(t);for(let i of r.plan.anims.values())i[2]=i[0]*n,i[3]=i[1]*n;e.dom.redrawNow(!0),requestAnimationFrame((i=performance.now())=>to(e,i))}}function rr(e,o){let r=new Map(o.pieces),t=e(o),n=or(r,o);if(n.anims.size||n.fadings.size){let i=o.animation.current&&o.animation.current.start;o.animation.current={start:performance.now(),frequency:1/o.animation.duration,plan:n},i||to(o,performance.now())}else o.dom.redraw();return t}var tr=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var nr=["green","red","blue","yellow"];function no(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):Y(e);let r=T(o),t=E(r,h(e),e.dom.bounds());t&&(e.drawable.current={orig:t,pos:r,brush:ir(o),snapToValidMove:e.drawable.defaultSnapToValidMove},io(e))}function io(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let r=E(o.pos,h(e),e.dom.bounds());r||(o.snapToValidMove=!1);let t=o.snapToValidMove?eo(o.orig,o.pos,h(e),e.dom.bounds()):r;t!==o.mouseSq&&(o.mouseSq=t,o.dest=t!==o.orig?t:void 0,e.dom.redrawNow()),io(e)}})}function ao(e,o){e.drawable.current&&(e.drawable.current.pos=T(o))}function co(e){let o=e.drawable.current;o&&(o.mouseSq&&ar(e.drawable,o),Ne(e))}function Ne(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function so(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),lo(e.drawable))}function ir(e){let o=(e.shiftKey||e.ctrlKey)&&ie(e),r=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return nr[(o?1:0)+(r?2:0)]}function ar(e,o){let r=n=>n.orig===o.orig&&n.dest===o.dest,t=e.shapes.find(r);t&&(e.shapes=e.shapes.filter(n=>!r(n))),(!t||t.brush!==o.brush)&&e.shapes.push({orig:o.orig,dest:o.dest,brush:o.brush}),lo(e)}function lo(e){e.onChange&&e.onChange(e.shapes)}function uo(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(),t=T(o),n=E(t,h(e),r);if(!n)return;let i=e.pieces.get(n),a=e.selected;if(!a&&e.drawable.enabled&&(e.drawable.eraseOnClick||!i||i.color!==e.turnColor)&&so(e),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||sr(e,t)))o.preventDefault();else if(o.touches)return;let c=!!e.premovable.current,l=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&le(e,e.selected,n)?q(d=>X(d,n),e):X(e,n);let s=e.selected===n,f=ho(e,n);if(i&&f&&s&&Ye(e,n)){e.draggable.current={orig:n,piece:i,origPos:t,pos:t,started:e.draggable.autoDistance&&e.stats.dragged,element:f,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},f.cgDragging=!0,f.classList.add("dragging");let d=e.dom.elements.ghost;d&&(d.className=`ghost ${i.color} ${i.role}`,x(d,V(r)(g(n),h(e))),Z(d,!0)),He(e)}else c&&C(e),l&&D(e);e.dom.redraw()}function sr(e,o){let r=h(e),t=e.dom.bounds(),n=Math.pow(t.width/8,2);for(let i of e.pieces.keys()){let a=ae(i,r,t);if(B(a,o)<=n)return!0}return!1}function po(e,o,r,t){let n="a0";e.pieces.set(n,o),e.dom.redraw();let i=T(r);e.draggable.current={orig:n,piece:o,origPos:i,pos:i,started:!0,element:()=>ho(e,n),originTarget:r.target,newPiece:!0,force:!!t,keyHasChanged:!1},He(e)}function He(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||!U(r,o.piece))W(e);else if(!o.started&&B(o.pos,o.origPos)>=Math.pow(e.draggable.distance,2)&&(o.started=!0),o.started){if(typeof o.element=="function"){let n=o.element();if(!n)return;n.cgDragging=!0,n.classList.add("dragging"),o.element=n}let t=e.dom.bounds();x(o.element,[o.pos[0]-t.left-t.width/16,o.pos[1]-t.top-t.height/16]),o.keyHasChanged||=o.orig!==E(o.pos,h(e),t)}He(e)})}function fo(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=T(o))}function go(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}C(e),D(e);let t=T(o)||r.pos,n=E(t,h(e),e.dom.bounds());n&&r.started&&r.orig!==n?r.newPiece?se(e,r.orig,n,r.force):(e.stats.ctrlKey=o.ctrlKey,Pe(e,r.orig,n)&&(e.stats.dragged=!0)):r.newPiece?e.pieces.delete(r.orig):e.draggable.deleteOnDropOff&&!n&&(e.pieces.delete(r.orig),M(e.events.change)),(r.orig===r.previouslySelected||r.keyHasChanged)&&(r.orig===n||!n)?P(e):e.selectable.enabled||P(e),mo(e),e.draggable.current=void 0,e.dom.redraw()}function W(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),mo(e),e.dom.redraw())}function mo(e){let o=e.dom.elements;o.ghost&&Z(o.ghost,!1)}function ho(e,o){let r=e.dom.elements.board.firstChild;for(;r;){if(r.cgKey===o&&r.tagName==="PIECE")return r;r=r.nextSibling}}function vo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{bo(e,2),setTimeout(()=>bo(e,void 0),120)},120)}function bo(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function yo(e,o){function r(){je(e),o()}return{set(t){t.orientation&&t.orientation!==e.orientation&&r(),De(e,t),(t.fen?q:R)(n=>ue(n,t),e)},state:e,getFen:()=>oo(e.pieces),toggleOrientation:r,setPieces(t){q(n=>Ue(n,t),e)},selectSquare(t,n){t?q(i=>X(i,t,n),e):e.selected&&(P(e),e.dom.redraw())},move(t,n){q(i=>we(i,t,n),e)},newPiece(t,n){q(i=>ce(i,t,n),e)},playPremove(){if(e.premovable.current){if(q(_e,e))return!0;e.dom.redraw()}return!1},playPredrop(t){if(e.predroppable.current){let n=Je(e,t);return e.dom.redraw(),n}return!1},cancelPremove(){R(C,e)},cancelPredrop(){R(D,e)},cancelMove(){R(t=>{Y(t),W(t)},e)},stop(){R(t=>{Ke(t),W(t)},e)},explode(t){vo(e,t)},setAutoShapes(t){R(n=>n.drawable.autoShapes=t,e)},setShapes(t){R(n=>n.drawable.shapes=t.slice(),e)},getKeyAtDomPos(t){return E(t,h(e),e.dom.bounds())},redrawAll:o,dragNewPiece(t,n,i){po(e,t,n,i)},destroy(){Ke(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function So(){return{pieces:de(Ce),orientation:"white",turnColor:"white",coordinates:!0,coordinatesOnSquares:!1,ranksPosition:"right",autoCastle:!0,viewOnly:!1,disableContextMenu:!1,addPieceZIndex:!1,blockTouchScroll:!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,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,eraseOnClick:!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}},prevSvgHash:""},hold:ze()}}var wo={hilitePrimary:{key:"hilitePrimary",color:"#3291ff",opacity:1,lineWidth:1},hiliteWhite:{key:"hiliteWhite",color:"#ffffff",opacity:1,lineWidth:1}};function xo(){let e=b("defs"),o=y(b("filter"),{id:"cg-filter-blur"});return o.appendChild(y(b("feGaussianBlur"),{stdDeviation:"0.019"})),e.appendChild(o),e}function Ko(e,o,r){let t=e.drawable,n=t.current,i=n&&n.mouseSq?n:void 0,a=new Map,c=e.dom.bounds(),l=t.autoShapes.filter(u=>!u.piece);for(let u of t.shapes.concat(l).concat(i?[i]:[])){if(!u.dest)continue;let S=a.get(u.dest)??new Set,v=ge(fe(g(u.orig),e.orientation),c),p=ge(fe(g(u.dest),e.orientation),c);S.add(qe(v,p)),a.set(u.dest,S)}let s=t.shapes.concat(l).map(u=>({shape:u,current:!1,hash:Po(u,Te(u.dest,a),!1,c)}));i&&s.push({shape:i,current:!0,hash:Po(i,Te(i.dest,a),!0,c)});let f=s.map(u=>u.hash).join(";");if(f===e.drawable.prevSvgHash)return;e.drawable.prevSvgHash=f;let d=o.querySelector("defs");dr(t,s,d),ur(s,o.querySelector("g"),r.querySelector("g"),u=>gr(e,u,t.brushes,a,c))}function dr(e,o,r){let t=new Map,n;for(let c of o.filter(l=>l.shape.dest&&l.shape.brush))n=ko(e.brushes[c.shape.brush],c.shape.modifiers),c.shape.modifiers?.hilite&&t.set(pe(n).key,pe(n)),t.set(n.key,n);let i=new Set,a=r.firstElementChild;for(;a;)i.add(a.getAttribute("cgKey")),a=a.nextElementSibling;for(let[c,l]of t.entries())i.has(c)||r.appendChild(br(l))}function ur(e,o,r,t){let n=new Map;for(let i of e)n.set(i.hash,!1);for(let i of[o,r]){let a=[],c=i.firstElementChild,l;for(;c;)l=c.getAttribute("cgHash"),n.has(l)?n.set(l,!0):a.push(c),c=c.nextElementSibling;for(let s of a)i.removeChild(s)}for(let i of e.filter(a=>!n.get(a.hash)))for(let a of t(i))a.isCustom?r.appendChild(a.el):o.appendChild(a.el)}function Po({orig:e,dest:o,brush:r,piece:t,modifiers:n,customSvg:i,label:a},c,l,s){return[s.width,s.height,l,e,o,r,c&&"-",t&&pr(t),n&&fr(n),i&&`custom-${Mo(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Mo(a.text)}`].filter(f=>f).join(",")}function pr(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function fr(e){return[e.lineWidth,e.hilite&&"*"].filter(o=>o).join(",")}function Mo(e){let o=0;for(let r=0;r<e.length;r++)o=(o<<5)-o+e.charCodeAt(r)>>>0;return o.toString()}function gr(e,{shape:o,current:r,hash:t},n,i,a){let c=ge(fe(g(o.orig),e.orientation),a),l=o.dest?ge(fe(g(o.dest),e.orientation),a):c,s=o.brush&&ko(n[o.brush],o.modifiers),f=i.get(o.dest),d=[];if(s){let u=y(b("g"),{cgHash:t});d.push({el:u}),c[0]!==l[0]||c[1]!==l[1]?u.appendChild(hr(o,s,c,l,r,Te(o.dest,i))):u.appendChild(mr(n[o.brush],c,r,a))}if(o.label){let u=o.label;u.fill??=o.brush&&n[o.brush].color;let S=o.brush?void 0:"tr";d.push({el:vr(u,t,c,l,f,S),isCustom:!0})}if(o.customSvg){let u=o.customSvg.center??"orig",[S,v]=u==="label"?Do(c,l,f).map(F=>F-.5):u==="dest"?l:c,p=y(b("g"),{transform:`translate(${S},${v})`,cgHash:t});p.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,d.push({el:p,isCustom:!0})}return d}function mr(e,o,r,t){let n=yr(),i=(t.width+t.height)/(4*Math.max(t.width,t.height));return y(b("circle"),{stroke:e.color,"stroke-width":n[r?0:1],fill:"none",opacity:Co(e,r),cx:o[0],cy:o[1],r:i-n[1]/2})}function pe(e){return["#ffffff","#fff","white"].includes(e.color)?wo.hilitePrimary:wo.hiliteWhite}function hr(e,o,r,t,n,i){function a(s){let f=wr(i&&!n),d=t[0]-r[0],u=t[1]-r[1],S=Math.atan2(u,d),v=Math.cos(S)*f,p=Math.sin(S)*f;return y(b("line"),{stroke:s?pe(o).color:o.color,"stroke-width":Sr(o,n)+(s?.04:0),"stroke-linecap":"round","marker-end":`url(#arrowhead-${s?pe(o).key:o.key})`,opacity:e.modifiers?.hilite?1:Co(o,n),x1:r[0],y1:r[1],x2:t[0]-v,y2:t[1]-p})}if(!e.modifiers?.hilite)return a(!1);let c=b("g"),l=y(b("g"),{filter:"url(#cg-filter-blur)"});return l.appendChild(Pr(r,t)),l.appendChild(a(!0)),c.appendChild(l),c.appendChild(a(!1)),c}function br(e){let o=y(b("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(y(b("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),o.setAttribute("cgKey",e.key),o}function vr(e,o,r,t,n,i){let c=.4*.75**e.text.length,l=Do(r,t,n),s=i==="tr"?.4:0,f=y(b("g"),{transform:`translate(${l[0]+s},${l[1]-s})`,cgHash:o});f.appendChild(y(b("circle"),{r:.4/2,"fill-opacity":i?1:.8,"stroke-opacity":i?1:.7,"stroke-width":.03,fill:e.fill??"#666",stroke:"white"}));let d=y(b("text"),{"font-size":c,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return d.innerHTML=e.text,f.appendChild(d),f}function fe(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function Te(e,o){return(e&&o.has(e)&&o.get(e).size>1)===!0}function b(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function y(e,o){for(let r in o)Object.prototype.hasOwnProperty.call(o,r)&&e.setAttribute(r,o[r]);return e}function ko(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 yr(){return[3/64,4/64]}function Sr(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function Co(e,o){return(e.opacity||1)*(o?.9:1)}function wr(e){return(e?20:10)/64}function ge(e,o){let r=Math.min(1,o.width/o.height),t=Math.min(1,o.height/o.width);return[(e[0]-3.5)*r,(3.5-e[1])*t]}function Pr(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 y(b("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 qe(e,o,r=!0){let t=Math.atan2(o[1]-e[1],o[0]-e[0])+Math.PI;return r?(Math.round(t*8/Math.PI)+16)%16:t}function Mr(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((r,t)=>r+t*t,0))}function Do(e,o,r){let t=Mr(e,o),n=qe(e,o,!1);if(r&&(t-=33/64,r.size>1)){t-=10/64;let i=qe(e,o);(r.has((i+1)%16)||r.has((i+15)%16))&&i&1&&(t-=.4)}return[e[0]-Math.cos(n)*t,e[1]-Math.sin(n)*t].map(i=>i+.5)}function Eo(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let l of Le)e.classList.toggle("orientation-"+l,o.orientation===l);e.classList.toggle("manipulable",!o.viewOnly);let r=K("cg-container");e.appendChild(r);let t=K("cg-board");r.appendChild(t);let n,i,a;if(o.drawable.visible&&(n=y(b("svg"),{class:"cg-shapes",viewBox:"-4 -4 8 8",preserveAspectRatio:"xMidYMid slice"}),n.appendChild(xo()),n.appendChild(b("g")),i=y(b("svg"),{class:"cg-custom-svgs",viewBox:"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"}),i.appendChild(b("g")),a=K("cg-auto-pieces"),r.appendChild(n),r.appendChild(i),r.appendChild(a)),o.coordinates){let l=o.orientation==="black"?" black":"",s=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let f=o.orientation==="white"?d=>d+1:d=>8-d;L.forEach((d,u)=>r.appendChild(Re($.map(S=>d+S),"squares rank"+f(u)+l+s)))}else r.appendChild(Re($,"ranks"+l+s)),r.appendChild(Re(L,"files"+l))}let c;return o.draggable.enabled&&o.draggable.showGhost&&(c=K("piece","ghost"),Z(c,!1),r.appendChild(c)),{board:t,container:r,wrap:e,ghost:c,svg:n,customSvg:i,autoPieces:a}}function Re(e,o){let r=K("coords",o),t;for(let n of e)t=K("coord"),t.textContent=n,r.appendChild(t);return r}function Ao(e,o){if(!e.dropmode.active)return;C(e),D(e);let r=e.dropmode.piece;if(r){e.pieces.set("a0",r);let t=T(o),n=t&&E(t,h(e),e.dom.bounds());n&&se(e,"a0",n)}e.dom.redraw()}function Ho(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",n=>n.preventDefault()),e.viewOnly)return;let t=Kr(e);r.addEventListener("touchstart",t,{passive:!1}),r.addEventListener("mousedown",t,{passive:!1})}function To(e,o){let r=[];if("ResizeObserver"in window||r.push(_(document.body,"chessground.resize",o)),!e.viewOnly){let t=No(e,fo,ao),n=No(e,go,co);for(let a of["touchmove","mousemove"])r.push(_(document,a,t));for(let a of["touchend","mouseup"])r.push(_(document,a,n));let i=()=>e.dom.bounds.clear();r.push(_(document,"scroll",i,{capture:!0,passive:!0})),r.push(_(window,"resize",i,{passive:!0}))}return()=>r.forEach(t=>t())}function _(e,o,r,t){return e.addEventListener(o,r,t),()=>e.removeEventListener(o,r,t)}var Kr=e=>o=>{e.draggable.current?W(e):e.drawable.current?Ne(e):o.shiftKey||ie(o)?e.drawable.enabled&&no(e,o):e.viewOnly||(e.dropmode.active?Ao(e,o):uo(e,o))},No=(e,o,r)=>t=>{e.drawable.current?e.drawable.enabled&&r(e,t):e.viewOnly||o(e,t)};function Ro(e){let o=h(e),r=V(e.dom.bounds()),t=e.dom.elements.board,n=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,c=i?i.plan.fadings:new Map,l=e.draggable.current,s=Cr(e),f=new Set,d=new Set,u=new Map,S=new Map,v,p,F,z,k,I,me,A,he,ee;for(p=t.firstChild;p;){if(v=p.cgKey,Bo(p))if(F=n.get(v),k=a.get(v),I=c.get(v),z=p.cgPiece,p.cgDragging&&(!l||l.orig!==v)&&(p.classList.remove("dragging"),x(p,r(g(v),o)),p.cgDragging=!1),!I&&p.cgFading&&(p.cgFading=!1,p.classList.remove("fading")),F){if(k&&p.cgAnimating&&z===J(F)){let m=g(v);m[0]+=k[2],m[1]+=k[3],p.classList.add("anim"),x(p,r(m,o))}else p.cgAnimating&&(p.cgAnimating=!1,p.classList.remove("anim"),x(p,r(g(v),o)),e.addPieceZIndex&&(p.style.zIndex=Oe(g(v),o)));z===J(F)&&(!I||!p.cgFading)?f.add(v):I&&z===J(I)?(p.classList.add("fading"),p.cgFading=!0):Be(u,z,p)}else Be(u,z,p);else if(Vo(p)){let m=p.className;s.get(v)===m?d.add(v):Be(S,m,p)}p=p.nextSibling}for(let[m,j]of s)if(!d.has(m)){he=S.get(j),ee=he&&he.pop();let N=r(g(m),o);if(ee)ee.cgKey=m,x(ee,N);else{let H=K("square",j);H.cgKey=m,x(H,N),t.insertBefore(H,t.firstChild)}}for(let[m,j]of n)if(k=a.get(m),!f.has(m))if(me=u.get(J(j)),A=me&&me.pop(),A){A.cgKey=m,A.cgFading&&(A.classList.remove("fading"),A.cgFading=!1);let N=g(m);e.addPieceZIndex&&(A.style.zIndex=Oe(N,o)),k&&(A.cgAnimating=!0,A.classList.add("anim"),N[0]+=k[2],N[1]+=k[3]),x(A,r(N,o))}else{let N=J(j),H=K("piece",N),oe=g(m);H.cgPiece=N,H.cgKey=m,k&&(H.cgAnimating=!0,oe[0]+=k[2],oe[1]+=k[3]),x(H,r(oe,o)),e.addPieceZIndex&&(H.style.zIndex=Oe(oe,o)),t.appendChild(H)}for(let m of u.values())qo(e,m);for(let m of S.values())qo(e,m)}function Oo(e){let o=h(e),r=V(e.dom.bounds()),t=e.dom.elements.board.firstChild;for(;t;)(Bo(t)&&!t.cgAnimating||Vo(t))&&x(t,r(g(t.cgKey),o)),t=t.nextSibling}function Ve(e){let o=e.dom.elements.wrap.getBoundingClientRect(),r=e.dom.elements.container,t=o.height/o.width,n=Math.floor(o.width*window.devicePixelRatio/8)*8/window.devicePixelRatio,i=n*t;r.style.width=n+"px",r.style.height=i+"px",e.dom.bounds.clear(),e.addDimensionsCssVarsTo?.style.setProperty("---cg-width",n+"px"),e.addDimensionsCssVarsTo?.style.setProperty("---cg-height",i+"px")}var Bo=e=>e.tagName==="PIECE",Vo=e=>e.tagName==="SQUARE";function qo(e,o){for(let r of o)e.dom.elements.board.removeChild(r)}function Oe(e,o){let t=e[1];return`${o?10-t:3+t}`}var J=e=>`${e.color} ${e.role}`;function Cr(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let n of e.lastMove)O(o,n,"last-move");if(e.check&&e.highlight.check&&O(o,e.check,"check"),e.selected&&(O(o,e.selected,"selected"),e.movable.showDests)){let n=e.movable.dests?.get(e.selected);if(n)for(let a of n)O(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)O(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let r=e.premovable.current;if(r)for(let n of r)O(o,n,"current-premove");else e.predroppable.current&&O(o,e.predroppable.current.key,"current-premove");let t=e.exploding;if(t)for(let n of t.keys)O(o,n,"exploding"+t.stage);return e.highlight.custom&&e.highlight.custom.forEach((n,i)=>{O(o,i,n)}),o}function O(e,o,r){let t=e.get(o);t?e.set(o,`${t} ${r}`):e.set(o,r)}function Be(e,o,r){let t=e.get(o);t?t.push(r):e.set(o,[r])}function Lo(e,o,r){let t=new Map,n=[];for(let c of e)t.set(c.hash,!1);let i=o.firstElementChild,a;for(;i;)a=i.getAttribute("cgHash"),t.has(a)?t.set(a,!0):n.push(i),i=i.nextElementSibling;for(let c of n)o.removeChild(c);for(let c of e)t.get(c.hash)||o.appendChild(r(c))}function Go(e,o){let t=e.drawable.autoShapes.filter(n=>n.piece).map(n=>({shape:n,hash:Er(n),current:!1}));Lo(t,o,n=>Dr(e,n,e.dom.bounds()))}function Wo(e){let o=h(e),r=V(e.dom.bounds()),t=e.dom.elements.autoPieces?.firstChild;for(;t;)be(t,r(g(t.cgKey),o),t.cgScale),t=t.nextSibling}function Dr(e,{shape:o,hash:r},t){let n=o.orig,i=o.piece?.role,a=o.piece?.color,c=o.piece?.scale,l=K("piece",`${i} ${a}`);return l.setAttribute("cgHash",r),l.cgKey=n,l.cgScale=c,be(l,V(t)(g(n),h(e)),c),l}var Er=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function Et({el:e,config:o}){return Nr(e,o)}function Nr(e,o){let r=So();ue(r,o||{});function t(){let n="dom"in r?r.dom.unbind:void 0,i=Eo(e,r),a=Fe(()=>i.board.getBoundingClientRect()),c=f=>{Ro(s),i.autoPieces&&Go(s,i.autoPieces),!f&&i.svg&&Ko(s,i.svg,i.customSvg)},l=()=>{Ve(s),Oo(s),i.autoPieces&&Wo(s)},s=r;return s.dom={elements:i,bounds:a,redraw:Hr(c),redrawNow:c,unbind:n},s.drawable.prevSvgHash="",Ve(s),c(!1),Ho(s,l),n||(s.dom.unbind=To(s,l)),s.events.insert&&s.events.insert(i),s}return yo(t(),t)}function Hr(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{Nr as Chessground,Et as initModule};
1
+ var Fe=["white","black"];var G=["a","b","c","d","e","f","g","h"],$=["1","2","3","4","5","6","7","8"];var ze=[...$].reverse(),ne=Array.prototype.concat(...G.map(e=>$.map(o=>e+o))),S=e=>ne[8*e[0]+e[1]],g=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49];var te=ne.map(g);function $e(e){let o,r=()=>(o===void 0&&(o=e()),o);return r.clear=()=>{o=void 0},r}var Ie=()=>{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}}},I=e=>e==="white"?"black":"white",V=(e,o)=>{let r=e[0]-o[0],n=e[1]-o[1];return r*r+n*n},Z=(e,o)=>e.role===o.role&&e.color===o.color,L=e=>(o,r)=>[(r?o[0]:7-o[0])*e.width/8,(r?7-o[1]:o[1])*e.height/8],x=(e,o)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px)`},ve=(e,o,r=1)=>{e.style.transform=`translate(${o[0]}px,${o[1]}px) scale(${r})`},X=(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]},ie=e=>e.button===2,k=(e,o)=>{let r=document.createElement(e);return o&&(r.className=o),r};function ae(e,o,r){let n=g(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 q=(e,o)=>Math.abs(e-o),ce=(e,o,r,n)=>{let t=q(e,r),i=q(o,n);return t===1&&i===2||t===2&&i===1},ye=(e,o,r,n)=>e===r||o===n,Se=(e,o,r,n)=>q(e,r)===q(o,n),je=(e,o,r,n)=>ye(e,o,r,n)||Se(e,o,r,n),Ue=(e,o,r,n)=>{let t=r-e,i=n-o;if(t&&i&&Math.abs(t)!==Math.abs(i))return[];let a=t===0?0:t>0?1:-1,c=i===0?0:i>0?1:-1,l=[],s=e+a,u=o+c;for(;s!==r||u!==n;)l.push([s,u]),s+=a,u+=c;return l.map(d=>S(d))};var we=(e,o,r,n,t,i)=>Ue(e,o,r,n).filter(a=>t.get(a)?.color===i),Ze=(e,o,r,n,t,i,a)=>{let c=we(e,o,r,n,t,i);if(!c.length)return!0;if(c.length>1||!a||c[0]!==a[1])return!1;let l=a[1],s=g(a[0]),u=g(l),d=t.get(l);return d.role==="pawn"&&q(s[1],u[1])===2&&[1,-1].some(p=>{let v=t.get(S([u[0]+p,u[1]]));return v?.role==="pawn"&&v.color===I(d.color)})},Uo=(e,o,r)=>(n,t,i,a)=>{let c=o==="white"?1:-1;return q(n,i)===1?a===t+c:n===i&&(a===t+c||a===t+2*c&&(o==="white"?t<=1:t>=6))&&(r||!we(n,t,i,a+c,e,o).length)},Zo=(e,o,r,n)=>ce(e,o,r,n),Xe=(e,o,r,n)=>(t,i,a,c)=>Se(t,i,a,c)&&(r||Ze(t,i,a,c,e,o,n)),Ye=(e,o,r,n)=>(t,i,a,c)=>ye(t,i,a,c)&&(r||Ze(t,i,a,c,e,o,n)),Xo=(e,o,r,n)=>(t,i,a,c)=>Xe(e,o,r,n)(t,i,a,c)||Ye(e,o,r,n)(t,i,a,c),Yo=(e,o,r,n,t)=>(i,a,c,l)=>q(i,c)<2&&q(a,l)<2||t&&a===l&&a===(o==="white"?0:7)&&(i===4&&(c===2&&n.includes(0)||c===6&&n.includes(7))||n.includes(c))&&(r||we(i,a,c>i?7:1,l,e,o).every(s=>e.get(s).role==="rook")),Qo=(e,o)=>{let r=o==="white"?"1":"8",n=[];for(let[t,i]of e)t[1]===r&&i.color===o&&i.role==="rook"&&n.push(g(t)[0]);return n};function Pe(e,o){let r=e.pieces,n=e.premovable.castle,t=!!e.premovable.premoveThroughFriendlies,i=r.get(o);if(!i)return[];let a=g(o),c=i.role,l=c==="pawn"?Uo(r,i.color,t):c==="knight"?Zo:c==="bishop"?Xe(r,i.color,t,e.lastMove):c==="rook"?Ye(r,i.color,t,e.lastMove):c==="queen"?Xo(r,i.color,t,e.lastMove):Yo(r,i.color,t,Qo(r,i.color),n);return te.filter(s=>(a[0]!==s[0]||a[1]!==s[1])&&l(a[0],a[1],s[0],s[1])).map(S)}function M(e,...o){e&&setTimeout(()=>e(...o),1)}function Qe(e){e.orientation=I(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0}function _e(e,o){for(let[r,n]of o)n?e.pieces.set(r,n):e.pieces.delete(r)}function Je(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 _o(e,o,r,n){K(e),e.premovable.current=[o,r],M(e.premovable.events.set,o,r,n)}function C(e){e.premovable.current&&(e.premovable.current=void 0,M(e.premovable.events.unset))}function Jo(e,o,r){C(e),e.predroppable.current={role:o,key:r},M(e.predroppable.events.set,o,r)}function K(e){let o=e.predroppable;o.current&&(o.current=void 0,M(o.events.unset))}function er(e,o,r){if(!e.autoCastle)return!1;let n=e.pieces.get(o);if(!n||n.role!=="king")return!1;let t=g(o),i=g(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=S([7,i[1]]):i[0]===2&&(r=S([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(S([6,i[1]]),n),e.pieces.set(S([5,i[1]]),a)):(e.pieces.set(S([2,i[1]]),n),e.pieces.set(S([3,i[1]]),a)),!0)}function Me(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),M(e.events.move,o,r,i),er(e,o,r)||(e.pieces.set(r,n),e.pieces.delete(o)),e.lastMove=[o,r],e.check=void 0,M(e.events.change),i||!0}function se(e,o,r,n){if(e.pieces.has(r))if(n)e.pieces.delete(r);else return!1;return M(e.events.dropNewPiece,o,r),e.pieces.set(r,o),e.lastMove=[r],e.check=void 0,M(e.events.change),e.movable.dests=void 0,e.turnColor=I(e.turnColor),!0}function eo(e,o,r){let n=Me(e,o,r);return n&&(e.movable.dests=void 0,e.turnColor=I(e.turnColor),e.animation.current=void 0),n}function xe(e,o,r){if(de(e,o,r)){let n=eo(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),M(e.movable.events.after,o,r,i),!0}}else if(rr(e,o,r))return _o(e,o,r,{ctrlKey:e.stats.ctrlKey}),P(e),!0;return P(e),!1}function le(e,o,r,n){let t=e.pieces.get(o);t&&(or(e,o,r)||n)?(e.pieces.delete(o),se(e,t,r,n),M(e.movable.events.afterNewPiece,t.role,r,{premove:!1,predrop:!1})):t&&nr(e,o,r)?Jo(e,t.role,r):(C(e),K(e)),e.pieces.delete(o),P(e)}function Q(e,o,r){if(M(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&&xe(e,e.selected,o)){e.stats.dragged=!1;return}}(e.selectable.enabled||e.draggable.enabled)&&(oo(e,o)||De(e,o))&&(ke(e,o),e.hold.start())}function ke(e,o){e.selected=o,De(e,o)?e.premovable.customDests||(e.premovable.dests=Pe(e,o)):e.premovable.dests=void 0}function P(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function oo(e,o){let r=e.pieces.get(o);return!!r&&(e.movable.color==="both"||e.movable.color===r.color&&e.turnColor===r.color)}var de=(e,o,r)=>o!==r&&oo(e,o)&&(e.movable.free||!!e.movable.dests?.get(o)?.includes(r));function or(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 De(e,o){let r=e.pieces.get(o);return!!r&&e.premovable.enabled&&e.movable.color===r.color&&e.turnColor!==r.color}var rr=(e,o,r)=>o!==r&&De(e,o)&&(e.premovable.customDests?.get(o)??Pe(e,o)).includes(r);function nr(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 ro(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 no(e){let o=e.premovable.current;if(!o)return!1;let r=o[0],n=o[1],t=!1;if(de(e,r,n)){let i=eo(e,r,n);if(i){let a={premove:!0};i!==!0&&(a.captured=i),M(e.movable.events.after,r,n,a),t=!0}}return C(e),t}function to(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};se(e,t,r.key)&&(M(e.movable.events.afterNewPiece,r.role,r.key,{premove:!1,predrop:!0}),n=!0)}return K(e),n}function _(e){C(e),K(e),P(e)}function Ce(e){e.movable.color=e.movable.dests=e.animation.current=void 0,_(e)}function E(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?S([n,t]):void 0}function io(e,o,r,n){let t=g(e),i=te.filter(s=>je(t[0],t[1],s[0],s[1])||ce(t[0],t[1],s[0],s[1])),c=i.map(s=>ae(S(s),r,n)).map(s=>V(o,s)),[,l]=c.reduce((s,u,d)=>s[0]<u?s:[u,d],[c[0],0]);return S(i[l])}var b=e=>e.orientation==="white";var Ee="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",tr={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},ir={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};function ue(e){e==="start"&&(e=Ee);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=o.get(S([n-1,r]));i&&(i.promoted=!0);break}default:{let i=t.charCodeAt(0);if(i<57)n+=i-48;else{let a=t.toLowerCase();o.set(S([n,r]),{role:tr[a],color:t===a?"black":"white"}),++n}}}return o}function ao(e){return ze.map(o=>G.map(r=>{let n=e.get(r+o);if(n){let t=ir[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 Ae(e,o){o.animation&&(Ne(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=[]),Ne(e,o),o.fen&&(e.pieces=ue(o.fen),e.drawable.shapes=o.drawable?.shapes||[]),"check"in o&&Je(e,o.check||!1),"lastMove"in o&&!o.lastMove?e.lastMove=void 0:o.lastMove&&(e.lastMove=o.lastMove),e.selected&&ke(e,e.selected),Ae(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 Ne(e,o){for(let r in o)r==="__proto__"||r==="constructor"||!Object.prototype.hasOwnProperty.call(o,r)||(Object.prototype.hasOwnProperty.call(e,r)&&co(e[r])&&co(o[r])?Ne(e[r],o[r]):e[r]=o[r])}function co(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?lr(e,o):R(e,o);function R(e,o){let r=e(o);return o.dom.redraw(),r}var He=(e,o)=>({key:e,pos:g(e),piece:o}),cr=(e,o)=>o.sort((r,n)=>V(e.pos,r.pos)-V(e.pos,n.pos))[0];function sr(e,o){let r=new Map,n=[],t=new Map,i=[],a=[],c=new Map,l,s,u;for(let[d,p]of e)c.set(d,He(d,p));for(let d of ne)l=o.pieces.get(d),s=c.get(d),l?s?Z(l,s.piece)||(i.push(s),a.push(He(d,l))):a.push(He(d,l)):s&&i.push(s);for(let d of a)s=cr(d,i.filter(p=>Z(d.piece,p.piece))),s&&(u=[s.pos[0]-d.pos[0],s.pos[1]-d.pos[1]],r.set(d.key,u.concat(u)),n.push(s.key));for(let d of i)n.includes(d.key)||t.set(d.key,d.piece);return{anims:r,fadings:t}}function so(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=dr(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())=>so(e,i))}}function lr(e,o){let r=new Map(o.pieces),n=e(o),t=sr(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||so(o,performance.now())}else o.dom.redraw();return n}var dr=e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1;var ur=["green","red","blue","yellow"];function lo(e,o){if(o.touches&&o.touches.length>1)return;o.stopPropagation(),o.preventDefault(),o.ctrlKey?P(e):_(e);let r=T(o),n=E(r,b(e),e.dom.bounds());n&&(e.drawable.current={orig:n,pos:r,brush:pr(o),snapToValidMove:e.drawable.defaultSnapToValidMove},uo(e))}function uo(e){requestAnimationFrame(()=>{let o=e.drawable.current;if(o){let r=E(o.pos,b(e),e.dom.bounds());r||(o.snapToValidMove=!1);let n=o.snapToValidMove?io(o.orig,o.pos,b(e),e.dom.bounds()):r;n!==o.mouseSq&&(o.mouseSq=n,o.dest=n!==o.orig?n:void 0,e.dom.redrawNow()),uo(e)}})}function po(e,o){e.drawable.current&&(e.drawable.current.pos=T(o))}function fo(e){let o=e.drawable.current;o&&(o.mouseSq&&fr(e.drawable,o),Te(e))}function Te(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function go(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),mo(e.drawable))}function pr(e){let o=(e.shiftKey||e.ctrlKey)&&ie(e),r=e.altKey||e.metaKey||e.getModifierState?.("AltGraph");return ur[(o?1:0)+(r?2:0)]}function fr(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}),mo(e)}function mo(e){e.onChange&&e.onChange(e.shapes)}function bo(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=E(n,b(e),r);if(!t)return;let i=e.pieces.get(t),a=e.selected;if(!a&&e.drawable.enabled&&(e.drawable.eraseOnClick||!i||i.color!==e.turnColor)&&go(e),o.cancelable!==!1&&(!o.touches||e.blockTouchScroll||i||a||mr(e,n)))o.preventDefault();else if(o.touches)return;let c=!!e.premovable.current,l=!!e.predroppable.current;e.stats.ctrlKey=o.ctrlKey,e.selected&&de(e,e.selected,t)?O(d=>Q(d,t),e):Q(e,t);let s=e.selected===t,u=wo(e,t);if(i&&u&&s&&ro(e,t)){e.draggable.current={orig:t,piece:i,origPos:n,pos:n,started:e.draggable.autoDistance&&e.stats.dragged,element:u,previouslySelected:a,originTarget:o.target,keyHasChanged:!1},u.cgDragging=!0,u.classList.add("dragging");let d=e.dom.elements.ghost;d&&(d.className=`ghost ${i.color} ${i.role}`,x(d,L(r)(g(t),b(e))),X(d,!0)),qe(e)}else c&&C(e),l&&K(e);e.dom.redraw()}function mr(e,o){let r=b(e),n=e.dom.bounds(),t=Math.pow(n.width/8,2);for(let i of e.pieces.keys()){let a=ae(i,r,n);if(V(a,o)<=t)return!0}return!1}function ho(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:()=>wo(e,t),originTarget:r.target,newPiece:!0,force:!!n,keyHasChanged:!1},qe(e)}function qe(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))F(e);else if(!o.started&&V(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();x(o.element,[o.pos[0]-n.left-n.width/16,o.pos[1]-n.top-n.height/16]),o.keyHasChanged||=o.orig!==E(o.pos,b(e),n)}qe(e)})}function vo(e,o){e.draggable.current&&(!o.touches||o.touches.length<2)&&(e.draggable.current.pos=T(o))}function yo(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}C(e),K(e);let n=T(o)||r.pos,t=E(n,b(e),e.dom.bounds());t&&r.started&&r.orig!==t?r.newPiece?le(e,r.orig,t,r.force):(e.stats.ctrlKey=o.ctrlKey,xe(e,r.orig,t)&&(e.stats.dragged=!0)):r.newPiece?e.pieces.delete(r.orig):e.draggable.deleteOnDropOff&&!t&&(e.pieces.delete(r.orig),M(e.events.change)),(r.orig===r.previouslySelected||r.keyHasChanged)&&(r.orig===t||!t)?P(e):e.selectable.enabled||P(e),So(e),e.draggable.current=void 0,e.dom.redraw()}function F(e){let o=e.draggable.current;o&&(o.newPiece&&e.pieces.delete(o.orig),e.draggable.current=void 0,P(e),So(e),e.dom.redraw())}function So(e){let o=e.dom.elements;o.ghost&&X(o.ghost,!1)}function wo(e,o){let r=e.dom.elements.board.firstChild;for(;r;){if(r.cgKey===o&&r.tagName==="PIECE")return r;r=r.nextSibling}}function Mo(e,o){e.exploding={stage:1,keys:o},e.dom.redraw(),setTimeout(()=>{Po(e,2),setTimeout(()=>Po(e,void 0),120)},120)}function Po(e,o){e.exploding&&(o?e.exploding.stage=o:e.exploding=void 0,e.dom.redraw())}function xo(e,o){function r(){Qe(e),o()}return{set(n){n.orientation&&n.orientation!==e.orientation&&r(),Ae(e,n),(n.fen?O:R)(t=>pe(t,n),e)},state:e,getFen:()=>ao(e.pieces),toggleOrientation:r,setPieces(n){O(t=>_e(t,n),e)},selectSquare(n,t){n?O(i=>Q(i,n,t),e):e.selected&&(P(e),e.dom.redraw())},move(n,t){O(i=>Me(i,n,t),e)},newPiece(n,t){O(i=>se(i,n,t),e)},playPremove(){if(e.premovable.current){if(O(no,e))return!0;e.dom.redraw()}return!1},playPredrop(n){if(e.predroppable.current){let t=to(e,n);return e.dom.redraw(),t}return!1},cancelPremove(){R(C,e)},cancelPredrop(){R(K,e)},cancelMove(){R(n=>{_(n),F(n)},e)},stop(){R(n=>{Ce(n),F(n)},e)},explode(n){Mo(e,n)},setAutoShapes(n){R(t=>t.drawable.autoShapes=n,e)},setShapes(n){R(t=>t.drawable.shapes=n.slice(),e)},getKeyAtDomPos(n){return E(n,b(e),e.dom.bounds())},redrawAll:o,dragNewPiece(n,t,i){ho(e,n,t,i)},destroy(){Ce(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}function ko(){return{pieces:ue(Ee),orientation:"white",turnColor:"white",coordinates:!0,coordinatesOnSquares:!1,ranksPosition:"right",autoCastle:!0,viewOnly:!1,disableContextMenu:!1,addPieceZIndex:!1,blockTouchScroll:!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,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,eraseOnClick:!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}},prevSvgHash:""},hold:Ie()}}var Do={hilitePrimary:{key:"hilitePrimary",color:"#3291ff",opacity:1,lineWidth:1},hiliteWhite:{key:"hiliteWhite",color:"#ffffff",opacity:1,lineWidth:1}};function Eo(){let e=h("defs"),o=w(h("filter"),{id:"cg-filter-blur"});return o.appendChild(w(h("feGaussianBlur"),{stdDeviation:"0.019"})),e.appendChild(o),e}function Ao(e,o,r){let n=e.drawable,t=n.current,i=t&&t.mouseSq?t:void 0,a=new Map,c=e.dom.bounds(),l=n.autoShapes.filter(p=>!p.piece);for(let p of n.shapes.concat(l).concat(i?[i]:[])){if(!p.dest)continue;let v=a.get(p.dest)??new Set,y=me(ge(g(p.orig),e.orientation),c),f=me(ge(g(p.dest),e.orientation),c);v.add(Re(y,f)),a.set(p.dest,v)}let s=n.shapes.concat(l).map(p=>({shape:p,current:!1,hash:Co(p,Oe(p.dest,a),!1,c)}));i&&s.push({shape:i,current:!0,hash:Co(i,Oe(i.dest,a),!0,c)});let u=s.map(p=>p.hash).join(";");if(u===e.drawable.prevSvgHash)return;e.drawable.prevSvgHash=u;let d=o.querySelector("defs");hr(n,s,d),vr(s,o.querySelector("g"),r.querySelector("g"),p=>wr(e,p,n.brushes,a,c))}function hr(e,o,r){let n=new Map,t;for(let c of o.filter(l=>l.shape.dest&&l.shape.brush))t=No(e.brushes[c.shape.brush],c.shape.modifiers),c.shape.modifiers?.hilite&&n.set(fe(t).key,fe(t)),n.set(t.key,t);let i=new Set,a=r.firstElementChild;for(;a;)i.add(a.getAttribute("cgKey")),a=a.nextElementSibling;for(let[c,l]of n.entries())i.has(c)||r.appendChild(xr(l))}function vr(e,o,r,n){let t=new Map;for(let i of e)t.set(i.hash,!1);for(let i of[o,r]){let a=[],c=i.firstElementChild,l;for(;c;)l=c.getAttribute("cgHash"),t.has(l)?t.set(l,!0):a.push(c),c=c.nextElementSibling;for(let s of a)i.removeChild(s)}for(let i of e.filter(a=>!t.get(a.hash)))for(let a of n(i))a.isCustom?r.appendChild(a.el):o.appendChild(a.el)}function Co({orig:e,dest:o,brush:r,piece:n,modifiers:t,customSvg:i,label:a},c,l,s){return[s.width,s.height,l,e,o,r,c&&"-",n&&yr(n),t&&Sr(t),i&&`custom-${Ko(i.html)},${i.center?.[0]??"o"}`,a&&`label-${Ko(a.text)}`].filter(u=>u).join(",")}function yr(e){return[e.color,e.role,e.scale].filter(o=>o).join(",")}function Sr(e){return[e.lineWidth,e.hilite&&"*"].filter(o=>o).join(",")}function Ko(e){let o=0;for(let r=0;r<e.length;r++)o=(o<<5)-o+e.charCodeAt(r)>>>0;return o.toString()}function wr(e,{shape:o,current:r,hash:n},t,i,a){let c=me(ge(g(o.orig),e.orientation),a),l=o.dest?me(ge(g(o.dest),e.orientation),a):c,s=o.brush&&No(t[o.brush],o.modifiers),u=i.get(o.dest),d=[];if(s){let p=w(h("g"),{cgHash:n});d.push({el:p}),c[0]!==l[0]||c[1]!==l[1]?p.appendChild(Mr(o,s,c,l,r,Oe(o.dest,i))):p.appendChild(Pr(t[o.brush],c,r,a))}if(o.label){let p=o.label;p.fill??=o.brush&&t[o.brush].color;let v=o.brush?void 0:"tr";d.push({el:kr(p,n,c,l,u,v),isCustom:!0})}if(o.customSvg){let p=o.customSvg.center??"orig",[v,y]=p==="label"?To(c,l,u).map(W=>W-.5):p==="dest"?l:c,f=w(h("g"),{transform:`translate(${v},${y})`,cgHash:n});f.innerHTML=`<svg width="1" height="1" viewBox="0 0 100 100">${o.customSvg.html}</svg>`,d.push({el:f,isCustom:!0})}return d}function Pr(e,o,r,n){let t=Dr(),i=(n.width+n.height)/(4*Math.max(n.width,n.height));return w(h("circle"),{stroke:e.color,"stroke-width":t[r?0:1],fill:"none",opacity:Ho(e,r),cx:o[0],cy:o[1],r:i-t[1]/2})}function fe(e){return["#ffffff","#fff","white"].includes(e.color)?Do.hilitePrimary:Do.hiliteWhite}function Mr(e,o,r,n,t,i){function a(s){let u=Kr(i&&!t),d=n[0]-r[0],p=n[1]-r[1],v=Math.atan2(p,d),y=Math.cos(v)*u,f=Math.sin(v)*u;return w(h("line"),{stroke:s?fe(o).color:o.color,"stroke-width":Cr(o,t)+(s?.04:0),"stroke-linecap":"round","marker-end":`url(#arrowhead-${s?fe(o).key:o.key})`,opacity:e.modifiers?.hilite?1:Ho(o,t),x1:r[0],y1:r[1],x2:n[0]-y,y2:n[1]-f})}if(!e.modifiers?.hilite)return a(!1);let c=h("g"),l=w(h("g"),{filter:"url(#cg-filter-blur)"});return l.appendChild(Er(r,n)),l.appendChild(a(!0)),c.appendChild(l),c.appendChild(a(!1)),c}function xr(e){let o=w(h("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(h("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),o.setAttribute("cgKey",e.key),o}function kr(e,o,r,n,t,i){let c=.4*.75**e.text.length,l=To(r,n,t),s=i==="tr"?.4:0,u=w(h("g"),{transform:`translate(${l[0]+s},${l[1]-s})`,cgHash:o});u.appendChild(w(h("circle"),{r:.4/2,"fill-opacity":i?1:.8,"stroke-opacity":i?1:.7,"stroke-width":.03,fill:e.fill??"#666",stroke:"white"}));let d=w(h("text"),{"font-size":c,"font-family":"Noto Sans","text-anchor":"middle",fill:"white",y:.13*.75**e.text.length});return d.innerHTML=e.text,u.appendChild(d),u}function ge(e,o){return o==="white"?e:[7-e[0],7-e[1]]}function Oe(e,o){return(e&&o.has(e)&&o.get(e).size>1)===!0}function h(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 No(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 Dr(){return[3/64,4/64]}function Cr(e,o){return(e.lineWidth||10)*(o?.85:1)/64}function Ho(e,o){return(e.opacity||1)*(o?.9:1)}function Kr(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 Er(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(h("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 Re(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 Ar(e,o){return Math.sqrt([e[0]-o[0],e[1]-o[1]].reduce((r,n)=>r+n*n,0))}function To(e,o,r){let n=Ar(e,o),t=Re(e,o,!1);if(r&&(n-=33/64,r.size>1)){n-=10/64;let i=Re(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 qo(e,o){e.innerHTML="",e.classList.add("cg-wrap");for(let l of Fe)e.classList.toggle("orientation-"+l,o.orientation===l);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;if(o.drawable.visible&&(t=w(h("svg"),{class:"cg-shapes",viewBox:"-4 -4 8 8",preserveAspectRatio:"xMidYMid slice"}),t.appendChild(Eo()),t.appendChild(h("g")),i=w(h("svg"),{class:"cg-custom-svgs",viewBox:"-3.5 -3.5 8 8",preserveAspectRatio:"xMidYMid slice"}),i.appendChild(h("g")),a=k("cg-auto-pieces"),r.appendChild(t),r.appendChild(i),r.appendChild(a)),o.coordinates){let l=o.orientation==="black"?" black":"",s=o.ranksPosition==="left"?" left":"";if(o.coordinatesOnSquares){let u=o.orientation==="white"?d=>d+1:d=>8-d;G.forEach((d,p)=>r.appendChild(Be($.map(v=>d+v),"squares rank"+u(p)+l+s)))}else r.appendChild(Be($,"ranks"+l+s)),r.appendChild(Be(G,"files"+l))}let c;return o.draggable.enabled&&o.draggable.showGhost&&(c=k("piece","ghost"),X(c,!1),r.appendChild(c)),{board:n,container:r,wrap:e,ghost:c,svg:t,customSvg:i,autoPieces:a}}function Be(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 Oo(e,o){if(!e.dropmode.active)return;C(e),K(e);let r=e.dropmode.piece;if(r){e.pieces.set("a0",r);let n=T(o),t=n&&E(n,b(e),e.dom.bounds());t&&le(e,"a0",t)}e.dom.redraw()}function Bo(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=Hr(e);r.addEventListener("touchstart",n,{passive:!1}),r.addEventListener("mousedown",n,{passive:!1})}function Vo(e,o){let r=[];if("ResizeObserver"in window||r.push(J(document.body,"chessground.resize",o)),!e.viewOnly){let n=Ro(e,vo,po),t=Ro(e,yo,fo);for(let a of["touchmove","mousemove"])r.push(J(document,a,n));for(let a of["touchend","mouseup"])r.push(J(document,a,t));let i=()=>e.dom.bounds.clear();r.push(J(document,"scroll",i,{capture:!0,passive:!0})),r.push(J(window,"resize",i,{passive:!0}))}return()=>r.forEach(n=>n())}function J(e,o,r,n){return e.addEventListener(o,r,n),()=>e.removeEventListener(o,r,n)}var Hr=e=>o=>{e.draggable.current?F(e):e.drawable.current?Te(e):o.shiftKey||ie(o)?e.drawable.enabled&&lo(e,o):e.viewOnly||(e.dropmode.active?Oo(e,o):bo(e,o))},Ro=(e,o,r)=>n=>{e.drawable.current?e.drawable.enabled&&r(e,n):e.viewOnly||o(e,n)};function Go(e){let o=b(e),r=L(e.dom.bounds()),n=e.dom.elements.board,t=e.pieces,i=e.animation.current,a=i?i.plan.anims:new Map,c=i?i.plan.fadings:new Map,l=e.draggable.current,s=qr(e),u=new Set,d=new Set,p=new Map,v=new Map,y,f,W,z,D,j,be,A,he,oe;for(f=n.firstChild;f;){if(y=f.cgKey,Wo(f))if(W=t.get(y),D=a.get(y),j=c.get(y),z=f.cgPiece,f.cgDragging&&(!l||l.orig!==y)&&(f.classList.remove("dragging"),x(f,r(g(y),o)),f.cgDragging=!1),!j&&f.cgFading&&(f.cgFading=!1,f.classList.remove("fading")),W){if(D&&f.cgAnimating&&z===ee(W)){let m=g(y);m[0]+=D[2],m[1]+=D[3],f.classList.add("anim"),x(f,r(m,o))}else f.cgAnimating&&(f.cgAnimating=!1,f.classList.remove("anim"),x(f,r(g(y),o)),e.addPieceZIndex&&(f.style.zIndex=Ve(g(y),o)));z===ee(W)&&(!j||!f.cgFading)?u.add(y):j&&z===ee(j)?(f.classList.add("fading"),f.cgFading=!0):Le(p,z,f)}else Le(p,z,f);else if(zo(f)){let m=f.className;s.get(y)===m?d.add(y):Le(v,m,f)}f=f.nextSibling}for(let[m,U]of s)if(!d.has(m)){he=v.get(U),oe=he&&he.pop();let N=r(g(m),o);if(oe)oe.cgKey=m,x(oe,N);else{let H=k("square",U);H.cgKey=m,x(H,N),n.insertBefore(H,n.firstChild)}}for(let[m,U]of t)if(D=a.get(m),!u.has(m))if(be=p.get(ee(U)),A=be&&be.pop(),A){A.cgKey=m,A.cgFading&&(A.classList.remove("fading"),A.cgFading=!1);let N=g(m);e.addPieceZIndex&&(A.style.zIndex=Ve(N,o)),D&&(A.cgAnimating=!0,A.classList.add("anim"),N[0]+=D[2],N[1]+=D[3]),x(A,r(N,o))}else{let N=ee(U),H=k("piece",N),re=g(m);H.cgPiece=N,H.cgKey=m,D&&(H.cgAnimating=!0,re[0]+=D[2],re[1]+=D[3]),x(H,r(re,o)),e.addPieceZIndex&&(H.style.zIndex=Ve(re,o)),n.appendChild(H)}for(let m of p.values())Lo(e,m);for(let m of v.values())Lo(e,m)}function Fo(e){let o=b(e),r=L(e.dom.bounds()),n=e.dom.elements.board.firstChild;for(;n;)(Wo(n)&&!n.cgAnimating||zo(n))&&x(n,r(g(n.cgKey),o)),n=n.nextSibling}function Ge(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 Wo=e=>e.tagName==="PIECE",zo=e=>e.tagName==="SQUARE";function Lo(e,o){for(let r of o)e.dom.elements.board.removeChild(r)}function Ve(e,o){let n=e[1];return`${o?10-n:3+n}`}var ee=e=>`${e.color} ${e.role}`;function qr(e){let o=new Map;if(e.lastMove&&e.highlight.lastMove)for(let t of e.lastMove)B(o,t,"last-move");if(e.check&&e.highlight.check&&B(o,e.check,"check"),e.selected&&(B(o,e.selected,"selected"),e.movable.showDests)){let t=e.movable.dests?.get(e.selected);if(t)for(let a of t)B(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)B(o,a,"premove-dest"+(e.pieces.has(a)?" oc":""))}let r=e.premovable.current;if(r)for(let t of r)B(o,t,"current-premove");else e.predroppable.current&&B(o,e.predroppable.current.key,"current-premove");let n=e.exploding;if(n)for(let t of n.keys)B(o,t,"exploding"+n.stage);return e.highlight.custom&&e.highlight.custom.forEach((t,i)=>{B(o,i,t)}),o}function B(e,o,r){let n=e.get(o);n?e.set(o,`${n} ${r}`):e.set(o,r)}function Le(e,o,r){let n=e.get(o);n?n.push(r):e.set(o,[r])}function $o(e,o,r){let n=new Map,t=[];for(let c of e)n.set(c.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 c of t)o.removeChild(c);for(let c of e)n.get(c.hash)||o.appendChild(r(c))}function Io(e,o){let n=e.drawable.autoShapes.filter(t=>t.piece).map(t=>({shape:t,hash:Rr(t),current:!1}));$o(n,o,t=>Or(e,t,e.dom.bounds()))}function jo(e){let o=b(e),r=L(e.dom.bounds()),n=e.dom.elements.autoPieces?.firstChild;for(;n;)ve(n,r(g(n.cgKey),o),n.cgScale),n=n.nextSibling}function Or(e,{shape:o,hash:r},n){let t=o.orig,i=o.piece?.role,a=o.piece?.color,c=o.piece?.scale,l=k("piece",`${i} ${a}`);return l.setAttribute("cgHash",r),l.cgKey=t,l.cgScale=c,ve(l,L(n)(g(t),b(e)),c),l}var Rr=e=>[e.orig,e.piece?.role,e.piece?.color,e.piece?.scale].join(",");function Bn({el:e,config:o}){return Vr(e,o)}function Vr(e,o){let r=ko();pe(r,o||{});function n(){let t="dom"in r?r.dom.unbind:void 0,i=qo(e,r),a=$e(()=>i.board.getBoundingClientRect()),c=u=>{Go(s),i.autoPieces&&Io(s,i.autoPieces),!u&&i.svg&&Ao(s,i.svg,i.customSvg)},l=()=>{Ge(s),Fo(s),i.autoPieces&&jo(s)},s=r;return s.dom={elements:i,bounds:a,redraw:Lr(c),redrawNow:c,unbind:t},s.drawable.prevSvgHash="",Ge(s),c(!1),Bo(s,l),t||(s.dom.unbind=Vo(s,l)),s.events.insert&&s.events.insert(i),s}return xo(n(),n)}function Lr(e){let o=!1;return()=>{o||(o=!0,requestAnimationFrame(()=>{e(),o=!1}))}}export{Vr as Chessground,Bn as initModule};
package/dist/config.d.ts CHANGED
@@ -43,6 +43,7 @@ export interface Config {
43
43
  castle?: boolean;
44
44
  dests?: cg.Key[];
45
45
  customDests?: cg.Dests;
46
+ premoveThroughFriendlies?: boolean;
46
47
  events?: {
47
48
  set?: (orig: cg.Key, dest: cg.Key, metadata?: cg.SetPremoveMetadata) => void;
48
49
  unset?: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,IAAI,OAAO,EA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AG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;;YAC/B,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC"}
package/dist/premove.d.ts CHANGED
@@ -1,6 +1,3 @@
1
1
  import * as cg from './types.js';
2
- type Mobility = (x1: number, y1: number, x2: number, y2: number) => boolean;
3
- export declare const knight: Mobility;
4
- export declare const queen: Mobility;
5
- export declare function premove(pieces: cg.Pieces, key: cg.Key, canCastle: boolean): cg.Key[];
6
- export {};
2
+ import { HeadlessState } from './state.js';
3
+ export declare function premove(state: HeadlessState, key: cg.Key): cg.Key[];
package/dist/premove.js CHANGED
@@ -1,31 +1,50 @@
1
1
  import * as util from './util.js';
2
- const diff = (a, b) => Math.abs(a - b);
3
- const pawn = (color) => (x1, y1, x2, y2) => diff(x1, x2) < 2 &&
4
- (color === 'white'
5
- ? // allow 2 squares from first two ranks, for horde
6
- y2 === y1 + 1 || (y1 <= 1 && y2 === y1 + 2 && x1 === x2)
7
- : y2 === y1 - 1 || (y1 >= 6 && y2 === y1 - 2 && x1 === x2));
8
- export const knight = (x1, y1, x2, y2) => {
9
- const xd = diff(x1, x2);
10
- const yd = diff(y1, y2);
11
- return (xd === 1 && yd === 2) || (xd === 2 && yd === 1);
2
+ const squaresFriendlyPiecesBetween = (x1, y1, x2, y2, pieces, color) => util.squaresBetween(x1, y1, x2, y2).filter(sq => { var _a; return ((_a = pieces.get(sq)) === null || _a === void 0 ? void 0 : _a.color) === color; });
3
+ const noFriendliesBetweenOrJustOneEnPassantTarget = (x1, y1, x2, y2, pieces, color, lastMove) => {
4
+ const squaresFriendliesBetween = squaresFriendlyPiecesBetween(x1, y1, x2, y2, pieces, color);
5
+ if (!squaresFriendliesBetween.length)
6
+ return true;
7
+ if (squaresFriendliesBetween.length > 1 || !lastMove || squaresFriendliesBetween[0] !== lastMove[1])
8
+ return false;
9
+ const destKey = lastMove[1], srcPos = util.key2pos(lastMove[0]), destPos = util.key2pos(destKey), piece = pieces.get(destKey);
10
+ return (piece.role === 'pawn' &&
11
+ util.diff(srcPos[1], destPos[1]) === 2 &&
12
+ [1, -1].some(delta => {
13
+ const enemyPiece = pieces.get(util.pos2key([destPos[0] + delta, destPos[1]]));
14
+ return (enemyPiece === null || enemyPiece === void 0 ? void 0 : enemyPiece.role) === 'pawn' && enemyPiece.color === util.opposite(piece.color);
15
+ }));
12
16
  };
13
- const bishop = (x1, y1, x2, y2) => {
14
- return diff(x1, x2) === diff(y1, y2);
17
+ const pawn = (pieces, color, premoveThroughFriendlies) => (x1, y1, x2, y2) => {
18
+ const step = color === 'white' ? 1 : -1;
19
+ if (util.diff(x1, x2) === 1)
20
+ return y2 === y1 + step;
21
+ return (x1 === x2 &&
22
+ (y2 === y1 + step ||
23
+ // allow 2 squares from first two ranks, for horde
24
+ (y2 === y1 + 2 * step && (color === 'white' ? y1 <= 1 : y1 >= 6))) &&
25
+ (premoveThroughFriendlies || !squaresFriendlyPiecesBetween(x1, y1, x2, y2 + step, pieces, color).length));
15
26
  };
16
- const rook = (x1, y1, x2, y2) => {
17
- return x1 === x2 || y1 === y2;
18
- };
19
- export const queen = (x1, y1, x2, y2) => {
20
- return bishop(x1, y1, x2, y2) || rook(x1, y1, x2, y2);
21
- };
22
- const king = (color, rookFiles, canCastle) => (x1, y1, x2, y2) => (diff(x1, x2) < 2 && diff(y1, y2) < 2) ||
27
+ const knight = (x1, y1, x2, y2) => util.knightDir(x1, y1, x2, y2);
28
+ const bishop = (pieces, color, premoveThroughFriendlies, lastMove) => (x1, y1, x2, y2) => util.bishopDir(x1, y1, x2, y2) &&
29
+ (premoveThroughFriendlies ||
30
+ noFriendliesBetweenOrJustOneEnPassantTarget(x1, y1, x2, y2, pieces, color, lastMove));
31
+ const rook = (pieces, color, premoveThroughFriendlies, lastMove) => (x1, y1, x2, y2) => util.rookDir(x1, y1, x2, y2) &&
32
+ (premoveThroughFriendlies ||
33
+ noFriendliesBetweenOrJustOneEnPassantTarget(x1, y1, x2, y2, pieces, color, lastMove));
34
+ const queen = (pieces, color, premoveThroughFriendlies, lastMove) => (x1, y1, x2, y2) => bishop(pieces, color, premoveThroughFriendlies, lastMove)(x1, y1, x2, y2) ||
35
+ rook(pieces, color, premoveThroughFriendlies, lastMove)(x1, y1, x2, y2);
36
+ const king = (pieces, color, premoveThroughFriendlies, rookFiles, canCastle) => (x1, y1, x2, y2) => (util.diff(x1, x2) < 2 && util.diff(y1, y2) < 2) ||
23
37
  (canCastle &&
24
38
  y1 === y2 &&
25
39
  y1 === (color === 'white' ? 0 : 7) &&
26
40
  ((x1 === 4 && ((x2 === 2 && rookFiles.includes(0)) || (x2 === 6 && rookFiles.includes(7)))) ||
27
- rookFiles.includes(x2)));
28
- function rookFilesOf(pieces, color) {
41
+ rookFiles.includes(x2)) &&
42
+ (premoveThroughFriendlies ||
43
+ /* The following checks if no non-rook friendly piece is in the way between the king and its castling destination.
44
+ Note that for the Chess960 edge case of Kb1 "long castling", the check passes even if there is a piece in the way
45
+ on c1. But this is fine, since the king can always premove recapturing Ra1. */
46
+ squaresFriendlyPiecesBetween(x1, y1, x2 > x1 ? 7 : 1, y2, pieces, color).every(s => pieces.get(s).role === 'rook')));
47
+ const rookFilesOf = (pieces, color) => {
29
48
  const backrank = color === 'white' ? '1' : '8';
30
49
  const files = [];
31
50
  for (const [key, piece] of pieces) {
@@ -34,22 +53,23 @@ function rookFilesOf(pieces, color) {
34
53
  }
35
54
  }
36
55
  return files;
37
- }
38
- export function premove(pieces, key, canCastle) {
56
+ };
57
+ export function premove(state, key) {
58
+ const pieces = state.pieces, canCastle = state.premovable.castle, premoveThroughFriendlies = !!state.premovable.premoveThroughFriendlies;
39
59
  const piece = pieces.get(key);
40
60
  if (!piece)
41
61
  return [];
42
62
  const pos = util.key2pos(key), r = piece.role, mobility = r === 'pawn'
43
- ? pawn(piece.color)
63
+ ? pawn(pieces, piece.color, premoveThroughFriendlies)
44
64
  : r === 'knight'
45
65
  ? knight
46
66
  : r === 'bishop'
47
- ? bishop
67
+ ? bishop(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
48
68
  : r === 'rook'
49
- ? rook
69
+ ? rook(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
50
70
  : r === 'queen'
51
- ? queen
52
- : king(piece.color, rookFilesOf(pieces, piece.color), canCastle);
71
+ ? queen(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
72
+ : king(pieces, piece.color, premoveThroughFriendlies, rookFilesOf(pieces, piece.color), canCastle);
53
73
  return util.allPos
54
74
  .filter(pos2 => (pos[0] !== pos2[0] || pos[1] !== pos2[1]) && mobility(pos[0], pos[1], pos2[0], pos2[1]))
55
75
  .map(util.pos2key);
@@ -1 +1 @@
1
- {"version":3,"file":"premove.js","sourceRoot":"","sources":["../src/premove.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAKlC,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,MAAM,IAAI,GACR,CAAC,KAAe,EAAY,EAAE,CAC9B,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CACjB,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC;IAChB,CAAC,KAAK,KAAK,OAAO;QAChB,CAAC,CAAC,kDAAkD;YAClD,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,C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K,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,CAAC,QAAQ,CAAC;oBACrE,CAAC,CAAC,CAAC,KAAK,OAAO;wBACb,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,CAAC,QAAQ,CAAC;wBACtE,CAAC,CAAC,IAAI,CACF,MAAM,EACN,KAAK,CAAC,KAAK,EACX,wBAAwB,EACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAChC,SAAS,CACV,CAAC;IAClB,OAAO,IAAI,CAAC,MAAM;SACf,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACxG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC"}
package/dist/state.d.ts CHANGED
@@ -48,6 +48,7 @@ export interface HeadlessState {
48
48
  dests?: cg.Key[];
49
49
  customDests?: cg.Dests;
50
50
  current?: cg.KeyPair;
51
+ premoveThroughFriendlies?: boolean;
51
52
  events: {
52
53
  set?: (orig: cg.Key, dest: cg.Key, metadata?: cg.SetPremoveMetadata) => void;
53
54
  unset?: () => void;
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;AAIhC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AA0GlC,MAAM,UAAU,QAAQ;IACtB,OAAO;QACL,MAAM,EAAE,G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AE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;gBACtE,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;gBACvE,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;gBACrE,QAAQ,EAAE;oBACR,GAAG,EAAE,KAAK;oBACV,KAAK,EAAE,SAAS;oBAChB,OAAO,EAAE,IAAI;oBACb,SAAS,EAAE,EAAE;iBACd;gBACD,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE;gBACzE,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE;gBACpE,KAAK,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;aACnE;YACD,WAAW,EAAE,EAAE;SAChB;QACD,IAAI,EAAE,KAAK,EAAE;KACd,CAAC;AACJ,CAAC"}
package/dist/types.d.ts CHANGED
@@ -92,3 +92,4 @@ export declare const ranks: readonly ["1", "2", "3", "4", "5", "6", "7", "8"];
92
92
  export type RanksPosition = 'left' | 'right';
93
93
  export type BrushColor = 'green' | 'red' | 'blue' | 'yellow';
94
94
  export type SquareClasses = Map<Key, string>;
95
+ export type DirectionalCheck = (x1: number, y1: number, x2: number, y2: number) => boolean;
package/dist/util.d.ts CHANGED
@@ -18,3 +18,12 @@ export declare const eventPosition: (e: cg.MouchEvent) => cg.NumberPair | undefi
18
18
  export declare const isRightButton: (e: cg.MouchEvent) => boolean;
19
19
  export declare const createEl: (tagName: string, className?: string) => HTMLElement;
20
20
  export declare function computeSquareCenter(key: cg.Key, asWhite: boolean, bounds: DOMRectReadOnly): cg.NumberPair;
21
+ export declare const diff: (a: number, b: number) => number;
22
+ export declare const knightDir: cg.DirectionalCheck;
23
+ export declare const rookDir: cg.DirectionalCheck;
24
+ export declare const bishopDir: cg.DirectionalCheck;
25
+ export declare const queenDir: cg.DirectionalCheck;
26
+ /** Return all board squares between (x1, y1) and (x2, y2) exclusive,
27
+ * along a straight line (rook or bishop path). Returns [] if not aligned, or none between.
28
+ */
29
+ export declare const squaresBetween: (x1: number, y1: number, x2: number, y2: number) => cg.Key[];
package/dist/util.js CHANGED
@@ -86,4 +86,34 @@ export function computeSquareCenter(key, asWhite, bounds) {
86
86
  bounds.top + (bounds.height * (7 - pos[1])) / 8 + bounds.height / 16,
87
87
  ];
88
88
  }
89
+ export const diff = (a, b) => Math.abs(a - b);
90
+ export const knightDir = (x1, y1, x2, y2) => {
91
+ const xd = diff(x1, x2);
92
+ const yd = diff(y1, y2);
93
+ return (xd === 1 && yd === 2) || (xd === 2 && yd === 1);
94
+ };
95
+ export const rookDir = (x1, y1, x2, y2) => x1 === x2 || y1 === y2;
96
+ export const bishopDir = (x1, y1, x2, y2) => diff(x1, x2) === diff(y1, y2);
97
+ export const queenDir = (x1, y1, x2, y2) => rookDir(x1, y1, x2, y2) || bishopDir(x1, y1, x2, y2);
98
+ /** Return all board squares between (x1, y1) and (x2, y2) exclusive,
99
+ * along a straight line (rook or bishop path). Returns [] if not aligned, or none between.
100
+ */
101
+ export const squaresBetween = (x1, y1, x2, y2) => {
102
+ const dx = x2 - x1;
103
+ const dy = y2 - y1;
104
+ // Must be a straight or diagonal line
105
+ if (dx && dy && Math.abs(dx) !== Math.abs(dy))
106
+ return [];
107
+ // Determine step direction
108
+ const stepX = dx === 0 ? 0 : dx > 0 ? 1 : -1;
109
+ const stepY = dy === 0 ? 0 : dy > 0 ? 1 : -1;
110
+ const squares = [];
111
+ let x = x1 + stepX, y = y1 + stepY;
112
+ while (x !== x2 || y !== y2) {
113
+ squares.push([x, y]);
114
+ x += stepX;
115
+ y += stepY;
116
+ }
117
+ return squares.map(sq => pos2key(sq));
118
+ };
89
119
  //# sourceMappingURL=util.js.map
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,KAAK,CAAC,SAAS,CAAC,MAAM,CAC9D,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAuB,EAAwB,EAAE;IACzE,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,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AAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAChB,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IACjB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC,IAAI,KAAK,CAAC;QACX,CAAC,IAAI,KAAK,CAAC;IACb,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@lichess-org/chessground",
3
- "version": "9.2.3",
3
+ "version": "9.3.1",
4
+ "//": "version is managed by the build system",
4
5
  "description": "lichess.org chess ui",
5
6
  "type": "module",
6
7
  "main": "dist/chessground.js",
@@ -22,8 +23,20 @@
22
23
  "@typescript-eslint/parser": "^7.7.0",
23
24
  "esbuild": "^0.25.0",
24
25
  "eslint": "^8.57.0",
26
+ "jsdom": "^26.1.0",
25
27
  "prettier": "^3.2.5",
26
- "typescript": "^5.6.3"
28
+ "typescript": "^5.6.3",
29
+ "vitest": "^3.2.4"
30
+ },
31
+ "scripts": {
32
+ "prepare": "$npm_execpath run compile",
33
+ "compile": "tsc --sourceMap --declaration",
34
+ "lint": "eslint src/*.ts",
35
+ "format": "prettier --write .",
36
+ "check-format": "prettier --check .",
37
+ "bundle": "esbuild src/chessground.ts --bundle --format=esm --outfile=dist/chessground.min.js --minify",
38
+ "dist": "$npm_execpath run compile && $npm_execpath run bundle",
39
+ "test": "vitest"
27
40
  },
28
41
  "files": [
29
42
  "/dist/*.js",
@@ -47,12 +60,5 @@
47
60
  "url": "https://github.com/lichess-org/chessground/issues"
48
61
  },
49
62
  "funding": "https://lichess.org/patron",
50
- "scripts": {
51
- "compile": "tsc --sourceMap --declaration",
52
- "lint": "eslint src/*.ts",
53
- "format": "prettier --write .",
54
- "check-format": "prettier --check .",
55
- "bundle": "esbuild src/chessground.ts --bundle --format=esm --outfile=dist/chessground.min.js --minify",
56
- "dist": "$npm_execpath run compile && $npm_execpath run bundle"
57
- }
58
- }
63
+ "packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
64
+ }
package/src/board.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import { HeadlessState } from './state.js';
2
- import { pos2key, key2pos, opposite, distanceSq, allPos, computeSquareCenter } from './util.js';
3
- import { premove, queen, knight } from './premove.js';
2
+ import {
3
+ pos2key,
4
+ key2pos,
5
+ opposite,
6
+ distanceSq,
7
+ allPos,
8
+ computeSquareCenter,
9
+ queenDir,
10
+ knightDir,
11
+ } from './util.js';
12
+ import { premove } from './premove.js';
4
13
  import * as cg from './types.js';
5
14
 
6
15
  export function callUserFunction<T extends (...args: any[]) => void>(
@@ -208,12 +217,9 @@ export function selectSquare(state: HeadlessState, key: cg.Key, force?: boolean)
208
217
 
209
218
  export function setSelected(state: HeadlessState, key: cg.Key): void {
210
219
  state.selected = key;
211
- if (isPremovable(state, key)) {
212
- // calculate chess premoves if custom premoves are not passed
213
- if (!state.premovable.customDests) {
214
- state.premovable.dests = premove(state.pieces, key, state.premovable.castle);
215
- }
216
- } else state.premovable.dests = undefined;
220
+ if (!isPremovable(state, key)) state.premovable.dests = undefined;
221
+ else if (!state.premovable.customDests) state.premovable.dests = premove(state, key);
222
+ // calculate chess premoves if custom premoves are not passed
217
223
  }
218
224
 
219
225
  export function unselect(state: HeadlessState): void {
@@ -256,11 +262,10 @@ function isPremovable(state: HeadlessState, orig: cg.Key): boolean {
256
262
  );
257
263
  }
258
264
 
259
- function canPremove(state: HeadlessState, orig: cg.Key, dest: cg.Key): boolean {
260
- const validPremoves: cg.Key[] =
261
- state.premovable.customDests?.get(orig) ?? premove(state.pieces, orig, state.premovable.castle);
262
- return orig !== dest && isPremovable(state, orig) && validPremoves.includes(dest);
263
- }
265
+ const canPremove = (state: HeadlessState, orig: cg.Key, dest: cg.Key): boolean =>
266
+ orig !== dest &&
267
+ isPremovable(state, orig) &&
268
+ (state.premovable.customDests?.get(orig) ?? premove(state, orig)).includes(dest);
264
269
 
265
270
  function canPredrop(state: HeadlessState, orig: cg.Key, dest: cg.Key): boolean {
266
271
  const piece = state.pieces.get(orig);
@@ -357,7 +362,8 @@ export function getSnappedKeyAtDomPos(
357
362
  const origPos = key2pos(orig);
358
363
  const validSnapPos = allPos.filter(
359
364
  pos2 =>
360
- queen(origPos[0], origPos[1], pos2[0], pos2[1]) || knight(origPos[0], origPos[1], pos2[0], pos2[1]),
365
+ queenDir(origPos[0], origPos[1], pos2[0], pos2[1]) ||
366
+ knightDir(origPos[0], origPos[1], pos2[0], pos2[1]),
361
367
  );
362
368
  const validSnapCenters = validSnapPos.map(pos2 => computeSquareCenter(pos2key(pos2), asWhite, bounds));
363
369
  const validSnapDistances = validSnapCenters.map(pos2 => distanceSq(pos, pos2));
package/src/config.ts CHANGED
@@ -47,6 +47,7 @@ export interface Config {
47
47
  castle?: boolean; // whether to allow king castle premoves
48
48
  dests?: cg.Key[]; // premove destinations for the current selection
49
49
  customDests?: cg.Dests; // use custom valid premoves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]}
50
+ premoveThroughFriendlies?: boolean; // if falsy, the positions of friendly pieces will be used to trim premove options
50
51
  events?: {
51
52
  set?: (orig: cg.Key, dest: cg.Key, metadata?: cg.SetPremoveMetadata) => void; // called after the premove has been set
52
53
  unset?: () => void; // called after the premove has been unset
package/src/premove.ts CHANGED
@@ -1,48 +1,120 @@
1
1
  import * as util from './util.js';
2
2
  import * as cg from './types.js';
3
+ import { HeadlessState } from './state.js';
3
4
 
4
5
  type Mobility = (x1: number, y1: number, x2: number, y2: number) => boolean;
5
6
 
6
- const diff = (a: number, b: number): number => Math.abs(a - b);
7
+ const squaresFriendlyPiecesBetween = (
8
+ x1: number,
9
+ y1: number,
10
+ x2: number,
11
+ y2: number,
12
+ pieces: cg.Pieces,
13
+ color: cg.Color,
14
+ ): cg.Key[] => util.squaresBetween(x1, y1, x2, y2).filter(sq => pieces.get(sq)?.color === color);
15
+
16
+ const noFriendliesBetweenOrJustOneEnPassantTarget = (
17
+ x1: number,
18
+ y1: number,
19
+ x2: number,
20
+ y2: number,
21
+ pieces: cg.Pieces,
22
+ color: cg.Color,
23
+ lastMove: cg.Key[] | undefined,
24
+ ): boolean => {
25
+ const squaresFriendliesBetween = squaresFriendlyPiecesBetween(x1, y1, x2, y2, pieces, color);
26
+ if (!squaresFriendliesBetween.length) return true;
27
+ if (squaresFriendliesBetween.length > 1 || !lastMove || squaresFriendliesBetween[0] !== lastMove[1])
28
+ return false;
29
+ const destKey = lastMove[1],
30
+ srcPos = util.key2pos(lastMove[0]),
31
+ destPos = util.key2pos(destKey),
32
+ piece = pieces.get(destKey)!;
33
+ return (
34
+ piece.role === 'pawn' &&
35
+ util.diff(srcPos[1], destPos[1]) === 2 &&
36
+ [1, -1].some(delta => {
37
+ const enemyPiece = pieces.get(util.pos2key([destPos[0] + delta, destPos[1]]));
38
+ return enemyPiece?.role === 'pawn' && enemyPiece.color === util.opposite(piece.color);
39
+ })
40
+ );
41
+ };
7
42
 
8
43
  const pawn =
9
- (color: cg.Color): Mobility =>
10
- (x1, y1, x2, y2) =>
11
- diff(x1, x2) < 2 &&
12
- (color === 'white'
13
- ? // allow 2 squares from first two ranks, for horde
14
- y2 === y1 + 1 || (y1 <= 1 && y2 === y1 + 2 && x1 === x2)
15
- : y2 === y1 - 1 || (y1 >= 6 && y2 === y1 - 2 && x1 === x2));
44
+ (pieces: cg.Pieces, color: cg.Color, premoveThroughFriendlies: boolean): Mobility =>
45
+ (x1, y1, x2, y2) => {
46
+ const step = color === 'white' ? 1 : -1;
47
+ if (util.diff(x1, x2) === 1) return y2 === y1 + step;
48
+ return (
49
+ x1 === x2 &&
50
+ (y2 === y1 + step ||
51
+ // allow 2 squares from first two ranks, for horde
52
+ (y2 === y1 + 2 * step && (color === 'white' ? y1 <= 1 : y1 >= 6))) &&
53
+ (premoveThroughFriendlies || !squaresFriendlyPiecesBetween(x1, y1, x2, y2 + step, pieces, color).length)
54
+ );
55
+ };
16
56
 
17
- export const knight: Mobility = (x1, y1, x2, y2) => {
18
- const xd = diff(x1, x2);
19
- const yd = diff(y1, y2);
20
- return (xd === 1 && yd === 2) || (xd === 2 && yd === 1);
21
- };
57
+ const knight: Mobility = (x1, y1, x2, y2) => util.knightDir(x1, y1, x2, y2);
22
58
 
23
- const bishop: Mobility = (x1, y1, x2, y2) => {
24
- return diff(x1, x2) === diff(y1, y2);
25
- };
59
+ const bishop =
60
+ (
61
+ pieces: cg.Pieces,
62
+ color: cg.Color,
63
+ premoveThroughFriendlies: boolean,
64
+ lastMove: cg.Key[] | undefined,
65
+ ): Mobility =>
66
+ (x1, y1, x2, y2) =>
67
+ util.bishopDir(x1, y1, x2, y2) &&
68
+ (premoveThroughFriendlies ||
69
+ noFriendliesBetweenOrJustOneEnPassantTarget(x1, y1, x2, y2, pieces, color, lastMove));
26
70
 
27
- const rook: Mobility = (x1, y1, x2, y2) => {
28
- return x1 === x2 || y1 === y2;
29
- };
71
+ const rook =
72
+ (
73
+ pieces: cg.Pieces,
74
+ color: cg.Color,
75
+ premoveThroughFriendlies: boolean,
76
+ lastMove: cg.Key[] | undefined,
77
+ ): Mobility =>
78
+ (x1, y1, x2, y2) =>
79
+ util.rookDir(x1, y1, x2, y2) &&
80
+ (premoveThroughFriendlies ||
81
+ noFriendliesBetweenOrJustOneEnPassantTarget(x1, y1, x2, y2, pieces, color, lastMove));
30
82
 
31
- export const queen: Mobility = (x1, y1, x2, y2) => {
32
- return bishop(x1, y1, x2, y2) || rook(x1, y1, x2, y2);
33
- };
83
+ const queen =
84
+ (
85
+ pieces: cg.Pieces,
86
+ color: cg.Color,
87
+ premoveThroughFriendlies: boolean,
88
+ lastMove: cg.Key[] | undefined,
89
+ ): Mobility =>
90
+ (x1, y1, x2, y2) =>
91
+ bishop(pieces, color, premoveThroughFriendlies, lastMove)(x1, y1, x2, y2) ||
92
+ rook(pieces, color, premoveThroughFriendlies, lastMove)(x1, y1, x2, y2);
34
93
 
35
94
  const king =
36
- (color: cg.Color, rookFiles: number[], canCastle: boolean): Mobility =>
95
+ (
96
+ pieces: cg.Pieces,
97
+ color: cg.Color,
98
+ premoveThroughFriendlies: boolean,
99
+ rookFiles: number[],
100
+ canCastle: boolean,
101
+ ): Mobility =>
37
102
  (x1, y1, x2, y2) =>
38
- (diff(x1, x2) < 2 && diff(y1, y2) < 2) ||
103
+ (util.diff(x1, x2) < 2 && util.diff(y1, y2) < 2) ||
39
104
  (canCastle &&
40
105
  y1 === y2 &&
41
106
  y1 === (color === 'white' ? 0 : 7) &&
42
107
  ((x1 === 4 && ((x2 === 2 && rookFiles.includes(0)) || (x2 === 6 && rookFiles.includes(7)))) ||
43
- rookFiles.includes(x2)));
108
+ rookFiles.includes(x2)) &&
109
+ (premoveThroughFriendlies ||
110
+ /* The following checks if no non-rook friendly piece is in the way between the king and its castling destination.
111
+ Note that for the Chess960 edge case of Kb1 "long castling", the check passes even if there is a piece in the way
112
+ on c1. But this is fine, since the king can always premove recapturing Ra1. */
113
+ squaresFriendlyPiecesBetween(x1, y1, x2 > x1 ? 7 : 1, y2, pieces, color).every(
114
+ s => pieces.get(s)!.role === 'rook',
115
+ )));
44
116
 
45
- function rookFilesOf(pieces: cg.Pieces, color: cg.Color) {
117
+ const rookFilesOf = (pieces: cg.Pieces, color: cg.Color) => {
46
118
  const backrank = color === 'white' ? '1' : '8';
47
119
  const files = [];
48
120
  for (const [key, piece] of pieces) {
@@ -51,25 +123,34 @@ function rookFilesOf(pieces: cg.Pieces, color: cg.Color) {
51
123
  }
52
124
  }
53
125
  return files;
54
- }
126
+ };
55
127
 
56
- export function premove(pieces: cg.Pieces, key: cg.Key, canCastle: boolean): cg.Key[] {
128
+ export function premove(state: HeadlessState, key: cg.Key): cg.Key[] {
129
+ const pieces = state.pieces,
130
+ canCastle = state.premovable.castle,
131
+ premoveThroughFriendlies = !!state.premovable.premoveThroughFriendlies;
57
132
  const piece = pieces.get(key);
58
133
  if (!piece) return [];
59
134
  const pos = util.key2pos(key),
60
135
  r = piece.role,
61
136
  mobility: Mobility =
62
137
  r === 'pawn'
63
- ? pawn(piece.color)
138
+ ? pawn(pieces, piece.color, premoveThroughFriendlies)
64
139
  : r === 'knight'
65
140
  ? knight
66
141
  : r === 'bishop'
67
- ? bishop
142
+ ? bishop(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
68
143
  : r === 'rook'
69
- ? rook
144
+ ? rook(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
70
145
  : r === 'queen'
71
- ? queen
72
- : king(piece.color, rookFilesOf(pieces, piece.color), canCastle);
146
+ ? queen(pieces, piece.color, premoveThroughFriendlies, state.lastMove)
147
+ : king(
148
+ pieces,
149
+ piece.color,
150
+ premoveThroughFriendlies,
151
+ rookFilesOf(pieces, piece.color),
152
+ canCastle,
153
+ );
73
154
  return util.allPos
74
155
  .filter(pos2 => (pos[0] !== pos2[0] || pos[1] !== pos2[1]) && mobility(pos[0], pos[1], pos2[0], pos2[1]))
75
156
  .map(util.pos2key);
package/src/state.ts CHANGED
@@ -51,6 +51,7 @@ export interface HeadlessState {
51
51
  dests?: cg.Key[]; // premove destinations for the current selection
52
52
  customDests?: cg.Dests; // use custom valid premoves. {"a2" ["a3" "a4"] "b1" ["a3" "c3"]}
53
53
  current?: cg.KeyPair; // keys of the current saved premove ["e2" "e4"]
54
+ premoveThroughFriendlies?: boolean; // if falsy, the positions of friendly pieces will be used to trim premove options
54
55
  events: {
55
56
  set?: (orig: cg.Key, dest: cg.Key, metadata?: cg.SetPremoveMetadata) => void; // called after the premove has been set
56
57
  unset?: () => void; // called after the premove has been unset
package/src/types.ts CHANGED
@@ -108,3 +108,5 @@ export type RanksPosition = 'left' | 'right';
108
108
  export type BrushColor = 'green' | 'red' | 'blue' | 'yellow';
109
109
 
110
110
  export type SquareClasses = Map<Key, string>;
111
+
112
+ export type DirectionalCheck = (x1: number, y1: number, x2: number, y2: number) => boolean;
package/src/util.ts CHANGED
@@ -103,3 +103,43 @@ export function computeSquareCenter(key: cg.Key, asWhite: boolean, bounds: DOMRe
103
103
  bounds.top + (bounds.height * (7 - pos[1])) / 8 + bounds.height / 16,
104
104
  ];
105
105
  }
106
+
107
+ export const diff = (a: number, b: number): number => Math.abs(a - b);
108
+
109
+ export const knightDir: cg.DirectionalCheck = (x1, y1, x2, y2) => {
110
+ const xd = diff(x1, x2);
111
+ const yd = diff(y1, y2);
112
+ return (xd === 1 && yd === 2) || (xd === 2 && yd === 1);
113
+ };
114
+
115
+ export const rookDir: cg.DirectionalCheck = (x1, y1, x2, y2) => x1 === x2 || y1 === y2;
116
+
117
+ export const bishopDir: cg.DirectionalCheck = (x1, y1, x2, y2) => diff(x1, x2) === diff(y1, y2);
118
+
119
+ export const queenDir: cg.DirectionalCheck = (x1, y1, x2, y2) =>
120
+ rookDir(x1, y1, x2, y2) || bishopDir(x1, y1, x2, y2);
121
+
122
+ /** Return all board squares between (x1, y1) and (x2, y2) exclusive,
123
+ * along a straight line (rook or bishop path). Returns [] if not aligned, or none between.
124
+ */
125
+ export const squaresBetween = (x1: number, y1: number, x2: number, y2: number): cg.Key[] => {
126
+ const dx = x2 - x1;
127
+ const dy = y2 - y1;
128
+
129
+ // Must be a straight or diagonal line
130
+ if (dx && dy && Math.abs(dx) !== Math.abs(dy)) return [];
131
+
132
+ // Determine step direction
133
+ const stepX = dx === 0 ? 0 : dx > 0 ? 1 : -1;
134
+ const stepY = dy === 0 ? 0 : dy > 0 ? 1 : -1;
135
+
136
+ const squares: cg.Pos[] = [];
137
+ let x = x1 + stepX,
138
+ y = y1 + stepY;
139
+ while (x !== x2 || y !== y2) {
140
+ squares.push([x, y]);
141
+ x += stepX;
142
+ y += stepY;
143
+ }
144
+ return squares.map(sq => pos2key(sq));
145
+ };