arrayswpeeper-gui
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1795,3 +1795,3 @@ // This just supports loading in any enviroment | ||
+ ((stack1 = this.invokePartial(partials.help,depth0,{"name":"help","data":data,"indent":"\t\t","helpers":helpers,"partials":partials})) != null ? stack1 : "") | ||
+ " </div>\n <div class=\"board-wrap\">\n <div class=\"as-gameboard\">\n\n </div>\n <div class=\"as-screen\">\n\n </div>\n </div>\n</div>"; | ||
+ " </div>\n <div class=\"as-board-wrap\">\n <div class=\"as-gameboard\">\n\n </div>\n <div class=\"as-screen\">\n\n </div>\n </div>\n</div>"; | ||
},"usePartial":true,"useData":true}); |
@@ -1,1 +0,1 @@ | ||
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Arraysweeper=b()}(this,function(){for(var a=function(a,b,c){this.height=a,this.width=b,this.count={mines:c,hidden:b*a,moves:0,revealed:0,flags:0},this._buildBoard()},b={mineCount:function(a,b){return"revealed"===this._board[a][b].state?this._board[a][b].count:"Reveal space to see count"},flag:function(a,b,c){return void 0===c?"flag"===this._board[a][b].state:(this.count.flags=this.count.flags+(c?1:-1),this.count.hidden=this.count.hidden-(c?1:-1),this._board[a][b].state=c?"flag":"hidden",this.count.flags+this.count.hidden===this.count.mines?"You Win!":void 0)},reveal:function(a,b){var c,d,e=this._board[a][b];return e.bomb&&0!==this.count.moves?"Game Over!":(e.bomb?this._buildBoard():this.count.flags+this.count.hidden===this.count.mines+1&&(c="You Win!"),this.count.moves++,d=this._reveal(a,b),c||d)},render:function(){for(var a=[],b=0;b<this.height;b++)a.push(JSON.stringify(this._board[b].map(this._renderMap)));console.log(a.join(",\n"))},getBoard:function(){return this._board},_renderMap:function(a){return"revealed"===a.state?a.count.toString():"flag"===a.state?"!":"X"},_getMines:function(){this.mines=[];for(var a=0;a<this.count.mines;a++){for(var b,c=!1;c===!1;){var d=this._getMine();-1===this.mines.indexOf(d.row+","+d.col)&&(b=d,c=!0)}this.mines.push(b.row+","+b.col)}},_getMine:function(){return{row:Math.floor(Math.random()*(this.height-1)),col:Math.floor(Math.random()*(this.width-1))}},_reveal:function(a,b,c,d){d=d||0,c="object"==typeof c?c:[],this._board[a][b].state="revealed",this.count.revealed++,this.count.hidden--;for(var e=a-1>0?a-1:0;a+1>=e&&e<this.width;e++)for(var f=b-1>0?b-1:0;b+1>=f&&f<this.width;f++)e>=0&&f>=0&&e<this.height&&f<this.width&&0===this._board[e][f].count&&"revealed"!==this._board[e][f].state&&!this._board[e][f].bomb&&-1===c.indexOf(e+","+f)&&(e!==a||f!==b)&&(this._board[e][f].state="",c.push(e+","+f));if(c.length&&c.length>=d+1){var g=c[d].split(",");this._reveal(parseFloat(g[0],10),parseFloat(g[1],10),c,d+1)}return c},_count:function(a,b){for(var c=0,d=a-1;a+1>=d;d++)for(var e=b-1;b+1>=e;e++)-1!==this.mines.indexOf(d+","+e)&&c++;return c},_buildBoard:function(){var a=[];this._getMines();for(var b=0;b<this.height;b++){for(var c=[],d=0;d<this.width;d++)c.push({state:"hidden",bomb:this.mines.indexOf(b+","+d)>=0,count:this._count(b,d)});a.push(c)}this._board=a}},c=Object.keys(b),d=0;d<c.length;d++)a.prototype[c[d]]=b[c[d]];return a}),function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.PointerEventsPolyfill=b()}(this,function(){"use strict";function a(){if(k){var a=new Map;return a.pointers=l,a}this.keys=[],this.values=[]}function b(a,b,c,d){this.addCallback=a.bind(d),this.removeCallback=b.bind(d),this.changedCallback=c.bind(d),x&&(this.observer=new x(this.mutationWatcher.bind(this)))}function c(a,b){b=b||Object.create(null);var c=document.createEvent("Event");c.initEvent(a,b.bubbles||!1,b.cancelable||!1);for(var d,e=2;e<B.length;e++)d=B[e],c[d]=b[d]||C[e];c.buttons=b.buttons||0;var f=0;return f=b.pressure?b.pressure:c.buttons?.5:0,c.x=c.clientX,c.y=c.clientY,c.pointerId=b.pointerId||0,c.width=b.width||0,c.height=b.height||0,c.pressure=f,c.tiltX=b.tiltX||0,c.tiltY=b.tiltY||0,c.pointerType=b.pointerType||"",c.hwTimestamp=b.hwTimestamp||0,c.isPrimary=b.isPrimary||!1,c}function d(a){return"body /shadow-deep/ "+e(a)}function e(a){return'[touch-action="'+a+'"]'}function f(a){return"{ -ms-touch-action: "+a+"; touch-action: "+a+"; touch-action-delay: none; }"}function g(){if(G){E.forEach(function(a){String(a)===a?(F+=e(a)+f(a)+"\n",H&&(F+=d(a)+f(a)+"\n")):(F+=a.selectors.map(e)+f(a.rule)+"\n",H&&(F+=a.selectors.map(d)+f(a.rule)+"\n"))});var a=document.createElement("style");a.textContent=F,document.head.appendChild(a)}}function h(){if(!window.PointerEvent){if(window.PointerEvent=D,window.navigator.msPointerEnabled){var a=window.navigator.msMaxTouchPoints;Object.defineProperty(window.navigator,"maxTouchPoints",{value:a,enumerable:!0}),r.registerSource("ms",da)}else r.registerSource("mouse",P),void 0!==window.ontouchstart&&r.registerSource("touch",_);r.register(document)}}function i(a){if(!r.pointermap.has(a))throw new Error("InvalidPointerId")}function j(){window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:Z},releasePointerCapture:{value:$}})}var k=window.Map&&window.Map.prototype.forEach,l=function(){return this.size};a.prototype={set:function(a,b){var c=this.keys.indexOf(a);c>-1?this.values[c]=b:(this.keys.push(a),this.values.push(b))},has:function(a){return this.keys.indexOf(a)>-1},"delete":function(a){var b=this.keys.indexOf(a);b>-1&&(this.keys.splice(b,1),this.values.splice(b,1))},get:function(a){var b=this.keys.indexOf(a);return this.values[b]},clear:function(){this.keys.length=0,this.values.length=0},forEach:function(a,b){this.values.forEach(function(c,d){a.call(b,c,this.keys[d],this)},this)},pointers:function(){return this.keys.length}};var m=a,n=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","buttons","pointerId","width","height","pressure","tiltX","tiltY","pointerType","hwTimestamp","isPrimary","type","target","currentTarget","which","pageX","pageY","timeStamp"],o=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0,0,0,0,0,0,"",0,!1,"",null,null,0,0,0,0],p="undefined"!=typeof SVGElementInstance,q={pointermap:new m,eventMap:Object.create(null),captureInfo:Object.create(null),eventSources:Object.create(null),eventSourceList:[],registerSource:function(a,b){var c=b,d=c.events;d&&(d.forEach(function(a){c[a]&&(this.eventMap[a]=c[a].bind(c))},this),this.eventSources[a]=c,this.eventSourceList.push(c))},register:function(a){for(var b,c=this.eventSourceList.length,d=0;c>d&&(b=this.eventSourceList[d]);d++)b.register.call(b,a)},unregister:function(a){for(var b,c=this.eventSourceList.length,d=0;c>d&&(b=this.eventSourceList[d]);d++)b.unregister.call(b,a)},contains:function(a,b){return a.contains(b)},down:function(a){a.bubbles=!0,this.fireEvent("pointerdown",a)},move:function(a){a.bubbles=!0,this.fireEvent("pointermove",a)},up:function(a){a.bubbles=!0,this.fireEvent("pointerup",a)},enter:function(a){a.bubbles=!1,this.fireEvent("pointerenter",a)},leave:function(a){a.bubbles=!1,this.fireEvent("pointerleave",a)},over:function(a){a.bubbles=!0,this.fireEvent("pointerover",a)},out:function(a){a.bubbles=!0,this.fireEvent("pointerout",a)},cancel:function(a){a.bubbles=!0,this.fireEvent("pointercancel",a)},leaveOut:function(a){this.out(a),this.contains(a.target,a.relatedTarget)||this.leave(a)},enterOver:function(a){this.over(a),this.contains(a.target,a.relatedTarget)||this.enter(a)},eventHandler:function(a){if(!a._handledByPE){var b=a.type,c=this.eventMap&&this.eventMap[b];c&&c(a),a._handledByPE=!0}},listen:function(a,b){b.forEach(function(b){this.addEvent(a,b)},this)},unlisten:function(a,b){b.forEach(function(b){this.removeEvent(a,b)},this)},addEvent:function(a,b){a.addEventListener(b,this.boundHandler)},removeEvent:function(a,b){a.removeEventListener(b,this.boundHandler)},makeEvent:function(a,b){this.captureInfo[b.pointerId]&&(b.relatedTarget=null);var c=new PointerEvent(a,b);return b.preventDefault&&(c.preventDefault=b.preventDefault),c._target=c._target||b.target,c},fireEvent:function(a,b){var c=this.makeEvent(a,b);return this.dispatchEvent(c)},cloneEvent:function(a){for(var b,c=Object.create(null),d=0;d<n.length;d++)b=n[d],c[b]=a[b]||o[d],!p||"target"!==b&&"relatedTarget"!==b||c[b]instanceof SVGElementInstance&&(c[b]=c[b].correspondingUseElement);return a.preventDefault&&(c.preventDefault=function(){a.preventDefault()}),c},getTarget:function(a){return this.captureInfo[a.pointerId]||a._target},setCapture:function(a,b){this.captureInfo[a]&&this.releaseCapture(a),this.captureInfo[a]=b;var c=document.createEvent("Event");c.initEvent("gotpointercapture",!0,!1),c.pointerId=a,this.implicitRelease=this.releaseCapture.bind(this,a),document.addEventListener("pointerup",this.implicitRelease),document.addEventListener("pointercancel",this.implicitRelease),c._target=b,this.asyncDispatchEvent(c)},releaseCapture:function(a){var b=this.captureInfo[a];if(b){var c=document.createEvent("Event");c.initEvent("lostpointercapture",!0,!1),c.pointerId=a,this.captureInfo[a]=void 0,document.removeEventListener("pointerup",this.implicitRelease),document.removeEventListener("pointercancel",this.implicitRelease),c._target=b,this.asyncDispatchEvent(c)}},dispatchEvent:function(a){var b=this.getTarget(a);return b?b.dispatchEvent(a):void 0},asyncDispatchEvent:function(a){requestAnimationFrame(this.dispatchEvent.bind(this,a))}};q.boundHandler=q.eventHandler.bind(q);var r=q,s={shadow:function(a){return a?a.shadowRoot||a.webkitShadowRoot:void 0},canTarget:function(a){return a&&Boolean(a.elementFromPoint)},targetingShadow:function(a){var b=this.shadow(a);return this.canTarget(b)?b:void 0},olderShadow:function(a){var b=a.olderShadowRoot;if(!b){var c=a.querySelector("shadow");c&&(b=c.olderShadowRoot)}return b},allShadows:function(a){for(var b=[],c=this.shadow(a);c;)b.push(c),c=this.olderShadow(c);return b},searchRoot:function(a,b,c){if(a){var d,e,f=a.elementFromPoint(b,c);for(e=this.targetingShadow(f);e;){if(d=e.elementFromPoint(b,c)){var g=this.targetingShadow(d);return this.searchRoot(g,b,c)||d}e=this.olderShadow(e)}return f}},owner:function(a){for(var b=a;b.parentNode;)b=b.parentNode;return b.nodeType!=Node.DOCUMENT_NODE&&b.nodeType!=Node.DOCUMENT_FRAGMENT_NODE&&(b=document),b},findTarget:function(a){var b=a.clientX,c=a.clientY,d=this.owner(a.target);return d.elementFromPoint(b,c)||(d=document),this.searchRoot(d,b,c)}},t=Array.prototype.forEach.call.bind(Array.prototype.forEach),u=Array.prototype.map.call.bind(Array.prototype.map),v=Array.prototype.slice.call.bind(Array.prototype.slice),w=Array.prototype.filter.call.bind(Array.prototype.filter),x=window.MutationObserver||window.WebKitMutationObserver,y="[touch-action]",z={subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["touch-action"]};b.prototype={watchSubtree:function(a){s.canTarget(a)&&this.observer.observe(a,z)},enableOnSubtree:function(a){this.watchSubtree(a),a===document&&"complete"!==document.readyState?this.installOnLoad():this.installNewSubtree(a)},installNewSubtree:function(a){t(this.findElements(a),this.addElement,this)},findElements:function(a){return a.querySelectorAll?a.querySelectorAll(y):[]},removeElement:function(a){this.removeCallback(a)},addElement:function(a){this.addCallback(a)},elementChanged:function(a,b){this.changedCallback(a,b)},concatLists:function(a,b){return a.concat(v(b))},installOnLoad:function(){document.addEventListener("readystatechange",function(){"complete"===document.readyState&&this.installNewSubtree(document)}.bind(this))},isElement:function(a){return a.nodeType===Node.ELEMENT_NODE},flattenMutationTree:function(a){var b=u(a,this.findElements,this);return b.push(w(a,this.isElement)),b.reduce(this.concatLists,[])},mutationWatcher:function(a){a.forEach(this.mutationHandler,this)},mutationHandler:function(a){if("childList"===a.type){var b=this.flattenMutationTree(a.addedNodes);b.forEach(this.addElement,this);var c=this.flattenMutationTree(a.removedNodes);c.forEach(this.removeElement,this)}else"attributes"===a.type&&this.elementChanged(a.target,a.oldValue)}},x||(b.prototype.watchSubtree=function(){console.warn("PointerEventsPolyfill: MutationObservers not found, touch-action will not be dynamically detected")});var A=b,B=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","pageX","pageY"],C=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0],D=c,E=["none","auto","pan-x","pan-y",{rule:"pan-x pan-y",selectors:["pan-x pan-y","pan-y pan-x"]}],F="",G=(document.head,window.PointerEvent||window.MSPointerEvent),H=!window.ShadowDOMPolyfill&&document.head.createShadowRoot,I=r.pointermap,J=25,K=[0,1,4,2],L=!1;try{L=1===new MouseEvent("test",{buttons:1}).buttons}catch(M){}var N,O={POINTER_ID:1,POINTER_TYPE:"mouse",events:["mousedown","mousemove","mouseup","mouseover","mouseout"],register:function(a){r.listen(a,this.events)},unregister:function(a){r.unlisten(a,this.events)},lastTouches:[],isEventSimulatedFromTouch:function(a){for(var b,c=this.lastTouches,d=a.clientX,e=a.clientY,f=0,g=c.length;g>f&&(b=c[f]);f++){var h=Math.abs(d-b.x),i=Math.abs(e-b.y);if(J>=h&&J>=i)return!0}},prepareEvent:function(a){var b=r.cloneEvent(a),c=b.preventDefault;return b.preventDefault=function(){a.preventDefault(),c()},b.pointerId=this.POINTER_ID,b.isPrimary=!0,b.pointerType=this.POINTER_TYPE,L||(b.buttons=K[b.which]||0),b},mousedown:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=I.has(this.POINTER_ID);b&&this.cancel(a);var c=this.prepareEvent(a);I.set(this.POINTER_ID,a),r.down(c)}},mousemove:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.move(b)}},mouseup:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=I.get(this.POINTER_ID);if(b&&b.button===a.button){var c=this.prepareEvent(a);r.up(c),this.cleanupMouse()}}},mouseover:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.enterOver(b)}},mouseout:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.leaveOut(b)}},cancel:function(a){var b=this.prepareEvent(a);r.cancel(b),this.cleanupMouse()},cleanupMouse:function(){I["delete"](this.POINTER_ID)}},P=O,Q=r.captureInfo,R=s.findTarget.bind(s),S=s.allShadows.bind(s),T=r.pointermap,U=(Array.prototype.map.call.bind(Array.prototype.map),2500),V=200,W="touch-action",X=!1,Y={events:["touchstart","touchmove","touchend","touchcancel"],register:function(a){X?r.listen(a,this.events):N.enableOnSubtree(a)},unregister:function(a){X&&r.unlisten(a,this.events)},elementAdded:function(a){var b=a.getAttribute(W),c=this.touchActionToScrollType(b);c&&(a._scrollType=c,r.listen(a,this.events),S(a).forEach(function(a){a._scrollType=c,r.listen(a,this.events)},this))},elementRemoved:function(a){a._scrollType=void 0,r.unlisten(a,this.events),S(a).forEach(function(a){a._scrollType=void 0,r.unlisten(a,this.events)},this)},elementChanged:function(a,b){var c=a.getAttribute(W),d=this.touchActionToScrollType(c),e=this.touchActionToScrollType(b);d&&e?(a._scrollType=d,S(a).forEach(function(a){a._scrollType=d},this)):e?this.elementRemoved(a):d&&this.elementAdded(a)},scrollTypes:{EMITTER:"none",XSCROLLER:"pan-x",YSCROLLER:"pan-y",SCROLLER:/^(?:pan-x pan-y)|(?:pan-y pan-x)|auto$/},touchActionToScrollType:function(a){var b=a,c=this.scrollTypes;return"none"===b?"none":b===c.XSCROLLER?"X":b===c.YSCROLLER?"Y":c.SCROLLER.exec(b)?"XY":void 0},POINTER_TYPE:"touch",firstTouch:null,isPrimaryTouch:function(a){return this.firstTouch===a.identifier},setPrimaryTouch:function(a){(0===T.pointers()||1===T.pointers()&&T.has(1))&&(this.firstTouch=a.identifier,this.firstXY={X:a.clientX,Y:a.clientY},this.scrolling=!1,this.cancelResetClickCount())},removePrimaryPointer:function(a){a.isPrimary&&(this.firstTouch=null,this.firstXY=null,this.resetClickCount())},clickCount:0,resetId:null,resetClickCount:function(){var a=function(){this.clickCount=0,this.resetId=null}.bind(this);this.resetId=setTimeout(a,V)},cancelResetClickCount:function(){this.resetId&&clearTimeout(this.resetId)},typeToButtons:function(a){var b=0;return("touchstart"===a||"touchmove"===a)&&(b=1),b},touchToPointer:function(a){var b=this.currentTouchEvent,c=r.cloneEvent(a),d=c.pointerId=a.identifier+2;c.target=Q[d]||R(c),c.bubbles=!0,c.cancelable=!0,c.detail=this.clickCount,c.button=0,c.buttons=this.typeToButtons(b.type),c.width=a.webkitRadiusX||a.radiusX||0,c.height=a.webkitRadiusY||a.radiusY||0,c.pressure=a.webkitForce||a.force||.5,c.isPrimary=this.isPrimaryTouch(a),c.pointerType=this.POINTER_TYPE;var e=this;return c.preventDefault=function(){e.scrolling=!1,e.firstXY=null,b.preventDefault()},c},processTouches:function(a,b){var c=a.changedTouches;this.currentTouchEvent=a;for(var d,e=0;e<c.length;e++)d=c[e],b.call(this,this.touchToPointer(d))},shouldScroll:function(a){if(this.firstXY){var b,c=a.currentTarget._scrollType;if("none"===c)b=!1;else if("XY"===c)b=!0;else{var d=a.changedTouches[0],e=c,f="Y"===c?"X":"Y",g=Math.abs(d["client"+e]-this.firstXY[e]),h=Math.abs(d["client"+f]-this.firstXY[f]);b=g>=h}return this.firstXY=null,b}},findTouch:function(a,b){for(var c,d=0,e=a.length;e>d&&(c=a[d]);d++)if(c.identifier===b)return!0},vacuumTouches:function(a){var b=a.touches;if(T.pointers()>=b.length){var c=[];T.forEach(function(a,d){if(1!==d&&!this.findTouch(b,d-2)){var e=a.out;c.push(e)}},this),c.forEach(this.cancelOut,this)}},touchstart:function(a){this.vacuumTouches(a),this.setPrimaryTouch(a.changedTouches[0]),this.dedupSynthMouse(a),this.scrolling||(this.clickCount++,this.processTouches(a,this.overDown))},overDown:function(a){T.set(a.pointerId,{target:a.target,out:a,outTarget:a.target});r.over(a),r.enter(a),r.down(a)},touchmove:function(a){this.scrolling||(this.shouldScroll(a)?(this.scrolling=!0,this.touchcancel(a)):(a.preventDefault(),this.processTouches(a,this.moveOverOut)))},moveOverOut:function(a){var b=a,c=T.get(b.pointerId);if(c){var d=c.out,e=c.outTarget;r.move(b),d&&e!==b.target&&(d.relatedTarget=b.target,b.relatedTarget=e,d.target=e,b.target?(r.leaveOut(d),r.enterOver(b)):(b.target=e,b.relatedTarget=null,this.cancelOut(b))),c.out=b,c.outTarget=b.target}},touchend:function(a){this.dedupSynthMouse(a),this.processTouches(a,this.upOut)},upOut:function(a){this.scrolling||(r.up(a),r.out(a),r.leave(a)),this.cleanUpPointer(a)},touchcancel:function(a){this.processTouches(a,this.cancelOut)},cancelOut:function(a){r.cancel(a),r.out(a),r.leave(a),this.cleanUpPointer(a)},cleanUpPointer:function(a){T["delete"](a.pointerId),this.removePrimaryPointer(a)},dedupSynthMouse:function(a){var b=P.lastTouches,c=a.changedTouches[0];if(this.isPrimaryTouch(c)){var d={x:c.clientX,y:c.clientY};b.push(d);var e=function(a,b){var c=a.indexOf(b);c>-1&&a.splice(c,1)}.bind(null,b,d);setTimeout(e,U)}}};X||(N=new A(Y.elementAdded,Y.elementRemoved,Y.elementChanged,Y));var Z,$,_=Y,aa=r.pointermap,ba=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,ca={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(a){r.listen(a,this.events)},unregister:function(a){r.unlisten(a,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(a){var b=a;return ba&&(b=r.cloneEvent(a),b.pointerType=this.POINTER_TYPES[a.pointerType]),b},cleanup:function(a){aa["delete"](a)},MSPointerDown:function(a){aa.set(a.pointerId,a);var b=this.prepareEvent(a);r.down(b)},MSPointerMove:function(a){var b=this.prepareEvent(a);r.move(b)},MSPointerUp:function(a){var b=this.prepareEvent(a);r.up(b),this.cleanup(a.pointerId)},MSPointerOut:function(a){var b=this.prepareEvent(a);r.leaveOut(b)},MSPointerOver:function(a){var b=this.prepareEvent(a);r.enterOver(b)},MSPointerCancel:function(a){var b=this.prepareEvent(a);r.cancel(b),this.cleanup(a.pointerId)},MSLostPointerCapture:function(a){var b=r.makeEvent("lostpointercapture",a);r.dispatchEvent(b)},MSGotPointerCapture:function(a){var b=r.makeEvent("gotpointercapture",a);r.dispatchEvent(b)}},da=ca,ea=window.navigator;ea.msPointerEnabled?(Z=function(a){i(a),this.msSetPointerCapture(a)},$=function(a){i(a),this.msReleasePointerCapture(a)}):(Z=function(a){i(a),r.setCapture(a,this)},$=function(a){i(a),r.releaseCapture(a,this)}),g(),h(),j();var fa={dispatcher:r,Installer:A,PointerEvent:D,PointerMap:m,targetFinding:s};return fa}),function(a,b){"function"==typeof define&&define.amd?define(["jquery","handlebars","node_modules/arraysweeper/index.js"],b):"object"==typeof exports?module.exports=b(jQuery,Handlebars,Arraysweeper):b(jQuery,Handlebars,Arraysweeper)}(this,function(a,b,c){return a.arraysweeper=function(b,c,d,e){return this.element=a(b),this.height=c,this.width=d,this.count=e,this.refresh(!1),this._bindEvents(),this},a.fn.arraysweeper=function(b,c,d){return this.data("arraysweeper",new a.arraysweeper(this,b,c,d)),this},a.extend(a.arraysweeper.prototype,{refresh:function(a){if(a!==!1){var b=this.toolbar.getValues();this.width=b.width,this.height=b.height,this.count=b.count}this.board=new c(this.height,this.width,this.count),this.element.html(this.templates.game({})),this.boardElement=this.element.find(".as-gameboard"),this.screen=this.element.find(".as-screen"),this.toolbar.init(this.element,this.height,this.width,this.count),this.renderBoard(),this.setHeight()},toolbar:{getValues:function(){return{width:this.width.val(),height:this.height.val(),count:this.count.val()}},init:function(a,b,c,d){this.element=a,this.width=a.find(".as-width-input"),this.height=a.find(".as-height-input"),this.count=a.find(".as-count-input"),this.remaining=this.element.find(".remaining-val"),this.setValues(b,c,d)},setValues:function(a,b,c){this.remaining.html(c),this.width.val(b),this.height.val(a),this.count.val(c)}},renderBoard:function(){this.boardElement.html(this.templates.board(this.board.getBoard()))},setHeight:function(){this.styleSheet&&this.styleSheet.remove(),this.styleSheet=a("<style>").appendTo(this.element),this.styleSheet.html(".as-game-space { height: "+this.element.find(".as-game-space").eq(0).width()+"px; }")},_on:function(a,b,c){var d=this;this.element.on(a,b,function(){d.handlers[c].apply(d,arguments)})},flagTime:500,handlers:{reveal:function(b){if(!a(b.target).hasClass("flag")){var c=b.target.getAttribute("data-as-location").split(","),d=this.board.reveal(Number(c[0]),Number(c[1]));"Game Over!"===d?this.screen.addClass("as-failure"):"You Win!"===d&&this.screen.addClass("as-success"),this.renderBoard(),this.toolbar.remaining.html(this.board.count.mines-this.board.count.flags)}},flag:function(a){if(!(3!==a.which&&(new Date).getTime()-this.pointerTime<this.flagTime)){a.preventDefault();var b=a.target.getAttribute("data-as-location").split(",");this.board.flag(parseInt(b[0],10),parseInt(b[1],10),!this.board.flag(parseInt(b[0],10),parseInt(b[1],10))),this.renderBoard()}},recordPointer:function(){this.pointerTime=(new Date).getTime()},prevent:function(a){a.preventDefault()},refresh:function(){console.log("refresh"),this.refresh()},settings:function(){this.toolbar.element.find(".as-settings-panel").toggleClass("as-settings-panel-hidden")},help:function(){this.toolbar.element.find(".as-help-panel").toggleClass("as-help-panel-hidden")}},_bindEvents:function(){var b=this;this._on("click",".as-reset","refresh"),this._on("click",".as-settings","settings"),this._on("click",".as-help","help"),this._on("click",".as-game-space:not( .revealed )","reveal"),this._on("pointerup",".as-game-space:not( .revealed )","flag"),this._on("touchstart pointerdown",".as-game-space:not( .revealed )","recordPointer"),this._on("contextmenu",".as-game-space:not( .revealed )","prevent"),a(window).on("resize",function(){b.setHeight.apply(b,arguments)})}}),a.fn.arraysweeper}),this.$=this.$||{},this.$.arraysweeper=this.$.arraysweeper||{},this.$.arraysweeper.prototype=this.$.arraysweeper.prototype||{},this.$.arraysweeper.prototype.templates=this.$.arraysweeper.prototype.templates||{},Handlebars.registerPartial("help",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="row as-help-panel as-help-panel-hidden">\n <h3 class="as-help-title">Help and Instructions</h3>\n <ul class="as-help-list">\n <li><p>Click on a space to reveal it</p></li>\n <li><p>Right Click or Hold Down on a space for more then .5 seconds to flag or unflag a space</p></li>\n <li><p>The number on a space indicates the number of mines which it touches</p></li>\n <li><p>If any space you reveal touchs a space which has a count of 0 it will also be revealed</p></li>\n <li><p>Click Reset / ⟳ at any time to reset the game</p></li>\n <li><p>Click settings / ⚙ to toggle the board settings panel</p></li>\n <li><p>Click reset after adjust settings to make them take effect</p></li>\n </ul>\n</div>'},useData:!0})),Handlebars.registerPartial("settings",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="row as-settings-panel as-settings-panel-hidden">\n <div class="col-xs-4">\n <label for="as-mine-count">Mine Count: </label>\n <input type="number" id="as-mine-count" class="as-count-input">\n </div>\n <div class="col-xs-4">\n <label for="as-board-width">Board Width: </label>\n <input type="number" id="as-mine-width" class="as-width-input">\n </div>\n <div class="col-xs-4">\n <label for="as-board-height">Board Height: </label>\n <input type="number" id="as-mine-height" class="as-height-input">\n </div>\n</div>'},useData:!0})),Handlebars.registerPartial("toolbar",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="as-toolbar row">\n <div class="col-xs-8 as-remaining">\n Remaining: <span class="remaining-val"></span>\n </div>\n <div class="col-xs as-reset" title="reset">\n ⟳\n </div>\n <div class="col-xs as-settings" title="settings">\n ⚙\n </div>\n <div class="col-xs as-help" title="help">\n ?\n </div>\n</div>'},useData:!0})),this.$.arraysweeper.prototype.templates.board=Handlebars.template({1:function(a,b,c,d,e,f){var g;return' <div class="row">\n'+(null!=(g=b.each.call(a,a,{name:"each",hash:{},fn:this.program(2,d,0,e,f),inverse:this.noop,data:d}))?g:"")+" </div>\n"},2:function(a,b,c,d,e,f){var g,h,i=this.escapeExpression,j=b.helperMissing,k="function";return' <div toush-action="auto" tabindex="-1" data-as-location="'+i(this.lambda(this.data(d,1)&&this.data(d,1).index,a))+","+i((h=null!=(h=b.index||d&&d.index)?h:j,typeof h===k?h.call(a,{name:"index",hash:{},data:d}):h))+'" class="as-game-space '+i((h=null!=(h=b.state||(null!=a?a.state:a))?h:j,typeof h===k?h.call(a,{name:"state",hash:{},data:d}):h))+' col-xs">\n <div class="as-content">\n'+(null!=(g=b["if"].call(a,null!=a?a.bomb:a,{name:"if",hash:{},fn:this.program(3,d,0,e,f),inverse:this.program(5,d,0,e,f),data:d}))?g:"")+" </div>\n </div>\n"},3:function(a,b,c,d){return" 💣\n"},5:function(a,b,c,d){var e;return" "+this.escapeExpression((e=null!=(e=b.count||(null!=a?a.count:a))?e:b.helperMissing,"function"==typeof e?e.call(a,{name:"count",hash:{},data:d}):e))+"\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d,e,f){var g;return null!=(g=b.each.call(a,a,{name:"each",hash:{},fn:this.program(1,d,0,e,f),inverse:this.noop,data:d}))?g:""},useData:!0,useDepths:!0}),this.$.arraysweeper.prototype.templates.game=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){var e;return'<div class="as-mine">\n <div class="as-toolbar-wrap">\n'+(null!=(e=this.invokePartial(c.toolbar,a,{name:"toolbar",data:d,indent:" ",helpers:b,partials:c}))?e:"")+(null!=(e=this.invokePartial(c.settings,a,{name:"settings",data:d,indent:" ",helpers:b,partials:c}))?e:"")+(null!=(e=this.invokePartial(c.help,a,{name:"help",data:d,indent:" ",helpers:b,partials:c}))?e:"")+' </div>\n <div class="board-wrap">\n <div class="as-gameboard">\n\n </div>\n <div class="as-screen">\n\n </div>\n </div>\n</div>'},usePartial:!0,useData:!0}); | ||
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.Arraysweeper=b()}(this,function(){for(var a=function(a,b,c){this.height=a,this.width=b,this.count={mines:c,hidden:b*a,moves:0,revealed:0,flags:0},this._buildBoard()},b={mineCount:function(a,b){return"revealed"===this._board[a][b].state?this._board[a][b].count:"Reveal space to see count"},flag:function(a,b,c){return void 0===c?"flag"===this._board[a][b].state:(this.count.flags=this.count.flags+(c?1:-1),this.count.hidden=this.count.hidden-(c?1:-1),this._board[a][b].state=c?"flag":"hidden",this.count.flags+this.count.hidden===this.count.mines?"You Win!":void 0)},reveal:function(a,b){var c,d,e=this._board[a][b];return e.bomb&&0!==this.count.moves?"Game Over!":(e.bomb?this._buildBoard():this.count.flags+this.count.hidden===this.count.mines+1&&(c="You Win!"),this.count.moves++,d=this._reveal(a,b),c||d)},render:function(){for(var a=[],b=0;b<this.height;b++)a.push(JSON.stringify(this._board[b].map(this._renderMap)));console.log(a.join(",\n"))},getBoard:function(){return this._board},_renderMap:function(a){return"revealed"===a.state?a.count.toString():"flag"===a.state?"!":"X"},_getMines:function(){this.mines=[];for(var a=0;a<this.count.mines;a++){for(var b,c=!1;c===!1;){var d=this._getMine();-1===this.mines.indexOf(d.row+","+d.col)&&(b=d,c=!0)}this.mines.push(b.row+","+b.col)}},_getMine:function(){return{row:Math.floor(Math.random()*(this.height-1)),col:Math.floor(Math.random()*(this.width-1))}},_reveal:function(a,b,c,d){d=d||0,c="object"==typeof c?c:[],this._board[a][b].state="revealed",this.count.revealed++,this.count.hidden--;for(var e=a-1>0?a-1:0;a+1>=e&&e<this.width;e++)for(var f=b-1>0?b-1:0;b+1>=f&&f<this.width;f++)e>=0&&f>=0&&e<this.height&&f<this.width&&0===this._board[e][f].count&&"revealed"!==this._board[e][f].state&&!this._board[e][f].bomb&&-1===c.indexOf(e+","+f)&&(e!==a||f!==b)&&(this._board[e][f].state="",c.push(e+","+f));if(c.length&&c.length>=d+1){var g=c[d].split(",");this._reveal(parseFloat(g[0],10),parseFloat(g[1],10),c,d+1)}return c},_count:function(a,b){for(var c=0,d=a-1;a+1>=d;d++)for(var e=b-1;b+1>=e;e++)-1!==this.mines.indexOf(d+","+e)&&c++;return c},_buildBoard:function(){var a=[];this._getMines();for(var b=0;b<this.height;b++){for(var c=[],d=0;d<this.width;d++)c.push({state:"hidden",bomb:this.mines.indexOf(b+","+d)>=0,count:this._count(b,d)});a.push(c)}this._board=a}},c=Object.keys(b),d=0;d<c.length;d++)a.prototype[c[d]]=b[c[d]];return a}),function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.PointerEventsPolyfill=b()}(this,function(){"use strict";function a(){if(k){var a=new Map;return a.pointers=l,a}this.keys=[],this.values=[]}function b(a,b,c,d){this.addCallback=a.bind(d),this.removeCallback=b.bind(d),this.changedCallback=c.bind(d),x&&(this.observer=new x(this.mutationWatcher.bind(this)))}function c(a,b){b=b||Object.create(null);var c=document.createEvent("Event");c.initEvent(a,b.bubbles||!1,b.cancelable||!1);for(var d,e=2;e<B.length;e++)d=B[e],c[d]=b[d]||C[e];c.buttons=b.buttons||0;var f=0;return f=b.pressure?b.pressure:c.buttons?.5:0,c.x=c.clientX,c.y=c.clientY,c.pointerId=b.pointerId||0,c.width=b.width||0,c.height=b.height||0,c.pressure=f,c.tiltX=b.tiltX||0,c.tiltY=b.tiltY||0,c.pointerType=b.pointerType||"",c.hwTimestamp=b.hwTimestamp||0,c.isPrimary=b.isPrimary||!1,c}function d(a){return"body /shadow-deep/ "+e(a)}function e(a){return'[touch-action="'+a+'"]'}function f(a){return"{ -ms-touch-action: "+a+"; touch-action: "+a+"; touch-action-delay: none; }"}function g(){if(G){E.forEach(function(a){String(a)===a?(F+=e(a)+f(a)+"\n",H&&(F+=d(a)+f(a)+"\n")):(F+=a.selectors.map(e)+f(a.rule)+"\n",H&&(F+=a.selectors.map(d)+f(a.rule)+"\n"))});var a=document.createElement("style");a.textContent=F,document.head.appendChild(a)}}function h(){if(!window.PointerEvent){if(window.PointerEvent=D,window.navigator.msPointerEnabled){var a=window.navigator.msMaxTouchPoints;Object.defineProperty(window.navigator,"maxTouchPoints",{value:a,enumerable:!0}),r.registerSource("ms",da)}else r.registerSource("mouse",P),void 0!==window.ontouchstart&&r.registerSource("touch",_);r.register(document)}}function i(a){if(!r.pointermap.has(a))throw new Error("InvalidPointerId")}function j(){window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:Z},releasePointerCapture:{value:$}})}var k=window.Map&&window.Map.prototype.forEach,l=function(){return this.size};a.prototype={set:function(a,b){var c=this.keys.indexOf(a);c>-1?this.values[c]=b:(this.keys.push(a),this.values.push(b))},has:function(a){return this.keys.indexOf(a)>-1},"delete":function(a){var b=this.keys.indexOf(a);b>-1&&(this.keys.splice(b,1),this.values.splice(b,1))},get:function(a){var b=this.keys.indexOf(a);return this.values[b]},clear:function(){this.keys.length=0,this.values.length=0},forEach:function(a,b){this.values.forEach(function(c,d){a.call(b,c,this.keys[d],this)},this)},pointers:function(){return this.keys.length}};var m=a,n=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","buttons","pointerId","width","height","pressure","tiltX","tiltY","pointerType","hwTimestamp","isPrimary","type","target","currentTarget","which","pageX","pageY","timeStamp"],o=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0,0,0,0,0,0,"",0,!1,"",null,null,0,0,0,0],p="undefined"!=typeof SVGElementInstance,q={pointermap:new m,eventMap:Object.create(null),captureInfo:Object.create(null),eventSources:Object.create(null),eventSourceList:[],registerSource:function(a,b){var c=b,d=c.events;d&&(d.forEach(function(a){c[a]&&(this.eventMap[a]=c[a].bind(c))},this),this.eventSources[a]=c,this.eventSourceList.push(c))},register:function(a){for(var b,c=this.eventSourceList.length,d=0;c>d&&(b=this.eventSourceList[d]);d++)b.register.call(b,a)},unregister:function(a){for(var b,c=this.eventSourceList.length,d=0;c>d&&(b=this.eventSourceList[d]);d++)b.unregister.call(b,a)},contains:function(a,b){return a.contains(b)},down:function(a){a.bubbles=!0,this.fireEvent("pointerdown",a)},move:function(a){a.bubbles=!0,this.fireEvent("pointermove",a)},up:function(a){a.bubbles=!0,this.fireEvent("pointerup",a)},enter:function(a){a.bubbles=!1,this.fireEvent("pointerenter",a)},leave:function(a){a.bubbles=!1,this.fireEvent("pointerleave",a)},over:function(a){a.bubbles=!0,this.fireEvent("pointerover",a)},out:function(a){a.bubbles=!0,this.fireEvent("pointerout",a)},cancel:function(a){a.bubbles=!0,this.fireEvent("pointercancel",a)},leaveOut:function(a){this.out(a),this.contains(a.target,a.relatedTarget)||this.leave(a)},enterOver:function(a){this.over(a),this.contains(a.target,a.relatedTarget)||this.enter(a)},eventHandler:function(a){if(!a._handledByPE){var b=a.type,c=this.eventMap&&this.eventMap[b];c&&c(a),a._handledByPE=!0}},listen:function(a,b){b.forEach(function(b){this.addEvent(a,b)},this)},unlisten:function(a,b){b.forEach(function(b){this.removeEvent(a,b)},this)},addEvent:function(a,b){a.addEventListener(b,this.boundHandler)},removeEvent:function(a,b){a.removeEventListener(b,this.boundHandler)},makeEvent:function(a,b){this.captureInfo[b.pointerId]&&(b.relatedTarget=null);var c=new PointerEvent(a,b);return b.preventDefault&&(c.preventDefault=b.preventDefault),c._target=c._target||b.target,c},fireEvent:function(a,b){var c=this.makeEvent(a,b);return this.dispatchEvent(c)},cloneEvent:function(a){for(var b,c=Object.create(null),d=0;d<n.length;d++)b=n[d],c[b]=a[b]||o[d],!p||"target"!==b&&"relatedTarget"!==b||c[b]instanceof SVGElementInstance&&(c[b]=c[b].correspondingUseElement);return a.preventDefault&&(c.preventDefault=function(){a.preventDefault()}),c},getTarget:function(a){return this.captureInfo[a.pointerId]||a._target},setCapture:function(a,b){this.captureInfo[a]&&this.releaseCapture(a),this.captureInfo[a]=b;var c=document.createEvent("Event");c.initEvent("gotpointercapture",!0,!1),c.pointerId=a,this.implicitRelease=this.releaseCapture.bind(this,a),document.addEventListener("pointerup",this.implicitRelease),document.addEventListener("pointercancel",this.implicitRelease),c._target=b,this.asyncDispatchEvent(c)},releaseCapture:function(a){var b=this.captureInfo[a];if(b){var c=document.createEvent("Event");c.initEvent("lostpointercapture",!0,!1),c.pointerId=a,this.captureInfo[a]=void 0,document.removeEventListener("pointerup",this.implicitRelease),document.removeEventListener("pointercancel",this.implicitRelease),c._target=b,this.asyncDispatchEvent(c)}},dispatchEvent:function(a){var b=this.getTarget(a);return b?b.dispatchEvent(a):void 0},asyncDispatchEvent:function(a){requestAnimationFrame(this.dispatchEvent.bind(this,a))}};q.boundHandler=q.eventHandler.bind(q);var r=q,s={shadow:function(a){return a?a.shadowRoot||a.webkitShadowRoot:void 0},canTarget:function(a){return a&&Boolean(a.elementFromPoint)},targetingShadow:function(a){var b=this.shadow(a);return this.canTarget(b)?b:void 0},olderShadow:function(a){var b=a.olderShadowRoot;if(!b){var c=a.querySelector("shadow");c&&(b=c.olderShadowRoot)}return b},allShadows:function(a){for(var b=[],c=this.shadow(a);c;)b.push(c),c=this.olderShadow(c);return b},searchRoot:function(a,b,c){if(a){var d,e,f=a.elementFromPoint(b,c);for(e=this.targetingShadow(f);e;){if(d=e.elementFromPoint(b,c)){var g=this.targetingShadow(d);return this.searchRoot(g,b,c)||d}e=this.olderShadow(e)}return f}},owner:function(a){for(var b=a;b.parentNode;)b=b.parentNode;return b.nodeType!=Node.DOCUMENT_NODE&&b.nodeType!=Node.DOCUMENT_FRAGMENT_NODE&&(b=document),b},findTarget:function(a){var b=a.clientX,c=a.clientY,d=this.owner(a.target);return d.elementFromPoint(b,c)||(d=document),this.searchRoot(d,b,c)}},t=Array.prototype.forEach.call.bind(Array.prototype.forEach),u=Array.prototype.map.call.bind(Array.prototype.map),v=Array.prototype.slice.call.bind(Array.prototype.slice),w=Array.prototype.filter.call.bind(Array.prototype.filter),x=window.MutationObserver||window.WebKitMutationObserver,y="[touch-action]",z={subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["touch-action"]};b.prototype={watchSubtree:function(a){s.canTarget(a)&&this.observer.observe(a,z)},enableOnSubtree:function(a){this.watchSubtree(a),a===document&&"complete"!==document.readyState?this.installOnLoad():this.installNewSubtree(a)},installNewSubtree:function(a){t(this.findElements(a),this.addElement,this)},findElements:function(a){return a.querySelectorAll?a.querySelectorAll(y):[]},removeElement:function(a){this.removeCallback(a)},addElement:function(a){this.addCallback(a)},elementChanged:function(a,b){this.changedCallback(a,b)},concatLists:function(a,b){return a.concat(v(b))},installOnLoad:function(){document.addEventListener("readystatechange",function(){"complete"===document.readyState&&this.installNewSubtree(document)}.bind(this))},isElement:function(a){return a.nodeType===Node.ELEMENT_NODE},flattenMutationTree:function(a){var b=u(a,this.findElements,this);return b.push(w(a,this.isElement)),b.reduce(this.concatLists,[])},mutationWatcher:function(a){a.forEach(this.mutationHandler,this)},mutationHandler:function(a){if("childList"===a.type){var b=this.flattenMutationTree(a.addedNodes);b.forEach(this.addElement,this);var c=this.flattenMutationTree(a.removedNodes);c.forEach(this.removeElement,this)}else"attributes"===a.type&&this.elementChanged(a.target,a.oldValue)}},x||(b.prototype.watchSubtree=function(){console.warn("PointerEventsPolyfill: MutationObservers not found, touch-action will not be dynamically detected")});var A=b,B=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","pageX","pageY"],C=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0],D=c,E=["none","auto","pan-x","pan-y",{rule:"pan-x pan-y",selectors:["pan-x pan-y","pan-y pan-x"]}],F="",G=(document.head,window.PointerEvent||window.MSPointerEvent),H=!window.ShadowDOMPolyfill&&document.head.createShadowRoot,I=r.pointermap,J=25,K=[0,1,4,2],L=!1;try{L=1===new MouseEvent("test",{buttons:1}).buttons}catch(M){}var N,O={POINTER_ID:1,POINTER_TYPE:"mouse",events:["mousedown","mousemove","mouseup","mouseover","mouseout"],register:function(a){r.listen(a,this.events)},unregister:function(a){r.unlisten(a,this.events)},lastTouches:[],isEventSimulatedFromTouch:function(a){for(var b,c=this.lastTouches,d=a.clientX,e=a.clientY,f=0,g=c.length;g>f&&(b=c[f]);f++){var h=Math.abs(d-b.x),i=Math.abs(e-b.y);if(J>=h&&J>=i)return!0}},prepareEvent:function(a){var b=r.cloneEvent(a),c=b.preventDefault;return b.preventDefault=function(){a.preventDefault(),c()},b.pointerId=this.POINTER_ID,b.isPrimary=!0,b.pointerType=this.POINTER_TYPE,L||(b.buttons=K[b.which]||0),b},mousedown:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=I.has(this.POINTER_ID);b&&this.cancel(a);var c=this.prepareEvent(a);I.set(this.POINTER_ID,a),r.down(c)}},mousemove:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.move(b)}},mouseup:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=I.get(this.POINTER_ID);if(b&&b.button===a.button){var c=this.prepareEvent(a);r.up(c),this.cleanupMouse()}}},mouseover:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.enterOver(b)}},mouseout:function(a){if(!this.isEventSimulatedFromTouch(a)){var b=this.prepareEvent(a);r.leaveOut(b)}},cancel:function(a){var b=this.prepareEvent(a);r.cancel(b),this.cleanupMouse()},cleanupMouse:function(){I["delete"](this.POINTER_ID)}},P=O,Q=r.captureInfo,R=s.findTarget.bind(s),S=s.allShadows.bind(s),T=r.pointermap,U=(Array.prototype.map.call.bind(Array.prototype.map),2500),V=200,W="touch-action",X=!1,Y={events:["touchstart","touchmove","touchend","touchcancel"],register:function(a){X?r.listen(a,this.events):N.enableOnSubtree(a)},unregister:function(a){X&&r.unlisten(a,this.events)},elementAdded:function(a){var b=a.getAttribute(W),c=this.touchActionToScrollType(b);c&&(a._scrollType=c,r.listen(a,this.events),S(a).forEach(function(a){a._scrollType=c,r.listen(a,this.events)},this))},elementRemoved:function(a){a._scrollType=void 0,r.unlisten(a,this.events),S(a).forEach(function(a){a._scrollType=void 0,r.unlisten(a,this.events)},this)},elementChanged:function(a,b){var c=a.getAttribute(W),d=this.touchActionToScrollType(c),e=this.touchActionToScrollType(b);d&&e?(a._scrollType=d,S(a).forEach(function(a){a._scrollType=d},this)):e?this.elementRemoved(a):d&&this.elementAdded(a)},scrollTypes:{EMITTER:"none",XSCROLLER:"pan-x",YSCROLLER:"pan-y",SCROLLER:/^(?:pan-x pan-y)|(?:pan-y pan-x)|auto$/},touchActionToScrollType:function(a){var b=a,c=this.scrollTypes;return"none"===b?"none":b===c.XSCROLLER?"X":b===c.YSCROLLER?"Y":c.SCROLLER.exec(b)?"XY":void 0},POINTER_TYPE:"touch",firstTouch:null,isPrimaryTouch:function(a){return this.firstTouch===a.identifier},setPrimaryTouch:function(a){(0===T.pointers()||1===T.pointers()&&T.has(1))&&(this.firstTouch=a.identifier,this.firstXY={X:a.clientX,Y:a.clientY},this.scrolling=!1,this.cancelResetClickCount())},removePrimaryPointer:function(a){a.isPrimary&&(this.firstTouch=null,this.firstXY=null,this.resetClickCount())},clickCount:0,resetId:null,resetClickCount:function(){var a=function(){this.clickCount=0,this.resetId=null}.bind(this);this.resetId=setTimeout(a,V)},cancelResetClickCount:function(){this.resetId&&clearTimeout(this.resetId)},typeToButtons:function(a){var b=0;return("touchstart"===a||"touchmove"===a)&&(b=1),b},touchToPointer:function(a){var b=this.currentTouchEvent,c=r.cloneEvent(a),d=c.pointerId=a.identifier+2;c.target=Q[d]||R(c),c.bubbles=!0,c.cancelable=!0,c.detail=this.clickCount,c.button=0,c.buttons=this.typeToButtons(b.type),c.width=a.webkitRadiusX||a.radiusX||0,c.height=a.webkitRadiusY||a.radiusY||0,c.pressure=a.webkitForce||a.force||.5,c.isPrimary=this.isPrimaryTouch(a),c.pointerType=this.POINTER_TYPE;var e=this;return c.preventDefault=function(){e.scrolling=!1,e.firstXY=null,b.preventDefault()},c},processTouches:function(a,b){var c=a.changedTouches;this.currentTouchEvent=a;for(var d,e=0;e<c.length;e++)d=c[e],b.call(this,this.touchToPointer(d))},shouldScroll:function(a){if(this.firstXY){var b,c=a.currentTarget._scrollType;if("none"===c)b=!1;else if("XY"===c)b=!0;else{var d=a.changedTouches[0],e=c,f="Y"===c?"X":"Y",g=Math.abs(d["client"+e]-this.firstXY[e]),h=Math.abs(d["client"+f]-this.firstXY[f]);b=g>=h}return this.firstXY=null,b}},findTouch:function(a,b){for(var c,d=0,e=a.length;e>d&&(c=a[d]);d++)if(c.identifier===b)return!0},vacuumTouches:function(a){var b=a.touches;if(T.pointers()>=b.length){var c=[];T.forEach(function(a,d){if(1!==d&&!this.findTouch(b,d-2)){var e=a.out;c.push(e)}},this),c.forEach(this.cancelOut,this)}},touchstart:function(a){this.vacuumTouches(a),this.setPrimaryTouch(a.changedTouches[0]),this.dedupSynthMouse(a),this.scrolling||(this.clickCount++,this.processTouches(a,this.overDown))},overDown:function(a){T.set(a.pointerId,{target:a.target,out:a,outTarget:a.target});r.over(a),r.enter(a),r.down(a)},touchmove:function(a){this.scrolling||(this.shouldScroll(a)?(this.scrolling=!0,this.touchcancel(a)):(a.preventDefault(),this.processTouches(a,this.moveOverOut)))},moveOverOut:function(a){var b=a,c=T.get(b.pointerId);if(c){var d=c.out,e=c.outTarget;r.move(b),d&&e!==b.target&&(d.relatedTarget=b.target,b.relatedTarget=e,d.target=e,b.target?(r.leaveOut(d),r.enterOver(b)):(b.target=e,b.relatedTarget=null,this.cancelOut(b))),c.out=b,c.outTarget=b.target}},touchend:function(a){this.dedupSynthMouse(a),this.processTouches(a,this.upOut)},upOut:function(a){this.scrolling||(r.up(a),r.out(a),r.leave(a)),this.cleanUpPointer(a)},touchcancel:function(a){this.processTouches(a,this.cancelOut)},cancelOut:function(a){r.cancel(a),r.out(a),r.leave(a),this.cleanUpPointer(a)},cleanUpPointer:function(a){T["delete"](a.pointerId),this.removePrimaryPointer(a)},dedupSynthMouse:function(a){var b=P.lastTouches,c=a.changedTouches[0];if(this.isPrimaryTouch(c)){var d={x:c.clientX,y:c.clientY};b.push(d);var e=function(a,b){var c=a.indexOf(b);c>-1&&a.splice(c,1)}.bind(null,b,d);setTimeout(e,U)}}};X||(N=new A(Y.elementAdded,Y.elementRemoved,Y.elementChanged,Y));var Z,$,_=Y,aa=r.pointermap,ba=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,ca={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(a){r.listen(a,this.events)},unregister:function(a){r.unlisten(a,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(a){var b=a;return ba&&(b=r.cloneEvent(a),b.pointerType=this.POINTER_TYPES[a.pointerType]),b},cleanup:function(a){aa["delete"](a)},MSPointerDown:function(a){aa.set(a.pointerId,a);var b=this.prepareEvent(a);r.down(b)},MSPointerMove:function(a){var b=this.prepareEvent(a);r.move(b)},MSPointerUp:function(a){var b=this.prepareEvent(a);r.up(b),this.cleanup(a.pointerId)},MSPointerOut:function(a){var b=this.prepareEvent(a);r.leaveOut(b)},MSPointerOver:function(a){var b=this.prepareEvent(a);r.enterOver(b)},MSPointerCancel:function(a){var b=this.prepareEvent(a);r.cancel(b),this.cleanup(a.pointerId)},MSLostPointerCapture:function(a){var b=r.makeEvent("lostpointercapture",a);r.dispatchEvent(b)},MSGotPointerCapture:function(a){var b=r.makeEvent("gotpointercapture",a);r.dispatchEvent(b)}},da=ca,ea=window.navigator;ea.msPointerEnabled?(Z=function(a){i(a),this.msSetPointerCapture(a)},$=function(a){i(a),this.msReleasePointerCapture(a)}):(Z=function(a){i(a),r.setCapture(a,this)},$=function(a){i(a),r.releaseCapture(a,this)}),g(),h(),j();var fa={dispatcher:r,Installer:A,PointerEvent:D,PointerMap:m,targetFinding:s};return fa}),function(a,b){"function"==typeof define&&define.amd?define(["jquery","handlebars","node_modules/arraysweeper/index.js"],b):"object"==typeof exports?module.exports=b(jQuery,Handlebars,Arraysweeper):b(jQuery,Handlebars,Arraysweeper)}(this,function(a,b,c){return a.arraysweeper=function(b,c,d,e){return this.element=a(b),this.height=c,this.width=d,this.count=e,this.refresh(!1),this._bindEvents(),this},a.fn.arraysweeper=function(b,c,d){return this.data("arraysweeper",new a.arraysweeper(this,b,c,d)),this},a.extend(a.arraysweeper.prototype,{refresh:function(a){if(a!==!1){var b=this.toolbar.getValues();this.width=b.width,this.height=b.height,this.count=b.count}this.board=new c(this.height,this.width,this.count),this.element.html(this.templates.game({})),this.boardElement=this.element.find(".as-gameboard"),this.screen=this.element.find(".as-screen"),this.toolbar.init(this.element,this.height,this.width,this.count),this.renderBoard(),this.setHeight()},toolbar:{getValues:function(){return{width:this.width.val(),height:this.height.val(),count:this.count.val()}},init:function(a,b,c,d){this.element=a,this.width=a.find(".as-width-input"),this.height=a.find(".as-height-input"),this.count=a.find(".as-count-input"),this.remaining=this.element.find(".remaining-val"),this.setValues(b,c,d)},setValues:function(a,b,c){this.remaining.html(c),this.width.val(b),this.height.val(a),this.count.val(c)}},renderBoard:function(){this.boardElement.html(this.templates.board(this.board.getBoard()))},setHeight:function(){this.styleSheet&&this.styleSheet.remove(),this.styleSheet=a("<style>").appendTo(this.element),this.styleSheet.html(".as-game-space { height: "+this.element.find(".as-game-space").eq(0).width()+"px; }")},_on:function(a,b,c){var d=this;this.element.on(a,b,function(){d.handlers[c].apply(d,arguments)})},flagTime:500,handlers:{reveal:function(b){if(!a(b.target).hasClass("flag")){var c=b.target.getAttribute("data-as-location").split(","),d=this.board.reveal(Number(c[0]),Number(c[1]));"Game Over!"===d?this.screen.addClass("as-failure"):"You Win!"===d&&this.screen.addClass("as-success"),this.renderBoard(),this.toolbar.remaining.html(this.board.count.mines-this.board.count.flags)}},flag:function(a){if(!(3!==a.which&&(new Date).getTime()-this.pointerTime<this.flagTime)){a.preventDefault();var b=a.target.getAttribute("data-as-location").split(",");this.board.flag(parseInt(b[0],10),parseInt(b[1],10),!this.board.flag(parseInt(b[0],10),parseInt(b[1],10))),this.renderBoard()}},recordPointer:function(){this.pointerTime=(new Date).getTime()},prevent:function(a){a.preventDefault()},refresh:function(){console.log("refresh"),this.refresh()},settings:function(){this.toolbar.element.find(".as-settings-panel").toggleClass("as-settings-panel-hidden")},help:function(){this.toolbar.element.find(".as-help-panel").toggleClass("as-help-panel-hidden")}},_bindEvents:function(){var b=this;this._on("click",".as-reset","refresh"),this._on("click",".as-settings","settings"),this._on("click",".as-help","help"),this._on("click",".as-game-space:not( .revealed )","reveal"),this._on("pointerup",".as-game-space:not( .revealed )","flag"),this._on("touchstart pointerdown",".as-game-space:not( .revealed )","recordPointer"),this._on("contextmenu",".as-game-space:not( .revealed )","prevent"),a(window).on("resize",function(){b.setHeight.apply(b,arguments)})}}),a.fn.arraysweeper}),this.$=this.$||{},this.$.arraysweeper=this.$.arraysweeper||{},this.$.arraysweeper.prototype=this.$.arraysweeper.prototype||{},this.$.arraysweeper.prototype.templates=this.$.arraysweeper.prototype.templates||{},Handlebars.registerPartial("help",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="row as-help-panel as-help-panel-hidden">\n <h3 class="as-help-title">Help and Instructions</h3>\n <ul class="as-help-list">\n <li><p>Click on a space to reveal it</p></li>\n <li><p>Right Click or Hold Down on a space for more then .5 seconds to flag or unflag a space</p></li>\n <li><p>The number on a space indicates the number of mines which it touches</p></li>\n <li><p>If any space you reveal touchs a space which has a count of 0 it will also be revealed</p></li>\n <li><p>Click Reset / ⟳ at any time to reset the game</p></li>\n <li><p>Click settings / ⚙ to toggle the board settings panel</p></li>\n <li><p>Click reset after adjust settings to make them take effect</p></li>\n </ul>\n</div>'},useData:!0})),Handlebars.registerPartial("settings",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="row as-settings-panel as-settings-panel-hidden">\n <div class="col-xs-4">\n <label for="as-mine-count">Mine Count: </label>\n <input type="number" id="as-mine-count" class="as-count-input">\n </div>\n <div class="col-xs-4">\n <label for="as-board-width">Board Width: </label>\n <input type="number" id="as-mine-width" class="as-width-input">\n </div>\n <div class="col-xs-4">\n <label for="as-board-height">Board Height: </label>\n <input type="number" id="as-mine-height" class="as-height-input">\n </div>\n</div>'},useData:!0})),Handlebars.registerPartial("toolbar",Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){return'<div class="as-toolbar row">\n <div class="col-xs-8 as-remaining">\n Remaining: <span class="remaining-val"></span>\n </div>\n <div class="col-xs as-reset" title="reset">\n ⟳\n </div>\n <div class="col-xs as-settings" title="settings">\n ⚙\n </div>\n <div class="col-xs as-help" title="help">\n ?\n </div>\n</div>'},useData:!0})),this.$.arraysweeper.prototype.templates.board=Handlebars.template({1:function(a,b,c,d,e,f){var g;return' <div class="row">\n'+(null!=(g=b.each.call(a,a,{name:"each",hash:{},fn:this.program(2,d,0,e,f),inverse:this.noop,data:d}))?g:"")+" </div>\n"},2:function(a,b,c,d,e,f){var g,h,i=this.escapeExpression,j=b.helperMissing,k="function";return' <div toush-action="auto" tabindex="-1" data-as-location="'+i(this.lambda(this.data(d,1)&&this.data(d,1).index,a))+","+i((h=null!=(h=b.index||d&&d.index)?h:j,typeof h===k?h.call(a,{name:"index",hash:{},data:d}):h))+'" class="as-game-space '+i((h=null!=(h=b.state||(null!=a?a.state:a))?h:j,typeof h===k?h.call(a,{name:"state",hash:{},data:d}):h))+' col-xs">\n <div class="as-content">\n'+(null!=(g=b["if"].call(a,null!=a?a.bomb:a,{name:"if",hash:{},fn:this.program(3,d,0,e,f),inverse:this.program(5,d,0,e,f),data:d}))?g:"")+" </div>\n </div>\n"},3:function(a,b,c,d){return" 💣\n"},5:function(a,b,c,d){var e;return" "+this.escapeExpression((e=null!=(e=b.count||(null!=a?a.count:a))?e:b.helperMissing,"function"==typeof e?e.call(a,{name:"count",hash:{},data:d}):e))+"\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d,e,f){var g;return null!=(g=b.each.call(a,a,{name:"each",hash:{},fn:this.program(1,d,0,e,f),inverse:this.noop,data:d}))?g:""},useData:!0,useDepths:!0}),this.$.arraysweeper.prototype.templates.game=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,c,d){var e;return'<div class="as-mine">\n <div class="as-toolbar-wrap">\n'+(null!=(e=this.invokePartial(c.toolbar,a,{name:"toolbar",data:d,indent:" ",helpers:b,partials:c}))?e:"")+(null!=(e=this.invokePartial(c.settings,a,{name:"settings",data:d,indent:" ",helpers:b,partials:c}))?e:"")+(null!=(e=this.invokePartial(c.help,a,{name:"help",data:d,indent:" ",helpers:b,partials:c}))?e:"")+' </div>\n <div class="as-board-wrap">\n <div class="as-gameboard">\n\n </div>\n <div class="as-screen">\n\n </div>\n </div>\n</div>'},usePartial:!0,useData:!0}); |
@@ -57,3 +57,3 @@ this["$"] = this["$"] || {}; | ||
+ ((stack1 = this.invokePartial(partials.help,depth0,{"name":"help","data":data,"indent":"\t\t","helpers":helpers,"partials":partials})) != null ? stack1 : "") | ||
+ " </div>\n <div class=\"board-wrap\">\n <div class=\"as-gameboard\">\n\n </div>\n <div class=\"as-screen\">\n\n </div>\n </div>\n</div>"; | ||
+ " </div>\n <div class=\"as-board-wrap\">\n <div class=\"as-gameboard\">\n\n </div>\n <div class=\"as-screen\">\n\n </div>\n </div>\n</div>"; | ||
},"usePartial":true,"useData":true}); |
{ | ||
"name": "arrayswpeeper-gui", | ||
"description": "A GUI implementation of the arraysweeper module ", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Alex Schmitz", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1019843