@maily-to/render 2.0.0-beta.7 → 2.0.0-beta.8

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.cts CHANGED
@@ -1,8 +1,6 @@
1
- import { AnyMailyMark, AnyMailyNode, FontFamilyItem, FontProps, RendererThemeOptions } from "@maily-to/shared";
1
+ import { AnyMailyMark, AnyMailyNode, FontFamilyItem, FontProps, NodeThemeOptions } from "@maily-to/shared";
2
2
  import { HtmlProps } from "@react-email/components";
3
3
  import { JSONContent } from "@tiptap/core";
4
- import * as react from "react";
5
-
6
4
  //#region src/lib/meta.d.ts
7
5
  /**
8
6
  * Descriptor for a single meta element to inject into the `<head>`.
@@ -36,8 +34,8 @@ type MetaDescriptor = {
36
34
  * Return a placeholder string (e.g. `{{name}}` or `${name}`).
37
35
  */
38
36
  type VariableFormatter = (opts: {
39
- variable: string;
40
37
  fallback?: string;
38
+ variable: string;
41
39
  }) => string;
42
40
  /**
43
41
  * Any value that can be stored in the unified `variables` map.
@@ -46,85 +44,56 @@ type VariableFormatter = (opts: {
46
44
  * - `number` — numeric comparisons in visibility rules
47
45
  * - `boolean` — truthy/falsy visibility checks
48
46
  * - `Record<string, unknown>` — nested object data
49
- * - `Array<Record<string, unknown>>` — arrays iterated by repeat nodes
47
+ * - `VariableValue[]` — arrays iterated by repeat nodes
50
48
  */
51
- type VariableValue = string | number | boolean | Record<string, unknown> | Array<Record<string, unknown>>;
52
- /** Internal resolved config produced by buildConfig. */
53
- type MailyRenderConfig = {
54
- theme: RendererThemeOptions;
55
- fontFamilies: FontFamilyItem[];
56
- variableFormatter: VariableFormatter;
57
- variableValues: Map<string, VariableValue>;
58
- preview?: string | JSONContent;
59
- meta: MetaDescriptor[];
60
- htmlProps: HtmlProps;
61
- openTrackingPixel?: string;
62
- };
49
+ type VariableValue = Record<string, unknown> | VariableValue[] | boolean | number | string;
63
50
  /**
64
51
  * Public config passed to `render()`.
65
52
  *
66
- * All user-provided data lives under a single `variables` key:
67
- *
68
- * @example
69
- * ```ts
70
- * render(json, {
71
- * variables: {
72
- * name: 'Alice', // string → variable substitution
73
- * active: true, // boolean → visibility rules
74
- * items: [{ id: 1 }], // array → repeat iteration
75
- * cta: 'https://example.com', // string → link href override
76
- * },
77
- * });
78
- * ```
79
- *
80
53
  * Resolution priority (highest → lowest):
81
54
  * 1. `item` — per-iteration data set by repeat nodes (via context)
82
55
  * 2. `variables` — this map
83
56
  * 3. `variableFormatter` — fallback that produces a placeholder string
84
57
  */
85
58
  type MailyConfig = {
86
- preview?: string | JSONContent;
87
- theme?: Partial<RendererThemeOptions>;
88
59
  fontFamilies?: FontFamilyItem[];
89
- variables?: Record<string, VariableValue>;
90
- variableFormatter?: VariableFormatter;
91
- meta?: MetaDescriptor[];
92
60
  htmlProps?: HtmlProps;
61
+ meta?: MetaDescriptor[];
93
62
  openTrackingPixel?: string;
63
+ preview?: JSONContent | string;
64
+ theme?: NodeThemeOptions;
65
+ variableFormatter?: VariableFormatter;
66
+ variables?: Record<string, VariableValue>;
94
67
  };
