@marvalt/wparser 0.1.41 → 0.1.42
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 +46 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +46 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2136,34 +2136,62 @@ function extractBackgroundColor(block, context) {
|
|
|
2136
2136
|
*/
|
|
2137
2137
|
function extractTextColor(block, context) {
|
|
2138
2138
|
const attrs = block.attributes || {};
|
|
2139
|
-
|
|
2139
|
+
// Try multiple possible attribute names for text color
|
|
2140
|
+
let wpColorName = attrs['textColor'] ||
|
|
2141
|
+
attrs['text'] ||
|
|
2142
|
+
attrs['textColorSlug'] ||
|
|
2143
|
+
null;
|
|
2144
|
+
// If not found in attributes, check className for WordPress color classes
|
|
2145
|
+
// WordPress uses classes like: has-accent-4-color, has-contrast-color
|
|
2146
|
+
// Note: We need to avoid matching has-{color}-background-color, so we check for -color that's not followed by -background
|
|
2147
|
+
if (!wpColorName && attrs['className']) {
|
|
2148
|
+
const className = attrs['className'];
|
|
2149
|
+
// Match: has-{color}-color (text color class, not background-color)
|
|
2150
|
+
// This regex matches "has-accent-4-color" but not "has-accent-4-background-color"
|
|
2151
|
+
const colorMatch = className.match(/has-([\w-]+)-color(?!-background)/);
|
|
2152
|
+
if (colorMatch && colorMatch[1]) {
|
|
2153
|
+
wpColorName = colorMatch[1];
|
|
2154
|
+
}
|
|
2155
|
+
// Debug logging
|
|
2156
|
+
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development' && !wpColorName) {
|
|
2157
|
+
// Check if there are any color-related classes
|
|
2158
|
+
const hasColorClass = className.includes('-color');
|
|
2159
|
+
if (hasColorClass && context.colorMapper) {
|
|
2160
|
+
console.log('🔍 extractTextColor - Found color class in className but no match:', {
|
|
2161
|
+
blockName: block.name,
|
|
2162
|
+
className: className,
|
|
2163
|
+
colorClasses: className.split(' ').filter(c => c.includes('-color')),
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2140
2168
|
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2141
2169
|
return null;
|
|
2142
2170
|
}
|
|
2143
|
-
// Special handling for common WordPress color names when used as text color
|
|
2144
|
-
// These mappings take precedence because text color semantics differ from background color
|
|
2145
|
-
const textColorMap = {
|
|
2146
|
-
'contrast': 'text-gray-900', // Contrast text is typically dark/black (opposite of contrast background)
|
|
2147
|
-
'base': 'text-white', // Base text on dark backgrounds
|
|
2148
|
-
};
|
|
2149
|
-
// Check special text color mappings first
|
|
2150
|
-
if (textColorMap[wpColorName]) {
|
|
2151
|
-
return textColorMap[wpColorName];
|
|
2152
|
-
}
|
|
2153
2171
|
// Use colorMapper from context if available
|
|
2154
|
-
// Note: colorMapper
|
|
2155
|
-
// We
|
|
2172
|
+
// Note: colorMapper returns combined classes like "bg-[#FBFAF3] text-gray-900"
|
|
2173
|
+
// We need to extract just the text color part
|
|
2156
2174
|
if (context.colorMapper) {
|
|
2157
2175
|
const mapped = context.colorMapper(wpColorName);
|
|
2158
2176
|
if (mapped) {
|
|
2159
|
-
//
|
|
2160
|
-
//
|
|
2161
|
-
const textColorMatch = mapped.match(/\btext
|
|
2162
|
-
if (textColorMatch) {
|
|
2163
|
-
|
|
2177
|
+
// Extract text color classes (e.g., "text-white", "text-gray-900")
|
|
2178
|
+
// Match text- classes but not text- in the middle of other classes
|
|
2179
|
+
const textColorMatch = mapped.match(/\btext-[\w-]+/g);
|
|
2180
|
+
if (textColorMatch && textColorMatch.length > 0) {
|
|
2181
|
+
// Return the last text color class (in case there are multiple)
|
|
2182
|
+
const result = textColorMatch[textColorMatch.length - 1];
|
|
2183
|
+
// Debug logging
|
|
2184
|
+
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
|
|
2185
|
+
console.log('🎨 extractTextColor - Mapped', wpColorName, '→', result, '(from:', mapped, ')');
|
|
2186
|
+
}
|
|
2187
|
+
return result;
|
|
2164
2188
|
}
|
|
2189
|
+
// If no text color class found, try to determine from the background color
|
|
2190
|
+
// For theme palette colors, we can infer text color based on brightness
|
|
2191
|
+
// But for now, return null if no text color is in the mapped result
|
|
2165
2192
|
}
|
|
2166
2193
|
}
|
|
2194
|
+
// Fallback: return null (no text color applied, will inherit from parent)
|
|
2167
2195
|
return null;
|
|
2168
2196
|
}
|
|
2169
2197
|
/**
|