@maily-to/render 0.2.0 → 0.2.2

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,2 @@
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},P={WebkitFontSmoothing:`antialiased`,MozOsxFontSmoothing:`grayscale`},te={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`},ne=`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,re=`100%`,J=8,ie=`transparent`,ae=0,oe=0,se=`transparent`,ce=0,le=0,ue=0,de=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`},fe={pretty:!1,plainText:!1};var pe=class{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=fe){let t=this.markup();return g(t,e)}markup(){let n=this.content.content||[],r=n.map((t,r)=>{let i={prev:n[r-1],next:n[r+1],parent:t},a=this.renderNode(t,i);return a?v(e,{children:a},D()):null}),{preview:s}=this.config,c=O(this.meta),d=this.htmlProps,p=this.config.theme?.container,m={...this.config.theme?.font||j,fontStyle:`normal`,fontWeight:400},h={margin:`0px`,...this.config.theme?.body},g=y(l,{...d,children:[y(o,{children:[v(a,{...m}),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}}`}}),c]}),y(t,{style:h,children:[s?v(f,{id:`__react-email-preview`,children:s}):null,v(i,{style:{width:`100%`,marginLeft:`auto`,marginRight:`auto`,borderStyle:`solid`,...p},children:r}),this.openTrackingPixel?v(u,{alt:``,src:this.openTrackingPixel,style:{display:`none`,width:`1px`,height:`1px`}}):null]})]});return g}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`,{isParentListItem:i,shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,t),o=this.shouldShow(e,t);if(!o)return v(_,{});let s=i||a?0:20;return v(h,{style:{...r===`left`?{}:{textAlign:r},...P,fontSize:this.config.theme?.fontSize?.paragraph?.size,lineHeight:this.config.theme?.fontSize?.paragraph?.lineHeight,color:this.config.theme?.colors?.paragraph,margin:`0 0 ${s}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?.textAlign||`left`,{shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,t),{fontSize:o,lineHeight:c,fontWeight:l}=te[r],u=this.shouldShow(e,t);return u?v(s,{as:r,style:{textAlign:i,color:this.config.theme?.colors?.heading,fontSize:o,lineHeight:c,fontWeight:l},mb:a?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`}=n||{},{shouldRemoveBottomMargin:i}=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:i?`0px`:`20px`,textAlign:r,...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:ne,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 me(e,t){let{theme:n,preview:r,...i}=t||{},a=new pe(e);return a.setPreviewText(r),a.setTheme(n||{}),a.render(i)}export{J as DEFAULT_COLUMNS_GAP,re as DEFAULT_COLUMNS_WIDTH,ie as DEFAULT_COLUMN_BACKGROUND_COLOR,se as DEFAULT_COLUMN_BORDER_COLOR,ae as DEFAULT_COLUMN_BORDER_RADIUS,oe as DEFAULT_COLUMN_BORDER_WIDTH,ue as DEFAULT_COLUMN_PADDING_BOTTOM,de as DEFAULT_COLUMN_PADDING_LEFT,le as DEFAULT_COLUMN_PADDING_RIGHT,ce 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,pe as Maily,me as render};
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`,{isParentListItem:i,shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,t),o=this.shouldShow(e,t);if(!o)return v(_,{});let s=i||a?0:20;return v(h,{style:{...r===`left`?{}:{textAlign:r},...P,fontSize:this.config.theme?.fontSize?.paragraph?.size,lineHeight:this.config.theme?.fontSize?.paragraph?.lineHeight,color:this.config.theme?.colors?.paragraph,margin:`0 0 ${s}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?.textAlign||`left`,{shouldRemoveBottomMargin:a}=this.getMarginOverrideConditions(e,t),{fontSize:o,lineHeight:c,fontWeight:l}=ne[r],u=this.shouldShow(e,t);return u?v(s,{as:r,style:{textAlign:i,color:this.config.theme?.colors?.heading,fontSize:o,lineHeight:c,fontWeight:l},mb:a?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`}=n||{},{shouldRemoveBottomMargin:i}=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:i?`0px`:`20px`,textAlign:r,...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};
2
2
  //# sourceMappingURL=index.mjs.map