@react-email/render 1.0.5-canary.1 → 1.0.6

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.
@@ -17,8 +17,11 @@ type Options = {
17
17
 
18
18
  declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
19
 
20
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
21
-
22
20
  declare const plainTextSelectors: SelectorDefinition[];
23
21
 
22
+ /**
23
+ * @deprecated use {@link render}
24
+ */
25
+ declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+
24
27
  export { Options, plainTextSelectors, render, renderAsync };
@@ -17,8 +17,11 @@ type Options = {
17
17
 
18
18
  declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
19
 
20
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
21
-
22
20
  declare const plainTextSelectors: SelectorDefinition[];
23
21
 
22
+ /**
23
+ * @deprecated use {@link render}
24
+ */
25
+ declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
26
+
24
27
  export { Options, plainTextSelectors, render, renderAsync };
@@ -222,81 +222,10 @@ var render = (element, options) => __async(void 0, null, function* () {
222
222
  return document;
223
223
  });
224
224
 
225
- // src/browser/render-async.tsx
226
- var import_html_to_text2 = require("html-to-text");
227
- var import_react2 = require("react");
228
-
229
- // src/browser/read-stream.ts
230
- var decoder2 = new TextDecoder("utf-8");
231
- var readStream2 = (stream) => __async(void 0, null, function* () {
232
- const chunks = [];
233
- if ("pipeTo" in stream) {
234
- const writableStream = new WritableStream({
235
- write(chunk) {
236
- chunks.push(chunk);
237
- }
238
- });
239
- yield stream.pipeTo(writableStream);
240
- } else {
241
- throw new Error(
242
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
243
- {
244
- cause: {
245
- stream
246
- }
247
- }
248
- );
249
- }
250
- let length = 0;
251
- chunks.forEach((item) => {
252
- length += item.length;
253
- });
254
- const mergedChunks = new Uint8Array(length);
255
- let offset = 0;
256
- chunks.forEach((item) => {
257
- mergedChunks.set(item, offset);
258
- offset += item.length;
259
- });
260
- return decoder2.decode(mergedChunks);
261
- });
262
-
263
- // src/browser/render-async.tsx
264
- var import_jsx_runtime2 = require("react/jsx-runtime");
265
- var renderAsync = (element, options) => __async(void 0, null, function* () {
266
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
267
- const reactDOMServer = yield import("react-dom/server");
268
- let html2;
269
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
270
- html2 = yield readStream2(
271
- yield reactDOMServer.renderToReadableStream(suspendedElement)
272
- );
273
- } else {
274
- yield new Promise((resolve, reject) => {
275
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
276
- onAllReady() {
277
- return __async(this, null, function* () {
278
- html2 = yield readStream2(stream);
279
- resolve();
280
- });
281
- },
282
- onError(error) {
283
- reject(error);
284
- }
285
- });
286
- });
287
- }
288
- if (options == null ? void 0 : options.plainText) {
289
- return (0, import_html_to_text2.convert)(html2, __spreadValues({
290
- selectors: plainTextSelectors
291
- }, options.htmlToTextOptions));
292
- }
293
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
294
- const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
295
- if (options == null ? void 0 : options.pretty) {
296
- return pretty(document);
297
- }
298
- return document;
299
- });
225
+ // src/browser/index.ts
226
+ var renderAsync = (element, options) => {
227
+ return render(element, options);
228
+ };
300
229
  // Annotate the CommonJS export names for ESM import in node:
