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

1 line
5.3 KiB
JavaScript
Raw Normal View History

"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.previousElementSibling,{x:r,y:c}=t.target.previousElementSibling.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),A=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: ${A}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":null,ariaModal:({context:e})=>e.core.image.lightboxEnabled?"true":null,dialogLabel:({context:e})=>e.core.image.lightboxEnabled?e.core.image.dialogLabel:null,lightboxObjectFit:({context:e})=>{if(e.core.image.initialized)return"cover"},enlargedImgSrc:({context:e})=>e.core.image.initialized?e.core.image.imageUploadedSrc:"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="}}},effect