@react-email/render 0.0.14 → 0.0.16-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 +182 -0
- package/dist/browser/index.mjs +146 -0
- package/dist/node/index.d.mts +24 -0
- package/dist/node/index.d.ts +24 -0
- package/dist/{index.js → node/index.js} +13 -13
- package/dist/{index.mjs → node/index.mjs} +8 -15
- package/package.json +57 -14
- /package/dist/{index.d.mts → browser/index.d.mts} +0 -0
- /package/dist/{index.d.ts → browser/index.d.ts} +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
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/browser/index.ts
|
|
65
|
+
var browser_exports = {};
|
|
66
|
+
__export(browser_exports, {
|
|
67
|
+
plainTextSelectors: () => plainTextSelectors,
|
|
68
|
+
render: () => render,
|
|
69
|
+
renderAsync: () => renderAsync
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(browser_exports);
|
|
72
|
+
|
|
73
|
+
// src/shared/render.ts
|
|
74
|
+
var ReactDomServer = __toESM(require("react-dom/server"));
|
|
75
|
+
var import_html_to_text = require("html-to-text");
|
|
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/render.ts
|
|
101
|
+
var render = (component, options) => {
|
|
102
|
+
if (options == null ? void 0 : options.plainText) {
|
|
103
|
+
return renderAsPlainText(component, options);
|
|
104
|
+
}
|
|
105
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
106
|
+
const markup = ReactDomServer.renderToStaticMarkup(component);
|
|
107
|
+
const document = `${doctype}${markup}`;
|
|
108
|
+
if (options && options.pretty) {
|
|
109
|
+
return pretty(document);
|
|
110
|
+
}
|
|
111
|
+
return document;
|
|
112
|
+
};
|
|
113
|
+
var renderAsPlainText = (component, options) => {
|
|
114
|
+
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
|
|
115
|
+
selectors: plainTextSelectors
|
|
116
|
+
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/browser/render-async.ts
|
|
120
|
+
var import_html_to_text2 = require("html-to-text");
|
|
121
|
+
var decoder = new TextDecoder("utf-8");
|
|
122
|
+
var readStream = (stream) => __async(void 0, null, function* () {
|
|
123
|
+
let result = "";
|
|
124
|
+
if ("pipeTo" in stream) {
|
|
125
|
+
const writableStream = new WritableStream({
|
|
126
|
+
write(chunk) {
|
|
127
|
+
result += decoder.decode(chunk);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
yield stream.pipeTo(writableStream);
|
|
131
|
+
} else {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
|
|
134
|
+
{
|
|
135
|
+
cause: {
|
|
136
|
+
stream
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
});
|
|
143
|
+
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
144
|
+
const { default: reactDOMServer } = yield import("react-dom/server");
|
|
145
|
+
let html;
|
|
146
|
+
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
|
|
147
|
+
html = yield readStream(
|
|
148
|
+
yield reactDOMServer.renderToReadableStream(component)
|
|
149
|
+
);
|
|
150
|
+
} else {
|
|
151
|
+
yield new Promise((resolve, reject) => {
|
|
152
|
+
const stream = reactDOMServer.renderToPipeableStream(component, {
|
|
153
|
+
onAllReady() {
|
|
154
|
+
return __async(this, null, function* () {
|
|
155
|
+
html = yield readStream(stream);
|
|
156
|
+
resolve();
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
onError(error) {
|
|
160
|
+
reject(error);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (options == null ? void 0 : options.plainText) {
|
|
166
|
+
return (0, import_html_to_text2.convert)(html, __spreadValues({
|
|
167
|
+
selectors: plainTextSelectors
|
|
168
|
+
}, options.htmlToTextOptions));
|
|
169
|
+
}
|
|
170
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
171
|
+
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
172
|
+
if (options == null ? void 0 : options.pretty) {
|
|
173
|
+
return pretty(document);
|
|
174
|
+
}
|
|
175
|
+
return document;
|
|
176
|
+
});
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 && (module.exports = {
|
|
179
|
+
plainTextSelectors,
|
|
180
|
+
render,
|
|
181
|
+
renderAsync
|
|
182
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
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/shared/render.ts
|
|
39
|
+
import * as ReactDomServer from "react-dom/server";
|
|
40
|
+
import { convert } from "html-to-text";
|
|
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/render.ts
|
|
66
|
+
var render = (component, options) => {
|
|
67
|
+
if (options == null ? void 0 : options.plainText) {
|
|
68
|
+
return renderAsPlainText(component, options);
|
|
69
|
+
}
|
|
70
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
71
|
+
const markup = ReactDomServer.renderToStaticMarkup(component);
|
|
72
|
+
const document = `${doctype}${markup}`;
|
|
73
|
+
if (options && options.pretty) {
|
|
74
|
+
return pretty(document);
|
|
75
|
+
}
|
|
76
|
+
return document;
|
|
77
|
+
};
|
|
78
|
+
var renderAsPlainText = (component, options) => {
|
|
79
|
+
return convert(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
|
|
80
|
+
selectors: plainTextSelectors
|
|
81
|
+
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/browser/render-async.ts
|
|
85
|
+
import { convert as convert2 } from "html-to-text";
|
|
86
|
+
var decoder = new TextDecoder("utf-8");
|
|
87
|
+
var readStream = (stream) => __async(void 0, null, function* () {
|
|
88
|
+
let result = "";
|
|
89
|
+
if ("pipeTo" in stream) {
|
|
90
|
+
const writableStream = new WritableStream({
|
|
91
|
+
write(chunk) {
|
|
92
|
+
result += decoder.decode(chunk);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
yield stream.pipeTo(writableStream);
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error(
|
|
98
|
+
"For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
|
|
99
|
+
{
|
|
100
|
+
cause: {
|
|
101
|
+
stream
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
});
|
|
108
|
+
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
109
|
+
const { default: reactDOMServer } = yield import("react-dom/server");
|
|
110
|
+
let html;
|
|
111
|
+
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
|
|
112
|
+
html = yield readStream(
|
|
113
|
+
yield reactDOMServer.renderToReadableStream(component)
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
yield new Promise((resolve, reject) => {
|
|
117
|
+
const stream = reactDOMServer.renderToPipeableStream(component, {
|
|
118
|
+
onAllReady() {
|
|
119
|
+
return __async(this, null, function* () {
|
|
120
|
+
html = yield readStream(stream);
|
|
121
|
+
resolve();
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
onError(error) {
|
|
125
|
+
reject(error);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (options == null ? void 0 : options.plainText) {
|
|
131
|
+
return convert2(html, __spreadValues({
|
|
132
|
+
selectors: plainTextSelectors
|
|
133
|
+
}, options.htmlToTextOptions));
|
|
134
|
+
}
|
|
135
|
+
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
136
|
+
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
137
|
+
if (options == null ? void 0 : options.pretty) {
|
|
138
|
+
return pretty(document);
|
|
139
|
+
}
|
|
140
|
+
return document;
|
|
141
|
+
});
|
|
142
|
+
export {
|
|
143
|
+
plainTextSelectors,
|
|
144
|
+
render,
|
|
145
|
+
renderAsync
|
|
146
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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: (component: React.ReactElement, options?: Options) => string;
|
|
19
|
+
|
|
20
|
+
declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;
|
|
21
|
+
|
|
22
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
23
|
+
|
|
24
|
+
export { Options, plainTextSelectors, render, renderAsync };
|
|
@@ -0,0 +1,24 @@
|
|
|
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: (component: React.ReactElement, options?: Options) => string;
|
|
19
|
+
|
|
20
|
+
declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;
|
|
21
|
+
|
|
22
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
23
|
+
|
|
24
|
+
export { Options, plainTextSelectors, render, renderAsync };
|
|
@@ -61,20 +61,20 @@ var __async = (__this, __arguments, generator) => {
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
// src/index.ts
|
|
65
|
-
var
|
|
66
|
-
__export(
|
|
64
|
+
// src/node/index.ts
|
|
65
|
+
var node_exports = {};
|
|
66
|
+
__export(node_exports, {
|
|
67
67
|
plainTextSelectors: () => plainTextSelectors,
|
|
68
68
|
render: () => render,
|
|
69
69
|
renderAsync: () => renderAsync
|
|
70
70
|
});
|
|
71
|
-
module.exports = __toCommonJS(
|
|
71
|
+
module.exports = __toCommonJS(node_exports);
|
|
72
72
|
|
|
73
|
-
// src/render.ts
|
|
73
|
+
// src/shared/render.ts
|
|
74
74
|
var ReactDomServer = __toESM(require("react-dom/server"));
|
|
75
75
|
var import_html_to_text = require("html-to-text");
|
|
76
76
|
|
|
77
|
-
// src/utils/pretty.ts
|
|
77
|
+
// src/shared/utils/pretty.ts
|
|
78
78
|
var import_js_beautify = __toESM(require("js-beautify"));
|
|
79
79
|
var defaults = {
|
|
80
80
|
unformatted: ["code", "pre", "em", "strong", "span"],
|
|
@@ -87,7 +87,7 @@ var pretty = (str, options = {}) => {
|
|
|
87
87
|
return import_js_beautify.default.html(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
// src/plain-text-selectors.ts
|
|
90
|
+
// src/shared/plain-text-selectors.ts
|
|
91
91
|
var plainTextSelectors = [
|
|
92
92
|
{ selector: "img", format: "skip" },
|
|
93
93
|
{ selector: "#__react-email-preview", format: "skip" },
|
|
@@ -97,7 +97,7 @@ var plainTextSelectors = [
|
|
|
97
97
|
}
|
|
98
98
|
];
|
|
99
99
|
|
|
100
|
-
// src/render.ts
|
|
100
|
+
// src/shared/render.ts
|
|
101
101
|
var render = (component, options) => {
|
|
102
102
|
if (options == null ? void 0 : options.plainText) {
|
|
103
103
|
return renderAsPlainText(component, options);
|
|
@@ -116,7 +116,8 @@ var renderAsPlainText = (component, options) => {
|
|
|
116
116
|
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
// src/render-async.ts
|
|
119
|
+
// src/node/render-async.ts
|
|
120
|
+
var import_node_stream = require("stream");
|
|
120
121
|
var import_html_to_text2 = require("html-to-text");
|
|
121
122
|
var decoder = new TextDecoder("utf-8");
|
|
122
123
|
var readStream = (stream) => __async(void 0, null, function* () {
|
|
@@ -129,8 +130,7 @@ var readStream = (stream) => __async(void 0, null, function* () {
|
|
|
129
130
|
});
|
|
130
131
|
yield stream.pipeTo(writableStream);
|
|
131
132
|
} else {
|
|
132
|
-
const
|
|
133
|
-
const writable = new Writable({
|
|
133
|
+
const writable = new import_node_stream.Writable({
|
|
134
134
|
write(chunk, _encoding, callback) {
|
|
135
135
|
result += decoder.decode(chunk);
|
|
136
136
|
callback();
|
|
@@ -147,7 +147,7 @@ var readStream = (stream) => __async(void 0, null, function* () {
|
|
|
147
147
|
return result;
|
|
148
148
|
});
|
|
149
149
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
150
|
-
const reactDOMServer = yield import("react-dom/server");
|
|
150
|
+
const { default: reactDOMServer } = yield import("react-dom/server");
|
|
151
151
|
let html;
|
|
152
152
|
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
|
|
153
153
|
html = yield readStream(
|
|
@@ -174,7 +174,7 @@ var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
|
174
174
|
}, options.htmlToTextOptions));
|
|
175
175
|
}
|
|
176
176
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
177
|
-
const document = `${doctype}${html}`;
|
|
177
|
+
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
178
178
|
if (options == null ? void 0 : options.pretty) {
|
|
179
179
|
return pretty(document);
|
|
180
180
|
}
|
|
@@ -14,13 +14,6 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
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
|
-
});
|
|
24
17
|
var __async = (__this, __arguments, generator) => {
|
|
25
18
|
return new Promise((resolve, reject) => {
|
|
26
19
|
var fulfilled = (value) => {
|
|
@@ -42,11 +35,11 @@ var __async = (__this, __arguments, generator) => {
|
|
|
42
35
|
});
|
|
43
36
|
};
|
|
44
37
|
|
|
45
|
-
// src/render.ts
|
|
38
|
+
// src/shared/render.ts
|
|
46
39
|
import * as ReactDomServer from "react-dom/server";
|
|
47
40
|
import { convert } from "html-to-text";
|
|
48
41
|
|
|
49
|
-
// src/utils/pretty.ts
|
|
42
|
+
// src/shared/utils/pretty.ts
|
|
50
43
|
import jsBeautify from "js-beautify";
|
|
51
44
|
var defaults = {
|
|
52
45
|
unformatted: ["code", "pre", "em", "strong", "span"],
|
|
@@ -59,7 +52,7 @@ var pretty = (str, options = {}) => {
|
|
|
59
52
|
return jsBeautify.html(str, __spreadValues(__spreadValues({}, defaults), options));
|
|
60
53
|
};
|
|
61
54
|
|
|
62
|
-
// src/plain-text-selectors.ts
|
|
55
|
+
// src/shared/plain-text-selectors.ts
|
|
63
56
|
var plainTextSelectors = [
|
|
64
57
|
{ selector: "img", format: "skip" },
|
|
65
58
|
{ selector: "#__react-email-preview", format: "skip" },
|
|
@@ -69,7 +62,7 @@ var plainTextSelectors = [
|
|
|
69
62
|
}
|
|
70
63
|
];
|
|
71
64
|
|
|
72
|
-
// src/render.ts
|
|
65
|
+
// src/shared/render.ts
|
|
73
66
|
var render = (component, options) => {
|
|
74
67
|
if (options == null ? void 0 : options.plainText) {
|
|
75
68
|
return renderAsPlainText(component, options);
|
|
@@ -88,7 +81,8 @@ var renderAsPlainText = (component, options) => {
|
|
|
88
81
|
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
|
|
89
82
|
};
|
|
90
83
|
|
|
91
|
-
// src/render-async.ts
|
|
84
|
+
// src/node/render-async.ts
|
|
85
|
+
import { Writable } from "node:stream";
|
|
92
86
|
import { convert as convert2 } from "html-to-text";
|
|
93
87
|
var decoder = new TextDecoder("utf-8");
|
|
94
88
|
var readStream = (stream) => __async(void 0, null, function* () {
|
|
@@ -101,7 +95,6 @@ var readStream = (stream) => __async(void 0, null, function* () {
|
|
|
101
95
|
});
|
|
102
96
|
yield stream.pipeTo(writableStream);
|
|
103
97
|
} else {
|
|
104
|
-
const { Writable } = __require("stream");
|
|
105
98
|
const writable = new Writable({
|
|
106
99
|
write(chunk, _encoding, callback) {
|
|
107
100
|
result += decoder.decode(chunk);
|
|
@@ -119,7 +112,7 @@ var readStream = (stream) => __async(void 0, null, function* () {
|
|
|
119
112
|
return result;
|
|
120
113
|
});
|
|
121
114
|
var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
122
|
-
const reactDOMServer = yield import("react-dom/server");
|
|
115
|
+
const { default: reactDOMServer } = yield import("react-dom/server");
|
|
123
116
|
let html;
|
|
124
117
|
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
|
|
125
118
|
html = yield readStream(
|
|
@@ -146,7 +139,7 @@ var renderAsync = (component, options) => __async(void 0, null, function* () {
|
|
|
146
139
|
}, options.htmlToTextOptions));
|
|
147
140
|
}
|
|
148
141
|
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
|
|
149
|
-
const document = `${doctype}${html}`;
|
|
142
|
+
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
150
143
|
if (options == null ? void 0 : options.pretty) {
|
|
151
144
|
return pretty(document);
|
|
152
145
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-email/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16-canary.0",
|
|
4
4
|
"description": "Transform React components into HTML email templates",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/browser/index.js",
|
|
7
|
+
"module": "./dist/browser/index.mjs",
|
|
8
|
+
"types": "./dist/browser/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**"
|
|
11
11
|
],
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
14
|
+
"node": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/node/index.d.mts",
|
|
17
|
+
"default": "./dist/node/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/node/index.d.ts",
|
|
21
|
+
"default": "./dist/node/index.js"
|
|
22
|
+
}
|
|
17
23
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
24
|
+
"deno": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/browser/index.d.mts",
|
|
27
|
+
"default": "./dist/browser/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/browser/index.d.ts",
|
|
31
|
+
"default": "./dist/browser/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"worker": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/browser/index.d.mts",
|
|
37
|
+
"default": "./dist/browser/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/browser/index.d.ts",
|
|
41
|
+
"default": "./dist/browser/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"browser": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/browser/index.d.mts",
|
|
47
|
+
"default": "./dist/browser/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/browser/index.d.ts",
|
|
51
|
+
"default": "./dist/browser/index.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"default": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/node/index.d.mts",
|
|
57
|
+
"default": "./dist/node/index.mjs"
|
|
58
|
+
},
|
|
59
|
+
"require": {
|
|
60
|
+
"types": "./dist/node/index.d.ts",
|
|
61
|
+
"default": "./dist/node/index.js"
|
|
62
|
+
}
|
|
21
63
|
}
|
|
22
64
|
}
|
|
23
65
|
},
|
|
@@ -47,6 +89,7 @@
|
|
|
47
89
|
"@types/html-to-text": "9.0.4",
|
|
48
90
|
"@types/js-beautify": "1.14.3",
|
|
49
91
|
"jsdom": "23.0.1",
|
|
92
|
+
"tsup": "7.2.0",
|
|
50
93
|
"typescript": "5.1.6",
|
|
51
94
|
"vitest": "1.1.2",
|
|
52
95
|
"eslint-config-custom": "0.0.0",
|
|
@@ -56,11 +99,11 @@
|
|
|
56
99
|
"access": "public"
|
|
57
100
|
},
|
|
58
101
|
"scripts": {
|
|
59
|
-
"build": "tsup
|
|
102
|
+
"build": "tsup-node",
|
|
60
103
|
"clean": "rm -rf dist",
|
|
61
|
-
"dev": "tsup
|
|
104
|
+
"dev": "tsup-node --watch",
|
|
62
105
|
"lint": "eslint .",
|
|
63
|
-
"test
|
|
64
|
-
"test": "vitest
|
|
106
|
+
"test": "vitest run",
|
|
107
|
+
"test:watch": "vitest"
|
|
65
108
|
}
|
|
66
109
|
}
|
|
File without changes
|
|
File without changes
|