@marvalt/wparser 0.1.14 → 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.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
- let bgImageUrl = url || backgroundImage || (typeof backgroundImage === 'object' && backgroundImage?.url);
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 && isCloudflareImageUrl(bgImageUrl)) {
1858
- // Use full width for cover images
1859
- bgImageUrl = getCloudflareVariantUrl(bgImageUrl, { width: 1920 });
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
- const mediaBlockIndex = innerBlocks.findIndex((b) => b.name === 'core/image' || b.name === 'core/video');
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
- const mediaElement = mediaBlockIndex >= 0 && childrenArray[mediaBlockIndex]
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
- return (jsxRuntimeExports.jsx("div", { className: buildClassName(alignClass, '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'), children: mediaElement || jsxRuntimeExports.jsx("div", { className: "bg-gray-200 h-64 rounded-lg" }) }), jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-1' : 'order-2', imageFill ? 'w-full md:w-1/2' : 'flex-1', 'space-y-4'), children: contentElements.length > 0 ? contentElements : children })] }) }));
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