@react-email/render 0.0.8 → 0.0.9-canary.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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +51 -4
- package/dist/index.mjs +51 -4
- 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) => string
|
|
5
|
+
declare const render: (component: React.ReactElement, options?: Options) => Promise<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) => string
|
|
5
|
+
declare const render: (component: React.ReactElement, options?: Options) => Promise<string>;
|
|
6
6
|
|
|
7
7
|
declare const renderAsync: (component: React.ReactElement, options?: {
|
|
8
8
|
pretty?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -65,18 +65,65 @@ module.exports = __toCommonJS(src_exports);
|
|
|
65
65
|
var ReactDomServer = __toESM(require("react-dom/server"));
|
|
66
66
|
var import_html_to_text = require("html-to-text");
|
|
67
67
|
var import_pretty = __toESM(require("pretty"));
|
|
68
|
-
var
|
|
68
|
+
var readPipeableStream = (readableStream) => __async(void 0, null, function* () {
|
|
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
|
+
);
|
|
69
115
|
if (options == null ? void 0 : options.plainText) {
|
|
70
116
|
return renderAsPlainText(component, options);
|
|
71
117
|
}
|
|
72
118
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
73
|
-
const
|
|
74
|
-
const
|
|
119
|
+
const readableStream = yield renderToStream2(component);
|
|
120
|
+
const html = yield readStream(readableStream);
|
|
121
|
+
const document = `${doctype}${html}`;
|
|
75
122
|
if (options && options.pretty) {
|
|
76
123
|
return (0, import_pretty.default)(document);
|
|
77
124
|
}
|
|
78
125
|
return document;
|
|
79
|
-
};
|
|
126
|
+
});
|
|
80
127
|
var renderAsPlainText = (component, _options) => {
|
|
81
128
|
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), {
|
|
82
129
|
selectors: [
|
package/dist/index.mjs
CHANGED
|
@@ -29,18 +29,65 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
29
29
|
import * as ReactDomServer from "react-dom/server";
|
|
30
30
|
import { convert } from "html-to-text";
|
|
31
31
|
import pretty from "pretty";
|
|
32
|
-
var
|
|
32
|
+
var readPipeableStream = (readableStream) => __async(void 0, null, function* () {
|
|
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
|
+
);
|
|
33
79
|
if (options == null ? void 0 : options.plainText) {
|
|
34
80
|
return renderAsPlainText(component, options);
|
|
35
81
|
}
|
|
36
82
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
37
|
-
const
|
|
38
|
-
const
|
|
83
|
+
const readableStream = yield renderToStream2(component);
|
|
84
|
+
const html = yield readStream(readableStream);
|
|
85
|
+
const document = `${doctype}${html}`;
|
|
39
86
|
if (options && options.pretty) {
|
|
40
87
|
return pretty(document);
|
|
41
88
|
}
|
|
42
89
|
return document;
|
|
43
|
-
};
|
|
90
|
+
});
|
|
44
91
|
var renderAsPlainText = (component, _options) => {
|
|
45
92
|
return convert(ReactDomServer.renderToStaticMarkup(component), {
|
|
46
93
|
selectors: [
|