@marvalt/wparser 0.1.13 → 0.1.15
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 +58 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +58 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +1 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1835,9 +1835,13 @@ const ButtonBlock = ({ block }) => {
|
|
|
1835
1835
|
};
|
|
1836
1836
|
const Cover = ({ block, children }) => {
|
|
1837
1837
|
const attrs = block.attributes || {};
|
|
1838
|
-
const { url, id, backgroundImage, overlayColor, dimRatio = 0, align = 'full', minHeight, minHeightUnit = 'vh', hasParallax, } = attrs;
|
|
1838
|
+
const { url, id, backgroundImage, cloudflareUrl, overlayColor, dimRatio = 0, align = 'full', minHeight, minHeightUnit = 'vh', hasParallax, } = attrs;
|
|
1839
1839
|
// Get background image URL from various possible sources
|
|
1840
|
-
|
|
1840
|
+
// Priority: cloudflareUrl (from plugin) > url > backgroundImage > innerHTML extraction
|
|
1841
|
+
let bgImageUrl = cloudflareUrl;
|
|
1842
|
+
if (!bgImageUrl) {
|
|
1843
|
+
bgImageUrl = url || backgroundImage || (typeof backgroundImage === 'object' && backgroundImage?.url);
|
|
1844
|
+
}
|
|
1841
1845
|
// If not found in attributes, try to extract from innerHTML
|
|
1842
1846
|
if (!bgImageUrl && block.innerHTML) {
|
|
1843
1847
|
// Try to extract img src from innerHTML
|
|
@@ -1853,10 +1857,16 @@ const Cover = ({ block, children }) => {
|
|
|
1853
1857
|
}
|
|
1854
1858
|
}
|
|
1855
1859
|
}
|
|
1856
|
-
// Convert to Cloudflare URL if it's a Cloudflare image, otherwise use as-is
|
|
1857
|
-
if (bgImageUrl
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
+
// Convert to Cloudflare URL variant if it's a Cloudflare image, otherwise use as-is
|
|
1861
|
+
if (bgImageUrl) {
|
|
1862
|
+
if (isCloudflareImageUrl(bgImageUrl)) {
|
|
1863
|
+
// Use full width for cover images
|
|
1864
|
+
bgImageUrl = getCloudflareVariantUrl(bgImageUrl, { width: 1920 });
|
|
1865
|
+
}
|
|
1866
|
+
// If cloudflareUrl was provided, it's already a Cloudflare URL, just add variant
|
|
1867
|
+
else if (cloudflareUrl) {
|
|
1868
|
+
bgImageUrl = getCloudflareVariantUrl(cloudflareUrl, { width: 1920 });
|
|
1869
|
+
}
|
|
1860
1870
|
}
|
|
1861
1871
|
// Build alignment classes
|
|
1862
1872
|
const alignClass = getAlignmentClasses(align);
|
|
@@ -1887,12 +1897,36 @@ const MediaText = ({ block, children, context }) => {
|
|
|
1887
1897
|
// Access innerBlocks to identify media vs content
|
|
1888
1898
|
const innerBlocks = block.innerBlocks || [];
|
|
1889
1899
|
// Find media block (image or video)
|
|
1890
|
-
|
|
1900
|
+
let mediaBlockIndex = innerBlocks.findIndex((b) => b.name === 'core/image' || b.name === 'core/video');
|
|
1901
|
+
// Check for cloudflareUrl in attributes first (provided by WordPress plugin)
|
|
1902
|
+
const cloudflareUrl = attrs['cloudflareUrl'];
|
|
1903
|
+
// If no media block found, try to extract from innerHTML
|
|
1904
|
+
let imageUrl = null;
|
|
1905
|
+
if (mediaBlockIndex === -1 && block.innerHTML) {
|
|
1906
|
+
// Extract img src from innerHTML
|
|
1907
|
+
const imgMatch = block.innerHTML.match(/<img[^>]+src=["']([^"']+)["']/i);
|
|
1908
|
+
if (imgMatch && imgMatch[1]) {
|
|
1909
|
+
imageUrl = imgMatch[1];
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1891
1912
|
// Render children - media-text typically has media as first child, then content
|
|
1892
1913
|
const childrenArray = React.Children.toArray(children);
|
|
1893
|
-
|
|
1914
|
+
let mediaElement = mediaBlockIndex >= 0 && childrenArray[mediaBlockIndex]
|
|
1894
1915
|
? childrenArray[mediaBlockIndex]
|
|
1895
1916
|
: null;
|
|
1917
|
+
// Use cloudflareUrl from attributes if available
|
|
1918
|
+
if (!mediaElement && cloudflareUrl) {
|
|
1919
|
+
const finalImageUrl = getCloudflareVariantUrl(cloudflareUrl, { width: 1024 });
|
|
1920
|
+
mediaElement = (jsxRuntimeExports.jsx("img", { src: finalImageUrl, alt: "", className: "w-full h-auto rounded-lg object-cover" }));
|
|
1921
|
+
}
|
|
1922
|
+
// If we extracted image URL from innerHTML, render it
|
|
1923
|
+
else if (!mediaElement && imageUrl) {
|
|
1924
|
+
// Convert to Cloudflare URL if applicable
|
|
1925
|
+
const finalImageUrl = isCloudflareImageUrl(imageUrl)
|
|
1926
|
+
? getCloudflareVariantUrl(imageUrl, { width: 1024 })
|
|
1927
|
+
: imageUrl;
|
|
1928
|
+
mediaElement = (jsxRuntimeExports.jsx("img", { src: finalImageUrl, alt: "", className: "w-full h-auto rounded-lg object-cover" }));
|
|
1929
|
+
}
|
|
1896
1930
|
// Content is all other children
|
|
1897
1931
|
const contentElements = childrenArray.filter((_, index) => index !== mediaBlockIndex);
|
|
1898
1932
|
// Build alignment classes
|
|
@@ -1905,7 +1939,9 @@ const MediaText = ({ block, children, context }) => {
|
|
|
1905
1939
|
const stackClass = 'flex-col md:flex-row';
|
|
1906
1940
|
// Media position determines order
|
|
1907
1941
|
const isMediaRight = mediaPosition === 'right';
|
|
1908
|
-
|
|
1942
|
+
// Add section spacing for consistent vertical rhythm
|
|
1943
|
+
const spacingClass = getSectionSpacingClasses();
|
|
1944
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName(alignClass, spacingClass, 'px-4'), children: jsxRuntimeExports.jsxs("div", { className: buildClassName('flex', stackClass, verticalAlignClass, 'gap-6 lg:gap-12'), children: [jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-2' : 'order-1', imageFill ? 'w-full md:w-1/2' : 'flex-shrink-0 md:w-1/2'), children: mediaElement || jsxRuntimeExports.jsx("div", { className: "bg-gray-200 h-64 rounded-lg" }) }), jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-1' : 'order-2', 'md:w-1/2', getContentSpacingClasses()), children: contentElements.length > 0 ? contentElements : children })] }) }));
|
|
1909
1945
|
};
|
|
1910
1946
|
const Fallback = ({ block, children }) => {
|
|
1911
1947
|
// Minimal fallback; do not render innerHTML directly in v1 for safety
|
|
@@ -2132,6 +2168,9 @@ function detectHeroShortcode(blocks) {
|
|
|
2132
2168
|
const html = (block.innerHTML || '').toLowerCase();
|
|
2133
2169
|
if (html.includes('[herosection]'))
|
|
2134
2170
|
return true;
|
|
2171
|
+
// Check if this is a cover block (which is a hero section)
|
|
2172
|
+
if (block.name === 'core/cover')
|
|
2173
|
+
return true;
|
|
2135
2174
|
if (block.innerBlocks?.length && detectHeroShortcode(block.innerBlocks))
|
|
2136
2175
|
return true;
|
|
2137
2176
|
}
|
|
@@ -2437,10 +2476,12 @@ function extractButtonsFromInnerBlocks(block) {
|
|
|
2437
2476
|
* Extract text alignment from inner blocks
|
|
2438
2477
|
* Recursively searches for heading or paragraph blocks with textAlign attribute
|
|
2439
2478
|
* Also checks group blocks for justifyContent in layout
|
|
2479
|
+
* Priority: heading/paragraph textAlign takes precedence over group justifyContent
|
|
2440
2480
|
*/
|
|
2441
2481
|
function extractTextAlignFromInnerBlocks(block) {
|
|
2442
2482
|
const innerBlocks = block.innerBlocks || [];
|
|
2443
|
-
//
|
|
2483
|
+
// First, recursively search for heading or paragraph blocks with textAlign
|
|
2484
|
+
// (These take priority over group justifyContent)
|
|
2444
2485
|
for (const innerBlock of innerBlocks) {
|
|
2445
2486
|
if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
|
|
2446
2487
|
const attrs = innerBlock.attributes || {};
|
|
@@ -2449,7 +2490,13 @@ function extractTextAlignFromInnerBlocks(block) {
|
|
|
2449
2490
|
return textAlign;
|
|
2450
2491
|
}
|
|
2451
2492
|
}
|
|
2452
|
-
//
|
|
2493
|
+
// Recursively search nested blocks for headings/paragraphs first
|
|
2494
|
+
const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
|
|
2495
|
+
if (nestedAlign)
|
|
2496
|
+
return nestedAlign;
|
|
2497
|
+
}
|
|
2498
|
+
// Only check group blocks if no heading/paragraph alignment found
|
|
2499
|
+
for (const innerBlock of innerBlocks) {
|
|
2453
2500
|
if (innerBlock.name === 'core/group') {
|
|
2454
2501
|
const attrs = innerBlock.attributes || {};
|
|
2455
2502
|
const layout = attrs['layout'];
|
|
@@ -2461,10 +2508,6 @@ function extractTextAlignFromInnerBlocks(block) {
|
|
|
2461
2508
|
if (justifyContent === 'right')
|
|
2462
2509
|
return 'right';
|
|
2463
2510
|
}
|
|
2464
|
-
// Recursively search nested blocks
|
|
2465
|
-
const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
|
|
2466
|
-
if (nestedAlign)
|
|
2467
|
-
return nestedAlign;
|
|
2468
2511
|
}
|
|
2469
2512
|
return null;
|
|
2470
2513
|
}
|