1(async()=>{const{Core}=await importModule("Core"),{Routes,parseHTML}=await importModule("Utils"),CART_R_SECTION="r_cart",NOTIFICATION_SECTION="r_cart-notification",ATTR_IS_CART_PAGE="cart-page",SECTION_DRAWER="g_cart-drawer";customElements.define("cart-provider",class extends Core{subscriptions={"cart:add-feature":"_addFeature","cart:add":"_add","cart:change":"_update"};features={};render(){this.subscribe("cart:add-feature",{global:!0}),this.subscribe("cart:add",{global:!0}),this.subscribe("cart:change",{global:!0})}_addFeature({feature}){this.features[feature]=!0}async _add({items}){try{const resBody={items};this.features.notification&&(resBody.sections=[NOTIFICATION_SECTION],resBody.attributes={notification_items_variant_ids:items.map(({id})=>id).join(",")});const res=await this._requestCart("cartAdd",resBody);if(this._cleanCartAttributes(),this.redirectToCart){window.location.pathname=Routes("cart");return}const cartData=await res.json();if(res.ok)this._publishUpdates(cartData);else throw new Error(JSON.stringify({message:cartData.message,description:cartData.description}))}catch(e){console.error(e);const{message="",description=""}=JSON.parse(e.message);(message||description)&&this.publish("toast-notification:open",{title:message,message:description,type:"error"}),this.publish("cart:error")}}_cleanCartAttributes(){this.features.notification&&this._requestCart("cartUpdate",{attributes:{notification_items_variant_ids:null}})}async _update({key,quantity,selling_plan}){const cartData=await(await this._requestCart("cartChange",{id:key,quantity,selling_plan,sections:[CART_R_SECTION],sections_url:Routes("cart")})).json();this._publishUpdates(cartData)}async _publishUpdates(cartData){const eventData={};if((this.features["cart-total"]||this.features.counter||this.features.drawer)&&(eventData.meta=await this._getCartMeta()),this.features.drawer&&(eventData.drawer={section:await this._getDrawerSection(),open:!this.features.notification}),this.features.notification&&(eventData.notification={section:cartData.sections[NOTIFICATION_SECTION],recommendationProductId:cartData.items[0]?.product_id}),this.features.cart){const $cartDoc=parseHTML(cartData.sections[CART_R_SECTION]);eventData.cart={getCount:()=>$cartDoc.querySelector("[data-cart-counter]").innerText,getItems:()=>
1$cartDoc.querySelector("[data-cart-items]"),getSubtotalBlock:()=>$cartDoc.querySelector("[data-cart-subtotal-block]"),getFreeShippingBlock:()=>$cartDoc.querySelector("[data-cart-free-shipping-block]")}}this.publish("cart:update",eventData)}async _getCartMeta(){const res=await fetch(`${Routes("cart")}?view=meta`),{count,...data}=await res.json();return{count:Number(count),...data}}async _getDrawerSection(){return await(await fetch(`${Routes("root")}?section_id=${SECTION_DRAWER}`)).text()}_requestCart(route,body){return fetch(`${Routes(route)}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(body)})}get isCartPage(){return this.hasAttribute(ATTR_IS_CART_PAGE)}get redirectToCart(){return!this.isCartPage&&!this.features.notification&&!this.features.drawer}})})(); 2//# sourceMappingURL=/cdn/shop/t/34/assets/cart-provider.js.map?v=70892282141505034821721816886
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.