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