@chaibuilder/sdk 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";const B=require("./common-functions-BZmyleS1.cjs"),t=require("lodash-es"),_=require("himalaya"),O=require("@chaibuilder/runtime"),F=require("tailwind-merge"),m="#styles:",J="__ADD_BLOCK_INTERNAL_ROOT",z="@",H="#",V=s=>{if(s=s.replace(m,""),!s)return{baseClasses:"",classes:""};const n=s.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[a,...e]=n;return{baseClasses:a.trim(),classes:e.join(",").trim().replace(/ +(?= )/g,"")}},Y=s=>{const n=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,a=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return n.test(s)||a.test(s)},U=s=>{if(t.isEmpty(s))return s;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,e=s.match(n),i=s.match(a),r=e?e[1]:i?i[1]:null,l=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,p=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return r&&(l.test(r)||p.test(r))?r:s},M=["chai-name","data-chai-name"],K={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},X=(s,n)=>s.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),T=s=>s.map(n=>n.type==="text"?t.get(n,"content",""):t.isEmpty(n.children)?"":T(n.children)).join(""),v=s=>s===null?"":s,W=s=>{const n=t.compact(t.map(s.split(/\s+/),t.trim)),a=t.find(n,p=>/^w-/.test(p)),e=t.find(n,p=>/^h-/.test(p));if(!e||!a)return{height:"",width:""};const i=p=>{if(!p)return;const h=p.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!h)return;if(h[1])return h[1];const o=h[2];return/^\d+(\.\d+)?$/.test(o)?`${Number(o)*4}px`:o==="auto"||t.includes(o,"%")?o:"16px"},r=i(a),l=i(e);return{width:t.includes(r,"px")?r:"16px",height:t.includes(l,"px")?l:"16px"}},q=s=>{if(s.tagName==="svg")return{};const n={},a=K[s.tagName]||{},e=s.attributes;return t.forEach(e,({key:i,value:r})=>{if(!t.includes(M,i))if(a[i]){if(s.tagName==="img"&&i==="src"&&!r.startsWith("http")){const l=t.find(s.attributes,{key:"width"}),p=t.find(s.attributes,{key:"height"});l&&p?r=`https://via.placeholder.com/${l==null?void 0:l.value}x${p==null?void 0:p.value}`:r="https://via.placeholder.com/150x150"}t.set(n,a[i],v(r))}else t.includes(["style","class","srcset"],i)||(t.has(n,"styles_attrs")||(n.styles_attrs={}),t.startsWith(i,"@")&&(i=i.replace("@","x-on:")),n.styles_attrs[`${i}`]=v(r))}),delete n.class,n},Z=(s,n="styles")=>{if(!s.attributes)return{[n]:`${m},`};const a=t.find(s.attributes,{key:"class"});if(a){const e=a.value;return{[n]:`${m},${e}`}}return{[n]:`${m},`}},G=s=>{const n=t.get(s,"attributes",[]),a=n.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),e=n.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),i=n.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),r=n.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),l=n.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content"),p=n.find(o=>o.key==="class"),h=p&&p.value.split(/\s+/).includes("rte");if(i)return{_type:"Dropdown"};if(r)return{_type:"DropdownButton"};if(l)return{_type:"DropdownContent"};if(a||h)return{_type:"Paragraph"};if(e)return{_type:"LightBoxLink"};switch(s.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:s.tagName,_listType:s.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:s.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:s.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:s.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:s.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const o=t.get(s,"children",[]).length>0?"Box":"EmptyBox";return{_type:o,tag:s.tagName,_name:o=="EmptyBox"||s.tagName==="div"?o:t.capitalize(s.tagName)}}}},E=(s,n=null)=>t.flatMapDeep(s,a=>{var I,$,C,S,D,N,L,A,R,j;if(a.type==="comment")return[];let e={_id:B.generateUUID()};if(n&&(e._parent=n.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:n&&X(n.node,n.block)?(t.set(n,"block.content",t.get(a,"content","")),[]):{...e,_type:"Text",content:t.get(a,"content","")};if(t.startsWith(a.tagName,"chai-")){const c=a.attributes,u=t.find(c,{key:"chai-type"}),d=(u==null?void 0:u.value)||t.startCase(a.tagName.replace("chai-","")).replace(/\s+/g,"");e._type=d,t.forEach(c,({key:y,value:P})=>{if(y==="about-this-component"||y==="chai-type"||y==="can-move"||y==="can-delete")return;if(y==="id"){e._id=P;return}let b=v(P);typeof b=="string"&&t.startsWith(b,"#styles:")&&(b=b.replace("#styles:","#styles:,")),e[y]=b});const g=E(a.children,{block:e,node:a});return[e,...g]}const i=t.get(a,"attributes",[]),r=i.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),l=i.find(c=>c.key==="class"),p=l&&l.value.split(/\s+/).includes("rte"),h=i.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),o=i.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),f=i.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),k=i.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content");if(e={...e,...G(a),...q(a),...Z(a)},a.attributes){const c=a.attributes.find(u=>t.includes(M,u.key));c&&(e._name=c.value)}if(r||p)return e.content=_.stringify(a.children),t.has(e,"styles_attrs.data-chai-richtext")&&delete e.styles_attrs["data-chai-richtext"],t.has(e,"styles_attrs.chai-richtext")&&delete e.styles_attrs["chai-richtext"],[e];if(h){const c=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];e={...e,href:((I=i.find(u=>u.key==="href"))==null?void 0:I.value)||"",hrefType:(($=i.find(u=>u.key==="data-vbtype"))==null?void 0:$.value)||"video",autoplay:((C=i.find(u=>u.key==="data-autoplay"))==null?void 0:C.value)==="true"?"true":"false",maxWidth:((D=(S=i.find(u=>u.key==="data-maxwidth"))==null?void 0:S.value)==null?void 0:D.replace("px",""))||"",backdropColor:((N=i.find(u=>u.key==="data-overlay"))==null?void 0:N.value)||"",galleryName:((L=i.find(u=>u.key==="data-gall"))==null?void 0:L.value)||""},t.forEach(c,u=>{t.has(e,`styles_attrs.${u}`)&&delete e.styles_attrs[u]})}if(o&&(delete e.styles_attrs,e.showDropdown=!1),k&&delete e.styles_attrs,f){delete e.styles_attrs;const c=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");e.content=T(c);const u=t.find(a.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],g=>(g==null?void 0:g.tagName)==="svg"));if(u){const d=t.find(u.children||[],g=>(g==null?void 0:g.tagName)==="svg");if(d){e.icon=_.stringify([d]);const{height:g,width:y}=Q(d,"16px","16px");e.iconHeight=g,e.iconWidth=y}}return[e]}if(e._type==="Input"){const c=e.inputType||"text";c==="checkbox"?t.set(e,"_type","Checkbox"):c==="radio"&&t.set(e,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const c=_.stringify([a]);return Y(c)&&(t.set(e,"_type","Video"),t.set(e,"url",U(c)),t.set(e,"styles",`${m},`),t.set(e,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),e.content=c,[e]}else if(a.tagName==="svg"){const c=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:u,width:d}=W(c);if(u&&d)e.styles=`${m}, ${B.cn(`w-${d} h-${u}`,c)}`.trim(),e.height=u==null?void 0:u.replace("px",""),e.width=d==null?void 0:d.replace("px","");else{const g=(A=t.find(a.attributes,{key:"height"}))==null?void 0:A.value,y=(R=t.find(a.attributes,{key:"width"}))==null?void 0:R.value;g&&y?(e.styles=`${m}, ${B.cn(`w-[${y}px] h-[${g}px]`,c)}`.trim(),e.height=g,e.width=y):e.styles=`${m}, ${B.cn("w-full h-full",c)}`.trim()}return a.attributes=t.filter(a.attributes,g=>!t.includes(["style","width","height","class"],g.key)),e.icon=_.stringify([a]),[e]}else if(a.tagName=="option"&&n&&((j=n.block)==null?void 0:j._type)==="Select")return n.block.options.push({label:T(a.children),...q(a)}),[];const x=E(a.children,{block:e,node:a});return[e,...x]}),Q=(s,n,a)=>{var h,o;const e=t.get(s,"attributes",[]),{height:i,width:r}=W(t.get(t.find(e,{key:"class"}),"value",""));if(i&&r)return{height:`[${i}px]`,width:`[${r}px]`};const l=(h=t.find(e,{key:"height"}))==null?void 0:h.value,p=(o=t.find(e,{key:"width"}))==null?void 0:o.value;return{height:l?`[${l}px]`:a,width:p?`[${p}px]`:n}},tt=s=>{s=s.replace(/(\w+)=\\?"(.*?)\\?"/g,(e,i,r)=>{let l=r.replace(/\\"/g,'"');return l=l.replace(/{([^}]+)}/g,p=>p.replace(/"/g,'\\"')),`${i}="${l.replace(/\\"/g,'"')}"`}),s=s.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),s=s.replace(/\$name="[^"]*"/g,"");const n=s.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):s).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},et=(s,n)=>t.find(s,{_id:n}),st=(s,n)=>t.isEmpty(n)?s:t.map(s,a=>{const e=et(n,a._id);return e?{...e,...a}:a}),at=s=>{const n=_.parse(tt(s));return t.isEmpty(s)?[]:t.flatten(E(n))};function nt(s,n,a){const e=t.get(a,"i18nProps",[]);if(t.isEmpty(n)||t.isEmpty(e))return s;const i=t.cloneDeep(s);return t.forEach(t.keys(i),r=>{if(t.includes(e,r)&&!t.isEmpty(n)){const l=t.get(i,r),p=t.get(i,`${r}-${n}`,"");t.isString(l)?i[r]=t.isString(p)&&!t.isEmpty(p.trim())&&p.trimStart()||l:i[r]=t.isEmpty(p)?l:p}}),i}const rt=t.memoize(s=>{const{baseClasses:n,classes:a}=V(s);return F.twMerge(n,a)});function ot(s,n){return t.get(s,`${n}_attrs`,{})}function lt(s,n=!0){const a={};return Object.keys(s).forEach(e=>{if(t.isString(s[e])&&s[e].startsWith(m)){const i=rt(s[e]),r=ot(s,e);a[e]={...!t.isEmpty(i)&&{className:i},...r,...n?{"data-style-prop":e,"data-block-parent":s._id,"data-style-id":`${e}-${s._id}`}:{}}}}),a}const ct=t.memoize(s=>{const n=O.getRegisteredChaiBlock(s),a=t.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,e])=>t.get(e,"runtime",!1)))}),pt=(s,n)=>{if(!t.isArray(s))return s;let a=s,e;return typeof n.limit=="number"&&n.limit>0&&(e=n.limit),e!==void 0&&(a=a.slice(0,e)),a},ut=(s,n)=>{const a=t.cloneDeep(s);return t.forEach(t.keys(a),e=>{if(t.isString(a[e])&&!t.startsWith(e,"_")){let i=a[e];e==="repeaterItems"&&(a.repeaterItemsBinding=i);const r=/\{\{(.*?)\}\}/g,l=i.match(r);l&&l.forEach(p=>{let h=p.slice(2,-2);const o=t.get(n,h,p);i=t.isArray(o)?o:i.replace(p,o)}),a[e]=i}}),a},dt=s=>{const n=t.last(s);return s.map(a=>{const e=Object.keys(a);for(let i=0;i<e.length;i++)if(t.isString(a[e[i]])&&t.startsWith(e[i],"content")){const r=a===n?"":" ";a[e[i]]=`${a[e[i]].trim()}${r}`}return a})},w=(s,n,{index:a,key:e},i)=>{if(t.isString(s)){let r=s;const l=/\{\{(.*?)\}\}/g,p=s.match(l);if(p){const h=i==="image"||i==="mobileImage";p.forEach(o=>{let f=o.slice(2,-2).trim(),k=e.slice(2,-2).trim();a!==-1&&t.startsWith(f,"$index.")?f=`${k}.${a}.${f.slice(7)}`:a!==-1&&t.startsWith(f,"$index")&&(f=`${k}.${a}`);const x=t.get(n,f);x===void 0?r=r.replace(o,""):h&&!t.isArray(x)?r=x:r=t.isArray(x)?x:r.replace(o,x)})}return r}if(t.isArray(s))return s.map(r=>w(r,n,{index:a,key:e},i));if(s&&typeof s=="object"){const r={};return t.forEach(t.keys(s),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?r[l]=w(s[l],n,{index:a,key:e},l):r[l]=s[l]}),r}return s},gt=(s,n,{index:a,key:e})=>{let i=t.cloneDeep(s);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,t.startsWith(i.repeaterItems,`{{${H}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`),!t.isEmpty(i.repeaterItems)&&i.pagination&&(i.repeaterTotalItems=`${i.repeaterItems.replace("}}",`/${i._id}/totalItems}}`)}`)),w(i,n,{index:a,key:e})};exports.COLLECTION_PREFIX=H;exports.REPEATER_PREFIX=z;exports.ROOT_TEMP_KEY=J;exports.STYLES_KEY=m;exports.adjustSpacingInContentBlocks=dt;exports.applyBindingToBlockProps=gt;exports.applyChaiDataBinding=ut;exports.applyLanguage=nt;exports.applyLimit=pt;exports.getBlockRuntimeProps=ct;exports.getBlockTagAttributes=lt;exports.getBlocksFromHTML=at;exports.getSplitChaiClasses=V;exports.mergeBlocksWithExisting=st;
1
+ "use strict";const T=require("./common-functions-BZmyleS1.cjs"),t=require("lodash-es"),_=require("himalaya"),O=require("@chaibuilder/runtime"),F=require("tailwind-merge"),m="#styles:",J="__ADD_BLOCK_INTERNAL_ROOT",z="@",H="#",V=s=>{if(s=s.replace(m,""),!s)return{baseClasses:"",classes:""};const n=s.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[a,...e]=n;return{baseClasses:a.trim(),classes:e.join(",").trim().replace(/ +(?= )/g,"")}},Y=s=>{const n=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,a=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return n.test(s)||a.test(s)},U=s=>{if(t.isEmpty(s))return s;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,e=s.match(n),i=s.match(a),r=e?e[1]:i?i[1]:null,l=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,p=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return r&&(l.test(r)||p.test(r))?r:s},M=["chai-name","data-chai-name"],K={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},X=(s,n)=>s.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),B=s=>s.map(n=>n.type==="text"?t.get(n,"content",""):t.isEmpty(n.children)?"":B(n.children)).join(""),v=s=>s===null?"":s,W=s=>{const n=t.compact(t.map(s.split(/\s+/),t.trim)),a=t.find(n,p=>/^w-/.test(p)),e=t.find(n,p=>/^h-/.test(p));if(!e||!a)return{height:"",width:""};const i=p=>{if(!p)return;const h=p.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!h)return;if(h[1])return h[1];const o=h[2];return/^\d+(\.\d+)?$/.test(o)?`${Number(o)*4}px`:o==="auto"||t.includes(o,"%")?o:"16px"},r=i(a),l=i(e);return{width:t.includes(r,"px")?r:"16px",height:t.includes(l,"px")?l:"16px"}},q=s=>{if(s.tagName==="svg")return{};const n={},a=K[s.tagName]||{},e=s.attributes;return t.forEach(e,({key:i,value:r})=>{if(!t.includes(M,i))if(a[i]){if(s.tagName==="img"&&i==="src"&&!r.startsWith("http")){const l=t.find(s.attributes,{key:"width"}),p=t.find(s.attributes,{key:"height"});l&&p?r=`https://via.placeholder.com/${l==null?void 0:l.value}x${p==null?void 0:p.value}`:r="https://via.placeholder.com/150x150"}t.set(n,a[i],v(r))}else t.includes(["style","class","srcset"],i)||(t.has(n,"styles_attrs")||(n.styles_attrs={}),t.startsWith(i,"@")&&(i=i.replace("@","x-on:")),n.styles_attrs[`${i}`]=v(r))}),delete n.class,n},Z=(s,n="styles")=>{if(!s.attributes)return{[n]:`${m},`};const a=t.find(s.attributes,{key:"class"});if(a){const e=a.value;return{[n]:`${m},${e}`}}return{[n]:`${m},`}},G=s=>{const n=t.get(s,"attributes",[]),a=n.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),e=n.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),i=n.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),r=n.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),l=n.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content"),p=n.find(o=>o.key==="class"),h=p&&p.value.split(/\s+/).includes("rte");if(i)return{_type:"Dropdown"};if(r)return{_type:"DropdownButton"};if(l)return{_type:"DropdownContent"};if(a||h)return{_type:"Paragraph"};if(e)return{_type:"LightBoxLink"};switch(s.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:s.tagName,_listType:s.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:s.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:s.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:s.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:s.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const o=t.get(s,"children",[]).length>0?"Box":"EmptyBox";return{_type:o,tag:s.tagName,_name:o=="EmptyBox"||s.tagName==="div"?o:t.capitalize(s.tagName)}}}},E=(s,n=null)=>t.flatMapDeep(s,a=>{var I,$,C,S,D,N,L,A,R,j;if(a.type==="comment")return[];let e={_id:T.generateUUID()};if(n&&(e._parent=n.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:n&&X(n.node,n.block)?(t.set(n,"block.content",t.get(a,"content","")),[]):{...e,_type:"Text",content:t.get(a,"content","")};if(t.startsWith(a.tagName,"chai-")){const c=a.attributes,u=t.find(c,{key:"chai-type"}),d=(u==null?void 0:u.value)||t.startCase(a.tagName.replace("chai-","")).replace(/\s+/g,"");e._type=d,t.forEach(c,({key:y,value:P})=>{if(y==="about-this-component"||y==="chai-type"||y==="can-move"||y==="can-delete")return;if(y==="id"){e._id=P;return}let b=v(P);typeof b=="string"&&t.startsWith(b,"#styles:")&&(b=b.replace("#styles:","#styles:,")),e[y]=b});const g=E(a.children,{block:e,node:a});return[e,...g]}const i=t.get(a,"attributes",[]),r=i.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),l=i.find(c=>c.key==="class"),p=l&&l.value.split(/\s+/).includes("rte"),h=i.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),o=i.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),f=i.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),k=i.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content");if(e={...e,...G(a),...q(a),...Z(a)},a.attributes){const c=a.attributes.find(u=>t.includes(M,u.key));c&&(e._name=c.value)}if(r||p)return e.content=_.stringify(a.children),t.has(e,"styles_attrs.data-chai-richtext")&&delete e.styles_attrs["data-chai-richtext"],t.has(e,"styles_attrs.chai-richtext")&&delete e.styles_attrs["chai-richtext"],[e];if(h){const c=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];e={...e,href:((I=i.find(u=>u.key==="href"))==null?void 0:I.value)||"",hrefType:(($=i.find(u=>u.key==="data-vbtype"))==null?void 0:$.value)||"video",autoplay:((C=i.find(u=>u.key==="data-autoplay"))==null?void 0:C.value)==="true"?"true":"false",maxWidth:((D=(S=i.find(u=>u.key==="data-maxwidth"))==null?void 0:S.value)==null?void 0:D.replace("px",""))||"",backdropColor:((N=i.find(u=>u.key==="data-overlay"))==null?void 0:N.value)||"",galleryName:((L=i.find(u=>u.key==="data-gall"))==null?void 0:L.value)||""},t.forEach(c,u=>{t.has(e,`styles_attrs.${u}`)&&delete e.styles_attrs[u]})}if(o&&(delete e.styles_attrs,e.showDropdown=!1),k&&delete e.styles_attrs,f){delete e.styles_attrs;const c=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");e.content=B(c);const u=t.find(a.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],g=>(g==null?void 0:g.tagName)==="svg"));if(u){const d=t.find(u.children||[],g=>(g==null?void 0:g.tagName)==="svg");if(d){e.icon=_.stringify([d]);const{height:g,width:y}=Q(d,"16px","16px");e.iconHeight=g,e.iconWidth=y}}return[e]}if(e._type==="Input"){const c=e.inputType||"text";c==="checkbox"?t.set(e,"_type","Checkbox"):c==="radio"&&t.set(e,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const c=_.stringify([a]);return Y(c)&&(t.set(e,"_type","Video"),t.set(e,"url",U(c)),t.set(e,"styles",`${m},`),t.set(e,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),e.content=c,[e]}else if(a.tagName==="svg"){const c=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:u,width:d}=W(c);if(u&&d)e.styles=`${m}, ${T.cn(`w-${d} h-${u}`,c)}`.trim(),e.height=u==null?void 0:u.replace("px",""),e.width=d==null?void 0:d.replace("px","");else{const g=(A=t.find(a.attributes,{key:"height"}))==null?void 0:A.value,y=(R=t.find(a.attributes,{key:"width"}))==null?void 0:R.value;g&&y?(e.styles=`${m}, ${T.cn(`w-[${y}px] h-[${g}px]`,c)}`.trim(),e.height=g,e.width=y):e.styles=`${m}, ${T.cn("w-full h-full",c)}`.trim()}return a.attributes=t.filter(a.attributes,g=>!t.includes(["style","width","height","class"],g.key)),e.icon=_.stringify([a]),[e]}else if(a.tagName=="option"&&n&&((j=n.block)==null?void 0:j._type)==="Select")return n.block.options.push({label:B(a.children),...q(a)}),[];const x=E(a.children,{block:e,node:a});return[e,...x]}),Q=(s,n,a)=>{var h,o;const e=t.get(s,"attributes",[]),{height:i,width:r}=W(t.get(t.find(e,{key:"class"}),"value",""));if(i&&r)return{height:`[${i}px]`,width:`[${r}px]`};const l=(h=t.find(e,{key:"height"}))==null?void 0:h.value,p=(o=t.find(e,{key:"width"}))==null?void 0:o.value;return{height:l?`[${l}px]`:a,width:p?`[${p}px]`:n}},tt=s=>{s=s.replace(/(\w+)=\\?"(.*?)\\?"/g,(e,i,r)=>{let l=r.replace(/\\"/g,'"');return l=l.replace(/{([^}]+)}/g,p=>p.replace(/"/g,'\\"')),`${i}="${l.replace(/\\"/g,'"')}"`}),s=s.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),s=s.replace(/\$name="[^"]*"/g,"");const n=s.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):s).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},et=(s,n)=>t.find(s,{_id:n}),st=(s,n)=>t.isEmpty(n)?s:t.map(s,a=>{const e=et(n,a._id);return e?(e._type==="Icon"&&t.get(a,"icon","").match(/chai-default-svg/)&&delete a.icon,{...e,...a}):a}),at=s=>{const n=_.parse(tt(s));return t.isEmpty(s)?[]:t.flatten(E(n))};function nt(s,n,a){const e=t.get(a,"i18nProps",[]);if(t.isEmpty(n)||t.isEmpty(e))return s;const i=t.cloneDeep(s);return t.forEach(t.keys(i),r=>{if(t.includes(e,r)&&!t.isEmpty(n)){const l=t.get(i,r),p=t.get(i,`${r}-${n}`,"");t.isString(l)?i[r]=t.isString(p)&&!t.isEmpty(p.trim())&&p.trimStart()||l:i[r]=t.isEmpty(p)?l:p}}),i}const rt=t.memoize(s=>{const{baseClasses:n,classes:a}=V(s);return F.twMerge(n,a)});function ot(s,n){return t.get(s,`${n}_attrs`,{})}function lt(s,n=!0){const a={};return Object.keys(s).forEach(e=>{if(t.isString(s[e])&&s[e].startsWith(m)){const i=rt(s[e]),r=ot(s,e);a[e]={...!t.isEmpty(i)&&{className:i},...r,...n?{"data-style-prop":e,"data-block-parent":s._id,"data-style-id":`${e}-${s._id}`}:{}}}}),a}const ct=t.memoize(s=>{const n=O.getRegisteredChaiBlock(s),a=t.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,e])=>t.get(e,"runtime",!1)))}),pt=(s,n)=>{if(!t.isArray(s))return s;let a=s,e;return typeof n.limit=="number"&&n.limit>0&&(e=n.limit),e!==void 0&&(a=a.slice(0,e)),a},ut=(s,n)=>{const a=t.cloneDeep(s);return t.forEach(t.keys(a),e=>{if(t.isString(a[e])&&!t.startsWith(e,"_")){let i=a[e];e==="repeaterItems"&&(a.repeaterItemsBinding=i);const r=/\{\{(.*?)\}\}/g,l=i.match(r);l&&l.forEach(p=>{let h=p.slice(2,-2);const o=t.get(n,h,p);i=t.isArray(o)?o:i.replace(p,o)}),a[e]=i}}),a},dt=s=>{const n=t.last(s);return s.map(a=>{const e=Object.keys(a);for(let i=0;i<e.length;i++)if(t.isString(a[e[i]])&&t.startsWith(e[i],"content")){const r=a===n?"":" ";a[e[i]]=`${a[e[i]].trim()}${r}`}return a})},w=(s,n,{index:a,key:e},i)=>{if(t.isString(s)){let r=s;const l=/\{\{(.*?)\}\}/g,p=s.match(l);if(p){const h=i==="image"||i==="mobileImage";p.forEach(o=>{let f=o.slice(2,-2).trim(),k=e.slice(2,-2).trim();a!==-1&&t.startsWith(f,"$index.")?f=`${k}.${a}.${f.slice(7)}`:a!==-1&&t.startsWith(f,"$index")&&(f=`${k}.${a}`);const x=t.get(n,f);x===void 0?r=r.replace(o,""):h&&!t.isArray(x)?r=x:r=t.isArray(x)?x:r.replace(o,x)})}return r}if(t.isArray(s))return s.map(r=>w(r,n,{index:a,key:e},i));if(s&&typeof s=="object"){const r={};return t.forEach(t.keys(s),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?r[l]=w(s[l],n,{index:a,key:e},l):r[l]=s[l]}),r}return s},gt=(s,n,{index:a,key:e})=>{let i=t.cloneDeep(s);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,t.startsWith(i.repeaterItems,`{{${H}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`),!t.isEmpty(i.repeaterItems)&&i.pagination&&(i.repeaterTotalItems=`${i.repeaterItems.replace("}}",`/${i._id}/totalItems}}`)}`)),w(i,n,{index:a,key:e})};exports.COLLECTION_PREFIX=H;exports.REPEATER_PREFIX=z;exports.ROOT_TEMP_KEY=J;exports.STYLES_KEY=m;exports.adjustSpacingInContentBlocks=dt;exports.applyBindingToBlockProps=gt;exports.applyChaiDataBinding=ut;exports.applyLanguage=nt;exports.applyLimit=pt;exports.getBlockRuntimeProps=ct;exports.getBlockTagAttributes=lt;exports.getBlocksFromHTML=at;exports.getSplitChaiClasses=V;exports.mergeBlocksWithExisting=st;
@@ -1,17 +1,17 @@
1
1
  import { g as nt, c as S } from "./common-functions-BGzDsf1z.js";
