roulette-wheel/dist/bundle.js
2022-01-13 21:12:18 +01:00

1 line
6.5 KiB
JavaScript

(()=>{"use strict";var e={583:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Component=void 0,t.Component=class{constructor(e){this.el=e}removeChildren(){if(this.el.childNodes.length>0)for(;this.el.firstChild;)this.el.removeChild(this.el.firstChild)}}},983:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ItemRemoval=void 0;const n=o(583);class a extends n.Component{constructor(e){const t=document.createElement("img");t.src="static/close.png",t.alt="delete",t.className="item-delete",t.id=`${e}-delete`,super(t)}}t.ItemRemoval=a},658:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MenuItem=void 0;const n=o(583),a=o(983);class l extends n.Component{constructor(e,t,o){const n=new a.ItemRemoval(e),l=document.createElement("li");l.className="menu-item",l.id=`${e}-item`,l.textContent=t,l.style.backgroundColor=o,l.appendChild(n.el),super(l),this.deleteItem=n,this.appearAnimation()}appearAnimation(){this.el.animate([{transform:"scale(1.25)"},{transform:"scale(1.00)"}],{duration:500})}}t.MenuItem=l},191:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ItemList=void 0,t.ItemList=class{constructor(e){this.items=[],this.maximumSize=e}add(e){this.items.length<this.maximumSize&&this.items.push(e)}removeById(e){const t=this.items.find((t=>t.id===e));t&&this.remove(t)}remove(e){this.items.splice(this.items.indexOf(e),1)}clear(){this.items=[]}}},418:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Item=void 0,t.Item=class{constructor(e,t,o){this.id=e,this.name=t,this.color=o}}},497:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IdPool=void 0;class o{static initializeIdsPool(e){for(let t=1;t<=e;t++)o.avaliableIds[t]=t}static getAnId(){const e=this.avaliableIds.pop();if(e)return e;alert("Maxiumum number of items!")}static addId(e){this.avaliableIds.push(e)}}t.IdPool=o,o.avaliableIds=[]},617:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LightDarkMode=void 0,t.LightDarkMode=class{}},974:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.avaliableRGBs=void 0,t.avaliableRGBs=["rgba(255, 0, 0, 0.5)","rgba(0, 255, 0, 0.5)","rgba(0, 0, 255, 0.5)","rgba(255, 255, 0, 0.5)","rgba(0, 255, 255, 0.5)","rgba(205, 127, 50, 0.5)","rgba(115, 147, 179, 0.5)","rgba(255, 117, 24, 0.5)","rgba(255, 0, 255, 0.5)","rgba(191, 64, 191, 0.5)","rgba(47, 197, 114, 0.5)","rgba(255, 222, 173, 0.5)","rgba(204, 204, 255, 0.5)","rgba(93, 63, 211, 0.5)","rgba(250, 128, 114, 0.5)","rgba(0, 255, 127, 0.5)"]}},t={};function o(n){var a=t[n];if(void 0!==a)return a.exports;var l=t[n]={exports:{}};return e[n](l,l.exports,o),l.exports}(()=>{const e=o(658),t=o(418),n=o(191),a=o(497),l=o(617),i=o(974),s=document.getElementsByClassName("add-item-button")[0],r=document.querySelector("input"),d=document.getElementsByClassName("menu-item-list")[0],c=document.getElementsByClassName("counter")[0],m=document.getElementsByClassName("remove-all-items-button")[0],h=document.getElementsByClassName("light-dark-mode")[0],u=document.querySelector("canvas"),g=document.querySelector("body"),f=h.querySelector("img"),v=document.getElementsByClassName("winner")[0],b=document.querySelector("footer"),p=document.getElementsByClassName("icons-authors")[0],y=document.getElementsByClassName("roulette-wheel")[0],I=new Audio("/static/roulette-wheel.mp3"),M=u.getContext("2d");u.width=y.offsetWidth,u.height=y.offsetHeight;const C=u.width/2,k=u.height/2,P=u.height/2-5,x=1e3/60,E=new n.ItemList(16),B=[];let w=0;function L(){c.textContent=`${E.items.length}/16`,c.animate([{transform:"scale(1.5)"},{transform:"scale(1.00)"}],{duration:500})}function _(e){const t=360/B.length;let o=t+e;M.clearRect(0,0,u.width,u.height),M.beginPath(),M.save(),M.translate(C+P+50,k),M.lineTo(0,-20),M.lineTo(0,20),M.lineTo(-50,0),M.fillStyle="#C4B454",M.fill(),M.stroke(),M.restore(),M.arc(C,k,P,0,2*Math.PI),M.stroke();for(let n=0;n<B.length;n++){M.beginPath(),M.lineTo(C,k),console.log(outerHeight),console.log(outerWidth),outerWidth<1280?M.font="bold 10px verdana, sans-serif":M.font="bold 24px verdana, sans-serif",M.arc(C,k,P,e*Math.PI/180,o*Math.PI/180),M.lineTo(C,k),M.fillStyle=E.items[n].color,M.fill(),M.save(),M.fillStyle="black";const a=E.items[n].name;if(B.length>1){const o=(e+t/2)*Math.PI/180,n=C+Math.cos(o)*P/2,l=k+Math.sin(o)*P/2;M.translate(n,l),M.rotate(Math.PI/B.length+Math.PI/180*e),M.fillText(a,-M.measureText(a).width/2,0)}else M.fillText(a,C,k);M.restore(),1!==B.length&&M.stroke(),e+=t,o+=t}}c.textContent="0/16",I.volume=.2,l.LightDarkMode.currentMode="dark",a.IdPool.initializeIdsPool(16),s.addEventListener("click",(()=>{if(!N){G();const o=r.value;if(o){const n=a.IdPool.getAnId();if(n){const l=i.avaliableRGBs[n%i.avaliableRGBs.length],s=new t.Item(n,o,l),r=new e.MenuItem(n,o,l);r.deleteItem.el.addEventListener("click",(()=>{N||(G(),r.el.remove(),B.splice(B.indexOf(r),1),E.remove(s),a.IdPool.addId(s.id),L(),_(0))})),function(e,t){t.el.addEventListener("click",(()=>{if(!N){const o=i.avaliableRGBs.indexOf(t.el.style.backgroundColor);if(-1!==o){const n=i.avaliableRGBs[(o+1)%i.avaliableRGBs.length];t.el.style.backgroundColor=n,e.color=n,_(0)}}}))}(s,r),E.add(s),B.push(r),d.appendChild(r.el),L(),S=Math.floor(Math.random()*B.length),T=360/B.length,j=7200+T*S,_(0)}}}})),g.addEventListener("keyup",(e=>{"Enter"===e.key&&s.click()})),m.addEventListener("click",(()=>{N||(G(),B.length>0&&(B.forEach((e=>e.el.remove())),B.length=0,E.clear(),a.IdPool.initializeIdsPool(16),L(),_(0)))})),h.addEventListener("click",(()=>{f.animate([{transform:"rotate(360deg)"}],{duration:500}),"dark"===l.LightDarkMode.currentMode?(f.src="static/sun.png",g.style.backgroundColor="#FAF9F6",g.style.color="black",l.LightDarkMode.currentMode="light"):(f.src="static/moon.png",g.style.backgroundColor="#121212",g.style.color="white",l.LightDarkMode.currentMode="dark")})),_(0),u.addEventListener("click",(function(){B.length>1&&!N&&(G()?_(0):(I.play(),s.style.background="#C0C0C0",m.style.background="#C0C0C0",S=Math.floor(Math.random()*B.length),O=E.items[S].name,T=360/B.length,w=0,j=7200+(B.length-1-S)*T+Math.random()*T,R=j/50*x,A()))})),b.addEventListener("click",(()=>{p.hidden=!p.hidden}));let N,O,R,S=Math.floor(Math.random()*B.length),T=360/B.length,j=7200+T*S;function A(){const e=(0,o=j,(t=w)==(n=R)?0+o:o*(1-Math.pow(2,-10*t/n))+0);var t,o,n;w<R||j-e>.1?setTimeout((()=>{_(e),w+=x,N=window.requestAnimationFrame(A)}),x):(window.cancelAnimationFrame(N),N=null,v.textContent=`Winner: ${O}`,s.style.background="#6082B6",m.style.background="#6082B6",v.animate({opacity:[.5,1],easing:["ease-in","ease-out"]},1e3))}function G(){return!!O&&(O="",v.textContent="",!0)}})()})();