WordPress/wp-includes/blocks/image/view.min.js

1 line
5.1 KiB
JavaScript

"use strict";(self.__WordPressPrivateInteractivityAPI__=self.__WordPressPrivateInteractivityAPI__||[]).push([[354],{699:function(e,t,i){var o=i(754);const n=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'];(0,o.h)({state:{core:{image:{windowWidth:window.innerWidth,windowHeight:window.innerHeight}}},actions:{core:{image:{showLightbox:({context:e,event:t})=>{e.core.image.imageLoaded&&(e.core.image.initialized=!0,e.core.image.lastFocusedElement=window.document.activeElement,e.core.image.scrollDelta=0,e.core.image.lightboxEnabled=!0,function(e,t){let{naturalWidth:i,naturalHeight:o,offsetWidth:n,offsetHeight:a}=t.target.nextElementSibling,{x:c,y:r}=t.target.nextElementSibling.getBoundingClientRect();const l=i/o;let g=n/a;if("contain"===e.core.image.scaleAttr)if(l>g){const e=n/l;r+=(a-e)/2,a=e}else{const e=a*l;c+=(n-e)/2,n=e}g=n/a;let d=parseFloat("none"!==e.core.image.targetWidth?e.core.image.targetWidth:i),m=parseFloat("none"!==e.core.image.targetHeight?e.core.image.targetHeight:o),s=d/m,h=d,u=m,f=d,w=m;if(l.toFixed(2)!==s.toFixed(2)){if(l>s){const e=d/l;m-e>d?(m=e,d=e*l):m=d/l}else{const e=m*l;d-e>m?(d=e,m=e/l):d=m*l}f=d,w=m,s=d/m,g>s?(h=d,u=h/g):(u=m,h=u*g)}(n>f||a>w)&&(f=n,w=a);let b=0;window.innerWidth>480?b=80:window.innerWidth>1920&&(b=160);const x=80,p=Math.min(window.innerWidth-b,f),E=Math.min(window.innerHeight-x,w);g>p/E?(f=p,w=f/g):(w=E,f=w*g);const y=n/f,v=d*(f/h),W=m*(w/u);let H=document.getElementById("wp-lightbox-styles");H||(H=document.createElement("style"),H.id="wp-lightbox-styles",document.head.appendChild(H));H.innerHTML=`\n\t\t:root {\n\t\t\t--wp--lightbox-initial-top-position: ${r}px;\n\t\t\t--wp--lightbox-initial-left-position: ${c}px;\n\t\t\t--wp--lightbox-container-width: ${f+1}px;\n\t\t\t--wp--lightbox-container-height: ${w+1}px;\n\t\t\t--wp--lightbox-image-width: ${v}px;\n\t\t\t--wp--lightbox-image-height: ${W}px;\n\t\t\t--wp--lightbox-scale: ${y};\n\t\t}\n\t`}(e,t),document.documentElement.classList.add("wp-has-lightbox-open"))},hideLightbox:async({context:e,event:t})=>{if(e.core.image.hideAnimationEnabled=!0,e.core.image.lightboxEnabled){if("fade"===e.core.image.lightboxAnimation){if(e.core.image.scrollDelta+=t.deltaY,"mousewheel"===t.type&&Math.abs(window.scrollY-e.core.image.scrollDelta)<10)return}else if("zoom"===e.core.image.lightboxAnimation){const e=window.pageYOffset||document.documentElement.scrollTop,t=window.pageXOffset||document.documentElement.scrollLeft;window.onscroll=function(){window.scrollTo(t,e)},setTimeout((function(){window.onscroll=function(){}}),400)}document.documentElement.classList.remove("wp-has-lightbox-open"),e.core.image.lightboxEnabled=!1,e.core.image.lastFocusedElement.focus({preventScroll:!0})}},handleKeydown:({context:e,actions:t,event:i})=>{e.core.image.lightboxEnabled&&("Tab"!==i.key&&9!==i.keyCode||(i.shiftKey&&window.document.activeElement===e.core.image.firstFocusableElement?(i.preventDefault(),e.core.image.lastFocusableElement.focus()):i.shiftKey||window.document.activeElement!==e.core.image.lastFocusableElement||(i.preventDefault(),e.core.image.firstFocusableElement.focus())),"Escape"!==i.key&&27!==i.keyCode||t.core.image.hideLightbox({context:e,event:i}))},handleLoad:({state:e,context:t,effects:i,ref:o})=>{t.core.image.imageLoaded=!0,t.core.image.imageCurrentSrc=o.currentSrc,i.core.image.setButtonStyles({state:e,context:t,ref:o})}}}},selectors:{core:{image:{roleAttribute:({context:e})=>e.core.image.lightboxEnabled?"dialog":"",lightboxObjectFit:({context:e})=>{if(e.core.image.initialized)return"cover"},enlargedImgSrc:({context:e})=>e.core.image.initialized?e.core.image.imageUploadedSrc:""}}},effects:{core:{image:{setCurrentSrc:({context:e,ref:t})=>{t.complete&&(e.core.image.imageLoaded=!0,e.core.image.imageCurrentSrc=t.currentSrc)},initLightbox:async({context:e,ref:t})=>{if(e.core.image.figureRef=t.querySelector("figure"),e.core.image.imageRef=t.querySelector("img"),e.core.image.lightboxEnabled){const i=t.querySelectorAll(n);e.core.image.firstFocusableElement=i[0],e.core.image.lastFocusableElement=i[i.length-1],t.querySelector(".close-button").focus()}},setButtonStyles:({state:e,context:t,ref:i})=>{const{naturalWidth:o,naturalHeight:n,offsetWidth:a,offsetHeight:c}=i;if(0!==o&&0!==n)if((e.core.image.windowWidth||e.core.image.windowHeight)&&"contain"===t.core.image.scaleAttr){const e=o/n;if(e>a/c){t.core.image.imageButtonWidth=a;const i=a/e;t.core.image.imageButtonHeight=i,t.core.image.imageButtonTop=(c-i)/2}else{t.core.image.imageButtonHeight=c;const i=c*e;t.core.image.imageButtonWidth=i,t.core.image.imageButtonLeft=(a-i)/2}}else t.core.image.imageButtonWidth=a,t.core.image.imageButtonHeight=c}}}}},{afterLoad:({state:e})=>{window.addEventListener("resize",function(e,t=50){let i;return()=>{const o=()=>{i=null,e()};clearTimeout(i),i=setTimeout(o,t)}}((()=>{e.core.image.windowWidth=window.innerWidth,e.core.image.windowHeight=window.innerHeight})))}})}},function(e){var t;t=699,e(e.s=t)}]);