Merge branch 'refs/heads/master' into v8-optimizations

Conflicts:
	src/core/Base.js
	src/style/Color.js
This commit is contained in:
Jürg Lehni 2014-01-05 05:01:13 +01:00
commit ea63d4c288
118 changed files with 498 additions and 462 deletions

View file

@ -1,6 +1,6 @@
## Authors ## Authors
- Juerg Lehni <juerg@lehni.org> - Juerg Lehni <juerg@scratchdisk.com>
- Jonathan Puckey <jonathan@studiomoniker.com> - Jonathan Puckey <jonathan@studiomoniker.com>
## Contributors ## Contributors

View file

@ -1,5 +1,5 @@
Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
http://lehni.org/ & http://jonathanpuckey.com/ http://scratchdisk.com/ & http://jonathanpuckey.com/
All rights reserved. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -14,7 +14,11 @@ You can download prebuilt packages from <http://paperjs.org/download/>.
As of July 2013, the recommended way to install and maintain Paper.js is through Bower for browsers, and through NPM for Node.js. As of July 2013, the recommended way to install and maintain Paper.js is through Bower for browsers, and through NPM for Node.js.
See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX. For OSX see <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower.
For Linux see <http://nodejs.org/download/> to locate 32-bit and 64-bit nodejs binaries as well as sources. It is recommended that you download directly from the nodejs site; the version available via many OS-supplied package managers is out-of-date and doesn't work with many of the packages paper uses. NPM is now included with the nodejs distribution. Once nodejs (with npm) has been installed you can install bower using the following command:
npm install -g bower
With Bower installed, simply type this command in your project folder: With Bower installed, simply type this command in your project folder:
@ -22,26 +26,38 @@ With Bower installed, simply type this command in your project folder:
Upon execution, you will find a `paper` folder inside the project's `component` folder. For more information on Bower and to learn about its features for dependence tracking, see <http://bower.io/>. Upon execution, you will find a `paper` folder inside the project's `component` folder. For more information on Bower and to learn about its features for dependence tracking, see <http://bower.io/>.
## Installing for Node.js ## Installing Paper.js for Node.js through NPM
Similarly you can use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see <http://cairographics.org/>. You can also use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see <http://cairographics.org/>.
The easiest way to install Cairo on OSX is through Homebrew <http://mxcl.github.io/homebrew/>. **Installing Cairo on OSX:**
The easiest way to install Cairo is install Homebrew <http://mxcl.github.io/homebrew/> then issue the command:
brew install cairo brew install cairo
Once Homebrew has installed this for you, you can then install the Paper.js module:
npm install paper
Note that currently there is an issue on OSX with Cairo. If the above causes errors, the following will most likely fix it: Note that currently there is an issue on OSX with Cairo. If the above causes errors, the following will most likely fix it:
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm insetall paper
Also, whenever you would like to update the modules, you will need to execute: Also, whenever you would like to update the modules, you will need to execute:
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm update PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm update
**Installing Cairo on Debian/Ubuntu Linux:**
sudo apt-get install libcairo2-dev
You might also need these additional packages if you don't usually build from c++ sources:
sudo apt-get install build-essential libssl-dev libjpeg8-dev libgif-dev
**Ater Cairo has been installed:**
You should now be able to install the Paper.js module from NPM:
npm install paper
## Development ## Development
**Get the source (for building):** **Get the source (for building):**
@ -53,11 +69,12 @@ Also, whenever you would like to update the modules, you will need to execute:
If you want to contribute to the project you will have to [make a fork](http://help.github.com/forking/). Then do this: If you want to contribute to the project you will have to [make a fork](http://help.github.com/forking/). Then do this:
git clone --recursive git@github.com:yourusername/paper.js.git git clone --recursive git@github.com:yourusername/paper.js.git
cd paper.js
git remote add upstream git://github.com/paperjs/paper.js.git git remote add upstream git://github.com/paperjs/paper.js.git
### Refreshing Your Clone ### Refreshing Your Clone
To fetch changes from origin, run To fetch changes from origin (your fork), run
git fetch origin git fetch origin
@ -73,11 +90,15 @@ To update the `jsdoc-toolkit` submodule inside the `build` folder, used to gener
Paper.js has a couple of dependencies as Bower and NPM modules. See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX. Paper.js has a couple of dependencies as Bower and NPM modules. See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX.
In order to be able to build Paper.js, these dependencies need to be installed first after checking out the repository: In order to be able to build Paper.js, after checking out the repository, paper has dependencies that need to be installed. Install them by issuing the following commands from the paper.js directory:
npm install npm install
bower install bower install
You might find that the npm command fails attempting to fetch packages needed for dependencies due to using https (the default protocol to access the npm registry). If that is the case you can switch to using http for registry access with the following command:
npm config set registry http://registry.npmjs.org/
Next you need to create minified versions of some of these dependencies. This is handled by the `minify-components.sh` script inside the `build` folder: Next you need to create minified versions of some of these dependencies. This is handled by the `minify-components.sh` script inside the `build` folder:
cd build cd build
@ -145,7 +166,8 @@ As mentioned earlier in this article, we prefer that you send a [*pull request*]
3. This is important: Create a so-called *topic branch*: `git checkout -tb name-of-my-patch` where "name-of-my-patch" is a short but descriptive name of the patch you're about to create. Don't worry about the perfect name though -- you can change this name at any time later on. 3. This is important: Create a so-called *topic branch*: `git checkout -tb name-of-my-patch` where "name-of-my-patch" is a short but descriptive name of the patch you're about to create. Don't worry about the perfect name though -- you can change this name at any time later on.
4. Hack! Make your changes, additions, etc and commit them. 4. Hack! Make your changes, additions, etc., commit them then push them to your github fork: `git push origin name-of-my-patch`
5. Send a pull request to the upstream repository's owner by visiting your repository's site at github (i.e. https://github.com/yourusername/paper.js) and press the "Pull Request" button. Here's a good guide on pull requests: <http://help.github.com/pull-requests/> 5. Send a pull request to the upstream repository's owner by visiting your repository's site at github (i.e. https://github.com/yourusername/paper.js) and press the "Pull Request" button. Here's a good guide on pull requests: <http://help.github.com/pull-requests/>

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting. # Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/ # http://paperjs.org/
# #
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # http://scratchdisk.com/ & http://jonathanpuckey.com/
# #
# Distributed under the MIT license. See LICENSE file for details. # Distributed under the MIT license. See LICENSE file for details.
# #

View file

@ -1,7 +1,7 @@
require('paper'); var paper = require('paper');
var paper = require('./Tadpoles.pjs'); var scope = require('./Tadpoles.pjs')(new paper.Size(1024, 768));
paper.view.exportFrames({ scope.view.exportFrames({
amount: 400, amount: 400,
directory: __dirname, directory: __dirname,
onComplete: function() { onComplete: function() {

View file

@ -1,5 +1,3 @@
paper.setup(new Canvas(1024, 768));
// Adapted from Flocking Processing example by Daniel Schiffman: // Adapted from Flocking Processing example by Daniel Schiffman:
// http://processing.org/learning/topics/flocking.html // http://processing.org/learning/topics/flocking.html

View file

@ -89,12 +89,11 @@
function onMouseDrag(event) { function onMouseDrag(event) {
if (segment) { if (segment) {
segment.point = event.point; segment.point += event.delta;
path.smooth(); path.smooth();
} } else if (path) {
if (movePath)
path.position += event.delta; path.position += event.delta;
}
} }
</script> </script>
</head> </head>

5
node_modules/.gitignore generated vendored
View file

@ -1,7 +1,8 @@
.bin .bin
canvas canvas
grunt*
jsdoc
jsdom jsdom
prepro
request request
uglify-js uglify-js
prepro
grunt*

View file

@ -5,7 +5,7 @@
"homepage": "http://paperjs.org", "homepage": "http://paperjs.org",
"repository": "git://github.com/paperjs/paper.js", "repository": "git://github.com/paperjs/paper.js",
"contributors": [ "contributors": [
"Jürg Lehni <juerg@lehni.org> (http://lehni.org)", "Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)",
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)" "Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
], ],
"main": "./dist/paper-node.js", "main": "./dist/paper-node.js",
@ -26,7 +26,7 @@
}, },
"devDependencies": { "devDependencies": {
"uglify-js": "~2.3.6", "uglify-js": "~2.3.6",
"prepro": "~0.8.0", "prepro": "~0.8.1",
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.2" "grunt-contrib-uglify": "~0.2.2"
}, },

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -15,8 +15,7 @@
* @class * @class
* @private * @private
*/ */
// Extend Base with utility functions used across the library. Also set // Extend Base with utility functions used across the library.
// this.Base on the injection scope, since straps.js ommits that.
Base.inject(/** @lends Base# */{ Base.inject(/** @lends Base# */{
/** /**
* Renders base objects to strings in object literal notation. * Renders base objects to strings in object literal notation.
@ -40,7 +39,7 @@ Base.inject(/** @lends Base# */{
/** /**
* Serializes this object to a JSON string. * Serializes this object to a JSON string.
* *
* @param {Object} [options={ precision: 5 }] * @param {Object} [options={ asString: true, precision: 5 }]
*/ */
exportJSON: function(options) { exportJSON: function(options) {
return Base.exportJSON(this, options); return Base.exportJSON(this, options);
@ -180,9 +179,6 @@ Base.inject(/** @lends Base# */{
obj = Base.create(this.prototype); obj = Base.create(this.prototype);
if (readIndex) if (readIndex)
obj.__read = true; obj.__read = true;
// If options were provided, pass them on to the constructed object
if (options)
obj.__options = options;
obj = obj.initialize.apply(obj, index > 0 || length < list.length obj = obj.initialize.apply(obj, index > 0 || length < list.length
? Array.prototype.slice.call(list, index, index + length) ? Array.prototype.slice.call(list, index, index + length)
: list) || obj; : list) || obj;
@ -192,8 +188,6 @@ Base.inject(/** @lends Base# */{
// last read() call // last read() call
list.__read = obj.__read; list.__read = obj.__read;
obj.__read = undefined; obj.__read = undefined;
if (options)
obj.__options = undefined;
} }
return obj; return obj;
}, },
@ -211,7 +205,7 @@ Base.inject(/** @lends Base# */{
/** /**
* Reads all readable arguments from the list, handling nested arrays * Reads all readable arguments from the list, handling nested arrays
* seperately. * separately.
* @param {Array} list the list to read from, either an arguments object * @param {Array} list the list to read from, either an arguments object
* or a normal array. * or a normal array.
* @param {Number} start the index at which to start reading in the list * @param {Number} start the index at which to start reading in the list
@ -433,7 +427,10 @@ Base.inject(/** @lends Base# */{
}, },
exportJSON: function(obj, options) { exportJSON: function(obj, options) {
return JSON.stringify(Base.serialize(obj, options)); var json = Base.serialize(obj, options);
return options && options.asString === false
? json
: JSON.stringify(json);
}, },
importJSON: function(json, target) { importJSON: function(json, target) {

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -77,32 +77,16 @@ var Callback = {
if (!handlers) if (!handlers)
return false; return false;
var args = [].slice.call(arguments, 1), var args = [].slice.call(arguments, 1),
PaperScript = paper.PaperScript,
handleException = PaperScript && PaperScript.handleException,
that = this; that = this;
for (var i in handlers) {
function callHandlers() { // When the handler function returns false, prevent the default
for (var i in handlers) { // behaviour and stop propagation of the event by calling stop()
// When the handler function returns false, prevent the default if (handlers[i].apply(that, args) === false
// behaviour and stop propagation of the event by calling stop() && event && event.stop) {
if (handlers[i].apply(that, args) === false event.stop();
&& event && event.stop) { break;
event.stop();
break;
}
} }
} }
// See PaperScript.handleException for an explanation of the following.
// Firefox is to blame for the necessity of this...
if (handleException) {
try {
callHandlers();
} catch (e) {
handleException(e);
}
} else {
callHandlers();
}
return true; return true;
}, },

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -14,17 +14,12 @@
* @name PaperScript * @name PaperScript
* @namespace * @namespace
*/ */
var PaperScript = Base.exports.PaperScript = (function(root) { var PaperScript = Base.exports.PaperScript = (function() {
// Locally turn of exports and define for inlined acorn / esprima. // Locally turn of exports and define for inlined acorn / esprima.
// Just declaring the local vars is enough, as they will be undefined. // Just declaring the local vars is enough, as they will be undefined.
var exports, define, var exports, define,
// The scope into which the library is loaded. // The scope into which the library is loaded.
scope = this; scope = this;
/*#*/ if (__options.version == 'dev') {
// As the above inclusion loads code into the root scope during dev,
// set scope to root, so we can find the library.
scope = root;
/*#*/ } // __options.version == 'dev'
/*#*/ if (__options.parser == 'acorn') { /*#*/ if (__options.parser == 'acorn') {
/*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false }); /*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false });
/*#*/ } else if (__options.parser == 'esprima') { /*#*/ } else if (__options.parser == 'esprima') {
@ -34,7 +29,7 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// Operators to overload // Operators to overload
var binaryOperators = { var binaryOperators = {
// The hidden math functions are to be injected specifically, see below. // The hidden math methods are to be injected specifically, see below.
'+': '__add', '+': '__add',
'-': '__subtract', '-': '__subtract',
'*': '__multiply', '*': '__multiply',
@ -50,11 +45,11 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
'+': null '+': null
}; };
// Inject underscored math functions as aliases to Point, Size and Color. // Inject underscored math methods as aliases to Point, Size and Color.
var fields = Base.each( var fields = Base.each(
['add', 'subtract', 'multiply', 'divide', 'modulo', 'negate'], ['add', 'subtract', 'multiply', 'divide', 'modulo', 'negate'],
function(name) { function(name) {
// Create an alias for ach math function to be injected into the // Create an alias for each math method to be injected into the
// classes using Straps.js' #inject() // classes using Straps.js' #inject()
this['__' + name] = '#' + name; this['__' + name] = '#' + name;
}, },
@ -109,13 +104,12 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
*/ */
function compile(code) { function compile(code) {
// Use Acorn or Esprima to translate the code into an AST structure // Use Acorn or Esprima to translate the code into an AST structure
// which is then walked and parsed for operators to overload. // which is then walked and parsed for operators to overload. Instead of
// Instead of modifying the AST and converting back to code, we directly // modifying the AST and translating it back to code, we directly change
// change the source code based on the parser's range information, so we // the source code based on the parser's range information, to preserve
// can preserve line-numbers in syntax errors and remove the need for // line-numbers in syntax errors and remove the need for Escodegen.
// Escodegen.
// Tracks code insertions so we can add their differences to the // Track code insertions so their differences can be added to the
// original offsets. // original offsets.
var insertions = []; var insertions = [];
@ -143,8 +137,8 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// information up-to-date. // information up-to-date.
function replaceCode(node, str) { function replaceCode(node, str) {
var start = getOffset(node.range[0]), var start = getOffset(node.range[0]),
end = getOffset(node.range[1]); end = getOffset(node.range[1]),
var insert = 0; insert = 0;
// Sort insertions by their offset, so getOffest() can do its thing // Sort insertions by their offset, so getOffest() can do its thing
for (var i = insertions.length - 1; i >= 0; i--) { for (var i = insertions.length - 1; i >= 0; i--) {
if (start > insertions[i][0]) { if (start > insertions[i][0]) {
@ -245,7 +239,7 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
var view = scope.getView(), var view = scope.getView(),
// Only create a tool object if something resembling a tool handler // Only create a tool object if something resembling a tool handler
// definition is contained in the code. // definition is contained in the code.
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code) tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code)
? new Tool() ? new Tool()
: null, : null,
toolHandlers = tool ? tool._events : [], toolHandlers = tool ? tool._events : [],
@ -255,71 +249,69 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// injecting a code line that defines them as variables. // injecting a code line that defines them as variables.
// They are exported again at the end of the function. // They are exported again at the end of the function.
handlers = ['onFrame', 'onResize'].concat(toolHandlers), handlers = ['onFrame', 'onResize'].concat(toolHandlers),
res; // compile a list of paramter names for all variables that need to
// appear as globals inside the script. At the same time, also
// collect their values, so we can pass them on as arguments in the
// function call.
params = [],
args = [],
func;
code = compile(code); code = compile(code);
// compile a list of paramter names for all variables that need to function expose(scope, hidden) {
// appear as globals inside the script. At the same time, also collect // Look through all enumerable properties on the scope and expose
// their values, so we can pass them on as arguments in the function // these too as pseudo-globals, but only if they seem to be in use.
// call. for (var key in scope) {
var params = ['_$_', '$_', 'view', 'tool'], if ((hidden || !/^_/.test(key)) && new RegExp(
args = [_$_, $_ , view, tool]; '\\b' + key.replace(/\$/g, '\\$') + '\\b').test(code)) {
// Look through all enumerable properties on the scope and expose these params.push(key);
// too as pseudo-globals. args.push(scope[key]);
for (var key in scope) { }
if (!/^_/.test(key)) {
params.push(key);
args.push(scope[key]);
} }
} }
expose({ _$_: _$_, $_: $_, view: view, tool: tool }, true);
expose(scope);
// Finally define the handler variable names as parameters and compose // Finally define the handler variable names as parameters and compose
// the string describing the properties for the returned object at the // the string describing the properties for the returned object at the
// end of the code execution, so we can retrieve their values from the // end of the code execution, so we can retrieve their values from the
// function call. // function call.
handlers = Base.each(handlers, function(key) { handlers = Base.each(handlers, function(key) {
params.push(key); // Check for each handler explicitely and only return them if they
this.push(key + ': ' + key); // seem to exist.
if (new RegExp('\\s+' + key + '\\b').test(code)) {
params.push(key);
this.push(key + ': ' + key);
}
}, []).join(', '); }, []).join(', ');
// We need an additional line that returns the handlers in one object. // We need an additional line that returns the handlers in one object.
code += '\nreturn { ' + handlers + ' };'; if (handlers)
code += '\nreturn { ' + handlers + ' };';
/*#*/ if (__options.environment == 'browser') { /*#*/ if (__options.environment == 'browser') {
if (root.InstallTrigger) { // Firefox if (window.InstallTrigger || window.chrome) { // Firefox and Chrome
// Add a semi-colon at the start so Firefox doesn't swallow empty // On Firefox, all error numbers inside dynamically compiled code
// lines and shift error messages. // are relative to the line where the eval / compilation happened.
code = ';' + code; // To fix this issue, we're temporarily inserting a new script
// On Firefox, all error numbers inside evaled code are relative to // tag. We also use this on Chrome to fix an issue with compiled
// the line where the eval happened. Totally silly, but that's how // functions:
// it is. So we're calculating the base of lineNumbers, to remove it // https://code.google.com/p/chromium/issues/detail?id=331655
// again from reported errors. Luckily, Firefox is the only browser var script = document.createElement('script'),
// where we can define the lineNumber for exceptions. head = document.head;
var handle = PaperScript.handleException; // Do not add a new-line before the code on Chrome since the error
if (!handle) { // messages are shifted by one line there...
handle = PaperScript.handleException = function(e) { if (!window.chrome)
throw e.lineNumber >= lineNumber code = '\n' + code;
? new Error(e.message, e.fileName, script.appendChild(document.createTextNode(
e.lineNumber - lineNumber) 'paper._execute = function(' + params + ') {' + code + '\n}'
: e; ));
}; head.appendChild(script);
// We're using a crazy hack to detect wether the library is func = paper._execute;
// minified or not: By generating a second error on the 2nd line head.removeChild(script);
// and using the difference in line numbers to calculate the
// offset to the eval, it works in both casees.
var lineNumber = new Error().lineNumber;
lineNumber += (new Error().lineNumber - lineNumber) * 3;
}
try {
res = new Function(params, code).apply(scope, args);
// NOTE: in order for the calculation of the above lineNumber
// offset to work, we cannot add any statements before the above
// line of code, nor can we put it into a separate function.
} catch (e) {
handle(e);
}
} else { } else {
res = new Function(params, code).apply(scope, args); func = Function(params, code);
} }
/*#*/ } else { // !__options.environment == 'browser' /*#*/ } else { // !__options.environment == 'browser'
res = new Function(params, code).apply(scope, args); func = Function(params, code);
/*#*/ } // !__options.environment == 'browser' /*#*/ } // !__options.environment == 'browser'
var res = func.apply(scope, args) || {};
// Now install the 'global' tool and view handlers, and we're done! // Now install the 'global' tool and view handlers, and we're done!
Base.each(toolHandlers, function(key) { Base.each(toolHandlers, function(key) {
var value = res[key]; var value = res[key];
@ -404,15 +396,21 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
path = require('path'); path = require('path');
require.extensions['.pjs'] = function(module, uri) { require.extensions['.pjs'] = function(module, uri) {
var source = compile(fs.readFileSync(uri, 'utf8')), // Requiring a PaperScript on Node.js returns an initialize method which
scope = new PaperScope(); // needs to receive a Canvas object when called and returns the
scope.__filename = uri; // PaperScope.
scope.__dirname = path.dirname(uri); module.exports = function(canvas) {
// Expose core methods and values var source = compile(fs.readFileSync(uri, 'utf8')),
scope.require = require; scope = new PaperScope();
scope.console = console; scope.setup(canvas);
execute(source, scope); scope.__filename = uri;
module.exports = scope; scope.__dirname = path.dirname(uri);
// Expose core methods and values
scope.require = require;
scope.console = console;
execute(source, scope);
return scope;
};
}; };
/*#*/ } // __options.environment == 'node' /*#*/ } // __options.environment == 'node'
@ -423,4 +421,6 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
}; };
/*#*/ } // !__options.environment == 'browser' /*#*/ } // !__options.environment == 'browser'
})(this); // Pass on `this` as the binding object, so we can reference Acorn both in
// development and in the built library.
}).call(this);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -46,7 +46,7 @@ var DomElement = new function() {
return res; return res;
} }
return { return /** @lends DomElement */{
create: function(nodes, parent) { create: function(nodes, parent) {
var isArray = Array.isArray(nodes), var isArray = Array.isArray(nodes),
res = create(isArray ? nodes : arguments, isArray ? parent : null); res = create(isArray ? nodes : arguments, isArray ? parent : null);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -15,7 +15,7 @@
* @namespace * @namespace
* @private * @private
*/ */
var DomEvent = { var DomEvent = /** @lends DomEvent */{
add: function(el, events) { add: function(el, events) {
for (var type in events) for (var type in events)
el.addEventListener(type, events[type], false); el.addEventListener(type, events[type], false);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -1804,12 +1804,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* data string. * data string.
* *
* The options object offers control over some aspects of the SVG export: * The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether the JSON is returned as
* a {@code Object} or a {@code String}.
* <b>options.precision:</b> {@code Number} the amount of fractional * <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in JSON data. * digits in numbers used in JSON data.
* *
* @name Item#exportJSON * @name Item#exportJSON
* @function * @function
* @param {Object} [options={ precision: 5 }] the serialization options * @param {Object} [options={ asString: true, precision: 5 }] the
* serialization options
* @return {String} the exported JSON data * @return {String} the exported JSON data
*/ */
@ -1836,8 +1839,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* Exports the item with its content and child items as an SVG DOM. * Exports the item with its content and child items as an SVG DOM.
* *
* The options object offers control over some aspects of the SVG export: * The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a String * <b>options.asString:</b> {@code Boolean} wether a SVG node or a
* is to be returned. * {@code String} is to be returned.
* <b>options.precision:</b> {@code Number} the amount of fractional * <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in SVG data. * digits in numbers used in SVG data.
* <b>options.matchShapes:</b> {@code Boolean} wether imported path * <b>options.matchShapes:</b> {@code Boolean} wether imported path
@ -2718,6 +2721,9 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns', // 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns',
// 'lines'. Default: ['objects', 'children'] // 'lines'. Default: ['objects', 'children']
transform: function(matrix /*, applyMatrix */) { transform: function(matrix /*, applyMatrix */) {
// Bail out immediatelly if there is nothing to do
if (matrix.isIdentity())
return this;
// Calling _changed will clear _bounds and _position, but depending // Calling _changed will clear _bounds and _position, but depending
// on matrix we can calculate and set them again. // on matrix we can calculate and set them again.
var bounds = this._bounds, var bounds = this._bounds,

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -13,16 +13,16 @@
* *
*** ***
* *
* straps.js - Class inheritance library with support for bean-style accessors * Straps.js - Class inheritance library with support for bean-style accessors
* *
* Copyright (c) 2006 - 2013 Juerg Lehni * Copyright (c) 2006 - 2013 Juerg Lehni
* http://lehni.org/ * http://scratchdisk.com/
* *
* Distributed under the MIT license. * Distributed under the MIT license.
* *
*** ***
* *
* acorn.js * Acorn.js
* http://marijnhaverbeke.nl/acorn/ * http://marijnhaverbeke.nl/acorn/
* *
* Acorn is a tiny, fast JavaScript parser written in JavaScript, * Acorn is a tiny, fast JavaScript parser written in JavaScript,

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -555,7 +555,7 @@ statics: {
}, },
getParameterOf: function(v, x, y) { getParameterOf: function(v, x, y) {
// Handle beginnings and end seperately, as they are not detected // Handle beginnings and end separately, as they are not detected
// sometimes. // sometimes.
var tolerance = /*#=*/ Numerical.TOLERANCE; var tolerance = /*#=*/ Numerical.TOLERANCE;
if (Math.abs(v[0] - x) < tolerance && Math.abs(v[1] - y) < tolerance) if (Math.abs(v[0] - x) < tolerance && Math.abs(v[1] - y) < tolerance)
@ -674,7 +674,7 @@ statics: {
c = v1 - v0, c = v1 - v0,
count = Numerical.solveQuadratic(a, b, c, roots), count = Numerical.solveQuadratic(a, b, c, roots),
// Add some tolerance for good roots, as t = 0 / 1 are added // Add some tolerance for good roots, as t = 0 / 1 are added
// seperately anyhow, and we don't want joins to be added with // separately anyhow, and we don't want joins to be added with
// radiuses in getStrokeBounds() // radiuses in getStrokeBounds()
tMin = /*#=*/ Numerical.TOLERANCE, tMin = /*#=*/ Numerical.TOLERANCE,
tMax = 1 - tMin; tMax = 1 - tMin;
@ -1090,12 +1090,13 @@ new function() { // Scope for methods that require numerical integration
b = 1; b = 1;
var isZero = Numerical.isZero; var isZero = Numerical.isZero;
// See if the curve is linear by checking p1 == c1 and p2 == c2 // See if the curve is linear by checking p1 == c1 and p2 == c2
if (isZero(v[0] - v[2]) && isZero(v[1] - v[3]) if (a === 0 && b === 1
&& isZero(v[0] - v[2]) && isZero(v[1] - v[3])
&& isZero(v[6] - v[4]) && isZero(v[7] - v[5])) { && isZero(v[6] - v[4]) && isZero(v[7] - v[5])) {
// Straight line // Straight line
var dx = v[6] - v[0], // p2x - p1x var dx = v[6] - v[0], // p2x - p1x
dy = v[7] - v[1]; // p2y - p1y dy = v[7] - v[1]; // p2y - p1y
return (b - a) * Math.sqrt(dx * dx + dy * dy); return Math.sqrt(dx * dx + dy * dy);
} }
var ds = getLengthIntegrand(v); var ds = getLengthIntegrand(v);
return Numerical.integrate(ds, a, b, getIterations(a, b)); return Numerical.integrate(ds, a, b, getIterations(a, b));

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -15,6 +15,11 @@
// from "Graphics Gems", Academic Press, 1990 // from "Graphics Gems", Academic Press, 1990
// Modifications and optimisations of original algorithm by Juerg Lehni. // Modifications and optimisations of original algorithm by Juerg Lehni.
/**
* @name PathFitter
* @class
* @private
*/
var PathFitter = Base.extend({ var PathFitter = Base.extend({
initialize: function(path, error) { initialize: function(path, error) {
this.points = []; this.points = [];

View file

@ -2,14 +2,19 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
* All rights reserved. * All rights reserved.
*/ */
/**
* @name PathFlattener
* @class
* @private
*/
var PathFlattener = Base.extend({ var PathFlattener = Base.extend({
initialize: function(path) { initialize: function(path) {
this.curves = []; // The curve values as returned by getValues() this.curves = []; // The curve values as returned by getValues()

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -335,12 +335,15 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* a JSON data string. * a JSON data string.
* *
* The options object offers control over some aspects of the SVG export: * The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether the JSON is returned as
* a {@code Object} or a {@code String}.
* <b>options.precision:</b> {@code Number} the amount of fractional * <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in JSON data. * digits in numbers used in JSON data.
* *
* @name Project#exportJSON * @name Project#exportJSON
* @function * @function
* @param {Object} [options={ precision: 5 }] the serialization options * @param {Object} [options={ asString: true, precision: 5 }] the
* serialization options
* @return {String} the exported JSON data * @return {String} the exported JSON data
*/ */
@ -364,8 +367,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* all contained in one top level SVG group node. * all contained in one top level SVG group node.
* *
* The options object offers control over some aspects of the SVG export: * The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a String * <b>options.asString:</b> {@code Boolean} wether a SVG node or a
* is to be returned. * {@code String} is to be returned.
* <b>options.precision:</b> {@code Number} the amount of fractional * <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in SVG data. * digits in numbers used in SVG data.
* <b>options.matchShapes:</b> {@code Boolean} wether imported path * <b>options.matchShapes:</b> {@code Boolean} wether imported path

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -247,23 +247,20 @@ var Color = Base.extend(new function() {
} }
return value; return value;
} }
: name === 'hue' : type === 'gradient'
? function(value) { ? function(/* value */) {
// Keep negative values within modulo 360 too: return Point.read(arguments, 0, 0, {
return isNaN(value) ? 0 readNull: name === 'highlight',
: ((value % 360) + 360) % 360; clone: true
});
} }
: type === 'gradient' : function(value) {
? function(/* value */) { // NOTE: We don't clamp values here, they're only
return Point.read(arguments, 0, 0, { // clamped once the actual CSS values are produced.
readNull: name === 'highlight', // Gotta love the fact that isNaN(null) is false,
clone: true // while isNaN(undefined) is true.
}); return value == null || isNaN(value) ? 0 : value;
} };
: function(value) {
return isNaN(value) ? 0
: Math.min(Math.max(value, 0), 1);
};
this['get' + part] = function() { this['get' + part] = function() {
return this._type === type return this._type === type
@ -401,7 +398,7 @@ var Color = Base.extend(new function() {
* // the path and to position the gradient color: * // the path and to position the gradient color:
* var topLeft = view.center - [80, 80]; * var topLeft = view.center - [80, 80];
* var bottomRight = view.center + [80, 80]; * var bottomRight = view.center + [80, 80];
* *
* var path = new Path.Rectangle({ * var path = new Path.Rectangle({
* topLeft: topLeft, * topLeft: topLeft,
* bottomRight: bottomRight, * bottomRight: bottomRight,
@ -489,7 +486,6 @@ var Color = Base.extend(new function() {
var slice = Array.prototype.slice, var slice = Array.prototype.slice,
args = arguments, args = arguments,
read = 0, read = 0,
parse = true,
type, type,
components, components,
alpha, alpha,
@ -520,8 +516,6 @@ var Color = Base.extend(new function() {
} }
} }
if (!components) { if (!components) {
// Only parse values if we're not told to not do so
parse = !(this.__options && this.__options.dontParse);
// Determine if there is a values array // Determine if there is a values array
values = argType === 'number' values = argType === 'number'
? args ? args
@ -586,7 +580,7 @@ var Color = Base.extend(new function() {
: 'rgb'; : 'rgb';
// Convert to array and parse in one loop, for efficiency // Convert to array and parse in one loop, for efficiency
var properties = types[type]; var properties = types[type];
parsers = parse && componentParsers[type]; parsers = componentParsers[type];
this._components = components = []; this._components = components = [];
for (var i = 0, l = properties.length; i < l; i++) { for (var i = 0, l = properties.length; i < l; i++) {
var value = arg[properties[i]]; var value = arg[properties[i]];
@ -600,8 +594,7 @@ var Color = Base.extend(new function() {
radial: arg.radial radial: arg.radial
}; };
} }
if (parse) value = parsers[i].call(this, value);
value = parsers[i].call(this, value);
if (value != null) if (value != null)
components[i] = value; components[i] = value;
} }
@ -623,9 +616,7 @@ var Color = Base.extend(new function() {
this._components = components = []; this._components = components = [];
var parsers = componentParsers[this._type]; var parsers = componentParsers[this._type];
for (var i = 0, l = parsers.length; i < l; i++) { for (var i = 0, l = parsers.length; i < l; i++) {
var value = values && values[i]; var value = parsers[i].call(this, values && values[i]);
if (parse)
value = parsers[i].call(this, value);
if (value != null) if (value != null)
components[i] = value; components[i] = value;
} }
@ -656,6 +647,24 @@ var Color = Base.extend(new function() {
this._owner._changed(/*#=*/ Change.STYLE); this._owner._changed(/*#=*/ Change.STYLE);
}, },
/**
* Returns a copy of the components array with all values clamped to
* valid numbers, based on the type of property they represent.
*/
_clamp: function() {
var components = this._components.slice(),
properties = this._properties;
if (this._type !== 'gradient') {
for (var i = 0, l = properties.length; i < l; i++) {
var value = components[i];
components[i] = properties[i] === 'hue'
? ((value % 360) + 360) % 360
: value < 0 ? 0 : value > 1 ? 1 : value;
}
}
return components;
},
/** /**
* @return {Number[]} the converted components as an array * @return {Number[]} the converted components as an array
*/ */
@ -664,11 +673,11 @@ var Color = Base.extend(new function() {
return this._type === type return this._type === type
? this._components.slice() ? this._components.slice()
: (converter = converters[this._type + '-' + type]) : (converter = converters[this._type + '-' + type])
? converter.apply(this, this._components) ? converter.apply(this, this._clamp())
// Convert to and from rgb if no direct converter exists // Convert to and from rgb if no direct converter exists
: converters['rgb-' + type].apply(this, : converters['rgb-' + type].apply(this,
converters[this._type + '-rgb'].apply(this, converters[this._type + '-rgb'].apply(this,
this._components)); this._clamp()));
}, },
/** /**
@ -776,6 +785,7 @@ var Color = Base.extend(new function() {
/** /**
* @name Color#clone * @name Color#clone
* @function
* *
* Returns a copy of the color object. * Returns a copy of the color object.
* *
@ -815,13 +825,16 @@ var Color = Base.extend(new function() {
// TODO: Support HSL / HSLA CSS3 colors directly, without conversion // TODO: Support HSL / HSLA CSS3 colors directly, without conversion
var components = this._convert('rgb'), var components = this._convert('rgb'),
alpha = hex || this._alpha == null ? 1 : this._alpha; alpha = hex || this._alpha == null ? 1 : this._alpha;
function convert(val) {
return Math.round((val < 0 ? 0 : val > 1 ? 1 : val) * 255);
}
components = [ components = [
Math.round(components[0] * 255), convert(components[0]),
Math.round(components[1] * 255), convert(components[1]),
Math.round(components[2] * 255) convert(components[2])
]; ];
if (alpha < 1) if (alpha < 1)
components.push(alpha); components.push(val < 0 ? 0 : val);
return hex return hex
? '#' + ((1 << 24) + (components[0] << 16) ? '#' + ((1 << 24) + (components[0] << 16)
+ (components[1] << 8) + (components[1] << 8)
@ -1119,48 +1132,33 @@ var Color = Base.extend(new function() {
} }
}); });
}, new function() { }, new function() {
function clamp(value, hue) {
return value < 0
? 0
: hue && value > 360
? 360
: !hue && value > 1
? 1
: value;
}
var operators = { var operators = {
add: function(a, b, hue) { add: function(a, b) {
return clamp(a + b, hue); return a + b;
}, },
subtract: function(a, b, hue) { subtract: function(a, b) {
return clamp(a - b, hue); return a - b;
}, },
multiply: function(a, b, hue) { multiply: function(a, b) {
return clamp(a * b, hue); return a * b;
}, },
divide: function(a, b, hue) { divide: function(a, b) {
return clamp(a / b, hue); return a / b;
} }
}; };
return Base.each(operators, function(operator, name) { return Base.each(operators, function(operator, name) {
// Tell the argument reader not to parse values for multiply and divide, this[name] = function(color) {
// so the are not clamped yet. color = Color.read(arguments, 0, 0);
var options = { dontParse: /^(multiply|divide)$/.test(name) };
this[name] = function(/* color */) {
var color = Color.read(arguments, 0, 0, options);
var type = this._type, var type = this._type,
properties = this._properties, properties = this._properties,
components1 = this._components, components1 = this._components,
components2 = color._convert(type); components2 = color._convert(type);
for (var i = 0, l = components1.length; i < l; i++) for (var i = 0, l = components1.length; i < l; i++)
components2[i] = operator(components1[i], components2[i], components2[i] = operator(components1[i], components2[i]);
properties[i] === 'hue');
return new Color(type, components2, return new Color(type, components2,
this._alpha != null this._alpha != null
? operator(this._alpha, color.getAlpha()) ? operator(this._alpha, color.getAlpha())

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -55,24 +55,25 @@ new function() {
attrs[center ? 'cy' : 'y'] = point.y; attrs[center ? 'cy' : 'y'] = point.y;
trans = null; trans = null;
} }
if (matrix.isIdentity()) if (!matrix.isIdentity()) {
return attrs; // See if we can decompose the matrix and can formulate it as a
// See if we can decompose the matrix and can formulate it as a simple // simple translate/scale/rotate command sequence.
// translate/scale/rotate command sequence. var decomposed = matrix.decompose();
var decomposed = matrix.decompose(); if (decomposed && !decomposed.shearing) {
if (decomposed && !decomposed.shearing) { var parts = [],
var parts = [], angle = decomposed.rotation,
angle = decomposed.rotation, scale = decomposed.scaling;
scale = decomposed.scaling; if (trans && !trans.isZero())
if (trans && !trans.isZero()) parts.push('translate(' + formatter.point(trans) + ')');
parts.push('translate(' + formatter.point(trans) + ')'); if (angle)
if (angle) parts.push('rotate(' + formatter.number(angle) + ')');
parts.push('rotate(' + formatter.number(angle) + ')'); if (!Numerical.isZero(scale.x - 1)
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1)) || !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')'); parts.push('scale(' + formatter.point(scale) +')');
attrs.transform = parts.join(' '); attrs.transform = parts.join(' ');
} else { } else {
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')'; attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
}
} }
return attrs; return attrs;
} }

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -143,7 +143,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
return false; return false;
} }
return { return /** @lends CanvasView# */{
/** /**
* Returns true if event was stopped, false otherwise, whether handler * Returns true if event was stopped, false otherwise, whether handler
* was called or not! * was called or not!

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -706,8 +706,7 @@ var View = Base.extend(Callback, /** @lends View# */{
} }
if (view) { if (view) {
var point = viewToProject(view, event); var point = viewToProject(view, event);
if (dragging || new Rectangle(new Point(), if (dragging || view.getBounds().contains(point))
view.getViewSize()).contains(point))
tool = handleMouseMove(view, point, event); tool = handleMouseMove(view, point, event);
} }
} }

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -12,9 +12,10 @@
/** /**
* @name Formatter * @name Formatter
* @class
* @private * @private
*/ */
var Formatter = Base.extend({ var Formatter = Base.extend(/** @lends Formatter# */{
/** /**
* @param {Number} [precision=5] the amount of fractional digits. * @param {Number} [precision=5] the amount of fractional digits.
*/ */

View file

@ -2,14 +2,19 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
* All rights reserved. * All rights reserved.
*/ */
/**
* @name Numerical
* @namespace
* @private
*/
var Numerical = new function() { var Numerical = new function() {
// Lookup tables for abscissas and weights with values for n = 2 .. 16. // Lookup tables for abscissas and weights with values for n = 2 .. 16.
@ -75,7 +80,7 @@ var Numerical = new function() {
}; };
} }
return { return /** @lends Numerical */{
TOLERANCE: TOLERANCE, TOLERANCE: TOLERANCE,
// Precision when comparing against 0 // Precision when comparing against 0
EPSILON: EPSILON, EPSILON: EPSILON,
@ -114,13 +119,13 @@ var Numerical = new function() {
findRoot: function(f, df, x, a, b, n, tolerance) { findRoot: function(f, df, x, a, b, n, tolerance) {
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
var fx = f(x), var fx = f(x),
dx = fx / df(x); // Calculate a new candidate with the Newton-Raphson method.
dx = fx / df(x),
nx = x - dx;
// See if we can trust the Newton-Raphson result. If not we use // See if we can trust the Newton-Raphson result. If not we use
// bisection to find another candiate for Newton's method. // bisection to find another candiate for Newton's method.
if (abs(dx) < tolerance) if (abs(dx) < tolerance)
return x; return nx;
// Generate a candidate for Newton's method.
var nx = x - dx;
// Update the root-bounding interval and test for containment of // Update the root-bounding interval and test for containment of
// the candidate. If candidate is outside the root-bounding // the candidate. If candidate is outside the root-bounding
// interval, use bisection instead. // interval, use bisection instead.
@ -135,6 +140,9 @@ var Numerical = new function() {
x = nx >= b ? 0.5 * (a + b) : nx; x = nx >= b ? 0.5 * (a + b) : nx;
} }
} }
// Return the best result even though we haven't gotten close
// enough to the root... (In paper.js this never seems to happen).
return x;
}, },
/** /**

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *
@ -51,6 +51,14 @@ test('Set color to array', function() {
}); });
test('Creating Colors', function() { test('Creating Colors', function() {
compareColors(new Color(), new Color(0, 0, 0),
'Color with no arguments should be black');
compareColors(new Color('black'), new Color(0, 0, 0),
'Color from name (black)');
compareColors(new Color('red'), new Color(1, 0, 0),
'Color from name (red)');
compareColors(new Color('#ff0000'), new Color(1, 0, 0), compareColors(new Color('#ff0000'), new Color(1, 0, 0),
'Color from hex code'); 'Color from hex code');
@ -203,7 +211,7 @@ test('Saturation from black rgb', function() {
test('Color#add', function() { test('Color#add', function() {
var color = new Color(0, 1, 1); var color = new Color(0, 1, 1);
compareColors(color.add([1, 0, 0]), [1, 1, 1]); compareColors(color.add([1, 0, 0]), [1, 1, 1]);
compareColors(color.add([1, 0.5, 0]), [1, 1, 1]); compareColors(color.add([1, 0.5, 0]), [1, 1.5, 1]);
var color = new Color(0, 0.5, 0); var color = new Color(0, 0.5, 0);
compareColors(color.add(0.5), [0.5, 1, 0.5]); compareColors(color.add(0.5), [0.5, 1, 0.5]);
}); });
@ -229,7 +237,7 @@ test('Color#divide', function() {
var color = new Color(1, 1, 1); var color = new Color(1, 1, 1);
compareColors(color.divide([1, 2, 4]), [1, 0.5, 0.25]); compareColors(color.divide([1, 2, 4]), [1, 0.5, 0.25]);
var color = new Color(1, 0.5, 0.25); var color = new Color(1, 0.5, 0.25);
compareColors(color.divide(0.25), [1, 1, 1]); compareColors(color.divide(0.25), [4, 2, 1]);
var color = new Color(1, 1, 1); var color = new Color(1, 1, 1);
compareColors(color.divide(4), [0.25, 0.25, 0.25]); compareColors(color.divide(4), [0.25, 0.25, 0.25]);
}); });

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://scratchdisk.com/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details. * Distributed under the MIT license. See LICENSE file for details.
* *

Some files were not shown because too many files have changed in this diff Show more