@swell/apps-sdk 1.0.115 → 1.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -926,7 +926,7 @@ var W2=Object.defineProperty;var J2=(n,e)=>{for(var t in e)W2(n,t,{get:e[t],enum
926
926
  </clipPath>
927
927
  </defs>
928
928
  </svg>
929
- `;var J1={image:V5,"product-1":v5,"product-2":R5,"product-3":D5,"product-4":x5,"product-5":j5,"product-6":Z5,"collection-1":F5,"collection-2":N5,"collection-3":I5,"collection-4":H5,"collection-5":B5,"collection-6":G5,"lifestyle-1":q5,"lifestyle-2":O5,"product-apparel-1":U5,"product-apparel-2":$5,"product-apparel-3":K5,"product-apparel-4":z5,"collection-apparel-1":W5,"collection-apparel-2":J5,"collection-apparel-3":Y5,"collection-apparel-4":Q5,"hero-apparel-1":X5,"hero-apparel-2":e2,"hero-apparel-3":t2,"blog-apparel-1":i2,"blog-apparel-2":n2,"blog-apparel-3":r2,"detailed-apparel-1":o2},a2=J1;function _e(n){return e=>{let t=a2[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function Me(n){return function(t){if(typeof t=="string")switch(t){case"option_selection.js":return"https://cdn.shopify.com/s/shopify/option_selection.js";case"api.jquery.js":return"https://cdn.shopify.com/s/shopify/api.jquery.js";case"shopify_common.js":return"https://cdn.shopify.com/s/shopify/shopify_common.js";case"customer_area.js":return"https://cdn.shopify.com/s/shopify/customer_area.js";case"currencies.js":return"https://cdn.shopify.com/s/javascripts/currencies.js";case"customer.css":return"https://cdn.shopify.com/s/shopify/customer.css";default:break}return t}}function Pe(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var Y1={asset_url:q4,brightness_difference:O4,color_brightness:V4,color_contrast:U4,color_darken:$4,color_desaturate:K4,color_difference:z4,color_extract:W4,color_lighten:J4,color_mix:Y4,color_modify:Q4,color_saturate:X4,color_to_hex:ee,color_to_hsl:te,color_to_rgb:ie,date:S3,default_errors:re,divided_by:oe,font_face:ae,font_modify:se,font_url:le,format_address:g5,image_tag:ce,image_url:_5,inline_asset_content:he,json:de,json_pretty:ue,locale_flag:me,money:pe,money_with_currency:Ce,money_without_currency:fe,money_without_trailing_zeros:ge,script_tag:we,stylesheet_tag:ye,time_tag:Se,translate:V3,t:V3,where:ke,asset_img_url:Le,hex_to_rgba:be,item_count_for_variant:E5,payment_button:Ae,payment_terms:Te,placeholder_svg_tag:_e,shopify_asset_url:Me,inline_editable:Pe};function s2(n){for(let[e,t]of Object.entries(Y1))typeof t=="function"?n.registerFilter(e,t(n)):typeof t.bind=="function"&&n.registerFilter(e,Q1(n,t.bind,t.resolve))}function Q1(n,e,t=[]){let i=e(n);return Array.isArray(t)?async function(...r){let[o,...a]=await Promise.all(r.map((s,l)=>Array.isArray(t[l])||t[l]===!0?l2(s,t[l]):s));return i.call(this,o,...a)}:i}async function l2(n,e){if(!n)return n;let t=n;P(t)&&(t=await t);try{if(Array.isArray(e))for(let i of e){if(typeof i!="string")continue;let[r,...o]=i.split("."),a=t[r];R(a)&&(P(a)?t[r]=await a:l3(a.resolve)&&(t[r]=await a.resolve())),o.length>0&&(t[r]=await l2(t[r],[o.join(".")]))}}catch{}return t}import{defaultOperators as X1}from"liquidjs";var c2={...X1,"==":U3,"!=":(n,e)=>!U3(n,e),contains:(n,e)=>(n=Y(n),c3(n)?n.some(t=>U3(t,e)):l3(n?.indexOf)?n.indexOf(Y(e))>-1:!1)};function U3(n,e){return f3(n)?n.equals(e):f3(e)?e.equals(n):(n=Y(n),e=Y(e),c3(n)?c3(e)&&ei(n,e):n==e)}function ei(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!U3(t,e[i]))}import $3 from"color";import{Drop as ti}from"liquidjs";var S=class n extends ti{color;colorValues;red;green;blue;constructor(e){super();try{this.color=h2(e)?typeof e.color.object=="function"?e.color:$3(e.colorValues):$3(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=$3("#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)}static clone(e){return h2(e)?new n(n.get(e).toString()):new n(e)}toString(){return this.color.string()}valueOf(){return this.toString()}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,[o,a,s]=i.rgb().array(),[l,h,u]=r.rgb().array(),c=$3.rgb([K3(o,l,t),K3(a,h,t),K3(s,u,t)]).alpha(K3(i.alpha(),r.alpha(),t));return i.alpha()!==1?c.string():c.hex()}contrast(e){return this.color.contrast(e.color).toFixed(1)}difference(e){let[t,i,r]=this.color.rgb().array(),[o,a,s]=e.color.rgb().array();return Ee(t,o)+Ee(i,a)+Ee(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 K3(n,e,t){return(n*t+e*(100-t))/100}function Ee(n,e){return Math.max(n,e)-Math.min(n,e)}function h2(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 W3=class extends ii{theme;getThemeConfig;getThemeTemplateConfigByType;getAssetUrl;renderTemplate;renderTemplateString;renderPageSections;renderTranslation;renderCurrency;isEditor;locale;currency;layoutName;extName;componentsDir;sectionsDir;lastSchema;constructor({theme:e,getThemeConfig:t,getThemeTemplateConfigByType:i,getAssetUrl:r,renderTemplate:o,renderTemplateString:a,renderPageSections:s,renderTranslation:l,renderCurrency:h,isEditor:u,locale:c,currency:C,layoutName:m,extName:f,componentsDir:p,sectionsDir:g}){t=t||e.getThemeConfig.bind(e),f=f||"liquid",super({cache:!1,relativeReference:!1,fs:ni(t,f),ownPropertyOnly:!1,operators:c2}),this.theme=e,this.getThemeConfig=t,this.getThemeTemplateConfigByType=i||e.getThemeTemplateConfigByType.bind(e),this.getAssetUrl=r||e.getAssetUrl.bind(e),this.renderTemplate=o||e.renderTemplate.bind(e),this.renderTemplateString=a||e.renderTemplateString.bind(e),this.renderPageSections=s||e.renderPageSections.bind(e),this.renderTranslation=l||e.renderTranslation.bind(e),this.renderCurrency=h||e.renderCurrency.bind(e),this.isEditor=!!u,this.locale=c||"en-US",this.currency=C||"USD",this.layoutName=m||"theme",this.extName=f,this.componentsDir=p||"components",this.sectionsDir=g||"sections",this.lastSchema=void 0,f5(this),s2(this)}async parseAndRender(e,t){return super.parseAndRender(e,t)}async resolveFilePathByType(e,t){let i=await this.getThemeTemplateConfigByType(e,t);if(i?.file_path)return i.file_path}async getComponentPath(e){return await this.resolveFilePathByType("components",e)||z3(`${this.componentsDir}/${e}`,this.extName)}async getSectionPath(e){return await this.resolveFilePathByType("sections",e)||z3(`${this.sectionsDir}/${e}`,this.extName)}async getSectionGroupPath(e){return await this.resolveFilePathByType("sections",`${e}.json`)||z3(`${this.sectionsDir}/${e}`,"json")}};function z3(n,e){return`theme/${n}.${e}`}function ni(n,e){return{async readFile(t){let i=z3(t,e);return n(i).then(r=>r?.file_data||`<!-- theme template not found: ${i} -->`)},async exists(t){return!0},readFileSync(t){return""},existsSync(t){return!1},contains(t,i){return!0},resolve(t,i,r){return i},fallback(t){}}}import{get as d2}from"lodash-es";async function u2(n,e,t){let r=(await Promise.all(e?.map(async o=>({...o,items:await m2(n,o.items,t)})))).map(o=>(n.shopifyCompatibility&&Object.assign(o,n.shopifyCompatibility.getMenuData(o)),o))||[];return C2([...r,...n.shopifyCompatibility?r.reduce((o,a)=>(a.handle&&o.push({...a,id:a.handle}),o),[]):[]])}async function m2(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:o,resource:a}=await ri(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await m2(n,r.items,t);return{...r,url:o,resource:a,levels:p2(s),current:t?.currentUrl===o,active:t?.currentUrl?.startsWith(o),...s?{items:s,child_current:oi(s),child_active:ve(s)}:void 0}})):[]}async function ri(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await si(n,e),o=i.slice(-1)==="/";return t?.trailingSlash&&!o&&i.length>1&&(i=i+"/"),!t?.trailingSlash&&o&&i.length>1&&(i=i.slice(0,-1)),{url:i,resource:r}}else return{url:e}}function p2(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+p2(t.items):0),0)||0}function oi(n){return n.some(e=>e.current||e.items&&ve(e.items))}function ve(n){return n.some(e=>e.active||e.items&&ve(e.items))}function ai(n){return d2(n,"id",d2(n,"slug",typeof n=="string"?n:""))||""}async function si(n,e){let{type:t,value:i,url:r,model:o}=e;if(typeof t>"u"&&r)return{url:r};if(t==="url")return{url:typeof i=="string"?i:""};let a=ai(i);switch(t){case"home":return{url:p3(n,"index")};case"category":return a?await m3(n,"categories/category",a):{url:p3(n,"categories/index")};case"product":return a?await m3(n,"products/product",a):{url:p3(n,"products/index")};case"page":return await m3(n,"pages/page",a);case"blog":return await m3(n,"blogs/blog",a,async s=>new A(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await m3(n,"blogs/category",a);case"content_list":if(o){let s=o?.replace("content/","");return{url:p3(n,"content/index",s),resource:new b(n.swell,o)}}break;case"content":if(o){let s=o?.replace("content/","");return await m3(n,"content/content",a,s)}break;case"search":return{url:p3(n,"search")};default:break}return{url:`/${a}`}}function p3(n,e,t,i){let{props:r}=n,o=r?.pages?.find(a=>a.id===e)?.url;return o?.includes(":collection")&&i&&(o=o.replace(":collection",i)),o?.includes(":slug")&&(o=o.replace(":slug",t||"")),o||`/${t||""}`}async function m3(n,e,t,i){let{props:r}=n,o=r?.pages?.find(h=>h.id===e)?.collection,a=o?new A(n.swell,o,t):void 0,s=await a?.slug||t,l=typeof i=="string"?i:void 0;return a?.id&&typeof i=="function"&&(l=await i(a)),{url:p3(n,e,s,typeof l=="string"?l:void 0),resource:a}}import li from"bluebird";var{Promise:L3}=li,ci=50,J3=class n{static cache=null;swell;manifest;configs;configPaths;constructor(e){this.swell=e,this.manifest=null,this.configs=new Map,this.configPaths=[]}async init(e){let{swellHeaders:t}=this.swell;if(e){this.setConfigs(e);return}t["theme-id"]&&(await this.fetchManifest(),this.manifest===null&&(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()}getCache(){return n.cache===null&&(n.cache=new b3({kvStore:this.swell.workerEnv?.THEME})),n.cache}setConfigs(e){this.configs=new Map(e),this.configPaths=Array.from(this.configs.keys()),this.manifest=this.configPaths.reduce((t,i)=>(t[i]=this.configs.get(i)?.hash,t),{})}async preloadTheme(e,t){console.log(`ThemeLoader.preloadTheme${e?.hash?` - manifest: ${e.hash}`:""}${t?.length?` - configs: ${t.length}`:""}`),await L3.all([e&&this.cacheManifest(e),t&&L3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}async fetchThemeConfig(e){let t=this.configs.get(e);if(t!==void 0)return t;let i=this.manifest?.[e];if(i){let r=await this.getCache().get(`config:${i}`);return r?(this.configs.set(e,r),r):this.fetchThemeConfigsFromSourceByPath(e,i)}return null}async fetchThemeConfigsByPath(e,t){let i=this.configPaths.filter(o=>o.startsWith(e)&&(!t||o.endsWith(t)));return(await L3.map(i,o=>this.fetchThemeConfig(o),{concurrency:10})).filter(o=>o!==null)}async loadThemeAllConfigs(){let{swellHeaders:e}=this.swell,t=String(e["theme-config-version"]);if(!t)throw new Error("Theme version is required");return(await this.getCache().fetch(`configs-all:${this.swell.instanceId}:v@${t}2`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)return null;let t=[],i=new Map;if(await L3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(o=>{o?(i.set(o.hash,o),this.configs.set(o.file_path,o)):t.push(r)}),{concurrency:10}),t.length>0){let o=(await this.fetchThemeConfigsFromSource(i.size===0?void 0:t))?.results??[];for(let a of o)i.set(a.hash,a),this.configs.set(a.file_path,a);await L3.map(o,a=>this.cacheThemeConfig(a),{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>ci;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:S4}})}async fetchThemeConfigsFromSourceByPath(e,t){console.log(`Retrieving theme config - ${e}`);let i=await this.swell.get("/:themes:configs/:last",{...this.themeVersionQueryFilter(),file_path:e,fields:"name, file, file_path, hash",include:{file_data:S4}});return i&&(this.configs.set(e,i),t&&(i.hash=t),await this.cacheThemeConfig(i)),i??null}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}}}};var f2=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=A3;shopifyCompatibilityConfig=null;formData={};globalData={};themeSettingFilePath="theme/config/theme.json";constructor(e,t={}){let{forms:i,resources:r,globals:o,shopifyCompatibilityClass:a}=t;this.swell=e,this.props=this.getSwellAppThemeProps(e.config),this.shopifyCompatibilityConfig=e.shopifyCompatibilityConfig||null,this.globals=o||{},this.forms=i,this.resources=r,this.shopifyCompatibilityClass=a||A3,this.liquidSwell=new W3({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),renderPageSections:this.renderPageSections.bind(this),renderTranslation:this.lang.bind(this),renderCurrency:this.renderCurrency.bind(this),isEditor:e.isEditor}),this.themeLoader=new J3(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:o,configs:a}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:h,cart:u,account:c,customer:C}=await this.resolvePageData(t,a,e);this.page=h;let m={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:h,cart:u,account:c,customer:C,geo:o,configs:a,language:a?.language,canonical_url:`${t.url}${this.swell.url?.pathname||""}`,shopify_compatibility:!!s.shopify_compatibility};this.shopifyCompatibility&&this.shopifyCompatibility.initGlobals(m),this.setGlobals(m),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.shopifyCompatibility&&this.shopifyCompatibility.adaptGlobals(e,this.globals),this.globals={...this.globals,...e},this.liquidSwell.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=h5,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getThemeConfigsByPath("theme/config/",".json")]),r={theme:{},editor:{},language:{},presets:[],...Array.from(i.values()).reduce((s,l)=>{let h=String(l?.name||"").split(".")[0];if(h){let u;try{u=n3.parse(l.file_data)}catch(c){console.error(`Error parsing ${h} config: ${c}`),u={}}s[h]=u}return s},{})},o=await this.swell.storefront.settings.session();if(r.translations&&(r.language=r.translations),Object.keys(r.language).length>0)r.language=this.resolveTranslationLocale(r.language);else{let{locale:s}=this.swell.getStorefrontLocalization();r.language=await this.getLocaleConfig(s)}await this.setCompatibilityConfigs(r);let a=await this.resolveMenuSettings();return{store:t?.store,session:o,menus:a,geo:e,configs:r}}async resolvePageData(e,t,i){let r=String(this.swell.swellHeaders["theme-config-version"]),o=await this.swell.getCachedResource(`theme-settings-resolved:v@${r}`,[],()=>(t.editor?.settings&&mi(t.theme,t.editor?.settings),e4(this,t.theme,t.editor?.settings)));if(!o)throw new Error("Failed to resolve theme settings");let{locale:a,currency:s}=this.swell.getStorefrontLocalization(),l={host:this.swell.url.host,origin:this.swell.url.origin,path:this.swell.url.pathname,query:this.swell.queryParams,locale:a||e.locale,currency:s||e.currency,is_editor:this.swell.isEditor,is_preview:this.swell.isPreview},h=this.props.pages?.find(f=>f.id===i),u={...h,current:Number(this.swell.queryParams.page)||1,url:this.swell.url.pathname,custom:!h,slug:void 0,description:void 0,$locale:void 0};if(i){let f=await this.getThemeTemplateConfigByType("templates",i),p;try{p=n3.parse(f?.file_data||"{}")}catch(g){console.warn(g)}if(p?.page){let{slug:g,label:I,description:W,$locale:a3}=p.page;u.slug=g,u.label=I||u.label,u.description=W,u.$locale=a3}}let[c,C]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!c)throw new Error("Failed to fetch cart");let m;return this.shopifyCompatibility&&(m=C),{settings:o,request:l,page:u,cart:c,account:C,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 Q(this.swell,"cart");if(t._isEmpty=function(){return!this._result?.items?.length},await t.id,this.shopifyCompatibility){let i=w3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new Q(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=i3(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 e3(e);i instanceof e3&&(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):T3(e,t)}resolveTranslationLocale(e,t){if(!e)return{};if(t=t||this.swell.getStorefrontLocalization().locale,!t)return e;let i=t.split("-")[0];return di(e,(r,o,a)=>{if(v(o))if(a==="$locale")for(let s of Object.keys(o)){let l=o[s];v(l)&&Object.assign(r,this.resolveTranslationLocale(l,t))}else a[0]!=="$"&&(r[a]=this.resolveTranslationLocale(o,t));else if(typeof o=="string")if(o.startsWith("t:")){let s=o.slice(2),l=s.split("."),h=l.pop(),u=l.join("."),c=this.globals.language;r[a]=K(c,`${u}.$locale.${t}.${h}`)||K(c,`${u}.$locale.${i}.${h}`)||K(c,s)||o}else r[a]=K(e,`$locale.${t}.${a}`)||K(e,`$locale.${i}.${a}`)||o;return r},{})}async setCompatibilityConfigs(e){let t=()=>(this.shopifyCompatibility||(this.shopifyCompatibility=new this.shopifyCompatibilityClass(this)),this.shopifyCompatibility);if(!Object.keys(e.editor).length&&e.settings_schema){let i=await this.swell.storefront.settings.get("store");e.editor=t().getEditorConfig(e.settings_schema),e.editor=await t().renderSchemaTranslations(this,e.editor,i.locale||"en-US")}!Object.keys(e.theme).length&&e.settings_data&&(e.theme=t().getThemeConfig(e.settings_data),this.themeSettingFilePath="theme/config/settings_data.json"),!Object.keys(e.presets).length&&e.settings_data&&(e.presets=t().getPresetsConfig(e.settings_data)),e.theme.shopify_compatibility?t():this.shopifyCompatibility&&(e.theme.shopify_compatibility=!0)}setCompatibilityData(e){!e||!this.shopifyCompatibility||this.shopifyCompatibility.adaptPageData(e)}async getLocaleConfig(e="en",t=".json"){let i=await this.getThemeConfigsByPath("theme/locales/",t),r=i.get(`theme/locales/${e}${t}`)??null;if(!r){let o=e.split("-")[0];if(r=i.get(`theme/locales/${o}${t}`)??null,!r){let a=`.default${t}`;for(let s of i.values())if(s.file_path?.endsWith(a)){r=s;break}}}if(r){r=await this.getThemeConfig(r.file_path);try{return n3.parse(r?.file_data||"{}")}catch(o){console.warn(o)}}return{}}resolveLookupSetting(e,t){if(t instanceof _)return t;let i=pi(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 A(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return u2(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=D.get(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return D.get(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===null){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 o of i)r.set(o.file_path,o);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 o=await this.getThemeTemplateConfig(`theme/${r}`);if(o)return o}return null}async getAssetUrl(e){let i=(await this.getThemeConfig(`theme/assets/${e}`)||await this.getThemeConfig(`assets/${e}`))?.file;if(!i)return null;let r=i.url||null;return r&&(r.endsWith(e)?r:`${r}/${e}`)}async renderTemplate(e,t){let i=e?.file_data||null;if(e===null||i===null)return"";i=gi(i);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=n3.parse(i.file_data)||void 0,this.shopifyCompatibility&&(t=this.shopifyCompatibility.getSectionConfigSchema(t),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.store?.locale))}catch(r){console.warn(r);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 o=this.liquidSwell.lastSchema;o&&(t=this.shopifyCompatibility.getSectionConfigSchema(o),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.store?.locale))}return t&&(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),o=e.file_data.indexOf(i),a=e.file_data.slice(r+t.length,o);return r===-1||o===-1?null:{...e,file_data:t+a+i}}async renderThemeTemplate(e,t){let i=await this.getThemeTemplateConfig(e),r=await this.renderTemplate(i,t);if(i?.file_path?.endsWith(".json"))try{return n3.parse(r)}catch(o){throw console.log("Unable to render theme template",i.file_path,r),new Q3(o)}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 o=e.split("/").splice(1).join("/")||null,a={name:e,alt_name:i||null,path:o||null};this.shopifyCompatibility&&(a=f4(this.shopifyCompatibility,a)),this.setGlobals({template:a});let s=await this.renderThemeTemplate(r.file_path,t);return s&&typeof s!="string"&&(s.id=String(r.name)),s}throw new X3("Page template not found",404,`templates/${e}`)}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 X3;i.page=this.resolveTranslationLocale(i.page)}return i}getShopify1HomePageSectionGroup(){let e=this.globals.configs.theme||{};return{sections:e.sections||{},order:e.content_for_index||[]}}async getShopify1HomePageSections(e=!0){let t=this.getShopify1HomePageSectionGroup();return this.getPageSections(t,e)}async renderShopify1HomePage(e){let t=this.getShopify1HomePageSectionGroup(),i=await this.renderPageSections(t);return this.renderTemplateString(e,{content_for_index:i})}isShopify1HomePage(e,t){return e==="index"&&typeof t=="string"}async renderAllSections(e,t){let i=typeof e=="string"?e.split(/\s*,\s*/):e;return(await Promise.all(i.map(o=>this.renderSection(o,t)))).reduce((o,a,s)=>{let l=i[s];return this.shopifyCompatibility?o[l]=`
929
+ `;var J1={image:V5,"product-1":v5,"product-2":R5,"product-3":D5,"product-4":x5,"product-5":j5,"product-6":Z5,"collection-1":F5,"collection-2":N5,"collection-3":I5,"collection-4":H5,"collection-5":B5,"collection-6":G5,"lifestyle-1":q5,"lifestyle-2":O5,"product-apparel-1":U5,"product-apparel-2":$5,"product-apparel-3":K5,"product-apparel-4":z5,"collection-apparel-1":W5,"collection-apparel-2":J5,"collection-apparel-3":Y5,"collection-apparel-4":Q5,"hero-apparel-1":X5,"hero-apparel-2":e2,"hero-apparel-3":t2,"blog-apparel-1":i2,"blog-apparel-2":n2,"blog-apparel-3":r2,"detailed-apparel-1":o2},a2=J1;function _e(n){return e=>{let t=a2[e];return t?.src?`<img src="${t.src}" alt="${e}" class="placeholder-svg placeholder-svg--${e}" />`:t}}function Me(n){return function(t){if(typeof t=="string")switch(t){case"option_selection.js":return"https://cdn.shopify.com/s/shopify/option_selection.js";case"api.jquery.js":return"https://cdn.shopify.com/s/shopify/api.jquery.js";case"shopify_common.js":return"https://cdn.shopify.com/s/shopify/shopify_common.js";case"customer_area.js":return"https://cdn.shopify.com/s/shopify/customer_area.js";case"currencies.js":return"https://cdn.shopify.com/s/javascripts/currencies.js";case"customer.css":return"https://cdn.shopify.com/s/shopify/customer.css";default:break}return t}}function Pe(n){return(e,t)=>(typeof e=="object"&&"value"in e&&(e=e.value),`<span data-swell-inline-editable="${t}">${e}</span>`)}var Y1={asset_url:q4,brightness_difference:O4,color_brightness:V4,color_contrast:U4,color_darken:$4,color_desaturate:K4,color_difference:z4,color_extract:W4,color_lighten:J4,color_mix:Y4,color_modify:Q4,color_saturate:X4,color_to_hex:ee,color_to_hsl:te,color_to_rgb:ie,date:S3,default_errors:re,divided_by:oe,font_face:ae,font_modify:se,font_url:le,format_address:g5,image_tag:ce,image_url:_5,inline_asset_content:he,json:de,json_pretty:ue,locale_flag:me,money:pe,money_with_currency:Ce,money_without_currency:fe,money_without_trailing_zeros:ge,script_tag:we,stylesheet_tag:ye,time_tag:Se,translate:V3,t:V3,where:ke,asset_img_url:Le,hex_to_rgba:be,item_count_for_variant:E5,payment_button:Ae,payment_terms:Te,placeholder_svg_tag:_e,shopify_asset_url:Me,inline_editable:Pe};function s2(n){for(let[e,t]of Object.entries(Y1))typeof t=="function"?n.registerFilter(e,t(n)):typeof t.bind=="function"&&n.registerFilter(e,Q1(n,t.bind,t.resolve))}function Q1(n,e,t=[]){let i=e(n);return Array.isArray(t)?async function(...r){let[o,...a]=await Promise.all(r.map((s,l)=>Array.isArray(t[l])||t[l]===!0?l2(s,t[l]):s));return i.call(this,o,...a)}:i}async function l2(n,e){if(!n)return n;let t=n;P(t)&&(t=await t);try{if(Array.isArray(e))for(let i of e){if(typeof i!="string")continue;let[r,...o]=i.split("."),a=t[r];R(a)&&(P(a)?t[r]=await a:l3(a.resolve)&&(t[r]=await a.resolve())),o.length>0&&(t[r]=await l2(t[r],[o.join(".")]))}}catch{}return t}import{defaultOperators as X1}from"liquidjs";var c2={...X1,"==":U3,"!=":(n,e)=>!U3(n,e),contains:(n,e)=>(n=Y(n),c3(n)?n.some(t=>U3(t,e)):l3(n?.indexOf)?n.indexOf(Y(e))>-1:!1)};function U3(n,e){return f3(n)?n.equals(e):f3(e)?e.equals(n):(n=Y(n),e=Y(e),c3(n)?c3(e)&&ei(n,e):n==e)}function ei(n,e){return n.length!==e.length?!1:!n.some((t,i)=>!U3(t,e[i]))}import $3 from"color";import{Drop as ti}from"liquidjs";var S=class n extends ti{color;colorValues;red;green;blue;constructor(e){super();try{this.color=h2(e)?typeof e.color.object=="function"?e.color:$3(e.colorValues):$3(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=$3("#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)}static clone(e){return h2(e)?new n(n.get(e).toString()):new n(e)}toString(){return this.color.string()}valueOf(){return this.toString()}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,[o,a,s]=i.rgb().array(),[l,h,u]=r.rgb().array(),c=$3.rgb([K3(o,l,t),K3(a,h,t),K3(s,u,t)]).alpha(K3(i.alpha(),r.alpha(),t));return i.alpha()!==1?c.string():c.hex()}contrast(e){return this.color.contrast(e.color).toFixed(1)}difference(e){let[t,i,r]=this.color.rgb().array(),[o,a,s]=e.color.rgb().array();return Ee(t,o)+Ee(i,a)+Ee(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 K3(n,e,t){return(n*t+e*(100-t))/100}function Ee(n,e){return Math.max(n,e)-Math.min(n,e)}function h2(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 W3=class extends ii{theme;getThemeConfig;getThemeTemplateConfigByType;getAssetUrl;renderTemplate;renderTemplateString;renderPageSections;renderTranslation;renderCurrency;isEditor;locale;currency;layoutName;extName;componentsDir;sectionsDir;lastSchema;constructor({theme:e,getThemeConfig:t,getThemeTemplateConfigByType:i,getAssetUrl:r,renderTemplate:o,renderTemplateString:a,renderPageSections:s,renderTranslation:l,renderCurrency:h,isEditor:u,locale:c,currency:C,layoutName:m,extName:f,componentsDir:p,sectionsDir:g}){t=t||e.getThemeConfig.bind(e),f=f||"liquid",super({cache:!1,relativeReference:!1,fs:ni(t,f),ownPropertyOnly:!1,operators:c2}),this.theme=e,this.getThemeConfig=t,this.getThemeTemplateConfigByType=i||e.getThemeTemplateConfigByType.bind(e),this.getAssetUrl=r||e.getAssetUrl.bind(e),this.renderTemplate=o||e.renderTemplate.bind(e),this.renderTemplateString=a||e.renderTemplateString.bind(e),this.renderPageSections=s||e.renderPageSections.bind(e),this.renderTranslation=l||e.renderTranslation.bind(e),this.renderCurrency=h||e.renderCurrency.bind(e),this.isEditor=!!u,this.locale=c||"en-US",this.currency=C||"USD",this.layoutName=m||"theme",this.extName=f,this.componentsDir=p||"components",this.sectionsDir=g||"sections",this.lastSchema=void 0,f5(this),s2(this)}async parseAndRender(e,t){return super.parseAndRender(e,t)}async resolveFilePathByType(e,t){let i=await this.getThemeTemplateConfigByType(e,t);if(i?.file_path)return i.file_path}async getComponentPath(e){return await this.resolveFilePathByType("components",e)||z3(`${this.componentsDir}/${e}`,this.extName)}async getSectionPath(e){return await this.resolveFilePathByType("sections",e)||z3(`${this.sectionsDir}/${e}`,this.extName)}async getSectionGroupPath(e){return await this.resolveFilePathByType("sections",`${e}.json`)||z3(`${this.sectionsDir}/${e}`,"json")}};function z3(n,e){return`theme/${n}.${e}`}function ni(n,e){return{async readFile(t){let i=z3(t,e);return n(i).then(r=>r?.file_data||`<!-- theme template not found: ${i} -->`)},async exists(t){return!0},readFileSync(t){return""},existsSync(t){return!1},contains(t,i){return!0},resolve(t,i,r){return i},fallback(t){}}}import{get as d2}from"lodash-es";async function u2(n,e,t){let r=(await Promise.all(e?.map(async o=>({...o,items:await m2(n,o.items,t)})))).map(o=>(n.shopifyCompatibility&&Object.assign(o,n.shopifyCompatibility.getMenuData(o)),o))||[];return C2([...r,...n.shopifyCompatibility?r.reduce((o,a)=>(a.handle&&o.push({...a,id:a.handle}),o),[]):[]])}async function m2(n,e,t){return e?.length>0?Promise.all(e.map(async r=>{let{url:o,resource:a}=await ri(n,r,{trailingSlash:t?.currentUrl?.endsWith("/")&&t.currentUrl!=="/"}),s=r.items&&await m2(n,r.items,t);return{...r,url:o,resource:a,levels:p2(s),current:t?.currentUrl===o,active:t?.currentUrl?.startsWith(o),...s?{items:s,child_current:oi(s),child_active:ve(s)}:void 0}})):[]}async function ri(n,e,t){if(!e)return{url:"#invalid-link-item"};if(typeof e=="object"&&e!==null){let{url:i,resource:r}=await si(n,e),o=i.slice(-1)==="/";return t?.trailingSlash&&!o&&i.length>1&&(i=i+"/"),!t?.trailingSlash&&o&&i.length>1&&(i=i.slice(0,-1)),{url:i,resource:r}}else return{url:e}}function p2(n){return n?.reduce((e,t)=>Math.max(e,t.items?1+p2(t.items):0),0)||0}function oi(n){return n.some(e=>e.current||e.items&&ve(e.items))}function ve(n){return n.some(e=>e.active||e.items&&ve(e.items))}function ai(n){return d2(n,"id",d2(n,"slug",typeof n=="string"?n:""))||""}async function si(n,e){let{type:t,value:i,url:r,model:o}=e;if(typeof t>"u"&&r)return{url:r};if(t==="url")return{url:typeof i=="string"?i:""};let a=ai(i);switch(t){case"home":return{url:p3(n,"index")};case"category":return a?await m3(n,"categories/category",a):{url:p3(n,"categories/index")};case"product":return a?await m3(n,"products/product",a):{url:p3(n,"products/index")};case"page":return await m3(n,"pages/page",a);case"blog":return await m3(n,"blogs/blog",a,async s=>new A(n.swell,"content/blog-categories",s.category_id).slug);case"blog_category":return await m3(n,"blogs/category",a);case"content_list":if(o){let s=o?.replace("content/","");return{url:p3(n,"content/index",s),resource:new b(n.swell,o)}}break;case"content":if(o){let s=o?.replace("content/","");return await m3(n,"content/content",a,s)}break;case"search":return{url:p3(n,"search")};default:break}return{url:`/${a}`}}function p3(n,e,t,i){let{props:r}=n,o=r?.pages?.find(a=>a.id===e)?.url;return o?.includes(":collection")&&i&&(o=o.replace(":collection",i)),o?.includes(":slug")&&(o=o.replace(":slug",t||"")),o||`/${t||""}`}async function m3(n,e,t,i){let{props:r}=n,o=r?.pages?.find(h=>h.id===e)?.collection,a=o?new A(n.swell,o,t):void 0,s=await a?.slug||t,l=typeof i=="string"?i:void 0;return a?.id&&typeof i=="function"&&(l=await i(a)),{url:p3(n,e,s,typeof l=="string"?l:void 0),resource:a}}import li from"bluebird";var{Promise:L3}=li,ci=50,J3=class n{static cache=null;swell;manifest;configs;configPaths;constructor(e){this.swell=e,this.manifest=null,this.configs=new Map,this.configPaths=[]}async init(e){let{swellHeaders:t}=this.swell;if(e){this.setConfigs(e);return}t["theme-id"]&&(await this.fetchManifest(),this.manifest===null&&(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()}getCache(){return n.cache===null&&(n.cache=new b3({kvStore:this.swell.workerEnv?.THEME})),n.cache}setConfigs(e){this.configs=new Map(e),this.configPaths=Array.from(this.configs.keys()),this.manifest=this.configPaths.reduce((t,i)=>(t[i]=this.configs.get(i)?.hash,t),{})}async preloadTheme(e,t){console.log(`ThemeLoader.preloadTheme${e?.hash?` - manifest: ${e.hash}`:""}${t?.length?` - configs: ${t.length}`:""}`),await L3.all([e&&this.cacheManifest(e),t&&L3.map(t,i=>this.cacheThemeConfig(i),{concurrency:10})])}async fetchThemeConfig(e){let t=this.configs.get(e);if(t!==void 0)return t;let i=this.manifest?.[e];if(i){let r=await this.getCache().get(`config:${i}`);return r?(this.configs.set(e,r),r):this.fetchThemeConfigsFromSourceByPath(e,i)}return null}async fetchThemeConfigsByPath(e,t){let i=this.configPaths.filter(o=>o.startsWith(e)&&(!t||o.endsWith(t)));return(await L3.map(i,o=>this.fetchThemeConfig(o),{concurrency:10})).filter(o=>o!==null)}async loadThemeAllConfigs(){let{swellHeaders:e}=this.swell,t=String(e["theme-config-version"]);if(!t)throw new Error("Theme version is required");return(await this.getCache().fetch(`configs-all:${this.swell.instanceId}:v@${t}2`,()=>this.fetchThemeConfigsFromSource()))?.results??[]}async loadThemeFromManifest(){let e=await this.fetchManifest();if(!e)return null;let t=[],i=new Map;if(await L3.map(Object.values(e),r=>this.getCache().get(`config:${r}`).then(o=>{o?(i.set(o.hash,o),this.configs.set(o.file_path,o)):t.push(r)}),{concurrency:10}),t.length>0){let o=(await this.fetchThemeConfigsFromSource(i.size===0?void 0:t))?.results??[];for(let a of o)i.set(a.hash,a),this.configs.set(a.file_path,a);await L3.map(o,a=>this.cacheThemeConfig(a),{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>ci;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:S4}})}async fetchThemeConfigsFromSourceByPath(e,t){console.log(`Retrieving theme config - ${e}`);let i=await this.swell.get("/:themes:configs/:last",{...this.themeVersionQueryFilter(),file_path:e,fields:"name, file, file_path, hash",include:{file_data:S4}});return i&&(this.configs.set(e,i),t&&(i.hash=t),await this.cacheThemeConfig(i)),i??null}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}}}};var f2=class{swell;props;globals;forms;resources;liquidSwell;themeLoader;themeConfigs=null;page;pageId;shopifyCompatibility=null;shopifyCompatibilityClass=A3;shopifyCompatibilityConfig=null;formData={};globalData={};themeSettingFilePath="theme/config/theme.json";constructor(e,t={}){let{forms:i,resources:r,globals:o,shopifyCompatibilityClass:a}=t;this.swell=e,this.props=this.getSwellAppThemeProps(e.config),this.shopifyCompatibilityConfig=e.shopifyCompatibilityConfig||null,this.globals=o||{},this.forms=i,this.resources=r,this.shopifyCompatibilityClass=a||A3,this.liquidSwell=new W3({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),renderPageSections:this.renderPageSections.bind(this),renderTranslation:this.lang.bind(this),renderCurrency:this.renderCurrency.bind(this),isEditor:e.isEditor}),this.themeLoader=new J3(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:o,configs:a}=await this.getSettingsAndConfigs(),{settings:s,request:l,page:h,cart:u,account:c,customer:C}=await this.resolvePageData(t,a,e);this.page=h;let m={...this.globalData,store:t,settings:s,session:i,request:l,menus:r,page:h,cart:u,account:c,customer:C,geo:o,configs:a,language:a?.language,canonical_url:`${t.url}${this.swell.url?.pathname||""}`,shopify_compatibility:!!s.shopify_compatibility};this.shopifyCompatibility&&this.shopifyCompatibility.initGlobals(m),this.setGlobals(m),this.shopifyCompatibility&&this.shopifyCompatibility.adaptQueryParams()}setGlobals(e){this.shopifyCompatibility&&this.shopifyCompatibility.adaptGlobals(e,this.globals),this.globals={...this.globals,...e},this.liquidSwell.options.globals={...this.globals}}async getSettingsAndConfigs(){let e=h5,[t,i]=await Promise.all([this.swell.getStorefrontSettings(),this.getThemeConfigsByPath("theme/config/",".json")]),r={theme:{},editor:{},language:{},presets:[],...Array.from(i.values()).reduce((s,l)=>{let h=String(l?.name||"").split(".")[0];if(h&&l?.file_data){let u;try{u=n3.parse(l.file_data)}catch(c){console.error(`Error parsing ${h} config: ${c}`),u={}}s[h]=u}return s},{})},o=await this.swell.storefront.settings.session();if(r.translations&&(r.language=r.translations),Object.keys(r.language).length>0)r.language=this.resolveTranslationLocale(r.language);else{let{locale:s}=this.swell.getStorefrontLocalization();r.language=await this.getLocaleConfig(s)}await this.setCompatibilityConfigs(r);let a=await this.resolveMenuSettings();return{store:t?.store,session:o,menus:a,geo:e,configs:r}}async resolvePageData(e,t,i){let r=String(this.swell.swellHeaders["theme-config-version"]),o=await this.swell.getCachedResource(`theme-settings-resolved:v@${r}`,[],()=>(t.editor?.settings&&mi(t.theme,t.editor?.settings),e4(this,t.theme,t.editor?.settings)));if(!o)throw new Error("Failed to resolve theme settings");let{locale:a,currency:s}=this.swell.getStorefrontLocalization(),l={host:this.swell.url.host,origin:this.swell.url.origin,path:this.swell.url.pathname,query:this.swell.queryParams,locale:a||e.locale,currency:s||e.currency,is_editor:this.swell.isEditor,is_preview:this.swell.isPreview},h=this.props.pages?.find(f=>f.id===i),u={...h,current:Number(this.swell.queryParams.page)||1,url:this.swell.url.pathname,custom:!h,slug:void 0,description:void 0,$locale:void 0};if(i){let f=await this.getThemeTemplateConfigByType("templates",i),p;try{p=n3.parse(f?.file_data||"{}")}catch(g){console.warn(g)}if(p?.page){let{slug:g,label:I,description:W,$locale:a3}=p.page;u.slug=g,u.label=I||u.label,u.description=W,u.$locale=a3}}let[c,C]=await Promise.all([this.fetchSingletonResourceCached("cart",()=>this.fetchCart(),{}),this.fetchSingletonResourceCached("account",()=>this.fetchAccount(),null)]);if(!c)throw new Error("Failed to fetch cart");let m;return this.shopifyCompatibility&&(m=C),{settings:o,request:l,page:u,cart:c,account:C,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 Q(this.swell,"cart");if(t._isEmpty=function(){return!this._result?.items?.length},await t.id,this.shopifyCompatibility){let i=w3(this.shopifyCompatibility,t);t.setCompatibilityProps(i)}return t}async fetchAccount(){let e=this.resources?.singletons?.account,t=e?new e(this.swell):new Q(this.swell,"account");if(await t.id,!t?.id)return null;if(this.shopifyCompatibility){let i=i3(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 e3(e);i instanceof e3&&(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):T3(e,t)}resolveTranslationLocale(e,t){if(!e)return{};if(t=t||this.swell.getStorefrontLocalization().locale,!t)return e;let i=t.split("-")[0];return di(e,(r,o,a)=>{if(v(o))if(a==="$locale")for(let s of Object.keys(o)){let l=o[s];v(l)&&Object.assign(r,this.resolveTranslationLocale(l,t))}else a[0]!=="$"&&(r[a]=this.resolveTranslationLocale(o,t));else if(typeof o=="string")if(o.startsWith("t:")){let s=o.slice(2),l=s.split("."),h=l.pop(),u=l.join("."),c=this.globals.language;r[a]=K(c,`${u}.$locale.${t}.${h}`)||K(c,`${u}.$locale.${i}.${h}`)||K(c,s)||o}else r[a]=K(e,`$locale.${t}.${a}`)||K(e,`$locale.${i}.${a}`)||o;return r},{})}async setCompatibilityConfigs(e){let t=()=>(this.shopifyCompatibility||(this.shopifyCompatibility=new this.shopifyCompatibilityClass(this)),this.shopifyCompatibility);if(!Object.keys(e.editor).length&&e.settings_schema){let i=await this.swell.storefront.settings.get("store");e.editor=t().getEditorConfig(e.settings_schema),e.editor=await t().renderSchemaTranslations(this,e.editor,i.locale||"en-US")}!Object.keys(e.theme).length&&e.settings_data&&(e.theme=t().getThemeConfig(e.settings_data),this.themeSettingFilePath="theme/config/settings_data.json"),!Object.keys(e.presets).length&&e.settings_data&&(e.presets=t().getPresetsConfig(e.settings_data)),e.theme.shopify_compatibility?t():this.shopifyCompatibility&&(e.theme.shopify_compatibility=!0)}setCompatibilityData(e){!e||!this.shopifyCompatibility||this.shopifyCompatibility.adaptPageData(e)}async getLocaleConfig(e="en",t=".json"){let i=await this.getThemeConfigsByPath("theme/locales/",t),r=i.get(`theme/locales/${e}${t}`)??null;if(!r){let o=e.split("-")[0];if(r=i.get(`theme/locales/${o}${t}`)??null,!r){let a=`.default${t}`;for(let s of i.values())if(s.file_path?.endsWith(a)){r=s;break}}}if(r){r=await this.getThemeConfig(r.file_path);try{return n3.parse(r?.file_data||"{}")}catch(o){console.warn(o)}}return{}}resolveLookupSetting(e,t){if(t instanceof _)return t;let i=pi(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 A(this.swell,e,t);return this.shopifyCompatibility&&this.shopifyCompatibility.adaptPageData({resource:r}),r}resolveMenuSettings(){return u2(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=D.get(t||e);return Object.assign(i,this.shopifyCompatibility.getFontData(i)),i}return D.get(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===null){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 o of i)r.set(o.file_path,o);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 o=await this.getThemeTemplateConfig(`theme/${r}`);if(o)return o}return null}async getAssetUrl(e){let i=(await this.getThemeConfig(`theme/assets/${e}`)||await this.getThemeConfig(`assets/${e}`))?.file;if(!i)return null;let r=i.url||null;return r&&(r.endsWith(e)?r:`${r}/${e}`)}async renderTemplate(e,t){let i=e?.file_data||null;if(e===null||i===null)return"";i=gi(i);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=n3.parse(i.file_data)||void 0,this.shopifyCompatibility&&(t=this.shopifyCompatibility.getSectionConfigSchema(t),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.store?.locale))}catch(r){console.warn(r);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 o=this.liquidSwell.lastSchema;o&&(t=this.shopifyCompatibility.getSectionConfigSchema(o),t=await this.shopifyCompatibility.renderSchemaTranslations(this,t,this.globals.store?.locale))}return t&&(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),o=e.file_data.indexOf(i),a=e.file_data.slice(r+t.length,o);return r===-1||o===-1?null:{...e,file_data:t+a+i}}async renderThemeTemplate(e,t){let i=await this.getThemeTemplateConfig(e),r=await this.renderTemplate(i,t);if(i?.file_path?.endsWith(".json"))try{return n3.parse(r)}catch(o){throw console.log("Unable to render theme template",i.file_path,r),new Q3(o)}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 o=e.split("/").splice(1).join("/")||null,a={name:e,alt_name:i||null,path:o||null};this.shopifyCompatibility&&(a=f4(this.shopifyCompatibility,a)),this.setGlobals({template:a});let s=await this.renderThemeTemplate(r.file_path,t);return s&&typeof s!="string"&&(s.id=String(r.name)),s}throw new X3("Page template not found",404,`templates/${e}`)}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 X3;i.page=this.resolveTranslationLocale(i.page)}return i}getShopify1HomePageSectionGroup(){let e=this.globals.configs.theme||{};return{sections:e.sections||{},order:e.content_for_index||[]}}async getShopify1HomePageSections(e=!0){let t=this.getShopify1HomePageSectionGroup();return this.getPageSections(t,e)}async renderShopify1HomePage(e){let t=this.getShopify1HomePageSectionGroup(),i=await this.renderPageSections(t);return this.renderTemplateString(e,{content_for_index:i})}isShopify1HomePage(e,t){return e==="index"&&typeof t=="string"}async renderAllSections(e,t){let i=typeof e=="string"?e.split(/\s*,\s*/):e;return(await Promise.all(i.map(o=>this.renderSection(o,t)))).reduce((o,a,s)=>{let l=i[s];return this.shopifyCompatibility?o[l]=`
930
930
  <div id="shopify-section-${l}" class="shopify-section">${String(a)}</div>
931
931
  `.trim():o[l]=`
932
932
  <div id="swell-section-${l}" class="swell-section">${String(a)}</div>
@@ -945,6 +945,6 @@ Shopify.routes = Shopify.routes || {};
945
945
  Shopify.routes.root = "/";
946
946
  ${o.join(`
947
947
  `)}</script>`}getMenuData(e){return qe(this,e)}getFontData(e){return Oe(this,e)}getFormData(e){return Ve(this,e)}getFontFromShopifySetting(e){return P2(e)}getThemeConfig(e){return A2(e)}getPresetsConfig(e){return T2(e)}getEditorConfig(e){let{locale:t}=this.swell.getStorefrontLocalization();return b2(e,t)}getSectionConfigSchema(e){let{locale:t}=this.swell.getStorefrontLocalization();return _2(e,t)}getSectionGroup(e){let{locale:t}=this.swell.getStorefrontLocalization();return M2(e,t)}async getEditorLocaleConfig(e,t){if(this.editorLocaleConfig?.[t])return this.editorLocaleConfig[t];let i=await e.getLocaleConfig(t,".schema.json");return this.editorLocaleConfig={[t]:i},i}async renderSchemaTranslations(e,t,i="en"){if(!ji(t))return t;let r=await this.getEditorLocaleConfig(e,i);return this.renderSchemaTranslationValue(e,t,i,r)}async renderSchemaTranslationValue(e,t,i,r){switch(typeof t){case"string":{if(t.startsWith("t:")){let o=t.slice(2),a=o?.split("."),s=a.pop()||"",l=a.join(".");return xi(r,l)?.[s]??o}break}case"object":{if(Array.isArray(t)){let o=[];for(let a of t)o.push(await this.renderSchemaTranslationValue(e,a,i,r));return o}if(t!==null){let o={...t};for(let[a,s]of Object.entries(t))o[a]=await this.renderSchemaTranslationValue(e,s,i,r);return o}break}default:break}return t}getPageType(e){return this.shopifyCompatibilityConfig?.page_types?.[e]||e}getPageRouteUrl(e){return this.theme.props.pages?.find(t=>t.id===e)?.url||e}getPageRoutes(){let e={account_addresses_url:this.getPageRouteUrl("account/addresses"),account_login_url:this.getPageRouteUrl("account/login"),account_logout_url:this.getPageRouteUrl("account/logout"),account_recover_url:this.getPageRouteUrl("account/recover"),account_register_url:this.getPageRouteUrl("account/signup"),account_url:this.getPageRouteUrl("account/index"),all_products_collection_url:this.getPageRouteUrl("products/index"),cart_add_url:this.getPageRouteUrl("cart/add"),cart_change_url:this.getPageRouteUrl("cart/change"),cart_clear_url:this.getPageRouteUrl("cart/clear"),cart_update_url:this.getPageRouteUrl("cart/update"),cart_url:this.getPageRouteUrl("cart/index"),collections_url:this.getPageRouteUrl("categories/index"),predictive_search_url:this.getPageRouteUrl("search/suggest"),product_recommendations_url:this.getPageRouteUrl("products/index"),root_url:this.getPageRouteUrl("index"),search_url:this.getPageRouteUrl("search")};if(this.shopifyCompatibilityConfig?.page_routes)for(let[t,i]of Object.entries(this.shopifyCompatibilityConfig.page_routes))i&&typeof i=="object"&&i.page_id?e[t]=this.getPageRouteUrl(i.page_id):typeof i=="string"&&(e[t]=i);return e}getLocalizationObject(e,t){return k3(this,e,t)}getAdaptedPageUrl(e){if(!e)return;let t,i,r={},[o,a]=e.split("?"),s=o.split("."),l=s[1]?s.pop():null,[,h,u,c]=s.join(".").split("/");switch(l==="js"&&(i="json"),h){case"account":switch(u){case"order":t="account/order",r.id=c;break;case"register":t="account/login";break;default:break}break;case"blog":u&&(t="blogs/category",r.category=u),c&&(t="blogs/blog",r.slug=c);break;case"collections":u?u==="all"?t="products/index":(t="categories/category",r.slug=u):t="categories/index";break;case"gift_card":u&&(t="gift-card",r.code=u);break}if(t){let C=this.getPageRouteUrl(t);if(C)return C.replace(/:(\w+)/g,(f,p)=>r[p])+(l?`.${l}`:"")+(a?`?${a}`:"")}else if(i)return o.replace(new RegExp(`.${l}$`),`.${i}`)+(a?`?${a}`:"")}getThemeFilePath(e,t){switch(e){case"assets":return`assets/${t}`;case"components":return`snippets/${t}`;case"config":return`config/${t}`;case"layouts":return`layout/${t}`;case"templates":return`templates/${this.getPageType(t)}`;case"sections":return`sections/${t}`;default:throw new Error(`Theme file type not supported: ${e}`)}}getPageResourceMap(){return this.shopifyCompatibilityConfig?.page_resources?this.shopifyCompatibilityConfig.page_resources.reduce((e,t)=>e.set(t.page,{page:t.page,resources:t.resources.map(({from:i,to:r,object:o})=>{let a=a4[o];if(!a)throw new Error(`ShopifyObject for '${o}' not found.`);return{from:i,to:r,object:a}})}),new Map):new Map}getObjectResourceMap(){return this.shopifyCompatibilityConfig?.object_resources?this.shopifyCompatibilityConfig.object_resources.reduce((e,t)=>{let i=a4[t.object];if(!i)throw new Error(`ShopifyObject for '${t.object}' not found.`);return e.set(t.from,{from:t.from,object:i})},new Map):new Map}getFormResourceMap(){return this.shopifyCompatibilityConfig?.forms?this.shopifyCompatibilityConfig.forms.map(e=>({shopifyType:e.shopify_type,type:e.id})):[]}getQueryParamsMap(){return[{from:"sort_by",to:"sort"},{from(e){return e.startsWith("filter.v.")},to(e,t){let i=e.split("filter.v.")[1],r=t;return{[i]:r}}}]}getAllCountryOptionTags(e){return e?e.countries?.map(t=>{if(!t)return"";let i=(e.states||[]).filter(o=>o.country===t.id).map(o=>[o.id,o.name]),r=JSON.stringify(i).replace(/"/g,"&quot;");return`<option value="${t.id}" data-provinces="${r}">${t.name}</option>`}).filter(Boolean).join(`
948
- `):""}isScriptFormActionUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_actions_routes||{};for(let i of Object.values(t))if(e===i)return!0;return!1}isScriptUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_routes||{};for(let i of Object.values(t))if(e.startsWith(i))return!0;return!1}needRedirectToPageStart(e){return e?(this.shopifyCompatibilityConfig?.editor_configs?.redirect_to_page_start_forms||[]).includes(e):!1}isCheckoutForm(e){return e?this.shopifyCompatibilityConfig?.editor_configs?.checkout_form===e:!1}};var y=class n{props;stringProp;linkProps;constructor(e,t,i){return this.props=e,this.stringProp=t,this.linkProps=i,new Proxy(e,{get(r,o){let a=r;switch(o){case"toJSON":return e;case"clone":return()=>new n(Ke(e),Ke(t),Ke(i));case"toString":{if(t)return()=>e[t];break}default:break}return a[o]instanceof o3?a[o].resolve().then(s=>(a[o]=s,s),s=>(console.log(s),a[o]=null,null)):a[o]},getPrototypeOf(){return n.prototype}})}valueOf(){return this.stringProp?this.props[this.stringProp]:this}clone(){return new n({})}},o3=class{handler;result;constructor(e){this.result=void 0,this.handler=e}async resolve(){return this.result===void 0&&(this.result=Promise.resolve().then(()=>{let e=this.handler();return this.handler=Zi,e}).then(e=>(e=e!==void 0?e:null,this.result=e,e))),this.result}};function w(n){return new o3(n)}function Fi(n){return R(n)&&(P(n)||typeof n._resolve=="function")}function E2(n){return R(n)&&typeof n._resolve=="function"}async function Ni(n){return Array.isArray(n)?Promise.all(n.map(e=>E2(e)?e._resolve():e)):E2(n)?n._resolve():n}async function v2(n,e){return Ni(n).then(t=>Array.isArray(n)&&Array.isArray(t)?e(...t.map(i=>i||{})):Fi(t)?v2(t,e):e(t||{})).catch(t=>(console.log(t),null))}function d(n,e){return new o3(()=>v2(n,e))}function y4(n,e,t,i,r){return d(e,o=>o[t]?._cloneWithCompatibilityResult(a=>({results:a?.results?.map(s=>{let l=i(n,s);return r&&r(l,s),l})}))||[])}import Rc from"json5";function D3(n){let e={description:n.description,defaultValue:n.default,isLabelHidden:!0,layout:"column",params:n},t;switch(n?.type){case"text":case"short_text":t={type:"swell_short_text"};break;case"paragraph":t={type:"swell_paragraph"};break;case"textarea":case"long_text":case"liquid":t={type:"swell_long_text"};break;case"basic_html":case"rich_text":case"rich_text_pre_heading":case"rich_html":case"markdown":t={type:"swell_editor"};break;case"number":t={type:"swell_number"};break;case"select":t={type:"swell_select"};break;case"radio":t={type:"swell_radio"};break;case"checkbox":t={type:"swell_boolean"};break;case"color":t={type:"swell_color"};break;case"color_scheme":t={type:"swell_color_scheme"};break;case"color_scheme_group":t={type:"swell_color_scheme_group"};break;case"font":t={type:"swell_font"};break;case"header":t={type:"swell_header"};break;case"icon":t={type:"swell_menu"};break;case"menu":t={type:"swell_menu"};break;case"url":t={type:"swell_url"};break;case"lookup":case"generic_lookup":case"product_lookup":case"category_lookup":case"customer_lookup":t={type:"swell_lookup"};break;case"image":t={type:"swell_image",defaultValue:null};break;case"asset":case"document":case"video":t={type:"swell_file"};break;default:t={type:"swell_short_text"};break}return{...e,...t}}function N(n,e,t){if(t===void 0)return null;switch(n?.find(r=>r.id===e)?.type){default:return t}}function Ii(n,e){return e?.reduce((t,i)=>{for(let r of i.fields||[])r?.id&&(t[r.id]=n[r.id]);return t},{})}function Hi(n,e){if(e)return{settings:e.fields.reduce((t,i)=>(i?.id&&(t[i.id]=n[i.id]),t),{$locale:n.$locale}),id:e.id,blocks:n.Blocks?.filter(t=>!!t.props.compiled?._component).map(t=>{let i=t.props.compiled.props,r=t.props.compiled._component.split("__")[2],o=e.blocks?.find(a=>a.type===r);return{type:r,settings:o?.fields?.reduce((a,s)=>(s?.id&&(a[s.id]=i[s.id]),a),{$locale:i.$locale})||{}}})}}function x3(n){return n&&n.replace(/\./g,"\xB7")}function R2(n){return n&&n.replace(/·/g,".")}function X(n){var e="0123456789abcdef";function t(L){var k,T="";for(k=0;k<=3;k++)T+=e.charAt(L>>k*8+4&15)+e.charAt(L>>k*8&15);return T}function i(L,k){var T=(L&65535)+(k&65535),M=(L>>16)+(k>>16)+(T>>16);return M<<16|T&65535}function r(L,k){return L<<k|L>>>32-k}function o(L,k,T,M,H,B){return i(r(i(i(k,L),i(M,B)),H),T)}function a(L,k,T,M,H,B,J){return o(k&T|~k&M,L,k,H,B,J)}function s(L,k,T,M,H,B,J){return o(k&M|T&~M,L,k,H,B,J)}function l(L,k,T,M,H,B,J){return o(k^T^M,L,k,H,B,J)}function h(L,k,T,M,H,B,J){return o(T^(k|~M),L,k,H,B,J)}function u(L){var k,T=(L.length+8>>6)+1,M=new Array(T*16);for(k=0;k<T*16;k++)M[k]=0;for(k=0;k<L.length;k++)M[k>>2]|=L.charCodeAt(k)<<k%4*8;return M[k>>2]|=128<<k%4*8,M[T*16-2]=L.length*8,M}var c,C=u(""+n),m=1732584193,f=-271733879,p=-1732584194,g=271733878,I,W,a3,Je;for(c=0;c<C.length;c+=16)I=m,W=f,a3=p,Je=g,m=a(m,f,p,g,C[c+0],7,-680876936),g=a(g,m,f,p,C[c+1],12,-389564586),p=a(p,g,m,f,C[c+2],17,606105819),f=a(f,p,g,m,C[c+3],22,-1044525330),m=a(m,f,p,g,C[c+4],7,-176418897),g=a(g,m,f,p,C[c+5],12,1200080426),p=a(p,g,m,f,C[c+6],17,-1473231341),f=a(f,p,g,m,C[c+7],22,-45705983),m=a(m,f,p,g,C[c+8],7,1770035416),g=a(g,m,f,p,C[c+9],12,-1958414417),p=a(p,g,m,f,C[c+10],17,-42063),f=a(f,p,g,m,C[c+11],22,-1990404162),m=a(m,f,p,g,C[c+12],7,1804603682),g=a(g,m,f,p,C[c+13],12,-40341101),p=a(p,g,m,f,C[c+14],17,-1502002290),f=a(f,p,g,m,C[c+15],22,1236535329),m=s(m,f,p,g,C[c+1],5,-165796510),g=s(g,m,f,p,C[c+6],9,-1069501632),p=s(p,g,m,f,C[c+11],14,643717713),f=s(f,p,g,m,C[c+0],20,-373897302),m=s(m,f,p,g,C[c+5],5,-701558691),g=s(g,m,f,p,C[c+10],9,38016083),p=s(p,g,m,f,C[c+15],14,-660478335),f=s(f,p,g,m,C[c+4],20,-405537848),m=s(m,f,p,g,C[c+9],5,568446438),g=s(g,m,f,p,C[c+14],9,-1019803690),p=s(p,g,m,f,C[c+3],14,-187363961),f=s(f,p,g,m,C[c+8],20,1163531501),m=s(m,f,p,g,C[c+13],5,-1444681467),g=s(g,m,f,p,C[c+2],9,-51403784),p=s(p,g,m,f,C[c+7],14,1735328473),f=s(f,p,g,m,C[c+12],20,-1926607734),m=l(m,f,p,g,C[c+5],4,-378558),g=l(g,m,f,p,C[c+8],11,-2022574463),p=l(p,g,m,f,C[c+11],16,1839030562),f=l(f,p,g,m,C[c+14],23,-35309556),m=l(m,f,p,g,C[c+1],4,-1530992060),g=l(g,m,f,p,C[c+4],11,1272893353),p=l(p,g,m,f,C[c+7],16,-155497632),f=l(f,p,g,m,C[c+10],23,-1094730640),m=l(m,f,p,g,C[c+13],4,681279174),g=l(g,m,f,p,C[c+0],11,-358537222),p=l(p,g,m,f,C[c+3],16,-722521979),f=l(f,p,g,m,C[c+6],23,76029189),m=l(m,f,p,g,C[c+9],4,-640364487),g=l(g,m,f,p,C[c+12],11,-421815835),p=l(p,g,m,f,C[c+15],16,530742520),f=l(f,p,g,m,C[c+2],23,-995338651),m=h(m,f,p,g,C[c+0],6,-198630844),g=h(g,m,f,p,C[c+7],10,1126891415),p=h(p,g,m,f,C[c+14],15,-1416354905),f=h(f,p,g,m,C[c+5],21,-57434055),m=h(m,f,p,g,C[c+12],6,1700485571),g=h(g,m,f,p,C[c+3],10,-1894986606),p=h(p,g,m,f,C[c+10],15,-1051523),f=h(f,p,g,m,C[c+1],21,-2054922799),m=h(m,f,p,g,C[c+8],6,1873313359),g=h(g,m,f,p,C[c+15],10,-30611744),p=h(p,g,m,f,C[c+6],15,-1560198380),f=h(f,p,g,m,C[c+13],21,1309151649),m=h(m,f,p,g,C[c+4],6,-145523070),g=h(g,m,f,p,C[c+11],10,-1120210379),p=h(p,g,m,f,C[c+2],15,718787259),f=h(f,p,g,m,C[c+9],21,-343485551),m=i(m,I),f=i(f,W),p=i(p,a3),g=i(g,Je);return t(m)+t(f)+t(p)+t(g)}function Vi(n,e){if(!n.file_path.startsWith("theme/sections/"))return!1;if(n.file_path.endsWith(".liquid")){if(!e.get(n.file_path.replace(/\.liquid$/,".json")))return!0}else if(n.file_path.endsWith(".json"))return!0;return!1}async function y2(n,e){let t=[];for(let i of n.values())if(Vi(i,n)){let r=await e(i);r&&t.push({...r,id:String(i.name||"").split(".").pop()??"",...r&&{presets:Ui(r)}})}return t}function Ui(n){return Array.isArray(n?.presets)?n.presets.map(e=>({label:e.label,settings:{...n.fields?.reduce((t,i)=>(i.id&&i.default!==void 0&&(t[i.id]=i.default),t),{}),...e.settings||void 0},blocks:e.blocks?.map(t=>{let i=n.blocks?.find(r=>r.type===t.type);return i?{...t,settings:{...i.fields.reduce((r,o)=>(o.id&&o.default!==void 0&&(r[o.id]=o.default),r),{}),...t.settings||void 0}}:t})})):[]}async function S2(n,e){let t=Array.from(n.values()),i=t.filter(a=>a.file_path.endsWith(".json")&&!n.has(a.file_path.replace(/\.json$/,".liquid"))),r=async a=>{let s=t.find(h=>{if(!h.file_path.endsWith(`/${a}.json`)&&!h.file_path.endsWith(`/${a}.liquid`))return!1;if(h.file_path.endsWith(".liquid")){if(!n.get(h.file_path.replace(/\.liquid$/,".json")))return!0}else if(h.file_path.endsWith(".json"))return!0;return!1});return s?{...await e(s),id:String(s.name||"").split(".").pop()}:void 0},o=[];for(let a of i){let s;try{s=Oi.parse(a.file_data)}catch(l){console.warn(l)}if(s?.type){let l=await De(s,r);o.push({...s,id:String(a.name||"").split(".").pop(),sectionConfigs:l})}}return o}async function De(n,e){let t=Array.isArray(n?.order)&&n.order.length>0?n.order:Object.keys(n?.sections||{}),i=[];for(let r of t){let o=n.sections?.[r];if(!o)continue;let a=await e(o.type)||{id:o.type,label:o.type,tag:"div",class:"",fields:[],blocks:[]},s=n.id?`page__${n.id}__${r}`:a.id,h=(Array.isArray(o.block_order)?o.block_order:Object.keys(o.blocks||{})).map(c=>o.blocks?.[c]).filter(Boolean),u={section:{id:s,...o,blocks:h}};i.push({id:s,section:{id:s,...o},schema:a,settings:u,tag:a.tag||"div",class:a.class})}return i}function qc(n){return String(n)==="[object Array]"}function v(n){let e=typeof n;return n!==null&&(e==="object"||e==="function")}function x2(n){let e=new TextEncoder().encode(n),t="";for(let i=0;i<e.length;i+=3){let r=Array.from(e.slice(i,i+3));t+=btoa(String.fromCharCode(...r))}return t}function C2(n,e="id"){return qi(n,(t,i)=>(t[String(i[e])]=i,t),{})}function M5(n){let e=n.split(/-|_/),t=e.pop()?.toUpperCase(),i=e.join("-");return(t||d5[i]||"").toLowerCase()}function P5(n){return v(n)&&Object.hasOwn(n,"code")&&Object.hasOwn(n,"name")&&Object.hasOwn(n,"fallback")}function j2(n,e){if(!(typeof n!="object"||n===null))for(let[t,i]of Object.entries(n))e(t,n)!==!1&&typeof i=="object"&&i!==null&&j2(i,e)}function Oc(n){let e=new Set;return j2(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return!1;e.add(i)}return!0}),Array.from(e)}function Vc(n){if(!n)return n;let e=new WeakSet;return JSON.parse(JSON.stringify(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return JSON.parse(JSON.stringify(i));e.add(i)}return i}))}function $i(n){if(!(typeof n!="object"||n===null))for(let[e,t]of Object.entries(n))e==="_swell"&&"_swell"in n?n[e]=void 0:$i(t)}function D2(n){if(n!==void 0)return n instanceof b?"SwellStorefrontCollection":n instanceof A?"SwellStorefrontRecord":n instanceof y?"ShopifyResource":n instanceof _?"StorefrontResource":"promise"}async function G(n,e=!0,t=!1){let i=n,r=e;try{if(P(n)&&(r=!1,i=await n),n instanceof _&&(r=!1,i=await G(n.resolve(),e,t)),Array.isArray(i)){let o=await Promise.all(i.map(a=>G(a,e,t)));if(i=o,!o.some(a=>a!==void 0))return e?[]:void 0}else if(typeof i=="object"&&i!==null&&(!("_swell"in i)||!i._swell)){let o={};for(let[a,s]of Object.entries(i)){if(!e&&(P(s)||s instanceof _||s instanceof y)){o[a]={_type:D2(s),...t?{value:await G(s,r,t)}:void 0};continue}if(s instanceof _&&t){o[a]={_type:D2(s),value:await G(s,r,t)};continue}o[a]=await G(s,r,t)}return!e&&Object.keys(o).length===0?void 0:o}}catch(o){return console.error(o),n}return i}function V(n){return Bi.stringify({...n,sections:void 0,section_id:void 0},{encodeValuesOnly:!0,arrayFormat:"repeat"})}function k2(n,e){return n=Array.isArray(n)?n.join(" "):n,n.split("}").map(r=>{let[o,a]=r.split("{");return!o||!a?"":`${o.split(",").map(l=>`#${e} ${l.trim()}`).join(", ")} {${a}}`}).join(" ")}function T3(n,e){return Object.entries(n).reduce((t,[i,r])=>(r?.value!==null&&r?.value!==void 0&&(t[R2(i)]=r?.value),t),Gi(e))}var t4="ContentSections";function C3(n){return`SectionGroup_${n}`}var zi="THEME",Wi=5*1e3,Ji=1e3*60*60*24*7,Yi=Object.freeze({ttl:Wi}),F2="__NULL__",O=class{client;constructor(e){e=e||{},e.stores=e.stores||Qi(e.kvStore),this.client=Ki({...Yi,...e})}async fetch(e,t){return this.client.wrap(e,t)}async fetchSWR(e,t,i=Ji){let r=await this.client.get(e);console.log("Cache.fetchSWR",{key:e,ttl:i,cacheValue:!!r});let o=Promise.resolve().then(()=>t()).then(async s=>{let l=s==null,h=await G(s);return await this.client.set(e,l?F2:h,i),s});return r!==null?r===F2?null:r:await o}async get(e){return this.client.get(e)}async set(e,t,i){return this.client.set(e,t,i)}async flush(e){await this.client.del(e)}async flushAll(){await this.client.clear()}};function Qi(n){let e=[];return n?e.push(new Z2({namespace:zi,store:new N3(n)})):e.push(new Z2),e}var j3=class extends O{constructor(e){super({...e})}};import{Keyv as Xi}from"keyv";var Z3=class extends O{constructor(e){super({stores:e6(),...e})}};function e6(){return[new Xi({serialize:void 0,deserialize:void 0})]}var t6=90*24*60*60*1e3,b3=class extends O{constructor(e){super({ttl:t6,...e})}};var N2="https://api.schema.io",I2=new Map,H2=new Map,B2=class n{url;headers;swellHeaders;queryParams;workerEnv;config;shopifyCompatibilityConfig;backend;storefront;storefrontContext;instanceId="";isPreview=!1;isEditor=!1;sentResponse=!1;storefront_url;resourceLoadingIndicator;constructor(e){let{url:t,config:i,shopifyCompatibilityConfig:r,headers:o,swellHeaders:a,serverHeaders:s,queryParams:l,workerEnv:h,...u}=e;if(this.url=t instanceof URL?t:new URL(t||""),this.config=i,this.shopifyCompatibilityConfig=r,this.queryParams=n.formatQueryParams(l||this.url.searchParams),this.workerEnv=h,this.resourceLoadingIndicator=e.resourceLoadingIndicator,console.log(`KV cache: ${this.workerEnv?.THEME?"enabled":"disabled"}`),s){let{headers:c,swellHeaders:C}=n.formatHeaders(s);this.headers=c,this.swellHeaders=C,this.backend=new ze({storeId:C["store-id"],accessToken:C["access-token"],apiHost:C["api-host"]}),this.storefront=this.getStorefrontInstance({...e,headers:c,swellHeaders:C}),this.instanceId=["store-id","environment-id","deployment-mode","theme-id","theme-branch-id"].map(m=>C[m]||"0").join(":"),this.isEditor=u.isEditor??C["deployment-mode"]==="editor",this.isPreview=this.isEditor||C["deployment-mode"]==="preview"}else if(o&&a)Object.assign(this,u),this.headers=o,this.swellHeaders=a,this.storefront=this.getStorefrontInstance(e);else throw new Error("Swell client requires `serverHeaders` when initialized on the server-side, or `headers` and `swellHeaders` when initialized on the client-side.");this.storefrontContext=this.initStorefrontContext()}static formatHeaders(e){let t={},i={};e instanceof Headers?e.forEach((r,o)=>{t[o]=r}):e&&(t=e);for(let[r,o]of Object.entries(t))r.startsWith("swell-")&&o&&(i[r.replace("swell-","")]=o);return{headers:t,swellHeaders:i}}static formatQueryParams(e){let t={};return e instanceof URLSearchParams?t=n6.parse(e.toString()):e&&(t=e),t}async getCachedResource(e,t,i){let r=G2(e,[this.instanceId,t]);return this.getResourceCache().fetchSWR(r,i)}async getAppSettings(){return await this.get("/:storefronts/{id}/configs/settings/values",{id:this.swellHeaders["storefront-id"]})||{}}async getStorefrontSettings(e=!1){try{let{settings:t,menus:i,payments:r,subscriptions:o,session:a}=await this.storefront.request("get","/settings/all",void 0,void 0,{force:e}),s=this.storefront.settings;s.localizedState={},s.set({value:t}),s.set({model:"menus",value:i}),s.set({model:"payments",value:r}),s.set({model:"subscriptions",value:o}),s.set({model:"session",value:a})}catch(t){t instanceof Error&&(t.message=`Swell: unable to load settings (${t.message})`),console.error(t)}return this.storefront.settings.get()}getStorefrontMenus(){let e=this.storefront.settings.getState("/settings/menus","menuState");return!e||P(e)?[]:e}getStorefrontLocalization(){let e=this.storefront.locale.selected(),t=this.storefront.currency.selected();return!e||P(e)?{locale:"en-US",currency:"USD"}:{locale:e,currency:t}}async get(...e){return this.backend?.get(...e)}async put(...e){return this.backend?.put(...e)}async post(...e){return this.backend?.post(...e)}async delete(...e){return this.backend?.delete(...e)}isLoading(e=!0){this.resourceLoadingIndicator&&this.resourceLoadingIndicator(e)}getStorefrontInstance(e){let{swellHeaders:t,getCookie:i,setCookie:r,storefrontSettingStates:o}=e;if(!t)throw new Error("Swell headers are required");let a=t["store-id"],s=t["public-key"];if(!a||!s)throw new Error('Missing required headers: "swell-store-id" and "swell-public-key"');let l=i6.create(a,s,{url:t["admin-url"],vaultUrl:t["vault-url"],getCookie:i,setCookie:r&&((h,u,c)=>r(h,u,c,this)),headers:{"Swell-Store-id":a,"Swell-Storefront-Id":t["storefront-id"]}});return o&&Object.assign(l.settings,o),l.request=this.getCacheableStorefrontRequestHandler(l),l}initStorefrontContext(){let e={};if(this.swellHeaders?.["storefront-context"])try{e=JSON.parse(decodeURIComponent(this.swellHeaders["storefront-context"]))}catch{console.error("Failed to parse swell-storefront-context. Ignoring...")}return e}isStorefrontRequestCacheable(e,t,i){if(i?.force)return!1;if(e==="get")switch(t.split("/")[1]){case"products":case"categories":case"content":case"settings":return!0;default:return!1}return!1}getCacheableStorefrontRequestHandler(e){let t=e.request;return(i,r,o,a,s)=>{if(this.isStorefrontRequestCacheable(i,r,s))return this.getRequestCache().fetchSWR(G2("request",[this.instanceId,i,r,o,a,s]),()=>(console.log("Storefront request",{method:i,url:r,id:o,data:a}),t(i,r,o,a,s)));switch(i){case"delete":case"post":case"put":{let l=r.split("/")[1];delete this.storefrontContext[l];break}default:}return t(i,r,o,a,s)}}getResourceCache(){let e=I2.get(this.instanceId);return e||(e=new Z3({kvStore:this.workerEnv?.THEME}),I2.set(this.instanceId,e)),e}getRequestCache(){let e=H2.get(this.instanceId);return e||(e=new j3({kvStore:this.workerEnv?.THEME}),H2.set(this.instanceId,e)),e}};function G2(n,e){let t=n;return Array.isArray(e)&&e.length>0&&(t+=`_${JSON.stringify(e)}`),t.length>512&&(t=`${t.slice(0,480)}${X(t)}`),t}var ze=class{apiHost=N2;apiAuth="";constructor({storeId:e,accessToken:t,apiHost:i}){this.apiHost=i||N2,this.apiAuth=x2(`${e}:${t}`)}async makeRequest(e,t,i){let r={method:e,headers:{Authorization:`Basic ${this.apiAuth}`,"User-Agent":"swell-functions/1.0","Content-Type":"application/json"}},o="";if(i)try{e==="GET"?o=`?${this.stringifyQuery(i)}`:(r.body=JSON.stringify(i),r.headers["Content-Length"]=String(r.body.length))}catch{throw new Error(`Error serializing data: ${i}`)}let a=String(t).startsWith("/")?t.substring(1):t,s=`${this.apiHost}/${a}${o}`,l=await fetch(s,r),h=await l.text(),u;try{u=JSON.parse(h)}catch{u=String(h||"").trim()}if(l.status>299)throw new s4(u,{status:l.status,method:e,endpointUrl:a});if(e!=="GET"&&u?.errors)throw new s4(u.errors,{status:400,method:e,endpointUrl:a});return u}stringifyQuery(e,t){let i=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}[${r}]`:r,l=o!==null&&typeof o=="object"?this.stringifyQuery(o,a):`${encodeURIComponent(a)}=${o===null?"":encodeURIComponent(o)}`;i.push(l)}return i.join("&")}async get(e,t){return this.makeRequest("GET",e,t)}async put(e,t){return this.makeRequest("PUT",e,t)}async post(e,t){return this.makeRequest("POST",e,t)}async delete(e,t){return this.makeRequest("DELETE",e,t)}},s4=class extends Error{status=200;constructor(e,t={}){let i;typeof e=="string"?i=e:i=JSON.stringify(e,null,2),t.method&&t.endpointUrl&&(i=`${t.method} /${t.endpointUrl}
948
+ `):""}isScriptFormActionUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_actions_routes||{};for(let i of Object.values(t))if(e===i)return!0;return!1}isScriptUrl(e){if(!e)return!1;let t=this.shopifyCompatibilityConfig?.editor_configs?.script_routes||{};for(let i of Object.values(t))if(e.startsWith(i))return!0;return!1}needRedirectToPageStart(e){return e?(this.shopifyCompatibilityConfig?.editor_configs?.redirect_to_page_start_forms||[]).includes(e):!1}isCheckoutForm(e){return e?this.shopifyCompatibilityConfig?.editor_configs?.checkout_form===e:!1}};var y=class n{props;stringProp;linkProps;constructor(e,t,i){return this.props=e,this.stringProp=t,this.linkProps=i,new Proxy(e,{get(r,o){let a=r;switch(o){case"toJSON":return e;case"clone":return()=>new n(Ke(e),Ke(t),Ke(i));case"toString":{if(t)return()=>e[t];break}default:break}return a[o]instanceof o3?a[o].resolve().then(s=>(a[o]=s,s),s=>(console.log(s),a[o]=null,null)):a[o]},getPrototypeOf(){return n.prototype}})}valueOf(){return this.stringProp?this.props[this.stringProp]:this}clone(){return new n({})}},o3=class{handler;result;constructor(e){this.result=void 0,this.handler=e}async resolve(){return this.result===void 0&&(this.result=Promise.resolve().then(()=>{let e=this.handler();return this.handler=Zi,e}).then(e=>(e=e!==void 0?e:null,this.result=e,e))),this.result}};function w(n){return new o3(n)}function Fi(n){return R(n)&&(P(n)||typeof n._resolve=="function")}function E2(n){return R(n)&&typeof n._resolve=="function"}async function Ni(n){return Array.isArray(n)?Promise.all(n.map(e=>E2(e)?e._resolve():e)):E2(n)?n._resolve():n}async function v2(n,e){return Ni(n).then(t=>Array.isArray(n)&&Array.isArray(t)?e(...t.map(i=>i||{})):Fi(t)?v2(t,e):e(t||{})).catch(t=>(console.log(t),null))}function d(n,e){return new o3(()=>v2(n,e))}function y4(n,e,t,i,r){return d(e,o=>o[t]?._cloneWithCompatibilityResult(a=>({results:a?.results?.map(s=>{let l=i(n,s);return r&&r(l,s),l})}))||[])}import Rc from"json5";function D3(n){let e={description:n.description,defaultValue:n.default,isLabelHidden:!0,layout:"column",params:n},t;switch(n?.type){case"text":case"short_text":t={type:"swell_short_text"};break;case"paragraph":t={type:"swell_paragraph"};break;case"textarea":case"long_text":case"liquid":t={type:"swell_long_text"};break;case"basic_html":case"rich_text":case"rich_text_pre_heading":case"rich_html":case"markdown":t={type:"swell_editor"};break;case"number":t={type:"swell_number"};break;case"select":t={type:"swell_select"};break;case"radio":t={type:"swell_radio"};break;case"checkbox":t={type:"swell_boolean"};break;case"color":t={type:"swell_color"};break;case"color_scheme":t={type:"swell_color_scheme"};break;case"color_scheme_group":t={type:"swell_color_scheme_group"};break;case"font":t={type:"swell_font"};break;case"header":t={type:"swell_header"};break;case"icon":t={type:"swell_menu"};break;case"menu":t={type:"swell_menu"};break;case"url":t={type:"swell_url"};break;case"lookup":case"generic_lookup":case"product_lookup":case"category_lookup":case"customer_lookup":t={type:"swell_lookup"};break;case"image":t={type:"swell_image",defaultValue:null};break;case"asset":case"document":case"video":t={type:"swell_file"};break;default:t={type:"swell_short_text"};break}return{...e,...t}}function N(n,e,t){if(t===void 0)return null;switch(n?.find(r=>r.id===e)?.type){default:return t}}function Ii(n,e){return e?.reduce((t,i)=>{for(let r of i.fields||[])r?.id&&(t[r.id]=n[r.id]);return t},{})}function Hi(n,e){if(e)return{settings:e.fields.reduce((t,i)=>(i?.id&&(t[i.id]=n[i.id]),t),{$locale:n.$locale}),id:e.id,blocks:n.Blocks?.filter(t=>!!t.props.compiled?._component).map(t=>{let i=t.props.compiled.props,r=t.props.compiled._component.split("__")[2],o=e.blocks?.find(a=>a.type===r);return{type:r,settings:o?.fields?.reduce((a,s)=>(s?.id&&(a[s.id]=i[s.id]),a),{$locale:i.$locale})||{}}})}}function x3(n){return n&&n.replace(/\./g,"\xB7")}function R2(n){return n&&n.replace(/·/g,".")}function X(n){var e="0123456789abcdef";function t(L){var k,T="";for(k=0;k<=3;k++)T+=e.charAt(L>>k*8+4&15)+e.charAt(L>>k*8&15);return T}function i(L,k){var T=(L&65535)+(k&65535),M=(L>>16)+(k>>16)+(T>>16);return M<<16|T&65535}function r(L,k){return L<<k|L>>>32-k}function o(L,k,T,M,H,B){return i(r(i(i(k,L),i(M,B)),H),T)}function a(L,k,T,M,H,B,J){return o(k&T|~k&M,L,k,H,B,J)}function s(L,k,T,M,H,B,J){return o(k&M|T&~M,L,k,H,B,J)}function l(L,k,T,M,H,B,J){return o(k^T^M,L,k,H,B,J)}function h(L,k,T,M,H,B,J){return o(T^(k|~M),L,k,H,B,J)}function u(L){var k,T=(L.length+8>>6)+1,M=new Array(T*16);for(k=0;k<T*16;k++)M[k]=0;for(k=0;k<L.length;k++)M[k>>2]|=L.charCodeAt(k)<<k%4*8;return M[k>>2]|=128<<k%4*8,M[T*16-2]=L.length*8,M}var c,C=u(""+n),m=1732584193,f=-271733879,p=-1732584194,g=271733878,I,W,a3,Je;for(c=0;c<C.length;c+=16)I=m,W=f,a3=p,Je=g,m=a(m,f,p,g,C[c+0],7,-680876936),g=a(g,m,f,p,C[c+1],12,-389564586),p=a(p,g,m,f,C[c+2],17,606105819),f=a(f,p,g,m,C[c+3],22,-1044525330),m=a(m,f,p,g,C[c+4],7,-176418897),g=a(g,m,f,p,C[c+5],12,1200080426),p=a(p,g,m,f,C[c+6],17,-1473231341),f=a(f,p,g,m,C[c+7],22,-45705983),m=a(m,f,p,g,C[c+8],7,1770035416),g=a(g,m,f,p,C[c+9],12,-1958414417),p=a(p,g,m,f,C[c+10],17,-42063),f=a(f,p,g,m,C[c+11],22,-1990404162),m=a(m,f,p,g,C[c+12],7,1804603682),g=a(g,m,f,p,C[c+13],12,-40341101),p=a(p,g,m,f,C[c+14],17,-1502002290),f=a(f,p,g,m,C[c+15],22,1236535329),m=s(m,f,p,g,C[c+1],5,-165796510),g=s(g,m,f,p,C[c+6],9,-1069501632),p=s(p,g,m,f,C[c+11],14,643717713),f=s(f,p,g,m,C[c+0],20,-373897302),m=s(m,f,p,g,C[c+5],5,-701558691),g=s(g,m,f,p,C[c+10],9,38016083),p=s(p,g,m,f,C[c+15],14,-660478335),f=s(f,p,g,m,C[c+4],20,-405537848),m=s(m,f,p,g,C[c+9],5,568446438),g=s(g,m,f,p,C[c+14],9,-1019803690),p=s(p,g,m,f,C[c+3],14,-187363961),f=s(f,p,g,m,C[c+8],20,1163531501),m=s(m,f,p,g,C[c+13],5,-1444681467),g=s(g,m,f,p,C[c+2],9,-51403784),p=s(p,g,m,f,C[c+7],14,1735328473),f=s(f,p,g,m,C[c+12],20,-1926607734),m=l(m,f,p,g,C[c+5],4,-378558),g=l(g,m,f,p,C[c+8],11,-2022574463),p=l(p,g,m,f,C[c+11],16,1839030562),f=l(f,p,g,m,C[c+14],23,-35309556),m=l(m,f,p,g,C[c+1],4,-1530992060),g=l(g,m,f,p,C[c+4],11,1272893353),p=l(p,g,m,f,C[c+7],16,-155497632),f=l(f,p,g,m,C[c+10],23,-1094730640),m=l(m,f,p,g,C[c+13],4,681279174),g=l(g,m,f,p,C[c+0],11,-358537222),p=l(p,g,m,f,C[c+3],16,-722521979),f=l(f,p,g,m,C[c+6],23,76029189),m=l(m,f,p,g,C[c+9],4,-640364487),g=l(g,m,f,p,C[c+12],11,-421815835),p=l(p,g,m,f,C[c+15],16,530742520),f=l(f,p,g,m,C[c+2],23,-995338651),m=h(m,f,p,g,C[c+0],6,-198630844),g=h(g,m,f,p,C[c+7],10,1126891415),p=h(p,g,m,f,C[c+14],15,-1416354905),f=h(f,p,g,m,C[c+5],21,-57434055),m=h(m,f,p,g,C[c+12],6,1700485571),g=h(g,m,f,p,C[c+3],10,-1894986606),p=h(p,g,m,f,C[c+10],15,-1051523),f=h(f,p,g,m,C[c+1],21,-2054922799),m=h(m,f,p,g,C[c+8],6,1873313359),g=h(g,m,f,p,C[c+15],10,-30611744),p=h(p,g,m,f,C[c+6],15,-1560198380),f=h(f,p,g,m,C[c+13],21,1309151649),m=h(m,f,p,g,C[c+4],6,-145523070),g=h(g,m,f,p,C[c+11],10,-1120210379),p=h(p,g,m,f,C[c+2],15,718787259),f=h(f,p,g,m,C[c+9],21,-343485551),m=i(m,I),f=i(f,W),p=i(p,a3),g=i(g,Je);return t(m)+t(f)+t(p)+t(g)}function Vi(n,e){if(!n.file_path.startsWith("theme/sections/"))return!1;if(n.file_path.endsWith(".liquid")){if(!e.get(n.file_path.replace(/\.liquid$/,".json")))return!0}else if(n.file_path.endsWith(".json"))return!0;return!1}async function y2(n,e){let t=[];for(let i of n.values())if(Vi(i,n)){let r=await e(i);r&&t.push({...r,id:String(i.name||"").split(".").pop()??"",...r&&{presets:Ui(r)}})}return t}function Ui(n){return Array.isArray(n?.presets)?n.presets.map(e=>({label:e.label,settings:{...n.fields?.reduce((t,i)=>(i.id&&i.default!==void 0&&(t[i.id]=i.default),t),{}),...e.settings||void 0},blocks:e.blocks?.map(t=>{let i=n.blocks?.find(r=>r.type===t.type);return i?{...t,settings:{...i.fields.reduce((r,o)=>(o.id&&o.default!==void 0&&(r[o.id]=o.default),r),{}),...t.settings||void 0}}:t})})):[]}async function S2(n,e){let t=Array.from(n.values()),i=t.filter(a=>a.file_path.endsWith(".json")&&!n.has(a.file_path.replace(/\.json$/,".liquid"))),r=async a=>{let s=t.find(h=>{if(!h.file_path.endsWith(`/${a}.json`)&&!h.file_path.endsWith(`/${a}.liquid`))return!1;if(h.file_path.endsWith(".liquid")){if(!n.get(h.file_path.replace(/\.liquid$/,".json")))return!0}else if(h.file_path.endsWith(".json"))return!0;return!1});return s?{...await e(s),id:String(s.name||"").split(".").pop()}:void 0},o=[];for(let a of i){let s;try{s=Oi.parse(a.file_data)}catch(l){console.warn(l)}if(s?.type){let l=await De(s,r);o.push({...s,id:String(a.name||"").split(".").pop(),sectionConfigs:l})}}return o}async function De(n,e){let t=Array.isArray(n?.order)&&n.order.length>0?n.order:Object.keys(n?.sections||{}),i=[];for(let r of t){let o=n.sections?.[r];if(!o)continue;let a=await e(o.type)||{id:o.type,label:o.type,tag:"div",class:"",fields:[],blocks:[]},s=n.id?`page__${n.id}__${r}`:a.id,h=(Array.isArray(o.block_order)?o.block_order:Object.keys(o.blocks||{})).map(c=>o.blocks?.[c]).filter(Boolean),u={section:{id:s,...o,blocks:h}};i.push({id:s,section:{id:s,...o},schema:a,settings:u,tag:a.tag||"div",class:a.class})}return i}function qc(n){return String(n)==="[object Array]"}function v(n){let e=typeof n;return n!==null&&(e==="object"||e==="function")}function x2(n){let e=new TextEncoder().encode(n),t="";for(let i=0;i<e.length;i+=3){let r=Array.from(e.slice(i,i+3));t+=btoa(String.fromCharCode(...r))}return t}function C2(n,e="id"){return qi(n,(t,i)=>(t[String(i[e])]=i,t),{})}function M5(n){let e=n.split(/-|_/),t=e.pop()?.toUpperCase(),i=e.join("-");return(t||d5[i]||"").toLowerCase()}function P5(n){return v(n)&&Object.hasOwn(n,"code")&&Object.hasOwn(n,"name")&&Object.hasOwn(n,"fallback")}function j2(n,e){if(!(typeof n!="object"||n===null))for(let[t,i]of Object.entries(n))e(t,n)!==!1&&typeof i=="object"&&i!==null&&j2(i,e)}function Oc(n){let e=new Set;return j2(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return!1;e.add(i)}return!0}),Array.from(e)}function Vc(n){if(!n)return n;let e=new WeakSet;return JSON.parse(JSON.stringify(n,(t,i)=>{if(typeof i=="object"&&i!==null){if(e.has(i))return JSON.parse(JSON.stringify(i));e.add(i)}return i}))}function $i(n){if(!(typeof n!="object"||n===null))for(let[e,t]of Object.entries(n))e==="_swell"&&"_swell"in n?n[e]=void 0:$i(t)}function D2(n){if(n!==void 0)return n instanceof b?"SwellStorefrontCollection":n instanceof A?"SwellStorefrontRecord":n instanceof y?"ShopifyResource":n instanceof _?"StorefrontResource":"promise"}async function G(n,e=!0,t=!1){let i=n,r=e;try{if(P(n)&&(r=!1,i=await n),n instanceof _&&(r=!1,i=await G(n.resolve(),e,t)),Array.isArray(i)){let o=await Promise.all(i.map(a=>G(a,e,t)));if(i=o,!o.some(a=>a!==void 0))return e?[]:void 0}else if(typeof i=="object"&&i!==null&&(!("_swell"in i)||!i._swell)){let o={};for(let[a,s]of Object.entries(i)){if(!e&&(P(s)||s instanceof _||s instanceof y)){o[a]={_type:D2(s),...t?{value:await G(s,r,t)}:void 0};continue}if(s instanceof _&&t){o[a]={_type:D2(s),value:await G(s,r,t)};continue}o[a]=await G(s,r,t)}return!e&&Object.keys(o).length===0?void 0:o}}catch(o){return console.error(o),n}return i}function V(n){return Bi.stringify({...n,sections:void 0,section_id:void 0},{encodeValuesOnly:!0,arrayFormat:"repeat"})}function k2(n,e){return n=Array.isArray(n)?n.join(" "):n,n.split("}").map(r=>{let[o,a]=r.split("{");return!o||!a?"":`${o.split(",").map(l=>`#${e} ${l.trim()}`).join(", ")} {${a}}`}).join(" ")}function T3(n,e){return Object.entries(n).reduce((t,[i,r])=>(r?.value!==null&&r?.value!==void 0&&(t[R2(i)]=r?.value),t),Gi(e))}var t4="ContentSections";function C3(n){return`SectionGroup_${n}`}var zi="THEME",Wi=5*1e3,Ji=1e3*60*60*24*7,Yi=Object.freeze({ttl:Wi}),F2="__NULL__",O=class{client;constructor(e){e=e||{},e.stores=e.stores||Qi(e.kvStore),this.client=Ki({...Yi,...e})}async fetch(e,t){return this.client.wrap(e,t)}async fetchSWR(e,t,i=Ji){let r=await this.client.get(e);console.log("Cache.fetchSWR",{key:e,ttl:i,cacheValue:!!r});let o=Promise.resolve().then(()=>t()).then(async s=>{let l=s==null,h=await G(s);return console.log("Cache.fetchSWR result",{key:e,value:!!s,valueResolved:!!h}),await this.client.set(e,l?F2:h,i),s});return r!==null?r===F2?null:r:await o}async get(e){return this.client.get(e)}async set(e,t,i){return this.client.set(e,t,i)}async flush(e){await this.client.del(e)}async flushAll(){await this.client.clear()}};function Qi(n){let e=[];return n?e.push(new Z2({namespace:zi,store:new N3(n)})):e.push(new Z2),e}var j3=class extends O{constructor(e){super({...e})}};import{Keyv as Xi}from"keyv";var Z3=class extends O{constructor(e){super({stores:e6(),...e})}};function e6(){return[new Xi({serialize:void 0,deserialize:void 0})]}var t6=90*24*60*60*1e3,b3=class extends O{constructor(e){super({ttl:t6,...e})}};var N2="https://api.schema.io",I2=new Map,H2=new Map,B2=class n{url;headers;swellHeaders;queryParams;workerEnv;config;shopifyCompatibilityConfig;backend;storefront;storefrontContext;instanceId="";isPreview=!1;isEditor=!1;sentResponse=!1;storefront_url;resourceLoadingIndicator;constructor(e){let{url:t,config:i,shopifyCompatibilityConfig:r,headers:o,swellHeaders:a,serverHeaders:s,queryParams:l,workerEnv:h,...u}=e;if(this.url=t instanceof URL?t:new URL(t||""),this.config=i,this.shopifyCompatibilityConfig=r,this.queryParams=n.formatQueryParams(l||this.url.searchParams),this.workerEnv=h,this.resourceLoadingIndicator=e.resourceLoadingIndicator,console.log(`KV cache: ${this.workerEnv?.THEME?"enabled":"disabled"}`),s){let{headers:c,swellHeaders:C}=n.formatHeaders(s);this.headers=c,this.swellHeaders=C,this.backend=new ze({storeId:C["store-id"],accessToken:C["access-token"],apiHost:C["api-host"]}),this.storefront=this.getStorefrontInstance({...e,headers:c,swellHeaders:C}),this.instanceId=["store-id","environment-id","deployment-mode","theme-id","theme-branch-id"].map(m=>C[m]||"0").join(":"),this.isEditor=u.isEditor??C["deployment-mode"]==="editor",this.isPreview=this.isEditor||C["deployment-mode"]==="preview"}else if(o&&a)Object.assign(this,u),this.headers=o,this.swellHeaders=a,this.storefront=this.getStorefrontInstance(e);else throw new Error("Swell client requires `serverHeaders` when initialized on the server-side, or `headers` and `swellHeaders` when initialized on the client-side.");this.storefrontContext=this.initStorefrontContext()}static formatHeaders(e){let t={},i={};e instanceof Headers?e.forEach((r,o)=>{t[o]=r}):e&&(t=e);for(let[r,o]of Object.entries(t))r.startsWith("swell-")&&o&&(i[r.replace("swell-","")]=o);return{headers:t,swellHeaders:i}}static formatQueryParams(e){let t={};return e instanceof URLSearchParams?t=n6.parse(e.toString()):e&&(t=e),t}async getCachedResource(e,t,i){let r=G2(e,[this.instanceId,t]);return this.getResourceCache().fetchSWR(r,i)}async getAppSettings(){return await this.get("/:storefronts/{id}/configs/settings/values",{id:this.swellHeaders["storefront-id"]})||{}}async getStorefrontSettings(e=!1){try{let{settings:t,menus:i,payments:r,subscriptions:o,session:a}=await this.storefront.request("get","/settings/all",void 0,void 0,{force:e}),s=this.storefront.settings;s.localizedState={},s.set({value:t}),s.set({model:"menus",value:i}),s.set({model:"payments",value:r}),s.set({model:"subscriptions",value:o}),s.set({model:"session",value:a})}catch(t){t instanceof Error&&(t.message=`Swell: unable to load settings (${t.message})`),console.error(t)}return this.storefront.settings.get()}getStorefrontMenus(){let e=this.storefront.settings.getState("/settings/menus","menuState");return!e||P(e)?[]:e}getStorefrontLocalization(){let e=this.storefront.locale.selected(),t=this.storefront.currency.selected();return!e||P(e)?{locale:"en-US",currency:"USD"}:{locale:e,currency:t}}async get(...e){return this.backend?.get(...e)}async put(...e){return this.backend?.put(...e)}async post(...e){return this.backend?.post(...e)}async delete(...e){return this.backend?.delete(...e)}isLoading(e=!0){this.resourceLoadingIndicator&&this.resourceLoadingIndicator(e)}getStorefrontInstance(e){let{swellHeaders:t,getCookie:i,setCookie:r,storefrontSettingStates:o}=e;if(!t)throw new Error("Swell headers are required");let a=t["store-id"],s=t["public-key"];if(!a||!s)throw new Error('Missing required headers: "swell-store-id" and "swell-public-key"');let l=i6.create(a,s,{url:t["admin-url"],vaultUrl:t["vault-url"],getCookie:i,setCookie:r&&((h,u,c)=>r(h,u,c,this)),headers:{"Swell-Store-id":a,"Swell-Storefront-Id":t["storefront-id"]}});return o&&Object.assign(l.settings,o),l.request=this.getCacheableStorefrontRequestHandler(l),l}initStorefrontContext(){let e={};if(this.swellHeaders?.["storefront-context"])try{e=JSON.parse(decodeURIComponent(this.swellHeaders["storefront-context"]))}catch{console.error("Failed to parse swell-storefront-context. Ignoring...")}return e}isStorefrontRequestCacheable(e,t,i){if(i?.force)return!1;if(e==="get")switch(t.split("/")[1]){case"products":case"categories":case"content":case"settings":return!0;default:return!1}return!1}getCacheableStorefrontRequestHandler(e){let t=e.request;return(i,r,o,a,s)=>{if(this.isStorefrontRequestCacheable(i,r,s))return this.getRequestCache().fetchSWR(G2("request",[this.instanceId,i,r,o,a,s]),()=>(console.log("Storefront request",{method:i,url:r,id:o,data:a}),t(i,r,o,a,s)));switch(i){case"delete":case"post":case"put":{let l=r.split("/")[1];delete this.storefrontContext[l];break}default:}return t(i,r,o,a,s)}}getResourceCache(){let e=I2.get(this.instanceId);return e||(e=new Z3({kvStore:this.workerEnv?.THEME}),I2.set(this.instanceId,e)),e}getRequestCache(){let e=H2.get(this.instanceId);return e||(e=new j3({kvStore:this.workerEnv?.THEME}),H2.set(this.instanceId,e)),e}};function G2(n,e){let t=n;return Array.isArray(e)&&e.length>0&&(t+=`_${JSON.stringify(e)}`),t.length>512&&(t=`${t.slice(0,480)}${X(t)}`),t}var ze=class{apiHost=N2;apiAuth="";constructor({storeId:e,accessToken:t,apiHost:i}){this.apiHost=i||N2,this.apiAuth=x2(`${e}:${t}`)}async makeRequest(e,t,i){let r={method:e,headers:{Authorization:`Basic ${this.apiAuth}`,"User-Agent":"swell-functions/1.0","Content-Type":"application/json"}},o="";if(i)try{e==="GET"?o=`?${this.stringifyQuery(i)}`:(r.body=JSON.stringify(i),r.headers["Content-Length"]=String(r.body.length))}catch{throw new Error(`Error serializing data: ${i}`)}let a=String(t).startsWith("/")?t.substring(1):t,s=`${this.apiHost}/${a}${o}`,l=await fetch(s,r),h=await l.text(),u;try{u=JSON.parse(h)}catch{u=String(h||"").trim()}if(l.status>299)throw new s4(u,{status:l.status,method:e,endpointUrl:a});if(e!=="GET"&&u?.errors)throw new s4(u.errors,{status:400,method:e,endpointUrl:a});return u}stringifyQuery(e,t){let i=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}[${r}]`:r,l=o!==null&&typeof o=="object"?this.stringifyQuery(o,a):`${encodeURIComponent(a)}=${o===null?"":encodeURIComponent(o)}`;i.push(l)}return i.join("&")}async get(e,t){return this.makeRequest("GET",e,t)}async put(e,t){return this.makeRequest("PUT",e,t)}async post(e,t){return this.makeRequest("POST",e,t)}async delete(e,t){return this.makeRequest("DELETE",e,t)}},s4=class extends Error{status=200;constructor(e,t={}){let i;typeof e=="string"?i=e:i=JSON.stringify(e,null,2),t.method&&t.endpointUrl&&(i=`${t.method} /${t.endpointUrl}
949
949
  ${i}`),super(i),this.name="SwellError",this.status=t.status||500}};function q2(n,e){return new b(n,"products",e)}function kh(n,e,t){return new A(n,"products",e,t)}function Lh(n,{search:e,filter:t,sort:i}){return new b(n,"products",{search:e,filter:t,sort:i})}function Mh(n,e){return new b(n,"categories",e)}function r6(n,e,t){return new A(n,"categories",e,t)}async function Ph(n,e,t){let i=r6(n,e,t),r=await i.id;return i.products=q2(n,{category:r}),i}function Dh(n,e){return n.getCachedResource(`content-model-${e}`,[],()=>n.get("/:content/{name}",{name:e,public:!0,"storefront.enabled":!0}))}async function o6(n,e,t){return new b(n,`content/${e}`,t)}async function O2(n,e,t,i){return new A(n,`content/${e}`,t,i)}async function xh(n,e,t){return O2(n,"pages",e,t)}async function jh(n,e){return o6(n,"blogs",e)}async function Zh(n,e,t){return O2(n,"blogs",e,t)}import a6 from"json5";import{reduce as z}from"lodash-es";var l4=!0;async function Gh(n,e){let t=null;if(t=await n.getThemeTemplateConfigByType("templates",e),t){if(t.file_path.endsWith(".liquid"))return t.file_data;try{return a6.parse(t.file_data)}catch{return t.file_data}}}function s6(n,e){return n.reduce((t,i)=>(i.enabled_on?c4(i.enabled_on,"groups",e)&&t.push(String(i.id)):i.disabled_on?c4(i.disabled_on,"groups",e)||t.push(String(i.id)):i.id===e&&t.push(String(i.id)),t),[])}function l6(n,e){return e.map(t=>({prop:C3(t.id),type:"component-collection",label:t.label,required:!0,noInline:l4,accepts:s6(n,t.type)}))}function c4(n,e,t){return!!(n.templates==="*"||n[e]?.includes(t))}function c6(n,e,t){return n.reduce((i,r)=>(r.enabled_on?c4(r.enabled_on,"templates",t)&&i.push(String(r.id)):r.disabled_on?c4(r.disabled_on,"templates",t)||i.push(String(r.id)):e.some(({type:o})=>o===r.id)||i.push(String(r.id)),i),[])}function h6(n){return(n?.configs?.editor?.settings??[]).reduce((e,t)=>{for(let i of t.fields||[])e.push({prop:x3(i.id),label:i.label,optional:!0,group:t.label,...D3(i)});return e},[])}function d6(n){let e=[];for(let t of n){let i=Array.isArray(t.blocks)&&t.blocks.length>0;e.push({id:t.id,label:t.label,schema:[...(t.fields||[]).reduce((r,o)=>(o.id&&o.type&&r.push({prop:x3(o.id),label:o.label,optional:!0,...D3(o)}),r),[]),...i?[{prop:"Blocks",type:"component-collection",required:!0,noInline:l4,accepts:(t.blocks||[]).map(r=>`Block__${t.id}__${r.type}`),defaultValue:t.presets?.reduce((r,o,a)=>o.blocks?o.blocks.reduce((s,l)=>{let h=t.blocks?.find(({type:u})=>u===l.type);return h&&s.push({_id:`Block__${t.id}__${l.type}__preset_${a}`,_component:`Block__${t.id}__${l.type}`,...z(h.fields,(u,c)=>(c.id&&(u[c.id]=N(h.fields,c.id,c.default)),u),{})}),s},r):r,[]),placeholderAppearance:{height:50,label:"Add block",aspectRatio:1}}]:[],{prop:"custom_css",type:"swell_css",label:"Custom CSS",description:"Add custom CSS for this section",layout:"column",isLabelHidden:!0,params:{rows:5,placeholder:"Enter custom CSS..."}},{prop:"$locale",type:"swell_locale",isLabelHidden:!0}],styles:()=>({styled:{Root:{}}})}),i&&e.push(...(t.blocks||[]).map(r=>({id:`Block__${t.id}__${r.type}`,label:r.label,schema:(r.fields||[]).reduce((o,a)=>(a.id&&a.type&&o.push({prop:x3(a.id),label:a.label,optional:!0,...D3(a)}),o),[{prop:"$locale",type:"swell_locale",isLabelHidden:!0}]),styles:()=>({styled:{Root:{}}})})))}return e}function u6(n){return n?.configs?.editor?.settings?.reduce((e,t)=>{for(let i of t.fields||[])i?.id&&(e[i.id]=N(t.fields,i.id,n?.configs?.theme?.[i.id]));return e},{})}function m6(n){return n.reduce((e,t)=>(e[C3(t.id)]=t.sectionConfigs.map(({section:i,settings:r,schema:o})=>({_id:`SectionGroup__${i.type}_${V2()}`,_component:i.type,...z(r?.section.settings,(a,s,l)=>(a[l]=N(o?.fields,l,s),a),{}),custom_css:r?.section.custom_css||"",...r?.section.blocks?{Blocks:r.section.blocks.map(a=>({_id:`Block__${i.type}__${a.type}_${V2()}`,_component:`Block__${i.type}__${a.type}`,...z(a.settings,(s,l,h)=>(s[h]=N(o?.blocks?.find(({type:u})=>u===a.type)?.fields,h,l),s),{})}))}:void 0})),e),{})}function p6(n){return(n||"").replaceAll("/","_")}function C6(n){let e=[];for(let t of n)t.presets&&e.push(...t.presets.map((i,r)=>({id:`${t.id}__preset_${r}`,entry:{_id:`${t.id}__preset_${r}`,_component:t.id,custom_css:i.settings?.custom_css||"",...z(t.fields,(o,a)=>(a.id&&(o[a.id]=N(t.fields,a.id,i.settings?.[a.id])),o),{}),Blocks:i.blocks?.reduce((o,a)=>{let s=t.blocks?.find(({type:l})=>l===a.type);return s&&o.push({_id:`Block__${t.id}__${a.type}__preset_${r}`,_component:`Block__${t.id}__${a.type}`,...z(s.fields,(l,h)=>(h.id&&(l[h.id]=N(s.fields,h.id,a.settings?.[h.id])),l),{})}),o},[])}}))),t.blocks&&e.push(...t.blocks.map(i=>({id:`Block__${t.id}__${i.type}`,entry:{_id:`Block__${t.id}__${i.type}`,_component:`Block__${t.id}__${i.type}`,...z(i.fields,(r,o)=>(o.id&&(r[o.id]=N(i.fields,o.id,o.default)),r),{})}})));return e.filter(t=>Object.keys(t.entry).some(i=>i!=="_id"&&i!=="_component"))}function qh(n,e,t,i,r){let o={id:"swell_global",label:"Theme settings",schema:[{prop:"swell_page",type:"component",required:!0,accepts:["swell_page"],isNonChangable:!0,noInline:l4},{prop:"$locale",type:"swell_locale",isLabelHidden:!0},...h6(n)],groups:(n?.configs?.editor?.settings??[]).map(c=>({key:c.label,label:c.label,collapsable:!0,collapsed:!0})),styles:()=>({styled:{Root:{}}})},a={id:"swell_page",label:"Page settings",schema:[{prop:t4,type:"component-collection",required:!0,noInline:l4,accepts:c6(e,i,r),placeholderAppearance:{height:250,label:"Add section",aspectRatio:1}},...l6(e,i)],allowSave:!0,styles:()=>({styled:{Root:{}}})},s=[o,a,...d6(e)],l=o.schema.find(c=>c.prop==="color_schemes");if(l){let c=l.params,{fields:C=[]}=c;s.push({id:"swell_color_scheme_group",label:"Swell color scheme",schema:C.map(m=>({prop:x3(m.id),label:m.label,optional:!0,...D3({...m,type:m.id==="background_gradient"?"text":m.type})})),styles(){return{styled:{Root:{}}}}})}let h=new Set;for(let c of s)h.add(c.id);let u=[{id:"swell_global",entry:{_id:"swell_global",_component:"swell_global",...u6(n),$locale:n?.configs?.theme?.$locale,swell_page:[{_id:"swell_page",_component:"swell_page",ContentSections:t.filter(c=>h.has(c.section.type)).map(({section:c,settings:C,schema:m})=>({_id:p6(c.id),_component:c.type,custom_css:C?.section?.custom_css||"",disabled:C?.section?.disabled||!1,$locale:C?.section?.settings?.$locale,...z(m?.fields,(f,p)=>(p?.id&&(f[p.id]=N(m?.fields,p.id,C?.section?.settings?.[p.id])),f),{}),...c?.blocks?{Blocks:Object.entries(c.blocks).map(([f,p])=>({_id:`Block__${f}__${p.type}_${Math.random()}`,_component:`Block__${c.type}__${p.type}`,disabled:p.disabled||!1,...z(p.settings,(g,I,W)=>(g[W]=N(m?.blocks?.find(({type:a3})=>a3===p.type)?.fields,W,I),g),{})}))}:void 0})),...m6(i)}]}},{id:"swell_page",entry:{_id:"swell_page",_component:"swell_page"}},...C6(e)];return{easyblocksConfig:{components:s,templates:u,backend:f6(),hideCloseButton:!0,allowSave:!0,readOnly:!1,locales:[{code:"en-US",isDefault:!0}],types:{swell_css:{type:"inline",widget:{id:"SwellCSS"}},swell_locale:{type:"inline",widget:{id:"SwellLocale"}},swell_boolean:{type:"inline",widget:{id:"SwellBoolean"}},swell_color:{type:"inline",widget:{id:"SwellColor"}},swell_color_scheme:{type:"inline",widget:{id:"SwellColorScheme"}},swell_color_scheme_group:{type:"inline",widget:{id:"SwellColorSchemeGroup"}},swell_font:{type:"inline",widget:{id:"SwellFont"}},swell_header:{type:"inline",widget:{id:"SwellHeader"}},swell_icon:{type:"inline",widget:{id:"SwellIcon"}},swell_lookup:{type:"inline",widget:{id:"SwellLookup"}},swell_menu:{type:"inline",widget:{id:"SwellMenu"}},swell_url:{type:"inline",widget:{id:"SwellUrl"}},swell_number:{type:"inline",widget:{id:"SwellNumber"}},swell_select:{type:"inline",widget:{id:"SwellSelect"}},swell_radio:{type:"inline",widget:{id:"SwellRadio"}},swell_short_text:{type:"inline",widget:{id:"SwellText"}},swell_long_text:{type:"inline",widget:{id:"SwellTextarea"}},swell_paragraph:{type:"inline",widget:{id:"SwellParagraph"}},swell_editor:{type:"inline",widget:{id:"SwellEditor"}},swell_file:{type:"inline",widget:{id:"SwellFile"}},swell_image:{type:"inline",widget:{id:"SwellImage"}}},tokens:{colors:[],fonts:[]}}}}function Oh(n,e,t){let i=n.reduce((a,s)=>(a[`${s.id}`]=t("pageSection",s),a),{}),r=e.reduce((a,s)=>(a[C3(s.id)]=t("layoutSectionGroup",s),a),{}),o=n.reduce((a,s)=>{if(s.blocks)for(let l of s.blocks){let h=`Block__${s.id}__${l.type}`;a[h]=t("block",{section:s,block:l})}return a},{});return{...i,...r,...o,swell_page:t("root"),swell_global:t("global")}}function f6(){return{documents:{get({id:e}){console.log("Easyblocks backend documents.get()",e);let t={id:e,version:1,entry:{_id:"page",_component:"swell_page"}};return Promise.resolve(t)},create(e){return console.log("Easyblocks backend documents.create()",e),Promise.resolve({})},update(e){return console.log("Easyblocks backend documents.update()",e),Promise.resolve({})}},templates:{get(e){return console.log("Easyblocks backend templates.get()",e),Promise.resolve({})},getAll(){return console.log("Easyblocks backend get templates.getAll()"),Promise.resolve([])},create(e){return console.log("Easyblocks backend get templates.create()",e),Promise.resolve({})},update(e){return console.log("Easyblocks backend get templates.update()",e),Promise.resolve({})},delete(e){return console.log("Easyblocks backend get templates.delete()",e),Promise.resolve()}}}}function V2(){return(Math.random()+1).toString(36).substring(7)}function h4(n,e){let i=n?.storefront?.options?.getCookie;return typeof i=="function"&&i(e)||""}var U2=class extends A{constructor(e,t,i={}){super(e,"",t,i,async function(){let r=await K2(e,this._resourceName,t,i);return F3(this._resourceName,r,e,"",t,i)})}},$2=class extends Q{constructor(e,t,i={}){super(e,"",async function(){let r=await K2(e,this._resourceName,t,i);return F3(this._resourceName,r,e,"",t,i)})}};async function K2(n,e,t,i){let r=new URLSearchParams({...t&&{slug:t},...i&&{query:JSON.stringify(i)}}),o=r.size>0?`?${r}`:"",a=h4(n,"swell-session"),s=h4(n,"swell-data")||{};return(await fetch(`${n.storefront_url}/resources/${e}.json/${o}`,{headers:{"X-Session":a,"Swell-Data":JSON.stringify(s)}})).json()}function F3(n,e,t,i="",r,o){let a={};for(let[s,l]of Object.entries(e)){let h=i+`${i===""?"":"/"}${s}`,u;switch(l?._type){case"SwellStorefrontCollection":u=y6;break;case"SwellStorefrontRecord":u=w6;break;case"createStorefrontResource":u=g6;break;default:break}a[s]=u?u(n,t,h,r,o):l}return a}function g6(n,e,t,i,r){return new _(async function(){let o=await We(e,n,t,i,r);return F3(n,o,e,t,i,r)})}function w6(n,e,t,i,r){let o=z2(i,r);return new A(e,n,t,o,async function(){let a=await We(e,n,t,i,r);return F3(n,a,e,t,i,r)})}function y6(n,e,t,i,r){let o=z2(i,r);return new b(e,n,o,async function(){let a=await We(e,n,t,i,r);return F3(n,a,e,t,i,r)})}async function We(n,e,t,i,r){let o=new URLSearchParams({path:t,...i&&{slug:i},...r&&{query:JSON.stringify(r)}}),a=o.size>0?`?${o}`:"",s=h4(n,"swell-session"),l=h4(n,"swell-data")||{};return(await fetch(`${n.storefront_url}/resources/${e}.json${a}`,{headers:{"X-Session":s,"Swell-Data":JSON.stringify(l)}})).json()}function z2(n,e){return{...n&&{slug:n},...e}}export{n5 as DEFAULT_QUERY_PAGE_LIMIT,o3 as DeferredShopifyResource,S4 as FILE_DATA_INCLUDE_QUERY,h5 as GEO_DATA,d5 as LANG_TO_COUNTRY_CODES,W3 as LiquidSwell,i5 as MAX_QUERY_PAGE_LIMIT,U2 as MockRecordResource,$2 as MockRecordSingleton,Q3 as PageError,X3 as PageNotFound,t4 as SECTION_GROUP_CONTENT,_3 as ShopifyArticle,xe as ShopifyBlog,w3 as ShopifyCart,q as ShopifyCollection,Ze as ShopifyCollections,A3 as ShopifyCompatibility,i3 as ShopifyCustomer,P3 as ShopifyFont,o4 as ShopifyForm,E3 as ShopifyLink,k3 as ShopifyLocalization,u3 as ShopifyOrder,Be as ShopifyPage,y3 as ShopifyPaginate,Ie as ShopifyPredictiveSearch,E as ShopifyProduct,He as ShopifyRecommendations,y as ShopifyResource,Ge as ShopifySearch,$ as ShopifyVariant,_ as StorefrontResource,B2 as Swell,ze as SwellBackendAPI,s4 as SwellError,b as SwellStorefrontCollection,H3 as SwellStorefrontPagination,A as SwellStorefrontRecord,g3 as SwellStorefrontResource,Q as SwellStorefrontSingleton,f2 as SwellTheme,S as ThemeColor,D as ThemeFont,e3 as ThemeForm,C4 as ThemeFormErrors,Oe as adaptShopifyFontData,Ve as adaptShopifyFormData,qe as adaptShopifyMenuData,C2 as arrayToObject,m3 as deferMenuItemUrlAndResource,$i as dehydrateSwellRefsInStorefrontResources,T3 as extractSettingsFromForm,Oc as findCircularReferences,w2 as findEditorSetting,g2 as findThemeSettingsByType,p4 as fontMap,j2 as forEachKeyDeep,y2 as getAllSections,Zh as getBlog,jh as getBlogs,Mh as getCategories,r6 as getCategory,Ph as getCategoryWithProducts,O2 as getContentEntry,o6 as getContentList,Dh as getContentModel,M5 as getCountryCodeFromLocale,f6 as getEasyblocksBackend,Oh as getEasyblocksComponentDefinitions,qh as getEasyblocksPagePropsWithConfigs,Gh as getEasyblocksPageTemplate,S2 as getLayoutSectionGroups,p3 as getMenuItemStorefrontUrl,si as getMenuItemUrlAndResource,ai as getMenuItemValueId,xh as getPage,De as getPageSections,kh as getProduct,q2 as getProducts,Lh as getProductsFiltered,C3 as getSectionGroupProp,Hi as getSectionSettingsFromProps,Ii as getThemeSettingsFromProps,qc as isArray,P5 as isLikeSwellLocale,v as isObject,X as md5,Vc as removeCircularReferences,G as resolveAsyncResources,pi as resolveLookupCollection,ri as resolveMenuItemUrlAndResource,m2 as resolveMenuItems,u2 as resolveMenuSettings,Re as resolveSectionSettings,e4 as resolveThemeSettings,k2 as scopeCustomCSS,V as stringifyQueryParams,v6 as systemFonts,x2 as toBase64};
950
950
  //# sourceMappingURL=index.mjs.map