@maily-to/render 2.0.0-beta.7 → 2.0.0-beta.9

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.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
@@ -26,126 +26,27 @@ let react = require("react");
26
26
  let react_jsx_runtime = require("react/jsx-runtime");
27
27
  let _react_email_components = require("@react-email/components");
28
28
  let juice = require("juice");
29
- juice = __toESM(juice);
29
+ juice = __toESM(juice, 1);
30
30
  let node_html_parser = require("node-html-parser");
31
- let _maily_to_migration = require("@maily-to/migration");
32
31
  let _react_email_render = require("@react-email/render");
33
- //#region src/lib/font-face.ts
34
- /**
35
- * Registers a font face in the context's shared font collector.
36
- * Deduplicates by family+style+weight+fallback so each variant
37
- * only appears once in the final `<style>` block.
38
- */
39
- function registerFontFace(ctx, font) {
40
- const { fontFamily, fontWeight = 400, fallbackFontFamily, fontStyle = "normal" } = font;
41
- if (!fontFamily) return;
42
- const key = `${fontFamily}:${fontStyle}:${fontWeight}:${fallbackFontFamily}`;
43
- if (ctx.fonts.has(key)) return;
44
- ctx.font(key, font);
45
- }
46
- /**
47
- * Resolves a complete FontProps from a node's font style attributes
48
- * (falling back to the theme font and CDN entries) and registers it.
49
- * Called by node renderers that support per-node font overrides.
50
- */
51
- function prepareAndRegisterFontFaceFromAttrs(ctx, attrs, defaults) {
52
- const primaryFont = ctx.config.theme.font ?? _maily_to_shared.DEFAULT_FONT;
53
- if (!primaryFont) return;
54
- const { fontFamily, fontWeight, fontFallback, fontStyle } = attrs;
55
- const family = fontFamily ?? primaryFont.fontFamily;
56
- if (!family) return;
57
- const weight = fontWeight ?? defaults?.fontWeight ?? 400;
58
- const style = fontStyle ?? defaults?.fontStyle ?? "normal";
59
- const fallback = fontFallback ?? primaryFont.fallbackFontFamily;
60
- const webFont = fontFamily ? ctx.config.fontFamilies.find((f) => f.fontFamily === fontFamily)?.webFont : primaryFont.webFont;
61
- registerFontFace(ctx, {
62
- fontFamily: family,
63
- fontWeight: weight,
64
- fallbackFontFamily: fallback,
65
- fontStyle: style,
66
- ...webFont && { webFont }
67
- });
68
- }
69
- //#endregion
70
- //#region src/lib/spacing.ts
71
- const BLOCK_CONTAINERS = new Set([
72
- _maily_to_shared.MAILY_NODE_TYPES.DOCUMENT,
73
- _maily_to_shared.MAILY_NODE_TYPES.SECTION,
74
- _maily_to_shared.MAILY_NODE_TYPES.COLUMN,
75
- _maily_to_shared.MAILY_NODE_TYPES.REPEAT
76
- ]);
77
- /**
78
- * Returns true if this node's top margin should be collapsed — i.e. it's
79
- * the first child of a block container or follows a spacer node.
80
- */
81
- function shouldSuppressMarginTop(ctx) {
82
- const { parent, siblingIndex } = ctx;
83
- if (!parent || !_maily_to_shared.is.node(parent) || !_maily_to_shared.is.parent(parent)) return true;
84
- if (!BLOCK_CONTAINERS.has(parent.type)) return true;
85
- const prev = parent.content[siblingIndex - 1];
86
- const isFirst = siblingIndex === 0;
87
- const isPrevSpacer = prev?.type === _maily_to_shared.MAILY_NODE_TYPES.SPACER;
88
- return isFirst || isPrevSpacer;
89
- }
90
- /**
91
- * Returns true if this node's bottom margin should be collapsed — i.e. it's
92
- * the last child of a block container, or is followed by a spacer or hr.
93
- */
94
- function shouldSuppressMarginBottom(ctx) {
95
- const { parent, siblingIndex } = ctx;
96
- if (!parent || !_maily_to_shared.is.node(parent) || !_maily_to_shared.is.parent(parent)) return true;
97
- if (parent.type === _maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM) return true;
98
- if (!BLOCK_CONTAINERS.has(parent.type)) return true;
99
- const content = parent.content;
100
- const next = content[siblingIndex + 1];
101
- const isLast = siblingIndex === content.length - 1;
102
- const isNextSpacer = next?.type === _maily_to_shared.MAILY_NODE_TYPES.SPACER;
103
- const isNextHr = next?.type === _maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE;
104
- return isLast || isNextSpacer || isNextHr;
105
- }
106
- //#endregion
107
- //#region src/nodes/blockquote.tsx
108
- const blockquote = (node, ctx) => {
109
- if (!_maily_to_shared.is.blockquote(node)) return null;
110
- const { dir } = node.attrs;
111
- const theme = ctx.config.theme;
112
- const fontStyle = (0, _maily_to_shared.getFontStyle)(node.attrs, theme.blockquote);
113
- prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.blockquote);
114
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("blockquote", {
115
- style: {
116
- borderLeftWidth: "4px",
117
- borderLeftStyle: "solid",
118
- borderLeftColor: theme.blockquote?.borderColor,
119
- paddingLeft: "16px",
120
- marginLeft: "0px",
121
- marginRight: "0px",
122
- marginTop: shouldSuppressMarginTop(ctx) ? 0 : 20,
123
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
124
- color: theme.blockquote?.color,
125
- ...(0, _maily_to_shared.getCssDirection)(dir),
126
- ...fontStyle
127
- },
128
- children: ctx.children(node)
129
- });
130
- };
131
- //#endregion
132
- //#region src/nodes/bullet-list.tsx
133
- const bulletList = (node, ctx) => {
134
- if (!_maily_to_shared.is.bulletList(node)) return null;
135
- const { dir } = node.attrs;
136
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
137
- style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20 },
138
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
139
- style: {
140
- paddingLeft: 26,
141
- listStyleType: "disc",
142
- margin: 0,
143
- ...(0, _maily_to_shared.getCssDirection)(dir)
144
- },
145
- children: ctx.children(node)
146
- })
32
+ //#region src/config.ts
33
+ const DEFAULT_VARIABLE_FORMATTER = ({ fallback, variable }) => {
34
+ return (0, _maily_to_shared.serializeVariableToText)({
35
+ fallback,
36
+ id: variable
147
37
  });
148
38
  };
39
+ function buildConfig(config = {}) {
40
+ return {
41
+ fontFamilies: config.fontFamilies ?? _maily_to_shared.DEFAULT_FONT_FAMILIES,
42
+ htmlProps: config.htmlProps ?? {},
43
+ meta: config.meta ?? [],
44
+ openTrackingPixel: config.openTrackingPixel,
45
+ preview: config.preview,
46
+ variableFormatter: config.variableFormatter ?? DEFAULT_VARIABLE_FORMATTER,
47
+ variableValues: new Map(Object.entries(config.variables ?? {}))
48
+ };
49
+ }
149
50
  //#endregion
150
51
  //#region src/lib/resolve-variable.ts
151
52
  /**
@@ -158,16 +59,33 @@ function resolveVariableId(id, fallback, ctx) {
158
59
  const { config } = ctx;
159
60
  const item = ctx.get("item");
160
61
  if (item && id in item) return String(item[id]);
161
- const varValue = config.variableValues.get(id);
162
- if (varValue !== void 0) {
163
- if (typeof varValue === "object") return JSON.stringify(varValue);
164
- return String(varValue);
165
- }
62
+ const value = config.variableValues.get(id);
63
+ if (value !== void 0) return typeof value === "object" ? JSON.stringify(value) : String(value);
166
64
  return config.variableFormatter({
167
- variable: id,
168
- fallback: fallback ?? void 0
65
+ fallback: fallback ?? void 0,
66
+ variable: id
169
67
  });
170
68
  }
69
+ function getVariableId(text) {
70
+ if (!(0, _maily_to_shared.hasVariableInText)(text)) return text.trim() || null;
71
+ const paragraph = (0, _maily_to_shared.buildDocFromVariableText)(text).content.find((node) => node.type === _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH);
72
+ for (const node of paragraph?.content ?? []) if (node.type === _maily_to_shared.MAILY_NODE_TYPES.VARIABLE) return node.attrs.id || null;
73
+ return null;
74
+ }
75
+ function getVariableValue(options) {
76
+ const { ctx, id } = options;
77
+ const item = ctx.get("item");
78
+ return item && id in item ? item[id] : ctx.config.variableValues.get(id);
79
+ }
80
+ function getVariableList(each, ctx) {
81
+ const id = getVariableId(each);
82
+ if (!id) return [];
83
+ const value = getVariableValue({
84
+ ctx,
85
+ id
86
+ });
87
+ return Array.isArray(value) ? value : [];
88
+ }
171
89
  /**
172
90
  * Resolves a text string that may contain `{{variable}}` placeholders.
173
91
  * Returns the original string unchanged if no placeholders are present.
@@ -179,141 +97,250 @@ function resolveVariableText(text, ctx) {
179
97
  return paragraph.content.map((node) => {
180
98
  if (node.type === _maily_to_shared.MAILY_NODE_TYPES.TEXT) return node.text;
181
99
  if (node.type === _maily_to_shared.MAILY_NODE_TYPES.VARIABLE) {
182
- const { id, fallback } = node.attrs;
183
- if (!id) return "";
184
- return resolveVariableId(id, fallback, ctx);
100
+ const { fallback, id } = node.attrs ?? {};
101
+ return id ? resolveVariableId(id, fallback, ctx) : "";
185
102
  }
186
103
  return "";
187
104
  }).join("");
188
105
  }
189
106
  //#endregion
190
107
  //#region src/lib/visibility.ts
108
+ function getOperatorMatch(options) {
109
+ const { operator, resolved, value } = options;
110
+ switch (operator) {
111
+ case _maily_to_shared.VISIBILITY_OPERATORS.IS_TRUE: return Boolean(resolved);
112
+ case _maily_to_shared.VISIBILITY_OPERATORS.IS_FALSE: return !resolved;
113
+ case _maily_to_shared.VISIBILITY_OPERATORS.EQUALS: return String(resolved) === value;
114
+ case _maily_to_shared.VISIBILITY_OPERATORS.NOT_EQUALS: return String(resolved) !== value;
115
+ case _maily_to_shared.VISIBILITY_OPERATORS.CONTAINS: return String(resolved).includes(value);
116
+ case _maily_to_shared.VISIBILITY_OPERATORS.NOT_CONTAINS: return !String(resolved).includes(value);
117
+ case _maily_to_shared.VISIBILITY_OPERATORS.STARTS_WITH: return String(resolved).startsWith(value);
118
+ case _maily_to_shared.VISIBILITY_OPERATORS.ENDS_WITH: return String(resolved).endsWith(value);
119
+ case _maily_to_shared.VISIBILITY_OPERATORS.GREATER_THAN: return Number(resolved) > Number(value);
120
+ case _maily_to_shared.VISIBILITY_OPERATORS.LESS_THAN: return Number(resolved) < Number(value);
121
+ default: return false;
122
+ }
123
+ }
124
+ function getVisibilityMatch(options) {
125
+ const { ctx, rule } = options;
126
+ const id = getVariableId(rule.variable);
127
+ return getOperatorMatch({
128
+ operator: rule.operator,
129
+ resolved: id ? getVariableValue({
130
+ ctx,
131
+ id
132
+ }) : void 0,
133
+ value: rule.value
134
+ });
135
+ }
136
+ function shouldShowNode(options) {
137
+ const { ctx, node } = options;
138
+ const rule = node.attrs?.visibilityRule;
139
+ if (!rule) return true;
140
+ const matched = getVisibilityMatch({
141
+ ctx,
142
+ rule
143
+ });
144
+ return rule.action === _maily_to_shared.VISIBILITY_ACTIONS.SHOW ? matched : !matched;
145
+ }
146
+ //#endregion
147
+ //#region src/lib/styles.ts
148
+ function getNodeStyle(style) {
149
+ return style ? (0, _maily_to_shared.parseInlineStyles)(style) : void 0;
150
+ }
151
+ const ANTIALIASED = {
152
+ WebkitFontSmoothing: "antialiased",
153
+ MozOsxFontSmoothing: "grayscale"
154
+ };
155
+ function getStyleAlignment(style) {
156
+ const start = style?.marginLeft === "auto";
157
+ const end = style?.marginRight === "auto";
158
+ if (start && end) return "center";
159
+ if (end) return "left";
160
+ if (start) return "right";
161
+ }
162
+ //#endregion
163
+ //#region src/nodes/blockquote.tsx
164
+ const blockquote = (node, ctx) => {
165
+ if (!_maily_to_shared.is.blockquote(node)) return null;
166
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("blockquote", {
167
+ dir: node.attrs?.dir ?? void 0,
168
+ style: {
169
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
170
+ ...getNodeStyle(node.attrs?.style)
171
+ },
172
+ children: ctx.children(node)
173
+ });
174
+ };
175
+ //#endregion
176
+ //#region src/lib/preview.ts
191
177
  /**
192
- * Evaluates a node's visibility rule against the current variables.
193
- * Returns true (visible) when there's no rule, or when the rule
194
- * matches for "show" / doesn't match for "hide".
178
+ * Resolves a preview value to a plain string.
179
+ *
180
+ * - `string` → resolves `{{variable}}` placeholders
181
+ * - `JSONContent` → walks the tree and resolves variable nodes
195
182
  */
