From e18ab3e700c0484570882bd640b3ffce35a7249c Mon Sep 17 00:00:00 2001 From: Victor Bahl Date: Mon, 30 Nov 2026 17:27:57 +0100 Subject: [PATCH] feat: a theme can change slides in a view transition A theme that sets --slide-transition on :root has the show change slides in a view transition, typed forward or backward, and animates it. Not in the edit view, the presenter's panes or print, nor for reduced motion. A browser without typed view transitions changes the slide at once. The default theme has a dissolve, off until --slide-transition is set to it. --- README.md | 19 ++++++++++++++ skills/deck/assets/template.html | 30 ++++++++++++++++++++- skills/deck/references/theming.md | 5 ++++ src/deck.js | 21 ++++++++++++++- src/theme.css | 7 +++++ template.html | 30 ++++++++++++++++++++- test/deck.spec.mjs | 43 +++++++++++++++++++++++++++++++ 7 files changed, 152 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d58c58..2947ada 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,25 @@ or a different title card, goes in the theme block or the deck-specific block. The tokens are listed in [`skills/deck/references/theming.md`](skills/deck/references/theming.md). +A theme can also change slides with a transition. The default theme has a +dissolve, off until you set `--slide-transition:dissolve`. With any value but +`none`, the show changes slides inside a +[view transition](https://developer.mozilla.org/docs/Web/API/View_Transition_API), +typed `forward` or `backward`, and the theme animates it: + +```css +:root{--slide-transition:dissolve} +/* the next slide fades in over this one, never through black */ +::view-transition-old(root){animation:none} +::view-transition-new(root){animation:.45s ease both dissolve} +@keyframes dissolve{from{opacity:0}} +/* by direction: html:active-view-transition-type(backward)::view-transition-new(root){…} */ +``` + +The edit view, the presenter's panes, print and reduced motion change slides +at once, and so does a browser without typed view transitions. How a build appears +is the theme's too: `.build` and `.build.on`. + Use only fonts whose license permits it, such as SIL Open Font License faces from Google Fonts, and fall back to generic families (`system-ui`, `serif`, `monospace`) so the deck still reads well offline. The default theme uses Geist diff --git a/skills/deck/assets/template.html b/skills/deck/assets/template.html index e609a49..00b51a1 100644 --- a/skills/deck/assets/template.html +++ b/skills/deck/assets/template.html @@ -101,6 +101,8 @@ --logo-dark/--icon-dark on .dark slides. --watermark is an optional large mark. */ --logo:none; --icon:none; --logo-dark:none; --icon-dark:none; --watermark:none; --watermark-dark:none; + /* how the show changes slides: none, or dissolve */ + --slide-transition:none; } /* slides (the engine places and scales them; the theme gives them their look) */ @@ -193,6 +195,11 @@ kbd{display:inline-block;min-width:1.3em;padding:9px 12px;border:1.5px solid var(--ink);border-radius:4px; font:500 .72em/1 var(--font-body);letter-spacing:0;text-align:center;margin-right:8px} +/* dissolve: the next slide fades in over this one, never through black */ +::view-transition-old(root){animation:none} +::view-transition-new(root){animation:.45s ease both dissolve} +@keyframes dissolve{from{opacity:0}} + /* print: the title card without its entrance */ @media print{.slide.title *{animation:none!important}} @@ -387,6 +394,7 @@

A theme is a set of CSS tokens

To brand a deck

Set your colours, fonts and logo in the theme block, and every slide follows.

CSS for one deck goes in the last <style> block.

+

Set --slide-transition to dissolve and the slides fade into each other.

Theme block

@@ -397,6 +405,7 @@

Theme block

--font-display:"Geist",…; --font-mono:"Geist Mono",…; --logo:none; + --slide-transition:none; }
@@ -627,6 +636,8 @@

Start from template.html

data-skip on a section left out of the show, its numbers and the print; the edit view still shows it data-public on the stage a public copy made in the edit view, to hand out: it has no edit view The engine sets .current on the slide shown, .on on each build revealed, and adds a to every slide. + Transitions: --slide-transition on :root, in the theme, changes slides in a view transition, typed forward or backward; + the theme animates ::view-transition-old(root) and ::view-transition-new(root). Builds are the theme's .build and .build.on. URL: ?print opens the print dialog once loaded; ?presenter is the presenter window; ?view is one read-only slide, used for the presenter's panes and the edit view's thumbnails and layout previews. The README describes the presenter and edit views. @@ -692,15 +703,32 @@

Start from template.html

