Files
chess-3miz/client/assets/index-Cj8AUTlf.js
T
2026-10-15 11:17:29 +03:30

123 lines
26 KiB
JavaScript

(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))t(o);new MutationObserver(o=>{for(const e of o)if(e.type==="childList")for(const a of e.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&t(a)}).observe(document,{childList:!0,subtree:!0});function r(o){const e={};return o.integrity&&(e.integrity=o.integrity),o.referrerPolicy&&(e.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?e.credentials="include":o.crossOrigin==="anonymous"?e.credentials="omit":e.credentials="same-origin",e}function t(o){if(o.ep)return;o.ep=!0;const e=r(o);fetch(o.href,e)}})();function Z(n){const s=new URLSearchParams(location.search).get("host")??"*",r=o=>window.parent.postMessage({m3:1,...o},s);let t=0;return window.addEventListener("message",o=>{var a,f,h;if(o.source!==window.parent||s!=="*"&&o.origin!==s)return;const e=o.data;if(!(!e||e.m3!==1))switch(e.type){case"init":n.onInit(e),r({type:"ready"});break;case"state":n.onState(e.env);break;case"ack":(a=n.onAck)==null||a.call(n,e);break;case"view_changed":(f=n.onViewChanged)==null||f.call(n,e.view);break;case"cmd_failed":(h=n.onCmdFailed)==null||h.call(n,e.req_id,e.code);break}}),r({type:"loaded"}),{cmd(o,e={}){const a=++t;return r({type:"cmd",cmd_type:o,payload:e,req_id:a}),a},toast(o,e,a="info"){r({type:"toast",text_fa:o,text_en:e,kind:a})}}}const tt={k:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M22.5 11.63V6M20 8h5" stroke-linejoin="miter"/>
<path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#fff" stroke-linecap="butt" stroke-linejoin="miter"/>
<path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V23.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7z" fill="#fff"/>
<path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0"/>
</g>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M22.5 11.63V6M20 8h5" stroke="#fff" stroke-linejoin="miter"/>
<path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#2d3038" stroke-linecap="butt" stroke-linejoin="miter"/>
<path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V23.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7z" fill="#2d3038"/>
<path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0" stroke="#fff"/>
</g>
</svg>`},q:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<g fill="#fff" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm17 0a2 2 0 1 1-4 0 2 2 0 1 1 4 0z"/>
<path d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-13.5V25L7 14l2 12z" stroke-linecap="butt"/>
<path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 2-1 .5-2.5 0 0 0-1.5-1.5-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/>
<path d="M11 38.5a35 35 1 0 0 23 0" fill="none" stroke-linecap="butt"/>
<path d="M11 29a35 35 1 0 1 23 0M12.5 31.5h20M11.5 34.5a35 35 1 0 0 22 0M10.5 37.5a35 35 1 0 0 24 0" fill="none"/>
</g>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<g fill="#2d3038" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm17 0a2 2 0 1 1-4 0 2 2 0 1 1 4 0z"/>
<path d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-13.5V25L7 14l2 12z" stroke-linecap="butt"/>
<path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 2-1 .5-2.5 0 0 0-1.5-1.5-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/>
<path d="M11 38.5a35 35 1 0 0 23 0" fill="none" stroke="#fff" stroke-linecap="butt"/>
<path d="M11 29a35 35 1 0 1 23 0M12.5 31.5h20M11.5 34.5a35 35 1 0 0 22 0M10.5 37.5a35 35 1 0 0 24 0" fill="none" stroke="#fff"/>
</g>
</svg>`},r:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<g fill="#fff" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M9 39h27v-3H9v3zm3-3v-4.5h21V36H12zm2-4.5v-11h17v11H14z" stroke-linecap="butt"/>
<path d="M14 20.5h17M11 14h23l-2.5 6.5h-18L11 14z"/>
<path d="M12 10.5h4v3.5h-4zm7 0h7v3.5h-7zm10 0h4v3.5h-4z" stroke-linecap="butt"/>
<path d="M14 29.5v-1h17v1H14zm-1 3.5v-1h19v1H13z" fill="none"/>
</g>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<g fill="#2d3038" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M9 39h27v-3H9v3zm3-3v-4.5h21V36H12zm2-4.5v-11h17v11H14z" stroke-linecap="butt"/>
<path d="M14 20.5h17M11 14h23l-2.5 6.5h-18L11 14z"/>
<path d="M12 10.5h4v3.5h-4zm7 0h7v3.5h-7zm10 0h4v3.5h-4z" stroke-linecap="butt"/>
<path d="M14 29.5v-1h17v1H14zm-1 3.5v-1h19v1H13z" fill="none" stroke="#fff"/>
</g>
</svg>`},b:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<g fill="#fff">
<path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.35.49-2.32.47-3-.5 1.35-1.94 3-2 3-2z"/>
<path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/>
<path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/>
</g>
<path d="M17.5 26h10M15 30h15M22.5 15.5v5M20 18h5" stroke-linejoin="miter"/>
</g>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<g fill="#2d3038">
<path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.35.49-2.32.47-3-.5 1.35-1.94 3-2 3-2z"/>
<path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/>
<path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/>
</g>
<path d="M17.5 26h10M15 30h15M22.5 15.5v5M20 18h5" stroke="#fff" stroke-linejoin="miter"/>
</g>
</svg>`},n:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" fill="#fff"/>
<path d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,7.4 17.03,5.16 20,6 C 22,6.5 21.84,7.85 22,10 z" fill="#fff"/>
<path d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" fill="#222" stroke="#222"/>
<path d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" fill="#222" stroke="#222"/>
</g>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" fill="#2d3038"/>
<path d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,7.4 17.03,5.16 20,6 C 22,6.5 21.84,7.85 22,10 z" fill="#2d3038"/>
<path d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" fill="#fff" stroke="#fff"/>
<path d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" fill="#fff" stroke="#fff"/>
</g>
</svg>`},p:{w:`<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" fill="#fff" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>`,b:`<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" fill="#2d3038" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>`}};function S(n,s){var r;return!n||!s?"":((r=tt[n])==null?void 0:r[s])??""}class et{constructor(s){this.particles=[],this.shockwaves=[],this.animId=null,this.lastTime=0,this.canvas=s,this.ctx=s.getContext("2d"),this.resize(),window.addEventListener("resize",()=>this.resize()),this.startLoop()}resize(){var t,o,e;const s=(t=this.canvas.parentElement)==null?void 0:t.getBoundingClientRect();if(!s)return;const r=window.devicePixelRatio||1;this.canvas.width=Math.round(s.width*r),this.canvas.height=Math.round(s.height*r),this.canvas.style.width=`${s.width}px`,this.canvas.style.height=`${s.height}px`,(e=(o=this.ctx).resetTransform)==null||e.call(o),this.ctx.scale(r,r)}startLoop(){if(this.animId)return;const s=r=>{const t=this.lastTime?Math.min((r-this.lastTime)/1e3,.1):.016;this.lastTime=r,this.update(t),this.render(),this.animId=requestAnimationFrame(s)};this.animId=requestAnimationFrame(s)}update(s){for(let r=this.shockwaves.length-1;r>=0;r--){const t=this.shockwaves[r];t.radius+=(t.maxRadius-t.radius)*12*s,t.alpha-=t.decay*s,(t.alpha<=0||t.radius>=t.maxRadius*.98)&&this.shockwaves.splice(r,1)}for(let r=this.particles.length-1;r>=0;r--){const t=this.particles[r];t.x+=t.vx*s,t.y+=t.vy*s,t.vx*=Math.pow(t.drag,s*60),t.vy*=Math.pow(t.drag,s*60),t.vy+=t.gravity*s,t.vRot&&t.rotation!==void 0&&(t.rotation+=t.vRot*s),t.alpha-=t.decay*s,t.alpha<=0&&this.particles.splice(r,1)}}render(){const s=this.canvas.width/(window.devicePixelRatio||1),r=this.canvas.height/(window.devicePixelRatio||1);this.ctx.clearRect(0,0,s,r);for(const t of this.shockwaves)this.ctx.save(),this.ctx.beginPath(),this.ctx.arc(t.x,t.y,Math.max(1,t.radius),0,Math.PI*2),this.ctx.strokeStyle=t.color,this.ctx.globalAlpha=Math.max(0,t.alpha),this.ctx.lineWidth=t.lineWidth,this.ctx.stroke(),this.ctx.restore();for(const t of this.particles){if(this.ctx.save(),this.ctx.globalAlpha=Math.max(0,t.alpha),this.ctx.fillStyle=t.color,t.shape==="rect"||t.shape==="spark"){this.ctx.translate(t.x,t.y),t.rotation!==void 0&&this.ctx.rotate(t.rotation);const o=t.size||t.radius*2;t.shape==="spark"?this.ctx.fillRect(-o,-o*.25,o*2,o*.5):this.ctx.fillRect(-o*.5,-o*.5,o,o)}else this.ctx.beginPath(),this.ctx.arc(t.x,t.y,Math.max(.5,t.radius),0,Math.PI*2),this.ctx.fill();this.ctx.restore()}}captureImpact(s,r,t="w"){this.shockwaves.push({x:s,y:r,radius:4,maxRadius:48,color:t==="w"?"rgba(255, 235, 180, 0.9)":"rgba(120, 140, 180, 0.9)",alpha:.9,decay:2.8,lineWidth:3});const o=t==="w"?["#ffffff","#fef08a","#f59e0b","#fbbf24"]:["#94a3b8","#cbd5e1","#64748b","#38bdf8"],e=18;for(let a=0;a<e;a++){const f=Math.PI*2*a/e+(Math.random()-.5)*.5,h=120+Math.random()*220;this.particles.push({x:s,y:r,vx:Math.cos(f)*h,vy:Math.sin(f)*h,radius:2+Math.random()*2.5,color:o[Math.floor(Math.random()*o.length)],alpha:1,decay:1.8+Math.random()*1.4,gravity:80,drag:.92,shape:"spark",size:3+Math.random()*3,rotation:f})}for(let a=0;a<6;a++){const f=Math.random()*Math.PI*2,h=25+Math.random()*45;this.particles.push({x:s+(Math.random()-.5)*12,y:r+(Math.random()-.5)*12,vx:Math.cos(f)*h,vy:Math.sin(f)*h,radius:4+Math.random()*6,color:"rgba(200, 200, 210, 0.4)",alpha:.6,decay:1.2,gravity:-10,drag:.88,shape:"circle"})}}landingPuff(s,r){for(let t=0;t<8;t++){const o=20+Math.random()*40;this.particles.push({x:s+(Math.random()-.5)*10,y:r+10,vx:(Math.random()-.5)*o,vy:-Math.random()*20,radius:2.5+Math.random()*3,color:"rgba(220, 220, 230, 0.35)",alpha:.5,decay:2,gravity:15,drag:.85,shape:"circle"})}}promotionBurst(s,r){this.shockwaves.push({x:s,y:r,radius:6,maxRadius:60,color:"rgba(251, 191, 36, 0.95)",alpha:1,decay:2,lineWidth:4});const t=["#fbbf24","#fef08a","#60a5fa","#a78bfa","#ffffff"];for(let o=0;o<28;o++){const e=Math.random()*Math.PI*2,a=60+Math.random()*180;this.particles.push({x:s,y:r,vx:Math.cos(e)*a,vy:Math.sin(e)*a-50,radius:2+Math.random()*3,color:t[Math.floor(Math.random()*t.length)],alpha:1,decay:1.2+Math.random()*1,gravity:-30,drag:.94,shape:"rect",size:3+Math.random()*4,rotation:Math.random()*Math.PI*2,vRot:(Math.random()-.5)*10})}}victoryConfetti(){const s=this.canvas.width/(window.devicePixelRatio||1),r=this.canvas.height/(window.devicePixelRatio||1),t=["#ef4444","#3b82f6","#10b981","#f59e0b","#8b5cf6","#ec4899","#ffffff","#fbbf24"];for(let o=0;o<90;o++){const e=s*.5+(Math.random()-.5)*100,a=r*.45+(Math.random()-.5)*50,f=-Math.PI*.5+(Math.random()-.5)*Math.PI*.85,h=180+Math.random()*360;this.particles.push({x:e,y:a,vx:Math.cos(f)*h,vy:Math.sin(f)*h,radius:3+Math.random()*3,color:t[Math.floor(Math.random()*t.length)],alpha:1,decay:.4+Math.random()*.3,gravity:160,drag:.97,shape:"rect",size:5+Math.random()*5,rotation:Math.random()*Math.PI*2,vRot:(Math.random()-.5)*12})}}}function _(n){return{f:n.charCodeAt(0)-97,r:parseInt(n[1],10)-1}}function w(n,s){return String.fromCharCode(97+n)+(s+1)}function A(n,s,r){const t=new Map;for(const i of s)t.set(i.square,i);const o=t.get(n);if(!o||!o.type||o.color!==r)return[];const{f:e,r:a}=_(n),f=[],h=(i,p)=>{if(i<0||i>7||p<0||p>7)return!1;const g=w(i,p),c=t.get(g);return!c||!c.color?(f.push({target:g,isCapture:!1}),!0):(c.color!==r&&f.push({target:g,isCapture:!0}),!1)};switch(o.type){case"p":{const i=r==="w"?1:-1,p=r==="w"?1:6,g=w(e,a+i),c=t.get(g);if(c&&!c.color&&(f.push({target:g,isCapture:!1}),a===p)){const d=w(e,a+i*2),u=t.get(d);u&&!u.color&&f.push({target:d,isCapture:!1})}for(const d of[-1,1])if(e+d>=0&&e+d<=7){const u=w(e+d,a+i),v=t.get(u);v&&v.color&&v.color!==r&&f.push({target:u,isCapture:!0})}break}case"n":{const i=[[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]];for(const[p,g]of i){const c=e+p,d=a+g;if(c>=0&&c<=7&&d>=0&&d<=7){const u=w(c,d),v=t.get(u);!v||!v.color?f.push({target:u,isCapture:!1}):v.color!==r&&f.push({target:u,isCapture:!0})}}break}case"b":{const i=[[-1,-1],[-1,1],[1,-1],[1,1]];for(const[p,g]of i){let c=e+p,d=a+g;for(;h(c,d);)c+=p,d+=g}break}case"r":{const i=[[-1,0],[1,0],[0,-1],[0,1]];for(const[p,g]of i){let c=e+p,d=a+g;for(;h(c,d);)c+=p,d+=g}break}case"q":{const i=[[-1,-1],[-1,1],[1,-1],[1,1],[-1,0],[1,0],[0,-1],[0,1]];for(const[p,g]of i){let c=e+p,d=a+g;for(;h(c,d);)c+=p,d+=g}break}case"k":{for(let p=-1;p<=1;p++)for(let g=-1;g<=1;g++){if(p===0&&g===0)continue;const c=e+p,d=a+g;if(c>=0&&c<=7&&d>=0&&d<=7){const u=w(c,d),v=t.get(u);!v||!v.color?f.push({target:u,isCapture:!1}):v.color!==r&&f.push({target:u,isCapture:!0})}}const i=r==="w"?0:7;if(a===i&&e===4){const p=t.get(w(5,i)),g=t.get(w(6,i)),c=t.get(w(7,i));p&&!p.color&&g&&!g.color&&(c==null?void 0:c.type)==="r"&&c.color===r&&f.push({target:w(6,i),isCapture:!1});const d=t.get(w(3,i)),u=t.get(w(2,i)),v=t.get(w(1,i)),m=t.get(w(0,i));d&&!d.color&&u&&!u.color&&v&&!v.color&&(m==null?void 0:m.type)==="r"&&m.color===r&&f.push({target:w(2,i),isCapture:!1})}break}}return f.filter(i=>!ot(n,i.target,s,r))}function ot(n,s,r,t){const o=r.map(c=>{if(c.square===n)return{square:n,type:null,color:null};if(c.square===s){const d=r.find(u=>u.square===n);return{square:s,type:(d==null?void 0:d.type)??null,color:t}}return{...c}}),e=o.find(c=>c.type==="k"&&c.color===t);if(!e)return!1;const{f:a,r:f}=_(e.square),h=t==="w"?"b":"w",i=new Map;for(const c of o)i.set(c.square,c);const p=[[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]];for(const[c,d]of p){const u=a+c,v=f+d;if(u>=0&&u<=7&&v>=0&&v<=7){const m=i.get(w(u,v));if(m&&m.color===h&&m.type==="n")return!0}}const g=h==="w"?1:-1;for(const c of[-1,1]){const d=a-c,u=f-g;if(d>=0&&d<=7&&u>=0&&u<=7){const v=i.get(w(d,u));if(v&&v.color===h&&v.type==="p")return!0}}for(const[c,d]of[[-1,0],[1,0],[0,-1],[0,1]]){let u=a+c,v=f+d;for(;u>=0&&u<=7&&v>=0&&v<=7;){const m=i.get(w(u,v));if(m&&m.color){if(m.color===h&&(m.type==="r"||m.type==="q"))return!0;break}u+=c,v+=d}}for(const[c,d]of[[-1,-1],[-1,1],[1,-1],[1,1]]){let u=a+c,v=f+d;for(;u>=0&&u<=7&&v>=0&&v<=7;){const m=i.get(w(u,v));if(m&&m.color){if(m.color===h&&(m.type==="b"||m.type==="q"))return!0;break}u+=c,v+=d}}for(let c=-1;c<=1;c++)for(let d=-1;d<=1;d++){if(c===0&&d===0)continue;const u=a+c,v=f+d;if(u>=0&&u<=7&&v>=0&&v<=7){const m=i.get(w(u,v));if(m&&m.color===h&&m.type==="k")return!0}}return!1}let l=null,H=null,E=null,C=null,k="",y=[],x=null,R=null,V=!1;const b=(n,s)=>(E==null?void 0:E.locale)==="en"?s:n,T=Z({onInit(n){E=n,document.documentElement.lang=n.locale,document.documentElement.dir=n.dir,document.getElementById("board-grid")||O(),z()},onState(n){n.t==="snap"&&(document.getElementById("board-grid")||O(),H=l,l=n.body,st(H,l),l.turn!==l.me&&(k="",y=[],x=null),z())},onAck(n){n.status==="rejected"&&T.toast("حرکت پذیرفته نشد","Move not accepted","warn")}});function st(n,s){var f;if(!n||!s||!C)return;const r=new Map(n.board.map(h=>[h.square,h])),t=new Map(s.board.map(h=>[h.square,h]));let o="",e="",a=null;for(const[h,i]of t.entries()){const p=r.get(h);p&&(p.color&&!i.color?o=h:i.color&&(!p.color||p.color!==i.color||p.type!==i.type)&&(e=h,p.color&&p.color!==i.color&&(a=p)))}if(o&&e){R={from:o,to:e};const h=document.querySelector(`[data-square="${e}"]`);if(h){const i=h.getBoundingClientRect(),p=(f=document.getElementById("vfx-canvas"))==null?void 0:f.getBoundingClientRect();if(p){const c=i.left-p.left+i.width/2,d=i.top-p.top+i.height/2;a?C.captureImpact(c,d,a.color):C.landingPuff(c,d)}const g=h.querySelector(".piece-wrapper");g&&(g.classList.remove("anim-land"),g.offsetWidth,g.classList.add("anim-land"))}}s.phase==="over"&&s.winner!==null&&!V&&(V=!0,setTimeout(()=>C==null?void 0:C.victoryConfetti(),350))}function O(){const n=document.getElementById("app");n.innerHTML=`
<div id="top-bar" class="player-bar"></div>
<div class="board-container">
<canvas id="vfx-canvas"></canvas>
<div id="board-grid" class="board-grid"></div>
</div>
<div id="bottom-bar" class="player-bar"></div>
<div id="modal-container"></div>
`;const s=document.getElementById("vfx-canvas");C=new et(s);const r=document.getElementById("board-grid");r.addEventListener("click",t=>{const o=t.target.closest(".cell");o&&o.dataset.square&&!o.disabled&&it(o.dataset.square)});for(let t=0;t<64;t++){const o=document.createElement("button");o.className="cell",o.dataset.index=String(t),r.appendChild(o)}}function z(){var m;if(!l)return;const n=l.me,s=n!=null&&l.players[n]!==void 0;let r,t;s?(r=l.players[n],t=l.players.find(M=>M.seat!==n)||l.players[1-n]):(r=l.players.find(M=>M.color==="w")||l.players[0],t=l.players.find(M=>M.color==="b")||l.players[1]);const o=(r==null?void 0:r.color)||"w",e=o==="b",a=r?l.turn===r.seat&&l.phase==="play":!1,f=t?l.turn===t.seat&&l.phase==="play":!1;N("top-bar",t,f,!1),N("bottom-bar",r,a,s);const h=new Map;for(const M of l.board)h.set(M.square,M);const i=e?[7,6,5,4,3,2,1,0]:[0,1,2,3,4,5,6,7],p=e?[0,1,2,3,4,5,6,7]:[7,6,5,4,3,2,1,0],g=document.getElementById("board-grid");if(!g)return;const c=g.children;let d=0;const u=l.phase==="play"&&l.turn===n,v=l.check&&l.phase==="play"?(m=l.board.find(M=>{var q;return M.type==="k"&&M.color===((q=l.players[l.turn])==null?void 0:q.color)}))==null?void 0:m.square:null;for(const M of p)for(const q of i){const B=String.fromCharCode(97+q)+(M+1),I=h.get(B)||{type:null,color:null},$=c[d++];$.dataset.square=B,$.dataset.color=I.color||"";const F=(q+M)%2===0?"dark":"light",j=k===B,W=R&&(R.from===B||R.to===B),D=v===B;$.className=`cell ${F}`+(j?" selected":"")+(W?" last-move":"")+(D?" in-check":"");const U=y.some(P=>P.target===B),K=y.some(P=>P.target===B&&P.isCapture);let L="";const Y=e?q===7:q===0,G=e?M===7:M===0;if(Y&&(L+=`<span class="coord-rank">${M+1}</span>`),G&&(L+=`<span class="coord-file">${String.fromCharCode(97+q)}</span>`),I.type&&I.color){const P=S(I.type,I.color),X=I.type==="n"&&j?" anim-knight":"";L+=`<div class="piece-wrapper${X}">${P}</div>`}K?L+='<div class="capture-ring"></div>':U&&(L+='<div class="move-dot"></div>'),$.innerHTML=L;const J=u&&!0&&I.color===o,Q=k?u:J;$.disabled=!Q}at()}function N(n,s,r,t){const o=document.getElementById(n);if(!o||!s||!l)return;o.className="player-bar"+(r?" active":"");const e=rt(s.color),a=nt(s.color),f=a>0?`<span class="advantage-score">+${a}</span>`:"",h=s.bot?'<span class="bot-tag">BOT</span>':"",i=t?`<span class="bot-tag you-tag">${b("شما","YOU")}</span>`:"",p=l.phase==="over"?l.winner===s.seat?b("برنده 🏆","Winner 🏆"):"":r?t?b("نوبت شماست","Your turn"):b("در حال تفکر…","Thinking…"):"";o.innerHTML=`
<div class="player-profile">
<div class="player-badge ${s.color}">
${s.color==="w"?"♔":"♚"}
</div>
<div class="player-meta">
<div class="player-name">${s.name} ${h} ${i}</div>
<div class="player-status">${p}</div>
</div>
</div>
<div class="captured-tray">
${e.map(g=>`<div class="mini-piece">${S(g.type,g.color)}</div>`).join("")}
${f}
</div>
`}function rt(n){if(!l)return[];const s=n==="w"?"b":"w",r={p:8,n:2,b:2,r:2,q:1},t={p:0,n:0,b:0,r:0,q:0};for(const e of l.board)e.color===s&&e.type&&t[e.type]!==void 0&&t[e.type]++;const o=[];for(const e of["q","r","b","n","p"]){const a=r[e]-(t[e]||0);for(let f=0;f<a;f++)o.push({square:"",type:e,color:s})}return o}function nt(n){if(!l)return 0;const s={p:1,n:3,b:3,r:5,q:9};let r=0,t=0;for(const o of l.board){if(!o.type||!o.color)continue;const e=s[o.type]||0;o.color===n?r+=e:t+=e}return r-t}function at(){var s,r,t;const n=document.getElementById("modal-container");if(!(!n||!l)){if(x){const o=l.me!==null&&l.me!==void 0?(s=l.players[l.me])==null?void 0:s.color:"w";n.innerHTML=`
<div class="modal-backdrop">
<div class="promo-card">
<div class="promo-title">${b("ارتقای پیاده به:","Promote pawn to:")}</div>
<div class="promo-options">
${["q","r","b","n"].map(e=>`
<button class="promo-piece-btn" data-promo="${e}" title="${e}">
${S(e,o)}
</button>
`).join("")}
</div>
<button class="promo-cancel-btn" data-cancel-promo="1">${b("لغو","Cancel")}</button>
</div>
</div>
`,n.querySelectorAll("[data-promo]").forEach(e=>{e.addEventListener("click",()=>{var f;const a=e.dataset.promo;if(x&&a){T.cmd("move",{from:x.from,to:x.to,promotion:a});const h=document.querySelector(`[data-square="${x.to}"]`);if(h){const i=h.getBoundingClientRect(),p=(f=document.getElementById("vfx-canvas"))==null?void 0:f.getBoundingClientRect();p&&(C==null||C.promotionBurst(i.left-p.left+i.width/2,i.top-p.top+i.height/2))}x=null,k="",y=[],z()}})}),(r=n.querySelector("[data-cancel-promo]"))==null||r.addEventListener("click",()=>{x=null,z()});return}if(l.phase==="over"){l.winner!==null&&(l.winner,l.me);const o=l.winner===null;let e="",a="";o?(e=l.result_reason==="stalemate"?b("پات — مساوی!","Stalemate — Draw!"):b("بازی مساوی شد","Draw!"),a=b("هیچ‌کدام از طرفین برنده نشد","No side achieved victory")):(e=`${(t=l.players[l.winner])==null?void 0:t.name} ${b("برنده شد! 🏆","Wins! 🏆")}`,a=l.result_reason==="checkmate"?b("با کیش و مات حریف","By checkmate"):l.result_reason==="abandoned"?b("به دلیل ترک حریف","By abandonment"):""),n.innerHTML=`
<div class="game-over-banner">
<div class="game-over-title">${e}</div>
<div class="game-over-subtitle">${a}</div>
</div>
`;return}n.innerHTML=""}}function it(n){var o;if(!l||l.phase!=="play"||x)return;const s=l.me;if(s==null||l.turn!==s)return;const r=(o=l.players[s])==null?void 0:o.color;if(!r)return;const t=l.board.find(e=>e.square===n);if(k){if(k===n){k="",y=[],z();return}if(t!=null&&t.color&&t.color===r){k=n;try{y=A(n,l.board,r)}catch{y=[]}z();return}const e=l.board.find(f=>f.square===k),a=r==="b"?"1":"8";if((e==null?void 0:e.type)==="p"&&n[1]===a){x={from:k,to:n},k="",y=[],z();return}T.cmd("move",{from:k,to:n}),k="",y=[],z()}else if(t&&t.color===r){k=n;try{y=A(n,l.board,r)}catch{y=[]}z()}}