index.mjs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {useEffect as $1wErz$useEffect} from "react";
  2. /** Number of components which have requested interest to have focus guards */ let $3db38b7d1fb3fe6a$var$count = 0;
  3. function $3db38b7d1fb3fe6a$export$ac5b58043b79449b(props) {
  4. $3db38b7d1fb3fe6a$export$b7ece24a22aeda8c();
  5. return props.children;
  6. }
  7. /**
  8. * Injects a pair of focus guards at the edges of the whole DOM tree
  9. * to ensure `focusin` & `focusout` events can be caught consistently.
  10. */ function $3db38b7d1fb3fe6a$export$b7ece24a22aeda8c() {
  11. $1wErz$useEffect(()=>{
  12. var _edgeGuards$, _edgeGuards$2;
  13. const edgeGuards = document.querySelectorAll('[data-radix-focus-guard]');
  14. document.body.insertAdjacentElement('afterbegin', (_edgeGuards$ = edgeGuards[0]) !== null && _edgeGuards$ !== void 0 ? _edgeGuards$ : $3db38b7d1fb3fe6a$var$createFocusGuard());
  15. document.body.insertAdjacentElement('beforeend', (_edgeGuards$2 = edgeGuards[1]) !== null && _edgeGuards$2 !== void 0 ? _edgeGuards$2 : $3db38b7d1fb3fe6a$var$createFocusGuard());
  16. $3db38b7d1fb3fe6a$var$count++;
  17. return ()=>{
  18. if ($3db38b7d1fb3fe6a$var$count === 1) document.querySelectorAll('[data-radix-focus-guard]').forEach((node)=>node.remove()
  19. );
  20. $3db38b7d1fb3fe6a$var$count--;
  21. };
  22. }, []);
  23. }
  24. function $3db38b7d1fb3fe6a$var$createFocusGuard() {
  25. const element = document.createElement('span');
  26. element.setAttribute('data-radix-focus-guard', '');
  27. element.tabIndex = 0;
  28. element.style.cssText = 'outline: none; opacity: 0; position: fixed; pointer-events: none';
  29. return element;
  30. }
  31. const $3db38b7d1fb3fe6a$export$be92b6f5f03c0fe9 = $3db38b7d1fb3fe6a$export$ac5b58043b79449b;
  32. export {$3db38b7d1fb3fe6a$export$ac5b58043b79449b as FocusGuards, $3db38b7d1fb3fe6a$export$be92b6f5f03c0fe9 as Root, $3db38b7d1fb3fe6a$export$b7ece24a22aeda8c as useFocusGuards};
  33. //# sourceMappingURL=index.mjs.map