select(null); } clearTimeout(autoTimer); + const from = i; i = clamp(n, 0, slides.length - 1); - slides.forEach((s, k) => s.classList.toggle('current', k === i)); + // the slide's builds are set while it is still hidden; then it shows, in a view transition when the theme has one builds(slides[i]).forEach(b => b.classList.toggle('on', built)); + turn(from, () => slides.forEach((s, k) => s.classList.toggle('current', k === i))); if (mode === 'deck') store.set(i); drawNotes(); if (mode === 'deck' && !built && slides[i].dataset.auto !== undefined) autoBuild(+slides[i].dataset.auto || 500); if (editing) drawEdit(); sync(); } + // Transitions. A theme that sets --slide-transition on :root (any value but none) has the show change slides inside + // document.startViewTransition, typed forward or backward, and animates ::view-transition-old(root) and -new(root). + // Not in the edit view, the presenter's panes or print, nor for reduced motion; in a browser without typed view + // transitions the slide just changes. The state (i, builds) changes at once, so a second press while one runs goes on + // from the new slide + const transitions = () => mode === 'deck' && !editing && 'types' in (window.ViewTransition?.prototype || {}) && + !matchMedia('(prefers-reduced-motion: reduce)').matches && + !['', 'none'].includes(getComputedStyle(document.documentElement).getPropertyValue('--slide-transition').trim()); + function turn(from, draw) { + if (from === i || !transitions()) return draw(); + const t = document.startViewTransition({ update: draw, types: [i > from ? 'forward' : 'backward'] }); + // a press while one runs skips its animation; that is expected, not an error + t.ready.catch(() => {}); + t.finished.catch(() => {}); + } function autoBuild(delay) { const step = () => { const b = builds(slides[i]).find(x => !x.classList.contains('on')); diff --git a/skills/deck/references/theming.md b/skills/deck/references/theming.md index 2f59489..9dd6b99 100644 --- a/skills/deck/references/theming.md +++ b/skills/deck/references/theming.md @@ -20,6 +20,7 @@ CSS under `/* deck-specific */`. The `data-deck="engine"` blocks are never edite | `--logo` / `--icon` | Logo on light slides (bottom-left) / icon on title and closing | `none` | | `--logo-dark` / `--icon-dark` | The same, on `.dark` slides | `none` | | `--watermark` / `--watermark-dark` | Optional large low-contrast mark, bottom-right | `none` | +| `--slide-transition` | How the show changes slides: `none` or `dissolve`, see [Transitions](#transitions) | `none` | `--ink`, `--muted`, `--accent`, `--panel` and `--paper` are derived from the tokens above and re-pointed by `.dark`; don't set them in `:root`. @@ -89,3 +90,7 @@ h1,h2{font-family:var(--font-body);text-transform:uppercase;letter-spacing:.01em Override, don't fork: keep the engine blocks intact, so `deckfile update` can bring in later engine fixes without merge pain. + +## Transitions + +`--slide-transition` on `:root`, set to any value but `none`, makes the show change slides inside a view transition, typed `forward` or `backward`. The theme animates `::view-transition-old(root)` and `::view-transition-new(root)`, by direction with `html:active-view-transition-type(backward)`. Keep it short and calm. The default theme has a dissolve, off until you set `--slide-transition:dissolve`. The edit view, the presenter's panes, print and reduced motion change slides at once. How a build appears is `.build` and `.build.on`. diff --git a/src/deck.js b/src/deck.js index 64ed6d0..66f8751 100644 --- a/src/deck.js +++ b/src/deck.js @@ -18,6 +18,8 @@ data-skip on a section left out of the show, its numbers and the print; the edit view still shows it data-public on the stage a public copy made in the edit view, to hand out: it has no edit view The engine sets .current on the slide shown, .on on each build revealed, and adds a to every slide. + Transitions: --slide-transition on :root, in the theme, changes slides in a view transition, typed forward or backward; + the theme animates ::view-transition-old(root) and ::view-transition-new(root). Builds are the theme's .build and .build.on. URL: ?print opens the print dialog once loaded; ?presenter is the presenter window; ?view is one read-only slide, used for the presenter's panes and the edit view's thumbnails and layout previews. The README describes the presenter and edit views. @@ -83,15 +85,32 @@ select(null); } clearTimeout(autoTimer); + const from = i; i = clamp(n, 0, slides.length - 1); - slides.forEach((s, k) => s.classList.toggle('current', k === i)); + // the slide's builds are set while it is still hidden; then it shows, in a view transition when the theme has one builds(slides[i]).forEach(b => b.classList.toggle('on', built)); + turn(from, () => slides.forEach((s, k) => s.classList.toggle('current', k === i))); if (mode === 'deck') store.set(i); drawNotes(); if (mode === 'deck' && !built && slides[i].dataset.auto !== undefined) autoBuild(+slides[i].dataset.auto || 500); if (editing) drawEdit(); sync(); } + // Transitions. A theme that sets --slide-transition on :root (any value but none) has the show change slides inside + // document.startViewTransition, typed forward or backward, and animates ::view-transition-old(root) and -new(root). + // Not in the edit view, the presenter's panes or print, nor for reduced motion; in a browser without typed view + // transitions the slide just changes. The state (i, builds) changes at once, so a second press while one runs goes on + // from the new slide + const transitions = () => mode === 'deck' && !editing && 'types' in (window.ViewTransition?.prototype || {}) && + !matchMedia('(prefers-reduced-motion: reduce)').matches && + !['', 'none'].includes(getComputedStyle(document.documentElement).getPropertyValue('--slide-transition').trim()); + function turn(from, draw) { + if (from === i || !transitions()) return draw(); + const t = document.startViewTransition({ update: draw, types: [i > from ? 'forward' : 'backward'] }); + // a press while one runs skips its animation; that is expected, not an error + t.ready.catch(() => {}); + t.finished.catch(() => {}); + } function autoBuild(delay) { const step = () => { const b = builds(slides[i]).find(x => !x.classList.contains('on')); diff --git a/src/theme.css b/src/theme.css index a18156d..0445b9e 100644 --- a/src/theme.css +++ b/src/theme.css @@ -17,6 +17,8 @@ --logo-dark/--icon-dark on .dark slides. --watermark is an optional large mark. */ --logo:none; --icon:none; --logo-dark:none; --icon-dark:none; --watermark:none; --watermark-dark:none; + /* how the show changes slides: none, or dissolve */ + --slide-transition:none; } /* slides (the engine places and scales them; the theme gives them their look) */ @@ -109,5 +111,10 @@ a{color:inherit} kbd{display:inline-block;min-width:1.3em;padding:9px 12px;border:1.5px solid var(--ink);border-radius:4px; font:500 .72em/1 var(--font-body);letter-spacing:0;text-align:center;margin-right:8px} +/* dissolve: the next slide fades in over this one, never through black */ +::view-transition-old(root){animation:none} +::view-transition-new(root){animation:.45s ease both dissolve} +@keyframes dissolve{from{opacity:0}} + /* print: the title card without its entrance */ @media print{.slide.title *{animation:none!important}} diff --git a/template.html b/template.html index e609a49..00b51a1 100644 --- a/template.html +++ b/template.html @@ -101,6 +101,8 @@ --logo-dark/--icon-dark on .dark slides. --watermark is an optional large mark. */ --logo:none; --icon:none; --logo-dark:none; --icon-dark:none; --watermark:none; --watermark-dark:none; + /* how the show changes slides: none, or dissolve */ + --slide-transition:none; } /* slides (the engine places and scales them; the theme gives them their look) */ @@ -193,6 +195,11 @@ kbd{display:inline-block;min-width:1.3em;padding:9px 12px;border:1.5px solid var(--ink);border-radius:4px; font:500 .72em/1 var(--font-body);letter-spacing:0;text-align:center;margin-right:8px} +/* dissolve: the next slide fades in over this one, never through black */ +::view-transition-old(root){animation:none} +::view-transition-new(root){animation:.45s ease both dissolve} +@keyframes dissolve{from{opacity:0}} + /* print: the title card without its entrance */ @media print{.slide.title *{animation:none!important}} @@ -387,6 +394,7 @@

