summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-16 15:11:51 +0800
committerEltrac <hi@guhub.cn>2025-09-16 15:11:51 +0800
commitf4f5d842dfb398e9da599fe2534167e95cc1d6b9 (patch)
tree57a2a76cf6b101a0787b9ad74fd14de869d95791 /dist
parent788a3d9c1965bbba1ba793732a054d1b0d898a4e (diff)
chore(build): upload built files
Diffstat (limited to 'dist')
-rw-r--r--dist/libra.min.js2
-rw-r--r--dist/libra.min.js.map2
2 files changed, 2 insertions, 2 deletions
diff --git a/dist/libra.min.js b/dist/libra.min.js
index e1cdce0..ac819a5 100644
--- a/dist/libra.min.js
+++ b/dist/libra.min.js
@@ -1,2 +1,2 @@
-class e{zIndex=900;zIndexHidden=-100;constructor(){let e=document.createElement("div");return e.id="libra-overlay",e.classList.add("libra-overlay"),e.style.zIndex=this.zIndexHidden,e.style.opacity="0",this.element=e,document.body.appendChild(e),this}show(){this.element.style.opacity="1",this.element.style.zIndex=this.zIndex}hide(){this.element.style.opacity="0",this.element.style.zIndex="-100"}}class t{zIndex="1000";isOpen=!1;constructor(e){return this.create(e),this.calculateStartsAndFinals(),this}create(e){let t=document.createElement("img");t.src=e.src,t.id=`libra-shadow-${e.id}`,t.classList.add("libra-shadow"),t.style.top=e.offsetTop,t.style.left=e.offsetLeft,t.style.width=e.offsetWidth,t.style.height=e.offsetHeight,t.style.zIndex=this.zIndex,document.body.appendChild(t),this.element=t}calculateStartsAndFinals(){let e={top:this.element.offsetTop,left:this.element.offsetLeft,width:this.element.offsetWidth,height:this.element.offsetHeight},t={},i=this.element.naturalWidth,s=i/this.element.naturalHeight,n=window.innerWidth-100,h=window.innerHeight-100;t.width=Math.min(i,n),t.height=t.width/s,t.height>=h&&(t.height=h,t.width=t.height*s),t.left=(n-t.width)/2+50,t.top=(h-t.height)/2+50,this.finalState=t,this.startingState=e}open(){this.isOpen=!0,this.animate(this.startingState,this.finalState)}close(){this.isOpen=!1,this.element.style.transform="matrix(1, 0, 0, 1, 0, 0)",setTimeout(()=>{this.destroyItself()},300)}animate(e,t){let i=t.width/e.width,s=t.height/e.height,n=e.left+e.width/2,h=e.top+e.height/2,l=t.left+t.width/2,a=t.top+t.height/2;this.element.style.transform=`matrix(${i}, 0, 0, ${s}, ${l-n}, ${a-h})`}placeItself(){document.body.appendChild(this.element)}destroyItself(){document.body.contains(this.element)&&document.body.removeChild(this.element)}}class i{currentImage=null;shadows={};constructor({container:e}){this.container=e,this.initOverlay(),this.initImages(),this.initControls()}initOverlay(){this.overlay=new e,this.overlay.element.addEventListener("click",e=>{this.closeCurrent()})}initImages(){this.images=document.querySelectorAll(`${this.container} img[data-libra]`),this.images.forEach(e=>{e.id=crypto.randomUUID(),(function(e){let t,i=e.parentElement;return i&&"A"===i.tagName?t=i:((t=document.createElement("a")).href=e.src,i.insertBefore(t,e),t.appendChild(e)),t})(e).addEventListener("click",t=>{t.preventDefault(),this.openLightBox(e)})})}initControls(){document.addEventListener("keydown",e=>{("Escape"===e.key||" "===e.key)&&this.closeCurrent()}),document.body.addEventListener("wheel",e=>{this.closeCurrent()})}openLightBox(e){e.style.visibility="hidden",this.currentImage=e;let i=this.shadows[e.id]||new t(e);this.shadows[e.id]||(this.shadows[e.id]=i),document.body.contains(i.element)||i.placeItself(),i.open(),this.overlay.show()}closeLightBox(e){e.style.visibility="visible",this.currentImage=null;let t=this.shadows[e.id];t&&(t.close(),this.overlay.hide())}closeCurrent(){this.currentImage&&this.closeLightBox(this.currentImage)}closeAll(){this.images.forEach(e=>{this.closeLightBox(e)}),this.overlay.hide()}}export{i as default};
+class e{zIndex=900;zIndexHidden=-100;constructor(){let e=document.createElement("div");return e.id="libra-overlay",e.classList.add("libra-overlay"),e.style.zIndex=this.zIndexHidden,e.style.opacity="0",this.element=e,document.body.appendChild(e),this}show(){this.element.style.opacity="1",this.element.style.zIndex=this.zIndex}hide(){this.element.style.opacity="0",this.element.style.zIndex="-100"}}class t{static calculateFinalState(e){let t={},i=e.naturalWidth/e.naturalHeight,s=window.innerWidth-100,l=window.innerHeight-100;return e.naturalWidth>s?(t.width=s,t.height=s/i,t.height>l&&(t.height=l,t.width=l*i)):(t.width=e.offsetWidth,t.height=e.offsetHeight),t.top=(l-t.height)/2+window.scrollY+50,t.left=(s-t.width)/2+window.scrollX+50,t}static transformMatrix(e,t,i){let s=i.width/t.width,l=i.height/t.height,h=t.left+t.width/2,n=t.top+t.height/2,o=i.left+i.width/2,a=i.top+i.height/2;e.style.transform=`matrix(${s}, 0, 0, ${l}, ${o-h}, ${a-n})`}static resetTransformMatrix(e){e.style.transform="matrix(1, 0, 0, 1, 0, 0)"}}class i{zIndex="1000";isOpen=!1;constructor(e){return this.create(e),this.startingState={top:this.element.offsetTop,left:this.element.offsetLeft,width:this.element.offsetWidth,height:this.element.offsetHeight},this}create(e){let t=document.createElement("img");t.src=e.src,t.id=`libra-shadow-${e.id}`,t.classList.add("libra-shadow"),t.style.top=e.offsetTop,t.style.left=e.offsetLeft,t.style.width=e.offsetWidth,t.style.height=e.offsetHeight,t.style.zIndex=this.zIndex,document.body.appendChild(t),this.element=t}open(){this.isOpen=!0,t.transformMatrix(this.element,this.startingState,t.calculateFinalState(this.element))}close(){this.isOpen=!1,t.resetTransformMatrix(this.element),setTimeout(()=>this.destroyItself(),300)}placeItself(){document.body.appendChild(this.element)}destroyItself(){document.body.contains(this.element)&&document.body.removeChild(this.element)}}class s{currentImage=null;shadows={};constructor({selector:e}){this.selector=e,this.initOverlay(),this.initImages(),this.initControls()}initOverlay(){this.overlay=new e,this.overlay.element.addEventListener("click",()=>{this.closeCurrent()})}initImages(){this.images=document.querySelectorAll(this.selector),this.images.forEach(e=>{"IMG"===e.tagName&&(e.id=crypto.randomUUID(),e.addEventListener("click",()=>this.open(e)))})}initControls(){document.addEventListener("keydown",e=>{("Escape"===e.key||" "===e.key)&&this.closeCurrent()}),document.body.addEventListener("wheel",e=>{this.closeCurrent()})}open(e){e.style.visibility="hidden",this.currentImage=e;let t=this.shadows[e.id]||new i(e);this.shadows[e.id]||(this.shadows[e.id]=t),document.body.contains(t.element)||t.placeItself(),t.open(),this.overlay.show()}close(e){e.style.visibility="visible",this.currentImage=null;let t=this.shadows[e.id];t&&(t.close(),this.overlay.hide())}closeCurrent(){this.currentImage&&this.close(this.currentImage)}closeAll(){this.images.forEach(e=>{this.close(e)}),this.overlay.hide()}}export{s as default};
//# sourceMappingURL=libra.min.js.map
diff --git a/dist/libra.min.js.map b/dist/libra.min.js.map
index 3efb1f7..7c6892a 100644
--- a/dist/libra.min.js.map
+++ b/dist/libra.min.js.map
@@ -1 +1 @@
-{"mappings":"AEAe,MAAA,EACb,OAAS,GAAI,AACb,CAAA,aAAe,IAAK,AAEpB,cAAc,CACZ,IAAM,EAAU,SAAS,aAAa,CAAC,OAWvC,OAVA,EAAQ,EAAE,CAAG,gBACb,EAAQ,SAAS,CAAC,GAAG,CAAC,iBAGtB,EAAQ,KAAK,CAAC,MAAM,CAAG,IAAI,CAAC,YAAY,CACxC,EAAQ,KAAK,CAAC,OAAO,CAAG,IAExB,IAAI,CAAC,OAAO,CAAG,EACf,SAAS,IAAI,CAAC,WAAW,CAAC,GAEnB,IAAI,AACb,CAEA,MAAO,CACL,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAG,IAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAG,IAAI,CAAC,MAAM,AACzC,CAEA,MAAO,CACL,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAG,IAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAG,MAC9B,CACF,CC5Be,MAAA,EACb,OAAS,MAAM,AACf,CAAA,OAAS,CAAA,CAAK,AAQd,aAAY,CAAK,CAAE,CAGjB,OAFA,IAAI,CAAC,MAAM,CAAC,GACZ,IAAI,CAAC,wBAAwB,GACtB,IAAI,AACb,CAEA,OAAO,CAAK,CAAE,CAEZ,IAAM,EAAc,SAA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AAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,CAAG,CAD3B,EAKI,AAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,EAAO,OAAO,GAAG,EAAO,WAAW,GAC/D,EAAO,IAAI,GAEX,IAAI,CAAC,OAAO,CAAC,IAAI,EACnB,CAEA,cAAc,CAAK,CAAE,CAEnB,EAAM,KAAK,CAAC,UAAU,CAAG,UACzB,IAAI,CAAC,YAAY,CAAG,KAGpB,IAAM,EAAS,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,CAChC,IACL,EAAO,KAAK,GAEZ,IAAI,CAAC,OAAO,CAAC,IAAI,GACnB,CAEA,cAAe,CACR,IAAI,CAAC,YAAY,EACtB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CACtC,CAEA,UAAW,CACT,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,AAAA,IAClB,IAAI,CAAC,aAAa,CAAC,EACrB,GACA,IAAI,CAAC,OAAO,CAAC,IAAI,EACnB,CACF,Q,K,O","sources":["<anon>","src/lightbox.js","src/overlay.js","src/shadow.js"],"sourcesContent":["class $e49d13fc7942bae1$export$2e2bcd8739ae039 {\n zIndex = 900;\n zIndexHidden = -100;\n constructor(){\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay');\n // initialized state\n overlay.style.zIndex = this.zIndexHidden;\n overlay.style.opacity = '0';\n this.element = overlay;\n document.body.appendChild(overlay);\n return this;\n }\n show() {\n this.element.style.opacity = '1';\n this.element.style.zIndex = this.zIndex;\n }\n hide() {\n this.element.style.opacity = '0';\n this.element.style.zIndex = '-100';\n }\n}\n\n\nclass $2f427fc7e1c3703f$export$2e2bcd8739ae039 {\n zIndex = '1000';\n isOpen = false;\n /**\n * ============\n * Constructors\n * ============\n */ constructor(image){\n this.create(image);\n this.calculateStartsAndFinals();\n return this;\n }\n create(image) {\n // create shadow image\n const shadowImage = document.createElement('img');\n shadowImage.src = image.src;\n shadowImage.id = `libra-shadow-${image.id}`;\n shadowImage.classList.add('libra-shadow');\n // style and position shadow image\n shadowImage.style.top = image.offsetTop;\n shadowImage.style.left = image.offsetLeft;\n shadowImage.style.width = image.offsetWidth;\n shadowImage.style.height = image.offsetHeight;\n shadowImage.style.zIndex = this.zIndex;\n document.body.appendChild(shadowImage);\n this.element = shadowImage;\n }\n calculateStartsAndFinals() {\n // get starting state\n const s = {\n top: this.element.offsetTop,\n left: this.element.offsetLeft,\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n };\n const f = {};\n const margin = 50;\n // calculate final size\n const nw = this.element.naturalWidth;\n const nh = this.element.naturalHeight;\n const ratio = nw / nh;\n const ww = window.innerWidth - margin * 2;\n const wh = window.innerHeight - margin * 2;\n f.width = Math.min(nw, ww);\n f.height = f.width / ratio;\n if (f.height >= wh) {\n f.height = wh;\n f.width = f.height * ratio;\n }\n // calculate final position\n f.left = (ww - f.width) / 2 + margin;\n f.top = (wh - f.height) / 2 + margin;\n this.finalState = f;\n this.startingState = s;\n }\n /**\n * ============\n * Actions\n * ============\n */ open() {\n this.isOpen = true;\n this.animate(this.startingState, this.finalState);\n }\n close() {\n this.isOpen = false;\n this.element.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;\n setTimeout(()=>{\n this.destroyItself();\n }, 300);\n }\n animate(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 this.element.style.transform = `matrix(${scaleX}, 0, 0, ${scaleY}, ${translateX}, ${translateY})`;\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\nclass $e220af4964903f87$export$2e2bcd8739ae039 {\n currentImage = null;\n shadows = {};\n /**\n * ============\n * Initializers\n * ============\n */ constructor({ container: container }){\n this.container = container;\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', (e)=>{\n this.closeCurrent();\n });\n }\n initImages() {\n this.images = document.querySelectorAll(`${this.container} img[data-libra]`);\n function wrapInLink(image) {\n // wrap image with a link if it's not already wrapped\n const parent = image.parentElement;\n let link;\n if (!parent || parent.tagName !== 'A') {\n link = document.createElement('a');\n link.href = image.src;\n // replace image with the linked one\n parent.insertBefore(link, image);\n link.appendChild(image);\n } else link = parent;\n return link;\n }\n this.images.forEach((image)=>{\n // generate unique id for each image\n image.id = crypto.randomUUID();\n // make sure every image has a link\n const link = wrapInLink(image);\n // click link to open lightbox\n link.addEventListener('click', (e)=>{\n e.preventDefault();\n this.openLightBox(image);\n });\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)=>{\n this.closeCurrent();\n });\n }\n /**\n * ============\n * Actions\n * ============\n */ openLightBox(image) {\n // hide and store original image\n image.style.visibility = 'hidden';\n this.currentImage = image;\n // get shadow of this 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 // place and open shadow\n if (!document.body.contains(shadow.element)) shadow.placeItself();\n shadow.open();\n this.overlay.show();\n }\n closeLightBox(image) {\n // show and unstore original image\n image.style.visibility = 'visible';\n this.currentImage = null;\n // close shadow\n const shadow = this.shadows[image.id];\n if (!shadow) return;\n shadow.close();\n this.overlay.hide();\n }\n closeCurrent() {\n if (!this.currentImage) return;\n this.closeLightBox(this.currentImage);\n }\n closeAll() {\n this.images.forEach((image)=>{\n this.closeLightBox(image);\n });\n this.overlay.hide();\n }\n}\n\n\nexport {$e220af4964903f87$export$2e2bcd8739ae039 as default};\n//# sourceMappingURL=libra.min.js.map\n","import Overlay from './overlay.js';\nimport Shadow from './shadow.js';\n\nexport default class LightBox {\n currentImage = null;\n shadows = {};\n\n /**\n * ============\n * Initializers\n * ============\n */\n\n constructor({ container }) {\n this.container = container;\n this.initOverlay();\n this.initImages();\n this.initControls();\n }\n\n initOverlay() {\n this.overlay = new Overlay();\n this.overlay.element.addEventListener('click', e => {\n this.closeCurrent();\n });\n }\n\n initImages() {\n this.images = document.querySelectorAll(`${this.container} img[data-libra]`);\n\n function wrapInLink(image) {\n // wrap image with a link if it's not already wrapped\n const parent = image.parentElement;\n let link;\n if (!parent || parent.tagName !== 'A') {\n link = document.createElement('a');\n link.href = image.src;\n // replace image with the linked one\n parent.insertBefore(link, image);\n link.appendChild(image);\n } else {\n link = parent;\n }\n return link;\n }\n\n this.images.forEach(image => {\n // generate unique id for each image\n image.id = crypto.randomUUID();\n // make sure every image has a link\n const link = wrapInLink(image);\n // click link to open lightbox\n link.addEventListener('click', e => {\n e.preventDefault();\n this.openLightBox(image);\n });\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 });\n // scroll to dismiss\n document.body.addEventListener('wheel', e => {\n this.closeCurrent();\n });\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n openLightBox(image) {\n // hide and store original image\n image.style.visibility = 'hidden';\n this.currentImage = image;\n\n // get shadow of this image\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 // place and open shadow\n if (!document.body.contains(shadow.element)) shadow.placeItself();\n shadow.open();\n\n this.overlay.show();\n }\n\n closeLightBox(image) {\n // show and unstore original image\n image.style.visibility = 'visible';\n this.currentImage = null;\n\n // close shadow\n const shadow = this.shadows[image.id];\n if (!shadow) return;\n shadow.close();\n\n this.overlay.hide();\n }\n\n closeCurrent() {\n if (!this.currentImage) return;\n this.closeLightBox(this.currentImage);\n }\n\n closeAll() {\n this.images.forEach(image => {\n this.closeLightBox(image);\n });\n this.overlay.hide();\n }\n}\n","export default class Overlay {\n zIndex = 900;\n zIndexHidden = -100;\n\n constructor() {\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay');\n\n // initialized state\n overlay.style.zIndex = this.zIndexHidden;\n overlay.style.opacity = '0';\n\n this.element = overlay;\n document.body.appendChild(overlay);\n\n return this;\n }\n\n show() {\n this.element.style.opacity = '1';\n this.element.style.zIndex = this.zIndex;\n }\n\n hide() {\n this.element.style.opacity = '0';\n this.element.style.zIndex = '-100';\n }\n}\n","export default class Shadow {\n zIndex = '1000'\n isOpen = false\n\n /**\n * ============\n * Constructors\n * ============\n */\n\n constructor(image) {\n this.create(image);\n this.calculateStartsAndFinals();\n return this;\n }\n\n create(image) {\n // create shadow image\n const shadowImage = document.createElement('img');\n shadowImage.src = image.src;\n shadowImage.id = `libra-shadow-${image.id}`;\n shadowImage.classList.add('libra-shadow');\n\n // style and position shadow image\n shadowImage.style.top = image.offsetTop;\n shadowImage.style.left = image.offsetLeft;\n shadowImage.style.width = image.offsetWidth;\n shadowImage.style.height = image.offsetHeight;\n shadowImage.style.zIndex = this.zIndex;\n\n document.body.appendChild(shadowImage);\n this.element = shadowImage;\n }\n\n calculateStartsAndFinals() {\n // get starting state\n const s = {\n top: this.element.offsetTop,\n left: this.element.offsetLeft,\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n }\n\n const f = {};\n const margin = 50;\n\n // calculate final size\n const nw = this.element.naturalWidth;\n const nh = this.element.naturalHeight;\n const ratio = nw / nh;\n\n const ww = window.innerWidth - margin*2;\n const wh = window.innerHeight - margin*2;\n\n f.width = Math.min(nw, ww);\n f.height = f.width / ratio;\n\n if (f.height >= wh) {\n f.height = wh;\n f.width = f.height * ratio;\n }\n\n // calculate final position\n f.left = (ww - f.width) / 2 + margin;\n f.top = (wh - f.height) / 2 + margin;\n\n this.finalState = f;\n this.startingState = s;\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n open() {\n this.isOpen = true;\n this.animate(this.startingState, this.finalState)\n }\n\n close() {\n this.isOpen = false;\n this.element.style.transform = `matrix(1, 0, 0, 1, 0, 0)`;\n setTimeout(() => {\n this.destroyItself();\n }, 300);\n }\n\n animate(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 this.element.style.transform = `matrix(${scaleX}, 0, 0, ${scaleY}, ${translateX}, ${translateY})`;\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"],"names":["$e49d13fc7942bae1$export$2e2bcd8739ae039","zIndex","zIndexHidden","overlay","document","createElement","id","classList","add","style","opacity","element","body","appendChild","show","hide","$2f427fc7e1c3703f$export$2e2bcd8739ae039","isOpen","image","create","calculateStartsAndFinals","shadowImage","src","top","offsetTop","left","offsetLeft","width","offsetWidth","height","offsetHeight","s","f","nw","naturalWidth","ratio","naturalHeight","ww","window","innerWidth","margin","wh","innerHeight","Math","min","finalState","startingState","open","animate","close","transform","setTimeout","destroyItself","starts","finals","scaleX","scaleY","startCenterX","startCenterY","finalCenterX","finalCenterY","placeItself","contains","removeChild","$e220af4964903f87$export$2e2bcd8739ae039","currentImage","shadows","container","initOverlay","initImages","initControls","addEventListener","e","closeCurrent","images","querySelectorAll","forEach","crypto","randomUUID","link","wrapInLink","parent","parentElement","tagName","href","insertBefore","preventDefault","openLightBox","key","visibility","shadow","closeLightBox","closeAll","default"],"version":3,"file":"libra.min.js.map"} \ No newline at end of file
+{"mappings":"AEAe,MAAA,EACb,OAAS,GAAI,AACb,CAAA,aAAe,IAAK,AAEpB,cAAc,CACZ,IAAM,EAAU,SAAS,aAAa,CAAC,OAWvC,OAVA,EAAQ,EAAE,CAAG,gBACb,EAAQ,SAAS,CAAC,GAAG,CAAC,iBAGtB,EAAQ,KAAK,CAAC,MAAM,CAAG,IAAI,CAAC,YAAY,CACxC,EAAQ,KAAK,CAAC,OAAO,CAAG,IAExB,IAAI,CAAC,OAAO,CAAG,EACf,SAAS,IAAI,CAAC,WAAW,CAAC,GAEnB,IAAI,AACb,CAEA,MAAO,CACL,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAG,IAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAG,IAAI,CAAC,MAAM,AACzC,CAEA,MAAO,CACL,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAG,IAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAG,MAC9B,CACF,CE5Be,MAAA,EACb,OAAO,oBAAoB,CAAO,CAAE,CAClC,IAAI,EAAS,CAAC,EAGR,EAAQ,EAAQ,YAAY,CAAG,EAAQ,aAAa,CACpD,EAAK,OAAO,UAAU,CAAG,IACzB,EAAK,OAAO,WAAW,CAAG,IAiBhC,OAfI,EAAQ,YAAY,CAAG,GACzB,EAAO,KAAK,CAAG,EACf,EAAO,MAAM,CAAG,EAAK,EACjB,EAAO,MAAM,CAAG,IAClB,EAAO,MAAM,CAAG,EAChB,EAAO,KAAK,CAAG,EAAK,KAGtB,EAAO,KAAK,CAAG,EAAQ,WAAW,CAClC,EAAO,MAAM,CAAG,EAAQ,YAAY,EAGtC,EAAO,GAAG,CAAG,AAAC,CAAA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AC,YAAY,EACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAC9B,CAEA,UAAW,CACT,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,AAAA,IAClB,IAAI,CAAC,KAAK,CAAC,EACb,GACA,IAAI,CAAC,OAAO,CAAC,IAAI,EACnB,CACF,Q,K,O","sources":["<anon>","src/lightbox.js","src/overlay.js","src/shadow.js","src/animation.js"],"sourcesContent":["class $e49d13fc7942bae1$export$2e2bcd8739ae039 {\n zIndex = 900;\n zIndexHidden = -100;\n constructor(){\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay');\n // initialized state\n overlay.style.zIndex = this.zIndexHidden;\n overlay.style.opacity = '0';\n this.element = overlay;\n document.body.appendChild(overlay);\n return this;\n }\n show() {\n this.element.style.opacity = '1';\n this.element.style.zIndex = this.zIndex;\n }\n hide() {\n this.element.style.opacity = '0';\n this.element.style.zIndex = '-100';\n }\n}\n\n\nclass $6e8e6c64a3263339$export$2e2bcd8739ae039 {\n static calculateFinalState(element) {\n let finals = {};\n const margin = 50;\n const ratio = element.naturalWidth / element.naturalHeight;\n const ww = window.innerWidth - 2 * margin;\n const wh = window.innerHeight - 2 * margin;\n if (element.naturalWidth > ww) {\n finals.width = ww;\n finals.height = ww / ratio;\n if (finals.height > wh) {\n finals.height = wh;\n finals.width = wh * ratio;\n }\n } else {\n finals.width = element.offsetWidth;\n finals.height = element.offsetHeight;\n }\n finals.top = (wh - finals.height) / 2 + window.scrollY + margin;\n finals.left = (ww - finals.width) / 2 + window.scrollX + margin;\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\nclass $2f427fc7e1c3703f$export$2e2bcd8739ae039 {\n zIndex = '1000';\n isOpen = false;\n /**\n * ============\n * Constructors\n * ============\n */ constructor(image){\n this.create(image);\n this.startingState = {\n top: this.element.offsetTop,\n left: this.element.offsetLeft,\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n };\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 // style and position shadow image\n shadow.style.top = image.offsetTop;\n shadow.style.left = image.offsetLeft;\n shadow.style.width = image.offsetWidth;\n shadow.style.height = image.offsetHeight;\n shadow.style.zIndex = this.zIndex;\n document.body.appendChild(shadow);\n this.element = shadow;\n }\n /**\n * ============\n * Actions\n * ============\n */ open() {\n this.isOpen = true;\n (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).transformMatrix(this.element, this.startingState, (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).calculateFinalState(this.element));\n }\n close() {\n this.isOpen = false;\n (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).resetTransformMatrix(this.element);\n setTimeout(()=>this.destroyItself(), 300);\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\nclass $e220af4964903f87$export$2e2bcd8739ae039 {\n currentImage = null;\n shadows = {};\n /**\n * ============\n * Initializers\n * ============\n */ constructor({ selector: selector }){\n this.selector = selector;\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(this.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.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)=>{\n this.closeCurrent();\n });\n }\n /**\n * ============\n * Actions\n * ============\n */ open(image) {\n // hide and store original image\n image.style.visibility = 'hidden';\n this.currentImage = image;\n // get shadow of this 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 // place and open shadow\n if (!document.body.contains(shadow.element)) shadow.placeItself();\n shadow.open();\n this.overlay.show();\n }\n close(image) {\n // show and unstore original image\n image.style.visibility = 'visible';\n this.currentImage = null;\n // close shadow\n const shadow = this.shadows[image.id];\n if (!shadow) return;\n shadow.close();\n this.overlay.hide();\n }\n closeCurrent() {\n if (!this.currentImage) return;\n this.close(this.currentImage);\n }\n closeAll() {\n this.images.forEach((image)=>{\n this.close(image);\n });\n this.overlay.hide();\n }\n}\n\n\nexport {$e220af4964903f87$export$2e2bcd8739ae039 as default};\n//# sourceMappingURL=libra.min.js.map\n","import Overlay from './overlay.js';\nimport Shadow from './shadow.js';\n\nexport default class LightBox {\n currentImage = null;\n shadows = {};\n\n /**\n * ============\n * Initializers\n * ============\n */\n\n constructor({ selector }) {\n this.selector = selector;\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(this.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.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 });\n // scroll to dismiss\n document.body.addEventListener('wheel', e => {\n this.closeCurrent();\n });\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n open(image) {\n // hide and store original image\n image.style.visibility = 'hidden';\n this.currentImage = image;\n\n // get shadow of this image\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 // place and open shadow\n if (!document.body.contains(shadow.element)) shadow.placeItself();\n shadow.open();\n\n this.overlay.show();\n }\n\n close(image) {\n // show and unstore original image\n image.style.visibility = 'visible';\n this.currentImage = null;\n\n // close shadow\n const shadow = this.shadows[image.id];\n if (!shadow) return;\n shadow.close();\n\n this.overlay.hide();\n }\n\n closeCurrent() {\n if (!this.currentImage) return;\n this.close(this.currentImage);\n }\n\n closeAll() {\n this.images.forEach(image => {\n this.close(image);\n });\n this.overlay.hide();\n }\n}\n","export default class Overlay {\n zIndex = 900;\n zIndexHidden = -100;\n\n constructor() {\n const overlay = document.createElement('div');\n overlay.id = 'libra-overlay';\n overlay.classList.add('libra-overlay');\n\n // initialized state\n overlay.style.zIndex = this.zIndexHidden;\n overlay.style.opacity = '0';\n\n this.element = overlay;\n document.body.appendChild(overlay);\n\n return this;\n }\n\n show() {\n this.element.style.opacity = '1';\n this.element.style.zIndex = this.zIndex;\n }\n\n hide() {\n this.element.style.opacity = '0';\n this.element.style.zIndex = '-100';\n }\n}\n","import Animation from './animation.js'\n\nexport default class Shadow {\n zIndex = '1000'\n isOpen = false\n\n /**\n * ============\n * Constructors\n * ============\n */\n\n constructor(image) {\n this.create(image);\n\n this.startingState = {\n top: this.element.offsetTop,\n left: this.element.offsetLeft,\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n }\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\n // style and position shadow image\n shadow.style.top = image.offsetTop;\n shadow.style.left = image.offsetLeft;\n shadow.style.width = image.offsetWidth;\n shadow.style.height = image.offsetHeight;\n shadow.style.zIndex = this.zIndex;\n\n document.body.appendChild(shadow);\n this.element = shadow;\n }\n\n /**\n * ============\n * Actions\n * ============\n */\n\n open() {\n this.isOpen = true;\n Animation.transformMatrix(\n this.element,\n this.startingState,\n Animation.calculateFinalState(this.element)\n );\n }\n\n close() {\n this.isOpen = false;\n Animation.resetTransformMatrix(this.element);\n setTimeout(() => this.destroyItself(), 300);\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","export default class Animation {\n static calculateFinalState(element) {\n let finals = {}\n\n const margin = 50\n const ratio = element.naturalWidth / element.naturalHeight;\n const ww = window.innerWidth - 2*margin;\n const wh = window.innerHeight - 2*margin;\n\n if (element.naturalWidth > ww) {\n finals.width = ww;\n finals.height = ww / ratio;\n if (finals.height > wh) {\n finals.height = wh;\n finals.width = wh * ratio;\n }\n } else {\n finals.width = element.offsetWidth;\n finals.height = element.offsetHeight;\n }\n\n finals.top = (wh - finals.height) / 2 + window.scrollY + margin;\n finals.left = (ww - finals.width) / 2 + window.scrollX + margin;\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":["$e49d13fc7942bae1$export$2e2bcd8739ae039","zIndex","zIndexHidden","overlay","document","createElement","id","classList","add","style","opacity","element","body","appendChild","show","hide","$6e8e6c64a3263339$export$2e2bcd8739ae039","calculateFinalState","finals","ratio","naturalWidth","naturalHeight","ww","window","innerWidth","wh","innerHeight","width","height","offsetWidth","offsetHeight","top","scrollY","left","scrollX","transformMatrix","starts","scaleX","scaleY","startCenterX","startCenterY","finalCenterX","finalCenterY","transform","resetTransformMatrix","$2f427fc7e1c3703f$export$2e2bcd8739ae039","isOpen","image","create","startingState","offsetTop","offsetLeft","shadow","src","open","close","setTimeout","destroyItself","placeItself","contains","removeChild","$e220af4964903f87$export$2e2bcd8739ae039","currentImage","shadows","selector","initOverlay","initImages","initControls","addEventListener","closeCurrent","images","querySelectorAll","forEach","tagName","crypto","randomUUID","e","key","visibility","closeAll","default"],"version":3,"file":"libra.min.js.map"} \ No newline at end of file