@react-email/render 0.0.12 → 0.0.14-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.js CHANGED
@@ -7,11 +7,6 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __knownSymbol = (name, symbol) => {
11
- if (symbol = Symbol[name])
12
- return symbol;
13
- throw Error("Symbol." + name + " is not defined");
14
- };
15
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
11
  var __spreadValues = (a, b) => {
17
12
  for (var prop in b || (b = {}))
@@ -65,7 +60,6 @@ var __async = (__this, __arguments, generator) => {
65
60
  step((generator = generator.apply(__this, __arguments)).next());
66
61
  });
67
62
  };
68
- 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);
69
63
 
70
64
  // src/index.ts
71
65
  var src_exports = {};
@@ -125,48 +119,61 @@ var renderAsPlainText = (component, options) => {
125
119
  // src/render-async.ts
126
120
  var import_html_to_text2 = require("html-to-text");
127
121
  var decoder = new TextDecoder("utf-8");
128
- var readStream = (readableStream) => __async(void 0, null, function* () {
122
+ var readStream = (stream) => __async(void 0, null, function* () {
129
123
  let result = "";
130
- if ("allReady" in readableStream) {
131
- const reader = readableStream.getReader();
132
- while (true) {
133
- const { value, done } = yield reader.read();
134
- if (done) {
135
- break;
124
+ if ("pipeTo" in stream) {
125
+ const writableStream = new WritableStream({
126
+ write(chunk) {
127
+ result += decoder.decode(chunk);
136
128
  }
137
- result += decoder.decode(value);
138
- }
129
+ });
130
+ yield stream.pipeTo(writableStream);
139
131
  } else {
140
- try {
141
- for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
142
- const chunk = temp.value;
143
- result += decoder.decode(Buffer.from(chunk));
132
+ const { Writable } = require("stream");
133
+ const writable = new Writable({
134
+ write(chunk, _encoding, callback) {
135
+ result += decoder.decode(chunk);
136
+ callback();
144
137
  }
145
- } catch (temp) {
146
- error = [temp];
147
- } finally {
148
- try {
149
- more && (temp = iter.return) && (yield temp.call(iter));
150
- } finally {
151
- if (error)
152
- throw error[0];
153
- }
154
- }
138
+ });
139
+ stream.pipe(writable);
140
+ return new Promise((resolve, reject) => {
141
+ writable.on("error", reject);
142
+ writable.on("close", () => {
143
+ resolve(result);
144
+ });
145
+ });
155
146
  }
156
147
  return result;
157
148
  });
158
149
  var renderAsync = (component, options) => __async(void 0, null, function* () {
159
- var _a;
160
- const reactDOMServer = (yield import("react-dom/server")).default;
161
- const renderToStream = (_a = reactDOMServer.renderToReadableStream) != null ? _a : reactDOMServer.renderToStaticNodeStream;
162
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
163
- const htmlOrReadableStream = yield renderToStream(component);
164
- const html = typeof htmlOrReadableStream === "string" ? htmlOrReadableStream : yield readStream(htmlOrReadableStream);
150
+ const reactDOMServer = yield import("react-dom/server");
151
+ let html;
152
+ if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
153
+ html = yield readStream(
154
+ yield reactDOMServer.renderToReadableStream(component)
155
+ );
156
+ } else {
157
+ yield new Promise((resolve, reject) => {
158
+ const stream = reactDOMServer.renderToPipeableStream(component, {
159
+ onAllReady() {
160
+ return __async(this, null, function* () {
161
+ html = yield readStream(stream);
162
+ resolve();
163
+ });
164
+ },
165
+ onError(error) {
166
+ reject(error);
167
+ }
168
+ });
169
+ });
170
+ }
165
171
  if (options == null ? void 0 : options.plainText) {
166
172
  return (0, import_html_to_text2.convert)(html, __spreadValues({
167
173
  selectors: plainTextSelectors
168
174
  }, options.htmlToTextOptions));
169
175
  }
176
+ const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
170
177
  const document = `${doctype}${html}`;
171
178
  if (options == null ? void 0 : options.pretty) {
172
179
  return pretty(document);
package/dist/index.mjs CHANGED
@@ -2,11 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __knownSymbol = (name, symbol) => {
6
- if (symbol = Symbol[name])
7
- return symbol;
8
- throw Error("Symbol." + name + " is not defined");
9
- };
10
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
6
  var __spreadValues = (a, b) => {
12
7
  for (var prop in b || (b = {}))
@@ -19,6 +14,13 @@ var __spreadValues = (a, b) => {
19
14
  }
20
15
  return a;
21
16
  };
17
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
18
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
19
+ }) : x)(function(x) {
20
+ if (typeof require !== "undefined")
21
+ return require.apply(this, arguments);
22
+ throw Error('Dynamic require of "' + x + '" is not supported');
23
+ });
22
24
  var __async = (__this, __arguments, generator) => {
23
25
  return new Promise((resolve, reject) => {
24
26
  var fulfilled = (value) => {
@@ -39,7 +41,6 @@ var __async = (__this, __arguments, generator) => {
39
41
  step((generator = generator.apply(__this, __arguments)).next());
40
42
  });
41
43
  };
42
- 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);
43
44
 
44
45
  // src/render.ts
45
46
  import * as ReactDomServer from "react-dom/server";
@@ -90,48 +91,61 @@ var renderAsPlainText = (component, options) => {
90
91
  // src/render-async.ts
91
92
  import { convert as convert2 } from "html-to-text";
92
93
  var decoder = new TextDecoder("utf-8");
93
- var readStream = (readableStream) => __async(void 0, null, function* () {
94
+ var readStream = (stream) => __async(void 0, null, function* () {
94
95
  let result = "";
95
- if ("allReady" in readableStream) {
96
- const reader = readableStream.getReader();
97
- while (true) {
98
- const { value, done } = yield reader.read();
99
- if (done) {
100
- break;
96
+ if ("pipeTo" in stream) {
97
+ const writableStream = new WritableStream({
98
+ write(chunk) {
99
+ result += decoder.decode(chunk);
101
100
  }
102
- result += decoder.decode(value);
103
- }
101
+ });
102
+ yield stream.pipeTo(writableStream);
104
103
  } else {
105
- try {
106
- for (var iter = __forAwait(readableStream), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
107
- const chunk = temp.value;
108
- result += decoder.decode(Buffer.from(chunk));
109
- }
110
- } catch (temp) {
111
- error = [temp];
112
- } finally {
113
- try {
114
- more && (temp = iter.return) && (yield temp.call(iter));
115
- } finally {
116
- if (error)
117
- throw error[0];
104
+ const { Writable } = __require("stream");
105
+ const writable = new Writable({
106
+ write(chunk, _encoding, callback) {
107
+ result += decoder.decode(chunk);
108
+ callback();
118
109
  }
119
- }
110
+ });
111
+ stream.pipe(writable);
112
+ return new Promise((resolve, reject) => {
113
+ writable.on("error", reject);
114
+ writable.on("close", () => {
115
+ resolve(result);
116
+ });
117
+ });
120
118
  }
121
119
  return result;
122
120
  });
123
121
  var renderAsync = (component, options) => __async(void 0, null, function* () {
124
- var _a;
125
- const reactDOMServer = (yield import("react-dom/server")).default;
126
- const renderToStream = (_a = reactDOMServer.renderToReadableStream) != null ? _a : reactDOMServer.renderToStaticNodeStream;
127
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
128
- const htmlOrReadableStream = yield renderToStream(component);
129
- const html = typeof htmlOrReadableStream === "string" ? htmlOrReadableStream : yield readStream(htmlOrReadableStream);
122
+ const reactDOMServer = yield import("react-dom/server");
123
+ let html;
124
+ if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
125
+ html = yield readStream(
126
+ yield reactDOMServer.renderToReadableStream(component)
127
+ );
128
+ } else {
129
+ yield new Promise((resolve, reject) => {
130
+ const stream = reactDOMServer.renderToPipeableStream(component, {
131
+ onAllReady() {
132
+ return __async(this, null, function* () {
133
+ html = yield readStream(stream);
134
+ resolve();
135
+ });
136
+ },
137
+ onError(error) {
138
+ reject(error);
139
+ }
140
+ });
141
+ });
142
+ }
130
143
  if (options == null ? void 0 : options.plainText) {
131
144
  return convert2(html, __spreadValues({
132
145
  selectors: plainTextSelectors
133
146
  }, options.htmlToTextOptions));
134
147
  }
148
+ const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
135
149
  const document = `${doctype}${html}`;
136
150
  if (options == null ? void 0 : options.pretty) {
137
151
  return pretty(document);
package/license.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 Bu Kinoshita and Zeno Rocha
1
+ Copyright 2024 Plus Five Five, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-email/render",
3
- "version": "0.0.12",
3
+ "version": "0.0.14-canary.0",
4
4
  "description": "Transform React components into HTML email templates",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -22,14 +22,6 @@
22
22
  }
23
23
  },
24
24
  "license": "MIT",
25
- "scripts": {
26
- "build": "tsup src/index.ts --format esm,cjs --dts --external react",
27
- "clean": "rm -rf dist",
28
- "dev": "tsup src/index.ts --format esm,cjs --dts --external react --watch",
29
- "lint": "eslint .",
30
- "test:watch": "vitest",
31
- "test": "vitest run"
32
- },
33
25
  "repository": {
34
26
  "type": "git",
35
27
  "url": "https://github.com/resend/react-email.git",
@@ -45,21 +37,30 @@
45
37
  "dependencies": {
46
38
  "html-to-text": "9.0.5",
47
39
  "js-beautify": "^1.14.11",
48
- "react": "18.2.0",
49
- "react-dom": "18.2.0"
40
+ "react": "^18.2.0",
41
+ "react-dom": "^18.2.0",
42
+ "react-promise-suspense": "0.3.4"
50
43
  },
51
44
  "devDependencies": {
52
- "@babel/preset-react": "7.22.5",
53
- "@edge-runtime/vm": "3.1.7",
54
- "@types/html-to-text": "9.0.1",
45
+ "@babel/preset-react": "7.23.3",
46
+ "@edge-runtime/vm": "3.1.8",
47
+ "@types/html-to-text": "9.0.4",
55
48
  "@types/js-beautify": "1.14.3",
56
- "eslint-config-custom": "workspace:*",
57
49
  "jsdom": "23.0.1",
58
- "tsconfig": "workspace:*",
59
50
  "typescript": "5.1.6",
60
- "vitest": "0.34.6"
51
+ "vitest": "1.1.2",
52
+ "eslint-config-custom": "0.0.0",
53
+ "tsconfig": "0.0.0"
61
54
  },
62
55
  "publishConfig": {
63
56
  "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup src/index.ts --format esm,cjs --dts --external react",
60
+ "clean": "rm -rf dist",
61
+ "dev": "tsup src/index.ts --format esm,cjs --dts --external react --watch",
62
+ "lint": "eslint .",
63
+ "test:watch": "vitest",
64
+ "test": "vitest run"
64
65
  }
65
- }
66
+ }