@templatical/renderer 0.51.1 → 0.52.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/README.md CHANGED
@@ -56,18 +56,20 @@ const mjml = await renderToMjml(content, {
56
56
 
57
57
  ### With custom blocks
58
58
 
59
- The renderer doesn't know how to render custom blocks on its own — you supply a callback. Editor consumers wire this automatically through `editor.toMjml()`. Headless callers provide their own resolver:
59
+ Editor consumers use `editor.toMjml()`. Headless callers pass the registered definitions as `customBlocks`. Install the optional `liquidjs` peer (`^10.30.1`) in the server project:
60
60
 
61
61
  ```ts
62
- const mjml = await renderToMjml(content, {
63
- async renderCustomBlock(block) {
64
- // e.g. run the same liquid template the editor uses, against block.fieldValues
65
- return await myLiquidEngine.render(block.customType, block.fieldValues);
66
- },
67
- });
62
+ import { renderToMjml } from '@templatical/renderer';
63
+ import type { CustomBlockDefinition, TemplateContent } from '@templatical/types';
64
+
65
+ export async function renderTemplate(content: TemplateContent, definitions: CustomBlockDefinition[]) {
66
+ return renderToMjml(content, { customBlocks: definitions });
67
+ }
68
68
  ```
69
69
 
70
- If you don't pass `renderCustomBlock`, the renderer falls back to the block's `renderedHtml` field (if any) and otherwise omits the block from output.
70
+ The [Custom blocks guide](https://docs.templatical.com/guide/custom-blocks) covers the option's fallback, conflicts and missing-peer error. For a lower-level resolver, use `createCustomBlockLiquid(liquidjs)` from `@templatical/types`. Use `{{ body | raw }}` for a field intended to hold HTML. Always quote attribute values and validate URL schemes from untrusted sources. The editor canvas also sanitizes each rendered block; email output keeps the template's HTML.
71
+
72
+ Without a matching definition or callback, the renderer falls back to `renderedHtml` (if any) and otherwise omits the block.
71
73
 
72
74
  ## API
73
75
 
@@ -77,6 +79,7 @@ Options:
77
79
  - `customFonts` — `CustomFont[]` declarations rendered into `<mj-attributes>`
78
80
  - `defaultFallbackFont` — fallback when a block doesn't specify a font
79
81
  - `allowHtmlBlocks` — pass `false` to strip HTML blocks before render (e.g. for untrusted content)
82
+ - `customBlocks` — `CustomBlockDefinition[]` — render saved blocks from definitions
80
83
  - `renderCustomBlock` — `(block: CustomBlock) => Promise<string>` — resolves custom blocks to HTML
81
84
 
82
85
  ## Documentation
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Block, BlockType, ColumnLayout, ContentDirection, CustomBlock, CustomFont, ImageBlock, SpacingValue, TemplateContent } from "@templatical/types";
2
- //#region src/render-context.d.ts
1
+ import { Block, BlockType, ColumnLayout, ContentDirection, CustomBlock, CustomBlockDefinition, CustomFont, ImageBlock, SpacingValue, TemplateContent } from "@templatical/types";
3
2
  /**
4
3
  * A function type that renders a single block to MJML markup.
5
4
  */
@@ -117,8 +116,6 @@ export declare class RenderContext {
117
116
  */
118
117
  resolveFontFamily(fontFamily: string): string;
119
118
  }
120
- //#endregion
121
- //#region src/escape.d.ts
122
119
  /**
123
120
  * Escape HTML special characters (& < > " ').
124
121
  * Equivalent to PHP htmlspecialchars with ENT_QUOTES | ENT_HTML5.
@@ -141,8 +138,6 @@ export declare function escapeAttr(text: string): string;
141
138
  * quote-aware `findOpenTagEnd`, keeping the work strictly O(n).
142
139
  */
143
140
  export declare function convertMergeTagsToValues(html: string): string;
144
- //#endregion
145
- //#region src/visibility.d.ts
146
141
  /**
147
142
  * Check if a block is hidden on all viewports.
148
143
  */
@@ -160,8 +155,6 @@ export declare function getCssClassAttr(block: Block, extraClasses?: string[]):
160
155
  * Get the CSS classes for visibility hiding.
161
156
  */
162
157
  export declare function getCssClasses(block: Block): string;
163
- //#endregion
164
- //#region src/rich-text.d.ts
165
158
  /**
166
159
  * Marks the `mj-text` of a block whose content is editor-authored rich text
167
160
  * (paragraph and title). MJML puts a `css-class` on the wrapping `<td>`, which
@@ -196,8 +189,6 @@ export declare function richTextGapClass(gap: number): string;
196
189
  * `@templatical/editor`.
197
190
  */
198
191
  export declare function resolveParagraphGap(spacing: number | undefined): number;
199
- //#endregion
200
- //#region src/renderers/button.d.ts
201
192
  /**
202
193
  * Marks the `mj-button` of a full-width button. MJML gives the button's `<a>`
203
194
  * a width only for a px `width`; for `100%` it widens the `<table>` and leaves
@@ -206,8 +197,6 @@ export declare function resolveParagraphGap(spacing: number | undefined): number
206
197
  * this class.
207
198
  */
208
199
  export declare const BUTTON_FULL_WIDTH_CSS_CLASS = "tpl-button-full";
209
- //#endregion
210
- //#region src/utils.d.ts
211
200
  /**
212
201
  * `fluid-on-mobile` for an `mj-image`, set only on an image that fills its
213
202
  * column on desktop: `"full"`, or a pixel width MJML caps at the room it gives
@@ -222,8 +211,6 @@ export declare const BUTTON_FULL_WIDTH_CSS_CLASS = "tpl-button-full";
222
211
  * wrappers and sections around the column.
223
212
  */
224
213
  export declare function fluidOnMobileAttr(block: Pick<ImageBlock, "width" | "styles" | "border">, context: RenderContext): string;
225
- //#endregion
226
- //#region src/columns.d.ts
227
214
  /**
228
215
  * Get width percentages for each column in a layout.
229
216
  */
@@ -232,14 +219,10 @@ export declare function getWidthPercentages(layout: ColumnLayout): string[];
232
219
  * Get width in pixels for each column in a layout.
233
220
  */
234
221
  export declare function getWidthPixels(layout: ColumnLayout, containerWidth: number): number[];
235
- //#endregion
236
- //#region src/padding.d.ts
237
222
  /**
238
223
  * Convert a SpacingValue to a CSS padding string like "10px 10px 10px 10px".
239
224
  */
240
225
  export declare function toPaddingString(padding: SpacingValue): string;
241
- //#endregion
242
- //#region src/renderers/index.d.ts
243
226
  /**
244
227
  * Render a single block to MJML markup.
245
228
  * Dispatches to the appropriate block-type renderer.
@@ -249,8 +232,6 @@ export declare function toPaddingString(padding: SpacingValue): string;
249
232
  * placeholder marker plus a warning rather than disappearing.
250
233
  */
251
234
  export declare function renderBlock(block: Block, context: RenderContext): string;
252
- //#endregion
253
- //#region src/unrenderable.d.ts
254
235
  /**
255
236
  * Prefix every unrenderable-block marker carries. Stable and greppable on
256
237
  * purpose: it is what a consumer searches for after noticing a gap in a rendered
@@ -274,25 +255,22 @@ export declare const UNRENDERABLE_MARKER_PREFIX = "templatical:unrenderable-bloc
274
255
  * where every non-section block ends up.
275
256
  */
276
257
  export declare function renderUnrenderableBlock(block: Block): string;
277
- //#endregion
278
- //#region src/index.d.ts
279
258
  export interface RenderOptions {
280
259
  customFonts?: CustomFont[];
281
260
  defaultFallbackFont?: string;
282
261
  allowHtmlBlocks?: boolean;
262
+ /** Headless custom block definitions. The last definition per type wins. */
263
+ customBlocks?: CustomBlockDefinition[];
283
264
  /**
284
265
  * Resolves custom blocks to their HTML representation. Called once per
285
266
  * custom block in the content tree before MJML rendering. The renderer
286
- * has no built-in knowledge of how to render custom blocks; consumers
287
- * provide this function.
267
+ * accepts `customBlocks` for headless rendering; this callback is the
268
+ * editor's integration path.
288
269
  *
289
270
  * Editor consumers: pass `editor.renderCustomBlock`.
290
271
  *
291
- * Headless consumers (Node.js, server, CLI): provide your own resolver,
292
- * typically using the same liquid template + field values pipeline as
293
- * the editor uses. If omitted, custom blocks fall back to
294
- * `block.renderedHtml` (if present) and otherwise are omitted from the
295
- * output.
272
+ * With neither this callback nor `customBlocks`, each custom block uses
273
+ * `block.renderedHtml` (if present) and is otherwise omitted.
296
274
  */
297
275
  renderCustomBlock?: (block: CustomBlock) => Promise<string>;
298
276
  /**
@@ -330,14 +308,12 @@ export interface RenderOptions {
330
308
  * Editor consumers: pass a function that reads
331
309
  * `blockRegistry.getDefinition(customType)?.stylesheet`.
332
310
  *
333
- * Headless consumers: provide your own resolver, typically from the same
334
- * definitions map used by `renderCustomBlock`. Return `undefined` or `null`
335
- * for definitions without a stylesheet — those are skipped.
311
+ * Headless consumers can pass `customBlocks` instead. A listed definition
312
+ * decides its type's CSS; no stylesheet means none is emitted.
336
313
  *
337
- * Without a resolver, each type's `block.renderedStylesheet` is emitted
338
- * instead: the copy the editor writes before a render provider or Cloud
339
- * storage sees the content. A resolver, when passed, decides every type and
340
- * the copies are ignored, so a stale one never overrides a live definition.
314
+ * Without a resolver or matching definition, each type's saved
315
+ * `block.renderedStylesheet` is emitted. A resolver decides every type and
316
+ * ignores saved copies, so a stale one never overrides a live definition.
341
317
  */
342
318
  getCustomBlockStylesheet?: (customType: string) => string | undefined | null;
343
319
  /**
@@ -361,13 +337,11 @@ export interface RenderOptions {
361
337
  /**
362
338
  * Render template content to an MJML string.
363
339
  *
364
- * The function is async because resolving custom blocks may require
365
- * asynchronous work (e.g., the editor's liquid renderer dynamically imports
366
- * `liquidjs`). When the content has no custom blocks or `renderCustomBlock`
367
- * is omitted, no async work is performed but the function still resolves
368
- * synchronously — i.e., it always returns a Promise.
340
+ * With `customBlocks`, this imports the optional `liquidjs` peer only when
341
+ * the content holds a custom block. The editor uses `renderCustomBlock` via
342
+ * `toMjml()`; headless callers can pass definitions directly. The function
343
+ * always returns a Promise.
369
344
  */
370
345
  export declare function renderToMjml(content: TemplateContent, options?: RenderOptions): Promise<string>;
371
- //#endregion
372
346
  export type { BlockRenderer, BlockRendererMap };
373
347
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import { HEADING_LEVEL_FONT_SIZE, RICH_TEXT_SPACING, TITLE_FONT_WEIGHT, TITLE_LINE_HEIGHT, applyLayout, assertNoSlotInContent, assertNoWrapperInContent, fillEmptyParagraphs, findOpenTagEnd, getTagAttrValue, isBlankRichText, isButton, isCustomBlock, isDivider, isHtml, isImage, isMenu, isParagraph, isSection, isSocialIcons, isSpacer, isTable, isTitle, isVideo, isWrapper, resolveBackgroundImage, resolveContentDirection, resolveFontStack, resolveHero, socialIconAssetDir, toBorderCss, toBorderDeclarations, toBorderRadiusCss } from "@templatical/types";
2
- //#endregion
3
- //#region src/render-context.ts
4
- const DEFAULT_SOCIAL_ICONS_BASE_URL = `https://cdn.jsdelivr.net/npm/@templatical/renderer@0.51.1/assets/social`;
1
+ import { HEADING_LEVEL_FONT_SIZE, RICH_TEXT_SPACING, TITLE_FONT_WEIGHT, TITLE_LINE_HEIGHT, applyLayout, assertNoSlotInContent, assertNoWrapperInContent, createCustomBlockLiquid, fillEmptyParagraphs, findOpenTagEnd, getTagAttrValue, isBlankRichText, isButton, isCustomBlock, isDivider, isHtml, isImage, isMenu, isParagraph, isSection, isSocialIcons, isSpacer, isTable, isTitle, isVideo, isWrapper, resolveBackgroundImage, resolveContentDirection, resolveFontStack, resolveHero, socialIconAssetDir, toBorderCss, toBorderDeclarations, toBorderRadiusCss } from "@templatical/types";
2
+ // src/render-context.ts
3
+ const DEFAULT_SOCIAL_ICONS_BASE_URL = `https://cdn.jsdelivr.net/npm/@templatical/renderer@0.52.1/assets/social`;
5
4
  /**
6
5
  * Immutable context passed through the block rendering chain.
7
6
  */
@@ -60,8 +59,7 @@ var RenderContext = class RenderContext {
60
59
  });
61
60
  }
62
61
  };
63
- //#endregion
64
- //#region src/visibility.ts
62
+ // src/visibility.ts
65
63
  /**
66
64
  * Check if a block is hidden on all viewports.
67
65
  */
@@ -94,8 +92,7 @@ function getCssClasses(block) {
94
92
  if (!visibility.mobile) classes.push("tpl-hide-mobile");
95
93
  return classes.join(" ");
96
94
  }
97
- //#endregion
98
- //#region src/unrenderable.ts
95
+ // src/unrenderable.ts
99
96
  /**
100
97
  * Prefix every unrenderable-block marker carries. Stable and greppable on
101
98
  * purpose: it is what a consumer searches for after noticing a gap in a rendered
@@ -137,8 +134,7 @@ function renderUnrenderableBlock(block) {
137
134
  const id = commentSafe(block.id);
138
135
  return `<mj-raw><!-- ${UNRENDERABLE_MARKER_PREFIX} type="${type}" id="${id}" --></mj-raw>`;
139
136
  }
140
- //#endregion
141
- //#region src/escape.ts
137
+ // src/escape.ts
142
138
  const HTML_ENTITIES = {
143
139
  "&": "&amp;",
144
140
  "<": "&lt;",
@@ -265,16 +261,14 @@ function rewriteMergeTagSpans(html, extract) {
265
261
  function findAttr(attrs, name) {
266
262
  return getTagAttrValue(attrs, name);
267
263
  }
268
- //#endregion
269
- //#region src/padding.ts
264
+ // src/padding.ts
270
265
  /**
271
266
  * Convert a SpacingValue to a CSS padding string like "10px 10px 10px 10px".
272
267
  */
273
268
  function toPaddingString(padding) {
274
269
  return `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`;
275
270
  }
276
- //#endregion
277
- //#region src/utils.ts
271
+ // src/utils.ts
278
272
  /**
279
273
  * Render the appropriate background-color attribute for an MJML element.
280
274
  * Returns an empty string when no color is set, or a leading-space attribute
@@ -366,8 +360,7 @@ function backgroundImageAttrs(bg) {
366
360
  if (resolved === null) return "";
367
361
  return ` background-url="${escapeAttr(resolved.url)}" background-size="${resolved.size}" background-position="${resolved.position}" background-repeat="${resolved.repeat}"`;
368
362
  }
369
- //#endregion
370
- //#region src/rich-text.ts
363
+ // src/rich-text.ts
371
364
  /**
372
365
  * Marks the `mj-text` of a block whose content is editor-authored rich text
373
366
  * (paragraph and title). MJML puts a `css-class` on the wrapping `<td>`, which
@@ -465,8 +458,7 @@ function collectParagraphGaps(blocks) {
465
458
  for (const block of blocks) visit(block);
466
459
  return gaps;
467
460
  }
468
- //#endregion
469
- //#region src/renderers/title.ts
461
+ // src/renderers/title.ts
470
462
  /**
471
463
  * Render a title block to MJML markup.
472
464
  */
@@ -503,8 +495,7 @@ function renderFontFamilyAttr$3(fontFamily, context) {
503
495
  if (!fontFamily) return "";
504
496
  return ` font-family="${escapeFontFamily(context.resolveFontFamily(fontFamily))}"`;
505
497
  }
506
- //#endregion
507
- //#region src/renderers/paragraph.ts
498
+ // src/renderers/paragraph.ts
508
499
  /**
509
500
  * Render a paragraph block to MJML markup.
510
501
  * All text formatting is inline in the HTML content (managed by TipTap).
@@ -521,8 +512,7 @@ function renderParagraph(block, context) {
521
512
  padding="${padding}"${bgColor}${cssClassAttr}
522
513
  >${content}</mj-text>`;
523
514
  }
524
- //#endregion
525
- //#region src/renderers/image.ts
515
+ // src/renderers/image.ts
526
516
  /**
527
517
  * Render an image block to MJML markup.
528
518
  */
@@ -552,8 +542,7 @@ function renderImage(block, context) {
552
542
  padding="${padding}"${bgColor}${borderAttrStr}${borderRadiusAttrStr}${linkAttr}${visibilityAttr}${decorative ? " role=\"presentation\"" : ""}
553
543
  />`;
554
544
  }
555
- //#endregion
556
- //#region src/renderers/button.ts
545
+ // src/renderers/button.ts
557
546
  /**
558
547
  * Marks the `mj-button` of a full-width button. MJML gives the button's `<a>`
559
548
  * a width only for a px `width`; for `100%` it widens the `<table>` and leaves
@@ -617,8 +606,7 @@ function renderWidthAttr(width) {
617
606
  if (width === void 0) return "";
618
607
  return ` width="${width === "full" ? "100%" : `${width}px`}"`;
619
608
  }
620
- //#endregion
621
- //#region src/renderers/divider.ts
609
+ // src/renderers/divider.ts
622
610
  /**
623
611
  * Render a divider block to MJML markup.
624
612
  */
@@ -635,8 +623,7 @@ function renderDivider(block, _context) {
635
623
  padding="${padding}"${bgColor}${getCssClassAttr(block)}
636
624
  />`;
637
625
  }
638
- //#endregion
639
- //#region src/renderers/spacer.ts
626
+ // src/renderers/spacer.ts
640
627
  /**
641
628
  * Render a spacer block to MJML markup.
642
629
  *
@@ -650,8 +637,7 @@ function renderSpacer(block, _context) {
650
637
  if (isHiddenOnAll(block)) return "";
651
638
  return `<mj-spacer height="${block.height}px" padding="0"${block.styles.backgroundColor ? ` container-background-color="${escapeAttr(block.styles.backgroundColor)}"` : ""}${getCssClassAttr(block)} />`;
652
639
  }
653
- //#endregion
654
- //#region src/renderers/html.ts
640
+ // src/renderers/html.ts
655
641
  /**
656
642
  * Render an HTML block to MJML markup.
657
643
  * No sanitization in the OSS version -- consumers are responsible for content safety.
@@ -666,8 +652,7 @@ function renderHtml(block, context) {
666
652
  ${content}
667
653
  </mj-text>`;
668
654
  }
669
- //#endregion
670
- //#region src/renderers/social.ts
655
+ // src/renderers/social.ts
671
656
  /**
672
657
  * Render a social icons block to MJML markup.
673
658
  *
@@ -731,8 +716,7 @@ ${icons.map((icon, index) => {
731
716
  }).join("\n")}
732
717
  </mj-social>`;
733
718
  }
734
- //#endregion
735
- //#region src/renderers/menu.ts
719
+ // src/renderers/menu.ts
736
720
  /**
737
721
  * Render a menu block to MJML markup.
738
722
  * Uses mj-text with inline <a> tags separated by styled <span> separators.
@@ -781,8 +765,7 @@ function renderFontFamilyAttr$1(fontFamily, context) {
781
765
  if (!fontFamily) return "";
782
766
  return ` font-family="${escapeFontFamily(context.resolveFontFamily(fontFamily))}"`;
783
767
  }
784
- //#endregion
785
- //#region src/renderers/table.ts
768
+ // src/renderers/table.ts
786
769
  /**
787
770
  * Render a table block to MJML markup.
788
771
  * Uses mj-text wrapping an HTML <table> with styled <tr>/<td> elements.
@@ -834,15 +817,14 @@ function renderFontFamilyAttr(fontFamily, context) {
834
817
  if (!fontFamily) return "";
835
818
  return ` font-family="${escapeFontFamily(context.resolveFontFamily(fontFamily))}"`;
836
819
  }
837
- //#endregion
838
- //#region src/renderers/custom.ts
820
+ // src/renderers/custom.ts
839
821
  /**
840
822
  * Render a custom block to MJML markup.
841
823
  *
842
824
  * Custom block HTML resolution order:
843
825
  * 1. `context.customBlockHtml` map — populated by `renderToMjml` when the
844
- * caller passes a `renderCustomBlock` option (typical for editor
845
- * consumers and headless callers wiring their own resolver).
826
+ * caller passes `customBlocks` definitions or a `renderCustomBlock`
827
+ * callback (the editor's path).
846
828
  * 2. `block.renderedHtml` — populated by an external pre-render step
847
829
  * (e.g., a previous render pass that mutated the block).
848
830
  * 3. Empty — block omitted from output.
@@ -856,8 +838,7 @@ function renderCustom(block, context) {
856
838
  ${content}
857
839
  </mj-text>`;
858
840
  }
859
- //#endregion
860
- //#region src/columns.ts
841
+ // src/columns.ts
861
842
  /**
862
843
  * Get width percentages for each column in a layout.
863
844
  */
@@ -890,8 +871,7 @@ function getWidthPixels(layout, containerWidth) {
890
871
  default: return [containerWidth];
891
872
  }
892
873
  }
893
- //#endregion
894
- //#region src/hero-geometry.ts
874
+ // src/hero-geometry.ts
895
875
  /**
896
876
  * The `mj-hero` sizing for a hero in a box `boxWidth` px wide. Every hero's
897
877
  * mode, height and image size come from here, so an Outlook rendering
@@ -928,8 +908,7 @@ function heroGeometry(hero, boxWidth, padding) {
928
908
  backgroundHeight: imageHeight ?? height
929
909
  };
930
910
  }
931
- //#endregion
932
- //#region src/display-condition.ts
911
+ // src/display-condition.ts
933
912
  /**
934
913
  * Wrap rendered block markup in the block's liquid display-condition guards
935
914
  * (`<mj-raw>{% if %}</mj-raw>` … `<mj-raw>{% endif %}</mj-raw>`), if present.
@@ -951,8 +930,7 @@ function wrapWithDisplayCondition(block, rendered) {
951
930
  ` + rendered + `
952
931
  <mj-raw>${displayCondition.after}</mj-raw>`;
953
932
  }
954
- //#endregion
955
- //#region src/renderers/section.ts
933
+ // src/renderers/section.ts
956
934
  /**
957
935
  * Render a section block with columns to MJML markup.
958
936
  */
@@ -1029,8 +1007,7 @@ function filterHtmlBlocks$1(blocks, allowHtmlBlocks) {
1029
1007
  if (allowHtmlBlocks) return blocks;
1030
1008
  return blocks.filter((block) => block.type !== "html");
1031
1009
  }
1032
- //#endregion
1033
- //#region src/renderers/video.ts
1010
+ // src/renderers/video.ts
1034
1011
  /**
1035
1012
  * Extract video thumbnail URL from common platforms.
1036
1013
  * Works without server-side processing — YouTube and Vimeo thumbnails are publicly accessible.
@@ -1071,8 +1048,7 @@ function renderVideo(block, context) {
1071
1048
  rel="noopener"${bgColor}${visibilityAttr}
1072
1049
  />`;
1073
1050
  }
1074
- //#endregion
1075
- //#region src/renderers/index.ts
1051
+ // src/renderers/index.ts
1076
1052
  /**
1077
1053
  * Render a single block to MJML markup.
1078
1054
  * Dispatches to the appropriate block-type renderer.
@@ -1100,8 +1076,7 @@ function renderBlock(block, context) {
1100
1076
  if (isHiddenOnAll(block)) return "";
1101
1077
  return renderUnrenderableBlock(block);
1102
1078
  }
1103
- //#endregion
1104
- //#region src/index.ts
1079
+ // src/index.ts
1105
1080
  /**
1106
1081
  * Makes a full-width button's whole fill clickable. MJML sizes a button's `<a>`
1107
1082
  * only for a px width, so without this rule the link of a `100%` button stays
@@ -1118,20 +1093,21 @@ const BUTTON_FULL_WIDTH_RULE = `.${BUTTON_FULL_WIDTH_CSS_CLASS} a { display: blo
1118
1093
  /**
1119
1094
  * Render template content to an MJML string.
1120
1095
  *
1121
- * The function is async because resolving custom blocks may require
1122
- * asynchronous work (e.g., the editor's liquid renderer dynamically imports
1123
- * `liquidjs`). When the content has no custom blocks or `renderCustomBlock`
1124
- * is omitted, no async work is performed but the function still resolves
1125
- * synchronously — i.e., it always returns a Promise.
1096
+ * With `customBlocks`, this imports the optional `liquidjs` peer only when
1097
+ * the content holds a custom block. The editor uses `renderCustomBlock` via
1098
+ * `toMjml()`; headless callers can pass definitions directly. The function
1099
+ * always returns a Promise.
1126
1100
  */
