12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- let shadowDomIsSupported;
- /** Checks whether the user's browser support Shadow DOM. */
- function _supportsShadowDom() {
- if (shadowDomIsSupported == null) {
- const head = typeof document !== 'undefined' ? document.head : null;
- shadowDomIsSupported = !!(head && (head.createShadowRoot || head.attachShadow));
- }
- return shadowDomIsSupported;
- }
- /** Gets the shadow root of an element, if supported and the element is inside the Shadow DOM. */
- function _getShadowRoot(element) {
- if (_supportsShadowDom()) {
- const rootNode = element.getRootNode ? element.getRootNode() : null;
- // Note that this should be caught by `_supportsShadowDom`, but some
- // teams have been able to hit this code path on unsupported browsers.
- if (typeof ShadowRoot !== 'undefined' && ShadowRoot && rootNode instanceof ShadowRoot) {
- return rootNode;
- }
- }
- return null;
- }
- /**
- * Gets the currently-focused element on the page while
- * also piercing through Shadow DOM boundaries.
- */
- function _getFocusedElementPierceShadowDom() {
- let activeElement = typeof document !== 'undefined' && document
- ? document.activeElement
- : null;
- while (activeElement && activeElement.shadowRoot) {
- const newActiveElement = activeElement.shadowRoot.activeElement;
- if (newActiveElement === activeElement) {
- break;
- }
- else {
- activeElement = newActiveElement;
- }
- }
- return activeElement;
- }
- /** Gets the target of an event while accounting for Shadow DOM. */
- function _getEventTarget(event) {
- // If an event is bound outside the Shadow DOM, the `event.target` will
- // point to the shadow root so we have to use `composedPath` instead.
- return (event.composedPath ? event.composedPath()[0] : event.target);
- }
- export { _getEventTarget as _, _getShadowRoot as a, _supportsShadowDom as b, _getFocusedElementPierceShadowDom as c };
- //# sourceMappingURL=shadow-dom-B0oHn41l.mjs.map
|