@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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClH,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClH,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
package/dist/index.esm.js CHANGED
@@ -2057,6 +2057,42 @@ function extractBackgroundColor(block, context) {
2057
2057
  // Fallback: return null (no background applied)
2058
2058
  return null;
2059
2059
  }
2060
+ /**
2061
+ * Extract and map text color from block attributes
2062
+ * Uses colorMapper from context to convert WordPress theme colors to app CSS classes
2063
+ *
2064
+ * @param block - WordPress block to extract text color from
2065
+ * @param context - Render context containing optional colorMapper
2066
+ * @returns CSS class string (e.g., 'text-white') or null if no mapping
2067
+ */
2068
+ function extractTextColor(block, context) {
2069
+ const attrs = block.attributes || {};
2070
+ const wpColorName = attrs['textColor'] || attrs['text'];
2071
+ if (!wpColorName || typeof wpColorName !== 'string') {
2072
+ return null;
2073
+ }
2074
+ // Use colorMapper from context if available
2075
+ // Note: colorMapper might return combined classes like "bg-gray-900 text-white"
2076
+ // We'll extract just the text color part
2077
+ if (context.colorMapper) {
2078
+ const mapped = context.colorMapper(wpColorName);
2079
+ if (mapped) {
2080
+ // If the mapped class includes text color (e.g., "bg-gray-900 text-white"),
2081
+ // extract just the text color part
2082
+ const textColorMatch = mapped.match(/\btext-\S+/);
2083
+ if (textColorMatch) {
2084
+ return textColorMatch[0];
2085
+ }
2086
+ }
2087
+ }
2088
+ // Special handling for common WordPress color names when used as text color
2089
+ // These are common text color mappings that might not be in the colorMapper
2090
+ const textColorMap = {
2091
+ 'contrast': 'text-gray-900', // Contrast text is typically dark/black
2092
+ 'base': 'text-white', // Base text on dark backgrounds
2093
+ };
2094
+ return textColorMap[wpColorName] || null;
2095
+ }
2060
2096
  /**
2061
2097
  * Extract spacer height from block attributes or innerHTML
2062
2098
  * Returns height in pixels, or null if not found
@@ -2232,9 +2268,11 @@ const Paragraph = ({ block, context }) => {
2232
2268
  // Render block-level content without <p> wrapper, but add spacing wrapper
2233
2269
  return jsxRuntimeExports.jsx("div", { className: spacing, children: parts });
2234
2270
  }
2235
- return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', spacing, textAlign), children: parts });
2271
+ // Don't hardcode text color - let it inherit from parent (e.g., column with background color)
2272
+ return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: parts });
2236
2273
  }
2237
- return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', spacing, textAlign), children: content });
2274
+ // Don't hardcode text color - let it inherit from parent (e.g., column with background color)
2275
+ return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign), children: content });
2238
2276
  };
2239
2277
  const Heading = ({ block, children, context }) => {
2240
2278
  const attrs = block.attributes || {};
@@ -2247,7 +2285,10 @@ const Heading = ({ block, children, context }) => {
2247
2285
  const sizeClass = fontSize || (level === 1 ? 'text-4xl' : level === 2 ? 'text-3xl' : level === 3 ? 'text-2xl' : 'text-xl');
2248
2286
  // Get spacing from config with improved defaults
2249
2287
  const spacingClass = getHeadingSpacing(context.spacingConfig || context.registry.spacingConfig, level);
2250
- return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold text-gray-900', sizeClass, textAlign, spacingClass), children: children ?? content }));
2288
+ // Extract text color if specified, otherwise inherit from parent
2289
+ const textColor = extractTextColor(block, context);
2290
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2291
+ return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold', textColorClass, sizeClass, textAlign, spacingClass), children: children ?? content }));
2251
2292
  };
2252
2293
  const Image = ({ block, context }) => {
2253
2294
  const imageAttrs = getImageAttributes(block);
@@ -2268,9 +2309,12 @@ const List = ({ block, children, context }) => {
2268
2309
  const { ordered } = attrs;
2269
2310
  const Tag = ordered ? 'ol' : 'ul';
2270
2311
  const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
2271
- return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2 text-gray-700', spacing) }, children);
2312
+ // Extract text color if specified, otherwise inherit from parent
2313
+ const textColor = extractTextColor(block, context);
2314
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2315
+ return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
2272
2316
  };
2273
- const ListItem = ({ block, children }) => {
2317
+ const ListItem = ({ block, children, context }) => {
2274
2318
  // List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
2275
2319
  // We need to extract the content from inside the <li> tag and render it properly
2276
2320
  let content = null;
@@ -2287,12 +2331,15 @@ const ListItem = ({ block, children }) => {
2287
2331
  }
2288
2332
  }
2289
2333
  }
2334
+ // Extract text color if specified, otherwise inherit from parent
2335
+ const textColor = extractTextColor(block, context);
2336
+ const textColorClass = textColor || ''; // Don't hardcode - let it inherit from parent
2290
2337
  // If we have both innerHTML content and children (innerBlocks), combine them
2291
2338
  if (content && children && React.Children.count(children) > 0) {
2292
- return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
2339
+ return (jsxRuntimeExports.jsxs("li", { className: textColorClass || undefined, children: [content, children] }));
2293
2340
  }
2294
2341
  // Return content from innerHTML if available, otherwise use children
2295
- return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
2342
+ return jsxRuntimeExports.jsx("li", { className: textColorClass || undefined, children: content || children });
2296
2343
  };
2297
2344
  const Group = ({ block, children, context }) => {
2298
2345
  const attrs = block.attributes || {};
@@ -2324,15 +2371,17 @@ const Columns = ({ block, children }) => {
2324
2371
  const alignClass = getAlignmentClasses(align);
2325
2372
  return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
2326
2373
  };
2327
- const Column = ({ block, children }) => {
2374
+ const Column = ({ block, children, context }) => {
2328
2375
  const attrs = block.attributes || {};
2329
2376
  const width = attrs['width'];
2377
+ // Extract background color using color mapper
2378
+ const backgroundColor = extractBackgroundColor(block, context);
2330
2379
  // Handle column width (e.g., "50%" becomes flex-basis)
2331
2380
  const style = width ? { flexBasis: width } : undefined;
2332
- return (jsxRuntimeExports.jsx("div", { className: "space-y-4", style: style, children: children }));
2381
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2333
2382
  };
2334
2383
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2335
- const ButtonBlock = ({ block }) => {
2384
+ const ButtonBlock = ({ block, context }) => {
2336
2385
  const attrs = block.attributes || {};
2337
2386
  let url = attrs['url'];
2338
2387
  let text = attrs['text'];
@@ -2352,10 +2401,20 @@ const ButtonBlock = ({ block }) => {
2352
2401
  if (!url && !text)
2353
2402
  return null;
2354
2403
  const buttonText = text || 'Learn more';
2404
+ // Extract background and text colors from button attributes
2405
+ const backgroundColor = extractBackgroundColor(block, context);
2406
+ const textColor = extractTextColor(block, context);
2407
+ // Build button classes
2408
+ // Background: use extracted or default (buttons need a background)
2409
+ const bgClass = backgroundColor || 'bg-primary';
2410
+ // Text color: use extracted if specified, otherwise inherit from parent (don't force default)
2411
+ const textClass = textColor || '';
2412
+ // Hover: adjust based on whether we have a custom background
2413
+ const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
2355
2414
  // Handle internal vs external links
2356
2415
  const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
2357
2416
  const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
2358
- 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 }));
2417
+ 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 }));
2359
2418
  };
2360
2419
  const Cover = ({ block, children }) => {
2361
2420
  const attrs = block.attributes || {};
@@ -2833,5 +2892,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
2833
2892
  return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
2834
2893
  };
2835
2894
 
2836
- export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
2895
+ export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextColor, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
2837
2896
  //# sourceMappingURL=index.esm.js.map