paper.js/src/export.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
2014-01-03 19:47:16 -05:00
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
2013-06-27 06:58:14 -04:00
// First add Base and a couple of other objects that are not automatically
// exported to exports (Numerical, Key, etc), then inject all exports into
// PaperScope, and create the initial paper object, all in one statement:
/*#*/ if (__options.environment == 'browser') {
2014-10-08 09:52:41 -04:00
// NOTE: Do not create local variable `var paper` since it would shield the
// global one in the whole scope.
paper = new (PaperScope.inject(Base.exports, {
2014-08-16 13:24:54 -04:00
// Mark fields as enumerable so PaperScope.inject can pick them up
enumerable: true,
Base: Base,
Numerical: Numerical,
Key: Key
}))();
// https://github.com/umdjs/umd
2014-07-25 14:10:20 -04:00
if (typeof define === 'function' && define.amd) {
2014-08-16 13:24:54 -04:00
// Support AMD (e.g. require.js)
// Use named module AMD syntax since there are other unnamed calls to
// define() inside the built library (from inlined Acorn / Esprima) that
// apparently confuse the require.js optimizer.
define('paper', paper);
} else if (typeof module === 'object' && module) { // could be `null`
2014-08-16 13:24:54 -04:00
// Support CommonJS module
// NOTE: Do not check typeof module.exports === 'object' since it will be
// the Base constructor function after straps.js is included.
2014-08-16 13:24:54 -04:00
module.exports = paper;
2014-07-25 14:10:20 -04:00
}
/*#*/ } else if (__options.environment == 'node') {
paper = new (PaperScope.inject(Base.exports, {
2014-08-16 13:24:54 -04:00
// Mark fields as enumerable so PaperScope.inject can pick them up
enumerable: true,
Base: Base,
Numerical: Numerical,
// Export dom/node.js stuff too
XMLSerializer: XMLSerializer,
DOMParser: DOMParser,
Canvas: Canvas
}))();
// Export the paper scope.
module.exports = paper;
/*#*/ } // __options.environment == 'node'