Revert "Merge paper.js 0.12.3"

This commit is contained in:
DD Liu 2020-04-30 11:43:22 -04:00 committed by GitHub
parent 84fc26abbf
commit eab98477cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
142 changed files with 672 additions and 3593 deletions

View file

@ -1,12 +1,13 @@
language: node_js language: node_js
# Follow https://github.com/nodejs/LTS to decide when to remove a version # Follow https://github.com/nodejs/LTS to decide when to remove a version
node_js: node_js:
# Stable version is temporarily disabled due to a bug in resemblejs package with - 9
# node v12 (https://github.com/orgs/paperjs/teams/contributors/discussions/12).
# - stable
# - 11
- 10
- 8 - 8
# 6.13 and 6.14 causing unreasonable errors in SymbolDefinition.initialize.
# https://travis-ci.org/paperjs/paper.js/jobs/434854796
# To avoid these versions, we specify version to 6.12 as temporary solution.
# See https://github.com/paperjs/paper.js/issues/1523
- 6.12
sudo: false sudo: false
env: env:
matrix: matrix:

View file

@ -1,83 +1,5 @@
# Change Log # Change Log
## `0.12.3`
### Fixed
- Fix regression in `Color` change propagation (#1672, #1674).
- SVG Export: Fix viewport size of exported `Symbol` (#1668).
- Handle non-invertible matrices in `Item#contains()` (#1651).
- Improve documentation for `Item#clipMask` (#1673).
- Improve TypeScript definitions (#1659, #1663, #1664, #1667)
### Added
- Add documentation for `Item#internalBounds`.
## `0.12.2`
### Fixed
- Fix drawing with compound-paths as clip-items (#1361).
- Fix drawing of path selection with small handle size (#1327).
- Do not ignore `Group#clipItem.matrix` in `Group#internalBounds` (#1427).
- Correctly calculate bounds with nested empty items (#1467).
- Fix color change propagation on groups (#1152).
- Fix `Path#arcTo()` where `from` and `to` points are equal (#1613).
- Improve `new Raster(size[, position])` constructor (#1621).
- SVG Export: Fix error when `Item#matrix` is not invertible (#1580).
- SVG Export: Include missing viewBox attribute (#1576).
- SVG Import: Use correct default values for gradients (#1632, #1660).
- SVG Import: Add basic `<switch/>` support (#1597).
- JSON Import: Prevent `Item#insert()` method from being overridden (#1392).
- PaperScript: Fix issues with increment/decrement operators (#1450, #1611).
## `0.12.1`
### Added
- Add TypeScript definition, automatically generated from JSDoc comments
(#1612).
- Support `new Raster(size[, position])` constructor.
- Expose `Raster#context` accessor.
- Implement `Raster#clear()` method to clear associated canvas context.
- Node.js: Add support for Node.js v11 and v12.
### Fixed
- Fix parsing of CSS colors with spaces in parentheses (#1629).
- Improve `Color.random()` documentation.
- Fix `Tween#then()` documentation.
### Removed
- Node.js: Remove support for Node.js v6.
## `0.12.0`
### News
Another release, another new member on the team: Please welcome
[@arnoson](https://github.com/arnoson), who has worked hard on the all new
animation support, exposed through the `Tween` class and its various methods on
the `Item` class, see below for details:
### Added
- Add new `Tween` class and related methods on `Item`, to animate and
interpolate their various properties, including colors, sub-properties, etc.:
`Item#tween(from, to, options)`, `Item#tween(to, options)`,
`Item#tween(options)`, `Item#tweenFrom(from, options)`,
`Item#tweenTo(to, options)`
### Fixed
- Only draw Raster if image is not empty (#1320).
- Emit mousedrag events on correct items when covered by other items (#1465).
- Fix drawing issues of bounds and position with `Group#selectedColor` (#1571).
- Fix `Item.once()` to actually only emit event once.
- Various documentation fixes and improvements (#1399).
## `0.11.8` ## `0.11.8`
### News ### News
@ -137,7 +59,6 @@ the fixes and additions from the past two weeks:
## `0.11.5` ## `0.11.5`
### Fixed ### Fixed
- Fix `Curve#isSelected()` to correctly reflect the state of `#handle1` (#1378). - Fix `Curve#isSelected()` to correctly reflect the state of `#handle1` (#1378).
- Key Events: Fix auto-filling issue on Chrome (#1358, #1365). - Key Events: Fix auto-filling issue on Chrome (#1358, #1365).
- Boolean: Check that overlaps are on the right path (#1321). - Boolean: Check that overlaps are on the right path (#1321).
@ -150,42 +71,38 @@ the fixes and additions from the past two weeks:
## `0.11.4` ## `0.11.4`
### Changed ### Changed
- Node.js: Add support for v8, and keep testing v4, v6, v7 in Travis CI. - Node.js: Add support for v8, and keep testing v4, v6, v7 in Travis CI.
## `0.11.3` ## `0.11.3`
### Fixed ### Fixed
- Mouse Events: Fix item-based `doubleclick` events (#1316). - Mouse Events: Fix item-based `doubleclick` events (#1316).
- Overhaul the caching of bounds and matrix decomposition, improving reliability - Overhaul the caching of bounds and matrix decomposition, improving reliability
of `Item#rotation` and `#scaling` and fixing situations caused by wrongly of `Item#rotation` and `#scaling` and fixing situations caused by wrongly
caching `Item#position` and `#bounds` values. caching `Item#position` and `#bounds` values.
- Prevent consumed properties in object literal constructors from being set on - Prevent consumed properties in object literal constructors from being set on
the instance. the instance.
### Changed ### Changed
- Make all functions and accessors enumerable on all Paper.js classes. - Make all functions and accessors enumerable on all Paper.js classes.
## `0.11.2` ## `0.11.2`
### Fixed ### Fixed
- PaperScript: Fix a parsing error in math operations without white-space - PaperScript: Fix a parsing error in math operations without white-space
(#1314). (#1314).
## `0.11.1` ## `0.11.1`
### Fixed ### Fixed
- Bring back deactivation of Node.js modules on browsers. This has most probably - Bring back deactivation of Node.js modules on browsers. This has most probably
broken Webpack bundling in `0.11.0`. broken Webpack bundling in `0.11.0`.
## `0.11.0` ## `0.11.0`
### Changed ### Changed
- Separate `paper` module on NPM into: `paper`, `paper-jsdom` and - Separate `paper` module on NPM into: `paper`, `paper-jsdom` and
`paper-jsdom-canvas` (#1252): `paper-jsdom-canvas` (#1252):
- `paper` is the main library, and can be used directly in a browser - `paper` is the main library, and can be used directly in a browser
@ -198,14 +115,12 @@ the fixes and additions from the past two weeks:
[jsdom](https://github.com/tmpvar/jsdom). [jsdom](https://github.com/tmpvar/jsdom).
### Added ### Added
- PaperScript: Support newer, external versions of Acorn.js for PaperScript - PaperScript: Support newer, external versions of Acorn.js for PaperScript
parsing, opening the doors to ES 2015 (#1183, #1275). parsing, opening the doors to ES 2015 (#1183, #1275).
- Hit Tests: Implement `options.position` to hit `Item#position` (#1249). - Hit Tests: Implement `options.position` to hit `Item#position` (#1249).
- Split `Item#copyTo()` into `#addTo()` and `#copyTo()`. - Split `Item#copyTo()` into `#addTo()` and `#copyTo()`.
### Fixed ### Fixed
- Intersections: Bring back special handling of curve end-points (#1284). - Intersections: Bring back special handling of curve end-points (#1284).
- Intersections: Correctly handle `Item#applyMatrix = false` (#1289). - Intersections: Correctly handle `Item#applyMatrix = false` (#1289).
- Boolean: Bring back on-path winding handling (#1281). - Boolean: Bring back on-path winding handling (#1281).
@ -239,7 +154,6 @@ the fixes and additions from the past two weeks:
## `0.10.3` ## `0.10.3`
### Changed ### Changed
- Node.js: Support v7, and keep testing v4 up to v7 in Travis CI. - Node.js: Support v7, and keep testing v4 up to v7 in Travis CI.
- Node.js: Loosely couple Node.js / Electron code to `Canvas` module, and treat - Node.js: Loosely couple Node.js / Electron code to `Canvas` module, and treat
its absence like a headless web worker context in the browser (#1103). its absence like a headless web worker context in the browser (#1103).
@ -264,7 +178,6 @@ the fixes and additions from the past two weeks:
`#reorient()` (#973). `#reorient()` (#973).
### Added ### Added
- Implement `Path#divideAt(location)`, in analogy to `Curve#divideAt(location)`. - Implement `Path#divideAt(location)`, in analogy to `Curve#divideAt(location)`.
- Add `PathItem#compare()` as a way to compare the geometry of two paths to see - Add `PathItem#compare()` as a way to compare the geometry of two paths to see
if they describe the same shape, handling cases where paths start in different if they describe the same shape, handling cases where paths start in different
@ -283,7 +196,6 @@ the fixes and additions from the past two weeks:
(#1004, #1177). (#1004, #1177).
### Fixed ### Fixed
- Many improvements to boolean operations: - Many improvements to boolean operations:
- Improve performance of boolean operations when there no actual crossings - Improve performance of boolean operations when there no actual crossings
between the paths, but paths may be contained within each other. between the paths, but paths may be contained within each other.
@ -324,20 +236,17 @@ the fixes and additions from the past two weeks:
(#632). (#632).
### Removed ### Removed
- Remove `Numerical.TOLERANCE = 1e-6` as there is no internal use for it - Remove `Numerical.TOLERANCE = 1e-6` as there is no internal use for it
anymore. anymore.
## `0.10.2` ## `0.10.2`
### Fixed ### Fixed
- Get published version to work correctly in Bower again. - Get published version to work correctly in Bower again.
## `0.10.1` ## `0.10.1`
### Fixed ### Fixed
- Correct a few issues with documentation and NPM publishing that slipped - Correct a few issues with documentation and NPM publishing that slipped
through in the `0.10.0` release. through in the `0.10.0` release.
@ -375,7 +284,6 @@ Thank you all for using Paper.js, submitting bugs and ideas, and all those that
contribute to the code. contribute to the code.
### Changed ### Changed
- Significant overhaul and improvements of boolean path operations - Significant overhaul and improvements of boolean path operations
`PathItem#unite()`, `#subtract()`, `#intersect()`, `#exclude()`, `#divide()`: `PathItem#unite()`, `#subtract()`, `#intersect()`, `#exclude()`, `#divide()`:
- Improve handling of self-intersecting paths and non-zero fill-rules. - Improve handling of self-intersecting paths and non-zero fill-rules.
@ -392,7 +300,7 @@ contribute to the code.
- `Curve#getParameterAt(offset)``#getTimeAt(offset)` - `Curve#getParameterAt(offset)``#getTimeAt(offset)`
- `Curve#getParameterOf(point)``getTimeOf(point)` - `Curve#getParameterOf(point)``getTimeOf(point)`
- `Curve#getPointAt(time, true)``#getPointAtTime(time)` - `Curve#getPointAt(time, true)``#getPointAtTime(time)`
- `Curve#getTangentAt(time, true)``#getTangentAtTime(time)` - `Curve#getTangentAt(time, true)``#getTangenttTime(time)`
- `Curve#getNormalAt(time, true)``#getNormalAtTime(time)` - `Curve#getNormalAt(time, true)``#getNormalAtTime(time)`
- `Curve#getCurvatureAt(time, true)``#getCurvatureAtTime(time)` - `Curve#getCurvatureAt(time, true)``#getCurvatureAtTime(time)`
- `CurveLocation#parameter``#time` - `CurveLocation#parameter``#time`
@ -452,7 +360,6 @@ contribute to the code.
`Color` (#1043). `Color` (#1043).
### Added ### Added
- Use unified code-base for browsers, Node.js, Electron, and anything - Use unified code-base for browsers, Node.js, Electron, and anything
in-between, and enable npm install for browser use (#739). in-between, and enable npm install for browser use (#739).
- Start using automatic code testing and deployment of prebuilt versions through - Start using automatic code testing and deployment of prebuilt versions through
@ -517,7 +424,6 @@ contribute to the code.
- Add `Raster#loaded` to reflect the loading state of its image. - Add `Raster#loaded` to reflect the loading state of its image.
### Fixed ### Fixed
- Fix calculations of `Item#strokeBounds` for all possible combinations of - Fix calculations of `Item#strokeBounds` for all possible combinations of
`Item#strokeScaling` and `Item#applyMatrix` for `Path`, `Shape` and `Item#strokeScaling` and `Item#applyMatrix` for `Path`, `Shape` and
`SymbolItem`, along with correct handling of such strokes in Item#hitTest() `SymbolItem`, along with correct handling of such strokes in Item#hitTest()
@ -596,11 +502,10 @@ contribute to the code.
`Numerical.solveCubic()` for edge-cases (#1085). `Numerical.solveCubic()` for edge-cases (#1085).
### Removed ### Removed
- Canvas attributes "resize" and "data-paper-resize" no longer cause paper to - Canvas attributes "resize" and "data-paper-resize" no longer cause paper to
resize the canvas when the viewport size changes; Additional CSS styles are resize the canvas when the viewport size changes; Additional CSS styles are
required since `0.9.22`, e.g.: required since `0.9.22`, e.g.:
```css ```css
/* Scale canvas with resize attribute to full size */ /* Scale canvas with resize attribute to full size */
canvas[resize] { canvas[resize] {
@ -615,7 +520,6 @@ contribute to the code.
It is replaced by `Project#addLayer()` and `Project#insertLayer()`. It is replaced by `Project#addLayer()` and `Project#insertLayer()`.
### Deprecated ### Deprecated
- `#windingRule` on `Item` and `Style``#fillRule` - `#windingRule` on `Item` and `Style``#fillRule`
- `Curve#getNormalAt(time, true)``#getNormalAtTime(true)` - `Curve#getNormalAt(time, true)``#getNormalAtTime(true)`
- `Curve#divide()``#divideAt(offset)` / `#divideAtTime(time)` - `Curve#divide()``#divideAt(offset)` / `#divideAtTime(time)`
@ -623,7 +527,7 @@ contribute to the code.
- `Curve#getParameterAt(offset)``#getTimeAt(offset)` - `Curve#getParameterAt(offset)``#getTimeAt(offset)`
- `Curve#getParameterOf(point)``getTimeOf(point)` - `Curve#getParameterOf(point)``getTimeOf(point)`
- `Curve#getPointAt(time, true)``#getPointAtTime(time)` - `Curve#getPointAt(time, true)``#getPointAtTime(time)`
- `Curve#getTangentAt(time, true)``#getTangentAtTime(time)` - `Curve#getTangentAt(time, true)``#getTangenttTime(time)`
- `Curve#getNormalAt(time, true)``#getNormalAtTime(time)` - `Curve#getNormalAt(time, true)``#getNormalAtTime(time)`
- `Curve#getCurvatureAt(time, true)``#getCurvatureAtTime(time)` - `Curve#getCurvatureAt(time, true)``#getCurvatureAtTime(time)`
- `CurveLocation#parameter``#time` - `CurveLocation#parameter``#time`

View file

@ -1,5 +1,5 @@
Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
http://scratchdisk.com/ & https://puckey.studio/ http://scratchdisk.com/ & http://jonathanpuckey.com/
All rights reserved. All rights reserved.
The MIT License (MIT) The MIT License (MIT)

View file

@ -4,7 +4,6 @@ If you want to work with Paper.js, simply download the latest "stable" version
from [http://paperjs.org/download/](http://paperjs.org/download/) from [http://paperjs.org/download/](http://paperjs.org/download/)
- Website: <http://paperjs.org/> - Website: <http://paperjs.org/>
- Questions: <https://stackoverflow.com/questions/tagged/paperjs>
- Discussion forum: <https://groups.google.com/group/paperjs> - Discussion forum: <https://groups.google.com/group/paperjs>
- Mainline source code: <https://github.com/paperjs/paper.js> - Mainline source code: <https://github.com/paperjs/paper.js>
- Twitter: [@paperjs](https://twitter.com/paperjs) - Twitter: [@paperjs](https://twitter.com/paperjs)

View file

@ -24,7 +24,7 @@ raster.onLoad = function() {
var fs = require('fs'); var fs = require('fs');
var svg = new paper.XMLSerializer().serializeToString(project.exportSVG()); var svg = new paper.XMLSerializer().serializeToString(project.exportSVG());
fs.writeFile(path.resolve('./out.svg'), svg, function (err) { fs.writeFile(path.resolve('./out.svg'),svg, function (err) {
if (err) throw err; if (err) throw err;
console.log('Saved!'); console.log('Saved!');
}); });

View file

@ -45,7 +45,7 @@ with (paper) {
var svg = project.exportSVG({ asString: true }); var svg = project.exportSVG({ asString: true });
console.log(svg); console.log(svg);
fs.writeFile(path.resolve('./out.svg'), svg, function (err) { fs.writeFile(path.resolve('./out.svg'),svg, function (err) {
if (err) throw err; if (err) throw err;
console.log('Saved!'); console.log('Saved!');
}); });

@ -1 +1 @@
Subproject commit 6c10a800e2acafdb50b8493c6a67e5cbeec91f10 Subproject commit 2533ac8e1863262f3c28cd29bc940c6d2ecdf147

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -22,7 +22,6 @@ gulp.task('zip', ['clean:zip', 'dist'], function() {
gulp.src([ gulp.src([
'dist/paper-full*.js', 'dist/paper-full*.js',
'dist/paper-core*.js', 'dist/paper-core*.js',
'dist/paper.d.ts',
'dist/node/**/*', 'dist/node/**/*',
'LICENSE.txt', 'LICENSE.txt',
'examples/**/*', 'examples/**/*',

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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,15 +14,14 @@ var gulp = require('gulp'),
del = require('del'), del = require('del'),
rename = require('gulp-rename'), rename = require('gulp-rename'),
shell = require('gulp-shell'), shell = require('gulp-shell'),
options = require('../utils/options.js'), options = require('../utils/options.js');
run = require('run-sequence');
var docOptions = { var docOptions = {
local: 'docs', // Generates the offline docs local: 'docs', // Generates the offline docs
server: 'serverdocs' // Generates the website templates for the online docs server: 'serverdocs' // Generates the website templates for the online docs
}; };
gulp.task('docs', ['docs:local', 'docs:typescript', 'build:full'], function() { gulp.task('docs', ['docs:local', 'build:full'], function() {
return gulp.src('dist/paper-full.js') return gulp.src('dist/paper-full.js')
.pipe(rename({ basename: 'paper' })) .pipe(rename({ basename: 'paper' }))
.pipe(gulp.dest('dist/docs/assets/js/')); .pipe(gulp.dest('dist/docs/assets/js/'));
@ -33,58 +32,15 @@ Object.keys(docOptions).forEach(function(name) {
var mode = docOptions[name]; var mode = docOptions[name];
return gulp.src('src') return gulp.src('src')
.pipe(shell( .pipe(shell(
[ ['java -cp jsrun.jar:lib/* JsRun app/run.js',
'java -cp jsrun.jar:lib/* JsRun app/run.js', ' -c=conf/', name, '.conf ',
' -c=conf/', name, '.conf ', ' -D="renderMode:', mode, '" ',
' -D="renderMode:', mode, '" ', ' -D="version:', options.version, '"'].join(''),
' -D="version:', options.version, '"'
].join(''),
{ cwd: 'gulp/jsdoc' }) { cwd: 'gulp/jsdoc' })
); )
}); });
gulp.task('clean:docs:' + name, function() { gulp.task('clean:docs:' + name, function() {
return del(['dist/' + docOptions[name] + '/**']); return del([ 'dist/' + docOptions[name] + '/**' ]);
}); });
}); });
// The goal of the typescript task is to automatically generate a type
// definition for the library.
gulp.task('docs:typescript', function(callback) {
run(
'docs:typescript:clean:before',
'docs:typescript:build',
'docs:typescript:clean:after',
callback
);
});
// First clean eventually existing type definition...
gulp.task('docs:typescript:clean:before', function() {
return del('dist/paper.d.ts');
});
// ...then build the definition...
gulp.task('docs:typescript:build', function() {
// First parse JSDoc comments and store parsed data in a temporary file...
return gulp.src('src')
.pipe(shell(
[
'java -cp jsrun.jar:lib/* JsRun app/run.js',
' -c=conf/typescript.conf ',
' -D="file:../../gulp/typescript/typescript-definition-data.json"',
' -D="version:', options.version, '"',
' -D="date:', options.date, '"'
].join(''),
{ cwd: 'gulp/jsdoc' })
)
// ...then generate definition from parsed data...
.pipe(shell('node gulp/typescript/typescript-definition-generator.js'))
// ...finally test the definition by compiling a typescript file.
.pipe(shell('node node_modules/typescript/bin/tsc --project gulp/typescript'));
});
// ...finally remove all unneeded temporary files that were used for building.
gulp.task('docs:typescript:clean:after', function() {
return del([
'gulp/typescript/typescript-definition-data.json',
'gulp/typescript/typescript-definition-test.js'
]);
});

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -32,21 +32,20 @@ var packages = ['paper-jsdom', 'paper-jsdom-canvas'],
end_with_newline: true end_with_newline: true
}; };
gulp.task('publish', function(callback) { gulp.task('publish', function() {
if (options.branch !== 'develop') { if (options.branch !== 'develop') {
throw new Error('Publishing is only allowed on the develop branch.'); throw new Error('Publishing is only allowed on the develop branch.');
} }
// publish:website comes before publish:release, so paperjs.zip file is gone // publish:website comes before publish:release, so paperjs.zip file is gone
// before npm publish: // before npm publish:
run( return run(
'publish:json', 'publish:json',
'publish:dist', 'publish:dist',
'publish:packages', 'publish:packages',
'publish:commit', 'publish:commit',
'publish:website', 'publish:website',
'publish:release', 'publish:release',
'publish:load', 'publish:load'
callback
); );
}); });
@ -109,12 +108,11 @@ packages.forEach(function(name) {
}); });
}); });
gulp.task('publish:website', function(callback) { gulp.task('publish:website', function() {
if (fs.lstatSync(sitePath).isDirectory()) { if (fs.lstatSync(sitePath).isDirectory()) {
run( return run(
'publish:website:build', 'publish:website:build',
'publish:website:push', 'publish:website:push'
callback
); );
} }
}); });

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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,9 +0,0 @@
{
"compilerOptions": {
"target": "ES5",
"strictNullChecks": true
},
"files" : [
"typescript-definition-test.ts"
]
}

View file

@ -1,339 +0,0 @@
/**
* This script generates a type definition by taking JSDoc roughly parsed data,
* formatting it and passing it to a mustache template.
*/
const fs = require('fs');
const mustache = require('mustache');
// Retrieve JSDoc data.
const data = JSON.parse(fs.readFileSync(__dirname + '/typescript-definition-data.json', 'utf8'));
const classes = data.classes;
// Format classes.
classes.forEach(cls => {
// Format class.
// Store name as `className` and not simply `name`, to avoid name conflict
// in static constructors block.
cls.className = cls._name;
// Store closest parent if there is one.
cls.extends = cls.inheritsFrom && cls.inheritsFrom.length > 0
? cls.inheritsFrom[0]
: null;
// Store comment using class tag as description.
cls.comment = formatComment(cls.comment, 'class');
// Build a filter for deprecated or inherited methods or properties.
const filter = it => !it.deprecated && it.memberOf == cls.alias && !it.isNamespace;
// Format properties.
cls.properties = cls.properties
.filter(filter)
.map(it => ({
name: it._name,
type: formatType(it.type, { isProperty: true, isSettableProperty: !it.readOnly }),
static: formatStatic(it.isStatic),
readOnly: formatReadOnly(it.readOnly),
comment: formatComment(it.comment)
}));
// Format methods.
const methods = cls.methods
.filter(filter)
.map(it => {
const name = formatMethodName(it._name);
const isStaticConstructor = it.isStatic && it.isConstructor;
return {
name: name,
// Constructors don't need return type.
type: !it.isConstructor
? formatType(getMethodReturnType(it), { isMethodReturnType: true })
: '',
static: formatStatic(it.isStatic),
// This flag is only used below to filter methods.
isStaticConstructor: isStaticConstructor,
comment: formatComment(it.comment, 'desc', it.isConstructor),
params: it._params
? it._params
// Filter internal parameters (starting with underscore).
.filter(it => !/^_/.test(it.name))
.map(it => formatParameter(it, isStaticConstructor && cls))
.join(', ')
: ''
};
})
.sort(sortMethods);
// Divide methods in 2 parts: static constructors and other. Because static
// constructors need a special syntax in type definition.
cls.methods = [];
cls.staticConstructors = [];
methods.forEach(method => {
if (method.isStaticConstructor) {
// Group static constructors by method name.
let staticConstructors = cls.staticConstructors.find(it => it.name === method.name);
if (!staticConstructors) {
staticConstructors = {
name: method.name,
constructors: []
};
cls.staticConstructors.push(staticConstructors);
}
staticConstructors.constructors.push(method);
} else {
cls.methods.push(method);
}
});
// Store a conveniance flag to check whether class has static constructors.
cls.hasStaticConstructors = cls.staticConstructors.length > 0;
});
// PaperScope class needs to be handled slightly differently because it "owns"
// all the other classes as properties. Eg. we can do `new paperScope.Path()`.
// So we add a `classesPointers` property that the template will use.
const paperScopeClass = classes.find(_ => _.className === 'PaperScope');
paperScopeClass.classesPointers = classes.filter(_ => _.className !== 'PaperScope').map(_ => ({ name: _.className }));
// Since paper.js module is at the same time a PaperScope instance, we need to
// duplicate PaperScope instance properties and methods in the module scope.
// For that, we expose a special variable to the template.
const paperInstance = { ...paperScopeClass };
// We filter static properties and methods for module scope.
paperInstance.properties = paperInstance.properties.filter(_ => !_.static);
paperInstance.methods = paperInstance.methods.filter(_ => !_.static && _.name !== 'constructor');
// Format data trough a mustache template.
// Prepare data for the template.
const context = {
paperInstance: paperInstance,
classes: classes,
version: data.version,
date: data.date,
// {{#doc}} blocks are used in template to automatically generate a JSDoc
// comment with a custom indent.
doc: () => formatJSDoc
};
// Retrieve template content.
const template = fs.readFileSync(__dirname + '/typescript-definition-template.mustache', 'utf8');
// Render template.
const output = mustache.render(template, context);
// Write output in a file.
fs.writeFileSync(__dirname + '/../../dist/paper.d.ts', output, 'utf8');
//
// METHODS
//
function formatReadOnly(isReadOnly) {
return isReadOnly ? 'readonly ' : null;
}
function formatStatic(isStatic) {
return isStatic ? 'static ' : null;
}
function formatType(type, options) {
return ': ' + parseType(type, options);
}
function parseType(type, options) {
// Always return a type even if input type is empty. In that case, return
// `void` for method return type and `any` for the rest.
if (!type) {
return options.isMethodReturnType ? 'void' : 'any';
}
// Prefer `any[]` over `Array<any>` to be more consistent with other types.
if (type === 'Array') {
return 'any[]';
}
// Handle any type: `*` => `any`
type = type.replace('*', 'any');
// Check if type is a "rest" type (meaning that an infinite number of
// parameter of this type can be passed). In that case, we need to remove
// `...` prefix and add `[]` as a suffix:
// - `...Type` => `Type[]`
// - `...(TypeA|TypeB)` => `(TypeA|TypeB)[]`
const isRestType = type.startsWith('...');
if (isRestType) {
type = type.replace(/^\.\.\./, '');
}
// Handle multiple types possibility by splitting on `|` then re-joining
// back parsed types.
type = type.split('|').map(splittedType => {
// Get type without array suffix `[]` for easier matching.
const singleType = splittedType.replace(/(\[\])+$/, '');
// Handle eventual type conflict in static constructors block. For
// example, in `Path.Rectangle(rectangle: Rectangle)` method,
// `rectangle` parameter type must be mapped to `paper.Rectangle` as it
// is declared inside a `Path` namespace and would otherwise be wrongly
// assumed as being the type of `Path.Rectangle` class.
if (options.staticConstructorClass && options.staticConstructorClass.methods.find(it => it.isStatic && it.isConstructor && formatMethodName(it._name) === singleType)
) {
return 'paper.' + splittedType;
}
// Convert primitive types to their lowercase equivalent to suit
// typescript best practices.
if (['Number', 'String', 'Boolean', 'Object'].indexOf(singleType) >= 0) {
splittedType = splittedType.toLowerCase();
}
// Properties `object` type need to be turned into `any` to avoid
// errors when reading object properties. Eg. if `property` is of type
// `object`, `property.key` access is forbidden.
if (options.isProperty && splittedType === 'object') {
return 'any';
}
return splittedType;
}).join(' | ');
if (isRestType) {
type += '[]';
}
// We declare settable properties as nullable to be compatible with
// TypeScript `strictNullChecks` option (#1664).
if (options.isSettableProperty && type !== 'any') {
type += ' | null';
}
return type;
}
function formatMethodName(methodName) {
// Overloaded methods were parsed as `method^0`, `method^1`... here, we
// turn them back to `method` as typescript allow overloading.
methodName = methodName.replace(/\^[0-9]+$/, '');
// Real contructors are called `initialize` in the library.
methodName = methodName.replace(/^initialize$/, 'constructor');
return methodName;
}
function formatParameter(param, staticConstructorClass) {
let content = '';
// Handle rest parameter pattern `...Type`. Parameter name needs to be
// prefixed with `...` as in ES6. E.g. `...parameter: type[]`.
if (param.type.match(/^\.\.\.(.+)$/)) {
content += '...';
}
content += formatParameterName(param.name);
// Optional parameters are formatted as: `parameter?: type`.
if (param.isOptional) {
content += '?';
}
content += formatType(param.type, { staticConstructorClass });
return content;
}
function formatParameterName(parameterName) {
// Avoid usage of reserved keyword as parameter name.
// E.g. `function` => `callback`.
if (parameterName === 'function') {
return 'callback';
}
return parameterName;
}
function formatComment(comment, descriptionTagName = 'desc', skipReturn = false) {
const tags = comment.tags;
let content = '';
// Retrieve description tag.
const descriptionTag = tags.find(it => it.title === descriptionTagName);
if (descriptionTag) {
// Don't display group titles.
content += descriptionTag.desc.replace(/\{@grouptitle .+?\}/g, '').trim();
}
// Preserve some of the JSDoc tags that can be usefull even in type
// definition. Format their values to make sure that only informations
// that make sense are kept. E.g. method parameters types are already
// provided in the signature...
content += formatCommentTags(tags, 'see');
content += formatCommentTags(tags, 'option');
content += formatCommentTags(tags, 'param', it => it.name + ' - ' + it.desc);
if (!skipReturn) {
content += formatCommentTags(tags, 'return', it => it.desc.trim().replace(/^\{|\}$/g, '').replace(/@([a-zA-Z]+)/, '$1'));
}
// Make sure links are followable (e.g. by IDEs) by removing parameters.
// {@link Class#method(param)} => {@link Class#method}
content = content.replace(/(\{@link [^\}]+?)\(.*?\)(\})/g, '$1$2');
content = content.trim();
return content;
}
function formatCommentTags(tags, tagName, formatter) {
let content = '';
// Default formatter simply outputs description.
formatter = formatter || (it => it.desc);
// Only keep tags that have a description.
tags = tags.filter(it => it.desc && it.title === tagName);
if (tags.length > 0) {
content += '\n';
// Display tag as it was in original JSDoc, followed by formatted value.
tags.forEach(it => content += '\n@' + tagName + ' ' + formatter(it));
}
return content;
}
/**
* This outputs a JSDoc comment indented at the given offset and including the
* parsed comment for current mustache block.
* @param {Number} offset the number of spaces to use for indentation
* @param {Function} render the mustache render method
* @return {string} the formatted JSDoc comment
*/
function formatJSDoc(offset, render) {
// First render current block comment. Use `{{&}}` syntax to make sure
// special characters are not escaped.
let content = render('{{&comment}}');
if (!content) {
return '';
}
// Build indentation.
offset = parseInt(offset);
if (offset > 0) {
offset++;
}
const indentation = new Array(offset).join(' ');
// Prefix each line with the indentation.
content = content.split('\n')
.map(_ => indentation + ' * ' + _)
.join('\n');
// Wrap content in JSDoc delimiters: `/**` and `*/`.
return '/** \n' + content + '\n' + indentation + ' */';
}
function getMethodReturnType(method) {
return method.returnType || method.returns.length > 0 && method.returns[0].type;
}
function sortMethods(methodA, methodB) {
// This places constructors before other methods as it is a best practice.
// This also place constructors with only one object parameter after other
// constructors to avoid type inference errors due to constructors
// overloading order. E.g. if `constructor(object: object)` is defined
// before `constructor(instance: Class)`, calling `constructor(instance)`
// will always be mapped to `contructor(object: object)`, since everything
// is an object in JavaScript. This is problematic because most of Paper.js
// classes have a constructor accepting an object.
const aIsContructor = methodA.name === 'constructor';
const bIsContructor = methodB.name === 'constructor';
if (aIsContructor && bIsContructor) {
if (methodA.params === 'object: object') {
return 1;
}
if (methodB.params === 'object: object') {
return -1;
}
} else if (aIsContructor) {
return -1;
} else if (bIsContructor) {
return 1;
}
return 0;
}

View file

@ -1,70 +0,0 @@
/*!
* Paper.js v{{version}} - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
* Date: {{date}}
*
* This is an auto-generated type definition.
*/
declare module paper {
{{#paperInstance}}
{{#properties}}
{{#doc}}4{{/doc}}
let {{name}}{{type}}
{{/properties}}
{{#methods}}
{{#doc}}4{{/doc}}
function {{name}}({{params}}){{type}}
{{/methods}}
{{/paperInstance}}
{{#classes}}
{{#doc}}4{{/doc}}
class {{className}} {{#extends}}extends {{extends}}{{/extends}} {
{{#properties}}
{{#doc}}8{{/doc}}
{{static}}{{readOnly}}{{name}}{{type}}
{{/properties}}
{{#classesPointers}}
{{name}}: typeof {{name}}
{{/classesPointers}}
{{#methods}}
{{#doc}}8{{/doc}}
{{static}}{{name}}({{params}}){{type}}
{{/methods}}
}
{{#hasStaticConstructors}}
namespace {{className}} {
{{#staticConstructors}}
class {{name}} extends {{className}} {
{{#constructors}}
{{#doc}}12{{/doc}}
constructor({{params}})
{{/constructors}}
}
{{/staticConstructors}}
}
{{/hasStaticConstructors}}
{{/classes}}
}
declare module 'paper' {
export = paper
}

File diff suppressed because it is too large Load diff

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -24,10 +24,9 @@ options.date = git('log -1 --pretty=format:%ad');
options.branch = git('rev-parse --abbrev-ref HEAD'); options.branch = git('rev-parse --abbrev-ref HEAD');
// If a specific branch is requested, quit without errors if we don't match. // If a specific branch is requested, quit without errors if we don't match.
var ensureBranch = argv['ensure-branch']; if (argv.branch && argv.branch !== options.branch) {
if (ensureBranch && ensureBranch !== options.branch) { console.log('Branch "' + options.branch + '" does not match "' +
console.log('Branch "' + options.branch + '" does not match requested "' + argv.branch + '". There is nothing to do here.');
ensureBranch + '". There is nothing to do here.');
process.exit(0); process.exit(0);
} }

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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,6 +1,6 @@
{ {
"name": "@scratch/paper", "name": "@scratch/paper",
"version": "0.12.3", "version": "0.11.8",
"description": "The Swiss Army Knife of Vector Graphics Scripting", "description": "The Swiss Army Knife of Vector Graphics Scripting",
"license": "MIT", "license": "MIT",
"homepage": "http://paperjs.org", "homepage": "http://paperjs.org",
@ -9,13 +9,11 @@
"url": "https://github.com/paperjs/paper.js" "url": "https://github.com/paperjs/paper.js"
}, },
"bugs": "https://github.com/paperjs/paper.js/issues", "bugs": "https://github.com/paperjs/paper.js/issues",
"contributors": [ "contributors": ["Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)", "Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"],
"Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)",
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
],
"main": "dist/paper-full.js", "main": "dist/paper-full.js",
"types": "dist/paper.d.ts",
"scripts": { "scripts": {
"precommit": "gulp jshint --branch develop",
"prepush": "gulp test --branch develop",
"build": "gulp build", "build": "gulp build",
"dist": "gulp dist", "dist": "gulp dist",
"zip": "gulp zip", "zip": "gulp zip",
@ -24,22 +22,44 @@
"jshint": "gulp jshint", "jshint": "gulp jshint",
"test": "gulp test" "test": "gulp test"
}, },
"files": [ "files": ["AUTHORS.md", "CHANGELOG.md", "dist/", "examples/", "LICENSE.txt", "README.md"],
"AUTHORS.md",
"CHANGELOG.md",
"dist/",
"examples/",
"LICENSE.txt",
"README.md"
],
"engines": { "engines": {
"node": ">=8.0.0" "node": ">=4.0.0"
}, },
"husky": { "devDependencies": {
"hooks": { "acorn": "~0.5.0",
"pre-commit": "gulp jshint --ensure-branch develop", "canvas-prebuilt": "^2.0.0-alpha.14",
"pre-push": "gulp test --ensure-branch develop" "del": "^2.2.1",
} "gulp": "^3.9.1",
"gulp-cached": "^1.1.0",
"gulp-git-streamed": "^2.8.1",
"gulp-jshint": "^2.0.0",
"gulp-json-editor": "^2.2.1",
"gulp-prepro": "^2.4.0",
"gulp-qunits": "^2.1.1",
"gulp-rename": "^1.2.2",
"gulp-shell": "^0.5.2",
"gulp-symlink": "^2.1.4",
"gulp-uglify": "^1.5.4",
"gulp-uncomment": "^0.3.0",
"gulp-util": "^3.0.7",
"gulp-webserver": "^0.9.1",
"gulp-whitespace": "^0.1.0",
"gulp-zip": "^3.2.0",
"husky": "^0.11.4",
"jsdom": "^9.4.0",
"jshint": "^2.9.2",
"jshint-summary": "^0.4.0",
"merge-stream": "^1.0.0",
"minimist": "^1.2.0",
"prepro": "^2.4.0",
"qunitjs": "^1.23.0",
"require-dir": "^0.3.0",
"resemblejs": "^2.2.1",
"run-sequence": "^1.2.2",
"source-map-support": "^0.4.0",
"stats.js": "0.16.0",
"straps": "^3.0.1"
}, },
"browser": { "browser": {
"canvas": false, "canvas": false,
@ -49,58 +69,5 @@
"./dist/node/self.js": false, "./dist/node/self.js": false,
"./dist/node/extend.js": false "./dist/node/extend.js": false
}, },
"devDependencies": { "keywords": ["vector", "graphic", "graphics", "2d", "geometry", "bezier", "curve", "curves", "path", "paths", "canvas", "svg", "paper", "paper.js", "paperjs"]
"acorn": "~0.5.0",
"canvas": "^2.6.0",
"del": "^4.1.0",
"gulp": "^3.9.1",
"gulp-cached": "^1.1.0",
"gulp-git-streamed": "^2.8.1",
"gulp-jshint": "^2.1.0",
"gulp-json-editor": "^2.5.2",
"gulp-prepro": "^2.4.0",
"gulp-qunits": "^2.1.2",
"gulp-rename": "^1.4.0",
"gulp-shell": "^0.7.0",
"gulp-symlink": "^2.1.4",
"gulp-uglify": "^1.5.4",
"gulp-uncomment": "^0.3.0",
"gulp-util": "^3.0.7",
"gulp-webserver": "^0.9.1",
"gulp-whitespace": "^0.1.0",
"gulp-zip": "^3.2.0",
"husky": "^2.3.0",
"jsdom": "^15.1.1",
"jshint": "^2.10.2",
"jshint-summary": "^0.4.0",
"merge-stream": "^2.0.0",
"minimist": "^1.2.0",
"mustache": "^3.0.1",
"prepro": "^2.4.0",
"qunitjs": "^1.23.0",
"require-dir": "^1.2.0",
"resemblejs": "^3.2.3",
"run-sequence": "^2.2.1",
"source-map-support": "^0.5.12",
"stats.js": "0.17.0",
"straps": "^3.0.1",
"typescript": "^3.1.6"
},
"keywords": [
"vector",
"graphic",
"graphics",
"2d",
"geometry",
"bezier",
"curve",
"curves",
"path",
"paths",
"canvas",
"svg",
"paper",
"paper.js",
"paperjs"
]
} }

@ -1 +1 @@
Subproject commit 0fb6283f0955b8ee92fc9ac8838f167ea4a965d2 Subproject commit f601084fc319734d0bf47da700d6b6bff95260ba

@ -1 +1 @@
Subproject commit 1e276564106e5a29a6e00115c7e703cfc1fc2b09 Subproject commit a07b7d149f02e980dfd837cd595f5000a9d5e052

View file

@ -1,398 +0,0 @@
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name Tween
*
* @class Allows tweening `Object` properties between two states for a given
* duration. To tween properties on Paper.js {@link Item} instances,
* {@link Item#tween(from, to, options)} can be used, which returns created
* tween instance.
*
* @see Item#tween(from, to, options)
* @see Item#tween(to, options)
* @see Item#tween(options)
* @see Item#tweenTo(to, options)
* @see Item#tweenFrom(from, options)
*/
var Tween = Base.extend(Emitter, /** @lends Tween# */{
_class: 'Tween',
statics: {
easings: {
// no easing, no acceleration
linear: function(t) {
return t;
},
// accelerating from zero velocity
easeInQuad: function(t) {
return t * t;
},
// decelerating to zero velocity
easeOutQuad: function(t) {
return t * (2 - t);
},
// acceleration until halfway, then deceleration
easeInOutQuad: function(t) {
return t < 0.5
? 2 * t * t
: -1 + 2 * (2 - t) * t;
},
// accelerating from zero velocity
easeInCubic: function(t) {
return t * t * t;
},
// decelerating to zero velocity
easeOutCubic: function(t) {
return --t * t * t + 1;
},
// acceleration until halfway, then deceleration
easeInOutCubic: function(t) {
return t < 0.5
? 4 * t * t * t
: (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
},
// accelerating from zero velocity
easeInQuart: function(t) {
return t * t * t * t;
},
// decelerating to zero velocity
easeOutQuart: function(t) {
return 1 - (--t) * t * t * t;
},
// acceleration until halfway, then deceleration
easeInOutQuart: function(t) {
return t < 0.5
? 8 * t * t * t * t
: 1 - 8 * (--t) * t * t * t;
},
// accelerating from zero velocity
easeInQuint: function(t) {
return t * t * t * t * t;
},
// decelerating to zero velocity
easeOutQuint: function(t) {
return 1 + --t * t * t * t * t;
},
// acceleration until halfway, then deceleration
easeInOutQuint: function(t) {
return t < 0.5
? 16 * t * t * t * t * t
: 1 + 16 * (--t) * t * t * t * t;
}
}
},
/**
* Creates a new tween.
*
* @param {Object} object the object to tween the properties on
* @param {Object} from the state at the start of the tweening
* @param {Object} to the state at the end of the tweening
* @param {Number} duration the duration of the tweening
* @param {String|Function} [easing='linear'] the type of the easing
* function or the easing function
* @param {Boolean} [start=true] whether to start tweening automatically
* @return {Tween} the newly created tween
*/
initialize: function Tween(object, from, to, duration, easing, start) {
this.object = object;
var type = typeof easing;
var isFunction = type === 'function';
this.type = isFunction
? type
: type === 'string'
? easing
: 'linear';
this.easing = isFunction ? easing : Tween.easings[this.type];
this.duration = duration;
this.running = false;
this._then = null;
this._startTime = null;
var state = from || to;
this._keys = state ? Object.keys(state) : [];
this._parsedKeys = this._parseKeys(this._keys);
this._from = state && this._getState(from);
this._to = state && this._getState(to);
if (start !== false) {
this.start();
}
},
/**
* Set a function that will be executed when the tween completes.
* @param {Function} function the function to execute when the tween
* completes
* @return {Tween}
*
* @example {@paperscript}
* // Tweens chaining:
* var circle = new Path.Circle({
* center: view.center,
* radius: 40,
* fillColor: 'blue'
* });
* // Tween color from blue to red.
* var tween = circle.tweenTo({ fillColor: 'red' }, 2000);
* // When the first tween completes...
* tween.then(function() {
* // ...tween color back to blue.
* circle.tweenTo({ fillColor: 'blue' }, 2000);
* });
*/
then: function(then) {
this._then = then;
return this;
},
/**
* Start tweening.
* @return {Tween}
*
* @example {@paperscript}
* // Manually start tweening.
* var circle = new Path.Circle({
* center: view.center,
* radius: 40,
* fillColor: 'blue'
* });
* var tween = circle.tweenTo(
* { fillColor: 'red' },
* { duration: 2000, start: false }
* );
* tween.start();
*/
start: function() {
this._startTime = null;
this.running = true;
return this;
},
/**
* Stop tweening.
* @return {Tween}
*
* @example {@paperscript}
* // Stop a tween before it completes.
* var circle = new Path.Circle({
* center: view.center,
* radius: 40,
* fillColor: 'blue'
* });
* // Start tweening from blue to red for 2 seconds.
* var tween = circle.tweenTo({ fillColor: 'red' }, 2000);
* // After 1 second...
* setTimeout(function(){
* // ...stop tweening.
* tween.stop();
* }, 1000);
*/
stop: function() {
this.running = false;
return this;
},
// DOCS: Document Tween#update(progress)
update: function(progress) {
if (this.running) {
if (progress > 1) {
// always finish the animation
progress = 1;
this.running = false;
}
var factor = this.easing(progress),
keys = this._keys,
getValue = function(value) {
return typeof value === 'function'
? value(factor, progress)
: value;
};
for (var i = 0, l = keys && keys.length; i < l; i++) {
var key = keys[i],
from = getValue(this._from[key]),
to = getValue(this._to[key]),
// Some paper objects have math functions (e.g.: Point,
// Color) which can directly be used to do the tweening.
value = (from && to && from.__add && to.__add)
? to.__subtract(from).__multiply(factor).__add(from)
: ((to - from) * factor) + from;
this._setProperty(this._parsedKeys[key], value);
}
if (!this.running && this._then) {
// TODO Look into what should be returned.
this._then(this.object);
}
if (this.responds('update')) {
this.emit('update', new Base({
progress: progress,
factor: factor
}));
}
}
return this;
},
/**
* {@grouptitle Event Handlers}
*
* The function to be called when the tween is updated. It receives an
* object as its sole argument, containing the current progress of the
* tweening and the factor calculated by the easing function.
*
* @name Tween#onUpdate
* @property
* @type Function
*
* @example {@paperscript}
* // Display tween progression values:
* var circle = new Path.Circle({
* center: view.center,
* radius: 40,
* fillColor: 'blue'
* });
* var tween = circle.tweenTo(
* { fillColor: 'red' },
* {
* duration: 2000,
* easing: 'easeInCubic'
* }
* );
* var progressText = new PointText(view.center + [60, -10]);
* var factorText = new PointText(view.center + [60, 10]);
*
* // Install event using onUpdate() property:
* tween.onUpdate = function(event) {
* progressText.content = 'progress: ' + event.progress.toFixed(2);
* };
*
* // Install event using on('update') method:
* tween.on('update', function(event) {
* factorText.content = 'factor: ' + event.factor.toFixed(2);
* });
*/
_events: {
onUpdate: {}
},
_handleFrame: function(time) {
var startTime = this._startTime,
progress = startTime
? (time - startTime) / this.duration
: 0;
if (!startTime) {
this._startTime = time;
}
this.update(progress);
},
_getState: function(state) {
var keys = this._keys,
result = {};
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i],
path = this._parsedKeys[key],
current = this._getProperty(path),
value;
if (state) {
var resolved = this._resolveValue(current, state[key]);
// Temporarily set the resolved value, so we can retrieve the
// coerced value from paper's internal magic.
this._setProperty(path, resolved);
value = this._getProperty(path);
// Clone the value if possible to prevent future changes.
value = value && value.clone ? value.clone() : value;
this._setProperty(path, current);
} else {
// We want to get the current state at the time of the call, so
// we have to clone if possible to prevent future changes.
value = current && current.clone ? current.clone() : current;
}
result[key] = value;
}
return result;
},
_resolveValue: function(current, value) {
if (value) {
if (Array.isArray(value) && value.length === 2) {
var operator = value[0];
return (
operator &&
operator.match &&
// We're (unnecessarily) escaping '*/' here to not confuse
// the ol' JSDoc parser...
operator.match(/^[+\-\*\/]=/)
)
? this._calculate(current, operator[0], value[1])
: value;
} else if (typeof value === 'string') {
var match = value.match(/^[+\-*/]=(.*)/);
if (match) {
var parsed = JSON.parse(match[1].replace(
/(['"])?([a-zA-Z0-9_]+)(['"])?:/g,
'"$2": '
));
return this._calculate(current, value[0], parsed);
}
}
}
return value;
},
_calculate: function(left, operator, right) {
return paper.PaperScript.calculateBinary(left, operator, right);
},
_parseKeys: function(keys) {
var parsed = {};
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i],
path = key
// Convert from JS property access notation to JSON pointer:
.replace(/\.([^.]*)/g, '/$1')
// Expand array property access notation ([])
.replace(/\[['"]?([^'"\]]*)['"]?\]/g, '/$1');
parsed[key] = path.split('/');
}
return parsed;
},
_getProperty: function(path, offset) {
var obj = this.object;
for (var i = 0, l = path.length - (offset || 0); i < l && obj; i++) {
obj = obj[path[i]];
}
return obj;
},
_setProperty: function(path, value) {
var dest = this._getProperty(path, 1);
if (dest) {
dest[path[path.length - 1]] = value;
}
}
});

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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,8 +12,8 @@
/** /**
* @name Line * @name Line
*
* @class The Line object represents.. * @class The Line object represents..
* @private
*/ */
var Line = Base.extend(/** @lends Line# */{ var Line = Base.extend(/** @lends Line# */{
_class: 'Line', _class: 'Line',

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -104,8 +104,6 @@ var Matrix = Base.extend(/** @lends Matrix# */{
* also work for calls of `set()`. * also work for calls of `set()`.
* *
* @function * @function
* @param {...*} values
* @return {Point}
*/ */
set: '#initialize', set: '#initialize',
@ -185,7 +183,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
* Attempts to apply the matrix to the content of item that it belongs to, * Attempts to apply the matrix to the content of item that it belongs to,
* meaning its transformation is baked into the item's content or children. * meaning its transformation is baked into the item's content or children.
* *
* @param {Boolean} [recursively=true] controls whether to apply transformations * @param {Boolean} recursively controls whether to apply transformations
* recursively on children * recursively on children
* @return {Boolean} {@true if the matrix was applied} * @return {Boolean} {@true if the matrix was applied}
*/ */
@ -451,7 +449,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Returns a new matrix as the result of prepending the specified matrix * Returns a new matrix as the result of prepending the specified matrix
* to this matrix. This is the equivalent of multiplying * to this matrix. This is the equivalent of multiplying
* `(specified matrix) * (this matrix)`. * `(specified matrix) s* (this matrix)`.
* *
* @param {Matrix} matrix the matrix to prepend * @param {Matrix} matrix the matrix to prepend
* @return {Matrix} the newly created matrix * @return {Matrix} the newly created matrix
@ -500,15 +498,15 @@ var Matrix = Base.extend(/** @lends Matrix# */{
}, },
/** /**
* @deprecated use {@link #append(matrix)} instead. * @deprecated use use {@link #append(matrix)} instead.
*/ */
concatenate: '#append', concatenate: '#append',
/** /**
* @deprecated use {@link #prepend(matrix)} instead. * @deprecated use use {@link #prepend(matrix)} instead.
*/ */
preConcatenate: '#prepend', preConcatenate: '#prepend',
/** /**
* @deprecated use {@link #appended(matrix)} instead. * @deprecated use use {@link #appended(matrix)} instead.
*/ */
chain: '#appended', chain: '#appended',
@ -646,7 +644,6 @@ var Matrix = Base.extend(/** @lends Matrix# */{
* Inverse transforms a point and returns the result. * Inverse transforms a point and returns the result.
* *
* @param {Point} point the point to be transformed * @param {Point} point the point to be transformed
* @return {Point}
*/ */
inverseTransform: function(/* point */) { inverseTransform: function(/* point */) {
return this._inverseTransform(Point.read(arguments)); return this._inverseTransform(Point.read(arguments));

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -170,8 +170,6 @@ var Point = Base.extend(/** @lends Point# */{
* for calls of `set()`. * for calls of `set()`.
* *
* @function * @function
* @param {...*} values
* @return {Point}
*/ */
set: '#initialize', set: '#initialize',
@ -770,7 +768,7 @@ var Point = Base.extend(/** @lends Point# */{
* *
* @param {Number} quadrant the quadrant to check against * @param {Number} quadrant the quadrant to check against
* @return {Boolean} {@true if either x or y are not a number} * @return {Boolean} {@true if either x or y are not a number}
* @see #quadrant * @see #getQuadrant()
*/ */
isInQuadrant: function(q) { isInQuadrant: function(q) {
// Map quadrant to x & y coordinate pairs and multiply with coordinates, // Map quadrant to x & y coordinate pairs and multiply with coordinates,

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -73,7 +73,7 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* Creates a new rectangle object from the passed rectangle object. * Creates a new rectangle object from the passed rectangle object.
* *
* @name Rectangle#initialize * @name Rectangle#initialize
* @param {Rectangle} rectangle * @param {Rectangle} rt
*/ */
initialize: function Rectangle(arg0, arg1, arg2, arg3) { initialize: function Rectangle(arg0, arg1, arg2, arg3) {
var type = typeof arg0, var type = typeof arg0,
@ -159,8 +159,6 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* constructors also work for calls of `set()`. * constructors also work for calls of `set()`.
* *
* @function * @function
* @param {...*} values
* @return {Rectangle}
*/ */
set: '#initialize', set: '#initialize',
@ -203,7 +201,6 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
/** /**
* Returns a copy of the rectangle. * Returns a copy of the rectangle.
* @return {Rectangle}
*/ */
clone: function() { clone: function() {
return new Rectangle(this.x, this.y, this.width, this.height); return new Rectangle(this.x, this.y, this.width, this.height);
@ -775,8 +772,6 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* Rectangle#contains(point)} returns `false` for that point. * Rectangle#contains(point)} returns `false` for that point.
* *
* @param {Point} point * @param {Point} point
* @return {Rectangle} the smallest rectangle that contains both the
* original rectangle and the specified point
*/ */
include: function(/* point */) { include: function(/* point */) {
var point = Point.read(arguments); var point = Point.read(arguments);
@ -788,18 +783,17 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
}, },
/** /**
* Returns a new rectangle expanded by the specified amount in horizontal * Expands the rectangle by the specified amount in horizontal and
* and vertical directions. * vertical directions.
* *
* @name Rectangle#expand * @name Rectangle#expand
* @function * @function
* @param {Number|Size|Point} amount the amount to expand the rectangle in * @param {Number|Size|Point} amount the amount to expand the rectangle in
* both directions * both directions
* @return {Rectangle} the expanded rectangle
*/ */
/** /**
* Returns a new rectangle expanded by the specified amounts in horizontal * Expands the rectangle by the specified amounts in horizontal and
* and vertical directions. * vertical directions.
* *
* @name Rectangle#expand * @name Rectangle#expand
* @function * @function
@ -807,7 +801,6 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
* direction * direction
* @param {Number} ver the amount to expand the rectangle in vertical * @param {Number} ver the amount to expand the rectangle in vertical
* direction * direction
* @return {Rectangle} the expanded rectangle
*/ */
expand: function(/* amount */) { expand: function(/* amount */) {
var amount = Size.read(arguments), var amount = Size.read(arguments),
@ -818,23 +811,21 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
}, },
/** /**
* Returns a new rectangle scaled by the specified amount from its center. * Scales the rectangle by the specified amount from its center.
* *
* @name Rectangle#scale * @name Rectangle#scale
* @function * @function
* @param {Number} amount * @param {Number} amount
* @return {Rectangle} the scaled rectangle
*/ */
/** /**
* Returns a new rectangle scaled in horizontal direction by the specified * Scales the rectangle in horizontal direction by the specified `hor`
* `hor` amount and in vertical direction by the specified `ver` amount * amount and in vertical direction by the specified `ver` amount from its
* from its center. * center.
* *
* @name Rectangle#scale * @name Rectangle#scale
* @function * @function
* @param {Number} hor * @param {Number} hor
* @param {Number} ver * @param {Number} ver
* @return {Rectangle} the scaled rectangle
*/ */
scale: function(hor, ver) { scale: function(hor, ver) {
return this.expand(this.width * hor - this.width, return this.expand(this.width * hor - this.width,

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -130,8 +130,6 @@ var Size = Base.extend(/** @lends Size# */{
* for calls of `set()`. * for calls of `set()`.
* *
* @function * @function
* @param {...*} values
* @return {Size}
*/ */
set: '#initialize', set: '#initialize',
@ -160,7 +158,7 @@ var Size = Base.extend(/** @lends Size# */{
* Checks whether the width and height of the size are equal to those of the * Checks whether the width and height of the size are equal to those of the
* supplied size. * supplied size.
* *
* @param {Size} size the size to compare to * @param {Size}
* @return {Boolean} * @return {Boolean}
* *
* @example * @example
@ -178,7 +176,6 @@ var Size = Base.extend(/** @lends Size# */{
/** /**
* Returns a copy of the size. * Returns a copy of the size.
* @return {Size}
*/ */
clone: function() { clone: function() {
return new Size(this.width, this.height); return new Size(this.width, this.height);

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -558,16 +558,8 @@ statics: /** @lends Base */{
if (args.length === 1 && obj instanceof Item if (args.length === 1 && obj instanceof Item
&& (useTarget || !(obj instanceof Layer))) { && (useTarget || !(obj instanceof Layer))) {
var arg = args[0]; var arg = args[0];
if (Base.isPlainObject(arg)) { if (Base.isPlainObject(arg))
arg.insert = false; arg.insert = false;
// When using target, make sure the `item.insert()`
// method is not overridden with the `arg.insert`
// property that was just set. Pass an exclude
// object to the call of `obj.set()` below (#1392).
if (useTarget) {
args = args.concat([{ insert: true }]);
}
}
} }
// When reusing an object, initialize it through #set() // When reusing an object, initialize it through #set()
// instead of the constructor function: // instead of the constructor function:

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -68,9 +68,9 @@ var Emitter = {
}, },
once: function(type, func) { once: function(type, func) {
return this.on(type, function handler() { return this.on(type, function() {
func.apply(this, arguments); func.apply(this, arguments);
this.off(type, handler); this.off(type, func);
}); });
}, },

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -87,7 +87,7 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
// here: { chrome: true, webkit: false }, Mozilla missing is the // here: { chrome: true, webkit: false }, Mozilla missing is the
// only difference to jQuery.browser // only difference to jQuery.browser
user.replace( user.replace(
/(opera|chrome|safari|webkit|firefox|msie|trident|atom|node|jsdom)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g, /(opera|chrome|safari|webkit|firefox|msie|trident|atom|node)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g,
function(match, n, v1, v2, rv) { function(match, n, v1, v2, rv) {
// Do not set additional browsers once chrome is detected. // Do not set additional browsers once chrome is detected.
if (!agent.chrome) { if (!agent.chrome) {
@ -95,7 +95,7 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
/^(node|trident)$/.test(n) ? rv : v1; /^(node|trident)$/.test(n) ? rv : v1;
agent.version = v; agent.version = v;
agent.versionNumber = parseFloat(v); agent.versionNumber = parseFloat(v);
n = { trident: 'msie', jsdom: 'node' }[n] || n; n = n === 'trident' ? 'msie' : n;
agent.name = n; agent.name = n;
agent[n] = true; agent[n] = true;
} }
@ -112,7 +112,6 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
* The version of Paper.js, as a string. * The version of Paper.js, as a string.
* *
* @type String * @type String
* @readonly
*/ */
version: /*#=*/__options.version, version: /*#=*/__options.version,
@ -201,7 +200,7 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
* mapping, in case the code that's passed in has already been mingled. * mapping, in case the code that's passed in has already been mingled.
* *
* @param {String} code the PaperScript code * @param {String} code the PaperScript code
* @param {Object} [options] the compilation options * @param {Object} [option] the compilation options
*/ */
execute: function(code, options) { execute: function(code, options) {
/*#*/ if (__options.paperScript) { /*#*/ if (__options.paperScript) {

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -127,7 +127,7 @@ Base.exports.PaperScript = function() {
* mapping, in case the code that's passed in has already been mingled. * mapping, in case the code that's passed in has already been mingled.
* *
* @param {String} code the PaperScript code * @param {String} code the PaperScript code
* @param {Object} [options] the compilation options * @param {Object} [option] the compilation options
* @return {Object} an object holding the compiled PaperScript translated * @return {Object} an object holding the compiled PaperScript translated
* into JavaScript code along with source-maps and other information. * into JavaScript code along with source-maps and other information.
*/ */
@ -177,7 +177,7 @@ Base.exports.PaperScript = function() {
var start = getOffset(node.range[0]), var start = getOffset(node.range[0]),
end = getOffset(node.range[1]), end = getOffset(node.range[1]),
insert = 0; insert = 0;
// Sort insertions by their offset, so getOffset() 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]) {
insert = i + 1; insert = i + 1;
@ -256,19 +256,12 @@ Base.exports.PaperScript = function() {
exp = '__$__(' + arg + ', "' + node.operator[0] exp = '__$__(' + arg + ', "' + node.operator[0]
+ '", 1)', + '", 1)',
str = arg + ' = ' + exp; str = arg + ' = ' + exp;
if (node.prefix) { // If this is not a prefixed update expression
// A prefixed update expression (++a / --a), // (++a, --a), assign the old value before updating it.
// wrap expression in paranthesis. See #1611 if (!node.prefix
str = '(' + str + ')'; && (parentType === 'AssignmentExpression'
} else if ( || parentType === 'VariableDeclarator')) {
// A suffixed update expression (a++, a--), // Handle special issue #691 where the old value is
// assign the old value before updating it.
// See #691, #1450
parentType === 'AssignmentExpression' ||
parentType === 'VariableDeclarator' ||
parentType === 'BinaryExpression'
) {
// Handle special case where the old value is
// assigned to itself, and the expression is just // assigned to itself, and the expression is just
// executed after, e.g.: `var x = ***; x = x++;` // executed after, e.g.: `var x = ***; x = x++;`
if (getCode(parent.left || parent.id) === arg) if (getCode(parent.left || parent.id) === arg)
@ -330,7 +323,7 @@ Base.exports.PaperScript = function() {
// Source-map support: // Source-map support:
// Encodes a Variable Length Quantity as a Base64 string. // Encodes a Variable Length Quantity as a Base64 string.
// See: https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ // See: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps
function encodeVLQ(value) { function encodeVLQ(value) {
var res = '', var res = '',
base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@ -448,8 +441,8 @@ Base.exports.PaperScript = function() {
* *
* @param {String} code the PaperScript code * @param {String} code the PaperScript code
* @param {PaperScope} scope the scope for which the code is executed * @param {PaperScope} scope the scope for which the code is executed
* @param {Object} [options] the compilation options * @param {Object} [option] the compilation options
* @return {Object} the exports defined in the executed code * @return the exports defined in the executed code
*/ */
function execute(code, scope, options) { function execute(code, scope, options) {
// Set currently active scope. // Set currently active scope.
@ -491,7 +484,7 @@ Base.exports.PaperScript = function() {
} }
} }
} }
expose({ __$__: __$__, $__: $__, paper: scope, tool: tool }, expose({ __$__: __$__, $__: $__, paper: scope, view: view, tool: tool },
true); true);
expose(scope); expose(scope);
// Add a fake `module.exports` object so PaperScripts can export things. // Add a fake `module.exports` object so PaperScripts can export things.
@ -664,9 +657,7 @@ Base.exports.PaperScript = function() {
compile: compile, compile: compile,
execute: execute, execute: execute,
load: load, load: load,
parse: parse, parse: parse
calculateBinary: __$__,
calculateUnary: $__
}; };
// Pass on `this` as the binding object, so we can reference Acorn both in // Pass on `this` as the binding object, so we can reference Acorn both in
// development and in the built library. // development and in the built library.

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -39,7 +39,7 @@
* *
* The project for which the PaperScript is executed. * The project for which the PaperScript is executed.
* *
* Note that when working with multiple projects, this does not necessarily * Note that when working with mulitple projects, this does not necessarily
* reflect the currently active project. For this, use * reflect the currently active project. For this, use
* {@link PaperScope#project} instead. * {@link PaperScope#project} instead.
* *
@ -57,20 +57,19 @@
/** /**
* The reference to the project's view. * The reference to the project's view.
* *
* Note that when working with multiple projects, this does not necessarily * Note that when working with mulitple projects, this does not necessarily
* reflect the view of the currently active project. For this, use * reflect the view of the currently active project. For this, use
* {@link PaperScope#view} instead. * {@link PaperScope#view} instead.
* *
* @name view * @name view
* @type View * @type View
* @readonly
*/ */
/** /**
* The reference to the tool object which is automatically created when global * The reference to the tool object which is automatically created when global
* tool event handlers are defined. * tool event handlers are defined.
* *
* Note that when working with multiple tools, this does not necessarily * Note that when working with mulitple tools, this does not necessarily
* reflect the currently active tool. For this, use {@link PaperScope#tool} * reflect the currently active tool. For this, use {@link PaperScope#tool}
* instead. * instead.
* *

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -171,7 +171,8 @@ var Group = Item.extend(/** @lends Group# */{
_getBounds: function _getBounds(matrix, options) { _getBounds: function _getBounds(matrix, options) {
var clipItem = this._getClipItem(); var clipItem = this._getClipItem();
return clipItem return clipItem
? clipItem._getCachedBounds(clipItem._matrix.prepended(matrix), ? clipItem._getCachedBounds(
matrix && matrix.appended(clipItem._matrix),
Base.set({}, options, { stroke: false })) Base.set({}, options, { stroke: false }))
: _getBounds.base.call(this, matrix, options); : _getBounds.base.call(this, matrix, options);
}, },

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -658,8 +658,8 @@ new function() { // Injection scope for various item event handlers
/** /**
* Specifies whether the item defines a clip mask. This can only be set on * Specifies whether the item defines a clip mask. This can only be set on
* paths and compound paths, and only if the item is already contained * paths, compound paths, and text frame objects, and only if the item is
* within a clipping group. * already contained within a clipping group.
* *
* @bean * @bean
* @type Boolean * @type Boolean
@ -1075,9 +1075,7 @@ new function() { // Injection scope for various item event handlers
options = options || {}; options = options || {};
for (var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
var item = items[i]; var item = items[i];
// Item is handled if it is visible and not recursively empty. if (item._visible && !item.isEmpty()) {
// This avoid errors with nested empty groups (#1467).
if (item._visible && !item.isEmpty(true)) {
// Pass true for noInternal, since even when getting // Pass true for noInternal, since even when getting
// internal bounds for this item, we need to apply the // internal bounds for this item, we need to apply the
// matrices to its children. // matrices to its children.
@ -1122,17 +1120,6 @@ new function() { // Injection scope for various item event handlers
* @type Rectangle * @type Rectangle
*/ */
/**
* The bounding rectangle of the item without any matrix transformations.
*
* Typical use case would be drawing a frame around the object where you
* want to draw something of the same size, position, rotation, and scaling,
* like a selection frame.
*
* @name Item#internalBounds
* @type Rectangle
*/
/** /**
* The rough bounding rectangle of the item that is sure to include all of * The rough bounding rectangle of the item that is sure to include all of
* the drawing, including stroke width. * the drawing, including stroke width.
@ -1818,15 +1805,11 @@ new function() { // Injection scope for various item event handlers
* } * }
* *
* @param {Point} point the point to check for * @param {Point} point the point to check for
* @return {Boolean}
*/ */
contains: function(/* point */) { contains: function(/* point */) {
// See CompoundPath#_contains() for the reason for !! // See CompoundPath#_contains() for the reason for !!
var matrix = this._matrix; return !!this._contains(
return ( this._matrix._inverseTransform(Point.read(arguments)));
matrix.isInvertible() &&
!!this._contains(matrix._inverseTransform(Point.read(arguments)))
);
}, },
_contains: function(point) { _contains: function(point) {
@ -2370,7 +2353,6 @@ new function() { // Injection scope for hit-test functions shared with project
* items can have children. * items can have children.
* *
* @param {String} json the JSON data to import from * @param {String} json the JSON data to import from
* @return {Item}
*/ */
importJSON: function(json) { importJSON: function(json) {
// Try importing into `this`. If another item is returned, try adding // Try importing into `this`. If another item is returned, try adding
@ -2406,8 +2388,7 @@ new function() { // Injection scope for hit-test functions shared with project
* kept as a link to their external URL. * kept as a link to their external URL.
* *
* @param {Object} [options] the export options * @param {Object} [options] the export options
* @return {SVGElement|String} the item converted to an SVG node or a * @return {SVGElement} the item converted to an SVG node
* `String` depending on `option.asString` value
*/ */
/** /**
@ -2791,7 +2772,6 @@ new function() { // Injection scope for hit-test functions shared with project
* Replaces this item with the provided new item which will takes its place * Replaces this item with the provided new item which will takes its place
* in the project hierarchy instead. * in the project hierarchy instead.
* *
* @param {Item} item the item that will replace this item
* @return {Boolean} {@true if the item was replaced} * @return {Boolean} {@true if the item was replaced}
*/ */
replaceWith: function(item) { replaceWith: function(item) {
@ -2860,23 +2840,11 @@ new function() { // Injection scope for hit-test functions shared with project
* no children, a {@link TextItem} with no text content and a {@link Path} * no children, a {@link TextItem} with no text content and a {@link Path}
* with no segments all are considered empty. * with no segments all are considered empty.
* *
* @param {Boolean} [recursively=false] whether an item with children should be
* considered empty if all its descendants are empty
* @return Boolean * @return Boolean
*/ */
isEmpty: function(recursively) { isEmpty: function() {
var children = this._children; var children = this._children;
var numChildren = children ? children.length : 0; return !children || !children.length;
if (recursively) {
// In recursive check, item is empty if all its children are empty.
for (var i = 0; i < numChildren; i++) {
if (!children[i].isEmpty(recursively)) {
return false;
}
}
return true;
}
return !numChildren;
}, },
/** /**
@ -3226,7 +3194,7 @@ new function() { // Injection scope for hit-test functions shared with project
* *
* @name Item#dashArray * @name Item#dashArray
* @property * @property
* @type Number[] * @type Array
* @default [] * @default []
*/ */
@ -4449,10 +4417,8 @@ new function() { // Injection scope for hit-test functions shared with project
this._draw(ctx, param, viewMatrix, strokeMatrix); this._draw(ctx, param, viewMatrix, strokeMatrix);
ctx.restore(); ctx.restore();
matrices.pop(); matrices.pop();
if (param.clip && !param.dontFinish) { if (param.clip && !param.dontFinish)
// Pass fill-rule to handle clipping with compound-paths (#1361). ctx.clip();
ctx.clip(this.getFillRule());
}
// If a temporary canvas was created, composite it onto the main canvas: // If a temporary canvas was created, composite it onto the main canvas:
if (!direct) { if (!direct) {
// Use BlendMode.process even for processing normal blendMode with // Use BlendMode.process even for processing normal blendMode with
@ -4706,176 +4672,4 @@ new function() { // Injection scope for hit-test functions shared with project
} }
return this; return this;
} }
}), /** @lends Item# */{ }));
/**
* {@grouptitle Tweening Functions}
*
* Tween item between two states.
*
* @name Item#tween
*
* @option options.duration {Number} the duration of the tweening
* @option [options.easing='linear'] {Function|String} an easing function or the type
* of the easing: {@values 'linear' 'easeInQuad' 'easeOutQuad'
* 'easeInOutQuad' 'easeInCubic' 'easeOutCubic' 'easeInOutCubic'
* 'easeInQuart' 'easeOutQuart' 'easeInOutQuart' 'easeInQuint'
* 'easeOutQuint' 'easeInOutQuint'}
* @option [options.start=true] {Boolean} whether to start tweening automatically
*
* @function
* @param {Object} from the state at the start of the tweening
* @param {Object} to the state at the end of the tweening
* @param {Object|Number} options the options or the duration
* @return {Tween}
*
* @example {@paperscript height=100}
* // Tween fillColor:
* var path = new Path.Circle({
* radius: view.bounds.height * 0.4,
* center: view.center
* });
* path.tween(
* { fillColor: 'blue' },
* { fillColor: 'red' },
* 3000
* );
* @example {@paperscript height=100}
* // Tween rotation:
* var path = new Shape.Rectangle({
* fillColor: 'red',
* center: [50, view.center.y],
* size: [60, 60]
* });
* path.tween({
* rotation: 180,
* 'position.x': view.bounds.width - 50,
* 'fillColor.hue': '+= 90'
* }, {
* easing: 'easeInOutCubic',
* duration: 2000
* });
*/
/**
* Tween item to a state.
*
* @name Item#tween
*
* @function
* @param {Object} to the state at the end of the tweening
* @param {Object|Number} options the options or the duration
* @return {Tween}
*
* @example {@paperscript height=200}
* // Tween a nested property with relative values
* var path = new Path.Rectangle({
* size: [100, 100],
* position: view.center,
* fillColor: 'red',
* });
*
* var delta = { x: path.bounds.width / 2, y: 0 };
*
* path.tween({
* 'segments[1].point': ['+=', delta],
* 'segments[2].point.x': '-= 50'
* }, 3000);
*
* @see Item#tween(from, to, options)
*/
/**
* Tween item.
*
* @name Item#tween
*
* @function
* @param {Object|Number} options the options or the duration
* @return {Tween}
*
* @see Item#tween(from, to, options)
*
* @example {@paperscript height=100}
* // Start an empty tween and just use the update callback:
* var path = new Path.Circle({
* fillColor: 'blue',
* radius: view.bounds.height * 0.4,
* center: view.center,
* });
* var pathFrom = path.clone({ insert: false })
* var pathTo = new Path.Rectangle({
* position: view.center,
* rectangle: path.bounds,
* insert: false
* });
* path.tween(2000).onUpdate = function(event) {
* path.interpolate(pathFrom, pathTo, event.factor)
* };
*/
tween: function(from, to, options) {
if (!options) {
// If there are only two or one arguments, shift arguments to the
// left by one (omit `from`):
options = to;
to = from;
from = null;
if (!options) {
options = to;
to = null;
}
}
var easing = options && options.easing,
start = options && options.start,
duration = options != null && (
typeof options === 'number' ? options : options.duration
),
tween = new Tween(this, from, to, duration, easing, start);
function onFrame(event) {
tween._handleFrame(event.time * 1000);
if (!tween.running) {
this.off('frame', onFrame);
}
}
if (duration) {
this.on('frame', onFrame);
}
return tween;
},
/**
*
* Tween item to a state.
*
* @function
* @param {Object} to the state at the end of the tweening
* @param {Object|Number} options the options or the duration
* @return {Tween}
*
* @see Item#tween(to, options)
*/
tweenTo: function(to, options) {
return this.tween(null, to, options);
},
/**
*
* Tween item from a state to its state before the tweening.
*
* @function
* @param {Object} from the state at the start of the tweening
* @param {Object|Number} options the options or the duration
* @return {Tween}
*
* @see Item#tween(from, to, options)
*
* @example {@paperscript height=100}
* // Tween fillColor from red to the path's initial fillColor:
* var path = new Path.Circle({
* fillColor: 'blue',
* radius: view.bounds.height * 0.4,
* center: view.center
* });
* path.tweenFrom({ fillColor: 'red' }, { duration: 1000 });
*/
tweenFrom: function(from, options) {
return this.tween(from, null, options);
}
});

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -133,7 +133,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
/** /**
* Checks whether the project has any content or not. * Checks whether the project has any content or not.
* *
* @return {Boolean} * @return Boolean
*/ */
isEmpty: function() { isEmpty: function() {
return !this._children.length; return !this._children.length;
@ -348,7 +348,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* {@link #layers} list. * {@link #layers} list.
* *
* @param {Number} index the index at which to insert the layer * @param {Number} index the index at which to insert the layer
* @param {Layer} layer the layer to be inserted in the project * @param {Item} item the item to be inserted in the project
* @return {Layer} the added layer, or `null` if adding was not possible * @return {Layer} the added layer, or `null` if adding was not possible
*/ */
insertLayer: function(index, layer) { insertLayer: function(index, layer) {
@ -745,7 +745,6 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* {@link Project#clear()} to do so. * {@link Project#clear()} to do so.
* *
* @param {String} json the JSON data to import from * @param {String} json the JSON data to import from
* @return {Item} the imported item
*/ */
importJSON: function(json) { importJSON: function(json) {
this.activate(); this.activate();
@ -782,8 +781,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* kept as a link to their external URL. * kept as a link to their external URL.
* *
* @param {Object} [options] the export options * @param {Object} [options] the export options
* @return {SVGElement|String} the project converted to an SVG node or a * @return {SVGElement} the project converted to an SVG node
* `String` depending on `option.asString` value
*/ */
/** /**

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -18,7 +18,6 @@
* @extends Item * @extends Item
*/ */
var Raster = Item.extend(/** @lends Raster# */{ var Raster = Item.extend(/** @lends Raster# */{
}, /** @lends Raster# */{
_class: 'Raster', _class: 'Raster',
_applyMatrix: false, _applyMatrix: false,
_canApplyMatrix: false, _canApplyMatrix: false,
@ -32,19 +31,15 @@ var Raster = Item.extend(/** @lends Raster# */{
// Prioritize `crossOrigin` over `source`: // Prioritize `crossOrigin` over `source`:
_prioritize: ['crossOrigin'], _prioritize: ['crossOrigin'],
_smoothing: false, _smoothing: false,
// Enforce creation of beans, as bean getters have hidden parameters.
// See #getContext(_change) below.
beans: true,
// TODO: Implement type, width, height. // TODO: Implement type, width, height.
// TODO: Have SymbolItem & Raster inherit from a shared class? // TODO: Have SymbolItem & Raster inherit from a shared class?
/** /**
* Creates a new raster item from the passed argument, and places it in the * Creates a new raster item from the passed argument, and places it in the
* active layer. `source` can either be a DOM Image, a Canvas, or a string * active layer. `object` can either be a DOM Image, a Canvas, or a string
* describing the URL to load the image from, or the ID of a DOM element to * describing the URL to load the image from, or the ID of a DOM element to
* get the image from (either a DOM Image or a Canvas). * get the image from (either a DOM Image or a Canvas).
* *
* @name Raster#initialize
* @param {HTMLImageElement|HTMLCanvasElement|String} [source] the source of * @param {HTMLImageElement|HTMLCanvasElement|String} [source] the source of
* the raster * the raster
* @param {Point} [position] the center position at which the raster item is * @param {Point} [position] the center position at which the raster item is
@ -82,64 +77,22 @@ var Raster = Item.extend(/** @lends Raster# */{
* raster.scale(0.5); * raster.scale(0.5);
* raster.rotate(10); * raster.rotate(10);
*/ */
/** initialize: function Raster(object, position) {
* Creates a new empty raster of the given size, and places it in the // Support two forms of item initialization: Passing one object literal
* active layer. // describing all the different properties to be set, or an image
* // (object) and a point where it should be placed (point).
* @name Raster#initialize
* @param {Size} size the size of the raster
* @param {Point} [position] the center position at which the raster item is
* placed
*
* @example {@paperscript height=150}
* // Creating an empty raster and fill it with random pixels:
* var width = 100;
* var height = 100;
*
* // Create an empty raster placed at view center.
* var raster = new Raster(new Size(width, height), view.center);
*
* // For all of its pixels...
* for (var i = 0; i < width; i++) {
* for (var j = 0; j < height; j++) {
* // ...set a random color.
* raster.setPixel(i, j, Color.random());
* }
* }
*/
initialize: function Raster(source, position) {
// Support three forms of item initialization:
// - One object literal describing all the different properties.
// - An image (Image|Canvas|String) and an optional position (Point).
// - A size (Size) describing the canvas that will be created and an
// optional position (Point).
// If _initialize can set properties through object literal, we're done. // If _initialize can set properties through object literal, we're done.
// Otherwise we need to check the type of object: var image, // Otherwise we need to check the type of object:
if (!this._initialize(source, if (!this._initialize(object,
position !== undefined && Point.read(arguments))) { position !== undefined && Point.read(arguments, 1))) {
var image, // object can be an image, canvas, URL or DOM-ID:
type = typeof source, var image = typeof object === 'string'
object = type === 'string' ? document.getElementById(object) : object;
? document.getElementById(source)
: type === 'object'
? source
: null;
if (object && object !== Item.NO_INSERT) {
if (object.getContent || object.naturalHeight != null) {
image = object;
} else if (object) {
// See if the arguments describe the raster size:
var size = Size.read(arguments);
if (!size.isZero()) {
image = CanvasProvider.getCanvas(size);
}
}
}
if (image) { if (image) {
// #setImage() handles both canvas and image types. // #setImage() handles both canvas and image types.
this.setImage(image); this.setImage(image);
} else { } else {
this.setSource(source); this.setSource(object);
} }
} }
if (!this._size) { if (!this._size) {
@ -352,7 +305,7 @@ var Raster = Item.extend(/** @lends Raster# */{
* case `null` is returned instead. * case `null` is returned instead.
* *
* @bean * @bean
* @type HTMLCanvasElement * @type HTMLCanvasELement
*/ */
getCanvas: function() { getCanvas: function() {
if (!this._canvas) { if (!this._canvas) {
@ -377,15 +330,15 @@ var Raster = Item.extend(/** @lends Raster# */{
* The Canvas 2D drawing context of the raster. * The Canvas 2D drawing context of the raster.
* *
* @bean * @bean
* @type CanvasRenderingContext2D * @type Context
*/ */
getContext: function(_change) { getContext: function(modify) {
if (!this._context) if (!this._context)
this._context = this.getCanvas().getContext('2d'); this._context = this.getCanvas().getContext('2d');
// Support a hidden parameter that indicates if the context will be used // Support a hidden parameter that indicates if the context will be used
// to change the Raster object. We can notify such changes ahead since // to modify the Raster object. We can notify such changes ahead since
// they are only used afterwards for redrawing. // they are only used afterwards for redrawing.
if (_change) { if (modify) {
// Also set _image to null since the Raster stops representing it. // Also set _image to null since the Raster stops representing it.
// NOTE: This should theoretically be in our own _changed() handler // NOTE: This should theoretically be in our own _changed() handler
// for ChangeFlag.PIXELS, but since it's only happening in one place // for ChangeFlag.PIXELS, but since it's only happening in one place
@ -433,11 +386,7 @@ var Raster = Item.extend(/** @lends Raster# */{
crossOrigin = this._crossOrigin; crossOrigin = this._crossOrigin;
if (crossOrigin) if (crossOrigin)
image.crossOrigin = crossOrigin; image.crossOrigin = crossOrigin;
// Prevent setting image source to `null`, as this isn't supported by image.src = src;
// browsers, and it would actually throw exceptions in JSDOM.
// TODO: Look into fixing this bug in JSDOM.
if (src)
image.src = src;
this.setImage(image); this.setImage(image);
}, },
@ -514,7 +463,7 @@ var Raster = Item.extend(/** @lends Raster# */{
* @param {Rectangle} rect the boundaries of the sub image in pixel * @param {Rectangle} rect the boundaries of the sub image in pixel
* coordinates * coordinates
* *
* @return {HTMLCanvasElement} the sub image as a Canvas object * @return {HTMLCanvasELement} the sub image as a Canvas object
*/ */
getSubCanvas: function(/* rect */) { getSubCanvas: function(/* rect */) {
var rect = Rectangle.read(arguments), var rect = Rectangle.read(arguments),
@ -570,7 +519,7 @@ var Raster = Item.extend(/** @lends Raster# */{
/** /**
* Draws an image on the raster. * Draws an image on the raster.
* *
* @param {HTMLImageElement|HTMLCanvasElement} image * @param {HTMLImageELement|HTMLCanvasELement} image
* @param {Point} point the offset of the image as a point in pixel * @param {Point} point the offset of the image as a point in pixel
* coordinates * coordinates
*/ */
@ -665,8 +614,8 @@ var Raster = Item.extend(/** @lends Raster# */{
* *
* @name Raster#getPixel * @name Raster#getPixel
* @function * @function
* @param {Number} x the x offset of the pixel in pixel coordinates * @param x the x offset of the pixel in pixel coordinates
* @param {Number} y the y offset of the pixel in pixel coordinates * @param y the y offset of the pixel in pixel coordinates
* @return {Color} the color of the pixel * @return {Color} the color of the pixel
*/ */
/** /**
@ -674,8 +623,7 @@ var Raster = Item.extend(/** @lends Raster# */{
* *
* @name Raster#getPixel * @name Raster#getPixel
* @function * @function
* @param {Point} point the offset of the pixel as a point in pixel * @param point the offset of the pixel as a point in pixel coordinates
* coordinates
* @return {Color} the color of the pixel * @return {Color} the color of the pixel
*/ */
getPixel: function(/* point */) { getPixel: function(/* point */) {
@ -691,18 +639,17 @@ var Raster = Item.extend(/** @lends Raster# */{
* *
* @name Raster#setPixel * @name Raster#setPixel
* @function * @function
* @param {Number} x the x offset of the pixel in pixel coordinates * @param x the x offset of the pixel in pixel coordinates
* @param {Number} y the y offset of the pixel in pixel coordinates * @param y the y offset of the pixel in pixel coordinates
* @param {Color} color the color that the pixel will be set to * @param color the color that the pixel will be set to
*/ */
/** /**
* Sets the color of the specified pixel to the specified color. * Sets the color of the specified pixel to the specified color.
* *
* @name Raster#setPixel * @name Raster#setPixel
* @function * @function
* @param {Point} point the offset of the pixel as a point in pixel * @param point the offset of the pixel as a point in pixel coordinates
* coordinates * @param color the color that the pixel will be set to
* @param {Color} color the color that the pixel will be set to
*/ */
setPixel: function(/* point, color */) { setPixel: function(/* point, color */) {
var point = Point.read(arguments), var point = Point.read(arguments),
@ -719,14 +666,6 @@ var Raster = Item.extend(/** @lends Raster# */{
ctx.putImageData(imageData, point.x, point.y); ctx.putImageData(imageData, point.x, point.y);
}, },
/**
* Clears the image, if it is backed by a canvas.
*/
clear: function() {
var size = this._size;
this.getContext(true).clearRect(0, 0, size.width + 1, size.height + 1);
},
// DOCS: document Raster#createImageData // DOCS: document Raster#createImageData
/** /**
* {@grouptitle Image Data} * {@grouptitle Image Data}
@ -822,8 +761,7 @@ var Raster = Item.extend(/** @lends Raster# */{
_draw: function(ctx, param, viewMatrix) { _draw: function(ctx, param, viewMatrix) {
var element = this.getElement(); var element = this.getElement();
// Only draw if image is not empty (#1320). if (element) {
if (element && element.width > 0 && element.height > 0) {
// Handle opacity for Rasters separately from the rest, since // Handle opacity for Rasters separately from the rest, since
// Rasters never draw a stroke. See Item#draw(). // Rasters never draw a stroke. See Item#draw().
ctx.globalAlpha = this._opacity; ctx.globalAlpha = this._opacity;

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -140,7 +140,7 @@ var SymbolDefinition = Base.extend(/** @lends SymbolDefinition# */{
/** /**
* Returns a copy of the symbol. * Returns a copy of the symbol.
* *
* @return {SymbolDefinition} * @return {Symbol}
*/ */
clone: function() { clone: function() {
return new SymbolDefinition(this._item.clone(false)); return new SymbolDefinition(this._item.clone(false));
@ -149,7 +149,7 @@ var SymbolDefinition = Base.extend(/** @lends SymbolDefinition# */{
/** /**
* Checks whether the symbol's definition is equal to the supplied symbol. * Checks whether the symbol's definition is equal to the supplied symbol.
* *
* @param {SymbolDefinition} symbol * @param {Symbol} symbol
* @return {Boolean} {@true if they are equal} * @return {Boolean} {@true if they are equal}
*/ */
equals: function(symbol) { equals: function(symbol) {

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -31,9 +31,7 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{
/** /**
* Creates a new symbol item. * Creates a new symbol item.
* *
* @name SymbolItem#initialize * @param {Symbol} definition the symbol definition to place
* @param {SymbolDefinition|Item} definition the definition to place or an
* item to place as a symbol
* @param {Point} [point] the center point of the placed symbol * @param {Point} [point] the center point of the placed symbol
* *
* @example {@paperscript split=true height=240} * @example {@paperscript split=true height=240}

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -38,10 +38,11 @@ if (typeof window === 'object') {
} else { } else {
// Some native javascript classes have name collisions with Paper.js // Some native javascript classes have name collisions with Paper.js
// classes. Store them to be able to use them later in tests. // classes. Store them to be able to use them later in tests.
this.nativeClasses = { NativeClasses = {
Event: window.Event, Event: Event,
MouseEvent: window.MouseEvent MouseEvent: MouseEvent
}; };
include('options.js'); include('options.js');
// Load constants.js, required by the on-the-fly preprocessing: // Load constants.js, required by the on-the-fly preprocessing:
include('constants.js'); include('constants.js');

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -18,7 +18,7 @@
module.exports = function(self, requireName) { module.exports = function(self, requireName) {
var Canvas; var Canvas;
try { try {
Canvas = require('canvas').Canvas; Canvas = require('canvas');
} catch(error) { } catch(error) {
// Remove `self.window`, so we still have the global `self` reference, // Remove `self.window`, so we still have the global `self` reference,
// but no `window` object: // but no `window` object:

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -37,13 +37,15 @@ try {
if (jsdom) { if (jsdom) {
// Create our document and window objects through jsdom. // Create our document and window objects through jsdom.
/* global document:true, window:true */ /* global document:true, window:true */
var document = new jsdom.JSDOM('<html><body></body></html>', { var document = jsdom.jsdom('<html><body></body></html>', {
// Use the current working directory as the document's origin, so // Use the current working directory as the document's origin, so
// requests to local files work correctly with CORS. // requests to local files work correctly with CORS.
url: 'file://' + process.cwd() + '/', url: 'file://' + process.cwd() + '/',
resources: 'usable' features: {
FetchExternalResources: ['img', 'script']
}
}); });
self = document.window; self = document.defaultView;
require('./canvas.js')(self, requireName); require('./canvas.js')(self, requireName);
require('./xml.js')(self); require('./xml.js')(self);
} else { } else {

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -17,7 +17,7 @@
// The paper.js version. // The paper.js version.
// NOTE: Adjust value here before calling `gulp publish`, which then updates and // NOTE: Adjust value here before calling `gulp publish`, which then updates and
// publishes the various JSON package files automatically. // publishes the various JSON package files automatically.
var version = '0.12.3'; var version = '0.11.8';
// If this file is loaded in the browser, we're in load.js mode. // If this file is loaded in the browser, we're in load.js mode.
var load = typeof window === 'object'; var load = typeof window === 'object';

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 @@
* *
* 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 - 2019 Juerg Lehni * Copyright (c) 2006 - 2016 Juerg Lehni
* http://scratchdisk.com/ * http://scratchdisk.com/
* *
* Distributed under the MIT license. * Distributed under the MIT license.
@ -23,7 +23,7 @@
*** ***
* *
* Acorn.js * Acorn.js
* https://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,
* created by Marijn Haverbeke and released under an MIT license. * created by Marijn Haverbeke and released under an MIT license.
@ -102,8 +102,6 @@ var paper = function(self, undefined) {
/*#*/ include('tool/ToolEvent.js'); /*#*/ include('tool/ToolEvent.js');
/*#*/ include('tool/Tool.js'); /*#*/ include('tool/Tool.js');
/*#*/ include('anim/Tween.js');
/*#*/ include('net/Http.js'); /*#*/ include('net/Http.js');
/*#*/ include('canvas/CanvasProvider.js'); /*#*/ include('canvas/CanvasProvider.js');

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -161,7 +161,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
* *
* @bean * @bean
* @type Boolean * @type Boolean
* @see Path#closed * @see Path#isClosed()
*/ */
isClosed: function() { isClosed: function() {
var children = this._children; var children = this._children;
@ -193,7 +193,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
/** /**
* The last Segment contained within the compound-path, a short-cut to * The last Segment contained within the compound-path, a short-cut to
* calling {@link Path#lastSegment} on {@link Item#lastChild}. * calling {@link Path#lastChild} on {@link Item#lastChild}.
* *
* @bean * @bean
* @type Segment * @type Segment

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -1476,7 +1476,7 @@ new function() { // Scope for methods that require private functions
// 2: normal, 1st derivative // 2: normal, 1st derivative
// 3: curvature, 1st derivative & 2nd derivative // 3: curvature, 1st derivative & 2nd derivative
// Prevent tangents and normals of length 0: // Prevent tangents and normals of length 0:
// https://stackoverflow.com/questions/10506868/ // http://stackoverflow.com/questions/10506868/
if (t < tMin) { if (t < tMin) {
x = cx; x = cx;
y = cy; y = cy;
@ -1698,7 +1698,7 @@ new function() { // Scope for methods that require private functions
* Peaks are locations sharing some qualities of curvature extrema but * Peaks are locations sharing some qualities of curvature extrema but
* are cheaper to compute. They fulfill their purpose here quite well. * are cheaper to compute. They fulfill their purpose here quite well.
* See: * See:
* https://math.stackexchange.com/questions/1954845/bezier-curvature-extrema * http://math.stackexchange.com/questions/1954845/bezier-curvature-extrema
* *
* @param {Number[]} v the curve values array * @param {Number[]} v the curve values array
* @return {Number[]} the roots of all found peaks * @return {Number[]} the roots of all found peaks

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -147,7 +147,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
* The path that this locations is situated on. * The path that this locations is situated on.
* *
* @bean * @bean
* @type Path * @type Item
*/ */
getPath: function() { getPath: function() {
var curve = this.getCurve(); var curve = this.getCurve();
@ -159,7 +159,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
* it is part of a {@link Path} item. * it is part of a {@link Path} item.
* *
* @bean * @bean
* @type Number * @type Index
*/ */
getIndex: function() { getIndex: function() {
var curve = this.getCurve(); var curve = this.getCurve();
@ -284,7 +284,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
* @bean * @bean
* @type Number * @type Number
* @see Curve#getNearestLocation(point) * @see Curve#getNearestLocation(point)
* @see PathItem#getNearestLocation(point) * @see Path#getNearestLocation(point)
*/ */
getDistance: function() { getDistance: function() {
return this._distance; return this._distance;

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -75,6 +75,7 @@ var Path = PathItem.extend(/** @lends Path# */{
* Creates a new path item from SVG path-data and places it at the top of * Creates a new path item from SVG path-data and places it at the top of
* the active layer. * the active layer.
* *
* @param
* @name Path#initialize * @name Path#initialize
* @param {String} pathData the SVG path-data that describes the geometry * @param {String} pathData the SVG path-data that describes the geometry
* of this path * of this path
@ -483,11 +484,9 @@ var Path = PathItem.extend(/** @lends Path# */{
* Adds one or more segments to the end of the {@link #segments} array of * Adds one or more segments to the end of the {@link #segments} array of
* this path. * this path.
* *
* @param {...(Segment|Point|Number[])} segment the segment or point to be * @param {Segment|Point} segment the segment or point to be added.
* added. * @return {Segment} the added segment. This is not necessarily the same
* @return {Segment|Segment[]} the added segment(s). This is not necessarily * object, e.g. if the segment to be added already belongs to another path
* the same object, e.g. if the segment to be added already belongs to
* another path.
* *
* @example {@paperscript} * @example {@paperscript}
* // Adding segments to a path using point objects: * // Adding segments to a path using point objects:
@ -1216,8 +1215,6 @@ var Path = PathItem.extend(/** @lends Path# */{
/** /**
* Reduces the path by removing curves that have a length of 0, * Reduces the path by removing curves that have a length of 0,
* and unnecessary segments between two collinear flat curves. * and unnecessary segments between two collinear flat curves.
*
* @return {Path} the reduced path
*/ */
reduce: function(options) { reduce: function(options) {
var curves = this.getCurves(), var curves = this.getCurves(),
@ -2175,13 +2172,11 @@ new function() { // Scope for drawing
// SegmentPoint objects maybe seem a bit tedious but is worth the benefit in // SegmentPoint objects maybe seem a bit tedious but is worth the benefit in
// performance. // performance.
function drawHandles(ctx, segments, matrix, size) { function drawHandles(ctx, segments, matrix, size, isFullySelected) {
// Only draw if size is not null or negative. if (size === 0) {
if (size <= 0) return; return;
}
var half = size / 2, var half = size / 2,
miniSize = size - 2,
miniHalf = half - 1,
coords = new Array(6), coords = new Array(6),
pX, pY; pX, pY;
@ -2475,10 +2470,9 @@ new function() { // PostScript-style drawing commands
// #2: arcTo(through, to) // #2: arcTo(through, to)
through = to; through = to;
to = Point.read(arguments); to = Point.read(arguments);
} else if (!from.equals(to)) { } else {
// #3: arcTo(to, radius, rotation, clockwise, large) // #3: arcTo(to, radius, rotation, clockwise, large)
// Draw arc in SVG style, but only if `from` and `to` are not // Drawing arcs in SVG style:
// equal (#1613).
var radius = Size.read(arguments), var radius = Size.read(arguments),
isZero = Numerical.isZero; isZero = Numerical.isZero;
// If rx = 0 or ry = 0 then this arc is treated as a // If rx = 0 or ry = 0 then this arc is treated as a
@ -2487,7 +2481,7 @@ new function() { // PostScript-style drawing commands
if (isZero(radius.width) || isZero(radius.height)) if (isZero(radius.width) || isZero(radius.height))
return this.lineTo(to); return this.lineTo(to);
// See for an explanation of the following calculations: // See for an explanation of the following calculations:
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes // http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
var rotation = Base.read(arguments), var rotation = Base.read(arguments),
clockwise = !!Base.read(arguments), clockwise = !!Base.read(arguments),
large = !!Base.read(arguments), large = !!Base.read(arguments),
@ -2574,49 +2568,47 @@ new function() { // PostScript-style drawing commands
extent += extent < 0 ? 360 : -360; extent += extent < 0 ? 360 : -360;
} }
} }
if (extent) { var epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON,
var epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON, ext = abs(extent),
ext = abs(extent), // Calculate the amount of segments required to approximate over
// Calculate amount of segments required to approximate over // `extend` degrees (extend / 90), but prevent ceil() from
// `extend` degrees (extend / 90), but prevent ceil() from // rounding up small imprecisions by subtracting epsilon first.
// rounding up small imprecisions by subtracting epsilon. count = ext >= 360 ? 4 : Math.ceil((ext - epsilon) / 90),
count = ext >= 360 ? 4 : Math.ceil((ext - epsilon) / 90), inc = extent / count,
inc = extent / count, half = inc * Math.PI / 360,
half = inc * Math.PI / 360, z = 4 / 3 * Math.sin(half) / (1 + Math.cos(half)),
z = 4 / 3 * Math.sin(half) / (1 + Math.cos(half)), segments = [];
segments = []; for (var i = 0; i <= count; i++) {
for (var i = 0; i <= count; i++) { // Explicitly use to point for last segment, since depending
// Explicitly use to point for last segment, since depending // on values the calculation adds imprecision:
// on values the calculation adds imprecision: var pt = to,
var pt = to, out = null;
out = null; if (i < count) {
if (i < count) { out = vector.rotate(90).multiply(z);
out = vector.rotate(90).multiply(z); if (matrix) {
if (matrix) { pt = matrix._transformPoint(vector);
pt = matrix._transformPoint(vector); out = matrix._transformPoint(vector.add(out))
out = matrix._transformPoint(vector.add(out)) .subtract(pt);
.subtract(pt);
} else {
pt = center.add(vector);
}
}
if (!i) {
// Modify startSegment
current.setHandleOut(out);
} else { } else {
// Add new Segment pt = center.add(vector);
var _in = vector.rotate(-90).multiply(z);
if (matrix) {
_in = matrix._transformPoint(vector.add(_in))
.subtract(pt);
}
segments.push(new Segment(pt, _in, out));
} }
vector = vector.rotate(inc);
} }
// Add all segments at once at the end for higher performance if (!i) {
this._add(segments); // Modify startSegment
current.setHandleOut(out);
} else {
// Add new Segment
var _in = vector.rotate(-90).multiply(z);
if (matrix) {
_in = matrix._transformPoint(vector.add(_in))
.subtract(pt);
}
segments.push(new Segment(pt, _in, out));
}
vector = vector.rotate(inc);
} }
// Add all segments at once at the end for higher performance
this._add(segments);
}, },
lineBy: function(/* to */) { lineBy: function(/* to */) {
@ -2854,9 +2846,8 @@ statics: {
normal1 = curve1.getNormalAtTime(1).multiply(radius) normal1 = curve1.getNormalAtTime(1).multiply(radius)
.transform(strokeMatrix), .transform(strokeMatrix),
normal2 = curve2.getNormalAtTime(0).multiply(radius) normal2 = curve2.getNormalAtTime(0).multiply(radius)
.transform(strokeMatrix), .transform(strokeMatrix);
angle = normal1.getDirectedAngle(normal2); if (normal1.getDirectedAngle(normal2) < 0) {
if (angle < 0 || angle >= 180) {
normal1 = normal1.negate(); normal1 = normal1.negate();
normal2 = normal2.negate(); normal2 = normal2.negate();
} }

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -25,7 +25,7 @@
* @author Harikrishnan Gopalakrishnan <hari.exeption@gmail.com> * @author Harikrishnan Gopalakrishnan <hari.exeption@gmail.com>
* @author Jan Boesenberg <development@iconexperience.com> * @author Jan Boesenberg <development@iconexperience.com>
* @author Juerg Lehni <juerg@scratchdisk.com> * @author Juerg Lehni <juerg@scratchdisk.com>
* https://hkrish.com/playground/paperjs/booleanStudy.html * http://hkrish.com/playground/paperjs/booleanStudy.html
*/ */
PathItem.inject(new function() { PathItem.inject(new function() {
var min = Math.min, var min = Math.min,
@ -1125,7 +1125,7 @@ PathItem.inject(new function() {
/** /**
* Splits the geometry of this path along the geometry of the specified * Splits the geometry of this path along the geometry of the specified
* path returns the result as a new group item. This is equivalent to * path returns the result as a new group item. This is equivalent to
* calling {@link #subtract(path)} and {@link #intersect(path)} and * calling {@link #subtract(path)} and {@link #subtract(path)} and
* putting the results into a new group. * putting the results into a new group.
* *
* @option [options.insert=true] {Boolean} whether the resulting item * @option [options.insert=true] {Boolean} whether the resulting item
@ -1156,7 +1156,7 @@ PathItem.inject(new function() {
* amount of resulting paths allows so, otherwise a new path / * amount of resulting paths allows so, otherwise a new path /
* compound-path is created, replacing the current one. * compound-path is created, replacing the current one.
* *
* @return {PathItem} the resulting path item * @return {PahtItem} the resulting path item
*/ */
resolveCrossings: function() { resolveCrossings: function() {
var children = this._children, var children = this._children,
@ -1278,7 +1278,7 @@ PathItem.inject(new function() {
* @param {Boolean} [clockwise] if provided, the orientation of the root * @param {Boolean} [clockwise] if provided, the orientation of the root
* paths will be set to the orientation specified by `clockwise`, * paths will be set to the orientation specified by `clockwise`,
* otherwise the orientation of the largest root child is used. * otherwise the orientation of the largest root child is used.
* @return {PathItem} a reference to the item itself, reoriented * @return {PahtItem} a reference to the item itself, reoriented
*/ */
reorient: function(nonZero, clockwise) { reorient: function(nonZero, clockwise) {
var children = this._children; var children = this._children;

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -102,8 +102,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{
* *
* @bean * @bean
* @type Boolean * @type Boolean
* @see Path#area * @see Path#getArea()
* @see CompoundPath#area * @see CompoundPath#getArea()
*/ */
isClockwise: function() { isClockwise: function() {
return this.getArea() >= 0; return this.getArea() >= 0;
@ -345,8 +345,6 @@ var PathItem = Item.extend(/** @lends PathItem# */{
* crossing each other, as opposed to simply touching. * crossing each other, as opposed to simply touching.
* *
* @param {PathItem} path the other item to find the crossings with * @param {PathItem} path the other item to find the crossings with
* @return {CurveLocation[]} the locations of all crossings between the
* paths
* @see #getIntersections(path) * @see #getIntersections(path)
*/ */
getCrossings: function(path) { getCrossings: function(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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -234,8 +234,8 @@ var Segment = Base.extend(/** @lends Segment# */{
* Checks if the segment has any curve handles set. * Checks if the segment has any curve handles set.
* *
* @return {Boolean} {@true if the segment has handles set} * @return {Boolean} {@true if the segment has handles set}
* @see Segment#handleIn * @see Segment#getHandleIn()
* @see Segment#handleOut * @see Segment#getHandleOut()
* @see Curve#hasHandles() * @see Curve#hasHandles()
* @see Path#hasHandles() * @see Path#hasHandles()
*/ */
@ -554,9 +554,6 @@ var Segment = Base.extend(/** @lends Segment# */{
return this._path ? !!this._path.removeSegment(this._index) : false; return this._path ? !!this._path.removeSegment(this._index) : false;
}, },
/**
* @return {Segment}
*/
clone: function() { clone: function() {
return new Segment(this._point, this._handleIn, this._handleOut); return new Segment(this._point, this._handleIn, this._handleOut);
}, },

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -80,7 +80,7 @@ var Color = Base.extend(new function() {
} else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) { } else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) {
// RGB / RGBA or HSL / HSLA // RGB / RGBA or HSL / HSLA
type = match[1]; type = match[1];
components = match[2].trim().split(/[,\s]+/g); components = match[2].split(/[,\s]+/g);
var isHSL = type === 'hsl'; var isHSL = type === 'hsl';
for (var i = 0, l = Math.min(components.length, 4); i < l; i++) { for (var i = 0, l = Math.min(components.length, 4); i < l; i++) {
var component = components[i]; var component = components[i];
@ -691,8 +691,6 @@ var Color = Base.extend(new function() {
* constructors also work for calls of `set()`. * constructors also work for calls of `set()`.
* *
* @function * @function
* @param {...*} values
* @return {Color}
*/ */
set: '#initialize', set: '#initialize',
@ -711,13 +709,8 @@ var Color = Base.extend(new function() {
*/ */
_changed: function() { _changed: function() {
this._canvasStyle = null; this._canvasStyle = null;
if (this._owner) { if (this._owner)
if (this._setter) { this._owner._changed(/*#=*/Change.STYLE);
this._owner[this._setter](this);
} else {
this._owner._changed(/*#=*/Change.STYLE);
}
}
}, },
/** /**
@ -736,7 +729,7 @@ var Color = Base.extend(new function() {
}, },
/** /**
* Converts the color to another type. * Converts the color another type.
* *
* @param {String} type the color type to convert to. Possible values: * @param {String} type the color type to convert to. Possible values:
* {@values 'rgb', 'gray', 'hsb', 'hsl'} * {@values 'rgb', 'gray', 'hsb', 'hsl'}
@ -1190,35 +1183,9 @@ var Color = Base.extend(new function() {
// Export for backward compatibility code below. // Export for backward compatibility code below.
_types: types, _types: types,
/**
* Returns a color object with random {@link #red}, {@link #green}
* and {@link #blue} values between `0` and `1`.
*
* @return {Color} the newly created color object
* @static
*
* @example {@paperscript}
* var circle = new Path.Circle(view.center, 50);
* // Set a random color as circle fill color.
* circle.fillColor = Color.random();
*/
random: function() { random: function() {
var random = Math.random; var random = Math.random;
return new Color(random(), random(), random()); return new Color(random(), random(), random());
},
_setOwner: function(color, owner, setter) {
if (color) {
// Clone color if owner changes:
if (color._owner && owner && color._owner !== owner) {
color = color.clone();
}
if (!color._owner ^ !owner) {
color._owner = owner || null;
color._setter = setter || null;
}
}
return color;
} }
} }
}); });

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -175,10 +175,12 @@ var GradientStop = Base.extend(/** @lends GradientStop# */{
}, },
setColor: function(/* color */) { setColor: function(/* color */) {
// Clear old color owner before setting new one: // Make sure newly set colors are cloned, since they can only have
Color._setOwner(this._color, null); // one owner.
this._color = Color._setOwner(Color.read(arguments, 0), this, var color = Color.read(arguments, 0, { clone: true });
'setColor'); if (color)
color._owner = this;
this._color = color;
this._changed(); this._changed();
}, },

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -162,35 +162,29 @@ var Style = Base.extend(new function() {
// raw value is stored, and conversion only happens in the getter. // raw value is stored, and conversion only happens in the getter.
fields[set] = function(value) { fields[set] = function(value) {
var owner = this._owner, var owner = this._owner,
children = owner && owner._children, children = owner && owner._children;
applyToChildren = children && children.length > 0
&& !(owner instanceof CompoundPath);
// Only unify styles on children of Groups, excluding CompoundPaths. // Only unify styles on children of Groups, excluding CompoundPaths.
if (applyToChildren) { if (children && children.length > 0
&& !(owner instanceof CompoundPath)) {
for (var i = 0, l = children.length; i < l; i++) for (var i = 0, l = children.length; i < l; i++)
children[i]._style[set](value); children[i]._style[set](value);
} } else if (key in this._defaults) {
// Always store selectedColor in item _values to make sure that
// group selected bounds and position color is coherent whether it
// has children or not when the value is set.
if ((key === 'selectedColor' || !applyToChildren)
&& key in this._defaults) {
var old = this._values[key]; var old = this._values[key];
if (old !== value) { if (old !== value) {
if (isColor) { if (isColor) {
// The old value may be a native string or other color // The old value may be a native string or other color
// description that wasn't coerced to a color object yet // description that wasn't coerced to a color object yet
if (old) { if (old && old._owner !== undefined) {
Color._setOwner(old, null); old._owner = undefined;
old._canvasStyle = null; old._canvasStyle = null;
} }
if (value && value.constructor === Color) { if (value && value.constructor === Color) {
// Clone color if it already has an owner.
// NOTE: If value is not a Color, it is only // NOTE: If value is not a Color, it is only
// converted and cloned in the getter further down. // converted and cloned in the getter further down.
value = Color._setOwner(value, owner, if (value._owner)
// Only provide a color-setter if the style value = value.clone();
// is to be applied to the children: value._owner = owner;
applyToChildren && set);
} }
} }
// NOTE: We do not convert the values to Colors in the // NOTE: We do not convert the values to Colors in the
@ -207,13 +201,29 @@ var Style = Base.extend(new function() {
fields[get] = function(_dontMerge) { fields[get] = function(_dontMerge) {
var owner = this._owner, var owner = this._owner,
children = owner && owner._children, children = owner && owner._children,
applyToChildren = children && children.length > 0
&& !(owner instanceof CompoundPath),
value; value;
// If the owner has children, walk through all of them and see if // If the owner has children, walk through all of them and see if
// they all have the same style. // they all have the same style.
// If true is passed for _dontMerge, don't merge children styles. // If true is passed for _dontMerge, don't merge children styles
if (applyToChildren && !_dontMerge) { if (key in this._defaults && (!children || !children.length
|| _dontMerge || owner instanceof CompoundPath)) {
var value = this._values[key];
if (value === undefined) {
value = this._defaults[key];
if (value && value.clone)
value = value.clone();
} else {
var ctor = isColor ? Color : isPoint ? Point : null;
if (ctor && !(value && value.constructor === ctor)) {
// Convert to a Color / Point, and stored result of the
// conversion.
this._values[key] = value = ctor.read([value], 0,
{ readNull: true, clone: true });
if (value && isColor)
value._owner = owner;
}
}
} else if (children) {
for (var i = 0, l = children.length; i < l; i++) { for (var i = 0, l = children.length; i < l; i++) {
var childValue = children[i]._style[get](); var childValue = children[i]._style[get]();
if (!i) { if (!i) {
@ -224,30 +234,6 @@ var Style = Base.extend(new function() {
return undefined; return undefined;
} }
} }
} else if (key in this._defaults) {
var value = this._values[key];
if (value === undefined) {
value = this._defaults[key];
// Clone defaults if available:
if (value && value.clone) {
value = value.clone();
}
} else {
var ctor = isColor ? Color : isPoint ? Point : null;
if (ctor && !(value && value.constructor === ctor)) {
// Convert to a Color / Point, and stored result of the
// conversion.
this._values[key] = value = ctor.read([value], 0,
{ readNull: true, clone: true });
}
}
}
if (value && isColor) {
// Color._setOwner() may clone the color if it already has a
// different owner (e.g. resulting from `childValue` above).
// Only provide a color-setter if the style is to be applied to
// the children:
value = Color._setOwner(value, owner, applyToChildren && set);
} }
return value; return value;
}; };
@ -544,7 +530,7 @@ var Style = Base.extend(new function() {
* *
* @name Style#dashArray * @name Style#dashArray
* @property * @property
* @type Number[] * @type Array
* @default [] * @default []
*/ */

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -29,16 +29,11 @@ new function() {
// in rotate(). To do so, SVG requries us to inverse transform the // in rotate(). To do so, SVG requries us to inverse transform the
// translation point by the matrix itself, since they are provided // translation point by the matrix itself, since they are provided
// in local coordinates. // in local coordinates.
var point; matrix = matrix._shiftless();
if (matrix.isInvertible()) { var point = matrix._inverseTransform(trans);
matrix = matrix._shiftless();
point = matrix._inverseTransform(trans);
trans = null;
} else {
point = new Point();
}
attrs[center ? 'cx' : 'x'] = point.x; attrs[center ? 'cx' : 'x'] = point.x;
attrs[center ? 'cy' : 'y'] = point.y; attrs[center ? 'cy' : 'y'] = point.y;
trans = null;
} }
if (!matrix.isIdentity()) { if (!matrix.isIdentity()) {
// 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
@ -182,7 +177,7 @@ new function() {
definition = item._definition, definition = item._definition,
node = getDefinition(definition, 'symbol'), node = getDefinition(definition, 'symbol'),
definitionItem = definition._item, definitionItem = definition._item,
bounds = definitionItem.getStrokeBounds(); bounds = definitionItem.getBounds();
if (!node) { if (!node) {
node = SvgElement.create('symbol', { node = SvgElement.create('symbol', {
viewBox: formatter.rectangle(bounds) viewBox: formatter.rectangle(bounds)
@ -455,7 +450,7 @@ new function() {
if (rect) { if (rect) {
attrs.width = rect.width; attrs.width = rect.width;
attrs.height = rect.height; attrs.height = rect.height;
if (rect.x || rect.x === 0 || rect.y || rect.y === 0) if (rect.x || rect.y)
attrs.viewBox = formatter.rectangle(rect); attrs.viewBox = formatter.rectangle(rect);
} }
var node = SvgElement.create('svg', attrs, formatter), var node = SvgElement.create('svg', attrs, formatter),

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -22,12 +22,11 @@ new function() {
var definitions = {}, var definitions = {},
rootSize; rootSize;
function getValue(node, name, isString, allowNull, allowPercent, function getValue(node, name, isString, allowNull, allowPercent) {
defaultValue) {
// Interpret value as number. Never return NaN, but 0 instead. // Interpret value as number. Never return NaN, but 0 instead.
// If the value is a sequence of numbers, parseFloat will // If the value is a sequence of numbers, parseFloat will
// return the first occurring number, which is enough for now. // return the first occurring number, which is enough for now.
var value = SvgElement.get(node, name) || defaultValue, var value = SvgElement.get(node, name),
res = value == null res = value == null
? allowNull ? allowNull
? null ? null
@ -44,9 +43,9 @@ new function() {
: res; : res;
} }
function getPoint(node, x, y, allowNull, allowPercent, defaultX, defaultY) { function getPoint(node, x, y, allowNull, allowPercent) {
x = getValue(node, x || 'x', false, allowNull, allowPercent, defaultX); x = getValue(node, x || 'x', false, allowNull, allowPercent);
y = getValue(node, y || 'y', false, allowNull, allowPercent, defaultY); y = getValue(node, y || 'y', false, allowNull, allowPercent);
return allowNull && (x == null || y == null) ? null return allowNull && (x == null || y == null) ? null
: new Point(x, y); : new Point(x, y);
} }
@ -169,16 +168,13 @@ new function() {
'userSpaceOnUse'; 'userSpaceOnUse';
// Allow percentages in all values if scaleToBounds is true: // Allow percentages in all values if scaleToBounds is true:
if (radial) { if (radial) {
origin = getPoint(node, 'cx', 'cy', false, scaleToBounds, origin = getPoint(node, 'cx', 'cy', false, scaleToBounds);
'50%', '50%');
destination = origin.add( destination = origin.add(
getValue(node, 'r', false, false, scaleToBounds, '50%'), 0); getValue(node, 'r', false, false, scaleToBounds), 0);
highlight = getPoint(node, 'fx', 'fy', true, scaleToBounds); highlight = getPoint(node, 'fx', 'fy', true, scaleToBounds);
} else { } else {
origin = getPoint(node, 'x1', 'y1', false, scaleToBounds, origin = getPoint(node, 'x1', 'y1', false, scaleToBounds);
'0%', '0%'); destination = getPoint(node, 'x2', 'y2', false, scaleToBounds);
destination = getPoint(node, 'x2', 'y2', false, scaleToBounds,
'100%', '0%');
} }
var color = applyAttributes( var color = applyAttributes(
new Color(gradient, origin, destination, highlight), node); new Color(gradient, origin, destination, highlight), node);
@ -200,23 +196,23 @@ new function() {
return importNode(child, options, isRoot); return importNode(child, options, isRoot);
} }
}, },
// https://www.w3.org/TR/SVG/struct.html#Groups // http://www.w3.org/TR/SVG/struct.html#Groups
g: importGroup, g: importGroup,
// https://www.w3.org/TR/SVG/struct.html#NewDocument // http://www.w3.org/TR/SVG/struct.html#NewDocument
svg: importGroup, svg: importGroup,
clippath: importGroup, clippath: importGroup,
// https://www.w3.org/TR/SVG/shapes.html#PolygonElement // http://www.w3.org/TR/SVG/shapes.html#PolygonElement
polygon: importPoly, polygon: importPoly,
// https://www.w3.org/TR/SVG/shapes.html#PolylineElement // http://www.w3.org/TR/SVG/shapes.html#PolylineElement
polyline: importPoly, polyline: importPoly,
// https://www.w3.org/TR/SVG/paths.html // http://www.w3.org/TR/SVG/paths.html
path: importPath, path: importPath,
// https://www.w3.org/TR/SVG/pservers.html#LinearGradients // http://www.w3.org/TR/SVG/pservers.html#LinearGradients
lineargradient: importGradient, lineargradient: importGradient,
// https://www.w3.org/TR/SVG/pservers.html#RadialGradients // http://www.w3.org/TR/SVG/pservers.html#RadialGradients
radialgradient: importGradient, radialgradient: importGradient,
// https://www.w3.org/TR/SVG/struct.html#ImageElement // http://www.w3.org/TR/SVG/struct.html#ImageElement
image: function (node) { image: function (node) {
var raster = new Raster(getValue(node, 'href', true)); var raster = new Raster(getValue(node, 'href', true));
raster.on('load', function() { raster.on('load', function() {
@ -232,17 +228,17 @@ new function() {
return raster; return raster;
}, },
// https://www.w3.org/TR/SVG/struct.html#SymbolElement // http://www.w3.org/TR/SVG/struct.html#SymbolElement
symbol: function(node, type, options, isRoot) { symbol: function(node, type, options, isRoot) {
return new SymbolDefinition( return new SymbolDefinition(
// Pass true for dontCenter: // Pass true for dontCenter:
importGroup(node, type, options, isRoot), true); importGroup(node, type, options, isRoot), true);
}, },
// https://www.w3.org/TR/SVG/struct.html#DefsElement // http://www.w3.org/TR/SVG/struct.html#DefsElement
defs: importGroup, defs: importGroup,
// https://www.w3.org/TR/SVG/struct.html#UseElement // http://www.w3.org/TR/SVG/struct.html#UseElement
use: function(node) { use: function(node) {
// Note the namespaced xlink:href attribute is just called href // Note the namespaced xlink:href attribute is just called href
// as a property on node. // as a property on node.
@ -262,14 +258,14 @@ new function() {
: null; : null;
}, },
// https://www.w3.org/TR/SVG/shapes.html#InterfaceSVGCircleElement // http://www.w3.org/TR/SVG/shapes.html#InterfaceSVGCircleElement
circle: function(node) { circle: function(node) {
return new Shape.Circle( return new Shape.Circle(
getPoint(node, 'cx', 'cy'), getPoint(node, 'cx', 'cy'),
getValue(node, 'r')); getValue(node, 'r'));
}, },
// https://www.w3.org/TR/SVG/shapes.html#InterfaceSVGEllipseElement // http://www.w3.org/TR/SVG/shapes.html#InterfaceSVGEllipseElement
ellipse: function(node) { ellipse: function(node) {
// We only use object literal notation where the default one is not // We only use object literal notation where the default one is not
// supported (e.g. center / radius fo Shape.Ellipse). // supported (e.g. center / radius fo Shape.Ellipse).
@ -279,7 +275,7 @@ new function() {
}); });
}, },
// https://www.w3.org/TR/SVG/shapes.html#RectElement // http://www.w3.org/TR/SVG/shapes.html#RectElement
rect: function(node) { rect: function(node) {
return new Shape.Rectangle(new Rectangle( return new Shape.Rectangle(new Rectangle(
getPoint(node), getPoint(node),
@ -287,7 +283,7 @@ new function() {
), getSize(node, 'rx', 'ry')); ), getSize(node, 'rx', 'ry'));
}, },
// https://www.w3.org/TR/SVG/shapes.html#LineElement // http://www.w3.org/TR/SVG/shapes.html#LineElement
line: function(node) { line: function(node) {
return new Path.Line( return new Path.Line(
getPoint(node, 'x1', 'y1'), getPoint(node, 'x1', 'y1'),
@ -349,11 +345,7 @@ new function() {
text.setContent(lines.join('\n')); text.setContent(lines.join('\n'));
return text; return text;
} }
}, }
// https://www.w3.org/TR/SVG/struct.html#SwitchElement
// Conditional attributes are ignored and all children are rendered.
switch: importGroup
}; };
// Attributes and Styles // Attributes and Styles
@ -364,7 +356,7 @@ new function() {
function applyTransform(item, value, name, node) { function applyTransform(item, value, name, node) {
if (item.transform) { if (item.transform) {
// https://www.w3.org/TR/SVG/types.html#DataTypeTransformList // http://www.w3.org/TR/SVG/types.html#DataTypeTransformList
// Parse SVG transform string. First we split at /)\s*/, to separate // Parse SVG transform string. First we split at /)\s*/, to separate
// commands // commands
var transforms = (node.getAttribute(name) || '').split(/\)\s*/g), var transforms = (node.getAttribute(name) || '').split(/\)\s*/g),
@ -407,8 +399,8 @@ new function() {
} }
function applyOpacity(item, value, name) { function applyOpacity(item, value, name) {
// https://www.w3.org/TR/SVG/painting.html#FillOpacityProperty // http://www.w3.org/TR/SVG/painting.html#FillOpacityProperty
// https://www.w3.org/TR/SVG/painting.html#StrokeOpacityProperty // http://www.w3.org/TR/SVG/painting.html#StrokeOpacityProperty
var key = name === 'fill-opacity' ? 'getFillColor' : 'getStrokeColor', var key = name === 'fill-opacity' ? 'getFillColor' : 'getStrokeColor',
color = item[key] && item[key](); color = item[key] && item[key]();
if (color) if (color)
@ -450,7 +442,7 @@ new function() {
}, },
'clip-path': function(item, value) { 'clip-path': function(item, value) {
// https://www.w3.org/TR/SVG/masking.html#ClipPathProperty // http://www.w3.org/TR/SVG/masking.html#ClipPathProperty
var clip = getDefinition(value); var clip = getDefinition(value);
if (clip) { if (clip) {
clip = clip.clone(); clip = clip.clone();
@ -482,20 +474,20 @@ new function() {
}, },
'stop-color': function(item, value) { 'stop-color': function(item, value) {
// https://www.w3.org/TR/SVG/pservers.html#StopColorProperty // http://www.w3.org/TR/SVG/pservers.html#StopColorProperty
if (item.setColor) if (item.setColor)
item.setColor(value); item.setColor(value);
}, },
'stop-opacity': function(item, value) { 'stop-opacity': function(item, value) {
// https://www.w3.org/TR/SVG/pservers.html#StopOpacityProperty // http://www.w3.org/TR/SVG/pservers.html#StopOpacityProperty
// NOTE: It is important that this is applied after stop-color! // NOTE: It is important that this is applied after stop-color!
if (item._color) if (item._color)
item._color.setAlpha(parseFloat(value)); item._color.setAlpha(parseFloat(value));
}, },
offset: function(item, value) { offset: function(item, value) {
// https://www.w3.org/TR/SVG/pservers.html#StopElementOffsetAttribute // http://www.w3.org/TR/SVG/pservers.html#StopElementOffsetAttribute
if (item.setOffset) { if (item.setOffset) {
var percent = value.match(/(.*)%$/); var percent = value.match(/(.*)%$/);
item.setOffset(percent ? percent[1] / 100 : parseFloat(value)); item.setOffset(percent ? percent[1] / 100 : parseFloat(value));
@ -503,7 +495,7 @@ new function() {
}, },
viewBox: function(item, value, name, node, styles) { viewBox: function(item, value, name, node, styles) {
// https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute // http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
// TODO: implement preserveAspectRatio attribute // TODO: implement preserveAspectRatio attribute
// viewBox will be applied both to the group that's created for the // viewBox will be applied both to the group that's created for the
// content in SymbolDefinition#item, and the SymbolItem itself. // content in SymbolDefinition#item, and the SymbolItem itself.

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -49,7 +49,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
this._pixelRatio = 1; this._pixelRatio = 1;
if (!/^off|false$/.test(PaperScope.getAttribute(canvas, 'hidpi'))) { if (!/^off|false$/.test(PaperScope.getAttribute(canvas, 'hidpi'))) {
// Hi-DPI Canvas support based on: // Hi-DPI Canvas support based on:
// https://www.html5rocks.com/en/tutorials/canvas/hidpi/ // http://www.html5rocks.com/en/tutorials/canvas/hidpi/
var deviceRatio = window.devicePixelRatio || 1, var deviceRatio = window.devicePixelRatio || 1,
backingStoreRatio = DomElement.getPrefixed(ctx, backingStoreRatio = DomElement.getPrefixed(ctx,
'backingStorePixelRatio') || 1; 'backingStorePixelRatio') || 1;
@ -88,10 +88,6 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
} }
}, },
getContext: function() {
return this._context;
},
/** /**
* Converts the provide size in any of the units allowed in the browser to * Converts the provide size in any of the units allowed in the browser to
* pixels. * pixels.
@ -128,7 +124,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
/** /**
* Updates the view if there are changes. Note that when using built-in * Updates the view if there are changes. Note that when using built-in
* event handlers for interaction, animation and load events, this method is * event hanlders for interaction, animation and load events, this method is
* invoked for you automatically at the end. * invoked for you automatically at the end.
* *
* @return {Boolean} {@true if the view was updated} * @return {Boolean} {@true if the view was updated}

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 - 2019, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/ * 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.
* *
@ -522,7 +522,7 @@ var View = Base.extend(Emitter, /** @lends View# */{
* *
* @bean * @bean
* @type Number * @type Number
* @see #scaling * @see #getScaling()
*/ */
getZoom: function() { getZoom: function() {
var scaling = this._decompose().scaling; var scaling = this._decompose().scaling;
@ -559,7 +559,7 @@ var View = Base.extend(Emitter, /** @lends View# */{
* *
* @bean * @bean
* @type Point * @type Point
* @see #zoom * @see #getZoom()
*/ */
getScaling: function() { getScaling: function() {
var scaling = this._decompose().scaling; var scaling = this._decompose().scaling;
@ -1496,7 +1496,7 @@ new function() { // Injection scope for event handling on the browser
updateFocus: updateFocus, updateFocus: updateFocus,
/** /**
* Clear all events handling state information. Made for testing * Clear all events handling state informations. Made for testing
* purpose, to have a way to start with a fresh state before each * purpose, to have a way to start with a fresh state before each
* test. * test.
* @private * @private

View file

@ -1,17 +0,0 @@
<!-- test gradient default values -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="200">
<defs>
<!-- radial -->
<radialGradient id="gra-1">
<stop offset="0" stop-color="black"/>
<stop offset="1" stop-color="white"/>
</radialGradient>
<!-- linear -->
<linearGradient id="gra-2">
<stop offset="0" stop-color="black"/>
<stop offset="1" stop-color="white"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="100" height="100" fill="url(#gra-1)"/>
<rect x="0" y="100" width="100" height="100" fill="url(#gra-2)"/>
</svg>

Before

Width:  |  Height:  |  Size: 658 B

View file

@ -1,9 +0,0 @@
<svg x="0" y="0" width="300" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0" y1="0" y2="300" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="yellow"></stop>
<stop offset="1" stop-color="blue"></stop>
</linearGradient>
</defs>
<rect x="0" y="0" width="300" height="300" fill="url(#gradient)"></rect>
</svg>

Before

Width:  |  Height:  |  Size: 430 B

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