@marvalt/wparser 0.1.52 → 0.1.53

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.cjs CHANGED
@@ -2094,6 +2094,28 @@ function extractBackgroundColor(block, context) {
2094
2094
  // Fallback: return null (no background applied)
2095
2095
  return null;
2096
2096
  }
2097
+ /**
2098
+ * Extract the actual color value (hex/rgb) from background color attribute
2099
+ * Used to check if a section has a custom background color that should override alternating system
2100
+ *
2101
+ * @param block - WordPress block to extract background color value from
2102
+ * @param context - Render context containing optional themePalette
2103
+ * @returns Color value string (e.g., '#eb8900') or null if no color
2104
+ */
2105
+ function extractBackgroundColorValue(block, context) {
2106
+ const attrs = block.attributes || {};
2107
+ const wpColorName = attrs['backgroundColor'] || attrs['background'];
2108
+ if (!wpColorName || typeof wpColorName !== 'string') {
2109
+ return null;
2110
+ }
2111
+ // If themePalette is available, get the actual color value
2112
+ if (context.themePalette?.[wpColorName]) {
2113
+ const color = context.themePalette[wpColorName];
2114
+ // Return the color value (could be hex, rgb, or other CSS color format)
2115
+ return color;
2116
+ }
2117
+ return null;
2118
+ }
2097
2119
  /**
2098
2120
  * Extract and map text color from block attributes
2099
2121
  * Uses colorMapper from context to convert WordPress theme colors to app CSS classes
@@ -2119,13 +2141,17 @@ function extractTextColor(block, context) {
2119
2141
  return textColorMap[wpColorName];
2120
2142
  }
2121
2143
  // Use colorMapper from context if available
2122
- // Note: colorMapper might return combined classes like "bg-gray-900 text-white"
2123
- // We'll extract just the text color part
2144
+ // Note: colorMapper might return combined classes like "bg-gray-900 text-white" or "bg-[#eb8900] text-[#eb8900] text-white"
2145
+ // We'll extract just the text color part, prioritizing actual color values over generic classes
2124
2146
  if (context.colorMapper) {
2125
2147
  const mapped = context.colorMapper(wpColorName);
2126
2148
  if (mapped) {
2127
- // If the mapped class includes text color (e.g., "bg-gray-900 text-white"),
2128
- // extract just the text color part
2149
+ // First, try to extract text-[#color] (actual color value)
2150
+ const textColorValueMatch = mapped.match(/\btext-\[([^\]]+)\]/);
2151
+ if (textColorValueMatch) {
2152
+ return `text-[${textColorValueMatch[1]}]`;
2153
+ }
2154
+ // Then, try to extract generic text color classes (e.g., "text-white", "text-gray-900")
2129
2155
  const textColorMatch = mapped.match(/\btext-\S+/);
2130
2156
  if (textColorMatch) {
2131
2157
  return textColorMatch[0];
@@ -2987,6 +3013,7 @@ exports.createDefaultRegistry = createDefaultRegistry;
2987
3013
  exports.createEnhancedRegistry = createEnhancedRegistry;
2988
3014
  exports.extractAlignment = extractAlignment;
2989
3015
  exports.extractBackgroundColor = extractBackgroundColor;
3016
+ exports.extractBackgroundColorValue = extractBackgroundColorValue;
2990
3017
  exports.extractBackgroundImage = extractBackgroundImage;
2991
3018
  exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
2992
3019
  exports.extractContent = extractContent;