Files
konva/konva-node/index.js

48 lines
985 B
JavaScript
Raw Normal View History

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,
2020-11-10 08:59:20 -05:00
devicePixelRatio: 1,
2017-10-11 12:17:54 +04:00
};
2019-06-07 15:05:27 -05:00
// mock document
2017-10-11 12:17:54 +04:00
Konva.document = {
2020-11-10 08:59:20 -05:00
createElement: function () {},
2017-10-11 12:17:54 +04:00
documentElement: {
2020-11-10 08:59:20 -05:00
addEventListener: function () {},
},
2017-10-11 12:17:54 +04:00
};
2019-04-03 18:08:16 -05:00
2019-06-07 15:05:27 -05:00
// make some global injections
2020-11-10 08:59:20 -05:00
global.requestAnimationFrame = (cb) => {
2019-06-07 15:05:27 -05:00
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
2020-11-10 08:59:20 -05:00
// create image in Node env
2019-07-11 04:59:39 +07:00
Konva.Util.createImageElement = () => {
const node = new canvas.Image();
node.style = {};
return node;
};
2021-03-17 14:05:14 +01:00
Konva.Util._urlToImage = (url, callback) => {
2021-03-17 14:06:03 +01:00
const imageObj = Konva.Util.createImageElement();
imageObj.onload = function () {
callback(imageObj);
};
imageObj.src = url;
2021-03-17 14:05:14 +01:00
};
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;