Skip to content
This repository was archived by the owner on Mar 12, 2018. It is now read-only.

Commit 6fe68bd

Browse files
committed
Removed jsdom dependency
Simplified wrapper
1 parent f849849 commit 6fe68bd

File tree

4 files changed

+20
-143
lines changed

4 files changed

+20
-143
lines changed

lib/canvas.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/patch.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
2-
/**
3-
* Module dependencies.
4-
*/
5-
6-
var path = require('path');
7-
8-
/**
9-
* Apply patching for Processing instance.
10-
*
11-
* @param {Processing} p5
12-
* @param {String} filePath
13-
* @return {Processing}
14-
*/
15-
16-
module.exports = function(p5, filePath) {
17-
var loadImage = p5.loadImage;
18-
19-
p5.loadImage = function(file, type, callback) {
20-
console.log('IMG: ', file);
21-
console.log('PJS: ', filePath);
22-
return loadImage(file, type, callback);
23-
};
24-
25-
p5.canvas = p5.externals.canvas; // add short-hand.
26-
27-
return p5;
28-
};
1+
var noop = function(){};
2+
3+
module.exports = function(processingConstructor){
4+
//Wrap the Processing Constructor so we can augment node canvas as it is passed in
5+
return function(aCanvas, aCode, aFunctions){
6+
aCanvas.attachEvent = noop;
7+
aCanvas.getAttribute = noop;
8+
aCanvas.setAttribute = noop;
9+
aCanvas.style = {
10+
setProperty : noop
11+
};
12+
return new processingConstructor(aCanvas, aCode, aFunctions);
13+
}
14+
}

lib/processing.js

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,8 @@
11

2-
/**
3-
* Module dependencies.
4-
*/
2+
//Mock Browser used by Processing-js for their own tests
3+
var Browser = require('../deps/processing-js/lib/Browser');
4+
var patch = require("./patch");
55

6-
var fs = require('fs')
7-
, util = require('util')
8-
, jsdom = require('jsdom')
9-
, pkg = require('../package')
10-
, patch = require('./patch')
11-
, XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
12-
, Canvas = require('./canvas')
13-
, Image = Canvas.Image
14-
, document = jsdom.jsdom('<!doctype html><html><head></head><body></body></html>')
15-
, window = document.createWindow()
16-
, navigator = window.navigator
17-
, HTMLImageElement = window.HTMLImageElement
18-
, noop = function() {}
19-
, processing = fs.readFileSync(__dirname+'/../deps/processing-js/processing.js');
20-
21-
/**
22-
* Expose `version`.
23-
*/
24-
25-
exports.version = pkg.version;
26-
27-
/**
28-
* Expose `window`.
29-
*/
30-
31-
exports.window = window;
32-
33-
/**
34-
* Expose `document`.
35-
*/
36-
37-
exports.document = document;
38-
39-
/**
40-
* Make `Canvas` instance of `HTMLCanvasElement`.
41-
*/
42-
43-
function HTMLCanvasElement() {}
44-
Canvas.prototype.__proto__ = HTMLCanvasElement.prototype;
45-
46-
/**
47-
* Evaluating Processing source code.
48-
*
49-
* FIXME: `Processing` leaks to global object.
50-
*/
51-
52-
eval('(function(window, document) {'
53-
+ processing.toString('utf-8')
54-
+ '})(window, document);');
55-
56-
/**
57-
* Expose `Processing`.
58-
*/
59-
60-
exports.Processing = window.Processing;
61-
62-
/**
63-
* Return processing instance.
64-
*
65-
* @param {Canvas} canvas
66-
* @param {String} path
67-
* @return {Processing}
68-
*/
69-
70-
exports.createInstance = function(canvas, path) {
71-
var src;
72-
73-
if (Buffer.isBuffer(canvas)) {
74-
canvas = canvas.toString();
75-
}
76-
77-
if (1 == arguments.length) {
78-
path = canvas;
79-
canvas = document.createElement('canvas');
80-
} else if ('string' === typeof canvas) {
81-
src = canvas;
82-
canvas = document.createElement('canvas');
83-
}
84-
85-
if (!src) {
86-
src = fs.readFileSync(path).toString();
87-
}
88-
89-
return patch(new window.Processing(canvas, src), path);
90-
};
6+
var Processing = require('../deps/processing-js/src/')(Browser);
917

8+
module.exports = patch(Processing);

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
"test": "make test"
1313
},
1414
"dependencies": {
15-
"jsdom": "0.11.1",
16-
"xmlhttprequest": "*",
17-
"canvas": "*"
1815
},
1916
"devDependencies": {
17+
"canvas": "*",
2018
"express": "*",
2119
"morgan" : "*",
2220
"serve-index" : "*",

0 commit comments

Comments
 (0)