196
- function shouldShow(node, ctx) {
197
- const rule = node.attrs?.visibilityRule;
198
- if (!rule || rule.action === _maily_to_shared.VISIBILITY_ACTIONS.NONE) return true;
199
- const { action, variable, operator, value } = rule;
200
- const item = ctx.get("item");
201
- let resolvedValue;
202
- if (item && variable in item) resolvedValue = item[variable];
203
- else resolvedValue = ctx.config.variableValues.get(variable);
204
- const matched = evaluate(operator, resolvedValue, value);
205
- if (action === _maily_to_shared.VISIBILITY_ACTIONS.SHOW) return matched;
206
- if (action === _maily_to_shared.VISIBILITY_ACTIONS.HIDE) return !matched;
207
- return true;
183
+ function preview(options) {
184
+ const { ctx, preview } = options;
185
+ if (typeof preview === "string") return resolveVariableText(preview, ctx);
186
+ return getWalkedText({
187
+ ctx,
188
+ doc: preview
189
+ });
208
190
  }
209
- function evaluate(operator, resolvedValue, compareValue) {
210
- switch (operator) {
211
- case _maily_to_shared.VISIBILITY_OPERATORS.IS_TRUE: return Boolean(resolvedValue);
212
- case _maily_to_shared.VISIBILITY_OPERATORS.IS_FALSE: return !resolvedValue;
213
- case _maily_to_shared.VISIBILITY_OPERATORS.EQUALS: return String(resolvedValue) === compareValue;
214
- case _maily_to_shared.VISIBILITY_OPERATORS.NOT_EQUALS: return String(resolvedValue) !== compareValue;
215
- case _maily_to_shared.VISIBILITY_OPERATORS.CONTAINS: return String(resolvedValue).includes(compareValue);
216
- case _maily_to_shared.VISIBILITY_OPERATORS.NOT_CONTAINS: return !String(resolvedValue).includes(compareValue);
217
- case _maily_to_shared.VISIBILITY_OPERATORS.STARTS_WITH: return String(resolvedValue).startsWith(compareValue);
218
- case _maily_to_shared.VISIBILITY_OPERATORS.ENDS_WITH: return String(resolvedValue).endsWith(compareValue);
219
- case _maily_to_shared.VISIBILITY_OPERATORS.GREATER_THAN: return Number(resolvedValue) > Number(compareValue);
220
- case _maily_to_shared.VISIBILITY_OPERATORS.LESS_THAN: return Number(resolvedValue) < Number(compareValue);
221
- default: return false;
191
+ function getWalkedText(options) {
192
+ const { ctx, doc } = options;
193
+ const parts = [];
194
+ if (!_maily_to_shared.is.node(doc)) return parts.join("");
195
+ function visitor(node) {
196
+ if (_maily_to_shared.is.text(node)) parts.push(node.text);
197
+ if (_maily_to_shared.is.variable(node)) {
198
+ const { fallback, id } = node.attrs;
199
+ if (!id) return;
200
+ parts.push(resolveVariableId(id, fallback ?? void 0, ctx));
201
+ }
202
+ if (_maily_to_shared.is.parent(node)) node.content.forEach(visitor);
203
+ }
204
+ visitor(doc);
205
+ return parts.join("");
206
+ }
207
+ //#endregion
208
+ //#region src/lib/slots.tsx
209
+ function getPreviewSlot(ctx) {
210
+ const { preview: preview$1 } = ctx.config;
211
+ if (!preview$1) return null;
212
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Preview, { children: preview({
213
+ ctx,
214
+ preview: preview$1
215
+ }) });
216
+ }
217
+ function getTrackingPixelSlot(ctx) {
218
+ const { openTrackingPixel } = ctx.config;
219
+ if (!openTrackingPixel) return null;
220
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
221
+ alt: "",
222
+ height: "1",
223
+ src: openTrackingPixel,
224
+ style: { display: "none" },
225
+ width: "1"
226
+ });
227
+ }
228
+ //#endregion
229
+ //#region src/nodes/body.tsx
230
+ const body = (node, ctx) => {
231
+ if (!_maily_to_shared.is.body(node)) return null;
232
+ const { parent } = ctx;
233
+ const isShell = _maily_to_shared.is.node(parent) && _maily_to_shared.is.doc(parent);
234
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Body, {
235
+ style: getNodeStyle(node.attrs?.style),
236
+ children: [
237
+ isShell ? getPreviewSlot(ctx) : null,
238
+ ctx.children(node),
239
+ isShell ? getTrackingPixelSlot(ctx) : null
240
+ ]
241
+ });
242
+ };
243
+ //#endregion
244
+ //#region src/nodes/bullet-list.tsx
245
+ const bulletList = (node, ctx) => {
246
+ if (!_maily_to_shared.is.bulletList(node)) return null;
247
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
248
+ dir: node.attrs?.dir ?? void 0,
249
+ style: {
250
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
251
+ ...getNodeStyle(node.attrs?.style)
252
+ },
253
+ children: ctx.children(node)
254
+ });
255
+ };
256
+ //#endregion
257
+ //#region src/lib/link.ts
258
+ /**
259
+ * Extracts all valid URLs from link marks in a Maily document.
260
+ * Returns a deduplicated Set of href strings.
261
+ */
262
+ function links(json) {
263
+ const links = /* @__PURE__ */ new Set();
264
+ if (!_maily_to_shared.is.node(json)) return links;
265
+ function visitor(node) {
266
+ if (_maily_to_shared.is.marked(node)) for (const mark of node.marks) {
267
+ if (!_maily_to_shared.is.link(mark)) continue;
268
+ const href = mark.attrs.href;
269
+ if (!isValidUrl(href)) continue;
270
+ links.add(href);
271
+ }
272
+ if (_maily_to_shared.is.parent(node)) node.content.forEach(visitor);
273
+ }
274
+ visitor(json);
275
+ return links;
276
+ }
277
+ function isValidUrl(value) {
278
+ try {
279
+ new URL(value);
280
+ return true;
281
+ } catch {
282
+ return false;
222
283
  }
223
284
  }
285
+ const UNSAFE_SCHEME = /^(?:data|javascript|vbscript):/i;
286
+ function getSafeHref(url) {
287
+ if (!url) return url ?? void 0;
288
+ return UNSAFE_SCHEME.test(url.replace(/\s/g, "")) ? void 0 : url;
289
+ }
224
290
  //#endregion
225
291
  //#region src/nodes/button.tsx
226
292
  const button = (node, ctx) => {
227
293
  if (!_maily_to_shared.is.button(node)) return null;
228
- if (!shouldShow(node, ctx)) return null;
229
- const attrs = node.attrs;
230
- const { dir } = attrs;
231
- const theme = ctx.config.theme;
232
- const backgroundColor = attrs.backgroundColor ?? theme.button?.backgroundColor;
233
- const color = attrs.color ?? theme.button?.color;
234
- const url = resolveVariableText(attrs.url ?? "", ctx);
235
- const kind = attrs.kind ?? _maily_to_shared.BUTTON_KINDS.TIGHT;
236
- const alignment = attrs.alignment ?? _maily_to_shared.TEXT_ALIGNMENTS.CENTER;
237
- const isFullWidth = kind === _maily_to_shared.BUTTON_KINDS.FULL_WIDTH;
238
- const paddingTop = attrs.paddingTop ?? theme.button?.paddingTop ?? 10;
239
- const paddingRight = attrs.paddingRight ?? theme.button?.paddingRight ?? 32;
240
- const paddingBottom = attrs.paddingBottom ?? theme.button?.paddingBottom ?? 10;
241
- const paddingLeft = attrs.paddingLeft ?? theme.button?.paddingLeft ?? 32;
242
- const borderStyle = (0, _maily_to_shared.getBorderStyle)(attrs);
243
- const fontStyle = (0, _maily_to_shared.getFontStyle)(attrs, theme.button);
244
- prepareAndRegisterFontFaceFromAttrs(ctx, attrs, theme.button);
245
- const containerStyle = {
246
- textAlign: alignment,
247
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20
248
- };
249
- if (isFullWidth) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
250
- style: containerStyle,
251
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
252
- width: "100%",
253
- cellPadding: "0",
254
- cellSpacing: "0",
255
- border: 0,
256
- role: "presentation",
257
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
258
- align: alignment,
294
+ const { align, kind, url } = node.attrs;
295
+ const style = getNodeStyle(node.attrs.style);
296
+ const href = getSafeHref(resolveVariableText(url, ctx));
297
+ if (kind === _maily_to_shared.BUTTON_KINDS.FULL_WIDTH) {
298
+ const { backgroundColor, color, ...cellStyle } = style ?? {};
299
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
300
+ align,
301
+ style: {
302
+ backgroundColor,
303
+ ...cellStyle
304
+ },
305
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
306
+ href,
259
307
  style: {
260
- backgroundColor,
261
- paddingTop,
262
- paddingRight,
263
- paddingBottom,
264
- paddingLeft,
265
- ...borderStyle,
266
- ...(0, _maily_to_shared.getCssDirection)(dir)
308
+ color,
309
+ display: "block",
310
+ textAlign: align,
311
+ textDecoration: "none"
267
312
  },
268
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
269
- href: url,
270
- target: "_blank",
271
- style: {
272
- color,
273
- textDecoration: "none",
274
- display: "block",
275
- textAlign: alignment,
276
- ...fontStyle
277
- },
278
- children: ctx.children(node)
279
- })
280
- }) }) })
281
- })
282
- });
283
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
284
- style: containerStyle,
313
+ target: "_blank",
314
+ children: ctx.children(node)
315
+ })
316
+ }) });
317
+ }
318
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
319
+ align,
285
320
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Button, {
286
- href: url,
321
+ href,
287
322
  style: {
288
- backgroundColor,
289
- color,
290
- paddingTop,
291
- paddingRight,
292
- paddingBottom,
293
- paddingLeft,
294
323
  display: "inline-block",
295
- ...borderStyle,
296
- ...(0, _maily_to_shared.getCssDirection)(dir),
297
- ...fontStyle
324
+ ...style
298
325
  },
299
326
  children: ctx.children(node)
300
327
  })
301
- });
328
+ }) });
302
329
  };
303
330
  //#endregion
304
331
  //#region src/nodes/column.tsx
