@marvalt/wparser 0.1.52 → 0.1.54
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 +70 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +68 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/blockExtractors.d.ts +28 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1910,6 +1910,28 @@ function extractTitleFromInnerBlocks(block) {
|
|
|
1910
1910
|
}
|
|
1911
1911
|
return null;
|
|
1912
1912
|
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Extract text color from heading block in innerBlocks
|
|
1915
|
+
* Used to get custom text color for hero headings
|
|
1916
|
+
*
|
|
1917
|
+
* @param block - Block to search (typically a cover block)
|
|
1918
|
+
* @param context - Render context containing colorMapper
|
|
1919
|
+
* @returns CSS class string (e.g., 'text-white') or null if no custom color
|
|
1920
|
+
*/
|
|
1921
|
+
function extractTitleTextColorFromInnerBlocks(block, context) {
|
|
1922
|
+
const innerBlocks = block.innerBlocks || [];
|
|
1923
|
+
// Recursively search for heading blocks
|
|
1924
|
+
for (const innerBlock of innerBlocks) {
|
|
1925
|
+
if (innerBlock.name === 'core/heading') {
|
|
1926
|
+
return extractTextColor(innerBlock, context);
|
|
1927
|
+
}
|
|
1928
|
+
// Recursively search nested blocks
|
|
1929
|
+
const nestedColor = extractTitleTextColorFromInnerBlocks(innerBlock, context);
|
|
1930
|
+
if (nestedColor)
|
|
1931
|
+
return nestedColor;
|
|
1932
|
+
}
|
|
1933
|
+
return null;
|
|
1934
|
+
}
|
|
1913
1935
|
/**
|
|
1914
1936
|
* Extract subtitle/description from innerBlocks (finds first paragraph block)
|
|
1915
1937
|
*/
|
|
@@ -2094,6 +2116,43 @@ function extractBackgroundColor(block, context) {
|
|
|
2094
2116
|
// Fallback: return null (no background applied)
|
|
2095
2117
|
return null;
|
|
2096
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Extract the actual color value (hex/rgb) from background color attribute
|
|
2121
|
+
* Used to check if a section has a custom background color that should override alternating system
|
|
2122
|
+
*
|
|
2123
|
+
* @param block - WordPress block to extract background color value from
|
|
2124
|
+
* @param context - Render context containing optional themePalette
|
|
2125
|
+
* @returns Color value string (e.g., '#eb8900') or null if no color
|
|
2126
|
+
*/
|
|
2127
|
+
function extractBackgroundColorValue(block, context) {
|
|
2128
|
+
const attrs = block.attributes || {};
|
|
2129
|
+
const wpColorName = attrs['backgroundColor'] || attrs['background'];
|
|
2130
|
+
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2131
|
+
return null;
|
|
2132
|
+
}
|
|
2133
|
+
// If themePalette is available, get the actual color value
|
|
2134
|
+
if (context.themePalette?.[wpColorName]) {
|
|
2135
|
+
const color = context.themePalette[wpColorName];
|
|
2136
|
+
// Return the color value (could be hex, rgb, or other CSS color format)
|
|
2137
|
+
return color;
|
|
2138
|
+
}
|
|
2139
|
+
return null;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Extract gradient background from block attributes
|
|
2143
|
+
* WordPress stores gradients in attributes.style.color.gradient
|
|
2144
|
+
*
|
|
2145
|
+
* @param block - WordPress block to extract gradient from
|
|
2146
|
+
* @returns Gradient string (e.g., "linear-gradient(...)") or null if no gradient
|
|
2147
|
+
*/
|
|
2148
|
+
function extractGradientBackground(block) {
|
|
2149
|
+
const attrs = block.attributes || {};
|
|
2150
|
+
const style = attrs['style'];
|
|
2151
|
+
if (style?.color?.gradient && typeof style.color.gradient === 'string') {
|
|
2152
|
+
return style.color.gradient;
|
|
2153
|
+
}
|
|
2154
|
+
return null;
|
|
2155
|
+
}
|
|
2097
2156
|
/**
|
|
2098
2157
|
* Extract and map text color from block attributes
|
|
2099
2158
|
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
@@ -2119,13 +2178,17 @@ function extractTextColor(block, context) {
|
|
|
2119
2178
|
return textColorMap[wpColorName];
|
|
2120
2179
|
}
|
|
2121
2180
|
// 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
|
|
2181
|
+
// Note: colorMapper might return combined classes like "bg-gray-900 text-white" or "bg-[#eb8900] text-[#eb8900] text-white"
|
|
2182
|
+
// We'll extract just the text color part, prioritizing actual color values over generic classes
|
|
2124
2183
|
if (context.colorMapper) {
|
|
2125
2184
|
const mapped = context.colorMapper(wpColorName);
|
|
2126
2185
|
if (mapped) {
|
|
2127
|
-
//
|
|
2128
|
-
|
|
2186
|
+
// First, try to extract text-[#color] (actual color value)
|
|
2187
|
+
const textColorValueMatch = mapped.match(/\btext-\[([^\]]+)\]/);
|
|
2188
|
+
if (textColorValueMatch) {
|
|
2189
|
+
return `text-[${textColorValueMatch[1]}]`;
|
|
2190
|
+
}
|
|
2191
|
+
// Then, try to extract generic text color classes (e.g., "text-white", "text-gray-900")
|
|
2129
2192
|
const textColorMatch = mapped.match(/\btext-\S+/);
|
|
2130
2193
|
if (textColorMatch) {
|
|
2131
2194
|
return textColorMatch[0];
|
|
@@ -2987,11 +3050,13 @@ exports.createDefaultRegistry = createDefaultRegistry;
|
|
|
2987
3050
|
exports.createEnhancedRegistry = createEnhancedRegistry;
|
|
2988
3051
|
exports.extractAlignment = extractAlignment;
|
|
2989
3052
|
exports.extractBackgroundColor = extractBackgroundColor;
|
|
3053
|
+
exports.extractBackgroundColorValue = extractBackgroundColorValue;
|
|
2990
3054
|
exports.extractBackgroundImage = extractBackgroundImage;
|
|
2991
3055
|
exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
|
|
2992
3056
|
exports.extractContent = extractContent;
|
|
2993
3057
|
exports.extractDimRatio = extractDimRatio;
|
|
2994
3058
|
exports.extractFontSize = extractFontSize;
|
|
3059
|
+
exports.extractGradientBackground = extractGradientBackground;
|
|
2995
3060
|
exports.extractHeadingLevel = extractHeadingLevel;
|
|
2996
3061
|
exports.extractImageAttributes = extractImageAttributes;
|
|
2997
3062
|
exports.extractImageUrl = extractImageUrl;
|
|
@@ -3007,6 +3072,7 @@ exports.extractTextColor = extractTextColor;
|
|
|
3007
3072
|
exports.extractTextFromHTML = extractTextFromHTML;
|
|
3008
3073
|
exports.extractTitle = extractTitle;
|
|
3009
3074
|
exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
|
|
3075
|
+
exports.extractTitleTextColorFromInnerBlocks = extractTitleTextColorFromInnerBlocks;
|
|
3010
3076
|
exports.extractVerticalAlignment = extractVerticalAlignment;
|
|
3011
3077
|
exports.extractVideoIframeFromInnerBlocks = extractVideoIframeFromInnerBlocks;
|
|
3012
3078
|
exports.findMatchingMapping = findMatchingMapping;
|