composed-offset-position
Version:
This provides a set of ponyfills to achieve the same behavior of `offsetParent`, `offsetLeft` and `offsetTop` before the `offsetParent` spec was changed.
2 lines (1 loc) • 872 B
JavaScript
import{isContainingBlock as t}from"@floating-ui/utils/dom";function e(t){return i(t)}function n(t){return f(t,"offsetTop")}function o(t){return f(t,"offsetLeft")}function r(t){return t.assignedSlot?t.assignedSlot:t.parentNode instanceof ShadowRoot?t.parentNode.host:t.parentNode}function i(e){for(let t=e;t;t=r(t))if(t instanceof Element&&"none"===getComputedStyle(t).display)return null;for(let n=r(e);n;n=r(n)){if(!(n instanceof Element))continue;const e=getComputedStyle(n);if("contents"!==e.display){if("static"!==e.position||t(e))return n;if("BODY"===n.tagName)return n}}return null}function f(t,e){let n=t[e],o=i(t);const r=function(t){const e=new Set;let n=t.getRootNode();for(;n;)e.add(n),n=n.parentNode?n.parentNode.getRootNode():null;return e}(t);for(;o&&!r.has(o.getRootNode());)n-=o[e],o=i(o);return n}export{o as offsetLeft,e as offsetParent,n as offsetTop};