@skbkontur/icons 1.13.0-getrootnode-fix.0 → 1.13.0-getrootnode-fix.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/esm/internal/injectCss.js +11 -10
- package/internal/injectCss.js +11 -10
- package/package.json +1 -1
|
@@ -6,10 +6,17 @@ function checkRuleExists(rootNodeStyles, cssText) {
|
|
|
6
6
|
/**
|
|
7
7
|
* ponyfill for old browsers aka ie11, delete after drop support
|
|
8
8
|
*/
|
|
9
|
-
function getRootNode(
|
|
9
|
+
function getRootNode(element) {
|
|
10
10
|
return typeof Node === 'function' && Object.prototype.hasOwnProperty.call(Node.prototype, 'getRootNode')
|
|
11
|
-
?
|
|
12
|
-
:
|
|
11
|
+
? element.getRootNode()
|
|
12
|
+
: element.ownerDocument;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* not attached element can return the root of the DOM tree it belongs to, or itself - HTMLElement, Text, etc
|
|
16
|
+
*/
|
|
17
|
+
function getRootNodeWithAdoptedStyleSheets(element) {
|
|
18
|
+
var rootNode = getRootNode(element);
|
|
19
|
+
return rootNode instanceof Document || rootNode instanceof ShadowRoot ? rootNode : element.ownerDocument;
|
|
13
20
|
}
|
|
14
21
|
/**
|
|
15
22
|
* Whether the current browser supports `adoptedStyleSheets`.
|
|
@@ -22,13 +29,7 @@ var supportsAdoptingStyleSheets = Boolean(typeof window !== 'undefined' &&
|
|
|
22
29
|
'replace' in CSSStyleSheet.prototype);
|
|
23
30
|
export function injectCss(element) {
|
|
24
31
|
var _a;
|
|
25
|
-
var rootNode =
|
|
26
|
-
if (!rootNode) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (rootNode === element) {
|
|
30
|
-
rootNode = element.ownerDocument;
|
|
31
|
-
}
|
|
32
|
+
var rootNode = getRootNodeWithAdoptedStyleSheets(element);
|
|
32
33
|
if (supportsAdoptingStyleSheets) {
|
|
33
34
|
var currentWindow = element.ownerDocument.defaultView;
|
|
34
35
|
if (!currentWindow) {
|
package/internal/injectCss.js
CHANGED
|
@@ -9,10 +9,17 @@ function checkRuleExists(rootNodeStyles, cssText) {
|
|
|
9
9
|
/**
|
|
10
10
|
* ponyfill for old browsers aka ie11, delete after drop support
|
|
11
11
|
*/
|
|
12
|
-
function getRootNode(
|
|
12
|
+
function getRootNode(element) {
|
|
13
13
|
return typeof Node === 'function' && Object.prototype.hasOwnProperty.call(Node.prototype, 'getRootNode')
|
|
14
|
-
?
|
|
15
|
-
:
|
|
14
|
+
? element.getRootNode()
|
|
15
|
+
: element.ownerDocument;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* not attached element can return the root of the DOM tree it belongs to, or itself - HTMLElement, Text, etc
|
|
19
|
+
*/
|
|
20
|
+
function getRootNodeWithAdoptedStyleSheets(element) {
|
|
21
|
+
var rootNode = getRootNode(element);
|
|
22
|
+
return rootNode instanceof Document || rootNode instanceof ShadowRoot ? rootNode : element.ownerDocument;
|
|
16
23
|
}
|
|
17
24
|
/**
|
|
18
25
|
* Whether the current browser supports `adoptedStyleSheets`.
|
|
@@ -25,13 +32,7 @@ var supportsAdoptingStyleSheets = Boolean(typeof window !== 'undefined' &&
|
|
|
25
32
|
'replace' in CSSStyleSheet.prototype);
|
|
26
33
|
function injectCss(element) {
|
|
27
34
|
var _a;
|
|
28
|
-
var rootNode =
|
|
29
|
-
if (!rootNode) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (rootNode === element) {
|
|
33
|
-
rootNode = element.ownerDocument;
|
|
34
|
-
}
|
|
35
|
+
var rootNode = getRootNodeWithAdoptedStyleSheets(element);
|
|
35
36
|
if (supportsAdoptingStyleSheets) {
|
|
36
37
|
var currentWindow = element.ownerDocument.defaultView;
|
|
37
38
|
if (!currentWindow) {
|