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.

281 lines
9.1 KiB

8 months ago
  1. /*!
  2. * Bootstrap index.js v5.3.3 (https://getbootstrap.com/)
  3. * Copyright 2011-2024 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' ? factory(exports) :
  8. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Index = {}));
  10. })(this, (function (exports) { 'use strict';
  11. /**
  12. * --------------------------------------------------------------------------
  13. * Bootstrap util/index.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. const MAX_UID = 1000000;
  18. const MILLISECONDS_MULTIPLIER = 1000;
  19. const TRANSITION_END = 'transitionend';
  20. /**
  21. * Properly escape IDs selectors to handle weird IDs
  22. * @param {string} selector
  23. * @returns {string}
  24. */
  25. const parseSelector = selector => {
  26. if (selector && window.CSS && window.CSS.escape) {
  27. // document.querySelector needs escaping to handle IDs (html5+) containing for instance /
  28. selector = selector.replace(/#([^\s"#']+)/g, (match, id) => `#${CSS.escape(id)}`);
  29. }
  30. return selector;
  31. };
  32. // Shout-out Angus Croll (https://goo.gl/pxwQGp)
  33. const toType = object => {
  34. if (object === null || object === undefined) {
  35. return `${object}`;
  36. }
  37. return Object.prototype.toString.call(object).match(/\s([a-z]+)/i)[1].toLowerCase();
  38. };
  39. /**
  40. * Public Util API
  41. */
  42. const getUID = prefix => {
  43. do {
  44. prefix += Math.floor(Math.random() * MAX_UID);
  45. } while (document.getElementById(prefix));
  46. return prefix;
  47. };
  48. const getTransitionDurationFromElement = element => {
  49. if (!element) {
  50. return 0;
  51. }
  52. // Get transition-duration of the element
  53. let {
  54. transitionDuration,
  55. transitionDelay
  56. } = window.getComputedStyle(element);
  57. const floatTransitionDuration = Number.parseFloat(transitionDuration);
  58. const floatTransitionDelay = Number.parseFloat(transitionDelay);
  59. // Return 0 if element or transition duration is not found
  60. if (!floatTransitionDuration && !floatTransitionDelay) {
  61. return 0;
  62. }
  63. // If multiple durations are defined, take the first
  64. transitionDuration = transitionDuration.split(',')[0];
  65. transitionDelay = transitionDelay.split(',')[0];
  66. return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  67. };
  68. const triggerTransitionEnd = element => {
  69. element.dispatchEvent(new Event(TRANSITION_END));
  70. };
  71. const isElement = object => {
  72. if (!object || typeof object !== 'object') {
  73. return false;
  74. }
  75. if (typeof object.jquery !== 'undefined') {
  76. object = object[0];
  77. }
  78. return typeof object.nodeType !== 'undefined';
  79. };
  80. const getElement = object => {
  81. // it's a jQuery object or a node element
  82. if (isElement(object)) {
  83. return object.jquery ? object[0] : object;
  84. }
  85. if (typeof object === 'string' && object.length > 0) {
  86. return document.querySelector(parseSelector(object));
  87. }
  88. return null;
  89. };
  90. const isVisible = element => {
  91. if (!isElement(element) || element.getClientRects().length === 0) {
  92. return false;
  93. }
  94. const elementIsVisible = getComputedStyle(element).getPropertyValue('visibility') === 'visible';
  95. // Handle `details` element as its content may falsie appear visible when it is closed
  96. const closedDetails = element.closest('details:not([open])');
  97. if (!closedDetails) {
  98. return elementIsVisible;
  99. }
  100. if (closedDetails !== element) {
  101. const summary = element.closest('summary');
  102. if (summary && summary.parentNode !== closedDetails) {
  103. return false;
  104. }
  105. if (summary === null) {
  106. return false;
  107. }
  108. }
  109. return elementIsVisible;
  110. };
  111. const isDisabled = element => {
  112. if (!element || element.nodeType !== Node.ELEMENT_NODE) {
  113. return true;
  114. }
  115. if (element.classList.contains('disabled')) {
  116. return true;
  117. }
  118. if (typeof element.disabled !== 'undefined') {
  119. return element.disabled;
  120. }
  121. return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
  122. };
  123. const findShadowRoot = element => {
  124. if (!document.documentElement.attachShadow) {
  125. return null;
  126. }
  127. // Can find the shadow root otherwise it'll return the document
  128. if (typeof element.getRootNode === 'function') {
  129. const root = element.getRootNode();
  130. return root instanceof ShadowRoot ? root : null;
  131. }
  132. if (element instanceof ShadowRoot) {
  133. return element;
  134. }
  135. // when we don't find a shadow root
  136. if (!element.parentNode) {
  137. return null;
  138. }
  139. return findShadowRoot(element.parentNode);
  140. };
  141. const noop = () => {};
  142. /**
  143. * Trick to restart an element's animation
  144. *
  145. * @param {HTMLElement} element
  146. * @return void
  147. *
  148. * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
  149. */
  150. const reflow = element => {
  151. element.offsetHeight; // eslint-disable-line no-unused-expressions
  152. };
  153. const getjQuery = () => {
  154. if (window.jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  155. return window.jQuery;
  156. }
  157. return null;
  158. };
  159. const DOMContentLoadedCallbacks = [];
  160. const onDOMContentLoaded = callback => {
  161. if (document.readyState === 'loading') {
  162. // add listener on the first call when the document is in loading state
  163. if (!DOMContentLoadedCallbacks.length) {
  164. document.addEventListener('DOMContentLoaded', () => {
  165. for (const callback of DOMContentLoadedCallbacks) {
  166. callback();
  167. }
  168. });
  169. }
  170. DOMContentLoadedCallbacks.push(callback);
  171. } else {
  172. callback();
  173. }
  174. };
  175. const isRTL = () => document.documentElement.dir === 'rtl';
  176. const defineJQueryPlugin = plugin => {
  177. onDOMContentLoaded(() => {
  178. const $ = getjQuery();
  179. /* istanbul ignore if */
  180. if ($) {
  181. const name = plugin.NAME;
  182. const JQUERY_NO_CONFLICT = $.fn[name];
  183. $.fn[name] = plugin.jQueryInterface;
  184. $.fn[name].Constructor = plugin;
  185. $.fn[name].noConflict = () => {
  186. $.fn[name] = JQUERY_NO_CONFLICT;
  187. return plugin.jQueryInterface;
  188. };
  189. }
  190. });
  191. };
  192. const execute = (possibleCallback, args = [], defaultValue = possibleCallback) => {
  193. return typeof possibleCallback === 'function' ? possibleCallback(...args) : defaultValue;
  194. };
  195. const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
  196. if (!waitForTransition) {
  197. execute(callback);
  198. return;
  199. }
  200. const durationPadding = 5;
  201. const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
  202. let called = false;
  203. const handler = ({
  204. target
  205. }) => {
  206. if (target !== transitionElement) {
  207. return;
  208. }
  209. called = true;
  210. transitionElement.removeEventListener(TRANSITION_END, handler);
  211. execute(callback);
  212. };
  213. transitionElement.addEventListener(TRANSITION_END, handler);
  214. setTimeout(() => {
  215. if (!called) {
  216. triggerTransitionEnd(transitionElement);
  217. }
  218. }, emulatedDuration);
  219. };
  220. /**
  221. * Return the previous/next element of a list.
  222. *
  223. * @param {array} list The list of elements
  224. * @param activeElement The active element
  225. * @param shouldGetNext Choose to get next or previous element
  226. * @param isCycleAllowed
  227. * @return {Element|elem} The proper element
  228. */
  229. const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
  230. const listLength = list.length;
  231. let index = list.indexOf(activeElement);
  232. // if the element does not exist in the list return an element
  233. // depending on the direction and if cycle is allowed
  234. if (index === -1) {
  235. return !shouldGetNext && isCycleAllowed ? list[listLength - 1] : list[0];
  236. }
  237. index += shouldGetNext ? 1 : -1;
  238. if (isCycleAllowed) {
  239. index = (index + listLength) % listLength;
  240. }
  241. return list[Math.max(0, Math.min(index, listLength - 1))];
  242. };
  243. exports.defineJQueryPlugin = defineJQueryPlugin;
  244. exports.execute = execute;
  245. exports.executeAfterTransition = executeAfterTransition;
  246. exports.findShadowRoot = findShadowRoot;
  247. exports.getElement = getElement;
  248. exports.getNextActiveElement = getNextActiveElement;
  249. exports.getTransitionDurationFromElement = getTransitionDurationFromElement;
  250. exports.getUID = getUID;
  251. exports.getjQuery = getjQuery;
  252. exports.isDisabled = isDisabled;
  253. exports.isElement = isElement;
  254. exports.isRTL = isRTL;
  255. exports.isVisible = isVisible;
  256. exports.noop = noop;
  257. exports.onDOMContentLoaded = onDOMContentLoaded;
  258. exports.parseSelector = parseSelector;
  259. exports.reflow = reflow;
  260. exports.toType = toType;
  261. exports.triggerTransitionEnd = triggerTransitionEnd;
  262. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  263. }));
  264. //# sourceMappingURL=index.js.map