Skip to content

Commit a51a445

Browse files
committed
refactor(hub-ui): clarify viewer background application
1 parent e0c898d commit a51a445

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • packages/hub-ui/src/client/standalone

packages/hub-ui/src/client/standalone/main.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ import { DEFAULT_DOCK_SESSION_STORE } from '../state/docks'
1818
// off the document lets custom backgrounds composite with the host page.
1919
const brandingBackground = useBrandingBackground()
2020

21+
function applyViewerBackground(documentElement: HTMLElement, background: string | undefined): void {
22+
if (background === undefined || !CSS.supports('background', background)) {
23+
documentElement.classList.remove('viewer-background-custom')
24+
documentElement.style.removeProperty('--devframes-viewer-background')
25+
return
26+
}
27+
28+
documentElement.classList.add('viewer-background-custom')
29+
documentElement.style.setProperty('--devframes-viewer-background', background)
30+
}
31+
2132
watchEffect(() => {
2233
const el = document.documentElement
2334
el.classList.toggle('dark', isDark.value)
2435
el.classList.toggle('light', !isDark.value)
25-
26-
const background = brandingBackground.value
27-
const hasValidBackground = background !== undefined && CSS.supports('background', background)
28-
el.classList.toggle('viewer-background-custom', hasValidBackground)
29-
if (hasValidBackground)
30-
el.style.setProperty('--devframes-viewer-background', background)
31-
else
32-
el.style.removeProperty('--devframes-viewer-background')
36+
applyViewerBackground(el, brandingBackground.value)
3337
})
3438

3539
async function main(): Promise<void> {

0 commit comments

Comments
 (0)