@marvalt/wparser 0.1.31 → 0.1.33

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
@@ -2073,9 +2073,19 @@ function extractTextColor(block, context) {
2073
2073
  if (!wpColorName || typeof wpColorName !== 'string') {
2074
2074
  return null;
2075
2075
  }
2076
+ // Special handling for common WordPress color names when used as text color
2077
+ // These mappings take precedence because text color semantics differ from background color
2078
+ const textColorMap = {
2079
+ 'contrast': 'text-gray-900', // Contrast text is typically dark/black (opposite of contrast background)
2080
+ 'base': 'text-white', // Base text on dark backgrounds
2081
+ };
2082
+ // Check special text color mappings first
2083
+ if (textColorMap[wpColorName]) {
2084
+ return textColorMap[wpColorName];
2085
+ }
2076
2086
  // Use colorMapper from context if available
2077
2087
  // 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
2088
+ // We'll extract just the text color part
2079
2089
  if (context.colorMapper) {
2080
2090
  const mapped = context.colorMapper(wpColorName);
2081
2091
  if (mapped) {
@@ -2085,8 +2095,6 @@ function extractTextColor(block, context) {
2085
2095
  if (textColorMatch) {
2086
2096
  return textColorMatch[0];
2087
2097
  }
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
2098
  }
2091
2099
  }
2092
2100
  return null;
@@ -2266,9 +2274,11 @@ const Paragraph = ({ block, context }) => {
2266
2274
  // Render block-level content without <p> wrapper, but add spacing wrapper
2267
2275
  return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
2268
2276
  }
2269
- return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', spacing, textAlign), children: parts });
2277
+ // Don't hardcode text color - let it inherit from parent (e.g., column with background color)
2278
+ return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
2270
2279
  }
2271
- return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', spacing, textAlign), children: content });
2280
+ // Don't hardcode text color - let it inherit from parent (e.g., column with background color)
2281
+ return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: content });
2272
2282
  };
2273
2283
  const Heading = ({ block, children, context }) => {
2274
2284
  const attrs = block.attributes || {};
@@ -2281,7 +2291,10 @@ const Heading = ({ block, children, context }) => {
2281
2291
  const sizeClass = fontSize || (level === 1 ? 'text-4xl' : level === 2 ? 'text-3xl' : level === 3 ? 'text-2xl' : 'text-xl');
2282
2292
  // Get spacing from config with improved defaults
2283
2293
  const spacingClass = getHeadingSpacing(context.spacingConfig || context.registry.spacingConfig, level);
2284
- return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold text-gray-900', sizeClass, textAlign, spacingClass), children: children ?? content }));
2294
+ // Extract text color if specified, otherwise inherit from parent
2295
+ const textColor = extractTextColor(block, context);
2296
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2297
+ return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold', textColorClass, sizeClass, textAlign, spacingClass), children: children ?? content }));
2285
2298
  };
2286
2299
  const Image = ({ block, context }) => {
2287
2300
  const imageAttrs = getImageAttributes(block);
@@ -2302,13 +2315,12 @@ const List = ({ block, children, context }) => {
2302
2315
  const { ordered } = attrs;
2303
2316
  const Tag = ordered ? 'ol' : 'ul';
2304
2317
  const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
2305
- // Extract text color if specified
2318
+ // Extract text color if specified, otherwise inherit from parent
2306
2319
  const textColor = extractTextColor(block, context);
2307
- // Default text color if none specified
2308
- const textColorClass = textColor || 'text-gray-700';
2320
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2309
2321
  return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
2310
2322
  };
2311
- const ListItem = ({ block, children }) => {
2323
+ const ListItem = ({ block, children, context }) => {
2312
2324
  // List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
2313
2325
  // We need to extract the content from inside the <li> tag and render it properly
2314
2326
  let content = null;
@@ -2325,12 +2337,15 @@ const ListItem = ({ block, children }) => {
2325
2337
  }
2326
2338
  }
2327
2339
  }
2340
+ // Extract text color if specified, otherwise inherit from parent
2341
+ const textColor = extractTextColor(block, context);
2342
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2328
2343
  // If we have both innerHTML content and children (innerBlocks), combine them
2329
2344
  if (content && children && React.Children.count(children) > 0) {
2330
- return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
2345
+ return (jsxRuntimeExports.jsxs("li", { className: textColorClass || undefined, children: [content, children] }));
2331
2346
  }
2332
2347
  // Return content from innerHTML if available, otherwise use children
2333
- return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
2348
+ return jsxRuntimeExports.jsx("li", { className: textColorClass || undefined, children: content || children });
2334
2349
  };
2335
2350
  const Group = ({ block, children, context }) => {
2336
2351
  const attrs = block.attributes || {};
@@ -2395,9 +2410,12 @@ const ButtonBlock = ({ block, context }) => {
2395
2410
  // Extract background and text colors from button attributes
2396
2411
  const backgroundColor = extractBackgroundColor(block, context);
2397
2412
  const textColor = extractTextColor(block, context);
2398
- // Build button classes - use extracted colors or defaults
2413
+ // Build button classes
2414
+ // Background: use extracted or default (buttons need a background)
2399
2415
  const bgClass = backgroundColor || 'bg-primary';
2400
- const textClass = textColor || 'text-primary-foreground';
2416
+ // Text color: use extracted if specified, otherwise inherit from parent (don't force default)
2417
+ const textClass = textColor || '';
2418
+ // Hover: adjust based on whether we have a custom background
2401
2419
  const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
2402
2420
  // Handle internal vs external links
2403
2421
  const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));