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 ) ;
0 commit comments