305
332
  const column = (node, ctx) => {
306
333
  if (!_maily_to_shared.is.column(node)) return null;
307
- const attrs = node.attrs;
308
- const width = ctx.get("columnTdWidth") ?? (attrs.width === null ? void 0 : `${attrs.width}%`);
334
+ const width = ctx.get("columnWidth") ?? (node.attrs.width === null ? void 0 : `${node.attrs.width}%`);
309
335
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
310
- width,
311
336
  className: "tab-col-full",
312
337
  style: {
313
338
  margin: 0,
339
+ verticalAlign: node.attrs.verticalAlign,
314
340
  width,
315
- verticalAlign: attrs.verticalAlign
341
+ ...getNodeStyle(node.attrs.style)
316
342
  },
343
+ width,
317
344
  children: ctx.children(node)
318
345
  });
319
346
  };
@@ -357,43 +384,43 @@ function calculateColumnLayout(columnNodes, gap, containerBox) {
357
384
  const count = columnNodes.length;
358
385
  if (count === 0) return {
359
386
  columns: [],
360
- rowWidthPercent: 0,
361
- gapTdWidthPercent: 0
387
+ gapTdWidthPercent: 0,
388
+ rowWidthPercent: 0
362
389
  };
363
390
  const gapCount = count - 1;
364
391
  const gapPercent = gapCount > 0 && containerBox > 0 ? (0, _maily_to_shared.roundTo)(gap / containerBox * 100, 3) : 0;
365
392
  const totalGapPercent = (0, _maily_to_shared.roundTo)(gapCount * gapPercent, 3);
366
- const fixedSum = columnNodes.reduce((sum, col) => sum + (col.attrs.width ?? 0), 0);
367
- const autoCount = columnNodes.filter((col) => col.attrs.width === null).length;
393
+ const percents = columnNodes.map((node) => (0, _maily_to_shared.getColumnWidthPercent)({
394
+ containerWidth: containerBox,
395
+ width: node.attrs.width
396
+ }));
397
+ const fixedSum = percents.reduce((sum, percent) => sum + (percent ?? 0), 0);
398
+ const autoCount = percents.filter((percent) => percent === null).length;
368
399
  const autoEach = autoCount > 0 ? (0, _maily_to_shared.roundTo)(Math.max(0, 100 - fixedSum - totalGapPercent) / autoCount, 3) : 0;
369
- let containerPercents = columnNodes.map((col) => col.attrs.width ?? autoEach);
400
+ let containerPercents = percents.map((percent) => percent ?? autoEach);
370
401
  let rowWidthPercent = autoCount > 0 ? 100 : (0, _maily_to_shared.roundTo)(fixedSum + totalGapPercent, 3);
371
402
  let effectiveGapPercent = gapPercent;
372
403
  if (autoCount === 0 && rowWidthPercent > 100) {
373
404
  const scale = 100 / rowWidthPercent;
374
- containerPercents = containerPercents.map((p) => (0, _maily_to_shared.roundTo)(p * scale, 3));
405
+ containerPercents = containerPercents.map((percent) => (0, _maily_to_shared.roundTo)(percent * scale, 3));
375
406
  effectiveGapPercent = (0, _maily_to_shared.roundTo)(gapPercent * scale, 3);
376
407
  rowWidthPercent = 100;
377
408
  }
378
- const gapTdWidthPercent = rowWidthPercent > 0 ? (0, _maily_to_shared.roundTo)(effectiveGapPercent / rowWidthPercent * 100, 3) : 0;
409
+ const toRowRelative = (percent) => rowWidthPercent > 0 ? (0, _maily_to_shared.roundTo)(percent / rowWidthPercent * 100, 3) : 0;
379
410
  return {
380
- columns: columnNodes.map((col, i) => {
381
- const containerPercent = containerPercents[i];
382
- const tdWidthPercent = rowWidthPercent > 0 ? (0, _maily_to_shared.roundTo)(containerPercent / rowWidthPercent * 100, 3) : 0;
383
- return {
384
- node: {
385
- ...col,
386
- attrs: {
387
- ...col.attrs,
388
- width: col.attrs.width ?? containerPercent
389
- }
390
- },
391
- containerPercent,
392
- tdWidthPercent
393
- };
394
- }),
395
- rowWidthPercent,
396
- gapTdWidthPercent
411
+ columns: columnNodes.map((node, index) => ({
412
+ containerPercent: containerPercents[index],
413
+ node: {
414
+ ...node,
415
+ attrs: {
416
+ ...node.attrs,
417
+ width: percents[index] ?? containerPercents[index]
418
+ }
419
+ },
420
+ tdWidthPercent: toRowRelative(containerPercents[index])
421
+ })),
422
+ gapTdWidthPercent: toRowRelative(effectiveGapPercent),
423
+ rowWidthPercent
397
424
  };
398
425
  }
399
426
  //#endregion
