-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 945 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* PaperScript Loader
* This is a simple loader to load in the source code and
* wrap it in a portable function.
*/
module.exports = function(source) {
return [
'var paper = require("paper")',
// Export a function that will create the scope
// set up the view and execute the code.
'module.exports = function(view) {',
// Create new scope
'var scope = new paper.PaperScope()',
// Copy any globals to the scope
'paper.install(scope)',
// Set up the scope on the view param passed in
'paper.setup(view)',
// This part is a hack- we need paper.js to think
// it is a node environiment, when it is actually browser
// this prevents paper from appending <script>s to execute code
'scope.agent.chrome = false',
'scope.agent.firefox = false',
// Execute the source code
'scope.execute(' + JSON.stringify(source) + ')',
'return scope',
'}'
].join(';\n');
};