@marvalt/wparser 0.1.57 → 0.1.58
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 +65 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +65 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +4 -2
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -421,8 +421,9 @@ declare function extractHeadingLevel(block: WordPressBlock): number;
|
|
|
421
421
|
declare function extractTextAlign(block: WordPressBlock): 'left' | 'center' | 'right' | null;
|
|
422
422
|
/**
|
|
423
423
|
* Extract font size from block
|
|
424
|
+
* Checks both fontSize attribute and style.typography.fontSize
|
|
424
425
|
*/
|
|
425
|
-
declare function extractFontSize(block: WordPressBlock): string | null;
|
|
426
|
+
declare function extractFontSize(block: WordPressBlock, context?: RenderContext): string | null;
|
|
426
427
|
/**
|
|
427
428
|
* Convert image URL to Cloudflare variant if it's a Cloudflare URL
|
|
428
429
|
*/
|
|
@@ -515,9 +516,10 @@ declare function extractGradientBackground(block: WordPressBlock): string | null
|
|
|
515
516
|
/**
|
|
516
517
|
* Extract and map text color from block attributes
|
|
517
518
|
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
519
|
+
* Also checks style.color.text and inherited colors from parent groups
|
|
518
520
|
*
|
|
519
521
|
* @param block - WordPress block to extract text color from
|
|
520
|
-
* @param context - Render context containing optional colorMapper
|
|
522
|
+
* @param context - Render context containing optional colorMapper and themePalette
|
|
521
523
|
* @returns CSS class string (e.g., 'text-white') or null if no mapping
|
|
522
524
|
*/
|
|
523
525
|
declare function extractTextColor(block: WordPressBlock, context: RenderContext): string | null;
|
package/dist/index.esm.js
CHANGED
|
@@ -1872,11 +1872,31 @@ function extractTextAlign(block) {
|
|
|
1872
1872
|
}
|
|
1873
1873
|
/**
|
|
1874
1874
|
* Extract font size from block
|
|
1875
|
+
* Checks both fontSize attribute and style.typography.fontSize
|
|
1875
1876
|
*/
|
|
1876
|
-
function extractFontSize(block) {
|
|
1877
|
+
function extractFontSize(block, context) {
|
|
1877
1878
|
const attrs = block.attributes || {};
|
|
1879
|
+
// Check inherited font size from context (from parent group)
|
|
1880
|
+
if (context && context.inheritedFontSize) {
|
|
1881
|
+
return context.inheritedFontSize;
|
|
1882
|
+
}
|
|
1883
|
+
// Check style.typography.fontSize (can be a preset name or CSS value)
|
|
1884
|
+
const styleFontSize = attrs['style']?.typography?.fontSize;
|
|
1885
|
+
if (styleFontSize) {
|
|
1886
|
+
if (typeof styleFontSize === 'string') {
|
|
1887
|
+
return styleFontSize;
|
|
1888
|
+
}
|
|
1889
|
+
// If it's an object, it might have a value property
|
|
1890
|
+
if (typeof styleFontSize === 'object' && styleFontSize.value) {
|
|
1891
|
+
return styleFontSize.value;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
// Check fontSize attribute (preset name like 'small', 'medium', etc.)
|
|
1878
1895
|
const fontSize = attrs['fontSize'];
|
|
1879
|
-
|
|
1896
|
+
if (typeof fontSize === 'string') {
|
|
1897
|
+
return fontSize;
|
|
1898
|
+
}
|
|
1899
|
+
return null;
|
|
1880
1900
|
}
|
|
1881
1901
|
/**
|
|
1882
1902
|
* Convert image URL to Cloudflare variant if it's a Cloudflare URL
|
|
@@ -2154,17 +2174,46 @@ function extractGradientBackground(block) {
|
|
|
2154
2174
|
/**
|
|
2155
2175
|
* Extract and map text color from block attributes
|
|
2156
2176
|
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
2177
|
+
* Also checks style.color.text and inherited colors from parent groups
|
|
2157
2178
|
*
|
|
2158
2179
|
* @param block - WordPress block to extract text color from
|
|
2159
|
-
* @param context - Render context containing optional colorMapper
|
|
2180
|
+
* @param context - Render context containing optional colorMapper and themePalette
|
|
2160
2181
|
* @returns CSS class string (e.g., 'text-white') or null if no mapping
|
|
2161
2182
|
*/
|
|
2162
2183
|
function extractTextColor(block, context) {
|
|
2163
2184
|
const attrs = block.attributes || {};
|
|
2164
|
-
|
|
2185
|
+
// Check inherited text color from context (from parent group)
|
|
2186
|
+
if (context.inheritedTextColor) {
|
|
2187
|
+
return context.inheritedTextColor;
|
|
2188
|
+
}
|
|
2189
|
+
// Check style.color.text (can be a color name or CSS variable)
|
|
2190
|
+
const styleTextColor = attrs['style']?.color?.text;
|
|
2191
|
+
let wpColorName = null;
|
|
2192
|
+
if (styleTextColor) {
|
|
2193
|
+
if (typeof styleTextColor === 'string') {
|
|
2194
|
+
wpColorName = styleTextColor;
|
|
2195
|
+
}
|
|
2196
|
+
else if (typeof styleTextColor === 'object' && styleTextColor.color) {
|
|
2197
|
+
wpColorName = styleTextColor.color;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
// Fall back to textColor or text attribute
|
|
2201
|
+
if (!wpColorName) {
|
|
2202
|
+
wpColorName = attrs['textColor'] || attrs['text'];
|
|
2203
|
+
}
|
|
2165
2204
|
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2166
2205
|
return null;
|
|
2167
2206
|
}
|
|
2207
|
+
// If it's a CSS variable or hex color, return it directly
|
|
2208
|
+
if (wpColorName.startsWith('var(') || wpColorName.startsWith('#')) {
|
|
2209
|
+
return `text-[${wpColorName}]`;
|
|
2210
|
+
}
|
|
2211
|
+
// Get theme palette from context if available
|
|
2212
|
+
const themePalette = context?.themePalette || context.registry?.themePalette || context.registry?.wpStyles?.theme_palette;
|
|
2213
|
+
if (themePalette && themePalette[wpColorName]) {
|
|
2214
|
+
// Return inline style class with actual color value
|
|
2215
|
+
return `text-[${themePalette[wpColorName]}]`;
|
|
2216
|
+
}
|
|
2168
2217
|
// Special handling for common WordPress color names when used as text color
|
|
2169
2218
|
// These mappings take precedence because text color semantics differ from background color
|
|
2170
2219
|
const textColorMap = {
|
|
@@ -2339,6 +2388,9 @@ const Paragraph = ({ block, context }) => {
|
|
|
2339
2388
|
// Extract text color if specified, otherwise inherit from parent (CSS variables handle default)
|
|
2340
2389
|
const textColor = extractTextColor(block, context);
|
|
2341
2390
|
const textColorClass = textColor || ''; // Don't hardcode - let CSS variables handle default
|
|
2391
|
+
// Extract font size if specified
|
|
2392
|
+
const fontSize = extractFontSize(block, context);
|
|
2393
|
+
const fontSizeClass = fontSize ? getFontSizeClasses(fontSize) : '';
|
|
2342
2394
|
// Check if innerHTML contains HTML elements (like links, strong, em, etc.)
|
|
2343
2395
|
const hasHTML = block.innerHTML && /<[a-z][\s\S]*>/i.test(block.innerHTML);
|
|
2344
2396
|
// Check if content contains shortcodes (check both HTML and text content)
|
|
@@ -2374,24 +2426,28 @@ const Paragraph = ({ block, context }) => {
|
|
|
2374
2426
|
const hasBlockLevelContent = React.Children.toArray(parts).some((part) => isBlockLevelElement(part));
|
|
2375
2427
|
if (hasBlockLevelContent) {
|
|
2376
2428
|
// Render block-level content without <p> wrapper, but add spacing wrapper
|
|
2377
|
-
|
|
2429
|
+
const fontSize = extractFontSize(block, context);
|
|
2430
|
+
const fontSizeClass = fontSize ? getFontSizeClasses(fontSize) : '';
|
|
2431
|
+
return jsxRuntimeExports.jsx("div", { className: buildClassName(spacing, textColorClass, fontSizeClass), children: parts });
|
|
2378
2432
|
}
|
|
2379
2433
|
// Render shortcode parts inside paragraph (shortcodes are processed as React components)
|
|
2380
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), children: parts });
|
|
2434
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass, fontSizeClass), children: parts });
|
|
2381
2435
|
}
|
|
2382
2436
|
// If innerHTML contains HTML elements but no shortcodes, render it directly (preserves links, formatting, etc.)
|
|
2383
2437
|
if (hasHTML && block.innerHTML) {
|
|
2384
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), dangerouslySetInnerHTML: { __html: htmlContent } });
|
|
2438
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass, fontSizeClass), dangerouslySetInnerHTML: { __html: htmlContent } });
|
|
2385
2439
|
}
|
|
2386
2440
|
// No HTML and no shortcodes, just render plain text content
|
|
2387
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass), children: textContent });
|
|
2441
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName(spacing, textAlign, textColorClass, fontSizeClass), children: textContent });
|
|
2388
2442
|
};
|
|
2389
2443
|
const Heading = ({ block, children, context }) => {
|
|
2390
2444
|
const attrs = block.attributes || {};
|
|
2391
2445
|
const { level = 2 } = attrs;
|
|
2392
2446
|
const content = getBlockTextContent(block);
|
|
2393
2447
|
const textAlign = getTextAlignClasses(attrs['textAlign']);
|
|
2394
|
-
|
|
2448
|
+
// Extract font size - check both fontSize attribute and style.typography.fontSize
|
|
2449
|
+
const extractedFontSize = extractFontSize(block, context);
|
|
2450
|
+
const fontSize = extractedFontSize ? getFontSizeClasses(extractedFontSize) : '';
|
|
2395
2451
|
const Tag = `h${Math.min(Math.max(Number(level) || 2, 1), 6)}`;
|
|
2396
2452
|
// Use CSS variables for font sizes (defined in index.css) instead of Tailwind classes
|
|
2397
2453
|
// Only use Tailwind class if explicitly set via fontSize attribute
|