diff --git a/dist/paper-full.js b/dist/paper-full.js index 1f11c8bd..c5ab12b2 100644 --- a/dist/paper-full.js +++ b/dist/paper-full.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed May 7 17:35:17 2014 +0100 + * Date: Mon Apr 7 11:24:38 2014 +0200 * *** * @@ -194,10 +194,6 @@ var Base = new function() { return each(this, iter, bind); }, - set: function(props) { - return set(this, props); - }, - clone: function() { return new this.constructor(this); }, @@ -265,8 +261,8 @@ Base.inject({ return Base.serialize(this); }, - _set: function(props, exclude, dontCheck) { - if (props && (dontCheck || Base.isPlainObject(props))) { + _set: function(props, exclude) { + if (props && Base.isPlainObject(props)) { var orig = props._filtering || props; for (var key in orig) { if (key in this && orig.hasOwnProperty(key) @@ -283,7 +279,7 @@ Base.inject({ statics: { exports: { - enumerable: true + enumerable: true }, extend: function extend() { @@ -406,9 +402,8 @@ Base.inject({ return !!this.getNamed(list, name); }, - isPlainValue: function(obj, asString) { - return this.isPlainObject(obj) || Array.isArray(obj) - || asString && typeof obj === 'string'; + isPlainValue: function(obj) { + return this.isPlainObject(obj) || Array.isArray(obj); }, serialize: function(obj, options, compact, dictionary) { @@ -467,7 +462,8 @@ Base.inject({ }, deserialize: function(json, create, _data) { - var res = json; + var res = json, + isRoot = !_data; _data = _data || {}; if (Array.isArray(json)) { var type = json[0], @@ -485,7 +481,7 @@ Base.inject({ } else if (type) { var args = res; if (create) { - res = create(type, args); + res = create(type, args, isRoot); } else { res = Base.create(type.prototype); type.apply(res, args); @@ -509,13 +505,13 @@ Base.inject({ importJSON: function(json, target) { return Base.deserialize( typeof json === 'string' ? JSON.parse(json) : json, - function(type, args) { + function(type, args, isRoot) { var obj = target && target.constructor === type ? target : Base.create(type.prototype), isTarget = obj === target; - if (args.length === 1 && obj instanceof Item - && (isTarget || !(obj instanceof Layer))) { + if (!isRoot && args.length === 1 && obj instanceof Item + && (!(obj instanceof Layer) || isTarget)) { var arg = args[0]; if (Base.isPlainObject(arg)) arg.insert = false; @@ -581,7 +577,7 @@ var Callback = { if (entry) { var handlers = this._handlers = this._handlers || {}; handlers = handlers[type] = handlers[type] || []; - if (handlers.indexOf(func) == -1) { + if (handlers.indexOf(func) == -1) { handlers.push(func); if (entry.install && handlers.length == 1) entry.install.call(this, type); @@ -695,11 +691,11 @@ var PaperScope = Base.extend({ initialize: function PaperScope(script) { paper = this; - this.settings = new Base({ + this.settings = { applyMatrix: true, handleSize: 4, hitTolerance: 0 - }); + }; this.project = null; this.projects = []; this.tools = []; @@ -729,8 +725,8 @@ var PaperScope = Base.extend({ return this; }, - execute: function(code, url, options) { - paper.PaperScript.execute(code, this, url, options); + execute: function(code) { + paper.PaperScript.execute(code, this); View.updateFocus(); }, @@ -933,7 +929,7 @@ var Numerical = new function() { B = A + a, i = 0, m = (n + 1) >> 1, - sum = n & 1 ? w[i++] * f(B) : 0; + sum = n & 1 ? w[i++] * f(B) : 0; while (i < m) { var Ax = A * x[i]; sum += w[i++] * (f(B + Ax) + f(B - Ax)); @@ -965,7 +961,7 @@ var Numerical = new function() { if (abs(a) < EPSILON) { if (abs(b) >= EPSILON) return add(-c / b); - return abs(c) < EPSILON ? -1 : 0; + return abs(c) < EPSILON ? -1 : 0; } var p = b / (2 * a); var q = c / a; @@ -994,14 +990,14 @@ var Numerical = new function() { D = q * q - ppp; b /= 3; if (abs(D) < EPSILON) { - if (abs(q) < EPSILON) + if (abs(q) < EPSILON) return add(-b); var sqp = sqrt(p), snq = q > 0 ? 1 : -1; add(-snq * 2 * sqp - b); return add(snq * sqp - b); } - if (D < 0) { + if (D < 0) { var sqp = sqrt(p), phi = Math.acos(q / (sqp * sqp * sqp)) / 3, t = -2 * sqp, @@ -2343,9 +2339,9 @@ var Line = Base.extend({ } var v2x = x - px, v2y = y - py, - ccw = v2x * vy - v2y * vx; + ccw = v2x * vy - v2y * vx; if (ccw === 0) { - ccw = v2x * vx + v2y * vy; + ccw = v2x * vx + v2y * vy; if (ccw > 0) { v2x -= vx; v2y -= vy; @@ -2362,8 +2358,8 @@ var Line = Base.extend({ vx -= px; vy -= py; } - var m = vy / vx, - b = py - m * px; + var m = vy / vx, + b = py - m * px; return (y - (m * x) - b) / Math.sqrt(m * m + 1); } } @@ -2484,7 +2480,7 @@ var Project = PaperScopeItem.extend({ var point = Point.read(arguments), options = HitResult.getOptions(Base.read(arguments)); for (var i = this.layers.length - 1; i >= 0; i--) { - var res = this.layers[i]._hitTest(point, options); + var res = this.layers[i].hitTest(point, options); if (res) return res; } return null; @@ -2511,22 +2507,45 @@ var Project = PaperScopeItem.extend({ var param = new Base({ offset: new Point(0, 0), pixelRatio: pixelRatio, - viewMatrix: matrix.isIdentity() ? null : matrix, - matrices: [new Matrix()], - updateMatrix: true + trackTransforms: true, + transforms: [matrix] }); - for (var i = 0, layers = this.layers, l = layers.length; i < l; i++) - layers[i].draw(ctx, param); + for (var i = 0, l = this.layers.length; i < l; i++) + this.layers[i].draw(ctx, param); ctx.restore(); if (this._selectedItemCount > 0) { ctx.save(); ctx.strokeWidth = 1; - var items = this._selectedItems, - size = this._scope.settings.handleSize, - updateVersion = this._updateVersion; - for (var id in items) - items[id]._drawSelection(ctx, matrix, size, updateVersion); + for (var id in this._selectedItems) { + var item = this._selectedItems[id], + globalMatrix = item._globalMatrix, + size = this._scope.settings.handleSize, + half = size / 2; + if (item._updateVersion === this._updateVersion + && (item._drawSelected || item._boundsSelected) + && globalMatrix) { + var color = item.getSelectedColor() + || item.getLayer().getSelectedColor(); + ctx.strokeStyle = ctx.fillStyle = color + ? color.toCanvasStyle(ctx) : '#009dec'; + if (item._drawSelected) + item._drawSelected(ctx, globalMatrix); + if (item._boundsSelected) { + var coords = globalMatrix._transformCorners( + item.getInternalBounds()); + ctx.beginPath(); + for (var i = 0; i < 8; i++) + ctx[i === 0 ? 'moveTo' : 'lineTo']( + coords[i], coords[++i]); + ctx.closePath(); + ctx.stroke(); + for (var i = 0; i < 8; i++) + ctx.fillRect(coords[i] - half, coords[++i] - half, + size, size); + } + } + } ctx.restore(); } } @@ -2605,7 +2624,6 @@ var Item = Base.extend(Callback, { _selectChildren: false, _serializeFields: { name: null, - applyMatrix: null, matrix: new Matrix(), pivot: null, locked: false, @@ -2615,6 +2633,7 @@ var Item = Base.extend(Callback, { guide: false, selected: false, clipMask: false, + applyMatrix: null, data: {} }, @@ -2622,8 +2641,7 @@ var Item = Base.extend(Callback, { }, _initialize: function(props, point) { - var hasProps = props && Base.isPlainObject(props), - internal = hasProps && props.internal === true, + var internal = props && props.internal === true, matrix = this._matrix = new Matrix(), project = paper.project; if (!internal) @@ -2634,17 +2652,15 @@ var Item = Base.extend(Callback, { matrix._owner = this; this._style = new Style(project._currentStyle, this, project); if (!this._project) { - if (internal || hasProps && props.insert === false) { + if (internal || props && props.insert === false) { this._setProject(project); - } else if (hasProps && props.parent) { - this.setParent(props.parent); } else { (project.activeLayer || new Layer()).addChild(this); } } - if (hasProps && props !== Item.NO_INSERT) - this._set(props, { insert: true, parent: true }, true); - return hasProps; + return props && props !== Item.NO_INSERT + ? this._set(props, { insert: true }) + : true; }, _events: new function() { @@ -2769,7 +2785,7 @@ var Item = Base.extend(Callback, { set: function(props) { if (props) - this._set(props); + this._set(props, { insert: true }); return this; }, @@ -2812,6 +2828,18 @@ var Item = Base.extend(Callback, { setStyle: function(style) { this.getStyle().set(style); + }, + + hasFill: function() { + return this.getStyle().hasFill(); + }, + + hasStroke: function() { + return this.getStyle().hasStroke(); + }, + + hasShadow: function() { + return this.getStyle().hasShadow(); } }, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'], function(name) { @@ -2842,9 +2870,8 @@ var Item = Base.extend(Callback, { isSelected: function() { if (this._selectChildren) { - var children = this._children; - for (var i = 0, l = children.length; i < l; i++) - if (children[i].isSelected()) + for (var i = 0, l = this._children.length; i < l; i++) + if (this._children[i].isSelected()) return true; } return this._selected; @@ -2852,9 +2879,8 @@ var Item = Base.extend(Callback, { setSelected: function(selected, noChildren) { if (!noChildren && this._selectChildren) { - var children = this._children; - for (var i = 0, l = children.length; i < l; i++) - children[i].setSelected(selected); + for (var i = 0, l = this._children.length; i < l; i++) + this._children[i].setSelected(selected); } if ((selected = !!selected) ^ this._selected) { this._selected = selected; @@ -2866,10 +2892,9 @@ var Item = Base.extend(Callback, { _selected: false, isFullySelected: function() { - var children = this._children; - if (children && this._selected) { - for (var i = 0, l = children.length; i < l; i++) - if (!children[i].isFullySelected()) + if (this._children && this._selected) { + for (var i = 0, l = this._children.length; i < l; i++) + if (!this._children[i].isFullySelected()) return false; return true; } @@ -2877,10 +2902,9 @@ var Item = Base.extend(Callback, { }, setFullySelected: function(selected) { - var children = this._children; - if (children) { - for (var i = 0, l = children.length; i < l; i++) - children[i].setFullySelected(selected); + if (this._children) { + for (var i = 0, l = this._children.length; i < l; i++) + this._children[i].setFullySelected(selected); } this.setSelected(selected, true); }, @@ -2934,7 +2958,7 @@ var Item = Base.extend(Callback, { var pivot = this._pivot; if (pivot) { var ctor = _dontLink ? Point : LinkedPoint; - pivot = new ctor(pivot.x, pivot.y, this, 'setPivot'); + pivot = new ctor(pivot.x, pivot.y, this, 'setAnchor'); } return pivot; }, @@ -2959,7 +2983,7 @@ var Item = Base.extend(Callback, { name = !internalGetter && (typeof boundsGetter === 'string' ? boundsGetter : boundsGetter && boundsGetter[getter]) || getter, - bounds = this._getCachedBounds(name, _matrix, this, + bounds = this._getCachedBounds(name, _matrix, null, internalGetter); return key === 'bounds' ? new LinkedRectangle(bounds.x, bounds.y, bounds.width, @@ -3014,7 +3038,7 @@ var Item = Base.extend(Callback, { var _matrix = internalGetter ? null : this._matrix.orNullIfIdentity(), cache = (!matrix || matrix.equals(_matrix)) && getter; var cacheParent = this._parent || this._parentSymbol; - if (cacheParent) { + if (cacheItem && cacheParent) { var id = cacheItem._id, ref = cacheParent._boundsCache = cacheParent._boundsCache || { ids: {}, @@ -3033,7 +3057,7 @@ var Item = Base.extend(Callback, { ? matrix.clone().concatenate(_matrix) : matrix; var bounds = this._getBounds(internalGetter || getter, matrix, - cacheItem); + cache ? this : cacheItem); if (cache) { if (!this._bounds) this._bounds = {}; @@ -3049,13 +3073,11 @@ var Item = Base.extend(Callback, { for (var i = 0, list = item._boundsCache.list, l = list.length; i < l; i++) { var child = list[i]; - if (child !== item) { - child._bounds = child._position = undefined; - if (child._boundsCache) - Item._clearBoundsCache(child); - } + child._bounds = child._position = undefined; + if (child !== item && child._boundsCache) + Item._clearBoundsCache(child); } - item._bounds = item._position = item._boundsCache = undefined; + item._boundsCache = undefined; } } } @@ -3111,19 +3133,20 @@ var Item = Base.extend(Callback, { } }, - getGlobalMatrix: function(_dontClone) { + getGlobalMatrix: function(_internal) { var matrix = this._globalMatrix, - updateVersion = this._project._updateVersion; + updateVersion = this._project._updateVersion, + viewMatrix = this.getView()._matrix; if (matrix && matrix._updateVersion !== updateVersion) matrix = null; if (!matrix) { matrix = this._globalMatrix = this._matrix.clone(); - var parent = this._parent; - if (parent) - matrix.preConcatenate(parent.getGlobalMatrix(true)); + matrix.preConcatenate(this._parent + ? this._parent.getGlobalMatrix(true) + : viewMatrix); matrix._updateVersion = updateVersion; } - return _dontClone ? matrix : matrix.clone(); + return _internal ? matrix : viewMatrix.inverted().concatenate(matrix); }, getApplyMatrix: function() { @@ -3214,6 +3237,10 @@ var Item = Base.extend(Callback, { return this._index; }, + isInserted: function() { + return this._parent ? this._parent.isInserted() : false; + }, + equals: function(item) { return item === this || item && this._class === item._class && this._style.equals(item._style) @@ -3274,7 +3301,7 @@ var Item = Base.extend(Callback, { matrix = new Matrix().scale(scale).translate(topLeft.negate()); ctx.save(); matrix.applyToContext(ctx); - this.draw(ctx, new Base({ matrices: [matrix] })); + this.draw(ctx, new Base({ transforms: [matrix] })); ctx.restore(); var raster = new Raster(Item.NO_INSERT); raster.setCanvas(canvas); @@ -3300,13 +3327,9 @@ var Item = Base.extend(Callback, { return point.isInside(this.getInternalBounds()); }, - hitTest: function() { - return this._hitTest( - Point.read(arguments), - HitResult.getOptions(Base.read(arguments))); - }, - - _hitTest: function(point, options) { + hitTest: function(point, options) { + point = Point.read(arguments); + options = HitResult.getOptions(Base.read(arguments)); if (this._locked || !this._visible || this._guide && !options.guides || this.isEmpty()) return null; @@ -3316,7 +3339,8 @@ var Item = Base.extend(Callback, { view = this.getView(), totalMatrix = options._totalMatrix = parentTotalMatrix ? parentTotalMatrix.clone().concatenate(matrix) - : this.getGlobalMatrix().preConcatenate(view._matrix), + : this.getGlobalMatrix().clone().preConcatenate( + view._matrix), tolerancePadding = options._tolerancePadding = new Size( Path._getPenPadding(1, totalMatrix.inverted()) ).multiply( @@ -3327,10 +3351,12 @@ var Item = Base.extend(Callback, { if (!this._children && !this.getInternalRoughBounds() .expand(tolerancePadding.multiply(2))._containsPoint(point)) return null; - var checkSelf = !(options.guides && !this._guide + var type, + checkSelf = !(options.guides && !this._guide || options.selected && !this._selected - || options.type && options.type !== Base.hyphenate(this._class) - || options.class && !(this instanceof options.class)), + || (type = options.type) && (typeof type === 'string' + ? type !== Base.hyphenate(this._class) + : !(this instanceof type))), that = this, res; @@ -3359,10 +3385,10 @@ var Item = Base.extend(Callback, { if (children) { var opts = this._getChildHitTestOptions(options); for (var i = children.length - 1; i >= 0 && !res; i--) - res = children[i]._hitTest(point, opts); + res = children[i].hitTest(point, opts); } if (!res && checkSelf) - res = this._hitTestSelf(point, options); + res = this._hitTest(point, options); if (res && res.point) res.point = matrix.transform(res.point); options._totalMatrix = parentTotalMatrix; @@ -3373,11 +3399,11 @@ var Item = Base.extend(Callback, { return options; }, - _hitTestSelf: function(point, options) { + _hitTest: function(point, options) { if (options.fill && this.hasFill() && this._contains(point)) return new HitResult('fill', this); - }, - + } +}, { matches: function(match) { function matchObject(obj1, obj2) { for (var i in obj1) { @@ -3508,7 +3534,7 @@ var Item = Base.extend(Callback, { return null; var index = item._index + (above ? 1 : 0); if (item._parent === this._parent && index > this._index) - index--; + index--; return item._parent.insertChild(index, this, _preserve); }, @@ -3517,8 +3543,8 @@ var Item = Base.extend(Callback, { }, insertBelow: function(item, _preserve) { - return this._insert(false, item, _preserve); - }, + return this._insert(false, item, _preserve); + }, sendToBack: function() { return this._parent.insertChild(0, this); @@ -3618,7 +3644,7 @@ var Item = Base.extend(Callback, { }, isEmpty: function() { - return !this._children || this._children.length === 0; + return !this._children || this._children.length == 0; }, isEditable: function() { @@ -3631,18 +3657,6 @@ var Item = Base.extend(Callback, { return true; }, - hasFill: function() { - return this.getStyle().hasFill(); - }, - - hasStroke: function() { - return this.getStyle().hasStroke(); - }, - - hasShadow: function() { - return this.getStyle().hasShadow(); - }, - _getOrder: function(item) { function getList(item) { var list = []; @@ -3665,10 +3679,6 @@ var Item = Base.extend(Callback, { return this._children && this._children.length > 0; }, - isInserted: function() { - return this._parent ? this._parent.isInserted() : false; - }, - isAbove: function(item) { return this._getOrder(item) === -1; }, @@ -3746,7 +3756,7 @@ var Item = Base.extend(Callback, { fillColor = style.getFillColor(true), strokeColor = style.getStrokeColor(true); if (pivot) - _matrix._transformPoint(pivot, pivot, true); + pivot.transform(_matrix); if (fillColor) fillColor.transform(_matrix); if (strokeColor) @@ -3784,13 +3794,13 @@ var Item = Base.extend(Callback, { }, globalToLocal: function() { - return this.getGlobalMatrix(true)._inverseTransform( - Point.read(arguments)); + var matrix = this.getGlobalMatrix(); + return matrix && matrix._inverseTransform(Point.read(arguments)); }, localToGlobal: function() { - return this.getGlobalMatrix(true)._transformPoint( - Point.read(arguments)); + var matrix = this.getGlobalMatrix(); + return matrix && matrix._transformPoint(Point.read(arguments)); }, fitBounds: function(rectangle, fill) { @@ -3856,25 +3866,19 @@ var Item = Base.extend(Callback, { }, draw: function(ctx, param) { - var updateVersion = this._updateVersion = this._project._updateVersion; if (!this._visible || this._opacity === 0) return; - var matrices = param.matrices, - parentMatrix = matrices[matrices.length - 1], - viewMatrix = param.viewMatrix, + var updateVersion = this._updateVersion = this._project._updateVersion; + var trackTransforms = param.trackTransforms, + transforms = param.transforms, matrix = this._matrix, + parentMatrix = transforms[transforms.length - 1], globalMatrix = parentMatrix.clone().concatenate(matrix); if (!globalMatrix.isInvertible()) return; - - function getViewMatrix(matrix) { - return viewMatrix ? viewMatrix.clone().concatenate(matrix) : matrix; - } - - matrices.push(globalMatrix); - if (param.updateMatrix) { + if (trackTransforms) { + transforms.push(this._globalMatrix = globalMatrix); globalMatrix._updateVersion = updateVersion; - this._globalMatrix = globalMatrix; } var blendMode = this._blendMode, @@ -3887,7 +3891,7 @@ var Item = Base.extend(Callback, { && this._canComposite(), mainCtx, itemOffset, prevOffset; if (!direct) { - var bounds = this.getStrokeBounds(getViewMatrix(parentMatrix)); + var bounds = this.getStrokeBounds(parentMatrix); if (!bounds.width || !bounds.height) return; prevOffset = param.offset; @@ -3905,12 +3909,13 @@ var Item = Base.extend(Callback, { } else { ctx.translate(-itemOffset.x, -itemOffset.y); } - (direct ? matrix : getViewMatrix(globalMatrix)).applyToContext(ctx); + (direct ? matrix : globalMatrix).applyToContext(ctx); if (!direct && param.clipItem) param.clipItem.draw(ctx, param.extend({ clip: true })); this._draw(ctx, param); ctx.restore(); - matrices.pop(); + if (trackTransforms) + transforms.pop(); if (param.clip && !param.dontFinish) ctx.clip(); if (!direct) { @@ -3921,44 +3926,6 @@ var Item = Base.extend(Callback, { } }, - _isUpdated: function(updateVersion) { - var parent = this._parent; - if (parent instanceof CompoundPath) - return parent._isUpdated(updateVersion); - var updated = this._updateVersion === updateVersion; - if (!updated && parent && parent._visible - && parent._isUpdated(updateVersion)) { - this._updateVersion = updateVersion; - updated = true; - } - return updated; - }, - - _drawSelection: function(ctx, matrix, size, updateVersion) { - if ((this._drawSelected || this._boundsSelected) - && this._isUpdated(updateVersion)) { - var color = this.getSelectedColor(true) - || this.getLayer().getSelectedColor(true), - mx = matrix.clone().concatenate(this.getGlobalMatrix(true)); - ctx.strokeStyle = ctx.fillStyle = color - ? color.toCanvasStyle(ctx) : '#009dec'; - if (this._drawSelected) - this._drawSelected(ctx, mx); - if (this._boundsSelected) { - var half = size / 2; - coords = mx._transformCorners(this.getInternalBounds()); - ctx.beginPath(); - for (var i = 0; i < 8; i++) - ctx[i === 0 ? 'moveTo' : 'lineTo'](coords[i], coords[++i]); - ctx.closePath(); - ctx.stroke(); - for (var i = 0; i < 8; i++) - ctx.fillRect(coords[i] - half, coords[++i] - half, - size, size); - } - } - }, - _canComposite: function() { return false; } @@ -4065,7 +4032,7 @@ var Layer = Group.extend({ initialize: function Layer(arg) { var props = Base.isPlainObject(arg) - ? new Base(arg) + ? new Base(arg) : { children: Array.isArray(arg) ? arg : arguments }, insert = props.insert; props.insert = false; @@ -4264,7 +4231,7 @@ var Shape = Item.extend({ ctx.bezierCurveTo(cx, -ry, rx, -cy, rx, 0); ctx.bezierCurveTo(rx, cy, cx, ry, 0, ry); ctx.bezierCurveTo(-cx, ry, -rx, cy, -rx, 0); - } else { + } else { var size = this._size, width = size.width, height = size.height; @@ -4311,7 +4278,7 @@ var Shape = Item.extend({ return matrix ? matrix._transformBounds(rect) : rect; } }, -new function() { +new function() { function getCornerCenter(that, point, expand) { var radius = that._radius; @@ -4350,7 +4317,7 @@ new function() { } }, - _hitTestSelf: function _hitTestSelf(point, options) { + _hitTest: function _hitTest(point, options) { var hit = false; if (this.hasStroke()) { var type = this._type, @@ -4378,7 +4345,7 @@ new function() { } return hit ? new HitResult('stroke', this) - : _hitTestSelf.base.apply(this, arguments); + : _hitTest.base.apply(this, arguments); } }; }, { @@ -4497,7 +4464,7 @@ var Raster = Item.extend({ }, isEmpty: function() { - return this._size.width === 0 && this._size.height === 0; + return this._size.width == 0 && this._size.height == 0; }, getPpi: function() { @@ -4518,7 +4485,7 @@ var Raster = Item.extend({ setImage: function(image) { if (this._canvas) CanvasProvider.release(this._canvas); - if (image && image.getContext) { + if (image.getContext) { this._image = null; this._canvas = image; } else { @@ -4526,8 +4493,8 @@ var Raster = Item.extend({ this._canvas = null; } this._size = new Size( - image ? image.naturalWidth || image.width : 0, - image ? image.naturalHeight || image.height : 0); + image.naturalWidth || image.width, + image.naturalHeight || image.height); this._context = null; this._changed(9 | 513); }, @@ -4596,11 +4563,9 @@ var Raster = Item.extend({ getElement: function() { return this._canvas || this._image; - } -}, { - beans: false, + }, - getSubCanvas: function() { + getSubCanvas: function(rect) { var rect = Rectangle.read(arguments), ctx = CanvasProvider.getContext(rect.getSize()); ctx.drawImage(this.getCanvas(), rect.x, rect.y, @@ -4608,7 +4573,7 @@ var Raster = Item.extend({ return ctx.canvas; }, - getSubRaster: function() { + getSubRaster: function(rect) { var rect = Rectangle.read(arguments), raster = new Raster(Item.NO_INSERT); raster.setCanvas(this.getSubCanvas(rect)); @@ -4659,7 +4624,7 @@ var Raster = Item.extend({ .translate(-bounds.x, -bounds.y); matrix.applyToContext(ctx); if (path) - path.draw(ctx, new Base({ clip: true, matrices: [matrix] })); + path.draw(ctx, new Base({ clip: true, transforms: [matrix] })); this._matrix.applyToContext(ctx); ctx.drawImage(this.getElement(), -this._size.width / 2, -this._size.height / 2); @@ -4681,7 +4646,7 @@ var Raster = Item.extend({ return total ? Color.read(channels) : null; }, - getPixel: function() { + getPixel: function(point) { var point = Point.read(arguments); var data = this.getContext().getImageData(point.x, point.y, 1, 1).data; return new Color('rgb', [data[0] / 255, data[1] / 255, data[2] / 255], @@ -4708,7 +4673,7 @@ var Raster = Item.extend({ return this.getContext().createImageData(size.width, size.height); }, - getImageData: function() { + getImageData: function(rect) { var rect = Rectangle.read(arguments); if (rect.isEmpty()) rect = new Rectangle(this._size); @@ -4726,7 +4691,7 @@ var Raster = Item.extend({ return matrix ? matrix._transformBounds(rect) : rect; }, - _hitTestSelf: function(point) { + _hitTest: function(point) { if (this._contains(point)) { var that = this; return new HitResult('pixel', that, { @@ -4798,8 +4763,8 @@ var PlacedSymbol = Item.extend({ cacheItem); }, - _hitTestSelf: function(point, options) { - var res = this._symbol._definition._hitTest(point, options); + _hitTest: function(point, options) { + var res = this._symbol._definition.hitTest(point, options); if (res) res.item = this; return res; @@ -4825,7 +4790,7 @@ var HitResult = Base.extend({ statics: { getOptions: function(options) { - return new Base({ + return options && options._merged ? options : new Base({ type: null, tolerance: paper.settings.hitTolerance, fill: !options, @@ -4836,7 +4801,8 @@ var HitResult = Base.extend({ center: false, bounds: false, guides: false, - selected: false + selected: false, + _merged: true }, options); } } @@ -4864,7 +4830,7 @@ var Segment = Base.extend({ point = arg0; handleIn = arg1; handleOut = arg2; - } else { + } else { point = arg0 !== undefined ? [ arg0, arg1 ] : null; handleIn = arg2 !== undefined ? [ arg2, arg3 ] : null; handleOut = arg4 !== undefined ? [ arg4, arg5 ] : null; @@ -4930,12 +4896,9 @@ var Segment = Base.extend({ return this._handleIn.isZero() && this._handleOut.isZero(); }, - setLinear: function(linear) { - if (linear) { - this._handleIn.set(0, 0); - this._handleOut.set(0, 0); - } else { - } + setLinear: function() { + this._handleIn.set(0, 0); + this._handleOut.set(0, 0); }, isColinear: function(segment) { @@ -4987,7 +4950,7 @@ var Segment = Base.extend({ setSelected: function(selected, _point) { var path = this._path, - selected = !!selected, + selected = !!selected, state = this._selectionState, oldState = state, flag = !_point ? 7 @@ -5135,7 +5098,7 @@ var SegmentPoint = Point.extend({ var x, y, selected; if (!point) { x = y = 0; - } else if ((x = point[0]) !== undefined) { + } else if ((x = point[0]) !== undefined) { y = point[1]; } else { var pt = point; @@ -5372,7 +5335,7 @@ var Curve = Base.extend({ : offset && offset.curve === this ? offset.parameter : offset === undefined && isParameter === undefined - ? 0.5 + ? 0.5 : this.getParameterAt(offset, 0); }, @@ -5404,7 +5367,7 @@ var Curve = Base.extend({ } else { this._path.insert(this._segment2._index, segment); } - res = this; + res = this; } else { var end = this._segment2; this._segment2 = segment; @@ -5531,8 +5494,8 @@ statics: { p7x = u * p4x + t * p5x, p7y = u * p4y + t * p5y, p8x = u * p6x + t * p7x, p8y = u * p6y + t * p7y; return [ - [p1x, p1y, p3x, p3y, p6x, p6y, p8x, p8y], - [p8x, p8y, p7x, p7y, p5x, p5y, p2x, p2y] + [p1x, p1y, p3x, p3y, p6x, p6y, p8x, p8y], + [p8x, p8y, p7x, p7y, p5x, p5y, p2x, p2y] ]; }, @@ -5577,9 +5540,9 @@ statics: { getPart: function(v, from, to) { if (from > 0) - v = Curve.subdivide(v, from)[1]; + v = Curve.subdivide(v, from)[1]; if (to < 1) - v = Curve.subdivide(v, (to - from) / (1 - from))[0]; + v = Curve.subdivide(v, (to - from) / (1 - from))[0]; return v; }, @@ -5616,8 +5579,8 @@ statics: { }, getBounds: function(v) { - var min = v.slice(0, 2), - max = min.slice(), + var min = v.slice(0, 2), + max = min.slice(), roots = [0, 0]; for (var i = 0; i < 2; i++) Curve._addBounds(v[i], v[i + 2], v[i + 4], v[i + 6], @@ -5679,14 +5642,12 @@ statics: { }; }, { - beans: false, - getParameterAt: function(offset, start) { return Curve.getParameterAt(this.getValues(), offset, start !== undefined ? start : offset < 0 ? 1 : 0); }, - getParameterOf: function() { + getParameterOf: function(point) { var point = Point.read(arguments); return Curve.getParameterOf(this.getValues(), point.x, point.y); }, @@ -5697,13 +5658,13 @@ statics: { return new CurveLocation(this, offset); }, - getLocationOf: function() { + getLocationOf: function(point) { var point = Point.read(arguments), t = this.getParameterOf(point); return t != null ? new CurveLocation(this, t) : null; }, - getNearestLocation: function() { + getNearestLocation: function(point) { var point = Point.read(arguments), values = this.getValues(), count = 100, @@ -5735,12 +5696,13 @@ statics: { point.getDistance(pt)); }, - getNearestPoint: function() { - return this.getNearestLocation.apply(this, arguments).getPoint(); + getNearestPoint: function(point) { + var point = Point.read(arguments); + return this.getNearestLocation(point).getPoint(); } }), -new function() { +new function() { function getLengthIntegrand(v) { var p1x = v[0], p1y = v[1], @@ -5779,8 +5741,8 @@ new function() { if (a === 0 && b === 1 && isZero(v[0] - v[2]) && isZero(v[1] - v[3]) && isZero(v[6] - v[4]) && isZero(v[7] - v[5])) { - var dx = v[6] - v[0], - dy = v[7] - v[1]; + var dx = v[6] - v[0], + dy = v[7] - v[1]; return Math.sqrt(dx * dx + dy * dy); } var ds = getLengthIntegrand(v); @@ -5810,11 +5772,11 @@ new function() { return length - offset; } return Numerical.findRoot(f, ds, - forward ? a + guess : b - guess, + forward ? a + guess : b - guess, a, b, 16, 0.00001); } }; -}, new function() { +}, new function() { function addLocation(locations, include, curve1, t1, point1, curve2, t2, point2) { var loc = new CurveLocation(curve1, t1, point1, curve2, t2, point2); @@ -5892,7 +5854,7 @@ new function() { curve1, t1, Curve.evaluate(v1, t1, 0), curve2, t2, Curve.evaluate(v2, t2, 0)); } - } else { + } else { addCurveIntersections(v2, v1, curve2, curve1, locations, include, uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, ++recursion); } @@ -6427,7 +6389,7 @@ var Path = PathItem.extend({ if (segments && segments.length > 0) { this.setSegments(segments); } else { - this._curves = undefined; + this._curves = undefined; this._selectedSegmentState = 0; if (!segments && typeof arg === 'string') { this.setPathData(arg); @@ -6689,7 +6651,7 @@ var Path = PathItem.extend({ to = Base.pick(to, this._segments.length); var segments = this._segments, curves = this._curves, - count = segments.length, + count = segments.length, removed = segments.splice(from, to - from), amount = removed.length; if (!amount) @@ -6717,24 +6679,6 @@ var Path = PathItem.extend({ clear: '#removeSegments', - getLength: function() { - if (this._length == null) { - var curves = this.getCurves(); - this._length = 0; - for (var i = 0, l = curves.length; i < l; i++) - this._length += curves[i].getLength(); - } - return this._length; - }, - - getArea: function() { - var curves = this.getCurves(); - var area = 0; - for (var i = 0, l = curves.length; i < l; i++) - area += curves[i].getArea(); - return area; - }, - isFullySelected: function() { var length = this._segments.length; return this._selected && length > 0 && this._selectedSegmentState @@ -6858,7 +6802,6 @@ var Path = PathItem.extend({ this._curves = null; if (this._clockwise !== undefined) this._clockwise = !this._clockwise; - this._changed(8); }, join: function(path) { @@ -6898,6 +6841,106 @@ var Path = PathItem.extend({ } }, + getLength: function() { + if (this._length == null) { + var curves = this.getCurves(); + this._length = 0; + for (var i = 0, l = curves.length; i < l; i++) + this._length += curves[i].getLength(); + } + return this._length; + }, + + getArea: function() { + var curves = this.getCurves(); + var area = 0; + for (var i = 0, l = curves.length; i < l; i++) + area += curves[i].getArea(); + return area; + }, + + _getOffset: function(location) { + var index = location && location.getIndex(); + if (index != null) { + var curves = this.getCurves(), + offset = 0; + for (var i = 0; i < index; i++) + offset += curves[i].getLength(); + var curve = curves[index], + parameter = location.getParameter(); + if (parameter > 0) + offset += curve.getPartLength(0, parameter); + return offset; + } + return null; + }, + + getLocationOf: function(point) { + var point = Point.read(arguments), + curves = this.getCurves(); + for (var i = 0, l = curves.length; i < l; i++) { + var loc = curves[i].getLocationOf(point); + if (loc) + return loc; + } + return null; + }, + + getLocationAt: function(offset, isParameter) { + var curves = this.getCurves(), + length = 0; + if (isParameter) { + var index = ~~offset; + return curves[index].getLocationAt(offset - index, true); + } + for (var i = 0, l = curves.length; i < l; i++) { + var start = length, + curve = curves[i]; + length += curve.getLength(); + if (length > offset) { + return curve.getLocationAt(offset - start); + } + } + if (offset <= this.getLength()) + return new CurveLocation(curves[curves.length - 1], 1); + return null; + }, + + getPointAt: function(offset, isParameter) { + var loc = this.getLocationAt(offset, isParameter); + return loc && loc.getPoint(); + }, + + getTangentAt: function(offset, isParameter) { + var loc = this.getLocationAt(offset, isParameter); + return loc && loc.getTangent(); + }, + + getNormalAt: function(offset, isParameter) { + var loc = this.getLocationAt(offset, isParameter); + return loc && loc.getNormal(); + }, + + getNearestLocation: function(point) { + var point = Point.read(arguments), + curves = this.getCurves(), + minDist = Infinity, + minLoc = null; + for (var i = 0, l = curves.length; i < l; i++) { + var loc = curves[i].getNearestLocation(point); + if (loc._distance < minDist) { + minDist = loc._distance; + minLoc = loc; + } + } + return minLoc; + }, + + getNearestPoint: function(point) { + var point = Point.read(arguments); + return this.getNearestLocation(point).getPoint(); + }, + toShape: function(insert) { if (!this._closed) return null; @@ -6965,7 +7008,7 @@ var Path = PathItem.extend({ return null; }, - _hitTestSelf: function(point, options) { + _hitTest: function(point, options) { var that = this, style = this.getStyle(), segments = this._segments, @@ -6975,14 +7018,11 @@ var Path = PathItem.extend({ strokePadding = tolerancePadding, join, cap, miterLimit, area, loc, res, - hitStroke = options.stroke && style.hasStroke(), - hitFill = options.fill && style.hasFill(), - hitCurves = options.curves, - radius = hitStroke - ? style.getStrokeWidth() / 2 - : hitFill && options.tolerance > 0 || hitCurves - ? 0 : null; - if (radius !== null) { + hasStroke = options.stroke && style.hasStroke(), + hasFill = options.fill && style.hasFill(), + radius = hasStroke ? style.getStrokeWidth() / 2 + : hasFill ? 0 : null; + if (radius != null) { if (radius > 0) { join = style.getStrokeJoin(); cap = style.getStrokeCap(); @@ -7054,7 +7094,7 @@ var Path = PathItem.extend({ if (res = checkSegmentPoints(segments[i])) return res; } - if (radius !== null) { + if (radius != null) { loc = this.getNearestLocation(point); if (loc) { var parameter = loc.getParameter(); @@ -7076,101 +7116,17 @@ var Path = PathItem.extend({ } } } - return !loc && hitFill && this._contains(point) - || loc && !hitStroke && !hitCurves - ? new HitResult('fill', this) - : loc - ? new HitResult(hitStroke ? 'stroke' : 'curve', this, { - location: loc, - point: loc.getPoint() - }) - : null; + return !loc && hasFill && this._contains(point) || loc && !hasStroke + ? new HitResult('fill', this) + : loc + ? new HitResult('stroke', this, { + location: loc, + point: loc.getPoint() + }) + : null; } -}, { - beans: false, - - _getOffset: function(location) { - var index = location && location.getIndex(); - if (index != null) { - var curves = this.getCurves(), - offset = 0; - for (var i = 0; i < index; i++) - offset += curves[i].getLength(); - var curve = curves[index], - parameter = location.getParameter(); - if (parameter > 0) - offset += curve.getPartLength(0, parameter); - return offset; - } - return null; - }, - - getLocationOf: function() { - var point = Point.read(arguments), - curves = this.getCurves(); - for (var i = 0, l = curves.length; i < l; i++) { - var loc = curves[i].getLocationOf(point); - if (loc) - return loc; - } - return null; - }, - - getLocationAt: function(offset, isParameter) { - var curves = this.getCurves(), - length = 0; - if (isParameter) { - var index = ~~offset; - return curves[index].getLocationAt(offset - index, true); - } - for (var i = 0, l = curves.length; i < l; i++) { - var start = length, - curve = curves[i]; - length += curve.getLength(); - if (length > offset) { - return curve.getLocationAt(offset - start); - } - } - if (offset <= this.getLength()) - return new CurveLocation(curves[curves.length - 1], 1); - return null; - }, - - getPointAt: function(offset, isParameter) { - var loc = this.getLocationAt(offset, isParameter); - return loc && loc.getPoint(); - }, - - getTangentAt: function(offset, isParameter) { - var loc = this.getLocationAt(offset, isParameter); - return loc && loc.getTangent(); - }, - - getNormalAt: function(offset, isParameter) { - var loc = this.getLocationAt(offset, isParameter); - return loc && loc.getNormal(); - }, - - getNearestLocation: function() { - var point = Point.read(arguments), - curves = this.getCurves(), - minDist = Infinity, - minLoc = null; - for (var i = 0, l = curves.length; i < l; i++) { - var loc = curves[i].getNearestLocation(point); - if (loc._distance < minDist) { - minDist = loc._distance; - minLoc = loc; - } - } - return minLoc; - }, - - getNearestPoint: function() { - return this.getNearestLocation.apply(this, arguments).getPoint(); - } -}, new function() { +}, new function() { function drawHandles(ctx, segments, matrix, size) { var half = size / 2; @@ -7333,12 +7289,12 @@ var Path = PathItem.extend({ drawHandles(ctx, this._segments, matrix, paper.settings.handleSize); } }; -}, new function() { +}, new function() { function getFirstControlPoints(rhs) { var n = rhs.length, - x = [], - tmp = [], + x = [], + tmp = [], b = 2; x[0] = rhs[0] / b; for (var i = 1; i < n; i++) { @@ -7426,7 +7382,7 @@ var Path = PathItem.extend({ } } }; -}, new function() { +}, new function() { function getCurrentSegment(that) { var segments = that._segments; if (segments.length === 0) @@ -7650,7 +7606,7 @@ var Path = PathItem.extend({ this.join(); } }; -}, { +}, { _getBounds: function(getter, matrix) { return Path[getter](this._segments, this._closed, this.getStyle(), @@ -7675,18 +7631,18 @@ statics: { return new Rectangle(); var coords = new Array(6), prevCoords = first._transformCoordinates(matrix, new Array(6), false), - min = prevCoords.slice(0, 2), - max = min.slice(), + min = prevCoords.slice(0, 2), + max = min.slice(), roots = new Array(2); function processSegment(segment) { segment._transformCoordinates(matrix, coords, false); for (var i = 0; i < 2; i++) { Curve._addBounds( - prevCoords[i], - prevCoords[i + 4], - coords[i + 2], - coords[i], + prevCoords[i], + prevCoords[i + 4], + coords[i + 2], + coords[i], i, strokePadding ? strokePadding[i] : 0, min, max, roots); } var tmp = prevCoords; @@ -7725,7 +7681,7 @@ statics: { function addJoin(segment, join) { var handleIn = segment._handleIn, - handleOut = segment._handleOut; + handleOut = segment._handleOut if (join === 'round' || !handleIn.isZero() && !handleOut.isZero() && handleIn.isColinear(handleOut)) { addRound(segment); @@ -7812,7 +7768,7 @@ statics: { addPoint(point.add(normal)); } if (cap === 'square') - point = point.add(normal.rotate(loc.getParameter() === 0 ? -90 : 90)); + point = point.add(normal.rotate(loc.getParameter() == 0 ? -90 : 90)); addPoint(point.add(normal)); addPoint(point.subtract(normal)); }, @@ -7828,7 +7784,7 @@ statics: { var segment = segments[i]; segment._transformCoordinates(matrix, coords, false); for (var j = 0; j < 6; j += 2) { - var padding = j === 0 ? joinPadding : strokePadding, + var padding = j == 0 ? joinPadding : strokePadding, paddingX = padding ? padding[0] : 0, paddingY = padding ? padding[1] : 0, x = coords[j], @@ -8090,7 +8046,7 @@ var CompoundPath = PathItem.extend({ } }, { _getChildHitTestOptions: function(options) { - return options.class === Path || options.type === 'path' + return options.type === 'path' ? options : new Base(options, { fill: false }); }, @@ -8131,7 +8087,7 @@ var CompoundPath = PathItem.extend({ : matrix.clone().concatenate(child._matrix)); } } -}, new function() { +}, new function() { function getCurrentPath(that, check) { var children = that._children; if (check && children.length === 0) @@ -8254,9 +8210,7 @@ PathItem.inject(new function() { _path1.remove(); if (_path2) _path2.remove(); - result = result.reduce(); - result.setStyle(path1._style); - return result; + return result.reduce(); } function splitPath(intersections) { @@ -8388,7 +8342,7 @@ PathItem.inject(new function() { var path = new Path(Item.NO_INSERT), inter = seg._intersection, startInterSeg = inter && inter._segment, - added = false, + added = false, dir = 1; do { var handleIn = dir > 0 ? seg._handleIn : seg._handleOut, @@ -8501,12 +8455,12 @@ Path.inject({ curve = { values: v, winding: y0 === y1 - ? 0 + ? 0 : y0 > y1 - ? -1 - : 1, + ? -1 + : 1, previous: prevCurve, - next: null + next: null }; if (prevCurve) prevCurve.next = curve; @@ -8617,7 +8571,7 @@ CompoundPath.inject({ }); this.addChildren(children); var clockwise = children[0].isClockwise(); - for (var i = 1, l = children.length; i < l; i++) { + for (var i = 1, l = children.length; i < l; i++) { var point = children[i].getInteriorPoint(), counters = 0; for (var j = i - 1; j >= 0; j--) { @@ -8632,9 +8586,9 @@ CompoundPath.inject({ var PathFlattener = Base.extend({ initialize: function(path) { - this.curves = []; - this.parts = []; - this.length = 0; + this.curves = []; + this.parts = []; + this.length = 0; this.index = 0; var segments = path._segments, @@ -8900,7 +8854,7 @@ var PathFitter = Base.extend({ for (var i = first + 1; i < last; i++) { var P = this.evaluate(3, curve, u[i - first]); var v = P.subtract(this.points[i]); - var dist = v.x * v.x + v.y * v.y; + var dist = v.x * v.x + v.y * v.y; if (dist >= maxDist) { maxDist = dist; index = i; @@ -9023,6 +8977,7 @@ var PointText = TextItem.extend({ }); var Color = Base.extend(new function() { + var types = { gray: ['gray'], rgb: ['red', 'green', 'blue'], @@ -9074,12 +9029,12 @@ var Color = Base.extend(new function() { } var hsbIndices = [ - [0, 3, 1], - [2, 0, 1], - [1, 0, 3], - [1, 2, 0], - [3, 1, 0], - [0, 1, 2] + [0, 3, 1], + [2, 0, 1], + [1, 0, 3], + [1, 2, 0], + [3, 1, 0], + [0, 1, 2] ]; var converters = { @@ -9090,20 +9045,20 @@ var Color = Base.extend(new function() { h = delta === 0 ? 0 : ( max == r ? (g - b) / delta + (g < b ? 6 : 0) : max == g ? (b - r) / delta + 2 - : (r - g) / delta + 4) * 60; + : (r - g) / delta + 4) * 60; return [h, max === 0 ? 0 : delta / max, max]; }, 'hsb-rgb': function(h, s, b) { h = (((h / 60) % 6) + 6) % 6; - var i = Math.floor(h), + var i = Math.floor(h), f = h - i, i = hsbIndices[i], v = [ - b, - b * (1 - s), - b * (1 - s * f), - b * (1 - s * (1 - f)) + b, + b * (1 - s), + b * (1 - s * f), + b * (1 - s * (1 - f)) ]; return [v[i[0]], v[i[1]], v[i[2]]]; }, @@ -9116,7 +9071,7 @@ var Color = Base.extend(new function() { h = achromatic ? 0 : ( max == r ? (g - b) / delta + (g < b ? 6 : 0) : max == g ? (b - r) / delta + 2 - : (r - g) / delta + 4) * 60, + : (r - g) / delta + 4) * 60, l = (max + min) / 2, s = achromatic ? 0 : l < 0.5 ? delta / (max + min) @@ -9248,7 +9203,7 @@ var Color = Base.extend(new function() { alpha = args[2]; } else { if (this.__read) - read = 1; + read = 1; args = slice.call(args, 1); argType = typeof arg; } @@ -9407,7 +9362,7 @@ var Color = Base.extend(new function() { }, equals: function(color) { - var col = Base.isPlainValue(color, true) + var col = Base.isPlainValue(color) ? Color.read(arguments) : color; return col === this || col && this._class === col._class @@ -9739,7 +9694,7 @@ var Style = Base.extend(new function() { fontFamily: 'sans-serif', fontWeight: 'normal', fontSize: 12, - font: 'sans-serif', + font: 'sans-serif', leading: null, justification: 'left' }; @@ -9752,16 +9707,16 @@ var Style = Base.extend(new function() { fontFamily: 9, fontWeight: 9, fontSize: 9, - font: 9, + font: 9, leading: 9, justification: 9 }; - var item = { beans: true }, + var item = {}, fields = { _defaults: defaults, _textDefaults: new Base(defaults, { - fillColor: new Color() + fillColor: new Color() }), beans: true }; @@ -9830,8 +9785,8 @@ var Style = Base.extend(new function() { return value; }; - item[get] = function(_dontMerge) { - return this._style[get](_dontMerge); + item[get] = function() { + return this._style[get](); }; item[set] = function(value) { @@ -10417,7 +10372,7 @@ var View = Base.extend(Callback, { return; this._viewSize.set(size.width, size.height); this._setViewSize(size); - this._bounds = null; + this._bounds = null; this.fire('resize', { size: size, delta: delta @@ -10446,8 +10401,8 @@ var View = Base.extend(Callback, { return this.getBounds().getCenter(); }, - setCenter: function() { - var center = Point.read(arguments); + setCenter: function(center) { + center = Point.read(arguments); this.scrollBy(center.subtract(this.getCenter())); }, @@ -10707,7 +10662,7 @@ var CanvasView = View.extend({ project._needsUpdate = false; return true; } -}, new function() { +}, new function() { var downPoint, lastPoint, @@ -10752,7 +10707,7 @@ var CanvasView = View.extend({ return; var project = this._project, hit = project.hitTest(point, { - tolerance: 0, + tolerance: this._scope.settings.hitTolerance, fill: true, stroke: true }), @@ -10881,14 +10836,14 @@ var Key = new function() { 40: 'down', 46: 'delete', 91: 'command', - 93: 'command', - 224: 'command' + 93: 'command', + 224: 'command' }, specialChars = { - 9: true, - 13: true, - 32: true + 9: true, + 13: true, + 32: true }, modifiers = new Base({ @@ -10900,9 +10855,9 @@ var Key = new function() { space: false }), - charCodeMap = {}, - keyMap = {}, - downCode; + charCodeMap = {}, + keyMap = {}, + downCode; function handleKey(down, keyCode, charCode, event) { var character = charCode ? String.fromCharCode(charCode) : '', @@ -11558,9 +11513,9 @@ var BlendMode = new function() { var min = Math.min, max = Math.max, abs = Math.abs, - sr, sg, sb, sa, - br, bg, bb, ba, - dr, dg, db; + sr, sg, sb, sa, + br, bg, bb, ba, + dr, dg, db; function getLum(r, g, b) { return 0.2989 * r + 0.587 * g + 0.114 * b; @@ -11595,9 +11550,9 @@ var BlendMode = new function() { function setSat(r, g, b, s) { var col = [r, g, b], - mx = max(r, g, b), - mn = min(r, g, b), - md; + mx = max(r, g, b), + mn = min(r, g, b), + md; mn = mn === r ? 0 : mn === g ? 1 : 2; mx = mx === r ? 0 : mx === g ? 1 : 2; md = min(mn, mx) === 0 ? max(mn, mx) === 1 ? 2 : 1 : 0; @@ -11975,7 +11930,7 @@ new function() { radius = item._radius, attrs = getTransform(item, true, type !== 'rectangle'); if (type === 'rectangle') { - type = 'rect'; + type = 'rect'; var size = item._size, width = size.width, height = size.height; @@ -12128,7 +12083,7 @@ new function() { if (attrs.opacity === 1) delete attrs.opacity; - if (!item._visible) + if (item._visibility != null && !item._visibility) attrs.visibility = 'hidden'; return setAttributes(node, attrs); @@ -12175,12 +12130,9 @@ new function() { function exportSVG(item, options) { var exporter = exporters[item._class], node = exporter && exporter(item, options); - if (node) { - var onExport = options.onExport; - if (onExport) - node = onExport(item, node, options) || node; + if (node && item._data) { var data = JSON.stringify(item._data); - if (data && data !== '{}') + if (data !== '{}') node.setAttribute('data-paper-data', data); } return node && applyStyle(item, node); @@ -12523,10 +12475,6 @@ new function() { item.setVisible(value === 'visible'); }, - display: function(item, value) { - item.setVisible(value !== null); - }, - 'stop-color': function(item, value) { if (item.setColor) item.setColor(value); @@ -12655,9 +12603,6 @@ new function() { if (item) { if (!(item instanceof Group)) item = applyAttributes(item, node, isRoot); - var onImport = options.onImport; - if (onImport) - item = onImport(node, item, options) || item; if (options.expandShapes && item instanceof Shape) { item.remove(); item = item.toPath(); @@ -12689,19 +12634,6 @@ Base.exports.PaperScript = (function() { scope = this; !function(e,r){return"object"==typeof exports&&"object"==typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):(r(e.acorn||(e.acorn={})),void 0)}(this,function(e){"use strict";function r(e){fr=e||{};for(var r in hr)Object.prototype.hasOwnProperty.call(fr,r)||(fr[r]=hr[r]);mr=fr.sourceFile||null}function t(e,r){var t=vr(pr,e);r+=" ("+t.line+":"+t.column+")";var n=new SyntaxError(r);throw n.pos=e,n.loc=t,n.raisedAt=br,n}function n(e){function r(e){if(1==e.length)return t+="return str === "+JSON.stringify(e[0])+";";t+="switch(str){";for(var r=0;r3){n.sort(function(e,r){return r.length-e.length}),t+="switch(str.length){";for(var a=0;abr&&10!==t&&13!==t&&8232!==t&&8329!==t;)++br,t=pr.charCodeAt(br);fr.onComment&&fr.onComment(!1,pr.slice(e+2,br),e,br,r,fr.locations&&new a)}function u(){for(;dr>br;){var e=pr.charCodeAt(br);if(32===e)++br;else if(13===e){++br;var r=pr.charCodeAt(br);10===r&&++br,fr.locations&&(++Ar,Sr=br)}else if(10===e)++br,++Ar,Sr=br;else if(14>e&&e>8)++br;else if(47===e){var r=pr.charCodeAt(br+1);if(42===r)s();else{if(47!==r)break;c()}}else if(160===e)++br;else{if(!(e>=5760&&Jt.test(String.fromCharCode(e))))break;++br}}}function l(){var e=pr.charCodeAt(br+1);return e>=48&&57>=e?E(!0):(++br,i(xt))}function f(){var e=pr.charCodeAt(br+1);return Er?(++br,k()):61===e?x(Et,2):x(wt,1)}function p(){var e=pr.charCodeAt(br+1);return 61===e?x(Et,2):x(Ft,1)}function d(e){var r=pr.charCodeAt(br+1);return r===e?x(124===e?Lt:Ut,2):61===r?x(Et,2):x(124===e?Rt:Vt,1)}function m(){var e=pr.charCodeAt(br+1);return 61===e?x(Et,2):x(Tt,1)}function h(e){var r=pr.charCodeAt(br+1);return r===e?x(St,2):61===r?x(Et,2):x(At,1)}function v(e){var r=pr.charCodeAt(br+1),t=1;return r===e?(t=62===e&&62===pr.charCodeAt(br+2)?3:2,61===pr.charCodeAt(br+t)?x(Et,t+1):x(jt,t)):(61===r&&(t=61===pr.charCodeAt(br+2)?3:2),x(Ot,t))}function b(e){var r=pr.charCodeAt(br+1);return 61===r?x(qt,61===pr.charCodeAt(br+2)?3:2):x(61===e?Ct:It,1)}function y(e){switch(e){case 46:return l();case 40:return++br,i(ht);case 41:return++br,i(vt);case 59:return++br,i(yt);case 44:return++br,i(bt);case 91:return++br,i(ft);case 93:return++br,i(pt);case 123:return++br,i(dt);case 125:return++br,i(mt);case 58:return++br,i(gt);case 63:return++br,i(kt);case 48:var r=pr.charCodeAt(br+1);if(120===r||88===r)return C();case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return E(!1);case 34:case 39:return A(e);case 47:return f(e);case 37:case 42:return p();case 124:case 38:return d(e);case 94:return m();case 43:case 45:return h(e);case 60:case 62:return v(e);case 61:case 33:return b(e);case 126:return x(It,1)}return!1}function g(e){if(e?br=yr+1:yr=br,fr.locations&&(xr=new a),e)return k();if(br>=dr)return i(Br);var r=pr.charCodeAt(br);if(Qt(r)||92===r)return L();var n=y(r);if(n===!1){var o=String.fromCharCode(r);if("\\"===o||$t.test(o))return L();t(br,"Unexpected character '"+o+"'")}return n}function x(e,r){var t=pr.slice(br,br+r);br+=r,i(e,t)}function k(){for(var e,r,n="",a=br;;){br>=dr&&t(a,"Unterminated regular expression");var o=pr.charAt(br);if(Gt.test(o)&&t(a,"Unterminated regular expression"),e)e=!1;else{if("["===o)r=!0;else if("]"===o&&r)r=!1;else if("/"===o&&!r)break;e="\\"===o}++br}var n=pr.slice(a,br);++br;var s=I();return s&&!/^[gmsiy]*$/.test(s)&&t(a,"Invalid regexp flag"),i(jr,new RegExp(n,s))}function w(e,r){for(var t=br,n=0,a=0,o=null==r?1/0:r;o>a;++a){var i,s=pr.charCodeAt(br);if(i=s>=97?s-97+10:s>=65?s-65+10:s>=48&&57>=s?s-48:1/0,i>=e)break;++br,n=n*e+i}return br===t||null!=r&&br-t!==r?null:n}function C(){br+=2;var e=w(16);return null==e&&t(yr+2,"Expected hexadecimal number"),Qt(pr.charCodeAt(br))&&t(br,"Identifier directly after number"),i(Or,e)}function E(e){var r=br,n=!1,a=48===pr.charCodeAt(br);e||null!==w(10)||t(r,"Invalid number"),46===pr.charCodeAt(br)&&(++br,w(10),n=!0);var o=pr.charCodeAt(br);(69===o||101===o)&&(o=pr.charCodeAt(++br),(43===o||45===o)&&++br,null===w(10)&&t(r,"Invalid number"),n=!0),Qt(pr.charCodeAt(br))&&t(br,"Identifier directly after number");var s,c=pr.slice(r,br);return n?s=parseFloat(c):a&&1!==c.length?/[89]/.test(c)||Vr?t(r,"Invalid number"):s=parseInt(c,8):s=parseInt(c,10),i(Or,s)}function A(e){br++;for(var r="";;){br>=dr&&t(yr,"Unterminated string constant");var n=pr.charCodeAt(br);if(n===e)return++br,i(Fr,r);if(92===n){n=pr.charCodeAt(++br);var a=/^[0-7]+/.exec(pr.slice(br,br+3));for(a&&(a=a[0]);a&&parseInt(a,8)>255;)a=a.slice(0,a.length-1);if("0"===a&&(a=null),++br,a)Vr&&t(br-2,"Octal literal in strict mode"),r+=String.fromCharCode(parseInt(a,8)),br+=a.length-1;else switch(n){case 110:r+="\n";break;case 114:r+="\r";break;case 120:r+=String.fromCharCode(S(2));break;case 117:r+=String.fromCharCode(S(4));break;case 85:r+=String.fromCharCode(S(8));break;case 116:r+=" ";break;case 98:r+="\b";break;case 118:r+=" ";break;case 102:r+="\f";break;case 48:r+="\0";break;case 13:10===pr.charCodeAt(br)&&++br;case 10:fr.locations&&(Sr=br,++Ar);break;default:r+=String.fromCharCode(n)}}else(13===n||10===n||8232===n||8329===n)&&t(yr,"Unterminated string constant"),r+=String.fromCharCode(n),++br}}function S(e){var r=w(16,e);return null===r&&t(yr,"Bad character escape sequence"),r}function I(){Bt=!1;for(var e,r=!0,n=br;;){var a=pr.charCodeAt(br);if(Yt(a))Bt&&(e+=pr.charAt(br)),++br;else{if(92!==a)break;Bt||(e=pr.slice(n,br)),Bt=!0,117!=pr.charCodeAt(++br)&&t(br,"Expecting Unicode escape sequence \\uXXXX"),++br;var o=S(4),i=String.fromCharCode(o);i||t(br-1,"Invalid Unicode escape"),(r?Qt(o):Yt(o))||t(br-4,"Invalid Unicode escape"),e+=i}r=!1}return Bt?e:pr.slice(n,br)}function L(){var e=I(),r=Dr;return Bt||(Wt(e)?r=lt[e]:(fr.forbidReserved&&(3===fr.ecmaVersion?Mt:zt)(e)||Vr&&Xt(e))&&t(yr,"The keyword '"+e+"' is reserved")),i(r,e)}function U(){Ir=yr,Lr=gr,Ur=kr,g()}function R(e){for(Vr=e,br=Lr;Sr>br;)Sr=pr.lastIndexOf("\n",Sr-2)+1,--Ar;u(),g()}function T(){this.type=null,this.start=yr,this.end=null}function V(){this.start=xr,this.end=null,null!==mr&&(this.source=mr)}function q(){var e=new T;return fr.locations&&(e.loc=new V),fr.ranges&&(e.range=[yr,0]),e}function O(e){var r=new T;return r.start=e.start,fr.locations&&(r.loc=new V,r.loc.start=e.loc.start),fr.ranges&&(r.range=[e.range[0],0]),r}function j(e,r){return e.type=r,e.end=Lr,fr.locations&&(e.loc.end=Ur),fr.ranges&&(e.range[1]=Lr),e}function F(e){return fr.ecmaVersion>=5&&"ExpressionStatement"===e.type&&"Literal"===e.expression.type&&"use strict"===e.expression.value}function D(e){return wr===e?(U(),!0):void 0}function B(){return!fr.strictSemicolons&&(wr===Br||wr===mt||Gt.test(pr.slice(Lr,yr)))}function M(){D(yt)||B()||X()}function z(e){wr===e?U():X()}function X(){t(yr,"Unexpected token")}function N(e){"Identifier"!==e.type&&"MemberExpression"!==e.type&&t(e.start,"Assigning to rvalue"),Vr&&"Identifier"===e.type&&Nt(e.name)&&t(e.start,"Assigning to "+e.name+" in strict mode")}function W(e){Ir=Lr=br,fr.locations&&(Ur=new a),Rr=Vr=null,Tr=[],g();var r=e||q(),t=!0;for(e||(r.body=[]);wr!==Br;){var n=J();r.body.push(n),t&&F(n)&&R(!0),t=!1}return j(r,"Program")}function J(){wr===wt&&g(!0);var e=wr,r=q();switch(e){case Mr:case Nr:U();var n=e===Mr;D(yt)||B()?r.label=null:wr!==Dr?X():(r.label=lr(),M());for(var a=0;ar){var a=O(e);a.left=e,a.operator=Cr,U(),a.right=er(rr(),n,t);var a=j(a,/&&|\|\|/.test(a.operator)?"LogicalExpression":"BinaryExpression");return er(a,r,t)}return e}function rr(){if(wr.prefix){var e=q(),r=wr.isUpdate;return e.operator=Cr,e.prefix=!0,U(),e.argument=rr(),r?N(e.argument):Vr&&"delete"===e.operator&&"Identifier"===e.argument.type&&t(e.start,"Deleting local variable in strict mode"),j(e,r?"UpdateExpression":"UnaryExpression")}for(var n=tr();wr.postfix&&!B();){var e=O(n);e.operator=Cr,e.prefix=!1,e.argument=n,N(n),U(),n=j(e,"UpdateExpression")}return n}function tr(){return nr(ar())}function nr(e,r){if(D(xt)){var t=O(e);return t.object=e,t.property=lr(!0),t.computed=!1,nr(j(t,"MemberExpression"),r)}if(D(ft)){var t=O(e);return t.object=e,t.property=K(),t.computed=!0,z(pt),nr(j(t,"MemberExpression"),r)}if(!r&&D(ht)){var t=O(e);return t.callee=e,t.arguments=ur(vt,!1),nr(j(t,"CallExpression"),r)}return e}function ar(){switch(wr){case ot:var e=q();return U(),j(e,"ThisExpression");case Dr:return lr();case Or:case Fr:case jr:var e=q();return e.value=Cr,e.raw=pr.slice(yr,gr),U(),j(e,"Literal");case it:case st:case ct:var e=q();return e.value=wr.atomValue,e.raw=wr.keyword,U(),j(e,"Literal");case ht:var r=xr,t=yr;U();var n=K();return n.start=t,n.end=gr,fr.locations&&(n.loc.start=r,n.loc.end=kr),fr.ranges&&(n.range=[t,gr]),z(vt),n;case ft:var e=q();return U(),e.elements=ur(pt,!0,!0),j(e,"ArrayExpression");case dt:return ir();case Gr:var e=q();return U(),cr(e,!1);case at:return or();default:X()}}function or(){var e=q();return U(),e.callee=nr(ar(),!0),e.arguments=D(ht)?ur(vt,!1):qr,j(e,"NewExpression")}function ir(){var e=q(),r=!0,n=!1;for(e.properties=[],U();!D(mt);){if(r)r=!1;else if(z(bt),fr.allowTrailingCommas&&D(mt))break;var a,o={key:sr()},i=!1;if(D(gt)?(o.value=K(!0),a=o.kind="init"):fr.ecmaVersion>=5&&"Identifier"===o.key.type&&("get"===o.key.name||"set"===o.key.name)?(i=n=!0,a=o.kind=o.key.name,o.key=sr(),wr!==ht&&X(),o.value=cr(q(),!1)):X(),"Identifier"===o.key.type&&(Vr||n))for(var s=0;si?e.id:e.params[i];if((Xt(s.name)||Nt(s.name))&&t(s.start,"Defining '"+s.name+"' in strict mode"),i>=0)for(var c=0;i>c;++c)s.name===e.params[c].name&&t(s.start,"Argument name clash in strict mode")}return j(e,r?"FunctionDeclaration":"FunctionExpression")}function ur(e,r,t){for(var n=[],a=!0;!D(e);){if(a)a=!1;else if(z(bt),r&&fr.allowTrailingCommas&&D(e))break;t&&wr===bt?n.push(null):n.push(K(!0))}return n}function lr(e){var r=q();return r.name=wr===Dr?Cr:e&&!fr.forbidReserved&&wr.keyword||X(),U(),j(r,"Identifier")}e.version="0.3.2";var fr,pr,dr,mr;e.parse=function(e,t){return pr=String(e),dr=pr.length,r(t),o(),W(fr.program)};var hr=e.defaultOptions={ecmaVersion:5,strictSemicolons:!1,allowTrailingCommas:!0,forbidReserved:!1,locations:!1,onComment:null,ranges:!1,program:null,sourceFile:null},vr=e.getLineInfo=function(e,r){for(var t=1,n=0;;){Kt.lastIndex=n;var a=Kt.exec(e);if(!(a&&a.indexe?36===e:91>e?!0:97>e?95===e:123>e?!0:e>=170&&$t.test(String.fromCharCode(e))},Yt=e.isIdentifierChar=function(e){return 48>e?36===e:58>e?!0:65>e?!1:91>e?!0:97>e?95===e:123>e?!0:e>=170&&_t.test(String.fromCharCode(e))},Zt={kind:"loop"},en={kind:"switch"}}); - var ua = navigator.userAgent, - match = ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*([.\d]+)(?:.*rv\:([.\d]+))?/i) || [], - name = match[1].toLowerCase(), - version = match[2]; - if (name === 'trident') { - version = match[3]; - name = 'msie'; - } else if (match = ua.match(/version\/([.\d]+)/i)) { - version = match[1]; - } - var browser = { name: name, version: parseFloat(version) }; - browser[name] = true; - var binaryOperators = { '+': '__add', '-': '__subtract', @@ -12755,15 +12687,7 @@ Base.exports.PaperScript = (function() { } } - function parse(code, options) { - return scope.acorn.parse(code, options); - } - - function compile(code, url, options) { - if (!code) - return ''; - options = options || {}; - url = url || ''; + function compile(code) { var insertions = []; @@ -12800,7 +12724,7 @@ Base.exports.PaperScript = (function() { if (!node) return; for (var key in node) { - if (key === 'range' || key === 'loc') + if (key === 'range') continue; var value = node[key]; if (Array.isArray(value)) { @@ -12810,8 +12734,8 @@ Base.exports.PaperScript = (function() { walkAST(value, node); } } - switch (node.type) { - case 'UnaryExpression': + switch (node && node.type) { + case 'UnaryExpression': if (node.operator in unaryOperators && node.argument.type !== 'Literal') { var arg = getCode(node.argument); @@ -12819,7 +12743,7 @@ Base.exports.PaperScript = (function() { + arg + ')'); } break; - case 'BinaryExpression': + case 'BinaryExpression': if (node.operator in binaryOperators && node.left.type !== 'Literal') { var left = getCode(node.left), @@ -12828,8 +12752,8 @@ Base.exports.PaperScript = (function() { + '", ' + right + ')'); } break; - case 'UpdateExpression': - case 'AssignmentExpression': + case 'UpdateExpression': + case 'AssignmentExpression': if (!(parent && ( parent.type === 'ForStatement' || parent.type === 'BinaryExpression' @@ -12842,7 +12766,7 @@ Base.exports.PaperScript = (function() { replaceCode(node, arg + ' = _$_(' + arg + ', "' + node.operator[0] + '", 1)'); } - } else { + } else { if (/^.=$/.test(node.operator) && node.left.type !== 'Literal') { var left = getCode(node.left), @@ -12855,45 +12779,11 @@ Base.exports.PaperScript = (function() { break; } } - var sourceMap = null, - version = browser.version, - lineBreaks = /\r\n|\n|\r/mg; - if (browser.chrome && version >= 30 - || browser.safari && version >= 7 - || browser.firefox && version >= 23) { - var offset = 0; - if (url === window.location.href) { - var html = document.getElementsByTagName('html')[0].innerHTML; - offset = html.substr(0, html.indexOf(code) + 1).match( - lineBreaks).length + 1; - } - var mappings = ['AAAA']; - mappings.length = code.match(lineBreaks).length + 1 + offset; - sourceMap = { - version: 3, - file: url, - names:[], - mappings: mappings.join(';AACA'), - sourceRoot: '', - sources: [url] - }; - var source = options.source || !url && code; - if (source) - sourceMap.sourcesContent = [source]; - } - walkAST(parse(code, { ranges: true })); - - if (sourceMap) { - code = new Array(offset + 1).join('\n') + code - + "\n//# sourceMappingURL=data:application/json;base64," - + (btoa(unescape(encodeURIComponent( - JSON.stringify(sourceMap))))) - + "\n//# sourceURL=" + (url || 'paperscript'); - } + walkAST(scope.acorn.parse(code, { ranges: true })); return code; } - function execute(code, scope, url, options) { + function execute(code, scope) { paper = scope; var view = scope.getView(), tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code) @@ -12904,7 +12794,7 @@ Base.exports.PaperScript = (function() { params = [], args = [], func; - code = compile(code, url, options); + code = compile(code); function expose(scope, hidden) { for (var key in scope) { if ((hidden || !/^_/.test(key)) && new RegExp( @@ -12914,7 +12804,7 @@ Base.exports.PaperScript = (function() { } } } - expose({ _$_: _$_, $_: $_, paper: scope, view: view, tool: tool }, true); + expose({ _$_: _$_, $_: $_, view: view, tool: tool }, true); expose(scope); handlers = Base.each(handlers, function(key) { if (new RegExp('\\s+' + key + '\\b').test(code)) { @@ -12924,10 +12814,11 @@ Base.exports.PaperScript = (function() { }, []).join(', '); if (handlers) code += '\nreturn { ' + handlers + ' };'; - if (browser.chrome || browser.firefox) { + var firefox = window.InstallTrigger; + if (firefox || window.chrome) { var script = document.createElement('script'), head = document.head; - if (browser.firefox) + if (firefox) code = '\n' + code; script.appendChild(document.createTextNode( 'paper._execute = function(' + params + ') {' + code + '\n}' @@ -12968,10 +12859,10 @@ Base.exports.PaperScript = (function() { src = script.src; if (src) { Http.request('get', src, function(code) { - execute(code, scope, src); + execute(code, scope); }); } else { - execute(script.innerHTML, scope, script.baseURI); + execute(script.innerHTML, scope); } script.setAttribute('data-paper-ignore', true); } @@ -12988,7 +12879,7 @@ Base.exports.PaperScript = (function() { compile: compile, execute: execute, load: load, - parse: parse + lineNumberBase: 0 }; }).call(this);