{"version":3,"sources":["node_modules/browser-pack/_prelude.js","node_modules/chocolat/dist/js/chocolat.cjs.js","wp-content/themes/jcore2/js/wp-gallery.lightbox.js"],"names":[],"mappings":"AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACjsBA;;;;AAEA,QAAQ,CAAC,gBAAT,CAA0B,kBAA1B,EAA8C,YAAY;AACxD,MAAM,SAAS,GAAG,QAAQ,CAAC,gBAAT,CAA0B,mCAA1B,CAAlB;AACA,MAAM,UAAU,GAAG,EAAnB;AACA,MA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,EAnC6C;AAoCpD,UAAM,IAAI,GAAG,YAAY,CAAC,EAAD,CAAzB;AACA,MAAA,IAAI,CAAC,gBAAL,CAAsB,OAAtB,EAA+B;AAAA,eAAM,eAAe,CAAC,IAAhB,CAAqB,EAArB,CAAN;AAAA,OAA/B;AArCoD;;AAmCtD,SAAK,IAAI,EAAC,GAAG,CAAb,EAAgB,EAAC,GAAG,YAAY,CAAC,MAAjC,EAAyC,EAAC,EAA1C,EAA8C;AAAA,aAArC,EAAqC;AAG7C;AAtCqD;;AAMxD,OAAK,IAAI,CAAC,GAAG,CAAb,EAAgB,CAAC,GAAG,SAAS,CAAC,MAA9B,EAAsC,CAAC,EAAvC,EAA2C;AAAA,UAAlC,CAAkC;AAiC1C;AACF,CAxCD;;AA0CA,SAAS,WAAT,CAAqB,GAArB,EAA0B;AACxB,MAAI;AACF,WAAO,IAAI,GAAJ,CAAQ,GAAR,EAAa,QAApB;AACD,GAFD,CAEE,OAAO,CAAP,EAAU;AACV,WAAO,GAAP;AACD;AACF","file":"wp-gallery.lightbox.js","sourcesContent":["(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=\"function\"==typeof require&&require,i=0;i {\n const handleTransitionEnd = () => {\n el.removeEventListener('transitionend', handleTransitionEnd);\n resolve();\n };\n\n el.addEventListener('transitionend', handleTransitionEnd);\n const classesBefore = el.getAttribute('class');\n const stylesBefore = el.getAttribute('style');\n triggeringFunc();\n\n if (classesBefore === el.getAttribute('class') && stylesBefore === el.getAttribute('style')) {\n handleTransitionEnd();\n }\n\n if (parseFloat(getComputedStyle(el)['transitionDuration']) === 0) {\n handleTransitionEnd();\n }\n });\n}\nfunction loadImage({\n src,\n srcset,\n sizes\n}) {\n const image = new Image();\n image.src = src;\n\n if (srcset) {\n image.srcset = srcset;\n }\n\n if (sizes) {\n image.sizes = sizes;\n }\n\n if ('decode' in image) {\n return new Promise((resolve, reject) => {\n image.decode().then(() => {\n resolve(image);\n }).catch(() => {\n reject(image);\n });\n });\n } else {\n return new Promise((resolve, reject) => {\n image.onload = resolve(image);\n image.onerror = reject(image);\n });\n }\n}\nfunction fit(options) {\n let height;\n let width;\n const {\n imgHeight,\n imgWidth,\n containerHeight,\n containerWidth,\n canvasWidth,\n canvasHeight,\n imageSize\n } = options;\n const canvasRatio = canvasHeight / canvasWidth;\n const containerRatio = containerHeight / containerWidth;\n const imgRatio = imgHeight / imgWidth;\n\n if (imageSize == 'cover') {\n if (imgRatio < containerRatio) {\n height = containerHeight;\n width = height / imgRatio;\n } else {\n width = containerWidth;\n height = width * imgRatio;\n }\n } else if (imageSize == 'native') {\n height = imgHeight;\n width = imgWidth;\n } else {\n if (imgRatio > canvasRatio) {\n height = canvasHeight;\n width = height / imgRatio;\n } else {\n width = canvasWidth;\n height = width * imgRatio;\n }\n\n if (imageSize === 'scale-down' && (width >= imgWidth || height >= imgHeight)) {\n width = imgWidth;\n height = imgHeight;\n }\n }\n\n return {\n height: height,\n width: width\n };\n}\nfunction openFullScreen(wrapper) {\n if (wrapper.requestFullscreen) {\n return wrapper.requestFullscreen();\n } else if (wrapper.webkitRequestFullscreen) {\n return wrapper.webkitRequestFullscreen();\n } else if (wrapper.msRequestFullscreen) {\n return wrapper.msRequestFullscreen();\n } else {\n return Promise.reject();\n }\n}\nfunction exitFullScreen() {\n if (document.exitFullscreen) {\n return document.exitFullscreen();\n } else if (document.webkitExitFullscreen) {\n return document.webkitExitFullscreen();\n } else if (document.msExitFullscreen) {\n return document.msExitFullscreen();\n } else {\n return Promise.reject();\n }\n}\n\nconst defaults = {\n container: document.body,\n // window or element\n className: undefined,\n imageSize: 'scale-down',\n // 'scale-down', 'contain', 'cover' or 'native'\n fullScreen: false,\n loop: false,\n linkImages: true,\n setIndex: 0,\n firstImageIndex: 0,\n lastImageIndex: false,\n currentImageIndex: undefined,\n allowZoom: true,\n closeOnBackgroundClick: true,\n setTitle: function () {\n return '';\n },\n description: function () {\n return this.images[this.settings.currentImageIndex].title;\n },\n pagination: function () {\n const last = this.settings.lastImageIndex + 1;\n const position = this.settings.currentImageIndex + 1;\n return position + '/' + last;\n },\n\n afterInitialize() {},\n\n afterMarkup() {},\n\n afterImageLoad() {},\n\n afterClose() {},\n\n zoomedPaddingX: function (canvasWidth, imgWidth) {\n return 0;\n },\n zoomedPaddingY: function (canvasHeight, imgHeight) {\n return 0;\n }\n};\nclass Chocolat {\n constructor(elements, settings) {\n this.settings = settings;\n this.elems = {};\n this.images = [];\n this.events = [];\n this.state = {\n fullScreenOpen: false,\n initialZoomState: null,\n initialized: false,\n timer: false,\n visible: false\n };\n this._cssClasses = ['chocolat-open', 'chocolat-in-container', 'chocolat-cover', 'chocolat-zoomable', 'chocolat-zoomed', 'chocolat-zooming-in', 'chocolat-zooming-out'];\n\n if (NodeList.prototype.isPrototypeOf(elements) || HTMLCollection.prototype.isPrototypeOf(elements)) {\n elements.forEach((el, i) => {\n this.images.push({\n title: el.getAttribute('title'),\n src: el.getAttribute('href'),\n srcset: el.getAttribute('data-srcset'),\n sizes: el.getAttribute('data-sizes')\n });\n this.off(el, 'click.chocolat');\n this.on(el, 'click.chocolat', e => {\n this.init(i);\n e.preventDefault();\n });\n });\n } else {\n this.images = elements;\n }\n\n if (this.settings.container instanceof Element || this.settings.container instanceof HTMLElement) {\n this.elems.container = this.settings.container;\n } else {\n this.elems.container = document.body;\n }\n\n this.api = {\n open: i => {\n i = parseInt(i) || 0;\n return this.init(i);\n },\n close: () => {\n return this.close();\n },\n next: () => {\n return this.change(1);\n },\n prev: () => {\n return this.change(-1);\n },\n goto: i => {\n return this.open(i);\n },\n current: () => {\n return this.settings.currentImageIndex;\n },\n position: () => {\n return this.position(this.elems.img);\n },\n destroy: () => {\n return this.destroy();\n },\n set: (property, value) => {\n this.settings[property] = value;\n return value;\n },\n get: property => {\n return this.settings[property];\n },\n getElem: name => {\n return this.elems[name];\n }\n };\n }\n\n init(i) {\n if (!this.state.initialized) {\n this.markup();\n this.attachListeners();\n this.settings.lastImageIndex = this.images.length - 1;\n this.state.initialized = true;\n }\n\n this.settings.afterInitialize.call(this);\n return this.load(i);\n }\n\n load(index) {\n if (!this.state.visible) {\n this.state.visible = true;\n setTimeout(() => {\n this.elems.overlay.classList.add('chocolat-visible');\n this.elems.wrapper.classList.add('chocolat-visible');\n }, 0);\n this.elems.container.classList.add('chocolat-open');\n }\n\n if (this.settings.fullScreen) {\n openFullScreen(this.elems.wrapper);\n }\n\n if (this.settings.currentImageIndex === index) {\n return Promise.resolve();\n }\n\n let loaderTimer = setTimeout(() => {\n this.elems.loader.classList.add('chocolat-visible');\n }, 1000);\n let fadeOutPromise;\n let image;\n let fadeOutTimer = setTimeout(() => {\n fadeOutTimer = undefined;\n fadeOutPromise = transitionAsPromise(() => {\n this.elems.imageCanvas.classList.remove('chocolat-visible');\n }, this.elems.imageCanvas);\n }, 80);\n return loadImage(this.images[index]).then(loadedImage => {\n image = loadedImage;\n\n if (fadeOutTimer) {\n clearTimeout(fadeOutTimer);\n return Promise.resolve();\n } else {\n return fadeOutPromise;\n }\n }).then(() => {\n const nextIndex = index + 1;\n\n if (this.images[nextIndex] != undefined) {\n loadImage(this.images[nextIndex]);\n }\n\n this.settings.currentImageIndex = index;\n this.elems.description.textContent = this.settings.description.call(this);\n this.elems.pagination.textContent = this.settings.pagination.call(this);\n this.arrows();\n return this.position(image).then(() => {\n this.elems.loader.classList.remove('chocolat-visible');\n clearTimeout(loaderTimer);\n return this.appear(image);\n });\n }).then(() => {\n this.elems.container.classList.toggle('chocolat-zoomable', this.zoomable(image, this.elems.wrapper));\n this.settings.afterImageLoad.call(this);\n });\n }\n\n position({\n naturalHeight,\n naturalWidth\n }) {\n const fitOptions = {\n imgHeight: naturalHeight,\n imgWidth: naturalWidth,\n containerHeight: this.elems.container.clientHeight,\n containerWidth: this.elems.container.clientWidth,\n canvasWidth: this.elems.imageCanvas.clientWidth,\n canvasHeight: this.elems.imageCanvas.clientHeight,\n imageSize: this.settings.imageSize\n };\n const {\n width,\n height\n } = fit(fitOptions);\n return transitionAsPromise(() => {\n Object.assign(this.elems.imageWrapper.style, {\n width: width + 'px',\n height: height + 'px'\n });\n }, this.elems.imageWrapper);\n }\n\n appear(image) {\n this.elems.imageWrapper.removeChild(this.elems.img);\n this.elems.img = image;\n this.elems.img.setAttribute('class', 'chocolat-img');\n this.elems.imageWrapper.appendChild(this.elems.img);\n const fadeInPromise = transitionAsPromise(() => {\n this.elems.imageCanvas.classList.add('chocolat-visible');\n }, this.elems.imageCanvas);\n return fadeInPromise;\n }\n\n change(step) {\n if (!this.state.visible) {\n return;\n }\n\n if (!this.settings.linkImages) {\n return;\n }\n\n this.zoomOut();\n const requestedImage = this.settings.currentImageIndex + parseInt(step);\n\n if (requestedImage > this.settings.lastImageIndex) {\n if (this.settings.loop) {\n return this.load(this.settings.firstImageIndex);\n }\n } else if (requestedImage < this.settings.firstImageIndex) {\n if (this.settings.loop) {\n return this.load(this.settings.lastImageIndex);\n }\n } else {\n return this.load(requestedImage);\n }\n }\n\n arrows() {\n if (this.settings.loop) {\n this.elems.left.classList.add('active');\n this.elems.right.classList.add('active');\n } else if (this.settings.linkImages) {\n this.elems.right.classList.toggle('active', this.settings.currentImageIndex !== this.settings.lastImageIndex);\n this.elems.left.classList.toggle('active', this.settings.currentImageIndex !== this.settings.firstImageIndex);\n } else {\n this.elems.left.classList.remove('active');\n this.elems.right.classList.remove('active');\n }\n }\n\n close() {\n if (this.state.fullScreenOpen) {\n exitFullScreen();\n return;\n }\n\n this.state.visible = false;\n const promiseOverlay = transitionAsPromise(() => {\n this.elems.overlay.classList.remove('chocolat-visible');\n }, this.elems.overlay);\n const promiseWrapper = transitionAsPromise(() => {\n this.elems.wrapper.classList.remove('chocolat-visible');\n }, this.elems.wrapper);\n return Promise.all([promiseOverlay, promiseWrapper]).then(() => {\n this.elems.container.classList.remove('chocolat-open');\n this.settings.afterClose.call(this);\n });\n }\n\n destroy() {\n for (let i = this.events.length - 1; i >= 0; i--) {\n const {\n element,\n eventName\n } = this.events[i];\n this.off(element, eventName);\n }\n\n if (!this.state.initialized) {\n return;\n }\n\n if (this.state.fullScreenOpen) {\n exitFullScreen();\n }\n\n this.settings.currentImageIndex = undefined;\n this.state.visible = false;\n this.state.initialized = false;\n this.elems.container.classList.remove(...this._cssClasses);\n this.elems.wrapper.parentNode.removeChild(this.elems.wrapper);\n }\n\n markup() {\n this.elems.container.classList.add('chocolat-open', this.settings.className);\n\n if (this.settings.imageSize == 'cover') {\n this.elems.container.classList.add('chocolat-cover');\n }\n\n if (this.elems.container !== document.body) {\n this.elems.container.classList.add('chocolat-in-container');\n }\n\n this.elems.wrapper = document.createElement('div');\n this.elems.wrapper.setAttribute('id', 'chocolat-content-' + this.settings.setIndex);\n this.elems.wrapper.setAttribute('class', 'chocolat-wrapper');\n this.elems.container.appendChild(this.elems.wrapper);\n this.elems.overlay = document.createElement('div');\n this.elems.overlay.setAttribute('class', 'chocolat-overlay');\n this.elems.wrapper.appendChild(this.elems.overlay);\n this.elems.loader = document.createElement('div');\n this.elems.loader.setAttribute('class', 'chocolat-loader');\n this.elems.wrapper.appendChild(this.elems.loader);\n this.elems.layout = document.createElement('div');\n this.elems.layout.setAttribute('class', 'chocolat-layout');\n this.elems.wrapper.appendChild(this.elems.layout);\n this.elems.top = document.createElement('div');\n this.elems.top.setAttribute('class', 'chocolat-top');\n this.elems.layout.appendChild(this.elems.top);\n this.elems.center = document.createElement('div');\n this.elems.center.setAttribute('class', 'chocolat-center');\n this.elems.layout.appendChild(this.elems.center);\n this.elems.left = document.createElement('div');\n this.elems.left.setAttribute('class', 'chocolat-left');\n this.elems.center.appendChild(this.elems.left);\n this.elems.imageCanvas = document.createElement('div');\n this.elems.imageCanvas.setAttribute('class', 'chocolat-image-canvas');\n this.elems.center.appendChild(this.elems.imageCanvas);\n this.elems.imageWrapper = document.createElement('div');\n this.elems.imageWrapper.setAttribute('class', 'chocolat-image-wrapper');\n this.elems.imageCanvas.appendChild(this.elems.imageWrapper);\n this.elems.img = document.createElement('img');\n this.elems.img.setAttribute('class', 'chocolat-img');\n this.elems.imageWrapper.appendChild(this.elems.img);\n this.elems.right = document.createElement('div');\n this.elems.right.setAttribute('class', 'chocolat-right');\n this.elems.center.appendChild(this.elems.right);\n this.elems.bottom = document.createElement('div');\n this.elems.bottom.setAttribute('class', 'chocolat-bottom');\n this.elems.layout.appendChild(this.elems.bottom);\n this.elems.close = document.createElement('span');\n this.elems.close.setAttribute('class', 'chocolat-close');\n this.elems.top.appendChild(this.elems.close);\n this.elems.description = document.createElement('span');\n this.elems.description.setAttribute('class', 'chocolat-description');\n this.elems.bottom.appendChild(this.elems.description);\n this.elems.pagination = document.createElement('span');\n this.elems.pagination.setAttribute('class', 'chocolat-pagination');\n this.elems.bottom.appendChild(this.elems.pagination);\n this.elems.setTitle = document.createElement('span');\n this.elems.setTitle.setAttribute('class', 'chocolat-set-title');\n this.elems.setTitle.textContent = this.settings.setTitle();\n this.elems.bottom.appendChild(this.elems.setTitle);\n this.elems.fullscreen = document.createElement('span');\n this.elems.fullscreen.setAttribute('class', 'chocolat-fullscreen');\n this.elems.bottom.appendChild(this.elems.fullscreen);\n this.settings.afterMarkup.call(this);\n }\n\n attachListeners() {\n this.off(document, 'keydown.chocolat');\n this.on(document, 'keydown.chocolat', e => {\n if (this.state.initialized) {\n if (e.keyCode == 37) {\n this.change(-1);\n } else if (e.keyCode == 39) {\n this.change(1);\n } else if (e.keyCode == 27) {\n this.close();\n }\n }\n });\n const right = this.elems.wrapper.querySelector('.chocolat-right');\n this.off(right, 'click.chocolat');\n this.on(right, 'click.chocolat', () => {\n this.change(+1);\n });\n const left = this.elems.wrapper.querySelector('.chocolat-left');\n this.off(left, 'click.chocolat');\n this.on(left, 'click.chocolat', () => {\n this.change(-1);\n });\n this.off(this.elems.close, 'click.chocolat');\n this.on(this.elems.close, 'click.chocolat', this.close.bind(this));\n this.off(this.elems.fullscreen, 'click.chocolat');\n this.on(this.elems.fullscreen, 'click.chocolat', () => {\n if (this.state.fullScreenOpen) {\n exitFullScreen();\n return;\n }\n\n openFullScreen(this.elems.wrapper);\n });\n this.off(document, 'fullscreenchange.chocolat');\n this.on(document, 'fullscreenchange.chocolat', () => {\n if (document.fullscreenElement || document.webkitCurrentFullScreenElement || document.webkitFullscreenElement) {\n this.state.fullScreenOpen = true;\n } else {\n this.state.fullScreenOpen = false;\n }\n });\n this.off(document, 'webkitfullscreenchange.chocolat');\n this.on(document, 'webkitfullscreenchange.chocolat', () => {\n if (document.fullscreenElement || document.webkitCurrentFullScreenElement || document.webkitFullscreenElement) {\n this.state.fullScreenOpen = true;\n } else {\n this.state.fullScreenOpen = false;\n }\n });\n\n if (this.settings.closeOnBackgroundClick) {\n this.off(this.elems.overlay, 'click.chocolat');\n this.on(this.elems.overlay, 'click.chocolat', this.close.bind(this));\n }\n\n this.off(this.elems.wrapper, 'click.chocolat');\n this.on(this.elems.wrapper, 'click.chocolat', () => {\n if (this.state.initialZoomState === null || !this.state.visible) {\n return;\n }\n\n this.elems.container.classList.add('chocolat-zooming-out');\n this.zoomOut().then(() => {\n this.elems.container.classList.remove('chocolat-zoomed');\n this.elems.container.classList.remove('chocolat-zooming-out');\n });\n });\n this.off(this.elems.imageWrapper, 'click.chocolat');\n this.on(this.elems.imageWrapper, 'click.chocolat', e => {\n if (this.state.initialZoomState === null && this.elems.container.classList.contains('chocolat-zoomable')) {\n e.stopPropagation();\n this.elems.container.classList.add('chocolat-zooming-in');\n this.zoomIn(e).then(() => {\n this.elems.container.classList.add('chocolat-zoomed');\n this.elems.container.classList.remove('chocolat-zooming-in');\n });\n }\n });\n this.on(this.elems.wrapper, 'mousemove.chocolat', e => {\n if (this.state.initialZoomState === null || !this.state.visible) {\n return;\n }\n\n const rect = this.elems.wrapper.getBoundingClientRect();\n const pos = {\n top: rect.top + window.scrollY,\n left: rect.left + window.scrollX\n };\n const height = this.elems.wrapper.clientHeight;\n const width = this.elems.wrapper.clientWidth;\n const imgWidth = this.elems.img.width;\n const imgHeight = this.elems.img.height;\n const coord = [e.pageX - width / 2 - pos.left, e.pageY - height / 2 - pos.top];\n let mvtX = 0;\n\n if (imgWidth > width) {\n const paddingX = this.settings.zoomedPaddingX(imgWidth, width);\n mvtX = coord[0] / (width / 2);\n mvtX = ((imgWidth - width) / 2 + paddingX) * mvtX;\n }\n\n let mvtY = 0;\n\n if (imgHeight > height) {\n const paddingY = this.settings.zoomedPaddingY(imgHeight, height);\n mvtY = coord[1] / (height / 2);\n mvtY = ((imgHeight - height) / 2 + paddingY) * mvtY;\n }\n\n this.elems.img.style.marginLeft = -mvtX + 'px';\n this.elems.img.style.marginTop = -mvtY + 'px';\n });\n this.on(window, 'resize.chocolat', e => {\n if (!this.state.initialized || !this.state.visible) {\n return;\n }\n\n debounce(50, () => {\n const fitOptions = {\n imgHeight: this.elems.img.naturalHeight,\n imgWidth: this.elems.img.naturalWidth,\n containerHeight: this.elems.wrapper.clientHeight,\n containerWidth: this.elems.wrapper.clientWidth,\n canvasWidth: this.elems.imageCanvas.clientWidth,\n canvasHeight: this.elems.imageCanvas.clientHeight,\n imageSize: this.settings.imageSize\n };\n const {\n width,\n height\n } = fit(fitOptions);\n this.position(this.elems.img).then(() => {\n this.elems.container.classList.toggle('chocolat-zoomable', this.zoomable(this.elems.img, this.elems.wrapper));\n });\n });\n });\n }\n\n zoomable(image, wrapper) {\n const wrapperWidth = wrapper.clientWidth;\n const wrapperHeight = wrapper.clientHeight;\n const isImageZoomable = this.settings.allowZoom && (image.naturalWidth > wrapperWidth || image.naturalHeight > wrapperHeight) ? true : false;\n const isImageStretched = image.clientWidth > image.naturalWidth || image.clientHeight > image.naturalHeight;\n return isImageZoomable && !isImageStretched;\n }\n\n zoomIn(e) {\n this.state.initialZoomState = this.settings.imageSize;\n this.settings.imageSize = 'native';\n return this.position(this.elems.img);\n }\n\n zoomOut(e) {\n this.settings.imageSize = this.state.initialZoomState || this.settings.imageSize;\n this.state.initialZoomState = null;\n this.elems.img.style.margin = 0;\n return this.position(this.elems.img);\n }\n\n on(element, eventName, cb) {\n // const eventName = this.settings.setIndex + '-' + eventName\n const length = this.events.push({\n element,\n eventName,\n cb\n });\n element.addEventListener(eventName.split('.')[0], this.events[length - 1].cb);\n }\n\n off(element, eventName) {\n // const eventName = this.settings.setIndex + '-' + eventName\n const index = this.events.findIndex(event => {\n return event.element === element && event.eventName === eventName;\n });\n\n if (this.events[index]) {\n element.removeEventListener(eventName.split('.')[0], this.events[index].cb);\n this.events.splice(index, 1);\n }\n }\n\n}\n\nconst instances = [];\nfunction main_esm (elements, options) {\n const settings = Object.assign({}, defaults, {\n images: []\n }, options, {\n setIndex: instances.length\n });\n const instance = new Chocolat(elements, settings);\n instances.push(instance);\n return instance;\n}\n\nmodule.exports = main_esm;\n","import Chocolat from \"chocolat\";\n\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n const galleries = document.querySelectorAll(\".wp-block-gallery.enable-lightbox\");\n const lightboxes = [];\n let sources;\n\n // We loop through all galleries currently on the page.\n for (let i = 0; i < galleries.length; i++) {\n sources = []; // Setup the source array, which holds all images.\n const gallery = galleries[i];\n\n const galleryItems = gallery.querySelectorAll(\".blocks-gallery-item\");\n\n for (let j = 0; j < galleryItems.length; j++) {\n const item = galleryItems[j];\n const image = item.querySelector(\"figure > img\");\n if (image.sizes && image.srcset) {\n const { sizes, srcset, src } = image;\n sources.push({\n src: extractPath(src),\n sizes: sizes,\n srcset: srcset,\n title: image.alt ? image.alt : \"\",\n });\n } else {\n sources.push({\n src: extractPath(image.src),\n title: image.alt ? image.alt : \"\",\n });\n }\n }\n\n lightboxes.push(new Chocolat(sources)); // We initialize a lightbox.\n\n const currentLightbox = lightboxes[i].api;\n\n for (let j = 0; j < galleryItems.length; j++) {\n const item = galleryItems[j];\n item.addEventListener(\"click\", () => currentLightbox.open(j));\n }\n }\n});\n\nfunction extractPath(url) {\n try {\n return new URL(url).pathname;\n } catch (e) {\n return url;\n }\n}\n"],"preExistingComment":"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvY2hvY29sYXQvZGlzdC9qcy9jaG9jb2xhdC5janMuanMiLCJ3cC1jb250ZW50L3RoZW1lcy9qY29yZTIvanMvd3AtZ2FsbGVyeS5saWdodGJveC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUF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