@marvalt/wparser 0.1.73 → 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.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
@@ -351,6 +355,18 @@ declare function matchesPattern(block: WordPressBlock, pattern: BlockPattern): b
351
355
  */
352
356
  declare function findMatchingMapping(block: WordPressBlock, mappings: ComponentMapping[]): ComponentMapping | null;
353
357
 
358
+ /**
359
+ * Return WordPress preset class names for a block's textColor and backgroundColor from attributes only.
360
+ * Used so group/column wrappers output standard WordPress classes (has-{slug}-color, has-text-color, etc.)
361
+ * and app CSS can target them for cascade. No colorMapper or themePalette needed.
362
+ *
363
+ * @param block - WordPress block
364
+ * @returns Object with optional text and background class strings, or null if none
365
+ */
366
+ declare function getWordPressPresetColorClasses(block: WordPressBlock): {
367
+ text?: string;
368
+ background?: string;
369
+ } | null;
354
370
  /**
355
371
  * Extract background image URL from a block
356
372
  * Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
@@ -510,6 +526,15 @@ declare function extractBackgroundColor(block: WordPressBlock, context: RenderCo
510
526
  declare function extractBackgroundColorValue(block: WordPressBlock, context: RenderContext & {
511
527
  themePalette?: Record<string, string>;
512
528
  }): string | null;
529
+ /**
530
+ * Return inline style for background color when no Tailwind class is available.
531
+ * Supports WordPress custom color (style.color.background) and theme slug (themePalette).
532
+ *
533
+ * @param block - WordPress block
534
+ * @param context - Render context with optional themePalette
535
+ * @returns React.CSSProperties with backgroundColor or null
536
+ */
537
+ declare function getBackgroundInlineStyle(block: WordPressBlock, context: RenderContext): React$1.CSSProperties | null;
513
538
  /**
514
539
  * Extract gradient background from block attributes
515
540
  * WordPress stores gradients in attributes.style.color.gradient
@@ -585,5 +610,5 @@ interface SectionWrapperProps {
585
610
  */
586
611
  declare const SectionWrapper: React$1.FC<SectionWrapperProps>;
