{
  "version": 3,
  "sources": ["/cdn/shop/t/6/assets/paginated-list-aspect-ratio.js?cb=20260407-7"],
  "sourcesContent": ["/**\n * A helper class to keep the set aspect ratio in a card gallery element in the theme editor.\n * This applies the aspect ratio to newly loaded product cards even when the setting has changed and is unsaved.\n */\nexport class PaginatedListAspectRatioHelper {\n  /** @type {string | null} */\n  #imageRatioSetting = null;\n\n  /**\n   * Aspect ratio values matching the theme's standardized values\n   * @type {Object.<string, string>}\n   */\n  #ASPECT_RATIOS = {\n    square: '1',\n    portrait: '0.8',\n    landscape: '1.778',\n  };\n\n  /**\n   * @param {Object} options - The options object\n   * @param {HTMLElement} options.templateCard - The template card gallery element to get the image ratio from\n   */\n  constructor({ templateCard }) {\n    if (!Shopify.designMode) return;\n    this.#storeImageRatioSettings(templateCard);\n  }\n\n  /**\n   * Process newly added elements and apply correct aspect ratios\n   */\n  processNewElements() {\n    if (!Shopify.designMode) return;\n    // Wait for the DOM to update\n    requestAnimationFrame(() => {\n      this.#imageRatioSetting === 'adapt' ? this.#fixAdaptiveAspectRatios() : this.#applyFixedAspectRatio();\n    });\n  }\n\n  /**\n   * Store the image ratio from the template card for later use\n   * @param {HTMLElement} templateCard - The template card gallery element to get the image ratio from\n   */\n  #storeImageRatioSettings(templateCard) {\n    this.#imageRatioSetting = templateCard.getAttribute('data-image-ratio');\n  }\n\n  /**\n   * Fix adaptive aspect ratios for newly added cards\n   * For the 'adapt' setting, each product should use its own image's aspect ratio\n   */\n  #fixAdaptiveAspectRatios() {\n    const newCardGalleries = this.#getUnprocessedGalleries();\n    if (!newCardGalleries.length) return;\n\n    const productRatioCache = new Map();\n\n    newCardGalleries.forEach((gallery) => {\n      if (!(gallery instanceof HTMLElement)) return;\n\n      const productId = gallery.getAttribute('data-product-id');\n      if (productId && productRatioCache.has(productId)) {\n        this.#applyAspectRatioToGallery(gallery, productRatioCache.get(productId));\n        return;\n      }\n\n      const img = gallery.querySelector('img');\n      if (!img) {\n        this.#applyAspectRatioToGallery(gallery, '1');\n        return;\n      }\n\n      const loadAndSetRatio = () => {\n        if (!img.naturalWidth || !img.naturalHeight) return;\n\n        const imgRatio = this.#getSafeImageAspectRatio(img.naturalWidth, img.naturalHeight);\n\n        if (productId) {\n          productRatioCache.set(productId, imgRatio);\n        }\n\n        this.#applyAspectRatioToGallery(gallery, imgRatio);\n      };\n\n      if (img.complete) {\n        loadAndSetRatio();\n      } else {\n        img.addEventListener('load', loadAndSetRatio, { once: true });\n      }\n    });\n  }\n\n  /**\n   * Apply a fixed aspect ratio to all card-gallery and media container elements\n   * Only used for non-adaptive modes (square, portrait, landscape)\n   */\n  #applyFixedAspectRatio() {\n    if (!this.#imageRatioSetting) return;\n\n    const aspectRatio = this.#getAspectRatioValue(this.#imageRatioSetting);\n    if (!aspectRatio) return;\n\n    const newCardGalleries = this.#getUnprocessedGalleries();\n    if (!newCardGalleries.length) return;\n\n    // Batch DOM operations for better performance\n    requestAnimationFrame(() => {\n      newCardGalleries.forEach((gallery) => {\n        if (!(gallery instanceof HTMLElement)) return;\n        this.#applyAspectRatioToGallery(gallery, aspectRatio);\n      });\n    });\n  }\n\n  /**\n   * Calculate a safe aspect ratio value from image dimensions\n   * Ensures the ratio stays within reasonable bounds and has consistent decimal places\n   * @param {number} width - Natural width of the image\n   * @param {number} height - Natural height of the image\n   * @returns {string} Normalized aspect ratio as a string\n   */\n  #getSafeImageAspectRatio(width, height) {\n    const rawRatio = width / height;\n    return Math.max(0.1, Math.min(10, rawRatio)).toFixed(3);\n  }\n\n  /**\n   * Get aspect ratio value based on setting\n   * @param {string} ratioSetting - The ratio setting name\n   * @returns {string|null} - The aspect ratio value or null\n   */\n  #getAspectRatioValue(ratioSetting) {\n    return this.#ASPECT_RATIOS[ratioSetting] || null;\n  }\n\n  /**\n   * Apply an aspect ratio to a gallery and all its media containers\n   * @param {HTMLElement} gallery - The gallery element\n   * @param {string} aspectRatio - The aspect ratio to apply\n   */\n  #applyAspectRatioToGallery(gallery, aspectRatio) {\n    if (!(gallery instanceof HTMLElement)) return;\n\n    gallery.style.setProperty('--gallery-aspect-ratio', aspectRatio);\n\n    const mediaContainers = gallery.querySelectorAll('.product-media-container');\n    mediaContainers.forEach((container) => {\n      if (container instanceof HTMLElement) {\n        container.style.aspectRatio = aspectRatio;\n      }\n    });\n\n    this.#markAsProcessed(gallery);\n  }\n\n  /**\n   * Get all unprocessed card galleries\n   * @returns {NodeListOf<Element>} List of unprocessed galleries\n   */\n  #getUnprocessedGalleries() {\n    return document.querySelectorAll('.card-gallery:not([data-aspect-ratio-applied])');\n  }\n\n  /**\n   * Mark gallery as processed\n   * @param {HTMLElement} gallery - The gallery element to mark as processed\n   */\n  #markAsProcessed(gallery) {\n    if (!(gallery instanceof HTMLElement)) return;\n    gallery.setAttribute('data-aspect-ratio-applied', 'true');\n  }\n}\n"],
  "mappings": "AAIO,aAAM,8BAA+B,CAE1C,mBAAqB,KAMrB,eAAiB,CACf,OAAQ,IACR,SAAU,MACV,UAAW,OACb,EAMA,YAAY,CAAE,YAAa,EAAG,CACvB,QAAQ,YACb,KAAK,yBAAyB,YAAY,CAC5C,CAKA,oBAAqB,CACd,QAAQ,YAEb,sBAAsB,IAAM,CAC1B,KAAK,qBAAuB,QAAU,KAAK,yBAAyB,EAAI,KAAK,uBAAuB,CACtG,CAAC,CACH,CAMA,yBAAyB,aAAc,CACrC,KAAK,mBAAqB,aAAa,aAAa,kBAAkB,CACxE,CAMA,0BAA2B,CACzB,MAAM,iBAAmB,KAAK,yBAAyB,EACvD,GAAI,CAAC,iBAAiB,OAAQ,OAE9B,MAAM,kBAAoB,IAAI,IAE9B,iBAAiB,QAAS,SAAY,CACpC,GAAI,EAAE,mBAAmB,aAAc,OAEvC,MAAM,UAAY,QAAQ,aAAa,iBAAiB,EACxD,GAAI,WAAa,kBAAkB,IAAI,SAAS,EAAG,CACjD,KAAK,2BAA2B,QAAS,kBAAkB,IAAI,SAAS,CAAC,EACzE,MACF,CAEA,MAAM,IAAM,QAAQ,cAAc,KAAK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