@augment-vir/web 31.57.4 → 31.58.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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The callback triggered for each depth traversal in {@link walkActiveElement}. If this returns
|
|
3
|
+
* `true`, the walking stops.
|
|
4
|
+
*
|
|
5
|
+
* @category Web : Elements
|
|
6
|
+
* @category Package : @augment-vir/web
|
|
7
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
8
|
+
*/
|
|
9
|
+
export type WalkActiveElementCallback = (params: {
|
|
10
|
+
element: Element;
|
|
11
|
+
depth: number;
|
|
12
|
+
}) => boolean | void | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Get the currently active element and walks the shadow dom to find, if any, the truly active
|
|
15
|
+
* element nested within the shadow dom.
|
|
16
|
+
*
|
|
17
|
+
* @category Web : Elements
|
|
18
|
+
* @category Package : @augment-vir/web
|
|
19
|
+
* @returns The depth that walking stopped at.
|
|
20
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
21
|
+
*/
|
|
22
|
+
export declare function walkActiveElement(callback: WalkActiveElementCallback): number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
/**
|
|
3
|
+
* Get the currently active element and walks the shadow dom to find, if any, the truly active
|
|
4
|
+
* element nested within the shadow dom.
|
|
5
|
+
*
|
|
6
|
+
* @category Web : Elements
|
|
7
|
+
* @category Package : @augment-vir/web
|
|
8
|
+
* @returns The depth that walking stopped at.
|
|
9
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
10
|
+
*/
|
|
11
|
+
export function walkActiveElement(callback) {
|
|
12
|
+
let depth = 0;
|
|
13
|
+
let activeElement = document.activeElement || undefined;
|
|
14
|
+
while (activeElement) {
|
|
15
|
+
if (callback({ depth, element: activeElement })) {
|
|
16
|
+
return depth;
|
|
17
|
+
}
|
|
18
|
+
activeElement = activeElement.shadowRoot?.activeElement || undefined;
|
|
19
|
+
if (activeElement) {
|
|
20
|
+
++depth;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return depth;
|
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export * from './augments/elements/overflow.js';
|
|
|
10
10
|
export * from './augments/elements/query-through-shadow.js';
|
|
11
11
|
export * from './augments/elements/tag-or-definition.js';
|
|
12
12
|
export * from './augments/elements/text-dimensions.js';
|
|
13
|
+
export * from './augments/elements/walk-active-element.js';
|
|
13
14
|
export * from './augments/image.js';
|
|
14
15
|
export * from './augments/video.js';
|
package/dist/index.js
CHANGED
|
@@ -10,5 +10,6 @@ export * from './augments/elements/overflow.js';
|
|
|
10
10
|
export * from './augments/elements/query-through-shadow.js';
|
|
11
11
|
export * from './augments/elements/tag-or-definition.js';
|
|
12
12
|
export * from './augments/elements/text-dimensions.js';
|
|
13
|
+
export * from './augments/elements/walk-active-element.js';
|
|
13
14
|
export * from './augments/image.js';
|
|
14
15
|
export * from './augments/video.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/web",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.58.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"test:update": "npm test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@augment-vir/assert": "^31.
|
|
40
|
-
"@augment-vir/common": "^31.
|
|
39
|
+
"@augment-vir/assert": "^31.58.0",
|
|
40
|
+
"@augment-vir/common": "^31.58.0",
|
|
41
41
|
"@date-vir/duration": "^8.1.0",
|
|
42
42
|
"html-spec-tags": "^2.2.3",
|
|
43
43
|
"type-fest": "^5.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/test": "^31.
|
|
46
|
+
"@augment-vir/test": "^31.58.0",
|
|
47
47
|
"bowser": "^2.13.1",
|
|
48
48
|
"typescript": "^5.9.3"
|
|
49
49
|
},
|