@marvalt/wparser 0.1.75 → 0.1.76

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
@@ -1801,6 +1801,40 @@ const getCloudflareVariantUrl = (url, options) => {
1801
1801
  return `${base}/${variant}`;
1802
1802
  };
1803
1803
 
1804
+ /**
1805
+ * Normalize WordPress color preset slug (e.g. "var:preset|color|accent-1" -> "accent-1")
1806
+ */
1807
+ function normalizeColorSlug(value) {
1808
+ const prefix = 'var:preset|color|';
1809
+ if (value.startsWith(prefix)) {
1810
+ return value.slice(prefix.length).trim();
1811
+ }
1812
+ return value.trim();
1813
+ }
1814
+ /**
1815
+ * Return WordPress preset class names for a block's textColor and backgroundColor from attributes only.
1816
+ * Used so group/column wrappers output standard WordPress classes (has-{slug}-color, has-text-color, etc.)
1817
+ * and app CSS can target them for cascade. No colorMapper or themePalette needed.
1818
+ *
1819
+ * @param block - WordPress block
1820
+ * @returns Object with optional text and background class strings, or null if none
1821
+ */
1822
+ function getWordPressPresetColorClasses(block) {
1823
+ const attrs = block.attributes || {};
1824
+ const textSlug = attrs['textColor'] ?? attrs['style']?.color?.text;
1825
+ const textValue = typeof textSlug === 'string' ? textSlug : (typeof textSlug === 'object' && textSlug && 'color' in textSlug ? textSlug.color : null);
1826
+ const bgSlug = attrs['backgroundColor'] ?? attrs['background'];
1827
+ const textName = typeof textValue === 'string' && textValue ? normalizeColorSlug(textValue) : null;
1828
+ const bgName = typeof bgSlug === 'string' && bgSlug ? normalizeColorSlug(bgSlug) : null;
1829
+ if (!textName && !bgName)
1830
+ return null;
1831
+ const result = {};
1832
+ if (textName)
1833
+ result.text = `has-${textName}-color has-text-color`;
1834
+ if (bgName)
1835
+ result.background = `has-${bgName}-background-color has-background`;
1836
+ return result;
1837
+ }
1804
1838
  /**
1805
1839
  * Extract background image URL from a block
1806
1840
  * Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
@@ -2731,6 +2765,8 @@ const Group = ({ block, children, context }) => {
2731
2765
  const layout = attrs['layout'];
2732
2766
  // Extract background color using color mapper
2733
2767
  const backgroundColor = extractBackgroundColor(block, context);
2768
+ // WordPress preset classes from attributes so app CSS can cascade (has-accent-1-color etc.)
2769
+ const presetColors = getWordPressPresetColorClasses(block);
2734
2770
  // Determine if this is a section-level group (has alignment) or content-level
2735
2771
  const isSection = align === 'full' || align === 'wide';
2736
2772
  const containerClass = getContainerClasses(align, layout);
@@ -2743,9 +2779,9 @@ const Group = ({ block, children, context }) => {
2743
2779
  const finalContainerClass = layout?.type === 'constrained' && align === 'wide'
2744
2780
  ? 'container'
2745
2781
  : containerClass;
2746
- // Build className with background color if present
2747
- const className = buildClassName(finalContainerClass, spacingClass, backgroundColor // This will be null if no mapping, which is fine
2748
- );
2782
+ // Build className with background color and WordPress preset text/background classes if present
2783
+ const className = buildClassName(finalContainerClass, spacingClass, backgroundColor, // Tailwind from colorMapper when present
2784
+ presetColors?.text, presetColors?.background);
2749
2785
  return (jsxRuntimeExports.jsx("div", { className: className, children: children }));
2750
2786
  };
2751
2787
  const Columns = ({ block, children }) => {
@@ -2759,10 +2795,12 @@ const Column = ({ block, children, context }) => {
2759
2795
  const width = attrs['width'];
2760
2796
  // Extract background color using color mapper (Tailwind class)
2761
2797
  const backgroundColor = extractBackgroundColor(block, context);
2798
+ // WordPress preset classes from attributes for cascade
2799
+ const presetColors = getWordPressPresetColorClasses(block);
2762
2800
  // Inline background when no class (custom color or theme slug via themePalette)
2763
2801
  const backgroundStyle = getBackgroundInlineStyle(block, context);
2764
2802
  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 }));
2803
+ return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor, presetColors?.text, presetColors?.background), style: Object.keys(style).length ? style : undefined, children: children }));
2766
2804
  };
2767
2805
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2768
2806
  const ButtonBlock = ({ block, context }) => {
@@ -3399,6 +3437,7 @@ exports.getImageAttributes = getImageAttributes;
3399
3437
  exports.getImageUrl = getImageUrl;
3400
3438
  exports.getSectionSpacingClasses = getSectionSpacingClasses;
3401
3439
  exports.getTextAlignClasses = getTextAlignClasses;
3440
+ exports.getWordPressPresetColorClasses = getWordPressPresetColorClasses;
3402
3441
  exports.isCloudflareImageUrl = isCloudflareImageUrl;
3403
3442
  exports.isValidCloudflareUrl = isValidCloudflareUrl;
3404
3443
  exports.matchesPattern = matchesPattern;