@react-email/render 1.2.3 → 1.3.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.
@@ -1,40 +1,46 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
- import { Options as Options$1 } from 'prettier';
1
+ import { HtmlToTextOptions, SelectorDefinition } from "html-to-text";
2
+ import { Options as Options$1 } from "prettier";
3
3
 
4
+ //#region src/shared/options.d.ts
4
5
  type Options = {
5
- /**
6
- * @deprecated use {@link pretty} instead
7
- */
8
- pretty?: boolean;
6
+ /**
7
+ * @deprecated use {@link pretty} instead
8
+ */
9
+ pretty?: boolean;
9
10
  } & ({
10
- /**
11
- * @deprecated use {@link toPlainText} instead
12
- */
13
- plainText?: false;
11
+ /**
12
+ * @deprecated use {@link toPlainText} instead
13
+ */
14
+ plainText?: false;
14
15
  } | {
15
- /**
16
- * @deprecated use {@link toPlainText} instead
17
- */
18
- plainText?: true;
19
- /**
20
- * These are options you can pass down directly to the library we use for
21
- * converting the rendered email's HTML into plain text.
22
- *
23
- * @see https://github.com/html-to-text/node-html-to-text
24
- */
25
- htmlToTextOptions?: HtmlToTextOptions;
16
+ /**
17
+ * @deprecated use {@link toPlainText} instead
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;
26
27
  });
27
-
28
+ //#endregion
29
+ //#region src/shared/utils/pretty.d.ts
28
30
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
29
-
31
+ //#endregion
32
+ //#region src/shared/utils/to-plain-text.d.ts
30
33
  declare const plainTextSelectors: SelectorDefinition[];
31
34
  declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
32
-
35
+ //#endregion
36
+ //#region src/browser/render.d.ts
33
37
  declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
34
-
38
+ //#endregion
39
+ //#region src/browser/index.d.ts
35
40
  /**
36
41
  * @deprecated use {@link render}
37
42
  */
38
43
  declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
39
-
40
- export { type Options, plainTextSelectors, pretty, render, renderAsync, toPlainText };
44
+ //#endregion
45
+ export { Options, plainTextSelectors, pretty, render, renderAsync, toPlainText };
46
+ //# 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/browser/render.tsx","../../src/browser/index.ts"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC2FA;;WAA6C,CAAA,EAAA,KAAA;;EAAY;;;;ECzF5C;AASb;;;;ACVA;EAkCC,iBAAA,CAAA,EHZyB,iBGYzB;;;;cFwDY,gCAAgC,cAAY;;;cCzF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCVvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO;;;;;;AHDzD,cIEC,WJqBa,EAAA,CAAA,OAAiB,EIrBN,KAAA,CAAM,YJqBA,EAAA,OAAA,CAAA,EIrBwB,OJqBxB,EAAA,GIrB+B,OJqB/B,CAAA,MAAA,CAAA"}
@@ -1,40 +1,46 @@
1
- import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
2
- import { Options as Options$1 } from 'prettier';
1
+ import { HtmlToTextOptions, SelectorDefinition } from "html-to-text";
2
+ import { Options as Options$1 } from "prettier";
3
3
 
4
+ //#region src/shared/options.d.ts
4
5
  type Options = {
5
- /**
6
- * @deprecated use {@link pretty} instead
7
- */
8
- pretty?: boolean;
6
+ /**
7
+ * @deprecated use {@link pretty} instead
8
+ */
9
+ pretty?: boolean;
9
10
  } & ({
10
- /**
11
- * @deprecated use {@link toPlainText} instead
12
- */
13
- plainText?: false;
11
+ /**
12
+ * @deprecated use {@link toPlainText} instead
13
+ */
14
+ plainText?: false;
14
15
  } | {
15
- /**
16
- * @deprecated use {@link toPlainText} instead
17
- */
18
- plainText?: true;
19
- /**
20
- * These are options you can pass down directly to the library we use for
21
- * converting the rendered email's HTML into plain text.
22
- *
23
- * @see https://github.com/html-to-text/node-html-to-text
24
- */
25
- htmlToTextOptions?: HtmlToTextOptions;
16
+ /**
17
+ * @deprecated use {@link toPlainText} instead
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;
26
27
  });
27
-
28
+ //#endregion
29
+ //#region src/shared/utils/pretty.d.ts
28
30
  declare const pretty: (str: string, options?: Options$1) => Promise<string>;
29
-
31
+ //#endregion
32
+ //#region src/shared/utils/to-plain-text.d.ts
30
33
  declare const plainTextSelectors: SelectorDefinition[];
31
34
  declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
32
-
35
+ //#endregion
36
+ //#region src/browser/render.d.ts
33
37
  declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
34
-
38
+ //#endregion
39
+ //#region src/browser/index.d.ts
35
40
  /**
36
41
  * @deprecated use {@link render}
37
42
  */
38
43
  declare const renderAsync: (element: React.ReactElement, options?: Options) => Promise<string>;
39
-
40
- export { type Options, plainTextSelectors, pretty, render, renderAsync, toPlainText };
44
+ //#endregion
45
+ export { Options, plainTextSelectors, pretty, render, renderAsync, toPlainText };
46
+ //# 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/browser/render.tsx","../../src/browser/index.ts"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC2FA;;WAA6C,CAAA,EAAA,KAAA;;EAAY;;;;ECzF5C;AASb;;;;ACVA;EAkCC,iBAAA,CAAA,EHZyB,iBGYzB;;;;cFwDY,gCAAgC,cAAY;;;cCzF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCVvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO;;;;;;AHDzD,cIEC,WJqBa,EAAA,CAAA,OAAiB,EIrBN,KAAA,CAAM,YJqBA,EAAA,OAAA,CAAA,EIrBwB,OJqBxB,EAAA,GIrB+B,OJqB/B,CAAA,MAAA,CAAA"}
@@ -1,230 +1,173 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
6
  var __getProtoOf = Object.getPrototypeOf;
10
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
8
  var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
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;
36
17
  };
37
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
- // If the importer is in node compatibility mode or this is not an ESM
39
- // file that has been converted to a CommonJS file using a Babel-
40
- // compatible transform (i.e. "__esModule" has not been set), then set
41
- // "default" to the CommonJS "module.exports" for node compatibility.
42
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
- mod
44
- ));
45
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
- var __async = (__this, __arguments, generator) => {
47
- return new Promise((resolve, reject) => {
48
- var fulfilled = (value) => {
49
- try {
50
- step(generator.next(value));
51
- } catch (e) {
52
- reject(e);
53
- }
54
- };
55
- var rejected = (value) => {
56
- try {
57
- step(generator.throw(value));
58
- } catch (e) {
59
- reject(e);
60
- }
61
- };
62
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
- step((generator = generator.apply(__this, __arguments)).next());
64
- });
65
- };
66
-
67
- // src/browser/index.ts
68
- var index_exports = {};
69
- __export(index_exports, {
70
- plainTextSelectors: () => plainTextSelectors,
71
- pretty: () => pretty,
72
- render: () => render,
73
- renderAsync: () => renderAsync,
74
- toPlainText: () => toPlainText
75
- });
76
- module.exports = __toCommonJS(index_exports);
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));
77
22
 
