email-builder-utils 1.1.3 → 1.1.7
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/Generics.d.ts +4 -4
- package/dist/types/Generics.js +4 -4
- package/dist/utils/jsonToHTML.js +48 -22
- package/package.json +1 -1
package/dist/types/Generics.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ export declare enum FEATURE_TYPE {
|
|
|
38
38
|
GET_ORG = "GET_ORG",
|
|
39
39
|
DELETE_ORG = "DELETE_ORG",
|
|
40
40
|
UPDATE_ORG = "UPDATE_ORG",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
ADD_ORG_USER = "ADD_ORG_USER",
|
|
42
|
+
LIST_ORG_USER = "LIST_ORG_USER",
|
|
43
|
+
DELETE_ORG_USER = "DELETE_ORG_USER",
|
|
44
|
+
UPDATE_ORG_USER = "UPDATE_ORG_USER"
|
|
45
45
|
}
|
|
46
46
|
//# sourceMappingURL=Generics.d.ts.map
|
package/dist/types/Generics.js
CHANGED
|
@@ -50,8 +50,8 @@ var FEATURE_TYPE;
|
|
|
50
50
|
FEATURE_TYPE["DELETE_ORG"] = "DELETE_ORG";
|
|
51
51
|
FEATURE_TYPE["UPDATE_ORG"] = "UPDATE_ORG";
|
|
52
52
|
// Manage Org Users
|
|
53
|
-
FEATURE_TYPE["
|
|
54
|
-
FEATURE_TYPE["
|
|
55
|
-
FEATURE_TYPE["
|
|
56
|
-
FEATURE_TYPE["
|
|
53
|
+
FEATURE_TYPE["ADD_ORG_USER"] = "ADD_ORG_USER";
|
|
54
|
+
FEATURE_TYPE["LIST_ORG_USER"] = "LIST_ORG_USER";
|
|
55
|
+
FEATURE_TYPE["DELETE_ORG_USER"] = "DELETE_ORG_USER";
|
|
56
|
+
FEATURE_TYPE["UPDATE_ORG_USER"] = "UPDATE_ORG_USER";
|
|
57
57
|
})(FEATURE_TYPE || (exports.FEATURE_TYPE = FEATURE_TYPE = {}));
|
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", "borderWidth"];
|
|
8
8
|
const addPxOrPerToAttributes = ["width", "height"];
|
|
9
9
|
const allPxAttributes = [...addPxToAttributes, ...addPxOrPerToAttributes];
|
|
10
10
|
exports.tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
@@ -41,10 +41,10 @@ function buildStyles(style, { pxChanges, perChanges }) {
|
|
|
41
41
|
}
|
|
42
42
|
const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
43
43
|
if (pxChanges.includes(key)) {
|
|
44
|
-
stylesObj[cssKey] = `${value}px
|
|
44
|
+
stylesObj[cssKey] = typeof value === "number" ? `${value}px` : value;
|
|
45
45
|
}
|
|
46
46
|
else if (perChanges.includes(key)) {
|
|
47
|
-
stylesObj[cssKey] = `${value}
|
|
47
|
+
stylesObj[cssKey] = typeof value === "number" ? `${value}%` : value;
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
stylesObj[cssKey] = value;
|
|
@@ -75,11 +75,24 @@ function appendOutlookSupport(content, contentStyle) {
|
|
|
75
75
|
<table width="100%" style="${exports.tableCommonStyle}"><tr><td style="${contentStyle}">${content}</td></tr></table>
|
|
76
76
|
`;
|
|
77
77
|
}
|
|
78
|
+
// function convertDividerBlockToHtml(blockData: IBlockData) {
|
|
79
|
+
// const { style } = blockData.data;
|
|
80
|
+
// const { thickness, dividerColor, ...rest } = style;
|
|
81
|
+
// const convertedStyle = buildStyles(rest, {perChanges: [], pxChanges: allPxAttributes});
|
|
82
|
+
// return appendOutlookSupport(`<hr style="height:${thickness}px; background-color: ${dividerColor};" />`, convertedStyle);
|
|
83
|
+
// }
|
|
78
84
|
function convertDividerBlockToHtml(blockData) {
|
|
79
85
|
const { style } = blockData.data;
|
|
80
86
|
const { thickness, dividerColor, ...rest } = style;
|
|
81
87
|
const convertedStyle = buildStyles(rest, { perChanges: [], pxChanges: allPxAttributes });
|
|
82
|
-
|
|
88
|
+
const dividerContent = `
|
|
89
|
+
<table width="100%" cellpadding="0" cellspacing="0">
|
|
90
|
+
<tr>
|
|
91
|
+
<td height="${thickness}" style="font-size:1px; line-height:1px; background:${dividerColor};"> </td>
|
|
92
|
+
</tr>
|
|
93
|
+
</table>
|
|
94
|
+
`;
|
|
95
|
+
return appendOutlookSupport(dividerContent, convertedStyle);
|
|
83
96
|
}
|
|
84
97
|
function convertSpacerBlockToHtml(blockData) {
|
|
85
98
|
const { style } = blockData.data;
|
|
@@ -98,18 +111,16 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
98
111
|
const image = await jimp_1.Jimp.read(imageUrl);
|
|
99
112
|
const originalWidth = image.bitmap.width;
|
|
100
113
|
const originalHeight = image.bitmap.height;
|
|
101
|
-
// Calculate width scaling factor based on outer and inner widths
|
|
102
114
|
const widthScalingFactor = Math.min(outerContainerWidth / originalWidth, innerContainerWidth / originalWidth);
|
|
103
|
-
// Scale height proportionally
|
|
104
115
|
const scaledWidth = Math.round(originalWidth * widthScalingFactor);
|
|
105
|
-
const scaledHeight = Math.round(originalHeight * widthScalingFactor);
|
|
106
|
-
|
|
107
|
-
const borderWidth = style?.borderWidth || 0;
|
|
116
|
+
const scaledHeight = Math.round(originalHeight * widthScalingFactor);
|
|
117
|
+
const borderWidth = parseInt(style?.borderWidth) || 0;
|
|
108
118
|
const borderColor = style?.borderColor || "transparent";
|
|
109
|
-
const borderRadius = style?.borderRadius || 0;
|
|
119
|
+
const borderRadius = parseInt(style?.borderRadius) || 0;
|
|
110
120
|
const useRoundRect = borderRadius > 0;
|
|
111
|
-
const arcsize = useRoundRect
|
|
112
|
-
|
|
121
|
+
const arcsize = useRoundRect
|
|
122
|
+
? Math.min(borderRadius / scaledHeight, 1).toFixed(2)
|
|
123
|
+
: "";
|
|
113
124
|
const borderAttributes = borderWidth > 0
|
|
114
125
|
? `strokeweight="${borderWidth}px" strokecolor="${borderColor}"`
|
|
115
126
|
: `stroked="false"`;
|
|
@@ -118,8 +129,7 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
118
129
|
style="width:${scaledWidth}px;height:${scaledHeight}px;"
|
|
119
130
|
${borderAttributes}
|
|
120
131
|
${useRoundRect ? `arcsize="${arcsize}"` : ""}
|
|
121
|
-
fill="true"
|
|
122
|
-
fillcolor="none">
|
|
132
|
+
fill="true" fillcolor="none">
|
|
123
133
|
<v:fill src="${imageUrl}" type="frame" />
|
|
124
134
|
<v:textbox inset="0,0,0,0"><div style="display:none;">.</div></v:textbox>
|
|
125
135
|
</v:${useRoundRect ? "roundrect" : "rect"}>
|
|
@@ -134,16 +144,32 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
134
144
|
async function convertImageBlock(blockData, cellWidthInPx) {
|
|
135
145
|
const { style, props } = blockData.data;
|
|
136
146
|
const { altText, imageUrl, navigateToUrl } = props;
|
|
137
|
-
const { width, height, objectFit, ...containerStyle } = style;
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
147
|
+
const { width, height, objectFit, borderRadius, borderWidth, borderColor, borderStyle, ...containerStyle } = style;
|
|
148
|
+
// Ensure border styles are applied only to the container, not the image
|
|
149
|
+
const imageStyle = {
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
objectFit,
|
|
153
|
+
borderStyle,
|
|
154
|
+
borderRadius: borderRadius,
|
|
155
|
+
borderColor
|
|
156
|
+
};
|
|
157
|
+
// Add border styles to container for fallback clients
|
|
158
|
+
const containerStyles = buildStyles({
|
|
159
|
+
...containerStyle,
|
|
160
|
+
}, { perChanges: [], pxChanges: addPxToAttributes });
|
|
161
|
+
const imageTagStyles = buildStyles(imageStyle, {
|
|
162
|
+
perChanges: addPxOrPerToAttributes,
|
|
163
|
+
pxChanges: addPxToAttributes,
|
|
164
|
+
});
|
|
141
165
|
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}" />`;
|
|
142
|
-
const
|
|
143
|
-
(cellWidthInPx - style?.padding?.left - style?.padding?.right
|
|
166
|
+
const innerContainerWidth = ((typeof width === "string" ? parseInt(width.replace("%", "")) : width) / 100) *
|
|
167
|
+
(cellWidthInPx - (style?.padding?.left || 0) - (style?.padding?.right || 0));
|
|
168
|
+
const outlookImage = await appendOutlookForImage(imageElement, cellWidthInPx, innerContainerWidth, imageUrl, style);
|
|
144
169
|
const imageContent = appendOutlookSupport(outlookImage, containerStyles);
|
|
145
|
-
|
|
146
|
-
|
|
170
|
+
return navigateToUrl
|
|
171
|
+
? `<a href="${navigateToUrl}" target="_blank" style="display:block; text-decoration:none; cursor:pointer;">${imageContent}</a>`
|
|
172
|
+
: imageContent;
|
|
147
173
|
}
|
|
148
174
|
function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
149
175
|
const { width, buttonColor, borderColor, borderRadius, borderWidth, height, buttonPadding, color, fontFamily, fontSize, fontWeight } = buttonStyle;
|