mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
fix konva-node
This commit is contained in:
parent
3e95726b4d
commit
0c858ff591
@ -133,7 +133,7 @@ Then in you javascript file you will need to use
|
||||
const Konva = require('konva-node');
|
||||
```
|
||||
|
||||
See file `resources/nodejs-demo.js` for example.
|
||||
See file `konva-node/demo.js` file in this repo as a sample.
|
||||
|
||||
# Backers
|
||||
|
||||
|
@ -2,9 +2,7 @@ var fs = require('fs');
|
||||
|
||||
// relative path here
|
||||
// but you will need just require('konva-node');
|
||||
var Konva = require('../konva-node');
|
||||
|
||||
// console.log(Konva.Util.c);
|
||||
var Konva = require('./');
|
||||
|
||||
// Create stage. Container parameter is not required in NodeJS.
|
||||
var stage = new Konva.Stage({
|
@ -1,25 +1,33 @@
|
||||
var Konva = require('konva');
|
||||
var canvas = require('canvas');
|
||||
|
||||
var Canvas = require('canvas');
|
||||
|
||||
// mock window
|
||||
Konva.window = {
|
||||
Image: Canvas.Image,
|
||||
Image: canvas.Image,
|
||||
devicePixelRatio: 1
|
||||
};
|
||||
// mock document
|
||||
Konva.document = {
|
||||
createElement: function() {},
|
||||
documentElement: {
|
||||
addEventListener: function() {}
|
||||
}
|
||||
};
|
||||
Konva.window = new JSDOM(
|
||||
'<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
).window;
|
||||
Konva.document = Konva.window.document;
|
||||
Konva.window.Image = Canvas.Image;
|
||||
|
||||
Konva.Util.createCanvasElement = () => {
|
||||
return new Canvas();
|
||||
// make some global injections
|
||||
global.window = Konva.window;
|
||||
global.requestAnimationFrame = cb => {
|
||||
setImmediate(cb);
|
||||
};
|
||||
|
||||
// create canvas in Node env
|
||||
Konva.Util.createCanvasElement = () => {
|
||||
const node = new canvas.Canvas();
|
||||
node.style = {};
|
||||
return node;
|
||||
};
|
||||
|
||||
// _checkVisibility use dom element, in node we can skip it
|
||||
Konva.Stage.prototype._checkVisibility = () => {};
|
||||
|
||||
module.exports = Konva;
|
||||
|
@ -25,7 +25,7 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"canvas": "^1.6.13",
|
||||
"konva": "^2.6.0"
|
||||
"canvas": "^2.5.0",
|
||||
"konva": "^3.3.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user