301
230
  0 && (module.exports = {
302
231
  plainTextSelectors,
@@ -187,81 +187,10 @@ var render = (element, options) => __async(void 0, null, function* () {
187
187
  return document;
188
188
  });
189
189
 
190
- // src/browser/render-async.tsx
191
- import { convert as convert2 } from "html-to-text";
192
- import { Suspense as Suspense2 } from "react";
193
-
194
- // src/browser/read-stream.ts
195
- var decoder2 = new TextDecoder("utf-8");
196
- var readStream2 = (stream) => __async(void 0, null, function* () {
197
- const chunks = [];
198
- if ("pipeTo" in stream) {
199
- const writableStream = new WritableStream({
200
- write(chunk) {
201
- chunks.push(chunk);
202
- }
203
- });
204
- yield stream.pipeTo(writableStream);
205
- } else {
206
- throw new Error(
207
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
208
- {
209
- cause: {
210
- stream
211
- }
212
- }
213
- );
214
- }
215
- let length = 0;
216
- chunks.forEach((item) => {
217
- length += item.length;
218
- });
219
- const mergedChunks = new Uint8Array(length);
220
- let offset = 0;
221
- chunks.forEach((item) => {
222
- mergedChunks.set(item, offset);
223
- offset += item.length;
224
- });
225
- return decoder2.decode(mergedChunks);
226
- });
227
-
228
- // src/browser/render-async.tsx
229
- import { jsx as jsx2 } from "react/jsx-runtime";
230
- var renderAsync = (element, options) => __async(void 0, null, function* () {
231
- const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
232
- const reactDOMServer = yield import("react-dom/server");
233
- let html2;
234
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
235
- html2 = yield readStream2(
236
- yield reactDOMServer.renderToReadableStream(suspendedElement)
237
- );
238
- } else {
239
- yield new Promise((resolve, reject) => {
240
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
241
- onAllReady() {
242
- return __async(this, null, function* () {
243
- html2 = yield readStream2(stream);
244
- resolve();
245
- });
246
- },
247
- onError(error) {
248
- reject(error);
249
- }
250
- });
251
- });
252
- }
253
- if (options == null ? void 0 : options.plainText) {
254
- return convert2(html2, __spreadValues({
255
- selectors: plainTextSelectors
256
- }, options.htmlToTextOptions));
257
- }
258
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
259
- const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
260
- if (options == null ? void 0 : options.pretty) {
261
- return pretty(document);
262
- }
263
- return document;
264
- });
190
+ // src/browser/index.ts
191
+ var renderAsync = (element, options) => {
192
+ return render(element, options);
193
+ };
265
194
  export {
266
195
  plainTextSelectors,
267
196
  render,
@@ -17,11 +17,11 @@ type Options = {
17
17
 
18
18
  declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
19
 
20
+ declare const plainTextSelectors: SelectorDefinition[];
21
+
20
22
  /**
21
- * @deprecated use `render`
23
+ * @deprecated use {@link render}
22
24
  */
23
25
  declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
26
 
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
27
  export { Options, plainTextSelectors, render, renderAsync };
@@ -17,11 +17,11 @@ type Options = {
17
17
 
18
18
  declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
19
 
20
+ declare const plainTextSelectors: SelectorDefinition[];
21
+
20
22
  /**
21
- * @deprecated use `render`
23
+ * @deprecated use {@link render}
22
24
  */
23
25
  declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
26
 
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
27
  export { Options, plainTextSelectors, render, renderAsync };
@@ -220,45 +220,10 @@ var render = (element, options) => __async(void 0, null, function* () {
220
220
  return document;
221
221
  });
222
222
 
223
- // src/node/render-async.tsx
224
- var import_html_to_text2 = require("html-to-text");
225
- var import_react2 = require("react");
226
- var import_jsx_runtime2 = require("react/jsx-runtime");
227
- var renderAsync = (element, options) => __async(void 0, null, function* () {
228
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
229
- const reactDOMServer = yield import("react-dom/server");
230
- let html2;
231
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
232
- html2 = yield readStream(
233
- yield reactDOMServer.renderToReadableStream(suspendedElement)
234
- );
235
- } else {
236
- yield new Promise((resolve, reject) => {
237
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
238
- onAllReady() {
239
- return __async(this, null, function* () {
240
- html2 = yield readStream(stream);
241
- resolve();
242
- });
243
- },
244
- onError(error) {
245
- reject(error);
246
- }
247
- });
248
- });
249
- }
250
- if (options == null ? void 0 : options.plainText) {
251
- return (0, import_html_to_text2.convert)(html2, __spreadValues({
252
- selectors: plainTextSelectors
253
- }, options.htmlToTextOptions));
254
- }
255
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
256
- const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
257
- if (options == null ? void 0 : options.pretty) {
258
- return pretty(document);
259
- }
260
- return document;
261
- });
223
+ // src/node/index.ts
224
+ var renderAsync = (element, options) => {
225
+ return render(element, options);
226
+ };
262
227
  // Annotate the CommonJS export names for ESM import in node:
