email-builder-utils 1.1.23 → 1.1.24
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.
|
@@ -24,6 +24,5 @@ interface IBlockData {
|
|
|
24
24
|
export declare const tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
25
25
|
export declare function convertToHtml(blockData: IBlockData, rootData: any, cellWidthInPx: number): Promise<string>;
|
|
26
26
|
export declare function convertVideoBlock(blockData: any, cellWidthInPx: number): Promise<string>;
|
|
27
|
-
export declare function convertShapeBlock(blockData: IBlockData): Promise<string>;
|
|
28
27
|
export {};
|
|
29
28
|
//# sourceMappingURL=jsonToHTML.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAUrC,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE;QACJ,KAAK,EAAE,cAAc,CAAC;QACtB,KAAK,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KAC7B,CAAC;CACH;AAOD,e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HTML.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.tableCommonStyle = void 0;
|
|
4
4
|
exports.convertToHtml = convertToHtml;
|
|
5
5
|
exports.convertVideoBlock = convertVideoBlock;
|
|
6
|
-
exports.convertShapeBlock = convertShapeBlock;
|
|
7
6
|
const jimp_1 = require("jimp");
|
|
8
7
|
const types_1 = require("../types");
|
|
9
8
|
const common_1 = require("./common");
|
|
@@ -320,7 +319,7 @@ async function convertGridCellBlock(blockData, rootData, cellWidthPercent, paren
|
|
|
320
319
|
}
|
|
321
320
|
async function convertVideoBlock(blockData, cellWidthInPx) {
|
|
322
321
|
const { style, props } = blockData.data;
|
|
323
|
-
const { videoUrl, youtubeVideoUrl, thumbnailUrl, altText } = props
|
|
322
|
+
const { videoUrl, youtubeVideoUrl, thumbnailUrl, altText } = props;
|
|
324
323
|
const videoLink = youtubeVideoUrl || videoUrl || "#";
|
|
325
324
|
let resolvedThumbnail = thumbnailUrl || "https://via.placeholder.com/480x360?text=No+Thumbnail";
|
|
326
325
|
if (youtubeVideoUrl) {
|
|
@@ -351,7 +350,10 @@ async function convertVideoBlock(blockData, cellWidthInPx) {
|
|
|
351
350
|
else {
|
|
352
351
|
percentWidth = "100%";
|
|
353
352
|
}
|
|
354
|
-
const innerContainerWidth = (parseFloat(percentWidth) / 100) *
|
|
353
|
+
const innerContainerWidth = (parseFloat(percentWidth) / 100) *
|
|
354
|
+
(cellWidthInPx -
|
|
355
|
+
(style?.padding?.left || 0) -
|
|
356
|
+
(style?.padding?.right || 0));
|
|
355
357
|
const aspectRatio = 16 / 9;
|
|
356
358
|
const calculatedHeight = innerContainerWidth / aspectRatio;
|
|
357
359
|
const outerContainerStyles = buildStyles({
|
|
@@ -430,9 +432,15 @@ async function convertVideoBlock(blockData, cellWidthInPx) {
|
|
|
430
432
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="margin:0; padding:0; border-collapse: collapse;">
|
|
431
433
|
<tr>
|
|
432
434
|
<td align="center" style="padding:0; ${outerContainerStyles}">
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
435
|
+
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
|
|
436
|
+
align="center"
|
|
437
|
+
style="margin:0 auto; max-width:${cellWidthInPx}px; width:${percentWidth}; border-collapse:collapse;">
|
|
438
|
+
<tr>
|
|
439
|
+
<td align="center" style="text-align:center; padding:0;">
|
|
440
|
+
${videoContent}
|
|
441
|
+
</td>
|
|
442
|
+
</tr>
|
|
443
|
+
</table>
|
|
436
444
|
</td>
|
|
437
445
|
</tr>
|
|
438
446
|
</table>
|
|
@@ -534,24 +542,31 @@ function buildVMLShape({ shape, widthPx, heightPx, imageUrl, backgroundColor, bo
|
|
|
534
542
|
// ---------- convertShapeBlock (updated, keeps your structure) ----------
|
|
535
543
|
async function convertShapeBlock(blockData) {
|
|
536
544
|
const { style, props } = blockData.data;
|
|
537
|
-
const { shape, text, textColor = "#000000", imageUrl } = props
|
|
538
|
-
const { width = "100", height = "150", padding = {}, backgroundColor = "#2F80ED", borderRadius, borderWidth = 0, borderStyle = "solid", borderColor = "transparent", customCss, shapeColor, alignment = "left", msoBakeImageWithText
|
|
545
|
+
const { shape, text, textColor = "#000000", imageUrl } = props;
|
|
546
|
+
const { width = "100", height = "150", padding = {}, backgroundColor = "#2F80ED", borderRadius, borderWidth = 0, borderStyle = "solid", borderColor = "transparent", customCss, shapeColor, alignment = "left", msoBakeImageWithText } = style || {};
|
|
539
547
|
const borderRadiusMap = {
|
|
540
548
|
rectangle: "0",
|
|
541
549
|
rounded: "10px",
|
|
542
550
|
circle: "50%",
|
|
543
|
-
oval: "50%",
|
|
551
|
+
oval: "50%", // Keep this for modern browsers
|
|
544
552
|
};
|
|
545
553
|
let resolvedBorderRadius = borderRadius || borderRadiusMap[shape] || "0";
|
|
546
|
-
let resolvedWidthPx = typeof width === "number"
|
|
547
|
-
|
|
548
|
-
|
|
554
|
+
let resolvedWidthPx = typeof width === "number"
|
|
555
|
+
? width
|
|
556
|
+
: parseInt(width.toString().replace("px", ""), 10) || 100;
|
|
557
|
+
let resolvedHeightPx = typeof height === "number"
|
|
558
|
+
? height
|
|
559
|
+
: parseInt(height.toString().replace("px", ""), 10) || 150;
|
|
560
|
+
// Special handling for different shapes
|
|
549
561
|
if (shape === "circle") {
|
|
562
|
+
// Circle: make it a perfect square with 50% border radius
|
|
550
563
|
const side = Math.min(resolvedWidthPx, resolvedHeightPx);
|
|
551
564
|
resolvedWidthPx = side;
|
|
552
565
|
resolvedHeightPx = side;
|
|
553
566
|
resolvedBorderRadius = "50%";
|
|
554
567
|
}
|
|
568
|
+
else if (shape === "oval") {
|
|
569
|
+
}
|
|
555
570
|
const finalWidthPx = resolvedWidthPx;
|
|
556
571
|
const finalHeightPx = resolvedHeightPx;
|
|
557
572
|
const alignmentStyles = {
|
|
@@ -563,12 +578,14 @@ async function convertShapeBlock(blockData) {
|
|
|
563
578
|
const finalBackgroundColor = shapeColor || backgroundColor;
|
|
564
579
|
// --- Modern clients content ---
|
|
565
580
|
let nonMsoContent = "";
|
|
581
|
+
// For modern browsers, use CSS border-radius
|
|
582
|
+
const modernBorderRadius = shape === "oval" ? "50%" : resolvedBorderRadius;
|
|
566
583
|
// Case 1: Image + Text → use background-image
|
|
567
584
|
if (imageUrl && text) {
|
|
568
585
|
nonMsoContent = `
|
|
569
586
|
<div style="display:inline-block;width:${finalWidthPx}px;height:${finalHeightPx}px;
|
|
570
587
|
border:${borderWidth}px ${borderStyle} ${borderColor};
|
|
571
|
-
border-radius:${
|
|
588
|
+
border-radius:${modernBorderRadius};
|
|
572
589
|
background:${finalBackgroundColor} url('${imageUrl}') center/cover no-repeat;
|
|
573
590
|
overflow:hidden;${alignmentStyle}${customCss || ""}">
|
|
574
591
|
<div style="width:100%;height:100%;display:flex;align-items:center;justify-content:center;">
|
|
@@ -584,11 +601,11 @@ async function convertShapeBlock(blockData) {
|
|
|
584
601
|
nonMsoContent = `
|
|
585
602
|
<div style="display:inline-block;width:${finalWidthPx}px;height:${finalHeightPx}px;
|
|
586
603
|
border:${borderWidth}px ${borderStyle} ${borderColor};
|
|
587
|
-
border-radius:${
|
|
604
|
+
border-radius:${modernBorderRadius};
|
|
588
605
|
overflow:hidden;${alignmentStyle}${customCss || ""}">
|
|
589
606
|
<img src="${imageUrl}" alt="${text || "Shape image"}"
|
|
590
607
|
width="${finalWidthPx}" height="${finalHeightPx}"
|
|
591
|
-
style="width:100%;height:100%;object-fit:cover;border-radius:${
|
|
608
|
+
style="width:100%;height:100%;object-fit:cover;border-radius:${modernBorderRadius};display:block;" />
|
|
592
609
|
</div>`;
|
|
593
610
|
}
|
|
594
611
|
// Case 3: No image → solid background
|
|
@@ -597,7 +614,7 @@ async function convertShapeBlock(blockData) {
|
|
|
597
614
|
<div style="display:inline-block;width:${finalWidthPx}px;height:${finalHeightPx}px;
|
|
598
615
|
background:${finalBackgroundColor};
|
|
599
616
|
border:${borderWidth}px ${borderStyle} ${borderColor};
|
|
600
|
-
border-radius:${
|
|
617
|
+
border-radius:${modernBorderRadius};
|
|
601
618
|
${alignmentStyle}${customCss || ""}">
|
|
602
619
|
<div style="width:100%;height:100%;display:flex;align-items:center;justify-content:center;
|
|
603
620
|
color:${textColor};text-align:center;padding:8px;box-sizing:border-box;word-break:break-word;">
|
|
@@ -619,7 +636,7 @@ async function convertShapeBlock(blockData) {
|
|
|
619
636
|
textColor,
|
|
620
637
|
alignment,
|
|
621
638
|
padding,
|
|
622
|
-
msoBakeImageWithText
|
|
639
|
+
msoBakeImageWithText
|
|
623
640
|
});
|
|
624
641
|
// Wrap in container table
|
|
625
642
|
const containerTable = `
|