A theme is a set of CSS tokens

To brand a deck

Set your colours, fonts and logo in the theme block, and every slide follows.

CSS for one deck goes in the last <style> block.

+

Set --slide-transition to dissolve and the slides fade into each other.

Theme block

@@ -397,6 +405,7 @@

Theme block

--font-display:"Geist",…; --font-mono:"Geist Mono",…; --logo:none; + --slide-transition:none; }
@@ -627,6 +636,8 @@

Start from template.html

data-skip on a section left out of the show, its numbers and the print; the edit view still shows it data-public on the stage a public copy made in the edit view, to hand out: it has no edit view The engine sets .current on the slide shown, .on on each build revealed, and adds a to every slide. + Transitions: --slide-transition on :root, in the theme, changes slides in a view transition, typed forward or backward; + the theme animates ::view-transition-old(root) and ::view-transition-new(root). Builds are the theme's .build and .build.on. URL: ?print opens the print dialog once loaded; ?presenter is the presenter window; ?view is one read-only slide, used for the presenter's panes and the edit view's thumbnails and layout previews. The README describes the presenter and edit views. @@ -692,15 +703,32 @@

Start from template.html

select(null); } clearTimeout(autoTimer); + const from = i; i = clamp(n, 0, slides.length - 1); - slides.forEach((s, k) => s.classList.toggle('current', k === i)); + // the slide's builds are set while it is still hidden; then it shows, in a view transition when the theme has one builds(slides[i]).forEach(b => b.classList.toggle('on', built)); + turn(from, () => slides.forEach((s, k) => s.classList.toggle('current', k === i))); if (mode === 'deck') store.set(i); drawNotes(); if (mode === 'deck' && !built && slides[i].dataset.auto !== undefined) autoBuild(+slides[i].dataset.auto || 500); if (editing) drawEdit(); sync(); } + // Transitions. A theme that sets --slide-transition on :root (any value but none) has the show change slides inside + // document.startViewTransition, typed forward or backward, and animates ::view-transition-old(root) and -new(root). + // Not in the edit view, the presenter's panes or print, nor for reduced motion; in a browser without typed view + // transitions the slide just changes. The state (i, builds) changes at once, so a second press while one runs goes on + // from the new slide + const transitions = () => mode === 'deck' && !editing && 'types' in (window.ViewTransition?.prototype || {}) && + !matchMedia('(prefers-reduced-motion: reduce)').matches && + !['', 'none'].includes(getComputedStyle(document.documentElement).getPropertyValue('--slide-transition').trim()); + function turn(from, draw) { + if (from === i || !transitions()) return draw(); + const t = document.startViewTransition({ update: draw, types: [i > from ? 'forward' : 'backward'] }); + // a press while one runs skips its animation; that is expected, not an error + t.ready.catch(() => {}); + t.finished.catch(() => {}); + } function autoBuild(delay) { const step = () => { const b = builds(slides[i]).find(x => !x.classList.contains('on')); diff --git a/test/deck.spec.mjs b/test/deck.spec.mjs index dc23f85..bed1485 100644 --- a/test/deck.spec.mjs +++ b/test/deck.spec.mjs @@ -468,6 +468,49 @@ test.describe('slide view', () => { expect(pv.url()).toContain('?presenter'); }); + test('a theme with --slide-transition changes slides in a view transition, typed by direction', async ({ page }) => { + // record each view transition the engine starts, and its types + const spy = () => { + window.vts = []; + const start = document.startViewTransition.bind(document); + document.startViewTransition = o => { window.vts.push(o.types); return start(o); }; + }; + const themed = readFileSync(deck, 'utf8').replace('', '\n'); + await page.goto(pathToFileURL(tempFile(themed)).href); + await page.evaluate(spy); + await page.keyboard.press('ArrowDown'); + await expect.poll(() => current(page)).toBe(1); + await page.keyboard.press('ArrowUp'); + await expect.poll(() => current(page)).toBe(0); + expect(await page.evaluate(() => window.vts)).toEqual([['forward'], ['backward']]); + // a build is not a change of slide; nor is the edit view; reduced motion has none + const { manual } = await info(page); + await goTo(page, manual); + await page.evaluate(() => { window.vts = []; }); + await page.keyboard.press('ArrowRight'); + await page.keyboard.press('e'); + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('Escape'); + await page.emulateMedia({ reducedMotion: 'reduce' }); + await page.keyboard.press('ArrowDown'); + expect(await page.evaluate(() => window.vts)).toEqual([]); + // with none, as in the default theme, slides change at once + await page.goto(url); + await page.evaluate(spy); + await page.keyboard.press('ArrowDown'); + expect(await current(page)).toBe(1); + expect(await page.evaluate(() => window.vts)).toEqual([]); + // nor in a browser whose view transitions have no types + await page.goto(pathToFileURL(tempFile(themed)).href); + await page.emulateMedia({ reducedMotion: null }); + await page.evaluate(spy); + await page.evaluate(() => { delete ViewTransition.prototype.types; }); + const was = await current(page); + await page.keyboard.press('ArrowDown'); + expect(await current(page)).toBe(was + 1); + expect(await page.evaluate(() => window.vts)).toEqual([]); + }); + test('the help button shows the shortcuts until they are dismissed', async ({ page }) => { const size = page.viewportSize(); const controls = page.locator('#deck-controls'), help = page.locator('#deck-help'), button = page.locator('.c-help');