@lightspeed/crane-api 2.2.1 → 2.3.1

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 Ee,getCurrentInstance as ge,ref as y,computed as r,reactive as E}from"vue";import{renderToString as Te}from"vue/server-renderer";import{z as m}from"zod";function M(e){return{app:Ee(e)}}const w=new Map;function O(){const e=(a,i,l,d,v,c,s,u)=>{w.set(a._uid,{context:y(i),content:y(l),design:y(d),defaults:y(v),site:y(c?.site??{}),category:y(c?.category),storeData:y(c?.storeData),globalDesign:y(s),tileId:y(u??void 0)})},t=(a,i,l,d,v,c,s)=>{const u=w.get(a._uid);u!==void 0&&(u.content.value=i,u.design.value=l,u.defaults.value=d,u.site.value=v.site??{},u.category.value=v.category,u.globalDesign.value=c,u.storeData.value=v.storeData,u.tileId.value=s)},n=ge()?.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 fe(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{mount:(o,a)=>{O().init(n,a.context,a.data.content,a.data.design,a.data.defaults,a.data.externalContent,a.context.globalDesign,a.data.tileId),t?.mount?.(n,o,a),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 pe(){return globalThis.window.instantsite}function me(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{render:async(o,a)=>(O().init(n,o,a.content,a.design,a.defaults,a.externalContent,o.globalDesign,a.tileId),t?.render?.(n,o,a),{html:await Te(n,{context:o}),state:{context:o,data:a}})}}}}const U={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(U));const Ie=U,x={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(x));const Le=x,P={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(P));const _e=P,k={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(k));const Ce=k,$={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values($));const Re=$,K={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values(K));const be=K,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(X));const ye=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 R={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(R));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 Se=V,j={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(j));const Ae=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(W));const Ge=W;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 Ne={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},De={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},he={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 we=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 a of o.children)n(a)}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 Be(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Me(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Ue(e,t){if("pageUrl"in e)return e.pageUrl;const n=Me(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(a=>a.pageId===n);if(o)return o.url}return"/"}function xe(e){if("categoryId"in e)return e.categoryId}function Pe(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:a,email:i,phone:l}=e,d=O(),v=d.site?.value?.pages,c=d.site?.value?.languages,s=Pe(c),u=Ue(e,v),g=xe(e);switch(o){case S.HYPER_LINK:if(a){const f=e.linkTarget??"_blank";return()=>window.open(a,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=Be(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 ke(e){return"title"in e&&"type"in e}function $e(e,t,n,o){const a=r(()=>{const b=e.value[t];if(b!==void 0){if(ke(b))return b;throw new Error(`Element ${t} is not action link`)}}),i=r(()=>a.value?.title),l=r(()=>a.value?.type),d=r(()=>a.value?.link),v=r(()=>a.value?.email),c=r(()=>a.value?.phone),s=r(()=>a.value?.tileId?`tile-${a.value?.tileId}`:null),u=r(()=>a.value?.type==="GO_TO_STORE_LINK"?"products":a.value?.pageId),g=r(()=>a.value?.pageUrl),A=r(()=>!!i.value),f=r(()=>!!d.value),G=Z(a.value,n,o);return E({title:i,type:l,link:d,email:v,phone:c,tileDivId:s,pageId:u,pageUrl:g,hasTitle:A,hasLink:f,performAction:G})}function ee(e,t){const n=O(),o=r(()=>!!n.site?.value?.isPreviewMode),a=r(()=>{const l=n.category?.value?.categoryTree;return Q(l)}),i=r(()=>t!==void 0?t:n.content.value!==void 0?n.content.value:{});return $e(i,e,o.value,a.value)}function te({content:e,elementName:t,errorMessage:n,validatorFn:o}){return r(()=>{const a=e.value?.[t];if(a!==void 0){if(o(a))return a;throw new Error(n)}})}function Ke(e){return typeof e=="object"&&e!==null&&"categories"in e}function Xe(e){return r(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function ze(e){return e!==void 0}function Fe(e){return!!e?.trim()}function Ye({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:Fe(t)?t:e}function Ve(e,t){return ze(e)&&t}function ne({itemId:e,id:t,alt:n,name:o,nameTranslated:a,customName:i,enabled:l,productsCount:d,url:v,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,selectionType:g}){return{itemId:e||t.toString(),id:t,alt:n,name:Ye({name:o,customName:i,selectionType:g}),nameTranslated:a,label:o,enabled:l,url:v,productsCount:d,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,showCategory:Ve(t,l)}}function oe(e,t,n){const o=O(),a=r(()=>t!==void 0?t:o.content.value),i=te({content:a,elementName:e,errorMessage:`Element ${e} is not a category selector type`,validatorFn:Ke}),l=r(()=>n??o.storeData?.value),d=r(()=>i.value?.categories.selectionType??"ROOT"),v=r(()=>l.value?.categories??[]),c=r(()=>i.value?.categories?.categoryIds??[]),s=r(()=>{const A=Xe(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const G=A.value[f.id];return ne({...f,...G,selectionType:d.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:d.value}))??[]}),u=r(()=>i.value!==void 0),g=r(()=>s.value!==void 0&&s.value.length>0);return E({categories:s,categoryIds:c,hasContent:u,hasCategories:g})}function je(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function re(e,t,n){const o=O(),a=r(()=>t!==void 0?t:o.content.value),i=te({content:a,elementName:e,errorMessage:`Element ${e} is not a product selector type`,validatorFn:je}),l=r(()=>n??o.storeData?.value),d=r(()=>i.value?.products?.selectionType??"MANUAL"),v=r(()=>i.value?.products?.productIds??[]),c=r(()=>i.value?.product?.id),s=r(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),u=r(()=>{if(d.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 G=c.value?[c.value]:v.value??[];return l?.value?.products?.filter(b=>G.includes(b.id))??[]}),g=r(()=>l?.value?.categories.filter(G=>G.id===s?.value)??[]),A=r(()=>i.value!==void 0&&u.value.length>0),f=r(()=>u.value!==void 0&&u.value.length>0);return E({products:u,categories:g,categoryId:s,hasContent:A,hasProducts:f})}function We(e){return"bucket"in e&&"borderInfo"in e&&"set"in e}function N(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function He(e,t){const n=r(()=>{const c=e.value[t];if(c!==void 0){if(We(c))return c;throw new Error(`Element ${t} is not image`)}}),o=r(()=>n.value===void 0?"":O().context.value.imageBuckets?.[n.value?.bucket]),a=r(()=>n.value!==void 0),i=r(()=>N(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=r(()=>N(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),d=r(()=>N(n.value?.set?.["webp-200x200"]?.url,o.value)),v=r(()=>N(n.value?.set?.["webp-2000x2000"]?.url,o.value));return E({hasContent:a,lowResolutionMobileImage:i,highResolutionMobileImage:l,lowResolutionDesktopImage:d,highResolutionDesktopImage:v})}function ae(e,t){const n=O(),o=r(()=>t!==void 0?t:n.content.value);return He(o,e)}function Je(e,t){const n=r(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not inputbox`)}}),o=r(()=>n.value!==void 0&&n.value.length>0),a=r(()=>n.value);return E({hasContent:o,value:a})}function ie(e,t){const n=O(),o=r(()=>t!==void 0?t:n.content.value);return Je(o,e)}function qe(e,t){const n=r(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not selectbox`)}}),o=r(()=>n.value!==void 0),a=r(()=>n.value);return E({hasContent:o,value:a})}function le(e,t){const n=O(),o=r(()=>t!==void 0?t:n.content.value);return qe(o,e)}function Qe(e,t){const n=r(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not textarea`)}}),o=r(()=>n.value!==void 0),a=r(()=>n.value);return E({hasContent:o,value:a})}function ue(e,t){const n=O(),o=r(()=>t!==void 0?t:n.content.value);return Qe(o,e)}function Ze(e){return"enabled"in e}function et(e,t){const n=r(()=>{const i=e.value[t];if(i!==void 0){if(Ze(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=r(()=>n.value!==void 0),a=r(()=>n.value?.enabled);return E({hasContent:o,value:a})}function se(e,t){const n=O(),o=r(()=>t!==void 0?t:n.content.value);return et(o,e)}function tt(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 nt(e,t,n,o){if(e==null)throw Error("Could not get a reactive ref for undefined Card");const a=e.settings[n];if(a===void 0)return a;switch(t){case R.TEXTAREA:return ue(n,e.settings);case R.INPUTBOX:return ie(n,e.settings);case R.SELECTBOX:return le(n,e.settings);case R.IMAGE:return ae(n,e.settings);case R.TOGGLE:return se(n,e.settings);case R.BUTTON:return ee(n,e.settings);case R.CATEGORY_SELECTOR:return oe(n,e.settings,o);case R.PRODUCT_SELECTOR:return re(n,e.settings,o);default:return}}function ot(e){const t=O(),n=r(()=>t.storeData?.value),o=r(()=>{const l=t.content.value[e];if(l!==void 0){if(tt(l))return l;throw new Error(`Element ${e} is not of DECK type`)}}),a=r(()=>o.value!==void 0&&o.value.cards.length>0),i=r(()=>o.value?.cards);return E({hasContent:a,cards:i,getReactiveRef:(l,d,v)=>nt(l,d,v,n.value)})}function rt(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 at(){const e=O(),t=r(()=>{const l=e.content.value.logo;if(l!==void 0){if(rt(l))return l;throw new Error("Element logo is not LOGO")}}),n=r(()=>t.value?.type),o=r(()=>t.value?.text),a=r(()=>t.value?.image===void 0?"":e.context.value.imageBuckets?.[t.value.image.bucket]),i=r(()=>({lowResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-100x200"]?.url,a.value),highResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-1000x2000"]?.url,a.value),lowResolutionDesktopImage:D(t.value?.image?.set?.["webp-200x200"]?.url,a.value),highResolutionDesktopImage:D(t.value?.image?.set?.["webp-2000x2000"]?.url,a.value)}));return E({type:n,text:o,image:i})}function it(e){return e!==null&&"items"in e}function ce(e){const t=O(),n=r(()=>{const u=t.content.value[e];if(u!==void 0){if(it(u))return u;throw new Error(`Element ${e} is not an menu`)}}),o=r(()=>!!t.site?.value?.isPreviewMode),a=r(()=>{const u=t.category?.value?.categoryTree;return Q(u)}),i=r(()=>n.value!==void 0);function l(u){if(u)try{return new URL(u).pathname}catch{return u}}function d(u){return u?.map(g=>({...g,url:l(g.url)??g.url}))}const v=r(()=>d(a.value));function c(u){const g=Z(u,o.value,v.value);return{...u,performAction:g,nestedItems:u.nestedItems?.map(c)}}const s=r(()=>n.value?.items?n.value.items.map(c):[]);return E({hasContent:i,items:s})}const lt="menu";function ut(){return ce(lt)}function st(){return globalThis.craneSharedTranslation??{}}function ct(){const e=O(),t=r(()=>e.site?.value),n=r(()=>st()),o=r(()=>{const a=t.value?.languages;return a?a.find(i=>i.selected)?.code??a.find(i=>i.main)?.code??"en":"en"});return{t:a=>{const i=n.value;if(!i||Object.keys(i).length===0)return a;const l=o.value,d=i[l]?.[a];if(d!==void 0)return d;if(l!=="en"){const v=i.en?.[a];if(v!==void 0)return v}return a},currentLanguageCode:o}}function dt(e){const t=O(),n=r(()=>t.design.value[e]),o=r(()=>{const l=n.value?.items;return l!==void 0&&Object.keys(l).length>0}),a=r(()=>n.value?.items),i=r(()=>n.value?.sortable??!1);return E({hasItems:o,items:a,sortable:i})}function de(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);if(n!==void 0)return e.fontFamily?e.fontFamily[n].replaceAll("_"," "):void 0}function h(e,t,n){return t?de(e,t):de(e,n)}function ve(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 B(e,t,n){return t?ve(e,t):ve(e,n)}function Oe(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 I(e,t,n){return t?Oe(e,t):Oe(e,n)}function vt(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:I(e,t?.color,n?.color)}}function Ot(e){const t=O(),n=r(()=>{const a=t.design.value[e],i=t.defaults.value[e],l=t.globalDesign.value;return{background:{type:a?.background?.type??i?.background?.type,solid:{color:I(l,a?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:I(l,a?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:I(l,a?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=r(()=>n.value?.background);return E({background:o})}function Et(e){const t=O(),n=r(()=>{const c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{appearance:c?.appearance??s?.appearance,font:h(u,c?.font,s?.font),size:c?.size??s?.size,style:c?.style??s?.style,color:I(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=r(()=>n.value?.appearance),a=r(()=>n.value?.font),i=r(()=>n.value?.size),l=r(()=>n.value?.style),d=r(()=>n.value?.color),v=r(()=>n.value?.visible);return E({appearance:o,font:a,size:i,style:l,color:d,visible:v})}function gt(e){const t=O(),n=r(()=>{const i=t.design.value[e],l=t.defaults.value[e],d=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??l?.overlay?.type,solid:{color:I(d,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:I(d,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:I(d,i?.overlay?.gradient?.toColor,l?.overlay?.gradient?.toColor)}},visible:i?.visible??l?.visible??!1}}),o=r(()=>n.value?.overlay),a=r(()=>n.value?.visible);return E({overlay:o,visible:a})}function Tt(){const e=O(),t=r(()=>e.design.value.layout),n=r(()=>t.value);return E({layout:n})}function ft(){const e=O();return r(()=>{const t=e.design.value.logo,n=e.defaults.value.logo,o=e.globalDesign.value;return{font:h(o,t?.font,n?.font),size:B(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:I(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:vt(o,t?.frame,n?.frame)}})}function pt(e){const t=O(),n=r(()=>{const a=t.design.value[e],i=t.defaults.value[e];return{value:a?.value??i?.value}}),o=r(()=>n.value?.value);return E({value:o})}function mt(e){const t=O(),n=r(()=>{const c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{font:h(u,c?.font,s?.font),size:B(u,c?.size,s?.size),bold:c?.bold??s?.bold,italic:c?.italic??s?.italic,color:I(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=r(()=>n.value?.font),a=r(()=>n.value?.size),i=r(()=>n.value?.bold),l=r(()=>n.value?.italic),d=r(()=>n.value?.color),v=r(()=>n.value?.visible);return E({font:o,size:a,bold:i,italic:l,color:d,visible:v})}function It(e){const t=O(),n=r(()=>{const s=t.design.value[e],u=t.defaults.value[e],g=t.globalDesign.value;return{font:h(g,s?.font,u?.font),size:B(g,s?.size,u?.size),bold:s?.bold??u?.bold,italic:s?.italic??u?.italic,color:I(g,s?.color,u?.color),visible:s?.visible??u?.visible??!1,whiteSpace:"pre-wrap"}}),o=r(()=>n.value?.font),a=r(()=>n.value?.size),i=r(()=>n.value?.bold),l=r(()=>n.value?.italic),d=r(()=>n.value?.color),v=r(()=>n.value?.visible),c=r(()=>n.value?.whiteSpace);return E({font:o,size:a,bold:i,italic:l,color:d,visible:v,whiteSpace:c})}function Lt(e){const t=O(),n=r(()=>{const a=t.design.value[e],i=t.defaults.value[e];return{enabled:a?.enabled??i?.enabled}}),o=r(()=>n.value?.enabled);return E({enabled:o})}function T(e){return t=>"type"in t?t:{type:e,...t}}function p(e){return t=>{const{type:n,defaults:o,...a}=t,i=o?T(e)(o):void 0;return{type:e,...a,...i!==void 0?{defaults:i}:{}}}}const _t={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 L(e){return t=>"type"in t?t:{type:e,...t}}function _(e){return t=>{const{type:n,defaults:o,...a}=t,i=o?L(e)(o):void 0;return{type:e,...a,...i!==void 0?{defaults:i}:{}}}}const Ct={text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),divider:_("DIVIDER"),info:_("INFO"),accordion:_("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 C(e){return t=>{const{type:n,defaults:o,...a}=t,i=o,l=i&&!("type"in i)?{...i,type:e}:o;return{type:e,...a,...l!==void 0?{defaults:l}:{}}}}const Rt={init:e=>({...e}),designOverride:{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")}},bt={init:e=>e},yt={configuration:e=>({...e}),page:e=>({...e})},St={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}}},At={init:e=>({...e})};export{Y as ActionLinkTypeEnum,be as BackgroundStyleEnum,_e as ButtonAppearanceEnum,Re as ButtonShapeEnum,Ce as ButtonSizeEnum,Ie as ButtonTypeEnum,Ne as CatalogLayoutSlot,De as CategoryLayoutSlot,F as ConfigTypeEnum,Se as DesignEditorType,R as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,Ge as LogoTypeEnum,Le as OverlayTypeEnum,z as PluginTypeEnum,he as ProductLayoutSlot,ye as SectionTypeEnum,we as TemplateCategoriesList,Ae as ValidationTypeEnum,_t as content,fe as createVueClientApp,me as createVueServerApp,Ct as design,Rt as layout,St as section,bt as showcase,yt as template,At as translation,dt as useAccordionElementDesign,Ot as useBackgroundElementDesign,ee as useButtonElementContent,Et as useButtonElementDesign,oe as useCategorySelectorElementContent,ot as useDeckElementContent,ae as useImageElementContent,gt as useImageElementDesign,ie as useInputboxElementContent,pe as useInstantsiteJsApi,Tt as useLayoutElementDesign,at as useLogoElementContent,ft as useLogoElementDesign,ce as useMenuElementContent,ut as useNavigationMenuElementContent,re as useProductSelectorElementContent,le as useSelectboxElementContent,pt as useSelectboxElementDesign,mt as useTextElementDesign,ue as useTextareaElementContent,It as useTextareaElementDesign,se as useToggleElementContent,Lt as useToggleElementDesign,ct as useTranslation,O as useVueBaseProps};
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,d,v,c,s,u)=>{w.set(r._uid,{context:y(i),content:y(l),design:y(d),defaults:y(v),site:y(c?.site??{}),category:y(c?.category),storeData:y(c?.storeData),globalDesign:y(s),tileId:y(u??void 0)})},t=(r,i,l,d,v,c,s)=>{const u=w.get(r._uid);u!==void 0&&(u.content.value=i,u.design.value=l,u.defaults.value=d,u.site.value=v.site??{},u.category.value=v.category,u.globalDesign.value=c,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,d=O(),v=d.site?.value?.pages,c=d.site?.value?.languages,s=Fe(c),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),d=a(()=>r.value?.link),v=a(()=>r.value?.email),c=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(()=>!!d.value),N=Z(r.value,n,o);return E({title:i,type:l,link:d,email:v,phone:c,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:d,url:v,imageUrl:c,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:d,imageUrl:c,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),d=a(()=>i.value?.categories.selectionType??"ROOT"),v=a(()=>l.value?.categories??[]),c=a(()=>i.value?.categories?.categoryIds??[]),s=a(()=>{const A=We(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const N=A.value[f.id];return ne({...f,...N,selectionType:d.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:d.value}))??[]}),u=a(()=>i.value!==void 0),g=a(()=>s.value!==void 0&&s.value.length>0);return E({categories:s,categoryIds:c,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),d=a(()=>i.value?.products?.selectionType??"MANUAL"),v=a(()=>i.value?.products?.productIds??[]),c=a(()=>i.value?.product?.id),s=a(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),u=a(()=>{if(d.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=c.value?[c.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 c=e.value[t];if(c!==void 0){if(et(c))return c;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)),d=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:d,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,d,v)=>de(l,d,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,d,v)=>de(l,d,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 d(u){return u?.map(g=>({...g,url:l(g.url)??g.url}))}const v=a(()=>d(r.value));function c(u){const g=Z(u,o.value,v.value);return{...u,performAction:g,nestedItems:u.nestedItems?.map(c)}}const s=a(()=>n.value?.items?n.value.items.map(c):[]);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,d=i[l]?.[r];if(d!==void 0)return d;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 c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{appearance:c?.appearance??s?.appearance,font:h(u,c?.font,s?.font),size:c?.size??s?.size,style:c?.style??s?.style,color:L(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.appearance),r=a(()=>n.value?.font),i=a(()=>n.value?.size),l=a(()=>n.value?.style),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return E({appearance:o,font:r,size:i,style:l,color:d,visible:v.value??!1})}function It(e){const t=O(),n=a(()=>{const i=t.design.value[e],l=t.defaults.value[e],d=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??l?.overlay?.type,solid:{color:L(d,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:L(d,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:L(d,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 c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{font:h(u,c?.font,s?.font),size:U(u,c?.size,s?.size),bold:c?.bold??s?.bold,italic:c?.italic??s?.italic,color:L(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return E({font:o,size:r,bold:i,italic:l,color:d,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),d=a(()=>n.value?.color),v=a(()=>n.value?.visible),c=a(()=>n.value?.whiteSpace);return E({font:o,size:r,bold:i,italic:l,color:d,visible:v,whiteSpace:c})}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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/crane-api",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -41,12 +41,12 @@
41
41
  "eslint": "^9.33.0",
42
42
  "jest": "^30.0.4",
43
43
  "ts-jest": "^29.4.0",
44
- "typescript": "5.9.2",
44
+ "typescript": "5.9.3",
45
45
  "unbuild": "^3.5.0",
46
46
  "vue": "^3.3.4"
47
47
  },
48
48
  "dependencies": {
49
- "zod": "4.1.13"
49
+ "zod": "4.3.6"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "vue": "^3.3.4"
package/types.d.ts CHANGED
@@ -115,35 +115,35 @@ interface LogoContentData {
115
115
  readonly image: ImageContentData;
116
116
  }
117
117
 
118
- type GlobalColorsString
119
- = 'global.color.title'
120
- | 'global.color.body'
121
- | 'global.color.button'
122
- | 'global.color.link'
123
- | 'global.color.background';
124
-
125
- type GlobalFontsString
126
- = 'global.fontFamily.title'
127
- | 'global.fontFamily.body';
128
-
129
- type GlobalTextSizeString
130
- = 'global.textSize.title'
131
- | 'global.textSize.subtitle'
132
- | 'global.textSize.body';
133
-
134
- interface HSLColor {
135
- h: number;
136
- s: number;
137
- l: number;
138
- a: number;
139
- }
140
-
141
- interface RGBAColor {
142
- r: number;
143
- g: number;
144
- b: number;
145
- a: number;
146
- }
118
+ /**
119
+ * This type is added for backward compatibility and will be removed in the future.
120
+ * Import the same type from '@lightspeed/crane-api' directly.
121
+ */
122
+ type GlobalColorsString = import('./dist').GlobalColorsString;
123
+
124
+ /**
125
+ * This type is added for backward compatibility and will be removed in the future.
126
+ * Import the same type from '@lightspeed/crane-api' directly.
127
+ */
128
+ type GlobalFontsString = import('./dist').GlobalFontsString;
129
+
130
+ /**
131
+ * This type is added for backward compatibility and will be removed in the future.
132
+ * Import the same type from '@lightspeed/crane-api' directly.
133
+ */
134
+ type GlobalTextSizeString = import('./dist').GlobalTextSizeString;
135
+
136
+ /**
137
+ * This type is added for backward compatibility and will be removed in the future.
138
+ * Import the same type from '@lightspeed/crane-api' directly.
139
+ */
140
+ type HSLColor = import('./dist').HSLColor;
141
+
142
+ /**
143
+ * This type is added for backward compatibility and will be removed in the future.
144
+ * Import the same type from '@lightspeed/crane-api' directly.
145
+ */
146
+ type RGBAColor = import('./dist').RGBAColor;
147
147
 
148
148
  // Note: We should check if RGBAColor has abbreviations or full names
149
149
  interface RGBAColorNamed {
@@ -153,29 +153,30 @@ interface RGBAColorNamed {
153
153
  alpha: number;
154
154
  }
155
155
 
156
- interface Color {
157
- raw: string;
158
- hex: string;
159
- hsl: HSLColor;
160
- rgba: RGBAColor;
161
- auto?: boolean;
162
- }
156
+ /**
157
+ * This type is added for backward compatibility and will be removed in the future.
158
+ * Import the same type from '@lightspeed/crane-api' directly.
159
+ */
160
+ type Color = import('./dist').Color;
163
161
 
164
- interface SolidColor {
165
- color: Color | GlobalColorsString | undefined;
166
- }
162
+ /**
163
+ * This type is added for backward compatibility and will be removed in the future.
164
+ * Import the same type from '@lightspeed/crane-api' directly.
165
+ */
166
+ type SolidColor = import('./dist').SolidColor;
167
167
 
168
- interface GradientColor {
169
- fromColor: Color | GlobalColorsString | undefined;
170
- toColor: Color | GlobalColorsString | undefined;
171
- }
168
+ /**
169
+ * This type is added for backward compatibility and will be removed in the future.
170
+ * Import the same type from '@lightspeed/crane-api' directly.
171
+ */
172
+ type GradientColor = import('./dist').GradientColor;
172
173
 
173
174
  interface TextDesignData {
174
- font: string | GlobalFontsString | undefined;
175
- size: number | GlobalTextSizeString | undefined;
175
+ font: string | undefined;
176
+ size: number | undefined;
176
177
  bold: boolean | undefined;
177
178
  italic: boolean | undefined;
178
- color: Color | GlobalColorsString | undefined;
179
+ color: Color | undefined;
179
180
  visible: boolean;
180
181
  }
181
182
 
@@ -191,15 +192,15 @@ type CapitalizationType
191
192
  interface Frame {
192
193
  visible: boolean;
193
194
  width: number | undefined;
194
- color: Color | GlobalColorsString | undefined;
195
+ color: Color | undefined;
195
196
  }
196
197
 
197
198
  interface LogoDesignData {
198
- font: string | GlobalFontsString | undefined;
199
- size: number | GlobalTextSizeString | undefined;
199
+ font: string | undefined;
200
+ size: number | undefined;
200
201
  bold: boolean | undefined;
201
202
  italic: boolean | undefined;
202
- color: Color | GlobalColorsString | undefined;
203
+ color: Color | undefined;
203
204
  visible: boolean;
204
205
  spacing: number | undefined;
205
206
  capitalization: CapitalizationType | undefined;
@@ -223,17 +224,15 @@ type ButtonStyle
223
224
 
224
225
  interface ButtonDesignData {
225
226
  appearance: ButtonAppearance | undefined;
226
- font: string | GlobalFontsString | undefined;
227
+ font: string | undefined;
227
228
  size: ButtonSize | undefined;
228
229
  style: ButtonStyle | undefined;
229
- color: Color | GlobalColorsString | undefined;
230
+ color: Color | undefined;
230
231
  visible: boolean;
231
232
  }
232
233
 
233
- type OverlayType
234
- = 'solid'
235
- | 'gradient'
236
- | 'none';
234
+ declare const OverlayType: typeof import('./dist')['OverlayType'];
235
+ type OverlayType = import('./dist')['OverlayType'];
237
236
 
238
237
  interface Overlay {
239
238
  type: OverlayType | undefined;
@@ -301,6 +300,7 @@ interface MadeWith {
301
300
  readonly url: string | undefined;
302
301
  readonly target: string | undefined;
303
302
  readonly icon: string | undefined;
303
+ readonly iconSvg: string | undefined;
304
304
  readonly poweredBy: string | undefined;
305
305
  readonly company: string | undefined;
306
306
  }
@@ -339,6 +339,7 @@ interface SiteContent {
339
339
  readonly isPreviewMode: boolean;
340
340
  readonly reportAbuse?: ReportAbuse;
341
341
  readonly madeWith?: MadeWith;
342
+ readonly madeWithV2?: MadeWith;
342
343
  readonly languages?: Language[];
343
344
  readonly account?: Account;
344
345
  readonly cart?: Cart;