@vuemailer/render 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 John Campion Jr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @vuemailer/render
2
+
3
+ Transform Vue components into HTML email templates. The SSR rendering engine
4
+ behind [`vuemailer`](https://github.com/jcamp-code/vuemailer/tree/main/packages/components):
5
+ it renders a Vue component with `createSSRApp` + `vue/server-renderer`, then
6
+ post-processes the output for email — pretty-printing, plain-text conversion,
7
+ and XHTML void-element self-closing — matching
8
+ [react-email](https://github.com/resend/react-email)'s output.
9
+
10
+ ```bash
11
+ pnpm add @vuemailer/render
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { render } from '@vuemailer/render'
18
+ import Email from './email.vue'
19
+
20
+ // Production HTML (minified, self-closed void elements)
21
+ const html = await render(Email, { name: 'Ada' })
22
+
23
+ // Pretty-printed HTML
24
+ const pretty = await render(Email, { name: 'Ada' }, { pretty: true })
25
+
26
+ // Plain-text version
27
+ const text = await render(Email, { name: 'Ada' }, { plainText: true })
28
+ ```
29
+
30
+ ## API
31
+
32
+ ```ts
33
+ render(
34
+ component: Component,
35
+ props?: Record<string, unknown>,
36
+ options?: {
37
+ pretty?: boolean
38
+ plainText?: boolean
39
+ transform?: (html: string) => string | Promise<string>
40
+ },
41
+ ): Promise<string>
42
+ ```
43
+
44
+ - **`pretty`** — format the HTML with a prettier-based pretty-printer.
45
+ - **`plainText`** — return a plain-text rendering (via `html-to-text`) instead
46
+ of HTML.
47
+ - **`transform`** — a post-processing hook applied to the final HTML (after
48
+ pretty-print and self-closing). Pipe the output through an external pipeline —
49
+ [Maizzle](https://maizzle.com), [`juice`](https://github.com/Automattic/juice)
50
+ CSS inlining, or your own transforms — without vuemailer depending on any of
51
+ them. Ignored for `plainText`.
52
+
53
+ ```ts
54
+ import juice from 'juice'
55
+
56
+ const html = await render(Email, props, { transform: (html) => juice(html) })
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT. Derived from [react-email](https://github.com/resend/react-email) and
62
+ [vue-email](https://github.com/vue-email/vue-email) (both MIT).
@@ -0,0 +1,166 @@
1
+ 'use strict';
2
+
3
+ var htmlToText = require('html-to-text');
4
+ var vue = require('vue');
5
+ var serverRenderer = require('vue/server-renderer');
6
+ var html = require('prettier/plugins/html');
7
+ var standalone = require('prettier/standalone');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var html__namespace = /*#__PURE__*/_interopNamespace(html);
28
+
29
+ // src/shared/render.ts
30
+
31
+ // src/shared/plain-text-selectors.ts
32
+ var plainTextSelectors = [
33
+ { selector: "img", format: "skip" },
34
+ { selector: "[data-skip-in-text=true]", format: "skip" },
35
+ {
36
+ selector: "a",
37
+ options: { linkBrackets: false, hideLinkHrefIfSameAsText: true }
38
+ }
39
+ ];
40
+
41
+ // src/shared/utils/cleanup.ts
42
+ function cleanup(str) {
43
+ if (!str || typeof str !== "string") return str;
44
+ return str.replace(/ data-v-inspector="[^"]*"/g, "").replace(/<!---->/g, "").replace(/<!--\[-->/g, "").replace(/<!--\]-->/g, "").replace(/<!--teleport (?:start|end)[^>]*-->/g, "").replace(/<template>/g, "").replace(/<template[^>]*>/g, "").replace(/<\/template>/g, "").replace(/<vuemailer-clean-component>/g, "").replace(/<vuemailer-clean-component[^>]*>/g, "").replace(/<\/vuemailer-clean-component>/g, "");
45
+ }
46
+ function getHtmlNode(path) {
47
+ const topNode = path.node;
48
+ if (topNode) {
49
+ return topNode;
50
+ }
51
+ return path.stack?.[path.stack.length - 1];
52
+ }
53
+ function recursivelyMapDoc(doc, callback) {
54
+ if (Array.isArray(doc)) {
55
+ return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
56
+ }
57
+ if (typeof doc === "object") {
58
+ if (doc.type === "line") {
59
+ return callback(doc.soft ? "" : " ");
60
+ }
61
+ if (doc.type === "group") {
62
+ return {
63
+ ...doc,
64
+ contents: recursivelyMapDoc(doc.contents, callback),
65
+ expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
66
+ };
67
+ }
68
+ if ("contents" in doc) {
69
+ return {
70
+ ...doc,
71
+ contents: recursivelyMapDoc(doc.contents, callback)
72
+ };
73
+ }
74
+ if ("parts" in doc) {
75
+ return {
76
+ ...doc,
77
+ parts: recursivelyMapDoc(doc.parts, callback)
78
+ };
79
+ }
80
+ if (doc.type === "if-break") {
81
+ return {
82
+ ...doc,
83
+ breakContents: recursivelyMapDoc(doc.breakContents, callback),
84
+ flatContents: recursivelyMapDoc(doc.flatContents, callback)
85
+ };
86
+ }
87
+ const nextDoc = { ...doc };
88
+ for (const [key, value] of Object.entries(nextDoc)) {
89
+ if (value && typeof value === "object") {
90
+ nextDoc[key] = recursivelyMapDoc(value, callback);
91
+ }
92
+ }
93
+ return nextDoc;
94
+ }
95
+ return callback(doc);
96
+ }
97
+ var modifiedHtml = { ...html__namespace };
98
+ if (modifiedHtml.printers) {
99
+ const htmlPrinter = modifiedHtml.printers.html;
100
+ const previousPrint = htmlPrinter.print;
101
+ htmlPrinter.print = (path, options, print, args) => {
102
+ const node = getHtmlNode(path);
103
+ const rawPrintingResult = previousPrint(path, options, print, args);
104
+ if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") {
105
+ const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
106
+ if (typeof doc === "object" && doc.type === "line") {
107
+ return doc.soft ? "" : " ";
108
+ }
109
+ return doc;
110
+ });
111
+ return printingResult;
112
+ }
113
+ return rawPrintingResult;
114
+ };
115
+ }
116
+ var defaults = {
117
+ endOfLine: "lf",
118
+ tabWidth: 2,
119
+ plugins: [modifiedHtml],
120
+ bracketSameLine: true,
121
+ parser: "html"
122
+ };
123
+ var pretty = (str, options = {}) => {
124
+ return standalone.format(str.replaceAll("\0", ""), {
125
+ ...defaults,
126
+ ...options
127
+ });
128
+ };
129
+
130
+ // src/shared/utils/self-close-void-elements.ts
131
+ var VOID_ELEMENTS = "area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr";
132
+ var voidElementRegex = new RegExp(
133
+ `<(${VOID_ELEMENTS})\\b((?:"[^"]*"|'[^']*'|[^>])*?)\\s*/?>`,
134
+ "gi"
135
+ );
136
+ function selfCloseVoidElements(html2) {
137
+ return html2.replace(
138
+ voidElementRegex,
139
+ (_match, tag, attrs) => `<${tag}${attrs} />`
140
+ );
141
+ }
142
+
143
+ // src/shared/render.ts
144
+ var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
145
+ async function render(component, props, options) {
146
+ const app = vue.createSSRApp(component, props ?? {});
147
+ const markup = await serverRenderer.renderToString(app);
148
+ if (options?.plainText) {
149
+ return htmlToText.convert(markup, {
150
+ wordwrap: false,
151
+ selectors: plainTextSelectors,
152
+ ...options.htmlToTextOptions
153
+ });
154
+ }
155
+ let document = `${doctype}${cleanup(markup)}`;
156
+ if (options?.pretty) {
157
+ document = await pretty(document);
158
+ }
159
+ const html2 = selfCloseVoidElements(document).replace(/ (?:class|style)=""/g, "");
160
+ return options?.transform ? options.transform(html2) : html2;
161
+ }
162
+
163
+ exports.cleanup = cleanup;
164
+ exports.plainTextSelectors = plainTextSelectors;
165
+ exports.pretty = pretty;
166
+ exports.render = render;
@@ -0,0 +1,60 @@
1
+ import { VNodeProps, AllowedComponentProps, Component } from 'vue';
2
+ import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
3
+ import { Options as Options$1 } from 'prettier';
4
+
5
+ interface Options {
6
+ /**
7
+ * Pretty-print the rendered HTML using prettier.
8
+ * Ignored when `plainText` is `true`.
9
+ */
10
+ pretty?: boolean;
11
+ /**
12
+ * Render the email as plain text instead of HTML.
13
+ */
14
+ plainText?: boolean;
15
+ /**
16
+ * Options forwarded to the `html-to-text` library used for plain-text
17
+ * conversion. Only relevant when `plainText` is `true`.
18
+ *
19
+ * @see https://github.com/html-to-text/node-html-to-text
20
+ */
21
+ htmlToTextOptions?: HtmlToTextOptions;
22
+ /**
23
+ * A post-processing hook applied to the final HTML output, after
24
+ * pretty-printing and void-element self-closing. Use it to pipe the rendered
25
+ * email through an external transformation pipeline — e.g. Maizzle, `juice`
26
+ * CSS inlining, or your own transforms — without vuemailer taking a
27
+ * dependency on any of them.
28
+ *
29
+ * Receives the rendered HTML and returns the transformed HTML (sync or async).
30
+ * Ignored when `plainText` is `true`.
31
+ *
32
+ * @example
33
+ * render(Email, props, { transform: (html) => juice(html) })
34
+ */
35
+ transform?: (html: string) => string | Promise<string>;
36
+ }
37
+
38
+ type ExtractComponentProps<TComponent> = TComponent extends new () => {
39
+ $props: infer P;
40
+ } ? Omit<P, keyof VNodeProps | keyof AllowedComponentProps> : never;
41
+ /**
42
+ * Renders a Vue component into an HTML email string (or plain text).
43
+ *
44
+ * @param component The Vue component to render.
45
+ * @param props Props to pass to the component.
46
+ * @param options Rendering options (`pretty`, `plainText`, ...).
47
+ */
48
+ declare function render<T extends Component>(component: T, props?: ExtractComponentProps<T>, options?: Options): Promise<string>;
49
+
50
+ declare const plainTextSelectors: SelectorDefinition[];
51
+
52
+ declare const pretty: (str: string, options?: Options$1) => Promise<string>;
53
+
54
+ /**
55
+ * Strips Vue SSR/dev artifacts and non-email-friendly wrappers from the
56
+ * rendered markup before it is handed back to the caller.
57
+ */
58
+ declare function cleanup(str: string): string;
59
+
60
+ export { type ExtractComponentProps, type Options, cleanup, plainTextSelectors, pretty, render };
@@ -0,0 +1,60 @@
1
+ import { VNodeProps, AllowedComponentProps, Component } from 'vue';
2
+ import { HtmlToTextOptions, SelectorDefinition } from 'html-to-text';
3
+ import { Options as Options$1 } from 'prettier';
4
+
5
+ interface Options {
6
+ /**
7
+ * Pretty-print the rendered HTML using prettier.
8
+ * Ignored when `plainText` is `true`.
9
+ */
10
+ pretty?: boolean;
11
+ /**
12
+ * Render the email as plain text instead of HTML.
13
+ */
14
+ plainText?: boolean;
15
+ /**
16
+ * Options forwarded to the `html-to-text` library used for plain-text
17
+ * conversion. Only relevant when `plainText` is `true`.
18
+ *
19
+ * @see https://github.com/html-to-text/node-html-to-text
20
+ */
21
+ htmlToTextOptions?: HtmlToTextOptions;
22
+ /**
23
+ * A post-processing hook applied to the final HTML output, after
24
+ * pretty-printing and void-element self-closing. Use it to pipe the rendered
25
+ * email through an external transformation pipeline — e.g. Maizzle, `juice`
26
+ * CSS inlining, or your own transforms — without vuemailer taking a
27
+ * dependency on any of them.
28
+ *
29
+ * Receives the rendered HTML and returns the transformed HTML (sync or async).
30
+ * Ignored when `plainText` is `true`.
31
+ *
32
+ * @example
33
+ * render(Email, props, { transform: (html) => juice(html) })
34
+ */
35
+ transform?: (html: string) => string | Promise<string>;
36
+ }
37
+
38
+ type ExtractComponentProps<TComponent> = TComponent extends new () => {
39
+ $props: infer P;
40
+ } ? Omit<P, keyof VNodeProps | keyof AllowedComponentProps> : never;
41
+ /**
42
+ * Renders a Vue component into an HTML email string (or plain text).
43
+ *
44
+ * @param component The Vue component to render.
45
+ * @param props Props to pass to the component.
46
+ * @param options Rendering options (`pretty`, `plainText`, ...).
47
+ */
48
+ declare function render<T extends Component>(component: T, props?: ExtractComponentProps<T>, options?: Options): Promise<string>;
49
+
50
+ declare const plainTextSelectors: SelectorDefinition[];
51
+
52
+ declare const pretty: (str: string, options?: Options$1) => Promise<string>;
53
+
54
+ /**
55
+ * Strips Vue SSR/dev artifacts and non-email-friendly wrappers from the
56
+ * rendered markup before it is handed back to the caller.
57
+ */
58
+ declare function cleanup(str: string): string;
59
+
60
+ export { type ExtractComponentProps, type Options, cleanup, plainTextSelectors, pretty, render };
@@ -0,0 +1 @@
1
+ export { cleanup, plainTextSelectors, pretty, render } from '../chunk-Z2KO5WJS.js';
@@ -0,0 +1,139 @@
1
+ import * as html from 'prettier/plugins/html';
2
+ import { format } from 'prettier/standalone';
3
+ import { convert } from 'html-to-text';
4
+ import { createSSRApp } from 'vue';
5
+ import { renderToString } from 'vue/server-renderer';
6
+
7
+ // src/shared/plain-text-selectors.ts
8
+ var plainTextSelectors = [
9
+ { selector: "img", format: "skip" },
10
+ { selector: "[data-skip-in-text=true]", format: "skip" },
11
+ {
12
+ selector: "a",
13
+ options: { linkBrackets: false, hideLinkHrefIfSameAsText: true }
14
+ }
15
+ ];
16
+
17
+ // src/shared/utils/cleanup.ts
18
+ function cleanup(str) {
19
+ if (!str || typeof str !== "string") return str;
20
+ return str.replace(/ data-v-inspector="[^"]*"/g, "").replace(/<!---->/g, "").replace(/<!--\[-->/g, "").replace(/<!--\]-->/g, "").replace(/<!--teleport (?:start|end)[^>]*-->/g, "").replace(/<template>/g, "").replace(/<template[^>]*>/g, "").replace(/<\/template>/g, "").replace(/<vuemailer-clean-component>/g, "").replace(/<vuemailer-clean-component[^>]*>/g, "").replace(/<\/vuemailer-clean-component>/g, "");
21
+ }
22
+ function getHtmlNode(path) {
23
+ const topNode = path.node;
24
+ if (topNode) {
25
+ return topNode;
26
+ }
27
+ return path.stack?.[path.stack.length - 1];
28
+ }
29
+ function recursivelyMapDoc(doc, callback) {
30
+ if (Array.isArray(doc)) {
31
+ return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
32
+ }
33
+ if (typeof doc === "object") {
34
+ if (doc.type === "line") {
35
+ return callback(doc.soft ? "" : " ");
36
+ }
37
+ if (doc.type === "group") {
38
+ return {
39
+ ...doc,
40
+ contents: recursivelyMapDoc(doc.contents, callback),
41
+ expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
42
+ };
43
+ }
44
+ if ("contents" in doc) {
45
+ return {
46
+ ...doc,
47
+ contents: recursivelyMapDoc(doc.contents, callback)
48
+ };
49
+ }
50
+ if ("parts" in doc) {
51
+ return {
52
+ ...doc,
53
+ parts: recursivelyMapDoc(doc.parts, callback)
54
+ };
55
+ }
56
+ if (doc.type === "if-break") {
57
+ return {
58
+ ...doc,
59
+ breakContents: recursivelyMapDoc(doc.breakContents, callback),
60
+ flatContents: recursivelyMapDoc(doc.flatContents, callback)
61
+ };
62
+ }
63
+ const nextDoc = { ...doc };
64
+ for (const [key, value] of Object.entries(nextDoc)) {
65
+ if (value && typeof value === "object") {
66
+ nextDoc[key] = recursivelyMapDoc(value, callback);
67
+ }
68
+ }
69
+ return nextDoc;
70
+ }
71
+ return callback(doc);
72
+ }
73
+ var modifiedHtml = { ...html };
74
+ if (modifiedHtml.printers) {
75
+ const htmlPrinter = modifiedHtml.printers.html;
76
+ const previousPrint = htmlPrinter.print;
77
+ htmlPrinter.print = (path, options, print, args) => {
78
+ const node = getHtmlNode(path);
79
+ const rawPrintingResult = previousPrint(path, options, print, args);
80
+ if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") {
81
+ const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
82
+ if (typeof doc === "object" && doc.type === "line") {
83
+ return doc.soft ? "" : " ";
84
+ }
85
+ return doc;
86
+ });
87
+ return printingResult;
88
+ }
89
+ return rawPrintingResult;
90
+ };
91
+ }
92
+ var defaults = {
93
+ endOfLine: "lf",
94
+ tabWidth: 2,
95
+ plugins: [modifiedHtml],
96
+ bracketSameLine: true,
97
+ parser: "html"
98
+ };
99
+ var pretty = (str, options = {}) => {
100
+ return format(str.replaceAll("\0", ""), {
101
+ ...defaults,
102
+ ...options
103
+ });
104
+ };
105
+
106
+ // src/shared/utils/self-close-void-elements.ts
107
+ var VOID_ELEMENTS = "area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr";
108
+ var voidElementRegex = new RegExp(
109
+ `<(${VOID_ELEMENTS})\\b((?:"[^"]*"|'[^']*'|[^>])*?)\\s*/?>`,
110
+ "gi"
111
+ );
112
+ function selfCloseVoidElements(html2) {
113
+ return html2.replace(
114
+ voidElementRegex,
115
+ (_match, tag, attrs) => `<${tag}${attrs} />`
116
+ );
117
+ }
118
+
119
+ // src/shared/render.ts
120
+ var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
121
+ async function render(component, props, options) {
122
+ const app = createSSRApp(component, props ?? {});
123
+ const markup = await renderToString(app);
124
+ if (options?.plainText) {
125
+ return convert(markup, {
126
+ wordwrap: false,
127
+ selectors: plainTextSelectors,
128
+ ...options.htmlToTextOptions
129
+ });
130
+ }
131
+ let document = `${doctype}${cleanup(markup)}`;
132
+ if (options?.pretty) {
133
+ document = await pretty(document);
134
+ }
135
+ const html2 = selfCloseVoidElements(document).replace(/ (?:class|style)=""/g, "");
136
+ return options?.transform ? options.transform(html2) : html2;
137
+ }
138
+
139
+ export { cleanup, plainTextSelectors, pretty, render };
@@ -0,0 +1,166 @@
1
+ 'use strict';
2
+
3
+ var htmlToText = require('html-to-text');
4
+ var vue = require('vue');
5
+ var serverRenderer = require('vue/server-renderer');
6
+ var html = require('prettier/plugins/html');
7
+ var standalone = require('prettier/standalone');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var html__namespace = /*#__PURE__*/_interopNamespace(html);
28
+
29
+ // src/shared/render.ts
30
+
31
+ // src/shared/plain-text-selectors.ts
32
+ var plainTextSelectors = [
33
+ { selector: "img", format: "skip" },
34
+ { selector: "[data-skip-in-text=true]", format: "skip" },
35
+ {
36
+ selector: "a",
37
+ options: { linkBrackets: false, hideLinkHrefIfSameAsText: true }
38
+ }
39
+ ];
40
+
41
+ // src/shared/utils/cleanup.ts
42
+ function cleanup(str) {
43
+ if (!str || typeof str !== "string") return str;
44
+ return str.replace(/ data-v-inspector="[^"]*"/g, "").replace(/<!---->/g, "").replace(/<!--\[-->/g, "").replace(/<!--\]-->/g, "").replace(/<!--teleport (?:start|end)[^>]*-->/g, "").replace(/<template>/g, "").replace(/<template[^>]*>/g, "").replace(/<\/template>/g, "").replace(/<vuemailer-clean-component>/g, "").replace(/<vuemailer-clean-component[^>]*>/g, "").replace(/<\/vuemailer-clean-component>/g, "");
45
+ }
46
+ function getHtmlNode(path) {
47
+ const topNode = path.node;
48
+ if (topNode) {
49
+ return topNode;
50
+ }
51
+ return path.stack?.[path.stack.length - 1];
52
+ }
53
+ function recursivelyMapDoc(doc, callback) {
54
+ if (Array.isArray(doc)) {
55
+ return doc.map((innerDoc) => recursivelyMapDoc(innerDoc, callback));
56
+ }
57
+ if (typeof doc === "object") {
58
+ if (doc.type === "line") {
59
+ return callback(doc.soft ? "" : " ");
60
+ }
61
+ if (doc.type === "group") {
62
+ return {
63
+ ...doc,
64
+ contents: recursivelyMapDoc(doc.contents, callback),
65
+ expandedStates: recursivelyMapDoc(doc.expandedStates, callback)
66
+ };
67
+ }
68
+ if ("contents" in doc) {
69
+ return {
70
+ ...doc,
71
+ contents: recursivelyMapDoc(doc.contents, callback)
72
+ };
73
+ }
74
+ if ("parts" in doc) {
75
+ return {
76
+ ...doc,
77
+ parts: recursivelyMapDoc(doc.parts, callback)
78
+ };
79
+ }
80
+ if (doc.type === "if-break") {
81
+ return {
82
+ ...doc,
83
+ breakContents: recursivelyMapDoc(doc.breakContents, callback),
84
+ flatContents: recursivelyMapDoc(doc.flatContents, callback)
85
+ };
86
+ }
87
+ const nextDoc = { ...doc };
88
+ for (const [key, value] of Object.entries(nextDoc)) {
89
+ if (value && typeof value === "object") {
90
+ nextDoc[key] = recursivelyMapDoc(value, callback);
91
+ }
92
+ }
93
+ return nextDoc;
94
+ }
95
+ return callback(doc);
96
+ }
97
+ var modifiedHtml = { ...html__namespace };
98
+ if (modifiedHtml.printers) {
99
+ const htmlPrinter = modifiedHtml.printers.html;
100
+ const previousPrint = htmlPrinter.print;
101
+ htmlPrinter.print = (path, options, print, args) => {
102
+ const node = getHtmlNode(path);
103
+ const rawPrintingResult = previousPrint(path, options, print, args);
104
+ if (node?.type === "ieConditionalComment" || node?.kind === "ieConditionalComment") {
105
+ const printingResult = recursivelyMapDoc(rawPrintingResult, (doc) => {
106
+ if (typeof doc === "object" && doc.type === "line") {
107
+ return doc.soft ? "" : " ";
108
+ }
109
+ return doc;
110
+ });
111
+ return printingResult;
112
+ }
113
+ return rawPrintingResult;
114
+ };
115
+ }
116
+ var defaults = {
117
+ endOfLine: "lf",
118
+ tabWidth: 2,
119
+ plugins: [modifiedHtml],
120
+ bracketSameLine: true,
121
+ parser: "html"
122
+ };
123
+ var pretty = (str, options = {}) => {
124
+ return standalone.format(str.replaceAll("\0", ""), {
125
+ ...defaults,
126
+ ...options
127
+ });
128
+ };
129
+
130
+ // src/shared/utils/self-close-void-elements.ts
131
+ var VOID_ELEMENTS = "area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr";
132
+ var voidElementRegex = new RegExp(
133
+ `<(${VOID_ELEMENTS})\\b((?:"[^"]*"|'[^']*'|[^>])*?)\\s*/?>`,
134
+ "gi"
135
+ );
136
+ function selfCloseVoidElements(html2) {
137
+ return html2.replace(
138
+ voidElementRegex,
139
+ (_match, tag, attrs) => `<${tag}${attrs} />`
140
+ );
141
+ }
142
+
143
+ // src/shared/render.ts
144
+ var doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
145
+ async function render(component, props, options) {
146
+ const app = vue.createSSRApp(component, props ?? {});
147
+ const markup = await serverRenderer.renderToString(app);
148
+ if (options?.plainText) {
149
+ return htmlToText.convert(markup, {
150
+ wordwrap: false,
151
+ selectors: plainTextSelectors,
152
+ ...options.htmlToTextOptions
153
+ });
154
+ }
155
+ let document = `${doctype}${cleanup(markup)}`;
156
+ if (options?.pretty) {
157
+ document = await pretty(document);
158
+ }
159
+ const html2 = selfCloseVoidElements(document).replace(/ (?:class|style)=""/g, "");
160
+ return options?.transform ? options.transform(html2) : html2;
161
+ }
162
+
163
+ exports.cleanup = cleanup;
164
+ exports.plainTextSelectors = plainTextSelectors;
165
+ exports.pretty = pretty;
166
+ exports.render = render;
@@ -0,0 +1,4 @@
1
+ export { ExtractComponentProps, Options, cleanup, plainTextSelectors, pretty, render } from '../browser/index.cjs';
2
+ import 'vue';
3
+ import 'html-to-text';
4
+ import 'prettier';
@@ -0,0 +1,4 @@
1
+ export { ExtractComponentProps, Options, cleanup, plainTextSelectors, pretty, render } from '../browser/index.js';
2
+ import 'vue';
3
+ import 'html-to-text';
4
+ import 'prettier';
@@ -0,0 +1 @@
1
+ export { cleanup, plainTextSelectors, pretty, render } from '../chunk-Z2KO5WJS.js';
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@vuemailer/render",
3
+ "version": "1.0.0",
4
+ "description": "Transform Vue components into HTML email templates",
5
+ "keywords": [
6
+ "email",
7
+ "render",
8
+ "ssr",
9
+ "vue"
10
+ ],
11
+ "homepage": "https://github.com/jcamp-code/vuemailer/tree/main/packages/render#readme",
12
+ "bugs": "https://github.com/jcamp-code/vuemailer/issues",
13
+ "license": "MIT",
14
+ "author": "John Campion Jr",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/jcamp-code/vuemailer.git",
18
+ "directory": "packages/render"
19
+ },
20
+ "files": [
21
+ "dist/**"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./dist/node/index.cjs",
26
+ "module": "./dist/node/index.js",
27
+ "types": "./dist/node/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "node": {
31
+ "import": {
32
+ "types": "./dist/node/index.d.ts",
33
+ "default": "./dist/node/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/node/index.d.cts",
37
+ "default": "./dist/node/index.cjs"
38
+ }
39
+ },
40
+ "default": {
41
+ "import": {
42
+ "types": "./dist/browser/index.d.ts",
43
+ "default": "./dist/browser/index.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/browser/index.d.cts",
47
+ "default": "./dist/browser/index.cjs"
48
+ }
49
+ }
50
+ }
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "dependencies": {
56
+ "html-to-text": "^9.0.5",
57
+ "prettier": "^3.3.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/html-to-text": "^9.0.4",
61
+ "tsup": "^8.3.0",
62
+ "typescript": "^5.9.3",
63
+ "vitest": "^4.1.8",
64
+ "vue": "^3.5.0"
65
+ },
66
+ "peerDependencies": {
67
+ "vue": "^3.4.0"
68
+ },
69
+ "engines": {
70
+ "node": ">=18.0.0"
71
+ },
72
+ "scripts": {
73
+ "build": "tsup",
74
+ "dev": "tsup --watch",
75
+ "clean": "rm -rf dist",
76
+ "typecheck": "tsc --noEmit",
77
+ "test": "vitest run",
78
+ "test:watch": "vitest"
79
+ }
80
+ }