@swishapp/sdk 0.105.0 → 0.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/swish.js +1 -1
- package/package.json +1 -1
package/dist/swish.js
CHANGED
|
@@ -451,4 +451,4 @@ Values:
|
|
|
451
451
|
left: 0px;
|
|
452
452
|
right: 0px;
|
|
453
453
|
}
|
|
454
|
-
`),document.documentElement.setAttribute("swish-locked",""))}unlockScroll(){this.scrollLockRefCount>0&&this.scrollLockRefCount--,this.scrollLockRefCount===0&&(this.scrollLockStyleSheet&&this.scrollLockStyleSheet.replaceSync(""),window.scrollTo({top:this.scrollPositionBeforeLock,behavior:"instant"}),this.scrollPositionBeforeLock=0,document.documentElement.removeAttribute("swish-locked"))}};var gs=typeof HTMLElement<"u"?HTMLElement:class{},it=class extends gs{constructor(){super();this.getComponentRef=s(()=>this.componentRef,"getComponentRef");this.setComponentRef=s(t=>{this.componentRef=t},"setComponentRef");this.shadowRoot||this.attachShadow({mode:"open"});let t=this.querySelector("template");t&&this.shadowRoot&&(this.shadowRoot.appendChild(t.content),t.remove())}static{s(this,"SwishUiElement")}};var st=class{static{s(this,"ShopifyBadgesUtils")}#e;constructor({getBadges:e}){this.#e=e?.bind(this)}getBadges({product:e,variant:t}){try{let r=this.getDefaultBadges({product:e,variant:t});return this.#e?this.mapBadges(this.#e({product:e,variant:t,defaultBadges:r})??[]):this.mapBadges(r)}catch(r){return console.error("Error getting badges",r),[]}}getDefaultBadges({product:e,variant:t}){let r=[];if(e?.availableForSale===!1||t?.availableForSale===!1)return r.push("Sold out"),r;let i=t?t.price.amount:e?.priceRange?.minVariantPrice.amount,o=t?t.compareAtPrice?.amount:e?.compareAtPriceRange?.minVariantPrice.amount;return o&&parseFloat(o)>parseFloat(i)&&r.push("Sale"),r}mapBadges(e){return e.map(t=>typeof t=="string"?{id:t.toLowerCase().replace(/[^a-z0-9]/g,"_"),label:t}:t)}};var Fe="0.105.
|
|
454
|
+
`),document.documentElement.setAttribute("swish-locked",""))}unlockScroll(){this.scrollLockRefCount>0&&this.scrollLockRefCount--,this.scrollLockRefCount===0&&(this.scrollLockStyleSheet&&this.scrollLockStyleSheet.replaceSync(""),window.scrollTo({top:this.scrollPositionBeforeLock,behavior:"instant"}),this.scrollPositionBeforeLock=0,document.documentElement.removeAttribute("swish-locked"))}};var gs=typeof HTMLElement<"u"?HTMLElement:class{},it=class extends gs{constructor(){super();this.getComponentRef=s(()=>this.componentRef,"getComponentRef");this.setComponentRef=s(t=>{this.componentRef=t},"setComponentRef");this.shadowRoot||this.attachShadow({mode:"open"});let t=this.querySelector("template");t&&this.shadowRoot&&(this.shadowRoot.appendChild(t.content),t.remove())}static{s(this,"SwishUiElement")}};var st=class{static{s(this,"ShopifyBadgesUtils")}#e;constructor({getBadges:e}){this.#e=e?.bind(this)}getBadges({product:e,variant:t}){try{let r=this.getDefaultBadges({product:e,variant:t});return this.#e?this.mapBadges(this.#e({product:e,variant:t,defaultBadges:r})??[]):this.mapBadges(r)}catch(r){return console.error("Error getting badges",r),[]}}getDefaultBadges({product:e,variant:t}){let r=[];if(e?.availableForSale===!1||t?.availableForSale===!1)return r.push("Sold out"),r;let i=t?t.price.amount:e?.priceRange?.minVariantPrice.amount,o=t?t.compareAtPrice?.amount:e?.compareAtPriceRange?.minVariantPrice.amount;return o&&parseFloat(o)>parseFloat(i)&&r.push("Sale"),r}mapBadges(e){return e.map(t=>typeof t=="string"?{id:t.toLowerCase().replace(/[^a-z0-9]/g,"_"),label:t}:t)}};var Fe="0.105.1",lp=`https://swish.app/cdn/sdk@${Fe}/swish.js`,cp=s(async n=>{if(typeof window>"u")throw new Error("Swish is not supported in this environment");if(window.swish)return window.swish;let e=tn(n),t=new Ht(e);return window.swish=t,document.dispatchEvent(new Event("swish-ready")),t.api.initAuth().then(()=>{typeof window.Shopify?.analytics?.publish=="function"&&window.Shopify.analytics.publish("swish-ready",{market:e.storefrontContext.localization.market,country:e.storefrontContext.localization.country,language:e.storefrontContext.localization.language,rootUrl:e.storefrontContext.routes.rootUrl})}),t},"createSwish"),Ht=class{constructor(e){this.dom={createElementLocator:ce,createQueryParamsObserver:ae};this.state={itemContext:cn(this),itemState:pn(this),itemCount:dn(this),swishQuery:fn(this),effect:H,signal:T,computed:G};this.swishOptions=e,this.events=new ye,this.swishBadges=new st({getBadges:this.swishOptions.badges?.getBadges}),this.swishApiPublisher=new nt(this.events);let t=[Fe,e.swishUi?.version].join("-");this.swishApi=new tt({...this.swishOptions.swishApi,responseInterceptor:this.swishApiPublisher.processFetchResponse},this.swishOptions.storefrontContext,this.events,t),this.ajaxApiPublisher=new me(this.events),this.ajaxApi=new he({storeDomain:this.swishOptions.storefrontApi.storeDomain,responseInterceptor:this.ajaxApiPublisher.processFetchResponse}),this.ajaxApi.patchFetch(),this.storefrontApi=new Ye(this.swishOptions.storefrontApi,this.swishOptions.storefrontContext,this.swishBadges,this.swishOptions.metafields),this.swishUi=new rt(this.swishOptions.swishUi,this.swishOptions.storefrontContext),this.events.subscribe(["cart-add","cart-update","cart-change","cart-clear"],()=>{this.ajaxApi.clearCache()}),customElements.get("swish-ui")||customElements.define("swish-ui",it),this.intents=new Ge(this,this.swishUi)}static{s(this,"SwishApp")}get options(){return this.swishOptions}get storefrontContext(){return this.swishOptions.storefrontContext}get badges(){return this.swishBadges}get api(){return this.swishApi}get storefront(){return this.storefrontApi}get ajax(){return this.ajaxApi}get shopUrl(){return`https://${this.swishOptions.storefrontApi.storeDomain}`}};export{Fe as VERSION,cp as createSwish,lp as swishSdkUrl};
|