Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

browser-window

A web component that draws a browser window, or a phone or tablet, around a demo page or any HTML you put inside it. The Vanilla Breeze stylesheet sets the frame's colors, fonts and corner radius from the active theme.

At a glance

Package@profpowell/browser-window, version 1.4.9
Elements<browser-window>
Renders inShadow DOM. Content you place inside stays in the light DOM and is slotted into the frame. A page named by src loads in an iframe.
Sourcegithub.com/ProfPowell/browser-window, based on @zachleat/browser-window
Documentationprofpowell.github.io/browser-window
LicenceMIT
In Vanilla BreezeNot bundled. Vanilla Breeze lists it as a development dependency and imports it only in src/doc-extras.js, a bundle built for this docs site and left out of the npm package. You load the component yourself. The VB stylesheet does include the rules that theme it.

Install

Load the component from a CDN. It is one file with no stylesheet.

Or install it from npm and import it in your own script.

Demo

Two windows on a Vanilla Breeze page: one around inline content, one loading another page. The frame you are looking at is itself a <browser-window>.

Usage

Load a page into the frame with src. This also adds a view-source button, a download link and a share menu with a CodePen export.

Or put content between the tags. The url attribute only sets the text in the address bar.

Set device to draw a phone or tablet instead of a browser window.

The window can be resized by dragging its bottom-right corner. Set a starting size in CSS.

Reference

Attributes

AttributeValuesDefaultPurpose
srcURLNonePage to load in an iframe. Turns on the source view, download link and share menu.
urlTextNoneURL shown in the address bar. It is display only.
titleTextThe host name from urlTitle shown in the address bar.
modelight, darkFollows the page, then the operating systemFixes the color scheme.
shadowBooleanOffAdds a drop shadow.
deviceiphone-16, iphone-16-pro-max, iphone-se, pixel-9, pixel-9-pro-xl, galaxy-s24, ipad-air, ipad-pro-13, ipad-miniNoneDraws a phone or tablet frame. An unknown name falls back to iphone-16.
device-colormidnight, silver, gold, blue, whitemidnightColor of the device frame.
orientationportrait, landscapeportraitDevice orientation.
show-safe-areasBooleanOffIn device mode, tints the areas of the screen taken by the status bar and home indicator.
iframe-titleTexttitle, then url, then Embedded pageAccessible name of the iframe.
allowPermissions Policy list such as camera; microphoneNonePassed to the iframe's allow attribute.
allowfullscreenBooleanOffLets the framed page use the Fullscreen API.
referrerpolicyReferrer policy such as no-referrerNonePassed to the iframe.

Methods and properties

MemberPurpose
toggleMaximize()Opens the window as a centered overlay, or restores it.
toggleMinimize()Collapses the window to its header, or restores it.
toggleViewSource()Switches between the rendered page and its source. Returns a promise.
copySourceCode()Copies the fetched source to the clipboard. Returns a promise.
openInCodePen()Sends the page's HTML, CSS and JavaScript to CodePen.
shareViaWebAPI()Opens the system share sheet where the browser supports it.
url, src, mode, device, deviceColor, orientation, showSafeAreasProperties that mirror the attributes of the same name.
browserTitleProperty for the title attribute.
isMaximized, isMinimized, showSourceCurrent state, as booleans.

The component fires no custom events. It exposes two CSS parts for ::part(): header and content.

CSS custom properties

All properties start with --browser-window-. The table lists the suffix.

GroupProperties
Surfacesbg, header-bg, content-bg, url-bg, hover-bg, active-bg
Text and fontstext-color, text-muted, font-family, mono-font
Border and shapeborder-color, border-width, border-style, border-radius, inner-radius, shadow, margin
Controlsclose-color, minimize-color, maximize-color, accent-color
Device modebezel-color, status-bar-color, home-indicator-color, safe-area-color
Stackingz-index, overlay-z-index, menu-z-index

See the browser-window documentation for default values and more examples.

With Vanilla Breeze

A token is a CSS custom property that holds one design value, such as --color-surface. Two things connect the component to Vanilla Breeze tokens.

First, the component itself reads seven VB tokens as fallbacks.

VB tokenDrives
--color-surfaceWindow background, address bar background and content background
--color-surface-raisedHeader background
--color-borderBorder
--color-textText
--color-text-mutedMuted text, such as the address
--radius-mOuter corner radius
--radius-sRadius of the address bar and buttons

Second, the VB stylesheet contains a token bridge: a rule with the selector browser-window that sets the component's --browser-window-* properties from VB tokens. It ships in vanilla-breeze.css and vanilla-breeze-core.css, so there is no extra file to load and no attribute to add. Besides the tokens above, the bridge sets these.

VB tokenSet on
--color-surface-sunkenAddress bar background
--color-surface-altButton hover background
--color-interactiveAccent color
--color-error, --color-warning, --color-successThe close, minimize and maximize buttons
--font-sans, --font-monoInterface font and the font of the source view

For each color the order is: the --browser-window-* property if it is set, then the VB token, then the component's built-in color. With VB loaded, the bridge is what sets the --browser-window-* properties.

Light or dark is chosen separately. With no mode attribute, the component follows the nearest data-mode on itself or an ancestor, then page-level signals such as data-theme on <html>, then the operating system preference. When the framed page is on the same origin, it sets that page's color-scheme to match.

The bridge sits in a cascade layer, so any rule you write outside a layer wins. To change one window, set the property on it.

This docs site also styles the element with a data-demo-height attribute. That comes from the site's own stylesheet and is not part of the component.

Accessibility

↑