You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.7 KiB

  1. /*!
  2. * Bootstrap selector-engine.js v5.1.3 (https://getbootstrap.com/)
  3. * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SelectorEngine = factory());
  10. })(this, (function () { 'use strict';
  11. /**
  12. * --------------------------------------------------------------------------
  13. * Bootstrap (v5.1.3): util/index.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. const isElement = obj => {
  18. if (!obj || typeof obj !== 'object') {
  19. return false;
  20. }
  21. if (typeof obj.jquery !== 'undefined') {
  22. obj = obj[0];
  23. }
  24. return typeof obj.nodeType !== 'undefined';
  25. };
  26. const isVisible = element => {
  27. if (!isElement(element) || element.getClientRects().length === 0) {
  28. return false;
  29. }
  30. return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
  31. };
  32. const isDisabled = element => {
  33. if (!element || element.nodeType !== Node.ELEMENT_NODE) {
  34. return true;
  35. }
  36. if (element.classList.contains('disabled')) {
  37. return true;
  38. }
  39. if (typeof element.disabled !== 'undefined') {
  40. return element.disabled;
  41. }
  42. return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
  43. };
  44. /**
  45. * --------------------------------------------------------------------------
  46. * Bootstrap (v5.1.3): dom/selector-engine.js
  47. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  48. * --------------------------------------------------------------------------
  49. */
  50. const NODE_TEXT = 3;
  51. const SelectorEngine = {
  52. find(selector, element = document.documentElement) {
  53. return [].concat(...Element.prototype.querySelectorAll.call(element, selector));
  54. },
  55. findOne(selector, element = document.documentElement) {
  56. return Element.prototype.querySelector.call(element, selector);
  57. },
  58. children(element, selector) {
  59. return [].concat(...element.children).filter(child => child.matches(selector));
  60. },
  61. parents(element, selector) {
  62. const parents = [];
  63. let ancestor = element.parentNode;
  64. while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
  65. if (ancestor.matches(selector)) {
  66. parents.push(ancestor);
  67. }
  68. ancestor = ancestor.parentNode;
  69. }
  70. return parents;
  71. },
  72. prev(element, selector) {
  73. let previous = element.previousElementSibling;
  74. while (previous) {
  75. if (previous.matches(selector)) {
  76. return [previous];
  77. }
  78. previous = previous.previousElementSibling;
  79. }
  80. return [];
  81. },
  82. next(element, selector) {
  83. let next = element.nextElementSibling;
  84. while (next) {
  85. if (next.matches(selector)) {
  86. return [next];
  87. }
  88. next = next.nextElementSibling;
  89. }
  90. return [];
  91. },
  92. focusableChildren(element) {
  93. const focusables = ['a', 'button', 'input', 'textarea', 'select', 'details', '[tabindex]', '[contenteditable="true"]'].map(selector => `${selector}:not([tabindex^="-"])`).join(', ');
  94. return this.find(focusables, element).filter(el => !isDisabled(el) && isVisible(el));
  95. }
  96. };
  97. return SelectorEngine;
  98. }));
  99. //# sourceMappingURL=selector-engine.js.map