{"version":3,"file":"dom-C9pNCFiV.js","sources":["../../../app/frontend/src/yobbers/js/utils/dom.js"],"sourcesContent":["/**\n * Applies given styles to a DOM element\n * @param {HTMLElement} el - The DOM element to which styles should be applied\n * @param {Object} styles - An object containing style properties and their values\n */\nconst styles = (el, styles) => {\n for (const property in styles) {\n el.style[property] = styles[property];\n }\n};\n\n/**\n * Hides given DOM elements\n * @param {...HTMLElement} el - The DOM elements to hide\n */\nconst hide = (...el) => {\n [...el].forEach((e) => (e.style.display = 'none'));\n};\n\n/**\n * Shows given DOM elements\n * @param {...HTMLElement} el - The DOM elements to show\n */\nconst show = (...el) => {\n [...el].forEach((e) => (e.style.display = ''));\n};\n\n/**\n * Disables given DOM elements\n * @param {...HTMLElement} el - The DOM elements to disable\n */\nconst disable = (...el) =>\n [...el].forEach((e) => {\n e.classList.add('-disabled');\n e.readonly = true;\n });\n\n/**\n * Enables given DOM elements\n * @param {...HTMLElement} el - The DOM elements to enable\n */\nconst enable = (...el) =>\n [...el].forEach((e) => {\n e.classList.remove('-disabled');\n e.readonly = false;\n });\n\n/**\n * Returns a DOM element if valid, throws TypeError otherwise\n * @param {HTMLElement} element - The DOM element to validate\n * @returns {HTMLElement} - The valid DOM element\n * @throws {TypeError} - If the input is not a valid DOM element\n */\nconst getElement = (element) => {\n if (element.tagName) {\n return element;\n } else {\n throw new TypeError(\n `${element} is not a valid element. Valid options are: DOM Element.`\n );\n }\n};\n\n/**\n * Adds a class to a DOM element\n * @param {HTMLElement} element - The DOM element\n * @param {string} className - The class to add\n */\nconst addClass = (element, className) => {\n if (element.classList) {\n element.classList.add(className);\n } else {\n element.className += ` ${className}`;\n }\n};\n\n/**\n * Removes a class from a DOM element\n * @param {HTMLElement} element - The DOM element\n * @param {string} className - The class to remove\n */\nconst removeClass = (element, className) => {\n if (element.classList) {\n element.classList.remove(className);\n } else {\n const re = new RegExp(\n '(^|\\\\b)' + className.split(' ').join('|') + '(\\\\b|$)',\n 'gi'\n );\n element.className = element.className.replace(re, ' ');\n }\n};\n\n/**\n * Checks if a DOM element is visible in the viewport\n * @param {HTMLElement} el - The DOM element to check\n * @param {boolean} [partiallyVisible=false] - If true, checks if element is partially visible\n * @returns {boolean} - True if the element is (partially) visible, false otherwise\n */\nconst elementIsVisibleInViewport = (el, partiallyVisible = false) => {\n const { top, left, bottom, right } = el.getBoundingClientRect();\n const { innerHeight, innerWidth } = window;\n return partiallyVisible\n ? ((top > 0 && top < innerHeight) ||\n (bottom > 0 && bottom < innerHeight)) &&\n ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))\n : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;\n};\n\n/**\n * Gets a CSS rule value of a DOM element\n * @param {HTMLElement} el - The DOM element\n * @param {string} ruleName - The name of the CSS rule\n * @returns {string} - The CSS rule value\n */\nconst getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];\n\n/**\n * Toggles a class for a DOM element\n * @param {HTMLElement} el - The DOM element\n * @param {string} className - The class to toggle\n */\nconst toggleClass = (el, className) => el.classList.toggle(className);\n\n/**\n * Creates a DOM element from a string\n * @param {string} str - The string to convert into a DOM element\n * @returns {Node} - The DOM element\n */\nconst createElement = (str) => {\n const el = document.createElement('div');\n el.innerHTML = str;\n return el.firstElementChild;\n};\n\n/**\n * Checks if a target has a parent with a specific class\n * @param {Node} target - The target DOM node\n * @param {string} className - The class to look for\n * @returns {boolean} - True if a parent with the specified class is found, false otherwise\n */\nconst hasParentWithMatchingSelector = (target, className) => {\n return [...document.querySelectorAll(className)].some(\n (el) => el !== target && el.contains(target)\n );\n};\n\n/**\n * Adds an event listener to a DOM element with optional delegation and options\n * @param {HTMLElement} el - The DOM element\n * @param {string} evt - The event type\n * @param {Function} fn - The listener function\n * @param {Object} [opts={}] - Optional options for event delegation and listener options\n * @returns {Function} - The delegator function if target is specified in options, undefined otherwise\n */\nconst on = (el, evt, fn, opts = {}) => {\n const delegatorFn = (e) =>\n e.target.matches(opts.target) && fn.call(e.target, e);\n el.addEventListener(\n evt,\n opts.target ? delegatorFn : fn,\n opts.options || false\n );\n if (opts.target) return delegatorFn;\n};\n\n/**\n * Removes an event listener from a DOM element\n * @param {HTMLElement} el - The DOM element\n * @param {string} evt - The event type\n * @param {Function} fn - The listener function\n * @param {Object|boolean} [opts=false] - Optional options for the event listener\n */\nconst off = (el, evt, fn, opts = false) =>\n el.removeEventListener(evt, fn, opts);\n\n/**\n * Toggles a class for multiple DOM elements\n * @param {string} className - The class to toggle\n * @param {...HTMLElement} el - The DOM elements\n */\nconst toggleClasses = (className, ...el) =>\n [...el].forEach((e) => e.classList.toggle(className));\n\n/**\n * Creates and returns a debounced function that delays invoking the input function until after wait milliseconds have elapsed since the last time the debounced function was invoked\n * @param {Function} fn - The function to debounce\n * @param {number} [ms=0] - The number of milliseconds to delay\n * @returns {Function} - The debounced function\n */\nconst debounce = (fn, ms = 0) => {\n let timeoutId;\n return function (...args) {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => fn.apply(this, args), ms);\n };\n};\n\n/**\n * Copies a string to the clipboard\n * @param {string} str - The string to copy to the clipboard\n */\nconst copyToClipboard = (str) => {\n const el = document.createElement('textarea');\n el.value = str;\n el.setAttribute('readonly', '');\n el.style.position = 'absolute';\n el.style.left = '-9999px';\n document.body.appendChild(el);\n el.select();\n document.execCommand('copy');\n document.body.removeChild(el);\n};\n\nexport {\n styles,\n getStyle,\n hide,\n show,\n disable,\n enable,\n getElement,\n addClass,\n removeClass,\n elementIsVisibleInViewport,\n toggleClass,\n createElement,\n hasParentWithMatchingSelector,\n on,\n off,\n toggleClasses,\n debounce,\n copyToClipboard\n};\n"],"names":["styles","el","property","hide","show","getElement","element","addClass","className","removeClass","re","elementIsVisibleInViewport","partiallyVisible","top","left","bottom","right","innerHeight","innerWidth","getStyle","ruleName","createElement","str","hasParentWithMatchingSelector","target","on","evt","fn","opts","delegatorFn","e","debounce","ms","timeoutId","args","copyToClipboard"],"mappings":"AAKK,MAACA,EAAS,CAACC,EAAID,I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