@marvalt/wparser 0.1.39 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2081,13 +2081,45 @@ function extractVideoIframeFromInnerBlocks(block) {
2081
2081
  */
2082
2082
  function extractBackgroundColor(block, context) {
2083
2083
  const attrs = block.attributes || {};
2084
- const wpColorName = attrs['backgroundColor'] || attrs['background'];
2084
+ // Try multiple possible attribute names for background color
2085
+ // WordPress can store it as backgroundColor, background, or in style
2086
+ let wpColorName = attrs['backgroundColor'] ||
2087
+ attrs['background'] ||
2088
+ attrs['backgroundColorSlug'] ||
2089
+ null;
2090
+ // If not found in attributes, check className for WordPress color classes
2091
+ // WordPress uses classes like: has-accent-4-background-color, has-contrast-background-color
2092
+ if (!wpColorName && attrs['className']) {
2093
+ const className = attrs['className'];
2094
+ const colorMatch = className.match(/has-([\w-]+)-background-color/);
2095
+ if (colorMatch && colorMatch[1]) {
2096
+ // Convert kebab-case to slug (e.g., "accent-4" stays "accent-4", "contrast" stays "contrast")
2097
+ wpColorName = colorMatch[1];
2098
+ }
2099
+ }
2100
+ // Debug logging in development
2101
+ if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
2102
+ if (!wpColorName && context.colorMapper) {
2103
+ console.log('🔍 extractBackgroundColor - No backgroundColor found in block:', {
2104
+ blockName: block.name,
2105
+ hasClassName: !!attrs['className'],
2106
+ className: attrs['className'],
2107
+ hasStyle: !!attrs['style'],
2108
+ availableAttrs: Object.keys(attrs),
2109
+ });
2110
+ }
2111
+ }
2085
2112
  if (!wpColorName || typeof wpColorName !== 'string') {
2086
2113
  return null;
2087
2114
  }
2088
2115
  // Use colorMapper from context if available
2089
2116
  if (context.colorMapper) {
2090
- return context.colorMapper(wpColorName);
2117
+ const result = context.colorMapper(wpColorName);
2118
+ // Debug logging
2119
+ if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
2120
+ console.log('🎨 extractBackgroundColor - Mapped', wpColorName, '→', result);
2121
+ }
2122
+ return result;
2091
2123
  }
2092
2124
  // Fallback: return null (no background applied)
2093
2125
  return null;