@maily-to/render 2.0.0-beta.1 → 2.0.0-beta.10

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