95
- /**
96
- * Merges user-provided MailyConfig with defaults to produce the
97
- * internal MailyRenderConfig used throughout the render pass.
98
- */
99
- declare function buildConfig(config?: MailyConfig): MailyRenderConfig;
68
+ type BuiltMailyConfig = {
69
+ fontFamilies: FontFamilyItem[];
70
+ htmlProps: HtmlProps;
71
+ meta: MetaDescriptor[];
72
+ openTrackingPixel?: string;
73
+ preview?: JSONContent | string;
74
+ variableFormatter: VariableFormatter;
75
+ variableValues: Map<string, VariableValue>;
76
+ };
77
+ declare function buildConfig(config?: MailyConfig): BuiltMailyConfig;
100
78
  //#endregion
101
79
  //#region src/context.d.ts
102
80
  /**
103
81
  * Typed variable keys available on every RenderContext.
104
82
  *
105
- * Built-in keys:
106
- * - `item` — the current record during a repeat iteration. Set by repeat.tsx
107
- * when looping over an array variable. Each iteration gets its own copy so
108
- * sibling iterations are isolated. Variable/visibility lookups check `item`
109
- * first, then fall back to `config.variableValues`.
110
- * - `columnTdWidth` — the TD-relative percentage width string (e.g. `"48.4%"`)
111
- * set by columns.tsx and consumed by column.tsx.
112
- *
113
83
  * Extend via module augmentation to add custom keys:
114
84
  *
115
85
  * @example
116
86
  * ```ts
117
87
  * declare module '@maily-to/render' {
118
88
  * interface RenderVariableMap {
119
- * theme: 'light' | 'dark';
120
- * locale: string;
89
+ * item: Record<string, unknown>;
121
90
  * }
122
91
  * }
123
92
  * ```
124
93
  */
125
94
  interface RenderVariableMap {
126
- item?: Record<string, unknown>;
127
- columnTdWidth?: string;
95
+ columnWidth: string;
96
+ item: Record<string, unknown>;
128
97
  }
