Fix Node.js support.

This commit is contained in:
Jonathan Puckey 2012-09-01 19:27:38 +02:00
parent cbba321977
commit 7247c1a5a2
4 changed files with 5 additions and 7 deletions

View file

@ -1 +0,0 @@
module.exports = require('./src/loadNode.js');

View file

@ -1,9 +1,7 @@
var fs = require('fs'),
vm = require('vm'),
path = require('path'),
// Have HTMLCanvasElement reference Canvas too, so we do not handle browser
// and server differently in some places of our code.
Canvas = HTMLCanvasElement =require('canvas');
Canvas = require('canvas');
__dirname = path.resolve(__dirname, '../src/');
@ -16,6 +14,7 @@ var context = vm.createContext({
fs: fs,
// Node Canvas library: https://github.com/learnboost/node-canvas
Canvas: Canvas,
HTMLCanvasElement: Canvas,
Image: Canvas.Image,
// Copy over global variables:
console: console,

View file

@ -13,8 +13,8 @@
"keywords": ["canvas", "graphic", "graphics", "vector", "paper.js"],
"repository": "git://github.com/paperjs/paper.js/",
"dependencies": {
"canvas": "0.7.0"
"canvas": ">= 0.7.0"
},
"engines": { "node": ">= 0.4.0 && < 0.6.0" },
"engines": { "node": ">= 0.4.0" },
"main": "./node.js/index.js"
}

View file

@ -155,7 +155,7 @@ var PaperScript = this.PaperScript = new function() {
function evaluate(code, scope) {
// Set currently active scope.
paper = scope;
var view = scope.project.view,
var view = scope.project && scope.project.view,
res;
// Define variables for potential handlers, so eval() calls below to
// fetch their values do not require try-catch around them.