konva/konva-node/index.js

40 lines
792 B
JavaScript
Raw Normal View History

2017-10-19 17:45:28 +08:00
var Konva = require('konva');
2019-06-08 04:05:27 +08:00
var canvas = require('canvas');
2017-10-11 16:17:54 +08:00
2019-06-08 04:05:27 +08:00
// mock window
2017-10-11 16:17:54 +08:00
Konva.window = {
2019-06-08 04:05:27 +08:00
Image: canvas.Image,
2017-10-11 16:17:54 +08:00
devicePixelRatio: 1
};
2019-06-08 04:05:27 +08:00
// mock document
2017-10-11 16:17:54 +08:00
Konva.document = {
createElement: function() {},
documentElement: {
addEventListener: function() {}
}
};
2019-04-04 07:08:16 +08:00
2019-06-08 04:05:27 +08:00
// make some global injections
global.requestAnimationFrame = cb => {
setImmediate(cb);
};
// create canvas in Node env
2019-04-04 07:08:16 +08:00
Konva.Util.createCanvasElement = () => {
2019-06-08 04:05:27 +08:00
const node = new canvas.Canvas();
node.style = {};
return node;
2019-04-04 07:08:16 +08:00
};
2017-10-11 16:17:54 +08:00
2019-07-11 05:59:39 +08:00
// create canvas in Node env
Konva.Util.createImageElement = () => {
const node = new canvas.Image();
node.style = {};
return node;
};
2019-06-08 04:05:27 +08:00
// _checkVisibility use dom element, in node we can skip it
Konva.Stage.prototype._checkVisibility = () => {};
2017-10-11 16:17:54 +08:00
module.exports = Konva;