@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.cjs CHANGED
@@ -932,7 +932,7 @@
932
932
  </clipPath>
933
933
  </defs>
934
934
  </svg>
935
- `;var Mt={image:i1,"product-1":G2,"product-2":V2,"product-3":O2,"product-4":U2,"product-5":$2,"product-6":K2,"collection-1":z2,"collection-2":W2,"collection-3":J2,"collection-4":Y2,"collection-5":Q2,"collection-6":X2,"lifestyle-1":e1,"lifestyle-2":t1,"product-apparel-1":n1,"product-apparel-2":r1,"product-apparel-3":a1,"product-apparel-4":o1,"collection-apparel-1":s1,"collection-apparel-2":l1,"collection-apparel-3":h1,"collection-apparel-4":d1,"hero-apparel-1":c1,"hero-apparel-2":u1,"hero-apparel-3":C1,"blog-apparel-1":m1,"blog-apparel-2":p1,"blog-apparel-3":f1,"detailed-apparel-1":g1},w1=Mt;function v5(n){return e=>{let t=w1[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function D5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var Et={asset_url:z4,brightness_difference:W4,color_brightness:J4,color_contrast:Y4,color_darken:Q4,color_desaturate:X4,color_difference:e5,color_extract:t5,color_lighten:i5,color_mix:n5,color_modify:r5,color_saturate:a5,color_to_hex:o5,color_to_hsl:s5,color_to_rgb:l5,date:D3,default_errors:d5,divided_by:c5,font_face:u5,font_modify:C5,font_url:m5,format_address:F2,image_tag:p5,image_url:B2,inline_asset_content:f5,json:g5,json_pretty:w5,money:y5,money_with_currency:S5,money_without_currency:k5,money_without_trailing_zeros:L5,stylesheet_tag:A5,time_tag:b5,translate:i4,t:i4,where:T5,hex_to_rgba:_5,item_count_for_variant:q2,payment_button:M5,payment_terms:E5,placeholder_svg_tag:v5,inline_editable:D5};function S1(n){(0,y1.each)(Et,(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,vt(n,i,r))}})}function vt(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?k1(o,t[s]):o));return i(...a)}:i}async function k1(n,e){if(!n)return n;let t=n;D(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];D(o)?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await k1(t[r],[a.join(".")]))}}catch{}return t}var L1=require("liquidjs");var A1={...L1.defaultOperators,"==":b1};function b1(n,e){return E3(n)?n.equals(e):E3(e)?e.equals(n):(n=e3(n),e=e3(e),c3(n)?c3(e)&&Dt(n,e):n==e)}function Dt(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!b1(t,e[i]))}var r4=h3(require("color"),1),S=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=Pt(e)?e.color:(0,r4.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,r4.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=r4.default.rgb([n4(a,l,t),n4(o,u,t),n4(s,c,t)]).alpha(n4(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 P5(t,a)+P5(i,o)+P5(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 n4(n,e,t){return(n*t+e*(100-t))/100}function P5(n,e){return Math.max(n,e)-Math.min(n,e)}function Pt(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 P3=class extends x5.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 x5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:A1}),I2(this),S1(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 R5=require("lodash-es");async function j5(n,e,t){let r=(await Promise.all(e?.map(async a=>({...a,items:await Z5(n,a.items,t)})))).map(a=>(n.shopifyCompatibility&&Object.assign(a,n.shopifyCompatibility.getMenuData(a)),a))||[];return I5([...r,...n.shopifyCompatibility?r.map(a=>{if(a.handle)return{...a,id:a.handle}}).filter(Boolean):[]])}async function Z5(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:a,resource:o}=await T1(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await Z5(n,r.items,t);return{...r,url:a,resource:o,levels:_1(s),current:t?.currentUrl===a,active:t?.currentUrl?.startsWith(a),...s?{items:s,child_current:xt(s),child_active:N5(s)}:void 0}})):[]}async function T1(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await E1(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 _1(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+_1(t.items):0),0)||0}function xt(n){return n.some(e=>e.current||e.items&&N5(e.items))}function N5(n){return n.some(e=>e.active||e.items&&N5(e.items))}function M1(n){return(0,R5.get)(n,"id",(0,R5.get)(n,"slug",typeof n=="string"?n:""))||""}async function E1(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=M1(i);switch(t){case"home":return{url:a3(n,"index")};case"category":return o?await r3(n,"categories/category",o):{url:a3(n,"categories/index")};case"product":return o?await r3(n,"products/product",o):{url:a3(n,"products/index")};case"page":return await r3(n,"pages/page",o);case"blog":return await r3(n,"blogs/blog",o,async s=>new _(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await r3(n,"blogs/category",o);case"content_list":if(a){let s=a?.replace("content/","");return{url:a3(n,"content/index",s),resource:new A(n.swell,a)}}break;case"content":if(a){let s=a?.replace("content/","");return await r3(n,"content/content",o,s)}break;case"search":return{url:a3(n,"search")};default:break}return{url:`/${o}`}}function a3(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 r3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(u=>u.id===e)?.collection,o=a?new _(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:a3(n,e,s,typeof l=="string"?l:void 0),resource:o}}var v1=h3(require("bluebird"),1);var{Promise:x3}=v1.default,Rt=50,a4=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 x3.all([e&&this.cacheManifest(e),t&&x3.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 x3.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 x3.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 x3.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>Rt;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:Q3}})}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:Q3}});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 M3(this.swell.workerEnv?.THEME)),n.cache}};var H5=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=f3;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||f3,this.liquidSwell=new P3({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 a4(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=P4,[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}`,[],()=>Z3(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:Q,description:l3}=p.page;c.slug=g,c.label=Q,c.description=l3}}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 J(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=C3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new J(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=K(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 O(e);i instanceof O&&(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):g3(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(N3(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 T)return t;let i=D1(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 _(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return j5(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 P(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new P(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 R3(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 j3}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 j3;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 Mt={image:i1,"product-1":G2,"product-2":V2,"product-3":O2,"product-4":U2,"product-5":$2,"product-6":K2,"collection-1":z2,"collection-2":W2,"collection-3":J2,"collection-4":Y2,"collection-5":Q2,"collection-6":X2,"lifestyle-1":e1,"lifestyle-2":t1,"product-apparel-1":n1,"product-apparel-2":r1,"product-apparel-3":a1,"product-apparel-4":o1,"collection-apparel-1":s1,"collection-apparel-2":l1,"collection-apparel-3":h1,"collection-apparel-4":d1,"hero-apparel-1":c1,"hero-apparel-2":u1,"hero-apparel-3":C1,"blog-apparel-1":m1,"blog-apparel-2":p1,"blog-apparel-3":f1,"detailed-apparel-1":g1},w1=Mt;function v5(n){return e=>{let t=w1[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function D5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var Et={asset_url:z4,brightness_difference:W4,color_brightness:J4,color_contrast:Y4,color_darken:Q4,color_desaturate:X4,color_difference:e5,color_extract:t5,color_lighten:i5,color_mix:n5,color_modify:r5,color_saturate:a5,color_to_hex:o5,color_to_hsl:s5,color_to_rgb:l5,date:D3,default_errors:d5,divided_by:c5,font_face:u5,font_modify:C5,font_url:m5,format_address:F2,image_tag:p5,image_url:B2,inline_asset_content:f5,json:g5,json_pretty:w5,money:y5,money_with_currency:S5,money_without_currency:k5,money_without_trailing_zeros:L5,stylesheet_tag:A5,time_tag:b5,translate:i4,t:i4,where:T5,hex_to_rgba:_5,item_count_for_variant:q2,payment_button:M5,payment_terms:E5,placeholder_svg_tag:v5,inline_editable:D5};function S1(n){(0,y1.each)(Et,(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,vt(n,i,r))}})}function vt(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?k1(o,t[s]):o));return i(...a)}:i}async function k1(n,e){if(!n)return n;let t=n;D(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];D(o)?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await k1(t[r],[a.join(".")]))}}catch{}return t}var L1=require("liquidjs");var A1={...L1.defaultOperators,"==":b1};function b1(n,e){return E3(n)?n.equals(e):E3(e)?e.equals(n):(n=e3(n),e=e3(e),c3(n)?c3(e)&&Dt(n,e):n==e)}function Dt(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!b1(t,e[i]))}var r4=h3(require("color"),1),S=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=Pt(e)?e.color:(0,r4.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,r4.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=r4.default.rgb([n4(a,l,t),n4(o,u,t),n4(s,c,t)]).alpha(n4(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 P5(t,a)+P5(i,o)+P5(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 n4(n,e,t){return(n*t+e*(100-t))/100}function P5(n,e){return Math.max(n,e)-Math.min(n,e)}function Pt(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 P3=class extends x5.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 x5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:A1}),I2(this),S1(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 R5=require("lodash-es");async function j5(n,e,t){let r=(await Promise.all(e?.map(async a=>({...a,items:await Z5(n,a.items,t)})))).map(a=>(n.shopifyCompatibility&&Object.assign(a,n.shopifyCompatibility.getMenuData(a)),a))||[];return I5([...r,...n.shopifyCompatibility?r.map(a=>{if(a.handle)return{...a,id:a.handle}}).filter(Boolean):[]])}async function Z5(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:a,resource:o}=await T1(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await Z5(n,r.items,t);return{...r,url:a,resource:o,levels:_1(s),current:t?.currentUrl===a,active:t?.currentUrl?.startsWith(a),...s?{items:s,child_current:xt(s),child_active:N5(s)}:void 0}})):[]}async function T1(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await E1(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 _1(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+_1(t.items):0),0)||0}function xt(n){return n.some(e=>e.current||e.items&&N5(e.items))}function N5(n){return n.some(e=>e.active||e.items&&N5(e.items))}function M1(n){return(0,R5.get)(n,"id",(0,R5.get)(n,"slug",typeof n=="string"?n:""))||""}async function E1(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=M1(i);switch(t){case"home":return{url:a3(n,"index")};case"category":return o?await r3(n,"categories/category",o):{url:a3(n,"categories/index")};case"product":return o?await r3(n,"products/product",o):{url:a3(n,"products/index")};case"page":return await r3(n,"pages/page",o);case"blog":return await r3(n,"blogs/blog",o,async s=>new _(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await r3(n,"blogs/category",o);case"content_list":if(a){let s=a?.replace("content/","");return{url:a3(n,"content/index",s),resource:new A(n.swell,a)}}break;case"content":if(a){let s=a?.replace("content/","");return await r3(n,"content/content",o,s)}break;case"search":return{url:a3(n,"search")};default:break}return{url:`/${o}`}}function a3(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 r3(n,e,t,i){let{props:r}=n,a=r?.pages?.find(u=>u.id===e)?.collection,o=a?new _(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:a3(n,e,s,typeof l=="string"?l:void 0),resource:o}}var v1=h3(require("bluebird"),1);var{Promise:x3}=v1.default,Rt=50,a4=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 x3.all([e&&this.cacheManifest(e),t&&x3.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 x3.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 x3.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 x3.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>Rt;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:Q3}})}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:Q3}});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 M3(this.swell.workerEnv?.THEME)),n.cache}};var H5=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=f3;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||f3,this.liquidSwell=new P3({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 a4(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=P4,[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}`,[],()=>Z3(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:Q,description:l3}=p.page;c.slug=g,c.label=Q,c.description=l3}}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 J(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=C3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new J(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=K(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 O(e);i instanceof O&&(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):g3(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(N3(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 T)return t;let i=D1(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 _(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return j5(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 P(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new P(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 R3(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 j3}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 j3;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>