From f5ebee92ec6ac8b602d11a168831e9733ad24c64 Mon Sep 17 00:00:00 2001 From: zm-develops <241188374+zm-develops@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:53:55 +0000 Subject: [PATCH] Remove duplicate parent CSS properties --- src/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/index.js b/src/index.js index f87349b..1d038f7 100644 --- a/src/index.js +++ b/src/index.js @@ -686,6 +686,11 @@ function filterAuthorInlineStyles(context, element) { : null; const defaultStyle = getDefaultStyle(context, element); + // Remove property declarations that are duplicated from a parent element. + if (parentComputedStyle) { + removeDuplicateCustomProperties(styles, parentComputedStyle); + } + // Splice explicit inline style declarations that match default and parent values. tokenizeCssTextDeclarations(styles.inline.cssText) .map(getCssTextProperty) @@ -1022,6 +1027,21 @@ function destroyElementHierarchy(element) { } } +/** + * Removes duplicate CSS properties from the parent element's style. + * + * @param {Styles} styles Styles object for the element. + * @param {CSSStyleDeclaration} parentStyle Parent element's style declaration. + */ +function removeDuplicateCustomProperties(styles, parentStyle) { + for (const name of parentStyle) { + const parentValue = parentStyle.getPropertyValue(name); + if (name.startsWith('--') && styles.inline.getPropertyValue(name) === parentValue) { + styles.inline.removeProperty(name); + } + } +} + /** * Tokenize inline CSS styling declarations. *