Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lucky-canvas

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lucky-canvas - npm Package Compare versions

Comparing version 1.2.8 to 1.2.9

2

dist/lucky-canvas.cjs.min.js

@@ -16,2 +16,2 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});

***************************************************************************** */
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<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function o(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return n}var s=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},a=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),c=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){l(t,e,t[e])}))},l=function(t,e,i){var n=new h;c(i);Object.defineProperty(t,e,{get:function(){return h.target&&n.addSub(h.target),i},set:function(t){t!==i&&(i=t,c(t),n.notify())}})},u=0;var f=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=u++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){h.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){s(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),h.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),d=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.8"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return s(t,"number")?t:s(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&l(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new f(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),g=function(t){return Math.PI/180*t},p=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},m=function(t,e){var i=-t/e;return[i,-i*t+e]},v=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=g(180).toFixed(8)){var a=(r+n)/2;return o?(v(t,e,i,n,a,o),v(t,e,i,a,r,o)):(v(t,e,i,a,r,o),v(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=p(n,i),c=h[0],l=h[1],u=p(r,i),f=u[0],d=u[1],w=m(c,l),y=w[0],b=w[1],I=m(f,d),z=I[0],S=I[1],x=(S-b)/(y-z),C=(z*b-y*S)/(z-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?C=z*x+S:z!==1/0&&z!==-1/0||(C=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,C,f,d,i):e.quadraticCurveTo(x,C,f,d)},w=function(t,e,i,n,r,o,s,a){i||(i=s);var h=g(90/Math.PI/n*s),c=g(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,d=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,p(l,n)),v(t,e,n,l,u,!0),d>f?v(t,e,i,f,d,!1):e.lineTo.apply(e,p((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},y=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},b=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},I=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},z=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)}),{deep:!0}),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))}),{deep:!0}),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},h.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var a=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},h=0,c=0;s(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){c++,n.loadAndCacheImg(e,i,(function(){h++,c===h&&a.call(n)}))}))}))),c||a.call(this),null===(i=r.afterInit)||void 0===i||i.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=t<this.prizes.length,o=n?"prizes":"buttons",s=n?"prizeImgs":"btnImgs",t=n?t:t-this.prizes.length,(a=this[o][t])&&a.imgs?(h=a.imgs[e])?(this[s][t]||(this[s][t]=[]),c=this[s][t],l=e,[4,this.loadImg(h.src,h)]):[2]:[2];case 1:return c[l]=r.sent(),i.call(this),[2]}}))}))},h.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},h.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,h=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=g(this.prizeDeg);var c=g(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||h.lineHeight||t.fontSize||h.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?w(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(s.gutter),t.background||h.background);var d=Math.cos(n)*i.prizeRadius,p=Math.sin(n)*i.prizeRadius;o.translate(d,p),o.rotate(n+g(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,n=t.fontWeight||h.fontWeight,r=i.getLength(t.fontSize||h.fontSize),c=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:h.wordWrap){g=a(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||h.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(g(360)-n-g(90)),o.translate(-d,-p)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,r=t.fontWeight||h.fontWeight,s=i.getLength(t.fontSize||h.fontSize),a=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},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(I(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+b(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=I(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}(d),S=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},h.prototype.init=function(t){var e,i,n=this,r=this,o=r.config,a=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],s=i[2],c=i[3];a.beginPath(),a.rect(r,o,s,c),a.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;s(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},h.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},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,o)]):[2];case 1:return s[a]=(c.defaultImg=r.sent(),c),o.hasOwnProperty("activeSrc")?[4,this.loadImg(o.activeSrc,o)]:[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,e,i=this,n=this,r=n.config,h=n.ctx,c=n._defaultConfig,l=n._defaultStyle,u=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,h),h.clearRect(0,0,r.width,r.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(t,e){var n=t.x,r=t.y,o=t.w,a=t.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]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return y(h,n,r,o,a,g,i.handleBackground(n,r,o,a,e.background)),{x:n+f,y:r+l,w:o-f-d,h:a-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-c.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-c.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),o=n[0],s=n[1],c=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?u.shadow:t.shadow||l.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(h.shadowColor=g[3],h.shadowOffsetX=g[0]*r.dpr,h.shadowOffsetY=g[1]*r.dpr,h.shadowBlur=g[2],g[0]>0?c-=g[0]:(c+=g[0],o-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],s-=g[1])),y(h,o,s,c,f,i.getLength(t.borderRadius?t.borderRadius:l.borderRadius),i.handleBackground(o,s,c,f,t.background,d)),h.shadowColor="rgba(0, 0, 0, 0)",h.shadowOffsetX=0,h.shadowOffsetY=0,h.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var a=i.cellImgs[e][r];if(!a)return!1;var c,l=d&&a.activeImg||a.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[o+i.getOffsetX(f,t.col),s+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),h.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&u.fontStyle?u.fontStyle:e.fontStyle||l.fontStyle,r=d&&u.fontWeight?u.fontWeight:e.fontWeight||l.fontWeight,c=d&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||l.fontSize),f=d&&u.lineHeight?u.lineHeight:e.lineHeight||l.lineHeight||e.fontSize||l.fontSize;h.font=r+" "+c+"px "+n,h.fillStyle=d&&u.fontColor?u.fontColor:e.fontColor||l.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:l.wordWrap){p=a(p);for(var m="",v=0;v<p.length;v++){m+=p[v],h.measureText(m).width>i.getWidth(e.lengthLimit||l.lengthLimit,t.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(n,r){h.fillText(n,o+i.getOffsetX(h.measureText(n).width,t.col),s+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,h)},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(I(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+b(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=I(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}(d);exports.LuckyGrid=S,exports.LuckyWheel=z;
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<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var o=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},s=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},a=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),h=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){c(t,e,t[e])}))},c=function(t,e,i){var n=new a;h(i);Object.defineProperty(t,e,{get:function(){return a.target&&n.addSub(a.target),i},set:function(t){t!==i&&(i=t,h(t),n.notify())}})},l=0;var u=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=l++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){a.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){o(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),a.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),f=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.9"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return o(t,"number")?t:o(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&c(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new u(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),d=function(t){return Math.PI/180*t},g=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},p=function(t,e){var i=-t/e;return[i,-i*t+e]},m=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=d(180).toFixed(8)){var a=(r+n)/2;return o?(m(t,e,i,n,a,o),m(t,e,i,a,r,o)):(m(t,e,i,a,r,o),m(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=g(n,i),c=h[0],l=h[1],u=g(r,i),f=u[0],v=u[1],w=p(c,l),y=w[0],b=w[1],I=p(f,v),S=I[0],z=I[1],x=(z-b)/(y-S),C=(S*b-y*z)/(S-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?C=S*x+z:S!==1/0&&S!==-1/0||(C=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,C,f,v,i):e.quadraticCurveTo(x,C,f,v)},v=function(t,e,i,n,r,o,s,a){i||(i=s);var h=d(90/Math.PI/n*s),c=d(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,p=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,g(l,n)),m(t,e,n,l,u,!0),p>f?m(t,e,i,f,p,!1):e.lineTo.apply(e,g((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},w=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},y=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},b=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},I=function(t){function a(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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.blockImgs=[[]],n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch(),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:n.buttons.map((function(t){return t.imgs}))}),n}return e(a,t),a.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)},a.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)}))},a.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e,i){t.init({blockImgs:[]})}),{deep:!0}),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({prizeImgs:n})}),{deep:!0}),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({btnImgs:n})}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init({})})),this.$watch("endCallback",(function(){return t.init({})}))},a.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var s=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},a=0,h=0;this.draw(),Object.keys(t).forEach((function(e){var i=t[e],r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[e];i&&i.forEach((function(t,i){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,i,e,o,(function(){a++,h===a&&s.call(n)}))}))}))})),h||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},a.prototype.loadAndCacheImg=function(t,e,i,o,s){return n(this,void 0,void 0,(function(){var n,a,h,c;return r(this,(function(r){switch(r.label){case 0:return(n=this[t][e])&&n.imgs&&(a=n.imgs[o])?(this[i][e]||(this[i][e]=[]),h=this[i][e],c=o,[4,this.loadImg(a.src,a)]):[2];case 1:return h[c]=r.sent(),s.call(this),[2]}}))}))},a.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,a=n._defaultConfig,h=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e,n){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),e.imgs&&e.imgs.forEach((function(e,r){if(i.blockImgs[n]){var s=i.blockImgs[n][r];if(s){var a,h=i.computedWidthAndHeight(s,e,2*t,2*t),c=h[0],l=h[1],u=[i.getOffsetX(c),i.getHeight(e.top,2*t)-t],f=u[0],g=u[1];["WEB","MINI-WX"].includes(i.config.flag)?a=s:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(a=s.path),o.save(),e.rotate&&o.rotate(d(i.rotateDeg)),o.drawImage(a,f,g,c,l),o.restore()}}})),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=d(this.prizeDeg);var c=d(-90+this.rotateDeg+a.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||h.lineHeight||t.fontSize||h.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?v(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter),t.background||h.background);var g=Math.cos(n)*i.prizeRadius,p=Math.sin(n)*i.prizeRadius;o.translate(g,p),o.rotate(n+d(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,n=t.fontWeight||h.fontWeight,r=i.getLength(t.fontSize||h.fontSize),c=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:h.wordWrap){g=s(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(a.gutter);v>i.getWidth(t.lengthLimit||h.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(d(360)-n-d(90)),o.translate(-g,-p)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,r=t.fontWeight||h.fontWeight,s=i.getLength(t.fontSize||h.fontSize),a=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},a.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},a.prototype.stop=function(t){this.prizeFlag=Number(t)%this.prizes.length},a.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(b(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+y(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},a.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=b(c,s,a,h.decelerationTime)%360,this.draw(),n(this.slowDown.bind(this))},a.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},a.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},a.prototype.getOffsetX=function(t){return-t/2},a}(f),S=function(t){function a(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),n}return e(a,t),a.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)},a.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)}))},a.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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},a.prototype.init=function(t){var e,i,n=this,r=this,s=r.config,a=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=s.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&s.canvasElement&&(s.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],s=i[2],c=i[3];a.beginPath(),a.rect(r,o,s,c),a.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;o(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=s.afterInit)||void 0===i||i.call(this)},a.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},a.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,o)]):[2];case 1:return s[a]=(c.defaultImg=r.sent(),c),o.hasOwnProperty("activeSrc")?[4,this.loadImg(o.activeSrc,o)]:[3,3];case 2:h=r.sent(),this.cellImgs[t][e].activeImg=h,r.label=3;case 3:return i.call(this),[2]}}))}))},a.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)]},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,a=n.ctx,h=n._defaultConfig,c=n._defaultStyle,l=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,a),a.clearRect(0,0,r.width,r.height),this.cells=function(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return 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(t,e){var n=t.x,r=t.y,s=t.w,h=t.h,c=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,r=0,s=0;switch(e.length){case 1:i=n=r=s=e[0];break;case 2:i=n=e[0],r=s=e[1];break;case 3:i=e[0],r=s=e[1],n=e[2];break;default:i=e[0],n=e[1],r=e[2],s=e[3]}var a={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:s};for(var h in a)a[h]=t.hasOwnProperty(h)&&o(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):a[h];return[i,n,r,s]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return w(a,n,r,s,h,g,i.handleBackground(n,r,s,h,e.background)),{x:n+f,y:r+l,w:s-f-d,h:h-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-h.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-h.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),o=n[0],h=n[1],u=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(a.shadowColor=g[3],a.shadowOffsetX=g[0]*r.dpr,a.shadowOffsetY=g[1]*r.dpr,a.shadowBlur=g[2],g[0]>0?u-=g[0]:(u+=g[0],o-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],h-=g[1])),w(a,o,h,u,f,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(o,h,u,f,t.background,d)),a.shadowColor="rgba(0, 0, 0, 0)",a.shadowOffsetX=0,a.shadowOffsetY=0,a.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var s=i.cellImgs[e][r];if(!s)return!1;var c,l=d&&s.activeImg||s.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[o+i.getOffsetX(f,t.col),h+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),a.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=d&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,u=d&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=d&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;a.font=r+" "+u+"px "+n,a.fillStyle=d&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:c.wordWrap){p=s(p);for(var m="",v=0;v<p.length;v++){m+=p[v],a.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.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(n,r){a.fillText(n,o+i.getOffsetX(a.measureText(n).width,t.col),h+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,a)},a.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},a.prototype.play=function(){var t=this.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},a.prototype.stop=function(t){this.prizeFlag=t%this.prizes.length},a.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(b(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+y(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},a.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=b(c,s,a,h.decelerationTime)%r.length,this.draw(),n(this.slowDown.bind(this))},a.prototype.walk=function(){var t=this,e=this.setInterval;(0,this.clearInterval)(this.timer),this.timer=e((function(){t.currIndex+=1,t.draw()}),1300)},a.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},a.prototype.getWidth=function(t,e){return void 0===e&&(e=1),o(t,"number")?t:o(t,"string")?this.changeUnits(t,this.cellWidth*e+this._defaultConfig.gutter*(e-1)):0},a.prototype.getHeight=function(t,e){return void 0===e&&(e=1),o(t,"number")?t:o(t,"string")?this.changeUnits(t,this.cellHeight*e+this._defaultConfig.gutter*(e-1)):0},a.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},a}(f);exports.LuckyGrid=S,exports.LuckyWheel=I;

