chessboard-element
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
const t="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,e=(t,e,i=null)=>{for(;e!==i;){const i=e.nextSibling;t.removeChild(e),e=i}},i=`{{lit-${(Math.random()+"").slice(2)}}}`,s=`\x3c!--${i}--\x3e`,o=RegExp(`${i}|${s}`);class n{constructor(t,e){this.parts=[],this.element=e;const s=[],n=[],l=document.createTreeWalker(e.content,133,null,!1);let c=0,d=-1,p=0;const{strings:u,values:{length:f}}=t;for(;p<f;){const t=l.nextNode();if(null!==t){if(d++,1===t.nodeType){if(t.hasAttributes()){const e=t.attributes,{length:i}=e;let s=0;for(let t=0;t<i;t++)r(e[t].name,"$lit$")&&s++;for(;s-- >0;){const e=u[p],i=h.exec(e)[2],s=i.toLowerCase()+"$lit$",n=t.getAttribute(s);t.removeAttribute(s);const r=n.split(o);this.parts.push({type:"attribute",index:d,name:i,strings:r}),p+=r.length-1}}"TEMPLATE"===t.tagName&&(n.push(t),l.currentNode=t.content)}else if(3===t.nodeType){const e=t.data;if(e.indexOf(i)>=0){const i=t.parentNode,n=e.split(o),l=n.length-1;for(let e=0;e<l;e++){let s,o=n[e];if(""===o)s=a();else{const t=h.exec(o);null!==t&&r(t[2],"$lit$")&&(o=o.slice(0,t.index)+t[1]+t[2].slice(0,-5)+t[3]),s=document.createTextNode(o)}i.insertBefore(s,t),this.parts.push({type:"node",index:++d})}""===n[l]?(i.insertBefore(a(),t),s.push(t)):t.data=n[l],p+=l}}else if(8===t.nodeType)if(t.data===i){const e=t.parentNode;null!==t.previousSibling&&d!==c||(d++,e.insertBefore(a(),t)),c=d,this.parts.push({type:"node",index:d}),null===t.nextSibling?t.data="":(s.push(t),d--),p++}else{let e=-1;for(;-1!==(e=t.data.indexOf(i,e+1));)this.parts.push({type:"node",index:-1}),p++}}else l.currentNode=n.pop()}for(const t of s)t.parentNode.removeChild(t)}}const r=(t,e)=>{const i=t.length-e.length;return i>=0&&t.slice(i)===e},l=t=>-1!==t.index,a=()=>document.createComment(""),h=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function c(t,e){const{element:{content:i},parts:s}=t,o=document.createTreeWalker(i,133,null,!1);let n=p(s),r=s[n],l=-1,a=0;const h=[];let c=null;for(;o.nextNode();){l++;const t=o.currentNode;for(t.previousSibling===c&&(c=null),e.has(t)&&(h.push(t),null===c&&(c=t)),null!==c&&a++;void 0!==r&&r.index===l;)r.index=null!==c?-1:r.index-a,n=p(s,n),r=s[n]}h.forEach(t=>t.parentNode.removeChild(t))}const d=t=>{let e=11===t.nodeType?0:1;const i=document.createTreeWalker(t,133,null,!1);for(;i.nextNode();)e++;return e},p=(t,e=-1)=>{for(let i=e+1;i<t.length;i++){const e=t[i];if(l(e))return i}return-1};const u=new WeakMap,f=t=>(...e)=>{const i=t(...e);return u.set(i,!0),i},y=t=>"function"==typeof t&&u.has(t),m={},b={};class w{constructor(t,e,i){this.t=[],this.template=t,this.processor=e,this.options=i}update(t){let e=0;for(const i of this.t)void 0!==i&&i.setValue(t[e]),e++;for(const t of this.t)void 0!==t&&t.commit()}_clone(){const e=t?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),i=[],s=this.template.parts,o=document.createTreeWalker(e,133,null,!1);let n,r=0,a=0,h=o.nextNode();for(;r<s.length;)if(n=s[r],l(n)){for(;a<n.index;)a++,"TEMPLATE"===h.nodeName&&(i.push(h),o.currentNode=h.content),null===(h=o.nextNode())&&(o.currentNode=i.pop(),h=o.nextNode());if("node"===n.type){const t=this.processor.handleTextExpression(this.options);t.insertAfterNode(h.previousSibling),this.t.push(t)}else this.t.push(...this.processor.handleAttributeExpressions(h,n.name,n.strings,this.options));r++}else this.t.push(void 0),r++;return t&&(document.adoptNode(e),customElements.upgrade(e)),e}}const k=` ${i} `;class v{constructor(t,e,i,s){this.strings=t,this.values=e,this.type=i,this.processor=s}getHTML(){const t=this.strings.length-1;let e="",o=!1;for(let n=0;n<t;n++){const t=this.strings[n],r=t.lastIndexOf("\x3c!--");o=(r>-1||o)&&-1===t.indexOf("--\x3e",r+1);const l=h.exec(t);e+=null===l?t+(o?k:s):t.substr(0,l.index)+l[1]+l[2]+"$lit$"+l[3]+i}return e+=this.strings[t],e}getTemplateElement(){const t=document.createElement("template");return t.innerHTML=this.getHTML(),t}}class g extends v{getHTML(){return`<svg>${super.getHTML()}</svg>`}getTemplateElement(){const t=super.getTemplateElement(),e=t.content,i=e.firstChild;return e.removeChild(i),((t,e,i=null,s=null)=>{for(;e!==i;){const i=e.nextSibling;t.insertBefore(e,s),e=i}})(e,i.firstChild),t}}const C=t=>null===t||!("object"==typeof t||"function"==typeof t),P=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class L{constructor(t,e,i){this.dirty=!0,this.element=t,this.name=e,this.strings=i,this.parts=[];for(let t=0;t<i.length-1;t++)this.parts[t]=this._createPart()}_createPart(){return new M(this)}_getValue(){const t=this.strings,e=t.length-1;let i="";for(let s=0;s<e;s++){i+=t[s];const e=this.parts[s];if(void 0!==e){const t=e.value;if(C(t)||!P(t))i+="string"==typeof t?t:t+"";else for(const e of t)i+="string"==typeof e?e:e+""}}return i+=t[e],i}commit(){this.dirty&&(this.dirty=!1,this.element.setAttribute(this.name,this._getValue()))}}class M{constructor(t){this.value=void 0,this.committer=t}setValue(t){t===m||C(t)&&t===this.value||(this.value=t,y(t)||(this.committer.dirty=!0))}commit(){for(;y(this.value);){const t=this.value;this.value=m,t(this)}this.value!==m&&this.committer.commit()}}class x{constructor(t){this.value=void 0,this.i=void 0,this.options=t}appendInto(t){this.startNode=t.appendChild(a()),this.endNode=t.appendChild(a())}insertAfterNode(t){this.startNode=t,this.endNode=t.nextSibling}appendIntoPart(t){t.s(this.startNode=a()),t.s(this.endNode=a())}insertAfterPart(t){t.s(this.startNode=a()),this.endNode=t.endNode,t.endNode=this.startNode}setValue(t){this.i=t}commit(){if(null===this.startNode.parentNode)return;for(;y(this.i);){const t=this.i;this.i=m,t(this)}const t=this.i;t!==m&&(C(t)?t!==this.value&&this.o(t):t instanceof v?this.l(t):t instanceof Node?this.h(t):P(t)?this.u(t):t===b?(this.value=b,this.clear()):this.o(t))}s(t){this.endNode.parentNode.insertBefore(t,this.endNode)}h(t){this.value!==t&&(this.clear(),this.s(t),this.value=t)}o(t){const e=this.startNode.nextSibling,i="string"==typeof(t=null==t?"":t)?t:t+"";e===this.endNode.previousSibling&&3===e.nodeType?e.data=i:this.h(document.createTextNode(i)),this.value=t}l(t){const e=this.options.templateFactory(t);if(this.value instanceof w&&this.value.template===e)this.value.update(t.values);else{const i=new w(e,t.processor,this.options),s=i._clone();i.update(t.values),this.h(s),this.value=i}}u(t){Array.isArray(this.value)||(this.value=[],this.clear());const e=this.value;let i,s=0;for(const o of t)i=e[s],void 0===i&&(i=new x(this.options),e.push(i),0===s?i.appendIntoPart(this):i.insertAfterPart(e[s-1])),i.setValue(o),i.commit(),s++;s<e.length&&(e.length=s,this.clear(i&&i.endNode))}clear(t=this.startNode){e(this.startNode.parentNode,t.nextSibling,this.endNode)}}class S{constructor(t,e,i){if(this.value=void 0,this.i=void 0,2!==i.length||""!==i[0]||""!==i[1])throw Error("Boolean attributes can only contain a single expression");this.element=t,this.name=e,this.strings=i}setValue(t){this.i=t}commit(){for(;y(this.i);){const t=this.i;this.i=m,t(this)}if(this.i===m)return;const t=!!this.i;this.value!==t&&(t?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name),this.value=t),this.i=m}}class _ extends L{constructor(t,e,i){super(t,e,i),this.single=2===i.length&&""===i[0]&&""===i[1]}_createPart(){return new j(this)}_getValue(){return this.single?this.parts[0].value:super._getValue()}commit(){this.dirty&&(this.dirty=!1,this.element[this.name]=this._getValue())}}class j extends M{}let $=!1;(()=>{try{const t={get capture(){return $=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})();class A{constructor(t,e,i){this.value=void 0,this.i=void 0,this.element=t,this.eventName=e,this.eventContext=i,this.m=t=>this.handleEvent(t)}setValue(t){this.i=t}commit(){for(;y(this.i);){const t=this.i;this.i=m,t(this)}if(this.i===m)return;const t=this.i,e=this.value,i=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),s=null!=t&&(null==e||i);i&&this.element.removeEventListener(this.eventName,this.m,this.k),s&&(this.k=z(t),this.element.addEventListener(this.eventName,this.m,this.k)),this.value=t,this.i=m}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const z=t=>t&&($?{capture:t.capture,passive:t.passive,once:t.once}:t.capture);function q(t){let e=O.get(t.type);void 0===e&&(e={stringsArray:new WeakMap,keyString:new Map},O.set(t.type,e));let s=e.stringsArray.get(t.strings);if(void 0!==s)return s;const o=t.strings.join(i);return s=e.keyString.get(o),void 0===s&&(s=new n(t,t.getTemplateElement()),e.keyString.set(o,s)),e.stringsArray.set(t.strings,s),s}const O=new Map,N=new WeakMap,E=(t,i,s)=>{let o=N.get(i);void 0===o&&(e(i,i.firstChild),N.set(i,o=new x(Object.assign({templateFactory:q},s))),o.appendInto(i)),o.setValue(t),o.commit()};const R=new class{handleAttributeExpressions(t,e,i,s){const o=e[0];if("."===o){return new _(t,e.slice(1),i).parts}if("@"===o)return[new A(t,e.slice(1),s.eventContext)];if("?"===o)return[new S(t,e.slice(1),i)];return new L(t,e,i).parts}handleTextExpression(t){return new x(t)}};"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.2.1");const B=(t,...e)=>new v(t,e,"html",R),T=(t,...e)=>new g(t,e,"svg",R),D=(t,e)=>`${t}--${e}`;let K=!0;void 0===window.ShadyCSS?K=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),K=!1);const U=t=>e=>{const s=D(e.type,t);let o=O.get(s);void 0===o&&(o={stringsArray:new WeakMap,keyString:new Map},O.set(s,o));let r=o.stringsArray.get(e.strings);if(void 0!==r)return r;const l=e.strings.join(i);if(r=o.keyString.get(l),void 0===r){const i=e.getTemplateElement();K&&window.ShadyCSS.prepareTemplateDom(i,t),r=new n(e,i),o.keyString.set(l,r)}return o.stringsArray.set(e.strings,r),r},I=["html","svg"],Q=new Set,V=(t,e,i)=>{Q.add(t);const s=i?i.element:document.createElement("template"),o=e.querySelectorAll("style"),{length:n}=o;if(0===n)return void window.ShadyCSS.prepareTemplateStyles(s,t);const r=document.createElement("style");for(let t=0;t<n;t++){const e=o[t];e.parentNode.removeChild(e),r.textContent+=e.textContent}(t=>{I.forEach(e=>{const i=O.get(D(e,t));void 0!==i&&i.keyString.forEach(t=>{const{element:{content:e}}=t,i=new Set;Array.from(e.querySelectorAll("style")).forEach(t=>{i.add(t)}),c(t,i)})})})(t);const l=s.content;i?function(t,e,i=null){const{element:{content:s},parts:o}=t;if(null==i)return void s.appendChild(e);const n=document.createTreeWalker(s,133,null,!1);let r=p(o),l=0,a=-1;for(;n.nextNode();)for(a++,n.currentNode===i&&(l=d(e),i.parentNode.insertBefore(e,i));-1!==r&&o[r].index===a;){if(l>0){for(;-1!==r;)o[r].index+=l,r=p(o,r);return}r=p(o,r)}}(i,r,l.firstChild):l.insertBefore(r,l.firstChild),window.ShadyCSS.prepareTemplateStyles(s,t);const a=l.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==a)e.insertBefore(a.cloneNode(!0),e.firstChild);else if(i){l.insertBefore(r,l.firstChild);const t=new Set;t.add(r),c(i,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const W={toAttribute(t,e){switch(e){case Boolean:return t?"":null;case Object:case Array:return null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){switch(e){case Boolean:return null!==t;case Number:return null===t?null:Number(t);case Object:case Array:return JSON.parse(t)}return t}},J=(t,e)=>e!==t&&(e==e||t==t),F={attribute:!0,type:String,converter:W,reflect:!1,hasChanged:J};class H extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=new Promise(t=>this._enableUpdatingResolver=t),this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach((e,i)=>{const s=this._attributeNameForProperty(i,e);void 0!==s&&(this._attributeToPropertyMap.set(s,i),t.push(s))}),t}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const t=Object.getPrototypeOf(this)._classProperties;void 0!==t&&t.forEach((t,e)=>this._classProperties.set(e,t))}}static createProperty(t,e=F){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const i="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,i,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(i){const s=this[t];this[e]=i,this._requestUpdate(t,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this._classProperties&&this._classProperties.get(t)||F}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty("finalized")||t.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const t=this.properties,e=[...Object.getOwnPropertyNames(t),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]];for(const i of e)this.createProperty(i,t[i])}}static _attributeNameForProperty(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}static _valueHasChanged(t,e,i=J){return i(t,e)}static _propertyValueFromAttribute(t,e){const i=e.type,s=e.converter||W,o="function"==typeof s?s:s.fromAttribute;return o?o(t,i):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const i=e.type,s=e.converter;return(s&&s.toAttribute||W.toAttribute)(t,i)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_saveInstanceProperties(){this.constructor._classProperties.forEach((t,e)=>{if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(e,t)}})}_applyInstanceProperties(){this._instanceProperties.forEach((t,e)=>this[e]=t),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,i){e!==i&&this._attributeToProperty(t,i)}_propertyToAttribute(t,e,i=F){const s=this.constructor,o=s._attributeNameForProperty(t,i);if(void 0!==o){const t=s._propertyValueToAttribute(e,i);if(void 0===t)return;this._updateState=8|this._updateState,null==t?this.removeAttribute(o):this.setAttribute(o,t),this._updateState=-9&this._updateState}}_attributeToProperty(t,e){if(8&this._updateState)return;const i=this.constructor,s=i._attributeToPropertyMap.get(t);if(void 0!==s){const t=i.getPropertyOptions(s);this._updateState=16|this._updateState,this[s]=i._propertyValueFromAttribute(e,t),this._updateState=-17&this._updateState}}_requestUpdate(t,e){let i=!0;if(void 0!==t){const s=this.constructor,o=s.getPropertyOptions(t);s._valueHasChanged(this[t],e,o.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==o.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,o))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(t,e){return this._requestUpdate(t,e),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(t){}const t=this.performUpdate();return null!=t&&await t,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{t=this.shouldUpdate(e),t?this.update(e):this._markUpdated()}catch(e){throw t=!1,this._markUpdated(),e}t&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(t){return!0}update(t){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach((t,e)=>this._propertyToAttribute(e,this[e],t)),this._reflectingProperties=void 0),this._markUpdated()}updated(t){}firstUpdated(t){}}H.finalized=!0;const G=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object.assign(Object.assign({},e),{finisher(i){i.createProperty(e.key,t)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}};function X(t){return(e,i)=>void 0!==i?((t,e,i)=>{e.constructor.createProperty(i,t)})(t,e,i):G(t,e)}const Y=(t,e,i)=>{Object.defineProperty(e,i,t)},Z=(t,e)=>({kind:"method",placement:"prototype",key:e.key,descriptor:t}),tt="adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,et=Symbol();class it{constructor(t,e){if(e!==et)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){return void 0===this._styleSheet&&(tt?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}(window.litElementVersions||(window.litElementVersions=[])).push("2.3.1");const st={};class ot extends H{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(void 0===t)this._styles=[];else if(Array.isArray(t)){const e=(t,i)=>t.reduceRight((t,i)=>Array.isArray(i)?e(i,t):(t.add(i),t),i),i=e(t,new Set),s=[];i.forEach(t=>s.unshift(t)),this._styles=s}else this._styles=[t]}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?tt?this.renderRoot.adoptedStyleSheets=t.map(t=>t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==st&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){return st}}ot.finalized=!0,ot.render=(t,i,s)=>{if(!s||"object"!=typeof s||!s.scopeName)throw Error("The `scopeName` option is required.");const o=s.scopeName,n=N.has(i),r=K&&11===i.nodeType&&!!i.host,l=r&&!Q.has(o),a=l?document.createDocumentFragment():i;if(E(t,a,Object.assign({templateFactory:U(o)},s)),l){const t=N.get(a);N.delete(a);const s=t.value instanceof w?t.value.template:void 0;V(o,a,s),e(i,i.firstChild),i.appendChild(a),N.set(i,t)}!n&&r&&window.ShadyCSS.styleElement(i.host)};const nt=new WeakMap,rt=f(t=>e=>{if(!(e instanceof M)||e instanceof j||"style"!==e.committer.name||e.committer.parts.length>1)throw Error("The `styleMap` directive must be used in the style attribute and must be the only part in the attribute.");const{committer:i}=e,{style:s}=i.element;let o=nt.get(e);void 0===o&&(s.cssText=i.strings.join(" "),nt.set(e,o=new Set)),o.forEach(e=>{e in t||(o.delete(e),-1===e.indexOf("-")?s[e]=null:s.removeProperty(e))});for(const e in t)o.add(e),-1===e.indexOf("-")?s[e]=t[e]:s.setProperty(e,t[e])}),lt=new WeakMap,at=f(t=>e=>{const i=lt.get(e);if(void 0===t&&e instanceof M){if(void 0!==i||!lt.has(e)){const t=e.committer.name;e.committer.element.removeAttribute(t)}}else t!==i&&e.setValue(t);lt.set(e,t)}),ht=t=>"string"==typeof t,ct=t=>"function"==typeof t,dt=t=>JSON.parse(JSON.stringify(t)),pt=(t,e)=>{for(const[i,s]of Object.entries(e)){const e="{"+i+"}";for(;t.includes(e);)t=t.replace(e,s)}return t};console.assert("abc"===pt("abc",{a:"x"})),console.assert("{a}bc"===pt("{a}bc",{})),console.assert("{a}bc"===pt("{a}bc",{p:"q"})),console.assert("xbc"===pt("{a}bc",{a:"x"})),console.assert("xbcxbc"===pt("{a}bc{a}bc",{a:"x"})),console.assert("xxy"===pt("{a}{a}{b}",{a:"x",b:"y"}));const ut=((t,...e)=>{const i=e.reduce((e,i,s)=>e+(t=>{if(t instanceof it)return t.cssText;if("number"==typeof t)return t;throw Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+t[s+1],t[0]);return new it(i,et)})`:host{display:block;position:relative;--light-color:#f0d9b5;--dark-color:#b58863;--highlight-color:yellow}[part~=board]{border:2px solid #404040;box-sizing:border-box;display:grid;grid-template-columns:repeat(8,12.5%);grid-template-rows:repeat(8,12.5%)}[part~=square]{position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.piece-image,[part~=piece]{width:100%;height:100%;z-index:10}[part~=spare-pieces]{display:grid;position:relative;padding:0 2px;grid-template-columns:repeat(8,12.5%)}[part~=dragged-piece]{display:none;position:absolute}[part~=white]{background-color:var(--light-color);color:var(--dark-color)}[part~=black]{background-color:var(--dark-color);color:var(--light-color)}[part~=highlight]{box-shadow:inset 0 0 3px 3px var(--highlight-color)}[part~=notation]{cursor:default;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;position:absolute}[part~=alpha]{bottom:1px;right:3px}[part~=numeric]{top:2px;left:2px}`,ft="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",yt="abcdefgh".split(""),mt=["wK","wQ","wR","wB","wN","wP"],bt=["bK","bQ","bR","bB","bN","bP"],wt=t=>t.charCodeAt(0)%2^t.charCodeAt(1)%2?"white":"black",kt=t=>ht(t)&&-1!==t.search(/^[a-h][1-8]$/),vt=t=>{if(!ht(t))return!1;const e=t.split("-");return 2===e.length&&(kt(e[0])&&kt(e[1]))};console.assert(kt("a1")),console.assert(kt("e2")),console.assert(!kt("D2")),console.assert(!kt("g9")),console.assert(!kt("a")),console.assert(!kt(!0)),console.assert(!kt(null)),console.assert(!kt({}));const gt=t=>ht(t)&&-1!==t.search(/^[bw][KQRNBP]$/);console.assert(gt("bP")),console.assert(gt("bK")),console.assert(gt("wK")),console.assert(gt("wR")),console.assert(!gt("WR")),console.assert(!gt("Wr")),console.assert(!gt("a")),console.assert(!gt(!0)),console.assert(!gt(null)),console.assert(!gt({}));const Ct=t=>{if(!ht(t))return!1;const e=(t=(t=>t.replace(/8/g,"11111111").replace(/7/g,"1111111").replace(/6/g,"111111").replace(/5/g,"11111").replace(/4/g,"1111").replace(/3/g,"111").replace(/2/g,"11"))(t=t.replace(/ .+$/,""))).split("/");if(8!==e.length)return!1;for(let t=0;t<8;t++)if(8!==e[t].length||-1!==e[t].search(/[^kqrnbpKQRNBP1]/))return!1;return!0};console.assert(Ct(ft)),console.assert(Ct("8/8/8/8/8/8/8/8")),console.assert(Ct("r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R")),console.assert(Ct("3r3r/1p4pp/2nb1k2/pP3p2/8/PB2PN2/p4PPP/R4RK1 b - - 0 1")),console.assert(!Ct("3r3z/1p4pp/2nb1k2/pP3p2/8/PB2PN2/p4PPP/R4RK1 b - - 0 1")),console.assert(!Ct("anbqkbnr/8/8/8/8/8/PPPPPPPP/8")),console.assert(!Ct("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/")),console.assert(!Ct("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBN")),console.assert(!Ct("888888/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")),console.assert(!Ct("888888/pppppppp/74/8/8/8/PPPPPPPP/RNBQKBNR")),console.assert(!Ct({}));const Pt=t=>{if("object"!=typeof t||null===t)return!1;for(const[e,i]of Object.entries(t))if(!kt(e)||!gt(i))return!1;return!0};console.assert(Pt({})),console.assert(Pt({e2:"wP"})),console.assert(Pt({e2:"wP",d2:"wP"})),console.assert(!Pt({e2:"BP"})),console.assert(!Pt({y2:"wP"})),console.assert(!Pt(null)),console.assert(!Pt(void 0)),console.assert(!Pt(1)),console.assert(!Pt("start")),console.assert(!Pt(ft));const Lt=t=>{const e=t.split("");return"w"===e[0]?e[1].toUpperCase():e[1].toLowerCase()},Mt=t=>{if(!Ct(t))return!1;const e=(t=t.replace(/ .+$/,"")).split("/"),i={};let s=8;for(let t=0;t<8;t++){const n=e[t].split("");let r=0;for(let t=0;t<n.length;t++)if(-1!==n[t].search(/[1-8]/)){r+=parseInt(n[t],10)}else{i[yt[r]+s]=(o=n[t]).toLowerCase()===o?"b"+o.toUpperCase():"w"+o.toUpperCase(),r+=1}s-=1}var o;return i},xt=Mt(ft),St=t=>{if(!Pt(t))return!1;let e="",i=8;for(let s=0;s<8;s++){for(let s=0;s<8;s++){const o=yt[s]+i;t.hasOwnProperty(o)?e+=Lt(t[o]):e+="1"}7!==s&&(e+="/"),i-=1}return e=(t=>t.replace(/11111111/g,"8").replace(/1111111/g,"7").replace(/111111/g,"6").replace(/11111/g,"5").replace(/1111/g,"4").replace(/111/g,"3").replace(/11/g,"2"))(e),e};console.assert(St(xt)===ft),console.assert("8/8/8/8/8/8/8/8"===St({})),console.assert("8/8/8/8/8/8/Pp6/8"===St({a2:"wP",b2:"bP"}));const _t=t=>null==t?{}:(ht(t)&&"start"===t.toLowerCase()&&(t=dt(xt)),Ct(t)&&(t=Mt(t)),t),jt=(t,e)=>{const i=t.split(""),s=yt.indexOf(i[0])+1,o=parseInt(i[1],10),n=e.split(""),r=yt.indexOf(n[0])+1,l=parseInt(n[1],10),a=Math.abs(s-r),h=Math.abs(o-l);return a>=h?a:h},$t=(t,e,i)=>{const s=(t=>{const e=[];for(let i=0;i<8;i++)for(let s=0;s<8;s++){const o=yt[i]+(s+1);t!==o&&e.push({square:o,distance:jt(t,o)})}e.sort((function(t,e){return t.distance-e.distance}));const i=[];for(let t=0;t<e.length;t++)i.push(e[t].square);return i})(i);for(let i=0;i<s.length;i++){const o=s[i];if(t.hasOwnProperty(o)&&t[o]===e)return o}return!1},At=(t,e)=>{const i=dt(t);for(const t in e){if(!e.hasOwnProperty(t))continue;if(!i.hasOwnProperty(t))continue;const s=i[t];delete i[t],i[e[t]]=s}return i},zt=(t,e)=>{E(B`<svg class="piece-image" viewBox="0 0 45 45">${qt[t]}</svg>`,e)},qt={bB:T` | ||
const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e=Symbol(),i=new Map;class s{constructor(t,i){if(this._$cssResult$=!0,i!==e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let e=i.get(this.cssText);return t&&void 0===e&&(i.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o=t?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let i="";for(const e of t.cssRules)i+=e.cssText;return(t=>new s("string"==typeof t?t:t+"",e))(i)})(t):t;var n,r;const l={toAttribute(t,e){switch(e){case Boolean:t=t?"":null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},a=(t,e)=>e!==t&&(e==e||t==t),h={attribute:!0,type:String,converter:l,reflect:!1,hasChanged:a};class c extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;null!==(e=this.l)&&void 0!==e||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const s=this._$Eh(i,e);void 0!==s&&(this._$Eu.set(s,i),t.push(s))})),t}static createProperty(t,e=h){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,i,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(s){const o=this[t];this[e]=s,this.requestUpdate(t,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||h}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(o(t))}else void 0!==t&&e.push(o(t));return e}static _$Eh(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ev=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Ep(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$Em)&&void 0!==e?e:this._$Em=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$Em)||void 0===e||e.splice(this._$Em.indexOf(t)>>>0,1)}_$Ep(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])}))}createRenderRoot(){var e;const i=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,i)=>{t?e.adoptedStyleSheets=i.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):i.forEach((t=>{const i=document.createElement("style"),s=window.litNonce;void 0!==s&&i.setAttribute("nonce",s),i.textContent=t.cssText,e.appendChild(i)}))})(i,this.constructor.elementStyles),i}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$Eg(t,e,i=h){var s,o;const n=this.constructor._$Eh(t,i);if(void 0!==n&&!0===i.reflect){const r=(null!==(o=null===(s=i.converter)||void 0===s?void 0:s.toAttribute)&&void 0!==o?o:l.toAttribute)(e,i.type);this._$Ei=t,null==r?this.removeAttribute(n):this.setAttribute(n,r),this._$Ei=null}}_$AK(t,e){var i,s,o;const n=this.constructor,r=n._$Eu.get(t);if(void 0!==r&&this._$Ei!==r){const t=n.getPropertyOptions(r),a=t.converter,h=null!==(o=null!==(s=null===(i=a)||void 0===i?void 0:i.fromAttribute)&&void 0!==s?s:"function"==typeof a?a:null)&&void 0!==o?o:l.fromAttribute;this._$Ei=r,this[r]=h(e,t.type),this._$Ei=null}}requestUpdate(t,e,i){let s=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||a)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$Ei!==t&&(void 0===this._$ES&&(this._$ES=new Map),this._$ES.set(t,i))):s=!1),!this.isUpdatePending&&s&&(this._$Ev=this._$EC())}async _$EC(){this.isUpdatePending=!0;try{await this._$Ev}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,e)=>this[e]=t)),this._$Et=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$Em)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$ET()}catch(t){throw e=!1,this._$ET(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$Em)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$ET(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ev}shouldUpdate(t){return!0}update(t){void 0!==this._$ES&&(this._$ES.forEach(((t,e)=>this._$Eg(e,this[e],t))),this._$ES=void 0),this._$ET()}updated(t){}firstUpdated(t){}}var d,u;c.finalized=!0,c.elementProperties=new Map,c.elementStyles=[],c.shadowRootOptions={mode:"open"},null===(n=globalThis.reactiveElementPolyfillSupport)||void 0===n||n.call(globalThis,{ReactiveElement:c}),(null!==(r=globalThis.reactiveElementVersions)&&void 0!==r?r:globalThis.reactiveElementVersions=[]).push("1.0.0");const p=globalThis.trustedTypes,f=p?p.createPolicy("lit-html",{createHTML:t=>t}):void 0,v=`lit$${(Math.random()+"").slice(9)}$`,b="?"+v,y=`<${b}>`,k=document,g=(t="")=>k.createComment(t),m=t=>null===t||"object"!=typeof t&&"function"!=typeof t,C=Array.isArray,w=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,L=/-->/g,P=/>/g,M=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,$=/'/g,x=/"/g,S=/^(?:script|style|textarea)$/i,A=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),_=A(1),j=A(2),z=Symbol.for("lit-noChange"),E=Symbol.for("lit-nothing"),q=new WeakMap,N=(t,e,i)=>{var s,o;const n=null!==(s=null==i?void 0:i.renderBefore)&&void 0!==s?s:e;let r=n._$litPart$;if(void 0===r){const t=null!==(o=null==i?void 0:i.renderBefore)&&void 0!==o?o:null;n._$litPart$=r=new K(e.insertBefore(g(),t),t,void 0,null!=i?i:{})}return r._$AI(t),r},R=k.createTreeWalker(k,129,null,!1),O=(t,e)=>{const i=t.length-1,s=[];let o,n=2===e?"<svg>":"",r=w;for(let e=0;e<i;e++){const i=t[e];let l,a,h=-1,c=0;for(;c<i.length&&(r.lastIndex=c,a=r.exec(i),null!==a);)c=r.lastIndex,r===w?"!--"===a[1]?r=L:void 0!==a[1]?r=P:void 0!==a[2]?(S.test(a[2])&&(o=RegExp("</"+a[2],"g")),r=M):void 0!==a[3]&&(r=M):r===M?">"===a[0]?(r=null!=o?o:w,h=-1):void 0===a[1]?h=-2:(h=r.lastIndex-a[2].length,l=a[1],r=void 0===a[3]?M:'"'===a[3]?x:$):r===x||r===$?r=M:r===L||r===P?r=w:(r=M,o=void 0);const d=r===M&&t[e+1].startsWith("/>")?" ":"";n+=r===w?i+y:h>=0?(s.push(l),i.slice(0,h)+"$lit$"+i.slice(h)+v+d):i+v+(-2===h?(s.push(void 0),e):d)}const l=n+(t[i]||"<?>")+(2===e?"</svg>":"");return[void 0!==f?f.createHTML(l):l,s]};class T{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let o=0,n=0;const r=t.length-1,l=this.parts,[a,h]=O(t,e);if(this.el=T.createElement(a,i),R.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=R.nextNode())&&l.length<r;){if(1===s.nodeType){if(s.hasAttributes()){const t=[];for(const e of s.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(v)){const i=h[n++];if(t.push(e),void 0!==i){const t=s.getAttribute(i.toLowerCase()+"$lit$").split(v),e=/([.?@])?(.*)/.exec(i);l.push({type:1,index:o,name:e[2],strings:t,ctor:"."===e[1]?I:"?"===e[1]?Q:"@"===e[1]?J:U})}else l.push({type:6,index:o})}for(const e of t)s.removeAttribute(e)}if(S.test(s.tagName)){const t=s.textContent.split(v),e=t.length-1;if(e>0){s.textContent=p?p.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],g()),R.nextNode(),l.push({type:2,index:++o});s.append(t[e],g())}}}else if(8===s.nodeType)if(s.data===b)l.push({type:2,index:o});else{let t=-1;for(;-1!==(t=s.data.indexOf(v,t+1));)l.push({type:7,index:o}),t+=v.length-1}o++}}static createElement(t,e){const i=k.createElement("template");return i.innerHTML=t,i}}function B(t,e,i=t,s){var o,n,r,l;if(e===z)return e;let a=void 0!==s?null===(o=i._$Cl)||void 0===o?void 0:o[s]:i._$Cu;const h=m(e)?void 0:e._$litDirective$;return(null==a?void 0:a.constructor)!==h&&(null===(n=null==a?void 0:a._$AO)||void 0===n||n.call(a,!1),void 0===h?a=void 0:(a=new h(t),a._$AT(t,i,s)),void 0!==s?(null!==(r=(l=i)._$Cl)&&void 0!==r?r:l._$Cl=[])[s]=a:i._$Cu=a),void 0!==a&&(e=B(t,a._$AS(t,e.values),a,s)),e}class D{constructor(t,e){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var e;const{el:{content:i},parts:s}=this._$AD,o=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:k).importNode(i,!0);R.currentNode=o;let n=R.nextNode(),r=0,l=0,a=s[0];for(;void 0!==a;){if(r===a.index){let e;2===a.type?e=new K(n,n.nextSibling,this,t):1===a.type?e=new a.ctor(n,a.name,a.strings,this,t):6===a.type&&(e=new H(n,this,t)),this.v.push(e),a=s[++l]}r!==(null==a?void 0:a.index)&&(n=R.nextNode(),r++)}return o}m(t){let e=0;for(const i of this.v)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class K{constructor(t,e,i,s){var o;this.type=2,this._$AH=E,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cg=null===(o=null==s?void 0:s.isConnected)||void 0===o||o}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=B(this,t,e),m(t)?t===E||null==t||""===t?(this._$AH!==E&&this._$AR(),this._$AH=E):t!==this._$AH&&t!==z&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.S(t):(t=>{var e;return C(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.M(t):this.$(t)}A(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}S(t){this._$AH!==t&&(this._$AR(),this._$AH=this.A(t))}$(t){this._$AH!==E&&m(this._$AH)?this._$AA.nextSibling.data=t:this.S(k.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:s}=t,o="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=T.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===o)this._$AH.m(i);else{const t=new D(o,this),e=t.p(this.options);t.m(i),this.S(e),this._$AH=t}}_$AC(t){let e=q.get(t.strings);return void 0===e&&q.set(t.strings,e=new T(t)),e}M(t){C(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const o of t)s===e.length?e.push(i=new K(this.A(g()),this.A(g()),this,this.options)):i=e[s],i._$AI(o),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cg=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class U{constructor(t,e,i,s,o){this.type=1,this._$AH=E,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=o,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=E}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const o=this.strings;let n=!1;if(void 0===o)t=B(this,t,e,0),n=!m(t)||t!==this._$AH&&t!==z,n&&(this._$AH=t);else{const s=t;let r,l;for(t=o[0],r=0;r<o.length-1;r++)l=B(this,s[i+r],e,r),l===z&&(l=this._$AH[r]),n||(n=!m(l)||l!==this._$AH[r]),l===E?t=E:t!==E&&(t+=(null!=l?l:"")+o[r+1]),this._$AH[r]=l}n&&!s&&this.k(t)}k(t){t===E?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class I extends U{constructor(){super(...arguments),this.type=3}k(t){this.element[this.name]=t===E?void 0:t}}class Q extends U{constructor(){super(...arguments),this.type=4}k(t){t&&t!==E?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name)}}class J extends U{constructor(t,e,i,s,o){super(t,e,i,s,o),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=B(this,t,e,0))&&void 0!==i?i:E)===z)return;const s=this._$AH,o=t===E&&s!==E||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==E&&(s===E||o);o&&this.element.removeEventListener(this.name,this,s),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class H{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){B(this,t)}}var W,V,Z;null===(d=globalThis.litHtmlPolyfillSupport)||void 0===d||d.call(globalThis,T,K),(null!==(u=globalThis.litHtmlVersions)&&void 0!==u?u:globalThis.litHtmlVersions=[]).push("2.0.0");class G extends c{constructor(){super(...arguments),this.renderOptions={host:this},this._$Dt=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Dt=N(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return z}}G.finalized=!0,G._$litElement$=!0,null===(W=globalThis.litElementHydrateSupport)||void 0===W||W.call(globalThis,{LitElement:G}),null===(V=globalThis.litElementPolyfillSupport)||void 0===V||V.call(globalThis,{LitElement:G}),(null!==(Z=globalThis.litElementVersions)&&void 0!==Z?Z:globalThis.litElementVersions=[]).push("3.0.0");const X=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}};function Y(t){return(e,i)=>void 0!==i?((t,e,i)=>{e.constructor.createProperty(i,t)})(t,e,i):X(t,e)}const F=1,tt=t=>(...e)=>({_$litDirective$:t,values:e});class et{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}const it=tt(class extends et{constructor(t){var e;if(super(t),t.type!==F||"style"!==t.name||(null===(e=t.strings)||void 0===e?void 0:e.length)>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,i)=>{const s=t[i];return null==s?e:e+`${i=i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${s};`}),"")}update(t,[e]){const{style:i}=t.element;if(void 0===this.ut){this.ut=new Set;for(const t in e)this.ut.add(t);return this.render(e)}this.ut.forEach((t=>{null==e[t]&&(this.ut.delete(t),t.includes("-")?i.removeProperty(t):i[t]="")}));for(const t in e){const s=e[t];null!=s&&(this.ut.add(t),t.includes("-")?i.setProperty(t,s):i[t]=s)}return z}}),st=t=>"string"==typeof t,ot=t=>"function"==typeof t,nt=t=>JSON.parse(JSON.stringify(t)),rt=(t,e)=>{for(const[i,s]of Object.entries(e)){const e="{"+i+"}";for(;t.includes(e);)t=t.replace(e,s)}return t};console.assert("abc"===rt("abc",{a:"x"})),console.assert("{a}bc"===rt("{a}bc",{})),console.assert("{a}bc"===rt("{a}bc",{p:"q"})),console.assert("xbc"===rt("{a}bc",{a:"x"})),console.assert("xbcxbc"===rt("{a}bc{a}bc",{a:"x"})),console.assert("xxy"===rt("{a}{a}{b}",{a:"x",b:"y"}));const lt=((t,...i)=>{const o=1===t.length?t[0]:i.reduce(((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1]),t[0]);return new s(o,e)})`:host{display:block;position:relative;--light-color:#f0d9b5;--dark-color:#b58863;--highlight-color:yellow}[part~=board]{border:2px solid #404040;box-sizing:border-box;display:grid;grid-template-columns:repeat(8,12.5%);grid-template-rows:repeat(8,12.5%)}[part~=square]{position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.piece-image,[part~=piece]{width:100%;height:100%;z-index:10}[part~=spare-pieces]{display:grid;position:relative;padding:0 2px;grid-template-columns:repeat(8,12.5%)}[part~=dragged-piece]{display:none;position:absolute}[part~=white]{background-color:var(--light-color);color:var(--dark-color)}[part~=black]{background-color:var(--dark-color);color:var(--light-color)}[part~=highlight]{box-shadow:inset 0 0 3px 3px var(--highlight-color)}[part~=notation]{cursor:default;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;position:absolute}[part~=alpha]{bottom:1px;right:3px}[part~=numeric]{top:2px;left:2px}`,at="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR",ht="abcdefgh".split(""),ct=["wK","wQ","wR","wB","wN","wP"],dt=["bK","bQ","bR","bB","bN","bP"],ut=t=>t.charCodeAt(0)%2^t.charCodeAt(1)%2?"white":"black",pt=t=>st(t)&&-1!==t.search(/^[a-h][1-8]$/),ft=t=>{if(!st(t))return!1;const e=t.split("-");return 2===e.length&&(pt(e[0])&&pt(e[1]))};console.assert(pt("a1")),console.assert(pt("e2")),console.assert(!pt("D2")),console.assert(!pt("g9")),console.assert(!pt("a")),console.assert(!pt(!0)),console.assert(!pt(null)),console.assert(!pt({}));const vt=t=>st(t)&&-1!==t.search(/^[bw][KQRNBP]$/);console.assert(vt("bP")),console.assert(vt("bK")),console.assert(vt("wK")),console.assert(vt("wR")),console.assert(!vt("WR")),console.assert(!vt("Wr")),console.assert(!vt("a")),console.assert(!vt(!0)),console.assert(!vt(null)),console.assert(!vt({}));const bt=t=>{if(!st(t))return!1;const e=(t=(t=>t.replace(/8/g,"11111111").replace(/7/g,"1111111").replace(/6/g,"111111").replace(/5/g,"11111").replace(/4/g,"1111").replace(/3/g,"111").replace(/2/g,"11"))(t=t.replace(/ .+$/,""))).split("/");if(8!==e.length)return!1;for(let t=0;t<8;t++)if(8!==e[t].length||-1!==e[t].search(/[^kqrnbpKQRNBP1]/))return!1;return!0};console.assert(bt(at)),console.assert(bt("8/8/8/8/8/8/8/8")),console.assert(bt("r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R")),console.assert(bt("3r3r/1p4pp/2nb1k2/pP3p2/8/PB2PN2/p4PPP/R4RK1 b - - 0 1")),console.assert(!bt("3r3z/1p4pp/2nb1k2/pP3p2/8/PB2PN2/p4PPP/R4RK1 b - - 0 1")),console.assert(!bt("anbqkbnr/8/8/8/8/8/PPPPPPPP/8")),console.assert(!bt("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/")),console.assert(!bt("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBN")),console.assert(!bt("888888/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")),console.assert(!bt("888888/pppppppp/74/8/8/8/PPPPPPPP/RNBQKBNR")),console.assert(!bt({}));const yt=t=>{if("object"!=typeof t||null===t)return!1;for(const[e,i]of Object.entries(t))if(!pt(e)||!vt(i))return!1;return!0};console.assert(yt({})),console.assert(yt({e2:"wP"})),console.assert(yt({e2:"wP",d2:"wP"})),console.assert(!yt({e2:"BP"})),console.assert(!yt({y2:"wP"})),console.assert(!yt(null)),console.assert(!yt(void 0)),console.assert(!yt(1)),console.assert(!yt("start")),console.assert(!yt(at));const kt=t=>{const e=t.split("");return"w"===e[0]?e[1].toUpperCase():e[1].toLowerCase()},gt=t=>{if(!bt(t))return!1;const e=(t=t.replace(/ .+$/,"")).split("/"),i={};let s=8;for(let t=0;t<8;t++){const n=e[t].split("");let r=0;for(let t=0;t<n.length;t++)if(-1!==n[t].search(/[1-8]/)){r+=parseInt(n[t],10)}else{i[ht[r]+s]=(o=n[t]).toLowerCase()===o?"b"+o.toUpperCase():"w"+o.toUpperCase(),r+=1}s-=1}var o;return i},mt=gt(at),Ct=t=>{if(!yt(t))return!1;let e="",i=8;for(let s=0;s<8;s++){for(let s=0;s<8;s++){const o=ht[s]+i;t.hasOwnProperty(o)?e+=kt(t[o]):e+="1"}7!==s&&(e+="/"),i-=1}return e=(t=>t.replace(/11111111/g,"8").replace(/1111111/g,"7").replace(/111111/g,"6").replace(/11111/g,"5").replace(/1111/g,"4").replace(/111/g,"3").replace(/11/g,"2"))(e),e};console.assert(Ct(mt)===at),console.assert("8/8/8/8/8/8/8/8"===Ct({})),console.assert("8/8/8/8/8/8/Pp6/8"===Ct({a2:"wP",b2:"bP"}));const wt=t=>null==t?{}:(st(t)&&"start"===t.toLowerCase()&&(t=nt(mt)),bt(t)&&(t=gt(t)),t),Lt=(t,e)=>{const i=t.split(""),s=ht.indexOf(i[0])+1,o=parseInt(i[1],10),n=e.split(""),r=ht.indexOf(n[0])+1,l=parseInt(n[1],10),a=Math.abs(s-r),h=Math.abs(o-l);return a>=h?a:h},Pt=(t,e,i)=>{const s=(t=>{const e=[];for(let i=0;i<8;i++)for(let s=0;s<8;s++){const o=ht[i]+(s+1);t!==o&&e.push({square:o,distance:Lt(t,o)})}e.sort((function(t,e){return t.distance-e.distance}));const i=[];for(let t=0;t<e.length;t++)i.push(e[t].square);return i})(i);for(let i=0;i<s.length;i++){const o=s[i];if(t.hasOwnProperty(o)&&t[o]===e)return o}return!1},Mt=(t,e)=>{const i=nt(t);for(const t in e){if(!e.hasOwnProperty(t))continue;if(!i.hasOwnProperty(t))continue;const s=i[t];delete i[t],i[e[t]]=s}return i},$t=(t,e)=>{N(_`<svg class="piece-image" viewBox="0 0 45 45">${xt[t]}</svg>`,e)},xt={bB:j` | ||
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -15,3 +15,3 @@ <g style="fill:#000000; stroke:#000000; stroke-linecap:butt;"> | ||
</g> | ||
`,wB:T` | ||
`,wB:j` | ||
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -30,3 +30,3 @@ <g style="fill:#ffffff; stroke:#000000; stroke-linecap:butt;"> | ||
</g> | ||
`,bK:T` | ||
`,bK:j` | ||
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -53,3 +53,3 @@ <path | ||
</g> | ||
`,wK:T` | ||
`,wK:j` | ||
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -78,3 +78,3 @@ <path | ||
</g> | ||
`,bN:T` | ||
`,bN:j` | ||
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -98,3 +98,3 @@ <path | ||
</g> | ||
`,wN:T` | ||
`,wN:j` | ||
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -115,11 +115,11 @@ <path | ||
</g> | ||
`,bP:T` | ||
`,bP:j` | ||
<path | ||
d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z " | ||
style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" /> | ||
`,wP:T` | ||
`,wP:j` | ||
<path | ||
d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z " | ||
style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" /> | ||
`,bQ:T` | ||
`,bQ:j` | ||
<g style="opacity:1; fill:000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -155,3 +155,3 @@ <g style="fill:#000000; stroke:none;"> | ||
</g> | ||
`,wQ:T` | ||
`,wQ:j` | ||
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -186,3 +186,3 @@ <path | ||
</g> | ||
`,bR:T` | ||
`,bR:j` | ||
<g style="opacity:1; fill:000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -223,3 +223,3 @@ <path | ||
</g> | ||
`,wR:T` | ||
`,wR:j` | ||
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> | ||
@@ -246,2 +246,2 @@ <path | ||
</g> | ||
`};var Ot=function(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(o=t[l])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r};function Nt(t){if("dragging"!==(null==t?void 0:t.state))throw Error("unexpected drag state "+JSON.stringify(t))}const Et=t=>"number"==typeof t?t:"fast"===t?200:"slow"===t?600:parseInt(t,10),Rt=t=>"square-"+t,Bt=t=>"spare-piece-"+t,Tt=f((t,i)=>s=>{ct(i)?i(t,s.committer.element):e(s.committer.element,s.committer.element.firstChild)});let Dt=class extends ot{constructor(){super(...arguments),this.hideNotation=!1,this.orientation="white",this.draggablePieces=!1,this.dropOffBoard="snapback",this.renderPiece=(t,e)=>{let i=void 0;ht(this.pieceTheme)?i=pt(this.pieceTheme,{piece:t}):ct(this.pieceTheme)&&(i=this.pieceTheme(t)),void 0===i?zt(t,e):E(B`<img class="piece-image" src="${i}">`,e)},this.moveSpeed=200,this.snapbackSpeed=60,this.snapSpeed=30,this.trashSpeed=100,this.appearSpeed=200,this.sparePieces=!1,this._highlightedSquares=new Set,this._animations=new Map,this._currentPosition={},this._mousemoveWindow=t=>{var e;"dragging"===(null===(e=this._dragState)||void 0===e?void 0:e.state)&&this._updateDraggedPiece(t.clientX,t.clientY)},this._mouseupWindow=t=>{var e;if("dragging"!==(null===(e=this._dragState)||void 0===e?void 0:e.state))return;const i=this._isXYOnSquare(t.clientX,t.clientY);this._stopDraggedPiece(i)},this._touchmoveWindow=t=>{var e;if("dragging"!==(null===(e=this._dragState)||void 0===e?void 0:e.state))return;t.preventDefault();const i=t.changedTouches[0];this._updateDraggedPiece(i.clientX,i.clientY)},this._touchendWindow=t=>{var e;if("dragging"!==(null===(e=this._dragState)||void 0===e?void 0:e.state))return;const i=this._isXYOnSquare(t.changedTouches[0].clientX,t.changedTouches[0].clientY);this._stopDraggedPiece(i)}}get position(){return this._currentPosition}set position(t){const e=this._currentPosition;this._setCurrentPosition(t),this.requestUpdate("position",e)}get showNotation(){return!this.hideNotation}set showNotation(t){this.hideNotation=!t}get _squareSize(){return this.offsetWidth/8}_getSquareElement(t){return this.shadowRoot.getElementById(Rt(t))}_getSparePieceElement(t){return this.shadowRoot.getElementById(Bt(t))}render(){return B`<div part="spare-pieces">${this._renderSparePieces("white"===this.orientation?"black":"white")}</div>${this._renderBoard()}<div part="spare-pieces">${this._renderSparePieces("white"===this.orientation?"white":"black")}</div><div id="dragged-pieces" style="${rt({width:this._squareSize+"px",height:this._squareSize+"px"})}">${this._renderDraggedPiece()}</div>`}_renderSparePieces(t){if(!this.sparePieces)return b;return B`<div></div>${("black"===t?bt:mt).map(t=>B`<div id="spare-${t}" @mousedown="${this._mousedownSparePiece}" @touchstart="${this._touchstartSparePiece}">${this._renderPiece(t,{},!1,Bt(t))}</div>`)}<div></div>`}_renderDraggedPiece(){var t,e;const i={height:this._squareSize+"px",width:this._squareSize+"px"},s=this._dragState;if(void 0!==s){i.display="block";const t=this.getBoundingClientRect();if("dragging"===s.state){const{x:e,y:o}=s;Object.assign(i,{top:o-t.top-this._squareSize/2+"px",left:e-t.left-this._squareSize/2+"px"})}else if("snapback"===s.state){const{source:e}=s,o=this._getSquareElement(e).getBoundingClientRect();Object.assign(i,{transitionProperty:"top, left",transitionDuration:Et(this.snapbackSpeed)+"ms",top:o.top-t.top+"px",left:o.left-t.left+"px"})}else if("trash"===s.state){const{x:e,y:o}=s;Object.assign(i,{transitionProperty:"opacity",transitionDuration:Et(this.trashSpeed)+"ms",opacity:"0",top:o-t.top-this._squareSize/2+"px",left:e-t.left-this._squareSize/2+"px"})}else if("snap"===s.state){const e=this._getSquareElement(s.location).getBoundingClientRect();Object.assign(i,{transitionProperty:"top, left",transitionDuration:Et(this.snapSpeed)+"ms",top:e.top-t.top+"px",left:e.left-t.left+"px"})}}return this._renderPiece(null!==(e=null===(t=this._dragState)||void 0===t?void 0:t.piece)&&void 0!==e?e:"",i,!1,void 0,"dragged-piece")}_renderBoard(){var t;const e=[],i="black"===this.orientation;for(let s=0;s<8;s++)for(let o=0;o<8;o++){const n=yt[i?7-o:o],r=i?s+1:8-s,l=`${n}${r}`,a=wt(l);let h=this._currentPosition[l];const c=l===(null===(t=this._dragState)||void 0===t?void 0:t.source),d=this._animations.get(l),p=c||this._highlightedSquares.has(l)?"highlight":"",u=this._getAnimationStyles(h,d);h||"clear"!==(null==d?void 0:d.type)||(h=d.piece),e.push(B`<div class="square" id="${Rt(l)}" data-square="${l}" part="square ${l} ${a} ${p}" @mousedown="${this._mousedownSquare}" @mouseenter="${this._mouseenterSquare}" @mouseleave="${this._mouseleaveSquare}" @touchstart="${this._touchstartSquare}">${this.showNotation&&7===s?B`<div part="notation alpha">${n}</div>`:b} ${this.showNotation&&0===o?B`<div part="notation numeric">${r}</div>`:b} ${this._renderPiece(h,u,c)}</div>`)}const s={width:8*this._squareSize+"px",height:8*this._squareSize+"px"};return B`<div part="board" style="${rt(s)}">${e}</div>`}_renderPiece(t,e,i,s,o){if(void 0===t)return b;const n=Object.assign({opacity:"1",transitionProperty:"",transitionDuration:"0ms"},e);return(i||""===t)&&(n.display="none"),""===t?b:(ct(this.renderPiece)||this._error(8272,"invalid renderPiece."),B`<div id="${at(s)}" part="piece ${null!=o?o:""}" piece="${t}" style="${rt(n)}" ...="${Tt(t,this.renderPiece)}"></div>`)}_getAnimationStyles(t,e){if(e){if(t&&("move-start"===e.type||"add-start"===e.type&&this.draggablePieces)){const i="move-start"===e.type?this._getSquareElement(e.source):this._getSparePieceElement(t),s="move-start"===e.type?this._getSquareElement(e.destination):this._getSquareElement(e.square),o=i.getBoundingClientRect(),n=s.getBoundingClientRect();return{position:"absolute",left:o.left-n.left+"px",top:o.top-n.top+"px",width:this._squareSize+"px",height:this._squareSize+"px"}}if(t&&("move"===e.type||"add"===e.type&&this.draggablePieces))return{position:"absolute",transitionProperty:"top, left",transitionDuration:Et(this.moveSpeed)+"ms",top:"0",left:"0",width:this._squareSize+"px",height:this._squareSize+"px"};if(!t&&"clear"===e.type)return t=e.piece,{transitionProperty:"opacity",transitionDuration:Et(this.trashSpeed)+"ms",opacity:"0"};if(t&&"add-start"===e.type)return{opacity:"0"};if(t&&"add"===e.type)return{transitionProperty:"opacity",transitionDuration:Et(this.appearSpeed)+"ms"}}return{}}_mousedownSquare(t){if(t.preventDefault(),!this.draggablePieces&&!this.sparePieces)return;const e=t.currentTarget.getAttribute("data-square");null!==e&&this._currentPosition.hasOwnProperty(e)&&this._beginDraggingPiece(e,this._currentPosition[e],t.clientX,t.clientY)}_mousedownSparePiece(t){if(t.preventDefault(),!this.sparePieces)return;const e=t.currentTarget.querySelector("[part~=piece]").getAttribute("piece");this._beginDraggingPiece("spare",e,t.clientX,t.clientY)}_mouseenterSquare(t){if(void 0!==this._dragState)return;const e=t.currentTarget.getAttribute("data-square");if(!kt(e))return;let i=!1;this._currentPosition.hasOwnProperty(e)&&(i=this._currentPosition[e]),this.dispatchEvent(new CustomEvent("mouseover-square",{bubbles:!0,detail:{square:e,piece:i,position:dt(this._currentPosition),orientation:this.orientation}}))}_mouseleaveSquare(t){if(void 0!==this._dragState)return;const e=t.currentTarget.getAttribute("data-square");if(!kt(e))return;let i=!1;this._currentPosition.hasOwnProperty(e)&&(i=this._currentPosition[e]),this.dispatchEvent(new CustomEvent("mouseout-square",{bubbles:!0,detail:{square:e,piece:i,position:dt(this._currentPosition),orientation:this.orientation}}))}_touchstartSquare(t){if(!this.draggablePieces&&!this.sparePieces)return;const e=t.target.closest("[data-square]").getAttribute("data-square");kt(e)&&this._currentPosition.hasOwnProperty(e)&&(t.preventDefault(),this._beginDraggingPiece(e,this._currentPosition[e],t.changedTouches[0].clientX,t.changedTouches[0].clientY))}_touchstartSparePiece(t){if(!this.sparePieces)return;const e=t.target.closest("[piece]").getAttribute("piece");t.preventDefault(),this._beginDraggingPiece("spare",e,t.changedTouches[0].clientX,t.changedTouches[0].clientY)}setPosition(t,e=!0){if(t=_t(t),!Pt(t))throw this._error(6482,"Invalid value passed to the position method.",t);if(e){const e=this._calculateAnimations(this._currentPosition,t);this._doAnimations(e,this._currentPosition,t)}this._setCurrentPosition(t),this.requestUpdate()}fen(){return St(this._currentPosition)}start(t){this.setPosition("start",t)}clear(t){this.setPosition({},t)}move(...t){let e=!0;const i={};for(const s of t){if(!1===s){e=!1;continue}if(!vt(s)){this._error(2826,"Invalid move passed to the move method.",s);continue}const[t,o]=s.split("-");i[t]=o}const s=At(this._currentPosition,i);return this.setPosition(s,e),s}flip(){this.orientation="white"===this.orientation?"black":"white"}resize(){this.requestUpdate()}firstUpdated(){this.requestUpdate(),void 0!==window.ResizeObserver&&new ResizeObserver(()=>{this.resize()}).observe(this)}connectedCallback(){super.connectedCallback(),window.addEventListener("mousemove",this._mousemoveWindow),window.addEventListener("mouseup",this._mouseupWindow),window.addEventListener("touchmove",this._touchmoveWindow,{passive:!1}),window.addEventListener("touchend",this._touchendWindow,{passive:!1})}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("mousemove",this._mousemoveWindow),window.removeEventListener("mouseup",this._mouseupWindow),window.removeEventListener("touchmove",this._touchmoveWindow),window.removeEventListener("touchend",this._touchendWindow)}_setCurrentPosition(t){const e=dt(this._currentPosition),i=dt(t);St(e)!==St(i)&&(this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:i,oldValue:e}})),this._currentPosition=t)}_isXYOnSquare(t,e){const i=this.shadowRoot.elementsFromPoint(t,e).find(t=>t.classList.contains("square"));return void 0===i?"offboard":i.getAttribute("data-square")}_highlightSquare(t,e=!0){e?this._highlightedSquares.add(t):this._highlightedSquares.delete(t),this.requestUpdate("_highlightedSquares")}async _snapbackDraggedPiece(){Nt(this._dragState);const{source:t,piece:e}=this._dragState;return"spare"===t?this._trashDraggedPiece():(this._dragState={state:"snapback",piece:e,source:t},this.requestUpdate(),await new Promise(t=>setTimeout(t,0)),new Promise(i=>{const s=()=>{this._draggedPieceElement.removeEventListener("transitionend",s),i(),this.dispatchEvent(new CustomEvent("snapback-end",{bubbles:!0,detail:{piece:e,square:t,position:dt(this._currentPosition),orientation:this.orientation}}))};this._draggedPieceElement.addEventListener("transitionend",s)}))}async _trashDraggedPiece(){Nt(this._dragState);const{source:t,piece:e}=this._dragState,i=dt(this._currentPosition);return delete i[t],this._setCurrentPosition(i),this._dragState={state:"trash",piece:e,x:this._dragState.x,y:this._dragState.y,source:this._dragState.source},this.requestUpdate(),await new Promise(t=>setTimeout(t,0)),new Promise(t=>{const e=()=>{this._draggedPieceElement.removeEventListener("transitionend",e),t()};this._draggedPieceElement.addEventListener("transitionend",e)})}async _dropDraggedPieceOnSquare(t){Nt(this._dragState);const{source:e,piece:i}=this._dragState,s=dt(this._currentPosition);return delete s[e],s[t]=i,this._setCurrentPosition(s),this._dragState={state:"snap",piece:i,location:t,source:t},this.requestUpdate(),await new Promise(t=>setTimeout(t,0)),new Promise(s=>{const o=()=>{this._draggedPieceElement.removeEventListener("transitionend",o),s(),this.dispatchEvent(new CustomEvent("snap-end",{bubbles:!0,detail:{source:e,square:t,piece:i}}))};this._draggedPieceElement.addEventListener("transitionend",o)})}_beginDraggingPiece(t,e,i,s){const o=new CustomEvent("drag-start",{bubbles:!0,cancelable:!0,detail:{source:t,piece:e,position:dt(this._currentPosition),orientation:this.orientation}});this.dispatchEvent(o),o.defaultPrevented||(this._dragState={state:"dragging",x:i,y:s,piece:e,location:"spare"===t?"offboard":t,source:t},this.requestUpdate())}_updateDraggedPiece(t,e){Nt(this._dragState),this._dragState.x=t,this._dragState.y=e,this.requestUpdate();const i=this._isXYOnSquare(t,e);i!==this._dragState.location&&(kt(this._dragState.location)&&this._highlightSquare(this._dragState.location,!1),kt(i)&&this._highlightSquare(i),this.dispatchEvent(new CustomEvent("drag-move",{bubbles:!0,detail:{newLocation:i,oldLocation:this._dragState.location,source:this._dragState.source,piece:this._dragState.piece,position:dt(this._currentPosition),orientation:this.orientation}})),this._dragState.location=i)}async _stopDraggedPiece(t){Nt(this._dragState);const{source:e,piece:i}=this._dragState;let s="drop";"offboard"===t&&(s="trash"===this.dropOffBoard?"trash":"snapback");const o=dt(this._currentPosition),n=dt(this._currentPosition);"spare"===e&&kt(t)&&(o[t]=i),kt(e)&&(delete o[e],kt(t)&&(o[t]=i));const r=new CustomEvent("drop",{bubbles:!0,detail:{source:e,target:t,piece:i,newPosition:o,oldPosition:n,orientation:this.orientation,setAction(t){s=t}}});this.dispatchEvent(r),this._highlightedSquares.clear(),"snapback"===s?await this._snapbackDraggedPiece():"trash"===s?await this._trashDraggedPiece():"drop"===s&&await this._dropDraggedPieceOnSquare(t),this._dragState=void 0,this.requestUpdate()}_calculateAnimations(t,e){t=dt(t),e=dt(e);const i=[],s={};for(const i in e)e.hasOwnProperty(i)&&t.hasOwnProperty(i)&&t[i]===e[i]&&(delete t[i],delete e[i]);for(const o in e){if(!e.hasOwnProperty(o))continue;const n=$t(t,e[o],o);n&&(i.push({type:"move",source:n,destination:o,piece:e[o]}),delete t[n],delete e[o],s[o]=!0)}for(const t in e)e.hasOwnProperty(t)&&(i.push({type:"add",square:t,piece:e[t]}),delete e[t]);for(const e in t)t.hasOwnProperty(e)&&(s.hasOwnProperty(e)||(i.push({type:"clear",square:e,piece:t[e]}),delete t[e]));return i}async _doAnimations(t,e,i){if(0===t.length)return;let s=0;const o=()=>{s++,s===t.length&&(this.shadowRoot.removeEventListener("transitionend",o),this._animations.clear(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("move-end",{bubbles:!0,detail:{oldPosition:dt(e),newPosition:dt(i)}})))};this.shadowRoot.addEventListener("transitionend",o),this._animations.clear();for(const e of t)"add"===e.type||"add-start"===e.type?this._animations.set(e.square,Object.assign(Object.assign({},e),{type:"add-start"})):"move"===e.type||"move-start"===e.type?this._animations.set(e.destination,Object.assign(Object.assign({},e),{type:"move-start"})):this._animations.set(e.square,e);this.requestUpdate(),await new Promise(t=>setTimeout(t,0)),this._animations.clear();for(const e of t)"move"===e.type||"move-start"===e.type?this._animations.set(e.destination,e):this._animations.set(e.square,e);this.requestUpdate()}_error(t,e,i){const s=`Chessboard Error ${t} : ${e}`;return this.dispatchEvent(new ErrorEvent("error",{message:s})),Error(s)}};var Kt,Ut;Dt.styles=ut,Ot([X({converter:t=>_t(t)})],Dt.prototype,"position",null),Ot([X({attribute:"hide-notation",type:Boolean})],Dt.prototype,"hideNotation",void 0),Ot([X()],Dt.prototype,"orientation",void 0),Ot([X({attribute:"draggable-pieces",type:Boolean})],Dt.prototype,"draggablePieces",void 0),Ot([X({attribute:"drop-off-board"})],Dt.prototype,"dropOffBoard",void 0),Ot([X({attribute:"piece-theme"})],Dt.prototype,"pieceTheme",void 0),Ot([X({attribute:!1})],Dt.prototype,"renderPiece",void 0),Ot([X({attribute:"move-speed"})],Dt.prototype,"moveSpeed",void 0),Ot([X({attribute:"snapback-speed"})],Dt.prototype,"snapbackSpeed",void 0),Ot([X({attribute:"snap-speed"})],Dt.prototype,"snapSpeed",void 0),Ot([X({attribute:"trash-speed"})],Dt.prototype,"trashSpeed",void 0),Ot([X({attribute:"appear-speed"})],Dt.prototype,"appearSpeed",void 0),Ot([X({attribute:"spare-pieces",type:Boolean})],Dt.prototype,"sparePieces",void 0),Ot([(Kt='[part~="dragged-piece"]',(t,e)=>{const i={get(){return this.renderRoot.querySelector(Kt)},enumerable:!0,configurable:!0};return void 0!==e?Y(i,t,e):Z(i,t)})],Dt.prototype,"_draggedPieceElement",void 0),Dt=Ot([(Ut="chess-board",t=>"function"==typeof t?((t,e)=>(window.customElements.define(t,e),e))(Ut,t):((t,e)=>{const{kind:i,elements:s}=e;return{kind:i,elements:s,finisher(e){window.customElements.define(t,e)}}})(Ut,t))],Dt);export{yt as COLUMNS,Dt as ChessBoardElement,ft as START_FEN,xt as START_POSITION,bt as blackPieces,At as calculatePositionFromMoves,Mt as fenToObj,$t as findClosestPiece,wt as getSquareColor,_t as normalizePozition,St as objToFen,zt as renderWikipediaSVGPiece,Ct as validFen,vt as validMove,gt as validPieceCode,Pt as validPositionObject,kt as validSquare,mt as whitePieces}; | ||
`};var St=function(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(o=t[l])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r};function At(t){if("dragging"!==(null==t?void 0:t.state))throw Error("unexpected drag state "+JSON.stringify(t))}const _t=t=>"number"==typeof t?t:"fast"===t?200:"slow"===t?600:parseInt(t,10),jt=t=>"square-"+t,zt=t=>"spare-piece-"+t;const Et=tt(class extends et{render(t,e){return E}update(t,[e,i]){return ot(i)?i(e,t.element):t.element.replaceChildren(),z}});let qt=class extends G{constructor(){super(...arguments),this.hideNotation=!1,this.orientation="white",this.draggablePieces=!1,this.dropOffBoard="snapback",this.renderPiece=(t,e)=>{let i;st(this.pieceTheme)?i=rt(this.pieceTheme,{piece:t}):ot(this.pieceTheme)&&(i=this.pieceTheme(t)),void 0===i?$t(t,e):N(_`<img class="piece-image" src="${i}">`,e)},this.moveSpeed=200,this.snapbackSpeed=60,this.snapSpeed=30,this.trashSpeed=100,this.appearSpeed=200,this.sparePieces=!1,this._highlightedSquares=new Set,this._animations=new Map,this._currentPosition={},this._mousemoveWindow=t=>{var e;if("dragging"!==(null===(e=this._dragState)||void 0===e?void 0:e.state))return;t.preventDefault();const i=t instanceof MouseEvent?t:t.changedTouches[0];this._updateDraggedPiece(i.clientX,i.clientY)},this._mouseupWindow=t=>{var e;if("dragging"!==(null===(e=this._dragState)||void 0===e?void 0:e.state))return;const i=t instanceof MouseEvent?t:t.changedTouches[0],s=this._isXYOnSquare(i.clientX,i.clientY);this._stopDraggedPiece(s)}}get position(){return this._currentPosition}set position(t){const e=this._currentPosition;this._setCurrentPosition(t),this.requestUpdate("position",e)}get showNotation(){return!this.hideNotation}set showNotation(t){this.hideNotation=!t}get _squareSize(){return this.offsetWidth/8}_getSquareElement(t){return this.shadowRoot.getElementById(jt(t))}_getSparePieceElement(t){return this.shadowRoot.getElementById(zt(t))}render(){return _`<div part="spare-pieces">${this._renderSparePieces("white"===this.orientation?"black":"white")}</div>${this._renderBoard()}<div part="spare-pieces">${this._renderSparePieces("white"===this.orientation?"white":"black")}</div><div id="dragged-pieces" style="${it({width:this._squareSize+"px",height:this._squareSize+"px"})}">${this._renderDraggedPiece()}</div>`}_renderSparePieces(t){if(!this.sparePieces)return E;return _`<div></div>${("black"===t?dt:ct).map((t=>_`<div id="spare-${t}" @mousedown="${this._mousedownSparePiece}" @touchstart="${this._mousedownSparePiece}">${this._renderPiece(t,{},!1,zt(t))}</div>`))}<div></div>`}_renderDraggedPiece(){var t,e;const i={height:this._squareSize+"px",width:this._squareSize+"px"},s=this._dragState;if(void 0!==s){i.display="block";const t=this.getBoundingClientRect();if("dragging"===s.state){const{x:e,y:o}=s;Object.assign(i,{top:o-t.top-this._squareSize/2+"px",left:e-t.left-this._squareSize/2+"px"})}else if("snapback"===s.state){const{source:e}=s,o=this._getSquareElement(e).getBoundingClientRect();Object.assign(i,{transitionProperty:"top, left",transitionDuration:_t(this.snapbackSpeed)+"ms",top:o.top-t.top+"px",left:o.left-t.left+"px"})}else if("trash"===s.state){const{x:e,y:o}=s;Object.assign(i,{transitionProperty:"opacity",transitionDuration:_t(this.trashSpeed)+"ms",opacity:"0",top:o-t.top-this._squareSize/2+"px",left:e-t.left-this._squareSize/2+"px"})}else if("snap"===s.state){const e=this._getSquareElement(s.location).getBoundingClientRect();Object.assign(i,{transitionProperty:"top, left",transitionDuration:_t(this.snapSpeed)+"ms",top:e.top-t.top+"px",left:e.left-t.left+"px"})}}return this._renderPiece(null!==(e=null===(t=this._dragState)||void 0===t?void 0:t.piece)&&void 0!==e?e:"",i,!1,void 0,"dragged-piece")}_renderBoard(){var t;const e=[],i="black"===this.orientation;for(let s=0;s<8;s++)for(let o=0;o<8;o++){const n=ht[i?7-o:o],r=i?s+1:8-s,l=`${n}${r}`,a=ut(l);let h=this._currentPosition[l];const c=l===(null===(t=this._dragState)||void 0===t?void 0:t.source),d=this._animations.get(l),u=c||this._highlightedSquares.has(l)?"highlight":"",p=this._getAnimationStyles(h,d);h||"clear"!==(null==d?void 0:d.type)||(h=d.piece),e.push(_`<div class="square" id="${jt(l)}" data-square="${l}" part="square ${l} ${a} ${u}" @mousedown="${this._mousedownSquare}" @mouseenter="${this._mouseenterSquare}" @mouseleave="${this._mouseleaveSquare}" @touchstart="${this._mousedownSquare}">${this.showNotation&&7===s?_`<div part="notation alpha">${n}</div>`:E} ${this.showNotation&&0===o?_`<div part="notation numeric">${r}</div>`:E} ${this._renderPiece(h,p,c)}</div>`)}const s={width:8*this._squareSize+"px",height:8*this._squareSize+"px"};return _`<div part="board" style="${it(s)}">${e}</div>`}_renderPiece(t,e,i,s,o){if(void 0===t)return E;const n=Object.assign({opacity:"1",transitionProperty:"",transitionDuration:"0ms"},e);return(i||""===t)&&(n.display="none"),""===t?E:(ot(this.renderPiece)||this._error(8272,"invalid renderPiece."),_`<div id="${(t=>null!=t?t:E)(s)}" part="piece ${null!=o?o:""}" piece="${t}" style="${it(n)}" ...="${Et(t,this.renderPiece)}"></div>`)}_getAnimationStyles(t,e){if(e){if(t&&("move-start"===e.type||"add-start"===e.type&&this.draggablePieces)){const i="move-start"===e.type?this._getSquareElement(e.source):this._getSparePieceElement(t),s="move-start"===e.type?this._getSquareElement(e.destination):this._getSquareElement(e.square),o=i.getBoundingClientRect(),n=s.getBoundingClientRect();return{position:"absolute",left:o.left-n.left+"px",top:o.top-n.top+"px",width:this._squareSize+"px",height:this._squareSize+"px"}}if(t&&("move"===e.type||"add"===e.type&&this.draggablePieces))return{position:"absolute",transitionProperty:"top, left",transitionDuration:_t(this.moveSpeed)+"ms",top:"0",left:"0",width:this._squareSize+"px",height:this._squareSize+"px"};if(!t&&"clear"===e.type)return t=e.piece,{transitionProperty:"opacity",transitionDuration:_t(this.trashSpeed)+"ms",opacity:"0"};if(t&&"add-start"===e.type)return{opacity:"0"};if(t&&"add"===e.type)return{transitionProperty:"opacity",transitionDuration:_t(this.appearSpeed)+"ms"}}return{}}_mousedownSquare(t){if(!this.draggablePieces&&!this.sparePieces)return;const e=t.currentTarget.getAttribute("data-square");if(null===e||!this._currentPosition.hasOwnProperty(e))return;t.preventDefault();const i=t instanceof MouseEvent?t:t.changedTouches[0];this._beginDraggingPiece(e,this._currentPosition[e],i.clientX,i.clientY)}_mousedownSparePiece(t){if(!this.sparePieces)return;const e=t.currentTarget.querySelector("[part~=piece]").getAttribute("piece");t.preventDefault();const i=t instanceof MouseEvent?t:t.changedTouches[0];this._beginDraggingPiece("spare",e,i.clientX,i.clientY)}_mouseenterSquare(t){if(void 0!==this._dragState)return;const e=t.currentTarget.getAttribute("data-square");if(!pt(e))return;const i=this._currentPosition.hasOwnProperty(e)&&this._currentPosition[e];this.dispatchEvent(new CustomEvent("mouseover-square",{bubbles:!0,detail:{square:e,piece:i,position:nt(this._currentPosition),orientation:this.orientation}}))}_mouseleaveSquare(t){if(void 0!==this._dragState)return;const e=t.currentTarget.getAttribute("data-square");if(!pt(e))return;const i=this._currentPosition.hasOwnProperty(e)&&this._currentPosition[e];this.dispatchEvent(new CustomEvent("mouseout-square",{bubbles:!0,detail:{square:e,piece:i,position:nt(this._currentPosition),orientation:this.orientation}}))}setPosition(t,e=!0){if(t=wt(t),!yt(t))throw this._error(6482,"Invalid value passed to the position method.",t);if(e){const e=this._calculateAnimations(this._currentPosition,t);this._doAnimations(e,this._currentPosition,t)}this._setCurrentPosition(t),this.requestUpdate()}fen(){return Ct(this._currentPosition)}start(t){this.setPosition("start",t)}clear(t){this.setPosition({},t)}move(...t){let e=!0;const i={};for(const s of t){if(!1===s){e=!1;continue}if(!ft(s)){this._error(2826,"Invalid move passed to the move method.",s);continue}const[t,o]=s.split("-");i[t]=o}const s=Mt(this._currentPosition,i);return this.setPosition(s,e),s}flip(){this.orientation="white"===this.orientation?"black":"white"}resize(){this.requestUpdate()}firstUpdated(){this.requestUpdate(),void 0!==window.ResizeObserver&&new ResizeObserver((()=>{this.resize()})).observe(this)}connectedCallback(){super.connectedCallback(),window.addEventListener("mousemove",this._mousemoveWindow),window.addEventListener("mouseup",this._mouseupWindow),window.addEventListener("touchmove",this._mousemoveWindow,{passive:!1}),window.addEventListener("touchend",this._mouseupWindow,{passive:!1})}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("mousemove",this._mousemoveWindow),window.removeEventListener("mouseup",this._mouseupWindow),window.removeEventListener("touchmove",this._mousemoveWindow),window.removeEventListener("touchend",this._mouseupWindow)}_setCurrentPosition(t){const e=nt(this._currentPosition),i=nt(t);Ct(e)!==Ct(i)&&(this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{value:i,oldValue:e}})),this._currentPosition=t)}_isXYOnSquare(t,e){const i=this.shadowRoot.elementsFromPoint(t,e).find((t=>t.classList.contains("square")));return void 0===i?"offboard":i.getAttribute("data-square")}_highlightSquare(t,e=!0){e?this._highlightedSquares.add(t):this._highlightedSquares.delete(t),this.requestUpdate("_highlightedSquares")}async _snapbackDraggedPiece(){At(this._dragState);const{source:t,piece:e}=this._dragState;return"spare"===t?this._trashDraggedPiece():(this._dragState={state:"snapback",piece:e,source:t},this.requestUpdate(),await new Promise((t=>setTimeout(t,0))),new Promise((i=>{const s=()=>{this._draggedPieceElement.removeEventListener("transitionend",s),i(),this.dispatchEvent(new CustomEvent("snapback-end",{bubbles:!0,detail:{piece:e,square:t,position:nt(this._currentPosition),orientation:this.orientation}}))};this._draggedPieceElement.addEventListener("transitionend",s)})))}async _trashDraggedPiece(){At(this._dragState);const{source:t,piece:e}=this._dragState,i=nt(this._currentPosition);return delete i[t],this._setCurrentPosition(i),this._dragState={state:"trash",piece:e,x:this._dragState.x,y:this._dragState.y,source:this._dragState.source},this.requestUpdate(),await new Promise((t=>setTimeout(t,0))),new Promise((t=>{const e=()=>{this._draggedPieceElement.removeEventListener("transitionend",e),t()};this._draggedPieceElement.addEventListener("transitionend",e)}))}async _dropDraggedPieceOnSquare(t){At(this._dragState);const{source:e,piece:i}=this._dragState,s=nt(this._currentPosition);return delete s[e],s[t]=i,this._setCurrentPosition(s),this._dragState={state:"snap",piece:i,location:t,source:t},this.requestUpdate(),await new Promise((t=>setTimeout(t,0))),new Promise((s=>{const o=()=>{this._draggedPieceElement.removeEventListener("transitionend",o),s(),this.dispatchEvent(new CustomEvent("snap-end",{bubbles:!0,detail:{source:e,square:t,piece:i}}))};this._draggedPieceElement.addEventListener("transitionend",o)}))}_beginDraggingPiece(t,e,i,s){const o=new CustomEvent("drag-start",{bubbles:!0,cancelable:!0,detail:{source:t,piece:e,position:nt(this._currentPosition),orientation:this.orientation}});this.dispatchEvent(o),o.defaultPrevented||(this._dragState={state:"dragging",x:i,y:s,piece:e,location:"spare"===t?"offboard":t,source:t},this.requestUpdate())}_updateDraggedPiece(t,e){At(this._dragState),this._dragState.x=t,this._dragState.y=e,this.requestUpdate();const i=this._isXYOnSquare(t,e);i!==this._dragState.location&&(pt(this._dragState.location)&&this._highlightSquare(this._dragState.location,!1),pt(i)&&this._highlightSquare(i),this.dispatchEvent(new CustomEvent("drag-move",{bubbles:!0,detail:{newLocation:i,oldLocation:this._dragState.location,source:this._dragState.source,piece:this._dragState.piece,position:nt(this._currentPosition),orientation:this.orientation}})),this._dragState.location=i)}async _stopDraggedPiece(t){At(this._dragState);const{source:e,piece:i}=this._dragState;let s="drop";"offboard"===t&&(s="trash"===this.dropOffBoard?"trash":"snapback");const o=nt(this._currentPosition),n=nt(this._currentPosition);"spare"===e&&pt(t)&&(o[t]=i),pt(e)&&(delete o[e],pt(t)&&(o[t]=i));const r=new CustomEvent("drop",{bubbles:!0,detail:{source:e,target:t,piece:i,newPosition:o,oldPosition:n,orientation:this.orientation,setAction(t){s=t}}});this.dispatchEvent(r),this._highlightedSquares.clear(),"snapback"===s?await this._snapbackDraggedPiece():"trash"===s?await this._trashDraggedPiece():"drop"===s&&await this._dropDraggedPieceOnSquare(t),this._dragState=void 0,this.requestUpdate()}_calculateAnimations(t,e){t=nt(t),e=nt(e);const i=[],s={};for(const i in e)e.hasOwnProperty(i)&&t.hasOwnProperty(i)&&t[i]===e[i]&&(delete t[i],delete e[i]);for(const o in e){if(!e.hasOwnProperty(o))continue;const n=Pt(t,e[o],o);n&&(i.push({type:"move",source:n,destination:o,piece:e[o]}),delete t[n],delete e[o],s[o]=!0)}for(const t in e)e.hasOwnProperty(t)&&(i.push({type:"add",square:t,piece:e[t]}),delete e[t]);for(const e in t)t.hasOwnProperty(e)&&(s.hasOwnProperty(e)||(i.push({type:"clear",square:e,piece:t[e]}),delete t[e]));return i}async _doAnimations(t,e,i){if(0===t.length)return;let s=0;const o=()=>{s++,s===t.length&&(this.shadowRoot.removeEventListener("transitionend",o),this._animations.clear(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("move-end",{bubbles:!0,detail:{oldPosition:nt(e),newPosition:nt(i)}})))};this.shadowRoot.addEventListener("transitionend",o),this._animations.clear();for(const e of t)"add"===e.type||"add-start"===e.type?this._animations.set(e.square,Object.assign(Object.assign({},e),{type:"add-start"})):"move"===e.type||"move-start"===e.type?this._animations.set(e.destination,Object.assign(Object.assign({},e),{type:"move-start"})):this._animations.set(e.square,e);this.requestUpdate(),await new Promise((t=>setTimeout(t,0))),this._animations.clear();for(const e of t)"move"===e.type||"move-start"===e.type?this._animations.set(e.destination,e):this._animations.set(e.square,e);this.requestUpdate()}_error(t,e,i){const s=`Chessboard Error ${t} : ${e}`;return this.dispatchEvent(new ErrorEvent("error",{message:s})),Error(s)}};qt.styles=lt,St([Y({converter:t=>wt(t)})],qt.prototype,"position",null),St([Y({attribute:"hide-notation",type:Boolean})],qt.prototype,"hideNotation",void 0),St([Y()],qt.prototype,"orientation",void 0),St([Y({attribute:"draggable-pieces",type:Boolean})],qt.prototype,"draggablePieces",void 0),St([Y({attribute:"drop-off-board"})],qt.prototype,"dropOffBoard",void 0),St([Y({attribute:"piece-theme"})],qt.prototype,"pieceTheme",void 0),St([Y({attribute:!1})],qt.prototype,"renderPiece",void 0),St([Y({attribute:"move-speed"})],qt.prototype,"moveSpeed",void 0),St([Y({attribute:"snapback-speed"})],qt.prototype,"snapbackSpeed",void 0),St([Y({attribute:"snap-speed"})],qt.prototype,"snapSpeed",void 0),St([Y({attribute:"trash-speed"})],qt.prototype,"trashSpeed",void 0),St([Y({attribute:"appear-speed"})],qt.prototype,"appearSpeed",void 0),St([Y({attribute:"spare-pieces",type:Boolean})],qt.prototype,"sparePieces",void 0),St([function(t,e){return(({finisher:t,descriptor:e})=>(i,s)=>{var o;if(void 0===s){const s=null!==(o=i.originalKey)&&void 0!==o?o:i.key,n=null!=e?{kind:"method",placement:"prototype",key:s,descriptor:e(i.key)}:{...i,key:s};return null!=t&&(n.finisher=function(e){t(e,s)}),n}{const o=i.constructor;void 0!==e&&Object.defineProperty(i,s,e(s)),null==t||t(o,s)}})({descriptor:i=>{const s={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;s.get=function(){var i,s;return void 0===this[e]&&(this[e]=null!==(s=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==s?s:null),this[e]}}return s}})}('[part~="dragged-piece"]')],qt.prototype,"_draggedPieceElement",void 0),qt=St([(t=>e=>"function"==typeof e?((t,e)=>(window.customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:s}=e;return{kind:i,elements:s,finisher(e){window.customElements.define(t,e)}}})(t,e))("chess-board")],qt);export{ht as COLUMNS,qt as ChessBoardElement,at as START_FEN,mt as START_POSITION,dt as blackPieces,Mt as calculatePositionFromMoves,gt as fenToObj,Pt as findClosestPiece,ut as getSquareColor,wt as normalizePozition,Ct as objToFen,$t as renderWikipediaSVGPiece,bt as validFen,ft as validMove,vt as validPieceCode,yt as validPositionObject,pt as validSquare,ct as whitePieces}; |
@@ -0,9 +1,51 @@ | ||
Name: @lit/reactive-element | ||
Version: 1.0.0 | ||
License: BSD-3-Clause | ||
Private: false | ||
Description: A simple low level base class for creating fast, lightweight web components | ||
Repository: https://github.com/lit/lit.git | ||
Homepage: https://lit.dev/ | ||
Author: Google LLC | ||
License Copyright: | ||
=== | ||
BSD 3-Clause License | ||
Copyright (c) 2017 Google LLC. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--- | ||
Name: lit-html | ||
Version: 1.2.1 | ||
Version: 2.0.0 | ||
License: BSD-3-Clause | ||
Private: false | ||
Description: HTML template literals in JavaScript | ||
Repository: git+https://github.com/Polymer/lit-html.git | ||
Homepage: https://lit-html.polymer-project.org/ | ||
Author: The Polymer Authors | ||
Description: HTML templates literals in JavaScript | ||
Repository: https://github.com/lit/lit.git | ||
Homepage: https://lit.dev/ | ||
Author: Google LLC | ||
License Copyright: | ||
@@ -14,3 +56,3 @@ === | ||
Copyright (c) 2017, The Polymer Authors. All rights reserved. | ||
Copyright (c) 2017 Google LLC. All rights reserved. | ||
@@ -20,12 +62,12 @@ Redistribution and use in source and binary forms, with or without | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
@@ -47,9 +89,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
Name: lit-element | ||
Version: 2.3.1 | ||
Version: 3.0.0 | ||
License: BSD-3-Clause | ||
Private: false | ||
Description: A simple base class for creating fast, lightweight web components | ||
Repository: git+https://github.com/Polymer/lit-element.git | ||
Homepage: https://lit-element.polymer-project.org/ | ||
Author: The Polymer Authors | ||
Repository: https://github.com/lit/lit.git | ||
Homepage: https://lit.dev/ | ||
Author: Google LLC | ||
License Copyright: | ||
@@ -60,3 +102,3 @@ === | ||
Copyright (c) 2017, The Polymer Authors. All rights reserved. | ||
Copyright (c) 2017 Google LLC. All rights reserved. | ||
@@ -66,12 +108,12 @@ Redistribution and use in source and binary forms, with or without | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
@@ -78,0 +120,0 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
@@ -29,3 +29,3 @@ /** | ||
[from: string]: string; | ||
}) => any; | ||
}) => PositionObject; | ||
//# sourceMappingURL=chess-utils.d.ts.map |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
import { LitElement } from 'lit-element'; | ||
import { LitElement, nothing } from 'lit'; | ||
import { PositionObject, Position, Piece } from './chess-utils.js'; | ||
@@ -54,3 +54,3 @@ export { fenToObj, objToFen } from './chess-utils.js'; | ||
} | ||
export declare type RenderPieceFunction = (piece: Piece, container: Element) => void; | ||
export declare type RenderPieceFunction = (piece: Piece, container: HTMLElement) => void; | ||
/** | ||
@@ -156,3 +156,3 @@ * A custom element that renders an interactive chess board. | ||
export declare class ChessBoardElement extends LitElement { | ||
static styles: import("lit-element").CSSResult; | ||
static styles: import("lit").CSSResult; | ||
/** | ||
@@ -259,7 +259,7 @@ * The current position of the board, as a `PositionObject`. This property may | ||
private _getSparePieceElement; | ||
render(): import("lit-element").TemplateResult; | ||
render(): import("lit-html").TemplateResult<1>; | ||
private _renderSparePieces; | ||
private _renderDraggedPiece; | ||
private _renderBoard; | ||
_renderPiece(piece: Piece | undefined, styles: Partial<CSSStyleDeclaration>, isDragSource?: boolean, id?: string, part?: string): {}; | ||
_renderPiece(piece: Piece | undefined, styles: Partial<CSSStyleDeclaration>, isDragSource?: boolean, id?: string, part?: string): import("lit-html").TemplateResult<1> | typeof nothing; | ||
private _getAnimationStyles; | ||
@@ -272,6 +272,2 @@ private _mousedownSquare; | ||
private _mouseupWindow; | ||
private _touchstartSquare; | ||
private _touchstartSparePiece; | ||
private _touchmoveWindow; | ||
private _touchendWindow; | ||
/** | ||
@@ -311,3 +307,3 @@ * Sets the position of the board. | ||
*/ | ||
move(...args: Array<string | false>): any; | ||
move(...args: Array<string | false>): PositionObject; | ||
/** | ||
@@ -314,0 +310,0 @@ * Flip the orientation. |
@@ -13,7 +13,7 @@ /** | ||
}; | ||
import { customElement, property, LitElement, html, query } from 'lit-element'; | ||
import { render, directive, removeNodes } from 'lit-html'; | ||
import { styleMap } from 'lit-html/directives/style-map.js'; | ||
import { ifDefined } from 'lit-html/directives/if-defined.js'; | ||
import { nothing } from 'lit-html'; | ||
import { LitElement, html, nothing, render, noChange } from 'lit'; | ||
import { customElement, property, query } from 'lit/decorators.js'; | ||
import { directive, Directive } from 'lit/directive.js'; | ||
import { styleMap } from 'lit/directives/style-map.js'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { deepCopy, interpolateTemplate, isString, isFunction } from './utils.js'; | ||
@@ -56,10 +56,17 @@ import { styles } from './chessboard-styles.js'; | ||
const sparePieceId = (piece) => `spare-piece-${piece}`; | ||
const renderPieceDirective = directive((piece, renderPiece) => (part) => { | ||
if (isFunction(renderPiece)) { | ||
renderPiece(piece, part.committer.element); | ||
class RenderPieceDirective extends Directive { | ||
render(_piece, _renderPiece) { | ||
return nothing; | ||
} | ||
else { | ||
removeNodes(part.committer.element, part.committer.element.firstChild); | ||
update(part, [piece, renderPiece]) { | ||
if (isFunction(renderPiece)) { | ||
renderPiece(piece, part.element); | ||
} | ||
else { | ||
part.element.replaceChildren(); | ||
} | ||
return noChange; | ||
} | ||
}); | ||
} | ||
const renderPieceDirective = directive(RenderPieceDirective); | ||
/** | ||
@@ -248,35 +255,19 @@ * A custom element that renders an interactive chess board. | ||
var _a; | ||
if (((_a = this._dragState) === null || _a === void 0 ? void 0 : _a.state) === 'dragging') { | ||
this._updateDraggedPiece(e.clientX, e.clientY); | ||
} | ||
}; | ||
this._mouseupWindow = (e) => { | ||
var _a; | ||
// do nothing if we are not dragging a piece | ||
// Do nothing if we are not dragging a piece | ||
if (!(((_a = this._dragState) === null || _a === void 0 ? void 0 : _a.state) === 'dragging')) { | ||
return; | ||
} | ||
// get the location | ||
const location = this._isXYOnSquare(e.clientX, e.clientY); | ||
this._stopDraggedPiece(location); | ||
}; | ||
this._touchmoveWindow = (e) => { | ||
var _a; | ||
// do nothing if we are not dragging a piece | ||
if (!(((_a = this._dragState) === null || _a === void 0 ? void 0 : _a.state) === 'dragging')) { | ||
return; | ||
} | ||
// prevent screen from scrolling | ||
// Prevent screen from scrolling | ||
e.preventDefault(); | ||
const touch = e.changedTouches[0]; | ||
this._updateDraggedPiece(touch.clientX, touch.clientY); | ||
const pos = e instanceof MouseEvent ? e : e.changedTouches[0]; | ||
this._updateDraggedPiece(pos.clientX, pos.clientY); | ||
}; | ||
this._touchendWindow = (e) => { | ||
this._mouseupWindow = (e) => { | ||
var _a; | ||
// do nothing if we are not dragging a piece | ||
// Do nothing if we are not dragging a piece | ||
if (!(((_a = this._dragState) === null || _a === void 0 ? void 0 : _a.state) === 'dragging')) { | ||
return; | ||
} | ||
// get the location | ||
const location = this._isXYOnSquare(e.changedTouches[0].clientX, e.changedTouches[0].clientY); | ||
const pos = e instanceof MouseEvent ? e : e.changedTouches[0]; | ||
const location = this._isXYOnSquare(pos.clientX, pos.clientY); | ||
this._stopDraggedPiece(location); | ||
@@ -363,3 +354,3 @@ }; | ||
@mousedown=${this._mousedownSparePiece} | ||
@touchstart=${this._touchstartSparePiece} | ||
@touchstart=${this._mousedownSparePiece} | ||
> | ||
@@ -453,3 +444,3 @@ ${this._renderPiece(p, {}, false, sparePieceId(p))} | ||
@mouseleave=${this._mouseleaveSquare} | ||
@touchstart=${this._touchstartSquare} | ||
@touchstart=${this._mousedownSquare} | ||
> | ||
@@ -562,3 +553,2 @@ ${this.showNotation && row === 7 | ||
_mousedownSquare(e) { | ||
e.preventDefault(); | ||
// do nothing if we're not draggable. sparePieces implies draggable | ||
@@ -571,12 +561,10 @@ if (!this.draggablePieces && !this.sparePieces) { | ||
const square = squareEl.getAttribute('data-square'); | ||
if (square === null) { | ||
if (square === null || !this._currentPosition.hasOwnProperty(square)) { | ||
return; | ||
} | ||
if (!this._currentPosition.hasOwnProperty(square)) { | ||
return; | ||
} | ||
this._beginDraggingPiece(square, this._currentPosition[square], e.clientX, e.clientY); | ||
e.preventDefault(); | ||
const pos = e instanceof MouseEvent ? e : e.changedTouches[0]; | ||
this._beginDraggingPiece(square, this._currentPosition[square], pos.clientX, pos.clientY); | ||
} | ||
_mousedownSparePiece(e) { | ||
e.preventDefault(); | ||
// do nothing if sparePieces is not enabled | ||
@@ -589,3 +577,5 @@ if (!this.sparePieces) { | ||
const piece = pieceEl.getAttribute('piece'); | ||
this._beginDraggingPiece('spare', piece, e.clientX, e.clientY); | ||
e.preventDefault(); | ||
const pos = e instanceof MouseEvent ? e : e.changedTouches[0]; | ||
this._beginDraggingPiece('spare', piece, pos.clientX, pos.clientY); | ||
} | ||
@@ -604,7 +594,5 @@ _mouseenterSquare(e) { | ||
} | ||
// get the piece on this square | ||
let piece = false; | ||
if (this._currentPosition.hasOwnProperty(square)) { | ||
piece = this._currentPosition[square]; | ||
} | ||
// Get the piece on this square | ||
const piece = this._currentPosition.hasOwnProperty(square) && | ||
this._currentPosition[square]; | ||
this.dispatchEvent(new CustomEvent('mouseover-square', { | ||
@@ -621,3 +609,3 @@ bubbles: true, | ||
_mouseleaveSquare(e) { | ||
// do not fire this event if we are dragging a piece | ||
// Do not fire this event if we are dragging a piece | ||
// NOTE: this should never happen, but it's a safeguard | ||
@@ -627,3 +615,2 @@ if (this._dragState !== undefined) { | ||
} | ||
// get the square | ||
const square = e.currentTarget.getAttribute('data-square'); | ||
@@ -634,7 +621,5 @@ // NOTE: this should never happen; defensive | ||
} | ||
// get the piece on this square | ||
let piece = false; | ||
if (this._currentPosition.hasOwnProperty(square)) { | ||
piece = this._currentPosition[square]; | ||
} | ||
// Get the piece on this square | ||
const piece = this._currentPosition.hasOwnProperty(square) && | ||
this._currentPosition[square]; | ||
// execute their function | ||
@@ -651,28 +636,2 @@ this.dispatchEvent(new CustomEvent('mouseout-square', { | ||
} | ||
_touchstartSquare(e) { | ||
// do nothing if we're not draggable. sparePieces implies draggable | ||
if (!this.draggablePieces && !this.sparePieces) { | ||
return; | ||
} | ||
// do nothing if there is no piece on this square | ||
const squareEl = e.target.closest('[data-square]'); | ||
const square = squareEl.getAttribute('data-square'); | ||
if (!validSquare(square)) { | ||
return; | ||
} | ||
if (!this._currentPosition.hasOwnProperty(square)) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
this._beginDraggingPiece(square, this._currentPosition[square], e.changedTouches[0].clientX, e.changedTouches[0].clientY); | ||
} | ||
_touchstartSparePiece(e) { | ||
// do nothing if sparePieces is not enabled | ||
if (!this.sparePieces) | ||
return; | ||
const pieceEl = e.target.closest('[piece]'); | ||
const piece = pieceEl.getAttribute('piece'); | ||
e.preventDefault(); | ||
this._beginDraggingPiece('spare', piece, e.changedTouches[0].clientX, e.changedTouches[0].clientY); | ||
} | ||
// ------------------------------------------------------------------------- | ||
@@ -788,6 +747,6 @@ // Public Methods | ||
window.addEventListener('mouseup', this._mouseupWindow); | ||
window.addEventListener('touchmove', this._touchmoveWindow, { | ||
window.addEventListener('touchmove', this._mousemoveWindow, { | ||
passive: false, | ||
}); | ||
window.addEventListener('touchend', this._touchendWindow, { | ||
window.addEventListener('touchend', this._mouseupWindow, { | ||
passive: false, | ||
@@ -800,4 +759,4 @@ }); | ||
window.removeEventListener('mouseup', this._mouseupWindow); | ||
window.removeEventListener('touchmove', this._touchmoveWindow); | ||
window.removeEventListener('touchend', this._touchendWindow); | ||
window.removeEventListener('touchmove', this._mousemoveWindow); | ||
window.removeEventListener('touchend', this._mouseupWindow); | ||
} | ||
@@ -827,4 +786,5 @@ // ------------------------------------------------------------------------- | ||
_isXYOnSquare(x, y) { | ||
// TODO: test that this works with the polyfill | ||
const elements = this.shadowRoot.elementsFromPoint(x, y); | ||
// TODO: remove cast when TypeScript fixes ShadowRoot.elementsFromPoint | ||
const elements = this | ||
.shadowRoot.elementsFromPoint(x, y); | ||
const squareEl = elements.find((e) => e.classList.contains('square')); | ||
@@ -831,0 +791,0 @@ const square = squareEl === undefined |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare const styles: import("lit-element").CSSResult; | ||
export declare const styles: import("lit").CSSResult; | ||
//# sourceMappingURL=chessboard-styles.d.ts.map |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
import { css } from 'lit-element'; | ||
import { css } from 'lit'; | ||
export const styles = css ` | ||
@@ -10,0 +10,0 @@ :host { |
@@ -10,4 +10,4 @@ /** | ||
export declare const isInteger: (n: unknown) => n is number; | ||
export declare const deepCopy: (thing: unknown) => any; | ||
export declare const deepCopy: <T>(thing: T) => T; | ||
export declare const interpolateTemplate: (str: string, obj: object) => string; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { TemplateResult } from 'lit-html'; | ||
import { TemplateResult } from 'lit'; | ||
import { RenderPieceFunction } from './chessboard-element.js'; | ||
@@ -3,0 +3,0 @@ export declare const renderPiece: RenderPieceFunction; |
@@ -1,8 +0,4 @@ | ||
import { render, svg, html } from 'lit-html'; | ||
import { render, svg, html } from 'lit'; | ||
export const renderPiece = (piece, container) => { | ||
render(html ` | ||
<svg class="piece-image" viewBox="0 0 45 45"> | ||
${pieces[piece]} | ||
</svg> | ||
`, container); | ||
render(html ` <svg class="piece-image" viewBox="0 0 45 45">${pieces[piece]}</svg> `, container); | ||
}; | ||
@@ -9,0 +5,0 @@ // Pieces taked from: https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces |
@@ -7,3 +7,3 @@ { | ||
"license": "MIT", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"repository": { | ||
@@ -17,18 +17,17 @@ "type": "git", | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.9.1", | ||
"@typescript-eslint/parser": "^3.9.1", | ||
"eslint": "^7.7.0", | ||
"eslint-config-prettier": "^6.7.0", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.26.3", | ||
"rollup-plugin-filesize": "^9.0.2", | ||
"@rollup/plugin-node-resolve": "^13.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.39.0", | ||
"rollup-plugin-filesize": "^9.1.0", | ||
"rollup-plugin-license": "^2.2.0", | ||
"rollup-plugin-minify-html-literals": "^1.2.3", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"typescript": "~3.9.6", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typescript": "^4.4.3", | ||
"web-component-analyzer": "^1.0.2" | ||
}, | ||
"scripts": { | ||
"serve": "es-dev-server --node-resolve", | ||
"build": "npm run build:ts && npm run analyze && npm run api", | ||
@@ -43,5 +42,4 @@ "build:ts": "tsc", | ||
"dependencies": { | ||
"lit-element": "^2.2.1", | ||
"lit-html": "^1.2.1" | ||
"lit": "^2.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
9855887
3091.08%1
-50%293
318.57%17776
486.47%1
Infinity%5
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed