@lightspeed/crane-api 2.3.3-rc.0 → 2.3.3-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createSSRApp as Te,getCurrentInstance as fe,ref as y,computed as a,reactive as E}from"vue";import{renderToString as pe}from"vue/server-renderer";import{z as m}from"zod";function B(e){return{app:Te(e)}}const w=new Map;function O(){const e=(r,i,l,c,v,d,s,u)=>{w.set(r._uid,{context:y(i),content:y(l),design:y(c),defaults:y(v),site:y(d?.site??{}),category:y(d?.category),storeData:y(d?.storeData),globalDesign:y(s),tileId:y(u??void 0)})},t=(r,i,l,c,v,d,s)=>{const u=w.get(r._uid);u!==void 0&&(u.content.value=i,u.design.value=l,u.defaults.value=c,u.site.value=v.site??{},u.category.value=v.category,u.globalDesign.value=d,u.storeData.value=v.storeData,u.tileId.value=s)},n=fe()?.appContext.app._uid??-1,o=w.get(n);return{init:e,update:t,context:o?.context,content:o?.content,design:o?.design,defaults:o?.defaults,site:o?.site,category:o?.category,storeData:o?.storeData,globalDesign:o?.globalDesign,tileId:o?.tileId}}function me(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{mount:(o,r)=>{O().init(n,r.context,r.data.content,r.data.design,r.data.defaults,r.data.externalContent,r.context.globalDesign,r.data.tileId),t?.mount?.(n,o,r),n.mount(o)},update:o=>{O().update(n,o.data.content,o.data.design,o.data.defaults,o.data.externalContent,o.context.globalDesign,o.data.tileId),t?.update?.(n,o)},unmount:()=>{t?.unmount?.(n),n.unmount()}}}}}function Ie(){return globalThis.window.instantsite}function Le(e){const t={appName:"",blockName:"",version:"",scriptUrl:"",imageBuckets:{},globalDesign:{}};return{component:e,initState(n,o,r,i){O().init(n,t,o,r,i,{},{},void 0)},updateState(n,o,r,i){O().update(n,o,r,i,{},{},void 0)}}}function _e(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{render:async(o,r)=>(O().init(n,o,r.content,r.design,r.defaults,r.externalContent,o.globalDesign,r.tileId),t?.render?.(n,o,r),{html:await pe(n,{context:o}),state:{context:o,data:r}})}}}}const Ce={SOLID:"solid",GRADIENT:"gradient",NONE:"none"},M={SCROLL_TO_TILE:"SCROLL_TO_TILE",HYPER_LINK:"HYPER_LINK",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};m.enum(Object.values(M));const Re=M,x={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(x));const be=x,k={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(k));const ye=k,P={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(P));const Se=P,$={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values($));const Ae=$,K={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values(K));const Ne=K,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(X));const Ge=X;var z=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e[e.Layout=3]="Layout",e[e.Asset=4]="Asset",e[e.SharedFiles=5]="SharedFiles",e))(z||{}),F=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e[e.PageTemplateDescriptor=6]="PageTemplateDescriptor",e[e.TemplateAsset=7]="TemplateAsset",e[e.Layout=8]="Layout",e[e.LayoutSettings=9]="LayoutSettings",e[e.LayoutAsset=10]="LayoutAsset",e[e.SlotServer=11]="SlotServer",e[e.SlotClient=12]="SlotClient",e[e.SharedTranslation=13]="SharedTranslation",e[e.CollectionDescriptor=14]="CollectionDescriptor",e[e.CollectionAsset=15]="CollectionAsset",e))(F||{}),Y=(e=>(e.SCROLL_TO_TILE="SCROLL_TO_TILE",e.HYPER_LINK="HYPER_LINK",e.MAIL_LINK="MAIL_LINK",e.TEL_LINK="TEL_LINK",e.GO_TO_STORE="GO_TO_STORE",e.GO_TO_STORE_LINK="GO_TO_STORE_LINK",e.GO_TO_PAGE="GO_TO_PAGE",e))(Y||{});const I={TEXTAREA:"TEXTAREA",INPUTBOX:"INPUTBOX",SELECTBOX:"SELECTBOX",IMAGE:"IMAGE",TOGGLE:"TOGGLE",BUTTON:"BUTTON",DECK:"DECK",MENU:"MENU",NAVIGATION_MENU:"NAVIGATION_MENU",LOGO:"LOGO",INFO:"INFO",DIVIDER:"DIVIDER",PRODUCT_SELECTOR:"PRODUCT_SELECTOR",CATEGORY_SELECTOR:"CATEGORY_SELECTOR"};m.enum(Object.values(I));const V={TEXT:"TEXT",BUTTON:"BUTTON",IMAGE:"IMAGE",TOGGLE:"TOGGLE",SELECTBOX:"SELECTBOX",BACKGROUND:"BACKGROUND",COLOR_PICKER:"COLOR_PICKER",LOGO:"LOGO",DIVIDER:"DIVIDER",INFO:"INFO",ACCORDION:"ACCORDION"};m.enum(Object.values(V));const De=V,j={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(j));const he=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(W));const we=W;class Ue{type="STRUCTURED_COLOR";raw;hex;hsl;rgba;auto;constructor({raw:t,hex:n,hsl:o,rgba:r,auto:i}){this.raw=t,this.hex=n,this.hsl=o,this.rgba=r,this.auto=i}}function Be(e){if(e!==void 0)return{...e,type:"STRUCTURED_COLOR"}}var H=(e=>(e.ORIGINAL="original",e.WEBP_LOW_RES="webp-200x200",e.WEBP_HI_2X_RES="webp-2000x2000",e.MOBILE_WEBP_LOW_RES="cropped-webp-100x200",e.MOBILE_WEBP_HI_RES="cropped-webp-1000x2000",e))(H||{}),J=(e=>(e.TILE_LOADED="tile-loaded",e.TILE_UNLOADED="tile-unloaded",e))(J||{});const Me={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},xe={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},ke={TOP_BAR:"TOP_BAR",GALLERY:"GALLERY",SIDEBAR:"SIDEBAR",DESCRIPTION:"DESCRIPTION",REVIEW_LIST:"REVIEW_LIST",RELATED_PRODUCTS:"RELATED_PRODUCTS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},q={apparel_footwear:"apparel_footwear",vape_smoke:"vape_smoke",home_garden:"home_garden",sport_outdoor:"sport_outdoor",jewelry_accessories:"jewelry_accessories",pet_animals:"pet_animals",bikes:"bikes",health_beauty:"health_beauty",gift_shop:"gift_shop",electronics:"electronics",other:"other"};m.enum(Object.values(q));const Pe=q;function Q(e){if(!e||e.length===0)return[];const t=[];function n(o){if(t.push({id:o.id,name:o.name,url:o.urlPath}),o.children&&o.children.length>0)for(const r of o.children)n(r)}for(const o of e)n(o);return t}const S={HYPER_LINK:"HYPER_LINK",SCROLL_TO_TILE:"SCROLL_TO_TILE",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};function $e(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Ke(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Xe(e,t){if("pageUrl"in e)return e.pageUrl;const n=Ke(e);switch(n){case"products":return"/products";case"cart":return"/cart";case"account":return"/account";case"search":return"/search";case"home":return"/"}if(t){const o=t.find(r=>r.pageId===n);if(o)return o.url}return"/"}function ze(e){if("categoryId"in e)return e.categoryId}function Fe(e){if(!e||e.length===0)return"";const t=e.find(n=>n.selected);return!t||t.main?"":`/${t.code}`}const Z=(e,t,n)=>{if(!e||t)return;const{type:o,link:r,email:i,phone:l}=e,c=O(),v=c.site?.value?.pages,d=c.site?.value?.languages,s=Fe(d),u=Xe(e,v),g=ze(e);switch(o){case S.HYPER_LINK:if(r){const f=e.linkTarget??"_blank";return()=>window.open(r,f)}break;case S.GO_TO_STORE:case S.GO_TO_STORE_LINK:return()=>window.open(`${s}/products`,"_self");case S.GO_TO_CATEGORY:case S.GO_TO_CATEGORY_LINK:const A=n?.find(f=>f.id===g)?.url;return A===void 0?()=>window.open(`${s}/404`,"_self"):()=>window.open(A,"_self");case S.MAIL_LINK:if(i)return()=>window.open(`mailto:${i}`,"_self");break;case S.TEL_LINK:if(l)return()=>window.open(`tel:${l}`,"_self");break;case S.SCROLL_TO_TILE:if(typeof document<"u")return()=>{const f=$e(e);document.getElementById(`tile-${f}`)?.scrollIntoView()};break;case S.GO_TO_PAGE:if(u)return()=>window.open(`${s}${u}`,"_self");break;default:console.error(`Unknown type of ActionLink: ${o}`)}};function Ye(e){return"title"in e&&"type"in e}function Ve(e,t,n,o){const r=a(()=>{const b=e.value[t];if(b!==void 0){if(Ye(b))return b;throw new Error(`Element ${t} is not action link`)}}),i=a(()=>r.value?.title),l=a(()=>r.value?.type),c=a(()=>r.value?.link),v=a(()=>r.value?.email),d=a(()=>r.value?.phone),s=a(()=>r.value?.tileId?`tile-${r.value?.tileId}`:null),u=a(()=>r.value?.type==="GO_TO_STORE_LINK"?"products":r.value?.pageId),g=a(()=>r.value?.pageUrl),A=a(()=>!!i.value),f=a(()=>!!c.value),N=Z(r.value,n,o);return E({title:i,type:l,link:c,email:v,phone:d,tileDivId:s,pageId:u,pageUrl:g,hasTitle:A,hasLink:f,performAction:N})}function ee(e,t){const n=O(),o=a(()=>!!n.site?.value?.isPreviewMode),r=a(()=>{const l=n.category?.value?.categoryTree;return Q(l)}),i=a(()=>t!==void 0?t:n.content.value!==void 0?n.content.value:{});return Ve(i,e,o.value,r.value)}function te({content:e,elementName:t,errorMessage:n,validatorFn:o}){return a(()=>{const r=e.value?.[t];if(r!==void 0){if(o(r))return r;throw new Error(n)}})}function je(e){return typeof e=="object"&&e!==null&&"categories"in e}function We(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function He(e){return e!==void 0}function Je(e){return!!e?.trim()}function qe({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:Je(t)?t:e}function Qe(e,t){return He(e)&&t}function ne({itemId:e,id:t,alt:n,name:o,nameTranslated:r,customName:i,enabled:l,productsCount:c,url:v,imageUrl:d,thumbnailImageUrl:s,imageBorderInfo:u,selectionType:g}){return{itemId:e||t.toString(),id:t,alt:n,name:qe({name:o,customName:i,selectionType:g}),nameTranslated:r,label:o,enabled:l,url:v,productsCount:c,imageUrl:d,thumbnailImageUrl:s,imageBorderInfo:u,showCategory:Qe(t,l)}}function oe(e,t,n){const o=O(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a category selector type`,validatorFn:je}),l=a(()=>n??o.storeData?.value),c=a(()=>i.value?.categories.selectionType??"ROOT"),v=a(()=>l.value?.categories??[]),d=a(()=>i.value?.categories?.categoryIds??[]),s=a(()=>{const A=We(v);return c.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const N=A.value[f.id];return ne({...f,...N,selectionType:c.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:c.value}))??[]}),u=a(()=>i.value!==void 0),g=a(()=>s.value!==void 0&&s.value.length>0);return E({categories:s,categoryIds:d,hasContent:u,hasCategories:g})}function Ze(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function ae(e,t,n){const o=O(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a product selector type`,validatorFn:Ze}),l=a(()=>n??o.storeData?.value),c=a(()=>i.value?.products?.selectionType??"MANUAL"),v=a(()=>i.value?.products?.productIds??[]),d=a(()=>i.value?.product?.id),s=a(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),u=a(()=>{if(c.value==="ALL")return l?.value?.products??[];if(c.value==="CATEGORY")return s.value===0?l?.value?.products.filter(b=>b?.defaultCategoryId===0)??[]:l?.value?.products.filter(b=>s.value&&b?.categoryIds?.includes(s.value))??[];const N=d.value?[d.value]:v.value??[];return l?.value?.products?.filter(b=>N.includes(b.id))??[]}),g=a(()=>l?.value?.categories.filter(N=>N.id===s?.value)??[]),A=a(()=>i.value!==void 0&&u.value.length>0),f=a(()=>u.value!==void 0&&u.value.length>0);return E({products:u,categories:g,categoryId:s,hasContent:A,hasProducts:f})}function et(e){return"bucket"in e&&"set"in e}function G(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function tt(e,t){const n=a(()=>{const d=e.value[t];if(d!==void 0){if(et(d))return d;throw new Error(`Element ${t} is not image`)}}),o=a(()=>n.value===void 0?"":O().context.value.imageBuckets?.[n.value?.bucket]),r=a(()=>n.value!==void 0),i=a(()=>G(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=a(()=>G(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),c=a(()=>G(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>G(n.value?.set?.["webp-2000x2000"]?.url,o.value));return E({hasContent:r,lowResolutionMobileImage:i,highResolutionMobileImage:l,lowResolutionDesktopImage:c,highResolutionDesktopImage:v})}function re(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return tt(o,e)}function nt(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not inputbox`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return E({hasContent:o,value:r})}function ie(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return nt(o,e)}function ot(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not selectbox`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return E({hasContent:o,value:r})}function le(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return ot(o,e)}function at(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not textarea`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return E({hasContent:o,value:r})}function ue(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return at(o,e)}function rt(e){return"enabled"in e}function it(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(rt(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value?.enabled);return E({hasContent:o,value:r})}function se(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return it(o,e)}function ce(e){if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.cards)&&t.cards.every(n=>typeof n.settings=="object"&&n.settings!==null)}function de(e,t,n,o){if(e==null)throw Error("Could not get a reactive ref for undefined Card");const r=e.settings[n];if(r===void 0)return r;switch(t){case I.TEXTAREA:return ue(n,e.settings);case I.INPUTBOX:return ie(n,e.settings);case I.SELECTBOX:return le(n,e.settings);case I.IMAGE:return re(n,e.settings);case I.TOGGLE:return se(n,e.settings);case I.BUTTON:return ee(n,e.settings);case I.CATEGORY_SELECTOR:return oe(n,e.settings,o);case I.PRODUCT_SELECTOR:return ae(n,e.settings,o);case I.DECK:return lt(e,n,o);default:return}}function lt(e,t,n){const o=a(()=>{const l=e.settings[t];if(l!==void 0){if(ce(l))return l;throw new Error(`Element ${t} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return E({hasContent:r,cards:i,getReactiveRef:(l,c,v)=>de(l,c,v,n)})}function ut(e){const t=O(),n=a(()=>t.storeData?.value),o=a(()=>{const l=t.content.value[e];if(l!==void 0){if(ce(l))return l;throw new Error(`Element ${e} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return E({hasContent:r,cards:i,getReactiveRef:(l,c,v)=>de(l,c,v,n.value)})}function st(e){return"type"in e&&("text"in e||"image"in e)}function D(e,t){const n=new RegExp(/^https?:\/\//);return e!==void 0&&n.test(e)?e:`${t}/${e}`}function ct(){const e=O(),t=a(()=>{const l=e.content.value.logo;if(l!==void 0){if(st(l))return l;throw new Error("Element logo is not LOGO")}}),n=a(()=>t.value?.type),o=a(()=>t.value?.text),r=a(()=>t.value?.image===void 0?"":e.context.value.imageBuckets?.[t.value.image.bucket]),i=a(()=>({lowResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-100x200"]?.url,r.value),highResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-1000x2000"]?.url,r.value),lowResolutionDesktopImage:D(t.value?.image?.set?.["webp-200x200"]?.url,r.value),highResolutionDesktopImage:D(t.value?.image?.set?.["webp-2000x2000"]?.url,r.value)}));return E({type:n,text:o,image:i})}function dt(e){return e!==null&&"items"in e}function ve(e){const t=O(),n=a(()=>{const u=t.content.value[e];if(u!==void 0){if(dt(u))return u;throw new Error(`Element ${e} is not an menu`)}}),o=a(()=>!!t.site?.value?.isPreviewMode),r=a(()=>{const u=t.category?.value?.categoryTree;return Q(u)}),i=a(()=>n.value!==void 0);function l(u){if(u)try{return new URL(u).pathname}catch{return u}}function c(u){return u?.map(g=>({...g,url:l(g.url)??g.url}))}const v=a(()=>c(r.value));function d(u){const g=Z(u,o.value,v.value);return{...u,performAction:g,nestedItems:u.nestedItems?.map(d)}}const s=a(()=>n.value?.items?n.value.items.map(d):[]);return E({hasContent:i,items:s})}const vt="menu";function Ot(){return ve(vt)}function Et(){return globalThis.craneSharedTranslation??{}}function gt(){const e=O(),t=a(()=>e.site?.value),n=a(()=>Et()),o=a(()=>{const r=t.value?.languages;return r?r.find(i=>i.selected)?.code??r.find(i=>i.main)?.code??"en":"en"});return{t:r=>{const i=n.value;if(!i||Object.keys(i).length===0)return r;const l=o.value,c=i[l]?.[r];if(c!==void 0)return c;if(l!=="en"){const v=i.en?.[r];if(v!==void 0)return v}return r},currentLanguageCode:o}}function Tt(e){const t=O(),n=a(()=>t.design.value[e]),o=a(()=>{const l=n.value?.items;return l!==void 0&&Object.keys(l).length>0}),r=a(()=>n.value?.items),i=a(()=>n.value?.sortable??!1);return E({hasItems:o,items:r,sortable:i})}function Oe(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);return n===void 0?void 0:e.fontFamily?.[n]?.replaceAll("_"," ")}function h(e,t,n){return t?Oe(e,t):Oe(e,n)}function Ee(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.textSize?e.textSize[n]:void 0}function U(e,t,n){return t?Ee(e,t):Ee(e,n)}function ge(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.color?e.color[n]:void 0}function L(e,t,n){return t?ge(e,t):ge(e,n)}function ft(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:L(e,t?.color,n?.color)}}function pt(e){const t=O(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e],l=t.globalDesign.value;return{background:{type:r?.background?.type??i?.background?.type,solid:{color:L(l,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:L(l,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:L(l,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return E({background:o})}function mt(e){const t=O(),n=a(()=>{const d=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{appearance:d?.appearance??s?.appearance,font:h(u,d?.font,s?.font),size:d?.size??s?.size,style:d?.style??s?.style,color:L(u,d?.color,s?.color),visible:d?.visible??s?.visible??!1}}),o=a(()=>n.value?.appearance),r=a(()=>n.value?.font),i=a(()=>n.value?.size),l=a(()=>n.value?.style),c=a(()=>n.value?.color),v=a(()=>n.value?.visible);return E({appearance:o,font:r,size:i,style:l,color:c,visible:v.value??!1})}function It(e){const t=O(),n=a(()=>{const i=t.design.value[e],l=t.defaults.value[e],c=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??l?.overlay?.type,solid:{color:L(c,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:L(c,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:L(c,i?.overlay?.gradient?.toColor,l?.overlay?.gradient?.toColor)}},visible:i?.visible??l?.visible??!1}}),o=a(()=>n.value?.overlay),r=a(()=>n.value?.visible);return E({overlay:o,visible:r})}function Lt(){const e=O(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return E({layout:n})}function _t(){const e=O();return a(()=>{const t=e.design.value.logo,n=e.defaults.value.logo,o=e.globalDesign.value;return{font:h(o,t?.font,n?.font),size:U(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:L(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:ft(o,t?.frame,n?.frame)}})}function Ct(e){const t=O(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{value:r?.value??i?.value}}),o=a(()=>n.value?.value);return E({value:o})}function Rt(e){const t=O(),n=a(()=>{const d=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{font:h(u,d?.font,s?.font),size:U(u,d?.size,s?.size),bold:d?.bold??s?.bold,italic:d?.italic??s?.italic,color:L(u,d?.color,s?.color),visible:d?.visible??s?.visible??!1}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),c=a(()=>n.value?.color),v=a(()=>n.value?.visible);return E({font:o,size:r,bold:i,italic:l,color:c,visible:v})}function bt(e){const t=O(),n=a(()=>{const s=t.design.value[e],u=t.defaults.value[e],g=t.globalDesign.value;return{font:h(g,s?.font,u?.font),size:U(g,s?.size,u?.size),bold:s?.bold??u?.bold,italic:s?.italic??u?.italic,color:L(g,s?.color,u?.color),visible:s?.visible??u?.visible??!1,whiteSpace:"pre-wrap"}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),c=a(()=>n.value?.color),v=a(()=>n.value?.visible),d=a(()=>n.value?.whiteSpace);return E({font:o,size:r,bold:i,italic:l,color:c,visible:v,whiteSpace:d})}function yt(e){const t=O(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{enabled:r?.enabled??i?.enabled}}),o=a(()=>n.value?.enabled);return E({enabled:o})}const St={configuration:e=>({metadata:{...e.metadata},sections:[...e.sections]})};function T(e){return t=>{const{type:n}=t;return"type"in t?t:{type:e,...t}}}function p(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?T(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const At={inputbox:p("INPUTBOX"),textarea:p("TEXTAREA"),button:p("BUTTON"),image:p("IMAGE"),toggle:p("TOGGLE"),selectbox:p("SELECTBOX"),deck:p("DECK"),menu:p("MENU"),navigationMenu:p("NAVIGATION_MENU"),logo:p("LOGO"),productSelector:p("PRODUCT_SELECTOR"),categorySelector:p("CATEGORY_SELECTOR"),divider:p("DIVIDER"),info:p("INFO"),default:{inputbox:T("INPUTBOX"),textarea:T("TEXTAREA"),button:T("BUTTON"),selectbox:T("SELECTBOX"),image:T("IMAGE"),toggle:T("TOGGLE"),divider:T("DIVIDER"),info:T("INFO"),deck:T("DECK"),logo:T("LOGO"),menu:T("MENU"),navigationMenu:T("NAVIGATION_MENU"),productSelector:T("PRODUCT_SELECTOR"),categorySelector:T("CATEGORY_SELECTOR")}};function _(e){return t=>{const{type:n}=t;return"type"in t?t:{type:e,...t}}}function C(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?_(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const Nt={text:C("TEXT"),button:C("BUTTON"),image:C("IMAGE"),toggle:C("TOGGLE"),selectbox:C("SELECTBOX"),background:C("BACKGROUND"),colorPicker:C("COLOR_PICKER"),logo:C("LOGO"),divider:C("DIVIDER"),info:C("INFO"),accordion:C("ACCORDION"),default:{text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),accordion:_("ACCORDION"),info:_("INFO")}};function R(e){return t=>{const{type:n,defaults:o,...r}=t,i=o,l=i&&!("type"in i)?{...i,type:e}:o;return{type:e,...r,...l!==void 0?{defaults:l}:{}}}}const Gt={init:e=>({...e}),designOverride:{text:R("TEXT"),button:R("BUTTON"),image:R("IMAGE"),toggle:R("TOGGLE"),selectbox:R("SELECTBOX"),background:R("BACKGROUND"),colorPicker:R("COLOR_PICKER"),logo:R("LOGO"),divider:R("DIVIDER"),info:R("INFO"),accordion:R("ACCORDION")}},Dt={init:e=>e},ht={configuration:e=>({...e}),page:e=>({...e})},wt={default:e=>{const{type:t,...n}=e;return{type:"default",...n}},custom:e=>{const{type:t,...n}=e;return{type:"custom",...n}},store:(e={})=>{const{type:t,...n}=e;return{type:"store",...n}}},Ut={init:e=>({...e})};export{Y as ActionLinkTypeEnum,Ne as BackgroundStyleEnum,ye as ButtonAppearanceEnum,Ae as ButtonShapeEnum,Se as ButtonSizeEnum,Re as ButtonTypeEnum,Me as CatalogLayoutSlot,xe as CategoryLayoutSlot,Ue as Color,F as ConfigTypeEnum,De as DesignEditorType,I as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,we as LogoTypeEnum,Ce as OverlayType,be as OverlayTypeEnum,z as PluginTypeEnum,ke as ProductLayoutSlot,Ge as SectionTypeEnum,Pe as TemplateCategoriesList,he as ValidationTypeEnum,Be as asStructuredColor,St as collection,At as content,Le as createLayoutApp,me as createVueClientApp,_e as createVueServerApp,Nt as design,Gt as layout,wt as section,Dt as showcase,ht as template,Ut as translation,Tt as useAccordionElementDesign,pt as useBackgroundElementDesign,ee as useButtonElementContent,mt as useButtonElementDesign,oe as useCategorySelectorElementContent,ut as useDeckElementContent,re as useImageElementContent,It as useImageElementDesign,ie as useInputboxElementContent,Ie as useInstantsiteJsApi,Lt as useLayoutElementDesign,ct as useLogoElementContent,_t as useLogoElementDesign,ve as useMenuElementContent,Ot as useNavigationMenuElementContent,ae as useProductSelectorElementContent,le as useSelectboxElementContent,Ct as useSelectboxElementDesign,Rt as useTextElementDesign,ue as useTextareaElementContent,bt as useTextareaElementDesign,se as useToggleElementContent,yt as useToggleElementDesign,gt as useTranslation,O as useVueBaseProps};
1
+ import{createSSRApp as Ce,getCurrentInstance as Le,ref as y,computed as a,reactive as f}from"vue";import{renderToString as be}from"vue/server-renderer";import{z as m}from"zod";function B(e){return{app:Ce(e)}}const x=new Map;function g(){const e=(r,i,l,s,v,d,c,u)=>{x.set(r._uid,{context:y(i),content:y(l),design:y(s),defaults:y(v),site:y(d?.site??{}),category:y(d?.category),storeData:y(d?.storeData),globalDesign:y(c),tileId:y(u??void 0)})},t=(r,i,l,s,v,d,c)=>{const u=x.get(r._uid);u!==void 0&&(u.content.value=i,u.design.value=l,u.defaults.value=s,u.site.value=v.site??{},u.category.value=v.category,u.globalDesign.value=d,u.storeData.value=v.storeData,u.tileId.value=c)},n=Le()?.appContext.app._uid??-1,o=x.get(n);return{init:e,update:t,context:o?.context,content:o?.content,design:o?.design,defaults:o?.defaults,site:o?.site,category:o?.category,storeData:o?.storeData,globalDesign:o?.globalDesign,tileId:o?.tileId}}function _e(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{mount:(o,r)=>{g().init(n,r.context,r.data.content,r.data.design,r.data.defaults,r.data.externalContent,r.context.globalDesign,r.data.tileId),t?.mount?.(n,o,r),n.mount(o)},update:o=>{g().update(n,o.data.content,o.data.design,o.data.defaults,o.data.externalContent,o.context.globalDesign,o.data.tileId),t?.update?.(n,o)},unmount:()=>{t?.unmount?.(n),n.unmount()}}}}}function Re(e){const t={appName:"",blockName:"",version:"",scriptUrl:"",imageBuckets:{},globalDesign:{}};return{component:e,initState(n,o,r,i){g().init(n,t,o,r,i,{},{},void 0)},updateState(n,o,r,i){g().update(n,o,r,i,{},{},void 0)}}}function ye(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{render:async(o,r)=>(g().init(n,o,r.content,r.design,r.defaults,r.externalContent,o.globalDesign,r.tileId),t?.render?.(n,o,r),{html:await be(n,{context:o}),state:{context:o,data:r}})}}}}const Se={SOLID:"solid",GRADIENT:"gradient",NONE:"none"},$={SCROLL_TO_TILE:"SCROLL_TO_TILE",HYPER_LINK:"HYPER_LINK",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};m.enum(Object.values($));const he=$,M={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(M));const Ae=M,U={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(U));const Ne=U,P={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(P));const De=P,K={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values(K));const Ge=K,z={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values(z));const we=z,F={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(F));const xe=F;var X=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e[e.Layout=3]="Layout",e[e.Asset=4]="Asset",e[e.SharedFiles=5]="SharedFiles",e))(X||{}),Y=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e[e.PageTemplateDescriptor=6]="PageTemplateDescriptor",e[e.TemplateAsset=7]="TemplateAsset",e[e.Layout=8]="Layout",e[e.LayoutSettings=9]="LayoutSettings",e[e.LayoutAsset=10]="LayoutAsset",e[e.SlotServer=11]="SlotServer",e[e.SlotClient=12]="SlotClient",e[e.SharedTranslation=13]="SharedTranslation",e[e.CollectionDescriptor=14]="CollectionDescriptor",e[e.CollectionAsset=15]="CollectionAsset",e))(Y||{}),V=(e=>(e.SCROLL_TO_TILE="SCROLL_TO_TILE",e.HYPER_LINK="HYPER_LINK",e.MAIL_LINK="MAIL_LINK",e.TEL_LINK="TEL_LINK",e.GO_TO_STORE="GO_TO_STORE",e.GO_TO_STORE_LINK="GO_TO_STORE_LINK",e.GO_TO_PAGE="GO_TO_PAGE",e))(V||{});const I={TEXTAREA:"TEXTAREA",INPUTBOX:"INPUTBOX",SELECTBOX:"SELECTBOX",IMAGE:"IMAGE",TOGGLE:"TOGGLE",BUTTON:"BUTTON",DECK:"DECK",MENU:"MENU",NAVIGATION_MENU:"NAVIGATION_MENU",LOGO:"LOGO",INFO:"INFO",DIVIDER:"DIVIDER",PRODUCT_SELECTOR:"PRODUCT_SELECTOR",CATEGORY_SELECTOR:"CATEGORY_SELECTOR"};m.enum(Object.values(I));const j={TEXT:"TEXT",BUTTON:"BUTTON",IMAGE:"IMAGE",TOGGLE:"TOGGLE",SELECTBOX:"SELECTBOX",BACKGROUND:"BACKGROUND",COLOR_PICKER:"COLOR_PICKER",LOGO:"LOGO",DIVIDER:"DIVIDER",INFO:"INFO",ACCORDION:"ACCORDION"};m.enum(Object.values(j));const ke=j,W={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(W));const Be=W,H={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(H));const $e=H;class Me{type="STRUCTURED_COLOR";raw;hex;hsl;rgba;auto;constructor({raw:t,hex:n,hsl:o,rgba:r,auto:i}){this.raw=t,this.hex=n,this.hsl=o,this.rgba=r,this.auto=i}}function Ue(e){if(e!==void 0)return{...e,type:"STRUCTURED_COLOR"}}var J=(e=>(e.ORIGINAL="original",e.WEBP_LOW_RES="webp-200x200",e.WEBP_HI_2X_RES="webp-2000x2000",e.MOBILE_WEBP_LOW_RES="cropped-webp-100x200",e.MOBILE_WEBP_HI_RES="cropped-webp-1000x2000",e))(J||{}),q=(e=>(e.TILE_LOADED="tile-loaded",e.TILE_UNLOADED="tile-unloaded",e))(q||{});const Pe={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},Ke={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},ze={TOP_BAR:"TOP_BAR",GALLERY:"GALLERY",SIDEBAR:"SIDEBAR",DESCRIPTION:"DESCRIPTION",REVIEW_LIST:"REVIEW_LIST",RELATED_PRODUCTS:"RELATED_PRODUCTS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},Q={apparel_footwear:"apparel_footwear",vape_smoke:"vape_smoke",home_garden:"home_garden",sport_outdoor:"sport_outdoor",jewelry_accessories:"jewelry_accessories",pet_animals:"pet_animals",bikes:"bikes",health_beauty:"health_beauty",gift_shop:"gift_shop",electronics:"electronics",other:"other"};m.enum(Object.values(Q));const Fe=Q;function N(e,t="#000000"){return typeof e=="string"?e.startsWith("global.")?t:e:e&&e.hex?e.hex:t}function Xe(e,t,n){const o=e/255,r=t/255,i=n/255,l=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),s=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4),v=i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4);return .2126*l+.7152*s+.0722*v}function Ye(e){const t=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,"#$1$1$2$2$3$3"),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function Z(e){const t=Ye(e);return t?Xe(t.r,t.g,t.b)<=.5:!0}function ee(e,t="#808080",n="#FFFFFF"){return Z(e)?n:t}function Ve(e,t={}){const{defaultFont:n="inherit",defaultSize:o=16,defaultColor:r="#000000",defaultWeight:i="normal"}=t;if(e&&!e.visible)return{display:"none"};if(!e)return{fontFamily:n,fontSize:`${o}px`,color:r,fontWeight:i,fontStyle:"normal"};const l=e.size!==void 0?`${e.size}px`:`${o}px`,s=e.font||n,v=N(e.color,r),d=e.bold?"bold":i,c=e.italic?"italic":"normal";return{fontFamily:s,fontSize:l,color:v,fontWeight:d,fontStyle:c}}function te(e,t={}){const{direction:n="to right",fallbackColor:o=""}=t;if(!e?.background)return o?{backgroundColor:o}:{};const{background:r}=e;if(r.type==="solid"&&r.solid?.color)return{backgroundColor:N(r.solid.color,o)};if(r.type==="gradient"&&r.gradient){const{fromColor:i,toColor:l}=r.gradient,s=N(i,o),v=N(l,o);return s!==""&&v!==""?{backgroundImage:`linear-gradient(${n}, ${s}, ${v})`}:{}}return o?{backgroundColor:o}:{}}function je(e,t={}){return a(()=>te(e,t))}const We={small:{fontSize:"14px",padding:"8px 16px"},medium:{fontSize:"16px",padding:"10px 20px"},large:{fontSize:"18px",padding:"12px 24px"}};function He(e,t={}){const n={...We,...t.sizes};return a(()=>{if(!e?.visible)return{display:"none"};const o={fontFamily:e.font??"inherit",fontWeight:"400"},r=e.size??"medium",i=n[r]??n.medium;o.fontSize=i.fontSize,o.padding=i.padding;const l=N(e.color,"#000000"),s=e.appearance;switch(s){case"outline-button":o.backgroundColor="transparent",o.color=l,o.border=`2px solid ${l}`;break;case"text-link":o.backgroundColor="transparent",o.color=l,o.border="none",o.padding="0",o.textDecoration="none";break;case"solid-button":case void 0:default:o.backgroundColor=l,o.color=ee(l),o.border=`1px solid ${l}`;break}if(s!=="text-link")switch(e.style){case"pill":o.borderRadius="999px";break;case"round-corner":o.borderRadius="4px";break;case"rectangle":case void 0:default:o.borderRadius="0";break}else o.borderRadius="0";return o})}function ne(e){return!e||e.length===0?"en":e.find(t=>t.selected)?.code??e.find(t=>t.main)?.code??"en"}function Je(){const e=g(),t=a(()=>e.site?.value);return{currentLanguage:a(()=>ne(t.value?.languages))}}function qe(){return globalThis.window.instantsite}const S={HYPER_LINK:"HYPER_LINK",SCROLL_TO_TILE:"SCROLL_TO_TILE",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};function Qe(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Ze(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function et(e,t){if("pageUrl"in e)return e.pageUrl;const n=Ze(e);switch(n){case"products":return"/products";case"cart":return"/cart";case"account":return"/account";case"search":return"/search";case"home":return"/"}if(t){const o=t.find(r=>r.pageId===n);if(o)return o.url}return"/"}function tt(e){if("categoryId"in e)return e.categoryId}function nt(e){if(!e||e.length===0)return"";const t=e.find(n=>n.selected);return!t||t.main?"":`/${t.code}`}const oe=(e,t,n)=>{if(!e||t)return;const{type:o,link:r,email:i,phone:l}=e,s=g(),v=s.site?.value?.pages,d=s.site?.value?.languages,c=nt(d),u=et(e,v),O=tt(e);switch(o){case S.HYPER_LINK:if(r){const p=e.linkTarget??"_blank";return()=>window.open(r,p)}break;case S.GO_TO_STORE:case S.GO_TO_STORE_LINK:return()=>window.open(`${c}/products`,"_self");case S.GO_TO_CATEGORY:case S.GO_TO_CATEGORY_LINK:const h=n?.find(p=>p.id===O)?.url;return h===void 0?()=>window.open(`${c}/404`,"_self"):()=>window.open(h,"_self");case S.MAIL_LINK:if(i)return()=>window.open(`mailto:${i}`,"_self");break;case S.TEL_LINK:if(l)return()=>window.open(`tel:${l}`,"_self");break;case S.SCROLL_TO_TILE:if(typeof document<"u")return()=>{const p=Qe(e);document.getElementById(`tile-${p}`)?.scrollIntoView()};break;case S.GO_TO_PAGE:if(u)return()=>window.open(`${c}${u}`,"_self");break;default:console.error(`Unknown type of ActionLink: ${o}`)}};function re(e){if(!e||e.length===0)return[];const t=[];function n(o){if(t.push({id:o.id,name:o.name,url:o.urlPath}),o.children&&o.children.length>0)for(const r of o.children)n(r)}for(const o of e)n(o);return t}function ot(e){return"title"in e&&"type"in e}function rt(e,t,n,o){const r=a(()=>{const R=e.value[t];if(R!==void 0){if(ot(R))return R;throw new Error(`Element ${t} is not action link`)}}),i=a(()=>r.value?.title),l=a(()=>r.value?.type),s=a(()=>r.value?.link),v=a(()=>r.value?.email),d=a(()=>r.value?.phone),c=a(()=>r.value?.tileId?`tile-${r.value?.tileId}`:null),u=a(()=>r.value?.type==="GO_TO_STORE_LINK"?"products":r.value?.pageId),O=a(()=>r.value?.pageUrl),h=a(()=>!!i.value),p=a(()=>!!s.value),A=oe(r.value,n,o);return f({title:i,type:l,link:s,email:v,phone:d,tileDivId:c,pageId:u,pageUrl:O,hasTitle:h,hasLink:p,performAction:A})}function ae(e,t){const n=g(),o=a(()=>!!n.site?.value?.isPreviewMode),r=a(()=>{const l=n.category?.value?.categoryTree;return re(l)}),i=a(()=>t!==void 0?t:n.content.value!==void 0?n.content.value:{});return rt(i,e,o.value,r.value)}function ie({content:e,elementName:t,errorMessage:n,validatorFn:o}){return a(()=>{const r=e.value?.[t];if(r!==void 0){if(o(r))return r;throw new Error(n)}})}function at(e){return typeof e=="object"&&e!==null&&"categories"in e}function it(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function lt(e){return e!==void 0}function ut(e){return!!e?.trim()}function st({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:ut(t)?t:e}function ct(e,t){return lt(e)&&t}function le({itemId:e,id:t,alt:n,name:o,nameTranslated:r,customName:i,enabled:l,productsCount:s,url:v,imageUrl:d,thumbnailImageUrl:c,imageBorderInfo:u,selectionType:O}){return{itemId:e||t.toString(),id:t,alt:n,name:st({name:o,customName:i,selectionType:O}),nameTranslated:r,label:o,enabled:l,url:v,productsCount:s,imageUrl:d,thumbnailImageUrl:c,imageBorderInfo:u,showCategory:ct(t,l)}}function ue(e,t,n){const o=g(),r=a(()=>t!==void 0?t:o.content.value),i=ie({content:r,elementName:e,errorMessage:`Element ${e} is not a category selector type`,validatorFn:at}),l=a(()=>n??o.storeData?.value),s=a(()=>i.value?.categories.selectionType??"ROOT"),v=a(()=>l.value?.categories??[]),d=a(()=>i.value?.categories?.categoryIds??[]),c=a(()=>{const h=it(v);return s.value==="MANUAL"?i.value?.categories?.items?.flatMap(p=>{const A=h.value[p.id];return A?[le({...p,...A,selectionType:s.value})]:[]})??[]:l?.value?.categories.map(p=>le({...p,selectionType:s.value}))??[]}),u=a(()=>c.value.length>0),O=a(()=>c.value!==void 0&&c.value.length>0);return f({categories:c,categoryIds:d,hasContent:u,hasCategories:O})}function dt(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function se(e,t,n){const o=g(),r=a(()=>t!==void 0?t:o.content.value),i=ie({content:r,elementName:e,errorMessage:`Element ${e} is not a product selector type`,validatorFn:dt}),l=a(()=>n??o.storeData?.value),s=a(()=>i.value===void 0?"ALL":i.value.products?.selectionType??"MANUAL"),v=a(()=>i.value?.products?.productIds??[]),d=a(()=>i.value?.product?.id),c=a(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),u=a(()=>{if(s.value==="ALL")return l?.value?.products??[];if(s.value==="CATEGORY")return c.value===0?l?.value?.products.filter(R=>R?.defaultCategoryId===0)??[]:l?.value?.products.filter(R=>c.value&&R?.categoryIds?.includes(c.value))??[];const A=d.value?[d.value]:v.value??[];return l?.value?.products?.filter(R=>A.includes(R.id))??[]}),O=a(()=>l?.value?.categories.filter(A=>A.id===c?.value)??[]),h=a(()=>u.value.length>0),p=a(()=>u.value!==void 0&&u.value.length>0);return f({products:u,categories:O,categoryId:c,hasContent:h,hasProducts:p})}function vt(e){return"bucket"in e&&"set"in e}function D(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function gt(e,t){const n=a(()=>{const d=e.value[t];if(d!==void 0){if(vt(d))return d;throw new Error(`Element ${t} is not image`)}}),o=a(()=>n.value===void 0?"":g().context.value.imageBuckets?.[n.value?.bucket]),r=a(()=>n.value!==void 0),i=a(()=>D(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=a(()=>D(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),s=a(()=>D(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>D(n.value?.set?.["webp-2000x2000"]?.url,o.value));return f({hasContent:r,lowResolutionMobileImage:i,highResolutionMobileImage:l,lowResolutionDesktopImage:s,highResolutionDesktopImage:v})}function ce(e,t){const n=g(),o=a(()=>t!==void 0?t:n.content.value);return gt(o,e)}function ft(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not inputbox`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return f({hasContent:o,value:r})}function de(e,t){const n=g(),o=a(()=>t!==void 0?t:n.content.value);return ft(o,e)}function Ot(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not selectbox`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return f({hasContent:o,value:r})}function ve(e,t){const n=g(),o=a(()=>t!==void 0?t:n.content.value);return Ot(o,e)}function Et(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not textarea`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return f({hasContent:o,value:r})}function ge(e,t){const n=g(),o=a(()=>t!==void 0?t:n.content.value);return Et(o,e)}function pt(e){return"enabled"in e}function Tt(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(pt(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value?.enabled);return f({hasContent:o,value:r})}function fe(e,t){const n=g(),o=a(()=>t!==void 0?t:n.content.value);return Tt(o,e)}function Oe(e){if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.cards)&&t.cards.every(n=>typeof n.settings=="object"&&n.settings!==null)}function Ee(e,t,n,o){if(e==null)throw Error("Could not get a reactive ref for undefined Card");const r=e.settings[n];if(r===void 0)return r;switch(t){case I.TEXTAREA:return ge(n,e.settings);case I.INPUTBOX:return de(n,e.settings);case I.SELECTBOX:return ve(n,e.settings);case I.IMAGE:return ce(n,e.settings);case I.TOGGLE:return fe(n,e.settings);case I.BUTTON:return ae(n,e.settings);case I.CATEGORY_SELECTOR:return ue(n,e.settings,o);case I.PRODUCT_SELECTOR:return se(n,e.settings,o);case I.DECK:return mt(e,n,o);default:return}}function mt(e,t,n){const o=a(()=>{const l=e.settings[t];if(l!==void 0){if(Oe(l))return l;throw new Error(`Element ${t} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return f({hasContent:r,cards:i,getReactiveRef:(l,s,v)=>Ee(l,s,v,n)})}function It(e){const t=g(),n=a(()=>t.storeData?.value),o=a(()=>{const l=t.content.value[e];if(l!==void 0){if(Oe(l))return l;throw new Error(`Element ${e} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return f({hasContent:r,cards:i,getReactiveRef:(l,s,v)=>Ee(l,s,v,n.value)})}function Ct(e){return"type"in e&&("text"in e||"image"in e)}function G(e,t){const n=new RegExp(/^https?:\/\//);return e!==void 0&&n.test(e)?e:`${t}/${e}`}function Lt(){const e=g(),t=a(()=>{const l=e.content.value.logo;if(l!==void 0){if(Ct(l))return l;throw new Error("Element logo is not LOGO")}}),n=a(()=>t.value?.type),o=a(()=>t.value?.text),r=a(()=>t.value?.image===void 0?"":e.context.value.imageBuckets?.[t.value.image.bucket]),i=a(()=>({lowResolutionMobileImage:G(t.value?.image?.set?.["cropped-webp-100x200"]?.url,r.value),highResolutionMobileImage:G(t.value?.image?.set?.["cropped-webp-1000x2000"]?.url,r.value),lowResolutionDesktopImage:G(t.value?.image?.set?.["webp-200x200"]?.url,r.value),highResolutionDesktopImage:G(t.value?.image?.set?.["webp-2000x2000"]?.url,r.value)}));return f({type:n,text:o,image:i})}function bt(e){return e!==null&&"items"in e}function pe(e){const t=g(),n=a(()=>{const u=t.content.value[e];if(u!==void 0){if(bt(u))return u;throw new Error(`Element ${e} is not an menu`)}}),o=a(()=>!!t.site?.value?.isPreviewMode),r=a(()=>{const u=t.category?.value?.categoryTree;return re(u)}),i=a(()=>n.value!==void 0);function l(u){if(u)try{return new URL(u).pathname}catch{return u}}function s(u){return u?.map(O=>({...O,url:l(O.url)??O.url}))}const v=a(()=>s(r.value));function d(u){const O=oe(u,o.value,v.value);return{...u,performAction:O,nestedItems:u.nestedItems?.map(d)}}const c=a(()=>n.value?.items?n.value.items.map(d):[]);return f({hasContent:i,items:c})}const _t="menu";function Rt(){return pe(_t)}function yt(){return globalThis.craneSharedTranslation??{}}function St(){const e=g(),t=a(()=>e.site?.value),n=a(()=>yt()),o=a(()=>{const r=t.value?.languages;return r?r.find(i=>i.selected)?.code??r.find(i=>i.main)?.code??"en":"en"});return{t:r=>{const i=n.value;if(!i||Object.keys(i).length===0)return r;const l=o.value,s=i[l]?.[r];if(s!==void 0)return s;if(l!=="en"){const v=i.en?.[r];if(v!==void 0)return v}return r},currentLanguageCode:o}}function ht(e){const t=g(),n=a(()=>t.design.value[e]),o=a(()=>{const l=n.value?.items;return l!==void 0&&Object.keys(l).length>0}),r=a(()=>n.value?.items),i=a(()=>n.value?.sortable??!1);return f({hasItems:o,items:r,sortable:i})}function Te(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);return n===void 0?void 0:e.fontFamily?.[n]?.replaceAll("_"," ")}function w(e,t,n){return t?Te(e,t):Te(e,n)}function me(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.textSize?e.textSize[n]:void 0}function k(e,t,n){return t?me(e,t):me(e,n)}function Ie(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.color?e.color[n]:void 0}function C(e,t,n){return t?Ie(e,t):Ie(e,n)}function At(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:C(e,t?.color,n?.color)}}function Nt(e){const t=g(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e],l=t.globalDesign.value;return{background:{type:r?.background?.type??i?.background?.type,solid:{color:C(l,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:C(l,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:C(l,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return f({background:o})}function Dt(e){const t=g(),n=a(()=>{const d=t.design.value[e],c=t.defaults.value[e],u=t.globalDesign.value;return{appearance:d?.appearance??c?.appearance,font:w(u,d?.font,c?.font),size:d?.size??c?.size,style:d?.style??c?.style,color:C(u,d?.color,c?.color),visible:d?.visible??c?.visible??!1}}),o=a(()=>n.value?.appearance),r=a(()=>n.value?.font),i=a(()=>n.value?.size),l=a(()=>n.value?.style),s=a(()=>n.value?.color),v=a(()=>n.value?.visible);return f({appearance:o,font:r,size:i,style:l,color:s,visible:v.value??!1})}function Gt(e){const t=g(),n=a(()=>{const i=t.design.value[e],l=t.defaults.value[e],s=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??l?.overlay?.type,solid:{color:C(s,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:C(s,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:C(s,i?.overlay?.gradient?.toColor,l?.overlay?.gradient?.toColor)}},visible:i?.visible??l?.visible??!1}}),o=a(()=>n.value?.overlay),r=a(()=>n.value?.visible);return f({overlay:o,visible:r})}function wt(){const e=g(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return f({layout:n})}function xt(){const e=g();return a(()=>{const t=e.design.value.logo,n=e.defaults.value.logo,o=e.globalDesign.value;return{font:w(o,t?.font,n?.font),size:k(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:C(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:At(o,t?.frame,n?.frame)}})}function kt(e){const t=g(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{value:r?.value??i?.value}}),o=a(()=>n.value?.value);return f({value:o})}function Bt(e){const t=g(),n=a(()=>{const d=t.design.value[e],c=t.defaults.value[e],u=t.globalDesign.value;return{font:w(u,d?.font,c?.font),size:k(u,d?.size,c?.size),bold:d?.bold??c?.bold,italic:d?.italic??c?.italic,color:C(u,d?.color,c?.color),visible:d?.visible??c?.visible??!1}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),s=a(()=>n.value?.color),v=a(()=>n.value?.visible);return f({font:o,size:r,bold:i,italic:l,color:s,visible:v})}function $t(e){const t=g(),n=a(()=>{const c=t.design.value[e],u=t.defaults.value[e],O=t.globalDesign.value;return{font:w(O,c?.font,u?.font),size:k(O,c?.size,u?.size),bold:c?.bold??u?.bold,italic:c?.italic??u?.italic,color:C(O,c?.color,u?.color),visible:c?.visible??u?.visible??!1,whiteSpace:"pre-wrap"}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),s=a(()=>n.value?.color),v=a(()=>n.value?.visible),d=a(()=>n.value?.whiteSpace);return f({font:o,size:r,bold:i,italic:l,color:s,visible:v,whiteSpace:d})}function Mt(e){const t=g(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{enabled:r?.enabled??i?.enabled}}),o=a(()=>n.value?.enabled);return f({enabled:o})}const Ut={configuration:e=>({metadata:{...e.metadata},sections:[...e.sections]})};function E(e){return t=>{const{type:n}=t;return"type"in t?t:{type:e,...t}}}function T(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?E(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const Pt={inputbox:T("INPUTBOX"),textarea:T("TEXTAREA"),button:T("BUTTON"),image:T("IMAGE"),toggle:T("TOGGLE"),selectbox:T("SELECTBOX"),deck:T("DECK"),menu:T("MENU"),navigationMenu:T("NAVIGATION_MENU"),logo:T("LOGO"),productSelector:T("PRODUCT_SELECTOR"),categorySelector:T("CATEGORY_SELECTOR"),divider:T("DIVIDER"),info:T("INFO"),default:{inputbox:E("INPUTBOX"),textarea:E("TEXTAREA"),button:E("BUTTON"),selectbox:E("SELECTBOX"),image:E("IMAGE"),toggle:E("TOGGLE"),divider:E("DIVIDER"),info:E("INFO"),deck:E("DECK"),logo:E("LOGO"),menu:E("MENU"),navigationMenu:E("NAVIGATION_MENU"),productSelector:E("PRODUCT_SELECTOR"),categorySelector:E("CATEGORY_SELECTOR")}};function L(e){return t=>{const{type:n}=t;return"type"in t?t:{type:e,...t}}}function b(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?L(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const Kt={text:b("TEXT"),button:b("BUTTON"),image:b("IMAGE"),toggle:b("TOGGLE"),selectbox:b("SELECTBOX"),background:b("BACKGROUND"),colorPicker:b("COLOR_PICKER"),logo:b("LOGO"),divider:b("DIVIDER"),info:b("INFO"),accordion:b("ACCORDION"),default:{text:L("TEXT"),button:L("BUTTON"),image:L("IMAGE"),toggle:L("TOGGLE"),selectbox:L("SELECTBOX"),background:L("BACKGROUND"),colorPicker:L("COLOR_PICKER"),logo:L("LOGO"),accordion:L("ACCORDION"),info:L("INFO")}};function _(e){return t=>{const{type:n,defaults:o,...r}=t,i=o,l=i&&!("type"in i)?{...i,type:e}:o;return{type:e,...r,...l!==void 0?{defaults:l}:{}}}}const zt={init:e=>({...e}),designOverride:{text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),divider:_("DIVIDER"),info:_("INFO"),accordion:_("ACCORDION")}},Ft={init:e=>e},Xt={configuration:e=>({...e}),page:e=>({...e})},Yt={default:e=>{const{type:t,...n}=e;return{type:"default",...n}},custom:e=>{const{type:t,...n}=e;return{type:"custom",...n}},store:(e={})=>{const{type:t,...n}=e;return{type:"store",...n}}},Vt={init:e=>({...e})};export{V as ActionLinkTypeEnum,we as BackgroundStyleEnum,Ne as ButtonAppearanceEnum,Ge as ButtonShapeEnum,De as ButtonSizeEnum,he as ButtonTypeEnum,Pe as CatalogLayoutSlot,Ke as CategoryLayoutSlot,Me as Color,Y as ConfigTypeEnum,ke as DesignEditorType,I as EditorTypes,J as ImageSet,q as InstantsiteJsEvent,$e as LogoTypeEnum,Se as OverlayType,Ae as OverlayTypeEnum,X as PluginTypeEnum,ze as ProductLayoutSlot,xe as SectionTypeEnum,Fe as TemplateCategoriesList,Be as ValidationTypeEnum,Ue as asStructuredColor,Ut as collection,Pt as content,Re as createLayoutApp,Ve as createTextStyle,_e as createVueClientApp,ye as createVueServerApp,Kt as design,te as getBackgroundStyle,N as getColorHex,ee as getContrastTextColor,ne as getCurrentLanguageCode,Z as isColorDark,zt as layout,Yt as section,Ft as showcase,Xt as template,Vt as translation,ht as useAccordionElementDesign,Nt as useBackgroundElementDesign,je as useBackgroundStyle,ae as useButtonElementContent,Dt as useButtonElementDesign,He as useButtonStyles,ue as useCategorySelectorElementContent,Je as useCurrentLanguage,It as useDeckElementContent,ce as useImageElementContent,Gt as useImageElementDesign,de as useInputboxElementContent,qe as useInstantsiteJsApi,wt as useLayoutElementDesign,Lt as useLogoElementContent,xt as useLogoElementDesign,pe as useMenuElementContent,Rt as useNavigationMenuElementContent,se as useProductSelectorElementContent,ve as useSelectboxElementContent,kt as useSelectboxElementDesign,Bt as useTextElementDesign,ge as useTextareaElementContent,$t as useTextareaElementDesign,fe as useToggleElementContent,Mt as useToggleElementDesign,St as useTranslation,g as useVueBaseProps};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/crane-api",
3
- "version": "2.3.3-rc.0",
3
+ "version": "2.3.3-rc.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",