From e9ba3895a96e26c310829552cd24588e4b2a2784 Mon Sep 17 00:00:00 2001 From: Bilawal Hameed Date: Fri, 24 Apr 2020 16:57:13 +0200 Subject: [PATCH] adjust getBBox polyfill logic --- .../tech-radar/src/utils/polyfills/getBBox.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/tech-radar/src/utils/polyfills/getBBox.ts b/plugins/tech-radar/src/utils/polyfills/getBBox.ts index 664b72302e..8504910ab8 100644 --- a/plugins/tech-radar/src/utils/polyfills/getBBox.ts +++ b/plugins/tech-radar/src/utils/polyfills/getBBox.ts @@ -18,19 +18,32 @@ // SVGGElement.prototype.getBBox to calculate boundaries. // JSDOM doesn't support this: https://github.com/jsdom/jsdom/issues/1664 class GetBBoxPolyfill { + static exists(): boolean { + // @ts-ignore + return typeof window.Element.prototype.getBBox !== 'undefined'; + } + static create( x: number = 0, y: number = 0, width: number = 1000, height: number = 500, - ) { + ): void { + if (this.exists()) { + return; + } + Object.defineProperty(window.Element.prototype, 'getBBox', { writable: false, value: () => ({ x, y, width, height }), }); } - static remove() { + static remove(): void { + if (!this.exists()) { + return; + } + // @ts-ignore delete window.Element.prototype.getBBox; }