email-builder-utils 1.0.12 → 1.0.14
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC,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;CAClB;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;AASD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC,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;CAClB;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;AASD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;AAyDhF,wBAAsB,aAAa,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,mBAiB9F"}
|
package/dist/utils/jsonToHTML.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.tableCommonStyle = void 0;
|
|
|
4
4
|
exports.convertToHtml = convertToHtml;
|
|
5
5
|
const jimp_1 = require("jimp");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
|
-
const addPxToAttributes = ["fontSize", "lineHeight"];
|
|
7
|
+
const addPxToAttributes = ["fontSize", "lineHeight", "borderRadius"];
|
|
8
8
|
const addPxOrPerToAttributes = ["width", "height"];
|
|
9
9
|
const allPxAttributes = [...addPxToAttributes, ...addPxOrPerToAttributes];
|
|
10
10
|
exports.tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
@@ -34,6 +34,9 @@ function buildStyles(style, { pxChanges, perChanges }) {
|
|
|
34
34
|
}
|
|
35
35
|
const stylesObj = {};
|
|
36
36
|
Object.entries(style).forEach(([key, value]) => {
|
|
37
|
+
if (key === "customCss") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
37
40
|
const appendPx = pxChanges.includes(key);
|
|
38
41
|
const appendPer = perChanges.includes(key);
|
|
39
42
|
if (value === undefined || value === null || value === "")
|
|
@@ -54,7 +57,7 @@ function buildStyles(style, { pxChanges, perChanges }) {
|
|
|
54
57
|
}
|
|
55
58
|
return;
|
|
56
59
|
});
|
|
57
|
-
return jsonToPlainString(cleanJson(stylesObj)).trim();
|
|
60
|
+
return `${jsonToPlainString(cleanJson(stylesObj))}${style.customCss || ""}`.trim();
|
|
58
61
|
}
|
|
59
62
|
async function convertToHtml(blockData, rootData, cellWidthInPx) {
|
|
60
63
|
switch (blockData.type) {
|
|
@@ -109,7 +112,7 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
109
112
|
const scaledHeight = Math.round(originalHeight * widthScalingFactor); // Maintain aspect ratio
|
|
110
113
|
// VML for Outlook
|
|
111
114
|
const outlookImage = `<!--[if mso]>
|
|
112
|
-
<v:rect xmlns:v="urn:schemas-microsoft-com:vml"
|
|
115
|
+
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" style="width:${scaledWidth}px;height:${scaledHeight}px;" stroke="f">
|
|
113
116
|
<v:fill src="${imageUrl}" type="frame" />
|
|
114
117
|
</v:rect>
|
|
115
118
|
<![endif]-->`;
|
|
@@ -127,7 +130,7 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
127
130
|
const imageStyle = { width, height, objectFit };
|
|
128
131
|
const containerStyles = buildStyles(containerStyle, { perChanges: [], pxChanges: addPxToAttributes });
|
|
129
132
|
const imageTagStyles = buildStyles(imageStyle, { perChanges: addPxOrPerToAttributes, pxChanges: addPxToAttributes });
|
|
130
|
-
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}" />`;
|
|
133
|
+
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles};display:block;" />`;
|
|
131
134
|
const outlookImage = await appendOutlookForImage(imageElement, cellWidthInPx, ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) / 100) * (cellWidthInPx - style?.padding?.left - style?.padding?.right), imageUrl);
|
|
132
135
|
const imageContent = appendOutlookSupport(outlookImage, containerStyles);
|
|
133
136
|
return navigateToUrl ? `<a href="${navigateToUrl}" target="_blank" style="display:block; text-decoration:none; cursor:pointer;">${imageContent}</a>` : imageContent;
|
|
@@ -138,7 +141,7 @@ function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
|
138
141
|
<!--[if mso]>
|
|
139
142
|
<v:${borderRadius ? "roundrect" : "rect"} xmlns:v="urn:schemas-microsoft-com:vml" href="${navigateToUrl}" xmlns:w="urn:schemas-microsoft-com:office:word" style="height:${height || 44}px;width:${width || 200}px;v-text-anchor:middle;" arcsize="${borderRadius || 0}px" strokeweight="${borderWidth || 1}px" strokecolor="${borderColor || "transparent"}" fillcolor="${buttonColor || "none"}">
|
|
140
143
|
<w:anchorlock/>
|
|
141
|
-
<v:textbox inset="${buttonPadding?.
|
|
144
|
+
<v:textbox inset="${buttonPadding?.left || 0}px, ${buttonPadding?.top || 0}px, ${buttonPadding?.right || 0}px, ${buttonPadding?.bottom || 0}px">
|
|
142
145
|
<center style="font-family:${fontFamily || ""};font-size:${fontSize}px;font-weight:${fontWeight};color:${color};">${text}</center>
|
|
143
146
|
</v:textbox>
|
|
144
147
|
</v:${borderRadius ? "roundrect" : "rect"}>
|
|
@@ -151,8 +154,10 @@ function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
|
151
154
|
function convertButtonBlock(blockData) {
|
|
152
155
|
const { style, props } = blockData.data;
|
|
153
156
|
const { text, navigateToUrl } = props;
|
|
154
|
-
const { fontFamily, fontSize, fontWeight, borderColor, borderRadius, borderWidth, borderStyle, buttonPadding, textColor, buttonColor, ...rest } = style;
|
|
157
|
+
const { fontFamily, fontSize, fontWeight, borderColor, borderRadius, borderWidth, borderStyle, buttonPadding, textColor, buttonColor, width, height, ...rest } = style;
|
|
155
158
|
const buttonStyle = {
|
|
159
|
+
width,
|
|
160
|
+
height,
|
|
156
161
|
fontFamily,
|
|
157
162
|
fontSize,
|
|
158
163
|
fontWeight,
|