select-animation 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/select-animation.js +37 -27
package/package.json
CHANGED
package/select-animation.js
CHANGED
|
@@ -101,36 +101,46 @@
|
|
|
101
101
|
// Usage: select('.class', '#id')
|
|
102
102
|
// -----------------------------
|
|
103
103
|
// --- Enhanced DOM Selection Utility with Explicit Error Reporting ---
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// Warning if the selector is valid string but matches nothing
|
|
113
|
-
console.warn(`Select-Animation: No elements found matching the selector "${selector}".`);
|
|
114
|
-
}
|
|
115
|
-
return Array.from(nodes);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 3. Handle arrays or collections
|
|
119
|
-
if (Array.isArray(selector) || (selector && typeof selector.length === "number")) {
|
|
120
|
-
return Array.from(selector).filter(isElement);
|
|
104
|
+
// --- Enhanced DOM Selection Utility (Supports Multiple Arguments) ---
|
|
105
|
+
const selectDom = function (...selectors) {
|
|
106
|
+
const allElements = [];
|
|
107
|
+
|
|
108
|
+
// If no arguments were passed at all
|
|
109
|
+
if (selectors.length === 0) {
|
|
110
|
+
console.warn("Select-Animation: selectDom() was called without any arguments.");
|
|
111
|
+
return [];
|
|
121
112
|
}
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
selectors.forEach((selector) => {
|
|
115
|
+
// 1. If the argument is already a DOM element
|
|
116
|
+
if (isElement(selector)) {
|
|
117
|
+
allElements.push(selector);
|
|
118
|
+
}
|
|
119
|
+
// 2. If the argument is a string (Selector)
|
|
120
|
+
else if (typeof selector === "string") {
|
|
121
|
+
const nodes = document.querySelectorAll(selector);
|
|
122
|
+
if (nodes.length === 0) {
|
|
123
|
+
console.warn(`Select-Animation: No elements found for selector "${selector}".`);
|
|
124
|
+
} else {
|
|
125
|
+
// Spread the NodeList into our results array
|
|
126
|
+
allElements.push(...Array.from(nodes));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 3. If the argument is an array or collection
|
|
130
|
+
else if (Array.isArray(selector) || (selector && typeof selector.length === "number")) {
|
|
131
|
+
const filtered = Array.from(selector).filter(isElement);
|
|
132
|
+
allElements.push(...filtered);
|
|
133
|
+
}
|
|
134
|
+
// 4. INVALID INPUT: Alert the developer if they passed a number/null/etc.
|
|
135
|
+
else if (selector !== undefined && selector !== null) {
|
|
136
|
+
console.error(
|
|
137
|
+
`Select-Animation ERROR: Invalid selector type "${typeof selector}". ` +
|
|
138
|
+
`Expected String, Element, or Array, but received:`, selector
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
132
142
|
|
|
133
|
-
return
|
|
143
|
+
return allElements;
|
|
134
144
|
};
|
|
135
145
|
|
|
136
146
|
// -----------------------------
|