(function(){'use strict';function e(e,t,o){function a(){for(var e=Math.cos,a=[new THREE.Vector3(1,1,1),new THREE.Vector3(1,1,-1),new THREE.Vector3(-1,1,-1),new THREE.Vector3(-1,1,1),new THREE.Vector3(1,-1,1),new THREE.Vector3(1,-1,-1),new THREE.Vector3(-1,-1,-1),new THREE.Vector3(-1,-1,1)],s=0;8>s;s++)C.push([]),L.push([]);for(var r=i/2,l=new THREE.Vector3(b,f,z),c=0;c<=o;c++){var m=c/o,d=m*r,g=e(d),p=n(d);if(c==o){M.set(0,1,0);var h=M.clone().multiplyScalar(t).add(l);C[0].push(h),A.push(h);var v=M.clone();L[0].push(v),E.push(v);continue}for(var S=0;S<=o;S++){var w=S/o,u=w*r;M.x=g*e(u),M.y=p,M.z=g*n(u);var h=M.clone().multiplyScalar(t).add(l);C[0].push(h),A.push(h);var v=M.clone().normalize();L[0].push(v),E.push(v)}}for(var T=1;8>T;T++)for(var h,s=0;sr;r++){e=_*r;for(var n=0;ne;e++)for(var t=e*_,s=4*_+t,r=!0&e,n=0;ns;s++)for(var r=_*e[s],n=_*t[s],l=1>=s,m=0;mn;n++)for(var l=t[n]*_,m=s[n]*_,g=0;g<=e;g++){var p=l+o+g*x,a=l+(g==e?_-1:o+(g+1)*x),h=m+o+g*x,c=m+(g==e?_-1:o+(g+1)*x);r[n]?(P.push(p),P.push(h),P.push(a),P.push(a),P.push(h),P.push(c)):(P.push(p),P.push(a),P.push(h),P.push(a),P.push(c),P.push(h))}}THREE.BufferGeometry.call(this),this.type='RoundedBoxGeometry',o=isNaN(o)?1:c(1,d(o));var p,h,y;p=h=y=e,t=e*t,t=l(t,l(p,l(h,l(y)))/2);var b=p/2-t,f=h/2-t,z=y/2-t;this.parameters={width:p,height:h,depth:y,radius:t,radiusSegments:o};var x=o+1,v=x*o+1<<3,S=new THREE.BufferAttribute(new Float32Array(3*v),3),w=new THREE.BufferAttribute(new Float32Array(3*v),3),C=[],L=[],T=new THREE.Vector3,M=new THREE.Vector3,A=[],E=[],P=[],D=x*o,_=x*o+1;a(),r(),s(),m(),g(),u();for(var k=0,V=0;V{let e=0;return new class{constructor(){this.ids=[],this.animations={},this.update=this.update.bind(this),this.raf=0,this.time=0}update(){const e=performance.now(),t=e-this.time;this.time=e;let a=this.ids.length;for(this.raf=a?requestAnimationFrame(this.update):0;a--;)this.animations[this.ids[a]]&&this.animations[this.ids[a]].update(t)}add(t){t.id=e++,this.ids.push(t.id),this.animations[t.id]=t;0!==this.raf||(this.time=performance.now(),this.raf=requestAnimationFrame(this.update))}remove(e){const t=this.ids.indexOf(e.id);0>t||(this.ids.splice(t,1),delete this.animations[e.id],e=null)}}})();class g{constructor(e){!0===e&&this.start()}start(){u.add(this)}stop(){u.remove(this)}update(){}}class p extends g{constructor(e){super(!0),this.game=e,this.container=this.game.dom.game,this.scene=new THREE.Scene,this.renderer=new THREE.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.container.appendChild(this.renderer.domElement),this.camera=new THREE.PerspectiveCamera(2,1,.1,1e4),this.stage={width:2,height:3},this.fov=10,this.createLights(),this.onResize=[],this.resize(),window.addEventListener('resize',()=>this.resize(),!1)}update(){this.renderer.render(this.scene,this.camera)}resize(){this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.renderer.setSize(this.width,this.height),this.camera.fov=this.fov,this.camera.aspect=this.width/this.height;const e=this.stage.width/this.stage.height,t=this.fov*THREE.Math.DEG2RAD;let a=ee())}createLights(){this.lights={holder:new THREE.Object3D,ambient:new THREE.AmbientLight(16777215,.69),front:new THREE.DirectionalLight(16777215,.36),back:new THREE.DirectionalLight(16777215,.19)},this.lights.front.position.set(1.5,5,3),this.lights.back.position.set(-1.5,-5,-3),this.lights.holder.add(this.lights.ambient),this.lights.holder.add(this.lights.front),this.lights.holder.add(this.lights.back),this.scene.add(this.lights.holder)}}e.prototype=Object.create(THREE.BufferGeometry.prototype),e.constructor=e;class h{constructor(e){this.game=e,this.size=3,this.geometry={pieceCornerRadius:.12,edgeCornerRoundness:.15,edgeScale:.82,edgeDepth:.01},this.holder=new THREE.Object3D,this.object=new THREE.Object3D,this.animator=new THREE.Object3D,this.holder.add(this.animator),this.animator.add(this.object),this.game.world.scene.add(this.holder)}init(){this.cubes=[],this.object.children=[],this.object.add(this.game.controls.group),2===this.size?this.scale=1.25:3===this.size?this.scale=1:3{this.cubes.push(e.userData.cube),this.object.add(e)}),this.holder.traverse(e=>{e.frustumCulled&&(e.frustumCulled=!1)}),this.updateColors(this.game.themes.getColors()),this.sizeGenerated=this.size}resize(e=!1){(this.size!==this.sizeGenerated||e)&&(this.size=this.game.preferences.ranges.size.value,this.reset(),this.init(),this.game.saved=!1,this.game.timer.reset(),this.game.storage.clearGame())}reset(){this.game.controls.edges.rotation.set(0,0,0),this.holder.rotation.set(0,0,0),this.object.rotation.set(0,0,0),this.animator.rotation.set(0,0,0)}generatePositions(){const e=this.size-1,t=0==this.size%2?.5-this.size/2:0-d(this.size/2);let a,o,s;for(this.positions=[],a=0;a{const n=new THREE.Object3D,l=s.clone(),c=[];n.position.copy(e.clone().divideScalar(3)),n.add(l),n.name=t,n.edgesName='',e.edges.forEach(e=>{const t=new THREE.Mesh(r,o.clone()),s=['L','R','D','U','B','F'][e],l=a/2;t.position.set(l*[-1,1,0,0,0,0][e],l*[0,0,-1,1,0,0][e],l*[0,0,0,0,-1,1][e]),t.rotation.set(i/2*[0,0,1,-1,0,0][e],i/2*[-1,1,0,0,2,0][e],0),t.scale.set(this.geometry.edgeScale,this.geometry.edgeScale,this.geometry.edgeScale),t.name=s,n.add(t),c.push(s),this.edges.push(t)}),n.userData.edges=c,n.userData.cube=l,n.userData.start={position:n.position.clone(),rotation:n.rotation.clone()},this.pieces.push(n)})}updateColors(e){'object'!=typeof this.pieces&&'object'!=typeof this.edges||(this.pieces.forEach(t=>t.userData.cube.material.color.setHex(e.P)),this.edges.forEach(t=>t.material.color.setHex(e[t.name])))}loadFromData(e){this.size=e.size,this.reset(),this.init(),this.pieces.forEach(t=>{const a=e.names.indexOf(t.name),o=e.positions[a],s=e.rotations[a];t.position.set(o.x,o.y,o.z),t.rotation.set(s.x,s.y,s.z)})}}const y={Power:{In:e=>(e=r(e||1),a=>s(a,e)),Out:e=>(e=r(e||1),a=>1-o(s(a-1,e))),InOut:e=>(e=r(e||1),a=>.5>a?s(2*a,e)/2:(1-o(s(2*a-1-1,e)))/2+.5)},Sine:{In:()=>e=>1+n(i/2*e-i/2),Out:()=>e=>n(i/2*e),InOut:()=>e=>(1+n(i*e-i/2))/2},Back:{Out:e=>(e=e||1.70158,a=>(a-=1)*a*((e+1)*a+e)+1),In:e=>(e=e||1.70158,a=>a*a*((e+1)*a-e))},Elastic:{Out:(e,t)=>{let a=2*i,o=1<=e?e:1,r=(t||.3)/(1>e?e:1),l=r/a*(Math.asin(1/o)||0);return r=a/r,e=>o*s(2,-10*e)*n((e-l)*r)+1}}};class b extends g{constructor(e){super(!1),this.duration=e.duration||500,this.easing=e.easing||(e=>e),this.onUpdate=e.onUpdate||(()=>{}),this.onComplete=e.onComplete||(()=>{}),this.delay=e.delay||!1,this.yoyo=!e.yoyo&&null,this.progress=0,this.value=0,this.delta=0,this.getFromTo(e),this.delay?setTimeout(()=>super.start(),this.delay):super.start(),this.onUpdate(this)}update(e){const t=1*this.value,a=!0===this.yoyo?-1:1;this.progress+=e/this.duration*a,this.value=this.easing(this.progress),this.delta=this.value-t,null!==this.values&&this.updateFromTo(),null===this.yoyo?1>=this.progress?this.onUpdate(this):(this.progress=1,this.value=1,this.onUpdate(this),this.onComplete(this),super.stop()):this.updateYoyo()}updateYoyo(){(1this.progress)&&(this.value=this.progress=1{this.target[e]=this.from[e]+(this.to[e]-this.from[e])*this.value})}getFromTo(e){return e.target&&e.to?void(this.target=e.target||null,this.from=e.from||{},this.to=e.to||null,this.values=[],1>Object.keys(this.from).length&&Object.keys(this.to).forEach(e=>{this.from[e]=this.target[e]}),Object.keys(this.to).forEach(e=>{this.values.push(e)})):void(this.values=null)}}window.addEventListener('touchmove',()=>{}),document.addEventListener('touchmove',e=>{e.preventDefault()},{passive:!1});class v{constructor(e,t){return this.position={current:new THREE.Vector2,start:new THREE.Vector2,delta:new THREE.Vector2,old:new THREE.Vector2,drag:new THREE.Vector2},this.options=Object.assign({calcDelta:!1},t||{}),this.element=e,this.touch=null,this.drag={start:e=>{'mousedown'==e.type&&1!=e.which||'touchstart'==e.type&&1{this.options.calcDelta&&(this.position.old=this.position.current.clone()),this.getPositionCurrent(e),this.options.calcDelta&&(this.position.delta=this.position.current.clone().sub(this.position.old),this.position.drag=this.position.current.clone().sub(this.position.start)),this.onDragMove(this.position)},end:e=>{this.getPositionCurrent(e),this.onDragEnd(this.position),window.removeEventListener(this.touch?'touchmove':'mousemove',this.drag.move,!1),window.removeEventListener(this.touch?'touchend':'mouseup',this.drag.end,!1)}},this.onDragStart=()=>{},this.onDragMove=()=>{},this.onDragEnd=()=>{},this.enable(),this}enable(){return this.element.addEventListener('touchstart',this.drag.start,!1),this.element.addEventListener('mousedown',this.drag.start,!1),this}disable(){return this.element.removeEventListener('touchstart',this.drag.start,!1),this.element.removeEventListener('mousedown',this.drag.start,!1),this}getPositionCurrent(e){const t=e.touches?e.touches[0]||e.changedTouches[0]:e;this.position.current.set(t.pageX,t.pageY)}convertPosition(e){return e.x=2*(e.x/this.element.offsetWidth)-1,e.y=-(2*(e.y/this.element.offsetHeight)-1),e}}const f=0;class x{constructor(e){this.game=e,this.flipConfig=0,this.flipEasings=[y.Power.Out(3),y.Sine.Out(),y.Back.Out(1.5)],this.flipSpeeds=[125,200,300],this.raycaster=new THREE.Raycaster;const t=new THREE.MeshBasicMaterial({depthWrite:!1,transparent:!0,opacity:0,color:13311});this.group=new THREE.Object3D,this.group.name='controls',this.game.cube.object.add(this.group),this.helper=new THREE.Mesh(new THREE.PlaneBufferGeometry(200,200),t.clone()),this.helper.rotation.set(0,i/4,0),this.game.world.scene.add(this.helper),this.edges=new THREE.Mesh(new THREE.BoxBufferGeometry(1,1,1),t.clone()),this.game.world.scene.add(this.edges),this.onSolved=()=>{},this.onMove=()=>{},this.momentum=[],this.scramble=null,this.state=f,this.enabled=!1,this.initDraggable()}enable(){this.draggable.enable(),this.enabled=!0}disable(){this.draggable.disable(),this.enabled=!1}initDraggable(){this.draggable=new v(this.game.dom.game),this.draggable.onDragStart=e=>{if(null===this.scramble&&1!==this.state&&2!==this.state){this.gettingDrag=3===this.state;const t=this.getIntersect(e.current,this.edges,!1);!1!==t&&(this.dragIntersect=this.getIntersect(e.current,this.game.cube.cubes,!0)),!1!==t&&!1!==this.dragIntersect?(this.dragNormal=t.face.normal.round(),this.flipType='layer',this.attach(this.helper,this.edges),this.helper.rotation.set(0,0,0),this.helper.position.set(0,0,0),this.helper.lookAt(this.dragNormal),this.helper.translateZ(.5),this.helper.updateMatrixWorld(),this.detach(this.helper,this.edges)):(this.dragNormal=new THREE.Vector3(0,0,1),this.flipType='cube',this.helper.position.set(0,0,0),this.helper.rotation.set(0,i/4,0),this.helper.updateMatrixWorld());let a=this.getIntersect(e.current,this.helper,!1);!1===a||(this.dragCurrent=this.helper.worldToLocal(a.point),this.dragTotal=new THREE.Vector3,this.state=this.state===f?1:this.state)}},this.draggable.onDragMove=e=>{if(null===this.scramble&&this.state!==f&&(3!==this.state||!1!==this.gettingDrag)){const t=this.getIntersect(e.current,this.helper,!1);if(!1!==t){const a=this.helper.worldToLocal(t.point.clone());if(this.dragDelta=a.clone().sub(this.dragCurrent).setZ(0),this.dragTotal.add(this.dragDelta),this.dragCurrent=a,this.addMomentumPoint(this.dragDelta),1===this.state&&.05this.game.world.width/2?'z':'x';this.flipAxis=new THREE.Vector3,this.flipAxis[t]=1*('x'==t?-1:1)}this.flipAngle=0,this.state=2}else if(2===this.state){const e=this.dragDelta[this.dragDirection];'layer'===this.flipType?(this.group.rotateOnAxis(this.flipAxis,e),this.flipAngle+=e):(this.edges.rotateOnWorldAxis(this.flipAxis,e),this.game.cube.object.rotation.copy(this.edges.rotation),this.flipAngle+=e)}}}},this.draggable.onDragEnd=()=>{if(null===this.scramble){if(2!==this.state)return this.gettingDrag=!1,void(this.state=f);this.state=3;const e=this.getMomentum()[this.dragDirection],t=.05{this.game.storage.saveGame(),this.state=this.gettingDrag?1:f,this.gettingDrag=!1,this.checkIsSolved()}):this.rotateCube(r,()=>{this.state=this.gettingDrag?1:f,this.gettingDrag=!1})}}}rotateLayer(e,t,a){const o=t?0:this.flipConfig,s=this.flipEasings[o],r=this.flipSpeeds[o],n=2==o?this.bounceCube():()=>{};this.rotationTween=new b({easing:s,duration:r,onUpdate:t=>{let a=t.delta*e;this.group.rotateOnAxis(this.flipAxis,a),n(t.value,a,e)},onComplete:()=>{t||this.onMove();const e=this.flipLayer.slice(0);this.game.cube.object.rotation.setFromVector3(this.snapRotation(this.game.cube.object.rotation.toVector3())),this.group.rotation.setFromVector3(this.snapRotation(this.group.rotation.toVector3())),this.deselectLayer(this.flipLayer),a(e)}})}bounceCube(){let e=!0;return(t,a,o)=>{1<=t&&(e&&(a=(t-1)*o,e=!1),this.game.cube.object.rotateOnAxis(this.flipAxis,a))}}rotateCube(e,t){const a=this.flipConfig,o=[y.Power.Out(4),y.Sine.Out(),y.Back.Out(2)][a],s=[100,150,350][a];this.rotationTween=new b({easing:o,duration:s,onUpdate:t=>{this.edges.rotateOnWorldAxis(this.flipAxis,t.delta*e),this.game.cube.object.rotation.copy(this.edges.rotation)},onComplete:()=>{this.edges.rotation.setFromVector3(this.snapRotation(this.edges.rotation.toVector3())),this.game.cube.object.rotation.copy(this.edges.rotation),t()}})}selectLayer(e){this.group.rotation.set(0,0,0),this.movePieces(e,this.game.cube.object,this.group),this.flipLayer=e}deselectLayer(e){this.movePieces(e,this.group,this.game.cube.object),this.flipLayer=null}movePieces(e,t,a){t.updateMatrixWorld(),a.updateMatrixWorld(),e.forEach(e=>{const o=this.game.cube.pieces[e];o.applyMatrix(t.matrixWorld),t.remove(o),o.applyMatrix(new THREE.Matrix4().getInverse(a.matrixWorld)),a.add(o)})}getLayer(e){const t={2:6,3:3,4:4,5:3}[this.game.cube.size],a=[];let o;if(!1===e){const a=this.dragIntersect.object.parent;o=this.getMainAxis(this.flipAxis),e=a.position.clone().multiplyScalar(t).round()}else o=this.getMainAxis(e);return this.game.cube.pieces.forEach(s=>{const r=s.position.clone().multiplyScalar(t).round();r[o]==e[o]&&a.push(s.name)}),a}keyboardMove(e,t){if(this.state===f&&!0===this.enabled)if('LAYER'===e){const e=this.getLayer(t.position);this.flipAxis=new THREE.Vector3,this.flipAxis[t.axis]=1,this.state=2,this.selectLayer(e),this.rotateLayer(t.angle,!1,()=>{this.game.storage.saveGame(),this.state=f,this.checkIsSolved()})}else'CUBE'===e&&(this.flipAxis=new THREE.Vector3,this.flipAxis[t.axis]=1,this.state=2,this.rotateCube(t.angle,()=>{this.state=f}))}scrambleCube(){null==this.scramble&&(this.scramble=this.game.scrambler,this.scramble.callback='function'==typeof callback?callback:()=>{});const e=this.scramble.converted,t=e[0],a=this.getLayer(t.position);this.flipAxis=new THREE.Vector3,this.flipAxis[t.axis]=1,this.selectLayer(a),this.rotateLayer(t.angle,!0,()=>{e.shift(),0o(e[t])>o(e[a])?t:a)}detach(e,t){e.applyMatrix(t.matrixWorld),t.remove(e),this.game.world.scene.add(e)}attach(e,t){e.applyMatrix(new THREE.Matrix4().getInverse(t.matrixWorld)),this.game.world.scene.remove(e),t.add(e)}addMomentumPoint(e){const t=Date.now();this.momentum=this.momentum.filter(e=>500>t-e.time),!1!==e&&this.momentum.push({delta:e,time:t})}getMomentum(){const e=this.momentum.length,t=new THREE.Vector2;return this.addMomentumPoint(!1),this.momentum.forEach((a,o)=>{t.add(a.delta.multiplyScalar(o/e))}),t}roundAngle(e){const t=i/2;return a(e)*r(o(e)/t)*t}snapRotation(e){return e.set(this.roundAngle(e.x),this.roundAngle(e.y),this.roundAngle(e.z))}checkIsSolved(){performance.now();let e=!0;const t={"x-":[],"x+":[],"y-":[],"y+":[],"z-":[],"z+":[]};this.game.cube.edges.forEach(e=>{const a=e.parent.localToWorld(e.position.clone()).sub(this.game.cube.object.position),o=this.getMainAxis(a),s=1>a.multiplyScalar(2).round()[o]?'-':'+';t[o+s].push(e.name)}),Object.keys(t).forEach(a=>{t[a].every(e=>e===t[a][0])||(e=!1)}),e&&this.onSolved()}}class z{constructor(e){this.game=e,this.dificulty=0,this.scrambleLength={2:[7,9,11],3:[20,25,30],4:[30,40,50],5:[40,60,80]},this.moves=[],this.conveted=[],this.pring=''}scramble(e){let t=0;if(this.moves='undefined'==typeof e?[]:e.split(' '),1>this.moves.length){const a=this.scrambleLength[this.game.cube.size][this.dificulty],o=4>this.game.cube.size?'UDLRFB':'UuDdLlRrFfBb',s=['','\'','2'],r='undefined'==typeof e?a:e;for(;t{},this.convert(),this.print=this.moves.join(' '),this}convert(){this.converted=[],this.moves.forEach(e=>{const t=this.convertMove(e),a=e.charAt(1);this.converted.push(t),'2'==a&&this.converted.push(t)})}convertMove(e){const t=e.charAt(0),a=e.charAt(1),o={D:'y',U:'y',L:'x',R:'x',F:'z',B:'z'}[t.toUpperCase()];let s={D:-1,U:1,L:-1,R:1,F:1,B:-1}[t.toUpperCase()];3new b({target:e.style,duration:300,easing:t?y.Power.Out(2):y.Power.In(3),from:{opacity:t?0:1},to:{opacity:t?1:0},onUpdate:a=>{const o=t?1-a.value:a.value;e.style.transform=`translate3d(0, ${1.5*o}em, 0)`},onComplete:()=>e.style.pointerEvents=t?'all':'none'});t.forEach(e=>this.tweens.buttons[e]=a(this.game.dom.buttons[e],!1)),setTimeout(()=>e.forEach(e=>{this.tweens.buttons[e]=a(this.game.dom.buttons[e],!0)}),t?500:0)}cube(e,t=!1){this.activeTransitions++;try{this.tweens.cube.stop()}catch(t){}const a=this.game.cube.animator.position.y,o=this.game.cube.animator.rotation.x;this.tweens.cube=new b({duration:e?3e3:1250,easing:e?y.Elastic.Out(.8,.6):y.Back.In(1),onUpdate:s=>{this.game.cube.animator.position.y=e?t?.9+3.5*(1-s.value):4*(1-s.value):a+4*s.value,this.game.cube.animator.rotation.x=e?(1-s.value)*i/3:o+s.value*-i/3}}),t&&(e?(this.game.world.camera.zoom=.75,this.game.world.camera.updateProjectionMatrix()):setTimeout(()=>{this.game.world.camera.zoom=this.data.cameraZoom,this.game.world.camera.updateProjectionMatrix()},1500)),this.durations.cube=e?1500:1500,setTimeout(()=>this.activeTransitions--,this.durations.cube)}float(){try{this.tweens.float.stop()}catch(t){}this.tweens.float=new b({duration:1500,easing:y.Sine.InOut(),yoyo:!0,onUpdate:e=>{this.game.cube.holder.position.y=-.02+.04*e.value,this.game.cube.holder.rotation.x=.005-.01*e.value,this.game.cube.holder.rotation.z=-this.game.cube.holder.rotation.x,this.game.cube.holder.rotation.y=this.game.cube.holder.rotation.x,this.game.controls.edges.position.y=this.game.cube.holder.position.y+this.game.cube.object.position.y}})}zoom(e,t){this.activeTransitions++;const a=e?1:this.data.cameraZoom,o=0{this.game.world.camera.updateProjectionMatrix()}}),this.tweens.rotate=new b({target:this.game.cube.animator.rotation,duration:o,easing:n,to:{y:2*-i*s},onComplete:()=>{this.game.cube.animator.rotation.y=0}}),this.durations.zoom=o,setTimeout(()=>this.activeTransitions--,this.durations.zoom)}elevate(e){this.activeTransitions++;this.tweens.elevate=new b({target:this.game.cube.object.position,duration:e?1500:0,easing:y.Power.InOut(3),to:{y:e?-.05:this.data.cubeY}});this.durations.elevate=1500,setTimeout(()=>this.activeTransitions--,this.durations.elevate)}complete(e,t){this.activeTransitions++;const a=t?this.game.dom.texts.best:this.game.dom.texts.complete;null===a.querySelector('span i')&&a.querySelectorAll('span').forEach(e=>this.splitLetters(e));const o=a.querySelectorAll('.icon, i');this.flipLetters(t?'best':'complete',o,e),a.style.opacity=1;const s=this.durations[t?'best':'complete'];e||setTimeout(()=>this.game.dom.texts.timer.style.transform='',s),setTimeout(()=>this.activeTransitions--,s)}stats(e){e&&this.game.scores.calcStats(),this.activeTransitions++,this.tweens.stats.forEach(e=>{e.stop(),e=null});let t=-1;const a=this.game.dom.stats.querySelectorAll('.stats'),o=e?y.Power.Out(2):y.Power.In(3);a.forEach((a,s)=>{const r=s*(e?80:60);this.tweens.stats[t++]=new b({delay:r,duration:400,easing:o,onUpdate:t=>{const o=e?2*(1-t.value):t.value,s=e?t.value:1-t.value;a.style.transform=`translate3d(0, ${o}em, 0)`,a.style.opacity=s}})}),this.durations.stats=0,setTimeout(()=>this.activeTransitions--,this.durations.stats)}preferences(e){this.ranges(this.game.dom.prefs.querySelectorAll('.range'),'prefs',e)}theming(e){this.ranges(this.game.dom.theme.querySelectorAll('.range'),'prefs',e)}ranges(e,t,a){this.activeTransitions++,this.tweens[t].forEach(e=>{e.stop(),e=null});const o=a?y.Power.Out(2):y.Power.In(3);let s=-1,r=0;e.forEach((e,n)=>{const i=e.querySelector('.range__label'),l=e.querySelector('.range__track-line'),c=e.querySelector('.range__handle'),m=e.querySelectorAll('.range__list div'),d=n*(a?120:100);i.style.opacity=a?0:1,l.style.opacity=a?0:1,c.style.opacity=a?0:1,c.style.pointerEvents=a?'all':'none',this.tweens[t][s++]=new b({delay:a?d:d,duration:400,easing:o,onUpdate:e=>{const t=a?1-e.value:e.value,o=a?e.value:1-e.value;i.style.transform=`translate3d(0, ${t}em, 0)`,i.style.opacity=o}}),this.tweens[t][s++]=new b({delay:a?d+100:d,duration:400,easing:o,onUpdate:e=>{const t=a?1-e.value:e.value,o=a?e.value:1-e.value;l.style.transform=`translate3d(0, ${t}em, 0) scale3d(${o}, 1, 1)`,l.style.opacity=o}}),this.tweens[t][s++]=new b({delay:a?d+100:d,duration:400,easing:o,onUpdate:e=>{const t=a?1-e.value:e.value,o=1-t,s=.5+.5*o;c.style.transform=`translate3d(0, ${t}em, 0) scale3d(${s}, ${s}, ${s})`,c.style.opacity=o}}),m.forEach((e,r)=>{e.style.opacity=a?0:1,this.tweens[t][s++]=new b({delay:a?d+200+50*r:d,duration:400,easing:o,onUpdate:t=>{const o=a?1-t.value:t.value,s=a?t.value:1-t.value;e.style.transform=`translate3d(0, ${o}em, 0)`,e.style.opacity=s}})}),r=m.length>r?m.length-1:r,e.style.opacity=1}),this.durations[t]=a?100*(e.length-1)+200+50*r+400:100*(e.length-1)+400,setTimeout(()=>this.activeTransitions--,this.durations[t])}title(e){this.activeTransitions++;const t=this.game.dom.texts.title;null===t.querySelector('span i')&&t.querySelectorAll('span').forEach(e=>this.splitLetters(e));const a=t.querySelectorAll('i');this.flipLetters('title',a,e),t.style.opacity=1;const o=this.game.dom.texts.note;this.tweens.title[a.length]=new b({target:o.style,easing:y.Sine.InOut(),duration:e?800:400,yoyo:!!e||null,from:{opacity:e?0:parseFloat(getComputedStyle(o).opacity)},to:{opacity:e?1:0}}),setTimeout(()=>this.activeTransitions--,this.durations.title)}timer(e){this.activeTransitions++;const t=this.game.dom.texts.timer;t.style.opacity=0,this.game.timer.convert(),this.game.timer.setText(),this.splitLetters(t);const a=t.querySelectorAll('i');this.flipLetters('timer',a,e),t.style.opacity=1,setTimeout(()=>this.activeTransitions--,this.durations.timer)}splitLetters(e){const t=e.innerHTML;e.innerHTML='',t.split('').forEach(t=>{const a=document.createElement('i');a.innerHTML=t,e.appendChild(a)})}flipLetters(e,t,a){try{this.tweens[e].forEach(e=>e.stop())}catch(t){}t.forEach((t,o)=>{t.style.opacity=a?0:1,this.tweens[e][o]=new b({easing:y.Sine.Out(),duration:a?800:400,delay:50*o,onUpdate:e=>{const o=a?-80*(1-e.value):80*e.value;t.style.transform=`rotate3d(0, 1, 0, ${o}deg)`,t.style.opacity=a?e.value:1-e.value}})}),this.durations[e]=50*(t.length-1)+(a?800:400)}}class w extends g{constructor(e){super(!1),this.game=e,this.reset()}start(e){this.startTime=e?Date.now()-this.deltaTime:Date.now(),this.deltaTime=0,this.converted=this.convert(),super.start()}reset(){this.startTime=0,this.currentTime=0,this.deltaTime=0,this.converted='0:00'}stop(){return this.currentTime=Date.now(),this.deltaTime=this.currentTime-this.startTime,this.convert(),super.stop(),{time:this.converted,millis:this.deltaTime}}update(){const e=this.converted;this.currentTime=Date.now(),this.deltaTime=this.currentTime-this.startTime,this.convert(),this.converted!=e&&(localStorage.setItem('theCube_time',this.deltaTime),this.setText())}convert(){const e=parseInt(this.deltaTime/1e3%60),t=parseInt(this.deltaTime/60000);this.converted=t+':'+(10>e?'0':'')+e}setText(){this.game.dom.texts.timer.innerHTML=this.converted}}document.querySelectorAll('range').forEach(e=>{const t=document.createElement('div');t.innerHTML='
\n
\n
\n
\n
\n
\n
\n
';const a=t.querySelector('.range'),o=a.querySelector('.range__label'),s=a.querySelector('.range__list');a.setAttribute('name',e.getAttribute('name')),o.innerHTML=e.getAttribute('title'),e.hasAttribute('color')&&(a.classList.add('range--type-color'),a.classList.add('range--color-'+e.getAttribute('name'))),e.hasAttribute('list')&&e.getAttribute('list').split(',').forEach(e=>{const t=document.createElement('div');t.innerHTML=e,s.appendChild(t)}),e.parentNode.replaceChild(a,e)});class C{constructor(e,t){t=Object.assign({range:[0,1],value:0,step:0,onUpdate:()=>{},onComplete:()=>{}},t||{}),this.element=document.querySelector('.range[name="'+e+'"]'),this.track=this.element.querySelector('.range__track'),this.handle=this.element.querySelector('.range__handle'),this.list=[].slice.call(this.element.querySelectorAll('.range__list div')),this.value=t.value,this.min=t.range[0],this.max=t.range[1],this.step=t.step,this.onUpdate=t.onUpdate,this.onComplete=t.onComplete,this.setValue(this.value),this.initDraggable()}setValue(e){this.value=this.round(this.limitValue(e)),this.setHandlePosition()}initDraggable(){let e;this.draggable=new v(this.handle,{calcDelta:!0}),this.draggable.onDragStart=()=>{e=this.positionFromValue(this.value),this.handle.style.left=e+'px'},this.draggable.onDragMove=t=>{e=this.limitPosition(e+t.delta.x),this.value=this.round(this.valueFromPosition(e)),this.setHandlePosition(),this.onUpdate(this.value)},this.draggable.onDragEnd=()=>{this.onComplete(this.value)}}round(e){return 1>this.step?e:r((e-this.min)/this.step)*this.step+this.min}limitValue(e){const t=c(this.max,this.min),a=l(this.max,this.min);return l(c(e,a),t)}limitPosition(e){return l(c(e,0),this.track.offsetWidth)}percentsFromValue(e){return(e-this.min)/(this.max-this.min)}valueFromPosition(e){return this.min+(this.max-this.min)*(e/this.track.offsetWidth)}positionFromValue(e){return this.percentsFromValue(e)*this.track.offsetWidth}setHandlePosition(){this.handle.style.left=100*this.percentsFromValue(this.value)+'%'}}class L{constructor(e){this.game=e}init(){this.ranges={size:new C('size',{value:this.game.cube.size,range:[2,5],step:1,onUpdate:e=>{this.game.cube.size=e,this.game.preferences.ranges.scramble.list.forEach((e,t)=>{e.innerHTML=this.game.scrambler.scrambleLength[this.game.cube.size][t]})},onComplete:()=>this.game.storage.savePreferences()}),flip:new C('flip',{value:this.game.controls.flipConfig,range:[0,2],step:1,onUpdate:e=>{this.game.controls.flipConfig=e},onComplete:()=>this.game.storage.savePreferences()}),scramble:new C('scramble',{value:this.game.scrambler.dificulty,range:[0,2],step:1,onUpdate:e=>{this.game.scrambler.dificulty=e},onComplete:()=>this.game.storage.savePreferences()}),fov:new C('fov',{value:this.game.world.fov,range:[2,45],onUpdate:e=>{this.game.world.fov=e,this.game.world.resize()},onComplete:()=>this.game.storage.savePreferences()}),theme:new C('theme',{value:{cube:0,erno:1,dust:2,camo:3,rain:4}[this.game.themes.theme],range:[0,4],step:1,onUpdate:e=>{const t=['cube','erno','dust','camo','rain'][e];this.game.themes.setTheme(t)},onComplete:()=>this.game.storage.savePreferences()}),hue:new C('hue',{value:0,range:[0,360],onUpdate:()=>this.game.themeEditor.updateHSL(),onComplete:()=>this.game.storage.savePreferences()}),saturation:new C('saturation',{value:100,range:[0,100],onUpdate:()=>this.game.themeEditor.updateHSL(),onComplete:()=>this.game.storage.savePreferences()}),lightness:new C('lightness',{value:50,range:[0,100],onUpdate:()=>this.game.themeEditor.updateHSL(),onComplete:()=>this.game.storage.savePreferences()})},this.ranges.scramble.list.forEach((e,t)=>{e.innerHTML=this.game.scrambler.scrambleLength[this.game.cube.size][t]})}}class T{constructor(e){this.game=e,this.started=0,this.options={speed:{min:.0011,max:.0022},revolution:{min:.01,max:.05},size:{min:.1,max:.15},colors:[4303560,8571448,16772936,15677731,16747530]},this.geometry=new THREE.PlaneGeometry(1,1),this.material=new THREE.MeshLambertMaterial({side:THREE.DoubleSide}),this.holders=[new M(this.game,this,1,20),new M(this.game,this,-1,30)]}start(){0{this.game.world.scene.add(e.holder),e.start(),this.started++})}stop(){0==this.started||this.holders.forEach(e=>{e.stop(()=>{this.game.world.scene.remove(e.holder),this.started--})})}updateColors(e){this.holders.forEach(t=>{t.options.colors.forEach((a,o)=>{t.options.colors[o]=e[['D','F','R','B','L'][o]]})})}}class M extends g{constructor(e,t,a,o){super(!1),this.game=e,this.parent=t,this.distanceFromCube=a,this.count=o,this.particles=[],this.holder=new THREE.Object3D,this.holder.rotation.copy(this.game.world.camera.rotation),this.object=new THREE.Object3D,this.holder.add(this.object),this.resizeViewport=this.resizeViewport.bind(this),this.game.world.onResize.push(this.resizeViewport),this.resizeViewport(),this.geometry=this.parent.geometry,this.material=this.parent.material,this.options=this.parent.options;for(let s=this.count;s--;)this.particles.push(new A(this))}start(){this.time=performance.now(),this.playing=!0;for(let e=this.count;e--;)this.particles[e].reset();super.start()}stop(e){this.playing=!1,this.completed=0,this.callback=e}reset(){super.stop(),this.callback()}update(){const e=performance.now(),t=e-this.time;this.time=e;for(let e=this.count;e--;)this.particles[e].completed||this.particles[e].update(t);this.playing||this.completed!=this.count||this.reset()}resizeViewport(){const e=this.game.world.camera.fov*THREE.Math.DEG2RAD;this.height=2*m(e/2)*(this.game.world.camera.position.length()-this.distanceFromCube),this.width=this.height*this.game.world.camera.aspect;const t=1/this.game.transition.data.cameraZoom;this.width*=t,this.height*=t,this.object.position.z=this.distanceFromCube,this.object.position.y=this.height/2}}class A{constructor(e){return this.confetti=e,this.options=this.confetti.options,this.velocity=new THREE.Vector3,this.force=new THREE.Vector3,this.mesh=new THREE.Mesh(this.confetti.geometry,this.confetti.material.clone()),this.confetti.object.add(this.mesh),this.size=THREE.Math.randFloat(this.options.size.min,this.options.size.max),this.mesh.scale.set(this.size,this.size,this.size),this}reset(e=!0){this.completed=!1,this.color=new THREE.Color(this.options.colors[d(Math.random()*this.options.colors.length)]),this.mesh.material.color.set(this.color),this.speed=-1*THREE.Math.randFloat(this.options.speed.min,this.options.speed.max),this.mesh.position.x=THREE.Math.randFloat(-this.confetti.width/2,this.confetti.width/2),this.mesh.position.y=e?THREE.Math.randFloat(this.size,this.confetti.height+this.size):this.size,this.revolutionSpeed=THREE.Math.randFloat(this.options.revolution.min,this.options.revolution.max),this.revolutionAxis=['x','y','z'][d(3*Math.random())],this.mesh.rotation.set(Math.random()*i/3,Math.random()*i/3,Math.random()*i/3)}stop(){this.completed=!0,this.confetti.completed++}update(e){this.mesh.position.y+=this.speed*e,this.mesh.rotation[this.revolutionAxis]+=this.revolutionSpeed,this.mesh.position.y<-this.confetti.height-this.size&&(this.confetti.playing?this.reset(!1):this.stop())}}class E{constructor(e){this.game=e,this.data={2:{scores:[],solves:0,best:0,worst:0},3:{scores:[],solves:0,best:0,worst:0},4:{scores:[],solves:0,best:0,worst:0},5:{scores:[],solves:0,best:0,worst:0}}}addScore(e){const t=this.data[this.game.cube.sizeGenerated];t.scores.push(e),t.solves++,100t.worst&&(t.worst=e),this.game.storage.saveScores(),a}calcStats(){const e=this.game.cube.sizeGenerated,t=this.data[e];this.setStat('cube-size',`${e}x${e}x${e}`),this.setStat('total-solves',t.solves),this.setStat('best-time',this.convertTime(t.best)),this.setStat('worst-time',this.convertTime(t.worst)),this.setStat('average-5',this.getAverage(5)),this.setStat('average-12',this.getAverage(12)),this.setStat('average-25',this.getAverage(25))}setStat(e,t){0===t&&(t='-'),this.game.dom.stats.querySelector(`.stats[name="${e}"] b`).innerHTML=t}getAverage(e){const t=this.data[this.game.cube.sizeGenerated];return t.scores.lengthe+t,0)/e)}convertTime(e){if(0>=e)return 0;const t=parseInt(e/1e3%60),a=parseInt(e/60000);return a+':'+(10>t?'0':'')+t}}class P{constructor(e){this.game=e;const t=localStorage.getItem('theCube_version');t&&t===window.gameVersion||(this.clearGame(),this.clearPreferences(),this.migrateScores(),localStorage.setItem('theCube_version',window.gameVersion))}init(){this.loadPreferences(),this.loadScores()}loadGame(){try{const e='true'===localStorage.getItem('theCube_playing');if(!e)throw new Error;const t=JSON.parse(localStorage.getItem('theCube_savedState')),a=parseInt(localStorage.getItem('theCube_time'));if(!t||null===a)throw new Error;if(t.size!==this.game.cube.sizeGenerated)throw new Error;this.game.cube.loadFromData(t),this.game.timer.deltaTime=a,this.game.saved=!0}catch(t){this.game.saved=!1}}saveGame(){const e={names:[],positions:[],rotations:[]},t=this.game.timer.deltaTime;e.size=this.game.cube.sizeGenerated,this.game.cube.pieces.forEach(t=>{e.names.push(t.name),e.positions.push(t.position),e.rotations.push(t.rotation.toVector3())}),localStorage.setItem('theCube_playing',!0),localStorage.setItem('theCube_savedState',JSON.stringify(e)),localStorage.setItem('theCube_time',t)}clearGame(){localStorage.removeItem('theCube_playing'),localStorage.removeItem('theCube_savedState'),localStorage.removeItem('theCube_time')}loadScores(){try{const e=JSON.parse(localStorage.getItem('theCube_scores'));if(!e)throw new Error;this.game.scores.data=e}catch(t){}}saveScores(){const e=this.game.scores.data;localStorage.setItem('theCube_scores',JSON.stringify(e))}clearScores(){localStorage.removeItem('theCube_scores')}migrateScores(){try{const e=JSON.parse(localStorage.getItem('theCube_scoresData')),t=parseInt(localStorage.getItem('theCube_scoresBest')),a=parseInt(localStorage.getItem('theCube_scoresWorst')),o=parseInt(localStorage.getItem('theCube_scoresSolves'));if(!e||!t||!o||!a)return!1;this.game.scores.data[3].scores=e,this.game.scores.data[3].best=t,this.game.scores.data[3].solves=o,this.game.scores.data[3].worst=a,localStorage.removeItem('theCube_scoresData'),localStorage.removeItem('theCube_scoresBest'),localStorage.removeItem('theCube_scoresWorst'),localStorage.removeItem('theCube_scoresSolves')}catch(t){}}loadPreferences(){try{const e=JSON.parse(localStorage.getItem('theCube_preferences'));if(!e)throw new Error;return this.game.cube.size=parseInt(e.cubeSize),this.game.controls.flipConfig=parseInt(e.flipConfig),this.game.scrambler.dificulty=parseInt(e.dificulty),this.game.world.fov=parseFloat(e.fov),this.game.world.resize(),this.game.themes.colors=e.colors,this.game.themes.setTheme(e.theme),!0}catch(t){return this.game.cube.size=3,this.game.controls.flipConfig=0,this.game.scrambler.dificulty=1,this.game.world.fov=10,this.game.world.resize(),this.game.themes.setTheme('cube'),this.savePreferences(),!1}}savePreferences(){const e={cubeSize:this.game.cube.size,flipConfig:this.game.controls.flipConfig,dificulty:this.game.scrambler.dificulty,fov:this.game.world.fov,theme:this.game.themes.theme,colors:this.game.themes.colors};localStorage.setItem('theCube_preferences',JSON.stringify(e))}clearPreferences(){localStorage.removeItem('theCube_preferences')}}class D{constructor(e){this.game=e,this.theme=null,this.defaults={cube:{U:16775167,D:16772936,F:15677731,R:4303560,B:16747530,L:8571448,P:528410,G:13751771},erno:{U:16777215,D:16766208,F:12852794,R:20922,B:16734208,L:40544,P:528410,G:9092607},dust:{U:16774891,D:15189133,F:9381182,R:6323817,B:12480354,L:8691549,P:528410,G:15189133},camo:{U:16774891,D:12564082,F:3613724,R:7439446,B:8411185,L:3621661,P:528410,G:12564082},rain:{U:16448255,D:15579437,F:13508917,R:4496009,B:15489071,L:10725703,P:528410,G:8894892}},this.colors=JSON.parse(JSON.stringify(this.defaults))}getColors(){return this.colors[this.theme]}setTheme(e=!1,t=!1){if(e===this.theme&&!1===t)return;!1!==e&&(this.theme=e);const a=this.getColors();this.game.dom.prefs.querySelectorAll('.range__handle div').forEach(e=>{e.style.background='#'+a.R.toString(16).padStart(6,'0')}),this.game.cube.updateColors(a),this.game.confetti.updateColors(a),this.game.dom.back.style.background='#'+a.G.toString(16).padStart(6,'0')}}class _{constructor(e){this.game=e,this.editColor='R',this.getPieceColor=this.getPieceColor.bind(this)}colorFromHSL(e,t,a){return e=r(e),t=r(t),a=r(a),new THREE.Color(`hsl(${e}, ${t}%, ${a}%)`)}setHSL(e=null,t=!1){this.editColor=null===e?'R':e;const a=new THREE.Color(this.game.themes.getColors()[this.editColor]),{h:o,s:r,l:s}=a.getHSL(a),{hue:n,saturation:i,lightness:l}=this.game.preferences.ranges;if(t){const e=n.value/360,t=i.value/100,c=l.value/100,m=this.colorFromHSL(n.value,i.value,l.value);this.tweenHSL&&this.tweenHSL.stop(),this.tweenHSL=new b({duration:200,easing:y.Sine.Out(),onUpdate:d=>{n.setValue(360*(e+(o-e)*d.value)),i.setValue(100*(t+(r-t)*d.value)),l.setValue(100*(c+(s-c)*d.value));const u=m.clone().lerp(a,d.value),g=u.getStyle(),p=u.getHSL(u);n.handle.style.color=g,i.handle.style.color=g,l.handle.style.color=g,i.track.style.color=this.colorFromHSL(360*p.h,100,50).getStyle(),l.track.style.color=this.colorFromHSL(360*p.h,100*p.s,50).getStyle(),this.game.dom.theme.style.display='none',this.game.dom.theme.offsetHeight,this.game.dom.theme.style.display=''},onComplete:()=>{this.updateHSL(),this.game.storage.savePreferences()}})}else n.setValue(360*o),i.setValue(100*r),l.setValue(100*s),this.updateHSL(),this.game.storage.savePreferences()}updateHSL(){const{hue:e,saturation:t,lightness:a}=this.game.preferences.ranges,o=e.value,r=t.value,s=a.value,n=this.colorFromHSL(o,r,s).getStyle();e.handle.style.color=n,t.handle.style.color=n,a.handle.style.color=n,t.track.style.color=this.colorFromHSL(o,100,50).getStyle(),a.track.style.color=this.colorFromHSL(o,r,50).getStyle(),this.game.dom.theme.style.display='none',this.game.dom.theme.offsetHeight,this.game.dom.theme.style.display='';const i=this.game.themes.theme;this.game.themes.colors[i][this.editColor]=this.colorFromHSL(o,r,s).getHex(),this.game.themes.setTheme()}colorPicker(e){e?this.game.dom.game.addEventListener('click',this.getPieceColor,!1):this.game.dom.game.removeEventListener('click',this.getPieceColor,!1)}getPieceColor(e){const t=e.touches?e.touches[0]||e.changedTouches[0]:e,a=new THREE.Vector2(t.pageX,t.pageY);let o=this.game.controls.getIntersect(a,this.game.cube.edges,!0),s=this.game.controls.getIntersect(a,this.game.cube.cubes,!0);if(!1!==o){const e=o.object,t=e.parent.localToWorld(e.position.clone()).sub(this.game.cube.object.position).sub(this.game.cube.animator.position),a=this.game.controls.getMainAxis(t);1>t.multiplyScalar(2).round()[a]&&(o=!1)}const r=o?o.object.name:s?'P':'G';this.setHSL(r,!0)}resetTheme(){this.game.themes.colors[this.game.themes.theme]=JSON.parse(JSON.stringify(this.game.themes.defaults[this.game.themes.theme])),this.game.themes.setTheme(),this.setHSL(this.editColor,!0)}}const k={3:{checkerboard:{names:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],positions:[{x:1/3,y:-1/3,z:1/3},{x:-1/3,y:1/3,z:0},{x:1/3,y:-1/3,z:-1/3},{x:-1/3,y:0,z:-1/3},{x:1/3,y:0,z:0},{x:-1/3,y:0,z:1/3},{x:1/3,y:1/3,z:1/3},{x:-1/3,y:-1/3,z:0},{x:1/3,y:1/3,z:-1/3},{x:0,y:1/3,z:-1/3},{x:0,y:-1/3,z:0},{x:0,y:1/3,z:1/3},{x:0,y:0,z:1/3},{x:0,y:0,z:0},{x:0,y:0,z:-1/3},{x:0,y:-1/3,z:-1/3},{x:0,y:1/3,z:0},{x:0,y:-1/3,z:1/3},{x:-1/3,y:-1/3,z:1/3},{x:1/3,y:1/3,z:0},{x:-1/3,y:-1/3,z:-1/3},{x:1/3,y:0,z:-1/3},{x:-1/3,y:0,z:0},{x:1/3,y:0,z:1/3},{x:-1/3,y:1/3,z:1/3},{x:1/3,y:-1/3,z:0},{x:-1/3,y:1/3,z:-1/3}],rotations:[{x:-i,y:0,z:i},{x:i,y:0,z:0},{x:-i,y:0,z:i},{x:0,y:0,z:0},{x:0,y:0,z:i},{x:0,y:0,z:0},{x:-i,y:0,z:i},{x:i,y:0,z:0},{x:-i,y:0,z:i},{x:0,y:0,z:i},{x:0,y:0,z:0},{x:0,y:0,z:i},{x:-i,y:0,z:0},{x:i,y:0,z:i},{x:i,y:0,z:0},{x:0,y:0,z:i},{x:0,y:0,z:0},{x:0,y:0,z:i},{x:i,y:0,z:i},{x:-i,y:0,z:0},{x:i,y:0,z:i},{x:0,y:0,z:0},{x:0,y:0,z:i},{x:0,y:0,z:0},{x:i,y:0,z:i},{x:-i,y:0,z:0},{x:i,y:0,z:i}],size:3}}};const V=new class{constructor(e){if(e=Object.assign({tagName:'icon',className:'icon',styles:!1,icons:{},observe:!1,convert:!1},e||{}),this.tagName=e.tagName,this.className=e.className,this.icons=e.icons,this.svgTag=document.createElementNS('http://www.w3.org/2000/svg','svg'),this.svgTag.setAttribute('class',this.className),e.styles&&this.addStyles(),e.convert&&this.convertAllIcons(),e.observe){const e=window.MutationObserver||window.WebKitMutationObserver;this.observer=new e(()=>{this.convertAllIcons()}),this.observer.observe(document.documentElement,{childList:!0,subtree:!0})}return this}convertAllIcons(){document.querySelectorAll(this.tagName).forEach(e=>{this.convertIcon(e)})}convertIcon(e){const t=this.icons[e.attributes[0].localName];if('undefined'!=typeof t){const a=this.svgTag.cloneNode(!0),o=t.viewbox.split(' ');a.setAttributeNS(null,'viewBox',t.viewbox),a.style.width=o[2]/o[3]+'em',a.style.height='1em',a.innerHTML=t.content,e.parentNode.replaceChild(a,e)}}addStyles(){const e=document.createElement('style');e.innerHTML=`.${this.className} { display: inline-block; font-size: inherit; overflow: visible; vertical-align: -0.125em; preserveAspectRatio: none; }`,document.head.appendChild(e)}}({icons:{settings:{viewbox:'0 0 512 512',content:''},back:{viewbox:'0 0 512 512',content:''},trophy:{viewbox:'0 0 576 512',content:''},cancel:{viewbox:'0 0 352 512',content:''},theme:{viewbox:'0 0 512 512',content:''},reset:{viewbox:'0 0 512 512',content:''},trash:{viewbox:'0 0 448 512',content:''}},convert:!0}),I={Menu:0,Playing:1,Complete:2,Stats:3,Prefs:4,Theme:5},H={Menu:['stats','prefs'],Playing:['back'],Complete:[],Stats:[],Prefs:['back','theme'],Theme:['back','reset'],None:[]};window.game=new class{constructor(){this.dom={ui:document.querySelector('.ui'),game:document.querySelector('.ui__game'),back:document.querySelector('.ui__background'),prefs:document.querySelector('.ui__prefs'),theme:document.querySelector('.ui__theme'),stats:document.querySelector('.ui__stats'),texts:{title:document.querySelector('.text--title'),note:document.querySelector('.text--note'),timer:document.querySelector('.text--timer'),complete:document.querySelector('.text--complete'),best:document.querySelector('.text--best-time'),theme:document.querySelector('.text--theme')},buttons:{prefs:document.querySelector('.btn--prefs'),back:document.querySelector('.btn--back'),stats:document.querySelector('.btn--stats'),reset:document.querySelector('.btn--reset'),theme:document.querySelector('.btn--theme')}},this.world=new p(this),this.cube=new h(this),this.controls=new x(this),this.scrambler=new z(this),this.transition=new S(this),this.timer=new w(this),this.preferences=new L(this),this.scores=new E(this),this.storage=new P(this),this.confetti=new T(this),this.themes=new D(this),this.themeEditor=new _(this),this.initActions(),this.state=I.Menu,this.newGame=!1,this.saved=!1,this.storage.init(),this.preferences.init(),this.cube.init(),this.transition.init(),this.storage.loadGame(),this.scores.calcStats(),setTimeout(()=>{this.transition.float(),this.transition.cube(!0),setTimeout(()=>this.transition.title(!0),700),setTimeout(()=>this.transition.buttons(H.Menu,H.None),1e3)},500)}initActions(){let e=!1;this.dom.game.addEventListener('click',()=>{if(!(0e=!1,300),!1;this.game(!0)}else this.state===I.Complete?this.complete(!1):this.state===I.Stats&&this.stats(!1)},!1),this.controls.onMove=()=>{this.newGame&&(this.timer.start(!0),this.newGame=!1)},this.dom.buttons.back.onclick=()=>{0{this.state===I.Theme&&this.themeEditor.resetTheme()},this.dom.buttons.prefs.onclick=()=>this.prefs(!0),this.dom.buttons.theme.onclick=()=>this.theme(!0),this.dom.buttons.stats.onclick=()=>this.stats(!0),this.controls.onSolved=()=>this.complete(!0)}game(e){if(e){this.saved||(this.scrambler.scramble(),this.controls.scrambleCube(),this.newGame=!0);const e=this.saved?0:this.scrambler.converted.length*(this.controls.flipSpeeds[0]+10);this.state=I.Playing,this.saved=!0,this.transition.buttons(H.None,H.Menu),this.transition.zoom(I.Playing,e),this.transition.title(!1),setTimeout(()=>{this.transition.timer(!0),this.transition.buttons(H.Playing,H.None)},this.transition.durations.zoom-1e3),setTimeout(()=>{this.controls.enable(),this.newGame||this.timer.start(!0)},this.transition.durations.zoom)}else this.state=I.Menu,this.transition.buttons(H.Menu,H.Playing),this.transition.zoom(I.Menu,0),this.controls.disable(),this.newGame||this.timer.stop(),this.transition.timer(!1),setTimeout(()=>this.transition.title(!0),this.transition.durations.zoom-1e3),this.playing=!1,this.controls.disable()}prefs(e){if(e){if(0this.transition.preferences(!0),1e3)}else this.cube.resize(),this.state=I.Menu,this.transition.buttons(H.Menu,H.Prefs),this.transition.preferences(!1),setTimeout(()=>this.transition.cube(!0),500),setTimeout(()=>this.transition.title(!0),1200)}theme(e){if(this.themeEditor.colorPicker(e),e){if(0this.transition.cube(!0,!0),500),setTimeout(()=>this.transition.theming(!0),1e3)}else this.state=I.Prefs,this.transition.buttons(H.Prefs,H.Theme),this.transition.cube(!1,!0),this.transition.theming(!1),setTimeout(()=>this.transition.preferences(!0),1e3),setTimeout(()=>{const e=JSON.parse(localStorage.getItem('theCube_savedState'));return e?void this.cube.loadFromData(e):void this.cube.resize(!0)},1500)}stats(e){if(e){if(0this.transition.stats(!0),1e3)}else this.state=I.Menu,this.transition.buttons(H.Menu,H.None),this.transition.stats(!1),setTimeout(()=>this.transition.cube(!0),500),setTimeout(()=>this.transition.title(!0),1200)}complete(e){return e?void(this.transition.buttons(H.Complete,H.Playing),this.state=I.Complete,this.saved=!1,this.controls.disable(),this.timer.stop(),this.storage.clearGame(),this.bestTime=this.scores.addScore(this.timer.deltaTime),this.transition.zoom(I.Menu,0),this.transition.elevate(!0),setTimeout(()=>{this.transition.complete(!0,this.bestTime),this.confetti.start()},1e3)):(this.state=I.Stats,this.saved=!1,this.transition.timer(!1),this.transition.complete(!1,this.bestTime),this.transition.cube(!1),this.timer.reset(),setTimeout(()=>{this.cube.reset(),this.confetti.stop(),this.transition.stats(!0),this.transition.elevate(0)},1e3),!1)}}})();