lucky-canvas
Advanced tools
Comparing version 1.7.18 to 1.7.19
@@ -16,3 +16,3 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}); | ||
***************************************************************************** */ | ||
var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},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 a(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},s=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},c=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},h=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=function(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 c={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:s};for(var h in c)c[h]=Object.prototype.hasOwnProperty.call(t,h)&&a(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):c[h];return[n,r,o,s]},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}))},f=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;s<e.length;s++){r+=e[s];var c=t.measureText(r).width,h=i(o);if(n===o.length+1&&(c+=a),h<0)return o;if(c>h&&(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},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 v=Array.prototype,m=Object.create(v);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){m[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=v[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var w=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=m:Object.getOwnPropertyNames(m).forEach((function(e){g(t,e,m[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){b(t,e,t[e])}))},t}();function y(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new w(t)}function b(t,e,i){var n=new d,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=y(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),s&&s.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=y(e),n.notify()))}})}}var S=0,C=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=S++,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}(),z=function(){function t(t,e){var i=this;this.version="1.7.18",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","".concat("lucky-canvas","@").concat("1.7.18")),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=this.config,s=a.flag,c=a.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*c:t}))),t.drawImage.apply(t,o([i],n));var h=i.canvas.getContext("2d");n=n.map((function(t){return t*c}));var l=h.getImageData.apply(h,n.slice(0,4));t.putImageData.apply(t,o([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!s(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&b(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 C(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},k=function(t,e,i,n,r,o){t.beginPath();var a,s,c=x(90/Math.PI/i*o),h=n+c,l=r-c;t.arc(0,0,i,h,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},I=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],c=Math.min(o,a),h=Math.PI;s>c/2&&(s=c/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,-h/2,0),t.lineTo(n+o,r+a-s),t.arc(n+o-s,r+a-s,s,0,h/2),t.lineTo(n+s,r+a),t.arc(n+s,r+a-s,s,h/2,h),t.lineTo(n,r+s),t.arc(n+s,r+s,s,h,-h/2),t.closePath()},W=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},O=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},_=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.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 e(o,t),o.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)},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,this.step=0,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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},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)&&0===this.step&&(null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var c=o[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&o.loadImg(h.src,h).then((function(t){return n(o,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.prototype.drawBlock=function(t,e,i){var n=this,r=this.ctx;h(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],c=a[1],h=[n.getOffsetX(s),n.getHeight(e.top,2*t)-t],l=h[0],u=h[1];r.save(),e.rotate&&r.rotate(x(n.rotateDeg)),n.drawImage(r,o,l,u,s,c),r.restore()}}))},o.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.prizeRadian=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;h(p)&&(o.fillStyle=p,k(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),o.rotate(n+x(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.prizeRadian*i.prizeRadius,r),s=a[0],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,r)],l=h[0],u=h[1];i.drawImage(o,n,l,u,s,c)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,h=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(h>>0,"px ").concat(l);var m=String(t.text);(p?f(o,c(m),(function(e){var n=2*((i.prizeRadius-d(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),d(t,r,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius,i.prizeRadius);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,e){var r=i.ImageCache.get(t.src);if(r){var a=i.computedWidthAndHeight(r,t,2*n,2*n),s=a[0],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,n)],l=h[0],u=h[1];i.drawImage(o,r,l,u,s,c)}})),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),c=t.fontStyle||s.fontStyle;o.fillStyle=e,o.font="".concat(r," ").concat(a>>0,"px ").concat(c),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.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),c=0,h=0,l=0;++c;){var u=360*c-i*n-r-e.offsetDegree+s-n/2,f=O(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-h>f-a?u:l;break}l=u,h=f}},o.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())},o.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},o.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.stopDeg,s=i.endDeg,c=i._defaultConfig,h=c.accelerationTime,l=c.decelerationTime,u=c.speed;if(0!==r){if(-1!==o){3!==r||this.endDeg||this.carveOnGunwaleOfAMovingBoat();var f=Date.now()-this.startTime,d=Date.now()-this.endTime,p=this.rotateDeg;if(1===r||f<h){this.FPS=f/t;var g=W(f,0,u,h);g===u&&(this.step=2),p+=g%360}else 2===r?(p+=u%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(p=O(d,a,s,l),d>=l&&(this.step=0)):this.stop(-1);this.rotateDeg=p,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}))||{})},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),T=function(t){function a(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 e(a,t),a.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)},a.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)},a.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)},a.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"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)}))},a.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()}))},a.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},a.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()}))}))}))},a.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]),a=o[0],s=o[1],c=o[2],h=o[3];i.beginPath(),i.rect(a,s,c,h),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))}}))},a.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var c=o[t][e];if("buttons"===t&&!o.buttons.length&&o.button&&(c=o.button),c&&c.imgs){var h=c.imgs[i];if(h){var l=[o.loadImg(h.src,h),h.activeSrc&&o.loadImg(h.activeSrc,h,"$activeResolve")];Promise.all(l).then((function(t){var e=t[0],i=t[1];return n(o,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return"function"!=typeof(t=h.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(h.src,e),i&&this.ImageCache.set(h.activeSrc,i),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,a=n.ctx,s=n._defaultConfig,u=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,a),a.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,n){var r=t.x,o=t.y,s=t.w,c=t.h,f=l(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||u.background;return h(w)&&(a.fillStyle=i.handleBackground(r,o,s,c,w),I(a,r,o,s,c,m),a.fill()),e.imgs&&e.imgs.forEach((function(t,e){var n=i.ImageCache.get(t.src);if(n){var h=i.computedWidthAndHeight(n,t,s,c),l=h[0],u=h[1],f=[i.getOffsetX(l,s),i.getHeight(t.top,c)],d=f[0],p=f[1];i.drawImage(a,n,r+d,o+p,l,u)}})),{x:r+g,y:o+d,w:s-g-v,h:c-d-p}}),{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]),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 v=g?d.background:t.background||u.background;if(h(v)){var m=(g?d.shadow:t.shadow||u.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(a.shadowColor=m[3],a.shadowOffsetX=m[0]*r.dpr,a.shadowOffsetY=m[1]*r.dpr,a.shadowBlur=m[2],m[0]>0?l-=m[0]:(l+=m[0],o-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),a.fillStyle=i.handleBackground(o,s,l,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:u.borderRadius);I(a,o,s,l,p,w),a.fill(),a.shadowColor="rgba(0, 0, 0, 0)",a.shadowOffsetX=0,a.shadowOffsetY=0,a.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 c=g&&r||n;if(c){var h=i.computedWidthAndHeight(c,t,l,p),u=h[0],f=h[1],d=[o+i.getOffsetX(u,l),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(a,c,v,m,u,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&d.fontStyle?d.fontStyle:t.fontStyle||u.fontStyle,n=g&&d.fontWeight?d.fontWeight:t.fontWeight||u.fontWeight,r=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(t.fontSize||u.fontSize),h=g&&d.lineHeight?d.lineHeight:t.lineHeight||u.lineHeight||t.fontSize||u.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,m=t.lengthLimit||u.lengthLimit,w=t.lineClamp||u.lineClamp;a.font="".concat(n," ").concat(r>>0,"px ").concat(e),a.fillStyle=g&&d.fontColor?d.fontColor:t.fontColor||u.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,l);y=f(a,c(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){a.fillText(e,o+i.getOffsetX(a.measureText(e).width,l),s+i.getHeight(t.top,p)+(n+1)*i.getLength(h))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,a)},a.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(),c=[0,0,0,0];if(s.includes("deg")){var h=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?c=[e,i+r,e+n,i+r-n*h(s-0)]:s>=45&&s<90?c=[e,i+r,e+n-r*h(s-45),i]:s>=90&&s<135?c=[e+n,i+r,e+n-r*h(s-90),i]:s>=135&&s<180?c=[e+n,i+r,e,i+n*h(s-135)]:s>=180&&s<225?c=[e+n,i,e,i+n*h(s-180)]:s>=225&&s<270?c=[e+n,i,e+r*h(s-225),i+r]:s>=270&&s<315?c=[e,i,e+r*h(s-270),i+r]:s>=315&&s<360&&(c=[e,i,e+n,i+r-n*h(s-315)])}else s.includes("top")?c=[e,i+r,e,i]:s.includes("bottom")?c=[e,i,e,i+r]:s.includes("left")?c=[e+n,i,e,i]:s.includes("right")&&(c=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,c.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},a.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,c=0;++a;){var h=this.prizes.length*a+i-r,l=O(this.FPS,r,h,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?h:c;break}c=h,s=l}},a.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())},a.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},a.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.stopIndex,c=i.endIndex,h=i._defaultConfig,l=h.accelerationTime,u=h.decelerationTime,f=h.speed;if(0!==r){if(-1!==a){3!==r||this.endIndex||this.carveOnGunwaleOfAMovingBoat();var d=Date.now()-this.startTime,p=Date.now()-this.endTime,g=this.currIndex;if(1===r||d<l){this.FPS=d/t;var v=W(d,.1,f-.1,l);v===f&&(this.step=2),g+=v%o.length}else 2===r?(g+=f%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(g=O(p,s,c,u),p>=u&&(this.step=0)):this.stop(-1);this.currIndex=g,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}))||{})},a.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,c=this.cellHeight,h=this._defaultConfig.gutter,l=[this.prizeArea.x+(s+h)*e,this.prizeArea.y+(c+h)*i];return r&&a&&l.push(s*r+h*(r-1),c*a+h*(a-1)),l},a.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},a}(z),$=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.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 e(o,t),o.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)},o.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)},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,"slots",t.slots||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"endCallback",t.end)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({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 i({borderRadius:0,fontColor:"#000",fontSize:"18px",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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var c=o[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&o.loadImg(h.src,h).then((function(t){return n(o,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.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,l=this.displacementWidthOrHeight(),u=l.cellWidth,d=l.cellHeight,p=l.widthAndSpacing,g=l.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=d*r,l=0,v=function(t,e){for(var i={},n=[],r=0;r<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];l+=z;var x=r.background||i.background;if(h(x)){var k=t.getLength(s(r,"borderRadius")?r.borderRadius:i.borderRadius);I(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,d),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,d)],c=s[0],h=s[1];t.drawImage(S,n,c,h,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,h=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(h,u);p=f(S,c(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(e.top,d)+(n+1)*t.getLength(a))}))}))}}));for(var m=t.displacement([o,0,u,l],[0,a,l,d]),y=m[0],C=m[1],z=m[2],x=m[3],k=l;k<w+l;){var W=t.displacement([y,k],[k,C]),O=W[0],_=W[1];t.drawImage(S,b,y,C,z,x,O,_,z,x),k+=l}}}))},o.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,c=e.w,u=e.h,f=l(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return h(w)&&(I(i,a,s,c,u,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,c,u),h=o[0],l=o[1],f=[t.getOffsetX(h,c),t.getHeight(e.top,u)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,h,l)}})),{x:a+g,y:s+d,w:c-g-v,h:u-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},o.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,c=o.w,h=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(h-g)/2,-(c-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(l%=n);var v=e.displacement([u*i,l,u,h],[l,f*i,c,f]),m=v[0],w=v[1],y=v[2],b=v[3],S=e.displacement([a+p*i,s,u,h],[a,s+g*i,c,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)}))}},o.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,c=e.direction||i.direction,h=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*h+l*f*c-u,p=O(t.FPS,u,d,i.decelerationTime)-u;if(Math.abs(p)>s){t.endScroll[o]=d;break}}}))},o.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())},o.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(!a(t,"array"))return this.stop(-1),console.error("stop() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(t,"]) 参数长度的不正确"));this.prizeFlag=t}(null===(e=this.prizeFlag)||void 0===e?void 0:e.includes(-1))?(this.prizeFlag=[],this.step=0):this.step=2}},o.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,c=r._defaultConfig,h=r.cellAndSpacing,l=r.slots,u=c.accelerationTime,f=c.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=h*r.length,g=Math.abs(e.speed||c.speed),v=e.direction||c.direction,m=0,w=n.scroll[i];if(1===a||d<u){n.FPS=d/t;var y=W(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=O(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},o.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},o.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,c=o.w,h=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(h-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(c-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},o}(z);exports.LuckyGrid=T,exports.LuckyWheel=_,exports.SlotMachine=$,exports.cutRound=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,I(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},exports.opacity=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,c=s.length,h=0;h<c;h+=4){var l=s[h+3];0!==l&&(s[h+3]=l*e)}n.putImageData(a,0,0)}return i}; | ||
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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},s=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},c=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=function(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 c in h)h[c]=Object.prototype.hasOwnProperty.call(t,c)&&a(t[c],"string","number")?~~String(t[c]).replace(/px/g,""):h[c];return[n,r,o,s]},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}))},f=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;s<e.length;s++){r+=e[s];var h=t.measureText(r).width,c=i(o);if(n===o.length+1&&(h+=a),c<0)return o;if(h>c&&(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},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 v=Array.prototype,m=Object.create(v);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){m[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=v[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var w=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=m:Object.getOwnPropertyNames(m).forEach((function(e){g(t,e,m[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){b(t,e,t[e])}))},t}();function y(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new w(t)}function b(t,e,i){var n=new d,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=y(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),s&&s.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=y(e),n.notify()))}})}}var S=0,C=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=S++,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}(),z=function(){function t(t,e){var i=this;this.version="1.7.19",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","".concat("lucky-canvas","@").concat("1.7.19")),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=this.config,s=a.flag,h=a.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*h:t}))),t.drawImage.apply(t,o([i],n));var c=i.canvas.getContext("2d");n=n.map((function(t){return t*h}));var l=c.getImageData.apply(c,n.slice(0,4));t.putImageData.apply(t,o([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!s(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&b(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 C(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},k=function(t,e,i,n,r,o){t.beginPath();var a,s,h=x(90/Math.PI/i*o),c=n+h,l=r-h;t.arc(0,0,i,c,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},I=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],h=Math.min(o,a),c=Math.PI;s>h/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()},W=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},O=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},_=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.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 e(o,t),o.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)},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,this.step=0,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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},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)&&0===this.step&&(null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.prototype.drawBlock=function(t,e,i){var n=this,r=this.ctx;c(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.getHeight(e.top,2*t)-t],l=c[0],u=c[1];r.save(),e.rotate&&r.rotate(x(n.rotateDeg)),n.drawImage(r,o,l,u,s,h),r.restore()}}))},o.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.prizeRadian=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;c(p)&&(o.fillStyle=p,k(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),o.rotate(n+x(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.prizeRadian*i.prizeRadius,r),s=a[0],h=a[1],c=[i.getOffsetX(s),i.getHeight(t.top,r)],l=c[0],u=c[1];i.drawImage(o,n,l,u,s,h)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,c=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(c>>0,"px ").concat(l);var m=String(t.text);(p?f(o,h(m),(function(e){var n=2*((i.prizeRadius-d(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),d(t,r,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius,i.prizeRadius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),c(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&c(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.getHeight(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="".concat(r," ").concat(a>>0,"px ").concat(h),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.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=O(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-c>f-a?u:l;break}l=u,c=f}},o.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())},o.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},o.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<s){this.FPS=l/t;var d=W(l,0,c,s);d===c&&(this.step=2),f+=d%360}else 2===r?(f+=c%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(f=O(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}))||{})},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),T=function(t){function a(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 e(a,t),a.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)},a.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)},a.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)},a.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"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)}))},a.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()}))},a.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},a.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()}))}))}))},a.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]),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))}}))},a.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if("buttons"===t&&!o.buttons.length&&o.button&&(h=o.button),h&&h.imgs){var c=h.imgs[i];if(c){var l=[o.loadImg(c.src,c),c.activeSrc&&o.loadImg(c.activeSrc,c,"$activeResolve")];Promise.all(l).then((function(t){var e=t[0],i=t[1];return n(o,void 0,void 0,(function(){var t;return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,a=n.ctx,s=n._defaultConfig,u=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,a),a.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,n){var r=t.x,o=t.y,s=t.w,h=t.h,f=l(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||u.background;return c(w)&&(a.fillStyle=i.handleBackground(r,o,s,h,w),I(a,r,o,s,h,m),a.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.getHeight(t.top,h)],d=f[0],p=f[1];i.drawImage(a,n,r+d,o+p,l,u)}})),{x:r+g,y:o+d,w:s-g-v,h:h-d-p}}),{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]),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 v=g?d.background:t.background||u.background;if(c(v)){var m=(g?d.shadow:t.shadow||u.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(a.shadowColor=m[3],a.shadowOffsetX=m[0]*r.dpr,a.shadowOffsetY=m[1]*r.dpr,a.shadowBlur=m[2],m[0]>0?l-=m[0]:(l+=m[0],o-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),a.fillStyle=i.handleBackground(o,s,l,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:u.borderRadius);I(a,o,s,l,p,w),a.fill(),a.shadowColor="rgba(0, 0, 0, 0)",a.shadowOffsetX=0,a.shadowOffsetY=0,a.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=g&&r||n;if(h){var c=i.computedWidthAndHeight(h,t,l,p),u=c[0],f=c[1],d=[o+i.getOffsetX(u,l),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(a,h,v,m,u,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&d.fontStyle?d.fontStyle:t.fontStyle||u.fontStyle,n=g&&d.fontWeight?d.fontWeight:t.fontWeight||u.fontWeight,r=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(t.fontSize||u.fontSize),c=g&&d.lineHeight?d.lineHeight:t.lineHeight||u.lineHeight||t.fontSize||u.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,m=t.lengthLimit||u.lengthLimit,w=t.lineClamp||u.lineClamp;a.font="".concat(n," ").concat(r>>0,"px ").concat(e),a.fillStyle=g&&d.fontColor?d.fontColor:t.fontColor||u.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,l);y=f(a,h(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){a.fillText(e,o+i.getOffsetX(a.measureText(e).width,l),s+i.getHeight(t.top,p)+(n+1)*i.getLength(c))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,a)},a.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},a.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=O(this.FPS,r,c,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?c:h;break}h=c,s=l}},a.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())},a.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},a.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<h){this.FPS=u/t;var p=W(u,.1,l-.1,h);p===l&&(this.step=2),d+=p%o.length}else 2===r?(d+=l%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(d=O(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}))||{})},a.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},a.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},a}(z),$=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.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 e(o,t),o.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)},o.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)},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,"slots",t.slots||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"endCallback",t.end)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({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 i({borderRadius:0,fontColor:"#000",fontSize:"18px",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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.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,l=this.displacementWidthOrHeight(),u=l.cellWidth,d=l.cellHeight,p=l.widthAndSpacing,g=l.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=d*r,l=0,v=function(t,e){for(var i={},n=[],r=0;r<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];l+=z;var x=r.background||i.background;if(c(x)){var k=t.getLength(s(r,"borderRadius")?r.borderRadius:i.borderRadius);I(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,d),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,d)],h=s[0],c=s[1];t.drawImage(S,n,h,c,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,c=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(c,u);p=f(S,h(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(e.top,d)+(n+1)*t.getLength(a))}))}))}}));for(var m=t.displacement([o,0,u,l],[0,a,l,d]),y=m[0],C=m[1],z=m[2],x=m[3],k=l;k<w+l;){var W=t.displacement([y,k],[k,C]),O=W[0],_=W[1];t.drawImage(S,b,y,C,z,x,O,_,z,x),k+=l}}}))},o.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,h=e.w,u=e.h,f=l(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return c(w)&&(I(i,a,s,h,u,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,h,u),c=o[0],l=o[1],f=[t.getOffsetX(c,h),t.getHeight(e.top,u)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,c,l)}})),{x:a+g,y:s+d,w:h-g-v,h:u-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},o.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,h=o.w,c=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(c-g)/2,-(h-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(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)}))}},o.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=O(t.FPS,u,d,i.decelerationTime)-u;if(Math.abs(p)>s){t.endScroll[o]=d;break}}}))},o.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())},o.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(!a(t,"array"))return this.stop(-1),console.error("stop() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(t,"]) 参数长度的不正确"));this.prizeFlag=t}(null===(e=this.prizeFlag)||void 0===e?void 0:e.includes(-1))?(this.prizeFlag=[],this.step=0):this.step=2}},o.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<u){n.FPS=d/t;var y=W(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=O(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},o.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},o.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,h=o.w,c=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(c-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(h-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},o}(z);exports.LuckyGrid=T,exports.LuckyWheel=_,exports.SlotMachine=$,exports.cutRound=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,I(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},exports.opacity=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,h=s.length,c=0;c<h;c+=4){var l=s[c+3];0!==l&&(s[c+3]=l*e)}n.putImageData(a,0,0)}return i}; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -15,3 +15,3 @@ /*! ***************************************************************************** | ||
***************************************************************************** */ | ||
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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},s=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},c=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=function(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 c in h)h[c]=Object.prototype.hasOwnProperty.call(t,c)&&a(t[c],"string","number")?~~String(t[c]).replace(/px/g,""):h[c];return[n,r,o,s]},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}))},f=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;s<e.length;s++){r+=e[s];var h=t.measureText(r).width,c=i(o);if(n===o.length+1&&(h+=a),c<0)return o;if(h>c&&(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},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 v=Array.prototype,m=Object.create(v);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){m[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=v[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var w=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=m:Object.getOwnPropertyNames(m).forEach((function(e){g(t,e,m[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){b(t,e,t[e])}))},t}();function y(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new w(t)}function b(t,e,i){var n=new d,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=y(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),s&&s.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=y(e),n.notify()))}})}}var S=0,C=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=S++,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}(),z=function(){function t(t,e){var i=this;this.version="1.7.18",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","".concat("lucky-canvas","@").concat("1.7.18")),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=this.config,s=a.flag,h=a.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*h:t}))),t.drawImage.apply(t,o([i],n));var c=i.canvas.getContext("2d");n=n.map((function(t){return t*h}));var l=c.getImageData.apply(c,n.slice(0,4));t.putImageData.apply(t,o([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!s(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&b(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 C(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},k=function(t,e,i,n,r,o){t.beginPath();var a,s,h=x(90/Math.PI/i*o),c=n+h,l=r-h;t.arc(0,0,i,c,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},I=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],h=Math.min(o,a),c=Math.PI;s>h/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()},W=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},O=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},T=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.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 e(o,t),o.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)},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,this.step=0,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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},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)&&0===this.step&&(null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.prototype.drawBlock=function(t,e,i){var n=this,r=this.ctx;c(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.getHeight(e.top,2*t)-t],l=c[0],u=c[1];r.save(),e.rotate&&r.rotate(x(n.rotateDeg)),n.drawImage(r,o,l,u,s,h),r.restore()}}))},o.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.prizeRadian=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;c(p)&&(o.fillStyle=p,k(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),o.rotate(n+x(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.prizeRadian*i.prizeRadius,r),s=a[0],h=a[1],c=[i.getOffsetX(s),i.getHeight(t.top,r)],l=c[0],u=c[1];i.drawImage(o,n,l,u,s,h)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,c=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(c>>0,"px ").concat(l);var m=String(t.text);(p?f(o,h(m),(function(e){var n=2*((i.prizeRadius-d(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),d(t,r,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius,i.prizeRadius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),c(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&c(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.getHeight(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="".concat(r," ").concat(a>>0,"px ").concat(h),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.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=O(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-c>f-a?u:l;break}l=u,c=f}},o.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())},o.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},o.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.stopDeg,s=i.endDeg,h=i._defaultConfig,c=h.accelerationTime,l=h.decelerationTime,u=h.speed;if(0!==r){if(-1!==o){3!==r||this.endDeg||this.carveOnGunwaleOfAMovingBoat();var f=Date.now()-this.startTime,d=Date.now()-this.endTime,p=this.rotateDeg;if(1===r||f<c){this.FPS=f/t;var g=W(f,0,u,c);g===u&&(this.step=2),p+=g%360}else 2===r?(p+=u%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(p=O(d,a,s,l),d>=l&&(this.step=0)):this.stop(-1);this.rotateDeg=p,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}))||{})},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),_=function(t){function a(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 e(a,t),a.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)},a.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)},a.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)},a.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"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)}))},a.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()}))},a.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},a.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()}))}))}))},a.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]),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))}}))},a.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if("buttons"===t&&!o.buttons.length&&o.button&&(h=o.button),h&&h.imgs){var c=h.imgs[i];if(c){var l=[o.loadImg(c.src,c),c.activeSrc&&o.loadImg(c.activeSrc,c,"$activeResolve")];Promise.all(l).then((function(t){var e=t[0],i=t[1];return n(o,void 0,void 0,(function(){var t;return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,a=n.ctx,s=n._defaultConfig,u=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,a),a.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,n){var r=t.x,o=t.y,s=t.w,h=t.h,f=l(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||u.background;return c(w)&&(a.fillStyle=i.handleBackground(r,o,s,h,w),I(a,r,o,s,h,m),a.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.getHeight(t.top,h)],d=f[0],p=f[1];i.drawImage(a,n,r+d,o+p,l,u)}})),{x:r+g,y:o+d,w:s-g-v,h:h-d-p}}),{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]),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 v=g?d.background:t.background||u.background;if(c(v)){var m=(g?d.shadow:t.shadow||u.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(a.shadowColor=m[3],a.shadowOffsetX=m[0]*r.dpr,a.shadowOffsetY=m[1]*r.dpr,a.shadowBlur=m[2],m[0]>0?l-=m[0]:(l+=m[0],o-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),a.fillStyle=i.handleBackground(o,s,l,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:u.borderRadius);I(a,o,s,l,p,w),a.fill(),a.shadowColor="rgba(0, 0, 0, 0)",a.shadowOffsetX=0,a.shadowOffsetY=0,a.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=g&&r||n;if(h){var c=i.computedWidthAndHeight(h,t,l,p),u=c[0],f=c[1],d=[o+i.getOffsetX(u,l),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(a,h,v,m,u,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&d.fontStyle?d.fontStyle:t.fontStyle||u.fontStyle,n=g&&d.fontWeight?d.fontWeight:t.fontWeight||u.fontWeight,r=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(t.fontSize||u.fontSize),c=g&&d.lineHeight?d.lineHeight:t.lineHeight||u.lineHeight||t.fontSize||u.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,m=t.lengthLimit||u.lengthLimit,w=t.lineClamp||u.lineClamp;a.font="".concat(n," ").concat(r>>0,"px ").concat(e),a.fillStyle=g&&d.fontColor?d.fontColor:t.fontColor||u.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,l);y=f(a,h(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){a.fillText(e,o+i.getOffsetX(a.measureText(e).width,l),s+i.getHeight(t.top,p)+(n+1)*i.getLength(c))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,a)},a.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},a.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=O(this.FPS,r,c,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?c:h;break}h=c,s=l}},a.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())},a.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},a.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.stopIndex,h=i.endIndex,c=i._defaultConfig,l=c.accelerationTime,u=c.decelerationTime,f=c.speed;if(0!==r){if(-1!==a){3!==r||this.endIndex||this.carveOnGunwaleOfAMovingBoat();var d=Date.now()-this.startTime,p=Date.now()-this.endTime,g=this.currIndex;if(1===r||d<l){this.FPS=d/t;var v=W(d,.1,f-.1,l);v===f&&(this.step=2),g+=v%o.length}else 2===r?(g+=f%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(g=O(p,s,h,u),p>=u&&(this.step=0)):this.stop(-1);this.currIndex=g,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}))||{})},a.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},a.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},a}(z),$=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.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 e(o,t),o.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)},o.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)},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,"slots",t.slots||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"endCallback",t.end)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({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 i({borderRadius:0,fontColor:"#000",fontSize:"18px",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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.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,l=this.displacementWidthOrHeight(),u=l.cellWidth,d=l.cellHeight,p=l.widthAndSpacing,g=l.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=d*r,l=0,v=function(t,e){for(var i={},n=[],r=0;r<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];l+=z;var x=r.background||i.background;if(c(x)){var k=t.getLength(s(r,"borderRadius")?r.borderRadius:i.borderRadius);I(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,d),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,d)],h=s[0],c=s[1];t.drawImage(S,n,h,c,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,c=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(c,u);p=f(S,h(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(e.top,d)+(n+1)*t.getLength(a))}))}))}}));for(var m=t.displacement([o,0,u,l],[0,a,l,d]),y=m[0],C=m[1],z=m[2],x=m[3],k=l;k<w+l;){var W=t.displacement([y,k],[k,C]),O=W[0],T=W[1];t.drawImage(S,b,y,C,z,x,O,T,z,x),k+=l}}}))},o.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,h=e.w,u=e.h,f=l(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return c(w)&&(I(i,a,s,h,u,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,h,u),c=o[0],l=o[1],f=[t.getOffsetX(c,h),t.getHeight(e.top,u)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,c,l)}})),{x:a+g,y:s+d,w:h-g-v,h:u-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},o.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,h=o.w,c=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(c-g)/2,-(h-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(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)}))}},o.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=O(t.FPS,u,d,i.decelerationTime)-u;if(Math.abs(p)>s){t.endScroll[o]=d;break}}}))},o.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())},o.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(!a(t,"array"))return this.stop(-1),console.error("stop() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(t,"]) 参数长度的不正确"));this.prizeFlag=t}(null===(e=this.prizeFlag)||void 0===e?void 0:e.includes(-1))?(this.prizeFlag=[],this.step=0):this.step=2}},o.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<u){n.FPS=d/t;var y=W(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=O(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},o.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},o.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,h=o.w,c=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(c-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(h-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},o}(z),E=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,I(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},A=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,h=s.length,c=0;c<h;c+=4){var l=s[c+3];0!==l&&(s[c+3]=l*e)}n.putImageData(a,0,0)}return i};export{_ as LuckyGrid,T as LuckyWheel,$ as SlotMachine,E as cutRound,A as opacity}; | ||
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 a(t){try{h(n.next(t))}catch(t){o(t)}}function s(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}h((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function o(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),i=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var n=arguments[1],r=0;r<i;){var o=e[r];if(t.call(n,o,r,e))return o;r++}}});var a=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];return e.some((function(e){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()===e}))},s=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},c=function(t){if("string"!=typeof t)return!1;if("transparent"===(t=t.toLocaleLowerCase().trim()))return!1;if(/^rgba/.test(t)){var e=/([^\s,]+)\)$/.exec(t);if(0===(null===(i=e)?0:"object"==typeof i?NaN:"number"==typeof i?i:"string"==typeof i?"%"===i[i.length-1]?Number(i.slice(0,-1))/100:Number(i):NaN))return!1}var i;return!0},l=function(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 c in h)h[c]=Object.prototype.hasOwnProperty.call(t,c)&&a(t[c],"string","number")?~~String(t[c]).replace(/px/g,""):h[c];return[n,r,o,s]},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}))},f=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;s<e.length;s++){r+=e[s];var h=t.measureText(r).width,c=i(o);if(n===o.length+1&&(h+=a),c<0)return o;if(h>c&&(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},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 v=Array.prototype,m=Object.create(v);["push","pop","shift","unshift","sort","splice","reverse"].forEach((function(t){m[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var n=v[t].apply(this,e),r=this.__luckyOb__;return["push","unshift","splice"].includes(t)&&r.walk(this),r.dep.notify(),n}}));var w=function(){function t(t){this.dep=new d,g(t,"__luckyOb__",this),Array.isArray(t)&&(p?t.__proto__=m:Object.getOwnPropertyNames(m).forEach((function(e){g(t,e,m[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){b(t,e,t[e])}))},t}();function y(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new w(t)}function b(t,e,i){var n=new d,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=y(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return d.target&&(n.addSub(d.target),s&&s.dep.addSub(d.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=y(e),n.notify()))}})}}var S=0,C=function(){function t(t,e,i,n){void 0===n&&(n={}),this.id=S++,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}(),z=function(){function t(t,e){var i=this;this.version="1.7.19",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","".concat("lucky-canvas","@").concat("1.7.19")),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var a=this.config,s=a.flag,h=a.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*h:t}))),t.drawImage.apply(t,o([i],n));var c=i.canvas.getContext("2d");n=n.map((function(t){return t*h}));var l=c.getImageData.apply(c,n.slice(0,4));t.putImageData.apply(t,o([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return a(t,"number")?t:a(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!s(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&b(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 C(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),x=function(t){return Math.PI/180*t},k=function(t,e,i,n,r,o){t.beginPath();var a,s,h=x(90/Math.PI/i*o),c=n+h,l=r-h;t.arc(0,0,i,c,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},I=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],h=Math.min(o,a),c=Math.PI;s>h/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()},W=function(t,e,i,n){return t>=n&&(t=n),i*(t/=n)*t+e},O=function(t,e,i,n){return t>=n&&(t=n),-i*(t/=n)*(t-2)+e},T=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.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 e(o,t),o.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)},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,this.step=0,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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},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)&&0===this.step&&(null===(e=this.startCallback)||void 0===e||e.call(this,t))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.prototype.drawBlock=function(t,e,i){var n=this,r=this.ctx;c(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.getHeight(e.top,2*t)-t],l=c[0],u=c[1];r.save(),e.rotate&&r.rotate(x(n.rotateDeg)),n.drawImage(r,o,l,u,s,h),r.restore()}}))},o.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.prizeRadian=x(this.prizeDeg);var l=x(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},d=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;c(p)&&(o.fillStyle=p,k(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),o.rotate(n+x(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.prizeRadian*i.prizeRadius,r),s=a[0],h=a[1],c=[i.getOffsetX(s),i.getHeight(t.top,r)],l=c[0],u=c[1];i.drawImage(o,n,l,u,s,h)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,c=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(c>>0,"px ").concat(l);var m=String(t.text);(p?f(o,h(m),(function(e){var n=2*((i.prizeRadius-d(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),d(t,r,i))}))})),o.rotate(x(360)-n-x(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(t.radius,i.prizeRadius);i.maxBtnRadius=Math.max(i.maxBtnRadius,n),c(t.background)&&(o.beginPath(),o.fillStyle=t.background,o.arc(0,0,n,0,2*Math.PI,!1),o.fill()),t.pointer&&c(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.getHeight(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="".concat(r," ").concat(a>>0,"px ").concat(h),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),d(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},o.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=O(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-c>f-a?u:l;break}l=u,c=f}},o.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())},o.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},o.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<s){this.FPS=l/t;var d=W(l,0,c,s);d===c&&(this.step=2),f+=d%360}else 2===r?(f+=c%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(f=O(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}))||{})},o.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr-this.Radius,e/i.dpr-this.Radius]},o}(z),_=function(t){function a(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 e(a,t),a.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)},a.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)},a.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)},a.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({gutter:5,speed:20,accelerationTime:2500,decelerationTime:2500},t.defaultConfig);return e.gutter=t.getLength(e.gutter),e.speed=e.speed/40,e})),this.$computed(this,"_defaultStyle",(function(){return i({borderRadius:20,fontColor:"#000",fontSize:"18px",fontStyle:"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)}))},a.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()}))},a.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},a.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()}))}))}))},a.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]),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))}}))},a.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if("buttons"===t&&!o.buttons.length&&o.button&&(h=o.button),h&&h.imgs){var c=h.imgs[i];if(c){var l=[o.loadImg(c.src,c),c.activeSrc&&o.loadImg(c.activeSrc,c,"$activeResolve")];Promise.all(l).then((function(t){var e=t[0],i=t[1];return n(o,void 0,void 0,(function(){var t;return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},a.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,a=n.ctx,s=n._defaultConfig,u=n._defaultStyle,d=n._activeStyle;null===(t=r.beforeDraw)||void 0===t||t.call(this,a),a.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,n){var r=t.x,o=t.y,s=t.w,h=t.h,f=l(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||u.background;return c(w)&&(a.fillStyle=i.handleBackground(r,o,s,h,w),I(a,r,o,s,h,m),a.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.getHeight(t.top,h)],d=f[0],p=f[1];i.drawImage(a,n,r+d,o+p,l,u)}})),{x:r+g,y:o+d,w:s-g-v,h:h-d-p}}),{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]),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 v=g?d.background:t.background||u.background;if(c(v)){var m=(g?d.shadow:t.shadow||u.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(a.shadowColor=m[3],a.shadowOffsetX=m[0]*r.dpr,a.shadowOffsetY=m[1]*r.dpr,a.shadowBlur=m[2],m[0]>0?l-=m[0]:(l+=m[0],o-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),a.fillStyle=i.handleBackground(o,s,l,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:u.borderRadius);I(a,o,s,l,p,w),a.fill(),a.shadowColor="rgba(0, 0, 0, 0)",a.shadowOffsetX=0,a.shadowOffsetY=0,a.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=g&&r||n;if(h){var c=i.computedWidthAndHeight(h,t,l,p),u=c[0],f=c[1],d=[o+i.getOffsetX(u,l),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(a,h,v,m,u,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&d.fontStyle?d.fontStyle:t.fontStyle||u.fontStyle,n=g&&d.fontWeight?d.fontWeight:t.fontWeight||u.fontWeight,r=g&&d.fontSize?i.getLength(d.fontSize):i.getLength(t.fontSize||u.fontSize),c=g&&d.lineHeight?d.lineHeight:t.lineHeight||u.lineHeight||t.fontSize||u.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:u.wordWrap,m=t.lengthLimit||u.lengthLimit,w=t.lineClamp||u.lineClamp;a.font="".concat(n," ").concat(r>>0,"px ").concat(e),a.fillStyle=g&&d.fontColor?d.fontColor:t.fontColor||u.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,l);y=f(a,h(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){a.fillText(e,o+i.getOffsetX(a.measureText(e).width,l),s+i.getHeight(t.top,p)+(n+1)*i.getLength(c))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,a)},a.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},a.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=O(this.FPS,r,c,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?c:h;break}h=c,s=l}},a.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())},a.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=u(e)}t<0?(this.step=0,this.prizeFlag=-1):(this.step=2,this.prizeFlag=t%this.prizes.length)}},a.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<h){this.FPS=u/t;var p=W(u,.1,l-.1,h);p===l&&(this.step=2),d+=p%o.length}else 2===r?(d+=l%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(d=O(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}))||{})},a.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},a.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},a}(z),$=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.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 e(o,t),o.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)},o.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)},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,"slots",t.slots||[]),this.$set(this,"defaultConfig",t.defaultConfig||{}),this.$set(this,"defaultStyle",t.defaultStyle||{}),this.$set(this,"endCallback",t.end)},o.prototype.initComputed=function(){var t=this;this.$computed(this,"_defaultConfig",(function(){var e=i({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 i({borderRadius:0,fontColor:"#000",fontSize:"18px",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.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()}))},o.prototype.init=function(){var t,e;return n(this,void 0,void 0,(function(){var i;return r(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]}}))}))},o.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()}))}))}))},o.prototype.loadAndCacheImg=function(t,e,i){return n(this,void 0,void 0,(function(){var o=this;return r(this,(function(a){return[2,new Promise((function(a,s){var h=o[t][e];if(h&&h.imgs){var c=h.imgs[i];c&&o.loadImg(c.src,c).then((function(t){return n(o,void 0,void 0,(function(){return r(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("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}))]}))}))},o.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,l=this.displacementWidthOrHeight(),u=l.cellWidth,d=l.cellHeight,p=l.widthAndSpacing,g=l.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=d*r,l=0,v=function(t,e){for(var i={},n=[],r=0;r<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];l+=z;var x=r.background||i.background;if(c(x)){var k=t.getLength(s(r,"borderRadius")?r.borderRadius:i.borderRadius);I(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,d),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,d)],h=s[0],c=s[1];t.drawImage(S,n,h,c,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,c=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(c,u);p=f(S,h(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(e.top,d)+(n+1)*t.getLength(a))}))}))}}));for(var m=t.displacement([o,0,u,l],[0,a,l,d]),y=m[0],C=m[1],z=m[2],x=m[3],k=l;k<w+l;){var W=t.displacement([y,k],[k,C]),O=W[0],T=W[1];t.drawImage(S,b,y,C,z,x,O,T,z,x),k+=l}}}))},o.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,h=e.w,u=e.h,f=l(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return c(w)&&(I(i,a,s,h,u,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,h,u),c=o[0],l=o[1],f=[t.getOffsetX(c,h),t.getHeight(e.top,u)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,c,l)}})),{x:a+g,y:s+d,w:h-g-v,h:u-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},o.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,h=o.w,c=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(c-g)/2,-(h-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(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)}))}},o.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=O(t.FPS,u,d,i.decelerationTime)-u;if(Math.abs(p)>s){t.endScroll[o]=d;break}}}))},o.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())},o.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(!a(t,"array"))return this.stop(-1),console.error("stop() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(t,"]) 参数长度的不正确"));this.prizeFlag=t}(null===(e=this.prizeFlag)||void 0===e?void 0:e.includes(-1))?(this.prizeFlag=[],this.step=0):this.step=2}},o.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<u){n.FPS=d/t;var y=W(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=O(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},o.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},o.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,h=o.w,c=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(c-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(h-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},o}(z),E=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,I(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},A=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,h=s.length,c=0;c<h;c+=4){var l=s[c+3];0!==l&&(s[c+3]=l*e)}n.putImageData(a,0,0)}return i};export{_ as LuckyGrid,T as LuckyWheel,$ as SlotMachine,E as cutRound,A as opacity}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -15,3 +15,3 @@ !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 a(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),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}))},c=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},l=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=(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 c={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:a};for(var h in c)c[h]=Object.prototype.hasOwnProperty.call(t,h)&&s(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):c[h];return[n,r,o,a]},f=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}))},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;s<e.length;s++){r+=e[s];var c=t.measureText(r).width,h=i(o);if(n===o.length+1&&(c+=a),h<0)return o;if(c>h&&(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.18",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<arguments.length;i++)e[i]=arguments[i];var n=w[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 g,m(t,"__luckyOb__",this),Array.isArray(t)&&(v?t.__proto__=y:Object.getOwnPropertyNames(y).forEach((function(e){m(t,e,y[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){C(t,e,t[e])}))},t}();function S(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new b(t)}function C(t,e,i){var n=new g,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=S(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return g.target&&(n.addSub(g.target),s&&s.dep.addSub(g.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=S(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(){g.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),g.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}(),k=function(){function t(t,e){var i=this;this.version=p,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","".concat("lucky-canvas","@").concat(p)),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=this.config,s=o.flag,c=o.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*c:t}))),t.drawImage.apply(t,a([i],n));var h=i.canvas.getContext("2d");n=n.map((function(t){return t*c}));var l=h.getImageData.apply(h,n.slice(0,4));t.putImageData.apply(t,a([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!c(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&C(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new x(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),I=function(t){return Math.PI/180*t},W=function(t,e,i,n,r,o){t.beginPath();var a,s,c=I(90/Math.PI/i*o),h=n+c,l=r-c;t.arc(0,0,i,h,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},O=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],c=Math.min(o,a),h=Math.PI;s>c/2&&(s=c/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,-h/2,0),t.lineTo(n+o,r+a-s),t.arc(n+o-s,r+a-s,s,0,h/2),t.lineTo(n+s,r+a),t.arc(n+s,r+a-s,s,h/2,h),t.lineTo(n,r+s),t.arc(n+s,r+s,s,h,-h/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},$=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.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.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,this.step=0,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.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 c=n[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&n.loadImg(h.src,h).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(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],c=a[1],h=[n.getOffsetX(s),n.getHeight(e.top,2*t)-t],l=h[0],u=h[1];r.save(),e.rotate&&r.rotate(I(n.rotateDeg)),n.drawImage(r,o,l,u,s,c),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.prizeRadian=I(this.prizeDeg);var c=I(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;l(p)&&(o.fillStyle=p,W(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),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.prizeRadian*i.prizeRadius,r),s=a[0],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,r)],l=h[0],u=h[1];i.drawImage(o,n,l,u,s,c)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,c=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(c>>0,"px ").concat(l);var m=String(t.text);(p?d(o,h(m),(function(e){var n=2*((i.prizeRadius-f(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),f(t,r,i))}))})),o.rotate(I(360)-n-I(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(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],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,n)],l=h[0],u=h[1];i.drawImage(o,r,l,u,s,c)}})),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),c=t.fontStyle||s.fontStyle;o.fillStyle=e,o.font="".concat(r," ").concat(a>>0,"px ").concat(c),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),f(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.prototype.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),c=0,h=0,l=0;++c;){var u=360*c-i*n-r-e.offsetDegree+s-n/2,f=_(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-h>f-a?u:l;break}l=u,h=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.stopDeg,s=i.endDeg,c=i._defaultConfig,h=c.accelerationTime,l=c.decelerationTime,u=c.speed;if(0!==r){if(-1!==o){3!==r||this.endDeg||this.carveOnGunwaleOfAMovingBoat();var f=Date.now()-this.startTime,d=Date.now()-this.endTime,p=this.rotateDeg;if(1===r||f<h){this.FPS=f/t;var g=T(f,0,u,h);g===u&&(this.step=2),p+=g%360}else 2===r?(p+=u%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(p=_(d,a,s,l),d>=l&&(this.step=0)):this.stop(-1);this.rotateDeg=p,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),E=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||"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.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],c=o[2],h=o[3];i.beginPath(),i.rect(a,s,c,h),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 c=n[t][e];if("buttons"===t&&!n.buttons.length&&n.button&&(c=n.button),c&&c.imgs){var h=c.imgs[i];if(h){var l=[n.loadImg(h.src,h),h.activeSrc&&n.loadImg(h.activeSrc,h,"$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=h.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(h.src,e),i&&this.ImageCache.set(h.activeSrc,i),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,c=n._defaultStyle,f=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,f=u(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||c.background;return l(w)&&(o.fillStyle=i.handleBackground(r,a,s,h,w),O(o,r,a,s,h,m),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.getHeight(t.top,h)],d=f[0],p=f[1];i.drawImage(o,n,r+d,a+p,l,u)}})),{x:r+g,y:a+d,w:s-g-v,h:h-d-p}}),{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],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var v=g?f.background:t.background||c.background;if(l(v)){var m=(g?f.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?u-=m[0]:(u+=m[0],a-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),o.fillStyle=i.handleBackground(a,s,u,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:c.borderRadius);O(o,a,s,u,p,w),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 c=g&&r||n;if(c){var h=i.computedWidthAndHeight(c,t,u,p),l=h[0],f=h[1],d=[a+i.getOffsetX(l,u),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(o,c,v,m,l,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&f.fontStyle?f.fontStyle:t.fontStyle||c.fontStyle,n=g&&f.fontWeight?f.fontWeight:t.fontWeight||c.fontWeight,r=g&&f.fontSize?i.getLength(f.fontSize):i.getLength(t.fontSize||c.fontSize),l=g&&f.lineHeight?f.lineHeight:t.lineHeight||c.lineHeight||t.fontSize||c.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:c.wordWrap,m=t.lengthLimit||c.lengthLimit,w=t.lineClamp||c.lineClamp;o.font="".concat(n," ").concat(r>>0,"px ").concat(e),o.fillStyle=g&&f.fontColor?f.fontColor:t.fontColor||c.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,u);y=d(o,h(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){o.fillText(e,a+i.getOffsetX(o.measureText(e).width,u),s+i.getHeight(t.top,p)+(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(),c=[0,0,0,0];if(s.includes("deg")){var h=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?c=[e,i+r,e+n,i+r-n*h(s-0)]:s>=45&&s<90?c=[e,i+r,e+n-r*h(s-45),i]:s>=90&&s<135?c=[e+n,i+r,e+n-r*h(s-90),i]:s>=135&&s<180?c=[e+n,i+r,e,i+n*h(s-135)]:s>=180&&s<225?c=[e+n,i,e,i+n*h(s-180)]:s>=225&&s<270?c=[e+n,i,e+r*h(s-225),i+r]:s>=270&&s<315?c=[e,i,e+r*h(s-270),i+r]:s>=315&&s<360&&(c=[e,i,e+n,i+r-n*h(s-315)])}else s.includes("top")?c=[e,i+r,e,i]:s.includes("bottom")?c=[e,i,e,i+r]:s.includes("left")?c=[e+n,i,e,i]:s.includes("right")&&(c=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,c.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,c=0;++a;){var h=this.prizes.length*a+i-r,l=_(this.FPS,r,h,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?h:c;break}c=h,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.stopIndex,c=i.endIndex,h=i._defaultConfig,l=h.accelerationTime,u=h.decelerationTime,f=h.speed;if(0!==r){if(-1!==a){3!==r||this.endIndex||this.carveOnGunwaleOfAMovingBoat();var d=Date.now()-this.startTime,p=Date.now()-this.endTime,g=this.currIndex;if(1===r||d<l){this.FPS=d/t;var v=T(d,.1,f-.1,l);v===f&&(this.step=2),g+=v%o.length}else 2===r?(g+=f%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(g=_(p,s,c,u),p>=u&&(this.step=0)):this.stop(-1);this.currIndex=g,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,c=this.cellHeight,h=this._defaultConfig.gutter,l=[this.prizeArea.x+(s+h)*e,this.prizeArea.y+(c+h)*i];return r&&a&&l.push(s*r+h*(r-1),c*a+h*(a-1)),l},e.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},e}(k),A=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||"300px"),this.$set(this,"height",t.height||"300px"),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 c=n[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&n.loadImg(h.src,h).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(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<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];s+=z;var x=r.background||i.background;if(l(x)){var k=t.getLength(c(r,"borderRadius")?r.borderRadius:i.borderRadius);O(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,f),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,f)],c=s[0],h=s[1];t.drawImage(S,n,c,h,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,c=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(c,u);p=d(S,h(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(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;k<w+s;){var I=t.displacement([y,k],[k,C]),W=I[0],T=I[1];t.drawImage(S,b,y,C,z,x,W,T,z,x),k+=s}}}))},e.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,c=e.w,h=e.h,f=u(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return l(w)&&(O(i,a,s,c,h,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,c,h),l=o[0],u=o[1],f=[t.getOffsetX(l,c),t.getHeight(e.top,h)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,l,u)}})),{x:a+g,y:s+d,w:c-g-v,h:h-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},e.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,c=o.w,h=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(h-g)/2,-(c-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(l%=n);var v=e.displacement([u*i,l,u,h],[l,f*i,c,f]),m=v[0],w=v[1],y=v[2],b=v[3],S=e.displacement([a+p*i,s,u,h],[a,s+g*i,c,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,c=e.direction||i.direction,h=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*h+l*f*c-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() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(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,c=r._defaultConfig,h=r.cellAndSpacing,l=r.slots,u=c.accelerationTime,f=c.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=h*r.length,g=Math.abs(e.speed||c.speed),v=e.direction||c.direction,m=0,w=n.scroll[i];if(1===a||d<u){n.FPS=d/t;var y=T(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=_(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},e.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},e.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,c=o.w,h=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(h-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(c-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},e}(k);t.LuckyGrid=E,t.LuckyWheel=$,t.SlotMachine=A,t.cutRound=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,O(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},t.opacity=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,c=s.length,h=0;h<c;h+=4){var l=s[h+3];0!==l&&(s[h+3]=l*e)}n.putImageData(a,0,0)}return i},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 a(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}function o(t,e){var i,n,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function a(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t}Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var i=Object(this),n=i.length>>>0;if(0===n)return!1;var r,o,a=0|e,s=Math.max(a>=0?a:n-Math.abs(a),0);for(;s<n;){if((r=i[s])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;s++}return!1}}),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}))},c=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},h=function(t){return[].filter.call(t,(function(t){return"\n"!==t})).join("")},l=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=(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 c={paddingTop:n,paddingBottom:r,paddingLeft:o,paddingRight:a};for(var h in c)c[h]=Object.prototype.hasOwnProperty.call(t,h)&&s(t[h],"string","number")?~~String(t[h]).replace(/px/g,""):c[h];return[n,r,o,a]},f=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}))},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;s<e.length;s++){r+=e[s];var c=t.measureText(r).width,h=i(o);if(n===o.length+1&&(c+=a),h<0)return o;if(c>h&&(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.19",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<arguments.length;i++)e[i]=arguments[i];var n=w[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 g,m(t,"__luckyOb__",this),Array.isArray(t)&&(v?t.__proto__=y:Object.getOwnPropertyNames(y).forEach((function(e){m(t,e,y[e])}))),this.walk(t)}return t.prototype.walk=function(t){Object.keys(t).forEach((function(e){C(t,e,t[e])}))},t}();function S(t){if(t&&"object"==typeof t)return"__luckyOb__"in t?t.__luckyOb__:new b(t)}function C(t,e,i){var n=new g,r=Object.getOwnPropertyDescriptor(t,e);if(!r||!1!==r.configurable){var o=r&&r.get,a=r&&r.set;o&&!a||2!==arguments.length||(i=t[e]);var s=S(i);Object.defineProperty(t,e,{get:function(){var e=o?o.call(t):i;return g.target&&(n.addSub(g.target),s&&s.dep.addSub(g.target)),e},set:function(e){e!==i&&(i=e,o&&!a||(a?a.call(t,e):i=e,s=S(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(){g.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),g.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}(),k=function(){function t(t,e){var i=this;this.version=p,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","".concat("lucky-canvas","@").concat(p)),t.canvasElement.addEventListener("click",(function(t){return i.handleClick(t)}))),this.ctx=t.ctx,this.initWindowFunction(),this.config.ctx||console.error("无法获取到 CanvasContext2D"),window&&"function"==typeof window.addEventListener&&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(){return i.resize()}),300)),window&&"function"==typeof window.MutationObserver&&new window.MutationObserver((function(){i.resize()})).observe(document.documentElement,{attributes:!0})}return t.prototype.resize=function(){var t,e;null===(e=(t=this.config).beforeResize)||void 0===e||e.call(t),this.setHTMLFontSize(),this.setDpr(),this.resetWidthAndHeight(),this.zoomCanvas()},t.prototype.initLucky=function(){if(this.resize(),!this.boxWidth||!this.boxHeight)return console.error("无法获取到宽度或高度")},t.prototype.handleClick=function(t){},t.prototype.setHTMLFontSize=function(){window&&(this.htmlFontSize=+window.getComputedStyle(document.documentElement).fontSize.slice(0,-2))},t.prototype.clearCanvas=function(){var t=[this.boxWidth,this.boxHeight],e=t[0],i=t[1];this.ctx.clearRect(-e,-i,2*e,2*i)},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],a=r[1];i&&(i.width=o,i.height=a,i.style.width="".concat(o,"px"),i.style.height="".concat(a,"px"),i.style["transform-origin"]="left top",i.style.transform="scale(".concat(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("=> '".concat(e.src,"' 不能为空或不合法")),"WEB"!==n.config.flag)return e[i]=r,void(e.$reject=o);var a=new Image;a.onload=function(){return r(a)},a.onerror=function(){return o("=> '".concat(e.src,"' 图片加载失败"))},a.src=t}))},t.prototype.drawImage=function(t,e){for(var i,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=this.config,s=o.flag,c=o.dpr;if(["WEB","MP-WX"].includes(s))i=e;else{if(!["UNI-H5","UNI-MP","TARO-H5","TARO-MP"].includes(s))return console.error("意料之外的 flag, 该平台尚未兼容!");i=e.path}if(!i.canvas)return 8===n.length&&(n=n.map((function(t,e){return e<4?t*c:t}))),t.drawImage.apply(t,a([i],n));var h=i.canvas.getContext("2d");n=n.map((function(t){return t*c}));var l=h.getImageData.apply(h,n.slice(0,4));t.putImageData.apply(t,a([l],n.slice(4,6)))},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;void 0===e&&(e=1);var n=this.config;return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/,(function(t,r,o){var a={"%":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}}[o];if(a)return a(r);var s=n.handleCssUnit||n.unitFunc;return s?s(r,o):r})))},t.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)]},t.prototype.getWidth=function(t,e){return s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},t.prototype.getHeight=function(t,e){return s(t,"number")?t:s(t,"string")?this.changeUnits(t,e):0},t.prototype.getOffsetX=function(t,e){return void 0===e&&(e=0),(e-t)/2},t.prototype.getOffscreenCanvas=function(t,e){if(!c(this,"_offscreenCanvas")&&(window&&window.document&&"WEB"===this.config.flag?this._offscreenCanvas=document.createElement("canvas"):this._offscreenCanvas=this.config.offscreenCanvas,!this._offscreenCanvas))return console.log("离屏 Canvas 无法渲染!");var i=this.config.dpr,n=this._offscreenCanvas;n.width=(t||300)*i,n.height=(e||150)*i;var r=n.getContext("2d");return r.clearRect(0,0,t,e),r.scale(i,i),r.dpr=i,{_offscreenCanvas:n,_ctx:r}},t.prototype.$set=function(t,e,i){t&&"object"==typeof t&&C(t,e,i)},t.prototype.$computed=function(t,e,i){var n=this;Object.defineProperty(t,e,{get:function(){return i.call(n)}})},t.prototype.$watch=function(t,e,i){void 0===i&&(i={}),"object"==typeof e&&(e=(i=e).handler);var n=new x(this,t,e,i);return i.immediate&&e.call(this,n.value),function(){}},t}(),I=function(t){return Math.PI/180*t},W=function(t,e,i,n,r,o){t.beginPath();var a,s,c=I(90/Math.PI/i*o),h=n+c,l=r-c;t.arc(0,0,i,h,l,!1),t.lineTo.apply(t,(a=(n+r)/2,s=o/2/Math.abs(Math.sin((n-r)/2)),[+(Math.cos(a)*s).toFixed(8),+(Math.sin(a)*s).toFixed(8)])),t.closePath()},O=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=e[0],r=e[1],o=e[2],a=e[3],s=e[4],c=Math.min(o,a),h=Math.PI;s>c/2&&(s=c/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,-h/2,0),t.lineTo(n+o,r+a-s),t.arc(n+o-s,r+a-s,s,0,h/2),t.lineTo(n+s,r+a),t.arc(n+s,r+a-s,s,h/2,h),t.lineTo(n,r+s),t.arc(n+s,r+s,s,h,-h/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},$=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.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.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,this.step=0,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.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 c=n[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&n.loadImg(h.src,h).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(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],c=a[1],h=[n.getOffsetX(s),n.getHeight(e.top,2*t)-t],l=h[0],u=h[1];r.save(),e.rotate&&r.rotate(I(n.rotateDeg)),n.drawImage(r,o,l,u,s,c),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.prizeRadian=I(this.prizeDeg);var c=I(this.rotateDeg-90+this.prizeDeg/2+a.offsetDegree),u=function(t){return i.getOffsetX(o.measureText(t).width)},f=function(t,e,n){var r=t.lineHeight||s.lineHeight||t.fontSize||s.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,r=i.prizeRadius-i.maxBtnRadius,p=t.background||s.background;l(p)&&(o.fillStyle=p,W(o,i.maxBtnRadius,i.prizeRadius,n-i.prizeRadian/2,n+i.prizeRadian/2,i.getLength(a.gutter)),o.fill());var g=Math.cos(n)*i.prizeRadius,v=Math.sin(n)*i.prizeRadius;o.translate(g,v),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.prizeRadian*i.prizeRadius,r),s=a[0],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,r)],l=h[0],u=h[1];i.drawImage(o,n,l,u,s,c)}})),t.fonts&&t.fonts.forEach((function(t){var e=t.fontColor||s.fontColor,n=t.fontWeight||s.fontWeight,c=i.getLength(t.fontSize||s.fontSize),l=t.fontStyle||s.fontStyle,p=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:s.wordWrap,g=t.lengthLimit||s.lengthLimit,v=t.lineClamp||s.lineClamp;o.fillStyle=e,o.font="".concat(n," ").concat(c>>0,"px ").concat(l);var m=String(t.text);(p?d(o,h(m),(function(e){var n=2*((i.prizeRadius-f(t,r,e.length))*Math.tan(i.prizeRadian/2))-i.getLength(a.gutter);return i.getWidth(g,n)}),v):m.split("\n")).filter((function(t){return!!t})).forEach((function(e,i){o.fillText(e,u(e),f(t,r,i))}))})),o.rotate(I(360)-n-I(90)),o.translate(-g,-v)})),o.restore(),this.buttons.forEach((function(t,e){var n=i.getHeight(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],c=a[1],h=[i.getOffsetX(s),i.getHeight(t.top,n)],l=h[0],u=h[1];i.drawImage(o,r,l,u,s,c)}})),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),c=t.fontStyle||s.fontStyle;o.fillStyle=e,o.font="".concat(r," ").concat(a>>0,"px ").concat(c),String(t.text).split("\n").forEach((function(e,i){o.fillText(e,u(e),f(t,n,i))}))}))})),null===(e=r.afterDraw)||void 0===e||e.call(this,o)},e.prototype.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),c=0,h=0,l=0;++c;){var u=360*c-i*n-r-e.offsetDegree+s-n/2,f=_(this.FPS,o,u,e.decelerationTime)-o;if(f>a){this.endDeg=a-h>f-a?u:l;break}l=u,h=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,c=a.decelerationTime,h=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<s){this.FPS=l/t;var d=T(l,0,h,s);d===h&&(this.step=2),f+=d%360}else 2===r?(f+=h%360,void 0!==o&&o>=0&&(this.step=3,this.stopDeg=0,this.endDeg=0)):3===r?(f=_(u,this.stopDeg,this.endDeg,c),u>=c&&(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),E=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||"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.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],c=o[2],h=o[3];i.beginPath(),i.rect(a,s,c,h),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 c=n[t][e];if("buttons"===t&&!n.buttons.length&&n.button&&(c=n.button),c&&c.imgs){var h=c.imgs[i];if(h){var l=[n.loadImg(h.src,h),h.activeSrc&&n.loadImg(h.activeSrc,h,"$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=h.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(h.src,e),i&&this.ImageCache.set(h.activeSrc,i),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(n)),s()}))}}}))]}))}))},e.prototype.draw=function(){var t,e,i=this,n=this,r=n.config,o=n.ctx,s=n._defaultConfig,c=n._defaultStyle,f=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,f=u(e),d=f[0],p=f[1],g=f[2],v=f[3],m=e.borderRadius?i.getLength(e.borderRadius):0,w=e.background||c.background;return l(w)&&(o.fillStyle=i.handleBackground(r,a,s,h,w),O(o,r,a,s,h,m),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.getHeight(t.top,h)],d=f[0],p=f[1];i.drawImage(o,n,r+d,a+p,l,u)}})),{x:r+g,y:a+d,w:s-g-v,h:h-d-p}}),{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],p=n[3],g=!1;(void 0===i.prizeFlag||i.prizeFlag>-1)&&(g=e===i.currIndex%i.prizes.length>>0);var v=g?f.background:t.background||c.background;if(l(v)){var m=(g?f.shadow:t.shadow||c.shadow).replace(/px/g,"").split(",")[0].split(" ").map((function(t,e){return e<3?Number(t):t}));4===m.length&&(o.shadowColor=m[3],o.shadowOffsetX=m[0]*r.dpr,o.shadowOffsetY=m[1]*r.dpr,o.shadowBlur=m[2],m[0]>0?u-=m[0]:(u+=m[0],a-=m[0]),m[1]>0?p-=m[1]:(p+=m[1],s-=m[1])),o.fillStyle=i.handleBackground(a,s,u,p,v);var w=i.getLength(t.borderRadius?t.borderRadius:c.borderRadius);O(o,a,s,u,p,w),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 c=g&&r||n;if(c){var h=i.computedWidthAndHeight(c,t,u,p),l=h[0],f=h[1],d=[a+i.getOffsetX(l,u),s+i.getHeight(t.top,p)],v=d[0],m=d[1];i.drawImage(o,c,v,m,l,f)}}})),t.fonts&&t.fonts.forEach((function(t){var e=g&&f.fontStyle?f.fontStyle:t.fontStyle||c.fontStyle,n=g&&f.fontWeight?f.fontWeight:t.fontWeight||c.fontWeight,r=g&&f.fontSize?i.getLength(f.fontSize):i.getLength(t.fontSize||c.fontSize),l=g&&f.lineHeight?f.lineHeight:t.lineHeight||c.lineHeight||t.fontSize||c.fontSize,v=Object.prototype.hasOwnProperty.call(t,"wordWrap")?t.wordWrap:c.wordWrap,m=t.lengthLimit||c.lengthLimit,w=t.lineClamp||c.lineClamp;o.font="".concat(n," ").concat(r>>0,"px ").concat(e),o.fillStyle=g&&f.fontColor?f.fontColor:t.fontColor||c.fontColor;var y=[],b=String(t.text);if(v){var S=i.getWidth(m,u);y=d(o,h(b),(function(){return S}),w)}else y=b.split("\n");y.forEach((function(e,n){o.fillText(e,a+i.getOffsetX(o.measureText(e).width,u),s+i.getHeight(t.top,p)+(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(),c=[0,0,0,0];if(s.includes("deg")){var h=function(t){return Math.tan(t/180*Math.PI)};(s=s.slice(0,-3)%360)>=0&&s<45?c=[e,i+r,e+n,i+r-n*h(s-0)]:s>=45&&s<90?c=[e,i+r,e+n-r*h(s-45),i]:s>=90&&s<135?c=[e+n,i+r,e+n-r*h(s-90),i]:s>=135&&s<180?c=[e+n,i+r,e,i+n*h(s-135)]:s>=180&&s<225?c=[e+n,i,e,i+n*h(s-180)]:s>=225&&s<270?c=[e+n,i,e+r*h(s-225),i+r]:s>=270&&s<315?c=[e,i,e+r*h(s-270),i+r]:s>=315&&s<360&&(c=[e,i,e+n,i+r-n*h(s-315)])}else s.includes("top")?c=[e,i+r,e,i]:s.includes("bottom")?c=[e,i,e,i+r]:s.includes("left")?c=[e+n,i,e,i]:s.includes("right")&&(c=[e,i,e+n,i]);var l=t.createLinearGradient.apply(t,c.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,c=0;++a;){var h=this.prizes.length*a+i-r,l=_(this.FPS,r,h,e.decelerationTime)-r;if(l>o){this.endIndex=o-s>l-o?h:c;break}c=h,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,c=s.accelerationTime,h=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<c){this.FPS=u/t;var p=T(u,.1,l-.1,c);p===l&&(this.step=2),d+=p%o.length}else 2===r?(d+=l%o.length,void 0!==a&&a>=0&&(this.step=3,this.stopIndex=0,this.endIndex=0)):3===r?(d=_(f,this.stopIndex,this.endIndex,h),f>=h&&(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,c=this.cellHeight,h=this._defaultConfig.gutter,l=[this.prizeArea.x+(s+h)*e,this.prizeArea.y+(c+h)*i];return r&&a&&l.push(s*r+h*(r-1),c*a+h*(a-1)),l},e.prototype.conversionAxis=function(t,e){var i=this.config;return[t/i.dpr,e/i.dpr]},e}(k),A=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||"300px"),this.$set(this,"height",t.height||"300px"),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 c=n[t][e];if(c&&c.imgs){var h=c.imgs[i];h&&n.loadImg(h.src,h).then((function(t){return r(n,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return"function"!=typeof h.formatter?[3,2]:[4,Promise.resolve(h.formatter.call(this,t))];case 1:t=e.sent(),e.label=2;case 2:return this.ImageCache.set(h.src,t),a(),[2]}}))}))})).catch((function(n){console.error("".concat(t,"[").concat(e,"].imgs[").concat(i,"] ").concat(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<t.length;r++)i[r]=t[r];for(r=0;r<e.length;r++){var o=i[e[r]];o&&(n[r]=o)}return n}(t.prizes,n.order);if(v.length){v.forEach((function(r,v){if(r){n.order[v];var m=p*v+e.colSpacing/2,w=g*v+e.rowSpacing/2,y=t.displacement([o,w,g],[m,a,p]),b=y[0],C=y[1],z=y[2];s+=z;var x=r.background||i.background;if(l(x)){var k=t.getLength(c(r,"borderRadius")?r.borderRadius:i.borderRadius);O(S,b,C,u,u,k),S.fillStyle=x,S.fill()}r.imgs&&r.imgs.forEach((function(e,i){var n=t.ImageCache.get(e.src);if(n){var r=t.computedWidthAndHeight(n,e,u,f),o=r[0],a=r[1],s=[b+t.getOffsetX(o,u),C+t.getHeight(e.top,f)],c=s[0],h=s[1];t.drawImage(S,n,c,h,o,a)}})),r.fonts&&r.fonts.forEach((function(e){var n=e.fontStyle||i.fontStyle,r=e.fontWeight||i.fontWeight,o=t.getLength(e.fontSize||i.fontSize),a=e.lineHeight||i.lineHeight||e.fontSize||i.fontSize,s=Object.prototype.hasOwnProperty.call(e,"wordWrap")?e.wordWrap:i.wordWrap,c=e.lengthLimit||i.lengthLimit,l=e.lineClamp||i.lineClamp;S.font="".concat(r," ").concat(o>>0,"px ").concat(n),S.fillStyle=e.fontColor||i.fontColor;var p=[],g=String(e.text);if(s){var v=t.getWidth(c,u);p=d(S,h(g),(function(){return v}),l)}else p=g.split("\n");p.forEach((function(i,n){S.fillText(i,b+t.getOffsetX(S.measureText(i).width,u),C+t.getHeight(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;k<w+s;){var I=t.displacement([y,k],[k,C]),W=I[0],T=I[1];t.drawImage(S,b,y,C,z,x,W,T,z,x),k+=s}}}))},e.prototype.drawBlocks=function(){var t=this,e=this;e.config;var i=e.ctx;e._defaultConfig;var n=e._defaultStyle;return this.prizeArea=this.blocks.reduce((function(e,r,o){var a=e.x,s=e.y,c=e.w,h=e.h,f=u(r),d=f[0],p=f[1],g=f[2],v=f[3],m=r.borderRadius?t.getLength(r.borderRadius):0,w=r.background||n.background;return l(w)&&(O(i,a,s,c,h,m),i.fillStyle=w,i.fill()),r.imgs&&r.imgs.forEach((function(e,n){var r=t.ImageCache.get(e.src);if(r){var o=t.computedWidthAndHeight(r,e,c,h),l=o[0],u=o[1],f=[t.getOffsetX(l,c),t.getHeight(e.top,h)],d=f[0],p=f[1];t.drawImage(i,r,a+d,s+p,l,u)}})),{x:a+g,y:s+d,w:c-g-v,h:h-d-p}}),{x:0,y:0,w:this.boxWidth,h:this.boxHeight})},e.prototype.draw=function(){var t,e=this,i=this,n=i.config,r=i.ctx;i._defaultConfig,i._defaultStyle,null===(t=n.beforeDraw)||void 0===t||t.call(this,r),r.clearRect(0,0,this.boxWidth,this.boxHeight);var o=this.drawBlocks(),a=o.x,s=o.y,c=o.w,h=o.h;if(this._offscreenCanvas){var l=this,u=l.cellWidth,f=l.cellHeight,d=l.cellAndSpacing,p=l.widthAndSpacing,g=l.heightAndSpacing;this.slots.forEach((function(t,i){var n=d*t.order.length,o=e.displacement(-(h-g)/2,-(c-p)/2),l=e.scroll[i]+o;l<0&&(l=l%n+n),l>n&&(l%=n);var v=e.displacement([u*i,l,u,h],[l,f*i,c,f]),m=v[0],w=v[1],y=v[2],b=v[3],S=e.displacement([a+p*i,s,u,h],[a,s+g*i,c,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,c=e.direction||i.direction,h=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*h+l*f*c-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() 无法识别的参数类型 ".concat(typeof t));if(t.length!==this.slots.length)return this.stop(-1),console.error("stop([".concat(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,c=r._defaultConfig,h=r.cellAndSpacing,l=r.slots,u=c.accelerationTime,f=c.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=h*r.length,g=Math.abs(e.speed||c.speed),v=e.direction||c.direction,m=0,w=n.scroll[i];if(1===a||d<u){n.FPS=d/t;var y=T(d,0,g,u);y===g&&(n.step=2),m=(w+y*v)%o}else if(2===a)m=(w+g*v)%o,(null==s?void 0:s.length)===l.length&&(n.step=3,n.stopScroll=[],n.endScroll=[]);else if(3===a&&p){var b=n.stopScroll[i],S=n.endScroll[i];m=_(p,b,S,f),p>=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<l.length;v++){var m=l[v],w=s[v];if(!(null===(e=m.order)||void 0===e?void 0:e.includes(w))||g!==w){g=-1;break}}null===(i=this.endCallback)||void 0===i||i.call(this,this.prizes.find((function(t,e){return e===g}))||void 0)}},e.prototype.displacement=function(t,e){return"horizontal"===this._defaultConfig.mode?e:t},e.prototype.displacementWidthOrHeight=function(){var t=this._defaultConfig.mode,e=this.slots.length,i=this._defaultConfig,n=i.colSpacing,r=i.rowSpacing,o=this.prizeArea||this.drawBlocks();o.x,o.y;var a,s,c=o.w,h=o.h,l=0,u=0;return"horizontal"===t?(u=this.cellHeight=(h-r*(e-1))/e,l=this.cellWidth=u):(l=this.cellWidth=(c-n*(e-1))/e,u=this.cellHeight=l),a=this.widthAndSpacing=this.cellWidth+n,s=this.heightAndSpacing=this.cellHeight+r,this.cellAndSpacing="horizontal"===t?a:s,{cellWidth:l,cellHeight:u,widthAndSpacing:a,heightAndSpacing:s}},e}(k);t.LuckyGrid=E,t.LuckyWheel=$,t.SlotMachine=A,t.cutRound=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;return i.width=r,i.height=o,O(n,0,0,r,o,e),n.clip(),n.drawImage(t,0,0,r,o),i},t.opacity=function(t,e){var i=document.createElement("canvas"),n=i.getContext("2d"),r=t.width,o=t.height;if(i.width=r,i.height=o,"string"==typeof n.filter)n.filter="opacity(".concat(100*e,"%)"),n.drawImage(t,0,0,r,o);else{n.drawImage(t,0,0,r,o);for(var a=n.getImageData(0,0,r,o),s=a.data,c=s.length,h=0;h<c;h+=4){var l=s[h+3];0!==l&&(s[h+3]=l*e)}n.putImageData(a,0,0)}return i},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "lucky-canvas", | ||
"version": "1.7.18", | ||
"version": "1.7.19", | ||
"description": "一个基于原生 js 的(大转盘 / 九宫格 / 老虎机)抽奖插件", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"unpkg": "dist/index.umd.js", | ||
"jsdelivr": "dist/index.umd.js", | ||
@@ -8,0 +9,0 @@ "types": "types/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
670471