2a5bac2bb3
* major JSDoc write up * removed ESLint `no-bitwise` exception, it only applies to specific functions and not the entire code * the `SVGCubicMorph` component will remove un-necessary `Z` path commands when is the case for better out of the box animation * fixed a minor disambiguation with `filterEffects` and `drop-shadow` property and its `dropshadow` interpolation function * TypeScript strong: all files are modules, easy to implement in any third party app * updated `CubicBezier` and SVGPathCommander * code cleanup
27 lines
825 B
JavaScript
27 lines
825 B
JavaScript
/**
|
|
* selector
|
|
*
|
|
* A selector utility for KUTE.js.
|
|
*
|
|
* @param {KUTE.selectorType} el target(s) or string selector
|
|
* @param {boolean | number} multi when true returns an array/collection of elements
|
|
* @returns {Element | Element[] | null}
|
|
*/
|
|
export default function selector(el, multi) {
|
|
try {
|
|
let requestedElem;
|
|
let itemsArray;
|
|
if (multi) {
|
|
itemsArray = el instanceof Array && el.every((x) => x instanceof Element);
|
|
requestedElem = el instanceof HTMLCollection || el instanceof NodeList || itemsArray
|
|
? el : document.querySelectorAll(el);
|
|
} else {
|
|
requestedElem = el instanceof Element || el === window // scroll
|
|
? el : document.querySelector(el);
|
|
}
|
|
return requestedElem;
|
|
} catch (e) {
|
|
throw TypeError(`KUTE.js - Element(s) not found: ${el}.`);
|
|
}
|
|
}
|