email-builder-utils 1.1.19 → 1.1.21
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/utils/jsonToHTML.js +33 -5
- package/package.json +1 -1
package/dist/utils/jsonToHTML.js
CHANGED
|
@@ -111,15 +111,40 @@ function convertSpacerBlockToHtml(blockData) {
|
|
|
111
111
|
});
|
|
112
112
|
return appendOutlookSupport(``, styles);
|
|
113
113
|
}
|
|
114
|
+
// function convertTextBlock(blockData: IBlockData) {
|
|
115
|
+
// const { style, props } = blockData.data;
|
|
116
|
+
// const styles = buildStyles(style, {
|
|
117
|
+
// perChanges: [],
|
|
118
|
+
// pxChanges: allPxAttributes,
|
|
119
|
+
// });
|
|
120
|
+
// const text = props.text || "";
|
|
121
|
+
// const navigateToUrl = props.navigateToUrl || "";
|
|
122
|
+
// const textContent = appendOutlookSupport(
|
|
123
|
+
// text.replaceAll(/\n/g, "<br>"),
|
|
124
|
+
// styles
|
|
125
|
+
// );
|
|
126
|
+
// return navigateToUrl
|
|
127
|
+
// ? `<a href="${navigateToUrl}" rel="noreferrer noopener" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>`
|
|
128
|
+
// : textContent;
|
|
129
|
+
// }
|
|
114
130
|
function convertTextBlock(blockData) {
|
|
115
131
|
const { style, props } = blockData.data;
|
|
116
|
-
const
|
|
132
|
+
const { width, backgroundColor, padding, borderRadius, borderStyle, borderColor, borderWidth, textContainerBackgroundColor, textContainerPadding, ...rest } = style;
|
|
133
|
+
const textBoxStyle = { width, backgroundColor, padding, borderRadius, borderStyle, borderColor, borderWidth };
|
|
134
|
+
const convertedTextStyle = buildStyles(textBoxStyle, {
|
|
135
|
+
perChanges: [],
|
|
136
|
+
pxChanges: allPxAttributes,
|
|
137
|
+
});
|
|
138
|
+
const styles = buildStyles({ padding: textContainerPadding, backgroundColor: textContainerBackgroundColor, ...rest }, {
|
|
117
139
|
perChanges: [],
|
|
118
140
|
pxChanges: allPxAttributes,
|
|
119
141
|
});
|
|
120
|
-
const
|
|
142
|
+
const sanitizedText = (props.text ?? "")
|
|
143
|
+
.replaceAll(/<p>/g, "<div>")
|
|
144
|
+
.replaceAll(/<\/p>/g, "</div>");
|
|
121
145
|
const navigateToUrl = props.navigateToUrl || "";
|
|
122
|
-
const
|
|
146
|
+
const convertedTextBox = `<div style="display: inline-block; max-width: 100%; box-sizing: border-box; ${convertedTextStyle}">${sanitizedText.replaceAll(/\n/g, "<br>")}</div>`;
|
|
147
|
+
const textContent = appendOutlookSupport(convertedTextBox, styles);
|
|
123
148
|
return navigateToUrl
|
|
124
149
|
? `<a href="${navigateToUrl}" rel="noreferrer noopener" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>`
|
|
125
150
|
: textContent;
|
|
@@ -171,6 +196,9 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
171
196
|
borderRadius: borderRadius,
|
|
172
197
|
borderColor,
|
|
173
198
|
};
|
|
199
|
+
const image = await jimp_1.Jimp.read(imageUrl);
|
|
200
|
+
const originalWidth = image.bitmap.width;
|
|
201
|
+
const originalHeight = image.bitmap.height;
|
|
174
202
|
// Add border styles to container for fallback clients
|
|
175
203
|
const containerStyles = buildStyles({
|
|
176
204
|
...containerStyle,
|
|
@@ -179,7 +207,7 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
179
207
|
perChanges: addPxOrPerToAttributes,
|
|
180
208
|
pxChanges: addPxToAttributes,
|
|
181
209
|
});
|
|
182
|
-
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}" />`;
|
|
210
|
+
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}; max-width: ${originalWidth}px; max-height: ${originalHeight}px;" />`;
|
|
183
211
|
const innerContainerWidth = ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) /
|
|
184
212
|
100) *
|
|
185
213
|
(cellWidthInPx -
|
|
@@ -237,7 +265,7 @@ function convertButtonBlock(blockData) {
|
|
|
237
265
|
perChanges: [],
|
|
238
266
|
pxChanges: allPxAttributes,
|
|
239
267
|
});
|
|
240
|
-
const convertedStyles = buildStyles(rest, {
|
|
268
|
+
const convertedStyles = buildStyles({ maxWidth: "100%", boxSizing: "border-box", ...rest }, {
|
|
241
269
|
perChanges: [],
|
|
242
270
|
pxChanges: allPxAttributes,
|
|
243
271
|
});
|