From 1866e4ff158121b22a4a11846a4551cff6c2fc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 24 Jun 2013 10:15:54 -0700 Subject: [PATCH] Remove need for all special arguments in minification, and restructure code to avoid warnings. --- build/minify.sh | 6 ++---- lib/straps.js | 2 +- src/basic/Matrix.js | 46 ++++++++++++++++++++-------------------- src/basic/Point.js | 20 ++++++++--------- src/basic/Rectangle.js | 2 +- src/core/Base.js | 2 +- src/core/PaperScript.js | 1 - src/item/Item.js | 7 +++--- src/item/Layer.js | 2 +- src/item/Raster.js | 14 ++++++------ src/item/Shape.js | 2 +- src/path/CompoundPath.js | 4 ++-- src/path/Curve.js | 14 +++++++----- src/path/Path.js | 46 +++++++++++++++++++++------------------- src/path/PathFitter.js | 1 - src/path/Segment.js | 2 ++ src/style/Color.js | 6 +++--- src/svg/SVGExport.js | 1 - src/svg/SVGImport.js | 4 ++-- src/text/PointText.js | 4 ++-- src/ui/Palette.js | 2 +- src/ui/View.js | 13 +++++++----- 22 files changed, 103 insertions(+), 98 deletions(-) diff --git a/build/minify.sh b/build/minify.sh index f4d6ec20..25369b6a 100755 --- a/build/minify.sh +++ b/build/minify.sh @@ -10,7 +10,5 @@ # # All rights reserved. -# We need to keep dead_code around for now, since the very odd JavaScriptCore -# scope bug fix (nop().nop()) requires it. -uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true,unused=false -m -b ascii_only=true,beautify=false --comments /^!/ -uglifyjs ../dist/paper-core.js -o ../dist/paper-core-min.js -c unsafe=true,unused=false -m --comments /^!/ +uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true -m -b ascii_only=true,beautify=false --comments /^!/ +uglifyjs ../dist/paper-core.js -o ../dist/paper-core-min.js -c unsafe=true -m --comments /^!/ diff --git a/lib/straps.js b/lib/straps.js index ed23a437..35913d83 100755 --- a/lib/straps.js +++ b/lib/straps.js @@ -228,7 +228,7 @@ var Base = new function() { return this; }, - extend: function(src/* , ... */) { + extend: function(/* src, ... */) { var base = this, ctor; // Look for an initialize function in all injection objects and use diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index 3eef50e7..67a6eaf6 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -158,19 +158,19 @@ var Matrix = Base.extend(/** @lends Matrix# */{ * @param {Point} [center] The center for the scaling transformation * @return {Matrix} This affine transform */ - scale: function(scale, center) { + scale: function(/* scale, center */) { // Do not modify scale, center, since that would arguments of which // we're reading from! - var _scale = Point.read(arguments), - _center = Point.read(arguments, 0, 0, true); // readNull - if (_center) - this.translate(_center); - this._a *= _scale.x; - this._c *= _scale.x; - this._b *= _scale.y; - this._d *= _scale.y; - if (_center) - this.translate(_center.negate()); + var scale = Point.read(arguments), + center = Point.read(arguments, 0, 0, true); // readNull + if (center) + this.translate(center); + this._a *= scale.x; + this._c *= scale.x; + this._b *= scale.y; + this._d *= scale.y; + if (center) + this.translate(center.negate()); return this; }, @@ -263,21 +263,21 @@ var Matrix = Base.extend(/** @lends Matrix# */{ * @param {Point} [center] The center for the shear transformation * @return {Matrix} This affine transform */ - shear: function(point, center) { + shear: function(/* point, center */) { // Do not modify point, center, since that would arguments of which // we're reading from! - var _point = Point.read(arguments), - _center = Point.read(arguments, 0, 0, true); // readNull - if (_center) - this.translate(_center); + var point = Point.read(arguments), + center = Point.read(arguments, 0, 0, true); // readNull + if (center) + this.translate(center); var a = this._a, c = this._c; - this._a += _point.y * this._b; - this._c += _point.y * this._d; - this._b += _point.x * a; - this._d += _point.x * c; - if (_center) - this.translate(_center.negate()); + this._a += point.y * this._b; + this._c += point.y * this._d; + this._b += point.x * a; + this._d += point.x * c; + if (center) + this.translate(center.negate()); return this; }, @@ -447,7 +447,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{ * * @param {Point} point The point to be transformed */ - inverseTransform: function(point) { + inverseTransform: function(/* point */) { return this._inverseTransform(Point.read(arguments)); }, diff --git a/src/basic/Point.js b/src/basic/Point.js index 259e4fc4..fdd82d84 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -792,12 +792,12 @@ var Point = Base.extend(/** @lends Point# */{ * var minPoint = Point.min(point1, point2); * console.log(minPoint); // {x: 10, y: 5} */ - min: function(point1, point2) { - var _point1 = Point.read(arguments); - _point2 = Point.read(arguments); + min: function(/* point1, point2 */) { + var point1 = Point.read(arguments); + point2 = Point.read(arguments); return new Point( - Math.min(_point1.x, _point2.x), - Math.min(_point1.y, _point2.y) + Math.min(point1.x, point2.x), + Math.min(point1.y, point2.y) ); }, @@ -816,12 +816,12 @@ var Point = Base.extend(/** @lends Point# */{ * var maxPoint = Point.max(point1, point2); * console.log(maxPoint); // {x: 200, y: 100} */ - max: function(point1, point2) { - var _point1 = Point.read(arguments); - _point2 = Point.read(arguments); + max: function(/* point1, point2 */) { + var point1 = Point.read(arguments); + point2 = Point.read(arguments); return new Point( - Math.max(_point1.x, _point2.x), - Math.max(_point1.y, _point2.y) + Math.max(point1.x, point2.x), + Math.max(point1.y, point2.y) ); }, diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 479a783f..c85cc732 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -872,7 +872,7 @@ var LinkedRectangle = Rectangle.extend({ 'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'], function(key) { var name = 'set' + key; - this[name] = function(value) { + this[name] = function(/* value */) { // Make sure the above setters of x, y, width, height do not // each notify the owner, as we're going to take care of this // afterwards here, only once per change. diff --git a/src/core/Base.js b/src/core/Base.js index 5967d1c7..e92ee854 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -83,7 +83,7 @@ Base.inject(/** @lends Base# */{ // Keep track of all named classes for serialization and exporting. exports: {}, - extend: function extend(src) { + extend: function extend() { // Override Base.extend() to register named classes in Base.exports, // for deserialization and injection into PaperScope. var res = extend.base.apply(this, arguments), diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 40feb5cd..f4fe7dd2 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -101,7 +101,6 @@ paper.PaperScope.prototype.PaperScript = new function() { // Converts an original offset to the one in the current state of the // modified code. function getOffset(offset) { - var start = offset; // Add all insertions before this location together to calculate // the current offset for (var i = 0, l = insertions.length; i < l; i++) { diff --git a/src/item/Item.js b/src/item/Item.js index 4b47e2e6..749d25b1 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -723,7 +723,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ : LinkedPoint.create(this, 'setPosition', pos.x, pos.y); }, - setPosition: function(point) { + setPosition: function(/* point */) { // Calculate the distance to the current position, by which to // translate the item. Pass true for dontLink, as we do not need a // LinkedPoint to simply calculate this distance. @@ -1315,7 +1315,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ * * @param {Point} point The point to check for. */ - contains: function(point) { + contains: function(/* point */) { // See CompoundPath#_contains() for the reason for !! return !!this._contains( this._matrix._inverseTransform(Point.read(arguments))); @@ -2124,7 +2124,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ * * @param {Point} delta the offset to translate the item by */ - translate: function(delta) { + translate: function(/* delta */) { var mx = new Matrix(); return this.transform(mx.translate.apply(mx, arguments)); }, @@ -2896,7 +2896,6 @@ var Item = Base.extend(Callback, /** @lends Item# */{ // opacity by themselves (they also don't call _setStyles) var blendMode = this._blendMode, opacity = this._opacity, - type = this._type, nativeBlend = BlendMode.nativeModes[blendMode], // Determine if we can draw directly, or if we need to draw into a // separate canvas and then composite onto the main canvas. diff --git a/src/item/Layer.js b/src/item/Layer.js index 32a26832..e3210581 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -58,7 +58,7 @@ var Layer = Group.extend(/** @lends Layer# */{ * position: view.center * }); */ - initialize: function Layer(items) { + initialize: function Layer(/* items */) { this._project = paper.project; // Push it onto project.layers and set index: this._index = this._project.layers.push(this) - 1; diff --git a/src/item/Raster.js b/src/item/Raster.js index 1c22b291..636bcc29 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -483,11 +483,11 @@ var Raster = Item.extend(/** @lends Raster# */{ * @param point the offset of the pixel as a point in pixel coordinates * @param color the color that the pixel will be set to */ - setPixel: function(point, color) { - var _point = Point.read(arguments), - _color = Color.read(arguments), - components = _color._convert('rgb'), - alpha = _color._alpha, + setPixel: function(/* point, color */) { + var point = Point.read(arguments), + color = Color.read(arguments), + components = color._convert('rgb'), + alpha = color._alpha, ctx = this.getContext(true), imageData = ctx.createImageData(1, 1), data = imageData.data; @@ -495,7 +495,7 @@ var Raster = Item.extend(/** @lends Raster# */{ data[1] = components[1] * 255; data[2] = components[2] * 255; data[3] = alpha != null ? alpha * 255 : 255; - ctx.putImageData(imageData, _point.x, _point.y); + ctx.putImageData(imageData, point.x, point.y); }, // DOCS: document Raster#createImageData @@ -538,7 +538,7 @@ var Raster = Item.extend(/** @lends Raster# */{ return matrix ? matrix._transformBounds(rect) : rect; }, - _hitTest: function(point, options) { + _hitTest: function(point) { if (this._contains(point)) { var that = this; return new HitResult('pixel', that, { diff --git a/src/item/Shape.js b/src/item/Shape.js index 143108e7..ff09284c 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -91,7 +91,7 @@ var Shape = Item.extend(/** @lends Shape# */{ } }, - _hitTest: function _hitTest(point, options) { + _hitTest: function _hitTest(point) { if (this.hasStroke()) { var type = this._type, strokeWidth = this.getStrokeWidth(); diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 5de5d8f2..a9c03a95 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -268,13 +268,13 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{ // Note: Documentation for these methods is found in PathItem, as they // are considered abstract methods of PathItem and need to be defined in // all implementing classes. - moveTo: function(point) { + moveTo: function(/* point */) { var path = new Path(); this.addChild(path); path.moveTo.apply(path, arguments); }, - moveBy: function(point) { + moveBy: function(/* point */) { this.moveTo(getCurrentPath(this).getLastSegment()._point.add( Point.read(arguments))); }, diff --git a/src/path/Curve.js b/src/path/Curve.js index c75af1bc..fe8627ec 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -840,7 +840,10 @@ statics: { * @return {CurveLocation} the curve location of the specified point. */ getLocationOf: function(point) { - var t = this.getParameterOf.apply(this, arguments); + // We need to use point to avoid minification issues and prevent method + // from turning into a bean (by removal of the point argument). + point = Point.read(arguments); + var t = this.getParameterOf(point); return t != null ? new CurveLocation(this, t) : null; }, @@ -850,8 +853,7 @@ statics: { count = 100, tolerance = Numerical.TOLERANCE, minDist = Infinity, - minT = 0, - max = 1 + tolerance; // Accomodate imprecision in comparisson + minT = 0; function refine(t) { if (t >= 0 && t <= 1) { @@ -880,7 +882,10 @@ statics: { }, getNearestPoint: function(point) { - return this.getNearestLocation.apply(this, arguments).getPoint(); + // We need to use point to avoid minification issues and prevent method + // from turning into a bean (by removal of the point argument). + point = Point.read(arguments); + return this.getNearestLocation(point).getPoint(); } /** @@ -1339,7 +1344,6 @@ new function() { // Scope for methods that require numerical integration cos = Math.cos(angle), // (rl1x, rl1y) = (0, 0) rl2x = lvx * cos - lvy * sin, - rl2y = lvy * cos + lvx * sin, vcr = []; for(var i = 0; i < 8; i += 2) { diff --git a/src/path/Path.js b/src/path/Path.js index 9abf148d..8dbda8aa 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -524,11 +524,11 @@ var Path = PathItem.extend(/** @lends Path# */{ : this._add([ Segment.read(arguments, 1) ], index)[0]; }, - addSegment: function(segment) { + addSegment: function(/* segment */) { return this._add([ Segment.read(arguments) ])[0]; }, - insertSegment: function(index, segment) { + insertSegment: function(index /*, segment */) { return this._add([ Segment.read(arguments, 1) ], index)[0]; }, @@ -1582,6 +1582,9 @@ var Path = PathItem.extend(/** @lends Path# */{ * } */ getNearestPoint: function(point) { + // We need to use point to avoid minification issues and prevent method + // from turning into a bean (by removal of the point argument). + point = Point.read(arguments); return this.getNearestLocation(point).getPoint(); }, @@ -2102,7 +2105,7 @@ var Path = PathItem.extend(/** @lends Path# */{ // Note: Documentation for these methods is found in PathItem, as they // are considered abstract methods of PathItem and need to be defined in // all implementing classes. - moveTo: function(point) { + moveTo: function(/* point */) { // moveTo should only be called at the beginning of paths. But it // can ce called again if there is nothing drawn yet, in which case // the first segment gets readjusted. @@ -2114,29 +2117,29 @@ var Path = PathItem.extend(/** @lends Path# */{ this._add([ new Segment(Point.read(arguments)) ]); }, - moveBy: function(point) { + moveBy: function(/* point */) { throw new Error('moveBy() is unsupported on Path items.'); }, - lineTo: function(point) { + lineTo: function(/* point */) { // Let's not be picky about calling moveTo() first: this._add([ new Segment(Point.read(arguments)) ]); }, - cubicCurveTo: function(handle1, handle2, to) { - var _handle1 = Point.read(arguments), - _handle2 = Point.read(arguments), - _to = Point.read(arguments); + cubicCurveTo: function(/* handle1, handle2, to */) { + var handle1 = Point.read(arguments), + handle2 = Point.read(arguments), + to = Point.read(arguments); // First modify the current segment: var current = getCurrentSegment(this); // Convert to relative values: - current.setHandleOut(_handle1.subtract(current._point)); + current.setHandleOut(handle1.subtract(current._point)); // And add the new segment, with handleIn set to c2 - this._add([ new Segment(_to, _handle2.subtract(to)) ]); + this._add([ new Segment(to, handle2.subtract(to)) ]); }, - quadraticCurveTo: function(handle, to) { - var _handle = Point.read(arguments), + quadraticCurveTo: function(/* handle, to */) { + var handle = Point.read(arguments), to = Point.read(arguments); // This is exact: // If we have the three quad points: A E D, @@ -2145,26 +2148,26 @@ var Path = PathItem.extend(/** @lends Path# */{ // C = E + 1/3 (D - E) var current = getCurrentSegment(this)._point; this.cubicCurveTo( - _handle.add(current.subtract(_handle).multiply(1 / 3)), - _handle.add(to.subtract(_handle).multiply(1 / 3)), + handle.add(current.subtract(handle).multiply(1 / 3)), + handle.add(to.subtract(handle).multiply(1 / 3)), to ); }, - curveTo: function(through, to, parameter) { - var _through = Point.read(arguments), - _to = Point.read(arguments), + curveTo: function(/* through, to, parameter */) { + var through = Point.read(arguments), + to = Point.read(arguments), t = Base.pick(Base.read(arguments), 0.5), t1 = 1 - t, current = getCurrentSegment(this)._point, // handle = (through - (1 - t)^2 * current - t^2 * to) / // (2 * (1 - t) * t) - handle = _through.subtract(current.multiply(t1 * t1)) - .subtract(_to.multiply(t * t)).divide(2 * t * t1); + handle = through.subtract(current.multiply(t1 * t1)) + .subtract(to.multiply(t * t)).divide(2 * t * t1); if (handle.isNaN()) throw new Error( 'Cannot put a curve through points with parameter = ' + t); - this.quadraticCurveTo(handle, _to); + this.quadraticCurveTo(handle, to); }, arcTo: function(to, clockwise /* | through, to */) { @@ -2209,7 +2212,6 @@ var Path = PathItem.extend(/** @lends Path# */{ + [from, through, to]); } var vector = from.subtract(center), - radius = vector.getLength(), extent = vector.getDirectedAngle(to.subtract(center)), centerSide = line.getSide(center); if (centerSide == 0) { diff --git a/src/path/PathFitter.js b/src/path/PathFitter.js index 2fab15fd..b179529e 100644 --- a/src/path/PathFitter.js +++ b/src/path/PathFitter.js @@ -58,7 +58,6 @@ var PathFitter = Base.extend({ // Parameterize points, and attempt to fit curve var uPrime = this.chordLengthParameterize(first, last), maxError = Math.max(this.error, this.error * this.error), - error, split; // Try 4 iterations for (var i = 0; i <= 4; i++) { diff --git a/src/path/Segment.js b/src/path/Segment.js index f26a7539..5fa91938 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -222,6 +222,8 @@ var Segment = Base.extend(/** @lends Segment# */{ }, setHandleOut: function(point) { + // We need to use point to avoid minification issues and prevent method + // from turning into a bean (by removal of the point argument). point = Point.read(arguments); // See #setPoint: this._handleOut.set(point.x, point.y); diff --git a/src/style/Color.js b/src/style/Color.js index 4d19b873..66eda1aa 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -195,12 +195,12 @@ var Color = Base.extend(new function() { return [0, 0, g]; }, - 'gradient-rgb': function(gradient) { + 'gradient-rgb': function(/* gradient */) { // TODO: Implement return []; }, - 'rgb-gradient': function(r, g, b) { + 'rgb-gradient': function(/* r, g, b */) { // TODO: Implement return []; } @@ -243,7 +243,7 @@ var Color = Base.extend(new function() { : ((value % 360) + 360) % 360; } : type === 'gradient' - ? function(value) { + ? function(/* value */) { // ..., readNull, clone); return Point.read(arguments, 0, 0, name === 'highlight', true); diff --git a/src/svg/SVGExport.js b/src/svg/SVGExport.js index 96fb944f..c653d032 100644 --- a/src/svg/SVGExport.js +++ b/src/svg/SVGExport.js @@ -474,7 +474,6 @@ new function() { // #exportSVG() on an item rather than a whole project) // jsdom in Node.js uses uppercase values for nodeName... var svg = node.nodeName.toLowerCase() === 'svg' && node, - firstChild = svg ? svg.firstChild : node, defs = null; for (var i in definitions.svgs) { // This code is inside the loop so we only create a container if we diff --git a/src/svg/SVGImport.js b/src/svg/SVGImport.js index 41c56f4e..d16db33b 100644 --- a/src/svg/SVGImport.js +++ b/src/svg/SVGImport.js @@ -211,7 +211,7 @@ new function() { defs: importGroup, // http://www.w3.org/TR/SVG/struct.html#UseElement - use: function(node, type) { + use: function(node) { // Note the namespaced xlink:href attribute is just called href // as a property on node. // TODO: Support overflow and width, height, in combination with @@ -336,7 +336,7 @@ new function() { // since transform needs to be applied after fill color, as transformations // can affect gradient fills. var attributes = Base.merge(Base.each(SVGStyles, function(entry) { - this[entry.attribute] = function(item, value, name, node) { + this[entry.attribute] = function(item, value) { item[entry.set]( convertValue(value, entry.type, entry.fromSVG)); }; diff --git a/src/text/PointText.js b/src/text/PointText.js index 592d5dfd..c957d97c 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -65,8 +65,8 @@ var PointText = TextItem.extend(/** @lends PointText# */{ }, setPoint: function(point) { - this.translate(Point.read(arguments).subtract( - this._matrix.getTranslation())); + point = Point.read(arguments); + this.translate(point.subtract(this._matrix.getTranslation())); }, _draw: function(ctx) { diff --git a/src/ui/Palette.js b/src/ui/Palette.js index 5bf06f1e..c3cf8a5f 100644 --- a/src/ui/Palette.js +++ b/src/ui/Palette.js @@ -14,7 +14,7 @@ * @name Palette * @class */ -var Palette = Base.extend(Callback, /** @lends Palette# */{ +/* var Palette = */ Base.extend(Callback, /** @lends Palette# */{ _class: 'Palette', _events: [ 'onChange' ], diff --git a/src/ui/View.js b/src/ui/View.js index 05f52586..551e8bf3 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -46,7 +46,7 @@ var View = Base.extend(Callback, /** @lends View# */{ size = DomElement.getViewportBounds(element) .getSize().subtract(offset); this._windowHandlers = { - resize: function(event) { + resize: function() { // Only update element offset if it's not invisible, as // otherwise the offset would be wrong. if (!DomElement.isInvisible(element)) @@ -332,7 +332,10 @@ var View = Base.extend(Callback, /** @lends View# */{ }, setCenter: function(center) { - this.scrollBy(Point.read(arguments).subtract(this.getCenter())); + // We need to use center to avoid minification issues and prevent method + // from turning into a bean (by removal of the center argument). + center = Point.read(arguments); + this.scrollBy(center.subtract(this.getCenter())); }, /** @@ -367,7 +370,7 @@ var View = Base.extend(Callback, /** @lends View# */{ * * @param {Point} point */ - scrollBy: function(point) { + scrollBy: function(/* point */) { this._transform(new Matrix().translate(Point.read(arguments).negate())); }, @@ -389,11 +392,11 @@ var View = Base.extend(Callback, /** @lends View# */{ // TODO: getMousePoint // TODO: projectToView(rect) - projectToView: function(point) { + projectToView: function(/* point */) { return this._matrix._transformPoint(Point.read(arguments)); }, - viewToProject: function(point) { + viewToProject: function(/* point */) { return this._getInverse()._transformPoint(Point.read(arguments)); },