mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Merge constructor._name with _type and use CamelCase for Item types.
This commit is contained in:
parent
293294a55a
commit
3f5d0a6925
19 changed files with 29 additions and 44 deletions
|
@ -50,12 +50,10 @@ var context = vm.createContext({
|
||||||
// Load Paper.js library files:
|
// Load Paper.js library files:
|
||||||
context.include('paper.js');
|
context.include('paper.js');
|
||||||
|
|
||||||
|
// Export all classes through PaperScope:
|
||||||
context.Base.each(context, function(val, key) {
|
context.Base.each(context, function(val, key) {
|
||||||
if (val && val.prototype instanceof context.Base) {
|
if (val && val.prototype instanceof context.Base)
|
||||||
val._name = key;
|
|
||||||
// Export all classes through PaperScope:
|
|
||||||
context.PaperScope.prototype[key] = val;
|
context.PaperScope.prototype[key] = val;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
context.PaperScope.prototype['Canvas'] = context.Canvas;
|
context.PaperScope.prototype['Canvas'] = context.Canvas;
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@
|
||||||
* matrix multiplication).
|
* matrix multiplication).
|
||||||
*/
|
*/
|
||||||
var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
||||||
_type: 'matrix',
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a 2D affine transform.
|
* Creates a 2D affine transform.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* @class The Gradient object.
|
* @class The Gradient object.
|
||||||
*/
|
*/
|
||||||
var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
|
var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
|
||||||
_type: 'gradient',
|
_type: 'Gradient',
|
||||||
|
|
||||||
// TODO: Should type here be called 'radial' and have it receive a
|
// TODO: Should type here be called 'radial' and have it receive a
|
||||||
// boolean value?
|
// boolean value?
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* @class The GradientColor object.
|
* @class The GradientColor object.
|
||||||
*/
|
*/
|
||||||
var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor# */{
|
var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor# */{
|
||||||
_type: 'gradientcolor',
|
_type: 'GradientColor',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a gradient color object.
|
* Creates a gradient color object.
|
||||||
|
|
|
@ -36,7 +36,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
*/
|
*/
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return this._id != null
|
return this._id != null
|
||||||
? (this.constructor._name || 'Object') + (this._name
|
? (this._type || 'Object') + (this._name
|
||||||
? " '" + this._name + "'"
|
? " '" + this._name + "'"
|
||||||
: ' @' + this._id)
|
: ' @' + this._id)
|
||||||
: '{ ' + Base.each(this, function(value, key) {
|
: '{ ' + Base.each(this, function(value, key) {
|
||||||
|
|
|
@ -10,22 +10,13 @@
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Iterate over all produced Base classes and set the _name property of their
|
/*#*/ if (options.version == 'dev') {
|
||||||
// constructors to the key under which they are stored. This is a simple hack
|
// When in dev mode, also export all classes through PaperScope, to mimick
|
||||||
// that allow us to use their names.
|
// scoping behavior of the built library.
|
||||||
// Setting Function#name is not possible, as that is read-only.
|
|
||||||
Base.each(this, function(val, key) {
|
Base.each(this, function(val, key) {
|
||||||
if (val && val.prototype instanceof Base) {
|
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.
|
|
||||||
PaperScope.prototype[key] = val;
|
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
|
// 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
|
// due to the seperate loading of all source files, which are only availabe
|
||||||
// after the execution of paper.js
|
// after the execution of paper.js
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* @extends Item
|
* @extends Item
|
||||||
*/
|
*/
|
||||||
var Group = this.Group = Item.extend(/** @lends Group# */{
|
var Group = this.Group = Item.extend(/** @lends Group# */{
|
||||||
_type: 'group',
|
_type: 'Group',
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
children: []
|
children: []
|
||||||
},
|
},
|
||||||
|
|
|
@ -2563,7 +2563,7 @@ var Item = this.Item = Base.extend(Callback, {
|
||||||
// Exclude Raster items since they never draw a stroke and handle
|
// Exclude Raster items since they never draw a stroke and handle
|
||||||
// opacity by themselves (they also don't call _setStyles)
|
// opacity by themselves (they also don't call _setStyles)
|
||||||
if (item._blendMode !== 'normal' || item._opacity < 1
|
if (item._blendMode !== 'normal' || item._opacity < 1
|
||||||
&& item._type !== 'raster' && (item._type !== 'path'
|
&& item._type !== 'Raster' && (item._type !== 'Path'
|
||||||
|| item.getFillColor() && item.getStrokeColor())) {
|
|| item.getFillColor() && item.getStrokeColor())) {
|
||||||
var bounds = item.getStrokeBounds();
|
var bounds = item.getStrokeBounds();
|
||||||
if (!bounds.width || !bounds.height)
|
if (!bounds.width || !bounds.height)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @extends Group
|
* @extends Group
|
||||||
*/
|
*/
|
||||||
var Layer = this.Layer = Group.extend(/** @lends Layer# */{
|
var Layer = this.Layer = Group.extend(/** @lends Layer# */{
|
||||||
_type: 'layer',
|
_type: 'Layer',
|
||||||
// DOCS: improve constructor code example.
|
// DOCS: improve constructor code example.
|
||||||
/**
|
/**
|
||||||
* Creates a new Layer item and places it at the end of the
|
* Creates a new Layer item and places it at the end of the
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* @extends PlacedItem
|
* @extends PlacedItem
|
||||||
*/
|
*/
|
||||||
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
|
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
|
||||||
_type: 'placedsymbol',
|
_type: 'PlacedSymbol',
|
||||||
_boundsSelected: true,
|
_boundsSelected: true,
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
symbol: null
|
symbol: null
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
* @extends PlacedItem
|
* @extends PlacedItem
|
||||||
*/
|
*/
|
||||||
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
_type: 'raster',
|
_type: 'Raster',
|
||||||
_boundsSelected: true,
|
_boundsSelected: true,
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
source: null
|
source: null
|
||||||
|
|
|
@ -127,10 +127,7 @@ var paper = new function() {
|
||||||
/*#*/ } // options.svg
|
/*#*/ } // options.svg
|
||||||
|
|
||||||
/*#*/ include('core/PaperScript.js');
|
/*#*/ include('core/PaperScript.js');
|
||||||
|
|
||||||
/*#*/ if (options.browser) {
|
|
||||||
/*#*/ include('core/initialize.js');
|
/*#*/ include('core/initialize.js');
|
||||||
/*#*/ } // options.browser
|
|
||||||
|
|
||||||
/*#*/ if (options.version != 'dev') {
|
/*#*/ if (options.version != 'dev') {
|
||||||
// Finally inject the classes set on 'this' into the PaperScope class and create
|
// Finally inject the classes set on 'this' into the PaperScope class and create
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* @extends PathItem
|
* @extends PathItem
|
||||||
*/
|
*/
|
||||||
var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||||
_type: 'compoundpath',
|
_type: 'CompoundPath',
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
pathData: ''
|
pathData: ''
|
||||||
},
|
},
|
||||||
|
@ -52,7 +52,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
|
||||||
|
|
||||||
insertChild: function(index, item, _cloning) {
|
insertChild: function(index, item, _cloning) {
|
||||||
// Only allow the insertion of paths
|
// Only allow the insertion of paths
|
||||||
if (item._type !== 'path')
|
if (item._type !== 'Path')
|
||||||
return null;
|
return null;
|
||||||
item = this.base(index, item);
|
item = this.base(index, item);
|
||||||
// All children except for the bottom one (first one in list) are set
|
// All children except for the bottom one (first one in list) are set
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
// DOCS: Explain that path matrix is always applied with each transformation.
|
// DOCS: Explain that path matrix is always applied with each transformation.
|
||||||
var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
_type: 'path',
|
_type: 'Path',
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
pathData: ''
|
pathData: ''
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* objects that are connected by this segment.
|
* objects that are connected by this segment.
|
||||||
*/
|
*/
|
||||||
var Segment = this.Segment = Base.extend(/** @lends Segment# */{
|
var Segment = this.Segment = Base.extend(/** @lends Segment# */{
|
||||||
_type: 'segment',
|
_type: 'Segment',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Segment object.
|
* Creates a new Segment object.
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* to be updated with every transformation.
|
* to be updated with every transformation.
|
||||||
*/
|
*/
|
||||||
var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
|
var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
|
||||||
_type: 'symbol',
|
_type: 'Symbol',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Symbol item.
|
* Creates a Symbol item.
|
||||||
|
|
|
@ -386,13 +386,13 @@ new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var exporters = {
|
var exporters = {
|
||||||
group: exportGroup,
|
Group: exportGroup,
|
||||||
layer: exportGroup,
|
Layer: exportGroup,
|
||||||
raster: exportRaster,
|
Raster: exportRaster,
|
||||||
pointtext: exportText,
|
PointText: exportText,
|
||||||
placedsymbol: exportPlacedSymbol,
|
PlacedSymbol: exportPlacedSymbol,
|
||||||
path: exportPath,
|
Path: exportPath,
|
||||||
compoundpath: exportCompoundPath
|
CompoundPath: exportCompoundPath
|
||||||
};
|
};
|
||||||
|
|
||||||
function applyStyle(item, node) {
|
function applyStyle(item, node) {
|
||||||
|
|
|
@ -474,7 +474,7 @@ new function() {
|
||||||
importer = importers[type],
|
importer = importers[type],
|
||||||
item = importer && importer(node, type);
|
item = importer && importer(node, type);
|
||||||
// See importGroup() for an explanation of this filtering:
|
// See importGroup() for an explanation of this filtering:
|
||||||
if (item && item._type !== 'group')
|
if (item && item._type !== 'Group')
|
||||||
item = applyAttributes(item, node);
|
item = applyAttributes(item, node);
|
||||||
// Clear definitions at the end of import?
|
// Clear definitions at the end of import?
|
||||||
if (clearDefs)
|
if (clearDefs)
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
* @extends TextItem
|
* @extends TextItem
|
||||||
*/
|
*/
|
||||||
var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
||||||
_type: 'pointtext',
|
_type: 'PointText',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a point text item
|
* Creates a point text item
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue