@lit-pigeon/import-unlayer 0.2.0 → 0.3.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 CHANGED
@@ -55,6 +55,8 @@ const mjml = documentToMjml(document);
55
55
  | `social` | `social` | Known platforms map by name; anything else becomes a `custom` icon. |
56
56
  | rows / `cells` | rows / `columnRatios` | Relative widths convert to the 12-column grid (`[1, 2]` → `[4, 8]`). |
57
57
  | body `values` | body attributes | Width, background, font family, alignment, preheader. |
58
+ | `video` | `video` | From `@lit-pigeon/blocks`; carries the video URL and the poster image. |
59
+ | `timer` | `countdown` | From `@lit-pigeon/blocks`; carries `endTime` as the fallback label. |
58
60
 
59
61
  ### Why colours end up in a `<span>`
60
62
 
@@ -82,20 +84,39 @@ what needs a second look.
82
84
  | Code | Meaning |
83
85
  | --- | --- |
84
86
  | `not-a-design` | Input was not valid JSON, or had no `body` key. |
85
- | `unsupported-block` | An Unlayer block with no Pigeon equivalent (`video`, `timer`, `form`). |
87
+ | `unsupported-block` | An Unlayer block with no Pigeon equivalent (`form`). |
88
+ | `plugin-block` | Converted to a block from `@lit-pigeon/blocks`, which is not registered. See below. |
86
89
  | `custom-tool` | A `custom#*` tool. Re-create it as a Lit Pigeon plugin block. |
87
90
  | `display-condition-dropped` | See below. |
88
91
  | `heading-level-clamped` | `h4`–`h6` imported as `h3`. |
89
92
  | `empty-row` | A row with no columns was skipped. |
90
93
  | `no-rows` | The design had no rows at all. |
91
94
 
95
+ **`video` and `timer` need the standard catalog.** They convert to the `video`
96
+ and `countdown` blocks from `@lit-pigeon/blocks`, which this package does not
97
+ depend on — that would pull the whole catalog into every migration. The
98
+ importer emits the block by type name, so if the host has not installed the
99
+ package and called `registerStandardBlocks()`, the block shows as the
100
+ registry's labelled placeholder rather than rendering, and a `plugin-block`
101
+ warning says so. A timer's hosted countdown image is generated per open and is
102
+ not in the design JSON, so the block arrives with Unlayer's `endTime` as its
103
+ fallback label and a countdown image URL for you to paste in.
104
+
92
105
  **Display conditions are dropped deliberately.** Unlayer stores them as raw
93
106
  `before`/`after` template fragments, not as the boolean expression Pigeon's
94
107
  `condition` wraps in `{{#if}}`. Guessing a translation would silently change
95
108
  who receives the content, so the importer reports the condition by name and
96
109
  leaves the row unconditional for you to re-add.
97
110
 
98
- Mobile `_override` values and `hideDesktop` / `hideMobile` are not yet mapped.
111
+ `hideDesktop` and `_override.mobile.hideMobile` are mapped onto `hideOnDesktop`
112
+ / `hideOnMobile` on rows, columns and blocks; other `_override` values (mobile
113
+ padding, font sizes) are not. Rows Unlayer marks as locked are imported with
114
+ `locked: true`, which the editor enforces. HTML blocks are
115
+ passed through verbatim, so review imported designs before loading them into
116
+ the editor; see [Security](../../docs/guide/security.md).
117
+
118
+ A step-by-step migration, including mapping Unlayer's API calls and merge
119
+ tags, is in [Migrating from Unlayer](../../docs/guide/migrating-from-unlayer.md).
99
120
 
100
121
  ## Licence
