email-builder-utils 1.1.27 → 1.1.28
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/types/Template.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Template.d.ts","sourceRoot":"","sources":["../../src/types/Template.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,IAAI,YAAY;IAChB,KAAK,UAAU;IACf,QAAQ,WAAW;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"Template.d.ts","sourceRoot":"","sources":["../../src/types/Template.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,IAAI,YAAY;IAChB,KAAK,UAAU;IACf,QAAQ,WAAW;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,WAAW,gBAAgB;CAC5B;AAED,UAAU,MAAM;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,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,MAAM;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACH"}
|
package/dist/types/Template.js
CHANGED
|
@@ -14,6 +14,7 @@ var BlockType;
|
|
|
14
14
|
BlockType["EMAILLAYOUT"] = "EmailLayout";
|
|
15
15
|
BlockType["VIDEO"] = "Video";
|
|
16
16
|
BlockType["SHAPE"] = "Shape";
|
|
17
|
+
BlockType["VDivider"] = "VDivider";
|
|
17
18
|
})(BlockType || (exports.BlockType = BlockType = {}));
|
|
18
19
|
var visibility;
|
|
19
20
|
(function (visibility) {
|
|
@@ -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;
|
|
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;AAYD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;AA2DhF,wBAAsB,aAAa,CACjC,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,GAAG,EACb,aAAa,EAAE,MAAM,mBAwBtB;AAobD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,mBA8K5E"}
|
package/dist/utils/jsonToHTML.js
CHANGED
|
@@ -6,7 +6,12 @@ exports.convertVideoBlock = convertVideoBlock;
|
|
|
6
6
|
const jimp_1 = require("jimp");
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const common_1 = require("./common");
|
|
9
|
-
const addPxToAttributes = [
|
|
9
|
+
const addPxToAttributes = [
|
|
10
|
+
"fontSize",
|
|
11
|
+
"lineHeight",
|
|
12
|
+
"borderRadius",
|
|
13
|
+
"borderWidth",
|
|
14
|
+
];
|
|
10
15
|
const addPxOrPerToAttributes = ["width", "height"];
|
|
11
16
|
const allPxAttributes = [...addPxToAttributes, ...addPxOrPerToAttributes];
|
|
12
17
|
exports.tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
@@ -37,7 +42,8 @@ function buildStyles(style, { pxChanges, perChanges }) {
|
|
|
37
42
|
return;
|
|
38
43
|
if (value === undefined || value === null || value === "")
|
|
39
44
|
return;
|
|
40
|
-
if ((key === "padding" || key === "buttonPadding") &&
|
|
45
|
+
if ((key === "padding" || key === "buttonPadding") &&
|
|
46
|
+
typeof value === "object") {
|
|
41
47
|
const padding = value;
|
|
42
48
|
value = `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`;
|
|
43
49
|
}
|
|
@@ -72,6 +78,8 @@ async function convertToHtml(blockData, rootData, cellWidthInPx) {
|
|
|
72
78
|
return convertVideoBlock(blockData, cellWidthInPx);
|
|
73
79
|
case types_1.BlockType.SHAPE:
|
|
74
80
|
return await convertShapeBlock(blockData);
|
|
81
|
+
case types_1.BlockType.VDivider:
|
|
82
|
+
return convertVerticalDividerBlockToHtml(blockData);
|
|
75
83
|
default:
|
|
76
84
|
return "";
|
|
77
85
|
}
|
|
@@ -124,20 +132,36 @@ function convertSpacerBlockToHtml(blockData) {
|
|
|
124
132
|
function convertTextBlock(blockData) {
|
|
125
133
|
const { style, props } = blockData.data;
|
|
126
134
|
const { width, backgroundColor, padding, borderRadius, borderStyle, borderColor, borderWidth, textContainerBackgroundColor, textContainerPadding, ...rest } = style;
|
|
127
|
-
const textBoxStyle = {
|
|
135
|
+
const textBoxStyle = {
|
|
136
|
+
width,
|
|
137
|
+
backgroundColor,
|
|
138
|
+
padding,
|
|
139
|
+
borderRadius,
|
|
140
|
+
borderStyle,
|
|
141
|
+
borderColor,
|
|
142
|
+
borderWidth,
|
|
143
|
+
};
|
|
128
144
|
const convertedTextStyle = buildStyles(textBoxStyle, {
|
|
129
145
|
perChanges: [],
|
|
130
146
|
pxChanges: allPxAttributes,
|
|
131
147
|
});
|
|
132
|
-
const styles = buildStyles({
|
|
148
|
+
const styles = buildStyles({
|
|
149
|
+
padding: textContainerPadding,
|
|
150
|
+
backgroundColor: textContainerBackgroundColor,
|
|
151
|
+
...rest,
|
|
152
|
+
}, {
|
|
133
153
|
perChanges: [],
|
|
134
154
|
pxChanges: allPxAttributes,
|
|
135
155
|
});
|
|
136
|
-
const sanitizedText = (props.text ?? "")
|
|
156
|
+
const sanitizedText = (props.text ?? "")
|
|
157
|
+
.replaceAll(/<p>/g, "<div>")
|
|
158
|
+
.replaceAll(/<\/p>/g, "</div>");
|
|
137
159
|
const navigateToUrl = props.navigateToUrl || "";
|
|
138
160
|
const convertedTextBox = `<div style="display: inline-block; max-width: 100%; box-sizing: border-box; ${convertedTextStyle}">${sanitizedText.replaceAll(/\n/g, "<br>")}</div>`;
|
|
139
161
|
const textContent = appendOutlookSupport(convertedTextBox, styles);
|
|
140
|
-
return navigateToUrl
|
|
162
|
+
return navigateToUrl
|
|
163
|
+
? `<a href="${navigateToUrl}" rel="noreferrer noopener" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>`
|
|
164
|
+
: textContent;
|
|
141
165
|
}
|
|
142
166
|
async function appendOutlookForImage(content, outerContainerWidth, innerContainerWidth, imageUrl, style = {}) {
|
|
143
167
|
const image = await jimp_1.Jimp.read(imageUrl);
|
|
@@ -150,8 +174,12 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
150
174
|
const borderColor = style?.borderColor || "transparent";
|
|
151
175
|
const borderRadius = parseInt(style?.borderRadius) || 0;
|
|
152
176
|
const useRoundRect = borderRadius > 0;
|
|
153
|
-
const arcsize = useRoundRect
|
|
154
|
-
|
|
177
|
+
const arcsize = useRoundRect
|
|
178
|
+
? Math.min(borderRadius / scaledHeight, 1).toFixed(2)
|
|
179
|
+
: "";
|
|
180
|
+
const borderAttributes = borderWidth > 0
|
|
181
|
+
? `strokeweight="${borderWidth}px" strokecolor="${borderColor}"`
|
|
182
|
+
: `stroked="false"`;
|
|
155
183
|
const outlookImage = `<!--[if mso]>
|
|
156
184
|
<v:${useRoundRect ? "roundrect" : "rect"} xmlns:v="urn:schemas-microsoft-com:vml"
|
|
157
185
|
style="width:${scaledWidth}px;height:${scaledHeight}px;"
|
|
@@ -196,7 +224,11 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
196
224
|
pxChanges: addPxToAttributes,
|
|
197
225
|
});
|
|
198
226
|
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}; max-width: ${originalWidth}px; max-height: ${originalHeight}px;" />`;
|
|
199
|
-
const innerContainerWidth = ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) /
|
|
227
|
+
const innerContainerWidth = ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) /
|
|
228
|
+
100) *
|
|
229
|
+
(cellWidthInPx -
|
|
230
|
+
(style?.padding?.left || 0) -
|
|
231
|
+
(style?.padding?.right || 0));
|
|
200
232
|
const outlookImage = await appendOutlookForImage(imageElement, cellWidthInPx, innerContainerWidth, imageUrl, style);
|
|
201
233
|
const imageContent = appendOutlookSupport(outlookImage, containerStyles);
|
|
202
234
|
return navigateToUrl
|
|
@@ -205,7 +237,9 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
205
237
|
}
|
|
206
238
|
function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
207
239
|
const { width = 200, height = 44, borderRadius = 0, borderColor = "transparent", borderWidth = 0, buttonColor = "none", buttonPadding = { top: 0, bottom: 0, left: 0, right: 0 }, color = "#000000", fontFamily = "Arial, sans-serif", fontSize = 16, fontWeight = 400, } = buttonStyle;
|
|
208
|
-
const borderAttributes = borderWidth > 0
|
|
240
|
+
const borderAttributes = borderWidth > 0
|
|
241
|
+
? `strokeweight="${borderWidth}px" strokecolor="${borderColor}"`
|
|
242
|
+
: `stroked="false"`;
|
|
209
243
|
return `
|
|
210
244
|
<!--[if mso]>
|
|
211
245
|
<v:${borderRadius ? "roundrect" : "rect"} xmlns:v="urn:schemas-microsoft-com:vml" href="${navigateToUrl}"
|
|
@@ -387,7 +421,9 @@ async function convertVideoBlock(blockData, cellWidthInPx) {
|
|
|
387
421
|
<v:rect fill="t" style="position:absolute;width:${innerContainerWidth}px;height:${calculatedHeight}px; stroked="t"
|
|
388
422
|
strokeweight="${borderWidth}px"
|
|
389
423
|
strokecolor="${borderColor}"
|
|
390
|
-
${borderRadius > 0
|
|
424
|
+
${borderRadius > 0
|
|
425
|
+
? `arcsize="${Math.min(borderRadius / calculatedHeight, 1).toFixed(2)}"`
|
|
426
|
+
: ""}
|
|
391
427
|
>
|
|
392
428
|
<v:fill src="${resolvedThumbnail}" type="frame" color="${style?.backgroundColor || "#FFFFFF"}"/>
|
|
393
429
|
</v:rect>
|
|
@@ -613,9 +649,7 @@ function buildVMLShape({ shape, widthPx, heightPx, imageUrl, backgroundColor, bo
|
|
|
613
649
|
// --- Basic setup ---
|
|
614
650
|
const bw = borderWidth || 0;
|
|
615
651
|
const bc = borderColor || "transparent";
|
|
616
|
-
const borderAttrs = bw > 0
|
|
617
|
-
? `strokeweight="${bw}px" strokecolor="${bc}"`
|
|
618
|
-
: `stroked="false"`;
|
|
652
|
+
const borderAttrs = bw > 0 ? `strokeweight="${bw}px" strokecolor="${bc}"` : `stroked="false"`;
|
|
619
653
|
const fillColor = backgroundColor || "#2F80ED";
|
|
620
654
|
const fillMarkup = `<v:fill ${imageUrl ? `src="${imageUrl}" type="frame" aspect="atleast"` : ""} color="${fillColor}" />`;
|
|
621
655
|
// --- Shape tag ---
|
|
@@ -689,3 +723,28 @@ async function appendOutlookForShape(content, outerContainerWidth, innerContaine
|
|
|
689
723
|
</table>
|
|
690
724
|
<![endif]-->`;
|
|
691
725
|
}
|
|
726
|
+
function convertVerticalDividerBlockToHtml(blockData) {
|
|
727
|
+
const { style } = blockData.data;
|
|
728
|
+
const { width, height, dividerColor, ...rest } = style;
|
|
729
|
+
// Convert other styles to inline-safe HTML attributes
|
|
730
|
+
const convertedStyle = buildStyles(rest, {
|
|
731
|
+
perChanges: [],
|
|
732
|
+
pxChanges: allPxAttributes,
|
|
733
|
+
});
|
|
734
|
+
// Outlook-safe vertical divider
|
|
735
|
+
const dividerContent = `
|
|
736
|
+
<table cellpadding="0" cellspacing="0" border="0" align="center" style="width:auto; ${convertedStyle}">
|
|
737
|
+
<tr>
|
|
738
|
+
<td style="vertical-align: middle; text-align: center;">
|
|
739
|
+
<!--[if mso | IE]>
|
|
740
|
+
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fillcolor="${dividerColor}" style="width:${width}px;height:${height}px;" stroke="f"></v:rect>
|
|
741
|
+
<![endif]-->
|
|
742
|
+
<!--[if !mso]><!-- -->
|
|
743
|
+
<div style="display:inline-block;width:${width}px;height:${height}px;background:${dividerColor};line-height:0;font-size:0;"> </div>
|
|
744
|
+
<!--<![endif]-->
|
|
745
|
+
</td>
|
|
746
|
+
</tr>
|
|
747
|
+
</table>
|
|
748
|
+
`;
|
|
749
|
+
return appendOutlookSupport(dividerContent, convertedStyle);
|
|
750
|
+
}
|