diff --git a/example/util/wxdraw.min.js b/example/util/wxdraw.min.js index de69431..6d0da1d 100644 --- a/example/util/wxdraw.min.js +++ b/example/util/wxdraw.min.js @@ -1,2 +1,2 @@ -"use strict";function Line(t){var i=_extends({strokeStyle:"#000000",points:[[1,2],[23,45],[2,45],[230,205]]},commonAttr()),n=_extends({smooth:!0},commonUnAttr()),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this.max={maxX:null,maxY:null,minX:null,minY:null},this.massCenter=this.genMassCenter(this.Option.points),this.posPoints=this.genPointsPositiveLoc(),this.oriPoints=this.Option.points,this._Points=this.Option.points,this._CurvePoints=this.Option.points,this.detectPoints=this.getDetectPoints(),this.getMax(),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="line",this._canRotateOrigin=!0}function Watch(){this.startTime=0,this.running=!1,this.goesBytime=0,this.goesBy=void 0,this.DEFAULT_ELASTIC=2}function genExe(t,i,n){if(specialAtrr[i])return specialAtrr[i].getIncre(specialAtrr[i].get(n.Shape.Option[i]),t,n);if(!isNaN(Number(t)))return n.Shape.Option[i]||0===n.Shape.Option[i]?parseFloat(t)-parseFloat(n.Shape.Option[i]):parseFloat(t)-parseFloat(n.Shape[specialOption[n.type][i]][i]);if(0==t.indexOf("+=")){return t.split("=")[1]}if(0==t.indexOf("-=")){return-1*t.split("=")[1]}}function fakeAnimationFrame(t){var i;setTimeout(function(){i=+new Date,t(i)},16)}function WxDraw(t,i,n,s,e){this.canvas=t,this.wcid=guid(),this.store=new Store,this.bus=new eventBus,this.animation=new Animation(this.bus),this.x=i,this.y=n,this.w=s,this.h=e,this.bus.add("addAnimation",this,this.addAnimationFrag),this.bus.add("update",this,this.update),this.bus.add("getDetectedLayers",this,this.getDetectedLayers),this.bus.add("clearDetectedLayers",this,this.clearDetectedLayers),this.bus.add("updateLayer",this,this.updateLayer),this.bus.add("destory",this,this.destroy),this.animation.start(),Shape.bus=this.bus,this.detectedLayers=[]}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,i){for(var n=0;n0&&(this.turnColorLock(!0),i=t.createLinearGradient.apply(t,toConsumableArray(this.getGradientOption(n).lg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),this.UnOption.needGra&&"circle"==this.UnOption.needGra&&this.UnOption.gra&&this.UnOption.gra.length>0&&(this.turnColorLock(!0),i=t.createCircularGradient.apply(t,toConsumableArray(this.getGradientOption(n).cg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),(!this._colorLock||this.needGra&&"no"==his.UnOption.needGra)&&t.setFillStyle(this.Option.fillStyle),"miter"==this.UnOption.lineJoin&&t.setMiterLimit(this.Option.miterLimit),t.setStrokeStyle(this.Option.strokeStyle),t.setLineWidth(this.Option.lineWidth),t.setGlobalAlpha(this.Option.opacity),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this.UnOption.isLineDash&&t.setLineDash&&(this.Option.lineDash instanceof Array||(this.Option.lineDash[0]=objToArray(this.Option.lineDash[0])),t.setLineDash(this.Option.lineDash[0],this.Option.lineDash[1]))},stroke:function(t){return"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.stroke(),void t.restore())},fill:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(t.save(),t.setGlobalAlpha(this.Option.opacity),t.beginPath(),t.setFontSize(this.Option.fontSize),t.setTextAlign(this.UnOption.align),t.setTextBaseline(this.UnOption.textBaseline),t.setFillStyle(this.Option.fillStyle),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this._draw(t),t.closePath(),t.restore(),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!1,this._draw(t),this.setCommonstyle(t),t.fill(),void t.restore())},mixDraw:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.fill(),t.stroke(),void t.restore())},turnColorLock:function(t){this._colorLock=!!t},getGradientOption:function(t){return{circle:"circle"==t?{lg:[this.Option.x-this.Option.r,0,this.Option.x+this.Option.r,0],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},rect:"rect"==t?{lg:[this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2,this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow(this.Option.w/2,2)+Math.pow(this.Option.h/2,2))]}:{},polygon:"polygon"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},cshape:"cshape"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.massCenter.x,this.massCenter.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{},ellipse:"ellipse"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{}}[t]},_drawHelperPoints:function(t){t.save(),t.setFillStyle("#F34739"),t.beginPath(),this._detectPoints?this._detectPoints.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}):this._Points.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}),t.closePath(),t.fill(),t.restore()},closeRotateOrigin:function(){this._canRotateOrigin=!1}},Polygon=function(t){var i=_extends({x:10,y:10,r:10,sides:7},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(this.oriPoints),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="polygon",this._canRotateOrigin=!0};Polygon.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;sthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Ellipse=function(t){var i=_extends({x:10,y:10,a:10,b:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="ellipse",this._canRotateOrigin=!0};Ellipse.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;s<100;++s)t.push([this.Option.x+this.Option.a/2*Math.sin(n),this.Option.y-this.Option.b/2*Math.cos(n)]),i.push([this.Option.x+(this.Option.a/2+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.b+this.Option.lineWidth)/2*Math.cos(n)]),n+=2*Math.PI/100;this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var baseline=function(t,i){return{normal:2,bottom:-i/2,middle:0,top:i/2}[t]},align=function(t,i){return{left:i/2,center:0,right:-i/2}[t]},Text=function(t){t.text||(t.text="no text");var i={x:100,y:200,fontSize:12,shadow:{offsetX:5,offsetY:5,blur:5,color:"#000000"},fillStyle:"#000000",strokeStyle:"#000000",rotate:0,opacity:1},n={textBaseline:"normal",align:"left",needShadow:!1};this.text=t.text,this.Option=util.extend(t,i),this.UnOption=util.extend(t,n),this.boxOption={x:0,y:0},this.boxOriPoints=[],this.boxPoints=[],this.rotateOrigin=null,this.offset={x:0,y:0},this._offsetX=0,this._offsetY=0,this.getOriPoints(),this.getPoints(),this._dirty=!0,this._type="text",this._canRotateOrigin=!0};Text.prototype=_extends({getOriPoints:function(){for(var t=[],i=/^[\u4e00-\u9fa5]/,n=String(this.text).length,s=0,e=this.Option.fontSize,o=0;oi!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.boxOption.x=t,this.boxOption.y=i,this.Option.x=t-this.offset.x,this.Option.y=i-this.offset.y,this._dirty=!0},detected:function(t,i){return this._offsetX=this.boxOption.x-t,this._offsetY=this.boxOption.y-i,!!this._pnpolyTest(t,i)&&(this._isChoosed=!0,!0)},_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints()),t.save(),this.rotateOrigin?(t.translate(this.rotateOrigin[0],this.rotateOrigin[1]),t.rotate(this.Option.rotate),t.fillText(this.text,this.boxOption.x-this.rotateOrigin[0]-this.offset.x,this.boxOption.y-this.rotateOrigin[1]-this.offset.y)):(t.translate(this.boxOption.x,this.boxOption.y),t.rotate(this.Option.rotate),t.fillText(this.text,-this.offset.x,-this.offset.y)),t.restore(),this._dirty=!1},moveDetect:function(t,i){1==this._isChoosed&&this.move(t+this._offsetX,i+this._offsetY)},updateText:function(t){this.text=t,this._dirty=!0}},commonMethods);var getCurvePoints=function(t,i,n,s){i=void 0!==i?i:.5,n=n||!1,s=s||16;var e,o,h,r,a,u,p,c,l,m,f,x,d,O=[],g=[];for(O=t.slice(0),n?(O.unshift(t[t.length-1]),O.unshift(t[t.length-1]),O.push(t[0])):(O.unshift(t[1]),O.push(t[t.length-1])),d=1;dthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Circle=function(t){var i=_extends({x:10,y:10,r:10,sA:0,eA:2*Math.PI},commonAttr()),n=_extends({},commonUnAttr(),{counterclockwise:!1,closePath:!1}),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.fullCircle=!0,this._colorLock=!1,this._canRotateOrigin=!0,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="circle"};Circle.prototype=_extends({getOriPoints:function(){var t=[],i=[],n=this.Option.sA||0,s=this.Option.eA||2*Math.PI,e=s-n;e>=2*Math.PI?this.fullCircle=!0:this.fullCircle=!1;for(var o=0;o<=100;++o)n=this.Option.sA+o*e/100,t.push([this.Option.x+this.Option.r*Math.sin(n),this.Option.y-this.Option.r*Math.cos(n)]),i.push([this.Option.x+(this.Option.r+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.r+this.Option.lineWidth/2)*Math.cos(n)]);t.unshift([this.Option.x,this.Option.y]),i.unshift([this.Option.x,this.Option.y]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this.detectOriPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Rect=function(t){var i=_extends({x:10,y:10,w:10,h:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=util.extend({},n),this.UnOption=s,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.bus=null,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="rect",this._rotateOriginOver=!1,this._canRotateOrigin=!0};Rect.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.createPath(t),this._dirty=!1},getOriPoints:function(){var t=[],i=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._chengeCenter(n),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return console.log("检测方块",t,i),t>this.max.minX&&tthis.max.minY&&ithis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=a>i&&t<(r-o)*(i-h)/(a-h)+o&&(n=!n)}return n}},commonMethods);var Img=function(t){var i={x:10,y:10,w:10,h:10,rotate:0,opacity:1},n={file:""},s=util.extend(t,i),e=util.extend(t,n);this.Option=util.extend({},s),this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="image",this._canRotateOrigin=!0};Img.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.drawImage(t),this._dirty=!1},getOriPoints:function(){var t=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),this.oriPoints=t,this.detectOriPoints=t},getPoints:function(){var t=[],i=null;return i=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(n){ -t.push(this.getPointTodraw(n[0],n[1],i))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(t),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return t>this.max.minX&&tthis.max.minY&&i1&&!isNaN(t)?t:0}return this.goesBy},isRunning:function(){return this.running},reset:function(){this.goesBy=0}};var AnimationTimer=function(t,i){void 0!==t&&(this.duration=t),void 0!==i&&(this.timeFunc=i),this.watch=new Watch};AnimationTimer.prototype={start:function(){this.watch.start()},stop:function(){this.watch.stop()},getGoesByTime:function(){var t=this.watch.getGoesByTime(),i=t/this.duration;if(this.watch.running)return this.timeFunc?t*(EasingFunctions[this.timeFunc](i)/i):t},isOver:function(){return this.watch.getGoesByTime()>this.duration}};var specialOption={cshape:{x:"massCenter",y:"massCenter"},line:{x:"massCenter",y:"massCenter"}},specialAtrr={fillStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},strokeStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},shadow:{get:function(t){return{offsetX:t.offsetX,offsetY:t.offsetY,blur:t.blur,color:hex2rgb(t.color)}},set:function(t,i,n){var s=[t.color.r+Math.floor(i.color.r*n),t.color.g+Math.floor(i.color.g*n),t.color.b+Math.floor(i.color.b*n)],e="#"+rgb2hex.apply(void 0,s);return{offsetX:t.offsetX+i.offsetX*n,offsetY:t.offsetY+i.offsetY*n,blur:t.blur+i.blur*n,color:e}},getIncre:function(t,i,n){var s=util.extend(i,n.Shape.Option.shadow),e=hex2rgb(s.color),o={r:e.r-t.color.r,g:e.g-t.color.g,b:e.b-t.color.b};return{offsetX:(s.offsetX?s.offsetX:5)-t.offsetX,offsetY:(s.offsetY?s.offsetY:5)-t.offsetY,blur:(s.blur?s.blur:5)-t.blur,color:o}}},lineDash:{get:function(t){return t},set:function(t,i,n){return[[t[0][0]+i[0][0]*n,t[0][1]+i[0][1]*n],t[1][1]+i[1][1]*n]},getIncre:function(t,i,n){return[[-t[0][0]+i[0][0],-t[0][1]+i[0][1]],-t[1][1]+i[1][1]]}}},AnimationFrag=function(t,i,n,s,e){var o={onStart:function(){},onLooping:function(){},onEnd:function(){},duration:1e3,easing:"linear"},h=util.extend(s,o);this.object=t,this.source=0,this.genFlag=!1,this.bus=e,this.complete=!1,this.running=!1,this.started=!1,this.duration=h.duration,this.atrribute=i,this.atrributeList=[],"object"==(void 0===i?"undefined":_typeof(i))?(this.genFlag=!0,this.genAtrributeList(i)):(this.incre=genExe(n,i,t),this.exe=n),this.timer=new AnimationTimer(h.duration,h.easing),this.oriOption=h,this.endCallFrag=null,this.onEnd=h.onEnd,this.onLooping=h.onLooping,this.onStart=h.onStart,this._aniWrapbus=null};AnimationFrag.prototype={updateAnimation:function(){return!this.complete&&(this.timer.isOver()?(this.onEnd(),this.complete=!0,this.running=!1,this._aniWrapbus.dispatch("fragAniOver","no","me"),!1):void(this.started||this.complete?(this.onLooping(),this.updateAtrribute()):(this.genFlag||(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute]))),this.started=!0,this.running=!0,this.onStart(),this.timer.start())))},updateAtrribute:function(){this.genFlag?(this.atrributeList.forEach(function(t){this.object.Shape.Option[t.attr]||0==this.object.Shape.Option[t.attr]?specialAtrr[t.attr]?this.object.Shape.Option[t.attr]=specialAtrr[t.attr].set(t.source,t.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][t.attr]][t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration},this),this.object.Shape._dirty=!0):(this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?specialAtrr[this.atrribute]?this.object.Shape.Option[this.atrribute]=specialAtrr[this.atrribute].set(this.source,this.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration,this.object.Shape._dirty=!0)},genAtrributeList:function(t){var i=Object.keys(t),n=this;this.atrributeList=[],i.forEach(function(i){var s=this.object.Shape.Option[i]||0==this.object.Shape.Option[i]?this.object.Shape.Option[i]:this.object.Shape[specialOption[this.object.type][i]][i];specialAtrr[i]&&(s=specialAtrr[i].get(this.object.Shape.Option[i])),n.atrributeList.push({attr:i,incre:genExe(t[i],i,n.object),source:s})},this)},updateSourceAndtarget:function(){this.genFlag?this.genAtrributeList(this.atrribute):(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute])),this.incre=genExe(this.exe,this.atrribute,this.object))},addWrapBus:function(t){this._aniWrapbus=t},restart:function(){this.complete=!1,this.running=!1,this.started=!1,this.timer=new AnimationTimer(this.oriOption.duration,this.oriOption.easing)}};var eventBus=function(){this.eventList=[]};eventBus.prototype={add:function(t,i,n){this.eventList.length?(this.eventList.forEach(function(i){if(i.name==t)return i.thingsList.push(n),!1},this),this.eventList.push({name:t,scope:i,thingsList:[n]})):this.eventList.push({name:t,scope:i,thingsList:[n]})},dispatch:function(t,i){var n=arguments;if(arguments.length<2)return!1;var s=Array.prototype.slice.call(n,2);this.eventList.forEach(function(n){n.name===t&&n.thingsList.forEach(function(t){"no"!==i?t.call.apply(t,[i].concat(toConsumableArray(s))):t.call.apply(t,[n.scope].concat(toConsumableArray(s)))})})},destroy:function(){}};var AniFragWrap=function(t,i,n){this.runing=!1,this.stoped=!1,this.started=!1,this.fragStore=[],this.animationPick=0,this.bus=t,this.aniFraBus=new eventBus,this.aniFraBus.add("fragAniOver",this,this.getAniOver),this.overAni=[],this.aniFragListId=i,this.loop=!1,this.loopTimes=!1,this.looped=0,this.object=n,this.oriOption=util.extend(n.Shape.Option,n.Shape.Option),this.oriUnOption=util.extend(n.Shape.Option,n.Shape.UnOption),this.endCallWraper=null,this.firstTime=!0};AniFragWrap.prototype={updateFrag:function(t){t.addWrapBus(this.aniFraBus),this.fragStore.length?(this.fragStore[this.fragStore.length-1].endCallFrag=t,this.fragStore.push(t)):this.fragStore.push(t)},exeAnimate:function(){if(this.object.disableDrag(),this.firstTime&&(this.firstTime=!1,this.oriOption=util.extend(this.object.Shape.Option,this.object.Shape.Option),this.oriUnOption=util.extend(this.object.Shape.Option,this.object.Shape.UnOption)),this.stoped)return this.endCallWraper?this.endCallWraper.exeAnimate():this.object.restoreDrag(),!1;this.fragStore[this.animationPick]&&this.fragStore[this.animationPick].updateAnimation()},getAniOver:function(t){if(this.overAni.push(t),this.overAni.length==this.fragStore.length){if(this.loop){if(this.loopTimes&&this.looped<=this.loopTimes&&this.looped++,this.loopTimes&&this.looped>this.loopTimes)return this.stop(),!1;this.restart()}else this.stop();return!1}this.animationPick++,this.fragStore[this.animationPick].updateSourceAndtarget()},restart:function(){this.object.restoreOption(this.oriOption),this.object.restoreOption(this.oriUnOption),this.overAni=[],this.animationPick=0,this.fragStore.forEach(function(t){t.restart()},this),this.started=!1,this.stoped=!1},stop:function(){this.stoped=!0,this.bus.dispatch("wraperAniComplete","no",this.aniFragListId,this.object.Shapeid,this.object)},resume:function(){},setLoop:function(t,i){this.loop=t||!1,this.loopTimes=i||!1,this.looped=1}};var Shape=function(t,i,n,s){this.draggable=!!s,this.strokeOrfill=n||"fill",this.type=t,this.Shape=new shapeTypes[t](i),this.draggable&&this.Shape.closeRotateOrigin(),this.AnimationTimer=new AnimationTimer,this.animtionFragList=[],this.bus=null,this.Shapeid="sp"+guid(),this.animationStart=!1,this.aniFragListId="",this.aniFragWraper=null,this._oldDrag=this.draggable,this._layerIndex=0,this._getChoosed=!1,this._eventStore={tap:[],touchstart:[],touchmove:[],touchend:[],longpress:[],drag:[]},this._nowType="tap",this._canRotateOrigin=!0};Shape.prototype={updateBus:function(t){this.bus=t},paint:function(t){switch(this.strokeOrfill){case"fill":this.Shape.fill(t);break;case"stroke":this.Shape.stroke(t);break;case"mix":this.Shape.mixDraw(t);break;case!0:this.Shape.fill(t)}},detect:function(t,i,n){this.Shape.detected(t,i)?(this._nowType=n,this.bus.dispatch("getDetectedLayers","no",this._layerIndex)):this.bus.dispatch("getDetectedLayers","no",-1)},moveDetect:function(t,i){this._getChoosed&&this._eventStore.touchmove.forEach(function(t){t(this)},this),this.draggable&&this._getChoosed&&(this._eventStore.drag.forEach(function(t){t(this)},this),this.Shape.moveDetect(t,i))},upDetect:function(){this._getChoosed&&(this.bus.dispatch("clearDetectedLayers","no"),this._eventStore.touchend.forEach(function(t){t(this)},this),this.Shape.upDetect(),this._getChoosed=!1)},animate:function(t,i,n){this.aniFragListId||(this.aniFragListId="af"+guid(),this.aniFragWraper=new AniFragWrap(this.bus,this.aniFragListId,this));var s=null;return s="object"==(void 0===t?"undefined":_typeof(t))?new AnimationFrag(this,t,"no",arguments[1],this.bus):new AnimationFrag(this,t,arguments[1],arguments[2],this.bus),this.aniFragWraper.updateFrag(s),this},start:function(t){this.animationStart=!0,this.aniFragWraper&&(!0===t&&this.aniFragWraper.setLoop(t),"number"==typeof t&&this.aniFragWraper.setLoop(!0,t),this.bus.dispatch("addAnimation","no",this.aniFragWraper,this.Shapeid),this.aniFragListId="",this.aniFragWraper=null)},updateOption:function(t){return this.Shape.bus||(this.Shape.bus=this.bus),this.Shape.updateOption(t),this},restoreOption:function(t){this.Shape.restoreOption(t)},setOrigin:function(t){return this.Shape.setRotateOrigin(t),this},_updateLayer:function(t){this._layerIndex=t},updateLayer:function(t){this.bus.dispatch("updateLayer","no",this,this._layerIndex,t)},getChoosed:function(){this._getChoosed=!0,this._eventStore[this._nowType].forEach(function(t){t(this)},this)},destroy:function(){this.bus.dispatch("destory","no",this._layerIndex,this.Shapeid),this.bus.dispatch("destoryAnimation","no",this._layerIndex,this.Shapeid)},restoreDrag:function(){this.draggable=this._oldDrag},disableDrag:function(){this.draggable=!1},bind:function(t,i){void 0!==this._eventStore[t]&&this._eventStore[t].push(i)},unbind:function(t,i){var n=-1;void 0!==this._eventStore[t]&&this._eventStore[t].forEach(function(t,i){n=i}),-1!==n&&this._eventStore[t].splice(n,1)},clone:function(){var t={};return"text"==this.type&&(t={text:this.Shape.text}),new Shape(this.type,_extends({},this.Shape.Option,this.Shape.UnOption,t),this.strokeOrfill,this.draggable)},updateText:function(t){if("text"!=this.type)return!1;this.Shape.updateText(t)}};var shapeTypes={circle:function(t){return new Circle(t)},rect:function(t){return new Rect(t)},polygon:function(t){return new Polygon(t)},cshape:function(t){return new Cshape(t)},line:function(t){return new Line(t)},ellipse:function(t){return new Ellipse(t)},text:function(t){return new Text(t)},image:function(t){return new Img(t)}},AnimationFrame=function(){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:fakeAnimationFrame},animationFrame=AnimationFrame(),Animation=function(t){this.running=!1,this.paused=!0,this.bus=t,this.animationFragStore={},this.animationCompleteList=[],this.wraperAniCompleteOb={},this.bus.add("animationComplete",this,this.animationComplete),this.bus.add("wraperAniComplete",this,this.wraperAniComplete),this.bus.add("destoryAnimation",this,this.destroyAnimation),this.bus.add("clearAnimation",this,this.clearAnimation)};Animation.prototype={start:function(){this.running=!0,this.loopAnimation()},loopAnimation:function(){function t(){animationFrame(t),i.running&&i.updateStep()}var i=this;animationFrame(t)},updateStep:function(){Object.keys(this.animationFragStore).forEach(function(t){this.animationFragStore[t][0].exeAnimate()},this),this.bus.dispatch("update","no")},animationComplete:function(t){this.animationCompleteList.push(t),Object.keys(this.wraperAniCompleteOb).length===Object.keys(this.animationFragStore).length&&(this.running=!1)},wraperAniComplete:function(t,i,n){this.wraperAniCompleteOb[i]?this.wraperAniCompleteOb[i].push(t):this.wraperAniCompleteOb[i]=[t],this.wraperAniCompleteOb[i].length==this.animationFragStore[i].length&&(n.restoreDrag(),this.bus.dispatch("animationComplete","no",i))},destroyAnimation:function(t,i){delete this.animationFragStore[i]},clearAnimation:function(){this.animationFragStore={},this.running=!1}},WxDraw.prototype={add:function(t){t.updateBus(this.bus),t._updateLayer(this.store.getLength()),this.store.add(t)},draw:function(){this.store.store.forEach(function(t){t.paint(this.canvas)},this)},tapDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"tap")},this)},longpressDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"longpress")},this)},touchstartDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.detect(i.x,i.y,"touchstart")},this)},touchendDetect:function(t){this.store.store.forEach(function(t){t.upDetect()},this)},touchmoveDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.moveDetect(i.x,i.y)},this),this.draw(),this.canvas.draw()},getLoc:function(t,i){return{x:t-this.x>0?t-this.x>this.w?this.w:t-this.x:0,y:i-this.y>0?i-this.y>this.h?this.h:i-this.y:0}},update:function(){this.draw(),this.canvas.draw()},AnimationCenter:function(){},addAnimationFrag:function(t,i){this.animation.animationFragStore[i]?(this.animation.animationFragStore[i][this.animation.animationFragStore[i].length-1].endCallWraper=t,this.animation.animationFragStore[i].push(t)):this.animation.animationFragStore[i]=[t]},getDetectedLayers:function(t){this.detectedLayers.push(t),this.detectedLayers.length==this.store.getLength()&&-1!=Math.max.apply(null,this.detectedLayers)&&this.store.find(Math.max.apply(null,this.detectedLayers)).getChoosed(),this.detectedLayers.length==this.store.getLength()&&-1==Math.max.apply(null,this.detectedLayers)&&this.clearDetectedLayers()},clearDetectedLayers:function(){this.detectedLayers=[]},updateLayer:function(t,i,n){var s=0,e=void 0;s=n,"string"==typeof n&&(e=0===n.indexOf("-")?-1:0===n.indexOf("+")&&1),s=e?i+e*parseInt(-1==e?n.split("-")[1]:n.split("+")[1]):parseInt(n),s>=this.store.store.length-1&&(s=this.store.store.length-1),s<=0&&(s=0),this.store.changeIndex(t,i,s),this._updateLayer()},destroy:function(t){this.store.store.splice(t,1)},_updateLayer:function(){this.store.store.forEach(function(t,i){t._updateLayer(i)})},clear:function(){this.canvas.clearActions(),this.store.clear(),this.canvas=null,this.bus.dispatch("clearAnimation","no","no")}};var wxDraw={wxDraw:WxDraw,Shape:Shape,AnimationFrame:AnimationFrame()};module.exports=wxDraw; +"use strict";function Line(t){var i=_extends({strokeStyle:"#000000",points:[[1,2],[23,45],[2,45],[230,205]]},commonAttr()),n=_extends({smooth:!0},commonUnAttr()),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this.max={maxX:null,maxY:null,minX:null,minY:null},this.massCenter=this.genMassCenter(this.Option.points),this.posPoints=this.genPointsPositiveLoc(),this.oriPoints=this.Option.points,this._Points=this.Option.points,this._CurvePoints=this.Option.points,this.detectPoints=this.getDetectPoints(),this.getMax(),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="line",this._canRotateOrigin=!0}function Watch(){this.startTime=0,this.running=!1,this.goesBytime=0,this.goesBy=void 0,this.DEFAULT_ELASTIC=2}function genExe(t,i,n){if(specialAtrr[i])return specialAtrr[i].getIncre(specialAtrr[i].get(n.Shape.Option[i]),t,n);if(!isNaN(Number(t)))return n.Shape.Option[i]||0===n.Shape.Option[i]?parseFloat(t)-parseFloat(n.Shape.Option[i]):parseFloat(t)-parseFloat(n.Shape[specialOption[n.type][i]][i]);if(0==t.indexOf("+=")){return t.split("=")[1]}if(0==t.indexOf("-=")){return-1*t.split("=")[1]}}function fakeAnimationFrame(t){var i;setTimeout(function(){i=+new Date,t(i)},16)}function WxDraw(t,i,n,s,e){this.canvas=t,this.wcid=guid(),this.store=new Store,this.bus=new eventBus,this.animation=new Animation(this.bus),this.x=i,this.y=n,this.w=s,this.h=e,this.bus.add("addAnimation",this,this.addAnimationFrag),this.bus.add("update",this,this.update),this.bus.add("getDetectedLayers",this,this.getDetectedLayers),this.bus.add("clearDetectedLayers",this,this.clearDetectedLayers),this.bus.add("updateLayer",this,this.updateLayer),this.bus.add("destory",this,this.destroy),this.animation.start(),Shape.bus=this.bus,this.detectedLayers=[]}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,i){for(var n=0;n0&&(this.turnColorLock(!0),i=t.createLinearGradient.apply(t,toConsumableArray(this.getGradientOption(n).lg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),this.UnOption.needGra&&"circle"==this.UnOption.needGra&&this.UnOption.gra&&this.UnOption.gra.length>0&&(this.turnColorLock(!0),i=t.createCircularGradient.apply(t,toConsumableArray(this.getGradientOption(n).cg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),(!this._colorLock||this.needGra&&"no"==his.UnOption.needGra)&&t.setFillStyle(this.Option.fillStyle),"miter"==this.UnOption.lineJoin&&t.setMiterLimit(this.Option.miterLimit),t.setStrokeStyle(this.Option.strokeStyle),t.setLineWidth(this.Option.lineWidth),t.setGlobalAlpha(this.Option.opacity),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this.UnOption.isLineDash&&t.setLineDash&&(this.Option.lineDash instanceof Array||(this.Option.lineDash[0]=objToArray(this.Option.lineDash[0])),t.setLineDash(this.Option.lineDash[0],this.Option.lineDash[1]))},stroke:function(t){return"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.stroke(),void t.restore())},fill:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(t.save(),t.setGlobalAlpha(this.Option.opacity),t.beginPath(),t.setFontSize(this.Option.fontSize),t.setTextAlign(this.UnOption.align),t.setTextBaseline(this.UnOption.textBaseline),t.setFillStyle(this.Option.fillStyle),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this._draw(t),t.closePath(),t.restore(),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!1,this._draw(t),this.setCommonstyle(t),t.fill(),void t.restore())},mixDraw:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.fill(),t.stroke(),void t.restore())},turnColorLock:function(t){this._colorLock=!!t},getGradientOption:function(t){return{circle:"circle"==t?{lg:[this.Option.x-this.Option.r,0,this.Option.x+this.Option.r,0],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},rect:"rect"==t?{lg:[this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2,this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow(this.Option.w/2,2)+Math.pow(this.Option.h/2,2))]}:{},polygon:"polygon"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},cshape:"cshape"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.massCenter.x,this.massCenter.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{},ellipse:"ellipse"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{}}[t]},_drawHelperPoints:function(t){t.save(),t.setFillStyle("#F34739"),t.beginPath(),this._detectPoints?this._detectPoints.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}):this._Points.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}),t.closePath(),t.fill(),t.restore()},closeRotateOrigin:function(){this._canRotateOrigin=!1}},Polygon=function(t){var i=_extends({x:10,y:10,r:10,sides:7},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(this.oriPoints),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="polygon",this._canRotateOrigin=!0};Polygon.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;sthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Ellipse=function(t){var i=_extends({x:10,y:10,a:10,b:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="ellipse",this._canRotateOrigin=!0};Ellipse.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;s<100;++s)t.push([this.Option.x+this.Option.a/2*Math.sin(n),this.Option.y-this.Option.b/2*Math.cos(n)]),i.push([this.Option.x+(this.Option.a/2+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.b+this.Option.lineWidth)/2*Math.cos(n)]),n+=2*Math.PI/100;this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var baseline=function(t,i){return{normal:2,bottom:-i/2,middle:0,top:i/2}[t]},align=function(t,i){return{left:i/2,center:0,right:-i/2}[t]},Text=function(t){t.text||(t.text="no text");var i={x:100,y:200,fontSize:12,shadow:{offsetX:5,offsetY:5,blur:5,color:"#000000"},fillStyle:"#000000",strokeStyle:"#000000",rotate:0,opacity:1},n={textBaseline:"normal",align:"left",needShadow:!1};this.text=t.text,this.Option=util.extend(t,i),this.UnOption=util.extend(t,n),this.boxOption={x:0,y:0},this.boxOriPoints=[],this.boxPoints=[],this.rotateOrigin=null,this.offset={x:0,y:0},this._offsetX=0,this._offsetY=0,this.getOriPoints(),this.getPoints(),this._dirty=!0,this._type="text",this._canRotateOrigin=!0};Text.prototype=_extends({getOriPoints:function(){for(var t=[],i=/^[\u4e00-\u9fa5]/,n=String(this.text).length,s=0,e=this.Option.fontSize,o=0;oi!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.boxOption.x=t,this.boxOption.y=i,this.Option.x=t-this.offset.x,this.Option.y=i-this.offset.y,this._dirty=!0},detected:function(t,i){return this._offsetX=this.boxOption.x-t,this._offsetY=this.boxOption.y-i,!!this._pnpolyTest(t,i)&&(this._isChoosed=!0,!0)},_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints()),t.save(),this.rotateOrigin?(t.translate(this.rotateOrigin[0],this.rotateOrigin[1]),t.rotate(this.Option.rotate),t.fillText(this.text,this.boxOption.x-this.rotateOrigin[0]-this.offset.x,this.boxOption.y-this.rotateOrigin[1]-this.offset.y)):(t.translate(this.boxOption.x,this.boxOption.y),t.rotate(this.Option.rotate),t.fillText(this.text,-this.offset.x,-this.offset.y)),t.restore(),this._dirty=!1},moveDetect:function(t,i){1==this._isChoosed&&this.move(t+this._offsetX,i+this._offsetY)},updateText:function(t){this.text=t,this._dirty=!0}},commonMethods);var getCurvePoints=function(t,i,n,s){i=void 0!==i?i:.5,n=n||!1,s=s||16;var e,o,h,r,a,u,p,c,l,m,f,x,d,g=[],O=[];for(g=t.slice(0),n?(g.unshift(t[t.length-1]),g.unshift(t[t.length-1]),g.push(t[0])):(g.unshift(t[1]),g.push(t[t.length-1])),d=1;dthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Circle=function(t){var i=_extends({x:10,y:10,r:10,sA:0,eA:2*Math.PI},commonAttr()),n=_extends({},commonUnAttr(),{counterclockwise:!1,closePath:!1}),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.fullCircle=!0,this._colorLock=!1,this._canRotateOrigin=!0,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="circle"};Circle.prototype=_extends({getOriPoints:function(){var t=[],i=[],n=this.Option.sA||0,s=this.Option.eA||2*Math.PI,e=s-n;e>=2*Math.PI?this.fullCircle=!0:this.fullCircle=!1;for(var o=0;o<=100;++o)n=this.Option.sA+o*e/100,t.push([this.Option.x+this.Option.r*Math.sin(n),this.Option.y-this.Option.r*Math.cos(n)]),i.push([this.Option.x+(this.Option.r+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.r+this.Option.lineWidth/2)*Math.cos(n)]);t.unshift([this.Option.x,this.Option.y]),i.unshift([this.Option.x,this.Option.y]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this.detectOriPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Rect=function(t){var i=_extends({x:10,y:10,w:10,h:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=util.extend({},n),this.UnOption=s,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.bus=null,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="rect",this._rotateOriginOver=!1,this._canRotateOrigin=!0};Rect.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.createPath(t),this._dirty=!1},getOriPoints:function(){var t=[],i=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._changeCenter(n),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return console.log("检测方块",t,i),t>this.max.minX&&tthis.max.minY&&ithis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=a>i&&t<(r-o)*(i-h)/(a-h)+o&&(n=!n)}return n}},commonMethods);var Img=function(t){var i={x:10,y:10,w:10,h:10,rotate:0,opacity:1},n={file:""},s=util.extend(t,i),e=util.extend(t,n);this.Option=util.extend({},s),this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="image",this._canRotateOrigin=!0};Img.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.drawImage(t),this._dirty=!1},getOriPoints:function(){var t=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),this.oriPoints=t,this.detectOriPoints=t},getPoints:function(){var t=[],i=null;return i=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(n){t.push(this.getPointTodraw(n[0],n[1],i))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(t),this._Points}, +getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return t>this.max.minX&&tthis.max.minY&&i1&&!isNaN(t)?t:0}return this.goesBy},isRunning:function(){return this.running},reset:function(){this.goesBy=0}};var AnimationTimer=function(t,i){void 0!==t&&(this.duration=t),void 0!==i&&(this.timeFunc=i),this.watch=new Watch};AnimationTimer.prototype={start:function(){this.watch.start()},stop:function(){this.watch.stop()},getGoesByTime:function(){var t=this.watch.getGoesByTime(),i=t/this.duration;if(this.watch.running)return this.timeFunc?t*(EasingFunctions[this.timeFunc](i)/i):t},isOver:function(){return this.watch.getGoesByTime()>this.duration}};var specialOption={cshape:{x:"massCenter",y:"massCenter"},line:{x:"massCenter",y:"massCenter"}},specialAtrr={fillStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},strokeStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},shadow:{get:function(t){return{offsetX:t.offsetX,offsetY:t.offsetY,blur:t.blur,color:hex2rgb(t.color)}},set:function(t,i,n){var s=[t.color.r+Math.floor(i.color.r*n),t.color.g+Math.floor(i.color.g*n),t.color.b+Math.floor(i.color.b*n)],e="#"+rgb2hex.apply(void 0,s);return{offsetX:t.offsetX+i.offsetX*n,offsetY:t.offsetY+i.offsetY*n,blur:t.blur+i.blur*n,color:e}},getIncre:function(t,i,n){var s=util.extend(i,n.Shape.Option.shadow),e=hex2rgb(s.color),o={r:e.r-t.color.r,g:e.g-t.color.g,b:e.b-t.color.b};return{offsetX:(s.offsetX?s.offsetX:5)-t.offsetX,offsetY:(s.offsetY?s.offsetY:5)-t.offsetY,blur:(s.blur?s.blur:5)-t.blur,color:o}}},lineDash:{get:function(t){return t},set:function(t,i,n){return[[t[0][0]+i[0][0]*n,t[0][1]+i[0][1]*n],t[1][1]+i[1][1]*n]},getIncre:function(t,i,n){return[[-t[0][0]+i[0][0],-t[0][1]+i[0][1]],-t[1][1]+i[1][1]]}}},AnimationFrag=function(t,i,n,s,e){var o={onStart:function(){},onLooping:function(){},onEnd:function(){},duration:1e3,easing:"linear"},h=util.extend(s,o);this.object=t,this.source=0,this.genFlag=!1,this.bus=e,this.complete=!1,this.running=!1,this.started=!1,this.duration=h.duration,this.atrribute=i,this.atrributeList=[],"object"==(void 0===i?"undefined":_typeof(i))?(this.genFlag=!0,this.genAtrributeList(i)):(this.incre=genExe(n,i,t),this.exe=n),this.timer=new AnimationTimer(h.duration,h.easing),this.oriOption=h,this.endCallFrag=null,this.onEnd=h.onEnd,this.onLooping=h.onLooping,this.onStart=h.onStart,this._aniWrapbus=null};AnimationFrag.prototype={updateAnimation:function(){return!this.complete&&(this.timer.isOver()?(this.onEnd(),this.complete=!0,this.running=!1,this._aniWrapbus.dispatch("fragAniOver","no","me"),!1):void(this.started||this.complete?(this.onLooping(),this.updateAtrribute()):(this.genFlag||(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute]))),this.started=!0,this.running=!0,this.onStart(),this.timer.start())))},updateAtrribute:function(){this.genFlag?(this.atrributeList.forEach(function(t){this.object.Shape.Option[t.attr]||0==this.object.Shape.Option[t.attr]?specialAtrr[t.attr]?this.object.Shape.Option[t.attr]=specialAtrr[t.attr].set(t.source,t.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][t.attr]][t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration},this),this.object.Shape._dirty=!0):(this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?specialAtrr[this.atrribute]?this.object.Shape.Option[this.atrribute]=specialAtrr[this.atrribute].set(this.source,this.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration,this.object.Shape._dirty=!0)},genAtrributeList:function(t){var i=Object.keys(t),n=this;this.atrributeList=[],i.forEach(function(i){var s=this.object.Shape.Option[i]||0==this.object.Shape.Option[i]?this.object.Shape.Option[i]:this.object.Shape[specialOption[this.object.type][i]][i];specialAtrr[i]&&(s=specialAtrr[i].get(this.object.Shape.Option[i])),n.atrributeList.push({attr:i,incre:genExe(t[i],i,n.object),source:s})},this)},updateSourceAndtarget:function(){this.genFlag?this.genAtrributeList(this.atrribute):(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute])),this.incre=genExe(this.exe,this.atrribute,this.object))},addWrapBus:function(t){this._aniWrapbus=t},restart:function(){this.complete=!1,this.running=!1,this.started=!1,this.timer=new AnimationTimer(this.oriOption.duration,this.oriOption.easing)}};var eventBus=function(){this.eventList=[]};eventBus.prototype={add:function(t,i,n){this.eventList.length?(this.eventList.forEach(function(i){if(i.name==t)return i.thingsList.push(n),!1},this),this.eventList.push({name:t,scope:i,thingsList:[n]})):this.eventList.push({name:t,scope:i,thingsList:[n]})},dispatch:function(t,i){var n=arguments;if(arguments.length<2)return!1;var s=Array.prototype.slice.call(n,2);this.eventList.forEach(function(n){n.name===t&&n.thingsList.forEach(function(t){"no"!==i?t.call.apply(t,[i].concat(toConsumableArray(s))):t.call.apply(t,[n.scope].concat(toConsumableArray(s)))})})},destroy:function(){}};var AniFragWrap=function(t,i,n){this.runing=!1,this.stoped=!1,this.started=!1,this.fragStore=[],this.animationPick=0,this.bus=t,this.aniFraBus=new eventBus,this.aniFraBus.add("fragAniOver",this,this.getAniOver),this.overAni=[],this.aniFragListId=i,this.loop=!1,this.loopTimes=!1,this.looped=0,this.object=n,this.oriOption=util.extend(n.Shape.Option,n.Shape.Option),this.oriUnOption=util.extend(n.Shape.Option,n.Shape.UnOption),this.endCallWraper=null,this.firstTime=!0};AniFragWrap.prototype={updateFrag:function(t){t.addWrapBus(this.aniFraBus),this.fragStore.length?(this.fragStore[this.fragStore.length-1].endCallFrag=t,this.fragStore.push(t)):this.fragStore.push(t)},exeAnimate:function(){if(this.object.disableDrag(),this.firstTime&&(this.firstTime=!1,this.oriOption=util.extend(this.object.Shape.Option,this.object.Shape.Option),this.oriUnOption=util.extend(this.object.Shape.Option,this.object.Shape.UnOption)),this.stoped)return this.endCallWraper?this.endCallWraper.exeAnimate():this.object.restoreDrag(),!1;this.fragStore[this.animationPick]&&this.fragStore[this.animationPick].updateAnimation()},getAniOver:function(t){if(this.overAni.push(t),this.overAni.length==this.fragStore.length){if(this.loop){if(this.loopTimes&&this.looped<=this.loopTimes&&this.looped++,this.loopTimes&&this.looped>this.loopTimes)return this.stop(),!1;this.restart()}else this.stop();return!1}this.animationPick++,this.fragStore[this.animationPick].updateSourceAndtarget()},restart:function(){this.object.restoreOption(this.oriOption),this.object.restoreOption(this.oriUnOption),this.overAni=[],this.animationPick=0,this.fragStore.forEach(function(t){t.restart()},this),this.started=!1,this.stoped=!1},stop:function(){this.stoped=!0,this.bus.dispatch("wraperAniComplete","no",this.aniFragListId,this.object.Shapeid,this.object)},resume:function(){},setLoop:function(t,i){this.loop=t||!1,this.loopTimes=i||!1,this.looped=1}};var Shape=function(t,i,n,s){this.draggable=!!s,this.strokeOrfill=n||"fill",this.type=t,this.Shape=new shapeTypes[t](i),this.draggable&&this.Shape.closeRotateOrigin(),this.AnimationTimer=new AnimationTimer,this.animtionFragList=[],this.bus=null,this.Shapeid="sp"+guid(),this.animationStart=!1,this.aniFragListId="",this.aniFragWraper=null,this._oldDrag=this.draggable,this._layerIndex=0,this._getChoosed=!1,this._eventStore={tap:[],touchstart:[],touchmove:[],touchend:[],longpress:[],drag:[]},this._nowType="tap",this._canRotateOrigin=!0};Shape.prototype={updateBus:function(t){this.bus=t},paint:function(t){switch(this.strokeOrfill){case"fill":this.Shape.fill(t);break;case"stroke":this.Shape.stroke(t);break;case"mix":this.Shape.mixDraw(t);break;case!0:this.Shape.fill(t)}},detect:function(t,i,n){this.Shape.detected(t,i)?(this._nowType=n,this.bus.dispatch("getDetectedLayers","no",this._layerIndex)):this.bus.dispatch("getDetectedLayers","no",-1)},moveDetect:function(t,i){this._getChoosed&&this._eventStore.touchmove.forEach(function(t){t(this)},this),this.draggable&&this._getChoosed&&(this._eventStore.drag.forEach(function(t){t(this)},this),this.Shape.moveDetect(t,i))},upDetect:function(){this._getChoosed&&(this.bus.dispatch("clearDetectedLayers","no"),this._eventStore.touchend.forEach(function(t){t(this)},this),this.Shape.upDetect(),this._getChoosed=!1)},animate:function(t,i,n){this.aniFragListId||(this.aniFragListId="af"+guid(),this.aniFragWraper=new AniFragWrap(this.bus,this.aniFragListId,this));var s=null;return s="object"==(void 0===t?"undefined":_typeof(t))?new AnimationFrag(this,t,"no",arguments[1],this.bus):new AnimationFrag(this,t,arguments[1],arguments[2],this.bus),this.aniFragWraper.updateFrag(s),this},start:function(t){this.animationStart=!0,this.aniFragWraper&&(!0===t&&this.aniFragWraper.setLoop(t),"number"==typeof t&&this.aniFragWraper.setLoop(!0,t),this.bus.dispatch("addAnimation","no",this.aniFragWraper,this.Shapeid),this.aniFragListId="",this.aniFragWraper=null),console.log("start")},updateOption:function(t){return this.Shape.bus||(this.Shape.bus=this.bus),this.Shape.updateOption(t),this},restoreOption:function(t){this.Shape.restoreOption(t)},setOrigin:function(t){return this.Shape.setRotateOrigin(t),this},_updateLayer:function(t){this._layerIndex=t},updateLayer:function(t){this.bus.dispatch("updateLayer","no",this,this._layerIndex,t)},getChoosed:function(){this._getChoosed=!0,this._eventStore[this._nowType].forEach(function(t){t(this)},this)},destroy:function(){this.bus.dispatch("destory","no",this._layerIndex,this.Shapeid),this.bus.dispatch("destoryAnimation","no",this._layerIndex,this.Shapeid)},restoreDrag:function(){this.draggable=this._oldDrag},disableDrag:function(){this.draggable=!1},bind:function(t,i){void 0!==this._eventStore[t]&&this._eventStore[t].push(i)},unbind:function(t,i){var n=-1;void 0!==this._eventStore[t]&&this._eventStore[t].forEach(function(t,i){n=i}),-1!==n&&this._eventStore[t].splice(n,1)},clone:function(){var t={};return"text"==this.type&&(t={text:this.Shape.text}),new Shape(this.type,_extends({},this.Shape.Option,this.Shape.UnOption,t),this.strokeOrfill,this.draggable)},updateText:function(t){if("text"!=this.type)return!1;this.Shape.updateText(t)}};var shapeTypes={circle:function(t){return new Circle(t)},rect:function(t){return new Rect(t)},polygon:function(t){return new Polygon(t)},cshape:function(t){return new Cshape(t)},line:function(t){return new Line(t)},ellipse:function(t){return new Ellipse(t)},text:function(t){return new Text(t)},image:function(t){return new Img(t)}},AnimationFrame=function(){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:fakeAnimationFrame},animationFrame=AnimationFrame(),Animation=function(t){this.running=!1,this.paused=!0,this.bus=t,this.animationFragStore={},this.animationCompleteList=[],this.wraperAniCompleteOb={},this.bus.add("animationComplete",this,this.animationComplete),this.bus.add("wraperAniComplete",this,this.wraperAniComplete),this.bus.add("destoryAnimation",this,this.destroyAnimation),this.bus.add("clearAnimation",this,this.clearAnimation)};Animation.prototype={start:function(){this.running=!0,this.loopAnimation()},loopAnimation:function(){function t(){animationFrame(t),i.running&&i.updateStep()}var i=this;animationFrame(t)},updateStep:function(){Object.keys(this.animationFragStore).forEach(function(t){this.animationFragStore[t][0].exeAnimate()},this),this.bus.dispatch("update","no")},animationComplete:function(t){this.animationCompleteList.push(t),delete this.animationFragStore[t],console.log("结束动画"),Object.keys(this.wraperAniCompleteOb).length===Object.keys(this.animationFragStore).length&&(this.running=!1)},wraperAniComplete:function(t,i,n){this.wraperAniCompleteOb[i]?this.wraperAniCompleteOb[i].push(t):this.wraperAniCompleteOb[i]=[t],this.wraperAniCompleteOb[i].length==this.animationFragStore[i].length&&(n.restoreDrag(),this.bus.dispatch("animationComplete","no",i))},destroyAnimation:function(t,i){delete this.animationFragStore[i]},clearAnimation:function(){this.animationFragStore={},this.running=!1}},WxDraw.prototype={add:function(t){t.updateBus(this.bus),t._updateLayer(this.store.getLength()),this.store.add(t)},draw:function(){this.store.store.forEach(function(t){t.paint(this.canvas)},this)},tapDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"tap")},this)},longpressDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"longpress")},this)},touchstartDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.detect(i.x,i.y,"touchstart")},this)},touchendDetect:function(t){this.store.store.forEach(function(t){t.upDetect()},this)},touchmoveDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.moveDetect(i.x,i.y)},this),this.draw(),this.canvas.draw()},getLoc:function(t,i){return{x:t-this.x>0?t-this.x>this.w?this.w:t-this.x:0,y:i-this.y>0?i-this.y>this.h?this.h:i-this.y:0}},update:function(){this.draw(),this.canvas.draw()},AnimationCenter:function(){},addAnimationFrag:function(t,i){this.animation.animationFragStore[i]?(this.animation.animationFragStore[i][this.animation.animationFragStore[i].length-1].endCallWraper=t,this.animation.animationFragStore[i].push(t)):this.animation.animationFragStore[i]=[t]},getDetectedLayers:function(t){this.detectedLayers.push(t),this.detectedLayers.length==this.store.getLength()&&-1!=Math.max.apply(null,this.detectedLayers)&&this.store.find(Math.max.apply(null,this.detectedLayers)).getChoosed(),this.detectedLayers.length==this.store.getLength()&&-1==Math.max.apply(null,this.detectedLayers)&&this.clearDetectedLayers()},clearDetectedLayers:function(){this.detectedLayers=[]},updateLayer:function(t,i,n){var s=0,e=void 0;s=n,"string"==typeof n&&(e=0===n.indexOf("-")?-1:0===n.indexOf("+")&&1),s=e?i+e*parseInt(-1==e?n.split("-")[1]:n.split("+")[1]):parseInt(n),s>=this.store.store.length-1&&(s=this.store.store.length-1),s<=0&&(s=0),this.store.changeIndex(t,i,s),this._updateLayer()},destroy:function(t){this.store.store.splice(t,1)},_updateLayer:function(){this.store.store.forEach(function(t,i){t._updateLayer(i)})},clear:function(){this.canvas.clearActions(),this.store.clear(),this.canvas=null,this.bus.dispatch("clearAnimation","no","no")}};var wxDraw={wxDraw:WxDraw,Shape:Shape,AnimationFrame:AnimationFrame()};module.exports=wxDraw; diff --git a/example2/app.js b/test/app.js similarity index 100% rename from example2/app.js rename to test/app.js diff --git a/example2/app.json b/test/app.json similarity index 100% rename from example2/app.json rename to test/app.json diff --git a/example2/app.wxss b/test/app.wxss similarity index 100% rename from example2/app.wxss rename to test/app.wxss diff --git a/example2/config.js b/test/config.js similarity index 100% rename from example2/config.js rename to test/config.js diff --git a/example2/image/green_tri.png b/test/image/green_tri.png similarity index 100% rename from example2/image/green_tri.png rename to test/image/green_tri.png diff --git a/example2/image/icon64_appwx_logo.png b/test/image/icon64_appwx_logo.png similarity index 100% rename from example2/image/icon64_appwx_logo.png rename to test/image/icon64_appwx_logo.png diff --git a/example2/image/icon_API.png b/test/image/icon_API.png similarity index 100% rename from example2/image/icon_API.png rename to test/image/icon_API.png diff --git a/example2/image/icon_API_HL.png b/test/image/icon_API_HL.png similarity index 100% rename from example2/image/icon_API_HL.png rename to test/image/icon_API_HL.png diff --git a/example2/image/icon_component.png b/test/image/icon_component.png similarity index 100% rename from example2/image/icon_component.png rename to test/image/icon_component.png diff --git a/example2/image/icon_component_HL.png b/test/image/icon_component_HL.png similarity index 100% rename from example2/image/icon_component_HL.png rename to test/image/icon_component_HL.png diff --git a/example2/image/icon_foot.png b/test/image/icon_foot.png similarity index 100% rename from example2/image/icon_foot.png rename to test/image/icon_foot.png diff --git a/example2/image/location.png b/test/image/location.png similarity index 100% rename from example2/image/location.png rename to test/image/location.png diff --git a/example2/image/pause.png b/test/image/pause.png similarity index 100% rename from example2/image/pause.png rename to test/image/pause.png diff --git a/example2/image/play.png b/test/image/play.png similarity index 100% rename from example2/image/play.png rename to test/image/play.png diff --git a/example2/image/plus.png b/test/image/plus.png similarity index 100% rename from example2/image/plus.png rename to test/image/plus.png diff --git a/example2/image/record.png b/test/image/record.png similarity index 100% rename from example2/image/record.png rename to test/image/record.png diff --git a/example2/image/stop.png b/test/image/stop.png similarity index 100% rename from example2/image/stop.png rename to test/image/stop.png diff --git a/example2/image/trash.png b/test/image/trash.png similarity index 100% rename from example2/image/trash.png rename to test/image/trash.png diff --git a/example2/image/wechat.png b/test/image/wechat.png similarity index 100% rename from example2/image/wechat.png rename to test/image/wechat.png diff --git a/example2/image/wechatHL.png b/test/image/wechatHL.png similarity index 100% rename from example2/image/wechatHL.png rename to test/image/wechatHL.png diff --git a/example2/page/about/index.js b/test/page/about/index.js similarity index 100% rename from example2/page/about/index.js rename to test/page/about/index.js diff --git a/example2/page/about/index.json b/test/page/about/index.json similarity index 100% rename from example2/page/about/index.json rename to test/page/about/index.json diff --git a/example2/page/about/index.wxml b/test/page/about/index.wxml similarity index 100% rename from example2/page/about/index.wxml rename to test/page/about/index.wxml diff --git a/example2/page/about/index.wxss b/test/page/about/index.wxss similarity index 100% rename from example2/page/about/index.wxss rename to test/page/about/index.wxss diff --git a/example2/page/about/resources/me.jpg b/test/page/about/resources/me.jpg similarity index 100% rename from example2/page/about/resources/me.jpg rename to test/page/about/resources/me.jpg diff --git a/example2/page/common/foot.wxml b/test/page/common/foot.wxml similarity index 100% rename from example2/page/common/foot.wxml rename to test/page/common/foot.wxml diff --git a/example2/page/common/head.wxml b/test/page/common/head.wxml similarity index 100% rename from example2/page/common/head.wxml rename to test/page/common/head.wxml diff --git a/example2/page/common/index.wxss b/test/page/common/index.wxss similarity index 100% rename from example2/page/common/index.wxss rename to test/page/common/index.wxss diff --git a/example2/page/common/lib/weui.wxss b/test/page/common/lib/weui.wxss similarity index 100% rename from example2/page/common/lib/weui.wxss rename to test/page/common/lib/weui.wxss diff --git a/example2/page/component/index.js b/test/page/component/index.js similarity index 100% rename from example2/page/component/index.js rename to test/page/component/index.js diff --git a/example2/page/component/index.json b/test/page/component/index.json similarity index 100% rename from example2/page/component/index.json rename to test/page/component/index.json diff --git a/example2/page/component/index.wxml b/test/page/component/index.wxml similarity index 100% rename from example2/page/component/index.wxml rename to test/page/component/index.wxml diff --git a/example2/page/component/index.wxss b/test/page/component/index.wxss similarity index 100% rename from example2/page/component/index.wxss rename to test/page/component/index.wxss diff --git a/example2/page/component/pages/all/index.js b/test/page/component/pages/all/index.js similarity index 100% rename from example2/page/component/pages/all/index.js rename to test/page/component/pages/all/index.js diff --git a/example2/page/component/pages/all/index.wxml b/test/page/component/pages/all/index.wxml similarity index 100% rename from example2/page/component/pages/all/index.wxml rename to test/page/component/pages/all/index.wxml diff --git a/example2/page/component/pages/all/index.wxss b/test/page/component/pages/all/index.wxss similarity index 100% rename from example2/page/component/pages/all/index.wxss rename to test/page/component/pages/all/index.wxss diff --git a/example2/page/component/pages/circle/1.jpg b/test/page/component/pages/circle/1.jpg similarity index 100% rename from example2/page/component/pages/circle/1.jpg rename to test/page/component/pages/circle/1.jpg diff --git a/example2/page/component/pages/circle/1.png b/test/page/component/pages/circle/1.png similarity index 100% rename from example2/page/component/pages/circle/1.png rename to test/page/component/pages/circle/1.png diff --git a/example2/page/component/pages/circle/index.js b/test/page/component/pages/circle/index.js similarity index 100% rename from example2/page/component/pages/circle/index.js rename to test/page/component/pages/circle/index.js diff --git a/example2/page/component/pages/circle/index.wxml b/test/page/component/pages/circle/index.wxml similarity index 100% rename from example2/page/component/pages/circle/index.wxml rename to test/page/component/pages/circle/index.wxml diff --git a/example2/page/component/pages/circle/index.wxss b/test/page/component/pages/circle/index.wxss similarity index 100% rename from example2/page/component/pages/circle/index.wxss rename to test/page/component/pages/circle/index.wxss diff --git a/example2/page/component/pages/cshape/index.js b/test/page/component/pages/cshape/index.js similarity index 100% rename from example2/page/component/pages/cshape/index.js rename to test/page/component/pages/cshape/index.js diff --git a/example2/page/component/pages/cshape/index.wxml b/test/page/component/pages/cshape/index.wxml similarity index 100% rename from example2/page/component/pages/cshape/index.wxml rename to test/page/component/pages/cshape/index.wxml diff --git a/example2/page/component/pages/cshape/index.wxss b/test/page/component/pages/cshape/index.wxss similarity index 100% rename from example2/page/component/pages/cshape/index.wxss rename to test/page/component/pages/cshape/index.wxss diff --git a/example2/page/component/pages/demo1/index.js b/test/page/component/pages/demo1/index.js similarity index 100% rename from example2/page/component/pages/demo1/index.js rename to test/page/component/pages/demo1/index.js diff --git a/example2/page/component/pages/demo1/index.wxml b/test/page/component/pages/demo1/index.wxml similarity index 100% rename from example2/page/component/pages/demo1/index.wxml rename to test/page/component/pages/demo1/index.wxml diff --git a/example2/page/component/pages/demo1/index.wxss b/test/page/component/pages/demo1/index.wxss similarity index 100% rename from example2/page/component/pages/demo1/index.wxss rename to test/page/component/pages/demo1/index.wxss diff --git a/example2/page/component/pages/demo2/index.js b/test/page/component/pages/demo2/index.js similarity index 100% rename from example2/page/component/pages/demo2/index.js rename to test/page/component/pages/demo2/index.js diff --git a/example2/page/component/pages/demo2/index.wxml b/test/page/component/pages/demo2/index.wxml similarity index 100% rename from example2/page/component/pages/demo2/index.wxml rename to test/page/component/pages/demo2/index.wxml diff --git a/example2/page/component/pages/demo2/index.wxss b/test/page/component/pages/demo2/index.wxss similarity index 100% rename from example2/page/component/pages/demo2/index.wxss rename to test/page/component/pages/demo2/index.wxss diff --git a/example2/page/component/pages/demo3/index.js b/test/page/component/pages/demo3/index.js similarity index 100% rename from example2/page/component/pages/demo3/index.js rename to test/page/component/pages/demo3/index.js diff --git a/example2/page/component/pages/demo3/index.wxml b/test/page/component/pages/demo3/index.wxml similarity index 100% rename from example2/page/component/pages/demo3/index.wxml rename to test/page/component/pages/demo3/index.wxml diff --git a/example2/page/component/pages/demo3/index.wxss b/test/page/component/pages/demo3/index.wxss similarity index 100% rename from example2/page/component/pages/demo3/index.wxss rename to test/page/component/pages/demo3/index.wxss diff --git a/example2/page/component/pages/demo4/index.js b/test/page/component/pages/demo4/index.js similarity index 100% rename from example2/page/component/pages/demo4/index.js rename to test/page/component/pages/demo4/index.js diff --git a/example2/page/component/pages/demo4/index.wxml b/test/page/component/pages/demo4/index.wxml similarity index 100% rename from example2/page/component/pages/demo4/index.wxml rename to test/page/component/pages/demo4/index.wxml diff --git a/example2/page/component/pages/demo4/index.wxss b/test/page/component/pages/demo4/index.wxss similarity index 100% rename from example2/page/component/pages/demo4/index.wxss rename to test/page/component/pages/demo4/index.wxss diff --git a/example2/page/component/pages/demo5/index.js b/test/page/component/pages/demo5/index.js similarity index 100% rename from example2/page/component/pages/demo5/index.js rename to test/page/component/pages/demo5/index.js diff --git a/example2/page/component/pages/demo5/index.json b/test/page/component/pages/demo5/index.json similarity index 100% rename from example2/page/component/pages/demo5/index.json rename to test/page/component/pages/demo5/index.json diff --git a/example2/page/component/pages/demo5/index.wxml b/test/page/component/pages/demo5/index.wxml similarity index 100% rename from example2/page/component/pages/demo5/index.wxml rename to test/page/component/pages/demo5/index.wxml diff --git a/example2/page/component/pages/demo5/index.wxss b/test/page/component/pages/demo5/index.wxss similarity index 100% rename from example2/page/component/pages/demo5/index.wxss rename to test/page/component/pages/demo5/index.wxss diff --git a/example2/page/component/pages/ellipse/index.js b/test/page/component/pages/ellipse/index.js similarity index 100% rename from example2/page/component/pages/ellipse/index.js rename to test/page/component/pages/ellipse/index.js diff --git a/example2/page/component/pages/ellipse/index.wxml b/test/page/component/pages/ellipse/index.wxml similarity index 100% rename from example2/page/component/pages/ellipse/index.wxml rename to test/page/component/pages/ellipse/index.wxml diff --git a/example2/page/component/pages/ellipse/index.wxss b/test/page/component/pages/ellipse/index.wxss similarity index 100% rename from example2/page/component/pages/ellipse/index.wxss rename to test/page/component/pages/ellipse/index.wxss diff --git a/example2/page/component/pages/img/1.jpg b/test/page/component/pages/img/1.jpg similarity index 100% rename from example2/page/component/pages/img/1.jpg rename to test/page/component/pages/img/1.jpg diff --git a/example2/page/component/pages/img/1.png b/test/page/component/pages/img/1.png similarity index 100% rename from example2/page/component/pages/img/1.png rename to test/page/component/pages/img/1.png diff --git a/example2/page/component/pages/img/index.js b/test/page/component/pages/img/index.js similarity index 100% rename from example2/page/component/pages/img/index.js rename to test/page/component/pages/img/index.js diff --git a/example2/page/component/pages/img/index.json b/test/page/component/pages/img/index.json similarity index 100% rename from example2/page/component/pages/img/index.json rename to test/page/component/pages/img/index.json diff --git a/example2/page/component/pages/img/index.wxml b/test/page/component/pages/img/index.wxml similarity index 100% rename from example2/page/component/pages/img/index.wxml rename to test/page/component/pages/img/index.wxml diff --git a/example2/page/component/pages/img/index.wxss b/test/page/component/pages/img/index.wxss similarity index 100% rename from example2/page/component/pages/img/index.wxss rename to test/page/component/pages/img/index.wxss diff --git a/example2/page/component/pages/line/index.js b/test/page/component/pages/line/index.js similarity index 100% rename from example2/page/component/pages/line/index.js rename to test/page/component/pages/line/index.js diff --git a/example2/page/component/pages/line/index.wxml b/test/page/component/pages/line/index.wxml similarity index 100% rename from example2/page/component/pages/line/index.wxml rename to test/page/component/pages/line/index.wxml diff --git a/example2/page/component/pages/line/index.wxss b/test/page/component/pages/line/index.wxss similarity index 100% rename from example2/page/component/pages/line/index.wxss rename to test/page/component/pages/line/index.wxss diff --git a/example2/page/component/pages/polygon/index.js b/test/page/component/pages/polygon/index.js similarity index 100% rename from example2/page/component/pages/polygon/index.js rename to test/page/component/pages/polygon/index.js diff --git a/example2/page/component/pages/polygon/index.wxml b/test/page/component/pages/polygon/index.wxml similarity index 100% rename from example2/page/component/pages/polygon/index.wxml rename to test/page/component/pages/polygon/index.wxml diff --git a/example2/page/component/pages/polygon/index.wxss b/test/page/component/pages/polygon/index.wxss similarity index 100% rename from example2/page/component/pages/polygon/index.wxss rename to test/page/component/pages/polygon/index.wxss diff --git a/example2/page/component/pages/rect/index.js b/test/page/component/pages/rect/index.js similarity index 100% rename from example2/page/component/pages/rect/index.js rename to test/page/component/pages/rect/index.js diff --git a/example2/page/component/pages/rect/index.wxml b/test/page/component/pages/rect/index.wxml similarity index 100% rename from example2/page/component/pages/rect/index.wxml rename to test/page/component/pages/rect/index.wxml diff --git a/example2/page/component/pages/rect/index.wxss b/test/page/component/pages/rect/index.wxss similarity index 100% rename from example2/page/component/pages/rect/index.wxss rename to test/page/component/pages/rect/index.wxss diff --git a/example2/page/component/pages/text/index.js b/test/page/component/pages/text/index.js similarity index 100% rename from example2/page/component/pages/text/index.js rename to test/page/component/pages/text/index.js diff --git a/example2/page/component/pages/text/index.wxml b/test/page/component/pages/text/index.wxml similarity index 100% rename from example2/page/component/pages/text/index.wxml rename to test/page/component/pages/text/index.wxml diff --git a/example2/page/component/pages/text/index.wxss b/test/page/component/pages/text/index.wxss similarity index 100% rename from example2/page/component/pages/text/index.wxss rename to test/page/component/pages/text/index.wxss diff --git a/example2/page/component/resources/kind/canvas.png b/test/page/component/resources/kind/canvas.png similarity index 100% rename from example2/page/component/resources/kind/canvas.png rename to test/page/component/resources/kind/canvas.png diff --git a/example2/page/component/resources/kind/content.png b/test/page/component/resources/kind/content.png similarity index 100% rename from example2/page/component/resources/kind/content.png rename to test/page/component/resources/kind/content.png diff --git a/example2/page/component/resources/kind/form.png b/test/page/component/resources/kind/form.png similarity index 100% rename from example2/page/component/resources/kind/form.png rename to test/page/component/resources/kind/form.png diff --git a/example2/page/component/resources/kind/logo.png b/test/page/component/resources/kind/logo.png similarity index 100% rename from example2/page/component/resources/kind/logo.png rename to test/page/component/resources/kind/logo.png diff --git a/example2/page/component/resources/kind/map.png b/test/page/component/resources/kind/map.png similarity index 100% rename from example2/page/component/resources/kind/map.png rename to test/page/component/resources/kind/map.png diff --git a/example2/page/component/resources/kind/media.png b/test/page/component/resources/kind/media.png similarity index 100% rename from example2/page/component/resources/kind/media.png rename to test/page/component/resources/kind/media.png diff --git a/example2/page/component/resources/kind/nav.png b/test/page/component/resources/kind/nav.png similarity index 100% rename from example2/page/component/resources/kind/nav.png rename to test/page/component/resources/kind/nav.png diff --git a/example2/page/component/resources/kind/view.png b/test/page/component/resources/kind/view.png similarity index 100% rename from example2/page/component/resources/kind/view.png rename to test/page/component/resources/kind/view.png diff --git a/example2/page/component/resources/kind/wxDrawS.png b/test/page/component/resources/kind/wxDrawS.png similarity index 100% rename from example2/page/component/resources/kind/wxDrawS.png rename to test/page/component/resources/kind/wxDrawS.png diff --git a/example2/page/component/resources/pic/1.jpg b/test/page/component/resources/pic/1.jpg similarity index 100% rename from example2/page/component/resources/pic/1.jpg rename to test/page/component/resources/pic/1.jpg diff --git a/example2/page/component/resources/pic/2.jpg b/test/page/component/resources/pic/2.jpg similarity index 100% rename from example2/page/component/resources/pic/2.jpg rename to test/page/component/resources/pic/2.jpg diff --git a/example2/page/rec/index.js b/test/page/rec/index.js similarity index 100% rename from example2/page/rec/index.js rename to test/page/rec/index.js diff --git a/example2/page/rec/index.json b/test/page/rec/index.json similarity index 100% rename from example2/page/rec/index.json rename to test/page/rec/index.json diff --git a/example2/page/rec/index.wxml b/test/page/rec/index.wxml similarity index 100% rename from example2/page/rec/index.wxml rename to test/page/rec/index.wxml diff --git a/example2/page/rec/index.wxss b/test/page/rec/index.wxss similarity index 100% rename from example2/page/rec/index.wxss rename to test/page/rec/index.wxss diff --git a/example2/page/rect/index.js b/test/page/rect/index.js similarity index 100% rename from example2/page/rect/index.js rename to test/page/rect/index.js diff --git a/example2/page/rect/index.json b/test/page/rect/index.json similarity index 100% rename from example2/page/rect/index.json rename to test/page/rect/index.json diff --git a/example2/page/rect/index.wxml b/test/page/rect/index.wxml similarity index 100% rename from example2/page/rect/index.wxml rename to test/page/rect/index.wxml diff --git a/example2/page/rect/index.wxss b/test/page/rect/index.wxss similarity index 100% rename from example2/page/rect/index.wxss rename to test/page/rect/index.wxss diff --git a/example2/project.config.json b/test/project.config.json similarity index 100% rename from example2/project.config.json rename to test/project.config.json diff --git a/example2/util/util.js b/test/util/util.js similarity index 100% rename from example2/util/util.js rename to test/util/util.js diff --git a/example2/util/wxdraw.js b/test/util/wxdraw.js similarity index 99% rename from example2/util/wxdraw.js rename to test/util/wxdraw.js index 4bb1488..6fc13cd 100644 --- a/example2/util/wxdraw.js +++ b/test/util/wxdraw.js @@ -2211,7 +2211,7 @@ Circle.prototype = _extends({ * @Author: Thunderball.Wu * @Date: 2017-10-23 19:04:04 * @Last Modified by: Thunderball.Wu - * @Last Modified time: 2017-11-29 10:12:31 + * @Last Modified time: 2018-01-14 22:20:08 * 分离开 */ @@ -2301,7 +2301,7 @@ Rect.prototype = _extends({ _points2.push(this.getPointTodraw(item[0], item[1], origin)); }, this); - this._chengeCenter(origin); + this._changeCenter(origin); this._Points = matrixToarray(_points); //除掉矩阵多余的部分 this._detectPoints = matrixToarray(_points2); //除掉矩阵多余的部分 // //console.log(this._Points); @@ -2431,8 +2431,9 @@ Rect.prototype = _extends({ // this.getMax();//拿到边界点 } }, - _chengeCenter: function _chengeCenter(origin) { - console.log(this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0], this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0]); + _changeCenter: function _changeCenter(origin) { + + // console.log(this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0],this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0]) // this.Option.x = this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0] // this.Option.y = this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0] } diff --git a/example2/util/wxdraw.min.js b/test/util/wxdraw.min.js similarity index 100% rename from example2/util/wxdraw.min.js rename to test/util/wxdraw.min.js diff --git a/wxDraw/dist/wxdraw.js b/wxDraw/dist/wxdraw.js index 4bb1488..6fc13cd 100644 --- a/wxDraw/dist/wxdraw.js +++ b/wxDraw/dist/wxdraw.js @@ -2211,7 +2211,7 @@ Circle.prototype = _extends({ * @Author: Thunderball.Wu * @Date: 2017-10-23 19:04:04 * @Last Modified by: Thunderball.Wu - * @Last Modified time: 2017-11-29 10:12:31 + * @Last Modified time: 2018-01-14 22:20:08 * 分离开 */ @@ -2301,7 +2301,7 @@ Rect.prototype = _extends({ _points2.push(this.getPointTodraw(item[0], item[1], origin)); }, this); - this._chengeCenter(origin); + this._changeCenter(origin); this._Points = matrixToarray(_points); //除掉矩阵多余的部分 this._detectPoints = matrixToarray(_points2); //除掉矩阵多余的部分 // //console.log(this._Points); @@ -2431,8 +2431,9 @@ Rect.prototype = _extends({ // this.getMax();//拿到边界点 } }, - _chengeCenter: function _chengeCenter(origin) { - console.log(this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0], this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0]); + _changeCenter: function _changeCenter(origin) { + + // console.log(this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0],this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0]) // this.Option.x = this.getPointTodraw(this.Option.x, this.Option.y, origin)[0][0] // this.Option.y = this.getPointTodraw(this.Option.x, this.Option.y, origin)[1][0] } diff --git a/wxDraw/dist/wxdraw.min.js b/wxDraw/dist/wxdraw.min.js index de69431..6d0da1d 100644 --- a/wxDraw/dist/wxdraw.min.js +++ b/wxDraw/dist/wxdraw.min.js @@ -1,2 +1,2 @@ -"use strict";function Line(t){var i=_extends({strokeStyle:"#000000",points:[[1,2],[23,45],[2,45],[230,205]]},commonAttr()),n=_extends({smooth:!0},commonUnAttr()),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this.max={maxX:null,maxY:null,minX:null,minY:null},this.massCenter=this.genMassCenter(this.Option.points),this.posPoints=this.genPointsPositiveLoc(),this.oriPoints=this.Option.points,this._Points=this.Option.points,this._CurvePoints=this.Option.points,this.detectPoints=this.getDetectPoints(),this.getMax(),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="line",this._canRotateOrigin=!0}function Watch(){this.startTime=0,this.running=!1,this.goesBytime=0,this.goesBy=void 0,this.DEFAULT_ELASTIC=2}function genExe(t,i,n){if(specialAtrr[i])return specialAtrr[i].getIncre(specialAtrr[i].get(n.Shape.Option[i]),t,n);if(!isNaN(Number(t)))return n.Shape.Option[i]||0===n.Shape.Option[i]?parseFloat(t)-parseFloat(n.Shape.Option[i]):parseFloat(t)-parseFloat(n.Shape[specialOption[n.type][i]][i]);if(0==t.indexOf("+=")){return t.split("=")[1]}if(0==t.indexOf("-=")){return-1*t.split("=")[1]}}function fakeAnimationFrame(t){var i;setTimeout(function(){i=+new Date,t(i)},16)}function WxDraw(t,i,n,s,e){this.canvas=t,this.wcid=guid(),this.store=new Store,this.bus=new eventBus,this.animation=new Animation(this.bus),this.x=i,this.y=n,this.w=s,this.h=e,this.bus.add("addAnimation",this,this.addAnimationFrag),this.bus.add("update",this,this.update),this.bus.add("getDetectedLayers",this,this.getDetectedLayers),this.bus.add("clearDetectedLayers",this,this.clearDetectedLayers),this.bus.add("updateLayer",this,this.updateLayer),this.bus.add("destory",this,this.destroy),this.animation.start(),Shape.bus=this.bus,this.detectedLayers=[]}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,i){for(var n=0;n0&&(this.turnColorLock(!0),i=t.createLinearGradient.apply(t,toConsumableArray(this.getGradientOption(n).lg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),this.UnOption.needGra&&"circle"==this.UnOption.needGra&&this.UnOption.gra&&this.UnOption.gra.length>0&&(this.turnColorLock(!0),i=t.createCircularGradient.apply(t,toConsumableArray(this.getGradientOption(n).cg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),(!this._colorLock||this.needGra&&"no"==his.UnOption.needGra)&&t.setFillStyle(this.Option.fillStyle),"miter"==this.UnOption.lineJoin&&t.setMiterLimit(this.Option.miterLimit),t.setStrokeStyle(this.Option.strokeStyle),t.setLineWidth(this.Option.lineWidth),t.setGlobalAlpha(this.Option.opacity),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this.UnOption.isLineDash&&t.setLineDash&&(this.Option.lineDash instanceof Array||(this.Option.lineDash[0]=objToArray(this.Option.lineDash[0])),t.setLineDash(this.Option.lineDash[0],this.Option.lineDash[1]))},stroke:function(t){return"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.stroke(),void t.restore())},fill:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(t.save(),t.setGlobalAlpha(this.Option.opacity),t.beginPath(),t.setFontSize(this.Option.fontSize),t.setTextAlign(this.UnOption.align),t.setTextBaseline(this.UnOption.textBaseline),t.setFillStyle(this.Option.fillStyle),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this._draw(t),t.closePath(),t.restore(),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!1,this._draw(t),this.setCommonstyle(t),t.fill(),void t.restore())},mixDraw:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.fill(),t.stroke(),void t.restore())},turnColorLock:function(t){this._colorLock=!!t},getGradientOption:function(t){return{circle:"circle"==t?{lg:[this.Option.x-this.Option.r,0,this.Option.x+this.Option.r,0],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},rect:"rect"==t?{lg:[this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2,this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow(this.Option.w/2,2)+Math.pow(this.Option.h/2,2))]}:{},polygon:"polygon"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},cshape:"cshape"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.massCenter.x,this.massCenter.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{},ellipse:"ellipse"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{}}[t]},_drawHelperPoints:function(t){t.save(),t.setFillStyle("#F34739"),t.beginPath(),this._detectPoints?this._detectPoints.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}):this._Points.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}),t.closePath(),t.fill(),t.restore()},closeRotateOrigin:function(){this._canRotateOrigin=!1}},Polygon=function(t){var i=_extends({x:10,y:10,r:10,sides:7},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(this.oriPoints),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="polygon",this._canRotateOrigin=!0};Polygon.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;sthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Ellipse=function(t){var i=_extends({x:10,y:10,a:10,b:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="ellipse",this._canRotateOrigin=!0};Ellipse.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;s<100;++s)t.push([this.Option.x+this.Option.a/2*Math.sin(n),this.Option.y-this.Option.b/2*Math.cos(n)]),i.push([this.Option.x+(this.Option.a/2+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.b+this.Option.lineWidth)/2*Math.cos(n)]),n+=2*Math.PI/100;this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var baseline=function(t,i){return{normal:2,bottom:-i/2,middle:0,top:i/2}[t]},align=function(t,i){return{left:i/2,center:0,right:-i/2}[t]},Text=function(t){t.text||(t.text="no text");var i={x:100,y:200,fontSize:12,shadow:{offsetX:5,offsetY:5,blur:5,color:"#000000"},fillStyle:"#000000",strokeStyle:"#000000",rotate:0,opacity:1},n={textBaseline:"normal",align:"left",needShadow:!1};this.text=t.text,this.Option=util.extend(t,i),this.UnOption=util.extend(t,n),this.boxOption={x:0,y:0},this.boxOriPoints=[],this.boxPoints=[],this.rotateOrigin=null,this.offset={x:0,y:0},this._offsetX=0,this._offsetY=0,this.getOriPoints(),this.getPoints(),this._dirty=!0,this._type="text",this._canRotateOrigin=!0};Text.prototype=_extends({getOriPoints:function(){for(var t=[],i=/^[\u4e00-\u9fa5]/,n=String(this.text).length,s=0,e=this.Option.fontSize,o=0;oi!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.boxOption.x=t,this.boxOption.y=i,this.Option.x=t-this.offset.x,this.Option.y=i-this.offset.y,this._dirty=!0},detected:function(t,i){return this._offsetX=this.boxOption.x-t,this._offsetY=this.boxOption.y-i,!!this._pnpolyTest(t,i)&&(this._isChoosed=!0,!0)},_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints()),t.save(),this.rotateOrigin?(t.translate(this.rotateOrigin[0],this.rotateOrigin[1]),t.rotate(this.Option.rotate),t.fillText(this.text,this.boxOption.x-this.rotateOrigin[0]-this.offset.x,this.boxOption.y-this.rotateOrigin[1]-this.offset.y)):(t.translate(this.boxOption.x,this.boxOption.y),t.rotate(this.Option.rotate),t.fillText(this.text,-this.offset.x,-this.offset.y)),t.restore(),this._dirty=!1},moveDetect:function(t,i){1==this._isChoosed&&this.move(t+this._offsetX,i+this._offsetY)},updateText:function(t){this.text=t,this._dirty=!0}},commonMethods);var getCurvePoints=function(t,i,n,s){i=void 0!==i?i:.5,n=n||!1,s=s||16;var e,o,h,r,a,u,p,c,l,m,f,x,d,O=[],g=[];for(O=t.slice(0),n?(O.unshift(t[t.length-1]),O.unshift(t[t.length-1]),O.push(t[0])):(O.unshift(t[1]),O.push(t[t.length-1])),d=1;dthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Circle=function(t){var i=_extends({x:10,y:10,r:10,sA:0,eA:2*Math.PI},commonAttr()),n=_extends({},commonUnAttr(),{counterclockwise:!1,closePath:!1}),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.fullCircle=!0,this._colorLock=!1,this._canRotateOrigin=!0,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="circle"};Circle.prototype=_extends({getOriPoints:function(){var t=[],i=[],n=this.Option.sA||0,s=this.Option.eA||2*Math.PI,e=s-n;e>=2*Math.PI?this.fullCircle=!0:this.fullCircle=!1;for(var o=0;o<=100;++o)n=this.Option.sA+o*e/100,t.push([this.Option.x+this.Option.r*Math.sin(n),this.Option.y-this.Option.r*Math.cos(n)]),i.push([this.Option.x+(this.Option.r+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.r+this.Option.lineWidth/2)*Math.cos(n)]);t.unshift([this.Option.x,this.Option.y]),i.unshift([this.Option.x,this.Option.y]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this.detectOriPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Rect=function(t){var i=_extends({x:10,y:10,w:10,h:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=util.extend({},n),this.UnOption=s,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.bus=null,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="rect",this._rotateOriginOver=!1,this._canRotateOrigin=!0};Rect.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.createPath(t),this._dirty=!1},getOriPoints:function(){var t=[],i=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._chengeCenter(n),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return console.log("检测方块",t,i),t>this.max.minX&&tthis.max.minY&&ithis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=a>i&&t<(r-o)*(i-h)/(a-h)+o&&(n=!n)}return n}},commonMethods);var Img=function(t){var i={x:10,y:10,w:10,h:10,rotate:0,opacity:1},n={file:""},s=util.extend(t,i),e=util.extend(t,n);this.Option=util.extend({},s),this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="image",this._canRotateOrigin=!0};Img.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.drawImage(t),this._dirty=!1},getOriPoints:function(){var t=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),this.oriPoints=t,this.detectOriPoints=t},getPoints:function(){var t=[],i=null;return i=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(n){ -t.push(this.getPointTodraw(n[0],n[1],i))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(t),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return t>this.max.minX&&tthis.max.minY&&i1&&!isNaN(t)?t:0}return this.goesBy},isRunning:function(){return this.running},reset:function(){this.goesBy=0}};var AnimationTimer=function(t,i){void 0!==t&&(this.duration=t),void 0!==i&&(this.timeFunc=i),this.watch=new Watch};AnimationTimer.prototype={start:function(){this.watch.start()},stop:function(){this.watch.stop()},getGoesByTime:function(){var t=this.watch.getGoesByTime(),i=t/this.duration;if(this.watch.running)return this.timeFunc?t*(EasingFunctions[this.timeFunc](i)/i):t},isOver:function(){return this.watch.getGoesByTime()>this.duration}};var specialOption={cshape:{x:"massCenter",y:"massCenter"},line:{x:"massCenter",y:"massCenter"}},specialAtrr={fillStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},strokeStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},shadow:{get:function(t){return{offsetX:t.offsetX,offsetY:t.offsetY,blur:t.blur,color:hex2rgb(t.color)}},set:function(t,i,n){var s=[t.color.r+Math.floor(i.color.r*n),t.color.g+Math.floor(i.color.g*n),t.color.b+Math.floor(i.color.b*n)],e="#"+rgb2hex.apply(void 0,s);return{offsetX:t.offsetX+i.offsetX*n,offsetY:t.offsetY+i.offsetY*n,blur:t.blur+i.blur*n,color:e}},getIncre:function(t,i,n){var s=util.extend(i,n.Shape.Option.shadow),e=hex2rgb(s.color),o={r:e.r-t.color.r,g:e.g-t.color.g,b:e.b-t.color.b};return{offsetX:(s.offsetX?s.offsetX:5)-t.offsetX,offsetY:(s.offsetY?s.offsetY:5)-t.offsetY,blur:(s.blur?s.blur:5)-t.blur,color:o}}},lineDash:{get:function(t){return t},set:function(t,i,n){return[[t[0][0]+i[0][0]*n,t[0][1]+i[0][1]*n],t[1][1]+i[1][1]*n]},getIncre:function(t,i,n){return[[-t[0][0]+i[0][0],-t[0][1]+i[0][1]],-t[1][1]+i[1][1]]}}},AnimationFrag=function(t,i,n,s,e){var o={onStart:function(){},onLooping:function(){},onEnd:function(){},duration:1e3,easing:"linear"},h=util.extend(s,o);this.object=t,this.source=0,this.genFlag=!1,this.bus=e,this.complete=!1,this.running=!1,this.started=!1,this.duration=h.duration,this.atrribute=i,this.atrributeList=[],"object"==(void 0===i?"undefined":_typeof(i))?(this.genFlag=!0,this.genAtrributeList(i)):(this.incre=genExe(n,i,t),this.exe=n),this.timer=new AnimationTimer(h.duration,h.easing),this.oriOption=h,this.endCallFrag=null,this.onEnd=h.onEnd,this.onLooping=h.onLooping,this.onStart=h.onStart,this._aniWrapbus=null};AnimationFrag.prototype={updateAnimation:function(){return!this.complete&&(this.timer.isOver()?(this.onEnd(),this.complete=!0,this.running=!1,this._aniWrapbus.dispatch("fragAniOver","no","me"),!1):void(this.started||this.complete?(this.onLooping(),this.updateAtrribute()):(this.genFlag||(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute]))),this.started=!0,this.running=!0,this.onStart(),this.timer.start())))},updateAtrribute:function(){this.genFlag?(this.atrributeList.forEach(function(t){this.object.Shape.Option[t.attr]||0==this.object.Shape.Option[t.attr]?specialAtrr[t.attr]?this.object.Shape.Option[t.attr]=specialAtrr[t.attr].set(t.source,t.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][t.attr]][t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration},this),this.object.Shape._dirty=!0):(this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?specialAtrr[this.atrribute]?this.object.Shape.Option[this.atrribute]=specialAtrr[this.atrribute].set(this.source,this.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration,this.object.Shape._dirty=!0)},genAtrributeList:function(t){var i=Object.keys(t),n=this;this.atrributeList=[],i.forEach(function(i){var s=this.object.Shape.Option[i]||0==this.object.Shape.Option[i]?this.object.Shape.Option[i]:this.object.Shape[specialOption[this.object.type][i]][i];specialAtrr[i]&&(s=specialAtrr[i].get(this.object.Shape.Option[i])),n.atrributeList.push({attr:i,incre:genExe(t[i],i,n.object),source:s})},this)},updateSourceAndtarget:function(){this.genFlag?this.genAtrributeList(this.atrribute):(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute])),this.incre=genExe(this.exe,this.atrribute,this.object))},addWrapBus:function(t){this._aniWrapbus=t},restart:function(){this.complete=!1,this.running=!1,this.started=!1,this.timer=new AnimationTimer(this.oriOption.duration,this.oriOption.easing)}};var eventBus=function(){this.eventList=[]};eventBus.prototype={add:function(t,i,n){this.eventList.length?(this.eventList.forEach(function(i){if(i.name==t)return i.thingsList.push(n),!1},this),this.eventList.push({name:t,scope:i,thingsList:[n]})):this.eventList.push({name:t,scope:i,thingsList:[n]})},dispatch:function(t,i){var n=arguments;if(arguments.length<2)return!1;var s=Array.prototype.slice.call(n,2);this.eventList.forEach(function(n){n.name===t&&n.thingsList.forEach(function(t){"no"!==i?t.call.apply(t,[i].concat(toConsumableArray(s))):t.call.apply(t,[n.scope].concat(toConsumableArray(s)))})})},destroy:function(){}};var AniFragWrap=function(t,i,n){this.runing=!1,this.stoped=!1,this.started=!1,this.fragStore=[],this.animationPick=0,this.bus=t,this.aniFraBus=new eventBus,this.aniFraBus.add("fragAniOver",this,this.getAniOver),this.overAni=[],this.aniFragListId=i,this.loop=!1,this.loopTimes=!1,this.looped=0,this.object=n,this.oriOption=util.extend(n.Shape.Option,n.Shape.Option),this.oriUnOption=util.extend(n.Shape.Option,n.Shape.UnOption),this.endCallWraper=null,this.firstTime=!0};AniFragWrap.prototype={updateFrag:function(t){t.addWrapBus(this.aniFraBus),this.fragStore.length?(this.fragStore[this.fragStore.length-1].endCallFrag=t,this.fragStore.push(t)):this.fragStore.push(t)},exeAnimate:function(){if(this.object.disableDrag(),this.firstTime&&(this.firstTime=!1,this.oriOption=util.extend(this.object.Shape.Option,this.object.Shape.Option),this.oriUnOption=util.extend(this.object.Shape.Option,this.object.Shape.UnOption)),this.stoped)return this.endCallWraper?this.endCallWraper.exeAnimate():this.object.restoreDrag(),!1;this.fragStore[this.animationPick]&&this.fragStore[this.animationPick].updateAnimation()},getAniOver:function(t){if(this.overAni.push(t),this.overAni.length==this.fragStore.length){if(this.loop){if(this.loopTimes&&this.looped<=this.loopTimes&&this.looped++,this.loopTimes&&this.looped>this.loopTimes)return this.stop(),!1;this.restart()}else this.stop();return!1}this.animationPick++,this.fragStore[this.animationPick].updateSourceAndtarget()},restart:function(){this.object.restoreOption(this.oriOption),this.object.restoreOption(this.oriUnOption),this.overAni=[],this.animationPick=0,this.fragStore.forEach(function(t){t.restart()},this),this.started=!1,this.stoped=!1},stop:function(){this.stoped=!0,this.bus.dispatch("wraperAniComplete","no",this.aniFragListId,this.object.Shapeid,this.object)},resume:function(){},setLoop:function(t,i){this.loop=t||!1,this.loopTimes=i||!1,this.looped=1}};var Shape=function(t,i,n,s){this.draggable=!!s,this.strokeOrfill=n||"fill",this.type=t,this.Shape=new shapeTypes[t](i),this.draggable&&this.Shape.closeRotateOrigin(),this.AnimationTimer=new AnimationTimer,this.animtionFragList=[],this.bus=null,this.Shapeid="sp"+guid(),this.animationStart=!1,this.aniFragListId="",this.aniFragWraper=null,this._oldDrag=this.draggable,this._layerIndex=0,this._getChoosed=!1,this._eventStore={tap:[],touchstart:[],touchmove:[],touchend:[],longpress:[],drag:[]},this._nowType="tap",this._canRotateOrigin=!0};Shape.prototype={updateBus:function(t){this.bus=t},paint:function(t){switch(this.strokeOrfill){case"fill":this.Shape.fill(t);break;case"stroke":this.Shape.stroke(t);break;case"mix":this.Shape.mixDraw(t);break;case!0:this.Shape.fill(t)}},detect:function(t,i,n){this.Shape.detected(t,i)?(this._nowType=n,this.bus.dispatch("getDetectedLayers","no",this._layerIndex)):this.bus.dispatch("getDetectedLayers","no",-1)},moveDetect:function(t,i){this._getChoosed&&this._eventStore.touchmove.forEach(function(t){t(this)},this),this.draggable&&this._getChoosed&&(this._eventStore.drag.forEach(function(t){t(this)},this),this.Shape.moveDetect(t,i))},upDetect:function(){this._getChoosed&&(this.bus.dispatch("clearDetectedLayers","no"),this._eventStore.touchend.forEach(function(t){t(this)},this),this.Shape.upDetect(),this._getChoosed=!1)},animate:function(t,i,n){this.aniFragListId||(this.aniFragListId="af"+guid(),this.aniFragWraper=new AniFragWrap(this.bus,this.aniFragListId,this));var s=null;return s="object"==(void 0===t?"undefined":_typeof(t))?new AnimationFrag(this,t,"no",arguments[1],this.bus):new AnimationFrag(this,t,arguments[1],arguments[2],this.bus),this.aniFragWraper.updateFrag(s),this},start:function(t){this.animationStart=!0,this.aniFragWraper&&(!0===t&&this.aniFragWraper.setLoop(t),"number"==typeof t&&this.aniFragWraper.setLoop(!0,t),this.bus.dispatch("addAnimation","no",this.aniFragWraper,this.Shapeid),this.aniFragListId="",this.aniFragWraper=null)},updateOption:function(t){return this.Shape.bus||(this.Shape.bus=this.bus),this.Shape.updateOption(t),this},restoreOption:function(t){this.Shape.restoreOption(t)},setOrigin:function(t){return this.Shape.setRotateOrigin(t),this},_updateLayer:function(t){this._layerIndex=t},updateLayer:function(t){this.bus.dispatch("updateLayer","no",this,this._layerIndex,t)},getChoosed:function(){this._getChoosed=!0,this._eventStore[this._nowType].forEach(function(t){t(this)},this)},destroy:function(){this.bus.dispatch("destory","no",this._layerIndex,this.Shapeid),this.bus.dispatch("destoryAnimation","no",this._layerIndex,this.Shapeid)},restoreDrag:function(){this.draggable=this._oldDrag},disableDrag:function(){this.draggable=!1},bind:function(t,i){void 0!==this._eventStore[t]&&this._eventStore[t].push(i)},unbind:function(t,i){var n=-1;void 0!==this._eventStore[t]&&this._eventStore[t].forEach(function(t,i){n=i}),-1!==n&&this._eventStore[t].splice(n,1)},clone:function(){var t={};return"text"==this.type&&(t={text:this.Shape.text}),new Shape(this.type,_extends({},this.Shape.Option,this.Shape.UnOption,t),this.strokeOrfill,this.draggable)},updateText:function(t){if("text"!=this.type)return!1;this.Shape.updateText(t)}};var shapeTypes={circle:function(t){return new Circle(t)},rect:function(t){return new Rect(t)},polygon:function(t){return new Polygon(t)},cshape:function(t){return new Cshape(t)},line:function(t){return new Line(t)},ellipse:function(t){return new Ellipse(t)},text:function(t){return new Text(t)},image:function(t){return new Img(t)}},AnimationFrame=function(){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:fakeAnimationFrame},animationFrame=AnimationFrame(),Animation=function(t){this.running=!1,this.paused=!0,this.bus=t,this.animationFragStore={},this.animationCompleteList=[],this.wraperAniCompleteOb={},this.bus.add("animationComplete",this,this.animationComplete),this.bus.add("wraperAniComplete",this,this.wraperAniComplete),this.bus.add("destoryAnimation",this,this.destroyAnimation),this.bus.add("clearAnimation",this,this.clearAnimation)};Animation.prototype={start:function(){this.running=!0,this.loopAnimation()},loopAnimation:function(){function t(){animationFrame(t),i.running&&i.updateStep()}var i=this;animationFrame(t)},updateStep:function(){Object.keys(this.animationFragStore).forEach(function(t){this.animationFragStore[t][0].exeAnimate()},this),this.bus.dispatch("update","no")},animationComplete:function(t){this.animationCompleteList.push(t),Object.keys(this.wraperAniCompleteOb).length===Object.keys(this.animationFragStore).length&&(this.running=!1)},wraperAniComplete:function(t,i,n){this.wraperAniCompleteOb[i]?this.wraperAniCompleteOb[i].push(t):this.wraperAniCompleteOb[i]=[t],this.wraperAniCompleteOb[i].length==this.animationFragStore[i].length&&(n.restoreDrag(),this.bus.dispatch("animationComplete","no",i))},destroyAnimation:function(t,i){delete this.animationFragStore[i]},clearAnimation:function(){this.animationFragStore={},this.running=!1}},WxDraw.prototype={add:function(t){t.updateBus(this.bus),t._updateLayer(this.store.getLength()),this.store.add(t)},draw:function(){this.store.store.forEach(function(t){t.paint(this.canvas)},this)},tapDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"tap")},this)},longpressDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"longpress")},this)},touchstartDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.detect(i.x,i.y,"touchstart")},this)},touchendDetect:function(t){this.store.store.forEach(function(t){t.upDetect()},this)},touchmoveDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.moveDetect(i.x,i.y)},this),this.draw(),this.canvas.draw()},getLoc:function(t,i){return{x:t-this.x>0?t-this.x>this.w?this.w:t-this.x:0,y:i-this.y>0?i-this.y>this.h?this.h:i-this.y:0}},update:function(){this.draw(),this.canvas.draw()},AnimationCenter:function(){},addAnimationFrag:function(t,i){this.animation.animationFragStore[i]?(this.animation.animationFragStore[i][this.animation.animationFragStore[i].length-1].endCallWraper=t,this.animation.animationFragStore[i].push(t)):this.animation.animationFragStore[i]=[t]},getDetectedLayers:function(t){this.detectedLayers.push(t),this.detectedLayers.length==this.store.getLength()&&-1!=Math.max.apply(null,this.detectedLayers)&&this.store.find(Math.max.apply(null,this.detectedLayers)).getChoosed(),this.detectedLayers.length==this.store.getLength()&&-1==Math.max.apply(null,this.detectedLayers)&&this.clearDetectedLayers()},clearDetectedLayers:function(){this.detectedLayers=[]},updateLayer:function(t,i,n){var s=0,e=void 0;s=n,"string"==typeof n&&(e=0===n.indexOf("-")?-1:0===n.indexOf("+")&&1),s=e?i+e*parseInt(-1==e?n.split("-")[1]:n.split("+")[1]):parseInt(n),s>=this.store.store.length-1&&(s=this.store.store.length-1),s<=0&&(s=0),this.store.changeIndex(t,i,s),this._updateLayer()},destroy:function(t){this.store.store.splice(t,1)},_updateLayer:function(){this.store.store.forEach(function(t,i){t._updateLayer(i)})},clear:function(){this.canvas.clearActions(),this.store.clear(),this.canvas=null,this.bus.dispatch("clearAnimation","no","no")}};var wxDraw={wxDraw:WxDraw,Shape:Shape,AnimationFrame:AnimationFrame()};module.exports=wxDraw; +"use strict";function Line(t){var i=_extends({strokeStyle:"#000000",points:[[1,2],[23,45],[2,45],[230,205]]},commonAttr()),n=_extends({smooth:!0},commonUnAttr()),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this.max={maxX:null,maxY:null,minX:null,minY:null},this.massCenter=this.genMassCenter(this.Option.points),this.posPoints=this.genPointsPositiveLoc(),this.oriPoints=this.Option.points,this._Points=this.Option.points,this._CurvePoints=this.Option.points,this.detectPoints=this.getDetectPoints(),this.getMax(),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="line",this._canRotateOrigin=!0}function Watch(){this.startTime=0,this.running=!1,this.goesBytime=0,this.goesBy=void 0,this.DEFAULT_ELASTIC=2}function genExe(t,i,n){if(specialAtrr[i])return specialAtrr[i].getIncre(specialAtrr[i].get(n.Shape.Option[i]),t,n);if(!isNaN(Number(t)))return n.Shape.Option[i]||0===n.Shape.Option[i]?parseFloat(t)-parseFloat(n.Shape.Option[i]):parseFloat(t)-parseFloat(n.Shape[specialOption[n.type][i]][i]);if(0==t.indexOf("+=")){return t.split("=")[1]}if(0==t.indexOf("-=")){return-1*t.split("=")[1]}}function fakeAnimationFrame(t){var i;setTimeout(function(){i=+new Date,t(i)},16)}function WxDraw(t,i,n,s,e){this.canvas=t,this.wcid=guid(),this.store=new Store,this.bus=new eventBus,this.animation=new Animation(this.bus),this.x=i,this.y=n,this.w=s,this.h=e,this.bus.add("addAnimation",this,this.addAnimationFrag),this.bus.add("update",this,this.update),this.bus.add("getDetectedLayers",this,this.getDetectedLayers),this.bus.add("clearDetectedLayers",this,this.clearDetectedLayers),this.bus.add("updateLayer",this,this.updateLayer),this.bus.add("destory",this,this.destroy),this.animation.start(),Shape.bus=this.bus,this.detectedLayers=[]}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,i){for(var n=0;n0&&(this.turnColorLock(!0),i=t.createLinearGradient.apply(t,toConsumableArray(this.getGradientOption(n).lg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),this.UnOption.needGra&&"circle"==this.UnOption.needGra&&this.UnOption.gra&&this.UnOption.gra.length>0&&(this.turnColorLock(!0),i=t.createCircularGradient.apply(t,toConsumableArray(this.getGradientOption(n).cg)),this.UnOption.gra.forEach(function(t){i.addColorStop(t[0],t[1])},this),t.setFillStyle(i)),(!this._colorLock||this.needGra&&"no"==his.UnOption.needGra)&&t.setFillStyle(this.Option.fillStyle),"miter"==this.UnOption.lineJoin&&t.setMiterLimit(this.Option.miterLimit),t.setStrokeStyle(this.Option.strokeStyle),t.setLineWidth(this.Option.lineWidth),t.setGlobalAlpha(this.Option.opacity),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this.UnOption.isLineDash&&t.setLineDash&&(this.Option.lineDash instanceof Array||(this.Option.lineDash[0]=objToArray(this.Option.lineDash[0])),t.setLineDash(this.Option.lineDash[0],this.Option.lineDash[1]))},stroke:function(t){return"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.stroke(),void t.restore())},fill:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(t.save(),t.setGlobalAlpha(this.Option.opacity),t.beginPath(),t.setFontSize(this.Option.fontSize),t.setTextAlign(this.UnOption.align),t.setTextBaseline(this.UnOption.textBaseline),t.setFillStyle(this.Option.fillStyle),this.UnOption.needShadow&&this.Option.shadow&&t.setShadow(this.Option.shadow.offsetX,this.Option.shadow.offsetY,this.Option.shadow.blur,this.Option.shadow.color),this._draw(t),t.closePath(),t.restore(),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!1,this._draw(t),this.setCommonstyle(t),t.fill(),void t.restore())},mixDraw:function(t){return"line"==this._type?(this.stroke(t),!1):"text"==this._type?(this.fill(t),!1):"image"==this._type?(this._draw(t),!1):(t.save(),this._drawLine=!0,this._draw(t),this.setCommonstyle(t),t.fill(),t.stroke(),void t.restore())},turnColorLock:function(t){this._colorLock=!!t},getGradientOption:function(t){return{circle:"circle"==t?{lg:[this.Option.x-this.Option.r,0,this.Option.x+this.Option.r,0],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},rect:"rect"==t?{lg:[this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2,this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow(this.Option.w/2,2)+Math.pow(this.Option.h/2,2))]}:{},polygon:"polygon"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,this.Option.r]}:{},cshape:"cshape"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.massCenter.x,this.massCenter.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{},ellipse:"ellipse"==t?{lg:[this.max.minX,this.max.minY,this.max.maxX,this.max.minY],cg:[this.Option.x,this.Option.y,Math.sqrt(Math.pow((this.max.maxX-this.max.minX)/2,2)+Math.pow((this.max.maxY-this.max.minY)/2,2))]}:{}}[t]},_drawHelperPoints:function(t){t.save(),t.setFillStyle("#F34739"),t.beginPath(),this._detectPoints?this._detectPoints.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}):this._Points.forEach(function(i){t.arc(i[0],i[1],5,2*Math.PI,0,2*Math.PI,!1)}),t.closePath(),t.fill(),t.restore()},closeRotateOrigin:function(){this._canRotateOrigin=!1}},Polygon=function(t){var i=_extends({x:10,y:10,r:10,sides:7},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(this.oriPoints),this._isChoosed=!1,this.rotateOrigin=null,this._dirty=!0,this._type="polygon",this._canRotateOrigin=!0};Polygon.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;sthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Ellipse=function(t){var i=_extends({x:10,y:10,a:10,b:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=n,this.UnOption=s,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="ellipse",this._canRotateOrigin=!0};Ellipse.prototype=_extends({getOriPoints:function(){for(var t=[],i=[],n=this.Option.startAngle||0,s=0;s<100;++s)t.push([this.Option.x+this.Option.a/2*Math.sin(n),this.Option.y-this.Option.b/2*Math.cos(n)]),i.push([this.Option.x+(this.Option.a/2+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.b+this.Option.lineWidth)/2*Math.cos(n)]),n+=2*Math.PI/100;this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var baseline=function(t,i){return{normal:2,bottom:-i/2,middle:0,top:i/2}[t]},align=function(t,i){return{left:i/2,center:0,right:-i/2}[t]},Text=function(t){t.text||(t.text="no text");var i={x:100,y:200,fontSize:12,shadow:{offsetX:5,offsetY:5,blur:5,color:"#000000"},fillStyle:"#000000",strokeStyle:"#000000",rotate:0,opacity:1},n={textBaseline:"normal",align:"left",needShadow:!1};this.text=t.text,this.Option=util.extend(t,i),this.UnOption=util.extend(t,n),this.boxOption={x:0,y:0},this.boxOriPoints=[],this.boxPoints=[],this.rotateOrigin=null,this.offset={x:0,y:0},this._offsetX=0,this._offsetY=0,this.getOriPoints(),this.getPoints(),this._dirty=!0,this._type="text",this._canRotateOrigin=!0};Text.prototype=_extends({getOriPoints:function(){for(var t=[],i=/^[\u4e00-\u9fa5]/,n=String(this.text).length,s=0,e=this.Option.fontSize,o=0;oi!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.boxOption.x=t,this.boxOption.y=i,this.Option.x=t-this.offset.x,this.Option.y=i-this.offset.y,this._dirty=!0},detected:function(t,i){return this._offsetX=this.boxOption.x-t,this._offsetY=this.boxOption.y-i,!!this._pnpolyTest(t,i)&&(this._isChoosed=!0,!0)},_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints()),t.save(),this.rotateOrigin?(t.translate(this.rotateOrigin[0],this.rotateOrigin[1]),t.rotate(this.Option.rotate),t.fillText(this.text,this.boxOption.x-this.rotateOrigin[0]-this.offset.x,this.boxOption.y-this.rotateOrigin[1]-this.offset.y)):(t.translate(this.boxOption.x,this.boxOption.y),t.rotate(this.Option.rotate),t.fillText(this.text,-this.offset.x,-this.offset.y)),t.restore(),this._dirty=!1},moveDetect:function(t,i){1==this._isChoosed&&this.move(t+this._offsetX,i+this._offsetY)},updateText:function(t){this.text=t,this._dirty=!0}},commonMethods);var getCurvePoints=function(t,i,n,s){i=void 0!==i?i:.5,n=n||!1,s=s||16;var e,o,h,r,a,u,p,c,l,m,f,x,d,g=[],O=[];for(g=t.slice(0),n?(g.unshift(t[t.length-1]),g.unshift(t[t.length-1]),g.push(t[0])):(g.unshift(t[1]),g.push(t[t.length-1])),d=1;dthis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Circle=function(t){var i=_extends({x:10,y:10,r:10,sA:0,eA:2*Math.PI},commonAttr()),n=_extends({},commonUnAttr(),{counterclockwise:!1,closePath:!1}),s=util.extend(t,i),e=util.extend(t,n);this.Option=s,this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.fullCircle=!0,this._colorLock=!1,this._canRotateOrigin=!0,this.max={maxX:null,maxY:null,minX:null,minY:null},this.oriPoints=null,this._Points=[],this._isChoosed=!1,this.rotateOrigin=null,this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.getOriPoints(),this.getMax(),this._dirty=!0,this._type="circle"};Circle.prototype=_extends({getOriPoints:function(){var t=[],i=[],n=this.Option.sA||0,s=this.Option.eA||2*Math.PI,e=s-n;e>=2*Math.PI?this.fullCircle=!0:this.fullCircle=!1;for(var o=0;o<=100;++o)n=this.Option.sA+o*e/100,t.push([this.Option.x+this.Option.r*Math.sin(n),this.Option.y-this.Option.r*Math.cos(n)]),i.push([this.Option.x+(this.Option.r+this.Option.lineWidth/2)*Math.sin(n),this.Option.y-(this.Option.r+this.Option.lineWidth/2)*Math.cos(n)]);t.unshift([this.Option.x,this.Option.y]),i.unshift([this.Option.x,this.Option.y]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getMax:function(){var t=this.detectOriPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n}},commonMethods);var Rect=function(t){var i=_extends({x:10,y:10,w:10,h:10},commonAttr()),n=util.extend(t,i),s=util.extend(t,commonUnAttr());this.Option=util.extend({},n),this.UnOption=s,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.bus=null,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="rect",this._rotateOriginOver=!1,this._canRotateOrigin=!0};Rect.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.createPath(t),this._dirty=!1},getOriPoints:function(){var t=[],i=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),i.push([this.Option.x-this.Option.w/2-this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y+this.Option.h/2+this.Option.lineWidth/2]),i.push([this.Option.x+this.Option.w/2+this.Option.lineWidth/2,this.Option.y-this.Option.h/2-this.Option.lineWidth/2]),this.oriPoints=t,this.detectOriPoints=i},getPoints:function(){var t=[],i=[],n=null;return n=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(i){t.push(this.getPointTodraw(i[0],i[1],n))},this),this.detectOriPoints.forEach(function(t){i.push(this.getPointTodraw(t[0],t[1],n))},this),this._changeCenter(n),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(i),this._Points},getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return console.log("检测方块",t,i),t>this.max.minX&&tthis.max.minY&&ithis.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]this.max.minX&&tthis.max.minY&&ii!=a>i&&t<(r-o)*(i-h)/(a-h)+o&&(n=!n)}return n}},commonMethods);var Img=function(t){var i={x:10,y:10,w:10,h:10,rotate:0,opacity:1},n={file:""},s=util.extend(t,i),e=util.extend(t,n);this.Option=util.extend({},s),this.UnOption=e,this._isChoosed=!1,this._offsetX=0,this._offsetY=0,this.rotateOrigin=null,this.oriPoints=[],this._Points=[],this._drawLine=!1,this.detectOriPoints=[],this._detectPoints=[],this.max={maxX:null,maxY:null,minX:null,minY:null},this.getOriPoints(),this.getPoints(),this.getMax(),this._dirty=!0,this._type="image",this._canRotateOrigin=!0};Img.prototype=_extends({_draw:function(t){this._dirty&&(this.getOriPoints(),this.getPoints(),this.getMax()),this.drawImage(t),this._dirty=!1},getOriPoints:function(){var t=[];t.push([this.Option.x-this.Option.w/2,this.Option.y-this.Option.h/2]),t.push([this.Option.x-this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y+this.Option.h/2]),t.push([this.Option.x+this.Option.w/2,this.Option.y-this.Option.h/2]),this.oriPoints=t,this.detectOriPoints=t},getPoints:function(){var t=[],i=null;return i=this.rotateOrigin?this.rotateOrigin:[this.Option.x,this.Option.y],this.oriPoints.forEach(function(n){t.push(this.getPointTodraw(n[0],n[1],i))},this),this._Points=matrixToarray(t),this._detectPoints=matrixToarray(t),this._Points}, +getPointTodraw:function(t,i,n){var s=this.Option.rotate;return new Point(t,i).rotate(n,s)},getMax:function(){var t=this._detectPoints;this.max={maxX:null,maxY:null,minX:null,minY:null},t.forEach(function(t){t[0]>this.max.maxX&&(this.max.maxX=t[0]),this.max.minX||0===this.max.minX||(this.max.minX=t[0]),this.max.minX&&t[0]this.max.maxY&&(this.max.maxY=t[1]),this.max.minY||0===this.max.minY||(this.max.minY=t[1]),this.max.minY&&t[1]i!=u>i&&t<(a-h)*(i-r)/(u-r)+h&&(n=!n)}return n},move:function(t,i){this.Option.x=t,this.Option.y=i,this._dirty=!0},detected:function(t,i){return t>this.max.minX&&tthis.max.minY&&i1&&!isNaN(t)?t:0}return this.goesBy},isRunning:function(){return this.running},reset:function(){this.goesBy=0}};var AnimationTimer=function(t,i){void 0!==t&&(this.duration=t),void 0!==i&&(this.timeFunc=i),this.watch=new Watch};AnimationTimer.prototype={start:function(){this.watch.start()},stop:function(){this.watch.stop()},getGoesByTime:function(){var t=this.watch.getGoesByTime(),i=t/this.duration;if(this.watch.running)return this.timeFunc?t*(EasingFunctions[this.timeFunc](i)/i):t},isOver:function(){return this.watch.getGoesByTime()>this.duration}};var specialOption={cshape:{x:"massCenter",y:"massCenter"},line:{x:"massCenter",y:"massCenter"}},specialAtrr={fillStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},strokeStyle:{get:function(t){return hex2rgb(t)},set:function(t,i,n){var s=[t.r+Math.floor(i.r*n),t.g+Math.floor(i.g*n),t.b+Math.floor(i.b*n)];return"#"+rgb2hex.apply(void 0,s)},getIncre:function(t,i,n){var s=hex2rgb(i);return{r:s.r-t.r,g:s.g-t.g,b:s.b-t.b}}},shadow:{get:function(t){return{offsetX:t.offsetX,offsetY:t.offsetY,blur:t.blur,color:hex2rgb(t.color)}},set:function(t,i,n){var s=[t.color.r+Math.floor(i.color.r*n),t.color.g+Math.floor(i.color.g*n),t.color.b+Math.floor(i.color.b*n)],e="#"+rgb2hex.apply(void 0,s);return{offsetX:t.offsetX+i.offsetX*n,offsetY:t.offsetY+i.offsetY*n,blur:t.blur+i.blur*n,color:e}},getIncre:function(t,i,n){var s=util.extend(i,n.Shape.Option.shadow),e=hex2rgb(s.color),o={r:e.r-t.color.r,g:e.g-t.color.g,b:e.b-t.color.b};return{offsetX:(s.offsetX?s.offsetX:5)-t.offsetX,offsetY:(s.offsetY?s.offsetY:5)-t.offsetY,blur:(s.blur?s.blur:5)-t.blur,color:o}}},lineDash:{get:function(t){return t},set:function(t,i,n){return[[t[0][0]+i[0][0]*n,t[0][1]+i[0][1]*n],t[1][1]+i[1][1]*n]},getIncre:function(t,i,n){return[[-t[0][0]+i[0][0],-t[0][1]+i[0][1]],-t[1][1]+i[1][1]]}}},AnimationFrag=function(t,i,n,s,e){var o={onStart:function(){},onLooping:function(){},onEnd:function(){},duration:1e3,easing:"linear"},h=util.extend(s,o);this.object=t,this.source=0,this.genFlag=!1,this.bus=e,this.complete=!1,this.running=!1,this.started=!1,this.duration=h.duration,this.atrribute=i,this.atrributeList=[],"object"==(void 0===i?"undefined":_typeof(i))?(this.genFlag=!0,this.genAtrributeList(i)):(this.incre=genExe(n,i,t),this.exe=n),this.timer=new AnimationTimer(h.duration,h.easing),this.oriOption=h,this.endCallFrag=null,this.onEnd=h.onEnd,this.onLooping=h.onLooping,this.onStart=h.onStart,this._aniWrapbus=null};AnimationFrag.prototype={updateAnimation:function(){return!this.complete&&(this.timer.isOver()?(this.onEnd(),this.complete=!0,this.running=!1,this._aniWrapbus.dispatch("fragAniOver","no","me"),!1):void(this.started||this.complete?(this.onLooping(),this.updateAtrribute()):(this.genFlag||(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute]))),this.started=!0,this.running=!0,this.onStart(),this.timer.start())))},updateAtrribute:function(){this.genFlag?(this.atrributeList.forEach(function(t){this.object.Shape.Option[t.attr]||0==this.object.Shape.Option[t.attr]?specialAtrr[t.attr]?this.object.Shape.Option[t.attr]=specialAtrr[t.attr].set(t.source,t.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][t.attr]][t.attr]=t.source+t.incre*this.timer.getGoesByTime()/this.duration},this),this.object.Shape._dirty=!0):(this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?specialAtrr[this.atrribute]?this.object.Shape.Option[this.atrribute]=specialAtrr[this.atrribute].set(this.source,this.incre,this.timer.getGoesByTime()/this.duration):this.object.Shape.Option[this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute]=this.source+this.incre*this.timer.getGoesByTime()/this.duration,this.object.Shape._dirty=!0)},genAtrributeList:function(t){var i=Object.keys(t),n=this;this.atrributeList=[],i.forEach(function(i){var s=this.object.Shape.Option[i]||0==this.object.Shape.Option[i]?this.object.Shape.Option[i]:this.object.Shape[specialOption[this.object.type][i]][i];specialAtrr[i]&&(s=specialAtrr[i].get(this.object.Shape.Option[i])),n.atrributeList.push({attr:i,incre:genExe(t[i],i,n.object),source:s})},this)},updateSourceAndtarget:function(){this.genFlag?this.genAtrributeList(this.atrribute):(this.source=this.object.Shape.Option[this.atrribute]||0==this.object.Shape.Option[this.atrribute]?this.object.Shape.Option[this.atrribute]:this.object.Shape[specialOption[this.object.type][this.atrribute]][this.atrribute],specialAtrr[this.atrribute]&&(this.source=specialAtrr[this.atrribute].get(this.object.Shape.Option[this.atrribute])),this.incre=genExe(this.exe,this.atrribute,this.object))},addWrapBus:function(t){this._aniWrapbus=t},restart:function(){this.complete=!1,this.running=!1,this.started=!1,this.timer=new AnimationTimer(this.oriOption.duration,this.oriOption.easing)}};var eventBus=function(){this.eventList=[]};eventBus.prototype={add:function(t,i,n){this.eventList.length?(this.eventList.forEach(function(i){if(i.name==t)return i.thingsList.push(n),!1},this),this.eventList.push({name:t,scope:i,thingsList:[n]})):this.eventList.push({name:t,scope:i,thingsList:[n]})},dispatch:function(t,i){var n=arguments;if(arguments.length<2)return!1;var s=Array.prototype.slice.call(n,2);this.eventList.forEach(function(n){n.name===t&&n.thingsList.forEach(function(t){"no"!==i?t.call.apply(t,[i].concat(toConsumableArray(s))):t.call.apply(t,[n.scope].concat(toConsumableArray(s)))})})},destroy:function(){}};var AniFragWrap=function(t,i,n){this.runing=!1,this.stoped=!1,this.started=!1,this.fragStore=[],this.animationPick=0,this.bus=t,this.aniFraBus=new eventBus,this.aniFraBus.add("fragAniOver",this,this.getAniOver),this.overAni=[],this.aniFragListId=i,this.loop=!1,this.loopTimes=!1,this.looped=0,this.object=n,this.oriOption=util.extend(n.Shape.Option,n.Shape.Option),this.oriUnOption=util.extend(n.Shape.Option,n.Shape.UnOption),this.endCallWraper=null,this.firstTime=!0};AniFragWrap.prototype={updateFrag:function(t){t.addWrapBus(this.aniFraBus),this.fragStore.length?(this.fragStore[this.fragStore.length-1].endCallFrag=t,this.fragStore.push(t)):this.fragStore.push(t)},exeAnimate:function(){if(this.object.disableDrag(),this.firstTime&&(this.firstTime=!1,this.oriOption=util.extend(this.object.Shape.Option,this.object.Shape.Option),this.oriUnOption=util.extend(this.object.Shape.Option,this.object.Shape.UnOption)),this.stoped)return this.endCallWraper?this.endCallWraper.exeAnimate():this.object.restoreDrag(),!1;this.fragStore[this.animationPick]&&this.fragStore[this.animationPick].updateAnimation()},getAniOver:function(t){if(this.overAni.push(t),this.overAni.length==this.fragStore.length){if(this.loop){if(this.loopTimes&&this.looped<=this.loopTimes&&this.looped++,this.loopTimes&&this.looped>this.loopTimes)return this.stop(),!1;this.restart()}else this.stop();return!1}this.animationPick++,this.fragStore[this.animationPick].updateSourceAndtarget()},restart:function(){this.object.restoreOption(this.oriOption),this.object.restoreOption(this.oriUnOption),this.overAni=[],this.animationPick=0,this.fragStore.forEach(function(t){t.restart()},this),this.started=!1,this.stoped=!1},stop:function(){this.stoped=!0,this.bus.dispatch("wraperAniComplete","no",this.aniFragListId,this.object.Shapeid,this.object)},resume:function(){},setLoop:function(t,i){this.loop=t||!1,this.loopTimes=i||!1,this.looped=1}};var Shape=function(t,i,n,s){this.draggable=!!s,this.strokeOrfill=n||"fill",this.type=t,this.Shape=new shapeTypes[t](i),this.draggable&&this.Shape.closeRotateOrigin(),this.AnimationTimer=new AnimationTimer,this.animtionFragList=[],this.bus=null,this.Shapeid="sp"+guid(),this.animationStart=!1,this.aniFragListId="",this.aniFragWraper=null,this._oldDrag=this.draggable,this._layerIndex=0,this._getChoosed=!1,this._eventStore={tap:[],touchstart:[],touchmove:[],touchend:[],longpress:[],drag:[]},this._nowType="tap",this._canRotateOrigin=!0};Shape.prototype={updateBus:function(t){this.bus=t},paint:function(t){switch(this.strokeOrfill){case"fill":this.Shape.fill(t);break;case"stroke":this.Shape.stroke(t);break;case"mix":this.Shape.mixDraw(t);break;case!0:this.Shape.fill(t)}},detect:function(t,i,n){this.Shape.detected(t,i)?(this._nowType=n,this.bus.dispatch("getDetectedLayers","no",this._layerIndex)):this.bus.dispatch("getDetectedLayers","no",-1)},moveDetect:function(t,i){this._getChoosed&&this._eventStore.touchmove.forEach(function(t){t(this)},this),this.draggable&&this._getChoosed&&(this._eventStore.drag.forEach(function(t){t(this)},this),this.Shape.moveDetect(t,i))},upDetect:function(){this._getChoosed&&(this.bus.dispatch("clearDetectedLayers","no"),this._eventStore.touchend.forEach(function(t){t(this)},this),this.Shape.upDetect(),this._getChoosed=!1)},animate:function(t,i,n){this.aniFragListId||(this.aniFragListId="af"+guid(),this.aniFragWraper=new AniFragWrap(this.bus,this.aniFragListId,this));var s=null;return s="object"==(void 0===t?"undefined":_typeof(t))?new AnimationFrag(this,t,"no",arguments[1],this.bus):new AnimationFrag(this,t,arguments[1],arguments[2],this.bus),this.aniFragWraper.updateFrag(s),this},start:function(t){this.animationStart=!0,this.aniFragWraper&&(!0===t&&this.aniFragWraper.setLoop(t),"number"==typeof t&&this.aniFragWraper.setLoop(!0,t),this.bus.dispatch("addAnimation","no",this.aniFragWraper,this.Shapeid),this.aniFragListId="",this.aniFragWraper=null),console.log("start")},updateOption:function(t){return this.Shape.bus||(this.Shape.bus=this.bus),this.Shape.updateOption(t),this},restoreOption:function(t){this.Shape.restoreOption(t)},setOrigin:function(t){return this.Shape.setRotateOrigin(t),this},_updateLayer:function(t){this._layerIndex=t},updateLayer:function(t){this.bus.dispatch("updateLayer","no",this,this._layerIndex,t)},getChoosed:function(){this._getChoosed=!0,this._eventStore[this._nowType].forEach(function(t){t(this)},this)},destroy:function(){this.bus.dispatch("destory","no",this._layerIndex,this.Shapeid),this.bus.dispatch("destoryAnimation","no",this._layerIndex,this.Shapeid)},restoreDrag:function(){this.draggable=this._oldDrag},disableDrag:function(){this.draggable=!1},bind:function(t,i){void 0!==this._eventStore[t]&&this._eventStore[t].push(i)},unbind:function(t,i){var n=-1;void 0!==this._eventStore[t]&&this._eventStore[t].forEach(function(t,i){n=i}),-1!==n&&this._eventStore[t].splice(n,1)},clone:function(){var t={};return"text"==this.type&&(t={text:this.Shape.text}),new Shape(this.type,_extends({},this.Shape.Option,this.Shape.UnOption,t),this.strokeOrfill,this.draggable)},updateText:function(t){if("text"!=this.type)return!1;this.Shape.updateText(t)}};var shapeTypes={circle:function(t){return new Circle(t)},rect:function(t){return new Rect(t)},polygon:function(t){return new Polygon(t)},cshape:function(t){return new Cshape(t)},line:function(t){return new Line(t)},ellipse:function(t){return new Ellipse(t)},text:function(t){return new Text(t)},image:function(t){return new Img(t)}},AnimationFrame=function(){return"undefined"!=typeof requestAnimationFrame?requestAnimationFrame:fakeAnimationFrame},animationFrame=AnimationFrame(),Animation=function(t){this.running=!1,this.paused=!0,this.bus=t,this.animationFragStore={},this.animationCompleteList=[],this.wraperAniCompleteOb={},this.bus.add("animationComplete",this,this.animationComplete),this.bus.add("wraperAniComplete",this,this.wraperAniComplete),this.bus.add("destoryAnimation",this,this.destroyAnimation),this.bus.add("clearAnimation",this,this.clearAnimation)};Animation.prototype={start:function(){this.running=!0,this.loopAnimation()},loopAnimation:function(){function t(){animationFrame(t),i.running&&i.updateStep()}var i=this;animationFrame(t)},updateStep:function(){Object.keys(this.animationFragStore).forEach(function(t){this.animationFragStore[t][0].exeAnimate()},this),this.bus.dispatch("update","no")},animationComplete:function(t){this.animationCompleteList.push(t),delete this.animationFragStore[t],console.log("结束动画"),Object.keys(this.wraperAniCompleteOb).length===Object.keys(this.animationFragStore).length&&(this.running=!1)},wraperAniComplete:function(t,i,n){this.wraperAniCompleteOb[i]?this.wraperAniCompleteOb[i].push(t):this.wraperAniCompleteOb[i]=[t],this.wraperAniCompleteOb[i].length==this.animationFragStore[i].length&&(n.restoreDrag(),this.bus.dispatch("animationComplete","no",i))},destroyAnimation:function(t,i){delete this.animationFragStore[i]},clearAnimation:function(){this.animationFragStore={},this.running=!1}},WxDraw.prototype={add:function(t){t.updateBus(this.bus),t._updateLayer(this.store.getLength()),this.store.add(t)},draw:function(){this.store.store.forEach(function(t){t.paint(this.canvas)},this)},tapDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"tap")},this)},longpressDetect:function(t){this.bus.dispatch("clearDetectedLayers","no");var i=this.getLoc(t.touches[0].pageX,t.touches[0].pageY);this.store.store.forEach(function(t){t.detect(i.x,i.y,"longpress")},this)},touchstartDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.detect(i.x,i.y,"touchstart")},this)},touchendDetect:function(t){this.store.store.forEach(function(t){t.upDetect()},this)},touchmoveDetect:function(t){var i={x:t.touches[0].x,y:t.touches[0].y};this.store.store.forEach(function(t){t.moveDetect(i.x,i.y)},this),this.draw(),this.canvas.draw()},getLoc:function(t,i){return{x:t-this.x>0?t-this.x>this.w?this.w:t-this.x:0,y:i-this.y>0?i-this.y>this.h?this.h:i-this.y:0}},update:function(){this.draw(),this.canvas.draw()},AnimationCenter:function(){},addAnimationFrag:function(t,i){this.animation.animationFragStore[i]?(this.animation.animationFragStore[i][this.animation.animationFragStore[i].length-1].endCallWraper=t,this.animation.animationFragStore[i].push(t)):this.animation.animationFragStore[i]=[t]},getDetectedLayers:function(t){this.detectedLayers.push(t),this.detectedLayers.length==this.store.getLength()&&-1!=Math.max.apply(null,this.detectedLayers)&&this.store.find(Math.max.apply(null,this.detectedLayers)).getChoosed(),this.detectedLayers.length==this.store.getLength()&&-1==Math.max.apply(null,this.detectedLayers)&&this.clearDetectedLayers()},clearDetectedLayers:function(){this.detectedLayers=[]},updateLayer:function(t,i,n){var s=0,e=void 0;s=n,"string"==typeof n&&(e=0===n.indexOf("-")?-1:0===n.indexOf("+")&&1),s=e?i+e*parseInt(-1==e?n.split("-")[1]:n.split("+")[1]):parseInt(n),s>=this.store.store.length-1&&(s=this.store.store.length-1),s<=0&&(s=0),this.store.changeIndex(t,i,s),this._updateLayer()},destroy:function(t){this.store.store.splice(t,1)},_updateLayer:function(){this.store.store.forEach(function(t,i){t._updateLayer(i)})},clear:function(){this.canvas.clearActions(),this.store.clear(),this.canvas=null,this.bus.dispatch("clearAnimation","no","no")}};var wxDraw={wxDraw:WxDraw,Shape:Shape,AnimationFrame:AnimationFrame()};module.exports=wxDraw; diff --git a/wxDraw/package.json b/wxDraw/package.json index b121cbf..3bd6565 100755 --- a/wxDraw/package.json +++ b/wxDraw/package.json @@ -18,7 +18,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "rollup -c rollup.config.prod.js&&cp ./dist/wxdraw.min.js ../example/util", - "start": "rollup -c&&cp ./dist/wxdraw.js ../example2/util", + "start": "rollup -c&&cp ./dist/wxdraw.js ../test/util", "bd":"rollup -c rollup.config.prod.js&&cp ./dist/wxdraw.min.js ../example/util" },