@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.cjs +70 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +69 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +21 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
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) {
|
|
@@ -1800,6 +1801,40 @@ const getCloudflareVariantUrl = (url, options) => {
|
|
|
1800
1801
|
return `${base}/${variant}`;
|
|
1801
1802
|
};
|
|
1802
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
|
+
}
|
|
1803
1838
|
/**
|
|
1804
1839
|
* Extract background image URL from a block
|
|
1805
1840
|
* Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
|
|
@@ -2277,6 +2312,27 @@ function extractBackgroundColorValue(block, context) {
|
|
|
2277
2312
|
}
|
|
2278
2313
|
return null;
|
|
2279
2314
|
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Return inline style for background color when no Tailwind class is available.
|
|
2317
|
+
* Supports WordPress custom color (style.color.background) and theme slug (themePalette).
|
|
2318
|
+
*
|
|
2319
|
+
* @param block - WordPress block
|
|
2320
|
+
* @param context - Render context with optional themePalette
|
|
2321
|
+
* @returns React.CSSProperties with backgroundColor or null
|
|
2322
|
+
*/
|
|
2323
|
+
function getBackgroundInlineStyle(block, context) {
|
|
2324
|
+
const attrs = block.attributes || {};
|
|
2325
|
+
const styleAttr = attrs['style'];
|
|
2326
|
+
const customBg = styleAttr?.color?.background;
|
|
2327
|
+
if (typeof customBg === 'string' && customBg.trim()) {
|
|
2328
|
+
return { backgroundColor: customBg.trim() };
|
|
2329
|
+
}
|
|
2330
|
+
const wpColorName = attrs['backgroundColor'] || attrs['background'];
|
|
2331
|
+
if (typeof wpColorName === 'string' && context.themePalette?.[wpColorName]) {
|
|
2332
|
+
return { backgroundColor: context.themePalette[wpColorName] };
|
|
2333
|
+
}
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2280
2336
|
/**
|
|
2281
2337
|
* Extract gradient background from block attributes
|
|
2282
2338
|
* WordPress stores gradients in attributes.style.color.gradient
|
|
@@ -2709,6 +2765,8 @@ const Group = ({ block, children, context }) => {
|
|
|
2709
2765
|
const layout = attrs['layout'];
|
|
2710
2766
|
// Extract background color using color mapper
|
|
2711
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);
|
|
2712
2770
|
// Determine if this is a section-level group (has alignment) or content-level
|
|
2713
2771
|
const isSection = align === 'full' || align === 'wide';
|
|
2714
2772
|
const containerClass = getContainerClasses(align, layout);
|
|
@@ -2721,9 +2779,9 @@ const Group = ({ block, children, context }) => {
|
|
|
2721
2779
|
const finalContainerClass = layout?.type === 'constrained' && align === 'wide'
|
|
2722
2780
|
? 'container'
|
|
2723
2781
|
: containerClass;
|
|
2724
|
-
// Build className with background color if present
|
|
2725
|
-
const className = buildClassName(finalContainerClass, spacingClass, backgroundColor //
|
|
2726
|
-
);
|
|
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);
|
|
2727
2785
|
return (jsxRuntimeExports.jsx("div", { className: className, children: children }));
|
|
2728
2786
|
};
|
|
2729
2787
|
const Columns = ({ block, children }) => {
|
|
@@ -2735,11 +2793,14 @@ const Columns = ({ block, children }) => {
|
|
|
2735
2793
|
const Column = ({ block, children, context }) => {
|
|
2736
2794
|
const attrs = block.attributes || {};
|
|
2737
2795
|
const width = attrs['width'];
|
|
2738
|
-
// Extract background color using color mapper
|
|
2796
|
+
// Extract background color using color mapper (Tailwind class)
|
|
2739
2797
|
const backgroundColor = extractBackgroundColor(block, context);
|
|
2740
|
-
//
|
|
2741
|
-
const
|
|
2742
|
-
|
|
2798
|
+
// WordPress preset classes from attributes for cascade
|
|
2799
|
+
const presetColors = getWordPressPresetColorClasses(block);
|
|
2800
|
+
// Inline background when no class (custom color or theme slug via themePalette)
|
|
2801
|
+
const backgroundStyle = getBackgroundInlineStyle(block, context);
|
|
2802
|
+
const style = { ...(width ? { flexBasis: width } : {}), ...(backgroundStyle || {}) };
|
|
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 }));
|
|
2743
2804
|
};
|
|
2744
2805
|
const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
|
|
2745
2806
|
const ButtonBlock = ({ block, context }) => {
|
|
@@ -3366,6 +3427,7 @@ exports.extractVideoIframeFromInnerBlocks = extractVideoIframeFromInnerBlocks;
|
|
|
3366
3427
|
exports.findMatchingMapping = findMatchingMapping;
|
|
3367
3428
|
exports.findShortcodes = findShortcodes;
|
|
3368
3429
|
exports.getAlignmentClasses = getAlignmentClasses;
|
|
3430
|
+
exports.getBackgroundInlineStyle = getBackgroundInlineStyle;
|
|
3369
3431
|
exports.getBlockTextContent = getBlockTextContent;
|
|
3370
3432
|
exports.getCloudflareVariantUrl = getCloudflareVariantUrl;
|
|
3371
3433
|
exports.getContainerClasses = getContainerClasses;
|
|
@@ -3375,6 +3437,7 @@ exports.getImageAttributes = getImageAttributes;
|
|
|
3375
3437
|
exports.getImageUrl = getImageUrl;
|
|
3376
3438
|
exports.getSectionSpacingClasses = getSectionSpacingClasses;
|
|
3377
3439
|
exports.getTextAlignClasses = getTextAlignClasses;
|
|
3440
|
+
exports.getWordPressPresetColorClasses = getWordPressPresetColorClasses;
|
|
3378
3441
|
exports.isCloudflareImageUrl = isCloudflareImageUrl;
|
|
3379
3442
|
exports.isValidCloudflareUrl = isValidCloudflareUrl;
|
|
3380
3443
|
exports.matchesPattern = matchesPattern;
|