101
122
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@lit-pigeon/core"),z=require("htmlparser2");function p(t,e=0){const o=r=>({top:r,right:r,bottom:r,left:r});if(typeof t!="string"||!t.trim())return o(e);const n=t.trim().split(/\s+/).map(r=>g(r,e));switch(n.length){case 1:return o(n[0]);case 2:return{top:n[0],right:n[1],bottom:n[0],left:n[1]};case 3:return{top:n[0],right:n[1],bottom:n[2],left:n[1]};case 4:return{top:n[0],right:n[1],bottom:n[2],left:n[3]};default:return o(e)}}function g(t,e=0){if(typeof t=="number")return Number.isFinite(t)?t:e;if(typeof t!="string")return e;const o=parseFloat(t);return Number.isNaN(o)?e:o}function s(t,e=""){return typeof t=="string"?t:e}function u(t){const e=s(t).trim();return e||void 0}function y(t,e="left"){return t==="left"||t==="center"||t==="right"?t:e}function c(t,...e){let o=t;for(const n of e){if(typeof o!="object"||o===null)return;o=o[n]}return o}function D(t,e){if(e<=0)return[];const o=t&&t.length===e&&t.every(a=>a>0)?t:new Array(e).fill(1),n=o.reduce((a,d)=>a+d,0),r=o.map(a=>Math.max(1,Math.round(a*12/n)));let i=12-r.reduce((a,d)=>a+d,0);for(;i!==0;){const a=i>0?r.indexOf(Math.max(...r)):r.indexOf(Math.max(...r.filter(d=>d>1)));if(a===-1)break;r[a]+=i>0?1:-1,i+=i>0?-1:1}return r}const x=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function P(t){const e=[];return t.color&&e.push(`color: ${t.color}`),t.fontFamily&&e.push(`font-family: ${t.fontFamily}`),t.fontSize&&e.push(`font-size: ${t.fontSize}`),e.length?e.join("; "):void 0}function S(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function k(t){return Object.entries(t).map(([e,o])=>` ${e}="${S(o)}"`).join("")}function $(t,e){const o=P(e);if(!o)return t;const n=`<span style="${S(o)}">`,r="</span>";let i="",a=0,d=!1;const m=new z.Parser({onopentag(l,h){if(x.has(l)){a===0?i+=`${n}<${l}${k(h)}>${r}`:i+=`<${l}${k(h)}>`;return}i+=`<${l}${k(h)}>`,a===0&&(i+=n,d=!0),a++},ontext(l){if(a===0){i+=l.trim()?`${n}${l}${r}`:l;return}i+=l},onclosetag(l){x.has(l)||(a--,a===0&&d&&(i+=r,d=!1),i+=`</${l}>`)}},{recognizeSelfClosing:!0,lowerCaseTags:!0,lowerCaseAttributeNames:!0});return m.write(t),m.end(),i}function T(t){const e=t.trim();return e?/^<(p|h[1-6]|ul|ol|blockquote|div|table)[\s>]/i.test(e)?e:`<p>${e}</p>`:"<p></p>"}function O(t,e,o){const n=s(t.type),r=t.values??{};switch(n){case"text":return W(r,e);case"heading":return B(r,e,o);case"image":return N(r);case"button":return U(r);case"divider":return L(r);case"html":return R(r);case"menu":return H(r,e);case"social":return j(r);default:return null}}function W(t,e){const o=$(s(t.text),{fontSize:s(t.fontSize)||void 0,color:u(t.color)??e.textColor,fontFamily:e.fontFamily});return{id:f.generateId(),type:"text",values:{content:T(o),padding:p(t.containerPadding,10),lineHeight:s(t.lineHeight,"140%"),textAlign:y(t.textAlign)}}}function B(t,e,o){const n=s(t.headingType,"h1").toLowerCase();let r=/^h[1-6]$/.test(n)?n:"h1";/^h[4-6]$/.test(r)&&(o.push({code:"heading-level-clamped",message:`Heading level <${r}> is not supported by the editor; imported as <h3>.`}),r="h3");const i=$(s(t.text),{fontSize:s(t.fontSize)||void 0,color:u(t.color)??e.textColor,fontFamily:e.fontFamily});return{id:f.generateId(),type:"text",values:{content:`<${r}>${i}</${r}>`,padding:p(t.containerPadding,10),lineHeight:s(t.lineHeight,"140%"),textAlign:y(t.textAlign)}}}function N(t){const e=s(c(t,"action","values","href")),o=c(t,"src","autoWidth")===!0;return{id:f.generateId(),type:"image",values:{src:s(c(t,"src","url")),alt:s(t.altText),width:o?"auto":g(c(t,"src","width"),0)||"auto",...e?{href:e}:{},padding:p(t.containerPadding,10),alignment:y(t.textAlign,"center")}}}function U(t){return{id:f.generateId(),type:"button",values:{content:T(s(t.text)),href:s(c(t,"href","values","href"),"#"),backgroundColor:u(c(t,"buttonColors","backgroundColor"))??"#3b82f6",textColor:u(c(t,"buttonColors","color"))??"#ffffff",borderRadius:g(t.borderRadius,4),padding:p(t.containerPadding,10),innerPadding:p(t.padding,12),fontSize:g(t.fontSize,16),fontWeight:"600",alignment:y(t.textAlign,"center"),fullWidth:c(t,"size","autoWidth")===!1}}}function L(t){const e=s(c(t,"border","borderTopStyle"),"solid");return{id:f.generateId(),type:"divider",values:{borderColor:u(c(t,"border","borderTopColor"))??"#cccccc",borderWidth:g(c(t,"border","borderTopWidth"),1),borderStyle:e==="dashed"||e==="dotted"?e:"solid",padding:p(t.containerPadding,10),width:s(t.width,"100%")}}}function R(t){return{id:f.generateId(),type:"html",values:{content:s(t.html),padding:p(t.containerPadding,0)}}}function H(t,e){const o=c(t,"menu","items"),n=Array.isArray(o)?o.map(r=>({href:s(c(r,"link","values","href"),"#"),text:s(c(r,"text"))})):[];return{id:f.generateId(),type:"navbar",values:{links:n,hamburger:"none",alignment:y(t.align,"center"),padding:p(t.containerPadding,10),linkColor:u(t.linkColor)??u(t.textColor)??e.textColor??"#000000",linkFontSize:g(t.fontSize,14),linkPadding:s(t.padding,"5px 10px")}}}const E=["facebook","twitter","instagram","linkedin","youtube","tiktok"];function M(t){const e=t.toLowerCase();return e==="x"?"twitter":E.includes(e)?e:"custom"}function j(t){const e=c(t,"icons","icons"),o=Array.isArray(e)?e.map(n=>{const r=s(c(n,"name")),i=M(r),a=s(c(n,"image","url"))||s(c(n,"src"));return{type:i,href:s(c(n,"url"),"#"),...r?{label:r}:{},...i==="custom"&&a?{iconUrl:a}:{}}}):[];return{id:f.generateId(),type:"social",values:{icons:o,iconSize:g(c(t,"icons","iconSize"),32),spacing:g(t.spacing,8),alignment:y(t.align,"center"),padding:p(t.containerPadding,10)}}}const w=600,I="#f4f4f5",F="Arial, Helvetica, sans-serif";function q(t,e={}){var A,C;const o=[],n=_(t,o),r=e.name??"Imported from Unlayer";if(!n)return{document:K(r),warnings:o};const i=((A=n.body)==null?void 0:A.values)??{},a={fontFamily:s(c(i,"fontFamily","value"))||void 0,textColor:u(i.textColor)},d=Array.isArray((C=n.body)==null?void 0:C.rows)?n.body.rows:[];d.length===0&&o.push({code:"no-rows",message:"The design contains no rows; imported an empty template."});const m=d.map(b=>J(b,a,o)).filter(b=>b!==null),l=new Date().toISOString(),h=s(i.preheaderText);return{document:{version:"1.0",metadata:{name:r,...h?{previewText:h}:{},createdAt:l,updatedAt:l},body:{attributes:{width:g(i.contentWidth,w)||w,backgroundColor:u(i.backgroundColor)??I,fontFamily:a.fontFamily??F,contentAlignment:i.contentAlign==="left"?"left":"center"},rows:m}},warnings:o}}function _(t,e){let o=t;if(typeof t=="string")try{o=JSON.parse(t)}catch{return e.push({code:"not-a-design",message:"Input is not valid JSON."}),null}return typeof o!="object"||o===null||!("body"in o)?(e.push({code:"not-a-design",message:"Input does not look like an Unlayer design (no `body` key). Export it with `editor.saveDesign()`."}),null):o}function J(t,e,o){const n=t.values??{},r=Array.isArray(t.columns)?t.columns:[];if(r.length===0)return o.push({code:"empty-row",message:"Skipped a row with no columns."}),null;if(n.displayCondition!=null){const d=s(c(n,"displayCondition","label"));o.push({code:"display-condition-dropped",message:`Display condition${d?` "${d}"`:""} was dropped — Unlayer stores raw template fragments that cannot be translated automatically. Re-add it on the row.`})}const i=r.map(d=>V(d,e,o)),a=s(c(n,"backgroundImage","url"));return{id:f.generateId(),type:"row",attributes:{...u(n.backgroundColor)??u(n.columnsBackgroundColor)?{backgroundColor:u(n.backgroundColor)??u(n.columnsBackgroundColor)}:{},...a?{backgroundImage:a}:{},padding:p(n.padding,0),fullWidth:n.fullWidth===!0||c(n,"backgroundImage","fullWidth")===!0},columns:i,columnRatios:D(t.cells,i.length),locked:n.locked===!0||n.draggable===!1&&n.deletable===!1}}function V(t,e,o){const n=t.values??{},r=Array.isArray(t.contents)?t.contents:[],i=[];for(const d of r){const m=O(d,e,o);if(m){i.push(m);continue}const l=s(d.type,"unknown");l.startsWith("custom#")?o.push({code:"custom-tool",contentType:l,message:`Custom tool "${l.slice(7)}" was dropped — re-create it as a Lit Pigeon plugin block.`}):o.push({code:"unsupported-block",contentType:l,message:`Unsupported Unlayer block "${l}" was dropped.`})}const a=u(n.backgroundColor);return{id:f.generateId(),type:"column",attributes:{...a?{backgroundColor:a}:{},padding:p(n.padding,0),verticalAlign:G(n.verticalAlign)},blocks:i}}function G(t){return t==="middle"||t==="bottom"?t:"top"}function K(t){const e=new Date().toISOString();return{version:"1.0",metadata:{name:t,createdAt:e,updatedAt:e},body:{attributes:{width:w,backgroundColor:I,fontFamily:F,contentAlignment:"center"},rows:[]}}}exports.unlayerToDocument=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@lit-pigeon/core"),P=require("htmlparser2");function p(t,e=0){const n=r=>({top:r,right:r,bottom:r,left:r});if(typeof t!="string"||!t.trim())return n(e);const o=t.trim().split(/\s+/).map(r=>g(r,e));switch(o.length){case 1:return n(o[0]);case 2:return{top:o[0],right:o[1],bottom:o[0],left:o[1]};case 3:return{top:o[0],right:o[1],bottom:o[2],left:o[1]};case 4:return{top:o[0],right:o[1],bottom:o[2],left:o[3]};default:return n(e)}}function g(t,e=0){if(typeof t=="number")return Number.isFinite(t)?t:e;if(typeof t!="string")return e;const n=parseFloat(t);return Number.isNaN(n)?e:n}function i(t,e=""){return typeof t=="string"?t:e}function u(t){const e=i(t).trim();return e||void 0}function W(t){if(typeof t=="number")return Number.isFinite(t)?String(t):void 0;const e=i(t).trim();return e||void 0}function b(t,e="left"){return t==="left"||t==="center"||t==="right"?t:e}function c(t,...e){let n=t;for(const o of e){if(typeof n!="object"||n===null)return;n=n[o]}return n}function L(t,e){if(e<=0)return[];const n=t&&t.length===e&&t.every(s=>s>0)?t:new Array(e).fill(1),o=n.reduce((s,l)=>s+l,0),r=n.map(s=>Math.max(1,Math.round(s*12/o)));let a=12-r.reduce((s,l)=>s+l,0);for(;a!==0;){const s=a>0?r.indexOf(Math.max(...r)):r.indexOf(Math.max(...r.filter(l=>l>1)));if(s===-1)break;r[s]+=a>0?1:-1,a+=a>0?-1:1}return r}const I=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]);function N(t){const e=[];return t.color&&e.push(`color: ${t.color}`),t.fontFamily&&e.push(`font-family: ${t.fontFamily}`),t.fontSize&&e.push(`font-size: ${t.fontSize}`),e.length?e.join("; "):void 0}function B(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function k(t){return Object.entries(t).map(([e,n])=>` ${e}="${B(n)}"`).join("")}function F(t,e){const n=N(e);if(!n)return t;const o=`<span style="${B(n)}">`,r="</span>";let a="",s=0,l=!1;const m=new P.Parser({onopentag(d,h){if(I.has(d)){s===0?a+=`${o}<${d}${k(h)}>${r}`:a+=`<${d}${k(h)}>`;return}a+=`<${d}${k(h)}>`,s===0&&(a+=o,l=!0),s++},ontext(d){if(s===0){a+=d.trim()?`${o}${d}${r}`:d;return}a+=d},onclosetag(d){I.has(d)||(s--,s===0&&l&&(a+=r,l=!1),a+=`</${d}>`)}},{recognizeSelfClosing:!0,lowerCaseTags:!0,lowerCaseAttributeNames:!0});return m.write(t),m.end(),a}function D(t){const e=t.trim();return e?/^<(p|h[1-6]|ul|ol|blockquote|div|table)[\s>]/i.test(e)?e:`<p>${e}</p>`:"<p></p>"}function M(t,e,n){const o=i(t.type),r=t.values??{};switch(o){case"text":return H(r,e);case"heading":return E(r,e,n);case"image":return _(r);case"button":return J(r);case"divider":return G(r);case"html":return K(r);case"menu":return V(r,e);case"social":return Y(r);case"video":return R(r,n);case"timer":return j(r,n);default:return null}}function z(t,e,n,o){return f.getBlockDefinition(t)||o.push({code:"plugin-block",contentType:n,message:`Imported as a "${t}" block from @lit-pigeon/blocks, which is not registered. Install the package and call registerStandardBlocks(), or the block renders as a placeholder.`}),{id:f.generateId(),type:t,values:e}}function R(t,e){const n=i(c(t,"thumbnail","url"))||i(t.thumbnailUrl);return z("video",{posterUrl:n,videoUrl:i(t.videoUrl,"#"),alt:i(t.altText)||"Watch the video",width:g(c(t,"thumbnail","width"),560)||560,playButtonColor:u(t.playIconColor)??"#ffffff"},"video",e)}function j(t,e){return z("countdown",{imageUrl:"",alt:"Countdown",href:i(c(t,"href","values","href")),width:480,endDateLabel:i(t.endTime)},"timer",e)}function H(t,e){const n=F(i(t.text),{fontSize:i(t.fontSize)||void 0,color:u(t.color)??e.textColor,fontFamily:e.fontFamily});return{id:f.generateId(),type:"text",values:{content:D(n),padding:p(t.containerPadding,10),lineHeight:i(t.lineHeight,"140%"),textAlign:b(t.textAlign)}}}function E(t,e,n){const o=i(t.headingType,"h1").toLowerCase();let r=/^h[1-6]$/.test(o)?o:"h1";/^h[4-6]$/.test(r)&&(n.push({code:"heading-level-clamped",message:`Heading level <${r}> is not supported by the editor; imported as <h3>.`}),r="h3");const a=F(i(t.text),{fontSize:i(t.fontSize)||void 0,color:u(t.color)??e.textColor,fontFamily:e.fontFamily});return{id:f.generateId(),type:"text",values:{content:`<${r}>${a}</${r}>`,padding:p(t.containerPadding,10),lineHeight:i(t.lineHeight,"140%"),textAlign:b(t.textAlign)}}}function _(t){const e=i(c(t,"action","values","href")),n=c(t,"src","autoWidth")===!0;return{id:f.generateId(),type:"image",values:{src:i(c(t,"src","url")),alt:i(t.altText),width:n?"auto":g(c(t,"src","width"),0)||"auto",...e?{href:e}:{},padding:p(t.containerPadding,10),alignment:b(t.textAlign,"center")}}}function q(t){const e=g(c(t,"borderTopWidth"),0),n=i(c(t,"borderTopStyle"),"solid");if(!(e<=0||n==="none"||n==="hidden"))return{width:e,style:n==="dashed"||n==="dotted"?n:"solid",color:u(c(t,"borderTopColor"))??"#000000"}}function J(t){const e=q(t.border);return{id:f.generateId(),type:"button",values:{content:D(i(t.text)),href:i(c(t,"href","values","href"),"#"),backgroundColor:u(c(t,"buttonColors","backgroundColor"))??"#3b82f6",textColor:u(c(t,"buttonColors","color"))??"#ffffff",borderRadius:g(t.borderRadius,4),...e?{border:e}:{},padding:p(t.containerPadding,10),innerPadding:p(t.padding,12),fontSize:g(t.fontSize,16),fontWeight:W(t.fontWeight)??"600",alignment:b(t.textAlign,"center"),fullWidth:c(t,"size","autoWidth")===!1}}}function G(t){const e=i(c(t,"border","borderTopStyle"),"solid");return{id:f.generateId(),type:"divider",values:{borderColor:u(c(t,"border","borderTopColor"))??"#cccccc",borderWidth:g(c(t,"border","borderTopWidth"),1),borderStyle:e==="dashed"||e==="dotted"?e:"solid",padding:p(t.containerPadding,10),width:i(t.width,"100%")}}}function K(t){return{id:f.generateId(),type:"html",values:{content:i(t.html),padding:p(t.containerPadding,0)}}}function V(t,e){const n=c(t,"menu","items"),o=Array.isArray(n)?n.map(r=>({href:i(c(r,"link","values","href"),"#"),text:i(c(r,"text"))})):[];return{id:f.generateId(),type:"navbar",values:{links:o,hamburger:"none",alignment:b(t.align,"center"),padding:p(t.containerPadding,10),linkColor:u(t.linkColor)??u(t.textColor)??e.textColor??"#000000",linkFontSize:g(t.fontSize,14),linkPadding:i(t.padding,"5px 10px")}}}const Q=["facebook","twitter","instagram","linkedin","youtube","tiktok"];function X(t){const e=t.toLowerCase();return e==="x"?"twitter":Q.includes(e)?e:"custom"}function Y(t){const e=c(t,"icons","icons"),n=Array.isArray(e)?e.map(o=>{const r=i(c(o,"name")),a=X(r),s=i(c(o,"image","url"))||i(c(o,"src"));return{type:a,href:i(c(o,"url"),"#"),...r?{label:r}:{},...a==="custom"&&s?{iconUrl:s}:{}}}):[];return{id:f.generateId(),type:"social",values:{icons:n,iconSize:g(c(t,"icons","iconSize"),32),spacing:g(t.spacing,8),alignment:b(t.align,"center"),padding:p(t.containerPadding,10)}}}const w=600,O="#f4f4f5",U="Arial, Helvetica, sans-serif";function Z(t,e={}){var $,T;const n=[],o=et(t,n),r=e.name??"Imported from Unlayer";if(!o)return{document:at(r),warnings:n};const a=(($=o.body)==null?void 0:$.values)??{},s={fontFamily:i(c(a,"fontFamily","value"))||void 0,textColor:u(a.textColor)},l=Array.isArray((T=o.body)==null?void 0:T.rows)?o.body.rows:[];l.length===0&&n.push({code:"no-rows",message:"The design contains no rows; imported an empty template."});const m=l.map(y=>ot(y,s,n)).filter(y=>y!==null),d=new Date().toISOString(),h=i(a.preheaderText),x=v(a.linkStyle),{language:A,direction:S}=tt(a,n);return{document:{version:"1.0",metadata:{name:r,...h?{previewText:h}:{},createdAt:d,updatedAt:d},body:{attributes:{width:g(a.contentWidth,w)||w,backgroundColor:u(a.backgroundColor)??O,fontFamily:s.fontFamily??U,contentAlignment:a.contentAlign==="left"?"left":"center",...x?{linkStyle:x}:{},...A?{language:A}:{},...S?{direction:S}:{}},rows:m}},warnings:n}}function v(t){if(typeof t!="object"||t===null||c(t,"inherit")===!0)return;const e=u(c(t,"linkColor")),n=c(t,"linkUnderline"),o={...e?{color:e}:{},...typeof n=="boolean"?{underline:n}:{}};return Object.keys(o).length?o:void 0}function tt(t,e){const n=i(t.language)||void 0,o=i(t.textDirection);return o?o==="ltr"||o==="rtl"?{language:n,direction:o}:(e.push({code:"unknown-text-direction",message:`Unrecognised text direction "${o}"; the document falls back to its language's natural direction.`}),{language:n}):{language:n}}function et(t,e){let n=t;if(typeof t=="string")try{n=JSON.parse(t)}catch{return e.push({code:"not-a-design",message:"Input is not valid JSON."}),null}return typeof n!="object"||n===null||!("body"in n)?(e.push({code:"not-a-design",message:"Input does not look like an Unlayer design (no `body` key). Export it with `editor.saveDesign()`."}),null):n}function nt(t,e){const n=i(c(t,"url"));if(!n)return{};const o=c(t,"repeat");(o==="repeat-x"||o==="repeat-y")&&e.push({code:"background-repeat-clamped",message:`Background image repeats on one axis (${o}), which the row model cannot express — imported as a full repeat. Check the row's background.`});const r=c(t,"customPosition"),a=Array.isArray(r)&&r.length===2?`${i(r[0])} ${i(r[1])}`.trim():c(t,"center")===!0?"center center":void 0,s=i(c(t,"size"));return{backgroundImage:n,backgroundRepeat:o===!1||o==="no-repeat"?"no-repeat":"repeat",...s?{backgroundSize:s}:{},...a?{backgroundPosition:a}:{}}}function ot(t,e,n){const o=t.values??{},r=Array.isArray(t.columns)?t.columns:[];if(r.length===0)return n.push({code:"empty-row",message:"Skipped a row with no columns."}),null;if(o.displayCondition!=null){const l=i(c(o,"displayCondition","label"));n.push({code:"display-condition-dropped",message:`Display condition${l?` "${l}"`:""} was dropped — Unlayer stores raw template fragments that cannot be translated automatically. Re-add it on the row.`})}const a=r.map(l=>rt(l,e,n)),s=nt(o.backgroundImage,n);return{id:f.generateId(),type:"row",attributes:{...C(o),...u(o.backgroundColor)??u(o.columnsBackgroundColor)?{backgroundColor:u(o.backgroundColor)??u(o.columnsBackgroundColor)}:{},...s,padding:p(o.padding,0),fullWidth:o.fullWidth===!0||c(o,"backgroundImage","fullWidth")===!0},columns:a,columnRatios:L(t.cells,a.length),locked:o.locked===!0||o.draggable===!1&&o.deletable===!1}}function rt(t,e,n){const o=t.values??{},r=Array.isArray(t.contents)?t.contents:[],a=[];for(const l of r){const m=M(l,e,n);if(m){Object.assign(m.values,C(l.values??{})),a.push(m);continue}const d=i(l.type,"unknown");d.startsWith("custom#")?n.push({code:"custom-tool",contentType:d,message:`Custom tool "${d.slice(7)}" was dropped — re-create it as a Lit Pigeon plugin block.`}):n.push({code:"unsupported-block",contentType:d,message:`Unsupported Unlayer block "${d}" was dropped.`})}const s=u(o.backgroundColor);return{id:f.generateId(),type:"column",attributes:{...C(o),...s?{backgroundColor:s}:{},padding:p(o.padding,0),verticalAlign:it(o.verticalAlign)},blocks:a}}function C(t){const e={};return t.hideDesktop===!0&&(e.hideOnDesktop=!0),(t.hideMobile===!0||c(t,"_override","mobile","hideMobile")===!0)&&(e.hideOnMobile=!0),e}function it(t){return t==="middle"||t==="bottom"?t:"top"}function at(t){const e=new Date().toISOString();return{version:"1.0",metadata:{name:t,createdAt:e,updatedAt:e},body:{attributes:{width:w,backgroundColor:O,fontFamily:U,contentAlignment:"center"},rows:[]}}}exports.unlayerToDocument=Z;
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare interface ImportWarning {
24
24
  contentType?: string;
25
25
  }
