Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion skills/deck/assets/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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}}
</style>
Expand Down Expand Up @@ -387,6 +394,7 @@ <h2>A theme is a set of CSS tokens</h2>
<h3>To brand a deck</h3>
<p>Set your colours, fonts and logo in the theme block, and every slide follows.</p>
<p>CSS for one deck goes in the last <code>&lt;style&gt;</code> block.</p>
<p>Set <code>--slide-transition</code> to <code>dissolve</code> and the slides fade into each other.</p>
</div>
<div>
<h3>Theme block</h3>
Expand All @@ -397,6 +405,7 @@ <h3>Theme block</h3>
--font-display:<span class="b">"Geist"</span>,…;
--font-mono:<span class="b">"Geist Mono"</span>,…;
--logo:<span class="b">none</span>;
--slide-transition:<span class="b">none</span>;
}</div>
</div>
</div>
Expand Down Expand Up @@ -627,6 +636,8 @@ <h1>Start from template.html</h1>
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 <span class="counter"> 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.
Expand Down Expand Up @@ -692,15 +703,32 @@ <h1>Start from template.html</h1>
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'));
Expand Down
5 changes: 5 additions & 0 deletions skills/deck/references/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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`.
21 changes: 20 additions & 1 deletion src/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span class="counter"> 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.
Expand Down Expand Up @@ -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'));
Expand Down
7 changes: 7 additions & 0 deletions src/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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}}
30 changes: 29 additions & 1 deletion template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down Expand Up @@ -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}}
</style>
Expand Down Expand Up @@ -387,6 +394,7 @@ <h2>A theme is a set of CSS tokens</h2>
<h3>To brand a deck</h3>
<p>Set your colours, fonts and logo in the theme block, and every slide follows.</p>
<p>CSS for one deck goes in the last <code>&lt;style&gt;</code> block.</p>
<p>Set <code>--slide-transition</code> to <code>dissolve</code> and the slides fade into each other.</p>
</div>
<div>
<h3>Theme block</h3>
Expand All @@ -397,6 +405,7 @@ <h3>Theme block</h3>
--font-display:<span class="b">"Geist"</span>,…;
--font-mono:<span class="b">"Geist Mono"</span>,…;
--logo:<span class="b">none</span>;
--slide-transition:<span class="b">none</span>;
}</div>
</div>
</div>
Expand Down Expand Up @@ -627,6 +636,8 @@ <h1>Start from template.html</h1>
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 <span class="counter"> 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.
Expand Down Expand Up @@ -692,15 +703,32 @@ <h1>Start from template.html</h1>
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'));
Expand Down
43 changes: 43 additions & 0 deletions test/deck.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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('</head>', '<style>:root{--slide-transition:dissolve}</style>\n</head>');
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');
Expand Down
Loading