1127
1101
  async function renderToMjml(content, options) {
1102
+ if (options?.customBlocks !== void 0 && options.renderCustomBlock !== void 0) throw new TypeError("[Templatical] customBlocks cannot be combined with renderCustomBlock");
1103
+ if (options?.customBlocks !== void 0 && options.getCustomBlockStylesheet !== void 0) throw new TypeError("[Templatical] customBlocks cannot be combined with getCustomBlockStylesheet");
1128
1104
  const toRender = options?.layout ? applyLayout(options.layout, content) : (assertNoSlotInContent(content), assertNoWrapperInContent(content), content);
1129
1105
  const customFonts = options?.customFonts ?? [];
1130
1106
  const defaultFallbackFont = options?.defaultFallbackFont ?? "Arial, sans-serif";
1131
1107
  const allowHtmlBlocks = options?.allowHtmlBlocks ?? true;
1132
1108
  const socialIconsBaseUrl = stripTrailingSlash(options?.socialIconsBaseUrl ?? DEFAULT_SOCIAL_ICONS_BASE_URL);
1133
- const customBlockHtml = await resolveCustomBlocks(toRender, options?.renderCustomBlock);
1134
- const customBlockStylesheets = collectCustomBlockStylesheets(toRender, options?.getCustomBlockStylesheet);
1109
+ const customBlockHtml = options?.customBlocks !== void 0 ? await resolveCustomBlockDefinitions(toRender, options.customBlocks) : await resolveCustomBlocks(toRender, options?.renderCustomBlock);
1110
+ const customBlockStylesheets = collectCustomBlockStylesheets(toRender, options?.getCustomBlockStylesheet, options?.customBlocks === void 0 ? void 0 : new Map(options.customBlocks.map((definition) => [definition.type, definition])));
1135
1111
  const contentDirection = resolveContentDirection(toRender.settings);
1136
1112
  const renderContext = new RenderContext(toRender.settings.width, customFonts, defaultFallbackFont, allowHtmlBlocks, customBlockHtml, socialIconsBaseUrl, options?.blockRenderers ?? {}, contentDirection);
1137
1113
  const blocks = filterHtmlBlocks(toRender.blocks, allowHtmlBlocks);
@@ -1261,6 +1237,31 @@ async function resolveCustomBlocks(content, renderCustomBlock) {
1261
1237
  for (let index = 0; index < customBlocks.length; index++) result.set(customBlocks[index].id, rendered[index]);
1262
1238
  return result;
1263
1239
  }
1240
+ /** One Liquid engine serves every definition in this render call. Template
1241
+ * errors propagate as callback rejections do. */
1242
+ async function resolveCustomBlockDefinitions(content, definitions) {
1243
+ const result = /* @__PURE__ */ new Map();
1244
+ const blocks = [];
1245
+ collectCustomBlocks(content.blocks, blocks);
1246
+ if (blocks.length === 0) return result;
1247
+ let liquidjs;
1248
+ try {
1249
+ liquidjs = await import("liquidjs");
1250
+ } catch {
1251
+ throw new Error("[Templatical] customBlocks requires the optional liquidjs package.");
1252
+ }
1253
+ const liquid = createCustomBlockLiquid(liquidjs);
1254
+ const byType = new Map(definitions.map((definition) => [definition.type, definition]));
1255
+ const rendered = await Promise.all(blocks.map(async (block) => {
1256
+ const definition = byType.get(block.customType);
1257
+ return definition ? String(await liquid.parseAndRender(definition.template, block.fieldValues)) : void 0;
1258
+ }));
1259
+ for (let index = 0; index < blocks.length; index++) {
1260
+ const html = rendered[index];
1261
+ if (html !== void 0) result.set(blocks[index].id, html);
1262
+ }
1263
+ return result;
1264
+ }
1264
1265
  function collectCustomBlocks(blocks, out) {
1265
1266
  for (const block of blocks) {
1266
1267
  if (isCustomBlock(block)) {
@@ -1282,7 +1283,7 @@ function collectCustomBlocks(blocks, out) {
1282
1283
  * matches the "one rule, emitted once" mental model. Whitespace-only and
1283
1284
  * empty stylesheets are skipped.
1284
1285
  */
1285
- function collectCustomBlockStylesheets(content, resolver) {
1286
+ function collectCustomBlockStylesheets(content, resolver, definitions) {
1286
1287
  const customBlocks = [];
1287
1288
  collectCustomBlocks(content.blocks, customBlocks);
1288
1289
  if (customBlocks.length === 0) return [];
@@ -1296,7 +1297,8 @@ function collectCustomBlockStylesheets(content, resolver) {
1296
1297
  for (const block of customBlocks) {
1297
1298
  if (seenTypes.has(block.customType)) continue;
1298
1299
  seenTypes.add(block.customType);
1299
- const css = resolver ? resolver(block.customType) : copies.get(block.customType);
1300
+ const definition = definitions?.get(block.customType);
1301
+ const css = resolver ? resolver(block.customType) : definition ? definition.stylesheet : copies.get(block.customType);
1300
1302
  if (!css) continue;
1301
1303
  const trimmed = css.trim();
1302
1304
  if (trimmed === "" || seenContent.has(trimmed)) continue;
@@ -1309,7 +1311,6 @@ function renderCustomBlockStylesheets(stylesheets) {
1309
1311
  if (stylesheets.length === 0) return "";
1310
1312
  return stylesheets.map((css) => `\n <mj-style>\n${css}\n </mj-style>`).join("");
1311
1313
  }
1312
- //#endregion
1313
1314
  export { BUTTON_FULL_WIDTH_CSS_CLASS, DEFAULT_SOCIAL_ICONS_BASE_URL, RICH_TEXT_CSS_CLASS, RenderContext, UNRENDERABLE_MARKER_PREFIX, convertMergeTagsToValues, escapeAttr, escapeHtml, fluidOnMobileAttr, getCssClassAttr, getCssClasses, getWidthPercentages, getWidthPixels, isHiddenOnAll, renderBlock, renderToMjml, renderUnrenderableBlock, resolveParagraphGap, richTextGapClass, toPaddingString };
1314
1315
 
1315
1316
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["pkg.version","renderFontFamilyAttr","renderFontFamilyAttr","renderFontFamilyAttr","filterHtmlBlocks"],"sources":["../package.json","../src/render-context.ts","../src/visibility.ts","../src/unrenderable.ts","../src/escape.ts","../src/padding.ts","../src/utils.ts","../src/rich-text.ts","../src/renderers/title.ts","../src/renderers/paragraph.ts","../src/renderers/image.ts","../src/renderers/button.ts","../src/renderers/divider.ts","../src/renderers/spacer.ts","../src/renderers/html.ts","../src/renderers/social.ts","../src/renderers/menu.ts","../src/renderers/table.ts","../src/renderers/custom.ts","../src/columns.ts","../src/hero-geometry.ts","../src/display-condition.ts","../src/renderers/section.ts","../src/renderers/video.ts","../src/renderers/index.ts","../src/index.ts"],"sourcesContent":["","import type {\n Block,\n BlockType,\n ContentDirection,\n CustomFont,\n} from \"@templatical/types\";\nimport { resolveFontStack } from \"@templatical/types\";\nimport pkg from \"../package.json\" with { type: \"json\" };\n\n/**\n * A function type that renders a single block to MJML markup.\n */\nexport type BlockRenderer = (block: Block, context: RenderContext) => string;\n\n/**\n * Per-block-type renderer overrides, keyed by `block.type`. An entry replaces the\n * built-in renderer for that type wholesale — including its hidden-on-all-\n * viewports check, which becomes the override's responsibility.\n *\n * Generalises `renderCustomBlock`, which is the same idea for one block type. Its\n * reason to exist is that Templatical Cloud's render output is a deliberate\n * *superset*: countdown blocks resolve to a server-generated animated GIF and\n * video thumbnails get a composited play button, neither of which a browser can\n * do at render time. With this hook Cloud's renderer is the published one plus\n * two injected functions, so parity for every other block type holds by\n * construction instead of by review.\n */\nexport type BlockRendererMap = Partial<Record<BlockType, BlockRenderer>>;\n\nexport const DEFAULT_SOCIAL_ICONS_BASE_URL = `https://cdn.jsdelivr.net/npm/@templatical/renderer@${pkg.version}/assets/social`;\n\n/**\n * Immutable context passed through the block rendering chain.\n */\nexport class RenderContext {\n /**\n * The whole pixels MJML gives this container's content: the body width less\n * the side padding and border of every wrapper and section around it, then\n * the column's own percentage of what is left, floored as MJML floors it.\n * Width-aware decisions read this one, since it is the box MJML caps a block\n * at. Defaults to `containerWidth`.\n */\n public readonly contentWidth: number;\n\n constructor(\n /**\n * The column's share of the body width, ignoring any padding or border\n * around it. Emitted as the pixel width of a `\"full\"` image or video, which\n * MJML then caps at the real box ({@link contentWidth}).\n */\n public readonly containerWidth: number,\n public readonly customFonts: CustomFont[],\n public readonly defaultFallbackFont: string,\n public readonly allowHtmlBlocks: boolean,\n /**\n * Map of custom block id → pre-rendered HTML, populated by `renderToMjml`\n * before the synchronous render pass. Set when the consumer provides a\n * `renderCustomBlock` option. Empty by default.\n */\n public readonly customBlockHtml: ReadonlyMap<string, string> = new Map(),\n /**\n * Base URL (no trailing slash) for the social icon PNG assets. Resolved to\n * `${baseUrl}/${style}/${platform}.png`. Outlook desktop has no SVG support\n * and rejects base64 data URIs in `<img src>`, so PNGs must be served over\n * HTTP. Default points at the version-pinned jsDelivr mirror of this\n * package; consumers can override to self-host.\n */\n public readonly socialIconsBaseUrl: string = DEFAULT_SOCIAL_ICONS_BASE_URL,\n /**\n * Per-block-type renderer overrides from `RenderOptions.blockRenderers`.\n * Consulted before every built-in renderer — see {@link BlockRendererMap}.\n */\n public readonly blockRenderers: BlockRendererMap = {},\n /**\n * Writing direction of the email, resolved once in `renderToMjml`.\n * Nested columns copy it via `withContainerWidth` — dropping it there\n * would leave a two-column RTL section rendering LTR inside the columns.\n */\n public readonly contentDirection: ContentDirection = \"ltr\",\n contentWidth?: number,\n ) {\n this.contentWidth = contentWidth ?? containerWidth;\n }\n\n /**\n * Create a new context with a different container width. Used when rendering\n * columns, and wrappers, whose content is narrower. `contentWidth` defaults\n * to `width`, a container with nothing around it.\n */\n withContainerWidth(\n width: number,\n contentWidth: number = width,\n ): RenderContext {\n return new RenderContext(\n width,\n this.customFonts,\n this.defaultFallbackFont,\n this.allowHtmlBlocks,\n this.customBlockHtml,\n this.socialIconsBaseUrl,\n this.blockRenderers,\n this.contentDirection,\n contentWidth,\n );\n }\n\n /**\n * The stack to emit for a block's or the template's `fontFamily`. A stack is\n * the author's own fallback chain and is emitted as written, as is anything\n * that doesn't parse as a font. A lone family gets a fallback: a custom\n * font's own `fallback` (or `defaultFallbackFont`), a built-in's fixed stack,\n * or, for any other family, `defaultFallbackFont`, so a client without the\n * face falls back to it rather than to its own default (Times New Roman in\n * Outlook on Windows). A generic family needs nothing appended.\n *\n * The rule is {@link resolveFontStack}, shared with the editor canvas so a\n * font previews with the fallbacks the recipient gets.\n */\n resolveFontFamily(fontFamily: string): string {\n return resolveFontStack(fontFamily, {\n customFonts: this.customFonts,\n defaultFallback: this.defaultFallbackFont,\n });\n }\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Check if a block is hidden on all viewports.\n */\nexport function isHiddenOnAll(block: Block): boolean {\n const visibility = block.visibility;\n\n if (!visibility) {\n return false;\n }\n\n return !visibility.desktop && !visibility.mobile;\n}\n\n/**\n * Get the MJML css-class attribute string for a block.\n * Returns a string like ` css-class=\"tpl-hide-desktop\"` or empty string.\n *\n * `extraClasses` are appended to the visibility classes on the *same*\n * attribute. MJML keeps only one `css-class` per element, so a caller needing\n * both must merge here rather than emitting a second attribute.\n */\nexport function getCssClassAttr(\n block: Block,\n extraClasses: string[] = [],\n): string {\n const classes = [getCssClasses(block), ...extraClasses]\n .filter((entry) => entry !== \"\")\n .join(\" \");\n\n if (classes === \"\") {\n return \"\";\n }\n\n return ` css-class=\"${classes}\"`;\n}\n\n/**\n * Get the CSS classes for visibility hiding.\n */\nexport function getCssClasses(block: Block): string {\n const visibility = block.visibility;\n\n if (!visibility) {\n return \"\";\n }\n\n const classes: string[] = [];\n\n if (!visibility.desktop) {\n classes.push(\"tpl-hide-desktop\");\n }\n\n if (!visibility.mobile) {\n classes.push(\"tpl-hide-mobile\");\n }\n\n return classes.join(\" \");\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Prefix every unrenderable-block marker carries. Stable and greppable on\n * purpose: it is what a consumer searches for after noticing a gap in a rendered\n * email, and what a send pipeline can scan for before shipping.\n */\nexport const UNRENDERABLE_MARKER_PREFIX = \"templatical:unrenderable-block\";\n\n/**\n * Strip anything that would terminate or nest an HTML comment. `-->` and `--!>`\n * inside the marker would close it early and leak the rest as body text; a lone\n * `--` is enough to make the comment non-conforming, so both collapse.\n *\n * Brackets go **before** hyphens collapse, and the order is load-bearing.\n * Removing `<` from `-<-` brings two hyphens together that a collapse pass has\n * already walked past, so collapsing first leaves a `--` behind — the sanitizer\n * reintroducing the sequence it exists to remove.\n */\nfunction commentSafe(value: string): string {\n return value.replace(/[<>]/g, \"\").replace(/-{2,}/g, \"-\");\n}\n\n/**\n * Emit the placeholder for a block no renderer can handle — no built-in renderer\n * and no `blockRenderers` override for its type.\n *\n * **A marker, not a throw and not silence.** The renderer runs inside send\n * pipelines, so killing an entire render over one block is worse than shipping a\n * marked gap. Silence is worse still: a block that simply vanishes reaches\n * recipients as a missing section with nothing anywhere explaining why. The rule\n * is general rather than countdown-specific, so\n * a block type added to `@templatical/types` before its renderer lands degrades\n * the same way.\n *\n * `mj-raw` is used because it is the one element that passes its content through\n * verbatim and is valid everywhere a block renders — inside `mj-column`, which is\n * where every non-section block ends up.\n */\nexport function renderUnrenderableBlock(block: Block): string {\n console.warn(\n `[Templatical] No renderer for block type \"${block.type}\" (id: ${block.id}). ` +\n \"A placeholder comment was emitted in its place. Pass a `blockRenderers` \" +\n \"entry for this type to render it.\",\n );\n\n const type = commentSafe(block.type);\n const id = commentSafe(block.id);\n\n return `<mj-raw><!-- ${UNRENDERABLE_MARKER_PREFIX} type=\"${type}\" id=\"${id}\" --></mj-raw>`;\n}\n","import { findOpenTagEnd, getTagAttrValue } from \"@templatical/types\";\n\nconst HTML_ENTITIES: Record<string, string> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"'\": \"&#039;\",\n};\n\nconst HTML_ENTITY_REGEX = /[&<>\"']/g;\n\n/**\n * Escape HTML special characters (& < > \" ').\n * Equivalent to PHP htmlspecialchars with ENT_QUOTES | ENT_HTML5.\n */\nexport function escapeHtml(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n\n return text.replace(HTML_ENTITY_REGEX, (char) => HTML_ENTITIES[char] ?? char);\n}\n\n/**\n * Escape a string for use in an HTML attribute value.\n * Same implementation as escapeHtml for consistency with PHP.\n */\nexport function escapeAttr(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n\n return text.replace(HTML_ENTITY_REGEX, (char) => HTML_ENTITIES[char] ?? char);\n}\n\n/**\n * Escape a string for use as a CSS property value inside an inline\n * `style=\"prop: ${value}\"` attribute. Beyond HTML entity escaping (so the\n * value survives the attribute boundary), this strips characters that\n * could break out of the property value into a sibling property:\n *\n * `;` — separates CSS declarations\n * `{`/`}` — opens/closes a CSS rule (rejected by attribute parsers but\n * still safer to remove)\n * `\\n`/`\\r` — would smuggle past line-based CSS sanitizers\n *\n * Without this, an attacker-controlled color like\n * `\"red; background: url('//attacker/log')\"` lands as a real CSS rule.\n */\nexport function escapeCssValue(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n return escapeAttr(text).replace(/[;{}\\r\\n]/g, \"\");\n}\n\nconst FONT_FAMILY_ENTITY_REGEX = /[&<>\"]/g;\n\n/**\n * Escape a font stack for a double-quoted `font-family=\"…\"` MJML attribute.\n * A `\"`-quoted family (`\"Helvetica Neue\", Arial`) must not end the attribute,\n * or the compiler reads it as empty. Unlike `escapeAttr`, single quotes are\n * left alone: they can't end a double-quoted attribute, and they're how the\n * renderer quotes families itself (`'Times New Roman', serif`), so every\n * stack without `&<>\"` is emitted byte-for-byte.\n */\nexport function escapeFontFamily(text: string): string {\n return text.replace(\n FONT_FAMILY_ENTITY_REGEX,\n (char) => HTML_ENTITIES[char] ?? char,\n );\n}\n\n/**\n * Replace merge tag span elements with their data attribute values.\n * Converts `<span data-merge-tag=\"{{name}}\">Label</span>` to `{{name}}`.\n * Also handles `data-logic-merge-tag` attributes.\n *\n * Uses a single-pass linear scan instead of an `[^>]*…[^>]*` regex because\n * the latter is polynomial-ReDoS over inputs that contain many `<span`\n * starts but no closing `>` — the engine retries `[^>]*` at every span\n * position. The scan below resolves each `<span>` open tag with a bounded,\n * quote-aware `findOpenTagEnd`, keeping the work strictly O(n).\n */\nexport function convertMergeTagsToValues(html: string): string {\n if (html === \"\") {\n return \"\";\n }\n\n return rewriteMergeTagSpans(\n html,\n (attrs) =>\n findAttr(attrs, \"data-merge-tag\") ??\n findAttr(attrs, \"data-logic-merge-tag\"),\n );\n}\n\n/**\n * Walk `html`, find every `<span …>…</span>`, and replace the entire span\n * with whatever `extract` returns for its attribute string (or leave it\n * alone if `extract` returns `null`). Linear in the length of `html`:\n * every `indexOf` advances the cursor monotonically.\n */\nfunction rewriteMergeTagSpans(\n html: string,\n extract: (attrs: string) => string | null,\n): string {\n let out = \"\";\n let i = 0;\n while (i < html.length) {\n const open = html.indexOf(\"<span\", i);\n if (open === -1) {\n out += html.substring(i);\n break;\n }\n // `<span` must be followed by `>` or whitespace to be a real opening tag.\n const afterTagName = html[open + 5];\n if (\n afterTagName !== \">\" &&\n afterTagName !== \" \" &&\n afterTagName !== \"\\t\" &&\n afterTagName !== \"\\n\" &&\n afterTagName !== \"\\r\" &&\n afterTagName !== \"/\"\n ) {\n out += html.substring(i, open + 5);\n i = open + 5;\n continue;\n }\n const openEnd = findOpenTagEnd(html, open + 5);\n if (openEnd === -1) {\n out += html.substring(i);\n break;\n }\n const closeStart = html.indexOf(\"</span>\", openEnd + 1);\n if (closeStart === -1) {\n out += html.substring(i);\n break;\n }\n const attrs = html.substring(open + 5, openEnd);\n const replacement = extract(attrs);\n if (replacement === null) {\n // This `<span>` isn't a merge-tag — emit up to and including the\n // `<span` literal and let the next iteration scan inward, so any\n // nested merge-tag span still gets a chance to match.\n out += html.substring(i, open + 5);\n i = open + 5;\n continue;\n }\n out += html.substring(i, open);\n out += replacement;\n i = closeStart + 7;\n }\n return out;\n}\n\n/**\n * Extract the value of `name=\"…\"` from an HTML attribute string, or `null`\n * if absent.\n *\n * Delegates to `@templatical/types` so the editor's preview rewriter and this\n * export rewriter read markup identically. They were separate regexes once, and\n * both excluded `<` / `>` from the value — which silently left the whole span\n * in the rendered MJML whenever a consumer configured a merge-tag syntax whose\n * values contain those characters (`<% $email %>`), so the ESP never received\n * the token.\n */\nfunction findAttr(attrs: string, name: string): string | null {\n return getTagAttrValue(attrs, name);\n}\n","import type { SpacingValue } from \"@templatical/types\";\n\n/**\n * Convert a SpacingValue to a CSS padding string like \"10px 10px 10px 10px\".\n */\nexport function toPaddingString(padding: SpacingValue): string {\n return `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`;\n}\n","/**\n * MJML attribute helpers — single source of truth for placement rules\n * that the MJML spec enforces but accepts silently when violated.\n *\n * MJML drops unrecognized attributes without error. The most common trap is\n * background placement: only `mj-section`, `mj-button`, `mj-wrapper`, `mj-hero`\n * accept the native `background-color` attribute. Inner content elements\n * (`mj-text`, `mj-image`, `mj-table`, `mj-navbar`, `mj-video`) require\n * `container-background-color`, which paints the enclosing `<td>`. Passing\n * `background-color` to an inner element results in the attribute being\n * silently dropped — the email ships without the bg.\n *\n * https://documentation.mjml.io/\n */\n\nimport type {\n BackgroundImage,\n BorderRadiusValue,\n BorderValue,\n ImageBlock,\n SpacingValue,\n} from \"@templatical/types\";\nimport {\n resolveBackgroundImage,\n toBorderCss,\n toBorderDeclarations,\n toBorderRadiusCss,\n} from \"@templatical/types\";\nimport { escapeAttr, escapeCssValue } from \"./escape\";\nimport type { RenderContext } from \"./render-context\";\n\n/**\n * Where the MJML element accepts a background-color attribute.\n * - `native`: the element has its own `background-color` (mj-section, mj-button).\n * - `container`: the element only accepts `container-background-color`,\n * which colors the wrapping `<td>` (mj-text, mj-image, mj-table, mj-navbar, mj-video).\n */\nexport type BgPlacement = \"native\" | \"container\";\n\n/**\n * Render the appropriate background-color attribute for an MJML element.\n * Returns an empty string when no color is set, or a leading-space attribute\n * fragment ready to interpolate into a tag's attribute list.\n */\nexport function bgAttr(\n backgroundColor: string | undefined,\n placement: BgPlacement,\n): string {\n if (!backgroundColor) {\n return \"\";\n }\n\n const name =\n placement === \"native\" ? \"background-color\" : \"container-background-color\";\n\n return ` ${name}=\"${backgroundColor}\"`;\n}\n\n/**\n * Render `mj-image`'s height attribute. Returns an empty string when no height\n * is set, so MJML applies its own `auto` and the image keeps its aspect ratio.\n *\n * The px suffix is not cosmetic: `height` is a Unit attribute accepting only\n * `px` or `auto`, so a bare number is a validation error and MJML drops it.\n * Non-finite or non-positive values are treated as unset — a `0` here would\n * collapse the image rather than express \"no opinion\".\n */\nexport function heightAttr(height: number | undefined): string {\n if (typeof height !== \"number\" || !Number.isFinite(height) || height <= 0) {\n return \"\";\n }\n\n return ` height=\"${height}px\"`;\n}\n\n/**\n * The width an element's side padding and drawn side borders take from its\n * box. MJML subtracts exactly these when it sizes a wrapper's, a section's or\n * an image's content, so a side `toBorderCss` would not draw counts for 0.\n * MJML reads each side as a whole pixel (`parseInt` in its `shorthandParser`\n * and `borderParser`), so 20.5px of padding takes 20px and a 2.5px border 2px.\n */\nexport function horizontalInset(\n padding: SpacingValue | undefined,\n border?: BorderValue,\n): number {\n const whole = (value: number | undefined) => Math.trunc(value ?? 0);\n const drawn = (side: BorderValue[\"left\"] | undefined) =>\n toBorderCss(side) === null ? 0 : Math.trunc(side!.width);\n return (\n whole(padding?.left) +\n whole(padding?.right) +\n drawn(border?.left) +\n drawn(border?.right)\n );\n}\n\n/**\n * `fluid-on-mobile` for an `mj-image`, set only on an image that fills its\n * column on desktop: `\"full\"`, or a pixel width MJML caps at the room it gives\n * the image (the column less the image's own side padding and border). On a\n * phone the attribute widens the image to the stacked column, so an image set\n * narrower must not carry it: a 120px logo would grow to the whole column, and\n * one with a set height would stretch out of shape. An image wider than the\n * phone shrinks to fit without it.\n *\n * Exported for `blockRenderers` entries that emit their own `mj-image`. Pass\n * the context the renderer received, whose `contentWidth` already excludes the\n * wrappers and sections around the column.\n */\nexport function fluidOnMobileAttr(\n block: Pick<ImageBlock, \"width\" | \"styles\" | \"border\">,\n context: RenderContext,\n): string {\n const room =\n Math.floor(context.contentWidth) -\n horizontalInset(block.styles.padding, block.border);\n return block.width === \"full\" || block.width >= room\n ? ' fluid-on-mobile=\"true\"'\n : \"\";\n}\n\n/**\n * Render the border attributes for the MJML elements that accept them natively\n * (`mj-section`, `mj-image`, `mj-button`): a single `border` when it covers all\n * four sides, otherwise one `border-<side>` per chosen side. Returns an empty\n * string when there is nothing to draw, so templates without a border render\n * exactly as before.\n *\n * MJML copies the values into an inline `style`, so they go through\n * `escapeCssValue` — a tampered color must not smuggle in a sibling\n * declaration.\n */\nexport function borderAttr(border: BorderValue | undefined): string {\n return Object.entries(toBorderDeclarations(border))\n .map(([name, value]) => ` ${name}=\"${escapeCssValue(value)}\"`)\n .join(\"\");\n}\n\n/**\n * Render the `border-radius` attribute: `\"8px\"` for matching corners, or the\n * four-value shorthand (top-left, top-right, bottom-right, bottom-left) that\n * `mj-section`, `mj-wrapper`, `mj-image` and `mj-button` all accept. Returns an\n * empty string when every corner is square, rather than a `border-radius=\"0px\"`\n * every existing template would suddenly grow.\n */\nexport function borderRadiusAttr(\n radius: BorderRadiusValue | undefined,\n): string {\n const css = toBorderRadiusCss(radius);\n\n if (css === null) {\n return \"\";\n }\n\n return ` border-radius=\"${css}\"`;\n}\n\n/**\n * Render the background-image attributes `mj-section` and `mj-wrapper` accept.\n * All four are emitted together, so MJML's own defaults (`auto`, `top center`,\n * `repeat`) never apply. Returns an empty string when there is no image.\n *\n * MJML pastes `background-url` verbatim into `url('…')` and the Outlook VML\n * `src`; `resolveBackgroundImage` has already percent-encoded the characters\n * that could end the CSS string, and `escapeAttr` keeps the attribute closed.\n */\nexport function backgroundImageAttrs(bg: BackgroundImage | undefined): string {\n const resolved = resolveBackgroundImage(bg);\n\n if (resolved === null) {\n return \"\";\n }\n\n return ` background-url=\"${escapeAttr(resolved.url)}\" background-size=\"${resolved.size}\" background-position=\"${resolved.position}\" background-repeat=\"${resolved.repeat}\"`;\n}\n","import { RICH_TEXT_SPACING, isSection, isWrapper } from \"@templatical/types\";\nimport type { Block, ContentDirection } from \"@templatical/types\";\n\n/**\n * Marks the `mj-text` of a block whose content is editor-authored rich text\n * (paragraph and title). MJML puts a `css-class` on the wrapping `<td>`, which\n * is what {@link richTextStylesheet} scopes its selectors to.\n *\n * The scope is the point. A bare `p { … }` rule would also reach an `html`\n * block — the renderer puts consumer markup in `mj-text` too — and the editor\n * previews those in a sandboxed `srcdoc` iframe on UA defaults. Styling them\n * would trade this mismatch for another one, and an inlined declaration would\n * beat the consumer's own stylesheet.\n */\nexport const RICH_TEXT_CSS_CLASS = \"tpl-rich-text\";\n\n/**\n * The class carrying one specific paragraph gap, e.g. `tpl-rich-text-8`.\n *\n * Every rich-text block gets one of these *instead of* a shared paragraph rule.\n * That is a hard constraint, not a preference: `.tpl-rich-text p` and\n * `.tpl-rich-text-4 p` have identical specificity (one class, one type), so a\n * surviving base rule would win on source order and flatten every per-block gap\n * back to the default.\n */\nexport function richTextGapClass(gap: number): string {\n return `${RICH_TEXT_CSS_CLASS}-${gap}`;\n}\n\n/**\n * The global rules that make exported rich text match the editor canvas.\n *\n * Two gaps they close, neither visible until you measure the delivered email:\n *\n * - MJML's core skeleton injects `p { display:block;margin:13px 0; }` into\n * every document. Against the canvas's paragraph gap that made a\n * three-paragraph block 99px in the editor and 135px in the inbox — 13px\n * above the first paragraph, 13px below the last, and 13px rather than 8px\n * between each (issue #616).\n * - The skeleton resets nothing for `ul` / `ol` / `li`, so those fall through\n * to each client's UA stylesheet — around 14px margin and a 40px bullet\n * indent in Chromium, against the canvas's 8px and 24px. Unlike the\n * paragraph case the value is not even a fixed constant, so matching MJML in\n * the editor could not have fixed it.\n *\n * Emitted inside `<mj-style inline=\"inline\">`, so MJML runs it through juice\n * and the declarations land as real inline styles. That matters twice: they\n * survive a client that strips `<style>` from the head, and juice resolves\n * `:last-child` structurally at build time instead of dropping it.\n *\n * One paragraph rule per *distinct* gap in the document, so a template using\n * two gaps costs two rules rather than one per block. The list values stay on\n * the unversioned class: MJML resets nothing for `ul`/`ol`/`li`, so they exist\n * to pin down client defaults rather than to be designed with.\n */\nexport function richTextStylesheet(\n gaps: number[],\n direction: ContentDirection = \"ltr\",\n): string {\n const s = RICH_TEXT_SPACING;\n const scope = `.${RICH_TEXT_CSS_CLASS}`;\n const distinct = [...new Set(gaps)].sort((a, b) => a - b);\n\n const paragraphRules = distinct.flatMap((gap) => {\n const gapScope = `.${richTextGapClass(gap)}`;\n return [\n `${gapScope} p { margin: 0 0 ${gap}px; }`,\n `${gapScope} p:last-child { margin-bottom: 0; }`,\n ];\n });\n\n // Physical sides: Outlook does not honour `padding-inline-start`.\n const listPaddingSide =\n direction === \"rtl\" ? \"padding-right\" : \"padding-left\";\n\n return [\n ...paragraphRules,\n `${scope} ul, ${scope} ol { margin: ${s.listMarginY}px 0; ${listPaddingSide}: ${s.listPaddingLeft}px; }`,\n `${scope} li { margin: ${s.listItemMarginY}px 0; }`,\n ].join(\"\\n \");\n}\n\n/**\n * The paragraph gap a block asks for, or the built-in default.\n *\n * The fallback must produce a *rule* rather than nothing: silence hands the\n * paragraph back to MJML's `p { margin: 13px 0 }` skeleton default and reopens\n * the canvas/export mismatch. `0` is a legitimate gap, so this tests for\n * absence rather than falsiness.\n *\n * Mirrored on the canvas side by `getBlockWrapperStyle` in\n * `@templatical/editor`.\n */\nexport function resolveParagraphGap(spacing: number | undefined): number {\n return spacing ?? RICH_TEXT_SPACING.paragraphGap;\n}\n\n/**\n * Every paragraph gap the document uses, so the head can carry a rule for each.\n *\n * Walks section columns and wrapper children too — a paragraph inside a column\n * or a layout card needs its rule as much as a top-level one. Titles always\n * use the default gap: their content is normally a single paragraph the\n * renderer unwraps, and the multi-paragraph case is an edge worth spacing\n * consistently rather than configuring.\n */\nexport function collectParagraphGaps(blocks: Block[]): number[] {\n const gaps: number[] = [RICH_TEXT_SPACING.paragraphGap];\n\n const visit = (block: Block): void => {\n if (block.type === \"paragraph\") {\n gaps.push(resolveParagraphGap(block.paragraphSpacing));\n }\n if (isSection(block)) {\n for (const column of block.children) {\n for (const child of column) {\n visit(child);\n }\n }\n } else if (isWrapper(block)) {\n for (const child of block.children) {\n visit(child);\n }\n }\n };\n\n for (const block of blocks) {\n visit(block);\n }\n\n return gaps;\n}\n","import type { TitleBlock } from \"@templatical/types\";\nimport {\n HEADING_LEVEL_FONT_SIZE,\n TITLE_FONT_WEIGHT,\n TITLE_LINE_HEIGHT,\n fillEmptyParagraphs,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n convertMergeTagsToValues,\n escapeAttr,\n escapeFontFamily,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"../rich-text\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a title block to MJML markup.\n */\nexport function renderTitle(block: TitleBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n // Blank lines between a title's paragraphs are filled as the canvas fills\n // them; a single paragraph is unwrapped into the heading.\n const content = unwrapParagraph(\n fillEmptyParagraphs(convertMergeTagsToValues(block.content)),\n );\n // Clamp out-of-range levels to a defined entry so we never interpolate\n // `undefined` into `font-size=\"${...}px\"` (mjml@5 rejects \"undefinedpx\").\n const fontSize =\n HEADING_LEVEL_FONT_SIZE[block.level] ?? HEADING_LEVEL_FONT_SIZE[2];\n // Emit the color only when the block sets one; otherwise the `mj-text`\n // inherits the document `textColor` default from `<mj-attributes>`.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n const align = block.textAlign;\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n // `unwrapParagraph` strips only a *single* outer `<p>`, so a title the user\n // pressed Enter in keeps its paragraphs and needs a spacing rule. Titles\n // carry no gap of their own, so they always take the default.\n const cssClassAttr = getCssClassAttr(block, [\n RICH_TEXT_CSS_CLASS,\n richTextGapClass(resolveParagraphGap(undefined)),\n ]);\n // Same clamp logic as fontSize so that an out-of-range level still\n // produces a valid heading element.\n const safeLevel = HEADING_LEVEL_FONT_SIZE[block.level] ? block.level : 2;\n const tag = `h${safeLevel}`;\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"${TITLE_LINE_HEIGHT}\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${cssClassAttr}\n><${tag} style=\"margin:0;font-size:inherit;color:inherit;line-height:inherit;font-weight:${TITLE_FONT_WEIGHT}\">${content}</${tag}></mj-text>`;\n}\n\n/**\n * The editor stores title content as a TipTap paragraph (`<p>...</p>`),\n * but the renderer wraps it in `<h${level}>`. `<p>` is invalid inside a\n * heading, so strip a single outer `<p>` wrapper if present.\n */\nfunction unwrapParagraph(html: string): string {\n const match = html.match(/^\\s*<p\\b[^>]*>([\\s\\S]*)<\\/p>\\s*$/);\n if (!match) return html;\n // Only unwrap when there is exactly one top-level <p> — otherwise the\n // content has multiple paragraphs and we must leave it alone.\n if (/<\\/p>\\s*<p\\b/i.test(match[1])) return html;\n return match[1];\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type { ParagraphBlock } from \"@templatical/types\";\nimport { fillEmptyParagraphs, isBlankRichText } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { convertMergeTagsToValues } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"../rich-text\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a paragraph block to MJML markup.\n * All text formatting is inline in the HTML content (managed by TipTap).\n */\nexport function renderParagraph(\n block: ParagraphBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n // Skip when the user has cleared the paragraph — otherwise we emit a\n // styled `<td>` cell that adds visible whitespace to the email even\n // though the canvas shows nothing for an empty paragraph.\n if (isBlankRichText(block.content)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n // The canvas fills blank lines with the same helper, so the two agree.\n const content = fillEmptyParagraphs(convertMergeTagsToValues(block.content));\n const cssClassAttr = getCssClassAttr(block, [\n RICH_TEXT_CSS_CLASS,\n richTextGapClass(resolveParagraphGap(block.paragraphSpacing)),\n ]);\n\n // RTL templates need a start-edge default on the wrapper. Inner\n // `<p style=\"text-align:…\">` from TipTap still wins per paragraph.\n const alignAttr =\n context.contentDirection === \"rtl\" ? '\\n align=\"right\"' : \"\";\n\n return `<mj-text\n line-height=\"1.5\"${alignAttr}\n padding=\"${padding}\"${bgColor}${cssClassAttr}\n>${content}</mj-text>`;\n}\n","import type { ImageBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport {\n bgAttr,\n borderAttr,\n borderRadiusAttr,\n fluidOnMobileAttr,\n heightAttr,\n} from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render an image block to MJML markup.\n */\nexport function renderImage(block: ImageBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.src === \"\") {\n // Skip rather than emit `<mj-image src=\"\">` which compiles to a\n // broken-image icon. Mirrors video.ts behavior when no source is set.\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const width =\n block.width === \"full\" ? context.containerWidth + \"px\" : block.width + \"px\";\n const height = heightAttr(block.height);\n const fluid = fluidOnMobileAttr(block, context);\n\n const visibilityAttr = getCssClassAttr(block);\n\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const borderAttrStr = borderAttr(block.border);\n\n let linkAttr = \"\";\n if (block.linkUrl) {\n linkAttr = ` href=\"${escapeAttr(block.linkUrl)}\"`;\n if (block.linkOpenInNewTab) {\n linkAttr += ' target=\"_blank\" rel=\"noopener\"';\n }\n }\n\n const src = escapeAttr(block.src);\n const decorative = block.decorative === true;\n const alt = decorative ? \"\" : escapeAttr(block.alt);\n const align = block.align;\n const roleAttr = decorative ? ' role=\"presentation\"' : \"\";\n\n return `<mj-image\n src=\"${src}\"\n alt=\"${alt}\"\n width=\"${width}\"${height}${fluid}\n align=\"${align}\"\n padding=\"${padding}\"${bgColor}${borderAttrStr}${borderRadiusAttrStr}${linkAttr}${visibilityAttr}${roleAttr}\n/>`;\n}\n","import type { ButtonBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr, escapeFontFamily, escapeHtml } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport type { BorderRadiusValue } from \"@templatical/types\";\nimport { toBorderRadiusCss } from \"@templatical/types\";\nimport { bgAttr, borderAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Marks the `mj-button` of a full-width button. MJML gives the button's `<a>`\n * a width only for a px `width`; for `100%` it widens the `<table>` and leaves\n * the `<a>` at `display:inline-block`, so only the label is clickable.\n * `renderToMjml` scopes the head rule that makes the `<a>` fill the button to\n * this class.\n */\nexport const BUTTON_FULL_WIDTH_CSS_CLASS = \"tpl-button-full\";\n\n/**\n * Render a button block to MJML markup.\n */\nexport function renderButton(\n block: ButtonBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const buttonPadding = toPaddingString(block.buttonPadding);\n\n // Omit href entirely when no URL is set so we don't emit a clickable\n // `<a href=\"\">` that navigates to whatever URL the email is opened from.\n const href = block.url === \"\" ? \"\" : escapeAttr(block.url);\n const hrefAttr = href === \"\" ? \"\" : ` href=\"${href}\"`;\n const backgroundColor = buttonBackgroundAttr(block.backgroundColor);\n const textColor = escapeAttr(block.textColor);\n const fontSize = block.fontSize;\n const borderRadius = renderButtonRadius(block.borderRadius);\n const text = escapeHtml(block.text);\n const targetAttr = block.openInNewTab\n ? ' target=\"_blank\" rel=\"noopener\"'\n : \"\";\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const widthAttr = renderWidthAttr(block.width);\n const cssClassAttr = getCssClassAttr(\n block,\n block.width === \"full\" ? [BUTTON_FULL_WIDTH_CSS_CLASS] : [],\n );\n const borderAttrStr = borderAttr(block.border);\n // Templates stored before `align` existed have no value for it. Fall back to\n // MJML's own default so they keep rendering exactly as they did.\n const align = block.align ?? \"center\";\n\n return `<mj-button${hrefAttr}${targetAttr}\n background-color=\"${backgroundColor}\"\n color=\"${textColor}\"\n font-size=\"${fontSize}px\"\n font-weight=\"bold\"\n border-radius=\"${borderRadius}\"${borderAttrStr}\n inner-padding=\"${buttonPadding}\"\n align=\"${align}\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${widthAttr}${cssClassAttr}\n>${text}</mj-button>`;\n}\n\n/**\n * MJML paints `#414141` when `background-color` is omitted, and `\"\"` is not a\n * color it accepts. An unset button fill is the keyword `transparent`.\n */\nfunction buttonBackgroundAttr(color: string): string {\n if (color.trim() === \"\") return \"transparent\";\n return escapeAttr(color);\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n\n/**\n * The button has always emitted its radius, `0px` included, so a plain number\n * keeps rendering exactly as it did. Per-corner radii go through the shared\n * formatter, with all-square corners as `0px`.\n */\nfunction renderButtonRadius(radius: BorderRadiusValue): string {\n if (typeof radius === \"number\") {\n return `${radius}px`;\n }\n\n return toBorderRadiusCss(radius) ?? \"0px\";\n}\n\nfunction renderWidthAttr(width: number | \"full\" | undefined): string {\n if (width === undefined) {\n return \"\";\n }\n\n const value = width === \"full\" ? \"100%\" : `${width}px`;\n\n return ` width=\"${value}\"`;\n}\n","import type { DividerBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a divider block to MJML markup.\n */\nexport function renderDivider(\n block: DividerBlock,\n _context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n // A percentage passes through as is: MJML takes it natively.\n const width =\n block.width === \"full\"\n ? \"100%\"\n : typeof block.width === \"number\"\n ? `${block.width}px`\n : block.width;\n const thickness = block.thickness;\n const lineStyle = block.lineStyle;\n const color = escapeAttr(block.color);\n const visibilityAttr = getCssClassAttr(block);\n\n return `<mj-divider\n border-width=\"${thickness}px\"\n border-style=\"${lineStyle}\"\n border-color=\"${color}\"\n width=\"${width}\"\n padding=\"${padding}\"${bgColor}${visibilityAttr}\n/>`;\n}\n","import type { SpacerBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a spacer block to MJML markup.\n *\n * The canvas renders a spacer at exactly `block.height` pixels and ignores\n * `block.styles.padding`. Match that here: emit `padding=\"0\"` so the\n * exported email's spacer occupies the same vertical space the user saw\n * in the editor preview. Any non-zero `block.styles.padding` on a spacer\n * is meaningless and silently dropped from the export.\n */\nexport function renderSpacer(\n block: SpacerBlock,\n _context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const height = block.height;\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n const visibilityAttr = getCssClassAttr(block);\n\n return `<mj-spacer height=\"${height}px\" padding=\"0\"${bgColor}${visibilityAttr} />`;\n}\n","import type { HtmlBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render an HTML block to MJML markup.\n * No sanitization in the OSS version -- consumers are responsible for content safety.\n */\nexport function renderHtml(block: HtmlBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (!context.allowHtmlBlocks) {\n return \"\";\n }\n\n const content = block.content;\n\n if (content === \"\") {\n return \"\";\n }\n\n const visibilityAttr = getCssClassAttr(block);\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n\n // Use mj-text to render HTML content inside proper table cell structure.\n // mj-raw bypasses MJML's table layout and content won't be visible.\n return `<mj-text padding=\"${padding}\"${bgColor}${visibilityAttr}>\n${content}\n</mj-text>`;\n}\n","import type { SocialIconsBlock } from \"@templatical/types\";\nimport { socialIconAssetDir } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a social icons block to MJML markup.\n *\n * Icons are emitted as `<img src=\"…/{dir}/{platform}.png\">` rather than\n * inline SVG or base64 data URIs. Outlook desktop (Word rendering engine)\n * does not support SVG and rejects base64 in `<img src>`, so hosted PNGs are\n * the only format that renders across every mainstream client. The base URL\n * is read from `context.socialIconsBaseUrl` (configurable via\n * `RenderOptions.socialIconsBaseUrl`; default is the version-pinned jsDelivr\n * mirror of this package). `{dir}` is the style, plus `-{tone}` for a\n * one-color tone (`socialIconAssetDir`).\n */\nexport function renderSocialIcons(\n block: SocialIconsBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const icons = block.icons;\n\n if (icons.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n const visibilityAttr = getCssClassAttr(block);\n const align = block.align;\n const iconSize = block.iconSize;\n const iconStyle = block.iconStyle;\n const assetDir = socialIconAssetDir(iconStyle, block.iconTone);\n const spacing = block.spacing;\n\n let iconSizePx: number;\n switch (iconSize) {\n case \"small\":\n iconSizePx = 24;\n break;\n case \"large\":\n iconSizePx = 48;\n break;\n default:\n iconSizePx = 32;\n break;\n }\n\n // MJML mj-social-element has default border-radius of 3px, override per style\n let borderRadius: string;\n switch (iconStyle) {\n case \"circle\":\n borderRadius = \"50%\";\n break;\n case \"rounded\":\n borderRadius = \"8px\";\n break;\n case \"square\":\n borderRadius = \"0\";\n break;\n default:\n borderRadius = \"4px\"; // solid, outlined, plain\n break;\n }\n\n const iconCount = icons.length;\n const socialElements = icons.map((icon, index) => {\n const platform = icon.platform;\n const url = escapeAttr(icon.url);\n const iconSrc = `${context.socialIconsBaseUrl}/${assetDir}/${platform}.png`;\n\n // Apply spacing as right padding only (except last icon) to match CSS gap behavior\n const rightPad = index === iconCount - 1 ? 0 : spacing;\n\n // Empty content hides the platform name text, matching the editor display\n return `<mj-social-element src=\"${iconSrc}\" href=\"${url}\" icon-size=\"${iconSizePx}px\" padding=\"0 ${rightPad}px 0 0\" border-radius=\"${borderRadius}\" background-color=\"transparent\"></mj-social-element>`;\n });\n\n const socialContent = socialElements.join(\"\\n\");\n\n return `<mj-social\n mode=\"horizontal\"\n align=\"${align}\"\n icon-padding=\"0\"\n padding=\"${padding}\"${bgColor}${visibilityAttr}\n>\n${socialContent}\n</mj-social>`;\n}\n","import type { MenuBlock, MenuItemData } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n escapeHtml,\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a menu block to MJML markup.\n * Uses mj-text with inline <a> tags separated by styled <span> separators.\n */\nexport function renderMenu(block: MenuBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.items.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const visibilityAttr = getCssClassAttr(block);\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const align = block.textAlign;\n const fontSize = block.fontSize;\n // Emit the color only when set; otherwise the `mj-text` inherits the\n // document `textColor` and the item anchors below inherit it in turn.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n\n const content = renderMenuItems(block);\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"1.5\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${visibilityAttr}\n>${content}</mj-text>`;\n}\n\nfunction renderMenuItems(block: MenuBlock): string {\n const items = block.items;\n const separator = escapeHtml(block.separator);\n const separatorColor = escapeCssValue(block.separatorColor);\n const spacing = block.spacing;\n const linkColor = block.linkColor ?? block.color;\n\n const parts: string[] = [];\n const itemCount = items.length;\n\n for (let index = 0; index < itemCount; index++) {\n parts.push(renderMenuItem(items[index], linkColor));\n\n if (index < itemCount - 1) {\n parts.push(\n `<span style=\"color: ${separatorColor}; padding: 0 ${spacing}px;\">${separator}</span>`,\n );\n }\n }\n\n return parts.join(\"\");\n}\n\nfunction renderMenuItem(\n item: MenuItemData,\n linkColor: string | undefined,\n): string {\n const text = escapeHtml(item.text);\n const url = escapeAttr(item.url);\n // Item color, else the menu link color; when neither is set the anchor omits\n // an explicit color and inherits the mj-text color (the document `textColor`).\n const resolvedColor = item.color ?? linkColor;\n const target = item.openInNewTab ? ' target=\"_blank\" rel=\"noopener\"' : \"\";\n\n const styles: string[] = [\"text-decoration: none\"];\n\n if (resolvedColor) {\n styles.unshift(`color: ${escapeCssValue(resolvedColor)}`);\n }\n\n if (item.bold) {\n styles.push(\"font-weight: bold\");\n }\n\n if (item.underline) {\n styles.push(\"text-decoration: underline\");\n }\n\n const styleAttr = styles.join(\"; \");\n\n return `<a href=\"${url}\" style=\"${styleAttr}\"${target}>${text}</a>`;\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type {\n TableBlock,\n TableRowData,\n TableCellData,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n escapeHtml,\n convertMergeTagsToValues,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a table block to MJML markup.\n * Uses mj-text wrapping an HTML <table> with styled <tr>/<td> elements.\n */\nexport function renderTable(block: TableBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.rows.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const visibilityAttr = getCssClassAttr(block);\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const fontSize = block.fontSize;\n // Emit the color only when set; otherwise the `mj-text` (and its cells,\n // which carry no color of their own) inherit the document `textColor`.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n const align = block.textAlign;\n\n const tableHtml = renderTableElement(block);\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"1.5\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${visibilityAttr}\n>${tableHtml}</mj-text>`;\n}\n\nfunction renderTableElement(block: TableBlock): string {\n const borderColor = escapeCssValue(block.borderColor);\n const borderWidth = block.borderWidth;\n\n const tableStyle = \"width: 100%; border-collapse: collapse;\";\n\n let rowsHtml = \"\";\n\n for (let index = 0; index < block.rows.length; index++) {\n const row = block.rows[index];\n const isHeader = block.hasHeaderRow && index === 0;\n rowsHtml += renderRow(row, block, isHeader, borderColor, borderWidth);\n }\n\n return `<table style=\"${tableStyle}\">${rowsHtml}</table>`;\n}\n\nfunction renderRow(\n row: TableRowData,\n block: TableBlock,\n isHeader: boolean,\n borderColor: string,\n borderWidth: number,\n): string {\n let cellsHtml = \"\";\n\n for (const cell of row.cells) {\n cellsHtml += renderCell(cell, block, isHeader, borderColor, borderWidth);\n }\n\n return `<tr>${cellsHtml}</tr>`;\n}\n\nfunction renderCell(\n cell: TableCellData,\n block: TableBlock,\n isHeader: boolean,\n borderColor: string,\n borderWidth: number,\n): string {\n const cellPadding = block.cellPadding;\n\n const styles: string[] = [\n `border: ${borderWidth}px solid ${borderColor}`,\n `padding: ${cellPadding}px`,\n ];\n\n if (isHeader) {\n styles.push(\"font-weight: bold\");\n\n if (block.headerBackgroundColor) {\n styles.push(\n `background-color: ${escapeCssValue(block.headerBackgroundColor)}`,\n );\n }\n }\n\n const styleAttr = styles.join(\"; \");\n // Cells are a plain-text field (the editor stores innerText; TableCellData\n // carries no rich-text hint), so escape the content like menu/button. Merge\n // tags are resolved first: convertMergeTagsToValues matches a literal\n // `<span`, so escaping has to run after it — escaping first would turn the\n // span into `&lt;span` and the `{{value}}` placeholder would never resolve.\n const content = escapeHtml(convertMergeTagsToValues(cell.content));\n\n const tag = isHeader ? \"th\" : \"td\";\n\n return `<${tag} style=\"${styleAttr}\">${content}</${tag}>`;\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type { CustomBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a custom block to MJML markup.\n *\n * Custom block HTML resolution order:\n * 1. `context.customBlockHtml` map — populated by `renderToMjml` when the\n * caller passes a `renderCustomBlock` option (typical for editor\n * consumers and headless callers wiring their own resolver).\n * 2. `block.renderedHtml` — populated by an external pre-render step\n * (e.g., a previous render pass that mutated the block).\n * 3. Empty — block omitted from output.\n */\nexport function renderCustom(\n block: CustomBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const fromContext = context.customBlockHtml.get(block.id);\n const content = fromContext ?? block.renderedHtml;\n\n if (!content || content === \"\") {\n return \"\";\n }\n\n const visibilityAttr = getCssClassAttr(block);\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n\n return `<mj-text padding=\"${padding}\"${bgColor}${visibilityAttr}>\n${content}\n</mj-text>`;\n}\n","import type { ColumnLayout } from \"@templatical/types\";\n\n/**\n * Get width percentages for each column in a layout.\n */\nexport function getWidthPercentages(layout: ColumnLayout): string[] {\n switch (layout) {\n case \"2\":\n return [\"50%\", \"50%\"];\n case \"3\":\n // 33.33 × 3 = 99.99% — let the last column absorb the rounding gap\n // so widths sum to exactly 100% in the compiled HTML.\n return [\"33.33%\", \"33.33%\", \"33.34%\"];\n case \"1-2\":\n return [\"33.33%\", \"66.67%\"];\n case \"2-1\":\n return [\"66.67%\", \"33.33%\"];\n default:\n return [\"100%\"];\n }\n}\n\n/**\n * Get width in pixels for each column in a layout.\n */\nexport function getWidthPixels(\n layout: ColumnLayout,\n containerWidth: number,\n): number[] {\n switch (layout) {\n case \"2\":\n return [containerWidth * 0.5, containerWidth * 0.5];\n case \"3\":\n return [containerWidth / 3, containerWidth / 3, containerWidth / 3];\n case \"1-2\":\n return [containerWidth / 3, (containerWidth * 2) / 3];\n case \"2-1\":\n return [(containerWidth * 2) / 3, containerWidth / 3];\n default:\n return [containerWidth];\n }\n}\n","import type { AppliedHero, SpacingValue } from \"@templatical/types\";\n\n/** The sizing attributes of an `mj-hero`. */\nexport interface HeroGeometry {\n mode: \"fixed-height\";\n /** Total height in px, padding included. */\n height: number;\n backgroundWidth: number;\n backgroundHeight: number;\n}\n\n/**\n * The `mj-hero` sizing for a hero in a box `boxWidth` px wide. Every hero's\n * mode, height and image size come from here, so an Outlook rendering\n * finding changes this function and nothing else.\n *\n * Every hero is `fixed-height`: classic Outlook on Windows ignores\n * `fluid-height` (its spacer cells carry `mso-padding-bottom-alt:0`) and\n * shrinks the box to its content, showing only the top of the image.\n *\n * - `height: \"image\"` → the image's own height at the box width, so the box\n * matches the image on desktop. A phone keeps that height and crops the\n * image's sides to cover the narrower box.\n * - a number → that height.\n *\n * Either is at least the top and bottom `padding`, each a whole pixel as MJML\n * reads it: MJML sizes the cell as the height less that padding and would\n * write a negative height for a shorter box.\n *\n * Outlook draws the image as a `v:image` of exactly `backgroundWidth ×\n * backgroundHeight` px from the box's top, clipped to the box, so the width is\n * always the box's and the height is the image's own at that width. An image\n * with no known size takes the fixed box's height, which fills the box and\n * stretches the image to it.\n */\nexport function heroGeometry(\n hero: AppliedHero,\n boxWidth: number,\n padding: SpacingValue,\n): HeroGeometry {\n const backgroundWidth = Math.max(1, Math.round(boxWidth));\n const imageHeight =\n hero.aspectRatio === null\n ? null\n : Math.max(1, Math.round(backgroundWidth * hero.aspectRatio));\n\n // resolveHero applies \"image\" only with a known ratio.\n const wanted =\n hero.height === \"image\" ? (imageHeight ?? backgroundWidth) : hero.height;\n const height = Math.max(\n wanted,\n Math.trunc(padding.top) + Math.trunc(padding.bottom),\n );\n\n return {\n mode: \"fixed-height\",\n height,\n backgroundWidth,\n backgroundHeight: imageHeight ?? height,\n };\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Wrap rendered block markup in the block's liquid display-condition guards\n * (`<mj-raw>{% if %}</mj-raw>` … `<mj-raw>{% endif %}</mj-raw>`), if present.\n *\n * Returns the input unchanged when the block has no display condition, and an\n * empty string when the rendered markup is empty (a hidden block) so callers\n * can keep using an `=== \"\"` filter to drop it.\n *\n * Used for BOTH top-level blocks (`index.ts`) and blocks nested inside section\n * columns (`renderers/section.ts`). A condition on a nested block must emit the\n * same guards as a top-level one — otherwise conditional content placed inside\n * a multi-column section renders unconditionally for every recipient.\n */\nexport function wrapWithDisplayCondition(\n block: Block,\n rendered: string,\n): string {\n if (rendered === \"\") {\n return \"\";\n }\n\n const displayCondition = block.displayCondition;\n\n if (!displayCondition) {\n return rendered;\n }\n\n return (\n `<mj-raw>${displayCondition.before}</mj-raw>` +\n \"\\n\" +\n rendered +\n \"\\n\" +\n `<mj-raw>${displayCondition.after}</mj-raw>`\n );\n}\n","import type { AppliedHero, Block, SectionBlock } from \"@templatical/types\";\nimport { isSection, resolveHero } from \"@templatical/types\";\nimport type { BlockRenderer, RenderContext } from \"../render-context\";\nimport { getWidthPercentages, getWidthPixels } from \"../columns\";\nimport { escapeAttr } from \"../escape\";\nimport { heroGeometry } from \"../hero-geometry\";\nimport { toPaddingString } from \"../padding\";\nimport {\n backgroundImageAttrs,\n bgAttr,\n borderAttr,\n borderRadiusAttr,\n horizontalInset,\n} from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\nimport { wrapWithDisplayCondition } from \"../display-condition\";\n\n// `BlockRenderer` is defined in `../render-context`, next to the `blockRenderers`\n// override map it types. Re-exported here so the package's\n// `export type { BlockRenderer } from \"./renderers/section\"` entry point resolves\n// for consumers.\nexport type { BlockRenderer };\n\n/**\n * Render a section block with columns to MJML markup.\n */\nexport function renderSection(\n block: SectionBlock,\n context: RenderContext,\n renderBlock: BlockRenderer,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const hero = resolveHero(block);\n if (hero?.applied) {\n return renderHero(block, hero, context, renderBlock);\n }\n\n const columnsLayout = block.columns;\n const columnWidths = getWidthPercentages(columnsLayout);\n const columnWidthsPx = getWidthPixels(columnsLayout, context.containerWidth);\n // What MJML gives each column's content: the emitted percentage of the room\n // inside the section's padding and border, floored as MJML floors it. From\n // the percentage strings, not `columnWidthsPx`: 33.33% of 600 is 199, a\n // third is 200.\n const sectionBox =\n Math.floor(context.contentWidth) -\n horizontalInset(block.styles.padding, block.border);\n const columnContentWidths = columnWidths.map((width) =>\n Math.floor((sectionBox * parseFloat(width)) / 100),\n );\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"native\");\n const bgImage = backgroundImageAttrs(block.backgroundImage);\n const visibilityAttr = getCssClassAttr(block);\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const borderAttrStr = borderAttr(block.border);\n // MJML's `mj-section`, `mj-group` and `mj-column` each default to\n // `direction=\"ltr\"` and inline it on their own element, so an RTL email\n // needs it on all three — the column's inline style otherwise resets the\n // text inside to LTR under a section that reverses the column order.\n const dirAttr = context.contentDirection === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n\n const children = block.children;\n const columnsContent: string[] = [];\n\n for (let index = 0; index < children.length; index++) {\n const column = children[index];\n const width = columnWidths[index] ?? \"100%\";\n const columnWidth = Math.floor(\n columnWidthsPx[index] ?? context.containerWidth,\n );\n\n // Sections cannot be nested inside columns per MJML spec — drop any\n // SectionBlocks that landed inside a column (via tampered JSON or a\n // future API). Keeping them would emit `<mj-section>` inside\n // `<mj-column>`, which mjml@5 rejects with a hard error.\n const filteredColumn = filterHtmlBlocks(\n column,\n context.allowHtmlBlocks,\n ).filter((child) => !isSection(child));\n const columnContext = context.withContainerWidth(\n columnWidth,\n columnContentWidths[index] ?? sectionBox,\n );\n\n const columnBlocks = filteredColumn\n .map((child) =>\n wrapWithDisplayCondition(child, renderBlock(child, columnContext)),\n )\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n const content =\n columnBlocks === \"\" ? \"<mj-text>&nbsp;</mj-text>\" : columnBlocks;\n\n columnsContent.push(`<mj-column width=\"${width}\"${dirAttr}>\n${content}\n</mj-column>`);\n }\n\n const columns = columnsContent.join(\"\\n\");\n\n // Opting out of mobile stacking wraps the columns in an `<mj-group>`, which\n // keeps them side-by-side below 480px instead of stacking (MJML's default).\n // `mj-group` requires percentage column widths — `getWidthPercentages`\n // already guarantees that. Only meaningful with 2+ columns.\n const body =\n block.stackOnMobile === false && columnsContent.length > 1\n ? `<mj-group${dirAttr}>\n${columns}\n</mj-group>`\n : columns;\n\n return `<mj-section${bgColor}${bgImage} padding=\"${padding}\"${borderAttrStr}${borderRadiusAttrStr}${visibilityAttr}${dirAttr}>\n${body}\n</mj-section>`;\n}\n\n/**\n * Render a section `resolveHero` applies as an `<mj-hero>`. The content is\n * column 0's blocks, filtered as a column's are; mj-hero takes content\n * elements directly, with no `mj-column`.\n *\n * The hero's box is the room its bands leave it, `context.contentWidth`\n * floored as MJML floors every band; Outlook draws the image at exactly that\n * width. Its content renders `\"full\"` at the box and gets the box less the\n * hero's own side padding as its room, as mj-hero gives it: no border comes\n * off, since a hero draws none.\n *\n * Left out on purpose: `border` (mj-hero has none), `background-size` and\n * `background-repeat` (it always paints `cover`, unrepeated) and `direction`\n * (it inlines none, so its text keeps the body's `dir`). An unset fill is\n * `transparent`, since mj-hero's own default is white.\n */\nfunction renderHero(\n block: SectionBlock,\n hero: AppliedHero,\n context: RenderContext,\n renderBlock: BlockRenderer,\n): string {\n const boxWidth = Math.floor(context.contentWidth);\n const geometry = heroGeometry(hero, boxWidth, block.styles.padding);\n const bgColor =\n bgAttr(block.styles.backgroundColor, \"native\") ||\n ' background-color=\"transparent\"';\n const padding = toPaddingString(block.styles.padding);\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const visibilityAttr = getCssClassAttr(block);\n const contentContext = context.withContainerWidth(\n boxWidth,\n boxWidth - horizontalInset(block.styles.padding),\n );\n\n const content = filterHtmlBlocks(\n block.children[0] ?? [],\n context.allowHtmlBlocks,\n )\n .filter((child) => !isSection(child))\n .map((child) =>\n wrapWithDisplayCondition(child, renderBlock(child, contentContext)),\n )\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n return `<mj-hero mode=\"${geometry.mode}\" height=\"${geometry.height}px\" background-url=\"${escapeAttr(hero.image.url)}\" background-width=\"${geometry.backgroundWidth}px\" background-height=\"${geometry.backgroundHeight}px\" background-position=\"${hero.image.position}\"${bgColor} padding=\"${padding}\" vertical-align=\"${hero.verticalAlign}\"${borderRadiusAttrStr}${visibilityAttr}>\n${content}\n</mj-hero>`;\n}\n\n/**\n * Filter out HTML blocks if they are not allowed.\n */\nfunction filterHtmlBlocks(blocks: Block[], allowHtmlBlocks: boolean): Block[] {\n if (allowHtmlBlocks) {\n return blocks;\n }\n\n return blocks.filter((block) => block.type !== \"html\");\n}\n","import type { VideoBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr, fluidOnMobileAttr, heightAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Extract video thumbnail URL from common platforms.\n * Works without server-side processing — YouTube and Vimeo thumbnails are publicly accessible.\n */\nfunction getVideoThumbnail(\n url: string,\n customThumbnail?: string,\n): string | null {\n if (customThumbnail) {\n return customThumbnail;\n }\n\n if (!url) {\n return null;\n }\n\n // YouTube\n const youtubePatterns = [\n /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/)([a-zA-Z0-9_-]{11})/,\n /youtube\\.com\\/shorts\\/([a-zA-Z0-9_-]{11})/,\n ];\n\n for (const pattern of youtubePatterns) {\n const match = url.match(pattern);\n if (match) {\n return `https://img.youtube.com/vi/${match[1]}/maxresdefault.jpg`;\n }\n }\n\n // Vimeo\n const vimeoMatch = url.match(/vimeo\\.com\\/(?:video\\/)?(\\d+)/);\n if (vimeoMatch) {\n return `https://vumbnail.com/${vimeoMatch[1]}.jpg`;\n }\n\n return null;\n}\n\n/**\n * Render a video block to MJML markup.\n * Videos in email are rendered as a linked thumbnail image pointing to the video URL.\n */\nexport function renderVideo(block: VideoBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const thumbnailUrl = getVideoThumbnail(block.url, block.thumbnailUrl);\n\n if (!thumbnailUrl) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const width =\n block.width === \"full\" ? context.containerWidth + \"px\" : block.width + \"px\";\n const height = heightAttr(block.height);\n const fluid = fluidOnMobileAttr(block, context);\n const visibilityAttr = getCssClassAttr(block);\n\n const src = escapeAttr(thumbnailUrl);\n const alt = escapeAttr(block.alt);\n const align = block.align;\n const href = escapeAttr(block.url);\n\n return `<mj-image\n src=\"${src}\"\n alt=\"${alt}\"\n width=\"${width}\"${height}${fluid}\n align=\"${align}\"\n padding=\"${padding}\"\n href=\"${href}\"\n target=\"_blank\"\n rel=\"noopener\"${bgColor}${visibilityAttr}\n/>`;\n}\n","import type { Block } from \"@templatical/types\";\nimport {\n isSection,\n isTitle,\n isParagraph,\n isImage,\n isButton,\n isDivider,\n isSpacer,\n isHtml,\n isSocialIcons,\n isMenu,\n isTable,\n isVideo,\n isCustomBlock,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { isHiddenOnAll } from \"../visibility\";\nimport { renderUnrenderableBlock } from \"../unrenderable\";\nimport { renderTitle } from \"./title\";\nimport { renderParagraph } from \"./paragraph\";\nimport { renderImage } from \"./image\";\nimport { renderButton } from \"./button\";\nimport { renderDivider } from \"./divider\";\nimport { renderSpacer } from \"./spacer\";\nimport { renderHtml } from \"./html\";\nimport { renderSocialIcons } from \"./social\";\nimport { renderMenu } from \"./menu\";\nimport { renderTable } from \"./table\";\nimport { renderCustom } from \"./custom\";\nimport { renderSection } from \"./section\";\nimport { renderVideo } from \"./video\";\n\n/**\n * Render a single block to MJML markup.\n * Dispatches to the appropriate block-type renderer.\n *\n * A `blockRenderers` override for the block's type wins over the built-in\n * renderer — see {@link RenderContext.blockRenderers}. A type with neither gets a\n * placeholder marker plus a warning rather than disappearing.\n */\nexport function renderBlock(block: Block, context: RenderContext): string {\n // Checked first so an override replaces the built-in wholesale rather than\n // running after it. The override then owns everything the built-in did,\n // including the hidden-on-all-viewports early return.\n const override = context.blockRenderers[block.type];\n if (override) {\n return override(block, context);\n }\n\n if (isSection(block)) {\n return renderSection(block, context, renderBlock);\n }\n\n if (isTitle(block)) {\n return renderTitle(block, context);\n }\n\n if (isParagraph(block)) {\n return renderParagraph(block, context);\n }\n\n if (isImage(block)) {\n return renderImage(block, context);\n }\n\n if (isButton(block)) {\n return renderButton(block, context);\n }\n\n if (isDivider(block)) {\n return renderDivider(block, context);\n }\n\n if (isSpacer(block)) {\n return renderSpacer(block, context);\n }\n\n if (isHtml(block)) {\n return renderHtml(block, context);\n }\n\n if (isSocialIcons(block)) {\n return renderSocialIcons(block, context);\n }\n\n if (isMenu(block)) {\n return renderMenu(block, context);\n }\n\n if (isTable(block)) {\n return renderTable(block, context);\n }\n\n if (isVideo(block)) {\n return renderVideo(block, context);\n }\n\n if (isCustomBlock(block)) {\n return renderCustom(block, context);\n }\n\n // Nothing here knows how to render this type. A block the author hid on every\n // viewport is meant to produce nothing, so it still does — every built-in\n // renderer above makes the same call, and warning about a deliberate hide would\n // be noise. Everything else gets a marker: `countdown` today (Cloud renders it\n // server-side as an animated GIF, which no browser can do), and any future type\n // whose renderer hasn't landed yet.\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n return renderUnrenderableBlock(block);\n}\n","import type {\n Block,\n ContentDirection,\n CustomBlock,\n TemplateContent,\n CustomFont,\n SectionWrapper,\n SpacingValue,\n} from \"@templatical/types\";\nimport {\n applyLayout,\n assertNoSlotInContent,\n assertNoWrapperInContent,\n isCustomBlock,\n isSection,\n isWrapper,\n resolveContentDirection,\n} from \"@templatical/types\";\nimport { RenderContext, DEFAULT_SOCIAL_ICONS_BASE_URL } from \"./render-context\";\nimport type { BlockRendererMap } from \"./render-context\";\nimport { renderBlock } from \"./renderers\";\nimport {\n escapeHtml,\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n} from \"./escape\";\nimport { wrapWithDisplayCondition } from \"./display-condition\";\nimport {\n backgroundImageAttrs,\n bgAttr,\n borderRadiusAttr,\n horizontalInset,\n} from \"./utils\";\nimport { richTextStylesheet, collectParagraphGaps } from \"./rich-text\";\nimport { BUTTON_FULL_WIDTH_CSS_CLASS } from \"./renderers/button\";\nimport { toPaddingString } from \"./padding\";\n\nexport interface RenderOptions {\n customFonts?: CustomFont[];\n defaultFallbackFont?: string;\n allowHtmlBlocks?: boolean;\n /**\n * Resolves custom blocks to their HTML representation. Called once per\n * custom block in the content tree before MJML rendering. The renderer\n * has no built-in knowledge of how to render custom blocks; consumers\n * provide this function.\n *\n * Editor consumers: pass `editor.renderCustomBlock`.\n *\n * Headless consumers (Node.js, server, CLI): provide your own resolver,\n * typically using the same liquid template + field values pipeline as\n * the editor uses. If omitted, custom blocks fall back to\n * `block.renderedHtml` (if present) and otherwise are omitted from the\n * output.\n */\n renderCustomBlock?: (block: CustomBlock) => Promise<string>;\n /**\n * Per-block-type renderer overrides, keyed by `block.type`. An entry replaces\n * the built-in renderer for that type wholesale — including its\n * hidden-on-all-viewports check, which becomes the override's responsibility.\n *\n * ```ts\n * renderToMjml(content, {\n * blockRenderers: {\n * countdown: (block) => `<mj-image src=\"${countdownGifUrl(block)}\" />`,\n * video: (block, ctx) => renderVideoWithPlayButton(block, ctx),\n * },\n * });\n * ```\n *\n * This generalises {@link renderCustomBlock}, which is the same idea for a\n * single block type. It exists so a backend whose render output is a *superset*\n * of the browser's — a server-generated countdown GIF, a composited video\n * thumbnail — can inject exactly that delta instead of forking the renderer:\n * parity for every other block type then holds by construction.\n *\n * A block type with neither a built-in renderer nor an override emits an\n * `mj-raw` placeholder comment and warns, rather than vanishing from the\n * output.\n */\n blockRenderers?: BlockRendererMap;\n /**\n * Resolves the definition-level CSS for a custom block type. Called once\n * per unique `customType` present in the content tree (not per instance).\n * The non-empty results are deduped by content and emitted as additional\n * `<mj-style>` blocks inside `<mj-head>` alongside the built-in visibility\n * media queries.\n *\n * Editor consumers: pass a function that reads\n * `blockRegistry.getDefinition(customType)?.stylesheet`.\n *\n * Headless consumers: provide your own resolver, typically from the same\n * definitions map used by `renderCustomBlock`. Return `undefined` or `null`\n * for definitions without a stylesheet — those are skipped.\n *\n * Without a resolver, each type's `block.renderedStylesheet` is emitted\n * instead: the copy the editor writes before a render provider or Cloud\n * storage sees the content. A resolver, when passed, decides every type and\n * the copies are ignored, so a stale one never overrides a live definition.\n */\n getCustomBlockStylesheet?: (customType: string) => string | undefined | null;\n /**\n * Base URL (no trailing slash) for the social icon PNG assets. Resolved to\n * `${baseUrl}/${style}/${platform}.png` per icon. Defaults to the\n * version-pinned jsDelivr mirror of this package. Override to self-host\n * (e.g., behind your own CDN or for air-gapped environments).\n *\n * Why PNGs: Outlook desktop (Word rendering engine) does not support SVG\n * and rejects base64 data URIs in `<img src>`, so social icons must be\n * served as raster images over HTTP for cross-client compatibility.\n */\n socialIconsBaseUrl?: string;\n /**\n * Embedder shell applied at render. Cloned and spliced around `content`\n * via `applyLayout`; `content` is not mutated. Omitted, the document is\n * rendered as authored and must not contain `slot` or `wrapper`.\n */\n layout?: TemplateContent;\n}\n\n/**\n * Makes a full-width button's whole fill clickable. MJML sizes a button's `<a>`\n * only for a px width, so without this rule the link of a `100%` button stays\n * the size of its label.\n *\n * It sits in the inline `<mj-style>` so `mjml`'s juice pass writes it onto the\n * `<a>`; MRML's default build emits that block as a plain `<style>` instead.\n * `!important` lets it beat MJML's inline `display:inline-block` either way.\n * Every template carries it, so nothing has to walk the tree for full-width\n * buttons: juice drops a rule that matches nothing, so with `mjml` it costs\n * nothing in the compiled HTML.\n */\nconst BUTTON_FULL_WIDTH_RULE = `.${BUTTON_FULL_WIDTH_CSS_CLASS} a { display: block !important; }`;\n\n/**\n * Render template content to an MJML string.\n *\n * The function is async because resolving custom blocks may require\n * asynchronous work (e.g., the editor's liquid renderer dynamically imports\n * `liquidjs`). When the content has no custom blocks or `renderCustomBlock`\n * is omitted, no async work is performed but the function still resolves\n * synchronously — i.e., it always returns a Promise.\n */\nexport async function renderToMjml(\n content: TemplateContent,\n options?: RenderOptions,\n): Promise<string> {\n const toRender = options?.layout\n ? applyLayout(options.layout, content)\n : (assertNoSlotInContent(content),\n assertNoWrapperInContent(content),\n content);\n\n const customFonts = options?.customFonts ?? [];\n const defaultFallbackFont =\n options?.defaultFallbackFont ?? \"Arial, sans-serif\";\n const allowHtmlBlocks = options?.allowHtmlBlocks ?? true;\n const socialIconsBaseUrl = stripTrailingSlash(\n options?.socialIconsBaseUrl ?? DEFAULT_SOCIAL_ICONS_BASE_URL,\n );\n\n const customBlockHtml = await resolveCustomBlocks(\n toRender,\n options?.renderCustomBlock,\n );\n\n const customBlockStylesheets = collectCustomBlockStylesheets(\n toRender,\n options?.getCustomBlockStylesheet,\n );\n\n const contentDirection = resolveContentDirection(toRender.settings);\n\n const renderContext = new RenderContext(\n toRender.settings.width,\n customFonts,\n defaultFallbackFont,\n allowHtmlBlocks,\n customBlockHtml,\n socialIconsBaseUrl,\n options?.blockRenderers ?? {},\n contentDirection,\n );\n\n const blocks = filterHtmlBlocks(toRender.blocks, allowHtmlBlocks);\n const fontFamily = renderContext.resolveFontFamily(\n toRender.settings.fontFamily,\n );\n const backgroundColor = toRender.settings.backgroundColor;\n // Document-level default text color → the `<mj-text>` default below. Blocks\n // that set their own color (e.g. Title) or carry inline text-color marks\n // override it. Omitted when unset so existing templates render identically.\n const textColorAttr = toRender.settings.textColor\n ? ` color=\"${escapeAttr(toRender.settings.textColor)}\"`\n : \"\";\n // Document-level link styling → the global `a { … }` rule below, cascading to\n // every link (rich-text and menu). An unset `linkColor` keeps `color: inherit`\n // so links follow the text color and legacy content renders identically; a\n // per-link/per-item color still overrides (inline styles beat this rule).\n const linkColor = toRender.settings.linkColor\n ? escapeCssValue(toRender.settings.linkColor)\n : \"inherit\";\n const linkDecoration = toRender.settings.linkUnderline ? \"underline\" : \"none\";\n\n const bodyContent = blocks\n .map((block) => renderTopLevelBlock(block, renderContext))\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n const fontDeclarations = generateFontDeclarations(customFonts);\n const previewTag = generatePreviewTag(toRender.settings.preheaderText);\n\n const lang = escapeAttr(toRender.settings.locale);\n const dir = escapeAttr(contentDirection);\n\n return `<mjml lang=\"${lang}\" dir=\"${dir}\">\n <mj-head>${previewTag}\n <mj-attributes>\n <mj-all font-family=\"${escapeFontFamily(fontFamily)}\" />\n <mj-text font-size=\"14px\"${textColorAttr} />\n <mj-section padding=\"0\" />\n <mj-column padding=\"0\" />\n </mj-attributes>${fontDeclarations}\n <mj-style inline=\"inline\">\n ${richTextStylesheet(collectParagraphGaps(blocks), contentDirection)}\n ${BUTTON_FULL_WIDTH_RULE}\n </mj-style>\n <mj-style>\n a { color: ${linkColor}; text-decoration: ${linkDecoration}; }\n @media only screen and (max-width: 480px) {\n .tpl-hide-mobile { display: none !important; mso-hide: all !important; }\n }\n @media only screen and (min-width: 481px) {\n .tpl-hide-desktop { display: none !important; mso-hide: all !important; }\n }\n </mj-style>${renderCustomBlockStylesheets(customBlockStylesheets)}\n </mj-head>\n <mj-body width=\"${renderContext.containerWidth}px\" background-color=\"${backgroundColor}\">\n${bodyContent}\n </mj-body>\n</mjml>`;\n}\n\n/**\n * Render a top-level block. Wrappers emit `mj-wrapper` around their children.\n * Sections are rendered directly; other blocks are wrapped in a default\n * section/column.\n */\nfunction renderTopLevelBlock(block: Block, context: RenderContext): string {\n if (isWrapper(block)) {\n const innerContext = insideWrapper(context, block.styles.padding);\n const inner = filterHtmlBlocks(block.children, context.allowHtmlBlocks)\n .map((child) => renderTopLevelBlock(child, innerContext))\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n const framed = renderMjWrapper(\n inner,\n {\n backgroundColor: block.styles.backgroundColor,\n padding: block.styles.padding,\n borderRadius: block.borderRadius,\n backgroundImage: block.backgroundImage,\n },\n context.contentDirection,\n );\n return wrapWithDisplayCondition(block, framed);\n }\n\n if (isSection(block)) {\n const rendered = renderBlock(\n block,\n block.wrapper ? insideWrapper(context, block.wrapper.padding) : context,\n );\n // An empty render (hidden section) stays empty — never emit a bare wrapper.\n const framed =\n block.wrapper && rendered !== \"\"\n ? renderMjWrapper(rendered, block.wrapper, context.contentDirection)\n : rendered;\n return wrapWithDisplayCondition(block, framed);\n }\n\n const content = renderBlock(block, context);\n const wrapped = wrapInSection(content, context.contentDirection);\n return wrapWithDisplayCondition(block, wrapped);\n}\n\n/**\n * The context for what an `mj-wrapper` holds: MJML narrows its children by the\n * wrapper's side padding. `containerWidth` stays the nominal share of the body.\n */\nfunction insideWrapper(\n context: RenderContext,\n padding: SpacingValue | undefined,\n): RenderContext {\n return context.withContainerWidth(\n context.containerWidth,\n Math.floor(context.contentWidth) - horizontalInset(padding),\n );\n}\n\n/**\n * `mj-wrapper` attributes shared by a layout `wrapper` block and\n * `section.wrapper`. Padding is always explicit: MJML's wrapper default is\n * `20px 0`, ours is 0. Direction is explicit for the same reason: MJML's\n * default `ltr` would otherwise be inlined on the band of an RTL email.\n */\nfunction renderMjWrapper(\n inner: string,\n wrapper: SectionWrapper,\n direction: ContentDirection,\n): string {\n const bg = bgAttr(wrapper.backgroundColor, \"native\");\n const bgImage = backgroundImageAttrs(wrapper.backgroundImage);\n const padding = ` padding=\"${\n wrapper.padding ? toPaddingString(wrapper.padding) : \"0\"\n }\"`;\n const radius = borderRadiusAttr(wrapper.borderRadius);\n const dirAttr = direction === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n return `<mj-wrapper${bg}${bgImage}${padding}${radius}${dirAttr}>\n${inner}\n</mj-wrapper>`;\n}\n\n/**\n * Wrap block content in a default mj-section/mj-column for non-section blocks.\n */\nfunction wrapInSection(content: string, direction: ContentDirection): string {\n if (content === \"\") {\n return \"\";\n }\n\n const dirAttr = direction === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n return `<mj-section${dirAttr}>\n <mj-column${dirAttr}>\n${content}\n </mj-column>\n</mj-section>`;\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nfunction generatePreviewTag(preheaderText?: string): string {\n if (!preheaderText) {\n return \"\";\n }\n\n const trimmed = preheaderText.trim();\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n const escaped = escapeHtml(trimmed);\n\n return `\\n <mj-preview>${escaped}</mj-preview>`;\n}\n\nfunction generateFontDeclarations(customFonts: CustomFont[]): string {\n if (customFonts.length === 0) {\n return \"\";\n }\n\n return customFonts\n .map(\n (font) =>\n `\\n <mj-font name=\"${escapeAttr(font.name)}\" href=\"${escapeAttr(font.url)}\" />`,\n )\n .join(\"\");\n}\n\n/**\n * Filter out HTML blocks if they are not allowed.\n */\nfunction filterHtmlBlocks(blocks: Block[], allowHtmlBlocks: boolean): Block[] {\n if (allowHtmlBlocks) {\n return blocks;\n }\n\n return blocks.filter((block) => block.type !== \"html\");\n}\n\n/**\n * Walk the content tree, collect every custom block, then resolve each in\n * parallel via the supplied callback. Returns a map keyed by block id that\n * the synchronous render pass reads from. If no callback is provided, returns\n * an empty map and the sync pass falls back to `block.renderedHtml`.\n *\n * Per-block failures bubble up — the caller decides whether to swallow or\n * rethrow. We don't replace failures with placeholders here because that's\n * a policy decision (the editor swallows; a strict CLI may want to fail).\n */\nasync function resolveCustomBlocks(\n content: TemplateContent,\n renderCustomBlock: RenderOptions[\"renderCustomBlock\"],\n): Promise<Map<string, string>> {\n const result = new Map<string, string>();\n\n if (!renderCustomBlock) {\n return result;\n }\n\n const customBlocks: CustomBlock[] = [];\n collectCustomBlocks(content.blocks, customBlocks);\n\n if (customBlocks.length === 0) {\n return result;\n }\n\n const rendered = await Promise.all(\n customBlocks.map((block) => renderCustomBlock(block)),\n );\n\n for (let index = 0; index < customBlocks.length; index++) {\n result.set(customBlocks[index].id, rendered[index]);\n }\n\n return result;\n}\n\nfunction collectCustomBlocks(blocks: Block[], out: CustomBlock[]): void {\n for (const block of blocks) {\n if (isCustomBlock(block)) {\n out.push(block);\n continue;\n }\n\n if (isSection(block)) {\n for (const column of block.children) {\n collectCustomBlocks(column, out);\n }\n } else if (isWrapper(block)) {\n collectCustomBlocks(block.children, out);\n }\n }\n}\n\n/**\n * Walk the content tree, find every unique `customType`, ask the consumer's\n * resolver for that definition's stylesheet (or, with no resolver, take the\n * first `renderedStylesheet` a block of that type carries), and return the\n * non-empty, content-deduped set in insertion order.\n *\n * Content-level dedupe (not just by customType) means two definitions that\n * happen to ship the same stylesheet string emit it only once — cheap and\n * matches the \"one rule, emitted once\" mental model. Whitespace-only and\n * empty stylesheets are skipped.\n */\nfunction collectCustomBlockStylesheets(\n content: TemplateContent,\n resolver: RenderOptions[\"getCustomBlockStylesheet\"],\n): string[] {\n const customBlocks: CustomBlock[] = [];\n collectCustomBlocks(content.blocks, customBlocks);\n\n if (customBlocks.length === 0) {\n return [];\n }\n\n // Without a resolver, the first copy each type carries stands in for it.\n const copies = new Map<string, string>();\n if (!resolver) {\n for (const block of customBlocks) {\n if (block.renderedStylesheet && !copies.has(block.customType)) {\n copies.set(block.customType, block.renderedStylesheet);\n }\n }\n }\n\n const seenTypes = new Set<string>();\n const seenContent = new Set<string>();\n const stylesheets: string[] = [];\n\n for (const block of customBlocks) {\n if (seenTypes.has(block.customType)) {\n continue;\n }\n seenTypes.add(block.customType);\n\n const css = resolver\n ? resolver(block.customType)\n : copies.get(block.customType);\n if (!css) {\n continue;\n }\n\n const trimmed = css.trim();\n if (trimmed === \"\" || seenContent.has(trimmed)) {\n continue;\n }\n seenContent.add(trimmed);\n stylesheets.push(trimmed);\n }\n\n return stylesheets;\n}\n\nfunction renderCustomBlockStylesheets(stylesheets: string[]): string {\n if (stylesheets.length === 0) {\n return \"\";\n }\n\n // One `<mj-style>` per unique stylesheet so per-definition CSS can be\n // independently inspected in the rendered MJML, and authors can grep their\n // contribution without disentangling a merged blob.\n return stylesheets\n .map((css) => `\\n <mj-style>\\n${css}\\n </mj-style>`)\n .join(\"\");\n}\n\n// Re-export utilities for consumers\nexport { RenderContext } from \"./render-context\";\nexport { escapeHtml, escapeAttr, convertMergeTagsToValues } from \"./escape\";\nexport { isHiddenOnAll, getCssClassAttr, getCssClasses } from \"./visibility\";\n// Exported for `blockRenderers` consumers replacing the paragraph or title\n// renderer: without both classes on their `mj-text`, their block silently\n// loses the spacing rules and drifts back to MJML's 13px.\nexport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"./rich-text\";\n// Exported for `blockRenderers` consumers replacing the button renderer: a\n// full-width button whose `mj-button` lacks this class is clickable only on\n// its label.\nexport { BUTTON_FULL_WIDTH_CSS_CLASS } from \"./renderers/button\";\n// Exported for `blockRenderers` consumers that emit their own `mj-image` (a\n// video thumbnail, a countdown GIF): `fluid-on-mobile` is set per image, so an\n// `mj-image` without it keeps its desktop width on a phone.\nexport { fluidOnMobileAttr } from \"./utils\";\nexport { getWidthPercentages, getWidthPixels } from \"./columns\";\nexport { toPaddingString } from \"./padding\";\nexport { DEFAULT_SOCIAL_ICONS_BASE_URL } from \"./render-context\";\nexport { renderBlock } from \"./renderers\";\nexport {\n renderUnrenderableBlock,\n UNRENDERABLE_MARKER_PREFIX,\n} from \"./unrenderable\";\nexport type { BlockRenderer, BlockRendererMap } from \"./render-context\";\n"],"mappings":";;;AC6BA,MAAa,gCAAgC;;;;AAK7C,IAAa,gBAAb,MAAa,cAAc;CAgBP;CACA;CACA;CACA;CAMA;CAQA;CAKA;CAMA;;;;;;;;CApClB;CAEA,YAME,gBACA,aACA,qBACA,iBAMA,kCAA+D,IAAI,IAAI,GAQvE,qBAA6C,+BAK7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YACJ,KAAK,QAAQ,qBAAqB,IAAI,kBAAkB,CAAC,CACzD,KAAK,EAAE;AACZ"}
1
+ {"version":3,"file":"index.js","names":["pkg.version","renderFontFamilyAttr","renderFontFamilyAttr","renderFontFamilyAttr","filterHtmlBlocks"],"sources":["../package.json","../src/render-context.ts","../src/visibility.ts","../src/unrenderable.ts","../src/escape.ts","../src/padding.ts","../src/utils.ts","../src/rich-text.ts","../src/renderers/title.ts","../src/renderers/paragraph.ts","../src/renderers/image.ts","../src/renderers/button.ts","../src/renderers/divider.ts","../src/renderers/spacer.ts","../src/renderers/html.ts","../src/renderers/social.ts","../src/renderers/menu.ts","../src/renderers/table.ts","../src/renderers/custom.ts","../src/columns.ts","../src/hero-geometry.ts","../src/display-condition.ts","../src/renderers/section.ts","../src/renderers/video.ts","../src/renderers/index.ts","../src/index.ts"],"sourcesContent":["","import type {\n Block,\n BlockType,\n ContentDirection,\n CustomFont,\n} from \"@templatical/types\";\nimport { resolveFontStack } from \"@templatical/types\";\nimport pkg from \"../package.json\" with { type: \"json\" };\n\n/**\n * A function type that renders a single block to MJML markup.\n */\nexport type BlockRenderer = (block: Block, context: RenderContext) => string;\n\n/**\n * Per-block-type renderer overrides, keyed by `block.type`. An entry replaces the\n * built-in renderer for that type wholesale — including its hidden-on-all-\n * viewports check, which becomes the override's responsibility.\n *\n * Generalises `renderCustomBlock`, which is the same idea for one block type. Its\n * reason to exist is that Templatical Cloud's render output is a deliberate\n * *superset*: countdown blocks resolve to a server-generated animated GIF and\n * video thumbnails get a composited play button, neither of which a browser can\n * do at render time. With this hook Cloud's renderer is the published one plus\n * two injected functions, so parity for every other block type holds by\n * construction instead of by review.\n */\nexport type BlockRendererMap = Partial<Record<BlockType, BlockRenderer>>;\n\nexport const DEFAULT_SOCIAL_ICONS_BASE_URL = `https://cdn.jsdelivr.net/npm/@templatical/renderer@${pkg.version}/assets/social`;\n\n/**\n * Immutable context passed through the block rendering chain.\n */\nexport class RenderContext {\n /**\n * The whole pixels MJML gives this container's content: the body width less\n * the side padding and border of every wrapper and section around it, then\n * the column's own percentage of what is left, floored as MJML floors it.\n * Width-aware decisions read this one, since it is the box MJML caps a block\n * at. Defaults to `containerWidth`.\n */\n public readonly contentWidth: number;\n\n constructor(\n /**\n * The column's share of the body width, ignoring any padding or border\n * around it. Emitted as the pixel width of a `\"full\"` image or video, which\n * MJML then caps at the real box ({@link contentWidth}).\n */\n public readonly containerWidth: number,\n public readonly customFonts: CustomFont[],\n public readonly defaultFallbackFont: string,\n public readonly allowHtmlBlocks: boolean,\n /**\n * Map of custom block id → pre-rendered HTML, populated by `renderToMjml`\n * before the synchronous render pass. Set when the consumer provides a\n * `renderCustomBlock` option. Empty by default.\n */\n public readonly customBlockHtml: ReadonlyMap<string, string> = new Map(),\n /**\n * Base URL (no trailing slash) for the social icon PNG assets. Resolved to\n * `${baseUrl}/${style}/${platform}.png`. Outlook desktop has no SVG support\n * and rejects base64 data URIs in `<img src>`, so PNGs must be served over\n * HTTP. Default points at the version-pinned jsDelivr mirror of this\n * package; consumers can override to self-host.\n */\n public readonly socialIconsBaseUrl: string = DEFAULT_SOCIAL_ICONS_BASE_URL,\n /**\n * Per-block-type renderer overrides from `RenderOptions.blockRenderers`.\n * Consulted before every built-in renderer — see {@link BlockRendererMap}.\n */\n public readonly blockRenderers: BlockRendererMap = {},\n /**\n * Writing direction of the email, resolved once in `renderToMjml`.\n * Nested columns copy it via `withContainerWidth` — dropping it there\n * would leave a two-column RTL section rendering LTR inside the columns.\n */\n public readonly contentDirection: ContentDirection = \"ltr\",\n contentWidth?: number,\n ) {\n this.contentWidth = contentWidth ?? containerWidth;\n }\n\n /**\n * Create a new context with a different container width. Used when rendering\n * columns, and wrappers, whose content is narrower. `contentWidth` defaults\n * to `width`, a container with nothing around it.\n */\n withContainerWidth(\n width: number,\n contentWidth: number = width,\n ): RenderContext {\n return new RenderContext(\n width,\n this.customFonts,\n this.defaultFallbackFont,\n this.allowHtmlBlocks,\n this.customBlockHtml,\n this.socialIconsBaseUrl,\n this.blockRenderers,\n this.contentDirection,\n contentWidth,\n );\n }\n\n /**\n * The stack to emit for a block's or the template's `fontFamily`. A stack is\n * the author's own fallback chain and is emitted as written, as is anything\n * that doesn't parse as a font. A lone family gets a fallback: a custom\n * font's own `fallback` (or `defaultFallbackFont`), a built-in's fixed stack,\n * or, for any other family, `defaultFallbackFont`, so a client without the\n * face falls back to it rather than to its own default (Times New Roman in\n * Outlook on Windows). A generic family needs nothing appended.\n *\n * The rule is {@link resolveFontStack}, shared with the editor canvas so a\n * font previews with the fallbacks the recipient gets.\n */\n resolveFontFamily(fontFamily: string): string {\n return resolveFontStack(fontFamily, {\n customFonts: this.customFonts,\n defaultFallback: this.defaultFallbackFont,\n });\n }\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Check if a block is hidden on all viewports.\n */\nexport function isHiddenOnAll(block: Block): boolean {\n const visibility = block.visibility;\n\n if (!visibility) {\n return false;\n }\n\n return !visibility.desktop && !visibility.mobile;\n}\n\n/**\n * Get the MJML css-class attribute string for a block.\n * Returns a string like ` css-class=\"tpl-hide-desktop\"` or empty string.\n *\n * `extraClasses` are appended to the visibility classes on the *same*\n * attribute. MJML keeps only one `css-class` per element, so a caller needing\n * both must merge here rather than emitting a second attribute.\n */\nexport function getCssClassAttr(\n block: Block,\n extraClasses: string[] = [],\n): string {\n const classes = [getCssClasses(block), ...extraClasses]\n .filter((entry) => entry !== \"\")\n .join(\" \");\n\n if (classes === \"\") {\n return \"\";\n }\n\n return ` css-class=\"${classes}\"`;\n}\n\n/**\n * Get the CSS classes for visibility hiding.\n */\nexport function getCssClasses(block: Block): string {\n const visibility = block.visibility;\n\n if (!visibility) {\n return \"\";\n }\n\n const classes: string[] = [];\n\n if (!visibility.desktop) {\n classes.push(\"tpl-hide-desktop\");\n }\n\n if (!visibility.mobile) {\n classes.push(\"tpl-hide-mobile\");\n }\n\n return classes.join(\" \");\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Prefix every unrenderable-block marker carries. Stable and greppable on\n * purpose: it is what a consumer searches for after noticing a gap in a rendered\n * email, and what a send pipeline can scan for before shipping.\n */\nexport const UNRENDERABLE_MARKER_PREFIX = \"templatical:unrenderable-block\";\n\n/**\n * Strip anything that would terminate or nest an HTML comment. `-->` and `--!>`\n * inside the marker would close it early and leak the rest as body text; a lone\n * `--` is enough to make the comment non-conforming, so both collapse.\n *\n * Brackets go **before** hyphens collapse, and the order is load-bearing.\n * Removing `<` from `-<-` brings two hyphens together that a collapse pass has\n * already walked past, so collapsing first leaves a `--` behind — the sanitizer\n * reintroducing the sequence it exists to remove.\n */\nfunction commentSafe(value: string): string {\n return value.replace(/[<>]/g, \"\").replace(/-{2,}/g, \"-\");\n}\n\n/**\n * Emit the placeholder for a block no renderer can handle — no built-in renderer\n * and no `blockRenderers` override for its type.\n *\n * **A marker, not a throw and not silence.** The renderer runs inside send\n * pipelines, so killing an entire render over one block is worse than shipping a\n * marked gap. Silence is worse still: a block that simply vanishes reaches\n * recipients as a missing section with nothing anywhere explaining why. The rule\n * is general rather than countdown-specific, so\n * a block type added to `@templatical/types` before its renderer lands degrades\n * the same way.\n *\n * `mj-raw` is used because it is the one element that passes its content through\n * verbatim and is valid everywhere a block renders — inside `mj-column`, which is\n * where every non-section block ends up.\n */\nexport function renderUnrenderableBlock(block: Block): string {\n console.warn(\n `[Templatical] No renderer for block type \"${block.type}\" (id: ${block.id}). ` +\n \"A placeholder comment was emitted in its place. Pass a `blockRenderers` \" +\n \"entry for this type to render it.\",\n );\n\n const type = commentSafe(block.type);\n const id = commentSafe(block.id);\n\n return `<mj-raw><!-- ${UNRENDERABLE_MARKER_PREFIX} type=\"${type}\" id=\"${id}\" --></mj-raw>`;\n}\n","import { findOpenTagEnd, getTagAttrValue } from \"@templatical/types\";\n\nconst HTML_ENTITIES: Record<string, string> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n '\"': \"&quot;\",\n \"'\": \"&#039;\",\n};\n\nconst HTML_ENTITY_REGEX = /[&<>\"']/g;\n\n/**\n * Escape HTML special characters (& < > \" ').\n * Equivalent to PHP htmlspecialchars with ENT_QUOTES | ENT_HTML5.\n */\nexport function escapeHtml(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n\n return text.replace(HTML_ENTITY_REGEX, (char) => HTML_ENTITIES[char] ?? char);\n}\n\n/**\n * Escape a string for use in an HTML attribute value.\n * Same implementation as escapeHtml for consistency with PHP.\n */\nexport function escapeAttr(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n\n return text.replace(HTML_ENTITY_REGEX, (char) => HTML_ENTITIES[char] ?? char);\n}\n\n/**\n * Escape a string for use as a CSS property value inside an inline\n * `style=\"prop: ${value}\"` attribute. Beyond HTML entity escaping (so the\n * value survives the attribute boundary), this strips characters that\n * could break out of the property value into a sibling property:\n *\n * `;` — separates CSS declarations\n * `{`/`}` — opens/closes a CSS rule (rejected by attribute parsers but\n * still safer to remove)\n * `\\n`/`\\r` — would smuggle past line-based CSS sanitizers\n *\n * Without this, an attacker-controlled color like\n * `\"red; background: url('//attacker/log')\"` lands as a real CSS rule.\n */\nexport function escapeCssValue(text: string): string {\n if (text === \"\") {\n return \"\";\n }\n return escapeAttr(text).replace(/[;{}\\r\\n]/g, \"\");\n}\n\nconst FONT_FAMILY_ENTITY_REGEX = /[&<>\"]/g;\n\n/**\n * Escape a font stack for a double-quoted `font-family=\"…\"` MJML attribute.\n * A `\"`-quoted family (`\"Helvetica Neue\", Arial`) must not end the attribute,\n * or the compiler reads it as empty. Unlike `escapeAttr`, single quotes are\n * left alone: they can't end a double-quoted attribute, and they're how the\n * renderer quotes families itself (`'Times New Roman', serif`), so every\n * stack without `&<>\"` is emitted byte-for-byte.\n */\nexport function escapeFontFamily(text: string): string {\n return text.replace(\n FONT_FAMILY_ENTITY_REGEX,\n (char) => HTML_ENTITIES[char] ?? char,\n );\n}\n\n/**\n * Replace merge tag span elements with their data attribute values.\n * Converts `<span data-merge-tag=\"{{name}}\">Label</span>` to `{{name}}`.\n * Also handles `data-logic-merge-tag` attributes.\n *\n * Uses a single-pass linear scan instead of an `[^>]*…[^>]*` regex because\n * the latter is polynomial-ReDoS over inputs that contain many `<span`\n * starts but no closing `>` — the engine retries `[^>]*` at every span\n * position. The scan below resolves each `<span>` open tag with a bounded,\n * quote-aware `findOpenTagEnd`, keeping the work strictly O(n).\n */\nexport function convertMergeTagsToValues(html: string): string {\n if (html === \"\") {\n return \"\";\n }\n\n return rewriteMergeTagSpans(\n html,\n (attrs) =>\n findAttr(attrs, \"data-merge-tag\") ??\n findAttr(attrs, \"data-logic-merge-tag\"),\n );\n}\n\n/**\n * Walk `html`, find every `<span …>…</span>`, and replace the entire span\n * with whatever `extract` returns for its attribute string (or leave it\n * alone if `extract` returns `null`). Linear in the length of `html`:\n * every `indexOf` advances the cursor monotonically.\n */\nfunction rewriteMergeTagSpans(\n html: string,\n extract: (attrs: string) => string | null,\n): string {\n let out = \"\";\n let i = 0;\n while (i < html.length) {\n const open = html.indexOf(\"<span\", i);\n if (open === -1) {\n out += html.substring(i);\n break;\n }\n // `<span` must be followed by `>` or whitespace to be a real opening tag.\n const afterTagName = html[open + 5];\n if (\n afterTagName !== \">\" &&\n afterTagName !== \" \" &&\n afterTagName !== \"\\t\" &&\n afterTagName !== \"\\n\" &&\n afterTagName !== \"\\r\" &&\n afterTagName !== \"/\"\n ) {\n out += html.substring(i, open + 5);\n i = open + 5;\n continue;\n }\n const openEnd = findOpenTagEnd(html, open + 5);\n if (openEnd === -1) {\n out += html.substring(i);\n break;\n }\n const closeStart = html.indexOf(\"</span>\", openEnd + 1);\n if (closeStart === -1) {\n out += html.substring(i);\n break;\n }\n const attrs = html.substring(open + 5, openEnd);\n const replacement = extract(attrs);\n if (replacement === null) {\n // This `<span>` isn't a merge-tag — emit up to and including the\n // `<span` literal and let the next iteration scan inward, so any\n // nested merge-tag span still gets a chance to match.\n out += html.substring(i, open + 5);\n i = open + 5;\n continue;\n }\n out += html.substring(i, open);\n out += replacement;\n i = closeStart + 7;\n }\n return out;\n}\n\n/**\n * Extract the value of `name=\"…\"` from an HTML attribute string, or `null`\n * if absent.\n *\n * Delegates to `@templatical/types` so the editor's preview rewriter and this\n * export rewriter read markup identically. They were separate regexes once, and\n * both excluded `<` / `>` from the value — which silently left the whole span\n * in the rendered MJML whenever a consumer configured a merge-tag syntax whose\n * values contain those characters (`<% $email %>`), so the ESP never received\n * the token.\n */\nfunction findAttr(attrs: string, name: string): string | null {\n return getTagAttrValue(attrs, name);\n}\n","import type { SpacingValue } from \"@templatical/types\";\n\n/**\n * Convert a SpacingValue to a CSS padding string like \"10px 10px 10px 10px\".\n */\nexport function toPaddingString(padding: SpacingValue): string {\n return `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px`;\n}\n","/**\n * MJML attribute helpers — single source of truth for placement rules\n * that the MJML spec enforces but accepts silently when violated.\n *\n * MJML drops unrecognized attributes without error. The most common trap is\n * background placement: only `mj-section`, `mj-button`, `mj-wrapper`, `mj-hero`\n * accept the native `background-color` attribute. Inner content elements\n * (`mj-text`, `mj-image`, `mj-table`, `mj-navbar`, `mj-video`) require\n * `container-background-color`, which paints the enclosing `<td>`. Passing\n * `background-color` to an inner element results in the attribute being\n * silently dropped — the email ships without the bg.\n *\n * https://documentation.mjml.io/\n */\n\nimport type {\n BackgroundImage,\n BorderRadiusValue,\n BorderValue,\n ImageBlock,\n SpacingValue,\n} from \"@templatical/types\";\nimport {\n resolveBackgroundImage,\n toBorderCss,\n toBorderDeclarations,\n toBorderRadiusCss,\n} from \"@templatical/types\";\nimport { escapeAttr, escapeCssValue } from \"./escape\";\nimport type { RenderContext } from \"./render-context\";\n\n/**\n * Where the MJML element accepts a background-color attribute.\n * - `native`: the element has its own `background-color` (mj-section, mj-button).\n * - `container`: the element only accepts `container-background-color`,\n * which colors the wrapping `<td>` (mj-text, mj-image, mj-table, mj-navbar, mj-video).\n */\nexport type BgPlacement = \"native\" | \"container\";\n\n/**\n * Render the appropriate background-color attribute for an MJML element.\n * Returns an empty string when no color is set, or a leading-space attribute\n * fragment ready to interpolate into a tag's attribute list.\n */\nexport function bgAttr(\n backgroundColor: string | undefined,\n placement: BgPlacement,\n): string {\n if (!backgroundColor) {\n return \"\";\n }\n\n const name =\n placement === \"native\" ? \"background-color\" : \"container-background-color\";\n\n return ` ${name}=\"${backgroundColor}\"`;\n}\n\n/**\n * Render `mj-image`'s height attribute. Returns an empty string when no height\n * is set, so MJML applies its own `auto` and the image keeps its aspect ratio.\n *\n * The px suffix is not cosmetic: `height` is a Unit attribute accepting only\n * `px` or `auto`, so a bare number is a validation error and MJML drops it.\n * Non-finite or non-positive values are treated as unset — a `0` here would\n * collapse the image rather than express \"no opinion\".\n */\nexport function heightAttr(height: number | undefined): string {\n if (typeof height !== \"number\" || !Number.isFinite(height) || height <= 0) {\n return \"\";\n }\n\n return ` height=\"${height}px\"`;\n}\n\n/**\n * The width an element's side padding and drawn side borders take from its\n * box. MJML subtracts exactly these when it sizes a wrapper's, a section's or\n * an image's content, so a side `toBorderCss` would not draw counts for 0.\n * MJML reads each side as a whole pixel (`parseInt` in its `shorthandParser`\n * and `borderParser`), so 20.5px of padding takes 20px and a 2.5px border 2px.\n */\nexport function horizontalInset(\n padding: SpacingValue | undefined,\n border?: BorderValue,\n): number {\n const whole = (value: number | undefined) => Math.trunc(value ?? 0);\n const drawn = (side: BorderValue[\"left\"] | undefined) =>\n toBorderCss(side) === null ? 0 : Math.trunc(side!.width);\n return (\n whole(padding?.left) +\n whole(padding?.right) +\n drawn(border?.left) +\n drawn(border?.right)\n );\n}\n\n/**\n * `fluid-on-mobile` for an `mj-image`, set only on an image that fills its\n * column on desktop: `\"full\"`, or a pixel width MJML caps at the room it gives\n * the image (the column less the image's own side padding and border). On a\n * phone the attribute widens the image to the stacked column, so an image set\n * narrower must not carry it: a 120px logo would grow to the whole column, and\n * one with a set height would stretch out of shape. An image wider than the\n * phone shrinks to fit without it.\n *\n * Exported for `blockRenderers` entries that emit their own `mj-image`. Pass\n * the context the renderer received, whose `contentWidth` already excludes the\n * wrappers and sections around the column.\n */\nexport function fluidOnMobileAttr(\n block: Pick<ImageBlock, \"width\" | \"styles\" | \"border\">,\n context: RenderContext,\n): string {\n const room =\n Math.floor(context.contentWidth) -\n horizontalInset(block.styles.padding, block.border);\n return block.width === \"full\" || block.width >= room\n ? ' fluid-on-mobile=\"true\"'\n : \"\";\n}\n\n/**\n * Render the border attributes for the MJML elements that accept them natively\n * (`mj-section`, `mj-image`, `mj-button`): a single `border` when it covers all\n * four sides, otherwise one `border-<side>` per chosen side. Returns an empty\n * string when there is nothing to draw, so templates without a border render\n * exactly as before.\n *\n * MJML copies the values into an inline `style`, so they go through\n * `escapeCssValue` — a tampered color must not smuggle in a sibling\n * declaration.\n */\nexport function borderAttr(border: BorderValue | undefined): string {\n return Object.entries(toBorderDeclarations(border))\n .map(([name, value]) => ` ${name}=\"${escapeCssValue(value)}\"`)\n .join(\"\");\n}\n\n/**\n * Render the `border-radius` attribute: `\"8px\"` for matching corners, or the\n * four-value shorthand (top-left, top-right, bottom-right, bottom-left) that\n * `mj-section`, `mj-wrapper`, `mj-image` and `mj-button` all accept. Returns an\n * empty string when every corner is square, rather than a `border-radius=\"0px\"`\n * every existing template would suddenly grow.\n */\nexport function borderRadiusAttr(\n radius: BorderRadiusValue | undefined,\n): string {\n const css = toBorderRadiusCss(radius);\n\n if (css === null) {\n return \"\";\n }\n\n return ` border-radius=\"${css}\"`;\n}\n\n/**\n * Render the background-image attributes `mj-section` and `mj-wrapper` accept.\n * All four are emitted together, so MJML's own defaults (`auto`, `top center`,\n * `repeat`) never apply. Returns an empty string when there is no image.\n *\n * MJML pastes `background-url` verbatim into `url('…')` and the Outlook VML\n * `src`; `resolveBackgroundImage` has already percent-encoded the characters\n * that could end the CSS string, and `escapeAttr` keeps the attribute closed.\n */\nexport function backgroundImageAttrs(bg: BackgroundImage | undefined): string {\n const resolved = resolveBackgroundImage(bg);\n\n if (resolved === null) {\n return \"\";\n }\n\n return ` background-url=\"${escapeAttr(resolved.url)}\" background-size=\"${resolved.size}\" background-position=\"${resolved.position}\" background-repeat=\"${resolved.repeat}\"`;\n}\n","import { RICH_TEXT_SPACING, isSection, isWrapper } from \"@templatical/types\";\nimport type { Block, ContentDirection } from \"@templatical/types\";\n\n/**\n * Marks the `mj-text` of a block whose content is editor-authored rich text\n * (paragraph and title). MJML puts a `css-class` on the wrapping `<td>`, which\n * is what {@link richTextStylesheet} scopes its selectors to.\n *\n * The scope is the point. A bare `p { … }` rule would also reach an `html`\n * block — the renderer puts consumer markup in `mj-text` too — and the editor\n * previews those in a sandboxed `srcdoc` iframe on UA defaults. Styling them\n * would trade this mismatch for another one, and an inlined declaration would\n * beat the consumer's own stylesheet.\n */\nexport const RICH_TEXT_CSS_CLASS = \"tpl-rich-text\";\n\n/**\n * The class carrying one specific paragraph gap, e.g. `tpl-rich-text-8`.\n *\n * Every rich-text block gets one of these *instead of* a shared paragraph rule.\n * That is a hard constraint, not a preference: `.tpl-rich-text p` and\n * `.tpl-rich-text-4 p` have identical specificity (one class, one type), so a\n * surviving base rule would win on source order and flatten every per-block gap\n * back to the default.\n */\nexport function richTextGapClass(gap: number): string {\n return `${RICH_TEXT_CSS_CLASS}-${gap}`;\n}\n\n/**\n * The global rules that make exported rich text match the editor canvas.\n *\n * Two gaps they close, neither visible until you measure the delivered email:\n *\n * - MJML's core skeleton injects `p { display:block;margin:13px 0; }` into\n * every document. Against the canvas's paragraph gap that made a\n * three-paragraph block 99px in the editor and 135px in the inbox — 13px\n * above the first paragraph, 13px below the last, and 13px rather than 8px\n * between each (issue #616).\n * - The skeleton resets nothing for `ul` / `ol` / `li`, so those fall through\n * to each client's UA stylesheet — around 14px margin and a 40px bullet\n * indent in Chromium, against the canvas's 8px and 24px. Unlike the\n * paragraph case the value is not even a fixed constant, so matching MJML in\n * the editor could not have fixed it.\n *\n * Emitted inside `<mj-style inline=\"inline\">`, so MJML runs it through juice\n * and the declarations land as real inline styles. That matters twice: they\n * survive a client that strips `<style>` from the head, and juice resolves\n * `:last-child` structurally at build time instead of dropping it.\n *\n * One paragraph rule per *distinct* gap in the document, so a template using\n * two gaps costs two rules rather than one per block. The list values stay on\n * the unversioned class: MJML resets nothing for `ul`/`ol`/`li`, so they exist\n * to pin down client defaults rather than to be designed with.\n */\nexport function richTextStylesheet(\n gaps: number[],\n direction: ContentDirection = \"ltr\",\n): string {\n const s = RICH_TEXT_SPACING;\n const scope = `.${RICH_TEXT_CSS_CLASS}`;\n const distinct = [...new Set(gaps)].sort((a, b) => a - b);\n\n const paragraphRules = distinct.flatMap((gap) => {\n const gapScope = `.${richTextGapClass(gap)}`;\n return [\n `${gapScope} p { margin: 0 0 ${gap}px; }`,\n `${gapScope} p:last-child { margin-bottom: 0; }`,\n ];\n });\n\n // Physical sides: Outlook does not honour `padding-inline-start`.\n const listPaddingSide =\n direction === \"rtl\" ? \"padding-right\" : \"padding-left\";\n\n return [\n ...paragraphRules,\n `${scope} ul, ${scope} ol { margin: ${s.listMarginY}px 0; ${listPaddingSide}: ${s.listPaddingLeft}px; }`,\n `${scope} li { margin: ${s.listItemMarginY}px 0; }`,\n ].join(\"\\n \");\n}\n\n/**\n * The paragraph gap a block asks for, or the built-in default.\n *\n * The fallback must produce a *rule* rather than nothing: silence hands the\n * paragraph back to MJML's `p { margin: 13px 0 }` skeleton default and reopens\n * the canvas/export mismatch. `0` is a legitimate gap, so this tests for\n * absence rather than falsiness.\n *\n * Mirrored on the canvas side by `getBlockWrapperStyle` in\n * `@templatical/editor`.\n */\nexport function resolveParagraphGap(spacing: number | undefined): number {\n return spacing ?? RICH_TEXT_SPACING.paragraphGap;\n}\n\n/**\n * Every paragraph gap the document uses, so the head can carry a rule for each.\n *\n * Walks section columns and wrapper children too — a paragraph inside a column\n * or a layout card needs its rule as much as a top-level one. Titles always\n * use the default gap: their content is normally a single paragraph the\n * renderer unwraps, and the multi-paragraph case is an edge worth spacing\n * consistently rather than configuring.\n */\nexport function collectParagraphGaps(blocks: Block[]): number[] {\n const gaps: number[] = [RICH_TEXT_SPACING.paragraphGap];\n\n const visit = (block: Block): void => {\n if (block.type === \"paragraph\") {\n gaps.push(resolveParagraphGap(block.paragraphSpacing));\n }\n if (isSection(block)) {\n for (const column of block.children) {\n for (const child of column) {\n visit(child);\n }\n }\n } else if (isWrapper(block)) {\n for (const child of block.children) {\n visit(child);\n }\n }\n };\n\n for (const block of blocks) {\n visit(block);\n }\n\n return gaps;\n}\n","import type { TitleBlock } from \"@templatical/types\";\nimport {\n HEADING_LEVEL_FONT_SIZE,\n TITLE_FONT_WEIGHT,\n TITLE_LINE_HEIGHT,\n fillEmptyParagraphs,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n convertMergeTagsToValues,\n escapeAttr,\n escapeFontFamily,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"../rich-text\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a title block to MJML markup.\n */\nexport function renderTitle(block: TitleBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n // Blank lines between a title's paragraphs are filled as the canvas fills\n // them; a single paragraph is unwrapped into the heading.\n const content = unwrapParagraph(\n fillEmptyParagraphs(convertMergeTagsToValues(block.content)),\n );\n // Clamp out-of-range levels to a defined entry so we never interpolate\n // `undefined` into `font-size=\"${...}px\"` (mjml@5 rejects \"undefinedpx\").\n const fontSize =\n HEADING_LEVEL_FONT_SIZE[block.level] ?? HEADING_LEVEL_FONT_SIZE[2];\n // Emit the color only when the block sets one; otherwise the `mj-text`\n // inherits the document `textColor` default from `<mj-attributes>`.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n const align = block.textAlign;\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n // `unwrapParagraph` strips only a *single* outer `<p>`, so a title the user\n // pressed Enter in keeps its paragraphs and needs a spacing rule. Titles\n // carry no gap of their own, so they always take the default.\n const cssClassAttr = getCssClassAttr(block, [\n RICH_TEXT_CSS_CLASS,\n richTextGapClass(resolveParagraphGap(undefined)),\n ]);\n // Same clamp logic as fontSize so that an out-of-range level still\n // produces a valid heading element.\n const safeLevel = HEADING_LEVEL_FONT_SIZE[block.level] ? block.level : 2;\n const tag = `h${safeLevel}`;\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"${TITLE_LINE_HEIGHT}\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${cssClassAttr}\n><${tag} style=\"margin:0;font-size:inherit;color:inherit;line-height:inherit;font-weight:${TITLE_FONT_WEIGHT}\">${content}</${tag}></mj-text>`;\n}\n\n/**\n * The editor stores title content as a TipTap paragraph (`<p>...</p>`),\n * but the renderer wraps it in `<h${level}>`. `<p>` is invalid inside a\n * heading, so strip a single outer `<p>` wrapper if present.\n */\nfunction unwrapParagraph(html: string): string {\n const match = html.match(/^\\s*<p\\b[^>]*>([\\s\\S]*)<\\/p>\\s*$/);\n if (!match) return html;\n // Only unwrap when there is exactly one top-level <p> — otherwise the\n // content has multiple paragraphs and we must leave it alone.\n if (/<\\/p>\\s*<p\\b/i.test(match[1])) return html;\n return match[1];\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type { ParagraphBlock } from \"@templatical/types\";\nimport { fillEmptyParagraphs, isBlankRichText } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { convertMergeTagsToValues } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"../rich-text\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a paragraph block to MJML markup.\n * All text formatting is inline in the HTML content (managed by TipTap).\n */\nexport function renderParagraph(\n block: ParagraphBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n // Skip when the user has cleared the paragraph — otherwise we emit a\n // styled `<td>` cell that adds visible whitespace to the email even\n // though the canvas shows nothing for an empty paragraph.\n if (isBlankRichText(block.content)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n // The canvas fills blank lines with the same helper, so the two agree.\n const content = fillEmptyParagraphs(convertMergeTagsToValues(block.content));\n const cssClassAttr = getCssClassAttr(block, [\n RICH_TEXT_CSS_CLASS,\n richTextGapClass(resolveParagraphGap(block.paragraphSpacing)),\n ]);\n\n // RTL templates need a start-edge default on the wrapper. Inner\n // `<p style=\"text-align:…\">` from TipTap still wins per paragraph.\n const alignAttr =\n context.contentDirection === \"rtl\" ? '\\n align=\"right\"' : \"\";\n\n return `<mj-text\n line-height=\"1.5\"${alignAttr}\n padding=\"${padding}\"${bgColor}${cssClassAttr}\n>${content}</mj-text>`;\n}\n","import type { ImageBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport {\n bgAttr,\n borderAttr,\n borderRadiusAttr,\n fluidOnMobileAttr,\n heightAttr,\n} from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render an image block to MJML markup.\n */\nexport function renderImage(block: ImageBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.src === \"\") {\n // Skip rather than emit `<mj-image src=\"\">` which compiles to a\n // broken-image icon. Mirrors video.ts behavior when no source is set.\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const width =\n block.width === \"full\" ? context.containerWidth + \"px\" : block.width + \"px\";\n const height = heightAttr(block.height);\n const fluid = fluidOnMobileAttr(block, context);\n\n const visibilityAttr = getCssClassAttr(block);\n\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const borderAttrStr = borderAttr(block.border);\n\n let linkAttr = \"\";\n if (block.linkUrl) {\n linkAttr = ` href=\"${escapeAttr(block.linkUrl)}\"`;\n if (block.linkOpenInNewTab) {\n linkAttr += ' target=\"_blank\" rel=\"noopener\"';\n }\n }\n\n const src = escapeAttr(block.src);\n const decorative = block.decorative === true;\n const alt = decorative ? \"\" : escapeAttr(block.alt);\n const align = block.align;\n const roleAttr = decorative ? ' role=\"presentation\"' : \"\";\n\n return `<mj-image\n src=\"${src}\"\n alt=\"${alt}\"\n width=\"${width}\"${height}${fluid}\n align=\"${align}\"\n padding=\"${padding}\"${bgColor}${borderAttrStr}${borderRadiusAttrStr}${linkAttr}${visibilityAttr}${roleAttr}\n/>`;\n}\n","import type { ButtonBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr, escapeFontFamily, escapeHtml } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport type { BorderRadiusValue } from \"@templatical/types\";\nimport { toBorderRadiusCss } from \"@templatical/types\";\nimport { bgAttr, borderAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Marks the `mj-button` of a full-width button. MJML gives the button's `<a>`\n * a width only for a px `width`; for `100%` it widens the `<table>` and leaves\n * the `<a>` at `display:inline-block`, so only the label is clickable.\n * `renderToMjml` scopes the head rule that makes the `<a>` fill the button to\n * this class.\n */\nexport const BUTTON_FULL_WIDTH_CSS_CLASS = \"tpl-button-full\";\n\n/**\n * Render a button block to MJML markup.\n */\nexport function renderButton(\n block: ButtonBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const buttonPadding = toPaddingString(block.buttonPadding);\n\n // Omit href entirely when no URL is set so we don't emit a clickable\n // `<a href=\"\">` that navigates to whatever URL the email is opened from.\n const href = block.url === \"\" ? \"\" : escapeAttr(block.url);\n const hrefAttr = href === \"\" ? \"\" : ` href=\"${href}\"`;\n const backgroundColor = buttonBackgroundAttr(block.backgroundColor);\n const textColor = escapeAttr(block.textColor);\n const fontSize = block.fontSize;\n const borderRadius = renderButtonRadius(block.borderRadius);\n const text = escapeHtml(block.text);\n const targetAttr = block.openInNewTab\n ? ' target=\"_blank\" rel=\"noopener\"'\n : \"\";\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const widthAttr = renderWidthAttr(block.width);\n const cssClassAttr = getCssClassAttr(\n block,\n block.width === \"full\" ? [BUTTON_FULL_WIDTH_CSS_CLASS] : [],\n );\n const borderAttrStr = borderAttr(block.border);\n // Templates stored before `align` existed have no value for it. Fall back to\n // MJML's own default so they keep rendering exactly as they did.\n const align = block.align ?? \"center\";\n\n return `<mj-button${hrefAttr}${targetAttr}\n background-color=\"${backgroundColor}\"\n color=\"${textColor}\"\n font-size=\"${fontSize}px\"\n font-weight=\"bold\"\n border-radius=\"${borderRadius}\"${borderAttrStr}\n inner-padding=\"${buttonPadding}\"\n align=\"${align}\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${widthAttr}${cssClassAttr}\n>${text}</mj-button>`;\n}\n\n/**\n * MJML paints `#414141` when `background-color` is omitted, and `\"\"` is not a\n * color it accepts. An unset button fill is the keyword `transparent`.\n */\nfunction buttonBackgroundAttr(color: string): string {\n if (color.trim() === \"\") return \"transparent\";\n return escapeAttr(color);\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n\n/**\n * The button has always emitted its radius, `0px` included, so a plain number\n * keeps rendering exactly as it did. Per-corner radii go through the shared\n * formatter, with all-square corners as `0px`.\n */\nfunction renderButtonRadius(radius: BorderRadiusValue): string {\n if (typeof radius === \"number\") {\n return `${radius}px`;\n }\n\n return toBorderRadiusCss(radius) ?? \"0px\";\n}\n\nfunction renderWidthAttr(width: number | \"full\" | undefined): string {\n if (width === undefined) {\n return \"\";\n }\n\n const value = width === \"full\" ? \"100%\" : `${width}px`;\n\n return ` width=\"${value}\"`;\n}\n","import type { DividerBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a divider block to MJML markup.\n */\nexport function renderDivider(\n block: DividerBlock,\n _context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n // A percentage passes through as is: MJML takes it natively.\n const width =\n block.width === \"full\"\n ? \"100%\"\n : typeof block.width === \"number\"\n ? `${block.width}px`\n : block.width;\n const thickness = block.thickness;\n const lineStyle = block.lineStyle;\n const color = escapeAttr(block.color);\n const visibilityAttr = getCssClassAttr(block);\n\n return `<mj-divider\n border-width=\"${thickness}px\"\n border-style=\"${lineStyle}\"\n border-color=\"${color}\"\n width=\"${width}\"\n padding=\"${padding}\"${bgColor}${visibilityAttr}\n/>`;\n}\n","import type { SpacerBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a spacer block to MJML markup.\n *\n * The canvas renders a spacer at exactly `block.height` pixels and ignores\n * `block.styles.padding`. Match that here: emit `padding=\"0\"` so the\n * exported email's spacer occupies the same vertical space the user saw\n * in the editor preview. Any non-zero `block.styles.padding` on a spacer\n * is meaningless and silently dropped from the export.\n */\nexport function renderSpacer(\n block: SpacerBlock,\n _context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const height = block.height;\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n const visibilityAttr = getCssClassAttr(block);\n\n return `<mj-spacer height=\"${height}px\" padding=\"0\"${bgColor}${visibilityAttr} />`;\n}\n","import type { HtmlBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render an HTML block to MJML markup.\n * No sanitization in the OSS version -- consumers are responsible for content safety.\n */\nexport function renderHtml(block: HtmlBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (!context.allowHtmlBlocks) {\n return \"\";\n }\n\n const content = block.content;\n\n if (content === \"\") {\n return \"\";\n }\n\n const visibilityAttr = getCssClassAttr(block);\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n\n // Use mj-text to render HTML content inside proper table cell structure.\n // mj-raw bypasses MJML's table layout and content won't be visible.\n return `<mj-text padding=\"${padding}\"${bgColor}${visibilityAttr}>\n${content}\n</mj-text>`;\n}\n","import type { SocialIconsBlock } from \"@templatical/types\";\nimport { socialIconAssetDir } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a social icons block to MJML markup.\n *\n * Icons are emitted as `<img src=\"…/{dir}/{platform}.png\">` rather than\n * inline SVG or base64 data URIs. Outlook desktop (Word rendering engine)\n * does not support SVG and rejects base64 in `<img src>`, so hosted PNGs are\n * the only format that renders across every mainstream client. The base URL\n * is read from `context.socialIconsBaseUrl` (configurable via\n * `RenderOptions.socialIconsBaseUrl`; default is the version-pinned jsDelivr\n * mirror of this package). `{dir}` is the style, plus `-{tone}` for a\n * one-color tone (`socialIconAssetDir`).\n */\nexport function renderSocialIcons(\n block: SocialIconsBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const icons = block.icons;\n\n if (icons.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = block.styles.backgroundColor\n ? ` container-background-color=\"${escapeAttr(block.styles.backgroundColor)}\"`\n : \"\";\n const visibilityAttr = getCssClassAttr(block);\n const align = block.align;\n const iconSize = block.iconSize;\n const iconStyle = block.iconStyle;\n const assetDir = socialIconAssetDir(iconStyle, block.iconTone);\n const spacing = block.spacing;\n\n let iconSizePx: number;\n switch (iconSize) {\n case \"small\":\n iconSizePx = 24;\n break;\n case \"large\":\n iconSizePx = 48;\n break;\n default:\n iconSizePx = 32;\n break;\n }\n\n // MJML mj-social-element has default border-radius of 3px, override per style\n let borderRadius: string;\n switch (iconStyle) {\n case \"circle\":\n borderRadius = \"50%\";\n break;\n case \"rounded\":\n borderRadius = \"8px\";\n break;\n case \"square\":\n borderRadius = \"0\";\n break;\n default:\n borderRadius = \"4px\"; // solid, outlined, plain\n break;\n }\n\n const iconCount = icons.length;\n const socialElements = icons.map((icon, index) => {\n const platform = icon.platform;\n const url = escapeAttr(icon.url);\n const iconSrc = `${context.socialIconsBaseUrl}/${assetDir}/${platform}.png`;\n\n // Apply spacing as right padding only (except last icon) to match CSS gap behavior\n const rightPad = index === iconCount - 1 ? 0 : spacing;\n\n // Empty content hides the platform name text, matching the editor display\n return `<mj-social-element src=\"${iconSrc}\" href=\"${url}\" icon-size=\"${iconSizePx}px\" padding=\"0 ${rightPad}px 0 0\" border-radius=\"${borderRadius}\" background-color=\"transparent\"></mj-social-element>`;\n });\n\n const socialContent = socialElements.join(\"\\n\");\n\n return `<mj-social\n mode=\"horizontal\"\n align=\"${align}\"\n icon-padding=\"0\"\n padding=\"${padding}\"${bgColor}${visibilityAttr}\n>\n${socialContent}\n</mj-social>`;\n}\n","import type { MenuBlock, MenuItemData } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n escapeHtml,\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a menu block to MJML markup.\n * Uses mj-text with inline <a> tags separated by styled <span> separators.\n */\nexport function renderMenu(block: MenuBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.items.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const visibilityAttr = getCssClassAttr(block);\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const align = block.textAlign;\n const fontSize = block.fontSize;\n // Emit the color only when set; otherwise the `mj-text` inherits the\n // document `textColor` and the item anchors below inherit it in turn.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n\n const content = renderMenuItems(block);\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"1.5\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${visibilityAttr}\n>${content}</mj-text>`;\n}\n\nfunction renderMenuItems(block: MenuBlock): string {\n const items = block.items;\n const separator = escapeHtml(block.separator);\n const separatorColor = escapeCssValue(block.separatorColor);\n const spacing = block.spacing;\n const linkColor = block.linkColor ?? block.color;\n\n const parts: string[] = [];\n const itemCount = items.length;\n\n for (let index = 0; index < itemCount; index++) {\n parts.push(renderMenuItem(items[index], linkColor));\n\n if (index < itemCount - 1) {\n parts.push(\n `<span style=\"color: ${separatorColor}; padding: 0 ${spacing}px;\">${separator}</span>`,\n );\n }\n }\n\n return parts.join(\"\");\n}\n\nfunction renderMenuItem(\n item: MenuItemData,\n linkColor: string | undefined,\n): string {\n const text = escapeHtml(item.text);\n const url = escapeAttr(item.url);\n // Item color, else the menu link color; when neither is set the anchor omits\n // an explicit color and inherits the mj-text color (the document `textColor`).\n const resolvedColor = item.color ?? linkColor;\n const target = item.openInNewTab ? ' target=\"_blank\" rel=\"noopener\"' : \"\";\n\n const styles: string[] = [\"text-decoration: none\"];\n\n if (resolvedColor) {\n styles.unshift(`color: ${escapeCssValue(resolvedColor)}`);\n }\n\n if (item.bold) {\n styles.push(\"font-weight: bold\");\n }\n\n if (item.underline) {\n styles.push(\"text-decoration: underline\");\n }\n\n const styleAttr = styles.join(\"; \");\n\n return `<a href=\"${url}\" style=\"${styleAttr}\"${target}>${text}</a>`;\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type {\n TableBlock,\n TableRowData,\n TableCellData,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport {\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n escapeHtml,\n convertMergeTagsToValues,\n} from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a table block to MJML markup.\n * Uses mj-text wrapping an HTML <table> with styled <tr>/<td> elements.\n */\nexport function renderTable(block: TableBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n if (block.rows.length === 0) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const visibilityAttr = getCssClassAttr(block);\n const fontFamilyAttr = renderFontFamilyAttr(block.fontFamily, context);\n const fontSize = block.fontSize;\n // Emit the color only when set; otherwise the `mj-text` (and its cells,\n // which carry no color of their own) inherit the document `textColor`.\n const colorAttr = block.color ? `\\n color=\"${escapeAttr(block.color)}\"` : \"\";\n const align = block.textAlign;\n\n const tableHtml = renderTableElement(block);\n\n return `<mj-text\n font-size=\"${fontSize}px\"${colorAttr}\n align=\"${align}\"\n line-height=\"1.5\"\n padding=\"${padding}\"${bgColor}${fontFamilyAttr}${visibilityAttr}\n>${tableHtml}</mj-text>`;\n}\n\nfunction renderTableElement(block: TableBlock): string {\n const borderColor = escapeCssValue(block.borderColor);\n const borderWidth = block.borderWidth;\n\n const tableStyle = \"width: 100%; border-collapse: collapse;\";\n\n let rowsHtml = \"\";\n\n for (let index = 0; index < block.rows.length; index++) {\n const row = block.rows[index];\n const isHeader = block.hasHeaderRow && index === 0;\n rowsHtml += renderRow(row, block, isHeader, borderColor, borderWidth);\n }\n\n return `<table style=\"${tableStyle}\">${rowsHtml}</table>`;\n}\n\nfunction renderRow(\n row: TableRowData,\n block: TableBlock,\n isHeader: boolean,\n borderColor: string,\n borderWidth: number,\n): string {\n let cellsHtml = \"\";\n\n for (const cell of row.cells) {\n cellsHtml += renderCell(cell, block, isHeader, borderColor, borderWidth);\n }\n\n return `<tr>${cellsHtml}</tr>`;\n}\n\nfunction renderCell(\n cell: TableCellData,\n block: TableBlock,\n isHeader: boolean,\n borderColor: string,\n borderWidth: number,\n): string {\n const cellPadding = block.cellPadding;\n\n const styles: string[] = [\n `border: ${borderWidth}px solid ${borderColor}`,\n `padding: ${cellPadding}px`,\n ];\n\n if (isHeader) {\n styles.push(\"font-weight: bold\");\n\n if (block.headerBackgroundColor) {\n styles.push(\n `background-color: ${escapeCssValue(block.headerBackgroundColor)}`,\n );\n }\n }\n\n const styleAttr = styles.join(\"; \");\n // Cells are a plain-text field (the editor stores innerText; TableCellData\n // carries no rich-text hint), so escape the content like menu/button. Merge\n // tags are resolved first: convertMergeTagsToValues matches a literal\n // `<span`, so escaping has to run after it — escaping first would turn the\n // span into `&lt;span` and the `{{value}}` placeholder would never resolve.\n const content = escapeHtml(convertMergeTagsToValues(cell.content));\n\n const tag = isHeader ? \"th\" : \"td\";\n\n return `<${tag} style=\"${styleAttr}\">${content}</${tag}>`;\n}\n\nfunction renderFontFamilyAttr(\n fontFamily: string | undefined,\n context: RenderContext,\n): string {\n if (!fontFamily) {\n return \"\";\n }\n\n const resolved = context.resolveFontFamily(fontFamily);\n\n return ` font-family=\"${escapeFontFamily(resolved)}\"`;\n}\n","import type { CustomBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Render a custom block to MJML markup.\n *\n * Custom block HTML resolution order:\n * 1. `context.customBlockHtml` map — populated by `renderToMjml` when the\n * caller passes `customBlocks` definitions or a `renderCustomBlock`\n * callback (the editor's path).\n * 2. `block.renderedHtml` — populated by an external pre-render step\n * (e.g., a previous render pass that mutated the block).\n * 3. Empty — block omitted from output.\n */\nexport function renderCustom(\n block: CustomBlock,\n context: RenderContext,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const fromContext = context.customBlockHtml.get(block.id);\n const content = fromContext ?? block.renderedHtml;\n\n if (!content || content === \"\") {\n return \"\";\n }\n\n const visibilityAttr = getCssClassAttr(block);\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n\n return `<mj-text padding=\"${padding}\"${bgColor}${visibilityAttr}>\n${content}\n</mj-text>`;\n}\n","import type { ColumnLayout } from \"@templatical/types\";\n\n/**\n * Get width percentages for each column in a layout.\n */\nexport function getWidthPercentages(layout: ColumnLayout): string[] {\n switch (layout) {\n case \"2\":\n return [\"50%\", \"50%\"];\n case \"3\":\n // 33.33 × 3 = 99.99% — let the last column absorb the rounding gap\n // so widths sum to exactly 100% in the compiled HTML.\n return [\"33.33%\", \"33.33%\", \"33.34%\"];\n case \"1-2\":\n return [\"33.33%\", \"66.67%\"];\n case \"2-1\":\n return [\"66.67%\", \"33.33%\"];\n default:\n return [\"100%\"];\n }\n}\n\n/**\n * Get width in pixels for each column in a layout.\n */\nexport function getWidthPixels(\n layout: ColumnLayout,\n containerWidth: number,\n): number[] {\n switch (layout) {\n case \"2\":\n return [containerWidth * 0.5, containerWidth * 0.5];\n case \"3\":\n return [containerWidth / 3, containerWidth / 3, containerWidth / 3];\n case \"1-2\":\n return [containerWidth / 3, (containerWidth * 2) / 3];\n case \"2-1\":\n return [(containerWidth * 2) / 3, containerWidth / 3];\n default:\n return [containerWidth];\n }\n}\n","import type { AppliedHero, SpacingValue } from \"@templatical/types\";\n\n/** The sizing attributes of an `mj-hero`. */\nexport interface HeroGeometry {\n mode: \"fixed-height\";\n /** Total height in px, padding included. */\n height: number;\n backgroundWidth: number;\n backgroundHeight: number;\n}\n\n/**\n * The `mj-hero` sizing for a hero in a box `boxWidth` px wide. Every hero's\n * mode, height and image size come from here, so an Outlook rendering\n * finding changes this function and nothing else.\n *\n * Every hero is `fixed-height`: classic Outlook on Windows ignores\n * `fluid-height` (its spacer cells carry `mso-padding-bottom-alt:0`) and\n * shrinks the box to its content, showing only the top of the image.\n *\n * - `height: \"image\"` → the image's own height at the box width, so the box\n * matches the image on desktop. A phone keeps that height and crops the\n * image's sides to cover the narrower box.\n * - a number → that height.\n *\n * Either is at least the top and bottom `padding`, each a whole pixel as MJML\n * reads it: MJML sizes the cell as the height less that padding and would\n * write a negative height for a shorter box.\n *\n * Outlook draws the image as a `v:image` of exactly `backgroundWidth ×\n * backgroundHeight` px from the box's top, clipped to the box, so the width is\n * always the box's and the height is the image's own at that width. An image\n * with no known size takes the fixed box's height, which fills the box and\n * stretches the image to it.\n */\nexport function heroGeometry(\n hero: AppliedHero,\n boxWidth: number,\n padding: SpacingValue,\n): HeroGeometry {\n const backgroundWidth = Math.max(1, Math.round(boxWidth));\n const imageHeight =\n hero.aspectRatio === null\n ? null\n : Math.max(1, Math.round(backgroundWidth * hero.aspectRatio));\n\n // resolveHero applies \"image\" only with a known ratio.\n const wanted =\n hero.height === \"image\" ? (imageHeight ?? backgroundWidth) : hero.height;\n const height = Math.max(\n wanted,\n Math.trunc(padding.top) + Math.trunc(padding.bottom),\n );\n\n return {\n mode: \"fixed-height\",\n height,\n backgroundWidth,\n backgroundHeight: imageHeight ?? height,\n };\n}\n","import type { Block } from \"@templatical/types\";\n\n/**\n * Wrap rendered block markup in the block's liquid display-condition guards\n * (`<mj-raw>{% if %}</mj-raw>` … `<mj-raw>{% endif %}</mj-raw>`), if present.\n *\n * Returns the input unchanged when the block has no display condition, and an\n * empty string when the rendered markup is empty (a hidden block) so callers\n * can keep using an `=== \"\"` filter to drop it.\n *\n * Used for BOTH top-level blocks (`index.ts`) and blocks nested inside section\n * columns (`renderers/section.ts`). A condition on a nested block must emit the\n * same guards as a top-level one — otherwise conditional content placed inside\n * a multi-column section renders unconditionally for every recipient.\n */\nexport function wrapWithDisplayCondition(\n block: Block,\n rendered: string,\n): string {\n if (rendered === \"\") {\n return \"\";\n }\n\n const displayCondition = block.displayCondition;\n\n if (!displayCondition) {\n return rendered;\n }\n\n return (\n `<mj-raw>${displayCondition.before}</mj-raw>` +\n \"\\n\" +\n rendered +\n \"\\n\" +\n `<mj-raw>${displayCondition.after}</mj-raw>`\n );\n}\n","import type { AppliedHero, Block, SectionBlock } from \"@templatical/types\";\nimport { isSection, resolveHero } from \"@templatical/types\";\nimport type { BlockRenderer, RenderContext } from \"../render-context\";\nimport { getWidthPercentages, getWidthPixels } from \"../columns\";\nimport { escapeAttr } from \"../escape\";\nimport { heroGeometry } from \"../hero-geometry\";\nimport { toPaddingString } from \"../padding\";\nimport {\n backgroundImageAttrs,\n bgAttr,\n borderAttr,\n borderRadiusAttr,\n horizontalInset,\n} from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\nimport { wrapWithDisplayCondition } from \"../display-condition\";\n\n// `BlockRenderer` is defined in `../render-context`, next to the `blockRenderers`\n// override map it types. Re-exported here so the package's\n// `export type { BlockRenderer } from \"./renderers/section\"` entry point resolves\n// for consumers.\nexport type { BlockRenderer };\n\n/**\n * Render a section block with columns to MJML markup.\n */\nexport function renderSection(\n block: SectionBlock,\n context: RenderContext,\n renderBlock: BlockRenderer,\n): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const hero = resolveHero(block);\n if (hero?.applied) {\n return renderHero(block, hero, context, renderBlock);\n }\n\n const columnsLayout = block.columns;\n const columnWidths = getWidthPercentages(columnsLayout);\n const columnWidthsPx = getWidthPixels(columnsLayout, context.containerWidth);\n // What MJML gives each column's content: the emitted percentage of the room\n // inside the section's padding and border, floored as MJML floors it. From\n // the percentage strings, not `columnWidthsPx`: 33.33% of 600 is 199, a\n // third is 200.\n const sectionBox =\n Math.floor(context.contentWidth) -\n horizontalInset(block.styles.padding, block.border);\n const columnContentWidths = columnWidths.map((width) =>\n Math.floor((sectionBox * parseFloat(width)) / 100),\n );\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"native\");\n const bgImage = backgroundImageAttrs(block.backgroundImage);\n const visibilityAttr = getCssClassAttr(block);\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const borderAttrStr = borderAttr(block.border);\n // MJML's `mj-section`, `mj-group` and `mj-column` each default to\n // `direction=\"ltr\"` and inline it on their own element, so an RTL email\n // needs it on all three — the column's inline style otherwise resets the\n // text inside to LTR under a section that reverses the column order.\n const dirAttr = context.contentDirection === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n\n const children = block.children;\n const columnsContent: string[] = [];\n\n for (let index = 0; index < children.length; index++) {\n const column = children[index];\n const width = columnWidths[index] ?? \"100%\";\n const columnWidth = Math.floor(\n columnWidthsPx[index] ?? context.containerWidth,\n );\n\n // Sections cannot be nested inside columns per MJML spec — drop any\n // SectionBlocks that landed inside a column (via tampered JSON or a\n // future API). Keeping them would emit `<mj-section>` inside\n // `<mj-column>`, which mjml@5 rejects with a hard error.\n const filteredColumn = filterHtmlBlocks(\n column,\n context.allowHtmlBlocks,\n ).filter((child) => !isSection(child));\n const columnContext = context.withContainerWidth(\n columnWidth,\n columnContentWidths[index] ?? sectionBox,\n );\n\n const columnBlocks = filteredColumn\n .map((child) =>\n wrapWithDisplayCondition(child, renderBlock(child, columnContext)),\n )\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n const content =\n columnBlocks === \"\" ? \"<mj-text>&nbsp;</mj-text>\" : columnBlocks;\n\n columnsContent.push(`<mj-column width=\"${width}\"${dirAttr}>\n${content}\n</mj-column>`);\n }\n\n const columns = columnsContent.join(\"\\n\");\n\n // Opting out of mobile stacking wraps the columns in an `<mj-group>`, which\n // keeps them side-by-side below 480px instead of stacking (MJML's default).\n // `mj-group` requires percentage column widths — `getWidthPercentages`\n // already guarantees that. Only meaningful with 2+ columns.\n const body =\n block.stackOnMobile === false && columnsContent.length > 1\n ? `<mj-group${dirAttr}>\n${columns}\n</mj-group>`\n : columns;\n\n return `<mj-section${bgColor}${bgImage} padding=\"${padding}\"${borderAttrStr}${borderRadiusAttrStr}${visibilityAttr}${dirAttr}>\n${body}\n</mj-section>`;\n}\n\n/**\n * Render a section `resolveHero` applies as an `<mj-hero>`. The content is\n * column 0's blocks, filtered as a column's are; mj-hero takes content\n * elements directly, with no `mj-column`.\n *\n * The hero's box is the room its bands leave it, `context.contentWidth`\n * floored as MJML floors every band; Outlook draws the image at exactly that\n * width. Its content renders `\"full\"` at the box and gets the box less the\n * hero's own side padding as its room, as mj-hero gives it: no border comes\n * off, since a hero draws none.\n *\n * Left out on purpose: `border` (mj-hero has none), `background-size` and\n * `background-repeat` (it always paints `cover`, unrepeated) and `direction`\n * (it inlines none, so its text keeps the body's `dir`). An unset fill is\n * `transparent`, since mj-hero's own default is white.\n */\nfunction renderHero(\n block: SectionBlock,\n hero: AppliedHero,\n context: RenderContext,\n renderBlock: BlockRenderer,\n): string {\n const boxWidth = Math.floor(context.contentWidth);\n const geometry = heroGeometry(hero, boxWidth, block.styles.padding);\n const bgColor =\n bgAttr(block.styles.backgroundColor, \"native\") ||\n ' background-color=\"transparent\"';\n const padding = toPaddingString(block.styles.padding);\n const borderRadiusAttrStr = borderRadiusAttr(block.borderRadius);\n const visibilityAttr = getCssClassAttr(block);\n const contentContext = context.withContainerWidth(\n boxWidth,\n boxWidth - horizontalInset(block.styles.padding),\n );\n\n const content = filterHtmlBlocks(\n block.children[0] ?? [],\n context.allowHtmlBlocks,\n )\n .filter((child) => !isSection(child))\n .map((child) =>\n wrapWithDisplayCondition(child, renderBlock(child, contentContext)),\n )\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n return `<mj-hero mode=\"${geometry.mode}\" height=\"${geometry.height}px\" background-url=\"${escapeAttr(hero.image.url)}\" background-width=\"${geometry.backgroundWidth}px\" background-height=\"${geometry.backgroundHeight}px\" background-position=\"${hero.image.position}\"${bgColor} padding=\"${padding}\" vertical-align=\"${hero.verticalAlign}\"${borderRadiusAttrStr}${visibilityAttr}>\n${content}\n</mj-hero>`;\n}\n\n/**\n * Filter out HTML blocks if they are not allowed.\n */\nfunction filterHtmlBlocks(blocks: Block[], allowHtmlBlocks: boolean): Block[] {\n if (allowHtmlBlocks) {\n return blocks;\n }\n\n return blocks.filter((block) => block.type !== \"html\");\n}\n","import type { VideoBlock } from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { escapeAttr } from \"../escape\";\nimport { toPaddingString } from \"../padding\";\nimport { bgAttr, fluidOnMobileAttr, heightAttr } from \"../utils\";\nimport { isHiddenOnAll, getCssClassAttr } from \"../visibility\";\n\n/**\n * Extract video thumbnail URL from common platforms.\n * Works without server-side processing — YouTube and Vimeo thumbnails are publicly accessible.\n */\nfunction getVideoThumbnail(\n url: string,\n customThumbnail?: string,\n): string | null {\n if (customThumbnail) {\n return customThumbnail;\n }\n\n if (!url) {\n return null;\n }\n\n // YouTube\n const youtubePatterns = [\n /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/)([a-zA-Z0-9_-]{11})/,\n /youtube\\.com\\/shorts\\/([a-zA-Z0-9_-]{11})/,\n ];\n\n for (const pattern of youtubePatterns) {\n const match = url.match(pattern);\n if (match) {\n return `https://img.youtube.com/vi/${match[1]}/maxresdefault.jpg`;\n }\n }\n\n // Vimeo\n const vimeoMatch = url.match(/vimeo\\.com\\/(?:video\\/)?(\\d+)/);\n if (vimeoMatch) {\n return `https://vumbnail.com/${vimeoMatch[1]}.jpg`;\n }\n\n return null;\n}\n\n/**\n * Render a video block to MJML markup.\n * Videos in email are rendered as a linked thumbnail image pointing to the video URL.\n */\nexport function renderVideo(block: VideoBlock, context: RenderContext): string {\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n const thumbnailUrl = getVideoThumbnail(block.url, block.thumbnailUrl);\n\n if (!thumbnailUrl) {\n return \"\";\n }\n\n const padding = toPaddingString(block.styles.padding);\n const bgColor = bgAttr(block.styles.backgroundColor, \"container\");\n const width =\n block.width === \"full\" ? context.containerWidth + \"px\" : block.width + \"px\";\n const height = heightAttr(block.height);\n const fluid = fluidOnMobileAttr(block, context);\n const visibilityAttr = getCssClassAttr(block);\n\n const src = escapeAttr(thumbnailUrl);\n const alt = escapeAttr(block.alt);\n const align = block.align;\n const href = escapeAttr(block.url);\n\n return `<mj-image\n src=\"${src}\"\n alt=\"${alt}\"\n width=\"${width}\"${height}${fluid}\n align=\"${align}\"\n padding=\"${padding}\"\n href=\"${href}\"\n target=\"_blank\"\n rel=\"noopener\"${bgColor}${visibilityAttr}\n/>`;\n}\n","import type { Block } from \"@templatical/types\";\nimport {\n isSection,\n isTitle,\n isParagraph,\n isImage,\n isButton,\n isDivider,\n isSpacer,\n isHtml,\n isSocialIcons,\n isMenu,\n isTable,\n isVideo,\n isCustomBlock,\n} from \"@templatical/types\";\nimport type { RenderContext } from \"../render-context\";\nimport { isHiddenOnAll } from \"../visibility\";\nimport { renderUnrenderableBlock } from \"../unrenderable\";\nimport { renderTitle } from \"./title\";\nimport { renderParagraph } from \"./paragraph\";\nimport { renderImage } from \"./image\";\nimport { renderButton } from \"./button\";\nimport { renderDivider } from \"./divider\";\nimport { renderSpacer } from \"./spacer\";\nimport { renderHtml } from \"./html\";\nimport { renderSocialIcons } from \"./social\";\nimport { renderMenu } from \"./menu\";\nimport { renderTable } from \"./table\";\nimport { renderCustom } from \"./custom\";\nimport { renderSection } from \"./section\";\nimport { renderVideo } from \"./video\";\n\n/**\n * Render a single block to MJML markup.\n * Dispatches to the appropriate block-type renderer.\n *\n * A `blockRenderers` override for the block's type wins over the built-in\n * renderer — see {@link RenderContext.blockRenderers}. A type with neither gets a\n * placeholder marker plus a warning rather than disappearing.\n */\nexport function renderBlock(block: Block, context: RenderContext): string {\n // Checked first so an override replaces the built-in wholesale rather than\n // running after it. The override then owns everything the built-in did,\n // including the hidden-on-all-viewports early return.\n const override = context.blockRenderers[block.type];\n if (override) {\n return override(block, context);\n }\n\n if (isSection(block)) {\n return renderSection(block, context, renderBlock);\n }\n\n if (isTitle(block)) {\n return renderTitle(block, context);\n }\n\n if (isParagraph(block)) {\n return renderParagraph(block, context);\n }\n\n if (isImage(block)) {\n return renderImage(block, context);\n }\n\n if (isButton(block)) {\n return renderButton(block, context);\n }\n\n if (isDivider(block)) {\n return renderDivider(block, context);\n }\n\n if (isSpacer(block)) {\n return renderSpacer(block, context);\n }\n\n if (isHtml(block)) {\n return renderHtml(block, context);\n }\n\n if (isSocialIcons(block)) {\n return renderSocialIcons(block, context);\n }\n\n if (isMenu(block)) {\n return renderMenu(block, context);\n }\n\n if (isTable(block)) {\n return renderTable(block, context);\n }\n\n if (isVideo(block)) {\n return renderVideo(block, context);\n }\n\n if (isCustomBlock(block)) {\n return renderCustom(block, context);\n }\n\n // Nothing here knows how to render this type. A block the author hid on every\n // viewport is meant to produce nothing, so it still does — every built-in\n // renderer above makes the same call, and warning about a deliberate hide would\n // be noise. Everything else gets a marker: `countdown` today (Cloud renders it\n // server-side as an animated GIF, which no browser can do), and any future type\n // whose renderer hasn't landed yet.\n if (isHiddenOnAll(block)) {\n return \"\";\n }\n\n return renderUnrenderableBlock(block);\n}\n","import type {\n Block,\n ContentDirection,\n CustomBlock,\n CustomBlockDefinition,\n TemplateContent,\n CustomFont,\n SectionWrapper,\n SpacingValue,\n} from \"@templatical/types\";\nimport {\n applyLayout,\n assertNoSlotInContent,\n assertNoWrapperInContent,\n createCustomBlockLiquid,\n isCustomBlock,\n isSection,\n isWrapper,\n resolveContentDirection,\n} from \"@templatical/types\";\nimport { RenderContext, DEFAULT_SOCIAL_ICONS_BASE_URL } from \"./render-context\";\nimport type { BlockRendererMap } from \"./render-context\";\nimport { renderBlock } from \"./renderers\";\nimport {\n escapeHtml,\n escapeAttr,\n escapeCssValue,\n escapeFontFamily,\n} from \"./escape\";\nimport { wrapWithDisplayCondition } from \"./display-condition\";\nimport {\n backgroundImageAttrs,\n bgAttr,\n borderRadiusAttr,\n horizontalInset,\n} from \"./utils\";\nimport { richTextStylesheet, collectParagraphGaps } from \"./rich-text\";\nimport { BUTTON_FULL_WIDTH_CSS_CLASS } from \"./renderers/button\";\nimport { toPaddingString } from \"./padding\";\n\nexport interface RenderOptions {\n customFonts?: CustomFont[];\n defaultFallbackFont?: string;\n allowHtmlBlocks?: boolean;\n /** Headless custom block definitions. The last definition per type wins. */\n customBlocks?: CustomBlockDefinition[];\n /**\n * Resolves custom blocks to their HTML representation. Called once per\n * custom block in the content tree before MJML rendering. The renderer\n * accepts `customBlocks` for headless rendering; this callback is the\n * editor's integration path.\n *\n * Editor consumers: pass `editor.renderCustomBlock`.\n *\n * With neither this callback nor `customBlocks`, each custom block uses\n * `block.renderedHtml` (if present) and is otherwise omitted.\n */\n renderCustomBlock?: (block: CustomBlock) => Promise<string>;\n /**\n * Per-block-type renderer overrides, keyed by `block.type`. An entry replaces\n * the built-in renderer for that type wholesale — including its\n * hidden-on-all-viewports check, which becomes the override's responsibility.\n *\n * ```ts\n * renderToMjml(content, {\n * blockRenderers: {\n * countdown: (block) => `<mj-image src=\"${countdownGifUrl(block)}\" />`,\n * video: (block, ctx) => renderVideoWithPlayButton(block, ctx),\n * },\n * });\n * ```\n *\n * This generalises {@link renderCustomBlock}, which is the same idea for a\n * single block type. It exists so a backend whose render output is a *superset*\n * of the browser's — a server-generated countdown GIF, a composited video\n * thumbnail — can inject exactly that delta instead of forking the renderer:\n * parity for every other block type then holds by construction.\n *\n * A block type with neither a built-in renderer nor an override emits an\n * `mj-raw` placeholder comment and warns, rather than vanishing from the\n * output.\n */\n blockRenderers?: BlockRendererMap;\n /**\n * Resolves the definition-level CSS for a custom block type. Called once\n * per unique `customType` present in the content tree (not per instance).\n * The non-empty results are deduped by content and emitted as additional\n * `<mj-style>` blocks inside `<mj-head>` alongside the built-in visibility\n * media queries.\n *\n * Editor consumers: pass a function that reads\n * `blockRegistry.getDefinition(customType)?.stylesheet`.\n *\n * Headless consumers can pass `customBlocks` instead. A listed definition\n * decides its type's CSS; no stylesheet means none is emitted.\n *\n * Without a resolver or matching definition, each type's saved\n * `block.renderedStylesheet` is emitted. A resolver decides every type and\n * ignores saved copies, so a stale one never overrides a live definition.\n */\n getCustomBlockStylesheet?: (customType: string) => string | undefined | null;\n /**\n * Base URL (no trailing slash) for the social icon PNG assets. Resolved to\n * `${baseUrl}/${style}/${platform}.png` per icon. Defaults to the\n * version-pinned jsDelivr mirror of this package. Override to self-host\n * (e.g., behind your own CDN or for air-gapped environments).\n *\n * Why PNGs: Outlook desktop (Word rendering engine) does not support SVG\n * and rejects base64 data URIs in `<img src>`, so social icons must be\n * served as raster images over HTTP for cross-client compatibility.\n */\n socialIconsBaseUrl?: string;\n /**\n * Embedder shell applied at render. Cloned and spliced around `content`\n * via `applyLayout`; `content` is not mutated. Omitted, the document is\n * rendered as authored and must not contain `slot` or `wrapper`.\n */\n layout?: TemplateContent;\n}\n\n/**\n * Makes a full-width button's whole fill clickable. MJML sizes a button's `<a>`\n * only for a px width, so without this rule the link of a `100%` button stays\n * the size of its label.\n *\n * It sits in the inline `<mj-style>` so `mjml`'s juice pass writes it onto the\n * `<a>`; MRML's default build emits that block as a plain `<style>` instead.\n * `!important` lets it beat MJML's inline `display:inline-block` either way.\n * Every template carries it, so nothing has to walk the tree for full-width\n * buttons: juice drops a rule that matches nothing, so with `mjml` it costs\n * nothing in the compiled HTML.\n */\nconst BUTTON_FULL_WIDTH_RULE = `.${BUTTON_FULL_WIDTH_CSS_CLASS} a { display: block !important; }`;\n\n/**\n * Render template content to an MJML string.\n *\n * With `customBlocks`, this imports the optional `liquidjs` peer only when\n * the content holds a custom block. The editor uses `renderCustomBlock` via\n * `toMjml()`; headless callers can pass definitions directly. The function\n * always returns a Promise.\n */\nexport async function renderToMjml(\n content: TemplateContent,\n options?: RenderOptions,\n): Promise<string> {\n if (\n options?.customBlocks !== undefined &&\n options.renderCustomBlock !== undefined\n ) {\n throw new TypeError(\n \"[Templatical] customBlocks cannot be combined with renderCustomBlock\",\n );\n }\n if (\n options?.customBlocks !== undefined &&\n options.getCustomBlockStylesheet !== undefined\n ) {\n throw new TypeError(\n \"[Templatical] customBlocks cannot be combined with getCustomBlockStylesheet\",\n );\n }\n\n const toRender = options?.layout\n ? applyLayout(options.layout, content)\n : (assertNoSlotInContent(content),\n assertNoWrapperInContent(content),\n content);\n\n const customFonts = options?.customFonts ?? [];\n const defaultFallbackFont =\n options?.defaultFallbackFont ?? \"Arial, sans-serif\";\n const allowHtmlBlocks = options?.allowHtmlBlocks ?? true;\n const socialIconsBaseUrl = stripTrailingSlash(\n options?.socialIconsBaseUrl ?? DEFAULT_SOCIAL_ICONS_BASE_URL,\n );\n\n const customBlockHtml =\n options?.customBlocks !== undefined\n ? await resolveCustomBlockDefinitions(toRender, options.customBlocks)\n : await resolveCustomBlocks(toRender, options?.renderCustomBlock);\n\n const customBlockStylesheets = collectCustomBlockStylesheets(\n toRender,\n options?.getCustomBlockStylesheet,\n options?.customBlocks === undefined\n ? undefined\n : new Map(\n options.customBlocks.map((definition) => [\n definition.type,\n definition,\n ]),\n ),\n );\n\n const contentDirection = resolveContentDirection(toRender.settings);\n\n const renderContext = new RenderContext(\n toRender.settings.width,\n customFonts,\n defaultFallbackFont,\n allowHtmlBlocks,\n customBlockHtml,\n socialIconsBaseUrl,\n options?.blockRenderers ?? {},\n contentDirection,\n );\n\n const blocks = filterHtmlBlocks(toRender.blocks, allowHtmlBlocks);\n const fontFamily = renderContext.resolveFontFamily(\n toRender.settings.fontFamily,\n );\n const backgroundColor = toRender.settings.backgroundColor;\n // Document-level default text color → the `<mj-text>` default below. Blocks\n // that set their own color (e.g. Title) or carry inline text-color marks\n // override it. Omitted when unset so existing templates render identically.\n const textColorAttr = toRender.settings.textColor\n ? ` color=\"${escapeAttr(toRender.settings.textColor)}\"`\n : \"\";\n // Document-level link styling → the global `a { … }` rule below, cascading to\n // every link (rich-text and menu). An unset `linkColor` keeps `color: inherit`\n // so links follow the text color and legacy content renders identically; a\n // per-link/per-item color still overrides (inline styles beat this rule).\n const linkColor = toRender.settings.linkColor\n ? escapeCssValue(toRender.settings.linkColor)\n : \"inherit\";\n const linkDecoration = toRender.settings.linkUnderline ? \"underline\" : \"none\";\n\n const bodyContent = blocks\n .map((block) => renderTopLevelBlock(block, renderContext))\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n\n const fontDeclarations = generateFontDeclarations(customFonts);\n const previewTag = generatePreviewTag(toRender.settings.preheaderText);\n\n const lang = escapeAttr(toRender.settings.locale);\n const dir = escapeAttr(contentDirection);\n\n return `<mjml lang=\"${lang}\" dir=\"${dir}\">\n <mj-head>${previewTag}\n <mj-attributes>\n <mj-all font-family=\"${escapeFontFamily(fontFamily)}\" />\n <mj-text font-size=\"14px\"${textColorAttr} />\n <mj-section padding=\"0\" />\n <mj-column padding=\"0\" />\n </mj-attributes>${fontDeclarations}\n <mj-style inline=\"inline\">\n ${richTextStylesheet(collectParagraphGaps(blocks), contentDirection)}\n ${BUTTON_FULL_WIDTH_RULE}\n </mj-style>\n <mj-style>\n a { color: ${linkColor}; text-decoration: ${linkDecoration}; }\n @media only screen and (max-width: 480px) {\n .tpl-hide-mobile { display: none !important; mso-hide: all !important; }\n }\n @media only screen and (min-width: 481px) {\n .tpl-hide-desktop { display: none !important; mso-hide: all !important; }\n }\n </mj-style>${renderCustomBlockStylesheets(customBlockStylesheets)}\n </mj-head>\n <mj-body width=\"${renderContext.containerWidth}px\" background-color=\"${backgroundColor}\">\n${bodyContent}\n </mj-body>\n</mjml>`;\n}\n\n/**\n * Render a top-level block. Wrappers emit `mj-wrapper` around their children.\n * Sections are rendered directly; other blocks are wrapped in a default\n * section/column.\n */\nfunction renderTopLevelBlock(block: Block, context: RenderContext): string {\n if (isWrapper(block)) {\n const innerContext = insideWrapper(context, block.styles.padding);\n const inner = filterHtmlBlocks(block.children, context.allowHtmlBlocks)\n .map((child) => renderTopLevelBlock(child, innerContext))\n .filter((value) => value !== \"\")\n .join(\"\\n\");\n const framed = renderMjWrapper(\n inner,\n {\n backgroundColor: block.styles.backgroundColor,\n padding: block.styles.padding,\n borderRadius: block.borderRadius,\n backgroundImage: block.backgroundImage,\n },\n context.contentDirection,\n );\n return wrapWithDisplayCondition(block, framed);\n }\n\n if (isSection(block)) {\n const rendered = renderBlock(\n block,\n block.wrapper ? insideWrapper(context, block.wrapper.padding) : context,\n );\n // An empty render (hidden section) stays empty — never emit a bare wrapper.\n const framed =\n block.wrapper && rendered !== \"\"\n ? renderMjWrapper(rendered, block.wrapper, context.contentDirection)\n : rendered;\n return wrapWithDisplayCondition(block, framed);\n }\n\n const content = renderBlock(block, context);\n const wrapped = wrapInSection(content, context.contentDirection);\n return wrapWithDisplayCondition(block, wrapped);\n}\n\n/**\n * The context for what an `mj-wrapper` holds: MJML narrows its children by the\n * wrapper's side padding. `containerWidth` stays the nominal share of the body.\n */\nfunction insideWrapper(\n context: RenderContext,\n padding: SpacingValue | undefined,\n): RenderContext {\n return context.withContainerWidth(\n context.containerWidth,\n Math.floor(context.contentWidth) - horizontalInset(padding),\n );\n}\n\n/**\n * `mj-wrapper` attributes shared by a layout `wrapper` block and\n * `section.wrapper`. Padding is always explicit: MJML's wrapper default is\n * `20px 0`, ours is 0. Direction is explicit for the same reason: MJML's\n * default `ltr` would otherwise be inlined on the band of an RTL email.\n */\nfunction renderMjWrapper(\n inner: string,\n wrapper: SectionWrapper,\n direction: ContentDirection,\n): string {\n const bg = bgAttr(wrapper.backgroundColor, \"native\");\n const bgImage = backgroundImageAttrs(wrapper.backgroundImage);\n const padding = ` padding=\"${\n wrapper.padding ? toPaddingString(wrapper.padding) : \"0\"\n }\"`;\n const radius = borderRadiusAttr(wrapper.borderRadius);\n const dirAttr = direction === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n return `<mj-wrapper${bg}${bgImage}${padding}${radius}${dirAttr}>\n${inner}\n</mj-wrapper>`;\n}\n\n/**\n * Wrap block content in a default mj-section/mj-column for non-section blocks.\n */\nfunction wrapInSection(content: string, direction: ContentDirection): string {\n if (content === \"\") {\n return \"\";\n }\n\n const dirAttr = direction === \"rtl\" ? ' direction=\"rtl\"' : \"\";\n return `<mj-section${dirAttr}>\n <mj-column${dirAttr}>\n${content}\n </mj-column>\n</mj-section>`;\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nfunction generatePreviewTag(preheaderText?: string): string {\n if (!preheaderText) {\n return \"\";\n }\n\n const trimmed = preheaderText.trim();\n\n if (trimmed === \"\") {\n return \"\";\n }\n\n const escaped = escapeHtml(trimmed);\n\n return `\\n <mj-preview>${escaped}</mj-preview>`;\n}\n\nfunction generateFontDeclarations(customFonts: CustomFont[]): string {\n if (customFonts.length === 0) {\n return \"\";\n }\n\n return customFonts\n .map(\n (font) =>\n `\\n <mj-font name=\"${escapeAttr(font.name)}\" href=\"${escapeAttr(font.url)}\" />`,\n )\n .join(\"\");\n}\n\n/**\n * Filter out HTML blocks if they are not allowed.\n */\nfunction filterHtmlBlocks(blocks: Block[], allowHtmlBlocks: boolean): Block[] {\n if (allowHtmlBlocks) {\n return blocks;\n }\n\n return blocks.filter((block) => block.type !== \"html\");\n}\n\n/**\n * Walk the content tree, collect every custom block, then resolve each in\n * parallel via the supplied callback. Returns a map keyed by block id that\n * the synchronous render pass reads from. If no callback is provided, returns\n * an empty map and the sync pass falls back to `block.renderedHtml`.\n *\n * Per-block failures bubble up — the caller decides whether to swallow or\n * rethrow. We don't replace failures with placeholders here because that's\n * a policy decision (the editor swallows; a strict CLI may want to fail).\n */\nasync function resolveCustomBlocks(\n content: TemplateContent,\n renderCustomBlock: RenderOptions[\"renderCustomBlock\"],\n): Promise<Map<string, string>> {\n const result = new Map<string, string>();\n\n if (!renderCustomBlock) {\n return result;\n }\n\n const customBlocks: CustomBlock[] = [];\n collectCustomBlocks(content.blocks, customBlocks);\n\n if (customBlocks.length === 0) {\n return result;\n }\n\n const rendered = await Promise.all(\n customBlocks.map((block) => renderCustomBlock(block)),\n );\n\n for (let index = 0; index < customBlocks.length; index++) {\n result.set(customBlocks[index].id, rendered[index]);\n }\n\n return result;\n}\n\n/** One Liquid engine serves every definition in this render call. Template\n * errors propagate as callback rejections do. */\nasync function resolveCustomBlockDefinitions(\n content: TemplateContent,\n definitions: CustomBlockDefinition[],\n): Promise<Map<string, string>> {\n const result = new Map<string, string>();\n const blocks: CustomBlock[] = [];\n collectCustomBlocks(content.blocks, blocks);\n if (blocks.length === 0) return result;\n\n let liquidjs: typeof import(\"liquidjs\");\n try {\n liquidjs = await import(\"liquidjs\");\n } catch {\n throw new Error(\n \"[Templatical] customBlocks requires the optional liquidjs package.\",\n );\n }\n const liquid = createCustomBlockLiquid(liquidjs);\n const byType = new Map(\n definitions.map((definition) => [definition.type, definition]),\n );\n const rendered = await Promise.all(\n blocks.map(async (block) => {\n const definition = byType.get(block.customType);\n return definition\n ? String(\n await liquid.parseAndRender(definition.template, block.fieldValues),\n )\n : undefined;\n }),\n );\n for (let index = 0; index < blocks.length; index++) {\n const html = rendered[index];\n if (html !== undefined) result.set(blocks[index].id, html);\n }\n return result;\n}\n\nfunction collectCustomBlocks(blocks: Block[], out: CustomBlock[]): void {\n for (const block of blocks) {\n if (isCustomBlock(block)) {\n out.push(block);\n continue;\n }\n\n if (isSection(block)) {\n for (const column of block.children) {\n collectCustomBlocks(column, out);\n }\n } else if (isWrapper(block)) {\n collectCustomBlocks(block.children, out);\n }\n }\n}\n\n/**\n * Walk the content tree, find every unique `customType`, ask the consumer's\n * resolver for that definition's stylesheet (or, with no resolver, take the\n * first `renderedStylesheet` a block of that type carries), and return the\n * non-empty, content-deduped set in insertion order.\n *\n * Content-level dedupe (not just by customType) means two definitions that\n * happen to ship the same stylesheet string emit it only once — cheap and\n * matches the \"one rule, emitted once\" mental model. Whitespace-only and\n * empty stylesheets are skipped.\n */\nfunction collectCustomBlockStylesheets(\n content: TemplateContent,\n resolver: RenderOptions[\"getCustomBlockStylesheet\"],\n definitions?: Map<string, CustomBlockDefinition>,\n): string[] {\n const customBlocks: CustomBlock[] = [];\n collectCustomBlocks(content.blocks, customBlocks);\n\n if (customBlocks.length === 0) {\n return [];\n }\n\n // Without a resolver, the first copy each type carries stands in for it.\n const copies = new Map<string, string>();\n if (!resolver) {\n for (const block of customBlocks) {\n if (block.renderedStylesheet && !copies.has(block.customType)) {\n copies.set(block.customType, block.renderedStylesheet);\n }\n }\n }\n\n const seenTypes = new Set<string>();\n const seenContent = new Set<string>();\n const stylesheets: string[] = [];\n\n for (const block of customBlocks) {\n if (seenTypes.has(block.customType)) {\n continue;\n }\n seenTypes.add(block.customType);\n\n const definition = definitions?.get(block.customType);\n const css = resolver\n ? resolver(block.customType)\n : definition\n ? definition.stylesheet\n : copies.get(block.customType);\n if (!css) {\n continue;\n }\n\n const trimmed = css.trim();\n if (trimmed === \"\" || seenContent.has(trimmed)) {\n continue;\n }\n seenContent.add(trimmed);\n stylesheets.push(trimmed);\n }\n\n return stylesheets;\n}\n\nfunction renderCustomBlockStylesheets(stylesheets: string[]): string {\n if (stylesheets.length === 0) {\n return \"\";\n }\n\n // One `<mj-style>` per unique stylesheet so per-definition CSS can be\n // independently inspected in the rendered MJML, and authors can grep their\n // contribution without disentangling a merged blob.\n return stylesheets\n .map((css) => `\\n <mj-style>\\n${css}\\n </mj-style>`)\n .join(\"\");\n}\n\n// Re-export utilities for consumers\nexport { RenderContext } from \"./render-context\";\nexport { escapeHtml, escapeAttr, convertMergeTagsToValues } from \"./escape\";\nexport { isHiddenOnAll, getCssClassAttr, getCssClasses } from \"./visibility\";\n// Exported for `blockRenderers` consumers replacing the paragraph or title\n// renderer: without both classes on their `mj-text`, their block silently\n// loses the spacing rules and drifts back to MJML's 13px.\nexport {\n RICH_TEXT_CSS_CLASS,\n richTextGapClass,\n resolveParagraphGap,\n} from \"./rich-text\";\n// Exported for `blockRenderers` consumers replacing the button renderer: a\n// full-width button whose `mj-button` lacks this class is clickable only on\n// its label.\nexport { BUTTON_FULL_WIDTH_CSS_CLASS } from \"./renderers/button\";\n// Exported for `blockRenderers` consumers that emit their own `mj-image` (a\n// video thumbnail, a countdown GIF): `fluid-on-mobile` is set per image, so an\n// `mj-image` without it keeps its desktop width on a phone.\nexport { fluidOnMobileAttr } from \"./utils\";\nexport { getWidthPercentages, getWidthPixels } from \"./columns\";\nexport { toPaddingString } from \"./padding\";\nexport { DEFAULT_SOCIAL_ICONS_BASE_URL } from \"./render-context\";\nexport { renderBlock } from \"./renderers\";\nexport {\n renderUnrenderableBlock,\n UNRENDERABLE_MARKER_PREFIX,\n} from \"./unrenderable\";\nexport type { BlockRenderer, BlockRendererMap } from \"./render-context\";\n"],"mappings":";;AC6BA,MAAa,gCAAgC;;;;AAK7C,IAAa,gBAAb,MAAa,cAAc;CAgBP;CACA;CACA;CACA;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,WAAW,GACzB,OAAO;CAMT,OAAO,YACJ,KAAK,QAAQ,qBAAqB,IAAI,kBAAkB,CAAC,CACzD,KAAK,EAAE;AACZ"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@templatical/renderer",
3
3
  "description": "Render Templatical email templates to MJML",
4
- "version": "0.51.1",
4
+ "version": "0.52.1",
5
5
  "bugs": "https://github.com/templatical/sdk/issues",
6
6
  "dependencies": {
7
- "@templatical/types": "0.51.1"
7
+ "@templatical/types": "0.52.1"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@jsquash/oxipng": "^2.3.0",
11
11
  "@resvg/resvg-js": "^2.6.2",
12
+ "liquidjs": "^10.30.1",
12
13
  "mjml": "^5.4.1",
13
14
  "typescript": "^6.0.3",
14
15
  "vitest": "^5.0.5"
@@ -34,6 +35,14 @@
34
35
  ],
35
36
  "license": "MIT",
36
37
  "module": "./dist/index.js",
38
+ "peerDependencies": {
39
+ "liquidjs": "^10.30.1"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "liquidjs": {
43
+ "optional": true
44
+ }
45
+ },
37
46
  "publishConfig": {
38
47
  "access": "public"
39
48
  },