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^="-"])'];let a,r=!1,c=0;function l(e){!r&&Date.now()-c>450&&window.scrollTo(e.core.image.scrollLeftReset,e.core.image.scrollTopReset)}(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:r,y:c}=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;c+=(a-e)/2,a=e}else{const e=a*l;r+=(n-e)/2,n=e}g=n/a;let d=parseFloat("none"!==e.core.image.targetWidth?e.core.image.targetWidth:i),s=parseFloat("none"!==e.core.image.targetHeight?e.core.image.targetHeight:o),m=d/s,h=d,u=s,f=d,w=s;if(l.toFixed(2)!==m.toFixed(2)){if(l>m){const e=d/l;s-e>d?(s=e,d=e*l):s=d/l}else{const e=s*l;d-e>s?(d=e,s=e/l):d=s*l}f=d,w=s,m=d/s,g>m?(h=d,u=h/g):(u=s,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 v=n/f,y=d*(f/h),W=s*(w/u);let L=document.getElementById("wp-lightbox-styles");L||(L=document.createElement("style"),L.id="wp-lightbox-styles",document.head.appendChild(L));L.innerHTML=`\n\t\t:root {\n\t\t\t--wp--lightbox-initial-top-position: ${c}px;\n\t\t\t--wp--lightbox-initial-left-position: ${r}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: ${y}px;\n\t\t\t--wp--lightbox-image-height: ${W}px;\n\t\t\t--wp--lightbox-scale: ${v};\n\t\t}\n\t`}(e,t),e.core.image.scrollTopReset=window.pageYOffset||document.documentElement.scrollTop,e.core.image.scrollLeftReset=window.pageXOffset||document.documentElement.scrollLeft,a=l.bind(null,e),window.addEventListener("scroll",a,!1))},hideLightbox:async({context:e})=>{e.core.image.hideAnimationEnabled=!0,e.core.image.lightboxEnabled&&(setTimeout((function(){window.removeEventListener("scroll",a)}),450),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})},handleTouchStart:()=>{r=!0},handleTouchMove:({context:e,event:t})=>{e.core.image.lightboxEnabled&&t.preventDefault()},handleTouchEnd:()=>{c=Date.now(),r=!1}}}},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:r}=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/r){t.core.image.imageButtonWidth=a;const i=a/e;t.core.image.imageButtonHeight=i,t.core.image.imageButtonTop=(r-i)/2}else{t.core.image.imageButtonHeight=r;const i=r*e;t.core.image.imageButtonWidth=i,t.core.image.imageButtonLeft=(a-i)/2}}else t.core.image.imageButtonWidth=a,t.core.image.imageButtonHeight=r}}}}},{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)}]);