Skip to content

Instantly share code, notes, and snippets.

@farukuzun
Created September 30, 2020 18:58
Show Gist options
  • Save farukuzun/c8db325fabd4083c2f0fa34bd0a65884 to your computer and use it in GitHub Desktop.
Save farukuzun/c8db325fabd4083c2f0fa34bd0a65884 to your computer and use it in GitHub Desktop.
Lichess Round.Js
var LichessRound=function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e,t,o){return e(o={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&o.path)}},o.exports),o.exports}function r(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})})),t}var s=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});function o(e,t){var o,n=t.elm,r=e.data.attrs,s=t.data.attrs;if((r||s)&&r!==s){for(o in r=r||{},s=s||{}){var i=s[o];r[o]!==i&&(!0===i?n.setAttribute(o,""):!1===i?n.removeAttribute(o):120!==o.charCodeAt(0)?n.setAttribute(o,i):58===o.charCodeAt(3)?n.setAttributeNS("http://www.w3.org/XML/1998/namespace",o,i):58===o.charCodeAt(5)?n.setAttributeNS("http://www.w3.org/1999/xlink",o,i):n.setAttribute(o,i))}for(o in r)o in s||n.removeAttribute(o)}}t.attributesModule={create:o,update:o},t.default=t.attributesModule})),i=o(s),a=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.prop=t.notEmpty=t.isEmpty=t.notNull=t.defined=void 0,t.defined=e=>void 0!==e,t.notNull=e=>null!=e,t.isEmpty=e=>!e||0===e.length,t.notEmpty=e=>!t.isEmpty(e),t.prop=e=>{let o=e;return function(e){return t.defined(e)&&(o=e),o}}})),c=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.formToXhr=t.url=t.form=t.script=t.text=t.json=t.xhrHeader=t.defaultInit=void 0;const o={Accept:"application/vnd.lichess.v5+json"};t.defaultInit={cache:"no-cache",credentials:"same-origin"},t.xhrHeader={"X-Requested-With":"XMLHttpRequest"},t.json=(e,n={})=>fetch(e,Object.assign(Object.assign(Object.assign({},t.defaultInit),{headers:Object.assign(Object.assign({},o),t.xhrHeader)}),n)).then((e=>{if(e.ok)return e.json();throw e.statusText})),t.text=(e,o={})=>fetch(e,Object.assign(Object.assign(Object.assign({},t.defaultInit),{headers:Object.assign({},t.xhrHeader)}),o)).then((e=>{if(e.ok)return e.text();throw e.statusText})),t.script=e=>new Promise(((t,o)=>{const n=document.body.getAttribute("data-nonce"),r=document.createElement("script");n&&r.setAttribute("nonce",n),r.onload=t,r.onerror=o,r.src=e,document.head.append(r)})),t.form=e=>{const t=new FormData;for(const o of Object.keys(e))t.append(o,e[o]);return t},t.url=(e,t)=>{const o=new URLSearchParams;for(const r of Object.keys(t))a.defined(t[r])&&o.append(r,t[r]);const n=o.toString();return n?`${e}?${n}`:e},t.formToXhr=e=>t.text(e.action,{method:e.method,body:new FormData(e)})}));function l(e,t,o,n,r){return{sel:e,data:t,children:o,text:n,elm:r,key:void 0===t?void 0:t.key}}var d=Array.isArray;function u(e){return"string"==typeof e||"number"==typeof e}var h={createElement:function(e){return document.createElement(e)},createElementNS:function(e,t){return document.createElementNS(e,t)},createTextNode:function(e){return document.createTextNode(e)},createComment:function(e){return document.createComment(e)},insertBefore:function(e,t,o){e.insertBefore(t,o)},removeChild:function(e,t){e.removeChild(t)},appendChild:function(e,t){e.appendChild(t)},parentNode:function(e){return e.parentNode},nextSibling:function(e){return e.nextSibling},tagName:function(e){return e.tagName},setTextContent:function(e,t){e.textContent=t},getTextContent:function(e){return e.textContent},isElement:function(e){return 1===e.nodeType},isText:function(e){return 3===e.nodeType},isComment:function(e){return 8===e.nodeType}};function p(e,t,o){if(e.ns="http://www.w3.org/2000/svg","foreignObject"!==o&&void 0!==t)for(var n=0;n<t.length;++n){var r=t[n].data;void 0!==r&&p(r,t[n].children,t[n].sel)}}function f(e,t,o){var n,r,s,i={};if(void 0!==o?(i=t,d(o)?n=o:u(o)?r=o:o&&o.sel&&(n=[o])):void 0!==t&&(d(t)?n=t:u(t)?r=t:t&&t.sel?n=[t]:i=t),void 0!==n)for(s=0;s<n.length;++s)u(n[s])&&(n[s]=l(void 0,void 0,void 0,n[s],void 0));return"s"!==e[0]||"v"!==e[1]||"g"!==e[2]||3!==e.length&&"."!==e[3]&&"#"!==e[3]||p(i,n,e),l(e,i,n,r,void 0)}function m(e,t){t.elm=e.elm,e.data.fn=t.data.fn,e.data.args=t.data.args,t.data=e.data,t.children=e.children,t.text=e.text,t.elm=e.elm}function g(e){var t=e.data;m(t.fn.apply(void 0,t.args),e)}function v(e,t){var o,n=e.data,r=t.data,s=n.args,i=r.args;if(n.fn===r.fn&&s.length===i.length){for(o=0;o<i.length;++o)if(s[o]!==i[o])return void m(r.fn.apply(void 0,i),t);m(e,t)}else m(r.fn.apply(void 0,i),t)}function b(e){return void 0===e}function y(e){return void 0!==e}var w=l("",{},[],void 0,void 0);function k(e,t){return e.key===t.key&&e.sel===t.sel}function P(e,t,o){var n,r,s,i={};for(n=t;n<=o;++n)null!=(s=e[n])&&void 0!==(r=s.key)&&(i[r]=n);return i}var M=["create","update","remove","destroy","pre","post"];function T(e,t){var o,n,r={},s=void 0!==t?t:h;for(o=0;o<M.length;++o)for(r[M[o]]=[],n=0;n<e.length;++n){var i=e[n][M[o]];void 0!==i&&r[M[o]].push(i)}function a(e){var t=e.id?"#"+e.id:"",o=e.className?"."+e.className.split(" ").join("."):"";return l(s.tagName(e).toLowerCase()+t+o,{},[],void 0,e)}function c(e,t){return function(){if(0==--t){var o=s.parentNode(e);s.removeChild(o,e)}}}function p(e,t){var o,n=e.data;void 0!==n&&y(o=n.hook)&&y(o=o.init)&&(o(e),n=e.data);var i=e.children,a=e.sel;if("!"===a)b(e.text)&&(e.text=""),e.elm=s.createComment(e.text);else if(void 0!==a){var c=a.indexOf("#"),l=a.indexOf(".",c),h=c>0?c:a.length,f=l>0?l:a.length,m=-1!==c||-1!==l?a.slice(0,Math.min(h,f)):a,g=e.elm=y(n)&&y(o=n.ns)?s.createElementNS(o,m):s.createElement(m);for(h<f&&g.setAttribute("id",a.slice(h+1,f)),l>0&&g.setAttribute("class",a.slice(f+1).replace(/\./g," ")),o=0;o<r.create.length;++o)r.create[o](w,e);if(d(i))for(o=0;o<i.length;++o){var v=i[o];null!=v&&s.appendChild(g,p(v,t))}else u(e.text)&&s.appendChild(g,s.createTextNode(e.text));y(o=e.data.hook)&&(o.create&&o.create(w,e),o.insert&&t.push(e))}else e.elm=s.createTextNode(e.text);return e.elm}function f(e,t,o,n,r,i){for(;n<=r;++n){var a=o[n];null!=a&&s.insertBefore(e,p(a,i),t)}}function m(e){var t,o,n=e.data;if(void 0!==n){for(y(t=n.hook)&&y(t=t.destroy)&&t(e),t=0;t<r.destroy.length;++t)r.destroy[t](e);if(void 0!==e.children)for(o=0;o<e.children.length;++o)null!=(t=e.children[o])&&"string"!=typeof t&&m(t)}}function g(e,t,o,n){for(;o<=n;++o){var i=void 0,a=void 0,l=void 0,d=t[o];if(null!=d)if(y(d.sel)){for(m(d),a=r.remove.length+1,l=c(d.elm,a),i=0;i<r.remove.length;++i)r.remove[i](d,l);y(i=d.data)&&y(i=i.hook)&&y(i=i.remove)?i(d,l):l()}else s.removeChild(e,d.elm)}}function v(e,t,o){var n,i;y(n=t.data)&&y(i=n.hook)&&y(n=i.prepatch)&&n(e,t);var a=t.elm=e.elm,c=e.children,l=t.children;if(e!==t){if(void 0!==t.data){for(n=0;n<r.update.length;++n)r.update[n](e,t);y(n=t.data.hook)&&y(n=n.update)&&n(e,t)}b(t.text)?y(c)&&y(l)?c!==l&&function(e,t,o,n){for(var r,i,a,c=0,l=0,d=t.length-1,u=t[0],h=t[d],m=o.length-1,y=o[0],w=o[m];c<=d&&l<=m;)null==u?u=t[++c]:null==h?h=t[--d]:null==y?y=o[++l]:null==w?w=o[--m]:k(u,y)?(v(u,y,n),u=t[++c],y=o[++l]):k(h,w)?(v(h,w,n),h=t[--d],w=o[--m]):k(u,w)?(v(u,w,n),s.insertBefore(e,u.elm,s.nextSibling(h.elm)),u=t[++c],w=o[--m]):k(h,y)?(v(h,y,n),s.insertBefore(e,h.elm,u.elm),h=t[--d],y=o[++l]):(void 0===r&&(r=P(t,c,d)),b(i=r[y.key])?(s.insertBefore(e,p(y,n),u.elm),y=o[++l]):((a=t[i]).sel!==y.sel?s.insertBefore(e,p(y,n),u.elm):(v(a,y,n),t[i]=void 0,s.insertBefore(e,a.elm,u.elm)),y=o[++l]));(c<=d||l<=m)&&(c>d?f(e,null==o[m+1]?null:o[m+1].elm,o,l,m,n):g(e,t,c,d))}(a,c,l,o):y(l)?(y(e.text)&&s.setTextContent(a,""),f(a,null,l,0,l.length-1,o)):y(c)?g(a,c,0,c.length-1):y(e.text)&&s.setTextContent(a,""):e.text!==t.text&&(y(c)&&g(a,c,0,c.length-1),s.setTextContent(a,t.text)),y(i)&&y(n=i.postpatch)&&n(e,t)}}return function(e,t){var o,n,i,c=[];for(o=0;o<r.pre.length;++o)r.pre[o]();for(function(e){return void 0!==e.sel}(e)||(e=a(e)),k(e,t)?v(e,t,c):(n=e.elm,i=s.parentNode(n),p(t,c),null!==i&&(s.insertBefore(i,t.elm,s.nextSibling(n)),g(i,[e],0,0))),o=0;o<c.length;++o)c[o].data.hook.insert(c[o]);for(o=0;o<r.post.length;++o)r.post[o]();return t}}var C=Object.freeze({__proto__:null,init:T,h:f,thunk:function(e,t,o,n){return void 0===n&&(n=o,o=t,t=void 0),f(e,{key:t,hook:{init:g,prepatch:v},fn:o,args:n})}}),x=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.ranks=t.files=t.colors=void 0,t.colors=["white","black"],t.files=["a","b","c","d","e","f","g","h"],t.ranks=["1","2","3","4","5","6","7","8"]})),S=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.computeSquareCenter=t.createEl=t.isRightButton=t.eventPosition=t.setVisible=t.translateRel=t.translateAbs=t.posToTranslateRel=t.posToTranslateAbs=t.samePiece=t.distanceSq=t.opposite=t.timer=t.memo=t.allPos=t.key2pos=t.pos2key=t.allKeys=t.invRanks=void 0,t.invRanks=[...x.ranks].reverse(),t.allKeys=Array.prototype.concat(...x.files.map((e=>x.ranks.map((t=>e+t))))),t.pos2key=e=>t.allKeys[8*e[0]+e[1]],t.key2pos=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49],t.allPos=t.allKeys.map(t.key2pos),t.memo=function(e){let t;const o=()=>(void 0===t&&(t=e()),t);return o.clear=()=>{t=void 0},o},t.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}}},t.opposite=e=>"white"===e?"black":"white",t.distanceSq=(e,t)=>{const o=e[0]-t[0],n=e[1]-t[1];return o*o+n*n},t.samePiece=(e,t)=>e.role===t.role&&e.color===t.color;const o=(e,t,o,n)=>[(t?e[0]:7-e[0])*o,(t?7-e[1]:e[1])*n];t.posToTranslateAbs=e=>{const t=e.width/8,n=e.height/8;return(e,r)=>o(e,r,t,n)},t.posToTranslateRel=(e,t)=>o(e,t,100,100),t.translateAbs=(e,t)=>{e.style.transform=`translate(${t[0]}px,${t[1]}px)`},t.translateRel=(e,t)=>{e.style.transform=`translate(${t[0]}%,${t[1]}%)`},t.setVisible=(e,t)=>{e.style.visibility=t?"visible":"hidden"},t.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},t.isRightButton=e=>2===e.buttons||2===e.button,t.createEl=(e,t)=>{const o=document.createElement(e);return t&&(o.className=t),o},t.computeSquareCenter=function(e,o,n){const r=t.key2pos(e);return o||(r[0]=7-r[0],r[1]=7-r[1]),[n.left+n.width*r[0]/8+n.width/16,n.top+n.height*(7-r[1])/8+n.height/16]}}));const O={pawn:1,knight:3,bishop:3,rook:5,queen:9,king:0};function _(e){return{attrs:{"data-icon":e}}}function j(e){if(e)return"@"===e[1]?[e.slice(2,4)]:[e.slice(0,2),e.slice(2,4)]}function A(e){return{insert(t){e(t.elm)}}}function L(e,t,o,n=!0){return A((r=>{r.addEventListener(e,o?e=>{const n=t(e);return o(),n}:t,{passive:n})}))}function D(e){const t=new Map;if(!e)return t;if("string"==typeof e)for(const o of e.split(" "))t.set(o.slice(0,2),o.slice(2).match(/.{2}/g));else for(const o in e)t.set(o,e[o].match(/.{2}/g));return t}const E={white:0,black:0};var N=n((function(e,t){function o(e,t){var o,n,r=t.elm,s=e.data.class,i=t.data.class;if((s||i)&&s!==i){for(n in i=i||{},s=s||{})i[n]||r.classList.remove(n);for(n in i)(o=i[n])!==s[n]&&r.classList[o?"add":"remove"](n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.classModule={create:o,update:o},t.default=t.classModule})),B=o(N),R=r(C),I=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.bind=t.userLink=void 0,t.userLink=function(e,t){const o=e.substring(0,14);return R.h("a",{class:{"user-link":!0,ulpt:!0},attrs:{href:"/@/"+e}},t&&"BOT"!=t?[R.h("span.utitle",t),o]:[o])},t.bind=function(e,t){return{insert(o){o.elm.addEventListener(e,t)}}}})),q=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.presetView=t.presetCtrl=void 0;const o={start:["hi/Hello","gl/Good luck","hf/Have fun!","u2/You too!"].map(n),end:["gg/Good game","wp/Well played","ty/Thank you","gtg/I've got to go","bye/Bye!"].map(n)};function n(e){const t=e.split("/");return{key:t[0],text:t[1]}}t.presetCtrl=function(e){let t=e.initialGroup,n=[];return{group:()=>t,said:()=>n,setGroup(o){o!==t&&(t=o,o||(n=[]),e.redraw())},post(r){if(!t)return;o[t]&&(n.includes(r.key)||e.post(r.text)&&n.push(r.key))}}},t.presetView=function(e){const t=e.group();if(!t)return;const n=o[t],r=e.said();return n&&r.length<2?R.h("div.mchat__presets",n.map((t=>{const o=r.includes(t.key);return R.h("span",{class:{disabled:o},attrs:{title:t.text,disabled:o},hook:I.bind("click",(()=>{!o&&e.post(t)}))},t.key)}))):void 0}})),z=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.setNote=t.getNote=t.flag=t.userModInfo=void 0,t.userModInfo=e=>c.json("/mod/chat-user/"+e),t.flag=(e,t,o)=>c.json("/report/flag",{method:"post",body:c.form({username:t,resource:e,text:o})}),t.getNote=e=>c.text(o(e)),t.setNote=(e,t)=>c.json(o(e),{method:"post",body:c.form({text:t})});const o=e=>`/${e}/note`})),H=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,o=!1){let n,r=0;return function(){let s=this,i=arguments,a=performance.now()-r;r=performance.now();let c=()=>{n=void 0,e.apply(s,i)};clearTimeout(n),o&&a>t?e.apply(s,i):n=setTimeout(c,t)}}})),K=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.noteView=t.noteCtrl=void 0,t.noteCtrl=function(e){let t=e.text;const o=H.default((()=>{z.setNote(e.id,t||"")}),1e3);return{id:e.id,trans:e.trans,text:()=>t,fetch(){z.getNote(e.id).then((o=>{t=o||"",e.redraw()}))},post(e){t=e,o()}}},t.noteView=function(e){const t=e.text();return null==t?R.h("div.loading",{hook:{insert:e.fetch}}):R.h("textarea",{attrs:{placeholder:e.trans("typePrivateNotesHere")},hook:{insert(o){const n=$(o.elm);n.val(t).on("change keyup paste",(()=>e.post(n.val())))}}})}})),F=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.numberFormat=void 0;let o=!1;t.numberFormat=e=>(!1===o&&(o=window.Intl&&Intl.NumberFormat?new Intl.NumberFormat:null),null===o?""+e:o.format(e))})),G=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.moderationView=t.lineAction=t.moderationCtrl=void 0,t.moderationCtrl=function(e){let t,o=!1;const n=()=>{t=void 0,o=!1,e.redraw()};return{loading:()=>o,data:()=>t,reasons:e.reasons,permissions:()=>e.permissions,open:n=>{const r=n.querySelector("a.user-link"),s=n.querySelector("t").innerText,i=r.href.split("/")[4];e.permissions.timeout?(o=!0,z.userModInfo(i).then((n=>{t=Object.assign(Object.assign({},n),{text:s}),o=!1,e.redraw()}))):t={id:i,username:i,text:s},e.redraw()},close:n,timeout(o,r){t&&lichess.pubsub.emit("socket.send","timeout",{userId:t.id,reason:o.key,text:r}),n(),e.redraw()}}},t.lineAction=()=>R.h("i.mod",{attrs:{"data-icon":""}}),t.moderationView=function(e){if(!e)return;if(e.loading())return[R.h("div.loading")];const t=e.data();if(!t)return;const o=e.permissions(),n=t.history?R.h("div.infos.block",[F.numberFormat(t.games||0)+" games",t.troll?"TROLL":void 0,t.engine?"ENGINE":void 0,t.booster?"BOOSTER":void 0].map((e=>e&&R.h("span",e))).concat([R.h("a",{attrs:{href:"/@/"+t.username+"?mod"}},"profile")]).concat(o.shadowban?[R.h("a",{attrs:{href:"/mod/"+t.username+"/communication"}},"coms")]:[])):void 0,r=o.timeout?R.h("div.timeout.block",[R.h("strong","Timeout 10 minutes for"),...e.reasons.map((o=>R.h("a.text",{attrs:{"data-icon":"p"},hook:I.bind("click",(()=>e.timeout(o,t.text)))},o.name)))]):R.h("div.timeout.block",[R.h("strong","Moderation"),R.h("a.text",{attrs:{"data-icon":"p"},hook:I.bind("click",(()=>e.timeout(e.reasons[0],t.text)))},"Timeout 10 minutes")]),s=t.history?R.h("div.history.block",[R.h("strong","Timeout history"),R.h("table",R.h("tbody.slist",{hook:{insert(){lichess.contentLoaded()}}},t.history.map((function(e){return R.h("tr",[R.h("td.reason",e.reason),R.h("td.mod",e.mod),R.h("td",R.h("time.timeago",{attrs:{datetime:e.date}}))])}))))]):void 0;return[R.h("div.top",{key:"mod-"+t.id},[R.h("span.text",{attrs:{"data-icon":""}},[I.userLink(t.username)]),R.h("a",{attrs:{"data-icon":"L"},hook:I.bind("click",e.close)})]),R.h("div.mchat__content.moderation",[R.h("i.line-text.block",['"',t.text,'"']),n,r,s])]}})),U=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){const o=e.data;o.domVersion=1;const n={instance:void 0,loaded:!1,enabled:a.prop(!!o.palantir)},r=["discussion"];e.noteId&&r.push("note"),e.plugin&&r.push(e.plugin.tab.key);const s=lichess.storage.make("chat.tab"),i=s.get();let c;const l={tab:r.find((e=>e===i))||r[0],enabled:e.alwaysEnabled||!lichess.storage.get("nochat"),placeholderKey:"talkInChat",loading:!1,timeout:e.timeout,writeable:e.writeable};r.length>1&&"discussion"===l.tab&&lichess.storage.get("nochat")&&(l.tab=r[1]);const d=function(e){return!!(e=e.trim())&&(!("You too!"==e&&!o.lines.some((e=>e.u!=o.userId)))&&(e.length>140?(alert("Max length: 140 chars. "+e.length+" chars used."),!1):(lichess.pubsub.emit("socket.send","talk",e),!0)))},u=lichess.trans(e.i18n);function h(){(e.permissions.timeout||e.permissions.local)&&(c=G.moderationCtrl({reasons:e.timeoutReasons||[{key:"other",name:"Inappropriate behavior"}],permissions:e.permissions,redraw:t}),e.loadCss("chat.mod"))}h();const p=e.noteId?K.noteCtrl({id:e.noteId,text:e.noteText,trans:u,redraw:t}):void 0,f=q.presetCtrl({initialGroup:e.preset,post:d,redraw:t}),m=[["socket.in.message",function(e){o.lines.push(e);const n=o.lines.length;n>200&&(o.lines.splice(0,n-200+50),o.domVersion++),t()}],["socket.in.chat_timeout",function(e){o.lines.forEach((t=>{t.u&&t.u.toLowerCase()==e&&(t.d=!0)})),e==o.userId&&(l.timeout=!0),o.domVersion++,t()}],["socket.in.chat_reinstate",function(e){e==o.userId&&(l.timeout=!1,t())}],["chat.writeable",function(e){l.writeable=e,t()}],["chat.permissions",function(o){let n;for(n in o)e.permissions[n]=o[n];h(),t()}],["palantir.toggle",n.enabled]];m.forEach((([e,t])=>lichess.pubsub.on(e,t)));const g=()=>lichess.pubsub.emit("chat.enabled",l.enabled);return g(),{data:o,opts:e,vm:l,allTabs:r,setTab(e){l.tab=e,s.set(e),"discussion"===e&&lichess.requestIdleCallback((()=>$(".mchat__say").each((function(){this.focus()})))),t()},moderation:()=>c,note:p,preset:f,post:d,trans:u,plugin:e.plugin,setEnabled(e){l.enabled=e,g(),e?lichess.storage.remove("nochat"):lichess.storage.set("nochat","1"),t()},redraw:t,palantir:n,destroy:()=>{m.forEach((([e,t])=>lichess.pubsub.off(e,t)))}}}})),W=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isMoreThanText=t.enhance=void 0,t.enhance=function(e,t){const o=lichess.escapeHtml(e),n=o.replace(i,c).replace(r,s);return t&&n===o?function(e){return e.replace(l,d)}(n):n};const o=/[&<>"@]/,n=/\.\w/;t.isMoreThanText=function(e){return o.test(e)||n.test(e)};const r=/\b\b(?:https?:\/\/)?(lichess\.org\/[-–—\w+&'@#\/%?=()~|!:,.;]+[\w+&@#\/%=~|])/gi;function s(e,t){return t.includes("&quot;")?t:`<a target="_blank" rel="nofollow noopener noreferrer" href="https://${t}">${t}</a>`}const i=/(^|[^\w@#/])@([\w-]{2,})/g,a=/^[a-h][2-7]$/;function c(e,t,o){return o.length>20||o.match(a)?e:t+'<a href="/@/'+o+'">@'+o+"</a>"}const l=/\b(\d+)\s*(\.+)\s*(?:[o0-]+[o0]|[NBRQKP]?[a-h]?[1-8]?[x@]?[a-z][1-8](?:=[NBRQK])?)\+?\#?[!\?=]{0,5}/gi;function d(e,t,o){if(t<1||t>200)return e;return'<a class="jump" data-ply="'+(2*t-(o.length>1?0:1))+'">'+e+"</a>"}})),V=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.hasTeamUrl=t.selfReport=t.skip=void 0,t.skip=e=>(r(e)||s(e))&&!o(),t.selfReport=e=>{if(o())return;const t=r(e);t&&c.text(`/jslog/${window.location.href.substr(-12)}?n=spam`,{method:"post"}),(t||s(e))&&lichess.storage.set("chat-spam","1")};const o=()=>"1"==lichess.storage.get("chat-spam"),n=new RegExp(["xcamweb.com","(^|[^i])chess-bot","chess-cheat","coolteenbitch","letcafa.webcam","tinyurl.com/","wooga.info/","bit.ly/","wbt.link/","eb.by/","001.rs/","shr.name/","u.to/",".3-a.net",".ssl443.org",".ns02.us",".myftp.info",".flinkup.com",".serveusers.com","badoogirls.com","hide.su","wyon.de","sexdatingcz.club"].map((e=>e.replace(/\./g,"\\.").replace(/\//g,"\\/"))).join("|")),r=e=>!!e.match(n),s=e=>e.toLowerCase().includes("follow me"),i=/lichess\.org\/team\//i;t.hasTeamUrl=e=>!!e.match(i)})),Y=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});const o=/^\/[wW](?:hisper)?\s/;function n(e){if(!e.vm.writeable)return;if(e.data.loginRequired&&!e.data.userId||e.data.restricted)return R.h("input.mchat__say",{attrs:{placeholder:e.trans("loginToChat"),disabled:!0}});let t;return t=e.vm.timeout?e.trans("youHaveBeenTimedOut"):e.opts.blind?"Chat":e.trans.noarg(e.vm.placeholderKey),R.h("input.mchat__say",{attrs:{placeholder:t,autocomplete:"off",maxlength:140,disabled:e.vm.timeout||!e.vm.writeable,"aria-label":"Chat input"},hook:{insert(t){s(e,t.elm)}}})}let r;t.default=function(e){if(!e.vm.enabled)return[];const t=t=>{const o=t.elm;if(e.data.lines.length>5){(0===o.scrollTop||o.scrollTop>o.scrollHeight-o.clientHeight-100)&&(o.scrollTop=999999,setTimeout((e=>o.scrollTop=999999),300))}},o=e.moderation(),r=[R.h("ol.mchat__messages.chat-v-"+e.data.domVersion,{attrs:{role:"log","aria-live":"polite","aria-atomic":!1},hook:{insert(n){const r=$(n.elm).on("click","a.jump",(e=>{lichess.pubsub.emit("jump",e.target.getAttribute("data-ply"))}));o?r.on("click",".mod",(e=>o.open(e.target.parentNode))):r.on("click",".flag",(t=>function(e,t){const o=t.querySelector("a.user-link"),n=t.querySelector("t").innerText;o&&confirm(`Report "${n}" to moderators?`)&&z.flag(e.data.resourceId,o.href.split("/")[4],n)}(e,t.target.parentNode))),t(n)},postpatch:(e,o)=>t(o)}},i(e).map((t=>function(e,t){const o=function(e,t){if(W.isMoreThanText(e)){const o=function(e){return(t,o)=>{o.data.lichessChat!==t.data.lichessChat&&(o.elm.innerHTML=W.enhance(o.data.lichessChat,e))}}(t);return R.h("t",{lichessChat:e,hook:{create:o,update:o}})}return R.h("t",e)}(t.t,e.opts.parseMoves);if("lichess"===t.u)return R.h("li.system",o);if(t.c)return R.h("li",[R.h("span.color","["+t.c+"]"),o]);const n=R.thunk("a",t.u,I.userLink,[t.u,t.title]);return R.h("li",e.moderation()?[t.u?G.lineAction():null,n," ",o]:[e.data.userId&&t.u&&e.data.userId!=t.u?R.h("i.flag",{attrs:{"data-icon":"!",title:"Report"}}):null,n," ",o])}(e,t)))),n(e)],s=q.presetView(e.preset);return s&&r.push(s),r};const s=(e,t)=>{const n=lichess.tempStorage.make("chatInput");n.get()&&(t.value=n.get(),n.remove(),t.focus()),t.addEventListener("keypress",(t=>setTimeout((()=>{const r=t.target,s=r.value,i=e.opts.public;n.set(r.value),10==t.which||13==t.which?""===s?$(".keyboard-move input").each((function(){this.focus()})):(e.opts.kobold||V.selfReport(s),i&&V.hasTeamUrl(s)?alert("Please don't advertise teams in the chat."):e.post(s),r.value="",n.remove(),i||r.classList.remove("whisper")):(r.removeAttribute("placeholder"),i||r.classList.toggle("whisper",!!s.match(o)))})))),window.Mousetrap.bind("c",(()=>t.focus()));const s=["touchstart","mousedown"];r&&s.forEach((e=>document.body.removeEventListener(e,r,{capture:!0}))),r=e=>{e.shiftKey||2===e.buttons||2===e.button||t.blur()},t.onfocus=()=>s.forEach((e=>document.body.addEventListener(e,r,{passive:!0,capture:!0}))),t.onblur=()=>s.forEach((e=>document.body.removeEventListener(e,r,{capture:!0})))};function i(e){let t,o=[];return e.data.lines.forEach((n=>{var r,s;n.d||t&&(s=n,(r=t).d&&s.d&&r.u===s.u)||n.r&&(n.u||"").toLowerCase()!=e.data.userId||V.skip(n.t)||o.push(n),t=n})),o}})),X=n((function(e,t){function o(e){const t=e.palantir;if(t.enabled())return t.instance?t.instance.render(R.h):R.h("div.mchat__tab.palantir.palantir-slot",{attrs:{"data-icon":"",title:"Voice chat"},hook:I.bind("click",(()=>{t.loaded||(t.loaded=!0,lichess.loadScript("javascripts/vendor/peerjs.min.js").then((()=>{lichess.loadModule("palantir").then((()=>{t.instance=window.Palantir.palantir({uid:e.data.userId,redraw:e.redraw}),e.redraw()}))})))}))})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=e.moderation();return R.h("section.mchat"+(e.opts.alwaysEnabled?"":".mchat-optional"),{class:{"mchat-mod":!!t},hook:{destroy:e.destroy}},G.moderationView(t)||function(e){const t=e.vm.tab;return[R.h("div.mchat__tabs.nb_"+e.allTabs.length,[...e.allTabs.map((o=>function(e,t,o){return R.h("div.mchat__tab."+t,{class:{"mchat__tab-active":t===o},hook:I.bind("click",(()=>e.setTab(t)))},function(e,t){return"discussion"===t?[R.h("span",e.data.name),e.opts.alwaysEnabled?void 0:R.h("input",{attrs:{type:"checkbox",title:e.trans.noarg("toggleTheChat"),checked:e.vm.enabled},hook:I.bind("change",(t=>{e.setEnabled(t.target.checked)}))})]:"note"===t?[R.h("span",e.trans.noarg("notes"))]:e.plugin&&t===e.plugin.tab.key?[R.h("span",e.plugin.tab.name)]:[]}(e,t))}(e,o,t))),o(e)]),R.h("div.mchat__content."+t,"note"===t&&e.note?[K.noteView(e.note)]:e.plugin&&t===e.plugin.tab.key?[e.plugin.view()]:Y.default(e))]}(e))}})),J=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){const o=R.init([N.default,s.default]);let n,r;r=U.default(t,(function(){n=o(n,X.default(r))}));const i=X.default(r);return e.innerHTML="",n=o(e,i),r}}))),Q=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){if("ontouchstart"in window)return;let e,t;const o=o=>{e=o.pageX,t=o.pageY};let n={};$("#topnav.hover").each((function(){const r=$(this).removeClass("hover"),s=()=>r.toggleClass("hover"),i=()=>{Math.sqrt((n.pX-e)*(n.pX-e)+(n.pY-t)*(n.pY-t))<10?(r.off(n.event,o),delete n.timeoutId,n.isActive=!0,s()):(n.pX=e,n.pY=t,n.timeoutId=setTimeout(i,100))},a=function(e){n.timeoutId&&(n.timeoutId=clearTimeout(n.timeoutId));const t=n.event="mousemove";if("mouseover"==e.type){if(n.isActive||e.buttons)return;n.pX=e.pageX,n.pY=e.pageY,r.off(t,o).on(t,o),n.timeoutId=setTimeout(i,100)}else{if(!n.isActive)return;r.off(t,o),n={},s()}};r.on("mouseover",a).on("mouseleave",a)}))}})));const Z=(()=>{const e="mousemove";let t=!1,o=[],n=0;function r(e){var t;o.push({b:0!=e.buttons,x:e.clientX,y:e.clientY}),o.length>4&&(o.shift(),!(t=o)[0].b&&t[1].b&&t[2].b&&!t[3].b&&s(t[0],t[1])>900&&0===s(t[1],t[2])&&0===s(t[2],t[3])&&n++)}function s(e,t){return Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)}return{start(){t||(t=!1,document.addEventListener(e,r))},stop(){t&&(t=!1,document.removeEventListener(e,r))},hits:()=>n}})();let ee=[],te=!1,oe={holdAcc:0},ne=!1;const re=(e,t)=>fetch("/jslog/"+e.game.id+e.player.id+"?n="+t,{method:"post"}),se=10+Math.round(Math.random(11));var ie=(e,t)=>{!function(e,t){if(t.premove&&e.ply>1&&(ne=!0),ne||!t.holdTime||e.ply>30)return void Z.stop();if(ee.push(t.holdTime),ee.length<=6)return;let o=!1;ee.shift();const n=ee.reduce(((e,t)=>e+t))/6;n>2&&n<140&&(o=ee.map((e=>Math.pow(e-n,2))).reduce(((e,t)=>e+t))/5<256);(o||te)&&$(".manipulable .cg-board").toggleClass("bh1",o&&Z.hits()>2),o?(oe.hold||(oe.holdAcc++,oe.holdAcc>5&&(e.socket.send("hold",{mean:Math.round(n),sd:Math.round(Math.sqrt(variance))}),oe.hold=!0)),Z.start(),Z.hits()>2&&!oe.ick&&(e.socket.send("bye2"),re(e.data,"ick2"),oe.ick=!0)):oe.holdAcc=0,te=o}(e,t),e.ply<=se+2&&e.ply>se&&(($(atob("TWVudUFwcGVuZA==")).length||$(atob("LmNnLWJvYXJkIGNhbnZhcw==")).length)&&re(e.data,"mcb"),$(atob("I2NoZXNzX2J0bl9jb250YWluZXI")).length&&re(e.data,"cma"))},ae=e=>{Object.keys(window.WebSocket).length||re(e.data,"ih1")};function ce(e){return e.steps[0].ply}function le(e){return de(e).ply}function de(e){return e.steps[e.steps.length-1]}function ue(e,t){return e.steps[t-ce(e)]}function he(e){e.clock&&(e.clock.showTenths=e.pref.clockTenths,e.clock.showBar=e.pref.clockBar),e.correspondence&&(e.correspondence.showBar=e.pref.clockBar),["horde","crazyhouse"].includes(e.game.variant.key)&&(e.pref.showCaptured=!1),e.expiration&&(e.expiration.movedAt=Date.now()-e.expiration.idleMillis)}var pe=n((function(e,t){function o(e){return e.game.status.id>=t.ids.started}function n(e){return e.game.status.id>=t.ids.mate}function r(e){return e.game.status.id===t.ids.aborted}Object.defineProperty(t,"__esModule",{value:!0}),t.playing=t.aborted=t.finished=t.started=t.ids=void 0,t.ids={created:10,started:20,aborted:25,mate:30,resign:31,stalemate:32,timeout:33,draw:34,outoftime:35,cheat:36,noStart:37,variantEnd:60},t.started=o,t.finished=n,t.aborted=r,t.playing=function(e){return o(e)&&!n(e)&&!r(e)}})),fe=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0})})),me=n((function(e,o){var n=t&&t.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[o]}})}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),r=t&&t.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(o,"__esModule",{value:!0}),o.isSwitchable=o.nbMoves=o.setGone=o.setOnGame=o.isCorrespondence=o.userAnalysable=o.hasAi=o.getPlayer=o.replayable=o.moretimeable=o.berserkableBy=o.resignable=o.drawable=o.takebackable=o.abortable=o.bothPlayersHavePlayed=o.playedTurns=o.mandatory=o.isPlayerTurn=o.isPlayerPlaying=o.playable=void 0,r(fe,o),o.playable=e=>e.game.status.id<pe.ids.aborted&&!s(e),o.isPlayerPlaying=e=>o.playable(e)&&!e.player.spectator,o.isPlayerTurn=e=>o.isPlayerPlaying(e)&&e.game.player==e.player.color,o.mandatory=e=>!!e.tournament||!!e.simul||!!e.swiss,o.playedTurns=e=>e.game.turns-(e.game.startedAtTurn||0),o.bothPlayersHavePlayed=e=>o.playedTurns(e)>1,o.abortable=e=>o.playable(e)&&!o.bothPlayersHavePlayed(e)&&!o.mandatory(e),o.takebackable=e=>o.playable(e)&&e.takebackable&&o.bothPlayersHavePlayed(e)&&!e.player.proposingTakeback&&!e.opponent.proposingTakeback,o.drawable=e=>o.playable(e)&&e.game.turns>=2&&!e.player.offeringDraw&&!o.hasAi(e),o.resignable=e=>o.playable(e)&&!o.abortable(e),o.berserkableBy=e=>!!e.tournament&&e.tournament.berserkable&&o.isPlayerPlaying(e)&&!o.bothPlayersHavePlayed(e),o.moretimeable=e=>o.isPlayerPlaying(e)&&e.moretimeable&&(!!e.clock||!!e.correspondence&&e.correspondence[e.opponent.color]<e.correspondence.increment-3600);const s=e=>"import"===e.game.source;function i(e,t){return e.player.color===t?e.player:e.opponent.color===t?e.opponent:null}o.replayable=e=>s(e)||pe.finished(e)||pe.aborted(e)&&o.bothPlayersHavePlayed(e),o.getPlayer=i,o.hasAi=e=>!(!e.player.ai&&!e.opponent.ai),o.userAnalysable=e=>pe.finished(e)||o.playable(e)&&(!e.clock||!o.isPlayerPlaying(e)),o.isCorrespondence=e=>"correspondence"===e.game.speed,o.setOnGame=(e,t,n)=>{const r=i(e,t);n=n||!!r.ai,r.onGame=n,n&&o.setGone(e,t,!1)},o.setGone=(e,t,o)=>{const n=i(e,t);n.gone=!n.ai&&o,!1===n.gone&&n.user&&(n.user.online=!0)},o.nbMoves=(e,t)=>Math.floor((e.game.turns+("white"==t?1:0))/2),o.isSwitchable=e=>!o.hasAi(e)&&(!!e.simul||o.isCorrespondence(e))})),ge=n((function(e,t){function o(e,t){return Math.abs(e-t)}Object.defineProperty(t,"__esModule",{value:!0}),t.premove=t.queen=t.knight=void 0,t.knight=(e,t,n,r)=>{const s=o(e,n),i=o(t,r);return 1===s&&2===i||2===s&&1===i};const n=(e,t,n,r)=>o(e,n)===o(t,r),r=(e,t,o,n)=>e===o||t===n;t.queen=(e,t,o,s)=>n(e,t,o,s)||r(e,t,o,s),t.premove=function(e,s,i){const a=e.get(s);if(!a)return[];const c=S.key2pos(s),l=a.role,d="pawn"===l?(u=a.color,(e,t,n,r)=>o(e,n)<2&&("white"===u?r===t+1||t<=1&&r===t+2&&e===n:r===t-1||t>=6&&r===t-2&&e===n)):"knight"===l?t.knight:"bishop"===l?n:"rook"===l?r:"queen"===l?t.queen:function(e,t,n){return(r,s,i,a)=>o(r,i)<2&&o(s,a)<2||n&&s===a&&s===("white"===e?0:7)&&(4===r&&(2===i&&t.includes(0)||6===i&&t.includes(7))||t.includes(i))}(a.color,function(e,t){const o="white"===t?"1":"8",n=[];for(const[r,s]of e)r[1]===o&&s.color===t&&"rook"===s.role&&n.push(S.key2pos(r)[0]);return n}(e,a.color),i);var u;return S.allPos.filter((e=>(c[0]!==e[0]||c[1]!==e[1])&&d(c[0],c[1],e[0],e[1]))).map(S.pos2key)}})),ve=n((function(e,t){function o(e,...t){e&&setTimeout((()=>e(...t)),1)}function n(e){e.premovable.current&&(e.premovable.current=void 0,o(e.premovable.events.unset))}function r(e){const t=e.predroppable;t.current&&(t.current=void 0,o(t.events.unset))}function s(e,t,n){const r=e.pieces.get(t),s=e.pieces.get(n);if(t===n||!r)return!1;const i=s&&s.color!==r.color?s:void 0;return n===e.selected&&d(e),o(e.events.move,t,n,i),function(e,t,o){if(!e.autoCastle)return!1;const n=e.pieces.get(t);if(!n||"king"!==n.role)return!1;const r=S.key2pos(t),s=S.key2pos(o);if(0!==r[1]&&7!==r[1]||r[1]!==s[1])return!1;4!==r[0]||e.pieces.has(o)||(6===s[0]?o=S.pos2key([7,s[1]]):2===s[0]&&(o=S.pos2key([0,s[1]])));const i=e.pieces.get(o);return!(!i||i.color!==n.color||"rook"!==i.role||(e.pieces.delete(t),e.pieces.delete(o),r[0]<s[0]?(e.pieces.set(S.pos2key([6,s[1]]),n),e.pieces.set(S.pos2key([5,s[1]]),i)):(e.pieces.set(S.pos2key([2,s[1]]),n),e.pieces.set(S.pos2key([3,s[1]]),i)),0))}(e,t,n)||(e.pieces.set(n,r),e.pieces.delete(t)),e.lastMove=[t,n],e.check=void 0,o(e.events.change),i||!0}function i(e,t,n,r){if(e.pieces.has(n)){if(!r)return!1;e.pieces.delete(n)}return o(e.events.dropNewPiece,t,n),e.pieces.set(n,t),e.lastMove=[n],e.check=void 0,o(e.events.change),e.movable.dests=void 0,e.turnColor=S.opposite(e.turnColor),!0}function a(e,t,o){const n=s(e,t,o);return n&&(e.movable.dests=void 0,e.turnColor=S.opposite(e.turnColor),e.animation.current=void 0),n}function c(e,t,n){if(h(e,t,n)){const r=a(e,t,n);if(r){const s=e.hold.stop();d(e);const i={premove:!1,ctrlKey:e.stats.ctrlKey,holdTime:s};return!0!==r&&(i.captured=r),o(e.movable.events.after,t,n,i),!0}}else if(function(e,t,o){return t!==o&&p(e,t)&&ge.premove(e.pieces,t,e.premovable.castle).includes(o)}(e,t,n))return function(e,t,n,s){r(e),e.premovable.current=[t,n],o(e.premovable.events.set,t,n,s)}(e,t,n,{ctrlKey:e.stats.ctrlKey}),d(e),!0;return d(e),!1}function l(e,t){e.selected=t,p(e,t)?e.premovable.dests=ge.premove(e.pieces,t,e.premovable.castle):e.premovable.dests=void 0}function d(e){e.selected=void 0,e.premovable.dests=void 0,e.hold.cancel()}function u(e,t){const o=e.pieces.get(t);return!!o&&("both"===e.movable.color||e.movable.color===o.color&&e.turnColor===o.color)}function h(e,t,o){var n,r;return t!==o&&u(e,t)&&(e.movable.free||!!(null===(r=null===(n=e.movable.dests)||void 0===n?void 0:n.get(t))||void 0===r?void 0:r.includes(o)))}function p(e,t){const o=e.pieces.get(t);return!!o&&e.premovable.enabled&&e.movable.color===o.color&&e.turnColor!==o.color}function f(e){n(e),r(e),d(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.whitePov=t.getSnappedKeyAtDomPos=t.getKeyAtDomPos=t.stop=t.cancelMove=t.playPredrop=t.playPremove=t.isDraggable=t.canMove=t.unselect=t.setSelected=t.selectSquare=t.dropNewPiece=t.userMove=t.baseNewPiece=t.baseMove=t.unsetPredrop=t.unsetPremove=t.setCheck=t.setPieces=t.reset=t.toggleOrientation=t.callUserFunction=void 0,t.callUserFunction=o,t.toggleOrientation=function(e){e.orientation=S.opposite(e.orientation),e.animation.current=e.draggable.current=e.selected=void 0},t.reset=function(e){e.lastMove=void 0,d(e),n(e),r(e)},t.setPieces=function(e,t){for(const[o,n]of t)n?e.pieces.set(o,n):e.pieces.delete(o)},t.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)},t.unsetPremove=n,t.unsetPredrop=r,t.baseMove=s,t.baseNewPiece=i,t.userMove=c,t.dropNewPiece=function(e,t,s,a){const c=e.pieces.get(t);c&&(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,s)||a)?(e.pieces.delete(t),i(e,c,s,a),o(e.movable.events.afterNewPiece,c.role,s,{predrop:!1})):c&&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,s)?function(e,t,r){n(e),e.predroppable.current={role:t,key:r},o(e.predroppable.events.set,t,r)}(e,c.role,s):(n(e),r(e)),e.pieces.delete(t),d(e)},t.selectSquare=function(e,t,n){if(o(e.events.select,t),e.selected){if(e.selected===t&&!e.draggable.enabled)return d(e),void e.hold.cancel();if((e.selectable.enabled||n)&&e.selected!==t&&c(e,e.selected,t))return void(e.stats.dragged=!1)}(u(e,t)||p(e,t))&&(l(e,t),e.hold.start())},t.setSelected=l,t.unselect=d,t.canMove=h,t.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))},t.playPremove=function(e){const t=e.premovable.current;if(!t)return!1;const r=t[0],s=t[1];let i=!1;if(h(e,r,s)){const t=a(e,r,s);if(t){const n={premove:!0};!0!==t&&(n.captured=t),o(e.movable.events.after,r,s,n),i=!0}}return n(e),i},t.playPredrop=function(e,t){const n=e.predroppable.current;let s=!1;if(!n)return!1;if(t(n)){i(e,{role:n.role,color:e.movable.color},n.key)&&(o(e.movable.events.afterNewPiece,n.role,n.key,{predrop:!0}),s=!0)}return r(e),s},t.cancelMove=f,t.stop=function(e){e.movable.color=e.movable.dests=e.animation.current=void 0,f(e)},t.getKeyAtDomPos=function(e,t,o){let n=Math.floor(8*(e[0]-o.left)/o.width);t||(n=7-n);let r=7-Math.floor(8*(e[1]-o.top)/o.height);return t||(r=7-r),n>=0&&n<8&&r>=0&&r<8?S.pos2key([n,r]):void 0},t.getSnappedKeyAtDomPos=function(e,t,o,n){const r=S.key2pos(e),s=S.allPos.filter((e=>ge.queen(r[0],r[1],e[0],e[1])||ge.knight(r[0],r[1],e[0],e[1]))),i=s.map((e=>S.computeSquareCenter(S.pos2key(e),o,n))).map((e=>S.distanceSq(t,e))),[,a]=i.reduce(((e,t,o)=>e[0]<t?e:[t,o]),[i[0],0]);return S.pos2key(s[a])},t.whitePov=function(e){return"white"===e.orientation}})),be=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.write=t.read=t.initial=void 0,t.initial="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";const o={p:"pawn",r:"rook",n:"knight",b:"bishop",q:"queen",k:"king"},n={pawn:"p",rook:"r",knight:"n",bishop:"b",queen:"q",king:"k"};t.read=function(e){"start"===e&&(e=t.initial);const n=new Map;let r=7,s=0;for(const t of e)switch(t){case" ":return n;case"/":if(--r,r<0)return n;s=0;break;case"~":const e=n.get(S.pos2key([s,r]));e&&(e.promoted=!0);break;default:const i=t.charCodeAt(0);if(i<57)s+=i-48;else{const e=t.toLowerCase();n.set(S.pos2key([s,r]),{role:o[e],color:t===e?"black":"white"}),++s}}return n},t.write=function(e){return S.invRanks.map((t=>x.files.map((o=>{const r=e.get(o+t);if(r){const e=n[r.role];return"white"===r.color?e.toUpperCase():e}return"1"})).join(""))).join("/").replace(/1{2,}/g,(e=>e.length.toString()))}})),ye=n((function(e,t){function o(e,t){for(const r in t)n(e[r])&&n(t[r])?o(e[r],t[r]):e[r]=t[r]}function n(e){return"object"==typeof e}Object.defineProperty(t,"__esModule",{value:!0}),t.configure=void 0,t.configure=function(e,t){var n;if((null===(n=t.movable)||void 0===n?void 0:n.dests)&&(e.movable.dests=void 0),o(e,t),t.fen&&(e.pieces=be.read(t.fen),e.drawable.shapes=[]),t.hasOwnProperty("check")&&ve.setCheck(e,t.check||!1),t.hasOwnProperty("lastMove")&&!t.lastMove?e.lastMove=void 0:t.lastMove&&(e.lastMove=t.lastMove),e.selected&&ve.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&&n.includes("c"+t)||e==="h"+t&&n.includes("g"+t)))))}}})),we=n((function(e,t){function o(e,t){const o=e(t);return t.dom.redraw(),o}function n(e,t){return{key:e,pos:S.key2pos(e),piece:t}}function r(e,t){return t.sort(((t,o)=>S.distanceSq(e.pos,t.pos)-S.distanceSq(e.pos,o.pos)))[0]}function s(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())=>s(e,t)))}var r}Object.defineProperty(t,"__esModule",{value:!0}),t.render=t.anim=void 0,t.anim=function(e,t){return t.animation.enabled?function(e,t){const o=new Map(t.pieces),i=e(t),a=function(e,t){const o=new Map,s=[],i=new Map,a=[],c=[],l=new Map;let d,u,h;for(const[r,p]of e)l.set(r,n(r,p));for(const r of S.allKeys)d=t.pieces.get(r),u=l.get(r),d?u?S.samePiece(d,u.piece)||(a.push(u),c.push(n(r,d))):c.push(n(r,d)):u&&a.push(u);for(const n of c)u=r(n,a.filter((e=>S.samePiece(n.piece,e.piece)))),u&&(h=[u.pos[0]-n.pos[0],u.pos[1]-n.pos[1]],o.set(n.key,h.concat(h)),s.push(u.key));for(const n of a)s.includes(n.key)||i.set(n.key,n.piece);return{anims:o,fadings:i}}(o,t);if(a.anims.size||a.fadings.size){const e=t.animation.current&&t.animation.current.start;t.animation.current={start:performance.now(),frequency:1/t.animation.duration,plan:a},e||s(t,performance.now())}else t.dom.redraw();return i}(e,t):o(e,t)},t.render=o})),ke=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.clear=t.cancel=t.end=t.move=t.processDraw=t.start=void 0;const o=["green","red","blue","yellow"];function n(e){requestAnimationFrame((()=>{const t=e.drawable.current;if(t){const o=ve.getKeyAtDomPos(t.pos,ve.whitePov(e),e.dom.bounds());o||(t.snapToValidMove=!1);const r=t.snapToValidMove?ve.getSnappedKeyAtDomPos(t.orig,t.pos,ve.whitePov(e),e.dom.bounds()):o;r!==t.mouseSq&&(t.mouseSq=r,t.dest=r!==t.orig?r:void 0,e.dom.redrawNow()),n(e)}}))}function r(e){e.drawable.current&&(e.drawable.current=void 0,e.dom.redraw())}function s(e){var t;const n=(e.shiftKey||e.ctrlKey)&&S.isRightButton(e),r=e.altKey||e.metaKey||(null===(t=e.getModifierState)||void 0===t?void 0:t.call(e,"AltGraph"));return o[(n?1:0)+(r?2:0)]}function i(e){e.onChange&&e.onChange(e.shapes)}t.start=function(e,t){if(t.touches&&t.touches.length>1)return;t.stopPropagation(),t.preventDefault(),t.ctrlKey?ve.unselect(e):ve.cancelMove(e);const o=S.eventPosition(t),r=ve.getKeyAtDomPos(o,ve.whitePov(e),e.dom.bounds());r&&(e.drawable.current={orig:r,pos:o,brush:s(t),snapToValidMove:e.drawable.defaultSnapToValidMove},n(e))},t.processDraw=n,t.move=function(e,t){e.drawable.current&&(e.drawable.current.pos=S.eventPosition(t))},t.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);i(e)}(e.drawable,t),r(e))},t.cancel=r,t.clear=function(e){e.drawable.shapes.length&&(e.drawable.shapes=[],e.dom.redraw(),i(e.drawable))}})),Pe=n((function(e,t){function o(e){requestAnimationFrame((()=>{var t;const r=e.draggable.current;if(!r)return;(null===(t=e.animation.current)||void 0===t?void 0:t.plan.anims.has(r.orig))&&(e.animation.current=void 0);const s=e.pieces.get(r.orig);if(s&&S.samePiece(s,r.piece)){if(!r.started&&S.distanceSq(r.pos,r.origPos)>=Math.pow(e.draggable.distance,2)&&(r.started=!0),r.started){if("function"==typeof r.element){const e=r.element();if(!e)return;e.cgDragging=!0,e.classList.add("dragging"),r.element=e}const t=e.dom.bounds();S.translateAbs(r.element,[r.pos[0]-t.left-t.width/16,r.pos[1]-t.top-t.height/16])}}else n(e);o(e)}))}function n(e){const t=e.draggable.current;t&&(t.newPiece&&e.pieces.delete(t.orig),e.draggable.current=void 0,ve.unselect(e),r(e),e.dom.redraw())}function r(e){const t=e.dom.elements;t.ghost&&S.setVisible(t.ghost,!1)}function s(e,t){let o=e.dom.elements.board.firstChild;for(;o;){if(o.cgKey===t&&"PIECE"===o.tagName)return o;o=o.nextSibling}}Object.defineProperty(t,"__esModule",{value:!0}),t.cancel=t.end=t.move=t.dragNewPiece=t.start=void 0,t.start=function(e,t){if(void 0!==t.button&&0!==t.button)return;if(t.touches&&t.touches.length>1)return;const n=e.dom.bounds(),r=S.eventPosition(t),i=ve.getKeyAtDomPos(r,ve.whitePov(e),n);if(!i)return;const a=e.pieces.get(i),c=e.selected;c||!e.drawable.enabled||!e.drawable.eraseOnClick&&a&&a.color===e.turnColor||ke.clear(e),!1===t.cancelable||t.touches&&e.movable.color&&!a&&!c&&!function(e,t){const o=ve.whitePov(e),n=e.dom.bounds(),r=Math.pow(n.width/8,2);for(const s in e.pieces){const e=S.computeSquareCenter(s,o,n);if(S.distanceSq(e,t)<=r)return!0}return!1}(e,r)||t.preventDefault();const l=!!e.premovable.current,d=!!e.predroppable.current;e.stats.ctrlKey=t.ctrlKey,e.selected&&ve.canMove(e,e.selected,i)?we.anim((e=>ve.selectSquare(e,i)),e):ve.selectSquare(e,i);const u=e.selected===i,h=s(e,i);if(a&&h&&u&&ve.isDraggable(e,i)){e.draggable.current={orig:i,piece:a,origPos:r,pos:r,started:e.draggable.autoDistance&&e.stats.dragged,element:h,previouslySelected:c,originTarget:t.target},h.cgDragging=!0,h.classList.add("dragging");const s=e.dom.elements.ghost;s&&(s.className=`ghost ${a.color} ${a.role}`,S.translateAbs(s,S.posToTranslateAbs(n)(S.key2pos(i),ve.whitePov(e))),S.setVisible(s,!0)),o(e)}else l&&ve.unsetPremove(e),d&&ve.unsetPredrop(e);e.dom.redraw()},t.dragNewPiece=function(e,t,n,r){const i="a0";e.pieces.set(i,t),e.dom.redraw();const a=S.eventPosition(n);e.draggable.current={orig:i,piece:t,origPos:a,pos:a,started:!0,element:()=>s(e,i),originTarget:n.target,newPiece:!0,force:!!r},o(e)},t.move=function(e,t){e.draggable.current&&(!t.touches||t.touches.length<2)&&(e.draggable.current.pos=S.eventPosition(t))},t.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);ve.unsetPremove(e),ve.unsetPredrop(e);const n=S.eventPosition(t)||o.pos,s=ve.getKeyAtDomPos(n,ve.whitePov(e),e.dom.bounds());s&&o.started&&o.orig!==s?o.newPiece?ve.dropNewPiece(e,o.orig,s,o.force):(e.stats.ctrlKey=t.ctrlKey,ve.userMove(e,o.orig,s)&&(e.stats.dragged=!0)):o.newPiece?e.pieces.delete(o.orig):e.draggable.deleteOnDropOff&&!s&&(e.pieces.delete(o.orig),ve.callUserFunction(e.events.change)),(o.orig!==o.previouslySelected||o.orig!==s&&s)&&e.selectable.enabled||ve.unselect(e),r(e),e.draggable.current=void 0,e.dom.redraw()},t.cancel=n})),Me=n((function(e,t){function o(e,t){e.exploding&&(t?e.exploding.stage=t:e.exploding=void 0,e.dom.redraw())}Object.defineProperty(t,"__esModule",{value:!0}),t.explosion=void 0,t.explosion=function(e,t){e.exploding={stage:1,keys:t},e.dom.redraw(),setTimeout((()=>{o(e,2),setTimeout((()=>o(e,void 0)),120)}),120)}})),Te=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.start=void 0,t.start=function(e,t){function o(){ve.toggleOrientation(e),t()}return{set(t){t.orientation&&t.orientation!==e.orientation&&o(),(t.fen?we.anim:we.render)((e=>ye.configure(e,t)),e)},state:e,getFen:()=>be.write(e.pieces),toggleOrientation:o,setPieces(t){we.anim((e=>ve.setPieces(e,t)),e)},selectSquare(t,o){t?we.anim((e=>ve.selectSquare(e,t,o)),e):e.selected&&(ve.unselect(e),e.dom.redraw())},move(t,o){we.anim((e=>ve.baseMove(e,t,o)),e)},newPiece(t,o){we.anim((e=>ve.baseNewPiece(e,t,o)),e)},playPremove(){if(e.premovable.current){if(we.anim(ve.playPremove,e))return!0;e.dom.redraw()}return!1},playPredrop(t){if(e.predroppable.current){const o=ve.playPredrop(e,t);return e.dom.redraw(),o}return!1},cancelPremove(){we.render(ve.unsetPremove,e)},cancelPredrop(){we.render(ve.unsetPredrop,e)},cancelMove(){we.render((e=>{ve.cancelMove(e),Pe.cancel(e)}),e)},stop(){we.render((e=>{ve.stop(e),Pe.cancel(e)}),e)},explode(t){Me.explosion(e,t)},setAutoShapes(t){we.render((e=>e.drawable.autoShapes=t),e)},setShapes(t){we.render((e=>e.drawable.shapes=t),e)},getKeyAtDomPos:t=>ve.getKeyAtDomPos(t,ve.whitePov(e),e.dom.bounds()),redrawAll:t,dragNewPiece(t,o,n){Pe.dragNewPiece(e,t,o,n)},destroy(){ve.stop(e),e.dom.unbind&&e.dom.unbind(),e.dom.destroyed=!0}}}})),Ce=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.defaults=void 0,t.defaults=function(){return{pieces:be.read(be.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:S.timer()}}})),xe=n((function(e,t){function o(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function n({orig:e,dest:t,brush:o,piece:n,modifiers:s},i,a,c){return[c.width,c.height,a,e,t,o,t&&(i.get(t)||0)>1,n&&r(n),s&&(l=s,""+(l.lineWidth||""))].filter((e=>e)).join(",");var l}function r(e){return[e.color,e.role,e.scale].filter((e=>e)).join(",")}function s(e,{shape:t,current:n,hash:r},s,i,p){let f;if(t.piece)f=function(e,t,n,r){const s=h(t,r),i=r.width/8*(n.scale||1),c=n.color[0]+("knight"===n.role?"n":n.role[0]).toUpperCase();return a(o("image"),{className:`${n.role} ${n.color}`,x:s[0]-i/2,y:s[1]-i/2,width:i,height:i,href:e+c+".svg"})}(e.drawable.pieces.baseUrl,c(S.key2pos(t.orig),e.orientation),t.piece,p);else{const r=c(S.key2pos(t.orig),e.orientation);if(t.dest){let m=s[t.brush];t.modifiers&&(m=l(m,t.modifiers)),f=function(e,t,n,r,s,i){const c=function(e,t){return(t?20:10)/512*e.width}(i,s&&!r),l=h(t,i),p=h(n,i),f=p[0]-l[0],m=p[1]-l[1],g=Math.atan2(m,f),v=Math.cos(g)*c,b=Math.sin(g)*c;return a(o("line"),{stroke:e.color,"stroke-width":d(e,r,i),"stroke-linecap":"round","marker-end":"url(#arrowhead-"+e.key+")",opacity:u(e,r),x1:l[0],y1:l[1],x2:p[0]-v,y2:p[1]-b})}(m,r,c(S.key2pos(t.dest),e.orientation),n,(i.get(t.dest)||0)>1,p)}else f=function(e,t,n,r){const s=h(t,r),i=function(e){const t=e.width/512;return[3*t,4*t]}(r),c=(r.width+r.height)/32;return a(o("circle"),{stroke:e.color,"stroke-width":i[n?0:1],fill:"none",opacity:u(e,n),cx:s[0],cy:s[1],r:c-i[1]/2})}(s[t.brush],r,n,p)}return f.setAttribute("cgHash",r),f}function i(e){const t=a(o("marker"),{id:"arrowhead-"+e.key,orient:"auto",markerWidth:4,markerHeight:8,refX:2.05,refY:2.01});return t.appendChild(a(o("path"),{d:"M0,0 V4 L3,2 Z",fill:e.color})),t.setAttribute("cgKey",e.key),t}function a(e,t){for(const o in t)e.setAttribute(o,t[o]);return e}function c(e,t){return"white"===t?e:[7-e[0],7-e[1]]}function l(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 d(e,t,o){return(e.lineWidth||10)*(t?.85:1)/512*o.width}function u(e,t){return(e.opacity||1)*(t?.9:1)}function h(e,t){return[(e[0]+.5)*t.width/8,(7.5-e[1])*t.height/8]}Object.defineProperty(t,"__esModule",{value:!0}),t.renderSvg=t.createElement=void 0,t.createElement=o,t.renderSvg=function(e,t){const o=e.drawable,r=o.current,a=r&&r.mouseSq?r:void 0,c=new Map,d=e.dom.bounds();for(const n of o.shapes.concat(o.autoShapes).concat(a?[a]:[]))n.dest&&c.set(n.dest,(c.get(n.dest)||0)+1);const u=o.shapes.concat(o.autoShapes).map((e=>({shape:e,current:!1,hash:n(e,c,!1,d)})));a&&u.push({shape:a,current:!0,hash:n(a,c,!0,d)});const h=u.map((e=>e.hash)).join(";");if(h===e.drawable.prevSvgHash)return;e.drawable.prevSvgHash=h;const p=t.firstChild;!function(e,t,o){const n=new Map;let r;for(const i of t)i.shape.dest&&(r=e.brushes[i.shape.brush],i.shape.modifiers&&(r=l(r,i.shape.modifiers)),n.set(r.key,r));const s=new Set;let a=o.firstChild;for(;a;)s.add(a.getAttribute("cgKey")),a=a.nextSibling;for(const[c,l]of n.entries())s.has(c)||o.appendChild(i(l))}(o,u,p),function(e,t,o,n,r,i){const a=e.dom.bounds(),c=new Map,l=[];for(const s of t)c.set(s.hash,!1);let d,u=i.nextSibling;for(;u;)d=u.getAttribute("cgHash"),c.has(d)?c.set(d,!0):l.push(u),u=u.nextSibling;for(const s of l)r.removeChild(s);for(const h of t)c.get(h.hash)||r.appendChild(s(e,h,o,n,a))}(e,u,o.brushes,c,t,p)}})),Se=n((function(e,t){function o(e,t){const o=S.createEl("coords",t);let n;for(const r of e)n=S.createEl("coord"),n.textContent=r,o.appendChild(n);return o}Object.defineProperty(t,"__esModule",{value:!0}),t.renderWrap=void 0,t.renderWrap=function(e,t,n){e.innerHTML="",e.classList.add("cg-wrap");for(const o of x.colors)e.classList.toggle("orientation-"+o,t.orientation===o);e.classList.toggle("manipulable",!t.viewOnly);const r=S.createEl("cg-helper");e.appendChild(r);const s=S.createEl("cg-container");r.appendChild(s);const i=S.createEl("cg-board");let a,c;if(s.appendChild(i),t.drawable.visible&&!n&&(a=xe.createElement("svg"),a.appendChild(xe.createElement("defs")),s.appendChild(a)),t.coordinates){const e="black"===t.orientation?" black":"";s.appendChild(o(x.ranks,"ranks"+e)),s.appendChild(o(x.files,"files"+e))}return t.draggable.showGhost&&!n&&(c=S.createEl("piece","ghost"),S.setVisible(c,!1),s.appendChild(c)),{board:i,container:s,ghost:c,svg:a}}})),Oe=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.drop=t.cancelDropMode=t.setDropMode=void 0,t.setDropMode=function(e,t){e.dropmode={active:!0,piece:t},Pe.cancel(e)},t.cancelDropMode=function(e){e.dropmode={active:!1}},t.drop=function(e,t){if(!e.dropmode.active)return;ve.unsetPremove(e),ve.unsetPredrop(e);const o=e.dropmode.piece;if(o){e.pieces.set("a0",o);const n=S.eventPosition(t),r=n&&ve.getKeyAtDomPos(n,ve.whitePov(e),e.dom.bounds());r&&ve.dropNewPiece(e,"a0",r)}e.dom.redraw()}})),_e=n((function(e,t){function o(e,t,o,n){return e.addEventListener(t,o,n),()=>e.removeEventListener(t,o,n)}function n(e,t,o){return n=>{e.drawable.current?e.drawable.enabled&&o(e,n):e.viewOnly||t(e,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.bindDocument=t.bindBoard=void 0,t.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 n=function(e){return t=>{e.draggable.current?Pe.cancel(e):e.drawable.current?ke.cancel(e):t.shiftKey||S.isRightButton(t)?e.drawable.enabled&&ke.start(e,t):e.viewOnly||(e.dropmode.active?Oe.drop(e,t):Pe.start(e,t))}}(e);o.addEventListener("touchstart",n,{passive:!1}),o.addEventListener("mousedown",n,{passive:!1}),(e.disableContextMenu||e.drawable.enabled)&&o.addEventListener("contextmenu",(e=>e.preventDefault()))},t.bindDocument=function(e,t){const r=[];if(e.dom.relative||!e.resizable||"ResizeObserver"in window||r.push(o(document.body,"chessground.resize",t)),!e.viewOnly){const t=n(e,Pe.move,ke.move),s=n(e,Pe.end,ke.end);for(const e of["touchmove","mousemove"])r.push(o(document,e,t));for(const e of["touchend","mouseup"])r.push(o(document,e,s));const i=()=>e.dom.bounds.clear();r.push(o(document,"scroll",i,{capture:!0,passive:!0})),r.push(o(window,"resize",i,{passive:!0}))}return()=>r.forEach((e=>e()))}})),je=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.updateBounds=t.render=void 0;const o=S;function n(e){return"PIECE"===e.tagName}function r(e){return"SQUARE"===e.tagName}function s(e,t){for(const o of t)e.dom.elements.board.removeChild(o)}function i(e,t){let o=2+8*e[1]+(7-e[0]);return t&&(o=67-o),o+""}function a(e){return`${e.color} ${e.role}`}function c(e,t,o){const n=e.get(t);n?e.set(t,`${n} ${o}`):e.set(t,o)}function l(e,t,o){const n=e.get(t);n?n.push(o):e.set(t,[o])}t.render=function(e){const t=ve.whitePov(e),d=e.dom.relative?o.posToTranslateRel:o.posToTranslateAbs(e.dom.bounds()),u=e.dom.relative?o.translateRel:o.translateAbs,h=e.dom.elements.board,p=e.pieces,f=e.animation.current,m=f?f.plan.anims:new Map,g=f?f.plan.fadings:new Map,v=e.draggable.current,b=function(e){var t;const o=new Map;if(e.lastMove&&e.highlight.lastMove)for(const s of e.lastMove)c(o,s,"last-move");e.check&&e.highlight.check&&c(o,e.check,"check");if(e.selected&&(c(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)c(o,t,"move-dest"+(e.pieces.has(t)?" oc":""));const r=e.premovable.dests;if(r)for(const t of r)c(o,t,"premove-dest"+(e.pieces.has(t)?" oc":""))}const n=e.premovable.current;if(n)for(const s of n)c(o,s,"current-premove");else e.predroppable.current&&c(o,e.predroppable.current.key,"current-premove");const r=e.exploding;if(r)for(const s of r.keys)c(o,s,"exploding"+r.stage);return o}(e),y=new Set,w=new Set,k=new Map,P=new Map;let M,T,C,x,O,_,j,A,L,D;for(T=h.firstChild;T;){if(M=T.cgKey,n(T))if(C=p.get(M),O=m.get(M),_=g.get(M),x=T.cgPiece,!T.cgDragging||v&&v.orig===M||(T.classList.remove("dragging"),u(T,d(S.key2pos(M),t)),T.cgDragging=!1),!_&&T.cgFading&&(T.cgFading=!1,T.classList.remove("fading")),C){if(O&&T.cgAnimating&&x===a(C)){const e=S.key2pos(M);e[0]+=O[2],e[1]+=O[3],T.classList.add("anim"),u(T,d(e,t))}else T.cgAnimating&&(T.cgAnimating=!1,T.classList.remove("anim"),u(T,d(S.key2pos(M),t)),e.addPieceZIndex&&(T.style.zIndex=i(S.key2pos(M),t)));x!==a(C)||_&&T.cgFading?_&&x===a(_)?(T.classList.add("fading"),T.cgFading=!0):l(k,x,T):y.add(M)}else l(k,x,T);else if(r(T)){const e=T.className;b.get(M)===e?w.add(M):l(P,e,T)}T=T.nextSibling}for(const[o,n]of b)if(!w.has(o)){L=P.get(n),D=L&&L.pop();const e=d(S.key2pos(o),t);if(D)D.cgKey=o,u(D,e);else{const t=S.createEl("square",n);t.cgKey=o,u(t,e),h.insertBefore(t,h.firstChild)}}for(const[o,n]of p)if(O=m.get(o),!y.has(o))if(j=k.get(a(n)),A=j&&j.pop(),A){A.cgKey=o,A.cgFading&&(A.classList.remove("fading"),A.cgFading=!1);const n=S.key2pos(o);e.addPieceZIndex&&(A.style.zIndex=i(n,t)),O&&(A.cgAnimating=!0,A.classList.add("anim"),n[0]+=O[2],n[1]+=O[3]),u(A,d(n,t))}else{const r=a(n),s=S.createEl("piece",r),c=S.key2pos(o);s.cgPiece=r,s.cgKey=o,O&&(s.cgAnimating=!0,c[0]+=O[2],c[1]+=O[3]),u(s,d(c,t)),e.addPieceZIndex&&(s.style.zIndex=i(c,t)),h.appendChild(s)}for(const o of k.values())s(e,o);for(const o of P.values())s(e,o)},t.updateBounds=function(e){if(e.dom.relative)return;const t=ve.whitePov(e),s=o.posToTranslateAbs(e.dom.bounds());let i=e.dom.elements.board.firstChild;for(;i;)(n(i)&&!i.cgAnimating||r(i))&&o.translateAbs(i,s(S.key2pos(i.cgKey),t)),i=i.nextSibling}})),Ae=n((function(e,t){function o(e){let t=!1;return()=>{t||(t=!0,requestAnimationFrame((()=>{e(),t=!1})))}}Object.defineProperty(t,"__esModule",{value:!0}),t.Chessground=void 0,t.Chessground=function(e,t){const n=Ce.defaults();function r(){const t="dom"in n?n.dom.unbind:void 0,r=n.viewOnly&&!n.drawable.visible,s=Se.renderWrap(e,n,r),i=S.memo((()=>s.board.getBoundingClientRect())),a=e=>{je.render(l),!e&&s.svg&&xe.renderSvg(l,s.svg)},c=()=>{i.clear(),je.updateBounds(l),s.svg&&xe.renderSvg(l,s.svg)},l=n;return l.dom={elements:s,bounds:i,redraw:o(a),redrawNow:a,unbind:t,relative:r},l.drawable.prevSvgHash="",a(!1),_e.bindBoard(l,c),t||(l.dom.unbind=_e.bindDocument(l,c)),l.events.insert&&l.events.insert(s),l}return ye.configure(n,t||{}),Te.start(r(),r)}})),Le=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});t.default=()=>{const e={blue:"#DEE3E6 #788a94",blue2:"#97b2c7 #546f82",blue3:"#d9e0e6 #315991",canvas:"#d7daeb #547388",wood:"#d8a45b #9b4d0f",wood2:"#a38b5d #6c5017",wood3:"#d0ceca #755839",wood4:"#caaf7d #7b5330",maple:"#e8ceab #bc7944",maple2:"#E2C89F #996633",leather:"#d1d1c9 #c28e16",green:"#FFFFDD #6d8753",brown:"#F0D9B5 #946f51",pink:"#E8E9B7 #ED7272",marble:"#93ab91 #4f644e","blue-marble":"#EAE6DD #7C7F87","green-plastic":"#f2f9bb #59935d",grey:"#b8b8b8 #7d7d7d",metal:"#c9c9c9 #727272",olive:"#b8b19f #6d6655",newspaper:"#fff #8d8d8d",purple:"#9f90b0 #7d4a8d","purple-diag":"#E5DAF0 #957AB0",ic:"#ececec #c1c18e"};for(const t of document.body.className.split(" "))if(t in e){const o=document.documentElement.style,n=e[t].split(" ");o.setProperty("--cg-coord-color-white",n[0]),o.setProperty("--cg-coord-color-black",n[1]),o.setProperty("--cg-coord-shadow","none")}}}))),De=o(n((function(e,t){function o(e){return e.clientX||0===e.clientX?[e.clientX,e.clientY]:e.touches&&e.targetTouches[0]?[e.targetTouches[0].clientX,e.targetTouches[0].clientY]:void 0}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n,r){if(!t)return;const s=document.createElement("cg-resize");e.container.appendChild(s);const i=e=>{e.preventDefault();const t="touchstart"===e.type?"touchmove":"mousemove",n="touchstart"===e.type?"touchend":"mouseup",r=o(e),s=parseInt(getComputedStyle(document.body).getPropertyValue("--zoom"));let i=s;const a=H.default((()=>c.text("/pref/zoom?v="+(100+i),{method:"post"})),700),l=e=>{const t=o(e),n=t[0]-r[0]+t[1]-r[1];i=Math.round(Math.min(100,Math.max(0,s+n/10))),document.body.setAttribute("style","--zoom:"+i),window.dispatchEvent(new Event("resize")),a()};document.body.classList.add("resizing"),document.addEventListener(t,l),document.addEventListener(n,(()=>{document.removeEventListener(t,l),document.body.classList.remove("resizing")}),{once:!0})};if(s.addEventListener("touchstart",i,{passive:!1}),s.addEventListener("mousedown",i,{passive:!1}),1==t){const e=e=>s.classList.toggle("none",r?!r(e):e>=2);e(n),lichess.pubsub.on("ply",e)}!function(e){const t=lichess.storage.makeBoolean("resize-nag");if(t.get())return;lichess.loadCssPath("nag-circle"),e.title="Drag to resize",e.innerHTML='<div class="nag-circle"></div>';for(const o of["touchstart","mousedown"])e.addEventListener(o,(()=>{t.set(!0),e.innerHTML=""}),{once:!0});setTimeout((()=>t.set(!0)),15e3)}(s)}})));function Ee(e){const t=e.data,o=e.makeCgHooks(),n=ue(t,e.ply),r=e.isPlaying();return{fen:n.fen,orientation:$e(t,e.flip),turnColor:n.ply%2==0?"white":"black",lastMove:j(n.uci),check:!!n.check,coordinates:0!==t.pref.coords,addPieceZIndex:e.data.pref.is3d,highlight:{lastMove:t.pref.highlight,check:t.pref.highlight},events:{move:o.onMove,dropNewPiece:o.onNewPiece,insert(o){De(o,e.data.pref.resizeHandle,e.ply),1==t.pref.coords&&Le()}},movable:{free:!1,color:r?t.player.color:void 0,dests:r?D(t.possibleMoves):new Map,showDests:t.pref.destination,rookCastle:t.pref.rookCastle,events:{after:o.onUserMove,afterNewPiece:o.onUserNewPiece}},animation:{enabled:!0,duration:t.pref.animationDuration},premovable:{enabled:t.pref.enablePremove,showDests:t.pref.destination,castle:"antichess"!==t.game.variant.key,events:{set:o.onPremove,unset:o.onCancelPremove}},predroppable:{enabled:t.pref.enablePremove&&"crazyhouse"===t.game.variant.key,events:{set:o.onPredrop,unset(){o.onPredrop(void 0)}}},draggable:{enabled:t.pref.moveEvent>0,showGhost:t.pref.highlight},selectable:{enabled:1!==t.pref.moveEvent},drawable:{enabled:!0,defaultSnapToValidMove:"0"!=(lichess.storage.get("arrow.snap")||1)},disableContextMenu:!0}}function Ne(e,t,o){const n=e.state.pieces.get(t);n&&"pawn"===n.role&&e.setPieces(new Map([[t,{color:n.color,role:o,promoted:!0}]]))}function $e(e,t){return"racingKings"===e.game.variant.key?t?"black":"white":t?e.opponent.color:e.player.color}function Be(e){return f("div.cg-wrap",{hook:A((t=>e.setChessground(Ae.Chessground(t,Ee(e)))))})}var Re=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});let o=[],n=!1;function r(e){const t=lichess.storage.make("just-notified");if(document.hasFocus()||Date.now()-parseInt(t.get(),10)<1e3)return;t.set(""+Date.now()),$.isFunction(e)&&(e=e());const r=new Notification("lichess.org",{icon:lichess.assetUrl("logo/lichess-favicon-256.png",{noVersion:!0}),body:e});r.onclick=()=>window.focus(),o.push(r),n||(n=!0,window.addEventListener("focus",(()=>{o.forEach((e=>e.close())),o=[]})))}t.default=function(e){!document.hasFocus()&&"Notification"in window&&"granted"===Notification.permission&&setTimeout(r,10+500*Math.random(),e)}}))),Ie=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){let o,n=0;return function(...r){const s=this,i=performance.now()-n;function a(){o=void 0,n=performance.now(),t.apply(s,r)}o&&clearTimeout(o),i>e?a():o=setTimeout(a,e-i)}}})),qe=o(Ie),ze=o(n((function(e,t){function o(e,t,n){o.close();const r=$('<div id="modal-wrap"><span class="close" data-icon="L"></span></div>'),s=$(`<div id="modal-overlay" class="${t}">`).on("click",o.close);return r.appendTo(s),e.clone().removeClass("none").appendTo(r),o.onClose=n,r.find(".close").on("click",o.close),r.on("click",(e=>e.stopPropagation())),$("body").addClass("overlayed").prepend(s),r}Object.defineProperty(t,"__esModule",{value:!0}),t.default=o,o.close=()=>{$("body").removeClass("overlayed"),$("#modal-overlay").each((function(){o.onClose&&o.onClose(),$(this).remove()})),delete o.onClose},o.onClose=void 0})));const He=e=>c.json(e.data.url.round),Ke=qe(1e3,(e=>c.text("/pref/zen",{method:"post",body:c.form({zen:e?1:0})}))),Fe=e=>qe(100,(()=>lichess.sound.play(e))),Ge=Fe("move"),Ue=Fe("capture"),We=Fe("check"),Ve=Fe("explosion");function Ye(e,t,o){let n,r=0;return function(...s){const i=this,a=performance.now()-r;function c(){n=void 0,r=performance.now(),e*=t,o.apply(i,s)}n&&clearTimeout(n),a>e?c():n=setTimeout(c,e-a)}}const Xe=document.title;let Je=0;const Qe=["/assets/logo/lichess-favicon-32.png","/assets/logo/lichess-favicon-32-invert.png"].map(((e,t)=>()=>{Je!==t&&(document.getElementById("favicon").href=e,Je=t)}));let Ze,et,tt;function ot(){Ze&&clearTimeout(Ze),Ze=void 0,Qe[0]()}function nt(e,t){e.data.player.spectator||(t||(pe.aborted(e.data)||pe.finished(e.data)?t=e.noarg("gameOver"):me.isPlayerTurn(e.data)?(t=e.noarg("yourTurn"),document.hasFocus()||Ze||(Ze=setTimeout((function e(){document.hasFocus()||(Qe[1-Je](),Ze=setTimeout(e,1e3))}),200))):(t=e.noarg("waitingForOpponent"),ot())),document.title=`${t} - ${Xe}`)}function rt(e,t,o,n,r){return Ne(e.chessground,o,n),e.sendMove(t,o,n,r),!0}function st(e,t,o,n={}){const r=e.data,s=e.chessground.state.pieces.get(o),i=e.chessground.state.pieces.get(t);return!(!(s&&"pawn"===s.role&&!i||i&&"pawn"===i.role)||!("8"===o[1]&&"white"===r.player.color||"1"===o[1]&&"black"===r.player.color))&&(tt&&n&&n.premove?rt(e,t,o,tt,n):n.ctrlKey||et||!(3===r.pref.autoQueen||2===r.pref.autoQueen&&i||e.keyboardMove&&e.keyboardMove.justSelected())?(et={move:[t,o],pre:!!i,meta:n},e.redraw(),!0):(i?it(e,o,"queen"):rt(e,t,o,"queen",n),!0))}function it(e,t,o){tt=o,e.chessground.setAutoShapes([{orig:t,piece:{color:e.data.player.color,role:o,opacity:.8},brush:""}])}function at(e){tt&&(e.chessground.setAutoShapes([]),tt=void 0,e.redraw())}function ct(e){at(e),e.chessground.cancelPremove(),et&&He(e).then(e.reload,lichess.reload),et=void 0}function lt(e,t,o,n,r){var s=12.5*(7-S.key2pos(t)[0]);return"white"===r&&(s=87.5-s),f("div#promotion-choice."+(n===r?"top":"bottom"),{hook:A((t=>{t.addEventListener("click",(()=>ct(e))),t.addEventListener("contextmenu",(e=>(e.preventDefault(),!1)))}))},o.map(((t,o)=>f("square",{attrs:{style:`top:${12.5*(n===r?o:7-o)}%;left:${s}%`},hook:L("click",(o=>{o.stopPropagation(),function(e,t){if(et){const o=et;et=void 0,o.pre?it(e,o.move[1],t):rt(e,o.move[0],o.move[1],t,o.meta),e.redraw()}}(e,t)}))},[f(`piece.${t}.${n}`)]))))}const dt=["queen","knight","rook","bishop"];function ut(e){if(et)return lt(e,et.move[1],"antichess"===e.data.game.variant.key?dt.concat("king"):dt,e.data.player.color,e.chessground.state.orientation)}let ht=0,pt=0;function ft(){return ht>=pt}var mt=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){const t=e.trans.noarg,o=e.data;switch(o.game.status.name){case"started":return t("playingRightNow");case"aborted":return t("gameAborted");case"mate":return t("checkmate");case"resign":return t("white"==o.game.winner?"blackResigned":"whiteResigned");case"stalemate":return t("stalemate");case"timeout":switch(o.game.winner){case"white":return t("blackLeftTheGame");case"black":return t("whiteLeftTheGame")}return t("draw");case"draw":return t("draw");case"outoftime":return`${o.game.turns%2==0?t("whiteTimeOut"):t("blackTimeOut")}${o.game.winner?"":" • "+t("draw")}`;case"noStart":return("white"==o.game.winner?"Black":"White")+" didn't move";case"cheat":return"Cheat detected";case"variantEnd":switch(o.game.variant.key){case"kingOfTheHill":return t("kingInTheCenter");case"threeCheck":return t("threeChecks")}return t("variantEnding");default:return o.game.status.name}}})));function gt(e){return function(t){!window.LichessSpeech&&t?lichess.loadModule("speech").then((()=>vt(e))):window.LichessSpeech&&!t&&(window.LichessSpeech=void 0)}}function vt(e){const t=mt(e);if("playingRightNow"==t)window.LichessSpeech.step(e.stepAt(e.ply),!1);else{bt((e=>e.say(t,!1)));const o=e.data.game.winner;o&&bt((t=>t.say(e.noarg(o+"IsVictorious"),!1)))}}function bt(e){window.LichessSpeech&&e(window.LichessSpeech)}var yt=n((function(e,t){function o(e,t,o){return(o?"/embed/":"/")+(e.game?e.game.id:e)+(t?"/"+t:"")}Object.defineProperty(t,"__esModule",{value:!0}),t.cont=t.game=void 0,t.game=o,t.cont=function(e,t){return o(e)+"/continue/"+t}}));function wt(e){const t=e.data,o=yt.game(t,"racingKings"===(n=t).game.variant.key?"white":n.player.color)+"#"+e.ply;var n;return me.replayable(t)?f("a.fbt",{attrs:{href:o},hook:L("click",(e=>{location.pathname===o.split("#")[0]&&location.reload()}))},e.noarg("analysis")):null}function kt(e,t,o,n,r,s){const i=()=>!t||t(e.data);return f("button.fbt."+r,{attrs:{disabled:!i(),title:e.noarg(n)},hook:L("click",(t=>{i()&&(s?s():e.socket.sendLoading(r))}))},[f("span","offerDraw"==n?["½"]:e.nvui?[e.noarg(n)]:_(o))])}function Pt(e){const t=e.opponentGone();return!0===t?f("div.suggestion",[f("p",{hook:Rt},e.noarg("opponentLeftChoices")),f("button.button",{hook:L("click",(()=>e.socket.sendLoading("resign-force")))},e.noarg("forceResignation")),f("button.button",{hook:L("click",(()=>e.socket.sendLoading("draw-force")))},e.noarg("forceDraw"))]):t?f("div.suggestion",[f("p",e.trans.vdomPlural("opponentLeftCounter",t,f("strong",""+t)))]):null}const Mt=(e,t)=>f("button.fbt.no",{attrs:{title:e.noarg("cancel"),"data-icon":"L"},hook:L("click",(()=>t(!1)))}),Tt=e=>f("div.act-confirm",[f("button.fbt.yes",{attrs:{title:e.noarg("resign"),"data-icon":"b"},hook:L("click",(()=>e.resign(!0)))}),Mt(e,e.resign)]),Ct=e=>f("div.act-confirm",[f("button.fbt.yes.draw-yes",{attrs:{title:e.noarg("offerDraw")},hook:L("click",(()=>e.offerDraw(!0)))},f("span","½")),Mt(e,e.offerDraw)]);function xt(e){return e.data.game.threefold?f("div.suggestion",[f("p",{hook:Rt},e.noarg("threefoldRepetition")),f("button.button",{hook:L("click",(()=>e.socket.sendLoading("draw-claim")))},e.noarg("claimADraw"))]):null}function St(e){return e.data.player.offeringDraw?f("div.pending",[f("p",e.noarg("drawOfferSent"))]):null}function Ot(e){return e.data.opponent.offeringDraw?f("div.negotiation.draw",[f("p",e.noarg("yourOpponentOffersADraw")),jt(e,"draw-yes",(()=>e.socket.sendLoading("draw-yes"))),At(e,(()=>e.socket.sendLoading("draw-no")))]):null}function _t(e){return e.data.player.proposingTakeback?f("div.pending",[f("p",e.noarg("takebackPropositionSent")),f("button.button",{hook:L("click",(()=>e.socket.sendLoading("takeback-no")))},e.noarg("cancel"))]):null}function jt(e,t,o,n="accept"){const r=e.noarg(n);return e.nvui?f("button."+t,{hook:L("click",o)},r):f("a.accept",{attrs:{"data-icon":"E",title:r},hook:L("click",o)})}function At(e,t,o="decline"){const n=e.noarg(o);return e.nvui?f("button",{hook:L("click",t)},n):f("a.decline",{attrs:{"data-icon":"L",title:n},hook:L("click",t)})}function Lt(e){return e.data.opponent.proposingTakeback?f("div.negotiation.takeback",[f("p",e.noarg("yourOpponentProposesATakeback")),jt(e,"takeback-yes",e.takebackYes),At(e,(()=>e.socket.sendLoading("takeback-no")))]):null}function Dt(e){var t;const o=e.data;return(null===(t=o.tournament)||void 0===t?void 0:t.running)?f("div.follow-up",[f("a.text.fbt.strong.glowing",{attrs:{"data-icon":"G",href:"/tournament/"+o.tournament.id},hook:L("click",e.setRedirecting)},e.noarg("backToTournament")),f("form",{attrs:{method:"post",action:"/tournament/"+o.tournament.id+"/withdraw"}},[f("button.text.fbt.weak",_("Z"),"Pause")]),wt(e)]):void 0}function Et(e){var t;const o=e.data;return(null===(t=o.swiss)||void 0===t?void 0:t.running)?f("div.follow-up",[f("a.text.fbt.strong.glowing",{attrs:{"data-icon":"G",href:"/swiss/"+o.swiss.id},hook:L("click",e.setRedirecting)},e.noarg("backToTournament")),wt(e)]):void 0}function Nt(e){return me.moretimeable(e.data)?f("a.moretime",{attrs:{title:e.data.clock?e.trans("giveNbSeconds",e.data.clock.moretime):e.noarg("giveMoreTime"),"data-icon":"O"},hook:L("click",e.socket.moreTime)}):null}function $t(e){const t=e.data,o=!t.game.rematch&&(pe.finished(t)||pe.aborted(t))&&!t.tournament&&!t.simul&&!t.swiss&&!t.game.boosted,n=(pe.finished(t)||pe.aborted(t))&&("lobby"===t.game.source||"pool"===t.game.source),r=e.challengeRematched?[f("div.suggestion.text",{hook:Rt},e.noarg("rematchOfferSent"))]:o||t.game.rematch?function(e){const t=e.data,o=!!t.player.offeringRematch,n=!!t.opponent.offeringRematch,r=e.noarg;return[n?f("button.rematch-decline",{attrs:{"data-icon":"L",title:r("decline")},hook:L("click",(()=>{e.socket.send("rematch-no")}))},e.nvui?r("decline"):""):null,f("button.fbt.rematch.white",{class:{me:o,glowing:n,disabled:!o&&!(t.opponent.onGame||!t.clock&&t.player.user&&t.opponent.user)},attrs:{title:n?r("yourOpponentWantsToPlayANewGameWithYou"):o?r("rematchOfferSent"):""},hook:L("click",(t=>{const o=e.data;o.game.rematch?location.href=yt.game(o.game.rematch,o.opponent.color):o.player.offeringRematch?(o.player.offeringRematch=!1,e.socket.send("rematch-no")):o.opponent.onGame?(o.player.offeringRematch=!0,e.socket.send("rematch-yes")):t.target.classList.contains("disabled")||e.challengeRematch()}),e.redraw)},[o?f("div.spinner",{"aria-label":"loading"},[f("svg",{attrs:{viewBox:"0 0 40 40"}},[f("circle",{attrs:{cx:20,cy:20,r:18,fill:"none"}})])]):f("span",r("rematch"))])]}(e):[];return f("div.follow-up",[...r,t.tournament?f("a.fbt",{attrs:{href:"/tournament/"+t.tournament.id}},e.noarg("viewTournament")):null,t.swiss?f("a.fbt",{attrs:{href:"/swiss/"+t.swiss.id}},e.noarg("viewTournament")):null,n?f("a.fbt",{attrs:{href:"pool"===t.game.source?(s=t.clock,i=t.opponent.user,"/#pool/"+s.initial/60+"+"+s.increment+(i?"/"+i.id:"")):"/?hook_like="+t.game.id}},e.noarg("newOpponent")):null,wt(e)]);var s,i}function Bt(e){const t=e.data,o=[t.game.rematch?f("a.fbt.text",{attrs:{"data-icon":"v",href:`/${t.game.rematch}/${t.opponent.color}`}},e.noarg("viewRematch")):null,t.tournament?f("a.fbt",{attrs:{href:"/tournament/"+t.tournament.id}},e.noarg("viewTournament")):null,t.swiss?f("a.fbt",{attrs:{href:"/swiss/"+t.swiss.id}},e.noarg("viewTournament")):null,wt(e)];return o.find((e=>!!e))?f("div.follow-up",o):null}const Rt=A((e=>lichess.pubsub.emit("round.suggestion",e.textContent)));function It(e){return(e<10?"0":"")+e}const qt="<sep>:</sep>";function zt(e,t,o,n){const r=new Date(e);if(n)return(e>=36e5?Math.floor(e/36e5)+"H:":"")+r.getUTCMinutes()+"M:"+r.getUTCSeconds()+"S";const s=r.getUTCMilliseconds(),i=o&&s<500?'<sep class="low">:</sep>':qt,a=It(r.getUTCMinutes())+i+It(r.getUTCSeconds());if(e>=36e5){return It(Math.floor(e/36e5))+qt+a}if(t){let t=Math.floor(s/100).toString();return!o&&e<1e3&&(t+="<huns>"+Math.floor(s/10)%10+"</huns>"),a+"<tenths><sep>.</sep>"+t+"</tenths>"}return a}function Ht(e,t){const o=e.clock,n=e=>{if(void 0!==e.animate){let n=o.elements[t].barAnim;void 0!==n&&n.effect&&n.effect.target===e||(n=e.animate([{transform:"scale(1)"},{transform:"scale(0, 1)"}],{duration:o.barTime,fill:"both"}),o.elements[t].barAnim=n);const r=o.millisOf(t);n.currentTime=o.barTime-r,t===o.times.activeColor?r>0&&n.play():n.pause()}else o.elements[t].bar=e,e.style.transform="scale("+o.timeRatio(o.millisOf(t))+",1)"};return f("div.bar",{class:{berserk:!!e.goneBerserk[t]},hook:{insert:e=>n(e.elm),postpatch:(e,t)=>n(t.elm)}})}function Kt(e,t){return!!e.goneBerserk[t]&&e.data.game.turns<=1&&me.playable(e.data)}function Ft(e,t,o){return Kt(e,t)?f("div.berserked."+o,_("`")):null}function Gt(e){if(me.berserkableBy(e.data)&&!e.goneBerserk[e.data.player.color])return f("button.fbt.go-berserk",{attrs:{title:"GO BERSERK! Half the time, no increment, bonus point","data-icon":"`"},hook:L("click",e.goBerserk)})}function Ut(e,t,o){var n,r;const s=e.data,i=(null===(n=s.tournament)||void 0===n?void 0:n.ranks)||(null===(r=s.swiss)||void 0===r?void 0:r.ranks);return i&&!Kt(e,t)?f("div.tour-rank."+o,{attrs:{title:"Current tournament rank"}},"#"+i[t]):null}class Wt{constructor(e,t){this.opts=t,this.emergSound={play:()=>lichess.sound.play("lowTime"),delay:2e4,playable:{white:!0,black:!0}},this.elements={white:{},black:{}},this.timeRatio=e=>Math.min(1,e*this.timeRatioDivisor),this.setClock=(e,t,o,n=0)=>{const r=me.playable(e)&&(me.playedTurns(e)>1||e.clock.running),s=10*n;this.times={white:1e3*t,black:1e3*o,activeColor:r?e.game.player:void 0,lastUpdate:performance.now()+s},r&&this.scheduleTick(this.times[e.game.player],s)},this.addTime=(e,t)=>{this.times[e]+=10*t},this.stopClock=()=>{const e=this.times.activeColor;if(e){const t=this.elapsed();return this.times[e]=Math.max(0,this.times[e]-t),this.times.activeColor=void 0,t}},this.hardStopClock=()=>this.times.activeColor=void 0,this.scheduleTick=(e,t)=>{void 0!==this.tickCallback&&clearTimeout(this.tickCallback),this.tickCallback=setTimeout(this.tick,this.opts.nvui?1e3:e%(this.showTenths(e)?100:500)+1+t)},this.tick=()=>{this.tickCallback=void 0;const e=this.times.activeColor;if(void 0===e)return;const t=performance.now(),o=Math.max(0,this.times[e]-this.elapsed(t));this.scheduleTick(o,0),0===o?this.opts.onFlag():function(e,t,o){if(t.time&&(t.time.innerHTML=zt(o,e.showTenths(o),!0,e.opts.nvui)),t.bar&&(t.bar.style.transform="scale("+e.timeRatio(o)+",1)"),t.clock){const n=t.clock.classList;o<e.emergMs?n.add("emerg"):n.contains("emerg")&&n.remove("emerg")}}(this,this.elements[e],o),this.opts.soundColor===e&&(this.emergSound.playable[e]?o<this.emergMs&&!(t<this.emergSound.next)&&(this.emergSound.play(),this.emergSound.next=t+this.emergSound.delay,this.emergSound.playable[e]=!1):o>1.5*this.emergMs&&(this.emergSound.playable[e]=!0))},this.elapsed=(e=performance.now())=>Math.max(0,e-this.times.lastUpdate),this.millisOf=e=>this.times.activeColor===e?Math.max(0,this.times[e]-this.elapsed()):this.times[e],this.isRunning=()=>void 0!==this.times.activeColor;const o=e.clock;if(0===o.showTenths)this.showTenths=()=>!1;else{const e=1===o.showTenths?1e4:36e5;this.showTenths=t=>t<e}this.showBar=o.showBar&&!this.opts.nvui,this.barTime=1e3*(Math.max(o.initial,2)+5*o.increment),this.timeRatioDivisor=1/this.barTime,this.emergMs=1e3*Math.min(60,Math.max(10,.125*o.initial)),this.setClock(e,o.white,o.black)}}class Vt{constructor(e,t){this.ctrl=e,this.key=t,this.storage=lichess.storage.makeBoolean(this.key),this.toggle=()=>{this.storage.toggle(),this.next(!0)},this.get=this.storage.get,this.redirect=e=>{this.ctrl.setRedirecting(),window.location.href=e},this.next=e=>{const t=this.ctrl.data;!t.player.spectator&&me.isSwitchable(t)&&!me.isPlayerTurn(t)&&this.get()&&(e?this.redirect("/round-next/"+t.game.id):t.simul?t.simul.hostId===this.ctrl.opts.userId&&t.simul.nbPlaying>1&&this.redirect("/round-next/"+t.game.id):(e=>c.json(`/whats-next/${e.data.game.id}${e.data.player.id}`))(this.ctrl).then((e=>{e.next&&this.redirect("/"+e.next)})))}}}class Yt{constructor(e){this.socket=e,this.current=void 0,this.register=()=>{this.current=setTimeout(this.expire,1e4)},this.clear=()=>{this.current&&clearTimeout(this.current)},this.expire=()=>{c.text("/statlog?e=roundTransientExpire",{method:"post"}),this.socket.reload({})}}}function Xt(e,t){const o=[],n=new Map,r=S.key2pos(t),s=Math.max(0,r[0]-1),i=Math.min(7,r[0]+1),a=Math.max(0,r[1]-1),c=Math.min(7,r[1]+1);for(let l=s;l<=i;l++)for(let r=a;r<=c;r++){const s=S.pos2key([l,r]);o.push(s);const i=e.chessground.state.pieces.get(s);i&&(s===t||"pawn"!==i.role)&&n.set(s,void 0)}e.chessground.setPieces(n),e.chessground.explode(o)}const Jt=["pawn","knight","bishop","rook","queen"];let Qt=!1,Zt=!1,eo=!1;function to(e,t,o){if(0===oo.length?Zt=!0:(Qt=!0,eo||no(e)),!me.isPlayerTurn(e))return!1;if("pawn"===t&&("1"===o[1]||"8"===o[1]))return!1;const n=e.possibleDrops;if(null==n)return!0;return(n.match(/.{2}/g)||[]).includes(o)}const oo=[];function no(e){const t=e.player.color[0];for(const o of"PNBRQ")fetch(lichess.assetUrl(`piece/cburnett/${t}${o}.svg`));eo=!0}const ro={P:"pawn",N:"knight",B:"bishop",R:"rook",Q:"queen",K:"king"};function so(e){return f("div.keyboard-move",[f("input",{attrs:{spellcheck:!1,autocomplete:!1},hook:A((t=>lichess.loadModule("round.keyboardMove").then((()=>e.registerHandler(lichess.keyboardMove({input:t,ctrl:e}))))))}),e.hasFocus()?f("em","Enter SAN (Nc3) or UCI (b1c3) moves, or type / to focus chat"):f("strong","Press <enter> to focus")])}function io(e,t){return e.trans("aiNameLevelAiLevel","Stockfish",t)}function ao(e,t){return t.user?(t.user.title?t.user.title+" ":"")+t.user.username:t.ai?io(e,t.ai):"Anonymous"}let co=!1;function lo(e){return e.split(" ")[0]}const uo=e=>e.userJump(e.ply-1),ho=e=>e.userJump(e.ply+1);class po{constructor(e,t){var o;this.opts=e,this.redraw=t,this.firstSeconds=!0,this.flip=!1,this.loading=!1,this.redirecting=!1,this.goneBerserk={},this.resignConfirm=void 0,this.drawConfirm=void 0,this.autoScroll=()=>{},this.challengeRematched=!1,this.shouldSendMoveTime=!1,this.showExpiration=()=>{this.data.expiration&&(this.redraw(),setTimeout(this.showExpiration,250))},this.onUserMove=(e,t,o)=>{this.keyboardMove&&this.keyboardMove.usedSan||ie(this,o),st(this,e,t,o)||this.sendMove(e,t,void 0,o)},this.onUserNewPiece=(e,t,o)=>{!this.replaying()&&to(this.data,e,t)?this.sendNewPiece(e,t,!!o.predrop):this.jump(this.ply)},this.onMove=(e,t,o)=>{o?"atomic"===this.data.game.variant.key?(Ve(),Xt(this,t)):Ue():Ge()},this.onPremove=(e,t,o)=>{st(this,e,t,o)},this.onCancelPremove=()=>{at(this)},this.onPredrop=(e,t)=>{this.preDrop=e,this.redraw()},this.isSimulHost=()=>this.data.simul&&this.data.simul.hostId===this.opts.userId,this.makeCgHooks=()=>({onUserMove:this.onUserMove,onUserNewPiece:this.onUserNewPiece,onMove:this.onMove,onNewPiece:Ge,onPremove:this.onPremove,onCancelPremove:this.onCancelPremove,onPredrop:this.onPredrop}),this.replaying=()=>this.ply!==le(this.data),this.userJump=e=>{this.cancelMove(),this.chessground.selectSquare(null),e!=this.ply&&this.jump(e)?function(e,t){bt((o=>o.step(e.stepAt(t),!0)))}(this,this.ply):this.redraw()},this.isPlaying=()=>me.isPlayerPlaying(this.data),this.jump=e=>{const t=(e=Math.max(ce(this.data),Math.min(le(this.data),e)))===this.ply+1;this.ply=e,this.justDropped=void 0,this.preDrop=void 0;const o=this.stepAt(e),n={fen:o.fen,lastMove:j(o.uci),check:!!o.check,turnColor:this.ply%2==0?"white":"black"};return this.replaying()?this.chessground.stop():n.movable={color:this.isPlaying()?this.data.player.color:void 0,dests:D(this.data.possibleMoves)},this.chessground.set(n),o.san&&t&&(o.san.includes("x")?Ue():Ge(),/[+#]/.test(o.san)&&We()),this.autoScroll(),this.keyboardMove&&this.keyboardMove.update(o),lichess.pubsub.emit("ply",e),!0},this.replayEnabledByPref=()=>{const e=this.data;return 2===e.pref.replay||1===e.pref.replay&&("classical"===e.game.speed||"unlimited"===e.game.speed||"correspondence"===e.game.speed)},this.isLate=()=>this.replaying()&&pe.playing(this.data),this.playerAt=e=>this.flip^"top"===e?this.data.opponent:this.data.player,this.flipNow=()=>{this.flip=!this.nvui&&!this.flip,this.chessground.set({orientation:$e(this.data,this.flip)}),this.redraw()},this.setTitle=()=>nt(this),this.actualSendMove=(e,t,o={})=>{const n={ackable:!0};if(this.clock)if(n.withLag=!this.shouldSendMoveTime||!this.clock.isRunning,o.premove&&this.shouldSendMoveTime)this.clock.hardStopClock(),n.millis=0;else{const e=this.clock.stopClock();void 0!==e&&this.shouldSendMoveTime&&(n.millis=e)}this.socket.send(e,t,n),this.justDropped=o.justDropped,this.justCaptured=o.justCaptured,this.preDrop=void 0,this.transientMove.register(),this.redraw()},this.sendMove=(e,t,o,n)=>{const r={u:e+t};o&&(r.u+="knight"===o?"n":o[0]),ft()&&(r.b=1),this.resign(!1),this.data.pref.submitMove&&!n.premove?(this.moveToSubmit=r,this.redraw()):this.actualSendMove("move",r,{justCaptured:n.captured,premove:n.premove})},this.sendNewPiece=(e,t,o)=>{const n={role:e,pos:t};ft()&&(n.b=1),this.resign(!1),this.data.pref.submitMove&&!o?(this.dropToSubmit=n,this.redraw()):this.actualSendMove("drop",n,{justDropped:e,premove:o})},this.showYourMoveNotification=()=>{const e=this.data;me.isPlayerTurn(e)?Re((()=>{let t=this.noarg("yourTurn"),o=ao(this,e.opponent);if(this.ply<1)t=`${o}\njoined the game.\n${t}`;else{let n=e.steps[e.steps.length-1].san;n=`${Math.floor((this.ply-1)/2)+1}${this.ply%2==1?".":"..."} ${n}`,t=`${o}\nplayed ${n}.\n${t}`}return t})):this.isPlaying()&&this.ply<1&&Re((()=>ao(this,e.opponent)+"\njoined the game."))},this.playerByColor=e=>this.data[e===this.data.player.color?"player":"opponent"],this.apiMove=e=>{var t,o;const n=this.data,r=this.isPlaying();n.game.turns=e.ply,n.game.player=e.ply%2==0?"white":"black";const s=e.ply%2==0?"black":"white",i=n.player.color===n.game.player;if(e.status&&(n.game.status=e.status),e.winner&&(n.game.winner=e.winner),this.playerByColor("white").offeringDraw=e.wDraw,this.playerByColor("black").offeringDraw=e.bDraw,n.possibleMoves=i?e.dests:void 0,n.possibleDrops=i?e.drops:void 0,n.crazyhouse=e.crazyhouse,this.setTitle(),!this.replaying()){if(this.ply++,e.role)this.chessground.newPiece({role:e.role,color:s},e.uci.substr(2,2));else{const n=j(e.uci),r=this.chessground.state.pieces;(!e.castle||"king"===(null===(t=r.get(e.castle.king[0]))||void 0===t?void 0:t.role)&&"rook"===(null===(o=r.get(e.castle.rook[0]))||void 0===o?void 0:o.role))&&this.chessground.move(n[0],n[1])}if(e.enpassant){const t=e.enpassant;this.chessground.setPieces(new Map([[t.key,void 0]])),"atomic"===n.game.variant.key?(!function(e,t,o){const n=S.key2pos(t),r=[n[0],n[1]+("white"===o?-1:1)];Xt(e,S.pos2key(r))}(this,t.key,t.color),Ve()):Ue()}e.promotion&&Ne(this.chessground,e.promotion.key,e.promotion.pieceClass),this.chessground.set({turnColor:n.game.player,movable:{dests:r?D(n.possibleMoves):new Map},check:!!e.check}),e.check&&We(),pt=Date.now()+1e3,lichess.pubsub.emit("ply",this.ply)}n.game.threefold=!!e.threefold;const a={ply:le(this.data)+1,fen:e.fen,san:e.san,uci:e.uci,check:e.check,crazy:e.crazyhouse};if(n.steps.push(a),this.justDropped=void 0,this.justCaptured=void 0,me.setOnGame(n,s,!0),this.data.forecastCount=void 0,e.clock){this.shouldSendMoveTime=!0;const t=e.clock,o=r&&i?0:t.lag||1;this.clock?this.clock.setClock(n,t.white,t.black,o):this.corresClock&&this.corresClock.update(t.white,t.black)}if(this.data.expiration&&(this.data.steps.length>2?this.data.expiration=void 0:this.data.expiration.movedAt=Date.now()),this.redraw(),r&&s==n.player.color&&(this.transientMove.clear(),this.moveOn.next(),function(e,t){e.opponent.ai&&lichess.storage.fire("ceval.fen",t.fen)}(n,e)),!this.replaying()&&s!=n.player.color){const e="atomic"===n.game.variant.key?100:1;setTimeout((()=>{this.chessground.playPremove()||this.playPredrop()||(ct(this),this.showYourMoveNotification())}),e)}return this.autoScroll(),this.onChange(),this.keyboardMove&&this.keyboardMove.update(a,s!=n.player.color),this.music&&this.music.jump(e),function(e){bt((t=>t.step(e,!1)))}(a),!0},this.playPredrop=()=>this.chessground.playPredrop((e=>to(this.data,e.role,e.key))),this.reload=e=>{e.steps.length!==this.data.steps.length&&(this.ply=e.steps[e.steps.length-1].ply),he(e),this.data=e,this.clearJust(),this.shouldSendMoveTime=!1,this.clock&&this.clock.setClock(e,e.clock.white,e.clock.black),this.corresClock&&this.corresClock.update(e.correspondence.white,e.correspondence.black),this.replaying()||function(e){e.chessground.set(Ee(e))}(this),this.setTitle(),this.moveOn.next(),this.setQuietMode(),this.redraw(),this.autoScroll(),this.onChange(),this.setLoading(!1),this.keyboardMove&&this.keyboardMove.update(e.steps[e.steps.length-1])},this.endWithData=e=>{var t,o;const n=this.data;if(n.game.winner=e.winner,n.game.status=e.status,n.game.boosted=e.boosted,this.userJump(le(n)),this.chessground.stop(),e.ratingDiff&&(n.player.ratingDiff=e.ratingDiff[n.player.color],n.opponent.ratingDiff=e.ratingDiff[n.opponent.color]),!n.player.spectator&&n.game.turns>1){const r=e.winner?n.player.color===e.winner?"victory":"defeat":"draw";lichess.sound.play(r),"victory"!=r&&n.game.turns>6&&!n.tournament&&!n.swiss&&"1"==lichess.storage.get("courtesy")&&(null===(o=null===(t=this.opts.chat)||void 0===t?void 0:t.instance)||void 0===o||o.then((e=>e.post("Good game, well played"))))}n.crazyhouse&&function(){const e=lichess.storage.make("crazyKeyHist");if(Qt)e.set(10);else if(Zt){const t=parseInt(e.get());t>0&&t<=10?e.set(t-1):0!==t&&e.set(3)}}(),this.clearJust(),this.setTitle(),this.moveOn.next(),this.setQuietMode(),this.setLoading(!1),this.clock&&e.clock&&this.clock.setClock(n,.01*e.clock.wc,.01*e.clock.bc),this.redraw(),this.autoScroll(),this.onChange(),n.tv&&setTimeout(lichess.reload,1e4),vt(this)},this.challengeRematch=()=>{var e;this.challengeRematched=!0,(e=this.data.game.id,c.json("/challenge/rematch-of/"+e,{method:"post"})).then((()=>{lichess.pubsub.emit("challenge-app.open"),lichess.once("rematch-challenge")&&setTimeout((()=>{lichess.hopscotch((function(){window.hopscotch.configure({i18n:{doneBtn:"OK, got it"}}).startTour({id:"rematch-challenge",showPrevButton:!0,steps:[{title:"Challenged to a rematch",content:"Your opponent is offline, but they can accept this challenge later!",target:"#challenge-app",placement:"bottom"}]})}))}),1e3)}),(e=>{this.challengeRematched=!1}))},this.makeCorrespondenceClock=()=>{this.data.correspondence&&!this.corresClock&&(this.corresClock=function(e,t,o){const n=.1/t.increment;let r;function s(e,t){r={white:1e3*e,black:1e3*t,lastUpdate:performance.now()}}return s(t.white,t.black),{root:e,data:t,timePercent:function(e){return Math.max(0,Math.min(100,r[e]*n))},millisOf:function(e){return Math.max(0,r[e])},update:s,tick:function(e){const t=performance.now();r[e]-=t-r.lastUpdate,r.lastUpdate=t,r[e]<=0&&o()}}}(this,this.data.correspondence,this.socket.outoftime))},this.corresClockTick=()=>{this.corresClock&&me.playable(this.data)&&this.corresClock.tick(this.data.game.player)},this.setQuietMode=()=>{const e=lichess.quietMode,t=this.isPlaying();e!==t&&(lichess.quietMode=t,$("body").toggleClass("playing",t).toggleClass("no-select",t&&this.clock&&this.clock.millisOf(this.data.player.color)<=3e5))},this.takebackYes=()=>{this.socket.sendLoading("takeback-yes"),this.chessground.cancelPremove(),ct(this)},this.resign=(e,t)=>{e?(this.resignConfirm||!this.data.pref.confirmResign||t?(this.socket.sendLoading("resign"),clearTimeout(this.resignConfirm)):this.resignConfirm=setTimeout((()=>this.resign(!1)),3e3),this.redraw()):this.resignConfirm&&(clearTimeout(this.resignConfirm),this.resignConfirm=void 0,this.redraw())},this.goBerserk=()=>{this.socket.berserk(),lichess.sound.play("berserk")},this.setBerserk=e=>{this.goneBerserk[e]||(this.goneBerserk[e]=!0,e!==this.data.player.color&&lichess.sound.play("berserk"),this.redraw())},this.setLoading=(e,t=1500)=>{clearTimeout(this.loadingTimeout),e?(this.loading=!0,this.loadingTimeout=setTimeout((()=>{this.loading=!1,this.redraw()}),t),this.redraw()):this.loading&&(this.loading=!1,this.redraw())},this.setRedirecting=()=>{this.redirecting=!0,lichess.unload.expected=!0,setTimeout((()=>{this.redirecting=!1,this.redraw()}),2500),this.redraw()},this.submitMove=e=>{const t=this.moveToSubmit||this.dropToSubmit;e&&t?(this.moveToSubmit?this.actualSendMove("move",this.moveToSubmit):this.actualSendMove("drop",this.dropToSubmit),lichess.sound.play("confirmation")):this.jump(this.ply),this.cancelMove(),t&&this.setLoading(!0,300)},this.cancelMove=()=>{this.moveToSubmit=void 0,this.dropToSubmit=void 0},this.onChange=()=>{this.opts.onChange&&setTimeout((()=>this.opts.onChange(this.data)),150)},this.setGone=e=>{me.setGone(this.data,this.data.opponent.color,e),clearTimeout(this.goneTick),Number(e)>1&&(this.goneTick=setTimeout((()=>{const e=Number(this.opponentGone());e>1&&this.setGone(e-1)}),1e3)),this.redraw()},this.opponentGone=()=>{const e=this.data;return!1!==e.opponent.gone&&!me.isPlayerTurn(e)&&me.resignable(e)&&e.opponent.gone},this.canOfferDraw=()=>me.drawable(this.data)&&(this.lastDrawOfferAtPly||-99)<this.ply-20,this.offerDraw=e=>{this.canOfferDraw()&&(this.drawConfirm?(e&&this.doOfferDraw(),clearTimeout(this.drawConfirm),this.drawConfirm=void 0):e&&(this.data.pref.confirmResign?this.drawConfirm=setTimeout((()=>{this.offerDraw(!1)}),3e3):this.doOfferDraw())),this.redraw()},this.doOfferDraw=()=>{this.lastDrawOfferAtPly=this.ply,this.socket.sendLoading("draw-yes",null)},this.setChessground=e=>{this.chessground=e,this.data.pref.keyboardMove&&(this.keyboardMove=function(e,t,o){let n,r=!1,s=t.fen,i=Date.now();const a=e.chessground.state,c=function(t){a.selected===t?e.chessground.cancelMove():(e.chessground.selectSquare(t,!0),i=Date.now())};let l=!1;return{drop(t,o){const n=ro[o],r=e.data.crazyhouse,s=e.data.player.color;n&&r&&!a.pieces.has(t)&&r.pockets["white"===s?0:1][n]&&to(e.data,n,t)&&(e.chessground.cancelMove(),e.chessground.newPiece({role:n,color:s},t),e.sendNewPiece(n,t,!1))},promote(t,o,n){const r=ro[n];r&&"pawn"!=r&&(e.chessground.cancelMove(),rt(e,t,o,r,{premove:!1}))},update(e,t=!1){n?n(e.fen,a.movable.dests,t):s=e.fen},registerHandler(e){n=e,s&&n(s,a.movable.dests)},hasFocus:()=>r,setFocus(e){r=e,o()},san(t,o){l=!0,e.chessground.cancelMove(),c(t),c(o)},select:c,hasSelected:()=>a.selected,confirmMove(){e.submitMove(!0)},usedSan:l,jump(t){e.userJump(e.ply+t),o()},justSelected:()=>Date.now()-i<500,clock:()=>e.clock,resign:e.resign}}(this,this.stepAt(this.ply),this.redraw),requestAnimationFrame((()=>this.redraw())))},this.stepAt=e=>ue(this.data,e),this.delayedInit=()=>{const e=this.data;this.isPlaying()&&0===me.nbMoves(e,e.player.color)&&!this.isSimulHost()&&lichess.sound.play("genericNotify"),lichess.requestIdleCallback((()=>{const e=this.data;this.isPlaying()&&(e.simul||(e.steps.length>2||(pt=Date.now()+1e4),window.addEventListener("focus",(()=>ht=Date.now()))),window.addEventListener("focus",ot),this.setTitle(),e.crazyhouse&&function(e){const t=window.Mousetrap;let o;const n=()=>{if(o&&document.body.classList.remove(o),oo.length>0){const t=Jt[oo[oo.length-1]-1],n=e.data.player.color,r=e.data.crazyhouse;if(!r)return;const s=r.pockets["white"===n?0:1][t];Oe.setDropMode(e.chessground.state,s>0?{color:n,role:t}:void 0),o=`cursor-${n}-${t}`,document.body.classList.add(o)}else Oe.cancelDropMode(e.chessground.state),o=void 0};lichess.pubsub.on("ply",(()=>{oo.length>0&&n()}));for(let s=1;s<=5;s++){const e=s.toString();t.bind(e,(()=>{oo.includes(s)||(oo.push(s),n())})).bind(e,(()=>{const e=oo.indexOf(s);e>=0&&(oo.splice(e,1),e===oo.length&&n())}),"keyup")}const r=()=>{oo.length>0&&(oo.length=0,n())};window.addEventListener("blur",r),window.addEventListener("focus",(e=>{e.target&&"input"===e.target.localName&&r()}),{capture:!0}),"0"!==lichess.storage.get("crazyKeyHist")&&no(e.data)}(this),window.addEventListener("beforeunload",(e=>{const t=this.data;if(lichess.unload.expected||this.nvui||!me.playable(t)||!t.clock||t.opponent.ai||this.isSimulHost())return;this.socket.send("bye2");const o="There is a game in progress!";return(e||window.event).returnValue=o,o})),!this.nvui&&e.pref.submitMove&&window.Mousetrap.bind("esc",(()=>{this.submitMove(!1),this.chessground.cancelMove()})).bind("return",(()=>this.submitMove(!0))),function(e){e.data.opponent.ai||!e.data.game.rated&&e.opts.userId||e.data.player.user&&"BOT"===e.data.player.user.title||(lichess.storage.fire("ceval.disable"),lichess.storage.make("ceval.fen").listen((t=>{const o=e.data,n=de(e.data);!co&&n.ply>14&&e.isPlaying()&&t.value&&lo(n.fen)===lo(t.value)&&(c.text(`/jslog/${o.game.id}${o.player.id}?n=ceval`,{method:"post"}),co=!0)})))}(this)),this.nvui||(e=>{window.Mousetrap.bind(["left","h"],(()=>{uo(e),e.redraw()})).bind(["right","l"],(()=>{ho(e),e.redraw()})).bind(["up","k"],(()=>{e.userJump(0),e.redraw()})).bind(["down","j"],(()=>{e.userJump(e.data.steps.length-1),e.redraw()})).bind("f",e.flipNow).bind("z",(()=>lichess.pubsub.emit("zen")))})(this),function(e){lichess.pubsub.on("speech.enabled",gt(e)),gt(e)(lichess.sound.speech())}(this),this.onChange()}))},he(e.data);const n=this.data=e.data;this.ply=le(n),this.goneBerserk[n.player.color]=n.player.berserk,this.goneBerserk[n.opponent.color]=n.opponent.berserk,setTimeout((()=>{this.firstSeconds=!1,this.redraw()}),3e3),this.socket=function(e,t){function o(e,r){e&&e.t?(t.setLoading(!1),n[e.t](e.d)):He(t).then((n=>{lichess.socket.getVersion()>n.player.version?r?lichess.reload():o(e,!0):t.reload(n)}),lichess.reload)}const n={takebackOffers(e){t.setLoading(!1),t.data.player.proposingTakeback=e[t.data.player.color],(t.data.opponent.proposingTakeback=e[t.data.opponent.color])&&Re(t.noarg("yourOpponentProposesATakeback")),t.redraw()},move:t.apiMove,drop:t.apiMove,reload:o,redirect:t.setRedirecting,clockInc(e){t.clock&&(t.clock.addTime(e.color,e.time),t.redraw())},cclock(e){t.corresClock&&(t.data.correspondence.white=e.white,t.data.correspondence.black=e.black,t.corresClock.update(e.white,e.black),t.redraw())},crowd(e){["white","black"].forEach((o=>{a.defined(e[o])&&me.setOnGame(t.data,o,e[o])})),t.redraw()},endData:t.endWithData,rematchOffer(e){t.data.player.offeringRematch=e===t.data.player.color,(t.data.opponent.offeringRematch=e===t.data.opponent.color)&&Re(t.noarg("yourOpponentWantsToPlayANewGameWithYou")),t.redraw()},rematchTaken(e){t.data.game.rematch=e,t.data.player.spectator?t.redraw():t.setLoading(!0)},drawOffer(e){t.data.player.offeringDraw=e===t.data.player.color,(t.data.opponent.offeringDraw=e===t.data.opponent.color)&&Re(t.noarg("yourOpponentOffersADraw")),t.redraw()},berserk(e){t.setBerserk(e)},gone:t.setGone,goneIn:t.setGone,checkCount(e){t.data.player.checks="white"==t.data.player.color?e.white:e.black,t.data.opponent.checks="white"==t.data.opponent.color?e.white:e.black,t.redraw()},simulPlayerMove(e){t.opts.userId&&t.data.simul&&t.opts.userId==t.data.simul.hostId&&e!==t.data.game.id&&t.moveOn.get()&&!me.isPlayerTurn(t.data)&&(t.setRedirecting(),Ge(),location.href="/"+e)},simulEnd(e){lichess.loadCssPath("modal"),ze($(`<p>Simul complete!</p><br /><br /><a class="button" href="/simul/${e.id}">Back to ${e.name} simul</a>`))}};return lichess.pubsub.on("ab.rep",(t=>e("rep",{n:t}))),{send:e,handlers:n,moreTime:qe(300,(()=>e("moretime"))),outoftime:Ye(500,1.1,(()=>e("flag",t.data.game.player))),berserk:qe(200,(()=>e("berserk",null,{ackable:!0}))),sendLoading(o,n){t.setLoading(!0),e(o,n)},receive:(e,t)=>!!n[e]&&(n[e](t),!0),reload:o}}(e.socketSend,this),lichess.RoundNVUI&&(this.nvui=lichess.RoundNVUI(t)),n.clock?this.clock=new Wt(n,{onFlag:this.socket.outoftime,soundColor:n.simul||n.player.spectator||!n.pref.clockSound?void 0:n.player.color,nvui:!!this.nvui}):(this.makeCorrespondenceClock(),setInterval(this.corresClockTick,1e3)),this.setQuietMode(),this.moveOn=new Vt(this,"move-on"),this.transientMove=new Yt(this.socket),this.trans=lichess.trans(e.i18n),this.noarg=this.trans.noarg,setTimeout(this.delayedInit,200),setTimeout(this.showExpiration,350),(null===(o=document.referrer)||void 0===o?void 0:o.includes("/serviceWorker."))||setTimeout(this.showYourMoveNotification,500),lichess.pubsub.on("jump",(e=>{this.jump(parseInt(e)),this.redraw()})),lichess.pubsub.on("sound_set",(e=>{this.music||"music"!==e||lichess.loadScript("javascripts/music/play.js").then((()=>{this.music=lichess.playMusic()})),this.music&&"music"!==e&&(this.music=void 0)})),lichess.pubsub.on("zen",(()=>{if(this.isPlaying()){const e=!$("body").hasClass("zen");$("body").toggleClass("zen",e),window.dispatchEvent(new Event("resize")),Ke(e)}})),this.isPlaying()&&ae(this)}clearJust(){this.justDropped=void 0,this.justCaptured=void 0,this.preDrop=void 0}}function fo(e,t){return(e/Math.pow(10,t)).toFixed(t).substr(2)}function mo(e){return"<b>"+e+"</b>"}function go(e,t,o,n,r){const s=e.millisOf(o),i=e=>{e.innerHTML=function(e,t){const o=new Date(t),n=fo(o.getUTCMinutes(),2),r=fo(o.getSeconds(),2);let s,i="";if(t>=864e5){const t=o.getUTCDate()-1;s=o.getUTCHours(),i+=(1===t?e("oneDay"):e.plural("nbDays",t))+" ",0!==s&&(i+=e.plural("nbHours",s))}else t>=36e5?(s=o.getUTCHours(),i+=mo(fo(s,2))+":"+mo(n)):i+=mo(n)+":"+mo(r);return i}(t,s)},a=e.root.data.player.color===o;return f("div.rclock.rclock-correspondence.rclock-"+n,{class:{outoftime:s<=0,running:r===o}},[e.data.showBar?f("div.bar",[f("span",{attrs:{style:`width: ${e.timePercent(o)}%`}})]):null,f("div.time",{hook:{insert:e=>i(e.elm),postpatch:(e,t)=>i(t.elm)}}),a?null:Nt(e.root)])}var vo=o(n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});let o="init";t.default=function(){return"string"==typeof o&&("init"==o&&(window.addEventListener("resize",(()=>{o="rec"})),navigator.userAgent.indexOf("Edge/")>-1&&requestAnimationFrame((()=>{o="rec"}))),o=!!getComputedStyle(document.body).getPropertyValue("--col1")),o}})));const bo="u8t",yo="i5z".toUpperCase(),wo=qe(100,((e,t)=>window.requestAnimationFrame((()=>{if(t.data.steps.length<7)return;let o=void 0;if(t.ply<3)o=0;else if(t.ply==le(t.data))o=99999;else{const t=e.querySelector(".a1t");t&&(o=vo()?t.offsetLeft-e.offsetWidth/2+t.offsetWidth/2:t.offsetTop-e.offsetHeight/2+t.offsetHeight/2)}"number"==typeof o&&(99999==o?e.scrollLeft=e.scrollTop=o:vo()?e.scrollLeft=o:e.scrollTop=o)}))));function ko(e,t,o){return e?f(bo,{class:{a1t:e.ply===t}},"P"===e.san[0]?e.san.slice(1):e.san):o?f(bo,"…"):void 0}function Po(e){let t;if(pe.finished(e.data))switch(e.data.game.winner){case"white":t="1-0";break;case"black":t="0-1";break;default:t="½-½"}if(t||pe.aborted(e.data)){const o=e.data.game.winner;return f("div.result-wrap",[f("p.result",t||""),f("p.status",{hook:A((()=>{e.autoScroll?e.autoScroll():setTimeout((()=>e.autoScroll()),200)}))},[mt(e),o?" • "+e.noarg(o+"IsVictorious"):""])])}}function Mo(e){const t=e.data.forecastCount;return me.userAnalysable(e.data)?f("a.fbt.analysis",{class:{text:!!t},attrs:{title:e.noarg("analysis"),href:yt.game(e.data,e.data.player.color)+"/analysis#"+e.ply,"data-icon":"A"}},t?[""+t]:[]):void 0}function To(e){const t=e.data,o=ce(t),n=le(t);return f("div.buttons",{hook:L("mousedown",(o=>{const n=o.target,r=parseInt(n.getAttribute("data-ply")||"");if(isNaN(r)){"flip"===(n.getAttribute("data-act")||n.parentNode.getAttribute("data-act"))&&(t.tv?location.href="/tv/"+t.tv.channel+(t.tv.flip?"":"?flip=1"):t.player.spectator?location.href=yt.game(t,t.opponent.color):e.flipNow())}else e.userJump(r)}),e.redraw)},[f("button.fbt.flip",{class:{active:e.flip},attrs:{title:e.noarg("flipBoard"),"data-act":"flip","data-icon":"B"}}),...[["W",o],["Y",e.ply-1],["X",e.ply+1],["V",n]].map(((t,r)=>{const s=e.ply!==t[1]&&t[1]>=o&&t[1]<=n;return f("button.fbt",{class:{glowing:3===r&&e.isLate()},attrs:{disabled:!s,"data-icon":t[0],"data-ply":s?t[1]:"-"}})})),Mo(e)||f("div.noop")])}function Co(e,t){return me.playable(e)&&0===e.game.turns&&!e.player.spectator?f("div.message",_(""),[f("div",[t("white"===e.player.color?"youPlayTheWhitePieces":"youPlayTheBlackPieces"),..."white"===e.player.color?[f("br"),f("strong",t("itsYourTurn"))]:[]])]):null}function xo(e,t,o,n){return n?null:f("button.fbt",{attrs:{disabled:n,"data-icon":o,"data-ply":e.ply+t},hook:L("mousedown",(o=>{o.preventDefault(),e.userJump(e.ply+t),e.redraw()}))})}function So(e){const t=e.data,o=e.replayEnabledByPref()&&f("l4x",{hook:A((t=>{t.addEventListener("mousedown",(t=>{let o=t.target,n=-2;if(o.tagName===bo.toUpperCase())for(;o=o.previousSibling;)if(n++,o.tagName===yo){e.userJump(2*parseInt(o.textContent||"")+n),e.redraw();break}})),e.autoScroll=()=>wo(t,e),e.autoScroll(),window.addEventListener("load",e.autoScroll),window.addEventListener("blur",(()=>$(bo).first().append("<j>")),{once:!0})}))},function(e){const t=e.data.steps,o=ce(e.data);if(void 0===le(e.data))return[];const n=[];let r=1;o%2==1&&(n.push([null,t[1]]),r=2);for(let a=r;a<t.length;a+=2)n.push([t[a],t[a+1]]);const s=[],i=e.ply;for(let a=0;a<n.length;a++)s.push(f("i5z",a+1+"")),s.push(ko(n[a][0],i,!0)),s.push(ko(n[a][1],i,!1));return s.push(Po(e)),s}(e));return e.nvui?void 0:f("rm6",[To(e),Co(t,e.trans.noarg)||(o?vo()?f("div.col1-moves",[xo(e,-1,"Y",e.ply==ce(t)),o,xo(e,1,"X",e.ply==le(t))]):o:Po(e))])}let Oo=!1;function _o(e){const t=me.playable(e.data)&&e.data.expiration;if(!t)return;const o=Math.max(0,t.movedAt-Date.now()+t.millisToMove),n=Math.floor(o/1e3),r=me.isPlayerTurn(e.data),s=r&&o<8e3;!Oo&&s&&(lichess.sound.play("lowTime"),Oo=!0);return f("div.expiration.expiration-"+(r!=e.flip?"bottom":"top"),{class:{emerg:s,"bar-glider":r}},e.trans.vdomPlural("nbSecondsToPlayTheFirstMove",n,f("strong",""+n)))}function jo(e,t){const o=e.playerAt(t);return e.nvui?void 0:o.ai?f("div.user-link.online.ruser.ruser-"+t,[f("i.line"),f("name",io(e,o.ai))]):function(e,t,o){const n=e.data,r=t.user,s=r?r.perfs[n.game.perf]:null,i=t.rating?t.rating:s&&s.rating,a=t.ratingDiff,c=0===a?f("span","±0"):a&&a>0?f("good","+"+a):a&&a<0?f("bad","−"+-a):void 0;if(r){const n=!t.onGame&&e.firstSeconds&&r.online;return f(`div.ruser-${o}.ruser.user-link`,{class:{online:t.onGame,offline:!t.onGame,long:r.username.length>16,connecting:n}},[f("i.line"+(r.patron?".patron":""),{attrs:{title:n?"Connecting to the game":t.onGame?"Joined the game":"Left the game"}}),f("a.text.ulpt",{attrs:{"data-pt-pos":"s",href:"/@/"+r.username,target:e.isPlaying()?"_blank":"_self"}},r.title?[f("span.utitle","BOT"==r.title?{attrs:{"data-bot":!0}}:{},r.title)," ",r.username]:[r.username]),i?f("rating",i+(t.provisional?"?":"")):null,c,t.engine?f("span",{attrs:{"data-icon":"j",title:e.noarg("thisAccountViolatedTos")}}):null])}const l=!t.onGame&&e.firstSeconds;return f(`div.ruser-${o}.ruser.user-link`,{class:{online:t.onGame,offline:!t.onGame,connecting:l}},[f("i.line",{attrs:{title:l?"Connecting to the game":t.onGame?"Joined the game":"Left the game"}}),f("name",t.name||"Anonymous")])}(e,o,t)}const Ao=e=>e.loading||e.redirecting,Lo=()=>f("i.ddloader"),Do=(e,t)=>[So(e),t.find((e=>!!e))?f("div.rcontrols",t):null],Eo=e=>Do(e,[Ao(e)?Lo():Dt(e)||Et(e)||$t(e)]),No=e=>Do(e,[Ao(e)?Lo():me.playable(e.data)?void 0:Bt(e)]),$o=e=>{const t=e.data,o=Ao(e),n=function(e){return e.moveToSubmit||e.dropToSubmit?f("div.negotiation.move-confirm",[f("p",e.noarg("confirmMove")),jt(e,"confirm-yes",(()=>e.submitMove(!0))),At(e,(()=>e.submitMove(!1)),"cancel")]):void 0}(e),r=o||n?[]:[me.abortable(t)?kt(e,void 0,"L","abortGame","abort"):kt(e,me.takebackable,"i","proposeATakeback","takeback-yes",e.takebackYes),e.drawConfirm?Ct(e):kt(e,e.canOfferDraw,"2","offerDraw","draw-yes",(()=>e.offerDraw(!0))),e.resignConfirm?Tt(e):kt(e,me.resignable,"b","resign","resign",(()=>e.resign(!0))),Mo(e)],s=o?[Lo()]:n?[n]:[Pt(e),xt(e),St(e),Ot(e),_t(e),Lt(e)];return[So(e),f("div.rcontrols",[...s,f("div.ricons",{class:{confirm:!(!e.drawConfirm&&!e.resignConfirm)}},r)])]};function Bo(e,t){const o=e.playerAt(t);return e.clock?function(e,t,o){const n=e.clock,r=n.millisOf(t.color),s=e.data.player.color===t.color,i=t.color===n.times.activeColor,a=e=>{const o=n.elements[t.color],r=n.millisOf(t.color),s=t.color===n.times.activeColor;o.time=e,o.clock=e.parentElement,e.innerHTML=zt(r,n.showTenths(r),s,n.opts.nvui)},c={insert:e=>a(e.elm),postpatch:(e,t)=>a(t.elm)};return f("div.rclock.rclock-"+o,{class:{outoftime:r<=0,running:i,emerg:r<n.emergMs}},n.opts.nvui?[f("div.time",{attrs:{role:"timer"},hook:c})]:[n.showBar&&me.bothPlayersHavePlayed(e.data)?Ht(e,t.color):void 0,f("div.time",{attrs:{title:t.color+" clock"},class:{hour:r>36e5},hook:c}),Ft(e,t.color,o),s?Gt(e):Nt(e),Ut(e,t.color,o)])}(e,o,t):e.data.correspondence&&e.data.game.turns>1?go(e.corresClock,e.trans,o.color,t,e.data.game.player):function(e,t,o){const n=e.data;if(!pe.finished(n)&&!pe.aborted(n))return f("div.rclock.rclock-turn.rclock-"+o,[n.game.player===t?f("div.rclock-turn__text",n.player.spectator?e.trans(n.game.player+"Plays"):e.trans(n.game.player===n.player.color?"yourTurn":"waitingForOpponent")):null])}(e,o.color,t)}const Ro=e=>[f("div.round__app__table"),_o(e),jo(e,"top"),...e.data.player.spectator?No(e):me.playable(e.data)?$o(e):Eo(e),jo(e,"bottom"),Bo(e,"top"),Bo(e,"bottom")];var Io=n((function(e,t){let o;Object.defineProperty(t,"__esModule",{value:!0}),t.needsBoardHeightFix=t.bindChessgroundResizeOnce=t.fixMainBoardHeight=t.runner=void 0,t.runner=(e,t=100)=>{let o;const n=Ie.default(t,(()=>{requestAnimationFrame((()=>{e(),o&&clearTimeout(o),o=setTimeout(n,500)}))}));n()},t.fixMainBoardHeight=e=>{const t=e.querySelector(".main-board");if(t){const e=t.offsetWidth;o!=e&&(o=e,t.style.height=e+"px",t.querySelector(".cg-wrap").style.height=e+"px",document.body.dispatchEvent(new Event("chessground.resize")))}};let n=!1;t.bindChessgroundResizeOnce=e=>{n||(n=!0,document.body.addEventListener("chessground.resize",e))},t.needsBoardHeightFix=()=>{if(window.chrome)return!1;const e=navigator.userAgent.split("Firefox/");return!e[1]||parseInt(e[1])<61}}));function qo(e){if(!Io.needsBoardHeightFix())return;const t=()=>Io.fixMainBoardHeight(e);Io.runner(t),Io.bindChessgroundResizeOnce(t)}const zo=["mousedown","touchstart"];function Ho(e,t,o){const n=ue(e.data,e.ply);if(!n.crazy)return;const r=e.justDropped,s=e.preDrop,i=n.crazy.pockets["white"===t?0:1],a=o===(e.flip?"top":"bottom")&&!e.replaying()&&e.isPlaying(),c=t===e.data.player.color,l=e.justCaptured,d=l&&(l.promoted?"pawn":l.role);return f("div.pocket.is2d.pocket-"+o,{class:{usable:a},hook:A((t=>zo.forEach((n=>t.addEventListener(n,(t=>{o===(e.flip?"top":"bottom")&&0==oo.length&&function(e,t){if(void 0!==t.button&&0!==t.button)return;if(e.replaying()||!e.isPlaying())return;const o=t.target,n=o.getAttribute("data-role"),r=o.getAttribute("data-color"),s=o.getAttribute("data-nb");n&&r&&"0"!==s&&(t.stopPropagation(),t.preventDefault(),Pe.dragNewPiece(e.chessground.state,{color:r,role:n},t))}(e,t)}))))))},Jt.map((e=>{let o=i[e]||0;return c&&(r===e&&o--,d===e&&o++),f("div.pocket-c1",f("div.pocket-c2",f("piece."+e+"."+t,{class:{premove:c&&s===e},attrs:{"data-role":e,"data-color":t,"data-nb":o}})))})))}function Ko(e,t,o,n){const r=[];let s,i;for(s in e)if(e[s]>0){const t=[];for(i=0;i<e[s];i++)t.push(f("mpiece."+s));r.push(f("div",t))}if(n)for(i=0;i<n;i++)r.push(f("div",f("mpiece.king")));return t>0&&r.push(f("score","+"+t)),f("div.material.material-"+o,r)}const Fo={white:{},black:{}};function Go(e){const t=e.data,o=e.chessground&&e.chessground.state,n=t[e.flip?"player":"opponent"].color,r=t[e.flip?"opponent":"player"].color;let s,i=0;if(t.pref.showCaptured){const t=o?o.pieces:be.read(ue(e.data,e.ply).fen);s=function(e){const t={white:{king:0,queen:0,rook:0,bishop:0,knight:0,pawn:0},black:{king:0,queen:0,rook:0,bishop:0,knight:0,pawn:0}};for(const o of e.values()){const e=t[S.opposite(o.color)];e[o.role]>0?e[o.role]--:t[o.color][o.role]++}return t}(t),i=function(e){let t=0;for(const o of e.values())t+=O[o.role]*("white"===o.color?1:-1);return t}(t)*("white"===r?1:-1)}else s=Fo;const a=t.player.checks||t.opponent.checks?function(e,t){const o=Object.assign({},E);for(let n of e){if(t<n.ply)break;n.check&&(n.ply%2==1?o.white++:o.black++)}return o}(e.data.steps,e.ply):E;return e.nvui?e.nvui.render(e):f("div.round__app.variant-"+t.game.variant.key,{class:{"move-confirm":!(!e.moveToSubmit&&!e.dropToSubmit)},hook:A(qo)},[f("div.round__app__board.main-board"+(e.data.pref.blindfold?".blindfold":""),{hook:"ontouchstart"in window?void 0:L("wheel",(t=>function(e,t){return!!e.isPlaying()||(t.preventDefault(),t.deltaY>0?ho(e):t.deltaY<0&&uo(e),e.redraw(),!1)}(e,t)),void 0,!1)},[Be(e),ut(e)]),Ho(e,n,"top")||Ko(s[n],-i,"top",a[n]),...Ro(e),Ho(e,r,"bottom")||Ko(s[r],i,"bottom",a[r]),e.keyboardMove?so(e.keyboardMove):null])}const Uo=T([B,i]);return window.LichessChat=J,window.Chessground=Ae.Chessground,e.app=function(e){let t,o;function n(){t=Uo(t,Go(o))}o=new po(e,n);const r=Go(o);return e.element.innerHTML="",t=Uo(e.element,r),window.addEventListener("resize",n),o.isPlaying()&&Q(),{socketReceive:o.socket.receive,moveOn:o.moveOn}},e.boot=function(e){var t;const o=document.querySelector(".round__app"),n=e.data;let r;function s(){n.tournament&&$(".game__tournament .clock").each((function(){$(this).clock({time:parseFloat($(this).data("time"))})}))}function i(e){if(!e.player.spectator)return e.steps.length<4?"start":e.game.status.id>=30?"end":void 0}n.tournament&&$("body").data("tournament-id",n.tournament.id),lichess.socket=new lichess.StrongSocket(n.url.socket,n.player.version,{params:{userTv:n.userTv&&n.userTv.id},receive(e,t){r.socketReceive(e,t)},events:{tvSelect(e){n.tv&&n.tv.channel==e.channel?lichess.reload():$(".tv-channels ."+e.channel+" .champion").html(e.player?[e.player.title,e.player.name,e.player.rating].filter((e=>e)).join("&nbsp"):"Anonymous")},end(){c.text(`${n.tv?"/tv":""}/${n.game.id}/${n.player.color}/sides`).then((e=>{const t=$(e),o=t.find(".game__meta");o.length&&$(".game__meta").replaceWith(o),$(".crosstable").replaceWith(t.find(".crosstable")),s(),lichess.contentLoaded()}))},tourStanding(t){var o,n,r;(null===(o=e.chat)||void 0===o?void 0:o.plugin)&&(null===(r=null===(n=e.chat)||void 0===n?void 0:n.instance)||void 0===r||r.then((o=>{e.chat.plugin.set(t),o.redraw()})))}}}),e.element=o,e.socketSend=lichess.socket.send,r=window.LichessRound.app(e);const a=e.chat;var l,d;a&&((null===(t=n.tournament)||void 0===t?void 0:t.top)?(a.plugin=(l=n.tournament.top,d=n.tournament.team,{set(e){l=e},tab:{key:"tourStanding",name:e.i18n.standing},view:()=>f("div",{hook:A((e=>{lichess.loadCssPath("round.tour-standing")}))},[d?f("h3.text",{attrs:{"data-icon":"f"}},d.name):null,f("table.slist",[f("tbody",l.map(((e,t)=>f("tr."+e.n,[f("td.name",[f("span.rank",""+(t+1)),f("a.user-link.ulpt",{attrs:{href:"/@/"+e.n}},(e.t?e.t+" ":"")+e.n)]),f("td.total",e.f?{class:{"is-gold":!0},attrs:{"data-icon":"Q"}}:{},""+e.s)]))))])])}),a.alwaysEnabled=!0):n.simul||n.swiss||(a.preset=i(n),a.parseMoves=!0),a.noteId&&(a.noteAge||0)<10&&(a.noteText=""),a.instance=lichess.makeChat(a),n.tournament||n.simul||n.swiss||(e.onChange=e=>a.instance.then((t=>t.preset.setGroup(i(e)))))),s(),$(".round__now-playing .move-on input").on("change",r.moveOn.toggle).prop("checked",r.moveOn.get()).on("click","a",(()=>(lichess.unload.expected=!0,!0))),0===location.pathname.lastIndexOf("/round-next/",0)&&history.replaceState(null,"","/"+n.game.id),$("#zentog").on("click",(()=>lichess.pubsub.emit("zen"))),lichess.storage.make("reload-round-tabs").listen(lichess.reload)},e}({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment