From 3f5d0a6925972fe4dc766a37c36ed5eb76b6ccaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 1 Mar 2013 17:13:22 -0800 Subject: [PATCH] Merge constructor._name with _type and use CamelCase for Item types. --- node.js/index.js | 6 ++---- src/basic/Matrix.js | 2 -- src/color/Gradient.js | 2 +- src/color/GradientColor.js | 2 +- src/core/Base.js | 2 +- src/core/initialize.js | 17 ++++------------- src/item/Group.js | 2 +- src/item/Item.js | 2 +- src/item/Layer.js | 2 +- src/item/PlacedSymbol.js | 2 +- src/item/Raster.js | 2 +- src/paper.js | 3 --- src/path/CompoundPath.js | 4 ++-- src/path/Path.js | 2 +- src/path/Segment.js | 2 +- src/project/Symbol.js | 2 +- src/svg/SvgExport.js | 14 +++++++------- src/svg/SvgImport.js | 2 +- src/text/PointText.js | 3 ++- 19 files changed, 29 insertions(+), 44 deletions(-) diff --git a/node.js/index.js b/node.js/index.js index 9cb6035d..8262a5f6 100644 --- a/node.js/index.js +++ b/node.js/index.js @@ -50,12 +50,10 @@ var context = vm.createContext({ // Load Paper.js library files: context.include('paper.js'); +// Export all classes through PaperScope: context.Base.each(context, function(val, key) { - if (val && val.prototype instanceof context.Base) { - val._name = key; - // Export all classes through PaperScope: + if (val && val.prototype instanceof context.Base) context.PaperScope.prototype[key] = val; - } }); context.PaperScope.prototype['Canvas'] = context.Canvas; diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index e819a53c..8d8d6e3f 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -38,8 +38,6 @@ * matrix multiplication). */ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{ - _type: 'matrix', - /** * Creates a 2D affine transform. * diff --git a/src/color/Gradient.js b/src/color/Gradient.js index 304cdfc4..f8756915 100644 --- a/src/color/Gradient.js +++ b/src/color/Gradient.js @@ -16,7 +16,7 @@ * @class The Gradient object. */ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{ - _type: 'gradient', + _type: 'Gradient', // TODO: Should type here be called 'radial' and have it receive a // boolean value? diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index 000a7956..0fc07acf 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -16,7 +16,7 @@ * @class The GradientColor object. */ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor# */{ - _type: 'gradientcolor', + _type: 'GradientColor', /** * Creates a gradient color object. diff --git a/src/core/Base.js b/src/core/Base.js index c4bd7c18..498e29df 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -36,7 +36,7 @@ this.Base = Base.inject(/** @lends Base# */{ */ toString: function() { return this._id != null - ? (this.constructor._name || 'Object') + (this._name + ? (this._type || 'Object') + (this._name ? " '" + this._name + "'" : ' @' + this._id) : '{ ' + Base.each(this, function(value, key) { diff --git a/src/core/initialize.js b/src/core/initialize.js index a3bc932a..a3984634 100644 --- a/src/core/initialize.js +++ b/src/core/initialize.js @@ -10,22 +10,13 @@ * All rights reserved. */ -// Iterate over all produced Base classes and set the _name property of their -// constructors to the key under which they are stored. This is a simple hack -// that allow us to use their names. -// Setting Function#name is not possible, as that is read-only. +/*#*/ if (options.version == 'dev') { +// When in dev mode, also export all classes through PaperScope, to mimick +// scoping behavior of the built library. Base.each(this, function(val, key) { - if (val && val.prototype instanceof Base) { - val._name = key; -/*#*/ if (options.version == 'dev') { - // If we're in dev mode, also export all classes through PaperScope, to - // mimick scoping behavior of the built library. + if (val && val.prototype instanceof Base) PaperScope.prototype[key] = val; -/*#*/ } // options.version == 'dev' - } }); - -/*#*/ if (options.version == 'dev') { // See paper.js for the non-dev version of this code. We cannot handle dev there // due to the seperate loading of all source files, which are only availabe // after the execution of paper.js diff --git a/src/item/Group.js b/src/item/Group.js index 489d22e4..e4391386 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -20,7 +20,7 @@ * @extends Item */ var Group = this.Group = Item.extend(/** @lends Group# */{ - _type: 'group', + _type: 'Group', _serializeFields: { children: [] }, diff --git a/src/item/Item.js b/src/item/Item.js index bc3f92ac..317da712 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -2563,7 +2563,7 @@ var Item = this.Item = Base.extend(Callback, { // Exclude Raster items since they never draw a stroke and handle // opacity by themselves (they also don't call _setStyles) if (item._blendMode !== 'normal' || item._opacity < 1 - && item._type !== 'raster' && (item._type !== 'path' + && item._type !== 'Raster' && (item._type !== 'Path' || item.getFillColor() && item.getStrokeColor())) { var bounds = item.getStrokeBounds(); if (!bounds.width || !bounds.height) diff --git a/src/item/Layer.js b/src/item/Layer.js index 0ddd62cf..7199d935 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -23,7 +23,7 @@ * @extends Group */ var Layer = this.Layer = Group.extend(/** @lends Layer# */{ - _type: 'layer', + _type: 'Layer', // DOCS: improve constructor code example. /** * Creates a new Layer item and places it at the end of the diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index d65373ab..899aa183 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -19,7 +19,7 @@ * @extends PlacedItem */ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{ - _type: 'placedsymbol', + _type: 'PlacedSymbol', _boundsSelected: true, _serializeFields: { symbol: null diff --git a/src/item/Raster.js b/src/item/Raster.js index fd182e4b..5cfd5fb2 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -18,7 +18,7 @@ * @extends PlacedItem */ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ - _type: 'raster', + _type: 'Raster', _boundsSelected: true, _serializeFields: { source: null diff --git a/src/paper.js b/src/paper.js index 26ba81b5..871887d3 100644 --- a/src/paper.js +++ b/src/paper.js @@ -127,10 +127,7 @@ var paper = new function() { /*#*/ } // options.svg /*#*/ include('core/PaperScript.js'); - -/*#*/ if (options.browser) { /*#*/ include('core/initialize.js'); -/*#*/ } // options.browser /*#*/ if (options.version != 'dev') { // Finally inject the classes set on 'this' into the PaperScope class and create diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index a1cbb5a8..42799343 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -21,7 +21,7 @@ * @extends PathItem */ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# */{ - _type: 'compoundpath', + _type: 'CompoundPath', _serializeFields: { pathData: '' }, @@ -52,7 +52,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# insertChild: function(index, item, _cloning) { // Only allow the insertion of paths - if (item._type !== 'path') + if (item._type !== 'Path') return null; item = this.base(index, item); // All children except for the bottom one (first one in list) are set diff --git a/src/path/Path.js b/src/path/Path.js index d2e5f0b4..2fbdff36 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -19,7 +19,7 @@ */ // DOCS: Explain that path matrix is always applied with each transformation. var Path = this.Path = PathItem.extend(/** @lends Path# */{ - _type: 'path', + _type: 'Path', _serializeFields: { pathData: '' }, diff --git a/src/path/Segment.js b/src/path/Segment.js index 2209aad3..3e45d7a6 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -23,7 +23,7 @@ * objects that are connected by this segment. */ var Segment = this.Segment = Base.extend(/** @lends Segment# */{ - _type: 'segment', + _type: 'Segment', /** * Creates a new Segment object. diff --git a/src/project/Symbol.js b/src/project/Symbol.js index a7238e3d..c6c5ddc8 100644 --- a/src/project/Symbol.js +++ b/src/project/Symbol.js @@ -20,7 +20,7 @@ * to be updated with every transformation. */ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{ - _type: 'symbol', + _type: 'Symbol', /** * Creates a Symbol item. diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 11fe3701..725f2578 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -386,13 +386,13 @@ new function() { } var exporters = { - group: exportGroup, - layer: exportGroup, - raster: exportRaster, - pointtext: exportText, - placedsymbol: exportPlacedSymbol, - path: exportPath, - compoundpath: exportCompoundPath + Group: exportGroup, + Layer: exportGroup, + Raster: exportRaster, + PointText: exportText, + PlacedSymbol: exportPlacedSymbol, + Path: exportPath, + CompoundPath: exportCompoundPath }; function applyStyle(item, node) { diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 80909dfc..e5742821 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -474,7 +474,7 @@ new function() { importer = importers[type], item = importer && importer(node, type); // See importGroup() for an explanation of this filtering: - if (item && item._type !== 'group') + if (item && item._type !== 'Group') item = applyAttributes(item, node); // Clear definitions at the end of import? if (clearDefs) diff --git a/src/text/PointText.js b/src/text/PointText.js index 42d27f9f..e81bf1a3 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -20,7 +20,8 @@ * @extends TextItem */ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{ - _type: 'pointtext', + _type: 'PointText', + /** * Creates a point text item *