UNPKG

@jengaui/utils

Version:

Jenga UI Utils component in React

8 lines (4 loc) 3.75 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function E(i,n){let t=Object.prototype.toString.call(i),c=t==="[object Array]"||t==="[object NodeList]"||t==="[object HTMLCollection]"||t==="[object Object]"||typeof jQuery<"u"&&i instanceof jQuery||typeof Elements<"u"&&i instanceof Elements,s=0,r=i.length;if(c)for(;s<r;s++)n(i[s]);else n(i);}function R(i){if(!i.getBoundingClientRect)return {width:i.offsetWidth,height:i.offsetHeight};let n=i.getBoundingClientRect();return {width:Math.round(n.width),height:Math.round(n.height)}}function z(i,n){Object.keys(n).forEach(function(t){i.style[t]=n[t];});}var y=function(i,n){let t=window,c=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||function(e){return t.setTimeout(e,20)},s=t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||function(e){t.clearTimeout(e);},r=0;function T(){let e=[];this.add=function(f){e.push(f);};let o,a;this.call=function(f){for(o=0,a=e.length;o<a;o++)e[o].call(this,f);},this.remove=function(f){let d=[];for(o=0,a=e.length;o<a;o++)e[o]!==f&&d.push(e[o]);e=d;},this.length=function(){return e.length};}function H(e,o){if(!e)return;if(e.resizedAttached){e.resizedAttached.add(o);return}e.resizedAttached=new T,e.resizedAttached.add(o),e.resizeSensor=document.createElement("div"),e.resizeSensor.dir="ltr",e.resizeSensor.className="resize-sensor";let a={pointerEvents:"none",position:"absolute",left:"0px",top:"0px",right:"0px",bottom:"0px",overflow:"hidden",zIndex:"-1",visibility:"hidden",maxWidth:"100%"},f={position:"absolute",left:"0px",top:"0px",transition:"0s"};z(e.resizeSensor,a);let d=document.createElement("div");d.className="resize-sensor-expand",z(d,a);let S=document.createElement("div");z(S,f),d.appendChild(S);let l=document.createElement("div");l.className="resize-sensor-shrink",z(l,a);let b=document.createElement("div");z(b,f),z(b,{width:"200%",height:"200%"}),l.appendChild(b),e.resizeSensor.appendChild(d),e.resizeSensor.appendChild(l),e.appendChild(e.resizeSensor);let C=window.getComputedStyle(e),g=C?C.getPropertyValue("position"):null;g!=="absolute"&&g!=="relative"&&g!=="fixed"&&g!=="sticky"&&(e.style.position="relative");let w=!1,A=0,u=R(e),x=0,j=0,F=!0;r=0;let M=function(){let h=e.offsetWidth,p=e.offsetHeight;S.style.width=h+10+"px",S.style.height=p+10+"px",d.scrollLeft=h+10,d.scrollTop=p+10,l.scrollLeft=h+10,l.scrollTop=p+10;},v=function(){if(F)if(e.offsetWidth===0&&e.offsetHeight===0){r||(r=c(function(){r=0,v();}));return}else F=!1;M();};e.resizeSensor.resetSensor=v;let W=function(){A=0,w&&(x=u.width,j=u.height,e.resizedAttached&&e.resizedAttached.call(u));},k=function(){u=R(e),w=u.width!==x||u.height!==j,w&&!A&&(A=c(W)),v();},L=function(h,p,O){h.attachEvent?h.attachEvent("on"+p,O):h.addEventListener(p,O);};L(d,"scroll",k),L(l,"scroll",k),r=c(function(){r=0,v();});}E(i,function(e){H(e,n);}),this.detach=function(e){r&&(s(r),r=0),y.detach(i,e);},this.reset=function(){i.resizeSensor.resetSensor&&i.resizeSensor.resetSensor();};};y.reset=function(i){E(i,function(n){i.resizeSensor.resetSensor&&n.resizeSensor.resetSensor();});};y.detach=function(i,n){E(i,function(t){!t||t.resizedAttached&&typeof n=="function"&&(t.resizedAttached.remove(n),t.resizedAttached.length())||t.resizeSensor&&(t.contains(t.resizeSensor)&&t.removeChild(t.resizeSensor),delete t.resizeSensor,delete t.resizedAttached);});};if(typeof MutationObserver<"u"){let i=new MutationObserver(function(n){for(let t in n)if(n.hasOwnProperty(t)){let c=n[t].addedNodes;for(let s=0;s<c.length;s++)c[s].resizeSensor&&y.reset(c[s]);}});document.addEventListener("DOMContentLoaded",function(n){i.observe(document.body,{childList:!0,subtree:!0});});} exports.ResizeSensor = y;