Let's say I have the following CSS rule in a stylesheet:
.demo-rule {
--custom-prop-1: 12px;
--custom-prop-2: 54px;
width: 100%;
height: 100%;
/* several more properties are set here */
}
Now, that rule is applied to multiple HTML elements and I want to recalculate and reassign the values of the two custom CSS properties --custom-prop-1 and --custom-prop-2 using JavaScript. Currently, I'm first obtaining the style of the corresponding rule in the stylesheet as follows:
const style = this.shadowRoot.styleSheets[0].rules[0].style;
Once I got that I calculate and set the values of those properties:
const valueProp1 = /* calculation */;
const valueProp2 = /* calculation */;
style.setProperty("--custom-prop-1", valueProp1);
style.setProperty("--custom-prop-2", valueProp2);
The problem I see is that I edit the style twice. This might force the web browser's rendering engine to recalculcate the layout twice. I would like to change both properties in one atomic operation to prevent that. Is that possible somehow?