mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
40 lines
798 B
JavaScript
40 lines
798 B
JavaScript
![]() |
var Konva = require('konva');
|
||
|
var canvas = require('canvas');
|
||
|
|
||
|
// mock window
|
||
|
Konva.window = {
|
||
|
Image: canvas.Image,
|
||
|
devicePixelRatio: 1,
|
||
|
};
|
||
|
// mock document
|
||
|
Konva.document = {
|
||
|
createElement: function () {},
|
||
|
documentElement: {
|
||
|
addEventListener: function () {},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
// make some global injections
|
||
|
global.requestAnimationFrame = (cb) => {
|
||
|
setImmediate(cb);
|
||
|
};
|
||
|
|
||
|
// create canvas in Node env
|
||
|
Konva.Util.createCanvasElement = () => {
|
||
|
const node = new canvas.Canvas();
|
||
|
node.style = {};
|
||
|
return node;
|
||
|
};
|
||
|
|
||
|
// create image in Node env
|
||
|
Konva.Util.createImageElement = () => {
|
||
|
const node = new canvas.Image();
|
||
|
node.style = {};
|
||
|
return node;
|
||
|
};
|
||
|
|
||
|
// _checkVisibility use dom element, in node we can skip it
|
||
|
Konva.Stage.prototype._checkVisibility = () => {};
|
||
|
|
||
|
module.exports = Konva;
|