@react-email/render 1.0.4 → 1.0.5-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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __export = (target, all) => {
23
26
  for (var name in all)
24
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -74,19 +77,6 @@ module.exports = __toCommonJS(browser_exports);
74
77
  var import_html_to_text = require("html-to-text");
75
78
  var import_react = require("react");
76
79
 
77
- // src/shared/utils/pretty.ts
78
- var import_standalone = require("prettier/standalone");
79
- var import_html = __toESM(require("prettier/plugins/html"));
80
- var defaults = {
81
- endOfLine: "lf",
82
- tabWidth: 2,
83
- plugins: [import_html.default],
84
- parser: "html"
85
- };
86
- var pretty = (str, options = {}) => {
87
- return (0, import_standalone.format)(str, __spreadValues(__spreadValues({}, defaults), options));
88
- };
89
-
90
80
  // src/shared/plain-text-selectors.ts
91
81
  var plainTextSelectors = [
92
82
  { selector: "img", format: "skip" },
@@ -97,6 +87,71 @@ var plainTextSelectors = [
97
87
  }
98
88
  ];
99
89
 
90
+ // src/shared/utils/pretty.ts
91
+ var import_html = __toESM(require("prettier/plugins/html"));
92
+ var import_standalone = require("prettier/standalone");
93
+ function recursivelyMapDoc(doc, callback) {
94
+ if (Array.isArray(doc)) {
95
+ return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
96
+ }
97
+ if (typeof doc === "object") {
98
+ if (doc.type === "group") {
99
+ return __spreadProps(__spreadValues({}, doc), {
100
+ contents: recursivelyMapDoc(doc.contents, callback),
101
+ expandedStates: recursivelyMapDoc(
102
+ doc.expandedStates,
103
+ callback
104
+ )
105
+ });
106
+ }
107
+ if ("contents" in doc) {
108
+ return __spreadProps(__spreadValues({}, doc), {
109
+ contents: recursivelyMapDoc(doc.contents, callback)
110
+ });
111
+ }
112
+ if ("parts" in doc) {
113
+ return __spreadProps(__spreadValues({}, doc), {
114
+ parts: recursivelyMapDoc(doc.parts, callback)
115
+ });
116
+ }
117
+ if (doc.type === "if-break") {
118
+ return __spreadProps(__spreadValues({}, doc), {
119
+ breakContents: recursivelyMapDoc(doc.breakContents, callback),
120
+ flatContents: recursivelyMapDoc(doc.flatContents, callback)
121
+ });
122
+ }
123
+ }
124
+ return callback(doc);
125
+ }
126
+ var modifiedHtml = __spreadValues({}, import_html.default);
127
+ if (modifiedHtml.printers) {
128
+ const previousPrint = modifiedHtml.printers.html.print;
129
+ modifiedHtml.printers.html.print = (path, options, print, args) => {
130
+ const node = path.getNode();
131
+ const rawPrintingResult = previousPrint(path, options, print, args);
132
+ if (node.type === "ieConditionalComment") {
133
+ const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
134
+ if (typeof doc === "object" && doc.type === "line") {
135
+ return doc.soft ? "" : " ";
136
+ }
137
+ return doc;
138
+ });
139
+ return printingResult;
140
+ }
141
+ return rawPrintingResult;
142
+ };
143
+ }
144
+ var defaults = {
145
+ endOfLine: "lf",
146
+ tabWidth: 2,
147
+ plugins: [modifiedHtml],
148
+ bracketSameLine: true,
149
+ parser: "html"
150
+ };
151
+ var pretty = (str, options = {}) => {
152
+ return (0, import_standalone.format)(str.replaceAll("\0", ""), __spreadValues(__spreadValues({}, defaults), options));
153
+ };
154
+
100
155
  // src/browser/render.tsx
101
156
  var import_jsx_runtime = require("react/jsx-runtime");
