@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/dist/index.js CHANGED
@@ -1,36 +1,45 @@
1
- import { Parser as _ } from "htmlparser2";
2
- import { generateId as m } from "@lit-pigeon/core";
3
- function H(t, n) {
4
- const e = { attributeDefaults: { all: {}, tags: {}, classes: {} } }, r = [];
5
- for (const o of t)
6
- switch (o.tag) {
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 = o.text;
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 a of o.children) {
12
- const l = e.attributeDefaults;
13
- if (a.tag === "mj-all")
14
- Object.assign(l.all, a.attrs);
15
- else if (a.tag === "mj-class") {
16
- const { name: s, ...c } = a.attrs;
17
- s && (l.classes[s] = { ...l.classes[s], ...c });
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
- l.tags[a.tag] = { ...l.tags[a.tag], ...a.attrs };
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
- o.attrs.inline !== "inline" && o.text.trim() && r.push(o.text.trim());
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 r.length > 0 && (e.css = r.join(`
36
+ return o.length > 0 && (e.css = o.join(`
28
37
  `)), e;
29
38
  }
30
- function f(t, n = 0) {
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(L);
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 L(t) {
56
+ function G(t) {
48
57
  const n = parseFloat(t);
49
58
  return isNaN(n) ? 0 : n;
50
59
  }
51
- function i(t, n, e = "") {
60
+ function a(t, n, e = "") {
52
61
  return t[n] ?? e;
53
62
  }
54
- function b(t, n, e = 0) {
55
- const r = t[n];
56
- if (r === void 0 || r === "") return e;
57
- const o = parseFloat(r);
58
- return isNaN(o) ? e : o;
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 O(t, n) {
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: m(),
77
+ id: b(),
63
78
  type: "text",
64
79
  values: {
65
80
  content: n,
66
- padding: f(i(t, "padding"), 10),
67
- lineHeight: i(t, "line-height", "1.5"),
68
- textAlign: i(t, "align", "left"),
69
- cssClass: i(t, "css-class") || void 0
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 U(t) {
74
- const n = i(t, "width"), e = n && parseInt(n, 10) || "auto";
88
+ function K(t) {
89
+ const n = a(t, "width"), e = n && parseInt(n, 10) || "auto";
75
90
  return {
76
- id: m(),
91
+ id: b(),
77
92
  type: "image",
78
93
  values: {
79
- src: i(t, "src"),
80
- alt: i(t, "alt"),
94
+ src: a(t, "src"),
95
+ alt: a(t, "alt"),
81
96
  width: e,
82
- href: i(t, "href") || void 0,
83
- padding: f(i(t, "padding"), 10),
84
- alignment: i(t, "align", "center"),
85
- borderRadius: b(t, "border-radius", 0),
86
- cssClass: i(t, "css-class") || void 0
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
- function W(t, n) {
91
- const e = n.trim(), r = /^<p[\s>]/i.test(e) ? e : `<p>${e}</p>`;
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: m(),
126
+ id: b(),
94
127
  type: "button",
95
128
  values: {
96
- content: r,
97
- href: i(t, "href", "#"),
98
- backgroundColor: i(t, "background-color", "#3b82f6"),
99
- textColor: i(t, "color", "#ffffff"),
100
- borderRadius: b(t, "border-radius", 4),
101
- padding: f(i(t, "padding"), 10),
102
- innerPadding: f(i(t, "inner-padding"), 12),
103
- fontSize: b(t, "font-size", 16),
104
- fontWeight: i(t, "font-weight", "600"),
105
- alignment: i(t, "align", "center"),
106
- fullWidth: i(t, "width") === "100%",
107
- cssClass: i(t, "css-class") || void 0
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 P(t) {
145
+ function Q(t) {
112
146
  return {
113
- id: m(),
147
+ id: b(),
114
148
  type: "divider",
115
149
  values: {
116
- borderColor: i(t, "border-color", "#e2e8f0"),
117
- borderWidth: b(t, "border-width", 1),
118
- borderStyle: i(t, "border-style", "solid"),
119
- padding: f(i(t, "padding"), 10),
120
- width: i(t, "width", "100%")
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 q(t) {
158
+ function tt(t) {
125
159
  return {
126
- id: m(),
160
+ id: b(),
127
161
  type: "spacer",
128
162
  values: {
129
- height: b(t, "height", 20)
163
+ height: w(t, "height", 20)
130
164
  }
131
165
  };
132
166
  }
133
- const G = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
134
- function X(t) {
167
+ const et = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
168
+ function nt(t) {
135
169
  const n = t.toLowerCase();
136
- for (const e of G)
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 M(t, n) {
141
- const e = n.map((r) => {
142
- const a = {
143
- type: X(i(r.attrs, "name", "custom")),
144
- href: i(r.attrs, "href", "#"),
145
- label: r.innerText.trim() || void 0
146
- }, l = i(r.attrs, "src");
147
- return l && (a.iconUrl = l), a;
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: m(),
185
+ id: b(),
151
186
  type: "social",
152
187
  values: {
153
188
  icons: e,
154
- iconSize: b(t, "icon-size", 32),
155
- spacing: b(t, "icon-padding", 8),
156
- alignment: i(t, "align", "center"),
157
- padding: f(i(t, "padding"), 10)
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 K(t) {
162
- const n = t.match(/^<div\s+style="padding:\s*([^"]*)">([\s\S]*)<\/div>$/);
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: m(),
201
+ id: b(),
165
202
  type: "html",
166
203
  values: {
167
- content: n[2],
168
- padding: f(n[1], 0)
204
+ content: n[3],
205
+ padding: m(n[2], 0),
206
+ ...R({ "css-class": n[1] ?? "" })
169
207
  }
170
208
  } : {
171
- id: m(),
209
+ id: b(),
172
210
  type: "html",
173
211
  values: {
174
212
  content: t,
175
- padding: f(void 0, 0)
213
+ padding: m(void 0, 0)
176
214
  }
177
215
  };
178
216
  }
179
- const V = {
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 Y(t, n) {
193
- const e = { ...V, ...t }, r = e.width.endsWith("%") || e.width === "auto" ? e.width : String(parseInt(e.width, 10)), o = parseFloat(e.cellspacing.replace(/[^\d.]/g, "")), a = [
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
- ...o > 0 ? ["border-collapse:separate"] : []
202
- ].map((s) => `${s};`).join(""), l = [];
203
- return e.align !== "left" && l.push(`align="${j(e.align)}"`), l.push(`cellpadding="${j(e.cellpadding)}"`, `cellspacing="${j(e.cellspacing)}"`), t.role && l.push(`role="${j(t.role)}"`), l.push(`width="${j(r)}"`, 'border="0"', `style="${j(a)}"`), {
204
- id: m(),
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 ${l.join(" ")}>${n.trim()}</table>`,
208
- padding: f(i(e, "padding"), 0)
245
+ content: `<table ${s.join(" ")}>${n.trim()}</table>`,
246
+ padding: m(a(e, "padding"), 0)
209
247
  }
210
248
  };
211
249
  }
212
- function j(t) {
250
+ function $(t) {
213
251
  return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
214
252
  }
215
- function Z(t, n) {
216
- const e = i(t, "base-url"), r = n.map((o) => {
217
- const a = {
218
- href: e + i(o.attrs, "href", "#"),
219
- text: o.innerText.trim() || "Link"
220
- }, l = i(o.attrs, "color");
221
- l && (a.color = l);
222
- const s = i(o.attrs, "font-weight");
223
- s && (a.fontWeight = s);
224
- const c = i(o.attrs, "text-decoration");
225
- c && (a.textDecoration = c);
226
- const g = i(o.attrs, "padding");
227
- return g && (a.padding = g), a;
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: m(),
268
+ id: b(),
231
269
  type: "navbar",
232
270
  values: {
233
- links: r,
234
- hamburger: i(t, "hamburger", "hamburger"),
235
- alignment: i(t, "align", "center"),
236
- padding: f(i(t, "padding"), 10),
237
- linkColor: i(t, "ico-color", "#000000"),
238
- linkFontSize: b(t, "font-size", 14),
239
- linkPadding: i(t, "link-padding", "10px 15px")
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 T(t, n) {
244
- const e = t.attrs, r = [];
245
- for (const o of t.children) {
246
- const a = J(o, n);
247
- a && r.push(a);
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: m(),
296
+ id: b(),
251
297
  type: "column",
252
298
  attributes: {
253
- backgroundColor: i(e, "background-color") || void 0,
254
- padding: f(i(e, "padding"), 0),
255
- borderRadius: b(e, "border-radius", 0) || void 0,
256
- verticalAlign: i(e, "vertical-align", "top"),
257
- cssClass: i(e, "css-class") || void 0
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: r
306
+ blocks: o
260
307
  };
261
308
  }
262
- function J(t, n) {
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 O(t.attrs, t.text);
320
+ return X(t.attrs, t.text);
266
321
  case "mj-image":
267
- return U(t.attrs);
322
+ return K(t.attrs);
268
323
  case "mj-button":
269
- return W(t.attrs, t.text);
324
+ return Z(t.attrs, t.text);
270
325
  case "mj-divider":
271
- return P(t.attrs);
326
+ return Q(t.attrs);
272
327
  case "mj-spacer":
273
- return q(t.attrs);
328
+ return tt(t.attrs);
274
329
  case "mj-social": {
275
- const e = t.children.filter((r) => r.tag === "mj-social-element").map((r) => ({ attrs: r.attrs, innerText: r.text }));
276
- return M(t.attrs, e);
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 K(t.text);
334
+ return it(t.text);
280
335
  case "mj-table":
281
- return Y(t.attrs, t.text);
336
+ return at(t.attrs, t.text);
282
337
  case "mj-navbar": {
283
- const e = t.children.filter((r) => r.tag === "mj-navbar-link").map((r) => ({ attrs: r.attrs, innerText: r.text }));
284
- return Z(t.attrs, e);
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 A(t, n) {
294
- const e = t.attrs, r = [];
295
- for (const s of t.children)
296
- if (s.tag === "mj-column")
297
- r.push(T(s, n));
298
- else if (s.tag === "mj-group")
299
- for (const c of s.children)
300
- c.tag === "mj-column" && r.push(T(c, n));
301
- else
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: ${s.tag}`,
304
- tag: s.tag
360
+ message: `Unexpected section child: ${f.tag}`,
361
+ tag: f.tag
305
362
  });
306
- r.length === 0 && r.push({
307
- id: m(),
363
+ i.length === 0 && i.push({
364
+ id: b(),
308
365
  type: "column",
309
366
  attributes: {
310
- padding: f(void 0, 0),
367
+ padding: m(void 0, 0),
311
368
  verticalAlign: "top"
312
369
  },
313
370
  blocks: []
314
371
  });
315
- const o = Q(r), l = i(e, "full-width") === "full-width";
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: m(),
379
+ id: b(),
318
380
  type: "row",
319
381
  attributes: {
320
- backgroundColor: i(e, "background-color") || void 0,
321
- backgroundImage: i(e, "background-url") || void 0,
322
- padding: f(i(e, "padding"), 0),
323
- fullWidth: l,
324
- cssClass: i(e, "css-class") || void 0
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: r,
327
- columnRatios: o,
390
+ columns: i,
391
+ columnRatios: d,
328
392
  locked: !1
329
393
  };
330
394
  }
331
- function Q(t, n) {
332
- const e = t.length, r = Math.floor(12 / e);
333
- return t.map(() => r);
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 tt(t, n, e) {
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": "&#9776;",
534
+ "ico-close": "&#8855;",
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: m(),
570
+ id: b(),
338
571
  type: "hero",
339
572
  values: {
340
- backgroundUrl: i(t, "background-url"),
341
- backgroundPosition: i(t, "background-position", "center center"),
342
- mode: i(t, "mode", "fluid-height"),
343
- width: b(t, "width", 600),
344
- height: b(t, "height", 400),
345
- verticalAlign: i(t, "vertical-align", "middle"),
346
- padding: f(i(t, "padding"), 0),
347
- innerPadding: f(e, 20),
348
- backgroundColor: i(t, "background-color", "#ffffff"),
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 et = [
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
- ], nt = "1.5";
363
- function E(t, n, e) {
364
- const r = et.filter(([o, a]) => t[a] && !(o === "line-height" && t[a] === nt)).concat(!e && t.padding ? [["padding", "padding"]] : []).map(([o, a]) => `${o}:${t[a]};`).join("");
365
- return r ? `<div style="${w(r)}">${n}</div>` : e ? n : `<div>${n}</div>`;
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
- const rt = {
368
- align: "center",
369
- "background-color": "#414141",
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 w(t) {
604
+ function j(t) {
389
605
  return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
390
606
  }
391
- function it(t, n) {
392
- const e = b(t.attrs, "width", 600), r = i(t.attrs, "background-color", "#f4f4f5"), o = [];
393
- let a;
394
- const l = (s) => (a && (s.attributes.condition = a, a = void 0), s);
395
- for (const s of t.children)
396
- switch (s.tag) {
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 c = /\{\{#if\s+([^}]+?)\s*\}\}/.exec(s.text ?? "");
399
- c && (a = c[1].trim());
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
- o.push(l(A(s, n)));
627
+ i.push(c(_(d, n, e)));
404
628
  break;
405
629
  case "mj-hero": {
406
- const c = at(s, n), g = tt(s.attrs, c.content, c.innerPadding), p = {
407
- id: m(),
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: f(void 0, 0),
636
+ padding: m(void 0, 0),
411
637
  verticalAlign: "top"
412
638
  },
413
- blocks: [g]
414
- }, d = {
415
- id: m(),
639
+ blocks: [u]
640
+ }, f = {
641
+ id: b(),
416
642
  type: "row",
417
643
  attributes: {
418
- padding: f(void 0, 0),
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
- o.push(l(d));
651
+ i.push(c(f));
426
652
  break;
427
653
  }
428
- case "mj-wrapper":
429
- n.push({
430
- message: "mj-wrapper styling (padding, background-color) was dropped: the document model has no wrapper; its sections were imported unwrapped",
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: ${s.tag}`,
439
- tag: s.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: r, rows: o };
689
+ return { width: e, backgroundColor: o, rows: i };
444
690
  }
445
- function at(t, n) {
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: E(e.attrs, e.text, !0), innerPadding: e.attrs.padding };
449
- const r = [];
450
- for (const o of t.children)
451
- o.tag === "mj-text" ? r.push(E(o.attrs, o.text, !1)) : o.tag === "mj-button" ? r.push(ot(o.attrs, o.text)) : n.push({ message: `Unsupported mj-hero child element: ${o.tag}`, tag: o.tag });
452
- return { content: r.join("") || "<p>Hero Content</p>" };
453
- }
454
- const st = /* @__PURE__ */ new Set(["mj-section", "mj-column", "mj-text", "mj-button", "mj-image"]);
455
- function R(t, n, e) {
456
- const { "mj-class": r = "", ...o } = t.attrs, a = r.split(/\s+/).filter(Boolean).reduce((s, c) => {
457
- const g = n.classes[c] ?? {}, p = s["css-class"] && g["css-class"] ? { "css-class": `${s["css-class"]} ${g["css-class"]}` } : {};
458
- return { ...s, ...g, ...p };
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], ...a, ...o };
461
- const l = t.attrs["css-class"];
462
- l && !st.has(t.tag) && e.push({ message: `css-class "${l}" on <${t.tag}> was dropped`, tag: t.tag });
463
- for (const s of t.children)
464
- R(s, n, e);
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 D = /* @__PURE__ */ new Set([
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
- ]), lt = "14px", ct = "#000000";
518
- function z(t, n) {
763
+ ]), vt = "14px", jt = "#000000";
764
+ function M(t, n) {
519
765
  if (t.tag === "mj-text") {
520
- const { color: e, "font-size": r, "font-family": o } = t.attrs, a = [];
521
- e && e.toLowerCase() !== ct && a.push(`color: ${e}`), r && r !== lt && a.push(`font-size: ${r}`), o && o !== n && a.push(`font-family: ${o}`), a.length > 0 && (t.text = dt(t.text, `<span style="${ut(a.join("; "))}">`));
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
- z(e, n);
771
+ M(e, n);
526
772
  }
527
- function dt(t, n) {
773
+ function yt(t, n) {
528
774
  const e = [];
529
- let r = -1, o = -1, a = !1, l = 0;
530
- const s = () => {
531
- r >= 0 && a && e.push([r, n], [o, "</span>"]), r = -1, a = !1;
532
- }, c = (d, h) => {
533
- r < 0 && (r = d), o = h;
534
- }, g = new _({
535
- onopentag(d) {
536
- if (l === 0 && D.has(d)) {
537
- s();
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
- c(g.startIndex, g.endIndex + 1), B.has(d) ? a = !0 : l++;
786
+ d(l.startIndex, l.endIndex + 1), B.has(p) ? r = !0 : s++;
541
787
  },
542
- onclosetag(d, h) {
543
- if (!B.has(d)) {
544
- if (l === 0) {
545
- D.has(d) && s();
788
+ onclosetag(p, f) {
789
+ if (!B.has(p)) {
790
+ if (s === 0) {
791
+ I.has(p) && c();
546
792
  return;
547
793
  }
548
- l--, h || (o = g.endIndex + 1);
794
+ s--, f || (i = l.endIndex + 1);
549
795
  }
550
796
  },
551
- ontext(d) {
552
- r < 0 && !d.trim() || (c(g.startIndex, g.endIndex + 1), d.trim() && (a = !0));
797
+ ontext(p) {
798
+ o < 0 && !p.trim() || (d(l.startIndex, l.endIndex + 1), p.trim() && (r = !0));
553
799
  },
554
800
  oncomment() {
555
- r >= 0 && (o = g.endIndex + 1);
801
+ o >= 0 && (i = l.endIndex + 1);
556
802
  }
557
803
  }, { recognizeSelfClosing: !0, lowerCaseTags: !0 });
558
- g.write(t), g.end(), s();
559
- let p = t;
560
- for (const [d, h] of e.reverse())
561
- p = p.slice(0, d) + h + p.slice(d);
562
- return p;
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 ut(t) {
810
+ function $t(t) {
565
811
  return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
566
812
  }
567
- function gt(t) {
568
- const n = { tag: "root", attrs: {}, children: [], text: "" }, e = [n], r = /* @__PURE__ */ new Set([
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
- ]), o = /* @__PURE__ */ new Set([
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
- ]), a = /* @__PURE__ */ new Set([
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
- ]), l = /* @__PURE__ */ new Set(["mj-text", "mj-button", "mj-raw"]), s = /* @__PURE__ */ new Set(["style", "script"]), c = (u) => u.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), g = (u) => u.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
599
- let p = null, d = "", h = 0, x = !1;
600
- const y = new _({
601
- onopentag(u, $) {
602
- if (p) {
603
- const N = l.has(p.node.tag), S = Object.entries($).map(([F, C]) => `${F}="${N ? g(C) : C}"`).join(" ");
604
- d += S ? `<${u} ${S}>` : `<${u}>`, a.has(u) || h++, s.has(u) && (x = !0);
845
+ ]), s = /* @__PURE__ */ new Set(["mj-text", "mj-button", "mj-raw"]), c = /* @__PURE__ */ new Set(["style", "script"]), d = (g) => g.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), l = (g) => g.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
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 k = { tag: u, attrs: $, children: [], text: "" };
608
- e[e.length - 1].children.push(k), !o.has(u) && (e.push(k), r.has(u) && (p = { node: k, depth: 0 }, d = "", h = 0));
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(u) {
611
- if (p) {
612
- const k = l.has(p.node.tag) && !x;
613
- d += k ? c(u) : u;
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 $ = e[e.length - 1];
617
- $.text += u;
863
+ const k = e[e.length - 1];
864
+ k.text += g;
618
865
  },
619
- onclosetag(u) {
620
- if (p) {
621
- if (a.has(u)) return;
622
- if (h > 0) {
623
- d += `</${u}>`, h--, s.has(u) && (x = !1);
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
- p.node.text = d, p = null, d = "", h = 0, e.length > 1 && e[e.length - 1].tag === u && e.pop();
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
- o.has(u) || e.length > 1 && e[e.length - 1].tag === u && e.pop();
876
+ i.has(g) || e.length > 1 && e[e.length - 1].tag === g && e.pop();
630
877
  },
631
- oncomment(u) {
632
- p && (d += `<!--${u}-->`);
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 y.write(t), y.end(), n;
886
+ return h.write(t), h.end(), n;
640
887
  }
641
- function v(t, n) {
888
+ function C(t, n) {
642
889
  if (t.tag === n) return t;
643
890
  for (const e of t.children) {
644
- const r = v(e, n);
645
- if (r) return r;
891
+ const o = C(e, n);
892
+ if (o) return o;
646
893
  }
647
894
  }
648
- function mt(t, n) {
649
- const e = [], r = gt(t), o = v(r, "mjml");
650
- if (!o)
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: I(),
653
- warnings: e
900
+ document: L(),
901
+ warnings: e,
902
+ fonts: []
654
903
  };
655
- const a = v(o, "mj-head"), l = v(o, "mj-body");
656
- let s = { attributeDefaults: { all: {}, tags: {}, classes: {} } };
657
- if (a && (s = H(
658
- a.children.map((h) => ({
659
- tag: h.tag,
660
- attrs: h.attrs,
661
- children: h.children.map((x) => ({
662
- tag: x.tag,
663
- attrs: x.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: x.text
914
+ text: S.text
666
915
  })),
667
- text: h.text
916
+ text: v.text
668
917
  }))
669
- )), !l)
918
+ )), !s)
670
919
  return e.push({ message: "No <mj-body> element found" }), {
671
- document: I(),
672
- warnings: e
920
+ document: L(),
921
+ warnings: e,
922
+ fonts: c.fonts
673
923
  };
674
- const c = s.fontFamily ?? "Arial, Helvetica, sans-serif";
675
- R(l, s.attributeDefaults, e), z(l, c);
676
- const g = it(l, e), p = (/* @__PURE__ */ new Date()).toISOString();
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: s.previewText,
682
- createdAt: p,
683
- updatedAt: p
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: g.width,
688
- backgroundColor: g.backgroundColor,
689
- fontFamily: c,
937
+ width: l.width,
938
+ backgroundColor: l.backgroundColor,
939
+ fontFamily: d,
690
940
  contentAlignment: "center",
691
- css: s.css
941
+ ...c.linkStyle ? { linkStyle: c.linkStyle } : {},
942
+ ...p ? { language: p } : {},
943
+ ...x ? { direction: x } : {},
944
+ css: c.css
692
945
  },
693
- rows: g.rows
946
+ rows: l.rows
694
947
  }
695
- }, warnings: e };
948
+ }, warnings: e, fonts: c.fonts };
696
949
  }
697
- function I() {
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
- mt as mjmlToDocument
971
+ At as mjmlToDocument
719
972
  };