diff --git a/dist/vue-luck-draw.common.js b/dist/vue-luck-draw.common.js index 818d2c7..59c11cc 100644 --- a/dist/vue-luck-draw.common.js +++ b/dist/vue-luck-draw.common.js @@ -504,7 +504,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(e,i)};function e(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i=a(180).toFixed(8)){var s=(n+i)/2;return r?(f(t,e,i,s,r),f(t,e,s,n,r)):(f(t,e,s,n,r),f(t,e,i,s,r)),!1}r||(i=(o=[n,i])[0],n=o[1]);var l=h(i,e),u=l[0],g=l[1],d=h(n,e),p=d[0],m=d[1],v=c(u,g),w=v[0],y=v[1],b=c(p,m),z=b[0],I=b[1],S=(I-y)/(w-z),x=(z*y-w*I)/(z-w);isNaN(S)&&(Math.abs(u)===+e.toFixed(8)&&(S=u),Math.abs(p)===+e.toFixed(8)&&(S=p)),w===1/0||w===-1/0?x=z*S+I:z!==1/0&&z!==-1/0||(x=w*S+y),t.lineTo(u,g),t.arcTo(S,x,p,m,e)},l=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.arcTo(e+n,i,e+n,i+o,o),t.lineTo(e+n,i+r-o),t.arcTo(e+n,i+r,e+n-o,i+r,o),t.lineTo(e+o,i+r),t.arcTo(e,i+r,e,i+r-o,o),t.lineTo(e,i+o),t.arcTo(e,i,e+o,i,o),t.closePath(),t.fill()},u=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},g=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},d=function(t){function s(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",wordWrap:!0,lengthLimit:"90%"},n.Radius=0,n.prizeRadius=0,n.prizeDeg=0,n.prizeRadian=0,n.rotateDeg=0,n.maxBtnRadius=0,n.startTime=0,n.endTime=0,n.stopDeg=0,n.endDeg=0,n.animationId=0,n.FPS=16.6,n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.buttons&&r.push.apply(r,n.buttons.map((function(t){return t.imgs}))),n.init(r),n}return e(s,t),s.prototype.initData=function(t){this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},s.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},s.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.prizeImgs[r]&&t.prizeImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("buttons",(function(e,i){var r=[];return i?e&&e.forEach((function(e,n){var o=[],s=i[n];s&&s.imgs?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var r=s.imgs[i];r&&t.btnImgs[n]&&t.btnImgs[n][i]?e.src!==r.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],r[n]=o})):r=e.map((function(t){return t.imgs})),t.init(n(new Array(t.prizes.length).fill(void 0),r))}))},s.prototype.init=function(t){var e=this,i=this.config,n=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),this.Radius=Math.min(i.width,i.height)/2,n.translate(this.Radius,this.Radius);var o=function(){e.draw(),e.draw(),i.canvasElement&&(i.canvasElement.onclick=function(t){var i;n.beginPath(),n.arc(0,0,e.maxBtnRadius,0,2*Math.PI,!1),n.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},s=0,a=0;r(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){a++,e.loadAndCacheImg(i,n,(function(){s++,a===s&&o.call(e)}))}))}))),a||o.call(this)},s.prototype.loadAndCacheImg=function(t,e,i){var n=this,r=td?f(t,e,d,p,!1):t.lineTo.apply(t,h((n+r)/2,o/2/Math.abs(Math.sin((n-r)/2)))),t.closePath(),t.fill()}(i,t.maxBtnRadius,t.prizeRadius,g-t.prizeRadian/2,g+t.prizeRadian/2,t.getLength(n.gutter),e.background||r.background||"rgba(0, 0, 0, 0)");var p=Math.cos(g)*t.prizeRadius,m=Math.sin(g)*t.prizeRadius;i.translate(p,m),i.rotate(g+a(90)),e.imgs&&e.imgs.forEach((function(e,n){if(t.prizeImgs[u]){var r=t.prizeImgs[u][n];if(r){var o,s=t.computedWidthAndHeight(r,e,t.prizeRadian*t.prizeRadius,d),a=s[0],h=s[1],c=[t.getOffsetX(a),t.getHeight(e.top,d)],f=c[0],l=c[1];"WEB"===t.config.flag?o=r:0===t.config.flag.indexOf("UNI-")&&(o=r.path),i.drawImage(o,f,l,a,h)}}})),e.fonts&&e.fonts.forEach((function(e){var s=e.fontColor||r.fontColor,a=e.fontWeight||r.fontWeight,h=t.getLength(e.fontSize||r.fontSize),f=e.fontStyle||r.fontStyle;i.fillStyle=s,i.font=a+" "+h+"px "+f;var u=[],g=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:r.wordWrap){g=o(g);for(var p="",m=0;mt.getWidth(e.lengthLimit||r.lengthLimit,w)&&(u.push(p.slice(0,-1)),p=g[m])}p&&u.push(p),u.length||u.push(g)}else u=g.split("\n");u.filter((function(t){return!!t})).forEach((function(t,n){i.fillText(t,c(t),l(e,d,n))}))})),i.rotate(a(360)-g-a(90)),i.translate(-p,-m)})),i.restore(),this.buttons.forEach((function(e,n){var o=t.getHeight(e.radius);t.maxBtnRadius=Math.max(t.maxBtnRadius,o),i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.arc(0,0,o,0,2*Math.PI,!1),i.fill(),e.pointer&&(i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.moveTo(-o,0),i.lineTo(o,0),i.lineTo(0,2*-o),i.closePath(),i.fill()),e.imgs&&e.imgs.forEach((function(r,s){if(t.btnImgs[n]){var a=t.btnImgs[n][s];if(a){var h,c=t.computedWidthAndHeight(a,r,2*t.getHeight(e.radius),2*t.getHeight(e.radius)),f=c[0],l=c[1],u=[t.getOffsetX(f),t.getHeight(r.top,o)],g=u[0],d=u[1];"WEB"===t.config.flag?h=a:0===t.config.flag.indexOf("UNI-")&&(h=a.path),i.drawImage(h,g,d,f,l)}}})),e.fonts&&e.fonts.forEach((function(e){var n=e.fontColor||r.fontColor,s=e.fontWeight||r.fontWeight,a=t.getLength(e.fontSize||r.fontSize),h=e.fontStyle||r.fontStyle;i.fillStyle=n,i.font=s+" "+a+"px "+h,String(e.text).split("\n").forEach((function(t,n){i.fillText(t,c(t),l(e,o,n))}))}))})),0===this.config.flag.indexOf("UNI-")&&i.draw()},s.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},s.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},s.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.prizeFlag,r=e.prizeDeg,o=e.rotateDeg,s=e._defaultConfig,a=Date.now()-this.startTime;if(a>=s.accelerationTime&&void 0!==n){this.FPS=a/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var c=360*h-n*r-o-s.offsetDegree;if(g(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+u(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},s.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopDeg,a=e.endDeg,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>=h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.rotateDeg=g(c,s,a,h.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},s.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),r(t,"number")?t:r(t,"string")?this.changeUnits(t,e):0},s.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),r(t,"number")?t:r(t,"string")?this.changeUnits(t,e):0},s.prototype.getOffsetX=function(t){return-t/2},s}(s),p=function(t){function s(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},n.activeStyle={},n._activeStyle={background:"#ffce98",shadow:"",fontStyle:"",fontWeight:"",fontSize:"",lineHeight:"",fontColor:""},n.cellWidth=0,n.cellHeight=0,n.startTime=0,n.endTime=0,n.currIndex=0,n.stopIndex=0,n.endIndex=0,n.demo=!1,n.timer=0,n.animationId=0,n.FPS=16.6,n.cells=[],n.cellImgs=[],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.button&&(r[n.cols*n.rows-1]=n.button.imgs),n.init(r),n}return e(s,t),s.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"button",t.button),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"activeStyle",t.activeStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},s.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},s.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.cellImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("button",(function(e,i){var n=[],r=t.cols*t.rows-1;if(i&&i.imgs){if(e.imgs){var o=[];e.imgs.forEach((function(e,n){if(!i.imgs)return o[n]=e;var s=i.imgs[n];s&&t.cellImgs[r][n]?e.src!==s.src&&(o[n]=e):o[n]=e})),n[r]=o}}else n[r]=e.imgs;return t.init(n)}))},s.prototype.init=function(t){var e=this,i=this,n=i.config,o=i.ctx,s=i.button;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas();var a=function(){e.draw(),e.demo&&e.walk(),s&&n.canvasElement&&(n.canvasElement.onclick=function(t){var i,n=e.getGeometricProperty([s.x,s.y,s.col||1,s.row||1]),r=n[0],a=n[1],h=n[2],c=n[3];o.beginPath(),o.rect(r,a,h,c),o.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},h=0,c=0;r(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){c++,e.loadAndCacheImg(i,n,(function(){h++,c===h&&a.call(e)}))}))}))),c||a.call(this)},s.prototype.loadAndCacheImg=function(t,e,i){var n=this,r=this.cells[t];if(r&&r.imgs){var o=r.imgs[e];this.cellImgs[t]||(this.cellImgs[t]=[]);var s=0,a=1;if("WEB"===this.config.flag){var h=new Image;this.cellImgs[t][e]={defaultImg:h},h.src=o.src,h.onload=function(){++s===a&&i.call(n)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.src,success:function(r){n.cellImgs[t][e]={defaultImg:r},++s===a&&i.call(n)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.src)}});if(o.hasOwnProperty("activeSrc"))if(a++,"WEB"===this.config.flag){var c=new Image;this.cellImgs[t][e].activeImg=c,c.src=o.activeSrc,c.onload=function(){++s===a&&i.call(n)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.activeSrc,success:function(r){n.cellImgs[t][e].activeImg=r,++s===a&&i.call(n)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.activeSrc)}})}},s.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},s.prototype.draw=function(){var t=this,e=this,i=e.config,s=e.ctx,a=e._defaultConfig,h=e._defaultStyle,c=e._activeStyle;s.clearRect(0,0,i.width,i.height),this.cells=n(this.prizes),this.button&&(this.cells[this.cols*this.rows-1]=this.button),this.cells.forEach((function(t){t.col=t.col||1,t.row=t.row||1})),this.prizeArea=this.blocks.reduce((function(e,i){var n=e.x,o=e.y,a=e.w,h=e.h,c=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,o=0,s=0;switch(e.length){case 1:i=n=o=s=e[0];break;case 2:i=n=e[0],o=s=e[1];break;case 3:i=e[0],o=s=e[1],n=e[2];break;default:i=e[0],n=e[1],o=e[2],s=e[3]}var a={paddingTop:i,paddingBottom:n,paddingLeft:o,paddingRight:s};for(var h in a)a[h]=t.hasOwnProperty(h)&&r(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):a[h];return[i,n,o,s]}(i).map((function(t){return~~t})),f=c[0],u=c[1],g=c[2],d=c[3],p=i.borderRadius?t.getLength(i.borderRadius):0;return l(s,n,o,a,h,p,t.handleBackground(n,o,a,h,i.background)),{x:n+g,y:o+f,w:a-g-d,h:h-f-u}}),{x:0,y:0,w:i.width,h:i.height}),this.cellWidth=(this.prizeArea.w-a.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-a.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(e,i){var n=t.getGeometricProperty([e.x,e.y,e.col,e.row]),r=n[0],a=n[1],f=n[2],u=n[3],g=i===t.currIndex%t.prizes.length>>0,d=(g?c.shadow:e.shadow||h.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===d.length&&(s.shadowColor=d[3],s.shadowOffsetX=d[0],s.shadowOffsetY=d[1],s.shadowBlur=d[2],d[0]>0?f-=d[0]:(f+=d[0],r-=d[0]),d[1]>0?u-=d[1]:(u+=d[1],a-=d[1])),l(s,r,a,f,u,t.getLength(e.borderRadius?e.borderRadius:h.borderRadius),t.handleBackground(r,a,f,u,e.background,g)),s.shadowColor="rgba(255, 255, 255, 0)",s.shadowOffsetX=0,s.shadowOffsetY=0,s.shadowBlur=0,e.imgs&&e.imgs.forEach((function(n,o){if(!t.cellImgs[i])return!1;var h=t.cellImgs[i][o];if(!h)return!1;var c,f=g&&h.activeImg||h.defaultImg,l=t.computedWidthAndHeight(f,n,e),u=l[0],d=l[1],p=[r+t.getOffsetX(u,e.col),a+t.getHeight(n.top,e.row)],m=p[0],v=p[1];"WEB"===t.config.flag?c=f:0===t.config.flag.indexOf("UNI-")&&(c=f.path),s.drawImage(c,m,v,u,d)})),e.fonts&&e.fonts.forEach((function(i){var n=g&&c.fontStyle?c.fontStyle:i.fontStyle||h.fontStyle,f=g&&c.fontWeight?c.fontWeight:i.fontWeight||h.fontWeight,l=g&&c.fontSize?t.getLength(c.fontSize):t.getLength(i.fontSize||h.fontSize),u=g&&c.lineHeight?c.lineHeight:i.lineHeight||h.lineHeight||i.fontSize||h.fontSize;s.font=f+" "+l+"px "+n,s.fillStyle=g&&c.fontColor?c.fontColor:i.fontColor||h.fontColor;var d=[],p=String(i.text);if(i.hasOwnProperty("wordWrap")?i.wordWrap:h.wordWrap){p=o(p);for(var m="",v=0;vt.getWidth(i.lengthLimit||h.lengthLimit,e.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,o){s.fillText(n,r+t.getOffsetX(s.measureText(n).width,e.col),a+t.getHeight(i.top,e.row)+(o+1)*t.getLength(u))}))}))})),s.draw&&s.draw()},s.prototype.handleBackground=function(t,e,i,n,r,o){void 0===o&&(o=!1);var s=this,a=s.ctx,h=s._defaultStyle,c=s._activeStyle;return(r=o?c.background:r||h.background).includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var s=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),a=s.shift(),h=[0,0,0,0];if(a.includes("deg")){var c=function(t){return Math.tan(t/180*Math.PI)};(a=a.slice(0,-3)%360)>=0&&a<45?h=[e,i+r,e+n,i+r-n*c(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*c(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*c(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*c(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*c(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*c(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*c(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*c(a-315)])}else a.includes("top")?h=[e,i+r,e,i]:a.includes("bottom")?h=[e,i,e,i+r]:a.includes("left")?h=[e+n,i,e,i]:a.includes("right")&&(h=[e,i,e+n,i]);var f=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return s.reduce((function(t,e,i){var n=e.split(" ");return 1===n.length?t.addColorStop(i,n[0]):2===n.length&&t.addColorStop.apply(t,n),t}),f)}(a,t,e,i,n,r)),r},s.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},s.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},s.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.currIndex,r=e.prizes,o=e.prizeFlag,s=e.startTime,a=e._defaultConfig,h=Date.now()-s;if(h>=a.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var c=0;++c;){var f=r.length*c+o-(n>>0);if(g(this.FPS,this.stopIndex,f,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=f;break}}return this.slowDown()}this.currIndex=(n+u(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},s.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopIndex,a=e.endIndex,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.currIndex=g(c,s,a,h.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},s.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},s.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=t[3],o=this.cellWidth,s=this.cellHeight,a=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+a)*e,this.prizeArea.y+(s+a)*i];return n&&r&&h.push(o*n+a*(n-1),s*r+a*(r-1)),h},s.prototype.getWidth=function(t,e){return void 0===e&&(e=1),r(t,"number")?t:r(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},s.prototype.getHeight=function(t,e){return void 0===e&&(e=1),r(t,"number")?t:r(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},s.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},s}(s);exports.LuckyGrid=p,exports.LuckyWheel=d; +var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(e,i)};function e(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=c(180).toFixed(8)){var s=(n+i)/2;return r?(u(t,e,i,s,r),u(t,e,s,n,r)):(u(t,e,s,n,r),u(t,e,i,s,r)),!1}r||(i=(o=[n,i])[0],n=o[1]);var a=l(i,e),h=a[0],d=a[1],g=l(n,e),p=g[0],m=g[1],v=f(h,d),y=v[0],w=v[1],b=f(p,m),I=b[0],z=b[1],x=(z-w)/(y-I),S=(I*w-y*z)/(I-y);isNaN(x)&&(Math.abs(h)===+e.toFixed(8)&&(x=h),Math.abs(p)===+e.toFixed(8)&&(x=p)),y===1/0||y===-1/0?S=I*x+z:I!==1/0&&I!==-1/0||(S=y*x+w),t.lineTo(h,d),t.arcTo(x,S,p,m,e)},d=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.arcTo(e+n,i,e+n,i+o,o),t.lineTo(e+n,i+r-o),t.arcTo(e+n,i+r,e+n-o,i+r,o),t.lineTo(e+o,i+r),t.arcTo(e,i+r,e,i+r-o,o),t.lineTo(e,i+o),t.arcTo(e,i,e+o,i,o),t.closePath(),t.fill()},g=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},p=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},m=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",wordWrap:!0,lengthLimit:"90%"},n.Radius=0,n.prizeRadius=0,n.prizeDeg=0,n.prizeRadian=0,n.rotateDeg=0,n.maxBtnRadius=0,n.startTime=0,n.endTime=0,n.stopDeg=0,n.endDeg=0,n.animationId=0,n.FPS=16.6,n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.buttons&&r.push.apply(r,n.buttons.map((function(t){return t.imgs}))),n.init(r),n}return e(h,t),h.prototype.initData=function(t){this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},h.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.prizeImgs[r]&&t.prizeImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("buttons",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s&&s.imgs?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.btnImgs[r]&&t.btnImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(o(new Array(t.prizes.length).fill(void 0),n))}))},h.prototype.init=function(t){var e=this,i=this.config,n=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),this.Radius=Math.min(i.width,i.height)/2,"WEB"===i.flag&&n.translate(this.Radius,this.Radius);var r=function(){e.draw(),e.draw(),i.canvasElement&&(i.canvasElement.onclick=function(t){var i;n.beginPath(),n.arc(0,0,e.maxBtnRadius,0,2*Math.PI,!1),n.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},o=0,a=0;s(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){a++,e.loadAndCacheImg(i,n,(function(){o++,a===o&&r.call(e)}))}))}))),a||r.call(this)},h.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var n,o,s,a,h,c,l;return r(this,(function(r){switch(r.label){case 0:return n=tg?u(t,e,g,p,!1):t.lineTo.apply(t,l((n+r)/2,o/2/Math.abs(Math.sin((n-r)/2)))),t.closePath(),t.fill()}(i,t.maxBtnRadius,t.prizeRadius,d-t.prizeRadian/2,d+t.prizeRadian/2,t.getLength(n.gutter),e.background||r.background||"rgba(0, 0, 0, 0)");var p=Math.cos(d)*t.prizeRadius,m=Math.sin(d)*t.prizeRadius;i.translate(p,m),i.rotate(d+c(90)),e.imgs&&e.imgs.forEach((function(e,n){if(t.prizeImgs[f]){var r=t.prizeImgs[f][n];if(r){var o,s=t.computedWidthAndHeight(r,e,t.prizeRadian*t.prizeRadius,g),a=s[0],h=s[1],c=[t.getOffsetX(a),t.getHeight(e.top,g)],l=c[0],u=c[1];"WEB"===t.config.flag?o=r:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(o=r.path),i.drawImage(o,l,u,a,h)}}})),e.fonts&&e.fonts.forEach((function(e){var o=e.fontColor||r.fontColor,c=e.fontWeight||r.fontWeight,l=t.getLength(e.fontSize||r.fontSize),f=e.fontStyle||r.fontStyle;i.fillStyle=o,i.font=c+" "+l+"px "+f;var u=[],d=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:r.wordWrap){d=a(d);for(var p="",m=0;mt.getWidth(e.lengthLimit||r.lengthLimit,y)&&(u.push(p.slice(0,-1)),p=d[m])}p&&u.push(p),u.length||u.push(d)}else u=d.split("\n");u.filter((function(t){return!!t})).forEach((function(t,n){i.fillText(t,s(t),h(e,g,n))}))})),i.rotate(c(360)-d-c(90)),i.translate(-p,-m)})),i.restore(),this.buttons.forEach((function(e,n){var o=t.getHeight(e.radius);t.maxBtnRadius=Math.max(t.maxBtnRadius,o),i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.arc(0,0,o,0,2*Math.PI,!1),i.fill(),e.pointer&&(i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.moveTo(-o,0),i.lineTo(o,0),i.lineTo(0,2*-o),i.closePath(),i.fill()),e.imgs&&e.imgs.forEach((function(r,s){if(t.btnImgs[n]){var a=t.btnImgs[n][s];if(a){var h,c=t.computedWidthAndHeight(a,r,2*t.getHeight(e.radius),2*t.getHeight(e.radius)),l=c[0],f=c[1],u=[t.getOffsetX(l),t.getHeight(r.top,o)],d=u[0],g=u[1];"WEB"===t.config.flag?h=a:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(h=a.path),i.drawImage(h,d,g,l,f)}}})),e.fonts&&e.fonts.forEach((function(e){var n=e.fontColor||r.fontColor,a=e.fontWeight||r.fontWeight,c=t.getLength(e.fontSize||r.fontSize),l=e.fontStyle||r.fontStyle;i.fillStyle=n,i.font=a+" "+c+"px "+l,String(e.text).split("\n").forEach((function(t,n){i.fillText(t,s(t),h(e,o,n))}))}))})),0===this.config.flag.indexOf("UNI-")&&i.draw()},h.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},h.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},h.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.prizeFlag,r=e.prizeDeg,o=e.rotateDeg,s=e._defaultConfig,a=Date.now()-this.startTime;if(a>=s.accelerationTime&&void 0!==n){this.FPS=a/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var c=360*h-n*r-o-s.offsetDegree;if(p(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+g(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},h.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopDeg,a=e.endDeg,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>=h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.rotateDeg=p(c,s,a,h.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},h.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},h.prototype.getOffsetX=function(t){return-t/2},h}(h),v=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},n.activeStyle={},n._activeStyle={background:"#ffce98",shadow:"",fontStyle:"",fontWeight:"",fontSize:"",lineHeight:"",fontColor:""},n.cellWidth=0,n.cellHeight=0,n.startTime=0,n.endTime=0,n.currIndex=0,n.stopIndex=0,n.endIndex=0,n.demo=!1,n.timer=0,n.animationId=0,n.FPS=16.6,n.cells=[],n.cellImgs=[],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.button&&(r[n.cols*n.rows-1]=n.button.imgs),n.init(r),n}return e(h,t),h.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"button",t.button),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"activeStyle",t.activeStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},h.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.cellImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("button",(function(e,i){var n=[],r=t.cols*t.rows-1;if(i&&i.imgs){if(e.imgs){var o=[];e.imgs.forEach((function(e,n){if(!i.imgs)return o[n]=e;var s=i.imgs[n];s&&t.cellImgs[r][n]?e.src!==s.src&&(o[n]=e):o[n]=e})),n[r]=o}}else n[r]=e.imgs;return t.init(n)}))},h.prototype.init=function(t){var e=this,i=this,n=i.config,r=i.ctx,o=i.button;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas();var a=function(){e.draw(),e.demo&&e.walk(),o&&n.canvasElement&&(n.canvasElement.onclick=function(t){var i,n=e.getGeometricProperty([o.x,o.y,o.col||1,o.row||1]),s=n[0],a=n[1],h=n[2],c=n[3];r.beginPath(),r.rect(s,a,h,c),r.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},h=0,c=0;s(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){c++,e.loadAndCacheImg(i,n,(function(){h++,c===h&&a.call(e)}))}))}))),c||a.call(this)},h.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var n,o,s,a,h,c;return r(this,(function(r){switch(r.label){case 0:return(n=this.cells[t])&&n.imgs?(o=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(o.src)]):[2];case 1:return s[a]=(c.defaultImg=r.sent(),c),o.hasOwnProperty("activeSrc")?[4,this.loadImg(o.activeSrc)]:[3,3];case 2:h=r.sent(),this.cellImgs[t][e].activeImg=h,r.label=3;case 3:return i.call(this),[2]}}))}))},h.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},h.prototype.draw=function(){var t=this,e=this,i=e.config,n=e.ctx,r=e._defaultConfig,h=e._defaultStyle,c=e._activeStyle;n.clearRect(0,0,i.width,i.height),this.cells=o(this.prizes),this.button&&(this.cells[this.cols*this.rows-1]=this.button),this.cells.forEach((function(t){t.col=t.col||1,t.row=t.row||1})),this.prizeArea=this.blocks.reduce((function(e,i){var r=e.x,o=e.y,a=e.w,h=e.h,c=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,r=0,o=0;switch(e.length){case 1:i=n=r=o=e[0];break;case 2:i=n=e[0],r=o=e[1];break;case 3:i=e[0],r=o=e[1],n=e[2];break;default:i=e[0],n=e[1],r=e[2],o=e[3]}var a={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o};for(var h in a)a[h]=t.hasOwnProperty(h)&&s(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):a[h];return[i,n,r,o]}(i).map((function(t){return~~t})),l=c[0],f=c[1],u=c[2],g=c[3],p=i.borderRadius?t.getLength(i.borderRadius):0;return d(n,r,o,a,h,p,t.handleBackground(r,o,a,h,i.background)),{x:r+u,y:o+l,w:a-u-g,h:h-l-f}}),{x:0,y:0,w:i.width,h:i.height}),this.cellWidth=(this.prizeArea.w-r.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-r.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(e,i){var r=t.getGeometricProperty([e.x,e.y,e.col,e.row]),o=r[0],s=r[1],l=r[2],f=r[3],u=i===t.currIndex%t.prizes.length>>0,g=(u?c.shadow:e.shadow||h.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(n.shadowColor=g[3],n.shadowOffsetX=g[0],n.shadowOffsetY=g[1],n.shadowBlur=g[2],g[0]>0?l-=g[0]:(l+=g[0],o-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],s-=g[1])),d(n,o,s,l,f,t.getLength(e.borderRadius?e.borderRadius:h.borderRadius),t.handleBackground(o,s,l,f,e.background,u)),n.shadowColor="rgba(255, 255, 255, 0)",n.shadowOffsetX=0,n.shadowOffsetY=0,n.shadowBlur=0,e.imgs&&e.imgs.forEach((function(r,a){if(!t.cellImgs[i])return!1;var h=t.cellImgs[i][a];if(!h)return!1;var c,l=u&&h.activeImg||h.defaultImg,f=t.computedWidthAndHeight(l,r,e),d=f[0],g=f[1],p=[o+t.getOffsetX(d,e.col),s+t.getHeight(r.top,e.row)],m=p[0],v=p[1];"WEB"===t.config.flag?c=l:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(c=l.path),n.drawImage(c,m,v,d,g)})),e.fonts&&e.fonts.forEach((function(i){var r=u&&c.fontStyle?c.fontStyle:i.fontStyle||h.fontStyle,l=u&&c.fontWeight?c.fontWeight:i.fontWeight||h.fontWeight,f=u&&c.fontSize?t.getLength(c.fontSize):t.getLength(i.fontSize||h.fontSize),d=u&&c.lineHeight?c.lineHeight:i.lineHeight||h.lineHeight||i.fontSize||h.fontSize;n.font=l+" "+f+"px "+r,n.fillStyle=u&&c.fontColor?c.fontColor:i.fontColor||h.fontColor;var g=[],p=String(i.text);if(i.hasOwnProperty("wordWrap")?i.wordWrap:h.wordWrap){p=a(p);for(var m="",v=0;vt.getWidth(i.lengthLimit||h.lengthLimit,e.col)&&(g.push(m.slice(0,-1)),m=p[v])}m&&g.push(m),g.length||g.push(p)}else g=p.split("\n");g.forEach((function(r,a){n.fillText(r,o+t.getOffsetX(n.measureText(r).width,e.col),s+t.getHeight(i.top,e.row)+(a+1)*t.getLength(d))}))}))})),n.draw&&n.draw()},h.prototype.handleBackground=function(t,e,i,n,r,o){void 0===o&&(o=!1);var s=this,a=s.ctx,h=s._defaultStyle,c=s._activeStyle;return(r=o?c.background:r||h.background).includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var s=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),a=s.shift(),h=[0,0,0,0];if(a.includes("deg")){var c=function(t){return Math.tan(t/180*Math.PI)};(a=a.slice(0,-3)%360)>=0&&a<45?h=[e,i+r,e+n,i+r-n*c(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*c(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*c(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*c(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*c(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*c(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*c(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*c(a-315)])}else a.includes("top")?h=[e,i+r,e,i]:a.includes("bottom")?h=[e,i,e,i+r]:a.includes("left")?h=[e+n,i,e,i]:a.includes("right")&&(h=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return s.reduce((function(t,e,i){var n=e.split(" ");return 1===n.length?t.addColorStop(i,n[0]):2===n.length&&t.addColorStop.apply(t,n),t}),l)}(a,t,e,i,n,r)),r},h.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},h.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},h.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.currIndex,r=e.prizes,o=e.prizeFlag,s=e.startTime,a=e._defaultConfig,h=Date.now()-s;if(h>=a.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var c=0;++c;){var l=r.length*c+o-(n>>0);if(p(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+g(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},h.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopIndex,a=e.endIndex,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.currIndex=p(c,s,a,h.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},h.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},h.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=t[3],o=this.cellWidth,s=this.cellHeight,a=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+a)*e,this.prizeArea.y+(s+a)*i];return n&&r&&h.push(o*n+a*(n-1),s*r+a*(r-1)),h},h.prototype.getWidth=function(t,e){return void 0===e&&(e=1),s(t,"number")?t:s(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=1),s(t,"number")?t:s(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},h.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},h}(h);exports.LuckyGrid=v,exports.LuckyWheel=m; /***/ }), diff --git a/dist/vue-luck-draw.umd.js b/dist/vue-luck-draw.umd.js index 3a54e11..d1e4f65 100644 --- a/dist/vue-luck-draw.umd.js +++ b/dist/vue-luck-draw.umd.js @@ -513,7 +513,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(e,i)};function e(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i=a(180).toFixed(8)){var s=(n+i)/2;return r?(f(t,e,i,s,r),f(t,e,s,n,r)):(f(t,e,s,n,r),f(t,e,i,s,r)),!1}r||(i=(o=[n,i])[0],n=o[1]);var l=h(i,e),u=l[0],g=l[1],d=h(n,e),p=d[0],m=d[1],v=c(u,g),w=v[0],y=v[1],b=c(p,m),z=b[0],I=b[1],S=(I-y)/(w-z),x=(z*y-w*I)/(z-w);isNaN(S)&&(Math.abs(u)===+e.toFixed(8)&&(S=u),Math.abs(p)===+e.toFixed(8)&&(S=p)),w===1/0||w===-1/0?x=z*S+I:z!==1/0&&z!==-1/0||(x=w*S+y),t.lineTo(u,g),t.arcTo(S,x,p,m,e)},l=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.arcTo(e+n,i,e+n,i+o,o),t.lineTo(e+n,i+r-o),t.arcTo(e+n,i+r,e+n-o,i+r,o),t.lineTo(e+o,i+r),t.arcTo(e,i+r,e,i+r-o,o),t.lineTo(e,i+o),t.arcTo(e,i,e+o,i,o),t.closePath(),t.fill()},u=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},g=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},d=function(t){function s(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",wordWrap:!0,lengthLimit:"90%"},n.Radius=0,n.prizeRadius=0,n.prizeDeg=0,n.prizeRadian=0,n.rotateDeg=0,n.maxBtnRadius=0,n.startTime=0,n.endTime=0,n.stopDeg=0,n.endDeg=0,n.animationId=0,n.FPS=16.6,n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.buttons&&r.push.apply(r,n.buttons.map((function(t){return t.imgs}))),n.init(r),n}return e(s,t),s.prototype.initData=function(t){this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},s.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},s.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.prizeImgs[r]&&t.prizeImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("buttons",(function(e,i){var r=[];return i?e&&e.forEach((function(e,n){var o=[],s=i[n];s&&s.imgs?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var r=s.imgs[i];r&&t.btnImgs[n]&&t.btnImgs[n][i]?e.src!==r.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],r[n]=o})):r=e.map((function(t){return t.imgs})),t.init(n(new Array(t.prizes.length).fill(void 0),r))}))},s.prototype.init=function(t){var e=this,i=this.config,n=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),this.Radius=Math.min(i.width,i.height)/2,n.translate(this.Radius,this.Radius);var o=function(){e.draw(),e.draw(),i.canvasElement&&(i.canvasElement.onclick=function(t){var i;n.beginPath(),n.arc(0,0,e.maxBtnRadius,0,2*Math.PI,!1),n.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},s=0,a=0;r(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){a++,e.loadAndCacheImg(i,n,(function(){s++,a===s&&o.call(e)}))}))}))),a||o.call(this)},s.prototype.loadAndCacheImg=function(t,e,i){var n=this,r=td?f(t,e,d,p,!1):t.lineTo.apply(t,h((n+r)/2,o/2/Math.abs(Math.sin((n-r)/2)))),t.closePath(),t.fill()}(i,t.maxBtnRadius,t.prizeRadius,g-t.prizeRadian/2,g+t.prizeRadian/2,t.getLength(n.gutter),e.background||r.background||"rgba(0, 0, 0, 0)");var p=Math.cos(g)*t.prizeRadius,m=Math.sin(g)*t.prizeRadius;i.translate(p,m),i.rotate(g+a(90)),e.imgs&&e.imgs.forEach((function(e,n){if(t.prizeImgs[u]){var r=t.prizeImgs[u][n];if(r){var o,s=t.computedWidthAndHeight(r,e,t.prizeRadian*t.prizeRadius,d),a=s[0],h=s[1],c=[t.getOffsetX(a),t.getHeight(e.top,d)],f=c[0],l=c[1];"WEB"===t.config.flag?o=r:0===t.config.flag.indexOf("UNI-")&&(o=r.path),i.drawImage(o,f,l,a,h)}}})),e.fonts&&e.fonts.forEach((function(e){var s=e.fontColor||r.fontColor,a=e.fontWeight||r.fontWeight,h=t.getLength(e.fontSize||r.fontSize),f=e.fontStyle||r.fontStyle;i.fillStyle=s,i.font=a+" "+h+"px "+f;var u=[],g=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:r.wordWrap){g=o(g);for(var p="",m=0;mt.getWidth(e.lengthLimit||r.lengthLimit,w)&&(u.push(p.slice(0,-1)),p=g[m])}p&&u.push(p),u.length||u.push(g)}else u=g.split("\n");u.filter((function(t){return!!t})).forEach((function(t,n){i.fillText(t,c(t),l(e,d,n))}))})),i.rotate(a(360)-g-a(90)),i.translate(-p,-m)})),i.restore(),this.buttons.forEach((function(e,n){var o=t.getHeight(e.radius);t.maxBtnRadius=Math.max(t.maxBtnRadius,o),i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.arc(0,0,o,0,2*Math.PI,!1),i.fill(),e.pointer&&(i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.moveTo(-o,0),i.lineTo(o,0),i.lineTo(0,2*-o),i.closePath(),i.fill()),e.imgs&&e.imgs.forEach((function(r,s){if(t.btnImgs[n]){var a=t.btnImgs[n][s];if(a){var h,c=t.computedWidthAndHeight(a,r,2*t.getHeight(e.radius),2*t.getHeight(e.radius)),f=c[0],l=c[1],u=[t.getOffsetX(f),t.getHeight(r.top,o)],g=u[0],d=u[1];"WEB"===t.config.flag?h=a:0===t.config.flag.indexOf("UNI-")&&(h=a.path),i.drawImage(h,g,d,f,l)}}})),e.fonts&&e.fonts.forEach((function(e){var n=e.fontColor||r.fontColor,s=e.fontWeight||r.fontWeight,a=t.getLength(e.fontSize||r.fontSize),h=e.fontStyle||r.fontStyle;i.fillStyle=n,i.font=s+" "+a+"px "+h,String(e.text).split("\n").forEach((function(t,n){i.fillText(t,c(t),l(e,o,n))}))}))})),0===this.config.flag.indexOf("UNI-")&&i.draw()},s.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},s.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},s.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.prizeFlag,r=e.prizeDeg,o=e.rotateDeg,s=e._defaultConfig,a=Date.now()-this.startTime;if(a>=s.accelerationTime&&void 0!==n){this.FPS=a/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var c=360*h-n*r-o-s.offsetDegree;if(g(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+u(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},s.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopDeg,a=e.endDeg,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>=h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.rotateDeg=g(c,s,a,h.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},s.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),r(t,"number")?t:r(t,"string")?this.changeUnits(t,e):0},s.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),r(t,"number")?t:r(t,"string")?this.changeUnits(t,e):0},s.prototype.getOffsetX=function(t){return-t/2},s}(s),p=function(t){function s(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},n.activeStyle={},n._activeStyle={background:"#ffce98",shadow:"",fontStyle:"",fontWeight:"",fontSize:"",lineHeight:"",fontColor:""},n.cellWidth=0,n.cellHeight=0,n.startTime=0,n.endTime=0,n.currIndex=0,n.stopIndex=0,n.endIndex=0,n.demo=!1,n.timer=0,n.animationId=0,n.FPS=16.6,n.cells=[],n.cellImgs=[],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.button&&(r[n.cols*n.rows-1]=n.button.imgs),n.init(r),n}return e(s,t),s.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"button",t.button),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"activeStyle",t.activeStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},s.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},s.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.cellImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("button",(function(e,i){var n=[],r=t.cols*t.rows-1;if(i&&i.imgs){if(e.imgs){var o=[];e.imgs.forEach((function(e,n){if(!i.imgs)return o[n]=e;var s=i.imgs[n];s&&t.cellImgs[r][n]?e.src!==s.src&&(o[n]=e):o[n]=e})),n[r]=o}}else n[r]=e.imgs;return t.init(n)}))},s.prototype.init=function(t){var e=this,i=this,n=i.config,o=i.ctx,s=i.button;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas();var a=function(){e.draw(),e.demo&&e.walk(),s&&n.canvasElement&&(n.canvasElement.onclick=function(t){var i,n=e.getGeometricProperty([s.x,s.y,s.col||1,s.row||1]),r=n[0],a=n[1],h=n[2],c=n[3];o.beginPath(),o.rect(r,a,h,c),o.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},h=0,c=0;r(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){c++,e.loadAndCacheImg(i,n,(function(){h++,c===h&&a.call(e)}))}))}))),c||a.call(this)},s.prototype.loadAndCacheImg=function(t,e,i){var n=this,r=this.cells[t];if(r&&r.imgs){var o=r.imgs[e];this.cellImgs[t]||(this.cellImgs[t]=[]);var s=0,a=1;if("WEB"===this.config.flag){var h=new Image;this.cellImgs[t][e]={defaultImg:h},h.src=o.src,h.onload=function(){++s===a&&i.call(n)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.src,success:function(r){n.cellImgs[t][e]={defaultImg:r},++s===a&&i.call(n)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.src)}});if(o.hasOwnProperty("activeSrc"))if(a++,"WEB"===this.config.flag){var c=new Image;this.cellImgs[t][e].activeImg=c,c.src=o.activeSrc,c.onload=function(){++s===a&&i.call(n)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.activeSrc,success:function(r){n.cellImgs[t][e].activeImg=r,++s===a&&i.call(n)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.activeSrc)}})}},s.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},s.prototype.draw=function(){var t=this,e=this,i=e.config,s=e.ctx,a=e._defaultConfig,h=e._defaultStyle,c=e._activeStyle;s.clearRect(0,0,i.width,i.height),this.cells=n(this.prizes),this.button&&(this.cells[this.cols*this.rows-1]=this.button),this.cells.forEach((function(t){t.col=t.col||1,t.row=t.row||1})),this.prizeArea=this.blocks.reduce((function(e,i){var n=e.x,o=e.y,a=e.w,h=e.h,c=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,o=0,s=0;switch(e.length){case 1:i=n=o=s=e[0];break;case 2:i=n=e[0],o=s=e[1];break;case 3:i=e[0],o=s=e[1],n=e[2];break;default:i=e[0],n=e[1],o=e[2],s=e[3]}var a={paddingTop:i,paddingBottom:n,paddingLeft:o,paddingRight:s};for(var h in a)a[h]=t.hasOwnProperty(h)&&r(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):a[h];return[i,n,o,s]}(i).map((function(t){return~~t})),f=c[0],u=c[1],g=c[2],d=c[3],p=i.borderRadius?t.getLength(i.borderRadius):0;return l(s,n,o,a,h,p,t.handleBackground(n,o,a,h,i.background)),{x:n+g,y:o+f,w:a-g-d,h:h-f-u}}),{x:0,y:0,w:i.width,h:i.height}),this.cellWidth=(this.prizeArea.w-a.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-a.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(e,i){var n=t.getGeometricProperty([e.x,e.y,e.col,e.row]),r=n[0],a=n[1],f=n[2],u=n[3],g=i===t.currIndex%t.prizes.length>>0,d=(g?c.shadow:e.shadow||h.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===d.length&&(s.shadowColor=d[3],s.shadowOffsetX=d[0],s.shadowOffsetY=d[1],s.shadowBlur=d[2],d[0]>0?f-=d[0]:(f+=d[0],r-=d[0]),d[1]>0?u-=d[1]:(u+=d[1],a-=d[1])),l(s,r,a,f,u,t.getLength(e.borderRadius?e.borderRadius:h.borderRadius),t.handleBackground(r,a,f,u,e.background,g)),s.shadowColor="rgba(255, 255, 255, 0)",s.shadowOffsetX=0,s.shadowOffsetY=0,s.shadowBlur=0,e.imgs&&e.imgs.forEach((function(n,o){if(!t.cellImgs[i])return!1;var h=t.cellImgs[i][o];if(!h)return!1;var c,f=g&&h.activeImg||h.defaultImg,l=t.computedWidthAndHeight(f,n,e),u=l[0],d=l[1],p=[r+t.getOffsetX(u,e.col),a+t.getHeight(n.top,e.row)],m=p[0],v=p[1];"WEB"===t.config.flag?c=f:0===t.config.flag.indexOf("UNI-")&&(c=f.path),s.drawImage(c,m,v,u,d)})),e.fonts&&e.fonts.forEach((function(i){var n=g&&c.fontStyle?c.fontStyle:i.fontStyle||h.fontStyle,f=g&&c.fontWeight?c.fontWeight:i.fontWeight||h.fontWeight,l=g&&c.fontSize?t.getLength(c.fontSize):t.getLength(i.fontSize||h.fontSize),u=g&&c.lineHeight?c.lineHeight:i.lineHeight||h.lineHeight||i.fontSize||h.fontSize;s.font=f+" "+l+"px "+n,s.fillStyle=g&&c.fontColor?c.fontColor:i.fontColor||h.fontColor;var d=[],p=String(i.text);if(i.hasOwnProperty("wordWrap")?i.wordWrap:h.wordWrap){p=o(p);for(var m="",v=0;vt.getWidth(i.lengthLimit||h.lengthLimit,e.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,o){s.fillText(n,r+t.getOffsetX(s.measureText(n).width,e.col),a+t.getHeight(i.top,e.row)+(o+1)*t.getLength(u))}))}))})),s.draw&&s.draw()},s.prototype.handleBackground=function(t,e,i,n,r,o){void 0===o&&(o=!1);var s=this,a=s.ctx,h=s._defaultStyle,c=s._activeStyle;return(r=o?c.background:r||h.background).includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var s=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),a=s.shift(),h=[0,0,0,0];if(a.includes("deg")){var c=function(t){return Math.tan(t/180*Math.PI)};(a=a.slice(0,-3)%360)>=0&&a<45?h=[e,i+r,e+n,i+r-n*c(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*c(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*c(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*c(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*c(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*c(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*c(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*c(a-315)])}else a.includes("top")?h=[e,i+r,e,i]:a.includes("bottom")?h=[e,i,e,i+r]:a.includes("left")?h=[e+n,i,e,i]:a.includes("right")&&(h=[e,i,e+n,i]);var f=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return s.reduce((function(t,e,i){var n=e.split(" ");return 1===n.length?t.addColorStop(i,n[0]):2===n.length&&t.addColorStop.apply(t,n),t}),f)}(a,t,e,i,n,r)),r},s.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},s.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},s.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.currIndex,r=e.prizes,o=e.prizeFlag,s=e.startTime,a=e._defaultConfig,h=Date.now()-s;if(h>=a.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var c=0;++c;){var f=r.length*c+o-(n>>0);if(g(this.FPS,this.stopIndex,f,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=f;break}}return this.slowDown()}this.currIndex=(n+u(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},s.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopIndex,a=e.endIndex,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.currIndex=g(c,s,a,h.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},s.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},s.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=t[3],o=this.cellWidth,s=this.cellHeight,a=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+a)*e,this.prizeArea.y+(s+a)*i];return n&&r&&h.push(o*n+a*(n-1),s*r+a*(r-1)),h},s.prototype.getWidth=function(t,e){return void 0===e&&(e=1),r(t,"number")?t:r(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},s.prototype.getHeight=function(t,e){return void 0===e&&(e=1),r(t,"number")?t:r(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},s.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},s}(s);exports.LuckyGrid=p,exports.LuckyWheel=d; +var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(e,i)};function e(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,i=1,n=arguments.length;i0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=c(180).toFixed(8)){var s=(n+i)/2;return r?(u(t,e,i,s,r),u(t,e,s,n,r)):(u(t,e,s,n,r),u(t,e,i,s,r)),!1}r||(i=(o=[n,i])[0],n=o[1]);var a=l(i,e),h=a[0],d=a[1],g=l(n,e),p=g[0],m=g[1],v=f(h,d),y=v[0],w=v[1],b=f(p,m),I=b[0],z=b[1],x=(z-w)/(y-I),S=(I*w-y*z)/(I-y);isNaN(x)&&(Math.abs(h)===+e.toFixed(8)&&(x=h),Math.abs(p)===+e.toFixed(8)&&(x=p)),y===1/0||y===-1/0?S=I*x+z:I!==1/0&&I!==-1/0||(S=y*x+w),t.lineTo(h,d),t.arcTo(x,S,p,m,e)},d=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.arcTo(e+n,i,e+n,i+o,o),t.lineTo(e+n,i+r-o),t.arcTo(e+n,i+r,e+n-o,i+r,o),t.lineTo(e+o,i+r),t.arcTo(e,i+r,e,i+r-o,o),t.lineTo(e,i+o),t.arcTo(e,i,e+o,i,o),t.closePath(),t.fill()},g=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},p=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},m=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",wordWrap:!0,lengthLimit:"90%"},n.Radius=0,n.prizeRadius=0,n.prizeDeg=0,n.prizeRadian=0,n.rotateDeg=0,n.maxBtnRadius=0,n.startTime=0,n.endTime=0,n.stopDeg=0,n.endDeg=0,n.animationId=0,n.FPS=16.6,n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.buttons&&r.push.apply(r,n.buttons.map((function(t){return t.imgs}))),n.init(r),n}return e(h,t),h.prototype.initData=function(t){this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},h.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.prizeImgs[r]&&t.prizeImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("buttons",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s&&s.imgs?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.btnImgs[r]&&t.btnImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(o(new Array(t.prizes.length).fill(void 0),n))}))},h.prototype.init=function(t){var e=this,i=this.config,n=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),this.Radius=Math.min(i.width,i.height)/2,"WEB"===i.flag&&n.translate(this.Radius,this.Radius);var r=function(){e.draw(),e.draw(),i.canvasElement&&(i.canvasElement.onclick=function(t){var i;n.beginPath(),n.arc(0,0,e.maxBtnRadius,0,2*Math.PI,!1),n.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},o=0,a=0;s(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){a++,e.loadAndCacheImg(i,n,(function(){o++,a===o&&r.call(e)}))}))}))),a||r.call(this)},h.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var n,o,s,a,h,c,l;return r(this,(function(r){switch(r.label){case 0:return n=tg?u(t,e,g,p,!1):t.lineTo.apply(t,l((n+r)/2,o/2/Math.abs(Math.sin((n-r)/2)))),t.closePath(),t.fill()}(i,t.maxBtnRadius,t.prizeRadius,d-t.prizeRadian/2,d+t.prizeRadian/2,t.getLength(n.gutter),e.background||r.background||"rgba(0, 0, 0, 0)");var p=Math.cos(d)*t.prizeRadius,m=Math.sin(d)*t.prizeRadius;i.translate(p,m),i.rotate(d+c(90)),e.imgs&&e.imgs.forEach((function(e,n){if(t.prizeImgs[f]){var r=t.prizeImgs[f][n];if(r){var o,s=t.computedWidthAndHeight(r,e,t.prizeRadian*t.prizeRadius,g),a=s[0],h=s[1],c=[t.getOffsetX(a),t.getHeight(e.top,g)],l=c[0],u=c[1];"WEB"===t.config.flag?o=r:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(o=r.path),i.drawImage(o,l,u,a,h)}}})),e.fonts&&e.fonts.forEach((function(e){var o=e.fontColor||r.fontColor,c=e.fontWeight||r.fontWeight,l=t.getLength(e.fontSize||r.fontSize),f=e.fontStyle||r.fontStyle;i.fillStyle=o,i.font=c+" "+l+"px "+f;var u=[],d=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:r.wordWrap){d=a(d);for(var p="",m=0;mt.getWidth(e.lengthLimit||r.lengthLimit,y)&&(u.push(p.slice(0,-1)),p=d[m])}p&&u.push(p),u.length||u.push(d)}else u=d.split("\n");u.filter((function(t){return!!t})).forEach((function(t,n){i.fillText(t,s(t),h(e,g,n))}))})),i.rotate(c(360)-d-c(90)),i.translate(-p,-m)})),i.restore(),this.buttons.forEach((function(e,n){var o=t.getHeight(e.radius);t.maxBtnRadius=Math.max(t.maxBtnRadius,o),i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.arc(0,0,o,0,2*Math.PI,!1),i.fill(),e.pointer&&(i.beginPath(),i.fillStyle=e.background||"rgba(0, 0, 0, 0)",i.moveTo(-o,0),i.lineTo(o,0),i.lineTo(0,2*-o),i.closePath(),i.fill()),e.imgs&&e.imgs.forEach((function(r,s){if(t.btnImgs[n]){var a=t.btnImgs[n][s];if(a){var h,c=t.computedWidthAndHeight(a,r,2*t.getHeight(e.radius),2*t.getHeight(e.radius)),l=c[0],f=c[1],u=[t.getOffsetX(l),t.getHeight(r.top,o)],d=u[0],g=u[1];"WEB"===t.config.flag?h=a:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(h=a.path),i.drawImage(h,d,g,l,f)}}})),e.fonts&&e.fonts.forEach((function(e){var n=e.fontColor||r.fontColor,a=e.fontWeight||r.fontWeight,c=t.getLength(e.fontSize||r.fontSize),l=e.fontStyle||r.fontStyle;i.fillStyle=n,i.font=a+" "+c+"px "+l,String(e.text).split("\n").forEach((function(t,n){i.fillText(t,s(t),h(e,o,n))}))}))})),0===this.config.flag.indexOf("UNI-")&&i.draw()},h.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},h.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},h.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.prizeFlag,r=e.prizeDeg,o=e.rotateDeg,s=e._defaultConfig,a=Date.now()-this.startTime;if(a>=s.accelerationTime&&void 0!==n){this.FPS=a/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var c=360*h-n*r-o-s.offsetDegree;if(p(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+g(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},h.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopDeg,a=e.endDeg,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>=h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.rotateDeg=p(c,s,a,h.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},h.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},h.prototype.getOffsetX=function(t){return-t/2},h}(h),v=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},n.activeStyle={},n._activeStyle={background:"#ffce98",shadow:"",fontStyle:"",fontWeight:"",fontSize:"",lineHeight:"",fontColor:""},n.cellWidth=0,n.cellHeight=0,n.startTime=0,n.endTime=0,n.currIndex=0,n.stopIndex=0,n.endIndex=0,n.demo=!1,n.timer=0,n.animationId=0,n.FPS=16.6,n.cells=[],n.cellImgs=[],n.initData(i),n.initComputed(),n.initWatch();var r=[[]];return n.prizes&&(r=n.prizes.map((function(t){return t.imgs}))),n.button&&(r[n.cols*n.rows-1]=n.button.imgs),n.init(r),n}return e(h,t),h.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"button",t.button),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"activeStyle",t.activeStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},h.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,i){var n=[];return i?e&&e.forEach((function(e,r){var o=[],s=i[r];s?e.imgs&&e.imgs.forEach((function(e,i){if(!s.imgs)return o[i]=e;var n=s.imgs[i];n&&t.cellImgs[r][i]?e.src!==n.src&&(o[i]=e):o[i]=e})):o=e.imgs||[],n[r]=o})):n=e.map((function(t){return t.imgs})),t.init(n)})),this.$watch("button",(function(e,i){var n=[],r=t.cols*t.rows-1;if(i&&i.imgs){if(e.imgs){var o=[];e.imgs.forEach((function(e,n){if(!i.imgs)return o[n]=e;var s=i.imgs[n];s&&t.cellImgs[r][n]?e.src!==s.src&&(o[n]=e):o[n]=e})),n[r]=o}}else n[r]=e.imgs;return t.init(n)}))},h.prototype.init=function(t){var e=this,i=this,n=i.config,r=i.ctx,o=i.button;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas();var a=function(){e.draw(),e.demo&&e.walk(),o&&n.canvasElement&&(n.canvasElement.onclick=function(t){var i,n=e.getGeometricProperty([o.x,o.y,o.col||1,o.row||1]),s=n[0],a=n[1],h=n[2],c=n[3];r.beginPath(),r.rect(s,a,h,c),r.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(i=e.startCallback)||void 0===i||i.call(e,t))})},h=0,c=0;s(t,"array")&&(this.draw(),t.forEach((function(t,i){if(!t)return!1;t.forEach((function(t,n){c++,e.loadAndCacheImg(i,n,(function(){h++,c===h&&a.call(e)}))}))}))),c||a.call(this)},h.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var n,o,s,a,h,c;return r(this,(function(r){switch(r.label){case 0:return(n=this.cells[t])&&n.imgs?(o=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(o.src)]):[2];case 1:return s[a]=(c.defaultImg=r.sent(),c),o.hasOwnProperty("activeSrc")?[4,this.loadImg(o.activeSrc)]:[3,3];case 2:h=r.sent(),this.cellImgs[t][e].activeImg=h,r.label=3;case 3:return i.call(this),[2]}}))}))},h.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},h.prototype.draw=function(){var t=this,e=this,i=e.config,n=e.ctx,r=e._defaultConfig,h=e._defaultStyle,c=e._activeStyle;n.clearRect(0,0,i.width,i.height),this.cells=o(this.prizes),this.button&&(this.cells[this.cols*this.rows-1]=this.button),this.cells.forEach((function(t){t.col=t.col||1,t.row=t.row||1})),this.prizeArea=this.blocks.reduce((function(e,i){var r=e.x,o=e.y,a=e.w,h=e.h,c=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,r=0,o=0;switch(e.length){case 1:i=n=r=o=e[0];break;case 2:i=n=e[0],r=o=e[1];break;case 3:i=e[0],r=o=e[1],n=e[2];break;default:i=e[0],n=e[1],r=e[2],o=e[3]}var a={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o};for(var h in a)a[h]=t.hasOwnProperty(h)&&s(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):a[h];return[i,n,r,o]}(i).map((function(t){return~~t})),l=c[0],f=c[1],u=c[2],g=c[3],p=i.borderRadius?t.getLength(i.borderRadius):0;return d(n,r,o,a,h,p,t.handleBackground(r,o,a,h,i.background)),{x:r+u,y:o+l,w:a-u-g,h:h-l-f}}),{x:0,y:0,w:i.width,h:i.height}),this.cellWidth=(this.prizeArea.w-r.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-r.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(e,i){var r=t.getGeometricProperty([e.x,e.y,e.col,e.row]),o=r[0],s=r[1],l=r[2],f=r[3],u=i===t.currIndex%t.prizes.length>>0,g=(u?c.shadow:e.shadow||h.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(n.shadowColor=g[3],n.shadowOffsetX=g[0],n.shadowOffsetY=g[1],n.shadowBlur=g[2],g[0]>0?l-=g[0]:(l+=g[0],o-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],s-=g[1])),d(n,o,s,l,f,t.getLength(e.borderRadius?e.borderRadius:h.borderRadius),t.handleBackground(o,s,l,f,e.background,u)),n.shadowColor="rgba(255, 255, 255, 0)",n.shadowOffsetX=0,n.shadowOffsetY=0,n.shadowBlur=0,e.imgs&&e.imgs.forEach((function(r,a){if(!t.cellImgs[i])return!1;var h=t.cellImgs[i][a];if(!h)return!1;var c,l=u&&h.activeImg||h.defaultImg,f=t.computedWidthAndHeight(l,r,e),d=f[0],g=f[1],p=[o+t.getOffsetX(d,e.col),s+t.getHeight(r.top,e.row)],m=p[0],v=p[1];"WEB"===t.config.flag?c=l:["MINI-WX","UNI-H5","UNI-MINI-WX"].includes(t.config.flag)&&(c=l.path),n.drawImage(c,m,v,d,g)})),e.fonts&&e.fonts.forEach((function(i){var r=u&&c.fontStyle?c.fontStyle:i.fontStyle||h.fontStyle,l=u&&c.fontWeight?c.fontWeight:i.fontWeight||h.fontWeight,f=u&&c.fontSize?t.getLength(c.fontSize):t.getLength(i.fontSize||h.fontSize),d=u&&c.lineHeight?c.lineHeight:i.lineHeight||h.lineHeight||i.fontSize||h.fontSize;n.font=l+" "+f+"px "+r,n.fillStyle=u&&c.fontColor?c.fontColor:i.fontColor||h.fontColor;var g=[],p=String(i.text);if(i.hasOwnProperty("wordWrap")?i.wordWrap:h.wordWrap){p=a(p);for(var m="",v=0;vt.getWidth(i.lengthLimit||h.lengthLimit,e.col)&&(g.push(m.slice(0,-1)),m=p[v])}m&&g.push(m),g.length||g.push(p)}else g=p.split("\n");g.forEach((function(r,a){n.fillText(r,o+t.getOffsetX(n.measureText(r).width,e.col),s+t.getHeight(i.top,e.row)+(a+1)*t.getLength(d))}))}))})),n.draw&&n.draw()},h.prototype.handleBackground=function(t,e,i,n,r,o){void 0===o&&(o=!1);var s=this,a=s.ctx,h=s._defaultStyle,c=s._activeStyle;return(r=o?c.background:r||h.background).includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var s=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),a=s.shift(),h=[0,0,0,0];if(a.includes("deg")){var c=function(t){return Math.tan(t/180*Math.PI)};(a=a.slice(0,-3)%360)>=0&&a<45?h=[e,i+r,e+n,i+r-n*c(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*c(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*c(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*c(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*c(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*c(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*c(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*c(a-315)])}else a.includes("top")?h=[e,i+r,e,i]:a.includes("bottom")?h=[e,i,e,i+r]:a.includes("left")?h=[e+n,i,e,i]:a.includes("right")&&(h=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return s.reduce((function(t,e,i){var n=e.split(" ");return 1===n.length?t.addColorStop(i,n[0]):2===n.length&&t.addColorStop.apply(t,n),t}),l)}(a,t,e,i,n,r)),r},h.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},h.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},h.prototype.run=function(t){void 0===t&&(t=0);var e=this,i=e.rAF,n=e.currIndex,r=e.prizes,o=e.prizeFlag,s=e.startTime,a=e._defaultConfig,h=Date.now()-s;if(h>=a.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var c=0;++c;){var l=r.length*c+o-(n>>0);if(p(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+g(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},h.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,o=e.prizeFlag,s=e.stopIndex,a=e.endIndex,h=e._defaultConfig,c=Date.now()-this.endTime;if(c>h.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,i({},r.find((function(t,e){return e===o})))));this.currIndex=p(c,s,a,h.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},h.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},h.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=t[3],o=this.cellWidth,s=this.cellHeight,a=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+a)*e,this.prizeArea.y+(s+a)*i];return n&&r&&h.push(o*n+a*(n-1),s*r+a*(r-1)),h},h.prototype.getWidth=function(t,e){return void 0===e&&(e=1),s(t,"number")?t:s(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=1),s(t,"number")?t:s(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},h.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},h}(h);exports.LuckyGrid=v,exports.LuckyWheel=m; /***/ }), diff --git a/dist/vue-luck-draw.umd.min.js b/dist/vue-luck-draw.umd.min.js index 6577aa1..32f4806 100644 --- a/dist/vue-luck-draw.umd.min.js +++ b/dist/vue-luck-draw.umd.min.js @@ -13,4 +13,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function i(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n=f(180).toFixed(8)){var a=(r+n)/2;return i?(d(t,e,n,a,i),d(t,e,a,r,i)):(d(t,e,a,r,i),d(t,e,n,a,i)),!1}i||(n=(o=[r,n])[0],r=o[1]);var c=l(n,e),u=c[0],s=c[1],p=l(r,e),g=p[0],v=p[1],y=h(u,s),m=y[0],b=y[1],w=h(g,v),S=w[0],x=w[1],O=(x-b)/(m-S),I=(S*b-m*x)/(S-m);isNaN(O)&&(Math.abs(u)===+e.toFixed(8)&&(O=u),Math.abs(g)===+e.toFixed(8)&&(O=g)),m===1/0||m===-1/0?I=S*O+x:S!==1/0&&S!==-1/0||(I=m*O+b),t.lineTo(u,s),t.arcTo(O,I,g,v,e)},p=function(t,e,n,r,i,o,a){var c=Math.min(r,i);o>c/2&&(o=c/2),t.beginPath(),t.fillStyle=a,t.moveTo(e+o,n),t.lineTo(e+o,n),t.lineTo(e+r-o,n),t.arcTo(e+r,n,e+r,n+o,o),t.lineTo(e+r,n+i-o),t.arcTo(e+r,n+i,e+r-o,n+i,o),t.lineTo(e+o,n+i),t.arcTo(e,n+i,e,n+i-o,o),t.lineTo(e,n+o),t.arcTo(e,n,e+o,n,o),t.closePath(),t.fill()},g=function(t,e,n,r){return t>=r&&(t=r),n*(t/=r)*t+e},v=function(t,e,n,r){return t>=r&&(t=r),-n*(t/=r)*(t-2)+e},y=function(t){function e(e,n){void 0===n&&(n={});var r=t.call(this,e)||this;r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r._defaultConfig={gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},r.defaultStyle={},r._defaultStyle={fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",wordWrap:!0,lengthLimit:"90%"},r.Radius=0,r.prizeRadius=0,r.prizeDeg=0,r.prizeRadian=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.animationId=0,r.FPS=16.6,r.prizeImgs=[[]],r.btnImgs=[[]],r.initData(n),r.initComputed(),r.initWatch();var i=[[]];return r.prizes&&(i=r.prizes.map((function(t){return t.imgs}))),r.buttons&&i.push.apply(i,r.buttons.map((function(t){return t.imgs}))),r.init(i),r}return i(e,t),e.prototype.initData=function(t){this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},e.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return o({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return o({fontSize:"18px",fontColor:"#000",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,n){var r=[];return n?e&&e.forEach((function(e,i){var o=[],a=n[i];a?e.imgs&&e.imgs.forEach((function(e,n){if(!a.imgs)return o[n]=e;var r=a.imgs[n];r&&t.prizeImgs[i]&&t.prizeImgs[i][n]?e.src!==r.src&&(o[n]=e):o[n]=e})):o=e.imgs||[],r[i]=o})):r=e.map((function(t){return t.imgs})),t.init(r)})),this.$watch("buttons",(function(e,n){var r=[];return n?e&&e.forEach((function(e,i){var o=[],a=n[i];a&&a.imgs?e.imgs&&e.imgs.forEach((function(e,n){if(!a.imgs)return o[n]=e;var r=a.imgs[n];r&&t.btnImgs[i]&&t.btnImgs[i][n]?e.src!==r.src&&(o[n]=e):o[n]=e})):o=e.imgs||[],r[i]=o})):r=e.map((function(t){return t.imgs})),t.init(a(new Array(t.prizes.length).fill(void 0),r))}))},e.prototype.init=function(t){var e=this,n=this.config,r=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),this.Radius=Math.min(n.width,n.height)/2,r.translate(this.Radius,this.Radius);var i=function(){e.draw(),e.draw(),n.canvasElement&&(n.canvasElement.onclick=function(t){var n;r.beginPath(),r.arc(0,0,e.maxBtnRadius,0,2*Math.PI,!1),r.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(n=e.startCallback)||void 0===n||n.call(e,t))})},o=0,a=0;c(t,"array")&&(this.draw(),t.forEach((function(t,n){if(!t)return!1;t.forEach((function(t,r){a++,e.loadAndCacheImg(n,r,(function(){o++,a===o&&i.call(e)}))}))}))),a||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,n){var r=this,i=tp?d(t,e,p,g,!1):t.lineTo.apply(t,l((r+i)/2,o/2/Math.abs(Math.sin((r-i)/2)))),t.closePath(),t.fill()}(n,t.maxBtnRadius,t.prizeRadius,h-t.prizeRadian/2,h+t.prizeRadian/2,t.getLength(r.gutter),e.background||i.background||"rgba(0, 0, 0, 0)");var g=Math.cos(h)*t.prizeRadius,v=Math.sin(h)*t.prizeRadius;n.translate(g,v),n.rotate(h+f(90)),e.imgs&&e.imgs.forEach((function(e,r){if(t.prizeImgs[s]){var i=t.prizeImgs[s][r];if(i){var o,a=t.computedWidthAndHeight(i,e,t.prizeRadian*t.prizeRadius,p),c=a[0],u=a[1],f=[t.getOffsetX(c),t.getHeight(e.top,p)],l=f[0],h=f[1];"WEB"===t.config.flag?o=i:0===t.config.flag.indexOf("UNI-")&&(o=i.path),n.drawImage(o,l,h,c,u)}}})),e.fonts&&e.fonts.forEach((function(e){var o=e.fontColor||i.fontColor,s=e.fontWeight||i.fontWeight,f=t.getLength(e.fontSize||i.fontSize),l=e.fontStyle||i.fontStyle;n.fillStyle=o,n.font=s+" "+f+"px "+l;var h=[],d=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:i.wordWrap){d=u(d);for(var g="",v=0;vt.getWidth(e.lengthLimit||i.lengthLimit,m)&&(h.push(g.slice(0,-1)),g=d[v])}g&&h.push(g),h.length||h.push(d)}else h=d.split("\n");h.filter((function(t){return!!t})).forEach((function(t,r){n.fillText(t,a(t),c(e,p,r))}))})),n.rotate(f(360)-h-f(90)),n.translate(-g,-v)})),n.restore(),this.buttons.forEach((function(e,r){var o=t.getHeight(e.radius);t.maxBtnRadius=Math.max(t.maxBtnRadius,o),n.beginPath(),n.fillStyle=e.background||"rgba(0, 0, 0, 0)",n.arc(0,0,o,0,2*Math.PI,!1),n.fill(),e.pointer&&(n.beginPath(),n.fillStyle=e.background||"rgba(0, 0, 0, 0)",n.moveTo(-o,0),n.lineTo(o,0),n.lineTo(0,2*-o),n.closePath(),n.fill()),e.imgs&&e.imgs.forEach((function(i,a){if(t.btnImgs[r]){var c=t.btnImgs[r][a];if(c){var u,s=t.computedWidthAndHeight(c,i,2*t.getHeight(e.radius),2*t.getHeight(e.radius)),f=s[0],l=s[1],h=[t.getOffsetX(f),t.getHeight(i.top,o)],d=h[0],p=h[1];"WEB"===t.config.flag?u=c:0===t.config.flag.indexOf("UNI-")&&(u=c.path),n.drawImage(u,d,p,f,l)}}})),e.fonts&&e.fonts.forEach((function(e){var r=e.fontColor||i.fontColor,u=e.fontWeight||i.fontWeight,s=t.getLength(e.fontSize||i.fontSize),f=e.fontStyle||i.fontStyle;n.fillStyle=r,n.font=u+" "+s+"px "+f,String(e.text).split("\n").forEach((function(t,r){n.fillText(t,a(t),c(e,o,r))}))}))})),0===this.config.flag.indexOf("UNI-")&&n.draw()},e.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},e.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},e.prototype.run=function(t){void 0===t&&(t=0);var e=this,n=e.rAF,r=e.prizeFlag,i=e.prizeDeg,o=e.rotateDeg,a=e._defaultConfig,c=Date.now()-this.startTime;if(c>=a.accelerationTime&&void 0!==r){this.FPS=c/t,this.endTime=Date.now(),this.stopDeg=o;for(var u=0;++u;){var s=360*u-r*i-o-a.offsetDegree;if(v(this.FPS,this.stopDeg,s,a.decelerationTime)-this.stopDeg>a.speed){this.endDeg=s;break}}return this.slowDown()}this.rotateDeg=(o+g(c,0,a.speed,a.accelerationTime))%360,this.draw(),n(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,i=e.prizeFlag,a=e.stopDeg,c=e.endDeg,u=e._defaultConfig,s=Date.now()-this.endTime;if(s>=u.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,o({},r.find((function(t,e){return e===i})))));this.rotateDeg=v(s,a,c,u.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},e.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),c(t,"number")?t:c(t,"string")?this.changeUnits(t,e):0},e.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),c(t,"number")?t:c(t,"string")?this.changeUnits(t,e):0},e.prototype.getOffsetX=function(t){return-t/2},e}(s),m=function(t){function e(e,n){void 0===n&&(n={});var r=t.call(this,e)||this;r.rows=3,r.cols=3,r.blocks=[],r.prizes=[],r.defaultConfig={},r._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},r.defaultStyle={},r._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",lineHeight:"",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},r.activeStyle={},r._activeStyle={background:"#ffce98",shadow:"",fontStyle:"",fontWeight:"",fontSize:"",lineHeight:"",fontColor:""},r.cellWidth=0,r.cellHeight=0,r.startTime=0,r.endTime=0,r.currIndex=0,r.stopIndex=0,r.endIndex=0,r.demo=!1,r.timer=0,r.animationId=0,r.FPS=16.6,r.cells=[],r.cellImgs=[],r.initData(n),r.initComputed(),r.initWatch();var i=[[]];return r.prizes&&(i=r.prizes.map((function(t){return t.imgs}))),r.button&&(i[r.cols*r.rows-1]=r.button.imgs),r.init(i),r}return i(e,t),e.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"button",t.button),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"activeStyle",t.activeStyle||{}),this.$set(this,"startCallback",t.start),this.$set(this,"endCallback",t.end)},e.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=o({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return o({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"microsoft yahei ui,microsoft yahei,simsun,sans-serif",fontWeight:"400",background:"#fff",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return o({background:"#ffce98",shadow:""},t.activeStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("prizes",(function(e,n){var r=[];return n?e&&e.forEach((function(e,i){var o=[],a=n[i];a?e.imgs&&e.imgs.forEach((function(e,n){if(!a.imgs)return o[n]=e;var r=a.imgs[n];r&&t.cellImgs[i][n]?e.src!==r.src&&(o[n]=e):o[n]=e})):o=e.imgs||[],r[i]=o})):r=e.map((function(t){return t.imgs})),t.init(r)})),this.$watch("button",(function(e,n){var r=[],i=t.cols*t.rows-1;if(n&&n.imgs){if(e.imgs){var o=[];e.imgs.forEach((function(e,r){if(!n.imgs)return o[r]=e;var a=n.imgs[r];a&&t.cellImgs[i][r]?e.src!==a.src&&(o[r]=e):o[r]=e})),r[i]=o}}else r[i]=e.imgs;return t.init(r)}))},e.prototype.init=function(t){var e=this,n=this,r=n.config,i=n.ctx,o=n.button;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas();var a=function(){e.draw(),e.demo&&e.walk(),o&&r.canvasElement&&(r.canvasElement.onclick=function(t){var n,r=e.getGeometricProperty([o.x,o.y,o.col||1,o.row||1]),a=r[0],c=r[1],u=r[2],s=r[3];i.beginPath(),i.rect(a,c,u,s),i.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||null===(n=e.startCallback)||void 0===n||n.call(e,t))})},u=0,s=0;c(t,"array")&&(this.draw(),t.forEach((function(t,n){if(!t)return!1;t.forEach((function(t,r){s++,e.loadAndCacheImg(n,r,(function(){u++,s===u&&a.call(e)}))}))}))),s||a.call(this)},e.prototype.loadAndCacheImg=function(t,e,n){var r=this,i=this.cells[t];if(i&&i.imgs){var o=i.imgs[e];this.cellImgs[t]||(this.cellImgs[t]=[]);var a=0,c=1;if("WEB"===this.config.flag){var u=new Image;this.cellImgs[t][e]={defaultImg:u},u.src=o.src,u.onload=function(){++a===c&&n.call(r)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.src,success:function(i){r.cellImgs[t][e]={defaultImg:i},++a===c&&n.call(r)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.src)}});if(o.hasOwnProperty("activeSrc"))if(c++,"WEB"===this.config.flag){var s=new Image;this.cellImgs[t][e].activeImg=s,s.src=o.activeSrc,s.onload=function(){++a===c&&n.call(r)}}else 0===this.config.flag.indexOf("UNI-")&&uni.getImageInfo({src:o.activeSrc,success:function(i){r.cellImgs[t][e].activeImg=i,++a===c&&n.call(r)},fail:function(){return console.error("uni.getImageInfo 加载图片失败",o.activeSrc)}})}},e.prototype.computedWidthAndHeight=function(t,e,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,n.col);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var i=this.getHeight(e.height,n.row);return[t.width*(i/t.height),i]}return[this.getWidth(e.width,n.col),this.getHeight(e.height,n.row)]},e.prototype.draw=function(){var t=this,e=this,n=e.config,r=e.ctx,i=e._defaultConfig,o=e._defaultStyle,s=e._activeStyle;r.clearRect(0,0,n.width,n.height),this.cells=a(this.prizes),this.button&&(this.cells[this.cols*this.rows-1]=this.button),this.cells.forEach((function(t){t.col=t.col||1,t.row=t.row||1})),this.prizeArea=this.blocks.reduce((function(e,n){var i=e.x,o=e.y,a=e.w,u=e.h,s=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],n=0,r=0,i=0,o=0;switch(e.length){case 1:n=r=i=o=e[0];break;case 2:n=r=e[0],i=o=e[1];break;case 3:n=e[0],i=o=e[1],r=e[2];break;default:n=e[0],r=e[1],i=e[2],o=e[3]}var a={paddingTop:n,paddingBottom:r,paddingLeft:i,paddingRight:o};for(var u in a)a[u]=t.hasOwnProperty(u)&&c(t[u],"string","number")?~~String(t[u]).replace(/px/g,""):a[u];return[n,r,i,o]}(n).map((function(t){return~~t})),f=s[0],l=s[1],h=s[2],d=s[3],g=n.borderRadius?t.getLength(n.borderRadius):0;return p(r,i,o,a,u,g,t.handleBackground(i,o,a,u,n.background)),{x:i+h,y:o+f,w:a-h-d,h:u-f-l}}),{x:0,y:0,w:n.width,h:n.height}),this.cellWidth=(this.prizeArea.w-i.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-i.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(e,n){var i=t.getGeometricProperty([e.x,e.y,e.col,e.row]),a=i[0],c=i[1],f=i[2],l=i[3],h=n===t.currIndex%t.prizes.length>>0,d=(h?s.shadow:e.shadow||o.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===d.length&&(r.shadowColor=d[3],r.shadowOffsetX=d[0],r.shadowOffsetY=d[1],r.shadowBlur=d[2],d[0]>0?f-=d[0]:(f+=d[0],a-=d[0]),d[1]>0?l-=d[1]:(l+=d[1],c-=d[1])),p(r,a,c,f,l,t.getLength(e.borderRadius?e.borderRadius:o.borderRadius),t.handleBackground(a,c,f,l,e.background,h)),r.shadowColor="rgba(255, 255, 255, 0)",r.shadowOffsetX=0,r.shadowOffsetY=0,r.shadowBlur=0,e.imgs&&e.imgs.forEach((function(i,o){if(!t.cellImgs[n])return!1;var u=t.cellImgs[n][o];if(!u)return!1;var s,f=h&&u.activeImg||u.defaultImg,l=t.computedWidthAndHeight(f,i,e),d=l[0],p=l[1],g=[a+t.getOffsetX(d,e.col),c+t.getHeight(i.top,e.row)],v=g[0],y=g[1];"WEB"===t.config.flag?s=f:0===t.config.flag.indexOf("UNI-")&&(s=f.path),r.drawImage(s,v,y,d,p)})),e.fonts&&e.fonts.forEach((function(n){var i=h&&s.fontStyle?s.fontStyle:n.fontStyle||o.fontStyle,f=h&&s.fontWeight?s.fontWeight:n.fontWeight||o.fontWeight,l=h&&s.fontSize?t.getLength(s.fontSize):t.getLength(n.fontSize||o.fontSize),d=h&&s.lineHeight?s.lineHeight:n.lineHeight||o.lineHeight||n.fontSize||o.fontSize;r.font=f+" "+l+"px "+i,r.fillStyle=h&&s.fontColor?s.fontColor:n.fontColor||o.fontColor;var p=[],g=String(n.text);if(n.hasOwnProperty("wordWrap")?n.wordWrap:o.wordWrap){g=u(g);for(var v="",y=0;yt.getWidth(n.lengthLimit||o.lengthLimit,e.col)&&(p.push(v.slice(0,-1)),v=g[y]);v&&p.push(v),p.length||p.push(g)}else p=g.split("\n");p.forEach((function(i,o){r.fillText(i,a+t.getOffsetX(r.measureText(i).width,e.col),c+t.getHeight(n.top,e.row)+(o+1)*t.getLength(d))}))}))})),r.draw&&r.draw()},e.prototype.handleBackground=function(t,e,n,r,i,o){void 0===o&&(o=!1);var a=this,c=a.ctx,u=a._defaultStyle,s=a._activeStyle;return(i=o?s.background:i||u.background).includes("linear-gradient")&&(i=function(t,e,n,r,i,o){var a=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),c=a.shift(),u=[0,0,0,0];if(c.includes("deg")){var s=function(t){return Math.tan(t/180*Math.PI)};(c=c.slice(0,-3)%360)>=0&&c<45?u=[e,n+i,e+r,n+i-r*s(c-0)]:c>=45&&c<90?u=[e,n+i,e+r-i*s(c-45),n]:c>=90&&c<135?u=[e+r,n+i,e+r-i*s(c-90),n]:c>=135&&c<180?u=[e+r,n+i,e,n+r*s(c-135)]:c>=180&&c<225?u=[e+r,n,e,n+r*s(c-180)]:c>=225&&c<270?u=[e+r,n,e+i*s(c-225),n+i]:c>=270&&c<315?u=[e,n,e+i*s(c-270),n+i]:c>=315&&c<360&&(u=[e,n,e+r,n+i-r*s(c-315)])}else c.includes("top")?u=[e,n+i,e,n]:c.includes("bottom")?u=[e,n,e,n+i]:c.includes("left")?u=[e+r,n,e,n]:c.includes("right")&&(u=[e,n,e+r,n]);var f=t.createLinearGradient.apply(t,u.map((function(t){return t>>0})));return a.reduce((function(t,e,n){var r=e.split(" ");return 1===r.length?t.addColorStop(n,r[0]):2===r.length&&t.addColorStop.apply(t,r),t}),f)}(c,t,e,n,r,i)),i},e.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},e.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},e.prototype.run=function(t){void 0===t&&(t=0);var e=this,n=e.rAF,r=e.currIndex,i=e.prizes,o=e.prizeFlag,a=e.startTime,c=e._defaultConfig,u=Date.now()-a;if(u>=c.accelerationTime&&void 0!==o){this.FPS=u/t,this.endTime=Date.now(),this.stopIndex=r;for(var s=0;++s;){var f=i.length*s+o-(r>>0);if(v(this.FPS,this.stopIndex,f,c.decelerationTime)-this.stopIndex>c.speed){this.endIndex=f;break}}return this.slowDown()}this.currIndex=(r+g(u,.1,c.speed,c.accelerationTime))%i.length,this.draw(),n(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,n=e.rAF,r=e.prizes,i=e.prizeFlag,a=e.stopIndex,c=e.endIndex,u=e._defaultConfig,s=Date.now()-this.endTime;if(s>u.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,o({},r.find((function(t,e){return e===i})))));this.currIndex=v(s,a,c,u.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},e.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},e.prototype.getGeometricProperty=function(t){var e=t[0],n=t[1],r=t[2],i=t[3],o=this.cellWidth,a=this.cellHeight,c=this._defaultConfig.gutter,u=[this.prizeArea.x+(o+c)*e,this.prizeArea.y+(a+c)*n];return r&&i&&u.push(o*r+c*(r-1),a*i+c*(i-1)),u},e.prototype.getWidth=function(t,e){return void 0===e&&(e=1),c(t,"number")?t:c(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},e.prototype.getHeight=function(t,e){return void 0===e&&(e=1),c(t,"number")?t:c(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},e.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},e}(s);e.LuckyGrid=m,e.LuckyWheel=y},"37e8":function(t,e,n){var r=n("83ab"),i=n("9bf2"),o=n("825a"),a=n("df75");t.exports=r?Object.defineProperties:function(t,e){o(t);var n,r=a(e),c=r.length,u=0;while(c>u)i.f(t,n=r[u++],e[n]);return t}},"3bbe":function(t,e,n){var r=n("861d");t.exports=function(t){if(!r(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype");return t}},4160:function(t,e,n){"use strict";var r=n("23e7"),i=n("17c2");r({target:"Array",proto:!0,forced:[].forEach!=i},{forEach:i})},"428f":function(t,e,n){var r=n("da84");t.exports=r},"44ad":function(t,e,n){var r=n("d039"),i=n("c6b6"),o="".split;t.exports=r((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==i(t)?o.call(t,""):Object(t)}:Object},"45fc":function(t,e,n){"use strict";var r=n("23e7"),i=n("b727").some,o=n("a640"),a=n("ae40"),c=o("some"),u=a("some");r({target:"Array",proto:!0,forced:!c||!u},{some:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}})},4930:function(t,e,n){var r=n("d039");t.exports=!!Object.getOwnPropertySymbols&&!r((function(){return!String(Symbol())}))},"4d64":function(t,e,n){var r=n("fc6a"),i=n("50c4"),o=n("23cb"),a=function(t){return function(e,n,a){var c,u=r(e),s=i(u.length),f=o(a,s);if(t&&n!=n){while(s>f)if(c=u[f++],c!=c)return!0}else for(;s>f;f++)if((t||f in u)&&u[f]===n)return t||f||0;return!t&&-1}};t.exports={includes:a(!0),indexOf:a(!1)}},"4de4":function(t,e,n){"use strict";var r=n("23e7"),i=n("b727").filter,o=n("1dde"),a=n("ae40"),c=o("filter"),u=a("filter");r({target:"Array",proto:!0,forced:!c||!u},{filter:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}})},"50c4":function(t,e,n){var r=n("a691"),i=Math.min;t.exports=function(t){return t>0?i(r(t),9007199254740991):0}},5135:function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},5692:function(t,e,n){var r=n("c430"),i=n("c6cd");(t.exports=function(t,e){return i[t]||(i[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:r?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})},"56ef":function(t,e,n){var r=n("d066"),i=n("241c"),o=n("7418"),a=n("825a");t.exports=r("Reflect","ownKeys")||function(t){var e=i.f(a(t)),n=o.f;return n?e.concat(n(t)):e}},5899:function(t,e){t.exports="\t\n\v\f\r                 \u2028\u2029\ufeff"},"58a8":function(t,e,n){var r=n("1d80"),i=n("5899"),o="["+i+"]",a=RegExp("^"+o+o+"*"),c=RegExp(o+o+"*$"),u=function(t){return function(e){var n=String(r(e));return 1&t&&(n=n.replace(a,"")),2&t&&(n=n.replace(c,"")),n}};t.exports={start:u(1),end:u(2),trim:u(3)}},"5c6c":function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},"65f0":function(t,e,n){var r=n("861d"),i=n("e8b5"),o=n("b622"),a=o("species");t.exports=function(t,e){var n;return i(t)&&(n=t.constructor,"function"!=typeof n||n!==Array&&!i(n.prototype)?r(n)&&(n=n[a],null===n&&(n=void 0)):n=void 0),new(void 0===n?Array:n)(0===e?0:e)}},"69f3":function(t,e,n){var r,i,o,a=n("7f9a"),c=n("da84"),u=n("861d"),s=n("9112"),f=n("5135"),l=n("f772"),h=n("d012"),d=c.WeakMap,p=function(t){return o(t)?i(t):r(t,{})},g=function(t){return function(e){var n;if(!u(e)||(n=i(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return n}};if(a){var v=new d,y=v.get,m=v.has,b=v.set;r=function(t,e){return b.call(v,t,e),e},i=function(t){return y.call(v,t)||{}},o=function(t){return m.call(v,t)}}else{var w=l("state");h[w]=!0,r=function(t,e){return s(t,w,e),e},i=function(t){return f(t,w)?t[w]:{}},o=function(t){return f(t,w)}}t.exports={set:r,get:i,has:o,enforce:p,getterFor:g}},"6eeb":function(t,e,n){var r=n("da84"),i=n("9112"),o=n("5135"),a=n("ce4e"),c=n("8925"),u=n("69f3"),s=u.get,f=u.enforce,l=String(String).split("String");(t.exports=function(t,e,n,c){var u=!!c&&!!c.unsafe,s=!!c&&!!c.enumerable,h=!!c&&!!c.noTargetGet;"function"==typeof n&&("string"!=typeof e||o(n,"name")||i(n,"name",e),f(n).source=l.join("string"==typeof e?e:"")),t!==r?(u?!h&&t[e]&&(s=!0):delete t[e],s?t[e]=n:i(t,e,n)):s?t[e]=n:a(e,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&s(this).source||c(this)}))},7156:function(t,e,n){var r=n("861d"),i=n("d2bb");t.exports=function(t,e,n){var o,a;return i&&"function"==typeof(o=e.constructor)&&o!==n&&r(a=o.prototype)&&a!==n.prototype&&i(t,a),t}},7418:function(t,e){e.f=Object.getOwnPropertySymbols},"746f":function(t,e,n){var r=n("428f"),i=n("5135"),o=n("e538"),a=n("9bf2").f;t.exports=function(t){var e=r.Symbol||(r.Symbol={});i(e,t)||a(e,t,{value:o.f(t)})}},7839:function(t,e){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},"7b0b":function(t,e,n){var r=n("1d80");t.exports=function(t){return Object(r(t))}},"7c73":function(t,e,n){var r,i=n("825a"),o=n("37e8"),a=n("7839"),c=n("d012"),u=n("1be4"),s=n("cc12"),f=n("f772"),l=">",h="<",d="prototype",p="script",g=f("IE_PROTO"),v=function(){},y=function(t){return h+p+l+t+h+"/"+p+l},m=function(t){t.write(y("")),t.close();var e=t.parentWindow.Object;return t=null,e},b=function(){var t,e=s("iframe"),n="java"+p+":";return e.style.display="none",u.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(y("document.F=Object")),t.close(),t.F},w=function(){try{r=document.domain&&new ActiveXObject("htmlfile")}catch(e){}w=r?m(r):b();var t=a.length;while(t--)delete w[d][a[t]];return w()};c[g]=!0,t.exports=Object.create||function(t,e){var n;return null!==t?(v[d]=i(t),n=new v,v[d]=null,n[g]=t):n=w(),void 0===e?n:o(n,e)}},"7f9a":function(t,e,n){var r=n("da84"),i=n("8925"),o=r.WeakMap;t.exports="function"===typeof o&&/native code/.test(i(o))},"825a":function(t,e,n){var r=n("861d");t.exports=function(t){if(!r(t))throw TypeError(String(t)+" is not an object");return t}},"83ab":function(t,e,n){var r=n("d039");t.exports=!r((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}))},8418:function(t,e,n){"use strict";var r=n("c04e"),i=n("9bf2"),o=n("5c6c");t.exports=function(t,e,n){var a=r(e);a in t?i.f(t,a,o(0,n)):t[a]=n}},"861d":function(t,e){t.exports=function(t){return"object"===typeof t?null!==t:"function"===typeof t}},8875:function(t,e,n){var r,i,o;(function(n,a){i=[],r=a,o="function"===typeof r?r.apply(e,i):r,void 0===o||(t.exports=o)})("undefined"!==typeof self&&self,(function(){function t(){var e=Object.getOwnPropertyDescriptor(document,"currentScript");if(!e&&"currentScript"in document&&document.currentScript)return document.currentScript;if(e&&e.get!==t&&document.currentScript)return document.currentScript;try{throw new Error}catch(d){var n,r,i,o=/.*at [^(]*\((.*):(.+):(.+)\)$/gi,a=/@([^@]*):(\d+):(\d+)\s*$/gi,c=o.exec(d.stack)||a.exec(d.stack),u=c&&c[1]||!1,s=c&&c[2]||!1,f=document.location.href.replace(document.location.hash,""),l=document.getElementsByTagName("script");u===f&&(n=document.documentElement.outerHTML,r=new RegExp("(?:[^\\n]+?\\n){0,"+(s-2)+"}[^<]*