react-motion-gallery 2.0.69 → 2.0.71
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.
- package/README.md +2 -2
- package/dist/chunk-HLFWK42L.mjs +1 -0
- package/dist/chunk-WUB37KRW.mjs +4 -0
- package/dist/fullscreen-zoom-pan.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/zoomPan.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-7WKLGKCT.mjs +0 -1
- package/dist/chunk-GS2GLLIJ.mjs +0 -4
package/dist/zoomPan.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as ZoomPanImage,a as default}from'./chunk-
|
|
1
|
+
export{a as ZoomPanImage,a as default}from'./chunk-HLFWK42L.mjs';import'./chunk-WUB37KRW.mjs';import'./chunk-ADIHG7AT.mjs';import'./chunk-JJMFOLJZ.mjs';import'./chunk-P2GQPFSL.mjs';import'./chunk-HGY3QLCE.mjs';import'./chunk-AKY343WN.mjs';import'./chunk-UAEPMZQY.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-motion-gallery",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.71",
|
|
4
4
|
"description": "Composable React media gallery primitives for sliders, grids, masonry, fullscreen, video, zoom/pan, and stable skeleton loading",
|
|
5
5
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
6
|
"author": "React Motion Gallery",
|
package/dist/chunk-7WKLGKCT.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {k,h,g,j,a as a$2,i as i$1,f,e as e$1,l,m,n,o,d,c as c$1,b as b$3}from'./chunk-GS2GLLIJ.mjs';import {a as a$1}from'./chunk-ADIHG7AT.mjs';import {a}from'./chunk-JJMFOLJZ.mjs';import {b as b$2}from'./chunk-P2GQPFSL.mjs';import {e,c,b as b$1}from'./chunk-HGY3QLCE.mjs';import {b}from'./chunk-AKY343WN.mjs';import*as t from'react';import {jsx}from'react/jsx-runtime';var we=3,Rt="[data-rmg-slider-core-scope]";function pt(...p){return p.filter(Boolean).join(" ")}function i(p){return p>1.01}function dt(){let p=new Set;return {publishZoomIn(I){p.forEach(D=>D(I));},subscribeZoomIn(I){return p.add(I),()=>{p.delete(I);}}}}var ze=t.forwardRef(function(I,D){let{className:Be,style:Ve,imageClassName:_e,imageStyle:je,zoom:ie,disabled:o$1=false,onDragStart:fe,src:H,...Ne}=I,l$1=t.useMemo(()=>({...a,...ie??{}}),[ie]),m$1=t.useMemo(()=>k(l$1),[l$1]),Y=t.useMemo(()=>({zoom:l$1}),[l$1]),C=b(),r=t.useRef(null),me=t.useRef([]);me.current=[r];let a$3=t.useRef(1),Re=t.useRef({x:0,y:0}),pe=t.useRef({x:0,y:0}),We=t.useRef(false),B=t.useRef(false),X=t.useRef(false),c$2=t.useRef(null),Ke=t.useRef(false),Ue=t.useRef("idle"),de=t.useRef(null),V=t.useRef(null),_=t.useRef(null),j$1=t.useRef(null),N=t.useRef(null),M=t.useRef(null),S=t.useRef(null),Z=t.useRef(null),L=t.useRef(null),E=t.useRef(null),T=t.useRef(null),A=t.useRef(null),O=t.useRef(null),F=t.useRef(null),W=t.useRef(false),be=t.useRef(0),ye=t.useRef(1),Pe=t.useRef(false),R=t.useRef(false),v=t.useRef(null),K=t.useRef({active:false,pointerId:null,lastX:0,lastY:0,totalAbsDx:0,totalAbsDy:0}),[$e,qe]=t.useState(1),U=t.useCallback(e=>{a$3.current=e,qe(e);},[]),d$1=i($e),b$4=typeof C?.normIdx=="number"?C.normIdx:null,x=C?.indexChannel,w=t.useMemo(()=>C?.storeBag?C.storeBag.getOrCreate("rmg-zoom-pan-layout-sync",dt):null,[C?.storeBag]),he=t.useRef(false),Ge=t.useCallback(e=>{if(r.current=e,c$2.current=e,!!D){if(typeof D=="function"){D(e);return}D.current=e;}},[D]),y=t.useCallback((e,n,s,f,ne)=>h({scale:e,imgW:n,imgH:s,currentImageEl:c$2.current,viewW:f,viewH:ne}),[]),J=t.useCallback((e,n)=>{let s=c$2.current,f=a$1(s);f&&(f.style.transition&&(f.style.transition=""),f.style.transform=`translate3d(${e}px, ${n}px, 0) scale(${a$3.current})`);},[]),Q=t.useCallback(()=>{c$2.current=r.current,g({fs:Y,currentImage:c$2,scaleRef:a$3,locX:V,prevX:j$1,offX:M,tgtX:Z,locY:_,prevY:N,offY:S,tgtY:L,bodyX:E,bodyY:T,boundsX:A,boundsY:O,Vector1D:b$1,ScrollBody:c,ScrollBounds:e,boundsForCurrent:y});},[y,Y]),$=t.useCallback(()=>{F.current?.stop(),E.current?.useDuration(0).useFriction(1).sync(),T.current?.useDuration(0).useFriction(1).sync();},[]),ge=t.useCallback(()=>{c$2.current=r.current,j({currentImage:c$2,locX:V,prevX:j$1,offX:M,tgtX:Z,locY:_,prevY:N,offY:S,tgtY:L,bodyX:E,bodyY:T,boundsX:A,boundsY:O,ScrollBody:c,ScrollBounds:e,baseFitSize:a$2,boundsForCurrent:y,panDuration:l$1.panDuration,panFriction:l$1.panFriction,animRef:F});},[y,l$1.panDuration,l$1.panFriction]),P=t.useCallback((e="transform 0.2s cubic-bezier(.4,0,.22,1)")=>{c$2.current=r.current,$(),i$1({setScale:U,zoomState:{previousZoom:pe,panRef:Re,scaleRef:a$3},imageRefs:me,resetPan:ge,transition:e});},[ge,U,$]),u=t.useMemo(()=>({fs:Y,currentImage:c$2,scaleRef:a$3,setScale:U,previousZoom:pe,suppressLoopRef:We,locX:V,prevX:j$1,offX:M,tgtX:Z,locY:_,prevY:N,offY:S,tgtY:L,bodyX:E,bodyY:T,boundsX:A,boundsY:O,Vector1D:b$1,ScrollBody:c,ScrollBounds:e,boundsForCurrent:y,renderPan:J,animRef:F,panRef:Re,resetAllZoomDom:$}),[y,Y,J,U,$]),Je=f({fs:Y,isZoomed:d$1,zoomCtx:u,currentImage:c$2,rebuildPanBodies:Q,renderPan:J,handleZoomToggle:e$1,suppressNextClickRef:B,pointerDownRef:Ke,interactionModeRef:Ue,boundsX:A,boundsY:O,bodyX:E,bodyY:T,locX:V,locY:_,prevX:j$1,prevY:N,offX:M,offY:S,tgtX:Z,tgtY:L,axisRef:de,animRef:F});t.useEffect(()=>{de.current=b$2();},[]),t.useLayoutEffect(()=>{c$2.current=r.current,Pe.current=!!r.current?.closest(Rt);});let h$1=t.useCallback(()=>{K.current={active:false,pointerId:null,lastX:0,lastY:0,totalAbsDx:0,totalAbsDy:0};},[]),g$1=t.useCallback(()=>{R.current=false,v.current=null;},[]),Qe=t.useCallback(e=>{o$1||!m$1||!l(e)||i(a$3.current)||!r.current||!m(u,{imageRef:r,clientX:e.clientX,clientY:e.clientY,hover:m$1})||(R.current=true,v.current=e.pointerId??null,h$1());},[o$1,m$1,h$1,u]),et=t.useCallback(e=>{if(!(o$1||!m$1)&&l(e)){if(!R.current){if(i(a$3.current)||!r.current||!m(u,{imageRef:r,clientX:e.clientX,clientY:e.clientY,hover:m$1}))return;R.current=true,v.current=e.pointerId??null,h$1();return}v.current!=null&&e.pointerId!==v.current||n(u,{imageRef:r,clientX:e.clientX,clientY:e.clientY});}},[o$1,m$1,h$1,u]),De=t.useCallback(e=>{!m$1||!R.current||l(e)&&(v.current!=null&&e.pointerId!==v.current||(g$1(),o(u,{imageRef:r,durationMs:m$1.zoomOutDurationMs})));},[m$1,g$1,u]),tt=t.useCallback(e=>{o$1||i(a$3.current)||e.button!==void 0&&e.button!==0||(X.current=false,K.current={active:true,pointerId:e.pointerId,lastX:e.clientX,lastY:e.clientY,totalAbsDx:0,totalAbsDy:0});},[o$1]),nt=t.useCallback(e=>{if(o$1||i(a$3.current))return;let n=K.current;if(!n.active||n.pointerId!==e.pointerId)return;let s=e.clientX-n.lastX,f=e.clientY-n.lastY;n.lastX=e.clientX,n.lastY=e.clientY,n.totalAbsDx+=Math.abs(s),n.totalAbsDy+=Math.abs(f),(n.totalAbsDx>we||n.totalAbsDy>we)&&(X.current=true);},[o$1]),ee=t.useCallback(e=>{if(o$1||i(a$3.current))return;let n=K.current;!n.active||n.pointerId!==e.pointerId||h$1();},[o$1,h$1]),rt=t.useCallback(e=>{if(R.current){e.preventDefault(),e.stopPropagation();return}(B.current||X.current)&&(B.current=false,X.current=false,e.preventDefault(),e.stopPropagation());},[]),ot=t.useCallback(e=>{if(!e.defaultPrevented){if(R.current){e.preventDefault(),e.stopPropagation();return}o$1||d$1||W.current||(c$2.current=r.current,e$1(u,e,r));}},[o$1,d$1,u]),te=t.useCallback(e$1=>{if(o$1||!r.current)return;if(c$2.current=r.current,e$1.ctrlKey){e$1.cancelable&&e$1.preventDefault(),e$1.stopPropagation();let Ce=e$1.deltaY;e$1.deltaMode===1&&(Ce*=15);let mt=a$3.current*(1-Ce/100);d(u,{destZoomLevel:mt,centerPoint:{x:e$1.clientX,y:e$1.clientY},imageRef:r});return}if(!i(a$3.current))return;e$1.cancelable&&e$1.preventDefault(),e$1.stopPropagation(),Q();let n=a$1(r.current);if(!n)return;let s=r.current.getBoundingClientRect(),{baseW:f,baseH:ne}=a$2(n,s.width,s.height),{x:ve,y:Ie,povX:st,povY:lt}=y(a$3.current,f,ne,s.width,s.height);A.current=e(ve,M.current,Z.current,E.current,st,l$1.panDuration),O.current=e(Ie,S.current,L.current,T.current,lt,l$1.panDuration);let it=ve.constrain((M.current?.get()??0)-e$1.deltaX),ft=Ie.constrain((S.current?.get()??0)-e$1.deltaY);Z.current?.set(it),L.current?.set(ft),E.current?.useDuration(0).useFriction(1),T.current?.useDuration(0).useFriction(1),F.current?.start();},[y,o$1,Q,l$1.panDuration,u]);t.useEffect(()=>{let e=r.current;if(e)return e.addEventListener("wheel",te,{passive:false}),()=>{e.removeEventListener("wheel",te);}},[te]),t.useEffect(()=>{let e=r.current;if(!e)return;let n=s=>{o$1||Pe.current&&i(a$3.current)&&s.stopPropagation();};return e.addEventListener("mousedown",n,{capture:true}),e.addEventListener("touchstart",n,{capture:true,passive:false}),()=>{e.removeEventListener("mousedown",n,true),e.removeEventListener("touchstart",n,true);}},[o$1]);let at=t.useCallback(e=>{o$1||e.touches.length!==2||(e.preventDefault(),h$1(),X.current=false,W.current=true,be.current=c$1(e.touches[0],e.touches[1]),ye.current=a$3.current);},[o$1,h$1]),ct=t.useCallback(e=>{if(o$1||!W.current||e.touches.length!==2||!r.current)return;e.preventDefault(),c$2.current=r.current;let n=ye.current*(c$1(e.touches[0],e.touches[1])/be.current),s=b$3(e.touches[0],e.touches[1]);d(u,{destZoomLevel:n,centerPoint:s,imageRef:r});},[o$1,u]),Ee=t.useCallback(()=>{W.current=false;},[]);t.useEffect(()=>{o$1&&i(a$3.current)&&(g$1(),P());},[o$1,g$1,P]),t.useEffect(()=>{if(x)return x.onBasePointerDown(()=>{i(a$3.current)&&P();})},[P,x]),t.useEffect(()=>{if(w&&b$4!=null)return w.subscribeZoomIn(e=>{e!==b$4&&i(a$3.current)&&P();})},[b$4,w,P]),t.useEffect(()=>{let e=he.current;if(he.current=d$1,e||!d$1||b$4==null)return;w?.publishZoomIn(b$4);let n=x?.get().index;n==null||n===b$4||x?.set(b$4,"animated",{meta:{source:"external"}});},[d$1,b$4,w,x]);let Te=t.useRef(H);t.useEffect(()=>{Te.current!==H&&(Te.current=H,g$1(),P("none"));},[g$1,P,H]),t.useEffect(()=>()=>{let e=r.current,n=a$1(e);n&&(n.style.transition="",n.style.transform="translate(0, 0) scale(1)"),a$3.current=1,g$1();},[g$1]);let ut=t.useCallback(e=>{e.preventDefault(),fe?.(e);},[fe]);return jsx("div",{ref:Ge,className:Be,"data-rmg-zoom-pan-root":"true","data-rmg-fs-media":"true","data-rmg-fs-media-viewport":"true",onClickCapture:rt,onClick:ot,onPointerEnter:Qe,onPointerDown:e=>{if(R.current&&l(e)){B.current=true,e.preventDefault(),e.stopPropagation();return}tt(e),!o$1&&Je.handlePanPointerStart(e,r);},onPointerMove:e=>{et(e),!R.current&&nt(e);},onPointerLeave:e=>{De(e),ee(e);},onPointerUp:ee,onPointerCancel:e=>{De(e),ee(e);},onTouchStart:at,onTouchMove:ct,onTouchEnd:Ee,onTouchCancel:Ee,style:{position:"relative",overflow:"hidden",minWidth:0,minHeight:0,touchAction:o$1?"auto":d$1?"none":"pan-y",...Ve},children:jsx("div",{"data-rmg-zoom-pan-stage":"true",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"100%",minWidth:0},children:jsx("img",{...Ne,ref:e=>{e&&!e.style.transform&&(e.style.transform="translate(0, 0) scale(1)");},src:H,className:pt(_e),"data-rmg-zoom-pan-image":"true",draggable:false,onDragStart:ut,style:{display:"block",maxWidth:"100%",maxHeight:"100%",objectFit:"contain",transformOrigin:"0 0",touchAction:"manipulation",userSelect:"none",cursor:o$1?"default":d$1?"grab":"zoom-in",...je}})})})});export{ze as a};
|
package/dist/chunk-GS2GLLIJ.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import {a,c,h,e,b}from'./chunk-ADIHG7AT.mjs';import {f,d,g as g$1,h as h$1,a as a$1}from'./chunk-HGY3QLCE.mjs';import {g}from'./chunk-UAEPMZQY.mjs';import*as S from'react';function W(e){if(!e)return {x:0,y:0};let n=window.getComputedStyle(e).transform;if(!n||n==="none")return {x:0,y:0};let o=n.match(/matrix\(([^)]+)\)/);if(!o)return {x:0,y:0};let t=o[1].split(",").map(parseFloat),s=t[4]||0,c=t[5]||0;return {x:s,y:c}}function j(e,r,n){let o=e.naturalWidth||e.width||r,t=e.naturalHeight||e.height||n,s=Math.min(r/o,n/t);return {baseW:o*s,baseH:t*s}}function A(e,r,n){return Math.max(r,Math.min(n,e))}function Ie(e,r){return r?{x:(e.clientX+r.clientX)/2,y:(e.clientY+r.clientY)/2}:{x:e.clientX,y:e.clientY}}function Ae(e,r){let n=e.clientX-r.clientX,o=e.clientY-r.clientY;return Math.hypot(n,o)}var ne=new WeakMap;function He(e){let r=typeof window<"u"&&typeof window.getComputedStyle=="function"?window.getComputedStyle(e).transform:"";return r&&r!=="none"?r:e.style.transform||"translate3d(0px, 0px, 0) scale(1)"}function te(e,r,n,o,t=300){let s=e.currentImage.current;if(!s)return;let c=b(s);if(!c.length)return;let a=`transform ${t}ms cubic-bezier(.4,0,.22,1)`,m=`translate3d(${r}px, ${n}px, 0) scale(${o})`;c.forEach(u=>{let i=ne.get(u);i!=null&&window.clearTimeout(i);let f=He(u);u.style.transition="",u.style.transform=f,u.offsetWidth,u.style.transition=a,u.style.transform=m;let d=window.setTimeout(()=>{ne.get(u)===d&&(u.style.transition="",ne.delete(u));},t+30);ne.set(u,d);}),e.offX.current?.set(r),e.offY.current?.set(n),e.locX.current?.set(r),e.locY.current?.set(n),e.prevX.current?.set(r),e.prevY.current?.set(n),e.tgtX.current?.set(r),e.tgtY.current?.set(n),e.scaleRef.current=o,e.setScale(o);}function Ne(e,r){let{destZoomLevel:n,centerPoint:o,imageRef:t}=r;if(!t.current)return;e.currentImage.current=t.current;let s=e.currentImage.current,c$1=a(s);if(!c$1)return;let a$1=c(s)??s,m=a$1.getBoundingClientRect();if(h({width:m.width,height:m.height},c$1))return;let{x:u,y:i}=W(c$1);(!e.locX.current||!e.locY.current)&&(e.locX.current=e.Vector1D(u),e.prevX.current=e.Vector1D(u),e.offX.current=e.Vector1D(u),e.tgtX.current=e.Vector1D(u),e.locY.current=e.Vector1D(i),e.prevY.current=e.Vector1D(i),e.offY.current=e.Vector1D(i),e.tgtY.current=e.Vector1D(i),e.bodyX.current=e.ScrollBody(e.locX.current,e.offX.current,e.prevX.current,e.tgtX.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync(),e.bodyY.current=e.ScrollBody(e.locY.current,e.offY.current,e.prevY.current,e.tgtY.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync());let f=e.scaleRef.current||1,d=A(n,1,e.fs.zoom.maxZoomLevel),g=1.01;if(d===f){let z=e.offX.current?.get()??u,C=e.offY.current?.get()??i,O=Math.abs(z)<.5&&Math.abs(C)<.5;if(d>g||O)return}let R=f>g,v=d>g;!R&&v?e.suppressLoopRef.current=true:R&&!v&&(e.suppressLoopRef.current=false);let Y=a$1.getBoundingClientRect(),h$1=Y.width,X=Y.height,E=o.x-Y.left,H=o.y-Y.top,{baseW:y,baseH:M}=j(c$1,h$1,X),T=(h$1-y)/2,F=(X-M)/2,L=e.offX.current.get(),k=e.offY.current.get(),D=d/f,p=L+(1-D)*(E-T-L),l=k+(1-D)*(H-F-k),{x:P,y:w,povX:B,povY:V}=e.boundsForCurrent(d,y,M,h$1,X,{ignoreReserved:true});if(p=P.constrain(p),l=w.constrain(l),e.scaleRef.current=d,e.setScale(d),e.previousZoom.current.x=E,e.previousZoom.current.y=H,!v){p=P.constrain(0),l=w.constrain(0),e.boundsX.current=e.ScrollBounds(P,e.offX.current,e.tgtX.current,e.bodyX.current,B,e.fs.zoom.panDuration),e.boundsY.current=e.ScrollBounds(w,e.offY.current,e.tgtY.current,e.bodyY.current,V,e.fs.zoom.panDuration),e.tgtX.current.set(p),e.tgtY.current.set(l),e.bodyX.current?.resetVelocity?.(),e.bodyX.current?.useBaseDuration?.(),e.bodyX.current?.useBaseFriction?.(),e.bodyY.current?.resetVelocity?.(),e.bodyY.current?.useBaseDuration?.(),e.bodyY.current?.useBaseFriction?.(),e.animRef.current?.resetBlend(),e.animRef.current?.start();return}e.tgtX.current.set(p),e.locX.current.set(p),e.prevX.current.set(p),e.offX.current.set(p),e.tgtY.current.set(l),e.locY.current.set(l),e.prevY.current.set(l),e.offY.current.set(l),e.boundsX.current=e.ScrollBounds(P,e.offX.current,e.tgtX.current,e.bodyX.current,B,e.fs.zoom.panDuration),e.boundsY.current=e.ScrollBounds(w,e.offY.current,e.tgtY.current,e.bodyY.current,V,e.fs.zoom.panDuration),e.bodyX.current?.useDuration(0).useFriction(1),e.bodyY.current?.useDuration(0).useFriction(1),e.renderPan(p,l),e.animRef.current?.start();}function qe(e$1,r,n){if(!n.current)return;e$1.currentImage.current=n.current;let o=e$1.currentImage.current;if(!o)return;let t=a(o);if(!t)return;let s=c(o)??o,c$1=s.getBoundingClientRect();if(h({width:c$1.width,height:c$1.height},t))return;let{x:a$1,y:m}=W(t);(!e$1.locX.current||!e$1.locY.current)&&(e$1.locX.current=e$1.Vector1D(a$1),e$1.prevX.current=e$1.Vector1D(a$1),e$1.offX.current=e$1.Vector1D(a$1),e$1.tgtX.current=e$1.Vector1D(a$1),e$1.locY.current=e$1.Vector1D(m),e$1.prevY.current=e$1.Vector1D(m),e$1.offY.current=e$1.Vector1D(m),e$1.tgtY.current=e$1.Vector1D(m),e$1.bodyX.current=e$1.ScrollBody(e$1.locX.current,e$1.offX.current,e$1.prevX.current,e$1.tgtX.current,e$1.fs.zoom.panDuration,e$1.fs.zoom.panFriction).sync(),e$1.bodyY.current=e$1.ScrollBody(e$1.locY.current,e$1.offY.current,e$1.prevY.current,e$1.tgtY.current,e$1.fs.zoom.panDuration,e$1.fs.zoom.panFriction).sync());let u=e$1.scaleRef.current||1,i=u===1,f=i?e$1.fs.zoom.clickZoomLevel:1,d=1.01,g=u>d,R=f>d;g&&!R&&(e$1.suppressLoopRef.current=false,e$1.resetAllZoomDom());let v=s.getBoundingClientRect(),Y=v.width,h$1=v.height,{clientX:X,clientY:E}=e(r),H=X-v.left,y=E-v.top,{baseW:M,baseH:T}=j(t,Y,h$1),F=(Y-M)/2,L=(h$1-T)/2,k=e$1.offX.current.get(),D=e$1.offY.current.get(),p,l;if(i){let C=f/u;p=k+(1-C)*(H-F-k),l=D+(1-C)*(y-L-D);let{x:O,y:$}=e$1.boundsForCurrent(f,M,T,Y,h$1);p=O.constrain(p),l=$.constrain(l);}else p=0,l=0;te(e$1,p,l,f,300),e$1.scaleRef.current=f,e$1.setScale(f),e$1.previousZoom.current.x=H,e$1.previousZoom.current.y=y,e$1.panRef.current={x:p,y:l},e$1.locX.current.set(p),e$1.prevX.current.set(p),e$1.offX.current.set(p),e$1.tgtX.current.set(p),e$1.locY.current.set(l),e$1.prevY.current.set(l),e$1.offY.current.set(l),e$1.tgtY.current.set(l),e$1.bodyX.current=e$1.ScrollBody(e$1.locX.current,e$1.offX.current,e$1.prevX.current,e$1.tgtX.current,e$1.fs.zoom.panDuration,e$1.fs.zoom.panFriction).sync(),e$1.bodyY.current=e$1.ScrollBody(e$1.locY.current,e$1.offY.current,e$1.prevY.current,e$1.tgtY.current,e$1.fs.zoom.panDuration,e$1.fs.zoom.panFriction).sync();let{x:w,y:B,povX:V,povY:z}=e$1.boundsForCurrent(f,M,T,Y,h$1);e$1.boundsX.current=e$1.ScrollBounds(w,e$1.offX.current,e$1.tgtX.current,e$1.bodyX.current,V,e$1.fs.zoom.panDuration),e$1.boundsY.current=e$1.ScrollBounds(B,e$1.offY.current,e$1.tgtY.current,e$1.bodyY.current,z,e$1.fs.zoom.panDuration),e$1.tgtX.current.set(w.constrain(e$1.tgtX.current.get())),e$1.tgtY.current.set(B.constrain(e$1.tgtY.current.get())),e$1.animRef.current?.resetBlend();}function de(e){S.useEffect(()=>{let r=h$1(document,window,()=>{e.boundsX.current?.constrain(e.pointerDownRef.current),e.boundsY.current?.constrain(e.pointerDownRef.current),e.bodyX.current?.seek(),e.bodyY.current?.seek();},n=>{let o=e.locX.current,t=e.locY.current,s=e.prevX.current,c=e.prevY.current;if(!o||!t||!s||!c)return;let a=o.get()*n+s.get()*(1-n),m=t.get()*n+c.get()*(1-n);e.offX.current?.set(a),e.offY.current?.set(m),e.renderPan(a,m);let u=!!e.bodyX.current?.settled()&&!!e.bodyY.current?.settled(),i=!e.boundsX.current?.reached?.()&&!e.boundsY.current?.reached?.();u&&i&&!e.pointerDownRef.current&&e.animRef.current?.stop();});return e.animRef.current=r,r.init(),()=>{r.destroy(),e.animRef.current=null;}},[]);}function Pe(){return {scroll:"x",cross:"y",direction(e){return e},measureSize(e){return e.width}}}function ye(e,r){return typeof r.MouseEvent<"u"&&e instanceof r.MouseEvent}function Se(e,r){return a$1({ownerWindow:r,axis:e})}var N="data-rmg-pan-drag",be="rmg-zoom-pan-drag-style";function ge(e){let r=S.useMemo(()=>({mouse:400,touch:400}),[]),n=S.useRef(null),o=S.useRef(g$1()).current,t=S.useRef(g$1()).current,s=S.useCallback((u,i)=>u*(i?r.mouse:r.touch),[r]);function c(){if(document.getElementById(be))return;let u=document.createElement("style");u.id=be,u.textContent=`
|
|
2
|
-
[data-rmg-zoom-pan-root="true"][${N}] { cursor: grabbing !important; }
|
|
3
|
-
[data-rmg-zoom-pan-root="true"][${N}] * { cursor: grabbing !important; }
|
|
4
|
-
`,document.head.appendChild(u);}S.useEffect(()=>{c();},[]);let a$1=S.useCallback(u=>{let i=e.currentImage.current;if(i){if(u){i.hasAttribute(N)||i.setAttribute(N,"");return}i.hasAttribute(N)&&i.removeAttribute(N);}},[e.currentImage]),m=S.useCallback((u,i)=>{if(!e.isZoomed||!i.current)return;e.currentImage.current=i.current,e.rebuildPanBodies();let f=window,d=e.axisRef.current||Pe();n.current=Se(d,f);let g=u.button!==void 0,R=g?u.button===0:false;if(g&&!R)return;e.pointerDownRef.current=true,e.interactionModeRef.current="drag",a$1(true);let v=()=>{e.pointerDownRef.current=false,e.interactionModeRef.current="idle",t.clear(),a$1(false);};e.tgtX.current?.set(e.locX.current?.get?.()??0),e.tgtY.current?.set(e.locY.current?.get?.()??0);let Y=3,h=220,X=.075,E=0,H=0,y=false,M=performance.now(),T=u.nativeEvent;n.current.pointerDown(T);let F=p=>{if(!ye(p,window)&&p.touches?.length>=2)return y=true,v(),L(p);let l=n.current.pointerMove(p);E+=Math.abs(l.dx),H+=Math.abs(l.dy),e.bodyX.current?.useFriction(.3).useDuration(.75),e.bodyY.current?.useFriction(.3).useDuration(.75),e.tgtX.current?.add(l.dx),e.tgtY.current?.add(l.dy),e.animRef.current?.start(),"cancelable"in p&&p.cancelable&&p.preventDefault?.();},L=p=>{let l=n.current.pointerUp(p),P=ye(p,window),w=performance.now()-M,B=E<=Y&&H<=Y,V=Math.abs(l.fx)<=X&&Math.abs(l.fy)<=X,z=!y&&B&&V&&w<=h;if(e.pointerDownRef.current=false,e.interactionModeRef.current="idle",t.clear(),v(),z){let oe=e.currentImage.current,I=a(oe);if(I){let _=p,De=_?.touches?.[0]?.clientX??_?.changedTouches?.[0]?.clientX??_?.clientX??T?.clientX,Me=_?.touches?.[0]?.clientY??_?.changedTouches?.[0]?.clientY??_?.clientY??T?.clientY,we={target:I,currentTarget:I,clientX:De,clientY:Me,nativeEvent:_??T};e.handleZoomToggle(e.zoomCtx,we,e.currentImage),e.suppressNextClickRef.current=true;let ae=p;ae?.preventDefault?.(),ae?.stopPropagation?.(),e.animRef.current?.stop();return}e.animRef.current?.stop();return}let C=s(l.fx,P),O=s(l.fy,P),$=Math.min(1,Math.abs(l.fx)>0?Math.abs((Math.abs(C)-Math.abs(l.fx))/(l.fx||1)):0),x=Math.min(1,Math.abs(l.fy)>0?Math.abs((Math.abs(O)-Math.abs(l.fy))/(l.fy||1)):0),K=e.fs.zoom.panDuration,q=e.fs.zoom.panDuration,J=e.fs.zoom.panFriction+$/50,Q=e.fs.zoom.panFriction+x/50;e.bodyX.current?.useDuration(K).useFriction(J),e.bodyY.current?.useDuration(q).useFriction(Q),e.tgtX.current?.add(C),e.tgtY.current?.add(O),e.animRef.current?.start();},D=u.nativeEvent instanceof MouseEvent?document:window;t.add(D,"touchmove",F,{passive:false}).add(D,"touchend",L).add(D,"mousemove",F,{passive:false}).add(D,"mouseup",L),o.add(window,"touchcancel",L).add(window,"contextmenu",L);},[e,o,t,s,a$1]);return S.useEffect(()=>()=>{t.clear(),o.clear(),e.currentImage.current?.removeAttribute(N),document.documentElement.classList.remove("rmg-pan-grabbing");},[e.currentImage,t,o]),{handlePanPointerStart:m}}function sr(e){return de(e),ge(e)}function mr(e){if(!e.currentImage.current)return;let r=e.currentImage.current,n=a(r);if(!n)return;let o=c(r)?.getBoundingClientRect()??r.getBoundingClientRect(),t=o.width,s=o.height,{baseW:c$1,baseH:a$1}=j(n,t,s),{x:m,y:u}=W(n);e.locX.current=e.Vector1D(m),e.prevX.current=e.Vector1D(m),e.offX.current=e.Vector1D(m),e.tgtX.current=e.Vector1D(m),e.locY.current=e.Vector1D(u),e.prevY.current=e.Vector1D(u),e.offY.current=e.Vector1D(u),e.tgtY.current=e.Vector1D(u),e.bodyX.current=e.ScrollBody(e.locX.current,e.offX.current,e.prevX.current,e.tgtX.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync(),e.bodyY.current=e.ScrollBody(e.locY.current,e.offY.current,e.prevY.current,e.tgtY.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync();let{x:i,y:f,povX:d,povY:g}=e.boundsForCurrent(e.scaleRef.current,c$1,a$1,t,s);e.boundsX.current=e.ScrollBounds(i,e.offX.current,e.tgtX.current,e.bodyX.current,d,e.fs.zoom.panDuration),e.boundsY.current=e.ScrollBounds(f,e.offY.current,e.tgtY.current,e.bodyY.current,g,e.fs.zoom.panDuration);}function yr(e){let{scale:r,imgW:n,imgH:o,currentImageEl:t,viewW:s,viewH:c$1,captionW:a,captionH:m,captionPlacement:u,reservedLeft:i,reservedRight:f$1,reservedTop:d$1,reservedBottom:g}=e,R=c(t)?.getBoundingClientRect()??null,v=s??R?.width??document.documentElement.clientWidth,Y=c$1??R?.height??window.innerHeight,h=n*r,X=o*r,E=(v-n)/2,H=(Y-o)/2,y=R?.left??0,M=R?.top??0,T=y+E,F=M+H,L=u==="left"?a??0:0,k=u==="right"?a??0:0,D=u==="top"?m??0:0,p=u==="bottom"?m??0:0,l=i??L,P=f$1??k,w=d$1??D,B=g??p,V=y-l,z=y+v+P,C=M-w,O=M+Y+B,$=z-V,x=O-C,K,q,J,Q;if(h<=$){let I=(V+z)/2-T-h/2;K=I,q=I;}else q=V-T,K=z-h-T;if(X<=x){let I=(C+O)/2-F-X/2;J=I,Q=I;}else Q=C-F,J=O-X-F;return {x:d(K,q),y:d(J,Q),povX:f($),povY:f(x)}}function vr(e){let{setScale:r,zoomState:n,imageRefs:o,resetPan:t}=e,s=e.transition??"transform 0.2s cubic-bezier(.4,0,.22,1)",c="translate(0, 0) scale(1)";r(1),n.previousZoom.current.x=0,n.previousZoom.current.y=0,n.panRef.current={x:0,y:0},n.scaleRef.current=1,o.current.forEach(a$1=>{let m=a$1.current;if(!m)return;let u=m.children[0];if(g(u))return;let i=a(m);if(!i)return;let f=s.match(/([\d.]+)s/),d=f?parseFloat(f[1])*1e3:300;i.style.transition=s,i.offsetWidth,i.style.transform=c,window.setTimeout(()=>{i.style.transition="";},d+50);}),t();}function hr(e){let{currentImage:r,locX:n,prevX:o,offX:t,tgtX:s,locY:c$1,prevY:a$1,offY:m,tgtY:u,bodyX:i,bodyY:f,boundsX:d,boundsY:g$1,ScrollBody:R,ScrollBounds:v,baseFitSize:Y,boundsForCurrent:h,panDuration:X,panFriction:E,animRef:H}=e,y=r.current;if(!y||!n.current||!o.current||!t.current||!s.current||!c$1.current||!a$1.current||!m.current||!u.current)return;let M=y.children[0];if(g(M))return;let T=a(y);if(!T)return;H.current?.stop?.();let L=(c(y)??y).getBoundingClientRect(),k=L.width,D=L.height,{baseW:p,baseH:l}=Y(T,k,D);n.current.set(0),o.current.set(0),t.current.set(0),s.current.set(0),c$1.current.set(0),a$1.current.set(0),m.current.set(0),u.current.set(0),i.current=R(n.current,t.current,o.current,s.current,X,E).sync(),f.current=R(c$1.current,m.current,a$1.current,u.current,X,E).sync();let{x:P,y:w,povX:B,povY:V}=h(1,p,l,k,D,{ignoreReserved:true});d.current=v(P,t.current,s.current,i.current,B,X),g$1.current=v(w,m.current,u.current,f.current,V,X),s.current.set(P.constrain(0)),u.current.set(w.constrain(0)),H.current?.resetBlend();}var Ee=260,Ve=32,ve=1.01,G=new WeakMap;function Ze(e){return typeof e=="object"&&e!=null&&e.__rmgZoomPanPlugin===true}function Fe(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function ke(e,r){let n=a(e.current);if(!n)return r;let o=typeof window<"u"&&typeof window.getComputedStyle=="function"?window.getComputedStyle(n).transform:n.style.transform;if(!o||o==="none")return r;let t=o.match(/matrix3d\(([^)]+)\)/);if(t){let a=t[1].split(",").map(Number.parseFloat);return Number.isFinite(a[0])?a[0]:r}let s=o.match(/matrix\(([^)]+)\)/);if(s){let a=s[1].split(",").map(Number.parseFloat),m=a[0]||0,u=a[1]||0,i=Math.hypot(m,u);return Number.isFinite(i)&&i>0?i:r}let c=o.match(/scale\(([-\d.]+)\)/);if(c){let a=Number.parseFloat(c[1]);return Number.isFinite(a)?a:r}return r}function Ye(e){let r=a(e.current);if(!r)return;let n=G.get(r);n&&(window.cancelAnimationFrame(n.rafId),G.delete(r));}function Be(e){let r=a(e.current);return r?G.get(r)??null:null}function Hr(e){if(!e)return null;let r=e.plugins?.find(t=>Ze(t)&&t.kind==="hover");if(!r)return null;let n=r.options??{};if(n.enabled===false)return null;let o=n.zoomOutDurationMs??Ee;return {enabled:true,zoomLevel:n.zoomLevel??e.clickZoomLevel,zoomInDurationMs:n.zoomInDurationMs??o,zoomOutDurationMs:o}}function Pr(e){let r=e.pointerType;return r&&r!=="mouse"?false:typeof window>"u"||typeof window.matchMedia!="function"?true:window.matchMedia("(hover: hover) and (pointer: fine)").matches}function Xe(e,r,n){e.locX.current&&e.locY.current||(e.locX.current=e.Vector1D(r),e.prevX.current=e.Vector1D(r),e.offX.current=e.Vector1D(r),e.tgtX.current=e.Vector1D(r),e.locY.current=e.Vector1D(n),e.prevY.current=e.Vector1D(n),e.offY.current=e.Vector1D(n),e.tgtY.current=e.Vector1D(n),e.bodyX.current=e.ScrollBody(e.locX.current,e.offX.current,e.prevX.current,e.tgtX.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync(),e.bodyY.current=e.ScrollBody(e.locY.current,e.offY.current,e.prevY.current,e.tgtY.current,e.fs.zoom.panDuration,e.fs.zoom.panFriction).sync());}function Te(e,r,n){if(!r.current)return null;e.currentImage.current=r.current;let o=e.currentImage.current,t=a(o);if(!t)return null;let c$1=(c(o)??o).getBoundingClientRect();if(h({width:c$1.width,height:c$1.height},t))return null;let{x:a$1,y:m}=W(t);Xe(e,a$1,m);let{baseW:u,baseH:i}=j(t,c$1.width,c$1.height),f=e.boundsForCurrent(n,u,i,c$1.width,c$1.height);return {rect:c$1,bounds:f}}function he(e,r,n){let o=A(e.rect.width>0?(r-e.rect.left)/e.rect.width:.5,0,1),t=A(e.rect.height>0?(n-e.rect.top)/e.rect.height:.5,0,1),s=e.bounds.x.max-e.bounds.x.min,c=e.bounds.y.max-e.bounds.y.min;return {x:e.bounds.x.constrain(e.bounds.x.max-s*o),y:e.bounds.y.constrain(e.bounds.y.max-c*t)}}function Le(e,r){e.boundsX.current=e.ScrollBounds(r.bounds.x,e.offX.current,e.tgtX.current,e.bodyX.current,r.bounds.povX,e.fs.zoom.panDuration),e.boundsY.current=e.ScrollBounds(r.bounds.y,e.offY.current,e.tgtY.current,e.bodyY.current,r.bounds.povY,e.fs.zoom.panDuration);}function Ce(e,r){e.panRef&&(e.panRef.current=r),e.offX.current?.set(r.x),e.offY.current?.set(r.y),e.locX.current?.set(r.x),e.locY.current?.set(r.y),e.prevX.current?.set(r.x),e.prevY.current?.set(r.y),e.tgtX.current?.set(r.x),e.tgtY.current?.set(r.y);}function ie(e,r,n){let o=e.currentImage.current,t=b(o);if(!t.length)return;let s=`translate3d(${r.x}px, ${r.y}px, 0) scale(${n})`;t.forEach(c=>{c.style.transition&&(c.style.transition=""),c.style.transform=s;}),Ce(e,r);}function Oe(e){let s=1.2000000000000002,c=3*(.22-.4)-s,a=1-s-c,m=0,u=3-m,i=1-m-u,f=e;for(let d=0;d<6;d+=1){let g=((a*f+c)*f+s)*f,R=(3*a*f+2*c)*f+s;if(Math.abs(g-e)<.001||Math.abs(R)<.001)break;f-=(g-e)/R,f=A(f,0,1);}return ((i*f+u)*f+m)*f}function Re(e,r){let n=Math.max(0,r-e.lastFrameMs),o=r-e.startMs,t=e.durationMs<=0?1:A(o/e.durationMs,0,1),s=Oe(t),c={x:e.fromX+(e.target.x-e.fromX)*s,y:e.fromY+(e.target.y-e.fromY)*s},a=e.fromScale+(e.targetScale-e.fromScale)*s,m=t>=1?1:A(n/Ve,0,1);return e.currentX+=(c.x-e.currentX)*m,e.currentY+=(c.y-e.currentY)*m,e.lastFrameMs=r,ie(e.ctx,{x:e.currentX,y:e.currentY},a),t>=1}function ze(e,r,n){let o=a(r.current);if(!o)return;Ye(r);let t={ctx:e,imageRef:r,imgEl:o,rafId:0,startMs:Fe(),lastFrameMs:0,durationMs:n.durationMs,fromX:n.fromX,fromY:n.fromY,currentX:n.fromX,currentY:n.fromY,fromScale:n.fromScale,target:n.target,targetScale:n.targetScale};t.lastFrameMs=t.startMs;function s(c){if(G.get(o)!==t)return;if(Re(t,c)){G.delete(o),e.scaleRef.current=t.targetScale,e.setScale(t.targetScale),ie(e,t.target,t.targetScale);return}t.rafId=window.requestAnimationFrame(s);}G.set(o,t),Re(t,t.startMs),t.rafId=window.requestAnimationFrame(s);}function Sr(e,r){let n=A(r.hover.zoomLevel,1,e.fs.zoom.maxZoomLevel);if(n<=ve)return false;let o=Te(e,r.imageRef,n);if(!o)return false;let t=he(o,r.clientX,r.clientY);return Le(e,o),e.animRef.current?.stop(),e.suppressLoopRef.current=true,e.previousZoom.current.x=r.clientX-o.rect.left,e.previousZoom.current.y=r.clientY-o.rect.top,e.panRef&&(e.panRef.current=t),e.scaleRef.current=n,e.setScale(n),ze(e,r.imageRef,{fromX:e.offX.current?.get()??0,fromY:e.offY.current?.get()??0,fromScale:ke(r.imageRef,1),target:t,targetScale:n,durationMs:r.hover.zoomInDurationMs}),true}function Er(e,r){let n=e.scaleRef.current;if(n<=ve)return false;let o=Te(e,r.imageRef,n);if(!o)return false;let t=he(o,r.clientX,r.clientY);Le(e,o),e.suppressLoopRef.current=true,e.panRef&&(e.panRef.current=t),e.tgtX.current.set(t.x),e.tgtY.current.set(t.y);let s=Be(r.imageRef);return s?(s.target=t,true):(e.animRef.current?.stop(),ie(e,t,n),true)}function Vr(e,r){return r.imageRef.current?(e.currentImage.current=r.imageRef.current,Xe(e,e.offX.current?.get()??0,e.offY.current?.get()??0),Ye(r.imageRef),e.animRef.current?.stop(),e.suppressLoopRef.current=false,e.previousZoom.current.x=0,e.previousZoom.current.y=0,e.panRef&&(e.panRef.current={x:0,y:0}),e.bodyX.current?.resetVelocity?.(),e.bodyX.current?.useDuration?.(0),e.bodyX.current?.useFriction?.(1),e.bodyX.current?.sync?.(),e.bodyY.current?.resetVelocity?.(),e.bodyY.current?.useDuration?.(0),e.bodyY.current?.useFriction?.(1),e.bodyY.current?.sync?.(),te(e,0,0,1,r.durationMs),true):false}export{j as a,Ie as b,Ae as c,Ne as d,qe as e,sr as f,mr as g,yr as h,vr as i,hr as j,Hr as k,Pr as l,Sr as m,Er as n,Vr as o};
|