Skip to content

Theming ​

The viewer draws its own chrome (ribbon, backstage, status bar, Shapes window) from shared ooxml-ui controls. The element reads its colours from CSS custom properties, so a host can restyle it from its own stylesheet.

Shared --office-* tokens ​

The element follows the shared Office theme. When it connects it installs the ooxml-ui theme (installOfficeUiTheme, idempotent), and every colour it draws resolves from the --office-* custom properties, so the --office-* tokens are the primary way to theme it. Set them on :root, on a container, or on the element itself:

TokenRole
--office-backgroundRibbon, panel and dialog surface
--office-surfaceWindow background, secondary surface
--office-foregroundPrimary text
--office-muted-foregroundSecondary text
--office-borderBorders
--office-accentAccent colour
--office-accent-foregroundText on the accent colour
--office-ringFocus ring
--office-dangerDestructive and error states
--office-shadowPage shadow
css
visio-viewer {
	--office-accent: #c2431f;
	--office-accent-foreground: #ffffff;
}

Light and dark follow the suite theme: the viewer is light by default, dark when the system prefers it, and the data-office-theme="light" | "dark" attribute on the document root forces one. There is no theme property on the element; the same switch that themes the other Office elements on the page themes the viewer.

The default accent changed with this. The viewer used to hard-code #3955a3; it now takes --office-accent (#2563eb in light, #6366f1 in dark). A host that wants the previous colour sets --office-accent: #3955a3 or the --vv-accent override below.

Optional --vv-* overrides ​

The earlier --vv-* tokens still work. Each one, when set, wins over the --office-* token it aliases; when unset the viewer falls back to the shared token. Use them to restyle only this viewer without touching the rest of the page.

TokenFalls back toRole
--vv-font--office-fontFont family
--vv-background--office-surfaceWindow background
--vv-surface--office-backgroundRibbon and panel surface
--vv-secondary--office-surfaceSecondary surface
--vv-shadow--office-shadowPage shadow
--vv-ink--office-foregroundPrimary text
--vv-muted--office-muted-foregroundSecondary text
--vv-border--office-borderBorders
--vv-accent--office-accentAccent colour
--vv-accent-soft10% of the accentSoft accent surface (hover, selected)
--vv-accent-ink--office-accent-foregroundText on the accent colour
--vv-accent-text--vv-accent, then --office-accent-inkThe accent as text (current page tab, accent labels); keep it at 4.5:1 on the surface
--vv-focus--office-ringFocus ring
--vv-danger--office-dangerDestructive and error states

The playground sets data-theme="light" | "dark" on the document root and supplies matching --vv-* values in demos/visio/demo/workspace.css for its own page chrome (start screen, workspace shell); that file keeps working because --vv-* overrides still apply.

Following the docs site theme ​

This site stores the visitor's appearance choice in localStorage under the VitePress key vitepress-theme-appearance (light, dark or no value, which follows the system). All the viewer sites share the christophervr.github.io origin, and the playground (demos/visio/demo/suite-theme.js) reads the same key at start-up and updates live on the storage event, so toggling the theme on this site restyles an embedded viewer without reloading it or replacing its diagram.

ts
const key = 'vitepress-theme-appearance';
const resolve = (value: string | null) =>
	value === 'dark' || value === 'light'
		? value
		: matchMedia('(prefers-color-scheme: dark)').matches
			? 'dark'
			: 'light';

document.documentElement.dataset.theme = resolve(localStorage.getItem(key));
window.addEventListener('storage', (event) => {
	if (event.key === key || event.key === null)
		document.documentElement.dataset.theme = resolve(event.newValue);
});

Status bar theme ​

The status bar is neutral by default, like the other editors in the suite. Desktop Visio's "Colorful" Office theme fills it with the product colour instead. There are three ways to choose:

  • The user: File > Options > General > Office Theme (Colorful, White or Black, which is the dark theme). The choice is kept on the device.
  • The host: the status-bar attribute (colorful or neutral), or the statusBar property, on <visio-viewer>. A host's attribute wins over the saved choice.
  • Any colours: --vv-status-background and --vv-status-ink recolour the bar in either theme.
html
<visio-viewer status-bar="colorful"></visio-viewer>
<visio-viewer style="--vv-status-background: #1b5e20; --vv-status-ink: #fff"></visio-viewer>

Released under the Apache-2.0 License.