mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 04:42:02 +08:00
resolve chrome warning. close #1417
This commit is contained in:
parent
742c08599a
commit
ac6de95024
@ -31,6 +31,7 @@ interface ICanvasConfig {
|
|||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
pixelRatio?: number;
|
pixelRatio?: number;
|
||||||
|
willReadFrequently?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,9 +171,13 @@ export class Canvas {
|
|||||||
Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, getNumberValidator());
|
Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, getNumberValidator());
|
||||||
|
|
||||||
export class SceneCanvas extends Canvas {
|
export class SceneCanvas extends Canvas {
|
||||||
constructor(config: ICanvasConfig = { width: 0, height: 0 }) {
|
constructor(
|
||||||
|
config: ICanvasConfig = { width: 0, height: 0, willReadFrequently: false }
|
||||||
|
) {
|
||||||
super(config);
|
super(config);
|
||||||
this.context = new SceneContext(this);
|
this.context = new SceneContext(this, {
|
||||||
|
willReadFrequently: config.willReadFrequently,
|
||||||
|
});
|
||||||
this.setSize(config.width, config.height);
|
this.setSize(config.width, config.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -766,9 +766,11 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export class SceneContext extends Context {
|
export class SceneContext extends Context {
|
||||||
constructor(canvas: Canvas) {
|
constructor(canvas: Canvas, { willReadFrequently = false } = {}) {
|
||||||
super(canvas);
|
super(canvas);
|
||||||
this._context = canvas._canvas.getContext('2d') as CanvasRenderingContext2D;
|
this._context = canvas._canvas.getContext('2d', {
|
||||||
|
willReadFrequently,
|
||||||
|
}) as CanvasRenderingContext2D;
|
||||||
}
|
}
|
||||||
_fillColor(shape: Shape) {
|
_fillColor(shape: Shape) {
|
||||||
var fill = shape.fill();
|
var fill = shape.fill();
|
||||||
|
@ -368,6 +368,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
pixelRatio: pixelRatio,
|
pixelRatio: pixelRatio,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
willReadFrequently: true,
|
||||||
}),
|
}),
|
||||||
cachedHitCanvas = new HitCanvas({
|
cachedHitCanvas = new HitCanvas({
|
||||||
pixelRatio: hitCanvasPixelRatio,
|
pixelRatio: hitCanvasPixelRatio,
|
||||||
|
@ -43,47 +43,14 @@
|
|||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
fill: 'red',
|
fill: 'red',
|
||||||
|
filters: [Konva.Filters.Blur],
|
||||||
|
blurRadius: 10,
|
||||||
});
|
});
|
||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.on('wheel', (e) => {
|
rect.cache();
|
||||||
e.evt.preventDefault();
|
setInterval(() => {
|
||||||
console.log('wheel');
|
rect.blurRadius(rect.blurRadius() + 1);
|
||||||
});
|
}, 100);
|
||||||
stage.on('contextmenu', (e) => {
|
|
||||||
console.log('click');
|
|
||||||
});
|
|
||||||
|
|
||||||
var imageObj = new Image();
|
|
||||||
imageObj.onload = function () {
|
|
||||||
var yoda = new Konva.Image({
|
|
||||||
x: 150,
|
|
||||||
y: 50,
|
|
||||||
image: imageObj,
|
|
||||||
width: 200,
|
|
||||||
height: 200,
|
|
||||||
draggable: true,
|
|
||||||
strokeWidth: 4,
|
|
||||||
stroke: 'blue',
|
|
||||||
cornerRadius: [10, 20, 30, 40],
|
|
||||||
});
|
|
||||||
layer.add(yoda);
|
|
||||||
};
|
|
||||||
imageObj.src = 'https://konvajs.org/assets/yoda.jpg';
|
|
||||||
|
|
||||||
Konva.Image.fromURL('https://konvajs.org/assets/darth-vader.jpg', function (darthNode) {
|
|
||||||
darthNode.setAttrs({
|
|
||||||
x: 300,
|
|
||||||
y: 50,
|
|
||||||
// scaleX: 0.5,
|
|
||||||
// scaleY: 0.5,
|
|
||||||
draggable: true,
|
|
||||||
strokeEnabled: true,
|
|
||||||
stroke: 'green',
|
|
||||||
strokeWidth: 2,
|
|
||||||
cornerRadius: 30,
|
|
||||||
});
|
|
||||||
layer.add(darthNode);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user