!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"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var 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;i0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;sthis.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;r0){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}))},d=function(t,e,i,n){void 0===n&&(n=1/0),n<=0&&(n=1/0);for(var r="",o=[],a=t.measureText("...").width,s=0;sc&&(o.push(r.slice(0,-1)),r=e[s]),n===o.length)return o[o.length-1]+="...",o}return r&&o.push(r),o.length||o.push(e),o},p="1.7.26",g=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}(),v="__proto__"in{};function m(t,e,i,n){Object.defineProperty(t,e,{value:i,enumerable:!!n,writable:!0,configurable:!0})}var w=Array.prototype,y=Object.create(w);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){y[t]=function(){for(var e=[],i=0;i '"+e.src+"' 不能为空或不合法"),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.crossorigin="anonymous",a.onload=function(){return r(a)},a.onerror=function(){return o("=> '"+e.src+"' 图片加载失败")},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n,r,o=[],s=2;sh/2&&(s=h/2),t.beginPath(),t.moveTo(n+s,r),t.lineTo(n+s,r),t.lineTo(n+o-s,r),t.arc(n+o-s,r+s,s,-c/2,0),t.lineTo(n+o,r+a-s),t.arc(n+o-s,r+a-s,s,0,c/2),t.lineTo(n+s,r+a),t.arc(n+s,r+a-s,s,c/2,c),t.lineTo(n,r+s),t.arc(n+s,r+s,s,c,-c/2),t.closePath()},T=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},_=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},W=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.prizeAng=0,r.rotateDeg=0,r.maxBtnRadius=0,r.startTime=0,r.endTime=0,r.stopDeg=0,r.endDeg=0,r.FPS=16.6,r.step=0,r.ImageCache=new Map,r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init(),r}return i(e,t),e.prototype.resize=function(){var e,i;t.prototype.resize.call(this),this.Radius=Math.min(this.boxWidth,this.boxHeight)/2,this.ctx.translate(this.Radius,this.Radius),this.draw(),null===(i=(e=this.config).afterResize)||void 0===i||i.call(e)},e.prototype.initLucky=function(){this.Radius=0,this.prizeRadius=0,this.prizeDeg=0,this.prizeAng=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,this.step=0,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width),this.$set(this,"height",t.height),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.initImageCache()}),{deep:!0}),this.$watch("prizes",(function(e){t.initImageCache()}),{deep:!0}),this.$watch("buttons",(function(e){t.initImageCache()}),{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(){var t,e;return r(this,void 0,void 0,(function(){var i;return o(this,(function(n){switch(n.label){case 0:return this.initLucky(),i=this.config,null===(t=i.beforeInit)||void 0===t||t.call(this),this.draw(),this.draw(),[4,this.initImageCache()];case 1:return n.sent(),null===(e=i.afterInit)||void 0===e||e.call(this),[2]}}))}))},e.prototype.initImageCache=function(){var t=this;return new Promise((function(e){var i={blocks:t.blocks.map((function(t){return t.imgs})),prizes:t.prizes.map((function(t){return t.imgs})),buttons:t.buttons.map((function(t){return t.imgs}))};Object.keys(i).forEach((function(n){var r=i[n],o=[];r&&r.forEach((function(e,i){e&&e.forEach((function(e,r){o.push(t.loadAndCacheImg(n,i,r))}))})),Promise.all(o).then((function(){t.draw(),e()}))}))}))},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)&&0===this.step&&(null===(e=this.startCallback)||void 0===e||e.call(this,t))},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n=this;return o(this,(function(a){return[2,new Promise((function(a,s){var h=n[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&n.loadImg(c.src,c).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof c.formatter?[3,2]:[4,Promise.resolve(c.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(c.src,t),a(),[2]}}))}))})).catch((function(n){console.error(t+"["+e+"].imgs["+i+"] "+n),s()}))}}))]}))}))},e.prototype.drawBlock=function(t,e,i){var n=this,r=this.ctx;l(e.background)&&(r.beginPath(),r.fillStyle=e.background,r.arc(0,0,t,0,2*Math.PI,!1),r.fill()),e.imgs&&e.imgs.forEach((function(e,i){var o=n.ImageCache.get(e.src);if(o){var a=n.computedWidthAndHeight(o,e,2*t,2*t),s=a[0],h=a[1],c=[n.getOffsetX(s)+n.getLength(e.left,2*t),n.getLength(e.top,2*t)-t],l=c[0],u=c[1];r.save(),e.rotate&&r.rotate(I(n.rotateDeg)),n.drawImage(r,o,l,u,s,h),r.restore()}}))},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,a=n._defaultConfig,s=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 i.drawBlock(t,e,n),t-i.getLength(e.padding&&e.padding.split(" ")[0])}),this.Radius),this.prizeDeg=360/this.prizes.length,this.prizeAng=I(this.prizeDeg);var u=this.prizeRadius*Math.sin(this.prizeAng/2)*2,f=I(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),p=function(t,e){return i.getOffsetX(o.measureText(e).width)+i.getLength(t.left,u)},g=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.fontSize;return i.getLength(t.top,e)+(n+1)*i.getLength(r)};o.save(),this.prizes.forEach((function(t,e){var n=f+e*i.prizeAng,r=i.prizeRadius-i.maxBtnRadius,v=t.background||s.background;l(v)&&(o.fillStyle=v,A(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeAng/2,n+i.prizeAng/2,i.getLength(a.gutter)),o.fill());var m=Math.cos(n)*i.prizeRadius,w=Math.sin(n)*i.prizeRadius;o.translate(m,w),o.rotate(n+I(90)),t.imgs&&t.imgs.forEach((function(t,e){var n=i.ImageCache.get(t.src);if(n){var a=i.computedWidthAndHeight(n,t,i.prizeAng*i.prizeRadius,r),s=a[0],h=a[1],c=[i.getOffsetX(s)+i.getLength(t.left,u),i.getLength(t.top,r)],l=c[0],f=c[1];i.drawImage(o,n,l,f,s,h)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,l=i.getLength(t.fontSize||s.fontSize),u=t.fontStyle||s.fontStyle,f=h(t,"wordWrap")?t.wordWrap:s.wordWrap,v=t.lengthLimit||s.lengthLimit,m=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font=n+" "+(l>>0)+"px "+u;var w=String(t.text);(f?d(o,c(w),(function(e){var n=2*((i.prizeRadius-g(t,r,e.length))*Math.tan(i.prizeAng/2))-i.getLength(a.gutter);return i.getLength(v,n)}),m):w.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,p(t,e),g(t,r,i))}))})),o.rotate(I(360)-n-I(90)),o.translate(-m,-w)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getLength(t.radius,i.prizeRadius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),l(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&l(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,e){var r=i.ImageCache.get(t.src);if(r){var a=i.computedWidthAndHeight(r,t,2*n,2*n),s=a[0],h=a[1],c=[i.getOffsetX(s)+i.getLength(t.left,n),i.getLength(t.top,n)],l=c[0],u=c[1];i.drawImage(o,r,l,u,s,h)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,r=t.fontWeight||s.fontWeight,a=i.getLength(t.fontSize||s.fontSize),h=t.fontStyle||s.fontStyle;o.fillStyle=e,o.font=r+" "+(a>>0)+"px "+h,String(t.text).split("\n").forEach((function(e,i){o.fillText(e,p(t,e),g(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.prototype.carveOnGunwaleOfAMovingBoat=function(){var t=this,e=t._defaultConfig,i=t.prizeFlag,n=t.prizeDeg,r=t.rotateDeg;this.endTime=Date.now();for(var o=this.stopDeg=r,a=e.speed,s=(Math.random()*n-n/2)*this.getLength(e.stopRange),h=0,c=0,l=0;++h;){var u=360*h-i*n-r-e.offsetDegree+s-n/2,f=_(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-c>f-a?u:l;break}l=u,c=f}},e.prototype.play=function(){var t,e;0===this.step&&(this.startTime=Date.now(),this.prizeFlag=void 0,this.step=1,null===(e=(t=this.config).afterStart)||void 0===e||e.call(t),this.run())},e.prototype.stop=function(t){if(0!==this.step&&3!==this.step){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=f(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},e.prototype.run=function(t){var e;void 0===t&&(t=0);var i=this,n=i.rAF,r=i.step,o=i.prizeFlag,a=i._defaultConfig,s=a.accelerationTime,h=a.decelerationTime,c=a.speed;if(0!==r){if(-1!==o){3!==r||this.endDeg||this.carveOnGunwaleOfAMovingBoat();var l=Date.now()-this.startTime,u=Date.now()-this.endTime,f=this.rotateDeg;if(1===r||l=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(f=_(u,this.stopDeg,this.endDeg,h),u>=h&&(this.step=0)):this.stop(-1);this.rotateDeg=f,this.draw(),n(this.run.bind(this,t+1))}}else null===(e=this.endCallback)||void 0===e||e.call(this,this.prizes.find((function(t,e){return e===o}))||{})},e.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},e}(k),$=function(t){function e(e,i){var n,r=t.call(this,e,{width:i.width,height:i.height})||this;return 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.step=0,r.prizeFlag=-1,r.cells=[],r.ImageCache=new Map,r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init(),r}return i(e,t),e.prototype.resize=function(){var e,i;t.prototype.resize.call(this),this.draw(),null===(i=(e=this.config).afterResize)||void 0===i||i.call(e)},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,this.step=0,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width),this.$set(this,"height",t.height),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.initImageCache()}),{deep:!0}),this.$watch("prizes",(function(e){t.initImageCache()}),{deep:!0}),this.$watch("buttons",(function(e){t.initImageCache()}),{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(){var t,e;return r(this,void 0,void 0,(function(){var i;return o(this,(function(n){switch(n.label){case 0:return this.initLucky(),i=this.config,null===(t=i.beforeInit)||void 0===t||t.call(this),this.draw(),[4,this.initImageCache()];case 1:return n.sent(),null===(e=i.afterInit)||void 0===e||e.call(this),[2]}}))}))},e.prototype.initImageCache=function(){var t=this;return new Promise((function(e){var i=t.buttons.map((function(t){return t.imgs}));t.button&&i.push(t.button.imgs);var n={blocks:t.blocks.map((function(t){return t.imgs})),prizes:t.prizes.map((function(t){return t.imgs})),buttons:i};Object.keys(n).forEach((function(i){var r=n[i],o=[];r&&r.forEach((function(e,n){e&&e.forEach((function(e,r){o.push(t.loadAndCacheImg(i,n,r))}))})),Promise.all(o).then((function(){t.draw(),e()}))}))}))},e.prototype.handleClick=function(t){var e=this,i=this.ctx;a(a([],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]),a=o[0],s=o[1],h=o[2],c=o[3];i.beginPath(),i.rect(a,s,h,c),i.isPointInPath(t.offsetX,t.offsetY)&&0===e.step&&("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){return r(this,void 0,void 0,(function(){var n=this;return o(this,(function(a){return[2,new Promise((function(a,s){var h=n[t][e];if("buttons"===t&&!n.buttons.length&&n.button&&(h=n.button),h&&h.imgs){var c=h.imgs[i];if(c){var l=[n.loadImg(c.src,c),c.activeSrc&&n.loadImg(c.activeSrc,c,"$activeResolve")];Promise.all(l).then((function(t){var e=t[0],i=t[1];return r(n,void 0,void 0,(function(){var t;return o(this,(function(n){switch(n.label){case 0:return"function"!=typeof(t=c.formatter)?[3,3]:[4,Promise.resolve(t.call(this,e))];case 1:return e=n.sent(),i?[4,Promise.resolve(t.call(this,i))]:[3,3];case 2:i=n.sent(),n.label=3;case 3:return this.ImageCache.set(c.src,e),i&&this.ImageCache.set(c.activeSrc,i),a(),[2]}}))}))})).catch((function(n){console.error(t+"["+e+"].imgs["+i+"] "+n),s()}))}}}))]}))}))},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,f=n._defaultStyle,p=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,o),o.clearRect(0,0,this.boxWidth,this.boxHeight),this.cells=a(a([],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,n){var r=t.x,a=t.y,s=t.w,h=t.h,c=u(e,i.getLength.bind(i)),f=c[0],d=c[1],p=c[2],g=c[3],v=e.borderRadius?i.getLength(e.borderRadius):0,m=e.background;return l(m)&&(o.fillStyle=i.handleBackground(r,a,s,h,m),L(o,r,a,s,h,v),o.fill()),e.imgs&&e.imgs.forEach((function(t,e){var n=i.ImageCache.get(t.src);if(n){var c=i.computedWidthAndHeight(n,t,s,h),l=c[0],u=c[1],f=[i.getOffsetX(l,s)+i.getLength(t.left,s),i.getLength(t.top,h)],d=f[0],p=f[1];i.drawImage(o,n,r+d,a+p,l,u)}})),{x:r+p,y:a+f,w:s-p-g,h:h-f-d}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight}),this.cellWidth=(this.prizeArea.w-s.gutter*(this.cols-1))/this.cols,this.cellHeight=(this.prizeArea.h-s.gutter*(this.rows-1))/this.rows,this.cells.forEach((function(t,e){var n=i.getGeometricProperty([t.x,t.y,t.col,t.row]),a=n[0],s=n[1],u=n[2],g=n[3],v=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(v=e===i.currIndex%i.prizes.length>>0);var m=v?p.background:t.background||f.background;if(l(m)){var w=(v?p.shadow:t.shadow||f.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===w.length&&(o.shadowColor=w[3],o.shadowOffsetX=w[0]*r.dpr,o.shadowOffsetY=w[1]*r.dpr,o.shadowBlur=w[2],w[0]>0?u-=w[0]:(u+=w[0],a-=w[0]),w[1]>0?g-=w[1]:(g+=w[1],s-=w[1])),o.fillStyle=i.handleBackground(a,s,u,g,m);var y=i.getLength(t.borderRadius?t.borderRadius:f.borderRadius);L(o,a,s,u,g,y),o.fill(),o.shadowColor="rgba(0, 0, 0, 0)",o.shadowOffsetX=0,o.shadowOffsetY=0,o.shadowBlur=0}e>=i.prizes.length&&(e-=i.prizes.length),t.imgs&&t.imgs.forEach((function(t,e){var n=i.ImageCache.get(t.src),r=i.ImageCache.get(t.activeSrc);if(n){var h=v&&r||n;if(h){var c=i.computedWidthAndHeight(h,t,u,g),l=c[0],f=c[1],d=[a+i.getOffsetX(l,u)+i.getLength(t.left,u),s+i.getLength(t.top,g)],p=d[0],m=d[1];i.drawImage(o,h,p,m,l,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=v&&p.fontStyle?p.fontStyle:t.fontStyle||f.fontStyle,n=v&&p.fontWeight?p.fontWeight:t.fontWeight||f.fontWeight,r=v&&p.fontSize?i.getLength(p.fontSize):i.getLength(t.fontSize||f.fontSize),l=v&&p.lineHeight?p.lineHeight:t.lineHeight||f.lineHeight||t.fontSize||f.fontSize,m=h(t,"wordWrap")?t.wordWrap:f.wordWrap,w=t.lengthLimit||f.lengthLimit,y=t.lineClamp||f.lineClamp;o.font=n+" "+(r>>0)+"px "+e,o.fillStyle=v&&p.fontColor?p.fontColor:t.fontColor||f.fontColor;var b=[],S=String(t.text);if(m){var C=i.getLength(w,u);b=d(o,c(S),(function(){return C}),y)}else b=S.split("\n");b.forEach((function(e,n){o.fillText(e,a+i.getOffsetX(o.measureText(e).width,u)+i.getLength(t.left,u),s+i.getLength(t.top,g)+(n+1)*i.getLength(l))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.prototype.handleBackground=function(t,e,i,n,r){var o=this.ctx;return r.includes("linear-gradient")&&(r=function(t,e,i,n,r,o){var a=/linear-gradient\((.+)\)/.exec(o)[1].split(",").map((function(t){return t.trim()})),s=a.shift(),h=[0,0,0,0];if(s.includes("deg")){var c=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?h=[e,i+r,e+n,i+r-n*c(s-0)]:s>=45&&s<90?h=[e,i+r,e+n-r*c(s-45),i]:s>=90&&s<135?h=[e+n,i+r,e+n-r*c(s-90),i]:s>=135&&s<180?h=[e+n,i+r,e,i+n*c(s-135)]:s>=180&&s<225?h=[e+n,i,e,i+n*c(s-180)]:s>=225&&s<270?h=[e+n,i,e+r*c(s-225),i+r]:s>=270&&s<315?h=[e,i,e+r*c(s-270),i+r]:s>=315&&s<360&&(h=[e,i,e+n,i+r-n*c(s-315)])}else s.includes("top")?h=[e,i+r,e,i]:s.includes("bottom")?h=[e,i,e,i+r]:s.includes("left")?h=[e+n,i,e,i]:s.includes("right")&&(h=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,h.map((function(t){return t>>0})));return a.reduce((function(t,e,i){var n=e.split(" ");return 1===n.length?t.addColorStop(i,n[0]):2===n.length&&t.addColorStop.apply(t,n),t}),l)}(o,t,e,i,n,r)),r},e.prototype.carveOnGunwaleOfAMovingBoat=function(){var t=this,e=t._defaultConfig,i=t.prizeFlag,n=t.currIndex;this.endTime=Date.now();for(var r=this.stopIndex=n,o=e.speed,a=0,s=0,h=0;++a;){var c=this.prizes.length*a+i-r,l=_(this.FPS,r,c,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?c:h;break}h=c,s=l}},e.prototype.play=function(){var t,e;0===this.step&&(this.startTime=Date.now(),this.prizeFlag=void 0,this.step=1,null===(e=(t=this.config).afterStart)||void 0===e||e.call(t),this.run())},e.prototype.stop=function(t){if(0!==this.step&&3!==this.step){if(!t&&0!==t){var e=this.prizes.map((function(t){return t.range}));t=f(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},e.prototype.run=function(t){var e;void 0===t&&(t=0);var i=this,n=i.rAF,r=i.step,o=i.prizes,a=i.prizeFlag,s=i._defaultConfig,h=s.accelerationTime,c=s.decelerationTime,l=s.speed;if(0!==r){if(-1!==a){3!==r||this.endIndex||this.carveOnGunwaleOfAMovingBoat();var u=Date.now()-this.startTime,f=Date.now()-this.endTime,d=this.currIndex;if(1===r||u=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(d=_(f,this.stopIndex,this.endIndex,c),f>=c&&(this.step=0)):this.stop(-1);this.currIndex=d,this.draw(),n(this.run.bind(this,t+1))}}else null===(e=this.endCallback)||void 0===e||e.call(this,this.prizes.find((function(t,e){return e===a}))||{})},e.prototype.getGeometricProperty=function(t){var e=t[0],i=t[1],n=t[2],r=void 0===n?1:n,o=t[3],a=void 0===o?1:o,s=this.cellWidth,h=this.cellHeight,c=this._defaultConfig.gutter,l=[this.prizeArea.x+(s+c)*e,this.prizeArea.y+(h+c)*i];return r&&a&&l.push(s*r+c*(r-1),h*a+c*(a-1)),l},e.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},e}(k),E=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.slots=[],r.defaultConfig={},r._defaultConfig={},r.defaultStyle={},r._defaultStyle={},r.endCallback=function(){},r.cellWidth=0,r.cellHeight=0,r.cellAndSpacing=0,r.widthAndSpacing=0,r.heightAndSpacing=0,r.FPS=16.6,r.scroll=[],r.stopScroll=[],r.endScroll=[],r.startTime=0,r.endTime=0,r.step=0,r.prizeFlag=void 0,r.ImageCache=new Map,r.initData(i),r.initWatch(),r.initComputed(),null===(n=e.beforeCreate)||void 0===n||n.call(r),r.init(),r}return i(e,t),e.prototype.resize=function(){var e,i;t.prototype.resize.call(this),this.draw(),null===(i=(e=this.config).afterResize)||void 0===i||i.call(e)},e.prototype.initLucky=function(){this.cellWidth=0,this.cellHeight=0,this.cellAndSpacing=0,this.widthAndSpacing=0,this.heightAndSpacing=0,this.FPS=16.6,this.scroll=[],this.stopScroll=[],this.endScroll=[],this.startTime=0,this.endTime=0,this.prizeFlag=void 0,this.step=0,t.prototype.initLucky.call(this)},e.prototype.initData=function(t){this.$set(this,"width",t.width),this.$set(this,"height",t.height),this.$set(this,"blocks",t.blocks||[]),this.$set(this,"prizes",t.prizes||[]),this.$set(this,"slots",t.slots||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"endCallback",t.end)},e.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=n({mode:"vertical",rowSpacing:0,colSpacing:5,speed:20,direction:1,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.rowSpacing=t.getLength(e.rowSpacing),e.colSpacing=t.getLength(e.colSpacing),e})),this.$computed(this,"_defaultStyle",(function(){return n({borderRadius:0,fontColor:"#000",fontSize:"18px",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.initImageCache()}),{deep:!0}),this.$watch("prizes",(function(e){t.initImageCache()}),{deep:!0}),this.$watch("slots",(function(e){t.drawOffscreenCanvas(),t.draw()}),{deep:!0}),this.$watch("defaultConfig",(function(){return t.draw()}),{deep:!0}),this.$watch("defaultStyle",(function(){return t.draw()}),{deep:!0}),this.$watch("endCallback",(function(){return t.init()}))},e.prototype.init=function(){var t,e;return r(this,void 0,void 0,(function(){var i;return o(this,(function(n){switch(n.label){case 0:return this.initLucky(),i=this.config,null===(t=i.beforeInit)||void 0===t||t.call(this),this.drawOffscreenCanvas(),this.draw(),[4,this.initImageCache()];case 1:return n.sent(),null===(e=i.afterInit)||void 0===e||e.call(this),[2]}}))}))},e.prototype.initImageCache=function(){var t=this;return new Promise((function(e){var i={blocks:t.blocks.map((function(t){return t.imgs})),prizes:t.prizes.map((function(t){return t.imgs}))};Object.keys(i).forEach((function(n){var r=i[n],o=[];r&&r.forEach((function(e,i){e&&e.forEach((function(e,r){o.push(t.loadAndCacheImg(n,i,r))}))})),Promise.all(o).then((function(){t.drawOffscreenCanvas(),t.draw(),e()}))}))}))},e.prototype.loadAndCacheImg=function(t,e,i){return r(this,void 0,void 0,(function(){var n=this;return o(this,(function(a){return[2,new Promise((function(a,s){var h=n[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&n.loadImg(c.src,c).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof c.formatter?[3,2]:[4,Promise.resolve(c.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(c.src,t),a(),[2]}}))}))})).catch((function(n){console.error(t+"["+e+"].imgs["+i+"] "+n),s()}))}}))]}))}))},e.prototype.drawOffscreenCanvas=function(){var t=this,e=this._defaultConfig,i=this._defaultStyle,n=this.drawBlocks(),r=n.w,o=n.h,a=this.prizes.length,s=this.displacementWidthOrHeight(),u=s.cellWidth,f=s.cellHeight,p=s.widthAndSpacing,g=s.heightAndSpacing,v=new Array(a).fill(void 0).map((function(t,e){return e})),m=0,w=0;this.slots.forEach((function(e,i){void 0===t.scroll[i]&&(t.scroll[i]=0),e.order=e.order||v;var n=e.order.length;m=Math.max(m,r+p*n),w=Math.max(w,o+g*n)}));var y=this.getOffscreenCanvas(m,w),b=y._offscreenCanvas,S=y._ctx;this._offscreenCanvas=b,this.slots.forEach((function(n,r){var o=u*r,a=f*r,s=0,v=function(t,e){for(var i={},n=[],r=0;r>0)+"px "+n,S.fillStyle=e.fontColor||i.fontColor;var g=[],v=String(e.text);if(s){var m=t.getLength(l,u);g=d(S,c(v),(function(){return m}),p)}else g=v.split("\n");g.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u)+t.getLength(e.left,u),C+t.getLength(e.top,f)+(n+1)*t.getLength(a))}))}))}}));for(var m=t.displacement([o,0,u,s],[0,a,s,f]),y=m[0],C=m[1],z=m[2],x=m[3],k=s;kn&&(l%=n);var v=e.displacement([u*i,l,u,c],[l,f*i,h,f]),m=v[0],w=v[1],y=v[2],b=v[3],S=e.displacement([a+p*i,s,u,c],[a,s+g*i,h,f]),C=S[0],z=S[1],x=S[2],k=S[3];e.drawImage(r,e._offscreenCanvas,m,w,y,b,C,z,x,k)}))}},e.prototype.carveOnGunwaleOfAMovingBoat=function(){var t=this,e=this,i=e._defaultConfig,n=e.prizeFlag,r=e.cellAndSpacing;this.endTime=Date.now(),this.slots.forEach((function(e,o){var a=e.order;if(a.length)for(var s=e.speed||i.speed,h=e.direction||i.direction,c=a.findIndex((function(t){return t===n[o]})),l=r*a.length,u=t.stopScroll[o]=t.scroll[o],f=0;++f;){var d=r*c+l*f*h-u,p=_(t.FPS,u,d,i.decelerationTime)-u;if(Math.abs(p)>s){t.endScroll[o]=d;break}}}))},e.prototype.play=function(){var t,e;0===this.step&&(this.startTime=Date.now(),this.prizeFlag=void 0,this.step=1,null===(e=(t=this.config).afterStart)||void 0===e||e.call(t),this.run())},e.prototype.stop=function(t){var e;if(0!==this.step&&3!==this.step){if("number"==typeof t)this.prizeFlag=new Array(this.slots.length).fill(t);else{if(!s(t,"array"))return this.stop(-1),console.error("stop() 无法识别的参数类型 "+typeof t);if(t.length!==this.slots.length)return this.stop(-1),console.error("stop(["+t+"]) 参数长度的不正确");this.prizeFlag=t}(null===(e=this.prizeFlag)||void 0===e?void 0:e.includes(-1))?(this.prizeFlag=[],this.step=0):this.step=2}},e.prototype.run=function(t){var e,i,n=this;void 0===t&&(t=0);var r=this,o=r.rAF,a=r.step,s=r.prizeFlag,h=r._defaultConfig,c=r.cellAndSpacing,l=r.slots,u=h.accelerationTime,f=h.decelerationTime;if(0!==this.step||(null==s?void 0:s.length)!==l.length){if(void 0===s||s.length){3!==this.step||this.endScroll.length||this.carveOnGunwaleOfAMovingBoat();var d=Date.now()-this.startTime,p=Date.now()-this.endTime;l.forEach((function(e,i){var r=e.order;if(r&&r.length){var o=c*r.length,g=Math.abs(e.speed||h.speed),v=e.direction||h.direction,m=0,w=n.scroll[i];if(1===a||d=f&&(n.step=0)}n.scroll[i]=m}})),this.draw(),o(this.run.bind(this,t+1))}}else{for(var g=s[0],v=0;v