From 96744ff5c2de6d0610b787fd07ccfe0d4544df86 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Fri, 27 Sep 2024 15:11:52 +0200 Subject: [PATCH] chore: simplify viewbox cloning --- lib/core/Canvas.js | 2 +- test/spec/core/CanvasSpec.js | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/core/Canvas.js b/lib/core/Canvas.js index 7a0f9c96d..f5adcc1da 100644 --- a/lib/core/Canvas.js +++ b/lib/core/Canvas.js @@ -1153,7 +1153,7 @@ Canvas.prototype._viewboxChanged = function() { Canvas.prototype.viewbox = function(box) { if (box === undefined && this._cachedViewbox) { - return JSON.parse(JSON.stringify(this._cachedViewbox)); + return structuredClone(this._cachedViewbox); } const viewport = this._viewport, diff --git a/test/spec/core/CanvasSpec.js b/test/spec/core/CanvasSpec.js index 45624d01a..20c0b5fe6 100644 --- a/test/spec/core/CanvasSpec.js +++ b/test/spec/core/CanvasSpec.js @@ -869,20 +869,11 @@ describe('Canvas', function() { it('should return copy of viewbox', inject(function(canvas) { - // given - canvas.addShape({ id: 's0', x: 0, y: 0, width: 300, height: 300 }); - - var shape = canvas.addShape({ id: 's1', x: 10000, y: 0, width: 300, height: 300 }); - - var viewbox = canvas.viewbox(), - viewboxStringified = JSON.stringify(viewbox); - // when - canvas.scrollToElement(shape); + var viewbox = canvas.viewbox(); // then - expect(JSON.stringify(viewbox)).to.eql(viewboxStringified); - expect(JSON.stringify(canvas.viewbox())).not.to.eql(viewboxStringified); + expect(viewbox).to.not.equal(canvas.viewbox()); }));