@react-email/render 0.0.8 → 0.0.9-canary.1

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 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 render = (component, options) => {
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 renderToStream = (
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 markup = ReactDomServer.renderToStaticMarkup(component);
74
- const document = `${doctype}${markup}`;
119
+ const readableStream = yield renderToStream(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: [
@@ -89,15 +136,12 @@ var renderAsPlainText = (component, _options) => {
89
136
  // src/render-async.ts
90
137
  var import_html_to_text2 = require("html-to-text");
91
138
  var import_pretty2 = __toESM(require("pretty"));
92
- var import_server = __toESM(require("react-dom/server"));
93
- var { renderToStaticMarkup: renderToStaticMarkup2 } = import_server.default;
94
- var renderToStream = (
95
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
96
- import_server.default.renderToReadableStream || import_server.default.renderToPipeableStream
97
- );
139
+ var import_server = require("react-dom/server");
140
+ var import_server2 = __toESM(require("react-dom/server"));
98
141
  function renderToString(children) {
99
142
  return __async(this, null, function* () {
100
- const stream = yield renderToStream(children);
143
+ const renderToReadableStream = import_server2.default.renderToReadableStream;
144
+ const stream = yield renderToReadableStream(children);
101
145
  const html = yield readableStreamToString(
102
146
  // ReactDOMServerReadableStream behaves like ReadableStream
103
147
  // in modern edge runtimes but the types are not compatible
@@ -129,7 +173,7 @@ function readableStreamToString(readableStream) {
129
173
  });
130
174
  }
131
175
  var renderAsync = (component, options) => __async(void 0, null, function* () {
132
- const markup = typeof renderToStaticMarkup2 === "undefined" ? yield renderToString(component) : renderToStaticMarkup2(component);
176
+ const markup = typeof import_server.renderToStaticMarkup === "undefined" ? yield renderToString(component) : (0, import_server.renderToStaticMarkup)(component);
133
177
  if (options == null ? void 0 : options.plainText) {
134
178
  return (0, import_html_to_text2.convert)(markup, {
135
179
  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 render = (component, options) => {
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 renderToStream = (
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 markup = ReactDomServer.renderToStaticMarkup(component);
38
- const document = `${doctype}${markup}`;
83
+ const readableStream = yield renderToStream(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: [
@@ -53,15 +100,12 @@ var renderAsPlainText = (component, _options) => {
53
100
  // src/render-async.ts
54
101
  import { convert as convert2 } from "html-to-text";
55
102
  import pretty2 from "pretty";
56
- import react from "react-dom/server";
57
- var { renderToStaticMarkup: renderToStaticMarkup2 } = react;
58
- var renderToStream = (
59
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
60
- react.renderToReadableStream || react.renderToPipeableStream
61
- );
103
+ import { renderToStaticMarkup as renderToStaticMarkup2 } from "react-dom/server";
104
+ import ReactDOMServer from "react-dom/server";
62
105
  function renderToString(children) {
63
106
  return __async(this, null, function* () {
64
- const stream = yield renderToStream(children);
107
+ const renderToReadableStream = ReactDOMServer.renderToReadableStream;
108
+ const stream = yield renderToReadableStream(children);
65
109
  const html = yield readableStreamToString(
66
110
  // ReactDOMServerReadableStream behaves like ReadableStream
67
111
  // in modern edge runtimes but the types are not compatible
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-email/render",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-canary.1",
4
4
  "description": "Transform React components into HTML email templates",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",