@marvalt/wparser 0.1.72 → 0.1.75

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.d.ts CHANGED
@@ -51,6 +51,8 @@ interface RenderContext {
51
51
  page?: WordPressPageMinimal;
52
52
  colorMapper?: ColorMapper;
53
53
  spacingConfig?: SpacingConfig;
54
+ /** WordPress theme color slug to hex/rgb for resolving background/text colors when colorMapper has no mapping */
55
+ themePalette?: Record<string, string>;
54
56
  }
55
57
  interface BlockRendererProps {
56
58
  block: WordPressBlock;
@@ -73,6 +75,8 @@ interface ComponentRegistry {
73
75
  colorMapper?: ColorMapper;
74
76
  /** Optional spacing configuration for customizing element spacing */
75
77
  spacingConfig?: SpacingConfig;
78
+ /** Optional WordPress theme color slug to hex/rgb for block background/text resolution */
79
+ themePalette?: Record<string, string>;
76
80
  }
77
81
  /**
78
82
  * Pattern matching for blocks - allows matching blocks by name and attributes
@@ -510,6 +514,15 @@ declare function extractBackgroundColor(block: WordPressBlock, context: RenderCo
510
514
  declare function extractBackgroundColorValue(block: WordPressBlock, context: RenderContext & {
511
515
  themePalette?: Record<string, string>;
512
516
  }): string | null;
517
+ /**
518
+ * Return inline style for background color when no Tailwind class is available.
519
+ * Supports WordPress custom color (style.color.background) and theme slug (themePalette).
520
+ *
521
+ * @param block - WordPress block
522
+ * @param context - Render context with optional themePalette
523
+ * @returns React.CSSProperties with backgroundColor or null
524
+ */
525
+ declare function getBackgroundInlineStyle(block: WordPressBlock, context: RenderContext): React$1.CSSProperties | null;
513
526
  /**
514
527
  * Extract gradient background from block attributes
515
528
  * WordPress stores gradients in attributes.style.color.gradient
@@ -585,5 +598,5 @@ interface SectionWrapperProps {
585
598
  */
586
599
  declare const SectionWrapper: React$1.FC<SectionWrapperProps>;
587
600
 
588
- export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundColorValue, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractGradientBackground, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextColor, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractTitleTextColorFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
601
+ export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundColorValue, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractGradientBackground, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextColor, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractTitleTextColorFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBackgroundInlineStyle, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
589
602
  export type { AuthMode, BlockPattern, BlockRenderer, BlockRendererProps, CloudflareVariantOptions, ColorMapper, ComponentMapping, ComponentRegistry, EnhancedRegistry, ImageConversionOptions, ParseOptions, ParsedShortcode, RenderContext, RenderOptions, SectionWrapperProps, ShortcodeAttributes, ShortcodeRenderer, SpacingConfig, WPContentProps, WPNode, WPPageProps, WordPressBlock, WordPressEmbedded, WordPressFeaturedMedia, WordPressPageMinimal, WordPressTitleField };
@@ -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,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACtI,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,oCAAoC,EACpC,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,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,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACtI,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,oCAAoC,EACpC,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1396,6 +1396,7 @@ function renderBlock(block, registry, key, options, page) {
1396
1396
  page,
1397
1397
  colorMapper: registry.colorMapper,
1398
1398
  spacingConfig: registry.spacingConfig,
1399
+ themePalette: registry.themePalette,
1399
1400
  }
1400
1401
  });