@@ -402,51 +429,161 @@ const COLUMNS_RESPONSIVE_CSS = `@media only screen and (max-width:425px){.tab-ro
402
429
  const columns = (node, ctx) => {
403
430
  if (!_maily_to_shared.is.columns(node)) return null;
404
431
  ctx.style(COLUMNS_RESPONSIVE_CSS);
405
- const { gap = 0 } = node.attrs;
406
- const { columns, rowWidthPercent, gapTdWidthPercent } = calculateColumnLayout(node.content.filter(_maily_to_shared.is.column), gap, ctx.box);
432
+ const { columns, gapTdWidthPercent, rowWidthPercent } = calculateColumnLayout(node.content.filter(_maily_to_shared.is.column), node.attrs.gap, ctx.box);
407
433
  if (columns.length === 0) return null;
408
434
  const width = `${rowWidthPercent}%`;
409
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Section, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
410
- className: "tab-row-full",
411
- width,
412
- style: { width },
413
- align: _maily_to_shared.TEXT_ALIGNMENTS.LEFT,
414
- children: columns.flatMap((item, index) => {
415
- const widthInPixels = (0, _maily_to_shared.absoluteFromPercentage)(item.containerPercent, ctx.box);
416
- const childCtx = ctx.child({
417
- parent: node,
418
- siblingIndex: index,
419
- size: {
420
- totalWidth: widthInPixels,
421
- totalBorder: 0,
422
- totalPadding: 0
423
- }
424
- });
425
- const tdWidth = `${item.tdWidthPercent}%`;
426
- childCtx.set("columnTdWidth", tdWidth);
427
- const el = childCtx.render(item.node);
428
- const colEl = (0, react.isValidElement)(el) ? (0, react.cloneElement)(el, { key: item.node.attrs.id }) : null;
429
- if (index < columns.length - 1 && gap > 0) {
430
- const gapWidth = `${gapTdWidthPercent}%`;
431
- const gapKey = `gap-${item.node.attrs.id}`;
432
- return [colEl, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
435
+ const gapWidth = `${gapTdWidthPercent}%`;
436
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Section, {
437
+ style: getNodeStyle(node.attrs.style),
438
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
439
+ align: "left",
440
+ className: "tab-row-full",
441
+ style: { width },
442
+ width,
443
+ children: columns.map((item, index) => {
444
+ const childCtx = ctx.child({
445
+ parent: node,
446
+ siblingIndex: index,
447
+ size: {
448
+ totalWidth: (0, _maily_to_shared.absoluteFromPercentage)(item.containerPercent, ctx.box),
449
+ totalBorder: 0,
450
+ totalPadding: 0
451
+ }
452
+ });
453
+ childCtx.set("columnWidth", `${item.tdWidthPercent}%`);
454
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [childCtx.render(item.node), node.attrs.gap > 0 && index < columns.length - 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
433
455
  className: "tab-gap",
434
- width: gapWidth,
435
- style: { width: gapWidth }
436
- }, gapKey)];
437
- }
438
- return [colEl];
456
+ style: { width: gapWidth },
457
+ width: gapWidth
458
+ }) : null] }, index);
459
+ })
439
460
  })
440
- }) });
461
+ });
441
462
  };
442
463
  //#endregion
464
+ //#region src/lib/sizing.ts
465
+ function parsePxValue(value) {
466
+ if (value === void 0 || value === null) return 0;
467
+ if (typeof value === "number") return value;
468
+ const trimmed = value.trim();
469
+ if (trimmed.endsWith("px")) {
470
+ const parsed = Number.parseFloat(trimmed);
471
+ return Number.isNaN(parsed) ? 0 : parsed;
472
+ }
473
+ return 0;
474
+ }
475
+ function initSize(totalWidth) {
476
+ return {
477
+ totalWidth,
478
+ totalBorder: 0,
479
+ totalPadding: 0
480
+ };
481
+ }
482
+ function insetBox(size, spacing) {
483
+ return {
484
+ totalWidth: size.totalWidth,
485
+ totalBorder: size.totalBorder + parsePxValue(spacing.borderLeft) + parsePxValue(spacing.borderRight),
486
+ totalPadding: size.totalPadding + parsePxValue(spacing.paddingLeft) + parsePxValue(spacing.paddingRight)
487
+ };
488
+ }
489
+ function getShorthandSide(value, side) {
490
+ const parts = value?.trim().split(/\s+/);
491
+ if (!parts?.length) return;
492
+ return side === "right" ? parts[1] ?? parts[0] : parts[3] ?? parts[1] ?? parts[0];
493
+ }
494
+ function getBorderShorthandWidth(border) {
495
+ return border?.trim().split(/\s+/).find((token) => token.endsWith("px"));
496
+ }
497
+ function insetXFromStyle(size, style) {
498
+ const border = getBorderShorthandWidth(style?.border);
499
+ return insetBox(size, {
500
+ borderLeft: style?.borderLeftWidth ?? getShorthandSide(style?.borderWidth, "left") ?? border,
501
+ borderRight: style?.borderRightWidth ?? getShorthandSide(style?.borderWidth, "right") ?? border,
502
+ paddingLeft: style?.paddingLeft ?? getShorthandSide(style?.padding, "left"),
503
+ paddingRight: style?.paddingRight ?? getShorthandSide(style?.padding, "right")
504
+ });
505
+ }
506
+ //#endregion
507
+ //#region src/nodes/container.tsx
508
+ const container = (node, ctx) => {
509
+ if (!_maily_to_shared.is.container(node)) return null;
510
+ const style = getNodeStyle(node.attrs?.style);
511
+ const size = insetXFromStyle(initSize(parsePxValue(style?.maxWidth) || _maily_to_shared.DEFAULT_CONTAINER_MAX_WIDTH), style);
512
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
513
+ style,
514
+ children: ctx.child({ size }).children(node)
515
+ });
516
+ };
517
+ //#endregion
518
+ //#region src/lib/font-face.ts
519
+ /**
520
+ * Registers a font face in the context's shared font collector.
521
+ * Deduplicates by family+style+weight+fallback so each variant
522
+ * only appears once in the final `<style>` block.
523
+ */
524
+ function registerFontFace(options) {
525
+ const { ctx, font } = options;
526
+ const { fallbackFontFamily, fontFamily, fontStyle = "normal", fontWeight = 400 } = font;
527
+ if (!fontFamily) return;
528
+ const key = `${fontFamily}:${fontStyle}:${fontWeight}:${fallbackFontFamily}`;
529
+ if (ctx.fonts.has(key)) return;
530
+ ctx.font(key, font);
531
+ }
532
+ function getFallbackFont(names) {
533
+ return (names.length > 1 ? names.at(-1) : void 0) ?? _maily_to_shared.DEFAULT_FONT_FALLBACK;
534
+ }
535
+ function registerStyledFont(options) {
536
+ const { ctx, style } = options;
537
+ const declarations = (0, _maily_to_shared.parseInlineStyles)(style);
538
+ const value = declarations.fontFamily;
539
+ if (!value) return;
540
+ const names = (0, _maily_to_shared.getFontFamilyNames)(value);
541
+ const fontFamily = names[0];
542
+ if (!fontFamily) return;
543
+ const item = ctx.config.fontFamilies.find((entry) => {
544
+ return entry.fontFamily === fontFamily;
545
+ });
546
+ if (!item) return;
547
+ const weight = Number.parseInt(declarations.fontWeight ?? "", 10);
548
+ const { webFont } = item;
549
+ registerFontFace({
550
+ ctx,
551
+ font: {
552
+ fallbackFontFamily: getFallbackFont(names),
553
+ fontFamily,
554
+ fontStyle: declarations.fontStyle === "italic" ? "italic" : "normal",
555
+ fontWeight: Number.isNaN(weight) ? 400 : weight,
556
+ ...webFont ? { webFont } : {}
557
+ }
558
+ });
559
+ }
560
+ function registerDocumentFonts(options) {
561
+ const { ctx, node } = options;
562
+ const style = node.attrs?.style;
563
+ if (typeof style === "string" && style) registerStyledFont({
564
+ ctx,
565
+ style
566
+ });
567
+ for (const mark of node.marks ?? []) {
568
+ const markStyle = mark.attrs?.style;
569
+ if (typeof markStyle === "string" && markStyle) registerStyledFont({
570
+ ctx,
571
+ style: markStyle
572
+ });
573
+ }
574
+ for (const child of node.content ?? []) registerDocumentFonts({
575
+ ctx,
576
+ node: child
577
+ });
578
+ }
579
+ //#endregion
443
580
  //#region src/lib/meta.tsx
444
581
  /**
445
582
  * Deduplication key for a meta descriptor. Uses a sorted-key JSON hash
446
583
  * so `{ name: 'a', content: 'b' }` and `{ content: 'b', name: 'a' }`
447
584
  * produce the same key.
448
585
  */
449
- function hash(descriptor) {
586
+ function getHash(descriptor) {
450
587
  const sorted = Object.keys(descriptor).sort().reduce((acc, key) => {
451
588
  acc[key] = descriptor[key];
452
589
  return acc;
@@ -461,15 +598,19 @@ function meta(descriptors) {
461
598
  const seen = /* @__PURE__ */ new Set();
462
599
  const elements = [];
463
600
  for (const descriptor of descriptors) {
464
- const key = hash(descriptor);
601
+ const key = getHash(descriptor);
465
602
  if (seen.has(key)) continue;
466
603
  seen.add(key);
467
- const element = process(descriptor, key);
604
+ const element = getMetaElement({
605
+ descriptor,
606
+ key
607
+ });
468
608
  if (element) elements.push(element);
469
609
  }
470
610
  return elements;
471
611
  }
472
- function process(descriptor, key) {
612
+ function getMetaElement(options) {
613
+ const { descriptor, key } = options;
473
614
  if ("charSet" in descriptor) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { charSet: descriptor.charSet }, key);
474
615
  if ("title" in descriptor) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("title", { children: descriptor.title }, key);
475
616
  if ("tagName" in descriptor) {
@@ -485,167 +626,54 @@ function process(descriptor, key) {
485
626
  ...rest
486
627
  }, key);
487
628
  }
488
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { ...attrs }, key);
489
- }
490
- //#endregion
491
- //#region src/lib/preview.ts
492
- /**
493
- * Resolves a preview value to a plain string.
494
- *
495
- * - `string` → resolves `{{variable}}` placeholders
496
- * - `JSONContent` → walks the tree and resolves variable nodes
497
- */
498
- function preview(preview, ctx) {
499
- if (typeof preview === "string") return resolveVariableText(preview, ctx);
500
- return walk(preview, ctx);
501
- }
502
- function walk(doc, ctx) {
503
- const parts = [];
504
- if (!_maily_to_shared.is.node(doc)) return parts.join("");
505
- function visitor(node) {
506
- if (_maily_to_shared.is.text(node)) parts.push(node.text ?? "");
507
- if (_maily_to_shared.is.variable(node)) {
508
- const { id, fallback } = node.attrs;
509
- if (!id) return;
510
- parts.push(resolveVariableId(id, fallback ?? void 0, ctx));
511
- }
512
- if (_maily_to_shared.is.parent(node)) node.content.forEach(visitor);
513
- }
514
- visitor(doc);
515
- return parts.join("");
516
- }
517
- //#endregion
518
- //#region src/lib/sizing.ts
519
- /**
520
- * Extracts a numeric pixel value from a CSS string (e.g. "12px" → 12).
521
- * Returns 0 for undefined, non-px strings, or NaN results.
522
- */
523
- function parsePxValue(value) {
524
- if (value === void 0 || value === null) return 0;
525
- if (typeof value === "number") return value;
526
- const trimmed = value.trim();
527
- if (trimmed.endsWith("px")) {
528
- const n = parseFloat(trimmed);
529
- return isNaN(n) ? 0 : n;
530
- }
531
- return 0;
532
- }
533
- /**
534
- * Creates a fresh BoxModel with the given total width and zero
535
- * border/padding. Used as the starting point for layout calculations.
536
- */
537
- function initSize(totalWidth) {
538
- return {
539
- totalWidth,
540
- totalBorder: 0,
541
- totalPadding: 0
542
- };
543
- }
544
- /**
545
- * Accumulates horizontal border and padding into a BoxModel.
546
- * The total width stays the same — the usable content area shrinks.
547
- */
548
- function insetBox(size, spacing) {
549
- const totalBorder = size.totalBorder + parsePxValue(spacing.borderLeft) + parsePxValue(spacing.borderRight);
550
- const totalPadding = size.totalPadding + parsePxValue(spacing.paddingLeft) + parsePxValue(spacing.paddingRight);
551
- return {
552
- totalWidth: size.totalWidth,
553
- totalBorder,
554
- totalPadding
555
- };
629
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { ...attrs }, key);
556
630
  }
557
631
  //#endregion
558
632
  //#region src/nodes/document.tsx
559
- const BASE_CSS = `blockquote,h1,h2,h3,img,li,ol,p,ul{margin-top:0;margin-bottom:0}`;
560
633
  const document = (node, ctx) => {
561
634
  if (!_maily_to_shared.is.doc(node)) return null;
562
- const { dir } = node.attrs;
563
- const { theme, preview: preview$1, meta: meta$1, htmlProps, openTrackingPixel } = ctx.config;
564
- const font = theme.font;
565
- const container = theme.container ?? {};
566
- const body = theme.body ?? {};
567
- const size = insetBox(initSize(parsePxValue(container.maxWidth)), {
568
- paddingLeft: parsePxValue(container.paddingLeft) + parsePxValue(body.paddingLeft),
569
- paddingRight: parsePxValue(container.paddingRight) + parsePxValue(body.paddingRight),
570
- borderLeft: container.borderWidth,
571
- borderRight: container.borderWidth
635
+ const { dir } = node.attrs ?? {};
636
+ const { htmlProps, meta: meta$1 } = ctx.config;
637
+ registerDocumentFonts({
638
+ ctx,
639
+ node
572
640
  });
573
- const primaryFont = font === void 0 ? _maily_to_shared.DEFAULT_FONT : font;
574
- if (primaryFont) registerFontFace(ctx, primaryFont);
575
- const child = ctx.child({ size }).children(node);
576
- for (const fontEntry of ctx.fonts.values()) ctx.style((0, _maily_to_shared.getFontFaceStyle)(fontEntry));
577
- const css = BASE_CSS + Array.from(ctx.styles).join("");
578
- const bodyStyle = {
579
- ...body,
580
- ...primaryFont && primaryFont.fontFamily ? { fontFamily: `'${primaryFont.fontFamily}', ${primaryFont.fallbackFontFamily}` } : {}
581
- };
582
- const resolvedPreview = preview$1 ? preview(preview$1, ctx.child({ size })) : null;
641
+ const content = ctx.children(node);
642
+ for (const font of ctx.fonts.values()) ctx.style((0, _maily_to_shared.getFontFaceStyle)(font));
643
+ const css = Array.from(ctx.styles).join("");
583
644
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Html, {
584
645
  lang: "en",
585
646
  ...htmlProps,
586
- ...dir && dir !== _maily_to_shared.TEXT_DIRECTIONS.AUTO ? { dir } : {},
647
+ ...dir ? { dir } : {},
587
648
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Head, { children: [
588
649
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
589
- httpEquiv: "X-UA-Compatible",
590
- content: "IE=edge"
650
+ content: "IE=edge",
651
+ httpEquiv: "X-UA-Compatible"
591
652
  }),
592
653
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { name: "x-apple-disable-message-reformatting" }),
593
654
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
594
- name: "format-detection",
595
- content: "telephone=no,address=no,email=no,date=no,url=no"
596
- }),
597
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
598
- name: "color-scheme",
599
- content: "light"
655
+ content: "light",
656
+ name: "color-scheme"
600
657
  }),
601
658
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
602
- name: "supported-color-schemes",
603
- content: "light"
659
+ content: "light",
660
+ name: "supported-color-schemes"
604
661
  }),
605
662
  meta(meta$1),
606
663
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { dangerouslySetInnerHTML: { __html: css } })
607
- ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Body, {
608
- style: bodyStyle,
609
- children: [resolvedPreview && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Preview, { children: resolvedPreview }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Container, {
610
- style: container,
611
- children: [child, openTrackingPixel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
612
- src: openTrackingPixel,
613
- width: "1",
614
- height: "1",
615
- alt: "",
616
- style: { display: "none" }
617
- })]
618
- })]
619
- })]
664
+ ] }), content]
620
665
  });
621
666
  };
622
667
  //#endregion
623
- //#region src/lib/styles.ts
624
- /**
625
- * Cross-browser font smoothing properties. Applied to the document
626
- * root so all text renders with subpixel antialiasing disabled.
627
- */
628
- const ANTIALIASED = {
629
- WebkitFontSmoothing: "antialiased",
630
- MozOsxFontSmoothing: "grayscale"
631
- };
632
- //#endregion
633
668
  //#region src/nodes/footer.tsx
634
669
  const footer = (node, ctx) => {
635
670
  if (!_maily_to_shared.is.footer(node)) return null;
636
- const { textAlign, dir } = node.attrs;
637
- const theme = ctx.config.theme;
638
- const fontStyle = (0, _maily_to_shared.getFontStyle)(node.attrs, theme.footer);
639
- prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.footer);
640
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Text, {
671
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
672
+ dir: node.attrs?.dir ?? void 0,
641
673
  style: {
642
- ...textAlign ? { textAlign } : {},
643
- ...(0, _maily_to_shared.getCssDirection)(dir),
644
- color: theme.footer?.color,
645
- marginTop: 0,
646
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
647
674
  ...ANTIALIASED,
648
- ...fontStyle
675
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
676
+ ...getNodeStyle(node.attrs?.style)
649
677
  },
650
678
  children: ctx.children(node)
651
679
  });
@@ -664,67 +692,55 @@ const HEADING_LEVELS = {
664
692
  };
665
693
  const heading = (node, ctx) => {
666
694
  if (!_maily_to_shared.is.heading(node)) return null;
667
- const { level, textAlign, dir } = node.attrs;
668
- const theme = ctx.config.theme;
669
- const element = HEADING_LEVELS[level];
670
- const key = `h${level}`;
671
- const defaults = theme.heading?.[key];
672
- const fontStyle = (0, _maily_to_shared.getFontStyle)(node.attrs, defaults);
673
- prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, defaults);
674
695
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Heading, {
675
- as: element,
696
+ as: HEADING_LEVELS[node.attrs.level],
697
+ dir: node.attrs.dir ?? void 0,
676
698
  style: {
677
- textAlign: textAlign ?? _maily_to_shared.TEXT_ALIGNMENTS.LEFT,
678
- ...(0, _maily_to_shared.getCssDirection)(dir),
679
- color: theme.heading?.defaults?.color,
680
- marginTop: 0,
681
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 12,
682
- ...fontStyle
699
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs.dir),
700
+ ...getNodeStyle(node.attrs.style)
683
701
  },
684
702
  children: ctx.children(node)
685
703
  });
686
704
  };
687
705
  //#endregion
688
706
  //#region src/nodes/horizontal-rule.tsx
689
- const horizontalRule = (node, ctx) => {
707
+ const horizontalRule = (node) => {
690
708
  if (!_maily_to_shared.is.horizontalRule(node)) return null;
691
- const theme = ctx.config.theme;
692
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Hr, { style: {
693
- borderColor: theme.horizontalRule?.color,
694
- marginTop: shouldSuppressMarginTop(ctx) ? 0 : 32,
695
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32
696
- } });
709
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Hr, { style: getNodeStyle(node.attrs?.style) });
697
710
  };
698
711
  //#endregion
699
712
  //#region src/nodes/html-code-block.tsx
700
- function resolveText(node, ctx) {
701
- if (node.type === _maily_to_shared.MAILY_NODE_TYPES.TEXT && "text" in node) return node.text;
702
- if (node.type === _maily_to_shared.MAILY_NODE_TYPES.VARIABLE && "attrs" in node) {
703
- const { id, fallback } = node.attrs;
704
- if (!id) return "";
705
- return resolveVariableId(id, fallback, ctx);
713
+ function getResolvedText(node, ctx) {
714
+ if (_maily_to_shared.is.text(node)) return node.text;
715
+ if (_maily_to_shared.is.variable(node)) {
716
+ const { fallback, id } = node.attrs;
717
+ return id ? resolveVariableId(id, fallback, ctx) : "";
706
718
  }
707
- if (node.content && Array.isArray(node.content)) return node.content.map((child) => resolveText(child, ctx)).join("");
708
- return "";
719
+ if (!node.content) return "";
720
+ return node.content.map((child) => {
721
+ return getResolvedText(child, ctx);
722
+ }).join("");
709
723
  }
710
724
  const htmlCodeBlock = (node, ctx) => {
711
725
  if (!_maily_to_shared.is.htmlCodeBlock(node)) return null;
712
- const doc = (0, node_html_parser.parse)((0, juice.default)(node.content ? node.content.reduce((acc, child) => acc + resolveText(child, ctx), "") : ""));
713
- doc.querySelector("head")?.remove();
714
- const html = doc.toString();
726
+ const source = node.content ? node.content.map((child) => {
727
+ return getResolvedText(child, ctx);
728
+ }).join("") : "";
729
+ const document = (0, node_html_parser.parse)((0, juice.default)(source));
730
+ document.querySelector("head")?.remove();
715
731
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
716
732
  align: "left",
717
- width: "100%",
718
733
  border: 0,
719
734
  cellPadding: "0",
720
735
  cellSpacing: "0",
721
736
  role: "presentation",
722
- style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32 },
737
+ style: getNodeStyle(node.attrs?.style),
738
+ width: "100%",
723
739
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
724
740
  style: { width: "100%" },
725
741
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
726
- style: { width: "100%" },
727
- dangerouslySetInnerHTML: { __html: html }
742
+ dangerouslySetInnerHTML: { __html: document.toString() },
743
+ style: { width: "100%" }
728
744
  })
729
745
  }) })
730
746
  });
@@ -733,169 +749,193 @@ const htmlCodeBlock = (node, ctx) => {
733
749
  //#region src/nodes/image.tsx
734
750
  const image = (node, ctx) => {
735
751
  if (!_maily_to_shared.is.image(node)) return null;
736
- const { src, alt, title, width, align, externalLink } = node.attrs;
752
+ const { align, alt, externalLink, src, title, width } = node.attrs;
737
753
  const resolvedSrc = resolveVariableText(src, ctx);
738
- const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
754
+ const resolvedExternalLink = externalLink ? getSafeHref(resolveVariableText(externalLink, ctx)) : externalLink;
739
755
  const percent = (0, _maily_to_shared.parseWidthToPercentage)(width, ctx.box);
740
756
  const absoluteWidth = Math.round(ctx.box * percent / 100);
741
757
  const img = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
742
- src: resolvedSrc,
743
- alt,
744
- title,
745
- width: absoluteWidth,
758
+ alt: alt ?? void 0,
759
+ src: resolvedSrc || void 0,
746
760
  style: {
747
- width: width ?? "100%",
748
- maxWidth: absoluteWidth,
749
- height: "auto",
750
761
  display: "block",
751
- ...(0, _maily_to_shared.getBorderStyle)(node.attrs)
752
- }
753
- });
754
- const content = resolvedExternalLink ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
755
- href: resolvedExternalLink,
756
- target: "_blank",
757
- rel: "noopener noreferrer nofollow",
758
- style: { display: "block" },
759
- children: img
760
- }) : img;
761
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
762
- style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32 },
763
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
764
- align: align ?? _maily_to_shared.TEXT_ALIGNMENTS.LEFT,
765
- children: content
766
- })
762
+ height: "auto",
763
+ maxWidth: absoluteWidth,
764
+ width: width ?? "100%",
765
+ ...getNodeStyle(node.attrs.style)
766
+ },
767
+ title: title ?? void 0,
768
+ width: absoluteWidth
767
769
  });
770
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
771
+ align,
772
+ children: resolvedExternalLink ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
773
+ href: resolvedExternalLink,
774
+ rel: "noopener noreferrer nofollow",
775
+ style: { display: "block" },
776
+ target: "_blank",
777
+ children: img
778
+ }) : img
779
+ }) });
768
780
  };
769
781
  //#endregion
770
782
  //#region src/nodes/inline-image.tsx
771
783
  const inlineImage = (node, ctx) => {
772
784
  if (!_maily_to_shared.is.inlineImage(node)) return null;
773
- const { src, alt, width, height, externalLink } = node.attrs;
785
+ const { alt, externalLink, height, src, width } = node.attrs;
774
786
  const resolvedSrc = resolveVariableText(src, ctx);
775
- const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
787
+ const resolvedExternalLink = externalLink ? getSafeHref(resolveVariableText(externalLink, ctx)) : externalLink;
776
788
  const img = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
777
- src: resolvedSrc,
778
789
  alt: alt ?? "",
779
- width,
780
790
  height,
791
+ src: resolvedSrc || void 0,
781
792
  style: {
793
+ border: "none",
782
794
  display: "inline",
783
- verticalAlign: "middle",
784
- width,
785
795
  height,
786
796
  outline: "none",
787
- border: "none",
788
- textDecoration: "none"
789
- }
797
+ textDecoration: "none",
798
+ verticalAlign: "middle",
799
+ width,
800
+ ...getNodeStyle(node.attrs.style)
801
+ },
802
+ width
790
803
  });
791
- if (resolvedExternalLink) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
804
+ if (!resolvedExternalLink) return img;
805
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
792
806
  href: resolvedExternalLink,
793
- target: "_blank",
794
807
  rel: "noopener noreferrer nofollow",
795
808
  style: {
796
809
  display: "inline",
797
810
  textDecoration: "none"
798
811
  },
812
+ target: "_blank",
799
813
  children: img
800
814
  });
801
- return img;
802
815
  };
803
816
  //#endregion
817
+ //#region src/nodes/inline-span.tsx
818
+ const inlineSpan = (node) => {
819
+ if (!_maily_to_shared.is.inlineSpan(node)) return null;
820
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: getNodeStyle(node.attrs?.style) });
821
+ };
822
+ //#endregion
823
+ //#region src/lib/spacing.ts
824
+ function getNodePosition(ctx) {
825
+ const { parent, siblingIndex } = ctx;
826
+ const content = parent && _maily_to_shared.is.parent(parent) ? parent.content : [];
827
+ return {
828
+ isFirst: siblingIndex === 0,
829
+ isLast: siblingIndex === content.length - 1,
830
+ nextType: content[siblingIndex + 1]?.type,
831
+ parentType: parent?.type,
832
+ previousType: content[siblingIndex - 1]?.type
833
+ };
834
+ }
835
+ /**
836
+ * Returns true if this node's bottom margin should be collapsed — i.e. it's
837
+ * the last child of a block container, or is followed by a spacer or hr.
838
+ */
839
+ function shouldSuppressMarginBottom(ctx) {
840
+ return (0, _maily_to_shared.getSuppressedMargins)(getNodePosition(ctx)).marginBottom;
841
+ }
842
+ //#endregion
804
843
  //#region src/nodes/link-card.tsx
805
844
  const linkCard = (node, ctx) => {
806
845
  if (!_maily_to_shared.is.linkCard(node)) return null;
807
- if (!shouldShow(node, ctx)) return null;
808
- const { title, description, link, linkTitle, image, subTitle, badgeText } = node.attrs;
809
- const theme = ctx.config.theme.linkCard;
810
- const href = (link ? resolveVariableText(link, ctx) : "") || "#";
846
+ const { badgeText, description, image, link, linkTitle, subTitle, title } = node.attrs;
847
+ const href = (link ? getSafeHref(resolveVariableText(link, ctx)) : "") || "#";
848
+ const alt = title || "Link card";
811
849
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
812
850
  href,
813
851
  rel: "noopener noreferrer",
814
852
  style: {
815
- border: `1px solid ${theme?.borderColor ?? "#eaeaea"}`,
816
- borderRadius: 10,
817
- textDecoration: "none",
853
+ border: "1px solid #eaeaea",
854
+ borderRadius: "10px",
818
855
  color: "inherit",
819
856
  display: "block",
820
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20
857
+ marginBottom: shouldSuppressMarginBottom(ctx) ? "0" : "20px",
858
+ textDecoration: "none",
859
+ ...getNodeStyle(node.attrs?.style)
821
860
  },
822
861
  target: "_blank",
823
862
  children: [image ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
824
- style: { marginBottom: 6 },
863
+ style: { marginBottom: "6px" },
825
864
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
826
865
  style: {
827
- width: "100%",
828
- height: "100%"
866
+ height: "100%",
867
+ width: "100%"
829
868
  },
830
869
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
831
- alt: title || "Link Card",
870
+ alt,
832
871
  src: image,
833
872
  style: {
834
873
  borderRadius: "10px 10px 0 0",
835
- width: "100%",
836
874
  height: "100%",
837
- objectFit: "cover"
875
+ objectFit: "cover",
876
+ width: "100%"
838
877
  },
839
- title: title || "Link Card"
878
+ title: alt
840
879
  })
841
880
  })
842
881
  }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
843
882
  style: {
844
- padding: 15,
845
- marginTop: 0,
846
- marginBottom: 0
883
+ marginBottom: "0",
884
+ marginTop: "0",
885
+ padding: "15px"
847
886
  },
848
887
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Column, {
849
888
  style: { verticalAlign: "top" },
850
889
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
890
+ align: "left",
851
891
  style: {
852
- marginBottom: 8,
853
- marginTop: 0
892
+ marginBottom: "8px",
893
+ marginTop: "0"
854
894
  },
855
- width: "100%",
856
- align: "left",
857
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Text, {
895
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
858
896
  style: {
859
- fontSize: 18,
860
- fontWeight: 600,
861
- color: theme?.titleColor ?? "#111827",
862
- margin: 0,
863
- textAlign: "left",
864
- ...ANTIALIASED
897
+ ...ANTIALIASED,
898
+ color: "#111827",
899
+ fontSize: "18px",
900
+ fontWeight: "600",
901
+ lineHeight: "24px",
902
+ margin: "0",
903
+ textAlign: "left"
865
904
  },
866
905
  children: [
867
906
  title,
868
- badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
907
+ badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
869
908
  style: {
870
- fontWeight: 600,
871
- color: theme?.badgeTextColor ?? "#6B7280",
872
- padding: "4px 8px",
909
+ backgroundColor: "#f3f4f6",
873
910
  borderRadius: "8px",
874
- backgroundColor: theme?.badgeBackgroundColor ?? "#F3F4F6",
911
+ color: "#6b7280",
875
912
  fontSize: "12px",
913
+ fontWeight: "600",
876
914
  lineHeight: "12px",
877
- marginLeft: "6px"
915
+ marginLeft: "6px",
916
+ padding: "4px 8px"
878
917
  },
879
918
  children: badgeText
880
- }),
881
- subTitle && !badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
919
+ }) : null,
920
+ subTitle && !badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
882
921
  style: {
922
+ color: "#6b7280",
923
+ fontSize: "12px",
883
924
  fontWeight: "normal",
884
- color: theme?.subTitleColor ?? "#6B7280",
885
- fontSize: 12,
886
925
  lineHeight: "12px",
887
926
  marginLeft: "6px"
888
927
  },
889
928
  children: subTitle
890
- })
929
+ }) : null
891
930
  ]
892
931
  }) })
893
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Text, {
932
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
894
933
  style: {
895
- fontSize: 16,
896
- color: theme?.descriptionColor ?? "#374151",
897
- marginTop: 0,
898
- marginBottom: 0
934
+ color: "#374151",
935
+ fontSize: "16px",
936
+ lineHeight: "24px",
937
+ marginBottom: "0",
938
+ marginTop: "0"
899
939
  },
900
940
  children: [
901
941
  description,
@@ -904,11 +944,12 @@ const linkCard = (node, ctx) => {
904
944
  href,
905
945
  rel: "noopener noreferrer",
906
946
  style: {
907
- color: theme?.titleColor ?? "#111827",
908
- fontSize: 14,
909
- fontWeight: 600,
947
+ color: "#111827",
948
+ fontSize: "14px",
949
+ fontWeight: "600",
910
950
  textDecoration: "underline"
911
951
  },
952
+ target: "_blank",
912
953
  children: linkTitle
913
954
  }) : null
914
955
  ]
@@ -921,15 +962,12 @@ const linkCard = (node, ctx) => {
921
962
  //#region src/nodes/list-item.tsx
922
963
  const listItem = (node, ctx) => {
923
964
  if (!_maily_to_shared.is.listItem(node)) return null;
924
- const { dir } = node.attrs;
925
965
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
966
+ dir: node.attrs?.dir ?? void 0,
926
967
  style: {
927
- color: ctx.config.theme.listMarker?.color,
928
- marginBottom: 8,
929
- marginTop: 8,
930
- paddingLeft: 6,
931
968
  ...ANTIALIASED,
932
- ...(0, _maily_to_shared.getCssDirection)(dir)
969
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
970
+ ...getNodeStyle(node.attrs?.style)
933
971
  },
934
972
  children: ctx.children(node)
935
973
  });
@@ -938,37 +976,24 @@ const listItem = (node, ctx) => {
938
976
  //#region src/nodes/ordered-list.tsx
939
977
  const orderedList = (node, ctx) => {
940
978
  if (!_maily_to_shared.is.orderedList(node)) return null;
941
- const { dir } = node.attrs;
942
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
943
- style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20 },
944
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
945
- style: {
946
- paddingLeft: 26,
947
- listStyleType: "decimal",
948
- margin: 0,
949
- ...(0, _maily_to_shared.getCssDirection)(dir)
950
- },
951
- children: ctx.children(node)
952
- })
979
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
980
+ start: node.attrs?.start,
981
+ style: {
982
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
983
+ ...getNodeStyle(node.attrs?.style)
984
+ },
985
+ children: ctx.children(node)
953
986
  });
954
987
  };
955
988
  //#endregion
956
989
  //#region src/nodes/paragraph.tsx
957
990
  const paragraph = (node, ctx) => {
958
991
  if (!_maily_to_shared.is.paragraph(node)) return null;
959
- const { textAlign, dir } = node.attrs;
960
- const theme = ctx.config.theme;
961
- const fontStyle = (0, _maily_to_shared.getFontStyle)(node.attrs, theme.paragraph);
962
- prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.paragraph);
963
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Text, {
992
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
993
+ dir: node.attrs?.dir ?? void 0,
964
994
  style: {
965
- ...textAlign ? { textAlign } : {},
966
- ...(0, _maily_to_shared.getCssDirection)(dir),
967
- color: theme.paragraph?.color,
968
- marginTop: 0,
969
- marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
970
- ...ANTIALIASED,
971
- ...fontStyle
995
+ ...(0, _maily_to_shared.getCssDirection)(node.attrs?.dir),
996
+ ...getNodeStyle(node.attrs?.style)
972
997
  },
973
998
  children: ctx.children(node)
974
999
  });
@@ -978,8 +1003,7 @@ const paragraph = (node, ctx) => {
978
1003
  const repeat = (node, ctx) => {
979
1004
  if (!_maily_to_shared.is.repeat(node)) return null;
980
1005
  const { each } = node.attrs;
981
- const payload = ctx.config.variableValues.get(each);
982
- if (!Array.isArray(payload)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: ctx.children(node) });
1006
+ const payload = getVariableList(each, ctx);
983
1007
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: payload.map((item, index) => {
984
1008
  const childContext = ctx.child({
985
1009
  parent: node,
@@ -993,90 +1017,215 @@ const repeat = (node, ctx) => {
993
1017
  //#region src/nodes/section.tsx
994
1018
  const section = (node, ctx) => {
995
1019
  if (!_maily_to_shared.is.section(node)) return null;
996
- if (!shouldShow(node, ctx)) return null;
997
- const { backgroundColor, align } = node.attrs;
998
- const borderStyle = (0, _maily_to_shared.getBorderStyle)(node.attrs);
999
- const paddingStyle = (0, _maily_to_shared.getPaddingStyle)(node.attrs);
1000
- const marginStyle = (0, _maily_to_shared.getMarginStyle)(node.attrs);
1001
- const size = insetBox(ctx.size, {
1002
- paddingLeft: node.attrs.paddingLeft,
1003
- paddingRight: node.attrs.paddingRight,
1004
- borderLeft: node.attrs.borderLeftWidth,
1005
- borderRight: node.attrs.borderRightWidth
1006
- });
1007
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
1008
- style: marginStyle,
1009
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
1010
- align: align ?? _maily_to_shared.TEXT_ALIGNMENTS.LEFT,
1011
- style: {
1012
- backgroundColor,
1013
- ...borderStyle,
1014
- ...paddingStyle
1015
- },
1016
- children: ctx.child({ size }).children(node)
1017
- })
1020
+ const style = getNodeStyle(node.attrs?.style);
1021
+ const align = getStyleAlignment(style) ?? "left";
1022
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Section, {
1023
+ align,
1024
+ style,
1025
+ children: ctx.children(node)
1018
1026
  });
1019
1027
  };
1020
1028
  //#endregion
1021
1029
  //#region src/nodes/spacer.tsx
1022
1030
  const spacer = (node) => {
1023
1031
  if (!_maily_to_shared.is.spacer(node)) return null;
1024
- const { height } = node.attrs;
1025
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, { style: { height: `${height}px` } });
1032
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, { style: {
1033
+ height: `${node.attrs.height}px`,
1034
+ ...getNodeStyle(node.attrs.style)
1035
+ } });
1036
+ };
1037
+ //#endregion
1038
+ //#region src/lib/table.ts
1039
+ const ALIGNMENTS = [
1040
+ "center",
1041
+ "justify",
1042
+ "left",
1043
+ "right"
1044
+ ];
1045
+ const VERTICAL_ALIGNMENTS = [
1046
+ "baseline",
1047
+ "bottom",
1048
+ "middle",
1049
+ "top"
1050
+ ];
1051
+ function toAttributeLength(value) {
1052
+ if (!value) return;
1053
+ const trimmed = value.trim();
1054
+ if (trimmed.endsWith("%")) return trimmed;
1055
+ return trimmed.endsWith("px") ? trimmed.slice(0, -2) : void 0;
1056
+ }
1057
+ function toAllowedKeyword(value, allowed) {
1058
+ return value && allowed.includes(value) ? value : void 0;
1059
+ }
1060
+ function getTableAlignment(style) {
1061
+ const left = style.marginLeft === "auto";
1062
+ const right = style.marginRight === "auto";
1063
+ if (left && right) return "center";
1064
+ if (left) return "right";
1065
+ return right ? "left" : void 0;
1066
+ }
1067
+ function getTableAttributes(style) {
1068
+ if (!style) return {};
1069
+ return {
1070
+ align: getTableAlignment(style),
1071
+ bgcolor: style.backgroundColor,
1072
+ width: toAttributeLength(style.width)
1073
+ };
1074
+ }
1075
+ function getRowAttributes(style) {
1076
+ if (!style) return {};
1077
+ return {
1078
+ align: toAllowedKeyword(style.textAlign, ALIGNMENTS),
1079
+ bgcolor: style.backgroundColor,
1080
+ valign: toAllowedKeyword(style.verticalAlign, VERTICAL_ALIGNMENTS)
1081
+ };
1082
+ }
1083
+ function getCellAttributes(style) {
1084
+ if (!style) return {};
1085
+ return {
1086
+ align: toAllowedKeyword(style.textAlign, ALIGNMENTS),
1087
+ bgcolor: style.backgroundColor,
1088
+ height: toAttributeLength(style.height),
1089
+ valign: toAllowedKeyword(style.verticalAlign, VERTICAL_ALIGNMENTS),
1090
+ width: toAttributeLength(style.width)
1091
+ };
1092
+ }
1093
+ function getDeclaredWidth(style, box) {
1094
+ const width = style?.width?.trim();
1095
+ if (!width) return null;
1096
+ const value = Number.parseFloat(width);
1097
+ if (Number.isNaN(value)) return null;
1098
+ if (width.endsWith("%")) return box * value / 100;
1099
+ return width.endsWith("px") ? value : null;
1100
+ }
1101
+ function getCellWidths(cells, box) {
1102
+ const declared = cells.map((cell) => getDeclaredWidth(getNodeStyle(cell.attrs?.style), box));
1103
+ const spans = cells.map((cell) => Number(cell.attrs?.colspan) || 1);
1104
+ const claimed = declared.reduce((total, width) => total + (width ?? 0), 0);
1105
+ const freeSpans = spans.reduce((total, span, index) => declared[index] === null ? total + span : total, 0);
1106
+ const free = Math.max(0, box - claimed);
1107
+ return declared.map((width, index) => width ?? (freeSpans > 0 ? free * spans[index] / freeSpans : 0));
1108
+ }
1109
+ //#endregion
1110
+ //#region src/nodes/table.tsx
1111
+ const RESPONSIVE_TABLE_CSS = `@media only screen and (max-width:480px){table[data-mly-responsive="stack"]>tbody>tr>td{display:block!important;width:100%!important}}`;
1112
+ const table = (node, ctx) => {
1113
+ if (!_maily_to_shared.is.table(node)) return null;
1114
+ const style = getNodeStyle(node.attrs.style);
1115
+ const hasHeaders = node.content.some((row) => row.content?.some((cell) => cell.type === _maily_to_shared.MAILY_NODE_TYPES.TABLE_HEADER));
1116
+ if (node.attrs.responsive) ctx.style(RESPONSIVE_TABLE_CSS);
1117
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
1118
+ ...getTableAttributes(style),
1119
+ border: node.attrs.border ?? 0,
1120
+ cellPadding: node.attrs.cellpadding ?? 0,
1121
+ cellSpacing: node.attrs.cellspacing ?? 0,
1122
+ "data-mly-responsive": node.attrs.responsive ? "stack" : void 0,
1123
+ role: hasHeaders ? void 0 : "presentation",
1124
+ style,
1125
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: ctx.children(node) })
1126
+ });
1127
+ };
1128
+ //#endregion
1129
+ //#region src/nodes/table-cell.tsx
1130
+ const tableCell = (node, ctx) => {
1131
+ if (!_maily_to_shared.is.tableCell(node)) return null;
1132
+ const style = getNodeStyle(node.attrs.style);
1133
+ const size = insetXFromStyle(ctx.size, style);
1134
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
1135
+ ...getCellAttributes(style),
1136
+ colSpan: node.attrs.colspan,
1137
+ rowSpan: node.attrs.rowspan,
1138
+ style,
1139
+ children: ctx.child({ size }).children(node)
1140
+ });
1141
+ };
1142
+ //#endregion
1143
+ //#region src/nodes/table-header.tsx
1144
+ const tableHeader = (node, ctx) => {
1145
+ if (!_maily_to_shared.is.tableHeader(node)) return null;
1146
+ const style = getNodeStyle(node.attrs.style);
1147
+ const size = insetXFromStyle(ctx.size, style);
1148
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
1149
+ ...getCellAttributes(style),
1150
+ colSpan: node.attrs.colspan,
1151
+ rowSpan: node.attrs.rowspan,
1152
+ style,
1153
+ children: ctx.child({ size }).children(node)
1154
+ });
1155
+ };
1156
+ //#endregion
1157
+ //#region src/nodes/table-row.tsx
1158
+ const tableRow = (node, ctx) => {
1159
+ if (!_maily_to_shared.is.tableRow(node)) return null;
1160
+ const style = getNodeStyle(node.attrs?.style);
1161
+ const widths = getCellWidths(node.content, ctx.box);
1162
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
1163
+ ...getRowAttributes(style),
1164
+ style,
1165
+ children: node.content.map((cell, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: ctx.child({
1166
+ parent: node,
1167
+ siblingIndex: index,
1168
+ size: initSize(widths[index])
1169
+ }).render(cell) }, index))
1170
+ });
1026
1171
  };
1027
1172
  //#endregion
1028
1173
  //#region src/marks/bold.tsx
1029
- const bold = (_mark, text, _ctx) => {
1030
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: text });
1174
+ const bold = (mark, text) => {
1175
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
1176
+ style: getNodeStyle(mark.attrs?.style),
1177
+ children: text
1178
+ });
1031
1179
  };
1032
1180
  //#endregion
1033
1181
  //#region src/marks/code.tsx
1034
- const CODE_FONT_FAMILY = "ui-monospace, monospace";
1035
- const code = (_mark, text, ctx) => {
1036
- const theme = ctx.config.theme;
1182
+ const code = (mark, text) => {
1037
1183
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1038
1184
  style: {
1039
- backgroundColor: theme.code?.backgroundColor,
1040
- color: theme.code?.color,
1041
- fontFamily: CODE_FONT_FAMILY,
1042
- fontSize: "85%",
1043
- padding: "2px 6px",
1044
- borderRadius: 8,
1045
- ...ANTIALIASED
1185
+ ...ANTIALIASED,
1186
+ ...getNodeStyle(mark.attrs?.style)
1046
1187
  },
1047
1188
  children: text
1048
1189
  });
1049
1190
  };
1050
1191
  //#endregion
1051
1192
  //#region src/marks/italic.tsx
1052
- const italic = (_mark, text, _ctx) => {
1053
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("em", { children: text });
1193
+ const italic = (mark, text) => {
1194
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("em", {
1195
+ style: getNodeStyle(mark.attrs?.style),
1196
+ children: text
1197
+ });
1054
1198
  };
1055
1199
  //#endregion
1056
1200
  //#region src/marks/link.tsx
1057
- const link = (mark, text, ctx) => {
1201
+ const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
1202
+ const link = (mark, text) => {
1058
1203
  if (!_maily_to_shared.is.link(mark)) return null;
1059
- const theme = ctx.config.theme;
1060
- const linkOverride = ctx.config.variableValues.get(mark.attrs.href);
1061
- const href = (typeof linkOverride === "string" ? linkOverride : void 0) ?? resolveVariableText(mark.attrs.href, ctx);
1062
- const color = theme.link?.color;
1204
+ const { href, rel, style, target, title } = mark.attrs;
1063
1205
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
1064
1206
  href,
1065
- target: "_blank",
1066
- rel: "noopener noreferrer nofollow",
1067
- style: color ? { color } : void 0,
1207
+ rel: rel ?? DEFAULT_LINK_REL,
1208
+ style: getNodeStyle(style),
1209
+ target: target ?? "_blank",
1210
+ title: title ?? void 0,
1068
1211
  children: text
1069
1212
  });
1070
1213
  };
1071
1214
  //#endregion
1072
1215
  //#region src/marks/strike.tsx
1073
- const strike = (_mark, text, _ctx) => {
1074
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("s", { children: text });
1216
+ const strike = (mark, text) => {
1217
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("s", {
1218
+ style: getNodeStyle(mark.attrs?.style),
1219
+ children: text
1220
+ });
1075
1221
  };
1076
1222
  //#endregion
1077
1223
  //#region src/marks/underline.tsx
1078
- const underline = (_mark, text, _ctx) => {
1079
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("u", { children: text });
1224
+ const underline = (mark, text) => {
1225
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("u", {
1226
+ style: getNodeStyle(mark.attrs?.style),
1227
+ children: text
1228
+ });
1080
1229
  };
1081
1230
  //#endregion
1082
1231
  //#region src/mark.tsx
@@ -1102,21 +1251,16 @@ function render$1(mark, text, ctx) {
1102
1251
  if (!renderer) return null;
1103
1252
  return renderer(mark, text, ctx);
1104
1253
  }
1105
- /**
1106
- * Applies all marks on a text node. Merges textStyle and highlight
1107
- * marks into a single span, then wraps with remaining marks in order.
1108
- */
1109
1254
  function marks(node, ctx) {
1110
1255
  if (!_maily_to_shared.is.marked(node)) return [];
1111
- const themeColor = ctx.config.theme.paragraph?.color;
1112
- const textStyles = node.marks.filter((mark) => _maily_to_shared.is.textStyle(mark) || _maily_to_shared.is.highlight(mark)).reduce((acc, mark) => {
1113
- if (_maily_to_shared.is.textStyle(mark)) acc.color = mark.attrs.color || themeColor;
1114
- else acc.backgroundColor = mark.attrs.color;
1256
+ const textStyles = node.marks.filter((mark) => _maily_to_shared.is.textStyle(mark) || _maily_to_shared.is.highlight(mark) || _maily_to_shared.is.span(mark)).reduce((acc, mark) => {
1257
+ if (_maily_to_shared.is.textStyle(mark)) {
1258
+ if (mark.attrs.color) acc.color = mark.attrs.color;
1259
+ } else if (_maily_to_shared.is.highlight(mark)) acc.backgroundColor = mark.attrs.color;
1260
+ else Object.assign(acc, getNodeStyle(mark.attrs?.style));
1115
1261
  return acc;
1116
1262
  }, {});
1117
- const marks = node.marks.filter((mark) => !_maily_to_shared.is.textStyle(mark) && !_maily_to_shared.is.highlight(mark)).sort((a, b) => {
1118
- return MAILY_MARKS_ORDER.indexOf(a.type) - MAILY_MARKS_ORDER.indexOf(b.type);
1119
- });
1263
+ const marks = node.marks.filter((mark) => !_maily_to_shared.is.textStyle(mark) && !_maily_to_shared.is.highlight(mark) && !_maily_to_shared.is.span(mark)).sort((a, b) => MAILY_MARKS_ORDER.indexOf(a.type) - MAILY_MARKS_ORDER.indexOf(b.type));
1120
1264
  const text = node?.text || /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: "\xA0" });
1121
1265
  const baseText = isEmptyObject(textStyles) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: text }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1122
1266
  style: textStyles,
@@ -1148,7 +1292,7 @@ const text = (node, ctx) => {
1148
1292
  //#region src/nodes/variable.tsx
1149
1293
  const variable = (node, ctx) => {
1150
1294
  if (!_maily_to_shared.is.variable(node)) return null;
1151
- const { id, fallback } = node.attrs;
1295
+ const { fallback, id } = node.attrs;
1152
1296
  if (!id) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback ?? "" });
1153
1297
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: resolveVariableId(id, fallback, ctx) });
1154
1298
  };
@@ -1156,32 +1300,43 @@ const variable = (node, ctx) => {
1156
1300
  //#region src/node.tsx
1157
1301
  const MAILY_NODE_RENDERERS = {
1158
1302
  [_maily_to_shared.MAILY_NODE_TYPES.DOCUMENT]: document,
1303
+ [_maily_to_shared.MAILY_NODE_TYPES.BODY]: body,
1304
+ [_maily_to_shared.MAILY_NODE_TYPES.CONTAINER]: container,
1305
+ [_maily_to_shared.MAILY_NODE_TYPES.SECTION]: section,
1306
+ [_maily_to_shared.MAILY_NODE_TYPES.COLUMNS]: columns,
1307
+ [_maily_to_shared.MAILY_NODE_TYPES.COLUMN]: column,
1159
1308
  [_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH]: paragraph,
1160
- [_maily_to_shared.MAILY_NODE_TYPES.TEXT]: text,
1161
1309
  [_maily_to_shared.MAILY_NODE_TYPES.HEADING]: heading,
1162
- [_maily_to_shared.MAILY_NODE_TYPES.VARIABLE]: variable,
1310
+ [_maily_to_shared.MAILY_NODE_TYPES.REPEAT]: repeat,
1163
1311
  [_maily_to_shared.MAILY_NODE_TYPES.IMAGE]: image,
1164
1312
  [_maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE]: inlineImage,
1313
+ [_maily_to_shared.MAILY_NODE_TYPES.INLINE_SPAN]: inlineSpan,
1165
1314
  [_maily_to_shared.MAILY_NODE_TYPES.SPACER]: spacer,
1166
- [_maily_to_shared.MAILY_NODE_TYPES.SECTION]: section,
1167
1315
  [_maily_to_shared.MAILY_NODE_TYPES.BUTTON]: button,
1168
- [_maily_to_shared.MAILY_NODE_TYPES.REPEAT]: repeat,
1169
- [_maily_to_shared.MAILY_NODE_TYPES.COLUMNS]: columns,
1170
- [_maily_to_shared.MAILY_NODE_TYPES.COLUMN]: column,
1171
- [_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST]: bulletList,
1172
- [_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST]: orderedList,
1173
- [_maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM]: listItem,
1316
+ [_maily_to_shared.MAILY_NODE_TYPES.FOOTER]: footer,
1317
+ [_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE]: blockquote,
1174
1318
  [_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE]: horizontalRule,
1175
1319
  [_maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK]: htmlCodeBlock,
1176
- [_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE]: blockquote,
1177
1320
  [_maily_to_shared.MAILY_NODE_TYPES.HARD_BREAK]: hardBreak,
1178
- [_maily_to_shared.MAILY_NODE_TYPES.FOOTER]: footer,
1179
- [_maily_to_shared.MAILY_NODE_TYPES.LINK_CARD]: linkCard
1321
+ [_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST]: bulletList,
1322
+ [_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST]: orderedList,
1323
+ [_maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM]: listItem,
1324
+ [_maily_to_shared.MAILY_NODE_TYPES.LINK_CARD]: linkCard,
1325
+ [_maily_to_shared.MAILY_NODE_TYPES.TEXT]: text,
1326
+ [_maily_to_shared.MAILY_NODE_TYPES.VARIABLE]: variable,
1327
+ [_maily_to_shared.MAILY_NODE_TYPES.TABLE]: table,
1328
+ [_maily_to_shared.MAILY_NODE_TYPES.TABLE_ROW]: tableRow,
1329
+ [_maily_to_shared.MAILY_NODE_TYPES.TABLE_CELL]: tableCell,
1330
+ [_maily_to_shared.MAILY_NODE_TYPES.TABLE_HEADER]: tableHeader
1180
1331
  };
1181
1332
  function dispatch(node, ctx) {
1182
1333
  if (!_maily_to_shared.is.node(node)) return null;
1183
1334
  const renderer = MAILY_NODE_RENDERERS[node.type];
1184
1335
  if (!renderer) return null;
1336
+ if (!shouldShowNode({
1337
+ ctx,
1338
+ node
1339
+ })) return null;
1185
1340
  return renderer(node, ctx);
1186
1341
  }
1187
1342
  function children(parent, ctx) {
@@ -1212,15 +1367,14 @@ function defineRenderContext(opts) {
1212
1367
  styles: /* @__PURE__ */ new Set(),
1213
1368
  fonts: /* @__PURE__ */ new Map()
1214
1369
  };
1215
- const size = {
1216
- ...DEFAULT_SIZE,
1217
- ...opts.size
1218
- };
1219
1370
  return defineContext({
1220
1371
  config: opts.config,
1221
1372
  parent: opts.parent,
1222
1373
  siblingIndex: opts.siblingIndex ?? 0,
1223
- size
1374
+ size: {
1375
+ ...DEFAULT_SIZE,
1376
+ ...opts.size
1377
+ }
1224
1378
  }, shared);
1225
1379
  }
1226
1380
  function defineContext(opts, shared) {
@@ -1254,8 +1408,8 @@ function defineContext(opts, shared) {
1254
1408
  style(css) {
1255
1409
  styles.add(css);
1256
1410
  },
1257
- font(name, props) {
1258
- fonts.set(name, props);
1411
+ font(key, font) {
1412
+ fonts.set(key, font);
1259
1413
  },
1260
1414
  child(opts) {
1261
1415
  const childSize = opts.size ? {
@@ -1285,144 +1439,181 @@ function defineContext(opts, shared) {
1285
1439
  return ctx;
1286
1440
  }
1287
1441
  //#endregion
1288
- //#region src/lib/link.ts
1289
- /**
1290
- * Extracts all valid URLs from link marks in a Maily document.
1291
- * Returns a deduplicated Set of href strings.
1292
- */
1293
- function links(json) {
1294
- const links = /* @__PURE__ */ new Set();
1295
- if (!_maily_to_shared.is.node(json)) return links;
1296
- function visitor(node) {
1297
- if (_maily_to_shared.is.marked(node)) for (const mark of node.marks) {
1298
- if (!_maily_to_shared.is.link(mark)) continue;
1299
- const href = mark.attrs.href;
1300
- if (!isValid(href)) continue;
1301
- links.add(href);
1302
- }
1303
- if (_maily_to_shared.is.parent(node)) node.content.forEach(visitor);
1304
- }
1305
- visitor(json);
1306
- return links;
1442
+ //#region src/lib/normalize.ts
1443
+ function getUnwrappedBodies(content) {
1444
+ return content.flatMap((node) => {
1445
+ return _maily_to_shared.is.body(node) ? node.content : [node];
1446
+ });
1307
1447
  }
1308
- function isValid(string) {
1309
- try {
1310
- new URL(string);
1311
- return true;
1312
- } catch {
1313
- return false;
1314
- }
1448
+ function getShellBody(content) {
1449
+ const [only] = content;
1450
+ if (content.length === 1 && _maily_to_shared.is.body(only)) return only;
1451
+ const authored = content.find((node) => {
1452
+ return _maily_to_shared.is.body(node);
1453
+ });
1454
+ return {
1455
+ ...authored?.attrs ? { attrs: authored.attrs } : {},
1456
+ content: getUnwrappedBodies(content),
1457
+ type: _maily_to_shared.MAILY_NODE_TYPES.BODY
1458
+ };
1459
+ }
1460
+ function getShellContainers(body) {
1461
+ const shelled = body.content.every((node) => {
1462
+ return _maily_to_shared.is.container(node);
1463
+ });
1464
+ if (body.content.length > 0 && shelled) return body.content;
1465
+ return [{
1466
+ content: body.content,
1467
+ type: _maily_to_shared.MAILY_NODE_TYPES.CONTAINER
1468
+ }];
1469
+ }
1470
+ function getNormalizedDocument(options) {
1471
+ const { document } = options;
1472
+ const body = getShellBody(document.content ?? []);
1473
+ return {
1474
+ ...document,
1475
+ content: [{
1476
+ ...body,
1477
+ content: getShellContainers(body)
1478
+ }]
1479
+ };
1315
1480
  }
1316
1481
  //#endregion
1317
- //#region src/config.ts
1318
- const DEFAULT_VARIABLE_FORMATTER = ({ variable, fallback }) => {
1319
- return fallback ? `{{${variable}|${fallback}}}` : `{{${variable}}}`;
1320
- };
1321
- /**
1322
- * Merges user-provided MailyConfig with defaults to produce the
1323
- * internal MailyRenderConfig used throughout the render pass.
1324
- */
1325
- function buildConfig(config = {}) {
1482
+ //#region src/lib/theme.ts
1483
+ function getChildPosition(options) {
1484
+ const { index, parent } = options;
1485
+ const content = parent.content ?? [];
1326
1486
  return {
1327
- theme: {
1328
- ..._maily_to_shared.DEFAULT_RENDERER_THEME,
1329
- ...config.theme,
1330
- paragraph: {
1331
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.paragraph,
1332
- ...config.theme?.paragraph
1333
- },
1334
- heading: {
1335
- defaults: {
1336
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.heading?.defaults,
1337
- ...config.theme?.heading?.defaults
1338
- },
1339
- h1: {
1340
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.heading?.h1,
1341
- ...config.theme?.heading?.h1
1342
- },
1343
- h2: {
1344
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.heading?.h2,
1345
- ...config.theme?.heading?.h2
1346
- },
1347
- h3: {
1348
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.heading?.h3,
1349
- ...config.theme?.heading?.h3
1350
- }
1351
- },
1352
- footer: {
1353
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.footer,
1354
- ...config.theme?.footer
1355
- },
1356
- blockquote: {
1357
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.blockquote,
1358
- ...config.theme?.blockquote
1359
- },
1360
- horizontalRule: {
1361
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.horizontalRule,
1362
- ...config.theme?.horizontalRule
1363
- },
1364
- code: {
1365
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.code,
1366
- ...config.theme?.code
1367
- },
1368
- linkCard: {
1369
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.linkCard,
1370
- ...config.theme?.linkCard
1371
- },
1372
- container: {
1373
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.container,
1374
- ...config.theme?.container
1375
- },
1376
- body: {
1377
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.body,
1378
- ...config.theme?.body
1379
- },
1380
- button: {
1381
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.button,
1382
- ...config.theme?.button
1383
- },
1384
- link: {
1385
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.link,
1386
- ...config.theme?.link
1387
- },
1388
- font: config.theme?.font !== void 0 ? config.theme.font : _maily_to_shared.DEFAULT_RENDERER_THEME.font,
1389
- listMarker: {
1390
- ..._maily_to_shared.DEFAULT_RENDERER_THEME.listMarker,
1391
- ...config.theme?.listMarker
1392
- }
1393
- },
1394
- fontFamilies: config.fontFamilies ?? _maily_to_shared.DEFAULT_FONT_FAMILIES,
1395
- variableValues: new Map(Object.entries(config.variables ?? {})),
1396
- variableFormatter: config.variableFormatter ?? DEFAULT_VARIABLE_FORMATTER,
1397
- preview: config.preview,
1398
- meta: config.meta ?? [],
1399
- htmlProps: config.htmlProps ?? {},
1400
- openTrackingPixel: config.openTrackingPixel
1487
+ isFirst: index === 0,
1488
+ isLast: index === content.length - 1,
1489
+ nextType: content[index + 1]?.type,
1490
+ parentType: parent.type,
1491
+ previousType: content[index - 1]?.type
1492
+ };
1493
+ }
1494
+ function getSpacedDeclarations(options) {
1495
+ const { declarations, position } = options;
1496
+ const suppressed = (0, _maily_to_shared.getSuppressedMargins)(position);
1497
+ const spaced = { ...declarations };
1498
+ if (suppressed.marginTop) spaced.marginTop = "0";
1499
+ if (suppressed.marginBottom) spaced.marginBottom = "0";
1500
+ return spaced;
1501
+ }
1502
+ function getStyledAttrs(options) {
1503
+ const { attrs, declarations } = options;
1504
+ const authored = (0, _maily_to_shared.parseInlineStyles)(attrs?.style ?? "");
1505
+ const style = (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)(declarations, authored));
1506
+ return {
1507
+ ...attrs,
1508
+ style: style || null
1509
+ };
1510
+ }
1511
+ function getThemedMarks(options) {
1512
+ const { node, theme } = options;
1513
+ if (!_maily_to_shared.is.marked(node)) return;
1514
+ return node.marks.map((mark) => {
1515
+ const attrs = mark.attrs;
1516
+ const declarations = (0, _maily_to_shared.getThemeDeclarations)({
1517
+ attrs,
1518
+ theme,
1519
+ type: mark.type
1520
+ });
1521
+ if (!declarations) return mark;
1522
+ return {
1523
+ ...mark,
1524
+ attrs: getStyledAttrs({
1525
+ attrs,
1526
+ declarations
1527
+ })
1528
+ };
1529
+ });
1530
+ }
1531
+ function getThemedNode(options) {
1532
+ const { node, position, theme } = options;
1533
+ const attrs = node.attrs;
1534
+ const declarations = (0, _maily_to_shared.getThemeDeclarations)({
1535
+ attrs,
1536
+ theme,
1537
+ type: node.type
1538
+ });
1539
+ const content = node.content?.map((child, index) => {
1540
+ return getThemedNode({
1541
+ node: child,
1542
+ position: getChildPosition({
1543
+ index,
1544
+ parent: node
1545
+ }),
1546
+ theme
1547
+ });
1548
+ });
1549
+ const marks = getThemedMarks({
1550
+ node,
1551
+ theme
1552
+ });
1553
+ if (!declarations) {
1554
+ if (!(content || marks)) return node;
1555
+ return {
1556
+ ...node,
1557
+ ...content ? { content } : {},
1558
+ ...marks ? { marks } : {}
1559
+ };
1560
+ }
1561
+ return {
1562
+ ...node,
1563
+ ...content ? { content } : {},
1564
+ ...marks ? { marks } : {},
1565
+ attrs: getStyledAttrs({
1566
+ attrs,
1567
+ declarations: getSpacedDeclarations({
1568
+ declarations,
1569
+ position
1570
+ })
1571
+ })
1572
+ };
1573
+ }
1574
+ function getThemedDocument(options) {
1575
+ const { document, theme } = options;
1576
+ const resolved = (0, _maily_to_shared.deepMerge)(document.attrs?.theme ?? {}, theme ?? {});
1577
+ if (Object.keys(resolved).length === 0) return document;
1578
+ return {
1579
+ ...document,
1580
+ content: document.content.map((node, index) => {
1581
+ return getThemedNode({
1582
+ node,
1583
+ position: getChildPosition({
1584
+ index,
1585
+ parent: document
1586
+ }),
1587
+ theme: resolved
1588
+ });
1589
+ })
1401
1590
  };
1402
1591
  }
1403
1592
  //#endregion
1404
1593
  //#region src/render.tsx
1405
- /**
1406
- * Converts a Maily JSON document into React elements. Returns null
1407
- * if the input is not a valid Maily node.
1408
- */
1409
1594
  function markup(json, config = {}) {
1410
- const { json: migrated } = (0, _maily_to_migration.migrate)(json);
1411
- if (!_maily_to_shared.is.node(migrated)) return null;
1412
- return document(migrated, defineRenderContext({ config: buildConfig(config) }));
1595
+ (0, _maily_to_shared.invariant)(_maily_to_shared.is.doc(json), `Expected a Maily document, received "${json?.type}"`);
1596
+ return defineRenderContext({ config: buildConfig(config) }).render(getThemedDocument({
1597
+ document: getNormalizedDocument({ document: json }),
1598
+ theme: config.theme
1599
+ }));
1413
1600
  }
1414
- /** Renders a Maily JSON document to an HTML string using @react-email/render. */
1415
1601
  async function render(json, config = {}) {
1416
- if (!_maily_to_shared.is.node(json)) return "";
1417
1602
  return (0, _react_email_render.render)(markup(json, config));
1418
1603
  }
1604
+ async function renderText(json, config = {}) {
1605
+ return (0, _react_email_render.render)(markup(json, config), { plainText: true });
1606
+ }
1419
1607
  //#endregion
1420
1608
  exports.buildConfig = buildConfig;
1421
1609
  exports.children = children;
1422
1610
  exports.defineRenderContext = defineRenderContext;
1423
1611
  exports.dispatch = dispatch;
1612
+ exports.getSafeHref = getSafeHref;
1424
1613
  exports.links = links;
1614
+ exports.marks = marks;
1425
1615
  exports.markup = markup;
1426
1616
  exports.render = render;
1617
+ exports.renderText = renderText;
1427
1618
 
1428
1619
  //# sourceMappingURL=index.cjs.map