587
612
 
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 };
613
+ 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, getWordPressPresetColorClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
589
614
  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;AAC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/B,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,8BAA8B,GAC/B,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) {
@@ -1798,6 +1799,40 @@ const getCloudflareVariantUrl = (url, options) => {
1798
1799
  return `${base}/${variant}`;
1799
1800
  };
1800
1801
 
1802
+ /**
1803
+ * Normalize WordPress color preset slug (e.g. "var:preset|color|accent-1" -> "accent-1")
1804
+ */
1805
+ function normalizeColorSlug(value) {
1806
+ const prefix = 'var:preset|color|';
1807
+ if (value.startsWith(prefix)) {
1808
+ return value.slice(prefix.length).trim();
1809
+ }
1810
+ return value.trim();
1811
+ }
1812
+ /**
1813
+ * Return WordPress preset class names for a block's textColor and backgroundColor from attributes only.
1814
+ * Used so group/column wrappers output standard WordPress classes (has-{slug}-color, has-text-color, etc.)
1815
+ * and app CSS can target them for cascade. No colorMapper or themePalette needed.
1816
+ *
1817
+ * @param block - WordPress block
1818
+ * @returns Object with optional text and background class strings, or null if none
1819
+ */
1820
+ function getWordPressPresetColorClasses(block) {
1821
+ const attrs = block.attributes || {};
1822
+ const textSlug = attrs['textColor'] ?? attrs['style']?.color?.text;
1823
+ const textValue = typeof textSlug === 'string' ? textSlug : (typeof textSlug === 'object' && textSlug && 'color' in textSlug ? textSlug.color : null);
1824
+ const bgSlug = attrs['backgroundColor'] ?? attrs['background'];
1825
+ const textName = typeof textValue === 'string' && textValue ? normalizeColorSlug(textValue) : null;
1826
+ const bgName = typeof bgSlug === 'string' && bgSlug ? normalizeColorSlug(bgSlug) : null;
1827
+ if (!textName && !bgName)
1828
+ return null;
1829
+ const result = {};
1830
+ if (textName)
1831
+ result.text = `has-${textName}-color has-text-color`;
1832
+ if (bgName)
1833
+ result.background = `has-${bgName}-background-color has-background`;
1834
+ return result;
1835
+ }
1801
1836
  /**
1802
1837
  * Extract background image URL from a block
1803
1838
  * Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
@@ -2275,6 +2310,27 @@ function extractBackgroundColorValue(block, context) {
2275
2310
  }
2276
2311
  return null;
2277
2312
  }
2313
+ /**
2314
+ * Return inline style for background color when no Tailwind class is available.
2315
+ * Supports WordPress custom color (style.color.background) and theme slug (themePalette).
2316
+ *
2317
+ * @param block - WordPress block
2318
+ * @param context - Render context with optional themePalette
2319
+ * @returns React.CSSProperties with backgroundColor or null
2320
+ */
2321
+ function getBackgroundInlineStyle(block, context) {
2322
+ const attrs = block.attributes || {};
2323
+ const styleAttr = attrs['style'];
2324
+ const customBg = styleAttr?.color?.background;
2325
+ if (typeof customBg === 'string' && customBg.trim()) {
2326
+ return { backgroundColor: customBg.trim() };
2327
+ }
2328
+ const wpColorName = attrs['backgroundColor'] || attrs['background'];
2329
+ if (typeof wpColorName === 'string' && context.themePalette?.[wpColorName]) {
2330
+ return { backgroundColor: context.themePalette[wpColorName] };
2331
+ }
2332
+ return null;
2333
+ }
2278
2334
  /**
2279
2335
  * Extract gradient background from block attributes
2280
2336
  * WordPress stores gradients in attributes.style.color.gradient
@@ -2707,6 +2763,8 @@ const Group = ({ block, children, context }) => {
2707
2763
  const layout = attrs['layout'];
2708
2764
  // Extract background color using color mapper
2709
2765
  const backgroundColor = extractBackgroundColor(block, context);
2766
+ // WordPress preset classes from attributes so app CSS can cascade (has-accent-1-color etc.)
2767
+ const presetColors = getWordPressPresetColorClasses(block);
2710
2768
  // Determine if this is a section-level group (has alignment) or content-level
2711
2769
  const isSection = align === 'full' || align === 'wide';
2712
2770
  const containerClass = getContainerClasses(align, layout);
@@ -2719,9 +2777,9 @@ const Group = ({ block, children, context }) => {
2719
2777
  const finalContainerClass = layout?.type === 'constrained' && align === 'wide'
2720
2778
  ? 'container'
2721
2779
  : containerClass;
2722
- // Build className with background color if present
2723
- const className = buildClassName(finalContainerClass, spacingClass, backgroundColor // This will be null if no mapping, which is fine
2724
- );
2780
+ // Build className with background color and WordPress preset text/background classes if present
2781
+ const className = buildClassName(finalContainerClass, spacingClass, backgroundColor, // Tailwind from colorMapper when present
2782
+ presetColors?.text, presetColors?.background);
2725
2783
  return (jsxRuntimeExports.jsx("div", { className: className, children: children }));
2726
2784
  };
2727
2785
  const Columns = ({ block, children }) => {
@@ -2733,11 +2791,14 @@ const Columns = ({ block, children }) => {
2733
2791
  const Column = ({ block, children, context }) => {
2734
2792
  const attrs = block.attributes || {};
2735
2793
  const width = attrs['width'];
2736
- // Extract background color using color mapper
2794
+ // Extract background color using color mapper (Tailwind class)
2737
2795
  const backgroundColor = extractBackgroundColor(block, context);
2738
- // Handle column width (e.g., "50%" becomes flex-basis)
2739
- const style = width ? { flexBasis: width } : undefined;
2740
- return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
2796
+ // WordPress preset classes from attributes for cascade
2797
+ const presetColors = getWordPressPresetColorClasses(block);
2798
+ // Inline background when no class (custom color or theme slug via themePalette)
2799
+ const backgroundStyle = getBackgroundInlineStyle(block, context);
2800
+ const style = { ...(width ? { flexBasis: width } : {}), ...(backgroundStyle || {}) };
2801
+ 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 }));
2741
2802
  };
2742
2803
  const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
2743
2804
  const ButtonBlock = ({ block, context }) => {
@@ -3324,5 +3385,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
3324
3385
  return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
3325
3386
  };
3326
3387
 
3327
- 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 };
3388
+ 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, getWordPressPresetColorClasses, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
3328
3389
  //# sourceMappingURL=index.esm.js.map