@marvalt/wparser 0.1.51 → 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 +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +33 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +11 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
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
|
-
//
|
|
2128
|
-
|
|
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];
|
|
@@ -2337,7 +2363,8 @@ const Heading = ({ block, children, context }) => {
|
|
|
2337
2363
|
// Extract text color if specified, otherwise inherit from parent (CSS variables handle default)
|
|
2338
2364
|
const textColor = extractTextColor(block, context);
|
|
2339
2365
|
const textColorClass = textColor || ''; // Don't hardcode - let CSS variables handle default
|
|
2340
|
-
|
|
2366
|
+
// Don't hardcode font-bold - let CSS variables handle font weight from WordPress
|
|
2367
|
+
return (jsxRuntimeExports.jsx(Tag, { className: buildClassName(textColorClass, sizeClass, textAlign, spacingClass), children: children ?? content }));
|
|
2341
2368
|
};
|
|
2342
2369
|
const Image = ({ block, context }) => {
|
|
2343
2370
|
const imageAttrs = getImageAttributes(block);
|
|
@@ -2986,6 +3013,7 @@ exports.createDefaultRegistry = createDefaultRegistry;
|
|
|
2986
3013
|
exports.createEnhancedRegistry = createEnhancedRegistry;
|
|
2987
3014
|
exports.extractAlignment = extractAlignment;
|
|
2988
3015
|
exports.extractBackgroundColor = extractBackgroundColor;
|
|
3016
|
+
exports.extractBackgroundColorValue = extractBackgroundColorValue;
|
|
2989
3017
|
exports.extractBackgroundImage = extractBackgroundImage;
|
|
2990
3018
|
exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
|
|
2991
3019
|
exports.extractContent = extractContent;
|