-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8681f15
commit d501e5b
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class ObserverShim { | ||
observe(): void { | ||
void 0; | ||
} | ||
|
||
disconnect(): void { | ||
void 0; | ||
} | ||
} | ||
|
||
class MiniHTMLElement { | ||
innerHTML = ''; | ||
constructor(public tagName: string) { } | ||
} | ||
|
||
class MiniHTMLTemplateElement extends MiniHTMLElement { | ||
content = { cloneNode: (): string => this.innerHTML }; | ||
} | ||
|
||
class MiniDocument { | ||
createElement(tagName: string): MiniHTMLElement { | ||
switch (tagName) { | ||
case 'template': | ||
return new MiniHTMLTemplateElement(tagName); | ||
default: | ||
return new MiniHTMLElement(tagName); | ||
} | ||
} | ||
} | ||
|
||
// @ts-expect-error: this runs in node | ||
globalThis.window ??= globalThis; | ||
// @ts-expect-error: this runs in node | ||
globalThis.document ??= new MiniDocument(); | ||
// @ts-expect-error: this runs in node | ||
globalThis.navigator ??= { userAgent: '' }; | ||
// @ts-expect-error: this runs in node | ||
globalThis.ErrorEvent ??= Event; | ||
// @ts-expect-error: this runs in node | ||
globalThis.IntersectionObserver ??= ObserverShim; | ||
// @ts-expect-error: this runs in node | ||
globalThis.MutationObserver ??= ObserverShim; | ||
// @ts-expect-error: this runs in node | ||
globalThis.getComputedStyle ??= function() { | ||
return { | ||
getPropertyPriority() { | ||
return ''; | ||
}, | ||
getPropertyValue() { | ||
return ''; | ||
}, | ||
}; | ||
} | ||
|
||
; | ||
|