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