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

Showing Changes

How to show what changed: tracked edits in prose, two images compared, and the difference between versions of a page. Which element fits which case.

Pick by what you are comparing

There is no single diff component. Showing a change means different things for an edited sentence, a redesigned screen and a superseded page, so each has its own element.

You haveUseThe reader gets
Edits marked in the text with <ins> and <del> <change-set> Buttons to see the edits, the new text alone or the old text alone
Two images, or two blocks of the same size <compare-surface> A divider to drag across them
Several versions of one page, each at an address <version-switcher> A picker that goes to a version, swaps it in, or shows a line diff against it
Two strings your own code compares Your diff, written out as <ins> and <del> inside a <change-set> The same three views

Tracked edits

<ins> and <del> are HTML's elements for added and removed text, and the library styles them wherever they appear. Wrap a group of related edits in <change-set> and readers can switch between three views: Tracking shows both, Final shows the text as it now stands, Original shows it as it was.

  • author and datetime make the caption above the edits.
  • view="final" or view="original" sets the starting view. Leave it off for Tracking.
  • controls="none" removes the buttons, for a fixed view. The views are plain CSS on the view attribute, so a fixed view needs no script.
  • On an individual <ins> or <del>, data-reason shows a short label before the change and data-author names who made it.

In Tracking view the start and end of each change are announced to screen readers, so the edit is not carried by colour and strike-through alone.

Two images

<compare-surface> takes exactly two children and lays the second over the first, with a divider between them. The first child shows on the start side and the second on the end side. The reader drags the divider or moves it with the arrow keys. Without script the two children sit side by side.

The children are told apart by order. There are no named slots. position sets where the divider starts, from 0 to 100, and label names the divider for assistive technology.

Versions of a page

<version-switcher> works from a list of versions, each with an id and usually a url. Give it the list inline in data-versions, as a JSON file in data-src, or through a vb:versions-manifest tag in the <head>. Mark the entry for the page being viewed with "current": true.

data-action decides what choosing a version does.

ActionChoosing a versionUse it when
navigate (default) Goes to that version's address Each version is a full page of its own, as with versioned documentation
swap Fetches that version and replaces the versioned region of this page with it You want the reader to stay in place while flipping between versions
diff Fetches that version, compares its text with this page's, and inserts a <change-set> showing the difference The question is what changed

What to know about swap and diff:

  • The versioned region is the first element with data-versioned, or <main> when the page has none. Put the attribute on <main>, as above, or on a smaller region inside it. To use a different selector, set data-versioned-region. The other version's page must have a matching region.
  • Both fetch the other version, so its address must be on the same origin as the page.
  • The diff compares text line by line. It does not understand markup: a reworded sentence shows as one line removed and one added, and formatting changes do not show at all.
  • The diff is placed before the region. data-diff-position="after" puts it after.
  • Swapped-in content passes through the library's sanitizer, which removes scripts and inline event handlers.

data-banner adds a notice when the version on screen is marked archived. Each action fires a cancellable event first (version-switcher:before-navigate, before-swap, before-diff), so your code can step in.

Your own comparison

To show the difference between two strings that are not pages, such as two saved drafts or two API responses, use the line comparison that <version-switcher> uses. The package exports it as two functions. diffLines(oldText, newText) returns a list of { type, text } entries, one per line, where type is 'eq', 'add' or 'del'. renderDiffFragment(ops) turns that list into a <pre class="text-diff"> with an <ins> for each added line and a <del> for each removed one.

Put the result inside a <change-set>, as here, and the component supplies the three views. The comparison works on whole lines and suits texts of up to a few thousand lines. For a word-level or markup-aware diff, use a diff library and write its output as <ins> and <del> elements inside a <change-set> in the same way.

What is not here

  • A side-by-side text diff. The Final and Original views of a <change-set> cover the same need in less width.
  • A review tool with comments pinned to changes and accept or reject controls. The <review-surface> element that earlier versions of this page named for that now ships in the separate vb-project-planning package, not in Vanilla Breeze.
  • A diff that understands HTML structure.
↑