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