1import{isObject}from"helpers";const SECTIONS_TO_RENDER=[{name:"cart-count",liveRegion:"cart-count"},{name:"shipping-threshold",liveRegion:"shipping-threshold"},{name:"cart",liveRegion:"cart-items"},{name:"cart",liveRegion:"cart-totals"},{name:"cart",liveRegion:"cart-checkout"},{name:"cart",liveRegion:"cart-recommendations"}];function isCart(payload){return Array.isArray(payload?.items)&&typeof payload.item_count=="number"}function cartWithoutSections(cart){if(!cart||typeof cart!="object"||!("sections"in cart))return cart;const rest={...cart};return delete rest.sections,rest}function mergeAddResponse(previousCart,addResponse){const previousItems=previousCart?.items??[],addedItems=Array.isArray(addResponse?.items)?addResponse.items:[addResponse],itemsByKey=new Map(previousItems.map(item=>[item.key,item]));addedItems.forEach(item=>{itemsByKey.set(item.key,item)});const items=[...itemsByKey.values()],itemCount=items.reduce((sum,item)=>sum+item.quantity,0),totalPrice=items.reduce((sum,item)=>{const linePrice=item.final_line_price??item.line_price??(item.final_price??item.price??0)*item.quantity;return sum+linePrice},0);return{...previousCart,items,item_count:itemCount,total_price:totalPrice}}class Cart{#data={items:[]};#ready;#seeded=!1;#mutationQueue=Promise.resolve();constructor(){this.#ready=this.seed()}#enqueue(run){const result=this.#mutationQueue.then(run,run);return this.#mutationQueue=result.then(()=>{},()=>{}),result}get data(){return this.#data}get ready(){return this.#ready}getSectionNames(){return[...new Set(SECTIONS_TO_RENDER.map(section=>section.name))]}sectionUpdates(sections){return sections?SECTIONS_TO_RENDER.flatMap(({liveRegion,name})=>{const html=sections[name];return html?[{liveRegion,html}]:[]}):[]}async#fetchCart(){const response=await fetch(`${WYATT.routes.cart_url}.js`);if(!response.ok)throw new Error(`${response.url} responded with status: ${response.status} ${response.statusText}`);return response.json()}async seed(){const cart=WYATT.shopify?.cart;if(cart&&typeof cart=="object")this.#data=cartWithoutSections({...cart,items:Array.isArray(cart.items)?cart.items:[]});else try{const fetched=await this.#fetchCart();isCart(fetched)&&(this.#data=cartWithoutSections(fetched))}catch(error){window.console.error("Cart: failed to seed from /cart.js",error)}return this.#seeded=!0,WYATT.PubSub.publish(WYATT.PubSub.events.cartReady,this.#data),this.#data}async reseed(){try{const cart=await this.#fetchCart();return this.#commit(cart)}catch(error){window.console.error("Cart: failed to reseed from /cart.js",error);return}}async applyChangeResponse(changeResponse){return this.#commit(changeResponse)??this.reseed()}async update(body,enqueue=!0){if(!isObject(body)){window.console.error("WYATT.Cart.update() requires a plain object body",body);return}const storeAttribute=WYATT?.PreferredStores?.serializeStore?.(),bodyWithStore=body.attributes?.store==null&&storeAttribute?{...body,attributes:{...body.attributes,store:storeAttribute}}:body;if(enqueue)return this.#enqueue(()=>this.update(bodyWithStore,!1));this.#seeded||await this.ready;try{const response=await fetch(`${WYATT.routes.cart_update_url}.js`,{...WYATT.config.fetch.post,body:JSON.stringify(bodyWithStore)});if(!response.ok)throw new Error(`${response.url} responded with status: ${response.status} ${response.statusText}`);return this.applyChangeResponse(await response.json())}catch(error){window.console.error("Cart: failed to update via /cart/update.js",error),await this.reseed();return}}async applyAddResponse(addResponse){let addedItems=null;if(Array.isArray(addResponse?.items)?addedItems=addResponse.items:(addResponse?.key!=null||addResponse?.variant_id!=null)&&(addedItems=[addResponse]),!addedItems)return this.reseed();const nextCart=mergeAddResponse(this.#data,{...addResponse,items:addedItems});return this.#commit({...nextCart,sections:addResponse?.sections})??this.reseed()}#commit(cart){if(isCart(cart))return this.#data=cartWithoutSections(cart),{sections:cart.sections}}}WYATT.Cart=new Cart;export default Cart; 2//# sourceMappingURL=/cdn/shop/t/3/assets/cart.js.map?v=79647037617783598411785855215
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.