email-builder-utils 1.0.8 → 1.0.10

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.
@@ -1,2 +1,2 @@
1
- export declare const convertJsonToHtml: (jsonData: any) => string;
1
+ export declare const convertJsonToHtml: (jsonData: any) => Promise<string>;
2
2
  //# sourceMappingURL=convertJsonToHtml.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convertJsonToHtml.d.ts","sourceRoot":"","sources":["../../src/utils/convertJsonToHtml.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAI,UAAU,GAAG,WA6B9C,CAAA"}
1
+ {"version":3,"file":"convertJsonToHtml.d.ts","sourceRoot":"","sources":["../../src/utils/convertJsonToHtml.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAU,UAAU,GAAG,oBAgCpD,CAAA"}
@@ -2,9 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertJsonToHtml = void 0;
4
4
  const jsonToHTML_1 = require("./jsonToHTML");
5
- const convertJsonToHtml = (jsonData) => {
5
+ const convertJsonToHtml = async (jsonData) => {
6
6
  const rootData = jsonData?.root?.data;
7
- const blocksHtml = rootData?.childrenIds.map((childId) => (0, jsonToHTML_1.convertToHtml)(jsonData[childId], jsonData, 600)).join("");
7
+ const blocksHtml = [];
8
+ for (const childId of rootData?.childrenIds) {
9
+ blocksHtml.push(await (0, jsonToHTML_1.convertToHtml)(jsonData[childId], jsonData, 600));
10
+ }
8
11
  const rawHtml = `
9
12
  <!DOCTYPE html>
10
13
  <html lang="en">
@@ -23,7 +26,7 @@ const convertJsonToHtml = (jsonData) => {
23
26
  <table class="responsive-table" style="font-family:${rootData.style?.fontFamily}; margin:0 auto; background-color:${rootData.style?.canvasColor}; color:${rootData.style?.textColor}; ${jsonToHTML_1.tableCommonStyle}">
24
27
  <tbody>
25
28
  <tr>
26
- <td style="padding:0;">${blocksHtml}</td>
29
+ <td style="padding:0;">${blocksHtml.join("")}</td>
27
30
  </tr>
28
31
  </tbody>
29
32
  </table>
@@ -100,7 +100,7 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
100
100
  const originalWidth = image.bitmap.width;
101
101
  const originalHeight = image.bitmap.height;
102
102
  // Calculate width scaling factor based on outer and inner widths
103
- const widthScalingFactor = Math.min(outerContainerWidth / originalWidth, innerContainerWidth / originalWidth, 1);
103
+ const widthScalingFactor = Math.min(outerContainerWidth / originalWidth, innerContainerWidth / originalWidth);
104
104
  // Scale the height proportionally
105
105
  const scaledWidth = Math.round(originalWidth * widthScalingFactor);
106
106
  const scaledHeight = Math.round(originalHeight * widthScalingFactor); // Maintain aspect ratio
@@ -125,7 +125,7 @@ async function convertImageBlock(blockData, cellWidthInPx) {
125
125
  const containerStyles = buildStyles(containerStyle, { perChanges: [], pxChanges: addPxToAttributes });
126
126
  const imageTagStyles = buildStyles(imageStyle, { perChanges: addPxOrPerToAttributes, pxChanges: addPxToAttributes });
127
127
  const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}" />`;
128
- const outlookImage = await appendOutlookForImage(imageElement, cellWidthInPx, parseInt(width.replace("%", "")) * cellWidthInPx, imageUrl);
128
+ const outlookImage = await appendOutlookForImage(imageElement, cellWidthInPx, ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) / 100) * cellWidthInPx, imageUrl);
129
129
  const imageContent = appendOutlookSupport(outlookImage, containerStyles);
130
130
  return navigateToUrl ? `<a href="${navigateToUrl}" target="_blank" style="display:block; text-decoration:none; cursor:pointer;">${imageContent}</a>` : imageContent;
131
131
  }
@@ -201,7 +201,7 @@ async function convertGridCellBlock(blockData, rootData, cellWidth, parentCellWi
201
201
  const cellItems = [];
202
202
  if (childrenIds && childrenIds?.length > 0) {
203
203
  for (const childId of childrenIds) {
204
- cellItems.push(await convertToHtml(rootData[childId], rootData, parentCellWidth * ((style.width || "0").replace("px", "") / 100)));
204
+ cellItems.push(await convertToHtml(rootData[childId], rootData, parentCellWidth * (cellWidth || 0) / 100));
205
205
  }
206
206
  }
207
207
  return `<td style="width:${cellWidth}% ; max-width:${cellWidth}%; ${styles}">${cellItems.join("")}</td>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-builder-utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [