summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-17 22:07:44 +0800
committerEltrac <hi@guhub.cn>2025-09-17 22:07:44 +0800
commit6c0220a4fa9c1c31b876db4addac29cbb3e2e5a0 (patch)
treed891b982b0d3692c7fb84788484e0382749f0b5b
parentea260c1ef753eb35c75e9016840357abdfddaac1 (diff)
chore(build): upload built files
-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 8b6d12f..c33723d 100644
--- a/dist/libra.min.js
+++ b/dist/libra.min.js
@@ -1,2 +1,2 @@
-class t{zIndex=900;zIndexHidden=-100;constructor(){let t=document.createElement("div");return t.id="libra-overlay",t.classList.add("libra-overlay"),t.style.zIndex=this.zIndexHidden,t.style.opacity="0",this.element=t,document.body.appendChild(t),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 e{static calculateFinalState(t){let e={},i=t.naturalWidth/t.naturalHeight,s=window.innerWidth-100,n=window.innerHeight-100;return t.naturalWidth>s?(e.width=s,e.height=s/i,e.height>n&&(e.height=n,e.width=n*i)):(e.width=t.offsetWidth,e.height=t.offsetHeight),e.top=(n-e.height)/2+window.scrollY+50,e.left=(s-e.width)/2+window.scrollX+50,e}static transformMatrix(t,e,i){let s=i.width/e.width,n=i.height/e.height,l=e.left+e.width/2,o=e.top+e.height/2,h=i.left+i.width/2,r=i.top+i.height/2;t.style.transform=`matrix(${s}, 0, 0, ${n}, ${h-l}, ${r-o})`}static resetTransformMatrix(t){t.style.transform="matrix(1, 0, 0, 1, 0, 0)"}}class i{zIndex="1000";isOpen=!1;constructor(t){this.original=t;let e=this.original.getBoundingClientRect();return this.originalPosition={top:e.top+window.scrollY,left:e.left+window.scrollX,width:e.width,height:e.height},this.create(t),this}create(t){let e=document.createElement("img");e.src=t.src,e.id=`libra-shadow-${t.id}`,e.classList.add("libra-shadow"),e.style.top=`${this.originalPosition.top}px`,e.style.left=`${this.originalPosition.left}px`,e.style.width=`${this.originalPosition.width}px`,e.style.height=`${this.originalPosition.height}px`,e.style.zIndex=this.zIndex,document.body.appendChild(e),this.element=e}open(){this.isOpen=!0,this.original.style.visibility="hidden",document.body.contains(this.element)||this.placeItself(),e.transformMatrix(this.element,this.originalPosition,e.calculateFinalState(this.element))}close(){this.isOpen=!1,this.original.style.visibility="visible",e.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:t}){this.selector=t,this.initOverlay(),this.initImages(),this.initControls()}initOverlay(){this.overlay=new t,this.overlay.element.addEventListener("click",()=>{this.closeCurrent()})}initImages(){this.images=document.querySelectorAll(this.selector),this.images.forEach(t=>{"IMG"===t.tagName&&(t.id=crypto.randomUUID(),t.style.cursor="zoom-in",t.addEventListener("click",()=>this.open(t)))})}initControls(){document.addEventListener("keydown",t=>{("Escape"===t.key||" "===t.key)&&this.closeCurrent()}),document.body.addEventListener("wheel",t=>{this.closeCurrent()})}open(t){this.currentImage=t;let e=this.shadows[t.id]||new i(t);this.shadows[t.id]||(this.shadows[t.id]=e),e.open(),this.overlay.show()}close(t){this.currentImage=null,this.shadows[t.id]&&(this.shadows[t.id].close(),this.overlay.hide())}closeCurrent(){this.currentImage&&this.close(this.currentImage)}}export{s as default};
+class t{zIndex=900;zIndexHidden=-100;constructor(){let t=document.createElement("div");return t.id="libra-overlay",t.classList.add("libra-overlay"),t.style.zIndex=this.zIndexHidden,t.style.opacity="0",this.element=t,document.body.appendChild(t),this}show(){this.element.style.opacity="1",this.element.style.zIndex=this.zIndex}hide(){this.element.style.opacity="0",this.element.style.zIndex="-100"}}let e={selector:"[data-libra]",margin:50,offset:{x:0,y:0}};class i{static calculateFinalState(t){let i={},s=e.margin,n=t.naturalWidth,l=t.naturalHeight,o=n/l,r=window.innerWidth-2*s,h=window.innerHeight-2*s;return i.width=n>r?r:n,i.height=n>r?r/o:l,i.height>h&&(i.height=h,i.width=h*o),i.top=(h-i.height)/2+window.scrollY+s+e.offset.y,i.left=(r-i.width)/2+window.scrollX+s+e.offset.x,i}static transformMatrix(t,e,i){let s=i.width/e.width,n=i.height/e.height,l=e.left+e.width/2,o=e.top+e.height/2,r=i.left+i.width/2,h=i.top+i.height/2;t.style.transform=`matrix(${s}, 0, 0, ${n}, ${r-l}, ${h-o})`}static resetTransformMatrix(t){t.style.transform="matrix(1, 0, 0, 1, 0, 0)"}}class s{zIndex="1000";isOpen=!1;constructor(t){this.original=t;let i=this.original.getBoundingClientRect();return this.originalPosition={top:i.top+window.scrollY+e.offset.y,left:i.left+window.scrollX+e.offset.x,width:i.width,height:i.height},this.create(t),this}create(t){let e=document.createElement("img");e.src=t.src,e.id=`libra-shadow-${t.id}`,e.classList.add("libra-shadow"),e.style.top=`${this.originalPosition.top}px`,e.style.left=`${this.originalPosition.left}px`,e.style.width=`${this.originalPosition.width}px`,e.style.height=`${this.originalPosition.height}px`,e.style.zIndex=this.zIndex,document.body.appendChild(e),this.element=e}open(){this.isOpen=!0,this.element.classList.add("open"),this.original.style.visibility="hidden",document.body.contains(this.element)||this.placeItself(),i.transformMatrix(this.element,this.originalPosition,i.calculateFinalState(this.element))}close(){this.isOpen=!1,this.element.classList.remove("open"),this.original.style.visibility="visible",i.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 n{currentImage=null;shadows={};constructor(t){!function t(e,i){for(let s in i)"object"!=typeof i[s]||null===i[s]||Array.isArray(i[s])?e[s]=i[s]:(e[s]||(e[s]={}),t(e[s],i[s]));return e}(e,t),this.initOverlay(),this.initImages(),this.initControls()}initOverlay(){this.overlay=new t,this.overlay.element.addEventListener("click",()=>{this.closeCurrent()})}initImages(){this.images=document.querySelectorAll(e.selector),this.images.forEach(t=>{"IMG"===t.tagName&&(t.id=crypto.randomUUID(),t.style.cursor="zoom-in",t.addEventListener("click",()=>this.open(t)))})}initControls(){document.addEventListener("keydown",t=>{("Escape"===t.key||" "===t.key)&&this.closeCurrent()}),document.body.addEventListener("wheel",t=>{this.closeCurrent()})}open(t){this.currentImage=t;let e=this.shadows[t.id]||new s(t);this.shadows[t.id]||(this.shadows[t.id]=e),e.open(),this.overlay.show()}close(t){this.currentImage=null,this.shadows[t.id]&&(this.shadows[t.id].close(),this.overlay.hide())}closeCurrent(){this.currentImage&&this.close(this.currentImage)}}export{n as default};
//# sourceMappingURL=libra.min.js.map
diff --git a/dist/libra.min.js.map b/dist/libra.min.js.map
index b263b98..8268c69 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,CE5Be,MAAA,EACb,OAAO,oBAAoB,CAAO,CAAE,CAClC,IAAI,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B,CAAC,UAAW,AAAA,IAC/B,CAAA,AAAU,WAAV,EAAE,GAAG,EAAiB,AAAU,MAAV,EAAE,GAAG,AAAK,GAClC,IAAI,CAAC,YAAY,EAErB,GAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,QAAS,AAAA,IACtC,IAAI,CAAC,YAAY,EACnB,EACF,CASA,KAAK,CAAK,CAAE,CACV,IAAI,CAAC,YAAY,CAAG,EAEpB,IAAM,EAAS,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,EAAI,IAAI,EAAO,EAChD,AAAC,CAAA,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,EACzB,CAAA,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,CAAG,CAD3B,EAIA,EAAO,IAAI,GACX,IAAI,CAAC,OAAO,CAAC,IAAI,EACnB,CAGA,MAAM,CAAK,CAAE,CACX,IAAI,CAAC,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/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.original = image;\n const rect = this.original.getBoundingClientRect();\n this.originalPosition = {\n top: rect.top + window.scrollY,\n left: rect.left + window.scrollX,\n width: rect.width,\n height: rect.height\n };\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 // style and position shadow image\n shadow.style.top = `${this.originalPosition.top}px`;\n shadow.style.left = `${this.originalPosition.left}px`;\n shadow.style.width = `${this.originalPosition.width}px`;\n shadow.style.height = `${this.originalPosition.height}px`;\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 this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).transformMatrix(this.element, this.originalPosition, (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).calculateFinalState(this.element));\n }\n close() {\n this.isOpen = false;\n this.original.style.visibility = 'visible';\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.style.cursor = 'zoom-in';\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 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.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.style.cursor = 'zoom-in';\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 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","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.original = image;\n\n const rect = this.original.getBoundingClientRect();\n this.originalPosition = {\n top: rect.top + window.scrollY,\n left: rect.left + window.scrollX,\n width: rect.width,\n height: rect.height\n }\n\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\n // style and position shadow image\n shadow.style.top = `${this.originalPosition.top}px`;\n shadow.style.left = `${this.originalPosition.left}px`;\n shadow.style.width = `${this.originalPosition.width}px`;\n shadow.style.height = `${this.originalPosition.height}px`;\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\n this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n\n Animation.transformMatrix(\n this.element,\n this.originalPosition,\n Animation.calculateFinalState(this.element)\n );\n }\n\n close() {\n this.isOpen = false;\n\n this.original.style.visibility = 'visible';\n\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","original","rect","getBoundingClientRect","originalPosition","create","shadow","src","open","visibility","contains","placeItself","close","setTimeout","destroyItself","removeChild","$e220af4964903f87$export$2e2bcd8739ae039","currentImage","shadows","selector","initOverlay","initImages","initControls","addEventListener","closeCurrent","images","querySelectorAll","forEach","tagName","crypto","randomUUID","cursor","e","key","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,CG5BA,IAAM,EAAS,CACb,SAAU,eACV,OAAQ,GACR,OAAQ,CAAE,EAAG,EAAG,EAAG,CAAE,CACvB,CDFe,OAAA,EACb,OAAO,oBAAoB,CAAO,CAAE,CAClC,IAAI,EAAS,CAAC,EAER,EAAS,ACoBJ,EDpBW,MAAM,CACtB,EAAK,EAAQ,YAAY,CACzB,EAAK,EAAQ,aAAa,CAC1B,EAAQ,EAAK,EACb,EAAK,OAAO,UAAU,CAAG,EAAE,EAC3B,EAAK,OAAO,WAAW,CAAG,EAAE,EAelC,OAZA,EAAO,KAAK,CAAK,EAAK,EAAM,EAAK,EACjC,EAAO,MAAM,CAAI,EAAK,EAAM,EAAK,EAAQ,EAGrC,EAAO,MAAM,CAAG,IAClB,EAAO,MAAM,CAAG,E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AgB,CAAC,AIL7B,EJKoC,QAAQ,EACvD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,AAAA,IACI,QAAlB,EAAM,OAAO,GACjB,EAAM,EAAE,CAAG,OAAO,UAAU,GAC5B,EAAM,KAAK,CAAC,MAAM,CAAG,UACrB,EAAM,gBAAgB,CAAC,QAAS,IAAM,IAAI,CAAC,IAAI,CAAC,IAClD,EACF,CAEA,cAAe,CAEb,SAAS,gBAAgB,CAAC,UAAW,AAAA,IAC/B,CAAA,AAAU,WAAV,EAAE,GAAG,EAAiB,AAAU,MAAV,EAAE,GAAG,AAAK,GAClC,IAAI,CAAC,YAAY,EAErB,GAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,QAAS,AAAA,IACtC,IAAI,CAAC,YAAY,EACnB,EACF,CASA,KAAK,CAAK,CAAE,CACV,IAAI,CAAC,YAAY,CAAG,EAEpB,IAAM,EAAS,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,EAAI,IAAI,EAAO,EAChD,AAAC,CAAA,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,EACzB,CAAA,IAAI,CAAC,OAAO,CAAC,EAAM,EAAE,CAAC,CAAG,CAD3B,EAIA,EAAO,IAAI,GACX,IAAI,CAAC,OAAO,CAAC,IAAI,EACnB,CAGA,MAAM,CAAK,CAAE,CACX,IAAI,CAAC,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/shadow.js","src/animation.js","src/config.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\nconst $0c04c0cc2b6985d8$var$config = {\n selector: '[data-libra]',\n margin: 50,\n offset: {\n x: 0,\n y: 0\n }\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 $6e8e6c64a3263339$export$2e2bcd8739ae039 {\n static calculateFinalState(element) {\n let finals = {};\n const margin = (0, $0c04c0cc2b6985d8$export$2e2bcd8739ae039).margin;\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 zIndex = '1000';\n isOpen = false;\n /**\n * ============\n * Constructors\n * ============\n */ constructor(image){\n this.original = image;\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 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 // style and position shadow image\n shadow.style.top = `${this.originalPosition.top}px`;\n shadow.style.left = `${this.originalPosition.left}px`;\n shadow.style.width = `${this.originalPosition.width}px`;\n shadow.style.height = `${this.originalPosition.height}px`;\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 this.element.classList.add('open');\n this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).transformMatrix(this.element, this.originalPosition, (0, $6e8e6c64a3263339$export$2e2bcd8739ae039).calculateFinalState(this.element));\n }\n close() {\n this.isOpen = false;\n this.element.classList.remove('open');\n this.original.style.visibility = 'visible';\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\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 = 'zoom-in';\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 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 = 'zoom-in';\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 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","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'\nimport config from './config'\n\nexport default class Shadow {\n zIndex = '1000'\n isOpen = false\n\n /**\n * ============\n * Constructors\n * ============\n */\n\n constructor(image) {\n this.original = image;\n\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 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\n // style and position shadow image\n shadow.style.top = `${this.originalPosition.top}px`;\n shadow.style.left = `${this.originalPosition.left}px`;\n shadow.style.width = `${this.originalPosition.width}px`;\n shadow.style.height = `${this.originalPosition.height}px`;\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 this.element.classList.add('open');\n\n this.original.style.visibility = 'hidden';\n if (!document.body.contains(this.element)) this.placeItself();\n\n Animation.transformMatrix(\n this.element,\n this.originalPosition,\n Animation.calculateFinalState(this.element)\n );\n }\n\n close() {\n this.isOpen = false;\n this.element.classList.remove('open');\n\n this.original.style.visibility = 'visible';\n\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","import config from './config';\n\nexport default class Animation {\n static calculateFinalState(element) {\n let finals = {}\n\n const margin = config.margin;\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","const config = {\n selector: '[data-libra]',\n margin: 50,\n offset: { x: 0, y: 0 }\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"],"names":["$e49d13fc7942bae1$export$2e2bcd8739ae039","zIndex","zIndexHidden","overlay","document","createElement","id","classList","add","style","opacity","element","body","appendChild","show","hide","$0c04c0cc2b6985d8$var$config","selector","margin","offset","x","y","$6e8e6c64a3263339$export$2e2bcd8739ae039","calculateFinalState","finals","nw","naturalWidth","nh","naturalHeight","ratio","ww","window","innerWidth","wh","innerHeight","width","height","top","scrollY","left","scrollX","transformMatrix","starts","scaleX","scaleY","startCenterX","startCenterY","finalCenterX","finalCenterY","transform","resetTransformMatrix","$2f427fc7e1c3703f$export$2e2bcd8739ae039","isOpen","image","original","rect","getBoundingClientRect","originalPosition","create","shadow","src","open","visibility","contains","placeItself","close","remove","setTimeout","destroyItself","removeChild","$e220af4964903f87$export$2e2bcd8739ae039","currentImage","shadows","config","$0c04c0cc2b6985d8$var$deepMerge","target","source","key","Array","isArray","initOverlay","initImages","initControls","addEventListener","closeCurrent","images","querySelectorAll","forEach","tagName","crypto","randomUUID","cursor","e","default"],"version":3,"file":"libra.min.js.map"} \ No newline at end of file