Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-email/render

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-email/render - npm Package Compare versions

Comparing version 0.0.18-canary.0 to 1.0.0-canary.1

2

dist/browser/index.d.ts

@@ -18,3 +18,3 @@ import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';

declare const render: (component: React.ReactElement, options?: Options) => string;
declare const render: (component: React.ReactElement, options?: Options) => Promise<string>;

@@ -21,0 +21,0 @@ declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;

@@ -73,4 +73,3 @@ "use strict";

// src/shared/render.ts
var ReactDomServer = __toESM(require("react-dom/server"));
// src/browser/render.ts
var import_html_to_text = require("html-to-text");

@@ -101,25 +100,64 @@

// src/shared/render.ts
var render = (component, options) => {
// src/browser/render.ts
var decoder = new TextDecoder("utf-8");
var readStream = (stream) => __async(void 0, null, function* () {
let result = "";
if ("pipeTo" in stream) {
const writableStream = new WritableStream({
write(chunk) {
result += decoder.decode(chunk);
}
});
yield stream.pipeTo(writableStream);
} else {
throw new Error(
"For some reason, the Node version of `react-dom/server` has been imported instead of the browser one.",
{
cause: {
stream
}
}
);
}
return result;
});
var render = (component, options) => __async(void 0, null, function* () {
const { default: reactDOMServer } = yield import("react-dom/server");
let html;
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
html = yield readStream(
yield reactDOMServer.renderToReadableStream(component)
);
} else {
yield new Promise((resolve, reject) => {
const stream = reactDOMServer.renderToPipeableStream(component, {
onAllReady() {
return __async(this, null, function* () {
html = yield readStream(stream);
resolve();
});
},
onError(error) {
reject(error);
}
});
});
}
if (options == null ? void 0 : options.plainText) {
return renderAsPlainText(component, options);
return (0, import_html_to_text.convert)(html, __spreadValues({
selectors: plainTextSelectors
}, options.htmlToTextOptions));
}
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
const markup = ReactDomServer.renderToStaticMarkup(component);
const document = `${doctype}${markup}`;
if (options && options.pretty) {
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
if (options == null ? void 0 : options.pretty) {
return pretty(document);
}
return document;
};
var renderAsPlainText = (component, options) => {
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
selectors: plainTextSelectors
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
};
});
// src/browser/render-async.ts
var import_html_to_text2 = require("html-to-text");
var decoder = new TextDecoder("utf-8");
var readStream = (stream) => __async(void 0, null, function* () {
var decoder2 = new TextDecoder("utf-8");
var readStream2 = (stream) => __async(void 0, null, function* () {
let result = "";

@@ -129,3 +167,3 @@ if ("pipeTo" in stream) {

write(chunk) {
result += decoder.decode(chunk);
result += decoder2.decode(chunk);
}

@@ -150,3 +188,3 @@ });

if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
html = yield readStream(
html = yield readStream2(
yield reactDOMServer.renderToReadableStream(component)

@@ -159,3 +197,3 @@ );

return __async(this, null, function* () {
html = yield readStream(stream);
html = yield readStream2(stream);
resolve();

@@ -162,0 +200,0 @@ });

@@ -18,4 +18,7 @@ import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';

declare const render: (component: React.ReactElement, options?: Options) => string;
declare const render: (component: React.ReactElement, options?: Options) => Promise<string>;
/**
* @deprecated use `render`
*/
declare const renderAsync: (component: React.ReactElement, options?: Options) => Promise<string>;

@@ -22,0 +25,0 @@

@@ -73,4 +73,4 @@ "use strict";

// src/shared/render.ts
var ReactDomServer = __toESM(require("react-dom/server"));
// src/node/render.ts
var import_node_stream = require("stream");
var import_html_to_text = require("html-to-text");

@@ -101,26 +101,70 @@

// src/shared/render.ts
var render = (component, options) => {
// src/node/render.ts
var decoder = new TextDecoder("utf-8");
var readStream = (stream) => __async(void 0, null, function* () {
let result = "";
if ("pipeTo" in stream) {
const writableStream = new WritableStream({
write(chunk) {
result += decoder.decode(chunk);
}
});
yield stream.pipeTo(writableStream);
} else {
const writable = new import_node_stream.Writable({
write(chunk, _encoding, callback) {
result += decoder.decode(chunk);
callback();
}
});
stream.pipe(writable);
return new Promise((resolve, reject) => {
writable.on("error", reject);
writable.on("close", () => {
resolve(result);
});
});
}
return result;
});
var render = (component, options) => __async(void 0, null, function* () {
const { default: reactDOMServer } = yield import("react-dom/server");
let html;
if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
html = yield readStream(
yield reactDOMServer.renderToReadableStream(component)
);
} else {
yield new Promise((resolve, reject) => {
const stream = reactDOMServer.renderToPipeableStream(component, {
onAllReady() {
return __async(this, null, function* () {
html = yield readStream(stream);
resolve();
});
},
onError(error) {
reject(error);
}
});
});
}
if (options == null ? void 0 : options.plainText) {
return renderAsPlainText(component, options);
return (0, import_html_to_text.convert)(html, __spreadValues({
selectors: plainTextSelectors
}, options.htmlToTextOptions));
}
const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
const markup = ReactDomServer.renderToStaticMarkup(component);
const document = `${doctype}${markup}`;
if (options && options.pretty) {
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, "")}`;
if (options == null ? void 0 : options.pretty) {
return pretty(document);
}
return document;
};
var renderAsPlainText = (component, options) => {
return (0, import_html_to_text.convert)(ReactDomServer.renderToStaticMarkup(component), __spreadValues({
selectors: plainTextSelectors
}, (options == null ? void 0 : options.plainText) === true ? options.htmlToTextOptions : {}));
};
});
// src/node/render-async.ts
var import_node_stream = require("stream");
var import_node_stream2 = require("stream");
var import_html_to_text2 = require("html-to-text");
var decoder = new TextDecoder("utf-8");
var readStream = (stream) => __async(void 0, null, function* () {
var decoder2 = new TextDecoder("utf-8");
var readStream2 = (stream) => __async(void 0, null, function* () {
let result = "";

@@ -130,3 +174,3 @@ if ("pipeTo" in stream) {

write(chunk) {
result += decoder.decode(chunk);
result += decoder2.decode(chunk);
}

@@ -136,5 +180,5 @@ });

} else {
const writable = new import_node_stream.Writable({
const writable = new import_node_stream2.Writable({
write(chunk, _encoding, callback) {
result += decoder.decode(chunk);
result += decoder2.decode(chunk);
callback();

@@ -157,3 +201,3 @@ }

if (Object.hasOwn(reactDOMServer, "renderToReadableStream")) {
html = yield readStream(
html = yield readStream2(
yield reactDOMServer.renderToReadableStream(component)

@@ -166,3 +210,3 @@ );

return __async(this, null, function* () {
html = yield readStream(stream);
html = yield readStream2(stream);
resolve();

@@ -169,0 +213,0 @@ });

{
"name": "@react-email/render",
"version": "0.0.18-canary.0",
"version": "1.0.0-canary.1",
"description": "Transform React components into HTML email templates",

@@ -89,3 +89,2 @@ "sideEffects": false,

"devDependencies": {
"@babel/preset-react": "7.23.3",
"@edge-runtime/vm": "3.1.8",

@@ -92,0 +91,0 @@ "@types/html-to-text": "9.0.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc