1import{OverflowList}from"@theme/overflow-list";import VariantPicker from"@theme/variant-picker";import{ProductComponent}from"@theme/view-event-elements";import{debounce,isDesktopBreakpoint,mediaQueryLarge,yieldToMainThread}from"@theme/utilities";import{SlideshowSelectEvent}from"@theme/events";import{morph}from"@theme/morph";import{StandardEvents}from"@shopify/events";export class ProductCardLink extends ProductComponent{get productTransitionEnabled(){return this.getAttribute("data-product-transition")==="true"}get featuredMediaUrl(){return this.getAttribute("data-featured-media-url")}handleViewTransition(event){if(event.defaultPrevented||event.target instanceof Element&&event.target.closest('button, input, label, select, [tabindex="1"]')||!this.productTransitionEnabled)return;const{cardGallery}=this.refs;if(!cardGallery||!cardGallery.hasAttribute("data-view-transition-to-main-product"))return;const{imagesToTransition}=this.refs,activeImage=imagesToTransition?.find(image=>image.closest("slideshow-slide")?.getAttribute("aria-hidden")==="false")||imagesToTransition?.[imagesToTransition.length-1];activeImage instanceof HTMLImageElement&&this.#setImageSrcset(activeImage),cardGallery.setAttribute("data-view-transition-type","product-image-transition"),cardGallery.setAttribute("data-view-transition-triggered","true")}#setImageSrcset(image){if(!this.featuredMediaUrl)return;const currentImageUrl=new URL(image.currentSrc),currentImageRawUrl=currentImageUrl.host+currentImageUrl.pathname;if(!this.featuredMediaUrl.includes(currentImageRawUrl)){const imageFade=image.animate([{opacity:.8},{opacity:1}],{duration:125,easing:"ease-in-out"});imageFade.onfinish=()=>{image.srcset=this.featuredMediaUrl??""}}}}customElements.get("product-card-link")||customElements.define("product-card-link",ProductCardLink);export class ProductCard extends ProductCardLink{requiredRefs=["productCardLink"];get productPageUrl(){const link=this.refs.productCardLink;if(!link.getAttribute("href"))return"";const url=new URL(link.href),variantOverride=this.#getProductPageVariantOverride();return variantOverride?.action==="set"?url.searchParams.set("variant",variantOverride.variantId):variantOverride?.action==="remove"&&url.searchParams.delete("variant"),url.toString()}getSelectedVariantId(){const variantOverride=this.#getProductPageVariantOverride();return variantOverride?.action==="set"?variantOverride.variantId:null}#getProductPageVariantOverride(){const link=this.refs.productCardLink;if(link.getAttribute("href")&&new URL(link.href).searchParams.has("variant"))return null;const variantId=this.#getCheckedVariantId();return variantId===void 0?null:variantId?{action:"set",variantId}:{action:"remove"}}#getCheckedVariantId(){return this.querySelector('input[type="radio"]:checked[data-variant-id]')?.dataset.variantId}getProductCardLink(){return this.refs.productCardLink||null}#fetchProductPageHandler=()=>{this.refs.quickAdd?.fetchProductPage(this.productPageUrl)};#navigateToURL=(event,url)=>{if(event instanceof MouseEvent&&(event.metaKey||event.ctrlKey||event.shiftKey||event.button===1)){event.preventDefault(),window.open(url.href,"_blank");return}else window.location.href=url.href};connectedCallback(){if(super.connectedCallback(),!(this.refs.productCardLink instanceof HTMLAnchorElement))throw new Error("Product card link not found");this.#handleQuickAdd(),this.addEventListener(StandardEvents.productSelect,this.#handleProductSelect),this.addEventListener(SlideshowSelectEvent.eventName,this.#handleSlideshowSelect),mediaQueryLarge.addEventListener("change",this.#handleQuickAdd),this.addEventListener("click",this.navigateToProduct),setTimeout(()=>{this.refs.slideshow?.isNested&&this.#preloadNextPreviewImage()})}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.navigateToProduct)}#preloadNextPreviewImage(){this.refs.slideshow?.slides?.[this.refs.slideshow?.current]?.nextElementSibling?.querySelector('img[loading="lazy"]')?.removeAttribute("loading")}#handleQuickAdd=()=>{this.removeEventListener("pointerenter",this.#fetchProductPageHandler),this.removeEventListener("focusin",this.#fetchProductPageHandler),isDesktopBreakpoint()&&(this.addEventListener("pointerenter",this.#fetchProductPageHandler),this.addEventListener("focusin",this.#fetchProductPageHandler))};#handleProductSelect=event=>{const{optionValueId,variantId,connectedProductUrl}=event.detail??{};optionValueId&&event.target!==this.variantPicker&&this.variantPicker?.updateSelectedOption(optionValueId),typeof variantId=="string"&&this.applyVariantToLinks(variantId,typeof connectedProductUrl=="string"?connectedProductUrl:void 0),event.promise.then(({detail})=>
1{if(!detail?.html)return;const{html}=detail;this.updatePrice(html),this.#isUnavailableVariantSelected(html),this.#updateProductUrl(html,typeof variantId=="string"?variantId:void 0),this.refs.quickAdd?.fetchProductPage(this.productPageUrl),event.target!==this.variantPicker&&this.variantPicker?.updateVariantPicker(html),this.#updateVariantImages(),this.#previousSlideIndex=null,this.removeAttribute("data-no-swatch-selected"),this.#updateOverflowList()}).catch(error=>{error?.name!=="AbortError"&&console.warn("[product-card] Event promise rejected:",error)})};#updateOverflowList(){const overflowList=this.querySelector("swatches-variant-picker-component overflow-list"),isActiveOverflowList=!!overflowList?.querySelector('[slot="overflow"]');!overflowList||!isActiveOverflowList||requestAnimationFrame(()=>{overflowList.dispatchEvent(new CustomEvent("reflow",{bubbles:!0,detail:{}}))})}updatePrice(html){const priceContainer=this.querySelectorAll("product-price [ref='priceContainer']")[1],newPriceElement=html.querySelector("product-price [ref='priceContainer']");newPriceElement&&priceContainer&&morph(priceContainer,newPriceElement)}#updateProductUrl(html,intendedVariantId){const responseProductCard=html.querySelector("product-card"),anchorElement=responseProductCard?.querySelector("a"),featuredMediaUrl=responseProductCard?.getAttribute("data-featured-media-url");if(featuredMediaUrl&&this.setAttribute("data-featured-media-url",featuredMediaUrl),anchorElement instanceof HTMLAnchorElement){if(anchorElement.getAttribute("href")?.trim()==="")return;const responseUrl=new URL(anchorElement.href);this.#updateLinks({pathname:responseUrl.pathname,variantId:intendedVariantId??responseUrl.searchParams.get("variant")})}}applyVariantToLinks(variantId,productUrl){let pathname;if(productUrl)try{pathname=new URL(productUrl,window.location.origin).pathname}catch(error){console.warn("[product-card] Invalid product URL:",productUrl,error);return}this.#updateLinks({pathname,variantId})}#updateLinks({pathname,variantId}){const{productCardLink,productTitleLink,cardGalleryLink}=this.refs;for(const linkEl of[productCardLink,cardGalleryLink,productTitleLink]){if(!(linkEl instanceof HTMLAnchorElement)||!linkEl.href)continue;const url=new URL(linkEl.href);pathname&&(url.pathname=pathname),variantId?url.searchParams.set("variant",variantId):url.searchParams.delete("variant"),linkEl.href=url.toString()}}#isUnavailableVariantSelected(html){const allVariants=html.querySelectorAll("input:checked");for(const variant of allVariants)this.#toggleAddToCartButton(variant.dataset.optionAvailable==="true")}#toggleAddToCartButton(enable){const addToCartButton=this.querySelector(".add-to-cart__button button");addToCartButton instanceof HTMLButtonElement&&(addToCartButton.disabled=!enable)}#updateVariantImages(){const{slideshow}=this.refs;if(!this.variantPicker?.selectedOption)return;const selectedImageId=this.variantPicker?.selectedOption.dataset.optionMediaId;if(slideshow&&selectedImageId){const{slides=[]}=slideshow.refs;for(const slide of slides)slide.getAttribute("variant-image")!=null&&(slide.hidden=slide.getAttribute("slide-id")!==selectedImageId);slideshow.select({id:selectedImageId},void 0,{animate:!1})}}get allVariants(){return this.querySelectorAll("input[data-variant-id]")}get variantPicker(){return this.querySelector("swatches-variant-picker-component")}#previousSlideIndex=null;#handleSlideshowSelect=event=>{event.detail.userInitiated&&(this.#previousSlideIndex=event.detail.index)};previewVariant(id){const{slideshow}=this.refs;slideshow&&(this.resetVariant.cancel(),slideshow.select({id},void 0,{animate:!1}))}previewImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;slideshow&&(this.resetVariant.cancel(),this.#previousSlideIndex!=null&&this.#previousSlideIndex>0?slideshow.select(this.#previousSlideIndex,void 0,{animate:!1}):(slideshow.next(void 0,{animate:!1}),setTimeout(()=>this.#preloadNextPreviewImage())))}resetImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;if(this.variantPicker)this.#resetVariant();
1else{if(!slideshow)return;slideshow.previous(void 0,{animate:!1})}}#resetVariant=()=>{const{slideshow}=this.refs;if(!slideshow)return;if(this.variantPicker?.selectedOption){const id=this.variantPicker.selectedOption.dataset.optionMediaId;if(id){slideshow.select({id},void 0,{animate:!1});return}}const initialSlide=slideshow.initialSlide,slideId=initialSlide?.getAttribute("slide-id");if(initialSlide&&slideshow.slides?.includes(initialSlide)&&slideId){slideshow.select({id:slideId},void 0,{animate:!1});return}slideshow.previous(void 0,{animate:!1})};navigateToProduct=event=>{if(!(event.target instanceof Element)||this.hasAttribute("data-no-navigation")||event.target.closest('button, input, label, select, [tabindex="1"]'))return;const link=this.refs.productCardLink;if(!link.href)return;const linkURL=new URL(link.href),productCardAnchor=link.getAttribute("id");if(!productCardAnchor)return;const infiniteResultsList=this.closest('results-list[infinite-scroll="true"]');if(!window.Shopify.designMode&&infiniteResultsList){const url=new URL(window.location.href),parent=this.closest("li");url.hash=productCardAnchor,parent&&parent.dataset.page&&url.searchParams.set("page",parent.dataset.page),yieldToMainThread().then(()=>{history.replaceState({},"",url.toString())})}event.target.closest("a")||this.#navigateToURL(event,linkURL)};resetVariant=debounce(this.#resetVariant,100)}customElements.get("product-card")||customElements.define("product-card",ProductCard);class SwatchesVariantPickerComponent extends VariantPicker{variantChanged(event){if(!(event.target instanceof HTMLElement))return;const isSwatchInput=event.target instanceof HTMLInputElement&&event.target.name?.includes("-swatch"),clickedSwatch=event.target,hasAvailableVariant=clickedSwatch.dataset.hasAvailableVariant==="true",firstAvailableVariantId=clickedSwatch.dataset.firstAvailableOrFirstVariantId;if(isSwatchInput&&hasAvailableVariant&&firstAvailableVariantId){event.stopPropagation(),this.updateSelectedOption(clickedSwatch);const optionValueId=clickedSwatch.dataset.optionValueId||"",connectedProductUrl=clickedSwatch.dataset.connectedProductUrl||"",requestUrl=this.buildRequestUrl(clickedSwatch,"product-card",[optionValueId]);this.fetchUpdatedSection(requestUrl,{detail:{optionValueId,variantId:firstAvailableVariantId,connectedProductUrl}});return}super.variantChanged(event)}showAllSwatches(event){event?.preventDefault();const{overflowList}=this.refs;overflowList instanceof OverflowList&&overflowList.showAll()}}customElements.get("swatches-variant-picker-component")||customElements.define("swatches-variant-picker-component",SwatchesVariantPickerComponent); 2//# sourceMappingURL=/cdn/shop/t/140/assets/product-card.js.map?v=80689566448612614681788956658
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.