You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
8.3 KiB
1 lines
8.3 KiB
!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).lime={})}(this,(function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var i=0;e.length>i;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);e>i;i++)n[i]=t[i];return n}function a(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return r(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?r(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,a=function(){};return{s:a,n:function(){return t.length>n?{done:!1,value:t[n++]}:{done:!0}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,h=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return s=t.done,t},e:function(t){h=!0,o=t},f:function(){try{s||null==i.return||i.return()}finally{if(h)throw o}}}}var o=function(t){return/^#.{3,6}$/.test(t)?4===t.length?t.substring(1).split("").map((function(t){return 17*parseInt(t,16)})):[t.substring(1,3),t.substring(3,5),t.substring(5,7)].map((function(t){return parseInt(t,16)})):(console.error("lime-circle: 渐变仅支持hex值"),[0,0,0])},s=function(t){return 1===t.length?"0"+t:t},h=function(t,e,i){var n,r,a,h,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,c=[],l=[],d=function(t){return Math.pow(t/255,u)};for(t=o(t).map(d),e=o(e).map(d),n=0;i>n;n++){for(h=1-(a=n/(i-1)),r=0;3>r;r++)l[r]=s(Math.round(255*Math.pow(t[r]*h+e[r]*a,1/u)).toString(16));c.push("#"+l.join(""))}return c};var u=function(t,e,i,n){var r=1e-6,a=3*t-3*i+1,o=3*i-6*t,s=3*t,h=3*e-3*n+1,u=3*n-6*e,c=3*e;function l(t){return((a*t+o)*t+s)*t}return function(t){return e=function(t){for(var e,i,n,h=t,u=0;8>u;u++){if(i=l(h)-t,r>Math.abs(i))return h;if(r>Math.abs(e=(3*a*(n=h)+2*o)*n+s))break;h-=i/e}var c=1,d=0;for(h=t;c>d;){if(i=l(h)-t,r>Math.abs(i))return h;i>0?c=h:d=h,h=(c+d)/2}return h}(t),((h*e+u)*e+c)*e;var e}}(.25,.1,.25,1),c=Symbol("tick"),l=Symbol("tick-handler"),d=Symbol("animations"),f=Symbol("start-times"),v=Symbol("pause-start"),m=Symbol("pause-time"),g="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:function(t){return setTimeout(t,1e3/60)},y="undefined"!=typeof cancelAnimationFrame?cancelAnimationFrame:function(t){clearTimeout(t)},p=function(){function t(){e(this,t),this.state=void 0,this.state="Initiated",this[d]=new Set,this[f]=new Map}return n(t,[{key:"start",value:function(){var t=this;if("Initiated"===this.state){this.state="Started";var e=Date.now();this[m]=0,this[c]=function(){var i,n=Date.now(),r=a(t[d]);try{for(r.s();!(i=r.n()).done;){var o=i.value,s=void 0;(s=t[f].get(o)<e?n-e-o.delay-t[m]:n-t[f].get(o)-o.delay-t[m])>o.duration&&(t[d].delete(o),s=o.duration),s>0&&o.run(s)}}catch(t){r.e(t)}finally{r.f()}t[l]=g(t[c])},this[c]()}}},{key:"pause",value:function(){"Started"===this.state&&(this.state="Paused",this[v]=Date.now(),y(this[l]))}},{key:"resume",value:function(){"Paused"===this.state&&(this.state="Started",this[m]+=Date.now()-this[v],this[c]())}},{key:"reset",value:function(){this.pause(),this.state="Initiated",this[m]=0,this[v]=0,this[d]=new Set,this[f]=new Map,this[l]=null}},{key:"add",value:function(t,e){2>arguments.length&&(e=Date.now()),this[d].add(t),this[f].set(t,e)}}]),t}(),w=function(){function t(i,n,r,a,o,s){e(this,t),this.startValue=void 0,this.endValue=void 0,this.duration=void 0,this.timingFunction=void 0,this.delay=void 0,this.template=void 0,o=o||function(t){return t},s=s||function(t){return t},this.startValue=i,this.endValue=n,this.duration=r,this.timingFunction=o,this.delay=a,this.template=s}return n(t,[{key:"run",value:function(t){var e=this.endValue-this.startValue,i=this.timingFunction(t/this.duration);this.template(this.startValue+e*i)}}]),t}(),b=Math.PI/180,k=function(){function t(i,n){e(this,t),this.canvas=void 0,this.context=void 0,this.current=0,this.size=0,this.pixelRatio=1,this._isConicGradient=!1,this._attrs={percent:0,size:"120px",lineCap:"round",strokeWidth:6,strokeColor:"#2db7f5",trailWidth:6,trailColor:"#ddd",dashboard:!1,clockwise:!0,duration:300,max:100,beforeAnimate:!0,animate:!0,formatter:"{d}{d}.{d}{d}%",fontSize:"16px",showText:!1},this._timer=void 0,this.startTime=0,this.target=0,this._colors=[],this._gradientColors=[],this._rAF=function(t){},this._cAf=function(t){},this.timeline=void 0,this.run=void 0,this.canvas=i,this.run=n.run,this.size=n.size||120,this.pixelRatio=n.pixelRatio||1,this.init(),this.initRaf(),this.timeline=new p(this._rAF,this._cAf)}return n(t,[{key:"init",value:function(){var t=this.size,e=this.pixelRatio;if(this.canvas){this.canvas.width=t*e,this.canvas.height=t*e;var i=this.canvas.getContext("2d");this._isConicGradient=!!i.createConicGradient,this.context=i}}},{key:"initRaf",value:function(){var t=this.canvas;"undefined"!=typeof window?(this._rAF=window.requestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)},this._cAf=window.cancelAnimationFrame||function(t){window.clearTimeout(t)}):t&&t.requestAnimationFrame?(this._rAF=t.requestAnimationFrame,this._cAf=t.cancelAnimationFrame):(this._rAF=function(t){return setTimeout(t,16.7)},this._cAf=function(t){clearTimeout(t)})}},{key:"setOption",value:function(t){Object.assign(this._attrs,t)}},{key:"set",value:function(t,e){this._attrs[t]=e}},{key:"get",value:function(t){return this._attrs[t]||this.canvas[t]}},{key:"play",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.get("percent");this.target=Math.max(Math.min(e,this.get("max")||100),0),this.createConicGradient(),this.timeline.start(),this.timeline.add(new w(this.current,e,this.get("duration"),0,u,(function(e){t.current=1e-4>e?0:e,t.render(t.current),t.run(t.current)})))}},{key:"createConicGradient",value:function(){if(!this._isConicGradient){var t=this.get("strokeColor");if("string"!=typeof t&&this._colors!==t){this._colors=t,this._gradientColors=[];for(var e=this.getArc(),i=t.length-1,n=Math.floor(e/i),r=0;i>r;r++){e-=n,this._gradientColors=this._gradientColors.concat(h(t[r],t[r+1],r+1===i?n+e:n))}}}}},{key:"render",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=this.context,i=this.size,n=this.pixelRatio,r=this.getSalce(),a=this.getRotate(),o=i/2;e.setTransform(1,0,0,1,0,0),e.clearRect(-o,-o,i,i),e.setTransform(r*n,0,0,n,o*n,o*n),e.rotate(a*b),this.drawTrail(o),this.drawStroke(o,t),e.draw&&e.draw()}},{key:"drawArc",value:function(t,e,i,n,r){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:this.get("lineCap"),o=this.context;o.beginPath(),o.lineCap=a,o.strokeStyle=e,o.lineWidth=i,o.arc(0,0,t,n,r),o.stroke()}},{key:"getArc",value:function(){var t=this.get("arc");return t||(this.get("dashboard")?270:360)}},{key:"getSalce",value:function(){return this.get("clockwise")?1:-1}},{key:"getRotate",value:function(){return this.get("arc")?180:this.get("dashboard")?135:-90}},{key:"drawTrail",value:function(t){var e=t-this.get("trailWidth")/2;this.drawArc(e,this.get("trailColor"),this.get("trailWidth"),0,this.getArc()*b)}},{key:"drawStroke",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e){var i=t-this.get("strokeWidth")/2,n=this.get("strokeColor"),r=this.getArc(),a=Math.round(r/this.get("max")*e);if("string"==typeof n||this._isConicGradient)if("string"!=typeof n&&this._isConicGradient){var o=this.context,s=o.createConicGradient(this.get("dashboard")?45:90,0,0);n.forEach((function(t,e){s.addColorStop(e/(n.length-1),t)})),this.drawArc(i,s,this.get("strokeWidth"),0,a*b)}else this.drawArc(i,n,this.get("strokeWidth"),0,a*b);else for(var h=0;a>h;h++)this.drawArc(i,this._gradientColors[h],this.get("strokeWidth"),h*b,(h+1)*b,this.get("dashboard")||r!=a?this.get("lineCap"):"butt")}}}]),t}();t.Circle=k,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
|