Preparing fabric for publishing through npm. Make fabric.createCanvasForNode accept width/height rather than reference to node-canvas, to prevent user from having to instantiate node-canvas instance. Add fabric.Canvas.prototype.createPNGStream which is a simple proxy for node-canvas createPNGStream.

This commit is contained in:
kangax 2011-08-16 15:57:07 -04:00
parent b53d794af6
commit 6e9543cb69
4 changed files with 71 additions and 10 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

31
dist/all.js vendored
View file

@ -11031,9 +11031,9 @@ fabric.util.object.extend(fabric.Canvas.prototype, {
var XML = require('o3-xml'),
URL = require('url'),
HTTP = require('http'),
Image = require('canvas').Image,
fabric = require('../dist/all.js').fabric;
Canvas = require('canvas'),
Image = require('canvas').Image;
function request(url, encoding, callback) {
var oURL = URL.parse(url),
@ -11082,8 +11082,10 @@ fabric.util.object.extend(fabric.Canvas.prototype, {
});
};
fabric.createCanvasForNode = function(nodeCanvas) {
var canvasEl = fabric.document.createElement('canvas');
fabric.createCanvasForNode = function(width, height) {
var canvasEl = fabric.document.createElement('canvas'),
nodeCanvas = new Canvas(width || 600, height || 600);
// jsdom doesn't create style on canvas element, so here be temp. workaround
canvasEl.style = { };
@ -11093,8 +11095,27 @@ fabric.util.object.extend(fabric.Canvas.prototype, {
var fabricCanvas = new fabric.Canvas(canvasEl);
fabricCanvas.contextContainer = nodeCanvas.getContext('2d');
fabricCanvas.nodeCanvas = nodeCanvas;
return fabricCanvas;
};
fabric.Canvas.prototype.createPNGStream = function() {
return this.nodeCanvas.createPNGStream();
};
var origSetWidth = fabric.Canvas.prototype.setWidth;
fabric.Canvas.prototype.setWidth = function(width) {
origSetWidth.call(this);
this.nodeCanvas.width = width;
return this;
};
var origSetHeight = fabric.Canvas.prototype.setHeight;
fabric.Canvas.prototype.setHeight = function(height) {
origSetHeight.call(this);
this.nodeCanvas.height = height;
return this;
};
})();

View file

@ -7,9 +7,9 @@
var XML = require('o3-xml'),
URL = require('url'),
HTTP = require('http'),
Image = require('canvas').Image,
fabric = require('../dist/all.js').fabric;
Canvas = require('canvas'),
Image = require('canvas').Image;
function request(url, encoding, callback) {
var oURL = URL.parse(url),
@ -58,8 +58,10 @@
});
};
fabric.createCanvasForNode = function(nodeCanvas) {
var canvasEl = fabric.document.createElement('canvas');
fabric.createCanvasForNode = function(width, height) {
var canvasEl = fabric.document.createElement('canvas'),
nodeCanvas = new Canvas(width || 600, height || 600);
// jsdom doesn't create style on canvas element, so here be temp. workaround
canvasEl.style = { };
@ -69,8 +71,27 @@
var fabricCanvas = new fabric.Canvas(canvasEl);
fabricCanvas.contextContainer = nodeCanvas.getContext('2d');
fabricCanvas.nodeCanvas = nodeCanvas;
return fabricCanvas;
};
fabric.Canvas.prototype.createPNGStream = function() {
return this.nodeCanvas.createPNGStream();
};
var origSetWidth = fabric.Canvas.prototype.setWidth;
fabric.Canvas.prototype.setWidth = function(width) {
origSetWidth.call(this);
this.nodeCanvas.width = width;
return this;
};
var origSetHeight = fabric.Canvas.prototype.setHeight;
fabric.Canvas.prototype.setHeight = function(height) {
origSetHeight.call(this);
this.nodeCanvas.height = height;
return this;
};
})();

18
package.json Normal file
View file

@ -0,0 +1,18 @@
{
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"version": "0.5.1",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"],
"repository": "git://github.com/kangax/fabric.js",
"scripts": {
"build": "node build.js modules=ALL"
},
"dependencies": {
"canvas": "0.7.0",
"jsdom": "0.2.3",
"o3-xml": "0.1.0"
},
"engines": { "node": ">= 0.4.0 && < 0.6.0" },
"main": "./dist/all.js"
}