@marvalt/wparser 0.1.29 → 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.
@@ -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,38 @@ 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, or create a separate text color mapping
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
+ // If no text color in the mapped class, try to infer from the color name
2087
+ // For now, return null and let the app handle it via a separate text color mapper
2088
+ }
2089
+ }
2090
+ return null;
2091
+ }
2060
2092
  /**
2061
2093
  * Extract spacer height from block attributes or innerHTML
2062
2094
  * Returns height in pixels, or null if not found
@@ -2268,10 +2300,35 @@ const List = ({ block, children, context }) => {
2268
2300
  const { ordered } = attrs;
2269
2301
  const Tag = ordered ? 'ol' : 'ul';
2270
2302
  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);
2303
+ // Extract text color if specified
2304
+ const textColor = extractTextColor(block, context);
2305
+ // Default text color if none specified
2306
+ const textColorClass = textColor || 'text-gray-700';
2307
+ return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
2272
2308
  };
2273
- const ListItem = ({ children }) => {
2274
- return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: children });
2309
+ const ListItem = ({ block, children }) => {
2310
+ // List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
2311
+ // We need to extract the content from inside the <li> tag and render it properly
2312
+ let content = null;
2313
+ if (block.innerHTML) {
2314
+ // Extract content from innerHTML - remove the outer <li> tags
2315
+ // Pattern: <li>content</li> or <li>content<br>more</li>
2316
+ const liMatch = block.innerHTML.match(/<li[^>]*>(.*?)<\/li>/is);
2317
+ if (liMatch && liMatch[1]) {
2318
+ const innerContent = liMatch[1].trim();
2319
+ if (innerContent) {
2320
+ // Use dangerouslySetInnerHTML to properly render HTML content including <br> tags and entities
2321
+ // This is safe because we're only rendering content from WordPress (trusted source)
2322
+ content = jsxRuntimeExports.jsx("span", { dangerouslySetInnerHTML: { __html: innerContent } });
2323
+ }
2324
+ }
2325
+ }
2326
+ // If we have both innerHTML content and children (innerBlocks), combine them
2327
+ if (content && children && React.Children.count(children) > 0) {
2328
+ return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
2329
+ }
2330
+ // Return content from innerHTML if available, otherwise use children
2331
+ return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
2275
2332
  };
2276
2333
  const Group = ({ block, children, context }) => {
2277
2334
  const attrs = block.attributes || {};
@@ -2303,15 +2360,17 @@ const Columns = ({ block, children }) => {
2303
2360
  const alignClass = getAlignmentClasses(align);
2304
2361
  return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
2305
2362
  };
2306
- const Column = ({ block, children }) => {
2363
+ const Column = ({ block, children, context }) => {
2307
2364
  const attrs = block.attributes || {};
2308
2365
  const width = attrs['width'];
2366
+ // Extract background color using color mapper
2367
+ const backgroundColor = extractBackgroundColor(block, context);
2309
2368
  // Handle column width (e.g., "50%" becomes flex-basis)
2310
2369
  const style = width ? { flexBasis: width } : undefined;
2311
- return (jsxRuntimeExports.jsx("div", { className: "space-y-4", style: style, children: children }));
2370
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2312
2371
  };
2313
2372
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2314
- const ButtonBlock = ({ block }) => {
2373
+ const ButtonBlock = ({ block, context }) => {
2315
2374
  const attrs = block.attributes || {};
2316
2375
  let url = attrs['url'];
2317
2376
  let text = attrs['text'];
@@ -2331,10 +2390,17 @@ const ButtonBlock = ({ block }) => {
2331
2390
  if (!url && !text)
2332
2391
  return null;
2333
2392
  const buttonText = text || 'Learn more';
2393
+ // Extract background and text colors from button attributes
2394
+ const backgroundColor = extractBackgroundColor(block, context);
2395
+ const textColor = extractTextColor(block, context);
2396
+ // Build button classes - use extracted colors or defaults
2397
+ const bgClass = backgroundColor || 'bg-primary';
2398
+ const textClass = textColor || 'text-primary-foreground';
2399
+ const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
2334
2400
  // Handle internal vs external links
2335
2401
  const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
2336
2402
  const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
2337
- 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 }));
2403
+ 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 }));
2338
2404
  };
2339
2405
  const Cover = ({ block, children }) => {
2340
2406
  const attrs = block.attributes || {};
@@ -2812,5 +2878,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
2812
2878
  return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
2813
2879
  };
2814
2880
 
2815
- 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 };
2881
+ 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 };
2816
2882
  //# sourceMappingURL=index.esm.js.map