From 55cc2bdab3f810b1cba2a03f03aaf4b04bb1e3bf Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 29 Sep 2021 09:37:49 +0200 Subject: [PATCH] canvas: force computation of css var containing calc() or var() --- src/client/widgets/common/canvas.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/client/widgets/common/canvas.js b/src/client/widgets/common/canvas.js index 46ce34e9..15434a37 100644 --- a/src/client/widgets/common/canvas.js +++ b/src/client/widgets/common/canvas.js @@ -111,8 +111,20 @@ class Canvas extends Widget { for (var data of this.constructor.cssVariables) { var val = style.getPropertyValue(data.css).trim() + + if (typeof val === 'string' && val.includes('(')) { + // property not computed because of calc() or var() in user style + // -> attempt to force calculation + var dummy = html`
` + this.container.appendChild(dummy) + let s = window.getComputedStyle(dummy) + val = parseInt(s.getPropertyValue('width')) + this.container.removeChild(dummy) + } + this.cssVars[data.js] = data.toJs ? data.toJs(val) : val + } this.fontFamily = style.getPropertyValue('font-family').trim()