lucky-canvas
Advanced tools
Comparing version 1.3.4 to 1.4.0
@@ -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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(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(a,s)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}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,s])}}}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}))},a=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},s=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},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}(),l="__proto__"in{};function c(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var u=Array.prototype,f=Object.create(u);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){f[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=u[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var d=function(){function t(t){this.dep=new h,c(t,"__luckyOb__",this),Array.isArray(t)&&(l?t.__proto__=f:Object.getOwnPropertyNames(f).forEach((function(e){c(t,e,f[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){p(t,e,t[e])}))},t}();function g(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new d(t)}function p(t,e,i){var n=new h,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=g(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return h.target&&(n.addSub(h.target),s&&s.dep.addSub(h.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=g(e),n.notify()))}})}}var m=0,v=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=m++,this.$lucky=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.$lucky,this.$lucky);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),h.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),w=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.3.4"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},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 a=i.config.unitFunc;return a?a(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&p(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 v(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),y=function(t){return Math.PI/180*t},b=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},I=function(t,e){var i=-t/e;return[i,-i*t+e]},S=function(t,e,i,n,r,o){var a;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=y(180).toFixed(8)){var s=(r+n)/2;return o?(S(t,e,i,n,s,o),S(t,e,i,s,r,o)):(S(t,e,i,s,r,o),S(t,e,i,n,s,o)),!1}o||(n=(a=[r,n])[0],r=a[1]);var h=b(n,i),l=h[0],c=h[1],u=b(r,i),f=u[0],d=u[1],g=I(l,c),p=g[0],m=g[1],v=I(f,d),w=v[0],z=v[1],x=(z-m)/(p-w),k=(w*m-p*z)/(w-p);isNaN(x)&&(Math.abs(l)===+i.toFixed(8)&&(x=l),Math.abs(f)===+i.toFixed(8)&&(x=f)),p===1/0||p===-1/0?k=w*x+z:w!==1/0&&w!==-1/0||(k=p*x+m),e.lineTo(l,c),["WEB","UNI-H5"].includes(t)?e.arcTo(x,k,f,d,i):e.quadraticCurveTo(x,k,f,d)},z=function(t,e,i,n,r,o,a,s){i||(i=a);var h=y(90/Math.PI/n*a),l=y(90/Math.PI/i*a),c=r+h,u=o-h,f=r+l,d=o-l;e.beginPath(),e.fillStyle=s,e.moveTo.apply(e,b(c,n)),S(t,e,n,c,u,!0),d>f?S(t,e,i,f,d,!1):e.lineTo.apply(e,b((r+o)/2,a/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},x=function(t,e,i,n,r,o,a){var s=Math.min(n,r);o>s/2&&(o=s/2),t.beginPath(),t.fillStyle=a,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()},k=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},C=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},T=function(t){function h(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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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(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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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))})},s=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(){s++,h===s&&a.call(n)}))}))}))})),h||a.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},h.prototype.loadAndCacheImg=function(t,e,i,o,a){return n(this,void 0,void 0,(function(){var n,s,h,l;return r(this,(function(r){switch(r.label){case 0:return(n=this[t][e])&&n.imgs&&(s=n.imgs[o])?(this[i][e]||(this[i][e]=[]),h=this[i][e],l=o,[4,this.loadImg(s.src,s)]):[2];case 1:return h[l]=r.sent(),a.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.drawImage=function(t,e,i,n,r){var o,a=this.ctx,s=this.config,h=this.computedWidthAndHeight(t,e,i,n),l=h[0],c=h[1];["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,this.getOffsetX(l),r,l,c)},h.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,h=n._defaultConfig,l=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 s(e.background)&&(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 a=i.blockImgs[n][r];a&&(o.save(),e.rotate&&o.rotate(y(i.rotateDeg)),i.drawImage(a,e,2*t,2*t,i.getHeight(e.top,2*t)-t),o.restore())}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=y(this.prizeDeg);var c=y(-90+this.rotateDeg+h.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||l.lineHeight||t.fontSize||l.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||l.background;s(g)&&function(t,e,i,n,r,o,a,s){a?z(t,e,i,n,r,o,a,s):(e.beginPath(),e.fillStyle=s,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(h.gutter),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+y(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];r&&i.drawImage(r,t,i.prizeRadian*i.prizeRadius,d,i.getHeight(t.top,d))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,n=t.fontWeight||l.fontWeight,r=i.getLength(t.fontSize||l.fontSize),s=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+s;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:l.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-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(h.gutter);v>i.getWidth(t.lengthLimit||l.lengthLimit,w)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),f(t,d,i))}))})),o.rotate(y(360)-n-y(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),s(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&s(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];o&&i.drawImage(o,t,2*n,2*n,i.getHeight(t.top,n))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,r=t.fontWeight||l.fontWeight,a=i.getLength(t.fontSize||l.fontSize),s=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=r+" "+(a>>0)+"px "+s,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),f(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,a=e._defaultConfig,s=Date.now()-this.startTime;if(s>=a.accelerationTime&&void 0!==n){this.FPS=s/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var l=360*h-n*r-o-a.offsetDegree;if(C(this.FPS,this.stopDeg,l,a.decelerationTime)-this.stopDeg>a.speed){this.endDeg=l;break}}return this.slowDown()}this.rotateDeg=(o+k(s,0,a.speed,a.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,a=e.stopDeg,s=e.endDeg,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>=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=C(l,a,s,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),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},h.prototype.getOffsetX=function(t){return-t/2},h}(w),W=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",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){return t.init(e.map((function(t){return t.imgs})))}),{deep:!0}),this.$watch("button",(function(e,i){var n=[];return n[t.cols*t.rows-1]=e.imgs,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,a=r.config,s=r.ctx,h=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=a.beforeInit)||void 0===e||e.call(this);var l=function(){n.draw(),n.demo&&n.walk(),h&&a.canvasElement&&(a.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],l=i[3];s.beginPath(),s.rect(r,o,a,l),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},c=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(){c++,u===c&&l.call(n)}))}))}))),u||l.call(this),null===(i=a.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,a,s,h=this;return r(this,(function(r){return(n=this.cells[t])&&n.imgs?(o=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),this.cellImgs[t][e]||(this.cellImgs[t][e]={}),a=1,s=0,this.loadImg(o.src,o).then((function(n){h.cellImgs[t][e].defaultImg=n,a===++s&&i.call(h)})),o.hasOwnProperty("activeSrc")&&(a++,this.loadImg(o.activeSrc,o,"$activeResolve").then((function(n){h.cellImgs[t][e].activeImg=n,a===++s&&i.call(h)}))),[2]):[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,l=n._defaultConfig,c=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=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],a=0,s=o.length;a<s;a++,r++)n[r]=o[a];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,l=t.h,u=function(t){var e=t.padding.replace(/px/g,"").split(" ").map((function(t){return~~t}))||[0],i=0,n=0,r=0,a=0;switch(e.length){case 1:i=n=r=a=e[0];break;case 2:i=n=e[0],r=a=e[1];break;case 3:i=e[0],r=a=e[1],n=e[2];break;default:i=e[0],n=e[1],r=e[2],a=e[3]}var s={paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:a};for(var h in s)s[h]=t.hasOwnProperty(h)&&o(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):s[h];return[i,n,r,a]}(e).map((function(t){return~~t})),f=u[0],d=u[1],g=u[2],p=u[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return s(v)&&x(h,n,r,a,l,m,i.handleBackground(n,r,a,l,v)),{x:n+g,y:r+f,w:a-g-p,h:l-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-l.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-l.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],l=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?u.background:t.background||c.background;if(s(p)){var m=(g?u.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(h.shadowColor=m[3],h.shadowOffsetX=m[0]*r.dpr,h.shadowOffsetY=m[1]*r.dpr,h.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],o-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],l-=m[1])),x(h,o,l,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(o,l,f,d,p)),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 s=g&&a.activeImg||a.defaultImg;if(s){var c,u=i.computedWidthAndHeight(s,n,t),f=u[0],d=u[1],p=[o+i.getOffsetX(f,t.col),l+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=s:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=s.path),h.drawImage(c,m,v,f,d)}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&u.fontStyle?u.fontStyle:e.fontStyle||c.fontStyle,r=g&&u.fontWeight?u.fontWeight:e.fontWeight||c.fontWeight,s=g&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&u.lineHeight?u.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;h.font=r+" "+(s>>0)+"px "+n,h.fillStyle=g&&u.fontColor?u.fontColor:e.fontColor||c.fontColor;var d=[],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],h.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){h.fillText(n,o+i.getOffsetX(h.measureText(n).width,t.col),l+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){var o=this.ctx;return r.includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var a=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),s=a.shift(),h=[0,0,0,0];if(s.includes("deg")){var l=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?h=[e,i+r,e+n,i+r-n*l(s-0)]:s>=45&&s<90?h=[e,i+r,e+n-r*l(s-45),i]:s>=90&&s<135?h=[e+n,i+r,e+n-r*l(s-90),i]:s>=135&&s<180?h=[e+n,i+r,e,i+n*l(s-135)]:s>=180&&s<225?h=[e+n,i,e,i+n*l(s-180)]:s>=225&&s<270?h=[e+n,i,e+r*l(s-225),i+r]:s>=270&&s<315?h=[e,i,e+r*l(s-270),i+r]:s>=315&&s<360&&(h=[e,i,e+n,i+r-n*l(s-315)])}else s.includes("top")?h=[e,i+r,e,i]:s.includes("bottom")?h=[e,i,e,i+r]:s.includes("left")?h=[e+n,i,e,i]:s.includes("right")&&(h=[e,i,e+n,i]);var c=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return a.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}),c)}(o,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,a=e.startTime,s=e._defaultConfig,h=Date.now()-a;if(h>=s.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var l=0;++l;){var c=r.length*l+o-(n>>0);if(C(this.FPS,this.stopIndex,c,s.decelerationTime)-this.stopIndex>s.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+k(h,.1,s.speed,s.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,a=e.stopIndex,s=e.endIndex,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>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=C(l,a,s,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,a=this.cellHeight,s=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+s)*e,this.prizeArea.y+(a+s)*i];return n&&r&&h.push(o*n+s*(n-1),a*r+s*(r-1)),h},h.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},h.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},h.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},h}(w);exports.LuckyGrid=W,exports.LuckyWheel=T; | ||
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(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},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}(),u="__proto__"in{};function c(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var l=Array.prototype,f=Object.create(l);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){f[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=l[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var d=function(){function t(t){this.dep=new h,c(t,"__luckyOb__",this),Array.isArray(t)&&(u?t.__proto__=f:Object.getOwnPropertyNames(f).forEach((function(e){c(t,e,f[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){p(t,e,t[e])}))},t}();function g(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new d(t)}function p(t,e,i){var n=new h,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,s=r&&r.set;o&&!s||2!==arguments.length||(i=t[e]);var a=g(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return h.target&&(n.addSub(h.target),a&&a.dep.addSub(h.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=g(e),n.notify()))}})}}var m=0,v=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=m++,this.$lucky=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.$lucky,this.$lucky);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),h.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),b=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.4.0"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},t.prototype.drawImage=function(t,e,i,n,r){var o,s=this.config,a=this.ctx;return["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,e,i,n,r)},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&&p(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 v(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),w=function(t){return Math.PI/180*t},y=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},I=function(t,e){var i=-t/e;return[i,-i*t+e]},z=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=w(180).toFixed(8)){var a=(r+n)/2;return o?(z(t,e,i,n,a,o),z(t,e,i,a,r,o)):(z(t,e,i,a,r,o),z(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=y(n,i),u=h[0],c=h[1],l=y(r,i),f=l[0],d=l[1],g=I(u,c),p=g[0],m=g[1],v=I(f,d),b=v[0],S=v[1],k=(S-m)/(p-b),x=(b*m-p*S)/(b-p);isNaN(k)&&(Math.abs(u)===+i.toFixed(8)&&(k=u),Math.abs(f)===+i.toFixed(8)&&(k=f)),p===1/0||p===-1/0?x=b*k+S:b!==1/0&&b!==-1/0||(x=p*k+m),e.lineTo(u,c),["WEB","UNI-H5"].includes(t)?e.arcTo(k,x,f,d,i):e.quadraticCurveTo(k,x,f,d)},S=function(t,e,i,n,r,o,s,a){i||(i=s);var h=w(90/Math.PI/n*s),u=w(90/Math.PI/i*s),c=r+h,l=o-h,f=r+u,d=o-u;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,y(c,n)),z(t,e,n,c,l,!0),d>f?z(t,e,i,f,d,!1):e.lineTo.apply(e,y((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},k=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()},x=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},C=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},T=function(t){function h(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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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(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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},h.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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 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=e,r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i],o=t[i];o&&o.forEach((function(t,e){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,e,i,o,(function(){a++,h===a&&s.call(n)}))}))}))})),h||s.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},h.prototype.loadAndCacheImg=function(t,e,i,o,s){return n(this,void 0,void 0,(function(){var n,a,h,u;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],u=o,[4,this.loadImg(a.src,a)]):[2];case 1:return h[u]=r.sent(),s.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,h=n._defaultConfig,u=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 a(e.background)&&(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=i.computedWidthAndHeight(s,e,2*t,2*t),h=a[0],u=a[1],c=[i.getOffsetX(h),i.getHeight(e.top,2*t)-t],l=c[0],f=c[1];o.save(),e.rotate&&o.rotate(w(i.rotateDeg)),i.drawImage(s,l,f,h,u),o.restore()}}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=w(this.prizeDeg);var c=w(-90+this.rotateDeg+h.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||u.lineHeight||t.fontSize||u.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||u.background;a(g)&&function(t,e,i,n,r,o,s,a){s?S(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(h.gutter),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+w(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var o=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,d),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,d)],u=h[0],c=h[1];i.drawImage(r,u,c,s,a)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,n=t.fontWeight||u.fontWeight,r=i.getLength(t.fontSize||u.fontSize),a=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+a;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:u.wordWrap){g=s(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,b=(i.prizeRadius-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(h.gutter);v>i.getWidth(t.lengthLimit||u.lengthLimit,b)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),f(t,d,i))}))})),o.rotate(w(360)-n-w(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),a(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&a(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];if(o){var s=i.computedWidthAndHeight(o,t,2*n,2*n),a=s[0],h=s[1],u=[i.getOffsetX(a),i.getHeight(t.top,n)],c=u[0],l=u[1];i.drawImage(o,c,l,a,h)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,r=t.fontWeight||u.fontWeight,s=i.getLength(t.fontSize||u.fontSize),a=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=r+" "+(s>>0)+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),f(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 u=360*h-n*r-o-s.offsetDegree;if(C(this.FPS,this.stopDeg,u,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=u;break}}return this.slowDown()}this.rotateDeg=(o+x(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,u=Date.now()-this.endTime;if(u>=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=C(u,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),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},h.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),o(t,"number")?t:o(t,"string")?this.changeUnits(t,e):0},h.prototype.getOffsetX=function(t){return-t/2},h}(b),E=function(t){function h(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.FPS=16.6,n.cells=[],n.blockImgs=[[]],n.prizeImgs=[],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=n.buttons.map((function(t){return t.imgs}));return n.button&&r.push(n.button.imgs),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:r}),n}return e(h,t),h.prototype.initData=function(t){this.$set(this,"rows",Number(t.rows)||3),this.$set(this,"cols",Number(t.cols)||3),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"buttons",t.buttons||[]),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:"sans-serif",fontWeight:"400",background:"transparent",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("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=t.buttons.map((function(t){return t.imgs}));return t.button&&i.push(t.button.imgs),t.init({btnImgs:i})}),{deep:!0}),this.$watch("button",(function(){var e=t.buttons.map((function(t){return t.imgs}));return t.button&&e.push(t.button.imgs),t.init({btnImgs:e})}),{deep:!0}),this.$watch("rows",(function(){return t.init({})})),this.$watch("cols",(function(){return t.init({})})),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,s=r.ctx,a=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var h=function(){n.draw(),n.demo&&n.walk(),n.buttons.length&&o.canvasElement&&(o.canvasElement.onclick=function(t){n.buttons.forEach((function(e){var i,r=n.getGeometricProperty([e.x,e.y,e.col||1,e.row||1]),o=r[0],a=r[1],h=r[2],u=r[3];s.beginPath(),s.rect(o,a,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(i=n.startCallback)||void 0===i||i.call(n,t))}))}),a&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([a.x,a.y,a.col||1,a.row||1]),r=i[0],o=i[1],h=i[2],u=i[3];s.beginPath(),s.rect(r,o,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},u=0,c=0;this.draw(),Object.keys(t).forEach((function(e){var i=e,r=t[i],o={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i];r&&r.forEach((function(t,e){t&&t.forEach((function(t,r){c++,n.loadAndCacheImg(o,e,i,r,(function(){u++,c===u&&h.call(n)}))}))}))})),c||h.call(this),null===(i=o.afterInit)||void 0===i||i.call(this)},h.prototype.loadAndCacheImg=function(t,e,i,o,s){return n(this,void 0,void 0,(function(){var n,a,h,u,c,l,f,d=this;return r(this,(function(r){switch(r.label){case 0:return n=this[t][e],"buttons"===t&&!this.buttons.length&&this.button&&(n=this.button),n&&n.imgs?(a=n.imgs[o])?(this[i][e]||(this[i][e]=[]),"blockImgs"!==i&&"btnImgs"!==i?[3,2]:(h=this[i][e],u=o,f={},[4,this.loadImg(a.src,a)])):[2]:[2];case 1:return h[u]=(f.defaultImg=r.sent(),f),[2,s.call(this)];case 2:return this.prizeImgs[e][o]||(this.prizeImgs[e][o]={}),c=1,l=0,this.loadImg(a.src,a).then((function(t){d.prizeImgs[e][o].defaultImg=t,c===++l&&s.call(d)})),a.hasOwnProperty("activeSrc")&&(c++,this.loadImg(a.activeSrc,a,"$activeResolve").then((function(t){d.prizeImgs[e][o].activeImg=t,c===++l&&s.call(d)}))),[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,u=n._defaultConfig,c=n._defaultStyle,l=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,h),h.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.buttons),this.button&&this.cells.push(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,u=t.h,l=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})),f=l[0],d=l[1],g=l[2],p=l[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return a(v)&&k(h,n,r,s,u,m,i.handleBackground(n,r,s,u,v)),{x:n+g,y:r+f,w:s-g-p,h:u-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-u.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-u.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],u=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?l.background:t.background||c.background;if(a(p)){var m=(g?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(h.shadowColor=m[3],h.shadowOffsetX=m[0]*r.dpr,h.shadowOffsetY=m[1]*r.dpr,h.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],o-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],u-=m[1])),k(h,o,u,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(o,u,f,d,p)),h.shadowColor="rgba(0, 0, 0, 0)",h.shadowOffsetX=0,h.shadowOffsetY=0,h.shadowBlur=0}var v="prizeImgs";e>=i.prizes.length&&(v="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[v][e]){var s=i[v][e][r];if(s){var a=g&&s.activeImg||s.defaultImg;if(a){var h=i.computedWidthAndHeight(a,n,t),c=h[0],l=h[1],f=[o+i.getOffsetX(c,t.col),u+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(a,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=g&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,a=g&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;h.font=r+" "+(a>>0)+"px "+n,h.fillStyle=g&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var d=[],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],h.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){h.fillText(n,o+i.getOffsetX(h.measureText(n).width,t.col),u+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){var o=this.ctx;return r.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 u=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*u(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*u(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*u(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*u(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*u(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*u(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*u(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*u(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 c=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}),c)}(o,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 u=0;++u;){var c=r.length*u+o-(n>>0);if(C(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+x(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,u=Date.now()-this.endTime;if(u>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=C(u,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),o(t,"number")?t:o(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),o(t,"number")?t:o(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}(b);exports.LuckyGrid=E,exports.LuckyWheel=T; |
@@ -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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(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(a,s)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}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,s])}}}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 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}))},s=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=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="__proto__"in{};function u(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var f=Array.prototype,d=Object.create(f);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){d[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=f[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var g=function(){function t(t){this.dep=new l,u(t,"__luckyOb__",this),Array.isArray(t)&&(c?t.__proto__=d:Object.getOwnPropertyNames(d).forEach((function(e){u(t,e,d[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){m(t,e,t[e])}))},t}();function p(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new g(t)}function m(t,e,i){var n=new l,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=p(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return l.target&&(n.addSub(l.target),s&&s.dep.addSub(l.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=p(e),n.notify()))}})}}var v=0,w=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=v++,this.$lucky=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(){l.target=this;var t=this.getter.call(this.$lucky,this.$lucky);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),l.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),y=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.3.4"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},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 a=i.config.unitFunc;return a?a(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&m(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 w(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),b=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},S=function(t,e){var i=-t/e;return[i,-i*t+e]},z=function(t,e,i,n,r,o){var a;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=b(180).toFixed(8)){var s=(r+n)/2;return o?(z(t,e,i,n,s,o),z(t,e,i,s,r,o)):(z(t,e,i,s,r,o),z(t,e,i,n,s,o)),!1}o||(n=(a=[r,n])[0],r=a[1]);var h=I(n,i),l=h[0],c=h[1],u=I(r,i),f=u[0],d=u[1],g=S(l,c),p=g[0],m=g[1],v=S(f,d),w=v[0],y=v[1],x=(y-m)/(p-w),k=(w*m-p*y)/(w-p);isNaN(x)&&(Math.abs(l)===+i.toFixed(8)&&(x=l),Math.abs(f)===+i.toFixed(8)&&(x=f)),p===1/0||p===-1/0?k=w*x+y:w!==1/0&&w!==-1/0||(k=p*x+m),e.lineTo(l,c),["WEB","UNI-H5"].includes(t)?e.arcTo(x,k,f,d,i):e.quadraticCurveTo(x,k,f,d)},x=function(t,e,i,n,r,o,a,s){i||(i=a);var h=b(90/Math.PI/n*a),l=b(90/Math.PI/i*a),c=r+h,u=o-h,f=r+l,d=o-l;e.beginPath(),e.fillStyle=s,e.moveTo.apply(e,I(c,n)),z(t,e,n,c,u,!0),d>f?z(t,e,i,f,d,!1):e.lineTo.apply(e,I((r+o)/2,a/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},k=function(t,e,i,n,r,o,a){var s=Math.min(n,r);o>s/2&&(o=s/2),t.beginPath(),t.fillStyle=a,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()},C=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},T=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},W=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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 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))})},s=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(){s++,h===s&&a.call(n)}))}))}))})),h||a.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i,n,a){return r(this,void 0,void 0,(function(){var r,s,h,l;return o(this,(function(o){switch(o.label){case 0:return(r=this[t][e])&&r.imgs&&(s=r.imgs[n])?(this[i][e]||(this[i][e]=[]),h=this[i][e],l=n,[4,this.loadImg(s.src,s)]):[2];case 1:return h[l]=o.sent(),a.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.drawImage=function(t,e,i,n,r){var o,a=this.ctx,s=this.config,h=this.computedWidthAndHeight(t,e,i,n),l=h[0],c=h[1];["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,this.getOffsetX(l),r,l,c)},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,a=n._defaultConfig,l=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 h(e.background)&&(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 a=i.blockImgs[n][r];a&&(o.save(),e.rotate&&o.rotate(b(i.rotateDeg)),i.drawImage(a,e,2*t,2*t,i.getHeight(e.top,2*t)-t),o.restore())}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=b(this.prizeDeg);var c=b(-90+this.rotateDeg+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||l.lineHeight||t.fontSize||l.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||l.background;h(g)&&function(t,e,i,n,r,o,a,s){a?x(t,e,i,n,r,o,a,s):(e.beginPath(),e.fillStyle=s,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),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+b(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];r&&i.drawImage(r,t,i.prizeRadian*i.prizeRadius,d,i.getHeight(t.top,d))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,n=t.fontWeight||l.fontWeight,r=i.getLength(t.fontSize||l.fontSize),h=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:l.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-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(a.gutter);v>i.getWidth(t.lengthLimit||l.lengthLimit,w)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),f(t,d,i))}))})),o.rotate(b(360)-n-b(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];o&&i.drawImage(o,t,2*n,2*n,i.getHeight(t.top,n))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,r=t.fontWeight||l.fontWeight,a=i.getLength(t.fontSize||l.fontSize),s=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=r+" "+(a>>0)+"px "+s,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),f(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,a=e._defaultConfig,s=Date.now()-this.startTime;if(s>=a.accelerationTime&&void 0!==n){this.FPS=s/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var l=360*h-n*r-o-a.offsetDegree;if(T(this.FPS,this.stopDeg,l,a.decelerationTime)-this.stopDeg>a.speed){this.endDeg=l;break}}return this.slowDown()}this.rotateDeg=(o+C(s,0,a.speed,a.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,a=e.stopDeg,s=e.endDeg,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>=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=T(l,a,s,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}(y),_=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",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){return t.init(e.map((function(t){return t.imgs})))}),{deep:!0}),this.$watch("button",(function(e,i){var n=[];return n[t.cols*t.rows-1]=e.imgs,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 l=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],l=i[3];s.beginPath(),s.rect(r,o,a,l),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},c=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(){c++,u===c&&l.call(n)}))}))}))),u||l.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,a,s,h=this;return o(this,(function(o){return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),this.cellImgs[t][e]||(this.cellImgs[t][e]={}),a=1,s=0,this.loadImg(r.src,r).then((function(n){h.cellImgs[t][e].defaultImg=n,a===++s&&i.call(h)})),r.hasOwnProperty("activeSrc")&&(a++,this.loadImg(r.activeSrc,r,"$activeResolve").then((function(n){h.cellImgs[t][e].activeImg=n,a===++s&&i.call(h)}))),[2]):[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,l=n._defaultConfig,c=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=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],a=0,s=o.length;a<s;a++,r++)n[r]=o[a];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,l=t.h,u=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})),f=u[0],d=u[1],g=u[2],p=u[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return h(v)&&k(o,n,r,s,l,m,i.handleBackground(n,r,s,l,v)),{x:n+g,y:r+f,w:s-g-p,h:l-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-l.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-l.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),a=n[0],l=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?u.background:t.background||c.background;if(h(p)){var m=(g?u.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],a-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],l-=m[1])),k(o,a,l,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(a,l,f,d,p)),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 s=i.cellImgs[e][r];if(!s)return!1;var h=g&&s.activeImg||s.defaultImg;if(h){var c,u=i.computedWidthAndHeight(h,n,t),f=u[0],d=u[1],p=[a+i.getOffsetX(f,t.col),l+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=h:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=h.path),o.drawImage(c,m,v,f,d)}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&u.fontStyle?u.fontStyle:e.fontStyle||c.fontStyle,r=g&&u.fontWeight?u.fontWeight:e.fontWeight||c.fontWeight,h=g&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&u.lineHeight?u.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+(h>>0)+"px "+n,o.fillStyle=g&&u.fontColor?u.fontColor:e.fontColor||c.fontColor;var d=[],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],o.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){o.fillText(n,a+i.getOffsetX(o.measureText(n).width,t.col),l+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){var o=this.ctx;return r.includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var a=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),s=a.shift(),h=[0,0,0,0];if(s.includes("deg")){var l=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?h=[e,i+r,e+n,i+r-n*l(s-0)]:s>=45&&s<90?h=[e,i+r,e+n-r*l(s-45),i]:s>=90&&s<135?h=[e+n,i+r,e+n-r*l(s-90),i]:s>=135&&s<180?h=[e+n,i+r,e,i+n*l(s-135)]:s>=180&&s<225?h=[e+n,i,e,i+n*l(s-180)]:s>=225&&s<270?h=[e+n,i,e+r*l(s-225),i+r]:s>=270&&s<315?h=[e,i,e+r*l(s-270),i+r]:s>=315&&s<360&&(h=[e,i,e+n,i+r-n*l(s-315)])}else s.includes("top")?h=[e,i+r,e,i]:s.includes("bottom")?h=[e,i,e,i+r]:s.includes("left")?h=[e+n,i,e,i]:s.includes("right")&&(h=[e,i,e+n,i]);var c=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return a.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}),c)}(o,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,a=e.startTime,s=e._defaultConfig,h=Date.now()-a;if(h>=s.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var l=0;++l;){var c=r.length*l+o-(n>>0);if(T(this.FPS,this.stopIndex,c,s.decelerationTime)-this.stopIndex>s.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+C(h,.1,s.speed,s.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,a=e.stopIndex,s=e.endIndex,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>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=T(l,a,s,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,a=this.cellHeight,s=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+s)*e,this.prizeArea.y+(a+s)*i];return n&&r&&h.push(o*n+s*(n-1),a*r+s*(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}(y);t.LuckyGrid=_,t.LuckyWheel=W,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(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},u=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="__proto__"in{};function l(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var f=Array.prototype,d=Object.create(f);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){d[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=f[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var g=function(){function t(t){this.dep=new u,l(t,"__luckyOb__",this),Array.isArray(t)&&(c?t.__proto__=d:Object.getOwnPropertyNames(d).forEach((function(e){l(t,e,d[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){m(t,e,t[e])}))},t}();function p(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new g(t)}function m(t,e,i){var n=new u,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,s=r&&r.set;o&&!s||2!==arguments.length||(i=t[e]);var a=p(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return u.target&&(n.addSub(u.target),a&&a.dep.addSub(u.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=p(e),n.notify()))}})}}var v=0,b=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=v++,this.$lucky=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(){u.target=this;var t=this.getter.call(this.$lucky,this.$lucky);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),u.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),y=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.4.0"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},t.prototype.drawImage=function(t,e,i,n,r){var o,s=this.config,a=this.ctx;return["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,e,i,n,r)},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&&m(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 b(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),w=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},z=function(t,e){var i=-t/e;return[i,-i*t+e]},S=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=w(180).toFixed(8)){var a=(r+n)/2;return o?(S(t,e,i,n,a,o),S(t,e,i,a,r,o)):(S(t,e,i,a,r,o),S(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=I(n,i),u=h[0],c=h[1],l=I(r,i),f=l[0],d=l[1],g=z(u,c),p=g[0],m=g[1],v=z(f,d),b=v[0],y=v[1],k=(y-m)/(p-b),x=(b*m-p*y)/(b-p);isNaN(k)&&(Math.abs(u)===+i.toFixed(8)&&(k=u),Math.abs(f)===+i.toFixed(8)&&(k=f)),p===1/0||p===-1/0?x=b*k+y:b!==1/0&&b!==-1/0||(x=p*k+m),e.lineTo(u,c),["WEB","UNI-H5"].includes(t)?e.arcTo(k,x,f,d,i):e.quadraticCurveTo(k,x,f,d)},k=function(t,e,i,n,r,o,s,a){i||(i=s);var h=w(90/Math.PI/n*s),u=w(90/Math.PI/i*s),c=r+h,l=o-h,f=r+u,d=o-u;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,I(c,n)),S(t,e,n,c,l,!0),d>f?S(t,e,i,f,d,!1):e.lineTo.apply(e,I((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},x=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()},C=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},T=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},E=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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=e,r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i],o=t[i];o&&o.forEach((function(t,e){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,e,i,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,u;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],u=n,[4,this.loadImg(a.src,a)]):[2];case 1:return h[u]=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,u=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 h(e.background)&&(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=i.computedWidthAndHeight(s,e,2*t,2*t),h=a[0],u=a[1],c=[i.getOffsetX(h),i.getHeight(e.top,2*t)-t],l=c[0],f=c[1];o.save(),e.rotate&&o.rotate(w(i.rotateDeg)),i.drawImage(s,l,f,h,u),o.restore()}}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=w(this.prizeDeg);var c=w(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||u.lineHeight||t.fontSize||u.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||u.background;h(g)&&function(t,e,i,n,r,o,s,a){s?k(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),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+w(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var o=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,d),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,d)],u=h[0],c=h[1];i.drawImage(r,u,c,s,a)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,n=t.fontWeight||u.fontWeight,r=i.getLength(t.fontSize||u.fontSize),h=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:u.wordWrap){g=a(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,b=(i.prizeRadius-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||u.lengthLimit,b)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),f(t,d,i))}))})),o.rotate(w(360)-n-w(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];if(o){var s=i.computedWidthAndHeight(o,t,2*n,2*n),a=s[0],h=s[1],u=[i.getOffsetX(a),i.getHeight(t.top,n)],c=u[0],l=u[1];i.drawImage(o,c,l,a,h)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,r=t.fontWeight||u.fontWeight,s=i.getLength(t.fontSize||u.fontSize),a=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=r+" "+(s>>0)+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),f(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 u=360*h-n*r-o-s.offsetDegree;if(T(this.FPS,this.stopDeg,u,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=u;break}}return this.slowDown()}this.rotateDeg=(o+C(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,u=Date.now()-this.endTime;if(u>=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=T(u,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}(y),W=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.FPS=16.6,n.cells=[],n.blockImgs=[[]],n.prizeImgs=[],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=n.buttons.map((function(t){return t.imgs}));return n.button&&r.push(n.button.imgs),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:r}),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,"buttons",t.buttons||[]),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:"sans-serif",fontWeight:"400",background:"transparent",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("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=t.buttons.map((function(t){return t.imgs}));return t.button&&i.push(t.button.imgs),t.init({btnImgs:i})}),{deep:!0}),this.$watch("button",(function(){var e=t.buttons.map((function(t){return t.imgs}));return t.button&&e.push(t.button.imgs),t.init({btnImgs:e})}),{deep:!0}),this.$watch("rows",(function(){return t.init({})})),this.$watch("cols",(function(){return t.init({})})),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,a=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var h=function(){n.draw(),n.demo&&n.walk(),n.buttons.length&&o.canvasElement&&(o.canvasElement.onclick=function(t){n.buttons.forEach((function(e){var i,r=n.getGeometricProperty([e.x,e.y,e.col||1,e.row||1]),o=r[0],a=r[1],h=r[2],u=r[3];s.beginPath(),s.rect(o,a,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(i=n.startCallback)||void 0===i||i.call(n,t))}))}),a&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([a.x,a.y,a.col||1,a.row||1]),r=i[0],o=i[1],h=i[2],u=i[3];s.beginPath(),s.rect(r,o,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},u=0,c=0;this.draw(),Object.keys(t).forEach((function(e){var i=e,r=t[i],o={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i];r&&r.forEach((function(t,e){t&&t.forEach((function(t,r){c++,n.loadAndCacheImg(o,e,i,r,(function(){u++,c===u&&h.call(n)}))}))}))})),c||h.call(this),null===(i=o.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,u,c,l,f,d=this;return o(this,(function(o){switch(o.label){case 0:return r=this[t][e],"buttons"===t&&!this.buttons.length&&this.button&&(r=this.button),r&&r.imgs?(a=r.imgs[n])?(this[i][e]||(this[i][e]=[]),"blockImgs"!==i&&"btnImgs"!==i?[3,2]:(h=this[i][e],u=n,f={},[4,this.loadImg(a.src,a)])):[2]:[2];case 1:return h[u]=(f.defaultImg=o.sent(),f),[2,s.call(this)];case 2:return this.prizeImgs[e][n]||(this.prizeImgs[e][n]={}),c=1,l=0,this.loadImg(a.src,a).then((function(t){d.prizeImgs[e][n].defaultImg=t,c===++l&&s.call(d)})),a.hasOwnProperty("activeSrc")&&(c++,this.loadImg(a.activeSrc,a,"$activeResolve").then((function(t){d.prizeImgs[e][n].activeImg=t,c===++l&&s.call(d)}))),[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,u=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.buttons),this.button&&this.cells.push(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,u=t.h,l=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})),f=l[0],d=l[1],g=l[2],p=l[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return h(v)&&x(o,n,r,a,u,m,i.handleBackground(n,r,a,u,v)),{x:n+g,y:r+f,w:a-g-p,h:u-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-u.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-u.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],u=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?l.background:t.background||c.background;if(h(p)){var m=(g?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],s-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],u-=m[1])),x(o,s,u,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(s,u,f,d,p)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0}var v="prizeImgs";e>=i.prizes.length&&(v="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[v][e]){var o=i[v][e][r];if(o){var a=g&&o.activeImg||o.defaultImg;if(a){var h=i.computedWidthAndHeight(a,n,t),c=h[0],l=h[1],f=[s+i.getOffsetX(c,t.col),u+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(a,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=g&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,h=g&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+(h>>0)+"px "+n,o.fillStyle=g&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var d=[],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)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),u+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){var o=this.ctx;return r.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 u=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*u(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*u(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*u(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*u(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*u(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*u(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*u(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*u(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 c=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}),c)}(o,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 u=0;++u;){var c=r.length*u+o-(n>>0);if(T(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+C(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,u=Date.now()-this.endTime;if(u>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=T(u,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}(y);t.LuckyGrid=W,t.LuckyWheel=E,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "lucky-canvas", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"description": "一个基于原生 js 的(大转盘抽奖 / 九宫格抽奖)插件", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,8 +54,7 @@ | ||
- **最新版本:** [https://cdn.jsdelivr.net/npm/lucky-canvas/dist/lucky-canvas.umd.min.js](https://cdn.jsdelivr.net/npm/lucky-canvas/dist/lucky-canvas.umd.min.js) | ||
- **指定版本:** [https://cdn.jsdelivr.net/npm/lucky-canvas@1.2.6/dist/lucky-canvas.umd.min.js](https://cdn.jsdelivr.net/npm/lucky-canvas@1.2.3/dist/lucky-canvas.umd.min.js) | ||
- **指定版本:** [https://cdn.jsdelivr.net/npm/lucky-canvas@1.4/dist/lucky-canvas.umd.min.js](https://cdn.jsdelivr.net/npm/lucky-canvas@1.4/dist/lucky-canvas.umd.min.js) | ||
```html | ||
<div id="my-lucky"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/lucky-canvas/dist/lucky-canvas.umd.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/lucky-canvas@1.4/dist/lucky-canvas.umd.min.js"></script> | ||
<script> | ||
@@ -62,0 +61,0 @@ |
@@ -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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(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(a,s)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}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,s])}}}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 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}))},s=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=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="__proto__"in{};function u(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var f=Array.prototype,d=Object.create(f);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){d[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=f[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var g=function(){function t(t){this.dep=new l,u(t,"__luckyOb__",this),Array.isArray(t)&&(c?t.__proto__=d:Object.getOwnPropertyNames(d).forEach((function(e){u(t,e,d[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){m(t,e,t[e])}))},t}();function p(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new g(t)}function m(t,e,i){var n=new l,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=p(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return l.target&&(n.addSub(l.target),s&&s.dep.addSub(l.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=p(e),n.notify()))}})}}var v=0,w=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=v++,this.$lucky=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(){l.target=this;var t=this.getter.call(this.$lucky,this.$lucky);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),l.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),y=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.3.4"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},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 a=i.config.unitFunc;return a?a(n,r):n})))},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&m(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 w(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),b=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},S=function(t,e){var i=-t/e;return[i,-i*t+e]},z=function(t,e,i,n,r,o){var a;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=b(180).toFixed(8)){var s=(r+n)/2;return o?(z(t,e,i,n,s,o),z(t,e,i,s,r,o)):(z(t,e,i,s,r,o),z(t,e,i,n,s,o)),!1}o||(n=(a=[r,n])[0],r=a[1]);var h=I(n,i),l=h[0],c=h[1],u=I(r,i),f=u[0],d=u[1],g=S(l,c),p=g[0],m=g[1],v=S(f,d),w=v[0],y=v[1],x=(y-m)/(p-w),k=(w*m-p*y)/(w-p);isNaN(x)&&(Math.abs(l)===+i.toFixed(8)&&(x=l),Math.abs(f)===+i.toFixed(8)&&(x=f)),p===1/0||p===-1/0?k=w*x+y:w!==1/0&&w!==-1/0||(k=p*x+m),e.lineTo(l,c),["WEB","UNI-H5"].includes(t)?e.arcTo(x,k,f,d,i):e.quadraticCurveTo(x,k,f,d)},x=function(t,e,i,n,r,o,a,s){i||(i=a);var h=b(90/Math.PI/n*a),l=b(90/Math.PI/i*a),c=r+h,u=o-h,f=r+l,d=o-l;e.beginPath(),e.fillStyle=s,e.moveTo.apply(e,I(c,n)),z(t,e,n,c,u,!0),d>f?z(t,e,i,f,d,!1):e.lineTo.apply(e,I((r+o)/2,a/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},k=function(t,e,i,n,r,o,a){var s=Math.min(n,r);o>s/2&&(o=s/2),t.beginPath(),t.fillStyle=a,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()},C=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},T=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},W=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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 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))})},s=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(){s++,h===s&&a.call(n)}))}))}))})),h||a.call(this),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.loadAndCacheImg=function(t,e,i,n,a){return r(this,void 0,void 0,(function(){var r,s,h,l;return o(this,(function(o){switch(o.label){case 0:return(r=this[t][e])&&r.imgs&&(s=r.imgs[n])?(this[i][e]||(this[i][e]=[]),h=this[i][e],l=n,[4,this.loadImg(s.src,s)]):[2];case 1:return h[l]=o.sent(),a.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.drawImage=function(t,e,i,n,r){var o,a=this.ctx,s=this.config,h=this.computedWidthAndHeight(t,e,i,n),l=h[0],c=h[1];["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,this.getOffsetX(l),r,l,c)},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,a=n._defaultConfig,l=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 h(e.background)&&(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 a=i.blockImgs[n][r];a&&(o.save(),e.rotate&&o.rotate(b(i.rotateDeg)),i.drawImage(a,e,2*t,2*t,i.getHeight(e.top,2*t)-t),o.restore())}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=b(this.prizeDeg);var c=b(-90+this.rotateDeg+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||l.lineHeight||t.fontSize||l.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||l.background;h(g)&&function(t,e,i,n,r,o,a,s){a?x(t,e,i,n,r,o,a,s):(e.beginPath(),e.fillStyle=s,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),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+b(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];r&&i.drawImage(r,t,i.prizeRadian*i.prizeRadius,d,i.getHeight(t.top,d))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,n=t.fontWeight||l.fontWeight,r=i.getLength(t.fontSize||l.fontSize),h=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:l.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-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(a.gutter);v>i.getWidth(t.lengthLimit||l.lengthLimit,w)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),f(t,d,i))}))})),o.rotate(b(360)-n-b(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];o&&i.drawImage(o,t,2*n,2*n,i.getHeight(t.top,n))}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||l.fontColor,r=t.fontWeight||l.fontWeight,a=i.getLength(t.fontSize||l.fontSize),s=t.fontStyle||l.fontStyle;o.fillStyle=e,o.font=r+" "+(a>>0)+"px "+s,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),f(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,a=e._defaultConfig,s=Date.now()-this.startTime;if(s>=a.accelerationTime&&void 0!==n){this.FPS=s/t,this.endTime=Date.now(),this.stopDeg=o;for(var h=0;++h;){var l=360*h-n*r-o-a.offsetDegree;if(T(this.FPS,this.stopDeg,l,a.decelerationTime)-this.stopDeg>a.speed){this.endDeg=l;break}}return this.slowDown()}this.rotateDeg=(o+C(s,0,a.speed,a.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,a=e.stopDeg,s=e.endDeg,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>=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=T(l,a,s,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}(y),_=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",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){return t.init(e.map((function(t){return t.imgs})))}),{deep:!0}),this.$watch("button",(function(e,i){var n=[];return n[t.cols*t.rows-1]=e.imgs,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 l=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],l=i[3];s.beginPath(),s.rect(r,o,a,l),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},c=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(){c++,u===c&&l.call(n)}))}))}))),u||l.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,a,s,h=this;return o(this,(function(o){return(n=this.cells[t])&&n.imgs?(r=n.imgs[e],this.cellImgs[t]||(this.cellImgs[t]=[]),this.cellImgs[t][e]||(this.cellImgs[t][e]={}),a=1,s=0,this.loadImg(r.src,r).then((function(n){h.cellImgs[t][e].defaultImg=n,a===++s&&i.call(h)})),r.hasOwnProperty("activeSrc")&&(a++,this.loadImg(r.activeSrc,r,"$activeResolve").then((function(n){h.cellImgs[t][e].activeImg=n,a===++s&&i.call(h)}))),[2]):[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,l=n._defaultConfig,c=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=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],a=0,s=o.length;a<s;a++,r++)n[r]=o[a];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,l=t.h,u=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})),f=u[0],d=u[1],g=u[2],p=u[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return h(v)&&k(o,n,r,s,l,m,i.handleBackground(n,r,s,l,v)),{x:n+g,y:r+f,w:s-g-p,h:l-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-l.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-l.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),a=n[0],l=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?u.background:t.background||c.background;if(h(p)){var m=(g?u.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],a-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],l-=m[1])),k(o,a,l,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(a,l,f,d,p)),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 s=i.cellImgs[e][r];if(!s)return!1;var h=g&&s.activeImg||s.defaultImg;if(h){var c,u=i.computedWidthAndHeight(h,n,t),f=u[0],d=u[1],p=[a+i.getOffsetX(f,t.col),l+i.getHeight(n.top,t.row)],m=p[0],v=p[1];["WEB","MINI-WX"].includes(i.config.flag)?c=h:["UNI-H5","UNI-MINI-WX"].includes(i.config.flag)&&(c=h.path),o.drawImage(c,m,v,f,d)}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&u.fontStyle?u.fontStyle:e.fontStyle||c.fontStyle,r=g&&u.fontWeight?u.fontWeight:e.fontWeight||c.fontWeight,h=g&&u.fontSize?i.getLength(u.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&u.lineHeight?u.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+(h>>0)+"px "+n,o.fillStyle=g&&u.fontColor?u.fontColor:e.fontColor||c.fontColor;var d=[],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],o.measureText(m).width>i.getWidth(e.lengthLimit||c.lengthLimit,t.col)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){o.fillText(n,a+i.getOffsetX(o.measureText(n).width,t.col),l+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){var o=this.ctx;return r.includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var a=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),s=a.shift(),h=[0,0,0,0];if(s.includes("deg")){var l=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?h=[e,i+r,e+n,i+r-n*l(s-0)]:s>=45&&s<90?h=[e,i+r,e+n-r*l(s-45),i]:s>=90&&s<135?h=[e+n,i+r,e+n-r*l(s-90),i]:s>=135&&s<180?h=[e+n,i+r,e,i+n*l(s-135)]:s>=180&&s<225?h=[e+n,i,e,i+n*l(s-180)]:s>=225&&s<270?h=[e+n,i,e+r*l(s-225),i+r]:s>=270&&s<315?h=[e,i,e+r*l(s-270),i+r]:s>=315&&s<360&&(h=[e,i,e+n,i+r-n*l(s-315)])}else s.includes("top")?h=[e,i+r,e,i]:s.includes("bottom")?h=[e,i,e,i+r]:s.includes("left")?h=[e+n,i,e,i]:s.includes("right")&&(h=[e,i,e+n,i]);var c=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return a.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}),c)}(o,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,a=e.startTime,s=e._defaultConfig,h=Date.now()-a;if(h>=s.accelerationTime&&void 0!==o){this.FPS=h/t,this.endTime=Date.now(),this.stopIndex=n;for(var l=0;++l;){var c=r.length*l+o-(n>>0);if(T(this.FPS,this.stopIndex,c,s.decelerationTime)-this.stopIndex>s.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+C(h,.1,s.speed,s.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,a=e.stopIndex,s=e.endIndex,h=e._defaultConfig,l=Date.now()-this.endTime;if(l>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=T(l,a,s,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,a=this.cellHeight,s=this._defaultConfig.gutter,h=[this.prizeArea.x+(o+s)*e,this.prizeArea.y+(a+s)*i];return n&&r&&h.push(o*n+s*(n-1),a*r+s*(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}(y);t.LuckyGrid=_,t.LuckyWheel=W,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(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},u=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="__proto__"in{};function l(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var f=Array.prototype,d=Object.create(f);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){d[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=f[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var g=function(){function t(t){this.dep=new u,l(t,"__luckyOb__",this),Array.isArray(t)&&(c?t.__proto__=d:Object.getOwnPropertyNames(d).forEach((function(e){l(t,e,d[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){m(t,e,t[e])}))},t}();function p(t){if("object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new g(t)}function m(t,e,i){var n=new u,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,s=r&&r.set;o&&!s||2!==arguments.length||(i=t[e]);var a=p(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return u.target&&(n.addSub(u.target),a&&a.dep.addSub(u.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=p(e),n.notify()))}})}}var v=0,b=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=v++,this.$lucky=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(){u.target=this;var t=this.getter.call(this.$lucky,this.$lucky);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),u.target=null,t},t.prototype.update=function(){var t=this.get(),e=this.value;this.value=t,this.cb.call(this.$lucky,t,e)},t}(),y=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.4.0"),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,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r){if("WEB"===n.config.flag){var o=new Image;o.src=t,o.onload=function(){return r(o)}}else e[i]=r}))},t.prototype.drawImage=function(t,e,i,n,r){var o,s=this.config,a=this.ctx;return["WEB","MINI-WX"].includes(s.flag)?o=t:["UNI-H5","UNI-MINI-WX"].includes(s.flag)&&(o=t.path),a.drawImage(o,e,i,n,r)},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&&m(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 b(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),w=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},z=function(t,e){var i=-t/e;return[i,-i*t+e]},S=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=w(180).toFixed(8)){var a=(r+n)/2;return o?(S(t,e,i,n,a,o),S(t,e,i,a,r,o)):(S(t,e,i,a,r,o),S(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=I(n,i),u=h[0],c=h[1],l=I(r,i),f=l[0],d=l[1],g=z(u,c),p=g[0],m=g[1],v=z(f,d),b=v[0],y=v[1],k=(y-m)/(p-b),x=(b*m-p*y)/(b-p);isNaN(k)&&(Math.abs(u)===+i.toFixed(8)&&(k=u),Math.abs(f)===+i.toFixed(8)&&(k=f)),p===1/0||p===-1/0?x=b*k+y:b!==1/0&&b!==-1/0||(x=p*k+m),e.lineTo(u,c),["WEB","UNI-H5"].includes(t)?e.arcTo(k,x,f,d,i):e.quadraticCurveTo(k,x,f,d)},k=function(t,e,i,n,r,o,s,a){i||(i=s);var h=w(90/Math.PI/n*s),u=w(90/Math.PI/i*s),c=r+h,l=o-h,f=r+u,d=o-u;e.beginPath(),e.fillStyle=a,e.moveTo.apply(e,I(c,n)),S(t,e,n,c,l,!0),d>f?S(t,e,i,f,d,!1):e.lineTo.apply(e,I((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},x=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()},C=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},T=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},E=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:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.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:"sans-serif",fontWeight:"400",background:"transparent",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){return t.init({btnImgs:e.map((function(t){return t.imgs}))})}),{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=e,r={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i],o=t[i];o&&o.forEach((function(t,e){t&&t.forEach((function(t,o){h++,n.loadAndCacheImg(r,e,i,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,u;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],u=n,[4,this.loadImg(a.src,a)]):[2];case 1:return h[u]=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,u=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 h(e.background)&&(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=i.computedWidthAndHeight(s,e,2*t,2*t),h=a[0],u=a[1],c=[i.getOffsetX(h),i.getHeight(e.top,2*t)-t],l=c[0],f=c[1];o.save(),e.rotate&&o.rotate(w(i.rotateDeg)),i.drawImage(s,l,f,h,u),o.restore()}}})),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeRadian=w(this.prizeDeg);var c=w(-90+this.rotateDeg+s.offsetDegree),l=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||u.lineHeight||t.fontSize||u.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,d=i.prizeRadius-i.maxBtnRadius,g=t.background||u.background;h(g)&&function(t,e,i,n,r,o,s,a){s?k(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),g);var p=Math.cos(n)*i.prizeRadius,m=Math.sin(n)*i.prizeRadius;o.translate(p,m),o.rotate(n+w(90)),t.imgs&&t.imgs.forEach((function(t,n){if(i.prizeImgs[e]){var r=i.prizeImgs[e][n];if(r){var o=i.computedWidthAndHeight(r,t,i.prizeRadian*i.prizeRadius,d),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,d)],u=h[0],c=h[1];i.drawImage(r,u,c,s,a)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,n=t.fontWeight||u.fontWeight,r=i.getLength(t.fontSize||u.fontSize),h=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var c=[],g=String(t.text);if(t.hasOwnProperty("wordWrap")?t.wordWrap:u.wordWrap){g=a(g);for(var p="",m=0;m<g.length;m++){p+=g[m];var v=o.measureText(p).width,b=(i.prizeRadius-f(t,d,c.length))*Math.tan(i.prizeRadian/2)*2-i.getLength(s.gutter);v>i.getWidth(t.lengthLimit||u.lengthLimit,b)&&(c.push(p.slice(0,-1)),p=g[m])}p&&c.push(p),c.length||c.push(g)}else c=g.split("\n");c.filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,l(e),f(t,d,i))}))})),o.rotate(w(360)-n-w(90)),o.translate(-p,-m)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&h(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.moveTo(-n,0),o.lineTo(n,0),o.lineTo(0,2*-n),o.closePath(),o.fill()),t.imgs&&t.imgs.forEach((function(t,r){if(i.btnImgs[e]){var o=i.btnImgs[e][r];if(o){var s=i.computedWidthAndHeight(o,t,2*n,2*n),a=s[0],h=s[1],u=[i.getOffsetX(a),i.getHeight(t.top,n)],c=u[0],l=u[1];i.drawImage(o,c,l,a,h)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||u.fontColor,r=t.fontWeight||u.fontWeight,s=i.getLength(t.fontSize||u.fontSize),a=t.fontStyle||u.fontStyle;o.fillStyle=e,o.font=r+" "+(s>>0)+"px "+a,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,l(e),f(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 u=360*h-n*r-o-s.offsetDegree;if(T(this.FPS,this.stopDeg,u,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=u;break}}return this.slowDown()}this.rotateDeg=(o+C(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,u=Date.now()-this.endTime;if(u>=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=T(u,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}(y),W=function(t){function e(e,i){void 0===i&&(i={});var n=t.call(this,e)||this;n.rows=3,n.cols=3,n.blocks=[],n.prizes=[],n.buttons=[],n.defaultConfig={},n._defaultConfig={gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},n.defaultStyle={},n._defaultStyle={borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"sans-serif",fontWeight:"400",lineHeight:"",background:"transparent",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.FPS=16.6,n.cells=[],n.blockImgs=[[]],n.prizeImgs=[],n.btnImgs=[[]],n.initData(i),n.initComputed(),n.initWatch();var r=n.buttons.map((function(t){return t.imgs}));return n.button&&r.push(n.button.imgs),n.init({blockImgs:n.blocks.map((function(t){return t.imgs})),prizeImgs:n.prizes.map((function(t){return t.imgs})),btnImgs:r}),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,"buttons",t.buttons||[]),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:"sans-serif",fontWeight:"400",background:"transparent",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("blocks",(function(e){return t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){return t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=t.buttons.map((function(t){return t.imgs}));return t.button&&i.push(t.button.imgs),t.init({btnImgs:i})}),{deep:!0}),this.$watch("button",(function(){var e=t.buttons.map((function(t){return t.imgs}));return t.button&&e.push(t.button.imgs),t.init({btnImgs:e})}),{deep:!0}),this.$watch("rows",(function(){return t.init({})})),this.$watch("cols",(function(){return t.init({})})),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,a=r.button;this.setHTMLFontSize(),this.setDpr(),this.zoomCanvas(),null===(e=o.beforeInit)||void 0===e||e.call(this);var h=function(){n.draw(),n.demo&&n.walk(),n.buttons.length&&o.canvasElement&&(o.canvasElement.onclick=function(t){n.buttons.forEach((function(e){var i,r=n.getGeometricProperty([e.x,e.y,e.col||1,e.row||1]),o=r[0],a=r[1],h=r[2],u=r[3];s.beginPath(),s.rect(o,a,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(i=n.startCallback)||void 0===i||i.call(n,t))}))}),a&&o.canvasElement&&(o.canvasElement.onclick=function(t){var e,i=n.getGeometricProperty([a.x,a.y,a.col||1,a.row||1]),r=i[0],o=i[1],h=i[2],u=i[3];s.beginPath(),s.rect(r,o,h,u),s.isPointInPath(t.offsetX,t.offsetY)&&(n.startTime||null===(e=n.startCallback)||void 0===e||e.call(n,t))})},u=0,c=0;this.draw(),Object.keys(t).forEach((function(e){var i=e,r=t[i],o={blockImgs:"blocks",prizeImgs:"prizes",btnImgs:"buttons"}[i];r&&r.forEach((function(t,e){t&&t.forEach((function(t,r){c++,n.loadAndCacheImg(o,e,i,r,(function(){u++,c===u&&h.call(n)}))}))}))})),c||h.call(this),null===(i=o.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,u,c,l,f,d=this;return o(this,(function(o){switch(o.label){case 0:return r=this[t][e],"buttons"===t&&!this.buttons.length&&this.button&&(r=this.button),r&&r.imgs?(a=r.imgs[n])?(this[i][e]||(this[i][e]=[]),"blockImgs"!==i&&"btnImgs"!==i?[3,2]:(h=this[i][e],u=n,f={},[4,this.loadImg(a.src,a)])):[2]:[2];case 1:return h[u]=(f.defaultImg=o.sent(),f),[2,s.call(this)];case 2:return this.prizeImgs[e][n]||(this.prizeImgs[e][n]={}),c=1,l=0,this.loadImg(a.src,a).then((function(t){d.prizeImgs[e][n].defaultImg=t,c===++l&&s.call(d)})),a.hasOwnProperty("activeSrc")&&(c++,this.loadImg(a.activeSrc,a,"$activeResolve").then((function(t){d.prizeImgs[e][n].activeImg=t,c===++l&&s.call(d)}))),[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,u=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.buttons),this.button&&this.cells.push(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,u=t.h,l=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})),f=l[0],d=l[1],g=l[2],p=l[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||c.background;return h(v)&&x(o,n,r,a,u,m,i.handleBackground(n,r,a,u,v)),{x:n+g,y:r+f,w:a-g-p,h:u-f-d}}),{x:0,y:0,w:r.width,h:r.height}),this.cellWidth=(this.prizeArea.w-u.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-u.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],u=n[1],f=n[2],d=n[3],g=e===i.currIndex%i.prizes.length>>0,p=g?l.background:t.background||c.background;if(h(p)){var m=(g?l.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?f-=m[0]:(f+=m[0],s-=m[0]),m[1]>0?d-=m[1]:(d+=m[1],u-=m[1])),x(o,s,u,f,d,i.getLength(t.borderRadius?t.borderRadius:c.borderRadius),i.handleBackground(s,u,f,d,p)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0}var v="prizeImgs";e>=i.prizes.length&&(v="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[v][e]){var o=i[v][e][r];if(o){var a=g&&o.activeImg||o.defaultImg;if(a){var h=i.computedWidthAndHeight(a,n,t),c=h[0],l=h[1],f=[s+i.getOffsetX(c,t.col),u+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(a,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&l.fontStyle?l.fontStyle:e.fontStyle||c.fontStyle,r=g&&l.fontWeight?l.fontWeight:e.fontWeight||c.fontWeight,h=g&&l.fontSize?i.getLength(l.fontSize):i.getLength(e.fontSize||c.fontSize),f=g&&l.lineHeight?l.lineHeight:e.lineHeight||c.lineHeight||e.fontSize||c.fontSize;o.font=r+" "+(h>>0)+"px "+n,o.fillStyle=g&&l.fontColor?l.fontColor:e.fontColor||c.fontColor;var d=[],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)&&(d.push(m.slice(0,-1)),m=p[v])}m&&d.push(m),d.length||d.push(p)}else d=p.split("\n");d.forEach((function(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),u+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){var o=this.ctx;return r.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 u=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*u(a-0)]:a>=45&&a<90?h=[e,i+r,e+n-r*u(a-45),i]:a>=90&&a<135?h=[e+n,i+r,e+n-r*u(a-90),i]:a>=135&&a<180?h=[e+n,i+r,e,i+n*u(a-135)]:a>=180&&a<225?h=[e+n,i,e,i+n*u(a-180)]:a>=225&&a<270?h=[e+n,i,e+r*u(a-225),i+r]:a>=270&&a<315?h=[e,i,e+r*u(a-270),i+r]:a>=315&&a<360&&(h=[e,i,e+n,i+r-n*u(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 c=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}),c)}(o,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 u=0;++u;){var c=r.length*u+o-(n>>0);if(T(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+C(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,u=Date.now()-this.endTime;if(u>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=T(u,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}(y);t.LuckyGrid=W,t.LuckyWheel=E,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276426
4433
89