Bump version to v0.9.18

This commit is contained in:
Jürg Lehni 2014-04-07 11:26:37 +02:00
parent 495e10e408
commit 2111e76804
10 changed files with 906 additions and 830 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "paper", "name": "paper",
"version": "0.9.17", "version": "0.9.18",
"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",

View file

@ -42,6 +42,7 @@ update_version 'package.json'
update_version 'bower.json' update_version 'bower.json'
update_version 'component.json' update_version 'component.json'
# Add changed json configuration files # Add changed json configuration files
git add -u src/options.js # Commit as well, since it was manually bumped.
git add -u package.json git add -u package.json
git add -u bower.json git add -u bower.json
git add -u component.json git add -u component.json

View file

@ -1,6 +1,6 @@
{ {
"name": "paper", "name": "paper",
"version": "0.9.17", "version": "0.9.18",
"description": "The Swiss Army Knife of Vector Graphics Scripting", "description": "The Swiss Army Knife of Vector Graphics Scripting",
"license": "MIT", "license": "MIT",
"repo": "paperjs/paper.js", "repo": "paperjs/paper.js",

505
dist/paper-core.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

505
dist/paper-full.js vendored

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

487
dist/paper-node.js vendored
View file

@ -1,5 +1,5 @@
/*! /*!
* Paper.js v0.9.17 - The Swiss Army Knife of Vector Graphics Scripting. * Paper.js v0.9.18 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/ * http://paperjs.org/
* *
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
@ -9,7 +9,7 @@
* *
* All rights reserved. * All rights reserved.
* *
* Date: Thu Mar 20 17:20:10 2014 +0100 * Date: Mon Apr 7 11:24:38 2014 +0200
* *
*** ***
* *
@ -33,7 +33,7 @@
var paper = new function(undefined) { var paper = new function(undefined) {
var Base = new function() { var Base = new function() {
var hidden = /^(statics|preserve|enumerable|prototype|toString|valueOf)$/, var hidden = /^(statics|enumerable|beans|preserve)$/,
forEach = [].forEach || function(iter, bind) { forEach = [].forEach || function(iter, bind) {
for (var i = 0, l = this.length; i < l; i++) for (var i = 0, l = this.length; i < l; i++)
@ -78,26 +78,26 @@ var Base = new function() {
return _define(obj, name, desc); return _define(obj, name, desc);
}; };
function inject(dest, src, enumerable, base, preserve) { function inject(dest, src, enumerable, beans, preserve) {
var beans; var beansNames = {};
function field(name, val, dontCheck) { function field(name, val) {
var val = val || (val = describe(src, name)) val = val || (val = describe(src, name))
&& (val.get ? val : val.value); && (val.get ? val : val.value);
if (typeof val === 'string' && val[0] === '#') if (typeof val === 'string' && val[0] === '#')
val = dest[val.substring(1)] || val; val = dest[val.substring(1)] || val;
var isFunc = typeof val === 'function', var isFunc = typeof val === 'function',
res = val, res = val,
prev = preserve || isFunc prev = preserve || isFunc
? (val && val.get ? name in dest : dest[name]) : null, ? (val && val.get ? name in dest : dest[name])
: null,
bean; bean;
if ((dontCheck || val !== undefined && src.hasOwnProperty(name)) if (!preserve || !prev) {
&& (!preserve || !prev)) {
if (isFunc && prev) if (isFunc && prev)
val.base = prev; val.base = prev;
if (isFunc && beans if (isFunc && beans !== false
&& (bean = name.match(/^([gs]et|is)(([A-Z])(.*))$/))) && (bean = name.match(/^([gs]et|is)(([A-Z])(.*))$/)))
beans[bean[3].toLowerCase() + bean[4]] = bean[2]; beansNames[bean[3].toLowerCase() + bean[4]] = bean[2];
if (!res || isFunc || !res.get || typeof res.get !== 'function' if (!res || isFunc || !res.get || typeof res.get !== 'function'
|| !Base.isPlainObject(res)) || !Base.isPlainObject(res))
res = { value: res, writable: true }; res = { value: res, writable: true };
@ -110,18 +110,16 @@ var Base = new function() {
} }
} }
if (src) { if (src) {
beans = {}; for (var name in src) {
for (var name in src)
if (src.hasOwnProperty(name) && !hidden.test(name)) if (src.hasOwnProperty(name) && !hidden.test(name))
field(name, null, true); field(name);
field('toString'); }
field('valueOf'); for (var name in beansNames) {
for (var name in beans) { var part = beansNames[name],
var part = beans[name],
set = dest['set' + part], set = dest['set' + part],
get = dest['get' + part] || set && dest['is' + part]; get = dest['get' + part] || set && dest['is' + part];
if (get && (get.length === 0 || set)) if (get && (beans === true || get.length === 0))
field(name, { get: get, set: set }, true); field(name, { get: get, set: set });
} }
} }
return dest; return dest;
@ -136,26 +134,25 @@ var Base = new function() {
return bind; return bind;
} }
function copy(dest, source) { function set(obj, props) {
for (var i in source) for (var i in props)
if (source.hasOwnProperty(i)) if (props.hasOwnProperty(i))
dest[i] = source[i]; obj[i] = props[i];
return dest; return obj;
} }
return inject(function Base() { return inject(function Base() {
for (var i = 0, l = arguments.length; i < l; i++) for (var i = 0, l = arguments.length; i < l; i++)
copy(this, arguments[i]); set(this, arguments[i]);
}, { }, {
inject: function(src) { inject: function(src) {
if (src) { if (src) {
var proto = this.prototype, var statics = src.statics === true ? src : src.statics,
base = Object.getPrototypeOf(proto).constructor, beans = src.beans,
statics = src.statics === true ? src : src.statics; preserve = src.preserve;
if (statics != src) if (statics !== src)
inject(proto, src, src.enumerable, base && base.prototype, inject(this.prototype, src, src.enumerable, beans, preserve);
src.preserve); inject(this, statics, true, beans, preserve);
inject(this, statics, true, base, src.preserve);
} }
for (var i = 1, l = arguments.length; i < l; i++) for (var i = 1, l = arguments.length; i < l; i++)
this.inject(arguments[i]); this.inject(arguments[i]);
@ -180,8 +177,11 @@ var Base = new function() {
} }
}, true).inject({ }, true).inject({
inject: function() { inject: function() {
for (var i = 0, l = arguments.length; i < l; i++) for (var i = 0, l = arguments.length; i < l; i++) {
inject(this, arguments[i], arguments[i].enumerable); var src = arguments[i];
if (src)
inject(this, src, src.enumerable, src.beans, src.preserve);
}
return this; return this;
}, },
@ -203,10 +203,10 @@ var Base = new function() {
create: create, create: create,
define: define, define: define,
describe: describe, describe: describe,
copy: copy, set: set,
clone: function(obj) { clone: function(obj) {
return copy(new obj.constructor(), obj); return set(new obj.constructor(), obj);
}, },
isPlainObject: function(obj) { isPlainObject: function(obj) {
@ -219,7 +219,6 @@ var Base = new function() {
for (var i = 0, l = arguments.length; i < l; i++) for (var i = 0, l = arguments.length; i < l; i++)
if (arguments[i] !== undefined) if (arguments[i] !== undefined)
return arguments[i]; return arguments[i];
return null;
} }
} }
}); });
@ -706,7 +705,7 @@ var PaperScope = Base.extend({
} }
}, },
version: '0.9.17', version: '0.9.18',
getView: function() { getView: function() {
return this.project && this.project.getView(); return this.project && this.project.getView();
@ -1071,48 +1070,6 @@ var Point = Base.extend({
return [f.number(this.x), f.number(this.y)]; return [f.number(this.x), f.number(this.y)];
}, },
add: function() {
var point = Point.read(arguments);
return new Point(this.x + point.x, this.y + point.y);
},
subtract: function() {
var point = Point.read(arguments);
return new Point(this.x - point.x, this.y - point.y);
},
multiply: function() {
var point = Point.read(arguments);
return new Point(this.x * point.x, this.y * point.y);
},
divide: function() {
var point = Point.read(arguments);
return new Point(this.x / point.x, this.y / point.y);
},
modulo: function() {
var point = Point.read(arguments);
return new Point(this.x % point.x, this.y % point.y);
},
negate: function() {
return new Point(-this.x, -this.y);
},
transform: function(matrix) {
return matrix ? matrix._transformPoint(this) : this;
},
getDistance: function(_point, squared) {
var point = Point.read(arguments),
x = point.x - this.x,
y = point.y - this.y,
d = x * x + y * y;
squared = Base.read(arguments);
return squared ? d : Math.sqrt(d);
},
getLength: function() { getLength: function() {
return Math.sqrt(this.x * this.x + this.y * this.y); return Math.sqrt(this.x * this.x + this.y * this.y);
}, },
@ -1134,18 +1091,6 @@ var Point = Base.extend({
); );
} }
}, },
normalize: function(length) {
if (length === undefined)
length = 1;
var current = this.getLength(),
scale = current !== 0 ? length / current : 0,
point = new Point(this.x * scale, this.y * scale);
if (scale >= 0)
point._angle = this._angle;
return point;
},
getAngle: function() { getAngle: function() {
return this.getAngleInRadians.apply(this, arguments) * 180 / Math.PI; return this.getAngleInRadians.apply(this, arguments) * 180 / Math.PI;
}, },
@ -1186,12 +1131,33 @@ var Point = Base.extend({
getQuadrant: function() { getQuadrant: function() {
return this.x >= 0 ? this.y >= 0 ? 1 : 4 : this.y >= 0 ? 2 : 3; return this.x >= 0 ? this.y >= 0 ? 1 : 4 : this.y >= 0 ? 2 : 3;
}
}, {
beans: false,
getDirectedAngle: function() {
var point = Point.read(arguments);
return Math.atan2(this.cross(point), this.dot(point)) * 180 / Math.PI;
}, },
getDirectedAngle: function(_point) { getDistance: function() {
var point = _point; var point = Point.read(arguments),
point = Point.read(arguments); x = point.x - this.x,
return Math.atan2(this.cross(point), this.dot(point)) * 180 / Math.PI; y = point.y - this.y,
d = x * x + y * y,
squared = Base.read(arguments);
return squared ? d : Math.sqrt(d);
},
normalize: function(length) {
if (length === undefined)
length = 1;
var current = this.getLength(),
scale = current !== 0 ? length / current : 0,
point = new Point(this.x * scale, this.y * scale);
if (scale >= 0)
point._angle = this._angle;
return point;
}, },
rotate: function(angle, center) { rotate: function(angle, center) {
@ -1208,6 +1174,39 @@ var Point = Base.extend({
return center ? point.add(center) : point; return center ? point.add(center) : point;
}, },
transform: function(matrix) {
return matrix ? matrix._transformPoint(this) : this;
},
add: function() {
var point = Point.read(arguments);
return new Point(this.x + point.x, this.y + point.y);
},
subtract: function() {
var point = Point.read(arguments);
return new Point(this.x - point.x, this.y - point.y);
},
multiply: function() {
var point = Point.read(arguments);
return new Point(this.x * point.x, this.y * point.y);
},
divide: function() {
var point = Point.read(arguments);
return new Point(this.x / point.x, this.y / point.y);
},
modulo: function() {
var point = Point.read(arguments);
return new Point(this.x % point.x, this.y % point.y);
},
negate: function() {
return new Point(-this.x, -this.y);
},
isInside: function(rect) { isInside: function(rect) {
return rect.contains(this); return rect.contains(this);
}, },
@ -1257,7 +1256,7 @@ var Point = Base.extend({
statics: { statics: {
min: function() { min: function() {
var point1 = Point.read(arguments); var point1 = Point.read(arguments),
point2 = Point.read(arguments); point2 = Point.read(arguments);
return new Point( return new Point(
Math.min(point1.x, point2.x), Math.min(point1.x, point2.x),
@ -1266,7 +1265,7 @@ var Point = Base.extend({
}, },
max: function() { max: function() {
var point1 = Point.read(arguments); var point1 = Point.read(arguments),
point2 = Point.read(arguments); point2 = Point.read(arguments);
return new Point( return new Point(
Math.max(point1.x, point2.x), Math.max(point1.x, point2.x),
@ -1484,6 +1483,7 @@ var LinkedSize = Size.extend({
var Rectangle = Base.extend({ var Rectangle = Base.extend({
_class: 'Rectangle', _class: 'Rectangle',
_readIndex: true, _readIndex: true,
beans: true,
initialize: function Rectangle(arg0, arg1, arg2, arg3) { initialize: function Rectangle(arg0, arg1, arg2, arg3) {
var type = typeof arg0, var type = typeof arg0,
@ -1806,7 +1806,9 @@ var Rectangle = Base.extend({
this[setX](point.x); this[setX](point.x);
this[setY](point.y); this[setY](point.y);
}; };
}, {}); }, {
beans: true
});
}); });
var LinkedRectangle = Rectangle.extend({ var LinkedRectangle = Rectangle.extend({
@ -2230,8 +2232,7 @@ var Matrix = Base.extend({
applyToContext: function(ctx) { applyToContext: function(ctx) {
ctx.transform(this._a, this._c, this._b, this._d, this._tx, this._ty); ctx.transform(this._a, this._c, this._b, this._d, this._tx, this._ty);
} }
}, new function() { }, Base.each(['a', 'c', 'b', 'd', 'tx', 'ty'], function(name) {
return Base.each(['a', 'c', 'b', 'd', 'tx', 'ty'], function(name) {
var part = Base.capitalize(name), var part = Base.capitalize(name),
prop = '_' + name; prop = '_' + name;
this['get' + part] = function() { this['get' + part] = function() {
@ -2241,8 +2242,7 @@ var Matrix = Base.extend({
this[prop] = value; this[prop] = value;
this._changed(); this._changed();
}; };
}, {}); }, {}));
});
var Line = Base.extend({ var Line = Base.extend({
_class: 'Line', _class: 'Line',
@ -2497,7 +2497,8 @@ var Project = PaperScopeItem.extend({
var param = new Base({ var param = new Base({
offset: new Point(0, 0), offset: new Point(0, 0),
pixelRatio: pixelRatio, pixelRatio: pixelRatio,
trackTransforms: true trackTransforms: true,
transforms: [matrix]
}); });
for (var i = 0, l = this.layers.length; i < l; i++) for (var i = 0, l = this.layers.length; i < l; i++)
this.layers[i].draw(ctx, param); this.layers[i].draw(ctx, param);
@ -2509,7 +2510,7 @@ var Project = PaperScopeItem.extend({
for (var id in this._selectedItems) { for (var id in this._selectedItems) {
var item = this._selectedItems[id], var item = this._selectedItems[id],
globalMatrix = item._globalMatrix, globalMatrix = item._globalMatrix,
size = this._scope.settings.handleSize; size = this._scope.settings.handleSize,
half = size / 2; half = size / 2;
if (item._updateVersion === this._updateVersion if (item._updateVersion === this._updateVersion
&& (item._drawSelected || item._boundsSelected) && (item._drawSelected || item._boundsSelected)
@ -2518,11 +2519,10 @@ var Project = PaperScopeItem.extend({
|| item.getLayer().getSelectedColor(); || item.getLayer().getSelectedColor();
ctx.strokeStyle = ctx.fillStyle = color ctx.strokeStyle = ctx.fillStyle = color
? color.toCanvasStyle(ctx) : '#009dec'; ? color.toCanvasStyle(ctx) : '#009dec';
var mx = matrix.clone().concatenate(globalMatrix);
if (item._drawSelected) if (item._drawSelected)
item._drawSelected(ctx, mx); item._drawSelected(ctx, globalMatrix);
if (item._boundsSelected) { if (item._boundsSelected) {
var coords = mx._transformCorners( var coords = globalMatrix._transformCorners(
item.getInternalBounds()); item.getInternalBounds());
ctx.beginPath(); ctx.beginPath();
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
@ -2632,7 +2632,7 @@ var Item = Base.extend(Callback, {
_initialize: function(props, point) { _initialize: function(props, point) {
var internal = props && props.internal === true, var internal = props && props.internal === true,
matrix = this._matrix = new Matrix(); matrix = this._matrix = new Matrix(),
project = paper.project; project = paper.project;
if (!internal) if (!internal)
this._id = Item._id = (Item._id || 0) + 1; this._id = Item._id = (Item._id || 0) + 1;
@ -2846,6 +2846,7 @@ var Item = Base.extend(Callback, {
} }
}; };
}, {}), { }, {}), {
beans: true,
_locked: false, _locked: false,
@ -2979,11 +2980,10 @@ var Item = Base.extend(Callback, {
bounds.height, this, 'setBounds') bounds.height, this, 'setBounds')
: bounds; : bounds;
}; };
this[key] = {
get: this[getter]
};
}, },
{ {
beans: true,
_getBounds: function(getter, matrix, cacheItem) { _getBounds: function(getter, matrix, cacheItem) {
var children = this._children; var children = this._children;
if (!children || children.length == 0) if (!children || children.length == 0)
@ -3073,6 +3073,8 @@ var Item = Base.extend(Callback, {
} }
}), { }), {
beans: true,
_decompose: function() { _decompose: function() {
return this._decomposed = this._matrix.decompose(); return this._decomposed = this._matrix.decompose();
}, },
@ -3121,18 +3123,20 @@ var Item = Base.extend(Callback, {
} }
}, },
getGlobalMatrix: function() { getGlobalMatrix: function(_internal) {
var matrix = this._globalMatrix, var matrix = this._globalMatrix,
updateVersion = this._project._updateVersion; updateVersion = this._project._updateVersion,
viewMatrix = this.getView()._matrix;
if (matrix && matrix._updateVersion !== updateVersion) if (matrix && matrix._updateVersion !== updateVersion)
matrix = null; matrix = null;
if (!matrix) { if (!matrix) {
matrix = this._globalMatrix = this._matrix.clone(); matrix = this._globalMatrix = this._matrix.clone();
if (this._parent) matrix.preConcatenate(this._parent
matrix.preConcatenate(this._parent.getGlobalMatrix()); ? this._parent.getGlobalMatrix(true)
: viewMatrix);
matrix._updateVersion = updateVersion; matrix._updateVersion = updateVersion;
} }
return matrix; return _internal ? matrix : viewMatrix.inverted().concatenate(matrix);
}, },
getApplyMatrix: function() { getApplyMatrix: function() {
@ -3146,7 +3150,7 @@ var Item = Base.extend(Callback, {
getTransformContent: '#getApplyMatrix', getTransformContent: '#getApplyMatrix',
setTransformContent: '#setApplyMatrix', setTransformContent: '#setApplyMatrix',
}, {
getProject: function() { getProject: function() {
return this._project; return this._project;
}, },
@ -3280,7 +3284,7 @@ var Item = Base.extend(Callback, {
var bounds = this.getStrokeBounds(), var bounds = this.getStrokeBounds(),
scale = (resolution || this.getView().getResolution()) / 72, scale = (resolution || this.getView().getResolution()) / 72,
topLeft = bounds.getTopLeft().floor(), topLeft = bounds.getTopLeft().floor(),
bottomRight = bounds.getBottomRight().ceil() bottomRight = bounds.getBottomRight().ceil(),
size = new Size(bottomRight.subtract(topLeft)), size = new Size(bottomRight.subtract(topLeft)),
canvas = CanvasProvider.getCanvas(size.multiply(scale)), canvas = CanvasProvider.getCanvas(size.multiply(scale)),
ctx = canvas.getContext('2d'), ctx = canvas.getContext('2d'),
@ -3316,7 +3320,8 @@ var Item = Base.extend(Callback, {
hitTest: function(point, options) { hitTest: function(point, options) {
point = Point.read(arguments); point = Point.read(arguments);
options = HitResult.getOptions(Base.read(arguments)); options = HitResult.getOptions(Base.read(arguments));
if (this._locked || !this._visible || this._guide && !options.guides) if (this._locked || !this._visible || this._guide && !options.guides
|| this.isEmpty())
return null; return null;
var matrix = this._matrix, var matrix = this._matrix,
@ -3387,7 +3392,7 @@ var Item = Base.extend(Callback, {
_hitTest: function(point, options) { _hitTest: function(point, options) {
if (options.fill && this.hasFill() && this._contains(point)) if (options.fill && this.hasFill() && this._contains(point))
return new HitResult('fill', this); return new HitResult('fill', this);
}, }
}, { }, {
matches: function(match) { matches: function(match) {
function matchObject(obj1, obj2) { function matchObject(obj1, obj2) {
@ -3855,15 +3860,13 @@ var Item = Base.extend(Callback, {
return; return;
var updateVersion = this._updateVersion = this._project._updateVersion; var updateVersion = this._updateVersion = this._project._updateVersion;
var trackTransforms = param.trackTransforms, var trackTransforms = param.trackTransforms,
transforms = param.transforms = param.transforms || [new Matrix()], transforms = param.transforms,
matrix = this._matrix, matrix = this._matrix,
parentMatrix = transforms[transforms.length - 1], parentMatrix = transforms[transforms.length - 1],
globalMatrix = parentMatrix.clone().concatenate(matrix); globalMatrix = parentMatrix.clone().concatenate(matrix);
if (!globalMatrix.isInvertible()) if (!globalMatrix.isInvertible())
return; return;
if (trackTransforms) { if (trackTransforms) {
if (!transforms)
transforms = param.transforms = [];
transforms.push(this._globalMatrix = globalMatrix); transforms.push(this._globalMatrix = globalMatrix);
globalMatrix._updateVersion = updateVersion; globalMatrix._updateVersion = updateVersion;
} }
@ -4363,7 +4366,7 @@ statics: new function() {
}, },
Ellipse: function() { Ellipse: function() {
var ellipse = Shape._readEllipse(arguments); var ellipse = Shape._readEllipse(arguments),
radius = ellipse.radius; radius = ellipse.radius;
return createShape('ellipse', ellipse.center, radius.multiply(2), return createShape('ellipse', ellipse.center, radius.multiply(2),
radius, arguments); radius, arguments);
@ -4765,8 +4768,8 @@ var PlacedSymbol = Item.extend({
cacheItem); cacheItem);
}, },
_hitTest: function(point, options, matrix) { _hitTest: function(point, options) {
var res = this._symbol._definition._hitTest(point, options, matrix); var res = this._symbol._definition.hitTest(point, options);
if (res) if (res)
res.item = this; res.item = this;
return res; return res;
@ -4812,6 +4815,7 @@ var HitResult = Base.extend({
var Segment = Base.extend({ var Segment = Base.extend({
_class: 'Segment', _class: 'Segment',
beans: true,
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) { initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
var count = arguments.length, var count = arguments.length,
@ -4843,7 +4847,8 @@ var Segment = Base.extend({
_serialize: function(options) { _serialize: function(options) {
return Base.serialize(this.isLinear() ? this._point return Base.serialize(this.isLinear() ? this._point
: [this._point, this._handleIn, this._handleOut], options, true); : [this._point, this._handleIn, this._handleOut],
options, true);
}, },
_changed: function(point) { _changed: function(point) {
@ -4982,7 +4987,8 @@ var Segment = Base.extend({
var path = this._path, var path = this._path,
index = this._index; index = this._index;
if (path) { if (path) {
if (!path._closed && index == path._segments.length - 1) if (index > 0 && !path._closed
&& index === path._segments.length - 1)
index--; index--;
return path.getCurves()[index] || null; return path.getCurves()[index] || null;
} }
@ -4991,7 +4997,9 @@ var Segment = Base.extend({
getLocation: function() { getLocation: function() {
var curve = this.getCurve(); var curve = this.getCurve();
return curve ? new CurveLocation(curve, curve.getNext() ? 0 : 1) : null; return curve
? new CurveLocation(curve, this === curve._segment1 ? 0 : 1)
: null;
}, },
getNext: function() { getNext: function() {
@ -5999,6 +6007,8 @@ new function() {
var CurveLocation = Base.extend({ var CurveLocation = Base.extend({
_class: 'CurveLocation', _class: 'CurveLocation',
beans: true,
initialize: function CurveLocation(curve, parameter, point, _curve2, initialize: function CurveLocation(curve, parameter, point, _curve2,
_parameter2, _point2, _distance) { _parameter2, _point2, _distance) {
this._id = CurveLocation._id = (CurveLocation._id || 0) + 1; this._id = CurveLocation._id = (CurveLocation._id || 0) + 1;
@ -6024,8 +6034,8 @@ var CurveLocation = Base.extend({
} else if (parameter == null) { } else if (parameter == null) {
return null; return null;
} else { } else {
this._segment = curve.getLength(0, parameter) this._segment = curve.getPartLength(0, parameter)
< curve.getLength(parameter, 1) < curve.getPartLength(parameter, 1)
? curve._segment1 ? curve._segment1
: curve._segment2; : curve._segment2;
} }
@ -6033,10 +6043,6 @@ var CurveLocation = Base.extend({
return this._segment; return this._segment;
}, },
setSegment: function(segment) {
this._segment = segment;
},
getCurve: function(_uncached) { getCurve: function(_uncached) {
if (!this._curve || _uncached) { if (!this._curve || _uncached) {
this._curve = this._segment1.getCurve(); this._curve = this._segment1.getCurve();
@ -6046,10 +6052,6 @@ var CurveLocation = Base.extend({
return this._curve; return this._curve;
}, },
setCurve: function(curve) {
this._curve = curve;
},
getIntersection: function() { getIntersection: function() {
var intersection = this._intersection; var intersection = this._intersection;
if (!intersection && this._curve2) { if (!intersection && this._curve2) {
@ -6079,7 +6081,7 @@ var CurveLocation = Base.extend({
getCurveOffset: function() { getCurveOffset: function() {
var curve = this.getCurve(), var curve = this.getCurve(),
parameter = this.getParameter(); parameter = this.getParameter();
return parameter != null && curve && curve.getLength(0, parameter); return parameter != null && curve && curve.getPartLength(0, parameter);
}, },
getParameter: function(_uncached) { getParameter: function(_uncached) {
@ -6090,10 +6092,6 @@ var CurveLocation = Base.extend({
return this._parameter; return this._parameter;
}, },
setParameter: function(parameter) {
this._parameter = parameter;
},
getPoint: function(_uncached) { getPoint: function(_uncached) {
if ((!this._point || _uncached) && this._parameter != null) { if ((!this._point || _uncached) && this._parameter != null) {
var curve = this.getCurve(); var curve = this.getCurve();
@ -6102,10 +6100,6 @@ var CurveLocation = Base.extend({
return this._point; return this._point;
}, },
setPoint: function(point) {
this._point = point;
},
getTangent: function() { getTangent: function() {
var parameter = this.getParameter(), var parameter = this.getParameter(),
curve = this.getCurve(); curve = this.getCurve();
@ -6300,7 +6294,7 @@ var PathItem = Item.extend({
case 'l': case 'l':
var move = lower === 'm'; var move = lower === 'm';
if (move && previous && previous !== 'z') if (move && previous && previous !== 'z')
this.closePath(); this.closePath(true);
for (var j = 0; j < length; j += 2) for (var j = 0; j < length; j += 2)
this[j === 0 && move ? 'moveTo' : 'lineTo']( this[j === 0 && move ? 'moveTo' : 'lineTo'](
current = getPoint(j)); current = getPoint(j));
@ -6361,7 +6355,7 @@ var PathItem = Item.extend({
} }
break; break;
case 'z': case 'z':
this.closePath(); this.closePath(true);
break; break;
} }
previous = lower; previous = lower;
@ -6375,7 +6369,7 @@ var PathItem = Item.extend({
_contains: function(point) { _contains: function(point) {
var winding = this._getWinding(point, false, true); var winding = this._getWinding(point, false, true);
return !!(this.getWindingRule() === 'evenodd' ? winding & 1 : winding); return !!(this.getWindingRule() === 'evenodd' ? winding & 1 : winding);
}, }
}); });
@ -6490,40 +6484,6 @@ var Path = PathItem.extend({
return curves[curves.length - 1]; return curves[curves.length - 1];
}, },
getPathData: function(precision) {
var segments = this._segments,
f = Formatter.instance,
parts = [];
function addCurve(seg1, seg2, skipLine) {
var point1 = seg1._point,
point2 = seg2._point,
handle1 = seg1._handleOut,
handle2 = seg2._handleIn;
if (handle1.isZero() && handle2.isZero()) {
if (!skipLine) {
parts.push('L' + f.point(point2, precision));
}
} else {
var end = point2.subtract(point1);
parts.push('c' + f.point(handle1, precision)
+ ' ' + f.point(end.add(handle2), precision)
+ ' ' + f.point(end, precision));
}
}
if (segments.length === 0)
return '';
parts.push('M' + f.point(segments[0]._point));
for (var i = 0, l = segments.length - 1; i < l; i++)
addCurve(segments[i], segments[i + 1], false);
if (this._closed) {
addCurve(segments[segments.length - 1], segments[0], true);
parts.push('z');
}
return parts.join('');
},
isClosed: function() { isClosed: function() {
return this._closed; return this._closed;
}, },
@ -6539,7 +6499,44 @@ var Path = PathItem.extend({
} }
this._changed(25); this._changed(25);
} }
}, }
}, {
beans: true,
getPathData: function(_precision) {
var segments = this._segments,
f = Formatter.instance,
parts = [];
function addCurve(seg1, seg2, skipLine) {
var point1 = seg1._point,
point2 = seg2._point,
handle1 = seg1._handleOut,
handle2 = seg2._handleIn;
if (handle1.isZero() && handle2.isZero()) {
if (!skipLine) {
parts.push('L' + f.point(point2, _precision));
}
} else {
var end = point2.subtract(point1);
parts.push('c' + f.point(handle1, _precision)
+ ' ' + f.point(end.add(handle2), _precision)
+ ' ' + f.point(end, _precision));
}
}
if (segments.length === 0)
return '';
parts.push('M' + f.point(segments[0]._point));
for (var i = 0, l = segments.length - 1; i < l; i++)
addCurve(segments[i], segments[i + 1], false);
if (this._closed) {
addCurve(segments[segments.length - 1], segments[0], true);
parts.push('z');
}
return parts.join('');
}
}, {
isEmpty: function() { isEmpty: function() {
return this._segments.length === 0; return this._segments.length === 0;
@ -6839,16 +6836,14 @@ var Path = PathItem.extend({
if (path.closed) if (path.closed)
this._add([segments[0]]); this._add([segments[0]]);
path.remove(); path.remove();
first1 = this.getFirstSegment(); }
last1 = this.getLastSegment(); var first = this.getFirstSegment(),
if (last1._point.equals(first1._point)) { last = this.getLastSegment();
first1.setHandleIn(last1._handleIn); if (first !== last && first._point.equals(last._point)) {
last1.remove(); first.setHandleIn(last._handleIn);
last.remove();
this.setClosed(true); this.setClosed(true);
} }
return true;
}
return false;
}, },
getLength: function() { getLength: function() {
@ -6876,8 +6871,11 @@ var Path = PathItem.extend({
offset = 0; offset = 0;
for (var i = 0; i < index; i++) for (var i = 0; i < index; i++)
offset += curves[i].getLength(); offset += curves[i].getLength();
var curve = curves[index]; var curve = curves[index],
return offset + curve.getLength(0, location.getParameter()); parameter = location.getParameter();
if (parameter > 0)
offset += curve.getPartLength(0, parameter);
return offset;
} }
return null; return null;
}, },
@ -7019,6 +7017,7 @@ var Path = PathItem.extend({
var that = this, var that = this,
style = this.getStyle(), style = this.getStyle(),
segments = this._segments, segments = this._segments,
numSegments = segments.length,
closed = this._closed, closed = this._closed,
tolerancePadding = options._tolerancePadding, tolerancePadding = options._tolerancePadding,
strokePadding = tolerancePadding, strokePadding = tolerancePadding,
@ -7073,7 +7072,7 @@ var Path = PathItem.extend({
if (join !== 'round' || cap !== 'round') { if (join !== 'round' || cap !== 'round') {
area = new Path({ internal: true, closed: true }); area = new Path({ internal: true, closed: true });
if (closed || segment._index > 0 if (closed || segment._index > 0
&& segment._index < segments.length - 1) { && segment._index < numSegments - 1) {
if (join !== 'round' && (segment._handleIn.isZero() if (join !== 'round' && (segment._handleIn.isZero()
|| segment._handleOut.isZero())) || segment._handleOut.isZero()))
Path._addBevelJoin(segment, join, radius, miterLimit, Path._addBevelJoin(segment, join, radius, miterLimit,
@ -7093,10 +7092,10 @@ var Path = PathItem.extend({
if (options.ends && !options.segments && !closed) { if (options.ends && !options.segments && !closed) {
if (res = checkSegmentPoints(segments[0], true) if (res = checkSegmentPoints(segments[0], true)
|| checkSegmentPoints(segments[segments.length - 1], true)) || checkSegmentPoints(segments[numSegments - 1], true))
return res; return res;
} else if (options.segments || options.handles) { } else if (options.segments || options.handles) {
for (var i = 0, l = segments.length; i < l; i++) for (var i = 0; i < numSegments; i++)
if (res = checkSegmentPoints(segments[i])) if (res = checkSegmentPoints(segments[i]))
return res; return res;
} }
@ -7104,15 +7103,15 @@ var Path = PathItem.extend({
loc = this.getNearestLocation(point); loc = this.getNearestLocation(point);
if (loc) { if (loc) {
var parameter = loc.getParameter(); var parameter = loc.getParameter();
if (parameter === 0 || parameter === 1) { if (parameter === 0 || parameter === 1 && numSegments > 1) {
if (!checkSegmentStroke(loc.getSegment())) if (!checkSegmentStroke(loc.getSegment()))
loc = null; loc = null;
} else if (!isCloseEnough(loc.getPoint(), strokePadding)) { } else if (!isCloseEnough(loc.getPoint(), strokePadding)) {
loc = null; loc = null;
} }
} }
if (!loc && join === 'miter') { if (!loc && join === 'miter' && numSegments > 1) {
for (var i = 0, l = segments.length; i < l; i++) { for (var i = 0; i < numSegments; i++) {
var segment = segments[i]; var segment = segments[i];
if (point.getDistance(segment._point) <= miterLimit if (point.getDistance(segment._point) <= miterLimit
&& checkSegmentStroke(segment)) { && checkSegmentStroke(segment)) {
@ -7606,14 +7605,10 @@ var Path = PathItem.extend({
} }
}, },
closePath: function() { closePath: function(join) {
var first = this.getFirstSegment(),
last = this.getLastSegment();
if (first !== last && first._point.equals(last._point)) {
first.setHandleIn(last._handleIn);
last.remove();
}
this.setClosed(true); this.setClosed(true);
if (join)
this.join();
} }
}; };
}, { }, {
@ -8005,7 +8000,7 @@ var CompoundPath = PathItem.extend({
}, },
setClockwise: function(clockwise) { setClockwise: function(clockwise) {
if (this.isClockwise() != !!clockwise) if (this.isClockwise() !== !!clockwise)
this.reverse(); this.reverse();
}, },
@ -8043,16 +8038,18 @@ var CompoundPath = PathItem.extend({
for (var i = 0, l = children.length; i < l; i++) for (var i = 0, l = children.length; i < l; i++)
area += children[i].getArea(); area += children[i].getArea();
return area; return area;
}, }
}, {
beans: true,
getPathData: function(precision) { getPathData: function(_precision) {
var children = this._children, var children = this._children,
paths = []; paths = [];
for (var i = 0, l = children.length; i < l; i++) for (var i = 0, l = children.length; i < l; i++)
paths.push(children[i].getPathData(precision)); paths.push(children[i].getPathData(_precision));
return paths.join(' '); return paths.join(' ');
}, }
}, {
_getChildHitTestOptions: function(options) { _getChildHitTestOptions: function(options) {
return options.type === 'path' return options.type === 'path'
? options ? options
@ -8084,6 +8081,16 @@ var CompoundPath = PathItem.extend({
if (style.hasStroke()) if (style.hasStroke())
ctx.stroke(); ctx.stroke();
} }
},
_drawSelected: function(ctx, matrix) {
var children = this._children;
for (var i = 0, l = children.length; i < l; i++) {
var child = children[i],
mx = child._matrix;
child._drawSelected(ctx, mx.isIdentity() ? matrix
: matrix.clone().concatenate(child._matrix));
}
} }
}, new function() { }, new function() {
function getCurrentPath(that, check) { function getCurrentPath(that, check) {
@ -8109,8 +8116,8 @@ var CompoundPath = PathItem.extend({
this.moveTo(last ? point.add(last._point) : point); this.moveTo(last ? point.add(last._point) : point);
}, },
closePath: function() { closePath: function(join) {
getCurrentPath(this, true).closePath(); getCurrentPath(this, true).closePath(join);
} }
}; };
@ -8133,7 +8140,7 @@ PathItem.inject(new function() {
return path.clone(false).reduce().reorient().transform(null, true); return path.clone(false).reduce().reorient().transform(null, true);
} }
var _path1 = preparePath(path1); var _path1 = preparePath(path1),
_path2 = path2 && path1 !== path2 && preparePath(path2); _path2 = path2 && path1 !== path2 && preparePath(path2);
if (!_path1.isClockwise()) if (!_path1.isClockwise())
_path1.reverse(); _path1.reverse();
@ -8177,7 +8184,7 @@ PathItem.inject(new function() {
} while (segment && !segment._intersection && segment !== startSeg); } while (segment && !segment._intersection && segment !== startSeg);
for (var j = 0; j < 3; j++) { for (var j = 0; j < 3; j++) {
var length = totalLength * Math.random(), var length = totalLength * Math.random(),
amount = lengths.length; amount = lengths.length,
k = 0; k = 0;
do { do {
if (lengths[k] >= length) { if (lengths[k] >= length) {
@ -8435,6 +8442,7 @@ PathItem.inject(new function() {
exclude: function(path) { exclude: function(path) {
return new Group([this.subtract(path), path.subtract(this)]); return new Group([this.subtract(path), path.subtract(this)]);
}, },
divide: function(path) { divide: function(path) {
return new Group([this.subtract(path), this.intersect(path)]); return new Group([this.subtract(path), this.intersect(path)]);
} }
@ -8528,7 +8536,6 @@ Path.inject({
if (!this.contains(point)) { if (!this.contains(point)) {
var curves = this._getMonoCurves(), var curves = this._getMonoCurves(),
roots = [], roots = [],
x = point.x,
y = point.y, y = point.y,
xIntercepts = []; xIntercepts = [];
for (var i = 0, l = curves.length; i < l; i++) { for (var i = 0, l = curves.length; i < l; i++) {
@ -9715,7 +9722,8 @@ var Style = Base.extend(new function() {
_defaults: defaults, _defaults: defaults,
_textDefaults: new Base(defaults, { _textDefaults: new Base(defaults, {
fillColor: new Color() fillColor: new Color()
}) }),
beans: true
}; };
Base.each(defaults, function(value, key) { Base.each(defaults, function(value, key) {
@ -9845,7 +9853,7 @@ var Style = Base.extend(new function() {
getFontStyle: function() { getFontStyle: function() {
var fontSize = this.getFontSize(); var fontSize = this.getFontSize();
return this.getFontWeight() return this.getFontWeight()
+ ' ' + fontSize + (/\w/i.test(fontSize + '') ? ' ' : 'px ') + ' ' + fontSize + (/[a-z]/i.test(fontSize + '') ? ' ' : 'px ')
+ this.getFontFamily(); + this.getFontFamily();
}, },
@ -11244,8 +11252,11 @@ new function() {
function exportSVG(item, options) { function exportSVG(item, options) {
var exporter = exporters[item._class], var exporter = exporters[item._class],
node = exporter && exporter(item, options); node = exporter && exporter(item, options);
if (node && item._data) if (node && item._data) {
node.setAttribute('data-paper-data', JSON.stringify(item._data)); var data = JSON.stringify(item._data);
if (data !== '{}')
node.setAttribute('data-paper-data', data);
}
return node && applyStyle(item, node); return node && applyStyle(item, node);
} }
@ -11340,7 +11351,6 @@ new function() {
currentStyle = project._currentStyle, currentStyle = project._currentStyle,
children = []; children = [];
if (!isClip) { if (!isClip) {
item._applyMatrix = false;
item = applyAttributes(item, node, isRoot); item = applyAttributes(item, node, isRoot);
project._currentStyle = item._style.clone(); project._currentStyle = item._style.clone();
} }
@ -11386,6 +11396,12 @@ new function() {
} }
function importGradient(node, type) { function importGradient(node, type) {
var id = (getValue(node, 'href', true) || '').substring(1),
isRadial = type === 'radialgradient',
gradient;
if (id) {
gradient = definitions[id].getGradient();
} else {
var nodes = node.childNodes, var nodes = node.childNodes,
stops = []; stops = [];
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
@ -11393,9 +11409,9 @@ new function() {
if (child.nodeType === 1) if (child.nodeType === 1)
stops.push(applyAttributes(new GradientStop(), child)); stops.push(applyAttributes(new GradientStop(), child));
} }
var isRadial = type === 'radialgradient', gradient = new Gradient(stops, isRadial);
gradient = new Gradient(stops, isRadial), }
origin, destination, highlight; var origin, destination, highlight;
if (isRadial) { if (isRadial) {
origin = getPoint(node, 'cx', 'cy'); origin = getPoint(node, 'cx', 'cy');
destination = origin.add(getValue(node, 'r'), 0); destination = origin.add(getValue(node, 'r'), 0);
@ -11693,8 +11709,13 @@ new function() {
throw new Error('Unsupported SVG source: ' + source); throw new Error('Unsupported SVG source: ' + source);
var type = node.nodeName.toLowerCase(), var type = node.nodeName.toLowerCase(),
importer = importers[type], importer = importers[type],
item = importer && importer(node, type, isRoot, options) || null, item,
data = node.getAttribute && node.getAttribute('data-paper-data'); data = node.getAttribute && node.getAttribute('data-paper-data'),
settings = scope.settings,
prevApplyMatrix = settings.applyMatrix;
settings.applyMatrix = false;
item = importer && importer(node, type, isRoot, options) || null;
settings.applyMatrix = prevApplyMatrix;
if (item) { if (item) {
if (!(item instanceof Group)) if (!(item instanceof Group))
item = applyAttributes(item, node, isRoot); item = applyAttributes(item, node, isRoot);

View file

@ -1,6 +1,6 @@
{ {
"name": "paper", "name": "paper",
"version": "0.9.17", "version": "0.9.18",
"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",

View file

@ -16,7 +16,7 @@
var __options = { var __options = {
parser: 'acorn', parser: 'acorn',
version: '0.9.17', version: '0.9.18',
environment: 'browser', environment: 'browser',
legacy: true, legacy: true,
stats: true, stats: true,