26
26
 
27
- export declare type ImportWarningCode = 'not-a-design' | 'no-rows' | 'unsupported-block' | 'custom-tool' | 'display-condition-dropped' | 'heading-level-clamped' | 'empty-row';
27
+ export declare type ImportWarningCode = 'not-a-design' | 'no-rows' | 'unsupported-block' | 'plugin-block' | 'custom-tool' | 'display-condition-dropped' | 'heading-level-clamped' | 'empty-row' | 'unknown-text-direction' | 'background-repeat-clamped';
28
28
 
29
29
  export declare interface UnlayerBody {
30
30
  id?: string;
package/dist/index.js CHANGED
@@ -1,58 +1,63 @@
1
- import { generateId as f } from "@lit-pigeon/core";
2
- import { Parser as D } from "htmlparser2";
3
- function p(t, e = 0) {
4
- const o = (r) => ({ top: r, right: r, bottom: r, left: r });
5
- if (typeof t != "string" || !t.trim()) return o(e);
6
- const n = t.trim().split(/\s+/).map((r) => g(r, e));
7
- switch (n.length) {
1
+ import { generateId as g, getBlockDefinition as W } from "@lit-pigeon/core";
2
+ import { Parser as P } from "htmlparser2";
3
+ function f(t, e = 0) {
4
+ const n = (r) => ({ top: r, right: r, bottom: r, left: r });
5
+ if (typeof t != "string" || !t.trim()) return n(e);
6
+ const o = t.trim().split(/\s+/).map((r) => p(r, e));
7
+ switch (o.length) {
8
8
  case 1:
9
- return o(n[0]);
9
+ return n(o[0]);
10
10
  case 2:
11
- return { top: n[0], right: n[1], bottom: n[0], left: n[1] };
11
+ return { top: o[0], right: o[1], bottom: o[0], left: o[1] };
12
12
  case 3:
13
- return { top: n[0], right: n[1], bottom: n[2], left: n[1] };
13
+ return { top: o[0], right: o[1], bottom: o[2], left: o[1] };
14
14
  case 4:
15
- return { top: n[0], right: n[1], bottom: n[2], left: n[3] };
15
+ return { top: o[0], right: o[1], bottom: o[2], left: o[3] };
16
16
  default:
17
- return o(e);
17
+ return n(e);
18
18
  }
19
19
  }
20
- function g(t, e = 0) {
20
+ function p(t, e = 0) {
21
21
  if (typeof t == "number") return Number.isFinite(t) ? t : e;
22
22
  if (typeof t != "string") return e;
23
- const o = parseFloat(t);
24
- return Number.isNaN(o) ? e : o;
23
+ const n = parseFloat(t);
24
+ return Number.isNaN(n) ? e : n;
25
25
  }
26
- function a(t, e = "") {
26
+ function i(t, e = "") {
27
27
  return typeof t == "string" ? t : e;
28
28
  }
29
- function d(t) {
30
- const e = a(t).trim();
29
+ function u(t) {
30
+ const e = i(t).trim();
31
+ return e || void 0;
32
+ }
33
+ function L(t) {
34
+ if (typeof t == "number") return Number.isFinite(t) ? String(t) : void 0;
35
+ const e = i(t).trim();
31
36
  return e || void 0;
32
37
  }
33
- function y(t, e = "left") {
38
+ function b(t, e = "left") {
34
39
  return t === "left" || t === "center" || t === "right" ? t : e;
35
40
  }
36
- function c(t, ...e) {
37
- let o = t;
38
- for (const n of e) {
39
- if (typeof o != "object" || o === null) return;
40
- o = o[n];
41
+ function s(t, ...e) {
42
+ let n = t;
43
+ for (const o of e) {
44
+ if (typeof n != "object" || n === null) return;
45
+ n = n[o];
41
46
  }
42
- return o;
47
+ return n;
43
48
  }
44
- function I(t, e) {
49
+ function N(t, e) {
45
50
  if (e <= 0) return [];
46
- const o = t && t.length === e && t.every((s) => s > 0) ? t : new Array(e).fill(1), n = o.reduce((s, u) => s + u, 0), r = o.map((s) => Math.max(1, Math.round(s * 12 / n)));
47
- let i = 12 - r.reduce((s, u) => s + u, 0);
48
- for (; i !== 0; ) {
49
- const s = i > 0 ? r.indexOf(Math.max(...r)) : r.indexOf(Math.max(...r.filter((u) => u > 1)));
50
- if (s === -1) break;
51
- r[s] += i > 0 ? 1 : -1, i += i > 0 ? -1 : 1;
51
+ const n = t && t.length === e && t.every((a) => a > 0) ? t : new Array(e).fill(1), o = n.reduce((a, l) => a + l, 0), r = n.map((a) => Math.max(1, Math.round(a * 12 / o)));
52
+ let c = 12 - r.reduce((a, l) => a + l, 0);
53
+ for (; c !== 0; ) {
54
+ const a = c > 0 ? r.indexOf(Math.max(...r)) : r.indexOf(Math.max(...r.filter((l) => l > 1)));
55
+ if (a === -1) break;
56
+ r[a] += c > 0 ? 1 : -1, c += c > 0 ? -1 : 1;
52
57
  }
53
58
  return r;
54
59
  }
55
- const x = /* @__PURE__ */ new Set([
60
+ const B = /* @__PURE__ */ new Set([
56
61
  "area",
57
62
  "base",
58
63
  "br",
@@ -67,325 +72,406 @@ const x = /* @__PURE__ */ new Set([
67
72
  "track",
68
73
  "wbr"
69
74
  ]);
70
- function P(t) {
75
+ function R(t) {
71
76
  const e = [];
72
77
  return t.color && e.push(`color: ${t.color}`), t.fontFamily && e.push(`font-family: ${t.fontFamily}`), t.fontSize && e.push(`font-size: ${t.fontSize}`), e.length ? e.join("; ") : void 0;
73
78
  }
74
- function S(t) {
79
+ function F(t) {
75
80
  return t.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
76
81
  }
77
82
  function k(t) {
78
- return Object.entries(t).map(([e, o]) => ` ${e}="${S(o)}"`).join("");
79
- }
80
- function $(t, e) {
81
- const o = P(e);
82
- if (!o) return t;
83
- const n = `<span style="${S(o)}">`, r = "</span>";
84
- let i = "", s = 0, u = !1;
85
- const m = new D(
83
+ return Object.entries(t).map(([e, n]) => ` ${e}="${F(n)}"`).join("");
84
+ }
85
+ function z(t, e) {
86
+ const n = R(e);
87
+ if (!n) return t;
88
+ const o = `<span style="${F(n)}">`, r = "</span>";
89
+ let c = "", a = 0, l = !1;
90
+ const m = new P(
86
91
  {
87
- onopentag(l, h) {
88
- if (x.has(l)) {
89
- s === 0 ? i += `${n}<${l}${k(h)}>${r}` : i += `<${l}${k(h)}>`;
92
+ onopentag(d, h) {
93
+ if (B.has(d)) {
94
+ a === 0 ? c += `${o}<${d}${k(h)}>${r}` : c += `<${d}${k(h)}>`;
90
95
  return;
91
96
  }
92
- i += `<${l}${k(h)}>`, s === 0 && (i += n, u = !0), s++;
97
+ c += `<${d}${k(h)}>`, a === 0 && (c += o, l = !0), a++;
93
98
  },
94
- ontext(l) {
95
- if (s === 0) {
96
- i += l.trim() ? `${n}${l}${r}` : l;
99
+ ontext(d) {
100
+ if (a === 0) {
101
+ c += d.trim() ? `${o}${d}${r}` : d;
97
102
  return;
98
103
  }
99
- i += l;
104
+ c += d;
100
105
  },
101
- onclosetag(l) {
102
- x.has(l) || (s--, s === 0 && u && (i += r, u = !1), i += `</${l}>`);
106
+ onclosetag(d) {
107
+ B.has(d) || (a--, a === 0 && l && (c += r, l = !1), c += `</${d}>`);
103
108
  }
104
109
  },
105
110
  { recognizeSelfClosing: !0, lowerCaseTags: !0, lowerCaseAttributeNames: !0 }
106
111
  );
107
- return m.write(t), m.end(), i;
112
+ return m.write(t), m.end(), c;
108
113
  }
109
- function T(t) {
114
+ function D(t) {
110
115
  const e = t.trim();
111
116
  return e ? /^<(p|h[1-6]|ul|ol|blockquote|div|table)[\s>]/i.test(e) ? e : `<p>${e}</p>` : "<p></p>";
112
117
  }
113
- function W(t, e, o) {
114
- const n = a(t.type), r = t.values ?? {};
115
- switch (n) {
118
+ function M(t, e, n) {
119
+ const o = i(t.type), r = t.values ?? {};
120
+ switch (o) {
116
121
  case "text":
117
- return B(r, e);
122
+ return E(r, e);
118
123
  case "heading":
119
- return O(r, e, o);
124
+ return _(r, e, n);
120
125
  case "image":
121
- return N(r);
126
+ return q(r);
122
127
  case "button":
123
- return U(r);
128
+ return G(r);
124
129
  case "divider":
125
- return L(r);
130
+ return K(r);
126
131
  case "html":
127
- return R(r);
132
+ return V(r);
128
133
  case "menu":
129
- return H(r, e);
134
+ return Q(r, e);
130
135
  case "social":
131
- return j(r);
136
+ return Z(r);
137
+ case "video":
138
+ return j(r, n);
139
+ case "timer":
140
+ return H(r, n);
132
141
  default:
133
142
  return null;
134
143
  }
135
144
  }
136
- function B(t, e) {
137
- const o = $(a(t.text), {
138
- fontSize: a(t.fontSize) || void 0,
139
- color: d(t.color) ?? e.textColor,
145
+ function I(t, e, n, o) {
146
+ return W(t) || o.push({
147
+ code: "plugin-block",
148
+ contentType: n,
149
+ message: `Imported as a "${t}" block from @lit-pigeon/blocks, which is not registered. Install the package and call registerStandardBlocks(), or the block renders as a placeholder.`
150
+ }), { id: g(), type: t, values: e };
151
+ }
152
+ function j(t, e) {
153
+ const n = i(s(t, "thumbnail", "url")) || i(t.thumbnailUrl);
154
+ return I("video", {
155
+ posterUrl: n,
156
+ videoUrl: i(t.videoUrl, "#"),
157
+ alt: i(t.altText) || "Watch the video",
158
+ width: p(s(t, "thumbnail", "width"), 560) || 560,
159
+ playButtonColor: u(t.playIconColor) ?? "#ffffff"
160
+ }, "video", e);
161
+ }
162
+ function H(t, e) {
163
+ return I("countdown", {
164
+ imageUrl: "",
165
+ alt: "Countdown",
166
+ href: i(s(t, "href", "values", "href")),
167
+ width: 480,
168
+ endDateLabel: i(t.endTime)
169
+ }, "timer", e);
170
+ }
171
+ function E(t, e) {
172
+ const n = z(i(t.text), {
173
+ fontSize: i(t.fontSize) || void 0,
174
+ color: u(t.color) ?? e.textColor,
140
175
  fontFamily: e.fontFamily
141
176
  });
142
177
  return {
143
- id: f(),
178
+ id: g(),
144
179
  type: "text",
145
180
  values: {
146
- content: T(o),
147
- padding: p(t.containerPadding, 10),
148
- lineHeight: a(t.lineHeight, "140%"),
149
- textAlign: y(t.textAlign)
181
+ content: D(n),
182
+ padding: f(t.containerPadding, 10),
183
+ lineHeight: i(t.lineHeight, "140%"),
184
+ textAlign: b(t.textAlign)
150
185
  }
151
186
  };
152
187
  }
153
- function O(t, e, o) {
154
- const n = a(t.headingType, "h1").toLowerCase();
155
- let r = /^h[1-6]$/.test(n) ? n : "h1";
156
- /^h[4-6]$/.test(r) && (o.push({
188
+ function _(t, e, n) {
189
+ const o = i(t.headingType, "h1").toLowerCase();
190
+ let r = /^h[1-6]$/.test(o) ? o : "h1";
191
+ /^h[4-6]$/.test(r) && (n.push({
157
192
  code: "heading-level-clamped",
158
193
  message: `Heading level <${r}> is not supported by the editor; imported as <h3>.`
159
194
  }), r = "h3");
160
- const i = $(a(t.text), {
161
- fontSize: a(t.fontSize) || void 0,
162
- color: d(t.color) ?? e.textColor,
195
+ const c = z(i(t.text), {
196
+ fontSize: i(t.fontSize) || void 0,
197
+ color: u(t.color) ?? e.textColor,
163
198
  fontFamily: e.fontFamily
164
199
  });
165
200
  return {
166
- id: f(),
201
+ id: g(),
167
202
  type: "text",
168
203
  values: {
169
- content: `<${r}>${i}</${r}>`,
170
- padding: p(t.containerPadding, 10),
171
- lineHeight: a(t.lineHeight, "140%"),
172
- textAlign: y(t.textAlign)
204
+ content: `<${r}>${c}</${r}>`,
205
+ padding: f(t.containerPadding, 10),
206
+ lineHeight: i(t.lineHeight, "140%"),
207
+ textAlign: b(t.textAlign)
173
208
  }
174
209
  };
175
210
  }
176
- function N(t) {
177
- const e = a(c(t, "action", "values", "href")), o = c(t, "src", "autoWidth") === !0;
211
+ function q(t) {
212
+ const e = i(s(t, "action", "values", "href")), n = s(t, "src", "autoWidth") === !0;
178
213
  return {
179
- id: f(),
214
+ id: g(),
180
215
  type: "image",
181
216
  values: {
182
- src: a(c(t, "src", "url")),
183
- alt: a(t.altText),
184
- width: o ? "auto" : g(c(t, "src", "width"), 0) || "auto",
217
+ src: i(s(t, "src", "url")),
218
+ alt: i(t.altText),
219
+ width: n ? "auto" : p(s(t, "src", "width"), 0) || "auto",
185
220
  ...e ? { href: e } : {},
186
- padding: p(t.containerPadding, 10),
187
- alignment: y(t.textAlign, "center")
221
+ padding: f(t.containerPadding, 10),
222
+ alignment: b(t.textAlign, "center")
188
223
  }
189
224
  };
190
225
  }
191
- function U(t) {
226
+ function J(t) {
227
+ const e = p(s(t, "borderTopWidth"), 0), n = i(s(t, "borderTopStyle"), "solid");
228
+ if (!(e <= 0 || n === "none" || n === "hidden"))
229
+ return {
230
+ width: e,
231
+ style: n === "dashed" || n === "dotted" ? n : "solid",
232
+ color: u(s(t, "borderTopColor")) ?? "#000000"
233
+ };
234
+ }
235
+ function G(t) {
236
+ const e = J(t.border);
192
237
  return {
193
- id: f(),
238
+ id: g(),
194
239
  type: "button",
195
240
  values: {
196
- content: T(a(t.text)),
197
- href: a(c(t, "href", "values", "href"), "#"),
198
- backgroundColor: d(c(t, "buttonColors", "backgroundColor")) ?? "#3b82f6",
199
- textColor: d(c(t, "buttonColors", "color")) ?? "#ffffff",
200
- borderRadius: g(t.borderRadius, 4),
201
- padding: p(t.containerPadding, 10),
202
- innerPadding: p(t.padding, 12),
203
- fontSize: g(t.fontSize, 16),
204
- fontWeight: "600",
205
- alignment: y(t.textAlign, "center"),
241
+ content: D(i(t.text)),
242
+ href: i(s(t, "href", "values", "href"), "#"),
243
+ backgroundColor: u(s(t, "buttonColors", "backgroundColor")) ?? "#3b82f6",
244
+ textColor: u(s(t, "buttonColors", "color")) ?? "#ffffff",
245
+ borderRadius: p(t.borderRadius, 4),
246
+ ...e ? { border: e } : {},
247
+ padding: f(t.containerPadding, 10),
248
+ innerPadding: f(t.padding, 12),
249
+ fontSize: p(t.fontSize, 16),
250
+ fontWeight: L(t.fontWeight) ?? "600",
251
+ alignment: b(t.textAlign, "center"),
206
252
  // Unlayer's `size.autoWidth` is the inverse of Pigeon's `fullWidth`.
207
- fullWidth: c(t, "size", "autoWidth") === !1
253
+ fullWidth: s(t, "size", "autoWidth") === !1
208
254
  }
209
255
  };
210
256
  }
211
- function L(t) {
212
- const e = a(c(t, "border", "borderTopStyle"), "solid");
257
+ function K(t) {
258
+ const e = i(s(t, "border", "borderTopStyle"), "solid");
213
259
  return {
214
- id: f(),
260
+ id: g(),
215
261
  type: "divider",
216
262
  values: {
217
- borderColor: d(c(t, "border", "borderTopColor")) ?? "#cccccc",
218
- borderWidth: g(c(t, "border", "borderTopWidth"), 1),
263
+ borderColor: u(s(t, "border", "borderTopColor")) ?? "#cccccc",
264
+ borderWidth: p(s(t, "border", "borderTopWidth"), 1),
219
265
  borderStyle: e === "dashed" || e === "dotted" ? e : "solid",
220
- padding: p(t.containerPadding, 10),
221
- width: a(t.width, "100%")
266
+ padding: f(t.containerPadding, 10),
267
+ width: i(t.width, "100%")
222
268
  }
223
269
  };
224
270
  }
225
- function R(t) {
271
+ function V(t) {
226
272
  return {
227
- id: f(),
273
+ id: g(),
228
274
  type: "html",
229
275
  values: {
230
- content: a(t.html),
231
- padding: p(t.containerPadding, 0)
276
+ content: i(t.html),
277
+ padding: f(t.containerPadding, 0)
232
278
  }
233
279
  };
234
280
  }
235
- function H(t, e) {
236
- const o = c(t, "menu", "items"), n = Array.isArray(o) ? o.map((r) => ({
237
- href: a(c(r, "link", "values", "href"), "#"),
238
- text: a(c(r, "text"))
281
+ function Q(t, e) {
282
+ const n = s(t, "menu", "items"), o = Array.isArray(n) ? n.map((r) => ({
283
+ href: i(s(r, "link", "values", "href"), "#"),
284
+ text: i(s(r, "text"))
239
285
  })) : [];
240
286
  return {
241
- id: f(),
287
+ id: g(),
242
288
  type: "navbar",
243
289
  values: {
244
- links: n,
290
+ links: o,
245
291
  hamburger: "none",
246
- alignment: y(t.align, "center"),
247
- padding: p(t.containerPadding, 10),
248
- linkColor: d(t.linkColor) ?? d(t.textColor) ?? e.textColor ?? "#000000",
249
- linkFontSize: g(t.fontSize, 14),
250
- linkPadding: a(t.padding, "5px 10px")
292
+ alignment: b(t.align, "center"),
293
+ padding: f(t.containerPadding, 10),
294
+ linkColor: u(t.linkColor) ?? u(t.textColor) ?? e.textColor ?? "#000000",
295
+ linkFontSize: p(t.fontSize, 14),
296
+ linkPadding: i(t.padding, "5px 10px")
251
297
  }
252
298
  };
253
299
  }
254
- const E = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
255
- function M(t) {
300
+ const X = ["facebook", "twitter", "instagram", "linkedin", "youtube", "tiktok"];
301
+ function Y(t) {
256
302
  const e = t.toLowerCase();
257
- return e === "x" ? "twitter" : E.includes(e) ? e : "custom";
303
+ return e === "x" ? "twitter" : X.includes(e) ? e : "custom";
258
304
  }
259
- function j(t) {
260
- const e = c(t, "icons", "icons"), o = Array.isArray(e) ? e.map((n) => {
261
- const r = a(c(n, "name")), i = M(r), s = a(c(n, "image", "url")) || a(c(n, "src"));
305
+ function Z(t) {
306
+ const e = s(t, "icons", "icons"), n = Array.isArray(e) ? e.map((o) => {
307
+ const r = i(s(o, "name")), c = Y(r), a = i(s(o, "image", "url")) || i(s(o, "src"));
262
308
  return {
263
- type: i,
264
- href: a(c(n, "url"), "#"),
309
+ type: c,
310
+ href: i(s(o, "url"), "#"),
265
311
  ...r ? { label: r } : {},
266
- ...i === "custom" && s ? { iconUrl: s } : {}
312
+ ...c === "custom" && a ? { iconUrl: a } : {}
267
313
  };
268
314
  }) : [];
269
315
  return {
270
- id: f(),
316
+ id: g(),
271
317
  type: "social",
272
318
  values: {
273
- icons: o,
274
- iconSize: g(c(t, "icons", "iconSize"), 32),
275
- spacing: g(t.spacing, 8),
276
- alignment: y(t.align, "center"),
277
- padding: p(t.containerPadding, 10)
319
+ icons: n,
320
+ iconSize: p(s(t, "icons", "iconSize"), 32),
321
+ spacing: p(t.spacing, 8),
322
+ alignment: b(t.align, "center"),
323
+ padding: f(t.containerPadding, 10)
278
324
  }
279
325
  };
280
326
  }
281
- const w = 600, F = "#f4f4f5", z = "Arial, Helvetica, sans-serif";
282
- function X(t, e = {}) {
283
- var A, C;
284
- const o = [], n = _(t, o), r = e.name ?? "Imported from Unlayer";
285
- if (!n) return { document: G(r), warnings: o };
286
- const i = ((A = n.body) == null ? void 0 : A.values) ?? {}, s = {
287
- fontFamily: a(c(i, "fontFamily", "value")) || void 0,
288
- textColor: d(i.textColor)
289
- }, u = Array.isArray((C = n.body) == null ? void 0 : C.rows) ? n.body.rows : [];
290
- u.length === 0 && o.push({ code: "no-rows", message: "The design contains no rows; imported an empty template." });
291
- const m = u.map((b) => q(b, s, o)).filter((b) => b !== null), l = (/* @__PURE__ */ new Date()).toISOString(), h = a(i.preheaderText);
327
+ const w = 600, U = "#f4f4f5", O = "Arial, Helvetica, sans-serif";
328
+ function lt(t, e = {}) {
329
+ var $, T;
330
+ const n = [], o = et(t, n), r = e.name ?? "Imported from Unlayer";
331
+ if (!o) return { document: ct(r), warnings: n };
332
+ const c = (($ = o.body) == null ? void 0 : $.values) ?? {}, a = {
333
+ fontFamily: i(s(c, "fontFamily", "value")) || void 0,
334
+ textColor: u(c.textColor)
335
+ }, l = Array.isArray((T = o.body) == null ? void 0 : T.rows) ? o.body.rows : [];
336
+ l.length === 0 && n.push({ code: "no-rows", message: "The design contains no rows; imported an empty template." });
337
+ const m = l.map((y) => ot(y, a, n)).filter((y) => y !== null), d = (/* @__PURE__ */ new Date()).toISOString(), h = i(c.preheaderText), x = v(c.linkStyle), { language: A, direction: S } = tt(c, n);
292
338
  return {
293
339
  document: {
294
340
  version: "1.0",
295
341
  metadata: {
296
342
  name: r,
297
343
  ...h ? { previewText: h } : {},
298
- createdAt: l,
299
- updatedAt: l
344
+ createdAt: d,
345
+ updatedAt: d
300
346
  },
301
347
  body: {
302
348
  attributes: {
303
- width: g(i.contentWidth, w) || w,
304
- backgroundColor: d(i.backgroundColor) ?? F,
305
- fontFamily: s.fontFamily ?? z,
306
- contentAlignment: i.contentAlign === "left" ? "left" : "center"
349
+ width: p(c.contentWidth, w) || w,
350
+ backgroundColor: u(c.backgroundColor) ?? U,
351
+ fontFamily: a.fontFamily ?? O,
352
+ contentAlignment: c.contentAlign === "left" ? "left" : "center",
353
+ ...x ? { linkStyle: x } : {},
354
+ ...A ? { language: A } : {},
355
+ ...S ? { direction: S } : {}
307
356
  },
308
357
  rows: m
309
358
  }
310
359
  },
311
- warnings: o
360
+ warnings: n
312
361
  };
313
362
  }
314
- function _(t, e) {
315
- let o = t;
363
+ function v(t) {
364
+ if (typeof t != "object" || t === null || s(t, "inherit") === !0) return;
365
+ const e = u(s(t, "linkColor")), n = s(t, "linkUnderline"), o = {
366
+ ...e ? { color: e } : {},
367
+ ...typeof n == "boolean" ? { underline: n } : {}
368
+ };
369
+ return Object.keys(o).length ? o : void 0;
370
+ }
371
+ function tt(t, e) {
372
+ const n = i(t.language) || void 0, o = i(t.textDirection);
373
+ return o ? o === "ltr" || o === "rtl" ? { language: n, direction: o } : (e.push({
374
+ code: "unknown-text-direction",
375
+ message: `Unrecognised text direction "${o}"; the document falls back to its language's natural direction.`
376
+ }), { language: n }) : { language: n };
377
+ }
378
+ function et(t, e) {
379
+ let n = t;
316
380
  if (typeof t == "string")
317
381
  try {
318
- o = JSON.parse(t);
382
+ n = JSON.parse(t);
319
383
  } catch {
320
384
  return e.push({ code: "not-a-design", message: "Input is not valid JSON." }), null;
321
385
  }
322
- return typeof o != "object" || o === null || !("body" in o) ? (e.push({
386
+ return typeof n != "object" || n === null || !("body" in n) ? (e.push({
323
387
  code: "not-a-design",
324
388
  message: "Input does not look like an Unlayer design (no `body` key). Export it with `editor.saveDesign()`."
325
- }), null) : o;
389
+ }), null) : n;
326
390
  }
327
- function q(t, e, o) {
328
- const n = t.values ?? {}, r = Array.isArray(t.columns) ? t.columns : [];
391
+ function nt(t, e) {
392
+ const n = i(s(t, "url"));
393
+ if (!n) return {};
394
+ const o = s(t, "repeat");
395
+ (o === "repeat-x" || o === "repeat-y") && e.push({
396
+ code: "background-repeat-clamped",
397
+ message: `Background image repeats on one axis (${o}), which the row model cannot express — imported as a full repeat. Check the row's background.`
398
+ });
399
+ const r = s(t, "customPosition"), c = Array.isArray(r) && r.length === 2 ? `${i(r[0])} ${i(r[1])}`.trim() : s(t, "center") === !0 ? "center center" : void 0, a = i(s(t, "size"));
400
+ return {
401
+ backgroundImage: n,
402
+ backgroundRepeat: o === !1 || o === "no-repeat" ? "no-repeat" : "repeat",
403
+ ...a ? { backgroundSize: a } : {},
404
+ ...c ? { backgroundPosition: c } : {}
405
+ };
406
+ }
407
+ function ot(t, e, n) {
408
+ const o = t.values ?? {}, r = Array.isArray(t.columns) ? t.columns : [];
329
409
  if (r.length === 0)
330
- return o.push({ code: "empty-row", message: "Skipped a row with no columns." }), null;
331
- if (n.displayCondition != null) {
332
- const u = a(c(n, "displayCondition", "label"));
333
- o.push({
410
+ return n.push({ code: "empty-row", message: "Skipped a row with no columns." }), null;
411
+ if (o.displayCondition != null) {
412
+ const l = i(s(o, "displayCondition", "label"));
413
+ n.push({
334
414
  code: "display-condition-dropped",
335
- message: `Display condition${u ? ` "${u}"` : ""} was dropped — Unlayer stores raw template fragments that cannot be translated automatically. Re-add it on the row.`
415
+ message: `Display condition${l ? ` "${l}"` : ""} was dropped — Unlayer stores raw template fragments that cannot be translated automatically. Re-add it on the row.`
336
416
  });
337
417
  }
338
- const i = r.map((u) => J(u, e, o)), s = a(c(n, "backgroundImage", "url"));
418
+ const c = r.map((l) => rt(l, e, n)), a = nt(o.backgroundImage, n);
339
419
  return {
340
- id: f(),
420
+ id: g(),
341
421
  type: "row",
342
422
  attributes: {
343
- ...d(n.backgroundColor) ?? d(n.columnsBackgroundColor) ? { backgroundColor: d(n.backgroundColor) ?? d(n.columnsBackgroundColor) } : {},
344
- ...s ? { backgroundImage: s } : {},
345
- padding: p(n.padding, 0),
346
- fullWidth: n.fullWidth === !0 || c(n, "backgroundImage", "fullWidth") === !0
423
+ ...C(o),
424
+ ...u(o.backgroundColor) ?? u(o.columnsBackgroundColor) ? { backgroundColor: u(o.backgroundColor) ?? u(o.columnsBackgroundColor) } : {},
425
+ ...a,
426
+ padding: f(o.padding, 0),
427
+ fullWidth: o.fullWidth === !0 || s(o, "backgroundImage", "fullWidth") === !0
347
428
  },
348
- columns: i,
349
- columnRatios: I(t.cells, i.length),
429
+ columns: c,
430
+ columnRatios: N(t.cells, c.length),
350
431
  // Unlayer expresses "locked" as the absence of interaction flags.
351
- locked: n.locked === !0 || n.draggable === !1 && n.deletable === !1
432
+ locked: o.locked === !0 || o.draggable === !1 && o.deletable === !1
352
433
  };
353
434
  }
354
- function J(t, e, o) {
355
- const n = t.values ?? {}, r = Array.isArray(t.contents) ? t.contents : [], i = [];
356
- for (const u of r) {
357
- const m = W(u, e, o);
435
+ function rt(t, e, n) {
436
+ const o = t.values ?? {}, r = Array.isArray(t.contents) ? t.contents : [], c = [];
437
+ for (const l of r) {
438
+ const m = M(l, e, n);
358
439
  if (m) {
359
- i.push(m);
440
+ Object.assign(m.values, C(l.values ?? {})), c.push(m);
360
441
  continue;
361
442
  }
362
- const l = a(u.type, "unknown");
363
- l.startsWith("custom#") ? o.push({
443
+ const d = i(l.type, "unknown");
444
+ d.startsWith("custom#") ? n.push({
364
445
  code: "custom-tool",
365
- contentType: l,
366
- message: `Custom tool "${l.slice(7)}" was dropped — re-create it as a Lit Pigeon plugin block.`
367
- }) : o.push({
446
+ contentType: d,
447
+ message: `Custom tool "${d.slice(7)}" was dropped — re-create it as a Lit Pigeon plugin block.`
448
+ }) : n.push({
368
449
  code: "unsupported-block",
369
- contentType: l,
370
- message: `Unsupported Unlayer block "${l}" was dropped.`
450
+ contentType: d,
451
+ message: `Unsupported Unlayer block "${d}" was dropped.`
371
452
  });
372
453
  }
373
- const s = d(n.backgroundColor);
454
+ const a = u(o.backgroundColor);
374
455
  return {
375
- id: f(),
456
+ id: g(),
376
457
  type: "column",
377
458
  attributes: {
378
- ...s ? { backgroundColor: s } : {},
379
- padding: p(n.padding, 0),
380
- verticalAlign: V(n.verticalAlign)
459
+ ...C(o),
460
+ ...a ? { backgroundColor: a } : {},
461
+ padding: f(o.padding, 0),
462
+ verticalAlign: it(o.verticalAlign)
381
463
  },
382
- blocks: i
464
+ blocks: c
383
465
  };
384
466
  }
385
- function V(t) {
467
+ function C(t) {
468
+ const e = {};
469
+ return t.hideDesktop === !0 && (e.hideOnDesktop = !0), (t.hideMobile === !0 || s(t, "_override", "mobile", "hideMobile") === !0) && (e.hideOnMobile = !0), e;
470
+ }
471
+ function it(t) {
386
472
  return t === "middle" || t === "bottom" ? t : "top";
387
473
  }
388
- function G(t) {
474
+ function ct(t) {
389
475
  const e = (/* @__PURE__ */ new Date()).toISOString();
390
476
  return {
391
477
  version: "1.0",
@@ -393,8 +479,8 @@ function G(t) {
393
479
  body: {
394
480
  attributes: {
395
481
  width: w,
396
- backgroundColor: F,
397
- fontFamily: z,
482
+ backgroundColor: U,
483
+ fontFamily: O,
398
484
  contentAlignment: "center"
399
485
  },
400
486
  rows: []
@@ -402,5 +488,5 @@ function G(t) {
402
488
  };
403
489
  }
404
490
  export {
405
- X as unlayerToDocument
491
+ lt as unlayerToDocument
406
492
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lit-pigeon/import-unlayer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Unlayer design-JSON to PigeonDocument importer for Lit Pigeon — migrate off Unlayer without rebuilding your templates",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -20,13 +20,13 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "htmlparser2": "^9.1.0",
23
- "@lit-pigeon/core": "^0.3.3"
23
+ "@lit-pigeon/core": "^0.4.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.5.0",
27
27
  "vite": "^6.0.0",
28
28
  "vite-plugin-dts": "^4.0.0",
29
- "vitest": "^3.0.0"
29
+ "vitest": "^4.1.12"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"