email-builder-utils 1.1.2 → 1.1.5
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/convertJsonToHtml.js +42 -42
- package/dist/utils/jsonToHTML.js +50 -37
- package/package.json +33 -33
|
@@ -11,48 +11,48 @@ const convertJsonToHtml = async (jsonData) => {
|
|
|
11
11
|
(rootData.style?.padding?.left || 0) -
|
|
12
12
|
(rootData.style?.padding?.right || 0)));
|
|
13
13
|
}
|
|
14
|
-
const rawHtml = `
|
|
15
|
-
<!DOCTYPE html>
|
|
16
|
-
<html lang="en">
|
|
17
|
-
<head>
|
|
18
|
-
<meta charset="UTF-8" />
|
|
19
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
20
|
-
<title>Email Layout</title>
|
|
21
|
-
<style>
|
|
22
|
-
.responsive-table {
|
|
23
|
-
width: 100%;
|
|
24
|
-
max-width: 600px;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@media only screen and (max-width: 600px) {
|
|
28
|
-
.stack-column {
|
|
29
|
-
display: block !important;
|
|
30
|
-
width: 100% !important;
|
|
31
|
-
max-width: 100% !important;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
</style>
|
|
35
|
-
</head>
|
|
36
|
-
<body>
|
|
37
|
-
<center>
|
|
38
|
-
<table
|
|
39
|
-
class="responsive-table"
|
|
40
|
-
style="font-family: ${rootData.style?.fontFamily};
|
|
41
|
-
margin: 0 auto;
|
|
42
|
-
background-color: ${rootData.style?.canvasColor};
|
|
43
|
-
color: ${rootData.style?.textColor};
|
|
44
|
-
${jsonToHTML_1.tableCommonStyle}"
|
|
45
|
-
>
|
|
46
|
-
<tbody>
|
|
47
|
-
<tr>
|
|
48
|
-
<td style="padding: 0;">
|
|
49
|
-
${blocksHtml.join("")}
|
|
50
|
-
</td>
|
|
51
|
-
</tr>
|
|
52
|
-
</tbody>
|
|
53
|
-
</table>
|
|
54
|
-
</center>
|
|
55
|
-
</body>
|
|
14
|
+
const rawHtml = `
|
|
15
|
+
<!DOCTYPE html>
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<head>
|
|
18
|
+
<meta charset="UTF-8" />
|
|
19
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
20
|
+
<title>Email Layout</title>
|
|
21
|
+
<style>
|
|
22
|
+
.responsive-table {
|
|
23
|
+
width: 100%;
|
|
24
|
+
max-width: 600px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@media only screen and (max-width: 600px) {
|
|
28
|
+
.stack-column {
|
|
29
|
+
display: block !important;
|
|
30
|
+
width: 100% !important;
|
|
31
|
+
max-width: 100% !important;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<center>
|
|
38
|
+
<table
|
|
39
|
+
class="responsive-table"
|
|
40
|
+
style="font-family: ${rootData.style?.fontFamily};
|
|
41
|
+
margin: 0 auto;
|
|
42
|
+
background-color: ${rootData.style?.canvasColor};
|
|
43
|
+
color: ${rootData.style?.textColor};
|
|
44
|
+
${jsonToHTML_1.tableCommonStyle}"
|
|
45
|
+
>
|
|
46
|
+
<tbody>
|
|
47
|
+
<tr>
|
|
48
|
+
<td style="padding: 0;">
|
|
49
|
+
${blocksHtml.join("")}
|
|
50
|
+
</td>
|
|
51
|
+
</tr>
|
|
52
|
+
</tbody>
|
|
53
|
+
</table>
|
|
54
|
+
</center>
|
|
55
|
+
</body>
|
|
56
56
|
</html>`;
|
|
57
57
|
return rawHtml;
|
|
58
58
|
};
|
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;";
|
|
@@ -71,15 +71,28 @@ async function convertToHtml(blockData, rootData, cellWidthInPx) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
function appendOutlookSupport(content, contentStyle) {
|
|
74
|
-
return `
|
|
75
|
-
<table width="100%" style="${exports.tableCommonStyle}"><tr><td style="${contentStyle}">${content}</td></tr></table>
|
|
74
|
+
return `
|
|
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;
|
|
@@ -113,22 +126,22 @@ async function appendOutlookForImage(content, outerContainerWidth, innerContaine
|
|
|
113
126
|
const borderAttributes = borderWidth > 0
|
|
114
127
|
? `strokeweight="${borderWidth}px" strokecolor="${borderColor}"`
|
|
115
128
|
: `stroked="false"`;
|
|
116
|
-
const outlookImage = `<!--[if mso]>
|
|
117
|
-
<v:${useRoundRect ? "roundrect" : "rect"} xmlns:v="urn:schemas-microsoft-com:vml"
|
|
118
|
-
style="width:${scaledWidth}px;height:${scaledHeight}px;"
|
|
119
|
-
${borderAttributes}
|
|
120
|
-
${useRoundRect ? `arcsize="${arcsize}"` : ""}
|
|
121
|
-
fill="true"
|
|
122
|
-
fillcolor="none">
|
|
123
|
-
<v:fill src="${imageUrl}" type="frame" />
|
|
124
|
-
<v:textbox inset="0,0,0,0"><div style="display:none;">.</div></v:textbox>
|
|
125
|
-
</v:${useRoundRect ? "roundrect" : "rect"}>
|
|
129
|
+
const outlookImage = `<!--[if mso]>
|
|
130
|
+
<v:${useRoundRect ? "roundrect" : "rect"} xmlns:v="urn:schemas-microsoft-com:vml"
|
|
131
|
+
style="width:${scaledWidth}px;height:${scaledHeight}px;"
|
|
132
|
+
${borderAttributes}
|
|
133
|
+
${useRoundRect ? `arcsize="${arcsize}"` : ""}
|
|
134
|
+
fill="true"
|
|
135
|
+
fillcolor="none">
|
|
136
|
+
<v:fill src="${imageUrl}" type="frame" />
|
|
137
|
+
<v:textbox inset="0,0,0,0"><div style="display:none;">.</div></v:textbox>
|
|
138
|
+
</v:${useRoundRect ? "roundrect" : "rect"}>
|
|
126
139
|
<![endif]-->`;
|
|
127
|
-
return `
|
|
128
|
-
${outlookImage}
|
|
129
|
-
<!--[if !mso]><!-->
|
|
130
|
-
${content}
|
|
131
|
-
<!--<![endif]-->
|
|
140
|
+
return `
|
|
141
|
+
${outlookImage}
|
|
142
|
+
<!--[if !mso]><!-->
|
|
143
|
+
${content}
|
|
144
|
+
<!--<![endif]-->
|
|
132
145
|
`;
|
|
133
146
|
}
|
|
134
147
|
async function convertImageBlock(blockData, cellWidthInPx) {
|
|
@@ -147,18 +160,18 @@ async function convertImageBlock(blockData, cellWidthInPx) {
|
|
|
147
160
|
}
|
|
148
161
|
function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
149
162
|
const { width, buttonColor, borderColor, borderRadius, borderWidth, height, buttonPadding, color, fontFamily, fontSize, fontWeight } = buttonStyle;
|
|
150
|
-
return `
|
|
151
|
-
<!--[if mso]>
|
|
152
|
-
<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 || 0}px" strokecolor="${borderColor || "transparent"}" fillcolor="${buttonColor || "none"}">
|
|
153
|
-
<w:anchorlock/>
|
|
154
|
-
<v:textbox inset="${buttonPadding?.top || 0}px, ${buttonPadding?.left || 0}px, ${buttonPadding?.bottom || 0}px, ${buttonPadding?.right || 0}px">
|
|
155
|
-
<center style="font-family:${fontFamily || ""};font-size:${fontSize}px;font-weight:${fontWeight};color:${color};">${text}</center>
|
|
156
|
-
</v:textbox>
|
|
157
|
-
</v:${borderRadius ? "roundrect" : "rect"}>
|
|
158
|
-
<![endif]-->
|
|
159
|
-
<!--[if !mso]><!-->
|
|
160
|
-
${content}
|
|
161
|
-
<!--<![endif]-->
|
|
163
|
+
return `
|
|
164
|
+
<!--[if mso]>
|
|
165
|
+
<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 || 0}px" strokecolor="${borderColor || "transparent"}" fillcolor="${buttonColor || "none"}">
|
|
166
|
+
<w:anchorlock/>
|
|
167
|
+
<v:textbox inset="${buttonPadding?.top || 0}px, ${buttonPadding?.left || 0}px, ${buttonPadding?.bottom || 0}px, ${buttonPadding?.right || 0}px">
|
|
168
|
+
<center style="font-family:${fontFamily || ""};font-size:${fontSize}px;font-weight:${fontWeight};color:${color};">${text}</center>
|
|
169
|
+
</v:textbox>
|
|
170
|
+
</v:${borderRadius ? "roundrect" : "rect"}>
|
|
171
|
+
<![endif]-->
|
|
172
|
+
<!--[if !mso]><!-->
|
|
173
|
+
${content}
|
|
174
|
+
<!--<![endif]-->
|
|
162
175
|
`;
|
|
163
176
|
}
|
|
164
177
|
function convertButtonBlock(blockData) {
|
|
@@ -205,12 +218,12 @@ async function convertGridBlock(blockData, rootData, cellWidthInPx) {
|
|
|
205
218
|
const { rows, columns, cellWidths } = props;
|
|
206
219
|
const styles = buildStyles(rest, { perChanges: [], pxChanges: allPxAttributes });
|
|
207
220
|
const gridItems = await processGridItemsInParallel(columns, childrenIds, cellWidths, cellWidthInPx, rootData);
|
|
208
|
-
return `
|
|
209
|
-
<table cellspacing="${columnGap}" style="width:100%; max-width:100%; ${styles}">
|
|
210
|
-
<tbody>
|
|
211
|
-
<tr>${gridItems.join("")}</tr>
|
|
212
|
-
</tbody>
|
|
213
|
-
</table>
|
|
221
|
+
return `
|
|
222
|
+
<table cellspacing="${columnGap}" style="width:100%; max-width:100%; ${styles}">
|
|
223
|
+
<tbody>
|
|
224
|
+
<tr>${gridItems.join("")}</tr>
|
|
225
|
+
</tbody>
|
|
226
|
+
</table>
|
|
214
227
|
`;
|
|
215
228
|
}
|
|
216
229
|
async function convertGridCellBlock(blockData, rootData, cellWidth, parentCellWidth) {
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "email-builder-utils",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
|
-
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"start": "npm run build && node dist/index.js"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://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@github.com/Biztecno-Infra/email-builder-utils.git"
|
|
17
|
-
},
|
|
18
|
-
"author": "",
|
|
19
|
-
"license": "ISC",
|
|
20
|
-
"bugs": {
|
|
21
|
-
"url": "https://github.com/Biztecno-Infra/email-builder-utils/issues"
|
|
22
|
-
},
|
|
23
|
-
"homepage": "https://github.com/Biztecno-Infra/email-builder-utils#readme",
|
|
24
|
-
"description": "",
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@types/node": "^22.13.10",
|
|
27
|
-
"@types/pngjs": "^6.0.5",
|
|
28
|
-
"typescript": "^5.8.2"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"jimp": "^1.6.0"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "email-builder-utils",
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "npm run build && node dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://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@github.com/Biztecno-Infra/email-builder-utils.git"
|
|
17
|
+
},
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/Biztecno-Infra/email-builder-utils/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/Biztecno-Infra/email-builder-utils#readme",
|
|
24
|
+
"description": "",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.13.10",
|
|
27
|
+
"@types/pngjs": "^6.0.5",
|
|
28
|
+
"typescript": "^5.8.2"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"jimp": "^1.6.0"
|
|
32
|
+
}
|
|
33
|
+
}
|