@marvalt/wparser 0.1.30 → 0.1.31

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 CHANGED
@@ -2059,6 +2059,38 @@ 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, or create a separate text color mapping
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
+ // If no text color in the mapped class, try to infer from the color name
2089
+ // For now, return null and let the app handle it via a separate text color mapper
2090
+ }
2091
+ }
2092
+ return null;
2093
+ }
2062
2094
  /**
2063
2095
  * Extract spacer height from block attributes or innerHTML
2064
2096
  * Returns height in pixels, or null if not found
@@ -2270,7 +2302,11 @@ const List = ({ block, children, context }) => {
2270
2302
  const { ordered } = attrs;
2271
2303
  const Tag = ordered ? 'ol' : 'ul';
2272
2304
  const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
2273
- return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2 text-gray-700', spacing) }, children);
2305
+ // Extract text color if specified
2306
+ const textColor = extractTextColor(block, context);
2307
+ // Default text color if none specified
2308
+ const textColorClass = textColor || 'text-gray-700';
2309
+ return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
2274
2310
  };
2275
2311
  const ListItem = ({ block, children }) => {
2276
2312
  // List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
@@ -2326,15 +2362,17 @@ const Columns = ({ block, children }) => {
2326
2362
  const alignClass = getAlignmentClasses(align);
2327
2363
  return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
2328
2364
  };
2329
- const Column = ({ block, children }) => {
2365
+ const Column = ({ block, children, context }) => {
2330
2366
  const attrs = block.attributes || {};
2331
2367
  const width = attrs['width'];
2368
+ // Extract background color using color mapper
2369
+ const backgroundColor = extractBackgroundColor(block, context);
2332
2370
  // Handle column width (e.g., "50%" becomes flex-basis)
2333
2371
  const style = width ? { flexBasis: width } : undefined;
2334
- return (jsxRuntimeExports.jsx("div", { className: "space-y-4", style: style, children: children }));
2372
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2335
2373
  };
2336
2374
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2337
- const ButtonBlock = ({ block }) => {
2375
+ const ButtonBlock = ({ block, context }) => {
2338
2376
  const attrs = block.attributes || {};
2339
2377
  let url = attrs['url'];
2340
2378
  let text = attrs['text'];
@@ -2354,10 +2392,17 @@ const ButtonBlock = ({ block }) => {
2354
2392
  if (!url && !text)
2355
2393
  return null;
2356
2394
  const buttonText = text || 'Learn more';
2395
+ // Extract background and text colors from button attributes
2396
+ const backgroundColor = extractBackgroundColor(block, context);
2397
+ const textColor = extractTextColor(block, context);
2398
+ // Build button classes - use extracted colors or defaults
2399
+ const bgClass = backgroundColor || 'bg-primary';
2400
+ const textClass = textColor || 'text-primary-foreground';
2401
+ const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
2357
2402
  // Handle internal vs external links
2358
2403
  const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
2359
2404
  const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
2360
- return (jsxRuntimeExports.jsx("a", { href: url || '#', className: "inline-flex items-center justify-center rounded-md bg-primary px-6 py-3 text-primary-foreground font-medium hover:bg-primary/90 transition-colors", ...linkProps, children: buttonText }));
2405
+ 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
2406
  };
2362
2407
  const Cover = ({ block, children }) => {
2363
2408
  const attrs = block.attributes || {};
@@ -2863,6 +2908,7 @@ exports.extractSpacerHeight = extractSpacerHeight;
2863
2908
  exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
2864
2909
  exports.extractTextAlign = extractTextAlign;
2865
2910
  exports.extractTextAlignFromInnerBlocks = extractTextAlignFromInnerBlocks;
2911
+ exports.extractTextColor = extractTextColor;
2866
2912
  exports.extractTextFromHTML = extractTextFromHTML;
2867
2913
  exports.extractTitle = extractTitle;
2868
2914
  exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;