@react-email/render 0.0.9-canary.1 → 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 -96
- package/dist/index.mjs +22 -96
- 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 renderToStream = (
|
|
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,54 +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
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// ReactDOMServerReadableStream behaves like ReadableStream
|
|
147
|
-
// in modern edge runtimes but the types are not compatible
|
|
148
|
-
stream
|
|
149
|
-
);
|
|
150
|
-
return html.replace(/^<!DOCTYPE html>/, "").replace(/<!-- -->/g, "");
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function readableStreamToString(readableStream) {
|
|
154
|
-
return __async(this, null, function* () {
|
|
155
|
-
let result = "";
|
|
156
|
-
const decoder = new TextDecoder();
|
|
157
|
-
try {
|
|
158
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
159
|
-
const chunk = temp.value;
|
|
160
|
-
result += decoder.decode(chunk);
|
|
161
|
-
}
|
|
162
|
-
} catch (temp) {
|
|
163
|
-
error = [temp];
|
|
164
|
-
} finally {
|
|
165
|
-
try {
|
|
166
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
167
|
-
} finally {
|
|
168
|
-
if (error)
|
|
169
|
-
throw error[0];
|
|
170
|
-
}
|
|
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;
|
|
171
93
|
}
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
94
|
+
chunks.push(value);
|
|
95
|
+
}
|
|
96
|
+
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
97
|
+
});
|
|
175
98
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
176
|
-
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);
|
|
177
104
|
if (options == null ? void 0 : options.plainText) {
|
|
178
|
-
return (0, import_html_to_text2.convert)(
|
|
105
|
+
return (0, import_html_to_text2.convert)(html, {
|
|
179
106
|
selectors: [
|
|
180
107
|
{ selector: "img", format: "skip" },
|
|
181
108
|
{ selector: "#__react-email-preview", format: "skip" }
|
|
182
109
|
]
|
|
183
110
|
});
|
|
184
111
|
}
|
|
185
|
-
const
|
|
186
|
-
const document = `${doctype}${markup}`;
|
|
112
|
+
const document = `${doctype}${html}`;
|
|
187
113
|
if (options == null ? void 0 : options.pretty) {
|
|
188
114
|
return (0, import_pretty2.default)(document);
|
|
189
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 renderToStream = (
|
|
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,54 +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
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// ReactDOMServerReadableStream behaves like ReadableStream
|
|
111
|
-
// in modern edge runtimes but the types are not compatible
|
|
112
|
-
stream
|
|
113
|
-
);
|
|
114
|
-
return html.replace(/^<!DOCTYPE html>/, "").replace(/<!-- -->/g, "");
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function readableStreamToString(readableStream) {
|
|
118
|
-
return __async(this, null, function* () {
|
|
119
|
-
let result = "";
|
|
120
|
-
const decoder = new TextDecoder();
|
|
121
|
-
try {
|
|
122
|
-
for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
123
|
-
const chunk = temp.value;
|
|
124
|
-
result += decoder.decode(chunk);
|
|
125
|
-
}
|
|
126
|
-
} catch (temp) {
|
|
127
|
-
error = [temp];
|
|
128
|
-
} finally {
|
|
129
|
-
try {
|
|
130
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
131
|
-
} finally {
|
|
132
|
-
if (error)
|
|
133
|
-
throw error[0];
|
|
134
|
-
}
|
|
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;
|
|
135
57
|
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
58
|
+
chunks.push(value);
|
|
59
|
+
}
|
|
60
|
+
return chunks.map((chunk) => new TextDecoder("utf-8").decode(chunk)).join("");
|
|
61
|
+
});
|
|
139
62
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
140
|
-
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);
|
|
141
68
|
if (options == null ? void 0 : options.plainText) {
|
|
142
|
-
return convert2(
|
|
69
|
+
return convert2(html, {
|
|
143
70
|
selectors: [
|
|
144
71
|
{ selector: "img", format: "skip" },
|
|
145
72
|
{ selector: "#__react-email-preview", format: "skip" }
|
|
146
73
|
]
|
|
147
74
|
});
|
|
148
75
|
}
|
|
149
|
-
const
|
|
150
|
-
const document = `${doctype}${markup}`;
|
|
76
|
+
const document = `${doctype}${html}`;
|
|
151
77
|
if (options == null ? void 0 : options.pretty) {
|
|
152
78
|
return pretty2(document);
|
|
153
79
|
}
|