UNPKG

chessground-haichess

Version:
1 lines 33.8 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Chessground=e()}}(function(){return function e(t,o,n){function r(i,a){if(!o[i]){if(!t[i]){var c="function"==typeof require&&require;if(!a&&c)return c(i,!0);if(s)return s(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var d=o[i]={exports:{}};t[i][0].call(d.exports,function(e){return r(t[i][1][e]||e)},d,d.exports,e,t,o,n)}return o[i].exports}for(var s="function"==typeof require&&require,i=0;i<n.length;i++)r(n[i]);return r}({1:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.render=o.anim=void 0;const n=e("./util");function r(e,t){const o=e(t);return t.dom.redraw(),o}function s(e,t){return{key:e,pos:n.key2pos(e),piece:t}}function i(e,t){return t.sort((t,o)=>n.distanceSq(e.pos,t.pos)-n.distanceSq(e.pos,o.pos))[0]}function a(e,t){const o=e.animation.current;if(void 0===o)return void(e.dom.destroyed||e.dom.redrawNow());const n=1-(t-o.start)*o.frequency;if(n<=0)e.animation.current=void 0,e.dom.redrawNow();else{const t=(r=n)<.5?4*r*r*r:(r-1)*(2*r-2)*(2*r-2)+1;for(const e of o.plan.anims.values())e[2]=e[0]*t,e[3]=e[1]*t;e.dom.redrawNow(!0),requestAnimationFrame((t=performance.now())=>a(e,t))}var r}o.anim=function(e,t){return t.animation.enabled?function(e,t){const o=new Map(t.pieces),r=e(t),c=function(e,t){const o=new Map,r=[],a=new Map,c=[],l=[],d=new Map;let u,p,f;for(const[n,i]of e)d.set(n,s(n,i));for(const i of n.allKeys)u=t.pieces.get(i),p=d.get(i),u?p?n.samePiece(u,p.piece)||(c.push(p),l.push(s(i,u))):l.push(s(i,u)):p&&c.push(p);for(const s of l)p=i(s,c.filter(e=>n.samePiece(s.piece,e.piece))),p&&(f=[p.pos[0]-s.pos[0],p.pos[1]-s.pos[1]],o.set(s.key,f.concat(f)),r.push(p.key));for(const n of c)-1===r.indexOf(n.key)&&a.set(n.key,n.piece);return{anims:o,fadings:a}}(o,t);if(c.anims.size||c.fadings.size){const e=t.animation.current&&t.animation.current.start;t.animation.current={start:performance.now(),frequency:1/t.animation.duration,plan:c},e||a(t,performance.now())}else t.dom.redraw();return r}(e,t):r(e,t)},o.render=r},{"./util":18}],2:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.start=void 0;const n=e("./board"),r=e("./fen"),s=e("./config"),i=e("./anim"),a=e("./drag"),c=e("./explosion");o.start=function(e,t){function o(){n.toggleOrientation(e),t()}return{set(t){t.orientation&&t.orientation!==e.orientation&&o(),(t.fen?i.anim:i.render)(e=>s.configure(e,t),e)},state:e,getFen:()=>r.write(e.pieces),toggleOrientation:o,setPieces(t){i.anim(e=>n.setPieces(e,t),e)},selectSquare(t,o){t?i.anim(e=>n.selectSquare(e,t,o),e):e.selected&&(n.unselect(e),e.dom.redraw())},move(t,o){i.anim(e=>n.baseMove(e,t,o),e)},newPiece(t,o){i.anim(e=>n.baseNewPiece(e,t,o),e)},playPremove(){if(e.premovable.current){if(i.anim(n.playPremove,e))return!0;e.dom.redraw()}return!1},playPredrop(t){if(e.predroppable.current){const o=n.playPredrop(e,t);return e.dom.redraw(),o}return!1},cancelPremove(){i.render(n.unsetPremove,e)},cancelPredrop(){i.render(n.unsetPredrop,e)},cancelMove(){i.render(e=>{n.cancelMove(e),a.cancel(e)},e)},stop(){i.render(e=>{n.stop(e),a.cancel(e)},e)},explode(t){c.explosion(e,t)},setAutoShapes(t){i.render(e=>e.drawable.autoShapes=t,e)},setShapes(t){i.render(e=>e.drawable.shapes=t,e)},getKeyAtDomPos:t=>n.getKeyAtDomPos(t,n.whitePov(e),e.dom.bounds()),redrawAll:t,dragNewPiece(t,o,n){a.dragNewPiece(e,t,o,n)},destroy(){n.stop(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}},{"./anim":1,"./board":3,"./config":5,"./drag":6,"./explosion":10,"./fen":11}],3:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.whitePov=o.getSnappedKeyAtDomPos=o.getKeyAtDomPos=o.stop=o.cancelMove=o.playPredrop=o.playPremove=o.isDraggable=o.canMove=o.unselect=o.setSelected=o.selectSquare=o.dropNewPiece=o.userMove=o.baseNewPiece=o.baseMove=o.unsetPredrop=o.unsetPremove=o.setCheck=o.setPieces=o.reset=o.toggleOrientation=o.callUserFunction=void 0;const n=e("./util"),r=e("./premove");function s(e,...t){e&&setTimeout(()=>e(...t),1)}function i(e){e.premovable.current&&(e.premovable.current=void 0,s(e.premovable.events.unset))}function a(e){const t=e.predroppable;t.current&&(t.current=void 0,s(t.events.unset))}function c(e,t,o){const r=e.pieces.get(t),i=e.pieces.get(o);if(t===o||!r)return!1;const a=i&&i.color!==r.color?i:void 0;return o===e.selected&&f(e),s(e.events.move,t,o,a),function(e,t,o){if(!e.autoCastle)return!1;const r=e.pieces.get(t);if(!r||"king"!==r.role)return!1;const s=n.key2pos(t),i=n.key2pos(o);if(0!==s[1]&&7!==s[1]||s[1]!==i[1])return!1;4!==s[0]||e.pieces.has(o)||(6===i[0]?o=n.pos2key([7,i[1]]):2===i[0]&&(o=n.pos2key([0,i[1]])));const a=e.pieces.get(o);return!(!a||a.color!==r.color||"rook"!==a.role||(e.pieces.delete(t),e.pieces.delete(o),s[0]<i[0]?(e.pieces.set(n.pos2key([6,i[1]]),r),e.pieces.set(n.pos2key([5,i[1]]),a)):(e.pieces.set(n.pos2key([2,i[1]]),r),e.pieces.set(n.pos2key([3,i[1]]),a)),0))}(e,t,o)||(e.pieces.set(o,r),e.pieces.delete(t)),e.lastMove=[t,o],e.check=void 0,s(e.events.change),a||!0}function l(e,t,o,r){if(e.pieces.has(o)){if(!r)return!1;e.pieces.delete(o)}return s(e.events.dropNewPiece,t,o),e.pieces.set(o,t),e.lastMove=[o],e.check=void 0,s(e.events.change),e.movable.dests=void 0,e.turnColor=n.opposite(e.turnColor),!0}function d(e,t,o){const r=c(e,t,o);return r&&(e.movable.dests=void 0,e.turnColor=n.opposite(e.turnColor),e.animation.current=void 0),r}function u(e,t,o){if(v(e,t,o)){const n=d(e,t,o);if(n){const r=e.hold.stop();f(e);const i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:r};return!0!==n&&(i.captured=n),s(e.movable.events.after,t,o,i),!0}}else if(function(e,t,o){return t!==o&&m(e,t)&&-1!==r.premove(e.pieces,t,e.premovable.castle).indexOf(o)}(e,t,o))return function(e,t,o,n){a(e),e.premovable.current=[t,o],s(e.premovable.events.set,t,o,n)}(e,t,o,{ctrlKey:e.stats.ctrlKey}),f(e),!0;return f(e),!1}function p(e,t){e.selected=t,m(e,t)?e.premovable.dests=r.premove(e.pieces,t,e.premovable.castle):e.premovable.dests=void 0}function f(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function g(e,t){const o=e.pieces.get(t);return!!o&&("both"===e.movable.color||e.movable.color===o.color&&e.turnColor===o.color)}function v(e,t,o){var n,r;return t!==o&&g(e,t)&&(e.movable.free||!!e.movable.dests&&!!e.movable.dests.get(t)&&-1!==(null===(r=null===(n=e.movable.dests)||void 0===n?void 0:n.get(t))||void 0===r?void 0:r.indexOf(o)))}function m(e,t){const o=e.pieces.get(t);return!!o&&e.premovable.enabled&&e.movable.color===o.color&&e.turnColor!==o.color}function h(e){i(e),a(e),f(e)}o.callUserFunction=s,o.toggleOrientation=function(e){e.orientation=n.opposite(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0},o.reset=function(e){e.lastMove=void 0,f(e),i(e),a(e)},o.setPieces=function(e,t){for(const[o,n]of t)n?e.pieces.set(o,n):e.pieces.delete(o)},o.setCheck=function(e,t){if(e.check=void 0,!0===t&&(t=e.turnColor),t)for(const[o,n]of e.pieces)"king"===n.role&&n.color===t&&(e.check=o)},o.unsetPremove=i,o.unsetPredrop=a,o.baseMove=c,o.baseNewPiece=l,o.userMove=u,o.dropNewPiece=function(e,t,o,n){const r=e.pieces.get(t);r&&(function(e,t,o){const n=e.pieces.get(t);return!(!n||t!==o&&e.pieces.has(o)||"both"!==e.movable.color&&(e.movable.color!==n.color||e.turnColor!==n.color))}(e,t,o)||n)?(e.pieces.delete(t),l(e,r,o,n),s(e.movable.events.afterNewPiece,r.role,o,{premove:!1,predrop:!1})):r&&function(e,t,o){const n=e.pieces.get(t),r=e.pieces.get(o);return!!n&&(!r||r.color!==e.movable.color)&&e.predroppable.enabled&&("pawn"!==n.role||"1"!==o[1]&&"8"!==o[1])&&e.movable.color===n.color&&e.turnColor!==n.color}(e,t,o)?function(e,t,o){i(e),e.predroppable.current={role:t,key:o},s(e.predroppable.events.set,t,o)}(e,r.role,o):(i(e),a(e)),e.pieces.delete(t),f(e)},o.selectSquare=function(e,t,o){if(s(e.events.select,t),e.selected){if(e.selected===t&&!e.draggable.enabled)return f(e),void e.hold.cancel();if((e.selectable.enabled||o)&&e.selected!==t&&u(e,e.selected,t))return void(e.stats.dragged=!1)}(g(e,t)||m(e,t))&&(p(e,t),e.hold.start())},o.setSelected=p,o.unselect=f,o.canMove=v,o.isDraggable=function(e,t){const o=e.pieces.get(t);return!!o&&e.draggable.enabled&&("both"===e.movable.color||e.movable.color===o.color&&(e.turnColor===o.color||e.premovable.enabled))},o.playPremove=function(e){const t=e.premovable.current;if(!t)return!1;const o=t[0],n=t[1];let r=!1;if(v(e,o,n)){const t=d(e,o,n);if(t){const i={premove:!0};!0!==t&&(i.captured=t),s(e.movable.events.after,o,n,i),r=!0}}return i(e),r},o.playPredrop=function(e,t){const o=e.predroppable.current;let n=!1;if(!o)return!1;if(t(o)){l(e,{role:o.role,color:e.movable.color},o.key)&&(s(e.movable.events.afterNewPiece,o.role,o.key,{premove:!1,predrop:!0}),n=!0)}return a(e),n},o.cancelMove=h,o.stop=function(e){e.movable.color=e.movable.dests=e.animation.current=void 0,h(e)},o.getKeyAtDomPos=function(e,t,o){let r=Math.floor(8*(e[0]-o.left)/o.width);t||(r=7-r);let s=7-Math.floor(8*(e[1]-o.top)/o.height);return t||(s=7-s),r>=0&&r<8&&s>=0&&s<8?n.pos2key([r,s]):void 0},o.getSnappedKeyAtDomPos=function(e,t,o,s){const i=n.key2pos(e),a=n.allPos.filter(e=>r.queen(i[0],i[1],e[0],e[1])||r.knight(i[0],i[1],e[0],e[1])),c=a.map(e=>n.computeSquareCenter(n.pos2key(e),o,s)).map(e=>n.distanceSq(t,e)),[,l]=c.reduce((e,t,o)=>e[0]<t?e:[t,o],[c[0],0]);return n.pos2key(a[l])},o.whitePov=function(e){return"white"===e.orientation}},{"./premove":13,"./util":18}],4:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.Chessground=void 0;const n=e("./api"),r=e("./config"),s=e("./state"),i=e("./wrap"),a=e("./events"),c=e("./render"),l=e("./svg"),d=e("./util");function u(e){let t=!1;return()=>{t||(t=!0,requestAnimationFrame(()=>{e(),t=!1}))}}o.Chessground=function(e,t){const o=s.defaults();function p(){const t="dom"in o?o.dom.unbind:void 0,n=o.viewOnly&&!o.drawable.visible,r=i.renderWrap(e,o,n),s=d.memo(()=>r.board.getBoundingClientRect()),p=e=>{c.render(g),!e&&r.svg&&l.renderSvg(g,r.svg,r.customSvg)},f=()=>{s.clear(),c.updateBounds(g),r.svg&&l.renderSvg(g,r.svg,r.customSvg)},g=o;return g.dom={elements:r,bounds:s,redraw:u(p),redrawNow:p,unbind:t,relative:n},g.drawable.prevSvgHash="",p(!1),a.bindBoard(g,f),t||(g.dom.unbind=a.bindDocument(g,f)),g.events.insert&&g.events.insert(r),g}return r.configure(o,t||{}),n.start(p(),p)}},{"./api":2,"./config":5,"./events":9,"./render":14,"./state":15,"./svg":16,"./util":18,"./wrap":19}],5:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.configure=void 0;const n=e("./board"),r=e("./fen");function s(e,t){for(const o in t)i(e[o])&&i(t[o])?s(e[o],t[o]):e[o]=t[o]}function i(e){return"object"==typeof e}o.configure=function(e,t){var o,i;if((null===(o=t.movable)||void 0===o?void 0:o.dests)&&(e.movable.dests=void 0),(null===(i=t.drawable)||void 0===i?void 0:i.autoShapes)&&(e.drawable.autoShapes=[]),s(e,t),t.fen&&(e.pieces=r.read(t.fen),e.drawable.shapes=[]),"check"in t&&n.setCheck(e,t.check||!1),"lastMove"in t&&!t.lastMove?e.lastMove=void 0:t.lastMove&&(e.lastMove=t.lastMove),e.selected&&n.setSelected(e,e.selected),(!e.animation.duration||e.animation.duration<100)&&(e.animation.enabled=!1),!e.movable.rookCastle&&e.movable.dests){const t="white"===e.movable.color?"1":"8",o="e"+t,n=e.movable.dests.get(o),r=e.pieces.get(o);if(!n||!r||"king"!==r.role)return;e.movable.dests.set(o,n.filter(e=>!(e==="a"+t&&-1!==n.indexOf("c"+t)||e==="h"+t&&-1!==n.indexOf("g"+t))))}}},{"./board":3,"./fen":11}],6:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.cancel=o.end=o.move=o.dragNewPiece=o.start=void 0;const n=e("./board"),r=e("./util"),s=e("./draw"),i=e("./anim");function a(e){requestAnimationFrame(()=>{var t;const o=e.draggable.current;if(!o)return;(null===(t=e.animation.current)||void 0===t?void 0:t.plan.anims.has(o.orig))&&(e.animation.current=void 0);const n=e.pieces.get(o.orig);if(n&&r.samePiece(n,o.piece)){if(!o.started&&r.distanceSq(o.pos,o.origPos)>=Math.pow(e.draggable.distance,2)&&(o.started=!0),o.started){if("function"==typeof o.element){const e=o.element();if(!e)return;e.cgDragging=!0,e.classList.add("dragging"),o.element=e}const t=e.dom.bounds();r.translateAbs(o.element,[o.pos[0]-t.left-t.width/16,o.pos[1]-t.top-t.height/16])}}else c(e);a(e)})}function c(e){const t=e.draggable.current;t&&(t.newPiece&&e.pieces.delete(t.orig),e.draggable.current=void 0,n.unselect(e),l(e),e.dom.redraw())}function l(e){const t=e.dom.elements;t.ghost&&r.setVisible(t.ghost,!1)}function d(e,t){let o=e.dom.elements.board.firstChild;for(;o;){if(o.cgKey===t&&"PIECE"===o.tagName)return o;o=o.nextSibling}}o.start=function(e,t){if(!t.isTrusted||void 0!==t.button&&0!==t.button)return;if(t.touches&&t.touches.length>1)return;const o=e.dom.bounds(),c=r.eventPosition(t),l=n.getKeyAtDomPos(c,n.whitePov(e),o);if(!l)return;const u=e.pieces.get(l),p=e.selected;p||!e.drawable.enabled||!e.drawable.eraseOnClick&&u&&u.color===e.turnColor||s.clear(e),!1===t.cancelable||t.touches&&e.movable.color&&!u&&!p&&!function(e,t){const o=n.whitePov(e),s=e.dom.bounds(),i=Math.pow(s.width/8,2);for(const n in e.pieces){const e=r.computeSquareCenter(n,o,s);if(r.distanceSq(e,t)<=i)return!0}return!1}(e,c)||t.preventDefault();const f=!!e.premovable.current,g=!!e.predroppable.current;e.stats.ctrlKey=t.ctrlKey,e.selected&&n.canMove(e,e.selected,l)?i.anim(e=>n.selectSquare(e,l),e):n.selectSquare(e,l);const v=e.selected===l,m=d(e,l);if(u&&m&&v&&n.isDraggable(e,l)){e.draggable.current={orig:l,piece:u,origPos:c,pos:c,started:e.draggable.autoDistance&&e.stats.dragged,element:m,previouslySelected:p,originTarget:t.target},m.cgDragging=!0,m.classList.add("dragging");const s=e.dom.elements.ghost;s&&(s.className=`ghost ${u.color} ${u.role}`,r.translateAbs(s,r.posToTranslateAbs(o)(r.key2pos(l),n.whitePov(e))),r.setVisible(s,!0)),a(e)}else f&&n.unsetPremove(e),g&&n.unsetPredrop(e);e.dom.redraw()},o.dragNewPiece=function(e,t,o,n){const s="a0";e.pieces.set(s,t),e.dom.redraw();const i=r.eventPosition(o);e.draggable.current={orig:s,piece:t,origPos:i,pos:i,started:!0,element:()=>d(e,s),originTarget:o.target,newPiece:!0,force:!!n},a(e)},o.move=function(e,t){e.draggable.current&&(!t.touches||t.touches.length<2)&&(e.draggable.current.pos=r.eventPosition(t))},o.end=function(e,t){const o=e.draggable.current;if(!o)return;if("touchend"===t.type&&!1!==t.cancelable&&t.preventDefault(),"touchend"===t.type&&o.originTarget!==t.target&&!o.newPiece)return void(e.draggable.current=void 0);n.unsetPremove(e),n.unsetPredrop(e);const s=r.eventPosition(t)||o.pos,i=n.getKeyAtDomPos(s,n.whitePov(e),e.dom.bounds());i&&o.started&&o.orig!==i?o.newPiece?n.dropNewPiece(e,o.orig,i,o.force):(e.stats.ctrlKey=t.ctrlKey,n.userMove(e,o.orig,i)&&(e.stats.dragged=!0)):o.newPiece?e.pieces.delete(o.orig):e.draggable.deleteOnDropOff&&!i&&(e.pieces.delete(o.orig),n.callUserFunction(e.events.change)),(o.orig!==o.previouslySelected||o.orig!==i&&i)&&e.selectable.enabled||n.unselect(e),l(e),e.draggable.current=void 0,e.dom.redraw()},o.cancel=c},{"./anim":1,"./board":3,"./draw":7,"./util":18}],7:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.clear=o.cancel=o.end=o.move=o.processDraw=o.start=void 0;const n=e("./board"),r=e("./util"),s=["green","red","blue","yellow"];function i(e){requestAnimationFrame(()=>{const t=e.drawable.current;if(t){const o=n.getKeyAtDomPos(t.pos,n.whitePov(e),e.dom.bounds());o||(t.snapToValidMove=!1);const r=t.snapToValidMove?n.getSnappedKeyAtDomPos(t.orig,t.pos,n.whitePov(e),e.dom.bounds()):o;r!==t.mouseSq&&(t.mouseSq=r,t.dest=r!==t.orig?r:void 0,e.dom.redrawNow()),i(e)}})}function a(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function c(e){var t;const o=(e.shiftKey||e.ctrlKey)&&r.isRightButton(e),n=e.altKey||e.metaKey||(null===(t=e.getModifierState)||void 0===t?void 0:t.call(e,"AltGraph"));return s[(o?1:0)+(n?2:0)]}function l(e){e.onChange&&e.onChange(e.shapes)}o.start=function(e,t){if(t.touches&&t.touches.length>1)return;t.stopPropagation(),t.preventDefault(),t.ctrlKey?n.unselect(e):n.cancelMove(e);const o=r.eventPosition(t),s=n.getKeyAtDomPos(o,n.whitePov(e),e.dom.bounds());s&&(e.drawable.current={orig:s,pos:o,brush:c(t),snapToValidMove:e.drawable.defaultSnapToValidMove},i(e))},o.processDraw=i,o.move=function(e,t){e.drawable.current&&(e.drawable.current.pos=r.eventPosition(t))},o.end=function(e){const t=e.drawable.current;t&&(t.mouseSq&&function(e,t){const o=e=>e.orig===t.orig&&e.dest===t.dest,n=e.shapes.find(o);n&&(e.shapes=e.shapes.filter(e=>!o(e)));n&&n.brush===t.brush||e.shapes.push(t);l(e)}(e.drawable,t),a(e))},o.cancel=a,o.clear=function(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),l(e.drawable))}},{"./board":3,"./util":18}],8:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.drop=o.cancelDropMode=o.setDropMode=void 0;const n=e("./board"),r=e("./util"),s=e("./drag");o.setDropMode=function(e,t){e.dropmode={active:!0,piece:t},s.cancel(e)},o.cancelDropMode=function(e){e.dropmode={active:!1}},o.drop=function(e,t){if(!e.dropmode.active)return;n.unsetPremove(e),n.unsetPredrop(e);const o=e.dropmode.piece;if(o){e.pieces.set("a0",o);const s=r.eventPosition(t),i=s&&n.getKeyAtDomPos(s,n.whitePov(e),e.dom.bounds());i&&n.dropNewPiece(e,"a0",i)}e.dom.redraw()}},{"./board":3,"./drag":6,"./util":18}],9:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.bindDocument=o.bindBoard=void 0;const n=e("./drag"),r=e("./draw"),s=e("./drop"),i=e("./util");function a(e,t,o,n){return e.addEventListener(t,o,n),()=>e.removeEventListener(t,o,n)}function c(e,t,o){return n=>{e.drawable.current?e.drawable.enabled&&o(e,n):e.viewOnly||t(e,n)}}o.bindBoard=function(e,t){const o=e.dom.elements.board;if(!e.dom.relative&&e.resizable&&"ResizeObserver"in window){new window.ResizeObserver(t).observe(o)}if(e.viewOnly)return;const a=function(e){return t=>{e.draggable.current?n.cancel(e):e.drawable.current?r.cancel(e):t.shiftKey||i.isRightButton(t)?e.drawable.enabled&&r.start(e,t):e.viewOnly||(e.dropmode.active?s.drop(e,t):n.start(e,t))}}(e);o.addEventListener("touchstart",a,{passive:!1}),o.addEventListener("mousedown",a,{passive:!1}),(e.disableContextMenu||e.drawable.enabled)&&o.addEventListener("contextmenu",e=>e.preventDefault())},o.bindDocument=function(e,t){const o=[];if(e.dom.relative||!e.resizable||"ResizeObserver"in window||o.push(a(document.body,"chessground.resize",t)),!e.viewOnly){const t=c(e,n.move,r.move),s=c(e,n.end,r.end);for(const e of["touchmove","mousemove"])o.push(a(document,e,t));for(const e of["touchend","mouseup"])o.push(a(document,e,s));const i=()=>e.dom.bounds.clear();o.push(a(document,"scroll",i,{capture:!0,passive:!0})),o.push(a(window,"resize",i,{passive:!0}))}return()=>o.forEach(e=>e())}},{"./drag":6,"./draw":7,"./drop":8,"./util":18}],10:[function(e,t,o){"use strict";function n(e,t){e.exploding&&(t?e.exploding.stage=t:e.exploding=void 0,e.dom.redraw())}Object.defineProperty(o,"__esModule",{value:!0}),o.explosion=void 0,o.explosion=function(e,t){e.exploding={stage:1,keys:t},e.dom.redraw(),setTimeout(()=>{n(e,2),setTimeout(()=>n(e,void 0),120)},120)}},{}],11:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.write=o.read=o.initial=void 0;const n=e("./util"),r=e("./types");o.initial="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";const s={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},i={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};o.read=function(e){"start"===e&&(e=o.initial);const t=new Map;let r=7,i=0;for(const o of e)switch(o){case" ":return t;case"/":if(--r,r<0)return t;i=0;break;case"~":{const e=t.get(n.pos2key([i,r]));e&&(e.promoted=!0);break}default:{const e=o.charCodeAt(0);if(e<57)i+=e-48;else{const e=o.toLowerCase();t.set(n.pos2key([i,r]),{role:s[e],color:o===e?"black":"white"}),++i}}}return t},o.write=function(e){return n.invRanks.map(t=>r.files.map(o=>{const n=e.get(o+t);if(n){const e=i[n.role];return"white"===n.color?e.toUpperCase():e}return"1"}).join("")).join("/").replace(/1{2,}/g,e=>e.length.toString())}},{"./types":17,"./util":18}],12:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0});const n=e("./chessground");o.default=n.Chessground},{"./chessground":4}],13:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.premove=o.queen=o.knight=void 0;const n=e("./util");function r(e,t){return Math.abs(e-t)}o.knight=(e,t,o,n)=>{const s=r(e,o),i=r(t,n);return 1===s&&2===i||2===s&&1===i};const s=(e,t,o,n)=>r(e,o)===r(t,n),i=(e,t,o,n)=>e===o||t===n;o.queen=(e,t,o,n)=>s(e,t,o,n)||i(e,t,o,n),o.premove=function(e,t,a){const c=e.get(t);if(!c)return[];const l=n.key2pos(t),d=c.role,u="pawn"===d?(p=c.color,(e,t,o,n)=>r(e,o)<2&&("white"===p?n===t+1||t<=1&&n===t+2&&e===o:n===t-1||t>=6&&n===t-2&&e===o)):"knight"===d?o.knight:"bishop"===d?s:"rook"===d?i:"queen"===d?o.queen:function(e,t,o){return(n,s,i,a)=>r(n,i)<2&&r(s,a)<2||o&&s===a&&s===("white"===e?0:7)&&(4===n&&(2===i&&-1!==t.indexOf(0)||6===i&&-1!==t.indexOf(7))||-1!==t.indexOf(i))}(c.color,function(e,t){const o="white"===t?"1":"8",r=[];for(const[s,i]of e)s[1]===o&&i.color===t&&"rook"===i.role&&r.push(n.key2pos(s)[0]);return r}(e,c.color),a);var p;return n.allPos.filter(e=>(l[0]!==e[0]||l[1]!==e[1])&&u(l[0],l[1],e[0],e[1])).map(n.pos2key)}},{"./util":18}],14:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.updateBounds=o.render=void 0;const n=e("./util"),r=e("./board");function s(e){return"PIECE"===e.tagName}function i(e){return"SQUARE"===e.tagName}function a(e,t){for(const o of t)e.dom.elements.board.removeChild(o)}function c(e,t){let o=2+8*e[1]+(7-e[0]);return t&&(o=67-o),o+""}function l(e){return`${e.color} ${e.role}`}function d(e,t,o){const n=e.get(t);n?e.set(t,`${n} ${o}`):e.set(t,o)}function u(e,t,o){const n=e.get(t);n?n.push(o):e.set(t,[o])}o.render=function(e){const t=r.whitePov(e),o=e.dom.relative?n.posToTranslateRel:n.posToTranslateAbs(e.dom.bounds()),p=e.dom.relative?n.translateRel:n.translateAbs,f=e.dom.elements.board,g=e.pieces,v=e.animation.current,m=v?v.plan.anims:new Map,h=v?v.plan.fadings:new Map,b=e.draggable.current,w=function(e){var t;const o=new Map;if(e.lastMove&&e.highlight.lastMove)for(const s of e.lastMove)d(o,s,"last-move");e.check&&e.highlight.check&&d(o,e.check,"check");if(e.selected&&(d(o,e.selected,"selected"),e.movable.showDests)){const n=null===(t=e.movable.dests)||void 0===t?void 0:t.get(e.selected);if(n)for(const t of n)d(o,t,"move-dest"+(e.pieces.has(t)?" oc":""));const r=e.premovable.dests;if(r)for(const t of r)d(o,t,"premove-dest"+(e.pieces.has(t)?" oc":""))}const n=e.premovable.current;if(n)for(const s of n)d(o,s,"current-premove");else e.predroppable.current&&d(o,e.predroppable.current.key,"current-premove");const r=e.exploding;if(r)for(const s of r.keys)d(o,s,"exploding"+r.stage);return o}(e),y=new Set,P=new Set,k=new Map,M=new Map;let S,C,A,O,x,q,K,D,_,T;for(C=f.firstChild;C;){if(S=C.cgKey,s(C))if(A=g.get(S),x=m.get(S),q=h.get(S),O=C.cgPiece,!C.cgDragging||b&&b.orig===S||(C.classList.remove("dragging"),p(C,o(n.key2pos(S),t)),C.cgDragging=!1),!q&&C.cgFading&&(C.cgFading=!1,C.classList.remove("fading")),A){if(x&&C.cgAnimating&&O===l(A)){const e=n.key2pos(S);e[0]+=x[2],e[1]+=x[3],C.classList.add("anim"),p(C,o(e,t))}else C.cgAnimating&&(C.cgAnimating=!1,C.classList.remove("anim"),p(C,o(n.key2pos(S),t)),e.addPieceZIndex&&(C.style.zIndex=c(n.key2pos(S),t)));O!==l(A)||q&&C.cgFading?q&&O===l(q)?(C.classList.add("fading"),C.cgFading=!0):u(k,O,C):y.add(S)}else u(k,O,C);else if(i(C)){const e=C.className;w.get(S)===e?P.add(S):u(M,e,C)}C=C.nextSibling}for(const[r,s]of w)if(!P.has(r)){_=M.get(s),T=_&&_.pop();const e=o(n.key2pos(r),t);if(T)T.cgKey=r,p(T,e);else{const t=n.createEl("square",s);t.cgKey=r,p(t,e),f.insertBefore(t,f.firstChild)}}for(const[r,s]of g)if(x=m.get(r),!y.has(r))if(K=k.get(l(s)),D=K&&K.pop(),D){D.cgKey=r,D.cgFading&&(D.classList.remove("fading"),D.cgFading=!1);const s=n.key2pos(r);e.addPieceZIndex&&(D.style.zIndex=c(s,t)),x&&(D.cgAnimating=!0,D.classList.add("anim"),s[0]+=x[2],s[1]+=x[3]),p(D,o(s,t))}else{const i=l(s),a=n.createEl("piece",i),d=n.key2pos(r);a.cgPiece=i,a.cgKey=r,x&&(a.cgAnimating=!0,d[0]+=x[2],d[1]+=x[3]),p(a,o(d,t)),e.addPieceZIndex&&(a.style.zIndex=c(d,t)),f.appendChild(a)}for(const n of k.values())a(e,n);for(const n of M.values())a(e,n)},o.updateBounds=function(e){if(e.dom.relative)return;const t=r.whitePov(e),o=n.posToTranslateAbs(e.dom.bounds());let a=e.dom.elements.board.firstChild;for(;a;)(s(a)&&!a.cgAnimating||i(a))&&n.translateAbs(a,o(n.key2pos(a.cgKey),t)),a=a.nextSibling}},{"./board":3,"./util":18}],15:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.defaults=void 0;const n=e("./fen"),r=e("./util");o.defaults=function(){return{pieces:n.read(n.initial),orientation:"white",turnColor:"white",coordinates:!0,autoCastle:!0,viewOnly:!1,disableContextMenu:!1,resizable:!0,addPieceZIndex:!1,pieceKey:!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}},pieces:{baseUrl:"https://lichess1.org/assets/piece/cburnett/"},prevSvgHash:""},hold:r.timer()}}},{"./fen":11,"./util":18}],16:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.setAttributes=o.renderSvg=o.createElement=void 0;const n=e("./util");function r(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function s(e,t,o,n,r){const s=e.dom.bounds(),i=new Map,a=[];for(const l of t)i.set(l.hash,!1);let c,d=r.firstChild;for(;d;)c=d.getAttribute("cgHash"),i.has(c)?i.set(c,!0):a.push(d),d=d.nextSibling;for(const l of a)r.removeChild(l);for(const u of t)i.get(u.hash)||r.appendChild(l(e,u,o,n,s))}function i({orig:e,dest:t,brush:o,piece:n,modifiers:r,customSvg:s},i,l,d){return[d.width,d.height,l,e,t,o,t&&(i.get(t)||0)>1,n&&a(n),r&&(u=r,""+(u.lineWidth||"")),s&&c(s)].filter(e=>e).join(",");var u}function a(e){return[e.color,e.role,e.scale].filter(e=>e).join(",")}function c(e){let t=0;for(let o=0;o<e.length;o++)t=(t<<5)-t+e.charCodeAt(o)>>>0;return"custom-"+t.toString()}function l(e,{shape:t,current:o,hash:s},i,a,c){let l;if(t.customSvg){const o=p(n.key2pos(t.orig),e.orientation);l=function(e,t,o){const{width:n,height:s}=o,i=n/8,a=s/8,c=t[0]*i,l=(7-t[1])*a,d=u(r("g"),{transform:`translate(${c},${l})`}),p=u(r("svg"),{width:i,height:a,viewBox:"0 0 100 100"});return d.appendChild(p),p.innerHTML=e,d}(t.customSvg,o,c)}else if(t.piece)l=function(e,t,o,n){const s=m(t,n),i=n.width/8*(o.scale||1),a=o.color[0]+("knight"===o.role?"n":o.role[0]).toUpperCase();return u(r("image"),{className:`${o.role} ${o.color}`,x:s[0]-i/2,y:s[1]-i/2,width:i,height:i,href:e+a+".svg"})}(e.drawable.pieces.baseUrl,p(n.key2pos(t.orig),e.orientation),t.piece,c);else{const s=p(n.key2pos(t.orig),e.orientation);if(t.dest){let d=i[t.brush];t.modifiers&&(d=f(d,t.modifiers)),l=function(e,t,o,n,s,i){const a=function(e,t){return(t?20:10)/512*e.width}(i,s&&!n),c=m(t,i),l=m(o,i),d=l[0]-c[0],p=l[1]-c[1],f=Math.atan2(p,d),h=Math.cos(f)*a,b=Math.sin(f)*a;return u(r("line"),{stroke:e.color,"stroke-width":g(e,n,i),"stroke-linecap":"round","marker-end":"url(#arrowhead-"+e.key+")",opacity:v(e,n),x1:c[0],y1:c[1],x2:l[0]-h,y2:l[1]-b})}(d,s,p(n.key2pos(t.dest),e.orientation),o,(a.get(t.dest)||0)>1,c)}else l=function(e,t,o,n){const s=m(t,n),i=function(e){const t=e.width/512;return[3*t,4*t]}(n),a=(n.width+n.height)/32;return u(r("circle"),{stroke:e.color,"stroke-width":i[o?0:1],fill:"none",opacity:v(e,o),cx:s[0],cy:s[1],r:a-i[1]/2})}(i[t.brush],s,o,c)}return l.setAttribute("cgHash",s),l}function d(e){const t=u(r("marker"),{id:"arrowhead-"+e.key,orient:"auto",markerWidth:4,markerHeight:8,refX:2.05,refY:2.01});return t.appendChild(u(r("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),t.setAttribute("cgKey",e.key),t}function u(e,t){for(const o in t)e.setAttribute(o,t[o]);return e}function p(e,t){return"white"===t?e:[7-e[0],7-e[1]]}function f(e,t){return{color:e.color,opacity:Math.round(10*e.opacity)/10,lineWidth:Math.round(t.lineWidth||e.lineWidth),key:[e.key,t.lineWidth].filter(e=>e).join("")}}function g(e,t,o){return(e.lineWidth||10)*(t?.85:1)/512*o.width}function v(e,t){return(e.opacity||1)*(t?.9:1)}function m(e,t){return[(e[0]+.5)*t.width/8,(7.5-e[1])*t.height/8]}o.createElement=r,o.renderSvg=function(e,t,o){const n=e.drawable,r=n.current,a=r&&r.mouseSq?r:void 0,c=new Map,l=e.dom.bounds();for(const s of n.shapes.concat(n.autoShapes).concat(a?[a]:[]))s.dest&&c.set(s.dest,(c.get(s.dest)||0)+1);const u=n.shapes.concat(n.autoShapes).map(e=>({shape:e,current:!1,hash:i(e,c,!1,l)}));a&&u.push({shape:a,current:!0,hash:i(a,c,!0,l)});const p=u.map(e=>e.hash).join(";");if(p===e.drawable.prevSvgHash)return;e.drawable.prevSvgHash=p;const g=t.querySelector("defs"),v=t.querySelector("g"),m=o.querySelector("g");!function(e,t,o){const n=new Map;let r;for(const a of t)a.shape.dest&&(r=e.brushes[a.shape.brush],a.shape.modifiers&&(r=f(r,a.shape.modifiers)),n.set(r.key,r));const s=new Set;let i=o.firstChild;for(;i;)s.add(i.getAttribute("cgKey")),i=i.nextSibling;for(const[a,c]of n.entries())s.has(a)||o.appendChild(d(c))}(n,u,g),s(e,u.filter(e=>!e.shape.customSvg),n.brushes,c,v),s(e,u.filter(e=>e.shape.customSvg),n.brushes,c,m)},o.setAttributes=u},{"./util":18}],17:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.ranks=o.files=o.colors=void 0,o.colors=["white","black"],o.files=["a","b","c","d","e","f","g","h"],o.ranks=["1","2","3","4","5","6","7","8"]},{}],18:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.computeSquareCenter=o.createEl=o.isRightButton=o.eventPosition=o.setVisible=o.translateRel=o.translateAbs=o.posToTranslateRel=o.posToTranslateAbs=o.samePiece=o.distanceSq=o.opposite=o.timer=o.memo=o.allPos=o.key2pos=o.pos2key=o.allKeys=o.invRanks=void 0;const n=e("./types");o.invRanks=[...n.ranks].reverse(),o.allKeys=Array.prototype.concat(...n.files.map(e=>n.ranks.map(t=>e+t))),o.pos2key=e=>o.allKeys[8*e[0]+e[1]],o.key2pos=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49],o.allPos=o.allKeys.map(o.key2pos),o.memo=function(e){let t;const o=()=>(void 0===t&&(t=e()),t);return o.clear=()=>{t=void 0},o},o.timer=()=>{let e;return{start(){e=performance.now()},cancel(){e=void 0},stop(){if(!e)return 0;const t=performance.now()-e;return e=void 0,t}}},o.opposite=e=>"white"===e?"black":"white",o.distanceSq=(e,t)=>{const o=e[0]-t[0],n=e[1]-t[1];return o*o+n*n},o.samePiece=(e,t)=>e.role===t.role&&e.color===t.color;const r=(e,t,o,n)=>[(t?e[0]:7-e[0])*o,(t?7-e[1]:e[1])*n];o.posToTranslateAbs=e=>{const t=e.width/8,o=e.height/8;return(e,n)=>r(e,n,t,o)},o.posToTranslateRel=(e,t)=>r(e,t,100,100),o.translateAbs=(e,t)=>{e.style.transform=`translate(${t[0]}px,${t[1]}px)`},o.translateRel=(e,t)=>{e.style.transform=`translate(${t[0]}%,${t[1]}%)`},o.setVisible=(e,t)=>{e.style.visibility=t?"visible":"hidden"},o.eventPosition=e=>{var t;return e.clientX||0===e.clientX?[e.clientX,e.clientY]:(null===(t=e.targetTouches)||void 0===t?void 0:t[0])?[e.targetTouches[0].clientX,e.targetTouches[0].clientY]:void 0},o.isRightButton=e=>2===e.buttons||2===e.button,o.createEl=(e,t)=>{const o=document.createElement(e);return t&&(o.className=t),o},o.computeSquareCenter=function(e,t,n){const r=o.key2pos(e);return t||(r[0]=7-r[0],r[1]=7-r[1]),[n.left+n.width*r[0]/8+n.width/16,n.top+n.height*(7-r[1])/8+n.height/16]}},{"./types":17}],19:[function(e,t,o){"use strict";Object.defineProperty(o,"__esModule",{value:!0}),o.renderWrap=void 0;const n=e("./util"),r=e("./types"),s=e("./svg");function i(e,t){const o=n.createEl("coords",t);let r;for(const s of e)r=n.createEl("coord"),r.textContent=s,o.appendChild(r);return o}o.renderWrap=function(e,t,o){e.innerHTML="",e.classList.add("cg-wrap");for(const n of r.colors)e.classList.toggle("orientation-"+n,t.orientation===n);e.classList.toggle("manipulable",!t.viewOnly);const a=n.createEl("cg-helper");e.appendChild(a);const c=n.createEl("cg-container");a.appendChild(c);const l=n.createEl("cg-board");let d,u,p;if(c.appendChild(l),t.drawable.visible&&!o&&(d=s.setAttributes(s.createElement("svg"),{class:"cg-shapes"}),d.appendChild(s.createElement("defs")),d.appendChild(s.createElement("g")),u=s.setAttributes(s.createElement("svg"),{class:"cg-custom-svgs"}),u.appendChild(s.createElement("g")),c.appendChild(d),c.appendChild(u)),t.coordinates){const e="black"===t.orientation?" black":"";c.appendChild(i(r.ranks,"ranks"+e)),c.appendChild(i(r.files,"files"+e))}return t.draggable.showGhost&&!o&&(p=n.createEl("piece","ghost"),n.setVisible(p,!1),c.appendChild(p)),{board:l,container:c,ghost:p,svg:d,customSvg:u}}},{"./svg":16,"./types":17,"./util":18}]},{},[12])(12)});