From f4fb797d0b4d2aa89214f35772a1902ce4a19138 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Thu, 3 Oct 2024 16:11:40 -0700 Subject: [PATCH 1/2] fix(mock-doc): add missing ShadowRoot window primitive --- .../hydrate-factory-closure.ts | 1 + src/mock-doc/shadow-root.ts | 62 +++++++++++++++++++ src/mock-doc/window.ts | 5 ++ 3 files changed, 68 insertions(+) create mode 100644 src/mock-doc/shadow-root.ts diff --git a/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts b/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts index c844358ed7e..690d30838a5 100644 --- a/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts +++ b/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts @@ -43,6 +43,7 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr var CSS = $stencilWindow.CSS; var CustomEvent = $stencilWindow.CustomEvent; var Document = $stencilWindow.Document; + var ShadowRoot = $stencilWindow.ShadowRoot; var DocumentFragment = $stencilWindow.DocumentFragment; var DocumentType = $stencilWindow.DocumentType; var DOMTokenList = $stencilWindow.DOMTokenList; diff --git a/src/mock-doc/shadow-root.ts b/src/mock-doc/shadow-root.ts new file mode 100644 index 00000000000..9b490ea8134 --- /dev/null +++ b/src/mock-doc/shadow-root.ts @@ -0,0 +1,62 @@ +import { MockDocumentFragment } from './document-fragment'; + +export class MockShadowRoot extends MockDocumentFragment { + get activeElement() { + return null; + } + + set adoptedStyleSheets(adoptedStyleSheets: any) { + throw new Error('Unimplemented'); + } + + get adoptedStyleSheets() { + return []; + } + + get cloneable() { + return false; + } + + get delegatesFocus() { + return false; + } + + get fullscreenElement() { + return null + } + + get host() { + let parent = this.parentElement(); + while (parent) { + if (parent.nodeType === 11) { + return parent; + } + parent = parent.parentElement(); + } + return null; + } + + get mode() { + return 'open'; + } + + get pictureInPictureElement() { + return null; + } + + get pointerLockElement() { + return null; + } + + get serializable() { + return false; + } + + get slotAssignment() { + return 'named' + } + + get styleSheets() { + return []; + } +} diff --git a/src/mock-doc/window.ts b/src/mock-doc/window.ts index 3c0bc5e408b..226984b5a53 100644 --- a/src/mock-doc/window.ts +++ b/src/mock-doc/window.ts @@ -22,6 +22,7 @@ import { MockNavigator } from './navigator'; import { MockElement, MockHTMLElement, MockNode, MockNodeList } from './node'; import { MockPerformance, resetPerformance } from './performance'; import { MockResizeObserver } from './resize-observer'; +import { MockShadowRoot } from './shadow-root'; import { MockStorage } from './storage'; const nativeClearInterval = clearInterval; @@ -188,6 +189,10 @@ export class MockWindow { this.__docFragCstr = docFragCstr; } + get ShadowRoot() { + return MockShadowRoot; + } + get DocumentType() { if (this.__docTypeCstr == null) { const ownerDocument = this.document; From 06822f5ae91d57718714f9accae5346d93fcc90f Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Thu, 3 Oct 2024 16:19:08 -0700 Subject: [PATCH 2/2] prettier --- src/mock-doc/shadow-root.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/mock-doc/shadow-root.ts b/src/mock-doc/shadow-root.ts index 9b490ea8134..0ba6f93f149 100644 --- a/src/mock-doc/shadow-root.ts +++ b/src/mock-doc/shadow-root.ts @@ -1,31 +1,31 @@ import { MockDocumentFragment } from './document-fragment'; export class MockShadowRoot extends MockDocumentFragment { - get activeElement() { + get activeElement(): HTMLElement | null { return null; } - set adoptedStyleSheets(adoptedStyleSheets: any) { + set adoptedStyleSheets(_adoptedStyleSheets: StyleSheet[]) { throw new Error('Unimplemented'); } - get adoptedStyleSheets() { + get adoptedStyleSheets(): StyleSheet[] { return []; } - get cloneable() { + get cloneable(): boolean { return false; } - get delegatesFocus() { + get delegatesFocus(): boolean { return false; } - get fullscreenElement() { - return null + get fullscreenElement(): HTMLElement | null { + return null; } - get host() { + get host(): HTMLElement | null { let parent = this.parentElement(); while (parent) { if (parent.nodeType === 11) { @@ -36,27 +36,27 @@ export class MockShadowRoot extends MockDocumentFragment { return null; } - get mode() { + get mode(): 'open' | 'closed' { return 'open'; } - get pictureInPictureElement() { + get pictureInPictureElement(): HTMLElement | null { return null; } - get pointerLockElement() { + get pointerLockElement(): HTMLElement | null { return null; } - get serializable() { + get serializable(): boolean { return false; } - get slotAssignment() { - return 'named' + get slotAssignment(): 'named' | 'manual' { + return 'named'; } - get styleSheets() { + get styleSheets(): StyleSheet[] { return []; } }