@templatical/renderer 0.10.0 → 0.10.1
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.ts +108 -98
- package/dist/index.js +737 -884
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Block, ColumnLayout, CustomBlock, CustomFont, SpacingValue, TemplateContent } from "@templatical/types";
|
|
2
2
|
|
|
3
|
+
//#region src/render-context.d.ts
|
|
3
4
|
declare const DEFAULT_SOCIAL_ICONS_BASE_URL: string;
|
|
4
5
|
/**
|
|
5
6
|
* Immutable context passed through the block rendering chain.
|
|
6
7
|
*/
|
|
7
8
|
declare class RenderContext {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
customBlockHtml?: ReadonlyMap<string, string>,
|
|
33
|
-
/**
|
|
34
|
-
* Base URL (no trailing slash) for the social icon PNG assets. Resolved to
|
|
35
|
-
* `${baseUrl}/${style}/${platform}.png`. Outlook desktop has no SVG support
|
|
36
|
-
* and rejects base64 data URIs in `<img src>`, so PNGs must be served over
|
|
37
|
-
* HTTP. Default points at the version-pinned unpkg mirror of this
|
|
38
|
-
* package; consumers can override to self-host.
|
|
39
|
-
*/
|
|
40
|
-
socialIconsBaseUrl?: string);
|
|
41
|
-
/**
|
|
42
|
-
* Create a new context with a different container width.
|
|
43
|
-
* Used when rendering columns with narrower widths.
|
|
44
|
-
*/
|
|
45
|
-
withContainerWidth(width: number): RenderContext;
|
|
46
|
-
/**
|
|
47
|
-
* Resolve a font family name to include custom font fallbacks.
|
|
48
|
-
* If the font matches a custom font, returns `'FontName', fallback`.
|
|
49
|
-
* Otherwise returns the original font family string.
|
|
50
|
-
*/
|
|
51
|
-
resolveFontFamily(fontFamily: string): string;
|
|
52
|
-
}
|
|
9
|
+
readonly containerWidth: number;
|
|
10
|
+
readonly customFonts: CustomFont[];
|
|
11
|
+
readonly defaultFallbackFont: string;
|
|
12
|
+
readonly allowHtmlBlocks: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Map of custom block id → pre-rendered HTML, populated by `renderToMjml`
|
|
15
|
+
* before the synchronous render pass. Set when the consumer provides a
|
|
16
|
+
* `renderCustomBlock` option. Empty by default.
|
|
17
|
+
*/
|
|
18
|
+
readonly customBlockHtml: ReadonlyMap<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Base URL (no trailing slash) for the social icon PNG assets. Resolved to
|
|
21
|
+
* `${baseUrl}/${style}/${platform}.png`. Outlook desktop has no SVG support
|
|
22
|
+
* and rejects base64 data URIs in `<img src>`, so PNGs must be served over
|
|
23
|
+
* HTTP. Default points at the version-pinned unpkg mirror of this
|
|
24
|
+
* package; consumers can override to self-host.
|
|
25
|
+
*/
|
|
26
|
+
readonly socialIconsBaseUrl: string;
|
|
27
|
+
constructor(containerWidth: number, customFonts: CustomFont[], defaultFallbackFont: string, allowHtmlBlocks: boolean,
|
|
28
|
+
/**
|
|
29
|
+
* Map of custom block id → pre-rendered HTML, populated by `renderToMjml`
|
|
30
|
+
* before the synchronous render pass. Set when the consumer provides a
|
|
31
|
+
* `renderCustomBlock` option. Empty by default.
|
|
32
|
+
*/
|
|
53
33
|
|
|
34
|
+
customBlockHtml?: ReadonlyMap<string, string>,
|
|
35
|
+
/**
|
|
36
|
+
* Base URL (no trailing slash) for the social icon PNG assets. Resolved to
|
|
37
|
+
* `${baseUrl}/${style}/${platform}.png`. Outlook desktop has no SVG support
|
|
38
|
+
* and rejects base64 data URIs in `<img src>`, so PNGs must be served over
|
|
39
|
+
* HTTP. Default points at the version-pinned unpkg mirror of this
|
|
40
|
+
* package; consumers can override to self-host.
|
|
41
|
+
*/
|
|
42
|
+
socialIconsBaseUrl?: string);
|
|
43
|
+
/**
|
|
44
|
+
* Create a new context with a different container width.
|
|
45
|
+
* Used when rendering columns with narrower widths.
|
|
46
|
+
*/
|
|
47
|
+
withContainerWidth(width: number): RenderContext;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a font family name to include custom font fallbacks.
|
|
50
|
+
* If the font matches a custom font, returns `'FontName', fallback`.
|
|
51
|
+
* Otherwise returns the original font family string.
|
|
52
|
+
*/
|
|
53
|
+
resolveFontFamily(fontFamily: string): string;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/escape.d.ts
|
|
54
57
|
/**
|
|
55
58
|
* Escape HTML special characters (& < > " ').
|
|
56
59
|
* Equivalent to PHP htmlspecialchars with ENT_QUOTES | ENT_HTML5.
|
|
@@ -73,7 +76,8 @@ declare function escapeAttr(text: string): string;
|
|
|
73
76
|
* `indexOf('>')`, keeping the work strictly O(n).
|
|
74
77
|
*/
|
|
75
78
|
declare function convertMergeTagsToValues(html: string): string;
|
|
76
|
-
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/visibility.d.ts
|
|
77
81
|
/**
|
|
78
82
|
* Check if a block is hidden on all viewports.
|
|
79
83
|
*/
|
|
@@ -87,7 +91,8 @@ declare function getCssClassAttr(block: Block): string;
|
|
|
87
91
|
* Get the CSS classes for visibility hiding.
|
|
88
92
|
*/
|
|
89
93
|
declare function getCssClasses(block: Block): string;
|
|
90
|
-
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/columns.d.ts
|
|
91
96
|
/**
|
|
92
97
|
* Get width percentages for each column in a layout.
|
|
93
98
|
*/
|
|
@@ -96,68 +101,72 @@ declare function getWidthPercentages(layout: ColumnLayout): string[];
|
|
|
96
101
|
* Get width in pixels for each column in a layout.
|
|
97
102
|
*/
|
|
98
103
|
declare function getWidthPixels(layout: ColumnLayout, containerWidth: number): number[];
|
|
99
|
-
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/padding.d.ts
|
|
100
106
|
/**
|
|
101
107
|
* Convert a SpacingValue to a CSS padding string like "10px 10px 10px 10px".
|
|
102
108
|
*/
|
|
103
109
|
declare function toPaddingString(padding: SpacingValue): string;
|
|
104
|
-
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/renderers/index.d.ts
|
|
105
112
|
/**
|
|
106
113
|
* Render a single block to MJML markup.
|
|
107
114
|
* Dispatches to the appropriate block-type renderer.
|
|
108
115
|
*/
|
|
109
116
|
declare function renderBlock(block: Block, context: RenderContext): string;
|
|
110
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/renderers/section.d.ts
|
|
111
119
|
/**
|
|
112
120
|
* A function type that renders a single block to MJML markup.
|
|
113
121
|
*/
|
|
114
122
|
type BlockRenderer = (block: Block, context: RenderContext) => string;
|
|
115
|
-
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/index.d.ts
|
|
116
125
|
interface RenderOptions {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
126
|
+
customFonts?: CustomFont[];
|
|
127
|
+
defaultFallbackFont?: string;
|
|
128
|
+
allowHtmlBlocks?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Resolves custom blocks to their HTML representation. Called once per
|
|
131
|
+
* custom block in the content tree before MJML rendering. The renderer
|
|
132
|
+
* has no built-in knowledge of how to render custom blocks; consumers
|
|
133
|
+
* provide this function.
|
|
134
|
+
*
|
|
135
|
+
* Editor consumers: pass `editor.renderCustomBlock`.
|
|
136
|
+
*
|
|
137
|
+
* Headless consumers (Node.js, server, CLI): provide your own resolver,
|
|
138
|
+
* typically using the same liquid template + field values pipeline as
|
|
139
|
+
* the editor uses. If omitted, custom blocks fall back to
|
|
140
|
+
* `block.renderedHtml` (if present) and otherwise are omitted from the
|
|
141
|
+
* output.
|
|
142
|
+
*/
|
|
143
|
+
renderCustomBlock?: (block: CustomBlock) => Promise<string>;
|
|
144
|
+
/**
|
|
145
|
+
* Resolves the definition-level CSS for a custom block type. Called once
|
|
146
|
+
* per unique `customType` present in the content tree (not per instance).
|
|
147
|
+
* The non-empty results are deduped by content and emitted as additional
|
|
148
|
+
* `<mj-style>` blocks inside `<mj-head>` alongside the built-in visibility
|
|
149
|
+
* media queries.
|
|
150
|
+
*
|
|
151
|
+
* Editor consumers: pass a function that reads
|
|
152
|
+
* `blockRegistry.getDefinition(customType)?.stylesheet`.
|
|
153
|
+
*
|
|
154
|
+
* Headless consumers: provide your own resolver, typically from the same
|
|
155
|
+
* definitions map used by `renderCustomBlock`. Return `undefined` or `null`
|
|
156
|
+
* for definitions without a stylesheet — those are skipped.
|
|
157
|
+
*/
|
|
158
|
+
getCustomBlockStylesheet?: (customType: string) => string | undefined | null;
|
|
159
|
+
/**
|
|
160
|
+
* Base URL (no trailing slash) for the social icon PNG assets. Resolved to
|
|
161
|
+
* `${baseUrl}/${style}/${platform}.png` per icon. Defaults to the
|
|
162
|
+
* version-pinned unpkg mirror of this package. Override to self-host
|
|
163
|
+
* (e.g., behind your own CDN or for air-gapped environments).
|
|
164
|
+
*
|
|
165
|
+
* Why PNGs: Outlook desktop (Word rendering engine) does not support SVG
|
|
166
|
+
* and rejects base64 data URIs in `<img src>`, so social icons must be
|
|
167
|
+
* served as raster images over HTTP for cross-client compatibility.
|
|
168
|
+
*/
|
|
169
|
+
socialIconsBaseUrl?: string;
|
|
161
170
|
}
|
|
162
171
|
/**
|
|
163
172
|
* Render template content to an MJML string.
|
|
@@ -169,5 +178,6 @@ interface RenderOptions {
|
|
|
169
178
|
* synchronously — i.e., it always returns a Promise.
|
|
170
179
|
*/
|
|
171
180
|
declare function renderToMjml(content: TemplateContent, options?: RenderOptions): Promise<string>;
|
|
172
|
-
|
|
173
|
-
export { type BlockRenderer, DEFAULT_SOCIAL_ICONS_BASE_URL, RenderContext,
|
|
181
|
+
//#endregion
|
|
182
|
+
export { type BlockRenderer, DEFAULT_SOCIAL_ICONS_BASE_URL, RenderContext, RenderOptions, convertMergeTagsToValues, escapeAttr, escapeHtml, getCssClassAttr, getCssClasses, getWidthPercentages, getWidthPixels, isHiddenOnAll, renderBlock, renderToMjml, toPaddingString };
|
|
183
|
+
//# sourceMappingURL=index.d.ts.map
|