UNPKG

@speaker-ender/js-measure

Version:
3 lines (2 loc) 3.05 kB
var m=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},v=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of B(t))!H.call(e,i)&&i!==n&&m(e,i,{get:()=>t[i],enumerable:!(o=W(t,i))||o.enumerable});return e};var L=e=>v(m({},"__esModule",{value:!0}),e);var F={};y(F,{bottomEdgeDistance:()=>w,documentHeight:()=>f,hasDocument:()=>c,hasWindow:()=>r,height:()=>E,inViewport:()=>b,leftEdgeDistance:()=>O,percentInViewport:()=>C,propFromRect:()=>R,rawHeight:()=>s,rawHeightWithMargin:()=>p,rawWidth:()=>g,rawWidthWithMargin:()=>h,rightEdgeDistance:()=>x,scrollLeftDistance:()=>a,scrollTopDistance:()=>l,topEdgeDistance:()=>M,width:()=>D,windowHeight:()=>u,windowWidth:()=>d});module.exports=L(F);var r=typeof window=="object",c=typeof document<"u"&&document.documentElement,f=()=>{if(c){let e=document.body,t=document.documentElement;return t?Math.max(e.scrollHeight,e.offsetHeight,t.clientHeight,t.scrollHeight,t.offsetHeight):0}return 0},d=()=>r&&c?window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth:0,u=()=>r&&c?window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight:0,l=()=>r&&c?window.pageYOffset||document.documentElement.scrollTop:0,a=e=>e?e.scrollLeft:typeof window<"u"&&document&&document.documentElement?window.pageXOffset||document.documentElement.scrollLeft:0,R=(e,t)=>e[t],s=(e,t)=>(t||e.getBoundingClientRect()).height,p=(e,t)=>{let n=window.getComputedStyle(e),o=parseFloat(n.marginTop)+parseFloat(n.marginBottom);return s(e,t)+o},E=(e,t,n)=>t?p(e,n):s(e),g=(e,t)=>(t||e.getBoundingClientRect()).width,h=(e,t)=>{let n=window.getComputedStyle(e),o=parseFloat(n.marginLeft)+parseFloat(n.marginRight);return g(e,t)+o},D=(e,t,n)=>t?h(e,n):g(e,n),M=(e,t="viewport",n)=>{n=n||e.getBoundingClientRect();let o;switch(t){case"document":return n.top+l();case"viewport":return e.getBoundingClientRect().top;default:return o=t.getBoundingClientRect(),n.top-o.top}},w=(e,t="viewport",n)=>{n=n||e.getBoundingClientRect();let o;switch(t){case"document":return n.bottom+l();case"viewport":return e.getBoundingClientRect().bottom;default:return o=t.getBoundingClientRect(),n.bottom-o.bottom}},O=(e,t="viewport",n)=>{n=n||e.getBoundingClientRect();let o,i;switch(t){case"document":return i=t?a():r&&c?window.pageXOffset||document.documentElement.scrollLeft:0,n.left+i;case"viewport":return n.left;default:return o=t.getBoundingClientRect(),o.left-n.left}},x=(e,t="viewport",n)=>{n=n||e.getBoundingClientRect();let o,i;switch(t){case"document":return i=d(),i-n.right;case"viewport":return n.right;default:return o=t.getBoundingClientRect(),o.right-n.right}},b=(e,t)=>(t=t||e.getBoundingClientRect(),t.top>=0&&t.left>=0&&t.bottom<=u()&&t.right<=d()),C=(e,t,n)=>{n=n||e.getBoundingClientRect(),t=t||u();let o=w(e,"viewport",n);return(Math.min(Math.max(o,0),n.height)-Math.max(o-t,0))/(n.height/100)}; //# sourceMappingURL=index.cjs.js.map