Skip to content

Commit ebdafe5

Browse files
authored
Merge pull request #4619 from Tyriar/tyriar/4611_2
Avoid using global document, add copyright
2 parents 17b8247 + a9662e8 commit ebdafe5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/browser/renderer/dom/StyleSheet.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
/**
2+
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
3+
* @license MIT
4+
*/
5+
16
export interface IStyleSheet {
27
dispose: () => void;
38
setCss: (value: string) => void;
49
}
510

6-
const createCssStyleSheet = (): IStyleSheet => {
11+
const createCssStyleSheet = (doc: Document): IStyleSheet => {
712
const sheet = new CSSStyleSheet();
8-
document.adoptedStyleSheets.push(sheet);
13+
doc.adoptedStyleSheets.push(sheet);
914
return {
1015
dispose() {
11-
const index = document.adoptedStyleSheets.indexOf(sheet);
12-
document.adoptedStyleSheets.splice(index, 1);
16+
const index = doc.adoptedStyleSheets.indexOf(sheet);
17+
doc.adoptedStyleSheets.splice(index, 1);
1318
},
1419
setCss(css) {
1520
sheet.replaceSync(css);
@@ -18,7 +23,8 @@ const createCssStyleSheet = (): IStyleSheet => {
1823
};
1924

2025
const createStyleElement = (parent: HTMLElement): IStyleSheet => {
21-
const element = document.createElement('style');
26+
const doc = parent.ownerDocument;
27+
const element = doc.createElement('style');
2228
parent.append(element);
2329
return {
2430
dispose() {
@@ -32,7 +38,7 @@ const createStyleElement = (parent: HTMLElement): IStyleSheet => {
3238

3339
export const createStyle = (parent: HTMLElement): IStyleSheet => {
3440
try {
35-
return createCssStyleSheet();
41+
return createCssStyleSheet(parent.ownerDocument);
3642
} catch {
3743
return createStyleElement(parent);
3844
}

0 commit comments

Comments
 (0)