mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Make sure the Base class is exposed in Node.js
This commit is contained in:
parent
45ab6c7676
commit
c70b985911
3 changed files with 5 additions and 9 deletions
|
@ -18,7 +18,7 @@
|
||||||
* http://dev.helma.org/Wiki/JavaScript+Inheritance+Sugar/
|
* http://dev.helma.org/Wiki/JavaScript+Inheritance+Sugar/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Base = new function() { // Bootstrap scope
|
var Base = this.Base = new function() { // Straps scope
|
||||||
var hidden = /^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,
|
var hidden = /^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,
|
||||||
proto = Object.prototype,
|
proto = Object.prototype,
|
||||||
toString = proto.toString,
|
toString = proto.toString,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
// When in dev mode, also export all classes through PaperScope, to mimick
|
// When in dev mode, also export all classes through PaperScope, to mimick
|
||||||
// scoping behavior of the built library.
|
// scoping behavior of the built library.
|
||||||
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 === Base)
|
||||||
PaperScope.prototype[key] = val;
|
PaperScope.prototype[key] = val;
|
||||||
});
|
});
|
||||||
// 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
|
||||||
|
|
|
@ -93,8 +93,6 @@ context.include('paper.js');
|
||||||
// to redefine Base.isPlainObject() here.
|
// to redefine Base.isPlainObject() here.
|
||||||
// So instead of checking for Object.prototype, we're checking
|
// So instead of checking for Object.prototype, we're checking
|
||||||
// proto.constructor.name for 'Object'
|
// proto.constructor.name for 'Object'
|
||||||
// TODO: Benchmark the speed and consider this implementation instead of the
|
|
||||||
// current one in straps.js too
|
|
||||||
var Base = context.Base;
|
var Base = context.Base;
|
||||||
Base.isPlainObject = function(obj) {
|
Base.isPlainObject = function(obj) {
|
||||||
var proto = obj !== null && typeof obj === 'object'
|
var proto = obj !== null && typeof obj === 'object'
|
||||||
|
@ -103,16 +101,14 @@ Base.isPlainObject = function(obj) {
|
||||||
|| proto === Base.prototype);
|
|| proto === Base.prototype);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Expose the Canvas, XMLSerializer to paper scopes:
|
context.PaperScope.inject({
|
||||||
Base.each({
|
// Expose the Canvas, XMLSerializer & DOMParser to PaperScope:
|
||||||
Canvas: Canvas,
|
Canvas: Canvas,
|
||||||
XMLSerializer: XMLSerializer,
|
XMLSerializer: XMLSerializer,
|
||||||
DOMParser: DOMParser,
|
DOMParser: DOMParser,
|
||||||
// Also fix version. Remove 2nd dot, so we can make a float out of it:
|
// Also fix version. Remove 2nd dot, so we can make a float out of it:
|
||||||
version: parseFloat(json.version.replace(/(.)(\d)$/, '$2'))
|
version: parseFloat(json.version.replace(/(.)(\d)$/, '$2'))
|
||||||
}, function(value, key) {
|
});
|
||||||
this[key] = value;
|
|
||||||
}, context.PaperScope.prototype);
|
|
||||||
|
|
||||||
require.extensions['.pjs'] = function(module, uri) {
|
require.extensions['.pjs'] = function(module, uri) {
|
||||||
var source = context.PaperScript.compile(fs.readFileSync(uri, 'utf8'));
|
var source = context.PaperScript.compile(fs.readFileSync(uri, 'utf8'));
|
||||||
|
|
Loading…
Reference in a new issue