-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathomg.min.js
5 lines (5 loc) · 33.7 KB
/
omg.min.js
1
2
3
4
5
/*!
* omg.js v4.0.1
* Author: PengJiyuan
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.omg=t()}(this,function(){"use strict";!function(){for(var e=["ms","moz","webkit","o"],s=0,t=0;t<e.length&&!window.requestAnimationFrame;++t)window.requestAnimationFrame=window[e[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[t]+"CancelAnimationFrame"]||window[e[t]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e){var t=(new Date).getTime(),i=Math.max(0,16-(t-s)),n=window.setTimeout(function(){e(t+i)},i);return s=t+i,n}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)}),"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var i=Object(e),n=1;n<arguments.length;n++){var s=arguments[n];if(null!=s)for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(i[a]=s[a])}return i},writable:!0,configurable:!0})}();var n="4.0.1";function s(e,t,i){var n=e||window.event,s=(t||n.target).getBoundingClientRect(),a=void 0,o=void 0,r=i?n.changedTouches:n.touches;return h()?(a=r[0].clientX-s.left,o=r[0].clientY-s.top):(a=n.offsetX||n.clientX,o=n.offsetY||n.clientY),{x:a,y:o}}function f(e,t,i){return window.addEventListener?e.addEventListener(t,i,!1):e.attachEvent&&e.attachEvent("on"+t,i),e}function v(e,t,i){window.removeEventListener?e.removeEventListener(t,i,!1):window.detachEvent&&e.detachEvent&&e.detachEvent(t,i)}function a(e){for(var t=[e.length,[]],i=t[0],n=t[1],s=0;s<i;s++)n[s]=e[i-s-1];return n}function c(e){return Math.max.apply(null,e)}function l(e){return Math.min.apply(null,e)}function o(e,t,i,n){var s=[t,i].concat(n);Array.prototype.splice.apply(e,s)}function u(e){return!("[object Array]"!==Object.prototype.toString.call(e))}function d(e){return!("[object Object]"!==Object.prototype.toString.call(e))}function h(){return/(iphone|ipad|ipod|ios|android|mobile|blackberry|iemobile|mqqbrowser|juc|fennec|wosbrowser|browserng|Webos|symbian|windows phone)/i.test(navigator.userAgent)}var r=Object.freeze({getPos:s,bind:f,unbind:v,reverse:a,formatFloat:function(e){var t=Math.pow(10,10);return parseInt(e*t,10)/t},getMax:c,getMin:l,insertArray:o,isArr:u,isObj:d,isMobile:h}),g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m=(function(){function c(e){this.value=e}function e(s){var a,o;function r(e,t){try{var i=s[e](t),n=i.value;n instanceof c?Promise.resolve(n.value).then(function(e){r("next",e)},function(e){r("throw",e)}):h(i.done?"return":"normal",i.value)}catch(e){h("throw",e)}}function h(e,t){switch(e){case"return":a.resolve({value:t,done:!0});break;case"throw":a.reject(t);break;default:a.resolve({value:t,done:!1})}(a=a.next)?r(a.key,a.arg):o=null}this._invoke=function(n,s){return new Promise(function(e,t){var i={key:n,arg:s,resolve:e,reject:t,next:null};o?o=o.next=i:(a=o=i,r(n,s))})},"function"!=typeof s.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(e){return this._invoke("next",e)},e.prototype.throw=function(e){return this._invoke("throw",e)},e.prototype.return=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),b=function(){function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),e}}(),p=function(){function i(e){var t=this;m(this,i),this.mouseWheel=function(e){e.preventDefault(),e.deltaY&&0<e.deltaY?t._.scale=t._.scale-.01>=t._.minDeviceScale?t._.scale-.01:t._.minDeviceScale:e.deltaY&&e.deltaY<0&&(t._.scale=t._.scale+.01<=t._.maxDeviceScale?t._.scale+.01:t._.maxDeviceScale),t._.redraw()},this._=e,this.triggeredMouseDown=!1,this.triggeredMouseMove=!1}return b(i,[{key:"getPos",value:function(e){return s(e,this._.element)}},{key:"triggerEvents",value:function(){var t=this;if(this._.objects.filter(function(e){return!e.hide}).some(function(e){return e.events&&u(e.events)||e.enableDrag})||this._.enableGlobalTranslate||this._.enableGlobalScale){var e=this._.objects.some(function(e){return e.events&&e.events.some(function(e){return~t._.eventTypes.indexOf(e.eventType)})})||this._.globalMousemove;e&&!this.triggeredMouseMove&&(this.bindMouseMove(),this.triggeredMouseMove=!0),!e&&this.triggeredMouseMove&&(this.unBindMouseMove(),this.triggeredMouseMove=!1),this.triggeredMouseDown||(f(this._.element,"mousedown",this.mouseDown.bind(this)),this.triggeredMouseDown=!0),this._.enableGlobalScale?this.bindMouseWheel():this.unBindMouseWheel()}}},{key:"bindMouseWheel",value:function(){f(this._.element,"wheel",this.mouseWheel)}},{key:"unBindMouseWheel",value:function(){v(this._.element,"wheel",this.mouseWheel)}},{key:"bindMouseMove",value:function(){f(this._.element,"mousemove",this.mouseEnterOrMove.bind(this))}},{key:"unBindMouseMove",value:function(){v(this._.element,"mousemove",this.mouseEnterOrMove.bind(this))}},{key:"mouseEnterOrMove",value:function(e){var t,i=this,n=i.getPos(e).x,s=i.getPos(e).y;i._.globalMousemove&&i._.globalMousemove(e),t=i._.objects.some(function(e){return e.isDragging});var a=i._._objects.filter(function(e){return e.isPointInner(n,s)&&!e.hide});if(t){a&&1<a.length&&a[1].events&&a[1].events.forEach(function(e){"dragin"!==e.eventType||a[1].hasDraggedIn||(a[1].hasDraggedIn=!0,e.callback&&e.callback(a[1]))});i._._objects.some(function(e){return e.hasDraggedIn&&(!e.isPointInner(n,s)||a[1]!==e)&&((t=e).hasDraggedIn&&t.events.forEach(function(e){"dragout"===e.eventType&&e.callback&&e.callback(a[1])}),void(t.hasDraggedIn=!1));var t})}else{i._._objects.some(function(e){return e.hasEnter&&(!e.isPointInner(n,s)||a[0]!==e)&&((t=e).hasEnter&&t.events.forEach(function(e){"mouseleave"===e.eventType&&e.callback&&e.callback(t)}),void(t.hasEnter=!1));var t}),a&&0<a.length&&a[0].events&&a[0].events.forEach(function(e){"mouseenter"!==e.eventType||a[0].hasEnter?"mousemove"===e.eventType&&e.callback&&e.callback(a[0]):(a[0].hasEnter=!0,e.callback&&e.callback(a[0]))})}}},{key:"mouseDown",value:function(e){var a=this,o=void 0,n=void 0,r=void 0,s=void 0,h=void 0;this._.globalMousedown&&this._.globalMousedown(e);var t=this._.objects.filter(function(e){return!e.hide}).some(function(e){return e.enableDrag&&!e.fixed}),i=this.getPos(e).x,c=this.getPos(e).y;a.cacheX=i,a.cacheY=c;var l=this._._objects.filter(function(e){return e.isPointInner(i,c)&&!e.hide});if(l&&0<l.length&&(l[0].enableChangeIndex&&a.changeOrder(l[0]),l[0].events&&l[0].events.some(function(e){return"mousedown"===e.eventType&&e.callback&&e.callback(l[0])})),t){o=a._._objects.filter(function(e){return!e.hide}).filter(function(e){return e.isPointInner(i,c)&&!e.fixed}),n=0<o.length&&o[0].events&&o[0].events.some(function(e){return"drag"===e.eventType&&(s=e.callback),"drag"===e.eventType}),r=0<o.length&&o[0].events&&o[0].events.some(function(e){return"dragend"===e.eventType&&(h=e.callback),"dragend"===e.eventType});var u=function(e){var t=a.getPos(e).x,i=a.getPos(e).y;o[0].moveX=o[0].moveX+t-a.cacheX,o[0].moveY=o[0].moveY+i-a.cacheY,n&&s(l[0]),a._.redraw(),a.cacheX=t,a.cacheY=i,o[0].isDragging=!0};o&&0<o.length&&o[0].enableDrag&&(f(document,"mousemove",u),f(document,"mouseup",function e(t){var i=a.getPos(t).x,n=a.getPos(t).y,s=a._._objects.filter(function(e){return e.isPointInner(i,n)});s&&1<s.length&&s[1].hasDraggedIn&&(s[1].hasDraggedIn=!1,!s[1].events.some(function(e){return"drop"===e.eventType&&e.callback&&e.callback(s[1],s[0])})&&s[1].events.some(function(e){return"dragout"===e.eventType&&e.callback&&e.callback(s[1])}));r&&h(l[0]),v(document,"mousemove",u),v(document,"mouseup",e),o[0].isDragging=!1}))}if(this._.enableGlobalTranslate&&!(o&&0<o.length)){var d=function(e){var t=a.getPos(e).x,i=a.getPos(e).y;a._.transX=a._.transX+t-a.cacheX,a._.transY=a._.transY+i-a.cacheY,a._.redraw(),a.cacheX=t,a.cacheY=i};f(document,"mousemove",d),f(document,"mouseup",function e(){v(document,"mousemove",d),v(document,"mouseup",e)})}}},{key:"changeOrder",value:function(e){var t=this._.objects.indexOf(e),i=this._.objects[t];this._.objects.splice(t,1),this._.objects.push(i),this._._objects=a(this._.objects),this._.redraw()}}]),i}(),y=function(){function t(e){m(this,t),this._=e}return b(t,[{key:"getPos",value:function(e,t){return s(e,this._.element,t)}},{key:"triggerEvents",value:function(){(this._.objects.filter(function(e){return!e.hide}).some(function(e){return e.events&&u(e.events)||e.enableDrag})||this._.enableGlobalTranslate||this._.enableGlobalScale)&&(this.triggeredTouchStart||(f(this._.element,"touchstart",this.touchStart.bind(this)),this.triggeredTouchStart=!0))}},{key:"touchStart",value:function(e){e.preventDefault();var a=this,o=void 0,r=void 0,h=void 0,t=this.getPos(e),i=[t.x,t.y],n=i[0],s=i[1];a.cacheX=n,a.cacheY=s;var c=this._._objects.filter(function(e){return e.isPointInner(n,s)&&!e.hide});if(c&&0<c.length&&(c[0].enableChangeIndex&&a.changeOrder(c[0]),c[0].events&&c[0].events.some(function(e){return"touchstart"===e.eventType&&e.callback&&e.callback(c[0])})),this._.objects.filter(function(e){return!e.hide}).some(function(e){return e.enableDrag&&!e.fixed})){o=a._._objects.filter(function(e){return!e.hide}).filter(function(e){return e.isPointInner(n,s)&&!e.fixed}),r=0<o.length&&o[0].events&&o[0].events.some(function(e){return"drag"===e.eventType&&(h=e.callback),"drag"===e.eventType});var l=function(e){var t=a.getPos(e),i=[t.x,t.y],n=i[0],s=i[1];o[0].moveX=o[0].moveX+n-a.cacheX,o[0].moveY=o[0].moveY+s-a.cacheY,r&&h(c[0]),a._.redraw(),a.cacheX=n,a.cacheY=s,o[0].isDragging=!0};o&&0<o.length&&o[0].enableDrag&&(f(document,"touchmove",l),f(document,"touchend",function e(){o[0].events&&o[0].events.some(function(e){return"touchend"===e.eventType&&e.callback&&e.callback(o[0])}),v(document,"touchmove",l),v(document,"touchend",e),o[0].isDragging=!1}))}}},{key:"changeOrder",value:function(e){var t=this._.objects.indexOf(e),i=this._.objects[t];this._.objects.splice(t,1),this._.objects.push(i),this._._objects=a(this._.objects),this._.redraw()}}]),t}();var _=function(){function e(){m(this,e)}return b(e,[{key:"hexToRGB",value:function(e){var t=[];return 3===(e=e.substr(1)).length&&(e=e.replace(/(.)/g,"$1$1")),e.replace(/../g,function(e){return t.push(parseInt(e,16)),e}),{r:t[0],g:t[1],b:t[2],rgb:"rgb("+t.join(",")+")"}}},{key:"rgbToHSL",value:function(e,t,i){e/=255,t/=255,i/=255;var n=Math.max(e,t,i),s=Math.min(e,t,i),a=0,o=void 0,r=(n+s)/2;if(n==s)a=o=0;else{var h=n-s;switch(o=.5<r?h/(2-n-s):h/(n+s),n){case e:a=(t-i)/h+(t<i?6:0);break;case t:a=(i-e)/h+2;break;case i:a=(e-t)/h+4}a/=6}return{h:a,s:o,l:r,hsl:"hsl("+360*a+", "+100*o+"%, "+100*r+"%)"}}},{key:"lighten",value:function(e,t){var i=void 0,n=void 0,s=void 0;if(e&&t&&/^[0-9]{1,2}%$/.test(t))return this.isRgba(e)?(s=+(n=this.getRgba(e)).a-Number(t.slice(0,-1))/100,"rgba("+n.r+", "+n.g+", "+n.b+", "+s+")"):"hsl("+360*+(i=this.getHsl(e)).h+", "+100*+i.s+"%, "+(100*+i.l+ +t.slice(0,-1))+"%)"}},{key:"darken",value:function(e,t){var i=void 0,n=void 0,s=void 0;if(e&&t&&/^[0-9]{1,2}%$/.test(t))return this.isRgba(e)?(s=+(n=this.getRgba(e)).a+Number(t.slice(0,-1))/100,"rgba("+n.r+", "+n.g+", "+n.b+", "+s+")"):"hsl("+360*+(i=this.getHsl(e)).h+", "+100*+i.s+"%, "+(100*+i.l-+t.slice(0,-1))+"%)"}},{key:"isHex",value:function(e){return!!/^#[a-fA-F0-9]{3}$|#[a-fA-F0-9]{6}$/.test(e)}},{key:"isRgb",value:function(e){return!!/^rgb\((\s*[0-5]{0,3}\s*,?){3}\)$/.test(e)}},{key:"isRgba",value:function(e){return!!/^rgba\((\s*[0-5]{0,3}\s*,?){3}[0-9.\s]*\)$/.test(e)}},{key:"getRgb",value:function(e){var t=void 0,i=void 0,n=void 0,s=void 0;if(this.isHex(e)){var a=[(t=this.hexToRGB(e)).r,t.g,t.b];i=a[0],n=a[1],s=a[2]}else if(this.isRgb(e)){var o=[(t=e.slice(4,-1).split(","))[0],t[1],t[2]];i=o[0],n=o[1],s=o[2]}return{r:i,g:n,b:s}}},{key:"getRgba",value:function(e){var t,i=[(t=e.slice(5,-1).split(","))[0],t[1],t[2],t[3]];return{r:i[0],g:i[1],b:i[2],a:i[3]}}},{key:"getHsl",value:function(e){var t,i,n,s,a,o=[(i=this.getRgb(e)).r,i.g,i.b];n=o[0],s=o[1],a=o[2];var r=[(t=this.rgbToHSL(n,s,a)).h,t.s,t.l];return{h:r[0],s:r[1],l:r[2]}}}]),e}(),w=function(){function e(){m(this,e),this.imageList=[],this.loadNum=0}return b(e,[{key:"ready",value:function(e){var t=this;this.imageList.forEach(function(e){t.loadImg(e)});var i=setInterval(function(){t.loadNum===t.imageList.length&&(clearInterval(i),e&&e())},50)}},{key:"loadImg",value:function(e){var t=this,i=setInterval(function(){!0===e.complete&&(t.loadNum++,clearInterval(i))},50)}},{key:"addImg",value:function(e){var i=this;e.forEach(function(e){var t=new Image;t.src=e,t.id=e,i.imageList.push(t)})}},{key:"getImg",value:function(t){var i=void 0;return this.imageList.forEach(function(e){e.id==t&&(i=e)}),i}}]),e}(),i=function(t){return function(e){return Math.pow(e,t)}},x=function(t){return function(e){return 1-Math.abs(Math.pow(e-1,t))}},e=function(t){return function(e){return e<.5?i(t)(2*e)/2:x(t)(2*e-1)/2+.5}},t=i(2),k=x(2),T=e(2),j=i(3),I=x(3),M=e(3),P=i(4),S=x(4),Y=e(4),O=i(5),X=x(5),D=e(5),E=function(e){var t=7.5625,i=2.75;return e<1/i?t*e*e:e<2/i?t*(e-=1.5/i)*e+.75:e<2.5/i?t*(e-=2.25/i)*e+.9375:t*(e-=2.625/i)*e+.984375},A=function(e){return 1-E(1-e)},C=Object.freeze({linear:function(e){return e},quadIn:t,quadOut:k,quadInOut:T,cubicIn:j,cubicOut:I,cubicInOut:M,quartIn:P,quartOut:S,quartInOut:Y,quintIn:O,quintOut:X,quintInOut:D,sineIn:function(e){return 1+Math.sin(Math.PI/2*e-Math.PI/2)},sineOut:function(e){return Math.sin(Math.PI/2*e)},sineInOut:function(e){return(1+Math.sin(Math.PI*e-Math.PI/2))/2},bounceOut:E,bounceIn:A,bounceInOut:function(e){return e<.5?.5*A(2*e):.5*E(2*e-1)+.5}}),F=function(){function u(e){m(this,u);var t=e.from,i=e.to,n=e.duration,s=e.delay,a=e.easing,o=e.onStart,r=e.onUpdate,h=e.onFinish;for(var c in t)void 0===i[c]&&(i[c]=t[c]);for(var l in i)void 0===t[l]&&(t[l]=i[l]);this.from=t,this.to=i,this.duration=n||500,this.delay=s||0,this.easing=a||"linear",this.onStart=o,this.onUpdate=r,this.onFinish=h,this.startTime=Date.now()+this.delay,this.started=!1,this.finished=!1,this.keys={}}return b(u,[{key:"update",value:function(){if(this.time=Date.now(),!(this.time<this.startTime))if(this.elapsed!==this.duration){for(var e in this.elapsed=this.time-this.startTime,this.elapsed=this.elapsed>this.duration?this.duration:this.elapsed,this.to)this.keys[e]=this.from[e]+(this.to[e]-this.from[e])*C[this.easing](this.elapsed/this.duration);this.started||(this.onStart&&this.onStart(this.keys),this.started=!0),this.onUpdate(this.keys)}else this.finished||(this.finished=!0,this.onFinish&&this.onFinish(this.keys))}}]),u}(),L=function(e,t){var i=window.devicePixelRatio||1,n=null;return e.forEach(function(e){n=e.getContext("2d"),e.style.position=t.position,e.style.width=t.width+"px",e.style.height=t.height+"px",e.width=t.width*i,e.height=t.height*i,n.scale(i,i)}),e},W=function(e,t,i,n,s,a,o){if(0===s)return!1;var r=s,h=0;if(t+r<o&&n+r<o||o<t-r&&o<n-r||e+r<a&&i+r<a||a<e-r&&a<i-r)return!1;if(e===i)return Math.abs(a-e)<=r/2;var c=(h=(t-n)/(e-i))*a-o+(e*n-i*t)/(e-i);return c*c/(h*h+1)<=r/2*r/2},q=function(e,t){var i,n,s,a,o,r,h=this.moveX*this._.scale,c=this.moveY*this._.scale,l=e-h-(this.fixed?0:this._.transX),u=t-c-(this.fixed?0:this._.transY);switch(this.type){case"rectangle":case"group":return i=l,n=u,s=this.scaled_x,a=this.scaled_y,o=this.scaled_width,r=this.scaled_height,s<i&&i<s+o&&a<n&&n<a+r;case"arc":var d=this.scaled_x,f=this.scaled_y,v=Math.PI,g=this.startAngle<0?2*v+v/180*this.startAngle:v/180*this.startAngle,m=this.endAngle<0?2*v+v/180*this.endAngle:v/180*this.endAngle;return function(e,t,i,n,s){var a=Math.PI,o=void 0,r=void 0;if(isNaN(n)||isNaN(s))r=!!(Math.sqrt(e*e+t*t)<=i);else{var h=0;0<=e&&0<=t?h=0===e?a/2:Math.atan(t/e):e<=0&&0<=t?h=0===e?a:a-Math.atan(t/Math.abs(e)):e<=0&&t<=0?h=0===e?a:Math.atan(Math.abs(t)/Math.abs(e))+a:0<=e&&t<=0&&(h=0===e?3*a/2:2*a-Math.atan(Math.abs(t)/e)),o=Math.sqrt(e*e+t*t),r=n<s?!!(n<=h&&h<=s&&o<=i):!!((0<=h&&h<=s||n<=h&&h<=2*a)&&o<=i)}return r}(l-d,u-f,this.scaled_radius,g,m);case"polygon":return function(e,t,i){for(var n=!1,s=0,a=i.length-1;s<i.length;a=s++)i[s][1]>t!=i[a][1]>t&&e<(i[a][0]-i[s][0])*(t-i[s][1])/(i[a][1]-i[s][1])+i[s][0]&&(n=!n);return n}(l,u,this.scaled_matrix);case"line":for(var b=this.scaled_matrix,p=b.length,y=0;y<p;y++)if(0<y&&W(b[y-1][0],b[y-1][1],b[y][0],b[y][1],this.scaled_lineWidth,l,u))return!0;return!1}};var z=function(){function i(e,t){m(this,i),this._=t,this.enableDrag=!1,this.enableChangeIndex=!1,this.fixed=!1,this.cliping=!1,this.zindex=0,this.commonData={color:e.color,x:e.x,scaled_x:e.x*t.scale,y:e.y,scaled_y:e.y*t.scale,width:e.width,scaled_width:e.width*t.scale,height:e.height,scaled_height:e.height*t.scale,moveX:0,scaled_moveX:0,moveY:0,scaled_moveY:0,boundingWidth:0,boundingHeight:0,zindex:0}}return b(i,[{key:"on",value:function(e,t){if(!e)throw"no eventTypes defined!";if(!t||"function"!=typeof t)throw"you need defined a callback!";this.events=this.events||[];var i=this._.eventTypes.concat(this._.mobileEventTypes),n=e.split(" "),s=this;return n.forEach(function(e){if(!~i.indexOf(e))throw e+" is not in eventTypes!\n Please use event in "+i;s.events.push({eventType:e,callback:t})}),this}},{key:"isPointInner",value:function(e,t){return q.bind(this)(e,t)}},{key:"config",value:function(e){return d(e)&&(this.enableDrag=e.drag||this.enableDrag,this.enableChangeIndex=e.changeIndex||this.enableChangeIndex,this.fixed=e.fixed||this.fixed,this.cliping=e.cliping||this.cliping,this.zindex=e.zindex||this.zindex),this}},{key:"animateTo",value:function(e){var i=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};this.animating=!0;var t={},s=e,a={};for(var o in s)a[o]=this[o];for(var r in t.from=a,t.to=s,t.onUpdate=function(e){for(var t in s)i[t]=e[t];n.onUpdate&&n.onUpdate(e)},n)"onUpdate"!==r&&(t[r]=n[r]);t.onFinish=function(){i.animating=!1,n.onFinish&&n.onFinish(e)};var h=new F(t);return this._.animationList.push(h),this._.tick(),this}},{key:"drag",value:function(e){this.enableDrag=e}},{key:"changeIndex",value:function(e){this.enableChangeIndex=e}}]),i}();function R(e,t){var i=new z(e,t);return Object.assign({},i.commonData,{isDragging:!1,hasEnter:!1,hasDraggedIn:!1,on:i.on,animateTo:i.animateTo,isPointInner:i.isPointInner,config:i.config,_:i._,isShape:!0,parent:null,hide:e.hide,animating:!1,forceUpdate:!1,updated:!1,getBounding:function(){return e=this.scaled_matrix,t=this.scaled_lineWidth,i=t||0,n=e.map(function(e){return e[0]}),s=e.map(function(e){return e[1]}),a=l(n)-i,o=c(n)+i,r=l(s)-i,h=c(s)+i,{lt:[a,r],rt:[o,r],rb:[o,h],lb:[a,h],w:o-a,h:h-r};var e,t,i,n,s,a,o,r,h}})}var G=Math.PI,B=Math.cos,H=Math.sin,N=Math.abs,U=function(e,t){var s=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[0,0],t=arguments[1],i=e[0],n=e[1],s=-G/180*t;return[[B(s),-H(s),(1-B(s))*i+n*H(s)],[H(s),B(s),(1-B(s))*n-i*H(s)],[0,0,1]]}(e,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0),a=[];return t.forEach(function(e){var t=[e[0],e[1],1],i=s[0][0]*t[0]+s[0][1]*t[1]+s[0][2]*t[2],n=s[1][0]*t[0]+s[1][1]*t[1]+s[1][2]*t[2];a.push([N(i)<1e-7?0:i,N(n)<1e-7?0:n])}),a},$=function(t){for(var i=this,e=arguments.length,n=Array(1<e?e-1:0),s=1;s<e;s++)n[s-1]=arguments[s];n.forEach(function(e){"matrix"===e?i.scaled_matrix=i.matrix.map(function(e){return e.map(function(e){return e*t})}):i["scaled_"+e]=i[e]*t})},J=function(e,t,i,n,s){this.matrix=[[e,t],[e+i,t],[e+i,t+n],[e,t+n]],this.origin=[e+.5*i,t+.5*n],this.scaled_matrix=U(this.origin,this.matrix,s)},V="#555",K={tl:0,tr:0,bl:0,br:0};function Q(e,t,i){if(e.cliping){var n=e.getBounding();e.cliping.column?t.rect(n.lt[0],n.lt[1],n.rt[0]-n.lt[0],e.boundingHeight*i):t.rect(n.lt[0],n.lt[1],e.boundingWidth*i,n.rb[1]-n.rt[1]),t.clip()}}var Z={arc:function(e,i){return Object.assign({},R(e,i),{type:"arc",draw:function(){var e=i.canvas,t=i.scale;this.fixed||$.call(this,t,"x","y","width","height","moveX","moveY","radius"),e.save(),this.fixed&&e.translate(-i.transX,-i.transY),e.translate(this.scaled_moveX,this.scaled_moveY),e.translate(this.scaled_x,this.scaled_y),this.hide||(e.beginPath(),isNaN(this.startAngle)||isNaN(this.endAngle)?e.arc(0,0,this.scaled_radius,0,2*Math.PI):(e.arc(0,0,this.scaled_radius,Math.PI/180*this.startAngle,Math.PI/180*this.endAngle,!1),e.save(),e.rotate(Math.PI/180*this.endAngle),e.moveTo(this.scaled_radius,0),e.lineTo(0,0),e.restore(),e.rotate(Math.PI/180*this.startAngle),e.lineTo(this.scaled_radius,0)),"fill"===this.style?(e.fillStyle=this.color,e.fill()):(e.strokeStyle=this.color,e.stroke()),e.closePath()),e.restore()},style:e.style,startAngle:e.startAngle,endAngle:e.endAngle,radius:e.radius,scaled_radius:e.radius*i.scale})},image:function(n,s){n.src&&!~s.images.indexOf(n.src)&&s.images.push(n.src);return Object.assign({},R(n,s),{type:"rectangle",draw:function(){var e=s.canvas,t=n.src,i=s.scale;this.fixed||$.call(this,i,"x","y","width","height","moveX","moveY"),e.save(),e.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&e.translate(-s.transX,-s.transY);try{this.hide||(this.sliceWidth&&this.sliceHeight?e.drawImage(s.loader.getImg(t),this.sliceX,this.sliceY,this.sliceWidth,this.sliceHeight,this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height):e.drawImage(s.loader.getImg(t),this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height))}catch(e){throw new Error("The picture is not loaded successfully, please check the picture url : "+t)}e.restore()},sliceWidth:n.sliceWidth,sliceHeight:n.sliceHeight,sliceX:n.sliceX,sliceY:n.sliceY})},line:function(c,l){return Object.assign({},R(c,l),{type:"line",draw:function(){var i=l.canvas,e=c.lineCap,t=c.lineJoin,n=c.smooth,s=l.scale;if(this.matrix&&this.matrix.length<2)throw"The line needs at least two points";this.fixed||$.call(this,s,"moveX","moveY","matrix","lineWidth");var a=this.scaled_matrix;if(i.save(),i.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&i.translate(-l.transX,-l.transY),Q(this,i,s),!this.hide){if(i.beginPath(),i.lineWidth=this.scaled_lineWidth,i.strokeStyle=this.color,i.lineDashOffset=this.offset,this.dash&&u(this.dash)&&i.setLineDash(this.dash),e&&(i.lineCap=e),t&&(i.lineJoin=t),n)for(var o=function(e,t,i,n){var s=void 0,a=void 0,o=void 0,r=void 0;if(i&&n||(n=i=.25),t<1?(s=e[0][0]+(e[1][0]-e[0][0])*i,a=e[0][1]+(e[1][1]-e[0][1])*i):(s=e[t][0]+(e[t+1][0]-e[t-1][0])*i,a=e[t][1]+(e[t+1][1]-e[t-1][1])*i),t>e.length-3){var h=e.length-1;o=e[h][0]-(e[h][0]-e[h-1][0])*n,r=e[h][1]-(e[h][1]-e[h-1][1])*n}else o=e[t+1][0]-(e[t+2][0]-e[t][0])*n,r=e[t+1][1]-(e[t+2][1]-e[t][1])*n;return{pA:{x:s,y:a},pB:{x:o,y:r}}},r=0;r<a.length;r++)if(0===r)i.moveTo(a[r][0],a[r][1]);else{var h=o(a,r-1);i.bezierCurveTo(h.pA.x,h.pA.y,h.pB.x,h.pB.y,a[r].x,a[r].y)}else a.forEach(function(e,t){0===t?i.moveTo(e[0],e[1]):i.lineTo(e[0],e[1])});i.stroke(),i.closePath()}i.restore()},totalLength:void 0,lineWidth:c.lineWidth||1,dash:c.dash,offset:c.offset||0,color:c.color||V,matrix:c.matrix,scaled_matrix:c.matrix})},rectangle:function(e,s){return Object.assign({},R(e,s),{type:"polygon",draw:function(){var e=s.canvas,t=s.scale;if(this.fixed||$.call(this,t,"x","y","width","height","moveX","moveY"),J.call(this,this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height,this.rotate),e.save(),e.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&e.translate(-s.transX,-s.transY),Q(this,e,t),!this.hide){e.beginPath();var i=this.scaled_matrix,n=this.radius;e.moveTo(i[0][0]+n.tl*t,i[0][1]),e.lineTo(i[1][0]-n.tr*t,i[0][1]),e.quadraticCurveTo(i[1][0],i[0][1],i[1][0],i[0][1]+n.tr*t),e.lineTo(i[1][0],i[2][1]-n.br*t),e.quadraticCurveTo(i[1][0],i[2][1],i[1][0]-n.br*t,i[2][1]),e.lineTo(i[0][0]+n.bl*t,i[2][1]),e.quadraticCurveTo(i[0][0],i[2][1],i[0][0],i[2][1]-n.bl*t),e.lineTo(i[0][0],i[0][1]+n.tl*t),e.quadraticCurveTo(i[0][0],i[0][1],i[0][0]+n.tl*t,i[0][1]),"stroke"!==this.style?(e.fillStyle=this.color||V,e.fill()):(e.strokeStyle=this.color||V,e.lineWidth=this.lineWidth,e.stroke()),e.closePath()}e.restore()},rotate:e.radius?0:e.rotate,radius:e.radius||K})},text:function(h,c){h.background&&h.background.img&&!~c.images.indexOf(h.background.img)&&c.images.push(h.background.img);return Object.assign({},R(h,c),{type:"rectangle",draw:function(){var e=c.canvas,t=c.scale,i=h.center,n=h.fontFamily||"arial,sans-serif",s=h.fontSize||14,a="normal "+(h.fontWeight||400)+" "+s*t+"px "+n;this.fixed||$.call(this,t,"x","y","width","height","moveX","moveY","paddingTop","paddingLeft");var o=void 0,r=void 0;e.save(),e.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&e.translate(-c.transX,-c.transY),this.hide||(this.background&&(this.background.color?(e.save(),e.fillStyle=this.background.color,e.fillRect(this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height),e.restore()):this.background.img&&e.drawImage(c.loader.getImg(this.background.img),this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height)),e.font=a,e.textBaseline="top",o=e.measureText(this.text).width,r=function(e,t,i){var n=e.measureText(t).width,s=e.measureText("...").width;if(n<=i||n<=s)return t;for(var a=t.length;i-s<=n&&0<a--;)t=t.substring(0,a),n=e.measureText(t).width;return t+"..."}(e,this.text,this.scaled_width-8),"stroke"===this.style?(e.strokeStyle=this.color,i?o<this.scaled_width-8&&e.strokeText(r,this.scaled_x+this.scaled_paddingLeft+(this.scaled_width-o-8)/2,this.scaled_y+this.scaled_paddingTop):e.strokeText(r,this.scaled_x+this.scaled_paddingLeft,this.scaled_y+this.scaled_paddingTop)):(e.fillStyle=this.color,i?o<this.scaled_width-8&&e.fillText(r,this.scaled_x+this.scaled_paddingLeft+(this.scaled_width-o-8)/2,this.scaled_y+this.scaled_paddingTop):e.fillText(r,this.scaled_x+this.scaled_paddingLeft,this.scaled_y+this.scaled_paddingTop))),e.restore()},color:h.color||V,background:h.background,text:h.text||"no text",style:h.style||"fill",paddingTop:h.paddingTop||0,paddingLeft:h.paddingLeft||0,scaled_paddingTop:(h.paddingTop||0)*c.scale,scaled_paddingLeft:(h.paddingLeft||0)*c.scale})},polygon:function(e,n){return Object.assign({},R(e,n),{type:"polygon",draw:function(){var i=n.canvas,e=n.scale;this.fixed||$.call(this,e,"moveX","moveY","matrix","lineWidth");var t=this.scaled_matrix;i.save(),i.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&i.translate(-n.transX,-n.transY),this.hide||(i.beginPath(),Q(this,i,e),i.closePath(),i.beginPath(),t.forEach(function(e,t){0===t?i.moveTo(e[0],e[1]):i.lineTo(e[0],e[1])}),i.lineTo(t[0][0],t[0][1]),"fill"===this.style?(i.fillStyle=this.color,i.fill()):(i.strokeStyle=this.color,i.lineWidth=this.scaled_lineWidth,i.stroke()),i.closePath()),i.restore()},style:e.style||"fill",color:e.color||V,lineWidth:e.lineWidth||1,matrix:e.matrix,scaled_matrix:e.matrix})}},ee=Object.freeze({display:R,DefineScale:$,DefineMatrix:J}),te=function(){function i(e){var t;m(this,i),this.version=n,this.isMobile=h(),this.objects=[],this.groupRecords=0,this.transX=0,this.transY=0,this.deviceScale=e.deviceScale||1,this.minDeviceScale=e.minDeviceScale||.5*this.deviceScale,this.maxDeviceScale=e.maxDeviceScale||4*this.deviceScale,this.scale=this.deviceScale,this.loader=new w,this.prepareImage=e.prepareImage,this.globalMousedown=void 0,this.globalMousemove=void 0,this.Tween=F,this.animationList=[],this.animationId=0,this.animating=!1,this.cacheIdPool={},this.fpsFunc=void 0,this.fps=0,this.fpsCacheTime=0,this.graphs={},this.eventTypes=["click","mousedown","mouseup","mouseenter","mouseleave","mousemove","drag","dragend","dragin","dragout","drop"],this.mobileEventTypes=["touchstart","touchend","touchmove","tap","pinch","spread","drag","dragend","dragin","dragout","drop"],this._event=(t=this).isMobile?new y(t):new p(t),this.color=new _,this.element=e.element,this.canvas=this.element.getContext("2d"),this.width=e.width,this.height=e.height,L([this.element],{width:this.width,height:this.height,position:e.position||"relative"}),this.ext=ee,this.clip=Q,this.enableGlobalTranslate=e.enableGlobalTranslate||!1,this.enableGlobalScale=e.enableGlobalScale||!1,this.images=e.images||[],this.utils=r,this.shapes=Z}return b(i,[{key:"init",value:function(){var i=this,e=function(t){i.graphs[t]=function(e){return i.shapes[t](e,i)}};for(var t in this.shapes)e(t);this.group=function(e){return t=e,l=this,Object.assign({},R(t,l),{type:"group",draw:function(){var e=l.canvas,t=l.scale;$.call(this,t,"x","y","width","height","moveX","moveY"),J.call(this,this.scaled_x,this.scaled_y,this.scaled_width,this.scaled_height),e.save(),e.translate(this.scaled_moveX,this.scaled_moveY),this.fixed&&e.translate(-l.transX,-l.transY),e.beginPath();var i=this.scaled_matrix,n=this.radius;if(e.moveTo(i[0][0]+n.tl*t,i[0][1]),e.lineTo(i[1][0]-n.tr*t,i[0][1]),e.quadraticCurveTo(i[1][0],i[0][1],i[1][0],i[0][1]+n.tr*t),e.lineTo(i[1][0],i[2][1]-n.br*t),e.quadraticCurveTo(i[1][0],i[2][1],i[1][0]-n.br*t,i[2][1]),e.lineTo(i[0][0]+n.bl*t,i[2][1]),e.quadraticCurveTo(i[0][0],i[2][1],i[0][0],i[2][1]-n.bl*t),e.lineTo(i[0][0],i[0][1]+n.tl*t),e.quadraticCurveTo(i[0][0],i[0][1],i[0][0]+n.tl*t,i[0][1]),d(this.background)){var s=this.background;s.color&&(e.fillStyle=s.color||V,e.fill())}else if(d(this.border)){var a=this.border;e.strokeStyle=a.color||V,e.lineWidth=a.lineWidth||1,e.stroke()}e.closePath();var o=this.title;if(o&&"object"===(void 0===o?"undefined":g(o))){var r=o.fontSize||14,h=o.paddingTop||4,c=o.paddingLeft||2;e.fillStyle=o.color||"#000",e.textBaseline="top",e.font="normal 400 "+r*t+"px "+(o.fontFamily||"arial,sans-serif"),e.fillText(o.text,this.scaled_x+c*t,this.scaled_y+h*t)}e.restore()},background:t.background,border:t.border,radius:t.radius||K,title:t.title,children:[],add:function(e){var i=this;if(!u(e))throw"The parameter must be an array";if(!~this._.objects.indexOf(this))throw"before add, please addChild the parent!";e.forEach(function(e){var t;e.isShape&&((e.parent=i)._.groupRecords+=1e-10,e.zindex=i.zindex+i._.groupRecords,(t=e).updated&&!t.forceUpdate||(t.updated=!0,t.moveX=t.parent.x+t.parent.moveX,t.moveY=t.parent.y+t.parent.moveY,t.enableChangeIndex=!1,t.fixed=!1,t.drag=!1),i.enableDrag=!1,i.children.push(e))}),o(this._.objects,this._.objects.indexOf(this)+1,0,e),this._.objects.sort(function(e,t){return e.zindex-t.zindex}),this._._objects=a(this._.objects)},remove:function(e){var i=this,t=e;"function"==typeof e?t=this.children.filter(e):u(e)||(t=[e]),t.forEach(function(t){var e=i.children.indexOf(t);~e&&(t.parent=null,i.children.splice(e,1),i._.objects=i._.objects.filter(function(e){return e!==t}),i._._objects=a(i._.objects))})},updateAllChildsPosition:function(){this.children.forEach(function(e){e.moveX=e.parent.x+e.parent.moveX,e.moveY=e.parent.y+e.parent.moveY})}});var t,l}}},{key:"reset",value:function(){this.transX=0,this.transY=0,this.scale=this.deviceScale,this.objects.filter(function(e){return!e.parent}).forEach(function(e){e.moveX=0,e.moveY=0}),this.objects.filter(function(e){return"group"===e.type}).forEach(function(e){e.updateAllChildsPosition()}),this._objects=a(this.objects),this.redraw()}},{key:"extend",value:function(e){for(var t in e)this.shapes[t]=e[t]}},{key:"setGlobalProps",value:function(e){for(var t in e)switch(t){case"enableGlobalTranslate":this.enableGlobalTranslate=e[t];break;case"enableGlobalScale":this.enableGlobalScale=e[t]}this._event.triggerEvents()}},{key:"addChild",value:function(e){u(e)?this.objects=this.objects.concat(e):d(e)&&this.objects.push(e),this.objects.sort(function(e,t){return e.zindex-t.zindex}),this._objects=a(this.objects)}},{key:"removeChild",value:function(t){u(t)?this.objects=this.objects.filter(function(e){return!~t.indexOf(e)}):this.objects=this.objects.filter(function(e){return e!==t}),this._objects=a(this.objects)}},{key:"removeFirstChild",value:function(){this.objects.pop(),this._objects=a(this.objects)}},{key:"removeLastChild",value:function(){this.objects.shift(),this._objects=a(this.objects)}},{key:"removeAllChilds",value:function(){this.objects=[],this._objects=[]}},{key:"imgReady",value:function(){this.loader.addImg(this.images)}},{key:"show",value:function(){var e=this,t=this;this.prepareImage?(this.imgReady(),this.loader.ready(function(){"function"==typeof e.prepareImage&&e.prepareImage(),t.draw(),t._event.triggerEvents()})):(this.draw(),this._event.triggerEvents())}},{key:"draw",value:function(){this.objects.forEach(function(e){e.draw()})}},{key:"redraw",value:function(){this.clear(),this.canvas.save(),this.canvas.translate(this.transX,this.transY),this.draw(),this.canvas.restore()}},{key:"clear",value:function(){this.canvas.clearRect(0,0,this.width,this.height)}},{key:"tick",value:function(){var i=this;return 0<this.animationList.length&&!this.animating&&(this.animating=!0,this.animationId=Date.now(),function e(){if(i.fpsFunc){var t=Date.now();1e3<=t-i.fpsCacheTime?(i.fpsFunc&&i.fpsFunc(i.fps),i.fps=0,i.fpsCacheTime=t):i.fps++}i.animationList.forEach(function(e,t){e.finished?i.animationList.splice(t--,1):e.update?e.update():e()}),i.redraw(),0===i.animationList.length&&i.animating?(i.animating=!1,i.finishAnimation(),cancelAnimationFrame(i.cacheIdPool[i.animationId])):i.cacheIdPool[i.animationId]=requestAnimationFrame(e)}()),this.animationId}},{key:"finishAnimation",value:function(){}},{key:"fpsOn",value:function(e){this.fpsFunc=e,this.fpsCacheTime=Date.now()}},{key:"fpsOff",value:function(){this.fpsFunc=void 0,this.fps=0}},{key:"animate",value:function(e){this._event.triggerEvents(),this.animationList.push(e),this.tick()}},{key:"clearAnimation",value:function(){this.animationList=[],this.animating=!1,cancelAnimationFrame(this.cacheIdPool[this.animationId])}},{key:"getVersion",value:function(){return this.version}},{key:"mousedown",value:function(e){this.globalMousedown=e}},{key:"mousemove",value:function(e){this.globalMousemove=e}},{key:"resize",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(e){var t=this,i=function(){t.width=e.width(),t.height=e.height(),L([t.element],{width:t.width,height:t.height,position:"absolute"}),t.redraw()};window.onresize||f(window,"resize",function(){e.resize?e.resize(i):i()})})}]),i}();return function(e){return new te(e)}});