export class PaginatedListAspectRatioHelper{#imageRatioSetting=null;#ASPECT_RATIOS={square:"1",portrait:"0.8",landscape:"1.778"};constructor({templateCard}){Shopify.designMode&&this.#storeImageRatioSettings(templateCard)}processNewElements(){Shopify.designMode&&requestAnimationFrame(()=>{this.#imageRatioSetting==="adapt"?this.#fixAdaptiveAspectRatios():this.#applyFixedAspectRatio()})}#storeImageRatioSettings(templateCard){this.#imageRatioSetting=templateCard.getAttribute("data-image-ratio")}#fixAdaptiveAspectRatios(){const newCardGalleries=this.#getUnprocessedGalleries();if(!newCardGalleries.length)return;const productRatioCache=new Map;newCardGalleries.forEach(gallery=>{if(!(gallery instanceof HTMLElement))return;const productId=gallery.getAttribute("data-product-id");if(productId&&productRatioCache.has(productId)){this.#applyAspectRatioToGallery(gallery,productRatioCache.get(productId));return}const img=gallery.querySelector("img");if(!img){this.#applyAspectRatioToGallery(gallery,"1");return}const loadAndSetRatio=()=>{if(!img.naturalWidth||!img.naturalHeight)return;const imgRatio=this.#getSafeImageAspectRatio(img.naturalWidth,img.naturalHeight);productId&&productRatioCache.set(productId,imgRatio),this.#applyAspectRatioToGallery(gallery,imgRatio)};img.complete?loadAndSetRatio():img.addEventListener("load",loadAndSetRatio,{once:!0})})}#applyFixedAspectRatio(){if(!this.#imageRatioSetting)return;const aspectRatio=this.#getAspectRatioValue(this.#imageRatioSetting);if(!aspectRatio)return;const newCardGalleries=this.#getUnprocessedGalleries();newCardGalleries.length&&requestAnimationFrame(()=>{newCardGalleries.forEach(gallery=>{gallery instanceof HTMLElement&&this.#applyAspectRatioToGallery(gallery,aspectRatio)})})}#getSafeImageAspectRatio(width,height){const rawRatio=width/height;return Math.max(.1,Math.min(10,rawRatio)).toFixed(3)}#getAspectRatioValue(ratioSetting){return this.#ASPECT_RATIOS[ratioSetting]||null}#applyAspectRatioToGallery(gallery,aspectRatio){if(!(gallery instanceof HTMLElement))return;gallery.style.setProperty("--gallery-aspect-ratio",aspectRatio),gallery.querySelectorAll(".product-media-container").forEach(container=>{container instanceof HTMLElement&&(container.style.aspectRatio=aspectRatio)}),this.#markAsProcessed(gallery)}#getUnprocessedGalleries(){return document.querySelectorAll(".card-gallery:not([data-aspect-ratio-applied])")}#markAsProcessed(gallery){gallery instanceof HTMLElement&&gallery.setAttribute("data-aspect-ratio-applied","true")}}
//# sourceMappingURL=/s/files/1/0677/1399/0759/t/1/assets/paginated-list-aspect-ratio.js.map?v=1783078800
