This repository was archived by the owner on Mar 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathprocessing.js
More file actions
91 lines (70 loc) · 1.75 KB
/
processing.js
File metadata and controls
91 lines (70 loc) · 1.75 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Module dependencies.
*/
var fs = require('fs')
, util = require('util')
, jsdom = require('jsdom')
, pkg = require('../package')
, patch = require('./patch')
, XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
, Canvas = require('./canvas')
, Image = Canvas.Image
, document = jsdom.jsdom('<!doctype html><html><head></head><body></body></html>')
, window = document.createWindow()
, navigator = window.navigator
, HTMLImageElement = window.HTMLImageElement
, noop = function() {}
, processing = fs.readFileSync(__dirname+'/../deps/processing-js/processing.js');
/**
* Expose `version`.
*/
exports.version = pkg.version;
/**
* Expose `window`.
*/
exports.window = window;
/**
* Expose `document`.
*/
exports.document = document;
/**
* Make `Canvas` instance of `HTMLCanvasElement`.
*/
function HTMLCanvasElement() {}
Canvas.prototype.__proto__ = HTMLCanvasElement.prototype;
/**
* Evaluating Processing source code.
*
* FIXME: `Processing` leaks to global object.
*/
eval('(function(window, document) {'
+ processing.toString('utf-8')
+ '})(window, document);');
/**
* Expose `Processing`.
*/
exports.Processing = window.Processing;
/**
* Return processing instance.
*
* @param {Canvas} canvas
* @param {String} path
* @return {Processing}
*/
exports.createInstance = function(canvas, path) {
var src;
if (Buffer.isBuffer(canvas)) {
canvas = canvas.toString();
}
if (1 == arguments.length) {
path = canvas;
canvas = document.createElement('canvas');
} else if ('string' === typeof canvas) {
src = canvas;
canvas = document.createElement('canvas');
}
if (!src) {
src = fs.readFileSync(path).toString();
}
return patch(new Processing(canvas, src), path);
};