2
- import { isEmpty as f, flatten as rt, flatMapDeep as ot, get as d, set as E, startsWith as k, find as m, startCase as lt, forEach as B, includes as v, has as A, filter as Z, some as ct, map as Q, compact as pt, trim as ut, capitalize as dt, memoize as tt, cloneDeep as q, keys as M, isString as $, isArray as C, last as ht } from "lodash-es";
2
+ import { isEmpty as f, flatten as rt, flatMapDeep as ot, get as d, set as E, startsWith as k, find as m, startCase as lt, forEach as $, includes as v, has as A, filter as Z, some as ct, map as Q, compact as pt, trim as ut, capitalize as dt, memoize as tt, cloneDeep as q, keys as M, isString as B, isArray as C, last as ht } from "lodash-es";
3
3
  import { parse as gt, stringify as N } from "himalaya";
4
4
  import { getRegisteredChaiBlock as mt } from "@chaibuilder/runtime";
5
5
  import { twMerge as yt } from "tailwind-merge";
6
6
  const x = "#styles:", St = "__ADD_BLOCK_INTERNAL_ROOT", Rt = "@", bt = "#", et = (e) => {
7
7
  if (e = e.replace(x, ""), !e) return { baseClasses: "", classes: "" };
8
- const a = e.split(/,(?![^\[]*\])/);
9
- if (a.length === 1)
10
- return { baseClasses: "", classes: a[0].trim() };
11
- const [t, ...s] = a;
8
+ const s = e.split(/,(?![^\[]*\])/);
9
+ if (s.length === 1)
10
+ return { baseClasses: "", classes: s[0].trim() };
11
+ const [t, ...a] = s;
12
12
  return {
13
13
  baseClasses: t.trim(),
14
- classes: s.join(",").trim().replace(/ +(?= )/g, "")
14
+ classes: a.join(",").trim().replace(/ +(?= )/g, "")
15
15
  };
16
16
  };