@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LuckyCanvas={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(t,i){return(e=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])})(t,i)};function i(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return n}var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},c=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),l=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){u(t,e,t[e])}))},u=function(t,e,i){var n=new c;l(i);Object.defineProperty(t,e,{get:function(){return c.target&&n.addSub(c.target),i},set:function(t){t!==i&&(i=t,l(t),n.notify())}})},f=0;var d=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=f++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){c.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){a(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),c.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),g=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.8"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return a(t,"number")?t:a(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&u(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new d(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),p=function(t){return Math.PI/180*t},m=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},v=function(t,e){var i=-t/e;return[i,-i*t+e]},w=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=p(180).toFixed(8)){var a=(r+n)/2;return o?(w(t,e,i,n,a,o),w(t,e,i,a,r,o)):(w(t,e,i,a,r,o),w(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=m(n,i),c=h[0],l=h[1],u=m(r,i),f=u[0],d=u[1],g=v(c,l),y=g[0],b=g[1],I=v(f,d),z=I[0],S=I[1],x=(S-b)/(y-z),C=(z*b-y*S)/(z-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?C=z*x+S:z!==1/0&&z!==-1/0||(C=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,C,f,d,i):e.quadraticCurveTo(x,C,f,d)},y=function(t,e,i,n,r,o,s,a){i||(i=s);var h=p(90/Math.PI/n*s),c=p(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,d=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,m(l,n)),w(t,e,n,l,u,!0),d>f?w(t,e,i,f,d,!1):e.lineTo.apply(e,m((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},b=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},I=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},z=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},S=function(t){function e(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 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 n({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({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,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)}),{deep:!0}),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(s(new Array(t.prizes.length).fill(void 0),n))}),{deep:!0}),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var s=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},h=0,c=0;a(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){c++,n.loadAndCacheImg(e,i,(function(){h++,c===h&&s.call(n)}))}))}))),c||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c,l;return o(this,(function(o){switch(o.label){case 0:return n=t<this.prizes.length,r=n?"prizes":"buttons",s=n?"prizeImgs":"btnImgs",t=n?t:t-this.prizes.length,(a=this[r][t])&&a.imgs?(h=a.imgs[e])?(this[s][t]||(this[s][t]=[]),c=this[s][t],l=e,[4,this.loadImg(h.src,h)]):[2]:[2];case 1:return c[l]=o.sent(),i.call(this),[2]}}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,a=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=p(this.prizeDeg);var c=p(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||a.lineHeight||t.fontSize||a.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?y(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(s.gutter),t.background||a.background);var d=Math.cos(n)*i.prizeRadius,g=Math.sin(n)*i.prizeRadius;o.translate(d,g),o.rotate(n+p(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,n=t.fontWeight||a.fontWeight,r=i.getLength(t.fontSize||a.fontSize),c=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:a.wordWrap){g=h(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||a.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(p(360)-n-p(90)),o.translate(-d,-g)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,r=t.fontWeight||a.fontWeight,s=i.getLength(t.fontSize||a.fontSize),h=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+h,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},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,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(z(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+I(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.rotateDeg=z(c,s,a,h.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))},e.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},e.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},e.prototype.getOffsetX=function(t){return-t/2},e}(g),x=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),n}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=n({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 n({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 n({background:"#ffce98",shadow:""},t.activeStyle)}))},e.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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this,o=r.config,s=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],a=i[2],c=i[3];s.beginPath(),s.rect(r,o,a,c),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;a(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},e.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(r.src,r)]):[2];case 1:return s[a]=(c.defaultImg=o.sent(),c),r.hasOwnProperty("activeSrc")?[4,this.loadImg(r.activeSrc,r)]:[3,3];case 2:h=o.sent(),this.cellImgs[t][e].activeImg=h,o.label=3;case 3:return i.call(this),[2]}}))}))},e.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)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,c=n._defaultConfig,l=n._defaultStyle,u=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,r.width,r.height),this.cells=s(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(t,e){var n=t.x,r=t.y,s=t.w,h=t.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 s={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o};for(var h in s)s[h]=t.hasOwnProperty(h)&&a(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):s[h];return[i,n,r,o]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return b(o,n,r,s,h,g,i.handleBackground(n,r,s,h,e.background)),{x:n+f,y:r+l,w:s-f-d,h:h-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-c.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-c.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],a=n[1],c=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?u.shadow:t.shadow||l.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(o.shadowColor=g[3],o.shadowOffsetX=g[0]*r.dpr,o.shadowOffsetY=g[1]*r.dpr,o.shadowBlur=g[2],g[0]>0?c-=g[0]:(c+=g[0],s-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],a-=g[1])),b(o,s,a,c,f,i.getLength(t.borderRadius?t.borderRadius:l.borderRadius),i.handleBackground(s,a,c,f,t.background,d)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var h=i.cellImgs[e][r];if(!h)return!1;var c,l=d&&h.activeImg||h.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[s+i.getOffsetX(f,t.col),a+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),o.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&u.fontStyle?u.fontStyle:e.fontStyle||l.fontStyle,r=d&&u.fontWeight?u.fontWeight:e.fontWeight||l.fontWeight,c=d&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||l.fontSize),f=d&&u.lineHeight?u.lineHeight:e.lineHeight||l.lineHeight||e.fontSize||l.fontSize;o.font=r+" "+c+"px "+n,o.fillStyle=d&&u.fontColor?u.fontColor:e.fontColor||l.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:l.wordWrap){p=h(p);for(var m="",v=0;v<p.length;v++){m+=p[v],o.measureText(m).width>i.getWidth(e.lengthLimit||l.lengthLimit,t.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(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),a+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.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},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,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(z(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+I(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.currIndex=z(c,s,a,h.decelerationTime)%r.length,this.draw(),i(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],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},e.prototype.getWidth=function(t,e){return void 0===e&&(e=1),a(t,"number")?t:a(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),a(t,"number")?t:a(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}(g);t.LuckyGrid=x,t.LuckyWheel=S,Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var e=function(t,i){return(e=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])})(t,i)};function i(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var s=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},a=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),c=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){l(t,e,t[e])}))},l=function(t,e,i){var n=new h;c(i);Object.defineProperty(t,e,{get:function(){return h.target&&n.addSub(h.target),i},set:function(t){t!==i&&(i=t,c(t),n.notify())}})},u=0;var f=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=u++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){h.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){s(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),h.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),d=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.9"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return s(t,"number")?t:s(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&l(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new f(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),g=function(t){return Math.PI/180*t},p=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},m=function(t,e){var i=-t/e;return[i,-i*t+e]},v=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=g(180).toFixed(8)){var a=(r+n)/2;return o?(v(t,e,i,n,a,o),v(t,e,i,a,r,o)):(v(t,e,i,a,r,o),v(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=p(n,i),c=h[0],l=h[1],u=p(r,i),f=u[0],d=u[1],w=m(c,l),y=w[0],b=w[1],I=m(f,d),S=I[0],z=I[1],x=(z-b)/(y-S),T=(S*b-y*z)/(S-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?T=S*x+z:S!==1/0&&S!==-1/0||(T=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,T,f,d,i):e.quadraticCurveTo(x,T,f,d)},w=function(t,e,i,n,r,o,s,a){i||(i=s);var h=g(90/Math.PI/n*s),c=g(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,d=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,p(l,n)),v(t,e,n,l,u,!0),d>f?v(t,e,i,f,d,!1):e.lineTo.apply(e,p((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},y=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},b=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},I=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},S=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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.blockImgs=[[]],n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch(),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:n.buttons.map((function(t){return t.imgs}))}),n}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 n({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({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("blocks",(function(e,i){t.init({blockImgs:[]})}),{deep:!0}),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({prizeImgs:n})}),{deep:!0}),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({btnImgs:n})}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init({})})),this.$watch("endCallback",(function(){return t.init({})}))},e.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var s=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},a=0,h=0;this.draw(),Object.keys(t).forEach((function(e){var i=t[e],r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[e];i&&i.forEach((function(t,i){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,i,e,o,(function(){a++,h===a&&s.call(n)}))}))}))})),h||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i,n,s){return r(this,void 0,void 0,(function(){var r,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(r=this[t][e])&&r.imgs&&(a=r.imgs[n])?(this[i][e]||(this[i][e]=[]),h=this[i][e],c=n,[4,this.loadImg(a.src,a)]):[2];case 1:return h[c]=o.sent(),s.call(this),[2]}}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,h=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e,n){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),e.imgs&&e.imgs.forEach((function(e,r){if(i.blockImgs[n]){var s=i.blockImgs[n][r];if(s){var a,h=i.computedWidthAndHeight(s,e,2*t,2*t),c=h[0],l=h[1],u=[i.getOffsetX(c),i.getHeight(e.top,2*t)-t],f=u[0],d=u[1];["WEB","MINI-WX"].includes(i.config.flag)?a=s:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(a=s.path),o.save(),e.rotate&&o.rotate(g(i.rotateDeg)),o.drawImage(a,f,d,c,l),o.restore()}}})),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=g(this.prizeDeg);var c=g(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||h.lineHeight||t.fontSize||h.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?w(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(s.gutter),t.background||h.background);var d=Math.cos(n)*i.prizeRadius,p=Math.sin(n)*i.prizeRadius;o.translate(d,p),o.rotate(n+g(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,n=t.fontWeight||h.fontWeight,r=i.getLength(t.fontSize||h.fontSize),c=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:h.wordWrap){g=a(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||h.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(g(360)-n-g(90)),o.translate(-d,-p)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,r=t.fontWeight||h.fontWeight,s=i.getLength(t.fontSize||h.fontSize),a=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},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,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(I(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+b(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.rotateDeg=I(c,s,a,h.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))},e.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},e.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},e.prototype.getOffsetX=function(t){return-t/2},e}(d),z=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),n}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=n({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 n({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 n({background:"#ffce98",shadow:""},t.activeStyle)}))},e.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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this,o=r.config,a=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],s=i[2],c=i[3];a.beginPath(),a.rect(r,o,s,c),a.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;s(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},e.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(r.src,r)]):[2];case 1:return s[a]=(c.defaultImg=o.sent(),c),r.hasOwnProperty("activeSrc")?[4,this.loadImg(r.activeSrc,r)]:[3,3];case 2:h=o.sent(),this.cellImgs[t][e].activeImg=h,o.label=3;case 3:return i.call(this),[2]}}))}))},e.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)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,h=n._defaultConfig,c=n._defaultStyle,l=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,r.width,r.height),this.cells=function(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return 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(t,e){var n=t.x,r=t.y,a=t.w,h=t.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]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return y(o,n,r,a,h,g,i.handleBackground(n,r,a,h,e.background)),{x:n+f,y:r+l,w:a-f-d,h:h-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-h.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-h.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],h=n[1],u=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(o.shadowColor=g[3],o.shadowOffsetX=g[0]*r.dpr,o.shadowOffsetY=g[1]*r.dpr,o.shadowBlur=g[2],g[0]>0?u-=g[0]:(u+=g[0],s-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],h-=g[1])),y(o,s,h,u,f,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(s,h,u,f,t.background,d)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var a=i.cellImgs[e][r];if(!a)return!1;var c,l=d&&a.activeImg||a.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[s+i.getOffsetX(f,t.col),h+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),o.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=d&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,u=d&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=d&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+u+"px "+n,o.fillStyle=d&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:c.wordWrap){p=a(p);for(var m="",v=0;v<p.length;v++){m+=p[v],o.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.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(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),h+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.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},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,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(I(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+b(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.currIndex=I(c,s,a,h.decelerationTime)%r.length,this.draw(),i(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],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},e.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},e.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},e.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},e}(d);t.LuckyGrid=z,t.LuckyWheel=S,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "lucky-canvas",
"version": "1.2.8",
"version": "1.2.9",
"description": "一个基于原生 js 的(大转盘抽奖 / 九宫格抽奖)插件",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LuckyCanvas={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(t,i){return(e=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])})(t,i)};function i(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return n}var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},c=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),l=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){u(t,e,t[e])}))},u=function(t,e,i){var n=new c;l(i);Object.defineProperty(t,e,{get:function(){return c.target&&n.addSub(c.target),i},set:function(t){t!==i&&(i=t,l(t),n.notify())}})},f=0;var d=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=f++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){c.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){a(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),c.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),g=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.8"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return a(t,"number")?t:a(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&u(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new d(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),p=function(t){return Math.PI/180*t},m=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},v=function(t,e){var i=-t/e;return[i,-i*t+e]},w=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=p(180).toFixed(8)){var a=(r+n)/2;return o?(w(t,e,i,n,a,o),w(t,e,i,a,r,o)):(w(t,e,i,a,r,o),w(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=m(n,i),c=h[0],l=h[1],u=m(r,i),f=u[0],d=u[1],g=v(c,l),y=g[0],b=g[1],I=v(f,d),z=I[0],S=I[1],x=(S-b)/(y-z),C=(z*b-y*S)/(z-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?C=z*x+S:z!==1/0&&z!==-1/0||(C=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,C,f,d,i):e.quadraticCurveTo(x,C,f,d)},y=function(t,e,i,n,r,o,s,a){i||(i=s);var h=p(90/Math.PI/n*s),c=p(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,d=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,m(l,n)),w(t,e,n,l,u,!0),d>f?w(t,e,i,f,d,!1):e.lineTo.apply(e,m((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},b=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},I=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},z=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},S=function(t){function e(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 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 n({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({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,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)}),{deep:!0}),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(s(new Array(t.prizes.length).fill(void 0),n))}),{deep:!0}),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var s=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},h=0,c=0;a(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){c++,n.loadAndCacheImg(e,i,(function(){h++,c===h&&s.call(n)}))}))}))),c||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c,l;return o(this,(function(o){switch(o.label){case 0:return n=t<this.prizes.length,r=n?"prizes":"buttons",s=n?"prizeImgs":"btnImgs",t=n?t:t-this.prizes.length,(a=this[r][t])&&a.imgs?(h=a.imgs[e])?(this[s][t]||(this[s][t]=[]),c=this[s][t],l=e,[4,this.loadImg(h.src,h)]):[2]:[2];case 1:return c[l]=o.sent(),i.call(this),[2]}}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,a=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=p(this.prizeDeg);var c=p(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||a.lineHeight||t.fontSize||a.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?y(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(s.gutter),t.background||a.background);var d=Math.cos(n)*i.prizeRadius,g=Math.sin(n)*i.prizeRadius;o.translate(d,g),o.rotate(n+p(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,n=t.fontWeight||a.fontWeight,r=i.getLength(t.fontSize||a.fontSize),c=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:a.wordWrap){g=h(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||a.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(p(360)-n-p(90)),o.translate(-d,-g)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,r=t.fontWeight||a.fontWeight,s=i.getLength(t.fontSize||a.fontSize),h=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+h,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},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,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(z(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+I(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.rotateDeg=z(c,s,a,h.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))},e.prototype.getWidth=function(t,e){return void 0===e&&(e=this.prizeRadian*this.prizeRadius),a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},e.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},e.prototype.getOffsetX=function(t){return-t/2},e}(g),x=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),n}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=n({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 n({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 n({background:"#ffce98",shadow:""},t.activeStyle)}))},e.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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this,o=r.config,s=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],a=i[2],c=i[3];s.beginPath(),s.rect(r,o,a,c),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;a(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},e.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(r.src,r)]):[2];case 1:return s[a]=(c.defaultImg=o.sent(),c),r.hasOwnProperty("activeSrc")?[4,this.loadImg(r.activeSrc,r)]:[3,3];case 2:h=o.sent(),this.cellImgs[t][e].activeImg=h,o.label=3;case 3:return i.call(this),[2]}}))}))},e.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)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,c=n._defaultConfig,l=n._defaultStyle,u=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,r.width,r.height),this.cells=s(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(t,e){var n=t.x,r=t.y,s=t.w,h=t.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 s={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o};for(var h in s)s[h]=t.hasOwnProperty(h)&&a(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):s[h];return[i,n,r,o]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return b(o,n,r,s,h,g,i.handleBackground(n,r,s,h,e.background)),{x:n+f,y:r+l,w:s-f-d,h:h-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-c.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-c.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],a=n[1],c=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?u.shadow:t.shadow||l.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(o.shadowColor=g[3],o.shadowOffsetX=g[0]*r.dpr,o.shadowOffsetY=g[1]*r.dpr,o.shadowBlur=g[2],g[0]>0?c-=g[0]:(c+=g[0],s-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],a-=g[1])),b(o,s,a,c,f,i.getLength(t.borderRadius?t.borderRadius:l.borderRadius),i.handleBackground(s,a,c,f,t.background,d)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var h=i.cellImgs[e][r];if(!h)return!1;var c,l=d&&h.activeImg||h.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[s+i.getOffsetX(f,t.col),a+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),o.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&u.fontStyle?u.fontStyle:e.fontStyle||l.fontStyle,r=d&&u.fontWeight?u.fontWeight:e.fontWeight||l.fontWeight,c=d&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||l.fontSize),f=d&&u.lineHeight?u.lineHeight:e.lineHeight||l.lineHeight||e.fontSize||l.fontSize;o.font=r+" "+c+"px "+n,o.fillStyle=d&&u.fontColor?u.fontColor:e.fontColor||l.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:l.wordWrap){p=h(p);for(var m="",v=0;v<p.length;v++){m+=p[v],o.measureText(m).width>i.getWidth(e.lengthLimit||l.lengthLimit,t.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(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),a+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.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},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,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(z(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+I(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.currIndex=z(c,s,a,h.decelerationTime)%r.length,this.draw(),i(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],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},e.prototype.getWidth=function(t,e){return void 0===e&&(e=1),a(t,"number")?t:a(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),a(t,"number")?t:a(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}(g);t.LuckyGrid=x,t.LuckyWheel=S,Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var e=function(t,i){return(e=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])})(t,i)};function i(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var s=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},a=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(){function t(){this.subs=[]}return t.prototype.addSub=function(t){this.subs.includes(t)||this.subs.push(t)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}(),c=function(t){"object"==typeof t&&Object.keys(t).forEach((function(e){l(t,e,t[e])}))},l=function(t,e,i){var n=new h;c(i);Object.defineProperty(t,e,{get:function(){return h.target&&n.addSub(h.target),i},set:function(t){t!==i&&(i=t,c(t),n.notify())}})},u=0;var f=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=u++,this.vm=t,this.expr=e,this.deep=!!n.deep,this.getter="function"==typeof e?e:function(t){t+=".";for(var e=[],i="",n=0;n<t.length;n++){var r=t[n];if(/\[|\./.test(r))e.push(i),i="";else{if(/\W/.test(r))continue;i+=r}}return function(t){return e.reduce((function(t,e){return t[e]}),t)}}(e),this.cb=i,this.value=this.get()}return t.prototype.get=function(){h.target=this;var t=this.getter.call(this.vm,this.vm);return this.deep&&function(t){var e=function(t){s(t,"array","object")&&Object.keys(t).forEach((function(i){var n=t[i];e(n)}))};e(t)}(t),h.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.vm,t,e)},t}(),d=function(){function t(t){this.htmlFontSize=16,this.rAF=function(){},this.setTimeout=function(){},this.setInterval=function(){},this.clearInterval=function(){},this.setHTMLFontSize(),"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el));var e=0,i=0;t.divElement&&(e=t.divElement.offsetWidth,i=t.divElement.offsetHeight,t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.width=this.getLength(t.width)||e,t.height=this.getLength(t.height)||i,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=t.width+"px",t.divElement.style.height=t.height+"px"),t.canvasElement&&(t.canvasElement.setAttribute("package","lucky-canvas@1.2.9"),t.ctx=t.canvasElement.getContext("2d")),this.ctx=t.ctx,t.ctx&&t.width&&t.height?(this.setDpr(),this.initWindowFunction()):console.error("无法获取到 CanvasContext2D 或宽高")}return t.prototype.setDpr=function(){var t=this.config;t.dpr||(window?window.dpr=t.dpr=window.devicePixelRatio||1:t.dpr||console.error(t,"未传入 dpr 可能会导致绘制异常"))},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.initWindowFunction=function(){if(window)return this.rAF=window.requestAnimationFrame,this.setInterval=window.setInterval,void(this.clearInterval=window.clearInterval);if(this.config.rAF)this.rAF=this.config.rAF;else if(this.config.setTimeout){var t=this.config.setTimeout;this.rAF=function(e){return t(e,16)}}else this.rAF=function(t){return setTimeout(t,16)}},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=function(t){return(t*n-t)/(t*n)*(n/2)*100};i&&(i.width=t.width*n,i.height=t.height*n,i.style.width=i.width+"px",i.style.height=i.height+"px",i.style.transform="scale("+1/n+") translate(\n "+-r(i.width)+"%, "+-r(i.height)+"%\n )",e.scale(n,n))},t.prototype.loadImg=function(t,e){var i=this;return new Promise((function(n){if("WEB"===i.config.flag){var r=new Image;r.src=t,r.onload=function(){return n(r)}}else e.$resolve=n}))},t.prototype.getLength=function(t){return s(t,"number")?t:s(t,"string")?this.changeUnits(t):0},t.prototype.changeUnits=function(t,e){var i=this;return void 0===e&&(e=1),Number(t.replace(/^(\-*[0-9.]*)([a-z%]*)$/,(function(t,n,r){var o={"%":function(t){return t*(e/100)},px:function(t){return 1*t},rem:function(t){return t*i.htmlFontSize}}[r];if(o)return o(n);var s=i.config.unitFunc;return s?s(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&l(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new f(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),g=function(t){return Math.PI/180*t},p=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},m=function(t,e){var i=-t/e;return[i,-i*t+e]},v=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=g(180).toFixed(8)){var a=(r+n)/2;return o?(v(t,e,i,n,a,o),v(t,e,i,a,r,o)):(v(t,e,i,a,r,o),v(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=p(n,i),c=h[0],l=h[1],u=p(r,i),f=u[0],d=u[1],w=m(c,l),y=w[0],b=w[1],I=m(f,d),S=I[0],z=I[1],x=(z-b)/(y-S),T=(S*b-y*z)/(S-y);isNaN(x)&&(Math.abs(c)===+i.toFixed(8)&&(x=c),Math.abs(f)===+i.toFixed(8)&&(x=f)),y===1/0||y===-1/0?T=S*x+z:S!==1/0&&S!==-1/0||(T=y*x+b),e.lineTo(c,l),["WEB","UNI-H5"].includes(t)?e.arcTo(x,T,f,d,i):e.quadraticCurveTo(x,T,f,d)},w=function(t,e,i,n,r,o,s,a){i||(i=s);var h=g(90/Math.PI/n*s),c=g(90/Math.PI/i*s),l=r+h,u=o-h,f=r+c,d=o-c;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,p(l,n)),v(t,e,n,l,u,!0),d>f?v(t,e,i,f,d,!1):e.lineTo.apply(e,p((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},y=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.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},b=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},I=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},S=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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.blockImgs=[[]],n.prizeImgs=[[]],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch(),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:n.buttons.map((function(t){return t.imgs}))}),n}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 n({gutter:"0px",offsetDegree:0,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({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("blocks",(function(e,i){t.init({blockImgs:[]})}),{deep:!0}),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({prizeImgs:n})}),{deep:!0}),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({btnImgs:n})}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init({})})),this.$watch("endCallback",(function(){return t.init({})}))},e.prototype.init=function(t){var e,i,n=this,r=this.config,o=this.ctx;this.setDpr(),this.setHTMLFontSize(),this.zoomCanvas(),null===(e=r.beforeInit)||void 0===e||e.call(this),this.Radius=Math.min(r.width,r.height)/2,o.translate(this.Radius,this.Radius);var s=function(){n.draw(),r.canvasElement&&(r.canvasElement.onclick=function(t){var e;o.beginPath(),o.arc(0,0,n.maxBtnRadius,0,2*Math.PI,!1),o.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},a=0,h=0;this.draw(),Object.keys(t).forEach((function(e){var i=t[e],r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[e];i&&i.forEach((function(t,i){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,i,e,o,(function(){a++,h===a&&s.call(n)}))}))}))})),h||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i,n,s){return r(this,void 0,void 0,(function(){var r,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(r=this[t][e])&&r.imgs&&(a=r.imgs[n])?(this[i][e]||(this[i][e]=[]),h=this[i][e],c=n,[4,this.loadImg(a.src,a)]):[2];case 1:return h[c]=o.sent(),s.call(this),[2]}}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,h=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e,n){return o.beginPath(),o.fillStyle=e.background,o.arc(0,0,t,0,2*Math.PI,!1),o.fill(),e.imgs&&e.imgs.forEach((function(e,r){if(i.blockImgs[n]){var s=i.blockImgs[n][r];if(s){var a,h=i.computedWidthAndHeight(s,e,2*t,2*t),c=h[0],l=h[1],u=[i.getOffsetX(c),i.getHeight(e.top,2*t)-t],f=u[0],d=u[1];["WEB","MINI-WX"].includes(i.config.flag)?a=s:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(a=s.path),o.save(),e.rotate&&o.rotate(g(i.rotateDeg)),o.drawImage(a,f,d,c,l),o.restore()}}})),t-i.getLength(e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=g(this.prizeDeg);var c=g(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},u=function(t,e,n){var r=t.lineHeight||h.lineHeight||t.fontSize||h.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,f=i.prizeRadius-i.maxBtnRadius;!function(t,e,i,n,r,o,s,a){s?w(t,e,i,n,r,o,s,a):(e.beginPath(),e.fillStyle=a,e.moveTo(0,0),e.arc(0,0,n,r,o,!1),e.closePath(),e.fill())}(r.flag,o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(s.gutter),t.background||h.background);var d=Math.cos(n)*i.prizeRadius,p=Math.sin(n)*i.prizeRadius;o.translate(d,p),o.rotate(n+g(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var s,a=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,f),h=a[0],c=a[1],l=[i.getOffsetX(h),i.getHeight(t.top,f)],u=l[0],d=l[1];["WEB","MINI-WX"].includes(i.config.flag)?s=r:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(s=r.path),o.drawImage(s,u,d,h,c)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,n=t.fontWeight||h.fontWeight,r=i.getLength(t.fontSize||h.fontSize),c=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=n+" "+r+"px "+c;var d=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:h.wordWrap){g=a(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,w=(i.prizeRadius-u(t,f,d.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||h.lengthLimit,w)&&(d.push(p.slice(0,-1)),p=g[m])}p&&d.push(p),d.length||d.push(g)}else d=g.split("\n");d.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),u(t,f,i))}))})),o.rotate(g(360)-n-g(90)),o.translate(-d,-p)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),o.beginPath(),o.fillStyle=t.background||"#fff",o.arc(0,0,n,0,2*Math.PI,!1),o.fill(),t.pointer&&(o.beginPath(),o.fillStyle=t.background||"#fff",o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(r,s){if(i.btnImgs[e]){var a=i.btnImgs[e][s];if(a){var h,c=i.computedWidthAndHeight(a,r,2*i.getHeight(t.radius),2*i.getHeight(t.radius)),l=c[0],u=c[1],f=[i.getOffsetX(l),i.getHeight(r.top,n)],d=f[0],g=f[1];["WEB","MINI-WX"].includes(i.config.flag)?h=a:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(h=a.path),o.drawImage(h,d,g,l,u)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||h.fontColor,r=t.fontWeight||h.fontWeight,s=i.getLength(t.fontSize||h.fontSize),a=t.fontStyle||h.fontStyle;o.fillStyle=e,o.font=r+" "+s+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),u(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},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,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(I(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+b(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.rotateDeg=I(c,s,a,h.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))},e.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},e.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},e.prototype.getOffsetX=function(t){return-t/2},e}(d),z=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;return 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(),n.init(n.collectImg()),n}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=n({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 n({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 n({background:"#ffce98",shadow:""},t.activeStyle)}))},e.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)}),{deep:!0}),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)}),{deep:!0}),this.$watch("rows",(function(){return t.init(t.collectImg())})),this.$watch("cols",(function(){return t.init(t.collectImg())})),this.$watch("blocks",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("activeStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("startCallback",(function(){return t.init([])})),this.$watch("endCallback",(function(){return t.init([])}))},e.prototype.init=function(t){var e,i,n=this,r=this,o=r.config,a=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var c=function(){n.draw(),n.demo&&n.walk(),h&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([h.x,h.y,h.col||1,h.row||1]),r=i[0],o=i[1],s=i[2],c=i[3];a.beginPath(),a.rect(r,o,s,c),a.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},l=0,u=0;s(t,"array")&&(this.draw(),t.forEach((function(t,e){if(!t)return!1;t.forEach((function(t,i){u++,n.loadAndCacheImg(e,i,(function(){l++,u===l&&c.call(n)}))}))}))),u||c.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},e.prototype.collectImg=function(){var t=[[]];return this.prizes&&(t=this.prizes.map((function(t){return t.imgs}))),this.button&&(t[this.cols*this.rows-1]=this.button.imgs),t},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n,r,s,a,h,c;return o(this,(function(o){switch(o.label){case 0:return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),s=this.cellImgs[t],a=e,c={},[4,this.loadImg(r.src,r)]):[2];case 1:return s[a]=(c.defaultImg=o.sent(),c),r.hasOwnProperty("activeSrc")?[4,this.loadImg(r.activeSrc,r)]:[3,3];case 2:h=o.sent(),this.cellImgs[t][e].activeImg=h,o.label=3;case 3:return i.call(this),[2]}}))}))},e.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)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,h=n._defaultConfig,c=n._defaultStyle,l=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,r.width,r.height),this.cells=function(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),r=0;for(e=0;e<i;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,r++)n[r]=o[s];return 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(t,e){var n=t.x,r=t.y,a=t.w,h=t.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]}(e).map((function(t){return~~t})),l=c[0],u=c[1],f=c[2],d=c[3],g=e.borderRadius?i.getLength(e.borderRadius):0;return y(o,n,r,a,h,g,i.handleBackground(n,r,a,h,e.background)),{x:n+f,y:r+l,w:a-f-d,h:h-l-u}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-h.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-h.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],h=n[1],u=n[2],f=n[3],d=e===i.currIndex%i.prizes.length>>0,g=(d?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===g.length&&(o.shadowColor=g[3],o.shadowOffsetX=g[0]*r.dpr,o.shadowOffsetY=g[1]*r.dpr,o.shadowBlur=g[2],g[0]>0?u-=g[0]:(u+=g[0],s-=g[0]),g[1]>0?f-=g[1]:(f+=g[1],h-=g[1])),y(o,s,h,u,f,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(s,h,u,f,t.background,d)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0,t.imgs&&t.imgs.forEach((function(n,r){if(!i.cellImgs[e])return!1;var a=i.cellImgs[e][r];if(!a)return!1;var c,l=d&&a.activeImg||a.defaultImg,u=i.computedWidthAndHeight(l,n,t),f=u[0],g=u[1],p=[s+i.getOffsetX(f,t.col),h+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=l:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=l.path),o.drawImage(c,m,v,f,g)})),t.fonts&&t.fonts.forEach((function(e){var n=d&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=d&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,u=d&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=d&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+u+"px "+n,o.fillStyle=d&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var g=[],p=String(e.text);if(e.hasOwnProperty("wordWrap")?e.wordWrap:c.wordWrap){p=a(p);for(var m="",v=0;v<p.length;v++){m+=p[v],o.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.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(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),h+i.getHeight(e.top,t.row)+(r+1)*i.getLength(f))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.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},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,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(I(this.FPS,this.stopIndex,l,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=l;break}}return this.slowDown()}this.currIndex=(n+b(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))},e.prototype.slowDown=function(){var t,e=this,i=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,n({},r.find((function(t,e){return e===o})))));this.currIndex=I(c,s,a,h.decelerationTime)%r.length,this.draw(),i(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],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},e.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},e.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},e.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},e}(d);t.LuckyGrid=z,t.LuckyWheel=S,Object.defineProperty(t,"__esModule",{value:!0})}));

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc