Skip to content

Commit a44effd

Browse files
asynclizcopybara-github
authored andcommitted
chore: move functions out of adoptStyles()
PiperOrigin-RevId: 896580802
1 parent 7baa861 commit a44effd

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

labs/gb/styles/adopt-styles.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,12 @@ export function adoptStyles(
4848
if (!owner) return;
4949

5050
styles = Array.isArray(styles) ? styles : [styles];
51-
const isCSSResult = (style: CSSResultOrNative): style is CSSResult =>
52-
'styleSheet' in style;
5351
const stylesheets: CSSStyleSheet[] = styles.map((cssResultOrNative) =>
5452
isCSSResult(cssResultOrNative)
5553
? cssResultOrNative.styleSheet!
5654
: cssResultOrNative,
5755
);
5856

59-
const adopt = (
60-
node: DocumentOrShadowRoot | Node | null,
61-
stylesheets: CSSStyleSheet[],
62-
): node is DocumentOrShadowRoot => {
63-
if (node && 'adoptedStyleSheets' in node) {
64-
node.adoptedStyleSheets = Array.from(
65-
new Set([...node.adoptedStyleSheets, ...stylesheets]),
66-
);
67-
return true;
68-
}
69-
return false;
70-
};
71-
7257
if (adopt(owner, stylesheets)) {
7358
// Styles adopted directly on the owner document or shadow root.
7459
return;
@@ -79,3 +64,20 @@ export function adoptStyles(
7964
adopt(owner.ownerDocument, stylesheets);
8065
adopt(owner.getRootNode(), stylesheets);
8166
}
67+
68+
function adopt(
69+
node: DocumentOrShadowRoot | Node | null,
70+
stylesheets: CSSStyleSheet[],
71+
): node is DocumentOrShadowRoot {
72+
if (node && 'adoptedStyleSheets' in node) {
73+
node.adoptedStyleSheets = Array.from(
74+
new Set([...node.adoptedStyleSheets, ...stylesheets]),
75+
);
76+
return true;
77+
}
78+
return false;
79+
}
80+
81+
function isCSSResult(style: CSSResultOrNative): style is CSSResult {
82+
return 'styleSheet' in style;
83+
}

0 commit comments

Comments
 (0)