@styleless-ui/react
Version:
Completely unstyled, headless and accessible React UI components.
1 lines • 2.89 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.contains=exports.getViewportRect=exports.getBoundingClientRect=exports.getOffsetParent=exports.getContainingBlock=exports.getParentNode=exports.getNodeName=exports.getDocumentElement=exports.getWindow=void 0;var is_1=require("./is"),getWindow=function(t){if(!t)return window;if(!(0,is_1.isWindow)(t)){var e=t.ownerDocument;return e&&e.defaultView||window}return t};exports.getWindow=getWindow;var getDocumentElement=function(t){var e;return(null!==(e=t instanceof(0,exports.getWindow)(t).Node?t.ownerDocument:t.document)&&void 0!==e?e:window.document).documentElement};exports.getDocumentElement=getDocumentElement;var getNodeName=function(t){return(0,is_1.isWindow)(t)?"":t?(t.nodeName||"").toLowerCase():""};exports.getNodeName=getNodeName;var getParentNode=function(t){return"html"===(0,exports.getNodeName)(t)?t:t.assignedSlot||t.parentNode||((0,is_1.isShadowRoot)(t)?t.host:null)||(0,exports.getDocumentElement)(t)};exports.getParentNode=getParentNode;var getContainingBlock=function(t){var e=(0,exports.getParentNode)(t);for(e&&(0,is_1.isShadowRoot)(e)&&(e=e.host);(0,is_1.isHTMLElement)(e)&&!["html","body"].includes((0,exports.getNodeName)(e));){if((0,is_1.isContainingBlock)(e))return e;e=e.parentNode}return null};exports.getContainingBlock=getContainingBlock;var getOffsetParent=function(t){for(var e=(0,exports.getWindow)(t),o=function(t){return(0,is_1.isHTMLElement)(t)&&"fixed"!==e.getComputedStyle(t).position?t.offsetParent:null},n=o(t);n&&["table","td","th"].includes((0,exports.getNodeName)(n))&&"static"===e.getComputedStyle(n).position;)n=o(n);return n&&("html"===(0,exports.getNodeName)(n)||"body"===(0,exports.getNodeName)(n)&&"static"===e.getComputedStyle(n).position&&!(0,is_1.isContainingBlock)(n))?e:n||(0,exports.getContainingBlock)(t)||e};exports.getOffsetParent=getOffsetParent;var getBoundingClientRect=function(t,e){void 0===e&&(e=!1);var o=t.getBoundingClientRect(),n=1,i=1;return e&&(0,is_1.isHTMLElement)(t)&&(n=t.offsetWidth>0&&Math.round(o.width)/t.offsetWidth||1,i=t.offsetHeight>0&&Math.round(o.height)/t.offsetHeight||1),{width:o.width/n,height:o.height/i,top:o.top/i,right:o.right/n,bottom:o.bottom/i,left:o.left/n,x:o.left/n,y:o.top/i}};exports.getBoundingClientRect=getBoundingClientRect;var getViewportRect=function(t){var e=(0,exports.getWindow)(t),o=(0,exports.getDocumentElement)(t),n=e.visualViewport,i=o.clientWidth,r=o.clientHeight,s=0,d=0;return n&&(i=n.width,r=n.height,Math.abs(e.innerWidth/n.scale-n.width)<.01&&(s=n.offsetLeft,d=n.offsetTop)),{width:i,height:r,x:s,y:d}};exports.getViewportRect=getViewportRect;var contains=function(t,e){var o;if(t.contains(e))return!0;var n=null===(o=e.getRootNode)||void 0===o?void 0:o.call(e);if(n&&(0,is_1.isShadowRoot)(n)){var i=e;do{if(i&&t===i)return!0;i=i.parentNode||i.host}while(i)}return!1};exports.contains=contains;