feat(hub-ui): support transparent standalone viewers - #300
Conversation
|
@dvcolomban is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
|
I wonder if this would be in the branding object? I would kind prefer to note have dynamic assets which could be hard to control in some cases |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in createUi({ viewer: { background: 'transparent' } }) configuration to let the Hub UI standalone viewer render with a transparent document background, so apps embedding the viewer can visually “shine through” behind the iframe.
Changes:
- Extends
CreateUiOptions.viewerto accept an object withbackground: 'default' | 'transparent'. - Publishes a small runtime CSS asset (
__hub-ui.css) and ensures the standalone viewer HTML loads it before paint. - Adds tests + API snapshot updates and documents the new option.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/snapshots/tsnapi/@devframes/hub-ui/index.snapshot.d.ts | Updates public API snapshot to reflect the expanded viewer option type. |
| packages/hub-ui/src/index.ts | Implements the new viewer background option and serves the runtime CSS asset. |
| packages/hub-ui/src/index.test.ts | Adds coverage for the HTML link and the asset behavior in default/transparent/disabled modes. |
| packages/hub-ui/src/client/standalone/index.html | Loads the runtime CSS asset early via a <link rel="stylesheet">. |
| docs/content/1.guide/18.hub-initiate.md | Documents the new viewer option usage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@antfu Thanks for the review ! Indeed this was extracted from a local patch downstream and it included some downstream constraints (we inject pre-build federated design system sheets, hence the dynamic link), I've folded it in the base styling instead, much cleaner ! |
fd402e8 to
7892b85
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (1)
packages/hub-ui/src/index.test.ts:3
import.meta.dirnameis not a standard Node/Vite/Vitest field and will likely beundefinedat runtime, causing this test to fail when resolving the built HTML. Prefer resolving the file viaimport.meta.url(orfileURLToPath) instead, and drop the now-unusedjoinimport.
import { join } from 'node:path'
| logo?: BrandingLogo | ||
| wordmark?: BrandingLogo | ||
| primaryColor?: string | ||
| background: 'default' | 'transparent' |
There was a problem hiding this comment.
Would this better accept any CSS value? So background?: string | { light: string, dark: string }, and allow undefined for the default. This would allow not only transparent, but for custom devtools that want to add a bit shading to the background for example?
There was a problem hiding this comment.
Adopted in e0c898d. branding.background now accepts a CSS background string for both schemes or required light/dark values. The active value is validated with CSS.supports and applied through the existing static token; invalid values keep the default. I also browser-tested transparent, a translucent gradient, scheme switching, invalid fallback, and the opaque default.
What changed
createUi({ branding: { background } })accept any valid CSSbackgroundshorthand{ light, dark }variantsCSS.supports('background', value)and retain the default when it is invalid--devframes-viewer-backgroundtokencolor-scheme: normalso transparent and translucent backgrounds composite with the host pagebackgroundis omittedWhy
Applications embedding the standalone viewer may need its document background to match or composite with the surrounding host page. A CSS background value supports solid colors, gradients, images, alpha colors, and
transparentwithout adding a special mode for each case.The host page cannot reliably style a cross-origin iframe document, so the value travels through the existing branding configuration and is applied by the standalone viewer.
Usage
A string applies to both color schemes:
Implementation
The packaged viewer stylesheet remains static. Its HTML defines
--devframes-viewer-backgroundas#fffin light mode and#111in dark mode. The browser entry resolves the configured string or active light/dark variant, checks it withCSS.supports, and sets the token only when valid.Valid custom backgrounds enable a static selector that sets the document's
color-schemetonormal. This preserves iframe compositing fortransparent, alpha colors, and translucent gradients, while the component tree retains its light or darkcolor-schemefor native controls. Invalid values leave the default token untouched.The Hub publishes no request-specific stylesheet or extra asset route.
Visual comparison
Compatibility
Existing
createUi()calls retain the current opaque light and dark standalone viewer backgrounds. Disabling the standalone viewer withviewer: falsealso keeps its existing behavior. Background URLs are accepted as trusted application configuration.Validation
pnpm lintpnpm knippnpm typecheckpnpm test: 120 files passed, 1,323 tests passed, 9 skippedtransparentrevealed the host page