lucky-canvas
Advanced tools
Comparing version 1.5.13 to 1.5.14
@@ -15,2 +15,2 @@ /*! ***************************************************************************** | ||
***************************************************************************** */ | ||
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])},t(e,i)};function e(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");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},i.apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}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(t){var e=[],i=t.map((function(t){return Number(t)})).reduce((function(t,i){if(i>0){var n=t+i;return e.push(n),n}return e.push(NaN),t}),0),n=Math.random()*i;return e.findIndex((function(t){return n<=t}))},c=function(t,e,i,n){void 0===n&&(n=1/0),n<=0&&(n=1/0);for(var r="",o=[],s=t.measureText("...").width,a=0;a<e.length;a++){r+=e[a];var h=t.measureText(r).width,u=i(o);if(n===o.length+1&&(h+=s),u<0)return o;if(h>u&&(o.push(r.slice(0,-1)),r=e[a]),n===o.length)return o[o.length-1]+="...",o}return r&&o.push(r),o.length||o.push(e),o},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}(),f="__proto__"in{};function d(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var p=Array.prototype,g=Object.create(p);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){g[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=p[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var m=function(){function t(t){this.dep=new l,d(t,"__luckyOb__",this),Array.isArray(t)&&(f?t.__proto__=g:Object.getOwnPropertyNames(g).forEach((function(e){d(t,e,g[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){w(t,e,t[e])}))},t}();function v(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new m(t)}function w(t,e,i){var n=new l,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=v(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return l.target&&(n.addSub(l.target),a&&a.dep.addSub(l.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=v(e),n.notify()))}})}}var b=0,y=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=b++,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){s(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}(),z=function(){function t(t,e){var i=this;this.version="1.5.13",this.htmlFontSize=16,this.rAF=function(){},this.boxWidth=0,this.boxHeight=0,"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,this.data=e,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el)),t.divElement&&(t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.canvasElement&&(t.ctx=t.canvasElement.getContext("2d"),t.canvasElement.setAttribute("package","lucky-canvas@1.5.13"),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&window.addEventListener("resize",function(t,e){void 0===e&&(e=300);var i=null;return function(){for(var n=this,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i||(i=setTimeout((function(){t.apply(n,r),clearTimeout(i),i=null}),e))}}((function(){i.resize()}),300))}return t.prototype.resize=function(){this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){this.resize(),this.boxWidth&&this.boxHeight||console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},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.resetWidthAndHeight=function(){var t=this.config,e=this.data,i=0,n=0;t.divElement&&(i=t.divElement.offsetWidth,n=t.divElement.offsetHeight),this.boxWidth=this.getLength(e.width||t.width)||i,this.boxHeight=this.getLength(e.height||t.height)||n,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=this.boxWidth+"px",t.divElement.style.height=this.boxHeight+"px")},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=[this.boxWidth*n,this.boxHeight*n],o=r[0],s=r[1];i&&(i.width=o,i.height=s,i.style.width=o+"px",i.style.height=s+"px",i.style["transform-origin"]="left top",i.style.transform="scale("+1/n+")",e.scale(n,n))},t.prototype.initWindowFunction=function(){var t=this.config;if(window)return this.rAF=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},t.setTimeout=window.setTimeout,t.setInterval=window.setInterval,t.clearTimeout=window.clearTimeout,void(t.clearInterval=window.clearInterval);if(t.rAF)this.rAF=t.rAF;else if(t.setTimeout){var e=t.setTimeout;this.rAF=function(t){return e(t,16.7)}}else this.rAF=function(t){return setTimeout(t,16.7)}},t.prototype.loadImg=function(t,e,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r,o){if(t||o("=> '"+e.src+"' 不能为空或不合法"),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var s=new Image;s.onload=function(){return r(s)},s.onerror=function(){return o("=> '"+e.src+"' 图片加载失败")},s.src=t}))},t.prototype.drawImage=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n,r=this,s=r.config,a=r.ctx;if(["WEB","MP-WX"].includes(s.flag))n=t;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s.flag))return console.error("意料之外的 flag, 该平台尚未兼容!");n=t.path}return a.drawImage.apply(a,o([n],e))},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},vw:function(t){return t/100*window.innerWidth}}[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&&w(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 y(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},k=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)>=x(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],p=k(u,c),g=p[0],m=p[1],v=k(f,d),w=v[0],b=v[1],y=(b-m)/(g-w),z=(w*m-g*b)/(w-g);isNaN(y)&&(Math.abs(u)===+i.toFixed(8)&&(y=u),Math.abs(f)===+i.toFixed(8)&&(y=f)),g===1/0||g===-1/0?z=w*y+b:w!==1/0&&w!==-1/0||(z=g*y+m),e.lineTo(u,c),t.indexOf("MP")>0?e.quadraticCurveTo(y,z,f,d):e.arcTo(y,z,f,d,i)},T=function(t,e,i,n,r,o,s,a){i||(i=s);var h=x(90/Math.PI/n*s),u=x(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()},C=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()},O={easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e}},W={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*Math.cos(t/n*(Math.PI/2))+i+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sin(t/n*(Math.PI/2))+e}},$={easeIn:function(t,e,i,n){return t>=n&&(t=n),0==t?e:i*Math.pow(2,10*(t/n-1))+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),t==n?e+i:i*(1-Math.pow(2,-10*t/n))+e}},P={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*(Math.sqrt(1-(t/=n)*t)-1)+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sqrt(1-(t=t/n-1)*t)+e}},_=Object.freeze({__proto__:null,quad:O,cubic:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t+1)+e}},quart:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*((t=t/n-1)*t*t*t-1)+e}},quint:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t*t*t+1)+e}},sine:W,expo:$,circ:P}),R=function(t){function o(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;return r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r._defaultConfig={},r._defaultStyle={},r.Radius=0,r.prizeRadius=0,r.prizeDeg=0,r.prizeRadian=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.FPS=16.6,r.blockImgs=[[]],r.prizeImgs=[[]],r.btnImgs=[[]],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:r.buttons.map((function(t){return t.imgs}))}),r}return e(o,t),o.prototype.resize=function(){t.prototype.resize.call(this),this.Radius=Math.min(this.boxWidth,this.boxHeight)/2,this.ctx.translate(this.Radius,this.Radius),this.draw()},o.prototype.initLucky=function(){this.Radius=0,this.prizeRadius=0,this.prizeDeg=0,this.prizeRadian=0,this.rotateDeg=0,this.maxBtnRadius=0,this.startTime=0,this.endTime=0,this.stopDeg=0,this.endDeg=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},o.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,speedFunction:"quad",accelerationTime:2500,decelerationTime:2500,stopRange:0},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"sans-serif",fontWeight:"400",background:"rgba(0,0,0,0)",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},o.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){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({})}))},o.prototype.init=function(t){var e,i,n=this;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},o.prototype.handleClick=function(t){var e,i=this.ctx;i.beginPath(),i.arc(0,0,this.maxBtnRadius,0,2*Math.PI,!1),i.isPointInPath(t.offsetX,t.offsetY)&&(this.startTime||null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i,o){return n(this,void 0,void 0,(function(){var n=this;return r(this,(function(r){return[2,new Promise((function(r,s){var a=n[t][e];if(a&&a.imgs){var h=a.imgs[o];h&&(n[i][e]||(n[i][e]=[]),n.loadImg(h.src,h).then((function(t){n[i][e][o]=t,r()})).catch((function(i){console.error(t+"["+e+"].imgs["+o+"] "+i),s()})))}}))]}))}))},o.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)]},o.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(x(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=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+s.offsetDegree),f=function(t){return i.getOffsetX(o.measureText(t).width)},d=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=l+e*i.prizeRadian,p=i.prizeRadius-i.maxBtnRadius,g=t.background||u.background;h(g)&&function(t,e,i,n,r,o,s,a){s?T(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 m=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(m,v),o.rotate(n+x(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,p),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,p)],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,l=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,g=t.lengthLimit||u.lengthLimit,m=t.lineClamp||u.lineClamp;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var v=String(t.text);(l?c(o,a(v),(function(e){var n=2*((i.prizeRadius-d(t,p,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(s.gutter);return i.getWidth(g,n)}),m):v.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,f(e),d(t,p,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-m,-v)})),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,f(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},o.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=u(e)}t<0?(this.prizeFlag=-1,this.rotateDeg=0,this.draw()):this.prizeFlag=t%this.prizes.length},o.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;if(-1!==n){var 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=(Math.random()*r-r/2)*this.getLength(s.stopRange),u=0;++u;){var c=360*u-n*r-o-s.offsetDegree+h-r/2;if(_[s.speedFunction].easeOut(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+_[s.speedFunction].easeIn(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},o.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopDeg,s=e.endDeg,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>=a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.rotateDeg=_[a.speedFunction].easeOut(h,o,s,a.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},o.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},o.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},o.prototype.getOffsetX=function(t){return-t/2},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),E=function(t){function l(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;r.rows=3,r.cols=3,r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r.activeStyle={},r._defaultConfig={},r._defaultStyle={},r._activeStyle={},r.cellWidth=0,r.cellHeight=0,r.startTime=0,r.endTime=0,r.currIndex=0,r.stopIndex=0,r.endIndex=0,r.demo=!1,r.timer=0,r.FPS=16.6,r.prizeFlag=-1,r.cells=[],r.blockImgs=[[]],r.btnImgs=[[]],r.prizeImgs=[],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r);var o=r.buttons.map((function(t){return t.imgs}));return r.button&&o.push(r.button.imgs),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:o}),r}return e(l,t),l.prototype.resize=function(){t.prototype.resize.call(this),this.draw()},l.prototype.initLucky=function(){this.cellWidth=0,this.cellHeight=0,this.startTime=0,this.endTime=0,this.currIndex=0,this.stopIndex=0,this.endIndex=0,this.demo=!1,this.timer=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},l.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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)},l.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:"rgba(0,0,0,0)",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},l.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=e.map((function(t){return t.imgs}));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}));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({})}))},l.prototype.init=function(t){var e,i,n=this;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},l.prototype.handleClick=function(t){var e=this,i=this.ctx;o(o([],this.buttons),[this.button]).forEach((function(n){var r;if(n){var o=e.getGeometricProperty([n.x,n.y,n.col||1,n.row||1]),s=o[0],a=o[1],h=o[2],u=o[3];i.beginPath(),i.rect(s,a,h,u),i.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||("function"==typeof n.callback&&n.callback.call(e,n),null===(r=e.startCallback)||void 0===r||r.call(e,t,n)))}}))},l.prototype.loadAndCacheImg=function(t,e,i,o){return n(this,void 0,void 0,(function(){var n=this;return r(this,(function(r){return[2,new Promise((function(r,s){var a=n[t][e];if("buttons"===t&&!n.buttons.length&&n.button&&(a=n.button),a&&a.imgs){var h=a.imgs[o];if(h){n[i][e]||(n[i][e]=[]);var u=[n.loadImg(h.src,h),h.activeSrc&&n.loadImg(h.activeSrc,h,"$activeResolve")];Promise.all(u).then((function(t){var s=t[0],a=t[1];n[i][e][o]={defaultImg:s,activeImg:a},r()})).catch((function(i){console.error(t+"["+e+"].imgs["+o+"] "+i),s()}))}}}))]}))}))},l.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)]},l.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,u=n.ctx,l=n._defaultConfig,f=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,u),u.clearRect(0,0,this.boxWidth,this.boxHeight),this.cells=o(o([],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,o=t.w,a=t.h,c=function(t){var e,i=(null===(e=t.padding)||void 0===e?void 0:e.replace(/px/g,"").split(" ").map((function(t){return~~t})))||[0],n=0,r=0,o=0,a=0;switch(i.length){case 1:n=r=o=a=i[0];break;case 2:n=r=i[0],o=a=i[1];break;case 3:n=i[0],o=a=i[1],r=i[2];break;default:n=i[0],r=i[1],o=i[2],a=i[3]}var h={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:a};for(var u in h)h[u]=Object.prototype.hasOwnProperty.call(t,u)&&s(t[u],"string","number")?~~String(t[u]).replace(/px/g,""):h[u];return[n,r,o,a]}(e),l=c[0],d=c[1],p=c[2],g=c[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||f.background;return h(v)&&C(u,n,r,o,a,m,i.handleBackground(n,r,o,a,v)),{x:n+p,y:r+l,w:o-p-g,h:a-l-d}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight}),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],s=n[1],l=n[2],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var m=g?d.background:t.background||f.background;if(h(m)){var v=(g?d.shadow:t.shadow||f.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===v.length&&(u.shadowColor=v[3],u.shadowOffsetX=v[0]*r.dpr,u.shadowOffsetY=v[1]*r.dpr,u.shadowBlur=v[2],v[0]>0?l-=v[0]:(l+=v[0],o-=v[0]),v[1]>0?p-=v[1]:(p+=v[1],s-=v[1])),C(u,o,s,l,p,i.getLength(t.borderRadius?t.borderRadius:f.borderRadius),i.handleBackground(o,s,l,p,m)),u.shadowColor="rgba(0, 0, 0, 0)",u.shadowOffsetX=0,u.shadowOffsetY=0,u.shadowBlur=0}var w="prizeImgs";e>=i.prizes.length&&(w="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[w][e]){var a=i[w][e][r];if(a){var h=g&&a.activeImg||a.defaultImg;if(h){var u=i.computedWidthAndHeight(h,n,t),c=u[0],l=u[1],f=[o+i.getOffsetX(c,t.col),s+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(h,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&d.fontStyle?d.fontStyle:e.fontStyle||f.fontStyle,r=g&&d.fontWeight?d.fontWeight:e.fontWeight||f.fontWeight,h=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(e.fontSize||f.fontSize),l=g&&d.lineHeight?d.lineHeight:e.lineHeight||f.lineHeight||e.fontSize||f.fontSize,p=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:f.wordWrap,m=e.lengthLimit||f.lengthLimit,v=e.lineClamp||f.lineClamp;u.font=r+" "+(h>>0)+"px "+n,u.fillStyle=g&&d.fontColor?d.fontColor:e.fontColor||f.fontColor;var w=[],b=String(e.text);if(p){var y=i.getWidth(m,t.col);w=c(u,a(b),(function(){return y}),v)}else w=b.split("\n");w.forEach((function(n,r){u.fillText(n,o+i.getOffsetX(u.measureText(n).width,t.col),s+i.getHeight(e.top,t.row)+(r+1)*i.getLength(l))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,u)},l.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},l.prototype.play=function(){var t=this.config.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},l.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=u(e)}t<0?(this.prizeFlag=-1,this.currIndex=0,this.draw()):this.prizeFlag=t%this.prizes.length},l.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;if(-1!==o){var 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(O.easeOut(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+O.easeIn(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},l.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopIndex,s=e.endIndex,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.currIndex=O.easeOut(h,o,s,a.decelerationTime)%n.length,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},l.prototype.walk=function(){var t=this,e=this.config,i=e.setInterval;(0,e.clearInterval)(this.timer),this.timer=i((function(){t.currIndex+=1,t.draw()}),1300)},l.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=void 0===n?1:n,o=t[3],s=void 0===o?1:o,a=this.cellWidth,h=this.cellHeight,u=this._defaultConfig.gutter,c=[this.prizeArea.x+(a+u)*e,this.prizeArea.y+(h+u)*i];return r&&s&&c.push(a*r+u*(r-1),h*s+u*(s-1)),c},l.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},l.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},l.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},l.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},l}(z);export{E as LuckyGrid,R as LuckyWheel}; | ||
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])},t(e,i)};function e(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");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},i.apply(this,arguments)};function n(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}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(t){var e=[],i=t.map((function(t){return Number(t)})).reduce((function(t,i){if(i>0){var n=t+i;return e.push(n),n}return e.push(NaN),t}),0),n=Math.random()*i;return e.findIndex((function(t){return n<=t}))},c=function(t,e,i,n){void 0===n&&(n=1/0),n<=0&&(n=1/0);for(var r="",o=[],s=t.measureText("...").width,a=0;a<e.length;a++){r+=e[a];var h=t.measureText(r).width,u=i(o);if(n===o.length+1&&(h+=s),u<0)return o;if(h>u&&(o.push(r.slice(0,-1)),r=e[a]),n===o.length)return o[o.length-1]+="...",o}return r&&o.push(r),o.length||o.push(e),o},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}(),f="__proto__"in{};function d(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var p=Array.prototype,g=Object.create(p);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){g[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=p[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var m=function(){function t(t){this.dep=new l,d(t,"__luckyOb__",this),Array.isArray(t)&&(f?t.__proto__=g:Object.getOwnPropertyNames(g).forEach((function(e){d(t,e,g[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){w(t,e,t[e])}))},t}();function v(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new m(t)}function w(t,e,i){var n=new l,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=v(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return l.target&&(n.addSub(l.target),a&&a.dep.addSub(l.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=v(e),n.notify()))}})}}var b=0,y=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=b++,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){s(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}(),z=function(){function t(t,e){var i=this;this.version="1.5.14",this.htmlFontSize=16,this.rAF=function(){},this.boxWidth=0,this.boxHeight=0,"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,this.data=e,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el)),t.divElement&&(t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.canvasElement&&(t.ctx=t.canvasElement.getContext("2d"),t.canvasElement.setAttribute("package","lucky-canvas@1.5.14"),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&window.addEventListener("resize",function(t,e){void 0===e&&(e=300);var i=null;return function(){for(var n=this,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i||(i=setTimeout((function(){t.apply(n,r),clearTimeout(i),i=null}),e))}}((function(){i.resize()}),300))}return t.prototype.resize=function(){this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){this.resize(),this.boxWidth&&this.boxHeight||console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},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.resetWidthAndHeight=function(){var t=this.config,e=this.data,i=0,n=0;t.divElement&&(i=t.divElement.offsetWidth,n=t.divElement.offsetHeight),this.boxWidth=this.getLength(e.width||t.width)||i,this.boxHeight=this.getLength(e.height||t.height)||n,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=this.boxWidth+"px",t.divElement.style.height=this.boxHeight+"px")},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=[this.boxWidth*n,this.boxHeight*n],o=r[0],s=r[1];i&&(i.width=o,i.height=s,i.style.width=o+"px",i.style.height=s+"px",i.style["transform-origin"]="left top",i.style.transform="scale("+1/n+")",e.scale(n,n))},t.prototype.initWindowFunction=function(){var t=this.config;if(window)return this.rAF=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},t.setTimeout=window.setTimeout,t.setInterval=window.setInterval,t.clearTimeout=window.clearTimeout,void(t.clearInterval=window.clearInterval);if(t.rAF)this.rAF=t.rAF;else if(t.setTimeout){var e=t.setTimeout;this.rAF=function(t){return e(t,16.7)}}else this.rAF=function(t){return setTimeout(t,16.7)}},t.prototype.loadImg=function(t,e,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r,o){if(t||o("=> '"+e.src+"' 不能为空或不合法"),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var s=new Image;s.onload=function(){return r(s)},s.onerror=function(){return o("=> '"+e.src+"' 图片加载失败")},s.src=t}))},t.prototype.drawImage=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n,r=this,s=r.config,a=r.ctx;if(["WEB","MP-WX"].includes(s.flag))n=t;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s.flag))return console.error("意料之外的 flag, 该平台尚未兼容!");n=t.path}return a.drawImage.apply(a,o([n],e))},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},vw:function(t){return t/100*window.innerWidth}}[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&&w(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 y(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},I=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},k=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)>=x(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],p=k(u,c),g=p[0],m=p[1],v=k(f,d),w=v[0],b=v[1],y=(b-m)/(g-w),z=(w*m-g*b)/(w-g);isNaN(y)&&(Math.abs(u)===+i.toFixed(8)&&(y=u),Math.abs(f)===+i.toFixed(8)&&(y=f)),g===1/0||g===-1/0?z=w*y+b:w!==1/0&&w!==-1/0||(z=g*y+m),e.lineTo(u,c),t.indexOf("MP")>0?e.quadraticCurveTo(y,z,f,d):e.arcTo(y,z,f,d,i)},T=function(t,e,i,n,r,o,s,a){i||(i=s);var h=x(90/Math.PI/n*s),u=x(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()},C=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()},O={easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e}},W={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*Math.cos(t/n*(Math.PI/2))+i+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sin(t/n*(Math.PI/2))+e}},$={easeIn:function(t,e,i,n){return t>=n&&(t=n),0==t?e:i*Math.pow(2,10*(t/n-1))+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),t==n?e+i:i*(1-Math.pow(2,-10*t/n))+e}},P={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*(Math.sqrt(1-(t/=n)*t)-1)+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sqrt(1-(t=t/n-1)*t)+e}},_=Object.freeze({__proto__:null,quad:O,cubic:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t+1)+e}},quart:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*((t=t/n-1)*t*t*t-1)+e}},quint:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t*t*t+1)+e}},sine:W,expo:$,circ:P}),R=function(t){function o(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;return r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r._defaultConfig={},r._defaultStyle={},r.Radius=0,r.prizeRadius=0,r.prizeDeg=0,r.prizeRadian=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.FPS=16.6,r.blockImgs=[[]],r.prizeImgs=[[]],r.btnImgs=[[]],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:r.buttons.map((function(t){return t.imgs}))}),r}return e(o,t),o.prototype.resize=function(){t.prototype.resize.call(this),this.Radius=Math.min(this.boxWidth,this.boxHeight)/2,this.ctx.translate(this.Radius,this.Radius),this.draw()},o.prototype.initLucky=function(){this.Radius=0,this.prizeRadius=0,this.prizeDeg=0,this.prizeRadian=0,this.rotateDeg=0,this.maxBtnRadius=0,this.startTime=0,this.endTime=0,this.stopDeg=0,this.endDeg=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},o.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){return i({gutter:"0px",offsetDegree:0,speed:20,speedFunction:"quad",accelerationTime:2500,decelerationTime:2500,stopRange:0},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return i({fontSize:"18px",fontColor:"#000",fontStyle:"sans-serif",fontWeight:"400",background:"rgba(0,0,0,0)",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},o.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){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({})}))},o.prototype.init=function(t){var e,i,n=this;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},o.prototype.handleClick=function(t){var e,i=this.ctx;i.beginPath(),i.arc(0,0,this.maxBtnRadius,0,2*Math.PI,!1),i.isPointInPath(t.offsetX,t.offsetY)&&(this.startTime||null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i,o){return n(this,void 0,void 0,(function(){var n=this;return r(this,(function(r){return[2,new Promise((function(r,s){var a=n[t][e];if(a&&a.imgs){var h=a.imgs[o];h&&(n[i][e]||(n[i][e]=[]),n.loadImg(h.src,h).then((function(t){"function"==typeof h.formatter&&(t=h.formatter.call(n,t)),n[i][e][o]=t,r()})).catch((function(i){console.error(t+"["+e+"].imgs["+o+"] "+i),s()})))}}))]}))}))},o.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)]},o.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(x(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=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+s.offsetDegree),f=function(t){return i.getOffsetX(o.measureText(t).width)},d=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=l+e*i.prizeRadian,p=i.prizeRadius-i.maxBtnRadius,g=t.background||u.background;h(g)&&function(t,e,i,n,r,o,s,a){s?T(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 m=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(m,v),o.rotate(n+x(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,p),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,p)],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,l=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,g=t.lengthLimit||u.lengthLimit,m=t.lineClamp||u.lineClamp;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+h;var v=String(t.text);(l?c(o,a(v),(function(e){var n=2*((i.prizeRadius-d(t,p,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(s.gutter);return i.getWidth(g,n)}),m):v.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,f(e),d(t,p,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-m,-v)})),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,f(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.prototype.play=function(){this.startTime||(this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},o.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=u(e)}t<0?(this.prizeFlag=-1,this.rotateDeg=0,this.draw()):this.prizeFlag=t%this.prizes.length},o.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;if(-1!==n){var 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=(Math.random()*r-r/2)*this.getLength(s.stopRange),u=0;++u;){var c=360*u-n*r-o-s.offsetDegree+h-r/2;if(_[s.speedFunction].easeOut(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+_[s.speedFunction].easeIn(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},o.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopDeg,s=e.endDeg,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>=a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.rotateDeg=_[a.speedFunction].easeOut(h,o,s,a.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},o.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},o.prototype.getHeight=function(t,e){return void 0===e&&(e=this.prizeRadius),s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},o.prototype.getOffsetX=function(t){return-t/2},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),E=function(t){function l(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;r.rows=3,r.cols=3,r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r.activeStyle={},r._defaultConfig={},r._defaultStyle={},r._activeStyle={},r.cellWidth=0,r.cellHeight=0,r.startTime=0,r.endTime=0,r.currIndex=0,r.stopIndex=0,r.endIndex=0,r.demo=!1,r.timer=0,r.FPS=16.6,r.prizeFlag=-1,r.cells=[],r.blockImgs=[[]],r.btnImgs=[[]],r.prizeImgs=[],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r);var o=r.buttons.map((function(t){return t.imgs}));return r.button&&o.push(r.button.imgs),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:o}),r}return e(l,t),l.prototype.resize=function(){t.prototype.resize.call(this),this.draw()},l.prototype.initLucky=function(){this.cellWidth=0,this.cellHeight=0,this.startTime=0,this.endTime=0,this.currIndex=0,this.stopIndex=0,this.endIndex=0,this.demo=!1,this.timer=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},l.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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)},l.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:"rgba(0,0,0,0)",shadow:"",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)})),this.$computed(this,"_activeStyle",(function(){return i({background:"#ffce98",shadow:""},t.activeStyle)}))},l.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=e.map((function(t){return t.imgs}));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}));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({})}))},l.prototype.init=function(t){var e,i,n=this;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},l.prototype.handleClick=function(t){var e=this,i=this.ctx;o(o([],this.buttons),[this.button]).forEach((function(n){var r;if(n){var o=e.getGeometricProperty([n.x,n.y,n.col||1,n.row||1]),s=o[0],a=o[1],h=o[2],u=o[3];i.beginPath(),i.rect(s,a,h,u),i.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||("function"==typeof n.callback&&n.callback.call(e,n),null===(r=e.startCallback)||void 0===r||r.call(e,t,n)))}}))},l.prototype.loadAndCacheImg=function(t,e,i,o){return n(this,void 0,void 0,(function(){var n=this;return r(this,(function(r){return[2,new Promise((function(r,s){var a=n[t][e];if("buttons"===t&&!n.buttons.length&&n.button&&(a=n.button),a&&a.imgs){var h=a.imgs[o];if(h){n[i][e]||(n[i][e]=[]);var u=[n.loadImg(h.src,h),h.activeSrc&&n.loadImg(h.activeSrc,h,"$activeResolve")];Promise.all(u).then((function(t){var s=t[0],a=t[1],u=h.formatter;"function"==typeof u&&(s=u.call(n,s),a&&(a=u.call(n,a))),n[i][e][o]={defaultImg:s,activeImg:a},r()})).catch((function(i){console.error(t+"["+e+"].imgs["+o+"] "+i),s()}))}}}))]}))}))},l.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)]},l.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,u=n.ctx,l=n._defaultConfig,f=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,u),u.clearRect(0,0,this.boxWidth,this.boxHeight),this.cells=o(o([],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,o=t.w,a=t.h,c=function(t){var e,i=(null===(e=t.padding)||void 0===e?void 0:e.replace(/px/g,"").split(" ").map((function(t){return~~t})))||[0],n=0,r=0,o=0,a=0;switch(i.length){case 1:n=r=o=a=i[0];break;case 2:n=r=i[0],o=a=i[1];break;case 3:n=i[0],o=a=i[1],r=i[2];break;default:n=i[0],r=i[1],o=i[2],a=i[3]}var h={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:a};for(var u in h)h[u]=Object.prototype.hasOwnProperty.call(t,u)&&s(t[u],"string","number")?~~String(t[u]).replace(/px/g,""):h[u];return[n,r,o,a]}(e),l=c[0],d=c[1],p=c[2],g=c[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||f.background;return h(v)&&C(u,n,r,o,a,m,i.handleBackground(n,r,o,a,v)),{x:n+p,y:r+l,w:o-p-g,h:a-l-d}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight}),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],s=n[1],l=n[2],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var m=g?d.background:t.background||f.background;if(h(m)){var v=(g?d.shadow:t.shadow||f.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===v.length&&(u.shadowColor=v[3],u.shadowOffsetX=v[0]*r.dpr,u.shadowOffsetY=v[1]*r.dpr,u.shadowBlur=v[2],v[0]>0?l-=v[0]:(l+=v[0],o-=v[0]),v[1]>0?p-=v[1]:(p+=v[1],s-=v[1])),C(u,o,s,l,p,i.getLength(t.borderRadius?t.borderRadius:f.borderRadius),i.handleBackground(o,s,l,p,m)),u.shadowColor="rgba(0, 0, 0, 0)",u.shadowOffsetX=0,u.shadowOffsetY=0,u.shadowBlur=0}var w="prizeImgs";e>=i.prizes.length&&(w="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[w][e]){var a=i[w][e][r];if(a){var h=g&&a.activeImg||a.defaultImg;if(h){var u=i.computedWidthAndHeight(h,n,t),c=u[0],l=u[1],f=[o+i.getOffsetX(c,t.col),s+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(h,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&d.fontStyle?d.fontStyle:e.fontStyle||f.fontStyle,r=g&&d.fontWeight?d.fontWeight:e.fontWeight||f.fontWeight,h=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(e.fontSize||f.fontSize),l=g&&d.lineHeight?d.lineHeight:e.lineHeight||f.lineHeight||e.fontSize||f.fontSize,p=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:f.wordWrap,m=e.lengthLimit||f.lengthLimit,v=e.lineClamp||f.lineClamp;u.font=r+" "+(h>>0)+"px "+n,u.fillStyle=g&&d.fontColor?d.fontColor:e.fontColor||f.fontColor;var w=[],b=String(e.text);if(p){var y=i.getWidth(m,t.col);w=c(u,a(b),(function(){return y}),v)}else w=b.split("\n");w.forEach((function(n,r){u.fillText(n,o+i.getOffsetX(u.measureText(n).width,t.col),s+i.getHeight(e.top,t.row)+(r+1)*i.getLength(l))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,u)},l.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},l.prototype.play=function(){var t=this.config.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},l.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=u(e)}t<0?(this.prizeFlag=-1,this.currIndex=0,this.draw()):this.prizeFlag=t%this.prizes.length},l.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;if(-1!==o){var 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(O.easeOut(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+O.easeIn(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},l.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopIndex,s=e.endIndex,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.currIndex=O.easeOut(h,o,s,a.decelerationTime)%n.length,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},l.prototype.walk=function(){var t=this,e=this.config,i=e.setInterval;(0,e.clearInterval)(this.timer),this.timer=i((function(){t.currIndex+=1,t.draw()}),1300)},l.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=void 0===n?1:n,o=t[3],s=void 0===o?1:o,a=this.cellWidth,h=this.cellHeight,u=this._defaultConfig.gutter,c=[this.prizeArea.x+(a+u)*e,this.prizeArea.y+(h+u)*i];return r&&s&&c.push(a*r+u*(r-1),h*s+u*(s-1)),c},l.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},l.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},l.prototype.getOffsetX=function(t,e){return void 0===e&&(e=1),(this.cellWidth*e+this._defaultConfig.gutter*(e-1)-t)/2},l.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},l}(z);export{E as LuckyGrid,R as LuckyWheel}; |
@@ -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])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");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},n.apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}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}))},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},u=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},c=function(t){var e=[],i=t.map((function(t){return Number(t)})).reduce((function(t,i){if(i>0){var n=t+i;return e.push(n),n}return e.push(NaN),t}),0),n=Math.random()*i;return e.findIndex((function(t){return n<=t}))},l=function(t,e,i,n){void 0===n&&(n=1/0),n<=0&&(n=1/0);for(var r="",o=[],s=t.measureText("...").width,a=0;a<e.length;a++){r+=e[a];var h=t.measureText(r).width,u=i(o);if(n===o.length+1&&(h+=s),u<0)return o;if(h>u&&(o.push(r.slice(0,-1)),r=e[a]),n===o.length)return o[o.length-1]+="...",o}return r&&o.push(r),o.length||o.push(e),o},f="1.5.13",d=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}(),p="__proto__"in{};function g(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var m=Array.prototype,v=Object.create(m);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){v[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=m[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var b=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=v:Object.getOwnPropertyNames(v).forEach((function(e){g(t,e,v[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){y(t,e,t[e])}))},t}();function w(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new b(t)}function y(t,e,i){var n=new d,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=w(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),a&&a.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=w(e),n.notify()))}})}}var z=0,x=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=z++,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(){d.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),d.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}(),I=function(){function t(t,e){var i=this;this.version=f,this.htmlFontSize=16,this.rAF=function(){},this.boxWidth=0,this.boxHeight=0,"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,this.data=e,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el)),t.divElement&&(t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.canvasElement&&(t.ctx=t.canvasElement.getContext("2d"),t.canvasElement.setAttribute("package","lucky-canvas@1.5.13"),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&window.addEventListener("resize",function(t,e){void 0===e&&(e=300);var i=null;return function(){for(var n=this,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i||(i=setTimeout((function(){t.apply(n,r),clearTimeout(i),i=null}),e))}}((function(){i.resize()}),300))}return t.prototype.resize=function(){this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){this.resize(),this.boxWidth&&this.boxHeight||console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},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.resetWidthAndHeight=function(){var t=this.config,e=this.data,i=0,n=0;t.divElement&&(i=t.divElement.offsetWidth,n=t.divElement.offsetHeight),this.boxWidth=this.getLength(e.width||t.width)||i,this.boxHeight=this.getLength(e.height||t.height)||n,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=this.boxWidth+"px",t.divElement.style.height=this.boxHeight+"px")},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=[this.boxWidth*n,this.boxHeight*n],o=r[0],s=r[1];i&&(i.width=o,i.height=s,i.style.width=o+"px",i.style.height=s+"px",i.style["transform-origin"]="left top",i.style.transform="scale("+1/n+")",e.scale(n,n))},t.prototype.initWindowFunction=function(){var t=this.config;if(window)return this.rAF=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},t.setTimeout=window.setTimeout,t.setInterval=window.setInterval,t.clearTimeout=window.clearTimeout,void(t.clearInterval=window.clearInterval);if(t.rAF)this.rAF=t.rAF;else if(t.setTimeout){var e=t.setTimeout;this.rAF=function(t){return e(t,16.7)}}else this.rAF=function(t){return setTimeout(t,16.7)}},t.prototype.loadImg=function(t,e,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r,o){if(t||o("=> '"+e.src+"' 不能为空或不合法"),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var s=new Image;s.onload=function(){return r(s)},s.onerror=function(){return o("=> '"+e.src+"' 图片加载失败")},s.src=t}))},t.prototype.drawImage=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n,r=this,o=r.config,a=r.ctx;if(["WEB","MP-WX"].includes(o.flag))n=t;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(o.flag))return console.error("意料之外的 flag, 该平台尚未兼容!");n=t.path}return a.drawImage.apply(a,s([n],e))},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},vw:function(t){return t/100*window.innerWidth}}[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&&y(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 x(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),k=function(t){return Math.PI/180*t},S=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},T=function(t,e){var i=-t/e;return[i,-i*t+e]},C=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=k(180).toFixed(8)){var a=(r+n)/2;return o?(C(t,e,i,n,a,o),C(t,e,i,a,r,o)):(C(t,e,i,a,r,o),C(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=S(n,i),u=h[0],c=h[1],l=S(r,i),f=l[0],d=l[1],p=T(u,c),g=p[0],m=p[1],v=T(f,d),b=v[0],w=v[1],y=(w-m)/(g-b),z=(b*m-g*w)/(b-g);isNaN(y)&&(Math.abs(u)===+i.toFixed(8)&&(y=u),Math.abs(f)===+i.toFixed(8)&&(y=f)),g===1/0||g===-1/0?z=b*y+w:b!==1/0&&b!==-1/0||(z=g*y+m),e.lineTo(u,c),t.indexOf("MP")>0?e.quadraticCurveTo(y,z,f,d):e.arcTo(y,z,f,d,i)},O=function(t,e,i,n,r,o,s,a){i||(i=s);var h=k(90/Math.PI/n*s),u=k(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,S(c,n)),C(t,e,n,c,l,!0),d>f?C(t,e,i,f,d,!1):e.lineTo.apply(e,S((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},W=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},P={easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e}},$={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*Math.cos(t/n*(Math.PI/2))+i+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sin(t/n*(Math.PI/2))+e}},_={easeIn:function(t,e,i,n){return t>=n&&(t=n),0==t?e:i*Math.pow(2,10*(t/n-1))+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),t==n?e+i:i*(1-Math.pow(2,-10*t/n))+e}},R={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*(Math.sqrt(1-(t/=n)*t)-1)+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sqrt(1-(t=t/n-1)*t)+e}},E=Object.freeze({__proto__:null,quad:P,cubic:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t+1)+e}},quart:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*((t=t/n-1)*t*t*t-1)+e}},quint:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t*t*t+1)+e}},sine:$,expo:_,circ:R}),F=function(t){function e(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;return r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r._defaultConfig={},r._defaultStyle={},r.Radius=0,r.prizeRadius=0,r.prizeDeg=0,r.prizeRadian=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.FPS=16.6,r.blockImgs=[[]],r.prizeImgs=[[]],r.btnImgs=[[]],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:r.buttons.map((function(t){return t.imgs}))}),r}return i(e,t),e.prototype.resize=function(){t.prototype.resize.call(this),this.Radius=Math.min(this.boxWidth,this.boxHeight)/2,this.ctx.translate(this.Radius,this.Radius),this.draw()},e.prototype.initLucky=function(){this.Radius=0,this.prizeRadius=0,this.prizeDeg=0,this.prizeRadian=0,this.rotateDeg=0,this.maxBtnRadius=0,this.startTime=0,this.endTime=0,this.stopDeg=0,this.endDeg=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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,speedFunction:"quad",accelerationTime:2500,decelerationTime:2500,stopRange:0},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({fontSize:"18px",fontColor:"#000",fontStyle:"sans-serif",fontWeight:"400",background:"rgba(0,0,0,0)",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){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;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.handleClick=function(t){var e,i=this.ctx;i.beginPath(),i.arc(0,0,this.maxBtnRadius,0,2*Math.PI,!1),i.isPointInPath(t.offsetX,t.offsetY)&&(this.startTime||null===(e=this.startCallback)||void 0===e||e.call(this,t))},e.prototype.loadAndCacheImg=function(t,e,i,n){return r(this,void 0,void 0,(function(){var r=this;return o(this,(function(o){return[2,new Promise((function(o,s){var a=r[t][e];if(a&&a.imgs){var h=a.imgs[n];h&&(r[i][e]||(r[i][e]=[]),r.loadImg(h.src,h).then((function(t){r[i][e][n]=t,o()})).catch((function(i){console.error(t+"["+e+"].imgs["+n+"] "+i),s()})))}}))]}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,a=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e,n){return u(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(k(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=k(this.prizeDeg);var c=k(this.rotateDeg-90+this.prizeDeg/2+s.offsetDegree),f=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||a.lineHeight||t.fontSize||a.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,p=i.prizeRadius-i.maxBtnRadius,g=t.background||a.background;u(g)&&function(t,e,i,n,r,o,s,a){s?O(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 m=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(m,v),o.rotate(n+k(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,p),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,p)],u=h[0],c=h[1];i.drawImage(r,u,c,s,a)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,n=t.fontWeight||a.fontWeight,r=i.getLength(t.fontSize||a.fontSize),u=t.fontStyle||a.fontStyle,c=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:a.wordWrap,g=t.lengthLimit||a.lengthLimit,m=t.lineClamp||a.lineClamp;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+u;var v=String(t.text);(c?l(o,h(v),(function(e){var n=2*((i.prizeRadius-d(t,p,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(s.gutter);return i.getWidth(g,n)}),m):v.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,f(e),d(t,p,i))}))})),o.rotate(k(360)-n-k(90)),o.translate(-m,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),u(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&u(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||a.fontColor,r=t.fontWeight||a.fontWeight,s=i.getLength(t.fontSize||a.fontSize),h=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=r+" "+(s>>0)+"px "+h,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,f(e),d(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){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=c(e)}t<0?(this.prizeFlag=-1,this.rotateDeg=0,this.draw()):this.prizeFlag=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;if(-1!==n){var 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=(Math.random()*r-r/2)*this.getLength(s.stopRange),u=0;++u;){var c=360*u-n*r-o-s.offsetDegree+h-r/2;if(E[s.speedFunction].easeOut(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+E[s.speedFunction].easeIn(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},e.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopDeg,s=e.endDeg,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>=a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.rotateDeg=E[a.speedFunction].easeOut(h,o,s,a.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},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.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},e}(I),D=function(t){function e(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;r.rows=3,r.cols=3,r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r.activeStyle={},r._defaultConfig={},r._defaultStyle={},r._activeStyle={},r.cellWidth=0,r.cellHeight=0,r.startTime=0,r.endTime=0,r.currIndex=0,r.stopIndex=0,r.endIndex=0,r.demo=!1,r.timer=0,r.FPS=16.6,r.prizeFlag=-1,r.cells=[],r.blockImgs=[[]],r.btnImgs=[[]],r.prizeImgs=[],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r);var o=r.buttons.map((function(t){return t.imgs}));return r.button&&o.push(r.button.imgs),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:o}),r}return i(e,t),e.prototype.resize=function(){t.prototype.resize.call(this),this.draw()},e.prototype.initLucky=function(){this.cellWidth=0,this.cellHeight=0,this.startTime=0,this.endTime=0,this.currIndex=0,this.stopIndex=0,this.endIndex=0,this.demo=!1,this.timer=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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:"rgba(0,0,0,0)",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("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=e.map((function(t){return t.imgs}));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}));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;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.handleClick=function(t){var e=this,i=this.ctx;s(s([],this.buttons),[this.button]).forEach((function(n){var r;if(n){var o=e.getGeometricProperty([n.x,n.y,n.col||1,n.row||1]),s=o[0],a=o[1],h=o[2],u=o[3];i.beginPath(),i.rect(s,a,h,u),i.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||("function"==typeof n.callback&&n.callback.call(e,n),null===(r=e.startCallback)||void 0===r||r.call(e,t,n)))}}))},e.prototype.loadAndCacheImg=function(t,e,i,n){return r(this,void 0,void 0,(function(){var r=this;return o(this,(function(o){return[2,new Promise((function(o,s){var a=r[t][e];if("buttons"===t&&!r.buttons.length&&r.button&&(a=r.button),a&&a.imgs){var h=a.imgs[n];if(h){r[i][e]||(r[i][e]=[]);var u=[r.loadImg(h.src,h),h.activeSrc&&r.loadImg(h.activeSrc,h,"$activeResolve")];Promise.all(u).then((function(t){var s=t[0],a=t[1];r[i][e][n]={defaultImg:s,activeImg:a},o()})).catch((function(i){console.error(t+"["+e+"].imgs["+n+"] "+i),s()}))}}}))]}))}))},e.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,c=n._defaultConfig,f=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,this.boxWidth,this.boxHeight),this.cells=s(s([],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,h=t.h,c=function(t){var e,i=(null===(e=t.padding)||void 0===e?void 0:e.replace(/px/g,"").split(" ").map((function(t){return~~t})))||[0],n=0,r=0,o=0,s=0;switch(i.length){case 1:n=r=o=s=i[0];break;case 2:n=r=i[0],o=s=i[1];break;case 3:n=i[0],o=s=i[1],r=i[2];break;default:n=i[0],r=i[1],o=i[2],s=i[3]}var h={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:s};for(var u in h)h[u]=Object.prototype.hasOwnProperty.call(t,u)&&a(t[u],"string","number")?~~String(t[u]).replace(/px/g,""):h[u];return[n,r,o,s]}(e),l=c[0],d=c[1],p=c[2],g=c[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||f.background;return u(v)&&W(o,n,r,s,h,m,i.handleBackground(n,r,s,h,v)),{x:n+p,y:r+l,w:s-p-g,h:h-l-d}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight}),this.cellWidth=(this.prizeArea.w-c.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-c.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],a=n[1],c=n[2],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var m=g?d.background:t.background||f.background;if(u(m)){var v=(g?d.shadow:t.shadow||f.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===v.length&&(o.shadowColor=v[3],o.shadowOffsetX=v[0]*r.dpr,o.shadowOffsetY=v[1]*r.dpr,o.shadowBlur=v[2],v[0]>0?c-=v[0]:(c+=v[0],s-=v[0]),v[1]>0?p-=v[1]:(p+=v[1],a-=v[1])),W(o,s,a,c,p,i.getLength(t.borderRadius?t.borderRadius:f.borderRadius),i.handleBackground(s,a,c,p,m)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0}var b="prizeImgs";e>=i.prizes.length&&(b="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[b][e]){var o=i[b][e][r];if(o){var h=g&&o.activeImg||o.defaultImg;if(h){var u=i.computedWidthAndHeight(h,n,t),c=u[0],l=u[1],f=[s+i.getOffsetX(c,t.col),a+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(h,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&d.fontStyle?d.fontStyle:e.fontStyle||f.fontStyle,r=g&&d.fontWeight?d.fontWeight:e.fontWeight||f.fontWeight,u=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(e.fontSize||f.fontSize),c=g&&d.lineHeight?d.lineHeight:e.lineHeight||f.lineHeight||e.fontSize||f.fontSize,p=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:f.wordWrap,m=e.lengthLimit||f.lengthLimit,v=e.lineClamp||f.lineClamp;o.font=r+" "+(u>>0)+"px "+n,o.fillStyle=g&&d.fontColor?d.fontColor:e.fontColor||f.fontColor;var b=[],w=String(e.text);if(p){var y=i.getWidth(m,t.col);b=l(o,h(w),(function(){return y}),v)}else b=w.split("\n");b.forEach((function(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),a+i.getHeight(e.top,t.row)+(r+1)*i.getLength(c))}))}))})),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.config.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},e.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=c(e)}t<0?(this.prizeFlag=-1,this.currIndex=0,this.draw()):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;if(-1!==o){var 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(P.easeOut(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+P.easeIn(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},e.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopIndex,s=e.endIndex,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.currIndex=P.easeOut(h,o,s,a.decelerationTime)%n.length,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},e.prototype.walk=function(){var t=this,e=this.config,i=e.setInterval;(0,e.clearInterval)(this.timer),this.timer=i((function(){t.currIndex+=1,t.draw()}),1300)},e.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=void 0===n?1:n,o=t[3],s=void 0===o?1:o,a=this.cellWidth,h=this.cellHeight,u=this._defaultConfig.gutter,c=[this.prizeArea.x+(a+u)*e,this.prizeArea.y+(h+u)*i];return r&&s&&c.push(a*r+u*(r-1),h*s+u*(s-1)),c},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.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},e}(I);t.LuckyGrid=D,t.LuckyWheel=F,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])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");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},n.apply(this,arguments)};function r(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}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}))},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},u=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},c=function(t){var e=[],i=t.map((function(t){return Number(t)})).reduce((function(t,i){if(i>0){var n=t+i;return e.push(n),n}return e.push(NaN),t}),0),n=Math.random()*i;return e.findIndex((function(t){return n<=t}))},l=function(t,e,i,n){void 0===n&&(n=1/0),n<=0&&(n=1/0);for(var r="",o=[],s=t.measureText("...").width,a=0;a<e.length;a++){r+=e[a];var h=t.measureText(r).width,u=i(o);if(n===o.length+1&&(h+=s),u<0)return o;if(h>u&&(o.push(r.slice(0,-1)),r=e[a]),n===o.length)return o[o.length-1]+="...",o}return r&&o.push(r),o.length||o.push(e),o},f="1.5.14",d=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}(),p="__proto__"in{};function g(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var m=Array.prototype,v=Object.create(m);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){v[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=m[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var b=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=v:Object.getOwnPropertyNames(v).forEach((function(e){g(t,e,v[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){y(t,e,t[e])}))},t}();function w(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new b(t)}function y(t,e,i){var n=new d,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=w(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),a&&a.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!s||(s?s.call(t,e):i=e,a=w(e),n.notify()))}})}}var z=0,x=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=z++,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(){d.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),d.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}(),I=function(){function t(t,e){var i=this;this.version=f,this.htmlFontSize=16,this.rAF=function(){},this.boxWidth=0,this.boxHeight=0,"string"==typeof t?t={el:t}:1===t.nodeType&&(t={el:"",divElement:t}),t=t,this.config=t,this.data=e,t.flag||(t.flag="WEB"),t.el&&(t.divElement=document.querySelector(t.el)),t.divElement&&(t.canvasElement=document.createElement("canvas"),t.divElement.appendChild(t.canvasElement)),t.canvasElement&&(t.ctx=t.canvasElement.getContext("2d"),t.canvasElement.setAttribute("package","lucky-canvas@1.5.14"),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&window.addEventListener("resize",function(t,e){void 0===e&&(e=300);var i=null;return function(){for(var n=this,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];i||(i=setTimeout((function(){t.apply(n,r),clearTimeout(i),i=null}),e))}}((function(){i.resize()}),300))}return t.prototype.resize=function(){this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){this.resize(),this.boxWidth&&this.boxHeight||console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},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.resetWidthAndHeight=function(){var t=this.config,e=this.data,i=0,n=0;t.divElement&&(i=t.divElement.offsetWidth,n=t.divElement.offsetHeight),this.boxWidth=this.getLength(e.width||t.width)||i,this.boxHeight=this.getLength(e.height||t.height)||n,t.divElement&&(t.divElement.style.overflow="hidden",t.divElement.style.width=this.boxWidth+"px",t.divElement.style.height=this.boxHeight+"px")},t.prototype.zoomCanvas=function(){var t=this.config,e=this.ctx,i=t.canvasElement,n=t.dpr,r=[this.boxWidth*n,this.boxHeight*n],o=r[0],s=r[1];i&&(i.width=o,i.height=s,i.style.width=o+"px",i.style.height=s+"px",i.style["transform-origin"]="left top",i.style.transform="scale("+1/n+")",e.scale(n,n))},t.prototype.initWindowFunction=function(){var t=this.config;if(window)return this.rAF=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},t.setTimeout=window.setTimeout,t.setInterval=window.setInterval,t.clearTimeout=window.clearTimeout,void(t.clearInterval=window.clearInterval);if(t.rAF)this.rAF=t.rAF;else if(t.setTimeout){var e=t.setTimeout;this.rAF=function(t){return e(t,16.7)}}else this.rAF=function(t){return setTimeout(t,16.7)}},t.prototype.loadImg=function(t,e,i){var n=this;return void 0===i&&(i="$resolve"),new Promise((function(r,o){if(t||o("=> '"+e.src+"' 不能为空或不合法"),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var s=new Image;s.onload=function(){return r(s)},s.onerror=function(){return o("=> '"+e.src+"' 图片加载失败")},s.src=t}))},t.prototype.drawImage=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n,r=this,o=r.config,a=r.ctx;if(["WEB","MP-WX"].includes(o.flag))n=t;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(o.flag))return console.error("意料之外的 flag, 该平台尚未兼容!");n=t.path}return a.drawImage.apply(a,s([n],e))},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},vw:function(t){return t/100*window.innerWidth}}[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&&y(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 x(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),k=function(t){return Math.PI/180*t},S=function(t,e){return[+(Math.cos(t)*e).toFixed(8),+(Math.sin(t)*e).toFixed(8)]},T=function(t,e){var i=-t/e;return[i,-i*t+e]},C=function(t,e,i,n,r,o){var s;if(void 0===o&&(o=!0),Math.abs(r-n).toFixed(8)>=k(180).toFixed(8)){var a=(r+n)/2;return o?(C(t,e,i,n,a,o),C(t,e,i,a,r,o)):(C(t,e,i,a,r,o),C(t,e,i,n,a,o)),!1}o||(n=(s=[r,n])[0],r=s[1]);var h=S(n,i),u=h[0],c=h[1],l=S(r,i),f=l[0],d=l[1],p=T(u,c),g=p[0],m=p[1],v=T(f,d),b=v[0],w=v[1],y=(w-m)/(g-b),z=(b*m-g*w)/(b-g);isNaN(y)&&(Math.abs(u)===+i.toFixed(8)&&(y=u),Math.abs(f)===+i.toFixed(8)&&(y=f)),g===1/0||g===-1/0?z=b*y+w:b!==1/0&&b!==-1/0||(z=g*y+m),e.lineTo(u,c),t.indexOf("MP")>0?e.quadraticCurveTo(y,z,f,d):e.arcTo(y,z,f,d,i)},O=function(t,e,i,n,r,o,s,a){i||(i=s);var h=k(90/Math.PI/n*s),u=k(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,S(c,n)),C(t,e,n,c,l,!0),d>f?C(t,e,i,f,d,!1):e.lineTo.apply(e,S((r+o)/2,s/2/Math.abs(Math.sin((r-o)/2)))),e.closePath(),e.fill()},W=function(t,e,i,n,r,o,s){var a=Math.min(n,r);o>a/2&&(o=a/2),t.beginPath(),t.fillStyle=s,t.moveTo(e+o,i),t.lineTo(e+o,i),t.lineTo(e+n-o,i),t.quadraticCurveTo(e+n,i,e+n,i+o),t.lineTo(e+n,i+r-o),t.quadraticCurveTo(e+n,i+r,e+n-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath(),t.fill()},P={easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e}},$={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*Math.cos(t/n*(Math.PI/2))+i+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sin(t/n*(Math.PI/2))+e}},_={easeIn:function(t,e,i,n){return t>=n&&(t=n),0==t?e:i*Math.pow(2,10*(t/n-1))+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),t==n?e+i:i*(1-Math.pow(2,-10*t/n))+e}},R={easeIn:function(t,e,i,n){return t>=n&&(t=n),-i*(Math.sqrt(1-(t/=n)*t)-1)+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*Math.sqrt(1-(t=t/n-1)*t)+e}},E=Object.freeze({__proto__:null,quad:P,cubic:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t+1)+e}},quart:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),-i*((t=t/n-1)*t*t*t-1)+e}},quint:{easeIn:function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t*t*t*t+e},easeOut:function(t,e,i,n){return t>=n&&(t=n),i*((t=t/n-1)*t*t*t*t+1)+e}},sine:$,expo:_,circ:R}),F=function(t){function e(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;return r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r._defaultConfig={},r._defaultStyle={},r.Radius=0,r.prizeRadius=0,r.prizeDeg=0,r.prizeRadian=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.FPS=16.6,r.blockImgs=[[]],r.prizeImgs=[[]],r.btnImgs=[[]],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:r.buttons.map((function(t){return t.imgs}))}),r}return i(e,t),e.prototype.resize=function(){t.prototype.resize.call(this),this.Radius=Math.min(this.boxWidth,this.boxHeight)/2,this.ctx.translate(this.Radius,this.Radius),this.draw()},e.prototype.initLucky=function(){this.Radius=0,this.prizeRadius=0,this.prizeDeg=0,this.prizeRadian=0,this.rotateDeg=0,this.maxBtnRadius=0,this.startTime=0,this.endTime=0,this.stopDeg=0,this.endDeg=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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,speedFunction:"quad",accelerationTime:2500,decelerationTime:2500,stopRange:0},t.defaultConfig)})),this.$computed(this,"_defaultStyle",(function(){return n({fontSize:"18px",fontColor:"#000",fontStyle:"sans-serif",fontWeight:"400",background:"rgba(0,0,0,0)",wordWrap:!0,lengthLimit:"90%"},t.defaultStyle)}))},e.prototype.initWatch=function(){var t=this;this.$watch("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){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;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.handleClick=function(t){var e,i=this.ctx;i.beginPath(),i.arc(0,0,this.maxBtnRadius,0,2*Math.PI,!1),i.isPointInPath(t.offsetX,t.offsetY)&&(this.startTime||null===(e=this.startCallback)||void 0===e||e.call(this,t))},e.prototype.loadAndCacheImg=function(t,e,i,n){return r(this,void 0,void 0,(function(){var r=this;return o(this,(function(o){return[2,new Promise((function(o,s){var a=r[t][e];if(a&&a.imgs){var h=a.imgs[n];h&&(r[i][e]||(r[i][e]=[]),r.loadImg(h.src,h).then((function(t){"function"==typeof h.formatter&&(t=h.formatter.call(r,t)),r[i][e][n]=t,o()})).catch((function(i){console.error(t+"["+e+"].imgs["+n+"] "+i),s()})))}}))]}))}))},e.prototype.computedWidthAndHeight=function(t,e,i,n){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var r=this.getWidth(e.width,i);return[r,t.height*(r/t.width)]}if(!e.width&&e.height){var o=this.getHeight(e.height,n);return[t.width*(o/t.height),o]}return[this.getWidth(e.width,i),this.getHeight(e.height,n)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,a=n._defaultStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(-this.Radius,-this.Radius,2*this.Radius,2*this.Radius),this.prizeRadius=this.blocks.reduce((function(t,e,n){return u(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(k(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=k(this.prizeDeg);var c=k(this.rotateDeg-90+this.prizeDeg/2+s.offsetDegree),f=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||a.lineHeight||t.fontSize||a.fontSize;return i.getHeight(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=c+e*i.prizeRadian,p=i.prizeRadius-i.maxBtnRadius,g=t.background||a.background;u(g)&&function(t,e,i,n,r,o,s,a){s?O(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 m=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(m,v),o.rotate(n+k(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,p),s=o[0],a=o[1],h=[i.getOffsetX(s),i.getHeight(t.top,p)],u=h[0],c=h[1];i.drawImage(r,u,c,s,a)}}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||a.fontColor,n=t.fontWeight||a.fontWeight,r=i.getLength(t.fontSize||a.fontSize),u=t.fontStyle||a.fontStyle,c=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:a.wordWrap,g=t.lengthLimit||a.lengthLimit,m=t.lineClamp||a.lineClamp;o.fillStyle=e,o.font=n+" "+(r>>0)+"px "+u;var v=String(t.text);(c?l(o,h(v),(function(e){var n=2*((i.prizeRadius-d(t,p,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(s.gutter);return i.getWidth(g,n)}),m):v.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,f(e),d(t,p,i))}))})),o.rotate(k(360)-n-k(90)),o.translate(-m,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),u(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&u(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||a.fontColor,r=t.fontWeight||a.fontWeight,s=i.getLength(t.fontSize||a.fontSize),h=t.fontStyle||a.fontStyle;o.fillStyle=e,o.font=r+" "+(s>>0)+"px "+h,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,f(e),d(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){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=c(e)}t<0?(this.prizeFlag=-1,this.rotateDeg=0,this.draw()):this.prizeFlag=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;if(-1!==n){var 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=(Math.random()*r-r/2)*this.getLength(s.stopRange),u=0;++u;){var c=360*u-n*r-o-s.offsetDegree+h-r/2;if(E[s.speedFunction].easeOut(this.FPS,this.stopDeg,c,s.decelerationTime)-this.stopDeg>s.speed){this.endDeg=c;break}}return this.slowDown()}this.rotateDeg=(o+E[s.speedFunction].easeIn(a,0,s.speed,s.accelerationTime))%360,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},e.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopDeg,s=e.endDeg,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>=a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.rotateDeg=E[a.speedFunction].easeOut(h,o,s,a.decelerationTime)%360,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},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.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},e}(I),D=function(t){function e(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;r.rows=3,r.cols=3,r.blocks=[],r.prizes=[],r.buttons=[],r.defaultConfig={},r.defaultStyle={},r.activeStyle={},r._defaultConfig={},r._defaultStyle={},r._activeStyle={},r.cellWidth=0,r.cellHeight=0,r.startTime=0,r.endTime=0,r.currIndex=0,r.stopIndex=0,r.endIndex=0,r.demo=!1,r.timer=0,r.FPS=16.6,r.prizeFlag=-1,r.cells=[],r.blockImgs=[[]],r.btnImgs=[[]],r.prizeImgs=[],r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r);var o=r.buttons.map((function(t){return t.imgs}));return r.button&&o.push(r.button.imgs),r.init({blockImgs:r.blocks.map((function(t){return t.imgs})),prizeImgs:r.prizes.map((function(t){return t.imgs})),btnImgs:o}),r}return i(e,t),e.prototype.resize=function(){t.prototype.resize.call(this),this.draw()},e.prototype.initLucky=function(){this.cellWidth=0,this.cellHeight=0,this.startTime=0,this.endTime=0,this.currIndex=0,this.stopIndex=0,this.endIndex=0,this.demo=!1,this.timer=0,this.FPS=16.6,this.prizeFlag=-1,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width||"300px"),this.$set(this,"height",t.height||"300px"),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:"rgba(0,0,0,0)",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("width",(function(e){t.data.width=e,t.resize()})),this.$watch("height",(function(e){t.data.height=e,t.resize()})),this.$watch("blocks",(function(e){t.init({blockImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("prizes",(function(e){t.init({prizeImgs:e.map((function(t){return t.imgs}))})}),{deep:!0}),this.$watch("buttons",(function(e){var i=e.map((function(t){return t.imgs}));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}));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;void 0===t&&(t={}),this.initLucky();var r=this.config;null===(e=r.beforeInit)||void 0===e||e.call(this),this.draw(),Object.keys(t).forEach((function(e){var i;!function(t){t.blockImgs="blocks",t.prizeImgs="prizes",t.btnImgs="buttons"}(i||(i={}));var r=i[e],o=t[e],s=[];o&&o.forEach((function(t,i){t&&t.forEach((function(t,o){s.push(n.loadAndCacheImg(r,i,e,o))}))})),Promise.all(s).then((function(){n.draw()}))})),null===(i=r.afterInit)||void 0===i||i.call(this)},e.prototype.handleClick=function(t){var e=this,i=this.ctx;s(s([],this.buttons),[this.button]).forEach((function(n){var r;if(n){var o=e.getGeometricProperty([n.x,n.y,n.col||1,n.row||1]),s=o[0],a=o[1],h=o[2],u=o[3];i.beginPath(),i.rect(s,a,h,u),i.isPointInPath(t.offsetX,t.offsetY)&&(e.startTime||("function"==typeof n.callback&&n.callback.call(e,n),null===(r=e.startCallback)||void 0===r||r.call(e,t,n)))}}))},e.prototype.loadAndCacheImg=function(t,e,i,n){return r(this,void 0,void 0,(function(){var r=this;return o(this,(function(o){return[2,new Promise((function(o,s){var a=r[t][e];if("buttons"===t&&!r.buttons.length&&r.button&&(a=r.button),a&&a.imgs){var h=a.imgs[n];if(h){r[i][e]||(r[i][e]=[]);var u=[r.loadImg(h.src,h),h.activeSrc&&r.loadImg(h.activeSrc,h,"$activeResolve")];Promise.all(u).then((function(t){var s=t[0],a=t[1],u=h.formatter;"function"==typeof u&&(s=u.call(r,s),a&&(a=u.call(r,a))),r[i][e][n]={defaultImg:s,activeImg:a},o()})).catch((function(i){console.error(t+"["+e+"].imgs["+n+"] "+i),s()}))}}}))]}))}))},e.prototype.computedWidthAndHeight=function(t,e,i){if(!e.width&&!e.height)return[t.width,t.height];if(e.width&&!e.height){var n=this.getWidth(e.width,i.col);return[n,t.height*(n/t.width)]}if(!e.width&&e.height){var r=this.getHeight(e.height,i.row);return[t.width*(r/t.height),r]}return[this.getWidth(e.width,i.col),this.getHeight(e.height,i.row)]},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,c=n._defaultConfig,f=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,this.boxWidth,this.boxHeight),this.cells=s(s([],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,h=t.h,c=function(t){var e,i=(null===(e=t.padding)||void 0===e?void 0:e.replace(/px/g,"").split(" ").map((function(t){return~~t})))||[0],n=0,r=0,o=0,s=0;switch(i.length){case 1:n=r=o=s=i[0];break;case 2:n=r=i[0],o=s=i[1];break;case 3:n=i[0],o=s=i[1],r=i[2];break;default:n=i[0],r=i[1],o=i[2],s=i[3]}var h={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:s};for(var u in h)h[u]=Object.prototype.hasOwnProperty.call(t,u)&&a(t[u],"string","number")?~~String(t[u]).replace(/px/g,""):h[u];return[n,r,o,s]}(e),l=c[0],d=c[1],p=c[2],g=c[3],m=e.borderRadius?i.getLength(e.borderRadius):0,v=e.background||f.background;return u(v)&&W(o,n,r,s,h,m,i.handleBackground(n,r,s,h,v)),{x:n+p,y:r+l,w:s-p-g,h:h-l-d}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight}),this.cellWidth=(this.prizeArea.w-c.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-c.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),s=n[0],a=n[1],c=n[2],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var m=g?d.background:t.background||f.background;if(u(m)){var v=(g?d.shadow:t.shadow||f.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===v.length&&(o.shadowColor=v[3],o.shadowOffsetX=v[0]*r.dpr,o.shadowOffsetY=v[1]*r.dpr,o.shadowBlur=v[2],v[0]>0?c-=v[0]:(c+=v[0],s-=v[0]),v[1]>0?p-=v[1]:(p+=v[1],a-=v[1])),W(o,s,a,c,p,i.getLength(t.borderRadius?t.borderRadius:f.borderRadius),i.handleBackground(s,a,c,p,m)),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0}var b="prizeImgs";e>=i.prizes.length&&(b="btnImgs",e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(n,r){if(i[b][e]){var o=i[b][e][r];if(o){var h=g&&o.activeImg||o.defaultImg;if(h){var u=i.computedWidthAndHeight(h,n,t),c=u[0],l=u[1],f=[s+i.getOffsetX(c,t.col),a+i.getHeight(n.top,t.row)],d=f[0],p=f[1];i.drawImage(h,d,p,c,l)}}}})),t.fonts&&t.fonts.forEach((function(e){var n=g&&d.fontStyle?d.fontStyle:e.fontStyle||f.fontStyle,r=g&&d.fontWeight?d.fontWeight:e.fontWeight||f.fontWeight,u=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(e.fontSize||f.fontSize),c=g&&d.lineHeight?d.lineHeight:e.lineHeight||f.lineHeight||e.fontSize||f.fontSize,p=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:f.wordWrap,m=e.lengthLimit||f.lengthLimit,v=e.lineClamp||f.lineClamp;o.font=r+" "+(u>>0)+"px "+n,o.fillStyle=g&&d.fontColor?d.fontColor:e.fontColor||f.fontColor;var b=[],w=String(e.text);if(p){var y=i.getWidth(m,t.col);b=l(o,h(w),(function(){return y}),v)}else b=w.split("\n");b.forEach((function(n,r){o.fillText(n,s+i.getOffsetX(o.measureText(n).width,t.col),a+i.getHeight(e.top,t.row)+(r+1)*i.getLength(c))}))}))})),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.config.clearInterval;this.startTime||(t(this.timer),this.startTime=Date.now(),this.prizeFlag=void 0,this.run())},e.prototype.stop=function(t){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=c(e)}t<0?(this.prizeFlag=-1,this.currIndex=0,this.draw()):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;if(-1!==o){var 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(P.easeOut(this.FPS,this.stopIndex,c,a.decelerationTime)-this.stopIndex>a.speed){this.endIndex=c;break}}return this.slowDown()}this.currIndex=(n+P.easeIn(h,.1,a.speed,a.accelerationTime))%r.length,this.draw(),i(this.run.bind(this,t+1))}else this.startTime=0},e.prototype.slowDown=function(){var t,e=this,i=e.rAF,n=e.prizes,r=e.prizeFlag,o=e.stopIndex,s=e.endIndex,a=e._defaultConfig;if(-1!==r){var h=Date.now()-this.endTime;if(h>a.decelerationTime)return this.startTime=0,void(null===(t=this.endCallback)||void 0===t||t.call(this,n.find((function(t,e){return e===r}))||{}));this.currIndex=P.easeOut(h,o,s,a.decelerationTime)%n.length,this.draw(),i(this.slowDown.bind(this))}else this.startTime=0},e.prototype.walk=function(){var t=this,e=this.config,i=e.setInterval;(0,e.clearInterval)(this.timer),this.timer=i((function(){t.currIndex+=1,t.draw()}),1300)},e.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=void 0===n?1:n,o=t[3],s=void 0===o?1:o,a=this.cellWidth,h=this.cellHeight,u=this._defaultConfig.gutter,c=[this.prizeArea.x+(a+u)*e,this.prizeArea.y+(h+u)*i];return r&&s&&c.push(a*r+u*(r-1),h*s+u*(s-1)),c},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.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},e}(I);t.LuckyGrid=D,t.LuckyWheel=F,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "lucky-canvas", | ||
"version": "1.5.13", | ||
"version": "1.5.14", | ||
"description": "一个基于原生 js 的(大转盘抽奖 / 九宫格抽奖)插件", | ||
@@ -5,0 +5,0 @@ "module": "dist/lucky-canvas.esm", |
@@ -1,2 +0,2 @@ | ||
declare type FontType = { | ||
declare type FontItemType = { | ||
text: string; | ||
@@ -15,3 +15,4 @@ top?: string | number; | ||
}; | ||
declare type ImgType = { | ||
declare type ImgType = HTMLImageElement | HTMLCanvasElement; | ||
declare type ImgItemType = { | ||
src: string; | ||
@@ -21,2 +22,3 @@ top?: string | number; | ||
height?: string; | ||
formatter?: (img: ImgType) => ImgType; | ||
$resolve?: Function; | ||
@@ -118,3 +120,3 @@ $reject?: Function; | ||
*/ | ||
protected loadImg(src: string, info: ImgType, resolveName?: string): Promise<HTMLImageElement>; | ||
protected loadImg(src: string, info: ImgItemType, resolveName?: string): Promise<ImgType>; | ||
/** | ||
@@ -125,3 +127,3 @@ * 公共绘制图片的方法 | ||
*/ | ||
protected drawImage(imgObj: HTMLImageElement, ...rectInfo: [number, number, number, number]): void; | ||
protected drawImage(imgObj: ImgType, ...rectInfo: [number, number, number, number]): void; | ||
/** | ||
@@ -164,9 +166,9 @@ * 获取长度 | ||
declare type PrizeFontType$1 = FontType & FontExtendType; | ||
declare type ButtonFontType$1 = FontType & {}; | ||
declare type BlockImgType$1 = ImgType & { | ||
declare type PrizeFontType$1 = FontItemType & FontExtendType; | ||
declare type ButtonFontType$1 = FontItemType & {}; | ||
declare type BlockImgType$1 = ImgItemType & { | ||
rotate?: boolean; | ||
}; | ||
declare type PrizeImgType$1 = ImgType & {}; | ||
declare type ButtonImgType$1 = ImgType & {}; | ||
declare type PrizeImgType$1 = ImgItemType & {}; | ||
declare type ButtonImgType$1 = ImgItemType & {}; | ||
declare type BlockType$1 = { | ||
@@ -357,9 +359,9 @@ padding?: string; | ||
declare type PrizeFontType = FontType & FontExtendType; | ||
declare type ButtonFontType = FontType & FontExtendType; | ||
declare type BlockImgType = ImgType & {}; | ||
declare type PrizeImgType = ImgType & { | ||
declare type PrizeFontType = FontItemType & FontExtendType; | ||
declare type ButtonFontType = FontItemType & FontExtendType; | ||
declare type BlockImgType = ImgItemType & {}; | ||
declare type PrizeImgType = ImgItemType & { | ||
activeSrc?: string; | ||
}; | ||
declare type ButtonImgType = ImgType & {}; | ||
declare type ButtonImgType = ImgItemType & {}; | ||
declare type BlockType = { | ||
@@ -388,2 +390,3 @@ borderRadius?: BorderRadiusType; | ||
range?: number; | ||
disabled?: boolean; | ||
}; | ||
@@ -390,0 +393,0 @@ declare type ButtonType = CellType<ButtonFontType, ButtonImgType> & { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
605129
5502