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