@react-email/render 0.0.9-canary.0 → 0.0.9-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -99
- package/dist/index.mjs +22 -99
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ interface Options {
|
|
|
2
2
|
pretty?: boolean;
|
|
3
3
|
plainText?: boolean;
|
|
4
4
|
}
|
|
5
|
-
declare const render: (component: React.ReactElement, options?: Options) =>
|
|
5
|
+
declare const render: (component: React.ReactElement, options?: Options) => string;
|
|
6
6
|
|
|
7
7
|
declare const renderAsync: (component: React.ReactElement, options?: {
|
|
8
8
|
pretty?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ interface Options {
|
|
|
2
2
|
pretty?: boolean;
|
|
3
3
|
plainText?: boolean;
|
|
4
4
|
}
|
|
5
|
-
declare const render: (component: React.ReactElement, options?: Options) =>
|
|
5
|
+
declare const render: (component: React.ReactElement, options?: Options) => string;
|
|
6
6
|
|
|
7
7
|
declare const renderAsync: (component: React.ReactElement, options?: {
|
|
8
8
|
pretty?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __knownSymbol = (name, symbol) => {
|
|
9
|
-
if (symbol = Symbol[name])
|
|
10
|
-
return symbol;
|
|
11
|
-
throw Error("Symbol." + name + " is not defined");
|
|
12
|
-
};
|
|
13
8
|
var __export = (target, all) => {
|
|
14
9
|
for (var name in all)
|
|
15
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -51,7 +46,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
51
46
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
52
47
|
});
|
|
53
48
|
};
|
|
54
|
-
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
55
49
|
|
|
56
50
|
// src/index.ts
|
|
57
51
|
var src_exports = {};
|
|
@@ -65,65 +59,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
65
59
|
var ReactDomServer = __toESM(require("react-dom/server"));
|
|
66
60
|
var import_html_to_text = require("html-to-text");
|
|
67
61
|
var import_pretty = __toESM(require("pretty"));
|
|
68
|
-
var
|
|
69
|
-
let buffer = "";
|
|
70
|
-
try {
|
|
71
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
72
|
-
const chunk = temp.value;
|
|
73
|
-
const chunkText = new TextDecoder("utf-8").decode(chunk);
|
|
74
|
-
buffer += chunkText;
|
|
75
|
-
}
|
|
76
|
-
} catch (temp) {
|
|
77
|
-
error = [temp];
|
|
78
|
-
} finally {
|
|
79
|
-
try {
|
|
80
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
81
|
-
} finally {
|
|
82
|
-
if (error)
|
|
83
|
-
throw error[0];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return buffer;
|
|
87
|
-
});
|
|
88
|
-
var readReactDOMServerReadableStream = (readableStream) => __async(void 0, null, function* () {
|
|
89
|
-
const reader = readableStream.getReader();
|
|
90
|
-
const chunks = [];
|
|
91
|
-
while (true) {
|
|
92
|
-
const { value, done } = yield reader.read();
|
|
93
|
-
if (done) {
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
chunks.push(value);
|
|
97
|
-
}
|
|
98
|
-
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
99
|
-
});
|
|
100
|
-
var isPipeableStream = (stream) => "pipeTo" in stream;
|
|
101
|
-
var readStream = (readableStream) => __async(void 0, null, function* () {
|
|
102
|
-
if (isPipeableStream(readableStream)) {
|
|
103
|
-
return readPipeableStream(readableStream);
|
|
104
|
-
} else if (typeof readableStream === "string") {
|
|
105
|
-
return readableStream;
|
|
106
|
-
}
|
|
107
|
-
return readReactDOMServerReadableStream(readableStream);
|
|
108
|
-
});
|
|
109
|
-
var render = (component, options) => __async(void 0, null, function* () {
|
|
110
|
-
const reactDOMServer = (yield import("react-dom/server")).default;
|
|
111
|
-
const renderToStream2 = (
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
113
|
-
reactDOMServer.renderToReadableStream || reactDOMServer.renderToPipeableStream
|
|
114
|
-
);
|
|
62
|
+
var render = (component, options) => {
|
|
115
63
|
if (options == null ? void 0 : options.plainText) {
|
|
116
64
|
return renderAsPlainText(component, options);
|
|
117
65
|
}
|
|
118
66
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const document = `${doctype}${html}`;
|
|
67
|
+
const markup = ReactDomServer.renderToStaticMarkup(component);
|
|
68
|
+
const document = `${doctype}${markup}`;
|
|
122
69
|
if (options && options.pretty) {
|
|
123
70
|
return (0, import_pretty.default)(document);
|
|
124
71
|
}
|
|
125
72
|
return document;
|
|
126
|
-
}
|
|
73
|
+
};
|
|
127
74
|
var renderAsPlainText = (component, _options) => {
|
|
128
75
|
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), {
|
|
129
76
|
selectors: [
|
|
@@ -136,57 +83,33 @@ var renderAsPlainText = (component, _options) => {
|
|
|
136
83
|
// src/render-async.ts
|
|
137
84
|
var import_html_to_text2 = require("html-to-text");
|
|
138
85
|
var import_pretty2 = __toESM(require("pretty"));
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
return __async(this, null, function* () {
|
|
147
|
-
const stream = yield renderToStream(children);
|
|
148
|
-
const html = yield readableStreamToString(
|
|
149
|
-
// ReactDOMServerReadableStream behaves like ReadableStream
|
|
150
|
-
// in modern edge runtimes but the types are not compatible
|
|
151
|
-
stream
|
|
152
|
-
);
|
|
153
|
-
return html.replace(/^<!DOCTYPE html>/, "").replace(/<!-- -->/g, "");
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
function readableStreamToString(readableStream) {
|
|
157
|
-
return __async(this, null, function* () {
|
|
158
|
-
let result = "";
|
|
159
|
-
const decoder = new TextDecoder();
|
|
160
|
-
try {
|
|
161
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
162
|
-
const chunk = temp.value;
|
|
163
|
-
result += decoder.decode(chunk);
|
|
164
|
-
}
|
|
165
|
-
} catch (temp) {
|
|
166
|
-
error = [temp];
|
|
167
|
-
} finally {
|
|
168
|
-
try {
|
|
169
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
170
|
-
} finally {
|
|
171
|
-
if (error)
|
|
172
|
-
throw error[0];
|
|
173
|
-
}
|
|
86
|
+
var readStream = (readableStream) => __async(void 0, null, function* () {
|
|
87
|
+
const reader = readableStream.getReader();
|
|
88
|
+
const chunks = [];
|
|
89
|
+
while (true) {
|
|
90
|
+
const { value, done } = yield reader.read();
|
|
91
|
+
if (done) {
|
|
92
|
+
break;
|
|
174
93
|
}
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
94
|
+
chunks.push(value);
|
|
95
|
+
}
|
|
96
|
+
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
97
|
+
});
|
|
178
98
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
179
|
-
const
|
|
99
|
+
const reactDOMServer = (yield import("react-dom/server")).default;
|
|
100
|
+
const renderToStream = reactDOMServer.renderToReadableStream || reactDOMServer.renderToString || reactDOMServer.renderToPipeableStream;
|
|
101
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
102
|
+
const readableStream = yield renderToStream(component);
|
|
103
|
+
const html = typeof readableStream === "string" ? readableStream : yield readStream(readableStream);
|
|
180
104
|
if (options == null ? void 0 : options.plainText) {
|
|
181
|
-
return (0, import_html_to_text2.convert)(
|
|
105
|
+
return (0, import_html_to_text2.convert)(html, {
|
|
182
106
|
selectors: [
|
|
183
107
|
{ selector: "img", format: "skip" },
|
|
184
108
|
{ selector: "#__react-email-preview", format: "skip" }
|
|
185
109
|
]
|
|
186
110
|
});
|
|
187
111
|
}
|
|
188
|
-
const
|
|
189
|
-
const document = `${doctype}${markup}`;
|
|
112
|
+
const document = `${doctype}${html}`;
|
|
190
113
|
if (options == null ? void 0 : options.pretty) {
|
|
191
114
|
return (0, import_pretty2.default)(document);
|
|
192
115
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
var __knownSymbol = (name, symbol) => {
|
|
2
|
-
if (symbol = Symbol[name])
|
|
3
|
-
return symbol;
|
|
4
|
-
throw Error("Symbol." + name + " is not defined");
|
|
5
|
-
};
|
|
6
1
|
var __async = (__this, __arguments, generator) => {
|
|
7
2
|
return new Promise((resolve, reject) => {
|
|
8
3
|
var fulfilled = (value) => {
|
|
@@ -23,71 +18,23 @@ var __async = (__this, __arguments, generator) => {
|
|
|
23
18
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
24
19
|
});
|
|
25
20
|
};
|
|
26
|
-
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
27
21
|
|
|
28
22
|
// src/render.ts
|
|
29
23
|
import * as ReactDomServer from "react-dom/server";
|
|
30
24
|
import { convert } from "html-to-text";
|
|
31
25
|
import pretty from "pretty";
|
|
32
|
-
var
|
|
33
|
-
let buffer = "";
|
|
34
|
-
try {
|
|
35
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
36
|
-
const chunk = temp.value;
|
|
37
|
-
const chunkText = new TextDecoder("utf-8").decode(chunk);
|
|
38
|
-
buffer += chunkText;
|
|
39
|
-
}
|
|
40
|
-
} catch (temp) {
|
|
41
|
-
error = [temp];
|
|
42
|
-
} finally {
|
|
43
|
-
try {
|
|
44
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
45
|
-
} finally {
|
|
46
|
-
if (error)
|
|
47
|
-
throw error[0];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return buffer;
|
|
51
|
-
});
|
|
52
|
-
var readReactDOMServerReadableStream = (readableStream) => __async(void 0, null, function* () {
|
|
53
|
-
const reader = readableStream.getReader();
|
|
54
|
-
const chunks = [];
|
|
55
|
-
while (true) {
|
|
56
|
-
const { value, done } = yield reader.read();
|
|
57
|
-
if (done) {
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
chunks.push(value);
|
|
61
|
-
}
|
|
62
|
-
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
63
|
-
});
|
|
64
|
-
var isPipeableStream = (stream) => "pipeTo" in stream;
|
|
65
|
-
var readStream = (readableStream) => __async(void 0, null, function* () {
|
|
66
|
-
if (isPipeableStream(readableStream)) {
|
|
67
|
-
return readPipeableStream(readableStream);
|
|
68
|
-
} else if (typeof readableStream === "string") {
|
|
69
|
-
return readableStream;
|
|
70
|
-
}
|
|
71
|
-
return readReactDOMServerReadableStream(readableStream);
|
|
72
|
-
});
|
|
73
|
-
var render = (component, options) => __async(void 0, null, function* () {
|
|
74
|
-
const reactDOMServer = (yield import("react-dom/server")).default;
|
|
75
|
-
const renderToStream2 = (
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
77
|
-
reactDOMServer.renderToReadableStream || reactDOMServer.renderToPipeableStream
|
|
78
|
-
);
|
|
26
|
+
var render = (component, options) => {
|
|
79
27
|
if (options == null ? void 0 : options.plainText) {
|
|
80
28
|
return renderAsPlainText(component, options);
|
|
81
29
|
}
|
|
82
30
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const document = `${doctype}${html}`;
|
|
31
|
+
const markup = ReactDomServer.renderToStaticMarkup(component);
|
|
32
|
+
const document = `${doctype}${markup}`;
|
|
86
33
|
if (options && options.pretty) {
|
|
87
34
|
return pretty(document);
|
|
88
35
|
}
|
|
89
36
|
return document;
|
|
90
|
-
}
|
|
37
|
+
};
|
|
91
38
|
var renderAsPlainText = (component, _options) => {
|
|
92
39
|
return convert(ReactDomServer.renderToStaticMarkup(component), {
|
|
93
40
|
selectors: [
|
|
@@ -100,57 +47,33 @@ var renderAsPlainText = (component, _options) => {
|
|
|
100
47
|
// src/render-async.ts
|
|
101
48
|
import { convert as convert2 } from "html-to-text";
|
|
102
49
|
import pretty2 from "pretty";
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
return __async(this, null, function* () {
|
|
111
|
-
const stream = yield renderToStream(children);
|
|
112
|
-
const html = yield readableStreamToString(
|
|
113
|
-
// ReactDOMServerReadableStream behaves like ReadableStream
|
|
114
|
-
// in modern edge runtimes but the types are not compatible
|
|
115
|
-
stream
|
|
116
|
-
);
|
|
117
|
-
return html.replace(/^<!DOCTYPE html>/, "").replace(/<!-- -->/g, "");
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
function readableStreamToString(readableStream) {
|
|
121
|
-
return __async(this, null, function* () {
|
|
122
|
-
let result = "";
|
|
123
|
-
const decoder = new TextDecoder();
|
|
124
|
-
try {
|
|
125
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
126
|
-
const chunk = temp.value;
|
|
127
|
-
result += decoder.decode(chunk);
|
|
128
|
-
}
|
|
129
|
-
} catch (temp) {
|
|
130
|
-
error = [temp];
|
|
131
|
-
} finally {
|
|
132
|
-
try {
|
|
133
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
134
|
-
} finally {
|
|
135
|
-
if (error)
|
|
136
|
-
throw error[0];
|
|
137
|
-
}
|
|
50
|
+
var readStream = (readableStream) => __async(void 0, null, function* () {
|
|
51
|
+
const reader = readableStream.getReader();
|
|
52
|
+
const chunks = [];
|
|
53
|
+
while (true) {
|
|
54
|
+
const { value, done } = yield reader.read();
|
|
55
|
+
if (done) {
|
|
56
|
+
break;
|
|
138
57
|
}
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
58
|
+
chunks.push(value);
|
|
59
|
+
}
|
|
60
|
+
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
61
|
+
});
|
|
142
62
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
143
|
-
const
|
|
63
|
+
const reactDOMServer = (yield import("react-dom/server")).default;
|
|
64
|
+
const renderToStream = reactDOMServer.renderToReadableStream || reactDOMServer.renderToString || reactDOMServer.renderToPipeableStream;
|
|
65
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
66
|
+
const readableStream = yield renderToStream(component);
|
|
67
|
+
const html = typeof readableStream === "string" ? readableStream : yield readStream(readableStream);
|
|
144
68
|
if (options == null ? void 0 : options.plainText) {
|
|
145
|
-
return convert2(
|
|
69
|
+
return convert2(html, {
|
|
146
70
|
selectors: [
|
|
147
71
|
{ selector: "img", format: "skip" },
|
|
148
72
|
{ selector: "#__react-email-preview", format: "skip" }
|
|
149
73
|
]
|
|
150
74
|
});
|
|
151
75
|
}
|
|
152
|
-
const
|
|
153
|
-
const document = `${doctype}${markup}`;
|
|
76
|
+
const document = `${doctype}${html}`;
|
|
154
77
|
if (options == null ? void 0 : options.pretty) {
|
|
155
78
|
return pretty2(document);
|
|
156
79
|
}
|