255){var u=255-r,l=o-r;d=r+(d-r)*u/l,_=r+(_-r)*u/l,g=r+(g-r)*u/l}}function i(t,e,i){return p(t,e,i)-v(t,e,i)}function n(t,e,i,n){var r,s=[t,e,i],a=p(t,e,i),o=v(t,e,i);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,r=0===v(o,a)?1===p(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*n/(s[a]-s[o]),s[a]=n):s[r]=s[a]=0,s[o]=0,d=s[0],_=s[1],g=s[2]}var s,a,o,h,u,l,c,f,d,_,g,v=Math.min,p=Math.max,m=Math.abs,y={multiply:function(){d=u*s/255,_=l*a/255,g=c*o/255},screen:function(){d=u+s-u*s/255,_=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){d=u<128?2*u*s/255:255-2*(255-u)*(255-s)/255,_=l<128?2*l*a/255:255-2*(255-l)*(255-a)/255,g=c<128?2*c*o/255:255-2*(255-c)*(255-o)/255},"soft-light":function(){var t=s*u/255;d=t+u*(255-(255-u)*(255-s)/255-t)/255,t=a*l/255,_=t+l*(255-(255-l)*(255-a)/255-t)/255,t=o*c/255,g=t+c*(255-(255-c)*(255-o)/255-t)/255},"hard-light":function(){d=s<128?2*s*u/255:255-2*(255-s)*(255-u)/255,_=a<128?2*a*l/255:255-2*(255-a)*(255-l)/255,g=o<128?2*o*c/255:255-2*(255-o)*(255-c)/255},"color-dodge":function(){d=0===u?0:255===s?255:v(255,255*u/(255-s)),_=0===l?0:255===a?255:v(255,255*l/(255-a)),g=0===c?0:255===o?255:v(255,255*c/(255-o))},"color-burn":function(){d=255===u?255:0===s?0:p(0,255-255*(255-u)/s),_=255===l?255:0===a?0:p(0,255-255*(255-l)/a),g=255===c?255:0===o?0:p(0,255-255*(255-c)/o)},darken:function(){d=us?u:s,_=l>a?l:a,g=c>o?c:o},difference:function(){d=u-s,d<0&&(d=-d),_=l-a,_<0&&(_=-_),g=c-o,g<0&&(g=-g)},exclusion:function(){d=u+s*(255-u-u)/255,_=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){n(s,a,o,i(u,l,c)),e(d,_,g,t(u,l,c))},saturation:function(){n(u,l,c,i(s,a,o)),e(d,_,g,t(u,l,c))},luminosity:function(){e(u,l,c,t(s,a,o))},color:function(){e(s,a,o,t(u,l,c))},add:function(){d=v(u+s,255),_=v(l+a,255),g=v(c+o,255)},subtract:function(){d=p(u-s,0),_=p(l-a,0),g=p(c-o,0)},average:function(){d=(u+s)/2,_=(l+a)/2,g=(c+o)/2},negation:function(){d=255-m(255-s-u),_=255-m(255-a-l),g=255-m(255-o-c)}},w=this.nativeModes=r.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=et.getContext(1,1);x&&(r.each(y,function(t,e){var i="darken"===e,n=!1;x.save();try{x.fillStyle=i?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=i?"#a00":"#300",x.fillRect(0,0,1,1),n=x.getImageData(0,0,1,1).data[0]!==i?170:51)}catch(r){}x.restore(),w[e]=n}),et.release(x)),this.process=function(t,e,i,n,r){var v=e.canvas,p="normal"===t;if(p||w[t])i.save(),i.setTransform(1,0,0,1,0,0),i.globalAlpha=n,p||(i.globalCompositeOperation=t),i.drawImage(v,r.x,r.y),i.restore();else{var m=y[t];if(!m)return;for(var x=i.getImageData(r.x,r.y,v.width,v.height),b=x.data,C=e.getImageData(0,0,v.width,v.height).data,S=0,P=b.length;S=2&&!t.hasHandles())if(h>2){s=t._closed?"polygon":"polyline";for(var l=[],c=0;c>> 1;
+ if (allBounds[indices[mid]][coord] < value) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
+ }
+ return lo - 1;
+ }
+
+ var pri0 = sweepVertical ? 1 : 0,
+ pri1 = pri0 + 2,
+ sec0 = sweepVertical ? 0 : 1,
+ sec1 = sec0 + 2;
+ var allIndicesByPri0 = new Array(lengthAll);
+ for (var i = 0; i < lengthAll; i++) {
+ allIndicesByPri0[i] = i;
+ }
+ allIndicesByPri0.sort(function(i1, i2) {
+ return allBounds[i1][pri0] - allBounds[i2][pri0];
+ });
+ var activeIndicesByPri1 = [],
+ allCollisions = new Array(lengthA);
+ for (var i = 0; i < lengthAll; i++) {
+ var curIndex = allIndicesByPri0[i],
+ curBounds = allBounds[curIndex],
+ origIndex = self ? curIndex : curIndex - lengthA,
+ isCurrentA = curIndex < lengthA,
+ isCurrentB = self || !isCurrentA,
+ curCollisions = isCurrentA ? [] : null;
+ if (activeIndicesByPri1.length) {
+ var pruneCount = binarySearch(activeIndicesByPri1, pri1,
+ curBounds[pri0] - tolerance) + 1;
+ activeIndicesByPri1.splice(0, pruneCount);
+ if (self && onlySweepAxisCollisions) {
+ curCollisions = curCollisions.concat(activeIndicesByPri1);
+ for (var j = 0; j < activeIndicesByPri1.length; j++) {
+ var activeIndex = activeIndicesByPri1[j];
+ allCollisions[activeIndex].push(origIndex);
+ }
+ } else {
+ var curSec1 = curBounds[sec1],
+ curSec0 = curBounds[sec0];
+ for (var j = 0; j < activeIndicesByPri1.length; j++) {
+ var activeIndex = activeIndicesByPri1[j],
+ activeBounds = allBounds[activeIndex],
+ isActiveA = activeIndex < lengthA,
+ isActiveB = self || activeIndex >= lengthA;
+
+ if (
+ onlySweepAxisCollisions ||
+ (
+ isCurrentA && isActiveB ||
+ isCurrentB && isActiveA
+ ) && (
+ curSec1 >= activeBounds[sec0] - tolerance &&
+ curSec0 <= activeBounds[sec1] + tolerance
+ )
+ ) {
+ if (isCurrentA && isActiveB) {
+ curCollisions.push(
+ self ? activeIndex : activeIndex - lengthA);
+ }
+ if (isCurrentB && isActiveA) {
+ allCollisions[activeIndex].push(origIndex);
+ }
+ }
+ }
+ }
+ }
+ if (isCurrentA) {
+ if (boundsA === boundsB) {
+ curCollisions.push(curIndex);
+ }
+ allCollisions[curIndex] = curCollisions;
+ }
+ if (activeIndicesByPri1.length) {
+ var curPri1 = curBounds[pri1],
+ index = binarySearch(activeIndicesByPri1, pri1, curPri1);
+ activeIndicesByPri1.splice(index + 1, 0, curIndex);
+ } else {
+ activeIndicesByPri1.push(curIndex);
+ }
+ }
+ for (var i = 0; i < allCollisions.length; i++) {
+ var collisions = allCollisions[i];
+ if (collisions) {
+ collisions.sort(function(i1, i2) { return i1 - i2; });
+ }
+ }
+ return allCollisions;
+ }
+};
+
var Formatter = Base.extend({
initialize: function(precision) {
this.precision = Base.pick(precision, 5);
@@ -1025,6 +1227,10 @@ var Numerical = new function() {
return val >= -EPSILON && val <= EPSILON;
},
+ isMachineZero: function(val) {
+ return val >= -MACHINE_EPSILON && val <= MACHINE_EPSILON;
+ },
+
clamp: clamp,
integrate: function(f, a, b, n) {
@@ -1319,11 +1525,12 @@ var Point = Base.extend({
},
getDistance: function() {
- var point = Point.read(arguments),
+ var args = arguments,
+ point = Point.read(args),
x = point.x - this.x,
y = point.y - this.y,
d = x * x + y * y,
- squared = Base.read(arguments);
+ squared = Base.read(args);
return squared ? d : Math.sqrt(d);
},
@@ -1390,8 +1597,9 @@ var Point = Base.extend({
},
isClose: function() {
- var point = Point.read(arguments),
- tolerance = Base.read(arguments);
+ var args = arguments,
+ point = Point.read(args),
+ tolerance = Base.read(args);
return this.getDistance(point) <= tolerance;
},
@@ -1442,8 +1650,9 @@ var Point = Base.extend({
statics: {
min: function() {
- var point1 = Point.read(arguments),
- point2 = Point.read(arguments);
+ var args = arguments,
+ point1 = Point.read(args),
+ point2 = Point.read(args);
return new Point(
Math.min(point1.x, point2.x),
Math.min(point1.y, point2.y)
@@ -1451,8 +1660,9 @@ var Point = Base.extend({
},
max: function() {
- var point1 = Point.read(arguments),
- point2 = Point.read(arguments);
+ var args = arguments,
+ point1 = Point.read(args),
+ point2 = Point.read(args);
return new Point(
Math.max(point1.x, point2.x),
Math.max(point1.y, point2.y)
@@ -1699,7 +1909,8 @@ var Rectangle = Base.extend({
beans: true,
initialize: function Rectangle(arg0, arg1, arg2, arg3) {
- var type = typeof arg0,
+ var args = arguments,
+ type = typeof arg0,
read;
if (type === 'number') {
this._set(arg0, arg1, arg2, arg3);
@@ -1707,7 +1918,7 @@ var Rectangle = Base.extend({
} else if (type === 'undefined' || arg0 === null) {
this._set(0, 0, 0, 0);
read = arg0 === null ? 1 : 0;
- } else if (arguments.length === 1) {
+ } else if (args.length === 1) {
if (Array.isArray(arg0)) {
this._set.apply(this, arg0);
read = 1;
@@ -1717,20 +1928,20 @@ var Rectangle = Base.extend({
read = 1;
} else if (arg0.from === undefined && arg0.to === undefined) {
this._set(0, 0, 0, 0);
- Base.filter(this, arg0);
- read = 1;
+ if (Base.readSupported(args, this)) {
+ read = 1;
+ }
}
}
if (read === undefined) {
- var frm = Point.readNamed(arguments, 'from'),
- next = Base.peek(arguments),
+ var frm = Point.readNamed(args, 'from'),
+ next = Base.peek(args),
x = frm.x,
y = frm.y,
width,
height;
- if (next && next.x !== undefined
- || Base.hasNamed(arguments, 'to')) {
- var to = Point.readNamed(arguments, 'to');
+ if (next && next.x !== undefined || Base.hasNamed(args, 'to')) {
+ var to = Point.readNamed(args, 'to');
width = to.x - x;
height = to.y - y;
if (width < 0) {
@@ -1742,16 +1953,16 @@ var Rectangle = Base.extend({
height = -height;
}
} else {
- var size = Size.read(arguments);
+ var size = Size.read(args);
width = size.width;
height = size.height;
}
this._set(x, y, width, height);
- read = arguments.__index;
- var filtered = arguments.__filtered;
- if (filtered)
- this.__filtered = filtered;
+ read = args.__index;
}
+ var filtered = args.__filtered;
+ if (filtered)
+ this.__filtered = filtered;
if (this.__read)
this.__read = read;
return this;
@@ -2109,10 +2320,11 @@ var Matrix = Base.extend({
_class: 'Matrix',
initialize: function Matrix(arg, _dontNotify) {
- var count = arguments.length,
+ var args = arguments,
+ count = args.length,
ok = true;
if (count >= 6) {
- this._set.apply(this, arguments);
+ this._set.apply(this, args);
} else if (count === 1 || count === 2) {
if (arg instanceof Matrix) {
this._set(arg._a, arg._b, arg._c, arg._d, arg._tx, arg._ty,
@@ -2158,7 +2370,7 @@ var Matrix = Base.extend({
if (owner._applyMatrix) {
owner.transform(null, true);
} else {
- owner._changed(9);
+ owner._changed(25);
}
}
},
@@ -2193,8 +2405,7 @@ var Matrix = Base.extend({
apply: function(recursively, _setApplyMatrix) {
var owner = this._owner;
if (owner) {
- owner.transform(null, true, Base.pick(recursively, true),
- _setApplyMatrix);
+ owner.transform(null, Base.pick(recursively, true), _setApplyMatrix);
return this.isIdentity();
}
return false;
@@ -2211,8 +2422,9 @@ var Matrix = Base.extend({
},
scale: function() {
- var scale = Point.read(arguments),
- center = Point.read(arguments, 0, { readNull: true });
+ var args = arguments,
+ scale = Point.read(args),
+ center = Point.read(args, 0, { readNull: true });
if (center)
this.translate(center);
this._a *= scale.x;
@@ -2249,8 +2461,9 @@ var Matrix = Base.extend({
},
shear: function() {
- var shear = Point.read(arguments),
- center = Point.read(arguments, 0, { readNull: true });
+ var args = arguments,
+ shear = Point.read(args),
+ center = Point.read(args, 0, { readNull: true });
if (center)
this.translate(center);
var a = this._a,
@@ -2266,8 +2479,9 @@ var Matrix = Base.extend({
},
skew: function() {
- var skew = Point.read(arguments),
- center = Point.read(arguments, 0, { readNull: true }),
+ var args = arguments,
+ skew = Point.read(args),
+ center = Point.read(args, 0, { readNull: true }),
toRadians = Math.PI / 180,
shear = new Point(Math.tan(skew.x * toRadians),
Math.tan(skew.y * toRadians));
@@ -2507,11 +2721,11 @@ var Matrix = Base.extend({
},
getScaling: function() {
- return (this.decompose() || {}).scaling;
+ return this.decompose().scaling;
},
getRotation: function() {
- return (this.decompose() || {}).rotation;
+ return this.decompose().rotation;
},
applyToContext: function(ctx) {
@@ -2608,7 +2822,7 @@ var Line = Base.extend({
v2y -= p2y;
}
var cross = v1x * v2y - v1y * v2x;
- if (!Numerical.isZero(cross)) {
+ if (!Numerical.isMachineZero(cross)) {
var dx = p1x - p2x,
dy = p1y - p2y,
u1 = (v2x * dy - v2y * dx) / cross,
@@ -2636,7 +2850,7 @@ var Line = Base.extend({
var v2x = x - px,
v2y = y - py,
ccw = v2x * vy - v2y * vx;
- if (!isInfinite && Numerical.isZero(ccw)) {
+ if (!isInfinite && Numerical.isMachineZero(ccw)) {
ccw = (v2x * vx + v2x * vx) / (vx * vx + vy * vy);
if (ccw >= 0 && ccw <= 1)
ccw = 0;
@@ -2649,9 +2863,13 @@ var Line = Base.extend({
vx -= px;
vy -= py;
}
- return vx === 0 ? vy > 0 ? x - px : px - x
- : vy === 0 ? vx < 0 ? y - py : py - y
- : ((x-px) * vy - (y-py) * vx) / Math.sqrt(vx * vx + vy * vy);
+ return vx === 0 ? (vy > 0 ? x - px : px - x)
+ : vy === 0 ? (vx < 0 ? y - py : py - y)
+ : ((x - px) * vy - (y - py) * vx) / (
+ vy > vx
+ ? vy * Math.sqrt(1 + (vx * vx) / (vy * vy))
+ : vx * Math.sqrt(1 + (vy * vy) / (vx * vx))
+ );
},
getDistance: function(px, py, vx, vy, x, y, asVector) {
@@ -3046,11 +3264,13 @@ new function() {
cacheParent = this._parent || symbol,
project = this._project;
if (flags & 8) {
- this._bounds = this._position = this._decomposed =
- this._globalMatrix = undefined;
+ this._bounds = this._position = this._decomposed = undefined;
+ }
+ if (flags & 16) {
+ this._globalMatrix = undefined;
}
if (cacheParent
- && (flags & 40)) {
+ && (flags & 72)) {
Item._clearBoundsCache(cacheParent);
}
if (flags & 2) {
@@ -3086,7 +3306,7 @@ new function() {
children[name] = this;
}
this._name = name || undefined;
- this._changed(128);
+ this._changed(256);
},
getStyle: function() {
@@ -3101,8 +3321,8 @@ new function() {
var part = Base.capitalize(name),
key = '_' + name,
flags = {
- locked: 128,
- visible: 137
+ locked: 256,
+ visible: 265
};
this['get' + part] = function() {
return this[key];
@@ -3110,7 +3330,7 @@ new function() {
this['set' + part] = function(value) {
if (value != this[key]) {
this[key] = value;
- this._changed(flags[name] || 129);
+ this._changed(flags[name] || 257);
}
};
},
@@ -3127,7 +3347,7 @@ new function() {
var project = this._project;
if (project) {
project._updateSelection(this);
- this._changed(129);
+ this._changed(257);
}
}
},
@@ -3188,9 +3408,9 @@ new function() {
this.setFillColor(null);
this.setStrokeColor(null);
}
- this._changed(129);
+ this._changed(257);
if (this._parent)
- this._parent._changed(1024);
+ this._parent._changed(2048);
}
},
@@ -3205,14 +3425,9 @@ new function() {
},
getPosition: function(_dontLink) {
- var position = this._position,
- ctor = _dontLink ? Point : LinkedPoint;
- if (!position) {
- var pivot = this._pivot;
- position = this._position = pivot
- ? this._matrix._transformPoint(pivot)
- : this.getBounds().getCenter(true);
- }
+ var ctor = _dontLink ? Point : LinkedPoint;
+ var position = this._position ||
+ (this._position = this._getPositionFromBounds());
return new ctor(position.x, position.y, this, 'setPosition');
},
@@ -3220,6 +3435,12 @@ new function() {
this.translate(Point.read(arguments).subtract(this.getPosition(true)));
},
+ _getPositionFromBounds: function(bounds) {
+ return this._pivot
+ ? this._matrix._transformPoint(this._pivot)
+ : (bounds || this.getBounds()).getCenter(true);
+ },
+
getPivot: function() {
var pivot = this._pivot;
return pivot
@@ -3234,7 +3455,8 @@ new function() {
}, Base.each({
getStrokeBounds: { stroke: true },
getHandleBounds: { handle: true },
- getInternalBounds: { internal: true }
+ getInternalBounds: { internal: true },
+ getDrawnBounds: { stroke: true, drawnTextBounds: true },
},
function(options, key) {
this[key] = function(matrix) {
@@ -3291,6 +3513,7 @@ new function() {
return [
options.stroke ? 1 : 0,
options.handle ? 1 : 0,
+ options.drawnTextBounds? 1 : 0,
internal ? 1 : 0
].join('');
},
@@ -3379,7 +3602,7 @@ new function() {
options = options || {};
for (var i = 0, l = items.length; i < l; i++) {
var item = items[i];
- if (item._visible && !item.isEmpty()) {
+ if (item._visible && !item.isEmpty(true)) {
var bounds = item._getCachedBounds(
matrix && matrix.appended(item._matrix), options, true),
rect = bounds.rect;
@@ -3465,16 +3688,27 @@ new function() {
},
getGlobalMatrix: function(_dontClone) {
- var matrix = this._globalMatrix,
- updateVersion = this._project._updateVersion;
- if (matrix && matrix._updateVersion !== updateVersion)
- matrix = null;
+ var matrix = this._globalMatrix;
+ if (matrix) {
+ var parent = this._parent;
+ var parents = [];
+ while (parent) {
+ if (!parent._globalMatrix) {
+ matrix = null;
+ for (var i = 0, l = parents.length; i < l; i++) {
+ parents[i]._globalMatrix = null;
+ }
+ break;
+ }
+ parents.push(parent);
+ parent = parent._parent;
+ }
+ }
if (!matrix) {
matrix = this._globalMatrix = this._matrix.clone();
var parent = this._parent;
if (parent)
matrix.prepend(parent.getGlobalMatrix(true));
- matrix._updateVersion = updateVersion;
}
return _dontClone ? matrix : matrix.clone();
},
@@ -3649,8 +3883,8 @@ new function() {
this.setName(name);
},
- rasterize: function(resolution, insert) {
- var bounds = this.getStrokeBounds(),
+ rasterize: function(resolution, insert, boundRect) {
+ var bounds = boundRect ? boundRect : this.getStrokeBounds(),
scale = (resolution || this.getView().getResolution()) / 72,
topLeft = bounds.getTopLeft().floor(),
bottomRight = bounds.getBottomRight().ceil(),
@@ -3660,6 +3894,7 @@ new function() {
var canvas = CanvasProvider.getCanvas(size.multiply(scale)),
ctx = canvas.getContext('2d'),
matrix = new Matrix().scale(scale).translate(topLeft.negate());
+ ctx.imageSmoothingEnabled = false;
ctx.save();
matrix.applyToContext(ctx);
this.draw(ctx, new Base({ matrices: [matrix] }));
@@ -3674,8 +3909,11 @@ new function() {
},
contains: function() {
- return !!this._contains(
- this._matrix._inverseTransform(Point.read(arguments)));
+ var matrix = this._matrix;
+ return (
+ matrix.isInvertible() &&
+ !!this._contains(matrix._inverseTransform(Point.read(arguments)))
+ );
},
_contains: function(point) {
@@ -3711,16 +3949,18 @@ new function() {
},
new function() {
function hitTest() {
+ var args = arguments;
return this._hitTest(
- Point.read(arguments),
- HitResult.getOptions(arguments));
+ Point.read(args),
+ HitResult.getOptions(args));
}
function hitTestAll() {
- var point = Point.read(arguments),
- options = HitResult.getOptions(arguments),
+ var args = arguments,
+ point = Point.read(args),
+ options = HitResult.getOptions(args),
all = [];
- this._hitTest(point, Base.set({ all: all }, options));
+ this._hitTest(point, new Base({ all: all }, options));
return all;
}
@@ -4099,6 +4339,8 @@ new function() {
var owner = this._getOwner(),
project = this._project,
index = this._index;
+ if (this._style)
+ this._style._dispose();
if (owner) {
if (this._name)
this._removeNamed();
@@ -4155,9 +4397,18 @@ new function() {
}
},
- isEmpty: function() {
+ isEmpty: function(recursively) {
var children = this._children;
- return !children || !children.length;
+ var numChildren = children ? children.length : 0;
+ if (recursively) {
+ for (var i = 0; i < numChildren; i++) {
+ if (!children[i].isEmpty(recursively)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return !numChildren;
},
isEditable: function() {
@@ -4256,8 +4507,9 @@ new function() {
}, Base.each(['rotate', 'scale', 'shear', 'skew'], function(key) {
var rotate = key === 'rotate';
this[key] = function() {
- var value = (rotate ? Base : Point).read(arguments),
- center = Point.read(arguments, 0, { readNull: true });
+ var args = arguments,
+ value = (rotate ? Base : Point).read(args),
+ center = Point.read(args, 0, { readNull: true });
return this.transform(new Matrix()[key](value,
center || this.getPosition(true)));
};
@@ -4267,16 +4519,19 @@ new function() {
return this.transform(mx.translate.apply(mx, arguments));
},
- transform: function(matrix, _applyMatrix, _applyRecursively,
- _setApplyMatrix) {
+ transform: function(matrix, _applyRecursively, _setApplyMatrix) {
var _matrix = this._matrix,
- transform = matrix && !matrix.isIdentity(),
- applyMatrix = (_applyMatrix || this._applyMatrix)
- && ((!_matrix.isIdentity() || transform)
- || _applyMatrix && _applyRecursively && this._children);
- if (!transform && !applyMatrix)
+ transformMatrix = matrix && !matrix.isIdentity(),
+ applyMatrix = (
+ _setApplyMatrix && this._canApplyMatrix ||
+ this._applyMatrix && (
+ transformMatrix || !_matrix.isIdentity() ||
+ _applyRecursively && this._children
+ )
+ );
+ if (!transformMatrix && !applyMatrix)
return this;
- if (transform) {
+ if (transformMatrix) {
if (!matrix.isInvertible() && _matrix.isInvertible())
_matrix._backup = _matrix.getValues();
_matrix.prepend(matrix, true);
@@ -4288,8 +4543,9 @@ new function() {
if (strokeColor)
strokeColor.transform(matrix);
}
- if (applyMatrix && (applyMatrix = this._transformContent(_matrix,
- _applyRecursively, _setApplyMatrix))) {
+
+ if (applyMatrix && (applyMatrix = this._transformContent(
+ _matrix, _applyRecursively, _setApplyMatrix))) {
var pivot = this._pivot;
if (pivot)
_matrix._transformPoint(pivot, pivot, true);
@@ -4299,10 +4555,10 @@ new function() {
}
var bounds = this._bounds,
position = this._position;
- if (transform || applyMatrix) {
- this._changed(9);
+ if (transformMatrix || applyMatrix) {
+ this._changed(25);
}
- var decomp = transform && bounds && matrix.decompose();
+ var decomp = transformMatrix && bounds && matrix.decompose();
if (decomp && decomp.skewing.isZero() && decomp.rotation % 90 === 0) {
for (var key in bounds) {
var cache = bounds[key];
@@ -4315,11 +4571,11 @@ new function() {
}
this._bounds = bounds;
var cached = bounds[this._getBoundsCacheKey(
- this._boundsOptions || {})];
+ this._boundsOptions || {})];
if (cached) {
- this._position = cached.rect.getCenter(true);
+ this._position = this._getPositionFromBounds(cached.rect);
}
- } else if (transform && position && this._pivot) {
+ } else if (transformMatrix && position && this._pivot) {
this._position = matrix._transformPoint(position, position);
}
return this;
@@ -4328,9 +4584,9 @@ new function() {
_transformContent: function(matrix, applyRecursively, setApplyMatrix) {
var children = this._children;
if (children) {
- for (var i = 0, l = children.length; i < l; i++)
- children[i].transform(matrix, true, applyRecursively,
- setApplyMatrix);
+ for (var i = 0, l = children.length; i < l; i++) {
+ children[i].transform(matrix, applyRecursively, setApplyMatrix);
+ }
return true;
}
},
@@ -4368,14 +4624,14 @@ new function() {
}
}), {
- _setStyles: function(ctx, param, viewMatrix) {
+ _setStyles: function(ctx, param, viewMatrix, strokeMatrix) {
var style = this._style,
matrix = this._matrix;
if (style.hasFill()) {
- ctx.fillStyle = style.getFillColor().toCanvasStyle(ctx, matrix);
+ ctx.fillStyle = style.getFillColor().toCanvasStyle(ctx, matrix, strokeMatrix);
}
if (style.hasStroke()) {
- ctx.strokeStyle = style.getStrokeColor().toCanvasStyle(ctx, matrix);
+ ctx.strokeStyle = style.getStrokeColor().toCanvasStyle(ctx, matrix, strokeMatrix);
ctx.lineWidth = style.getStrokeWidth();
var strokeJoin = style.getStrokeJoin(),
strokeCap = style.getStrokeCap(),
@@ -4429,12 +4685,11 @@ new function() {
matrices.push(globalMatrix);
if (param.updateMatrix) {
- globalMatrix._updateVersion = updateVersion;
this._globalMatrix = globalMatrix;
}
var blendMode = this._blendMode,
- opacity = this._opacity,
+ opacity = Numerical.clamp(this._opacity, 0, 1),
normalBlend = blendMode === 'normal',
nativeBlend = BlendMode.nativeModes[blendMode],
direct = normalBlend && opacity === 1
@@ -4446,8 +4701,10 @@ new function() {
mainCtx, itemOffset, prevOffset;
if (!direct) {
var bounds = this.getStrokeBounds(viewMatrix);
- if (!bounds.width || !bounds.height)
+ if (!bounds.width || !bounds.height) {
+ matrices.pop();
return;
+ }
prevOffset = param.offset;
itemOffset = param.offset = bounds.getTopLeft().floor();
mainCtx = ctx;
@@ -4485,8 +4742,9 @@ new function() {
this._draw(ctx, param, viewMatrix, strokeMatrix);
ctx.restore();
matrices.pop();
- if (param.clip && !param.dontFinish)
- ctx.clip();
+ if (param.clip && !param.dontFinish) {
+ ctx.clip(this.getFillRule());
+ }
if (!direct) {
BlendMode.process(blendMode, ctx, mainCtx, opacity,
itemOffset.subtract(prevOffset).multiply(pixelRatio));
@@ -4525,10 +4783,13 @@ new function() {
half = size / 2;
ctx.strokeStyle = ctx.fillStyle = color
? color.toCanvasStyle(ctx) : '#009dec';
+ ctx.lineWidth=2.5;
if (itemSelected)
this._drawSelected(ctx, mx, selectionItems);
if (positionSelected) {
- var point = this.getPosition(true),
+ var pos = this.getPosition(true),
+ parent = this._parent,
+ point = parent ? parent.localToGlobal(pos) : pos,
x = point.x,
y = point.y;
ctx.beginPath();
@@ -4585,7 +4846,43 @@ new function() {
}
return this;
}
-}));
+}), {
+ tween: function(from, to, options) {
+ if (!options) {
+ 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;
+ },
+
+ tweenTo: function(to, options) {
+ return this.tween(null, to, options);
+ },
+
+ tweenFrom: function(from, options) {
+ return this.tween(from, null, options);
+ }
+});
var Group = Item.extend({
_class: 'Group',
@@ -4604,7 +4901,7 @@ var Group = Item.extend({
_changed: function _changed(flags) {
_changed.base.call(this, flags);
- if (flags & 1026) {
+ if (flags & 2050) {
this._clipItem = undefined;
}
},
@@ -4638,8 +4935,7 @@ var Group = Item.extend({
_getBounds: function _getBounds(matrix, options) {
var clipItem = this._getClipItem();
return clipItem
- ? clipItem._getCachedBounds(
- matrix && matrix.appended(clipItem._matrix),
+ ? clipItem._getCachedBounds(clipItem._matrix.prepended(matrix),
Base.set({}, options, { stroke: false }))
: _getBounds.base.call(this, matrix, options);
},
@@ -4745,7 +5041,7 @@ var Shape = Item.extend({
width = size.width,
height = size.height;
if (type === 'rectangle') {
- this._radius.set(Size.min(this._radius, size.divide(2)));
+ this._radius.set(Size.min(this._radius, size.divide(2).abs()));
} else if (type === 'circle') {
width = height = (width + height) / 2;
this._radius = width / 2;
@@ -4880,7 +5176,7 @@ var Shape = Item.extend({
ctx.closePath();
}
if (!dontPaint && (hasFill || hasStroke)) {
- this._setStyles(ctx, param, viewMatrix);
+ this._setStyles(ctx, param, viewMatrix, strokeMatrix);
if (hasFill) {
ctx.fill(style.getFillRule());
ctx.shadowColor = 'rgba(0,0,0,0)';
@@ -4983,34 +5279,38 @@ new function() {
statics: new function() {
function createShape(type, point, size, radius, args) {
- var item = new Shape(Base.getNamed(args), point);
+ var item = Base.create(Shape.prototype);
item._type = type;
item._size = size;
item._radius = radius;
+ item._initialize(Base.getNamed(args), point);
return item;
}
return {
Circle: function() {
- var center = Point.readNamed(arguments, 'center'),
- radius = Base.readNamed(arguments, 'radius');
+ var args = arguments,
+ center = Point.readNamed(args, 'center'),
+ radius = Base.readNamed(args, 'radius');
return createShape('circle', center, new Size(radius * 2), radius,
- arguments);
+ args);
},
Rectangle: function() {
- var rect = Rectangle.readNamed(arguments, 'rectangle'),
- radius = Size.min(Size.readNamed(arguments, 'radius'),
+ var args = arguments,
+ rect = Rectangle.readNamed(args, 'rectangle'),
+ radius = Size.min(Size.readNamed(args, 'radius'),
rect.getSize(true).divide(2));
return createShape('rectangle', rect.getCenter(true),
- rect.getSize(true), radius, arguments);
+ rect.getSize(true), radius, args);
},
Ellipse: function() {
- var ellipse = Shape._readEllipse(arguments),
+ var args = arguments,
+ ellipse = Shape._readEllipse(args),
radius = ellipse.radius;
return createShape('ellipse', ellipse.center, radius.multiply(2),
- radius, arguments);
+ radius, args);
},
_readEllipse: function(args) {
@@ -5039,16 +5339,33 @@ var Raster = Item.extend({
source: null
},
_prioritize: ['crossOrigin'],
+ _smoothing: false,
+ beans: true,
- initialize: function Raster(object, position) {
- if (!this._initialize(object,
- position !== undefined && Point.read(arguments, 1))) {
- var image = typeof object === 'string'
- ? document.getElementById(object) : object;
+ initialize: function Raster(source, position) {
+ if (!this._initialize(source,
+ position !== undefined && Point.read(arguments))) {
+ var image,
+ type = typeof source,
+ object = type === 'string'
+ ? document.getElementById(source)
+ : type === 'object'
+ ? source
+ : null;
+ if (object && object !== Item.NO_INSERT) {
+ if (object.getContext || object.naturalHeight != null) {
+ image = object;
+ } else if (object) {
+ var size = Size.read(arguments);
+ if (!size.isZero()) {
+ image = CanvasProvider.getCanvas(size);
+ }
+ }
+ }
if (image) {
this.setImage(image);
} else {
- this.setSource(object);
+ this.setSource(source);
}
}
if (!this._size) {
@@ -5181,7 +5498,7 @@ var Raster = Item.extend({
image ? image.naturalWidth || image.width : 0,
image ? image.naturalHeight || image.height : 0);
this._context = null;
- this._changed(521);
+ this._changed(1033);
},
getCanvas: function() {
@@ -5200,12 +5517,12 @@ var Raster = Item.extend({
setCanvas: '#setImage',
- getContext: function(modify) {
+ getContext: function(_change) {
if (!this._context)
this._context = this.getCanvas().getContext('2d');
- if (modify) {
+ if (_change) {
this._image = null;
- this._changed(513);
+ this._changed(1025);
}
return this._context;
},
@@ -5224,7 +5541,8 @@ var Raster = Item.extend({
crossOrigin = this._crossOrigin;
if (crossOrigin)
image.crossOrigin = crossOrigin;
- image.src = src;
+ if (src)
+ image.src = src;
this.setImage(image);
},
@@ -5240,6 +5558,15 @@ var Raster = Item.extend({
image.crossOrigin = crossOrigin;
},
+ getSmoothing: function() {
+ return this._smoothing;
+ },
+
+ setSmoothing: function(smoothing) {
+ this._smoothing = smoothing;
+ this._changed(257);
+ },
+
getElement: function() {
return this._canvas || this._loaded && this._image;
}
@@ -5249,8 +5576,16 @@ var Raster = Item.extend({
getSubCanvas: function() {
var rect = Rectangle.read(arguments),
ctx = CanvasProvider.getContext(rect.getSize());
- ctx.drawImage(this.getCanvas(), rect.x, rect.y,
- rect.width, rect.height, 0, 0, rect.width, rect.height);
+ var clippedStartX = Math.max(0, rect.x);
+ var clippedStartY = Math.max(0, rect.y);
+ var clippedEndX = Math.min(this.getCanvas().width, rect.x + rect.width);
+ var clippedEndY = Math.min(this.getCanvas().height, rect.y + rect.height);
+ ctx.drawImage(this.getCanvas(),
+ clippedStartX, clippedStartY,
+ clippedEndX - clippedStartX, clippedEndY - clippedStartY,
+ clippedStartX - rect.x, clippedStartY - rect.y,
+ clippedEndX - clippedStartX, clippedEndY - clippedStartY
+ );
return ctx.canvas;
},
@@ -5342,8 +5677,9 @@ var Raster = Item.extend({
},
setPixel: function() {
- var point = Point.read(arguments),
- color = Color.read(arguments),
+ var args = arguments,
+ point = Point.read(args),
+ color = Color.read(args),
components = color._convert('rgb'),
alpha = color._alpha,
ctx = this.getContext(true),
@@ -5356,6 +5692,11 @@ var Raster = Item.extend({
ctx.putImageData(imageData, point.x, point.y);
},
+ clear: function() {
+ var size = this._size;
+ this.getContext(true).clearRect(0, 0, size.width + 1, size.height + 1);
+ },
+
createImageData: function() {
var size = Size.read(arguments);
return this.getContext().createImageData(size.width, size.height);
@@ -5393,10 +5734,17 @@ var Raster = Item.extend({
}
},
- _draw: function(ctx) {
+ _draw: function(ctx, param, viewMatrix) {
var element = this.getElement();
- if (element) {
- ctx.globalAlpha = this._opacity;
+ if (element && element.width > 0 && element.height > 0) {
+ ctx.globalAlpha = Numerical.clamp(this._opacity, 0, 1);
+
+ this._setStyles(ctx, param, viewMatrix);
+
+ DomElement.setPrefixed(
+ ctx, 'imageSmoothingEnabled', this._smoothing
+ );
+
ctx.drawImage(element,
-this._size.width / 2, -this._size.height / 2);
}
@@ -5453,7 +5801,8 @@ var SymbolItem = Item.extend({
},
_hitTestSelf: function(point, options, viewMatrix) {
- var res = this._definition._item._hitTest(point, options, viewMatrix);
+ var opts = options.extend({ all: false });
+ var res = this._definition._item._hitTest(point, opts, viewMatrix);
if (res)
res.item = this;
return res;
@@ -5538,7 +5887,7 @@ var HitResult = Base.extend({
statics: {
getOptions: function(args) {
var options = args && Base.read(args);
- return Base.set({
+ return new Base({
type: null,
tolerance: paper.settings.hitTolerance,
fill: !options,
@@ -5617,7 +5966,7 @@ var Segment = Base.extend({
&& (curve = curves[index]))
curve._changed();
}
- path._changed(25);
+ path._changed(41);
},
getPoint: function() {
@@ -5670,7 +6019,7 @@ var Segment = Base.extend({
this._selection = selection = selection || 0;
if (path && selection !== oldSelection) {
path._updateSelection(this, oldSelection, selection);
- path._changed(129);
+ path._changed(257);
}
},
@@ -6598,6 +6947,13 @@ statics: {
getParameterAt: '#getTimeAt',
+ getTimesWithTangent: function () {
+ var tangent = Point.read(arguments);
+ return tangent.isZero()
+ ? []
+ : Curve.getTimesWithTangent(this.getValues(), tangent);
+ },
+
getOffsetAtTime: function(t) {
return this.getPartLength(0, t);
},
@@ -6958,8 +7314,9 @@ new function() {
flip ? c1 : c2, flip ? t : u);
} else {
v1 = Curve.getPart(v1, tMinClip, tMaxClip);
+ var uDiff = uMax - uMin;
if (tMaxClip - tMinClip > 0.8) {
- if (tMaxNew - tMinNew > uMax - uMin) {
+ if (tMaxNew - tMinNew > uDiff) {
var parts = Curve.subdivide(v1, 0.5),
t = (tMinNew + tMaxNew) / 2;
calls = addCurveIntersections(
@@ -6979,7 +7336,7 @@ new function() {
recursion, calls, u, uMax, tMinNew, tMaxNew);
}
} else {
- if (uMax - uMin >= fatLineEpsilon) {
+ if (uDiff === 0 || uDiff >= fatLineEpsilon) {
calls = addCurveIntersections(
v2, v1, c2, c1, locations, include, !flip,
recursion, calls, uMin, uMax, tMinNew, tMaxNew);
@@ -7147,7 +7504,7 @@ new function() {
return locations;
}
- function getLoopIntersection(v1, c1, locations, include) {
+ function getSelfIntersection(v1, c1, locations, include) {
var info = Curve.classify(v1);
if (info.type === 'loop') {
var roots = info.roots;
@@ -7160,39 +7517,46 @@ new function() {
function getIntersections(curves1, curves2, include, matrix1, matrix2,
_returnFirst) {
- var self = !curves2;
+ var epsilon = 1e-7,
+ self = !curves2;
if (self)
curves2 = curves1;
var length1 = curves1.length,
length2 = curves2.length,
- values2 = [],
- arrays = [],
- locations,
- current;
- for (var i = 0; i < length2; i++)
- values2[i] = curves2[i].getValues(matrix2);
+ values1 = new Array(length1),
+ values2 = self ? values1 : new Array(length2),
+ locations = [];
+
for (var i = 0; i < length1; i++) {
- var curve1 = curves1[i],
- values1 = self ? values2[i] : curve1.getValues(matrix1),
- path1 = curve1.getPath();
- if (path1 !== current) {
- current = path1;
- locations = [];
- arrays.push(locations);
- }
- if (self) {
- getLoopIntersection(values1, curve1, locations, include);
- }
- for (var j = self ? i + 1 : 0; j < length2; j++) {
- if (_returnFirst && locations.length)
- return locations;
- getCurveIntersections(values1, values2[j], curve1, curves2[j],
- locations, include);
+ values1[i] = curves1[i].getValues(matrix1);
+ }
+ if (!self) {
+ for (var i = 0; i < length2; i++) {
+ values2[i] = curves2[i].getValues(matrix2);
}
}
- locations = [];
- for (var i = 0, l = arrays.length; i < l; i++) {
- locations.push.apply(locations, arrays[i]);
+ var boundsCollisions = CollisionDetection.findCurveBoundsCollisions(
+ values1, values2, epsilon);
+ for (var index1 = 0; index1 < length1; index1++) {
+ var curve1 = curves1[index1],
+ v1 = values1[index1];
+ if (self) {
+ getSelfIntersection(v1, curve1, locations, include);
+ }
+ var collisions1 = boundsCollisions[index1];
+ if (collisions1) {
+ for (var j = 0; j < collisions1.length; j++) {
+ if (_returnFirst && locations.length)
+ return locations;
+ var index2 = collisions1[j];
+ if (!self || index2 > index1) {
+ var curve2 = curves2[index2],
+ v2 = values2[index2];
+ getCurveIntersections(
+ v1, v2, curve1, curve2, locations, include);
+ }
+ }
+ }
}
return locations;
}
@@ -7267,18 +7631,58 @@ new function() {
return pairs;
}
+ function getTimesWithTangent(v, tangent) {
+ var x0 = v[0], y0 = v[1],
+ x1 = v[2], y1 = v[3],
+ x2 = v[4], y2 = v[5],
+ x3 = v[6], y3 = v[7],
+ normalized = tangent.normalize(),
+ tx = normalized.x,
+ ty = normalized.y,
+ ax = 3 * x3 - 9 * x2 + 9 * x1 - 3 * x0,
+ ay = 3 * y3 - 9 * y2 + 9 * y1 - 3 * y0,
+ bx = 6 * x2 - 12 * x1 + 6 * x0,
+ by = 6 * y2 - 12 * y1 + 6 * y0,
+ cx = 3 * x1 - 3 * x0,
+ cy = 3 * y1 - 3 * y0,
+ den = 2 * ax * ty - 2 * ay * tx,
+ times = [];
+ if (Math.abs(den) < Numerical.CURVETIME_EPSILON) {
+ var num = ax * cy - ay * cx,
+ den = ax * by - ay * bx;
+ if (den != 0) {
+ var t = -num / den;
+ if (t >= 0 && t <= 1) times.push(t);
+ }
+ } else {
+ var delta = (bx * bx - 4 * ax * cx) * ty * ty +
+ (-2 * bx * by + 4 * ay * cx + 4 * ax * cy) * tx * ty +
+ (by * by - 4 * ay * cy) * tx * tx,
+ k = bx * ty - by * tx;
+ if (delta >= 0 && den != 0) {
+ var d = Math.sqrt(delta),
+ t0 = -(k + d) / den,
+ t1 = (-k + d) / den;
+ if (t0 >= 0 && t0 <= 1) times.push(t0);
+ if (t1 >= 0 && t1 <= 1) times.push(t1);
+ }
+ }
+ return times;
+ }
+
return {
getIntersections: function(curve) {
var v1 = this.getValues(),
v2 = curve && curve !== this && curve.getValues();
return v2 ? getCurveIntersections(v1, v2, this, curve, [])
- : getLoopIntersection(v1, this, []);
+ : getSelfIntersection(v1, this, []);
},
statics: {
getOverlaps: getOverlaps,
getIntersections: getIntersections,
- getCurveLineIntersections: getCurveLineIntersections
+ getCurveLineIntersections: getCurveLineIntersections,
+ getTimesWithTangent: getTimesWithTangent
}
};
});
@@ -7302,10 +7706,13 @@ var CurveLocation = Base.extend({
this._intersection = this._next = this._previous = null;
},
- _setCurve: function(curve) {
- var path = curve._path;
+ _setPath: function(path) {
this._path = path;
this._version = path ? path._version : 0;
+ },
+
+ _setCurve: function(curve) {
+ this._setPath(curve._path);
this._curve = curve;
this._segment = null;
this._segment1 = curve._segment1;
@@ -7313,7 +7720,14 @@ var CurveLocation = Base.extend({
},
_setSegment: function(segment) {
- this._setCurve(segment.getCurve());
+ var curve = segment.getCurve();
+ if (curve) {
+ this._setCurve(curve);
+ } else {
+ this._setPath(segment._path);
+ this._segment1 = segment;
+ this._segment2 = null;
+ }
this._segment = segment;
this._time = segment === this._segment1 ? 0 : 1;
this._point = segment._point.clone();
@@ -7500,9 +7914,9 @@ var CurveLocation = Base.extend({
if (t1Inside && t2Inside)
return !this.isTouching();
var c2 = this.getCurve(),
- c1 = t1 < tMin ? c2.getPrevious() : c2,
+ c1 = c2 && t1 < tMin ? c2.getPrevious() : c2,
c4 = inter.getCurve(),
- c3 = t2 < tMin ? c4.getPrevious() : c4;
+ c3 = c4 && t2 < tMin ? c4.getPrevious() : c4;
if (t1 > tMax)
c2 = c2.getNext();
if (t2 > tMax)
@@ -7516,10 +7930,10 @@ var CurveLocation = Base.extend({
var v = curve.getValues(),
roots = Curve.classify(v).roots || Curve.getPeaks(v),
count = roots.length,
- t = end && count > 1 ? roots[count - 1]
- : count > 0 ? roots[0]
- : 0.5;
- offsets.push(Curve.getLength(v, end ? t : 0, end ? 1 : t) / 2);
+ offset = Curve.getLength(v,
+ end && count ? roots[count - 1] : 0,
+ !end && count ? roots[0] : 1);
+ offsets.push(count ? offset : offset / 32);
}
function isInRange(angle, min, max) {
@@ -7815,7 +8229,7 @@ var PathItem = Item.extend({
getCrossings: function(path) {
return this.getIntersections(path, function(inter) {
- return inter.hasOverlap() || inter.isCrossing();
+ return inter.isCrossing();
});
},
@@ -7878,16 +8292,20 @@ var PathItem = Item.extend({
matched = [],
count = 0;
ok = true;
+ var boundsOverlaps = CollisionDetection.findItemBoundsCollisions(paths1, paths2, Numerical.GEOMETRIC_EPSILON);
for (var i1 = length1 - 1; i1 >= 0 && ok; i1--) {
var path1 = paths1[i1];
ok = false;
- for (var i2 = length2 - 1; i2 >= 0 && !ok; i2--) {
- if (path1.compare(paths2[i2])) {
- if (!matched[i2]) {
- matched[i2] = true;
- count++;
+ var pathBoundsOverlaps = boundsOverlaps[i1];
+ if (pathBoundsOverlaps) {
+ for (var i2 = pathBoundsOverlaps.length - 1; i2 >= 0 && !ok; i2--) {
+ if (path1.compare(paths2[pathBoundsOverlaps[i2]])) {
+ if (!matched[pathBoundsOverlaps[i2]]) {
+ matched[pathBoundsOverlaps[i2]] = true;
+ count++;
+ }
+ ok = true;
}
- ok = true;
}
}
}
@@ -7909,13 +8327,14 @@ var Path = PathItem.extend({
this._closed = false;
this._segments = [];
this._version = 0;
- var segments = Array.isArray(arg)
+ var args = arguments,
+ segments = Array.isArray(arg)
? typeof arg[0] === 'object'
? arg
- : arguments
+ : args
: arg && (arg.size === undefined && (arg.x !== undefined
|| arg.point !== undefined))
- ? arguments
+ ? args
: null;
if (segments && segments.length > 0) {
this.setSegments(segments);
@@ -7944,13 +8363,13 @@ var Path = PathItem.extend({
_changed.base.call(this, flags);
if (flags & 8) {
this._length = this._area = undefined;
- if (flags & 16) {
+ if (flags & 32) {
this._version++;
} else if (this._curves) {
for (var i = 0, l = this._curves.length; i < l; i++)
this._curves[i]._changed();
}
- } else if (flags & 32) {
+ } else if (flags & 64) {
this._bounds = undefined;
}
},
@@ -8025,7 +8444,7 @@ var Path = PathItem.extend({
this._curves[length - 1] = new Curve(this,
this._segments[length - 1], this._segments[0]);
}
- this._changed(25);
+ this._changed(41);
}
}
}, {
@@ -8115,7 +8534,7 @@ var Path = PathItem.extend({
this._updateSelection(segment, 0, segment._selection);
}
if (append) {
- segments.push.apply(segments, segs);
+ Base.push(segments, segs);
} else {
segments.splice.apply(segments, [index, 0].concat(segs));
for (var i = index + amount, l = segments.length; i < l; i++)
@@ -8135,7 +8554,7 @@ var Path = PathItem.extend({
curves.splice(i, 0, new Curve(this, null, null));
this._adjustCurves(start, end);
}
- this._changed(25);
+ this._changed(41);
return segs;
},
@@ -8167,15 +8586,17 @@ var Path = PathItem.extend({
},
add: function(segment1 ) {
- return arguments.length > 1 && typeof segment1 !== 'number'
- ? this._add(Segment.readList(arguments))
- : this._add([ Segment.read(arguments) ])[0];
+ var args = arguments;
+ return args.length > 1 && typeof segment1 !== 'number'
+ ? this._add(Segment.readList(args))
+ : this._add([ Segment.read(args) ])[0];
},
insert: function(index, segment1 ) {
- return arguments.length > 2 && typeof segment1 !== 'number'
- ? this._add(Segment.readList(arguments, 1), index)
- : this._add([ Segment.read(arguments, 1) ], index)[0];
+ var args = arguments;
+ return args.length > 2 && typeof segment1 !== 'number'
+ ? this._add(Segment.readList(args, 1), index)
+ : this._add([ Segment.read(args, 1) ], index)[0];
},
addSegment: function() {
@@ -8227,7 +8648,7 @@ var Path = PathItem.extend({
removed._curves = curves.slice(1);
this._adjustCurves(index, index);
}
- this._changed(25);
+ this._changed(41);
return removed;
},
@@ -8721,8 +9142,8 @@ var Path = PathItem.extend({
strokePadding = tolerancePadding,
join, cap, miterLimit,
area, loc, res,
- hitStroke = options.stroke && style.hasStroke(),
- hitFill = options.fill && style.hasFill(),
+ hitStroke = options.stroke && (style.hasStroke() || options.hitUnstrokedPaths),
+ hitFill = options.fill && (style.hasFill() || options.hitUnfilledPaths),
hitCurves = options.curves,
strokeRadius = hitStroke
? style.getStrokeWidth() / 2
@@ -8883,12 +9304,36 @@ var Path = PathItem.extend({
return offset;
}
return null;
- }
+ },
+ getOffsetsWithTangent: function() {
+ var tangent = Point.read(arguments);
+ if (tangent.isZero()) {
+ return [];
+ }
+
+ var offsets = [];
+ var curveStart = 0;
+ var curves = this.getCurves();
+ for (var i = 0, l = curves.length; i < l; i++) {
+ var curve = curves[i];
+ var curveTimes = curve.getTimesWithTangent(tangent);
+ for (var j = 0, m = curveTimes.length; j < m; j++) {
+ var offset = curveStart + curve.getOffsetAtTime(curveTimes[j]);
+ if (offsets.indexOf(offset) < 0) {
+ offsets.push(offset);
+ }
+ }
+ curveStart += curve.length;
+ }
+ return offsets;
+ }
}),
new function() {
- function drawHandles(ctx, segments, matrix, size) {
+ function drawHandles(ctx, segments, matrix, size, isFullySelected) {
+ if (size <= 0) return;
+
var half = size / 2,
coords = new Array(6),
pX, pY;
@@ -8900,10 +9345,12 @@ new function() {
ctx.beginPath();
ctx.moveTo(pX, pY);
ctx.lineTo(hX, hY);
+ ctx.moveTo(hX - half, hY);
+ ctx.lineTo(hX, hY + half);
+ ctx.lineTo(hX + half, hY);
+ ctx.lineTo(hX, hY - half);
+ ctx.closePath();
ctx.stroke();
- ctx.beginPath();
- ctx.arc(hX, hY, half, 0, Math.PI * 2, true);
- ctx.fill();
}
}
@@ -8913,17 +9360,19 @@ new function() {
segment._transformCoordinates(matrix, coords);
pX = coords[0];
pY = coords[1];
- if (selection & 2)
+ if (selection & 2 && !isFullySelected)
drawHandle(2);
- if (selection & 4)
+ if (selection & 4 && !isFullySelected)
drawHandle(4);
- ctx.fillRect(pX - half, pY - half, size, size);
+ ctx.beginPath();
+ ctx.arc(pX, pY, half, 0, Math.PI * 2, true);
+ ctx.stroke();
+ var fillStyle = ctx.fillStyle;
if (!(selection & 1)) {
- var fillStyle = ctx.fillStyle;
- ctx.fillStyle = '#ffffff';
- ctx.fillRect(pX - half + 1, pY - half + 1, size - 2, size - 2);
- ctx.fillStyle = fillStyle;
+ ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
}
+ ctx.fill();
+ ctx.fillStyle = fillStyle;
}
}
@@ -9009,7 +9458,7 @@ new function() {
}
if (!dontPaint && (hasFill || hasStroke)) {
- this._setStyles(ctx, param, viewMatrix);
+ this._setStyles(ctx, param, viewMatrix, strokeMatrix);
if (hasFill) {
ctx.fill(style.getFillRule());
ctx.shadowColor = 'rgba(0,0,0,0)';
@@ -9044,7 +9493,8 @@ new function() {
ctx.beginPath();
drawSegments(ctx, this, matrix);
ctx.stroke();
- drawHandles(ctx, this._segments, matrix, paper.settings.handleSize);
+ drawHandles(ctx, this._segments, matrix, paper.settings.handleSize,
+ this.isFullySelected());
}
};
},
@@ -9074,17 +9524,19 @@ new function() {
},
cubicCurveTo: function() {
- var handle1 = Point.read(arguments),
- handle2 = Point.read(arguments),
- to = Point.read(arguments),
+ var args = arguments,
+ handle1 = Point.read(args),
+ handle2 = Point.read(args),
+ to = Point.read(args),
current = getCurrentSegment(this);
current.setHandleOut(handle1.subtract(current._point));
this._add([ new Segment(to, handle2.subtract(to)) ]);
},
quadraticCurveTo: function() {
- var handle = Point.read(arguments),
- to = Point.read(arguments),
+ var args = arguments,
+ handle = Point.read(args),
+ to = Point.read(args),
current = getCurrentSegment(this)._point;
this.cubicCurveTo(
handle.add(current.subtract(handle).multiply(1 / 3)),
@@ -9094,9 +9546,10 @@ new function() {
},
curveTo: function() {
- var through = Point.read(arguments),
- to = Point.read(arguments),
- t = Base.pick(Base.read(arguments), 0.5),
+ var args = arguments,
+ through = Point.read(args),
+ to = Point.read(args),
+ t = Base.pick(Base.read(args), 0.5),
t1 = 1 - t,
current = getCurrentSegment(this)._point,
handle = through.subtract(current.multiply(t1 * t1))
@@ -9108,30 +9561,31 @@ new function() {
},
arcTo: function() {
- var abs = Math.abs,
+ var args = arguments,
+ abs = Math.abs,
sqrt = Math.sqrt,
current = getCurrentSegment(this),
from = current._point,
- to = Point.read(arguments),
+ to = Point.read(args),
through,
- peek = Base.peek(arguments),
+ peek = Base.peek(args),
clockwise = Base.pick(peek, true),
center, extent, vector, matrix;
if (typeof clockwise === 'boolean') {
var middle = from.add(to).divide(2),
through = middle.add(middle.subtract(from).rotate(
clockwise ? -90 : 90));
- } else if (Base.remain(arguments) <= 2) {
+ } else if (Base.remain(args) <= 2) {
through = to;
- to = Point.read(arguments);
- } else {
- var radius = Size.read(arguments),
+ to = Point.read(args);
+ } else if (!from.equals(to)) {
+ var radius = Size.read(args),
isZero = Numerical.isZero;
if (isZero(radius.width) || isZero(radius.height))
return this.lineTo(to);
- var rotation = Base.read(arguments),
- clockwise = !!Base.read(arguments),
- large = !!Base.read(arguments),
+ var rotation = Base.read(args),
+ clockwise = !!Base.read(args),
+ large = !!Base.read(args),
middle = from.add(to).divide(2),
pt = from.subtract(middle).rotate(-rotation),
x = pt.x,
@@ -9184,46 +9638,48 @@ new function() {
}
vector = from.subtract(center);
extent = vector.getDirectedAngle(to.subtract(center));
- var centerSide = line.getSide(center);
+ var centerSide = line.getSide(center, true);
if (centerSide === 0) {
extent = throughSide * abs(extent);
} else if (throughSide === centerSide) {
extent += extent < 0 ? 360 : -360;
}
}
- var epsilon = 1e-7,
- ext = abs(extent),
- count = ext >= 360 ? 4 : Math.ceil((ext - epsilon) / 90),
- inc = extent / count,
- half = inc * Math.PI / 360,
- z = 4 / 3 * Math.sin(half) / (1 + Math.cos(half)),
- segments = [];
- for (var i = 0; i <= count; i++) {
- var pt = to,
- out = null;
- if (i < count) {
- out = vector.rotate(90).multiply(z);
- if (matrix) {
- pt = matrix._transformPoint(vector);
- out = matrix._transformPoint(vector.add(out))
- .subtract(pt);
+ if (extent) {
+ var epsilon = 1e-7,
+ ext = abs(extent),
+ count = ext >= 360 ? 4 : Math.ceil((ext - epsilon) / 90),
+ inc = extent / count,
+ half = inc * Math.PI / 360,
+ z = 4 / 3 * Math.sin(half) / (1 + Math.cos(half)),
+ segments = [];
+ for (var i = 0; i <= count; i++) {
+ var pt = to,
+ out = null;
+ if (i < count) {
+ out = vector.rotate(90).multiply(z);
+ if (matrix) {
+ pt = matrix._transformPoint(vector);
+ out = matrix._transformPoint(vector.add(out))
+ .subtract(pt);
+ } else {
+ pt = center.add(vector);
+ }
+ }
+ if (!i) {
+ current.setHandleOut(out);
} else {
- 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);
}
- if (!i) {
- current.setHandleOut(out);
- } else {
- 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);
+ this._add(segments);
}
- this._add(segments);
},
lineBy: function() {
@@ -9233,37 +9689,41 @@ new function() {
},
curveBy: function() {
- var through = Point.read(arguments),
- to = Point.read(arguments),
- parameter = Base.read(arguments),
+ var args = arguments,
+ through = Point.read(args),
+ to = Point.read(args),
+ parameter = Base.read(args),
current = getCurrentSegment(this)._point;
this.curveTo(current.add(through), current.add(to), parameter);
},
cubicCurveBy: function() {
- var handle1 = Point.read(arguments),
- handle2 = Point.read(arguments),
- to = Point.read(arguments),
+ var args = arguments,
+ handle1 = Point.read(args),
+ handle2 = Point.read(args),
+ to = Point.read(args),
current = getCurrentSegment(this)._point;
this.cubicCurveTo(current.add(handle1), current.add(handle2),
current.add(to));
},
quadraticCurveBy: function() {
- var handle = Point.read(arguments),
- to = Point.read(arguments),
+ var args = arguments,
+ handle = Point.read(args),
+ to = Point.read(args),
current = getCurrentSegment(this)._point;
this.quadraticCurveTo(current.add(handle), current.add(to));
},
arcBy: function() {
- var current = getCurrentSegment(this)._point,
- point = current.add(Point.read(arguments)),
- clockwise = Base.pick(Base.peek(arguments), true);
+ var args = arguments,
+ current = getCurrentSegment(this)._point,
+ point = current.add(Point.read(args)),
+ clockwise = Base.pick(Base.peek(args), true);
if (typeof clockwise === 'boolean') {
this.arcTo(point, clockwise);
} else {
- this.arcTo(point, current.add(Point.read(arguments)));
+ this.arcTo(point, current.add(Point.read(args)));
}
},
@@ -9361,13 +9821,16 @@ statics: {
}
var length = segments.length - (closed ? 0 : 1);
- for (var i = 1; i < length; i++)
- addJoin(segments[i], join);
- if (closed) {
- addJoin(segments[0], join);
- } else if (length > 0) {
- addCap(segments[0], cap);
- addCap(segments[segments.length - 1], cap);
+ if (length > 0) {
+ for (var i = 1; i < length; i++) {
+ addJoin(segments[i], join);
+ }
+ if (closed) {
+ addJoin(segments[0], join);
+ } else {
+ addCap(segments[0], cap);
+ addCap(segments[segments.length - 1], cap);
+ }
}
return bounds;
},
@@ -9397,8 +9860,9 @@ statics: {
normal1 = curve1.getNormalAtTime(1).multiply(radius)
.transform(strokeMatrix),
normal2 = curve2.getNormalAtTime(0).multiply(radius)
- .transform(strokeMatrix);
- if (normal1.getDirectedAngle(normal2) < 0) {
+ .transform(strokeMatrix),
+ angle = normal1.getDirectedAngle(normal2);
+ if (angle < 0 || angle >= 180) {
normal1 = normal1.negate();
normal2 = normal2.negate();
}
@@ -9513,21 +9977,24 @@ Path.inject({ statics: new function() {
return {
Line: function() {
+ var args = arguments;
return createPath([
- new Segment(Point.readNamed(arguments, 'from')),
- new Segment(Point.readNamed(arguments, 'to'))
- ], false, arguments);
+ new Segment(Point.readNamed(args, 'from')),
+ new Segment(Point.readNamed(args, 'to'))
+ ], false, args);
},
Circle: function() {
- var center = Point.readNamed(arguments, 'center'),
- radius = Base.readNamed(arguments, 'radius');
- return createEllipse(center, new Size(radius), arguments);
+ var args = arguments,
+ center = Point.readNamed(args, 'center'),
+ radius = Base.readNamed(args, 'radius');
+ return createEllipse(center, new Size(radius), args);
},
Rectangle: function() {
- var rect = Rectangle.readNamed(arguments, 'rectangle'),
- radius = Size.readNamed(arguments, 'radius', 0,
+ var args = arguments,
+ rect = Rectangle.readNamed(args, 'rectangle'),
+ radius = Size.readNamed(args, 'radius', 0,
{ readNull: true }),
bl = rect.getBottomLeft(true),
tl = rect.getTopLeft(true),
@@ -9558,23 +10025,25 @@ Path.inject({ statics: new function() {
new Segment(br.subtract(rx, 0), [hx, 0])
];
}
- return createPath(segments, true, arguments);
+ return createPath(segments, true, args);
},
RoundRectangle: '#Rectangle',
Ellipse: function() {
- var ellipse = Shape._readEllipse(arguments);
- return createEllipse(ellipse.center, ellipse.radius, arguments);
+ var args = arguments,
+ ellipse = Shape._readEllipse(args);
+ return createEllipse(ellipse.center, ellipse.radius, args);
},
Oval: '#Ellipse',
Arc: function() {
- var from = Point.readNamed(arguments, 'from'),
- through = Point.readNamed(arguments, 'through'),
- to = Point.readNamed(arguments, 'to'),
- props = Base.getNamed(arguments),
+ var args = arguments,
+ from = Point.readNamed(args, 'from'),
+ through = Point.readNamed(args, 'through'),
+ to = Point.readNamed(args, 'to'),
+ props = Base.getNamed(args),
path = new Path(props && props.insert == false
&& Item.NO_INSERT);
path.moveTo(from);
@@ -9583,9 +10052,10 @@ Path.inject({ statics: new function() {
},
RegularPolygon: function() {
- var center = Point.readNamed(arguments, 'center'),
- sides = Base.readNamed(arguments, 'sides'),
- radius = Base.readNamed(arguments, 'radius'),
+ var args = arguments,
+ center = Point.readNamed(args, 'center'),
+ sides = Base.readNamed(args, 'sides'),
+ radius = Base.readNamed(args, 'radius'),
step = 360 / sides,
three = sides % 3 === 0,
vector = new Point(0, three ? -radius : radius),
@@ -9594,21 +10064,22 @@ Path.inject({ statics: new function() {
for (var i = 0; i < sides; i++)
segments[i] = new Segment(center.add(
vector.rotate((i + offset) * step)));
- return createPath(segments, true, arguments);
+ return createPath(segments, true, args);
},
Star: function() {
- var center = Point.readNamed(arguments, 'center'),
- points = Base.readNamed(arguments, 'points') * 2,
- radius1 = Base.readNamed(arguments, 'radius1'),
- radius2 = Base.readNamed(arguments, 'radius2'),
+ var args = arguments,
+ center = Point.readNamed(args, 'center'),
+ points = Base.readNamed(args, 'points') * 2,
+ radius1 = Base.readNamed(args, 'radius1'),
+ radius2 = Base.readNamed(args, 'radius2'),
step = 360 / points,
vector = new Point(0, -1),
segments = new Array(points);
for (var i = 0; i < points; i++)
segments[i] = new Segment(center.add(vector.rotate(step * i)
.multiply(i % 2 ? radius2 : radius1)));
- return createPath(segments, true, arguments);
+ return createPath(segments, true, args);
}
};
}});
@@ -9697,8 +10168,9 @@ var CompoundPath = PathItem.extend({
getCurves: function() {
var children = this._children,
curves = [];
- for (var i = 0, l = children.length; i < l; i++)
- curves.push.apply(curves, children[i].getCurves());
+ for (var i = 0, l = children.length; i < l; i++) {
+ Base.push(curves, children[i].getCurves());
+ }
return curves;
},
@@ -9742,7 +10214,7 @@ var CompoundPath = PathItem.extend({
_hitTestChildren: function _hitTestChildren(point, options, viewMatrix) {
return _hitTestChildren.base.call(this, point,
- options.class === Path || options.type === 'path' ? options
+ options.class === Path || options.type === 'path' || options.hitUnfilledPaths ? options
: Base.set({}, options, { fill: false }),
viewMatrix);
},
@@ -9758,7 +10230,7 @@ var CompoundPath = PathItem.extend({
children[i].draw(ctx, param, strokeMatrix);
if (!param.clip) {
- this._setStyles(ctx, param, viewMatrix);
+ this._setStyles(ctx, param, viewMatrix, strokeMatrix);
var style = this._style;
if (style.hasFill()) {
ctx.fill(style.getFillRule());
@@ -9841,13 +10313,30 @@ PathItem.inject(new function() {
exclude: { '1': true, '-1': true }
};
+ function getPaths(path) {
+ return path._children || [path];
+ }
+
function preparePath(path, resolve) {
- var res = path.clone(false).reduce({ simplify: true })
- .transform(null, true, true);
- return resolve
- ? res.resolveCrossings().reorient(
- res.getFillRule() === 'nonzero', true)
- : res;
+ var res = path
+ .clone(false)
+ .reduce({ simplify: true })
+ .transform(null, true, true);
+ if (resolve) {
+ var paths = getPaths(res);
+ for (var i = 0, l = paths.length; i < l; i++) {
+ var path = paths[i];
+ if (!path._closed && !path.isEmpty()) {
+ path.closePath(1e-12);
+ path.getFirstSegment().setHandleIn(0, 0);
+ path.getLastSegment().setHandleOut(0, 0);
+ }
+ }
+ res = res
+ .resolveCrossings()
+ .reorient(res.getFillRule() === 'nonzero', true);
+ }
+ return res;
}
function createResult(paths, simplify, path1, path2, options) {
@@ -9862,6 +10351,10 @@ PathItem.inject(new function() {
return result;
}
+ function filterIntersection(inter) {
+ return inter.hasOverlap() || inter.isCrossing();
+ }
+
function traceBoolean(path1, path2, operation, options) {
if (options && (options.trace == false || options.stroke) &&
/^(subtract|intersect)$/.test(operation))
@@ -9873,36 +10366,63 @@ PathItem.inject(new function() {
if (_path2 && (operator.subtract || operator.exclude)
^ (_path2.isClockwise() ^ _path1.isClockwise()))
_path2.reverse();
- var crossings = divideLocations(
- CurveLocation.expand(_path1.getCrossings(_path2))),
- paths1 = _path1._children || [_path1],
- paths2 = _path2 && (_path2._children || [_path2]),
+ var crossings = divideLocations(CurveLocation.expand(
+ _path1.getIntersections(_path2, filterIntersection))),
+ paths1 = getPaths(_path1),
+ paths2 = _path2 && getPaths(_path2),
segments = [],
curves = [],
paths;
- function collect(paths) {
+ function collectPaths(paths) {
for (var i = 0, l = paths.length; i < l; i++) {
var path = paths[i];
- segments.push.apply(segments, path._segments);
- curves.push.apply(curves, path.getCurves());
+ Base.push(segments, path._segments);
+ Base.push(curves, path.getCurves());
path._overlapsOnly = true;
}
}
+ function getCurves(indices) {
+ var list = [];
+ for (var i = 0, l = indices && indices.length; i < l; i++) {
+ list.push(curves[indices[i]]);
+ }
+ return list;
+ }
+
if (crossings.length) {
- collect(paths1);
+ collectPaths(paths1);
if (paths2)
- collect(paths2);
+ collectPaths(paths2);
+
+ var curvesValues = new Array(curves.length);
+ for (var i = 0, l = curves.length; i < l; i++) {
+ curvesValues[i] = curves[i].getValues();
+ }
+ var curveCollisions = CollisionDetection.findCurveBoundsCollisions(
+ curvesValues, curvesValues, 0, true);
+ var curveCollisionsMap = {};
+ for (var i = 0; i < curves.length; i++) {
+ var curve = curves[i],
+ id = curve._path._id,
+ map = curveCollisionsMap[id] = curveCollisionsMap[id] || {};
+ map[curve.getIndex()] = {
+ hor: getCurves(curveCollisions[i].hor),
+ ver: getCurves(curveCollisions[i].ver)
+ };
+ }
+
for (var i = 0, l = crossings.length; i < l; i++) {
- propagateWinding(crossings[i]._segment, _path1, _path2, curves,
- operator);
+ propagateWinding(crossings[i]._segment, _path1, _path2,
+ curveCollisionsMap, operator);
}
for (var i = 0, l = segments.length; i < l; i++) {
var segment = segments[i],
inter = segment._intersection;
if (!segment._winding) {
- propagateWinding(segment, _path1, _path2, curves, operator);
+ propagateWinding(segment, _path1, _path2,
+ curveCollisionsMap, operator);
}
if (!(inter && inter._overlap))
segment._path._overlapsOnly = false;
@@ -9915,14 +10435,13 @@ PathItem.inject(new function() {
return !!operator[w];
});
}
-
return createResult(paths, true, path1, path2, options);
}
function splitBoolean(path1, path2, operation) {
var _path1 = preparePath(path1),
_path2 = preparePath(path2),
- crossings = _path1.getCrossings(_path2),
+ crossings = _path1.getIntersections(_path2, filterIntersection),
subtract = operation === 'subtract',
divide = operation === 'divide',
added = {},
@@ -9985,22 +10504,30 @@ PathItem.inject(new function() {
return abs(b.getArea()) - abs(a.getArea());
}),
first = sorted[0];
+ var collisions = CollisionDetection.findItemBoundsCollisions(sorted,
+ null, Numerical.GEOMETRIC_EPSILON);
if (clockwise == null)
clockwise = first.isClockwise();
for (var i = 0; i < length; i++) {
var path1 = sorted[i],
entry1 = lookup[path1._id],
- point = path1.getInteriorPoint(),
- containerWinding = 0;
- for (var j = i - 1; j >= 0; j--) {
- var path2 = sorted[j];
- if (path2.contains(point)) {
- var entry2 = lookup[path2._id];
- containerWinding = entry2.winding;
- entry1.winding += containerWinding;
- entry1.container = entry2.exclude ? entry2.container
- : path2;
- break;
+ containerWinding = 0,
+ indices = collisions[i];
+ if (indices) {
+ var point = null;
+ for (var j = indices.length - 1; j >= 0; j--) {
+ if (indices[j] < i) {
+ point = point || path1.getInteriorPoint();
+ var path2 = sorted[indices[j]];
+ if (path2.contains(point)) {
+ var entry2 = lookup[path2._id];
+ containerWinding = entry2.winding;
+ entry1.winding += containerWinding;
+ entry1.container = entry2.exclude
+ ? entry2.container : path2;
+ break;
+ }
+ }
}
}
if (isInside(entry1.winding) === isInside(containerWinding)) {
@@ -10008,8 +10535,8 @@ PathItem.inject(new function() {
paths[entry1.index] = null;
} else {
var container = entry1.container;
- path1.setClockwise(container ? !container.isClockwise()
- : clockwise);
+ path1.setClockwise(
+ container ? !container.isClockwise() : clockwise);
}
}
}
@@ -10097,6 +10624,9 @@ PathItem.inject(new function() {
}
function getWinding(point, curves, dir, closed, dontFlip) {
+ var curvesList = Array.isArray(curves)
+ ? curves
+ : curves[dir ? 'hor' : 'ver'];
var ia = dir ? 1 : 0,
io = ia ^ 1,
pv = [point.x, point.y],
@@ -10172,7 +10702,7 @@ PathItem.inject(new function() {
onPath = true;
}
}
- quality = 0;
+ quality /= 4;
}
vPrev = v;
return !dontFlip && a > paL && a < paR
@@ -10201,12 +10731,12 @@ PathItem.inject(new function() {
}
}
- for (var i = 0, l = curves.length; i < l; i++) {
- var curve = curves[i],
+ for (var i = 0, l = curvesList.length; i < l; i++) {
+ var curve = curvesList[i],
path = curve._path,
v = curve.getValues(),
res;
- if (!i || curves[i - 1]._path !== path) {
+ if (!i || curvesList[i - 1]._path !== path) {
vPrev = null;
if (!path._closed) {
vClose = Curve.getValues(
@@ -10235,7 +10765,7 @@ PathItem.inject(new function() {
if (res = handleCurve(v))
return res;
- if (i + 1 === l || curves[i + 1]._path !== path) {
+ if (i + 1 === l || curvesList[i + 1]._path !== path) {
if (vClose && (res = handleCurve(vClose)))
return res;
if (onPath && !pathWindingL && !pathWindingR) {
@@ -10263,21 +10793,24 @@ PathItem.inject(new function() {
};
}
- function propagateWinding(segment, path1, path2, curves, operator) {
+ function propagateWinding(segment, path1, path2, curveCollisionsMap,
+ operator) {
var chain = [],
start = segment,
totalLength = 0,
winding;
do {
- var curve = segment.getCurve(),
- length = curve.getLength();
- chain.push({ segment: segment, curve: curve, length: length });
- totalLength += length;
+ var curve = segment.getCurve();
+ if (curve) {
+ var length = curve.getLength();
+ chain.push({ segment: segment, curve: curve, length: length });
+ totalLength += length;
+ }
segment = segment.getNext();
} while (segment && !segment._intersection && segment !== start);
var offsets = [0.5, 0.25, 0.75],
winding = { winding: 0, quality: -1 },
- tMin = 1e-8,
+ tMin = 1e-3,
tMax = 1 - tMin;
for (var i = 0; i < offsets.length && winding.quality < 0.5; i++) {
var length = totalLength * offsets[i];
@@ -10292,13 +10825,22 @@ PathItem.inject(new function() {
t = Numerical.clamp(curve.getTimeAt(length), tMin, tMax),
pt = curve.getPointAtTime(t),
dir = abs(curve.getTangentAtTime(t).y) < Math.SQRT1_2;
- var wind = !(operator.subtract && path2 && (
- operand === path1 &&
- path2._getWinding(pt, dir, true).winding ||
- operand === path2 &&
- !path1._getWinding(pt, dir, true).winding))
- ? getWinding(pt, curves, dir, true)
- : { winding: 0, quality: 1 };
+ var wind = null;
+ if (operator.subtract && path2) {
+ var otherPath = operand === path1 ? path2 : path1,
+ pathWinding = otherPath._getWinding(pt, dir, true);
+ if (operand === path1 && pathWinding.winding ||
+ operand === path2 && !pathWinding.winding) {
+ if (pathWinding.quality < 1) {
+ continue;
+ } else {
+ wind = { winding: 0, quality: 1 };
+ }
+ }
+ }
+ wind = wind || getWinding(
+ pt, curveCollisionsMap[path._id][curve.getIndex()],
+ dir, true);
if (wind.quality > winding.quality)
winding = wind;
break;
@@ -10370,8 +10912,8 @@ PathItem.inject(new function() {
if (inter) {
collect(inter);
- while (inter && inter._prev)
- inter = inter._prev;
+ while (inter && inter._previous)
+ inter = inter._previous;
collect(inter, start);
}
return crossings;
@@ -10572,7 +11114,7 @@ PathItem.inject(new function() {
if (clearCurves)
clearCurveHandles(clearCurves);
paths = tracePaths(Base.each(paths, function(path) {
- this.push.apply(this, path._segments);
+ Base.push(this, path._segments);
}, []));
}
var length = paths.length,
@@ -10701,7 +11243,7 @@ var PathFlattener = Base.extend({
segment1 = segment2;
}
if (path._closed)
- addCurve(segment2, segments[0]);
+ addCurve(segment2 || segment1, segments[0]);
this.curves = curves;
this.parts = parts;
this.length = length;
@@ -10927,7 +11469,7 @@ var PathFitter = Base.extend({
pt2 = this.evaluate(1, curve2, u),
diff = pt.subtract(point),
df = pt1.dot(pt1) + diff.dot(pt2);
- return Numerical.isZero(df) ? u : u - diff.dot(pt1) / df;
+ return Numerical.isMachineZero(df) ? u : u - diff.dot(pt1) / df;
},
evaluate: function(degree, curve, t) {
@@ -11003,7 +11545,7 @@ var TextItem = Item.extend({
setContent: function(content) {
this._content = '' + content;
this._lines = this._content.split(/\r\n|\n|\r/mg);
- this._changed(265);
+ this._changed(521);
},
isEmpty: function() {
@@ -11060,6 +11602,11 @@ var PointText = TextItem.extend({
},
_getBounds: function(matrix, options) {
+ var rect = options.drawnTextBounds ? this._getDrawnTextSize() : this._getMeasuredTextSize();
+ return matrix ? matrix._transformBounds(rect, rect) : rect;
+ },
+
+ _getMeasuredTextSize: function() {
var style = this._style,
lines = this._lines,
numLines = lines.length,
@@ -11069,10 +11616,67 @@ var PointText = TextItem.extend({
x = 0;
if (justification !== 'left')
x -= width / (justification === 'center' ? 2: 1);
- var rect = new Rectangle(x,
+ return new Rectangle(x,
numLines ? - 0.75 * leading : 0,
width, numLines * leading);
- return matrix ? matrix._transformBounds(rect, rect) : rect;
+ },
+
+ _getDrawnTextSize: function() {
+ var style = this._style;
+ var lines = this._lines;
+ var numLines = lines.length;
+ var leading = style.getLeading();
+ var justification = style.getJustification();
+
+ var svg = SvgElement.create('svg', {
+ version: '1.1',
+ xmlns: SvgElement.svg
+ });
+ var node = SvgElement.create('text');
+ node.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
+ svg.appendChild(node);
+ for (var i = 0; i < numLines; i++) {
+ var tspanNode = SvgElement.create('tspan', {
+ x: '0',
+ dy: i === 0 ? '0' : leading + 'px'
+ });
+ tspanNode.textContent = this._lines[i];
+ node.appendChild(tspanNode);
+ }
+
+ var element = document.createElement('span');
+ element.style.visibility = ('hidden');
+ element.style.whiteSpace = 'pre';
+ element.style.fontSize = this.fontSize + 'px';
+ element.style.fontFamily = this.font;
+ element.style.lineHeight = this.leading / this.fontSize;
+
+ var bbox;
+ try {
+ element.appendChild(svg);
+ document.body.appendChild(element);
+ bbox = svg.getBBox();
+ } finally {
+ document.body.removeChild(element);
+ }
+
+ var halfStrokeWidth = this.strokeWidth / 2;
+ var width = bbox.width + (halfStrokeWidth * 2);
+ var height = bbox.height + (halfStrokeWidth * 2);
+ var x = bbox.x - halfStrokeWidth;
+ var y = bbox.y - halfStrokeWidth;
+
+ if (justification !== 'left') {
+ var eltWidth = this.getView().getTextWidth(style.getFontStyle(), lines);
+ x -= eltWidth / (justification === 'center' ? 2: 1);
+ }
+
+ return new Rectangle(x, y, width + 1, Math.max(height, numLines * leading));
+ },
+
+ _hitTestSelf: function(point, options) {
+ if (options.fill && (this.hasFill() || options.hitUnfilledPaths) && this._contains(point))
+ return new HitResult('fill', this);
}
});
@@ -11086,47 +11690,74 @@ var Color = Base.extend(new function() {
};
var componentParsers = {},
- colorCache = {},
+ namedColors = {
+ transparent: [0, 0, 0, 0]
+ },
colorCtx;
function fromCSS(string) {
- var match = string.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/),
+ var match = string.match(
+ /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?$/i
+ ) || string.match(
+ /^#([\da-f])([\da-f])([\da-f])([\da-f])?$/i
+ ),
+ type = 'rgb',
components;
if (match) {
- components = [0, 0, 0];
- for (var i = 0; i < 3; i++) {
+ var amount = match[4] ? 4 : 3;
+ components = new Array(amount);
+ for (var i = 0; i < amount; i++) {
var value = match[i + 1];
components[i] = parseInt(value.length == 1
? value + value : value, 16) / 255;
}
- } else if (match = string.match(/^rgba?\((.*)\)$/)) {
- components = match[1].split(',');
- for (var i = 0, l = components.length; i < l; i++) {
- var value = +components[i];
- components[i] = i < 3 ? value / 255 : value;
- }
- } else if (window) {
- var cached = colorCache[string];
- if (!cached) {
- if (!colorCtx) {
- colorCtx = CanvasProvider.getContext(1, 1);
- colorCtx.globalCompositeOperation = 'copy';
+ } else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) {
+ type = match[1];
+ components = match[2].trim().split(/[,\s]+/g);
+ var isHSL = type === 'hsl';
+ for (var i = 0, l = Math.min(components.length, 4); i < l; i++) {
+ var component = components[i];
+ var value = parseFloat(component);
+ if (isHSL) {
+ if (i === 0) {
+ var unit = component.match(/([a-z]*)$/)[1];
+ value *= ({
+ turn: 360,
+ rad: 180 / Math.PI,
+ grad: 0.9
+ }[unit] || 1);
+ } else if (i < 3) {
+ value /= 100;
+ }
+ } else if (i < 3) {
+ value /= /%$/.test(component) ? 100 : 255;
}
- colorCtx.fillStyle = 'rgba(0,0,0,0)';
- colorCtx.fillStyle = string;
- colorCtx.fillRect(0, 0, 1, 1);
- var data = colorCtx.getImageData(0, 0, 1, 1).data;
- cached = colorCache[string] = [
- data[0] / 255,
- data[1] / 255,
- data[2] / 255
- ];
+ components[i] = value;
}
- components = cached.slice();
} else {
- components = [0, 0, 0];
+ var color = namedColors[string];
+ if (!color) {
+ if (window) {
+ if (!colorCtx) {
+ colorCtx = CanvasProvider.getContext(1, 1);
+ colorCtx.globalCompositeOperation = 'copy';
+ }
+ colorCtx.fillStyle = 'rgba(0,0,0,0)';
+ colorCtx.fillStyle = string;
+ colorCtx.fillRect(0, 0, 1, 1);
+ var data = colorCtx.getImageData(0, 0, 1, 1).data;
+ color = namedColors[string] = [
+ data[0] / 255,
+ data[1] / 255,
+ data[2] / 255
+ ];
+ } else {
+ color = [0, 0, 0];
+ }
+ }
+ components = color.slice();
}
- return components;
+ return [type, components];
}
var hsbIndices = [
@@ -11234,30 +11865,32 @@ var Color = Base.extend(new function() {
Base.each(properties, function(name, index) {
var part = Base.capitalize(name),
hasOverlap = /^(hue|saturation)$/.test(name),
- parser = componentParsers[type][index] = name === 'gradient'
- ? function(value) {
- var current = this._components[0];
- value = Gradient.read(Array.isArray(value) ? value
- : arguments, 0, { readNull: true });
- if (current !== value) {
- if (current)
- current._removeOwner(this);
- if (value)
- value._addOwner(this);
+ parser = componentParsers[type][index] = type === 'gradient'
+ ? name === 'gradient'
+ ? function(value) {
+ var current = this._components[0];
+ value = Gradient.read(
+ Array.isArray(value)
+ ? value
+ : arguments, 0, { readNull: true }
+ );
+ if (current !== value) {
+ if (current)
+ current._removeOwner(this);
+ if (value)
+ value._addOwner(this);
+ }
+ return value;
}
- return value;
- }
- : type === 'gradient'
- ? function() {
+ : function() {
return Point.read(arguments, 0, {
readNull: name === 'highlight',
clone: true
});
}
- : function(value) {
- return value == null || isNaN(value) ? 0 : value;
- };
-
+ : function(value) {
+ return value == null || isNaN(value) ? 0 : +value;
+ };
this['get' + part] = function() {
return this._type === type
|| hasOverlap && /^hs[bl]$/.test(this._type)
@@ -11327,8 +11960,9 @@ var Color = Base.extend(new function() {
if (values.length > length)
values = Base.slice(values, 0, length);
} else if (argType === 'string') {
- type = 'rgb';
- components = fromCSS(arg);
+ var converted = fromCSS(arg);
+ type = converted[0];
+ components = converted[1];
if (components.length === 4) {
alpha = components[3];
components.length--;
@@ -11412,8 +12046,13 @@ var Color = Base.extend(new function() {
_changed: function() {
this._canvasStyle = null;
- if (this._owner)
- this._owner._changed(65);
+ if (this._owner) {
+ if (this._setter) {
+ this._owner[this._setter](this);
+ } else {
+ this._owner._changed(129);
+ }
+ }
},
_convert: function(type) {
@@ -11509,8 +12148,9 @@ var Color = Base.extend(new function() {
+ components.join(',') + ')';
},
- toCanvasStyle: function(ctx, matrix) {
- if (this._canvasStyle)
+ toCanvasStyle: function(ctx, matrix, strokeMatrix) {
+ var strokeMayChange = this._type === 'gradient' && strokeMatrix;
+ if (this._canvasStyle && !strokeMayChange)
return this._canvasStyle;
if (this._type !== 'gradient')
return this._canvasStyle = this.toCSS();
@@ -11528,6 +12168,12 @@ var Color = Base.extend(new function() {
if (highlight)
highlight = inverse._transformPoint(highlight);
}
+ if (strokeMatrix) {
+ origin = strokeMatrix._transformPoint(origin);
+ destination = strokeMatrix._transformPoint(destination);
+ if (highlight)
+ highlight = strokeMatrix._transformPoint(highlight);
+ }
if (gradient._radial) {
var radius = destination.getDistance(origin);
if (highlight) {
@@ -11549,7 +12195,8 @@ var Color = Base.extend(new function() {
offset == null ? i / (l - 1) : offset,
stop._color.toCanvasStyle());
}
- return this._canvasStyle = canvasGradient;
+ if (!strokeMayChange) this._canvasStyle = canvasGradient;
+ return canvasGradient;
},
transform: function(matrix) {
@@ -11569,6 +12216,19 @@ var Color = Base.extend(new function() {
random: function() {
var random = Math.random;
return new Color(random(), random(), random());
+ },
+
+ _setOwner: function(color, owner, setter) {
+ if (color) {
+ if (color._owner && owner && color._owner !== owner) {
+ color = color.clone();
+ }
+ if (!color._owner ^ !owner) {
+ color._owner = owner || null;
+ color._setter = setter || null;
+ }
+ }
+ return color;
}
}
});
@@ -11744,7 +12404,7 @@ var GradientStop = Base.extend({
_changed: function() {
if (this._owner)
- this._owner._changed(65);
+ this._owner._changed(129);
},
getOffset: function() {
@@ -11764,10 +12424,9 @@ var GradientStop = Base.extend({
},
setColor: function() {
- var color = Color.read(arguments, 0, { clone: true });
- if (color)
- color._owner = this;
- this._color = color;
+ Color._setOwner(this._color, null);
+ this._color = Color._setOwner(Color.read(arguments, 0), this,
+ 'setColor');
this._changed();
},
@@ -11807,11 +12466,11 @@ var Style = Base.extend(new function() {
fillColor: new Color()
}),
flags = {
- strokeWidth: 97,
- strokeCap: 97,
- strokeJoin: 97,
- strokeScaling: 105,
- miterLimit: 97,
+ strokeWidth: 193,
+ strokeCap: 193,
+ strokeJoin: 193,
+ strokeScaling: 201,
+ miterLimit: 193,
fontFamily: 9,
fontWeight: 9,
fontSize: 9,
@@ -11849,26 +12508,30 @@ var Style = Base.extend(new function() {
fields[set] = function(value) {
var owner = this._owner,
- children = owner && owner._children;
- if (children && children.length > 0
- && !(owner instanceof CompoundPath)) {
+ children = owner && owner._children,
+ applyToChildren = children && children.length > 0
+ && !(owner instanceof CompoundPath);
+ if (applyToChildren) {
for (var i = 0, l = children.length; i < l; i++)
children[i]._style[set](value);
- } else if (key in this._defaults) {
+ }
+ if ((key === 'selectedColor' || !applyToChildren)
+ && key in this._defaults) {
var old = this._values[key];
if (old !== value) {
if (isColor) {
- if (old && old._owner !== undefined)
- old._owner = undefined;
+ if (old) {
+ Color._setOwner(old, null);
+ old._canvasStyle = null;
+ }
if (value && value.constructor === Color) {
- if (value._owner)
- value = value.clone();
- value._owner = owner;
+ value = Color._setOwner(value, owner,
+ applyToChildren && set);
}
}
this._values[key] = value;
if (owner)
- owner._changed(flag || 65);
+ owner._changed(flag || 129);
}
}
};
@@ -11876,24 +12539,10 @@ var Style = Base.extend(new function() {
fields[get] = function(_dontMerge) {
var owner = this._owner,
children = owner && owner._children,
+ applyToChildren = children && children.length > 0
+ && !(owner instanceof CompoundPath),
value;
- 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)) {
- this._values[key] = value = ctor.read([value], 0,
- { readNull: true, clone: true });
- if (value && isColor)
- value._owner = owner;
- }
- }
- } else if (children) {
+ if (applyToChildren && !_dontMerge) {
for (var i = 0, l = children.length; i < l; i++) {
var childValue = children[i]._style[get]();
if (!i) {
@@ -11902,6 +12551,23 @@ var Style = Base.extend(new function() {
return undefined;
}
}
+ } else if (key in this._defaults) {
+ 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)) {
+ this._values[key] = value = ctor.read([value], 0,
+ { readNull: true, clone: true });
+ }
+ }
+ }
+ if (value && isColor) {
+ value = Color._setOwner(value, owner, applyToChildren && set);
}
return value;
};
@@ -11963,6 +12629,16 @@ var Style = Base.extend(new function() {
|| false;
},
+ _dispose: function() {
+ var color;
+ color = this.getFillColor();
+ if (color) color._canvasStyle = null;
+ color = this.getStrokeColor();
+ if (color) color._canvasStyle = null;
+ color = this.getShadowColor();
+ if (color) color._canvasStyle = null;
+ },
+
hasFill: function() {
var color = this.getFillColor();
return !!color && color.alpha > 0;
@@ -12101,8 +12777,14 @@ var DomEvent = {
for (var type in events) {
var func = events[type],
parts = type.split(/[\s,]+/g);
- for (var i = 0, l = parts.length; i < l; i++)
- el.addEventListener(parts[i], func, false);
+ for (var i = 0, l = parts.length; i < l; i++) {
+ var name = parts[i];
+ var options = (
+ el === document
+ && (name === 'touchstart' || name === 'touchmove')
+ ) ? { passive: false } : false;
+ el.addEventListener(name, func, options);
+ }
}
}
},
@@ -12193,7 +12875,7 @@ var View = Base.extend(Emitter, {
if (window && element) {
this._id = element.getAttribute('id');
if (this._id == null)
- element.setAttribute('id', this._id = 'view-' + View._id++);
+ element.setAttribute('id', this._id = 'paper-view-' + View._id++);
DomEvent.add(element, this._viewEvents);
var none = 'none';
DomElement.setPrefixed(element.style, {
@@ -12379,7 +13061,7 @@ var View = Base.extend(Emitter, {
},
_changed: function() {
- this._project._changed(2049);
+ this._project._changed(4097);
this._bounds = this._decomposed = undefined;
},
@@ -12465,8 +13147,9 @@ var View = Base.extend(Emitter, {
}, Base.each(['rotate', 'scale', 'shear', 'skew'], function(key) {
var rotate = key === 'rotate';
this[key] = function() {
- var value = (rotate ? Base : Point).read(arguments),
- center = Point.read(arguments, 0, { readNull: true });
+ var args = arguments,
+ value = (rotate ? Base : Point).read(args),
+ center = Point.read(args, 0, { readNull: true });
return this.transform(new Matrix()[key](value,
center || this.getCenter(true)));
};
@@ -12490,9 +13173,8 @@ var View = Base.extend(Emitter, {
},
getZoom: function() {
- var decomposed = this._decompose(),
- scaling = decomposed && decomposed.scaling;
- return scaling ? (scaling.x + scaling.y) / 2 : 0;
+ var scaling = this._decompose().scaling;
+ return (scaling.x + scaling.y) / 2;
},
setZoom: function(zoom) {
@@ -12501,8 +13183,7 @@ var View = Base.extend(Emitter, {
},
getRotation: function() {
- var decomposed = this._decompose();
- return decomposed && decomposed.rotation;
+ return this._decompose().rotation;
},
setRotation: function(rotation) {
@@ -12513,11 +13194,8 @@ var View = Base.extend(Emitter, {
},
getScaling: function() {
- var decomposed = this._decompose(),
- scaling = decomposed && decomposed.scaling;
- return scaling
- ? new LinkedPoint(scaling.x, scaling.y, this, 'setScaling')
- : undefined;
+ var scaling = this._decompose().scaling;
+ return new LinkedPoint(scaling.x, scaling.y, this, 'setScaling');
},
setScaling: function() {
@@ -12747,8 +13425,8 @@ new function() {
point, prevPoint)
|| hitItem && hitItem !== dragItem
&& !hitItem.isDescendant(dragItem)
- && emitMouseEvent(hitItem, null, type, event, point, prevPoint,
- dragItem)
+ && emitMouseEvent(hitItem, null, type === 'mousedrag' ?
+ 'mousemove' : type, event, point, prevPoint, dragItem)
|| emitMouseEvent(view, dragItem || hitItem || view, type, event,
point, prevPoint));
}
@@ -12858,8 +13536,12 @@ new function() {
|| called;
}
- if (called && !mouse.move || mouse.down && responds('mouseup'))
+ if (
+ event.cancelable !== false
+ && (called && !mouse.move || mouse.down && responds('mouseup'))
+ ) {
event.preventDefault();
+ }
},
_handleKeyEvent: function(type, event, key, character) {
@@ -12894,7 +13576,14 @@ new function() {
},
statics: {
- updateFocus: updateFocus
+ updateFocus: updateFocus,
+
+ _resetState: function() {
+ dragging = mouseDown = called = wasInView = false;
+ prevFocus = tempFocus = overView = downPoint = lastPoint =
+ downItem = overItem = dragItem = clickItem = clickTime =
+ dblClick = null;
+ }
}
};
});
@@ -12946,6 +13635,10 @@ var CanvasView = View.extend({
}
},
+ getContext: function() {
+ return this._context;
+ },
+
getPixelSize: function getPixelSize(size) {
var agent = paper.agent,
pixels;
@@ -13362,7 +14055,7 @@ var Tool = PaperScopeItem.extend({
var pt = point,
toolPoint = move ? tool._point : (tool._downPoint || pt);
if (move) {
- if (tool._moveCount && pt.equals(toolPoint)) {
+ if (tool._moveCount >= 0 && pt.equals(toolPoint)) {
return false;
}
if (toolPoint && (minDistance != null || maxDistance != null)) {
@@ -13409,6 +14102,245 @@ var Tool = PaperScopeItem.extend({
});
+var Tween = Base.extend(Emitter, {
+ _class: 'Tween',
+
+ statics: {
+ easings: {
+ linear: function(t) {
+ return t;
+ },
+
+ easeInQuad: function(t) {
+ return t * t;
+ },
+
+ easeOutQuad: function(t) {
+ return t * (2 - t);
+ },
+
+ easeInOutQuad: function(t) {
+ return t < 0.5
+ ? 2 * t * t
+ : -1 + 2 * (2 - t) * t;
+ },
+
+ easeInCubic: function(t) {
+ return t * t * t;
+ },
+
+ easeOutCubic: function(t) {
+ return --t * t * t + 1;
+ },
+
+ easeInOutCubic: function(t) {
+ return t < 0.5
+ ? 4 * t * t * t
+ : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
+ },
+
+ easeInQuart: function(t) {
+ return t * t * t * t;
+ },
+
+ easeOutQuart: function(t) {
+ return 1 - (--t) * t * t * t;
+ },
+
+ easeInOutQuart: function(t) {
+ return t < 0.5
+ ? 8 * t * t * t * t
+ : 1 - 8 * (--t) * t * t * t;
+ },
+
+ easeInQuint: function(t) {
+ return t * t * t * t * t;
+ },
+
+ easeOutQuint: function(t) {
+ return 1 + --t * t * t * t * t;
+ },
+
+ easeInOutQuint: function(t) {
+ return t < 0.5
+ ? 16 * t * t * t * t * t
+ : 1 + 16 * (--t) * t * t * t * t;
+ }
+ }
+ },
+
+ 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();
+ }
+ },
+
+ then: function(then) {
+ this._then = then;
+ return this;
+ },
+
+ start: function() {
+ this._startTime = null;
+ this.running = true;
+ return this;
+ },
+
+ stop: function() {
+ this.running = false;
+ return this;
+ },
+
+ update: function(progress) {
+ if (this.running) {
+ if (progress > 1) {
+ 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]),
+ 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) {
+ this._then(this.object);
+ }
+ if (this.responds('update')) {
+ this.emit('update', new Base({
+ progress: progress,
+ factor: factor
+ }));
+ }
+ }
+ return this;
+ },
+
+ _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]);
+ this._setProperty(path, resolved);
+ value = this._getProperty(path);
+ value = value && value.clone ? value.clone() : value;
+ this._setProperty(path, current);
+ } else {
+ 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 &&
+ 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
+ .replace(/\.([^.]*)/g, '/$1')
+ .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;
+ }
+ }
+});
+
var Http = {
request: function(options) {
var xhr = new self.XMLHttpRequest();
@@ -13841,11 +14773,16 @@ new function() {
var attrs = new Base(),
trans = matrix.getTranslation();
if (coordinates) {
- matrix = matrix._shiftless();
- var point = matrix._inverseTransform(trans);
+ var point;
+ if (matrix.isInvertible()) {
+ matrix = matrix._shiftless();
+ point = matrix._inverseTransform(trans);
+ trans = null;
+ } else {
+ point = new Point();
+ }
attrs[center ? 'cx' : 'x'] = point.x;
attrs[center ? 'cy' : 'y'] = point.y;
- trans = null;
}
if (!matrix.isIdentity()) {
var decomposed = matrix.decompose();
@@ -13986,7 +14923,7 @@ new function() {
definition = item._definition,
node = getDefinition(definition, 'symbol'),
definitionItem = definition._item,
- bounds = definitionItem.getBounds();
+ bounds = definitionItem.getStrokeBounds();
if (!node) {
node = SvgElement.create('symbol', {
viewBox: formatter.rectangle(bounds)
@@ -14003,7 +14940,7 @@ new function() {
return SvgElement.create('use', attrs, formatter);
}
- function exportGradient(color) {
+ function exportGradient(color, item) {
var gradientNode = getDefinition(color, 'color');
if (!gradientNode) {
var gradient = color.getGradient(),
@@ -14030,6 +14967,11 @@ new function() {
y2: destination.y
};
}
+ if (item instanceof paper.PointText) {
+ attrs.gradientTransform = getTransform(
+ item._matrix.clone().invert(), false, formatter).transform;
+ }
+
attrs.gradientUnits = 'userSpaceOnUse';
gradientNode = SvgElement.create((radial ? 'radial' : 'linear')
+ 'Gradient', attrs, formatter);
@@ -14055,9 +14997,18 @@ new function() {
}
function exportText(item) {
- var node = SvgElement.create('text', getTransform(item._matrix, true),
+ var node = SvgElement.create('text', getTransform(item._matrix, false),
formatter);
- node.textContent = item._content;
+ node.setAttribute('font-size', item.fontSize);
+ node.setAttribute('xml:space', 'preserve');
+ for (var i = 0; i < item._lines.length; i++) {
+ var tspanNode = SvgElement.create('tspan', {
+ x: '0',
+ dy: i === 0 ? '0' : item.getLeading() + 'px'
+ }, formatter);
+ tspanNode.textContent = item._lines[i] ? item._lines[i] : ' ';
+ node.appendChild(tspanNode);
+ }
return node;
}
@@ -14084,9 +15035,13 @@ new function() {
var get = entry.get,
type = entry.type,
value = item[get]();
+
+ if (value === undefined) return;
+
if (entry.exportFilter
? entry.exportFilter(item, value)
- : !parent || !Base.equals(parent[get](), value)) {
+ : !parent || !Base.equals(parent[get](), value) ||
+ item instanceof paper.PointText) {
if (type === 'color' && value != null) {
var alpha = value.getAlpha();
if (alpha < 1)
@@ -14196,7 +15151,7 @@ new function() {
rect = bounds === 'view'
? new Rectangle([0, 0], view.getViewSize())
: bounds === 'content'
- ? Item._getBounds(children, matrix, { stroke: true })
+ ? Item._getBounds(children, matrix, { stroke: true, drawnTextBounds: true })
.rect
: Rectangle.read([bounds], 0, { readNull: true }),
attrs = {
@@ -14207,7 +15162,7 @@ new function() {
if (rect) {
attrs.width = rect.width;
attrs.height = rect.height;
- if (rect.x || rect.y)
+ if (rect.x || rect.x === 0 || rect.y || rect.y === 0)
attrs.viewBox = formatter.rectangle(rect);
}
var node = SvgElement.create('svg', attrs, formatter),
@@ -14229,8 +15184,9 @@ new function() {
var definitions = {},
rootSize;
- function getValue(node, name, isString, allowNull, allowPercent) {
- var value = SvgElement.get(node, name),
+ function getValue(node, name, isString, allowNull, allowPercent,
+ defaultValue) {
+ var value = SvgElement.get(node, name) || defaultValue,
res = value == null
? allowNull
? null
@@ -14244,9 +15200,9 @@ new function() {
: res;
}
- function getPoint(node, x, y, allowNull, allowPercent) {
- x = getValue(node, x || 'x', false, allowNull, allowPercent);
- y = getValue(node, y || 'y', false, allowNull, allowPercent);
+ function getPoint(node, x, y, allowNull, allowPercent, defaultX, defaultY) {
+ x = getValue(node, x || 'x', false, allowNull, allowPercent, defaultX);
+ y = getValue(node, y || 'y', false, allowNull, allowPercent, defaultY);
return allowNull && (x == null || y == null) ? null
: new Point(x, y);
}
@@ -14348,13 +15304,16 @@ new function() {
scaleToBounds = getValue(node, 'gradientUnits', true) !==
'userSpaceOnUse';
if (radial) {
- origin = getPoint(node, 'cx', 'cy', false, scaleToBounds);
+ origin = getPoint(node, 'cx', 'cy', false, scaleToBounds,
+ '50%', '50%');
destination = origin.add(
- getValue(node, 'r', false, false, scaleToBounds), 0);
+ getValue(node, 'r', false, false, scaleToBounds, '50%'), 0);
highlight = getPoint(node, 'fx', 'fy', true, scaleToBounds);
} else {
- origin = getPoint(node, 'x1', 'y1', false, scaleToBounds);
- destination = getPoint(node, 'x2', 'y2', false, scaleToBounds);
+ origin = getPoint(node, 'x1', 'y1', false, scaleToBounds,
+ '0%', '0%');
+ destination = getPoint(node, 'x2', 'y2', false, scaleToBounds,
+ '100%', '0%');
}
var color = applyAttributes(
new Color(gradient, origin, destination, highlight), node);
@@ -14385,9 +15344,8 @@ new function() {
raster.on('load', function() {
var size = getSize(node);
this.setSize(size);
- var center = this._matrix._transformPoint(
- getPoint(node).add(size.divide(2)));
- this.translate(center);
+ var center = getPoint(node).add(size.divide(2));
+ this._matrix.append(new Matrix().translate(center));
});
return raster;
},
@@ -14437,11 +15395,47 @@ new function() {
},
text: function(node) {
- var text = new PointText(getPoint(node).add(
- getPoint(node, 'dx', 'dy')));
- text.setContent(node.textContent.trim() || '');
- return text;
- }
+
+ var fontSize = parseFloat(node.getAttribute("font-size"));
+ var alignmentBaseline = node.getAttribute("alignment-baseline");
+ if (node.childElementCount === 0) {
+ var text = new PointText();
+ text.setContent(node.textContent.trim() || '');
+ text.translate(0, text._style.getLeading());
+ if (!isNaN(fontSize)) text.setFontSize(fontSize);
+ return text;
+ } else {
+ var lines = [];
+ var spacing = 1.2;
+ for (var i = 0; i < node.childNodes.length; i++) {
+ var child = node.childNodes[i];
+ if (!child.getAttribute) continue;
+ lines.push(child.textContent);
+ var dyString = child.getAttribute('dy');
+ if (dyString) {
+ var dy = parseFloat(dyString);
+ if (!isNaN(dy)) {
+ if (dyString.endsWith('em')) {
+ spacing = dy;
+ } else if (dyString.endsWith('px') && !isNaN(fontSize)) {
+ spacing = dy / fontSize;
+ }
+ }
+ }
+ }
+ var text = new PointText();
+ if (!isNaN(fontSize)) text.setFontSize(fontSize);
+ text.setLeading(text.fontSize * spacing);
+ if (alignmentBaseline === 'text-before-edge') {
+ text.setContent(' ');
+ text.translate(0, text.bounds.height);
+ }
+ text.setContent(lines.join('\n'));
+ return text;
+ }
+ },
+
+ switch: importGroup
};
function applyTransform(item, value, name, node) {
@@ -14463,10 +15457,10 @@ new function() {
new Matrix(v[0], v[1], v[2], v[3], v[4], v[5]));
break;
case 'rotate':
- matrix.rotate(v[0], v[1], v[2]);
+ matrix.rotate(v[0], v[1] || 0, v[2] || 0);
break;
case 'translate':
- matrix.translate(v[0], v[1]);
+ matrix.translate(v[0], v[1] || 0);
break;
case 'scale':
matrix.scale(v);
@@ -14510,8 +15504,6 @@ new function() {
}, {}), {
id: function(item, value) {
definitions[value] = item;
- if (item.setName)
- item.setName(value);
},
'clip-path': function(item, value) {
@@ -14584,13 +15576,17 @@ new function() {
if (matrix)
group.transform(matrix);
}
+ },
+
+ 'fill-rule': function(item, value) {
+ if (value === 'evenodd' || value === 'nonzero') item.fillRule = value;
}
});
function getAttribute(node, name, styles) {
var attr = node.attributes[name],
value = attr && attr.value;
- if (!value) {
+ if (!value && node.style) {
var style = Base.camelize(name);
value = node.style[style];
if (!value && styles.node[style] !== styles.parent[style])
@@ -14602,19 +15598,17 @@ new function() {
}
function applyAttributes(item, node, isRoot) {
- if (node.style) {
- var parent = node.parentNode,
- styles = {
- node: DomElement.getStyles(node) || {},
- parent: !isRoot && !/^defs$/i.test(parent.tagName)
- && DomElement.getStyles(parent) || {}
- };
- Base.each(attributes, function(apply, name) {
- var value = getAttribute(node, name, styles);
- item = value !== undefined
- && apply(item, value, name, node, styles) || item;
- });
- }
+ var parent = node.parentNode,
+ styles = {
+ node: DomElement.getStyles(node) || {},
+ parent: !isRoot && !/^defs$/i.test(parent.tagName)
+ && DomElement.getStyles(parent) || {}
+ };
+ Base.each(attributes, function(apply, name) {
+ var value = getAttribute(node, name, styles);
+ item = value !== undefined
+ && apply(item, value, name, node, styles) || item;
+ });
return item;
}
@@ -14700,8 +15694,12 @@ new function() {
function onLoad(svg) {
try {
- var node = typeof svg === 'object' ? svg : new self.DOMParser()
- .parseFromString(svg, 'image/svg+xml');
+ var node = typeof svg === 'object'
+ ? svg
+ : new self.DOMParser().parseFromString(
+ svg,
+ 'image/svg+xml'
+ );
if (!node.nodeName) {
node = null;
throw new Error('Unsupported SVG source: ' + source);
@@ -14728,7 +15726,7 @@ new function() {
}
}
- if (typeof source === 'string' && !/^.*= 30
|| agent.webkit && version >= 537.76
@@ -16321,7 +17370,16 @@ Base.exports.PaperScript = function() {
sourcesContent: [source]
};
}
- walkAST(parse(code, { ranges: true, preserveParens: true }));
+ if (
+ paperFeatures.operatorOverloading !== false ||
+ paperFeatures.moduleExports !== false
+ ) {
+ walkAST(parse(code, {
+ ranges: true,
+ preserveParens: true,
+ sourceType: 'module'
+ }), null, paperFeatures);
+ }
if (map) {
if (offsetCode) {
code = new Array(offset + 1).join('\n') + code;
@@ -16363,17 +17421,20 @@ Base.exports.PaperScript = function() {
}
}
}
- expose({ __$__: __$__, $__: $__, paper: scope, view: view, tool: tool },
+ expose({ __$__: __$__, $__: $__, paper: scope, tool: tool },
true);
expose(scope);
- handlers = Base.each(handlers, function(key) {
+ code = 'var module = { exports: {} }; ' + code;
+ var exports = Base.each(handlers, function(key) {
if (new RegExp('\\s+' + key + '\\b').test(code)) {
params.push(key);
- this.push(key + ': ' + key);
+ this.push('module.exports.' + key + ' = ' + key + ';');
}
- }, []).join(', ');
- if (handlers)
- code += '\nreturn { ' + handlers + ' };';
+ }, []).join('\n');
+ if (exports) {
+ code += '\n' + exports;
+ }
+ code += '\nreturn module.exports;';
var agent = paper.agent;
if (document && (agent.chrome
|| agent.firefox && agent.versionNumber < 40)) {
@@ -16382,33 +17443,36 @@ Base.exports.PaperScript = function() {
if (agent.firefox)
code = '\n' + code;
script.appendChild(document.createTextNode(
- 'paper._execute = function(' + params + ') {' + code + '\n}'
+ 'document.__paperscript__ = function(' + params + ') {' +
+ code +
+ '\n}'
));
head.appendChild(script);
- func = paper._execute;
- delete paper._execute;
+ func = document.__paperscript__;
+ delete document.__paperscript__;
head.removeChild(script);
} else {
func = Function(params, code);
}
- var res = func.apply(scope, args) || {};
+ var exports = func && func.apply(scope, args);
+ var obj = exports || {};
Base.each(toolHandlers, function(key) {
- var value = res[key];
+ var value = obj[key];
if (value)
tool[key] = value;
});
if (view) {
- if (res.onResize)
- view.setOnResize(res.onResize);
+ if (obj.onResize)
+ view.setOnResize(obj.onResize);
view.emit('resize', {
size: view.size,
delta: new Point()
});
- if (res.onFrame)
- view.setOnFrame(res.onFrame);
+ if (obj.onFrame)
+ view.setOnFrame(obj.onFrame);
view.requestUpdate();
}
- return compiled;
+ return exports;
}
function loadScript(script) {
@@ -16463,12 +17527,14 @@ Base.exports.PaperScript = function() {
compile: compile,
execute: execute,
load: load,
- parse: parse
+ parse: parse,
+ calculateBinary: __$__,
+ calculateUnary: $__
};
}.call(this);
-paper = new (PaperScope.inject(Base.exports, {
+var paper = new (PaperScope.inject(Base.exports, {
Base: Base,
Numerical: Numerical,
Key: Key,
diff --git a/dist/paper-full.min.js b/dist/paper-full.min.js
index b608f199..6cdd1e64 100644
--- a/dist/paper-full.min.js
+++ b/dist/paper-full.min.js
@@ -1,39 +1,39 @@
/*!
- * Paper.js v0.11.5-develop - The Swiss Army Knife of Vector Graphics Scripting.
+ * Paper.js v0.12.7 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
- * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
- * http://scratchdisk.com/ & http://jonathanpuckey.com/
+ * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
+ * http://juerglehni.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
- * Date: Sun Oct 8 17:48:20 2017 +0200
+ * Date: Mon Oct 30 15:37:23 2023 -0400
*
***
*
* Straps.js - Class inheritance library with support for bean-style accessors
*
- * Copyright (c) 2006 - 2016 Juerg Lehni
- * http://scratchdisk.com/
+ * Copyright (c) 2006 - 2020 Jürg Lehni
+ * http://juerglehni.com/
*
* Distributed under the MIT license.
*
***
*
* Acorn.js
- * http://marijnhaverbeke.nl/acorn/
+ * https://marijnhaverbeke.nl/acorn/
*
* Acorn is a tiny, fast JavaScript parser written in JavaScript,
* created by Marijn Haverbeke and released under an MIT license.
*
*/
-var paper=function(t,e){t=t||require("./node/self.js");var n=t.window,i=t.document,r=new function(){function t(t,e,r,s,a){function u(i,u){u=u||(u=o(e,i))&&(u.get?u:u.value),"string"==typeof u&&"#"===u[0]&&(u=t[u.substring(1)]||u);var c,f="function"==typeof u,d=u,_=a||f&&!u.base?u&&u.get?i in t:t[i]:null;a&&_||(f&&_&&(u.base=_),f&&s!==!1&&(c=i.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(l[c[3].toLowerCase()+c[4]]=c[2]),d&&!f&&d.get&&"function"==typeof d.get&&n.isPlainObject(d)||(d={value:d,writable:!0}),(o(t,i)||{configurable:!0}).configurable&&(d.configurable=!0,d.enumerable=null!=r?r:!c),h(t,i,d))}var l={};if(e){for(var c in e)e.hasOwnProperty(c)&&!i.test(c)&&u(c);for(var c in l){var f=l[c],d=t["set"+f],_=t["get"+f]||d&&t["is"+f];!_||s!==!0&&0!==_.length||u(c,{get:_,set:d})}}return t}function n(){for(var t=0,e=arguments.length;t0||u+s0?[["dictionary",i.definitions],s]:s},deserialize:function(t,e,n,i,s){var a=t,o=!n,h=o&&t&&t.length&&"dictionary"===t[0][0];if(n=n||{},Array.isArray(t)){var u=t[0],l="dictionary"===u;if(1==t.length&&/^#/.test(u))return n.dictionary[u];u=r.exports[u],a=[];for(var c=u?1:0,f=t.length;ct.length&&(i=t.length);for(var o=0;o0){var s=e[r],a=s&&s[i];a&&a.call(this,r)}},statics:{inject:function st(t){var e=t._events;if(e){var n={};r.each(e,function(e,i){var s="string"==typeof e,a=s?e:i,o=r.capitalize(a),h=a.substring(2).toLowerCase();n[h]=s?{}:e,a="_"+a,t["get"+o]=function(){return this[a]},t["set"+o]=function(t){var e=this[a];e&&this.off(h,e),t&&this.on(h,t),this[a]=t}}),t._eventTypes=n}return st.base.apply(this,arguments)}}},a=r.extend({_class:"PaperScope",initialize:function at(){paper=this,this.settings=new r({applyMatrix:!0,insertItems:!0,handleSize:4,hitTolerance:0}),this.project=null,this.projects=[],this.tools=[],this._id=at._id++,at._scopes[this._id]=this;var e=at.prototype;if(!this.support){var n=tt.getContext(1,1)||{};e.support={nativeDash:"setLineDash"in n||"mozDash"in n,nativeBlendModes:et.nativeModes},tt.release(n)}if(!this.agent){var i=t.navigator.userAgent.toLowerCase(),s=(/(darwin|win|mac|linux|freebsd|sunos)/.exec(i)||[])[0],a="darwin"===s?"mac":s,o=e.agent=e.browser={platform:a};a&&(o[a]=!0),i.replace(/(opera|chrome|safari|webkit|firefox|msie|trident|atom|node)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g,function(t,e,n,i,r){if(!o.chrome){var s="opera"===e?i:/^(node|trident)$/.test(e)?r:n;o.version=s,o.versionNumber=parseFloat(s),e="trident"===e?"msie":e,o.name=e,o[e]=!0}}),o.chrome&&delete o.webkit,o.atom&&delete o.chrome}},version:"0.11.5-develop",getView:function(){var t=this.project;return t&&t._view},getPaper:function(){return this},execute:function(t,e){paper.PaperScript.execute(t,this,e),Z.updateFocus()},install:function(t){var e=this;r.each(["project","view","tool"],function(n){r.define(t,n,{configurable:!0,get:function(){return e[n]}})});for(var n in this)!/^_/.test(n)&&this[n]&&(t[n]=this[n])},setup:function(t){return paper=this,this.project=new y(t),this},createCanvas:function(t,e){return tt.getCanvas(t,e)},activate:function(){paper=this},clear:function(){for(var t=this.projects,e=this.tools,n=t.length-1;n>=0;n--)t[n].remove();for(var n=e.length-1;n>=0;n--)e[n].remove()},remove:function(){this.clear(),delete a._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,n){return e[t](n)||e[t]("data-paper-"+n)}}return{_scopes:{},_id:0,get:function(t){return this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),o=r.extend(s,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,!t&&this._scope[this._reference]||this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!==this&&t.emit("deactivate"),this._scope[this._reference]=this,this.emit("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null!=this._index&&(r.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)},getView:function(){return this._scope.getView()}}),h=r.extend({initialize:function(t){this.precision=r.pick(t,5),this.multiplier=Math.pow(10,this.precision)},number:function(t){return this.precision<16?Math.round(t*this.multiplier)/this.multiplier:t},pair:function(t,e,n){return this.number(t)+(n||",")+this.number(e)},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});h.instance=new h;var u=new function(){function t(t,e,n){return tn?n:t}function e(t,e,n){function i(t){var e=134217729*t,n=t-e,i=n+e,r=t-i;return[i,r]}var r=e*e-t*n,a=e*e+t*n;if(3*s(r)1e8)?o(2,-Math.round(h(t))):0}var i=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],r=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],s=Math.abs,a=Math.sqrt,o=Math.pow,h=Math.log2||function(t){return Math.log(t)*Math.LOG2E},l=1e-12,c=1.12e-16;return{EPSILON:l,MACHINE_EPSILON:c,CURVETIME_EPSILON:1e-8,GEOMETRIC_EPSILON:1e-7,TRIGONOMETRIC_EPSILON:1e-8,KAPPA:4*(a(2)-1)/3,isZero:function(t){return t>=-l&&t<=l},clamp:t,integrate:function(t,e,n,s){for(var a=i[s-2],o=r[s-2],h=.5*(n-e),u=h+e,l=0,c=s+1>>1,f=1&s?o[l++]*t(u):0;l0?(a=i,i=f<=r?.5*(r+a):f):(r=i,i=f>=a?.5*(r+a):f)}return t(i,r,a)},solveQuadratic:function(i,r,o,h,u,f){var d,_=1/0;if(s(i)=-c){var p=g<0?0:a(g),m=r+(r<0?-p:p);0===m?(d=o/i,_=-d):(d=m/i,_=o/m)}}var y=0,w=null==u,x=u-l,b=f+l;return isFinite(d)&&(w||d>x&&dx&&_0?1.324717957244746*Math.max(C,a(k)):C,P=v-S*I;if(P!==v){do g(P),P=0===y?v:v-w/y/(1+c);while(S*P>S*v);s(e)*v*v>s(h/v)&&(m=-h/v,p=(m-r)/v)}}var A=u.solveQuadratic(e,p,m,f,d,_),M=null==d;return isFinite(v)&&(0===A||A>0&&v!==f[0]&&v!==f[1])&&(M||v>d-l&&v<_+l)&&(f[A++]=M?v:t(v,d,_)),A}}},l={_id:1,_pools:{},get:function(t){if(t){var e=this._pools[t];return e||(e=this._pools[t]={_id:1}),e._id++}return this._id++}},c=r.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var n=typeof t,i=this.__read,r=0;if("number"===n){var s="number"==typeof e;this._set(t,s?e:t),i&&(r=s?2:1)}else if("undefined"===n||null===t)this._set(0,0),i&&(r=null===t?1:0);else{var a="string"===n?t.split(/[\s,]+/)||[]:t;r=1,Array.isArray(a)?this._set(+a[0],+(a.length>1?a[1]:a[0])):"x"in a?this._set(a.x||0,a.y||0):"width"in a?this._set(a.width||0,a.height||0):"angle"in a?(this._set(a.length||0,0),this.setAngle(a.angle||0)):(this._set(0,0),r=0)}return i&&(this.__read=r),this},set:"#initialize",_set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return this===t||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new c(this.x,this.y)},toString:function(){var t=h.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},getLength:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this._set(Math.cos(e)*t,Math.sin(e)*t)}else{var n=t/this.getLength();u.isZero(n)&&this.getAngle(),this._set(this.x*n,this.y*n)}},getAngle:function(){return 180*this.getAngleInRadians.apply(this,arguments)/Math.PI},setAngle:function(t){this.setAngleInRadians.call(this,t*Math.PI/180)},getAngleInDegrees:"#getAngle",setAngleInDegrees:"#setAngle",getAngleInRadians:function(){if(arguments.length){var t=c.read(arguments),e=this.getLength()*t.getLength();if(u.isZero(e))return NaN;var n=this.dot(t)/e;return Math.acos(n<-1?-1:n>1?1:n)}return this.isZero()?this._angle||0:this._angle=Math.atan2(this.y,this.x)},setAngleInRadians:function(t){if(this._angle=t,!this.isZero()){var e=this.getLength();this._set(Math.cos(t)*e,Math.sin(t)*e)}},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3}},{beans:!1,getDirectedAngle:function(){var t=c.read(arguments);return 180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},getDistance:function(){var t=c.read(arguments),e=t.x-this.x,n=t.y-this.y,i=e*e+n*n,s=r.read(arguments);return s?i:Math.sqrt(i)},normalize:function(t){t===e&&(t=1);var n=this.getLength(),i=0!==n?t/n:0,r=new c(this.x*i,this.y*i);return i>=0&&(r._angle=this._angle),r},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var n=e?this.subtract(e):this,i=Math.sin(t),r=Math.cos(t);return n=new c(n.x*r-n.y*i,n.x*i+n.y*r),e?n.add(e):n},transform:function(t){return t?t._transformPoint(this):this},add:function(){var t=c.read(arguments);return new c(this.x+t.x,this.y+t.y)},subtract:function(){var t=c.read(arguments);return new c(this.x-t.x,this.y-t.y)},multiply:function(){var t=c.read(arguments);return new c(this.x*t.x,this.y*t.y)},divide:function(){var t=c.read(arguments);return new c(this.x/t.x,this.y/t.y)},modulo:function(){var t=c.read(arguments);return new c(this.x%t.x,this.y%t.y)},negate:function(){return new c((-this.x),(-this.y))},isInside:function(){return g.read(arguments).contains(this)},isClose:function(){var t=c.read(arguments),e=r.read(arguments);return this.getDistance(t)<=e},isCollinear:function(){var t=c.read(arguments);return c.isCollinear(this.x,this.y,t.x,t.y)},isColinear:"#isCollinear",isOrthogonal:function(){var t=c.read(arguments);return c.isOrthogonal(this.x,this.y,t.x,t.y)},isZero:function(){var t=u.isZero;return t(this.x)&&t(this.y)},isNaN:function(){return isNaN(this.x)||isNaN(this.y)},isInQuadrant:function(t){return this.x*(t>1&&t<4?-1:1)>=0&&this.y*(t>2?-1:1)>=0},dot:function(){var t=c.read(arguments);return this.x*t.x+this.y*t.y},cross:function(){var t=c.read(arguments);return this.x*t.y-this.y*t.x},project:function(){var t=c.read(arguments),e=t.isZero()?0:this.dot(t)/t.dot(t);return new c(t.x*e,t.y*e)},statics:{min:function(){var t=c.read(arguments),e=c.read(arguments);return new c(Math.min(t.x,e.x),Math.min(t.y,e.y))},max:function(){var t=c.read(arguments),e=c.read(arguments);return new c(Math.max(t.x,e.x),Math.max(t.y,e.y))},random:function(){return new c(Math.random(),Math.random())},isCollinear:function(t,e,n,i){return Math.abs(t*i-e*n)<=1e-8*Math.sqrt((t*t+e*e)*(n*n+i*i))},isOrthogonal:function(t,e,n,i){return Math.abs(t*n+e*i)<=1e-8*Math.sqrt((t*t+e*e)*(n*n+i*i))}}},r.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.x),e(this.y))}},{})),f=c.extend({initialize:function(t,e,n,i){this._x=t,this._y=e,this._owner=n,this._setter=i},_set:function(t,e,n){return this._x=t,this._y=e,n||this._owner[this._setter](this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner[this._setter](this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner[this._setter](this)},isSelected:function(){return!!(this._owner._selection&this._getSelection())},setSelected:function(t){this._owner._changeSelection(this._getSelection(),t)},_getSelection:function(){return"setPosition"===this._setter?4:0}}),d=r.extend({_class:"Size",_readIndex:!0,initialize:function(t,e){var n=typeof t,i=this.__read,r=0;if("number"===n){var s="number"==typeof e;this._set(t,s?e:t),i&&(r=s?2:1)}else if("undefined"===n||null===t)this._set(0,0),i&&(r=null===t?1:0);else{var a="string"===n?t.split(/[\s,]+/)||[]:t;r=1,Array.isArray(a)?this._set(+a[0],+(a.length>1?a[1]:a[0])):"width"in a?this._set(a.width||0,a.height||0):"x"in a?this._set(a.x||0,a.y||0):(this._set(0,0),r=0)}return i&&(this.__read=r),this},set:"#initialize",_set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new d(this.width,this.height)},toString:function(){var t=h.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(){var t=d.read(arguments);return new d(this.width+t.width,this.height+t.height)},subtract:function(){var t=d.read(arguments);return new d(this.width-t.width,this.height-t.height)},multiply:function(){var t=d.read(arguments);return new d(this.width*t.width,this.height*t.height)},divide:function(){var t=d.read(arguments);return new d(this.width/t.width,this.height/t.height)},modulo:function(){var t=d.read(arguments);return new d(this.width%t.width,this.height%t.height)},negate:function(){return new d((-this.width),(-this.height))},isZero:function(){var t=u.isZero;return t(this.width)&&t(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new d(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new d(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new d(Math.random(),Math.random())}}},r.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new d(e(this.width),e(this.height))}},{})),_=d.extend({initialize:function(t,e,n,i){this._width=t,this._height=e,this._owner=n,this._setter=i},_set:function(t,e,n){return this._width=t,this._height=e,n||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),g=r.extend({_class:"Rectangle",_readIndex:!0,beans:!0,initialize:function(t,n,i,s){var a,o=typeof t;if("number"===o?(this._set(t,n,i,s),a=4):"undefined"===o||null===t?(this._set(0,0,0,0),a=null===t?1:0):1===arguments.length&&(Array.isArray(t)?(this._set.apply(this,t),a=1):t.x!==e||t.width!==e?(this._set(t.x||0,t.y||0,t.width||0,t.height||0),a=1):t.from===e&&t.to===e&&(this._set(0,0,0,0),r.filter(this,t),a=1)),a===e){var h,u,l=c.readNamed(arguments,"from"),f=r.peek(arguments),_=l.x,g=l.y;if(f&&f.x!==e||r.hasNamed(arguments,"to")){var v=c.readNamed(arguments,"to");h=v.x-_,u=v.y-g,h<0&&(_=v.x,h=-h),u<0&&(g=v.y,u=-u)}else{var p=d.read(arguments);h=p.width,u=p.height}this._set(_,g,h,u),a=arguments.__index;var m=arguments.__filtered;m&&(this.__filtered=m)}return this.__read&&(this.__read=a),this},set:"#initialize",_set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new g(this.x,this.y,this.width,this.height)},equals:function(t){var e=r.isPlainValue(t)?g.read(arguments):t;return e===this||e&&this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height||!1},toString:function(){var t=h.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(t){var e=t?c:f;return new e(this.x,this.y,this,"setPoint")},setPoint:function(){var t=c.read(arguments);this.x=t.x,this.y=t.y},getSize:function(t){var e=t?d:_;return new e(this.width,this.height,this,"setSize")},_fw:1,_fh:1,setSize:function(){var t=d.read(arguments),e=this._sx,n=this._sy,i=t.width,r=t.height;e&&(this.x+=(this.width-i)*e),n&&(this.y+=(this.height-r)*n),this.width=i,this.height=r,this._fw=this._fh=1},getLeft:function(){return this.x},setLeft:function(t){if(!this._fw){var e=t-this.x;this.width-=.5===this._sx?2*e:e}this.x=t,this._sx=this._fw=0},getTop:function(){return this.y},setTop:function(t){if(!this._fh){var e=t-this.y;this.height-=.5===this._sy?2*e:e}this.y=t,this._sy=this._fh=0},getRight:function(){return this.x+this.width},setRight:function(t){if(!this._fw){var e=t-this.x;this.width=.5===this._sx?2*e:e}this.x=t-this.width,this._sx=1,this._fw=0},getBottom:function(){return this.y+this.height},setBottom:function(t){if(!this._fh){var e=t-this.y;this.height=.5===this._sy?2*e:e}this.y=t-this.height,this._sy=1,this._fh=0},getCenterX:function(){return this.x+this.width/2},setCenterX:function(t){this._fw||.5===this._sx?this.x=t-this.width/2:(this._sx&&(this.x+=2*(t-this.x)*this._sx),this.width=2*(t-this.x)),this._sx=.5,this._fw=0},getCenterY:function(){return this.y+this.height/2},setCenterY:function(t){this._fh||.5===this._sy?this.y=t-this.height/2:(this._sy&&(this.y+=2*(t-this.y)*this._sy),this.height=2*(t-this.y)),this._sy=.5,this._fh=0},getCenter:function(t){var e=t?c:f;return new e(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(){var t=c.read(arguments);return this.setCenterX(t.x),this.setCenterY(t.y),this},getArea:function(){return this.width*this.height},isEmpty:function(){return 0===this.width||0===this.height},contains:function(t){return t&&t.width!==e||4===(Array.isArray(t)?t:arguments).length?this._containsRectangle(g.read(arguments)):this._containsPoint(c.read(arguments))},_containsPoint:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e<=this.x+this.width&&n<=this.y+this.height},_containsRectangle:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e+t.width<=this.x+this.width&&n+t.height<=this.y+this.height},intersects:function(){var t=g.read(arguments),e=r.read(arguments)||0;return t.x+t.width>this.x-e&&t.y+t.height>this.y-e&&t.x=4&&(t[1]+=i?"Y":"X");var r=t[i?0:1],s=t[i?1:0],a="get"+r,o="get"+s,h="set"+r,u="set"+s,l="get"+n,d="set"+n;this[l]=function(t){var e=t?c:f;return new e(this[a](),this[o](),this,d)},this[d]=function(){var t=c.read(arguments);this[h](t.x),this[u](t.y)}},{beans:!0})),v=g.extend({initialize:function(t,e,n,i,r,s){this._set(t,e,n,i,!0),this._owner=r,this._setter=s},_set:function(t,e,n,i,r){return this._x=t,this._y=e,this._width=n,this._height=i,r||this._owner[this._setter](this),this}},new function(){var t=g.prototype;return r.each(["x","y","width","height"],function(t){var e=r.capitalize(t),n="_"+t;this["get"+e]=function(){return this[n]},this["set"+e]=function(t){this[n]=t,this._dontNotify||this._owner[this._setter](this)}},r.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var n="set"+e;this[n]=function(){this._dontNotify=!0,t[n].apply(this,arguments),this._dontNotify=!1,this._owner[this._setter](this)}},{isSelected:function(){return!!(2&this._owner._selection)},setSelected:function(t){var e=this._owner;e._changeSelection&&e._changeSelection(2,t)}}))}),p=r.extend({_class:"Matrix",initialize:function ot(t,e){var n=arguments.length,i=!0;if(n>=6?this._set.apply(this,arguments):1===n||2===n?t instanceof ot?this._set(t._a,t._b,t._c,t._d,t._tx,t._ty,e):Array.isArray(t)?this._set.apply(this,e?t.concat([e]):t):i=!1:n?i=!1:this.reset(),!i)throw new Error("Unsupported matrix parameters");return this},set:"#initialize",_set:function(t,e,n,i,r,s,a){return this._a=t,this._b=e,this._c=n,this._d=i,this._tx=r,this._ty=s,a||this._changed(),this},_serialize:function(t,e){return r.serialize(this.getValues(),t,!0,e)},_changed:function(){var t=this._owner;t&&(t._applyMatrix?t.transform(null,!0):t._changed(9))},clone:function(){return new p(this._a,this._b,this._c,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty},toString:function(){var t=h.instance;return"[["+[t.number(this._a),t.number(this._c),t.number(this._tx)].join(", ")+"], ["+[t.number(this._b),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(t){return this._a=this._d=1,this._b=this._c=this._tx=this._ty=0,t||this._changed(),this},apply:function(t,e){var n=this._owner;return!!n&&(n.transform(null,!0,r.pick(t,!0),e),this.isIdentity())},translate:function(){var t=c.read(arguments),e=t.x,n=t.y;return this._tx+=e*this._a+n*this._c,this._ty+=e*this._b+n*this._d,this._changed(),this},scale:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._b*=t.x,this._c*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this._changed(),this},rotate:function(t){
-t*=Math.PI/180;var e=c.read(arguments,1),n=e.x,i=e.y,r=Math.cos(t),s=Math.sin(t),a=n-n*r+i*s,o=i-n*s-i*r,h=this._a,u=this._b,l=this._c,f=this._d;return this._a=r*h+s*l,this._b=r*u+s*f,this._c=-s*h+r*l,this._d=-s*u+r*f,this._tx+=a*h+o*l,this._ty+=a*u+o*f,this._changed(),this},shear:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0});e&&this.translate(e);var n=this._a,i=this._b;return this._a+=t.y*this._c,this._b+=t.y*this._d,this._c+=t.x*n,this._d+=t.x*i,e&&this.translate(e.negate()),this._changed(),this},skew:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0}),n=Math.PI/180,i=new c(Math.tan(t.x*n),Math.tan(t.y*n));return this.shear(i,e)},append:function(t,e){if(t){var n=this._a,i=this._b,r=this._c,s=this._d,a=t._a,o=t._c,h=t._b,u=t._d,l=t._tx,c=t._ty;this._a=a*n+h*r,this._c=o*n+u*r,this._b=a*i+h*s,this._d=o*i+u*s,this._tx+=l*n+c*r,this._ty+=l*i+c*s,e||this._changed()}return this},prepend:function(t,e){if(t){var n=this._a,i=this._b,r=this._c,s=this._d,a=this._tx,o=this._ty,h=t._a,u=t._c,l=t._b,c=t._d,f=t._tx,d=t._ty;this._a=h*n+u*i,this._c=h*r+u*s,this._b=l*n+c*i,this._d=l*r+c*s,this._tx=h*a+u*o+f,this._ty=l*a+c*o+d,e||this._changed()}return this},appended:function(t){return this.clone().append(t)},prepended:function(t){return this.clone().prepend(t)},invert:function(){var t=this._a,e=this._b,n=this._c,i=this._d,r=this._tx,s=this._ty,a=t*i-e*n,o=null;return a&&!isNaN(a)&&isFinite(r)&&isFinite(s)&&(this._a=i/a,this._b=-e/a,this._c=-n/a,this._d=t/a,this._tx=(n*s-i*r)/a,this._ty=(e*r-t*s)/a,o=this),o},inverted:function(){return this.clone().invert()},concatenate:"#append",preConcatenate:"#prepend",chain:"#appended",_shiftless:function(){return new p(this._a,this._b,this._c,this._d,0,0)},_orNullIfIdentity:function(){return this.isIdentity()?null:this},isIdentity:function(){return 1===this._a&&0===this._b&&0===this._c&&1===this._d&&0===this._tx&&0===this._ty},isInvertible:function(){var t=this._a*this._d-this._c*this._b;return t&&!isNaN(t)&&isFinite(this._tx)&&isFinite(this._ty)},isSingular:function(){return!this.isInvertible()},transform:function(t,e,n){return arguments.length<3?this._transformPoint(c.read(arguments)):this._transformCoordinates(t,e,n)},_transformPoint:function(t,e,n){var i=t.x,r=t.y;return e||(e=new c),e._set(i*this._a+r*this._c+this._tx,i*this._b+r*this._d+this._ty,n)},_transformCoordinates:function(t,e,n){for(var i=0,r=2*n;is[h]&&(s[h]=o)}return e||(e=new g),e._set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(c.read(arguments))},_inverseTransform:function(t,e,n){var i=this._a,r=this._b,s=this._c,a=this._d,o=this._tx,h=this._ty,u=i*a-r*s,l=null;if(u&&!isNaN(u)&&isFinite(o)&&isFinite(h)){var f=t.x-this._tx,d=t.y-this._ty;e||(e=new c),l=e._set((f*a-d*s)/u,(d*i-f*r)/u,n)}return l},decompose:function(){var t,e,n,i=this._a,r=this._b,s=this._c,a=this._d,o=i*a-r*s,h=Math.sqrt,u=Math.atan2,l=180/Math.PI;if(0!==i||0!==r){var f=h(i*i+r*r);t=Math.acos(i/f)*(r>0?1:-1),e=[f,o/f],n=[u(i*s+r*a,f*f),0]}else if(0!==s||0!==a){var d=h(s*s+a*a);t=Math.asin(s/d)*(a>0?1:-1),e=[o/d,d],n=[0,u(i*s+r*a,d*d)]}else t=0,n=e=[0,0];return{translation:this.getTranslation(),rotation:t*l,scaling:new c(e),skewing:new c(n[0]*l,n[1]*l)}},getValues:function(){return[this._a,this._b,this._c,this._d,this._tx,this._ty]},getTranslation:function(){return new c(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},applyToContext:function(t){this.isIdentity()||t.transform(this._a,this._b,this._c,this._d,this._tx,this._ty)}},r.each(["a","b","c","d","tx","ty"],function(t){var e=r.capitalize(t),n="_"+t;this["get"+e]=function(){return this[n]},this["set"+e]=function(t){this[n]=t,this._changed()}},{})),m=r.extend({_class:"Line",initialize:function(t,e,n,i,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=n),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new c(this._px,this._py)},getVector:function(){return new c(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return m.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t,e){return m.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0,e)},getDistance:function(t){return Math.abs(this.getSignedDistance(t))},getSignedDistance:function(t){return m.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},isCollinear:function(t){return c.isCollinear(this._vx,this._vy,t._vx,t._vy)},isOrthogonal:function(t){return c.isOrthogonal(this._vx,this._vy,t._vx,t._vy)},statics:{intersect:function(t,e,n,i,r,s,a,o,h,l){h||(n-=t,i-=e,a-=r,o-=s);var f=n*o-i*a;if(!u.isZero(f)){var d=t-r,_=e-s,g=(a*_-o*d)/f,v=(n*_-i*d)/f,p=1e-12,m=-p,y=1+p;if(l||m=1?1:g),new c(t+g*n,e+g*i)}},getSide:function(t,e,n,i,r,s,a,o){a||(n-=t,i-=e);var h=r-t,l=s-e,c=h*i-l*n;return!o&&u.isZero(c)&&(c=(h*n+h*n)/(n*n+i*i),c>=0&&c<=1&&(c=0)),c<0?-1:c>0?1:0},getSignedDistance:function(t,e,n,i,r,s,a){return a||(n-=t,i-=e),0===n?i>0?r-t:t-r:0===i?n<0?s-e:e-s:((r-t)*i-(s-e)*n)/Math.sqrt(n*n+i*i)},getDistance:function(t,e,n,i,r,s,a){return Math.abs(m.getSignedDistance(t,e,n,i,r,s,a))}}}),y=o.extend({_class:"Project",_list:"projects",_reference:"project",_compactSerialize:!0,initialize:function(t){o.call(this,!0),this._children=[],this._namedChildren={},this._activeLayer=null,this._currentStyle=new V(null,null,this),this._view=Z.create(this,t||tt.getCanvas(1,1)),this._selectionItems={},this._selectionCount=0,this._updateVersion=0},_serialize:function(t,e){return r.serialize(this._children,t,!0,e)},_changed:function(t,e){if(1&t){var n=this._view;n&&(n._needsUpdate=!0,!n._requested&&n._autoUpdate&&n.requestUpdate())}var i=this._changes;if(i&&e){var r=this._changesById,s=e._id,a=r[s];a?a.flags|=t:i.push(r[s]={item:e,flags:t})}},clear:function(){for(var t=this._children,e=t.length-1;e>=0;e--)t[e].remove()},isEmpty:function(){return!this._children.length},remove:function ht(){return!!ht.base.call(this)&&(this._view&&this._view.remove(),!0)},getView:function(){return this._view},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.set(t)},getIndex:function(){return this._index},getOptions:function(){return this._scope.settings},getLayers:function(){return this._children},getActiveLayer:function(){return this._activeLayer||new b({project:this,insert:!0})},getSymbolDefinitions:function(){var t=[],e={};return this.getItems({"class":k,match:function(n){var i=n._definition,r=i._id;return e[r]||(e[r]=!0,t.push(i)),!1}}),t},getSymbols:"getSymbolDefinitions",getSelectedItems:function(){var t=this._selectionItems,e=[];for(var n in t){var i=t[n],r=i._selection;1&r&&i.isInserted()?e.push(i):r||this._updateSelection(i)}return e},_updateSelection:function(t){var e=t._id,n=this._selectionItems;t._selection?n[e]!==t&&(this._selectionCount++,n[e]=t):n[e]===t&&(this._selectionCount--,delete n[e])},selectAll:function(){for(var t=this._children,e=0,n=t.length;e0){t.save(),t.strokeWidth=1;var h=this._selectionItems,u=this._scope.settings.handleSize,l=this._updateVersion;for(var f in h)h[f]._drawSelection(t,e,u,h,l);t.restore()}}}),w=r.extend(s,{statics:{extend:function ut(t){return t._serializeFields&&(t._serializeFields=r.set({},this.prototype._serializeFields,t._serializeFields)),ut.base.apply(this,arguments)},NO_INSERT:{insert:!1}},_class:"Item",_name:null,_applyMatrix:!0,_canApplyMatrix:!0,_canScaleStroke:!1,_pivot:null,_visible:!0,_blendMode:"normal",_opacity:1,_locked:!1,_guide:!1,_clipMask:!1,_selection:0,_selectBounds:!0,_selectChildren:!1,_serializeFields:{name:null,applyMatrix:null,matrix:new p,pivot:null,visible:!0,blendMode:"normal",opacity:1,locked:!1,guide:!1,clipMask:!1,selected:!1,data:{}},_prioritize:["applyMatrix"]},new function(){var t=["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"];return r.each(t,function(t){this._events[t]={install:function(t){this.getView()._countItemEvent(t,1)},uninstall:function(t){this.getView()._countItemEvent(t,-1)}}},{_events:{onFrame:{install:function(){this.getView()._animateItem(this,!0)},uninstall:function(){this.getView()._animateItem(this,!1)}},onLoad:{},onError:{}},statics:{_itemHandlers:t}})},{initialize:function(){},_initialize:function(t,n){var i=t&&r.isPlainObject(t),s=i&&t.internal===!0,a=this._matrix=new p,o=i&&t.project||paper.project,h=paper.settings;return this._id=s?null:l.get(),this._parent=this._index=null,this._applyMatrix=this._canApplyMatrix&&h.applyMatrix,n&&a.translate(n),a._owner=this,this._style=new V(o._currentStyle,this,o),s||i&&0==t.insert||!h.insertItems&&(!i||t.insert!==!0)?this._setProject(o):(i&&t.parent||o)._insertItem(e,this,!0),i&&t!==w.NO_INSERT&&this.set(t,{internal:!0,insert:!0,project:!0,parent:!0}),i},_serialize:function(t,e){function n(n){for(var a in n){var o=s[a];r.equals(o,"leading"===a?1.2*n.fontSize:n[a])||(i[a]=r.serialize(o,t,"data"!==a,e))}}var i={},s=this;return n(this._serializeFields),this instanceof x||n(this._style._defaults),[this._class,i]},_changed:function(t){var n=this._symbol,i=this._parent||n,r=this._project;8&t&&(this._bounds=this._position=this._decomposed=this._globalMatrix=e),i&&40&t&&w._clearBoundsCache(i),2&t&&w._clearBoundsCache(this),r&&r._changed(t,this),n&&n._changed(t)},getId:function(){return this._id},getName:function(){return this._name},setName:function(t){if(this._name&&this._removeNamed(),t===+t+"")throw new Error("Names consisting only of numbers are not supported.");var n=this._getOwner();if(t&&n){var i=n._children,r=n._namedChildren;(r[t]=r[t]||[]).push(this),t in i||(i[t]=this)}this._name=t||e,this._changed(128)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)}},r.each(["locked","visible","blendMode","opacity","guide"],function(t){var e=r.capitalize(t),n="_"+t,i={locked:128,visible:137};this["get"+e]=function(){return this[n]},this["set"+e]=function(e){e!=this[n]&&(this[n]=e,this._changed(i[t]||129))}},{}),{beans:!0,getSelection:function(){return this._selection},setSelection:function(t){if(t!==this._selection){this._selection=t;var e=this._project;e&&(e._updateSelection(this),this._changed(129))}},_changeSelection:function(t,e){var n=this._selection;this.setSelection(e?n|t:n&~t)},isSelected:function(){if(this._selectChildren)for(var t=this._children,e=0,n=t.length;e=0;n--)if(e[n].contains(t))return!0;return!1}return t.isInside(this.getInternalBounds())},isInside:function(){return g.read(arguments).contains(this.getBounds())},_asPathItem:function(){return new L.Rectangle({rectangle:this.getInternalBounds(),matrix:this._matrix,insert:!1})},intersects:function(t,e){return t instanceof w&&this._asPathItem().getIntersections(t._asPathItem(),null,e,!0).length>0}},new function(){function t(){return this._hitTest(c.read(arguments),P.getOptions(arguments))}function e(){var t=c.read(arguments),e=P.getOptions(arguments),n=[];return this._hitTest(t,r.set({all:n},e)),n}function n(t,e,n,i){var r=this._children;if(r)for(var s=r.length-1;s>=0;s--){var a=r[s],o=a!==i&&a._hitTest(t,e,n);if(o&&!e.all)return o}return null}return y.inject({hitTest:t,hitTestAll:e,_hitTest:n}),{hitTest:t,hitTestAll:e,_hitTestChildren:n}},{_hitTest:function(t,e,n){function i(t){return t&&_&&!_(t)&&(t=null),t&&e.all&&e.all.push(t),t}function s(e,n){var i=n?l["get"+n]():g.getPosition();if(t.subtract(i).divide(u).length<=1)return new P(e,g,{name:n?r.hyphenate(n):e,point:i})}if(this._locked||!this._visible||this._guide&&!e.guides||this.isEmpty())return null;var a=this._matrix,o=n?n.appended(a):this.getGlobalMatrix().prepend(this.getView()._matrix),h=Math.max(e.tolerance,1e-12),u=e._tolerancePadding=new d(L._getStrokePadding(h,a._shiftless().invert()));if(t=a._inverseTransform(t),!t||!this._children&&!this.getBounds({internal:!0,stroke:!0,handle:!0}).expand(u.multiply(2))._containsPoint(t))return null;var l,c,f=!(e.guides&&!this._guide||e.selected&&!this.isSelected()||e.type&&e.type!==r.hyphenate(this._class)||e["class"]&&!(this instanceof e["class"])),_=e.match,g=this,v=e.position,p=e.center,m=e.bounds;if(f&&this._parent&&(v||p||m)){if((p||m)&&(l=this.getInternalBounds()),c=v&&s("position")||p&&s("center","Center"),!c&&m)for(var y=["TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],w=0;w<8&&!c;w++)c=s("bounds",y[w]);c=i(c)}return c||(c=this._hitTestChildren(t,e,o)||f&&i(this._hitTestSelf(t,e,o,this.getStrokeScaling()?null:o._shiftless().invert()))||null),c&&c.point&&(c.point=a.transform(c.point)),c},_hitTestSelf:function(t,e){if(e.fill&&this.hasFill()&&this._contains(t))return new P("fill",this)},matches:function(t,e){function n(t,e){for(var i in t)if(t.hasOwnProperty(i)){var s=t[i],a=e[i];if(r.isPlainObject(s)&&r.isPlainObject(a)){if(!n(s,a))return!1}else if(!r.equals(s,a))return!1}return!0}var i=typeof t;if("object"===i){for(var s in t)if(t.hasOwnProperty(s)&&!this.matches(s,t[s]))return!1;return!0}if("function"===i)return t(this);if("match"===t)return e(this);var a=/^(empty|editable)$/.test(t)?this["is"+r.capitalize(t)]():"type"===t?r.hyphenate(this._class):this[t];if("class"===t){if("function"==typeof e)return this instanceof e;a=this._class}if("function"==typeof e)return!!e(a);if(e){if(e.test)return e.test(a);if(r.isPlainObject(e))return n(e,a)}return r.equals(a,e)},getItems:function(t){return w._getItems(this,t,this._matrix)},getItem:function(t){return w._getItems(this,t,this._matrix,null,!0)[0]||null},statics:{_getItems:function ct(t,e,n,i,s){if(!i){var a="object"==typeof e&&e,o=a&&a.overlapping,h=a&&a.inside,u=o||h,l=u&&g.read([u]);i={items:[],recursive:a&&a.recursive!==!1,inside:!!h,overlapping:!!o,rect:l,path:o&&new L.Rectangle({rectangle:l,insert:!1})},a&&(e=r.filter({},e,{recursive:!0,inside:!0,overlapping:!0}))}var c=t._children,f=i.items,l=i.rect;n=l&&(n||new p);for(var d=0,_=c&&c.length;d<_;d++){var v=c[d],m=n&&n.appended(v._matrix),y=!0;if(l){var u=v.getBounds(m);if(!l.intersects(u))continue;l.contains(u)||i.overlapping&&(u.contains(l)||i.path.intersects(v,m))||(y=!1)}if(y&&v.matches(e)&&(f.push(v),s))break;if(i.recursive!==!1&&ct(v,e,m,i,s),s&&f.length>0)break}return f}}},{importJSON:function(t){var e=r.importJSON(t,this);return e!==this?this.addChild(e):e},addChild:function(t){return this.insertChild(e,t)},insertChild:function(t,e){var n=e?this.insertChildren(t,[e]):null;return n&&n[0]},addChildren:function(t){return this.insertChildren(this._children.length,t)},insertChildren:function(t,e){var n=this._children;if(n&&e&&e.length>0){e=r.slice(e);for(var i={},s=e.length-1;s>=0;s--){var a=e[s],o=a&&a._id;!a||i[o]?e.splice(s,1):(a._remove(!1,!0),i[o]=!0)}r.splice(n,e,t,0);for(var h=this._project,u=h._changes,s=0,l=e.length;s=0;i--)n[i]._remove(!0,!1);return n.length>0&&this._changed(11),n},clear:"#removeChildren",reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;t0},isInserted:function(){return!!this._parent&&this._parent.isInserted()},isAbove:function(t){return this._getOrder(t)===-1},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e===t)return!0;return!1},isAncestor:function(t){return!!t&&t.isDescendant(this)},isSibling:function(t){return this._parent===t._parent},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(Group|Layer|CompoundPath)$/.test(e._class)&&t.isDescendant(e))return!0;e=e._parent}return!1}},r.each(["rotate","scale","shear","skew"],function(t){var e="rotate"===t;this[t]=function(){var n=(e?r:c).read(arguments),i=c.read(arguments,0,{readNull:!0});return this.transform((new p)[t](n,i||this.getPosition(!0)))}},{translate:function(){var t=new p;return this.transform(t.translate.apply(t,arguments))},transform:function(t,e,n,i){var r=this._matrix,s=t&&!t.isIdentity(),a=(e||this._applyMatrix)&&(!r.isIdentity()||s||e&&n&&this._children);if(!s&&!a)return this;if(s){!t.isInvertible()&&r.isInvertible()&&(r._backup=r.getValues()),r.prepend(t,!0);var o=this._style,h=o.getFillColor(!0),u=o.getStrokeColor(!0);h&&h.transform(t),u&&u.transform(t)}if(a&&(a=this._transformContent(r,n,i))){var l=this._pivot;l&&r._transformPoint(l,l,!0),r.reset(!0),i&&this._canApplyMatrix&&(this._applyMatrix=!0)}var c=this._bounds,f=this._position;(s||a)&&this._changed(9);var d=s&&c&&t.decompose();if(d&&d.skewing.isZero()&&d.rotation%90===0){for(var _ in c){var g=c[_];if(g.nonscaling)delete c[_];else if(a||!g.internal){var v=g.rect;t._transformBounds(v,v)}}this._bounds=c;var p=c[this._getBoundsCacheKey(this._boundsOptions||{})];p&&(this._position=p.rect.getCenter(!0))}else s&&f&&this._pivot&&(this._position=t._transformPoint(f,f));return this},_transformContent:function(t,e,n){var i=this._children;if(i){for(var r=0,s=i.length;rr:i1&&s<4?-1:1,s>2?-1:1),o=a.multiply(r),h=o.subtract(a.multiply(i)),u=new g(n?o.add(a.multiply(n)):o,h);if(u.contains(e))return{point:h,quadrant:s}}}function e(t,e,n,i){var r=t.divide(e);return(!i||r.isInQuadrant(i))&&r.subtract(r.normalize()).multiply(e).divide(n).length<=1}return{_contains:function n(e){if("rectangle"===this._type){var i=t(this,e);return i?e.subtract(i.point).divide(this._radius).getLength()<=1:n.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTestSelf:function i(n,r,s,a){var o=!1,h=this._style,u=r.stroke&&h.hasStroke(),l=r.fill&&h.hasFill();if(u||l){var c=this._type,f=this._radius,d=u?h.getStrokeWidth()/2:0,_=r._tolerancePadding.add(L._getStrokePadding(d,!h.getStrokeScaling()&&a));if("rectangle"===c){var v=_.multiply(2),p=t(this,n,v);if(p)o=e(n.subtract(p.point),f,_,p.quadrant);else{var m=new g(this._size).setCenter(0,0),y=m.expand(v),w=m.expand(v.negate());o=y._containsPoint(n)&&!w._containsPoint(n)}}else o=e(n,f,_)}return o?new P(u?"stroke":"fill",this):i.base.apply(this,arguments)}}},{statics:new function(){function t(t,e,n,i,s){var a=new C(r.getNamed(s),e);return a._type=t,a._size=n,a._radius=i,a}return{Circle:function(){var e=c.readNamed(arguments,"center"),n=r.readNamed(arguments,"radius");return t("circle",e,new d(2*n),n,arguments)},Rectangle:function(){var e=g.readNamed(arguments,"rectangle"),n=d.min(d.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),n,arguments)},Ellipse:function(){var e=C._readEllipse(arguments),n=e.radius;return t("ellipse",e.center,n.multiply(2),n,arguments)},_readEllipse:function(t){var e,n;if(r.hasNamed(t,"radius"))e=c.readNamed(t,"center"),n=d.readNamed(t,"radius");else{var i=g.readNamed(t,"rectangle");e=i.getCenter(!0),n=i.getSize(!0).divide(2)}return{center:e,radius:n}}}}}),S=w.extend({_class:"Raster",_applyMatrix:!1,_canApplyMatrix:!1,_boundsOptions:{stroke:!1,handle:!1},_serializeFields:{crossOrigin:null,source:null},_prioritize:["crossOrigin"],initialize:function(t,n){if(!this._initialize(t,n!==e&&c.read(arguments,1))){var r="string"==typeof t?i.getElementById(t):t;r?this.setImage(r):this.setSource(t)}this._size||(this._size=new d,this._loaded=!1)},_equals:function(t){return this.getSource()===t.getSource()},copyContent:function(t){var e=t._image,n=t._canvas;if(e)this._setImage(e);else if(n){var i=tt.getCanvas(t._size);i.getContext("2d").drawImage(n,0,0),this._setImage(i)}this._crossOrigin=t._crossOrigin},getSize:function(){var t=this._size;return new _(t?t.width:0,t?t.height:0,this,"setSize")},setSize:function(){var t=d.read(arguments);if(!t.equals(this._size))if(t.width>0&&t.height>0){var e=this.getElement();this._setImage(tt.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}else this._canvas&&tt.release(this._canvas),this._size=t.clone()},getWidth:function(){return this._size?this._size.width:0},setWidth:function(t){this.setSize(t,this.getHeight())},getHeight:function(){return this._size?this._size.height:0},setHeight:function(t){this.setSize(this.getWidth(),t)},getLoaded:function(){return this._loaded},isEmpty:function(){var t=this._size;return!t||0===t.width&&0===t.height},getResolution:function(){var t=this._matrix,e=new c(0,0).transform(t),n=new c(1,0).transform(t).subtract(e),i=new c(0,1).transform(t).subtract(e);return new d(72/n.getLength(),72/i.getLength())},getPpi:"#getResolution",getImage:function(){return this._image},setImage:function(t){function e(t){var e=n.getView(),i=t&&t.type||"load";e&&n.responds(i)&&(paper=e._scope,n.emit(i,new $(t)))}var n=this;this._setImage(t),this._loaded?setTimeout(e,0):t&&H.add(t,{load:function(i){n._setImage(t),e(i)},error:e})},_setImage:function(t){this._canvas&&tt.release(this._canvas),t&&t.getContext?(this._image=null,this._canvas=t,this._loaded=!0):(this._image=t,this._canvas=null,this._loaded=!!(t&&t.src&&t.complete)),this._size=new d(t?t.naturalWidth||t.width:0,t?t.naturalHeight||t.height:0),this._context=null,this._changed(521)},getCanvas:function(){if(!this._canvas){var t=tt.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){tt.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(t){return this._context||(this._context=this.getCanvas().getContext("2d")),t&&(this._image=null,this._changed(513)),this._context},setContext:function(t){this._context=t},getSource:function(){var t=this._image;return t&&t.src||this.toDataURL()},setSource:function(e){var n=new t.Image,i=this._crossOrigin;i&&(n.crossOrigin=i),n.src=e,this.setImage(n)},getCrossOrigin:function(){var t=this._image;return t&&t.crossOrigin||this._crossOrigin||""},setCrossOrigin:function(t){this._crossOrigin=t;var e=this._image;e&&(e.crossOrigin=t)},getElement:function(){return this._canvas||this._loaded&&this._image}},{beans:!1,getSubCanvas:function(){var t=g.read(arguments),e=tt.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(){var t=g.read(arguments),e=new S(w.NO_INSERT);return e._setImage(this.getSubCanvas(t)),e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.prepend(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image,e=t&&t.src;if(/^data:/.test(e))return e;var n=this.getCanvas();return n?n.toDataURL.apply(n,arguments):null},drawImage:function(t){var e=c.read(arguments,1);this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(t){var e,n;if(t?t instanceof O?(n=t,e=t.getBounds()):"object"==typeof t&&("width"in t?e=new g(t):"x"in t&&(e=new g(t.x-.5,t.y-.5,1,1))):e=this.getBounds(),!e)return null;var i=32,s=Math.min(e.width,i),a=Math.min(e.height,i),o=S._sampleContext;o?o.clearRect(0,0,i+1,i+1):o=S._sampleContext=tt.getContext(new d(i)),o.save();var h=(new p).scale(s/e.width,a/e.height).translate(-e.x,-e.y);h.applyToContext(o),n&&n.draw(o,new r({clip:!0,matrices:[h]})),this._matrix.applyToContext(o);var u=this.getElement(),l=this._size;u&&o.drawImage(u,-l.width/2,-l.height/2),o.restore();for(var c=o.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,f=[0,0,0],_=0,v=0,m=c.length;v0&&(null==t||"object"==typeof t?1===c&&t&&"point"in t?(o=t.point,h=t.handleIn,u=t.handleOut,l=t.selection):(o=t,h=n,u=i,l=r):(o=[t,n],h=i!==e?[i,r]:null,u=s!==e?[s,a]:null)),new M(o,this,"_point"),new M(h,this,"_handleIn"),new M(u,this,"_handleOut"),l&&this.setSelection(l)},_serialize:function(t,e){var n=this._point,i=this._selection,s=i||this.hasHandles()?[n,this._handleIn,this._handleOut]:n;return i&&s.push(i),r.serialize(s,t,!0,e)},_changed:function(t){var e=this._path;if(e){var n,i=e._curves,r=this._index;i&&(t&&t!==this._point&&t!==this._handleIn||!(n=r>0?i[r-1]:e._closed?i[i.length-1]:null)||n._changed(),t&&t!==this._point&&t!==this._handleOut||!(n=i[r])||n._changed()),e._changed(25)}},getPoint:function(){return this._point},setPoint:function(){this._point.set(c.read(arguments))},getHandleIn:function(){return this._handleIn},setHandleIn:function(){this._handleIn.set(c.read(arguments))},getHandleOut:function(){return this._handleOut},setHandleOut:function(){this._handleOut.set(c.read(arguments))},hasHandles:function(){return!this._handleIn.isZero()||!this._handleOut.isZero()},isSmooth:function(){var t=this._handleIn,e=this._handleOut;return!t.isZero()&&!e.isZero()&&t.isCollinear(e)},clearHandles:function(){this._handleIn._set(0,0),this._handleOut._set(0,0)},getSelection:function(){return this._selection},setSelection:function(t){var e=this._selection,n=this._path;this._selection=t=t||0,n&&t!==e&&(n._updateSelection(this,e,t),n._changed(129))},_changeSelection:function(t,e){var n=this._selection;this.setSelection(e?n|t:n&~t)},isSelected:function(){return!!(7&this._selection)},setSelected:function(t){this._changeSelection(7,t)},getIndex:function(){return this._index!==e?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(e>0&&!t._closed&&e===t._segments.length-1&&e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new z(t,this===t._segment1?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},smooth:function(t,n,i){var r=t||{},s=r.type,a=r.factor,o=this.getPrevious(),h=this.getNext(),u=(o||this)._point,l=this._point,f=(h||this)._point,d=u.getDistance(l),_=l.getDistance(f);if(s&&"catmull-rom"!==s){if("geometric"!==s)throw new Error("Smoothing method '"+s+"' not supported.");if(o&&h){var g=u.subtract(f),v=a===e?.4:a,p=v*d/(d+_);n||this.setHandleIn(g.multiply(p)),i||this.setHandleOut(g.multiply(p-v))}}else{var m=a===e?.5:a,y=Math.pow(d,m),w=y*y,x=Math.pow(_,m),b=x*x;if(!n&&o){var C=2*b+3*x*y+w,S=3*x*(x+y);this.setHandleIn(0!==S?new c((b*u._x+C*l._x-w*f._x)/S-l._x,(b*u._y+C*l._y-w*f._y)/S-l._y):new c)}if(!i&&h){var C=2*w+3*y*x+b,S=3*y*(y+x);this.setHandleOut(0!==S?new c((w*f._x+C*l._x-b*u._x)/S-l._x,(w*f._y+C*l._y-b*u._y)/S-l._y):new c)}}},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},isFirst:function(){return!this._index},isLast:function(){var t=this._path;return t&&this._index===t._segments.length-1||!1},reverse:function(){var t=this._handleIn,e=this._handleOut,n=t.clone();t.set(e),e.set(n)},reversed:function(){return new A(this._point,this._handleOut,this._handleIn)},remove:function(){return!!this._path&&!!this._path.removeSegment(this._index)},clone:function(){return new A(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},transform:function(t){this._transformCoordinates(t,new Array(6),!0),this._changed()},interpolate:function(t,e,n){var i=1-n,r=n,s=t._point,a=e._point,o=t._handleIn,h=e._handleIn,u=e._handleOut,l=t._handleOut;this._point._set(i*s._x+r*a._x,i*s._y+r*a._y,!0),this._handleIn._set(i*o._x+r*h._x,i*o._y+r*h._y,!0),this._handleOut._set(i*l._x+r*u._x,i*l._y+r*u._y,!0),this._changed()},_transformCoordinates:function(t,e,n){var i=this._point,r=n&&this._handleIn.isZero()?null:this._handleIn,s=n&&this._handleOut.isZero()?null:this._handleOut,a=i._x,o=i._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,e,h/2),a=e[0],o=e[1],n?(i._x=a,i._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),M=c.extend({initialize:function(t,n,i){var r,s,a;if(t)if((r=t[0])!==e)s=t[1];else{var o=t;(r=o.x)===e&&(o=c.read(arguments),r=o.x),s=o.y,a=o.selected}else r=s=0;this._x=r,this._y=s,this._owner=n,n[i]=this,a&&this.setSelected(!0)},_set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){var t=u.isZero;return t(this._x)&&t(this._y)},isSelected:function(){return!!(this._owner._selection&this._getSelection())},setSelected:function(t){this._owner._changeSelection(this._getSelection(),t)},_getSelection:function(){var t=this._owner;return this===t._point?1:this===t._handleIn?2:this===t._handleOut?4:0}}),T=r.extend({_class:"Curve",beans:!0,initialize:function(t,e,n,i,r,s,a,o){var h,u,l,c,f,d,_=arguments.length;3===_?(this._path=t,h=e,u=n):_?1===_?"segment1"in t?(h=new A(t.segment1),u=new A(t.segment2)):"point1"in t?(l=t.point1,f=t.handle1,d=t.handle2,c=t.point2):Array.isArray(t)&&(l=[t[0],t[1]],c=[t[6],t[7]],f=[t[2]-t[0],t[3]-t[1]],d=[t[4]-t[6],t[5]-t[7]]):2===_?(h=new A(t),u=new A(e)):4===_?(l=t,f=e,d=n,c=i):8===_&&(l=[t,e],c=[a,o],f=[n-t,i-e],d=[r-a,s-o]):(h=new A,u=new A),this._segment1=h||new A(l,null,f),this._segment2=u||new A(c,d,null)},_serialize:function(t,e){return r.serialize(this.hasHandles()?[this.getPoint1(),this.getHandle1(),this.getHandle2(),this.getPoint2()]:[this.getPoint1(),this.getPoint2()],t,!0,e)},_changed:function(){this._length=this._bounds=e},clone:function(){return new T(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},classify:function(){return T.classify(this.getValues())},remove:function(){var t=!1;if(this._path){var e=this._segment2,n=e._handleOut;t=e.remove(),t&&this._segment1._handleOut.set(n)}return t},getPoint1:function(){return this._segment1._point},setPoint1:function(){this._segment1._point.set(c.read(arguments))},getPoint2:function(){return this._segment2._point},setPoint2:function(){this._segment2._point.set(c.read(arguments))},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(){this._segment1._handleOut.set(c.read(arguments))},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(){this._segment2._handleIn.set(c.read(arguments))},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isFirst:function(){return!this._segment1._index},isLast:function(){var t=this._path;return t&&this._segment1._index===t._curves.length-1||!1},isSelected:function(){return this.getPoint1().isSelected()&&this.getHandle1().isSelected()&&this.getHandle2().isSelected()&&this.getPoint2().isSelected()},setSelected:function(t){this.getPoint1().setSelected(t),this.getHandle1().setSelected(t),this.getHandle2().setSelected(t),this.getPoint2().setSelected(t)},getValues:function(t){return T.getValues(this._segment1,this._segment2,t)},getPoints:function(){for(var t=this.getValues(),e=[],n=0;n<8;n+=2)e.push(new c(t[n],t[n+1]));return e}},{getLength:function(){return null==this._length&&(this._length=T.getLength(this.getValues(),0,1)),this._length},getArea:function(){return T.getArea(this.getValues())},getLine:function(){return new m(this._segment1._point,this._segment2._point)},getPart:function(t,e){return new T(T.getPart(this.getValues(),t,e))},getPartLength:function(t,e){return T.getLength(this.getValues(),t,e)},divideAt:function(t){return this.divideAtTime(t&&t.curve===this?t.time:this.getTimeAt(t))},divideAtTime:function(t,e){var n=1e-8,i=1-n,r=null;if(t>=n&&t<=i){var s=T.subdivide(this.getValues(),t),a=s[0],o=s[1],h=e||this.hasHandles(),u=this._segment1,l=this._segment2,f=this._path;h&&(u._handleOut._set(a[2]-a[0],a[3]-a[1]),l._handleIn._set(o[4]-o[6],o[5]-o[7]));var d=a[6],_=a[7],g=new A(new c(d,_),h&&new c(a[4]-d,a[5]-_),h&&new c(o[2]-d,o[3]-_));f?(f.insert(u._index+1,g),r=this.getNext()):(this._segment2=g,this._changed(),r=new T(g,l))}return r},splitAt:function(t){var e=this._path;return e?e.splitAt(t):null},splitAtTime:function(t){return this.splitAt(this.getLocationAtTime(t))},divide:function(t,n){return this.divideAtTime(t===e?.5:n?t:this.getTimeAt(t))},split:function(t,n){return this.splitAtTime(t===e?.5:n?t:this.getTimeAt(t))},reversed:function(){return new T(this._segment2.reversed(),this._segment1.reversed())},clearHandles:function(){this._segment1._handleOut._set(0,0),this._segment2._handleIn._set(0,0)},statics:{getValues:function(t,e,n,i){var r=t._point,s=t._handleOut,a=e._handleIn,o=e._point,h=r.x,u=r.y,l=o.x,c=o.y,f=i?[h,u,h,u,l,c,l,c]:[h,u,h+s._x,u+s._y,l+a._x,c+a._y,l,c];return n&&n._transformCoordinates(f,f,4),f},subdivide:function(t,n){var i=t[0],r=t[1],s=t[2],a=t[3],o=t[4],h=t[5],u=t[6],l=t[7];n===e&&(n=.5);var c=1-n,f=c*i+n*s,d=c*r+n*a,_=c*s+n*o,g=c*a+n*h,v=c*o+n*u,p=c*h+n*l,m=c*f+n*_,y=c*d+n*g,w=c*_+n*v,x=c*g+n*p,b=c*m+n*w,C=c*y+n*x;return[[i,r,f,d,m,y,b,C],[b,C,w,x,v,p,u,l]]},getMonoCurves:function(t,e){var n=[],i=e?0:1,r=t[i+0],s=t[i+2],a=t[i+4],o=t[i+6];if(r>=s==s>=a&&s>=a==a>=o||T.isStraight(t))n.push(t);else{var h=3*(s-a)-r+o,l=2*(r+a)-4*s,c=s-r,f=1e-8,d=1-f,_=[],g=u.solveQuadratic(h,l,c,_,f,d);if(g){_.sort();var v=_[0],p=T.subdivide(t,v);n.push(p[0]),g>1&&(v=(_[1]-v)/(1-v),p=T.subdivide(p[1],v),n.push(p[0])),n.push(p[1])}else n.push(t)}return n},solveCubic:function(t,e,n,i,r,s){var a=t[e],o=t[e+2],h=t[e+4],l=t[e+6],c=0;if(!(an&&l>n&&o>n&&h>n)){var f=3*(o-a),d=3*(h-o)-f,_=l-a-f-d;c=u.solveCubic(_,d,f,a-n,i,r,s)}return c},getTimeOf:function(t,e){var n=new c(t[0],t[1]),i=new c(t[6],t[7]),r=1e-12,s=1e-7,a=e.isClose(n,r)?0:e.isClose(i,r)?1:null;if(null===a)for(var o=[e.x,e.y],h=[],u=0;u<2;u++)for(var l=T.solveCubic(t,u,o[u],h,0,1),f=0;f=0&&n<=1){var i=e.getDistance(T.getPoint(t,n),!0);if(i.999999999999?1:T.getTimeOf(t,new c(i+l*o,r+l*h))}for(var f=100,d=1/0,_=0,g=0;g<=f;g++)n(g/f);for(var v=1/(2*f);v>1e-8;)n(_-v)||n(_+v)||(v/=2);return _},getPart:function(t,e,n){var i=e>n;if(i){var r=e;e=n,n=r}return e>0&&(t=T.subdivide(t,e)[1]),n<1&&(t=T.subdivide(t,(n-e)/(1-e))[0]),i?[t[6],t[7],t[4],t[5],t[2],t[3],t[0],t[1]]:t},isFlatEnough:function(t,e){var n=t[0],i=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*n-h,c=3*s-2*i-u,f=3*a-2*h-n,d=3*o-2*u-i;return Math.max(l*l,f*f)+Math.max(c*c,d*d)<=16*e*e},getArea:function(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7];return 3*((h-n)*(i+s)-(o-e)*(r+a)+r*(e-s)-i*(n-a)+h*(s+e/3)-o*(a+n/3))/20},getBounds:function(t){for(var e=t.slice(0,2),n=e.slice(),i=[0,0],r=0;r<2;r++)T._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,n,i);return new g(e[0],e[1],n[0]-e[0],n[1]-e[1])},_addBounds:function(t,e,n,i,r,s,a,o,h){function l(t,e){var n=t-e,i=t+e;no[r]&&(o[r]=i)}s/=2;var c=a[r]-s,f=o[r]+s;if(tf||e>f||n>f||i>f)if(e=0&&h<=1&&u<=0&&u>=-1}}return!1},isLinear:function(t,e,n,i){var r=i.subtract(t).divide(3);return e.equals(r)&&n.negate().equals(r)}},function(t,e){this[e]=function(e){var n=this._segment1,i=this._segment2;return t(n._point,n._handleOut,i._handleIn,i._point,e)},this.statics[e]=function(e,n){var i=e[0],r=e[1],s=e[6],a=e[7];return t(new c(i,r),new c(e[2]-i,e[3]-r),new c(e[4]-s,e[5]-a),new c(s,a),n)}},{statics:{},hasHandles:function(){return!this._segment1._handleOut.isZero()||!this._segment2._handleIn.isZero()},hasLength:function(t){return(!this.getPoint1().equals(this.getPoint2())||this.hasHandles())&&this.getLength()>(t||0)},isCollinear:function(t){return t&&this.isStraight()&&t.isStraight()&&this.getLine().isCollinear(t.getLine())},isHorizontal:function(){return this.isStraight()&&Math.abs(this.getTangentAtTime(.5).y)<1e-8},isVertical:function(){return this.isStraight()&&Math.abs(this.getTangentAtTime(.5).x)<1e-8}}),{beans:!1,getLocationAt:function(t,e){return this.getLocationAtTime(e?t:this.getTimeAt(t))},getLocationAtTime:function(t){return null!=t&&t>=0&&t<=1?new z(this,t):null},getTimeAt:function(t,e){return T.getTimeAt(this.getValues(),t,e)},getParameterAt:"#getTimeAt",getOffsetAtTime:function(t){return this.getPartLength(0,t)},getLocationOf:function(){return this.getLocationAtTime(this.getTimeOf(c.read(arguments)))},getOffsetOf:function(){var t=this.getLocationOf.apply(this,arguments);return t?t.getOffset():null},getTimeOf:function(){return T.getTimeOf(this.getValues(),c.read(arguments))},getParameterOf:"#getTimeOf",getNearestLocation:function(){var t=c.read(arguments),e=this.getValues(),n=T.getNearestTime(e,t),i=T.getPoint(e,n);return new z(this,n,i,null,t.getDistance(i))},getNearestPoint:function(){var t=this.getNearestLocation.apply(this,arguments);return t?t.getPoint():t}},new function(){var t=["getPoint","getTangent","getNormal","getWeightedTangent","getWeightedNormal","getCurvature"];return r.each(t,function(t){this[t+"At"]=function(e,n){var i=this.getValues();return T[t](i,n?e:T.getTimeAt(i,e))},this[t+"AtTime"]=function(e){return T[t](this.getValues(),e)}},{statics:{_evaluateMethods:t}})},new function(){function t(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],u=9*(i-s)+3*(o-e),l=6*(e+s)-12*i,c=3*(i-e),f=9*(r-a)+3*(h-n),d=6*(n+a)-12*r,_=3*(r-n);return function(t){var e=(u*t+l)*t+c,n=(f*t+d)*t+_;return Math.sqrt(e*e+n*n)}}function n(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}function i(t,e,n,i){if(null==e||e<0||e>1)return null;var r=t[0],s=t[1],a=t[2],o=t[3],h=t[4],l=t[5],f=t[6],d=t[7],_=u.isZero;_(a-r)&&_(o-s)&&(a=r,o=s),_(h-f)&&_(l-d)&&(h=f,l=d);var g,v,p=3*(a-r),m=3*(h-a)-p,y=f-r-p-m,w=3*(o-s),x=3*(l-o)-w,b=d-s-w-x;if(0===n)g=0===e?r:1===e?f:((y*e+m)*e+p)*e+r,v=0===e?s:1===e?d:((b*e+x)*e+w)*e+s;else{var C=1e-8,S=1-C;if(eS?(g=3*(f-h),v=3*(d-l)):(g=(3*y*e+2*m)*e+p,v=(3*b*e+2*x)*e+w),i){0===g&&0===v&&(eS)&&(g=h-a,v=l-o);var k=Math.sqrt(g*g+v*v);k&&(g/=k,v/=k)}if(3===n){var h=6*y*e+2*m,l=6*b*e+2*x,I=Math.pow(g*g+v*v,1.5);g=0!==I?(g*l-v*h)/I:0,v=0}}return 2===n?new c(v,(-g)):new c(g,v)}return{statics:{
-classify:function(t){function n(t,n,i){var r=n!==e,s=r&&n>0&&n<1,a=r&&i>0&&i<1;return!r||(s||a)&&("loop"!==t||s&&a)||(t="arch",s=a=!1),{type:t,roots:s||a?s&&a?n0?Math.sqrt(b/3):Math.sqrt(-b),S=2*p;return n(b>0?x:"loop",(v+C)/S,(v-C)/S)},getLength:function(i,r,s,a){if(r===e&&(r=0),s===e&&(s=1),T.isStraight(i)){var o=i;s<1&&(o=T.subdivide(o,s)[0],r/=s),r>0&&(o=T.subdivide(o,r)[1]);var h=o[6]-o[0],l=o[7]-o[1];return Math.sqrt(h*h+l*l)}return u.integrate(a||t(i),r,s,n(r,s))},getTimeAt:function(i,r,s){function a(t){return p+=u.integrate(d,s,t,n(s,t)),s=t,p-r}if(s===e&&(s=r<0?1:0),0===r)return s;var o=Math.abs,h=1e-12,l=r>0,c=l?s:0,f=l?1:s,d=t(i),_=T.getLength(i,c,f,d),g=o(r)-_;if(o(g)h)return null;var v=r/_,p=0;return u.findRoot(a,d,s+v,c,f,32,1e-12)},getPoint:function(t,e){return i(t,e,0,!1)},getTangent:function(t,e){return i(t,e,1,!0)},getWeightedTangent:function(t,e){return i(t,e,1,!1)},getNormal:function(t,e){return i(t,e,2,!0)},getWeightedNormal:function(t,e){return i(t,e,2,!1)},getCurvature:function(t,e){return i(t,e,3,!1).x},getPeaks:function(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],l=-e+3*i-3*s+o,c=3*e-6*i+3*s,f=-3*e+3*i,d=-n+3*r-3*a+h,_=3*n-6*r+3*a,g=-3*n+3*r,v=1e-8,p=1-v,m=[];return u.solveCubic(9*(l*l+d*d),9*(l*c+_*d),2*(c*c+_*_)+3*(f*l+g*d),f*c+_*g,m,v,p),m.sort()}}}},new function(){function t(t,e,n,i,r,s,a){var o=!a&&n.getPrevious()===r,h=!a&&n!==r&&n.getNext()===r,u=1e-8,l=1-u;if(null!==i&&i>=(o?u:0)&&i<=(h?l:1)&&null!==s&&s>=(h?u:0)&&s<=(o?l:1)){var c=new z(n,i,null,a),f=new z(r,s,null,a);c._intersection=f,f._intersection=c,e&&!e(c)||z.insert(t,c,!0)}}function e(r,s,a,o,h,u,l,c,f,d,_,g,v){if(++f>=4096||++c>=40)return f;var p,y,w=1e-9,x=s[0],b=s[1],C=s[6],S=s[7],k=m.getSignedDistance,I=k(x,b,C,S,s[2],s[3]),P=k(x,b,C,S,s[4],s[5]),A=I*P>0?.75:4/9,M=A*Math.min(0,I,P),z=A*Math.max(0,I,P),O=k(x,b,C,S,r[0],r[1]),L=k(x,b,C,S,r[2],r[3]),E=k(x,b,C,S,r[4],r[5]),N=k(x,b,C,S,r[6],r[7]),B=n(O,L,E,N),j=B[0],F=B[1];if(0===I&&0===P&&0===O&&0===L&&0===E&&0===N||null==(p=i(j,F,M,z))||null==(y=i(j.reverse(),F.reverse(),M,z)))return f;var D=d+(_-d)*p,R=d+(_-d)*y;if(Math.max(v-g,R-D).8)if(R-D>v-g){var U=T.subdivide(r,.5),q=(D+R)/2;f=e(s,U[0],o,a,h,u,!l,c,f,g,v,D,q),f=e(s,U[1],o,a,h,u,!l,c,f,g,v,q,R)}else{var U=T.subdivide(s,.5),V=(g+v)/2;f=e(U[0],r,o,a,h,u,!l,c,f,g,V,D,R),f=e(U[1],r,o,a,h,u,!l,c,f,V,v,D,R)}else f=v-g>=w?e(s,r,o,a,h,u,!l,c,f,g,v,D,R):e(r,s,a,o,h,u,l,c,f,D,R,g,v);return f}function n(t,e,n,i){var r,s=[0,t],a=[1/3,e],o=[2/3,n],h=[1,i],u=e-(2*t+i)/3,l=n-(t+2*i)/3;if(u*l<0)r=[[s,a,h],[s,o,h]];else{var c=u/l;r=[c>=2?[s,a,h]:c<=.5?[s,o,h]:[s,a,o,h],[s,h]]}return(u||l)<0?r.reverse():r}function i(t,e,n,i){return t[0][1]i?r(e,!1,i):t[0][0]}function r(t,e,n){for(var i=t[0][0],r=t[0][1],s=1,a=t.length;s=n:h<=n)return h===n?o:i+(n-r)*(o-i)/(h-r);i=o,r=h}return null}function s(t,e,n,i,r){var s=u.isZero;if(s(i)&&s(r)){var a=T.getTimeOf(t,new c(e,n));return null===a?[]:[a]}for(var o=Math.atan2(-r,i),h=Math.sin(o),l=Math.cos(o),f=[],d=[],_=0;_<8;_+=2){var g=t[_]-e,v=t[_+1]-n;f.push(g*l-v*h,g*h+v*l)}return T.solveCubic(f,1,0,d,0,1),d}function a(e,n,i,r,a,o,h){for(var u=n[0],l=n[1],c=n[6],f=n[7],d=s(e,u,l,c-u,f-l),_=0,g=d.length;_f(i[0],i[2],i[4],i[6])&&f(n[0],n[2],n[4],n[6])-l<_(i[0],i[2],i[4],i[6])&&_(n[1],n[3],n[5],n[7])+l>f(i[1],i[3],i[5],i[7])&&f(n[1],n[3],n[5],n[7])-l<_(i[1],i[3],i[5],i[7])){var g=d(n,i);if(g)for(var v=0;v<2;v++){var p=g[v];t(h,u,r,p[0],s,p[1],!0)}else{var m=T.isStraight(n),y=T.isStraight(i),w=m&&y,x=m&&!y,b=h.length;if((w?o:m||y?a:e)(x?i:n,x?n:i,x?s:r,x?r:s,h,u,x,0,0,0,1,0,1),!w||h.length===b)for(var v=0;v<4;v++){var C=v>>1,S=1&v,k=6*C,I=6*S,P=new c(n[k],n[k+1]),A=new c(i[I],i[I+1]);P.isClose(A,l)&&t(h,u,r,C,s,S)}}}return h}function l(e,n,i,r){var s=T.classify(e);if("loop"===s.type){var a=s.roots;t(i,r,n,a[0],n,a[1])}return i}function f(t,e,n,i,r,s){var a=!e;a&&(e=t);for(var o,u,c=t.length,f=e.length,d=[],_=[],g=0;g>1,k=T.getTimeOf(y[b],new c(y[C][S?6:0],y[C][S?7:1]));if(null!=k){var I=b?[S,k]:[k,S];(!w.length||i(I[0]-w[0][0])>s&&i(I[1]-w[0][1])>s)&&w.push(I)}if(x>2&&!w.length)break}if(2!==w.length)w=null;else if(!u){var P=T.getPart(t,w[0][0],w[1][0]),A=T.getPart(e,w[0][1],w[1][1]);(i(A[2]-P[2])>a||i(A[3]-P[3])>a||i(A[4]-P[4])>a||i(A[5]-P[5])>a)&&(w=null)}return w}return{getIntersections:function(t){var e=this.getValues(),n=t&&t!==this&&t.getValues();return n?h(e,n,this,t,[]):l(e,this,[])},statics:{getOverlaps:d,getIntersections:f,getCurveLineIntersections:s}}}),z=r.extend({_class:"CurveLocation",initialize:function(t,e,n,i,r){if(e>=.99999999){var s=t.getNext();s&&(e=0,t=s)}this._setCurve(t),this._time=e,this._point=n||t.getPointAtTime(e),this._overlap=i,this._distance=r,this._intersection=this._next=this._previous=null},_setCurve:function(t){var e=t._path;this._path=e,this._version=e?e._version:0,this._curve=t,this._segment=null,this._segment1=t._segment1,this._segment2=t._segment2},_setSegment:function(t){this._setCurve(t.getCurve()),this._segment=t,this._time=t===this._segment1?0:1,this._point=t._point.clone()},getSegment:function(){var t=this._segment;if(!t){var e=this.getCurve(),n=this.getTime();0===n?t=e._segment1:1===n?t=e._segment2:null!=n&&(t=e.getPartLength(0,n)1?i[r-1]:r>0?i[0]:.5;d.push(T.getLength(n,e?s:0,e?1:s)/2)}function e(t,e,n){return ee&&te||t=s&&i<=a,h=r>=s&&r<=a;if(o&&h)return!this.isTouching();var u=this.getCurve(),l=ia&&(u=u.getNext()),r>a&&(c=c.getNext()),!(l&&u&&f&&c))return!1;var d=[];o||(t(l,!0),t(u,!1)),h||(t(f,!0),t(c,!1));var _=this.getPoint(),g=Math.min.apply(Math,d),v=o?u.getTangentAtTime(i):u.getPointAt(g).subtract(_),p=o?v.negate():l.getPointAt(-g).subtract(_),m=h?c.getTangentAtTime(r):c.getPointAt(g).subtract(_),y=h?m.negate():f.getPointAt(-g).subtract(_),w=p.getAngle(),x=v.getAngle(),b=y.getAngle(),C=m.getAngle();return!!(o?e(w,b,C)^e(x,b,C)&&e(w,C,b)^e(x,C,b):e(b,w,x)^e(C,w,x)&&e(b,x,w)^e(C,x,w))},hasOverlap:function(){return!!this._overlap}},r.each(T._evaluateMethods,function(t){var e=t+"At";this[t]=function(){var t=this.getCurve(),n=this.getTime();return null!=n&&t&&t[e](n,!0)}},{preserve:!0}),new function(){function t(t,e,n){function i(n,i){for(var s=n+i;s>=-1&&s<=r;s+=i){var a=t[(s%r+r)%r];if(!e.getPoint().isClose(a.getPoint(),1e-7))break;if(e.equals(a))return a}return null}for(var r=t.length,s=0,a=r-1;s<=a;){var o,h=s+a>>>1,u=t[h];if(n&&(o=e.equals(u)?u:i(h,-1)||i(h,1)))return e._overlap&&(o._overlap=o._intersection._overlap=!0),o;var l=e.getPath(),c=u.getPath(),f=l!==c?l._id-c._id:e.getIndex()+e.getTime()-(u.getIndex()+u.getTime());f<0?a=h-1:s=h+1}return t.splice(s,0,e),e}return{statics:{insert:t,expand:function(e){for(var n=e.slice(),i=e.length-1;i>=0;i--)t(n,e[i]._intersection,!1);return n}}}}),O=w.extend({_class:"PathItem",_selectBounds:!1,_canScaleStroke:!0,beans:!0,initialize:function(){},statics:{create:function(t){var e,n,i;if(r.isPlainObject(t)?(n=t.segments,e=t.pathData):Array.isArray(t)?n=t:"string"==typeof t&&(e=t),n){var s=n[0];i=s&&Array.isArray(s[0])}else e&&(i=(e.match(/m/gi)||[]).length>1||/z\s*\S+/i.test(e));var a=i?E:L;return new a(t)}},_asPathItem:function(){return this},isClockwise:function(){return this.getArea()>=0},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse()},setPathData:function(t){function e(t,e){var n=+i[t];return o&&(n+=h[e]),n}function n(t){return new c(e(t,"x"),e(t+1,"y"))}var i,r,s,a=t&&t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),o=!1,h=new c,u=new c;this.clear();for(var l=0,f=a&&a.length;l