mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
fix shape.getClientRect() when a parent is cached, fix #1759`
This commit is contained in:
parent
68b4ea3cb6
commit
d95ff79964
@ -3,6 +3,8 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
- Fix `shape.getClientRect()` when any of parents is cached
|
||||||
|
|
||||||
### 9.3.11 (2024-05-23)
|
### 9.3.11 (2024-05-23)
|
||||||
|
|
||||||
- Fix chrome clear canvas issue
|
- Fix chrome clear canvas issue
|
||||||
|
15
src/Shape.ts
15
src/Shape.ts
@ -528,9 +528,22 @@ export class Shape<
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
getClientRect(config: ShapeGetClientRectConfig = {}) {
|
getClientRect(config: ShapeGetClientRectConfig = {}) {
|
||||||
|
// if we have a cached parent, it will use cached transform matrix
|
||||||
|
// but we don't want to that
|
||||||
|
let hasCachedParent = false;
|
||||||
|
let parent = this.getParent();
|
||||||
|
while (parent) {
|
||||||
|
if (parent.isCached()) {
|
||||||
|
hasCachedParent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
const skipTransform = config.skipTransform;
|
const skipTransform = config.skipTransform;
|
||||||
|
|
||||||
const relativeTo = config.relativeTo;
|
// force relative to stage if we have a cached parent
|
||||||
|
const relativeTo =
|
||||||
|
config.relativeTo || (hasCachedParent && this.getStage()) || undefined;
|
||||||
|
|
||||||
const fillRect = this.getSelfRect();
|
const fillRect = this.getSelfRect();
|
||||||
|
|
||||||
|
@ -1653,6 +1653,35 @@ describe('Shape', function () {
|
|||||||
assert.equal(rect.height, 100, 'should not effect width');
|
assert.equal(rect.height, 100, 'should not effect width');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getClientRect should not use cached values', function () {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
|
var shape = new Konva.Rect({
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
strokeEnabled: false,
|
||||||
|
shadowOffsetX: 10,
|
||||||
|
shadowEnabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(shape);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
layer.cache();
|
||||||
|
|
||||||
|
layer.scaleX(2);
|
||||||
|
|
||||||
|
const rect = shape.getClientRect();
|
||||||
|
|
||||||
|
assert.equal(rect.x, 200);
|
||||||
|
});
|
||||||
|
|
||||||
it('getClientRect for shape in transformed parent', function () {
|
it('getClientRect for shape in transformed parent', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
|
Loading…
Reference in New Issue
Block a user