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) • 1.15 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@floating-ui/utils/dom")):"function"==typeof define&&define.amd?define(["exports","@floating-ui/utils/dom"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ComposedOffsetPosition={},t.FloatingUIUtilsDOM)}(this,(function(t,e){"use strict";function o(t){return t.assignedSlot?t.assignedSlot:t.parentNode instanceof ShadowRoot?t.parentNode.host:t.parentNode}function n(t){for(let e=t;e;e=o(e))if(e instanceof Element&&"none"===getComputedStyle(e).display)return null;for(let n=o(t);n;n=o(n)){if(!(n instanceof Element))continue;const t=getComputedStyle(n);if("contents"!==t.display){if("static"!==t.position||e.isContainingBlock(t))return n;if("BODY"===n.tagName)return n}}return null}function i(t,e){let o=t[e],i=n(t);const f=function(t){const e=new Set;let o=t.getRootNode();for(;o;)e.add(o),o=o.parentNode?o.parentNode.getRootNode():null;return e}(t);for(;i&&!f.has(i.getRootNode());)o-=i[e],i=n(i);return o}t.offsetLeft=function(t){return i(t,"offsetLeft")},t.offsetParent=function(t){return n(t)},t.offsetTop=function(t){return i(t,"offsetTop")}}));