78
- // src/browser/render.tsx
79
- var import_react = require("react");
23
+ //#endregion
24
+ let react = require("react");
25
+ react = __toESM(react);
26
+ let prettier_plugins_html = require("prettier/plugins/html");
27
+ prettier_plugins_html = __toESM(prettier_plugins_html);
28
+ let prettier_standalone = require("prettier/standalone");
29
+ prettier_standalone = __toESM(prettier_standalone);
30
+ let html_to_text = require("html-to-text");
31
+ html_to_text = __toESM(html_to_text);
32
+ let react_jsx_runtime = require("react/jsx-runtime");
33
+ react_jsx_runtime = __toESM(react_jsx_runtime);
80
34
 
81
- // src/shared/utils/pretty.ts
82
- var html = __toESM(require("prettier/plugins/html"));
83
- var import_standalone = require("prettier/standalone");
35
+ //#region src/shared/utils/pretty.ts
84
36
  function recursivelyMapDoc(doc, callback) {
85
- if (Array.isArray(doc)) {
86
- return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
87
- }
88
- if (typeof doc === "object") {
89
- if (doc.type === "group") {
90
- return __spreadProps(__spreadValues({}, doc), {
91
- contents: recursivelyMapDoc(doc.contents, callback),
92
- expandedStates: recursivelyMapDoc(
93
- doc.expandedStates,
94
- callback
95
- )
96
- });
97
- }
98
- if ("contents" in doc) {
99
- return __spreadProps(__spreadValues({}, doc), {
100
- contents: recursivelyMapDoc(doc.contents, callback)
101
- });
102
- }
103
- if ("parts" in doc) {
104
- return __spreadProps(__spreadValues({}, doc), {
105
- parts: recursivelyMapDoc(doc.parts, callback)
106
- });
107
- }
108
- if (doc.type === "if-break") {
109
- return __spreadProps(__spreadValues({}, doc), {
110
- breakContents: recursivelyMapDoc(doc.breakContents, callback),
111
- flatContents: recursivelyMapDoc(doc.flatContents, callback)
112
- });
113
- }
114
- }
115
- return callback(doc);
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);
116
59
  }
