@aurodesignsystem/auro-library 2.0.0 → 2.1.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Semantic Release Automated Changelog
2
2
 
3
+ # [2.1.0](https://github.com/AlaskaAirlines/auro-library/compare/v2.0.0...v2.1.0) (2023-12-28)
4
+
5
+
6
+ ### Features
7
+
8
+ * **closest:** add closest element function [#43](https://github.com/AlaskaAirlines/auro-library/issues/43) ([f215c74](https://github.com/AlaskaAirlines/auro-library/commit/f215c746c59d70007da2b3fcad7dfb74420bd182))
9
+
3
10
  # [2.0.0](https://github.com/AlaskaAirlines/auro-library/compare/v1.1.0...v2.0.0) (2023-10-05)
4
11
 
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurodesignsystem/auro-library",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "This repository holds shared scripts, utilities, and workflows utilized acorss repositories along the Auro Design System.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -174,5 +174,21 @@ export default class AuroLibraryUtils {
174
174
  */
175
175
  fs.writeFileSync(destination, result, { encoding: 'utf8'});
176
176
  }
177
+
178
+ /**
179
+ * Finds and returns the closest HTML Element based on a selector.
180
+ */
181
+ closestElement(
182
+ selector, // selector like in .closest()
183
+ base = this, // extra functionality to skip a parent
184
+ __Closest = (el, found = el && el.closest(selector)) =>
185
+ !el || el === document || el === window
186
+ ? null // standard .closest() returns null for non-found selectors also
187
+ : found
188
+ ? found // found a selector INside this element
189
+ : __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
190
+ ) {
191
+ return __Closest(base);
192
+ }
177
193
  }
178
194