All files / src/internal/client/dom/elements style.js

100% Statements 25/25
87.5% Branches 7/8
100% Functions 1/1
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 262x 2x 2x 2x 2x 2x 2x 2x 162x 162x 162x 162x 162x 162x 34x 34x 128x 128x 128x 162x 16x 162x 112x 112x 162x  
/**
 * @param {HTMLElement} dom
 * @param {string} key
 * @param {string} value
 * @param {boolean} [important]
 * @param {boolean} [force_check] Should be `true` if we can't rely on our cached value, because for example there's also a `style` attribute
 */
export function set_style(dom, key, value, important, force_check) {
	// @ts-expect-error
	var attributes = (dom.__attributes ??= {});
	var style = dom.style;
	var style_key = 'style-' + key;
 
	if (attributes[style_key] === value && (!force_check || style.getPropertyValue(key) === value)) {
		return;
	}
 
	attributes[style_key] = value;
 
	if (value == null) {
		style.removeProperty(key);
	} else {
		style.setProperty(key, value, important ? 'important' : '');
	}
}