129
98
  type BoxModel = {
130
99
  totalWidth: number;
@@ -132,22 +101,22 @@ type BoxModel = {
132
101
  totalPadding: number;
133
102
  };
134
103
  /**
135
- * Render-time context threaded through every node and mark renderer.
104
+ * Render-time context threaded through every node renderer.
136
105
  *
137
106
  * State scoping:
138
107
  * - `config` — immutable, shared by the entire tree.
139
- * - `styles` / `fonts` — shared collectors that accumulate to the document root.
140
- * Use `style()` and `font()` from any depth; they all write to the same sets.
108
+ * - `styles` — a shared collector that accumulates to the document root.
109
+ * Use `style()` from any depth; every context writes to the same set.
110
+ * - `fonts` — a shared collector of the fonts the document needs an
111
+ * `@font-face` rule for, keyed so each variant is registered once.
141
112
  * - `vars` — cloned per `child()` call. A child inherits the parent's vars at
142
- * creation time, but mutations in either direction are isolated. This is what
143
- * allows nested repeat iterations to each carry their own `item` without
144
- * leaking into siblings or parents.
113
+ * creation time, but mutations in either direction are isolated.
145
114
  * - `parent`, `siblingIndex`, `size` — local to each context instance.
146
115
  */
147
116
  interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap> {
148
- readonly parent: AnyMailyNode | AnyMailyMark | undefined;
117
+ readonly parent: AnyMailyNode | undefined;
149
118
  readonly siblingIndex: number;
150
- readonly config: MailyRenderConfig;
119
+ readonly config: BuiltMailyConfig;
151
120
  readonly size: Readonly<BoxModel>;
152
121
  /** Content width after subtracting border and padding from `size.totalWidth`. */
153
122
  readonly box: number;
@@ -170,12 +139,12 @@ interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap>
170
139
  readonly var: Readonly<Variables>;
171
140
  /** Add a CSS rule to the shared document-level style collector. */
172
141
  style(css: string): void;
173
- /** Register a font face in the shared document-level font collector. */
174
- font(name: string, props: FontProps): void;
142
+ /** Add a font to the shared document-level font collector. */
143
+ font(key: string, font: FontProps): void;
175
144
  /**
176
145
  * Derive a child context for rendering a child node.
177
146
  *
178
- * - `config`, `styles`, and `fonts` are shared by reference.
147
+ * - `config` and `styles` are shared by reference.
179
148
  * - `vars` are shallow-cloned so child `set()` calls don't affect the parent.
180
149
  * - `parent`, `siblingIndex`, and `size` can be overridden; unset fields
181
150
  * inherit from the current context.
@@ -185,13 +154,13 @@ interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap>
185
154
  readonly fonts: ReadonlyMap<string, FontProps>;
186
155
  }
187
156
  type ChildContextOptions = {
188
- parent?: AnyMailyNode | AnyMailyMark;
157
+ parent?: AnyMailyNode;
189
158
  siblingIndex?: number;
190
159
  size?: Partial<BoxModel>;
191
160
  };
192
161
  type CreateRenderContextOptions = {
193
- config: MailyRenderConfig;
194
- parent?: AnyMailyNode | AnyMailyMark;
162
+ config: BuiltMailyConfig;
163
+ parent?: AnyMailyNode;
195
164
  siblingIndex?: number;
196
165
  size?: Partial<BoxModel>;
197
166
  };
@@ -207,24 +176,21 @@ declare function defineRenderContext<Variables extends RenderVariableMap = Rende
207
176
  * Returns a deduplicated Set of href strings.
208
177
  */
209
178
  declare function links(json: JSONContent): Set<string>;
179
+ declare function getSafeHref(url: string | null | undefined): string | undefined;
180
+ //#endregion
181
+ //#region src/mark.d.ts
182
+ type MarkRenderer = (mark: AnyMailyMark, text: React.ReactNode, ctx: RenderContext) => React.ReactNode;
183
+ declare function marks(node: AnyMailyNode, ctx: RenderContext): string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null | undefined;
210
184
  //#endregion
211
185
  //#region src/node.d.ts
212
- /**
213
- * Function signature for a node renderer. Each node type (paragraph,
214
- * button, image, etc.) implements this to produce its React output.
215
- */
216
186
  type NodeRenderer = (node: AnyMailyNode, ctx: RenderContext) => React.ReactNode;
217
187
  declare function dispatch(node: AnyMailyNode, ctx: RenderContext): React.ReactNode;
218
188
  declare function children(parent: AnyMailyNode, ctx: RenderContext): React.ReactNode[];
219
189
  //#endregion
220
190
  //#region src/render.d.ts
221
- /**
222
- * Converts a Maily JSON document into React elements. Returns null
223
- * if the input is not a valid Maily node.
224
- */
225
- declare function markup(json: JSONContent, config?: MailyConfig): react.ReactNode;
226
- /** Renders a Maily JSON document to an HTML string using @react-email/render. */
227
- declare function render(json: JSONContent, config?: MailyConfig): Promise<string>;
191
+ declare function markup(json: AnyMailyNode, config?: MailyConfig): import("react").ReactNode;
192
+ declare function render(json: AnyMailyNode, config?: MailyConfig): Promise<string>;
193
+ declare function renderText(json: AnyMailyNode, config?: MailyConfig): Promise<string>;
228
194
  //#endregion
229
- export { BoxModel, ChildContextOptions, CreateRenderContextOptions, MailyConfig, MailyRenderConfig, type MetaDescriptor, NodeRenderer, RenderContext, RenderVariableMap, VariableFormatter, VariableValue, buildConfig, children, defineRenderContext, dispatch, links, markup, render };
195
+ export { BoxModel, BuiltMailyConfig, ChildContextOptions, CreateRenderContextOptions, MailyConfig, MarkRenderer, type MetaDescriptor, NodeRenderer, RenderContext, RenderVariableMap, VariableFormatter, VariableValue, buildConfig, children, defineRenderContext, dispatch, getSafeHref, links, marks, markup, render, renderText };
230
196
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/lib/meta.tsx","../src/config.ts","../src/context.ts","../src/lib/link.ts","../src/node.ts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GAAA,EAAK,aAAA,GACJ,KAAA,CAAM,SAAA;AAAA,iBAaO,QAAA,CACd,MAAA,EAAQ,YAAA,EACR,GAAA,EAAK,aAAA,GACJ,KAAA,CAAM,SAAA;;;;;;;iBCnEO,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,MAAA,GAAQ,WAAA,GAAgB,KAAA,CAAA,SAAA;;iBAa5C,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,MAAA,GAAQ,WAAA,GAAgB,OAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/lib/meta.tsx","../src/config.ts","../src/context.ts","../src/lib/link.ts","../src/mark.tsx","../src/node.tsx","../src/render.tsx"],"mappings":";;;;;;;;;;KAMY;EACN;;EACA;;EACA;EAAc;;EACd;EAAkB;;EAClB;EAAmB;;EACnB;GAA2B;;GAC1B;;;;;;;;KCCK,qBAAqB;EAC/B;EACA;;;;;;;;;;;KAYU,gBACR,0BACA;;;;;;;;;KAaQ;EACV,eAAe;EACf,YAAY;EACZ,OAAO;EACP;EACA,UAAU;EACV,QAAQ;EACR,oBAAoB;EACpB,YAAY,eAAe;;KAGjB;EACV,cAAc;EACd,WAAW;EACX,MAAM;EACN;EACA,UAAU;EACV,mBAAmB;EACnB,gBAAgB,YAAY;;iBAUd,YAAY,SAAQ,cAAmB;;;;;;;;;;;;;;;;;UCpDtC;EACf;EACA,MAAM;;KAGI;EACV;EACA;EACA;;;;;;;;;;;;;;;UAgBe,cACf,kBAAkB,oBAAoB;WAE7B,QAAQ;WACR;WACA,QAAQ;WACR,MAAM,SAAS;;WAEf;;EAGT,OAAO,MAAM,eAAe,MAAM;;EAGlC,SAAS,QAAQ,eAAe,MAAM;;;;;;EAOtC,IAAI,gBAAgB,WAAW,KAAK,GAAG,OAAO,UAAU;;EAGxD,IAAI,gBAAgB,WAAW,KAAK,IAAI,UAAU;;;;;WAMzC,KAAK,SAAS;;EAGvB,MAAM;;EAGN,KAAK,aAAa,MAAM;;;;;;;;;EAUxB,MAAM,MAAM,sBAAsB,cAAc;WAEvC,QAAQ;WACR,OAAO,oBAAoB;;KAG1B;EACV,SAAS;EACT;EACA,OAAO,QAAQ;;KASL;EACV,QAAQ;EACR,SAAS;EACT;EACA,OAAO,QAAQ;;;;;;iBAaD,oBACd,kBAAkB,oBAAoB,mBACtC,MAAM,6BAA6B,cAAc;;;;;;;iBCtHnC,MAAM,MAAM,cAAc;iBA0C1B,YAAY;;;KCzBhB,gBACV,MAAM,cACN,MAAM,MAAM,WACZ,KAAK,kBACF,MAAM;iBA6BK,MAAM,MAAM,cAAc,KAAK,qDAAa,yBAAA,aAAA,6CAAA,yBAAA,6BAAA,+CAAA,8CAAA,kDAAA,+CAAA;;;KCtBhD,gBACV,MAAM,cACN,KAAK,kBACF,MAAM;iBAkCK,SACd,MAAM,cACN,KAAK,gBACJ,MAAM;iBAiBO,SACd,QAAQ,cACR,KAAK,gBACJ,MAAM;;;iBCtFO,OAAO,MAAM,cAAc,SAAQ,8BAAgB;iBAc7C,OAAO,MAAM,cAAc,SAAQ,cAAgB;iBAInD,WAAW,MAAM,cAAc,SAAQ,cAAgB"}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,6 @@
1
- import { AnyMailyMark, AnyMailyNode, FontFamilyItem, FontProps, RendererThemeOptions } from "@maily-to/shared";
2
- import * as react from "react";
1
+ import { AnyMailyMark, AnyMailyNode, FontFamilyItem, FontProps, NodeThemeOptions } from "@maily-to/shared";
3
2
  import { HtmlProps } from "@react-email/components";
4
3
  import { JSONContent } from "@tiptap/core";
5
-
6
4
  //#region src/lib/meta.d.ts
7
5
  /**
8
6
  * Descriptor for a single meta element to inject into the `<head>`.
@@ -36,8 +34,8 @@ type MetaDescriptor = {
36
34
  * Return a placeholder string (e.g. `{{name}}` or `${name}`).
37
35
  */
38
36
  type VariableFormatter = (opts: {
39
- variable: string;
40
37
  fallback?: string;
38
+ variable: string;
41
39
  }) => string;
42
40
  /**
43
41
  * Any value that can be stored in the unified `variables` map.
@@ -46,85 +44,56 @@ type VariableFormatter = (opts: {
46
44
  * - `number` — numeric comparisons in visibility rules
47
45
  * - `boolean` — truthy/falsy visibility checks
48
46
  * - `Record<string, unknown>` — nested object data
49
- * - `Array<Record<string, unknown>>` — arrays iterated by repeat nodes
47
+ * - `VariableValue[]` — arrays iterated by repeat nodes
50
48
  */
51
- type VariableValue = string | number | boolean | Record<string, unknown> | Array<Record<string, unknown>>;
52
- /** Internal resolved config produced by buildConfig. */
53
- type MailyRenderConfig = {
54
- theme: RendererThemeOptions;
55
- fontFamilies: FontFamilyItem[];
56
- variableFormatter: VariableFormatter;
57
- variableValues: Map<string, VariableValue>;
58
- preview?: string | JSONContent;
59
- meta: MetaDescriptor[];
60
- htmlProps: HtmlProps;
61
- openTrackingPixel?: string;
62
- };
49
+ type VariableValue = Record<string, unknown> | VariableValue[] | boolean | number | string;
63
50
  /**
64
51
  * Public config passed to `render()`.
65
52
  *
66
- * All user-provided data lives under a single `variables` key:
67
- *
68
- * @example
69
- * ```ts
70
- * render(json, {
71
- * variables: {
72
- * name: 'Alice', // string → variable substitution
73
- * active: true, // boolean → visibility rules
74
- * items: [{ id: 1 }], // array → repeat iteration
75
- * cta: 'https://example.com', // string → link href override
76
- * },
77
- * });
78
- * ```
79
- *
80
53
  * Resolution priority (highest → lowest):
81
54
  * 1. `item` — per-iteration data set by repeat nodes (via context)
82
55
  * 2. `variables` — this map
83
56
  * 3. `variableFormatter` — fallback that produces a placeholder string
84
57
  */
85
58
  type MailyConfig = {
86
- preview?: string | JSONContent;
87
- theme?: Partial<RendererThemeOptions>;
88
59
  fontFamilies?: FontFamilyItem[];
89
- variables?: Record<string, VariableValue>;
90
- variableFormatter?: VariableFormatter;
91
- meta?: MetaDescriptor[];
92
60
  htmlProps?: HtmlProps;
61
+ meta?: MetaDescriptor[];
93
62
  openTrackingPixel?: string;
63
+ preview?: JSONContent | string;
64
+ theme?: NodeThemeOptions;
65
+ variableFormatter?: VariableFormatter;
66
+ variables?: Record<string, VariableValue>;
94
67
  };
95
- /**
96
- * Merges user-provided MailyConfig with defaults to produce the
97
- * internal MailyRenderConfig used throughout the render pass.
98
- */
99
- declare function buildConfig(config?: MailyConfig): MailyRenderConfig;
68
+ type BuiltMailyConfig = {
69
+ fontFamilies: FontFamilyItem[];
70
+ htmlProps: HtmlProps;
71
+ meta: MetaDescriptor[];
72
+ openTrackingPixel?: string;
73
+ preview?: JSONContent | string;
74
+ variableFormatter: VariableFormatter;
75
+ variableValues: Map<string, VariableValue>;
76
+ };
77
+ declare function buildConfig(config?: MailyConfig): BuiltMailyConfig;
100
78
  //#endregion
101
79
  //#region src/context.d.ts
102
80
  /**
103
81
  * Typed variable keys available on every RenderContext.
104
82
  *
105
- * Built-in keys:
106
- * - `item` — the current record during a repeat iteration. Set by repeat.tsx
107
- * when looping over an array variable. Each iteration gets its own copy so
108
- * sibling iterations are isolated. Variable/visibility lookups check `item`
109
- * first, then fall back to `config.variableValues`.
110
- * - `columnTdWidth` — the TD-relative percentage width string (e.g. `"48.4%"`)
111
- * set by columns.tsx and consumed by column.tsx.
112
- *
113
83
  * Extend via module augmentation to add custom keys:
114
84
  *
115
85
  * @example
116
86
  * ```ts
117
87
  * declare module '@maily-to/render' {
118
88
  * interface RenderVariableMap {
119
- * theme: 'light' | 'dark';
120
- * locale: string;
89
+ * item: Record<string, unknown>;
121
90
  * }
122
91
  * }
123
92
  * ```
124
93
  */
125
94
  interface RenderVariableMap {
126
- item?: Record<string, unknown>;
127
- columnTdWidth?: string;
95
+ columnWidth: string;
96
+ item: Record<string, unknown>;
128
97
  }
129
98
  type BoxModel = {
130
99
  totalWidth: number;
@@ -132,22 +101,22 @@ type BoxModel = {
132
101
  totalPadding: number;
133
102
  };
134
103
  /**
135
- * Render-time context threaded through every node and mark renderer.
104
+ * Render-time context threaded through every node renderer.
136
105
  *
137
106
  * State scoping:
138
107
  * - `config` — immutable, shared by the entire tree.
139
- * - `styles` / `fonts` — shared collectors that accumulate to the document root.
140
- * Use `style()` and `font()` from any depth; they all write to the same sets.
108
+ * - `styles` — a shared collector that accumulates to the document root.
109
+ * Use `style()` from any depth; every context writes to the same set.
110
+ * - `fonts` — a shared collector of the fonts the document needs an
111
+ * `@font-face` rule for, keyed so each variant is registered once.
141
112
  * - `vars` — cloned per `child()` call. A child inherits the parent's vars at
142
- * creation time, but mutations in either direction are isolated. This is what
143
- * allows nested repeat iterations to each carry their own `item` without
144
- * leaking into siblings or parents.
113
+ * creation time, but mutations in either direction are isolated.
145
114
  * - `parent`, `siblingIndex`, `size` — local to each context instance.
146
115
  */
147
116
  interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap> {
148
- readonly parent: AnyMailyNode | AnyMailyMark | undefined;
117
+ readonly parent: AnyMailyNode | undefined;
149
118
  readonly siblingIndex: number;
150
- readonly config: MailyRenderConfig;
119
+ readonly config: BuiltMailyConfig;
151
120
  readonly size: Readonly<BoxModel>;
152
121
  /** Content width after subtracting border and padding from `size.totalWidth`. */
153
122
  readonly box: number;
@@ -170,12 +139,12 @@ interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap>
170
139
  readonly var: Readonly<Variables>;
171
140
  /** Add a CSS rule to the shared document-level style collector. */
172
141
  style(css: string): void;
173
- /** Register a font face in the shared document-level font collector. */
174
- font(name: string, props: FontProps): void;
142
+ /** Add a font to the shared document-level font collector. */
143
+ font(key: string, font: FontProps): void;
175
144
  /**
176
145
  * Derive a child context for rendering a child node.
177
146
  *
178
- * - `config`, `styles`, and `fonts` are shared by reference.
147
+ * - `config` and `styles` are shared by reference.
179
148
  * - `vars` are shallow-cloned so child `set()` calls don't affect the parent.
180
149
  * - `parent`, `siblingIndex`, and `size` can be overridden; unset fields
181
150
  * inherit from the current context.
@@ -185,13 +154,13 @@ interface RenderContext<Variables extends RenderVariableMap = RenderVariableMap>
185
154
  readonly fonts: ReadonlyMap<string, FontProps>;
186
155
  }
187
156
  type ChildContextOptions = {
188
- parent?: AnyMailyNode | AnyMailyMark;
157
+ parent?: AnyMailyNode;
189
158
  siblingIndex?: number;
190
159
  size?: Partial<BoxModel>;
191
160
  };
192
161
  type CreateRenderContextOptions = {
193
- config: MailyRenderConfig;
194
- parent?: AnyMailyNode | AnyMailyMark;
162
+ config: BuiltMailyConfig;
163
+ parent?: AnyMailyNode;
195
164
  siblingIndex?: number;
196
165
  size?: Partial<BoxModel>;
197
166
  };
@@ -207,24 +176,21 @@ declare function defineRenderContext<Variables extends RenderVariableMap = Rende
207
176
  * Returns a deduplicated Set of href strings.
208
177
  */
209
178
  declare function links(json: JSONContent): Set<string>;
179
+ declare function getSafeHref(url: string | null | undefined): string | undefined;
180
+ //#endregion
181
+ //#region src/mark.d.ts
182
+ type MarkRenderer = (mark: AnyMailyMark, text: React.ReactNode, ctx: RenderContext) => React.ReactNode;
183
+ declare function marks(node: AnyMailyNode, ctx: RenderContext): string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null | undefined;
210
184
  //#endregion
211
185
  //#region src/node.d.ts
212
- /**
213
- * Function signature for a node renderer. Each node type (paragraph,
214
- * button, image, etc.) implements this to produce its React output.
215
- */
216
186
  type NodeRenderer = (node: AnyMailyNode, ctx: RenderContext) => React.ReactNode;
217
187
  declare function dispatch(node: AnyMailyNode, ctx: RenderContext): React.ReactNode;
218
188
  declare function children(parent: AnyMailyNode, ctx: RenderContext): React.ReactNode[];
219
189
  //#endregion
220
190
  //#region src/render.d.ts
221
- /**
222
- * Converts a Maily JSON document into React elements. Returns null
223
- * if the input is not a valid Maily node.
224
- */
225
- declare function markup(json: JSONContent, config?: MailyConfig): react.ReactNode;
226
- /** Renders a Maily JSON document to an HTML string using @react-email/render. */
227
- declare function render(json: JSONContent, config?: MailyConfig): Promise<string>;
191
+ declare function markup(json: AnyMailyNode, config?: MailyConfig): import("react").ReactNode;
192
+ declare function render(json: AnyMailyNode, config?: MailyConfig): Promise<string>;
193
+ declare function renderText(json: AnyMailyNode, config?: MailyConfig): Promise<string>;
228
194
  //#endregion
229
- export { BoxModel, ChildContextOptions, CreateRenderContextOptions, MailyConfig, MailyRenderConfig, type MetaDescriptor, NodeRenderer, RenderContext, RenderVariableMap, VariableFormatter, VariableValue, buildConfig, children, defineRenderContext, dispatch, links, markup, render };
195
+ export { BoxModel, BuiltMailyConfig, ChildContextOptions, CreateRenderContextOptions, MailyConfig, MarkRenderer, type MetaDescriptor, NodeRenderer, RenderContext, RenderVariableMap, VariableFormatter, VariableValue, buildConfig, children, defineRenderContext, dispatch, getSafeHref, links, marks, markup, render, renderText };
230
196
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/meta.tsx","../src/config.ts","../src/context.ts","../src/lib/link.ts","../src/node.tsx","../src/render.tsx"],"mappings":";;;;;;;;;;;;KAMY,cAAA;EACN,OAAA;AAAA;EACA,KAAA;AAAA;EACA,IAAA;EAAc,OAAA;AAAA;EACd,QAAA;EAAkB,OAAA;AAAA;EAClB,SAAA;EAAmB,OAAA;AAAA;EACnB,OAAA;EAAA,CAA2B,IAAA;AAAA;EAAA,CAC1B,IAAA;AAAA;;;;;AAPP;;KCQY,iBAAA,IAAqB,IAAA;EAC/B,QAAA;EACA,QAAA;AAAA;;;;;;;;;;KAYU,aAAA,+BAIR,MAAA,oBACA,KAAA,CAAM,MAAA;;KAGE,iBAAA;EACV,KAAA,EAAO,oBAAA;EACP,YAAA,EAAc,cAAA;EAEd,iBAAA,EAAmB,iBAAA;EACnB,cAAA,EAAgB,GAAA,SAAY,aAAA;EAE5B,OAAA,YAAmB,WAAA;EACnB,IAAA,EAAM,cAAA;EACN,SAAA,EAAW,SAAA;EACX,iBAAA;AAAA;;;AAlBF;;;;;;;;;;;;;AAQA;;;;;;;KAmCY,WAAA;EACV,OAAA,YAAmB,WAAA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AAA,EAAO,WAAA,SAAoB,SAAA;AAAA;AAAA,KAG1B,mBAAA;EACV,MAAA,GAAS,YAAA,GAAe,YAAA;EACxB,YAAA;EACA,IAAA,GAAO,OAAA,CAAQ,QAAA;AAAA;AAAA,KASL,0BAAA;EACV,MAAA,EAAQ,iBAAA;EACR,MAAA,GAAS,YAAA,GAAe,YAAA;EACxB,YAAA;EACA,IAAA,GAAO,OAAA,CAAQ,QAAA;AAAA;;;;;iBAaD,mBAAA,mBACI,iBAAA,GAAoB,iBAAA,CAAA,CACtC,IAAA,EAAM,0BAAA,GAA6B,aAAA,CAAc,SAAA;;;;;;;iBC9HnC,KAAA,CAAM,IAAA,EAAM,WAAA,GAAc,GAAA;;;;;;;KCwB9B,YAAA,IACV,IAAA,EAAM,YAAA,EACN,GAAA,EAAK,aAAA,KACF,KAAA,CAAM,SAAA;AAAA,iBA2BK,QAAA,CACd,IAAA,EAAM,YAAA,EACN,GAAA,EAAK,aAAA,GACJ,KAAA,CAAM,SAAA;AAAA,iBAaO,QAAA,CACd,MAAA,EAAQ,YAAA,EACR,GAAA,EAAK,aAAA,GACJ,KAAA,CAAM,SAAA;;;;;;;iBCnEO,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,MAAA,GAAQ,WAAA,GAAgB,KAAA,CAAA,SAAA;;iBAa5C,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,MAAA,GAAQ,WAAA,GAAgB,OAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/meta.tsx","../src/config.ts","../src/context.ts","../src/lib/link.ts","../src/mark.tsx","../src/node.tsx","../src/render.tsx"],"mappings":";;;;;;;;;;KAMY;EACN;;EACA;;EACA;EAAc;;EACd;EAAkB;;EAClB;EAAmB;;EACnB;GAA2B;;GAC1B;;;;;;;;KCCK,qBAAqB;EAC/B;EACA;;;;;;;;;;;KAYU,gBACR,0BACA;;;;;;;;;KAaQ;EACV,eAAe;EACf,YAAY;EACZ,OAAO;EACP;EACA,UA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