263
228
  0 && (module.exports = {
264
229
  plainTextSelectors,
@@ -185,45 +185,10 @@ var render = (element, options) => __async(void 0, null, function* () {
185
185
  return document;
186
186
  });
187
187
 
188
- // src/node/render-async.tsx
189
- import { convert as convert2 } from "html-to-text";
190
- import { Suspense as Suspense2 } from "react";
191
- import { jsx as jsx2 } from "react/jsx-runtime";
192
- var renderAsync = (element, options) => __async(void 0, null, function* () {
193
- const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
194
- const reactDOMServer = yield import("react-dom/server");
195
- let html2;
196
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
197
- html2 = yield readStream(
198
- yield reactDOMServer.renderToReadableStream(suspendedElement)
199
- );
200
- } else {
201
- yield new Promise((resolve, reject) => {
202
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
203
- onAllReady() {
204
- return __async(this, null, function* () {
205
- html2 = yield readStream(stream);
206
- resolve();
207
- });
208
- },
209
- onError(error) {
210
- reject(error);
211
- }
212
- });
213
- });
214
- }
215
- if (options == null ? void 0 : options.plainText) {
216
- return convert2(html2, __spreadValues({
217
- selectors: plainTextSelectors
218
- }, options.htmlToTextOptions));
219
- }
220
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
221
- const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
222
- if (options == null ? void 0 : options.pretty) {
223
- return pretty(document);
224
- }
225
- return document;
226
- });
188
+ // src/node/index.ts
189
+ var renderAsync = (element, options) => {
190
+ return render(element, options);
191
+ };
227
192
  export {
228
193
  plainTextSelectors,
229
194
  render,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-email/render",
3
- "version": "1.0.5-canary.1",
3
+ "version": "1.0.6",
4
4
  "description": "Transform React components into HTML email templates",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/browser/index.js",
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "html-to-text": "9.0.5",
81
- "prettier": "3.4.2",
81
+ "prettier": "3.5.3",
82
82
  "react-promise-suspense": "0.3.4"
83
83
  },
84
84
  "peerDependencies": {
@@ -94,7 +94,6 @@
94
94
  "jsdom": "23.0.1",
95
95
  "tsup": "7.2.0",
96
96
  "typescript": "5.1.6",
97
- "vitest": "1.1.2",
98
97
  "tsconfig": "0.0.0"
99
98
  },
