@maily-to/render 0.2.3 → 2.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,2 +1,1398 @@
1
- import{Fragment as e}from"react";import{Body as t,Button as n,Column as r,Container as i,Font as a,Head as o,Heading as s,Hr as c,Html as l,Img as u,Link as d,Preview as f,Row as p,Section as m,Text as h}from"@react-email/components";import{renderAsync as g}from"@react-email/render";import{Fragment as _,jsx as v,jsxs as y}from"react/jsx-runtime";import{parse as b}from"node-html-parser";import x from"juice";const S=e=>Object.prototype.toString.call(e),C=e=>S(e)===`[object Object]`;function w(e){return Object.keys(e)}function T(e,...t){if(!t.length)return e;let n=t.shift();return n===void 0?e:(E(e)&&E(n)&&w(n).forEach(t=>{t===`__proto__`||t===`constructor`||t===`prototype`||(E(n[t])?(e[t]||(e[t]={}),E(e[t])?T(e[t],n[t]):e[t]=n[t]):e[t]=n[t])}),T(e,...t))}function E(e){return C(e)&&!Array.isArray(e)}const ee=Symbol(`p-void`);function D(){return Math.random().toString(36).substr(2,6)}function O(e){return e.filter((e,t,n)=>{let r=A(e);return t===n.findIndex(e=>A(e)===r)}).map(k).filter(Boolean)}function k(e){if(`tagName`in e){let{tagName:t,...n}=e,r=t;return v(r,{...n},JSON.stringify(n))}return`title`in e?v(`title`,{children:e.title}):`charSet`in e?v(`meta`,{charSet:e.charSet}):v(`meta`,{...e},JSON.stringify(e))}function A(e){let t=Object.keys(e).sort().reduce((t,n)=>{let r=n;return t[r]=e[r],t},{});return JSON.stringify(t)}const j={fallbackFontFamily:`sans-serif`,fontFamily:`Inter`,webFont:{url:`https://rsms.me/inter/font-files/Inter-Regular.woff2?v=3.19`,format:`woff2`}},M=`#111827`,N={colors:{heading:`#111827`,paragraph:`#374151`,horizontal:`#EAEAEA`,footer:`#64748B`,blockquoteBorder:`#D1D5DB`,codeBackground:`#EFEFEF`,codeText:`#111827`,linkCardTitle:`#111827`,linkCardDescription:`#6B7280`,linkCardBadgeText:`#111827`,linkCardBadgeBackground:`#FEF08A`,linkCardSubTitle:`#6B7280`},fontSize:{paragraph:{size:`15px`,lineHeight:`26.25px`},footer:{size:`14px`,lineHeight:`24px`}},container:{backgroundColor:`#ffffff`,maxWidth:`600px`,minWidth:`300px`,paddingTop:`0.5rem`,paddingRight:`0.5rem`,paddingBottom:`0.5rem`,paddingLeft:`0.5rem`,borderRadius:`0px`,borderWidth:`0px`,borderColor:`transparent`},body:{backgroundColor:`#ffffff`,paddingTop:`0px`,paddingRight:`0px`,paddingBottom:`0px`,paddingLeft:`0px`},button:{backgroundColor:`#000000`,color:`#ffffff`,paddingTop:`10px`,paddingRight:`32px`,paddingBottom:`10px`,paddingLeft:`32px`},link:{color:M},font:j};var te=class{constructor(e){this.maily=e}render(e){return typeof e==`string`?e:this.renderNode(e)}renderNode(e){let t=e.type||``;switch(t){case`doc`:return this.doc(e);case`paragraph`:return this.paragraph(e);case`text`:return this.text(e);case`variable`:return this.variable(e);default:return``}}doc(e){let t=e.content||[];return t.length===0?``:t.map(e=>this.renderNode(e)).join(``)}paragraph(e){let t=e.content||[];return t.length===0?``:t.map(e=>this.renderNode(e)).join(``)}text(e){return e.text||``}variable(e){let{id:t,fallback:n}=e.attrs||{};return this.maily.getVariableValue(t,n)}};const P={WebkitFontSmoothing:`antialiased`,MozOsxFontSmoothing:`grayscale`},ne={h1:{fontSize:`36px`,lineHeight:`40px`,fontWeight:800},h2:{fontSize:`30px`,lineHeight:`36px`,fontWeight:700},h3:{fontSize:`24px`,lineHeight:`38px`,fontWeight:600}},F={sm:`40px`,md:`48px`,lg:`64px`},re=`SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace`,I=`#ffffff`,L=`left`,R=1,z=`#000000`,B=0,V=0,H=0,U=0,W=5,G=5,K=5,q=5,ie=`100%`,J=8,ae=`transparent`,oe=0,se=0,ce=`transparent`,le=0,ue=0,de=0,fe=0,Y=20,X=20,Z=/https?:\/\//,Q=[{name:`viewport`,content:`width=device-width`},{httpEquiv:`X-UA-Compatible`,content:`IE=edge`},{name:`x-apple-disable-message-reformatting`},{name:`format-detection`,content:`telephone=no,address=no,email=no,date=no,url=no`},{name:`color-scheme`,content:`light`},{name:`supported-color-schemes`,content:`light`}],$={lang:`en`,dir:`ltr`},pe={pretty:!1,plainText:!1};var me=class{preheader=new te(this);content;config={theme:N};variableFormatter=({variable:e,fallback:t})=>t?`{{${e},fallback=${t}}}`:`{{${e}}}`;shouldReplaceVariableValues=!1;variableValues=new Map;linkValues=new Map;openTrackingPixel;payloadValues=new Map;marksOrder=[`underline`,`bold`,`italic`,`textStyle`,`link`];meta=Q;htmlProps=$;constructor(e={type:`doc`,content:[]}){this.content=e}setPreviewText(e){this.config.preview=e}setTheme(e){this.config.theme=T(this.config.theme||N,e)}setVariableFormatter(e){this.variableFormatter=e}setVariableValue(e,t){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),this.variableValues.set(e,t)}setVariableValues(e){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),Object.entries(e).forEach(([e,t])=>{this.setVariableValue(e,t)})}setLinkValue(e,t){this.linkValues.set(e,t)}setLinkValues(e){Object.entries(e).forEach(([e,t])=>{this.setLinkValue(e,t)})}setPayloadValue(e,t){this.shouldReplaceVariableValues||(this.shouldReplaceVariableValues=!0),this.payloadValues.set(e,t)}setPayloadValues(e){Object.entries(e).forEach(([e,t])=>{this.setPayloadValue(e,t)})}setOpenTrackingPixel(e){this.openTrackingPixel=e}setShouldReplaceVariableValues(e){this.shouldReplaceVariableValues=e}setMetaTags(e){this.meta.push(...e)}setHtmlProps(e){this.htmlProps={...this.htmlProps,...e}}getAllLinks(){let e=this.content.content||[],t=new Set,n=e=>e&&this.isValidUrl(e)&&!e.startsWith(`#`)&&!e.startsWith(`mailto:`)&&!e.startsWith(`tel:`)&&typeof e==`string`,r=e=>{if(e.type===`button`){let r=e.attrs?.url;n(r)&&r&&t.add(r)}else e.content&&e.content.forEach(e=>{e.marks&&e.marks.forEach(e=>{let r=e.attrs?.href;e.type===`link`&&n(r)&&t.add(r)}),e.content&&r(e)})};return e.forEach(e=>{r(e)}),t}isValidUrl(e){try{let t=new URL(e);return!0}catch(e){return!1}}async render(e=pe){let t=this.markup();return g(t,e)}children(){let t=this.content.content||[],n=t.map((n,r)=>{let i={prev:t[r-1],next:t[r+1],parent:n},a=this.renderNode(n,i);return a?v(e,{children:a},D()):null});return n}markup(){let e=this.children(),{preview:n}=this.config,r=O(this.meta),s=this.htmlProps,c=this.config.theme?.container,d={...this.config.theme?.font||j,fontStyle:`normal`,fontWeight:400},p={margin:`0px`,...this.config.theme?.body},m=n?this.preheader.render(n):null,h=y(l,{...s,children:[y(o,{children:[v(a,{...d}),v(`style`,{dangerouslySetInnerHTML:{__html:`blockquote,h1,h2,h3,img,li,ol,p,ul{margin-top:0;margin-bottom:0}@media only screen and (max-width:425px){.tab-row-full{width:100%!important}.tab-col-full{display:block!important;width:100%!important}.tab-pad{padding:0!important}}`}}),r]}),y(t,{style:p,children:[m?v(f,{children:m}):null,v(i,{style:{width:`100%`,marginLeft:`auto`,marginRight:`auto`,borderStyle:`solid`,...c},children:e}),this.openTrackingPixel?v(u,{alt:``,src:this.openTrackingPixel,style:{display:`none`,width:`1px`,height:`1px`}}):null]})]});return h}getMarginOverrideConditions(e,t){let{parent:n,prev:r,next:i}=t||{},a=i?.type===`spacer`,o=r?.type===`spacer`,s=n?.type===`listItem`,c=n?.type===`section`&&!i,l=n?.type===`section`&&!r,u=n?.type===`column`&&!i,d=n?.type===`column`&&!r,f=n?.type===`repeat`&&!r,p=n?.type===`repeat`&&!i,m=n?.type===`show`&&!r,h=n?.type===`show`&&!i;return{isNextSpacer:a,isPrevSpacer:o,isLastSectionElement:c,isFirstSectionElement:l,isParentListItem:s,isLastColumnElement:u,isFirstColumnElement:d,isFirstRepeatElement:f,isLastRepeatElement:p,isFirstShowElement:m,isLastShowElement:h,shouldRemoveTopMargin:o||l||d||f||m,shouldRemoveBottomMargin:a||c||u||p||h}}getMappedContent(t,n){let r=t.content||[];return r.map((t,i)=>{let a=this.renderNode(t,{...n,next:r[i+1],prev:r[i-1]});return a?v(e,{children:a},D()):null}).filter(e=>e!==null)}renderNode(e,t={}){let n=e.type||``;if(n in this)return this[n]?.(e,t);throw Error(`Node type "${n}" is not supported.`)}renderMark(e,t){let n=e?.text||v(_,{children:`\xA0`}),r=e?.marks||[];return r.sort((e,t)=>this.marksOrder.indexOf(e.type)-this.marksOrder.indexOf(t.type)),r.reduce((e,t)=>{let n=t.type;if(n in this)return this[n]?.(t,e);throw Error(`Mark type "${n}" is not supported.`)},v(_,{children:n}))}paragraph(e,t){let{attrs:n}=e,r=n?.textAlign||`left`,i=n?.textDirection||`ltr`,{isParentListItem:a,shouldRemoveBottomMargin:o}=this.getMarginOverrideConditions(e,t),s=this.shouldShow(e,t);if(!s)return v(_,{});let c=a||o?0:20;return v(h,{style:{...r===`left`?{}:{textAlign:r},...i===`ltr`?{}:{direction:i},...P,fontSize:this.config.theme?.fontSize?.paragraph?.size,lineHeight:this.config.theme?.fontSize?.paragraph?.lineHeight,color:this.config.theme?.colors?.paragraph,margin:`0 0 ${c}px 0`},children:e.content?this.getMappedContent(e,{...t,parent:e}):v(_,{children:`\xA0`})})}text(t,n){if(t.marks)return this.renderMark(t,n);let r=t.text,i=r?.match(/\s/g);return i&&i.length===r?.length?v(_,{children:i.map((t,n)=>v(e,{children:`\xA0`},n))}):r?v(_,{children:r}):v(_,{children:`\xA0`})}bold(e,t){return v(`strong`,{children:t})}italic(e,t){return v(`em`,{children:t})}underline(e,t){return v(`u`,{children:t})}strike(e,t){return v(`s`,{style:{textDecoration:`line-through`},children:t})}textStyle(e,t){let{attrs:n}=e,{color:r=this.config.theme?.colors?.paragraph}=n||{};return v(`span`,{style:{color:r},children:t})}link(e,t,n){let{attrs:r}=e,i=this.config.theme?.link,a=r?.href||`#`,o=r?.target||`_blank`,s=r?.rel||`noopener noreferrer nofollow`,c=r?.isUrlVariable??!1;if(c){let e=this.removeLinkProtocol(a);a=this.variableUrlValue(e,n)}else a=this.linkValues.get(a)||a;return v(d,{href:a,rel:s,style:{fontWeight:500,textDecoration:`none`,color:i?.color||M},target:o,children:t})}removeLinkProtocol(e){return e.replace(Z,``)}variableUrlValue(e,t){let{payloadValue:n}=t||{},r=this.removeLinkProtocol(e);return this.shouldReplaceVariableValues?(typeof n==`object`?n[r]:n)??this.variableValues.get(r)??e:this.variableFormatter({variable:r})}heading(e,t){let{attrs:n}=e,r=`h${Number(n?.level)||1}`,i=n?.textDirection||`ltr`,a=i===`rtl`,o=a?`right`:`left`,c=n?.textAlign||o,{shouldRemoveBottomMargin:l}=this.getMarginOverrideConditions(e,t),{fontSize:u,lineHeight:d,fontWeight:f}=ne[r],p=this.shouldShow(e,t);return p?v(s,{as:r,style:{...c===`left`?{}:{textAlign:c},...a?{direction:i}:{},color:this.config.theme?.colors?.heading,fontSize:u,lineHeight:d,fontWeight:f},mb:l?0:12,mt:0,mx:0,children:this.getMappedContent(e,{...t,parent:e})}):v(_,{})}variable(e,t){let{payloadValue:n}=t||{},{id:r,fallback:i}=e.attrs||{},a=this.shouldShow(e,t);if(!a||!r)return v(_,{});let o=this.getVariableValue(r,i,t);return e?.marks?this.renderMark({text:o,marks:e.marks},t):v(_,{children:o})}getVariableValue(e,t,n){let{payloadValue:r}=n||{},i=this.variableFormatter({variable:e,fallback:t});return this.shouldReplaceVariableValues&&(i=(typeof r==`object`?r[e]:r)??this.variableValues.get(e)??t??i),i}horizontalRule(e,t){return v(c,{style:{marginTop:`32px`,marginBottom:`32px`}})}orderedList(e,t){let{shouldRemoveBottomMargin:n}=this.getMarginOverrideConditions(e,t);return v(i,{style:{marginTop:`0px`,marginBottom:n?`0`:`20px`},children:v(`ol`,{style:{paddingLeft:`26px`,listStyleType:`decimal`},children:this.getMappedContent(e,{...t,parent:e})})})}bulletList(e,t){let{parent:n,next:r}=t||{},{shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,{parent:n,next:r});return v(i,{style:{maxWidth:`100%`,marginTop:`0px`,marginBottom:a?`0`:`20px`},children:v(`ul`,{style:{paddingLeft:`26px`,listStyleType:`disc`},children:this.getMappedContent(e,{...t,parent:e})})})}listItem(e,t){return v(`li`,{style:{marginBottom:`8px`,marginTop:`8px`,paddingLeft:`6px`,...P},children:this.getMappedContent(e,{...t,parent:e})})}button(e,t){let{attrs:r}=e,a=this.config.theme?.button,{text:o,isTextVariable:s,url:c,isUrlVariable:l,variant:u,buttonColor:d,textColor:f,borderRadius:p,alignment:m=`left`,paddingTop:h,paddingRight:g,paddingBottom:y,paddingLeft:b}=r||{},x=d||a?.backgroundColor,S=f||a?.color,C=parseInt(String(h||a?.paddingTop))||0,w=parseInt(String(g||a?.paddingRight))||0,T=parseInt(String(y||a?.paddingBottom))||0,E=parseInt(String(b||a?.paddingLeft))||0,ee=this.shouldShow(e,t);if(!ee)return v(_,{});let D=`0px`;p===`round`?D=`9999px`:p===`smooth`&&(D=`6px`);let{shouldRemoveBottomMargin:O}=this.getMarginOverrideConditions(e,t),k=l?this.variableUrlValue(c,t):this.linkValues.get(c)||c,A=s?this.variableUrlValue(o,t):o;return C+=2,T+=2,v(i,{style:{textAlign:m,maxWidth:`100%`,marginBottom:O?`0px`:`20px`},children:v(n,{href:k,style:{color:String(S),backgroundColor:u===`filled`?String(x):`transparent`,borderColor:String(x),borderWidth:`2px`,borderStyle:`solid`,textDecoration:`none`,fontSize:`14px`,fontWeight:500,borderRadius:D,padding:`${C}px ${w}px ${T}px ${E}px`},children:A})})}spacer(e,t){let{attrs:n}=e,{height:r}=n||{},a=this.shouldShow(e,t);return a?v(i,{style:{height:`${r}px`}}):v(_,{})}hardBreak(e,t){return v(`br`,{})}logo(e,t){let{attrs:n}=e,{src:i,isSrcVariable:a,alt:o,title:s,size:c,alignment:l=`left`}=n||{},d=this.shouldShow(e,t);if(!d)return v(_,{});i=a?this.variableUrlValue(i,t):i;let{shouldRemoveBottomMargin:f}=this.getMarginOverrideConditions(e,t);return v(p,{style:{marginTop:`0px`,marginBottom:f?`0px`:`32px`},children:v(r,{align:l,children:v(u,{alt:o||s||`Logo`,src:i,style:{width:F[c]||c,height:F[c]||c},title:s||o||`Logo`})})})}image(e,t){let{attrs:n}=e,{src:i,isSrcVariable:a,alt:o,title:s,width:c=`auto`,height:l=`auto`,alignment:d=`center`,externalLink:f=``,isExternalLinkVariable:m,borderRadius:h=0}=n||{},g=this.shouldShow(e,t);if(!g)return v(_,{});let{shouldRemoveBottomMargin:y}=this.getMarginOverrideConditions(e,t);i=a?this.variableUrlValue(i,t):i,f=m?this.variableUrlValue(f,t):f;let b=c===`auto`?`auto`:Number(c),x=b===`auto`?`auto`:`${b}px`,S=l===`auto`?`auto`:Number(l),C=S===`auto`?`auto`:`${S}px`,w=v(u,{alt:o||s||`Image`,src:i,style:{width:x,height:C,maxWidth:`100%`,outline:`none`,border:`none`,textDecoration:`none`,display:`block`,borderRadius:h},title:s||o||`Image`});return v(p,{style:{marginTop:`0px`,marginBottom:y?`0px`:`32px`},children:v(r,{align:d,children:f?v(`a`,{href:f,rel:`noopener noreferrer`,style:{display:`block`,maxWidth:`100%`,textDecoration:`none`},target:`_blank`,children:w}):w})})}footer(e,t){let{attrs:n}=e,{textAlign:r=`left`,textDirection:i=`ltr`}=n||{},{shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,t);return v(h,{style:{fontSize:this.config.theme?.fontSize?.footer?.size,lineHeight:this.config.theme?.fontSize?.footer?.lineHeight,color:this.config.theme?.colors?.footer,marginTop:`0px`,marginBottom:a?`0px`:`20px`,textAlign:r,...i===`ltr`?{}:{direction:i},...P},children:this.getMappedContent(e,{...t,parent:e})})}blockquote(e,t){let{isPrevSpacer:n,shouldRemoveBottomMargin:r}=this.getMarginOverrideConditions(e,t);return v(`blockquote`,{style:{borderLeftWidth:`4px`,borderLeftStyle:`solid`,borderLeftColor:this.config.theme?.colors?.blockquoteBorder,paddingLeft:`16px`,marginLeft:`0px`,marginRight:`0px`,marginTop:n?`0px`:`20px`,marginBottom:r?`0px`:`20px`},children:this.getMappedContent(e,{...t,parent:e})})}code(e,t){return v(`code`,{style:{backgroundColor:this.config.theme?.colors?.codeBackground,color:this.config.theme?.colors?.codeText,padding:`2px 4px`,borderRadius:`6px`,fontFamily:re,fontWeight:400,letterSpacing:0},children:t})}linkCard(e,t){let{attrs:n}=e,{shouldRemoveBottomMargin:i}=this.getMarginOverrideConditions(e,t),{title:a,description:o,link:s,linkTitle:c,image:l,badgeText:d,subTitle:f}=n||{},m=this.linkValues.get(s)||this.variableValues.get(s)||s||`#`;return y(`a`,{href:m,rel:`noopener noreferrer`,style:{border:`1px solid #eaeaea`,borderRadius:`10px`,textDecoration:`none`,color:`inherit`,display:`block`,marginBottom:i?`0px`:`20px`},target:`_blank`,children:[l?v(p,{style:{marginBottom:`6px`},children:v(r,{style:{width:`100%`,height:`100%`},children:v(u,{alt:a||`Link Card`,src:l,style:{borderRadius:`10px 10px 0 0`,width:`100%`,height:`100%`,objectFit:`cover`},title:a||`Link Card`})})}):null,v(p,{style:{padding:`15px`,marginTop:0,marginBottom:0},children:y(r,{style:{verticalAlign:`top`},children:[y(p,{align:void 0,style:{marginBottom:`8px`,marginTop:`0px`},width:`auto`,children:[v(r,{children:v(h,{style:{fontSize:`18px`,fontWeight:600,color:this.config.theme?.colors?.linkCardTitle,margin:`0px`,...P},children:a})}),d||f?y(r,{style:{paddingLeft:`6px`,verticalAlign:`middle`},children:[d?v(`span`,{style:{fontWeight:600,color:this.config.theme?.colors?.linkCardBadgeText,padding:`4px 8px`,borderRadius:`8px`,backgroundColor:this.config.theme?.colors?.linkCardBadgeBackground,fontSize:`12px`,lineHeight:`12px`},children:d}):null,` `,f&&!d?v(`span`,{style:{fontWeight:`normal`,color:this.config.theme?.colors?.linkCardSubTitle,fontSize:`12px`,lineHeight:`12px`},children:f}):null]}):null]}),y(h,{style:{fontSize:`16px`,color:this.config.theme?.colors?.linkCardDescription,marginTop:`0px`,marginBottom:`0px`,...P},children:[o,` `,c?v(`a`,{href:m,rel:`noopener noreferrer`,style:{color:this.config.theme?.colors?.linkCardTitle,fontSize:`14px`,fontWeight:600,textDecoration:`underline`},children:c}):null]})]})})]})}section(e,t){let{attrs:n}=e,{borderRadius:i=0,backgroundColor:a=I,align:o=L,borderWidth:s=R,borderColor:c=z,marginTop:l=B,marginRight:u=V,marginBottom:d=H,marginLeft:f=U,paddingTop:m=W,paddingRight:h=G,paddingBottom:g=K,paddingLeft:y=q}=n||{},b=this.shouldShow(e,t);return b?v(p,{style:{marginTop:l,marginRight:u,marginBottom:d,marginLeft:f},children:v(r,{align:o,style:{borderColor:c,borderWidth:s,borderStyle:`solid`,backgroundColor:a,borderRadius:i,paddingTop:m,paddingRight:h,paddingBottom:g,paddingLeft:y},children:this.getMappedContent(e,{...t,parent:e})})}):v(_,{})}columns(e,t){let{attrs:n}=e,r=this.shouldShow(e,t);if(!r)return v(_,{});let[i,a]=this.adjustColumnsContent(e);return v(p,{width:`${a}%`,style:{margin:0,padding:0,width:`${a}%`},className:`tab-row-full`,children:this.getMappedContent(i,{...t,parent:i})})}adjustColumnsContent(e){let{content:t=[]}=e,n=100,r=t.filter(e=>e.type===`column`&&!!Number(e.attrs?.width||0)),i=t.filter(e=>e.type===`column`&&(e.attrs?.width===`auto`||!e.attrs?.width)),a=r.reduce((e,t)=>e+Number(t.attrs?.width),0),o=n-a,s=Math.round(o/i.length),c=t.filter(e=>e.type===`column`).length,l=e.attrs?.gap??J;return[{...e,content:t.map((e,n)=>{let r=e.type===`column`&&(e.attrs?.width===`auto`||!e.attrs?.width),i=n===0,a=n>0&&n<c-1,o=n===t.length-1,u=0,d=0;if(c<3)u=i?0:l/2,d=o?0:l/2;else{let e=l/2*1.5,t=e/2;u=i?0:a?t:e,d=o?0:a?t:e}return u=Math.round(u*100)/100,d=Math.round(d*100)/100,{...e,attrs:{...e.attrs,width:r?s:e.attrs?.width,isFirstColumn:i,isLastColumn:o,index:n,paddingLeft:u,paddingRight:d}}})},i.length===0?Math.min(n,a):n]}column(e,t){let{attrs:n}=e,{width:i,verticalAlign:a=`top`,paddingLeft:o=0,paddingRight:s=0}=n||{};return v(r,{width:`${Number(i)}%`,style:{width:`${Number(i)}%`,margin:0,verticalAlign:a},className:`tab-col-full`,children:v(m,{style:{margin:0,paddingLeft:o,paddingRight:s},className:`tab-pad`,children:this.getMappedContent(e,{...t,parent:e})})})}repeat(t,n){let{attrs:r}=t,{each:i=``}=r||{},a=this.shouldShow(t,n);if(!a)return v(_,{});let{payloadValue:o}=n||{};o=typeof o==`object`?o:{};let s=this.payloadValues.get(i)??o[i]??[];if(!Array.isArray(s))throw Error(`Payload value for each "${i}" is not an array`);return v(_,{children:s.map(r=>v(e,{children:this.getMappedContent(t,{...n,parent:t,payloadValue:r})},D()))})}for(e,t){return this.repeat(e,t)}shouldShow(e,t){let n=e?.attrs?.showIfKey??``;if(!n)return!0;let{payloadValue:r}=t||{};return r=typeof r==`object`?r:{},!!(this.payloadValues.get(n)??r[n])}htmlCodeBlock(e,t){let n=this.shouldShow(e,t);if(!n)return v(_,{});let r=e.content?.reduce((e,n)=>{if(n?.type===`text`)return e+n?.text;if(n?.type===`variable`){let r=this.getVariableValue(n?.attrs?.id,n?.attrs?.fallback,t);return e+r}return e},``)||``,i=x(r),a=b(i),o=a?.querySelector(`head`);o?.remove();let s=a.toString();return v(`table`,{align:`left`,width:`100%`,border:0,cellPadding:`0`,cellSpacing:`0`,role:`presentation`,children:v(`tbody`,{children:v(`tr`,{style:{width:`100%`},children:v(`td`,{style:{width:`100%`},dangerouslySetInnerHTML:{__html:s}})})})})}inlineImage(e,t){let{attrs:n}=e,{src:r,isSrcVariable:i,alt:a=``,title:o=``,height:s=Y,width:c=X,externalLink:l=``,isExternalLinkVariable:u}=n||{};r=i?this.variableUrlValue(r,t):r,l=u?this.variableUrlValue(l,t):l;let d=v(`img`,{src:r,alt:a,title:o,width:c,height:s,style:{display:`inline`,verticalAlign:`middle`,width:`${c}px`,height:`${s}px`,outline:`none`,border:`none`,textDecoration:`none`}});return l?v(`a`,{href:l,rel:`noopener noreferrer`,style:{display:`inline`,textDecoration:`none`},target:`_blank`,children:d}):d}};async function he(e,t){let{theme:n,preview:r,...i}=t||{},a=new me(e);return a.setPreviewText(r),a.setTheme(n||{}),a.render(i)}export{J as DEFAULT_COLUMNS_GAP,ie as DEFAULT_COLUMNS_WIDTH,ae as DEFAULT_COLUMN_BACKGROUND_COLOR,ce as DEFAULT_COLUMN_BORDER_COLOR,oe as DEFAULT_COLUMN_BORDER_RADIUS,se as DEFAULT_COLUMN_BORDER_WIDTH,de as DEFAULT_COLUMN_PADDING_BOTTOM,fe as DEFAULT_COLUMN_PADDING_LEFT,ue as DEFAULT_COLUMN_PADDING_RIGHT,le as DEFAULT_COLUMN_PADDING_TOP,$ as DEFAULT_HTML_PROPS,Y as DEFAULT_INLINE_IMAGE_HEIGHT,X as DEFAULT_INLINE_IMAGE_WIDTH,Q as DEFAULT_META_TAGS,L as DEFAULT_SECTION_ALIGN,I as DEFAULT_SECTION_BACKGROUND_COLOR,z as DEFAULT_SECTION_BORDER_COLOR,R as DEFAULT_SECTION_BORDER_WIDTH,H as DEFAULT_SECTION_MARGIN_BOTTOM,U as DEFAULT_SECTION_MARGIN_LEFT,V as DEFAULT_SECTION_MARGIN_RIGHT,B as DEFAULT_SECTION_MARGIN_TOP,K as DEFAULT_SECTION_PADDING_BOTTOM,q as DEFAULT_SECTION_PADDING_LEFT,G as DEFAULT_SECTION_PADDING_RIGHT,W as DEFAULT_SECTION_PADDING_TOP,Z as LINK_PROTOCOL_REGEX,me as Maily,he as render};
1
+ import { BUTTON_KINDS, DEFAULT_FONT, DEFAULT_FONT_FAMILIES, DEFAULT_RENDERER_THEME, MAILY_MARK_TYPES, MAILY_NODE_TYPES, TEXT_ALIGNMENTS, TEXT_DIRECTIONS, VISIBILITY_ACTIONS, VISIBILITY_OPERATORS, absoluteFromPercentage, buildDocFromVariableText, getBorderStyle, getCssDirection, getFontFaceStyle, getFontStyle, getMarginStyle, getPaddingStyle, hasVariableInText, is, isDef, isObject, parseWidthToPercentage, roundTo } from "@maily-to/shared";
2
+ import { Fragment, cloneElement, isValidElement } from "react";
3
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
+ import { Body, Button, Column, Container, Head, Heading, Hr, Html, Img, Preview, Row, Section, Text } from "@react-email/components";
5
+ import juice from "juice";
6
+ import { parse } from "node-html-parser";
7
+ import { migrate } from "@maily-to/migration";
8
+ import { render as render$1 } from "@react-email/render";
9
+ //#region src/lib/font-face.ts
10
+ /**
11
+ * Registers a font face in the context's shared font collector.
12
+ * Deduplicates by family+style+weight+fallback so each variant
13
+ * only appears once in the final `<style>` block.
14
+ */
15
+ function registerFontFace(ctx, font) {
16
+ const { fontFamily, fontWeight = 400, fallbackFontFamily, fontStyle = "normal" } = font;
17
+ if (!fontFamily) return;
18
+ const key = `${fontFamily}:${fontStyle}:${fontWeight}:${fallbackFontFamily}`;
19
+ if (ctx.fonts.has(key)) return;
20
+ ctx.font(key, font);
21
+ }
22
+ /**
23
+ * Resolves a complete FontProps from a node's font style attributes
24
+ * (falling back to the theme font and CDN entries) and registers it.
25
+ * Called by node renderers that support per-node font overrides.
26
+ */
27
+ function prepareAndRegisterFontFaceFromAttrs(ctx, attrs, defaults) {
28
+ const primaryFont = ctx.config.theme.font ?? DEFAULT_FONT;
29
+ if (!primaryFont) return;
30
+ const { fontFamily, fontWeight, fontFallback, fontStyle } = attrs;
31
+ const family = fontFamily ?? primaryFont.fontFamily;
32
+ if (!family) return;
33
+ const weight = fontWeight ?? defaults?.fontWeight ?? 400;
34
+ const style = fontStyle ?? defaults?.fontStyle ?? "normal";
35
+ const fallback = fontFallback ?? primaryFont.fallbackFontFamily;
36
+ const webFont = fontFamily ? ctx.config.fontFamilies.find((f) => f.fontFamily === fontFamily)?.webFont : primaryFont.webFont;
37
+ registerFontFace(ctx, {
38
+ fontFamily: family,
39
+ fontWeight: weight,
40
+ fallbackFontFamily: fallback,
41
+ fontStyle: style,
42
+ ...webFont && { webFont }
43
+ });
44
+ }
45
+ //#endregion
46
+ //#region src/lib/spacing.ts
47
+ const BLOCK_CONTAINERS = new Set([
48
+ MAILY_NODE_TYPES.DOCUMENT,
49
+ MAILY_NODE_TYPES.SECTION,
50
+ MAILY_NODE_TYPES.COLUMN,
51
+ MAILY_NODE_TYPES.REPEAT
52
+ ]);
53
+ /**
54
+ * Returns true if this node's top margin should be collapsed — i.e. it's
55
+ * the first child of a block container or follows a spacer node.
56
+ */
57
+ function shouldSuppressMarginTop(ctx) {
58
+ const { parent, siblingIndex } = ctx;
59
+ if (!parent || !is.node(parent) || !is.parent(parent)) return true;
60
+ if (!BLOCK_CONTAINERS.has(parent.type)) return true;
61
+ const prev = parent.content[siblingIndex - 1];
62
+ const isFirst = siblingIndex === 0;
63
+ const isPrevSpacer = prev?.type === MAILY_NODE_TYPES.SPACER;
64
+ return isFirst || isPrevSpacer;
65
+ }
66
+ /**
67
+ * Returns true if this node's bottom margin should be collapsed — i.e. it's
68
+ * the last child of a block container, or is followed by a spacer or hr.
69
+ */
70
+ function shouldSuppressMarginBottom(ctx) {
71
+ const { parent, siblingIndex } = ctx;
72
+ if (!parent || !is.node(parent) || !is.parent(parent)) return true;
73
+ if (parent.type === MAILY_NODE_TYPES.LIST_ITEM) return true;
74
+ if (!BLOCK_CONTAINERS.has(parent.type)) return true;
75
+ const content = parent.content;
76
+ const next = content[siblingIndex + 1];
77
+ const isLast = siblingIndex === content.length - 1;
78
+ const isNextSpacer = next?.type === MAILY_NODE_TYPES.SPACER;
79
+ const isNextHr = next?.type === MAILY_NODE_TYPES.HORIZONTAL_RULE;
80
+ return isLast || isNextSpacer || isNextHr;
81
+ }
82
+ //#endregion
83
+ //#region src/nodes/blockquote.tsx
84
+ const blockquote = (node, ctx) => {
85
+ if (!is.blockquote(node)) return null;
86
+ const { dir } = node.attrs;
87
+ const theme = ctx.config.theme;
88
+ const fontStyle = getFontStyle(node.attrs, theme.blockquote);
89
+ prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.blockquote);
90
+ return /* @__PURE__ */ jsx("blockquote", {
91
+ style: {
92
+ borderLeftWidth: "4px",
93
+ borderLeftStyle: "solid",
94
+ borderLeftColor: theme.blockquote?.borderColor,
95
+ paddingLeft: "16px",
96
+ marginLeft: "0px",
97
+ marginRight: "0px",
98
+ marginTop: shouldSuppressMarginTop(ctx) ? 0 : 20,
99
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
100
+ color: theme.blockquote?.color,
101
+ ...getCssDirection(dir),
102
+ ...fontStyle
103
+ },
104
+ children: ctx.children(node)
105
+ });
106
+ };
107
+ //#endregion
108
+ //#region src/nodes/bullet-list.tsx
109
+ const bulletList = (node, ctx) => {
110
+ if (!is.bulletList(node)) return null;
111
+ const { dir } = node.attrs;
112
+ return /* @__PURE__ */ jsx(Container, {
113
+ style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20 },
114
+ children: /* @__PURE__ */ jsx("ul", {
115
+ style: {
116
+ paddingLeft: 26,
117
+ listStyleType: "disc",
118
+ margin: 0,
119
+ ...getCssDirection(dir)
120
+ },
121
+ children: ctx.children(node)
122
+ })
123
+ });
124
+ };
125
+ //#endregion
126
+ //#region src/lib/resolve-variable.ts
127
+ /**
128
+ * Resolves a single variable ID using the 3-stage lookup:
129
+ * 1. item (current repeat iteration)
130
+ * 2. variableValues map
131
+ * 3. variableFormatter (fallback)
132
+ */
133
+ function resolveVariableId(id, fallback, ctx) {
134
+ const { config } = ctx;
135
+ const item = ctx.get("item");
136
+ if (item && id in item) return String(item[id]);
137
+ const varValue = config.variableValues.get(id);
138
+ if (varValue !== void 0) {
139
+ if (typeof varValue === "object") return JSON.stringify(varValue);
140
+ return String(varValue);
141
+ }
142
+ return config.variableFormatter({
143
+ variable: id,
144
+ fallback: fallback ?? void 0
145
+ });
146
+ }
147
+ /**
148
+ * Resolves a text string that may contain `{{variable}}` placeholders.
149
+ * Returns the original string unchanged if no placeholders are present.
150
+ */
151
+ function resolveVariableText(text, ctx) {
152
+ if (!hasVariableInText(text)) return text;
153
+ const paragraph = buildDocFromVariableText(text).content.find((node) => node.type === MAILY_NODE_TYPES.PARAGRAPH);
154
+ if (!paragraph) return text;
155
+ return paragraph.content.map((node) => {
156
+ if (node.type === MAILY_NODE_TYPES.TEXT) return node.text;
157
+ if (node.type === MAILY_NODE_TYPES.VARIABLE) {
158
+ const { id, fallback } = node.attrs;
159
+ if (!id) return "";
160
+ return resolveVariableId(id, fallback, ctx);
161
+ }
162
+ return "";
163
+ }).join("");
164
+ }
165
+ //#endregion
166
+ //#region src/lib/visibility.ts
167
+ /**
168
+ * Evaluates a node's visibility rule against the current variables.
169
+ * Returns true (visible) when there's no rule, or when the rule
170
+ * matches for "show" / doesn't match for "hide".
171
+ */
172
+ function shouldShow(node, ctx) {
173
+ const rule = node.attrs?.visibilityRule;
174
+ if (!rule || rule.action === VISIBILITY_ACTIONS.NONE) return true;
175
+ const { action, variable, operator, value } = rule;
176
+ const item = ctx.get("item");
177
+ let resolvedValue;
178
+ if (item && variable in item) resolvedValue = item[variable];
179
+ else resolvedValue = ctx.config.variableValues.get(variable);
180
+ const matched = evaluate(operator, resolvedValue, value);
181
+ if (action === VISIBILITY_ACTIONS.SHOW) return matched;
182
+ if (action === VISIBILITY_ACTIONS.HIDE) return !matched;
183
+ return true;
184
+ }
185
+ function evaluate(operator, resolvedValue, compareValue) {
186
+ switch (operator) {
187
+ case VISIBILITY_OPERATORS.IS_TRUE: return Boolean(resolvedValue);
188
+ case VISIBILITY_OPERATORS.IS_FALSE: return !resolvedValue;
189
+ case VISIBILITY_OPERATORS.EQUALS: return String(resolvedValue) === compareValue;
190
+ case VISIBILITY_OPERATORS.NOT_EQUALS: return String(resolvedValue) !== compareValue;
191
+ case VISIBILITY_OPERATORS.CONTAINS: return String(resolvedValue).includes(compareValue);
192
+ case VISIBILITY_OPERATORS.NOT_CONTAINS: return !String(resolvedValue).includes(compareValue);
193
+ case VISIBILITY_OPERATORS.STARTS_WITH: return String(resolvedValue).startsWith(compareValue);
194
+ case VISIBILITY_OPERATORS.ENDS_WITH: return String(resolvedValue).endsWith(compareValue);
195
+ case VISIBILITY_OPERATORS.GREATER_THAN: return Number(resolvedValue) > Number(compareValue);
196
+ case VISIBILITY_OPERATORS.LESS_THAN: return Number(resolvedValue) < Number(compareValue);
197
+ default: return false;
198
+ }
199
+ }
200
+ //#endregion
201
+ //#region src/nodes/button.tsx
202
+ const button = (node, ctx) => {
203
+ if (!is.button(node)) return null;
204
+ if (!shouldShow(node, ctx)) return null;
205
+ const attrs = node.attrs;
206
+ const { dir } = attrs;
207
+ const theme = ctx.config.theme;
208
+ const backgroundColor = attrs.backgroundColor ?? theme.button?.backgroundColor;
209
+ const color = attrs.color ?? theme.button?.color;
210
+ const url = resolveVariableText(attrs.url ?? "", ctx);
211
+ const kind = attrs.kind ?? BUTTON_KINDS.TIGHT;
212
+ const alignment = attrs.alignment ?? TEXT_ALIGNMENTS.CENTER;
213
+ const isFullWidth = kind === BUTTON_KINDS.FULL_WIDTH;
214
+ const paddingTop = attrs.paddingTop ?? theme.button?.paddingTop ?? 10;
215
+ const paddingRight = attrs.paddingRight ?? theme.button?.paddingRight ?? 32;
216
+ const paddingBottom = attrs.paddingBottom ?? theme.button?.paddingBottom ?? 10;
217
+ const paddingLeft = attrs.paddingLeft ?? theme.button?.paddingLeft ?? 32;
218
+ const borderStyle = getBorderStyle(attrs);
219
+ const fontStyle = getFontStyle(attrs, theme.button);
220
+ prepareAndRegisterFontFaceFromAttrs(ctx, attrs, theme.button);
221
+ const containerStyle = {
222
+ textAlign: alignment,
223
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20
224
+ };
225
+ if (isFullWidth) return /* @__PURE__ */ jsx(Container, {
226
+ style: containerStyle,
227
+ children: /* @__PURE__ */ jsx("table", {
228
+ width: "100%",
229
+ cellPadding: "0",
230
+ cellSpacing: "0",
231
+ border: 0,
232
+ role: "presentation",
233
+ children: /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
234
+ align: alignment,
235
+ style: {
236
+ backgroundColor,
237
+ paddingTop,
238
+ paddingRight,
239
+ paddingBottom,
240
+ paddingLeft,
241
+ ...borderStyle,
242
+ ...getCssDirection(dir)
243
+ },
244
+ children: /* @__PURE__ */ jsx("a", {
245
+ href: url,
246
+ target: "_blank",
247
+ style: {
248
+ color,
249
+ textDecoration: "none",
250
+ display: "block",
251
+ textAlign: alignment,
252
+ ...fontStyle
253
+ },
254
+ children: ctx.children(node)
255
+ })
256
+ }) }) })
257
+ })
258
+ });
259
+ return /* @__PURE__ */ jsx(Container, {
260
+ style: containerStyle,
261
+ children: /* @__PURE__ */ jsx(Button, {
262
+ href: url,
263
+ style: {
264
+ backgroundColor,
265
+ color,
266
+ paddingTop,
267
+ paddingRight,
268
+ paddingBottom,
269
+ paddingLeft,
270
+ display: "inline-block",
271
+ ...borderStyle,
272
+ ...getCssDirection(dir),
273
+ ...fontStyle
274
+ },
275
+ children: ctx.children(node)
276
+ })
277
+ });
278
+ };
279
+ //#endregion
280
+ //#region src/nodes/column.tsx
281
+ const column = (node, ctx) => {
282
+ if (!is.column(node)) return null;
283
+ const attrs = node.attrs;
284
+ const width = ctx.get("columnTdWidth") ?? (attrs.width === null ? void 0 : `${attrs.width}%`);
285
+ return /* @__PURE__ */ jsx(Column, {
286
+ width,
287
+ className: "tab-col-full",
288
+ style: {
289
+ margin: 0,
290
+ width,
291
+ verticalAlign: attrs.verticalAlign
292
+ },
293
+ children: ctx.children(node)
294
+ });
295
+ };
296
+ //#endregion
297
+ //#region src/lib/columns.ts
298
+ /**
299
+ * Simulates CSS `flexbox gap` using table-cell percentages.
300
+ *
301
+ * Since tables don't support `gap`, we create empty spacer `<td>` cells
302
+ * between columns. This function calculates how wide each column and
303
+ * spacer should be so the layout behaves similar to flexbox.
304
+ *
305
+ * How the gap affects the layout depends on the column configuration:
306
+ *
307
+ * 1. When there are auto-width columns
308
+ * The row always fills 100% of the container.
309
+ * Fixed columns keep their exact width, and auto columns divide
310
+ * the remaining space after subtracting fixed widths and gaps.
311
+ *
312
+ * Example:
313
+ * fixed 40% + auto column, gap 8px in a 600px container
314
+ * → auto column becomes ~58.667%
315
+ *
316
+ * 2. When all columns have fixed widths and still fit
317
+ * The row width becomes `fixed widths + gaps`, which may be
318
+ * smaller than 100%. Columns keep their exact size.
319
+ *
320
+ * Example:
321
+ * 20% + 20% columns, gap 8px in a 600px container
322
+ * → row width becomes ~41.333%
323
+ *
324
+ * 3. When all columns are fixed but overflow
325
+ * If `fixed widths + gaps` exceed 100%, everything is scaled
326
+ * down proportionally so the row never exceeds the container.
327
+ *
328
+ * Example:
329
+ * 50% + 50% columns with gap 8px
330
+ * → both columns shrink to ~49.342%
331
+ */
332
+ function calculateColumnLayout(columnNodes, gap, containerBox) {
333
+ const count = columnNodes.length;
334
+ if (count === 0) return {
335
+ columns: [],
336
+ rowWidthPercent: 0,
337
+ gapTdWidthPercent: 0
338
+ };
339
+ const gapCount = count - 1;
340
+ const gapPercent = gapCount > 0 && containerBox > 0 ? roundTo(gap / containerBox * 100, 3) : 0;
341
+ const totalGapPercent = roundTo(gapCount * gapPercent, 3);
342
+ const fixedSum = columnNodes.reduce((sum, col) => sum + (col.attrs.width ?? 0), 0);
343
+ const autoCount = columnNodes.filter((col) => col.attrs.width === null).length;
344
+ const autoEach = autoCount > 0 ? roundTo(Math.max(0, 100 - fixedSum - totalGapPercent) / autoCount, 3) : 0;
345
+ let containerPercents = columnNodes.map((col) => col.attrs.width ?? autoEach);
346
+ let rowWidthPercent = autoCount > 0 ? 100 : roundTo(fixedSum + totalGapPercent, 3);
347
+ let effectiveGapPercent = gapPercent;
348
+ if (autoCount === 0 && rowWidthPercent > 100) {
349
+ const scale = 100 / rowWidthPercent;
350
+ containerPercents = containerPercents.map((p) => roundTo(p * scale, 3));
351
+ effectiveGapPercent = roundTo(gapPercent * scale, 3);
352
+ rowWidthPercent = 100;
353
+ }
354
+ const gapTdWidthPercent = rowWidthPercent > 0 ? roundTo(effectiveGapPercent / rowWidthPercent * 100, 3) : 0;
355
+ return {
356
+ columns: columnNodes.map((col, i) => {
357
+ const containerPercent = containerPercents[i];
358
+ const tdWidthPercent = rowWidthPercent > 0 ? roundTo(containerPercent / rowWidthPercent * 100, 3) : 0;
359
+ return {
360
+ node: {
361
+ ...col,
362
+ attrs: {
363
+ ...col.attrs,
364
+ width: col.attrs.width ?? containerPercent
365
+ }
366
+ },
367
+ containerPercent,
368
+ tdWidthPercent
369
+ };
370
+ }),
371
+ rowWidthPercent,
372
+ gapTdWidthPercent
373
+ };
374
+ }
375
+ //#endregion
376
+ //#region src/nodes/columns.tsx
377
+ const COLUMNS_RESPONSIVE_CSS = `@media only screen and (max-width:425px){.tab-row-full{width:100%!important}.tab-col-full{display:block!important;width:100%!important}.tab-gap{display:none!important}}`;
378
+ const columns = (node, ctx) => {
379
+ if (!is.columns(node)) return null;
380
+ ctx.style(COLUMNS_RESPONSIVE_CSS);
381
+ const { gap = 0 } = node.attrs;
382
+ const { columns, rowWidthPercent, gapTdWidthPercent } = calculateColumnLayout(node.content.filter(is.column), gap, ctx.box);
383
+ if (columns.length === 0) return null;
384
+ const width = `${rowWidthPercent}%`;
385
+ return /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsx(Row, {
386
+ className: "tab-row-full",
387
+ width,
388
+ style: { width },
389
+ align: TEXT_ALIGNMENTS.LEFT,
390
+ children: columns.flatMap((item, index) => {
391
+ const widthInPixels = absoluteFromPercentage(item.containerPercent, ctx.box);
392
+ const childCtx = ctx.child({
393
+ parent: node,
394
+ siblingIndex: index,
395
+ size: {
396
+ totalWidth: widthInPixels,
397
+ totalBorder: 0,
398
+ totalPadding: 0
399
+ }
400
+ });
401
+ const tdWidth = `${item.tdWidthPercent}%`;
402
+ childCtx.set("columnTdWidth", tdWidth);
403
+ const el = childCtx.render(item.node);
404
+ const colEl = isValidElement(el) ? cloneElement(el, { key: item.node.attrs.id }) : null;
405
+ if (index < columns.length - 1 && gap > 0) {
406
+ const gapWidth = `${gapTdWidthPercent}%`;
407
+ const gapKey = `gap-${item.node.attrs.id}`;
408
+ return [colEl, /* @__PURE__ */ jsx(Column, {
409
+ className: "tab-gap",
410
+ width: gapWidth,
411
+ style: { width: gapWidth }
412
+ }, gapKey)];
413
+ }
414
+ return [colEl];
415
+ })
416
+ }) });
417
+ };
418
+ //#endregion
419
+ //#region src/lib/meta.tsx
420
+ /**
421
+ * Deduplication key for a meta descriptor. Uses a sorted-key JSON hash
422
+ * so `{ name: 'a', content: 'b' }` and `{ content: 'b', name: 'a' }`
423
+ * produce the same key.
424
+ */
425
+ function hash(descriptor) {
426
+ const sorted = Object.keys(descriptor).sort().reduce((acc, key) => {
427
+ acc[key] = descriptor[key];
428
+ return acc;
429
+ }, {});
430
+ return JSON.stringify(sorted);
431
+ }
432
+ /**
433
+ * Converts MetaDescriptor objects into React elements for the `<head>`.
434
+ * Duplicates (by sorted-key JSON hash) are skipped.
435
+ */
436
+ function meta(descriptors) {
437
+ const seen = /* @__PURE__ */ new Set();
438
+ const elements = [];
439
+ for (const descriptor of descriptors) {
440
+ const key = hash(descriptor);
441
+ if (seen.has(key)) continue;
442
+ seen.add(key);
443
+ const element = process(descriptor, key);
444
+ if (element) elements.push(element);
445
+ }
446
+ return elements;
447
+ }
448
+ function process(descriptor, key) {
449
+ if ("charSet" in descriptor) return /* @__PURE__ */ jsx("meta", { charSet: descriptor.charSet }, key);
450
+ if ("title" in descriptor) return /* @__PURE__ */ jsx("title", { children: descriptor.title }, key);
451
+ if ("tagName" in descriptor) {
452
+ const { tagName, ...attrs } = descriptor;
453
+ if (tagName === "link") return /* @__PURE__ */ jsx("link", { ...attrs }, key);
454
+ return /* @__PURE__ */ jsx("meta", { ...attrs }, key);
455
+ }
456
+ const attrs = descriptor;
457
+ if ("httpEquiv" in attrs) {
458
+ const { httpEquiv, ...rest } = attrs;
459
+ return /* @__PURE__ */ jsx("meta", {
460
+ httpEquiv,
461
+ ...rest
462
+ }, key);
463
+ }
464
+ return /* @__PURE__ */ jsx("meta", { ...attrs }, key);
465
+ }
466
+ //#endregion
467
+ //#region src/lib/preview.ts
468
+ /**
469
+ * Resolves a preview value to a plain string.
470
+ *
471
+ * - `string` → resolves `{{variable}}` placeholders
472
+ * - `JSONContent` → walks the tree and resolves variable nodes
473
+ */
474
+ function preview(preview, ctx) {
475
+ if (typeof preview === "string") return resolveVariableText(preview, ctx);
476
+ return walk(preview, ctx);
477
+ }
478
+ function walk(doc, ctx) {
479
+ const parts = [];
480
+ if (!is.node(doc)) return parts.join("");
481
+ function visitor(node) {
482
+ if (is.text(node)) parts.push(node.text ?? "");
483
+ if (is.variable(node)) {
484
+ const { id, fallback } = node.attrs;
485
+ if (!id) return;
486
+ parts.push(resolveVariableId(id, fallback ?? void 0, ctx));
487
+ }
488
+ if (is.parent(node)) node.content.forEach(visitor);
489
+ }
490
+ visitor(doc);
491
+ return parts.join("");
492
+ }
493
+ //#endregion
494
+ //#region src/lib/sizing.ts
495
+ /**
496
+ * Extracts a numeric pixel value from a CSS string (e.g. "12px" → 12).
497
+ * Returns 0 for undefined, non-px strings, or NaN results.
498
+ */
499
+ function parsePxValue(value) {
500
+ if (value === void 0 || value === null) return 0;
501
+ if (typeof value === "number") return value;
502
+ const trimmed = value.trim();
503
+ if (trimmed.endsWith("px")) {
504
+ const n = parseFloat(trimmed);
505
+ return isNaN(n) ? 0 : n;
506
+ }
507
+ return 0;
508
+ }
509
+ /**
510
+ * Creates a fresh BoxModel with the given total width and zero
511
+ * border/padding. Used as the starting point for layout calculations.
512
+ */
513
+ function initSize(totalWidth) {
514
+ return {
515
+ totalWidth,
516
+ totalBorder: 0,
517
+ totalPadding: 0
518
+ };
519
+ }
520
+ /**
521
+ * Accumulates horizontal border and padding into a BoxModel.
522
+ * The total width stays the same — the usable content area shrinks.
523
+ */
524
+ function insetBox(size, spacing) {
525
+ const totalBorder = size.totalBorder + parsePxValue(spacing.borderLeft) + parsePxValue(spacing.borderRight);
526
+ const totalPadding = size.totalPadding + parsePxValue(spacing.paddingLeft) + parsePxValue(spacing.paddingRight);
527
+ return {
528
+ totalWidth: size.totalWidth,
529
+ totalBorder,
530
+ totalPadding
531
+ };
532
+ }
533
+ //#endregion
534
+ //#region src/nodes/document.tsx
535
+ const BASE_CSS = `blockquote,h1,h2,h3,img,li,ol,p,ul{margin-top:0;margin-bottom:0}`;
536
+ const document = (node, ctx) => {
537
+ if (!is.doc(node)) return null;
538
+ const { dir } = node.attrs;
539
+ const { theme, preview: preview$1, meta: meta$1, htmlProps, openTrackingPixel } = ctx.config;
540
+ const font = theme.font;
541
+ const container = theme.container ?? {};
542
+ const body = theme.body ?? {};
543
+ const size = insetBox(initSize(parsePxValue(container.maxWidth)), {
544
+ paddingLeft: parsePxValue(container.paddingLeft) + parsePxValue(body.paddingLeft),
545
+ paddingRight: parsePxValue(container.paddingRight) + parsePxValue(body.paddingRight),
546
+ borderLeft: container.borderWidth,
547
+ borderRight: container.borderWidth
548
+ });
549
+ const primaryFont = font === void 0 ? DEFAULT_FONT : font;
550
+ if (primaryFont) registerFontFace(ctx, primaryFont);
551
+ const child = ctx.child({ size }).children(node);
552
+ for (const fontEntry of ctx.fonts.values()) ctx.style(getFontFaceStyle(fontEntry));
553
+ const css = BASE_CSS + Array.from(ctx.styles).join("");
554
+ const bodyStyle = {
555
+ ...body,
556
+ ...primaryFont && primaryFont.fontFamily ? { fontFamily: `'${primaryFont.fontFamily}', ${primaryFont.fallbackFontFamily}` } : {}
557
+ };
558
+ const resolvedPreview = preview$1 ? preview(preview$1, ctx.child({ size })) : null;
559
+ return /* @__PURE__ */ jsxs(Html, {
560
+ lang: "en",
561
+ ...htmlProps,
562
+ ...dir && dir !== TEXT_DIRECTIONS.AUTO ? { dir } : {},
563
+ children: [/* @__PURE__ */ jsxs(Head, { children: [
564
+ /* @__PURE__ */ jsx("meta", {
565
+ httpEquiv: "X-UA-Compatible",
566
+ content: "IE=edge"
567
+ }),
568
+ /* @__PURE__ */ jsx("meta", { name: "x-apple-disable-message-reformatting" }),
569
+ /* @__PURE__ */ jsx("meta", {
570
+ name: "format-detection",
571
+ content: "telephone=no,address=no,email=no,date=no,url=no"
572
+ }),
573
+ /* @__PURE__ */ jsx("meta", {
574
+ name: "color-scheme",
575
+ content: "light"
576
+ }),
577
+ /* @__PURE__ */ jsx("meta", {
578
+ name: "supported-color-schemes",
579
+ content: "light"
580
+ }),
581
+ meta(meta$1),
582
+ /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: css } })
583
+ ] }), /* @__PURE__ */ jsxs(Body, {
584
+ style: bodyStyle,
585
+ children: [resolvedPreview && /* @__PURE__ */ jsx(Preview, { children: resolvedPreview }), /* @__PURE__ */ jsxs(Container, {
586
+ style: container,
587
+ children: [child, openTrackingPixel && /* @__PURE__ */ jsx(Img, {
588
+ src: openTrackingPixel,
589
+ width: "1",
590
+ height: "1",
591
+ alt: "",
592
+ style: { display: "none" }
593
+ })]
594
+ })]
595
+ })]
596
+ });
597
+ };
598
+ //#endregion
599
+ //#region src/lib/styles.ts
600
+ /**
601
+ * Cross-browser font smoothing properties. Applied to the document
602
+ * root so all text renders with subpixel antialiasing disabled.
603
+ */
604
+ const ANTIALIASED = {
605
+ WebkitFontSmoothing: "antialiased",
606
+ MozOsxFontSmoothing: "grayscale"
607
+ };
608
+ //#endregion
609
+ //#region src/nodes/footer.tsx
610
+ const footer = (node, ctx) => {
611
+ if (!is.footer(node)) return null;
612
+ const { textAlign, dir } = node.attrs;
613
+ const theme = ctx.config.theme;
614
+ const fontStyle = getFontStyle(node.attrs, theme.footer);
615
+ prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.footer);
616
+ return /* @__PURE__ */ jsx(Text, {
617
+ style: {
618
+ ...textAlign ? { textAlign } : {},
619
+ ...getCssDirection(dir),
620
+ color: theme.footer?.color,
621
+ marginTop: 0,
622
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
623
+ ...ANTIALIASED,
624
+ ...fontStyle
625
+ },
626
+ children: ctx.children(node)
627
+ });
628
+ };
629
+ //#endregion
630
+ //#region src/nodes/hard-break.tsx
631
+ const hardBreak = () => {
632
+ return /* @__PURE__ */ jsx("br", {});
633
+ };
634
+ //#endregion
635
+ //#region src/nodes/heading.tsx
636
+ const HEADING_LEVELS = {
637
+ 1: "h1",
638
+ 2: "h2",
639
+ 3: "h3"
640
+ };
641
+ const heading = (node, ctx) => {
642
+ if (!is.heading(node)) return null;
643
+ const { level, textAlign, dir } = node.attrs;
644
+ const theme = ctx.config.theme;
645
+ const element = HEADING_LEVELS[level];
646
+ const key = `h${level}`;
647
+ const defaults = theme.heading?.[key];
648
+ const fontStyle = getFontStyle(node.attrs, defaults);
649
+ prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, defaults);
650
+ return /* @__PURE__ */ jsx(Heading, {
651
+ as: element,
652
+ style: {
653
+ textAlign: textAlign ?? TEXT_ALIGNMENTS.LEFT,
654
+ ...getCssDirection(dir),
655
+ color: theme.heading?.defaults?.color,
656
+ marginTop: 0,
657
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 12,
658
+ ...fontStyle
659
+ },
660
+ children: ctx.children(node)
661
+ });
662
+ };
663
+ //#endregion
664
+ //#region src/nodes/horizontal-rule.tsx
665
+ const horizontalRule = (node, ctx) => {
666
+ if (!is.horizontalRule(node)) return null;
667
+ const theme = ctx.config.theme;
668
+ return /* @__PURE__ */ jsx(Hr, { style: {
669
+ borderColor: theme.horizontalRule?.color,
670
+ marginTop: shouldSuppressMarginTop(ctx) ? 0 : 32,
671
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32
672
+ } });
673
+ };
674
+ //#endregion
675
+ //#region src/nodes/html-code-block.tsx
676
+ function resolveText(node, ctx) {
677
+ if (node.type === MAILY_NODE_TYPES.TEXT && "text" in node) return node.text;
678
+ if (node.type === MAILY_NODE_TYPES.VARIABLE && "attrs" in node) {
679
+ const { id, fallback } = node.attrs;
680
+ if (!id) return "";
681
+ return resolveVariableId(id, fallback, ctx);
682
+ }
683
+ if (node.content && Array.isArray(node.content)) return node.content.map((child) => resolveText(child, ctx)).join("");
684
+ return "";
685
+ }
686
+ const htmlCodeBlock = (node, ctx) => {
687
+ if (!is.htmlCodeBlock(node)) return null;
688
+ const doc = parse(juice(node.content ? node.content.reduce((acc, child) => acc + resolveText(child, ctx), "") : ""));
689
+ doc.querySelector("head")?.remove();
690
+ const html = doc.toString();
691
+ return /* @__PURE__ */ jsx("table", {
692
+ align: "left",
693
+ width: "100%",
694
+ border: 0,
695
+ cellPadding: "0",
696
+ cellSpacing: "0",
697
+ role: "presentation",
698
+ style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32 },
699
+ children: /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", {
700
+ style: { width: "100%" },
701
+ children: /* @__PURE__ */ jsx("td", {
702
+ style: { width: "100%" },
703
+ dangerouslySetInnerHTML: { __html: html }
704
+ })
705
+ }) })
706
+ });
707
+ };
708
+ //#endregion
709
+ //#region src/nodes/image.tsx
710
+ const image = (node, ctx) => {
711
+ if (!is.image(node)) return null;
712
+ const { src, alt, title, width, align, externalLink } = node.attrs;
713
+ const resolvedSrc = resolveVariableText(src, ctx);
714
+ const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
715
+ const percent = parseWidthToPercentage(width, ctx.box);
716
+ const absoluteWidth = Math.round(ctx.box * percent / 100);
717
+ const img = /* @__PURE__ */ jsx(Img, {
718
+ src: resolvedSrc,
719
+ alt,
720
+ title,
721
+ width: absoluteWidth,
722
+ style: {
723
+ width: width ?? "100%",
724
+ maxWidth: absoluteWidth,
725
+ height: "auto",
726
+ display: "block",
727
+ ...getBorderStyle(node.attrs)
728
+ }
729
+ });
730
+ const content = resolvedExternalLink ? /* @__PURE__ */ jsx("a", {
731
+ href: resolvedExternalLink,
732
+ target: "_blank",
733
+ rel: "noopener noreferrer nofollow",
734
+ style: { display: "block" },
735
+ children: img
736
+ }) : img;
737
+ return /* @__PURE__ */ jsx(Row, {
738
+ style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 32 },
739
+ children: /* @__PURE__ */ jsx(Column, {
740
+ align: align ?? TEXT_ALIGNMENTS.LEFT,
741
+ children: content
742
+ })
743
+ });
744
+ };
745
+ //#endregion
746
+ //#region src/nodes/inline-image.tsx
747
+ const inlineImage = (node, ctx) => {
748
+ if (!is.inlineImage(node)) return null;
749
+ const { src, alt, width, height, externalLink } = node.attrs;
750
+ const resolvedSrc = resolveVariableText(src, ctx);
751
+ const resolvedExternalLink = externalLink ? resolveVariableText(externalLink, ctx) : externalLink;
752
+ const img = /* @__PURE__ */ jsx("img", {
753
+ src: resolvedSrc,
754
+ alt: alt ?? "",
755
+ width,
756
+ height,
757
+ style: {
758
+ display: "inline",
759
+ verticalAlign: "middle",
760
+ width,
761
+ height,
762
+ outline: "none",
763
+ border: "none",
764
+ textDecoration: "none"
765
+ }
766
+ });
767
+ if (resolvedExternalLink) return /* @__PURE__ */ jsx("a", {
768
+ href: resolvedExternalLink,
769
+ target: "_blank",
770
+ rel: "noopener noreferrer nofollow",
771
+ style: {
772
+ display: "inline",
773
+ textDecoration: "none"
774
+ },
775
+ children: img
776
+ });
777
+ return img;
778
+ };
779
+ //#endregion
780
+ //#region src/nodes/link-card.tsx
781
+ const linkCard = (node, ctx) => {
782
+ if (!is.linkCard(node)) return null;
783
+ if (!shouldShow(node, ctx)) return null;
784
+ const { title, description, link, linkTitle, image, subTitle, badgeText } = node.attrs;
785
+ const theme = ctx.config.theme.linkCard;
786
+ const href = (link ? resolveVariableText(link, ctx) : "") || "#";
787
+ return /* @__PURE__ */ jsxs("a", {
788
+ href,
789
+ rel: "noopener noreferrer",
790
+ style: {
791
+ border: `1px solid ${theme?.borderColor ?? "#eaeaea"}`,
792
+ borderRadius: 10,
793
+ textDecoration: "none",
794
+ color: "inherit",
795
+ display: "block",
796
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20
797
+ },
798
+ target: "_blank",
799
+ children: [image ? /* @__PURE__ */ jsx(Row, {
800
+ style: { marginBottom: 6 },
801
+ children: /* @__PURE__ */ jsx(Column, {
802
+ style: {
803
+ width: "100%",
804
+ height: "100%"
805
+ },
806
+ children: /* @__PURE__ */ jsx(Img, {
807
+ alt: title || "Link Card",
808
+ src: image,
809
+ style: {
810
+ borderRadius: "10px 10px 0 0",
811
+ width: "100%",
812
+ height: "100%",
813
+ objectFit: "cover"
814
+ },
815
+ title: title || "Link Card"
816
+ })
817
+ })
818
+ }) : null, /* @__PURE__ */ jsx(Row, {
819
+ style: {
820
+ padding: 15,
821
+ marginTop: 0,
822
+ marginBottom: 0
823
+ },
824
+ children: /* @__PURE__ */ jsxs(Column, {
825
+ style: { verticalAlign: "top" },
826
+ children: [/* @__PURE__ */ jsx(Row, {
827
+ style: {
828
+ marginBottom: 8,
829
+ marginTop: 0
830
+ },
831
+ width: "100%",
832
+ align: "left",
833
+ children: /* @__PURE__ */ jsx(Column, { children: /* @__PURE__ */ jsxs(Text, {
834
+ style: {
835
+ fontSize: 18,
836
+ fontWeight: 600,
837
+ color: theme?.titleColor ?? "#111827",
838
+ margin: 0,
839
+ textAlign: "left",
840
+ ...ANTIALIASED
841
+ },
842
+ children: [
843
+ title,
844
+ badgeText && /* @__PURE__ */ jsx("span", {
845
+ style: {
846
+ fontWeight: 600,
847
+ color: theme?.badgeTextColor ?? "#6B7280",
848
+ padding: "4px 8px",
849
+ borderRadius: "8px",
850
+ backgroundColor: theme?.badgeBackgroundColor ?? "#F3F4F6",
851
+ fontSize: "12px",
852
+ lineHeight: "12px",
853
+ marginLeft: "6px"
854
+ },
855
+ children: badgeText
856
+ }),
857
+ subTitle && !badgeText && /* @__PURE__ */ jsx("span", {
858
+ style: {
859
+ fontWeight: "normal",
860
+ color: theme?.subTitleColor ?? "#6B7280",
861
+ fontSize: 12,
862
+ lineHeight: "12px",
863
+ marginLeft: "6px"
864
+ },
865
+ children: subTitle
866
+ })
867
+ ]
868
+ }) })
869
+ }), /* @__PURE__ */ jsxs(Text, {
870
+ style: {
871
+ fontSize: 16,
872
+ color: theme?.descriptionColor ?? "#374151",
873
+ marginTop: 0,
874
+ marginBottom: 0
875
+ },
876
+ children: [
877
+ description,
878
+ " ",
879
+ linkTitle ? /* @__PURE__ */ jsx("a", {
880
+ href,
881
+ rel: "noopener noreferrer",
882
+ style: {
883
+ color: theme?.titleColor ?? "#111827",
884
+ fontSize: 14,
885
+ fontWeight: 600,
886
+ textDecoration: "underline"
887
+ },
888
+ children: linkTitle
889
+ }) : null
890
+ ]
891
+ })]
892
+ })
893
+ })]
894
+ });
895
+ };
896
+ //#endregion
897
+ //#region src/nodes/list-item.tsx
898
+ const listItem = (node, ctx) => {
899
+ if (!is.listItem(node)) return null;
900
+ const { dir } = node.attrs;
901
+ return /* @__PURE__ */ jsx("li", {
902
+ style: {
903
+ color: ctx.config.theme.listMarker?.color,
904
+ marginBottom: 8,
905
+ marginTop: 8,
906
+ paddingLeft: 6,
907
+ ...ANTIALIASED,
908
+ ...getCssDirection(dir)
909
+ },
910
+ children: ctx.children(node)
911
+ });
912
+ };
913
+ //#endregion
914
+ //#region src/nodes/ordered-list.tsx
915
+ const orderedList = (node, ctx) => {
916
+ if (!is.orderedList(node)) return null;
917
+ const { dir } = node.attrs;
918
+ return /* @__PURE__ */ jsx(Container, {
919
+ style: { marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20 },
920
+ children: /* @__PURE__ */ jsx("ol", {
921
+ style: {
922
+ paddingLeft: 26,
923
+ listStyleType: "decimal",
924
+ margin: 0,
925
+ ...getCssDirection(dir)
926
+ },
927
+ children: ctx.children(node)
928
+ })
929
+ });
930
+ };
931
+ //#endregion
932
+ //#region src/nodes/paragraph.tsx
933
+ const paragraph = (node, ctx) => {
934
+ if (!is.paragraph(node)) return null;
935
+ const { textAlign, dir } = node.attrs;
936
+ const theme = ctx.config.theme;
937
+ const fontStyle = getFontStyle(node.attrs, theme.paragraph);
938
+ prepareAndRegisterFontFaceFromAttrs(ctx, node.attrs, theme.paragraph);
939
+ return /* @__PURE__ */ jsx(Text, {
940
+ style: {
941
+ ...textAlign ? { textAlign } : {},
942
+ ...getCssDirection(dir),
943
+ color: theme.paragraph?.color,
944
+ marginTop: 0,
945
+ marginBottom: shouldSuppressMarginBottom(ctx) ? 0 : 20,
946
+ ...ANTIALIASED,
947
+ ...fontStyle
948
+ },
949
+ children: ctx.children(node)
950
+ });
951
+ };
952
+ //#endregion
953
+ //#region src/nodes/repeat.tsx
954
+ const repeat = (node, ctx) => {
955
+ if (!is.repeat(node)) return null;
956
+ const { each } = node.attrs;
957
+ const payload = ctx.config.variableValues.get(each);
958
+ if (!Array.isArray(payload)) return /* @__PURE__ */ jsx(Fragment$1, { children: ctx.children(node) });
959
+ return /* @__PURE__ */ jsx(Fragment$1, { children: payload.map((item, index) => {
960
+ const childContext = ctx.child({
961
+ parent: node,
962
+ siblingIndex: index
963
+ });
964
+ childContext.set("item", isObject(item) ? item : { value: item });
965
+ return /* @__PURE__ */ jsx(Fragment, { children: childContext.children(node) }, index);
966
+ }) });
967
+ };
968
+ //#endregion
969
+ //#region src/nodes/section.tsx
970
+ const section = (node, ctx) => {
971
+ if (!is.section(node)) return null;
972
+ if (!shouldShow(node, ctx)) return null;
973
+ const { backgroundColor, align } = node.attrs;
974
+ const borderStyle = getBorderStyle(node.attrs);
975
+ const paddingStyle = getPaddingStyle(node.attrs);
976
+ const marginStyle = getMarginStyle(node.attrs);
977
+ const size = insetBox(ctx.size, {
978
+ paddingLeft: node.attrs.paddingLeft,
979
+ paddingRight: node.attrs.paddingRight,
980
+ borderLeft: node.attrs.borderLeftWidth,
981
+ borderRight: node.attrs.borderRightWidth
982
+ });
983
+ return /* @__PURE__ */ jsx(Row, {
984
+ style: marginStyle,
985
+ children: /* @__PURE__ */ jsx(Column, {
986
+ align: align ?? TEXT_ALIGNMENTS.LEFT,
987
+ style: {
988
+ backgroundColor,
989
+ ...borderStyle,
990
+ ...paddingStyle
991
+ },
992
+ children: ctx.child({ size }).children(node)
993
+ })
994
+ });
995
+ };
996
+ //#endregion
997
+ //#region src/nodes/spacer.tsx
998
+ const spacer = (node) => {
999
+ if (!is.spacer(node)) return null;
1000
+ const { height } = node.attrs;
1001
+ return /* @__PURE__ */ jsx(Container, { style: { height: `${height}px` } });
1002
+ };
1003
+ //#endregion
1004
+ //#region src/marks/bold.tsx
1005
+ const bold = (_mark, text, _ctx) => {
1006
+ return /* @__PURE__ */ jsx("strong", { children: text });
1007
+ };
1008
+ //#endregion
1009
+ //#region src/marks/code.tsx
1010
+ const CODE_FONT_FAMILY = "ui-monospace, monospace";
1011
+ const code = (_mark, text, ctx) => {
1012
+ const theme = ctx.config.theme;
1013
+ return /* @__PURE__ */ jsx("code", {
1014
+ style: {
1015
+ backgroundColor: theme.code?.backgroundColor,
1016
+ color: theme.code?.color,
1017
+ fontFamily: CODE_FONT_FAMILY,
1018
+ fontSize: "85%",
1019
+ padding: "2px 6px",
1020
+ borderRadius: 8,
1021
+ ...ANTIALIASED
1022
+ },
1023
+ children: text
1024
+ });
1025
+ };
1026
+ //#endregion
1027
+ //#region src/marks/italic.tsx
1028
+ const italic = (_mark, text, _ctx) => {
1029
+ return /* @__PURE__ */ jsx("em", { children: text });
1030
+ };
1031
+ //#endregion
1032
+ //#region src/marks/link.tsx
1033
+ const link = (mark, text, ctx) => {
1034
+ if (!is.link(mark)) return null;
1035
+ const theme = ctx.config.theme;
1036
+ const linkOverride = ctx.config.variableValues.get(mark.attrs.href);
1037
+ const href = (typeof linkOverride === "string" ? linkOverride : void 0) ?? resolveVariableText(mark.attrs.href, ctx);
1038
+ const color = theme.link?.color;
1039
+ return /* @__PURE__ */ jsx("a", {
1040
+ href,
1041
+ target: "_blank",
1042
+ rel: "noopener noreferrer nofollow",
1043
+ style: color ? { color } : void 0,
1044
+ children: text
1045
+ });
1046
+ };
1047
+ //#endregion
1048
+ //#region src/marks/strike.tsx
1049
+ const strike = (_mark, text, _ctx) => {
1050
+ return /* @__PURE__ */ jsx("s", { children: text });
1051
+ };
1052
+ //#endregion
1053
+ //#region src/marks/underline.tsx
1054
+ const underline = (_mark, text, _ctx) => {
1055
+ return /* @__PURE__ */ jsx("u", { children: text });
1056
+ };
1057
+ //#endregion
1058
+ //#region src/mark.tsx
1059
+ const MAILY_MARKS_ORDER = [
1060
+ MAILY_MARK_TYPES.UNDERLINE,
1061
+ MAILY_MARK_TYPES.BOLD,
1062
+ MAILY_MARK_TYPES.ITALIC,
1063
+ MAILY_MARK_TYPES.STRIKE,
1064
+ MAILY_MARK_TYPES.LINK,
1065
+ MAILY_MARK_TYPES.CODE
1066
+ ];
1067
+ const MAILY_MARK_RENDERERS = {
1068
+ [MAILY_MARK_TYPES.UNDERLINE]: underline,
1069
+ [MAILY_MARK_TYPES.BOLD]: bold,
1070
+ [MAILY_MARK_TYPES.ITALIC]: italic,
1071
+ [MAILY_MARK_TYPES.STRIKE]: strike,
1072
+ [MAILY_MARK_TYPES.LINK]: link,
1073
+ [MAILY_MARK_TYPES.CODE]: code
1074
+ };
1075
+ function render$2(mark, text, ctx) {
1076
+ if (!is.mark(mark)) return null;
1077
+ const renderer = MAILY_MARK_RENDERERS[mark.type];
1078
+ if (!renderer) return null;
1079
+ return renderer(mark, text, ctx);
1080
+ }
1081
+ /**
1082
+ * Applies all marks on a text node. Merges textStyle and highlight
1083
+ * marks into a single span, then wraps with remaining marks in order.
1084
+ */
1085
+ function marks(node, ctx) {
1086
+ if (!is.marked(node)) return [];
1087
+ const themeColor = ctx.config.theme.paragraph?.color;
1088
+ const textStyles = node.marks.filter((mark) => is.textStyle(mark) || is.highlight(mark)).reduce((acc, mark) => {
1089
+ if (is.textStyle(mark)) acc.color = mark.attrs.color || themeColor;
1090
+ else acc.backgroundColor = mark.attrs.color;
1091
+ return acc;
1092
+ }, {});
1093
+ const marks = node.marks.filter((mark) => !is.textStyle(mark) && !is.highlight(mark)).sort((a, b) => {
1094
+ return MAILY_MARKS_ORDER.indexOf(a.type) - MAILY_MARKS_ORDER.indexOf(b.type);
1095
+ });
1096
+ const text = node?.text || /* @__PURE__ */ jsx(Fragment$1, { children: "\xA0" });
1097
+ const baseText = isEmptyObject(textStyles) ? /* @__PURE__ */ jsx(Fragment$1, { children: text }) : /* @__PURE__ */ jsx("span", {
1098
+ style: textStyles,
1099
+ children: text
1100
+ });
1101
+ return marks.reduce((acc, mark, index) => {
1102
+ const component = render$2(mark, acc, ctx.child({
1103
+ parent: node,
1104
+ siblingIndex: index
1105
+ }));
1106
+ if (!component) return acc;
1107
+ return component;
1108
+ }, baseText);
1109
+ }
1110
+ function isEmptyObject(obj) {
1111
+ for (const _ in obj) return false;
1112
+ return true;
1113
+ }
1114
+ //#endregion
1115
+ //#region src/nodes/text.tsx
1116
+ const text = (node, ctx) => {
1117
+ if (!is.text(node)) return null;
1118
+ if (is.marked(node)) return marks(node, ctx);
1119
+ const { text } = node;
1120
+ if (!isDef(text)) return /* @__PURE__ */ jsx(Fragment$1, { children: "\xA0" });
1121
+ return /* @__PURE__ */ jsx(Fragment$1, { children: text });
1122
+ };
1123
+ //#endregion
1124
+ //#region src/nodes/variable.tsx
1125
+ const variable = (node, ctx) => {
1126
+ if (!is.variable(node)) return null;
1127
+ const { id, fallback } = node.attrs;
1128
+ if (!id) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback ?? "" });
1129
+ return /* @__PURE__ */ jsx(Fragment$1, { children: resolveVariableId(id, fallback, ctx) });
1130
+ };
1131
+ //#endregion
1132
+ //#region src/node.tsx
1133
+ const MAILY_NODE_RENDERERS = {
1134
+ [MAILY_NODE_TYPES.DOCUMENT]: document,
1135
+ [MAILY_NODE_TYPES.PARAGRAPH]: paragraph,
1136
+ [MAILY_NODE_TYPES.TEXT]: text,
1137
+ [MAILY_NODE_TYPES.HEADING]: heading,
1138
+ [MAILY_NODE_TYPES.VARIABLE]: variable,
1139
+ [MAILY_NODE_TYPES.IMAGE]: image,
1140
+ [MAILY_NODE_TYPES.INLINE_IMAGE]: inlineImage,
1141
+ [MAILY_NODE_TYPES.SPACER]: spacer,
1142
+ [MAILY_NODE_TYPES.SECTION]: section,
1143
+ [MAILY_NODE_TYPES.BUTTON]: button,
1144
+ [MAILY_NODE_TYPES.REPEAT]: repeat,
1145
+ [MAILY_NODE_TYPES.COLUMNS]: columns,
1146
+ [MAILY_NODE_TYPES.COLUMN]: column,
1147
+ [MAILY_NODE_TYPES.BULLET_LIST]: bulletList,
1148
+ [MAILY_NODE_TYPES.ORDERED_LIST]: orderedList,
1149
+ [MAILY_NODE_TYPES.LIST_ITEM]: listItem,
1150
+ [MAILY_NODE_TYPES.HORIZONTAL_RULE]: horizontalRule,
1151
+ [MAILY_NODE_TYPES.HTML_CODE_BLOCK]: htmlCodeBlock,
1152
+ [MAILY_NODE_TYPES.BLOCKQUOTE]: blockquote,
1153
+ [MAILY_NODE_TYPES.HARD_BREAK]: hardBreak,
1154
+ [MAILY_NODE_TYPES.FOOTER]: footer,
1155
+ [MAILY_NODE_TYPES.LINK_CARD]: linkCard
1156
+ };
1157
+ function dispatch(node, ctx) {
1158
+ if (!is.node(node)) return null;
1159
+ const renderer = MAILY_NODE_RENDERERS[node.type];
1160
+ if (!renderer) return null;
1161
+ return renderer(node, ctx);
1162
+ }
1163
+ function children(parent, ctx) {
1164
+ if (!is.parent(parent)) return [];
1165
+ return parent.content.map((child, index) => {
1166
+ const component = ctx.child({
1167
+ parent,
1168
+ siblingIndex: index
1169
+ }).render(child);
1170
+ if (!component) return null;
1171
+ return /* @__PURE__ */ jsx(Fragment, { children: component }, index);
1172
+ }).filter(Boolean);
1173
+ }
1174
+ //#endregion
1175
+ //#region src/context.ts
1176
+ const DEFAULT_SIZE = {
1177
+ totalWidth: 600,
1178
+ totalBorder: 0,
1179
+ totalPadding: 0
1180
+ };
1181
+ /**
1182
+ * Creates the root RenderContext for a render pass. Node renderers
1183
+ * derive child contexts via `ctx.child()` as they descend the tree.
1184
+ */
1185
+ function defineRenderContext(opts) {
1186
+ const shared = {
1187
+ vars: /* @__PURE__ */ new Map(),
1188
+ styles: /* @__PURE__ */ new Set(),
1189
+ fonts: /* @__PURE__ */ new Map()
1190
+ };
1191
+ const size = {
1192
+ ...DEFAULT_SIZE,
1193
+ ...opts.size
1194
+ };
1195
+ return defineContext({
1196
+ config: opts.config,
1197
+ parent: opts.parent,
1198
+ siblingIndex: opts.siblingIndex ?? 0,
1199
+ size
1200
+ }, shared);
1201
+ }
1202
+ function defineContext(opts, shared) {
1203
+ const { config, parent, siblingIndex, size } = opts;
1204
+ const { vars, styles, fonts } = shared;
1205
+ let varCache = null;
1206
+ const ctx = {
1207
+ parent,
1208
+ siblingIndex,
1209
+ config,
1210
+ size,
1211
+ get box() {
1212
+ return size.totalWidth - size.totalBorder - size.totalPadding;
1213
+ },
1214
+ render(node) {
1215
+ return dispatch(node, ctx);
1216
+ },
1217
+ children(parent) {
1218
+ return children(parent, ctx);
1219
+ },
1220
+ set(key, value) {
1221
+ vars.set(key, value);
1222
+ varCache = null;
1223
+ },
1224
+ get(key) {
1225
+ return vars.get(key);
1226
+ },
1227
+ get var() {
1228
+ return varCache ??= Object.fromEntries(vars);
1229
+ },
1230
+ style(css) {
1231
+ styles.add(css);
1232
+ },
1233
+ font(name, props) {
1234
+ fonts.set(name, props);
1235
+ },
1236
+ child(opts) {
1237
+ const childSize = opts.size ? {
1238
+ totalWidth: opts.size.totalWidth ?? size.totalWidth,
1239
+ totalBorder: opts.size.totalBorder ?? size.totalBorder,
1240
+ totalPadding: opts.size.totalPadding ?? size.totalPadding
1241
+ } : size;
1242
+ const childShared = {
1243
+ vars: new Map(vars),
1244
+ styles,
1245
+ fonts
1246
+ };
1247
+ return defineContext({
1248
+ config,
1249
+ parent: opts.parent ?? parent,
1250
+ siblingIndex: opts.siblingIndex ?? siblingIndex,
1251
+ size: childSize
1252
+ }, childShared);
1253
+ },
1254
+ get styles() {
1255
+ return styles;
1256
+ },
1257
+ get fonts() {
1258
+ return fonts;
1259
+ }
1260
+ };
1261
+ return ctx;
1262
+ }
1263
+ //#endregion
1264
+ //#region src/lib/link.ts
1265
+ /**
1266
+ * Extracts all valid URLs from link marks in a Maily document.
1267
+ * Returns a deduplicated Set of href strings.
1268
+ */
1269
+ function links(json) {
1270
+ const links = /* @__PURE__ */ new Set();
1271
+ if (!is.node(json)) return links;
1272
+ function visitor(node) {
1273
+ if (is.marked(node)) for (const mark of node.marks) {
1274
+ if (!is.link(mark)) continue;
1275
+ const href = mark.attrs.href;
1276
+ if (!isValid(href)) continue;
1277
+ links.add(href);
1278
+ }
1279
+ if (is.parent(node)) node.content.forEach(visitor);
1280
+ }
1281
+ visitor(json);
1282
+ return links;
1283
+ }
1284
+ function isValid(string) {
1285
+ try {
1286
+ new URL(string);
1287
+ return true;
1288
+ } catch {
1289
+ return false;
1290
+ }
1291
+ }
1292
+ //#endregion
1293
+ //#region src/config.ts
1294
+ const DEFAULT_VARIABLE_FORMATTER = ({ variable, fallback }) => {
1295
+ return fallback ? `{{${variable}|${fallback}}}` : `{{${variable}}}`;
1296
+ };
1297
+ /**
1298
+ * Merges user-provided MailyConfig with defaults to produce the
1299
+ * internal MailyRenderConfig used throughout the render pass.
1300
+ */
1301
+ function buildConfig(config = {}) {
1302
+ return {
1303
+ theme: {
1304
+ ...DEFAULT_RENDERER_THEME,
1305
+ ...config.theme,
1306
+ paragraph: {
1307
+ ...DEFAULT_RENDERER_THEME.paragraph,
1308
+ ...config.theme?.paragraph
1309
+ },
1310
+ heading: {
1311
+ defaults: {
1312
+ ...DEFAULT_RENDERER_THEME.heading?.defaults,
1313
+ ...config.theme?.heading?.defaults
1314
+ },
1315
+ h1: {
1316
+ ...DEFAULT_RENDERER_THEME.heading?.h1,
1317
+ ...config.theme?.heading?.h1
1318
+ },
1319
+ h2: {
1320
+ ...DEFAULT_RENDERER_THEME.heading?.h2,
1321
+ ...config.theme?.heading?.h2
1322
+ },
1323
+ h3: {
1324
+ ...DEFAULT_RENDERER_THEME.heading?.h3,
1325
+ ...config.theme?.heading?.h3
1326
+ }
1327
+ },
1328
+ footer: {
1329
+ ...DEFAULT_RENDERER_THEME.footer,
1330
+ ...config.theme?.footer
1331
+ },
1332
+ blockquote: {
1333
+ ...DEFAULT_RENDERER_THEME.blockquote,
1334
+ ...config.theme?.blockquote
1335
+ },
1336
+ horizontalRule: {
1337
+ ...DEFAULT_RENDERER_THEME.horizontalRule,
1338
+ ...config.theme?.horizontalRule
1339
+ },
1340
+ code: {
1341
+ ...DEFAULT_RENDERER_THEME.code,
1342
+ ...config.theme?.code
1343
+ },
1344
+ linkCard: {
1345
+ ...DEFAULT_RENDERER_THEME.linkCard,
1346
+ ...config.theme?.linkCard
1347
+ },
1348
+ container: {
1349
+ ...DEFAULT_RENDERER_THEME.container,
1350
+ ...config.theme?.container
1351
+ },
1352
+ body: {
1353
+ ...DEFAULT_RENDERER_THEME.body,
1354
+ ...config.theme?.body
1355
+ },
1356
+ button: {
1357
+ ...DEFAULT_RENDERER_THEME.button,
1358
+ ...config.theme?.button
1359
+ },
1360
+ link: {
1361
+ ...DEFAULT_RENDERER_THEME.link,
1362
+ ...config.theme?.link
1363
+ },
1364
+ font: config.theme?.font !== void 0 ? config.theme.font : DEFAULT_RENDERER_THEME.font,
1365
+ listMarker: {
1366
+ ...DEFAULT_RENDERER_THEME.listMarker,
1367
+ ...config.theme?.listMarker
1368
+ }
1369
+ },
1370
+ fontFamilies: config.fontFamilies ?? DEFAULT_FONT_FAMILIES,
1371
+ variableValues: new Map(Object.entries(config.variables ?? {})),
1372
+ variableFormatter: config.variableFormatter ?? DEFAULT_VARIABLE_FORMATTER,
1373
+ preview: config.preview,
1374
+ meta: config.meta ?? [],
1375
+ htmlProps: config.htmlProps ?? {},
1376
+ openTrackingPixel: config.openTrackingPixel
1377
+ };
1378
+ }
1379
+ //#endregion
1380
+ //#region src/render.tsx
1381
+ /**
1382
+ * Converts a Maily JSON document into React elements. Returns null
1383
+ * if the input is not a valid Maily node.
1384
+ */
1385
+ function markup(json, config = {}) {
1386
+ const { json: migrated } = migrate(json);
1387
+ if (!is.node(migrated)) return null;
1388
+ return document(migrated, defineRenderContext({ config: buildConfig(config) }));
1389
+ }
1390
+ /** Renders a Maily JSON document to an HTML string using @react-email/render. */
1391
+ async function render(json, config = {}) {
1392
+ if (!is.node(json)) return "";
1393
+ return render$1(markup(json, config));
1394
+ }
1395
+ //#endregion
1396
+ export { buildConfig, children, defineRenderContext, dispatch, links, markup, render };
1397
+
2
1398
  //# sourceMappingURL=index.mjs.map