2014-02-27 08:49:18 +08:00
|
|
|
|
2013-06-01 15:53:32 +08:00
|
|
|
/*
|
|
|
|
* KineticJS JavaScript Framework v@@version
|
2012-10-15 09:46:04 +08:00
|
|
|
* http://www.kineticjs.com/
|
2013-01-05 14:21:17 +08:00
|
|
|
* Copyright 2013, Eric Rowell
|
2012-10-15 09:46:04 +08:00
|
|
|
* Licensed under the MIT or GPL Version 2 licenses.
|
2013-06-01 15:53:32 +08:00
|
|
|
* Date: @@date
|
2012-10-15 09:46:04 +08:00
|
|
|
*
|
2013-01-05 14:21:17 +08:00
|
|
|
* Copyright (C) 2011 - 2013 by Eric Rowell
|
2012-10-15 09:46:04 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2013-07-23 12:41:41 +08:00
|
|
|
/**
|
2013-05-16 00:27:22 +08:00
|
|
|
* @namespace Kinetic
|
2013-03-26 16:09:21 +08:00
|
|
|
*/
|
2014-02-27 08:49:18 +08:00
|
|
|
/*jshint -W079, -W020*/
|
2013-07-23 12:41:41 +08:00
|
|
|
var Kinetic = {};
|
2014-02-27 19:55:39 +08:00
|
|
|
(function(root) {
|
2014-03-22 11:44:25 +08:00
|
|
|
var PI_OVER_180 = Math.PI / 180;
|
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
Kinetic = {
|
2013-09-09 13:02:04 +08:00
|
|
|
// public
|
2013-09-01 16:13:52 +08:00
|
|
|
version: '@@version',
|
2013-09-09 13:02:04 +08:00
|
|
|
|
|
|
|
// private
|
|
|
|
stages: [],
|
|
|
|
idCounter: 0,
|
|
|
|
ids: {},
|
|
|
|
names: {},
|
|
|
|
shapes: {},
|
|
|
|
listenClickTap: false,
|
|
|
|
inDblClickWindow: false,
|
2013-12-06 14:29:50 +08:00
|
|
|
|
2013-09-09 13:02:04 +08:00
|
|
|
// configurations
|
2013-09-01 16:13:52 +08:00
|
|
|
enableTrace: false,
|
|
|
|
traceArrMax: 100,
|
2013-09-09 13:02:04 +08:00
|
|
|
dblClickWindow: 400,
|
2014-04-14 09:49:10 +08:00
|
|
|
/**
|
|
|
|
* Global pixel ratio configuration. KineticJS automatically detect pixel ratio of current device.
|
|
|
|
* But you may override such property, if you want to use your value.
|
|
|
|
* @property
|
|
|
|
* @default undefined
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @example
|
|
|
|
* Kinetic.pixelRatio = 1;
|
|
|
|
*/
|
2013-09-14 14:26:58 +08:00
|
|
|
pixelRatio: undefined,
|
2014-04-14 09:49:10 +08:00
|
|
|
/**
|
|
|
|
* Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point,
|
|
|
|
* only then start dragging.
|
|
|
|
* @property
|
|
|
|
* @default 0
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @example
|
|
|
|
* Kinetic.dragDistance = 10;
|
|
|
|
*/
|
2014-03-11 23:14:03 +08:00
|
|
|
dragDistance : 0,
|
2014-04-14 09:49:10 +08:00
|
|
|
/**
|
|
|
|
* Use degree values for angle properties. You may set this property to false if you want to use radiant values.
|
|
|
|
* @property
|
|
|
|
* @default true
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @example
|
|
|
|
* node.rotation(45); // 45 degrees
|
|
|
|
* Kinetic.angleDeg = false;
|
|
|
|
* node.rotation(Math.PI / 2); // PI/2 radian
|
|
|
|
*/
|
2014-03-22 11:44:25 +08:00
|
|
|
angleDeg: true,
|
2013-09-09 13:02:04 +08:00
|
|
|
|
2013-09-15 02:02:47 +08:00
|
|
|
// user agent
|
|
|
|
UA: (function() {
|
2014-02-27 19:55:39 +08:00
|
|
|
var userAgent = (root.navigator && root.navigator.userAgent) || '';
|
|
|
|
var ua = userAgent.toLowerCase(),
|
2013-09-15 02:02:47 +08:00
|
|
|
// jQuery UA regex
|
|
|
|
match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
|
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
|
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
|
|
|
/(msie) ([\w.]+)/.exec( ua ) ||
|
2014-02-27 08:49:18 +08:00
|
|
|
ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
2014-02-26 23:57:05 +08:00
|
|
|
[],
|
|
|
|
|
|
|
|
// adding mobile flag as well
|
2014-02-27 19:55:39 +08:00
|
|
|
mobile = !!(userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i));
|
2013-09-15 02:02:47 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
browser: match[ 1 ] || '',
|
2014-02-26 23:57:05 +08:00
|
|
|
version: match[ 2 ] || '0',
|
|
|
|
|
|
|
|
// adding mobile flab
|
|
|
|
mobile: mobile
|
2013-09-15 02:02:47 +08:00
|
|
|
};
|
|
|
|
})(),
|
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* @namespace Filters
|
|
|
|
* @memberof Kinetic
|
|
|
|
*/
|
|
|
|
Filters: {},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Node constructor. Nodes are entities that can be transformed, layered,
|
|
|
|
* and have bound events. The stage, layers, groups, and shapes all extend Node.
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @abstract
|
|
|
|
* @param {Object} config
|
|
|
|
* @@nodeParams
|
|
|
|
*/
|
|
|
|
Node: function(config) {
|
|
|
|
this._init(config);
|
|
|
|
},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Shape constructor. Shapes are primitive objects such as rectangles,
|
|
|
|
* circles, text, lines, etc.
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Node
|
|
|
|
* @param {Object} config
|
|
|
|
* @@shapeParams
|
|
|
|
* @@nodeParams
|
|
|
|
* @example
|
2014-04-04 11:17:09 +08:00
|
|
|
* var customShape = new Kinetic.Shape({
|
|
|
|
* x: 5,
|
|
|
|
* y: 10,
|
|
|
|
* fill: 'red',
|
|
|
|
* // a Kinetic.Canvas renderer is passed into the drawFunc function
|
|
|
|
* drawFunc: function(context) {
|
|
|
|
* context.beginPath();
|
|
|
|
* context.moveTo(200, 50);
|
|
|
|
* context.lineTo(420, 80);
|
|
|
|
* context.quadraticCurveTo(300, 100, 260, 170);
|
|
|
|
* context.closePath();
|
|
|
|
* context.fillStrokeShape(this);
|
|
|
|
* }
|
2013-09-01 16:13:52 +08:00
|
|
|
*});
|
|
|
|
*/
|
|
|
|
Shape: function(config) {
|
|
|
|
this.__init(config);
|
|
|
|
},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Container constructor. Containers are used to contain nodes or other containers
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Node
|
|
|
|
* @abstract
|
|
|
|
* @param {Object} config
|
|
|
|
* @@nodeParams
|
|
|
|
* @@containerParams
|
|
|
|
*/
|
|
|
|
Container: function(config) {
|
|
|
|
this.__init(config);
|
|
|
|
},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Stage constructor. A stage is used to contain multiple layers
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @param {Object} config
|
|
|
|
* @param {String|DomElement} config.container Container id or DOM element
|
|
|
|
* @@nodeParams
|
|
|
|
* @@containerParams
|
|
|
|
* @example
|
2014-04-04 11:17:09 +08:00
|
|
|
* var stage = new Kinetic.Stage({
|
|
|
|
* width: 500,
|
|
|
|
* height: 800,
|
|
|
|
* container: 'containerId'
|
2013-09-01 16:13:52 +08:00
|
|
|
* });
|
|
|
|
*/
|
|
|
|
Stage: function(config) {
|
|
|
|
this.___init(config);
|
|
|
|
},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2014-03-21 02:15:55 +08:00
|
|
|
/**
|
|
|
|
* BaseLayer constructor.
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @param {Object} config
|
|
|
|
* @param {Boolean} [config.clearBeforeDraw] set this property to false if you don't want
|
|
|
|
* to clear the canvas before each layer draw. The default value is true.
|
|
|
|
* @@nodeParams
|
|
|
|
* @@containerParams
|
|
|
|
* @example
|
|
|
|
* var layer = new Kinetic.Layer();
|
|
|
|
*/
|
|
|
|
BaseLayer: function(config) {
|
|
|
|
this.___init(config);
|
|
|
|
},
|
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Layer constructor. Layers are tied to their own canvas element and are used
|
2014-04-09 17:53:15 +08:00
|
|
|
* to contain groups or shapes.
|
2013-09-01 16:13:52 +08:00
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @param {Object} config
|
|
|
|
* @param {Boolean} [config.clearBeforeDraw] set this property to false if you don't want
|
|
|
|
* to clear the canvas before each layer draw. The default value is true.
|
|
|
|
* @@nodeParams
|
|
|
|
* @@containerParams
|
|
|
|
* @example
|
|
|
|
* var layer = new Kinetic.Layer();
|
|
|
|
*/
|
|
|
|
Layer: function(config) {
|
2014-03-21 02:15:55 +08:00
|
|
|
this.____init(config);
|
2013-09-01 16:13:52 +08:00
|
|
|
},
|
2013-05-08 14:17:57 +08:00
|
|
|
|
2014-03-09 10:05:14 +08:00
|
|
|
/**
|
2014-04-09 17:53:15 +08:00
|
|
|
* FastLayer constructor. Layers are tied to their own canvas element and are used
|
|
|
|
* to contain shapes only. If you don't need node nesting, mouse and touch interactions,
|
|
|
|
* or event pub/sub, you should use FastLayer instead of Layer to create your layers.
|
|
|
|
* It renders about 2x faster than normal layers.
|
2014-03-09 10:05:14 +08:00
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @param {Object} config
|
|
|
|
* @param {Boolean} [config.clearBeforeDraw] set this property to false if you don't want
|
|
|
|
* to clear the canvas before each layer draw. The default value is true.
|
2014-04-09 17:53:15 +08:00
|
|
|
* @@containerParams
|
2014-03-09 10:05:14 +08:00
|
|
|
* @example
|
|
|
|
* var layer = new Kinetic.FastLayer();
|
|
|
|
*/
|
|
|
|
FastLayer: function(config) {
|
2014-03-21 02:15:55 +08:00
|
|
|
this.____init(config);
|
2014-03-09 10:05:14 +08:00
|
|
|
},
|
|
|
|
|
2013-09-01 16:13:52 +08:00
|
|
|
/**
|
|
|
|
* Group constructor. Groups are used to contain shapes or other groups.
|
|
|
|
* @constructor
|
|
|
|
* @memberof Kinetic
|
|
|
|
* @augments Kinetic.Container
|
|
|
|
* @param {Object} config
|
|
|
|
* @@nodeParams
|
|
|
|
* @@containerParams
|
|
|
|
* @example
|
|
|
|
* var group = new Kinetic.Group();
|
|
|
|
*/
|
|
|
|
Group: function(config) {
|
|
|
|
this.___init(config);
|
2013-09-09 13:02:04 +08:00
|
|
|
},
|
2013-07-24 02:39:44 +08:00
|
|
|
|
2013-03-26 16:09:21 +08:00
|
|
|
/**
|
2013-05-16 00:27:22 +08:00
|
|
|
* returns whether or not drag and drop is currently active
|
|
|
|
* @method
|
2013-09-09 13:02:04 +08:00
|
|
|
* @memberof Kinetic
|
2013-03-26 16:09:21 +08:00
|
|
|
*/
|
2013-03-24 13:56:22 +08:00
|
|
|
isDragging: function() {
|
2013-07-23 12:41:41 +08:00
|
|
|
var dd = Kinetic.DD;
|
2013-04-03 13:29:56 +08:00
|
|
|
|
|
|
|
// if DD is not included with the build, then
|
|
|
|
// drag and drop is not even possible
|
|
|
|
if (!dd) {
|
|
|
|
return false;
|
2013-07-23 12:41:41 +08:00
|
|
|
}
|
2013-04-03 13:29:56 +08:00
|
|
|
// if DD is included with the build
|
|
|
|
else {
|
|
|
|
return dd.isDragging;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
2013-05-16 00:27:22 +08:00
|
|
|
* returns whether or not a drag and drop operation is ready, but may
|
2013-04-03 13:29:56 +08:00
|
|
|
* not necessarily have started
|
2013-05-16 00:27:22 +08:00
|
|
|
* @method
|
2013-09-09 13:02:04 +08:00
|
|
|
* @memberof Kinetic
|
2013-04-03 13:29:56 +08:00
|
|
|
*/
|
|
|
|
isDragReady: function() {
|
2013-07-23 12:41:41 +08:00
|
|
|
var dd = Kinetic.DD;
|
2013-04-03 13:29:56 +08:00
|
|
|
|
|
|
|
// if DD is not included with the build, then
|
|
|
|
// drag and drop is not even possible
|
|
|
|
if (!dd) {
|
|
|
|
return false;
|
2013-07-23 12:41:41 +08:00
|
|
|
}
|
2013-04-03 13:29:56 +08:00
|
|
|
// if DD is included with the build
|
|
|
|
else {
|
|
|
|
return !!dd.node;
|
|
|
|
}
|
2013-03-24 13:56:22 +08:00
|
|
|
},
|
2013-01-14 03:10:49 +08:00
|
|
|
_addId: function(node, id) {
|
|
|
|
if(id !== undefined) {
|
|
|
|
this.ids[id] = node;
|
2012-07-04 13:08:59 +08:00
|
|
|
}
|
2012-12-02 04:04:10 +08:00
|
|
|
},
|
2013-01-14 03:10:49 +08:00
|
|
|
_removeId: function(id) {
|
|
|
|
if(id !== undefined) {
|
|
|
|
delete this.ids[id];
|
|
|
|
}
|
2012-12-02 04:04:10 +08:00
|
|
|
},
|
2013-01-14 03:10:49 +08:00
|
|
|
_addName: function(node, name) {
|
|
|
|
if(name !== undefined) {
|
|
|
|
if(this.names[name] === undefined) {
|
|
|
|
this.names[name] = [];
|
|
|
|
}
|
|
|
|
this.names[name].push(node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_removeName: function(name, _id) {
|
|
|
|
if(name !== undefined) {
|
|
|
|
var nodes = this.names[name];
|
|
|
|
if(nodes !== undefined) {
|
|
|
|
for(var n = 0; n < nodes.length; n++) {
|
|
|
|
var no = nodes[n];
|
|
|
|
if(no._id === _id) {
|
|
|
|
nodes.splice(n, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nodes.length === 0) {
|
|
|
|
delete this.names[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 11:44:25 +08:00
|
|
|
},
|
|
|
|
getAngle: function(angle) {
|
|
|
|
return this.angleDeg ? angle * PI_OVER_180 : angle;
|
2012-07-04 13:08:59 +08:00
|
|
|
}
|
2012-12-02 04:04:10 +08:00
|
|
|
};
|
2014-02-27 19:55:39 +08:00
|
|
|
})(this);
|
2012-12-02 04:04:10 +08:00
|
|
|
|
|
|
|
// Uses Node, AMD or browser globals to create a module.
|
|
|
|
|
|
|
|
// If you want something that will work in other stricter CommonJS environments,
|
|
|
|
// or if you need to create a circular dependency, see commonJsStrict.js
|
|
|
|
|
|
|
|
// Defines a module "returnExports" that depends another module called "b".
|
|
|
|
// Note that the name of the module is implied by the file name. It is best
|
|
|
|
// if the file name and the exported global have matching names.
|
|
|
|
|
|
|
|
// If the 'b' module also uses this type of boilerplate, then
|
|
|
|
// in the browser, it will create a global .b that is used below.
|
|
|
|
|
|
|
|
// If you do not want to support the browser global path, then you
|
|
|
|
// can remove the `root` use and the passing `this` as the first arg to
|
|
|
|
// the top function.
|
|
|
|
|
|
|
|
// if the module has no dependencies, the above pattern can be simplified to
|
|
|
|
( function(root, factory) {
|
|
|
|
if( typeof exports === 'object') {
|
|
|
|
// Node. Does not work with strict CommonJS, but
|
|
|
|
// only CommonJS-like enviroments that support module.exports,
|
|
|
|
// like Node.
|
2014-02-27 19:55:39 +08:00
|
|
|
var Canvas = require('canvas');
|
2014-02-28 10:37:57 +08:00
|
|
|
var jsdom = require('jsdom').jsdom;
|
2014-03-01 18:09:27 +08:00
|
|
|
var doc = jsdom('<!DOCTYPE html><html><head></head><body></body></html>');
|
2014-02-28 10:37:57 +08:00
|
|
|
|
2014-02-27 19:55:39 +08:00
|
|
|
var KineticJS = factory();
|
2014-02-28 10:37:57 +08:00
|
|
|
|
|
|
|
Kinetic.document = doc;
|
|
|
|
Kinetic.window = Kinetic.document.createWindow();
|
|
|
|
Kinetic.window.Image = Canvas.Image;
|
|
|
|
Kinetic.root = root;
|
2014-02-27 19:55:39 +08:00
|
|
|
Kinetic._nodeCanvas = Canvas;
|
|
|
|
module.exports = KineticJS;
|
2014-02-28 10:37:57 +08:00
|
|
|
return;
|
2012-12-02 04:04:10 +08:00
|
|
|
}
|
|
|
|
else if( typeof define === 'function' && define.amd) {
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define(factory);
|
|
|
|
}
|
2014-02-28 10:37:57 +08:00
|
|
|
Kinetic.document = document;
|
|
|
|
Kinetic.window = window;
|
|
|
|
Kinetic.root = root;
|
|
|
|
|
2014-04-26 17:25:21 +08:00
|
|
|
}(this, function() {
|
2012-12-02 04:04:10 +08:00
|
|
|
|
|
|
|
// Just return a value to define the module export.
|
|
|
|
// This example returns an object, but the module
|
|
|
|
// can return a function as the exported value.
|
|
|
|
return Kinetic;
|
|
|
|
}));
|