@react-email/render 2.0.4 → 2.0.6
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 → index.cjs} +25 -12
- package/dist/browser/{index.d.ts → index.d.cts} +1 -1
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.mjs +15 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/edge/{index.js → index.cjs} +25 -12
- package/dist/edge/{index.d.ts → index.d.cts} +1 -1
- package/dist/edge/index.d.cts.map +1 -0
- package/dist/edge/index.d.mts.map +1 -1
- package/dist/edge/index.mjs +15 -3
- package/dist/edge/index.mjs.map +1 -1
- package/dist/node/{index.js → index.cjs} +26 -14
- package/dist/node/{index.d.ts → index.d.cts} +1 -1
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.mjs +16 -4
- package/dist/node/index.mjs.map +1 -1
- package/package.json +20 -22
- package/dist/browser/index.d.ts.map +0 -1
- package/dist/edge/index.d.ts.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -24,18 +28,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
28
|
let prettier_plugins_html = require("prettier/plugins/html");
|
|
25
29
|
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
26
30
|
let prettier_standalone = require("prettier/standalone");
|
|
27
|
-
prettier_standalone = __toESM(prettier_standalone);
|
|
28
31
|
let html_to_text = require("html-to-text");
|
|
29
|
-
html_to_text = __toESM(html_to_text);
|
|
30
32
|
let react = require("react");
|
|
31
33
|
react = __toESM(react);
|
|
32
34
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
35
|
|
|
35
36
|
//#region src/shared/utils/pretty.ts
|
|
37
|
+
function getHtmlNode(path) {
|
|
38
|
+
const topNode = path.node;
|
|
39
|
+
if (topNode) return topNode;
|
|
40
|
+
return path.stack?.[path.stack.length - 1];
|
|
41
|
+
}
|
|
36
42
|
function recursivelyMapDoc(doc, callback) {
|
|
37
43
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
38
44
|
if (typeof doc === "object") {
|
|
45
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
39
46
|
if (doc.type === "group") return {
|
|
40
47
|
...doc,
|
|
41
48
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -54,6 +61,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
54
61
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
55
62
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
56
63
|
};
|
|
64
|
+
const nextDoc = { ...doc };
|
|
65
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
66
|
+
return nextDoc;
|
|
57
67
|
}
|
|
58
68
|
return callback(doc);
|
|
59
69
|
}
|
|
@@ -61,9 +71,9 @@ const modifiedHtml = { ...prettier_plugins_html };
|
|
|
61
71
|
if (modifiedHtml.printers) {
|
|
62
72
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
63
73
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
64
|
-
const node = path
|
|
74
|
+
const node = getHtmlNode(path);
|
|
65
75
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
66
|
-
if (node
|
|
76
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
67
77
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
68
78
|
return doc;
|
|
69
79
|
});
|
|
@@ -166,7 +176,10 @@ const render = async (node, options) => {
|
|
|
166
176
|
reject(error);
|
|
167
177
|
},
|
|
168
178
|
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
169
|
-
}).then(
|
|
179
|
+
}).then(async (stream) => {
|
|
180
|
+
await stream.allReady;
|
|
181
|
+
return readStream(stream);
|
|
182
|
+
}).then(resolve).catch(reject);
|
|
170
183
|
});
|
|
171
184
|
if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
|
|
172
185
|
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.*?>/, "")}`;
|
|
@@ -37,4 +37,4 @@ declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
|
|
|
37
37
|
declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
|
|
38
38
|
//#endregion
|
|
39
39
|
export { Options, plainTextSelectors, pretty, render, toPlainText };
|
|
40
|
-
//# sourceMappingURL=index.d.
|
|
40
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/shared/options.ts","../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/browser/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;ACyHA;;;;ECvHa;AASb;;;;ACTA;;;;;sBHqB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCTvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
|
@@ -1 +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"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;
|
|
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"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;ACyHA;;;;ECvHa;AASb;;;;ACTA;;;;;sBHqB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCTvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -5,9 +5,15 @@ import React, { Suspense } from "react";
|
|
|
5
5
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
6
|
|
|
7
7
|
//#region src/shared/utils/pretty.ts
|
|
8
|
+
function getHtmlNode(path) {
|
|
9
|
+
const topNode = path.node;
|
|
10
|
+
if (topNode) return topNode;
|
|
11
|
+
return path.stack?.[path.stack.length - 1];
|
|
12
|
+
}
|
|
8
13
|
function recursivelyMapDoc(doc, callback) {
|
|
9
14
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
10
15
|
if (typeof doc === "object") {
|
|
16
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
11
17
|
if (doc.type === "group") return {
|
|
12
18
|
...doc,
|
|
13
19
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -26,6 +32,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
26
32
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
27
33
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
28
34
|
};
|
|
35
|
+
const nextDoc = { ...doc };
|
|
36
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
37
|
+
return nextDoc;
|
|
29
38
|
}
|
|
30
39
|
return callback(doc);
|
|
31
40
|
}
|
|
@@ -33,9 +42,9 @@ const modifiedHtml = { ...html };
|
|
|
33
42
|
if (modifiedHtml.printers) {
|
|
34
43
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
35
44
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
36
|
-
const node = path
|
|
45
|
+
const node = getHtmlNode(path);
|
|
37
46
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
38
|
-
if (node
|
|
47
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
39
48
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
40
49
|
return doc;
|
|
41
50
|
});
|
|
@@ -138,7 +147,10 @@ const render = async (node, options) => {
|
|
|
138
147
|
reject(error);
|
|
139
148
|
},
|
|
140
149
|
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
141
|
-
}).then(
|
|
150
|
+
}).then(async (stream) => {
|
|
151
|
+
await stream.allReady;
|
|
152
|
+
return readStream(stream);
|
|
153
|
+
}).then(resolve).catch(reject);
|
|
142
154
|
});
|
|
143
155
|
if (options?.plainText) return toPlainText(html$1, options.htmlToTextOptions);
|
|
144
156
|
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.*?>/, "")}`;
|
|
@@ -1 +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/browser/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","import { Suspense } from 'react';\nimport { pretty, toPlainText } from '../node';\nimport { createErrorBoundary } from '../shared/error-boundary';\nimport type { Options } from '../shared/options';\nimport { readStream } from '../shared/read-stream.browser';\n\nexport const render = async (node: React.ReactNode, options?: Options) => {\n const reactDOMServer = await import('react-dom/server').then((m) => {\n if ('default' in m) {\n return m.default;\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 <Suspense>\n <ErrorBoundary>{node}</ErrorBoundary>\n </Suspense>,\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":";;;;;;;AAgBA,SAAS,kBACP,KACA,UACc;AACd,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,aAAa,kBAAkB,UAAU,SAAS,CAAC;AAGrE,KAAI,OAAO,QAAQ,UAAU;AAC3B,MAAI,IAAI,SAAS,QACf,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IA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,CACF,CACA,KAAK,WAAW,CAChB,KAAK,QAAQ,CACb,MAAM,OAAO;GAChB;AAEF,KAAI,SAAS,UACX,QAAO,YAAYA,QAAM,QAAQ,kBAAkB;CAMrD,MAAM,WAAW,4HAAaA,OAAK,QAAQ,iBAAiB,GAAG;AAE/D,KAAI,SAAS,OACX,QAAO,OAAO,SAAS;AAGzB,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["html","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/browser/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 kind?: 'element' | 'text' | 'ieConditionalComment' | 'root';\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 getHtmlNode(path: {\n node?: HtmlNode;\n stack?: Array<Record<string, unknown>>;\n}) {\n const topNode = path.node;\n if (topNode) {\n return topNode;\n }\n\n return path.stack?.[path.stack.length - 1] as 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 === 'line') {\n return callback(doc.soft ? '' : ' ');\n }\n\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 const nextDoc = { ...doc } as Record<string, unknown>;\n for (const [key, value] of Object.entries(nextDoc)) {\n if (value && typeof value === 'object') {\n nextDoc[key] = recursivelyMapDoc(value as builders.Doc, callback);\n }\n }\n\n return nextDoc as builders.Doc;\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 = getHtmlNode(\n path as Parameters<Plugin['printers']['html']['print']>[0],\n );\n\n const rawPrintingResult = previousPrint(path, options, print, args);\n\n if (\n node?.type === 'ieConditionalComment' ||\n node?.kind === 'ieConditionalComment'\n ) {\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","import { Suspense } from 'react';\nimport { pretty, toPlainText } from '../node';\nimport { createErrorBoundary } from '../shared/error-boundary';\nimport type { Options } from '../shared/options';\nimport { readStream } from '../shared/read-stream.browser';\n\nexport const render = async (node: React.ReactNode, options?: Options) => {\n const reactDOMServer = await import('react-dom/server').then((m) => {\n if ('default' in m) {\n return m.default;\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 <Suspense>\n <ErrorBoundary>{node}</ErrorBoundary>\n </Suspense>,\n {\n onError(error: unknown) {\n reject(error);\n },\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n },\n )\n .then(async (stream) => {\n await stream.allReady;\n return readStream(stream);\n })\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":";;;;;;;AAiBA,SAAS,YAAY,MAGlB;CACD,MAAM,UAAU,KAAK;AACrB,KAAI,QACF,QAAO;AAGT,QAAO,KAAK,QAAQ,KAAK,MAAM,SAAS;;AAG1C,SAAS,kBACP,KACA,UACc;AACd,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,aAAa,kBAAkB,UAAU,SAAS,CAAC;AAGrE,KAAI,OAAO,QAAQ,UAAU;AAC3B,MAAI,IAAI,SAAS,OACf,QAAO,SAAS,IAAI,OAAO,KAAK,IAAI;AAGtC,MAAI,IAAI,SAAS,QACf,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACnD,gBAAgB,kBACd,IAAI,gBACJ,SACD;GACF;AAGH,MAAI,cAAc,IAChB,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACpD;AAGH,MAAI,WAAW,IACb,QAAO;GACL,GAAG;GACH,OAAO,kBAAkB,IAAI,OAAO,SAAS;GAC9C;AAGH,MAAI,IAAI,SAAS,WACf,QAAO;GACL,GAAG;GACH,eAAe,kBAAkB,IAAI,eAAe,SAAS;GAC7D,cAAc,kBAAkB,IAAI,cAAc,SAAS;GAC5D;EAGH,MAAM,UAAU,EAAE,GAAG,KAAK;AAC1B,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAChD,KAAI,SAAS,OAAO,UAAU,SAC5B,SAAQ,OAAO,kBAAkB,OAAuB,SAAS;AAIrE,SAAO;;AAGT,QAAO,SAAS,IAAI;;AAGtB,MAAM,eAAe,EAAE,GAAG,MA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object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -24,18 +28,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
28
|
let prettier_plugins_html = require("prettier/plugins/html");
|
|
25
29
|
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
26
30
|
let prettier_standalone = require("prettier/standalone");
|
|
27
|
-
prettier_standalone = __toESM(prettier_standalone);
|
|
28
31
|
let html_to_text = require("html-to-text");
|
|
29
|
-
html_to_text = __toESM(html_to_text);
|
|
30
32
|
let react = require("react");
|
|
31
33
|
react = __toESM(react);
|
|
32
34
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
35
|
|
|
35
36
|
//#region src/shared/utils/pretty.ts
|
|
37
|
+
function getHtmlNode(path) {
|
|
38
|
+
const topNode = path.node;
|
|
39
|
+
if (topNode) return topNode;
|
|
40
|
+
return path.stack?.[path.stack.length - 1];
|
|
41
|
+
}
|
|
36
42
|
function recursivelyMapDoc(doc, callback) {
|
|
37
43
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
38
44
|
if (typeof doc === "object") {
|
|
45
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
39
46
|
if (doc.type === "group") return {
|
|
40
47
|
...doc,
|
|
41
48
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -54,6 +61,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
54
61
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
55
62
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
56
63
|
};
|
|
64
|
+
const nextDoc = { ...doc };
|
|
65
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
66
|
+
return nextDoc;
|
|
57
67
|
}
|
|
58
68
|
return callback(doc);
|
|
59
69
|
}
|
|
@@ -61,9 +71,9 @@ const modifiedHtml = { ...prettier_plugins_html };
|
|
|
61
71
|
if (modifiedHtml.printers) {
|
|
62
72
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
63
73
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
64
|
-
const node = path
|
|
74
|
+
const node = getHtmlNode(path);
|
|
65
75
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
66
|
-
if (node
|
|
76
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
67
77
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
68
78
|
return doc;
|
|
69
79
|
});
|
|
@@ -172,7 +182,10 @@ const render = async (element, options) => {
|
|
|
172
182
|
reject(error);
|
|
173
183
|
},
|
|
174
184
|
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
175
|
-
}).then(
|
|
185
|
+
}).then(async (stream) => {
|
|
186
|
+
await stream.allReady;
|
|
187
|
+
return readStream(stream);
|
|
188
|
+
}).then(resolve).catch(reject);
|
|
176
189
|
});
|
|
177
190
|
if (options?.plainText) return toPlainText(html, options.htmlToTextOptions);
|
|
178
191
|
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.*?>/, "")}`;
|
|
@@ -37,4 +37,4 @@ declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
|
|
|
37
37
|
declare const render: (element: React.ReactElement, options?: Options) => Promise<string>;
|
|
38
38
|
//#endregion
|
|
39
39
|
export { Options, plainTextSelectors, pretty, render, toPlainText };
|
|
40
|
-
//# sourceMappingURL=index.d.
|
|
40
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/shared/options.ts","../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/edge/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;ACyHA;;;;ECvHa;AASb;;;;ACPA;;;;;sBHmB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCPvC,kBACF,KAAA,CAAM,wBACL,YAAO"}
|
|
@@ -1 +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/edge/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;
|
|
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/edge/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;ACyHA;;;;ECvHa;AASb;;;;ACPA;;;;;sBHmB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCPvC,kBACF,KAAA,CAAM,wBACL,YAAO"}
|
package/dist/edge/index.mjs
CHANGED
|
@@ -5,9 +5,15 @@ import React, { Suspense } from "react";
|
|
|
5
5
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
6
6
|
|
|
7
7
|
//#region src/shared/utils/pretty.ts
|
|
8
|
+
function getHtmlNode(path) {
|
|
9
|
+
const topNode = path.node;
|
|
10
|
+
if (topNode) return topNode;
|
|
11
|
+
return path.stack?.[path.stack.length - 1];
|
|
12
|
+
}
|
|
8
13
|
function recursivelyMapDoc(doc, callback) {
|
|
9
14
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
10
15
|
if (typeof doc === "object") {
|
|
16
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
11
17
|
if (doc.type === "group") return {
|
|
12
18
|
...doc,
|
|
13
19
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -26,6 +32,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
26
32
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
27
33
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
28
34
|
};
|
|
35
|
+
const nextDoc = { ...doc };
|
|
36
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
37
|
+
return nextDoc;
|
|
29
38
|
}
|
|
30
39
|
return callback(doc);
|
|
31
40
|
}
|
|
@@ -33,9 +42,9 @@ const modifiedHtml = { ...html };
|
|
|
33
42
|
if (modifiedHtml.printers) {
|
|
34
43
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
35
44
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
36
|
-
const node = path
|
|
45
|
+
const node = getHtmlNode(path);
|
|
37
46
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
38
|
-
if (node
|
|
47
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
39
48
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
40
49
|
return doc;
|
|
41
50
|
});
|
|
@@ -144,7 +153,10 @@ const render = async (element, options) => {
|
|
|
144
153
|
reject(error);
|
|
145
154
|
},
|
|
146
155
|
progressiveChunkSize: Number.POSITIVE_INFINITY
|
|
147
|
-
}).then(
|
|
156
|
+
}).then(async (stream) => {
|
|
157
|
+
await stream.allReady;
|
|
158
|
+
return readStream(stream);
|
|
159
|
+
}).then(resolve).catch(reject);
|
|
148
160
|
});
|
|
149
161
|
if (options?.plainText) return toPlainText(html$1, options.htmlToTextOptions);
|
|
150
162
|
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.*?>/, "")}`;
|
package/dist/edge/index.mjs.map
CHANGED
|
@@ -1 +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":";;;;;;;AAgBA,SAAS,kBACP,KACA,UACc;AACd,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,aAAa,kBAAkB,UAAU,SAAS,CAAC;AAGrE,KAAI,OAAO,QAAQ,UAAU;AAC3B,MAAI,IAAI,SAAS,QACf,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACnD,gBAAgB,kBACd,IAAI,gBACJ,SACD;GACF;AAGH,MAAI,cAAc,IAChB,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACpD;AAGH,MAAI,WAAW,IACb,QAAO;GACL,GAAG;GACH,OAAO,kBAAkB,IAAI,OAAO,SAAS;GAC9C;AAGH,MAAI,IAAI,SAAS,WACf,QAAO;GACL,GAAG;GACH,eAAe,kBAAkB,IAAI,eAAe,SAAS;GAC7D,cAAc,kBAAkB,IAAI,cAAc,SAAS;GAC5D;;AAIL,QAAO,SAAS,IAAI;;AAGtB,MAAM,eAAe,EAAE,GAAG,MAAM;AAChC,IAAI,aAAa,UAAU;CACzB,MAAM,gBAAgB,aAAa,SAAS,KAAK;AACjD,cAAa,SAAS,KAAK,SAAS,MAAM,SAAS,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AQ;AACZ,SAAM,IAAI,MAAM,kBAAkB,EAChC,OAAO,EACL,QACD,EACF,CAAC;;EAEL,CAAC;AACF,OAAM,OAAO,OAAO,eAAe;CAEnC,IAAI,SAAS;AACb,QAAO,SAAS,SAAS;AACvB,YAAU,KAAK;GACf;CACF,MAAM,eAAe,IAAI,WAAW,OAAO;CAC3C,IAAI,SAAS;AACb,QAAO,SAAS,SAAS;AACvB,eAAa,IAAI,MAAM,OAAO;AAC9B,YAAU,KAAK;GACf;AAEF,QAAO,QAAQ,OAAO,aAAa;;;;;AChCrC,MAAa,uBAAuB;AAIlC,QAAO,OAAO,yBAAyB,YAInC,OAAO,oBACV;;;;;ACDH,MAAa,SAAS,OACpB,SACA,YACG;CACH,MAAM,iBAAiB,MAAM,gBAAgB,CAAC,MAAM,MAAM;AACxD,MAAI,aAAa,EACf,QAAO,EAAE;AAGX,SAAO;GACP;CAEF,MAAMC,SAAO,MAAM,IAAI,SAAiB,SAAS,WAAW;EAC1D,MAAM,gBAAgB,oBAAoB,OAAO;AACjD,iBACG,uBACC,oBAAC,2BACC,oBAAC,sBAAU,UAAmB,GAChB,EAChB;GACE,QAAQ,OAAgB;AACtB,WAAO,MAAM;;GAEf,sBAAsB,OAAO;GAC9B,CACF,CACA,KAAK,WAAW,CAChB,KAAK,QAAQ,CACb,MAAM,OAAO;GAChB;AAEF,KAAI,SAAS,UACX,QAAO,YAAYA,QAAM,QAAQ,kBAAkB;CAMrD,MAAM,WAAW,4HAAaA,OAAK,QAAQ,iBAAiB,GAAG;AAE/D,KAAI,SAAS,OACX,QAAO,OAAO,SAAS;AAGzB,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["html","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 kind?: 'element' | 'text' | 'ieConditionalComment' | 'root';\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 getHtmlNode(path: {\n node?: HtmlNode;\n stack?: Array<Record<string, unknown>>;\n}) {\n const topNode = path.node;\n if (topNode) {\n return topNode;\n }\n\n return path.stack?.[path.stack.length - 1] as 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 === 'line') {\n return callback(doc.soft ? '' : ' ');\n }\n\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 const nextDoc = { ...doc } as Record<string, unknown>;\n for (const [key, value] of Object.entries(nextDoc)) {\n if (value && typeof value === 'object') {\n nextDoc[key] = recursivelyMapDoc(value as builders.Doc, callback);\n }\n }\n\n return nextDoc as builders.Doc;\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 = getHtmlNode(\n path as Parameters<Plugin['printers']['html']['print']>[0],\n );\n\n const rawPrintingResult = previousPrint(path, options, print, args);\n\n if (\n node?.type === 'ieConditionalComment' ||\n node?.kind === 'ieConditionalComment'\n ) {\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(async (stream) => {\n await stream.allReady;\n return readStream(stream);\n })\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.*?>/, '')}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QACD,EACF,CAAC;;EAEL,CAAC;AACF,OAAM,OAAO,OAAO,eAAe;CAEnC,IAAI,SAAS;AACb,QAAO,SAAS,SAAS;AACvB,YAAU,KAAK;GACf;CACF,MAAM,eAAe,IAAI,WAAW,OAAO;CAC3C,IAAI,SAAS;AACb,QAAO,SAAS,SAAS;AACvB,eAAa,IAAI,MAAM,OAAO;AAC9B,YAAU,KAAK;GACf;AAEF,QAAO,QAAQ,OAAO,aAAa;;;;;AChCrC,MAAa,uBAAuB;AAIlC,QAAO,OAAO,yBAAyB,YAInC,OAAO,oBACV;;;;;ACDH,MAAa,SAAS,OACpB,SACA,YACG;CACH,MAAM,iBAAiB,MAAM,gBAAgB,CAAC,MAAM,MAAM;AACxD,MAAI,aAAa,EACf,QAAO,EAAE;AAGX,SAAO;GACP;CAEF,MAAMC,SAAO,MAAM,IAAI,SAAiB,SAAS,WAAW;EAC1D,MAAM,gBAAgB,oBAAoB,OAAO;AACjD,iBACG,uBACC,oBAAC,2BACC,oBAAC,sBAAU,UAAmB,GAChB,EAChB;GACE,QAAQ,OAAgB;AACtB,WAAO,MAAM;;GAEf,sBAAsB,OAAO;GAC9B,CACF,CACA,KAAK,OAAO,WAAW;AACtB,SAAM,OAAO;AACb,UAAO,WAAW,OAAO;IACzB,CACD,KAAK,QAAQ,CACb,MAAM,OAAO;GAChB;AAEF,KAAI,SAAS,UACX,QAAO,YAAYA,QAAM,QAAQ,kBAAkB;CAMrD,MAAM,WAAW,4HAAaA,OAAK,QAAQ,iBAAiB,GAAG;AAE/D,KAAI,SAAS,OACX,QAAO,OAAO,SAAS;AAGzB,QAAO"}
|
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -24,20 +28,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
28
|
let prettier_plugins_html = require("prettier/plugins/html");
|
|
25
29
|
prettier_plugins_html = __toESM(prettier_plugins_html);
|
|
26
30
|
let prettier_standalone = require("prettier/standalone");
|
|
27
|
-
prettier_standalone = __toESM(prettier_standalone);
|
|
28
31
|
let html_to_text = require("html-to-text");
|
|
29
|
-
html_to_text = __toESM(html_to_text);
|
|
30
32
|
let react = require("react");
|
|
31
33
|
react = __toESM(react);
|
|
32
34
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
35
|
let node_stream = require("node:stream");
|
|
35
|
-
node_stream = __toESM(node_stream);
|
|
36
36
|
|
|
37
37
|
//#region src/shared/utils/pretty.ts
|
|
38
|
+
function getHtmlNode(path) {
|
|
39
|
+
const topNode = path.node;
|
|
40
|
+
if (topNode) return topNode;
|
|
41
|
+
return path.stack?.[path.stack.length - 1];
|
|
42
|
+
}
|
|
38
43
|
function recursivelyMapDoc(doc, callback) {
|
|
39
44
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
40
45
|
if (typeof doc === "object") {
|
|
46
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
41
47
|
if (doc.type === "group") return {
|
|
42
48
|
...doc,
|
|
43
49
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -56,6 +62,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
56
62
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
57
63
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
58
64
|
};
|
|
65
|
+
const nextDoc = { ...doc };
|
|
66
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
67
|
+
return nextDoc;
|
|
59
68
|
}
|
|
60
69
|
return callback(doc);
|
|
61
70
|
}
|
|
@@ -63,9 +72,9 @@ const modifiedHtml = { ...prettier_plugins_html };
|
|
|
63
72
|
if (modifiedHtml.printers) {
|
|
64
73
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
65
74
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
66
|
-
const node = path
|
|
75
|
+
const node = getHtmlNode(path);
|
|
67
76
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
68
|
-
if (node
|
|
77
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
69
78
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
70
79
|
return doc;
|
|
71
80
|
});
|
|
@@ -183,9 +192,12 @@ const render = async (node, options) => {
|
|
|
183
192
|
reactDOMServer.renderToReadableStream(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBoundary, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, { children: node }) }), {
|
|
184
193
|
progressiveChunkSize: Number.POSITIVE_INFINITY,
|
|
185
194
|
onError(error) {
|
|
186
|
-
|
|
195
|
+
reject(error);
|
|
187
196
|
}
|
|
188
|
-
}).then(
|
|
197
|
+
}).then(async (stream) => {
|
|
198
|
+
await stream.allReady;
|
|
199
|
+
return readStream(stream);
|
|
200
|
+
}).then((result) => {
|
|
189
201
|
html = result;
|
|
190
202
|
resolve();
|
|
191
203
|
}).catch(reject);
|
|
@@ -37,4 +37,4 @@ declare function toPlainText(html: string, options?: HtmlToTextOptions): string;
|
|
|
37
37
|
declare const render: (node: React.ReactNode, options?: Options) => Promise<string>;
|
|
38
38
|
//#endregion
|
|
39
39
|
export { Options, plainTextSelectors, pretty, render, toPlainText };
|
|
40
|
-
//# sourceMappingURL=index.d.
|
|
40
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","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;;;;ACyHA;;;;ECvHa;AASb;;;;ACRA;;;;;sBHoB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCRvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
|
@@ -1 +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;;;;
|
|
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;;;;ACyHA;;;;ECvHa;AASb;;;;ACRA;;;;;sBHoB0B;;;;cCkGb,gCAAgC,cAAY;;;cCvH5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCRvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -6,9 +6,15 @@ import { Fragment, jsx } from "react/jsx-runtime";
|
|
|
6
6
|
import { Writable } from "node:stream";
|
|
7
7
|
|
|
8
8
|
//#region src/shared/utils/pretty.ts
|
|
9
|
+
function getHtmlNode(path) {
|
|
10
|
+
const topNode = path.node;
|
|
11
|
+
if (topNode) return topNode;
|
|
12
|
+
return path.stack?.[path.stack.length - 1];
|
|
13
|
+
}
|
|
9
14
|
function recursivelyMapDoc(doc, callback) {
|
|
10
15
|
if (Array.isArray(doc)) return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
|
|
11
16
|
if (typeof doc === "object") {
|
|
17
|
+
if (doc.type === "line") return callback(doc.soft ? "" : " ");
|
|
12
18
|
if (doc.type === "group") return {
|
|
13
19
|
...doc,
|
|
14
20
|
contents: recursivelyMapDoc(doc.contents, callback),
|
|
@@ -27,6 +33,9 @@ function recursivelyMapDoc(doc, callback) {
|
|
|
27
33
|
breakContents: recursivelyMapDoc(doc.breakContents, callback),
|
|
28
34
|
flatContents: recursivelyMapDoc(doc.flatContents, callback)
|
|
29
35
|
};
|
|
36
|
+
const nextDoc = { ...doc };
|
|
37
|
+
for (const [key, value] of Object.entries(nextDoc)) if (value && typeof value === "object") nextDoc[key] = recursivelyMapDoc(value, callback);
|
|
38
|
+
return nextDoc;
|
|
30
39
|
}
|
|
31
40
|
return callback(doc);
|
|
32
41
|
}
|
|
@@ -34,9 +43,9 @@ const modifiedHtml = { ...html };
|
|
|
34
43
|
if (modifiedHtml.printers) {
|
|
35
44
|
const previousPrint = modifiedHtml.printers.html.print;
|
|
36
45
|
modifiedHtml.printers.html.print = (path, options, print, args) => {
|
|
37
|
-
const node = path
|
|
46
|
+
const node = getHtmlNode(path);
|
|
38
47
|
const rawPrintingResult = previousPrint(path, options, print, args);
|
|
39
|
-
if (node
|
|
48
|
+
if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") return recursivelyMapDoc(rawPrintingResult, (doc) => {
|
|
40
49
|
if (typeof doc === "object" && doc.type === "line") return doc.soft ? "" : " ";
|
|
41
50
|
return doc;
|
|
42
51
|
});
|
|
@@ -154,9 +163,12 @@ const render = async (node, options) => {
|
|
|
154
163
|
reactDOMServer.renderToReadableStream(/* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Suspense, { children: node }) }), {
|
|
155
164
|
progressiveChunkSize: Number.POSITIVE_INFINITY,
|
|
156
165
|
onError(error) {
|
|
157
|
-
|
|
166
|
+
reject(error);
|
|
158
167
|
}
|
|
159
|
-
}).then(
|
|
168
|
+
}).then(async (stream) => {
|
|
169
|
+
await stream.allReady;
|
|
170
|
+
return readStream(stream);
|
|
171
|
+
}).then((result) => {
|
|
160
172
|
html$1 = result;
|
|
161
173
|
resolve();
|
|
162
174
|
}).catch(reject);
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["defaults: Options","plainTextSelectors: SelectorDefinition[]","html","html!: string","html"],"sources":["../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/shared/error-boundary.tsx","../../src/node/read-stream.ts","../../src/node/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 { Writable } from 'node:stream';\nimport type {\n PipeableStream,\n ReactDOMServerReadableStream,\n} from 'react-dom/server.browser';\n\nexport const readStream = async (\n stream: PipeableStream | ReactDOMServerReadableStream,\n) => {\n let result = '';\n // Create a single TextDecoder instance to handle streaming properly\n // This fixes issues with multi-byte characters (e.g., CJK) being split across chunks\n const decoder = new TextDecoder('utf-8');\n\n if ('pipeTo' in stream) {\n // means it's a readable stream\n const writableStream = new WritableStream({\n write(chunk: BufferSource) {\n // Use stream: true to handle multi-byte characters split across chunks\n result += decoder.decode(chunk, { stream: true });\n },\n close() {\n // Flush any remaining bytes\n result += decoder.decode();\n },\n });\n await stream.pipeTo(writableStream);\n } else {\n const writable = new Writable({\n write(chunk: BufferSource, _encoding, callback) {\n // Use stream: true to handle multi-byte characters split across chunks\n result += decoder.decode(chunk, { stream: true });\n\n callback();\n },\n final(callback) {\n // Flush any remaining bytes\n result += decoder.decode();\n callback();\n },\n });\n await new Promise<void>((resolve, reject) => {\n writable.on('pipe', (source) => {\n source.on('error', (err: Error) => {\n writable.destroy(err);\n });\n });\n writable.on('error', reject);\n writable.on('close', () => {\n resolve();\n });\n\n stream.pipe(writable);\n });\n }\n\n return result;\n};\n","import { Suspense } from 'react';\nimport { createErrorBoundary } from '../shared/error-boundary';\nimport type { Options } from '../shared/options';\nimport { pretty } from '../shared/utils/pretty';\nimport { toPlainText } from '../shared/utils/to-plain-text';\nimport { readStream } from './read-stream';\n\nexport const render = async (node: React.ReactNode, options?: Options) => {\n const reactDOMServer = await import('react-dom/server').then((m) => {\n if ('default' in m) {\n return m.default;\n }\n return m;\n });\n\n let html!: string;\n await new Promise<void>((resolve, reject) => {\n if (\n Object.hasOwn(reactDOMServer, 'renderToReadableStream') &&\n typeof WritableStream !== 'undefined'\n ) {\n const ErrorBoundary = createErrorBoundary(reject);\n reactDOMServer\n .renderToReadableStream(\n <ErrorBoundary>\n <Suspense>{node}</Suspense>\n </ErrorBoundary>,\n {\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n onError(error) {\n // Throw immediately when an error occurs to prevent CSR fallback\n throw error;\n },\n },\n )\n .then((stream) => readStream(stream))\n .then((result) => {\n html = result;\n resolve();\n })\n .catch(reject);\n } else {\n const ErrorBoundary = createErrorBoundary(reject);\n const stream = reactDOMServer.renderToPipeableStream(\n <ErrorBoundary>\n <Suspense>{node}</Suspense>\n </ErrorBoundary>,\n {\n async onAllReady() {\n html = await readStream(stream);\n resolve();\n },\n onError(error) {\n reject(error);\n },\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n },\n );\n }\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":";;;;;;;;AAgBA,SAAS,kBACP,KACA,UACc;AACd,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAK,aAAa,kBAAkB,UAAU,SAAS,CAAC;AAGrE,KAAI,OAAO,QAAQ,UAAU;AAC3B,MAAI,IAAI,SAAS,QACf,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACnD,gBAAgB,kBACd,IAAI,gBACJ,SACD;GACF;AAGH,MAAI,cAAc,IAChB,QAAO;GACL,GAAG;GACH,UAAU,kBAAkB,IAAI,UAAU,SAAS;GACpD;AAGH,MAAI,WAAW,IACb,QAAO;GACL,GAAG;GACH,O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,oBAAC,2BACC,oBAAC,sBAAU,OAAgB,GACb,EAChB;IACE,sBAAsB,OAAO;IAC7B,QAAQ,OAAO;AAEb,WAAM;;IAET,CACF,CACA,MAAM,WAAW,WAAW,OAAO,CAAC,CACpC,MAAM,WAAW;AAChB,aAAO;AACP,aAAS;KACT,CACD,MAAM,OAAO;SACX;GACL,MAAM,gBAAgB,oBAAoB,OAAO;GACjD,MAAM,SAAS,eAAe,uBAC5B,oBAAC,2BACC,oBAAC,sBAAU,OAAgB,GACb,EAChB;IACE,MAAM,aAAa;AACjB,cAAO,MAAM,WAAW,OAAO;AAC/B,cAAS;;IAEX,QAAQ,OAAO;AACb,YAAO,MAAM;;IAEf,sBAAsB,OAAO;IAC9B,CACF;;GAEH;AAEF,KAAI,SAAS,UACX,QAAO,YAAYC,QAAM,QAAQ,kBAAkB;CAMrD,MAAM,WAAW,4HAAaA,OAAK,QAAQ,iBAAiB,GAAG;AAE/D,KAAI,SAAS,OACX,QAAO,OAAO,SAAS;AAGzB,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["html","html"],"sources":["../../src/shared/utils/pretty.ts","../../src/shared/utils/to-plain-text.ts","../../src/shared/error-boundary.tsx","../../src/node/read-stream.ts","../../src/node/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 kind?: 'element' | 'text' | 'ieConditionalComment' | 'root';\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 getHtmlNode(path: {\n node?: HtmlNode;\n stack?: Array<Record<string, unknown>>;\n}) {\n const topNode = path.node;\n if (topNode) {\n return topNode;\n }\n\n return path.stack?.[path.stack.length - 1] as 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 === 'line') {\n return callback(doc.soft ? '' : ' ');\n }\n\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 const nextDoc = { ...doc } as Record<string, unknown>;\n for (const [key, value] of Object.entries(nextDoc)) {\n if (value && typeof value === 'object') {\n nextDoc[key] = recursivelyMapDoc(value as builders.Doc, callback);\n }\n }\n\n return nextDoc as builders.Doc;\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 = getHtmlNode(\n path as Parameters<Plugin['printers']['html']['print']>[0],\n );\n\n const rawPrintingResult = previousPrint(path, options, print, args);\n\n if (\n node?.type === 'ieConditionalComment' ||\n node?.kind === 'ieConditionalComment'\n ) {\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 { Writable } from 'node:stream';\nimport type {\n PipeableStream,\n ReactDOMServerReadableStream,\n} from 'react-dom/server.browser';\n\nexport const readStream = async (\n stream: PipeableStream | ReactDOMServerReadableStream,\n) => {\n let result = '';\n // Create a single TextDecoder instance to handle streaming properly\n // This fixes issues with multi-byte characters (e.g., CJK) being split across chunks\n const decoder = new TextDecoder('utf-8');\n\n if ('pipeTo' in stream) {\n // means it's a readable stream\n const writableStream = new WritableStream({\n write(chunk: BufferSource) {\n // Use stream: true to handle multi-byte characters split across chunks\n result += decoder.decode(chunk, { stream: true });\n },\n close() {\n // Flush any remaining bytes\n result += decoder.decode();\n },\n });\n await stream.pipeTo(writableStream);\n } else {\n const writable = new Writable({\n write(chunk: BufferSource, _encoding, callback) {\n // Use stream: true to handle multi-byte characters split across chunks\n result += decoder.decode(chunk, { stream: true });\n\n callback();\n },\n final(callback) {\n // Flush any remaining bytes\n result += decoder.decode();\n callback();\n },\n });\n await new Promise<void>((resolve, reject) => {\n writable.on('pipe', (source) => {\n source.on('error', (err: Error) => {\n writable.destroy(err);\n });\n });\n writable.on('error', reject);\n writable.on('close', () => {\n resolve();\n });\n\n stream.pipe(writable);\n });\n }\n\n return result;\n};\n","import { Suspense } from 'react';\nimport { createErrorBoundary } from '../shared/error-boundary';\nimport type { Options } from '../shared/options';\nimport { pretty } from '../shared/utils/pretty';\nimport { toPlainText } from '../shared/utils/to-plain-text';\nimport { readStream } from './read-stream';\n\nexport const render = async (node: React.ReactNode, options?: Options) => {\n const reactDOMServer = await import('react-dom/server').then((m) => {\n if ('default' in m) {\n return m.default;\n }\n return m;\n });\n\n let html!: string;\n await new Promise<void>((resolve, reject) => {\n if (\n Object.hasOwn(reactDOMServer, 'renderToReadableStream') &&\n typeof WritableStream !== 'undefined'\n ) {\n const ErrorBoundary = createErrorBoundary(reject);\n reactDOMServer\n .renderToReadableStream(\n <ErrorBoundary>\n <Suspense>{node}</Suspense>\n </ErrorBoundary>,\n {\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n onError(error) {\n // Throw immediately when an error occurs to prevent CSR fallback\n reject(error);\n },\n },\n )\n .then(async (stream) => {\n await stream.allReady;\n return readStream(stream);\n })\n .then((result) => {\n html = result;\n resolve();\n })\n .catch(reject);\n } else {\n const ErrorBoundary = createErrorBoundary(reject);\n const stream = reactDOMServer.renderToPipeableStream(\n <ErrorBoundary>\n <Suspense>{node}</Suspense>\n </ErrorBoundary>,\n {\n async onAllReady() {\n html = await readStream(stream);\n resolve();\n },\n onError(error) {\n reject(error);\n },\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n },\n );\n }\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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;IACE,MAAM,aAAa;AACjB,cAAO,MAAM,WAAW,OAAO;AAC/B,cAAS;;IAEX,QAAQ,OAAO;AACb,YAAO,MAAM;;IAEf,sBAAsB,OAAO;IAC9B,CACF;;GAEH;AAEF,KAAI,SAAS,UACX,QAAO,YAAYA,QAAM,QAAQ,kBAAkB;CAMrD,MAAM,WAAW,4HAAaA,OAAK,QAAQ,iBAAiB,GAAG;AAE/D,KAAI,SAAS,OACX,QAAO,OAAO,SAAS;AAGzB,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-email/render",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Transform React components into HTML email templates",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"main": "./dist/browser/index.
|
|
6
|
+
"main": "./dist/browser/index.cjs",
|
|
7
7
|
"module": "./dist/browser/index.mjs",
|
|
8
|
-
"types": "./dist/browser/index.d.
|
|
8
|
+
"types": "./dist/browser/index.d.cts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**"
|
|
11
11
|
],
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"default": "./dist/edge/index.mjs"
|
|
18
18
|
},
|
|
19
19
|
"require": {
|
|
20
|
-
"types": "./dist/edge/index.d.
|
|
21
|
-
"default": "./dist/edge/index.
|
|
20
|
+
"types": "./dist/edge/index.d.cts",
|
|
21
|
+
"default": "./dist/edge/index.cjs"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"deno": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"default": "./dist/browser/index.mjs"
|
|
28
28
|
},
|
|
29
29
|
"require": {
|
|
30
|
-
"types": "./dist/browser/index.d.
|
|
31
|
-
"default": "./dist/browser/index.
|
|
30
|
+
"types": "./dist/browser/index.d.cts",
|
|
31
|
+
"default": "./dist/browser/index.cjs"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"worker": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"default": "./dist/browser/index.mjs"
|
|
38
38
|
},
|
|
39
39
|
"require": {
|
|
40
|
-
"types": "./dist/browser/index.d.
|
|
41
|
-
"default": "./dist/browser/index.
|
|
40
|
+
"types": "./dist/browser/index.d.cts",
|
|
41
|
+
"default": "./dist/browser/index.cjs"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"edge-light": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"default": "./dist/edge/index.mjs"
|
|
48
48
|
},
|
|
49
49
|
"require": {
|
|
50
|
-
"types": "./dist/edge/index.d.
|
|
51
|
-
"default": "./dist/edge/index.
|
|
50
|
+
"types": "./dist/edge/index.d.cts",
|
|
51
|
+
"default": "./dist/edge/index.cjs"
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"convex": {
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"default": "./dist/edge/index.mjs"
|
|
58
58
|
},
|
|
59
59
|
"require": {
|
|
60
|
-
"types": "./dist/edge/index.d.
|
|
61
|
-
"default": "./dist/edge/index.
|
|
60
|
+
"types": "./dist/edge/index.d.cts",
|
|
61
|
+
"default": "./dist/edge/index.cjs"
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"node": {
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"default": "./dist/node/index.mjs"
|
|
68
68
|
},
|
|
69
69
|
"require": {
|
|
70
|
-
"types": "./dist/node/index.d.
|
|
71
|
-
"default": "./dist/node/index.
|
|
70
|
+
"types": "./dist/node/index.d.cts",
|
|
71
|
+
"default": "./dist/node/index.cjs"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"browser": {
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"default": "./dist/browser/index.mjs"
|
|
78
78
|
},
|
|
79
79
|
"require": {
|
|
80
|
-
"types": "./dist/browser/index.d.
|
|
81
|
-
"default": "./dist/browser/index.
|
|
80
|
+
"types": "./dist/browser/index.d.cts",
|
|
81
|
+
"default": "./dist/browser/index.cjs"
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"default": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"default": "./dist/node/index.mjs"
|
|
88
88
|
},
|
|
89
89
|
"require": {
|
|
90
|
-
"types": "./dist/node/index.d.
|
|
91
|
-
"default": "./dist/node/index.
|
|
90
|
+
"types": "./dist/node/index.d.cts",
|
|
91
|
+
"default": "./dist/node/index.cjs"
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -117,10 +117,8 @@
|
|
|
117
117
|
"devDependencies": {
|
|
118
118
|
"@edge-runtime/vm": "5.0.0",
|
|
119
119
|
"@types/html-to-text": "9.0.4",
|
|
120
|
-
"@types/react": "npm:types-react@19.0.0-rc.1",
|
|
121
|
-
"@types/react-dom": "npm:types-react-dom@19.0.0",
|
|
122
120
|
"jsdom": "26.1.0",
|
|
123
|
-
"typescript": "5.
|
|
121
|
+
"typescript": "5.9.3",
|
|
124
122
|
"tsconfig": "0.0.0"
|
|
125
123
|
},
|
|
126
124
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
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"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC0FA;;;;ECxFa;AASb;;;;ACTA;;;;;sBHqB0B;;;;cCmEb,gCAAgC,cAAY;;;cCxF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCTvC,eAAsB,KAAA,CAAM,qBAAqB,YAAO"}
|
package/dist/edge/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/edge/render.tsx"],"sourcesContent":[],"mappings":";;;;KAIY,OAAA;;;AAAZ;;;;AC0FA;;;;ECxFa;AASb;;;;ACPA;;;;;sBHmB0B;;;;cCmEb,gCAAgC,cAAY;;;cCxF5C,oBAAoB;iBASjB,WAAA,yBAAoC;;;cCPvC,kBACF,KAAA,CAAM,wBACL,YAAO"}
|
package/dist/node/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|