@maily-to/render 0.2.3 → 2.0.0-beta.6

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 ADDED
@@ -0,0 +1,1428 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let _maily_to_shared = require("@maily-to/shared");
25
+ let react = require("react");
26
+ let react_jsx_runtime = require("react/jsx-runtime");
27
+ let _react_email_components = require("@react-email/components");
28
+ let juice = require("juice");
29
+ juice = __toESM(juice);
30
+ let node_html_parser = require("node-html-parser");
31
+ let _maily_to_migration = require("@maily-to/migration");
32
+ 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
+ })
147
+ });
148
+ };
149
+ //#endregion
150
+ //#region src/lib/resolve-variable.ts
151
+ /**
152
+ * Resolves a single variable ID using the 3-stage lookup:
153
+ * 1. item (current repeat iteration)
154
+ * 2. variableValues map
155
+ * 3. variableFormatter (fallback)
156
+ */
157
+ function resolveVariableId(id, fallback, ctx) {
158
+ const { config } = ctx;
159
+ const item = ctx.get("item");
160
+ 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
+ }
166
+ return config.variableFormatter({
167
+ variable: id,
168
+ fallback: fallback ?? void 0
169
+ });
170
+ }
171
+ /**
172
+ * Resolves a text string that may contain `{{variable}}` placeholders.
173
+ * Returns the original string unchanged if no placeholders are present.
174
+ */
175
+ function resolveVariableText(text, ctx) {
176
+ if (!(0, _maily_to_shared.hasVariableInText)(text)) return text;
177
+ const paragraph = (0, _maily_to_shared.buildDocFromVariableText)(text).content.find((node) => node.type === _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH);
178
+ if (!paragraph) return text;
179
+ return paragraph.content.map((node) => {
180
+ if (node.type === _maily_to_shared.MAILY_NODE_TYPES.TEXT) return node.text;
181
+ 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);
185
+ }
186
+ return "";
187
+ }).join("");
188
+ }
189
+ //#endregion
190
+ //#region src/lib/visibility.ts
191
+ /**
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".
195
+ */
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;
208
+ }
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;
222
+ }
223
+ }
224
+ //#endregion
225
+ //#region src/nodes/button.tsx
226
+ const button = (node, ctx) => {
227
+ 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,
259
+ style: {
260
+ backgroundColor,
261
+ paddingTop,
262
+ paddingRight,
263
+ paddingBottom,
264
+ paddingLeft,
265
+ ...borderStyle,
266
+ ...(0, _maily_to_shared.getCssDirection)(dir)
267
+ },
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,
285
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Button, {
286
+ href: url,
287
+ style: {
288
+ backgroundColor,
289
+ color,
290
+ paddingTop,
291
+ paddingRight,
292
+ paddingBottom,
293
+ paddingLeft,
294
+ display: "inline-block",
295
+ ...borderStyle,
296
+ ...(0, _maily_to_shared.getCssDirection)(dir),
297
+ ...fontStyle
298
+ },
299
+ children: ctx.children(node)
300
+ })
301
+ });
302
+ };
303
+ //#endregion
304
+ //#region src/nodes/column.tsx
305
+ const column = (node, ctx) => {
306
+ 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}%`);
309
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
310
+ width,
311
+ className: "tab-col-full",
312
+ style: {
313
+ margin: 0,
314
+ width,
315
+ verticalAlign: attrs.verticalAlign
316
+ },
317
+ children: ctx.children(node)
318
+ });
319
+ };
320
+ //#endregion
321
+ //#region src/lib/columns.ts
322
+ /**
323
+ * Simulates CSS `flexbox gap` using table-cell percentages.
324
+ *
325
+ * Since tables don't support `gap`, we create empty spacer `<td>` cells
326
+ * between columns. This function calculates how wide each column and
327
+ * spacer should be so the layout behaves similar to flexbox.
328
+ *
329
+ * How the gap affects the layout depends on the column configuration:
330
+ *
331
+ * 1. When there are auto-width columns
332
+ * The row always fills 100% of the container.
333
+ * Fixed columns keep their exact width, and auto columns divide
334
+ * the remaining space after subtracting fixed widths and gaps.
335
+ *
336
+ * Example:
337
+ * fixed 40% + auto column, gap 8px in a 600px container
338
+ * → auto column becomes ~58.667%
339
+ *
340
+ * 2. When all columns have fixed widths and still fit
341
+ * The row width becomes `fixed widths + gaps`, which may be
342
+ * smaller than 100%. Columns keep their exact size.
343
+ *
344
+ * Example:
345
+ * 20% + 20% columns, gap 8px in a 600px container
346
+ * → row width becomes ~41.333%
347
+ *
348
+ * 3. When all columns are fixed but overflow
349
+ * If `fixed widths + gaps` exceed 100%, everything is scaled
350
+ * down proportionally so the row never exceeds the container.
351
+ *
352
+ * Example:
353
+ * 50% + 50% columns with gap 8px
354
+ * → both columns shrink to ~49.342%
355
+ */
356
+ function calculateColumnLayout(columnNodes, gap, containerBox) {
357
+ const count = columnNodes.length;
358
+ if (count === 0) return {
359
+ columns: [],
360
+ rowWidthPercent: 0,
361
+ gapTdWidthPercent: 0
362
+ };
363
+ const gapCount = count - 1;
364
+ const gapPercent = gapCount > 0 && containerBox > 0 ? (0, _maily_to_shared.roundTo)(gap / containerBox * 100, 3) : 0;
365
+ 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;
368
+ 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);
370
+ let rowWidthPercent = autoCount > 0 ? 100 : (0, _maily_to_shared.roundTo)(fixedSum + totalGapPercent, 3);
371
+ let effectiveGapPercent = gapPercent;
372
+ if (autoCount === 0 && rowWidthPercent > 100) {
373
+ const scale = 100 / rowWidthPercent;
374
+ containerPercents = containerPercents.map((p) => (0, _maily_to_shared.roundTo)(p * scale, 3));
375
+ effectiveGapPercent = (0, _maily_to_shared.roundTo)(gapPercent * scale, 3);
376
+ rowWidthPercent = 100;
377
+ }
378
+ const gapTdWidthPercent = rowWidthPercent > 0 ? (0, _maily_to_shared.roundTo)(effectiveGapPercent / rowWidthPercent * 100, 3) : 0;
379
+ 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
397
+ };
398
+ }
399
+ //#endregion
400
+ //#region src/nodes/columns.tsx
401
+ const COLUMNS_RESPONSIVE_CSS = `@media only screen and (max-width:425px){.tab-row-full{width:100%!important}.tab-col-full{display:block!important;width:100%!important}.tab-gap{display:none!important}}`;
402
+ const columns = (node, ctx) => {
403
+ if (!_maily_to_shared.is.columns(node)) return null;
404
+ 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);
407
+ if (columns.length === 0) return null;
408
+ 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, {
433
+ className: "tab-gap",
434
+ width: gapWidth,
435
+ style: { width: gapWidth }
436
+ }, gapKey)];
437
+ }
438
+ return [colEl];
439
+ })
440
+ }) });
441
+ };
442
+ //#endregion
443
+ //#region src/lib/meta.tsx
444
+ /**
445
+ * Deduplication key for a meta descriptor. Uses a sorted-key JSON hash
446
+ * so `{ name: 'a', content: 'b' }` and `{ content: 'b', name: 'a' }`
447
+ * produce the same key.
448
+ */
449
+ function hash(descriptor) {
450
+ const sorted = Object.keys(descriptor).sort().reduce((acc, key) => {
451
+ acc[key] = descriptor[key];
452
+ return acc;
453
+ }, {});
454
+ return JSON.stringify(sorted);
455
+ }
456
+ /**
457
+ * Converts MetaDescriptor objects into React elements for the `<head>`.
458
+ * Duplicates (by sorted-key JSON hash) are skipped.
459
+ */
460
+ function meta(descriptors) {
461
+ const seen = /* @__PURE__ */ new Set();
462
+ const elements = [];
463
+ for (const descriptor of descriptors) {
464
+ const key = hash(descriptor);
465
+ if (seen.has(key)) continue;
466
+ seen.add(key);
467
+ const element = process(descriptor, key);
468
+ if (element) elements.push(element);
469
+ }
470
+ return elements;
471
+ }
472
+ function process(descriptor, key) {
473
+ if ("charSet" in descriptor) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { charSet: descriptor.charSet }, key);
474
+ if ("title" in descriptor) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("title", { children: descriptor.title }, key);
475
+ if ("tagName" in descriptor) {
476
+ const { tagName, ...attrs } = descriptor;
477
+ if (tagName === "link") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("link", { ...attrs }, key);
478
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { ...attrs }, key);
479
+ }
480
+ const attrs = descriptor;
481
+ if ("httpEquiv" in attrs) {
482
+ const { httpEquiv, ...rest } = attrs;
483
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
484
+ httpEquiv,
485
+ ...rest
486
+ }, key);
487
+ }
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
+ };
556
+ }
557
+ //#endregion
558
+ //#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
+ const document = (node, ctx) => {
561
+ 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
572
+ });
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;
583
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Html, {
584
+ lang: "en",
585
+ ...htmlProps,
586
+ ...dir && dir !== _maily_to_shared.TEXT_DIRECTIONS.AUTO ? { dir } : {},
587
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Head, { children: [
588
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
589
+ httpEquiv: "X-UA-Compatible",
590
+ content: "IE=edge"
591
+ }),
592
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", { name: "x-apple-disable-message-reformatting" }),
593
+ /* @__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"
600
+ }),
601
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
602
+ name: "supported-color-schemes",
603
+ content: "light"
604
+ }),
605
+ meta(meta$1),
606
+ /* @__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
+ })]
620
+ });
621
+ };
622
+ //#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
+ //#region src/nodes/footer.tsx
634
+ const footer = (node, ctx) => {
635
+ 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, {
641
+ 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
+ ...ANTIALIASED,
648
+ ...fontStyle
649
+ },
650
+ children: ctx.children(node)
651
+ });
652
+ };
653
+ //#endregion
654
+ //#region src/nodes/hard-break.tsx
655
+ const hardBreak = () => {
656
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("br", {});
657
+ };
658
+ //#endregion
659
+ //#region src/nodes/heading.tsx
660
+ const HEADING_LEVELS = {
661
+ 1: "h1",
662
+ 2: "h2",
663
+ 3: "h3"
664
+ };
665
+ const heading = (node, ctx) => {
666
+ 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
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Heading, {
675
+ as: element,
676
+ 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
683
+ },
684
+ children: ctx.children(node)
685
+ });
686
+ };
687
+ //#endregion
688
+ //#region src/nodes/horizontal-rule.tsx
689
+ const horizontalRule = (node, ctx) => {
690
+ 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
+ } });
697
+ };
698
+ //#endregion
699
+ //#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);
706
+ }
707
+ if (node.content && Array.isArray(node.content)) return node.content.map((child) => resolveText(child, ctx)).join("");
708
+ return "";
709
+ }
710
+ const htmlCodeBlock = (node, ctx) => {
711
+ 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();
715
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
716
+ align: "left",
717
+ width: "100%",
718
+ border: 0,
719
+ cellPadding: "0",
720
+ cellSpacing: "0",
721
+ role: "presentation",
722
+ style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32 },
723
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
724
+ style: { width: "100%" },
725
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
726
+ style: { width: "100%" },
727
+ dangerouslySetInnerHTML: { __html: html }
728
+ })
729
+ }) })
730
+ });
731
+ };
732
+ //#endregion
733
+ //#region src/nodes/image.tsx
734
+ const image = (node, ctx) => {
735
+ if (!_maily_to_shared.is.image(node)) return null;
736
+ const { src, alt, title, width, align, externalLink } = node.attrs;
737
+ const resolvedSrc = resolveVariableText(src, ctx);
738
+ const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
739
+ const percent = (0, _maily_to_shared.parseWidthToPercentage)(width, ctx.box);
740
+ const absoluteWidth = Math.round(ctx.box * percent / 100);
741
+ const img = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
742
+ src: resolvedSrc,
743
+ alt,
744
+ title,
745
+ width: absoluteWidth,
746
+ style: {
747
+ width: width ?? "100%",
748
+ maxWidth: absoluteWidth,
749
+ height: "auto",
750
+ 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
+ })
767
+ });
768
+ };
769
+ //#endregion
770
+ //#region src/nodes/inline-image.tsx
771
+ const inlineImage = (node, ctx) => {
772
+ if (!_maily_to_shared.is.inlineImage(node)) return null;
773
+ const { src, alt, width, height, externalLink } = node.attrs;
774
+ const resolvedSrc = resolveVariableText(src, ctx);
775
+ const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
776
+ const img = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
777
+ src: resolvedSrc,
778
+ alt: alt ?? "",
779
+ width,
780
+ height,
781
+ style: {
782
+ display: "inline",
783
+ verticalAlign: "middle",
784
+ width,
785
+ height,
786
+ outline: "none",
787
+ border: "none",
788
+ textDecoration: "none"
789
+ }
790
+ });
791
+ if (resolvedExternalLink) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
792
+ href: resolvedExternalLink,
793
+ target: "_blank",
794
+ rel: "noopener noreferrer nofollow",
795
+ style: {
796
+ display: "inline",
797
+ textDecoration: "none"
798
+ },
799
+ children: img
800
+ });
801
+ return img;
802
+ };
803
+ //#endregion
804
+ //#region src/nodes/link-card.tsx
805
+ const linkCard = (node, ctx) => {
806
+ 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) : "") || "#";
811
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
812
+ href,
813
+ rel: "noopener noreferrer",
814
+ style: {
815
+ border: `1px solid ${theme?.borderColor ?? "#eaeaea"}`,
816
+ borderRadius: 10,
817
+ textDecoration: "none",
818
+ color: "inherit",
819
+ display: "block",
820
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20
821
+ },
822
+ target: "_blank",
823
+ children: [image ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
824
+ style: { marginBottom: 6 },
825
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
826
+ style: {
827
+ width: "100%",
828
+ height: "100%"
829
+ },
830
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Img, {
831
+ alt: title || "Link Card",
832
+ src: image,
833
+ style: {
834
+ borderRadius: "10px 10px 0 0",
835
+ width: "100%",
836
+ height: "100%",
837
+ objectFit: "cover"
838
+ },
839
+ title: title || "Link Card"
840
+ })
841
+ })
842
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
843
+ style: {
844
+ padding: 15,
845
+ marginTop: 0,
846
+ marginBottom: 0
847
+ },
848
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Column, {
849
+ style: { verticalAlign: "top" },
850
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
851
+ style: {
852
+ marginBottom: 8,
853
+ marginTop: 0
854
+ },
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, {
858
+ style: {
859
+ fontSize: 18,
860
+ fontWeight: 600,
861
+ color: theme?.titleColor ?? "#111827",
862
+ margin: 0,
863
+ textAlign: "left",
864
+ ...ANTIALIASED
865
+ },
866
+ children: [
867
+ title,
868
+ badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
869
+ style: {
870
+ fontWeight: 600,
871
+ color: theme?.badgeTextColor ?? "#6B7280",
872
+ padding: "4px 8px",
873
+ borderRadius: "8px",
874
+ backgroundColor: theme?.badgeBackgroundColor ?? "#F3F4F6",
875
+ fontSize: "12px",
876
+ lineHeight: "12px",
877
+ marginLeft: "6px"
878
+ },
879
+ children: badgeText
880
+ }),
881
+ subTitle && !badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
882
+ style: {
883
+ fontWeight: "normal",
884
+ color: theme?.subTitleColor ?? "#6B7280",
885
+ fontSize: 12,
886
+ lineHeight: "12px",
887
+ marginLeft: "6px"
888
+ },
889
+ children: subTitle
890
+ })
891
+ ]
892
+ }) })
893
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_react_email_components.Text, {
894
+ style: {
895
+ fontSize: 16,
896
+ color: theme?.descriptionColor ?? "#374151",
897
+ marginTop: 0,
898
+ marginBottom: 0
899
+ },
900
+ children: [
901
+ description,
902
+ " ",
903
+ linkTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
904
+ href,
905
+ rel: "noopener noreferrer",
906
+ style: {
907
+ color: theme?.titleColor ?? "#111827",
908
+ fontSize: 14,
909
+ fontWeight: 600,
910
+ textDecoration: "underline"
911
+ },
912
+ children: linkTitle
913
+ }) : null
914
+ ]
915
+ })]
916
+ })
917
+ })]
918
+ });
919
+ };
920
+ //#endregion
921
+ //#region src/nodes/list-item.tsx
922
+ const listItem = (node, ctx) => {
923
+ if (!_maily_to_shared.is.listItem(node)) return null;
924
+ const { dir } = node.attrs;
925
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
926
+ style: {
927
+ color: ctx.config.theme.listMarker?.color,
928
+ marginBottom: 8,
929
+ marginTop: 8,
930
+ paddingLeft: 6,
931
+ ...ANTIALIASED,
932
+ ...(0, _maily_to_shared.getCssDirection)(dir)
933
+ },
934
+ children: ctx.children(node)
935
+ });
936
+ };
937
+ //#endregion
938
+ //#region src/nodes/ordered-list.tsx
939
+ const orderedList = (node, ctx) => {
940
+ 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
+ })
953
+ });
954
+ };
955
+ //#endregion
956
+ //#region src/nodes/paragraph.tsx
957
+ const paragraph = (node, ctx) => {
958
+ 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, {
964
+ 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
972
+ },
973
+ children: ctx.children(node)
974
+ });
975
+ };
976
+ //#endregion
977
+ //#region src/nodes/repeat.tsx
978
+ const repeat = (node, ctx) => {
979
+ if (!_maily_to_shared.is.repeat(node)) return null;
980
+ 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) });
983
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: payload.map((item, index) => {
984
+ const childContext = ctx.child({
985
+ parent: node,
986
+ siblingIndex: index
987
+ });
988
+ childContext.set("item", (0, _maily_to_shared.isObject)(item) ? item : { value: item });
989
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: childContext.children(node) }, index);
990
+ }) });
991
+ };
992
+ //#endregion
993
+ //#region src/nodes/section.tsx
994
+ const section = (node, ctx) => {
995
+ 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
+ })
1018
+ });
1019
+ };
1020
+ //#endregion
1021
+ //#region src/nodes/spacer.tsx
1022
+ const spacer = (node) => {
1023
+ 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` } });
1026
+ };
1027
+ //#endregion
1028
+ //#region src/marks/bold.tsx
1029
+ const bold = (_mark, text, _ctx) => {
1030
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: text });
1031
+ };
1032
+ //#endregion
1033
+ //#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;
1037
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1038
+ 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
1046
+ },
1047
+ children: text
1048
+ });
1049
+ };
1050
+ //#endregion
1051
+ //#region src/marks/italic.tsx
1052
+ const italic = (_mark, text, _ctx) => {
1053
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("em", { children: text });
1054
+ };
1055
+ //#endregion
1056
+ //#region src/marks/link.tsx
1057
+ const link = (mark, text, ctx) => {
1058
+ 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;
1063
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
1064
+ href,
1065
+ target: "_blank",
1066
+ rel: "noopener noreferrer nofollow",
1067
+ style: color ? { color } : void 0,
1068
+ children: text
1069
+ });
1070
+ };
1071
+ //#endregion
1072
+ //#region src/marks/strike.tsx
1073
+ const strike = (_mark, text, _ctx) => {
1074
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("s", { children: text });
1075
+ };
1076
+ //#endregion
1077
+ //#region src/marks/underline.tsx
1078
+ const underline = (_mark, text, _ctx) => {
1079
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("u", { children: text });
1080
+ };
1081
+ //#endregion
1082
+ //#region src/mark.tsx
1083
+ const MAILY_MARKS_ORDER = [
1084
+ _maily_to_shared.MAILY_MARK_TYPES.UNDERLINE,
1085
+ _maily_to_shared.MAILY_MARK_TYPES.BOLD,
1086
+ _maily_to_shared.MAILY_MARK_TYPES.ITALIC,
1087
+ _maily_to_shared.MAILY_MARK_TYPES.STRIKE,
1088
+ _maily_to_shared.MAILY_MARK_TYPES.LINK,
1089
+ _maily_to_shared.MAILY_MARK_TYPES.CODE
1090
+ ];
1091
+ const MAILY_MARK_RENDERERS = {
1092
+ [_maily_to_shared.MAILY_MARK_TYPES.UNDERLINE]: underline,
1093
+ [_maily_to_shared.MAILY_MARK_TYPES.BOLD]: bold,
1094
+ [_maily_to_shared.MAILY_MARK_TYPES.ITALIC]: italic,
1095
+ [_maily_to_shared.MAILY_MARK_TYPES.STRIKE]: strike,
1096
+ [_maily_to_shared.MAILY_MARK_TYPES.LINK]: link,
1097
+ [_maily_to_shared.MAILY_MARK_TYPES.CODE]: code
1098
+ };
1099
+ function render$1(mark, text, ctx) {
1100
+ if (!_maily_to_shared.is.mark(mark)) return null;
1101
+ const renderer = MAILY_MARK_RENDERERS[mark.type];
1102
+ if (!renderer) return null;
1103
+ return renderer(mark, text, ctx);
1104
+ }
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
+ function marks(node, ctx) {
1110
+ 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;
1115
+ return acc;
1116
+ }, {});
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
+ });
1120
+ const text = node?.text || /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: "\xA0" });
1121
+ const baseText = isEmptyObject(textStyles) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: text }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1122
+ style: textStyles,
1123
+ children: text
1124
+ });
1125
+ return marks.reduce((acc, mark, index) => {
1126
+ const component = render$1(mark, acc, ctx.child({
1127
+ parent: node,
1128
+ siblingIndex: index
1129
+ }));
1130
+ if (!component) return acc;
1131
+ return component;
1132
+ }, baseText);
1133
+ }
1134
+ function isEmptyObject(obj) {
1135
+ for (const _ in obj) return false;
1136
+ return true;
1137
+ }
1138
+ //#endregion
1139
+ //#region src/nodes/text.tsx
1140
+ const text = (node, ctx) => {
1141
+ if (!_maily_to_shared.is.text(node)) return null;
1142
+ if (_maily_to_shared.is.marked(node)) return marks(node, ctx);
1143
+ const { text } = node;
1144
+ if (!(0, _maily_to_shared.isDef)(text)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: "\xA0" });
1145
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: text });
1146
+ };
1147
+ //#endregion
1148
+ //#region src/nodes/variable.tsx
1149
+ const variable = (node, ctx) => {
1150
+ if (!_maily_to_shared.is.variable(node)) return null;
1151
+ const { id, fallback } = node.attrs;
1152
+ if (!id) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback ?? "" });
1153
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: resolveVariableId(id, fallback, ctx) });
1154
+ };
1155
+ //#endregion
1156
+ //#region src/node.tsx
1157
+ const MAILY_NODE_RENDERERS = {
1158
+ [_maily_to_shared.MAILY_NODE_TYPES.DOCUMENT]: document,
1159
+ [_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH]: paragraph,
1160
+ [_maily_to_shared.MAILY_NODE_TYPES.TEXT]: text,
1161
+ [_maily_to_shared.MAILY_NODE_TYPES.HEADING]: heading,
1162
+ [_maily_to_shared.MAILY_NODE_TYPES.VARIABLE]: variable,
1163
+ [_maily_to_shared.MAILY_NODE_TYPES.IMAGE]: image,
1164
+ [_maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE]: inlineImage,
1165
+ [_maily_to_shared.MAILY_NODE_TYPES.SPACER]: spacer,
1166
+ [_maily_to_shared.MAILY_NODE_TYPES.SECTION]: section,
1167
+ [_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,
1174
+ [_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE]: horizontalRule,
1175
+ [_maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK]: htmlCodeBlock,
1176
+ [_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE]: blockquote,
1177
+ [_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
1180
+ };
1181
+ function dispatch(node, ctx) {
1182
+ if (!_maily_to_shared.is.node(node)) return null;
1183
+ const renderer = MAILY_NODE_RENDERERS[node.type];
1184
+ if (!renderer) return null;
1185
+ return renderer(node, ctx);
1186
+ }
1187
+ function children(parent, ctx) {
1188
+ if (!_maily_to_shared.is.parent(parent)) return [];
1189
+ return parent.content.map((child, index) => {
1190
+ const component = ctx.child({
1191
+ parent,
1192
+ siblingIndex: index
1193
+ }).render(child);
1194
+ if (!component) return null;
1195
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: component }, index);
1196
+ }).filter(Boolean);
1197
+ }
1198
+ //#endregion
1199
+ //#region src/context.ts
1200
+ const DEFAULT_SIZE = {
1201
+ totalWidth: 600,
1202
+ totalBorder: 0,
1203
+ totalPadding: 0
1204
+ };
1205
+ /**
1206
+ * Creates the root RenderContext for a render pass. Node renderers
1207
+ * derive child contexts via `ctx.child()` as they descend the tree.
1208
+ */
1209
+ function defineRenderContext(opts) {
1210
+ const shared = {
1211
+ vars: /* @__PURE__ */ new Map(),
1212
+ styles: /* @__PURE__ */ new Set(),
1213
+ fonts: /* @__PURE__ */ new Map()
1214
+ };
1215
+ const size = {
1216
+ ...DEFAULT_SIZE,
1217
+ ...opts.size
1218
+ };
1219
+ return defineContext({
1220
+ config: opts.config,
1221
+ parent: opts.parent,
1222
+ siblingIndex: opts.siblingIndex ?? 0,
1223
+ size
1224
+ }, shared);
1225
+ }
1226
+ function defineContext(opts, shared) {
1227
+ const { config, parent, siblingIndex, size } = opts;
1228
+ const { vars, styles, fonts } = shared;
1229
+ let varCache = null;
1230
+ const ctx = {
1231
+ parent,
1232
+ siblingIndex,
1233
+ config,
1234
+ size,
1235
+ get box() {
1236
+ return size.totalWidth - size.totalBorder - size.totalPadding;
1237
+ },
1238
+ render(node) {
1239
+ return dispatch(node, ctx);
1240
+ },
1241
+ children(parent) {
1242
+ return children(parent, ctx);
1243
+ },
1244
+ set(key, value) {
1245
+ vars.set(key, value);
1246
+ varCache = null;
1247
+ },
1248
+ get(key) {
1249
+ return vars.get(key);
1250
+ },
1251
+ get var() {
1252
+ return varCache ??= Object.fromEntries(vars);
1253
+ },
1254
+ style(css) {
1255
+ styles.add(css);
1256
+ },
1257
+ font(name, props) {
1258
+ fonts.set(name, props);
1259
+ },
1260
+ child(opts) {
1261
+ const childSize = opts.size ? {
1262
+ totalWidth: opts.size.totalWidth ?? size.totalWidth,
1263
+ totalBorder: opts.size.totalBorder ?? size.totalBorder,
1264
+ totalPadding: opts.size.totalPadding ?? size.totalPadding
1265
+ } : size;
1266
+ const childShared = {
1267
+ vars: new Map(vars),
1268
+ styles,
1269
+ fonts
1270
+ };
1271
+ return defineContext({
1272
+ config,
1273
+ parent: opts.parent ?? parent,
1274
+ siblingIndex: opts.siblingIndex ?? siblingIndex,
1275
+ size: childSize
1276
+ }, childShared);
1277
+ },
1278
+ get styles() {
1279
+ return styles;
1280
+ },
1281
+ get fonts() {
1282
+ return fonts;
1283
+ }
1284
+ };
1285
+ return ctx;
1286
+ }
1287
+ //#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;
1307
+ }
1308
+ function isValid(string) {
1309
+ try {
1310
+ new URL(string);
1311
+ return true;
1312
+ } catch {
1313
+ return false;
1314
+ }
1315
+ }
1316
+ //#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 = {}) {
1326
+ 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
1401
+ };
1402
+ }
1403
+ //#endregion
1404
+ //#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
+ 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) }));
1413
+ }
1414
+ /** Renders a Maily JSON document to an HTML string using @react-email/render. */
1415
+ async function render(json, config = {}) {
1416
+ if (!_maily_to_shared.is.node(json)) return "";
1417
+ return (0, _react_email_render.render)(markup(json, config));
1418
+ }
1419
+ //#endregion
1420
+ exports.buildConfig = buildConfig;
1421
+ exports.children = children;
1422
+ exports.defineRenderContext = defineRenderContext;
1423
+ exports.dispatch = dispatch;
1424
+ exports.links = links;
1425
+ exports.markup = markup;
1426
+ exports.render = render;
1427
+
1428
+ //# sourceMappingURL=index.cjs.map