diff --git a/Winwheel.js b/Winwheel.js index 520c07d..912faeb 100644 --- a/Winwheel.js +++ b/Winwheel.js @@ -1929,22 +1929,23 @@ Winwheel.prototype.getRandomForSegment = function(segmentNumber) { let stopAngle = 0; - if (segmentNumber) { - if (typeof this.segments[segmentNumber] !== 'undefined') { - let startAngle = this.segments[segmentNumber].startAngle; - let endAngle = this.segments[segmentNumber].endAngle; - let range = (endAngle - startAngle) - 2; - - if (range > 0) { - stopAngle = (startAngle + 1 + Math.floor((Math.random() * range))); - } else { - console.log('Segment size is too small to safely get random angle inside it'); - } + if (!segmentNumber) { + console.log('Segment number not specified, use 0 as a fallback value'); + segmentNumber = 0; + } + + if (typeof this.segments[segmentNumber] !== 'undefined') { + let startAngle = this.segments[segmentNumber].startAngle; + let endAngle = this.segments[segmentNumber].endAngle; + let range = (endAngle - startAngle) - 2; + + if (range > 0) { + stopAngle = (startAngle + 1 + Math.floor((Math.random() * range))); } else { - console.log('Segment ' + segmentNumber + ' undefined'); + console.log('Segment size is too small to safely get random angle inside it'); } } else { - console.log('Segment number not specified'); + console.log('Segment ' + segmentNumber + ' undefined'); } return stopAngle; diff --git a/Winwheel.min.js b/Winwheel.min.js index 6db3016..c940828 100644 --- a/Winwheel.min.js +++ b/Winwheel.min.js @@ -1,54 +1 @@ -function Winwheel(a,c){defaultOptions={canvasId:"canvas",centerX:null,centerY:null,outerRadius:null,innerRadius:0,numSegments:1,drawMode:"code",rotationAngle:0,textFontFamily:"Arial",textFontSize:20,textFontWeight:"bold",textOrientation:"horizontal",textAlignment:"center",textDirection:"normal",textMargin:null,textFillStyle:"black",textStrokeStyle:null,textLineWidth:1,fillStyle:"silver",strokeStyle:"black",lineWidth:1,clearTheCanvas:!0,imageOverlay:!1,drawText:!0,pointerAngle:0,wheelImage:null,imageDirection:"N", -responsive:!1,scaleFactor:1};for(var b in defaultOptions)this[b]=null!=a&&"undefined"!==typeof a[b]?a[b]:defaultOptions[b];if(null!=a)for(var d in a)"undefined"===typeof this[d]&&(this[d]=a[d]);this.canvasId?(this.canvas=document.getElementById(this.canvasId))?(null==this.centerX&&(this.centerX=this.canvas.width/2),null==this.centerY&&(this.centerY=this.canvas.height/2),null==this.outerRadius&&(this.outerRadius=this.canvas.widthc;d--)this.segments[d]=this.segments[d-1];this.segments[c]=b;b=c}else this.segments[this.numSegments]=b,b=this.numSegments;this.updateSegmentSizes();return this.segments[b]}; -Winwheel.prototype.setCanvasId=function(a){if(a){if(this.canvasId=a,this.canvas=document.getElementById(this.canvasId))this.ctx=this.canvas.getContext("2d")}else this.canvas=this.ctx=this.canvasId=null};Winwheel.prototype.deleteSegment=function(a){if(1d){var n=b.x-d;d="R"}else n=d-b.x,d="L";if(b.y>e){var r=b.y-e;e="B"}else r=e-b.y,e="T";var f=180*Math.atan(r/n)/Math.PI;b=0;n=Math.sqrt(r*r+n*n);"T"==e&&"R"==d?b=Math.round(90-f):"B"==e&&"R"==d?b=Math.round(f+90):"B"==e&&"L"==d?b=Math.round(90-f+180):"T"==e&&"L"== -d&&(b=Math.round(f+270));0!=this.rotationAngle&&(d=this.getRotationPosition(),b-=d,0>b&&(b=360-Math.abs(b)));d=null;for(e=1;e<=this.numSegments;e++)if(b>=this.segments[e].startAngle&&b<=this.segments[e].endAngle&&n>=h&&n<=t){d=e;break}return d};Winwheel.prototype.getIndicatedSegment=function(){var a=this.getIndicatedSegmentNumber();return this.segments[a]}; -Winwheel.prototype.getIndicatedSegmentNumber=function(){var a=0,c=this.getRotationPosition();c=Math.floor(this.pointerAngle-c);0>c&&(c=360-Math.abs(c));for(var b=1;b=this.segments[b].startAngle&&c<=this.segments[b].endAngle){a=b;break}return a}; -Winwheel.prototype.getCurrentPinNumber=function(){var a=0;if(this.pins){var c=this.getRotationPosition();c=Math.floor(this.pointerAngle-c);0>c&&(c=360-Math.abs(c));for(var b=360/this.pins.number,d=0,e=0;e=d&&c<=d+b){a=e;break}d+=b}"clockwise"==this.animation.direction&&(a++,a>this.pins.number&&(a=0))}return a};Winwheel.prototype.getRotationPosition=function(){var a=this.rotationAngle;0<=a?360a&&(a-=360*Math.ceil(a/360)),a=360+a);return a}; -Winwheel.prototype.startAnimation=function(){if(this.animation){this.computeAnimation();winwheelToDrawDuringAnimation=this;var a=Array(null);a[this.animation.propertyName]=this.animation.propertyValue;a.yoyo=this.animation.yoyo;a.repeat=this.animation.repeat;a.ease=this.animation.easing;a.onUpdate=winwheelAnimationLoop;a.onComplete=winwheelStopAnimation;this.tween=TweenMax.to(this,this.animation.duration,a)}}; -Winwheel.prototype.stopAnimation=function(a){winwheelToDrawDuringAnimation&&(winwheelToDrawDuringAnimation.tween&&winwheelToDrawDuringAnimation.tween.kill(),winwheelStopAnimation(a));winwheelToDrawDuringAnimation=this};Winwheel.prototype.pauseAnimation=function(){this.tween&&this.tween.pause()};Winwheel.prototype.resumeAnimation=function(){this.tween&&this.tween.play()}; -Winwheel.prototype.computeAnimation=function(){this.animation&&("spinOngoing"==this.animation.type?(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=-1),null==this.animation.easing&&(this.animation.easing="Linear.easeNone"),null==this.animation.yoyo&&(this.animation.yoyo=!1),this.animation.propertyValue=360*this.animation.spins,"anti-clockwise"==this.animation.direction&&(this.animation.propertyValue= -0-this.animation.propertyValue)):"spinToStop"==this.animation.type?(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=0),null==this.animation.easing&&(this.animation.easing="Power3.easeOut"),this.animation._stopAngle=null==this.animation.stopAngle?Math.floor(359*Math.random()):360-this.animation.stopAngle+this.pointerAngle,null==this.animation.yoyo&&(this.animation.yoyo=!1),this.animation.propertyValue= -360*this.animation.spins,"anti-clockwise"==this.animation.direction?(this.animation.propertyValue=0-this.animation.propertyValue,this.animation.propertyValue-=360-this.animation._stopAngle):this.animation.propertyValue+=this.animation._stopAngle):"spinAndBack"==this.animation.type&&(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=1),null==this.animation.easing&&(this.animation.easing="Power2.easeInOut"), -null==this.animation.yoyo&&(this.animation.yoyo=!0),this.animation._stopAngle=null==this.animation.stopAngle?0:360-this.animation.stopAngle,this.animation.propertyValue=360*this.animation.spins,"anti-clockwise"==this.animation.direction?(this.animation.propertyValue=0-this.animation.propertyValue,this.animation.propertyValue-=360-this.animation._stopAngle):this.animation.propertyValue+=this.animation._stopAngle))}; -Winwheel.prototype.getRandomForSegment=function(a){var c=0;if(a)if("undefined"!==typeof this.segments[a]){var b=this.segments[a].startAngle;a=this.segments[a].endAngle-b-2;0=a&&(c=a/100*360);return c} -function winwheelAnimationLoop(){if(winwheelToDrawDuringAnimation){0!=winwheelToDrawDuringAnimation.animation.clearTheCanvas&&winwheelToDrawDuringAnimation.ctx.clearRect(0,0,winwheelToDrawDuringAnimation.canvas.width,winwheelToDrawDuringAnimation.canvas.height);var a=winwheelToDrawDuringAnimation.animation.callbackBefore,c=winwheelToDrawDuringAnimation.animation.callbackAfter;null!=a&&("function"===typeof a?a():eval(a));winwheelToDrawDuringAnimation.draw(!1);null!=c&&("function"===typeof c?c():eval(c)); -winwheelToDrawDuringAnimation.animation.callbackSound&&winwheelTriggerSound()}} -function winwheelTriggerSound(){0==winwheelToDrawDuringAnimation.hasOwnProperty("_lastSoundTriggerNumber")&&(winwheelToDrawDuringAnimation._lastSoundTriggerNumber=0);var a=winwheelToDrawDuringAnimation.animation.callbackSound;var c="pin"==winwheelToDrawDuringAnimation.animation.soundTrigger?winwheelToDrawDuringAnimation.getCurrentPinNumber():winwheelToDrawDuringAnimation.getIndicatedSegmentNumber();c!=winwheelToDrawDuringAnimation._lastSoundTriggerNumber&&("function"===typeof a?a():eval(a),winwheelToDrawDuringAnimation._lastSoundTriggerNumber= -c)}var winwheelToDrawDuringAnimation=null;function winwheelStopAnimation(a){0!=a&&(a=winwheelToDrawDuringAnimation.animation.callbackFinished,null!=a&&("function"===typeof a?a(winwheelToDrawDuringAnimation.getIndicatedSegment()):eval(a)))}var winhweelAlreadyDrawn=!1; -function winwheelLoadedImage(){if(0==winhweelAlreadyDrawn){for(var a=0,c=1;c<=winwheelToDrawDuringAnimation.numSegments;c++)null!=winwheelToDrawDuringAnimation.segments[c].imgData&&winwheelToDrawDuringAnimation.segments[c].imgData.height&&a++;a==winwheelToDrawDuringAnimation.numSegments&&(winhweelAlreadyDrawn=!0,winwheelToDrawDuringAnimation.draw())}} -function winwheelResize(){var a=40;"undefined"!==typeof winwheelToDrawDuringAnimation._responsiveMargin&&(a=winwheelToDrawDuringAnimation._responsiveMargin);var c=window.innerWidth-a,b=winwheelToDrawDuringAnimation._responsiveMinWidth;a=winwheelToDrawDuringAnimation._responsiveMinHeight;cwinwheelToDrawDuringAnimation._originalCanvasWidth&&(c=winwheelToDrawDuringAnimation._originalCanvasWidth);c/=winwheelToDrawDuringAnimation._originalCanvasWidth;winwheelToDrawDuringAnimation.canvas.width= -winwheelToDrawDuringAnimation._originalCanvasWidth*c;winwheelToDrawDuringAnimation._responsiveScaleHeight&&(b=winwheelToDrawDuringAnimation._originalCanvasHeight*c,bwinwheelToDrawDuringAnimation._originalCanvasHeight&&(b=winwheelToDrawDuringAnimation._originalCanvasHeight),winwheelToDrawDuringAnimation.canvas.height=b);winwheelToDrawDuringAnimation.scaleFactor=c;winwheelToDrawDuringAnimation.draw()}; +function Winwheel(t,e){defaultOptions={canvasId:"canvas",centerX:null,centerY:null,outerRadius:null,innerRadius:0,numSegments:1,drawMode:"code",rotationAngle:0,textFontFamily:"Arial",textFontSize:20,textFontWeight:"bold",textOrientation:"horizontal",textAlignment:"center",textDirection:"normal",textMargin:null,textFillStyle:"black",textStrokeStyle:null,textLineWidth:1,fillStyle:"silver",strokeStyle:"black",lineWidth:1,clearTheCanvas:!0,imageOverlay:!1,drawText:!0,pointerAngle:0,wheelImage:null,imageDirection:"N",responsive:!1,scaleFactor:1};for(let e in defaultOptions)null!=t&&void 0!==t[e]?this[e]=t[e]:this[e]=defaultOptions[e];if(null!=t)for(let e in t)void 0===this[e]&&(this[e]=t[e]);this.canvasId?(this.canvas=document.getElementById(this.canvasId),this.canvas?(null==this.centerX&&(this.centerX=this.canvas.width/2),null==this.centerY&&(this.centerY=this.canvas.height/2),null==this.outerRadius&&(this.canvas.width0&&t<=100){e=360*(t/100)}return e}function winwheelAnimationLoop(){if(winwheelToDrawDuringAnimation){0!=winwheelToDrawDuringAnimation.animation.clearTheCanvas&&winwheelToDrawDuringAnimation.ctx.clearRect(0,0,winwheelToDrawDuringAnimation.canvas.width,winwheelToDrawDuringAnimation.canvas.height);let callbackBefore=winwheelToDrawDuringAnimation.animation.callbackBefore,callbackAfter=winwheelToDrawDuringAnimation.animation.callbackAfter;null!=callbackBefore&&("function"==typeof callbackBefore?callbackBefore():eval(callbackBefore)),winwheelToDrawDuringAnimation.draw(!1),null!=callbackAfter&&("function"==typeof callbackAfter?callbackAfter():eval(callbackAfter)),winwheelToDrawDuringAnimation.animation.callbackSound&&winwheelTriggerSound()}}function winwheelTriggerSound(){0==winwheelToDrawDuringAnimation.hasOwnProperty("_lastSoundTriggerNumber")&&(winwheelToDrawDuringAnimation._lastSoundTriggerNumber=0);let callbackSound=winwheelToDrawDuringAnimation.animation.callbackSound,currentTriggerNumber=0;currentTriggerNumber="pin"==winwheelToDrawDuringAnimation.animation.soundTrigger?winwheelToDrawDuringAnimation.getCurrentPinNumber():winwheelToDrawDuringAnimation.getIndicatedSegmentNumber(),currentTriggerNumber!=winwheelToDrawDuringAnimation._lastSoundTriggerNumber&&("function"==typeof callbackSound?callbackSound():eval(callbackSound),winwheelToDrawDuringAnimation._lastSoundTriggerNumber=currentTriggerNumber)}Winwheel.prototype.updateSegmentSizes=function(){if(this.segments){let t=0,e=0;for(let i=1;i<=this.numSegments;i++)null!==this.segments[i].size&&(t+=this.segments[i].size,e++);let i=360-t,n=0;i>0&&(n=i/(this.numSegments-e));let s=0;for(let t=1;t<=this.numSegments;t++)this.segments[t].startAngle=s,this.segments[t].size?s+=this.segments[t].size:s+=n,this.segments[t].endAngle=s}},Winwheel.prototype.clearCanvas=function(){this.ctx&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)},Winwheel.prototype.draw=function(t){this.ctx&&(void 0!==t?1==t&&this.clearCanvas():this.clearCanvas(),"image"==this.drawMode?(this.drawWheelImage(),1==this.drawText&&this.drawSegmentText(),1==this.imageOverlay&&this.drawSegments()):"segmentImage"==this.drawMode?(this.drawSegmentImages(),1==this.drawText&&this.drawSegmentText(),1==this.imageOverlay&&this.drawSegments()):(this.drawSegments(),1==this.drawText&&this.drawSegmentText()),void 0!==this.pins&&1==this.pins.visible&&this.drawPins(),1==this.pointerGuide.display&&this.drawPointerGuide())},Winwheel.prototype.drawPins=function(){if(this.pins&&this.pins.number){let t=this.centerX*this.scaleFactor,e=this.centerY*this.scaleFactor,i=this.outerRadius*this.scaleFactor,n=this.pins.outerRadius,s=this.pins.margin;this.pins.responsive&&(n=this.pins.outerRadius*this.scaleFactor,s=this.pins.margin*this.scaleFactor);let a=360/this.pins.number;for(let l=1;l<=this.pins.number;l++)this.ctx.save(),this.ctx.strokeStyle=this.pins.strokeStyle,this.ctx.lineWidth=this.pins.lineWidth,this.ctx.fillStyle=this.pins.fillStyle,this.ctx.translate(t,e),this.ctx.rotate(this.degToRad(l*a+this.rotationAngle)),this.ctx.translate(-t,-e),this.ctx.beginPath(),this.ctx.arc(t,e-i+n+s,n,0,2*Math.PI),this.pins.fillStyle&&this.ctx.fill(),this.pins.strokeStyle&&this.ctx.stroke(),this.ctx.restore()}},Winwheel.prototype.drawPointerGuide=function(){if(this.ctx){let t=this.centerX*this.scaleFactor,e=this.centerY*this.scaleFactor,i=this.outerRadius*this.scaleFactor;this.ctx.save(),this.ctx.translate(t,e),this.ctx.rotate(this.degToRad(this.pointerAngle)),this.ctx.translate(-t,-e),this.ctx.strokeStyle=this.pointerGuide.strokeStyle,this.ctx.lineWidth=this.pointerGuide.lineWidth,this.ctx.beginPath(),this.ctx.moveTo(t,e),this.ctx.lineTo(t,-i/4),this.ctx.stroke(),this.ctx.restore()}},Winwheel.prototype.drawWheelImage=function(){if(null!=this.wheelImage){let t=this.centerX*this.scaleFactor,e=this.centerY*this.scaleFactor,i=this.wheelImage.width*this.scaleFactor,n=this.wheelImage.height*this.scaleFactor,s=t-i/2,a=e-n/2;this.ctx.save(),this.ctx.translate(t,e),this.ctx.rotate(this.degToRad(this.rotationAngle)),this.ctx.translate(-t,-e),this.ctx.drawImage(this.wheelImage,s,a,i,n),this.ctx.restore()}},Winwheel.prototype.drawSegmentImages=function(){if(this.ctx){let t=this.centerX*this.scaleFactor,e=this.centerY*this.scaleFactor;if(this.segments)for(let i=1;i<=this.numSegments;i++){let n=this.segments[i];if(n.imgData.height){let i=0,s=0,a=0,l="",o=n.imgData.width*this.scaleFactor,h=n.imgData.height*this.scaleFactor;"S"==(l=null!==n.imageDirection?n.imageDirection:this.imageDirection)?(i=t-o/2,s=e,a=n.startAngle+180+(n.endAngle-n.startAngle)/2):"E"==l?(i=t,s=e-h/2,a=n.startAngle+270+(n.endAngle-n.startAngle)/2):"W"==l?(i=t-o,s=e-h/2,a=n.startAngle+90+(n.endAngle-n.startAngle)/2):(i=t-o/2,s=e-h,a=n.startAngle+(n.endAngle-n.startAngle)/2),this.ctx.save(),this.ctx.translate(t,e),this.ctx.rotate(this.degToRad(this.rotationAngle+a)),this.ctx.translate(-t,-e),this.ctx.drawImage(n.imgData,i,s,o,h),this.ctx.restore()}else console.log("Segment "+i+" imgData is not loaded")}}},Winwheel.prototype.drawSegments=function(){if(this.ctx&&this.segments){let t=this.centerX*this.scaleFactor,e=this.centerY*this.scaleFactor,i=this.innerRadius*this.scaleFactor,n=this.outerRadius*this.scaleFactor;for(let s=1;s<=this.numSegments;s++){let a,l,o,h=this.segments[s];if(a=null!==h.fillStyle?h.fillStyle:this.fillStyle,this.ctx.fillStyle=a,l=null!==h.lineWidth?h.lineWidth:this.lineWidth,this.ctx.lineWidth=l,o=null!==h.strokeStyle?h.strokeStyle:this.strokeStyle,this.ctx.strokeStyle=o,o||a){if(this.ctx.beginPath(),this.innerRadius){let n=Math.cos(this.degToRad(h.startAngle+this.rotationAngle-90))*(i-l/2),s=Math.sin(this.degToRad(h.startAngle+this.rotationAngle-90))*(i-l/2);this.ctx.moveTo(t+n,e+s)}else this.ctx.moveTo(t,e);this.ctx.arc(t,e,n,this.degToRad(h.startAngle+this.rotationAngle-90),this.degToRad(h.endAngle+this.rotationAngle-90),!1),this.innerRadius?this.ctx.arc(t,e,i,this.degToRad(h.endAngle+this.rotationAngle-90),this.degToRad(h.startAngle+this.rotationAngle-90),!0):this.ctx.lineTo(t,e),a&&this.ctx.fill(),o&&this.ctx.stroke()}}}},Winwheel.prototype.drawSegmentText=function(){if(this.ctx){let t,e,i,n,s,a,l,o,h,r,c=this.centerX*this.scaleFactor,g=this.centerY*this.scaleFactor,m=this.outerRadius*this.scaleFactor,u=this.innerRadius*this.scaleFactor;for(let d=1;d<=this.numSegments;d++){this.ctx.save();let w=this.segments[d];if(w.text){t=null!==w.textFontFamily?w.textFontFamily:this.textFontFamily,e=null!==w.textFontSize?w.textFontSize:this.textFontSize,i=null!==w.textFontWeight?w.textFontWeight:this.textFontWeight,n=null!==w.textOrientation?w.textOrientation:this.textOrientation,s=null!==w.textAlignment?w.textAlignment:this.textAlignment,a=null!==w.textDirection?w.textDirection:this.textDirection,l=null!==w.textMargin?w.textMargin:this.textMargin,o=null!==w.textFillStyle?w.textFillStyle:this.textFillStyle,h=null!==w.textStrokeStyle?w.textStrokeStyle:this.textStrokeStyle,r=null!==w.textLineWidth?w.textLineWidth:this.textLineWidth,e*=this.scaleFactor,l*=this.scaleFactor;let d="";null!=i&&(d+=i+" "),null!=e&&(d+=e+"px "),null!=t&&(d+=t),this.ctx.font=d,this.ctx.fillStyle=o,this.ctx.strokeStyle=h,this.ctx.lineWidth=r;let x=w.text.split("\n"),p=0-e*(x.length/2)+e/2;"curved"!=n||"inner"!=s&&"outer"!=s||(p=0);for(let t=0;t=0;e--){let i=x[t].charAt(e);o&&this.ctx.fillText(i,c+p,n),h&&this.ctx.strokeText(i,c+p,n),n-=a}else if("inner"==s)for(let e=0;e1&&(e=a*(x[t].length-1)/2);let i=g+u+(m-u)/2+e+l;for(let e=x[t].length-1;e>=0;e--){let n=x[t].charAt(e);o&&this.ctx.fillText(n,c+p,i),h&&this.ctx.strokeText(n,c+p,i),i-=a}}this.ctx.restore()}else if("curved"==n){let i=0;"inner"==s?(i=u+l,this.ctx.textBaseline="top"):"outer"==s?(i=m-l,this.ctx.textBaseline="bottom",i-=e*(x.length-1)):"center"==s&&(i=u+l+(m-u)/2,this.ctx.textBaseline="middle");let n=0,a=0;if(x[t].length>1){this.ctx.textAlign="left",n=e/10*4;let s=(n*=100/i)*x[t].length;a=w.startAngle+((w.endAngle-w.startAngle)/2-s/2)}else a=w.startAngle+(w.endAngle-w.startAngle)/2,this.ctx.textAlign="center";a+=this.rotationAngle,a-=180;for(let e=x[t].length;e>=0;e--){this.ctx.save();let s=x[t].charAt(e);this.ctx.translate(c,g),this.ctx.rotate(this.degToRad(a)),this.ctx.translate(-c,-g),h&&this.ctx.strokeText(s,c,g+i+p),o&&this.ctx.fillText(s,c,g+i+p),a+=n,this.ctx.restore()}}}else if("horizontal"==n){this.ctx.textAlign="inner"==s?"left":"outer"==s?"right":"center",this.ctx.textBaseline="middle";let e=this.degToRad(w.endAngle-(w.endAngle-w.startAngle)/2+this.rotationAngle-90);this.ctx.save(),this.ctx.translate(c,g),this.ctx.rotate(e),this.ctx.translate(-c,-g),"inner"==s?(o&&this.ctx.fillText(x[t],c+u+l,g+p),h&&this.ctx.strokeText(x[t],c+u+l,g+p)):"outer"==s?(o&&this.ctx.fillText(x[t],c+m-l,g+p),h&&this.ctx.strokeText(x[t],c+m-l,g+p)):(o&&this.ctx.fillText(x[t],c+u+(m-u)/2+l,g+p),h&&this.ctx.strokeText(x[t],c+u+(m-u)/2+l,g+p)),this.ctx.restore()}else if("vertical"==n){this.ctx.textAlign="center",this.ctx.textBaseline="inner"==s?"bottom":"outer"==s?"top":"middle";let i=w.endAngle-(w.endAngle-w.startAngle)/2;i+=this.rotationAngle,this.ctx.save(),this.ctx.translate(c,g),this.ctx.rotate(this.degToRad(i)),this.ctx.translate(-c,-g);let n=0;"outer"==s?n=g-m+l:"inner"==s&&(n=g-u-l);let a=e-e/9;if("outer"==s)for(let e=0;e=0;e--){let i=x[t].charAt(e);o&&this.ctx.fillText(i,c+p,n),h&&this.ctx.strokeText(i,c+p,n),n-=a}else if("center"==s){let e=0;x[t].length>1&&(e=a*(x[t].length-1)/2);let i=g-u-(m-u)/2-e-l;for(let e=0;e1){this.ctx.textAlign="left",n=e/10*4;let s=(n*=100/i)*x[t].length;a=w.startAngle+((w.endAngle-w.startAngle)/2-s/2)}else a=w.startAngle+(w.endAngle-w.startAngle)/2,this.ctx.textAlign="center";a+=this.rotationAngle;for(let e=0;ee;t--)this.segments[t]=this.segments[t-1];this.segments[e]=n,i=e}else this.segments[this.numSegments]=n,i=this.numSegments;return this.updateSegmentSizes(),this.segments[i]},Winwheel.prototype.setCanvasId=function(t){t?(this.canvasId=t,this.canvas=document.getElementById(this.canvasId),this.canvas&&(this.ctx=this.canvas.getContext("2d"))):(this.canvasId=null,this.ctx=null,this.canvas=null)},Winwheel.prototype.deleteSegment=function(t){if(this.numSegments>1){if(void 0!==t)for(let e=t;eh?(s=o.x-h,n="R"):(s=h-o.x,n="L"),o.y>r?(a=o.y-r,i="B"):(a=r-o.y,i="T");let m=a/s,u=180*Math.atan(m)/Math.PI,d=0;if(l=Math.sqrt(a*a+s*s),"T"==i&&"R"==n?d=Math.round(90-u):"B"==i&&"R"==n?d=Math.round(u+90):"B"==i&&"L"==n?d=Math.round(90-u+180):"T"==i&&"L"==n&&(d=Math.round(u+270)),0!=this.rotationAngle){(d-=this.getRotationPosition())<0&&(d=360-Math.abs(d))}let w=null;for(let t=1;t<=this.numSegments;t++)if(d>=this.segments[t].startAngle&&d<=this.segments[t].endAngle&&l>=g&&l<=c){w=t;break}return w},Winwheel.prototype.getIndicatedSegment=function(){let t=this.getIndicatedSegmentNumber();return this.segments[t]},Winwheel.prototype.getIndicatedSegmentNumber=function(){let t=0,e=this.getRotationPosition(),i=Math.floor(this.pointerAngle-e);i<0&&(i=360-Math.abs(i));for(let e=1;e=this.segments[e].startAngle&&i<=this.segments[e].endAngle){t=e;break}return t},Winwheel.prototype.getCurrentPinNumber=function(){let t=0;if(this.pins){let e=this.getRotationPosition(),i=Math.floor(this.pointerAngle-e);i<0&&(i=360-Math.abs(i));let n=360/this.pins.number,s=0;for(let e=0;e=s&&i<=s+n){t=e;break}s+=n}"clockwise"==this.animation.direction&&++t>this.pins.number&&(t=0)}return t},Winwheel.prototype.getRotationPosition=function(){let t=this.rotationAngle;if(t>=0){if(t>360){t-=360*Math.floor(t/360)}}else{if(t<-360){t-=360*Math.ceil(t/360)}t=360+t}return t},Winwheel.prototype.startAnimation=function(){if(this.animation){this.computeAnimation(),winwheelToDrawDuringAnimation=this;let t=new Array(null);t[this.animation.propertyName]=this.animation.propertyValue,t.yoyo=this.animation.yoyo,t.repeat=this.animation.repeat,t.ease=this.animation.easing,t.onUpdate=winwheelAnimationLoop,t.onComplete=winwheelStopAnimation,this.tween=TweenMax.to(this,this.animation.duration,t)}},Winwheel.prototype.stopAnimation=function(t){winwheelToDrawDuringAnimation&&(winwheelToDrawDuringAnimation.tween&&winwheelToDrawDuringAnimation.tween.kill(),winwheelStopAnimation(t)),winwheelToDrawDuringAnimation=this},Winwheel.prototype.pauseAnimation=function(){this.tween&&this.tween.pause()},Winwheel.prototype.resumeAnimation=function(){this.tween&&this.tween.play()},Winwheel.prototype.computeAnimation=function(){this.animation&&("spinOngoing"==this.animation.type?(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=-1),null==this.animation.easing&&(this.animation.easing="Linear.easeNone"),null==this.animation.yoyo&&(this.animation.yoyo=!1),this.animation.propertyValue=360*this.animation.spins,"anti-clockwise"==this.animation.direction&&(this.animation.propertyValue=0-this.animation.propertyValue)):"spinToStop"==this.animation.type?(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=0),null==this.animation.easing&&(this.animation.easing="Power3.easeOut"),null==this.animation.stopAngle?this.animation._stopAngle=Math.floor(359*Math.random()):this.animation._stopAngle=360-this.animation.stopAngle+this.pointerAngle,null==this.animation.yoyo&&(this.animation.yoyo=!1),this.animation.propertyValue=360*this.animation.spins,"anti-clockwise"==this.animation.direction?(this.animation.propertyValue=0-this.animation.propertyValue,this.animation.propertyValue-=360-this.animation._stopAngle):this.animation.propertyValue+=this.animation._stopAngle):"spinAndBack"==this.animation.type?(this.animation.propertyName="rotationAngle",null==this.animation.spins&&(this.animation.spins=5),null==this.animation.repeat&&(this.animation.repeat=1),null==this.animation.easing&&(this.animation.easing="Power2.easeInOut"),null==this.animation.yoyo&&(this.animation.yoyo=!0),null==this.animation.stopAngle?this.animation._stopAngle=0:this.animation._stopAngle=360-this.animation.stopAngle,this.animation.propertyValue=360*this.animation.spins,"anti-clockwise"==this.animation.direction?(this.animation.propertyValue=0-this.animation.propertyValue,this.animation.propertyValue-=360-this.animation._stopAngle):this.animation.propertyValue+=this.animation._stopAngle):this.animation.type)},Winwheel.prototype.getRandomForSegment=function(t){let e=0;if(t||(console.log("Segment number not specified, use 0 as a fallback value"),t=0),void 0!==this.segments[t]){let i=this.segments[t].startAngle,n=this.segments[t].endAngle-i-2;n>0?e=i+1+Math.floor(Math.random()*n):console.log("Segment size is too small to safely get random angle inside it")}else console.log("Segment "+t+" undefined");return e},Segment.prototype.changeImage=function(t,e){this.image=t,this.imgData=null,e&&(this.imageDirection=e),winhweelAlreadyDrawn=!1,this.imgData=new Image,this.imgData.onload=winwheelLoadedImage,this.imgData.src=this.image};let winwheelToDrawDuringAnimation=null;function winwheelStopAnimation(canCallback){if(0!=canCallback){let callback=winwheelToDrawDuringAnimation.animation.callbackFinished;null!=callback&&("function"==typeof callback?callback(winwheelToDrawDuringAnimation.getIndicatedSegment()):eval(callback))}}let winhweelAlreadyDrawn=!1;function winwheelLoadedImage(){if(0==winhweelAlreadyDrawn){let t=0;for(let e=1;e<=winwheelToDrawDuringAnimation.numSegments;e++)null!=winwheelToDrawDuringAnimation.segments[e].imgData&&winwheelToDrawDuringAnimation.segments[e].imgData.height&&t++;t==winwheelToDrawDuringAnimation.numSegments&&(winhweelAlreadyDrawn=!0,winwheelToDrawDuringAnimation.draw())}}function winwheelResize(){let t=40;void 0!==winwheelToDrawDuringAnimation._responsiveMargin&&(t=winwheelToDrawDuringAnimation._responsiveMargin);let e=window.innerWidth-t,i=winwheelToDrawDuringAnimation._responsiveMinWidth,n=winwheelToDrawDuringAnimation._responsiveMinHeight;ewinwheelToDrawDuringAnimation._originalCanvasWidth&&(e=winwheelToDrawDuringAnimation._originalCanvasWidth);let s=e/winwheelToDrawDuringAnimation._originalCanvasWidth;if(winwheelToDrawDuringAnimation.canvas.width=winwheelToDrawDuringAnimation._originalCanvasWidth*s,winwheelToDrawDuringAnimation._responsiveScaleHeight){let t=winwheelToDrawDuringAnimation._originalCanvasHeight*s;twinwheelToDrawDuringAnimation._originalCanvasHeight&&(t=winwheelToDrawDuringAnimation._originalCanvasHeight),winwheelToDrawDuringAnimation.canvas.height=t}winwheelToDrawDuringAnimation.scaleFactor=s,winwheelToDrawDuringAnimation.draw()} \ No newline at end of file