diff --git a/dist/kinetic-core.js b/dist/kinetic-core.js index 835d30a7..b6639fdb 100644 --- a/dist/kinetic-core.js +++ b/dist/kinetic-core.js @@ -3,7 +3,7 @@ * http://www.kineticjs.com/ * Copyright 2012, Eric Rowell * Licensed under the MIT or GPL Version 2 licenses. - * Date: Sep 05 2012 + * Date: Sep 07 2012 * * Copyright (C) 2011 - 2012 by Eric Rowell * @@ -86,7 +86,7 @@ Kinetic.Global = { * to stop, resume, or restart the transition * @constructor */ -Kinetic.Transition = gamecore.Base.extend("Kinetic.Transition", {}, +gamecore.Base.extend("Kinetic.Transition", {}, //Instance methods { init: function(node, config) { @@ -185,7 +185,7 @@ Kinetic.Transition = gamecore.Base.extend("Kinetic.Transition", {}, * utilities that determine data type and transform * one type into another */ -Kinetic.Type = gamecore.Base.extend("Kinetic.Type", +gamecore.Base.extend("Kinetic.Type", //Static methods { /* @@ -463,7 +463,7 @@ Kinetic.Type = gamecore.Base.extend("Kinetic.Type", * @param {Number} width * @param {Number} height */ -Kinetic.Canvas = gamecore.Base.extend("Kinetic.Canvas", {}, +gamecore.Base.extend("Kinetic.Canvas", {}, //Instance methods { init: function(width, height) { @@ -565,7 +565,7 @@ Kinetic.Canvas = gamecore.Base.extend("Kinetic.Canvas", {}, * an animation of a single Node property. A Transition is a set of * multiple tweens */ -Kinetic.Tween = gamecore.Base.extend("Kinetic.Tween", +gamecore.Base.extend("Kinetic.Tween", //Static properties {}, //Instance methods @@ -914,7 +914,7 @@ Kinetic.Tweens = * class. */ -Kinetic.Transform = gamecore.Base.extend("Kinetic.Transform", {}, +gamecore.Base.extend("Kinetic.Transform", {}, //Instance methods { init: function() { @@ -1026,7 +1026,7 @@ Kinetic.Transform = gamecore.Base.extend("Kinetic.Transform", {}, * @param {Object} config * @param {Function} config.func function to be executed on each animation frame */ -Kinetic.Animation = gamecore.Base.extend("Kinetic.Animation", +gamecore.Base.extend("Kinetic.Animation", //Static methods { animations: [], @@ -1178,7 +1178,7 @@ requestAnimFrame = (function(callback) { * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Node = gamecore.Base.extend("Kinetic.Node", +gamecore.Base.extend("Kinetic.Node", //Static methods { // add getter and setter methods @@ -2443,7 +2443,7 @@ Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']); * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Container = Kinetic.Node.extend("Kinetic.Container", +Kinetic.Node.extend("Kinetic.Container", //Static methods { }, @@ -2689,7 +2689,7 @@ Kinetic.Container = Kinetic.Node.extend("Kinetic.Container", * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Stage = Kinetic.Container.extend("Kinetic.Stage", {}, +Kinetic.Container.extend("Kinetic.Stage", {}, //Instance methods { init: function(config) { @@ -3522,7 +3522,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Stage, ['width', 'height']); * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Layer = Kinetic.Container.extend("Kinetic.Layer", {}, +Kinetic.Container.extend("Kinetic.Layer", {}, //Instance methods { init: function(config){ @@ -3727,7 +3727,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Layer, ['clearBeforeDraw']); * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Group = Kinetic.Container.extend("Kinetic.Group", {}, +Kinetic.Container.extend("Kinetic.Group", {}, //Instance methods { init: function(config) { @@ -3797,7 +3797,7 @@ Kinetic.Group = Kinetic.Container.extend("Kinetic.Group", {}, * @param {Number} [config.dragBounds.bottom] * @param {Number} [config.dragBounds.left] */ -Kinetic.Shape = Kinetic.Node.extend("Kinetic.Shape", {}, +Kinetic.Node.extend("Kinetic.Shape", {}, //Instance methods { init: function(config){ @@ -4254,7 +4254,8 @@ Kinetic.Node.addGettersSetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'st * @param {Number} [config.height] * @param {Object} [config.crop] */ -Kinetic.Image = Kinetic.Shape.extend("Kinetic.Image", {}, + + Kinetic.Shape.extend("Kinetic.Image", {}, //Instance methods { init: function(config) { @@ -4481,7 +4482,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Image, ['image', 'crop', 'filter', 'width * @augments Kinetic.Shape * @param {Object} config */ -Kinetic.Circle = Kinetic.Shape.extend("Kinetic.Circle", {}, +Kinetic.Shape.extend("Kinetic.Circle", {}, { init: function(config) { this.setDefaultAttrs({ @@ -4528,7 +4529,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Circle, ['radius']); * @augments Kinetic.Shape * @param {Object} config */ -Kinetic.Rect = Kinetic.Shape.extend("Kinetic.Rect", {}, +Kinetic.Shape.extend("Kinetic.Rect", {}, { init: function(config) { this.setDefaultAttrs({ @@ -4637,7 +4638,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Rect, ['width', 'height', 'cornerRadius'] * @augments Kinetic.Shape * @param {Object} config */ -Kinetic.Text = Kinetic.Shape.extend("Kinetic.Text", {}, +Kinetic.Shape.extend("Kinetic.Text", {}, //Instance methods { init: function(config) { @@ -5033,7 +5034,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontSty * @augments Kinetic.Shape * @param {Object} config */ -Kinetic.Sprite = Kinetic.Shape.extend("Kinetic.Sprite", {}, +Kinetic.Shape.extend("Kinetic.Sprite", {}, //Instance methods { init: function(config) { @@ -5186,7 +5187,7 @@ Kinetic.Node.addGettersSetters(Kinetic.Sprite, ['animation', 'animations', 'inde * @augments Kinetic.Shape * @param {Object} config */ -Kinetic.TextPath = Kinetic.Shape.extend("Kinetic.TextPath", {}, +Kinetic.Shape.extend("Kinetic.TextPath", {}, //Instance methods { init: function(config) { diff --git a/dist/kinetic-core.min.js b/dist/kinetic-core.min.js index 807f08bc..c3633912 100644 --- a/dist/kinetic-core.min.js +++ b/dist/kinetic-core.min.js @@ -3,7 +3,7 @@ * http://www.kineticjs.com/ * Copyright 2012, Eric Rowell * Licensed under the MIT or GPL Version 2 licenses. - * Date: Sep 06 2012 + * Date: Sep 07 2012 * * Copyright (C) 2011 - 2012 by Eric Rowell * @@ -25,5 +25,5 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -var Kinetic={};Kinetic.Plugins={},Kinetic.Global={BUBBLE_WHITELIST:["mousedown","mousemove","mouseup","mouseover","mouseout","click","dblclick","touchstart","touchmove","touchend","tap","dbltap","dragstart","dragmove","dragend"],BUFFER_WHITELIST:["fill","stroke","textFill","textStroke"],BUFFER_BLACKLIST:["shadow"],stages:[],idCounter:0,tempNodes:{},shapes:{},maxDragTimeInterval:20,drag:{moving:!1,offset:{x:0,y:0},lastDrawTime:0},warn:function(e){console&&console.warn&&console.warn("Kinetic warning: "+e)},_pullNodes:function(e){var t=this.tempNodes;for(var n in t){var r=t[n];r.getStage()!==undefined&&r.getStage()._id===e._id&&(e._addId(r),e._addName(r),this._removeTempNode(r))}},_addTempNode:function(e){this.tempNodes[e._id]=e},_removeTempNode:function(e){delete this.tempNodes[e._id]}},Kinetic.Transition=gamecore.Base.extend("Kinetic.Transition",{},{init:function(e,t){function r(e,t,i,s){for(var o in e)o!=="duration"&&o!=="easing"&&o!=="callback"&&(Kinetic.Type._isObject(e[o])?(i[o]={},r(e[o],t[o],i[o],s)):n._add(n._getTween(t,o,e[o],i,s)))}this.node=e,this.config=t,this.tweens=[];var n=this,i={};r(t,e.attrs,i,i);var s=0;for(var o=0;o=n.tweens.length&&n.onFinished()}}},start:function(){for(var e=0;e0},_getXY:function(e){if(this._isNumber(e))return{x:e,y:e};if(this._isArray(e)){if(e.length===1){var t=e[0];if(this._isNumber(t))return{x:t,y:t};if(this._isArray(t))return{x:t[0],y:t[1]};if(this._isObject(t))return t}else if(e.length>=2)return{x:e[0],y:e[1]}}else if(this._isObject(e))return e;return{x:0,y:0}},_getSize:function(e){if(this._isNumber(e))return{width:e,height:e};if(this._isArray(e))if(e.length===1){var t=e[0];if(this._isNumber(t))return{width:t,height:t};if(this._isArray(t)){if(t.length>=4)return{width:t[2],height:t[3]};if(t.length>=2)return{width:t[0],height:t[1]}}else if(this._isObject(t))return t}else{if(e.length>=4)return{width:e[2],height:e[3]};if(e.length>=2)return{width:e[0],height:e[1]}}else if(this._isObject(e))return e;return{width:0,height:0}},_getPoints:function(e){if(e===undefined)return[];if(this._isObject(e[0]))return e;var t=[];for(var n=0;n>16&255,g:t>>8&255,b:t&255}},_getRandomColorKey:function(){var e=Math.round(Math.random()*255),t=Math.round(Math.random()*255),n=Math.round(Math.random()*255);return this._rgbToHex(e,t,n)}},{}),Kinetic.Canvas=gamecore.Base.extend("Kinetic.Canvas",{},{init:function(e,t){this.element=document.createElement("canvas"),this.context=this.element.getContext("2d"),this.element.width=e,this.element.height=t},clear:function(){var e=this.getContext(),t=this.getElement();e.clearRect(0,0,t.width,t.height)},getElement:function(){return this.element},getContext:function(){return this.context},setWidth:function(e){this.element.width=e},setHeight:function(e){this.element.height=e},getWidth:function(){return this.element.width},getHeight:function(){return this.element.height},setSize:function(e,t){this.setWidth(e),this.setHeight(t)},toDataURL:function(e,t){try{return this.element.toDataURL(e,t)}catch(n){return this.element.toDataURL()}}}),Kinetic.Tween=gamecore.Base.extend("Kinetic.Tween",{},{init:function(e,t,n,r,i,s){this._listeners=[],this.addListener(this),this.obj=e,this.propFunc=t,this.begin=r,this._pos=r,this.setDuration(s),this.isPlaying=!1,this._change=0,this.prevTime=0,this.prevPos=0,this.looping=!1,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.name="",this.func=n,this.setFinish(i)},setTime:function(e){this.prevTime=this._time,e>this.getDuration()?this.looping?(this.rewind(e-this._duration),this.update(),this.broadcastMessage("onLooped",{target:this,type:"onLooped"})):(this._time=this._duration,this.update(),this.stop(),this.broadcastMessage("onFinished",{target:this,type:"onFinished"})):e<0?(this.rewind(),this.update()):(this._time=e,this.update())},getTime:function(){return this._time},setDuration:function(e){this._duration=e===null||e<=0?1e5:e},getDuration:function(){return this._duration},setPosition:function(e){this.prevPos=this._pos,this.propFunc(e),this._pos=e,this.broadcastMessage("onChanged",{target:this,type:"onChanged"})},getPosition:function(e){return e===undefined&&(e=this._time),this.func(e,this.begin,this._change,this._duration)},setFinish:function(e){this._change=e-this.begin},getFinish:function(){return this.begin+this._change},start:function(){this.rewind(),this.startEnterFrame(),this.broadcastMessage("onStarted",{target:this,type:"onStarted"})},rewind:function(e){this.stop(),this._time=e===undefined?0:e,this.fixTime(),this.update()},fforward:function(){this._time=this._duration,this.fixTime(),this.update()},update:function(){this.setPosition(this.getPosition(this._time))},startEnterFrame:function(){this.stopEnterFrame(),this.isPlaying=!0,this.onEnterFrame()},onEnterFrame:function(){this.isPlaying&&this.nextFrame()},nextFrame:function(){this.setTime((this.getTimer()-this._startTime)/1e3)},stop:function(){this.stopEnterFrame(),this.broadcastMessage("onStopped",{target:this,type:"onStopped"})},stopEnterFrame:function(){this.isPlaying=!1},continueTo:function(e,t){this.begin=this._pos,this.setFinish(e),this._duration!==undefined&&this.setDuration(t),this.start()},resume:function(){this.fixTime(),this.startEnterFrame(),this.broadcastMessage("onResumed",{target:this,type:"onResumed"})},yoyo:function(){this.continueTo(this.begin,this._time)},addListener:function(e){return this.removeListener(e),this._listeners.push(e)},removeListener:function(e){var t=this._listeners,n=t.length;while(n--)if(t[n]==e)return t.splice(n,1),!0;return!1},broadcastMessage:function(){var e=[];for(var t=0;t0){this._runFrames();var e=this;requestAnimFrame(function(){e._animationLoop()})}else this.animRunning=!1},_handleAnimation:function(){var e=this;this.animRunning||(this.animRunning=!0,e._animationLoop())}},{init:function(e){e||(e={});for(var t in e)this[t]=e[t];this.frame={time:0,timeDiff:0,lastTime:(new Date).getTime()},this.id=Kinetic.Animation.animIdCounter++},start:function(){this.stop(),this.frame.lastTime=(new Date).getTime(),Kinetic.Animation._addAnimation(this),Kinetic.Animation._handleAnimation()},stop:function(){Kinetic.Animation._removeAnimation(this)}}),requestAnimFrame=function(e){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}(),Kinetic.Node=gamecore.Base.extend("Kinetic.Node",{addSetters:function(e,t){for(var n=0;n1?o[1]:"";this.eventListeners[u]||(this.eventListeners[u]=[]),this.eventListeners[u].push({name:a,handler:t})}},off:function(e){var t=e.split(" ");for(var n=0;n1){var u=s[1];for(var a=0;a0&&s[0].getLevel()<=e&&i(s)}var e=this.getLevel(),t=this.getStage(),n=this,r=0;return n.nodeType!=="Stage"&&i(n.getStage().getChildren()),r},getLevel:function(){var e=0,t=this.parent;while(t)e++,t=t.parent;return e},setPosition:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments));this.setAttrs(e)},getPosition:function(){return{x:this.attrs.x,y:this.attrs.y}},getAbsolutePosition:function(){var e=this.getAbsoluteTransform(),t=this.getOffset();return e.translate(t.x,t.y),e.getTranslation()},setAbsolutePosition:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),t=this._clearTransform();this.attrs.x=t.x,this.attrs.y=t.y,delete t.x,delete t.y;var n=this.getAbsoluteTransform();n.invert(),n.translate(e.x,e.y),e={x:this.attrs.x+n.getTranslation().x,y:this.attrs.y+n.getTranslation().y},this.setPosition(e.x,e.y),this._setTransform(t)},move:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),t=this.getX(),n=this.getY();e.x!==undefined&&(t+=e.x),e.y!==undefined&&(n+=e.y),this.setAttrs({x:t,y:n})},getRotationDeg:function(){return this.attrs.rotation*180/Math.PI},rotate:function(e){this.setAttrs({rotation:this.getRotation()+e})},rotateDeg:function(e){this.setAttrs({rotation:this.getRotation()+e*Math.PI/180})},moveToTop:function(){var e=this.index;this.parent.children.splice(e,1),this.parent.children.push(this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.appendChild(this.canvas.element))}},moveUp:function(){var e=this.index;if(e0){this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.insertBefore(this.canvas.element,t.getChildren()[this.index+1].canvas.element))}}},moveToBottom:function(){var e=this.index;this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.insertBefore(this.canvas.element,t.getChildren()[1].canvas.element))}},setZIndex:function(e){var t=this.index;this.parent.children.splice(t,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices()},getAbsoluteOpacity:function(){var e=1,t=this;while(t.nodeType!=="Stage")e*=t.attrs.opacity,t=t.parent;return e},isDragging:function(){var e=Kinetic.Global;return e.drag.node&&e.drag.node._id===this._id&&e.drag.moving},moveTo:function(e){var t=this.parent;t.children.splice(this.index,1),t._setChildrenIndices(),e.children.push(this),this.index=e.children.length-1,this.parent=e,e._setChildrenIndices()},getParent:function(){return this.parent},getLayer:function(){return this.nodeType==="Layer"?this:this.getParent().getLayer()},getStage:function(){return this.nodeType!=="Stage"&&this.getParent()?this.getParent().getStage():this.nodeType==="Stage"?this:undefined},simulate:function(e){this._handleEvent(e,{})},transitionTo:function(e){var t=this.nodeType==="Stage"?this:this.getLayer(),n=this,r=new Kinetic.Transition(this,e);return this.transAnim.func=function(){r._onEnterFrame()},this.transAnim.node=t,r.onFinished=function(){n.transAnim.stop(),n.transAnim.node.draw(),e.callback&&e.callback()},r.start(),this.transAnim.start(),r},getAbsoluteTransform:function(){var e=new Kinetic.Transform,t=[],n=this.parent;t.unshift(this);while(n)t.unshift(n),n=n.parent;for(var r=0;r=0&&!t.cancelBubble&&this.parent&&(n&&n.parent?this._handleEvent.call(this.parent,e,t,n.parent):this._handleEvent.call(this.parent,e,t))}},_draw:function(e){if(this.isVisible()&&(!e||e.name!=="buffer"||this.getListening())){this.__draw&&this.__draw(e);var t=this.children;if(t)for(var n=0;n0)this.remove(this.children[0])},add:function(e){e._id=Kinetic.Global.idCounter++,e.index=this.children.length,e.parent=this,this.children.push(e);var t=e.getStage();if(!t)Kinetic.Global._addTempNode(e);else{t._addId(e),t._addName(e);var n=Kinetic.Global;n._pullNodes(t)}return this._add!==undefined&&this._add(e),this},remove:function(e){if(e&&e.index!==undefined&&this.children[e.index]._id==e._id){var t=this.getStage();t&&(t._removeId(e.getId()),t._removeName(e.getName(),e._id)),Kinetic.Global._removeTempNode(e),this.children.splice(e.index,1),this._setChildrenIndices();while(e.children&&e.children.length>0)e.remove(e.children[0]);e._remove!==undefined&&e._remove()}return this},get:function(e){var t=this.getStage(),n,r=e.slice(1);if(e.charAt(0)==="#")n=t.ids[r]!==undefined?[t.ids[r]]:[];else{if(e.charAt(0)!==".")return e==="Shape"||e==="Group"||e==="Layer"?this._getNodes(e):!1;n=t.names[r]!==undefined?t.names[r]:[]}var i=[];for(var s=0;s=0;r--){var i=n[r],s=i.bufferCanvas.context.getImageData(Math.round(e.x),Math.round(e.y),1,1).data;if(s[3]===255){var o=Kinetic.Type._rgbToHex(s[0],s[1],s[2]);return t=Kinetic.Global.shapes[o],{shape:t,pixel:s}}if(s[0]>0||s[1]>0||s[2]>0||s[3]>0)return{pixel:s}}return null},_resizeDOM:function(){var e=this.attrs.width,t=this.attrs.height;this.content.style.width=e+"px",this.content.style.height=t+"px",this.bufferCanvas.setSize(e,t);var n=this.children;for(var r=0;ro.right&&(a.x=o.right),o.top!==undefined&&a.yo.bottom&&(a.y=o.bottom),r.setAbsolutePosition(a),s==="horizontal"?r.attrs.y=u.y:s==="vertical"&&(r.attrs.x=u.x),n.drag.moving||(n.drag.moving=!0,n.drag.node._handleEvent("dragstart",e)),n.drag.node._handleEvent("dragmove",e)}},_buildDOM:function(){this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.display="inline-block",this.content.className="kineticjs-content",this.attrs.container.appendChild(this.content),this.bufferCanvas=new Kinetic.Canvas({width:this.attrs.width,height:this.attrs.height}),this._resizeDOM()},_addId:function(e){e.attrs.id!==undefined&&(this.ids[e.attrs.id]=e)},_removeId:function(e){e!==undefined&&delete this.ids[e]},_addName:function(e){var t=e.attrs.name;t!==undefined&&(this.names[t]===undefined&&(this.names[t]=[]),this.names[t].push(e))},_removeName:function(e,t){if(e!==undefined){var n=this.names[e];if(n!==undefined){for(var r=0;r0},_remove:function(){delete Kinetic.Global.shapes[this.colorKey]},__draw:function(e){if(this.attrs.drawFunc){var t=this.getStage(),n=e.getContext(),r=[],i=this.parent;r.unshift(this);while(i)r.unshift(i),i=i.parent;n.save();for(var s=0;s0&&r&&(this.attrs.height==="auto"||i*(n+1)this.attrs.width-this.attrs.padding*2){if(s==0)break;var a=u.lastIndexOf(" "),f=u.lastIndexOf("-"),l=Math.max(a,f);if(l>=0){o=e.splice(0,1+l).join("");break}o=e.splice(0,s).join("");break}s++,s===e.length&&(o=e.splice(0,s).join(""))}this.textWidth=Math.max(this.textWidth,this._getTextSize(o).width),o!==undefined&&(t.push(o),r=!0),n++}this.textArr=t}}),Kinetic.Node.addGettersSetters(Kinetic.Text,["fontFamily","fontSize","fontStyle","textFill","textStroke","textStrokeWidth","padding","align","lineHeight","text","width","height","cornerRadius","fill","stroke","strokeWidth","shadow"]),Kinetic.Sprite=Kinetic.Shape.extend("Kinetic.Sprite",{},{init:function(e){this.setDefaultAttrs({index:0,frameRate:17}),e.drawFunc=this.drawFunc,this._super(e),this.anim=new Kinetic.Animation;var t=this;this.on("animationChange.kinetic",function(){t.setIndex(0)})},drawFunc:function(e){var t=this.attrs.animation,n=this.attrs.index,r=this.attrs.animations[t][n];e.beginPath(),e.rect(0,0,r.width,r.height),e.closePath(),this.fill(e),this.stroke(e),this.attrs.image&&(e.beginPath(),e.rect(0,0,r.width,r.height),e.closePath(),this.drawImage(e,this.attrs.image,r.x,r.y,r.width,r.height,0,0,r.width,r.height))},start:function(){var e=this,t=this.getLayer();this.anim.node=t,this.interval=setInterval(function(){var t=e.attrs.index;e._updateIndex(),e.afterFrameFunc&&t===e.afterFrameIndex&&(e.afterFrameFunc(),delete e.afterFrameFunc,delete e.afterFrameIndex)},1e3/this.attrs.frameRate),this.anim.start()},stop:function(){this.anim.stop(),clearInterval(this.interval)},afterFrame:function(e,t){this.afterFrameIndex=e,this.afterFrameFunc=t},_updateIndex:function(){var e=this.attrs.index,t=this.attrs.animation;e0)return o=n,t[n];t[n].command=="M"&&(r={x:t[n].points[0],y:t[n].points[1]})}return{}},f=function(t,n){var o=e._getTextSize(t).width,f=0,l=0,c=!1;i=undefined;while(Math.abs(o-f)/o>.01&&l<25){l++;var h=f;while(s===undefined)s=a(),s&&h+s.pathLengtho?i=Kinetic.Path.getPointOnLine(o,r.x,r.y,s.points[0],s.points[1],r.x,r.y):s=undefined;break;case"A":var d=s.points[4],v=s.points[5],m=s.points[4]+v;u===0?u=d+1e-8:o>f?u+=Math.PI/180*v/Math.abs(v):u-=Math.PI/360*v/Math.abs(v),Math.abs(u)>Math.abs(m)&&(u=m,p=!0),i=Kinetic.Path.getPointOnEllipticalArc(s.points[0],s.points[1],s.points[2],s.points[3],u,s.points[6]);break;case"C":u===0?o>s.pathLength?u=1e-8:u=o/s.pathLength:o>f?u+=(o-f)/s.pathLength:u-=(f-o)/s.pathLength,u>1&&(u=1,p=!0),i=Kinetic.Path.getPointOnCubicBezier(u,s.start.x,s.start.y,s.points[0],s.points[1],s.points[2],s.points[3],s.points[4],s.points[5]);break;case"Q":u===0?u=o/s.pathLength:o>f?u+=(o-f)/s.pathLength:u-=(f-o)/s.pathLength,u>1&&(u=1,p=!0),i=Kinetic.Path.getPointOnQuadraticBezier(u,s.start.x,s.start.y,s.points[0],s.points[1],s.points[2],s.points[3])}i!==undefined&&(f=Kinetic.Path.getLineLength(r.x,r.y,i.x,i.y)),p&&(p=!1,s=undefined)}};for(var l=0;l=n.tweens.length&&n.onFinished()}}},start:function(){for(var e=0;e0},_getXY:function(e){if(this._isNumber(e))return{x:e,y:e};if(this._isArray(e)){if(e.length===1){var t=e[0];if(this._isNumber(t))return{x:t,y:t};if(this._isArray(t))return{x:t[0],y:t[1]};if(this._isObject(t))return t}else if(e.length>=2)return{x:e[0],y:e[1]}}else if(this._isObject(e))return e;return{x:0,y:0}},_getSize:function(e){if(this._isNumber(e))return{width:e,height:e};if(this._isArray(e))if(e.length===1){var t=e[0];if(this._isNumber(t))return{width:t,height:t};if(this._isArray(t)){if(t.length>=4)return{width:t[2],height:t[3]};if(t.length>=2)return{width:t[0],height:t[1]}}else if(this._isObject(t))return t}else{if(e.length>=4)return{width:e[2],height:e[3]};if(e.length>=2)return{width:e[0],height:e[1]}}else if(this._isObject(e))return e;return{width:0,height:0}},_getPoints:function(e){if(e===undefined)return[];if(this._isObject(e[0]))return e;var t=[];for(var n=0;n>16&255,g:t>>8&255,b:t&255}},_getRandomColorKey:function(){var e=Math.round(Math.random()*255),t=Math.round(Math.random()*255),n=Math.round(Math.random()*255);return this._rgbToHex(e,t,n)}},{}),gamecore.Base.extend("Kinetic.Canvas",{},{init:function(e,t){this.element=document.createElement("canvas"),this.context=this.element.getContext("2d"),this.element.width=e,this.element.height=t},clear:function(){var e=this.getContext(),t=this.getElement();e.clearRect(0,0,t.width,t.height)},getElement:function(){return this.element},getContext:function(){return this.context},setWidth:function(e){this.element.width=e},setHeight:function(e){this.element.height=e},getWidth:function(){return this.element.width},getHeight:function(){return this.element.height},setSize:function(e,t){this.setWidth(e),this.setHeight(t)},toDataURL:function(e,t){try{return this.element.toDataURL(e,t)}catch(n){return this.element.toDataURL()}}}),gamecore.Base.extend("Kinetic.Tween",{},{init:function(e,t,n,r,i,s){this._listeners=[],this.addListener(this),this.obj=e,this.propFunc=t,this.begin=r,this._pos=r,this.setDuration(s),this.isPlaying=!1,this._change=0,this.prevTime=0,this.prevPos=0,this.looping=!1,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.name="",this.func=n,this.setFinish(i)},setTime:function(e){this.prevTime=this._time,e>this.getDuration()?this.looping?(this.rewind(e-this._duration),this.update(),this.broadcastMessage("onLooped",{target:this,type:"onLooped"})):(this._time=this._duration,this.update(),this.stop(),this.broadcastMessage("onFinished",{target:this,type:"onFinished"})):e<0?(this.rewind(),this.update()):(this._time=e,this.update())},getTime:function(){return this._time},setDuration:function(e){this._duration=e===null||e<=0?1e5:e},getDuration:function(){return this._duration},setPosition:function(e){this.prevPos=this._pos,this.propFunc(e),this._pos=e,this.broadcastMessage("onChanged",{target:this,type:"onChanged"})},getPosition:function(e){return e===undefined&&(e=this._time),this.func(e,this.begin,this._change,this._duration)},setFinish:function(e){this._change=e-this.begin},getFinish:function(){return this.begin+this._change},start:function(){this.rewind(),this.startEnterFrame(),this.broadcastMessage("onStarted",{target:this,type:"onStarted"})},rewind:function(e){this.stop(),this._time=e===undefined?0:e,this.fixTime(),this.update()},fforward:function(){this._time=this._duration,this.fixTime(),this.update()},update:function(){this.setPosition(this.getPosition(this._time))},startEnterFrame:function(){this.stopEnterFrame(),this.isPlaying=!0,this.onEnterFrame()},onEnterFrame:function(){this.isPlaying&&this.nextFrame()},nextFrame:function(){this.setTime((this.getTimer()-this._startTime)/1e3)},stop:function(){this.stopEnterFrame(),this.broadcastMessage("onStopped",{target:this,type:"onStopped"})},stopEnterFrame:function(){this.isPlaying=!1},continueTo:function(e,t){this.begin=this._pos,this.setFinish(e),this._duration!==undefined&&this.setDuration(t),this.start()},resume:function(){this.fixTime(),this.startEnterFrame(),this.broadcastMessage("onResumed",{target:this,type:"onResumed"})},yoyo:function(){this.continueTo(this.begin,this._time)},addListener:function(e){return this.removeListener(e),this._listeners.push(e)},removeListener:function(e){var t=this._listeners,n=t.length;while(n--)if(t[n]==e)return t.splice(n,1),!0;return!1},broadcastMessage:function(){var e=[];for(var t=0;t0){this._runFrames();var e=this;requestAnimFrame(function(){e._animationLoop()})}else this.animRunning=!1},_handleAnimation:function(){var e=this;this.animRunning||(this.animRunning=!0,e._animationLoop())}},{init:function(e){e||(e={});for(var t in e)this[t]=e[t];this.frame={time:0,timeDiff:0,lastTime:(new Date).getTime()},this.id=Kinetic.Animation.animIdCounter++},start:function(){this.stop(),this.frame.lastTime=(new Date).getTime(),Kinetic.Animation._addAnimation(this),Kinetic.Animation._handleAnimation()},stop:function(){Kinetic.Animation._removeAnimation(this)}}),requestAnimFrame=function(e){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}(),gamecore.Base.extend("Kinetic.Node",{addSetters:function(e,t){for(var n=0;n1?o[1]:"";this.eventListeners[u]||(this.eventListeners[u]=[]),this.eventListeners[u].push({name:a,handler:t})}},off:function(e){var t=e.split(" ");for(var n=0;n1){var u=s[1];for(var a=0;a0&&s[0].getLevel()<=e&&i(s)}var e=this.getLevel(),t=this.getStage(),n=this,r=0;return n.nodeType!=="Stage"&&i(n.getStage().getChildren()),r},getLevel:function(){var e=0,t=this.parent;while(t)e++,t=t.parent;return e},setPosition:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments));this.setAttrs(e)},getPosition:function(){return{x:this.attrs.x,y:this.attrs.y}},getAbsolutePosition:function(){var e=this.getAbsoluteTransform(),t=this.getOffset();return e.translate(t.x,t.y),e.getTranslation()},setAbsolutePosition:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),t=this._clearTransform();this.attrs.x=t.x,this.attrs.y=t.y,delete t.x,delete t.y;var n=this.getAbsoluteTransform();n.invert(),n.translate(e.x,e.y),e={x:this.attrs.x+n.getTranslation().x,y:this.attrs.y+n.getTranslation().y},this.setPosition(e.x,e.y),this._setTransform(t)},move:function(){var e=Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),t=this.getX(),n=this.getY();e.x!==undefined&&(t+=e.x),e.y!==undefined&&(n+=e.y),this.setAttrs({x:t,y:n})},getRotationDeg:function(){return this.attrs.rotation*180/Math.PI},rotate:function(e){this.setAttrs({rotation:this.getRotation()+e})},rotateDeg:function(e){this.setAttrs({rotation:this.getRotation()+e*Math.PI/180})},moveToTop:function(){var e=this.index;this.parent.children.splice(e,1),this.parent.children.push(this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.appendChild(this.canvas.element))}},moveUp:function(){var e=this.index;if(e0){this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.insertBefore(this.canvas.element,t.getChildren()[this.index+1].canvas.element))}}},moveToBottom:function(){var e=this.index;this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices();if(this.nodeType==="Layer"){var t=this.getStage();t&&(t.content.removeChild(this.canvas.element),t.content.insertBefore(this.canvas.element,t.getChildren()[1].canvas.element))}},setZIndex:function(e){var t=this.index;this.parent.children.splice(t,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices()},getAbsoluteOpacity:function(){var e=1,t=this;while(t.nodeType!=="Stage")e*=t.attrs.opacity,t=t.parent;return e},isDragging:function(){var e=Kinetic.Global;return e.drag.node&&e.drag.node._id===this._id&&e.drag.moving},moveTo:function(e){var t=this.parent;t.children.splice(this.index,1),t._setChildrenIndices(),e.children.push(this),this.index=e.children.length-1,this.parent=e,e._setChildrenIndices()},getParent:function(){return this.parent},getLayer:function(){return this.nodeType==="Layer"?this:this.getParent().getLayer()},getStage:function(){return this.nodeType!=="Stage"&&this.getParent()?this.getParent().getStage():this.nodeType==="Stage"?this:undefined},simulate:function(e){this._handleEvent(e,{})},transitionTo:function(e){var t=this.nodeType==="Stage"?this:this.getLayer(),n=this,r=new Kinetic.Transition(this,e);return this.transAnim.func=function(){r._onEnterFrame()},this.transAnim.node=t,r.onFinished=function(){n.transAnim.stop(),n.transAnim.node.draw(),e.callback&&e.callback()},r.start(),this.transAnim.start(),r},getAbsoluteTransform:function(){var e=new Kinetic.Transform,t=[],n=this.parent;t.unshift(this);while(n)t.unshift(n),n=n.parent;for(var r=0;r=0&&!t.cancelBubble&&this.parent&&(n&&n.parent?this._handleEvent.call(this.parent,e,t,n.parent):this._handleEvent.call(this.parent,e,t))}},_draw:function(e){if(this.isVisible()&&(!e||e.name!=="buffer"||this.getListening())){this.__draw&&this.__draw(e);var t=this.children;if(t)for(var n=0;n0)this.remove(this.children[0])},add:function(e){e._id=Kinetic.Global.idCounter++,e.index=this.children.length,e.parent=this,this.children.push(e);var t=e.getStage();if(!t)Kinetic.Global._addTempNode(e);else{t._addId(e),t._addName(e);var n=Kinetic.Global;n._pullNodes(t)}return this._add!==undefined&&this._add(e),this},remove:function(e){if(e&&e.index!==undefined&&this.children[e.index]._id==e._id){var t=this.getStage();t&&(t._removeId(e.getId()),t._removeName(e.getName(),e._id)),Kinetic.Global._removeTempNode(e),this.children.splice(e.index,1),this._setChildrenIndices();while(e.children&&e.children.length>0)e.remove(e.children[0]);e._remove!==undefined&&e._remove()}return this},get:function(e){var t=this.getStage(),n,r=e.slice(1);if(e.charAt(0)==="#")n=t.ids[r]!==undefined?[t.ids[r]]:[];else{if(e.charAt(0)!==".")return e==="Shape"||e==="Group"||e==="Layer"?this._getNodes(e):!1;n=t.names[r]!==undefined?t.names[r]:[]}var i=[];for(var s=0;s=0;r--){var i=n[r],s=i.bufferCanvas.context.getImageData(Math.round(e.x),Math.round(e.y),1,1).data;if(s[3]===255){var o=Kinetic.Type._rgbToHex(s[0],s[1],s[2]);return t=Kinetic.Global.shapes[o],{shape:t,pixel:s}}if(s[0]>0||s[1]>0||s[2]>0||s[3]>0)return{pixel:s}}return null},_resizeDOM:function(){var e=this.attrs.width,t=this.attrs.height;this.content.style.width=e+"px",this.content.style.height=t+"px",this.bufferCanvas.setSize(e,t);var n=this.children;for(var r=0;ro.right&&(a.x=o.right),o.top!==undefined&&a.yo.bottom&&(a.y=o.bottom),r.setAbsolutePosition(a),s==="horizontal"?r.attrs.y=u.y:s==="vertical"&&(r.attrs.x=u.x),n.drag.moving||(n.drag.moving=!0,n.drag.node._handleEvent("dragstart",e)),n.drag.node._handleEvent("dragmove",e)}},_buildDOM:function(){this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.display="inline-block",this.content.className="kineticjs-content",this.attrs.container.appendChild(this.content),this.bufferCanvas=new Kinetic.Canvas({width:this.attrs.width,height:this.attrs.height}),this._resizeDOM()},_addId:function(e){e.attrs.id!==undefined&&(this.ids[e.attrs.id]=e)},_removeId:function(e){e!==undefined&&delete this.ids[e]},_addName:function(e){var t=e.attrs.name;t!==undefined&&(this.names[t]===undefined&&(this.names[t]=[]),this.names[t].push(e))},_removeName:function(e,t){if(e!==undefined){var n=this.names[e];if(n!==undefined){for(var r=0;r0},_remove:function(){delete Kinetic.Global.shapes[this.colorKey]},__draw:function(e){if(this.attrs.drawFunc){var t=this.getStage(),n=e.getContext(),r=[],i=this.parent;r.unshift(this);while(i)r.unshift(i),i=i.parent;n.save();for(var s=0;s0&&r&&(this.attrs.height==="auto"||i*(n+1)this.attrs.width-this.attrs.padding*2){if(s==0)break;var a=u.lastIndexOf(" "),f=u.lastIndexOf("-"),l=Math.max(a,f);if(l>=0){o=e.splice(0,1+l).join("");break}o=e.splice(0,s).join("");break}s++,s===e.length&&(o=e.splice(0,s).join(""))}this.textWidth=Math.max(this.textWidth,this._getTextSize(o).width),o!==undefined&&(t.push(o),r=!0),n++}this.textArr=t}}),Kinetic.Node.addGettersSetters(Kinetic.Text,["fontFamily","fontSize","fontStyle","textFill","textStroke","textStrokeWidth","padding","align","lineHeight","text","width","height","cornerRadius","fill","stroke","strokeWidth","shadow"]),Kinetic.Shape.extend("Kinetic.Sprite",{},{init:function(e){this.setDefaultAttrs({index:0,frameRate:17}),e.drawFunc=this.drawFunc,this._super(e),this.anim=new Kinetic.Animation;var t=this;this.on("animationChange.kinetic",function(){t.setIndex(0)})},drawFunc:function(e){var t=this.attrs.animation,n=this.attrs.index,r=this.attrs.animations[t][n];e.beginPath(),e.rect(0,0,r.width,r.height),e.closePath(),this.fill(e),this.stroke(e),this.attrs.image&&(e.beginPath(),e.rect(0,0,r.width,r.height),e.closePath(),this.drawImage(e,this.attrs.image,r.x,r.y,r.width,r.height,0,0,r.width,r.height))},start:function(){var e=this,t=this.getLayer();this.anim.node=t,this.interval=setInterval(function(){var t=e.attrs.index;e._updateIndex(),e.afterFrameFunc&&t===e.afterFrameIndex&&(e.afterFrameFunc(),delete e.afterFrameFunc,delete e.afterFrameIndex)},1e3/this.attrs.frameRate),this.anim.start()},stop:function(){this.anim.stop(),clearInterval(this.interval)},afterFrame:function(e,t){this.afterFrameIndex=e,this.afterFrameFunc=t},_updateIndex:function(){var e=this.attrs.index,t=this.attrs.animation;e0)return o=n,t[n];t[n].command=="M"&&(r={x:t[n].points[0],y:t[n].points[1]})}return{}},f=function(t,n){var o=e._getTextSize(t).width,f=0,l=0,c=!1;i=undefined;while(Math.abs(o-f)/o>.01&&l<25){l++;var h=f;while(s===undefined)s=a(),s&&h+s.pathLengtho?i=Kinetic.Path.getPointOnLine(o,r.x,r.y,s.points[0],s.points[1],r.x,r.y):s=undefined;break;case"A":var d=s.points[4],v=s.points[5],m=s.points[4]+v;u===0?u=d+1e-8:o>f?u+=Math.PI/180*v/Math.abs(v):u-=Math.PI/360*v/Math.abs(v),Math.abs(u)>Math.abs(m)&&(u=m,p=!0),i=Kinetic.Path.getPointOnEllipticalArc(s.points[0],s.points[1],s.points[2],s.points[3],u,s.points[6]);break;case"C":u===0?o>s.pathLength?u=1e-8:u=o/s.pathLength:o>f?u+=(o-f)/s.pathLength:u-=(f-o)/s.pathLength,u>1&&(u=1,p=!0),i=Kinetic.Path.getPointOnCubicBezier(u,s.start.x,s.start.y,s.points[0],s.points[1],s.points[2],s.points[3],s.points[4],s.points[5]);break;case"Q":u===0?u=o/s.pathLength:o>f?u+=(o-f)/s.pathLength:u-=(f-o)/s.pathLength,u>1&&(u=1,p=!0),i=Kinetic.Path.getPointOnQuadraticBezier(u,s.start.x,s.start.y,s.points[0],s.points[1],s.points[2],s.points[3])}i!==undefined&&(f=Kinetic.Path.getLineLength(r.x,r.y,i.x,i.y)),p&&(p=!1,s=undefined)}};for(var l=0;l