diff --git a/public/javascripts/vendor/chessground.min.js b/public/javascripts/vendor/chessground.min.js index b561e44b5f..cd1294762d 100755 --- a/public/javascripts/vendor/chessground.min.js +++ b/public/javascripts/vendor/chessground.min.js @@ -1,2 +1,2 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Chessground=e()}}(function(){var e;return function t(e,n,r){function o(i,s){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!s&&c)return c(i,!0);if(a)return a(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[i]={exports:{}};e[i][0].call(u.exports,function(t){var n=e[i][1][t];return o(n?n:t)},u,u.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;ic;++c){var l=r[c],u=o(l);if("object"===u)for(var d in l){var f=e?a.clone(l[d]):l[d];i[d]=t?n(i[d],f):f}}return i}function o(e){return{}.toString.call(e).slice(8,-1).toLowerCase()}var a=function(e){return r(e===!0,!1,arguments)},i="merge";a.recursive=function(e){return r(e===!0,!0,arguments)},a.clone=function(e){var t,n,r=e,i=o(e);if("array"===i)for(r=[],n=e.length,t=0;n>t;++t)r[t]=a.clone(e[t]);else if("object"===i){r={};for(t in e)r[t]=a.clone(e[t])}return r},e?t.exports=a:window[i]=a}("object"==typeof t&&t&&"object"==typeof t.exports&&t.exports)},{}],3:[function(t,n){var r=function o(e,t){function n(e){P=e.document,T=e.location,A=e.cancelAnimationFrame||e.clearTimeout,N=e.requestAnimationFrame||e.setTimeout}function r(){var e,t=[].slice.call(arguments),n=!(null==t[1]||L.call(t[1])!==S||"tag"in t[1]||"subtree"in t[1]),r=n?t[1]:{},o="class"in r?"class":"className",a={tag:"div",attrs:{}},i=[];if(L.call(t[0])!=D)throw new Error("selector in m(selector, attrs, children) should be a string");for(;e=B.exec(t[0]);)if(""===e[1]&&e[2])a.tag=e[2];else if("#"===e[1])a.attrs.id=e[2];else if("."===e[1])i.push(e[2]);else if("["===e[3][0]){var s=F.exec(e[3]);a.attrs[s[1]]=s[3]||(s[2]?"":!0)}i.length>0&&(a.attrs[o]=i.join(" "));var c=n?t[2]:t[1];a.children=L.call(c)===q?c:t.slice(n?2:1);for(var l in r)a.attrs[l]=l===o?(a.attrs[l]||"")+" "+r[l]:r[l];return a}function a(e,n,r,o,c,u,d,f,p,h,v){if((null==c||null==c.toString())&&(c=""),"retain"===c.subtree)return u;var m=L.call(u),g=L.call(c);if(null==u||m!==g){if(null!=u)if(r&&r.nodes){var b=f-o,y=b+(g===q?c:u.nodes).length;s(r.nodes.slice(b,y),r.slice(b,y))}else u.nodes&&s(u.nodes,u);u=new c.constructor,u.tag&&(u={}),u.nodes=[]}if(g===q){for(var w=0,x=c.length;x>w;w++)L.call(c[w])===q&&(c=c.concat.apply([],c),w--);for(var k=[],E=u.length===c.length,C=0,O=1,M=2,j=3,T={},N=[],A=!1,w=0,x=u.length;x>w;w++)u[w]&&u[w].attrs&&null!=u[w].attrs.key&&(A=!0,T[u[w].attrs.key]={action:O,index:w});if(A){c.indexOf(null)>-1&&(c=c.filter(function(e){return null!=e}));for(var w=0,x=c.length;x>w;w++)if(c[w]&&c[w].attrs)if(null!=c[w].attrs.key){var B=c[w].attrs.key;T[B]=T[B]?{action:j,index:w,from:T[B].index,element:e.childNodes[T[B].index]||P.createElement("div")}:{action:M,index:w}}else N.push({index:w,element:e.childNodes[w]||P.createElement("div")});for(var F,I=Object.keys(T).map(function(e){return T[e]}),z=I.sort(function(e,t){return e.action-t.action||e.index-t.index}),X=u.slice(),w=0;F=z[w];w++){if(F.action===O&&(s(u[F.index].nodes,u[F.index]),X.splice(F.index,1)),F.action===M){var U=P.createElement("div");U.key=c[F.index].attrs.key,e.insertBefore(U,e.childNodes[F.index]||null),X.splice(F.index,0,{attrs:{key:c[F.index].attrs.key},nodes:[U]})}F.action===j&&(e.childNodes[F.index]!==F.element&&null!==F.element&&e.insertBefore(F.element,e.childNodes[F.index]||null),X[F.index]=u[F.from])}for(var w=0,x=N.length;x>w;w++){var F=N[w];e.insertBefore(F.element,e.childNodes[F.index]||null),X[F.index]=u[F.index]}u=X,u.nodes=[];for(var H,w=0;H=e.childNodes[w];w++)u.nodes.push(H)}for(var w=0,G=0,x=c.length;x>w;w++){var J=a(e,n,u,f,c[w],u[G],d,f+C||C,p,h,v);J!==t&&(J.nodes.intact||(E=!1),C+=J.$trusted?(J.match(/<[^\/]|\>\s*[^<]/g)||[]).length:L.call(J)===q?J.length:1,u[G++]=J)}if(!E){for(var w=0,x=c.length;x>w;w++)null!=u[w]&&k.push.apply(k,u[w].nodes);for(var $,w=0;$=u.nodes[w];w++)null!=$.parentNode&&k.indexOf($)<0&&s([$],[u[w]]);c.length("key"in c.attrs?1:0)}if((c.tag!=u.tag||_.join()!=Object.keys(u.attrs).join()||c.attrs.id!=u.attrs.id)&&(u.nodes.length&&s(u.nodes),u.configContext&&typeof u.configContext.onunload===R&&u.configContext.onunload()),L.call(c.tag)!=D)return;var $,Y=0===u.nodes.length;if(c.attrs.xmlns?h=c.attrs.xmlns:"svg"===c.tag?h="http://www.w3.org/2000/svg":"math"===c.tag&&(h="http://www.w3.org/1998/Math/MathML"),Y?($=c.attrs.is?h===t?P.createElement(c.tag,c.attrs.is):P.createElementNS(h,c.tag,c.attrs.is):h===t?P.createElement(c.tag):P.createElementNS(h,c.tag),u={tag:c.tag,attrs:_.length?i($,c.tag,c.attrs,{},h):{},children:null!=c.children&&c.children.length>0?a($,c.tag,t,t,c.children,u.children,!0,0,c.attrs.contenteditable?$:p,h,v):c.children,nodes:[$]},u.children&&!u.children.nodes&&(u.children.nodes=[]),"select"===c.tag&&c.attrs.value&&i($,c.tag,{value:c.attrs.value},{},h),e.insertBefore($,e.childNodes[f]||null)):($=u.nodes[0],_.length&&i($,c.tag,c.attrs,u.attrs,h),u.children=a($,c.tag,t,t,c.children,u.children,!1,0,c.attrs.contenteditable?$:p,h,v),u.nodes.intact=!0,d===!0&&null!=$&&e.insertBefore($,e.childNodes[f]||null)),typeof c.attrs.config===R){var V=u.configContext=u.configContext||{},Q=function(e,t){return function(){return e.attrs.config.apply(e,t)}};v.push(Q(c,[$,!Y,V,u]))}}else if(typeof g!=R){var k;0===u.nodes.length?(c.$trusted?k=l(e,f,c):(k=[P.createTextNode(c)],e.nodeName.match(K)||e.insertBefore(k[0],e.childNodes[f]||null)),u="string number boolean".indexOf(typeof c)>-1?new c.constructor(c):c,u.nodes=k):u.valueOf()!==c.valueOf()||d===!0?(k=u.nodes,p&&p===P.activeElement||(c.$trusted?(s(k,u),k=l(e,f,c)):"textarea"===n?e.value=c:p?p.innerHTML=c:((1===k[0].nodeType||k.length>1)&&(s(u.nodes,u),k=[P.createTextNode(c)]),e.insertBefore(k[0],e.childNodes[f]||null),k[0].nodeValue=c)),u=new c.constructor(c),u.nodes=k):u.nodes.intact=!0}return u}function i(e,t,n,r,o){for(var a in n){var i=n[a],s=r[a];if(a in r&&s===i)"value"===a&&"input"===t&&e.value!=i&&(e.value=i);else{r[a]=i;try{if("config"===a)continue;if(typeof i===R&&0===a.indexOf("on"))e[a]=u(i,e);else if("style"===a&&null!=i&&L.call(i)===S){for(var c in i)(null==s||s[c]!==i[c])&&(e.style[c]=i[c]);for(var c in s)c in i||(e.style[c]="")}else null!=o?"href"===a?e.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===a?e.setAttribute("class",i):e.setAttribute(a,i):a in e&&"list"!==a&&"style"!==a&&"form"!==a&&"type"!==a?("input"!=a||e[a]!==i)&&(e[a]=i):e.setAttribute(a,i)}catch(l){if(l.message.indexOf("Invalid argument")<0)throw l}}}return r}function s(e,t){for(var n=e.length-1;n>-1;n--)if(e[n]&&e[n].parentNode){try{e[n].parentNode.removeChild(e[n])}catch(r){}t=[].concat(t),t[n]&&c(t[n])}0!=e.length&&(e.length=0)}function c(e){if(e.configContext&&typeof e.configContext.onunload===R&&e.configContext.onunload(),e.children)if(L.call(e.children)===q)for(var t,n=0;t=e.children[n];n++)c(t);else e.children.tag&&c(e.children)}function l(e,t,n){var r=e.childNodes[t];if(r){var o=1!=r.nodeType,a=P.createElement("span");o?(e.insertBefore(a,r||null),a.insertAdjacentHTML("beforebegin",n),e.removeChild(a)):r.insertAdjacentHTML("beforebegin",n)}else e.insertAdjacentHTML("beforeend",n);for(var i=[];e.childNodes[t]!==r;)i.push(e.childNodes[t]),t++;return i}function u(e,t){return function(n){n=n||event,r.redraw.strategy("diff"),r.startComputation();try{return e.call(t,n)}finally{Z()}}}function d(e){var t=X.indexOf(e);return 0>t?X.push(e)-1:t}function f(e){var t=function(){return arguments.length&&(e=arguments[0]),e};return t.toJSON=function(){return e},t}function p(){for(var e,t="all"===r.redraw.strategy(),n=0;e=G[n];n++)$[n]&&r.render(e,J[n].view($[n]),t);V&&(V(),V=null),_=null,Y=new Date,r.redraw.strategy("diff")}function h(e){return e.slice(nt[r.route.mode].length)}function v(e,t,n){et={};var o=n.indexOf("?");-1!==o&&(et=y(n.substr(o+1,n.length)),n=n.substr(0,o));for(var a in t){if(a===n)return r.module(e,t[a]),!0;var i=new RegExp("^"+a.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(i.test(n))return n.replace(i,function(){for(var n=a.match(/:[^\/]+/g)||[],o=[].slice.call(arguments,1,-2),i=0,s=n.length;s>i;i++)et[n[i].replace(/:|\./g,"")]=decodeURIComponent(o[i]);r.module(e,t[a])}),!0}}function m(e){if(e=e||event,!e.ctrlKey&&!e.metaKey&&2!==e.which){e.preventDefault?e.preventDefault():e.returnValue=!1;var t=e.currentTarget||this,n="pathname"===r.route.mode&&t.search?y(t.search.slice(1)):{};r.route(t[r.route.mode].slice(nt[r.route.mode].length),n)}}function g(){"hash"!=r.route.mode&&T.hash?T.hash=T.hash:e.scrollTo(0,0)}function b(e,t){var n=[];for(var r in e){var o=t?t+"["+r+"]":r,a=e[r];n.push(null!=a&&L.call(a)===S?b(a,o):encodeURIComponent(o)+"="+encodeURIComponent(a))}return n.join("&")}function y(e){for(var t=e.split("&"),n={},r=0,o=t.length;o>r;r++){var a=t[r].split("=");n[w(a[0])]=a[1]?w(a[1]):""}return n}function w(e){return decodeURIComponent(e.replace(/\+/g," "))}function x(e){var n=d(e);s(e.childNodes,U[n]),U[n]=t}function k(e){var t=r.prop();return e.then(t),t.then=function(t,n){return k(e.then(t,n))},t}function E(e,t){function n(e){d=e||l,p.map(function(e){d===c&&e.resolve(f)||e.reject(f)})}function o(e,t,n,o){if((null!=f&&L.call(f)===S||typeof f===R)&&typeof e===R)try{var a=0;e.call(f,function(e){a++||(f=e,t())},function(e){a++||(f=e,n())})}catch(i){r.deferred.onerror(i),f=i,n()}else o()}function a(){var l;try{l=f&&f.then}catch(p){return r.deferred.onerror(p),f=p,d=s,a()}o(l,function(){d=i,a()},function(){d=s,a()},function(){try{d===i&&typeof e===R?f=e(f):d===s&&"function"==typeof t&&(f=t(f),d=i)}catch(a){return r.deferred.onerror(a),f=a,n()}f===u?(f=TypeError(),n()):o(l,function(){n(c)},n,function(){n(d===i&&c)})})}var i=1,s=2,c=3,l=4,u=this,d=0,f=0,p=[];u.promise={},u.resolve=function(e){return d||(f=e,d=i,a()),this},u.reject=function(e){return d||(f=e,d=s,a()),this},u.promise.then=function(e,t){var n=new E(e,t);return d===c?n.resolve(f):d===l?n.reject(f):p.push(n),n.promise}}function C(e){return e}function O(n){if(!n.dataType||"jsonp"!==n.dataType.toLowerCase()){var r=new e.XMLHttpRequest;if(r.open(n.method,n.url,!0,n.user,n.password),r.onreadystatechange=function(){4===r.readyState&&(r.status>=200&&r.status<300?n.onload({type:"load",target:r}):n.onerror({type:"error",target:r}))},n.serialize===JSON.stringify&&n.data&&"GET"!==n.method&&r.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.deserialize===JSON.parse&&r.setRequestHeader("Accept","application/json, text/*"),typeof n.config===R){var o=n.config(r,n);null!=o&&(r=o)}var a="GET"!==n.method&&n.data?n.data:"";if(a&&L.call(a)!=D&&a.constructor!=e.FormData)throw"Request data should be either be a string or FormData. Check the `serialize` option in `m.request`";return r.send(a),r}var i="mithril_callback_"+(new Date).getTime()+"_"+Math.round(1e16*Math.random()).toString(36),s=P.createElement("script");e[i]=function(r){P.body.removeChild(s),n.onload({type:"load",target:{responseText:r}}),e[i]=t},s.onerror=function(){return P.body.removeChild(s),n.onerror({type:"error",target:{status:500,responseText:JSON.stringify({error:"Error making jsonp request"})}}),e[i]=t,!1},s.onload=function(){return!1},s.src=n.url+(n.url.indexOf("?")>0?"&":"?")+(n.callbackKey?n.callbackKey:"callback")+"="+i+"&"+b(n.data||{}),P.body.appendChild(s)}function M(e,t,n){if("GET"===e.method&&"jsonp"!=e.dataType){var r=e.url.indexOf("?")<0?"?":"&",o=b(t);e.url=e.url+(o?r+o:"")}else e.data=n(t);return e}function j(e,t){var n=e.match(/:[a-z]\w+/gi);if(n&&t)for(var r=0;ru;u++)o[u]()},r.trust=function(e){return e=new String(e),e.$trusted=!0,e},r.prop=function(e){return(null!=e&&L.call(e)===S||typeof e===R)&&typeof e.then===R?k(e):f(e)};var H,G=[],J=[],$=[],_=null,Y=0,V=null,Q=16;r.module=function(e,t){var n=G.indexOf(e);0>n&&(n=G.length);var o=!1;if($[n]&&typeof $[n].onunload===R){var a={preventDefault:function(){o=!0}};$[n].onunload(a)}if(!o){r.redraw.strategy("all"),r.startComputation(),G[n]=e;var i=H=t,s=new t.controller;return i===H&&($[n]=s,J[n]=t),Z(),$[n]}},r.redraw=function(t){_&&t!==!0?(new Date-Y>Q||N===e.requestAnimationFrame)&&(_>0&&A(_),_=N(p,Q)):(p(),_=N(function(){_=null},Q))},r.redraw.strategy=r.prop();var W=0;r.startComputation=function(){W++},r.endComputation=function(){W=Math.max(W-1,0),0===W&&r.redraw()};var Z=function(){"none"==r.redraw.strategy()?(W--,r.redraw.strategy("diff")):r.endComputation()};r.withAttr=function(e,t){return function(n){n=n||event;var r=n.currentTarget||this;t(e in r?r[e]:r.getAttribute(e))}};var et,tt,nt={pathname:"",hash:"#",search:"?"},rt=function(){};return r.route=function(){if(0===arguments.length)return tt;if(3===arguments.length&&L.call(arguments[1])===D){var t=arguments[0],n=arguments[1],o=arguments[2];rt=function(e){var a=tt=h(e);v(t,o,a)||r.route(n,!0)};var a="hash"===r.route.mode?"onhashchange":"onpopstate";e[a]=function(){tt!=h(T[r.route.mode])&&rt(T[r.route.mode])},V=g,e[a]()}else if(arguments[0].addEventListener){{var i=arguments[0];arguments[1],arguments[2]}i.href=("pathname"!==r.route.mode?T.pathname:"")+nt[r.route.mode]+this.attrs.href,i.removeEventListener("click",m),i.addEventListener("click",m)}else if(L.call(arguments[0])===D){tt=arguments[0];var s=arguments[1]||{},c=tt.indexOf("?"),l=c>-1?y(tt.slice(c+1)):{};for(var u in s)l[u]=s[u];var d=b(l),f=c>-1?tt.slice(0,c):tt;d&&(tt=f+(-1===f.indexOf("?")?"?":"&")+d);var p=(3===arguments.length?arguments[2]:arguments[1])===!0;e.history.pushState?(V=function(){e.history[p?"replaceState":"pushState"](null,P.title,nt[r.route.mode]+tt),g()},rt(nt[r.route.mode]+tt)):T[r.route.mode]=tt}},r.route.param=function(e){if(!et)throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()");return et[e]},r.route.mode="search",r.deferred=function(){var e=new E;return e.promise=k(e.promise),e},r.deferred.onerror=function(e){if("[object Error]"===L.call(e)&&!e.constructor.toString().match(/ Error/))throw e},r.sync=function(e){function t(e,t){return function(r){return i[e]=r,t||(n="reject"),0===--a&&(o.promise(i),o[n](i)),r}}var n="resolve",o=r.deferred(),a=e.length,i=new Array(a);if(e.length>0)for(var s=0;s=t)e.animation.current={},e.render();else{var n=u.easeInOutCubic(t);for(var r in e.animation.current.anims){var o=e.animation.current.anims[r];o[1]=[i(o[0][0]*n,10),i(o[0][1]*n,10)]}for(var a in e.animation.current.fadings)e.animation.current.fadings[a].opacity=i(n,100);e.render(),requestAnimationFrame(function(){s(e)})}}}function c(e,t){var n={orientation:t.orientation,pieces:{}};for(var r in t.pieces)n.pieces[r]={role:t.pieces[r].role,color:t.pieces[r].color};var o=e(),i=a(n,t);if(Object.keys(i.anims).length>0||i.fadings.length>0){var c=t.animation.current.start;t.animation.current={start:(new Date).getTime(),duration:t.animation.duration,anims:i.anims,fadings:i.fadings},c||s(t)}else t.renderRAF();return o}var l=(e("mithril"),e("./util")),u={easeInOutCubic:function(e){return.5>e?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1}};t.exports=function(e,t,n){return function(){var r=[t].concat(Array.prototype.slice.call(arguments,0));if(t.render){if(t.animation.enabled&&!n)return c(l.partialApply(e,r),t);var o=e.apply(null,r);return t.renderRAF(),o}return e.apply(null,r)}}},{"./util":14,mithril:3}],5:[function(e,t){var n=(e("mithril"),e("./board"));t.exports=function(e){return{set:e.set,toggleOrientation:e.toggleOrientation,getOrientation:function(){return e.data.orientation},getPieces:function(){return e.data.pieces},getMaterialDiff:function(){return n.getMaterialDiff(e.data)},getFen:e.getFen,dump:function(){return e.data},move:e.apiMove,setPieces:e.setPieces,setCheck:e.setCheck,playPremove:e.playPremove,cancelPremove:e.cancelPremove,cancelMove:e.cancelMove,stop:e.stop}}},{"./board":6,mithril:3}],6:[function(e,t){function n(e){setTimeout(e,1)}function r(e){e.orientation=O.opposite(e.orientation)}function o(e){e.lastMove=null,h(e,null),c(e)}function a(e,t){Object.keys(t).forEach(function(n){t[n]?e.pieces[n]=t[n]:delete e.pieces[n]}),e.movable.dropped=[]}function i(e,t){var n=t||e.turnColor;Object.keys(e.pieces).forEach(function(t){e.pieces[t].color===n&&"king"===e.pieces[t].role&&(e.check=t)})}function s(e,t,r){e.premovable.current=[t,r],n(O.partial(e.premovable.events.set,t,r))}function c(e){e.premovable.current&&(e.premovable.current=null,n(e.premovable.events.unset))}function l(e,t,r){var o=j(function(){return t!==r&&e.pieces[t]?(e.pieces[r]&&n(O.partial(e.events.capture,r,e.pieces[r])),e.pieces[r]=e.pieces[t],delete e.pieces[t],e.lastMove=[t,r],e.check=null,n(e.events.change),!0):!1},e)();return o&&(e.movable.dropped=[]),o}function u(e,t,n){var r=l(e,t,n);return r&&(e.movable.dests={},e.turnColor=O.opposite(e.turnColor)),r}function d(e,t,n){return l(e,t,n)}function f(e,t,r){r?m(e,t,r)?u(e,t,r)&&(h(e,null),n(O.partial(e.movable.events.after,t,r,{premove:!1,holdTime:P.stop()}))):b(e,t,r)?(s(e,t,r),h(e,null)):v(e,r)||g(e,r)?h(e,r):h(e,null):(h(e,null),"trash"===e.movable.dropOff&&(delete e.pieces[t],n(e.events.change)))}function p(e,t){e.selected?t?e.selected!==t&&f(e,e.selected,t):h(e,null):(v(e,t)||g(e,t))&&h(e,t),t&&n(O.partial(e.events.select,t))}function h(e,t){e.selected=t,e.premovable.dests=t&&g(e,t)?M(e.pieces,t):null}function v(e,t){var n=e.pieces[t];return n&&("both"===e.movable.color||e.movable.color===n.color&&e.turnColor===n.color)}function m(e,t,n){return t!==n&&v(e,t)&&(e.movable.free||O.containsX(e.movable.dests[t],n))}function g(e,t){var n=e.pieces[t];return n&&e.premovable.enabled&&e.movable.color===n.color&&e.turnColor!==n.color}function b(e,t,n){return t!==n&&g(e,t)&&O.containsX(M(e.pieces,t),n)}function y(e,t){var n=e.pieces[t];return n&&e.draggable.enabled&&("both"===e.movable.color||e.movable.color===n.color&&(e.turnColor===n.color||e.premovable.enabled))}function w(e){var t=e.premovable.current;if(t){var r=t[0],o=t[1];m(e,r,o)&&u(e,r,o)&&n(O.partial(e.movable.events.after,r,o,{premove:!0})),c(e)}}function x(e){c(e),p(e,null)}function k(e){e.movable.color=null,e.movable.dests={},x(e)}function E(e,t,n){if(n||e.bounds){n=n||e.bounds();var r=Math.ceil(8*((t[0]-n.left)/n.width));r="white"===e.orientation?r:9-r;var o=Math.ceil(8-8*((t[1]-n.top)/n.height));return o="white"===e.orientation?o:9-o,r>0&&9>r&&o>0&&9>o?O.pos2key([r,o]):void 0}}function C(e){var t={king:0,queen:0,rook:0,bishop:0,knight:0,pawn:0};for(var n in e.pieces){var r=e.pieces[n];t[r.role]+="white"===r.color?1:-1}var o={white:{},black:{}};for(var a in t){var i=t[a];i>0?o.white[a]=i:0>i&&(o.black[a]=-i)}return o}var O=e("./util"),M=e("./premove"),j=e("./anim"),P=e("./hold");t.exports={reset:o,toggleOrientation:r,setPieces:a,setCheck:i,selectSquare:p,setSelected:h,isDraggable:y,canMove:m,userMove:f,apiMove:d,playPremove:w,unsetPremove:c,cancelMove:x,stop:k,getKeyAtDomPos:E,getMaterialDiff:C}},{"./anim":4,"./hold":12,"./premove":13,"./util":14}],7:[function(e,t){var n=e("merge"),r=e("./board"),o=e("./fen");t.exports=function(e,t){t&&(t.movable&&t.movable.dests&&delete e.movable.dests,n.recursive(e,t),e.fen&&(e.pieces=o.read(e.fen),e.check=t.check,delete e.fen),e.check===!0&&r.setCheck(e),e.movable.dropped=[],e.selected&&r.setSelected(e,e.selected),e.animation.duration<10&&(e.animation.enabled=!1))}},{"./board":6,"./fen":11,merge:2}],8:[function(e,t){var n=e("./board"),r=e("./data"),o=e("./fen"),a=e("./configure"),i=e("./anim"),s=e("./drag");t.exports=function(e){this.data=r(e),this.getFen=function(){return o.write(this.data.pieces)}.bind(this),this.set=i(a,this.data),this.toggleOrientation=i(n.toggleOrientation,this.data),this.setPieces=i(n.setPieces,this.data),this.selectSquare=i(n.selectSquare,this.data,!0),this.apiMove=i(n.apiMove,this.data),this.playPremove=i(n.playPremove,this.data),this.cancelPremove=i(n.unsetPremove,this.data,!0),this.setCheck=i(n.setCheck,this.data,!0),this.cancelMove=i(function(e){n.cancelMove(e),s.cancel(e)}.bind(this),this.data,!0),this.stop=i(function(e){n.stop(e),s.cancel(e)}.bind(this),this.data,!0)}},{"./anim":4,"./board":6,"./configure":7,"./data":9,"./drag":10,"./fen":11}],9:[function(e,t){var n=e("./fen"),r=e("./configure");t.exports=function(e){var t={pieces:n.read(n.initial),orientation:"white",turnColor:"white",check:null,lastMove:null,selected:null,coordinates:!0,render:null,renderRAF:null,element:null,bounds:null,viewOnly:!1,minimalDom:!1,highlight:{lastMove:!0,check:!0,dragOver:!0},animation:{enabled:!0,duration:200,current:{}},movable:{free:!0,color:"both",dests:{},dropOff:"revert",dropped:[],showDests:!0,events:{after:function(){}}},premovable:{enabled:!0,showDests:!0,dests:[],current:null,events:{set:function(){},unset:function(){}}},draggable:{enabled:!0,distance:3,squareTarget:!1,centerPiece:!0,showGhost:!0,current:{}},events:{change:function(){},capture:function(){},select:function(){}}};return r(t,e||{}),t}},{"./configure":7,"./fen":11}],10:[function(e,t){function n(e){return e?e.color+" "+e.role:""}function r(e,t){if(!(void 0!==t.button&&0!==t.button||t.touches&&t.touches.length>1)){t.stopPropagation(),t.preventDefault(),c=t.target;var r=e.selected,a=u.eventPosition(t),i=e.bounds(),s=l.getKeyAtDomPos(e,a,i),f=!!e.premovable.current;l.selectSquare(e,s);var p=e.selected===s;if(e.pieces[s]&&p&&l.isDraggable(e,s)){var h=e.element.querySelector("."+s).getBoundingClientRect();e.draggable.current={previouslySelected:r,orig:s,piece:n(e.pieces[s]),rel:a,epos:a,pos:[0,0],dec:e.draggable.centerPiece?[a[0]-(h.left+h.width/2),a[1]-(h.top+h.height/2)]:[0,0],bounds:i,started:!1},d.start()}else f&&l.unsetPremove(e);o(e)}}function o(e){requestAnimationFrame(function(){var t=e.draggable.current;t.orig&&(e.animation.current.start&&-1!==Object.keys(e.animation.current.anims).indexOf(t.orig)&&(e.animation.current={}),n(e.pieces[t.orig])!=t.piece?s(e):(!t.started&&u.distance(t.epos,t.rel)>=e.draggable.distance&&(t.started=!0),t.started&&(t.pos=[t.epos[0]-t.rel[0],t.epos[1]-t.rel[1]],t.over=l.getKeyAtDomPos(e,t.epos,t.bounds)))),e.render(),t.orig&&o(e)})}function a(e,t){t.touches&&t.touches.length>1||e.draggable.current.orig&&(e.draggable.current.epos=u.eventPosition(t))}function i(e,t){var n=e.draggable,r=n.current?n.current.orig:null;r&&(t&&"touchend"===t.type&&c!==t.target||(l.unsetPremove(e),n.current.started?(dest=n.current.over,r!==dest&&(e.movable.dropped=[r,dest]),l.userMove(e,r,dest)):n.current.previouslySelected===r&&l.setSelected(e,null),n.current={}))}function s(e){e.draggable.current.orig&&(e.draggable.current={},l.selectSquare(e,null))}{var c,l=e("./board"),u=e("./util"),d=e("./hold");e("mithril")}t.exports={start:r,move:a,end:i,cancel:s,processDrag:o}},{"./board":6,"./hold":12,"./util":14,mithril:3}],11:[function(e,t){function n(e){"start"===e&&(e=a);var t={};return e.replace(/ .+$/,"").split("/").forEach(function(e,n){var r=0;e.split("").forEach(function(e){var a=parseInt(e);a?r+=a:(r++,t[o.pos2key([r,8-n])]={role:i[e.toLowerCase()],color:e===e.toLowerCase()?"black":"white"})})}),t}function r(e){return[8,7,6,5,4,3,2].reduce(function(e,t){return e.replace(new RegExp(Array(t+1).join("1"),"g"),t)},o.invRanks.map(function(t){return o.ranks.map(function(n){var r=e[o.pos2key([n,t])];if(r){var a=s[r.role];return"white"===r.color?a.toUpperCase():a}return"1"}).join("")}).join("/"))}var o=e("./util"),a="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",i={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},s={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};t.exports={initial:a,read:n,write:r}},{"./util":14}],12:[function(e,t){var n,r=function(){n=new Date},o=function(){n=null},a=function(){if(!n)return 0;var e=new Date-n;return n=null,e};t.exports={start:r,cancel:o,stop:a}},{}],13:[function(e,t){function n(e,t){return Math.abs(e-t)}function r(e,t,r,o,a){return n(t,o)<2&&("white"===e?a===r+1||2===r&&4===a&&t===o:a===r-1||7===r&&5===a&&t===o)}function o(e,t,r,o){var a=n(e,r),i=n(t,o);return 1===a&&2===i||2===a&&1===i}function a(e,t,r,o){return n(e,r)===n(t,o)}function i(e,t,n,r){return e===n||t===r}function s(e,t,n,r){return a(e,t,n,r)||i(e,t,n,r)}function c(e,t,r,o,a,i){return n(r,a)<2&&n(o,i)<2||o===i&&o===("white"===e?1:8)&&(5===r&&(3===a||7===a)||d.containsX(t,a))}function l(e,t){return Object.keys(e).filter(function(n){var r=e[n];return r&&r.color===t&&"rook"===r.role}).map(function(e){return d.key2pos(e)[0]})}function u(e,t){var n,u=e[t],f=d.key2pos(t);switch(u.role){case"pawn":n=r.bind(null,u.color);break;case"knight":n=o;break;case"bishop":n=a;break;case"rook":n=i;break;case"queen":n=s;break;case"king":n=c.bind(null,u.color,l(e,u.color))}return d.allPos.filter(function(e){return(f[0]!==e[0]||f[1]!==e[1])&&n(f[0],f[1],e[0],e[1])}).map(d.pos2key)}var d=e("./util");t.exports=u},{"./util":14}],14:[function(e,t){function n(e){return g[e[0]-1]+e[1]}function r(e){return[g.indexOf(e[0])+1,parseInt(e[1])]}function o(e){return g[7-g.indexOf(e[0])]+(9-parseInt(e[1]))}function a(e){var t=[];for(var n in e)e[n]&&t.push(n);return t.join(" ")}function i(e){return"white"===e?"black":"white"}function s(e,t){return e&&(e[0]===t||e[1]===t)}function c(e,t){return e&&-1!==e.indexOf(t)}function l(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}function u(){return m||(m=d()),m}function d(){return"transform"in document.body.style?"transform":"webkitTransform"in document.body.style?"webkitTransform":"mozTransform"in document.body.style?"mozTransform":"oTransform"in document.body.style?"oTransform":"msTransform"}function f(e){return"translate3d("+e[0]+"px,"+e[1]+"px,0)"}function p(e){return e.touches?[e.targetTouches[0].clientX,e.targetTouches[0].clientY]:[e.clientX,e.clientY]}function h(e,t){return e.bind.apply(e,[null].concat(t))}function v(){return h(arguments[0],Array.prototype.slice.call(arguments,1))}var m,g="abcdefgh".split(""),b=[1,2,3,4,5,6,7,8],y=[8,7,6,5,4,3,2,1],w=function(){var e=[];return y.forEach(function(t){b.forEach(function(n){e.push([n,t])})}),e}(),x=w.slice().reverse(),k=w.map(n);t.exports={files:g,ranks:b,invRanks:y,allPos:w,invPos:x,allKeys:k,pos2key:n,key2pos:r,invertKey:o,classSet:a,opposite:i,translate:f,contains2:s,containsX:c,distance:l,eventPosition:p,partialApply:h,partial:v,transformProp:u}},{}],15:[function(e,t){function n(e){return["cg-piece",e.role,e.color].join(" ")}function r(e,t,r){var o={style:{},"class":n(r)},a=e.data.draggable.current;if(a.orig!==t||0===a.pos[0]&&0===a.pos[1]){if(e.data.animation.current.anims){var i=e.data.animation.current.anims[t];i&&(o.style[f.transformProp()]=f.translate(i[1]))}}else o.style[f.transformProp()]=f.translate([a.pos[0]+a.dec[0],a.pos[1]+a.dec[1]]),o.class+=" dragging";return{tag:"div",attrs:o}}function o(e){return{tag:"div",attrs:{"class":n(e)+" ghost"}}}function a(e,t,n){var a=f.files[t[0]-1],i=t[1],s=a+i,c=e.data.pieces[s],l=e.data.highlight.dragOver&&e.data.draggable.current.over===s,u={"class":"cg-square "+s+" "+f.classSet({selected:e.data.selected===s,check:e.data.highlight.check&&e.data.check===s,"last-move":e.data.highlight.lastMove&&f.contains2(e.data.lastMove,s),"move-dest":(l||e.data.movable.showDests)&&f.containsX(e.data.movable.dests[e.data.selected],s),"premove-dest":(l||e.data.premovable.showDests)&&f.containsX(e.data.premovable.dests,s),"current-premove":f.contains2(e.data.premovable.current,s),"drag-over":l,occupied:!!c}),style:{left:12.5*(n?t[0]-1:8-t[0])+"%",bottom:12.5*(n?t[1]-1:8-t[1])+"%"}};e.data.coordinates&&(t[1]===(n?1:8)&&(u["data-coord-x"]=a),t[0]===(n?8:1)&&(u["data-coord-y"]=i));var d=[];return c&&(d.push(r(e,s,c)),e.data.draggable.current.orig===s&&e.data.draggable.showGhost&&d.push(o(c))),{tag:"div",attrs:u,children:d}}function i(e,t){var n=f.key2pos(t.over),r="white"===e.data.orientation?n[0]:9-n[0],o="white"===e.data.orientation?n[1]:9-n[1];return{tag:"div",attrs:{id:"cg-square-target",style:{width:t.bounds.width/4+"px",height:t.bounds.height/4+"px",left:(r-1.5)*t.bounds.width/8+"px",top:(7.5-o)*t.bounds.height/8+"px"}}} -}function s(e){return{tag:"div",attrs:{"class":"cg-square fading",style:{left:e.left,bottom:e.bottom,opacity:e.opacity}},children:[{tag:"div",attrs:{"class":n(e.piece)}}]}}function c(e,t){var r=[];return e.data.lastMove&&e.data.lastMove.forEach(function(e){var n=f.key2pos(e);r.push({tag:"div",attrs:{"class":"cg-square last-move",style:{left:12.5*(t?n[0]-1:8-n[0])+"%",bottom:12.5*(t?n[1]-1:8-n[1])+"%"}}})}),Object.keys(e.data.pieces).forEach(function(o){var a=f.key2pos(o),i={style:{left:12.5*(t?a[0]-1:8-a[0])+"%",bottom:12.5*(t?a[1]-1:8-a[1])+"%"},"class":n(e.data.pieces[o])};if(e.data.animation.current.anims){var s=e.data.animation.current.anims[o];s&&(i.style[f.transformProp()]=f.translate(s[1]))}r.push({tag:"div",attrs:i})}),r}function l(e){var t="white"==e.data.orientation;if(e.data.minimalDom)return c(e,t);var n=(t?f.allPos:f.invPos).map(function(n){return a(e,n,t)});return e.data.draggable.current.over&&e.data.draggable.squareTarget&&n.push(i(e,e.data.draggable.current)),e.data.animation.current.fadings&&e.data.animation.current.fadings.forEach(function(e){n.push(s(e))}),n}function u(e,t,n){var r=f.partial(p.start,e.data),o=f.partial(p.move,e.data),a=f.partial(p.end,e.data),i=["touchstart","mousedown"],s=["touchmove","mousemove"],c=["touchend","mouseup"];i.forEach(function(e){t.addEventListener(e,r)}),s.forEach(function(e){document.addEventListener(e,o)}),c.forEach(function(e){document.addEventListener(e,a)}),n.onunload=function(){i.forEach(function(e){t.removeEventListener(e,r)}),s.forEach(function(e){document.removeEventListener(e,o)}),c.forEach(function(e){document.removeEventListener(e,a)})}}function d(e){return{tag:"div",attrs:{"class":"cg-board orientation-"+e.data.orientation,config:function(t,n,r){n||(e.data.viewOnly||u(e,t,r),e.data.render=function(){h.render(t,l(e))},e.data.renderRAF=function(){requestAnimationFrame(e.data.render)},e.data.bounds=t.getBoundingClientRect.bind(t),e.data.element=t,e.data.render())}},children:[]}}var f=e("./util"),p=(e("./board"),e("./drag")),f=e("./util"),h=e("mithril");t.exports=function(e){return{tag:"div",attrs:{"class":["cg-board-wrap",e.data.viewOnly?"view-only":"manipulable",e.data.minimalDom?"minimal-dom":"full-dom"].join(" ")},children:[d(e)]}}},{"./board":6,"./drag":10,"./util":14,mithril:3}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Chessground=e()}}(function(){var e;return function t(e,n,r){function o(i,s){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!s&&c)return c(i,!0);if(a)return a(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[i]={exports:{}};e[i][0].call(u.exports,function(t){var n=e[i][1][t];return o(n?n:t)},u,u.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;ic;++c){var l=r[c],u=o(l);if("object"===u)for(var d in l){var f=e?a.clone(l[d]):l[d];i[d]=t?n(i[d],f):f}}return i}function o(e){return{}.toString.call(e).slice(8,-1).toLowerCase()}var a=function(e){return r(e===!0,!1,arguments)},i="merge";a.recursive=function(e){return r(e===!0,!0,arguments)},a.clone=function(e){var t,n,r=e,i=o(e);if("array"===i)for(r=[],n=e.length,t=0;n>t;++t)r[t]=a.clone(e[t]);else if("object"===i){r={};for(t in e)r[t]=a.clone(e[t])}return r},e?t.exports=a:window[i]=a}("object"==typeof t&&t&&"object"==typeof t.exports&&t.exports)},{}],3:[function(t,n){var r=function o(e,t){function n(e){j=e.document,P=e.location,A=e.cancelAnimationFrame||e.clearTimeout,N=e.requestAnimationFrame||e.setTimeout}function r(){var e,t=[].slice.call(arguments),n=!(null==t[1]||L.call(t[1])!==S||"tag"in t[1]||"subtree"in t[1]),r=n?t[1]:{},o="class"in r?"class":"className",a={tag:"div",attrs:{}},i=[];if(L.call(t[0])!=D)throw new Error("selector in m(selector, attrs, children) should be a string");for(;e=F.exec(t[0]);)if(""===e[1]&&e[2])a.tag=e[2];else if("#"===e[1])a.attrs.id=e[2];else if("."===e[1])i.push(e[2]);else if("["===e[3][0]){var s=B.exec(e[3]);a.attrs[s[1]]=s[3]||(s[2]?"":!0)}i.length>0&&(a.attrs[o]=i.join(" "));var c=n?t[2]:t[1];a.children=L.call(c)===q?c:t.slice(n?2:1);for(var l in r)a.attrs[l]=l===o?(a.attrs[l]||"")+" "+r[l]:r[l];return a}function a(e,n,r,o,c,u,d,f,p,h,v){if((null==c||null==c.toString())&&(c=""),"retain"===c.subtree)return u;var m=L.call(u),g=L.call(c);if(null==u||m!==g){if(null!=u)if(r&&r.nodes){var b=f-o,y=b+(g===q?c:u.nodes).length;s(r.nodes.slice(b,y),r.slice(b,y))}else u.nodes&&s(u.nodes,u);u=new c.constructor,u.tag&&(u={}),u.nodes=[]}if(g===q){for(var w=0,x=c.length;x>w;w++)L.call(c[w])===q&&(c=c.concat.apply([],c),w--);for(var k=[],E=u.length===c.length,C=0,O=1,M=2,T=3,P={},N=[],A=!1,w=0,x=u.length;x>w;w++)u[w]&&u[w].attrs&&null!=u[w].attrs.key&&(A=!0,P[u[w].attrs.key]={action:O,index:w});if(A){c.indexOf(null)>-1&&(c=c.filter(function(e){return null!=e}));for(var w=0,x=c.length;x>w;w++)if(c[w]&&c[w].attrs)if(null!=c[w].attrs.key){var F=c[w].attrs.key;P[F]=P[F]?{action:T,index:w,from:P[F].index,element:e.childNodes[P[F].index]||j.createElement("div")}:{action:M,index:w}}else N.push({index:w,element:e.childNodes[w]||j.createElement("div")});for(var B,I=Object.keys(P).map(function(e){return P[e]}),z=I.sort(function(e,t){return e.action-t.action||e.index-t.index}),X=u.slice(),w=0;B=z[w];w++){if(B.action===O&&(s(u[B.index].nodes,u[B.index]),X.splice(B.index,1)),B.action===M){var U=j.createElement("div");U.key=c[B.index].attrs.key,e.insertBefore(U,e.childNodes[B.index]||null),X.splice(B.index,0,{attrs:{key:c[B.index].attrs.key},nodes:[U]})}B.action===T&&(e.childNodes[B.index]!==B.element&&null!==B.element&&e.insertBefore(B.element,e.childNodes[B.index]||null),X[B.index]=u[B.from])}for(var w=0,x=N.length;x>w;w++){var B=N[w];e.insertBefore(B.element,e.childNodes[B.index]||null),X[B.index]=u[B.index]}u=X,u.nodes=[];for(var H,w=0;H=e.childNodes[w];w++)u.nodes.push(H)}for(var w=0,G=0,x=c.length;x>w;w++){var J=a(e,n,u,f,c[w],u[G],d,f+C||C,p,h,v);J!==t&&(J.nodes.intact||(E=!1),C+=J.$trusted?(J.match(/<[^\/]|\>\s*[^<]/g)||[]).length:L.call(J)===q?J.length:1,u[G++]=J)}if(!E){for(var w=0,x=c.length;x>w;w++)null!=u[w]&&k.push.apply(k,u[w].nodes);for(var $,w=0;$=u.nodes[w];w++)null!=$.parentNode&&k.indexOf($)<0&&s([$],[u[w]]);c.length("key"in c.attrs?1:0)}if((c.tag!=u.tag||_.join()!=Object.keys(u.attrs).join()||c.attrs.id!=u.attrs.id)&&(u.nodes.length&&s(u.nodes),u.configContext&&typeof u.configContext.onunload===R&&u.configContext.onunload()),L.call(c.tag)!=D)return;var $,Y=0===u.nodes.length;if(c.attrs.xmlns?h=c.attrs.xmlns:"svg"===c.tag?h="http://www.w3.org/2000/svg":"math"===c.tag&&(h="http://www.w3.org/1998/Math/MathML"),Y?($=c.attrs.is?h===t?j.createElement(c.tag,c.attrs.is):j.createElementNS(h,c.tag,c.attrs.is):h===t?j.createElement(c.tag):j.createElementNS(h,c.tag),u={tag:c.tag,attrs:_.length?i($,c.tag,c.attrs,{},h):{},children:null!=c.children&&c.children.length>0?a($,c.tag,t,t,c.children,u.children,!0,0,c.attrs.contenteditable?$:p,h,v):c.children,nodes:[$]},u.children&&!u.children.nodes&&(u.children.nodes=[]),"select"===c.tag&&c.attrs.value&&i($,c.tag,{value:c.attrs.value},{},h),e.insertBefore($,e.childNodes[f]||null)):($=u.nodes[0],_.length&&i($,c.tag,c.attrs,u.attrs,h),u.children=a($,c.tag,t,t,c.children,u.children,!1,0,c.attrs.contenteditable?$:p,h,v),u.nodes.intact=!0,d===!0&&null!=$&&e.insertBefore($,e.childNodes[f]||null)),typeof c.attrs.config===R){var V=u.configContext=u.configContext||{},Q=function(e,t){return function(){return e.attrs.config.apply(e,t)}};v.push(Q(c,[$,!Y,V,u]))}}else if(typeof g!=R){var k;0===u.nodes.length?(c.$trusted?k=l(e,f,c):(k=[j.createTextNode(c)],e.nodeName.match(K)||e.insertBefore(k[0],e.childNodes[f]||null)),u="string number boolean".indexOf(typeof c)>-1?new c.constructor(c):c,u.nodes=k):u.valueOf()!==c.valueOf()||d===!0?(k=u.nodes,p&&p===j.activeElement||(c.$trusted?(s(k,u),k=l(e,f,c)):"textarea"===n?e.value=c:p?p.innerHTML=c:((1===k[0].nodeType||k.length>1)&&(s(u.nodes,u),k=[j.createTextNode(c)]),e.insertBefore(k[0],e.childNodes[f]||null),k[0].nodeValue=c)),u=new c.constructor(c),u.nodes=k):u.nodes.intact=!0}return u}function i(e,t,n,r,o){for(var a in n){var i=n[a],s=r[a];if(a in r&&s===i)"value"===a&&"input"===t&&e.value!=i&&(e.value=i);else{r[a]=i;try{if("config"===a)continue;if(typeof i===R&&0===a.indexOf("on"))e[a]=u(i,e);else if("style"===a&&null!=i&&L.call(i)===S){for(var c in i)(null==s||s[c]!==i[c])&&(e.style[c]=i[c]);for(var c in s)c in i||(e.style[c]="")}else null!=o?"href"===a?e.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===a?e.setAttribute("class",i):e.setAttribute(a,i):a in e&&"list"!==a&&"style"!==a&&"form"!==a&&"type"!==a?("input"!=a||e[a]!==i)&&(e[a]=i):e.setAttribute(a,i)}catch(l){if(l.message.indexOf("Invalid argument")<0)throw l}}}return r}function s(e,t){for(var n=e.length-1;n>-1;n--)if(e[n]&&e[n].parentNode){try{e[n].parentNode.removeChild(e[n])}catch(r){}t=[].concat(t),t[n]&&c(t[n])}0!=e.length&&(e.length=0)}function c(e){if(e.configContext&&typeof e.configContext.onunload===R&&e.configContext.onunload(),e.children)if(L.call(e.children)===q)for(var t,n=0;t=e.children[n];n++)c(t);else e.children.tag&&c(e.children)}function l(e,t,n){var r=e.childNodes[t];if(r){var o=1!=r.nodeType,a=j.createElement("span");o?(e.insertBefore(a,r||null),a.insertAdjacentHTML("beforebegin",n),e.removeChild(a)):r.insertAdjacentHTML("beforebegin",n)}else e.insertAdjacentHTML("beforeend",n);for(var i=[];e.childNodes[t]!==r;)i.push(e.childNodes[t]),t++;return i}function u(e,t){return function(n){n=n||event,r.redraw.strategy("diff"),r.startComputation();try{return e.call(t,n)}finally{Z()}}}function d(e){var t=X.indexOf(e);return 0>t?X.push(e)-1:t}function f(e){var t=function(){return arguments.length&&(e=arguments[0]),e};return t.toJSON=function(){return e},t}function p(){for(var e,t="all"===r.redraw.strategy(),n=0;e=G[n];n++)$[n]&&r.render(e,J[n].view($[n]),t);V&&(V(),V=null),_=null,Y=new Date,r.redraw.strategy("diff")}function h(e){return e.slice(nt[r.route.mode].length)}function v(e,t,n){et={};var o=n.indexOf("?");-1!==o&&(et=y(n.substr(o+1,n.length)),n=n.substr(0,o));for(var a in t){if(a===n)return r.module(e,t[a]),!0;var i=new RegExp("^"+a.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(i.test(n))return n.replace(i,function(){for(var n=a.match(/:[^\/]+/g)||[],o=[].slice.call(arguments,1,-2),i=0,s=n.length;s>i;i++)et[n[i].replace(/:|\./g,"")]=decodeURIComponent(o[i]);r.module(e,t[a])}),!0}}function m(e){if(e=e||event,!e.ctrlKey&&!e.metaKey&&2!==e.which){e.preventDefault?e.preventDefault():e.returnValue=!1;var t=e.currentTarget||this,n="pathname"===r.route.mode&&t.search?y(t.search.slice(1)):{};r.route(t[r.route.mode].slice(nt[r.route.mode].length),n)}}function g(){"hash"!=r.route.mode&&P.hash?P.hash=P.hash:e.scrollTo(0,0)}function b(e,t){var n=[];for(var r in e){var o=t?t+"["+r+"]":r,a=e[r];n.push(null!=a&&L.call(a)===S?b(a,o):encodeURIComponent(o)+"="+encodeURIComponent(a))}return n.join("&")}function y(e){for(var t=e.split("&"),n={},r=0,o=t.length;o>r;r++){var a=t[r].split("=");n[w(a[0])]=a[1]?w(a[1]):""}return n}function w(e){return decodeURIComponent(e.replace(/\+/g," "))}function x(e){var n=d(e);s(e.childNodes,U[n]),U[n]=t}function k(e){var t=r.prop();return e.then(t),t.then=function(t,n){return k(e.then(t,n))},t}function E(e,t){function n(e){d=e||l,p.map(function(e){d===c&&e.resolve(f)||e.reject(f)})}function o(e,t,n,o){if((null!=f&&L.call(f)===S||typeof f===R)&&typeof e===R)try{var a=0;e.call(f,function(e){a++||(f=e,t())},function(e){a++||(f=e,n())})}catch(i){r.deferred.onerror(i),f=i,n()}else o()}function a(){var l;try{l=f&&f.then}catch(p){return r.deferred.onerror(p),f=p,d=s,a()}o(l,function(){d=i,a()},function(){d=s,a()},function(){try{d===i&&typeof e===R?f=e(f):d===s&&"function"==typeof t&&(f=t(f),d=i)}catch(a){return r.deferred.onerror(a),f=a,n()}f===u?(f=TypeError(),n()):o(l,function(){n(c)},n,function(){n(d===i&&c)})})}var i=1,s=2,c=3,l=4,u=this,d=0,f=0,p=[];u.promise={},u.resolve=function(e){return d||(f=e,d=i,a()),this},u.reject=function(e){return d||(f=e,d=s,a()),this},u.promise.then=function(e,t){var n=new E(e,t);return d===c?n.resolve(f):d===l?n.reject(f):p.push(n),n.promise}}function C(e){return e}function O(n){if(!n.dataType||"jsonp"!==n.dataType.toLowerCase()){var r=new e.XMLHttpRequest;if(r.open(n.method,n.url,!0,n.user,n.password),r.onreadystatechange=function(){4===r.readyState&&(r.status>=200&&r.status<300?n.onload({type:"load",target:r}):n.onerror({type:"error",target:r}))},n.serialize===JSON.stringify&&n.data&&"GET"!==n.method&&r.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.deserialize===JSON.parse&&r.setRequestHeader("Accept","application/json, text/*"),typeof n.config===R){var o=n.config(r,n);null!=o&&(r=o)}var a="GET"!==n.method&&n.data?n.data:"";if(a&&L.call(a)!=D&&a.constructor!=e.FormData)throw"Request data should be either be a string or FormData. Check the `serialize` option in `m.request`";return r.send(a),r}var i="mithril_callback_"+(new Date).getTime()+"_"+Math.round(1e16*Math.random()).toString(36),s=j.createElement("script");e[i]=function(r){j.body.removeChild(s),n.onload({type:"load",target:{responseText:r}}),e[i]=t},s.onerror=function(){return j.body.removeChild(s),n.onerror({type:"error",target:{status:500,responseText:JSON.stringify({error:"Error making jsonp request"})}}),e[i]=t,!1},s.onload=function(){return!1},s.src=n.url+(n.url.indexOf("?")>0?"&":"?")+(n.callbackKey?n.callbackKey:"callback")+"="+i+"&"+b(n.data||{}),j.body.appendChild(s)}function M(e,t,n){if("GET"===e.method&&"jsonp"!=e.dataType){var r=e.url.indexOf("?")<0?"?":"&",o=b(t);e.url=e.url+(o?r+o:"")}else e.data=n(t);return e}function T(e,t){var n=e.match(/:[a-z]\w+/gi);if(n&&t)for(var r=0;ru;u++)o[u]()},r.trust=function(e){return e=new String(e),e.$trusted=!0,e},r.prop=function(e){return(null!=e&&L.call(e)===S||typeof e===R)&&typeof e.then===R?k(e):f(e)};var H,G=[],J=[],$=[],_=null,Y=0,V=null,Q=16;r.module=function(e,t){var n=G.indexOf(e);0>n&&(n=G.length);var o=!1;if($[n]&&typeof $[n].onunload===R){var a={preventDefault:function(){o=!0}};$[n].onunload(a)}if(!o){r.redraw.strategy("all"),r.startComputation(),G[n]=e;var i=H=t,s=new t.controller;return i===H&&($[n]=s,J[n]=t),Z(),$[n]}},r.redraw=function(t){_&&t!==!0?(new Date-Y>Q||N===e.requestAnimationFrame)&&(_>0&&A(_),_=N(p,Q)):(p(),_=N(function(){_=null},Q))},r.redraw.strategy=r.prop();var W=0;r.startComputation=function(){W++},r.endComputation=function(){W=Math.max(W-1,0),0===W&&r.redraw()};var Z=function(){"none"==r.redraw.strategy()?(W--,r.redraw.strategy("diff")):r.endComputation()};r.withAttr=function(e,t){return function(n){n=n||event;var r=n.currentTarget||this;t(e in r?r[e]:r.getAttribute(e))}};var et,tt,nt={pathname:"",hash:"#",search:"?"},rt=function(){};return r.route=function(){if(0===arguments.length)return tt;if(3===arguments.length&&L.call(arguments[1])===D){var t=arguments[0],n=arguments[1],o=arguments[2];rt=function(e){var a=tt=h(e);v(t,o,a)||r.route(n,!0)};var a="hash"===r.route.mode?"onhashchange":"onpopstate";e[a]=function(){tt!=h(P[r.route.mode])&&rt(P[r.route.mode])},V=g,e[a]()}else if(arguments[0].addEventListener){{var i=arguments[0];arguments[1],arguments[2]}i.href=("pathname"!==r.route.mode?P.pathname:"")+nt[r.route.mode]+this.attrs.href,i.removeEventListener("click",m),i.addEventListener("click",m)}else if(L.call(arguments[0])===D){tt=arguments[0];var s=arguments[1]||{},c=tt.indexOf("?"),l=c>-1?y(tt.slice(c+1)):{};for(var u in s)l[u]=s[u];var d=b(l),f=c>-1?tt.slice(0,c):tt;d&&(tt=f+(-1===f.indexOf("?")?"?":"&")+d);var p=(3===arguments.length?arguments[2]:arguments[1])===!0;e.history.pushState?(V=function(){e.history[p?"replaceState":"pushState"](null,j.title,nt[r.route.mode]+tt),g()},rt(nt[r.route.mode]+tt)):P[r.route.mode]=tt}},r.route.param=function(e){if(!et)throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()");return et[e]},r.route.mode="search",r.deferred=function(){var e=new E;return e.promise=k(e.promise),e},r.deferred.onerror=function(e){if("[object Error]"===L.call(e)&&!e.constructor.toString().match(/ Error/))throw e},r.sync=function(e){function t(e,t){return function(r){return i[e]=r,t||(n="reject"),0===--a&&(o.promise(i),o[n](i)),r}}var n="resolve",o=r.deferred(),a=e.length,i=new Array(a);if(e.length>0)for(var s=0;s=t)e.animation.current={},e.render();else{var n=u.easeInOutCubic(t);for(var r in e.animation.current.anims){var o=e.animation.current.anims[r];o[1]=[i(o[0][0]*n,10),i(o[0][1]*n,10)]}for(var a in e.animation.current.fadings)e.animation.current.fadings[a].opacity=i(n,100);e.render(),requestAnimationFrame(function(){s(e)})}}}function c(e,t){var n={orientation:t.orientation,pieces:{}};for(var r in t.pieces)n.pieces[r]={role:t.pieces[r].role,color:t.pieces[r].color};var o=e(),i=a(n,t);if(Object.keys(i.anims).length>0||i.fadings.length>0){var c=t.animation.current.start;t.animation.current={start:(new Date).getTime(),duration:t.animation.duration,anims:i.anims,fadings:i.fadings},c||s(t)}else t.renderRAF();return o}var l=(e("mithril"),e("./util")),u={easeInOutCubic:function(e){return.5>e?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1}};t.exports=function(e,t,n){return function(){var r=[t].concat(Array.prototype.slice.call(arguments,0));if(t.render){if(t.animation.enabled&&!n)return c(l.partialApply(e,r),t);var o=e.apply(null,r);return t.renderRAF(),o}return e.apply(null,r)}}},{"./util":14,mithril:3}],5:[function(e,t){var n=(e("mithril"),e("./board"));t.exports=function(e){return{set:e.set,toggleOrientation:e.toggleOrientation,getOrientation:function(){return e.data.orientation},getPieces:function(){return e.data.pieces},getMaterialDiff:function(){return n.getMaterialDiff(e.data)},getFen:e.getFen,dump:function(){return e.data},move:e.apiMove,setPieces:e.setPieces,setCheck:e.setCheck,playPremove:e.playPremove,cancelPremove:e.cancelPremove,cancelMove:e.cancelMove,stop:e.stop,explode:e.explode}}},{"./board":6,mithril:3}],6:[function(e,t){function n(e){setTimeout(e,1)}function r(e){e.orientation=O.opposite(e.orientation)}function o(e){e.lastMove=null,h(e,null),c(e)}function a(e,t){Object.keys(t).forEach(function(n){t[n]?e.pieces[n]=t[n]:delete e.pieces[n]}),e.movable.dropped=[]}function i(e,t){var n=t||e.turnColor;Object.keys(e.pieces).forEach(function(t){e.pieces[t].color===n&&"king"===e.pieces[t].role&&(e.check=t)})}function s(e,t,r){e.premovable.current=[t,r],n(O.partial(e.premovable.events.set,t,r))}function c(e){e.premovable.current&&(e.premovable.current=null,n(e.premovable.events.unset))}function l(e,t,r){var o=T(function(){return t!==r&&e.pieces[t]?(e.pieces[r]&&n(O.partial(e.events.capture,r,e.pieces[r])),e.pieces[r]=e.pieces[t],delete e.pieces[t],e.lastMove=[t,r],e.check=null,n(e.events.change),!0):!1},e)();return o&&(e.movable.dropped=[]),o}function u(e,t,n){var r=l(e,t,n);return r&&(e.movable.dests={},e.turnColor=O.opposite(e.turnColor)),r}function d(e,t,n){return l(e,t,n)}function f(e,t,r){r?m(e,t,r)?u(e,t,r)&&(h(e,null),n(O.partial(e.movable.events.after,t,r,{premove:!1,holdTime:j.stop()}))):b(e,t,r)?(s(e,t,r),h(e,null)):v(e,r)||g(e,r)?h(e,r):h(e,null):(h(e,null),"trash"===e.movable.dropOff&&(delete e.pieces[t],n(e.events.change)))}function p(e,t){e.selected?t?e.selected!==t&&f(e,e.selected,t):h(e,null):(v(e,t)||g(e,t))&&h(e,t),t&&n(O.partial(e.events.select,t))}function h(e,t){e.selected=t,e.premovable.dests=t&&g(e,t)?M(e.pieces,t):null}function v(e,t){var n=e.pieces[t];return n&&("both"===e.movable.color||e.movable.color===n.color&&e.turnColor===n.color)}function m(e,t,n){return t!==n&&v(e,t)&&(e.movable.free||O.containsX(e.movable.dests[t],n))}function g(e,t){var n=e.pieces[t];return n&&e.premovable.enabled&&e.movable.color===n.color&&e.turnColor!==n.color}function b(e,t,n){return t!==n&&g(e,t)&&O.containsX(M(e.pieces,t),n)}function y(e,t){var n=e.pieces[t];return n&&e.draggable.enabled&&("both"===e.movable.color||e.movable.color===n.color&&(e.turnColor===n.color||e.premovable.enabled))}function w(e){var t=e.premovable.current;if(t){var r=t[0],o=t[1];m(e,r,o)&&u(e,r,o)&&n(O.partial(e.movable.events.after,r,o,{premove:!0})),c(e)}}function x(e){c(e),p(e,null)}function k(e){e.movable.color=null,e.movable.dests={},x(e)}function E(e,t,n){if(n||e.bounds){n=n||e.bounds();var r=Math.ceil(8*((t[0]-n.left)/n.width));r="white"===e.orientation?r:9-r;var o=Math.ceil(8-8*((t[1]-n.top)/n.height));return o="white"===e.orientation?o:9-o,r>0&&9>r&&o>0&&9>o?O.pos2key([r,o]):void 0}}function C(e){var t={king:0,queen:0,rook:0,bishop:0,knight:0,pawn:0};for(var n in e.pieces){var r=e.pieces[n];t[r.role]+="white"===r.color?1:-1}var o={white:{},black:{}};for(var a in t){var i=t[a];i>0?o.white[a]=i:0>i&&(o.black[a]=-i)}return o}var O=e("./util"),M=e("./premove"),T=e("./anim"),j=e("./hold");t.exports={reset:o,toggleOrientation:r,setPieces:a,setCheck:i,selectSquare:p,setSelected:h,isDraggable:y,canMove:m,userMove:f,apiMove:d,playPremove:w,unsetPremove:c,cancelMove:x,stop:k,getKeyAtDomPos:E,getMaterialDiff:C}},{"./anim":4,"./hold":12,"./premove":13,"./util":14}],7:[function(e,t){var n=e("merge"),r=e("./board"),o=e("./fen");t.exports=function(e,t){t&&(t.movable&&t.movable.dests&&delete e.movable.dests,n.recursive(e,t),e.fen&&(e.pieces=o.read(e.fen),e.check=t.check,delete e.fen),e.check===!0&&r.setCheck(e),e.movable.dropped=[],e.selected&&r.setSelected(e,e.selected),e.animation.duration<10&&(e.animation.enabled=!1))}},{"./board":6,"./fen":11,merge:2}],8:[function(e,t){var n=e("./board"),r=e("./data"),o=e("./fen"),a=e("./configure"),i=e("./anim"),s=e("./drag");t.exports=function(e){this.data=r(e),this.vm={exploding:!1},this.getFen=function(){return o.write(this.data.pieces)}.bind(this),this.set=i(a,this.data),this.toggleOrientation=i(n.toggleOrientation,this.data),this.setPieces=i(n.setPieces,this.data),this.selectSquare=i(n.selectSquare,this.data,!0),this.apiMove=i(n.apiMove,this.data),this.playPremove=i(n.playPremove,this.data),this.cancelPremove=i(n.unsetPremove,this.data,!0),this.setCheck=i(n.setCheck,this.data,!0),this.cancelMove=i(function(e){n.cancelMove(e),s.cancel(e)}.bind(this),this.data,!0),this.stop=i(function(e){n.stop(e),s.cancel(e)}.bind(this),this.data,!0),this.explode=function(e){setTimeout(function(){this.data.render&&(this.data.animation.current={},this.vm.exploding=e,e.forEach(function(e){delete this.data.pieces[e]}.bind(this)),this.data.renderRAF(),setTimeout(function(){this.vm.exploding=!1,this.data.renderRAF()}.bind(this),200))}.bind(this),this.data.animation.duration/2)}.bind(this)}},{"./anim":4,"./board":6,"./configure":7,"./data":9,"./drag":10,"./fen":11}],9:[function(e,t){var n=e("./fen"),r=e("./configure");t.exports=function(e){var t={pieces:n.read(n.initial),orientation:"white",turnColor:"white",check:null,lastMove:null,selected:null,coordinates:!0,render:null,renderRAF:null,element:null,bounds:null,viewOnly:!1,minimalDom:!1,highlight:{lastMove:!0,check:!0,dragOver:!0},animation:{enabled:!0,duration:200,current:{}},movable:{free:!0,color:"both",dests:{},dropOff:"revert",dropped:[],showDests:!0,events:{after:function(){}}},premovable:{enabled:!0,showDests:!0,dests:[],current:null,events:{set:function(){},unset:function(){}}},draggable:{enabled:!0,distance:3,squareTarget:!1,centerPiece:!0,showGhost:!0,current:{}},events:{change:function(){},capture:function(){},select:function(){}}};return r(t,e||{}),t}},{"./configure":7,"./fen":11}],10:[function(e,t){function n(e){return e?e.color+" "+e.role:""}function r(e,t){if(!(void 0!==t.button&&0!==t.button||t.touches&&t.touches.length>1)){t.stopPropagation(),t.preventDefault(),c=t.target;var r=e.selected,a=u.eventPosition(t),i=e.bounds(),s=l.getKeyAtDomPos(e,a,i),f=!!e.premovable.current;l.selectSquare(e,s);var p=e.selected===s;if(e.pieces[s]&&p&&l.isDraggable(e,s)){var h=e.element.querySelector("."+s).getBoundingClientRect();e.draggable.current={previouslySelected:r,orig:s,piece:n(e.pieces[s]),rel:a,epos:a,pos:[0,0],dec:e.draggable.centerPiece?[a[0]-(h.left+h.width/2),a[1]-(h.top+h.height/2)]:[0,0],bounds:i,started:!1},d.start()}else f&&l.unsetPremove(e);o(e)}}function o(e){requestAnimationFrame(function(){var t=e.draggable.current;t.orig&&(e.animation.current.start&&-1!==Object.keys(e.animation.current.anims).indexOf(t.orig)&&(e.animation.current={}),n(e.pieces[t.orig])!=t.piece?s(e):(!t.started&&u.distance(t.epos,t.rel)>=e.draggable.distance&&(t.started=!0),t.started&&(t.pos=[t.epos[0]-t.rel[0],t.epos[1]-t.rel[1]],t.over=l.getKeyAtDomPos(e,t.epos,t.bounds)))),e.render(),t.orig&&o(e)})}function a(e,t){t.touches&&t.touches.length>1||e.draggable.current.orig&&(e.draggable.current.epos=u.eventPosition(t))}function i(e,t){var n=e.draggable,r=n.current?n.current.orig:null;r&&(t&&"touchend"===t.type&&c!==t.target||(l.unsetPremove(e),n.current.started?(dest=n.current.over,r!==dest&&(e.movable.dropped=[r,dest]),l.userMove(e,r,dest)):n.current.previouslySelected===r&&l.setSelected(e,null),n.current={}))}function s(e){e.draggable.current.orig&&(e.draggable.current={},l.selectSquare(e,null))}{var c,l=e("./board"),u=e("./util"),d=e("./hold");e("mithril")}t.exports={start:r,move:a,end:i,cancel:s,processDrag:o}},{"./board":6,"./hold":12,"./util":14,mithril:3}],11:[function(e,t){function n(e){"start"===e&&(e=a);var t={};return e.replace(/ .+$/,"").split("/").forEach(function(e,n){var r=0;e.split("").forEach(function(e){var a=parseInt(e);a?r+=a:(r++,t[o.pos2key([r,8-n])]={role:i[e.toLowerCase()],color:e===e.toLowerCase()?"black":"white"})})}),t}function r(e){return[8,7,6,5,4,3,2].reduce(function(e,t){return e.replace(new RegExp(Array(t+1).join("1"),"g"),t)},o.invRanks.map(function(t){return o.ranks.map(function(n){var r=e[o.pos2key([n,t])];if(r){var a=s[r.role];return"white"===r.color?a.toUpperCase():a}return"1"}).join("")}).join("/"))}var o=e("./util"),a="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",i={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},s={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};t.exports={initial:a,read:n,write:r}},{"./util":14}],12:[function(e,t){var n,r=function(){n=new Date},o=function(){n=null},a=function(){if(!n)return 0;var e=new Date-n;return n=null,e};t.exports={start:r,cancel:o,stop:a}},{}],13:[function(e,t){function n(e,t){return Math.abs(e-t)}function r(e,t,r,o,a){return n(t,o)<2&&("white"===e?a===r+1||2===r&&4===a&&t===o:a===r-1||7===r&&5===a&&t===o)}function o(e,t,r,o){var a=n(e,r),i=n(t,o);return 1===a&&2===i||2===a&&1===i}function a(e,t,r,o){return n(e,r)===n(t,o)}function i(e,t,n,r){return e===n||t===r}function s(e,t,n,r){return a(e,t,n,r)||i(e,t,n,r)}function c(e,t,r,o,a,i){return n(r,a)<2&&n(o,i)<2||o===i&&o===("white"===e?1:8)&&(5===r&&(3===a||7===a)||d.containsX(t,a))}function l(e,t){return Object.keys(e).filter(function(n){var r=e[n];return r&&r.color===t&&"rook"===r.role}).map(function(e){return d.key2pos(e)[0]})}function u(e,t){var n,u=e[t],f=d.key2pos(t);switch(u.role){case"pawn":n=r.bind(null,u.color);break;case"knight":n=o;break;case"bishop":n=a;break;case"rook":n=i;break;case"queen":n=s;break;case"king":n=c.bind(null,u.color,l(e,u.color))}return d.allPos.filter(function(e){return(f[0]!==e[0]||f[1]!==e[1])&&n(f[0],f[1],e[0],e[1])}).map(d.pos2key)}var d=e("./util");t.exports=u},{"./util":14}],14:[function(e,t){function n(e){return g[e[0]-1]+e[1]}function r(e){return[g.indexOf(e[0])+1,parseInt(e[1])]}function o(e){return g[7-g.indexOf(e[0])]+(9-parseInt(e[1]))}function a(e){var t=[];for(var n in e)e[n]&&t.push(n);return t.join(" ")}function i(e){return"white"===e?"black":"white"}function s(e,t){return e&&(e[0]===t||e[1]===t)}function c(e,t){return e&&-1!==e.indexOf(t)}function l(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}function u(){return m||(m=d()),m}function d(){return"transform"in document.body.style?"transform":"webkitTransform"in document.body.style?"webkitTransform":"mozTransform"in document.body.style?"mozTransform":"oTransform"in document.body.style?"oTransform":"msTransform"}function f(e){return"translate3d("+e[0]+"px,"+e[1]+"px,0)"}function p(e){return e.touches?[e.targetTouches[0].clientX,e.targetTouches[0].clientY]:[e.clientX,e.clientY]}function h(e,t){return e.bind.apply(e,[null].concat(t))}function v(){return h(arguments[0],Array.prototype.slice.call(arguments,1))}var m,g="abcdefgh".split(""),b=[1,2,3,4,5,6,7,8],y=[8,7,6,5,4,3,2,1],w=function(){var e=[];return y.forEach(function(t){b.forEach(function(n){e.push([n,t])})}),e}(),x=w.slice().reverse(),k=w.map(n);t.exports={files:g,ranks:b,invRanks:y,allPos:w,invPos:x,allKeys:k,pos2key:n,key2pos:r,invertKey:o,classSet:a,opposite:i,translate:f,contains2:s,containsX:c,distance:l,eventPosition:p,partialApply:h,partial:v,transformProp:u}},{}],15:[function(e,t){function n(e){return["cg-piece",e.role,e.color].join(" ")}function r(e,t,r){var o={style:{},"class":n(r)},a=e.data.draggable.current;if(a.orig!==t||0===a.pos[0]&&0===a.pos[1]){if(e.data.animation.current.anims){var i=e.data.animation.current.anims[t];i&&(o.style[f.transformProp()]=f.translate(i[1]))}}else o.style[f.transformProp()]=f.translate([a.pos[0]+a.dec[0],a.pos[1]+a.dec[1]]),o.class+=" dragging";return{tag:"div",attrs:o}}function o(e){return{tag:"div",attrs:{"class":n(e)+" ghost"}}}function a(e,t,n){var a=f.files[t[0]-1],i=t[1],s=a+i,c=e.data.pieces[s],l=e.data.highlight.dragOver&&e.data.draggable.current.over===s,u={"class":"cg-square "+s+" "+f.classSet({selected:e.data.selected===s,check:e.data.highlight.check&&e.data.check===s,"last-move":e.data.highlight.lastMove&&f.contains2(e.data.lastMove,s),"move-dest":(l||e.data.movable.showDests)&&f.containsX(e.data.movable.dests[e.data.selected],s),"premove-dest":(l||e.data.premovable.showDests)&&f.containsX(e.data.premovable.dests,s),"current-premove":f.contains2(e.data.premovable.current,s),"drag-over":l,occupied:!!c,exploding:e.vm.exploding&&-1!==e.vm.exploding.indexOf(s)}),style:{left:12.5*(n?t[0]-1:8-t[0])+"%",bottom:12.5*(n?t[1]-1:8-t[1])+"%"}};e.data.coordinates&&(t[1]===(n?1:8)&&(u["data-coord-x"]=a),t[0]===(n?8:1)&&(u["data-coord-y"]=i)); +var d=[];return c&&(d.push(r(e,s,c)),e.data.draggable.current.orig===s&&e.data.draggable.showGhost&&d.push(o(c))),{tag:"div",attrs:u,children:d}}function i(e,t){var n=f.key2pos(t.over),r="white"===e.data.orientation?n[0]:9-n[0],o="white"===e.data.orientation?n[1]:9-n[1];return{tag:"div",attrs:{id:"cg-square-target",style:{width:t.bounds.width/4+"px",height:t.bounds.height/4+"px",left:(r-1.5)*t.bounds.width/8+"px",top:(7.5-o)*t.bounds.height/8+"px"}}}}function s(e){return{tag:"div",attrs:{"class":"cg-square fading",style:{left:e.left,bottom:e.bottom,opacity:e.opacity}},children:[{tag:"div",attrs:{"class":n(e.piece)}}]}}function c(e,t){var r=[];return e.data.lastMove&&e.data.lastMove.forEach(function(e){var n=f.key2pos(e);r.push({tag:"div",attrs:{"class":"cg-square last-move",style:{left:12.5*(t?n[0]-1:8-n[0])+"%",bottom:12.5*(t?n[1]-1:8-n[1])+"%"}}})}),Object.keys(e.data.pieces).forEach(function(o){var a=f.key2pos(o),i={style:{left:12.5*(t?a[0]-1:8-a[0])+"%",bottom:12.5*(t?a[1]-1:8-a[1])+"%"},"class":n(e.data.pieces[o])};if(e.data.animation.current.anims){var s=e.data.animation.current.anims[o];s&&(i.style[f.transformProp()]=f.translate(s[1]))}r.push({tag:"div",attrs:i})}),r}function l(e){var t="white"==e.data.orientation;if(e.data.minimalDom)return c(e,t);var n=(t?f.allPos:f.invPos).map(function(n){return a(e,n,t)});return e.data.draggable.current.over&&e.data.draggable.squareTarget&&n.push(i(e,e.data.draggable.current)),e.data.animation.current.fadings&&e.data.animation.current.fadings.forEach(function(e){n.push(s(e))}),n}function u(e,t,n){var r=f.partial(p.start,e.data),o=f.partial(p.move,e.data),a=f.partial(p.end,e.data),i=["touchstart","mousedown"],s=["touchmove","mousemove"],c=["touchend","mouseup"];i.forEach(function(e){t.addEventListener(e,r)}),s.forEach(function(e){document.addEventListener(e,o)}),c.forEach(function(e){document.addEventListener(e,a)}),n.onunload=function(){i.forEach(function(e){t.removeEventListener(e,r)}),s.forEach(function(e){document.removeEventListener(e,o)}),c.forEach(function(e){document.removeEventListener(e,a)})}}function d(e){return{tag:"div",attrs:{"class":"cg-board orientation-"+e.data.orientation,config:function(t,n,r){n||(e.data.viewOnly||u(e,t,r),e.data.render=function(){h.render(t,l(e))},e.data.renderRAF=function(){requestAnimationFrame(e.data.render)},e.data.bounds=t.getBoundingClientRect.bind(t),e.data.element=t,e.data.render())}},children:[]}}var f=e("./util"),p=(e("./board"),e("./drag")),f=e("./util"),h=e("mithril");t.exports=function(e){return{tag:"div",attrs:{"class":["cg-board-wrap",e.data.viewOnly?"view-only":"manipulable",e.data.minimalDom?"minimal-dom":"full-dom"].join(" ")},children:[d(e)]}}},{"./board":6,"./drag":10,"./util":14,mithril:3}]},{},[1])(1)}); \ No newline at end of file diff --git a/public/stylesheets/chessground.css b/public/stylesheets/chessground.css index 0ecbaac078..570a7126c0 100644 --- a/public/stylesheets/chessground.css +++ b/public/stylesheets/chessground.css @@ -129,6 +129,9 @@ body.highlight .cg-board .cg-square.check { body.base .cg-board .cg-square.current-premove { background-color: rgba(20, 30, 85, 0.5); } +body.base .cg-board .cg-square.exploding { + background-color: rgba(255, 0, 0, 0.5); +} .cg-piece { width: 100%; height: 100%; diff --git a/ui/analyse/package.json b/ui/analyse/package.json index 67fd26590e..c4f33e01e0 100644 --- a/ui/analyse/package.json +++ b/ui/analyse/package.json @@ -30,7 +30,7 @@ "watchify": "^1.0.2" }, "dependencies": { - "chessground": "1.8.2", + "chessground": "1.8.4", "chessli.js": "file:../chessli", "game": "file:../game", "lodash-node": "^2.4.1", diff --git a/ui/editor/package.json b/ui/editor/package.json index 6e3620b630..45eb9730e4 100644 --- a/ui/editor/package.json +++ b/ui/editor/package.json @@ -30,7 +30,7 @@ "watchify": "^1.0.2" }, "dependencies": { - "chessground": "1.8.2", + "chessground": "1.8.4", "lodash-node": "^2.4.1", "mithril": "0.1.27" } diff --git a/ui/lobby/package.json b/ui/lobby/package.json index 00a1afc468..ad8a89f516 100644 --- a/ui/lobby/package.json +++ b/ui/lobby/package.json @@ -30,7 +30,7 @@ "watchify": "^1.0.2" }, "dependencies": { - "chessground": "1.8.2", + "chessground": "1.8.4", "lodash-node": "^2.4.1", "mithril": "0.1.27" } diff --git a/ui/puzzle/package.json b/ui/puzzle/package.json index 23e5adef01..673685594e 100644 --- a/ui/puzzle/package.json +++ b/ui/puzzle/package.json @@ -30,7 +30,7 @@ "watchify": "^1.0.2" }, "dependencies": { - "chessground": "1.8.2", + "chessground": "1.8.4", "chessli.js": "file:../chessli", "lodash-node": "^2.4.1", "merge": "^1.2.0", diff --git a/ui/round/package.json b/ui/round/package.json index 67d357d5bc..725205e54b 100644 --- a/ui/round/package.json +++ b/ui/round/package.json @@ -30,7 +30,7 @@ "watchify": "^1.0.2" }, "dependencies": { - "chessground": "1.8.2", + "chessground": "1.8.4", "chessli.js": "file:../chessli", "game": "file:../game", "lodash-node": "^2.4.1", diff --git a/ui/round/src/atomic.js b/ui/round/src/atomic.js new file mode 100644 index 0000000000..0a4f88ffe5 --- /dev/null +++ b/ui/round/src/atomic.js @@ -0,0 +1,17 @@ +var util = require('chessground').util; + +function capture(ctrl, key) { + var ps = []; + var pos = util.key2pos(key); + for (var x = -1; x < 2; x++) { + for (var y = -1; y < 2; y++) { + var p = util.pos2key([pos[0] + x, pos[1] + y]); + if (p) ps.push(p); + } + } + ctrl.chessground.explode(ps); +}; + +module.exports = { + capture: capture +}; diff --git a/ui/round/src/ctrl.js b/ui/round/src/ctrl.js index 001de68713..7be5fe0332 100644 --- a/ui/round/src/ctrl.js +++ b/ui/round/src/ctrl.js @@ -16,6 +16,7 @@ var replayCtrl = require('./replay/ctrl'); var clockCtrl = require('./clock/ctrl'); var correspondenceClockCtrl = require('./correspondenceClock/ctrl'); var moveOn = require('./moveOn'); +var atomic = require('./atomic'); module.exports = function(opts) { @@ -51,12 +52,19 @@ module.exports = function(opts) { }); }.bind(this); - this.userMove = function(orig, dest, meta) { + var onUserMove = function(orig, dest, meta) { hold.register(this.socket, meta.holdTime); if (!promotion.start(this, orig, dest, meta.premove)) this.sendMove(orig, dest); $.sound.move(this.data.player.color == 'white'); }.bind(this); + var onCapture = function(key) { + if (this.data.game.variant.key === 'atomicChess') atomic.capture(this, key); + else $.sound.take(); + }.bind(this); + + this.chessground = ground.make(this.data, opts.data.game.fen, onUserMove, onCapture); + this.apiMove = function(o) { if (this.replay.active) this.replay.vm.late = true; else this.chessground.apiMove(o.from, o.to); @@ -69,8 +77,6 @@ module.exports = function(opts) { if (game.isPlayerPlaying(this.data) && o.color === this.data.player.color) this.moveOn.next(); }.bind(this); - this.chessground = ground.make(this.data, opts.data.game.fen, this.userMove); - this.reload = function(cfg) { this.replay.onReload(cfg); this.data = data(this.data, cfg); diff --git a/ui/round/src/ground.js b/ui/round/src/ground.js index 0eb1289bcd..73d76c86a3 100644 --- a/ui/round/src/ground.js +++ b/ui/round/src/ground.js @@ -39,18 +39,18 @@ function makeConfig(data, fen, flip) { }, draggable: { showGhost: data.pref.highlight - }, - events: { - capture: $.sound.take } }; } -function make(data, fen, userMove) { +function make(data, fen, userMove, onCapture) { var config = makeConfig(data, fen); config.movable.events = { after: userMove }; + config.events = { + capture: onCapture + }; config.viewOnly = data.player.spectator; return new chessground.controller(config); }