@xiping/react-components 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),v=require("@heroui/modal"),O=require("@heroui/spinner"),x=require("react-icons/io5"),z=require("../pinch-content/PinchContent.js"),o=require("motion/react"),u=require("react"),D=require("clsx"),$=n=>{n.target.closest(".image-viewer-main-content")&&n.preventDefault()},j="0%",U="100%",y="20%",g="80%",i="#0000",s="#000";function P(n){const t=o.useMotionValue(`linear-gradient(90deg, ${s}, ${s} ${j}, ${s} ${g}, ${i})`);return o.useMotionValueEvent(n,"change",c=>{c===0?o.animate(t,`linear-gradient(90deg, ${s}, ${s} ${j}, ${s} ${g}, ${i})`):c===1?o.animate(t,`linear-gradient(90deg, ${i}, ${s} ${y}, ${s} ${U}, ${s})`):(n.getPrevious()===0||n.getPrevious()===1)&&o.animate(t,`linear-gradient(90deg, ${i}, ${s} ${y}, ${s} ${g}, ${i})`)}),t}const V=n=>{const{isOpen:t,onClose:c,imgSrc:m,canDownload:C=!1,wrapperClassName:N}=n,d=Array.isArray(m)?m:[m],[f,k]=u.useState(0),[I,h]=u.useState(!0),p=u.useRef(null),b=()=>{h(!0),c()},S=async()=>{const a=d[f];try{const M=await(await fetch(a)).blob(),w=window.URL.createObjectURL(M),l=document.createElement("a");l.href=w,l.download=a.split("/").pop()||"image",document.body.appendChild(l),l.click(),window.URL.revokeObjectURL(w),document.body.removeChild(l)}catch(r){console.error("Error downloading image:",r)}},q=()=>{h(!1)},E=()=>{h(!1)};u.useEffect(()=>{if(t)return document.addEventListener("touchmove",$,{passive:!1}),()=>{document.removeEventListener("touchmove",$)}},[t]);const{scrollXProgress:L}=o.useScroll({container:p}),R=P(L);return e.jsx(v.Modal,{isOpen:t,size:"full",onClose:b,classNames:{wrapper:D("",N)},className:"bg-black bg-opacity-70",hideCloseButton:!0,portalContainer:document.body,children:e.jsx(v.ModalContent,{className:"overflow-hidden",children:e.jsxs("div",{className:"w-screen h-screen relative flex flex-col pt-safe-offset-0",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-4 z-10",children:[C&&e.jsx(x.IoDownloadOutline,{size:24,className:"text-white cursor-pointer",onClick:S}),e.jsx(x.IoCloseSharp,{size:24,className:"text-white cursor-pointer",onClick:b})]}),e.jsxs("div",{className:"flex-1 min-h-0 relative flex items-center justify-center image-viewer-main-content",children:[e.jsx(z.default,{canRotate:!1,className:"w-full h-full",children:e.jsx("img",{draggable:"false",src:d[f],alt:"",className:"w-screen h-full object-contain pointer-events-none",onLoad:q,onError:E})}),I&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black bg-opacity-50",children:e.jsx(O.Spinner,{color:"white",size:"lg"})})]}),d.length>1&&e.jsx("div",{className:"h-24 bg-black bg-opacity-50 shrink-0 z-10 pb-safe-offset-0 pl-safe-offset-0 pr-safe-offset-0",children:e.jsx(o.motion.div,{ref:p,style:{maskImage:R,WebkitOverflowScrolling:"touch",scrollbarWidth:"none",msOverflowStyle:"none"},className:"h-24 w-screen overflow-x-auto overflow-y-hidden scrollbar-hide",children:e.jsx("div",{className:"flex gap-2 p-2 h-24 min-w-max",children:d.map((a,r)=>e.jsx("div",{className:`h-full aspect-square flex-shrink-0 cursor-pointer border-2 transition-all ${r===f?"border-white":"border-transparent"}`,onClick:()=>k(r),children:e.jsx("img",{src:a,alt:"",className:"w-full h-full object-contain",draggable:"false"})},a))})})})]})})})},_=`
|
|
2
|
+
.scrollbar-hide {
|
|
3
|
+
-ms-overflow-style: none;
|
|
4
|
+
scrollbar-width: none;
|
|
5
|
+
}
|
|
6
|
+
.scrollbar-hide::-webkit-scrollbar {
|
|
7
|
+
display: none;
|
|
8
|
+
}
|
|
9
|
+
`;if(typeof document<"u"){const n="image-viewer-scrollbar-hide";if(!document.getElementById(n)){const t=document.createElement("style");t.id=n,t.textContent=_,document.head.appendChild(t)}}exports.default=V;
|