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