diff --git a/Gemfile b/Gemfile index 6a168aa9..080b3646 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source :rubygems -gem 'json-pure' -gem 'rake' +gem 'json_pure' +gem 'thor' gem 'uglifier' diff --git a/Gemfile.lock b/Gemfile.lock index c0ac0a8f..48ef0240 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,8 +3,9 @@ GEM specs: execjs (1.3.0) multi_json (~> 1.0) + json_pure (1.6.5) multi_json (1.1.0) - rake (0.9.2.2) + thor (0.14.6) uglifier (1.2.3) execjs (>= 0.3.0) multi_json (>= 1.0.2) @@ -13,5 +14,6 @@ PLATFORMS ruby DEPENDENCIES - rake + json_pure + thor uglifier diff --git a/README.md b/README.md index 87dbe23e..06500588 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Check out the official [KineticJS Tutorials](http://www.html5canvastutorials.com # Building the library To build the library, you need to have Ruby and Rubygems installed. After that, install the dependencies by running `bundle install`. -To build a development version of the library, run `rake build:dev`. To build a minify version of the library, run `rake build:prod`. +To build a development version of the library, run `thor build:dev VERSION`, where VERSION is in the format MAJOR.MINOR.PATCH. To build a minify version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012`). # Adding a new file in the src directory -If you add a file in the src directory, add into the array in the Rakefile. +If you add a file in the src directory, add into the array in the Thorfile. diff --git a/Rakefile b/Rakefile deleted file mode 100644 index ba88dc90..00000000 --- a/Rakefile +++ /dev/null @@ -1,40 +0,0 @@ -require 'json/pure' - -# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory. -FILES = [ - "license.js", "src/GlobalObject.js", "src/Node.js", "src/Container.js", "src/Stage.js", - "src/Layer.js", "src/Group.js", "src/geometries/Shape.js", "src/geometries/Rect.js", "src/geometries/Circle.js", "src/geometries/Image.js", - "src/geometries/Polygon.js", "src/geometries/RegularPolygon.js", "src/geometries/Star.js", "src/geometries/Text.js" -] - -def concatenate - content = "" - FILES.each do |file| - content << IO.read(File.expand_path(file)) << "\n" - end - - return content -end - -namespace :build do - desc "Concatenate all the js files into /dist/kinetic.js." - task :dev do - puts ":: Building the file /dist/kinetic.js..." - File.open("dist/kinetic.js", "w") do |file| - file.puts concatenate() - end - puts " -> Done!" - end - - desc "Concatenate all the js files in into /dist/kinetic.min.js and minify it." - task :prod do - puts ":: Building the file /dist/kinetic.min.js..." - require 'json/pure' - require 'uglifier' - File.open("dist/kinetic.min.js", "w") do |file| - file.puts Uglifier.compile(concatenate()) - end - puts ":: Minifying the file /dist/kinetic.min.js..." - puts " -> Done!" - end -end diff --git a/Thorfile b/Thorfile new file mode 100644 index 00000000..a4beb980 --- /dev/null +++ b/Thorfile @@ -0,0 +1,74 @@ +require 'json/pure' + +class Build < Thor + # This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory. + FILES = [ + "license.js", "src/GlobalObject.js", "src/Node.js", "src/Container.js", "src/Stage.js", + "src/Layer.js", "src/Group.js", "src/geometries/Shape.js", "src/geometries/Rect.js", "src/geometries/Circle.js", "src/geometries/Image.js", + "src/geometries/Polygon.js", "src/geometries/RegularPolygon.js", "src/geometries/Star.js", "src/geometries/Text.js" + ] + + desc "dev", "Concatenate all the js files into /dist/kinetic-vVERSION.js." + method_option :date, aliases: "-d", required: false, type: :string, desc: "The release date" + def dev(version) + file_name = "dist/kinetic-v#{version}.js" + + puts ":: Deleting other development files..." + Dir.foreach("dist") do |file| + if file.match(/kinetic-v.+\.(\d|\.)+\.js/) + File.delete("dist/" + file) + end + end + + puts ":: Building the file /#{file_name}..." + File.open(file_name, "w") do |file| + file.puts concatenate(version, options[:date]) + end + + puts " -> Done!" + end + + desc "prod", "Concatenate all the js files in into /dist/kinetic-vVERSION.min.js and minify it." + method_option :date, aliases: "-d", required: false, type: :string, desc: "The release date" + def prod(version) + file_name = "dist/kinetic-v#{version}.min.js" + + puts ":: Deleting other development files..." + Dir.foreach("dist") do |file| + if file.match(/kinetic-v.+\.min\.js/) + File.delete("dist/" + file) + end + end + + puts ":: Building the file /#{file_name}..." + require 'json/pure' + require 'uglifier' + File.open(file_name, "w") do |file| + uglify = Uglifier.compile(concatenate(version, options[:date])) + uglify.sub!(/\*\/ .+ \*\//xm, "*/") + file.puts uglify + end + puts ":: Minifying the file /#{file_name}..." + puts " -> Done!" + end + + private + + def concatenate(version, date) + date ||= Time.now.strftime("%b %d %Y") + content = "" + FILES.each do |file| + content << IO.read(File.expand_path(file)) << "\n" + end + + # Add the version number + content.sub!("@version", version) + + # Add the date + content.sub!("@date", date) + + return content + end + +end + diff --git a/dist/kinetic.js b/dist/kinetic-v3.8.3.js similarity index 99% rename from dist/kinetic.js rename to dist/kinetic-v3.8.3.js index 7c417362..3798c9aa 100644 --- a/dist/kinetic.js +++ b/dist/kinetic-v3.8.3.js @@ -3,7 +3,7 @@ * http://www.kineticjs.com/ * Copyright 2012, Eric Rowell * Licensed under the MIT or GPL Version 2 licenses. - * Date: Mar 03 2012 + * Date: Mar 07 2012 * * Copyright (C) 2011 - 2012 by Eric Rowell * @@ -25,6 +25,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + /////////////////////////////////////////////////////////////////////// // Global Object /////////////////////////////////////////////////////////////////////// diff --git a/dist/kinetic.min.js b/dist/kinetic-v3.8.3.min.js similarity index 99% rename from dist/kinetic.min.js rename to dist/kinetic-v3.8.3.min.js index ecf7c08c..f29c01eb 100644 --- a/dist/kinetic.min.js +++ b/dist/kinetic-v3.8.3.min.js @@ -3,7 +3,7 @@ * http://www.kineticjs.com/ * Copyright 2012, Eric Rowell * Licensed under the MIT or GPL Version 2 licenses. - * Date: Mar 03 2012 + * Date: Mar 07 2012 * * Copyright (C) 2011 - 2012 by Eric Rowell * @@ -25,11 +25,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -/////////////////////////////////////////////////////////////////////// -// Global Object -/////////////////////////////////////////////////////////////////////// -/** - * Kinetic Namespace - * @namespace - */ var Kinetic={};Kinetic.GlobalObject={stages:[],idCounter:0,isAnimating:!1,frame:{time:0,timeDiff:0,lastTime:0},drag:{moving:!1,node:undefined,offset:{x:0,y:0}},extend:function(a,b){for(var c in b.prototype)b.prototype.hasOwnProperty(c)&&(a.prototype[c]=b.prototype[c])},_isaCanvasAnimating:function(){for(var a=0;a1?g[1]:"";this.eventListeners[h]||(this.eventListeners[h]=[]),this.eventListeners[h].push({name:i,handler:b})}},off:function(a){var b=a.split(" ");for(var c=0;c1){var h=f[1];for(var i=0;i0&&(this.parent.children.splice(a,1),this.parent.children.splice(a-1,0,this),this.parent._setChildrenIndices())},moveToBottom:function(){var a=this.index;this.parent.children.splice(a,1),this.parent.children.unshift(this),this.parent._setChildrenIndices()},setZIndex:function(a){var b=this.index;this.parent.children.splice(b,1),this.parent.children.splice(a,0,this),this.parent._setChildrenIndices()},setAlpha:function(a){this.alpha=a},getAlpha:function(){return this.alpha},getAbsoluteAlpha:function(){var a=1,b=this;while(b.className!=="Stage")a*=b.alpha,b=b.parent;return a},draggable:function(a){if(a){var b=!this.drag.x&&!this.drag.y;this.drag.x=!0,this.drag.y=!0,b&&this._initDrag()}else this.drag.x=!1,this.drag.y=!1,this._dragCleanup()},draggableX:function(a){if(a){var b=!this.drag.x&&!this.drag.y;this.drag.x=!0,b&&this._initDrag()}else this.drag.x=!1,this._dragCleanup()},draggableY:function(a){if(a){var b=!this.drag.x&&!this.drag.y;this.drag.y=!0,b&&this._initDrag()}else this.drag.y=!1,this._dragCleanup()},isDragging:function(){var a=Kinetic.GlobalObject;return a.drag.node!==undefined&&a.drag.node.id===this.id&&a.drag.moving},moveTo:function(a){var b=this.parent;b.children.splice(this.index,1),b._setChildrenIndices(),a.children.push(this),this.index=a.children.length-1,this.parent=a,a._setChildrenIndices(),this.name&&(b.childrenNames[this.name]=undefined,a.childrenNames[this.name]=this)},getParent:function(){return this.parent},getLayer:function(){return this.className==="Layer"?this:this.getParent().getLayer()},getStage:function(){return this.getParent().getStage()},getName:function(){return this.name},setCenterOffset:function(a,b){this.centerOffset.x=a,this.centerOffset.y=b},getCenterOffset:function(){return this.centerOffset},_initDrag:function(){var a=Kinetic.GlobalObject,b=this;this.on("mousedown.initdrag touchstart.initdrag",function(c){var d=b.getStage(),e=d.getUserPosition();e&&(a.drag.node=b,a.drag.offset.x=e.x-b.x,a.drag.offset.y=e.y-b.y)})},_dragCleanup:function(){!this.drag.x&&!this.drag.y&&(this.off("mousedown.initdrag"),this.off("touchstart.initdrag"))},_handleEvents:function(a,b){function c(d){var e=d.eventListeners;if(e[a]){var f=e[a];for(var g=0;g0)this.remove(this.children[0])},_remove:function(a){a.name!==undefined&&(this.childrenNames[a.name]=undefined),this.children.splice(a.index,1),this._setChildrenIndices(),a=undefined},_drawChildren:function(){var a=this.children;for(var b=0;b=0;c--){var d=b[c];if(d.className==="Shape"){var e=g(d);if(e)return!0}else h(d)}return!1}var b=Kinetic.GlobalObject;a||(a=window.event),this._setMousePosition(a),this._setTouchPosition(a);var c=this.backstageLayer,d=c.getContext(),e=this;c.clear();var f=!1;if(b.drag.node===undefined)for(var i=this.children.length-1;i>=0;i--){var j=this.children[i];j.visible&&i>=0&&j.isListening&&h(j)&&(i=-1)}},_listen:function(){var a=this;this.container.addEventListener("mousedown",function(b){a.mouseDown=!0,a._handleEvent(b)},!1),this.container.addEventListener("mousemove",function(b){a.mouseUp=!1,a.mouseDown=!1,a._handleEvent(b)},!1),this.container.addEventListener("mouseup",function(b){a.mouseUp=!0,a.mouseDown=!1,a._handleEvent(b),a.clickStart=!1},!1),this.container.addEventListener("mouseover",function(b){a._handleEvent(b)},!1),this.container.addEventListener("mouseout",function(b){a.mousePos=undefined},!1),this.container.addEventListener("touchstart",function(b){b.preventDefault(),a.touchStart=!0,a._handleEvent(b)},!1),this.container.addEventListener("touchmove",function(b){b.preventDefault(),a._handleEvent(b)},!1),this.container.addEventListener("touchend",function(b){b.preventDefault(),a.touchEnd=!0,a._handleEvent(b)},!1)},_setMousePosition:function(a){var b=a.clientX-this._getContainerPosition().left+window.pageXOffset,c=a.clientY-this._getContainerPosition().top+window.pageYOffset;this.mousePos={x:b,y:c}},_setTouchPosition:function(a){if(a.touches!==undefined&&a.touches.length===1){var b=a.touches[0],c=b.clientX-this._getContainerPosition().left+window.pageXOffset,d=b.clientY-this._getContainerPosition().top+window.pageYOffset;this.touchPos={x:c,y:d}}},_getContainerPosition:function(){var a=this.container,b=0,c=0;while(a&&a.tagName!=="BODY")b+=a.offsetTop,c+=a.offsetLeft,a=a.offsetParent;return{top:b,left:c}},_stripLayer:function(a){a.context.stroke=function(){},a.context.fill=function(){},a.context.fillRect=function(b,c,d,e){a.context.rect(b,c,d,e)},a.context.strokeRect=function(b,c,d,e){a.context.rect(b,c,d,e)},a.context.drawImage=function(){},a.context.fillText=function(){},a.context.strokeText=function(){}},_endDrag:function(a){var b=Kinetic.GlobalObject;b.drag.node&&b.drag.moving&&(b.drag.moving=!1,b.drag.node._handleEvents("ondragend",a)),b.drag.node=undefined},_prepareDrag:function(){var a=this;this.on("mousemove touchmove",function(b){var c=Kinetic.GlobalObject;if(c.drag.node){var d=a.getUserPosition();c.drag.node.drag.x&&(c.drag.node.x=d.x-c.drag.offset.x),c.drag.node.drag.y&&(c.drag.node.y=d.y-c.drag.offset.y),c.drag.node.getLayer().draw(),c.drag.moving||(c.drag.moving=!0,c.drag.node._handleEvents("ondragstart",b)),c.drag.node._handleEvents("ondragmove",b)}},!1),this.on("mouseup touchend mouseout",function(b){a._endDrag(b)})}},Kinetic.GlobalObject.extend(Kinetic.Stage,Kinetic.Container),Kinetic.Layer=function(a){this.className="Layer",this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.canvas.style.position="absolute",Kinetic.Container.apply(this,[]),Kinetic.Node.apply(this,[a])},Kinetic.Layer.prototype={draw:function(){this._draw()},clear:function(){var a=this.getContext(),b=this.getCanvas();a.clearRect(0,0,b.width,b.height)},getCanvas:function(){return this.canvas},getContext:function(){return this.context},add:function(a){this._add(a)},remove:function(a){this._remove(a)},_draw:function(){this.clear(),this.visible&&this._drawChildren()}},Kinetic.GlobalObject.extend(Kinetic.Layer,Kinetic.Container),Kinetic.GlobalObject.extend(Kinetic.Layer,Kinetic.Node),Kinetic.Group=function(a){this.className="Group",Kinetic.Container.apply(this,[]),Kinetic.Node.apply(this,[a])},Kinetic.Group.prototype={add:function(a){this._add(a)},remove:function(a){this._remove(a)},_draw:function(){this.visible&&this._drawChildren()}},Kinetic.GlobalObject.extend(Kinetic.Group,Kinetic.Container),Kinetic.GlobalObject.extend(Kinetic.Group,Kinetic.Node),Kinetic.Shape=function(a){this.className="Shape";if(a.stroke!==undefined||a.strokeWidth!==undefined)a.stroke===undefined?a.stroke="black":a.strokeWidth===undefined&&(a.strokeWidth=2);this.drawFunc=a.drawFunc,Kinetic.Node.apply(this,[a])},Kinetic.Shape.prototype={getContext:function(){return this.tempLayer.getContext()},getCanvas:function(){return this.tempLayer.getCanvas()},fillStroke:function(){var a=this.getContext();this.fill!==undefined&&(a.fillStyle=this.fill,a.fill()),this.stroke!==undefined&&(a.lineWidth=this.strokeWidth===undefined?1:this.strokeWidth,a.strokeStyle=this.stroke,a.stroke())},setFill:function(a){this.fill=a},getFill:function(){return this.fill},setStroke:function(a){this.stroke=a},getStroke:function(){return this.stroke},setStrokeWidth:function(a){this.strokeWidth=a},getStrokeWidth:function(){return this.strokeWidth},_draw:function(a){if(this.visible){var b=a.getStage(),c=a.getContext(),d=[];d.unshift(this);var e=this.parent;while(e.className!=="Stage")d.unshift(e),e=e.parent;for(var f=0;f