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AC,YAAY,CAAG,KAEf,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,GAC3B,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,CAAC,KAAK,GAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,GACnB,CAEA,cAAe,CACR,IAAI,CAAC,YAAY,EACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAC9B,CACF,Q,K,O","sources":["<anon>","src/lightbox.js","src/overlay.js","src/config.js","src/shadow.js","src/animation.js"],"sourcesContent":["const $0c04c0cc2b6985d8$var$config = {\n // selects images that load libra.js\n selector: '[data-libra]',\n // margin between viewport and zoomed image\n // in px\n margin: 50,\n // in small screens, it's best to not use margins\n // otherwise, the zoomed image gets even smaller\n // define on screen smaller than what size, margin is set to 0\n zeroMarginBreakpoint: 768,\n // shifts the zoomed image if needed\n offset: {\n x: 0,\n y: 0\n },\n transitionDuration: 200,\n imageCursor: 'zoom-in'\n};\nfunction $0c04c0cc2b6985d8$var$deepMerge(target, source) {\n for(const key in source)if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) {\n if (!target[key]) target[key] = {};\n $0c04c0cc2b6985d8$var$deepMerge(target[key], source[key]);\n } else target[key] = source[key];\n return target;\n}\nfunction $0c04c0cc2b6985d8$export$940a7873bb071df8(newConfig) {\n $0c04c0cc2b6985d8$var$deepMerge($0c04c0cc2b6985d8$var$config, newConfig);\n}\nvar $0c04c0cc2b6985d8$export$2e2bcd8739ae039 = $0c04c0cc2b6985d8$var$config;\n\n\nclass $e49d13fc7942bae1$export$2e2bcd8739ae039 {\n constructor(){\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay', 'libra-hidden');\n // Set transition duration from config\n overlay.style.transitionDuration = (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).transitionDuration + 'ms';\n this.element = overlay;\n document.body.appendChild(overlay);\n return this;\n }\n show() {\n this.element.classList.remove('libra-hidden');\n this.element.classList.add('libra-visible');\n }\n hide() {\n this.element.classList.remove('libra-visible');\n this.element.classList.add('libra-hidden');\n }\n}\n\n\n\nclass $6e8e6c64a3263339$export$2e2bcd8739ae039 {\n static calculateFinalState(element) {\n let finals = {};\n let margin = (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).margin;\n if (window.innerWidth <= (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).zeroMarginBreakpoint) margin = 0;\n const nw = element.naturalWidth;\n const nh = element.naturalHeight;\n const ratio = nw / nh;\n const ww = window.innerWidth - 2 * margin;\n const wh = window.innerHeight - 2 * margin;\n // size image based on width first\n finals.width = nw > ww ? ww : nw;\n finals.height = nw > ww ? ww / ratio : nh;\n // if height is too big, adjust based on height\n if (finals.height > wh) {\n finals.height = wh;\n finals.width = wh * ratio;\n }\n finals.top = (wh - finals.height) / 2 + window.scrollY + margin + (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).offset.y;\n finals.left = (ww - finals.width) / 2 + window.scrollX + margin + (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).offset.x;\n return finals;\n }\n static transformMatrix(element, starts, finals) {\n // Calculate scaling factors based on width and height interpolation\n const scaleX = finals.width / starts.width;\n const scaleY = finals.height / starts.height;\n // Calculate the center of the starting and final positions\n const startCenterX = starts.left + starts.width / 2;\n const startCenterY = starts.top + starts.height / 2;\n const finalCenterX = finals.left + finals.width / 2;\n const finalCenterY = finals.top + finals.height / 2;\n const translateX = finalCenterX - startCenterX;\n const translateY = finalCenterY - startCenterY;\n // Apply the transform with matrix (scale + translate)\n element.style.transform = `matrix(${scaleX}, 0, 0, ${scaleY}, ${translateX}, ${translateY})`;\n }\n static resetTransformMatrix(element) {\n element.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;\n }\n}\n\n\n\nclass $2f427fc7e1c3703f$export$2e2bcd8739ae039 {\n isOpen = false;\n /**\n * ============\n * Constructors\n * ============\n */ constructor(image){\n this.original = image;\n this.fetchOriginalPosition();\n this.create(image);\n return this;\n }\n create(image) {\n // create shadow image\n const shadow = document.createElement('img');\n shadow.src = image.src;\n shadow.id = `libra-shadow-${image.id}`;\n shadow.classList.add('libra-shadow');\n shadow.style.transitionDuration = (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).transitionDuration + 'ms';\n this.element = shadow;\n // set positioning and place shadow element\n this.positionShadow();\n this.placeItself();\n }\n fetchOriginalPosition() {\n const rect = this.original.getBoundingClientRect();\n this.originalPosition = {\n top: rect.top + window.scrollY + (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).offset.y,\n left: rect.left + window.scrollX + (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).offset.x,\n width: rect.width,\n height: rect.height\n };\n }\n positionShadow() {\n this.element.style.top = this.originalPosition.top + 'px';\n this.element.style.left = this.originalPosition.left + 'px';\n this.element.style.width = this.originalPosition.width + 'px';\n this.element.style.height = this.originalPosition.height + 'px';\n }\n /**\n * ============\n * Actions\n * ============\n */ open() {\n this.isOpen = true;\n this.element.classList.add('open');\n // Update original position before animation in case viewport changed\n this.fetchOriginalPosition();\n this.positionShadow();\n this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n // play animation\n const animate = ()=>(0, $6e8e6c64a3263339$export$2e2bcd8739ae039).transformMatrix(this.element, this.originalPosition, (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).calculateFinalState(this.element));\n if (this.element.naturalWidth === 0 || this.element.naturalHeight === 0) // Wait for image to load before animating\n this.element.addEventListener('load', animate, {\n once: true\n });\n else // animate directly if loaded\n animate();\n }\n close() {\n this.isOpen = false;\n this.element.classList.remove('open');\n (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).resetTransformMatrix(this.element);\n // Wait for animation to complete before showing original and destroying shadow\n setTimeout(()=>{\n this.original.style.visibility = 'visible';\n this.destroyItself();\n }, (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).transitionDuration);\n }\n placeItself() {\n document.body.appendChild(this.element);\n }\n destroyItself() {\n if (!document.body.contains(this.element)) return;\n document.body.removeChild(this.element);\n }\n}\n\n\n\nclass $e220af4964903f87$export$2e2bcd8739ae039 {\n currentImage = null;\n shadows = {};\n /**\n * ============\n * Initializers\n * ============\n */ constructor(config){\n (0, $0c04c0cc2b6985d8$export$940a7873bb071df8)(config);\n this.initOverlay();\n this.initImages();\n this.initControls();\n }\n initOverlay() {\n this.overlay = new (0, $e49d13fc7942bae1$export$2e2bcd8739ae039)();\n this.overlay.element.addEventListener('click', ()=>{\n this.closeCurrent();\n });\n }\n initImages() {\n this.images = document.querySelectorAll((0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).selector);\n this.images.forEach((image)=>{\n if (image.tagName !== 'IMG') return;\n image.id = crypto.randomUUID(); // generate unique id for each image\n image.style.cursor = (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).imageCursor;\n image.addEventListener('click', ()=>this.open(image)); // click image to open lightbox\n });\n }\n initControls() {\n // keyboard shortcuts\n document.addEventListener('keydown', (e)=>{\n if (e.key === 'Escape' || e.key === ' ') this.closeCurrent();\n });\n // scroll to dismiss\n document.body.addEventListener('wheel', (e)=>this.closeCurrent());\n document.body.addEventListener('touchmove', (e)=>this.closeCurrent());\n }\n /**\n * ============\n * Actions\n * ============\n */ // open lightbox = open shadow + show overlay\n open(image) {\n this.currentImage = image;\n const shadow = this.shadows[image.id] || new (0, $2f427fc7e1c3703f$export$2e2bcd8739ae039)(image);\n if (!this.shadows[image.id]) this.shadows[image.id] = shadow;\n shadow.open();\n this.overlay.show();\n }\n // close lightbox = remove shadow + hide overlay\n close(image) {\n this.currentImage = null;\n if (!this.shadows[image.id]) return;\n this.shadows[image.id].close();\n this.overlay.hide();\n }\n closeCurrent() {\n if (!this.currentImage) return;\n this.close(this.currentImage);\n }\n}\n\n\nexport {$e220af4964903f87$export$2e2bcd8739ae039 as default};\n//# sourceMappingURL=libra.min.js.map\n","import Overlay from './overlay';\nimport Shadow from './shadow';\nimport config from './config';\nimport { setConfig } from './config';\n\nexport default class LightBox {\n currentImage = null;\n shadows = {};\n\n /**\n * ============\n * Initializers\n * ============\n */\n\n constructor(config) {\n setConfig(config);\n\n this.initOverlay();\n this.initImages();\n this.initControls();\n }\n\n initOverlay() {\n this.overlay = new Overlay();\n this.overlay.element.addEventListener('click', () => {\n this.closeCurrent();\n });\n }\n\n initImages() {\n this.images = document.querySelectorAll(config.selector);\n this.images.forEach(image => {\n if (image.tagName !== 'IMG') return;\n image.id = crypto.randomUUID(); // generate unique id for each image\n image.style.cursor = config.imageCursor;\n image.addEventListener('click', () => this.open(image)); // click image to open lightbox\n });\n }\n\n initControls() {\n // keyboard shortcuts\n document.addEventListener('keydown', e => {\n if (e.key === 'Escape' || e.key === ' ')\n this.closeCurrent();\n });\n // scroll to dismiss\n document.body.addEventListener('wheel', e => this.closeCurrent());\n document.body.addEventListener('touchmove', e => this.closeCurrent());\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n // open lightbox = open shadow + show overlay\n open(image) {\n this.currentImage = image;\n\n const shadow = this.shadows[image.id] || new Shadow(image);\n if (!this.shadows[image.id]) {\n this.shadows[image.id] = shadow;\n }\n\n shadow.open();\n this.overlay.show();\n }\n\n // close lightbox = remove shadow + hide overlay\n close(image) {\n this.currentImage = null;\n\n if (!this.shadows[image.id]) return;\n this.shadows[image.id].close();\n\n this.overlay.hide();\n }\n\n closeCurrent() {\n if (!this.currentImage) return;\n this.close(this.currentImage);\n }\n}\n","import config from './config';\n\nexport default class Overlay {\n constructor() {\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay', 'libra-hidden');\n\n // Set transition duration from config\n overlay.style.transitionDuration = config.transitionDuration + 'ms';\n\n this.element = overlay;\n document.body.appendChild(overlay);\n\n return this;\n }\n\n show() {\n this.element.classList.remove('libra-hidden');\n this.element.classList.add('libra-visible');\n }\n\n hide() {\n this.element.classList.remove('libra-visible');\n this.element.classList.add('libra-hidden');\n }\n}\n","const config = {\n // selects images that load libra.js\n selector: '[data-libra]',\n\n // margin between viewport and zoomed image\n // in px\n margin: 50,\n\n // in small screens, it's best to not use margins\n // otherwise, the zoomed image gets even smaller\n // define on screen smaller than what size, margin is set to 0\n zeroMarginBreakpoint: 768,\n\n // shifts the zoomed image if needed\n offset: { x: 0, y: 0 },\n\n transitionDuration: 200, // milliseconds\n imageCursor: 'zoom-in',\n};\n\nfunction deepMerge(target, source) {\n for (const key in source) {\n if (\n typeof source[key] === 'object' &&\n source[key] !== null &&\n !Array.isArray(source[key])\n ) {\n if (!target[key]) target[key] = {};\n deepMerge(target[key], source[key]);\n } else {\n target[key] = source[key];\n }\n }\n return target;\n}\n\nexport function setConfig(newConfig) {\n deepMerge(config, newConfig);\n}\n\nexport default config;\n","import Animation from './animation.js'\nimport config from './config'\n\nexport default class Shadow {\n isOpen = false;\n\n /**\n * ============\n * Constructors\n * ============\n */\n\n constructor(image) {\n this.original = image;\n this.fetchOriginalPosition();\n this.create(image);\n\n return this;\n }\n\n create(image) {\n // create shadow image\n const shadow = document.createElement('img');\n shadow.src = image.src;\n shadow.id = `libra-shadow-${image.id}`;\n shadow.classList.add('libra-shadow');\n shadow.style.transitionDuration = config.transitionDuration + 'ms';\n\n this.element = shadow;\n\n // set positioning and place shadow element\n this.positionShadow();\n this.placeItself();\n }\n\n fetchOriginalPosition() {\n const rect = this.original.getBoundingClientRect();\n this.originalPosition = {\n top: rect.top + window.scrollY + config.offset.y,\n left: rect.left + window.scrollX + config.offset.x,\n width: rect.width,\n height: rect.height,\n };\n }\n\n positionShadow() {\n this.element.style.top = this.originalPosition.top + 'px';\n this.element.style.left = this.originalPosition.left + 'px';\n this.element.style.width = this.originalPosition.width + 'px';\n this.element.style.height = this.originalPosition.height + 'px';\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n open() {\n this.isOpen = true;\n this.element.classList.add('open');\n\n // Update original position before animation in case viewport changed\n this.fetchOriginalPosition();\n this.positionShadow();\n\n this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n\n // play animation\n const animate = () =>\n Animation.transformMatrix(\n this.element,\n this.originalPosition,\n Animation.calculateFinalState(this.element),\n );\n\n if (this.element.naturalWidth === 0 || this.element.naturalHeight === 0) {\n // Wait for image to load before animating\n this.element.addEventListener('load', animate, { once: true });\n } else {\n // animate directly if loaded\n animate();\n }\n }\n\n close() {\n this.isOpen = false;\n this.element.classList.remove('open');\n\n Animation.resetTransformMatrix(this.element);\n // Wait for animation to complete before showing original and destroying shadow\n setTimeout(() => {\n this.original.style.visibility = 'visible';\n this.destroyItself();\n }, config.transitionDuration);\n }\n\n placeItself() {\n document.body.appendChild(this.element);\n }\n\n destroyItself() {\n if (!document.body.contains(this.element)) return;\n document.body.removeChild(this.element);\n }\n}\n","import config from './config';\n\nexport default class Animation {\n static calculateFinalState(element) {\n let finals = {}\n\n let margin = config.margin;\n if (window.innerWidth <= config.zeroMarginBreakpoint) {\n margin = 0\n }\n\n const nw = element.naturalWidth;\n const nh = element.naturalHeight;\n const ratio = nw / nh;\n const ww = window.innerWidth - 2*margin;\n const wh = window.innerHeight - 2*margin;\n\n // size image based on width first\n finals.width = (nw > ww) ? ww : nw;\n finals.height = (nw > ww) ? ww / ratio : nh;\n\n // if height is too big, adjust based on height\n if (finals.height > wh) {\n finals.height = wh;\n finals.width = wh * ratio;\n }\n\n finals.top = (wh - finals.height) / 2 + window.scrollY + margin + config.offset.y;\n finals.left = (ww - finals.width) / 2 + window.scrollX + margin + config.offset.x;\n\n return finals;\n }\n\n static transformMatrix(element, starts, finals) {\n // Calculate scaling factors based on width and height interpolation\n const scaleX = finals.width / starts.width;\n const scaleY = finals.height / starts.height;\n\n // Calculate the center of the starting and final positions\n const startCenterX = starts.left + starts.width / 2;\n const startCenterY = starts.top + starts.height / 2;\n const finalCenterX = finals.left + finals.width / 2;\n const finalCenterY = finals.top + finals.height / 2;\n\n const translateX = finalCenterX - startCenterX;\n const translateY = finalCenterY - startCenterY;\n\n // Apply the transform with matrix (scale + translate)\n element.style.transform = `matrix(${scaleX}, 0, 0, ${scaleY}, ${translateX}, ${translateY})`;\n }\n\n static resetTransformMatrix(element) {\n element.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;\n }\n}\n"],"names":["$0c04c0cc2b6985d8$var$config","selector","margin","zeroMarginBreakpoint","offset","x","y","transitionDuration","imageCursor","$e49d13fc7942bae1$export$2e2bcd8739ae039","overlay","document","createElement","id","classList","add","style","element","body","appendChild","show","remove","hide","$6e8e6c64a3263339$export$2e2bcd8739ae039","calculateFinalState","finals","window","innerWidth","nw","naturalWidth","nh","naturalHeight","ratio","ww","wh","innerHeight","width","height","top","scrollY","left","scrollX","transformMatrix","starts","scaleX","scaleY","startCenterX","startCenterY","finalCenterX","finalCenterY","transform","resetTransformMatrix","$2f427fc7e1c3703f$export$2e2bcd8739ae039","isOpen","image","original","fetchOriginalPosition","create","shadow","src","positionShadow","placeItself","rect","getBoundingClientRect","originalPosition","open","visibility","contains","animate","addEventListener","once","close","setTimeout","destroyItself","removeChild","$e220af4964903f87$export$2e2bcd8739ae039","currentImage","shadows","config","$0c04c0cc2b6985d8$var$deepMerge","target","source","key","Array","isArray","initOverlay","initImages","initControls","closeCurrent","images","querySelectorAll","forEach","tagName","crypto","randomUUID","cursor","e","default"],"version":3,"file":"libra.min.js.map"}
|