@marvalt/wparser 0.1.30 → 0.1.32
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 +71 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +71 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +9 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2059,6 +2059,42 @@ function extractBackgroundColor(block, context) {
|
|
|
2059
2059
|
// Fallback: return null (no background applied)
|
|
2060
2060
|
return null;
|
|
2061
2061
|
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Extract and map text color from block attributes
|
|
2064
|
+
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
2065
|
+
*
|
|
2066
|
+
* @param block - WordPress block to extract text color from
|
|
2067
|
+
* @param context - Render context containing optional colorMapper
|
|
2068
|
+
* @returns CSS class string (e.g., 'text-white') or null if no mapping
|
|
2069
|
+
*/
|
|
2070
|
+
function extractTextColor(block, context) {
|
|
2071
|
+
const attrs = block.attributes || {};
|
|
2072
|
+
const wpColorName = attrs['textColor'] || attrs['text'];
|
|
2073
|
+
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2074
|
+
return null;
|
|
2075
|
+
}
|
|
2076
|
+
// Use colorMapper from context if available
|
|
2077
|
+
// Note: colorMapper might return combined classes like "bg-gray-900 text-white"
|
|
2078
|
+
// We'll extract just the text color part
|
|
2079
|
+
if (context.colorMapper) {
|
|
2080
|
+
const mapped = context.colorMapper(wpColorName);
|
|
2081
|
+
if (mapped) {
|
|
2082
|
+
// If the mapped class includes text color (e.g., "bg-gray-900 text-white"),
|
|
2083
|
+
// extract just the text color part
|
|
2084
|
+
const textColorMatch = mapped.match(/\btext-\S+/);
|
|
2085
|
+
if (textColorMatch) {
|
|
2086
|
+
return textColorMatch[0];
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
// Special handling for common WordPress color names when used as text color
|
|
2091
|
+
// These are common text color mappings that might not be in the colorMapper
|
|
2092
|
+
const textColorMap = {
|
|
2093
|
+
'contrast': 'text-gray-900', // Contrast text is typically dark/black
|
|
2094
|
+
'base': 'text-white', // Base text on dark backgrounds
|
|
2095
|
+
};
|
|
2096
|
+
return textColorMap[wpColorName] || null;
|
|
2097
|
+
}
|
|
2062
2098
|
/**
|
|
2063
2099
|
* Extract spacer height from block attributes or innerHTML
|
|
2064
2100
|
* Returns height in pixels, or null if not found
|
|
@@ -2234,9 +2270,11 @@ const Paragraph = ({ block, context }) => {
|
|
|
2234
2270
|
// Render block-level content without <p> wrapper, but add spacing wrapper
|
|
2235
2271
|
return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
|
|
2236
2272
|
}
|
|
2237
|
-
|
|
2273
|
+
// Don't hardcode text color - let it inherit from parent (e.g., column with background color)
|
|
2274
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
|
|
2238
2275
|
}
|
|
2239
|
-
|
|
2276
|
+
// Don't hardcode text color - let it inherit from parent (e.g., column with background color)
|
|
2277
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: content });
|
|
2240
2278
|
};
|
|
2241
2279
|
const Heading = ({ block, children, context }) => {
|
|
2242
2280
|
const attrs = block.attributes || {};
|
|
@@ -2249,7 +2287,10 @@ const Heading = ({ block, children, context }) => {
|
|
|
2249
2287
|
const sizeClass = fontSize || (level === 1 ? 'text-4xl' : level === 2 ? 'text-3xl' : level === 3 ? 'text-2xl' : 'text-xl');
|
|
2250
2288
|
// Get spacing from config with improved defaults
|
|
2251
2289
|
const spacingClass = getHeadingSpacing(context.spacingConfig || context.registry.spacingConfig, level);
|
|
2252
|
-
|
|
2290
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2291
|
+
const textColor = extractTextColor(block, context);
|
|
2292
|
+
const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
|
|
2293
|
+
return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold', textColorClass, sizeClass, textAlign, spacingClass), children: children ?? content }));
|
|
2253
2294
|
};
|
|
2254
2295
|
const Image = ({ block, context }) => {
|
|
2255
2296
|
const imageAttrs = getImageAttributes(block);
|
|
@@ -2270,9 +2311,12 @@ const List = ({ block, children, context }) => {
|
|
|
2270
2311
|
const { ordered } = attrs;
|
|
2271
2312
|
const Tag = ordered ? 'ol' : 'ul';
|
|
2272
2313
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
|
|
2273
|
-
|
|
2314
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2315
|
+
const textColor = extractTextColor(block, context);
|
|
2316
|
+
const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
|
|
2317
|
+
return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
|
|
2274
2318
|
};
|
|
2275
|
-
const ListItem = ({ block, children }) => {
|
|
2319
|
+
const ListItem = ({ block, children, context }) => {
|
|
2276
2320
|
// List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
|
|
2277
2321
|
// We need to extract the content from inside the <li> tag and render it properly
|
|
2278
2322
|
let content = null;
|
|
@@ -2289,12 +2333,15 @@ const ListItem = ({ block, children }) => {
|
|
|
2289
2333
|
}
|
|
2290
2334
|
}
|
|
2291
2335
|
}
|
|
2336
|
+
// Extract text color if specified, otherwise inherit from parent
|
|
2337
|
+
const textColor = extractTextColor(block, context);
|
|
2338
|
+
const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
|
|
2292
2339
|
// If we have both innerHTML content and children (innerBlocks), combine them
|
|
2293
2340
|
if (content && children && React.Children.count(children) > 0) {
|
|
2294
|
-
return (jsxRuntimeExports.jsxs("li", { className:
|
|
2341
|
+
return (jsxRuntimeExports.jsxs("li", { className: textColorClass || undefined, children: [content, children] }));
|
|
2295
2342
|
}
|
|
2296
2343
|
// Return content from innerHTML if available, otherwise use children
|
|
2297
|
-
return jsxRuntimeExports.jsx("li", { className:
|
|
2344
|
+
return jsxRuntimeExports.jsx("li", { className: textColorClass || undefined, children: content || children });
|
|
2298
2345
|
};
|
|
2299
2346
|
const Group = ({ block, children, context }) => {
|
|
2300
2347
|
const attrs = block.attributes || {};
|
|
@@ -2326,15 +2373,17 @@ const Columns = ({ block, children }) => {
|
|
|
2326
2373
|
const alignClass = getAlignmentClasses(align);
|
|
2327
2374
|
return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
|
|
2328
2375
|
};
|
|
2329
|
-
const Column = ({ block, children }) => {
|
|
2376
|
+
const Column = ({ block, children, context }) => {
|
|
2330
2377
|
const attrs = block.attributes || {};
|
|
2331
2378
|
const width = attrs['width'];
|
|
2379
|
+
// Extract background color using color mapper
|
|
2380
|
+
const backgroundColor = extractBackgroundColor(block, context);
|
|
2332
2381
|
// Handle column width (e.g., "50%" becomes flex-basis)
|
|
2333
2382
|
const style = width ? { flexBasis: width } : undefined;
|
|
2334
|
-
return (jsxRuntimeExports.jsx("div", { className:
|
|
2383
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
|
|
2335
2384
|
};
|
|
2336
2385
|
const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
|
|
2337
|
-
const ButtonBlock = ({ block }) => {
|
|
2386
|
+
const ButtonBlock = ({ block, context }) => {
|
|
2338
2387
|
const attrs = block.attributes || {};
|
|
2339
2388
|
let url = attrs['url'];
|
|
2340
2389
|
let text = attrs['text'];
|
|
@@ -2354,10 +2403,20 @@ const ButtonBlock = ({ block }) => {
|
|
|
2354
2403
|
if (!url && !text)
|
|
2355
2404
|
return null;
|
|
2356
2405
|
const buttonText = text || 'Learn more';
|
|
2406
|
+
// Extract background and text colors from button attributes
|
|
2407
|
+
const backgroundColor = extractBackgroundColor(block, context);
|
|
2408
|
+
const textColor = extractTextColor(block, context);
|
|
2409
|
+
// Build button classes
|
|
2410
|
+
// Background: use extracted or default (buttons need a background)
|
|
2411
|
+
const bgClass = backgroundColor || 'bg-primary';
|
|
2412
|
+
// Text color: use extracted if specified, otherwise inherit from parent (don't force default)
|
|
2413
|
+
const textClass = textColor || '';
|
|
2414
|
+
// Hover: adjust based on whether we have a custom background
|
|
2415
|
+
const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
|
|
2357
2416
|
// Handle internal vs external links
|
|
2358
2417
|
const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
|
|
2359
2418
|
const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
|
|
2360
|
-
return (jsxRuntimeExports.jsx("a", { href: url || '#', className:
|
|
2419
|
+
return (jsxRuntimeExports.jsx("a", { href: url || '#', className: buildClassName('inline-flex items-center justify-center rounded-md px-6 py-3 font-medium transition-colors', bgClass, textClass, hoverClass), ...linkProps, children: buttonText }));
|
|
2361
2420
|
};
|
|
2362
2421
|
const Cover = ({ block, children }) => {
|
|
2363
2422
|
const attrs = block.attributes || {};
|
|
@@ -2863,6 +2922,7 @@ exports.extractSpacerHeight = extractSpacerHeight;
|
|
|
2863
2922
|
exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
|
|
2864
2923
|
exports.extractTextAlign = extractTextAlign;
|
|
2865
2924
|
exports.extractTextAlignFromInnerBlocks = extractTextAlignFromInnerBlocks;
|
|
2925
|
+
exports.extractTextColor = extractTextColor;
|
|
2866
2926
|
exports.extractTextFromHTML = extractTextFromHTML;
|
|
2867
2927
|
exports.extractTitle = extractTitle;
|
|
2868
2928
|
exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
|