mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-05-22 18:51:30 -04:00
Bring back _class names, since code minification breaks reliance on constructor.name.
Closes #248.
This commit is contained in:
parent
dff39dff78
commit
a4535edbb9
39 changed files with 65 additions and 28 deletions
build
lib
src
basic
core
item
path
project
style
text
tool
ui
|
@ -12,7 +12,4 @@
|
|||
|
||||
# We need to keep dead_code around for now, since the very odd JavaScriptCore
|
||||
# scope bug fix (nop().nop()) requires it.
|
||||
# TODO: uglifyjs gets confused about Base and Color constructor naming, so we
|
||||
# have to tell it to not rename these. It's also not renaming all the local
|
||||
# references to classes which could yield a lot of size improvements.
|
||||
uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true,unused=false,dead_code=false,hoist_funs=false -m -r "Base,Color,_$_,$_" -b ascii_only=true,beautify=false --comments /^!/
|
||||
uglifyjs ../dist/paper.js -o ../dist/paper-min.js -c unsafe=true,unused=false,dead_code=false,hoist_funs=false -m -r "_$_,$_" -b ascii_only=true,beautify=false --comments /^!/
|
||||
|
|
|
@ -83,19 +83,6 @@ var Base = new function() {
|
|||
return _define(obj, name, desc);
|
||||
};
|
||||
|
||||
// Fix Function#name on browsers that do not support it (IE):
|
||||
if (!(function f() {}).name) {
|
||||
define(Function.prototype, 'name', {
|
||||
get: function() {
|
||||
var name = this.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
|
||||
// For better performance only parse once, and then cache the
|
||||
// result through a new accessor for repeated access.
|
||||
define(this, 'name', { value: name });
|
||||
return name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function that injects functions from src into dest, overriding
|
||||
* (and inherinting from) base.
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* @class The Line object represents..
|
||||
*/
|
||||
var Line = Base.extend(/** @lends Line# */{
|
||||
_class: 'Line',
|
||||
|
||||
// DOCS: document Line class and constructor
|
||||
/**
|
||||
* Creates a Line object.
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
* matrix multiplication).
|
||||
*/
|
||||
var Matrix = Base.extend(/** @lends Matrix# */{
|
||||
_class: 'Matrix',
|
||||
|
||||
/**
|
||||
* Creates a 2D affine transform.
|
||||
*
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* console.log(point.y); // 5
|
||||
*/
|
||||
var Point = Base.extend(/** @lends Point# */{
|
||||
_class: 'Point',
|
||||
// Tell Base.read that the Point constructor supports reading with index
|
||||
_readIndex: true,
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* rectangular path, it is not an item.
|
||||
*/
|
||||
var Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||
_class: 'Rectangle',
|
||||
// Tell Base.read that the Rectangle constructor supports reading with index
|
||||
_readIndex: true,
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* console.log(size.height); // 5
|
||||
*/
|
||||
var Size = Base.extend(/** @lends Size# */{
|
||||
_class: 'Size',
|
||||
// Tell Base.read that the Point constructor supports reading with index
|
||||
_readIndex: true,
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ Base.inject(/** @lends Base# */{
|
|||
*/
|
||||
toString: function() {
|
||||
return this._id != null
|
||||
? (this.constructor.name || 'Object') + (this._name
|
||||
? (this._class || 'Object') + (this._name
|
||||
? " '" + this._name + "'"
|
||||
: ' @' + this._id)
|
||||
: '{ ' + Base.each(this, function(value, key) {
|
||||
|
@ -87,7 +87,7 @@ Base.inject(/** @lends Base# */{
|
|||
// Override Base.extend() to register named classes in Base.exports,
|
||||
// for deserialization and injection into PaperScope.
|
||||
var res = extend.base.apply(this, arguments),
|
||||
name = res.name;
|
||||
name = res.prototype._class;
|
||||
if (name)
|
||||
Base.exports[name] = res;
|
||||
return res;
|
||||
|
@ -300,7 +300,7 @@ Base.inject(/** @lends Base# */{
|
|||
if (!ref) {
|
||||
this.length++;
|
||||
var res = create.call(item),
|
||||
name = item.constructor.name;
|
||||
name = item._class;
|
||||
// Also automatically insert class for dictionary
|
||||
// entries.
|
||||
if (name && res[0] !== name)
|
||||
|
@ -317,7 +317,7 @@ Base.inject(/** @lends Base# */{
|
|||
// If we don't serialize to compact form (meaning no type
|
||||
// identifier), see if _serialize didn't already add the class,
|
||||
// e.g. for classes that do not support compact form.
|
||||
var name = obj.constructor.name;
|
||||
var name = obj._class;
|
||||
if (name && !compact && !res._compact && res[0] !== name)
|
||||
res.unshift(name);
|
||||
} else if (Array.isArray(obj)) {
|
||||
|
@ -326,7 +326,7 @@ Base.inject(/** @lends Base# */{
|
|||
res[i] = Base.serialize(obj[i], options, compact,
|
||||
dictionary);
|
||||
// Mark array as compact, so obj._serialize handling above
|
||||
// doesn't add the constructor name again.
|
||||
// doesn't add the class name again.
|
||||
if (compact)
|
||||
res._compact = true;
|
||||
} else if (Base.isPlainObject(obj)) {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
* {@code PaperScope}.
|
||||
*/
|
||||
var PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||
_class: 'PaperScope',
|
||||
|
||||
/**
|
||||
* Creates a PaperScope object.
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var Group = Item.extend(/** @lends Group# */{
|
||||
_class: 'Group',
|
||||
_serializeFields: {
|
||||
children: []
|
||||
},
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* {@link Project#hitTest(point)}.
|
||||
*/
|
||||
var HitResult = Base.extend(/** @lends HitResult# */{
|
||||
_class: 'HitResult',
|
||||
|
||||
initialize: function HitResult(type, item, values) {
|
||||
this.type = type;
|
||||
this.item = item;
|
||||
|
|
|
@ -33,14 +33,16 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
src._serializeFields = Base.merge(
|
||||
this.prototype._serializeFields, src._serializeFields);
|
||||
var res = extend.base.apply(this, arguments),
|
||||
name = res.name;
|
||||
// Derive the _type string from constructor name
|
||||
proto = res.prototype,
|
||||
name = proto._class;
|
||||
// Derive the _type string from class name
|
||||
if (name)
|
||||
res.prototype._type = Base.hyphenate(name);
|
||||
proto._type = Base.hyphenate(name);
|
||||
return res;
|
||||
}
|
||||
},
|
||||
|
||||
_class: 'Item',
|
||||
// All items apply their matrix by default.
|
||||
// Exceptions are Raster, PlacedSymbol, Clip and Shape.
|
||||
_transformContent: true,
|
||||
|
@ -170,8 +172,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
if (!(this instanceof Group))
|
||||
serialize(this._style._defaults);
|
||||
// There is no compact form for Item serialization, we always keep the
|
||||
// type.
|
||||
return [ this.constructor.name, props ];
|
||||
// class.
|
||||
return [ this._class, props ];
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
* @extends Group
|
||||
*/
|
||||
var Layer = Group.extend(/** @lends Layer# */{
|
||||
_class: 'Layer',
|
||||
|
||||
// DOCS: improve constructor code example.
|
||||
/**
|
||||
* Creates a new Layer item and places it at the end of the
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
|
||||
_class: 'PlacedSymbol',
|
||||
_transformContent: false,
|
||||
// PlacedSymbol uses strokeBounds for bounds
|
||||
_boundsGetter: { getBounds: 'getStrokeBounds' },
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var Raster = Item.extend(/** @lends Raster# */{
|
||||
_class: 'Raster',
|
||||
_transformContent: false,
|
||||
// Raster doesn't make the distinction between the different bounds,
|
||||
// so use the same name for all of them
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var Shape = Item.extend(/** @lends Shape# */{
|
||||
_class: 'Shape',
|
||||
_transformContent: false,
|
||||
|
||||
initialize: function Shape(type, point, size) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* @extends PathItem
|
||||
*/
|
||||
var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||
_class: 'CompoundPath',
|
||||
_serializeFields: {
|
||||
children: []
|
||||
},
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
* tangents at given offsets.
|
||||
*/
|
||||
var Curve = Base.extend(/** @lends Curve# */{
|
||||
_class: 'Curve',
|
||||
/**
|
||||
* Creates a new curve object.
|
||||
*
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* etc.
|
||||
*/
|
||||
var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||
_class: 'CurveLocation',
|
||||
// DOCS: CurveLocation class description: add these back when the mentioned
|
||||
// functioned have been added: {@link Path#split(location)}
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
// DOCS: Explain that path matrix is always applied with each transformation.
|
||||
var Path = PathItem.extend(/** @lends Path# */{
|
||||
_class: 'Path',
|
||||
_serializeFields: {
|
||||
segments: [],
|
||||
closed: false
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var PathItem = Item.extend(/** @lends PathItem# */{
|
||||
_class: 'PathItem',
|
||||
|
||||
initialize: function PathItem() {
|
||||
Item.apply(this, arguments);
|
||||
},
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
* objects that are connected by this segment.
|
||||
*/
|
||||
var Segment = Base.extend(/** @lends Segment# */{
|
||||
_class: 'Segment',
|
||||
|
||||
/**
|
||||
* Creates a new Segment object.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
* {@link PaperScope#projects} variable.
|
||||
*/
|
||||
var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||
_class: 'Project',
|
||||
_list: 'projects',
|
||||
_reference: 'project',
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
* to be updated with every transformation.
|
||||
*/
|
||||
var Symbol = Base.extend(/** @lends Symbol# */{
|
||||
_class: 'Symbol',
|
||||
|
||||
/**
|
||||
* Creates a Symbol item.
|
||||
*
|
||||
|
@ -70,7 +72,7 @@ var Symbol = Base.extend(/** @lends Symbol# */{
|
|||
|
||||
_serialize: function(options, dictionary) {
|
||||
return dictionary.add(this, function() {
|
||||
return Base.serialize([this.constructor.name, this._definition],
|
||||
return Base.serialize([this._class, this._definition],
|
||||
options, false, dictionary);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -275,6 +275,7 @@ var Color = Base.extend(new function() {
|
|||
};
|
||||
}, this);
|
||||
}, /** @lends Color# */{
|
||||
_class: 'Color',
|
||||
// Tell Base.read that the Point constructor supports reading with index
|
||||
_readIndex: true,
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
* };
|
||||
*/
|
||||
var Gradient = Base.extend(/** @lends Gradient# */{
|
||||
_class: 'Gradient',
|
||||
|
||||
// DOCS: Document #initialize()
|
||||
initialize: function Gradient(stops, radial) {
|
||||
// Define this Gradient's unique id.
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* @class The GradientStop object.
|
||||
*/
|
||||
var GradientStop = Base.extend(/** @lends GradientStop# */{
|
||||
_class: 'GradientStop',
|
||||
|
||||
/**
|
||||
* Creates a GradientStop object.
|
||||
*
|
||||
|
|
|
@ -202,6 +202,8 @@ var Style = Base.extend(new function() {
|
|||
Item.inject(item);
|
||||
return fields;
|
||||
}, /** @lends Style# */{
|
||||
_class: 'Style',
|
||||
|
||||
initialize: function Style(style, _item) {
|
||||
// We keep values in a separate object that we can iterate over.
|
||||
this._values = {};
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
* @extends TextItem
|
||||
*/
|
||||
var PointText = TextItem.extend(/** @lends PointText# */{
|
||||
_class: 'PointText',
|
||||
|
||||
/**
|
||||
* Creates a point text item
|
||||
*
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var TextItem = Item.extend(/** @lends TextItem# */{
|
||||
_class: 'TextItem',
|
||||
_boundsSelected: true,
|
||||
_serializeFields: {
|
||||
content: null
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
* }
|
||||
*/
|
||||
var Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
||||
_class: 'Tool',
|
||||
_list: 'tools',
|
||||
_reference: '_tool', // PaperScope has accessor for #tool
|
||||
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions',
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* @extends Event
|
||||
*/
|
||||
var ToolEvent = Event.extend(/** @lends ToolEvent# */{
|
||||
_class: 'ToolEvent',
|
||||
// Have ToolEvent#item fall back to returning null, not undefined.
|
||||
_item: null,
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* @private
|
||||
*/
|
||||
var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||
_class: 'CanvasView',
|
||||
|
||||
/**
|
||||
* Creates a view object that wraps a canvas element.
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* @class
|
||||
*/
|
||||
var Component = Base.extend(Callback, /** @lends Component# */{
|
||||
_class: 'Component',
|
||||
_events: [ 'onChange', 'onClick' ],
|
||||
|
||||
_types: {
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* @class
|
||||
*/
|
||||
var Event = Base.extend(/** @lends Event# */{
|
||||
_class: 'Event',
|
||||
|
||||
initialize: function Event(event) {
|
||||
this.event = event;
|
||||
},
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
* @extends Event
|
||||
*/
|
||||
var KeyEvent = Event.extend(/** @lends KeyEvent# */{
|
||||
_class: 'KeyEvent',
|
||||
|
||||
initialize: function KeyEvent(down, key, character, event) {
|
||||
Event.call(this, event);
|
||||
this.type = down ? 'keydown' : 'keyup';
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
* @extends Event
|
||||
*/
|
||||
var MouseEvent = Event.extend(/** @lends MouseEvent# */{
|
||||
_class: 'MouseEvent',
|
||||
|
||||
initialize: function MouseEvent(type, event, point, target, delta) {
|
||||
Event.call(this, event);
|
||||
this.type = type;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* @class
|
||||
*/
|
||||
var Palette = Base.extend(Callback, /** @lends Palette# */{
|
||||
_class: 'Palette',
|
||||
_events: [ 'onChange' ],
|
||||
|
||||
initialize: function Palette(title, components, values) {
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
* screen.
|
||||
*/
|
||||
var View = Base.extend(Callback, /** @lends View# */{
|
||||
_class: 'View',
|
||||
|
||||
initialize: function View(element) {
|
||||
// Store reference to the currently active global paper scope, and the
|
||||
// active project, which will be represented by this view
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue