@lit-pigeon/parser-mjml 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/index.cjs +2 -1
- package/dist/index.js +695 -231
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -32,9 +32,17 @@ const { document, warnings } = mjmlToDocument(mjml);
|
|
|
32
32
|
// `warnings` lists unsupported tags that were skipped or approximated.
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
`mjmlToDocument` never throws. Each warning is `{ message, tag? }`, for
|
|
36
|
+
example for `mj-wrapper` styling, unknown elements such as `mj-carousel`, and
|
|
37
|
+
`css-class` on elements that cannot keep it. Some things are dropped without a
|
|
38
|
+
warning: `mj-column` widths (columns open with equal widths), `mj-font`,
|
|
39
|
+
`mj-title`, inline `mj-style`, and attributes the document model has no field
|
|
40
|
+
for. The full list is in
|
|
41
|
+
[Load and save](../../docs/guide/load-and-save.md#what-the-parser-does-not-keep).
|
|
42
|
+
|
|
36
43
|
The exported `ParseOptions`, `ParseResult`, and `ParseWarning` types describe
|
|
37
|
-
the input and output shapes.
|
|
44
|
+
the input and output shapes. In 0.1.7, `ParseOptions.lenient` has no effect and
|
|
45
|
+
`ParseWarning.line` is never set.
|
|
38
46
|
|
|
39
47
|
Part of [Lit Pigeon](https://github.com/snxstudio/lit-pigeon) — open-source drag-and-drop email editor.
|
|
40
48
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("htmlparser2"),h=require("@lit-pigeon/core");function U(t,n){const e={attributeDefaults:{all:{},tags:{},classes:{}}},o=[];for(const i of t)switch(i.tag){case"mj-preview":e.previewText=i.text;break;case"mj-title":e.title=i.text;break;case"mj-attributes":for(const r of i.children){const s=e.attributeDefaults;if(r.tag==="mj-all")Object.assign(s.all,r.attrs);else if(r.tag==="mj-class"){const{name:c,...d}=r.attrs;c&&(s.classes[c]={...s.classes[c],...d})}else s.tags[r.tag]={...s.tags[r.tag],...r.attrs}}e.attributeDefaults.all["font-family"]&&(e.fontFamily=e.attributeDefaults.all["font-family"]);break;case"mj-style":{if(i.attrs.inline==="inline"||!i.text.trim())break;const r=h.generatedStyleName(i.text);r===h.LINK_STYLE_NAME?e.linkStyle=h.cssToLinkStyle(i.text):r||o.push(i.text.trim());break}}return o.length>0&&(e.css=o.join(`
|
|
2
|
+
`)),e}function m(t,n=0){if(!t)return{top:n,right:n,bottom:n,left:n};const e=t.trim().split(/\s+/).map(H);switch(e.length){case 1:return{top:e[0],right:e[0],bottom:e[0],left:e[0]};case 2:return{top:e[0],right:e[1],bottom:e[0],left:e[1]};case 3:return{top:e[0],right:e[1],bottom:e[2],left:e[1]};case 4:return{top:e[0],right:e[1],bottom:e[2],left:e[3]};default:return{top:n,right:n,bottom:n,left:n}}}function H(t){const n=parseFloat(t);return isNaN(n)?0:n}function a(t,n,e=""){return t[n]??e}function b(t,n,e=0){const o=t[n];if(o===void 0||o==="")return e;const i=parseFloat(o);return isNaN(i)?e:i}function R(t){const n={},e=t["css-class"];if(!e)return n;const o=e.replace(/(^|\s)pigeon-hide-(mobile|desktop)(?=\s|$)/g,(i,r,s)=>(n[s==="mobile"?"hideOnMobile":"hideOnDesktop"]=!0,"")).trim();return o?t["css-class"]=o:delete t["css-class"],n}function q(t,n){return{id:h.generateId(),type:"text",values:{content:n,padding:m(a(t,"padding"),10),lineHeight:a(t,"line-height","1.5"),textAlign:a(t,"align","left"),cssClass:a(t,"css-class")||void 0}}}function Y(t){const n=a(t,"width"),e=n&&parseInt(n,10)||"auto";return{id:h.generateId(),type:"image",values:{src:a(t,"src"),alt:a(t,"alt"),width:e,href:a(t,"href")||void 0,padding:m(a(t,"padding"),10),alignment:a(t,"align","center"),borderRadius:b(t,"border-radius",0),cssClass:a(t,"css-class")||void 0}}}const G=/^(solid|dashed|dotted|double|groove|ridge|inset|outset)$/;function X(t){const n=t.trim().split(/\s+/).filter(Boolean);if(!n.length)return;let e,o;const i=[];for(const r of n){const s=r.toLowerCase();if(s==="none"||s==="hidden")return;e===void 0&&/^\d*\.?\d+(px)?$/.test(s)?e=parseFloat(s):o===void 0&&G.test(s)?o=s==="dashed"||s==="dotted"?s:"solid":i.push(r)}if(e!==0)return{width:e??1,style:o??"solid",color:i.join(" ")||"#000000"}}function K(t,n){const e=n.trim(),o=/^<p[\s>]/i.test(e)?e:`<p>${e}</p>`,i=X(a(t,"border"));return{id:h.generateId(),type:"button",values:{content:o,href:a(t,"href","#"),backgroundColor:a(t,"background-color","#3b82f6"),textColor:a(t,"color","#ffffff"),borderRadius:b(t,"border-radius",4),...i?{border:i}:{},padding:m(a(t,"padding"),10),innerPadding:m(a(t,"inner-padding"),12),fontSize:b(t,"font-size",16),fontWeight:a(t,"font-weight","600"),alignment:a(t,"align","center"),fullWidth:a(t,"width")==="100%",cssClass:a(t,"css-class")||void 0}}}function V(t){return{id:h.generateId(),type:"divider",values:{borderColor:a(t,"border-color","#e2e8f0"),borderWidth:b(t,"border-width",1),borderStyle:a(t,"border-style","solid"),padding:m(a(t,"padding"),10),width:a(t,"width","100%")}}}function J(t){return{id:h.generateId(),type:"spacer",values:{height:b(t,"height",20)}}}const Z=["facebook","twitter","instagram","linkedin","youtube","tiktok"];function Q(t){const n=t.toLowerCase();for(const e of Z)if(n.includes(e))return e;return"custom"}function tt(t,n){const e=n.map(o=>{const r={type:Q(a(o.attrs,"name","custom")),href:a(o.attrs,"href","#"),label:o.innerText.trim()||void 0},s=a(o.attrs,"src");return s&&(r.iconUrl=s),r});return{id:h.generateId(),type:"social",values:{icons:e,iconSize:b(t,"icon-size",32),spacing:b(t,"icon-padding",0),alignment:a(t,"align","center"),padding:m(a(t,"padding"),10)}}}function et(t){const n=t.match(/^<div(?:\s+class="lp-html((?:\s+pigeon-hide-(?:mobile|desktop))*)")?\s+style="padding:\s*([^"]*)">([\s\S]*)<\/div>$/);return n?{id:h.generateId(),type:"html",values:{content:n[3],padding:m(n[2],0),...R({"css-class":n[1]??""})}}:{id:h.generateId(),type:"html",values:{content:t,padding:m(void 0,0)}}}const nt={align:"left",border:"none",cellpadding:"0",cellspacing:"0",color:"#000000","font-family":"Ubuntu, Helvetica, Arial, sans-serif","font-size":"13px","line-height":"22px",padding:"10px 25px","table-layout":"auto",width:"100%"};function ot(t,n){const e={...nt,...t},o=e.width.endsWith("%")||e.width==="auto"?e.width:String(parseInt(e.width,10)),i=parseFloat(e.cellspacing.replace(/[^\d.]/g,"")),r=[`color:${e.color}`,`font-family:${e["font-family"]}`,`font-size:${e["font-size"]}`,`line-height:${e["line-height"]}`,`table-layout:${e["table-layout"]}`,`width:${e.width}`,`border:${e.border}`,...i>0?["border-collapse:separate"]:[]].map(c=>`${c};`).join(""),s=[];return e.align!=="left"&&s.push(`align="${y(e.align)}"`),s.push(`cellpadding="${y(e.cellpadding)}"`,`cellspacing="${y(e.cellspacing)}"`),t.role&&s.push(`role="${y(t.role)}"`),s.push(`width="${y(o)}"`,'border="0"',`style="${y(r)}"`),{id:h.generateId(),type:"html",values:{content:`<table ${s.join(" ")}>${n.trim()}</table>`,padding:m(a(e,"padding"),0)}}}function y(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function it(t,n){const e=a(t,"base-url"),o=n.map(i=>{const r={href:e+a(i.attrs,"href","#"),text:i.innerText.trim()||"Link"},s=a(i.attrs,"color");s&&(r.color=s);const c=a(i.attrs,"font-weight");c&&(r.fontWeight=c);const d=a(i.attrs,"text-decoration");d&&(r.textDecoration=d);const l=a(i.attrs,"padding");return l&&(r.padding=l),r});return{id:h.generateId(),type:"navbar",values:{links:o,hamburger:a(t,"hamburger","none"),alignment:a(t,"align","center"),padding:m(a(t,"padding"),0),linkColor:a(t,"ico-color","#000000"),linkFontSize:b(t,"font-size",14),linkPadding:a(t,"link-padding","10px 15px")}}}function I(t,n){const e=t.attrs,o=[],i=t.children;for(let r=0;r<i.length;r++){const s=rt(i[r]);if(s&&at(i[r+2])){const d=z(i[r+1],n);if(d){Object.assign(d.values,i[r+1].visibility),d.values.condition=s,o.push(d),r+=2;continue}}const c=z(i[r],n);c&&(Object.assign(c.values,i[r].visibility),o.push(c))}return{id:h.generateId(),type:"column",attributes:{backgroundColor:a(e,"background-color")||void 0,padding:m(a(e,"padding"),0),borderRadius:b(e,"border-radius",0)||void 0,verticalAlign:a(e,"vertical-align","top"),cssClass:a(e,"css-class")||void 0,...t.visibility},blocks:o}}function rt(t){var n;if(t.tag==="mj-raw")return(n=/^\s*\{\{#if\s+([^}]+?)\s*\}\}\s*$/.exec(t.text??""))==null?void 0:n[1]}function at(t){return(t==null?void 0:t.tag)==="mj-raw"&&/^\s*\{\{\/if\}\}\s*$/.test(t.text??"")}function z(t,n){switch(t.tag){case"mj-text":return q(t.attrs,t.text);case"mj-image":return Y(t.attrs);case"mj-button":return K(t.attrs,t.text);case"mj-divider":return V(t.attrs);case"mj-spacer":return J(t.attrs);case"mj-social":{const e=t.children.filter(o=>o.tag==="mj-social-element").map(o=>({attrs:o.attrs,innerText:o.text}));return tt(t.attrs,e)}case"mj-raw":return et(t.text);case"mj-table":return ot(t.attrs,t.text);case"mj-navbar":{const e=t.children.filter(o=>o.tag==="mj-navbar-link").map(o=>({attrs:o.attrs,innerText:o.text}));return it(t.attrs,e)}default:return n.push({message:`Unknown block element: ${t.tag}`,tag:t.tag}),null}}function E(t,n,e){const o=t.attrs,i=[],r=[];let s=0,c=0;for(const g of t.children)if(g.tag==="mj-column")i.push(I(g,n)),r.push(g),c++;else if(g.tag==="mj-group"){s++;for(const x of g.children)x.tag==="mj-column"&&(i.push(I(x,n)),r.push(x))}else n.push({message:`Unexpected section child: ${g.tag}`,tag:g.tag});i.length===0&&i.push({id:h.generateId(),type:"column",attributes:{padding:m(void 0,0),verticalAlign:"top"},blocks:[]});const d=r.length?ct(r,e,n):[12],l=s===1&&c===0;s>0&&!l&&n.push({message:"A section mixing mj-group with other columns was flattened: its columns will stack on mobile",tag:"mj-group"});const u=a(o,"full-width")==="full-width";return{id:h.generateId(),type:"row",attributes:{...t.visibility,backgroundColor:a(o,"background-color")||void 0,...st(o,n),padding:m(a(o,"padding"),0),fullWidth:u,cssClass:a(o,"css-class")||void 0,...l?{noStackOnMobile:!0}:{}},columns:i,columnRatios:d,locked:!1}}function st(t,n){const e=a(t,"background-url");if(!e)return{};const o=a(t,"background-repeat");return(o==="repeat-x"||o==="repeat-y")&&n.push({message:`background-repeat="${o}" became "repeat" — a row cannot repeat on one axis`,tag:"mj-section"}),{backgroundImage:e,backgroundRepeat:o==="no-repeat"?"no-repeat":"repeat",backgroundSize:a(t,"background-size")||void 0,backgroundPosition:a(t,"background-position")||void 0}}function lt(t,n){var i;const e=(i=t.attrs.width)==null?void 0:i.trim();if(!e)return;const o=parseFloat(e);if(!(isNaN(o)||o<=0))return e.endsWith("%")?o:o/n*100}function ct(t,n,e){const o=t.map(l=>lt(l,n));if(o.every(l=>l===void 0)){const l=Math.floor(12/o.length);return o.map(()=>l)}const i=o.reduce((l,p)=>l+(p??0),0);i>101&&e.push({message:`Column widths total ${Math.round(i)}% of the body width; they were scaled to fit`,tag:"mj-section"});const r=o.filter(l=>l===void 0).length,s=Math.max(0,100-i),c=o.map(l=>l??s/r),d=c.reduce((l,p)=>l+p,0);return c.map(l=>Math.max(1,Math.round(l*12/d)))}const v="Ubuntu, Helvetica, Arial, sans-serif",M={"mj-body":{width:"600px"},"mj-section":{"background-repeat":"repeat","background-size":"auto","background-position":"top center",direction:"ltr",padding:"20px 0","text-align":"center","text-padding":"4px 4px 4px 0"},"mj-wrapper":{"background-repeat":"repeat","background-size":"auto","background-position":"top center",direction:"ltr",padding:"20px 0","text-align":"center","text-padding":"4px 4px 4px 0"},"mj-column":{direction:"ltr","vertical-align":"top"},"mj-text":{align:"left",color:"#000000","font-family":v,"font-size":"13px","line-height":"1",padding:"10px 25px"},"mj-button":{align:"center","background-color":"#414141",border:"none","border-radius":"3px",color:"#ffffff","font-family":v,"font-size":"13px","font-weight":"normal","inner-padding":"10px 25px","line-height":"120%",padding:"10px 25px",target:"_blank","text-decoration":"none","text-transform":"none","vertical-align":"middle"},"mj-image":{alt:"",align:"center",border:"0",height:"auto",padding:"10px 25px",target:"_blank","font-size":"13px"},"mj-divider":{"border-color":"#000000","border-style":"solid","border-width":"4px",padding:"10px 25px",width:"100%",align:"center"},"mj-spacer":{height:"20px"},"mj-social":{align:"center","border-radius":"3px",color:"#333333","font-family":v,"font-size":"13px","icon-size":"20px","line-height":"22px",mode:"horizontal",padding:"10px 25px","text-decoration":"none"},"mj-social-element":{alt:"",align:"left","icon-position":"left",color:"#000","border-radius":"3px","font-family":v,"font-size":"13px","line-height":"1",padding:"4px","text-padding":"4px 4px 4px 0",target:"_blank","text-decoration":"none","vertical-align":"middle"},"mj-hero":{mode:"fixed-height",height:"0px","background-position":"center center",padding:"0px","background-color":"#ffffff","vertical-align":"top"},"mj-navbar":{align:"center","ico-align":"center","ico-open":"☰","ico-close":"⊗","ico-color":"#000000","ico-font-size":"30px","ico-font-family":v,"ico-text-transform":"uppercase","ico-padding":"10px","ico-text-decoration":"none","ico-line-height":"30px"},"mj-navbar-link":{color:"#000000","font-family":v,"font-size":"13px","font-weight":"normal","line-height":"22px",padding:"15px 10px",target:"_blank","text-decoration":"none","text-transform":"uppercase"},"mj-table":{align:"left",border:"none",cellpadding:"0",cellspacing:"0",color:"#000000","font-family":v,"font-size":"13px","line-height":"22px",padding:"10px 25px","table-layout":"auto",width:"100%"}},dt=v;function pt(t,n,e){return{id:h.generateId(),type:"hero",values:{backgroundUrl:a(t,"background-url"),backgroundPosition:a(t,"background-position","center center"),mode:a(t,"mode","fluid-height"),width:b(t,"width",600),height:b(t,"height",400),verticalAlign:a(t,"vertical-align","middle"),padding:m(a(t,"padding"),0),innerPadding:m(e,20),backgroundColor:a(t,"background-color","#ffffff"),content:n}}}const ut=[["font-style","font-style"],["font-weight","font-weight"],["letter-spacing","letter-spacing"],["line-height","line-height"],["text-align","align"],["text-decoration","text-decoration"],["text-transform","text-transform"],["height","height"]],gt={"line-height":"1.5",align:"left"};function _(t,n,e){const o=ut.filter(([,i])=>t[i]&&t[i]!==gt[i]).concat(!e&&t.padding?[["padding","padding"]]:[]).map(([i,r])=>`${i}:${t[r]};`).join("");return o?`<div style="${w(o)}">${n}</div>`:e?n:`<div>${n}</div>`}function ft(t,n){const e={...M["mj-button"],...t},o=e["background-color"],i=`border:${e.border};border-radius:${e["border-radius"]};cursor:auto;mso-padding-alt:${e["inner-padding"]};background:${o};`,r=`display:inline-block;background:${o};color:${e.color};font-family:${e["font-family"]};font-size:${e["font-size"]};font-weight:${e["font-weight"]};line-height:${e["line-height"]};margin:0;text-decoration:${e["text-decoration"]};text-transform:${e["text-transform"]};padding:${e["inner-padding"]};mso-padding-alt:0px;border-radius:${e["border-radius"]};`,s=e.href?`<a href="${w(e.href)}" target="${w(e.target)}" style="${w(r)}">${n.trim()}</a>`:`<p style="${w(r)}">${n.trim()}</p>`;return`<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%"><tr><td align="${w(e.align)}" style="padding:${w(e.padding)};"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;"><tr><td align="center"${o==="none"?"":` bgcolor="${w(o)}"`} role="presentation" valign="${w(e["vertical-align"])}" style="${w(i)}">${s}</td></tr></table></td></tr></table>`}function w(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function ht(t,n){const e=b(t.attrs,"width",600),o=a(t.attrs,"background-color"),i=[];let r=[],s;const c=d=>{var g;const[l,p]=r;l&&(d.attributes.condition=l);const[u]=((g=d.columns[0])==null?void 0:g.blocks)??[];return p&&(u==null?void 0:u.type)==="hero"&&(u.values.condition=p),r=[],s&&(d.attributes.repeat=s,s=void 0),d};for(const d of t.children)switch(d.tag){case"mj-raw":{const l=/\{\{#if\s+([^}]+?)\s*\}\}/.exec(d.text??"");l&&r.push(l[1].trim());const p=/^\s*\{\{#each\s+([^}]+?)\s*\}\}\s*$/.exec(d.text??"");p&&(s=p[1].trim(),r=[r[0]]);break}case"mj-section":i.push(c(E(d,n,e)));break;case"mj-hero":{const l=mt(d,n),p=pt(d.attrs,l.content,l.innerPadding);Object.assign(p.values,d.visibility);const u={id:h.generateId(),type:"column",attributes:{padding:m(void 0,0),verticalAlign:"top"},blocks:[p]},g={id:h.generateId(),type:"row",attributes:{padding:m(void 0,0),fullWidth:!1},columns:[u],columnRatios:[12],locked:!1};i.push(c(g));break}case"mj-wrapper":n.push({message:"mj-wrapper styling (padding, background-color) was dropped: the document model has no wrapper; its sections were imported unwrapped",tag:"mj-wrapper"});for(const l of d.children)l.tag==="mj-section"&&i.push(c(E(l,n,e)));break;default:n.push({message:`Unknown body child element: ${d.tag}`,tag:d.tag});break}return{width:e,backgroundColor:o,rows:i}}function mt(t,n){const[e]=t.children;if(t.children.length===1&&e.tag==="mj-text")return{content:_(e.attrs,e.text,!0),innerPadding:e.attrs.padding};const o=[];for(const i of t.children)i.tag==="mj-text"?o.push(_(i.attrs,i.text,!1)):i.tag==="mj-button"?o.push(ft(i.attrs,i.text)):n.push({message:`Unsupported mj-hero child element: ${i.tag}`,tag:i.tag});return{content:o.join("")||"<p>Hero Content</p>"}}const bt=new Set(["mj-section","mj-column","mj-text","mj-button","mj-image"]);function N(t,n,e){const{"mj-class":o="",...i}=t.attrs,r=o.split(/\s+/).filter(Boolean).reduce((c,d)=>{const l=n.classes[d]??{},p=c["css-class"]&&l["css-class"]?{"css-class":`${c["css-class"]} ${l["css-class"]}`}:{};return{...c,...l,...p}},{});t.attrs={...M[t.tag],...n.all,...n.tags[t.tag],...r,...i},t.visibility=R(t.attrs);const s=t.attrs["css-class"];s&&!bt.has(t.tag)&&e.push({message:`css-class "${s}" on <${t.tag}> was dropped`,tag:t.tag});for(const c of t.children)N(c,n,e)}const D=new Set(["address","article","aside","blockquote","center","dd","div","dl","dt","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","ol","p","pre","section","table","tbody","td","tfoot","th","thead","tr","ul"]),B=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),xt="14px",kt="#000000";function F(t,n){if(t.tag==="mj-text"){const{color:e,"font-size":o,"font-family":i}=t.attrs,r=[];e&&e.toLowerCase()!==kt&&r.push(`color: ${e}`),o&&o!==xt&&r.push(`font-size: ${o}`),i&&i!==n&&r.push(`font-family: ${i}`),r.length>0&&(t.text=wt(t.text,`<span style="${vt(r.join("; "))}">`));return}for(const e of t.children)F(e,n)}function wt(t,n){const e=[];let o=-1,i=-1,r=!1,s=0;const c=()=>{o>=0&&r&&e.push([o,n],[i,"</span>"]),o=-1,r=!1},d=(u,g)=>{o<0&&(o=u),i=g},l=new O.Parser({onopentag(u){if(s===0&&D.has(u)){c();return}d(l.startIndex,l.endIndex+1),B.has(u)?r=!0:s++},onclosetag(u,g){if(!B.has(u)){if(s===0){D.has(u)&&c();return}s--,g||(i=l.endIndex+1)}},ontext(u){o<0&&!u.trim()||(d(l.startIndex,l.endIndex+1),u.trim()&&(r=!0))},oncomment(){o>=0&&(i=l.endIndex+1)}},{recognizeSelfClosing:!0,lowerCaseTags:!0});l.write(t),l.end(),c();let p=t;for(const[u,g]of e.reverse())p=p.slice(0,u)+g+p.slice(u);return p}function vt(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function jt(t){const n={tag:"root",attrs:{},children:[],text:""},e=[n],o=new Set(["mj-text","mj-button","mj-raw","mj-preview","mj-title","mj-social-element","mj-navbar-link","mj-table"]),i=new Set(["mj-image","mj-divider","mj-spacer","mj-all","mj-class","mj-font","mj-breakpoint"]),r=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),s=new Set(["mj-text","mj-button","mj-raw"]),c=new Set(["style","script"]),d=f=>f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),l=f=>f.replace(/&/g,"&").replace(/"/g,""");let p=null,u="",g=0,x=!1;const $=new O.Parser({onopentag(f,j){if(p){const P=s.has(p.node.tag),T=Object.entries(j).map(([W,A])=>`${W}="${P?l(A):A}"`).join(" ");u+=T?`<${f} ${T}>`:`<${f}>`,r.has(f)||g++,c.has(f)&&(x=!0);return}const k={tag:f,attrs:j,children:[],text:""};e[e.length-1].children.push(k),!i.has(f)&&(e.push(k),o.has(f)&&(p={node:k,depth:0},u="",g=0))},ontext(f){if(p){const k=s.has(p.node.tag)&&!x;u+=k?d(f):f;return}const j=e[e.length-1];j.text+=f},onclosetag(f){if(p){if(r.has(f))return;if(g>0){u+=`</${f}>`,g--,c.has(f)&&(x=!1);return}p.node.text=u,p=null,u="",g=0,e.length>1&&e[e.length-1].tag===f&&e.pop();return}i.has(f)||e.length>1&&e[e.length-1].tag===f&&e.pop()},oncomment(f){p&&(u+=`<!--${f}-->`)}},{recognizeSelfClosing:!0,lowerCaseTags:!0,lowerCaseAttributeNames:!0});return $.write(t),$.end(),n}function C(t,n){if(t.tag===n)return t;for(const e of t.children){const o=C(e,n);if(o)return o}}function yt(t,n){var j;const e=[],o=jt(t),i=C(o,"mjml");if(!i)return e.push({message:"No <mjml> root element found"}),{document:L(),warnings:e};const r=C(i,"mj-head"),s=C(i,"mj-body");let c={attributeDefaults:{all:{},tags:{},classes:{}}};if(r&&(c=U(r.children.map(k=>({tag:k.tag,attrs:k.attrs,children:k.children.map(S=>({tag:S.tag,attrs:S.attrs,children:[],text:S.text})),text:k.text})))),!s)return e.push({message:"No <mj-body> element found"}),{document:L(),warnings:e};const d=c.fontFamily??dt;N(s,c.attributeDefaults,e),F(s,d);const l=ht(s,e),p=i.attrs.lang,u=p&&p!=="und"?p:void 0,g=i.attrs.dir,x=g==="ltr"||g==="rtl"?g:void 0,$=new Date().toISOString();return{document:{version:"1.0",metadata:{name:((j=c.title)==null?void 0:j.trim())||"Imported Template",previewText:c.previewText,createdAt:$,updatedAt:$},body:{attributes:{width:l.width,backgroundColor:l.backgroundColor,fontFamily:d,contentAlignment:"center",...c.linkStyle?{linkStyle:c.linkStyle}:{},...u?{language:u}:{},...x?{direction:x}:{},css:c.css},rows:l.rows}},warnings:e}}function L(){const t=new Date().toISOString();return{version:"1.0",metadata:{name:"Imported Template",createdAt:t,updatedAt:t},body:{attributes:{width:600,backgroundColor:"#f4f4f5",fontFamily:"Arial, Helvetica, sans-serif",contentAlignment:"center"},rows:[]}}}exports.mjmlToDocument=yt;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
import { Parser as
|
|
2
|
-
import { generateId as
|
|
3
|
-
function
|
|
4
|
-
const e = {};
|
|
5
|
-
for (const
|
|
6
|
-
switch (
|
|
1
|
+
import { Parser as R } from "htmlparser2";
|
|
2
|
+
import { generatedStyleName as U, LINK_STYLE_NAME as H, cssToLinkStyle as Y, generateId as m } from "@lit-pigeon/core";
|
|
3
|
+
function q(t, n) {
|
|
4
|
+
const e = { attributeDefaults: { all: {}, tags: {}, classes: {} } }, o = [];
|
|
5
|
+
for (const i of t)
|
|
6
|
+
switch (i.tag) {
|
|
7
7
|
case "mj-preview":
|
|
8
|
-
e.previewText =
|
|
8
|
+
e.previewText = i.text;
|
|
9
|
+
break;
|
|
10
|
+
case "mj-title":
|
|
11
|
+
e.title = i.text;
|
|
9
12
|
break;
|
|
10
13
|
case "mj-attributes":
|
|
11
|
-
for (const
|
|
12
|
-
|
|
14
|
+
for (const r of i.children) {
|
|
15
|
+
const s = e.attributeDefaults;
|
|
16
|
+
if (r.tag === "mj-all")
|
|
17
|
+
Object.assign(s.all, r.attrs);
|
|
18
|
+
else if (r.tag === "mj-class") {
|
|
19
|
+
const { name: c, ...d } = r.attrs;
|
|
20
|
+
c && (s.classes[c] = { ...s.classes[c], ...d });
|
|
21
|
+
} else
|
|
22
|
+
s.tags[r.tag] = { ...s.tags[r.tag], ...r.attrs };
|
|
23
|
+
}
|
|
24
|
+
e.attributeDefaults.all["font-family"] && (e.fontFamily = e.attributeDefaults.all["font-family"]);
|
|
25
|
+
break;
|
|
26
|
+
case "mj-style": {
|
|
27
|
+
if (i.attrs.inline === "inline" || !i.text.trim()) break;
|
|
28
|
+
const r = U(i.text);
|
|
29
|
+
r === H ? e.linkStyle = Y(i.text) : r || o.push(i.text.trim());
|
|
13
30
|
break;
|
|
31
|
+
}
|
|
14
32
|
}
|
|
15
|
-
return e
|
|
33
|
+
return o.length > 0 && (e.css = o.join(`
|
|
34
|
+
`)), e;
|
|
16
35
|
}
|
|
17
|
-
function
|
|
36
|
+
function h(t, n = 0) {
|
|
18
37
|
if (!t)
|
|
19
38
|
return { top: n, right: n, bottom: n, left: n };
|
|
20
|
-
const e = t.trim().split(/\s+/).map(
|
|
39
|
+
const e = t.trim().split(/\s+/).map(G);
|
|
21
40
|
switch (e.length) {
|
|
22
41
|
case 1:
|
|
23
42
|
return { top: e[0], right: e[0], bottom: e[0], left: e[0] };
|
|
@@ -31,202 +50,289 @@ function u(t, n = 0) {
|
|
|
31
50
|
return { top: n, right: n, bottom: n, left: n };
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
|
-
function
|
|
53
|
+
function G(t) {
|
|
35
54
|
const n = parseFloat(t);
|
|
36
55
|
return isNaN(n) ? 0 : n;
|
|
37
56
|
}
|
|
38
|
-
function
|
|
57
|
+
function a(t, n, e = "") {
|
|
39
58
|
return t[n] ?? e;
|
|
40
59
|
}
|
|
41
|
-
function
|
|
60
|
+
function b(t, n, e = 0) {
|
|
42
61
|
const o = t[n];
|
|
43
62
|
if (o === void 0 || o === "") return e;
|
|
44
|
-
const
|
|
45
|
-
return isNaN(
|
|
63
|
+
const i = parseFloat(o);
|
|
64
|
+
return isNaN(i) ? e : i;
|
|
65
|
+
}
|
|
66
|
+
function O(t) {
|
|
67
|
+
const n = {}, e = t["css-class"];
|
|
68
|
+
if (!e) return n;
|
|
69
|
+
const o = e.replace(/(^|\s)pigeon-hide-(mobile|desktop)(?=\s|$)/g, (i, r, s) => (n[s === "mobile" ? "hideOnMobile" : "hideOnDesktop"] = !0, "")).trim();
|
|
70
|
+
return o ? t["css-class"] = o : delete t["css-class"], n;
|
|
46
71
|
}
|
|
47
|
-
function
|
|
72
|
+
function X(t, n) {
|
|
48
73
|
return {
|
|
49
|
-
id:
|
|
74
|
+
id: m(),
|
|
50
75
|
type: "text",
|
|
51
76
|
values: {
|
|
52
77
|
content: n,
|
|
53
|
-
padding:
|
|
54
|
-
lineHeight:
|
|
55
|
-
textAlign:
|
|
78
|
+
padding: h(a(t, "padding"), 10),
|
|
79
|
+
lineHeight: a(t, "line-height", "1.5"),
|
|
80
|
+
textAlign: a(t, "align", "left"),
|
|
81
|
+
cssClass: a(t, "css-class") || void 0
|
|
56
82
|
}
|
|
57
83
|
};
|
|
58
84
|
}
|
|
59
|
-
function
|
|
60
|
-
const n =
|
|
85
|
+
function K(t) {
|
|
86
|
+
const n = a(t, "width"), e = n && parseInt(n, 10) || "auto";
|
|
61
87
|
return {
|
|
62
|
-
id:
|
|
88
|
+
id: m(),
|
|
63
89
|
type: "image",
|
|
64
90
|
values: {
|
|
65
|
-
src:
|
|
66
|
-
alt:
|
|
91
|
+
src: a(t, "src"),
|
|
92
|
+
alt: a(t, "alt"),
|
|
67
93
|
width: e,
|
|
68
|
-
href:
|
|
69
|
-
padding:
|
|
70
|
-
alignment:
|
|
71
|
-
borderRadius:
|
|
94
|
+
href: a(t, "href") || void 0,
|
|
95
|
+
padding: h(a(t, "padding"), 10),
|
|
96
|
+
alignment: a(t, "align", "center"),
|
|
97
|
+
borderRadius: b(t, "border-radius", 0),
|
|
98
|
+
cssClass: a(t, "css-class") || void 0
|
|
72
99
|
}
|
|
73
100
|
};
|
|
74
101
|
}
|
|
75
|
-
|
|
76
|
-
|
|
102
|
+
const V = /^(solid|dashed|dotted|double|groove|ridge|inset|outset)$/;
|
|
103
|
+
function J(t) {
|
|
104
|
+
const n = t.trim().split(/\s+/).filter(Boolean);
|
|
105
|
+
if (!n.length) return;
|
|
106
|
+
let e, o;
|
|
107
|
+
const i = [];
|
|
108
|
+
for (const r of n) {
|
|
109
|
+
const s = r.toLowerCase();
|
|
110
|
+
if (s === "none" || s === "hidden") return;
|
|
111
|
+
e === void 0 && /^\d*\.?\d+(px)?$/.test(s) ? e = parseFloat(s) : o === void 0 && V.test(s) ? o = s === "dashed" || s === "dotted" ? s : "solid" : i.push(r);
|
|
112
|
+
}
|
|
113
|
+
if (e !== 0)
|
|
114
|
+
return {
|
|
115
|
+
width: e ?? 1,
|
|
116
|
+
style: o ?? "solid",
|
|
117
|
+
color: i.join(" ") || "#000000"
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function Z(t, n) {
|
|
121
|
+
const e = n.trim(), o = /^<p[\s>]/i.test(e) ? e : `<p>${e}</p>`, i = J(a(t, "border"));
|
|
77
122
|
return {
|
|
78
|
-
id:
|
|
123
|
+
id: m(),
|
|
79
124
|
type: "button",
|
|
80
125
|
values: {
|
|
81
126
|
content: o,
|
|
82
|
-
href:
|
|
83
|
-
backgroundColor:
|
|
84
|
-
textColor:
|
|
85
|
-
borderRadius:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
127
|
+
href: a(t, "href", "#"),
|
|
128
|
+
backgroundColor: a(t, "background-color", "#3b82f6"),
|
|
129
|
+
textColor: a(t, "color", "#ffffff"),
|
|
130
|
+
borderRadius: b(t, "border-radius", 4),
|
|
131
|
+
...i ? { border: i } : {},
|
|
132
|
+
padding: h(a(t, "padding"), 10),
|
|
133
|
+
innerPadding: h(a(t, "inner-padding"), 12),
|
|
134
|
+
fontSize: b(t, "font-size", 16),
|
|
135
|
+
fontWeight: a(t, "font-weight", "600"),
|
|
136
|
+
alignment: a(t, "align", "center"),
|
|
137
|
+
fullWidth: a(t, "width") === "100%",
|
|
138
|
+
cssClass: a(t, "css-class") || void 0
|
|
92
139
|
}
|
|
93
140
|
};
|
|
94
141
|
}
|
|
95
|
-
function
|
|
142
|
+
function Q(t) {
|
|
96
143
|
return {
|
|
97
|
-
id:
|
|
144
|
+
id: m(),
|
|
98
145
|
type: "divider",
|
|
99
146
|
values: {
|
|
100
|
-
borderColor:
|
|
101
|
-
borderWidth:
|
|
102
|
-
borderStyle:
|
|
103
|
-
padding:
|
|
104
|
-
width:
|
|
147
|
+
borderColor: a(t, "border-color", "#e2e8f0"),
|
|
148
|
+
borderWidth: b(t, "border-width", 1),
|
|
149
|
+
borderStyle: a(t, "border-style", "solid"),
|
|
150
|
+
padding: h(a(t, "padding"), 10),
|
|
151
|
+
width: a(t, "width", "100%")
|
|
105
152
|
}
|
|
106
153
|
};
|
|
107
154
|
}
|
|
108
|
-
function
|
|
155
|
+
function tt(t) {
|
|
109
156
|
return {
|
|
110
|
-
id:
|
|
157
|
+
id: m(),
|
|
111
158
|
type: "spacer",
|
|
112
159
|
values: {
|
|
113
|
-
height:
|
|
160
|
+
height: b(t, "height", 20)
|
|
114
161
|
}
|
|
115
162
|
};
|
|
116
163
|
}
|
|
117
|
-
const
|
|
118
|
-
function
|
|
164
|
+
const et = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
|
|
165
|
+
function nt(t) {
|
|
119
166
|
const n = t.toLowerCase();
|
|
120
|
-
for (const e of
|
|
167
|
+
for (const e of et)
|
|
121
168
|
if (n.includes(e)) return e;
|
|
122
169
|
return "custom";
|
|
123
170
|
}
|
|
124
|
-
function
|
|
171
|
+
function ot(t, n) {
|
|
125
172
|
const e = n.map((o) => {
|
|
126
|
-
const
|
|
127
|
-
type:
|
|
128
|
-
href:
|
|
173
|
+
const r = {
|
|
174
|
+
type: nt(a(o.attrs, "name", "custom")),
|
|
175
|
+
href: a(o.attrs, "href", "#"),
|
|
129
176
|
label: o.innerText.trim() || void 0
|
|
130
|
-
}, s =
|
|
131
|
-
return s && (
|
|
177
|
+
}, s = a(o.attrs, "src");
|
|
178
|
+
return s && (r.iconUrl = s), r;
|
|
132
179
|
});
|
|
133
180
|
return {
|
|
134
|
-
id:
|
|
181
|
+
id: m(),
|
|
135
182
|
type: "social",
|
|
136
183
|
values: {
|
|
137
184
|
icons: e,
|
|
138
|
-
iconSize:
|
|
139
|
-
spacing:
|
|
140
|
-
alignment:
|
|
141
|
-
padding:
|
|
185
|
+
iconSize: b(t, "icon-size", 32),
|
|
186
|
+
spacing: b(t, "icon-padding", 0),
|
|
187
|
+
alignment: a(t, "align", "center"),
|
|
188
|
+
padding: h(a(t, "padding"), 10)
|
|
142
189
|
}
|
|
143
190
|
};
|
|
144
191
|
}
|
|
145
|
-
function
|
|
146
|
-
const n = t.match(
|
|
192
|
+
function it(t) {
|
|
193
|
+
const n = t.match(
|
|
194
|
+
/^<div(?:\s+class="lp-html((?:\s+pigeon-hide-(?:mobile|desktop))*)")?\s+style="padding:\s*([^"]*)">([\s\S]*)<\/div>$/
|
|
195
|
+
);
|
|
147
196
|
return n ? {
|
|
148
|
-
id:
|
|
197
|
+
id: m(),
|
|
149
198
|
type: "html",
|
|
150
199
|
values: {
|
|
151
|
-
content: n[
|
|
152
|
-
padding:
|
|
200
|
+
content: n[3],
|
|
201
|
+
padding: h(n[2], 0),
|
|
202
|
+
...O({ "css-class": n[1] ?? "" })
|
|
153
203
|
}
|
|
154
204
|
} : {
|
|
155
|
-
id:
|
|
205
|
+
id: m(),
|
|
156
206
|
type: "html",
|
|
157
207
|
values: {
|
|
158
208
|
content: t,
|
|
159
|
-
padding:
|
|
209
|
+
padding: h(void 0, 0)
|
|
160
210
|
}
|
|
161
211
|
};
|
|
162
212
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
213
|
+
const rt = {
|
|
214
|
+
align: "left",
|
|
215
|
+
border: "none",
|
|
216
|
+
cellpadding: "0",
|
|
217
|
+
cellspacing: "0",
|
|
218
|
+
color: "#000000",
|
|
219
|
+
"font-family": "Ubuntu, Helvetica, Arial, sans-serif",
|
|
220
|
+
"font-size": "13px",
|
|
221
|
+
"line-height": "22px",
|
|
222
|
+
padding: "10px 25px",
|
|
223
|
+
"table-layout": "auto",
|
|
224
|
+
width: "100%"
|
|
225
|
+
};
|
|
226
|
+
function at(t, n) {
|
|
227
|
+
const e = { ...rt, ...t }, o = e.width.endsWith("%") || e.width === "auto" ? e.width : String(parseInt(e.width, 10)), i = parseFloat(e.cellspacing.replace(/[^\d.]/g, "")), r = [
|
|
228
|
+
`color:${e.color}`,
|
|
229
|
+
`font-family:${e["font-family"]}`,
|
|
230
|
+
`font-size:${e["font-size"]}`,
|
|
231
|
+
`line-height:${e["line-height"]}`,
|
|
232
|
+
`table-layout:${e["table-layout"]}`,
|
|
233
|
+
`width:${e.width}`,
|
|
234
|
+
`border:${e.border}`,
|
|
235
|
+
...i > 0 ? ["border-collapse:separate"] : []
|
|
236
|
+
].map((c) => `${c};`).join(""), s = [];
|
|
237
|
+
return e.align !== "left" && s.push(`align="${y(e.align)}"`), s.push(`cellpadding="${y(e.cellpadding)}"`, `cellspacing="${y(e.cellspacing)}"`), t.role && s.push(`role="${y(t.role)}"`), s.push(`width="${y(o)}"`, 'border="0"', `style="${y(r)}"`), {
|
|
238
|
+
id: m(),
|
|
239
|
+
type: "html",
|
|
240
|
+
values: {
|
|
241
|
+
content: `<table ${s.join(" ")}>${n.trim()}</table>`,
|
|
242
|
+
padding: h(a(e, "padding"), 0)
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function y(t) {
|
|
247
|
+
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
248
|
+
}
|
|
249
|
+
function st(t, n) {
|
|
250
|
+
const e = a(t, "base-url"), o = n.map((i) => {
|
|
251
|
+
const r = {
|
|
252
|
+
href: e + a(i.attrs, "href", "#"),
|
|
253
|
+
text: i.innerText.trim() || "Link"
|
|
254
|
+
}, s = a(i.attrs, "color");
|
|
255
|
+
s && (r.color = s);
|
|
256
|
+
const c = a(i.attrs, "font-weight");
|
|
257
|
+
c && (r.fontWeight = c);
|
|
258
|
+
const d = a(i.attrs, "text-decoration");
|
|
259
|
+
d && (r.textDecoration = d);
|
|
260
|
+
const l = a(i.attrs, "padding");
|
|
261
|
+
return l && (r.padding = l), r;
|
|
176
262
|
});
|
|
177
263
|
return {
|
|
178
|
-
id:
|
|
264
|
+
id: m(),
|
|
179
265
|
type: "navbar",
|
|
180
266
|
values: {
|
|
181
|
-
links:
|
|
182
|
-
hamburger:
|
|
183
|
-
alignment:
|
|
184
|
-
padding:
|
|
185
|
-
linkColor:
|
|
186
|
-
linkFontSize:
|
|
187
|
-
linkPadding:
|
|
267
|
+
links: o,
|
|
268
|
+
hamburger: a(t, "hamburger", "none"),
|
|
269
|
+
alignment: a(t, "align", "center"),
|
|
270
|
+
padding: h(a(t, "padding"), 0),
|
|
271
|
+
linkColor: a(t, "ico-color", "#000000"),
|
|
272
|
+
linkFontSize: b(t, "font-size", 14),
|
|
273
|
+
linkPadding: a(t, "link-padding", "10px 15px")
|
|
188
274
|
}
|
|
189
275
|
};
|
|
190
276
|
}
|
|
191
|
-
function
|
|
192
|
-
const e = t.attrs, o = [];
|
|
193
|
-
for (
|
|
194
|
-
const
|
|
195
|
-
|
|
277
|
+
function z(t, n) {
|
|
278
|
+
const e = t.attrs, o = [], i = t.children;
|
|
279
|
+
for (let r = 0; r < i.length; r++) {
|
|
280
|
+
const s = lt(i[r]);
|
|
281
|
+
if (s && ct(i[r + 2])) {
|
|
282
|
+
const d = E(i[r + 1], n);
|
|
283
|
+
if (d) {
|
|
284
|
+
Object.assign(d.values, i[r + 1].visibility), d.values.condition = s, o.push(d), r += 2;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const c = E(i[r], n);
|
|
289
|
+
c && (Object.assign(c.values, i[r].visibility), o.push(c));
|
|
196
290
|
}
|
|
197
291
|
return {
|
|
198
|
-
id:
|
|
292
|
+
id: m(),
|
|
199
293
|
type: "column",
|
|
200
294
|
attributes: {
|
|
201
|
-
backgroundColor:
|
|
202
|
-
padding:
|
|
203
|
-
borderRadius:
|
|
204
|
-
verticalAlign:
|
|
295
|
+
backgroundColor: a(e, "background-color") || void 0,
|
|
296
|
+
padding: h(a(e, "padding"), 0),
|
|
297
|
+
borderRadius: b(e, "border-radius", 0) || void 0,
|
|
298
|
+
verticalAlign: a(e, "vertical-align", "top"),
|
|
299
|
+
cssClass: a(e, "css-class") || void 0,
|
|
300
|
+
...t.visibility
|
|
205
301
|
},
|
|
206
302
|
blocks: o
|
|
207
303
|
};
|
|
208
304
|
}
|
|
209
|
-
function
|
|
305
|
+
function lt(t) {
|
|
306
|
+
var n;
|
|
307
|
+
if (t.tag === "mj-raw")
|
|
308
|
+
return (n = /^\s*\{\{#if\s+([^}]+?)\s*\}\}\s*$/.exec(t.text ?? "")) == null ? void 0 : n[1];
|
|
309
|
+
}
|
|
310
|
+
function ct(t) {
|
|
311
|
+
return (t == null ? void 0 : t.tag) === "mj-raw" && /^\s*\{\{\/if\}\}\s*$/.test(t.text ?? "");
|
|
312
|
+
}
|
|
313
|
+
function E(t, n) {
|
|
210
314
|
switch (t.tag) {
|
|
211
315
|
case "mj-text":
|
|
212
|
-
return
|
|
316
|
+
return X(t.attrs, t.text);
|
|
213
317
|
case "mj-image":
|
|
214
|
-
return
|
|
318
|
+
return K(t.attrs);
|
|
215
319
|
case "mj-button":
|
|
216
|
-
return
|
|
320
|
+
return Z(t.attrs, t.text);
|
|
217
321
|
case "mj-divider":
|
|
218
|
-
return
|
|
322
|
+
return Q(t.attrs);
|
|
219
323
|
case "mj-spacer":
|
|
220
|
-
return
|
|
324
|
+
return tt(t.attrs);
|
|
221
325
|
case "mj-social": {
|
|
222
326
|
const e = t.children.filter((o) => o.tag === "mj-social-element").map((o) => ({ attrs: o.attrs, innerText: o.text }));
|
|
223
|
-
return
|
|
327
|
+
return ot(t.attrs, e);
|
|
224
328
|
}
|
|
225
329
|
case "mj-raw":
|
|
226
|
-
return
|
|
330
|
+
return it(t.text);
|
|
331
|
+
case "mj-table":
|
|
332
|
+
return at(t.attrs, t.text);
|
|
227
333
|
case "mj-navbar": {
|
|
228
334
|
const e = t.children.filter((o) => o.tag === "mj-navbar-link").map((o) => ({ attrs: o.attrs, innerText: o.text }));
|
|
229
|
-
return
|
|
335
|
+
return st(t.attrs, e);
|
|
230
336
|
}
|
|
231
337
|
default:
|
|
232
338
|
return n.push({
|
|
@@ -235,130 +341,462 @@ function H(t, n) {
|
|
|
235
341
|
}), null;
|
|
236
342
|
}
|
|
237
343
|
}
|
|
238
|
-
function
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
344
|
+
function _(t, n, e) {
|
|
345
|
+
const o = t.attrs, i = [], r = [];
|
|
346
|
+
let s = 0, c = 0;
|
|
347
|
+
for (const g of t.children)
|
|
348
|
+
if (g.tag === "mj-column")
|
|
349
|
+
i.push(z(g, n)), r.push(g), c++;
|
|
350
|
+
else if (g.tag === "mj-group") {
|
|
351
|
+
s++;
|
|
352
|
+
for (const x of g.children)
|
|
353
|
+
x.tag === "mj-column" && (i.push(z(x, n)), r.push(x));
|
|
354
|
+
} else
|
|
247
355
|
n.push({
|
|
248
|
-
message: `Unexpected section child: ${
|
|
249
|
-
tag:
|
|
356
|
+
message: `Unexpected section child: ${g.tag}`,
|
|
357
|
+
tag: g.tag
|
|
250
358
|
});
|
|
251
|
-
|
|
252
|
-
id:
|
|
359
|
+
i.length === 0 && i.push({
|
|
360
|
+
id: m(),
|
|
253
361
|
type: "column",
|
|
254
362
|
attributes: {
|
|
255
|
-
padding:
|
|
363
|
+
padding: h(void 0, 0),
|
|
256
364
|
verticalAlign: "top"
|
|
257
365
|
},
|
|
258
366
|
blocks: []
|
|
259
367
|
});
|
|
260
|
-
const
|
|
368
|
+
const d = r.length ? ut(r, e, n) : [12], l = s === 1 && c === 0;
|
|
369
|
+
s > 0 && !l && n.push({
|
|
370
|
+
message: "A section mixing mj-group with other columns was flattened: its columns will stack on mobile",
|
|
371
|
+
tag: "mj-group"
|
|
372
|
+
});
|
|
373
|
+
const u = a(o, "full-width") === "full-width";
|
|
261
374
|
return {
|
|
262
|
-
id:
|
|
375
|
+
id: m(),
|
|
263
376
|
type: "row",
|
|
264
377
|
attributes: {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
378
|
+
...t.visibility,
|
|
379
|
+
backgroundColor: a(o, "background-color") || void 0,
|
|
380
|
+
...dt(o, n),
|
|
381
|
+
padding: h(a(o, "padding"), 0),
|
|
382
|
+
fullWidth: u,
|
|
383
|
+
cssClass: a(o, "css-class") || void 0,
|
|
384
|
+
...l ? { noStackOnMobile: !0 } : {}
|
|
269
385
|
},
|
|
270
|
-
columns:
|
|
271
|
-
columnRatios:
|
|
386
|
+
columns: i,
|
|
387
|
+
columnRatios: d,
|
|
272
388
|
locked: !1
|
|
273
389
|
};
|
|
274
390
|
}
|
|
275
|
-
function
|
|
276
|
-
const e = t
|
|
277
|
-
|
|
391
|
+
function dt(t, n) {
|
|
392
|
+
const e = a(t, "background-url");
|
|
393
|
+
if (!e) return {};
|
|
394
|
+
const o = a(t, "background-repeat");
|
|
395
|
+
return (o === "repeat-x" || o === "repeat-y") && n.push({
|
|
396
|
+
message: `background-repeat="${o}" became "repeat" — a row cannot repeat on one axis`,
|
|
397
|
+
tag: "mj-section"
|
|
398
|
+
}), {
|
|
399
|
+
backgroundImage: e,
|
|
400
|
+
backgroundRepeat: o === "no-repeat" ? "no-repeat" : "repeat",
|
|
401
|
+
backgroundSize: a(t, "background-size") || void 0,
|
|
402
|
+
backgroundPosition: a(t, "background-position") || void 0
|
|
403
|
+
};
|
|
278
404
|
}
|
|
279
|
-
function
|
|
405
|
+
function pt(t, n) {
|
|
406
|
+
var i;
|
|
407
|
+
const e = (i = t.attrs.width) == null ? void 0 : i.trim();
|
|
408
|
+
if (!e) return;
|
|
409
|
+
const o = parseFloat(e);
|
|
410
|
+
if (!(isNaN(o) || o <= 0))
|
|
411
|
+
return e.endsWith("%") ? o : o / n * 100;
|
|
412
|
+
}
|
|
413
|
+
function ut(t, n, e) {
|
|
414
|
+
const o = t.map((l) => pt(l, n));
|
|
415
|
+
if (o.every((l) => l === void 0)) {
|
|
416
|
+
const l = Math.floor(12 / o.length);
|
|
417
|
+
return o.map(() => l);
|
|
418
|
+
}
|
|
419
|
+
const i = o.reduce((l, p) => l + (p ?? 0), 0);
|
|
420
|
+
i > 101 && e.push({
|
|
421
|
+
message: `Column widths total ${Math.round(i)}% of the body width; they were scaled to fit`,
|
|
422
|
+
tag: "mj-section"
|
|
423
|
+
});
|
|
424
|
+
const r = o.filter((l) => l === void 0).length, s = Math.max(0, 100 - i), c = o.map((l) => l ?? s / r), d = c.reduce((l, p) => l + p, 0);
|
|
425
|
+
return c.map((l) => Math.max(1, Math.round(l * 12 / d)));
|
|
426
|
+
}
|
|
427
|
+
const v = "Ubuntu, Helvetica, Arial, sans-serif", N = {
|
|
428
|
+
"mj-body": { width: "600px" },
|
|
429
|
+
"mj-section": {
|
|
430
|
+
"background-repeat": "repeat",
|
|
431
|
+
"background-size": "auto",
|
|
432
|
+
"background-position": "top center",
|
|
433
|
+
direction: "ltr",
|
|
434
|
+
padding: "20px 0",
|
|
435
|
+
"text-align": "center",
|
|
436
|
+
"text-padding": "4px 4px 4px 0"
|
|
437
|
+
},
|
|
438
|
+
"mj-wrapper": {
|
|
439
|
+
"background-repeat": "repeat",
|
|
440
|
+
"background-size": "auto",
|
|
441
|
+
"background-position": "top center",
|
|
442
|
+
direction: "ltr",
|
|
443
|
+
padding: "20px 0",
|
|
444
|
+
"text-align": "center",
|
|
445
|
+
"text-padding": "4px 4px 4px 0"
|
|
446
|
+
},
|
|
447
|
+
"mj-column": { direction: "ltr", "vertical-align": "top" },
|
|
448
|
+
"mj-text": {
|
|
449
|
+
align: "left",
|
|
450
|
+
color: "#000000",
|
|
451
|
+
"font-family": v,
|
|
452
|
+
"font-size": "13px",
|
|
453
|
+
"line-height": "1",
|
|
454
|
+
padding: "10px 25px"
|
|
455
|
+
},
|
|
456
|
+
"mj-button": {
|
|
457
|
+
align: "center",
|
|
458
|
+
"background-color": "#414141",
|
|
459
|
+
border: "none",
|
|
460
|
+
"border-radius": "3px",
|
|
461
|
+
color: "#ffffff",
|
|
462
|
+
"font-family": v,
|
|
463
|
+
"font-size": "13px",
|
|
464
|
+
"font-weight": "normal",
|
|
465
|
+
"inner-padding": "10px 25px",
|
|
466
|
+
"line-height": "120%",
|
|
467
|
+
padding: "10px 25px",
|
|
468
|
+
target: "_blank",
|
|
469
|
+
"text-decoration": "none",
|
|
470
|
+
"text-transform": "none",
|
|
471
|
+
"vertical-align": "middle"
|
|
472
|
+
},
|
|
473
|
+
"mj-image": {
|
|
474
|
+
alt: "",
|
|
475
|
+
align: "center",
|
|
476
|
+
border: "0",
|
|
477
|
+
height: "auto",
|
|
478
|
+
padding: "10px 25px",
|
|
479
|
+
target: "_blank",
|
|
480
|
+
"font-size": "13px"
|
|
481
|
+
},
|
|
482
|
+
"mj-divider": {
|
|
483
|
+
"border-color": "#000000",
|
|
484
|
+
"border-style": "solid",
|
|
485
|
+
"border-width": "4px",
|
|
486
|
+
padding: "10px 25px",
|
|
487
|
+
width: "100%",
|
|
488
|
+
align: "center"
|
|
489
|
+
},
|
|
490
|
+
"mj-spacer": { height: "20px" },
|
|
491
|
+
"mj-social": {
|
|
492
|
+
align: "center",
|
|
493
|
+
"border-radius": "3px",
|
|
494
|
+
color: "#333333",
|
|
495
|
+
"font-family": v,
|
|
496
|
+
"font-size": "13px",
|
|
497
|
+
"icon-size": "20px",
|
|
498
|
+
"line-height": "22px",
|
|
499
|
+
mode: "horizontal",
|
|
500
|
+
padding: "10px 25px",
|
|
501
|
+
"text-decoration": "none"
|
|
502
|
+
},
|
|
503
|
+
"mj-social-element": {
|
|
504
|
+
alt: "",
|
|
505
|
+
align: "left",
|
|
506
|
+
"icon-position": "left",
|
|
507
|
+
color: "#000",
|
|
508
|
+
"border-radius": "3px",
|
|
509
|
+
"font-family": v,
|
|
510
|
+
"font-size": "13px",
|
|
511
|
+
"line-height": "1",
|
|
512
|
+
padding: "4px",
|
|
513
|
+
"text-padding": "4px 4px 4px 0",
|
|
514
|
+
target: "_blank",
|
|
515
|
+
"text-decoration": "none",
|
|
516
|
+
"vertical-align": "middle"
|
|
517
|
+
},
|
|
518
|
+
"mj-hero": {
|
|
519
|
+
mode: "fixed-height",
|
|
520
|
+
height: "0px",
|
|
521
|
+
"background-position": "center center",
|
|
522
|
+
padding: "0px",
|
|
523
|
+
"background-color": "#ffffff",
|
|
524
|
+
"vertical-align": "top"
|
|
525
|
+
},
|
|
526
|
+
"mj-navbar": {
|
|
527
|
+
align: "center",
|
|
528
|
+
"ico-align": "center",
|
|
529
|
+
"ico-open": "☰",
|
|
530
|
+
"ico-close": "⊗",
|
|
531
|
+
"ico-color": "#000000",
|
|
532
|
+
"ico-font-size": "30px",
|
|
533
|
+
"ico-font-family": v,
|
|
534
|
+
"ico-text-transform": "uppercase",
|
|
535
|
+
"ico-padding": "10px",
|
|
536
|
+
"ico-text-decoration": "none",
|
|
537
|
+
"ico-line-height": "30px"
|
|
538
|
+
},
|
|
539
|
+
"mj-navbar-link": {
|
|
540
|
+
color: "#000000",
|
|
541
|
+
"font-family": v,
|
|
542
|
+
"font-size": "13px",
|
|
543
|
+
"font-weight": "normal",
|
|
544
|
+
"line-height": "22px",
|
|
545
|
+
padding: "15px 10px",
|
|
546
|
+
target: "_blank",
|
|
547
|
+
"text-decoration": "none",
|
|
548
|
+
"text-transform": "uppercase"
|
|
549
|
+
},
|
|
550
|
+
"mj-table": {
|
|
551
|
+
align: "left",
|
|
552
|
+
border: "none",
|
|
553
|
+
cellpadding: "0",
|
|
554
|
+
cellspacing: "0",
|
|
555
|
+
color: "#000000",
|
|
556
|
+
"font-family": v,
|
|
557
|
+
"font-size": "13px",
|
|
558
|
+
"line-height": "22px",
|
|
559
|
+
padding: "10px 25px",
|
|
560
|
+
"table-layout": "auto",
|
|
561
|
+
width: "100%"
|
|
562
|
+
}
|
|
563
|
+
}, gt = v;
|
|
564
|
+
function ft(t, n, e) {
|
|
280
565
|
return {
|
|
281
|
-
id:
|
|
566
|
+
id: m(),
|
|
282
567
|
type: "hero",
|
|
283
568
|
values: {
|
|
284
|
-
backgroundUrl:
|
|
285
|
-
backgroundPosition:
|
|
286
|
-
mode:
|
|
287
|
-
width:
|
|
288
|
-
height:
|
|
289
|
-
verticalAlign:
|
|
290
|
-
padding:
|
|
291
|
-
innerPadding:
|
|
292
|
-
backgroundColor:
|
|
569
|
+
backgroundUrl: a(t, "background-url"),
|
|
570
|
+
backgroundPosition: a(t, "background-position", "center center"),
|
|
571
|
+
mode: a(t, "mode", "fluid-height"),
|
|
572
|
+
width: b(t, "width", 600),
|
|
573
|
+
height: b(t, "height", 400),
|
|
574
|
+
verticalAlign: a(t, "vertical-align", "middle"),
|
|
575
|
+
padding: h(a(t, "padding"), 0),
|
|
576
|
+
innerPadding: h(e, 20),
|
|
577
|
+
backgroundColor: a(t, "background-color", "#ffffff"),
|
|
293
578
|
content: n
|
|
294
579
|
}
|
|
295
580
|
};
|
|
296
581
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
582
|
+
const ht = [
|
|
583
|
+
["font-style", "font-style"],
|
|
584
|
+
["font-weight", "font-weight"],
|
|
585
|
+
["letter-spacing", "letter-spacing"],
|
|
586
|
+
["line-height", "line-height"],
|
|
587
|
+
["text-align", "align"],
|
|
588
|
+
["text-decoration", "text-decoration"],
|
|
589
|
+
["text-transform", "text-transform"],
|
|
590
|
+
["height", "height"]
|
|
591
|
+
], mt = { "line-height": "1.5", align: "left" };
|
|
592
|
+
function D(t, n, e) {
|
|
593
|
+
const o = ht.filter(([, i]) => t[i] && t[i] !== mt[i]).concat(!e && t.padding ? [["padding", "padding"]] : []).map(([i, r]) => `${i}:${t[r]};`).join("");
|
|
594
|
+
return o ? `<div style="${w(o)}">${n}</div>` : e ? n : `<div>${n}</div>`;
|
|
595
|
+
}
|
|
596
|
+
function bt(t, n) {
|
|
597
|
+
const e = { ...N["mj-button"], ...t }, o = e["background-color"], i = `border:${e.border};border-radius:${e["border-radius"]};cursor:auto;mso-padding-alt:${e["inner-padding"]};background:${o};`, r = `display:inline-block;background:${o};color:${e.color};font-family:${e["font-family"]};font-size:${e["font-size"]};font-weight:${e["font-weight"]};line-height:${e["line-height"]};margin:0;text-decoration:${e["text-decoration"]};text-transform:${e["text-transform"]};padding:${e["inner-padding"]};mso-padding-alt:0px;border-radius:${e["border-radius"]};`, s = e.href ? `<a href="${w(e.href)}" target="${w(e.target)}" style="${w(r)}">${n.trim()}</a>` : `<p style="${w(r)}">${n.trim()}</p>`;
|
|
598
|
+
return `<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%"><tr><td align="${w(e.align)}" style="padding:${w(e.padding)};"><table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;"><tr><td align="center"${o === "none" ? "" : ` bgcolor="${w(o)}"`} role="presentation" valign="${w(e["vertical-align"])}" style="${w(i)}">${s}</td></tr></table></td></tr></table>`;
|
|
599
|
+
}
|
|
600
|
+
function w(t) {
|
|
601
|
+
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
602
|
+
}
|
|
603
|
+
function xt(t, n) {
|
|
604
|
+
const e = b(t.attrs, "width", 600), o = a(t.attrs, "background-color"), i = [];
|
|
605
|
+
let r = [], s;
|
|
606
|
+
const c = (d) => {
|
|
607
|
+
var g;
|
|
608
|
+
const [l, p] = r;
|
|
609
|
+
l && (d.attributes.condition = l);
|
|
610
|
+
const [u] = ((g = d.columns[0]) == null ? void 0 : g.blocks) ?? [];
|
|
611
|
+
return p && (u == null ? void 0 : u.type) === "hero" && (u.values.condition = p), r = [], s && (d.attributes.repeat = s, s = void 0), d;
|
|
612
|
+
};
|
|
613
|
+
for (const d of t.children)
|
|
614
|
+
switch (d.tag) {
|
|
303
615
|
case "mj-raw": {
|
|
304
|
-
const
|
|
305
|
-
|
|
616
|
+
const l = /\{\{#if\s+([^}]+?)\s*\}\}/.exec(d.text ?? "");
|
|
617
|
+
l && r.push(l[1].trim());
|
|
618
|
+
const p = /^\s*\{\{#each\s+([^}]+?)\s*\}\}\s*$/.exec(d.text ?? "");
|
|
619
|
+
p && (s = p[1].trim(), r = [r[0]]);
|
|
306
620
|
break;
|
|
307
621
|
}
|
|
308
622
|
case "mj-section":
|
|
309
|
-
|
|
623
|
+
i.push(c(_(d, n, e)));
|
|
310
624
|
break;
|
|
311
625
|
case "mj-hero": {
|
|
312
|
-
const
|
|
313
|
-
|
|
626
|
+
const l = kt(d, n), p = ft(d.attrs, l.content, l.innerPadding);
|
|
627
|
+
Object.assign(p.values, d.visibility);
|
|
628
|
+
const u = {
|
|
629
|
+
id: m(),
|
|
314
630
|
type: "column",
|
|
315
631
|
attributes: {
|
|
316
|
-
padding:
|
|
632
|
+
padding: h(void 0, 0),
|
|
317
633
|
verticalAlign: "top"
|
|
318
634
|
},
|
|
319
|
-
blocks: [
|
|
635
|
+
blocks: [p]
|
|
320
636
|
}, g = {
|
|
321
|
-
id:
|
|
637
|
+
id: m(),
|
|
322
638
|
type: "row",
|
|
323
639
|
attributes: {
|
|
324
|
-
padding:
|
|
640
|
+
padding: h(void 0, 0),
|
|
325
641
|
fullWidth: !1
|
|
326
642
|
},
|
|
327
|
-
columns: [
|
|
643
|
+
columns: [u],
|
|
328
644
|
columnRatios: [12],
|
|
329
645
|
locked: !1
|
|
330
646
|
};
|
|
331
|
-
|
|
647
|
+
i.push(c(g));
|
|
332
648
|
break;
|
|
333
649
|
}
|
|
334
650
|
case "mj-wrapper":
|
|
335
|
-
|
|
336
|
-
|
|
651
|
+
n.push({
|
|
652
|
+
message: "mj-wrapper styling (padding, background-color) was dropped: the document model has no wrapper; its sections were imported unwrapped",
|
|
653
|
+
tag: "mj-wrapper"
|
|
654
|
+
});
|
|
655
|
+
for (const l of d.children)
|
|
656
|
+
l.tag === "mj-section" && i.push(c(_(l, n, e)));
|
|
337
657
|
break;
|
|
338
658
|
default:
|
|
339
659
|
n.push({
|
|
340
|
-
message: `Unknown body child element: ${
|
|
341
|
-
tag:
|
|
660
|
+
message: `Unknown body child element: ${d.tag}`,
|
|
661
|
+
tag: d.tag
|
|
342
662
|
});
|
|
343
663
|
break;
|
|
344
664
|
}
|
|
345
|
-
return { width: e, backgroundColor: o, rows:
|
|
665
|
+
return { width: e, backgroundColor: o, rows: i };
|
|
346
666
|
}
|
|
347
|
-
function
|
|
348
|
-
const
|
|
667
|
+
function kt(t, n) {
|
|
668
|
+
const [e] = t.children;
|
|
669
|
+
if (t.children.length === 1 && e.tag === "mj-text")
|
|
670
|
+
return { content: D(e.attrs, e.text, !0), innerPadding: e.attrs.padding };
|
|
671
|
+
const o = [];
|
|
672
|
+
for (const i of t.children)
|
|
673
|
+
i.tag === "mj-text" ? o.push(D(i.attrs, i.text, !1)) : i.tag === "mj-button" ? o.push(bt(i.attrs, i.text)) : n.push({ message: `Unsupported mj-hero child element: ${i.tag}`, tag: i.tag });
|
|
674
|
+
return { content: o.join("") || "<p>Hero Content</p>" };
|
|
675
|
+
}
|
|
676
|
+
const wt = /* @__PURE__ */ new Set(["mj-section", "mj-column", "mj-text", "mj-button", "mj-image"]);
|
|
677
|
+
function F(t, n, e) {
|
|
678
|
+
const { "mj-class": o = "", ...i } = t.attrs, r = o.split(/\s+/).filter(Boolean).reduce((c, d) => {
|
|
679
|
+
const l = n.classes[d] ?? {}, p = c["css-class"] && l["css-class"] ? { "css-class": `${c["css-class"]} ${l["css-class"]}` } : {};
|
|
680
|
+
return { ...c, ...l, ...p };
|
|
681
|
+
}, {});
|
|
682
|
+
t.attrs = { ...N[t.tag], ...n.all, ...n.tags[t.tag], ...r, ...i }, t.visibility = O(t.attrs);
|
|
683
|
+
const s = t.attrs["css-class"];
|
|
684
|
+
s && !wt.has(t.tag) && e.push({ message: `css-class "${s}" on <${t.tag}> was dropped`, tag: t.tag });
|
|
685
|
+
for (const c of t.children)
|
|
686
|
+
F(c, n, e);
|
|
687
|
+
}
|
|
688
|
+
const I = /* @__PURE__ */ new Set([
|
|
689
|
+
"address",
|
|
690
|
+
"article",
|
|
691
|
+
"aside",
|
|
692
|
+
"blockquote",
|
|
693
|
+
"center",
|
|
694
|
+
"dd",
|
|
695
|
+
"div",
|
|
696
|
+
"dl",
|
|
697
|
+
"dt",
|
|
698
|
+
"figcaption",
|
|
699
|
+
"figure",
|
|
700
|
+
"footer",
|
|
701
|
+
"form",
|
|
702
|
+
"h1",
|
|
703
|
+
"h2",
|
|
704
|
+
"h3",
|
|
705
|
+
"h4",
|
|
706
|
+
"h5",
|
|
707
|
+
"h6",
|
|
708
|
+
"header",
|
|
709
|
+
"hr",
|
|
710
|
+
"li",
|
|
711
|
+
"main",
|
|
712
|
+
"nav",
|
|
713
|
+
"ol",
|
|
714
|
+
"p",
|
|
715
|
+
"pre",
|
|
716
|
+
"section",
|
|
717
|
+
"table",
|
|
718
|
+
"tbody",
|
|
719
|
+
"td",
|
|
720
|
+
"tfoot",
|
|
721
|
+
"th",
|
|
722
|
+
"thead",
|
|
723
|
+
"tr",
|
|
724
|
+
"ul"
|
|
725
|
+
]), B = /* @__PURE__ */ new Set([
|
|
726
|
+
"area",
|
|
727
|
+
"base",
|
|
728
|
+
"br",
|
|
729
|
+
"col",
|
|
730
|
+
"embed",
|
|
731
|
+
"hr",
|
|
732
|
+
"img",
|
|
733
|
+
"input",
|
|
734
|
+
"link",
|
|
735
|
+
"meta",
|
|
736
|
+
"source",
|
|
737
|
+
"track",
|
|
738
|
+
"wbr"
|
|
739
|
+
]), vt = "14px", jt = "#000000";
|
|
740
|
+
function M(t, n) {
|
|
741
|
+
if (t.tag === "mj-text") {
|
|
742
|
+
const { color: e, "font-size": o, "font-family": i } = t.attrs, r = [];
|
|
743
|
+
e && e.toLowerCase() !== jt && r.push(`color: ${e}`), o && o !== vt && r.push(`font-size: ${o}`), i && i !== n && r.push(`font-family: ${i}`), r.length > 0 && (t.text = yt(t.text, `<span style="${$t(r.join("; "))}">`));
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
349
746
|
for (const e of t.children)
|
|
350
|
-
(e
|
|
351
|
-
return n.join("") || "<p>Hero Content</p>";
|
|
747
|
+
M(e, n);
|
|
352
748
|
}
|
|
353
|
-
function
|
|
749
|
+
function yt(t, n) {
|
|
750
|
+
const e = [];
|
|
751
|
+
let o = -1, i = -1, r = !1, s = 0;
|
|
752
|
+
const c = () => {
|
|
753
|
+
o >= 0 && r && e.push([o, n], [i, "</span>"]), o = -1, r = !1;
|
|
754
|
+
}, d = (u, g) => {
|
|
755
|
+
o < 0 && (o = u), i = g;
|
|
756
|
+
}, l = new R({
|
|
757
|
+
onopentag(u) {
|
|
758
|
+
if (s === 0 && I.has(u)) {
|
|
759
|
+
c();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
d(l.startIndex, l.endIndex + 1), B.has(u) ? r = !0 : s++;
|
|
763
|
+
},
|
|
764
|
+
onclosetag(u, g) {
|
|
765
|
+
if (!B.has(u)) {
|
|
766
|
+
if (s === 0) {
|
|
767
|
+
I.has(u) && c();
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
s--, g || (i = l.endIndex + 1);
|
|
771
|
+
}
|
|
772
|
+
},
|
|
773
|
+
ontext(u) {
|
|
774
|
+
o < 0 && !u.trim() || (d(l.startIndex, l.endIndex + 1), u.trim() && (r = !0));
|
|
775
|
+
},
|
|
776
|
+
oncomment() {
|
|
777
|
+
o >= 0 && (i = l.endIndex + 1);
|
|
778
|
+
}
|
|
779
|
+
}, { recognizeSelfClosing: !0, lowerCaseTags: !0 });
|
|
780
|
+
l.write(t), l.end(), c();
|
|
781
|
+
let p = t;
|
|
782
|
+
for (const [u, g] of e.reverse())
|
|
783
|
+
p = p.slice(0, u) + g + p.slice(u);
|
|
784
|
+
return p;
|
|
785
|
+
}
|
|
786
|
+
function $t(t) {
|
|
787
|
+
return t.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
788
|
+
}
|
|
789
|
+
function St(t) {
|
|
354
790
|
const n = { tag: "root", attrs: {}, children: [], text: "" }, e = [n], o = /* @__PURE__ */ new Set([
|
|
355
791
|
"mj-text",
|
|
356
792
|
"mj-button",
|
|
357
793
|
"mj-raw",
|
|
358
794
|
"mj-preview",
|
|
795
|
+
"mj-title",
|
|
359
796
|
"mj-social-element",
|
|
360
|
-
"mj-navbar-link"
|
|
361
|
-
|
|
797
|
+
"mj-navbar-link",
|
|
798
|
+
"mj-table"
|
|
799
|
+
]), i = /* @__PURE__ */ new Set([
|
|
362
800
|
"mj-image",
|
|
363
801
|
"mj-divider",
|
|
364
802
|
"mj-spacer",
|
|
@@ -366,98 +804,124 @@ function E(t) {
|
|
|
366
804
|
"mj-class",
|
|
367
805
|
"mj-font",
|
|
368
806
|
"mj-breakpoint"
|
|
369
|
-
])
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
807
|
+
]), r = /* @__PURE__ */ new Set([
|
|
808
|
+
"area",
|
|
809
|
+
"base",
|
|
810
|
+
"br",
|
|
811
|
+
"col",
|
|
812
|
+
"embed",
|
|
813
|
+
"hr",
|
|
814
|
+
"img",
|
|
815
|
+
"input",
|
|
816
|
+
"link",
|
|
817
|
+
"meta",
|
|
818
|
+
"source",
|
|
819
|
+
"track",
|
|
820
|
+
"wbr"
|
|
821
|
+
]), s = /* @__PURE__ */ new Set(["mj-text", "mj-button", "mj-raw"]), c = /* @__PURE__ */ new Set(["style", "script"]), d = (f) => f.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), l = (f) => f.replace(/&/g, "&").replace(/"/g, """);
|
|
822
|
+
let p = null, u = "", g = 0, x = !1;
|
|
823
|
+
const $ = new R({
|
|
824
|
+
onopentag(f, j) {
|
|
825
|
+
if (p) {
|
|
826
|
+
const W = s.has(p.node.tag), T = Object.entries(j).map(([P, A]) => `${P}="${W ? l(A) : A}"`).join(" ");
|
|
827
|
+
u += T ? `<${f} ${T}>` : `<${f}>`, r.has(f) || g++, c.has(f) && (x = !0);
|
|
376
828
|
return;
|
|
377
829
|
}
|
|
378
|
-
const
|
|
379
|
-
e[e.length - 1].children.push(
|
|
830
|
+
const k = { tag: f, attrs: j, children: [], text: "" };
|
|
831
|
+
e[e.length - 1].children.push(k), !i.has(f) && (e.push(k), o.has(f) && (p = { node: k, depth: 0 }, u = "", g = 0));
|
|
380
832
|
},
|
|
381
|
-
ontext(
|
|
382
|
-
if (
|
|
383
|
-
s
|
|
833
|
+
ontext(f) {
|
|
834
|
+
if (p) {
|
|
835
|
+
const k = s.has(p.node.tag) && !x;
|
|
836
|
+
u += k ? d(f) : f;
|
|
384
837
|
return;
|
|
385
838
|
}
|
|
386
|
-
const
|
|
387
|
-
|
|
839
|
+
const j = e[e.length - 1];
|
|
840
|
+
j.text += f;
|
|
388
841
|
},
|
|
389
|
-
onclosetag(
|
|
390
|
-
if (
|
|
391
|
-
if (
|
|
392
|
-
|
|
842
|
+
onclosetag(f) {
|
|
843
|
+
if (p) {
|
|
844
|
+
if (r.has(f)) return;
|
|
845
|
+
if (g > 0) {
|
|
846
|
+
u += `</${f}>`, g--, c.has(f) && (x = !1);
|
|
393
847
|
return;
|
|
394
848
|
}
|
|
395
|
-
|
|
849
|
+
p.node.text = u, p = null, u = "", g = 0, e.length > 1 && e[e.length - 1].tag === f && e.pop();
|
|
396
850
|
return;
|
|
397
851
|
}
|
|
398
|
-
|
|
852
|
+
i.has(f) || e.length > 1 && e[e.length - 1].tag === f && e.pop();
|
|
853
|
+
},
|
|
854
|
+
oncomment(f) {
|
|
855
|
+
p && (u += `<!--${f}-->`);
|
|
399
856
|
}
|
|
400
857
|
}, {
|
|
401
858
|
recognizeSelfClosing: !0,
|
|
402
859
|
lowerCaseTags: !0,
|
|
403
860
|
lowerCaseAttributeNames: !0
|
|
404
861
|
});
|
|
405
|
-
return
|
|
862
|
+
return $.write(t), $.end(), n;
|
|
406
863
|
}
|
|
407
|
-
function
|
|
864
|
+
function C(t, n) {
|
|
408
865
|
if (t.tag === n) return t;
|
|
409
866
|
for (const e of t.children) {
|
|
410
|
-
const o =
|
|
867
|
+
const o = C(e, n);
|
|
411
868
|
if (o) return o;
|
|
412
869
|
}
|
|
413
870
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
871
|
+
function At(t, n) {
|
|
872
|
+
var j;
|
|
873
|
+
const e = [], o = St(t), i = C(o, "mjml");
|
|
874
|
+
if (!i)
|
|
417
875
|
return e.push({ message: "No <mjml> root element found" }), {
|
|
418
|
-
document:
|
|
876
|
+
document: L(),
|
|
419
877
|
warnings: e
|
|
420
878
|
};
|
|
421
|
-
const
|
|
422
|
-
let
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
tag:
|
|
426
|
-
attrs:
|
|
427
|
-
children:
|
|
428
|
-
tag:
|
|
429
|
-
attrs:
|
|
879
|
+
const r = C(i, "mj-head"), s = C(i, "mj-body");
|
|
880
|
+
let c = { attributeDefaults: { all: {}, tags: {}, classes: {} } };
|
|
881
|
+
if (r && (c = q(
|
|
882
|
+
r.children.map((k) => ({
|
|
883
|
+
tag: k.tag,
|
|
884
|
+
attrs: k.attrs,
|
|
885
|
+
children: k.children.map((S) => ({
|
|
886
|
+
tag: S.tag,
|
|
887
|
+
attrs: S.attrs,
|
|
430
888
|
children: [],
|
|
431
|
-
text:
|
|
889
|
+
text: S.text
|
|
432
890
|
})),
|
|
433
|
-
text:
|
|
891
|
+
text: k.text
|
|
434
892
|
}))
|
|
435
893
|
)), !s)
|
|
436
894
|
return e.push({ message: "No <mj-body> element found" }), {
|
|
437
|
-
document:
|
|
895
|
+
document: L(),
|
|
438
896
|
warnings: e
|
|
439
897
|
};
|
|
440
|
-
const d =
|
|
898
|
+
const d = c.fontFamily ?? gt;
|
|
899
|
+
F(s, c.attributeDefaults, e), M(s, d);
|
|
900
|
+
const l = xt(s, e), p = i.attrs.lang, u = p && p !== "und" ? p : void 0, g = i.attrs.dir, x = g === "ltr" || g === "rtl" ? g : void 0, $ = (/* @__PURE__ */ new Date()).toISOString();
|
|
441
901
|
return { document: {
|
|
442
902
|
version: "1.0",
|
|
443
903
|
metadata: {
|
|
444
|
-
name: "Imported Template",
|
|
445
|
-
previewText:
|
|
446
|
-
createdAt:
|
|
447
|
-
updatedAt:
|
|
904
|
+
name: ((j = c.title) == null ? void 0 : j.trim()) || "Imported Template",
|
|
905
|
+
previewText: c.previewText,
|
|
906
|
+
createdAt: $,
|
|
907
|
+
updatedAt: $
|
|
448
908
|
},
|
|
449
909
|
body: {
|
|
450
910
|
attributes: {
|
|
451
|
-
width:
|
|
452
|
-
backgroundColor:
|
|
453
|
-
fontFamily:
|
|
454
|
-
contentAlignment: "center"
|
|
911
|
+
width: l.width,
|
|
912
|
+
backgroundColor: l.backgroundColor,
|
|
913
|
+
fontFamily: d,
|
|
914
|
+
contentAlignment: "center",
|
|
915
|
+
...c.linkStyle ? { linkStyle: c.linkStyle } : {},
|
|
916
|
+
...u ? { language: u } : {},
|
|
917
|
+
...x ? { direction: x } : {},
|
|
918
|
+
css: c.css
|
|
455
919
|
},
|
|
456
|
-
rows:
|
|
920
|
+
rows: l.rows
|
|
457
921
|
}
|
|
458
922
|
}, warnings: e };
|
|
459
923
|
}
|
|
460
|
-
function
|
|
924
|
+
function L() {
|
|
461
925
|
const t = (/* @__PURE__ */ new Date()).toISOString();
|
|
462
926
|
return {
|
|
463
927
|
version: "1.0",
|
|
@@ -478,5 +942,5 @@ function j() {
|
|
|
478
942
|
};
|
|
479
943
|
}
|
|
480
944
|
export {
|
|
481
|
-
|
|
945
|
+
At as mjmlToDocument
|
|
482
946
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lit-pigeon/parser-mjml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MJML-to-PigeonDocument parser for Pigeon email editor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"htmlparser2": "^9.1.0",
|
|
23
|
-
"@lit-pigeon/core": "^0.
|
|
23
|
+
"@lit-pigeon/core": "^0.4.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"mjml": "^4.15.0",
|
|
26
27
|
"typescript": "^5.5.0",
|
|
27
28
|
"vite": "^6.0.0",
|
|
28
29
|
"vite-plugin-dts": "^4.0.0",
|
|
29
|
-
"vitest": "^
|
|
30
|
+
"vitest": "^4.1.12",
|
|
31
|
+
"@lit-pigeon/renderer-mjml": "^0.3.0"
|
|
30
32
|
},
|
|
31
33
|
"publishConfig": {
|
|
32
34
|
"access": "public"
|