17
17
  import.meta.vitest && describe("getSplitChaiClasses", () => {
@@ -40,20 +40,20 @@ import.meta.vitest && describe("getSplitChaiClasses", () => {
40
40
  classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
41
41
  }
42
42
  };
43
- for (let a in e) {
44
- const t = et(`${x}${a}`);
45
- expect(t).toEqual(e[a]);
43
+ for (let s in e) {
44
+ const t = et(`${x}${s}`);
45
+ expect(t).toEqual(e[s]);
46
46
  }
47
47
  });
48
48
  });
49
49
  const ft = (e) => {
50
- const a = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, t = /(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;
51
- return a.test(e) || t.test(e);
50
+ const s = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, t = /(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;
51
+ return s.test(e) || t.test(e);
52
52
  }, xt = (e) => {
53
53
  if (f(e)) return e;
54
- const a = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, s = e.match(a), n = e.match(t), r = s ? s[1] : n ? n[1] : null, o = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, c = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
54
+ const s = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(s), n = e.match(t), r = a ? a[1] : n ? n[1] : null, o = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, c = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
55
55
  return r && (o.test(r) || c.test(r)) ? r : e;
56
- }, st = ["chai-name", "data-chai-name"], _t = {
56
+ }, at = ["chai-name", "data-chai-name"], _t = {
57
57
  img: { alt: "alt", width: "width", height: "height", src: "image" },
58
58
  video: {
59
59
  src: "url",
@@ -89,12 +89,12 @@ const ft = (e) => {
89
89
  form: {
90
90
  action: "action"
91
91
  }
92
- }, kt = (e, a) => e.children.length === 1 && v(
92
+ }, kt = (e, s) => e.children.length === 1 && v(
93
93
  ["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
94
- a._type
95
- ), R = (e) => e.map((a) => a.type === "text" ? d(a, "content", "") : f(a.children) ? "" : R(a.children)).join(""), H = (e) => e === null ? "" : e, at = (e) => {
96
- const a = pt(Q(e.split(/\s+/), ut)), t = m(a, (c) => /^w-/.test(c)), s = m(a, (c) => /^h-/.test(c));
97
- if (!s || !t) return { height: "", width: "" };
94
+ s._type
95
+ ), R = (e) => e.map((s) => s.type === "text" ? d(s, "content", "") : f(s.children) ? "" : R(s.children)).join(""), H = (e) => e === null ? "" : e, st = (e) => {
96
+ const s = pt(Q(e.split(/\s+/), ut)), t = m(s, (c) => /^w-/.test(c)), a = m(s, (c) => /^h-/.test(c));
97
+ if (!a || !t) return { height: "", width: "" };
98
98
  const n = (c) => {
99
99
  if (!c) return;
100
100
  const g = c.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
@@ -102,38 +102,38 @@ const ft = (e) => {
102
102
  if (g[1]) return g[1];
103
103
  const i = g[2];
104
104
  return /^\d+(\.\d+)?$/.test(i) ? `${Number(i) * 4}px` : i === "auto" || v(i, "%") ? i : "16px";
105
- }, r = n(t), o = n(s);
105
+ }, r = n(t), o = n(a);
106
106
  return {
107
107
  width: v(r, "px") ? r : "16px",
108
108
  height: v(o, "px") ? o : "16px"
109
109
  };
110
110
  }, G = (e) => {
111
111
  if (e.tagName === "svg") return {};
112
- const a = {}, t = _t[e.tagName] || {}, s = e.attributes;
113
- return B(s, ({ key: n, value: r }) => {
114
- if (!v(st, n))
112
+ const s = {}, t = _t[e.tagName] || {}, a = e.attributes;
113
+ return $(a, ({ key: n, value: r }) => {
114
+ if (!v(at, n))
115
115
  if (t[n]) {
116
116
  if (e.tagName === "img" && n === "src" && !r.startsWith("http")) {
117
117
  const o = m(e.attributes, { key: "width" }), c = m(e.attributes, { key: "height" });
118
118
  o && c ? r = `https://via.placeholder.com/${o == null ? void 0 : o.value}x${c == null ? void 0 : c.value}` : r = "https://via.placeholder.com/150x150";
119
119
  }
120
- E(a, t[n], H(r));
121
- } else v(["style", "class", "srcset"], n) || (A(a, "styles_attrs") || (a.styles_attrs = {}), k(n, "@") && (n = n.replace("@", "x-on:")), a.styles_attrs[`${n}`] = H(r));
122
- }), delete a.class, a;
123
- }, vt = (e, a = "styles") => {
124
- if (!e.attributes) return { [a]: `${x},` };
120
+ E(s, t[n], H(r));
121
+ } else v(["style", "class", "srcset"], n) || (A(s, "styles_attrs") || (s.styles_attrs = {}), k(n, "@") && (n = n.replace("@", "x-on:")), s.styles_attrs[`${n}`] = H(r));
122
+ }), delete s.class, s;
123
+ }, vt = (e, s = "styles") => {
124
+ if (!e.attributes) return { [s]: `${x},` };
125
125
  const t = m(e.attributes, { key: "class" });
126
126
  if (t) {
127
- const s = t.value;
128
- return { [a]: `${x},${s}` };
127
+ const a = t.value;
128
+ return { [s]: `${x},${a}` };
129
129
  }
130
- return { [a]: `${x},` };
130
+ return { [s]: `${x},` };
131
131
  }, wt = (e) => {
132
- const a = d(e, "attributes", []), t = a.find((i) => i.key === "data-chai-richtext" || i.key === "chai-richtext"), s = a.find((i) => i.key === "data-chai-lightbox" || i.key === "chai-lightbox"), n = a.find((i) => i.key === "data-chai-dropdown" || i.key === "chai-dropdown"), r = a.find(
132
+ const s = d(e, "attributes", []), t = s.find((i) => i.key === "data-chai-richtext" || i.key === "chai-richtext"), a = s.find((i) => i.key === "data-chai-lightbox" || i.key === "chai-lightbox"), n = s.find((i) => i.key === "data-chai-dropdown" || i.key === "chai-dropdown"), r = s.find(
133
133
  (i) => i.key === "data-chai-dropdown-button" || i.key === "chai-dropdown-button"
134
- ), o = a.find(
134
+ ), o = s.find(
135
135
  (i) => i.key === "data-chai-dropdown-content" || i.key === "chai-dropdown-content"
136
- ), c = a.find((i) => i.key === "class"), g = c && c.value.split(/\s+/).includes("rte");
136
+ ), c = s.find((i) => i.key === "class"), g = c && c.value.split(/\s+/).includes("rte");
137
137
  if (n)
138
138
  return { _type: "Dropdown" };
139
139
  if (r)
@@ -142,7 +142,7 @@ const ft = (e) => {
142
142
  return { _type: "DropdownContent" };
143
143
  if (t || g)
144
144
  return { _type: "Paragraph" };
145
- if (s)
145
+ if (a)
146
146
  return { _type: "LightBoxLink" };
147
147
  switch (e.tagName) {
148
148
  // self closing tags
@@ -230,25 +230,25 @@ const ft = (e) => {
230
230
  };
231
231
  }
232
232
  }
233
- }, j = (e, a = null) => ot(e, (t) => {
233
+ }, j = (e, s = null) => ot(e, (t) => {
234
234
  var P, J, O, z, V, W, F, U, Y, K;
235
235
  if (t.type === "comment") return [];
236
- let s = { _id: nt() };
237
- if (a && (s._parent = a.block._id), t.type === "text")
238
- return f(d(t, "content", "")) ? [] : a && kt(a.node, a.block) ? (E(a, "block.content", d(t, "content", "")), []) : { ...s, _type: "Text", content: d(t, "content", "") };
236
+ let a = { _id: nt() };
237
+ if (s && (a._parent = s.block._id), t.type === "text")
238
+ return f(d(t, "content", "")) ? [] : s && kt(s.node, s.block) ? (E(s, "block.content", d(t, "content", "")), []) : { ...a, _type: "Text", content: d(t, "content", "") };
239
239
  if (k(t.tagName, "chai-")) {
240
240
  const l = t.attributes, p = m(l, { key: "chai-type" }), u = (p == null ? void 0 : p.value) || lt(t.tagName.replace("chai-", "")).replace(/\s+/g, "");
241
- s._type = u, B(l, ({ key: b, value: X }) => {
241
+ a._type = u, $(l, ({ key: b, value: X }) => {
242
242
  if (b === "about-this-component" || b === "chai-type" || b === "can-move" || b === "can-delete") return;
243
243
  if (b === "id") {
244
- s._id = X;
244
+ a._id = X;
245
245
  return;
246
246
  }
247
247
  let I = H(X);
248
- typeof I == "string" && k(I, "#styles:") && (I = I.replace("#styles:", "#styles:,")), s[b] = I;
248
+ typeof I == "string" && k(I, "#styles:") && (I = I.replace("#styles:", "#styles:,")), a[b] = I;
249
249
  });
250
- const h = j(t.children, { block: s, node: t });
251
- return [s, ...h];
250
+ const h = j(t.children, { block: a, node: t });
251
+ return [a, ...h];
252
252
  }
253
253
  const n = d(t, "attributes", []), r = n.find(
254
254
  (l) => l.key === "data-chai-richtext" || l.key === "chai-richtext"
@@ -261,17 +261,17 @@ const ft = (e) => {
261
261
  ), D = n.find(
262
262
  (l) => l.key === "data-chai-dropdown-content" || l.key === "chai-dropdown-content"
263
263
  );
264
- if (s = {
265
- ...s,
264
+ if (a = {
265
+ ...a,
266
266
  ...wt(t),
267
267
  ...G(t),
268
268
  ...vt(t)
269
269
  }, t.attributes) {
270
- const l = t.attributes.find((p) => v(st, p.key));
271
- l && (s._name = l.value);
270
+ const l = t.attributes.find((p) => v(at, p.key));
271
+ l && (a._name = l.value);
272
272
  }
273
273
  if (r || c)
274
- return s.content = N(t.children), A(s, "styles_attrs.data-chai-richtext") && delete s.styles_attrs["data-chai-richtext"], A(s, "styles_attrs.chai-richtext") && delete s.styles_attrs["chai-richtext"], [s];
274
+ return a.content = N(t.children), A(a, "styles_attrs.data-chai-richtext") && delete a.styles_attrs["data-chai-richtext"], A(a, "styles_attrs.chai-richtext") && delete a.styles_attrs["chai-richtext"], [a];
275
275
  if (g) {
276
276
  const l = [
277
277
  "data-chai-lightbox",
@@ -283,22 +283,22 @@ const ft = (e) => {
283
283
  "data-gall",
284
284
  "href"
285
285
  ];
286
- s = {
287
- ...s,
286
+ a = {
287
+ ...a,
288
288
  href: ((P = n.find((p) => p.key === "href")) == null ? void 0 : P.value) || "",
289
289
  hrefType: ((J = n.find((p) => p.key === "data-vbtype")) == null ? void 0 : J.value) || "video",
290
290
  autoplay: ((O = n.find((p) => p.key === "data-autoplay")) == null ? void 0 : O.value) === "true" ? "true" : "false",
291
291
  maxWidth: ((V = (z = n.find((p) => p.key === "data-maxwidth")) == null ? void 0 : z.value) == null ? void 0 : V.replace("px", "")) || "",
292
292
  backdropColor: ((W = n.find((p) => p.key === "data-overlay")) == null ? void 0 : W.value) || "",
293
293
  galleryName: ((F = n.find((p) => p.key === "data-gall")) == null ? void 0 : F.value) || ""
294
- }, B(l, (p) => {
295
- A(s, `styles_attrs.${p}`) && delete s.styles_attrs[p];
294
+ }, $(l, (p) => {
295
+ A(a, `styles_attrs.${p}`) && delete a.styles_attrs[p];
296
296
  });
297
297
  }
298
- if (i && (delete s.styles_attrs, s.showDropdown = !1), D && delete s.styles_attrs, w) {
299
- delete s.styles_attrs;
298
+ if (i && (delete a.styles_attrs, a.showDropdown = !1), D && delete a.styles_attrs, w) {
299
+ delete a.styles_attrs;
300
300
  const l = Z(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
301
- s.content = R(l);
301
+ a.content = R(l);
302
302
  const p = m(
303
303
  t.children || [],
304
304
  (u) => (u == null ? void 0 : u.tagName) === "span" && ct(u.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg")
@@ -306,179 +306,179 @@ const ft = (e) => {
306
306
  if (p) {
307
307
  const u = m(p.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg");
308
308
  if (u) {
309
- s.icon = N([u]);
309
+ a.icon = N([u]);
310
310
  const { height: h, width: b } = Tt(u, "16px", "16px");
311
- s.iconHeight = h, s.iconWidth = b;
311
+ a.iconHeight = h, a.iconWidth = b;
312
312
  }
313
313
  }
314
- return [s];
314
+ return [a];
315
315
  }
316
- if (s._type === "Input") {
317
- const l = s.inputType || "text";
318
- l === "checkbox" ? E(s, "_type", "Checkbox") : l === "radio" && E(s, "_type", "Radio");
316
+ if (a._type === "Input") {
317
+ const l = a.inputType || "text";
318
+ l === "checkbox" ? E(a, "_type", "Checkbox") : l === "radio" && E(a, "_type", "Radio");
319
319
  } else if (t.tagName === "video" || t.tagName === "iframe") {
320
320
  const l = N([t]);
321
- return ft(l) && (E(s, "_type", "Video"), E(s, "url", xt(l)), E(s, "styles", `${x},`), E(s, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), s.content = l, [s];
321
+ return ft(l) && (E(a, "_type", "Video"), E(a, "url", xt(l)), E(a, "styles", `${x},`), E(a, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), a.content = l, [a];
322
322
  } else if (t.tagName === "svg") {
323
- const l = d(m(t.attributes, { key: "class" }), "value", ""), { height: p, width: u } = at(l);
323
+ const l = d(m(t.attributes, { key: "class" }), "value", ""), { height: p, width: u } = st(l);
324
324
  if (p && u)
325
- s.styles = `${x}, ${S(`w-${u} h-${p}`, l)}`.trim(), s.height = p == null ? void 0 : p.replace("px", ""), s.width = u == null ? void 0 : u.replace("px", "");
325
+ a.styles = `${x}, ${S(`w-${u} h-${p}`, l)}`.trim(), a.height = p == null ? void 0 : p.replace("px", ""), a.width = u == null ? void 0 : u.replace("px", "");
326
326
  else {
327
327
  const h = (U = m(t.attributes, { key: "height" })) == null ? void 0 : U.value, b = (Y = m(t.attributes, { key: "width" })) == null ? void 0 : Y.value;
328
- h && b ? (s.styles = `${x}, ${S(`w-[${b}px] h-[${h}px]`, l)}`.trim(), s.height = h, s.width = b) : s.styles = `${x}, ${S("w-full h-full", l)}`.trim();
328
+ h && b ? (a.styles = `${x}, ${S(`w-[${b}px] h-[${h}px]`, l)}`.trim(), a.height = h, a.width = b) : a.styles = `${x}, ${S("w-full h-full", l)}`.trim();
329
329
  }
330
- return t.attributes = Z(t.attributes, (h) => !v(["style", "width", "height", "class"], h.key)), s.icon = N([t]), [s];
331
- } else if (t.tagName == "option" && a && ((K = a.block) == null ? void 0 : K._type) === "Select")
332
- return a.block.options.push({
330
+ return t.attributes = Z(t.attributes, (h) => !v(["style", "width", "height", "class"], h.key)), a.icon = N([t]), [a];
331
+ } else if (t.tagName == "option" && s && ((K = s.block) == null ? void 0 : K._type) === "Select")
332
+ return s.block.options.push({
333
333
  label: R(t.children),
334
334
  ...G(t)
335
335
  }), [];
336
- const T = j(t.children, { block: s, node: t });
337
- return [s, ...T];
338
- }), Tt = (e, a, t) => {
336
+ const T = j(t.children, { block: a, node: t });
337
+ return [a, ...T];
338
+ }), Tt = (e, s, t) => {
339
339
  var g, i;
340
- const s = d(e, "attributes", []), { height: n, width: r } = at(
341
- d(m(s, { key: "class" }), "value", "")
340
+ const a = d(e, "attributes", []), { height: n, width: r } = st(
341
+ d(m(a, { key: "class" }), "value", "")
342
342
  );
343
343
  if (n && r)
344
344
  return {
345
345
  height: `[${n}px]`,
346
346
  width: `[${r}px]`
347
347
  };
348
- const o = (g = m(s, { key: "height" })) == null ? void 0 : g.value, c = (i = m(s, { key: "width" })) == null ? void 0 : i.value;
348
+ const o = (g = m(a, { key: "height" })) == null ? void 0 : g.value, c = (i = m(a, { key: "width" })) == null ? void 0 : i.value;
349
349
  return {
350
350
  height: o ? `[${o}px]` : t,
351
- width: c ? `[${c}px]` : a
351
+ width: c ? `[${c}px]` : s
352
352
  };
353
353
  }, Et = (e) => {
354
- e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (s, n, r) => {
354
+ e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (a, n, r) => {
355
355
  let o = r.replace(/\\"/g, '"');
356
356
  return o = o.replace(/{([^}]+)}/g, (c) => c.replace(/"/g, '\\"')), `${n}="${o.replace(/\\"/g, '"')}"`;
357
357
  }), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
358
- const a = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
359
- return (a && a.length > 0 ? a[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
360
- }, Bt = (e, a) => m(e, { _id: a }), Ht = (e, a) => f(a) ? e : Q(e, (t) => {
361
- const s = Bt(a, t._id);
362
- return s ? { ...s, ...t } : t;
358
+ const s = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
359
+ return (s && s.length > 0 ? s[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
360
+ }, $t = (e, s) => m(e, { _id: s }), Ht = (e, s) => f(s) ? e : Q(e, (t) => {
361
+ const a = $t(s, t._id);
362
+ return a ? (a._type === "Icon" && d(t, "icon", "").match(/chai-default-svg/) && delete t.icon, { ...a, ...t }) : t;
363
363
  }), jt = (e) => {
364
- const a = gt(Et(e));
365
- return f(e) ? [] : rt(j(a));
364
+ const s = gt(Et(e));
365
+ return f(e) ? [] : rt(j(s));
366
366
  };
367
- function qt(e, a, t) {
368
- const s = d(t, "i18nProps", []);
369
- if (f(a) || f(s)) return e;
367
+ function qt(e, s, t) {
368
+ const a = d(t, "i18nProps", []);
369
+ if (f(s) || f(a)) return e;
370
370
  const n = q(e);
371
- return B(M(n), (r) => {
372
- if (v(s, r) && !f(a)) {
373
- const o = d(n, r), c = d(n, `${r}-${a}`, "");
374
- $(o) ? n[r] = $(c) && !f(c.trim()) && c.trimStart() || o : n[r] = f(c) ? o : c;
371
+ return $(M(n), (r) => {
372
+ if (v(a, r) && !f(s)) {
373
+ const o = d(n, r), c = d(n, `${r}-${s}`, "");
374
+ B(o) ? n[r] = B(c) && !f(c.trim()) && c.trimStart() || o : n[r] = f(c) ? o : c;
375
375
  }
376
376
  }), n;
377
377
  }
378
- const $t = tt((e) => {
379
- const { baseClasses: a, classes: t } = et(e);
380
- return yt(a, t);
378
+ const Bt = tt((e) => {
379
+ const { baseClasses: s, classes: t } = et(e);
380
+ return yt(s, t);
381
381
  });
382
- function It(e, a) {
383
- return d(e, `${a}_attrs`, {});
382
+ function It(e, s) {
383
+ return d(e, `${s}_attrs`, {});
384
384
  }
385
- function Mt(e, a = !0) {
385
+ function Mt(e, s = !0) {
386
386
  const t = {};
387
- return Object.keys(e).forEach((s) => {
388
- if ($(e[s]) && e[s].startsWith(x)) {
389
- const n = $t(e[s]), r = It(e, s);
390
- t[s] = {
387
+ return Object.keys(e).forEach((a) => {
388
+ if (B(e[a]) && e[a].startsWith(x)) {
389
+ const n = Bt(e[a]), r = It(e, a);
390
+ t[a] = {
391
391
  ...!f(n) && { className: n },
392
392
  ...r,
393
- ...a ? {
394
- "data-style-prop": s,
393
+ ...s ? {
394
+ "data-style-prop": a,
395
395
  "data-block-parent": e._id,
396
- "data-style-id": `${s}-${e._id}`
396
+ "data-style-id": `${a}-${e._id}`
397
397
  } : {}
398
398
  };
399
399
  }
400
400
  }), t;
401
401
  }
402
402
  const Pt = tt((e) => {
403
- const a = mt(e), t = d(a, "schema.properties", {});
404
- return Object.fromEntries(Object.entries(t).filter(([, s]) => d(s, "runtime", !1)));
405
- }), Jt = (e, a) => {
403
+ const s = mt(e), t = d(s, "schema.properties", {});
404
+ return Object.fromEntries(Object.entries(t).filter(([, a]) => d(a, "runtime", !1)));
405
+ }), Jt = (e, s) => {
406
406
  if (!C(e)) return e;
407
- let t = e, s;
408
- return typeof a.limit == "number" && a.limit > 0 && (s = a.limit), s !== void 0 && (t = t.slice(0, s)), t;
409
- }, Ot = (e, a) => {
407
+ let t = e, a;
408
+ return typeof s.limit == "number" && s.limit > 0 && (a = s.limit), a !== void 0 && (t = t.slice(0, a)), t;
409
+ }, Ot = (e, s) => {
410
410
  const t = q(e);
411
- return B(M(t), (s) => {
412
- if ($(t[s]) && !k(s, "_")) {
413
- let n = t[s];
414
- s === "repeaterItems" && (t.repeaterItemsBinding = n);
411
+ return $(M(t), (a) => {
412
+ if (B(t[a]) && !k(a, "_")) {
413
+ let n = t[a];
414
+ a === "repeaterItems" && (t.repeaterItemsBinding = n);
415
415
  const r = /\{\{(.*?)\}\}/g, o = n.match(r);
416
416
  o && o.forEach((c) => {
417
417
  let g = c.slice(2, -2);
418
- const i = d(a, g, c);
418
+ const i = d(s, g, c);
419
419
  n = C(i) ? i : n.replace(c, i);
420
- }), t[s] = n;
420
+ }), t[a] = n;
421
421
  }
422
422
  }), t;
423
423
  }, _ = (e) => {
424
- const a = ht(e);
424
+ const s = ht(e);
425
425
  return e.map((t) => {
426
- const s = Object.keys(t);
427
- for (let n = 0; n < s.length; n++)
428
- if ($(t[s[n]]) && k(s[n], "content")) {
429
- const r = t === a ? "" : " ";
430
- t[s[n]] = `${t[s[n]].trim()}${r}`;
426
+ const a = Object.keys(t);
427
+ for (let n = 0; n < a.length; n++)
428
+ if (B(t[a[n]]) && k(a[n], "content")) {
429
+ const r = t === s ? "" : " ";
430
+ t[a[n]] = `${t[a[n]].trim()}${r}`;
431
431
  }
432
432
  return t;
433
433
  });
434
434
  };
435
435
  if (import.meta.vitest) {
436
- const { describe: e, it: a, expect: t } = import.meta.vitest;
436
+ const { describe: e, it: s, expect: t } = import.meta.vitest;
437
437
  e("adjustSpacingInContentBlocks", () => {
438
- a("should add space after content fields except for the last block", () => {
438
+ s("should add space after content fields except for the last block", () => {
439
439
  const n = _([
440
440
  { _id: "1", _type: "Text", content: "First" },
441
441
  { _id: "2", _type: "Text", content: "Second" },
442
442
  { _id: "3", _type: "Text", content: "Third" }
443
443
  ]);
444
444
  t(n[0].content).toBe("First "), t(n[1].content).toBe("Second "), t(n[2].content).toBe("Third");
445
- }), a("should trim whitespace from content before adding space", () => {
445
+ }), s("should trim whitespace from content before adding space", () => {
446
446
  const n = _([
447
447
  { _id: "1", _type: "Text", content: " First " },
448
448
  { _id: "2", _type: "Text", content: " Second " }
449
449
  ]);
450
450
  t(n[0].content).toBe("First "), t(n[1].content).toBe("Second");
451
- }), a("should handle multiple content fields in a single block", () => {
451
+ }), s("should handle multiple content fields in a single block", () => {
452
452
  const n = _([
453
453
  { _id: "1", _type: "Text", content: "Main", contentAlt: "Alt" },
454
454
  { _id: "2", _type: "Text", content: "Last", contentSecondary: "Secondary" }
455
455
  ]);
456
456
  t(n[0].content).toBe("Main "), t(n[0].contentAlt).toBe("Alt "), t(n[1].content).toBe("Last"), t(n[1].contentSecondary).toBe("Secondary");
457
- }), a("should only process fields that start with 'content'", () => {
457
+ }), s("should only process fields that start with 'content'", () => {
458
458
  const n = _([
459
459
  { _id: "1", _type: "Text", content: "Text", title: "Title", text: "Text" },
460
460
  { _id: "2", _type: "Text", content: "Last" }
461
461
  ]);
462
462
  t(n[0].content).toBe("Text "), t(n[0].title).toBe("Title"), t(n[0].text).toBe("Text"), t(n[1].content).toBe("Last");
463
- }), a("should handle empty array", () => {
463
+ }), s("should handle empty array", () => {
464
464
  const n = _([]);
465
465
  t(n).toEqual([]);
466
- }), a("should handle single block", () => {
466
+ }), s("should handle single block", () => {
467
467
  const n = _([{ _id: "1", _type: "Text", content: "Only" }]);
468
468
  t(n[0].content).toBe("Only");
469
- }), a("should handle blocks without content fields", () => {
469
+ }), s("should handle blocks without content fields", () => {
470
470
  const n = _([
471
471
  { _id: "1", _type: "Container", title: "Title" },
472
472
  { _id: "2", _type: "Container", name: "Name" }
473
473
  ]);
474
474
  t(n[0].title).toBe("Title"), t(n[1].name).toBe("Name");
475
- }), a("should handle blocks with non-string content fields", () => {
475
+ }), s("should handle blocks with non-string content fields", () => {
476
476
  const n = _([
477
477
  { _id: "1", _type: "Text", content: "Text", contentNum: 123 },
478
478
  { _id: "2", _type: "Text", content: "Last", contentBool: !0 }
479
479
  ]);
480
480
  t(n[0].content).toBe("Text "), t(n[0].contentNum).toBe(123), t(n[1].content).toBe("Last"), t(n[1].contentBool).toBe(!0);
481
- }), a("should handle empty string content", () => {
481
+ }), s("should handle empty string content", () => {
482
482
  const n = _([
483
483
  { _id: "1", _type: "Text", content: "" },
484
484
  { _id: "2", _type: "Text", content: "Last" }
@@ -487,33 +487,33 @@ if (import.meta.vitest) {
487
487
  });
488
488
  });
489
489
  }
490
- const y = (e, a, { index: t, key: s }, n) => {
491
- if ($(e)) {
490
+ const y = (e, s, { index: t, key: a }, n) => {
491
+ if (B(e)) {
492
492
  let r = e;
493
493
  const o = /\{\{(.*?)\}\}/g, c = e.match(o);
494
494
  if (c) {
495
495
  const g = n === "image" || n === "mobileImage";
496
496
  c.forEach((i) => {
497
- let w = i.slice(2, -2).trim(), D = s.slice(2, -2).trim();
497
+ let w = i.slice(2, -2).trim(), D = a.slice(2, -2).trim();
498
498
  t !== -1 && k(w, "$index.") ? w = `${D}.${t}.${w.slice(7)}` : t !== -1 && k(w, "$index") && (w = `${D}.${t}`);
499
- const T = d(a, w);
499
+ const T = d(s, w);
500
500
  T === void 0 ? r = r.replace(i, "") : g && !C(T) ? r = T : r = C(T) ? T : r.replace(i, T);
501
501
  });
502
502
  }
503
503
  return r;
504
504
  }
505
505
  if (C(e))
506
- return e.map((r) => y(r, a, { index: t, key: s }, n));
506
+ return e.map((r) => y(r, s, { index: t, key: a }, n));
507
507
  if (e && typeof e == "object") {
508
508
  const r = {};
509
- return B(M(e), (o) => {
510
- !k(o, "_") && o !== "$repeaterItemsKey" ? r[o] = y(e[o], a, { index: t, key: s }, o) : r[o] = e[o];
509
+ return $(M(e), (o) => {
510
+ !k(o, "_") && o !== "$repeaterItemsKey" ? r[o] = y(e[o], s, { index: t, key: a }, o) : r[o] = e[o];
511
511
  }), r;
512
512
  }
513
513
  return e;
514
- }, L = (e, a, { index: t, key: s }) => {
514
+ }, L = (e, s, { index: t, key: a }) => {
515
515
  let n = q(e);
516
- return n.repeaterItems && (n.$repeaterItemsKey = n.repeaterItems, k(n.repeaterItems, `{{${bt}`) && (n.$repeaterItemsKey = n.repeaterItems = `${n.repeaterItems.replace("}}", `/${n._id}}}`)}`), !f(n.repeaterItems) && n.pagination && (n.repeaterTotalItems = `${n.repeaterItems.replace("}}", `/${n._id}/totalItems}}`)}`)), y(n, a, { index: t, key: s });
516
+ return n.repeaterItems && (n.$repeaterItemsKey = n.repeaterItems, k(n.repeaterItems, `{{${bt}`) && (n.$repeaterItemsKey = n.repeaterItems = `${n.repeaterItems.replace("}}", `/${n._id}}}`)}`), !f(n.repeaterItems) && n.pagination && (n.repeaterTotalItems = `${n.repeaterItems.replace("}}", `/${n._id}/totalItems}}`)}`)), y(n, s, { index: t, key: a });
517
517
  };
518
518
  import.meta.vitest && (describe("applyBindingToValue", () => {
519
519
  it("should handle string values with bindings", () => {
@@ -547,11 +547,11 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
547
547
  const t = y("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
548
548
  expect(t).toBe("Hello ");
549
549
  }), it("should preserve private properties starting with _", () => {
550
- const a = y({
550
+ const s = y({
551
551
  name: "John",
552
552
  _private: "secret"
553
553
  }, {}, { index: -1, key: "" });
554
- expect(a).toEqual({
554
+ expect(s).toEqual({
555
555
  name: "John",
556
556
  _private: "secret"
557
557
  });
@@ -1,5 +1,5 @@
1
1
  import { jsx as o, jsxs as d } from "react/jsx-runtime";
2
- import { u as C, a as k, b as v, c as g } from "./index-0I-fi22L.js";
2
+ import { u as C, a as k, b as v, c as g } from "./index-DdxrsPQZ.js";
3
3
  import "lodash-es";
4
4
  import "clsx";
5
5
  import "tailwind-merge";