2016-01-26 14:02:23 -05:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2018-12-27 02:13:01 -05:00
|
|
|
* Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
|
2018-11-10 02:19:34 -05:00
|
|
|
* http://scratchdisk.com/ & https://puckey.studio/
|
2016-01-26 14:02:23 -05:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 14:14:49 -05:00
|
|
|
// Here we only make sure that there's a window and document object in the node
|
|
|
|
// environment. We can't do this directly in src/paper.js, due to the nature of
|
|
|
|
// how Prepro.js loads the include() files in the various scenarios. E.g. on
|
|
|
|
// Node.js,only the files included in such a way see each other's variables in
|
|
|
|
// their shared scope.
|
2016-01-26 14:02:23 -05:00
|
|
|
|
2017-03-19 11:03:29 -04:00
|
|
|
// Set up a local `window` variable valid across the full the paper.js scope,
|
|
|
|
// pointing to the native window in browsers and the one provided by JSDom in
|
|
|
|
// Node.js
|
|
|
|
// In workers and on Node.js, the global `window` variable is null. In workers,
|
|
|
|
// `self` is defined as a `WorkerGlobalScope` object, while in Node.js, `self`
|
|
|
|
// is null.
|
|
|
|
// When `self` is null (Node.js only). './node/self.js' is required to provide
|
|
|
|
// a window object through JSDom and assigned it to `self`.
|
|
|
|
// When `self.window` and therefore the local `window` is still null after that,
|
|
|
|
// we know that we are in a worker-like context. This check is used all across
|
|
|
|
// the library, see for example `View.create()`.
|
2016-02-02 11:30:38 -05:00
|
|
|
// NOTE: We're not modifying the global `self` here. We receive its value passed
|
|
|
|
// to the paper.js function scope, and this is the one that is modified here.
|
2017-03-19 11:03:29 -04:00
|
|
|
self = self || require('./node/self.js');
|
2016-07-12 13:11:09 -04:00
|
|
|
var window = self.window,
|
|
|
|
document = self.document;
|