{"version":3,"sources":["webpack:///./cartridges/app_harmony/cartridge/client/default/js/widgets/product/HarmonyProductImages.js"],"names":["IMAGE_MODE_ZOOM","ProductImages","HarmonyProductImages","getOriginalImageSize","element","Promise","resolve","resultSize","src","dataset","originalSrc","h","prefs","predefinedHeight","w","predefinedWidth","img","Image","addEventListener","height","width","initAndShowZoom","PhotoSwipe","PhotoSwipeUI","originalImagesSize","pswpElement","document","querySelectorAll","imgCarousel","getById","carousel","thumbnailsCarousel","thumbnails","options","index","getCurrentPageIndex","loop","zoomLoop","history","clickToCloseNonZoomable","zoomClickToCloseNonZoomable","closeElClasses","zoomCloseElClasses","split","closeOnScroll","showHideOpacity","gallery","listen","onZoomClosed","currentPage","getCurrentIndex","scrollToPage","markCurrentPage","scrollIntoView","init","imageMode","toggleZoomState","addGlobalDialogClass","addFocusTrap","update","loadPhotoswipeDependencies","carouselImages","all","Array","from","map","zoom","getImages","then","default","eventBus","emit","imagePosition","currentActiveSlideIndex","imageName","slides","querySelector","alt","closeZoom","renderImages","product","images","large","forEach","zoomImage","zoomImages","zoomUrl","url","isFirst","pagination","length","fill","_el","i","page","pageIndex","render","legendBadgeHtml","ratingBadgeShortHtml","ref"],"mappings":";;;;;;;;;;;;;;AAAA,MAAMA,eAAe,GAAG,MAAxB;AAEA;;;;;;AAKe,yEAAUC,aAAV,EAAyB;AACpC,SAAO,MAAMC,oBAAN,SAAmCD,aAAnC,CAAiD;AACpDE,wBAAoB,CAACC,OAAD,EAAU;AAC1B,aAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC5B,cAAMC,UAAU,GAAG;AACfC,aAAG,EAAEJ,OAAO,CAACK,OAAR,CAAgBC,WADN;AAEfC,WAAC,EAAE,KAAKC,KAAL,GAAaC,gBAFD;AAGfC,WAAC,EAAE,KAAKF,KAAL,GAAaG;AAHD,SAAnB;AAKA,cAAMC,GAAG,GAAG,IAAIC,KAAJ,EAAZ;AAEAD,WAAG,CAACE,gBAAJ,CAAqB,MAArB,EA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CAAR;AAAWE,iBAAS,EAAEF,CAAC,GAAG;AAA1B,OAAb,CAAnD,CADa,GAEb,EAFN;AAIA,WAAKG,MAAL,CAAY,iBAAZ,EAA+B;AAC3Bf,cAAM,EAAED,OAAO,CAACC,MADW;AAE3BgB,uBAAe,EAAEjB,OAAO,CAACiB,eAFE;AAG3BC,4BAAoB,EAAElB,OAAO,CAACkB,oBAHH;AAI3BT;AAJ2B,OAA/B,EAKG,KAAKU,GAAL,CAAS,eAAT,CALH,EAK8B/B,IAL9B,CAKmC,MAAM;AACrC,aAAKT,MAAL;AACH,OAPD;AAQH;;AAxHmD,GAAxD;AA0HH,C","file":"3.bundle.js","sourcesContent":["const IMAGE_MODE_ZOOM = 'zoom';\n\n/**\n * @description HarmonyProductImages implementation\n * @param {ProductImages} ProductImages widget for extending\n * @returns {typeof HarmonyProductImages}\n */\nexport default function (ProductImages) {\n return class HarmonyProductImages extends ProductImages {\n getOriginalImageSize(element) {\n return new Promise((resolve) => {\n const resultSize = {\n src: element.dataset.originalSrc,\n h: this.prefs().predefinedHeight,\n w: this.prefs().predefinedWidth\n };\n const img = new Image();\n\n img.addEventListener('load', () => {\n resultSize.h = img.height;\n resultSize.w = img.width;\n resolve(resultSize);\n });\n img.addEventListener('error', () => resolve(resultSize));\n img.src = element.dataset.originalSrc;\n });\n }\n\n initAndShowZoom(PhotoSwipe, PhotoSwipeUI, originalImagesSize) {\n const pswpElement = document.querySelectorAll('.pswp')[0];\n const imgCarousel = this.getById('imagesCarousel', (/** @type {carousel} */ carousel) => carousel);\n const thumbnailsCarousel = this.getById('imagesThumbnails', (/** @type {carousel} */ thumbnails) => thumbnails);\n const prefs = this.prefs();\n const options = {\n index: imgCarousel.getCurrentPageIndex(),\n loop: prefs.zoomLoop,\n history: false,\n clickToCloseNonZoomable: prefs.zoomClickToCloseNonZoomable,\n closeElClasses: prefs.zoomCloseElClasses.split(','),\n closeOnScroll: prefs.closeOnScroll,\n showHideOpacity: prefs.showHideOpacity\n };\n const gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI, originalImagesSize, options);\n\n gallery.listen('close', () => this.onZoomClosed());\n gallery.listen('beforeChange', () => {\n const currentPage = gallery.getCurrentIndex();\n\n imgCarousel.scrollToPage(currentPage);\n\n if (thumbnailsCarousel) {\n thumbnailsCarousel.markCurrentPage(currentPage).scrollIntoView();\n }\n });\n gallery.init();\n\n this.gallery = gallery;\n this.imageMode = IMAGE_MODE_ZOOM;\n\n if (thumbnailsCarousel) {\n thumbnailsCarousel.toggleZoomState(true);\n }\n\n this.addGlobalDialogClass();\n this.addFocusTrap();\n\n // Update thumbnails carousel metrics/pagination\n thumbnailsCarousel.update();\n }\n\n loadPhotoswipeDependencies(carouselImages) {\n return Promise.all([\n import(/* webpackChunkName: 'photoswipe' */'photoswipe'),\n import(/* webpackChunkName: 'photoswipe' */'photoswipe/dist/photoswipe-ui-default.js'),\n Promise.all(Array.from(carouselImages).map(element => this.getOriginalImageSize(element)))\n ]);\n }\n\n zoom() {\n const imgCarousel = this.getById('imagesCarousel', carousel => carousel);\n const carouselImages = imgCarousel && imgCarousel.getImages();\n\n if (!carouselImages) {\n return;\n }\n\n this.loadPhotoswipeDependencies(carouselImages).then(([PhotoSwipe, PhotoSwipeUI, originalImagesSize]) => {\n this.initAndShowZoom(PhotoSwipe.default, PhotoSwipeUI.default, originalImagesSize);\n });\n\n this.eventBus().emit('gtm.pdp.zoom.click', {\n imagePosition: imgCarousel.currentActiveSlideIndex,\n imageName: imgCarousel.slides[imgCarousel.currentActiveSlideIndex].querySelector('img').alt || ''\n });\n }\n\n closeZoom() {\n super.closeZoom();\n\n this.getById('imagesThumbnails', thumbnails => {\n // Update thumbnails carousel metrics/pagination\n thumbnails.update();\n });\n }\n\n renderImages(product) {\n if (!product || !product.images || !product.images.large) {\n return;\n }\n\n product.images.large.forEach((element, index) => {\n const zoomImage = product.zoomImages.zoom && product.zoomImages.zoom[element.index];\n element.zoomUrl = zoomImage && zoomImage.url;\n element.isFirst = index === 0;\n });\n\n const pagination = product.images.large.length > 1\n ? new Array(product.images.large.length).fill(0).map((_el, i) => ({ page: i, pageIndex: i + 1 }))\n : [];\n\n this.render('galleryTemplate', {\n images: product.images,\n legendBadgeHtml: product.legendBadgeHtml,\n ratingBadgeShortHtml: product.ratingBadgeShortHtml,\n pagination\n }, this.ref('carouselInner')).then(() => {\n this.update();\n });\n }\n };\n}\n"],"sourceRoot":""}