@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.
@@ -1,245 +1,180 @@
1
- "use strict";
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
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
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
- // If the importer is in node compatibility mode or this is not an ESM
39
- // file that has been converted to a CommonJS file using a Babel-
40
- // compatible transform (i.e. "__esModule" has not been set), then set
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
- // src/node/render.tsx
79
- var import_react = require("react");
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
- // src/shared/utils/pretty.ts
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
- if (Array.isArray(doc)) {
86
- return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
87
- }
88
- if (typeof doc === "object") {
89
- if (doc.type === "group") {
90
- return __spreadProps(__spreadValues({}, doc), {
91
- contents: recursivelyMapDoc(doc.contents, callback),
92
- expandedStates: recursivelyMapDoc(
93
- doc.expandedStates,
94
- callback
95
- )
96
- });
97
- }
98
- if ("contents" in doc) {
99
- return __spreadProps(__spreadValues({}, doc), {
100
- contents: recursivelyMapDoc(doc.contents, callback)
101
- });
102
- }
103
- if ("parts" in doc) {
104
- return __spreadProps(__spreadValues({}, doc), {
105
- parts: recursivelyMapDoc(doc.parts, callback)
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
- var modifiedHtml = __spreadValues({}, html);
62
+ const modifiedHtml = { ...prettier_plugins_html };
118
63
  if (modifiedHtml.printers) {
119
- const previousPrint = modifiedHtml.printers.html.print;
120
- modifiedHtml.printers.html.print = (path, options, print, args) => {
121
- const node = path.getNode();
122
- const rawPrintingResult = previousPrint(path, options, print, args);
123
- if (node.type === "ieConditionalComment") {
124
- const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
125
- if (typeof doc === "object" && doc.type === "line") {
126
- return doc.soft ? "" : " ";
127
- }
128
- return doc;
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
- var defaults = {
136
- endOfLine: "lf",
137
- tabWidth: 2,
138
- plugins: [modifiedHtml],
139
- bracketSameLine: true,
140
- parser: "html"
75
+ const defaults = {
76
+ endOfLine: "lf",
77
+ tabWidth: 2,
78
+ plugins: [modifiedHtml],
79
+ bracketSameLine: true,
80
+ parser: "html"
141
81
  };
142
- var pretty = (str, options = {}) => {
143
- return (0, import_standalone.format)(str.replaceAll("\0", ""), __spreadValues(__spreadValues({}, defaults), options));
82
+ const pretty = (str, options = {}) => {
83
+ return (0, prettier_standalone.format)(str.replaceAll("\0", ""), {
84
+ ...defaults,
85
+ ...options
86
+ });
144
87
  };
145
88
 
146
- // src/shared/utils/to-plain-text.ts
147
- var import_html_to_text = require("html-to-text");
148
- var plainTextSelectors = [
149
- { selector: "img", format: "skip" },
150
- { selector: "[data-skip-in-text=true]", format: "skip" },
151
- {
152
- selector: "a",
153
- options: { linkBrackets: false }
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(html2, options) {
157
- return (0, import_html_to_text.convert)(html2, __spreadValues({
158
- selectors: plainTextSelectors
159
- }, options));
108
+ function toPlainText(html, options) {
109
+ return (0, html_to_text.convert)(html, {
110
+ selectors: plainTextSelectors,
111
+ ...options
112
+ });
160
113
  }
161
114
 
162
- // src/node/read-stream.ts
163
- var import_node_stream = require("stream");
164
- var decoder = new TextDecoder("utf-8");
165
- var readStream = (stream) => __async(void 0, null, function* () {
166
- let result = "";
167
- if ("pipeTo" in stream) {
168
- const writableStream = new WritableStream({
169
- write(chunk) {
170
- result += decoder.decode(chunk);
171
- }
172
- });
173
- yield stream.pipeTo(writableStream);
174
- } else {
175
- const writable = new import_node_stream.Writable({
176
- write(chunk, _encoding, callback) {
177
- result += decoder.decode(chunk);
178
- callback();
179
- }
180
- });
181
- stream.pipe(writable);
182
- yield new Promise((resolve, reject) => {
183
- writable.on("error", reject);
184
- writable.on("close", () => {
185
- resolve();
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
- // src/node/render.tsx
193
- var import_jsx_runtime = require("react/jsx-runtime");
194
- var render = (node, options) => __async(void 0, null, function* () {
195
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: node });
196
- const reactDOMServer = yield import("react-dom/server").then(
197
- // This is beacuse react-dom/server is CJS
198
- (m) => m.default
199
- );
200
- let html2;
201
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
202
- html2 = yield readStream(
203
- yield reactDOMServer.renderToReadableStream(suspendedElement, {
204
- progressiveChunkSize: Number.POSITIVE_INFINITY
205
- })
206
- );
207
- } else {
208
- yield new Promise((resolve, reject) => {
209
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
210
- onAllReady() {
211
- return __async(this, null, function* () {
212
- html2 = yield readStream(stream);
213
- resolve();
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
- // src/node/index.ts
235
- var renderAsync = (element, options) => {
236
- return render(element, options);
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
- // Annotate the CommonJS export names for ESM import in node:
239
- 0 && (module.exports = {
240
- plainTextSelectors,
241
- pretty,
242
- render,
243
- renderAsync,
244
- toPlainText
245
- });
174
+
175
+ //#endregion
176
+ exports.plainTextSelectors = plainTextSelectors;
177
+ exports.pretty = pretty;
178
+ exports.render = render;
179
+ exports.renderAsync = renderAsync;
180
+ exports.toPlainText = toPlainText;