1+ import { installWindowOnGlobal } from '@lit-labs/ssr/lib/dom-shim.js' ;
2+
13class ObserverShim {
24 observe ( ) : void {
35 void 0 ;
@@ -17,35 +19,7 @@ class MiniHTMLTemplateElement extends MiniHTMLElement {
1719 content = { cloneNode : ( ) : string => this . innerHTML } ;
1820}
1921
20- class MiniDocument {
21- createElement ( tagName : string ) : MiniHTMLElement {
22- switch ( tagName ) {
23- case 'template' :
24- return new MiniHTMLTemplateElement ( tagName ) ;
25- default :
26- return new MiniHTMLElement ( tagName ) ;
27- }
28- }
29- }
30-
31- // @ts -expect-error: this runs in node
32- globalThis . window ??= globalThis ;
33- // @ts -expect-error: this runs in node
34- globalThis . document ??= new MiniDocument ( ) ;
35- // @ts -expect-error: this runs in node
36- globalThis . navigator ??= { userAgent : '' } ;
37- // @ts -expect-error: opt in to event support in ssr
38- globalThis . litSsrCallConnectedCallback = true ;
39- // @ts -expect-error: this runs in node
40- globalThis . ErrorEvent ??= Event ;
41- // @ts -expect-error: this runs in node
42- globalThis . IntersectionObserver ??= ObserverShim ;
43- // @ts -expect-error: this runs in node
44- globalThis . MutationObserver ??= ObserverShim ;
45- // @ts -expect-error: this runs in node
46- globalThis . ResizeObserver ??= ObserverShim ;
47- // @ts -expect-error: this runs in node
48- globalThis . getComputedStyle ??= function ( ) {
22+ function getComputedStyle ( ) {
4923 return {
5024 getPropertyPriority ( ) {
5125 return '' ;
@@ -54,6 +28,27 @@ globalThis.getComputedStyle ??= function() {
5428 return '' ;
5529 } ,
5630 } ;
57- }
31+ } ;
5832
59- ;
33+ // @ts -expect-error: opt in to event support in ssr
34+ globalThis . litSsrCallConnectedCallback = true ;
35+
36+ installWindowOnGlobal ( {
37+ ErrorEvent : Event ,
38+ IntersectionObserver : ObserverShim ,
39+ MutationObserver : ObserverShim ,
40+ ResizeObserver : ObserverShim ,
41+ getComputedStyle,
42+ } ) ;
43+
44+ // @ts -expect-error: this runs in node
45+ globalThis . navigator . userAgent ??= '@lit-labs/ssr' ;
46+
47+ globalThis . document . createElement = function createElement ( tagName : string ) : HTMLElement {
48+ switch ( tagName ) {
49+ case 'template' :
50+ return new MiniHTMLTemplateElement ( tagName ) as unknown as HTMLElement ;
51+ default :
52+ return new MiniHTMLElement ( tagName ) as HTMLElement ;
53+ }
54+ } ;
0 commit comments