@koine/dom 2.0.0-alpha.1 → 2.0.0-alpha.3
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/getVisualBackground.d.ts +6 -0
- package/getVisualBackground.js +25 -0
- package/getVisualBackground.mjs +21 -0
- package/package.json +2 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the background color of an element eventually looking recursively into
|
|
3
|
+
* its parents, if nothing is found it returns a `#fff` background
|
|
4
|
+
*/
|
|
5
|
+
export declare function getVisualBackgroundColor(elem?: null | HTMLElement): string;
|
|
6
|
+
export default getVisualBackgroundColor;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVisualBackgroundColor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get the background color of an element eventually looking recursively into
|
|
6
|
+
* its parents, if nothing is found it returns a `#fff` background
|
|
7
|
+
*/
|
|
8
|
+
function getVisualBackgroundColor(elem) {
|
|
9
|
+
if (!elem)
|
|
10
|
+
return "#fff";
|
|
11
|
+
var transparent = "rgba(0, 0, 0, 0)";
|
|
12
|
+
var transparentIE11 = "transparent";
|
|
13
|
+
// if (!elem) return transparent;
|
|
14
|
+
var bg = window.getComputedStyle(elem).backgroundColor;
|
|
15
|
+
if (bg === transparent || bg === transparentIE11) {
|
|
16
|
+
var parent_1 = elem.parentElement;
|
|
17
|
+
if (parent_1) {
|
|
18
|
+
return getVisualBackgroundColor(parent_1);
|
|
19
|
+
}
|
|
20
|
+
return "#fff";
|
|
21
|
+
}
|
|
22
|
+
return bg;
|
|
23
|
+
}
|
|
24
|
+
exports.getVisualBackgroundColor = getVisualBackgroundColor;
|
|
25
|
+
exports.default = getVisualBackgroundColor;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the background color of an element eventually looking recursively into
|
|
3
|
+
* its parents, if nothing is found it returns a `#fff` background
|
|
4
|
+
*/
|
|
5
|
+
export function getVisualBackgroundColor(elem) {
|
|
6
|
+
if (!elem)
|
|
7
|
+
return "#fff";
|
|
8
|
+
var transparent = "rgba(0, 0, 0, 0)";
|
|
9
|
+
var transparentIE11 = "transparent";
|
|
10
|
+
// if (!elem) return transparent;
|
|
11
|
+
var bg = window.getComputedStyle(elem).backgroundColor;
|
|
12
|
+
if (bg === transparent || bg === transparentIE11) {
|
|
13
|
+
var parent_1 = elem.parentElement;
|
|
14
|
+
if (parent_1) {
|
|
15
|
+
return getVisualBackgroundColor(parent_1);
|
|
16
|
+
}
|
|
17
|
+
return "#fff";
|
|
18
|
+
}
|
|
19
|
+
return bg;
|
|
20
|
+
}
|
|
21
|
+
export default getVisualBackgroundColor;
|
package/package.json
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/dom",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"dependencies": {
|
|
5
|
-
"clsx": "1.2.1",
|
|
6
|
-
"ts-debounce": "^4.0.0",
|
|
7
|
-
"type-fest": "^3.6.0"
|
|
8
|
-
},
|
|
9
4
|
"peerDependencies": {
|
|
10
|
-
"tslib": "
|
|
5
|
+
"tslib": "2.5.3"
|
|
11
6
|
},
|
|
12
7
|
"main": "./index.js",
|
|
13
8
|
"types": "./index.d.ts",
|
|
14
|
-
"version": "2.0.0-alpha.
|
|
9
|
+
"version": "2.0.0-alpha.3",
|
|
15
10
|
"module": "./index.mjs"
|
|
16
11
|
}
|