1if(!customElements.get("recently-viewed-products")){class RecentlyViewedProducts extends HTMLElement{static STORAGE_KEY="artmie_recently_viewed";static CARD_SECTION_ID="section-recently-viewed-card";constructor(){super(),this.swiperInstance=null}connectedCallback(){this.sectionId=this.dataset.sectionId,this.currentProductHandle=this.dataset.currentProductHandle,this.productsLimit=parseInt(this.dataset.productsLimit||"12"),this.currentProductHandle&&this.trackProduct(this.currentProductHandle);var self=this,go=function(){self.__armieInit||(self.__armieInit=!0,self.__armieIO&&self.__armieIO.disconnect(),self.loadRecentlyViewedProducts())};"IntersectionObserver"in window&&(self.__armieIO=new IntersectionObserver(function(en){for(var i=0;i<en.length;i++)if(en[i].isIntersecting){go();break}},{rootMargin:"600px 0px"}),self.__armieIO.observe(self)),setTimeout(go,2500)}trackProduct(handle){if(handle)try{const stored=localStorage.getItem(RecentlyViewedProducts.STORAGE_KEY);let handles=stored?JSON.parse(stored):[];handles=handles.filter(h=>h!==handle),handles.unshift(handle),handles.length>20&&(handles=handles.slice(0,20)),localStorage.setItem(RecentlyViewedProducts.STORAGE_KEY,JSON.stringify(handles))}catch(e){console.error("Failed to track product:",e)}}getStoredProductHandles(){try{const stored=localStorage.getItem(RecentlyViewedProducts.STORAGE_KEY);return stored?JSON.parse(stored):[]}catch{return[]}}async loadRecentlyViewedProducts(){const storedHandles=this.getStoredProductHandles();if(storedHandles.length===0){this.style.display="none";return}const filteredHandles=this.currentProductHandle?storedHandles.filter(handle=>handle!==this.currentProductHandle):storedHandles;if(filteredHandles.length===0){this.style.display="none";return}const fetchLimit=Math.min(filteredHandles.length,this.productsLimit*2),handlesToLoad=filteredHandles.slice(0,fetchLimit);try{const cardPromises=handlesToLoad.map(handle=>this.fetchProductCard(handle)),productCards=(await Promise.all(cardPromises)).filter(html=>html!==null&&html.trim()!=="").slice(0,this.productsLimit);if(productCards.length===0){this.style.display="none";return}this.renderProducts(productCards),this.style.display="block",setTimeout(()=>this.initSwiper(),100)}catch(error){console.error("Failed to load recently viewed products:",error),this.style.display="none"}}async fetchProductCard(handle){try{const url=`${window.Shopify.routes.root}products/${handle}?section_id=${RecentlyViewedProducts.CARD_SECTION_ID}`,response=await fetch(url);if(!response.ok)return null;const html=await response.text(),slide=new DOMParser().parseFromString(html,"text/html").querySelector(".recently-viewed-section__slide");return slide?slide.innerHTML:null}catch(error){return console.error(`Failed to fetch product card for ${handle}:`,error),null}}renderProducts(productCards){const wrapper=this.querySelector(".swiper-wrapper");wrapper&&(wrapper.innerHTML="",productCards.forEach(cardHtml=>{const slide=document.createElement("div");slide.className="swiper-slide",slide.innerHTML=cardHtml,wrapper.appendChild(slide)}))}initSwiper(){const slider=this.querySelector(".swiper");if(!slider||this.swiperInstance||slider.querySelectorAll(".swiper-slide").length===0)return;if(typeof Swiper>"u"){setTimeout(()=>this.initSwiper(),100);return}const nextButton=this.querySelector(".swiper-button-next"),prevButton=this.querySelector(".swiper-button-prev"),pagination=this.querySelector(".swiper-pagination"),desktopColumns=parseFloat(this.dataset.desktopColumns||"4"),mobileColumns=parseFloat(this.dataset.mobileColumns||"1.2"),gap=parseInt(this.dataset.gap||"24"),gapMobile=parseInt(this.dataset.gapMobile||"16");this.swiperInstance=new Swiper(slider,{slidesPerView:mobileColumns,spaceBetween:gapMobile,loop:!1,navigation:{nextEl:nextButton,prevEl:prevButton},pagination:{el:pagination,clickable:!0,type:"bullets",dynamicBullets:!1},breakpoints:{640:{slidesPerView:Math.min(desktopColumns,2),spaceBetween:gap},768:{slidesPerView:Math.min(desktopColumns,3),spaceBetween:gap},1024:{slidesPerView:desktopColumns,spaceBetween:gap}},on:{init:function(){console.log("Recently Viewed Products Swiper initialized")}}})}disconnectedCallback(){this.swiperInstance&&(this.swiperInstance.destroy(!0,!0),this.swiperInstance=null)}}customElements.define("recently-viewed-products",RecentlyViewedProducts)} 2//# sourceMappingURL=/cdn/shop/t/41/assets/section-recently-viewed-products.js.map?v=183779663286621687861782984729
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.