email-builder-utils 1.0.0
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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/types/ITemplate.d.ts +38 -0
- package/dist/types/ITemplate.d.ts.map +1 -0
- package/dist/types/ITemplate.js +20 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +17 -0
- package/dist/utils/convertJsonToHtml.d.ts +3 -0
- package/dist/utils/convertJsonToHtml.d.ts.map +1 -0
- package/dist/utils/convertJsonToHtml.js +44 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/jsonToHTML.d.ts +22 -0
- package/dist/utils/jsonToHTML.d.ts.map +1 -0
- package/dist/utils/jsonToHTML.js +181 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare enum BlockType {
|
|
2
|
+
TEXT = "Text",
|
|
3
|
+
IMAGE = "Image",
|
|
4
|
+
BUTTON = "Button",
|
|
5
|
+
GRID = "Columns",
|
|
6
|
+
EMPTY = "EMPTY",
|
|
7
|
+
GRIDCELL = "Column",
|
|
8
|
+
SPACER = "Spacer",
|
|
9
|
+
DIVIDER = "Divider"
|
|
10
|
+
}
|
|
11
|
+
export declare enum visibility {
|
|
12
|
+
PUBLIC = "PUBLIC",
|
|
13
|
+
PRIVATE = "PRIVATE",
|
|
14
|
+
PRE_DEFINED = "PRE_DEFINED"
|
|
15
|
+
}
|
|
16
|
+
interface IProps {
|
|
17
|
+
imageUrl: string;
|
|
18
|
+
text: string;
|
|
19
|
+
rows: number;
|
|
20
|
+
columns: number;
|
|
21
|
+
textAlign: string;
|
|
22
|
+
navigateToUrl: string;
|
|
23
|
+
altText: string;
|
|
24
|
+
cellWidths: number[];
|
|
25
|
+
}
|
|
26
|
+
interface IStyle {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
export interface IBlockData {
|
|
30
|
+
type: BlockType;
|
|
31
|
+
data: {
|
|
32
|
+
style: IStyle;
|
|
33
|
+
props: IProps;
|
|
34
|
+
childrenIds: string[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=ITemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITemplate.d.ts","sourceRoot":"","sources":["../../src/types/ITemplate.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;CACpB;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;CACtB;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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.visibility = exports.BlockType = void 0;
|
|
4
|
+
var BlockType;
|
|
5
|
+
(function (BlockType) {
|
|
6
|
+
BlockType["TEXT"] = "Text";
|
|
7
|
+
BlockType["IMAGE"] = "Image";
|
|
8
|
+
BlockType["BUTTON"] = "Button";
|
|
9
|
+
BlockType["GRID"] = "Columns";
|
|
10
|
+
BlockType["EMPTY"] = "EMPTY";
|
|
11
|
+
BlockType["GRIDCELL"] = "Column";
|
|
12
|
+
BlockType["SPACER"] = "Spacer";
|
|
13
|
+
BlockType["DIVIDER"] = "Divider";
|
|
14
|
+
})(BlockType || (exports.BlockType = BlockType = {}));
|
|
15
|
+
var visibility;
|
|
16
|
+
(function (visibility) {
|
|
17
|
+
visibility["PUBLIC"] = "PUBLIC";
|
|
18
|
+
visibility["PRIVATE"] = "PRIVATE";
|
|
19
|
+
visibility["PRE_DEFINED"] = "PRE_DEFINED";
|
|
20
|
+
})(visibility || (exports.visibility = visibility = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ITemplate"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertJsonToHtml.d.ts","sourceRoot":"","sources":["../../src/utils/convertJsonToHtml.ts"],"names":[],"mappings":"AAIA,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,GAAG,UAsCvC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const js_beautify_1 = require("js-beautify");
|
|
4
|
+
const jsonToHTML_1 = require("./jsonToHTML");
|
|
5
|
+
// @TODO: Update style of <table>, in frontend, useState was used
|
|
6
|
+
function convertJsonToHtml(jsonData) {
|
|
7
|
+
const rootData = jsonData?.root?.data;
|
|
8
|
+
const blocksHtml = rootData?.childrenIds.map((childId) => (0, jsonToHTML_1.convertToHtml)(jsonData[childId], jsonData)).join("");
|
|
9
|
+
const rawHtml = `
|
|
10
|
+
<!DOCTYPE html>
|
|
11
|
+
<html lang="en">
|
|
12
|
+
<head>
|
|
13
|
+
<meta charset="UTF-8">
|
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
15
|
+
<title>Email Layout</title>
|
|
16
|
+
<style>
|
|
17
|
+
@media screen and (max-width: 600px) {
|
|
18
|
+
.ebr-table-wrapper {
|
|
19
|
+
width: 360px !important;
|
|
20
|
+
max-width: 360px !important;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@media screen and (min-width: 601px) {
|
|
25
|
+
.ebr-table-wrapper {
|
|
26
|
+
width: 600px !important;
|
|
27
|
+
max-width: 600px !important;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<table class="ebr-table-wrapper" style="font-family:${"Modern Sans"}; width:600px; max-width:600px; margin:0 auto; background-color:${"#FFFFFF"}; color:${""}; ${"border-collapse:collapse; table-layout:fixed;"}">
|
|
34
|
+
<tbody>
|
|
35
|
+
<tr>
|
|
36
|
+
<td style="padding:0;">${blocksHtml}</td>
|
|
37
|
+
</tr>
|
|
38
|
+
</tbody>
|
|
39
|
+
</table>
|
|
40
|
+
</body>
|
|
41
|
+
</html>`;
|
|
42
|
+
return (0, js_beautify_1.html)(rawHtml, { indent_size: 2 });
|
|
43
|
+
}
|
|
44
|
+
exports.default = convertJsonToHtml;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./convertJsonToHtml"), exports);
|
|
18
|
+
__exportStar(require("./jsonToHTML"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BlockType } from "../types";
|
|
2
|
+
interface BlockJsonProps {
|
|
3
|
+
columns: number;
|
|
4
|
+
rows: number;
|
|
5
|
+
cellWidths: Array<number>;
|
|
6
|
+
navigateToUrl: string;
|
|
7
|
+
text: string;
|
|
8
|
+
altText: string;
|
|
9
|
+
imageUrl: string;
|
|
10
|
+
}
|
|
11
|
+
interface IBlockData {
|
|
12
|
+
type: BlockType;
|
|
13
|
+
data: {
|
|
14
|
+
props: BlockJsonProps;
|
|
15
|
+
style: any;
|
|
16
|
+
childrenIds?: Array<string>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare const tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
20
|
+
export declare function convertToHtml(blockData: IBlockData, rootData: any): string;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=jsonToHTML.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonToHTML.d.ts","sourceRoot":"","sources":["../../src/utils/jsonToHTML.ts"],"names":[],"mappings":"AAAA,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;AAGD,eAAO,MAAM,gBAAgB,kDAAkD,CAAC;AA4ChF,wBAAgB,aAAa,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,UAiBjE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableCommonStyle = void 0;
|
|
4
|
+
exports.convertToHtml = convertToHtml;
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const addPxToAttributes = ["width", "height", "fontSize"];
|
|
7
|
+
exports.tableCommonStyle = "border-collapse:collapse; table-layout:fixed;";
|
|
8
|
+
function cleanJson(obj) {
|
|
9
|
+
if (typeof obj !== "object" || obj === null)
|
|
10
|
+
return obj;
|
|
11
|
+
if (Array.isArray(obj)) {
|
|
12
|
+
return obj.map(cleanJson);
|
|
13
|
+
}
|
|
14
|
+
return Object.fromEntries(Object.entries(obj)
|
|
15
|
+
.filter(([_, value]) => value !== undefined && value !== null && value !== "")
|
|
16
|
+
.map(([key, value]) => [key, cleanJson(value)]));
|
|
17
|
+
}
|
|
18
|
+
function jsonToPlainString(obj) {
|
|
19
|
+
if (typeof obj !== "object" || obj === null)
|
|
20
|
+
return String(obj);
|
|
21
|
+
if (Array.isArray(obj)) {
|
|
22
|
+
return obj.map(jsonToPlainString).join(", ");
|
|
23
|
+
}
|
|
24
|
+
return Object.entries(obj)
|
|
25
|
+
.map(([key, value]) => `${key}:${jsonToPlainString(value)}; `)
|
|
26
|
+
.join("");
|
|
27
|
+
}
|
|
28
|
+
function buildStyles(style) {
|
|
29
|
+
const stylesObj = {};
|
|
30
|
+
Object.entries(style).forEach(([key, value]) => {
|
|
31
|
+
const appendPx = addPxToAttributes.includes(key);
|
|
32
|
+
if (value === undefined || value === null || value === "")
|
|
33
|
+
return null;
|
|
34
|
+
if ((key === "padding" || key === "buttonPadding") && typeof value === "object" && value !== null) {
|
|
35
|
+
const padding = value;
|
|
36
|
+
value = `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`;
|
|
37
|
+
}
|
|
38
|
+
const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
39
|
+
return (stylesObj[cssKey] = appendPx ? `${value}px` : value);
|
|
40
|
+
});
|
|
41
|
+
return jsonToPlainString(cleanJson(stylesObj)).trim();
|
|
42
|
+
}
|
|
43
|
+
function convertToHtml(blockData, rootData) {
|
|
44
|
+
switch (blockData.type) {
|
|
45
|
+
case types_1.BlockType.TEXT:
|
|
46
|
+
return convertTextBlock(blockData);
|
|
47
|
+
case types_1.BlockType.IMAGE:
|
|
48
|
+
return convertImageBlock(blockData);
|
|
49
|
+
case types_1.BlockType.BUTTON:
|
|
50
|
+
return convertButtonBlock(blockData);
|
|
51
|
+
case types_1.BlockType.GRID:
|
|
52
|
+
return convertGridBlock(blockData, rootData);
|
|
53
|
+
case types_1.BlockType.DIVIDER:
|
|
54
|
+
return convertDividerBlockToHtml(blockData);
|
|
55
|
+
case types_1.BlockType.SPACER:
|
|
56
|
+
return convertSpacerBlockToHtml(blockData);
|
|
57
|
+
default:
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function appendOutlookSupport(content, contentStyle) {
|
|
62
|
+
return `
|
|
63
|
+
<table width="100%" style="${exports.tableCommonStyle}">
|
|
64
|
+
<tr>
|
|
65
|
+
<td style="${contentStyle}">
|
|
66
|
+
${content}
|
|
67
|
+
</td>
|
|
68
|
+
</tr>
|
|
69
|
+
</table>
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
function convertDividerBlockToHtml(blockData) {
|
|
73
|
+
const { style } = blockData.data;
|
|
74
|
+
const { thickness, dividerColor, ...rest } = style;
|
|
75
|
+
const convertedStyle = buildStyles(rest);
|
|
76
|
+
return appendOutlookSupport(`<hr style="height:${thickness}px; background-color: ${dividerColor};" />`, convertedStyle);
|
|
77
|
+
}
|
|
78
|
+
function convertSpacerBlockToHtml(blockData) {
|
|
79
|
+
const { style } = blockData.data;
|
|
80
|
+
const styles = buildStyles(style);
|
|
81
|
+
return appendOutlookSupport(``, styles);
|
|
82
|
+
}
|
|
83
|
+
function convertTextBlock(blockData) {
|
|
84
|
+
const { style, props } = blockData.data;
|
|
85
|
+
const styles = buildStyles(style);
|
|
86
|
+
const text = props.text || "";
|
|
87
|
+
const navigateToUrl = props.navigateToUrl || "";
|
|
88
|
+
const textContent = appendOutlookSupport(text.replaceAll(/\n/g, "<br>"), styles);
|
|
89
|
+
return navigateToUrl ? `<a href="${navigateToUrl}" style="color:inherit; text-decoration:none; cursor:pointer;">${textContent}</a>` : textContent;
|
|
90
|
+
}
|
|
91
|
+
function appendOutlookForImage(content, imageStyle, imageUrl) {
|
|
92
|
+
return `
|
|
93
|
+
<!--[if mso]>
|
|
94
|
+
<v:rect xmlns:v="urn:schemas-microsoft-com:vml"
|
|
95
|
+
fill="t" stroke="f"
|
|
96
|
+
style="${imageStyle}">
|
|
97
|
+
<v:fill src="${imageUrl}" type="frame"/>
|
|
98
|
+
</v:rect>
|
|
99
|
+
<![endif]-->
|
|
100
|
+
<!--[if !mso]><!-->
|
|
101
|
+
${content}
|
|
102
|
+
<!--<![endif]-->
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
function convertImageBlock(blockData) {
|
|
106
|
+
const { style, props } = blockData.data;
|
|
107
|
+
const { altText, imageUrl, navigateToUrl } = props;
|
|
108
|
+
const { width, height, objectFit, ...containerStyle } = style;
|
|
109
|
+
const imageStyle = { width, height, objectFit };
|
|
110
|
+
const containerStyles = buildStyles(containerStyle);
|
|
111
|
+
const imageTagStyles = buildStyles(imageStyle);
|
|
112
|
+
const imageElement = `<img src="${imageUrl}" alt="${altText}" style="${imageTagStyles}" />`;
|
|
113
|
+
const imageContent = appendOutlookSupport(appendOutlookForImage(imageElement, imageTagStyles, imageUrl), containerStyles);
|
|
114
|
+
return navigateToUrl ? `<a href="${navigateToUrl}" target="_blank" style="display:block; text-decoration:none; cursor:pointer;">${imageContent}</a>` : imageContent;
|
|
115
|
+
}
|
|
116
|
+
function appendOutlookForButton(content, buttonStyle, navigateToUrl, text) {
|
|
117
|
+
const { width, buttonColor, borderColor, borderRadius, borderWidth, height, buttonPadding, color, fontFamily, fontSize, fontWeight } = buttonStyle;
|
|
118
|
+
return `
|
|
119
|
+
<!--[if mso]>
|
|
120
|
+
<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"}">
|
|
121
|
+
<w:anchorlock/>
|
|
122
|
+
<v:textbox inset="${buttonPadding?.top || 0}px, ${buttonPadding?.left || 0}px, ${buttonPadding?.bottom || 0}px, ${buttonPadding?.right || 0}px">
|
|
123
|
+
<center style="font-family:${fontFamily || ""};font-size:${fontSize}px;font-weight:${fontWeight};color:${color};">${text}</center>
|
|
124
|
+
</v:textbox>
|
|
125
|
+
</v:${borderRadius ? "roundrect" : "rect"}>
|
|
126
|
+
<![endif]-->
|
|
127
|
+
<!--[if !mso]><!-->
|
|
128
|
+
${content}
|
|
129
|
+
<!--<![endif]-->
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
function convertButtonBlock(blockData) {
|
|
133
|
+
const { style, props } = blockData.data;
|
|
134
|
+
const { text, navigateToUrl } = props;
|
|
135
|
+
const { fontFamily, fontSize, fontWeight, borderColor, borderRadius, borderWidth, borderStyle, buttonPadding, textColor, buttonColor, ...rest } = style;
|
|
136
|
+
const buttonStyle = {
|
|
137
|
+
fontFamily,
|
|
138
|
+
fontSize,
|
|
139
|
+
fontWeight,
|
|
140
|
+
borderColor,
|
|
141
|
+
borderRadius,
|
|
142
|
+
borderWidth,
|
|
143
|
+
borderStyle,
|
|
144
|
+
padding: buttonPadding,
|
|
145
|
+
textColor,
|
|
146
|
+
backgroundColor: buttonColor,
|
|
147
|
+
};
|
|
148
|
+
const convertedButtonStyle = buildStyles(buttonStyle);
|
|
149
|
+
const convertedStyles = buildStyles(rest);
|
|
150
|
+
const buttonElement = `<a href="${navigateToUrl}" style="display:inline-block; text-decoration:none; cursor:pointer;"><button style="${convertedButtonStyle}">${text}</button></a>`;
|
|
151
|
+
const buttonContent = appendOutlookSupport(appendOutlookForButton(buttonElement, style, navigateToUrl, text), convertedStyles);
|
|
152
|
+
return buttonContent;
|
|
153
|
+
}
|
|
154
|
+
function convertGridBlock(blockData, rootData) {
|
|
155
|
+
const { style, childrenIds = [], props } = blockData.data;
|
|
156
|
+
const { columnGap, ...rest } = style;
|
|
157
|
+
const { rows, columns, cellWidths } = props;
|
|
158
|
+
const styles = buildStyles(rest);
|
|
159
|
+
const gridItems = [];
|
|
160
|
+
for (let colIndex = 0; colIndex < columns; colIndex++) {
|
|
161
|
+
const childId = childrenIds[colIndex];
|
|
162
|
+
const cellWidth = cellWidths ? cellWidths[colIndex] : 100 / columns;
|
|
163
|
+
const childBlockData = rootData[childId];
|
|
164
|
+
if (childBlockData) {
|
|
165
|
+
gridItems.push(convertGridCellBlock(childBlockData, rootData, cellWidth));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return `
|
|
169
|
+
<table cellspacing="${columnGap}" style="width:100%; max-width:100%; ${styles}">
|
|
170
|
+
<tbody>
|
|
171
|
+
<tr>${gridItems.join("")}</tr>
|
|
172
|
+
</tbody>
|
|
173
|
+
</table>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
function convertGridCellBlock(blockData, rootData, cellWidth) {
|
|
177
|
+
const { style, childrenIds } = blockData.data;
|
|
178
|
+
const styles = buildStyles(style);
|
|
179
|
+
const cellItems = childrenIds && childrenIds.length > 0 ? childrenIds.map((childId) => convertToHtml(rootData[childId], rootData)).join("") : "";
|
|
180
|
+
return `<td style="width:${cellWidth}% ; max-width:${cellWidth}%; ${styles}">${cellItems}</td>`;
|
|
181
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "email-builder-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
+
"dependencies": {
|
|
26
|
+
"js-beautify": "^1.15.4"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/js-beautify": "^1.14.3",
|
|
30
|
+
"@types/node": "^22.13.10",
|
|
31
|
+
"typescript": "^5.8.2"
|
|
32
|
+
}
|
|
33
|
+
}
|