UNPKG

ycc.js

Version:

Mini and powerful canvas engine for creating App or Game.

2 lines 83.5 kB
var Ycc=function a(b){this.ctx=null,this.canvasDom=null,this.layerList=[],this.photoManager=null,this.layerManager=null,this.ticker=null,this["debugger"]=null,this.loader=new a.Loader,this.ajax=new a.Ajax,this.baseUI=null,this.gesture=null,this.config=a.utils.extend({debugDrawContainer:!1},b||{}),this.isMobile=a.utils.isMobile(),this.stageW=0,this.stageH=0,this.dpi=this.getSystemInfo().devicePixelRatio};if(Ycc.prototype.getStageWidth=function(){return this.canvasDom.width},Ycc.prototype.getStageHeight=function(){return this.canvasDom.height},Ycc.prototype.bindCanvas=function(a){return this.canvasDom=a,this.ctx=a.getContext("2d"),this.layerList=[],this.photoManager=new Ycc.PhotoManager(this),this.layerManager=new Ycc.LayerManager(this),this.ticker=new Ycc.Ticker(this),this["debugger"]=new Ycc.Debugger(this),this.baseUI=new Ycc.UI(this),this.init(),this},Ycc.prototype.init=function(){this._initStageGestureEvent(),this.ticker.start(6)},Ycc.prototype._initStageGestureEvent=function(){function a(a){var b=parseInt(a.clientX-f.ctx.canvas.getBoundingClientRect().left),c=parseInt(a.clientY-f.ctx.canvas.getBoundingClientRect().top);h="";var d=f.getUIFromPointer(new Ycc.Math.Dot(b,c));d&&(g[a.identifier]=d,d.triggerUIEventBubbleUp(a.type,b,c)),e(a.type,b,c)}function b(a){var b=parseInt(a.clientX-f.ctx.canvas.getBoundingClientRect().left),c=parseInt(a.clientY-f.ctx.canvas.getBoundingClientRect().top);if(h!==b+"_"+c){h=b+"_"+c;var d=g[a.identifier];d&&(g[a.identifier]=d,d.triggerUIEventBubbleUp(a.type,b,c)),e(a.type,b,c)}}function c(a){var b=parseInt(a.clientX-f.ctx.canvas.getBoundingClientRect().left),c=parseInt(a.clientY-f.ctx.canvas.getBoundingClientRect().top),d=g[a.identifier];d&&(g[a.identifier]=d,d.triggerUIEventBubbleUp(a.type,b,c),d=null,g[a.identifier]=null),e(a.type,b,c)}function d(a){var b=parseInt(a.clientX-f.ctx.canvas.getBoundingClientRect().left),c=parseInt(a.clientY-f.ctx.canvas.getBoundingClientRect().top),d=f.getUIFromPointer(new Ycc.Math.Dot(b,c));d&&d.triggerUIEventBubbleUp(a.type,b,c,a),e(a.type,b,c)}function e(a,b,c){for(var d=f.layerList.length-1;d>=0;d--){var e=f.layerList[d];e.enableEventManager&&e.enableEventManager&&e.triggerListener(a,new Ycc.Event({type:a,x:b,y:c}))}}var f=this,g={},h="",i=new Ycc.Gesture({target:this.ctx.canvas});this.gesture=i,i.addListener("tap",d),i.addListener("longtap",d),i.addListener("doubletap",d),i.addListener("swipe",d),i.addListener("swipeleft",d),i.addListener("swiperight",d),i.addListener("swipeup",d),i.addListener("swipedown",d),i.addListener("dragstart",a),i.addListener("dragging",b),i.addListener("dragend",c),i.addListener("mousemove",d)},Ycc.prototype.clearStage=function(){this.ctx.clearRect(0,0,this.getStageWidth(),this.getStageHeight())},Ycc.prototype.findLayerById=function(a){for(var b=0;b<this.layerList.length;b++){var c=this.layerList[b];if(c.id===a)return c}return null},Ycc.prototype.findUiById=function(a){for(var b=0;b<this.layerList.length;b++)for(var c=this.layerList[b],d=0;d<c.uiList.length;d++){var e=c.uiList[d];if(e.id===a)return e}return null},Ycc.prototype.getUIFromPointer=function(a,b){var c=this;b=!Ycc.utils.isBoolean(b)||b;for(var d=c.layerList.length-1;d>=0;d--){var e=c.layerList[d];if(!e.ghost&&(!b||e.show)){var f=e.getUIFromPointer(a,b);if(f)return f}}return null},Ycc.prototype.getUIListFromPointer=function(a,b){var c=this;b=b||{uiIsShow:!0,uiIsGhost:!1};for(var d=[],e=c.layerList.length-1;e>=0;e--){var f=c.layerList[e];if(f.show){var g=f.getUIListFromPointer(a);d=d.concat(g)}}return d=d.filter(function(a){return a.show===b.uiIsShow&&a.ghost===b.uiIsGhost})},Ycc.prototype.createCanvas=function(a){a=a||{};var b=Ycc.utils.mergeObject({width:window.innerWidth,height:window.innerHeight,dpiAdaptation:!1},a),c=document.createElement("canvas"),d=this.getSystemInfo().devicePixelRatio;return b.dpiAdaptation?(c.width=b.width*d,c.height=b.height*d,c.style.width=b.width+"px"):(c.width=b.width,c.height=b.height),c.style.display="block",c},Ycc.prototype.getSystemInfo=function(){return{model:"iPhone 5",pixelRatio:window.devicePixelRatio||1,windowWidth:window.innerWidth,windowHeight:window.innerHeight,screenWidth:320,screenHeight:568,devicePixelRatio:window.devicePixelRatio||1}},Ycc.prototype.createCacheCtx=function(a){a=a||{width:this.getStageWidth(),height:this.getStageHeight()};var b=this.createCanvas({width:a.width,height:a.height}).getContext("2d");return document.body.appendChild(b.canvas),b},function(a){a.utils={},a.utils.extend=function(b,c,d){d&&(c=a.utils.deepClone(c));for(var e in b)b.hasOwnProperty(e)&&c&&"undefined"!=typeof c[e]&&(b[e]=c[e]);return b},a.utils.mergeObject=function(a,b){b=b||{};for(var c in b)b.hasOwnProperty(c)&&"undefined"!=typeof b[c]&&(a[c]=b[c]);return a},a.utils.isString=function(a){return"string"==typeof a},a.utils.isNum=function(a){return"number"==typeof a},a.utils.isBoolean=function(a){return"boolean"==typeof a},a.utils.isObj=function(a){return"object"==typeof a},a.utils.isFn=function(a){return"function"==typeof a},a.utils.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.utils.isMobile=function(){for(var a=navigator.userAgent,b=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"],c=!1,d=0;d<b.length;d++)if(a.indexOf(b[d])>0){c=!0;break}return c},a.utils.deepClone=function(b){function c(b){var e={};for(var f in b)b.hasOwnProperty(f)&&(e[f]=b[f],a.utils.isArray(b[f])?e[f]=d(b[f]):a.utils.isObj(b[f])?e[f]=c(b[f]):e[f]=b[f]);return e}function d(b){for(var e=[],f=null,g=0;g<b.length;g++)f=b[g],a.utils.isArray(f)?e.push(d(f)):a.utils.isObj(f)?e.push(c(f)):e.push(f);return e}return a.utils.isArray(b)?d(b):c(b)},a.utils.renderTpl=function(a,b){return a.replace(/__.+?__/g,function(a){console.log("匹配到的文本-->",a);var c=a.slice(2).slice(0,-2).trim();return void 0!==b[c]?b[c]:a})},a.utils.releaseObject=function(a){for(var b in a)a.hasOwnProperty(b)&&delete a[b]},a.utils.releaseArray=function(a){a.length=0},a.utils.isWx=function(){return"undefined"!=typeof wx}}(Ycc),function(a){a.utils.extend;a.Math=function(){},a.Math.Dot=function(a){this.x=0,this.y=0;var b=arguments.length;1===b?(this.x=a.x,this.y=a.y):2===b&&(this.x=arguments[0],this.y=arguments[1])},a.Math.Dot.prototype.isInRect=function(a){return this.x>=a.x&&this.x<=a.x+a.width&&this.y>=a.y&&this.y<=a.y+a.height},a.Math.Dot.prototype.isEqual=function(a){return this.x===a.x&&this.y===a.y},a.Math.Dot.prototype.plus=function(b){return new a.Math.Dot(this.x+b.x,this.y+b.y)},a.Math.Dot.prototype.rotate=function(b,c){c=c||new a.Math.Dot(0,0);var d=this.x,e=this.y,f=c.x,g=c.y,h=(d-f)*Math.cos(b/180*Math.PI)-(e-g)*Math.sin(b/180*Math.PI)+f,i=(e-g)*Math.cos(b/180*Math.PI)+(d-f)*Math.sin(b/180*Math.PI)+g;return new a.Math.Dot(h,i)},a.Math.Dot.threeDotIsOnLine=function(a,b,c){if(a.isEqual(b)||a.isEqual(c)||b.isEqual(c))return!0;if(a.x===b.x&&b.x===c.x)return!0;var d=Math.abs(a.y-b.y)/Math.abs(a.x-b.x),e=Math.abs(a.y-c.y)/Math.abs(a.x-c.x);return d===e},a.Math.Rect=function(b){this.yccClass=a.Math.Rect,this.x=0,this.y=0,this.width=0,this.height=0;var c=arguments.length;1===c?(this.x=b.x,this.y=b.y,this.width=b.width,this.height=b.height):3===c?(this.x=arguments[0].x,this.y=arguments[0].y,this.width=arguments[1],this.height=arguments[2]):4===c&&(this.x=arguments[0],this.y=arguments[1],this.width=arguments[2],this.height=arguments[3]),this.toPositive()},a.Math.Rect.prototype.toPositive=function(){var a=this.x,b=this.y,c=this.x+this.width,d=this.y+this.height;this.x=a<c?a:c,this.y=b<d?b:d,this.width=Math.abs(this.width),this.height=Math.abs(this.height)},a.Math.Rect.prototype.getVertices=function(){return[new a.Math.Dot(this.x,this.y),new a.Math.Dot(this.x+this.width,this.y),new a.Math.Dot(this.x+this.width,this.y+this.height),new a.Math.Dot(this.x,this.y+this.height),new a.Math.Dot(this.x,this.y)]},a.Math.Rect.prototype.updateByVertices=function(b){return a.utils.isArray(b)?(this.x=b[0].x,this.y=b[0].y,this.width=b[1].x-this.x,void(this.height=b[2].y-this.y)):console.error("参数必须是数组!")},a.Math.Vector=function(){this.x=0,this.y=0,this.z=0,3!==arguments.length&&2!==arguments.length||(this.x=arguments[0]||0,this.y=arguments[1]||0,this.z=arguments[2]||0),1===arguments.length&&(a.utils.isObj(arguments[0])||console.error("constructor need a objec as param!"),this.x=arguments[0].x||0,this.y=arguments[0].y||0,this.z=arguments[0].z||0)},a.Math.Vector.prototype.dot=function(a){return this.x*a.x+this.y*a.y+this.z*a.z},a.Math.Vector.prototype.cross=function(b){var c=new a.Math.Vector;return c.x=this.y*b.z-b.y*this.z,c.y=b.x*this.z-this.x*b.z,c.z=this.x*b.y-b.x*this.y,c},a.Math.Vector.prototype.getLength=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z,2)},a.Math.Matrix=function(a,b,c){this.data=a,this.m=b,this.n=c},a.Math.Matrix.prototype.dot=function(b){if(b.m!==this.n||b.n!==this.m)return console.error("两个矩阵的行数和列数不对应,不能相乘!");for(var c=new a.Math.Matrix([],this.m,this.m),d=1;d<=this.m;d++)for(var e=1;e<=this.m;e++){for(var f=0,g=1;g<=this.n;g++)f+=this.get(d,g)*b.get(g,e);c.set(d,e,f)}return c},a.Math.Matrix.prototype.get=function(a,b){return this.data[(a-1)*this.n+b-1]},a.Math.Matrix.prototype.set=function(a,b,c){this.data[(a-1)*this.n+b-1]=c}}(Ycc),function(a){var b=1,c={};a.Tree=function(){this.$id=b++,this.$parentID=null,this.children=[],this.data=null,c[this.$id]=this},a.Tree.release=function(a){var b=a.getParent();if(b){var d=b.children,e=d.indexOf(a);e!==-1&&(d[e]=null)}delete c[a.$id],a.children.length=0,a.data=null},a.Tree.getNodeMap=function(){return c},a.Tree.prototype.getNodeMap=function(){return c},a.Tree.prototype.getParent=function(){return this.$parentID?c[this.$parentID]:null},a.Tree.prototype.addChildTree=function(a){return a.$parentID?console.error("sub tree's parent has exist! can't add!",a):(a.$parentID=this.$id,this.children.push(a),this)},a.Tree.prototype.removeChildTree=function(a){var b=this.children.indexOf(a);return b===-1?this:(this.children.splice(b,1),this)},a.Tree.prototype.getDepth=function(){var a=this,b=1;if(a.children.length>0)for(var c=0;c<a.children.length;c++){var d=a.children[c].getDepth();b=d+1>b?d+1:b}return b},a.Tree.prototype.itor=function(a){function b(a){if(a.call(h,h))return!0;if(h.children.length>0)for(var b=0;b<h.children.length;b++)if(h.children[b].itor().each(a))return!0;return!1}function c(a){if(h.children.length>0)for(var b=0;b<h.children.length;b++)if(h.children[b].itor().leftChildFirst(a))return!0;if(a.call(h,h))return!0}function d(a){if(h.children.length>0)for(var b=h.children.length-1;b>=0;b--)if(h.children[b].itor().rightChildFirst(a))return!0;if(a.call(h,h))return!0}function e(a){f([h],a)}function f(b,c,d){if(0===b.length)return!0;d=d||0,d++;for(var e=a.reverse?g(b):b,i=[],j=!1,k=0;k<e.length;k++){var l=c.call(h,e[k],d);if(l===!0){j=!0;break}l!==-1&&(i=i.concat(a.reverse?g(e[k].children):e[k].children))}return j&&(i=[]),a.reverse&&i.reverse(),f(i,c,d)}function g(a){for(var b=[],c=a.length-1;c>=0;c--)b.push(a[c]);return b}var h=this;return a=a||{reverse:!1},{each:b,leftChildFirst:c,rightChildFirst:d,depthDown:e}},a.Tree.prototype.toNodeList=function(){var a=[];return this.itor().depthDown(function(b){a.push(b)}),a},a.Tree.prototype.getNodeListGroupByLayer=function(){var a={};return this.itor().depthDown(function(b,c){a[c]||(a[c]=[]),a[c].push(b)}),a},a.Tree.prototype.getParentList=function(){for(var a=this,b=[];a.$parentID;){var d=c[a.$parentID];b.unshift(d),a=d}return b},a.Tree.prototype.getBrotherList=function(){var a=[];return a=this.$parentID?c[this.$parentID].children:[this]},a.Tree.createByJSON=function(b){var c=new a.Tree;if(c.data=b.data,a.utils.isArray(b.children)&&b.children.length>0)for(var d=0;d<b.children.length;d++)c.addChildTree(a.Tree.createByJSON(b.children[d]));return c},a.Tree.createByNodes=function(b){if(!a.utils.isArray(b)||0===b.length)return console.error("need an Array as param!");var c=null,d=[];return b.forEach(function(b){var e=new a.Tree;e.data=b,d.push(e),a.utils.isNum(b.parentID)||b.parentID||(c=e)}),d.forEach(function(a){d.forEach(function(b){b.data.parentID===a.data.id&&a.addChildTree(b)})}),c}}(Ycc),function(a){var b=1,c=1,d=1,e={},f={};a.Graph=function(a){this.type=a||1,this.$id=d++,this.vList=[],this.eList=[]},a.Graph.prototype.getMapV=function(){return e},a.Graph.prototype.getMapE=function(){return f},a.Graph.prototype.bfs=function(a,b,c){if(a=a||[],c=c||[],c.length===this.vList.length)return!0;if(0===a.length){for(var d=null,f=0;f<this.vList.length;f++)if(c.indexOf(this.vList[f].$id)===-1){d=this.vList[f].$id;break}return this.bfs([d],b,c)}for(var g=null,h=0;h<a.length;h++){if(g=e[a[h]],b.call(this,g))return!0;c.push(g.$id)}for(var i=[],j=0;j<a.length;j++){g=e[a[j]];var k=g.getAccessibleIds().filter(function(a){return c.indexOf(a)===-1});i=i.concat(k)}return this.bfs(i,b,c)},a.Graph.prototype.dfs=function(a,b,c){c=c||[];var d=e[a];if(c.push(d.$id),b.call(this,d))return!0;for(var f=d.getAccessibleIds(),g=0;g<f.length;g++){var h=f[g];if(c.indexOf(h)===-1&&this.dfs(h,b,c))return!0}if(c.length===this.vList.length)return!0;for(var i=null,j=0;j<this.vList.length;j++)if(c.indexOf(this.vList[j].$id)===-1){i=this.vList[j].$id;break}return this.dfs(i,b,c)},a.Graph.createDirectedGraph=function(b,c){var d=new a.Graph(1),e=d.vList,f=d.eList;return b.forEach(function(b){e.push(new a.Graph.DirectedV(b))}),c.forEach(function(b){for(var c=null,d=null,g=new a.Graph.DirectedE,h=0;h<e.length&&(!c||!d);h++){var i=e[h];i.data.id===b.fromId&&(c=i,i.outIDs.push(g.$id)),i.data.id===b.toId&&(d=i,i.inIDs.push(g.$id))}g.init(c.$id,d.$id,b),f.push(g)}),d},a.Graph.DirectedV=function(a){this.$id=b++,this.data=a,this.inIDs=[],this.outIDs=[],e[this.$id]=this},a.Graph.DirectedV.prototype.getAccessibleIds=function(){var a=[];return this.outIDs.forEach(function(b){a.push(f[b].toID)}),a},a.Graph.DirectedE=function(){this.$id=c++,this.data=null,this.fromID=null,this.toID=null,f[this.$id]=this},a.Graph.DirectedE.prototype.init=function(a,b,c){this.fromID=a,this.toID=b,this.data=c},a.Graph.createUnDirectedGraph=function(b,c){var d=new a.Graph(2),e=d.vList,f=d.eList;return b.forEach(function(b){e.push(new a.Graph.UnDirectedV(b))}),c.forEach(function(b){for(var c=[],d=new a.Graph.UnDirectedE,g=0;g<e.length;g++){var h=e[g];if(2===c.length)break;h.data.id!==b.ids[0]&&h.data.id!==b.ids[1]||(c.push(h.$id),h.eIDs.push(d.$id))}d.init(c,b),f.push(d)}),d},a.Graph.UnDirectedV=function(a){this.$id=b++,this.data=a,this.eIDs=[],e[this.$id]=this},a.Graph.UnDirectedV.prototype.getAccessibleIds=function(){for(var a=[],b=0;b<this.eIDs.length;b++){var c=f[this.eIDs[b]];c.vIDs[0]===this.$id&&a.push(c.vIDs[1]),c.vIDs[1]===this.$id&&a.push(c.vIDs[0])}return a},a.Graph.UnDirectedE=function(){this.$id=c++,this.data=null,this.vIDs=[],f[this.$id]=this},a.Graph.UnDirectedE.prototype.init=function(a,b){this.vIDs=a,this.data=b}}(Ycc),function(a){function b(a){this.createTime=Date.now(),this.deltaTime=a.deltaTime,this.fps=parseInt(1e3/this.deltaTime),this.frameCount=a.frameAllCount,this.isRendered=!1}a.Ticker=function(b){this.yccClass=a.Ticker,this.yccInstance=b,this.currentFrame=null,this.startTime=performance.now(),this.lastFrameTime=this.startTime,this.lastFrameTickerCount=0,this.deltaTime=0,this.deltaTimeExpect=0,this.deltaTimeRatio=1,this.frameListenerList=[],this.defaultFrameRate=60,this.defaultDeltaTime=1e3/this.defaultFrameRate,this.tickerSpace=1,this.frameAllCount=0,this.timerTickCount=0,this._timerId=0,this._isRunning=!1},a.Ticker.prototype.start=function(a){function c(a){e.timerTickCount++,e.timerTickCount-e.lastFrameTickerCount===e.tickerSpace&&(e.frameAllCount++,e.deltaTime=a-e.lastFrameTime,e.deltaTimeRatio=e.deltaTime/e.deltaTimeExpect,e.lastFrameTime+=e.deltaTime,e.lastFrameTickerCount=e.timerTickCount,e.currentFrame=new b(e),e.broadcastFrameEvent(e.currentFrame),e.broadcastToLayer(e.currentFrame)),e._timerId=d(c)}var d=requestAnimationFrame||webkitRequestAnimationFrame||mozRequestAnimationFrame||oRequestAnimationFrame||msRequestAnimationFrame,e=this;e.currentFrame=null,e.timerTickCount=0,e.lastFrameTickerCount=0,a=a?a:e.defaultFrameRate,e.tickerSpace=parseInt(60/a)||1,e.deltaTimeExpect=1e3/a,e.frameAllCount=0,e.startTime=performance.now(),e._isRunning||(d||(d=function(a){return setTimeout(function(){a(Date.now())},1e3/60)}),e._timerId=d(c),e._isRunning=!0)},a.Ticker.prototype.stop=function(){var a=cancelAnimationFrame||webkitCancelAnimationFrame||mozCancelAnimationFrame||oCancelAnimationFrame;a||(a=function(a){return clearTimeout(a)}),a(this._timerId),this._isRunning=!1,this.currentFrame=null},a.Ticker.prototype.addFrameListener=function(a){this.frameListenerList.push(a)},a.Ticker.prototype.removeFrameListener=function(a){var b=this.frameListenerList.indexOf(a);b!==-1&&this.frameListenerList.splice(b,1)},a.Ticker.prototype.broadcastFrameEvent=function(b){for(var c=0;c<this.frameListenerList.length;c++){var d=this.frameListenerList[c];a.utils.isFn(d)&&d(b)}},a.Ticker.prototype.broadcastToLayer=function(a){for(var b=0;b<this.yccInstance.layerList.length;b++){var c=this.yccInstance.layerList[b];c.show&&c.enableFrameEvent&&c.onFrameComing(a)}}}(Ycc),function(a){a.Debugger=function(b){this.yccClass=a.Debugger,this.yccInstance=b,this.deltaTime=null,this.deltaTimeExpect=null,this.frameAllCount=null,this.deltaTimeAverage=null,this.renderTime=null,this.renderUiCount=null,this.totalJSHeapSize=null,this.usedJSHeapSize=null,this.jsHeapSizeLimit=null,this.fields=[],this.rect=null,this.layer=null},a.Debugger.prototype.init=function(){this.rect=new a.UI.Rect({name:"debuggerRect",rect:new a.Math.Rect(10,10,200,140),color:"rgba(255,255,0,0.5)"}),this.layer=yccInstance.layerManager.newLayer({name:"debug图层"});var b=this;this.yccInstance.ticker.addFrameListener(function(){b.updateInfo()})},a.Debugger.prototype.showDebugPanel=function(){this.init();var a=this.layer;a.uiList.indexOf(this.rect)===-1&&a.addUI(this.rect)},a.Debugger.prototype.updateInfo=function(){var a=this.yccInstance.layerList,b=a.indexOf(this.layer);b!==-1&&(b+1!==a.length&&(a.splice(b,1),a.push(this.layer)),this.rect.rect.height=20*this.fields.length,this.fields.forEach(function(a){a.ui.content=a.name+" "+a.cb()}))},a.Debugger.prototype.addField=function(b,c){var d=this.fields.length,e=new a.UI.SingleLineText({content:"usedJSHeapSize "+c(),fontSize:"12px",rect:new a.Math.Rect(0,20*d,100,20),color:"green"});this.fields.push({name:b,cb:c,ui:e}),this.rect.addChild(e)},a.Debugger.prototype.addToLayer=function(a){a.uiList.indexOf(this.rect)===-1&&a.addUI(this.rect)},a.Debugger.prototype.updateField=function(a,b){for(var c=0;c<this.fields.length;c++)if(this.fields[c].name===a)return this.fields[c].cb=null,void(this.fields[c].cb=b)},a.Debugger.Log=function(a){this.message="[Ycc logger]=> "+a},a.Debugger.Error=function(a){this.message="[Ycc error]=> "+a}}(Ycc),function(a){function b(b,c){a.utils.isWx()&&b.indexOf("cloud://")!==-1?wx.cloud.downloadFile({fileID:b,success:function(a){c.call(this,a.tempFilePath)},fail:function(){c.call(this,b)}}):c.call(this,b)}function c(){this.currentTime=0,this.source=null,this.running=!1}a.Loader=function(){this.yccClass=a.Loader,this.ajax=new a.Ajax,this.basePath=""},a.Loader.prototype.loadResParallel=function(b,c,d,e,f){function g(g,h,i){return function(){e.push(g),"undefined"!=typeof g.name&&(f[g.name]=g.res),a.utils.isFn(d)&&d(g,i,h),b.length===e.length&&c(e,f)}}e=e||[],f=f||{};for(var h=0;h<b.length;h++){var i=b[h],j="load",k="error";i.type=i.type||"image","image"===i.type&&(i.res=new Image,i.res.src=i.url,i.res.crossOrigin=i.crossOrigin||""),"audio"===i.type&&(j="loadedmetadata",i.res=new Audio,i.res.src=i.url,i.res.preload="load",i.res.crossOrigin=i.crossOrigin||""),i.res.addEventListener(j,g(i,h,!0)),i.res.addEventListener(k,g(i,h,!1))}},a.Loader.prototype.loadResOneByOne=function(d,e,f,g,h){function i(){clearTimeout(p),("image"===m.type||"undefined"!=typeof wx&&"audio"===m.type)&&(m.res.removeEventListener(n,i),m.res.removeEventListener(o,j)),g.push(m),"undefined"!=typeof m.name&&(h[m.name]=m.res),a.utils.isFn(f)&&f(m,null,l),k.loadResOneByOne(d,e,f,g,h)}function j(b){console.log("loader:",m.name,"error"),clearTimeout(p),("image"===m.type||"undefined"!=typeof wx&&"audio"===m.type)&&(m.res.removeEventListener(n,i),m.res.removeEventListener(o,j)),g.push(m),"undefined"!=typeof m.name&&(h[m.name]=m.res),a.utils.isFn(f)&&f(m,b,l),k.loadResOneByOne(d,e,f,g,h)}if(g=g||[],h=h||{},d.length===g.length)return void e(g,h);var k=this,l=g.length,m=d[l],n="load",o="error";m.type=m.type||"image";var p=0;b(k.basePath+m.url,function(a){if("image"===m.type)m.res=new Image,m.res.src=a,m.res.addEventListener(n,i),m.res.addEventListener(o,j),p=setTimeout(function(){m.res.removeEventListener(n,i),m.res.removeEventListener(o,i),j({message:"获取资源超时!"})},m.timeout||1e4);else if("audio"===m.type){if("undefined"!=typeof wx)return m.res=new Audio,m.res.src=a,n="loadedmetadata",o="error",m.res.addEventListener(n,i),void m.res.addEventListener(o,j);if(m.res=new c,!m.res.context)return void j({message:"浏览器不支持AudioContext!"});console.log(a),k.ajax.get(a,function(a){return function(b){a.res.context.decodeAudioData(b,function(b){a.res.buf=b,i()},j)}}(m),j,"arraybuffer")}})},a.Loader.prototype.getResByName=function(a,b){for(var c=0;c<b.length;c++)if(b[c].name===a)return b[c];return null},c.prototype.context="undefined"!=typeof AudioContext&&new AudioContext||"undefined"!=typeof webkitAudioContext&&new webkitAudioContext,c.prototype.play=function(){var a=this.context;if(a){this.running=!0,this.source&&this.source.stop();var b=a.createBufferSource();b.buffer=this.buf,b.connect(a.destination),b.start(this.currentTime),this.source=b}},c.prototype.pause=function(){var a=this.context;a&&(this.running=!1,this.source.stop(),this.source=null)}}(Ycc),function(a){a.Ajax=function(){this.yccClass=a.Ajax},a.Ajax.prototype.get=function(a){var b,c,d=this,e="",f="json";1===arguments.length?(e="",b=a.successCb,c=a.errorCb,f="json"):(e=arguments[0],b=arguments[1],c=arguments[2],f=arguments[3]);var g=new XMLHttpRequest;g.open("GET",e,!0),g.responseType=f,g.onload=function(){b.call(d,g.response)},g.onerror=function(a){c.call(d,a)},g.send()}}(Ycc),function(a){a.Event=function(b){this.yccClass=a.Event,this.type=b?b:"",this.x=0,this.y=0,this.originEvent=null,this.stop=!1,this.target=null,a.utils.isObj(b)&&a.utils.extend(this,b)}}(Ycc),function(a){a.Listener=function(){this.yccClass=a.Listener,this.listeners={},this.stopType={},this.disableType={},this.stopAllEvent=!1,this.onclick=null,this.onmousedown=null,this.onmouseup=null,this.onmousemove=null,this.ondragstart=null,this.ondragging=null,this.ondragend=null,this.onmouseover=null,this.onmouseout=null,this.ontouchstart=null,this.ontouchmove=null,this.ontouchend=null,this.ontap=null},a.Listener.release=function(b){var c=null;b.yccClass=null;for(c in b.listeners)b.listeners.hasOwnProperty(c)&&(b.listeners[c].length=0,delete b.listeners[c]);a.utils.releaseObject(b.stopType),a.utils.releaseObject(b.disableType),b.stopAllEvent=!0,b.onclick=null,b.onmousedown=null,b.onmouseup=null,b.onmousemove=null,b.ondragstart=null,b.ondragging=null,b.ondragend=null,b.onmouseover=null,b.onmouseout=null,b.ontouchstart=null,b.ontouchmove=null,b.ontouchend=null,b.ontap=null},a.Listener.prototype.addListener=function(a,b){var c=this.listeners[a];c||(this.listeners[a]=[]),this.listeners[a].indexOf(b)===-1&&this.listeners[a].push(b)},a.Listener.prototype.stop=function(a){this.stopType[a]=!0},a.Listener.prototype.triggerListener=function(b,c){if(!this.stopAllEvent&&!this.disableType[b]){this.stopType[b]||a.utils.isFn(this["on"+b])&&this["on"+b].apply(this,Array.prototype.slice.call(arguments,1));var d=this.listeners&&this.listeners[b];if(d&&a.utils.isArray(d))for(var e=0;e<d.length;e++)this.stopType[b]||d[e].apply(this,Array.prototype.slice.call(arguments,1))}},a.Listener.prototype.removeListener=function(b,c){var d=this.listeners[b];if(d&&a.utils.isArray(d))for(var e=0;e<d.length;e++)if(d[e]===c)return void d.splice(e,1)},a.Listener.prototype.disableEvent=function(a){this.disableType[a]=!0},a.Listener.prototype.resumeEvent=function(a){this.disableType[a]=!1}}(Ycc),function(a){var b=function(){var a=0;return function(){this.id=a++,this.startTouchEvent=null,this.endTouchEvent=null,this.moveTouchEventList=[],this.startTime=Date.now(),this.endTime=0}}();a.TouchLifeTracer=function(c){a.Listener.call(this),this.target=c.target,this._lifeList=[],this.currentLifeList=[],this.targetTouches=[],this.touches=[],this.changedTouches=[],this.onlifestart=null,this.onlifechange=null,this.onlifeend=null,this.addLife=function(a){this._lifeList.push(a)},this.findCurrentLifeByTouchID=function(a){for(var b=0;b<this.currentLifeList.length;b++){var c=this.currentLifeList[b];if(c.startTouchEvent.identifier===a)return c}},this.deleteCurrentLifeByTouchID=function(a){for(var b=0;b<this.currentLifeList.length;b++){var c=this.currentLifeList[b];if(c.startTouchEvent.identifier===a)return this.currentLifeList.splice(b,1),!0}return!1},this.init=function(){var a=this;this.target.addEventListener("touchstart",function(c){c.preventDefault(),a.syncTouches(c);var d=new b;d.startTouchEvent=c.changedTouches[0],a.addLife(d),a.currentLifeList.push(d),a.triggerListener("lifestart",d)}),this.target.addEventListener("touchmove",function(b){b.preventDefault(),a.syncTouches(b);for(var c=b.changedTouches,d=0;d<c.length;d++){var e=c[d],f=a.findCurrentLifeByTouchID(e.identifier),g=a.indexOfTouchFromMoveTouchEventList(f.moveTouchEventList,e);g===-1?f.moveTouchEventList.push(e):f.moveTouchEventList[g]=e,a.triggerListener("lifechange",f)}}),this.target.addEventListener("touchend",function(b){b.preventDefault(),a.syncTouches(b);var c=b.changedTouches[0],d=a.findCurrentLifeByTouchID(c.identifier);d.endTouchEvent=c,d.endTime=Date.now(),a.deleteCurrentLifeByTouchID(c.identifier),a.triggerListener("lifeend",d)})},this.init()},a.utils.mergeObject(a.TouchLifeTracer.prototype,a.Listener.prototype),a.TouchLifeTracer.prototype.syncTouches=function(a){this.touches=[],this.changedTouches=[],this.targetTouches=[];var b=0,c=[];for(c=a.touches,b=0;b<c.length;b++)this.touches.push(c[b]);for(c=a.changedTouches,b=0;b<a.changedTouches.length;b++)this.changedTouches.push(c[b]);for(c=a.targetTouches,b=0;b<a.targetTouches.length;b++)this.targetTouches.push(c[b])},a.TouchLifeTracer.prototype.indexOfTouchFromMoveTouchEventList=function(a,b){for(var c=0;c<a.length;c++)if(b.identifier===a[c].identifier)return c;return-1}}(Ycc),function(a){a.Gesture=function(b){a.Listener.call(this),this.yccClass=a.Gesture,b=b||{},this.option={target:null,useMulti:!0},a.utils.extend(this.option,b),this._longTapTimeout=null,this._init()},a.Gesture.prototype=new a.Listener,a.Gesture.prototype._init=function(){a.utils.isMobile()?(console.log("mobile gesture init..."),this._initForMobile()):(console.log("pc gesture init..."),this._initForPC())},a.Gesture.prototype._initForMobile=function(){var b,c,d=this,e=new a.TouchLifeTracer({target:this.option.target}),f={tap:!1,swipe:!1};e.onlifestart=function(a){if(d.triggerListener("tap",d._createEventData(a.startTouchEvent,"tap")),d.triggerListener("log","tap triggered"),d.triggerListener("dragstart",d._createEventData(a.startTouchEvent,"dragstart")),e.currentLifeList.length>1){if(!d.option.useMulti)return;return d.triggerListener("log","multi touch start ..."),d.triggerListener("multistart",e.currentLifeList),f.tap=!1,f.swipe=!1,clearTimeout(this._longTapTimeout),b=e.currentLifeList[0],c=e.currentLifeList[1],this}f.tap=!1,f.swipe=!1,this._longTapTimeout=setTimeout(function(){d.triggerListener("longtap",d._createEventData(a.startTouchEvent,"longtap"))},750)},e.onlifechange=function(g){if(g.moveTouchEventList.forEach(function(a){d.triggerListener("dragging",d._createEventData(a,"dragging"))}),e.currentLifeList.length>1){if(!d.option.useMulti)return;f.tap=!0,f.swipe=!0,d.triggerListener("log","multi touch move ..."),d.triggerListener("multichange",b,c);var h=d.getZoomRateAndRotateAngle(b,c);return a.utils.isNum(h.rate)&&(d.triggerListener("zoom",h.rate),d.triggerListener("log","zoom triggered",h.rate)),a.utils.isNum(h.angle)&&(d.triggerListener("rotate",h.angle),d.triggerListener("log","rotate triggered",h.angle)),this}if(g.moveTouchEventList.length>0){var i=g.startTouchEvent,j=Array.prototype.slice.call(g.moveTouchEventList,-1)[0];(Math.abs(j.pageX-i.pageX)>10||Math.abs(j.pageY-i.pageY)>10)&&(f.tap=!0,clearTimeout(this._longTapTimeout))}},e.onlifeend=function(a){if(d.triggerListener("dragend",d._createEventData(a.endTouchEvent,"dragend")),1===e.currentLifeList.length)return d.triggerListener("multiend",b,c);if(0===e.currentLifeList.length){if(!f.tap&&a.endTime-a.startTime<300)return clearTimeout(this._longTapTimeout),b&&a.endTime-b.endTime<300&&Math.abs(b.endTouchEvent.pageX-a.endTouchEvent.pageX)<10&&Math.abs(b.endTouchEvent.pageY-a.endTouchEvent.pageY)<10?(d.triggerListener("doubletap",d._createEventData(a.endTouchEvent,"doubletap")),d.triggerListener("log","doubletap triggered"),b=null,this):(b=a,this);if(!f.swipe&&a.endTime-a.startTime<300){var g=a.startTouchEvent,h=Array.prototype.slice.call(a.moveTouchEventList,-1)[0];if(Math.abs(h.pageX-g.pageX)>30||Math.abs(h.pageY-g.pageY)>30){var i=d._getSwipeDirection(g.pageX,g.pageY,h.pageX,h.pageY),j="swipe"+i;d.triggerListener("log",j),a.endTouchEvent.swipeDirection=i,d.triggerListener(j,d._createEventData(a.endTouchEvent,j)),d.triggerListener("swipe",d._createEventData(a.endTouchEvent,"swipe")),console.log("swipe",j)}return this}}}},a.Gesture.prototype._initForPC=function(){var a=this,b=null,c=null,d=!1,e=null,f=-1,g=0;this.option.target.addEventListener("mousedown",function(c){c.identifier=++g,b=a._createEventData(c),f=setTimeout(function(){console.log("longtap",Date.now(),"..."),a.triggerListener("log","long tap ..."),a.triggerListener("longtap",a._createEventData(b,"longtap"))},750)}),this.option.target.addEventListener("mousemove",function(e){if(a.triggerListener("mousemove",a._createEventData(e,"mousemove")),b){if(b&&e.clientX===b.clientX&&e.clientY===b.clientY)return;if(c&&e.clientX===b.clientX&&e.clientY===b.clientY)return;clearTimeout(f),d||(a.triggerListener("dragstart",a._createEventData(b,"dragstart")),d=!0),e.identifier=g,a.triggerListener("dragging",a._createEventData(e,"dragging"))}else clearTimeout(f)}),this.option.target.addEventListener("mouseup",function(h){if(h.identifier=g,c=a._createEventData(h),d){if(clearTimeout(f),a.triggerListener("dragend",a._createEventData(h,"dragend")),d&&c.createTime-b.createTime<300&&(Math.abs(c.pageX-b.pageX)>30||Math.abs(c.pageY-b.pageY)>30)){var i=a._getSwipeDirection(b.pageX,b.pageY,c.pageX,c.pageY),j="swipe"+i;a.triggerListener("log",j),b.swipeDirection=i,a.triggerListener(j,a._createEventData(b,j)),a.triggerListener("swipe",a._createEventData(b,"swipe")),console.log("swipe",j)}return d=!1,b=null,null}if(!d&&b&&c.createTime-b.createTime<300){clearTimeout(f);var k=a._createEventData(b,"tap");return a.triggerListener("tap",k),a.triggerListener("log","tap triggered"),e&&k.createTime-e.createTime<300&&Math.abs(e.pageX-k.pageX)<10&&Math.abs(e.pageY-k.pageY)<10?(a.triggerListener("doubletap",a._createEventData(k,"doubletap")),a.triggerListener("log","doubletap triggered"),e=null,this):(e=k,b=null,this)}})},a.Gesture.prototype._createEventData=function(b,c){var d={type:"",target:null,identifier:-1,clientX:0,clientY:0,pageX:0,pageY:0,screenX:0,screenY:0,force:1,swipeDirection:"",createTime:Date.now()};return d=a.utils.extend(d,b),d.type=c,d},a.Gesture.prototype._getSwipeDirection=function(a,b,c,d){return Math.abs(a-c)>=Math.abs(b-d)?a-c>0?"left":"right":b-d>0?"up":"down"},a.Gesture.prototype.getZoomRateAndRotateAngle=function(b,c){this.triggerListener("log","preLife"),this.triggerListener("log",b),this.triggerListener("log","curLife"),this.triggerListener("log",c);var d=b.startTouchEvent.pageX,e=b.startTouchEvent.pageY,f=c.startTouchEvent.pageX,g=c.startTouchEvent.pageY,h=b.moveTouchEventList.length>0?b.moveTouchEventList[b.moveTouchEventList.length-1]:b.startTouchEvent,i=c.moveTouchEventList.length>0?c.moveTouchEventList[c.moveTouchEventList.length-1]:c.startTouchEvent,j=h.pageX,k=h.pageY,l=i.pageX,m=i.pageY,n=new a.Math.Vector(f-d,g-e),o=new a.Math.Vector(l-j,m-k),p=Math.acos(o.dot(n)/(o.getLength()*n.getLength()))/Math.PI*180; return{rate:o.getLength()/n.getLength(),angle:p*(o.cross(n).z>0?-1:1)}},a.Gesture.prototype.enableMutiTouch=function(a){this.option.useMulti=!1}}(Ycc),function(a){var b=0;a.Layer=function(c,d){a.Listener.call(this),d=d||{},this.yccClass=a.Layer,this.uiList=[],this.uiCountRecursion=0,this.uiCountRendered=0,this.yccInstance=c,this.ctx=null,this.useCache=!1,this.ctxCache=null,this.ctxCacheRect=null,this.renderCacheRect=!1,this.id=b++,this.type="ui",this.textValue="",this.name=d.name?d.name:"图层_"+this.type+"_"+this.id,this.x=0,this.y=0,this.width=c.getStageWidth(),this.height=c.getStageHeight(),this.show=!0,this.ghost=!1,this.enableEventManager=!1,this.enableFrameEvent=!1,this.onFrameComing=function(){},a.utils.extend(this,d),this.init()},a.Layer.prototype=new a.Listener,a.Layer.prototype.constructor=a.Layer,a.Layer.release=function(b){a.Listener.release(b),b.yccClass=null,b.uiList=null,b.yccInstance=null,b.show=!1,b.enableEventManager=!1,b.enableFrameEvent=!1,b.onFrameComing=null},a.Layer.prototype.init=function(){var a=this;this.ctx=this.yccInstance.ctx,this.ctxCache=this.useCache?this.yccInstance.createCacheCtx({width:this.width*this.yccInstance.dpi,height:this.height*this.yccInstance.dpi}):this.ctx,a._setCtxProps()},a.Layer.prototype._initEvent=function(){function b(b){if(!b.stop&&!(e&&b.x===e.x&&b.y===e.y||f&&b.x===f.x&&b.y===f.y)){if(g=!0,e){if(!h){var c=new a.Event({type:"dragstart",x:e.x,y:e.y,mouseDownYccEvent:e});d.triggerListener(c.type,c),e.target&&(c.target=e.target,c.target.triggerListener(c.type,c))}h=!0;var i=new a.Event({type:"dragging",x:b.x,y:b.y,mouseDownYccEvent:e});return d.triggerListener(i.type,i),e.target&&(i.target=e.target,i.target.triggerListener(i.type,i)),null}for(var j=d.uiList.length-1;j>=0;j--){var k=d.uiList[j],l=new a.Math.Dot(b.x-k.belongTo.x,b.y-k.belongTo.y);if(l.isInRect(k.rect)){b.stop=!0,b.mouseDownYccEvent=e,b.mouseUpYccEvent=f,b.target=k,k.triggerListener(b.type,b);break}}}}function c(b){if(!b.stop)for(var c=d.uiList.length-1;c>=0;c--){var g=d.uiList[c],h=new a.Math.Dot(b.x,b.y);if(g.rect&&h.isInRect(g.getAbsolutePosition())&&b.stop===!1){b.stop=!0,b.mouseDownYccEvent=e,b.mouseUpYccEvent=f,b.target=g,b.targetDeltaPosition=new a.Math.Dot(b.x-g.getAbsolutePosition().x,b.y-g.getAbsolutePosition().y),g.triggerListener(b.type,b);break}}}var d=this,e=null,f=null,g=!1,h=!1;this.addListener("click",function(a){g||c(a)}),this.addListener("mousedown",function(a){g=!1,h=!1,e=a,c(a)}),this.addListener("mouseup",function(b){if(h){var g=new a.Event({type:"dragend",x:b.x,y:b.y,mouseDownYccEvent:e});d.triggerListener("dragend",g),e&&e.target&&(d.target=e.target,d.target.triggerListener("dragend",g))}b.mouseDownYccEvent=e=null,f=b,c(b)}),this.addListener("mousemove",b)},a.Layer.prototype._setCtxProps=function(b,c){var d=this;c=c||d.ctx;var e={fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",fontSize:"16px",fontFamily:"微软雅黑",font:"16px 微软雅黑",textBaseline:"hanging",fillStyle:"red",strokeStyle:"blue"};e=a.utils.extend(e,b),e.fontSize=parseInt(e.fontSize)*this.yccInstance.getSystemInfo().devicePixelRatio+"px",e.font=[e.fontStyle,e.fontVariant,e.fontWeight,e.fontSize,e.fontFamily].join(" ");for(var f in e)e.hasOwnProperty(f)&&(c[f]=e[f])},a.Layer.prototype.clear=function(){this.ctx.clearRect(0,0,this.width,this.height)},a.Layer.prototype.removeAllUI=function(){this.uiList.forEach(function(b){a.UI.release(b)}),this.uiList.length=0,this.updateCache()},a.Layer.prototype.removeSelf=function(){this.removeAllUI(),this.yccInstance.layerManager.deleteLayer(this),a.Layer.release(this)},a.Layer.prototype.renderToStage=function(){this.show&&this.yccInstance.ctx.drawImage(this.ctx.canvas,0,0,this.width,this.height)},a.Layer.prototype.addUI=function(a,b){var c=this;a.itor().each(function(a){a.init(c)});var d=this.uiList.indexOf(b);return b&&d!==-1?(this.uiList.splice(d,0,a),a._onAdded&&a._onAdded(),this.updateCache(),a):(this.uiList.push(a),a._onAdded&&a._onAdded(),a)},a.Layer.prototype.removeUI=function(b){if(!b)return!1;var c=this.uiList.indexOf(b);return c!==-1&&(a.UI.release(b),this.uiList[c]=null,this.uiList.splice(c,1),this.updateCache(),!0)},a.Layer.prototype.render=function(a){this.reRender(a)},a.Layer.prototype.reRender=function(a){if(this.show)return this.useCache?this.renderCacheToStage(a):void this.renderAllToCtx(this.ctx)},a.Layer.prototype.renderCacheToStage=function(a){if(this.useCache){a&&this.updateCache();var b=this.yccInstance.dpi;if(this.ctxCacheRect){var c=this.ctxCacheRect.x*b,d=this.ctxCacheRect.y*b,e=this.ctxCacheRect.width*b,f=this.ctxCacheRect.height*b;this.ctx.drawImage(this.ctxCache.canvas,c,d,e,f,c,d,e,f)}else this.ctx.drawImage(this.ctxCache.canvas,0,0);this.ctx.draw&&this.ctx.draw()}},a.Layer.prototype.getUIFromPointer=function(b,c){c=!a.utils.isBoolean(c)||c;for(var d=this,e=null,f=0,g=0;g<this.uiList.length;g++){var h=d.uiList[g];c&&!h.show||this.uiList[g].itor().depthDown(function(a,d){return a.ghost?-1:c&&!a.show?-1:void(a.containDot(b)&&d>=f&&(e=a,f=d))})}return e},a.Layer.prototype.getUIListFromPointer=function(a){for(var b=[],c=0;c<this.uiList.length;c++)this.uiList[c].itor().depthDown(function(c,d){c.containDot(a)&&b.push(c)});return b},a.Layer.prototype.transformToAbsolute=function(b){var c=null;if(a.utils.isArray(b)){c=[];for(var d=0;d<b.length;d++){var e=new a.Math.Dot(0,0),f=b[d];e.x=this.x+f.x,e.y=this.y+f.y,c.push(e)}return c}return c=new a.Math.Dot(0,0),c.x=this.x+b.x,c.y=this.y+b.y,c},a.Layer.prototype.transformToLocal=function(b){var c=null;if(a.utils.isArray(b)){c=[];for(var d=0;d<b.length;d++){var e=new a.Math.Dot(0,0),f=b[d];e.x=f.x-this.x,e.y=f.y-this.y,c.push(e)}return c}return c=new a.Math.Dot(0,0),c.x=b.x-this.x,c.y=b.y-this.y,c},a.Layer.prototype.renderAllToCtx=function(a){var b=this;b.uiCountRecursion=0,b.uiCountRendered=0;for(var c=0;c<this.uiList.length;c++)this.uiList[c].show&&(this.uiList[c].itor().depthDown(function(a,c){if(b.uiCountRecursion++,!a.show)return-1;var d=a.__render();b.useCache&&b._mergeCtxCacheRect(a.getAbsolutePositionRect()),d||b.uiCountRendered++}),this.uiList[c]._onChildrenRendered&&this.uiList[c]._onChildrenRendered());var d=this.ctxCacheRect;if(this.useCache&&d&&this.renderCacheRect){var e=this.yccInstance.dpi,f=this.yccInstance.getStageWidth()/e,g=this.yccInstance.getStageHeight()/e,h=d.x<0?0:d.x,i=d.y<0?0:d.y,j=d.width>f?f:d.width,k=d.height>g?g:d.height;a.save(),a.beginPath(),a.strokeStyle="red",a.strokeWidth=2,a.rect(h*e,i*e,j*e,k*e),a.closePath(),a.stroke(),a.restore()}a.draw&&a.draw()},a.Layer.prototype._mergeCtxCacheRect=function(b){var c=this.yccInstance;if(!this.ctxCacheRect)return this.ctxCacheRect=new a.Math.Rect(b);var d=c.getStageWidth(),e=c.getStageHeight(),f=c.dpi,g=this.ctxCacheRect,h=g.x+g.width,i=g.y+g.height,j=b.x+b.width,k=b.y+b.height;return g.x=g.x<b.x?g.x:b.x,g.y=g.y<b.y?g.y:b.y,g.width=h<j?j-g.x:h-g.x,g.height=i<k?k-g.y:i-g.y,g.x=g.x<0?0:g.x,g.y=g.y<0?0:g.y,g.width=g.x+g.width>d/f?d/f-g.x:g.width,g.height=g.y+g.height>e/f?e/f-g.y:g.height,g},a.Layer.prototype.updateCache=function(){this.useCache&&(this.clearCache(),this.renderAllToCtx(this.ctxCache))},a.Layer.prototype.clearCache=function(){var a=this.ctxCache.canvas.width;this.ctxCache.canvas.width=a,this.ctxCacheRect=null}}(Ycc),function(a){a.LayerManager=function(a){this.yccInstance=a,this.renderTime=0,this.maxRenderTime=0,this.renderUiCount=0},a.LayerManager.prototype.init=function(){},a.LayerManager.prototype.newLayer=function(b){var c=new a.Layer(this.yccInstance,b);return this.yccInstance.layerList.push(c),c},a.LayerManager.prototype.deleteLayer=function(a){for(var b=this.yccInstance.layerList,c=0;c<b.length;c++)if(b[c].id===a.id)return this.yccInstance.layerList.splice(c,1),a;return a},a.LayerManager.prototype.deleteAllLayer=function(){for(var b=0;b<this.yccInstance.layerList.length;b++){var c=this.yccInstance.layerList[b];c.removeAllUI(),a.Layer.release(c),c=null}this.yccInstance.layerList=[]},a.LayerManager.prototype.reRenderAllLayerToStage=function(a){var b=this.yccInstance;if(b.ticker.currentFrame&&b.ticker.currentFrame.isRendered)return console.log("stop overdraw!");var c=Date.now();this.renderUiCount=0,this.yccInstance.clearStage();for(var d=0;d<this.yccInstance.layerList.length;d++){var e=this.yccInstance.layerList[d];e.show&&(e.reRender(a),this.renderUiCount+=e.uiCountRendered)}this.renderTime=Date.now()-c,this.maxRenderTime=this.renderTime>this.maxRenderTime?this.renderTime:this.maxRenderTime,b.ticker.currentFrame&&(b.ticker.currentFrame.isRendered=!0)},a.LayerManager.prototype.enableEventManagerOnly=function(a){if(!a)return!1;for(var b=0;b<this.yccInstance.layerList.length;b++)this.yccInstance.layerList[b].enableEventManager=!1;return a.enableEventManager=!0,this},a.LayerManager.prototype.enableEventManagerAll=function(a){for(var b=0;b<this.yccInstance.layerList.length;b++)this.yccInstance.layerList[b].enableEventManager=a;return this},a.LayerManager.prototype.renderAllLayerByJsonArray=function(b){if(!a.utils.isArray(b))return console.error("jsonArray is not an Array!",b);for(var c=this,d=0;d<b.length;d++){var e=b[d];if(!a.utils.isObj(e))return console.error("item in jsonArray should be an Object!",e);for(var f=c.newLayer(e.option),g=0;g<e.ui.length;g++){var h=e.ui[g];f.addUI(new a.UI[h.type](h.option))}f.render()}}}(Ycc),function(a){var b=function(a){this.imageData=a,this.createTime=new Date,this.id=this.createTime.getTime()};a.PhotoManager=function(a){this.yccInstance=a,this.ctx=a.ctx,this._photos=[]},a.PhotoManager.prototype.takePhoto=function(){return this._photos.push(new b(this.ctx.getImageData(0,0,this.yccInstance.getStageWidth(),this.yccInstance.getStageHeight()))),this},a.PhotoManager.prototype.getHistoryPhotos=function(){return this._photos},a.PhotoManager.prototype.showPhoto=function(a){return this.ctx.putImageData(a.imageData,0,0),a},a.PhotoManager.prototype.showLastPhoto=function(){var a=this._photos.length,b=!1;return a>=1&&(b=this._photos[a-1],this.showPhoto(b)),b},a.PhotoManager.prototype.delPhotoById=function(a){for(var b=this._photos.slice(0),c=0;c<b.length;c++)if(b[c].id===a)return b.splice(c+1,1),this._photos=b,b[c];return!1}}(Ycc),function(a){if(!a||!a.utils)return console.error("Error: Ycc.ui needs module `Ycc` and `Ycc.utils`!");a.utils.isObj,a.utils.isArray,a.utils.isString,a.utils.isNum,a.utils.extend;a.UI=function(b){this.yccClass=a.UI,this._photos=[],this.ctx=b.ctx,this.ctxWidth=b.getStageWidth(),this.ctxHeight=b.getStageHeight()},a.UI.prototype.text=function(a,b,c){return this.ctx.save(),c?this.ctx.fillText(b,a[0],a[1]):this.ctx.strokeText(b,a[0],a[1]),this.ctx.restore(),this},a.UI.prototype.line=function(a,b){return this.ctx.save(),this.ctx.beginPath(),this.ctx.moveTo(a[0],a[1]),this.ctx.lineTo(b[0],b[1]),this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore(),this},a.UI.prototype.rect=function(a,b,c){return this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(a[0],a[1],b[0]-a[0],b[1]-a[1]),this.ctx.closePath(),c?this.ctx.fill():this.ctx.stroke(),this.ctx.restore(),this},a.UI.prototype.ellipse=function(a,b,c,d,e){this.ctx.save();var f=b>c?b:c,g=b/f,h=c/f;return this.ctx.translate(a[0],a[1]),this.ctx.rotate(parseInt(d)*Math.PI/180),this.ctx.translate(-a[0],-a[1]),this.ctx.scale(g,h),this.ctx.beginPath(),this.ctx.arc(a[0]/g,a[1]/h,f,0,2*Math.PI,!1),this.ctx.closePath(),e?this.ctx.fill():this.ctx.stroke(),this.ctx.restore(),this},a.UI.prototype.circleArc=function(a,b,c,d,e){return this.ctx.save(),this.ctx.beginPath(),this.ctx.arc(a[0],a[1],b,c/180*Math.PI,d/180*Math.PI,e),this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore(),this},a.UI.prototype.sector=function(a,b,c,d,e,f){return this.ctx.save(),this.ctx.beginPath(),this.ctx.lineTo(a[0],a[1]),this.ctx.arc(a[0],a[1],b,c*Math.PI/180,d*Math.PI/180,f),this.ctx.lineTo(a[0],a[1]),this.ctx.closePath(),e?this.ctx.fill():this.ctx.stroke(),this.ctx.restore(),this},a.UI.prototype.foldLine=function(a){if(a.length<2)return console.error("Error: 参数错误!");this.ctx.save(),this.ctx.beginPath(),this.ctx.moveTo(a[0][0],a[0][1]);for(var b=0;b<a.length;b++)this.ctx.lineTo(a[b][0],a[b][1]);return this.ctx.stroke(),this.ctx.restore(),this},a.UI.prototype.circle=function(a,b,c){return this.ellipse(a,b,b,0,c),this},a.UI.prototype.image=function(a,b){var c=this;return b=b||[0,0],c.ctx.save(),c.ctx.beginPath(),c.ctx.drawImage(a,b[0],b[1]),c.ctx.closePath(),c.ctx.restore(),this},a.UI.prototype._getMaxLenContent=function(a,b){var c=a,d=0;if(this.ctx.measureText(a).width<=b)return a;for(var e=0;e<a.length;e++)if(c=a.slice(0,e),d=this.ctx.measureText(c).width,d>b)return a.slice(0,e-1)},a.UI.prototype.scale=function(a,b){return this.ctx.scale(a,b),this},a.UI.prototype.clear=function(){var a={fillStyle:"#fff"};return this.ctx.fillStyle=a.fillStyle,this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(0,0,this.ctxWidth,this.ctxHeight),this.ctx.fill(),this.ctx.closePath(),this.ctx.restore(),this}}(Ycc),function(a){var b=0,c=1;a.UI.Base=function(c){a.Listener.call(this),a.Tree.call(this),this.yccClass=a.UI.Base,this.id=b++,this.name="",this.ctx=null,this.ctxCache=null,this.dpi=1,this.rect=new a.Math.Rect,this.x=0,this.y=0,this.anchorX=0,this.anchorY=0,this.rotation=0,this.rectBgColor="rgba(0,0,0,0)",this.rectBorderWidth=0,this.rectBorderColor="#000",this.show=!0,this.ghost=!1,this.stopEventBubbleUp=!0,this.opacity=1,this.lineWidth=1,this.fillStyle="black",this.strokeStyle="black",this.belongTo=null,this.userData=null,this.isShowRotateBeforeUI=!1,this.baseUI=null,this._beforeInit=null,this._afterInit=null,this._onAdded=null,this._onChildrenRendered=null,this.oncomputestart=null,this.oncomputeend=null,this.onrenderstart=null,this.onrenderend=null,this.extend(c)},a.utils.mergeObject(a.UI.Base.prototype,a.Listener.prototype),a.utils.mergeObject(a.UI.Base.prototype,a.Tree.prototype),a.UI.Base.prototype.init=function(b){a.utils.isFn(this._beforeInit)&&this._beforeInit(),this.belongTo=b,this.ctx=b.ctx,this.ctxCache=this.belongTo.ctxCache,this.dpi=this.belongTo.yccInstance.getSystemInfo().devicePixelRatio,a.utils.isFn(this._afterInit)&&this._afterInit()},a.UI.Base.prototype.computeUIProps=function(){},a.UI.Base.prototype.renderRectBgColor=function(b){var c=b,d=this.getAbsolutePositionPolygon();if(!d||0===d.length)return console.log(new a.Debugger.Log("no polygon coordirates!").message);var e=this.ctxCache;e.save(),e.fillStyle=this.rectBgColor,e.beginPath(),e.moveTo(d[0].x*this.dpi,d[0].y*this.dpi);for(var f=1;f<d.length-1;f++)e.lineTo(d[f].x*this.dpi,d[f].y*this.dpi);e.closePath(),e.fill(),e.restore(),c=null},a.UI.Base.prototype.renderRectBorder=function(a){if(!(this.rectBorderWidth<=0)){var b=this.ctxCache,c=a;b.save(),b.strokeStyle=this.rectBorderColor,b.strokeWidth=this.rectBorderWidth,b.beginPath(),b.rect(c.x*this.dpi,c.y*this.dpi,c.width*this.dpi,c.height*this.dpi),b.closePath(),b.stroke(),b.restore(),c=null}},a.UI.Base.prototype.renderDashBeforeUI=function(a){},a.UI.Base.prototype.removeSelf=function(){this.belongTo.removeUI(this)},a.UI.Base.prototype.addChild=function(a){return this.belongTo&&a.init(this.belongTo),this.addChildTree(a),a},a.UI.Base.prototype.removeChild=function(b){return this.removeChildTree(b),a.UI.release(b),this},a.UI.Base.prototype.scaleAndRotate=function(){var a=this.getAbsolutePositionRect();this.ctx.translate(this.anchorX+a.x,this.anchorY+a.y),this.ctx.rotate(this.rotation*Math.PI/180),this.ctx.translate(-this.anchorX-a.x,-this.anchorY-a.y)},a.UI.Base.prototype.isOutOfStage=function(){var a=this.belongTo.yccInstance.getStageWidth(),b=this.belongTo.yccInstance.getStageHeight(),c=this.getAbsolutePositionRect();return c.x>a||c.x+c.width<0||c.y>b||c.y+c.height<0},a.UI.Base.prototype.isOutOfRect=function(a){var b=a.x,c=a.y,d=a.width,e=a.height,f=this.getAbsolutePositionRect();return f.x>d||f.x+f.width<b||f.y>e||f.y+f.height<c},a.UI.release=function(b){b.itor().leftChildFirst(function(b){b.yccClass!==a.UI.Image&&b.yccClass!==a.UI.ImageFrameAnimation||(b.res=null),a.Tree.release(b),a.Listener.release(b),b.yccInstance=null,b.yccClass=null,b.ctx=null,b.belongTo=null,b.userData=null,b.baseUI=null,b._beforeInit=null,b._afterInit=null,b.oncomputestart=null,b.oncomputeend=null,b.onrenderstart=null,b.onrenderend=null})},a.UI.Base.prototype.render=function(){},a.UI.Base.prototype._renderContainer=function(a){var b=a,c=this.ctxCache;c.save(),c.beginPath(),c.strokeStyle="#ff0000",c.rect(b.x*this.dpi,b.y*this.dpi,b.width*this.dpi,b.height*this.dpi),c.closePath(),c.stroke(),c.restore(),b=null},a.UI.Base.prototype.__render=function(){this.triggerListener("computestart",new a.Event("computestart"));var b=this.computeUIProps();if(this.triggerListener("computeend",new a.Event("computeend")),b)return b;if(!this.belongTo.useCache&&this.isOutOfStage())return{message:"UI超出舞台!"};if(this.belongTo.useCache&&this.isOutOfRect(new a.Math.Rect(0,0,this.ctxCache.canvas.width*this.dpi,this.ctxCache.canvas.height*this.dpi)))return{message:"UI超出离屏Canvas!"};this._processBeforeRender();var c=this.getAbsolutePositionRect();this.renderRectBgColor(c),this.renderRectBorder(c),this.renderDashBeforeUI(this.ctxCache),this.belongTo.yccInstance.config.debugDrawContainer&&this._renderContainer(c),this.render(),this._processAfterRender()},a.UI.Base.prototype._processBeforeRender=function(){this.triggerListener("renderstart",new a.Event("renderstart")),c=this.ctx.globalAlpha,this.ctx.globalAlpha=this.opacity},a.UI.Base.prototype._processAfterRender=function(){this.ctx.globalAlpha=c,this.triggerListener("renderend",new a.Event("renderend"))},a.UI.Base.prototype.getMaxContentInWidth=function(a,b){var c=a,d=0,e=this.ctxCache;if(e.measureText(a).width<=b)return a;for(var f=0;f<a.length;f++)if(c=a.slice(0,f+1),d=e.measureText(c).width,d>b)return a.slice(0,f)},a.UI.Base.prototype.extend=function(a){a=a||{};for(var b