1401
1402
  if (options?.debugWrappers) {
@@ -2110,10 +2111,14 @@ function extractTextAlignFromInnerBlocks(block) {
2110
2111
  const innerBlocks = block.innerBlocks || [];
2111
2112
  // First, recursively search for heading or paragraph blocks with textAlign
2112
2113
  // (These take priority over group justifyContent)
2114
+ // Note: heading blocks use 'textAlign', paragraph blocks use 'align'
2113
2115
  for (const innerBlock of innerBlocks) {
2114
2116
  if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
2115
2117
  const attrs = innerBlock.attributes || {};
2116
- const textAlign = attrs['textAlign'];
2118
+ // Heading blocks use 'textAlign', paragraph blocks use 'align'
2119
+ const textAlign = innerBlock.name === 'core/heading'
2120
+ ? attrs['textAlign']
2121
+ : attrs['align'] || attrs['textAlign']; // Check both for paragraph (fallback)
2117
2122
  if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
2118
2123
  return textAlign;
2119
2124
  }
@@ -2124,6 +2129,7 @@ function extractTextAlignFromInnerBlocks(block) {
2124
2129
  return nestedAlign;
2125
2130
  }
2126
2131
  // Only check group blocks if no heading/paragraph alignment found
2132
+ // Recursively search group blocks for justifyContent
2127
2133
  for (const innerBlock of innerBlocks) {
2128
2134
  if (innerBlock.name === 'core/group') {
2129
2135
  const attrs = innerBlock.attributes || {};
@@ -2135,6 +2141,10 @@ function extractTextAlignFromInnerBlocks(block) {
2135
2141
  return 'center';
2136
2142
  if (justifyContent === 'right')
2137
2143
  return 'right';
2144
+ // Also recursively check nested blocks within the group
2145
+ const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
2146
+ if (nestedAlign)
2147
+ return nestedAlign;
2138
2148
  }
2139
2149
  }
2140
2150
  return null;
@@ -2266,6 +2276,27 @@ function extractBackgroundColorValue(block, context) {
2266
2276
  }
2267
2277
  return null;
2268
2278
  }
2279
+ /**
2280
+ * Return inline style for background color when no Tailwind class is available.
2281
+ * Supports WordPress custom color (style.color.background) and theme slug (themePalette).
2282
+ *
2283
+ * @param block - WordPress block
2284
+ * @param context - Render context with optional themePalette
2285
+ * @returns React.CSSProperties with backgroundColor or null
2286
+ */
2287
+ function getBackgroundInlineStyle(block, context) {
2288
+ const attrs = block.attributes || {};
2289
+ const styleAttr = attrs['style'];
2290
+ const customBg = styleAttr?.color?.background;
2291
+ if (typeof customBg === 'string' && customBg.trim()) {
2292
+ return { backgroundColor: customBg.trim() };
2293
+ }
2294
+ const wpColorName = attrs['backgroundColor'] || attrs['background'];
2295
+ if (typeof wpColorName === 'string' && context.themePalette?.[wpColorName]) {
2296
+ return { backgroundColor: context.themePalette[wpColorName] };
2297
+ }
2298
+ return null;
2299
+ }
2269
2300
  /**
2270
2301
  * Extract gradient background from block attributes
2271
2302
  * WordPress stores gradients in attributes.style.color.gradient
@@ -2724,11 +2755,12 @@ const Columns = ({ block, children }) => {
2724
2755
  const Column = ({ block, children, context }) => {
2725
2756
  const attrs = block.attributes || {};
2726
2757
  const width = attrs['width'];
2727
- // Extract background color using color mapper
2758
+ // Extract background color using color mapper (Tailwind class)
2728
2759
  const backgroundColor = extractBackgroundColor(block, context);
2729
- // Handle column width (e.g., "50%" becomes flex-basis)
2730
- const style = width ? { flexBasis: width } : undefined;
2731
- return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2760
+ // Inline background when no class (custom color or theme slug via themePalette)
2761
+ const backgroundStyle = getBackgroundInlineStyle(block, context);
2762
+ const style = { ...(width ? { flexBasis: width } : {}), ...(backgroundStyle || {}) };
2763
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: Object.keys(style).length ? style : undefined, children: children }));
2732
2764
  };
2733
2765
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2734
2766
  const ButtonBlock = ({ block, context }) => {
@@ -3315,5 +3347,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
3315
3347
  return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
3316
3348
  };
3317
3349
 
3318
- export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundColorValue, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractGradientBackground, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextColor, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractTitleTextColorFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
3350
+ export { SectionWrapper, WPContent, WPErrorBoundary, WPPage, buildClassName, convertImageToCloudflareVariant, convertImageUrl, convertImageUrls, createDefaultRegistry, createEnhancedRegistry, extractAlignment, extractBackgroundColor, extractBackgroundColorValue, extractBackgroundImage, extractButtonsFromInnerBlocks, extractContent, extractDimRatio, extractFontSize, extractGradientBackground, extractHeadingLevel, extractImageAttributes, extractImageUrl, extractImageUrlWithFallback, extractMediaPosition, extractMinHeight, extractOverlayColor, extractSpacerHeight, extractSubtitleFromInnerBlocks, extractTextAlign, extractTextAlignFromInnerBlocks, extractTextColor, extractTextFromHTML, extractTitle, extractTitleFromInnerBlocks, extractTitleTextColorFromInnerBlocks, extractVerticalAlignment, extractVideoIframeFromInnerBlocks, findMatchingMapping, findShortcodes, getAlignmentClasses, getBackgroundInlineStyle, getBlockTextContent, getCloudflareVariantUrl, getContainerClasses, getContentSpacingClasses, getFontSizeClasses, getImageAttributes, getImageUrl, getSectionSpacingClasses, getTextAlignClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
3319
3351
  //# sourceMappingURL=index.esm.js.map