chunk.XAZSQ3AT.js 928 B

1234567891011121314151617181920212223242526272829303132
  1. // src/internal/focus-visible.ts
  2. var listeners = new WeakMap();
  3. function observe(el) {
  4. const keys = ["Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageDown", "PageUp"];
  5. const is = (event) => {
  6. if (keys.includes(event.key)) {
  7. el.classList.add("focus-visible");
  8. }
  9. };
  10. const isNot = () => el.classList.remove("focus-visible");
  11. listeners.set(el, { is, isNot });
  12. el.addEventListener("keydown", is);
  13. el.addEventListener("keyup", is);
  14. el.addEventListener("mousedown", isNot);
  15. el.addEventListener("mousedown", isNot);
  16. }
  17. function unobserve(el) {
  18. const { is, isNot } = listeners.get(el);
  19. el.classList.remove("focus-visible");
  20. el.removeEventListener("keydown", is);
  21. el.removeEventListener("keyup", is);
  22. el.removeEventListener("mousedown", isNot);
  23. el.removeEventListener("mousedown", isNot);
  24. }
  25. var focusVisible = {
  26. observe,
  27. unobserve
  28. };
  29. export {
  30. focusVisible
  31. };