-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathprogress.min.js
2 lines (2 loc) · 7.83 KB
/
progress.min.js
1
2
/*! mp-progress.js v1.2.8 https://www.npmjs.com/package/mp-progress */
var t,e;t=window,e=function(){return i={},o.m=n=[function(t,e,n){"use strict";function i(e,t){var n,i=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)),i}function o(o){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach(function(t){var e,n,i;e=o,i=r[n=t],n in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(r,t))})}return o}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}n.r(e);var s=function(){function u(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u);var e=t.canvasId,n=t.canvasSize,i=void 0===n?{width:0,height:0}:n,o=t.percent,r=void 0===o?100:o,s=t.barStyle,a=void 0===s?{}:s,h=t.needDot,c=void 0!==h&&h,l=t.dotStyle,d=void 0===l?[]:l,p=t.target,f=void 0===p?null:p;if(!e)throw"[初始化失败]: 缺少canvasId";this._percent=r<50?50:100<r?100:r,this._options={canvasId:e,needDot:c,dotStyle:d,canvasSize:i,barStyle:a,target:f},this._barIndex=0,this.isInit=!1}var t,e,n;return t=u,(e=[{key:"draw",value:function(t){var o=this,e=wx.getSystemInfoSync().SDKVersion;this.compareVersion(e,"2.7.0")<0?console.error("请在2.7.0以上的SDK中使用,当前SDK版本:".concat(e)):void 0!==t?(t<0&&(t=0,console.warn("[参数percentagegit<0]: 已自动调整为0")),100<t&&(t=100,console.warn("[参数percentage>100]: 已自动调整为100")),this._options.percentage=+t||0,this._context?this.drawFn():wx.createSelectorQuery().in(this._options.target).select("#".concat(this._options.canvasId)).fields({node:!0,size:!0}).exec(function(t){var e=t[0].node;o._requestAnimationFrame=e.requestAnimationFrame.bind(e);var n=e.getContext("2d"),i=wx.getSystemInfoSync().pixelRatio;e.width=t[0].width*i,e.height=t[0].height*i,n.scale(i,i),o._context=n,o.drawFn()})):console.warn("[绘图过程出现错误]: 调用draw方法必须传入百分比参数")}},{key:"drawFn",value:function(){var n=this;try{var t=this._options.barStyle;if(0<t.length){if(this.isInit)this._positionInfo,100===this._percent?this._context.clearRect(-this._positionInfo.originX,-this._positionInfo.originY,this.convertLength(this._options.canvasSize.width),this.convertLength(this._options.canvasSize.height)):this._context.clearRect(-this._positionInfo.originX,-this.convertLength(this._options.canvasSize.height)/2,this.convertLength(this._options.canvasSize.width),this.convertLength(this._options.canvasSize.height)),this._context.shadowColor="transparent",this._context.shadowBlur=0;else{for(var e=0,i=0;i<t.length;i++){var o=t[i].width;e<o&&(e=o)}var r=0,s=Math.cos(2*Math.PI/360*((100-this._percent)/2/100*360)),r=100===this._percent?((Math.min(this._options.canvasSize.width,this._options.canvasSize.height)-2*e)/2).toFixed(2):(Math.min(this._options.canvasSize.width/2,(this._options.canvasSize.height-2*e)/(1+s))-e).toFixed(2),a=Math.round(this._options.canvasSize.width/2),h=0,h=100===this._percent?Math.round(this._options.canvasSize.height/2):Math.round(this._options.canvasSize.height/(1+s));if(this.isInit=!0,this._options.needDot){if(!(0<this._options.dotStyle.length))return void console.warn("参数dotStyle不完整,请检查");var c,l=this._options.dotStyle[0].r;e<2*l&&(r-=l-e+(c=this._options.dotStyle[0].shadow?l/4:0),100!==this._percent&&(h-=l+c))}this.convertLength(a),this.convertLength(h);var d=100===this._percent?-90:360*((100-this._percent+(this._percent-50)/2)/100).toFixed(2);this._positionInfo={originX:this.convertLength(a),originY:this.convertLength(h)},this._context.translate(this._positionInfo.originX,this._positionInfo.originY),this._context.rotate(d*Math.PI/180),this._r=this.convertLength(r)}this.deg=2*(this._options.percentage/100).toFixed(2)*Math.PI,(t||[]).forEach(function(t,e){t.percent=0,n._barIndex=e,n.drawBar()}),this.hasAnimateBar?console.warn("animate和dotStyle不可同时使用"):this._options.needDot&&this.drawBarCoordinateDot()}else console.warn("参数barStyle不符合要求,请检查")}catch(t){console.warn("[绘图过程出现错误]: ",t)}}},{key:"drawBar",value:function(){var t=this._options.barStyle[this._barIndex],e=this._options.barStyle.length-1===this._barIndex,n=(e?this.deg:2*Math.PI)*this._percent/100,i=n;e&&t.animate&&t.percent<100&&(this.hasAnimateBar=!0,t.percent?t.percent+=2:t.percent=2,i=n*(t.percent/100)),"endAngle: ".concat(i),this._context.beginPath(),this._context.arc(0,0,this._r,0,i),this._context.lineWidth=this.convertLength(t.width),this._context.strokeStyle=this.generateBarFillStyle(t.fillStyle);var o=t.lineCap;o&&(this._context.lineCap=o),this._context.stroke(),e&&t.animate&&t.percent<100&&this._requestAnimationFrame(this.drawBar.bind(this))}},{key:"compareVersion",value:function(t,e){t=t.split("."),e=e.split(".");for(var n=Math.max(t.length,e.length);t.length<n;)t.push("0");for(;e.length<n;)e.push("0");for(var i=0;i<n;i++){var o=parseInt(t[i]),r=parseInt(e[i]);if(r<o)return 1;if(o<r)return-1}return 0}},{key:"generateBarFillStyle",value:function(t){if("string"==typeof t)return t;for(var e=this._context.createLinearGradient(0,0,100,90),n=0;n<t.length;n++){var i=t[n];e.addColorStop(i.position,i.color)}return e}},{key:"convertLength",value:function(t){return+Math.round(wx.getSystemInfoSync().windowWidth*t/750)}},{key:"drawCircleWithFillStyle",value:function(t){this._context.beginPath(),this._context.arc(t.x,t.y,this.convertLength(t.r),0,2*Math.PI),this._context.fillStyle=t.fillStyle||"#ffffff",t.shadow&&(this._context.shadowOffsetX=0,this._context.shadowOffsetY=0,this._context.shadowColor=t.shadow,this._context.shadowBlur=this.convertLength(t.r/2)),this._context.fill()}},{key:"drawBarCoordinateDot",value:function(){var t=360*(this._options.percentage/100*this._percent/100).toFixed(2),e="",n=0,i=0,i=t<=90?(e=2*Math.PI/360*t,n=(Math.cos(e)*this._r).toFixed(2),(Math.sin(e)*this._r).toFixed(2)):90<t&&t<=180?(e=2*Math.PI/360*(180-t),n=-(Math.cos(e)*this._r).toFixed(2),(Math.sin(e)*this._r).toFixed(2)):(n=180<t&&t<=270?(e=2*Math.PI/360*(t-180),-(Math.cos(e)*this._r).toFixed(2)):(e=2*Math.PI/360*(360-t),(Math.cos(e)*this._r).toFixed(2)),-(Math.sin(e)*this._r).toFixed(2));0<this._options.dotStyle.length?this.drawCircleWithFillStyle(o({x:n,y:i},this._options.dotStyle[0])):console.warn("参数dotStyle不完整,请检查"),1<this._options.dotStyle.length&&this.drawCircleWithFillStyle(o({x:n,y:i},this._options.dotStyle[1]))}}])&&r(t.prototype,e),n&&r(t,n),u}();e.default=s}],o.c=i,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)o.d(n,i,function(t){return e[t]}.bind(null,i));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0).default;function o(t){if(i[t])return i[t].exports;var e=i[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,i},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MpProgress=e():t.MpProgress=e();