@marvalt/wparser 0.1.33 → 0.1.35
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 +63 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +63 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/contentExtractor.d.ts +3 -2
- package/dist/utils/contentExtractor.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1590,16 +1590,41 @@ function getImageUrl(block) {
|
|
|
1590
1590
|
return null;
|
|
1591
1591
|
}
|
|
1592
1592
|
/**
|
|
1593
|
-
* Extract image attributes (alt, width, height) from block
|
|
1593
|
+
* Extract image attributes (alt, width, height, alignment) from block
|
|
1594
1594
|
*/
|
|
1595
1595
|
function getImageAttributes(block) {
|
|
1596
1596
|
const attrs = block.attributes || {};
|
|
1597
1597
|
const url = getImageUrl(block);
|
|
1598
|
+
// Extract width - can be number or string like "640px"
|
|
1599
|
+
let width;
|
|
1600
|
+
const widthAttr = attrs['width'];
|
|
1601
|
+
if (widthAttr) {
|
|
1602
|
+
if (typeof widthAttr === 'number') {
|
|
1603
|
+
width = widthAttr;
|
|
1604
|
+
}
|
|
1605
|
+
else if (typeof widthAttr === 'string') {
|
|
1606
|
+
// Try to parse number from string like "640px" or "640"
|
|
1607
|
+
const numMatch = widthAttr.match(/^(\d+)/);
|
|
1608
|
+
if (numMatch) {
|
|
1609
|
+
width = parseInt(numMatch[1], 10);
|
|
1610
|
+
}
|
|
1611
|
+
else {
|
|
1612
|
+
// Keep as string if it's not a simple number
|
|
1613
|
+
width = widthAttr;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
// Extract alignment
|
|
1618
|
+
const align = attrs['align'];
|
|
1619
|
+
const alignValue = align === 'left' || align === 'center' || align === 'right'
|
|
1620
|
+
? align
|
|
1621
|
+
: undefined;
|
|
1598
1622
|
return {
|
|
1599
1623
|
url,
|
|
1600
1624
|
alt: attrs['alt'] || '',
|
|
1601
|
-
width
|
|
1625
|
+
width,
|
|
1602
1626
|
height: attrs['height'] ? Number(attrs['height']) : undefined,
|
|
1627
|
+
align: alignValue,
|
|
1603
1628
|
};
|
|
1604
1629
|
}
|
|
1605
1630
|
/**
|
|
@@ -2298,15 +2323,48 @@ const Image = ({ block, context }) => {
|
|
|
2298
2323
|
const imageAttrs = getImageAttributes(block);
|
|
2299
2324
|
if (!imageAttrs.url)
|
|
2300
2325
|
return null;
|
|
2326
|
+
// Extract width for Cloudflare variant (use numeric value)
|
|
2327
|
+
const numericWidth = typeof imageAttrs.width === 'number'
|
|
2328
|
+
? imageAttrs.width
|
|
2329
|
+
: (typeof imageAttrs.width === 'string' ? parseInt(imageAttrs.width, 10) || 1024 : 1024);
|
|
2301
2330
|
// Use Cloudflare variant URL if it's a Cloudflare image
|
|
2302
2331
|
let imageUrl = imageAttrs.url;
|
|
2303
2332
|
if (isCloudflareImageUrl(imageUrl)) {
|
|
2304
|
-
const width = imageAttrs.width || 1024;
|
|
2305
2333
|
const height = imageAttrs.height;
|
|
2306
|
-
imageUrl = getCloudflareVariantUrl(imageUrl, { width, height });
|
|
2334
|
+
imageUrl = getCloudflareVariantUrl(imageUrl, { width: numericWidth, height });
|
|
2307
2335
|
}
|
|
2308
2336
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'image', 'my-6');
|
|
2309
|
-
|
|
2337
|
+
// Handle alignment (left, center, right)
|
|
2338
|
+
let alignClass = '';
|
|
2339
|
+
if (imageAttrs.align === 'left') {
|
|
2340
|
+
alignClass = 'mr-auto';
|
|
2341
|
+
}
|
|
2342
|
+
else if (imageAttrs.align === 'center') {
|
|
2343
|
+
alignClass = 'mx-auto';
|
|
2344
|
+
}
|
|
2345
|
+
else if (imageAttrs.align === 'right') {
|
|
2346
|
+
alignClass = 'ml-auto';
|
|
2347
|
+
}
|
|
2348
|
+
// Handle width - if specified, use it; otherwise use w-full
|
|
2349
|
+
let widthClass = 'w-full';
|
|
2350
|
+
let widthStyle = {};
|
|
2351
|
+
if (imageAttrs.width) {
|
|
2352
|
+
if (typeof imageAttrs.width === 'string' && imageAttrs.width.includes('px')) {
|
|
2353
|
+
// Use inline style for pixel values
|
|
2354
|
+
widthStyle.width = imageAttrs.width;
|
|
2355
|
+
widthClass = ''; // Don't use w-full if we have explicit width
|
|
2356
|
+
}
|
|
2357
|
+
else if (typeof imageAttrs.width === 'number') {
|
|
2358
|
+
// Use inline style for numeric pixel values
|
|
2359
|
+
widthStyle.width = `${imageAttrs.width}px`;
|
|
2360
|
+
widthClass = ''; // Don't use w-full if we have explicit width
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
// Build image classes - include shadow (app can override via registry)
|
|
2364
|
+
// Default shadow is shadow-md, but app can customize
|
|
2365
|
+
const imageClasses = buildClassName('h-auto rounded-lg object-cover shadow-md', // shadow-md is default, app can override
|
|
2366
|
+
widthClass, alignClass, spacing);
|
|
2367
|
+
return (jsxRuntimeExports.jsx("img", { src: imageUrl, alt: imageAttrs.alt, width: typeof imageAttrs.width === 'number' ? imageAttrs.width : undefined, height: imageAttrs.height, className: imageClasses, style: { maxWidth: '100%', height: 'auto', ...widthStyle }, loading: "lazy" }));
|
|
2310
2368
|
};
|
|
2311
2369
|
const List = ({ block, children, context }) => {
|
|
2312
2370
|
const attrs = block.attributes || {};
|