@swell/apps-sdk 1.0.67 → 1.0.68
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 +1 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -950,7 +950,7 @@ ${i}`),super(i),this.name="SwellError",this.status=t.status||500}};function q3(n
|
|
|
950
950
|
</clipPath>
|
|
951
951
|
</defs>
|
|
952
952
|
</svg>
|
|
953
|
-
`;var p6={image:N1,"product-1":L1,"product-2":A1,"product-3":b1,"product-4":T1,"product-5":_1,"product-6":M1,"collection-1":E1,"collection-2":D1,"collection-3":v1,"collection-4":P1,"collection-5":x1,"collection-6":R1,"lifestyle-1":j1,"lifestyle-2":Z1,"product-apparel-1":I1,"product-apparel-2":F1,"product-apparel-3":H1,"product-apparel-4":B1,"collection-apparel-1":q1,"collection-apparel-2":G1,"collection-apparel-3":V1,"collection-apparel-4":U1,"hero-apparel-1":O1,"hero-apparel-2":$1,"hero-apparel-3":K1,"blog-apparel-1":z1,"blog-apparel-2":W1,"blog-apparel-3":J1,"detailed-apparel-1":Y1},Q1=p6;function J5(n){return e=>{let t=Q1[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function Y5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var f6={asset_url:p5,brightness_difference:f5,color_brightness:g5,color_contrast:w5,color_darken:y5,color_desaturate:S5,color_difference:k5,color_extract:L5,color_lighten:A5,color_mix:b5,color_modify:T5,color_saturate:_5,color_to_hex:M5,color_to_hsl:E5,color_to_rgb:D5,date:Z4,default_errors:P5,divided_by:x5,font_face:R5,font_modify:j5,font_url:Z5,format_address:w1,image_tag:N5,image_url:S1,inline_asset_content:I5,json:F5,json_pretty:H5,money:B5,money_with_currency:q5,money_without_currency:G5,money_without_trailing_zeros:V5,stylesheet_tag:U5,time_tag:O5,translate:w3,t:w3,where:$5,hex_to_rgba:K5,item_count_for_variant:k1,payment_button:z5,payment_terms:W5,placeholder_svg_tag:J5,inline_editable:Y5};function ee(n){(0,X1.each)(f6,(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,g6(n,i,r))}})}function g6(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?te(o,t[s]):o));return i(...a)}:i}async function te(n,e){if(!n)return n;let t=n;t instanceof Promise&&(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];o instanceof Promise?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await te(t[r],[a.join(".")]))}}catch{}return t}var ie=require("liquidjs");var ne={...ie.defaultOperators,"==":re};function re(n,e){return M4(n)?n.equals(e):M4(e)?e.equals(n):(n=X(n),e=X(e),d4(n)?d4(e)&&w6(n,e):n==e)}function w6(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!re(t,e[i]))}var I4=l4(require("color"),1),S=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=(0,I4.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,I4.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){if(!["red","green","blue","alpha","hue","lightness","saturation"].includes(e))return this.toString();if(e==="saturation")return this.color.saturationl(t);let i=this.color[e](t);return e==="alpha"?i.string():i.hex()}extract(e){return["red","green","blue","alpha","hue","lightness","saturation"].includes(e)?e==="saturation"?this.color.saturationl():this.color[e]().toString():this.toString()}mix(e,t){let i=this.color,r=e.color,[a,o,s]=i.rgb().array(),[l,c,u]=r.rgb().array(),h=I4.default.rgb([N4(a,l,t),N4(o,c,t),N4(s,u,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 y3(t,a)+y3(i,o)+y3(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 y3(n,e){return Math.max(n,e)-Math.min(n,e)}function y6(n){let[e,t,i]=(0,I4.default)(n).rgb().array();return(e*299+t*587+i*114)/1e3}var F4=class extends Q5.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:c,isEditor:u,locale:h,currency:p,layoutName:C,extName:m,componentsDir:f,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=c||e.renderCurrency.bind(e),this.isEditor=u,this.locale=h||"en-US",this.currency=p||"USD",this.layoutName=C||"theme",this.extName=m||"liquid",this.componentsDir=f||"components",this.sectionsDir=g||"sections",this.engine=this.initLiquidEngine()}initLiquidEngine(){return this.engine=new Q5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:ne}),g1(this),ee(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 ae=l4(require("bluebird"),1);var{Promise:S3}=ae.default,S6=50,H4=class n{static cache;swell;constructor(e){this.swell=e}async loadTheme(){return this.loadThemeAllConfigs()}async preloadTheme(e,t){await S3.all([this.cacheManifest(e),S3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}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}`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)throw new Error(`Failed to resolve manifest: ${this.swell.instanceId}`);let t=[],i=new Map;if(await S3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(a=>{a?i.set(a.hash,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);await S3.map(a,o=>this.cacheThemeConfig(o),{concurrency:10})}return Array.from(i.values())}async cacheManifest(e){await this.getCache().set(`manifest:${e.hash}`,e.manifest)}async cacheThemeConfig(e){await this.getCache().set(`config:${e.hash}`,e)}async fetchManifest(){let{swellHeaders:e}=this.swell,t=e["theme-version-hash"],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 i}async fetchThemeConfigsFromSource(e=void 0){e=e||[];let{swellHeaders:t}=this.swell,i=String(t["theme-config-version"]),r=e.length===0||e.length>S6;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,fields:"type, name, file, file_path",include:{file_data:P3}})}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 _4(this.swell.workerEnv?.THEME)),n.cache}};var e2=class{swell;props;globals;forms;resources;liquidSwell;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=L4;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||L4,this.liquidSwell=new F4({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})}getSwellAppThemeProps(e){return e?.storefront?.theme||{}}async initGlobals(e){this.pageId=e;let{store:t,session:i,menus:r,geo:a,configs:o}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:c,cart:u,account:h,customer:p}=await this.resolvePageData(t,o,i,e);this.page=c;let C={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:c,cart:u,account:h,customer:p,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(C),this.setGlobals(C),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.globals={...this.globals,...e},this.liquidSwell.engine.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=x3,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getAllThemeConfigs()]),r=await Promise.all(Array.from(i.values()).filter(c=>c.file_path.startsWith("theme/config/")).map(async c=>c.file_path.endsWith(".json")?this.getThemeConfig(c.file_path):c)),a={theme:{},editor:{},translations:{},presets:[],...r.reduce((c,u)=>{let h=u?.name.split(".")[0];if(h){let p;if(u?.file_path?.endsWith(".json"))try{p=JSON.parse(u.file_data)}catch{p=null}c[h]=p}return c},{})},o=await this.swell.storefront.settings.session(),s=o.locale||t?.store?.locale;this.resolveTranslationLocale(a.translations,s),await this.setCompatibilityConfigs(a,s);let l=await this.resolveMenuSettings();return{store:t?.store,session:o,menus:l,geo:e,configs:a}}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}`,[],()=>G4(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(m=>m.id===r),c=!l,u={...l,current:this.swell.queryParams.page||1,url:this.swell.url.pathname,custom:c,slug:null,description:null};if(r){let m=await this.getThemeTemplateConfigByType("templates",r),f;try{f=JSON.parse(m?.file_data||"")}catch{}if(f?.page){let{slug:g,label:Y,description:s4}=f.page;u.slug=g,u.label=Y,u.description=s4}}let[h,p]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!h)throw new Error("Failed to fetch cart");let C;return this.shopifyCompatibility&&(C=p),{settings:o,request:s,page:u,cart:h,account:p,customer:C}}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 V(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=f4(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new V(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 W(e);i instanceof W&&(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):C4(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(D4(a))r[o]=this.resolveTranslationLocale(a,t);else if(typeof a=="string"&&a.startsWith("t:")){let s=a.slice(2),l=s.split("."),c=l.pop(),u=l.join("."),h=this.globals.translations;r[o]=(0,b.get)(h,`${u}.$locale.${t}.${c}`)||(0,b.get)(h,`${u}.$locale.${i}.${c}`)||(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=oe(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 $3(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 v(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new v(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}async getAllThemeConfigs(){if(!this.themeConfigs){let t=await new H4(this.swell).loadTheme(),i=new Map;for(let r of t)i.set(r.file_path,r);this.themeConfigs=i}return this.themeConfigs}async preloadThemeConfigs(e,t){await new H4(this.swell).preloadTheme(e,t)}getPageConfigPath(e){return this.shopifyCompatibility?`theme/${this.shopifyCompatibility.getThemeFilePath("templates",e)}.json`:`theme/templates/${e}.json`}async getThemeConfig(e){return(await this.getAllThemeConfigs()).get(e)??null}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)return"";if(i===null)return`<!-- template not found: ${e?.file_path} -->`;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 B4(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 q4}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 q4;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]=`
|
|
953
|
+
`;var p6={image:N1,"product-1":L1,"product-2":A1,"product-3":b1,"product-4":T1,"product-5":_1,"product-6":M1,"collection-1":E1,"collection-2":D1,"collection-3":v1,"collection-4":P1,"collection-5":x1,"collection-6":R1,"lifestyle-1":j1,"lifestyle-2":Z1,"product-apparel-1":I1,"product-apparel-2":F1,"product-apparel-3":H1,"product-apparel-4":B1,"collection-apparel-1":q1,"collection-apparel-2":G1,"collection-apparel-3":V1,"collection-apparel-4":U1,"hero-apparel-1":O1,"hero-apparel-2":$1,"hero-apparel-3":K1,"blog-apparel-1":z1,"blog-apparel-2":W1,"blog-apparel-3":J1,"detailed-apparel-1":Y1},Q1=p6;function J5(n){return e=>{let t=Q1[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function Y5(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var f6={asset_url:p5,brightness_difference:f5,color_brightness:g5,color_contrast:w5,color_darken:y5,color_desaturate:S5,color_difference:k5,color_extract:L5,color_lighten:A5,color_mix:b5,color_modify:T5,color_saturate:_5,color_to_hex:M5,color_to_hsl:E5,color_to_rgb:D5,date:Z4,default_errors:P5,divided_by:x5,font_face:R5,font_modify:j5,font_url:Z5,format_address:w1,image_tag:N5,image_url:S1,inline_asset_content:I5,json:F5,json_pretty:H5,money:B5,money_with_currency:q5,money_without_currency:G5,money_without_trailing_zeros:V5,stylesheet_tag:U5,time_tag:O5,translate:w3,t:w3,where:$5,hex_to_rgba:K5,item_count_for_variant:k1,payment_button:z5,payment_terms:W5,placeholder_svg_tag:J5,inline_editable:Y5};function ee(n){(0,X1.each)(f6,(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,g6(n,i,r))}})}function g6(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?te(o,t[s]):o));return i(...a)}:i}async function te(n,e){if(!n)return n;let t=n;t instanceof Promise&&(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];o instanceof Promise?t[r]=await o:typeof o?.resolve=="function"&&(t[r]=await o.resolve()),a.length>0&&(t[r]=await te(t[r],[a.join(".")]))}}catch{}return t}var ie=require("liquidjs");var ne={...ie.defaultOperators,"==":re};function re(n,e){return M4(n)?n.equals(e):M4(e)?e.equals(n):(n=X(n),e=X(e),d4(n)?d4(e)&&w6(n,e):n==e)}function w6(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!re(t,e[i]))}var I4=l4(require("color"),1),S=class n{color;colorValues;red;green;blue;constructor(e){try{this.color=(0,I4.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,I4.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){if(!["red","green","blue","alpha","hue","lightness","saturation"].includes(e))return this.toString();if(e==="saturation")return this.color.saturationl(t);let i=this.color[e](t);return e==="alpha"?i.string():i.hex()}extract(e){return["red","green","blue","alpha","hue","lightness","saturation"].includes(e)?e==="saturation"?this.color.saturationl():this.color[e]().toString():this.toString()}mix(e,t){let i=this.color,r=e.color,[a,o,s]=i.rgb().array(),[l,c,u]=r.rgb().array(),h=I4.default.rgb([N4(a,l,t),N4(o,c,t),N4(s,u,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 y3(t,a)+y3(i,o)+y3(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 y3(n,e){return Math.max(n,e)-Math.min(n,e)}function y6(n){let[e,t,i]=(0,I4.default)(n).rgb().array();return(e*299+t*587+i*114)/1e3}var F4=class extends Q5.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:c,isEditor:u,locale:h,currency:p,layoutName:C,extName:m,componentsDir:f,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=c||e.renderCurrency.bind(e),this.isEditor=u,this.locale=h||"en-US",this.currency=p||"USD",this.layoutName=C||"theme",this.extName=m||"liquid",this.componentsDir=f||"components",this.sectionsDir=g||"sections",this.engine=this.initLiquidEngine()}initLiquidEngine(){return this.engine=new Q5.Liquid({cache:!1,relativeReference:!1,fs:this.getLiquidFS(),ownPropertyOnly:!1,operators:ne}),g1(this),ee(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 ae=l4(require("bluebird"),1);var{Promise:S3}=ae.default,S6=50,H4=class n{static cache;swell;constructor(e){this.swell=e}async loadTheme(){return this.loadThemeAllConfigs()}async preloadTheme(e,t){await S3.all([this.cacheManifest(e),S3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}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}`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)throw new Error(`Failed to resolve manifest: ${this.swell.instanceId}`);let t=[],i=new Map;if(await S3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(a=>{a?i.set(a.hash,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);await S3.map(a,o=>this.cacheThemeConfig(o),{concurrency:10})}return Array.from(i.values())}async cacheManifest(e){await this.getCache().set(`manifest:${e.hash}`,e.manifest)}async cacheThemeConfig(e){await this.getCache().set(`config:${e.hash}`,e)}async fetchManifest(){let{swellHeaders:e}=this.swell,t=e["theme-version-hash"],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 i}async fetchThemeConfigsFromSource(e=void 0){e=e||[];let{swellHeaders:t}=this.swell,i=String(t["theme-config-version"]),r=e.length===0||e.length>S6;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,fields:"type, name, file, file_path",include:{file_data:P3}})}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 _4(this.swell.workerEnv?.THEME)),n.cache}};var e2=class{swell;props;globals;forms;resources;liquidSwell;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=L4;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||L4,this.liquidSwell=new F4({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})}getSwellAppThemeProps(e){return e?.storefront?.theme||{}}async initGlobals(e){this.pageId=e;let{store:t,session:i,menus:r,geo:a,configs:o}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:c,cart:u,account:h,customer:p}=await this.resolvePageData(t,o,i,e);this.page=c;let C={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:c,cart:u,account:h,customer:p,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(C),this.setGlobals(C),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.globals={...this.globals,...e},this.liquidSwell.engine.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=x3,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getAllThemeConfigs()]),r=await Promise.all(Array.from(i.values()).filter(c=>c.file_path.startsWith("theme/config/")).map(async c=>c.file_path.endsWith(".json")?this.getThemeConfig(c.file_path):c)),a={theme:{},editor:{},translations:{},presets:[],...r.reduce((c,u)=>{let h=u?.name.split(".")[0];if(h){let p;if(u?.file_path?.endsWith(".json"))try{p=JSON.parse(u.file_data)}catch{p=null}c[h]=p}return c},{})},o=await this.swell.storefront.settings.session(),s=o.locale||t?.store?.locale;this.resolveTranslationLocale(a.translations,s),await this.setCompatibilityConfigs(a,s);let l=await this.resolveMenuSettings();return{store:t?.store,session:o,menus:l,geo:e,configs:a}}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}`,[],()=>G4(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(m=>m.id===r),c=!l,u={...l,current:this.swell.queryParams.page||1,url:this.swell.url.pathname,custom:c,slug:null,description:null};if(r){let m=await this.getThemeTemplateConfigByType("templates",r),f;try{f=JSON.parse(m?.file_data||"")}catch{}if(f?.page){let{slug:g,label:Y,description:s4}=f.page;u.slug=g,u.label=Y,u.description=s4}}let[h,p]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!h)throw new Error("Failed to fetch cart");let C;return this.shopifyCompatibility&&(C=p),{settings:o,request:s,page:u,cart:h,account:p,customer:C}}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 V(this.swell,"cart");if(await t.id,!t?.id)return{};if(this.shopifyCompatibility){let i=f4(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new V(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 W(e);i instanceof W&&(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):C4(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(D4(a))r[o]=this.resolveTranslationLocale(a,t);else if(typeof a=="string"&&a.startsWith("t:")){let s=a.slice(2),l=s.split("."),c=l.pop(),u=l.join("."),h=this.globals.translations;r[o]=(0,b.get)(h,`${u}.$locale.${t}.${c}`)||(0,b.get)(h,`${u}.$locale.${i}.${c}`)||(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=oe(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 $3(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 v(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return new v(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}async getAllThemeConfigs(){if(!this.themeConfigs){let t=await new H4(this.swell).loadTheme(),i=new Map;for(let r of t)i.set(r.file_path,r);this.themeConfigs=i}return this.themeConfigs}async preloadThemeConfigs(e,t){await new H4(this.swell).preloadTheme(e,t)}getPageConfigPath(e){return this.shopifyCompatibility?`theme/${this.shopifyCompatibility.getThemeFilePath("templates",e)}.json`:`theme/templates/${e}.json`}async getThemeConfig(e){return(await this.getAllThemeConfigs()).get(e)??null}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)return"";if(i===null)return`<!-- template not found: ${e?.file_path} -->`;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 B4(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",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 q4}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 q4;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]=`
|
|
954
954
|
<div id="shopify-section-${l}" class="shopify-section">${o}</div>
|
|
955
955
|
`.trim():a[l]=`
|
|
956
956
|
<div id="swell-section-${l}" class="swell-section">${o}</div>
|