- md5
- 886d9bfa5072b0d64e06268c19feb03b
- sha1
- f6304f79dc22f25141fa8599b0169e9ff10f7b9c
- sha256
- dcb788e645288fbd4201f8d6824e8b51a4fd92da544e446ba03c5745846fea45
import{store as q,getContext as h,getElement as _,getConfig as N,withSyncEvent as D,withScope as k,splitTask as Z}from"@wordpress/interactivity";function B(){return window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches===!0}var X=200;var O=!1,L=0,y={startX:0,startY:0,startTime:0},W=[],i={isDragging:!1,direction:null,slideEls:[],animations:[],settle:null},j=220,Q=300,V="cubic-bezier(0.2, 0.7, 0.2, 1)",G=10,J=1.5,ee=.2,te=50,ae=300;function ne(){return window.innerWidth}function K(e){return`translate(calc(-50% + ${e}px), -50%)`}function C(e,a){e.forEach(n=>{a?n.style.setProperty("--wp--lightbox-drag-offset",`${a}px`):n.style.removeProperty("--wp--lightbox-drag-offset")})}function M(){i.animations.forEach(e=>e.cancel()),i.animations=[]}function H(){i.isDragging=!1,i.direction=null,i.slideEls=[]}async function oe(e){await Z();try{await e?.decode()}catch{}}var ie=[".wp-lightbox-close-button",".wp-lightbox-navigation-button"];function U({uploadedSrc:e}){return e||"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="}function z({lightboxSrcset:e}){return e||""}var{state:t,actions:w,callbacks:P}=q("core/image",{state:{selectedImageId:null,selectedGalleryId:null,preloadTimers:new Map,preloadedImageIds:new Set,get galleryImages(){return t.selectedGalleryId?Object.entries(t.metadata).filter(([,e])=>e.galleryId===t.selectedGalleryId).sort(([,e],[,a])=>{let n=e.order??0,o=a.order??0;return n-o}).map(([e])=>e):[t.selectedImageId]},get selectedImageIndex(){return t.galleryImages.findIndex(e=>e===t.selectedImageId)},get selectedImage(){return t.metadata[t.selectedImageId]},get hasNavigationIcon(){let{navigationButtonType:e}=t.selectedImage;return e==="icon"||e==="both"},get hasNavigationText(){let{navigationButtonType:e}=t.selectedImage;return e==="text"||e==="both"},get thisImage(){let{imageId:e}=h();return t.metadata[e]},get hasNavigation(){return t.galleryImages.length>1},get hasNextImage(){return t.selectedImageIndex+1<t.galleryImages.length},get hasPreviousImage(){return t.selectedImageIndex-1>=0},get overlayOpened(){return t.selectedImageId!==null},get roleAttribute(){return t.overlayOpened?"dialog":null},get ariaModal(){return t.overlayOpened?"true":null},get ariaLabel(){return t.selectedImage.customAriaLabel||N().defaultAriaLabel},get closeButtonAriaLabel(){return t.hasNavigationText?void 0:N().closeButtonText},get prevButtonAriaLabel(){return t.hasNavigationText?void 0:N().prevButtonText},get nextButtonAriaLabel(){return t.hasNavigationText?void 0:N().nextButtonText},get enlargedSrc(){return U(t.selectedImage)},get enlargedSrcset(){return z(t.selectedImage)},get figureStyles(){return t.overlayOpened&&`${t.selectedImage.figureStyles?.replace(/margin[^;]*;?/g,"")};`},get imgStyles(){return t.overlayOpened&&`${t.selectedImage.imgStyles?.replace(/;$/,"")}; object-fit:cover;`},get isContentHidden(){let e=h();return t.overlayEnabled&&t.selectedImageId===e.imageId},get isContentVisible(){let e=h();return!t.overlayEnabled&&t.selectedImageId===e.imageId}},actions:{showLightbox(){let{imageId:e}=h();if(!t.metadata[e].imageRef?.complete)return;t.scrollTopReset=document.documentElement.scrollTop,t.scrollLeftReset=document.documentElement.scrollLeft,t.selectedImageId=e;let{galleryId:a}=h("core/gallery")||{};t.selectedGalleryId=a||null,t.overlayEnabled=!0,P.setOverlayStyles()},hideLightbox(){t.overlayEnabled&&(t.overlayEnabled=!1,setTimeout(function(){t.selectedImage.buttonRef.focus({preventScroll:!0}),t.selectedImageId=null,t.selectedGalleryId=null},450))},showPreviousImage:D(e=>{e.stopPropagation();let a=t.hasPreviousImage?t.selectedImageIndex-1:t.galleryImages.length-1;t.selectedImageId=t.galleryImages[a],P.setOverlayStyles()}),showNextImage:D(e=>{e.stopPropagation();let a=t.hasNextImage?t.selectedImageIndex+1:0;t.selectedImageId=t.galleryImages[a],P.setOverlayStyles()}),handleKeydown:D(e=>{if(t.overlayEnabled){if(e.key==="Escape")w.hideLightbox();else if(e.key==="ArrowLeft")w.showPreviousImage(e);else if(e.key==="ArrowRight")w.showNextImage(e);else if(e.key==="Tab"){let a=Array.from(document.querySelectorAll(ie)),n=a[0],o=a[a.length-1];e.shiftKey&&e.target===n?(e.preventDefault(),o.focus()):!e.shiftKey&&e.target===o&&(e.preventDefault(),n.focus())}}}),handleTouchMove:D(e=>{if(!t.overlayEnabled)return;e.preventDefault();let a=e.touches&&e.touches[0];if(!a||!t.hasNavigation)return;let n=a.clientX-y.startX,o=a.clientY-y.startY,d=Math.abs(n),c=Math.abs(o);!i.direction&&(d>G||c>G)&&(i.direction=d>c?"horizontal":"vertical",i.slideEls=Array.from(e.currentTarget.querySelectorAll(".lightbox-image-container"))),i.direction==="horizontal"&&i.slideEls.length&&(i.isDragging=!0,C(i.slideEls,n))}),handleTouchStart(e){if(O=!0,e.touches?.length>1)return;let a=e.touches&&e.touches[0];a&&(y.startX=a.clientX,y.startY=a.clientY,y.startTime=Date.now()),i.settle?.(),M(),H()},handleTouchCancel(){M(),C(i.slideEls,0),H(),L=Date.now(),O=!1},handleTouchEnd:D(e=>{if(e.touches?.length)return;let a=e.changedTouches&&e.changedTouches[0]||e.touches&&e.touches[0],n=Date.now();if(a&&t.overlayEnabled&&i.isDragging){e.preventDefault();let o=a.clientX-y.startX,d=a.clientY-y.startY,c=Math.abs(o),f=Math.abs(d),v=n-y.startTime,m=ne(),I=c>f*J,g=c>m*ee,l=c>te&&v<ae,r=I&&(g||l),u=o<0,s=i.slideEls,T=B(),p=u?-m:m,R=r?p:0,b=()=>{if(i.settle!==b||(i.settle=null,M(),C(s,0),!r)||(u?w.showNextImage(e):w.showPreviousImage(e),T))return;let x=s.map(A=>A.animate([{opacity:0},{opacity:0}],{fill:"forwards"}));i.animations=x;let E=s[s.length-1];oe(E.querySelector("img")).then(()=>{i.animations===x&&(M(),i.animations=s.map(A=>A.animate([{opacity:0},{opacity:A===E?1:0}],{duration:Q,easing:"ease-out"})))})};i.settle=b,T?b():(i.animations=s.map(x=>x.animate([{transform:K(o)},{transform:K(R)}],{duration:j,easing:V,fill:"forwards"})),i.animations[0].onfinish=k(b))}L=n,O=!1,H()}),handleScroll(){t.overlayOpened&&!O&&Date.now()-L>450&&window.scrollTo(t.scrollLeftReset,t.scrollTopReset)},preloadImage(){let{imageId:e}=h();if(t.preloadedImageIds.has(e))return;let a=t.metadata[e],n=document.createElement("link");n.rel="preload",n.as="image",n.href=U(a);let o=z(a);o&&(n.setAttribute("imagesrcset",o),n.setAttribute("imagesizes","100vw")),document.head.appendChild(n),t.preloadedImageIds.add(e)},preloadImageWithDelay(){let{imageId:e}=h();w.cancelPreload();let a=setTimeout(k(()=>{w.preloadImage(),t.preloadTimers.delete(e)}),X);t.preloadTimers.set(e,a)},cancelPreload(){let{imageId:e}=h();t.preloadTimers.has(e)&&(clearTimeout(t.preloadTimers.get(e)),t.preloadTimers.delete(e))}},callbacks:{setOverlayStyles(){if(!t.overlayEnabled)return;let{naturalWidth:e,naturalHeight:a,offsetWidth:n,offsetHeight:o}=t.selectedImage.imageRef,{x:d,y:c}=t.selectedImage.imageRef.getBoundingClientRect(),f=e/a,v=n/o;if(t.selectedImage.scaleAttr==="contain")if(f>v){let S=n/f;c+=(o-S)/2,o=S}else{let S=o*f;d+=(n-S)/2,n=S}let m=parseFloat(t.selectedImage.targetWidth&&t.selectedImage.targetWidth!=="none"?t.selectedImage.targetWidth:e),I=parseFloat(t.selectedImage.targetHeight&&t.selectedImage.targetHeight!=="none"?t.selectedImage.targetHeight:a),g=m/I,l=m,r=I;(n>l||o>r)&&(l=n,r=o);let u=0,s=160;480<window.innerWidth&&(u=80,s=160),960<window.innerWidth&&(u=t.hasNavigation?320:80,s=80);let T=Math.min(window.innerWidth-u,l),p=Math.min(window.innerHeight-s,r),R=T/p;g>R?(l=T,r=l/g):(r=p,l=r*g);let b=f.toFixed(2)!==g.toFixed(2),x=b?f:g,E=Math.max(n/l,o/r,n/(r*x),o*x/l),A=n/E,F=o/E,Y=(l-A)/2,$=(r-F)/2;d-=Y*E,c-=$*E,t.overlayStyles=`
--wp--lightbox-initial-top-position: ${c}px;
--wp--lightbox-initial-left-position: ${d}px;
--wp--lightbox-container-width: ${l+1}px;
--wp--lightbox-container-height: ${r+1}px;
--wp--lightbox-image-width: ${l}px;
--wp--lightbox-image-height: ${r}px;
--wp--lightbox-initial-clip: inset(${$}px ${Y}px);
--wp--lightbox-thumbnail-width: ${b?A:l}px;
--wp--lightbox-thumbnail-height: ${b?F:r}px;
--wp--lightbox-scale: ${E};
--wp--lightbox-scrollbar-width: ${window.innerWidth-document.documentElement.clientWidth}px;
`},setButtonStyles(){let{ref:e}=_();if(!e)return;let{imageId:a}=h();t.metadata[a].imageRef=e,t.metadata[a].currentSrc=e.currentSrc;let{naturalWidth:n,naturalHeight:o,offsetWidth:d,offsetHeight:c}=e;if(n===0||o===0)return;let f=e.parentElement,v=e.parentElement.clientWidth,m=e.parentElement.clientHeight,I=f.querySelector("figcaption");if(I){let s=window.getComputedStyle(I);["absolute","fixed"].includes(s.position)||(m=m-I.offsetHeight-parseFloat(s.marginTop)-parseFloat(s.marginBottom))}let g=m-c,l=v-d,r=g+16,u=l+16;if(t.metadata[a].scaleAttr==="contain"){let s=n/o,T=d/c;if(s>=T){let p=d/s;r=(c-p)/2+g+16,u=l+16}else{let p=c*s;r=g+16,u=(d-p)/2+l+16}}t.metadata[a].buttonTop=r,t.metadata[a].buttonRight=u},setOverlayFocus(){if(t.overlayEnabled){let{ref:e}=_();e.focus()}},setInertElements(){if(!t.overlayEnabled){W.forEach(n=>n.removeAttribute("inert")),W=[];return}let{ref:e}=_(),a=e;for(;a&&a!==document.body&&a.parentElement;){for(let n of a.parentElement.children)n!==a&&!n.hasAttribute("inert")&&(n.setAttribute("inert",""),W.push(n));a=a.parentElement}},initTriggerButton(){let{imageId:e}=h(),{ref:a}=_();t.metadata[e].buttonRef=a}}},{lock:!0});
The same content is in 2 releases, WordPress 7.2-beta1 to 7.2-beta2. See them all, or every version of this file.