102
157
  var decoder = new TextDecoder("utf-8");
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  var __async = (__this, __arguments, generator) => {
18
21
  return new Promise((resolve, reject) => {
19
22
  var fulfilled = (value) => {
@@ -39,19 +42,6 @@ var __async = (__this, __arguments, generator) => {
39
42
  import { convert } from "html-to-text";
40
43
  import { Suspense } from "react";
41
44
 
42
- // src/shared/utils/pretty.ts
43
- import { format } from "prettier/standalone";
44
- import html from "prettier/plugins/html";
45
- var defaults = {
46
- endOfLine: "lf",
47
- tabWidth: 2,
48
- plugins: [html],
49
- parser: "html"
50
- };
51
- var pretty = (str, options = {}) => {
52
- return format(str, __spreadValues(__spreadValues({}, defaults), options));
53
- };
54
-
55
45
  // src/shared/plain-text-selectors.ts
56
46
  var plainTextSelectors = [
57
47
  { selector: "img", format: "skip" },
@@ -62,6 +52,71 @@ var plainTextSelectors = [
62
52
  }
63
53
  ];
64
54
 
55
+ // src/shared/utils/pretty.ts
56
+ import html from "prettier/plugins/html";
57
+ import { format } from "prettier/standalone";
58
+ function recursivelyMapDoc(doc, callback) {
59
+ if (Array.isArray(doc)) {
60
+ return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
61
+ }
62
+ if (typeof doc === "object") {
63
+ if (doc.type === "group") {
64
+ return __spreadProps(__spreadValues({}, doc), {
65
+ contents: recursivelyMapDoc(doc.contents, callback),
66
+ expandedStates: recursivelyMapDoc(
67
+ doc.expandedStates,
68
+ callback
69
+ )
70
+ });
71
+ }
72
+ if ("contents" in doc) {
73
+ return __spreadProps(__spreadValues({}, doc), {
74
+ contents: recursivelyMapDoc(doc.contents, callback)
75
+ });
76
+ }
77
+ if ("parts" in doc) {
78
+ return __spreadProps(__spreadValues({}, doc), {
79
+ parts: recursivelyMapDoc(doc.parts, callback)
80
+ });
81
+ }
82
+ if (doc.type === "if-break") {
83
+ return __spreadProps(__spreadValues({}, doc), {
84
+ breakContents: recursivelyMapDoc(doc.breakContents, callback),
85
+ flatContents: recursivelyMapDoc(doc.flatContents, callback)
86
+ });
87
+ }
88
+ }
89
+ return callback(doc);
90
+ }
91
+ var modifiedHtml = __spreadValues({}, html);
92
+ if (modifiedHtml.printers) {
93
+ const previousPrint = modifiedHtml.printers.html.print;
94
+ modifiedHtml.printers.html.print = (path, options, print, args) => {
95
+ const node = path.getNode();
96
+ const rawPrintingResult = previousPrint(path, options, print, args);
97
+ if (node.type === "ieConditionalComment") {
98
+ const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
99
+ if (typeof doc === "object" && doc.type === "line") {
100
+ return doc.soft ? "" : " ";
101
+ }
102
+ return doc;
103
+ });
104
+ return printingResult;
105
+ }
106
+ return rawPrintingResult;
107
+ };
108
+ }
109
+ var defaults = {
110
+ endOfLine: "lf",
111
+ tabWidth: 2,
112
+ plugins: [modifiedHtml],
113
+ bracketSameLine: true,
114
+ parser: "html"
115
+ };
116
+ var pretty = (str, options = {}) => {
117
+ return format(str.replaceAll("\0", ""), __spreadValues(__spreadValues({}, defaults), options));
118
+ };
119
+
65
120
  // src/browser/render.tsx
66
121
  import { jsx } from "react/jsx-runtime";
67
122
  var decoder = new TextDecoder("utf-8");
@@ -0,0 +1,27 @@
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 };
@@ -0,0 +1,27 @@
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 };
@@ -0,0 +1,216 @@
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
+ });
@@ -0,0 +1,180 @@
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 CHANGED
@@ -1,5 +1,4 @@
1
- import { HtmlToTextOptions } from 'html-to-text';
2
- import { Options as Options$1 } from 'prettier';
1
+ import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
3
2
 
4
3
  type Options = {
5
4
  pretty?: boolean;
@@ -18,6 +17,11 @@ type Options = {
18
17
 
19
18
  declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
20
19
 
21
- declare const pretty: (str: string, options?: Options$1) => Promise<string>;
20
+ /**
21
+ * @deprecated use `render`
22
+ */
23
+ declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
22
24
 
23
- export { Options, pretty, render };
25
+ declare const plainTextSelectors: SelectorDefinition[];
26
+
27
+ export { Options, plainTextSelectors, render, renderAsync };