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…
An element that shows a JavaScript value as a tree you can expand, collapse, search and copy from. Its colors and spacing come from --json-viewer-* custom properties, which you point at Vanilla Breeze tokens with a few lines of CSS.
An order record shown as a tree, two levels open, with item counts. The viewer's colors, radius, font and spacing are mapped to Vanilla Breeze tokens in the page's CSS.
Usage
Write the JSON inside the element. The viewer reads its own text content when it has no data or src.
Set the data property from JavaScript. This accepts any value, including ones JSON cannot hold: Map, Set, Date, BigInt and objects that refer to themselves. Set it after the element is defined, as here.
The value to show. If the string is not valid JSON it is shown as a plain string. Use the data property for values JSON cannot hold.
src
URL
None
Fetched as JSON when the element is added to the page and whenever the attribute changes.
expanded
Whole number, true, false
1
How many levels start open. true or an empty value opens every level; false opens none.
mode
tree, raw
tree
raw shows indented JSON text instead of the tree. The toolbar's Raw button switches this attribute.
show-types
Boolean
Off
Adds a type label, such as string or array, after each value.
show-sizes
Boolean
Off
Shows the number of items in each array and object.
show-indices
Boolean
Off
Shows the position number before each array item.
indent
Whole number, in ch units
2
Indentation of each tree level, and the spacing of raw mode and copied JSON.
Methods and properties
A path names one node: users[0].name for objects and arrays, cache@0 for the first entry of a Map or Set, and $ for the root. In a pattern, * matches one segment and ** matches any number.
Member
Purpose
data
The value to show. Setting it removes the dataattribute and renders again.
expand(matcher), collapse(matcher)
Open or close the branches that match. The matcher is a path, a pattern with * or **, a RegExp, or a function that receives a path and returns true or false.
expandAll(), collapseAll()
Open or close every branch.
search(query, options)
Finds the query in keys and values, opens and scrolls to the first match, and returns an object with next(), prev(), current and count. Options: regex and caseSensitive, both off by default.
entryAt(path)
Returns { key, value } for a path. For a Map entry the key is the original key object, not a string.
copy(text)
Writes the text to the clipboard. With no argument it copies the whole value as JSON, writing each BigInt as a string ending in n.
Events
Both events bubble and cross the shadow boundary, so you can listen on any ancestor.
Event
Detail
Fired when
json-viewer:keyclick
{ path, key, value }
A key is activated. The viewer also shows the key's path in a bar under the toolbar.
json-viewer:valueclick
{ path, value, type }
A value is clicked.
CSS custom properties
Property
Built-in default
Drives
--json-viewer-surface
light-dark(#ffffff, #1c1917)
Background of the viewer, toolbar and inputs; text on pressed buttons.
--json-viewer-text
light-dark(#1c1917, #f4f4f5)
Main text.
--json-viewer-text-muted
light-dark(#71717a, #a1a1aa)
Disclosure arrows, sizes, type labels, indices, the match count.
--json-viewer-border
light-dark(#e7e5e4, #3f3f46)
Outer border, dividers, button borders, the guide line beside open branches.
--json-viewer-accent
light-dark(#0f766e, #2dd4bf)
Hover and focus borders, pressed buttons, search match highlight.
--json-viewer-radius
0.5rem
Corner radius. Buttons use 60% of it.
--json-viewer-font-mono
ui-monospace, then a list of monospace fonts
Font of the whole viewer.
--json-viewer-space-1 to --json-viewer-space-4
0.25rem, 0.5rem, 0.75rem, 1rem
Gaps and padding.
--json-viewer-key
light-dark(#7e22ce, #c084fc)
Object keys.
--json-viewer-string
light-dark(#15803d, #4ade80)
Strings, dates and regular expressions.
--json-viewer-number
light-dark(#1d4ed8, #60a5fa)
Numbers and BigInt values.
--json-viewer-boolean
light-dark(#a16207, #fbbf24)
Booleans and symbols.
--json-viewer-null
light-dark(#71717a, #a1a1aa)
null.
--json-viewer-punct
light-dark(#52525b, #a1a1aa)
Brackets, braces and colons.
--max-height
none
Maximum height of the tree area. Beyond it the tree scrolls and the toolbar stays in place.
The shadow tree also exposes five parts for ::part() styling: toolbar, search, path-bar, path and body.
Each value in the viewer is resolved in three steps:
The public hook, for example --json-viewer-surface.
A fallback named --vb-*, for example --vb-surface.
A built-in value, written with light-dark() for colors.
The package README calls step 2 the Vanilla Breeze fallback. In version 0.1.0 the literal names it reads are --vb-surface, --vb-text, --vb-text-muted, --vb-border, --vb-accent, --vb-radius, --vb-font-mono, --vb-space-1 to --vb-space-4, and --vb-json-key, --vb-json-string, --vb-json-number, --vb-json-boolean, --vb-json-null, --vb-json-punct.
Vanilla Breeze does not define any of those names. Its tokens are --color-*, --size-*, --font-* and --radius-*. So on a Vanilla Breeze page step 2 never matches, and the viewer shows its built-in colors unless you set step 1 yourself. This table gives the mapping:
Set this hook
To this VB token
Drives
--json-viewer-surface
--color-surface
Background.
--json-viewer-text
--color-text
Main text.
--json-viewer-text-muted
--color-text-muted
Secondary text.
--json-viewer-border
--color-border
Borders and dividers.
--json-viewer-accent
--color-interactive
Focus, pressed and match colors.
--json-viewer-radius
--radius-m
Corners.
--json-viewer-font-mono
--font-mono
Font.
--json-viewer-space-1 to -4
--size-2xs, --size-xs, --size-s, --size-m
Gaps and padding. These four tokens have the same default sizes as the viewer's built-in values.
Put the mapping in page CSS. A rule on json-viewer covers every instance; a rule on an id or other selector covers one.
Map json-viewer to VB tokens
json-viewer {color-scheme: inherit;--json-viewer-surface: var(--color-surface);--json-viewer-text: var(--color-text);--json-viewer-text-muted: var(--color-text-muted);--json-viewer-border: var(--color-border);--json-viewer-accent: var(--color-interactive);--json-viewer-radius: var(--radius-m);--json-viewer-font-mono: var(--font-mono);--json-viewer-space-1: var(--size-2xs);--json-viewer-space-2: var(--size-xs);--json-viewer-space-3: var(--size-s);--json-viewer-space-4: var(--size-m);}/* One instance: a taller limit and a different key color */#order {--max-height: 24rem;--json-viewer-key: var(--color-primary);}
The color-scheme: inherit line matters when the page forces a mode with data-mode. The viewer sets color-scheme: light dark on itself, which makes every light-dark() value inside it follow the operating system preference. That includes its built-in value colors (keys, strings, numbers) and any Vanilla Breeze token whose value is a light-dark() pair. Inheriting the scheme from the page keeps them in step with the mode the page is showing.
Accessibility
Each branch is a native <details> element, so Enter or Space on its summary opens and closes it. Branches below the starting depth are built the first time they open.
Keys are buttons. They can be reached with Tab, and activating one shows its path.
Press / while focus is in the viewer to open search. In the search field, Enter goes to the next match, Shift + Enter to the previous one, and Escape closes search.
The toolbar has role="toolbar" and each button has an aria-label. The Search and Raw buttons report their state with aria-pressed.
The tree area has role="tree" and each node has role="treeitem". The match count and the path bar are polite live regions, so changes are announced.
The per-row copy buttons appear on hover or focus within the row and are left out of the Tab order. The toolbar's Copy button is reachable by keyboard.
With prefers-reduced-motion: reduce the disclosure arrow does not animate. Moving to a search match still scrolls smoothly.
Links in the data (strings that start with http:// or https://) open in a new tab.