diff --git a/CHANGELOG.md b/CHANGELOG.md index e0df18a1..571532a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 10.0.6 (2025-10-22) + +- Better `Image.getClientRect()` calculation if an instance has no image attached yet + ## 10.0.5 (2025-10-22) - Simplify types to fix TS errors diff --git a/src/shapes/Image.ts b/src/shapes/Image.ts index 667d3bf6..9423eb11 100644 --- a/src/shapes/Image.ts +++ b/src/shapes/Image.ts @@ -43,7 +43,7 @@ export interface ImageConfig extends ShapeConfig { export class Image extends Shape { private _loadListener: () => void; - constructor(attrs: ImageConfig) { + constructor(attrs?: ImageConfig) { super(attrs); this._loadListener = () => { this._requestDraw(); @@ -147,10 +147,10 @@ export class Image extends Shape { context.fillStrokeShape(this); } getWidth() { - return this.attrs.width ?? (this.image() as any)?.width; + return this.attrs.width ?? (this.image() as any)?.width ?? 0; } getHeight() { - return this.attrs.height ?? (this.image() as any)?.height; + return this.attrs.height ?? (this.image() as any)?.height ?? 0; } /** diff --git a/test/unit/Image-test.ts b/test/unit/Image-test.ts index c90b759a..04c75682 100644 --- a/test/unit/Image-test.ts +++ b/test/unit/Image-test.ts @@ -396,6 +396,16 @@ describe('Image', function () { }); }); + it('test image client rect without image object attached', function () { + var stage = addStage(); + var layer = new Konva.Layer(); + stage.add(layer); + var image = new Konva.Image(); + layer.add(image); + assert.equal(image.getClientRect().width, 0); + assert.equal(image.getClientRect().height, 0); + }); + it('corner radius with shadow', function (done) { // that will trigger buffer canvas loadImage('darth-vader.jpg', (imageObj) => {