1import Cart from"cart-store";class CartRecommendations extends HTMLElement{async connectedCallback(){this.sectionId=this.getAttribute("section-id"),this.recommendationsAmount=10,this.recommendations=[],this.sectionTitle=this.querySelector("cart-recommendations-title"),this.container=this.querySelector("[cart-recommendations-content]"),this.itemsScroll=this.querySelector("items-scroll"),this.intent=this.getAttribute("product-recommendations-type"),this.cards=Array.from(this.container.children),this.unsubscribe=Cart.subscribe(((t,e)=>{const i=(t,e)=>t.reduce(((t,i)=>{const r=i.product_id.toString();return e.includes(i.variant_id.toString())||t.includes(r)||t.push(r),t}),[]),r=i(e.cart.items,e.productVariantsBeingAdded),n=i(t.cart.items,t.productVariantsBeingAdded),s=(t,e)=>Object.values(t).reduce(((t,i)=>{const r=i.products.reduce(((r,n,s)=>(t.find((t=>t.item.id===n.id))||e.includes(n.id.toString())||r.push({weight:(s+1)/i.weight,item:n}),r)),[]);return[...t,...r]}),[]).sort(((t,e)=>t.weight-e.weight)).slice(0,this.recommendationsAmount),c=s(t.recommendations.items,n),o=s(e.recommendations.items,r);if(c.map((({item:t})=>t.id)).toString()===o.map((({item:t})=>t.id)).toString())return;this.recommendations=c,this.cards=this.cards.reduce(((t,e)=>{const i=e.getAttribute("product-id");return this.recommendations.find((({item:t})=>t.id.toString()===i))?(t.push(e),t):(e.remove(),t)}),[]);const d=this.cards.map((t=>t.getAttribute("product-id"))),a=[];this.recommendations.forEach((({item:t},e)=>{if(d.includes(t.id.toString())){const i=this.cards.find((e=>e.getAttribute("product-id")===t.id.toString()));d.indexOf(i.getAttribute("product-id"))!==e&&(0===e?this.container.prepend(i):a[e-1].after(i)),a.push(i)}else{const i=this.#t();0===e?this.container.prepend(i):a[e-1].after(i),i.sectionId=this.sectionId,i.product=t,i.id=`cart-recommendation--${t.id}`,a.push(i)}})),this.cards=a,this.itemsScroll&&this.itemsScroll.smoothScrollItems(0),this.recommendations.length>0?this.removeAttribute("hidden"):this.setAttribute("hidden","")})),await Cart.enableCartRecommendations(this.intent)}disconnectedCallback(){this.unsubscribe()}#t(){return document.getElementById(`${this.sectionId}--template-cart-recommendations-card`).content.cloneNode(!0).children[0]}}customElements.define("cart-recommendations",CartRecommendations); 2//# sourceMappingURL=cart-recommendations.js.map
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.