UNPKG

dgz-ui-shared

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library

3 lines (2 loc) 6.79 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),c=require("react"),S=require("dgz-ui/utils"),E=require("../../chunks/_commonjsHelpers-DKOUU3wS.cjs.js"),k=require("lucide-react");var N={exports:{}},A=N.exports,C;function L(){return C||(C=1,(function(l,y){(function(p,i){i()})(A,function(){function p(e,t){return typeof t>"u"?t={autoBom:!1}:typeof t!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\uFEFF",e],{type:e.type}):e}function i(e,t,d){var o=new XMLHttpRequest;o.open("GET",e),o.responseType="blob",o.onload=function(){f(o.response,t,d)},o.onerror=function(){console.error("could not download file")},o.send()}function h(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{t.send()}catch{}return 200<=t.status&&299>=t.status}function v(e){try{e.dispatchEvent(new MouseEvent("click"))}catch{var t=document.createEvent("MouseEvents");t.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var u=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof E.commonjsGlobal=="object"&&E.commonjsGlobal.global===E.commonjsGlobal?E.commonjsGlobal:void 0,s=u.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),f=u.saveAs||(typeof window!="object"||window!==u?function(){}:"download"in HTMLAnchorElement.prototype&&!s?function(e,t,d){var o=u.URL||u.webkitURL,a=document.createElement("a");t=t||e.name||"download",a.download=t,a.rel="noopener",typeof e=="string"?(a.href=e,a.origin===location.origin?v(a):h(a.href)?i(e,t,d):v(a,a.target="_blank")):(a.href=o.createObjectURL(e),setTimeout(function(){o.revokeObjectURL(a.href)},4e4),setTimeout(function(){v(a)},0))}:"msSaveOrOpenBlob"in navigator?function(e,t,d){if(t=t||e.name||"download",typeof e!="string")navigator.msSaveOrOpenBlob(p(e,d),t);else if(h(e))i(e,t,d);else{var o=document.createElement("a");o.href=e,o.target="_blank",setTimeout(function(){v(o)})}}:function(e,t,d,o){if(o=o||open("","_blank"),o&&(o.document.title=o.document.body.innerText="downloading..."),typeof e=="string")return i(e,t,d);var a=e.type==="application/octet-stream",j=/constructor/i.test(u.HTMLElement)||u.safari,w=/CriOS\/[\d]+/.test(navigator.userAgent);if((w||a&&j||s)&&typeof FileReader<"u"){var x=new FileReader;x.onloadend=function(){var r=x.result;r=w?r:r.replace(/^data:[^;]*;/,"data:attachment/file;"),o?o.location.href=r:location=r,o=null},x.readAsDataURL(e)}else{var b=u.URL||u.webkitURL,g=b.createObjectURL(e);o?o.location=g:location.href=g,o=null,setTimeout(function(){b.revokeObjectURL(g)},4e4)}});u.saveAs=f.saveAs=f,l.exports=f})})(N)),N.exports}var F=L();const M=()=>[{icon:n.jsx(k.Download,{size:20}),onClick:l=>{F.saveAs(l.src,l.title)},label:"Download"}],T=c.memo(({src:l,alt:y,fallbackImage:p})=>{const[i,h]=c.useState(!1),v=()=>{h(!0)};return n.jsx("img",{src:i&&p?p:l,alt:y,className:"max-h-full max-w-full object-contain",onError:v})}),O=c.memo(({image:l,index:y,onClick:p,fallbackImage:i,className:h,...v})=>{const[u,s]=c.useState(!1),f=()=>{s(!0)};return c.createElement("div",{...v,key:l.id,className:S.cn("aspect-video cursor-pointer overflow-hidden rounded-lg bg-gray-200 transition-opacity hover:opacity-80",h),onClick:()=>p(y)},n.jsx("img",{src:u&&i?i:l.thumbnail||l.src,alt:l.alt||`Image ${y+1}`,className:"h-full w-full object-cover",onError:f}))}),q=({images:l,thumbnailProps:y,actionButtons:p=[],fallbackImage:i,className:h,hasInfo:v,...u})=>{const[s,f]=c.useState(null),[e,t]=c.useState(!1),d=c.useMemo(()=>M(),[]),o=c.useMemo(()=>[...d,...p],[d,p]),a=c.useCallback(r=>{f(r),t(!0)},[]),j=c.useCallback(()=>{t(!1),f(null)},[]),w=c.useCallback(()=>{s!==null&&s>0&&f(s-1)},[s]),x=c.useCallback(()=>{s!==null&&s<l.length-1&&f(s+1)},[s,l.length]);c.useEffect(()=>{const r=m=>{if(e)switch(m.key){case"Escape":j();break;case"ArrowLeft":m.preventDefault(),w();break;case"ArrowRight":m.preventDefault(),x();break}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,w,x,j]),c.useEffect(()=>(e?document.body.style.overflow="hidden":document.body.style.overflow="unset",()=>{document.body.style.overflow="unset"}),[e]);const b=c.useMemo(()=>s!==null?l[s]:null,[s,l]),g=c.useMemo(()=>!e||!b?null:n.jsxs("div",{className:"bg-opacity-95 bg-bg fixed inset-0 z-50 flex flex-col items-center justify-center",children:[n.jsxs("div",{className:"absolute top-0 flex w-full items-start justify-between p-3",children:[n.jsx("div",{children:b.title&&n.jsx("h2",{className:"text-body-lg-semi-bold",children:b.title})}),n.jsxs("div",{className:"flex items-center gap-4 py-1",children:[o.map((r,m)=>n.jsx("button",{onClick:()=>r.onClick(b),className:"cursor-pointer",title:r.label,children:r.icon},m)),n.jsx("button",{onClick:j,className:"cursor-pointer",title:"Close (Esc)",children:n.jsx(k.X,{size:20})})]})]}),(s||0)>0&&n.jsx("button",{onClick:w,className:"bg-opacity-50 hover:bg-opacity-70 bg-bg text-secondary absolute top-1/2 left-2 z-50 -translate-y-1/2 rounded-full p-3 transition-all",title:"Previous (←)",children:n.jsx(k.ChevronLeft,{size:24})}),(s||0)<l.length-1&&n.jsx("button",{onClick:x,className:"bg-opacity-0 hover:bg-opacity-100 text-secondary bg-bg absolute top-1/2 right-2 z-50 -translate-y-1/2 rounded-full p-3 transition-all",title:"Next (→)",children:n.jsx(k.ChevronRight,{size:24})}),n.jsx("div",{className:"flex max-h-full max-w-full items-center justify-center overflow-hidden p-8",children:n.jsx(T,{src:b.src,alt:b.alt||`Image ${s}`,fallbackImage:i})}),n.jsx("div",{className:"bg-bg absolute bottom-0 w-full",children:n.jsx("div",{className:"flex gap-2 overflow-x-auto p-3",children:l.map((r,m)=>n.jsx("div",{className:S.cn("hover:border-item-primary h-16 min-w-16 shrink-0 cursor-pointer rounded border-3 border-transparent transition-all",m==s&&"border-item-primary"),onClick:()=>f(m),children:n.jsx("img",{src:r.thumbnail||r.src,alt:r.alt||`Thumbnail ${m+1}`,className:"size-full object-cover",onError:R=>{i&&(R.currentTarget.src=i)}})},r.id))})})]}),[e,i,b,o,j,s,w,l,x]);return n.jsxs("div",{className:"w-full",children:[n.jsx("div",{...u,className:S.cn("grid grid-cols-1 gap-4 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",h),children:l.map((r,m)=>n.jsxs("div",{className:"relative",children:[n.jsx(O,{...y,image:r,index:m,onClick:a,fallbackImage:i}),v&&r.title&&n.jsx("div",{className:"bg-bg/70 absolute bottom-0 flex min-h-10 w-full items-center justify-center text-center",children:r.title})]},r.id))}),g]})},D=c.memo(q);exports.MyGallery=D; //# sourceMappingURL=index.cjs.js.map