@depup/react-email__render 2.0.4-depup.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/README.md +31 -0
- package/changes.json +10 -0
- package/dist/browser/index.d.mts +40 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +40 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +181 -0
- package/dist/browser/index.mjs +151 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/edge/index.d.mts +40 -0
- package/dist/edge/index.d.mts.map +1 -0
- package/dist/edge/index.d.ts +40 -0
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +187 -0
- package/dist/edge/index.mjs +157 -0
- package/dist/edge/index.mjs.map +1 -0
- package/dist/node/index.d.mts +40 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +40 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +216 -0
- package/dist/node/index.mjs +185 -0
- package/dist/node/index.mjs.map +1 -0
- package/license.md +7 -0
- package/package.json +152 -0
- package/readme.md +42 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let prettier_plugins_html = require("prettier/plugins/html");
|
|
25
|
+
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
26
|
+
let prettier_standalone = require("prettier/standalone");
|
|
27
|
+
prettier_standalone = __toESM(prettier_standalone);
|
|
28
|
+
let html_to_text = require("html-to-text");
|
|
29
|
+
html_to_text = __toESM(html_to_text);
|
|
30
|
+
let react = require("react");
|
|
31
|
+
react = __toESM(react);
|
|
32
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
|
+
|
|
35
|
+
//#region src/shared/utils/pretty.ts
|
|
36
|
+
function recursivelyMapDoc(doc, callback) {
|
|
37
|
+
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
38
|
+
if (typeof doc === "object") {
|
|
39
|
+
if (doc.type === "group") return {
|
|
40
|
+
...doc,
|
|
41
|
+
contents: recursivelyMapDoc(doc.contents, callback),
|
|
42
|
+
expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
|
|
43
|
+
};
|
|
44
|
+
if ("contents" in doc) return {
|
|
45
|
+
...doc,
|
|
46
|
+
contents: recursivelyMapDoc(doc.contents, callback)
|
|
47
|
+
};
|
|
48
|
+
if ("parts" in doc) return {
|
|
49
|
+
...doc,
|
|
50
|
+
parts: recursivelyMapDoc(doc.parts, callback)
|
|
51
|
+
};
|
|
52
|
+
if (doc.type === "if-break") return {
|
|
53
|
+
...doc,
|
|
54
|
+
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
55
|
+
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return callback(doc);
|
|
59
|
+
}
|
|
60
|
+
const modifiedHtml = { ...prettier_plugins_html };
|
|
61
|
+
if (modifiedHtml.printers) {
|
|
62
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
63
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
64
|
+
const node = path.getNode();
|
|
65
|
+
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
66
|
+
if (node.type === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
67
|
+
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
68
|
+
return doc;
|
|
69
|
+
});
|
|
70
|
+
return rawPrintingResult;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const defaults = {
|
|
74
|
+
endOfLine: "lf",
|
|
75
|
+
tabWidth: 2,
|
|
76
|
+
plugins: [modifiedHtml],
|
|
77
|
+
bracketSameLine: true,
|
|
78
|
+
parser: "html"
|
|
79
|
+
};
|
|
80
|
+
const pretty = (str, options = {}) => {
|
|
81
|
+
return (0, prettier_standalone.format)(str.replaceAll("\0", ""), {
|
|
82
|
+
...defaults,
|
|
83
|
+
...options
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/shared/utils/to-plain-text.ts
|
|
89
|
+
const plainTextSelectors = [
|
|
90
|
+
{
|
|
91
|
+
selector: "img",
|
|
92
|
+
format: "skip"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
selector: "[data-skip-in-text=true]",
|
|
96
|
+
format: "skip"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
selector: "a",
|
|
100
|
+
options: {
|
|
101
|
+
linkBrackets: false,
|
|
102
|
+
hideLinkHrefIfSameAsText: true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
function toPlainText(html, options) {
|
|
107
|
+
return (0, html_to_text.convert)(html, {
|
|
108
|
+
wordwrap: false,
|
|
109
|
+
...options,
|
|
110
|
+
selectors: [...plainTextSelectors, ...options?.selectors ?? []]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/shared/error-boundary.tsx
|
|
116
|
+
function createErrorBoundary(reject) {
|
|
117
|
+
if (!react.default.Component) return (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.children });
|
|
118
|
+
return class ErrorBoundary extends react.default.Component {
|
|
119
|
+
componentDidCatch(error) {
|
|
120
|
+
reject(error);
|
|
121
|
+
}
|
|
122
|
+
render() {
|
|
123
|
+
return this.props.children;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/shared/read-stream.browser.ts
|
|
130
|
+
const decoder = new TextDecoder("utf-8");
|
|
131
|
+
const readStream = async (stream) => {
|
|
132
|
+
const chunks = [];
|
|
133
|
+
const writableStream = new WritableStream({
|
|
134
|
+
write(chunk) {
|
|
135
|
+
chunks.push(chunk);
|
|
136
|
+
},
|
|
137
|
+
abort(reason) {
|
|
138
|
+
throw new Error("Stream aborted", { cause: { reason } });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
await stream.pipeTo(writableStream);
|
|
142
|
+
let length = 0;
|
|
143
|
+
chunks.forEach((item) => {
|
|
144
|
+
length += item.length;
|
|
145
|
+
});
|
|
146
|
+
const mergedChunks = new Uint8Array(length);
|
|
147
|
+
let offset = 0;
|
|
148
|
+
chunks.forEach((item) => {
|
|
149
|
+
mergedChunks.set(item, offset);
|
|
150
|
+
offset += item.length;
|
|
151
|
+
});
|
|
152
|
+
return decoder.decode(mergedChunks);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/edge/import-react-dom.tsx
|
|
157
|
+
const importReactDom = () => {
|
|
158
|
+
return import("react-dom/server.edge").catch(() => import("react-dom/server"));
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/edge/render.tsx
|
|
163
|
+
const render = async (element, options) => {
|
|
164
|
+
const reactDOMServer = await importReactDom().then((m) => {
|
|
165
|
+
if ("default" in m) return m.default;
|
|
166
|
+
return m;
|
|
167
|
+
});
|
|
168
|
+
const html = await new Promise((resolve, reject) => {
|
|
169
|
+
const ErrorBoundary = createErrorBoundary(reject);
|
|
170
|
+
reactDOMServer.renderToReadableStream(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: element }) }), {
|
|
171
|
+
onError(error) {
|
|
172
|
+
reject(error);
|
|
173
|
+
},
|
|
174
|
+
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
175
|
+
}).then(readStream).then(resolve).catch(reject);
|
|
176
|
+
});
|
|
177
|
+
if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
|
|
178
|
+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
179
|
+
if (options?.pretty) return pretty(document);
|
|
180
|
+
return document;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
exports.plainTextSelectors = plainTextSelectors;
|
|
185
|
+
exports.pretty = pretty;
|
|
186
|
+
exports.render = render;
|
|
187
|
+
exports.toPlainText = toPlainText;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import * as html from "prettier/plugins/html";
|
|
2
|
+
import { format } from "prettier/standalone";
|
|
3
|
+
import { convert } from "html-to-text";
|
|
4
|
+
import React, { Suspense } from "react";
|
|
5
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/shared/utils/pretty.ts
|
|
8
|
+
function recursivelyMapDoc(doc, callback) {
|
|
9
|
+
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
10
|
+
if (typeof doc === "object") {
|
|
11
|
+
if (doc.type === "group") return {
|
|
12
|
+
...doc,
|
|
13
|
+
contents: recursivelyMapDoc(doc.contents, callback),
|
|
14
|
+
expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
|
|
15
|
+
};
|
|
16
|
+
if ("contents" in doc) return {
|
|
17
|
+
...doc,
|
|
18
|
+
contents: recursivelyMapDoc(doc.contents, callback)
|
|
19
|
+
};
|
|
20
|
+
if ("parts" in doc) return {
|
|
21
|
+
...doc,
|
|
22
|
+
parts: recursivelyMapDoc(doc.parts, callback)
|
|
23
|
+
};
|
|
24
|
+
if (doc.type === "if-break") return {
|
|
25
|
+
...doc,
|
|
26
|
+
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
27
|
+
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return callback(doc);
|
|
31
|
+
}
|
|
32
|
+
const modifiedHtml = { ...html };
|
|
33
|
+
if (modifiedHtml.printers) {
|
|
34
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
35
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
36
|
+
const node = path.getNode();
|
|
37
|
+
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
38
|
+
if (node.type === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
39
|
+
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
40
|
+
return doc;
|
|
41
|
+
});
|
|
42
|
+
return rawPrintingResult;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const defaults = {
|
|
46
|
+
endOfLine: "lf",
|
|
47
|
+
tabWidth: 2,
|
|
48
|
+
plugins: [modifiedHtml],
|
|
49
|
+
bracketSameLine: true,
|
|
50
|
+
parser: "html"
|
|
51
|
+
};
|
|
52
|
+
const pretty = (str, options = {}) => {
|
|
53
|
+
return format(str.replaceAll("\0", ""), {
|
|
54
|
+
...defaults,
|
|
55
|
+
...options
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/shared/utils/to-plain-text.ts
|
|
61
|
+
const plainTextSelectors = [
|
|
62
|
+
{
|
|
63
|
+
selector: "img",
|
|
64
|
+
format: "skip"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
selector: "[data-skip-in-text=true]",
|
|
68
|
+
format: "skip"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
selector: "a",
|
|
72
|
+
options: {
|
|
73
|
+
linkBrackets: false,
|
|
74
|
+
hideLinkHrefIfSameAsText: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
function toPlainText(html$1, options) {
|
|
79
|
+
return convert(html$1, {
|
|
80
|
+
wordwrap: false,
|
|
81
|
+
...options,
|
|
82
|
+
selectors: [...plainTextSelectors, ...options?.selectors ?? []]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/shared/error-boundary.tsx
|
|
88
|
+
function createErrorBoundary(reject) {
|
|
89
|
+
if (!React.Component) return (props) => /* @__PURE__ */ jsx(Fragment, { children: props.children });
|
|
90
|
+
return class ErrorBoundary extends React.Component {
|
|
91
|
+
componentDidCatch(error) {
|
|
92
|
+
reject(error);
|
|
93
|
+
}
|
|
94
|
+
render() {
|
|
95
|
+
return this.props.children;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/shared/read-stream.browser.ts
|
|
102
|
+
const decoder = new TextDecoder("utf-8");
|
|
103
|
+
const readStream = async (stream) => {
|
|
104
|
+
const chunks = [];
|
|
105
|
+
const writableStream = new WritableStream({
|
|
106
|
+
write(chunk) {
|
|
107
|
+
chunks.push(chunk);
|
|
108
|
+
},
|
|
109
|
+
abort(reason) {
|
|
110
|
+
throw new Error("Stream aborted", { cause: { reason } });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
await stream.pipeTo(writableStream);
|
|
114
|
+
let length = 0;
|
|
115
|
+
chunks.forEach((item) => {
|
|
116
|
+
length += item.length;
|
|
117
|
+
});
|
|
118
|
+
const mergedChunks = new Uint8Array(length);
|
|
119
|
+
let offset = 0;
|
|
120
|
+
chunks.forEach((item) => {
|
|
121
|
+
mergedChunks.set(item, offset);
|
|
122
|
+
offset += item.length;
|
|
123
|
+
});
|
|
124
|
+
return decoder.decode(mergedChunks);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/edge/import-react-dom.tsx
|
|
129
|
+
const importReactDom = () => {
|
|
130
|
+
return import("react-dom/server.edge").catch(() => import("react-dom/server"));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/edge/render.tsx
|
|
135
|
+
const render = async (element, options) => {
|
|
136
|
+
const reactDOMServer = await importReactDom().then((m) => {
|
|
137
|
+
if ("default" in m) return m.default;
|
|
138
|
+
return m;
|
|
139
|
+
});
|
|
140
|
+
const html$1 = await new Promise((resolve, reject) => {
|
|
141
|
+
const ErrorBoundary = createErrorBoundary(reject);
|
|
142
|
+
reactDOMServer.renderToReadableStream(/* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Suspense, { children: element }) }), {
|
|
143
|
+
onError(error) {
|
|
144
|
+
reject(error);
|
|
145
|
+
},
|
|
146
|
+
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
147
|
+
}).then(readStream).then(resolve).catch(reject);
|
|
148
|
+
});
|
|
149
|
+
if (options?.plainText) return toPlainText(html$1, options.htmlToTextOptions);
|
|
150
|
+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">${html$1.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
151
|
+
if (options?.pretty) return pretty(document);
|
|
152
|
+
return document;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { plainTextSelectors, pretty, render, toPlainText };
|
|
157
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["defaults: Options","plainTextSelectors: SelectorDefinition[]","html","chunks: Uint8Array[]","html"],"sources":["../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/shared/error-boundary.tsx","../../src/shared/read-stream.browser.ts","../../src/edge/import-react-dom.tsx","../../src/edge/render.tsx"],"sourcesContent":["import type { Options, Plugin } from 'prettier';\nimport type { builders } from 'prettier/doc';\nimport * as html from 'prettier/plugins/html';\nimport { format } from 'prettier/standalone';\n\ninterface HtmlNode {\n type: 'element' | 'text' | 'ieConditionalComment';\n name?: string;\n sourceSpan: {\n start: { file: unknown[]; offset: number; line: number; col: number };\n end: { file: unknown[]; offset: number; line: number; col: number };\n details: null;\n };\n parent?: HtmlNode;\n}\n\nfunction recursivelyMapDoc(\n doc: builders.Doc,\n callback: (innerDoc: string | builders.DocCommand) => builders.Doc,\n): builders.Doc {\n if (Array.isArray(doc)) {\n return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));\n }\n\n if (typeof doc === 'object') {\n if (doc.type === 'group') {\n return {\n ...doc,\n contents: recursivelyMapDoc(doc.contents, callback),\n expandedStates: recursivelyMapDoc(\n doc.expandedStates,\n callback,\n ) as builders.Doc[],\n };\n }\n\n if ('contents' in doc) {\n return {\n ...doc,\n contents: recursivelyMapDoc(doc.contents, callback),\n };\n }\n\n if ('parts' in doc) {\n return {\n ...doc,\n parts: recursivelyMapDoc(doc.parts, callback) as builders.Doc[],\n };\n }\n\n if (doc.type === 'if-break') {\n return {\n ...doc,\n breakContents: recursivelyMapDoc(doc.breakContents, callback),\n flatContents: recursivelyMapDoc(doc.flatContents, callback),\n };\n }\n }\n\n return callback(doc);\n}\n\nconst modifiedHtml = { ...html } as Plugin;\nif (modifiedHtml.printers) {\n const previousPrint = modifiedHtml.printers.html.print;\n modifiedHtml.printers.html.print = (path, options, print, args) => {\n const node = path.getNode() as HtmlNode;\n\n const rawPrintingResult = previousPrint(path, options, print, args);\n\n if (node.type === 'ieConditionalComment') {\n const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {\n if (typeof doc === 'object' && doc.type === 'line') {\n return doc.soft ? '' : ' ';\n }\n\n return doc;\n });\n\n return printingResult;\n }\n\n return rawPrintingResult;\n };\n}\n\nconst defaults: Options = {\n endOfLine: 'lf',\n tabWidth: 2,\n plugins: [modifiedHtml],\n bracketSameLine: true,\n parser: 'html',\n};\n\nexport const pretty = (str: string, options: Options = {}) => {\n return format(str.replaceAll('\\0', ''), {\n ...defaults,\n ...options,\n });\n};\n","import {\n convert,\n type HtmlToTextOptions,\n type SelectorDefinition,\n} from 'html-to-text';\n\nexport const plainTextSelectors: SelectorDefinition[] = [\n { selector: 'img', format: 'skip' },\n { selector: '[data-skip-in-text=true]', format: 'skip' },\n {\n selector: 'a',\n options: { linkBrackets: false, hideLinkHrefIfSameAsText: true },\n },\n];\n\nexport function toPlainText(html: string, options?: HtmlToTextOptions) {\n return convert(html, {\n wordwrap: false,\n ...options,\n selectors: [...plainTextSelectors, ...(options?.selectors ?? [])],\n });\n}\n","import React from 'react';\n\nexport function createErrorBoundary(reject: (error: unknown) => void) {\n // React Server Components don't support React.Component, so it's just not defined here\n if (!React.Component) {\n return (props: { children?: React.ReactNode }) => <>{props.children}</>;\n }\n\n return class ErrorBoundary extends React.Component<{\n children: React.ReactNode;\n }> {\n componentDidCatch(error: unknown) {\n reject(error);\n }\n render() {\n return this.props.children;\n }\n };\n}\n","import type { ReactDOMServerReadableStream } from 'react-dom/server.browser';\n\nconst decoder = new TextDecoder('utf-8');\n\nexport const readStream = async (stream: ReactDOMServerReadableStream) => {\n const chunks: Uint8Array[] = [];\n\n const writableStream = new WritableStream({\n write(chunk: Uint8Array) {\n chunks.push(chunk);\n },\n abort(reason) {\n throw new Error('Stream aborted', {\n cause: {\n reason,\n },\n });\n },\n });\n await stream.pipeTo(writableStream);\n\n let length = 0;\n chunks.forEach((item) => {\n length += item.length;\n });\n const mergedChunks = new Uint8Array(length);\n let offset = 0;\n chunks.forEach((item) => {\n mergedChunks.set(item, offset);\n offset += item.length;\n });\n\n return decoder.decode(mergedChunks);\n};\n","export const importReactDom = () => {\n // We don't use async here because tsup converts it to a generator syntax\n // that esbuild doesn't understand as dealing with the import failing during\n // bundling: https://github.com/evanw/esbuild/issues/3216#issuecomment-1628913722\n return import('react-dom/server.edge').catch(\n () =>\n // This ensures that we still have compatibility with React 18,\n // which doesn't have the `.edge` export.\n import('react-dom/server'),\n );\n};\n","import { Suspense } from 'react';\nimport { pretty } from '../node';\nimport { createErrorBoundary } from '../shared/error-boundary';\nimport type { Options } from '../shared/options';\nimport { readStream } from '../shared/read-stream.browser';\nimport { toPlainText } from '../shared/utils/to-plain-text';\nimport { importReactDom } from './import-react-dom';\n\nexport const render = async (\n element: React.ReactElement,\n options?: Options,\n) => {\n const reactDOMServer = await importReactDom().then((m) => {\n if ('default' in m) {\n return m.default;\n }\n\n return m;\n });\n\n const html = await new Promise<string>((resolve, reject) => {\n const ErrorBoundary = createErrorBoundary(reject);\n reactDOMServer\n .renderToReadableStream(\n <ErrorBoundary>\n <Suspense>{element}</Suspense>\n </ErrorBoundary>,\n {\n onError(error: unknown) {\n reject(error);\n },\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n },\n )\n .then(readStream)\n .then(resolve)\n .catch(reject);\n });\n\n if (options?.plainText) {\n return toPlainText(html, options.htmlToTextOptions);\n }\n\n const doctype =\n '<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">';\n\n const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, '')}`;\n\n if (options?.pretty) {\n return pretty(document);\n }\n\n return document;\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { HtmlToTextOptions, SelectorDefinition } from "html-to-text";
|
|
2
|
+
import { Options as Options$1 } from "prettier";
|
|
3
|
+
|
|
4
|
+
//#region src/shared/options.d.ts
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link pretty}
|
|
8
|
+
*/
|
|
9
|
+
pretty?: boolean;
|
|
10
|
+
} & ({
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link toPlainText}
|
|
13
|
+
*/
|
|
14
|
+
plainText?: false;
|
|
15
|
+
} | {
|
|
16
|
+
/**
|
|
17
|
+
* @see {@link toPlainText}
|
|
18
|
+
*/
|
|
19
|
+
plainText?: true;
|
|
20
|
+
/**
|
|
21
|
+
* These are options you can pass down directly to the library we use for
|
|
22
|
+
* converting the rendered email's HTML into plain text.
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/html-to-text/node-html-to-text
|
|
25
|
+
*/
|
|
26
|
+
htmlToTextOptions?: HtmlToTextOptions;
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/shared/utils/pretty.d.ts
|
|
30
|
+
declare const pretty: (str: string, options?: Options$1) => Promise<string>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/shared/utils/to-plain-text.d.ts
|
|
33
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
34
|
+
declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/node/render.d.ts
|
|
37
|
+
declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Options, plainTextSelectors, pretty, render, toPlainText };
|
|
40
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/shared/options.ts","../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/node/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC0FA;;;;ECxFa;AASb;;;;ACRA;;;;;sBHoB0B;;;;cCmEb,gCAAgC,cAAY;;;cCxF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCRvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { HtmlToTextOptions, SelectorDefinition } from "html-to-text";
|
|
2
|
+
import { Options as Options$1 } from "prettier";
|
|
3
|
+
|
|
4
|
+
//#region src/shared/options.d.ts
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link pretty}
|
|
8
|
+
*/
|
|
9
|
+
pretty?: boolean;
|
|
10
|
+
} & ({
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link toPlainText}
|
|
13
|
+
*/
|
|
14
|
+
plainText?: false;
|
|
15
|
+
} | {
|
|
16
|
+
/**
|
|
17
|
+
* @see {@link toPlainText}
|
|
18
|
+
*/
|
|
19
|
+
plainText?: true;
|
|
20
|
+
/**
|
|
21
|
+
* These are options you can pass down directly to the library we use for
|
|
22
|
+
* converting the rendered email's HTML into plain text.
|
|
23
|
+
*
|
|
24
|
+
* @see https://github.com/html-to-text/node-html-to-text
|
|
25
|
+
*/
|
|
26
|
+
htmlToTextOptions?: HtmlToTextOptions;
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/shared/utils/pretty.d.ts
|
|
30
|
+
declare const pretty: (str: string, options?: Options$1) => Promise<string>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/shared/utils/to-plain-text.d.ts
|
|
33
|
+
declare const plainTextSelectors: SelectorDefinition[];
|
|
34
|
+
declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/node/render.d.ts
|
|
37
|
+
declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Options, plainTextSelectors, pretty, render, toPlainText };
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shared/options.ts","../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/node/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC0FA;;;;ECxFa;AASb;;;;ACRA;;;;;sBHoB0B;;;;cCmEb,gCAAgC,cAAY;;;cCxF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCRvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let prettier_plugins_html = require("prettier/plugins/html");
|
|
25
|
+
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
26
|
+
let prettier_standalone = require("prettier/standalone");
|
|
27
|
+
prettier_standalone = __toESM(prettier_standalone);
|
|
28
|
+
let html_to_text = require("html-to-text");
|
|
29
|
+
html_to_text = __toESM(html_to_text);
|
|
30
|
+
let react = require("react");
|
|
31
|
+
react = __toESM(react);
|
|
32
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
|
+
let node_stream = require("node:stream");
|
|
35
|
+
node_stream = __toESM(node_stream);
|
|
36
|
+
|
|
37
|
+
//#region src/shared/utils/pretty.ts
|
|
38
|
+
function recursivelyMapDoc(doc, callback) {
|
|
39
|
+
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
40
|
+
if (typeof doc === "object") {
|
|
41
|
+
if (doc.type === "group") return {
|
|
42
|
+
...doc,
|
|
43
|
+
contents: recursivelyMapDoc(doc.contents, callback),
|
|
44
|
+
expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
|
|
45
|
+
};
|
|
46
|
+
if ("contents" in doc) return {
|
|
47
|
+
...doc,
|
|
48
|
+
contents: recursivelyMapDoc(doc.contents, callback)
|
|
49
|
+
};
|
|
50
|
+
if ("parts" in doc) return {
|
|
51
|
+
...doc,
|
|
52
|
+
parts: recursivelyMapDoc(doc.parts, callback)
|
|
53
|
+
};
|
|
54
|
+
if (doc.type === "if-break") return {
|
|
55
|
+
...doc,
|
|
56
|
+
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
57
|
+
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return callback(doc);
|
|
61
|
+
}
|
|
62
|
+
const modifiedHtml = { ...prettier_plugins_html };
|
|
63
|
+
if (modifiedHtml.printers) {
|
|
64
|
+
const previousPrint = modifiedHtml.printers.html.print;
|
|
65
|
+
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
66
|
+
const node = path.getNode();
|
|
67
|
+
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
68
|
+
if (node.type === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
69
|
+
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
70
|
+
return doc;
|
|
71
|
+
});
|
|
72
|
+
return rawPrintingResult;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const defaults = {
|
|
76
|
+
endOfLine: "lf",
|
|
77
|
+
tabWidth: 2,
|
|
78
|
+
plugins: [modifiedHtml],
|
|
79
|
+
bracketSameLine: true,
|
|
80
|
+
parser: "html"
|
|
81
|
+
};
|
|
82
|
+
const pretty = (str, options = {}) => {
|
|
83
|
+
return (0, prettier_standalone.format)(str.replaceAll("\0", ""), {
|
|
84
|
+
...defaults,
|
|
85
|
+
...options
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/shared/utils/to-plain-text.ts
|
|
91
|
+
const plainTextSelectors = [
|
|
92
|
+
{
|
|
93
|
+
selector: "img",
|
|
94
|
+
format: "skip"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
selector: "[data-skip-in-text=true]",
|
|
98
|
+
format: "skip"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
selector: "a",
|
|
102
|
+
options: {
|
|
103
|
+
linkBrackets: false,
|
|
104
|
+
hideLinkHrefIfSameAsText: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
function toPlainText(html, options) {
|
|
109
|
+
return (0, html_to_text.convert)(html, {
|
|
110
|
+
wordwrap: false,
|
|
111
|
+
...options,
|
|
112
|
+
selectors: [...plainTextSelectors, ...options?.selectors ?? []]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/shared/error-boundary.tsx
|
|
118
|
+
function createErrorBoundary(reject) {
|
|
119
|
+
if (!react.default.Component) return (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.children });
|
|
120
|
+
return class ErrorBoundary extends react.default.Component {
|
|
121
|
+
componentDidCatch(error) {
|
|
122
|
+
reject(error);
|
|
123
|
+
}
|
|
124
|
+
render() {
|
|
125
|
+
return this.props.children;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/node/read-stream.ts
|
|
132
|
+
const readStream = async (stream) => {
|
|
133
|
+
let result = "";
|
|
134
|
+
const decoder = new TextDecoder("utf-8");
|
|
135
|
+
if ("pipeTo" in stream) {
|
|
136
|
+
const writableStream = new WritableStream({
|
|
137
|
+
write(chunk) {
|
|
138
|
+
result += decoder.decode(chunk, { stream: true });
|
|
139
|
+
},
|
|
140
|
+
close() {
|
|
141
|
+
result += decoder.decode();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
await stream.pipeTo(writableStream);
|
|
145
|
+
} else {
|
|
146
|
+
const writable = new node_stream.Writable({
|
|
147
|
+
write(chunk, _encoding, callback) {
|
|
148
|
+
result += decoder.decode(chunk, { stream: true });
|
|
149
|
+
callback();
|
|
150
|
+
},
|
|
151
|
+
final(callback) {
|
|
152
|
+
result += decoder.decode();
|
|
153
|
+
callback();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
await new Promise((resolve, reject) => {
|
|
157
|
+
writable.on("pipe", (source) => {
|
|
158
|
+
source.on("error", (err) => {
|
|
159
|
+
writable.destroy(err);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
writable.on("error", reject);
|
|
163
|
+
writable.on("close", () => {
|
|
164
|
+
resolve();
|
|
165
|
+
});
|
|
166
|
+
stream.pipe(writable);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/node/render.tsx
|
|
174
|
+
const render = async (node, options) => {
|
|
175
|
+
const reactDOMServer = await import("react-dom/server").then((m) => {
|
|
176
|
+
if ("default" in m) return m.default;
|
|
177
|
+
return m;
|
|
178
|
+
});
|
|
179
|
+
let html;
|
|
180
|
+
await new Promise((resolve, reject) => {
|
|
181
|
+
if (Object.hasOwn(reactDOMServer, "renderToReadableStream") && typeof WritableStream !== "undefined") {
|
|
182
|
+
const ErrorBoundary = createErrorBoundary(reject);
|
|
183
|
+
reactDOMServer.renderToReadableStream(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: node }) }), {
|
|
184
|
+
progressiveChunkSize: Number.POSITIVE_INFINITY,
|
|
185
|
+
onError(error) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}).then((stream) => readStream(stream)).then((result) => {
|
|
189
|
+
html = result;
|
|
190
|
+
resolve();
|
|
191
|
+
}).catch(reject);
|
|
192
|
+
} else {
|
|
193
|
+
const ErrorBoundary = createErrorBoundary(reject);
|
|
194
|
+
const stream = reactDOMServer.renderToPipeableStream(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: node }) }), {
|
|
195
|
+
async onAllReady() {
|
|
196
|
+
html = await readStream(stream);
|
|
197
|
+
resolve();
|
|
198
|
+
},
|
|
199
|
+
onError(error) {
|
|
200
|
+
reject(error);
|
|
201
|
+
},
|
|
202
|
+
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
|
|
207
|
+
const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">${html.replace(/<!DOCTYPE.*?>/, "")}`;
|
|
208
|
+
if (options?.pretty) return pretty(document);
|
|
209
|
+
return document;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
exports.plainTextSelectors = plainTextSelectors;
|
|
214
|
+
exports.pretty = pretty;
|
|
215
|
+
exports.render = render;
|
|
216
|
+
exports.toPlainText = toPlainText;
|