@react-email/render 1.0.4 → 1.0.5-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/browser/index.js +27 -12
- package/dist/browser/index.mjs +27 -12
- package/dist/edge-light/index.d.mts +27 -0
- package/dist/edge-light/index.d.ts +27 -0
- package/dist/edge-light/index.js +216 -0
- package/dist/edge-light/index.mjs +180 -0
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +44 -668
- package/dist/index.mjs +41 -666
- package/dist/node/index.js +27 -12
- package/dist/node/index.mjs +27 -12
- package/package.json +1 -3
package/dist/browser/index.js
CHANGED
|
@@ -74,29 +74,44 @@ module.exports = __toCommonJS(browser_exports);
|
|
|
74
74
|
var import_html_to_text = require("html-to-text");
|
|
75
75
|
var import_react = require("react");
|
|
76
76
|
|
|
77
|
+
// src/shared/plain-text-selectors.ts
|
|
78
|
+
var plainTextSelectors = [
|
|
79
|
+
{ selector: "img", format: "skip" },
|
|
80
|
+
{ selector: "#__react-email-preview", format: "skip" },
|
|
81
|
+
{
|
|
82
|
+
selector: "a",
|
|
83
|
+
options: { linkBrackets: false }
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
|
|
77
87
|
// src/shared/utils/pretty.ts
|
|
78
|
-
var import_standalone = require("prettier/standalone");
|
|
79
88
|
var import_html = __toESM(require("prettier/plugins/html"));
|
|
89
|
+
var import_standalone = require("prettier/standalone");
|
|
90
|
+
var modifiedHtml = __spreadValues({}, import_html.default);
|
|
91
|
+
if (modifiedHtml.printers) {
|
|
92
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
93
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
94
|
+
const node = path.getNode();
|
|
95
|
+
if (node.type === "ieConditionalComment") {
|
|
96
|
+
return options.originalText.slice(
|
|
97
|
+
node.sourceSpan.start.offset,
|
|
98
|
+
node.sourceSpan.end.offset
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return previousPrint(path, options, print, args);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
80
104
|
var defaults = {
|
|
81
105
|
endOfLine: "lf",
|
|
82
106
|
tabWidth: 2,
|
|
83
|
-
plugins: [
|
|
107
|
+
plugins: [modifiedHtml],
|
|
108
|
+
bracketSameLine: true,
|
|
84
109
|
parser: "html"
|
|
85
110
|
};
|
|
86
111
|
var pretty = (str, options = {}) => {
|
|
87
112
|
return (0, import_standalone.format)(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
88
113
|
};
|
|
89
114
|
|
|
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
115
|
// src/browser/render.tsx
|
|
101
116
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
102
117
|
var decoder = new TextDecoder("utf-8");
|
package/dist/browser/index.mjs
CHANGED
|
@@ -39,29 +39,44 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
import { convert } from "html-to-text";
|
|
40
40
|
import { Suspense } from "react";
|
|
41
41
|
|
|
42
|
+
// src/shared/plain-text-selectors.ts
|
|
43
|
+
var plainTextSelectors = [
|
|
44
|
+
{ selector: "img", format: "skip" },
|
|
45
|
+
{ selector: "#__react-email-preview", format: "skip" },
|
|
46
|
+
{
|
|
47
|
+
selector: "a",
|
|
48
|
+
options: { linkBrackets: false }
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
|
|
42
52
|
// src/shared/utils/pretty.ts
|
|
43
|
-
import { format } from "prettier/standalone";
|
|
44
53
|
import html from "prettier/plugins/html";
|
|
54
|
+
import { format } from "prettier/standalone";
|
|
55
|
+
var modifiedHtml = __spreadValues({}, html);
|
|
56
|
+
if (modifiedHtml.printers) {
|
|
57
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
58
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
59
|
+
const node = path.getNode();
|
|
60
|
+
if (node.type === "ieConditionalComment") {
|
|
61
|
+
return options.originalText.slice(
|
|
62
|
+
node.sourceSpan.start.offset,
|
|
63
|
+
node.sourceSpan.end.offset
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return previousPrint(path, options, print, args);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
45
69
|
var defaults = {
|
|
46
70
|
endOfLine: "lf",
|
|
47
71
|
tabWidth: 2,
|
|
48
|
-
plugins: [
|
|
72
|
+
plugins: [modifiedHtml],
|
|
73
|
+
bracketSameLine: true,
|
|
49
74
|
parser: "html"
|
|
50
75
|
};
|
|
51
76
|
var pretty = (str, options = {}) => {
|
|
52
77
|
return format(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
53
78
|
};
|
|
54
79
|
|
|
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
80
|
// src/browser/render.tsx
|
|
66
81
|
import { jsx } from "react/jsx-runtime";
|
|
67
82
|
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
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated use `render`
|
|
22
|
+
*/
|
|
23
|
+
declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
26
|
+
|
|
27
|
+
export { Options, plainTextSelectors, render, renderAsync };
|
package/dist/index.d.ts
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
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated use `render`
|
|
22
|
+
*/
|
|
23
|
+
declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
26
|
+
|
|
27
|
+
export { Options, plainTextSelectors, render, renderAsync };
|