@react-email/render 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.mts +33 -27
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +33 -27
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +150 -207
- package/dist/browser/index.mjs +126 -178
- package/dist/browser/index.mjs.map +1 -0
- package/dist/edge/index.d.mts +33 -27
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +33 -27
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +154 -216
- package/dist/edge/index.mjs +130 -187
- package/dist/edge/index.mjs.map +1 -0
- package/dist/node/index.d.mts +33 -27
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +33 -27
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +157 -222
- package/dist/node/index.mjs +132 -193
- package/dist/node/index.mjs.map +1 -0
- package/package.json +13 -4
- package/readme.md +3 -4
package/dist/node/index.js
CHANGED
|
@@ -1,245 +1,180 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __export = (target, all) => {
|
|
26
|
-
for (var name in all)
|
|
27
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
-
};
|
|
29
8
|
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
36
17
|
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __async = (__this, __arguments, generator) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
var fulfilled = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
step(generator.next(value));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var rejected = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.throw(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/node/index.ts
|
|
68
|
-
var index_exports = {};
|
|
69
|
-
__export(index_exports, {
|
|
70
|
-
plainTextSelectors: () => plainTextSelectors,
|
|
71
|
-
pretty: () => pretty,
|
|
72
|
-
render: () => render,
|
|
73
|
-
renderAsync: () => renderAsync,
|
|
74
|
-
toPlainText: () => toPlainText
|
|
75
|
-
});
|
|
76
|
-
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
77
22
|
|
|
78
|
-
|
|
79
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
let react = require("react");
|
|
25
|
+
react = __toESM(react);
|
|
26
|
+
let prettier_plugins_html = require("prettier/plugins/html");
|
|
27
|
+
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
28
|
+
let prettier_standalone = require("prettier/standalone");
|
|
29
|
+
prettier_standalone = __toESM(prettier_standalone);
|
|
30
|
+
let html_to_text = require("html-to-text");
|
|
31
|
+
html_to_text = __toESM(html_to_text);
|
|
32
|
+
let node_stream = require("node:stream");
|
|
33
|
+
node_stream = __toESM(node_stream);
|
|
34
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
80
36
|
|
|
81
|
-
|
|
82
|
-
var html = __toESM(require("prettier/plugins/html"));
|
|
83
|
-
var import_standalone = require("prettier/standalone");
|
|
37
|
+
//#region src/shared/utils/pretty.ts
|
|
84
38
|
function recursivelyMapDoc(doc, callback) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
if (doc.type === "if-break") {
|
|
109
|
-
return __spreadProps(__spreadValues({}, doc), {
|
|
110
|
-
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
111
|
-
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return callback(doc);
|
|
39
|
+
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
40
|
+
if (typeof doc === "object") {
|
|
41
|
+
if (doc.type === "group") return {
|
|
42
|
+
...doc,
|
|
43
|
+
contents: recursivelyMapDoc(doc.contents, callback),
|
|
44
|
+
expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
|
|
45
|
+
};
|
|
46
|
+
if ("contents" in doc) return {
|
|
47
|
+
...doc,
|
|
48
|
+
contents: recursivelyMapDoc(doc.contents, callback)
|
|
49
|
+
};
|
|
50
|
+
if ("parts" in doc) return {
|
|
51
|
+
...doc,
|
|
52
|
+
parts: recursivelyMapDoc(doc.parts, callback)
|
|
53
|
+
};
|
|
54
|
+
if (doc.type === "if-break") return {
|
|
55
|
+
...doc,
|
|
56
|
+
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
57
|
+
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return callback(doc);
|
|
116
61
|
}
|
|
117
|
-
|
|
62
|
+
const modifiedHtml = { ...prettier_plugins_html };
|
|
118
63
|
if (modifiedHtml.printers) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
return printingResult;
|
|
131
|
-
}
|
|
132
|
-
return rawPrintingResult;
|
|
133
|
-
};
|
|
64
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
65
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
66
|
+
const node = path.getNode();
|
|
67
|
+
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
68
|
+
if (node.type === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
69
|
+
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
70
|
+
return doc;
|
|
71
|
+
});
|
|
72
|
+
return rawPrintingResult;
|
|
73
|
+
};
|
|
134
74
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
75
|
+
const defaults = {
|
|
76
|
+
endOfLine: "lf",
|
|
77
|
+
tabWidth: 2,
|
|
78
|
+
plugins: [modifiedHtml],
|
|
79
|
+
bracketSameLine: true,
|
|
80
|
+
parser: "html"
|
|
141
81
|
};
|
|
142
|
-
|
|
143
|
-
|
|
82
|
+
const pretty = (str, options = {}) => {
|
|
83
|
+
return (0, prettier_standalone.format)(str.replaceAll("\0", ""), {
|
|
84
|
+
...defaults,
|
|
85
|
+
...options
|
|
86
|
+
});
|
|
144
87
|
};
|
|
145
88
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/shared/utils/to-plain-text.ts
|
|
91
|
+
const plainTextSelectors = [
|
|
92
|
+
{
|
|
93
|
+
selector: "img",
|
|
94
|
+
format: "skip"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
selector: "[data-skip-in-text=true]",
|
|
98
|
+
format: "skip"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
selector: "a",
|
|
102
|
+
options: {
|
|
103
|
+
linkBrackets: false,
|
|
104
|
+
hideLinkHrefIfSameAsText: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
155
107
|
];
|
|
156
|
-
function toPlainText(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
108
|
+
function toPlainText(html, options) {
|
|
109
|
+
return (0, html_to_text.convert)(html, {
|
|
110
|
+
selectors: plainTextSelectors,
|
|
111
|
+
...options
|
|
112
|
+
});
|
|
160
113
|
}
|
|
161
114
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
190
|
-
});
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/node/read-stream.ts
|
|
117
|
+
const decoder = new TextDecoder("utf-8");
|
|
118
|
+
const readStream = async (stream) => {
|
|
119
|
+
let result = "";
|
|
120
|
+
if ("pipeTo" in stream) {
|
|
121
|
+
const writableStream = new WritableStream({ write(chunk) {
|
|
122
|
+
result += decoder.decode(chunk);
|
|
123
|
+
} });
|
|
124
|
+
await stream.pipeTo(writableStream);
|
|
125
|
+
} else {
|
|
126
|
+
const writable = new node_stream.Writable({ write(chunk, _encoding, callback) {
|
|
127
|
+
result += decoder.decode(chunk);
|
|
128
|
+
callback();
|
|
129
|
+
} });
|
|
130
|
+
stream.pipe(writable);
|
|
131
|
+
await new Promise((resolve, reject) => {
|
|
132
|
+
writable.on("error", reject);
|
|
133
|
+
writable.on("close", () => {
|
|
134
|
+
resolve();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
191
140
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
onError(error) {
|
|
217
|
-
reject(error);
|
|
218
|
-
},
|
|
219
|
-
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (options == null ? void 0 : options.plainText) {
|
|
224
|
-
return toPlainText(html2, options.htmlToTextOptions);
|
|
225
|
-
}
|
|
226
|
-
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
227
|
-
const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
228
|
-
if (options == null ? void 0 : options.pretty) {
|
|
229
|
-
return pretty(document);
|
|
230
|
-
}
|
|
231
|
-
return document;
|
|
232
|
-
});
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/node/render.tsx
|
|
143
|
+
const render = async (node, options) => {
|
|
144
|
+
const suspendedElement = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: node });
|
|
145
|
+
const reactDOMServer = await import("react-dom/server").then((m) => m.default);
|
|
146
|
+
let html;
|
|
147
|
+
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) html = await readStream(await reactDOMServer.renderToReadableStream(suspendedElement, { progressiveChunkSize: Number.POSITIVE_INFINITY }));
|
|
148
|
+
else await new Promise((resolve, reject) => {
|
|
149
|
+
const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
|
|
150
|
+
async onAllReady() {
|
|
151
|
+
html = await readStream(stream);
|
|
152
|
+
resolve();
|
|
153
|
+
},
|
|
154
|
+
onError(error) {
|
|
155
|
+
reject(error);
|
|
156
|
+
},
|
|
157
|
+
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
|
|
161
|
+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
162
|
+
if (options?.pretty) return pretty(document);
|
|
163
|
+
return document;
|
|
164
|
+
};
|
|
233
165
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/node/index.ts
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated use {@link render}
|
|
170
|
+
*/
|
|
171
|
+
const renderAsync = (element, options) => {
|
|
172
|
+
return render(element, options);
|
|
237
173
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
exports.plainTextSelectors = plainTextSelectors;
|
|
177
|
+
exports.pretty = pretty;
|
|
178
|
+
exports.render = render;
|
|
179
|
+
exports.renderAsync = renderAsync;
|
|
180
|
+
exports.toPlainText = toPlainText;
|