@maily-to/render 0.0.2 → 0.0.3
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/index.d.mts +99 -58
- package/dist/index.d.ts +99 -58
- package/dist/index.js +1 -3
- package/dist/index.mjs +1 -3
- package/package.json +7 -4
- package/readme.md +2 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { JSONContent } from '@tiptap/core';
|
|
3
|
+
export { JSONContent } from '@tiptap/core';
|
|
2
4
|
|
|
3
|
-
interface JSONContent {
|
|
4
|
-
type?: string;
|
|
5
|
-
attrs?: Record<string, any>;
|
|
6
|
-
content?: JSONContent[];
|
|
7
|
-
marks?: {
|
|
8
|
-
type: string;
|
|
9
|
-
attrs?: Record<string, any>;
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}[];
|
|
12
|
-
text?: string;
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
}
|
|
15
|
-
interface RenderOptions {
|
|
16
|
-
pretty?: boolean;
|
|
17
|
-
plainText?: boolean;
|
|
18
|
-
}
|
|
19
5
|
interface MarkType {
|
|
20
6
|
[key: string]: any;
|
|
21
7
|
type: string;
|
|
@@ -23,28 +9,23 @@ interface MarkType {
|
|
|
23
9
|
}
|
|
24
10
|
declare const allowedSpacers: readonly ["sm", "md", "lg", "xl"];
|
|
25
11
|
type AllowedSpacers = (typeof allowedSpacers)[number];
|
|
12
|
+
interface ThemeOptions {
|
|
13
|
+
colors?: {
|
|
14
|
+
heading?: string;
|
|
15
|
+
paragraph?: string;
|
|
16
|
+
horizontal?: string;
|
|
17
|
+
footer?: string;
|
|
18
|
+
blockquoteBorder?: string;
|
|
19
|
+
};
|
|
20
|
+
fontSize?: {
|
|
21
|
+
paragraph?: string;
|
|
22
|
+
footer?: {
|
|
23
|
+
size?: string;
|
|
24
|
+
lineHeight?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
26
28
|
interface MailyConfig {
|
|
27
|
-
/**
|
|
28
|
-
* The options object allows you to customize the output of the rendered
|
|
29
|
-
* email.
|
|
30
|
-
* - `pretty` - If `true`, the output will be formatted with indentation and
|
|
31
|
-
* line breaks.
|
|
32
|
-
* - `plainText` - If `true`, the output will be plain text instead of HTML.
|
|
33
|
-
* This is useful for testing purposes.
|
|
34
|
-
*
|
|
35
|
-
* Default: `{ pretty: false, plainText: false }`
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```js
|
|
39
|
-
* const maily = new Maily(content, {
|
|
40
|
-
* options: {
|
|
41
|
-
* pretty: true,
|
|
42
|
-
* plainText: true,
|
|
43
|
-
* },
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
options?: RenderOptions;
|
|
48
29
|
/**
|
|
49
30
|
* The preview text is the snippet of text that is pulled into the inbox
|
|
50
31
|
* preview of an email client, usually right after the subject line.
|
|
@@ -92,28 +73,87 @@ interface MailyConfig {
|
|
|
92
73
|
* });
|
|
93
74
|
* ```
|
|
94
75
|
*/
|
|
95
|
-
theme?:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
76
|
+
theme?: ThemeOptions;
|
|
77
|
+
}
|
|
78
|
+
interface RenderOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The options object allows you to customize the output of the rendered
|
|
81
|
+
* email.
|
|
82
|
+
* - `pretty` - If `true`, the output will be formatted with indentation and
|
|
83
|
+
* line breaks.
|
|
84
|
+
* - `plainText` - If `true`, the output will be plain text instead of HTML.
|
|
85
|
+
* This is useful for testing purposes.
|
|
86
|
+
*
|
|
87
|
+
* Default: `pretty` - `false`, `plainText` - `false`
|
|
88
|
+
*/
|
|
89
|
+
pretty?: boolean;
|
|
90
|
+
plainText?: boolean;
|
|
110
91
|
}
|
|
92
|
+
type VariableFormatter = (options: {
|
|
93
|
+
variable: string;
|
|
94
|
+
fallback?: string;
|
|
95
|
+
}) => string;
|
|
96
|
+
type VariableValues = Map<string, string>;
|
|
97
|
+
type LinkValues = Map<string, string>;
|
|
111
98
|
declare class Maily {
|
|
112
99
|
private readonly content;
|
|
113
100
|
private config;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
private variableFormatter;
|
|
102
|
+
private shouldReplaceVariableValues;
|
|
103
|
+
private variableValues;
|
|
104
|
+
private linkValues;
|
|
105
|
+
private openTrackingPixel;
|
|
106
|
+
constructor(content?: JSONContent);
|
|
107
|
+
setPreviewText(preview?: string): void;
|
|
108
|
+
setTheme(theme?: ThemeOptions): void;
|
|
109
|
+
setVariableFormatter(formatter: VariableFormatter): void;
|
|
110
|
+
/**
|
|
111
|
+
* `setVariableValue` will set the variable value.
|
|
112
|
+
* It will also set `shouldReplaceVariableValues` to `true`.
|
|
113
|
+
*
|
|
114
|
+
* @param variable - The variable name
|
|
115
|
+
* @param value - The variable value
|
|
116
|
+
*/
|
|
117
|
+
setVariableValue(variable: string, value: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* `setVariableValues` will set the variable values.
|
|
120
|
+
* It will also set `shouldReplaceVariableValues` to `true`.
|
|
121
|
+
*
|
|
122
|
+
* @param values - The variable values
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```js
|
|
126
|
+
* const maily = new Maily(content);
|
|
127
|
+
* maily.setVariableValues({
|
|
128
|
+
* name: 'John Doe',
|
|
129
|
+
* email: 'john@doe.com',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
setVariableValues(values: Record<string, string>): void;
|
|
134
|
+
setLinkValue(link: string, value: string): void;
|
|
135
|
+
setLinkValues(values: Record<string, string>): void;
|
|
136
|
+
/**
|
|
137
|
+
* `setOpenTrackingPixel` will set the open tracking pixel.
|
|
138
|
+
*
|
|
139
|
+
* @param pixel - The open tracking pixel
|
|
140
|
+
*/
|
|
141
|
+
setOpenTrackingPixel(pixel?: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* `setShouldReplaceVariableValues` will determine whether to replace the
|
|
144
|
+
* variable values or not. Otherwise, it will just return the formatted variable.
|
|
145
|
+
*
|
|
146
|
+
* Default: `false`
|
|
147
|
+
*/
|
|
148
|
+
setShouldReplaceVariableValues(shouldReplace: boolean): void;
|
|
149
|
+
getAllLinks(): string[];
|
|
150
|
+
private isValidUrl;
|
|
151
|
+
renderSync(options?: RenderOptions): string;
|
|
152
|
+
renderAsync(options?: RenderOptions): Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* `markup` will render the JSON content into React Email markup.
|
|
155
|
+
* and return the raw React Tree.
|
|
156
|
+
*/
|
|
117
157
|
markup(): react_jsx_runtime.JSX.Element;
|
|
118
158
|
private getMappedContent;
|
|
119
159
|
private renderNode;
|
|
@@ -137,10 +177,11 @@ declare class Maily {
|
|
|
137
177
|
private logo;
|
|
138
178
|
private image;
|
|
139
179
|
private footer;
|
|
180
|
+
private blockquote;
|
|
140
181
|
}
|
|
141
182
|
|
|
142
|
-
declare function
|
|
183
|
+
declare function renderSync(content: JSONContent, config?: MailyConfig & RenderOptions): string;
|
|
143
184
|
|
|
144
|
-
declare function renderAsync(content: JSONContent, config?: MailyConfig): Promise<string>;
|
|
185
|
+
declare function renderAsync(content: JSONContent, config?: MailyConfig & RenderOptions): Promise<string>;
|
|
145
186
|
|
|
146
|
-
export { type AllowedSpacers, type
|
|
187
|
+
export { type AllowedSpacers, type LinkValues, Maily, type MailyConfig, type MarkType, type RenderOptions, type ThemeOptions, type VariableFormatter, type VariableValues, renderAsync, renderSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { JSONContent } from '@tiptap/core';
|
|
3
|
+
export { JSONContent } from '@tiptap/core';
|
|
2
4
|
|
|
3
|
-
interface JSONContent {
|
|
4
|
-
type?: string;
|
|
5
|
-
attrs?: Record<string, any>;
|
|
6
|
-
content?: JSONContent[];
|
|
7
|
-
marks?: {
|
|
8
|
-
type: string;
|
|
9
|
-
attrs?: Record<string, any>;
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}[];
|
|
12
|
-
text?: string;
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
}
|
|
15
|
-
interface RenderOptions {
|
|
16
|
-
pretty?: boolean;
|
|
17
|
-
plainText?: boolean;
|
|
18
|
-
}
|
|
19
5
|
interface MarkType {
|
|
20
6
|
[key: string]: any;
|
|
21
7
|
type: string;
|
|
@@ -23,28 +9,23 @@ interface MarkType {
|
|
|
23
9
|
}
|
|
24
10
|
declare const allowedSpacers: readonly ["sm", "md", "lg", "xl"];
|
|
25
11
|
type AllowedSpacers = (typeof allowedSpacers)[number];
|
|
12
|
+
interface ThemeOptions {
|
|
13
|
+
colors?: {
|
|
14
|
+
heading?: string;
|
|
15
|
+
paragraph?: string;
|
|
16
|
+
horizontal?: string;
|
|
17
|
+
footer?: string;
|
|
18
|
+
blockquoteBorder?: string;
|
|
19
|
+
};
|
|
20
|
+
fontSize?: {
|
|
21
|
+
paragraph?: string;
|
|
22
|
+
footer?: {
|
|
23
|
+
size?: string;
|
|
24
|
+
lineHeight?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
26
28
|
interface MailyConfig {
|
|
27
|
-
/**
|
|
28
|
-
* The options object allows you to customize the output of the rendered
|
|
29
|
-
* email.
|
|
30
|
-
* - `pretty` - If `true`, the output will be formatted with indentation and
|
|
31
|
-
* line breaks.
|
|
32
|
-
* - `plainText` - If `true`, the output will be plain text instead of HTML.
|
|
33
|
-
* This is useful for testing purposes.
|
|
34
|
-
*
|
|
35
|
-
* Default: `{ pretty: false, plainText: false }`
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```js
|
|
39
|
-
* const maily = new Maily(content, {
|
|
40
|
-
* options: {
|
|
41
|
-
* pretty: true,
|
|
42
|
-
* plainText: true,
|
|
43
|
-
* },
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
options?: RenderOptions;
|
|
48
29
|
/**
|
|
49
30
|
* The preview text is the snippet of text that is pulled into the inbox
|
|
50
31
|
* preview of an email client, usually right after the subject line.
|
|
@@ -92,28 +73,87 @@ interface MailyConfig {
|
|
|
92
73
|
* });
|
|
93
74
|
* ```
|
|
94
75
|
*/
|
|
95
|
-
theme?:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
76
|
+
theme?: ThemeOptions;
|
|
77
|
+
}
|
|
78
|
+
interface RenderOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The options object allows you to customize the output of the rendered
|
|
81
|
+
* email.
|
|
82
|
+
* - `pretty` - If `true`, the output will be formatted with indentation and
|
|
83
|
+
* line breaks.
|
|
84
|
+
* - `plainText` - If `true`, the output will be plain text instead of HTML.
|
|
85
|
+
* This is useful for testing purposes.
|
|
86
|
+
*
|
|
87
|
+
* Default: `pretty` - `false`, `plainText` - `false`
|
|
88
|
+
*/
|
|
89
|
+
pretty?: boolean;
|
|
90
|
+
plainText?: boolean;
|
|
110
91
|
}
|
|
92
|
+
type VariableFormatter = (options: {
|
|
93
|
+
variable: string;
|
|
94
|
+
fallback?: string;
|
|
95
|
+
}) => string;
|
|
96
|
+
type VariableValues = Map<string, string>;
|
|
97
|
+
type LinkValues = Map<string, string>;
|
|
111
98
|
declare class Maily {
|
|
112
99
|
private readonly content;
|
|
113
100
|
private config;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
private variableFormatter;
|
|
102
|
+
private shouldReplaceVariableValues;
|
|
103
|
+
private variableValues;
|
|
104
|
+
private linkValues;
|
|
105
|
+
private openTrackingPixel;
|
|
106
|
+
constructor(content?: JSONContent);
|
|
107
|
+
setPreviewText(preview?: string): void;
|
|
108
|
+
setTheme(theme?: ThemeOptions): void;
|
|
109
|
+
setVariableFormatter(formatter: VariableFormatter): void;
|
|
110
|
+
/**
|
|
111
|
+
* `setVariableValue` will set the variable value.
|
|
112
|
+
* It will also set `shouldReplaceVariableValues` to `true`.
|
|
113
|
+
*
|
|
114
|
+
* @param variable - The variable name
|
|
115
|
+
* @param value - The variable value
|
|
116
|
+
*/
|
|
117
|
+
setVariableValue(variable: string, value: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* `setVariableValues` will set the variable values.
|
|
120
|
+
* It will also set `shouldReplaceVariableValues` to `true`.
|
|
121
|
+
*
|
|
122
|
+
* @param values - The variable values
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```js
|
|
126
|
+
* const maily = new Maily(content);
|
|
127
|
+
* maily.setVariableValues({
|
|
128
|
+
* name: 'John Doe',
|
|
129
|
+
* email: 'john@doe.com',
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
setVariableValues(values: Record<string, string>): void;
|
|
134
|
+
setLinkValue(link: string, value: string): void;
|
|
135
|
+
setLinkValues(values: Record<string, string>): void;
|
|
136
|
+
/**
|
|
137
|
+
* `setOpenTrackingPixel` will set the open tracking pixel.
|
|
138
|
+
*
|
|
139
|
+
* @param pixel - The open tracking pixel
|
|
140
|
+
*/
|
|
141
|
+
setOpenTrackingPixel(pixel?: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* `setShouldReplaceVariableValues` will determine whether to replace the
|
|
144
|
+
* variable values or not. Otherwise, it will just return the formatted variable.
|
|
145
|
+
*
|
|
146
|
+
* Default: `false`
|
|
147
|
+
*/
|
|
148
|
+
setShouldReplaceVariableValues(shouldReplace: boolean): void;
|
|
149
|
+
getAllLinks(): string[];
|
|
150
|
+
private isValidUrl;
|
|
151
|
+
renderSync(options?: RenderOptions): string;
|
|
152
|
+
renderAsync(options?: RenderOptions): Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* `markup` will render the JSON content into React Email markup.
|
|
155
|
+
* and return the raw React Tree.
|
|
156
|
+
*/
|
|
117
157
|
markup(): react_jsx_runtime.JSX.Element;
|
|
118
158
|
private getMappedContent;
|
|
119
159
|
private renderNode;
|
|
@@ -137,10 +177,11 @@ declare class Maily {
|
|
|
137
177
|
private logo;
|
|
138
178
|
private image;
|
|
139
179
|
private footer;
|
|
180
|
+
private blockquote;
|
|
140
181
|
}
|
|
141
182
|
|
|
142
|
-
declare function
|
|
183
|
+
declare function renderSync(content: JSONContent, config?: MailyConfig & RenderOptions): string;
|
|
143
184
|
|
|
144
|
-
declare function renderAsync(content: JSONContent, config?: MailyConfig): Promise<string>;
|
|
185
|
+
declare function renderAsync(content: JSONContent, config?: MailyConfig & RenderOptions): Promise<string>;
|
|
145
186
|
|
|
146
|
-
export { type AllowedSpacers, type
|
|
187
|
+
export { type AllowedSpacers, type LinkValues, Maily, type MailyConfig, type MarkType, type RenderOptions, type ThemeOptions, type VariableFormatter, type VariableValues, renderAsync, renderSync };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
"use strict";var u=Object.defineProperty,z=Object.defineProperties,M=Object.getOwnPropertyDescriptor,A=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var w=(g,t,e)=>t in g?u(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,f=(g,t)=>{for(var e in t||(t={}))b.call(t,e)&&w(g,e,t[e]);if(E)for(var e of E(t))T.call(t,e)&&w(g,e,t[e]);return g},C=(g,t)=>z(g,A(t));var L=(g,t)=>{for(var e in t)u(g,e,{get:t[e],enumerable:!0})},R=(g,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!b.call(g,r)&&r!==e&&u(g,r,{get:()=>t[r],enumerable:!(n=M(t,r))||n.enumerable});return g};var _=g=>R(u({},"__esModule",{value:!0}),g);var J=(g,t,e)=>new Promise((n,r)=>{var i=l=>{try{a(e.next(l))}catch(m){r(m)}},s=l=>{try{a(e.throw(l))}catch(m){r(m)}},a=l=>l.done?n(l.value):Promise.resolve(l.value).then(i,s);a((e=e.apply(g,t)).next())});var I={};L(I,{Maily:()=>S,render:()=>P,renderAsync:()=>F});module.exports=_(I);var k=require("react"),p=require("@react-email/components"),N=require("@react-email/render");function O(){return Math.random().toString(36).substr(2,6)}var o=require("react/jsx-runtime");var B={sm:"8px",md:"16px",lg:"32px",xl:"64px"},v={WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"};var W={h1:{fontSize:"36px",lineHeight:"40px",fontWeight:800},h2:{fontSize:"30px",lineHeight:"36px",fontWeight:700},h3:{fontSize:"24px",lineHeight:"38px",fontWeight:600}};var X={sm:"40px",md:"48px",lg:"64px"},S=class{constructor(t={type:"doc",content:[]},e={}){this.config={options:{pretty:!1,plainText:!1},theme:{colors:{heading:"rgb(17, 24, 39)",paragraph:"rgb(55, 65, 81)",horizontal:"rgb(234, 234, 234)",footer:"rgb(100, 116, 139)"},fontSize:{paragraph:"15px",footer:{size:"14px",lineHeight:"24px"}}}};this.content=t,this.config=f(f({},this.config),e)}render(){let t=this.config.options||{},e=this.markup();return(0,N.render)(e,t)}renderAsync(){return J(this,null,function*(){let t=this.config.options||{},e=this.markup();return(0,N.renderAsync)(e,t)})}markup(){let t=this.content.content||[],e=t.map((i,s)=>{let a={prev:t[s-1],next:t[s+1],parent:i},l=this.renderNode(i,a);return l?(0,o.jsx)(k.Fragment,{children:l},O()):null}),{preview:n}=this.config;return(0,o.jsxs)(p.Html,{children:[(0,o.jsx)(p.Head,{children:(0,o.jsx)(p.Font,{fallbackFontFamily:"sans-serif",fontFamily:"Inter",fontStyle:"normal",fontWeight:400,webFont:{url:"https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19",format:"woff2"}})}),n?(0,o.jsx)(p.Preview,{children:n}):null,(0,o.jsx)(p.Body,{children:(0,o.jsx)(p.Container,{style:{maxWidth:"600px",minWidth:"300px",width:"100%",marginLeft:"auto",marginRight:"auto",padding:"0.5rem"},children:e})})]})}getMappedContent(t,e){var n,r;return(r=(n=t.content)==null?void 0:n.map(i=>{let s=this.renderNode(i,e);return s?(0,o.jsx)(k.Fragment,{children:s},O()):null}))==null?void 0:r.filter(i=>i!==null)}renderNode(t,e={}){var r;let n=t.type||"";if(n in this)return(r=this[n])==null?void 0:r.call(this,t,e);throw new Error(`Node type "${n}" is not supported.`)}renderMark(t){let e=t.text||(0,o.jsx)(o.Fragment,{children:"\xA0"});return(t.marks||[]).reduce((r,i)=>{var a;let s=i.type;if(s in this)return(a=this[s])==null?void 0:a.call(this,i,r);throw new Error(`Mark type "${s}" is not supported.`)},(0,o.jsx)(o.Fragment,{children:e}))}paragraph(t,e){var m,c,d,h;let{attrs:n}=t,r=(n==null?void 0:n.textAlign)||"left",{parent:i,next:s}=e||{},a=(i==null?void 0:i.type)==="listItem",l=(s==null?void 0:s.type)==="spacer";return(0,o.jsx)(p.Text,{style:f({textAlign:r,marginBottom:a||l?"0px":"20px",marginTop:"0px",fontSize:(c=(m=this.config.theme)==null?void 0:m.fontSize)==null?void 0:c.paragraph,color:(h=(d=this.config.theme)==null?void 0:d.colors)==null?void 0:h.paragraph},v),children:t.content?this.getMappedContent(t):(0,o.jsx)(o.Fragment,{children:"\xA0"})})}text(t,e){let n=t.text||" ";return t.marks?this.renderMark(t):(0,o.jsx)(o.Fragment,{children:n})}bold(t,e){return(0,o.jsx)("strong",{children:e})}italic(t,e){return(0,o.jsx)("em",{children:e})}underline(t,e){return(0,o.jsx)("u",{children:e})}strike(t,e){return(0,o.jsx)("s",{style:{textDecoration:"line-through"},children:e})}link(t,e){var a,l;let{attrs:n}=t,r=(n==null?void 0:n.href)||"#",i=(n==null?void 0:n.target)||"_blank",s=(n==null?void 0:n.rel)||"noopener noreferrer nofollow";return(0,o.jsx)(p.Link,{href:r,rel:s,style:{fontWeight:500,textDecoration:"underline",color:(l=(a=this.config.theme)==null?void 0:a.colors)==null?void 0:l.heading},target:i,children:e})}heading(t,e){var y,x;let{attrs:n}=t,{next:r,prev:i}=e||{},s=`h${Number(n==null?void 0:n.level)||1}`,a=(n==null?void 0:n.textAlign)||"left",l=(r==null?void 0:r.type)==="spacer",m=(i==null?void 0:i.type)==="spacer",{fontSize:c,lineHeight:d,fontWeight:h}=W[s];return(0,o.jsx)(p.Heading,{as:s,style:{textAlign:a,color:(x=(y=this.config.theme)==null?void 0:y.colors)==null?void 0:x.heading,marginBottom:l?"0px":"12px",marginTop:"0px",fontSize:c,lineHeight:d,fontWeight:h},children:this.getMappedContent(t)})}variable(t,e){let{attrs:n}=t,r=(n==null?void 0:n.id)||"";return(0,o.jsx)(o.Fragment,{children:`{{${r}}}`})}horizontalRule(t,e){return(0,o.jsx)(p.Hr,{style:{marginTop:"32px",marginBottom:"32px"}})}orderedList(t,e){return(0,o.jsx)(p.Container,{children:(0,o.jsx)("ol",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"decimal"},children:this.getMappedContent(t)})})}bulletList(t,e){return(0,o.jsx)(p.Container,{children:(0,o.jsx)("ul",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"disc"},children:this.getMappedContent(t)})})}listItem(t,e){return(0,o.jsx)("li",{style:f({marginBottom:"8px",paddingLeft:"6px"},v),children:this.getMappedContent(t,C(f({},e),{parent:t}))})}button(t,e){let{attrs:n}=t,{text:r,url:i,variant:s,buttonColor:a,textColor:l,borderRadius:m,alignment:c="left"}=n||{},d="0px";return m==="round"?d="9999px":m==="smooth"&&(d="6px"),(0,o.jsx)(p.Container,{style:{textAlign:c},children:(0,o.jsx)(p.Button,{href:i,style:{color:String(l),backgroundColor:s==="filled"?String(a):"transparent",borderColor:String(a),padding:s==="filled"?"12px 34px":"10px 34px",borderWidth:"2px",borderStyle:"solid",textDecoration:"none",fontSize:"14px",fontWeight:500,borderRadius:d},children:r})})}spacer(t,e){let{attrs:n}=t,{height:r="auto"}=n||{};return(0,o.jsx)(p.Container,{style:{height:B[r]||r}})}hardBreak(t,e){return(0,o.jsx)("br",{})}logo(t,e){let{attrs:n}=t,{src:r,alt:i,title:s,size:a,alignment:l}=n||{},m={marginRight:"auto"};l==="center"?m={marginRight:"auto",marginLeft:"auto"}:l==="right"&&(m={marginLeft:"auto"});let{next:c}=e||{},d=(c==null?void 0:c.type)==="spacer";return(0,o.jsx)(p.Img,{alt:i||s||"Logo",src:r,style:C(f({width:X[a]||a,height:X[a]||a},m),{marginBottom:d?"0px":"32px"}),title:s||i||"Logo"})}image(t,e){let{attrs:n}=t,{src:r,alt:i,title:s}=n||{},{next:a}=e||{},l=(a==null?void 0:a.type)==="spacer";return(0,o.jsx)(p.Img,{alt:i||s||"Image",src:r,style:{height:"auto",width:"auto",maxWidth:"100%",marginBottom:l?"0px":"32px",marginTop:"0px"},title:s||i||"Image"})}footer(t,e){var a,l,m,c,d,h,y,x;let{attrs:n}=t,{textAlign:r="left"}=n||{},{next:i}=e||{},s=(i==null?void 0:i.type)==="spacer";return(0,o.jsx)(p.Text,{style:f({fontSize:(m=(l=(a=this.config.theme)==null?void 0:a.fontSize)==null?void 0:l.footer)==null?void 0:m.size,lineHeight:(h=(d=(c=this.config.theme)==null?void 0:c.fontSize)==null?void 0:d.footer)==null?void 0:h.lineHeight,color:(x=(y=this.config.theme)==null?void 0:y.colors)==null?void 0:x.footer,marginTop:"0px",marginBottom:s?"0px":"20px",textAlign:r},v),children:this.getMappedContent(t)})}};function P(g,t){return new S(g,t).render()}function F(g,t){return J(this,null,function*(){return new S(g,t).renderAsync()})}0&&(module.exports={Maily,render,renderAsync});
|
|
1
|
+
"use strict";var z=Object.create;var S=Object.defineProperty,A=Object.defineProperties,_=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols,B=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var w=(l,t,e)=>t in l?S(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,y=(l,t)=>{for(var e in t||(t={}))C.call(t,e)&&w(l,e,t[e]);if(b)for(var e of b(t))E.call(t,e)&&w(l,e,t[e]);return l},T=(l,t)=>A(l,H(t));var O=(l,t)=>{var e={};for(var n in l)C.call(l,n)&&t.indexOf(n)<0&&(e[n]=l[n]);if(l!=null&&b)for(var n of b(l))t.indexOf(n)<0&&E.call(l,n)&&(e[n]=l[n]);return e};var P=(l,t)=>{for(var e in t)S(l,e,{get:t[e],enumerable:!0})},L=(l,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of F(t))!C.call(l,o)&&o!==e&&S(l,o,{get:()=>t[o],enumerable:!(n=_(t,o))||n.enumerable});return l};var W=(l,t,e)=>(e=l!=null?z(B(l)):{},L(t||!l||!l.__esModule?S(e,"default",{value:l,enumerable:!0}):e,l)),I=l=>L(S({},"__esModule",{value:!0}),l);var k=(l,t,e)=>new Promise((n,o)=>{var r=c=>{try{a(e.next(c))}catch(g){o(g)}},s=c=>{try{a(e.throw(c))}catch(g){o(g)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(r,s);a((e=e.apply(l,t)).next())});var K={};P(K,{Maily:()=>x,renderAsync:()=>j,renderSync:()=>U});module.exports=I(K);var V=require("react"),p=require("@react-email/components"),N=require("@react-email/render"),X=W(require("lodash/merge"));function J(){return Math.random().toString(36).substr(2,6)}var i=require("react/jsx-runtime");var q={sm:"8px",md:"16px",lg:"32px",xl:"64px"},v={WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"};var D={h1:{fontSize:"36px",lineHeight:"40px",fontWeight:800},h2:{fontSize:"30px",lineHeight:"36px",fontWeight:700},h3:{fontSize:"24px",lineHeight:"38px",fontWeight:600}};var R={sm:"40px",md:"48px",lg:"64px"},M={pretty:!1,plainText:!1},$={colors:{heading:"rgb(17, 24, 39)",paragraph:"rgb(55, 65, 81)",horizontal:"rgb(234, 234, 234)",footer:"rgb(100, 116, 139)",blockquoteBorder:"rgb(209, 213, 219)"},fontSize:{paragraph:"15px",footer:{size:"14px",lineHeight:"24px"}}},x=class{constructor(t={type:"doc",content:[]}){this.config={theme:$};this.variableFormatter=({variable:t,fallback:e})=>e?`{{${t},fallback=${e}}}`:`{{${t}}}`;this.shouldReplaceVariableValues=!1;this.variableValues=new Map;this.linkValues=new Map;this.content=t}setPreviewText(t){this.config.preview=t}setTheme(t){this.config.theme=(0,X.default)(this.config.theme,t)}setVariableFormatter(t){this.variableFormatter=t}setVariableValue(t,e){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),this.variableValues.set(t,e)}setVariableValues(t){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),Object.entries(t).forEach(([e,n])=>{this.setVariableValue(e,n)})}setLinkValue(t,e){this.linkValues.set(t,e)}setLinkValues(t){Object.entries(t).forEach(([e,n])=>{this.setLinkValue(e,n)})}setOpenTrackingPixel(t){this.openTrackingPixel=t}setShouldReplaceVariableValues(t){this.shouldReplaceVariableValues=t}getAllLinks(){let t=this.content.content||[],e=[],n=r=>r&&this.isValidUrl(r)&&!r.startsWith("#")&&!r.startsWith("mailto:")&&!r.startsWith("tel:")&&typeof r=="string",o=r=>{var s;if(r.type==="button"){let a=(s=r.attrs)==null?void 0:s.url;n(a)&&a&&e.push(a)}else r.content&&r.content.forEach(a=>{a.marks&&a.marks.forEach(c=>{var m;let g=(m=c.attrs)==null?void 0:m.href;c.type==="link"&&n(g)&&e.push(g)}),a.content&&o(a)})};return t.forEach(r=>{o(r)}),e}isValidUrl(t){try{let e=new URL(t);return!0}catch(e){return!1}}renderSync(t=M){let e=this.markup();return(0,N.render)(e,t)}renderAsync(){return k(this,arguments,function*(t=M){let e=this.markup();return(0,N.renderAsync)(e,t)})}markup(){let t=this.content.content||[],e=t.map((r,s)=>{let a={prev:t[s-1],next:t[s+1],parent:r},c=this.renderNode(r,a);return c?(0,i.jsx)(V.Fragment,{children:c},J()):null}),{preview:n}=this.config;return(0,i.jsxs)(p.Html,{children:[(0,i.jsxs)(p.Head,{children:[(0,i.jsx)(p.Font,{fallbackFontFamily:"sans-serif",fontFamily:"Inter",fontStyle:"normal",fontWeight:400,webFont:{url:"https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19",format:"woff2"}}),(0,i.jsx)("style",{dangerouslySetInnerHTML:{__html:"blockquote,h1,h2,h3,img,li,ol,p,ul{margin-top:0;margin-bottom:0}"}})]}),(0,i.jsxs)(p.Body,{children:[n?(0,i.jsx)(p.Preview,{id:"__react-email-preview",children:n}):null,(0,i.jsx)(p.Container,{style:{maxWidth:"600px",minWidth:"300px",width:"100%",marginLeft:"auto",marginRight:"auto",padding:"0.5rem"},children:e}),this.openTrackingPixel?(0,i.jsx)(p.Img,{alt:"",src:this.openTrackingPixel,style:{display:"none",width:"1px",height:"1px"}}):null]})]})}getMappedContent(t,e){var n,o;return(o=(n=t.content)==null?void 0:n.map(r=>{let s=this.renderNode(r,e);return s?(0,i.jsx)(V.Fragment,{children:s},J()):null}))==null?void 0:o.filter(r=>r!==null)}renderNode(t,e={}){var o;let n=t.type||"";if(n in this)return(o=this[n])==null?void 0:o.call(this,t,e);throw new Error(`Node type "${n}" is not supported.`)}renderMark(t){let e=t.text||(0,i.jsx)(i.Fragment,{children:"\xA0"});return(t.marks||[]).reduce((o,r)=>{var a;let s=r.type;if(s in this)return(a=this[s])==null?void 0:a.call(this,r,o);throw new Error(`Mark type "${s}" is not supported.`)},(0,i.jsx)(i.Fragment,{children:e}))}paragraph(t,e){var g,m,h,d;let{attrs:n}=t,o=(n==null?void 0:n.textAlign)||"left",{parent:r,next:s}=e||{},a=(r==null?void 0:r.type)==="listItem",c=(s==null?void 0:s.type)==="spacer";return(0,i.jsx)(p.Text,{style:y({textAlign:o,marginBottom:a||c?"0px":"20px",marginTop:"0px",fontSize:(m=(g=this.config.theme)==null?void 0:g.fontSize)==null?void 0:m.paragraph,color:(d=(h=this.config.theme)==null?void 0:h.colors)==null?void 0:d.paragraph},v),children:t.content?this.getMappedContent(t):(0,i.jsx)(i.Fragment,{children:"\xA0"})})}text(t,e){let n=t.text||" ";return t.marks?this.renderMark(t):(0,i.jsx)(i.Fragment,{children:n})}bold(t,e){return(0,i.jsx)("strong",{children:e})}italic(t,e){return(0,i.jsx)("em",{children:e})}underline(t,e){return(0,i.jsx)("u",{children:e})}strike(t,e){return(0,i.jsx)("s",{style:{textDecoration:"line-through"},children:e})}link(t,e){var a,c;let{attrs:n}=t,o=(n==null?void 0:n.href)||"#",r=(n==null?void 0:n.target)||"_blank",s=(n==null?void 0:n.rel)||"noopener noreferrer nofollow";return(typeof this.linkValues=="object"||typeof this.variableValues=="object")&&(o=this.linkValues.get(o)||this.variableValues.get(o)||o),(0,i.jsx)(p.Link,{href:o,rel:s,style:{fontWeight:500,textDecoration:"underline",color:(c=(a=this.config.theme)==null?void 0:a.colors)==null?void 0:c.heading},target:r,children:e})}heading(t,e){var u,f;let{attrs:n}=t,{next:o,prev:r}=e||{},s=`h${Number(n==null?void 0:n.level)||1}`,a=(n==null?void 0:n.textAlign)||"left",c=(o==null?void 0:o.type)==="spacer",g=(r==null?void 0:r.type)==="spacer",{fontSize:m,lineHeight:h,fontWeight:d}=D[s];return(0,i.jsx)(p.Heading,{as:s,style:{textAlign:a,color:(f=(u=this.config.theme)==null?void 0:u.colors)==null?void 0:f.heading,marginBottom:c?"0px":"12px",marginTop:"0px",fontSize:m,lineHeight:h,fontWeight:d},children:this.getMappedContent(t)})}variable(t,e){let{id:n,fallback:o}=t.attrs||{},r=this.variableFormatter({variable:n,fallback:o});return this.shouldReplaceVariableValues&&(r=this.variableValues.get(n)||o||r),(0,i.jsx)(i.Fragment,{children:r})}horizontalRule(t,e){return(0,i.jsx)(p.Hr,{style:{marginTop:"32px",marginBottom:"32px"}})}orderedList(t,e){return(0,i.jsx)(p.Container,{children:(0,i.jsx)("ol",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"decimal"},children:this.getMappedContent(t)})})}bulletList(t,e){return(0,i.jsx)(p.Container,{style:{maxWidth:"100%"},children:(0,i.jsx)("ul",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"disc"},children:this.getMappedContent(t)})})}listItem(t,e){return(0,i.jsx)(p.Container,{style:{maxWidth:"100%"},children:(0,i.jsx)("li",{style:y({marginBottom:"8px",paddingLeft:"6px"},v),children:this.getMappedContent(t,T(y({},e),{parent:t}))})})}button(t,e){let{attrs:n}=t,{text:o,url:r,variant:s,buttonColor:a,textColor:c,borderRadius:g,alignment:m="left"}=n||{},h="0px";g==="round"?h="9999px":g==="smooth"&&(h="6px");let{next:d}=e||{},u=(d==null?void 0:d.type)==="spacer",f=this.linkValues.get(r)||this.variableValues.get(r)||r;return(0,i.jsx)(p.Container,{style:{textAlign:m,maxWidth:"100%",marginBottom:u?"0px":"20px"},children:(0,i.jsx)(p.Button,{href:f,style:{color:String(c),backgroundColor:s==="filled"?String(a):"transparent",borderColor:String(a),padding:s==="filled"?"12px 34px":"10px 34px",borderWidth:"2px",borderStyle:"solid",textDecoration:"none",fontSize:"14px",fontWeight:500,borderRadius:h},children:o})})}spacer(t,e){let{attrs:n}=t,{height:o="auto"}=n||{};return(0,i.jsx)(p.Container,{style:{height:q[o]||o}})}hardBreak(t,e){return(0,i.jsx)("br",{})}logo(t,e){let{attrs:n}=t,{src:o,alt:r,title:s,size:a,alignment:c="left"}=n||{},{next:g}=e||{},m=(g==null?void 0:g.type)==="spacer";return(0,i.jsx)(p.Row,{style:{marginTop:"0px",marginBottom:m?"0px":"32px"},children:(0,i.jsx)(p.Column,{align:c,children:(0,i.jsx)(p.Img,{alt:r||s||"Logo",src:o,style:{width:R[a]||a,height:R[a]||a},title:s||r||"Logo"})})})}image(t,e){let{attrs:n}=t,{src:o,alt:r,title:s,width:a="auto",height:c="auto",alignment:g="center"}=n||{},{next:m}=e||{},h=(m==null?void 0:m.type)==="spacer";return(0,i.jsx)(p.Row,{style:{marginTop:"0px",marginBottom:h?"0px":"32px"},children:(0,i.jsx)(p.Column,{align:g,children:(0,i.jsx)(p.Img,{alt:r||s||"Image",src:o,style:{height:c,width:a},title:s||r||"Image"})})})}footer(t,e){var a,c,g,m,h,d,u,f;let{attrs:n}=t,{textAlign:o="left"}=n||{},{next:r}=e||{},s=(r==null?void 0:r.type)==="spacer";return(0,i.jsx)(p.Text,{style:y({fontSize:(g=(c=(a=this.config.theme)==null?void 0:a.fontSize)==null?void 0:c.footer)==null?void 0:g.size,lineHeight:(d=(h=(m=this.config.theme)==null?void 0:m.fontSize)==null?void 0:h.footer)==null?void 0:d.lineHeight,color:(f=(u=this.config.theme)==null?void 0:u.colors)==null?void 0:f.footer,marginTop:"0px",marginBottom:s?"0px":"20px",textAlign:o},v),children:this.getMappedContent(t)})}blockquote(t,e){var a,c;let{next:n,prev:o}=e||{},r=(n==null?void 0:n.type)==="spacer",s=(o==null?void 0:o.type)==="spacer";return(0,i.jsx)("blockquote",{style:{borderLeftWidth:"4px",borderLeftStyle:"solid",borderLeftColor:(c=(a=this.config.theme)==null?void 0:a.colors)==null?void 0:c.blockquoteBorder,paddingLeft:"16px",marginLeft:"0px",marginRight:"0px",marginTop:s?"0px":"20px",marginBottom:r?"0px":"20px"},children:this.getMappedContent(t)})}};function U(l,t){let s=t||{},{theme:e,preview:n}=s,o=O(s,["theme","preview"]),r=new x(l);return r.setPreviewText(n),r.setTheme(e),r.renderSync(o)}function j(l,t){return k(this,null,function*(){let s=t||{},{theme:e,preview:n}=s,o=O(s,["theme","preview"]),r=new x(l);return r.setPreviewText(n),r.setTheme(e),r.renderAsync(o)})}0&&(module.exports={Maily,renderAsync,renderSync});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
var z=Object.defineProperty,M=Object.defineProperties;var A=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var k=(g,t,e)=>t in g?z(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,d=(g,t)=>{for(var e in t||(t={}))H.call(t,e)&&k(g,e,t[e]);if(v)for(var e of v(t))T.call(t,e)&&k(g,e,t[e]);return g},N=(g,t)=>M(g,A(t));var J=(g,t,e)=>new Promise((n,r)=>{var o=p=>{try{a(e.next(p))}catch(l){r(l)}},s=p=>{try{a(e.throw(p))}catch(l){r(l)}},a=p=>p.done?n(p.value):Promise.resolve(p.value).then(o,s);a((e=e.apply(g,t)).next())});import{Fragment as E}from"react";import{Text as w,Html as L,Head as R,Body as _,Font as B,Container as x,Link as W,Heading as P,Hr as F,Button as I,Img as b,Preview as $}from"@react-email/components";import{render as D,renderAsync as K}from"@react-email/render";function C(){return Math.random().toString(36).substr(2,6)}import{Fragment as u,jsx as i,jsxs as G}from"react/jsx-runtime";var j={sm:"8px",md:"16px",lg:"32px",xl:"64px"},O={WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"};var q={h1:{fontSize:"36px",lineHeight:"40px",fontWeight:800},h2:{fontSize:"30px",lineHeight:"36px",fontWeight:700},h3:{fontSize:"24px",lineHeight:"38px",fontWeight:600}};var X={sm:"40px",md:"48px",lg:"64px"},h=class{constructor(t={type:"doc",content:[]},e={}){this.config={options:{pretty:!1,plainText:!1},theme:{colors:{heading:"rgb(17, 24, 39)",paragraph:"rgb(55, 65, 81)",horizontal:"rgb(234, 234, 234)",footer:"rgb(100, 116, 139)"},fontSize:{paragraph:"15px",footer:{size:"14px",lineHeight:"24px"}}}};this.content=t,this.config=d(d({},this.config),e)}render(){let t=this.config.options||{},e=this.markup();return D(e,t)}renderAsync(){return J(this,null,function*(){let t=this.config.options||{},e=this.markup();return K(e,t)})}markup(){let t=this.content.content||[],e=t.map((o,s)=>{let a={prev:t[s-1],next:t[s+1],parent:o},p=this.renderNode(o,a);return p?i(E,{children:p},C()):null}),{preview:n}=this.config;return G(L,{children:[i(R,{children:i(B,{fallbackFontFamily:"sans-serif",fontFamily:"Inter",fontStyle:"normal",fontWeight:400,webFont:{url:"https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19",format:"woff2"}})}),n?i($,{children:n}):null,i(_,{children:i(x,{style:{maxWidth:"600px",minWidth:"300px",width:"100%",marginLeft:"auto",marginRight:"auto",padding:"0.5rem"},children:e})})]})}getMappedContent(t,e){var n,r;return(r=(n=t.content)==null?void 0:n.map(o=>{let s=this.renderNode(o,e);return s?i(E,{children:s},C()):null}))==null?void 0:r.filter(o=>o!==null)}renderNode(t,e={}){var r;let n=t.type||"";if(n in this)return(r=this[n])==null?void 0:r.call(this,t,e);throw new Error(`Node type "${n}" is not supported.`)}renderMark(t){let e=t.text||i(u,{children:"\xA0"});return(t.marks||[]).reduce((r,o)=>{var a;let s=o.type;if(s in this)return(a=this[s])==null?void 0:a.call(this,o,r);throw new Error(`Mark type "${s}" is not supported.`)},i(u,{children:e}))}paragraph(t,e){var l,m,c,f;let{attrs:n}=t,r=(n==null?void 0:n.textAlign)||"left",{parent:o,next:s}=e||{},a=(o==null?void 0:o.type)==="listItem",p=(s==null?void 0:s.type)==="spacer";return i(w,{style:d({textAlign:r,marginBottom:a||p?"0px":"20px",marginTop:"0px",fontSize:(m=(l=this.config.theme)==null?void 0:l.fontSize)==null?void 0:m.paragraph,color:(f=(c=this.config.theme)==null?void 0:c.colors)==null?void 0:f.paragraph},O),children:t.content?this.getMappedContent(t):i(u,{children:"\xA0"})})}text(t,e){let n=t.text||" ";return t.marks?this.renderMark(t):i(u,{children:n})}bold(t,e){return i("strong",{children:e})}italic(t,e){return i("em",{children:e})}underline(t,e){return i("u",{children:e})}strike(t,e){return i("s",{style:{textDecoration:"line-through"},children:e})}link(t,e){var a,p;let{attrs:n}=t,r=(n==null?void 0:n.href)||"#",o=(n==null?void 0:n.target)||"_blank",s=(n==null?void 0:n.rel)||"noopener noreferrer nofollow";return i(W,{href:r,rel:s,style:{fontWeight:500,textDecoration:"underline",color:(p=(a=this.config.theme)==null?void 0:a.colors)==null?void 0:p.heading},target:o,children:e})}heading(t,e){var S,y;let{attrs:n}=t,{next:r,prev:o}=e||{},s=`h${Number(n==null?void 0:n.level)||1}`,a=(n==null?void 0:n.textAlign)||"left",p=(r==null?void 0:r.type)==="spacer",l=(o==null?void 0:o.type)==="spacer",{fontSize:m,lineHeight:c,fontWeight:f}=q[s];return i(P,{as:s,style:{textAlign:a,color:(y=(S=this.config.theme)==null?void 0:S.colors)==null?void 0:y.heading,marginBottom:p?"0px":"12px",marginTop:"0px",fontSize:m,lineHeight:c,fontWeight:f},children:this.getMappedContent(t)})}variable(t,e){let{attrs:n}=t,r=(n==null?void 0:n.id)||"";return i(u,{children:`{{${r}}}`})}horizontalRule(t,e){return i(F,{style:{marginTop:"32px",marginBottom:"32px"}})}orderedList(t,e){return i(x,{children:i("ol",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"decimal"},children:this.getMappedContent(t)})})}bulletList(t,e){return i(x,{children:i("ul",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"disc"},children:this.getMappedContent(t)})})}listItem(t,e){return i("li",{style:d({marginBottom:"8px",paddingLeft:"6px"},O),children:this.getMappedContent(t,N(d({},e),{parent:t}))})}button(t,e){let{attrs:n}=t,{text:r,url:o,variant:s,buttonColor:a,textColor:p,borderRadius:l,alignment:m="left"}=n||{},c="0px";return l==="round"?c="9999px":l==="smooth"&&(c="6px"),i(x,{style:{textAlign:m},children:i(I,{href:o,style:{color:String(p),backgroundColor:s==="filled"?String(a):"transparent",borderColor:String(a),padding:s==="filled"?"12px 34px":"10px 34px",borderWidth:"2px",borderStyle:"solid",textDecoration:"none",fontSize:"14px",fontWeight:500,borderRadius:c},children:r})})}spacer(t,e){let{attrs:n}=t,{height:r="auto"}=n||{};return i(x,{style:{height:j[r]||r}})}hardBreak(t,e){return i("br",{})}logo(t,e){let{attrs:n}=t,{src:r,alt:o,title:s,size:a,alignment:p}=n||{},l={marginRight:"auto"};p==="center"?l={marginRight:"auto",marginLeft:"auto"}:p==="right"&&(l={marginLeft:"auto"});let{next:m}=e||{},c=(m==null?void 0:m.type)==="spacer";return i(b,{alt:o||s||"Logo",src:r,style:N(d({width:X[a]||a,height:X[a]||a},l),{marginBottom:c?"0px":"32px"}),title:s||o||"Logo"})}image(t,e){let{attrs:n}=t,{src:r,alt:o,title:s}=n||{},{next:a}=e||{},p=(a==null?void 0:a.type)==="spacer";return i(b,{alt:o||s||"Image",src:r,style:{height:"auto",width:"auto",maxWidth:"100%",marginBottom:p?"0px":"32px",marginTop:"0px"},title:s||o||"Image"})}footer(t,e){var a,p,l,m,c,f,S,y;let{attrs:n}=t,{textAlign:r="left"}=n||{},{next:o}=e||{},s=(o==null?void 0:o.type)==="spacer";return i(w,{style:d({fontSize:(l=(p=(a=this.config.theme)==null?void 0:a.fontSize)==null?void 0:p.footer)==null?void 0:l.size,lineHeight:(f=(c=(m=this.config.theme)==null?void 0:m.fontSize)==null?void 0:c.footer)==null?void 0:f.lineHeight,color:(y=(S=this.config.theme)==null?void 0:S.colors)==null?void 0:y.footer,marginTop:"0px",marginBottom:s?"0px":"20px",textAlign:r},O),children:this.getMappedContent(t)})}};function it(g,t){return new h(g,t).render()}function pt(g,t){return J(this,null,function*(){return new h(g,t).renderAsync()})}export{h as Maily,it as render,pt as renderAsync};
|
|
1
|
+
var _=Object.defineProperty,H=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var V=(p,t,e)=>t in p?_(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,S=(p,t)=>{for(var e in t||(t={}))w.call(t,e)&&V(p,e,t[e]);if(b)for(var e of b(t))E.call(t,e)&&V(p,e,t[e]);return p},T=(p,t)=>H(p,F(t));var O=(p,t)=>{var e={};for(var n in p)w.call(p,n)&&t.indexOf(n)<0&&(e[n]=p[n]);if(p!=null&&b)for(var n of b(p))t.indexOf(n)<0&&E.call(p,n)&&(e[n]=p[n]);return e};var k=(p,t,e)=>new Promise((n,o)=>{var r=l=>{try{s(e.next(l))}catch(c){o(c)}},i=l=>{try{s(e.throw(l))}catch(c){o(c)}},s=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,i);s((e=e.apply(p,t)).next())});import{Fragment as L}from"react";import{Text as R,Html as B,Head as P,Body as W,Font as I,Container as f,Link as q,Heading as D,Hr as $,Button as U,Img as C,Preview as j,Row as M,Column as X}from"@react-email/components";import{render as K,renderAsync as G}from"@react-email/render";import Q from"lodash/merge";function N(){return Math.random().toString(36).substr(2,6)}import{Fragment as y,jsx as a,jsxs as v}from"react/jsx-runtime";var Y={sm:"8px",md:"16px",lg:"32px",xl:"64px"},J={WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"};var Z={h1:{fontSize:"36px",lineHeight:"40px",fontWeight:800},h2:{fontSize:"30px",lineHeight:"36px",fontWeight:700},h3:{fontSize:"24px",lineHeight:"38px",fontWeight:600}};var z={sm:"40px",md:"48px",lg:"64px"},A={pretty:!1,plainText:!1},tt={colors:{heading:"rgb(17, 24, 39)",paragraph:"rgb(55, 65, 81)",horizontal:"rgb(234, 234, 234)",footer:"rgb(100, 116, 139)",blockquoteBorder:"rgb(209, 213, 219)"},fontSize:{paragraph:"15px",footer:{size:"14px",lineHeight:"24px"}}},x=class{constructor(t={type:"doc",content:[]}){this.config={theme:tt};this.variableFormatter=({variable:t,fallback:e})=>e?`{{${t},fallback=${e}}}`:`{{${t}}}`;this.shouldReplaceVariableValues=!1;this.variableValues=new Map;this.linkValues=new Map;this.content=t}setPreviewText(t){this.config.preview=t}setTheme(t){this.config.theme=Q(this.config.theme,t)}setVariableFormatter(t){this.variableFormatter=t}setVariableValue(t,e){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),this.variableValues.set(t,e)}setVariableValues(t){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),Object.entries(t).forEach(([e,n])=>{this.setVariableValue(e,n)})}setLinkValue(t,e){this.linkValues.set(t,e)}setLinkValues(t){Object.entries(t).forEach(([e,n])=>{this.setLinkValue(e,n)})}setOpenTrackingPixel(t){this.openTrackingPixel=t}setShouldReplaceVariableValues(t){this.shouldReplaceVariableValues=t}getAllLinks(){let t=this.content.content||[],e=[],n=r=>r&&this.isValidUrl(r)&&!r.startsWith("#")&&!r.startsWith("mailto:")&&!r.startsWith("tel:")&&typeof r=="string",o=r=>{var i;if(r.type==="button"){let s=(i=r.attrs)==null?void 0:i.url;n(s)&&s&&e.push(s)}else r.content&&r.content.forEach(s=>{s.marks&&s.marks.forEach(l=>{var g;let c=(g=l.attrs)==null?void 0:g.href;l.type==="link"&&n(c)&&e.push(c)}),s.content&&o(s)})};return t.forEach(r=>{o(r)}),e}isValidUrl(t){try{let e=new URL(t);return!0}catch(e){return!1}}renderSync(t=A){let e=this.markup();return K(e,t)}renderAsync(){return k(this,arguments,function*(t=A){let e=this.markup();return G(e,t)})}markup(){let t=this.content.content||[],e=t.map((r,i)=>{let s={prev:t[i-1],next:t[i+1],parent:r},l=this.renderNode(r,s);return l?a(L,{children:l},N()):null}),{preview:n}=this.config;return v(B,{children:[v(P,{children:[a(I,{fallbackFontFamily:"sans-serif",fontFamily:"Inter",fontStyle:"normal",fontWeight:400,webFont:{url:"https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19",format:"woff2"}}),a("style",{dangerouslySetInnerHTML:{__html:"blockquote,h1,h2,h3,img,li,ol,p,ul{margin-top:0;margin-bottom:0}"}})]}),v(W,{children:[n?a(j,{id:"__react-email-preview",children:n}):null,a(f,{style:{maxWidth:"600px",minWidth:"300px",width:"100%",marginLeft:"auto",marginRight:"auto",padding:"0.5rem"},children:e}),this.openTrackingPixel?a(C,{alt:"",src:this.openTrackingPixel,style:{display:"none",width:"1px",height:"1px"}}):null]})]})}getMappedContent(t,e){var n,o;return(o=(n=t.content)==null?void 0:n.map(r=>{let i=this.renderNode(r,e);return i?a(L,{children:i},N()):null}))==null?void 0:o.filter(r=>r!==null)}renderNode(t,e={}){var o;let n=t.type||"";if(n in this)return(o=this[n])==null?void 0:o.call(this,t,e);throw new Error(`Node type "${n}" is not supported.`)}renderMark(t){let e=t.text||a(y,{children:"\xA0"});return(t.marks||[]).reduce((o,r)=>{var s;let i=r.type;if(i in this)return(s=this[i])==null?void 0:s.call(this,r,o);throw new Error(`Mark type "${i}" is not supported.`)},a(y,{children:e}))}paragraph(t,e){var c,g,m,h;let{attrs:n}=t,o=(n==null?void 0:n.textAlign)||"left",{parent:r,next:i}=e||{},s=(r==null?void 0:r.type)==="listItem",l=(i==null?void 0:i.type)==="spacer";return a(R,{style:S({textAlign:o,marginBottom:s||l?"0px":"20px",marginTop:"0px",fontSize:(g=(c=this.config.theme)==null?void 0:c.fontSize)==null?void 0:g.paragraph,color:(h=(m=this.config.theme)==null?void 0:m.colors)==null?void 0:h.paragraph},J),children:t.content?this.getMappedContent(t):a(y,{children:"\xA0"})})}text(t,e){let n=t.text||" ";return t.marks?this.renderMark(t):a(y,{children:n})}bold(t,e){return a("strong",{children:e})}italic(t,e){return a("em",{children:e})}underline(t,e){return a("u",{children:e})}strike(t,e){return a("s",{style:{textDecoration:"line-through"},children:e})}link(t,e){var s,l;let{attrs:n}=t,o=(n==null?void 0:n.href)||"#",r=(n==null?void 0:n.target)||"_blank",i=(n==null?void 0:n.rel)||"noopener noreferrer nofollow";return(typeof this.linkValues=="object"||typeof this.variableValues=="object")&&(o=this.linkValues.get(o)||this.variableValues.get(o)||o),a(q,{href:o,rel:i,style:{fontWeight:500,textDecoration:"underline",color:(l=(s=this.config.theme)==null?void 0:s.colors)==null?void 0:l.heading},target:r,children:e})}heading(t,e){var d,u;let{attrs:n}=t,{next:o,prev:r}=e||{},i=`h${Number(n==null?void 0:n.level)||1}`,s=(n==null?void 0:n.textAlign)||"left",l=(o==null?void 0:o.type)==="spacer",c=(r==null?void 0:r.type)==="spacer",{fontSize:g,lineHeight:m,fontWeight:h}=Z[i];return a(D,{as:i,style:{textAlign:s,color:(u=(d=this.config.theme)==null?void 0:d.colors)==null?void 0:u.heading,marginBottom:l?"0px":"12px",marginTop:"0px",fontSize:g,lineHeight:m,fontWeight:h},children:this.getMappedContent(t)})}variable(t,e){let{id:n,fallback:o}=t.attrs||{},r=this.variableFormatter({variable:n,fallback:o});return this.shouldReplaceVariableValues&&(r=this.variableValues.get(n)||o||r),a(y,{children:r})}horizontalRule(t,e){return a($,{style:{marginTop:"32px",marginBottom:"32px"}})}orderedList(t,e){return a(f,{children:a("ol",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"decimal"},children:this.getMappedContent(t)})})}bulletList(t,e){return a(f,{style:{maxWidth:"100%"},children:a("ul",{style:{marginTop:"0px",marginBottom:"20px",paddingLeft:"26px",listStyleType:"disc"},children:this.getMappedContent(t)})})}listItem(t,e){return a(f,{style:{maxWidth:"100%"},children:a("li",{style:S({marginBottom:"8px",paddingLeft:"6px"},J),children:this.getMappedContent(t,T(S({},e),{parent:t}))})})}button(t,e){let{attrs:n}=t,{text:o,url:r,variant:i,buttonColor:s,textColor:l,borderRadius:c,alignment:g="left"}=n||{},m="0px";c==="round"?m="9999px":c==="smooth"&&(m="6px");let{next:h}=e||{},d=(h==null?void 0:h.type)==="spacer",u=this.linkValues.get(r)||this.variableValues.get(r)||r;return a(f,{style:{textAlign:g,maxWidth:"100%",marginBottom:d?"0px":"20px"},children:a(U,{href:u,style:{color:String(l),backgroundColor:i==="filled"?String(s):"transparent",borderColor:String(s),padding:i==="filled"?"12px 34px":"10px 34px",borderWidth:"2px",borderStyle:"solid",textDecoration:"none",fontSize:"14px",fontWeight:500,borderRadius:m},children:o})})}spacer(t,e){let{attrs:n}=t,{height:o="auto"}=n||{};return a(f,{style:{height:Y[o]||o}})}hardBreak(t,e){return a("br",{})}logo(t,e){let{attrs:n}=t,{src:o,alt:r,title:i,size:s,alignment:l="left"}=n||{},{next:c}=e||{},g=(c==null?void 0:c.type)==="spacer";return a(M,{style:{marginTop:"0px",marginBottom:g?"0px":"32px"},children:a(X,{align:l,children:a(C,{alt:r||i||"Logo",src:o,style:{width:z[s]||s,height:z[s]||s},title:i||r||"Logo"})})})}image(t,e){let{attrs:n}=t,{src:o,alt:r,title:i,width:s="auto",height:l="auto",alignment:c="center"}=n||{},{next:g}=e||{},m=(g==null?void 0:g.type)==="spacer";return a(M,{style:{marginTop:"0px",marginBottom:m?"0px":"32px"},children:a(X,{align:c,children:a(C,{alt:r||i||"Image",src:o,style:{height:l,width:s},title:i||r||"Image"})})})}footer(t,e){var s,l,c,g,m,h,d,u;let{attrs:n}=t,{textAlign:o="left"}=n||{},{next:r}=e||{},i=(r==null?void 0:r.type)==="spacer";return a(R,{style:S({fontSize:(c=(l=(s=this.config.theme)==null?void 0:s.fontSize)==null?void 0:l.footer)==null?void 0:c.size,lineHeight:(h=(m=(g=this.config.theme)==null?void 0:g.fontSize)==null?void 0:m.footer)==null?void 0:h.lineHeight,color:(u=(d=this.config.theme)==null?void 0:d.colors)==null?void 0:u.footer,marginTop:"0px",marginBottom:i?"0px":"20px",textAlign:o},J),children:this.getMappedContent(t)})}blockquote(t,e){var s,l;let{next:n,prev:o}=e||{},r=(n==null?void 0:n.type)==="spacer",i=(o==null?void 0:o.type)==="spacer";return a("blockquote",{style:{borderLeftWidth:"4px",borderLeftStyle:"solid",borderLeftColor:(l=(s=this.config.theme)==null?void 0:s.colors)==null?void 0:l.blockquoteBorder,paddingLeft:"16px",marginLeft:"0px",marginRight:"0px",marginTop:i?"0px":"20px",marginBottom:r?"0px":"20px"},children:this.getMappedContent(t)})}};function ht(p,t){let i=t||{},{theme:e,preview:n}=i,o=O(i,["theme","preview"]),r=new x(p);return r.setPreviewText(n),r.setTheme(e),r.renderSync(o)}function xt(p,t){return k(this,null,function*(){let i=t||{},{theme:e,preview:n}=i,o=O(i,["theme","preview"]),r=new x(p);return r.setPreviewText(n),r.setTheme(e),r.renderAsync(o)})}export{x as Maily,xt as renderAsync,ht as renderSync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maily-to/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A transformer that converts Maily content into HTML email templates.",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,14 +48,17 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/preset-react": "^7.23.3",
|
|
51
|
-
"@
|
|
51
|
+
"@tiptap/core": "^2.1.13",
|
|
52
|
+
"@types/lodash": "^4.14.202",
|
|
53
|
+
"@types/react": "^18.2.42",
|
|
52
54
|
"eslint-config-custom": "workspace:*",
|
|
53
55
|
"tsconfig": "workspace:*",
|
|
54
|
-
"typescript": "^5.3.
|
|
56
|
+
"typescript": "^5.3.3"
|
|
55
57
|
},
|
|
56
58
|
"dependencies": {
|
|
57
59
|
"@react-email/components": "^0.0.11",
|
|
58
|
-
"@react-email/render": "^0.0.9"
|
|
60
|
+
"@react-email/render": "^0.0.9",
|
|
61
|
+
"lodash": "^4.17.21"
|
|
59
62
|
},
|
|
60
63
|
"peerDependencies": {
|
|
61
64
|
"react": "18.2.0"
|
package/readme.md
CHANGED
|
@@ -20,13 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
Install `maily` from your command line.
|
|
22
22
|
|
|
23
|
-
#### With bun
|
|
24
|
-
|
|
25
23
|
```sh
|
|
26
24
|
pnpm add @maily-to/render
|
|
27
|
-
bun add @maily-to/render
|
|
28
|
-
yarn add @maily-to/render
|
|
29
|
-
npm install @maily-to/render
|
|
30
25
|
```
|
|
31
26
|
|
|
32
27
|
<br>
|
|
@@ -36,9 +31,9 @@ npm install @maily-to/render
|
|
|
36
31
|
Convert React components into a HTML string.
|
|
37
32
|
|
|
38
33
|
```jsx
|
|
39
|
-
import {
|
|
34
|
+
import { renderSync } from '@maily-to/render';
|
|
40
35
|
|
|
41
|
-
const html =
|
|
36
|
+
const html = renderSync({
|
|
42
37
|
type: 'doc',
|
|
43
38
|
content: [
|
|
44
39
|
{
|