@swell/apps-sdk 1.0.75 → 1.0.76

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.js CHANGED
@@ -932,7 +932,7 @@
932
932
  </clipPath>
933
933
  </defs>
934
934
  </svg>
935
- `;var pt={image:I2,"product-1":A2,"product-2":b2,"product-3":T2,"product-4":_2,"product-5":M2,"product-6":E2,"collection-1":v2,"collection-2":D2,"collection-3":P2,"collection-4":x2,"collection-5":R2,"collection-6":j2,"lifestyle-1":Z2,"lifestyle-2":N2,"product-apparel-1":F2,"product-apparel-2":H2,"product-apparel-3":B2,"product-apparel-4":q2,"collection-apparel-1":G2,"collection-apparel-2":V2,"collection-apparel-3":O2,"collection-apparel-4":U2,"hero-apparel-1":$2,"hero-apparel-2":K2,"hero-apparel-3":z2,"blog-apparel-1":W2,"blog-apparel-2":J2,"blog-apparel-3":Y2,"detailed-apparel-1":Q2},X2=pt;function f5(n){return e=>{let t=X2[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function g5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var ft={asset_url:Z4,brightness_difference:N4,color_brightness:I4,color_contrast:F4,color_darken:H4,color_desaturate:B4,color_difference:q4,color_extract:G4,color_lighten:V4,color_mix:O4,color_modify:U4,color_saturate:$4,color_to_hex:K4,color_to_hsl:z4,color_to_rgb:W4,date:k3,default_errors:Y4,divided_by:Q4,font_face:X4,font_modify:e5,font_url:t5,format_address:y2,image_tag:i5,image_url:k2,inline_asset_content:n5,json:r5,json_pretty:a5,money:o5,money_with_currency:s5,money_without_currency:l5,money_without_trailing_zeros:h5,stylesheet_tag:d5,time_tag:c5,translate:U3,t:U3,where:u5,hex_to_rgba:C5,item_count_for_variant:L2,payment_button:m5,payment_terms:p5,placeholder_svg_tag:f5,inline_editable:g5};function t1(n){(0,e1.each)(ft,(e,t)=>{if(typeof e=="function")n.engine.registerFilter(t,e(n));else if(typeof e.bind=="function"){let{bind:i,resolve:r}=e;n.engine.registerFilter(t,gt(n,i,r))}})}function gt(n,e,t=[]){let i=e(n);return Array.isArray(t)?async(...r)=>{let a=await Promise.all(r.map((o,s)=>Array.isArray(t[s])||t[s]===!0?i1(o,t[s]):o));return i(...a)}:i}async function i1(n,e){if(!n)return n;let t=n;P(t)&&(t=await t);try{if(Array.isArray(e))for(let i of e){if(typeof i!="string")continue;let[r,...a]=i.split("."),o=t[r];P(o)?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await i1(t[r],[a.join(".")]))}}catch{}return t}var n1=S("liquidjs");var r1={...n1.defaultOperators,"==":a1};function a1(n,e){return w3(n)?n.equals(e):w3(e)?e.equals(n):(n=Y(n),e=Y(e),l3(n)?l3(e)&&wt(n,e):n==e)}function wt(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!a1(t,e[i]))}var K3=o3(S("color"),1),k=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=yt(e)?e.color:(0,K3.default)(e),this.colorValues=this.color.object(),this.red=Number(this.colorValues.r),this.green=Number(this.colorValues.g),this.blue=Number(this.colorValues.b)}catch{this.color=(0,K3.default)("#000000"),this.colorValues=this.color.object(),this.red=Number(this.colorValues.r),this.green=Number(this.colorValues.g),this.blue=Number(this.colorValues.b)}}static get(e){return e instanceof n?e:new n(e)}toString(){return this.color.string()}lighten(e){return this.color.lighten(e/100).hex().toLowerCase()}darken(e){return this.color.darken(e/100).hex().toLowerCase()}rgb(){return this.color.rgb().toString()}rgba(e){return this.color.alpha(e).rgb().toString()}hsl(){return this.color.hsl().round().toString()}hex(){return this.color.hex().toLowerCase()}saturate(e){return this.color.saturate(e/100).hex().toLowerCase()}desaturate(e){return this.color.desaturate(e/100).hex().toLowerCase()}modify(e,t){switch(e){case"red":case"green":case"blue":case"alpha":case"hue":case"lightness":break;case"saturation":return this.color.saturationl(t).hex();default:return this.toString()}let i=this.color[e](t);return e==="alpha"?i.string():i.hex()}extract(e){switch(e){case"red":case"green":case"blue":case"alpha":case"hue":case"lightness":break;case"saturation":return this.color.saturationl().toString();default:return this.toString()}return this.color[e]().toString()}mix(e,t){let i=this.color,r=e.color,[a,o,s]=i.rgb().array(),[l,u,c]=r.rgb().array(),h=K3.default.rgb([$3(a,l,t),$3(o,u,t),$3(s,c,t)]).alpha($3(i.alpha(),r.alpha(),t));return i.alpha()!==1?h.string():h.hex()}contrast(e){return this.color.contrast(e.color).toFixed(1)}difference(e){let[t,i,r]=this.color.rgb().array(),[a,o,s]=e.color.rgb().array();return w5(t,a)+w5(i,o)+w5(r,s)}brightness(){return(this.red*299+this.green*587+this.blue*114)/1e3}brightnessDifference(e){return Math.max(this.brightness(),e.brightness())-Math.min(this.brightness(),e.brightness())}};function $3(n,e,t){return(n*t+e*(100-t))/100}function w5(n,e){return Math.max(n,e)-Math.min(n,e)}function yt(n){return typeof n=="object"&&n!==null&&Object.hasOwn(n,"color")&&Object.hasOwn(n,"colorValues")&&Object.hasOwn(n,"red")&&Object.hasOwn(n,"green")&&Object.hasOwn(n,"blue")}var z3=class extends y5.Liquid{theme;getThemeConfig;getThemeTemplateConfigByType;getAssetUrl;renderTemplate;renderTemplateString;renderTemplateSections;renderTranslation;renderCurrency;engine;isEditor;locale;currency;layoutName;extName;componentsDir;sectionsDir;lastSchema;constructor({theme:e,getThemeConfig:t,getThemeTemplateConfigByType:i,getAssetUrl:r,renderTemplate:a,renderTemplateString:o,renderTemplateSections:s,renderTranslation:l,renderCurrency:u,isEditor:c,locale:h,currency:f,layoutName:m,extName:C,componentsDir:p,sectionsDir:g}){super(),this.theme=e,this.getThemeConfig=t||e.getThemeConfig.bind(e),this.getThemeTemplateConfigByType=i||e.getThemeTemplateConfigByType.bind(e),this.getAssetUrl=r||e.getAssetUrl.bind(e),this.renderTemplate=a||e.renderTemplate.bind(e),this.renderTemplateString=o||e.renderTemplateString.bind(e),this.renderTemplateSections=s||e.renderTemplateSections.bind(e),this.renderTranslation=l||e.renderTranslation.bind(e),this.renderCurrency=u||e.renderCurrency.bind(e),this.isEditor=c,this.locale=h||"en-US",this.currency=f||"USD",this.layoutName=m||"theme",this.extName=C||"liquid",this.componentsDir=p||"components",this.sectionsDir=g||"sections",this.engine=this.initLiquidEngine()}initLiquidEngine(){return this.engine=new y5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:r1}),w2(this),t1(this),this.engine}getLiquidFS(){let{getThemeConfig:e,resolveFilePath:t}=this;return{async readFile(i){let r=t(i);return e(r).then(a=>a?.file_data||`<!-- theme template not found: ${r} -->`)},async exists(i){return!0},readFileSync(i){return""},existsSync(i){return!1},contains(i,r){return!0},resolve(i,r,a){return r},fallback(i){}}}async parseAndRender(e,t){return this.engine.parseAndRender(e,t)}resolveFilePath(e,t){return`theme/${e}.${t||this.extName}`}async resolveFilePathByType(e,t){if(this.getThemeTemplateConfigByType){let i=await this.getThemeTemplateConfigByType(e,t);if(i?.file_path)return i.file_path}}async getComponentPath(e){return await this.resolveFilePathByType("components",e)||this.resolveFilePath(`${this.componentsDir}/${e}`)}async getSectionPath(e){return await this.resolveFilePathByType("sections",e)||this.resolveFilePath(`${this.sectionsDir}/${e}`)}async getSectionGroupPath(e){return await this.resolveFilePathByType("sections",`${e}.json`)||this.resolveFilePath(`${this.sectionsDir}/${e}`,"json")}};var S5=S("lodash-es");async function o1(n,e,t){let r=(await Promise.all(e?.map(async a=>({...a,items:await s1(n,a.items,t)})))).map(a=>(n.shopifyCompatibility&&Object.assign(a,n.shopifyCompatibility.getMenuData(a)),a))||[];return h1([...r,...n.shopifyCompatibility?r.map(a=>{if(a.handle)return{...a,id:a.handle}}).filter(Boolean):[]])}async function s1(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:a,resource:o}=await St(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await s1(n,r.items,t);return{...r,url:a,resource:o,levels:l1(s),current:t?.currentUrl===a,active:t?.currentUrl?.startsWith(a),...s?{items:s,child_current:kt(s),child_active:k5(s)}:void 0}})):[]}async function St(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await At(n,e),a=i.slice(-1)==="/";return t?.trailingSlash&&!a&&i.length>1&&(i=i+"/"),!t?.trailingSlash&&a&&i.length>1&&(i=i.slice(0,-1)),{url:i,resource:r}}else return{url:e}}function l1(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+l1(t.items):0),0)||0}function kt(n){return n.some(e=>e.current||e.items&&k5(e.items))}function k5(n){return n.some(e=>e.active||e.items&&k5(e.items))}function Lt(n){return(0,S5.get)(n,"id",(0,S5.get)(n,"slug",typeof n=="string"?n:""))||""}async function At(n,e){let{type:t,value:i,url:r,model:a}=e;if(typeof t>"u"&&r)return{url:r};if(t==="url")return{url:typeof i=="string"?i:""};let o=Lt(i);switch(t){case"home":return{url:C3(n,"index")};case"category":return o?await u3(n,"categories/category",o):{url:C3(n,"categories/index")};case"product":return o?await u3(n,"products/product",o):{url:C3(n,"products/index")};case"page":return await u3(n,"pages/page",o);case"blog":return await u3(n,"blogs/blog",o,async s=>new E(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await u3(n,"blogs/category",o);case"content_list":if(a){let s=a?.replace("content/","");return{url:C3(n,"content/index",s),resource:new T(n.swell,a)}}break;case"content":if(a){let s=a?.replace("content/","");return await u3(n,"content/content",o,s)}break;case"search":return{url:C3(n,"search")};default:break}return{url:`/${o}`}}function C3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(o=>o.id===e)?.url;return a?.includes(":collection")&&i&&(a=a.replace(":collection",i)),a?.includes(":slug")&&(a=a.replace(":slug",t||"")),a||`/${t||""}`}async function u3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(u=>u.id===e)?.collection,o=a?new E(n.swell,a,t):void 0,s=await o?.slug||t,l=typeof i=="string"?i:void 0;return o?.id&&typeof i=="function"&&(l=await i(o)),{url:C3(n,e,s,typeof l=="string"?l:void 0),resource:o}}var d1=o3(S("bluebird"),1);var{Promise:L3}=d1.default,bt=50,W3=class n{static cache;swell;manifest=null;configs={};configPaths=[];constructor(e){this.swell=e}async init(){await this.fetchManifest(),this.manifest||(console.log("ThemeLoader.init - version manifest not found"),await this.loadTheme())}async loadTheme(){let{swellHeaders:e}=this.swell;if(console.log("ThemeLoader.loadTheme",e["theme-version-hash"]),e["theme-version-hash"]){let t=await this.loadThemeFromManifest();if(t)return t}return this.loadThemeAllConfigs()}async preloadTheme(e,t){console.log(`ThemeLoader.preloadTheme${e?.hash?` - manifest: ${e.hash}`:""}${t?.length?` - configs: ${t.length}`:""}`),await L3.all([e&&this.cacheManifest(e),t&&L3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}async fetchThemeConfig(e){if(this.configs[e]!==void 0)return this.configs[e];let t=this.manifest?.[e];if(t){let i=await this.getCache().get(`config:${t}`);return i?(this.configs[e]=i,i):this.fetchThemeConfigsFromSourceByPath(e)}return null}async fetchThemeConfigsByPath(e,t){let i=this.configPaths.filter(a=>a.startsWith(e)&&(!t||a.endsWith(t)));return(await L3.map(i,a=>this.fetchThemeConfig(a),{concurrency:10})).filter(a=>a!==null)}async loadThemeAllConfigs(){let{swellHeaders:e}=this.swell,t=String(e["theme-config-version"]);if(!t)throw new Error("Theme version is required");return(await this.getCache().fetch(`configs-all:${this.swell.instanceId}:v@${t}2`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)return null;let t=[],i=new Map;if(await L3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(a=>{a?(i.set(a.hash,a),this.configs[a.file_path]=a):t.push(r)}),{concurrency:10}),t.length>0){let a=(await this.fetchThemeConfigsFromSource(i.size===0?void 0:t))?.results??[];for(let o of a)i.set(o.hash,o),this.configs[o.file_path]=o;await L3.map(a,o=>this.cacheThemeConfig(o),{concurrency:10})}return Array.from(i.values())}async cacheManifest(e){e?.hash&&await this.getCache().set(`manifest:${e.hash}`,e.manifest)}async cacheThemeConfig(e){e?.hash&&await this.getCache().set(`config:${e.hash}`,e)}async fetchManifest(){let{swellHeaders:e}=this.swell,t=e["theme-version-hash"];console.log("ThemeLoader.fetchManifest",t);let i=await this.getCache().get(`manifest:${t}`);if(!i){let r=await this.swell.get("/:themes:versions/:last",{...this.themeVersionQueryFilter(),fields:"hash, manifest"});r&&(await this.cacheManifest(r),i=r.manifest)}return this.manifest=i,this.configPaths=Object.keys(i||{}),this.manifest}async fetchThemeConfigsFromSource(e=void 0){e=e||[];let{swellHeaders:t}=this.swell,i=String(t["theme-config-version"]),r=e.length===0||e.length>bt;return console.log(`Retrieving ${r?"all":"some"} theme configurations - version: ${i}`),await this.swell.get("/:themes:configs",{...this.themeVersionQueryFilter(),...r?{}:{hash:{$in:e}},limit:1e3,type:"theme",fields:"name, file, file_path, hash",include:{file_data:y4}})}async fetchThemeConfigsFromSourceByPath(e){console.log(`Retrieving theme config - ${e}`);let t=await this.swell.get("/:themes:configs/:last",{...this.themeVersionQueryFilter(),file_path:e,fields:"name, file, file_path, hash",include:{file_data:y4}});return t&&await this.cacheThemeConfig(t),this.configs[e]=t,t}themeVersionQueryFilter(){let{swellHeaders:e}=this.swell,t=e["theme-id"];if(!t)throw new Error("Theme ID is required");return{parent_id:t,branch_id:e["theme-branch-id"]||null,preview:e["deployment-mode"]==="editor"||e["deployment-mode"]==="preview"?!0:{$ne:!0}}}getCache(){return n.cache||(n.cache=new g3(this.swell.workerEnv?.THEME)),n.cache}};var c1=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=A3;shopifyCompatibilityConfig=null;formData={};globalData={};constructor(e,t={}){let{forms:i,resources:r,globals:a,shopifyCompatibilityClass:o}=t;this.swell=e,this.props=this.getSwellAppThemeProps(e.config),this.shopifyCompatibilityConfig=e.shopifyCompatibilityConfig||null,this.globals=a||{},this.forms=i,this.resources=r,this.shopifyCompatibilityClass=o||A3,this.liquidSwell=new z3({theme:this,getThemeConfig:this.getThemeConfig.bind(this),getAssetUrl:this.getAssetUrl.bind(this),getThemeTemplateConfigByType:this.getThemeTemplateConfigByType.bind(this),renderTemplate:this.renderTemplate.bind(this),renderTemplateString:this.renderTemplateString.bind(this),renderTemplateSections:this.renderTemplateSections.bind(this),renderTranslation:this.lang.bind(this),renderCurrency:this.renderCurrency.bind(this),isEditor:e.isEditor}),this.themeLoader=new W3(e)}getSwellAppThemeProps(e){return e?.storefront?.theme||{}}async initGlobals(e){this.pageId=e,await this.themeLoader.init();let{store:t,session:i,menus:r,geo:a,configs:o}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:u,cart:c,account:h,customer:f}=await this.resolvePageData(t,o,i,e);this.page=u;let m={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:u,cart:c,account:h,customer:f,geo:a,configs:o,translations:o?.translations,canonical_url:`${t.url}${this.swell.url?.pathname||""}`,shopify_compatibility:!!s.shopify_compatibility};this.shopifyCompatibility&&this.shopifyCompatibility.adaptGlobals(m),this.setGlobals(m),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.globals={...this.globals,...e},this.liquidSwell.engine.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=h2,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getThemeConfigsByPath("theme/config/",".json")]),r={theme:{},editor:{},translations:{},presets:[],...Array.from(i.values()).reduce((l,u)=>{let c=u?.name.split(".")[0];if(c){let h;try{h=JSON.parse(u.file_data)}catch{h=null}l[c]=h}return l},{})},a=await this.swell.storefront.settings.session(),o=a.locale||t?.store?.locale;this.resolveTranslationLocale(r.translations,o),await this.setCompatibilityConfigs(r,o);let s=await this.resolveMenuSettings();return{store:t?.store,session:a,menus:s,geo:e,configs:r}}async resolvePageData(e,t,i,r){let a=String(this.swell.swellHeaders["theme-config-version"]),o=await this.swell.getCachedResource(`theme-settings-resolved:v@${a}`,[],()=>Q3(this,t.theme,t.editor?.settings));if(!o)throw new Error("Failed to resolve theme settings");let s={host:this.swell.url.host,origin:this.swell.url.origin,path:this.swell.url.pathname,query:this.swell.queryParams,locale:i?.locale||e.locale,currency:i?.currency||e.currency,is_editor:this.swell.isEditor,is_preview:this.swell.isPreview},l=this.props.pages?.find(C=>C.id===r),u=!l,c={...l,current:this.swell.queryParams.page||1,url:this.swell.url.pathname,custom:u,slug:null,description:null};if(r){let C=await this.getThemeTemplateConfigByType("templates",r),p;try{p=JSON.parse(C?.file_data||"")}catch{}if(p?.page){let{slug:g,label:z,description:a3}=p.page;c.slug=g,c.label=z,c.description=a3}}let[h,f]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!h)throw new Error("Failed to fetch cart");let m;return this.shopifyCompatibility&&(m=f),{settings:o,request:s,page:c,cart:h,account:f,customer:m}}async fetchSingletonResourceCached(e,t,i){let r=this.swell.storefront.session.getCookie();return r?this.swell.getCachedResource(`${e}-${r}`,[],()=>t()):i}async fetchCart(){let e=this.resources?.singletons?.cart,t=e?new e(this.swell):new i3(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=y3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new i3(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=e3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}getFormConfig(e){let t=e;if(this.shopifyCompatibility){let i=this.shopifyCompatibility.getAdaptedFormType(e);i&&(t=i)}return this.forms?.find(i=>i.id===t)}setFormData(e,t){let i=this.formData[e]||new J(e);i instanceof J&&(t?.params&&i.setParams(t.params),t?.errors?(i.setSuccess(!1),i.setErrors(t.errors)):t?.success&&(t.withoutErrors&&!i.errors?i.setSuccess(!0):t.withoutErrors||(i.setSuccess(!0),i.clearErrors())),this.shopifyCompatibility&&Object.assign(i,this.shopifyCompatibility.getFormData(i))),this.formData[e]=i,this.setGlobals({forms:this.formData})}setFormSuccessWithoutErrors(e){this.setFormData(e,{success:!0,withoutErrors:!0})}clearFormData(e){e?delete this.formData[e]:this.formData={},this.setGlobals({forms:this.formData})}serializeFormData(){let e={};for(let t in this.formData){let i=this.formData[t];e[t]={success:i.success,errors:i.errors&&Array.from(i.errors)}}return Object.keys(e).length>0?e:null}setGlobalData(e={}){this.globalData={...this.globalData,...e},this.setGlobals(this.globalData)}serializeGlobalData(){return Object.keys(this.globalData).length>0?this.globalData:null}updateSettings(e,t){return this.shopifyCompatibility?this.shopifyCompatibility.adaptSettings(e,t):b3(e,t)}resolveTranslationLocale(e,t){if(!e)return{};if(!t)return e;let i=t.split("-")[0];return(0,b.reduce)(e,(r,a,o)=>{if(X3(a))r[o]=this.resolveTranslationLocale(a,t);else if(typeof a=="string"&&a.startsWith("t:")){let s=a.slice(2),l=s.split("."),u=l.pop(),c=l.join("."),h=this.globals.translations;r[o]=(0,b.get)(h,`${c}.$locale.${t}.${u}`)||(0,b.get)(h,`${c}.$locale.${i}.${u}`)||(0,b.get)(h,s)||a}else r[o]=(0,b.get)(e,`$locale.${t}.${o}`)||(0,b.get)(e,`$locale.${i}.${o}`)||a;return r},{})}async setCompatibilityConfigs(e,t){let i=()=>(this.shopifyCompatibility||(this.shopifyCompatibility=new this.shopifyCompatibilityClass(this)),this.shopifyCompatibility);!Object.keys(e.editor).length&&e.settings_schema&&(e.editor=i().getEditorConfig(e.settings_schema),e.editor=await i().renderSchemaTranslations(this,e.editor,t)),!Object.keys(e.theme).length&&e.settings_data&&(e.theme=i().getThemeConfig(e.settings_data)),!Object.keys(e.presets).length&&e.settings_data&&(e.presets=i().getPresetsConfig(e.settings_data)),Object.keys(e.translations).length||(e.translations=await i().getLocaleConfig(this,t),Object.keys(e.translations).length||(this.shopifyCompatibility=null)),e.theme.shopify_compatibility?i():this.shopifyCompatibility&&(e.theme.shopify_compatibility=!0)}setCompatibilityData(e){!e||!this.shopifyCompatibility||this.shopifyCompatibility.adaptPageData(e)}resolveLookupSetting(e,t){if(t instanceof M)return t;let i=Tt(e);if(i){if(e.multiple){if(t instanceof Array)return t.map(r=>this.resolveLookupResource(i,r))}else if(t!==""&&t!==null&&t!==void 0)return this.resolveLookupResource(i,t)}return null}resolveLookupResource(e,t){let i=this.resources?.records?.[e],r=i?new i(this.swell,t):new E(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return o1(this,this.swell.getStorefrontMenus(),{currentUrl:this.swell.url.pathname})}resolveMenuSetting(e){if(!e)return null;let t=this.globals.menus||{};return t[e]||t[e.replace(/-/g,"_")]||null}async lang(e,t,i){return await this.renderTranslation(e,t,i)}resolveFontSetting(e){if(this.shopifyCompatibility){let t=this.shopifyCompatibility.getFontFromShopifySetting(e),i=new x(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new x(e)}resolveUrlSetting(e){let t=e;if(this.shopifyCompatibility){e?.startsWith("shopify://")&&(t=e.replace("shopify://","/"));let i=this.shopifyCompatibility.getAdaptedPageUrl(t);if(i)return i}return t}resolveImageSetting(e){let t=e;return this.shopifyCompatibility&&e?.startsWith("shopify://")&&(t=""),t}async getAllThemeConfigs(){if(!this.themeConfigs){let e=await this.themeLoader.loadTheme(),t=new Map;for(let i of e)t.set(i.file_path,i);this.themeConfigs=t}return this.themeConfigs}async preloadThemeConfigs(e,t){await this.themeLoader.preloadTheme(e,t)}getPageConfigPath(e){return this.shopifyCompatibility?`theme/${this.shopifyCompatibility.getThemeFilePath("templates",e)}.json`:`theme/templates/${e}.json`}async getThemeConfig(e){return this.themeConfigs?this.themeConfigs.get(e)??null:this.themeLoader.fetchThemeConfig(e)}async getThemeConfigsByPath(e,t){let i=await this.themeLoader.fetchThemeConfigsByPath(e,t),r=new Map;for(let a of i)r.set(a.file_path,a);return r}async getThemeTemplateConfig(e){if(e.endsWith(".json")||e.endsWith(".liquid"))return this.getThemeConfig(e);let t=await this.getThemeConfig(`${e}.json`);return t||this.getThemeConfig(`${e}.liquid`)}async getThemeTemplateConfigByType(e,t){let i=[`${e}/${t}`];this.shopifyCompatibility&&i.push(this.shopifyCompatibility.getThemeFilePath(e,t));for(let r of i){let a=await this.getThemeTemplateConfig(`theme/${r}`);if(a)return a}return null}async getAssetUrl(e){return(await this.getThemeConfig(`theme/assets/${e}`)||await this.getThemeConfig(`assets/${e}`))?.file?.url||null}async renderTemplate(e,t){let i=e?.file_data||null;if(e===null||i===null)return"";try{return await this.liquidSwell.parseAndRender(i,t)}catch(r){return console.error(r),`<!-- template render error: ${r.message} -->`}}async renderTemplateString(e,t){try{return await this.liquidSwell.parseAndRender(e,t)}catch(i){return console.error(i),""}}async getSectionSchema(e){let t,i=await this.getThemeTemplateConfigByType("sections",e);if(i?.file_path?.endsWith(".json"))try{t=JSON.parse(i.file_data)||void 0}catch{return}else if(i?.file_path?.endsWith(".liquid")&&this.shopifyCompatibility){this.liquidSwell.lastSchema=void 0;let r=this.getSectionConfigWithSchemaTagOnly(i);if(!r)return;await this.renderTemplate(r);let a=this.liquidSwell.lastSchema;a&&(t=this.shopifyCompatibility.getSectionConfigSchema(a),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.request?.locale))}return t.id=t.id||e,t.label=t.label||e,t.fields=t.fields||[],t}getSectionConfigWithSchemaTagOnly(e){let t="{% schema %}",i="{% endschema %}",r=e.file_data.indexOf(t),a=e.file_data.indexOf(i),o=e.file_data.slice(r+t.length,a);return r===-1||a===-1?null:{...e,file_data:t+o+i}}async renderThemeTemplate(e,t){let i=await this.getThemeTemplateConfig(e),r=await this.renderTemplate(i,{...t,template:i});if(i?.file_path?.endsWith(".json"))try{return JSON.parse(r)}catch(a){throw console.log("Unable to render theme template",i.file_path,r),new J3(a)}return r}async renderLayoutTemplate(e,t){let i=await this.getThemeTemplateConfigByType("layouts",e);if(i){let r=await this.renderThemeTemplate(i.file_path,t);return typeof r=="string"?r:`<!-- invalid layout: ${e}--> {{ content_for_layout }}`}throw new Error(`Layout template not found: ${e}`)}async renderPageTemplate(e,t,i){let r=null;if(i&&(r=await this.getThemeTemplateConfigByType("templates",`${e}.${i}`)),r||(r=await this.getThemeTemplateConfigByType("templates",e)),r){let a=await this.renderThemeTemplate(r.file_path,t);return a&&typeof a!="string"&&(a.id=r.name),a}throw console.error(new Error(`Page template not found: templates/${e}.liquid`)),new Y3}async renderPage(e,t){e&&this.setGlobals(e);let i;if(this.page?.id?i=await this.renderPageTemplate(this.page.id,e,t):i=await this.renderPageTemplate("404",e),typeof i!="string"&&i?.page){if(i.page.published===!1)throw new Y3;i.page=this.resolveTranslationLocale(i.page,this.globals.request?.locale)}return i}async renderAllSections(e,t){let i=typeof e=="string"?e.split(/\s*,\s*/):e;return(await Promise.all(i.map?.(a=>this.renderSection(a,t)))).reduce((a,o,s)=>{let l=i[s];return this.shopifyCompatibility?a[l]=`
935
+ `;var pt={image:I2,"product-1":A2,"product-2":b2,"product-3":T2,"product-4":_2,"product-5":M2,"product-6":E2,"collection-1":v2,"collection-2":D2,"collection-3":P2,"collection-4":x2,"collection-5":R2,"collection-6":j2,"lifestyle-1":Z2,"lifestyle-2":N2,"product-apparel-1":F2,"product-apparel-2":H2,"product-apparel-3":B2,"product-apparel-4":q2,"collection-apparel-1":G2,"collection-apparel-2":V2,"collection-apparel-3":O2,"collection-apparel-4":U2,"hero-apparel-1":$2,"hero-apparel-2":K2,"hero-apparel-3":z2,"blog-apparel-1":W2,"blog-apparel-2":J2,"blog-apparel-3":Y2,"detailed-apparel-1":Q2},X2=pt;function f5(n){return e=>{let t=X2[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function g5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var ft={asset_url:Z4,brightness_difference:N4,color_brightness:I4,color_contrast:F4,color_darken:H4,color_desaturate:B4,color_difference:q4,color_extract:G4,color_lighten:V4,color_mix:O4,color_modify:U4,color_saturate:$4,color_to_hex:K4,color_to_hsl:z4,color_to_rgb:W4,date:k3,default_errors:Y4,divided_by:Q4,font_face:X4,font_modify:e5,font_url:t5,format_address:y2,image_tag:i5,image_url:k2,inline_asset_content:n5,json:r5,json_pretty:a5,money:o5,money_with_currency:s5,money_without_currency:l5,money_without_trailing_zeros:h5,stylesheet_tag:d5,time_tag:c5,translate:U3,t:U3,where:u5,hex_to_rgba:C5,item_count_for_variant:L2,payment_button:m5,payment_terms:p5,placeholder_svg_tag:f5,inline_editable:g5};function t1(n){(0,e1.each)(ft,(e,t)=>{if(typeof e=="function")n.engine.registerFilter(t,e(n));else if(typeof e.bind=="function"){let{bind:i,resolve:r}=e;n.engine.registerFilter(t,gt(n,i,r))}})}function gt(n,e,t=[]){let i=e(n);return Array.isArray(t)?async(...r)=>{let a=await Promise.all(r.map((o,s)=>Array.isArray(t[s])||t[s]===!0?i1(o,t[s]):o));return i(...a)}:i}async function i1(n,e){if(!n)return n;let t=n;P(t)&&(t=await t);try{if(Array.isArray(e))for(let i of e){if(typeof i!="string")continue;let[r,...a]=i.split("."),o=t[r];P(o)?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await i1(t[r],[a.join(".")]))}}catch{}return t}var n1=S("liquidjs");var r1={...n1.defaultOperators,"==":a1};function a1(n,e){return w3(n)?n.equals(e):w3(e)?e.equals(n):(n=Y(n),e=Y(e),l3(n)?l3(e)&&wt(n,e):n==e)}function wt(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!a1(t,e[i]))}var K3=o3(S("color"),1),k=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=yt(e)?e.color:(0,K3.default)(e),this.colorValues=this.color.object(),this.red=Number(this.colorValues.r),this.green=Number(this.colorValues.g),this.blue=Number(this.colorValues.b)}catch{this.color=(0,K3.default)("#000000"),this.colorValues=this.color.object(),this.red=Number(this.colorValues.r),this.green=Number(this.colorValues.g),this.blue=Number(this.colorValues.b)}}static get(e){return e instanceof n?e:new n(e)}toString(){return this.color.string()}lighten(e){return this.color.lighten(e/100).hex().toLowerCase()}darken(e){return this.color.darken(e/100).hex().toLowerCase()}rgb(){return this.color.rgb().toString()}rgba(e){return this.color.alpha(e).rgb().toString()}hsl(){return this.color.hsl().round().toString()}hex(){return this.color.hex().toLowerCase()}saturate(e){return this.color.saturate(e/100).hex().toLowerCase()}desaturate(e){return this.color.desaturate(e/100).hex().toLowerCase()}modify(e,t){switch(e){case"red":case"green":case"blue":case"alpha":case"hue":case"lightness":break;case"saturation":return this.color.saturationl(t).hex();default:return this.toString()}let i=this.color[e](t);return e==="alpha"?i.string():i.hex()}extract(e){switch(e){case"red":case"green":case"blue":case"alpha":case"hue":case"lightness":break;case"saturation":return this.color.saturationl().toString();default:return this.toString()}return this.color[e]().toString()}mix(e,t){let i=this.color,r=e.color,[a,o,s]=i.rgb().array(),[l,u,c]=r.rgb().array(),h=K3.default.rgb([$3(a,l,t),$3(o,u,t),$3(s,c,t)]).alpha($3(i.alpha(),r.alpha(),t));return i.alpha()!==1?h.string():h.hex()}contrast(e){return this.color.contrast(e.color).toFixed(1)}difference(e){let[t,i,r]=this.color.rgb().array(),[a,o,s]=e.color.rgb().array();return w5(t,a)+w5(i,o)+w5(r,s)}brightness(){return(this.red*299+this.green*587+this.blue*114)/1e3}brightnessDifference(e){return Math.max(this.brightness(),e.brightness())-Math.min(this.brightness(),e.brightness())}};function $3(n,e,t){return(n*t+e*(100-t))/100}function w5(n,e){return Math.max(n,e)-Math.min(n,e)}function yt(n){return typeof n=="object"&&n!==null&&Object.hasOwn(n,"color")&&Object.hasOwn(n,"colorValues")&&Object.hasOwn(n,"red")&&Object.hasOwn(n,"green")&&Object.hasOwn(n,"blue")}var z3=class extends y5.Liquid{theme;getThemeConfig;getThemeTemplateConfigByType;getAssetUrl;renderTemplate;renderTemplateString;renderTemplateSections;renderTranslation;renderCurrency;engine;isEditor;locale;currency;layoutName;extName;componentsDir;sectionsDir;lastSchema;constructor({theme:e,getThemeConfig:t,getThemeTemplateConfigByType:i,getAssetUrl:r,renderTemplate:a,renderTemplateString:o,renderTemplateSections:s,renderTranslation:l,renderCurrency:u,isEditor:c,locale:h,currency:f,layoutName:m,extName:C,componentsDir:p,sectionsDir:g}){super(),this.theme=e,this.getThemeConfig=t||e.getThemeConfig.bind(e),this.getThemeTemplateConfigByType=i||e.getThemeTemplateConfigByType.bind(e),this.getAssetUrl=r||e.getAssetUrl.bind(e),this.renderTemplate=a||e.renderTemplate.bind(e),this.renderTemplateString=o||e.renderTemplateString.bind(e),this.renderTemplateSections=s||e.renderTemplateSections.bind(e),this.renderTranslation=l||e.renderTranslation.bind(e),this.renderCurrency=u||e.renderCurrency.bind(e),this.isEditor=c,this.locale=h||"en-US",this.currency=f||"USD",this.layoutName=m||"theme",this.extName=C||"liquid",this.componentsDir=p||"components",this.sectionsDir=g||"sections",this.engine=this.initLiquidEngine()}initLiquidEngine(){return this.engine=new y5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:r1}),w2(this),t1(this),this.engine}getLiquidFS(){let{getThemeConfig:e,resolveFilePath:t}=this;return{async readFile(i){let r=t(i);return e(r).then(a=>a?.file_data||`<!-- theme template not found: ${r} -->`)},async exists(i){return!0},readFileSync(i){return""},existsSync(i){return!1},contains(i,r){return!0},resolve(i,r,a){return r},fallback(i){}}}async parseAndRender(e,t){return this.engine.parseAndRender(e,t)}resolveFilePath(e,t){return`theme/${e}.${t||this.extName}`}async resolveFilePathByType(e,t){if(this.getThemeTemplateConfigByType){let i=await this.getThemeTemplateConfigByType(e,t);if(i?.file_path)return i.file_path}}async getComponentPath(e){return await this.resolveFilePathByType("components",e)||this.resolveFilePath(`${this.componentsDir}/${e}`)}async getSectionPath(e){return await this.resolveFilePathByType("sections",e)||this.resolveFilePath(`${this.sectionsDir}/${e}`)}async getSectionGroupPath(e){return await this.resolveFilePathByType("sections",`${e}.json`)||this.resolveFilePath(`${this.sectionsDir}/${e}`,"json")}};var S5=S("lodash-es");async function o1(n,e,t){let r=(await Promise.all(e?.map(async a=>({...a,items:await s1(n,a.items,t)})))).map(a=>(n.shopifyCompatibility&&Object.assign(a,n.shopifyCompatibility.getMenuData(a)),a))||[];return h1([...r,...n.shopifyCompatibility?r.map(a=>{if(a.handle)return{...a,id:a.handle}}).filter(Boolean):[]])}async function s1(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:a,resource:o}=await St(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await s1(n,r.items,t);return{...r,url:a,resource:o,levels:l1(s),current:t?.currentUrl===a,active:t?.currentUrl?.startsWith(a),...s?{items:s,child_current:kt(s),child_active:k5(s)}:void 0}})):[]}async function St(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await At(n,e),a=i.slice(-1)==="/";return t?.trailingSlash&&!a&&i.length>1&&(i=i+"/"),!t?.trailingSlash&&a&&i.length>1&&(i=i.slice(0,-1)),{url:i,resource:r}}else return{url:e}}function l1(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+l1(t.items):0),0)||0}function kt(n){return n.some(e=>e.current||e.items&&k5(e.items))}function k5(n){return n.some(e=>e.active||e.items&&k5(e.items))}function Lt(n){return(0,S5.get)(n,"id",(0,S5.get)(n,"slug",typeof n=="string"?n:""))||""}async function At(n,e){let{type:t,value:i,url:r,model:a}=e;if(typeof t>"u"&&r)return{url:r};if(t==="url")return{url:typeof i=="string"?i:""};let o=Lt(i);switch(t){case"home":return{url:C3(n,"index")};case"category":return o?await u3(n,"categories/category",o):{url:C3(n,"categories/index")};case"product":return o?await u3(n,"products/product",o):{url:C3(n,"products/index")};case"page":return await u3(n,"pages/page",o);case"blog":return await u3(n,"blogs/blog",o,async s=>new E(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await u3(n,"blogs/category",o);case"content_list":if(a){let s=a?.replace("content/","");return{url:C3(n,"content/index",s),resource:new T(n.swell,a)}}break;case"content":if(a){let s=a?.replace("content/","");return await u3(n,"content/content",o,s)}break;case"search":return{url:C3(n,"search")};default:break}return{url:`/${o}`}}function C3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(o=>o.id===e)?.url;return a?.includes(":collection")&&i&&(a=a.replace(":collection",i)),a?.includes(":slug")&&(a=a.replace(":slug",t||"")),a||`/${t||""}`}async function u3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(u=>u.id===e)?.collection,o=a?new E(n.swell,a,t):void 0,s=await o?.slug||t,l=typeof i=="string"?i:void 0;return o?.id&&typeof i=="function"&&(l=await i(o)),{url:C3(n,e,s,typeof l=="string"?l:void 0),resource:o}}var d1=o3(S("bluebird"),1);var{Promise:L3}=d1.default,bt=50,W3=class n{static cache;swell;manifest=null;configs={};configPaths=[];constructor(e){this.swell=e}async init(e){let{swellHeaders:t}=this.swell;if(e){this.setConfigs(e);return}t["theme-id"]&&(await this.fetchManifest(),this.manifest||(console.log("ThemeLoader.init - version manifest not found"),await this.loadTheme()))}async loadTheme(){let{swellHeaders:e}=this.swell;if(console.log("ThemeLoader.loadTheme",e["theme-version-hash"]),e["theme-version-hash"]){let t=await this.loadThemeFromManifest();if(t)return t}return this.loadThemeAllConfigs()}setConfigs(e){this.configs=Object.fromEntries(e),this.configPaths=Object.keys(this.configs),this.manifest=this.configPaths.reduce((t,i)=>(t[i]=this.configs[i]?.hash,t),{})}async preloadTheme(e,t){console.log(`ThemeLoader.preloadTheme${e?.hash?` - manifest: ${e.hash}`:""}${t?.length?` - configs: ${t.length}`:""}`),await L3.all([e&&this.cacheManifest(e),t&&L3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}async fetchThemeConfig(e){if(this.configs[e]!==void 0)return this.configs[e];let t=this.manifest?.[e];if(t){let i=await this.getCache().get(`config:${t}`);return i?(this.configs[e]=i,i):this.fetchThemeConfigsFromSourceByPath(e)}return null}async fetchThemeConfigsByPath(e,t){let i=this.configPaths.filter(a=>a.startsWith(e)&&(!t||a.endsWith(t)));return(await L3.map(i,a=>this.fetchThemeConfig(a),{concurrency:10})).filter(a=>a!==null)}async loadThemeAllConfigs(){let{swellHeaders:e}=this.swell,t=String(e["theme-config-version"]);if(!t)throw new Error("Theme version is required");return(await this.getCache().fetch(`configs-all:${this.swell.instanceId}:v@${t}2`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)return null;let t=[],i=new Map;if(await L3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(a=>{a?(i.set(a.hash,a),this.configs[a.file_path]=a):t.push(r)}),{concurrency:10}),t.length>0){let a=(await this.fetchThemeConfigsFromSource(i.size===0?void 0:t))?.results??[];for(let o of a)i.set(o.hash,o),this.configs[o.file_path]=o;await L3.map(a,o=>this.cacheThemeConfig(o),{concurrency:10})}return Array.from(i.values())}async cacheManifest(e){e?.hash&&await this.getCache().set(`manifest:${e.hash}`,e.manifest)}async cacheThemeConfig(e){e?.hash&&await this.getCache().set(`config:${e.hash}`,e)}async fetchManifest(){let{swellHeaders:e}=this.swell,t=e["theme-version-hash"];console.log("ThemeLoader.fetchManifest",t);let i=await this.getCache().get(`manifest:${t}`);if(!i){let r=await this.swell.get("/:themes:versions/:last",{...this.themeVersionQueryFilter(),fields:"hash, manifest"});r&&(await this.cacheManifest(r),i=r.manifest)}return this.manifest=i,this.configPaths=Object.keys(i||{}),this.manifest}async fetchThemeConfigsFromSource(e=void 0){e=e||[];let{swellHeaders:t}=this.swell,i=String(t["theme-config-version"]),r=e.length===0||e.length>bt;return console.log(`Retrieving ${r?"all":"some"} theme configurations - version: ${i}`),await this.swell.get("/:themes:configs",{...this.themeVersionQueryFilter(),...r?{}:{hash:{$in:e}},limit:1e3,type:"theme",fields:"name, file, file_path, hash",include:{file_data:y4}})}async fetchThemeConfigsFromSourceByPath(e){console.log(`Retrieving theme config - ${e}`);let t=await this.swell.get("/:themes:configs/:last",{...this.themeVersionQueryFilter(),file_path:e,fields:"name, file, file_path, hash",include:{file_data:y4}});return t&&await this.cacheThemeConfig(t),this.configs[e]=t,t}themeVersionQueryFilter(){let{swellHeaders:e}=this.swell,t=e["theme-id"];if(!t)throw new Error("Theme ID is required");return{parent_id:t,branch_id:e["theme-branch-id"]||null,preview:e["deployment-mode"]==="editor"||e["deployment-mode"]==="preview"?!0:{$ne:!0}}}getCache(){return n.cache||(n.cache=new g3(this.swell.workerEnv?.THEME)),n.cache}};var c1=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=A3;shopifyCompatibilityConfig=null;formData={};globalData={};constructor(e,t={}){let{forms:i,resources:r,globals:a,shopifyCompatibilityClass:o}=t;this.swell=e,this.props=this.getSwellAppThemeProps(e.config),this.shopifyCompatibilityConfig=e.shopifyCompatibilityConfig||null,this.globals=a||{},this.forms=i,this.resources=r,this.shopifyCompatibilityClass=o||A3,this.liquidSwell=new z3({theme:this,getThemeConfig:this.getThemeConfig.bind(this),getAssetUrl:this.getAssetUrl.bind(this),getThemeTemplateConfigByType:this.getThemeTemplateConfigByType.bind(this),renderTemplate:this.renderTemplate.bind(this),renderTemplateString:this.renderTemplateString.bind(this),renderTemplateSections:this.renderTemplateSections.bind(this),renderTranslation:this.lang.bind(this),renderCurrency:this.renderCurrency.bind(this),isEditor:e.isEditor}),this.themeLoader=new W3(e)}getSwellAppThemeProps(e){return e?.storefront?.theme||{}}async initGlobals(e){this.pageId=e,await this.themeLoader.init(this.themeConfigs||void 0);let{store:t,session:i,menus:r,geo:a,configs:o}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:u,cart:c,account:h,customer:f}=await this.resolvePageData(t,o,i,e);this.page=u;let m={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:u,cart:c,account:h,customer:f,geo:a,configs:o,translations:o?.translations,canonical_url:`${t.url}${this.swell.url?.pathname||""}`,shopify_compatibility:!!s.shopify_compatibility};this.shopifyCompatibility&&this.shopifyCompatibility.adaptGlobals(m),this.setGlobals(m),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.globals={...this.globals,...e},this.liquidSwell.engine.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=h2,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getThemeConfigsByPath("theme/config/",".json")]),r={theme:{},editor:{},translations:{},presets:[],...Array.from(i.values()).reduce((l,u)=>{let c=u?.name.split(".")[0];if(c){let h;try{h=JSON.parse(u.file_data)}catch{h=null}l[c]=h}return l},{})},a=await this.swell.storefront.settings.session(),o=a.locale||t?.store?.locale;this.resolveTranslationLocale(r.translations,o),await this.setCompatibilityConfigs(r,o);let s=await this.resolveMenuSettings();return{store:t?.store,session:a,menus:s,geo:e,configs:r}}async resolvePageData(e,t,i,r){let a=String(this.swell.swellHeaders["theme-config-version"]),o=await this.swell.getCachedResource(`theme-settings-resolved:v@${a}`,[],()=>Q3(this,t.theme,t.editor?.settings));if(!o)throw new Error("Failed to resolve theme settings");let s={host:this.swell.url.host,origin:this.swell.url.origin,path:this.swell.url.pathname,query:this.swell.queryParams,locale:i?.locale||e.locale,currency:i?.currency||e.currency,is_editor:this.swell.isEditor,is_preview:this.swell.isPreview},l=this.props.pages?.find(C=>C.id===r),u=!l,c={...l,current:this.swell.queryParams.page||1,url:this.swell.url.pathname,custom:u,slug:null,description:null};if(r){let C=await this.getThemeTemplateConfigByType("templates",r),p;try{p=JSON.parse(C?.file_data||"")}catch{}if(p?.page){let{slug:g,label:z,description:a3}=p.page;c.slug=g,c.label=z,c.description=a3}}let[h,f]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!h)throw new Error("Failed to fetch cart");let m;return this.shopifyCompatibility&&(m=f),{settings:o,request:s,page:c,cart:h,account:f,customer:m}}async fetchSingletonResourceCached(e,t,i){let r=this.swell.storefront.session.getCookie();return r?this.swell.getCachedResource(`${e}-${r}`,[],()=>t()):i}async fetchCart(){let e=this.resources?.singletons?.cart,t=e?new e(this.swell):new i3(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=y3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new i3(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=e3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}getFormConfig(e){let t=e;if(this.shopifyCompatibility){let i=this.shopifyCompatibility.getAdaptedFormType(e);i&&(t=i)}return this.forms?.find(i=>i.id===t)}setFormData(e,t){let i=this.formData[e]||new J(e);i instanceof J&&(t?.params&&i.setParams(t.params),t?.errors?(i.setSuccess(!1),i.setErrors(t.errors)):t?.success&&(t.withoutErrors&&!i.errors?i.setSuccess(!0):t.withoutErrors||(i.setSuccess(!0),i.clearErrors())),this.shopifyCompatibility&&Object.assign(i,this.shopifyCompatibility.getFormData(i))),this.formData[e]=i,this.setGlobals({forms:this.formData})}setFormSuccessWithoutErrors(e){this.setFormData(e,{success:!0,withoutErrors:!0})}clearFormData(e){e?delete this.formData[e]:this.formData={},this.setGlobals({forms:this.formData})}serializeFormData(){let e={};for(let t in this.formData){let i=this.formData[t];e[t]={success:i.success,errors:i.errors&&Array.from(i.errors)}}return Object.keys(e).length>0?e:null}setGlobalData(e={}){this.globalData={...this.globalData,...e},this.setGlobals(this.globalData)}serializeGlobalData(){return Object.keys(this.globalData).length>0?this.globalData:null}updateSettings(e,t){return this.shopifyCompatibility?this.shopifyCompatibility.adaptSettings(e,t):b3(e,t)}resolveTranslationLocale(e,t){if(!e)return{};if(!t)return e;let i=t.split("-")[0];return(0,b.reduce)(e,(r,a,o)=>{if(X3(a))r[o]=this.resolveTranslationLocale(a,t);else if(typeof a=="string"&&a.startsWith("t:")){let s=a.slice(2),l=s.split("."),u=l.pop(),c=l.join("."),h=this.globals.translations;r[o]=(0,b.get)(h,`${c}.$locale.${t}.${u}`)||(0,b.get)(h,`${c}.$locale.${i}.${u}`)||(0,b.get)(h,s)||a}else r[o]=(0,b.get)(e,`$locale.${t}.${o}`)||(0,b.get)(e,`$locale.${i}.${o}`)||a;return r},{})}async setCompatibilityConfigs(e,t){let i=()=>(this.shopifyCompatibility||(this.shopifyCompatibility=new this.shopifyCompatibilityClass(this)),this.shopifyCompatibility);!Object.keys(e.editor).length&&e.settings_schema&&(e.editor=i().getEditorConfig(e.settings_schema),e.editor=await i().renderSchemaTranslations(this,e.editor,t)),!Object.keys(e.theme).length&&e.settings_data&&(e.theme=i().getThemeConfig(e.settings_data)),!Object.keys(e.presets).length&&e.settings_data&&(e.presets=i().getPresetsConfig(e.settings_data)),Object.keys(e.translations).length||(e.translations=await i().getLocaleConfig(this,t),Object.keys(e.translations).length||(this.shopifyCompatibility=null)),e.theme.shopify_compatibility?i():this.shopifyCompatibility&&(e.theme.shopify_compatibility=!0)}setCompatibilityData(e){!e||!this.shopifyCompatibility||this.shopifyCompatibility.adaptPageData(e)}resolveLookupSetting(e,t){if(t instanceof M)return t;let i=Tt(e);if(i){if(e.multiple){if(t instanceof Array)return t.map(r=>this.resolveLookupResource(i,r))}else if(t!==""&&t!==null&&t!==void 0)return this.resolveLookupResource(i,t)}return null}resolveLookupResource(e,t){let i=this.resources?.records?.[e],r=i?new i(this.swell,t):new E(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return o1(this,this.swell.getStorefrontMenus(),{currentUrl:this.swell.url.pathname})}resolveMenuSetting(e){if(!e)return null;let t=this.globals.menus||{};return t[e]||t[e.replace(/-/g,"_")]||null}async lang(e,t,i){return await this.renderTranslation(e,t,i)}resolveFontSetting(e){if(this.shopifyCompatibility){let t=this.shopifyCompatibility.getFontFromShopifySetting(e),i=new x(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new x(e)}resolveUrlSetting(e){let t=e;if(this.shopifyCompatibility){e?.startsWith("shopify://")&&(t=e.replace("shopify://","/"));let i=this.shopifyCompatibility.getAdaptedPageUrl(t);if(i)return i}return t}resolveImageSetting(e){let t=e;return this.shopifyCompatibility&&e?.startsWith("shopify://")&&(t=""),t}async getAllThemeConfigs(){if(!this.themeConfigs){let e=await this.themeLoader.loadTheme(),t=new Map;for(let i of e)t.set(i.file_path,i);this.themeConfigs=t}return this.themeConfigs}async preloadThemeConfigs(e,t){await this.themeLoader.preloadTheme(e,t)}getPageConfigPath(e){return this.shopifyCompatibility?`theme/${this.shopifyCompatibility.getThemeFilePath("templates",e)}.json`:`theme/templates/${e}.json`}async getThemeConfig(e){return this.themeConfigs?this.themeConfigs.get(e)??null:this.themeLoader.fetchThemeConfig(e)}async getThemeConfigsByPath(e,t){let i=await this.themeLoader.fetchThemeConfigsByPath(e,t),r=new Map;for(let a of i)r.set(a.file_path,a);return r}async getThemeTemplateConfig(e){if(e.endsWith(".json")||e.endsWith(".liquid"))return this.getThemeConfig(e);let t=await this.getThemeConfig(`${e}.json`);return t||this.getThemeConfig(`${e}.liquid`)}async getThemeTemplateConfigByType(e,t){let i=[`${e}/${t}`];this.shopifyCompatibility&&i.push(this.shopifyCompatibility.getThemeFilePath(e,t));for(let r of i){let a=await this.getThemeTemplateConfig(`theme/${r}`);if(a)return a}return null}async getAssetUrl(e){return(await this.getThemeConfig(`theme/assets/${e}`)||await this.getThemeConfig(`assets/${e}`))?.file?.url||null}async renderTemplate(e,t){let i=e?.file_data||null;if(e===null||i===null)return"";try{return await this.liquidSwell.parseAndRender(i,t)}catch(r){return console.error(r),`<!-- template render error: ${r.message} -->`}}async renderTemplateString(e,t){try{return await this.liquidSwell.parseAndRender(e,t)}catch(i){return console.error(i),""}}async getSectionSchema(e){let t,i=await this.getThemeTemplateConfigByType("sections",e);if(i?.file_path?.endsWith(".json"))try{t=JSON.parse(i.file_data)||void 0}catch{return}else if(i?.file_path?.endsWith(".liquid")&&this.shopifyCompatibility){this.liquidSwell.lastSchema=void 0;let r=this.getSectionConfigWithSchemaTagOnly(i);if(!r)return;await this.renderTemplate(r);let a=this.liquidSwell.lastSchema;a&&(t=this.shopifyCompatibility.getSectionConfigSchema(a),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.request?.locale))}return t.id=t.id||e,t.label=t.label||e,t.fields=t.fields||[],t}getSectionConfigWithSchemaTagOnly(e){let t="{% schema %}",i="{% endschema %}",r=e.file_data.indexOf(t),a=e.file_data.indexOf(i),o=e.file_data.slice(r+t.length,a);return r===-1||a===-1?null:{...e,file_data:t+o+i}}async renderThemeTemplate(e,t){let i=await this.getThemeTemplateConfig(e),r=await this.renderTemplate(i,{...t,template:i});if(i?.file_path?.endsWith(".json"))try{return JSON.parse(r)}catch(a){throw console.log("Unable to render theme template",i.file_path,r),new J3(a)}return r}async renderLayoutTemplate(e,t){let i=await this.getThemeTemplateConfigByType("layouts",e);if(i){let r=await this.renderThemeTemplate(i.file_path,t);return typeof r=="string"?r:`<!-- invalid layout: ${e}--> {{ content_for_layout }}`}throw new Error(`Layout template not found: ${e}`)}async renderPageTemplate(e,t,i){let r=null;if(i&&(r=await this.getThemeTemplateConfigByType("templates",`${e}.${i}`)),r||(r=await this.getThemeTemplateConfigByType("templates",e)),r){let a=await this.renderThemeTemplate(r.file_path,t);return a&&typeof a!="string"&&(a.id=r.name),a}throw console.error(new Error(`Page template not found: templates/${e}.liquid`)),new Y3}async renderPage(e,t){e&&this.setGlobals(e);let i;if(this.page?.id?i=await this.renderPageTemplate(this.page.id,e,t):i=await this.renderPageTemplate("404",e),typeof i!="string"&&i?.page){if(i.page.published===!1)throw new Y3;i.page=this.resolveTranslationLocale(i.page,this.globals.request?.locale)}return i}async renderAllSections(e,t){let i=typeof e=="string"?e.split(/\s*,\s*/):e;return(await Promise.all(i.map?.(a=>this.renderSection(a,t)))).reduce((a,o,s)=>{let l=i[s];return this.shopifyCompatibility?a[l]=`
936
936
  <div id="shopify-section-${l}" class="shopify-section">${o}</div>
937
937
  `.trim():a[l]=`
938
938
  <div id="swell-section-${l}" class="swell-section">${o}</div>