@marvalt/wparser 0.1.43 → 0.1.45
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 +48 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.esm.js +48 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +5 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -493,6 +493,11 @@ declare function extractBackgroundColor(block: WordPressBlock, context: RenderCo
|
|
|
493
493
|
* @returns CSS class string (e.g., 'text-white') or null if no mapping
|
|
494
494
|
*/
|
|
495
495
|
declare function extractTextColor(block: WordPressBlock, context: RenderContext): string | null;
|
|
496
|
+
/**
|
|
497
|
+
* Infer a readable text color class based on a background class string.
|
|
498
|
+
* Supports bg-[#hex] and bg-[rgb(...)].
|
|
499
|
+
*/
|
|
500
|
+
declare function inferTextColorFromBackground(backgroundClass: string | null): string | null;
|
|
496
501
|
/**
|
|
497
502
|
* Extract spacer height from block attributes or innerHTML
|
|
498
503
|
* Returns height in pixels, or null if not found
|
|
@@ -550,5 +555,5 @@ interface SectionWrapperProps {
|
|
|
550
555
|
*/
|
|
551
556
|
declare const SectionWrapper: React$1.FC<SectionWrapperProps>;
|
|
552
557
|
|
|
553
|
-
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 };
|
|
558
|
+
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, inferTextColorFromBackground, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
554
559
|
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 };
|
package/dist/index.esm.js
CHANGED
|
@@ -2134,6 +2134,7 @@ function extractBackgroundColor(block, context) {
|
|
|
2134
2134
|
*/
|
|
2135
2135
|
function extractTextColor(block, context) {
|
|
2136
2136
|
const attrs = block.attributes || {};
|
|
2137
|
+
const mapper = context.colorMapper;
|
|
2137
2138
|
// Try multiple possible attribute names for text color
|
|
2138
2139
|
let wpColorName = attrs['textColor'] ||
|
|
2139
2140
|
attrs['text'] ||
|
|
@@ -2169,17 +2170,23 @@ function extractTextColor(block, context) {
|
|
|
2169
2170
|
}
|
|
2170
2171
|
}
|
|
2171
2172
|
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2172
|
-
|
|
2173
|
+
wpColorName = null;
|
|
2173
2174
|
}
|
|
2174
2175
|
// Use colorMapper from context if available
|
|
2175
2176
|
// Note: colorMapper returns combined classes like "bg-[#FBFAF3] text-gray-900"
|
|
2176
2177
|
// We need to extract just the text color part
|
|
2177
|
-
if (
|
|
2178
|
-
const mapped =
|
|
2178
|
+
if (mapper && wpColorName) {
|
|
2179
|
+
const mapped = mapper(wpColorName);
|
|
2179
2180
|
if (mapped) {
|
|
2180
|
-
//
|
|
2181
|
-
|
|
2182
|
-
|
|
2181
|
+
// If the mapper provided a background arbitrary value, derive a text color class directly from it
|
|
2182
|
+
const bgArbitrary = mapped.match(/\bbg-\[([^\]]+)\]/);
|
|
2183
|
+
if (bgArbitrary && bgArbitrary[1]) {
|
|
2184
|
+
const derivedText = `text-[${bgArbitrary[1]}]`;
|
|
2185
|
+
return derivedText;
|
|
2186
|
+
}
|
|
2187
|
+
// Extract text color classes (e.g., "text-white", "text-gray-900", "text-[#123456]")
|
|
2188
|
+
// Match text- classes including arbitrary values in brackets
|
|
2189
|
+
const textColorMatch = mapped.match(/\btext-(\[[^\]]+\]|[\w-]+)/g);
|
|
2183
2190
|
if (textColorMatch && textColorMatch.length > 0) {
|
|
2184
2191
|
// Return the last text color class (in case there are multiple)
|
|
2185
2192
|
const result = textColorMatch[textColorMatch.length - 1];
|
|
@@ -2197,6 +2204,34 @@ function extractTextColor(block, context) {
|
|
|
2197
2204
|
// Fallback: return null (no text color applied, will inherit from parent)
|
|
2198
2205
|
return null;
|
|
2199
2206
|
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Infer a readable text color class based on a background class string.
|
|
2209
|
+
* Supports bg-[#hex] and bg-[rgb(...)].
|
|
2210
|
+
*/
|
|
2211
|
+
function inferTextColorFromBackground(backgroundClass) {
|
|
2212
|
+
if (!backgroundClass)
|
|
2213
|
+
return null;
|
|
2214
|
+
// Try to extract hex color from arbitrary value class bg-[#xxxxxx]
|
|
2215
|
+
const hexMatch = backgroundClass.match(/bg-\[#?([0-9a-fA-F]{6})\]/);
|
|
2216
|
+
if (hexMatch) {
|
|
2217
|
+
const hex = hexMatch[1];
|
|
2218
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
2219
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
2220
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
2221
|
+
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
|
|
2222
|
+
return brightness < 140 ? 'text-white' : 'text-gray-900';
|
|
2223
|
+
}
|
|
2224
|
+
// Try rgb() form
|
|
2225
|
+
const rgbMatch = backgroundClass.match(/bg-\[rgb\((\d+),\s*(\d+),\s*(\d+)\)\]/i);
|
|
2226
|
+
if (rgbMatch) {
|
|
2227
|
+
const r = parseInt(rgbMatch[1], 10);
|
|
2228
|
+
const g = parseInt(rgbMatch[2], 10);
|
|
2229
|
+
const b = parseInt(rgbMatch[3], 10);
|
|
2230
|
+
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
|
|
2231
|
+
return brightness < 140 ? 'text-white' : 'text-gray-900';
|
|
2232
|
+
}
|
|
2233
|
+
return null;
|
|
2234
|
+
}
|
|
2200
2235
|
/**
|
|
2201
2236
|
* Extract spacer height from block attributes or innerHTML
|
|
2202
2237
|
* Returns height in pixels, or null if not found
|
|
@@ -2495,6 +2530,8 @@ const Group = ({ block, children, context }) => {
|
|
|
2495
2530
|
const layout = attrs['layout'];
|
|
2496
2531
|
// Extract background color using color mapper
|
|
2497
2532
|
const backgroundColor = extractBackgroundColor(block, context);
|
|
2533
|
+
// Extract text color (apply on the wrapper so children inherit)
|
|
2534
|
+
const textColor = extractTextColor(block, context) || inferTextColorFromBackground(backgroundColor);
|
|
2498
2535
|
// Determine if this is a section-level group (has alignment) or content-level
|
|
2499
2536
|
const isSection = align === 'full' || align === 'wide';
|
|
2500
2537
|
const containerClass = getContainerClasses(align, layout);
|
|
@@ -2508,8 +2545,8 @@ const Group = ({ block, children, context }) => {
|
|
|
2508
2545
|
? 'container'
|
|
2509
2546
|
: containerClass;
|
|
2510
2547
|
// Build className with background color if present
|
|
2511
|
-
const className = buildClassName(finalContainerClass, spacingClass, backgroundColor // This will be null if no mapping, which is fine
|
|
2512
|
-
);
|
|
2548
|
+
const className = buildClassName(finalContainerClass, spacingClass, backgroundColor, // This will be null if no mapping, which is fine
|
|
2549
|
+
textColor);
|
|
2513
2550
|
return (jsxRuntimeExports.jsx("div", { className: className, children: children }));
|
|
2514
2551
|
};
|
|
2515
2552
|
const Columns = ({ block, children }) => {
|
|
@@ -2523,9 +2560,10 @@ const Column = ({ block, children, context }) => {
|
|
|
2523
2560
|
const width = attrs['width'];
|
|
2524
2561
|
// Extract background color using color mapper
|
|
2525
2562
|
const backgroundColor = extractBackgroundColor(block, context);
|
|
2563
|
+
const textColor = extractTextColor(block, context) || inferTextColorFromBackground(backgroundColor);
|
|
2526
2564
|
// Handle column width (e.g., "50%" becomes flex-basis)
|
|
2527
2565
|
const style = width ? { flexBasis: width } : undefined;
|
|
2528
|
-
return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
|
|
2566
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor, textColor), style: style, children: children }));
|
|
2529
2567
|
};
|
|
2530
2568
|
const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
|
|
2531
2569
|
const ButtonBlock = ({ block, context }) => {
|
|
@@ -3039,5 +3077,5 @@ const SectionWrapper = ({ children, background = 'light', spacing = 'medium', co
|
|
|
3039
3077
|
return (jsxRuntimeExports.jsx("section", { className: buildClassName(backgroundClasses[finalBackground] || backgroundClasses.light, spacingClasses[finalSpacing] || spacingClasses.medium, containerClasses[finalContainer] || containerClasses.contained, className), children: children }));
|
|
3040
3078
|
};
|
|
3041
3079
|
|
|
3042
|
-
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 };
|
|
3080
|
+
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, inferTextColorFromBackground, isCloudflareImageUrl, isValidCloudflareUrl, matchesPattern, parseContentPosition, parseGutenbergBlocks, parseShortcodeAttrs, renderNodes, renderTextWithShortcodes };
|
|
3043
3081
|
//# sourceMappingURL=index.esm.js.map
|