@lit-pigeon/parser-mjml 0.1.7 → 0.3.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/README.md +15 -3
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +601 -348
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,36 +1,45 @@
|
|
|
1
|
-
import { Parser as
|
|
2
|
-
import { generateId as
|
|
3
|
-
function
|
|
4
|
-
const e = { attributeDefaults: { all: {}, tags: {}, classes: {} } },
|
|
5
|
-
for (const
|
|
6
|
-
switch (
|
|
1
|
+
import { Parser as O } from "htmlparser2";
|
|
2
|
+
import { generatedStyleName as U, LINK_STYLE_NAME as H, cssToLinkStyle as Y, generateId as b } from "@lit-pigeon/core";
|
|
3
|
+
function q(t, n) {
|
|
4
|
+
const e = { fonts: [], attributeDefaults: { all: {}, tags: {}, classes: {} } }, o = [];
|
|
5
|
+
for (const i of t)
|
|
6
|
+
switch (i.tag) {
|
|
7
7
|
case "mj-preview":
|
|
8
|
-
e.previewText =
|
|
8
|
+
e.previewText = i.text;
|
|
9
|
+
break;
|
|
10
|
+
case "mj-title":
|
|
11
|
+
e.title = i.text;
|
|
12
|
+
break;
|
|
13
|
+
case "mj-font":
|
|
14
|
+
i.attrs.name && i.attrs.href && e.fonts.push({ name: i.attrs.name, family: i.attrs.name, url: i.attrs.href });
|
|
9
15
|
break;
|
|
10
16
|
case "mj-attributes":
|
|
11
|
-
for (const
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
Object.assign(
|
|
15
|
-
else if (
|
|
16
|
-
const { name:
|
|
17
|
-
|
|
17
|
+
for (const r of i.children) {
|
|
18
|
+
const s = e.attributeDefaults;
|
|
19
|
+
if (r.tag === "mj-all")
|
|
20
|
+
Object.assign(s.all, r.attrs);
|
|
21
|
+
else if (r.tag === "mj-class") {
|
|
22
|
+
const { name: c, ...d } = r.attrs;
|
|
23
|
+
c && (s.classes[c] = { ...s.classes[c], ...d });
|
|
18
24
|
} else
|
|
19
|
-
|
|
25
|
+
s.tags[r.tag] = { ...s.tags[r.tag], ...r.attrs };
|
|
20
26
|
}
|
|
21
27
|
e.attributeDefaults.all["font-family"] && (e.fontFamily = e.attributeDefaults.all["font-family"]);
|
|
22
28
|
break;
|
|
23
|
-
case "mj-style":
|
|
24
|
-
|
|
29
|
+
case "mj-style": {
|
|
30
|
+
if (i.attrs.inline === "inline" || !i.text.trim()) break;
|
|
31
|
+
const r = U(i.text);
|
|
32
|
+
r === H ? e.linkStyle = Y(i.text) : r || o.push(i.text.trim());
|
|
25
33
|
break;
|
|
34
|
+
}
|
|
26
35
|
}
|
|
27
|
-
return
|
|
36
|
+
return o.length > 0 && (e.css = o.join(`
|
|
28
37
|
`)), e;
|
|
29
38
|
}
|
|
30
|
-
function
|
|
39
|
+
function m(t, n = 0) {
|
|
31
40
|
if (!t)
|
|
32
41
|
return { top: n, right: n, bottom: n, left: n };
|
|
33
|
-
const e = t.trim().split(/\s+/).map(
|
|
42
|
+
const e = t.trim().split(/\s+/).map(G);
|
|
34
43
|
switch (e.length) {
|
|
35
44
|
case 1:
|
|
36
45
|
return { top: e[0], right: e[0], bottom: e[0], left: e[0] };
|
|
@@ -44,139 +53,168 @@ function f(t, n = 0) {
|
|
|
44
53
|
return { top: n, right: n, bottom: n, left: n };
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
|
-
function
|
|
56
|
+
function G(t) {
|
|
48
57
|
const n = parseFloat(t);
|
|
49
58
|
return isNaN(n) ? 0 : n;
|
|
50
59
|
}
|
|
51
|
-
function
|
|
60
|
+
function a(t, n, e = "") {
|
|
52
61
|
return t[n] ?? e;
|
|
53
62
|
}
|
|
54
|
-
function
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
return isNaN(
|
|
63
|
+
function w(t, n, e = 0) {
|
|
64
|
+
const o = t[n];
|
|
65
|
+
if (o === void 0 || o === "") return e;
|
|
66
|
+
const i = parseFloat(o);
|
|
67
|
+
return isNaN(i) ? e : i;
|
|
59
68
|
}
|
|
60
|
-
function
|
|
69
|
+
function R(t) {
|
|
70
|
+
const n = {}, e = t["css-class"];
|
|
71
|
+
if (!e) return n;
|
|
72
|
+
const o = e.replace(/(^|\s)pigeon-hide-(mobile|desktop)(?=\s|$)/g, (i, r, s) => (n[s === "mobile" ? "hideOnMobile" : "hideOnDesktop"] = !0, "")).trim();
|
|
73
|
+
return o ? t["css-class"] = o : delete t["css-class"], n;
|
|
74
|
+
}
|
|
75
|
+
function X(t, n) {
|
|
61
76
|
return {
|
|
62
|
-
id:
|
|
77
|
+
id: b(),
|
|
63
78
|
type: "text",
|
|
64
79
|
values: {
|
|
65
80
|
content: n,
|
|
66
|
-
padding:
|
|
67
|
-
lineHeight:
|
|
68
|
-
textAlign:
|
|
69
|
-
cssClass:
|
|
81
|
+
padding: m(a(t, "padding"), 10),
|
|
82
|
+
lineHeight: a(t, "line-height", "1.5"),
|
|
83
|
+
textAlign: a(t, "align", "left"),
|
|
84
|
+
cssClass: a(t, "css-class") || void 0
|
|
70
85
|
}
|
|
71
86
|
};
|
|
72
87
|
}
|
|
73
|
-
function
|
|
74
|
-
const n =
|
|
88
|
+
function K(t) {
|
|
89
|
+
const n = a(t, "width"), e = n && parseInt(n, 10) || "auto";
|
|
75
90
|
return {
|
|
76
|
-
id:
|
|
91
|
+
id: b(),
|
|
77
92
|
type: "image",
|
|
78
93
|
values: {
|
|
79
|
-
src:
|
|
80
|
-
alt:
|
|
94
|
+
src: a(t, "src"),
|
|
95
|
+
alt: a(t, "alt"),
|
|
81
96
|
width: e,
|
|
82
|
-
href:
|
|
83
|
-
padding:
|
|
84
|
-
alignment:
|
|
85
|
-
borderRadius:
|
|
86
|
-
cssClass:
|
|
97
|
+
href: a(t, "href") || void 0,
|
|
98
|
+
padding: m(a(t, "padding"), 10),
|
|
99
|
+
alignment: a(t, "align", "center"),
|
|
100
|
+
borderRadius: w(t, "border-radius", 0),
|
|
101
|
+
cssClass: a(t, "css-class") || void 0
|
|
87
102
|
}
|
|
88
103
|
};
|
|
89
104
|
}
|
|
90
|
-
|
|
91
|
-
|
|
105
|
+
const V = /^(solid|dashed|dotted|double|groove|ridge|inset|outset)$/;
|
|
106
|
+
function J(t) {
|
|
107
|
+
const n = t.trim().split(/\s+/).filter(Boolean);
|
|
108
|
+
if (!n.length) return;
|
|
109
|
+
let e, o;
|
|
110
|
+
const i = [];
|
|
111
|
+
for (const r of n) {
|
|
112
|
+
const s = r.toLowerCase();
|
|
113
|
+
if (s === "none" || s === "hidden") return;
|
|
114
|
+
e === void 0 && /^\d*\.?\d+(px)?$/.test(s) ? e = parseFloat(s) : o === void 0 && V.test(s) ? o = s === "dashed" || s === "dotted" ? s : "solid" : i.push(r);
|
|
115
|
+
}
|
|
116
|
+
if (e !== 0)
|
|
117
|
+
return {
|
|
118
|
+
width: e ?? 1,
|
|
119
|
+
style: o ?? "solid",
|
|
120
|
+
color: i.join(" ") || "#000000"
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function Z(t, n) {
|
|
124
|
+
const e = n.trim(), o = /^<p[\s>]/i.test(e) ? e : `<p>${e}</p>`, i = J(a(t, "border"));
|
|
92
125
|
return {
|
|
93
|
-
id:
|
|
126
|
+
id: b(),
|
|
94
127
|
type: "button",
|
|
95
128
|
values: {
|
|
96
|
-
content:
|
|
97
|
-
href:
|
|
98
|
-
backgroundColor:
|
|
99
|
-
textColor:
|
|
100
|
-
borderRadius:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
content: o,
|
|
130
|
+
href: a(t, "href", "#"),
|
|
131
|
+
backgroundColor: a(t, "background-color", "#3b82f6"),
|
|
132
|
+
textColor: a(t, "color", "#ffffff"),
|
|
133
|
+
borderRadius: w(t, "border-radius", 4),
|
|
134
|
+
...i ? { border: i } : {},
|
|
135
|
+
padding: m(a(t, "padding"), 10),
|
|
136
|
+
innerPadding: m(a(t, "inner-padding"), 12),
|
|
137
|
+
fontSize: w(t, "font-size", 16),
|
|
138
|
+
fontWeight: a(t, "font-weight", "600"),
|
|
139
|
+
alignment: a(t, "align", "center"),
|
|
140
|
+
fullWidth: a(t, "width") === "100%",
|
|
141
|
+
cssClass: a(t, "css-class") || void 0
|
|
108
142
|
}
|
|
109
143
|
};
|
|
110
144
|
}
|
|
111
|
-
function
|
|
145
|
+
function Q(t) {
|
|
112
146
|
return {
|
|
113
|
-
id:
|
|
147
|
+
id: b(),
|
|
114
148
|
type: "divider",
|
|
115
149
|
values: {
|
|
116
|
-
borderColor:
|
|
117
|
-
borderWidth:
|
|
118
|
-
borderStyle:
|
|
119
|
-
padding:
|
|
120
|
-
width:
|
|
150
|
+
borderColor: a(t, "border-color", "#e2e8f0"),
|
|
151
|
+
borderWidth: w(t, "border-width", 1),
|
|
152
|
+
borderStyle: a(t, "border-style", "solid"),
|
|
153
|
+
padding: m(a(t, "padding"), 10),
|
|
154
|
+
width: a(t, "width", "100%")
|
|
121
155
|
}
|
|
122
156
|
};
|
|
123
157
|
}
|
|
124
|
-
function
|
|
158
|
+
function tt(t) {
|
|
125
159
|
return {
|
|
126
|
-
id:
|
|
160
|
+
id: b(),
|
|
127
161
|
type: "spacer",
|
|
128
162
|
values: {
|
|
129
|
-
height:
|
|
163
|
+
height: w(t, "height", 20)
|
|
130
164
|
}
|
|
131
165
|
};
|
|
132
166
|
}
|
|
133
|
-
const
|
|
134
|
-
function
|
|
167
|
+
const et = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
|
|
168
|
+
function nt(t) {
|
|
135
169
|
const n = t.toLowerCase();
|
|
136
|
-
|
|
170
|
+
if (n === "x" || n === "x-noshare") return "twitter";
|
|
171
|
+
for (const e of et)
|
|
137
172
|
if (n.includes(e)) return e;
|
|
138
173
|
return "custom";
|
|
139
174
|
}
|
|
140
|
-
function
|
|
141
|
-
const e = n.map((
|
|
142
|
-
const
|
|
143
|
-
type:
|
|
144
|
-
href:
|
|
145
|
-
label:
|
|
146
|
-
},
|
|
147
|
-
return
|
|
175
|
+
function ot(t, n) {
|
|
176
|
+
const e = n.map((o) => {
|
|
177
|
+
const r = {
|
|
178
|
+
type: nt(a(o.attrs, "name", "custom")),
|
|
179
|
+
href: a(o.attrs, "href", "#"),
|
|
180
|
+
label: o.innerText.trim() || void 0
|
|
181
|
+
}, s = a(o.attrs, "src");
|
|
182
|
+
return s && (r.iconUrl = s), r;
|
|
148
183
|
});
|
|
149
184
|
return {
|
|
150
|
-
id:
|
|
185
|
+
id: b(),
|
|
151
186
|
type: "social",
|
|
152
187
|
values: {
|
|
153
188
|
icons: e,
|
|
154
|
-
iconSize:
|
|
155
|
-
spacing:
|
|
156
|
-
alignment:
|
|
157
|
-
padding:
|
|
189
|
+
iconSize: w(t, "icon-size", 32),
|
|
190
|
+
spacing: w(t, "icon-padding", 0),
|
|
191
|
+
alignment: a(t, "align", "center"),
|
|
192
|
+
padding: m(a(t, "padding"), 10)
|
|
158
193
|
}
|
|
159
194
|
};
|
|
160
195
|
}
|
|
161
|
-
function
|
|
162
|
-
const n = t.match(
|
|
196
|
+
function it(t) {
|
|
197
|
+
const n = t.match(
|
|
198
|
+
/^<div(?:\s+class="lp-html((?:\s+pigeon-hide-(?:mobile|desktop))*)")?\s+style="padding:\s*([^"]*)">([\s\S]*)<\/div>$/
|
|
199
|
+
);
|
|
163
200
|
return n ? {
|
|
164
|
-
id:
|
|
201
|
+
id: b(),
|
|
165
202
|
type: "html",
|
|
166
203
|
values: {
|
|
167
|
-
content: n[
|
|
168
|
-
padding:
|
|
204
|
+
content: n[3],
|
|
205
|
+
padding: m(n[2], 0),
|
|
206
|
+
...R({ "css-class": n[1] ?? "" })
|
|
169
207
|
}
|
|
170
208
|
} : {
|
|
171
|
-
id:
|
|
209
|
+
id: b(),
|
|
172
210
|
type: "html",
|
|
173
211
|
values: {
|
|
174
212
|
content: t,
|
|
175
|
-
padding:
|
|
213
|
+
padding: m(void 0, 0)
|
|
176
214
|
}
|
|
177
215
|
};
|
|
178
216
|
}
|
|
179
|
-
const
|
|
217
|
+
const rt = {
|
|
180
218
|
align: "left",
|
|
181
219
|
border: "none",
|
|
182
220
|
cellpadding: "0",
|
|
@@ -189,8 +227,8 @@ const V = {
|
|
|
189
227
|
"table-layout": "auto",
|
|
190
228
|
width: "100%"
|
|
191
229
|
};
|
|
192
|
-
function
|
|
193
|
-
const e = { ...
|
|
230
|
+
function at(t, n) {
|
|
231
|
+
const e = { ...rt, ...t }, o = e.width.endsWith("%") || e.width === "auto" ? e.width : String(parseInt(e.width, 10)), i = parseFloat(e.cellspacing.replace(/[^\d.]/g, "")), r = [
|
|
194
232
|
`color:${e.color}`,
|
|
195
233
|
`font-family:${e["font-family"]}`,
|
|
196
234
|
`font-size:${e["font-size"]}`,
|
|
@@ -198,90 +236,107 @@ function Y(t, n) {
|
|
|
198
236
|
`table-layout:${e["table-layout"]}`,
|
|
199
237
|
`width:${e.width}`,
|
|
200
238
|
`border:${e.border}`,
|
|
201
|
-
...
|
|
202
|
-
].map((
|
|
203
|
-
return e.align !== "left" &&
|
|
204
|
-
id:
|
|
239
|
+
...i > 0 ? ["border-collapse:separate"] : []
|
|
240
|
+
].map((c) => `${c};`).join(""), s = [];
|
|
241
|
+
return e.align !== "left" && s.push(`align="${$(e.align)}"`), s.push(`cellpadding="${$(e.cellpadding)}"`, `cellspacing="${$(e.cellspacing)}"`), t.role && s.push(`role="${$(t.role)}"`), s.push(`width="${$(o)}"`, 'border="0"', `style="${$(r)}"`), {
|
|
242
|
+
id: b(),
|
|
205
243
|
type: "html",
|
|
206
244
|
values: {
|
|
207
|
-
content: `<table ${
|
|
208
|
-
padding:
|
|
245
|
+
content: `<table ${s.join(" ")}>${n.trim()}</table>`,
|
|
246
|
+
padding: m(a(e, "padding"), 0)
|
|
209
247
|
}
|
|
210
248
|
};
|
|
211
249
|
}
|
|
212
|
-
function
|
|
250
|
+
function $(t) {
|
|
213
251
|
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
214
252
|
}
|
|
215
|
-
function
|
|
216
|
-
const e =
|
|
217
|
-
const
|
|
218
|
-
href: e + i
|
|
219
|
-
text:
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
return
|
|
253
|
+
function st(t, n) {
|
|
254
|
+
const e = a(t, "base-url"), o = n.map((i) => {
|
|
255
|
+
const r = {
|
|
256
|
+
href: e + a(i.attrs, "href", "#"),
|
|
257
|
+
text: i.innerText.trim() || "Link"
|
|
258
|
+
}, s = a(i.attrs, "color");
|
|
259
|
+
s && (r.color = s);
|
|
260
|
+
const c = a(i.attrs, "font-weight");
|
|
261
|
+
c && (r.fontWeight = c);
|
|
262
|
+
const d = a(i.attrs, "text-decoration");
|
|
263
|
+
d && (r.textDecoration = d);
|
|
264
|
+
const l = a(i.attrs, "padding");
|
|
265
|
+
return l && (r.padding = l), r;
|
|
228
266
|
});
|
|
229
267
|
return {
|
|
230
|
-
id:
|
|
268
|
+
id: b(),
|
|
231
269
|
type: "navbar",
|
|
232
270
|
values: {
|
|
233
|
-
links:
|
|
234
|
-
hamburger:
|
|
235
|
-
alignment:
|
|
236
|
-
padding:
|
|
237
|
-
linkColor:
|
|
238
|
-
linkFontSize:
|
|
239
|
-
linkPadding:
|
|
271
|
+
links: o,
|
|
272
|
+
hamburger: a(t, "hamburger", "none"),
|
|
273
|
+
alignment: a(t, "align", "center"),
|
|
274
|
+
padding: m(a(t, "padding"), 0),
|
|
275
|
+
linkColor: a(t, "ico-color", "#000000"),
|
|
276
|
+
linkFontSize: w(t, "font-size", 14),
|
|
277
|
+
linkPadding: a(t, "link-padding", "10px 15px")
|
|
240
278
|
}
|
|
241
279
|
};
|
|
242
280
|
}
|
|
243
|
-
function
|
|
244
|
-
const e = t.attrs,
|
|
245
|
-
for (
|
|
246
|
-
const
|
|
247
|
-
|
|
281
|
+
function z(t, n) {
|
|
282
|
+
const e = t.attrs, o = [], i = t.children;
|
|
283
|
+
for (let r = 0; r < i.length; r++) {
|
|
284
|
+
const s = lt(i[r]);
|
|
285
|
+
if (s && ct(i[r + 2])) {
|
|
286
|
+
const d = E(i[r + 1], n);
|
|
287
|
+
if (d) {
|
|
288
|
+
Object.assign(d.values, i[r + 1].visibility), d.values.condition = s, o.push(d), r += 2;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const c = E(i[r], n);
|
|
293
|
+
c && (Object.assign(c.values, i[r].visibility), o.push(c));
|
|
248
294
|
}
|
|
249
295
|
return {
|
|
250
|
-
id:
|
|
296
|
+
id: b(),
|
|
251
297
|
type: "column",
|
|
252
298
|
attributes: {
|
|
253
|
-
backgroundColor:
|
|
254
|
-
padding:
|
|
255
|
-
borderRadius:
|
|
256
|
-
verticalAlign:
|
|
257
|
-
cssClass:
|
|
299
|
+
backgroundColor: a(e, "background-color") || void 0,
|
|
300
|
+
padding: m(a(e, "padding"), 0),
|
|
301
|
+
borderRadius: w(e, "border-radius", 0) || void 0,
|
|
302
|
+
verticalAlign: a(e, "vertical-align", "top"),
|
|
303
|
+
cssClass: a(e, "css-class") || void 0,
|
|
304
|
+
...t.visibility
|
|
258
305
|
},
|
|
259
|
-
blocks:
|
|
306
|
+
blocks: o
|
|
260
307
|
};
|
|
261
308
|
}
|
|
262
|
-
function
|
|
309
|
+
function lt(t) {
|
|
310
|
+
var n;
|
|
311
|
+
if (t.tag === "mj-raw")
|
|
312
|
+
return (n = /^\s*\{\{#if\s+([^}]+?)\s*\}\}\s*$/.exec(t.text ?? "")) == null ? void 0 : n[1];
|
|
313
|
+
}
|
|
314
|
+
function ct(t) {
|
|
315
|
+
return (t == null ? void 0 : t.tag) === "mj-raw" && /^\s*\{\{\/if\}\}\s*$/.test(t.text ?? "");
|
|
316
|
+
}
|
|
317
|
+
function E(t, n) {
|
|
263
318
|
switch (t.tag) {
|
|
264
319
|
case "mj-text":
|
|
265
|
-
return
|
|
320
|
+
return X(t.attrs, t.text);
|
|
266
321
|
case "mj-image":
|
|
267
|
-
return
|
|
322
|
+
return K(t.attrs);
|
|
268
323
|
case "mj-button":
|
|
269
|
-
return
|
|
324
|
+
return Z(t.attrs, t.text);
|
|
270
325
|
case "mj-divider":
|
|
271
|
-
return
|
|
326
|
+
return Q(t.attrs);
|
|
272
327
|
case "mj-spacer":
|
|
273
|
-
return
|
|
328
|
+
return tt(t.attrs);
|
|
274
329
|
case "mj-social": {
|
|
275
|
-
const e = t.children.filter((
|
|
276
|
-
return
|
|
330
|
+
const e = t.children.filter((o) => o.tag === "mj-social-element").map((o) => ({ attrs: o.attrs, innerText: o.text }));
|
|
331
|
+
return ot(t.attrs, e);
|
|
277
332
|
}
|
|
278
333
|
case "mj-raw":
|
|
279
|
-
return
|
|
334
|
+
return it(t.text);
|
|
280
335
|
case "mj-table":
|
|
281
|
-
return
|
|
336
|
+
return at(t.attrs, t.text);
|
|
282
337
|
case "mj-navbar": {
|
|
283
|
-
const e = t.children.filter((
|
|
284
|
-
return
|
|
338
|
+
const e = t.children.filter((o) => o.tag === "mj-navbar-link").map((o) => ({ attrs: o.attrs, innerText: o.text }));
|
|
339
|
+
return st(t.attrs, e);
|
|
285
340
|
}
|
|
286
341
|
default:
|
|
287
342
|
return n.push({
|
|
@@ -290,67 +345,245 @@ function J(t, n) {
|
|
|
290
345
|
}), null;
|
|
291
346
|
}
|
|
292
347
|
}
|
|
293
|
-
function
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
348
|
+
function _(t, n, e) {
|
|
349
|
+
const o = t.attrs, i = [], r = [];
|
|
350
|
+
let s = 0, c = 0;
|
|
351
|
+
for (const f of t.children)
|
|
352
|
+
if (f.tag === "mj-column")
|
|
353
|
+
i.push(z(f, n)), r.push(f), c++;
|
|
354
|
+
else if (f.tag === "mj-group") {
|
|
355
|
+
s++;
|
|
356
|
+
for (const x of f.children)
|
|
357
|
+
x.tag === "mj-column" && (i.push(z(x, n)), r.push(x));
|
|
358
|
+
} else
|
|
302
359
|
n.push({
|
|
303
|
-
message: `Unexpected section child: ${
|
|
304
|
-
tag:
|
|
360
|
+
message: `Unexpected section child: ${f.tag}`,
|
|
361
|
+
tag: f.tag
|
|
305
362
|
});
|
|
306
|
-
|
|
307
|
-
id:
|
|
363
|
+
i.length === 0 && i.push({
|
|
364
|
+
id: b(),
|
|
308
365
|
type: "column",
|
|
309
366
|
attributes: {
|
|
310
|
-
padding:
|
|
367
|
+
padding: m(void 0, 0),
|
|
311
368
|
verticalAlign: "top"
|
|
312
369
|
},
|
|
313
370
|
blocks: []
|
|
314
371
|
});
|
|
315
|
-
const
|
|
372
|
+
const d = r.length ? pt(r, e, n) : [12], l = s === 1 && c === 0;
|
|
373
|
+
s > 0 && !l && n.push({
|
|
374
|
+
message: "A section mixing mj-group with other columns was flattened: its columns will stack on mobile",
|
|
375
|
+
tag: "mj-group"
|
|
376
|
+
});
|
|
377
|
+
const p = a(o, "full-width") === "full-width";
|
|
316
378
|
return {
|
|
317
|
-
id:
|
|
379
|
+
id: b(),
|
|
318
380
|
type: "row",
|
|
319
381
|
attributes: {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
382
|
+
...t.visibility,
|
|
383
|
+
backgroundColor: a(o, "background-color") || void 0,
|
|
384
|
+
...dt(o, n),
|
|
385
|
+
padding: m(a(o, "padding"), 0),
|
|
386
|
+
fullWidth: p,
|
|
387
|
+
cssClass: a(o, "css-class") || void 0,
|
|
388
|
+
...l ? { noStackOnMobile: !0 } : {}
|
|
325
389
|
},
|
|
326
|
-
columns:
|
|
327
|
-
columnRatios:
|
|
390
|
+
columns: i,
|
|
391
|
+
columnRatios: d,
|
|
328
392
|
locked: !1
|
|
329
393
|
};
|
|
330
394
|
}
|
|
331
|
-
function
|
|
332
|
-
const e = t
|
|
333
|
-
|
|
395
|
+
function dt(t, n) {
|
|
396
|
+
const e = a(t, "background-url");
|
|
397
|
+
if (!e) return {};
|
|
398
|
+
const o = a(t, "background-repeat");
|
|
399
|
+
return (o === "repeat-x" || o === "repeat-y") && n.push({
|
|
400
|
+
message: `background-repeat="${o}" became "repeat" — a row cannot repeat on one axis`,
|
|
401
|
+
tag: "mj-section"
|
|
402
|
+
}), {
|
|
403
|
+
backgroundImage: e,
|
|
404
|
+
backgroundRepeat: o === "no-repeat" ? "no-repeat" : "repeat",
|
|
405
|
+
backgroundSize: a(t, "background-size") || void 0,
|
|
406
|
+
backgroundPosition: a(t, "background-position") || void 0
|
|
407
|
+
};
|
|
334
408
|
}
|
|
335
|
-
function
|
|
409
|
+
function ut(t, n) {
|
|
410
|
+
var i;
|
|
411
|
+
const e = (i = t.attrs.width) == null ? void 0 : i.trim();
|
|
412
|
+
if (!e) return;
|
|
413
|
+
const o = parseFloat(e);
|
|
414
|
+
if (!(isNaN(o) || o <= 0))
|
|
415
|
+
return e.endsWith("%") ? o : o / n * 100;
|
|
416
|
+
}
|
|
417
|
+
function pt(t, n, e) {
|
|
418
|
+
const o = t.map((l) => ut(l, n));
|
|
419
|
+
if (o.every((l) => l === void 0)) {
|
|
420
|
+
const l = Math.floor(12 / o.length);
|
|
421
|
+
return o.map(() => l);
|
|
422
|
+
}
|
|
423
|
+
const i = o.reduce((l, u) => l + (u ?? 0), 0);
|
|
424
|
+
i > 101 && e.push({
|
|
425
|
+
message: `Column widths total ${Math.round(i)}% of the body width; they were scaled to fit`,
|
|
426
|
+
tag: "mj-section"
|
|
427
|
+
});
|
|
428
|
+
const r = o.filter((l) => l === void 0).length, s = Math.max(0, 100 - i), c = o.map((l) => l ?? s / r), d = c.reduce((l, u) => l + u, 0);
|
|
429
|
+
return c.map((l) => Math.max(1, Math.round(l * 12 / d)));
|
|
430
|
+
}
|
|
431
|
+
const y = "Ubuntu, Helvetica, Arial, sans-serif", N = {
|
|
432
|
+
"mj-body": { width: "600px" },
|
|
433
|
+
"mj-section": {
|
|
434
|
+
"background-repeat": "repeat",
|
|
435
|
+
"background-size": "auto",
|
|
436
|
+
"background-position": "top center",
|
|
437
|
+
direction: "ltr",
|
|
438
|
+
padding: "20px 0",
|
|
439
|
+
"text-align": "center",
|
|
440
|
+
"text-padding": "4px 4px 4px 0"
|
|
441
|
+
},
|
|
442
|
+
"mj-wrapper": {
|
|
443
|
+
"background-repeat": "repeat",
|
|
444
|
+
"background-size": "auto",
|
|
445
|
+
"background-position": "top center",
|
|
446
|
+
direction: "ltr",
|
|
447
|
+
padding: "20px 0",
|
|
448
|
+
"text-align": "center",
|
|
449
|
+
"text-padding": "4px 4px 4px 0"
|
|
450
|
+
},
|
|
451
|
+
"mj-column": { direction: "ltr", "vertical-align": "top" },
|
|
452
|
+
"mj-text": {
|
|
453
|
+
align: "left",
|
|
454
|
+
color: "#000000",
|
|
455
|
+
"font-family": y,
|
|
456
|
+
"font-size": "13px",
|
|
457
|
+
"line-height": "1",
|
|
458
|
+
padding: "10px 25px"
|
|
459
|
+
},
|
|
460
|
+
"mj-button": {
|
|
461
|
+
align: "center",
|
|
462
|
+
"background-color": "#414141",
|
|
463
|
+
border: "none",
|
|
464
|
+
"border-radius": "3px",
|
|
465
|
+
color: "#ffffff",
|
|
466
|
+
"font-family": y,
|
|
467
|
+
"font-size": "13px",
|
|
468
|
+
"font-weight": "normal",
|
|
469
|
+
"inner-padding": "10px 25px",
|
|
470
|
+
"line-height": "120%",
|
|
471
|
+
padding: "10px 25px",
|
|
472
|
+
target: "_blank",
|
|
473
|
+
"text-decoration": "none",
|
|
474
|
+
"text-transform": "none",
|
|
475
|
+
"vertical-align": "middle"
|
|
476
|
+
},
|
|
477
|
+
"mj-image": {
|
|
478
|
+
alt: "",
|
|
479
|
+
align: "center",
|
|
480
|
+
border: "0",
|
|
481
|
+
height: "auto",
|
|
482
|
+
padding: "10px 25px",
|
|
483
|
+
target: "_blank",
|
|
484
|
+
"font-size": "13px"
|
|
485
|
+
},
|
|
486
|
+
"mj-divider": {
|
|
487
|
+
"border-color": "#000000",
|
|
488
|
+
"border-style": "solid",
|
|
489
|
+
"border-width": "4px",
|
|
490
|
+
padding: "10px 25px",
|
|
491
|
+
width: "100%",
|
|
492
|
+
align: "center"
|
|
493
|
+
},
|
|
494
|
+
"mj-spacer": { height: "20px" },
|
|
495
|
+
"mj-social": {
|
|
496
|
+
align: "center",
|
|
497
|
+
"border-radius": "3px",
|
|
498
|
+
color: "#333333",
|
|
499
|
+
"font-family": y,
|
|
500
|
+
"font-size": "13px",
|
|
501
|
+
"icon-size": "20px",
|
|
502
|
+
"line-height": "22px",
|
|
503
|
+
mode: "horizontal",
|
|
504
|
+
padding: "10px 25px",
|
|
505
|
+
"text-decoration": "none"
|
|
506
|
+
},
|
|
507
|
+
"mj-social-element": {
|
|
508
|
+
alt: "",
|
|
509
|
+
align: "left",
|
|
510
|
+
"icon-position": "left",
|
|
511
|
+
color: "#000",
|
|
512
|
+
"border-radius": "3px",
|
|
513
|
+
"font-family": y,
|
|
514
|
+
"font-size": "13px",
|
|
515
|
+
"line-height": "1",
|
|
516
|
+
padding: "4px",
|
|
517
|
+
"text-padding": "4px 4px 4px 0",
|
|
518
|
+
target: "_blank",
|
|
519
|
+
"text-decoration": "none",
|
|
520
|
+
"vertical-align": "middle"
|
|
521
|
+
},
|
|
522
|
+
"mj-hero": {
|
|
523
|
+
mode: "fixed-height",
|
|
524
|
+
height: "0px",
|
|
525
|
+
"background-position": "center center",
|
|
526
|
+
padding: "0px",
|
|
527
|
+
"background-color": "#ffffff",
|
|
528
|
+
"vertical-align": "top"
|
|
529
|
+
},
|
|
530
|
+
"mj-navbar": {
|
|
531
|
+
align: "center",
|
|
532
|
+
"ico-align": "center",
|
|
533
|
+
"ico-open": "☰",
|
|
534
|
+
"ico-close": "⊗",
|
|
535
|
+
"ico-color": "#000000",
|
|
536
|
+
"ico-font-size": "30px",
|
|
537
|
+
"ico-font-family": y,
|
|
538
|
+
"ico-text-transform": "uppercase",
|
|
539
|
+
"ico-padding": "10px",
|
|
540
|
+
"ico-text-decoration": "none",
|
|
541
|
+
"ico-line-height": "30px"
|
|
542
|
+
},
|
|
543
|
+
"mj-navbar-link": {
|
|
544
|
+
color: "#000000",
|
|
545
|
+
"font-family": y,
|
|
546
|
+
"font-size": "13px",
|
|
547
|
+
"font-weight": "normal",
|
|
548
|
+
"line-height": "22px",
|
|
549
|
+
padding: "15px 10px",
|
|
550
|
+
target: "_blank",
|
|
551
|
+
"text-decoration": "none",
|
|
552
|
+
"text-transform": "uppercase"
|
|
553
|
+
},
|
|
554
|
+
"mj-table": {
|
|
555
|
+
align: "left",
|
|
556
|
+
border: "none",
|
|
557
|
+
cellpadding: "0",
|
|
558
|
+
cellspacing: "0",
|
|
559
|
+
color: "#000000",
|
|
560
|
+
"font-family": y,
|
|
561
|
+
"font-size": "13px",
|
|
562
|
+
"line-height": "22px",
|
|
563
|
+
padding: "10px 25px",
|
|
564
|
+
"table-layout": "auto",
|
|
565
|
+
width: "100%"
|
|
566
|
+
}
|
|
567
|
+
}, gt = y;
|
|
568
|
+
function ft(t, n, e) {
|
|
336
569
|
return {
|
|
337
|
-
id:
|
|
570
|
+
id: b(),
|
|
338
571
|
type: "hero",
|
|
339
572
|
values: {
|
|
340
|
-
backgroundUrl:
|
|
341
|
-
backgroundPosition:
|
|
342
|
-
mode:
|
|
343
|
-
width:
|
|
344
|
-
height:
|
|
345
|
-
verticalAlign:
|
|
346
|
-
padding:
|
|
347
|
-
innerPadding:
|
|
348
|
-
backgroundColor:
|
|
573
|
+
backgroundUrl: a(t, "background-url"),
|
|
574
|
+
backgroundPosition: a(t, "background-position", "center center"),
|
|
575
|
+
mode: a(t, "mode", "fluid-height"),
|
|
576
|
+
width: w(t, "width", 600),
|
|
577
|
+
height: w(t, "height", 400),
|
|
578
|
+
verticalAlign: a(t, "vertical-align", "middle"),
|
|
579
|
+
padding: m(a(t, "padding"), 0),
|
|
580
|
+
innerPadding: m(e, 20),
|
|
581
|
+
backgroundColor: a(t, "background-color", "#ffffff"),
|
|
349
582
|
content: n
|
|
350
583
|
}
|
|
351
584
|
};
|
|
352
585
|
}
|
|
353
|
-
const
|
|
586
|
+
const ht = [
|
|
354
587
|
["font-style", "font-style"],
|
|
355
588
|
["font-weight", "font-weight"],
|
|
356
589
|
["letter-spacing", "letter-spacing"],
|
|
@@ -359,111 +592,124 @@ const et = [
|
|
|
359
592
|
["text-decoration", "text-decoration"],
|
|
360
593
|
["text-transform", "text-transform"],
|
|
361
594
|
["height", "height"]
|
|
362
|
-
],
|
|
363
|
-
function
|
|
364
|
-
const
|
|
365
|
-
return
|
|
595
|
+
], mt = { "line-height": "1.5", align: "left" };
|
|
596
|
+
function D(t, n, e) {
|
|
597
|
+
const o = ht.filter(([, i]) => t[i] && t[i] !== mt[i]).concat(!e && t.padding ? [["padding", "padding"]] : []).map(([i, r]) => `${i}:${t[r]};`).join("");
|
|
598
|
+
return o ? `<div style="${j(o)}">${n}</div>` : e ? n : `<div>${n}</div>`;
|
|
366
599
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
"
|
|
370
|
-
border: "none",
|
|
371
|
-
"border-radius": "3px",
|
|
372
|
-
color: "#ffffff",
|
|
373
|
-
"font-family": "Ubuntu, Helvetica, Arial, sans-serif",
|
|
374
|
-
"font-size": "13px",
|
|
375
|
-
"font-weight": "normal",
|
|
376
|
-
"inner-padding": "10px 25px",
|
|
377
|
-
"line-height": "120%",
|
|
378
|
-
padding: "10px 25px",
|
|
379
|
-
target: "_blank",
|
|
380
|
-
"text-decoration": "none",
|
|
381
|
-
"text-transform": "none",
|
|
382
|
-
"vertical-align": "middle"
|
|
383
|
-
};
|
|
384
|
-
function ot(t, n) {
|
|
385
|
-
const e = { ...rt, ...t }, r = e["background-color"], o = `border:${e.border};border-radius:${e["border-radius"]};cursor:auto;mso-padding-alt:${e["inner-padding"]};background:${r};`, a = `display:inline-block;background:${r};color:${e.color};font-family:${e["font-family"]};font-size:${e["font-size"]};font-weight:${e["font-weight"]};line-height:${e["line-height"]};margin:0;text-decoration:${e["text-decoration"]};text-transform:${e["text-transform"]};padding:${e["inner-padding"]};mso-padding-alt:0px;border-radius:${e["border-radius"]};`, l = e.href ? `<a href="${w(e.href)}" target="${w(e.target)}" style="${w(a)}">${n.trim()}</a>` : `<p style="${w(a)}">${n.trim()}</p>`;
|
|
386
|
-
return `<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%"><tr><td align="${w(e.align)}" style="padding:${w(e.padding)};"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;"><tr><td align="center"${r === "none" ? "" : ` bgcolor="${w(r)}"`} role="presentation" valign="${w(e["vertical-align"])}" style="${w(o)}">${l}</td></tr></table></td></tr></table>`;
|
|
600
|
+
function bt(t, n) {
|
|
601
|
+
const e = { ...N["mj-button"], ...t }, o = e["background-color"], i = `border:${e.border};border-radius:${e["border-radius"]};cursor:auto;mso-padding-alt:${e["inner-padding"]};background:${o};`, r = `display:inline-block;background:${o};color:${e.color};font-family:${e["font-family"]};font-size:${e["font-size"]};font-weight:${e["font-weight"]};line-height:${e["line-height"]};margin:0;text-decoration:${e["text-decoration"]};text-transform:${e["text-transform"]};padding:${e["inner-padding"]};mso-padding-alt:0px;border-radius:${e["border-radius"]};`, s = e.href ? `<a href="${j(e.href)}" target="${j(e.target)}" style="${j(r)}">${n.trim()}</a>` : `<p style="${j(r)}">${n.trim()}</p>`;
|
|
602
|
+
return `<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%"><tr><td align="${j(e.align)}" style="padding:${j(e.padding)};"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;"><tr><td align="center"${o === "none" ? "" : ` bgcolor="${j(o)}"`} role="presentation" valign="${j(e["vertical-align"])}" style="${j(i)}">${s}</td></tr></table></td></tr></table>`;
|
|
387
603
|
}
|
|
388
|
-
function
|
|
604
|
+
function j(t) {
|
|
389
605
|
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
390
606
|
}
|
|
391
|
-
function
|
|
392
|
-
const e =
|
|
393
|
-
let
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
607
|
+
function xt(t, n) {
|
|
608
|
+
const e = w(t.attrs, "width", 600), o = a(t.attrs, "background-color"), i = [];
|
|
609
|
+
let r = [], s;
|
|
610
|
+
const c = (d) => {
|
|
611
|
+
var f;
|
|
612
|
+
const [l, u] = r;
|
|
613
|
+
l && (d.attributes.condition = l);
|
|
614
|
+
const [p] = ((f = d.columns[0]) == null ? void 0 : f.blocks) ?? [];
|
|
615
|
+
return u && (p == null ? void 0 : p.type) === "hero" && (p.values.condition = u), r = [], s && (d.attributes.repeat = s, s = void 0), d;
|
|
616
|
+
};
|
|
617
|
+
for (const d of t.children)
|
|
618
|
+
switch (d.tag) {
|
|
397
619
|
case "mj-raw": {
|
|
398
|
-
const
|
|
399
|
-
|
|
620
|
+
const l = /\{\{#if\s+([^}]+?)\s*\}\}/.exec(d.text ?? "");
|
|
621
|
+
l && r.push(l[1].trim());
|
|
622
|
+
const u = /^\s*\{\{#each\s+([^}]+?)\s*\}\}\s*$/.exec(d.text ?? "");
|
|
623
|
+
u && (s = u[1].trim(), r = [r[0]]);
|
|
400
624
|
break;
|
|
401
625
|
}
|
|
402
626
|
case "mj-section":
|
|
403
|
-
|
|
627
|
+
i.push(c(_(d, n, e)));
|
|
404
628
|
break;
|
|
405
629
|
case "mj-hero": {
|
|
406
|
-
const
|
|
407
|
-
|
|
630
|
+
const l = kt(d, n), u = ft(d.attrs, l.content, l.innerPadding);
|
|
631
|
+
Object.assign(u.values, d.visibility);
|
|
632
|
+
const p = {
|
|
633
|
+
id: b(),
|
|
408
634
|
type: "column",
|
|
409
635
|
attributes: {
|
|
410
|
-
padding:
|
|
636
|
+
padding: m(void 0, 0),
|
|
411
637
|
verticalAlign: "top"
|
|
412
638
|
},
|
|
413
|
-
blocks: [
|
|
414
|
-
},
|
|
415
|
-
id:
|
|
639
|
+
blocks: [u]
|
|
640
|
+
}, f = {
|
|
641
|
+
id: b(),
|
|
416
642
|
type: "row",
|
|
417
643
|
attributes: {
|
|
418
|
-
padding:
|
|
644
|
+
padding: m(void 0, 0),
|
|
419
645
|
fullWidth: !1
|
|
420
646
|
},
|
|
421
647
|
columns: [p],
|
|
422
648
|
columnRatios: [12],
|
|
423
649
|
locked: !1
|
|
424
650
|
};
|
|
425
|
-
|
|
651
|
+
i.push(c(f));
|
|
426
652
|
break;
|
|
427
653
|
}
|
|
428
|
-
case "mj-wrapper":
|
|
429
|
-
|
|
430
|
-
|
|
654
|
+
case "mj-wrapper": {
|
|
655
|
+
const l = d.children.filter((h) => h.tag === "mj-section"), u = m(d.attrs.padding), p = {};
|
|
656
|
+
for (const h of [
|
|
657
|
+
"background-color",
|
|
658
|
+
"background-url",
|
|
659
|
+
"background-repeat",
|
|
660
|
+
"background-size",
|
|
661
|
+
"background-position",
|
|
662
|
+
"full-width"
|
|
663
|
+
])
|
|
664
|
+
d.attrs[h] && (p[h] = d.attrs[h]);
|
|
665
|
+
const f = p["background-color"] || p["background-url"] || Object.values(u).some((h) => h > 0);
|
|
666
|
+
let x = !1;
|
|
667
|
+
for (let h = 0; h < l.length; h++) {
|
|
668
|
+
const g = l[h];
|
|
669
|
+
g.attrs["background-color"] || g.attrs["background-url"] ? f && (x = !0) : g.attrs = { ...g.attrs, ...p };
|
|
670
|
+
const k = c(_(g, n, e));
|
|
671
|
+
k.attributes.padding.left += u.left, k.attributes.padding.right += u.right, h === 0 && (k.attributes.padding.top += u.top), h === l.length - 1 && (k.attributes.padding.bottom += u.bottom), i.push(k);
|
|
672
|
+
}
|
|
673
|
+
x && n.push({
|
|
674
|
+
message: "A section with its own background covers the padding of its mj-wrapper",
|
|
675
|
+
tag: "mj-wrapper"
|
|
676
|
+
}), p["background-url"] && l.length > 1 && n.push({
|
|
677
|
+
message: "An mj-wrapper background image was repeated on each of its sections",
|
|
431
678
|
tag: "mj-wrapper"
|
|
432
679
|
});
|
|
433
|
-
for (const c of s.children)
|
|
434
|
-
c.tag === "mj-section" && o.push(l(A(c, n)));
|
|
435
680
|
break;
|
|
681
|
+
}
|
|
436
682
|
default:
|
|
437
683
|
n.push({
|
|
438
|
-
message: `Unknown body child element: ${
|
|
439
|
-
tag:
|
|
684
|
+
message: `Unknown body child element: ${d.tag}`,
|
|
685
|
+
tag: d.tag
|
|
440
686
|
});
|
|
441
687
|
break;
|
|
442
688
|
}
|
|
443
|
-
return { width: e, backgroundColor:
|
|
689
|
+
return { width: e, backgroundColor: o, rows: i };
|
|
444
690
|
}
|
|
445
|
-
function
|
|
691
|
+
function kt(t, n) {
|
|
446
692
|
const [e] = t.children;
|
|
447
693
|
if (t.children.length === 1 && e.tag === "mj-text")
|
|
448
|
-
return { content:
|
|
449
|
-
const
|
|
450
|
-
for (const
|
|
451
|
-
|
|
452
|
-
return { content:
|
|
453
|
-
}
|
|
454
|
-
const
|
|
455
|
-
function
|
|
456
|
-
const { "mj-class":
|
|
457
|
-
const
|
|
458
|
-
return { ...
|
|
694
|
+
return { content: D(e.attrs, e.text, !0), innerPadding: e.attrs.padding };
|
|
695
|
+
const o = [];
|
|
696
|
+
for (const i of t.children)
|
|
697
|
+
i.tag === "mj-text" ? o.push(D(i.attrs, i.text, !1)) : i.tag === "mj-button" ? o.push(bt(i.attrs, i.text)) : n.push({ message: `Unsupported mj-hero child element: ${i.tag}`, tag: i.tag });
|
|
698
|
+
return { content: o.join("") || "<p>Hero Content</p>" };
|
|
699
|
+
}
|
|
700
|
+
const wt = /* @__PURE__ */ new Set(["mj-section", "mj-column", "mj-text", "mj-button", "mj-image"]);
|
|
701
|
+
function F(t, n, e) {
|
|
702
|
+
const { "mj-class": o = "", ...i } = t.attrs, r = o.split(/\s+/).filter(Boolean).reduce((c, d) => {
|
|
703
|
+
const l = n.classes[d] ?? {}, u = c["css-class"] && l["css-class"] ? { "css-class": `${c["css-class"]} ${l["css-class"]}` } : {};
|
|
704
|
+
return { ...c, ...l, ...u };
|
|
459
705
|
}, {});
|
|
460
|
-
t.attrs = { ...n.all, ...n.tags[t.tag], ...
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
for (const
|
|
464
|
-
|
|
706
|
+
t.attrs = { ...N[t.tag], ...n.all, ...n.tags[t.tag], ...r, ...i }, t.visibility = R(t.attrs);
|
|
707
|
+
const s = t.attrs["css-class"];
|
|
708
|
+
s && !wt.has(t.tag) && e.push({ message: `css-class "${s}" on <${t.tag}> was dropped`, tag: t.tag });
|
|
709
|
+
for (const c of t.children)
|
|
710
|
+
F(c, n, e);
|
|
465
711
|
}
|
|
466
|
-
const
|
|
712
|
+
const I = /* @__PURE__ */ new Set([
|
|
467
713
|
"address",
|
|
468
714
|
"article",
|
|
469
715
|
"aside",
|
|
@@ -514,66 +760,67 @@ const D = /* @__PURE__ */ new Set([
|
|
|
514
760
|
"source",
|
|
515
761
|
"track",
|
|
516
762
|
"wbr"
|
|
517
|
-
]),
|
|
518
|
-
function
|
|
763
|
+
]), vt = "14px", jt = "#000000";
|
|
764
|
+
function M(t, n) {
|
|
519
765
|
if (t.tag === "mj-text") {
|
|
520
|
-
const { color: e, "font-size":
|
|
521
|
-
e && e.toLowerCase() !==
|
|
766
|
+
const { color: e, "font-size": o, "font-family": i } = t.attrs, r = [];
|
|
767
|
+
e && e.toLowerCase() !== jt && r.push(`color: ${e}`), o && o !== vt && r.push(`font-size: ${o}`), i && i !== n && r.push(`font-family: ${i}`), r.length > 0 && (t.text = yt(t.text, `<span style="${$t(r.join("; "))}">`));
|
|
522
768
|
return;
|
|
523
769
|
}
|
|
524
770
|
for (const e of t.children)
|
|
525
|
-
|
|
771
|
+
M(e, n);
|
|
526
772
|
}
|
|
527
|
-
function
|
|
773
|
+
function yt(t, n) {
|
|
528
774
|
const e = [];
|
|
529
|
-
let
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
},
|
|
535
|
-
onopentag(
|
|
536
|
-
if (
|
|
537
|
-
|
|
775
|
+
let o = -1, i = -1, r = !1, s = 0;
|
|
776
|
+
const c = () => {
|
|
777
|
+
o >= 0 && r && e.push([o, n], [i, "</span>"]), o = -1, r = !1;
|
|
778
|
+
}, d = (p, f) => {
|
|
779
|
+
o < 0 && (o = p), i = f;
|
|
780
|
+
}, l = new O({
|
|
781
|
+
onopentag(p) {
|
|
782
|
+
if (s === 0 && I.has(p)) {
|
|
783
|
+
c();
|
|
538
784
|
return;
|
|
539
785
|
}
|
|
540
|
-
|
|
786
|
+
d(l.startIndex, l.endIndex + 1), B.has(p) ? r = !0 : s++;
|
|
541
787
|
},
|
|
542
|
-
onclosetag(
|
|
543
|
-
if (!B.has(
|
|
544
|
-
if (
|
|
545
|
-
|
|
788
|
+
onclosetag(p, f) {
|
|
789
|
+
if (!B.has(p)) {
|
|
790
|
+
if (s === 0) {
|
|
791
|
+
I.has(p) && c();
|
|
546
792
|
return;
|
|
547
793
|
}
|
|
548
|
-
|
|
794
|
+
s--, f || (i = l.endIndex + 1);
|
|
549
795
|
}
|
|
550
796
|
},
|
|
551
|
-
ontext(
|
|
552
|
-
|
|
797
|
+
ontext(p) {
|
|
798
|
+
o < 0 && !p.trim() || (d(l.startIndex, l.endIndex + 1), p.trim() && (r = !0));
|
|
553
799
|
},
|
|
554
800
|
oncomment() {
|
|
555
|
-
|
|
801
|
+
o >= 0 && (i = l.endIndex + 1);
|
|
556
802
|
}
|
|
557
803
|
}, { recognizeSelfClosing: !0, lowerCaseTags: !0 });
|
|
558
|
-
|
|
559
|
-
let
|
|
560
|
-
for (const [
|
|
561
|
-
|
|
562
|
-
return
|
|
804
|
+
l.write(t), l.end(), c();
|
|
805
|
+
let u = t;
|
|
806
|
+
for (const [p, f] of e.reverse())
|
|
807
|
+
u = u.slice(0, p) + f + u.slice(p);
|
|
808
|
+
return u;
|
|
563
809
|
}
|
|
564
|
-
function
|
|
810
|
+
function $t(t) {
|
|
565
811
|
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
566
812
|
}
|
|
567
|
-
function
|
|
568
|
-
const n = { tag: "root", attrs: {}, children: [], text: "" }, e = [n],
|
|
813
|
+
function St(t) {
|
|
814
|
+
const n = { tag: "root", attrs: {}, children: [], text: "" }, e = [n], o = /* @__PURE__ */ new Set([
|
|
569
815
|
"mj-text",
|
|
570
816
|
"mj-button",
|
|
571
817
|
"mj-raw",
|
|
572
818
|
"mj-preview",
|
|
819
|
+
"mj-title",
|
|
573
820
|
"mj-social-element",
|
|
574
821
|
"mj-navbar-link",
|
|
575
822
|
"mj-table"
|
|
576
|
-
]),
|
|
823
|
+
]), i = /* @__PURE__ */ new Set([
|
|
577
824
|
"mj-image",
|
|
578
825
|
"mj-divider",
|
|
579
826
|
"mj-spacer",
|
|
@@ -581,7 +828,7 @@ function gt(t) {
|
|
|
581
828
|
"mj-class",
|
|
582
829
|
"mj-font",
|
|
583
830
|
"mj-breakpoint"
|
|
584
|
-
]),
|
|
831
|
+
]), r = /* @__PURE__ */ new Set([
|
|
585
832
|
"area",
|
|
586
833
|
"base",
|
|
587
834
|
"br",
|
|
@@ -595,106 +842,112 @@ function gt(t) {
|
|
|
595
842
|
"source",
|
|
596
843
|
"track",
|
|
597
844
|
"wbr"
|
|
598
|
-
]),
|
|
599
|
-
let
|
|
600
|
-
const
|
|
601
|
-
onopentag(
|
|
602
|
-
if (
|
|
603
|
-
const
|
|
604
|
-
|
|
845
|
+
]), s = /* @__PURE__ */ new Set(["mj-text", "mj-button", "mj-raw"]), c = /* @__PURE__ */ new Set(["style", "script"]), d = (g) => g.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), l = (g) => g.replace(/&/g, "&").replace(/"/g, """);
|
|
846
|
+
let u = null, p = "", f = 0, x = !1;
|
|
847
|
+
const h = new O({
|
|
848
|
+
onopentag(g, k) {
|
|
849
|
+
if (u) {
|
|
850
|
+
const W = s.has(u.node.tag), T = Object.entries(k).map(([P, A]) => `${P}="${W ? l(A) : A}"`).join(" ");
|
|
851
|
+
p += T ? `<${g} ${T}>` : `<${g}>`, r.has(g) || f++, c.has(g) && (x = !0);
|
|
605
852
|
return;
|
|
606
853
|
}
|
|
607
|
-
const
|
|
608
|
-
e[e.length - 1].children.push(
|
|
854
|
+
const v = { tag: g, attrs: k, children: [], text: "" };
|
|
855
|
+
e[e.length - 1].children.push(v), !i.has(g) && (e.push(v), o.has(g) && (u = { node: v, depth: 0 }, p = "", f = 0));
|
|
609
856
|
},
|
|
610
|
-
ontext(
|
|
611
|
-
if (
|
|
612
|
-
const
|
|
613
|
-
|
|
857
|
+
ontext(g) {
|
|
858
|
+
if (u) {
|
|
859
|
+
const v = s.has(u.node.tag) && !x;
|
|
860
|
+
p += v ? d(g) : g;
|
|
614
861
|
return;
|
|
615
862
|
}
|
|
616
|
-
const
|
|
617
|
-
|
|
863
|
+
const k = e[e.length - 1];
|
|
864
|
+
k.text += g;
|
|
618
865
|
},
|
|
619
|
-
onclosetag(
|
|
620
|
-
if (
|
|
621
|
-
if (
|
|
622
|
-
if (
|
|
623
|
-
|
|
866
|
+
onclosetag(g) {
|
|
867
|
+
if (u) {
|
|
868
|
+
if (r.has(g)) return;
|
|
869
|
+
if (f > 0) {
|
|
870
|
+
p += `</${g}>`, f--, c.has(g) && (x = !1);
|
|
624
871
|
return;
|
|
625
872
|
}
|
|
626
|
-
|
|
873
|
+
u.node.text = p, u = null, p = "", f = 0, e.length > 1 && e[e.length - 1].tag === g && e.pop();
|
|
627
874
|
return;
|
|
628
875
|
}
|
|
629
|
-
|
|
876
|
+
i.has(g) || e.length > 1 && e[e.length - 1].tag === g && e.pop();
|
|
630
877
|
},
|
|
631
|
-
oncomment(
|
|
632
|
-
|
|
878
|
+
oncomment(g) {
|
|
879
|
+
u && (p += `<!--${g}-->`);
|
|
633
880
|
}
|
|
634
881
|
}, {
|
|
635
882
|
recognizeSelfClosing: !0,
|
|
636
883
|
lowerCaseTags: !0,
|
|
637
884
|
lowerCaseAttributeNames: !0
|
|
638
885
|
});
|
|
639
|
-
return
|
|
886
|
+
return h.write(t), h.end(), n;
|
|
640
887
|
}
|
|
641
|
-
function
|
|
888
|
+
function C(t, n) {
|
|
642
889
|
if (t.tag === n) return t;
|
|
643
890
|
for (const e of t.children) {
|
|
644
|
-
const
|
|
645
|
-
if (
|
|
891
|
+
const o = C(e, n);
|
|
892
|
+
if (o) return o;
|
|
646
893
|
}
|
|
647
894
|
}
|
|
648
|
-
function
|
|
649
|
-
|
|
650
|
-
|
|
895
|
+
function At(t, n) {
|
|
896
|
+
var k;
|
|
897
|
+
const e = [], o = St(t), i = C(o, "mjml");
|
|
898
|
+
if (!i)
|
|
651
899
|
return e.push({ message: "No <mjml> root element found" }), {
|
|
652
|
-
document:
|
|
653
|
-
warnings: e
|
|
900
|
+
document: L(),
|
|
901
|
+
warnings: e,
|
|
902
|
+
fonts: []
|
|
654
903
|
};
|
|
655
|
-
const
|
|
656
|
-
let
|
|
657
|
-
if (
|
|
658
|
-
|
|
659
|
-
tag:
|
|
660
|
-
attrs:
|
|
661
|
-
children:
|
|
662
|
-
tag:
|
|
663
|
-
attrs:
|
|
904
|
+
const r = C(i, "mj-head"), s = C(i, "mj-body");
|
|
905
|
+
let c = { fonts: [], attributeDefaults: { all: {}, tags: {}, classes: {} } };
|
|
906
|
+
if (r && (c = q(
|
|
907
|
+
r.children.map((v) => ({
|
|
908
|
+
tag: v.tag,
|
|
909
|
+
attrs: v.attrs,
|
|
910
|
+
children: v.children.map((S) => ({
|
|
911
|
+
tag: S.tag,
|
|
912
|
+
attrs: S.attrs,
|
|
664
913
|
children: [],
|
|
665
|
-
text:
|
|
914
|
+
text: S.text
|
|
666
915
|
})),
|
|
667
|
-
text:
|
|
916
|
+
text: v.text
|
|
668
917
|
}))
|
|
669
|
-
)), !
|
|
918
|
+
)), !s)
|
|
670
919
|
return e.push({ message: "No <mj-body> element found" }), {
|
|
671
|
-
document:
|
|
672
|
-
warnings: e
|
|
920
|
+
document: L(),
|
|
921
|
+
warnings: e,
|
|
922
|
+
fonts: c.fonts
|
|
673
923
|
};
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
const
|
|
924
|
+
const d = c.fontFamily ?? gt;
|
|
925
|
+
F(s, c.attributeDefaults, e), M(s, d);
|
|
926
|
+
const l = xt(s, e), u = i.attrs.lang, p = u && u !== "und" ? u : void 0, f = i.attrs.dir, x = f === "ltr" || f === "rtl" ? f : void 0, h = (/* @__PURE__ */ new Date()).toISOString();
|
|
677
927
|
return { document: {
|
|
678
928
|
version: "1.0",
|
|
679
929
|
metadata: {
|
|
680
|
-
name: "Imported Template",
|
|
681
|
-
previewText:
|
|
682
|
-
createdAt:
|
|
683
|
-
updatedAt:
|
|
930
|
+
name: ((k = c.title) == null ? void 0 : k.trim()) || "Imported Template",
|
|
931
|
+
previewText: c.previewText,
|
|
932
|
+
createdAt: h,
|
|
933
|
+
updatedAt: h
|
|
684
934
|
},
|
|
685
935
|
body: {
|
|
686
936
|
attributes: {
|
|
687
|
-
width:
|
|
688
|
-
backgroundColor:
|
|
689
|
-
fontFamily:
|
|
937
|
+
width: l.width,
|
|
938
|
+
backgroundColor: l.backgroundColor,
|
|
939
|
+
fontFamily: d,
|
|
690
940
|
contentAlignment: "center",
|
|
691
|
-
|
|
941
|
+
...c.linkStyle ? { linkStyle: c.linkStyle } : {},
|
|
942
|
+
...p ? { language: p } : {},
|
|
943
|
+
...x ? { direction: x } : {},
|
|
944
|
+
css: c.css
|
|
692
945
|
},
|
|
693
|
-
rows:
|
|
946
|
+
rows: l.rows
|
|
694
947
|
}
|
|
695
|
-
}, warnings: e };
|
|
948
|
+
}, warnings: e, fonts: c.fonts };
|
|
696
949
|
}
|
|
697
|
-
function
|
|
950
|
+
function L() {
|
|
698
951
|
const t = (/* @__PURE__ */ new Date()).toISOString();
|
|
699
952
|
return {
|
|
700
953
|
version: "1.0",
|
|
@@ -715,5 +968,5 @@ function I() {
|
|
|
715
968
|
};
|
|
716
969
|
}
|
|
717
970
|
export {
|
|
718
|
-
|
|
971
|
+
At as mjmlToDocument
|
|
719
972
|
};
|