117
- var modifiedHtml = __spreadValues({}, html);
60
+ const modifiedHtml = { ...prettier_plugins_html };
118
61
  if (modifiedHtml.printers) {
119
- const previousPrint = modifiedHtml.printers.html.print;
120
- modifiedHtml.printers.html.print = (path, options, print, args) => {
121
- const node = path.getNode();
122
- const rawPrintingResult = previousPrint(path, options, print, args);
123
- if (node.type === "ieConditionalComment") {
124
- const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
125
- if (typeof doc === "object" && doc.type === "line") {
126
- return doc.soft ? "" : " ";
127
- }
128
- return doc;
129
- });
130
- return printingResult;
131
- }
132
- return rawPrintingResult;
133
- };
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
+ };
134
72
  }
135
- var defaults = {
136
- endOfLine: "lf",
137
- tabWidth: 2,
138
- plugins: [modifiedHtml],
139
- bracketSameLine: true,
140
- parser: "html"
73
+ const defaults = {
74
+ endOfLine: "lf",
75
+ tabWidth: 2,
76
+ plugins: [modifiedHtml],
77
+ bracketSameLine: true,
78
+ parser: "html"
141
79
  };
142
- var pretty = (str, options = {}) => {
143
- return (0, import_standalone.format)(str.replaceAll("\0", ""), __spreadValues(__spreadValues({}, defaults), options));
80
+ const pretty = (str, options = {}) => {
81
+ return (0, prettier_standalone.format)(str.replaceAll("\0", ""), {
82
+ ...defaults,
83
+ ...options
84
+ });
144
85
  };
145
86
 
146
- // src/shared/utils/to-plain-text.ts
147
- var import_html_to_text = require("html-to-text");
148
- var plainTextSelectors = [
149
- { selector: "img", format: "skip" },
150
- { selector: "[data-skip-in-text=true]", format: "skip" },
151
- {
152
- selector: "a",
153
- options: { linkBrackets: false }
154
- }
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
+ }
155
105
  ];
156
- function toPlainText(html2, options) {
157
- return (0, import_html_to_text.convert)(html2, __spreadValues({
158
- selectors: plainTextSelectors
159
- }, options));
106
+ function toPlainText(html, options) {
107
+ return (0, html_to_text.convert)(html, {
108
+ selectors: plainTextSelectors,
109
+ ...options
110
+ });
160
111
  }
161
112
 
162
- // src/shared/read-stream.browser.ts
163
- var decoder = new TextDecoder("utf-8");
164
- var readStream = (stream) => __async(void 0, null, function* () {
165
- const chunks = [];
166
- const writableStream = new WritableStream({
167
- write(chunk) {
168
- chunks.push(chunk);
169
- },
170
- abort(reason) {
171
- throw new Error("Stream aborted", {
172
- cause: {
173
- reason
174
- }
175
- });
176
- }
177
- });
178
- yield stream.pipeTo(writableStream);
179
- let length = 0;
180
- chunks.forEach((item) => {
181
- length += item.length;
182
- });
183
- const mergedChunks = new Uint8Array(length);
184
- let offset = 0;
185
- chunks.forEach((item) => {
186
- mergedChunks.set(item, offset);
187
- offset += item.length;
188
- });
189
- return decoder.decode(mergedChunks);
190
- });
113
+ //#endregion
114
+ //#region src/shared/read-stream.browser.ts
115
+ const decoder = new TextDecoder("utf-8");
116
+ const readStream = async (stream) => {
117
+ const chunks = [];
118
+ const writableStream = new WritableStream({
119
+ write(chunk) {
120
+ chunks.push(chunk);
121
+ },
122
+ abort(reason) {
123
+ throw new Error("Stream aborted", { cause: { reason } });
124
+ }
125
+ });
126
+ await stream.pipeTo(writableStream);
127
+ let length = 0;
128
+ chunks.forEach((item) => {
129
+ length += item.length;
130
+ });
131
+ const mergedChunks = new Uint8Array(length);
132
+ let offset = 0;
133
+ chunks.forEach((item) => {
134
+ mergedChunks.set(item, offset);
135
+ offset += item.length;
136
+ });
137
+ return decoder.decode(mergedChunks);
138
+ };
191
139
 
192
- // src/browser/render.tsx
193
- var import_jsx_runtime = require("react/jsx-runtime");
194
- var render = (node, options) => __async(void 0, null, function* () {
195
- const suspendedElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: node });
196
- const reactDOMServer = yield import("react-dom/server.browser").then(
197
- // This is beacuse react-dom/server is CJS
198
- (m) => m.default
199
- );
200
- const html2 = yield new Promise((resolve, reject) => {
201
- reactDOMServer.renderToReadableStream(suspendedElement, {
202
- onError(error) {
203
- reject(error);
204
- },
205
- progressiveChunkSize: Number.POSITIVE_INFINITY
206
- }).then(readStream).then(resolve).catch(reject);
207
- });
208
- if (options == null ? void 0 : options.plainText) {
209
- return toPlainText(html2, options.htmlToTextOptions);
210
- }
211
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
212
- const document = `${doctype}${html2.replace(/<!DOCTYPE.*?>/, "")}`;
213
- if (options == null ? void 0 : options.pretty) {
214
- return pretty(document);
215
- }
216
- return document;
217
- });
140
+ //#endregion
141
+ //#region src/browser/render.tsx
142
+ const render = async (node, options) => {
143
+ const suspendedElement = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: node });
144
+ const reactDOMServer = await import("react-dom/server.browser").then((m) => m.default);
145
+ const html = await new Promise((resolve, reject) => {
146
+ reactDOMServer.renderToReadableStream(suspendedElement, {
147
+ onError(error) {
148
+ reject(error);
149
+ },
150
+ progressiveChunkSize: Number.POSITIVE_INFINITY
151
+ }).then(readStream).then(resolve).catch(reject);
152
+ });
153
+ if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
154
+ 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.*?>/, "")}`;
155
+ if (options?.pretty) return pretty(document);
156
+ return document;
157
+ };
218
158
 
219
- // src/browser/index.ts
220
- var renderAsync = (element, options) => {
221
- return render(element, options);
159
+ //#endregion
160
+ //#region src/browser/index.ts
161
+ /**
162
+ * @deprecated use {@link render}
163
+ */
164
+ const renderAsync = (element, options) => {
165
+ return render(element, options);
222
166
  };
223
- // Annotate the CommonJS export names for ESM import in node:
224
- 0 && (module.exports = {
225
- plainTextSelectors,
226
- pretty,
227
- render,
228
- renderAsync,
229
- toPlainText
230
- });
167
+
168
+ //#endregion
169
+ exports.plainTextSelectors = plainTextSelectors;
170
+ exports.pretty = pretty;
171
+ exports.render = render;
172
+ exports.renderAsync = renderAsync;
173
+ exports.toPlainText = toPlainText;