@chaibuilder/sdk 3.0.3 → 3.0.4

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 H=require("@chaibuilder/runtime"),t=require("lodash-es"),V=require("tailwind-merge"),x=require("./common-functions-BZmyleS1.cjs"),b=require("himalaya"),y="#styles:",W="__ADD_BLOCK_INTERNAL_ROOT",O="@",S="#",A=e=>{if(e=e.replace(y,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[a,...s]=i;return{baseClasses:a.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function z(e,i,a){const s=t.get(a,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(s))return e;const n=t.cloneDeep(e);return t.forEach(t.keys(n),l=>{if(t.includes(s,l)&&!t.isEmpty(i)){const c=t.get(n,`${l}-${i}`,""),r=t.get(n,l,"");n[l]=t.isString(c)&&c.trim()||r}}),n}const F=t.memoize(e=>{const{baseClasses:i,classes:a}=A(e);return V.twMerge(i,a)});function J(e,i){return t.get(e,`${i}_attrs`,{})}function Y(e,i=!0){const a={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(y)){const n=F(e[s]),l=J(e,s);a[s]={...!t.isEmpty(n)&&{className:n},...l,...i?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),a}const j=t.memoize(e=>{const i=H.getRegisteredChaiBlock(e),a=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,i)=>{if(!t.isArray(e))return e;let a=e,s;return typeof i.limit=="number"&&i.limit>0&&(s=i.limit),s!==void 0&&(a=a.slice(0,s)),a},U=(e,i)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),s=>{if(t.isString(a[s])&&!t.startsWith(s,"_")){let n=a[s];s==="repeaterItems"&&(a.repeaterItemsBinding=n);const l=/\{\{(.*?)\}\}/g,c=n.match(l);c&&c.forEach(r=>{let u=r.slice(2,-2);const g=t.get(i,u,r);n=t.isArray(g)?g:n.replace(r,g)}),a[s]=n}}),a},X=e=>{const i=/(?: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 i.test(e)||a.test(e)},Z=e=>{if(t.isEmpty(e))return e;const i=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(i),n=e.match(a),l=s?s[1]:n?n[1]:null,c=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,r=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return l&&(c.test(l)||r.test(l))?l:e},P=["chai-name","data-chai-name"],G={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"}},Q=(e,i)=>e.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],i._type),_=e=>e.map(i=>i.type==="text"?t.get(i,"content",""):t.isEmpty(i.children)?"":_(i.children)).join(""),L=e=>e===null?"":e,M=e=>{const i=t.compact(t.map(e.split(/\s+/),t.trim)),a=t.find(i,r=>/^w-/.test(r)),s=t.find(i,r=>/^h-/.test(r));if(!s||!a)return{height:"",width:""};const n=r=>{if(!r)return;const u=r.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!u)return;if(u[1])return u[1];const g=u[2];return/^\d+(\.\d+)?$/.test(g)?`${Number(g)*4}px`:g==="auto"||t.includes(g,"%")?g:"16px"},l=n(a),c=n(s);return{width:t.includes(l,"px")?l:"16px",height:t.includes(c,"px")?c:"16px"}},R=e=>{if(e.tagName==="svg")return{};const i={},a=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:n,value:l})=>{if(!t.includes(P,n))if(a[n]){if(e.tagName==="img"&&n==="src"&&!l.startsWith("http")){const c=t.find(e.attributes,{key:"width"}),r=t.find(e.attributes,{key:"height"});c&&r?l=`https://via.placeholder.com/${c==null?void 0:c.value}x${r==null?void 0:r.value}`:l="https://via.placeholder.com/150x150"}t.set(i,a[n],L(l))}else t.includes(["style","class","srcset"],n)||(t.has(i,"styles_attrs")||(i.styles_attrs={}),t.startsWith(n,"@")&&(n=n.replace("@","x-on:")),i.styles_attrs[`${n}`]=L(l))}),delete i.class,i},ee=(e,i="styles")=>{if(!e.attributes)return{[i]:`${y},`};const a=t.find(e.attributes,{key:"class"});if(a){const s=a.value;return{[i]:`${y},${s}`}}return{[i]:`${y},`}},te=e=>{const i=t.get(e,"attributes",[]),a=i.find(r=>r.key==="data-chai-richtext"||r.key==="chai-richtext"),s=i.find(r=>r.key==="data-chai-lightbox"||r.key==="chai-lightbox"),n=i.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),l=i.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),c=i.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(n)return{_type:"Dropdown"};if(l)return{_type:"DropdownButton"};if(c)return{_type:"DropdownContent"};if(a)return{_type:"RichText"};if(s)return{_type:"LightBoxLink"};switch(e.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:e.tagName,_listType:e.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:e.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:e.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:e.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:e.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const r=t.get(e,"children",[]).length>0?"Box":"EmptyBox";return{_type:r,tag:e.tagName,_name:r=="EmptyBox"||e.tagName==="div"?r:t.capitalize(e.tagName)}}}},q=(e,i=null)=>t.flatMapDeep(e,a=>{var w,E,v,T,$,B,C,I,N,D;if(a.type==="comment")return[];let s={_id:x.generateUUID()};if(i&&(s._parent=i.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:i&&Q(i.node,i.block)?(t.set(i,"block.content",t.get(a,"content","")),[]):{...s,_type:"Text",content:t.get(a,"content","")};const n=t.get(a,"attributes",[]),l=n.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),c=n.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),r=n.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),u=n.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),g=n.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content");if(s={...s,...te(a),...R(a),...ee(a)},a.attributes){const o=a.attributes.find(p=>t.includes(P,p.key));o&&(s._name=o.value)}if(l)return s.content=b.stringify(a.children),t.has(s,"styles_attrs.data-chai-richtext")&&delete s.styles_attrs["data-chai-richtext"],t.has(s,"styles_attrs.chai-richtext")&&delete s.styles_attrs["chai-richtext"],[s];if(c){const o=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];s={...s,href:((w=n.find(p=>p.key==="href"))==null?void 0:w.value)||"",hrefType:((E=n.find(p=>p.key==="data-vbtype"))==null?void 0:E.value)||"video",autoplay:((v=n.find(p=>p.key==="data-autoplay"))==null?void 0:v.value)==="true"?"true":"false",maxWidth:(($=(T=n.find(p=>p.key==="data-maxwidth"))==null?void 0:T.value)==null?void 0:$.replace("px",""))||"",backdropColor:((B=n.find(p=>p.key==="data-overlay"))==null?void 0:B.value)||"",galleryName:((C=n.find(p=>p.key==="data-gall"))==null?void 0:C.value)||""},t.forEach(o,p=>{t.has(s,`styles_attrs.${p}`)&&delete s.styles_attrs[p]})}if(r&&(delete s.styles_attrs,s.showDropdown=!1),g&&delete s.styles_attrs,u){delete s.styles_attrs;const o=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");s.content=_(o);const p=t.find(a.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],h=>(h==null?void 0:h.tagName)==="svg"));if(p){const d=t.find(p.children||[],h=>(h==null?void 0:h.tagName)==="svg");if(d){s.icon=b.stringify([d]);const{height:h,width:f}=se(d,"16px","16px");s.iconHeight=h,s.iconWidth=f}}return[s]}if(s._type==="Input"){const o=s.inputType||"text";o==="checkbox"?t.set(s,"_type","Checkbox"):o==="radio"&&t.set(s,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const o=b.stringify([a]);return X(o)&&(t.set(s,"_type","Video"),t.set(s,"url",Z(o)),t.set(s,"styles",`${y},`),t.set(s,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),s.content=o,[s]}else if(a.tagName==="svg"){const o=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:p,width:d}=M(o);if(p&&d)s.styles=`${y}, ${x.cn(`w-${d} h-${p}`,o)}`.trim(),s.height=p==null?void 0:p.replace("px",""),s.width=d==null?void 0:d.replace("px","");else{const h=(I=t.find(a.attributes,{key:"height"}))==null?void 0:I.value,f=(N=t.find(a.attributes,{key:"width"}))==null?void 0:N.value;h&&f?(s.styles=`${y}, ${x.cn(`w-[${f}px] h-[${h}px]`,o)}`.trim(),s.height=h,s.width=f):s.styles=`${y}, ${x.cn("w-full h-full",o)}`.trim()}return a.attributes=t.filter(a.attributes,h=>!t.includes(["style","width","height","class"],h.key)),s.icon=b.stringify([a]),[s]}else if(a.tagName=="option"&&i&&((D=i.block)==null?void 0:D._type)==="Select")return i.block.options.push({label:_(a.children),...R(a)}),[];const m=q(a.children,{block:s,node:a});return[s,...m]}),se=(e,i,a)=>{var u,g;const s=t.get(e,"attributes",[]),{height:n,width:l}=M(t.get(t.find(s,{key:"class"}),"value",""));if(n&&l)return{height:`[${n}px]`,width:`[${l}px]`};const c=(u=t.find(s,{key:"height"}))==null?void 0:u.value,r=(g=t.find(s,{key:"width"}))==null?void 0:g.value;return{height:c?`[${c}px]`:a,width:r?`[${r}px]`:i}},ae=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,n,l)=>{let c=l.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${n}="${c.replace(/\\"/g,'"')}"`}),e=e.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),e=e.replace(/\$name="[^"]*"/g,"");const i=e.match(/<body[^>]*>[\s\S]*?<\/body>/);return(i&&i.length>0?i[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):e).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},ie=e=>{const i=b.parse(ae(e));return t.isEmpty(e)?[]:t.flatten(q(i))},k=(e,i,{index:a,key:s})=>{if(t.isString(e)){let n=e;const l=/\{\{(.*?)\}\}/g,c=e.match(l);return c&&c.forEach(r=>{let u=r.slice(2,-2).trim(),g=s.slice(2,-2).trim();a!==-1&&t.startsWith(u,"$index.")?u=`${g}.${a}.${u.slice(7)}`:a!==-1&&t.startsWith(u,"$index")&&(u=`${g}.${a}`);const m=t.get(i,u,r);n=t.isArray(m)?m:n.replace(r,m)}),n}if(t.isArray(e))return e.map(n=>k(n,i,{index:a,key:s}));if(e&&typeof e=="object"){const n={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?n[l]=k(e[l],i,{index:a,key:s}):n[l]=e[l]}),n}return e},ne=(e,i,{index:a,key:s})=>{let n=t.cloneDeep(e);return n.repeaterItems&&(n.$repeaterItemsKey=n.repeaterItems,t.startsWith(n.repeaterItems,`{{${S}`)&&(n.$repeaterItemsKey=n.repeaterItems=`${n.repeaterItems.replace("}}",`/${n._id}}}`)}`)),k(n,i,{index:a,key:s})};exports.COLLECTION_PREFIX=S;exports.REPEATER_PREFIX=O;exports.ROOT_TEMP_KEY=W;exports.STYLES_KEY=y;exports.applyBindingToBlockProps=ne;exports.applyChaiDataBinding=U;exports.applyLanguage=z;exports.applyLimit=K;exports.getBlockRuntimeProps=j;exports.getBlockTagAttributes=Y;exports.getBlocksFromHTML=ie;exports.getSplitChaiClasses=A;
1
+ "use strict";const q=require("@chaibuilder/runtime"),t=require("lodash-es"),V=require("tailwind-merge"),x=require("./common-functions-BZmyleS1.cjs"),b=require("himalaya"),y="#styles:",W="__ADD_BLOCK_INTERNAL_ROOT",O="@",S="#",A=e=>{if(e=e.replace(y,""),!e)return{baseClasses:"",classes:""};const n=e.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[a,...s]=n;return{baseClasses:a.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function z(e,n,a){const s=t.get(a,"i18nProps",[]);if(t.isEmpty(n)||t.isEmpty(s))return e;const i=t.cloneDeep(e);return t.forEach(t.keys(i),l=>{if(t.includes(s,l)&&!t.isEmpty(n)){const c=t.get(i,`${l}-${n}`,""),r=t.get(i,l,"");i[l]=t.isString(c)&&c.trim()||r}}),i}const F=t.memoize(e=>{const{baseClasses:n,classes:a}=A(e);return V.twMerge(n,a)});function J(e,n){return t.get(e,`${n}_attrs`,{})}function Y(e,n=!0){const a={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(y)){const i=F(e[s]),l=J(e,s);a[s]={...!t.isEmpty(i)&&{className:i},...l,...n?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),a}const j=t.memoize(e=>{const n=q.getRegisteredChaiBlock(e),a=t.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,n)=>{if(!t.isArray(e))return e;let a=e,s;return typeof n.limit=="number"&&n.limit>0&&(s=n.limit),s!==void 0&&(a=a.slice(0,s)),a},U=(e,n)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),s=>{if(t.isString(a[s])&&!t.startsWith(s,"_")){let i=a[s];s==="repeaterItems"&&(a.repeaterItemsBinding=i);const l=/\{\{(.*?)\}\}/g,c=i.match(l);c&&c.forEach(r=>{let u=r.slice(2,-2);const g=t.get(n,u,r);i=t.isArray(g)?g:i.replace(r,g)}),a[s]=i}}),a},X=e=>{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(e)||a.test(e)},Z=e=>{if(t.isEmpty(e))return e;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(n),i=e.match(a),l=s?s[1]:i?i[1]:null,c=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,r=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return l&&(c.test(l)||r.test(l))?l:e},P=["chai-name","data-chai-name"],G={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"}},Q=(e,n)=>e.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),_=e=>e.map(n=>n.type==="text"?t.get(n,"content",""):t.isEmpty(n.children)?"":_(n.children)).join(""),L=e=>e===null?"":e,H=e=>{const n=t.compact(t.map(e.split(/\s+/),t.trim)),a=t.find(n,r=>/^w-/.test(r)),s=t.find(n,r=>/^h-/.test(r));if(!s||!a)return{height:"",width:""};const i=r=>{if(!r)return;const u=r.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!u)return;if(u[1])return u[1];const g=u[2];return/^\d+(\.\d+)?$/.test(g)?`${Number(g)*4}px`:g==="auto"||t.includes(g,"%")?g:"16px"},l=i(a),c=i(s);return{width:t.includes(l,"px")?l:"16px",height:t.includes(c,"px")?c:"16px"}},R=e=>{if(e.tagName==="svg")return{};const n={},a=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:i,value:l})=>{if(!t.includes(P,i))if(a[i]){if(e.tagName==="img"&&i==="src"&&!l.startsWith("http")){const c=t.find(e.attributes,{key:"width"}),r=t.find(e.attributes,{key:"height"});c&&r?l=`https://via.placeholder.com/${c==null?void 0:c.value}x${r==null?void 0:r.value}`:l="https://via.placeholder.com/150x150"}t.set(n,a[i],L(l))}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}`]=L(l))}),delete n.class,n},ee=(e,n="styles")=>{if(!e.attributes)return{[n]:`${y},`};const a=t.find(e.attributes,{key:"class"});if(a){const s=a.value;return{[n]:`${y},${s}`}}return{[n]:`${y},`}},te=e=>{const n=t.get(e,"attributes",[]),a=n.find(r=>r.key==="data-chai-richtext"||r.key==="chai-richtext"),s=n.find(r=>r.key==="data-chai-lightbox"||r.key==="chai-lightbox"),i=n.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),l=n.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),c=n.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(i)return{_type:"Dropdown"};if(l)return{_type:"DropdownButton"};if(c)return{_type:"DropdownContent"};if(a)return{_type:"RichText"};if(s)return{_type:"LightBoxLink"};switch(e.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:e.tagName,_listType:e.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:e.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:e.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:e.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:e.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const r=t.get(e,"children",[]).length>0?"Box":"EmptyBox";return{_type:r,tag:e.tagName,_name:r=="EmptyBox"||e.tagName==="div"?r:t.capitalize(e.tagName)}}}},M=(e,n=null)=>t.flatMapDeep(e,a=>{var E,w,v,T,$,B,C,I,D,N;if(a.type==="comment")return[];let s={_id:x.generateUUID()};if(n&&(s._parent=n.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:n&&Q(n.node,n.block)?(t.set(n,"block.content",t.get(a,"content","")),[]):{...s,_type:"Text",content:t.get(a,"content","")};const i=t.get(a,"attributes",[]),l=i.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),c=i.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),r=i.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),u=i.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),g=i.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content");if(s={...s,...te(a),...R(a),...ee(a)},a.attributes){const o=a.attributes.find(p=>t.includes(P,p.key));o&&(s._name=o.value)}if(l)return s.content=b.stringify(a.children),t.has(s,"styles_attrs.data-chai-richtext")&&delete s.styles_attrs["data-chai-richtext"],t.has(s,"styles_attrs.chai-richtext")&&delete s.styles_attrs["chai-richtext"],[s];if(c){const o=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];s={...s,href:((E=i.find(p=>p.key==="href"))==null?void 0:E.value)||"",hrefType:((w=i.find(p=>p.key==="data-vbtype"))==null?void 0:w.value)||"video",autoplay:((v=i.find(p=>p.key==="data-autoplay"))==null?void 0:v.value)==="true"?"true":"false",maxWidth:(($=(T=i.find(p=>p.key==="data-maxwidth"))==null?void 0:T.value)==null?void 0:$.replace("px",""))||"",backdropColor:((B=i.find(p=>p.key==="data-overlay"))==null?void 0:B.value)||"",galleryName:((C=i.find(p=>p.key==="data-gall"))==null?void 0:C.value)||""},t.forEach(o,p=>{t.has(s,`styles_attrs.${p}`)&&delete s.styles_attrs[p]})}if(r&&(delete s.styles_attrs,s.showDropdown=!1),g&&delete s.styles_attrs,u){delete s.styles_attrs;const o=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");s.content=_(o);const p=t.find(a.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],h=>(h==null?void 0:h.tagName)==="svg"));if(p){const d=t.find(p.children||[],h=>(h==null?void 0:h.tagName)==="svg");if(d){s.icon=b.stringify([d]);const{height:h,width:f}=se(d,"16px","16px");s.iconHeight=h,s.iconWidth=f}}return[s]}if(s._type==="Input"){const o=s.inputType||"text";o==="checkbox"?t.set(s,"_type","Checkbox"):o==="radio"&&t.set(s,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const o=b.stringify([a]);return X(o)&&(t.set(s,"_type","Video"),t.set(s,"url",Z(o)),t.set(s,"styles",`${y},`),t.set(s,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),s.content=o,[s]}else if(a.tagName==="svg"){const o=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:p,width:d}=H(o);if(p&&d)s.styles=`${y}, ${x.cn(`w-${d} h-${p}`,o)}`.trim(),s.height=p==null?void 0:p.replace("px",""),s.width=d==null?void 0:d.replace("px","");else{const h=(I=t.find(a.attributes,{key:"height"}))==null?void 0:I.value,f=(D=t.find(a.attributes,{key:"width"}))==null?void 0:D.value;h&&f?(s.styles=`${y}, ${x.cn(`w-[${f}px] h-[${h}px]`,o)}`.trim(),s.height=h,s.width=f):s.styles=`${y}, ${x.cn("w-full h-full",o)}`.trim()}return a.attributes=t.filter(a.attributes,h=>!t.includes(["style","width","height","class"],h.key)),s.icon=b.stringify([a]),[s]}else if(a.tagName=="option"&&n&&((N=n.block)==null?void 0:N._type)==="Select")return n.block.options.push({label:_(a.children),...R(a)}),[];const m=M(a.children,{block:s,node:a});return[s,...m]}),se=(e,n,a)=>{var u,g;const s=t.get(e,"attributes",[]),{height:i,width:l}=H(t.get(t.find(s,{key:"class"}),"value",""));if(i&&l)return{height:`[${i}px]`,width:`[${l}px]`};const c=(u=t.find(s,{key:"height"}))==null?void 0:u.value,r=(g=t.find(s,{key:"width"}))==null?void 0:g.value;return{height:c?`[${c}px]`:a,width:r?`[${r}px]`:n}},ae=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,i,l)=>{let c=l.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${i}="${c.replace(/\\"/g,'"')}"`}),e=e.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),e=e.replace(/\$name="[^"]*"/g,"");const n=e.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):e).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},ne=e=>{const n=b.parse(ae(e));return t.isEmpty(e)?[]:t.flatten(M(n))},k=(e,n,{index:a,key:s})=>{if(t.isString(e)){let i=e;const l=/\{\{(.*?)\}\}/g,c=e.match(l);return c&&c.forEach(r=>{let u=r.slice(2,-2).trim(),g=s.slice(2,-2).trim();a!==-1&&t.startsWith(u,"$index.")?u=`${g}.${a}.${u.slice(7)}`:a!==-1&&t.startsWith(u,"$index")&&(u=`${g}.${a}`);const m=t.get(n,u);m===void 0?i=i.replace(r,""):i=t.isArray(m)?m:i.replace(r,m)}),i}if(t.isArray(e))return e.map(i=>k(i,n,{index:a,key:s}));if(e&&typeof e=="object"){const i={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?i[l]=k(e[l],n,{index:a,key:s}):i[l]=e[l]}),i}return e},ie=(e,n,{index:a,key:s})=>{let i=t.cloneDeep(e);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,t.startsWith(i.repeaterItems,`{{${S}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`)),k(i,n,{index:a,key:s})};exports.COLLECTION_PREFIX=S;exports.REPEATER_PREFIX=O;exports.ROOT_TEMP_KEY=W;exports.STYLES_KEY=y;exports.applyBindingToBlockProps=ie;exports.applyChaiDataBinding=U;exports.applyLanguage=z;exports.applyLimit=K;exports.getBlockRuntimeProps=j;exports.getBlockTagAttributes=Y;exports.getBlocksFromHTML=ne;exports.getSplitChaiClasses=A;
@@ -1,17 +1,17 @@
1
1
  import { getRegisteredChaiBlock as G } from "@chaibuilder/runtime";
2
- import { memoize as U, get as d, cloneDeep as L, forEach as $, keys as R, isString as N, startsWith as k, isArray as C, isEmpty as _, includes as f, flatten as Q, flatMapDeep as ee, set as x, has as I, filter as J, find as y, some as te, compact as se, map as ae, trim as re, capitalize as ne } from "lodash-es";
2
+ import { memoize as U, get as d, cloneDeep as L, forEach as $, keys as R, isString as N, startsWith as v, isArray as C, isEmpty as _, includes as f, flatten as Q, flatMapDeep as ee, set as x, has as I, filter as W, find as y, some as te, compact as ae, map as se, trim as re, capitalize as ne } from "lodash-es";
3
3
  import { twMerge as ie } from "tailwind-merge";
4
4
  import { g as oe, c as B } from "./common-functions-BGzDsf1z.js";
5
- import { parse as ce, stringify as T } from "himalaya";
6
- const m = "#styles:", Te = "__ADD_BLOCK_INTERNAL_ROOT", Ee = "@", le = "#", Y = (e) => {
7
- if (e = e.replace(m, ""), !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;
5
+ import { parse as ce, stringify as E } from "himalaya";
6
+ const b = "#styles:", Ee = "__ADD_BLOCK_INTERNAL_ROOT", Te = "@", le = "#", Y = (e) => {
7
+ if (e = e.replace(b, ""), !e) return { baseClasses: "", classes: "" };
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,74 +40,74 @@ 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 = Y(`${m}${a}`);
45
- expect(t).toEqual(e[a]);
43
+ for (let s in e) {
44
+ const t = Y(`${b}${s}`);
45
+ expect(t).toEqual(e[s]);
46
46
  }
47
47
  });
48
48
  });
49
- function Ie(e, a, t) {
50
- const s = d(t, "i18nProps", []);
51
- if (_(a) || _(s)) return e;
49
+ function Ie(e, s, t) {
50
+ const a = d(t, "i18nProps", []);
51
+ if (_(s) || _(a)) return e;
52
52
  const r = L(e);
53
53
  return $(R(r), (i) => {
54
- if (f(s, i) && !_(a)) {
55
- const c = d(r, `${i}-${a}`, ""), n = d(r, i, "");
54
+ if (f(a, i) && !_(s)) {
55
+ const c = d(r, `${i}-${s}`, ""), n = d(r, i, "");
56
56
  r[i] = N(c) && c.trim() || n;
57
57
  }
58
58
  }), r;
59
59
  }
60
60
  const pe = U((e) => {
61
- const { baseClasses: a, classes: t } = Y(e);
62
- return ie(a, t);
61
+ const { baseClasses: s, classes: t } = Y(e);
62
+ return ie(s, t);
63
63
  });
64
- function ue(e, a) {
65
- return d(e, `${a}_attrs`, {});
64
+ function ue(e, s) {
65
+ return d(e, `${s}_attrs`, {});
66
66
  }
67
- function Ce(e, a = !0) {
67
+ function Ce(e, s = !0) {
68
68
  const t = {};
69
- return Object.keys(e).forEach((s) => {
70
- if (N(e[s]) && e[s].startsWith(m)) {
71
- const r = pe(e[s]), i = ue(e, s);
72
- t[s] = {
69
+ return Object.keys(e).forEach((a) => {
70
+ if (N(e[a]) && e[a].startsWith(b)) {
71
+ const r = pe(e[a]), i = ue(e, a);
72
+ t[a] = {
73
73
  ...!_(r) && { className: r },
74
74
  ...i,
75
- ...a ? {
76
- "data-style-prop": s,
75
+ ...s ? {
76
+ "data-style-prop": a,
77
77
  "data-block-parent": e._id,
78
- "data-style-id": `${s}-${e._id}`
78
+ "data-style-id": `${a}-${e._id}`
79
79
  } : {}
80
80
  };
81
81
  }
82
82
  }), t;
83
83
  }
84
84
  const Ne = U((e) => {
85
- const a = G(e), t = d(a, "schema.properties", {});
86
- return Object.fromEntries(Object.entries(t).filter(([, s]) => d(s, "runtime", !1)));
87
- }), Be = (e, a) => {
85
+ const s = G(e), t = d(s, "schema.properties", {});
86
+ return Object.fromEntries(Object.entries(t).filter(([, a]) => d(a, "runtime", !1)));
87
+ }), Be = (e, s) => {
88
88
  if (!C(e)) return e;
89
- let t = e, s;
90
- return typeof a.limit == "number" && a.limit > 0 && (s = a.limit), s !== void 0 && (t = t.slice(0, s)), t;
91
- }, De = (e, a) => {
89
+ let t = e, a;
90
+ return typeof s.limit == "number" && s.limit > 0 && (a = s.limit), a !== void 0 && (t = t.slice(0, a)), t;
91
+ }, De = (e, s) => {
92
92
  const t = L(e);
93
- return $(R(t), (s) => {
94
- if (N(t[s]) && !k(s, "_")) {
95
- let r = t[s];
96
- s === "repeaterItems" && (t.repeaterItemsBinding = r);
93
+ return $(R(t), (a) => {
94
+ if (N(t[a]) && !v(a, "_")) {
95
+ let r = t[a];
96
+ a === "repeaterItems" && (t.repeaterItemsBinding = r);
97
97
  const i = /\{\{(.*?)\}\}/g, c = r.match(i);
98
98
  c && c.forEach((n) => {
99
99
  let p = n.slice(2, -2);
100
- const h = d(a, p, n);
100
+ const h = d(s, p, n);
101
101
  r = C(h) ? h : r.replace(n, h);
102
- }), t[s] = r;
102
+ }), t[a] = r;
103
103
  }
104
104
  }), t;
105
105
  }, de = (e) => {
106
- 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/;
107
- return a.test(e) || t.test(e);
106
+ 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/;
107
+ return s.test(e) || t.test(e);
108
108
  }, he = (e) => {
109
109
  if (_(e)) return e;
110
- const a = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, s = e.match(a), r = e.match(t), i = s ? s[1] : r ? r[1] : null, c = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, n = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
110
+ const s = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(s), r = e.match(t), i = a ? a[1] : r ? r[1] : null, c = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, n = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
111
111
  return i && (c.test(i) || n.test(i)) ? i : e;
112
112
  }, K = ["chai-name", "data-chai-name"], ge = {
113
113
  img: { alt: "alt", width: "width", height: "height", src: "image" },
@@ -145,12 +145,12 @@ const Ne = U((e) => {
145
145
  form: {
146
146
  action: "action"
147
147
  }
148
- }, ye = (e, a) => e.children.length === 1 && f(
148
+ }, ye = (e, s) => e.children.length === 1 && f(
149
149
  ["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
150
- a._type
151
- ), D = (e) => e.map((a) => a.type === "text" ? d(a, "content", "") : _(a.children) ? "" : D(a.children)).join(""), j = (e) => e === null ? "" : e, X = (e) => {
152
- const a = se(ae(e.split(/\s+/), re)), t = y(a, (n) => /^w-/.test(n)), s = y(a, (n) => /^h-/.test(n));
153
- if (!s || !t) return { height: "", width: "" };
150
+ s._type
151
+ ), D = (e) => e.map((s) => s.type === "text" ? d(s, "content", "") : _(s.children) ? "" : D(s.children)).join(""), j = (e) => e === null ? "" : e, X = (e) => {
152
+ const s = ae(se(e.split(/\s+/), re)), t = y(s, (n) => /^w-/.test(n)), a = y(s, (n) => /^h-/.test(n));
153
+ if (!a || !t) return { height: "", width: "" };
154
154
  const r = (n) => {
155
155
  if (!n) return;
156
156
  const p = n.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
@@ -158,36 +158,36 @@ const Ne = U((e) => {
158
158
  if (p[1]) return p[1];
159
159
  const h = p[2];
160
160
  return /^\d+(\.\d+)?$/.test(h) ? `${Number(h) * 4}px` : h === "auto" || f(h, "%") ? h : "16px";
161
- }, i = r(t), c = r(s);
161
+ }, i = r(t), c = r(a);
162
162
  return {
163
163
  width: f(i, "px") ? i : "16px",
164
164
  height: f(c, "px") ? c : "16px"
165
165
  };
166
166
  }, F = (e) => {
167
167
  if (e.tagName === "svg") return {};
168
- const a = {}, t = ge[e.tagName] || {}, s = e.attributes;
169
- return $(s, ({ key: r, value: i }) => {
168
+ const s = {}, t = ge[e.tagName] || {}, a = e.attributes;
169
+ return $(a, ({ key: r, value: i }) => {
170
170
  if (!f(K, r))
171
171
  if (t[r]) {
172
172
  if (e.tagName === "img" && r === "src" && !i.startsWith("http")) {
173
173
  const c = y(e.attributes, { key: "width" }), n = y(e.attributes, { key: "height" });
174
174
  c && n ? i = `https://via.placeholder.com/${c == null ? void 0 : c.value}x${n == null ? void 0 : n.value}` : i = "https://via.placeholder.com/150x150";
175
175
  }
176
- x(a, t[r], j(i));
177
- } else f(["style", "class", "srcset"], r) || (I(a, "styles_attrs") || (a.styles_attrs = {}), k(r, "@") && (r = r.replace("@", "x-on:")), a.styles_attrs[`${r}`] = j(i));
178
- }), delete a.class, a;
179
- }, me = (e, a = "styles") => {
180
- if (!e.attributes) return { [a]: `${m},` };
176
+ x(s, t[r], j(i));
177
+ } else f(["style", "class", "srcset"], r) || (I(s, "styles_attrs") || (s.styles_attrs = {}), v(r, "@") && (r = r.replace("@", "x-on:")), s.styles_attrs[`${r}`] = j(i));
178
+ }), delete s.class, s;
179
+ }, me = (e, s = "styles") => {
180
+ if (!e.attributes) return { [s]: `${b},` };
181
181
  const t = y(e.attributes, { key: "class" });
182
182
  if (t) {
183
- const s = t.value;
184
- return { [a]: `${m},${s}` };
183
+ const a = t.value;
184
+ return { [s]: `${b},${a}` };
185
185
  }
186
- return { [a]: `${m},` };
186
+ return { [s]: `${b},` };
187
187
  }, be = (e) => {
188
- const a = d(e, "attributes", []), t = a.find((n) => n.key === "data-chai-richtext" || n.key === "chai-richtext"), s = a.find((n) => n.key === "data-chai-lightbox" || n.key === "chai-lightbox"), r = a.find((n) => n.key === "data-chai-dropdown" || n.key === "chai-dropdown"), i = a.find(
188
+ const s = d(e, "attributes", []), t = s.find((n) => n.key === "data-chai-richtext" || n.key === "chai-richtext"), a = s.find((n) => n.key === "data-chai-lightbox" || n.key === "chai-lightbox"), r = s.find((n) => n.key === "data-chai-dropdown" || n.key === "chai-dropdown"), i = s.find(
189
189
  (n) => n.key === "data-chai-dropdown-button" || n.key === "chai-dropdown-button"
190
- ), c = a.find(
190
+ ), c = s.find(
191
191
  (n) => n.key === "data-chai-dropdown-content" || n.key === "chai-dropdown-content"
192
192
  );
193
193
  if (r)
@@ -198,7 +198,7 @@ const Ne = U((e) => {
198
198
  return { _type: "DropdownContent" };
199
199
  if (t)
200
200
  return { _type: "RichText" };
201
- if (s)
201
+ if (a)
202
202
  return { _type: "LightBoxLink" };
203
203
  switch (e.tagName) {
204
204
  // self closing tags
@@ -286,12 +286,12 @@ const Ne = U((e) => {
286
286
  };
287
287
  }
288
288
  }
289
- }, Z = (e, a = null) => ee(e, (t) => {
290
- var A, S, H, M, P, q, z, O, V, W;
289
+ }, Z = (e, s = null) => ee(e, (t) => {
290
+ var A, S, H, M, P, q, z, J, O, V;
291
291
  if (t.type === "comment") return [];
292
- let s = { _id: oe() };
293
- if (a && (s._parent = a.block._id), t.type === "text")
294
- return _(d(t, "content", "")) ? [] : a && ye(a.node, a.block) ? (x(a, "block.content", d(t, "content", "")), []) : { ...s, _type: "Text", content: d(t, "content", "") };
292
+ let a = { _id: oe() };
293
+ if (s && (a._parent = s.block._id), t.type === "text")
294
+ return _(d(t, "content", "")) ? [] : s && ye(s.node, s.block) ? (x(s, "block.content", d(t, "content", "")), []) : { ...a, _type: "Text", content: d(t, "content", "") };
295
295
  const r = d(t, "attributes", []), i = r.find(
296
296
  (o) => o.key === "data-chai-richtext" || o.key === "chai-richtext"
297
297
  ), c = r.find(
@@ -303,17 +303,17 @@ const Ne = U((e) => {
303
303
  ), h = r.find(
304
304
  (o) => o.key === "data-chai-dropdown-content" || o.key === "chai-dropdown-content"
305
305
  );
306
- if (s = {
307
- ...s,
306
+ if (a = {
307
+ ...a,
308
308
  ...be(t),
309
309
  ...F(t),
310
310
  ...me(t)
311
311
  }, t.attributes) {
312
312
  const o = t.attributes.find((l) => f(K, l.key));
313
- o && (s._name = o.value);
313
+ o && (a._name = o.value);
314
314
  }
315
315
  if (i)
316
- return s.content = T(t.children), I(s, "styles_attrs.data-chai-richtext") && delete s.styles_attrs["data-chai-richtext"], I(s, "styles_attrs.chai-richtext") && delete s.styles_attrs["chai-richtext"], [s];
316
+ return a.content = E(t.children), I(a, "styles_attrs.data-chai-richtext") && delete a.styles_attrs["data-chai-richtext"], I(a, "styles_attrs.chai-richtext") && delete a.styles_attrs["chai-richtext"], [a];
317
317
  if (c) {
318
318
  const o = [
319
319
  "data-chai-lightbox",
@@ -325,8 +325,8 @@ const Ne = U((e) => {
325
325
  "data-gall",
326
326
  "href"
327
327
  ];
328
- s = {
329
- ...s,
328
+ a = {
329
+ ...a,
330
330
  href: ((A = r.find((l) => l.key === "href")) == null ? void 0 : A.value) || "",
331
331
  hrefType: ((S = r.find((l) => l.key === "data-vbtype")) == null ? void 0 : S.value) || "video",
332
332
  autoplay: ((H = r.find((l) => l.key === "data-autoplay")) == null ? void 0 : H.value) === "true" ? "true" : "false",
@@ -334,13 +334,13 @@ const Ne = U((e) => {
334
334
  backdropColor: ((q = r.find((l) => l.key === "data-overlay")) == null ? void 0 : q.value) || "",
335
335
  galleryName: ((z = r.find((l) => l.key === "data-gall")) == null ? void 0 : z.value) || ""
336
336
  }, $(o, (l) => {
337
- I(s, `styles_attrs.${l}`) && delete s.styles_attrs[l];
337
+ I(a, `styles_attrs.${l}`) && delete a.styles_attrs[l];
338
338
  });
339
339
  }
340
- if (n && (delete s.styles_attrs, s.showDropdown = !1), h && delete s.styles_attrs, p) {
341
- delete s.styles_attrs;
342
- const o = J(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
343
- s.content = D(o);
340
+ if (n && (delete a.styles_attrs, a.showDropdown = !1), h && delete a.styles_attrs, p) {
341
+ delete a.styles_attrs;
342
+ const o = W(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
343
+ a.content = D(o);
344
344
  const l = y(
345
345
  t.children || [],
346
346
  (u) => (u == null ? void 0 : u.tagName) === "span" && te(u.children || [], (g) => (g == null ? void 0 : g.tagName) === "svg")
@@ -348,90 +348,90 @@ const Ne = U((e) => {
348
348
  if (l) {
349
349
  const u = y(l.children || [], (g) => (g == null ? void 0 : g.tagName) === "svg");
350
350
  if (u) {
351
- s.icon = T([u]);
352
- const { height: g, width: v } = fe(u, "16px", "16px");
353
- s.iconHeight = g, s.iconWidth = v;
351
+ a.icon = E([u]);
352
+ const { height: g, width: w } = fe(u, "16px", "16px");
353
+ a.iconHeight = g, a.iconWidth = w;
354
354
  }
355
355
  }
356
- return [s];
356
+ return [a];
357
357
  }
358
- if (s._type === "Input") {
359
- const o = s.inputType || "text";
360
- o === "checkbox" ? x(s, "_type", "Checkbox") : o === "radio" && x(s, "_type", "Radio");
358
+ if (a._type === "Input") {
359
+ const o = a.inputType || "text";
360
+ o === "checkbox" ? x(a, "_type", "Checkbox") : o === "radio" && x(a, "_type", "Radio");
361
361
  } else if (t.tagName === "video" || t.tagName === "iframe") {
362
- const o = T([t]);
363
- return de(o) && (x(s, "_type", "Video"), x(s, "url", he(o)), x(s, "styles", `${m},`), x(s, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), s.content = o, [s];
362
+ const o = E([t]);
363
+ return de(o) && (x(a, "_type", "Video"), x(a, "url", he(o)), x(a, "styles", `${b},`), x(a, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), a.content = o, [a];
364
364
  } else if (t.tagName === "svg") {
365
365
  const o = d(y(t.attributes, { key: "class" }), "value", ""), { height: l, width: u } = X(o);
366
366
  if (l && u)
367
- s.styles = `${m}, ${B(`w-${u} h-${l}`, o)}`.trim(), s.height = l == null ? void 0 : l.replace("px", ""), s.width = u == null ? void 0 : u.replace("px", "");
367
+ a.styles = `${b}, ${B(`w-${u} h-${l}`, o)}`.trim(), a.height = l == null ? void 0 : l.replace("px", ""), a.width = u == null ? void 0 : u.replace("px", "");
368
368
  else {
369
- const g = (O = y(t.attributes, { key: "height" })) == null ? void 0 : O.value, v = (V = y(t.attributes, { key: "width" })) == null ? void 0 : V.value;
370
- g && v ? (s.styles = `${m}, ${B(`w-[${v}px] h-[${g}px]`, o)}`.trim(), s.height = g, s.width = v) : s.styles = `${m}, ${B("w-full h-full", o)}`.trim();
369
+ const g = (J = y(t.attributes, { key: "height" })) == null ? void 0 : J.value, w = (O = y(t.attributes, { key: "width" })) == null ? void 0 : O.value;
370
+ g && w ? (a.styles = `${b}, ${B(`w-[${w}px] h-[${g}px]`, o)}`.trim(), a.height = g, a.width = w) : a.styles = `${b}, ${B("w-full h-full", o)}`.trim();
371
371
  }
372
- return t.attributes = J(t.attributes, (g) => !f(["style", "width", "height", "class"], g.key)), s.icon = T([t]), [s];
373
- } else if (t.tagName == "option" && a && ((W = a.block) == null ? void 0 : W._type) === "Select")
374
- return a.block.options.push({
372
+ return t.attributes = W(t.attributes, (g) => !f(["style", "width", "height", "class"], g.key)), a.icon = E([t]), [a];
373
+ } else if (t.tagName == "option" && s && ((V = s.block) == null ? void 0 : V._type) === "Select")
374
+ return s.block.options.push({
375
375
  label: D(t.children),
376
376
  ...F(t)
377
377
  }), [];
378
- const w = Z(t.children, { block: s, node: t });
379
- return [s, ...w];
380
- }), fe = (e, a, t) => {
378
+ const k = Z(t.children, { block: a, node: t });
379
+ return [a, ...k];
380
+ }), fe = (e, s, t) => {
381
381
  var p, h;
382
- const s = d(e, "attributes", []), { height: r, width: i } = X(
383
- d(y(s, { key: "class" }), "value", "")
382
+ const a = d(e, "attributes", []), { height: r, width: i } = X(
383
+ d(y(a, { key: "class" }), "value", "")
384
384
  );
385
385
  if (r && i)
386
386
  return {
387
387
  height: `[${r}px]`,
388
388
  width: `[${i}px]`
389
389
  };
390
- const c = (p = y(s, { key: "height" })) == null ? void 0 : p.value, n = (h = y(s, { key: "width" })) == null ? void 0 : h.value;
390
+ const c = (p = y(a, { key: "height" })) == null ? void 0 : p.value, n = (h = y(a, { key: "width" })) == null ? void 0 : h.value;
391
391
  return {
392
392
  height: c ? `[${c}px]` : t,
393
- width: n ? `[${n}px]` : a
393
+ width: n ? `[${n}px]` : s
394
394
  };
395
395
  }, xe = (e) => {
396
- e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (s, r, i) => {
396
+ e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (a, r, i) => {
397
397
  let c = i.replace(/\\"/g, '"');
398
398
  return c = c.replace(/{([^}]+)}/g, (n) => n.replace(/"/g, '\\"')), `${r}="${c.replace(/\\"/g, '"')}"`;
399
399
  }), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
400
- const a = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
401
- 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();
400
+ const s = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
401
+ 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();
402
402
  }, Le = (e) => {
403
- const a = ce(xe(e));
404
- return _(e) ? [] : Q(Z(a));
405
- }, b = (e, a, { index: t, key: s }) => {
403
+ const s = ce(xe(e));
404
+ return _(e) ? [] : Q(Z(s));
405
+ }, m = (e, s, { index: t, key: a }) => {
406
406
  if (N(e)) {
407
407
  let r = e;
408
408
  const i = /\{\{(.*?)\}\}/g, c = e.match(i);
409
409
  return c && c.forEach((n) => {
410
- let p = n.slice(2, -2).trim(), h = s.slice(2, -2).trim();
411
- t !== -1 && k(p, "$index.") ? p = `${h}.${t}.${p.slice(7)}` : t !== -1 && k(p, "$index") && (p = `${h}.${t}`);
412
- const w = d(a, p, n);
413
- r = C(w) ? w : r.replace(n, w);
410
+ let p = n.slice(2, -2).trim(), h = a.slice(2, -2).trim();
411
+ t !== -1 && v(p, "$index.") ? p = `${h}.${t}.${p.slice(7)}` : t !== -1 && v(p, "$index") && (p = `${h}.${t}`);
412
+ const k = d(s, p);
413
+ k === void 0 ? r = r.replace(n, "") : r = C(k) ? k : r.replace(n, k);
414
414
  }), r;
415
415
  }
416
416
  if (C(e))
417
- return e.map((r) => b(r, a, { index: t, key: s }));
417
+ return e.map((r) => m(r, s, { index: t, key: a }));
418
418
  if (e && typeof e == "object") {
419
419
  const r = {};
420
420
  return $(R(e), (i) => {
421
- !k(i, "_") && i !== "$repeaterItemsKey" ? r[i] = b(e[i], a, { index: t, key: s }) : r[i] = e[i];
421
+ !v(i, "_") && i !== "$repeaterItemsKey" ? r[i] = m(e[i], s, { index: t, key: a }) : r[i] = e[i];
422
422
  }), r;
423
423
  }
424
424
  return e;
425
- }, E = (e, a, { index: t, key: s }) => {
425
+ }, T = (e, s, { index: t, key: a }) => {
426
426
  let r = L(e);
427
- return r.repeaterItems && (r.$repeaterItemsKey = r.repeaterItems, k(r.repeaterItems, `{{${le}`) && (r.$repeaterItemsKey = r.repeaterItems = `${r.repeaterItems.replace("}}", `/${r._id}}}`)}`)), b(r, a, { index: t, key: s });
427
+ return r.repeaterItems && (r.$repeaterItemsKey = r.repeaterItems, v(r.repeaterItems, `{{${le}`) && (r.$repeaterItemsKey = r.repeaterItems = `${r.repeaterItems.replace("}}", `/${r._id}}}`)}`)), m(r, s, { index: t, key: a });
428
428
  };
429
429
  import.meta.vitest && (describe("applyBindingToValue", () => {
430
430
  it("should handle string values with bindings", () => {
431
- const t = b("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
431
+ const t = m("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
432
432
  expect(t).toBe("Hello John");
433
433
  }), it("should handle nested object properties", () => {
434
- const t = b({
434
+ const t = m({
435
435
  name: "John",
436
436
  address: {
437
437
  city: "{{user.city}}",
@@ -446,27 +446,30 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
446
446
  }
447
447
  });
448
448
  }), it("should handle arrays of values", () => {
449
- const t = b(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
449
+ const t = m(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
450
450
  expect(t).toEqual(["Hello John", "Welcome Admin"]);
451
451
  }), it("should handle $index binding in repeater context", () => {
452
- const t = b("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
452
+ const t = m("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
453
453
  expect(t).toBe("Item b");
454
454
  }), it("should handle $index binding with dot notation", () => {
455
- const t = b("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
455
+ const t = m("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
456
456
  expect(t).toBe("Item banana");
457
+ }), it("should return an empty string for non-existing bindings", () => {
458
+ const t = m("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
459
+ expect(t).toBe("Hello ");
457
460
  }), it("should preserve private properties starting with _", () => {
458
- const a = b({
461
+ const s = m({
459
462
  name: "John",
460
463
  _private: "secret"
461
464
  }, {}, { index: -1, key: "" });
462
- expect(a).toEqual({
465
+ expect(s).toEqual({
463
466
  name: "John",
464
467
  _private: "secret"
465
468
  });
466
469
  });
467
470
  }), describe("applyBindingToBlockProps", () => {
468
471
  it("should handle basic block with bindings", () => {
469
- const t = E({
472
+ const t = T({
470
473
  _id: "test-block",
471
474
  _type: "text",
472
475
  type: "text",
@@ -485,7 +488,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
485
488
  }
486
489
  });
487
490
  }), it("should handle repeaterItems and repeaterItemsBinding", () => {
488
- const t = E({
491
+ const t = T({
489
492
  _id: "test-block",
490
493
  _type: "repeater",
491
494
  type: "repeater",
@@ -501,7 +504,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
501
504
  items: ["a", "b", "c"]
502
505
  });
503
506
  }), it("should handle nested blocks with bindings", () => {
504
- const t = E({
507
+ const t = T({
505
508
  _id: "test-block",
506
509
  _type: "container",
507
510
  type: "container",
@@ -534,7 +537,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
534
537
  ]
535
538
  });
536
539
  }), it("should handle arrays of blocks", () => {
537
- const t = E({
540
+ const t = T({
538
541
  _id: "test-block",
539
542
  _type: "list",
540
543
  type: "list",
@@ -556,9 +559,9 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
556
559
  }));
557
560
  export {
558
561
  le as C,
559
- Ee as R,
560
- m as S,
561
- E as a,
562
+ Te as R,
563
+ b as S,
564
+ T as a,
562
565
  Ie as b,
563
566
  Ne as c,
564
567
  Be as d,
@@ -566,5 +569,5 @@ export {
566
569
  Le as f,
567
570
  Ce as g,
568
571
  Y as h,
569
- Te as i
572
+ Ee as i
570
573
  };