100
99
  "publishConfig": {
@@ -1,27 +0,0 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
-
3
- type Options = {
4
- pretty?: boolean;
5
- } & ({
6
- plainText?: false;
7
- } | {
8
- plainText?: true;
9
- /**
10
- * These are options you can pass down directly to the library we use for
11
- * converting the rendered email's HTML into plain text.
12
- *
13
- * @see https://github.com/html-to-text/node-html-to-text
14
- */
15
- htmlToTextOptions?: HtmlToTextOptions;
16
- });
17
-
18
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
-
20
- /**
21
- * @deprecated use `render`
22
- */
23
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
-
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
- export { Options, plainTextSelectors, render, renderAsync };
@@ -1,27 +0,0 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
-
3
- type Options = {
4
- pretty?: boolean;
5
- } & ({
6
- plainText?: false;
7
- } | {
8
- plainText?: true;
9
- /**
10
- * These are options you can pass down directly to the library we use for
11
- * converting the rendered email's HTML into plain text.
12
- *
13
- * @see https://github.com/html-to-text/node-html-to-text
14
- */
15
- htmlToTextOptions?: HtmlToTextOptions;
16
- });
17
-
18
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
-
20
- /**
21
- * @deprecated use `render`
22
- */
23
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
-
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
- export { Options, plainTextSelectors, render, renderAsync };
@@ -1,216 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- // If the importer is in node compatibility mode or this is not an ESM
36
- // file that has been converted to a CommonJS file using a Babel-
37
- // compatible transform (i.e. "__esModule" has not been set), then set
38
- // "default" to the CommonJS "module.exports" for node compatibility.
39
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
- mod
41
- ));
42
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
- var __async = (__this, __arguments, generator) => {
44
- return new Promise((resolve, reject) => {
45
- var fulfilled = (value) => {
46
- try {
47
- step(generator.next(value));
48
- } catch (e) {
49
- reject(e);
50
- }
51
- };
52
- var rejected = (value) => {
53
- try {
54
- step(generator.throw(value));
55
- } catch (e) {
56
- reject(e);
57
- }
58
- };
59
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
60
- step((generator = generator.apply(__this, __arguments)).next());
61
- });
62
- };
63
-
64
- // src/edge-light/index.ts
65
- var edge_light_exports = {};
66
- __export(edge_light_exports, {
67
- plainTextSelectors: () => plainTextSelectors,
68
- render: () => render,
69
- renderAsync: () => renderAsync
70
- });
71
- module.exports = __toCommonJS(edge_light_exports);
72
-
73
- // src/edge-light/render.tsx
74
- var import_html_to_text = require("html-to-text");
75
- var import_react = require("react");
76
-
77
- // src/shared/utils/pretty.ts
78
- var import_js_beautify = __toESM(require("js-beautify"));
79
- var defaults = {
80
- unformatted: ["code", "pre", "em", "strong", "span"],
81
- indent_inner_html: true,
82
- indent_char: " ",
83
- indent_size: 2,
84
- sep: "\n"
85
- };
86
- var pretty = (str, options = {}) => {
87
- return import_js_beautify.default.html(str, __spreadValues(__spreadValues({}, defaults), options));
88
- };
89
-
90
- // src/shared/plain-text-selectors.ts
91
- var plainTextSelectors = [
92
- { selector: "img", format: "skip" },
93
- { selector: "#__react-email-preview", format: "skip" },
94
- {
95
- selector: "a",
96
- options: { linkBrackets: false }
97
- }
98
- ];
99
-
100
- // src/shared/read-stream.browser.ts
101
- var decoder = new TextDecoder("utf-8");
102
- var readStream = (stream) => __async(void 0, null, function* () {
103
- const chunks = [];
104
- if ("pipeTo" in stream) {
105
- const writableStream = new WritableStream({
106
- write(chunk) {
107
- chunks.push(chunk);
108
- }
109
- });
110
- yield stream.pipeTo(writableStream);
111
- } else {
112
- throw new Error(
113
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
114
- {
115
- cause: {
116
- stream
117
- }
118
- }
119
- );
120
- }
121
- let length = 0;
122
- chunks.forEach((item) => {
123
- length += item.length;
124
- });
125
- const mergedChunks = new Uint8Array(length);
126
- let offset = 0;
127
- chunks.forEach((item) => {
128
- mergedChunks.set(item, offset);
129
- offset += item.length;
130
- });
131
- return decoder.decode(mergedChunks);
132
- });
133
-
134
- // src/edge-light/render.tsx
135
- var import_jsx_runtime = require("react/jsx-runtime");
136
- var render = (element, options) => __async(void 0, null, function* () {
137
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
138
- const { default: reactDOMServer } = yield import("react-dom/server.edge");
139
- let html;
140
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
141
- html = yield readStream(
142
- yield reactDOMServer.renderToReadableStream(suspendedElement)
143
- );
144
- } else {
145
- yield new Promise((resolve, reject) => {
146
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
147
- onAllReady() {
148
- return __async(this, null, function* () {
149
- html = yield readStream(stream);
150
- resolve();
151
- });
152
- },
153
- onError(error) {
154
- reject(error);
155
- }
156
- });
157
- });
158
- }
159
- if (options == null ? void 0 : options.plainText) {
160
- return (0, import_html_to_text.convert)(html, __spreadValues({
161
- selectors: plainTextSelectors
162
- }, options.htmlToTextOptions));
163
- }
164
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
165
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
166
- if (options == null ? void 0 : options.pretty) {
167
- return pretty(document);
168
- }
169
- return document;
170
- });
171
-
172
- // src/edge-light/render-async.tsx
173
- var import_html_to_text2 = require("html-to-text");
174
- var import_react2 = require("react");
175
- var import_jsx_runtime2 = require("react/jsx-runtime");
176
- var renderAsync = (element, options) => __async(void 0, null, function* () {
177
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
178
- const { default: reactDOMServer } = yield import("react-dom/server.edge");
179
- let html;
180
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
181
- html = yield readStream(
182
- yield reactDOMServer.renderToReadableStream(suspendedElement)
183
- );
184
- } else {
185
- yield new Promise((resolve, reject) => {
186
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
187
- onAllReady() {
188
- return __async(this, null, function* () {
189
- html = yield readStream(stream);
190
- resolve();
191
- });
192
- },
193
- onError(error) {
194
- reject(error);
195
- }
196
- });
197
- });
198
- }
199
- if (options == null ? void 0 : options.plainText) {
200
- return (0, import_html_to_text2.convert)(html, __spreadValues({
201
- selectors: plainTextSelectors
202
- }, options.htmlToTextOptions));
203
- }
204
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
205
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
206
- if (options == null ? void 0 : options.pretty) {
207
- return pretty(document);
208
- }
209
- return document;
210
- });
211
- // Annotate the CommonJS export names for ESM import in node:
212
- 0 && (module.exports = {
213
- plainTextSelectors,
214
- render,
215
- renderAsync
216
- });
@@ -1,180 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
37
-
38
- // src/edge-light/render.tsx
39
- import { convert } from "html-to-text";
40
- import { Suspense } from "react";
41
-
42
- // src/shared/utils/pretty.ts
43
- import jsBeautify from "js-beautify";
44
- var defaults = {
45
- unformatted: ["code", "pre", "em", "strong", "span"],
46
- indent_inner_html: true,
47
- indent_char: " ",
48
- indent_size: 2,
49
- sep: "\n"
50
- };
51
- var pretty = (str, options = {}) => {
52
- return jsBeautify.html(str, __spreadValues(__spreadValues({}, defaults), options));
53
- };
54
-
55
- // src/shared/plain-text-selectors.ts
56
- var plainTextSelectors = [
57
- { selector: "img", format: "skip" },
58
- { selector: "#__react-email-preview", format: "skip" },
59
- {
60
- selector: "a",
61
- options: { linkBrackets: false }
62
- }
63
- ];
64
-
65
- // src/shared/read-stream.browser.ts
66
- var decoder = new TextDecoder("utf-8");
67
- var readStream = (stream) => __async(void 0, null, function* () {
68
- const chunks = [];
69
- if ("pipeTo" in stream) {
70
- const writableStream = new WritableStream({
71
- write(chunk) {
72
- chunks.push(chunk);
73
- }
74
- });
75
- yield stream.pipeTo(writableStream);
76
- } else {
77
- throw new Error(
78
- "For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
79
- {
80
- cause: {
81
- stream
82
- }
83
- }
84
- );
85
- }
86
- let length = 0;
87
- chunks.forEach((item) => {
88
- length += item.length;
89
- });
90
- const mergedChunks = new Uint8Array(length);
91
- let offset = 0;
92
- chunks.forEach((item) => {
93
- mergedChunks.set(item, offset);
94
- offset += item.length;
95
- });
96
- return decoder.decode(mergedChunks);
97
- });
98
-
99
- // src/edge-light/render.tsx
100
- import { jsx } from "react/jsx-runtime";
101
- var render = (element, options) => __async(void 0, null, function* () {
102
- const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
103
- const { default: reactDOMServer } = yield import("react-dom/server.edge");
104
- let html;
105
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
106
- html = yield readStream(
107
- yield reactDOMServer.renderToReadableStream(suspendedElement)
108
- );
109
- } else {
110
- yield new Promise((resolve, reject) => {
111
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
112
- onAllReady() {
113
- return __async(this, null, function* () {
114
- html = yield readStream(stream);
115
- resolve();
116
- });
117
- },
118
- onError(error) {
119
- reject(error);
120
- }
121
- });
122
- });
123
- }
124
- if (options == null ? void 0 : options.plainText) {
125
- return convert(html, __spreadValues({
126
- selectors: plainTextSelectors
127
- }, options.htmlToTextOptions));
128
- }
129
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
130
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
131
- if (options == null ? void 0 : options.pretty) {
132
- return pretty(document);
133
- }
134
- return document;
135
- });
136
-
137
- // src/edge-light/render-async.tsx
138
- import { convert as convert2 } from "html-to-text";
139
- import { Suspense as Suspense2 } from "react";
140
- import { jsx as jsx2 } from "react/jsx-runtime";
141
- var renderAsync = (element, options) => __async(void 0, null, function* () {
142
- const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
143
- const { default: reactDOMServer } = yield import("react-dom/server.edge");
144
- let html;
145
- if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
146
- html = yield readStream(
147
- yield reactDOMServer.renderToReadableStream(suspendedElement)
148
- );
149
- } else {
150
- yield new Promise((resolve, reject) => {
151
- const stream = reactDOMServer.renderToPipeableStream(suspendedElement, {
152
- onAllReady() {
153
- return __async(this, null, function* () {
154
- html = yield readStream(stream);
155
- resolve();
156
- });
157
- },
158
- onError(error) {
159
- reject(error);
160
- }
161
- });
162
- });
163
- }
164
- if (options == null ? void 0 : options.plainText) {
165
- return convert2(html, __spreadValues({
166
- selectors: plainTextSelectors
167
- }, options.htmlToTextOptions));
168
- }
169
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
170
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
171
- if (options == null ? void 0 : options.pretty) {
172
- return pretty(document);
173
- }
174
- return document;
175
- });
176
- export {
177
- plainTextSelectors,
178
- render,
179
- renderAsync
180
- };
package/dist/index.d.mts DELETED
@@ -1,27 +0,0 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
-
3
- type Options = {
4
- pretty?: boolean;
5
- } & ({
6
- plainText?: false;
7
- } | {
8
- plainText?: true;
9
- /**
10
- * These are options you can pass down directly to the library we use for
11
- * converting the rendered email's HTML into plain text.
12
- *
13
- * @see https://github.com/html-to-text/node-html-to-text
14
- */
15
- htmlToTextOptions?: HtmlToTextOptions;
16
- });
17
-
18
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
-
20
- /**
21
- * @deprecated use `render`
22
- */
23
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
-
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
- export { Options, plainTextSelectors, render, renderAsync };
package/dist/index.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
-
3
- type Options = {
4
- pretty?: boolean;
5
- } & ({
6
- plainText?: false;
7
- } | {
8
- plainText?: true;
9
- /**
10
- * These are options you can pass down directly to the library we use for
11
- * converting the rendered email's HTML into plain text.
12
- *
13
- * @see https://github.com/html-to-text/node-html-to-text
14
- */
15
- htmlToTextOptions?: HtmlToTextOptions;
16
- });
17
-
18
- declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
19
-
20
- /**
21
- * @deprecated use `render`
22
- */
23
- declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
24
-
25
- declare const plainTextSelectors: SelectorDefinition[];
26
-
27
- export { Options, plainTextSelectors, render, renderAsync };
package/dist/index.js DELETED
@@ -1,144 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- // If the importer is in node compatibility mode or this is not an ESM
36
- // file that has been converted to a CommonJS file using a Babel-
37
- // compatible transform (i.e. "__esModule" has not been set), then set
38
- // "default" to the CommonJS "module.exports" for node compatibility.
39
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
- mod
41
- ));
42
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
- var __async = (__this, __arguments, generator) => {
44
- return new Promise((resolve, reject) => {
45
- var fulfilled = (value) => {
46
- try {
47
- step(generator.next(value));
48
- } catch (e) {
49
- reject(e);
50
- }
51
- };
52
- var rejected = (value) => {
53
- try {
54
- step(generator.throw(value));
55
- } catch (e) {
56
- reject(e);
57
- }
58
- };
59
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
60
- step((generator = generator.apply(__this, __arguments)).next());
61
- });
62
- };
63
-
64
- // src/index.ts
65
- var src_exports = {};
66
- __export(src_exports, {
67
- plainTextSelectors: () => plainTextSelectors,
68
- render: () => render,
69
- renderAsync: () => renderAsync
70
- });
71
- module.exports = __toCommonJS(src_exports);
72
-
73
- // src/render.tsx
74
- var import_html_to_text = require("html-to-text");
75
- var import_react_markup = require("react-markup");
76
- var import_react = require("react");
77
-
78
- // src/shared/utils/pretty.ts
79
- var import_js_beautify = __toESM(require("js-beautify"));
80
- var defaults = {
81
- unformatted: ["code", "pre", "em", "strong", "span"],
82
- indent_inner_html: true,
83
- indent_char: " ",
84
- indent_size: 2,
85
- sep: "\n"
86
- };
87
- var pretty = (str, options = {}) => {
88
- return import_js_beautify.default.html(str, __spreadValues(__spreadValues({}, defaults), options));
89
- };
90
-
91
- // src/shared/plain-text-selectors.ts
92
- var plainTextSelectors = [
93
- { selector: "img", format: "skip" },
94
- { selector: "#__react-email-preview", format: "skip" },
95
- {
96
- selector: "a",
97
- options: { linkBrackets: false }
98
- }
99
- ];
100
-
101
- // src/render.tsx
102
- var import_jsx_runtime = require("react/jsx-runtime");
103
- var render = (element, options) => __async(void 0, null, function* () {
104
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: element });
105
- const html = yield (0, import_react_markup.experimental_renderToHTML)(suspendedElement);
106
- if (options == null ? void 0 : options.plainText) {
107
- return (0, import_html_to_text.convert)(html, __spreadValues({
108
- selectors: plainTextSelectors
109
- }, options.htmlToTextOptions));
110
- }
111
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
112
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
113
- if (options == null ? void 0 : options.pretty) {
114
- return pretty(document);
115
- }
116
- return document;
117
- });
118
-
119
- // src/render-async.tsx
120
- var import_html_to_text2 = require("html-to-text");
121
- var import_react2 = require("react");
122
- var import_react_markup2 = require("react-markup");
123
- var import_jsx_runtime2 = require("react/jsx-runtime");
124
- var renderAsync = (element, options) => __async(void 0, null, function* () {
125
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react2.Suspense, { children: element });
126
- const html = yield (0, import_react_markup2.experimental_renderToHTML)(suspendedElement);
127
- if (options == null ? void 0 : options.plainText) {
128
- return (0, import_html_to_text2.convert)(html, __spreadValues({
129
- selectors: plainTextSelectors
130
- }, options.htmlToTextOptions));
131
- }
132
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
133
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
134
- if (options == null ? void 0 : options.pretty) {
135
- return pretty(document);
136
- }
137
- return document;
138
- });
139
- // Annotate the CommonJS export names for ESM import in node:
140
- 0 && (module.exports = {
141
- plainTextSelectors,
142
- render,
143
- renderAsync
144
- });
package/dist/index.mjs DELETED
@@ -1,108 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
37
-
38
- // src/render.tsx
39
- import { convert } from "html-to-text";
40
- import { experimental_renderToHTML as renderToHTML } from "react-markup";
41
- import { Suspense } from "react";
42
-
43
- // src/shared/utils/pretty.ts
44
- import jsBeautify from "js-beautify";
45
- var defaults = {
46
- unformatted: ["code", "pre", "em", "strong", "span"],
47
- indent_inner_html: true,
48
- indent_char: " ",
49
- indent_size: 2,
50
- sep: "\n"
51
- };
52
- var pretty = (str, options = {}) => {
53
- return jsBeautify.html(str, __spreadValues(__spreadValues({}, defaults), options));
54
- };
55
-
56
- // src/shared/plain-text-selectors.ts
57
- var plainTextSelectors = [
58
- { selector: "img", format: "skip" },
59
- { selector: "#__react-email-preview", format: "skip" },
60
- {
61
- selector: "a",
62
- options: { linkBrackets: false }
63
- }
64
- ];
65
-
66
- // src/render.tsx
67
- import { jsx } from "react/jsx-runtime";
68
- var render = (element, options) => __async(void 0, null, function* () {
69
- const suspendedElement = /* @__PURE__ */ jsx(Suspense, { children: element });
70
- const html = yield renderToHTML(suspendedElement);
71
- if (options == null ? void 0 : options.plainText) {
72
- return convert(html, __spreadValues({
73
- selectors: plainTextSelectors
74
- }, options.htmlToTextOptions));
75
- }
76
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
77
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
78
- if (options == null ? void 0 : options.pretty) {
79
- return pretty(document);
80
- }
81
- return document;
82
- });
83
-
84
- // src/render-async.tsx
85
- import { convert as convert2 } from "html-to-text";
86
- import { Suspense as Suspense2 } from "react";
87
- import { experimental_renderToHTML as renderToHTML2 } from "react-markup";
88
- import { jsx as jsx2 } from "react/jsx-runtime";
89
- var renderAsync = (element, options) => __async(void 0, null, function* () {
90
- const suspendedElement = /* @__PURE__ */ jsx2(Suspense2, { children: element });
91
- const html = yield renderToHTML2(suspendedElement);
92
- if (options == null ? void 0 : options.plainText) {
93
- return convert2(html, __spreadValues({
94
- selectors: plainTextSelectors
95
- }, options.htmlToTextOptions));
96
- }
97
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
98
- const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
99
- if (options == null ? void 0 : options.pretty) {
100
- return pretty(document);
101
- }
102
- return document;
103
- });
104
- export {
105
- plainTextSelectors,
106
- render,
107
- renderAsync
108
- };