@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.cjs CHANGED
@@ -1398,6 +1398,7 @@ function renderBlock(block, registry, key, options, page) {
1398
1398
  page,
1399
1399
  colorMapper: registry.colorMapper,
1400
1400
  spacingConfig: registry.spacingConfig,
1401
+ themePalette: registry.themePalette,
1401
1402
  }
1402
1403
  });
1403
1404
  if (options?.debugWrappers) {
@@ -2112,10 +2113,14 @@ function extractTextAlignFromInnerBlocks(block) {
2112
2113
  const innerBlocks = block.innerBlocks || [];
2113
2114
  // First, recursively search for heading or paragraph blocks with textAlign
2114
2115
  // (These take priority over group justifyContent)
2116
+ // Note: heading blocks use 'textAlign', paragraph blocks use 'align'
2115
2117
  for (const innerBlock of innerBlocks) {
2116
2118
  if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
2117
2119
  const attrs = innerBlock.attributes || {};
2118
- const textAlign = attrs['textAlign'];
2120
+ // Heading blocks use 'textAlign', paragraph blocks use 'align'
2121
+ const textAlign = innerBlock.name === 'core/heading'
2122
+ ? attrs['textAlign']
2123
+ : attrs['align'] || attrs['textAlign']; // Check both for paragraph (fallback)
2119
2124
  if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
2120
2125
  return textAlign;
2121
2126
  }
@@ -2126,6 +2131,7 @@ function extractTextAlignFromInnerBlocks(block) {
2126
2131
  return nestedAlign;
2127
2132
  }
2128
2133
  // Only check group blocks if no heading/paragraph alignment found
2134
+ // Recursively search group blocks for justifyContent
2129
2135
  for (const innerBlock of innerBlocks) {
2130
2136
  if (innerBlock.name === 'core/group') {
2131
2137
  const attrs = innerBlock.attributes || {};
@@ -2137,6 +2143,10 @@ function extractTextAlignFromInnerBlocks(block) {
2137
2143
  return 'center';
2138
2144
  if (justifyContent === 'right')
2139
2145
  return 'right';
2146
+ // Also recursively check nested blocks within the group
2147
+ const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
2148
+ if (nestedAlign)
2149
+ return nestedAlign;
2140
2150
  }
2141
2151
  }
2142
2152
  return null;
@@ -2268,6 +2278,27 @@ function extractBackgroundColorValue(block, context) {
2268
2278
  }
2269
2279
  return null;
2270
2280
  }
2281
+ /**
2282
+ * Return inline style for background color when no Tailwind class is available.
2283
+ * Supports WordPress custom color (style.color.background) and theme slug (themePalette).
2284
+ *
2285
+ * @param block - WordPress block
2286
+ * @param context - Render context with optional themePalette
2287
+ * @returns React.CSSProperties with backgroundColor or null
2288
+ */
2289
+ function getBackgroundInlineStyle(block, context) {
2290
+ const attrs = block.attributes || {};
2291
+ const styleAttr = attrs['style'];
2292
+ const customBg = styleAttr?.color?.background;
2293
+ if (typeof customBg === 'string' && customBg.trim()) {
2294
+ return { backgroundColor: customBg.trim() };
2295
+ }
2296
+ const wpColorName = attrs['backgroundColor'] || attrs['background'];
2297
+ if (typeof wpColorName === 'string' && context.themePalette?.[wpColorName]) {
2298
+ return { backgroundColor: context.themePalette[wpColorName] };
2299
+ }
2300
+ return null;
2301
+ }
2271
2302
  /**
2272
2303
  * Extract gradient background from block attributes
2273
2304
  * WordPress stores gradients in attributes.style.color.gradient
@@ -2726,11 +2757,12 @@ const Columns = ({ block, children }) => {
2726
2757
  const Column = ({ block, children, context }) => {
2727
2758
  const attrs = block.attributes || {};
2728
2759
  const width = attrs['width'];
2729
- // Extract background color using color mapper
2760
+ // Extract background color using color mapper (Tailwind class)
2730
2761
  const backgroundColor = extractBackgroundColor(block, context);
2731
- // Handle column width (e.g., "50%" becomes flex-basis)
2732
- const style = width ? { flexBasis: width } : undefined;
2733
- return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2762
+ // Inline background when no class (custom color or theme slug via themePalette)
2763
+ const backgroundStyle = getBackgroundInlineStyle(block, context);
2764
+ const style = { ...(width ? { flexBasis: width } : {}), ...(backgroundStyle || {}) };
2765
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: Object.keys(style).length ? style : undefined, children: children }));
2734
2766
  };
2735
2767
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2736
2768
  const ButtonBlock = ({ block, context }) => {
@@ -3357,6 +3389,7 @@ exports.extractVideoIframeFromInnerBlocks = extractVideoIframeFromInnerBlocks;
3357
3389
  exports.findMatchingMapping = findMatchingMapping;
3358
3390
  exports.findShortcodes = findShortcodes;
3359
3391
  exports.getAlignmentClasses = getAlignmentClasses;
3392
+ exports.getBackgroundInlineStyle = getBackgroundInlineStyle;
3360
3393
  exports.getBlockTextContent = getBlockTextContent;
3361
3394
  exports.getCloudflareVariantUrl = getCloudflareVariantUrl;
3362
3395
  exports.getContainerClasses = getContainerClasses;