@open-slide/core 1.15.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{build-CTCrO_M-.js → build-DaL4Gjn-.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-HXg3KTTo.js → config-CCHio3pk.js} +39 -11
- package/dist/{config-CE2sKgqH.d.ts → config-DIvIP8vY.d.ts} +1 -1
- package/dist/{dev-2FgsKkoD.js → dev-DLRQoCkT.js} +1 -1
- package/dist/{format-afijk371.js → format-CxmsgcBh.js} +8 -0
- package/dist/index.d.ts +15 -14
- package/dist/index.js +9 -6
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-Bdzz3PTc.js → preview-D3qVGc0S.js} +1 -1
- package/dist/{types-GA4ekcYB.d.ts → types-Di7nvL8V.d.ts} +2 -0
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +1 -1
- package/package.json +3 -3
- package/skills/apply-comments/SKILL.md +7 -8
- package/skills/create-slide/SKILL.md +9 -9
- package/skills/create-theme/SKILL.md +8 -5
- package/skills/current-slide/SKILL.md +1 -1
- package/skills/slide-authoring/SKILL.md +40 -315
- package/skills/slide-authoring/references/assets.md +52 -0
- package/skills/slide-authoring/references/design-system.md +48 -0
- package/skills/slide-authoring/references/morph.md +67 -0
- package/skills/slide-authoring/references/page-numbers.md +16 -0
- package/skills/slide-authoring/references/steps.md +43 -0
- package/skills/slide-authoring/references/transitions.md +175 -0
- package/skills/slide-authoring/references/webfonts.md +20 -0
- package/src/app/components/{shared-element.tsx → morph-element.tsx} +8 -13
- package/src/app/components/slide-transition-layer.tsx +61 -57
- package/src/app/lib/step-context.tsx +9 -1
- package/src/app/lib/transition.ts +2 -2
- package/src/app/routes/presenter.tsx +75 -17
- package/src/locale/en.ts +2 -0
- package/src/locale/ja.ts +2 -0
- package/src/locale/types.ts +2 -0
- package/src/locale/zh-cn.ts +2 -0
- package/src/locale/zh-tw.ts +2 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Page numbers (`useSlidePageNumber`)
|
|
2
|
+
|
|
3
|
+
If a footer shows the current page (`03 / 12`, `Page 3`, etc.), read it from `useSlidePageNumber()` — **never hardcode** `n` / `TOTAL`. Inserting, reordering, or deleting a page would otherwise force you to retouch every footer.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { useSlidePageNumber } from '@open-slide/core';
|
|
7
|
+
|
|
8
|
+
const Footer = () => {
|
|
9
|
+
const { current, total } = useSlidePageNumber();
|
|
10
|
+
return (
|
|
11
|
+
<span>{String(current).padStart(2, '0')} / {String(total).padStart(2, '0')}</span>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`current` is 1-indexed (matches what readers see) and `total` is the slide's page count. The hook works in every render context (main viewer, thumbnails, overview grid, present mode, presenter window, HTML/PDF export) — the same `<Footer />` JSX is correct everywhere. Call the hook inside a component that's used **per page**; don't try to call it at module top level.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Stepped reveals (`<Steps>` / `<Step>`)
|
|
2
|
+
|
|
3
|
+
Reveal a page one beat at a time instead of showing everything at once. Wrap the deferred parts in `<Step>`, wrap the group in `<Steps>`. Each `→` reveals the next `<Step>`; `→` after the last one advances to the next page. `←` peels the last reveal back. Use it to stage attention — show framing first, then the consequence, then the turn — so the audience reads at the speaker's pace, not ahead.
|
|
4
|
+
|
|
5
|
+
If `slides/build-on-reveal/` exists in this project (the demo workspace ships it), study it before authoring a stepped page; otherwise the rules and snippets below are sufficient.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Step, Steps } from '@open-slide/core';
|
|
9
|
+
|
|
10
|
+
<Steps>
|
|
11
|
+
<Step><div style={BULLET_ROW}>An audience reads faster than a presenter speaks.</div></Step>
|
|
12
|
+
<Step><div style={BULLET_ROW}>Showing every bullet at once invites pre-reading.</div></Step>
|
|
13
|
+
<Step><div style={BULLET_ROW}>Revealing in time stages attention.</div></Step>
|
|
14
|
+
</Steps>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Rules
|
|
18
|
+
|
|
19
|
+
- **`<Step>` must be a *direct* child of `<Steps>`.** A `<Step>` nested deeper (or used without a `<Steps>` parent) renders fully revealed and defers nothing.
|
|
20
|
+
- **Non-`Step` children render immediately.** Put a headline or intro paragraph *inside* `<Steps>` as a plain element and it shows from the start; only the `<Step>` blocks wait. This is the "headline always, body in turn" pattern:
|
|
21
|
+
```tsx
|
|
22
|
+
<Steps>
|
|
23
|
+
<h2>Not everything has to wait.</h2>{/* visible immediately */}
|
|
24
|
+
<Step><p>First, set the stage…</p></Step>
|
|
25
|
+
<Step><p>Then, layer the consequence…</p></Step>
|
|
26
|
+
</Steps>
|
|
27
|
+
```
|
|
28
|
+
- **Multiple `<Steps>` blocks on one page compose in document order.** The first block reveals all its steps before the second begins; `←` unwinds in reverse. Use this for two columns that build left-then-right, each column owning its own `<Steps>`:
|
|
29
|
+
```tsx
|
|
30
|
+
<div style={COL}><Steps><Step>…</Step><Step>…</Step></Steps></div>{/* finishes first */}
|
|
31
|
+
<div style={COL}><Steps><Step>…</Step><Step>…</Step></Steps></div>{/* then this */}
|
|
32
|
+
```
|
|
33
|
+
- **Entry direction decides the starting state — same content, two rhythms.** Entering forward (`→` from the previous page) starts empty and builds up. Jumping in via the overview grid, or arriving backward from a later page, shows the page **fully composed** with every step already revealed. Design the page to read well both ways: a thumbnail or overview jump should look complete, not blank.
|
|
34
|
+
- **`<Step>` fades in over `duration` ms (default 180).** Pass `<Step duration={...}>` to adjust. `prefers-reduced-motion: reduce` collapses it to an instant cut automatically — don't write a fallback.
|
|
35
|
+
|
|
36
|
+
## When to reach for it
|
|
37
|
+
|
|
38
|
+
Use stepped reveals when the *order* of ideas is the point — a list whose payoff is the last item, a build-up to a conclusion, a before/after. Don't wrap every page's content in `<Step>` reflexively: a page the audience should take in at a glance (a hero title, a single quote, a diagram) is stronger shown whole. Reveals are timing, not decoration — same restraint as transitions.
|
|
39
|
+
|
|
40
|
+
## Anti-patterns
|
|
41
|
+
|
|
42
|
+
- ❌ Wrapping every page's content in `<Step>` reflexively. Stepped reveals are for content whose *order* is the point; a glance-and-get-it page (hero title, single quote, diagram) is stronger shown whole.
|
|
43
|
+
- ❌ A `<Step>` that isn't a direct child of `<Steps>` (nested deeper, or with no `<Steps>` parent). It renders fully revealed and defers nothing — the reveal silently does nothing.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Page transitions (`SlideTransition`)
|
|
2
|
+
|
|
3
|
+
The framework can run an enter/exit animation between every slide change. There's **no default** — pages snap unless you declare a `SlideTransition`. Snap-swap is a perfectly tasteful default; only opt in when motion adds something.
|
|
4
|
+
|
|
5
|
+
`prefers-reduced-motion: reduce` is honored automatically. You don't write a fallback.
|
|
6
|
+
|
|
7
|
+
(For morphing a shared element across two pages — Keynote's "Magic Move" — see `morph.md`, which builds on the contract here.)
|
|
8
|
+
|
|
9
|
+
## Contract
|
|
10
|
+
|
|
11
|
+
Module-level for the whole deck; per-page to override. The **incoming page wins**: navigating A → B uses `pages[B].transition ?? module.transition`. Its `exit` plays on A, its `enter` plays on B. Going back B → A uses A's transition.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import type { Page, SlideTransition } from '@open-slide/core';
|
|
15
|
+
|
|
16
|
+
const Cover: Page = () => <section>…</section>;
|
|
17
|
+
const Body: Page = () => <section>…</section>;
|
|
18
|
+
|
|
19
|
+
// Module-level default — every page inherits unless it overrides.
|
|
20
|
+
export const transition: SlideTransition = { /* … */ };
|
|
21
|
+
|
|
22
|
+
// Per-page override.
|
|
23
|
+
Cover.transition = { /* … */ };
|
|
24
|
+
|
|
25
|
+
export default [Cover, Body];
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
type TransitionPhase = {
|
|
30
|
+
keyframes: Keyframe[] | PropertyIndexedKeyframes; // WAAPI keyframes
|
|
31
|
+
duration?: number; // ms (falls back to top-level duration)
|
|
32
|
+
easing?: string; // CSS easing
|
|
33
|
+
delay?: number; // ms — use to overlap exit + enter
|
|
34
|
+
};
|
|
35
|
+
type SlideTransition = {
|
|
36
|
+
duration: number; // top-level fallback
|
|
37
|
+
easing?: string; // top-level fallback
|
|
38
|
+
enter?: TransitionPhase; // runs on incoming page
|
|
39
|
+
exit?: TransitionPhase; // runs on outgoing page
|
|
40
|
+
morph?: boolean | MorphTransition; // shared-element morph — see morph.md
|
|
41
|
+
};
|
|
42
|
+
type MorphTransition = {
|
|
43
|
+
duration?: number;
|
|
44
|
+
easing?: string;
|
|
45
|
+
delay?: number;
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The framework also exposes `--osd-dir` (`1` forward, `-1` backward) and `data-osd-dir` (`"forward"` / `"backward"`) on the wrapper, so a single keyframe can mirror direction without a JS callback.
|
|
50
|
+
|
|
51
|
+
## Design principles (hold the line)
|
|
52
|
+
|
|
53
|
+
The single loudest signal of "made in PowerPoint" is six different transitions in one deck. Restraint is the rhythm.
|
|
54
|
+
|
|
55
|
+
- **Pick one DNA, hold it across the deck.** Same duration band, same easing pair, same out-then-in stagger. Variation lives only in *which property* gets the small nudge — Y, X, opacity, scale, blur.
|
|
56
|
+
- **Duration: 140–280 ms.** Exit 140–180 ms, enter 200–280 ms, enter delayed ~80 ms so they overlap but don't fight. Past 350 ms is video-editor territory; reserve for genuine state changes.
|
|
57
|
+
- **Magnitude ceiling: 12 px or 3% scale.** A 6 px Y-rise reads as "next thought." A 1920 px translateX reads as "different document." Premium tools move barely enough to register.
|
|
58
|
+
- **Opacity is always part of it.** Pure-transform transitions look stiff; pure-opacity transitions are the safest possible default.
|
|
59
|
+
- **Easing: ease-in for exit, ease-out for enter.** `cubic-bezier(0.4, 0, 1, 1)` going out, `cubic-bezier(0, 0, 0.2, 1)` coming in. Never `linear` (feels like a slideshow). Reserve symmetric `ease-in-out` for state-anchored morphs only.
|
|
60
|
+
|
|
61
|
+
## Tasteful family — six members, one DNA
|
|
62
|
+
|
|
63
|
+
Use this set as a starting point. Pick one as the deck's house transition; optionally reserve a second for hero/cover slides and a third for genuine section breaks. The CSS-`calc` + `--osd-dir` trick lets a single definition mirror itself on backward navigation when needed.
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
const EASE_OUT = 'cubic-bezier(0, 0, 0.2, 1)';
|
|
67
|
+
const EASE_IN = 'cubic-bezier(0.4, 0, 1, 1)';
|
|
68
|
+
|
|
69
|
+
// RISE — house quiet. 6 px Y. Use as module default.
|
|
70
|
+
export const transition: SlideTransition = {
|
|
71
|
+
duration: 200,
|
|
72
|
+
exit: { duration: 140, easing: EASE_IN,
|
|
73
|
+
keyframes: [
|
|
74
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
75
|
+
{ opacity: 0, transform: 'translateY(-4px)' },
|
|
76
|
+
] },
|
|
77
|
+
enter: { duration: 200, delay: 80, easing: EASE_OUT,
|
|
78
|
+
keyframes: [
|
|
79
|
+
{ opacity: 0, transform: 'translateY(6px)' },
|
|
80
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
81
|
+
] },
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// DISSOLVE — pure opacity. The quietest possible.
|
|
85
|
+
const dissolve: SlideTransition = {
|
|
86
|
+
duration: 240,
|
|
87
|
+
exit: { duration: 200, easing: EASE_IN,
|
|
88
|
+
keyframes: [{ opacity: 1 }, { opacity: 0 }] },
|
|
89
|
+
enter: { duration: 240, delay: 40, easing: EASE_OUT,
|
|
90
|
+
keyframes: [{ opacity: 0 }, { opacity: 1 }] },
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// SETTLE — cover-grade. Rise + a hair of blur on enter only.
|
|
94
|
+
Cover.transition = {
|
|
95
|
+
duration: 280,
|
|
96
|
+
exit: { duration: 160, easing: EASE_IN,
|
|
97
|
+
keyframes: [
|
|
98
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
99
|
+
{ opacity: 0, transform: 'translateY(-6px)' },
|
|
100
|
+
] },
|
|
101
|
+
enter: { duration: 280, delay: 100, easing: EASE_OUT,
|
|
102
|
+
keyframes: [
|
|
103
|
+
{ opacity: 0, transform: 'translateY(12px)', filter: 'blur(4px)' },
|
|
104
|
+
{ opacity: 1, transform: 'translateY(0)', filter: 'blur(0)' },
|
|
105
|
+
] },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// BLOOM — scale 0.97 → 1, no translate. Materializes in place.
|
|
109
|
+
const bloom: SlideTransition = {
|
|
110
|
+
duration: 240,
|
|
111
|
+
exit: { duration: 160, easing: EASE_IN,
|
|
112
|
+
keyframes: [
|
|
113
|
+
{ opacity: 1, transform: 'scale(1)' },
|
|
114
|
+
{ opacity: 0, transform: 'scale(1.01)' },
|
|
115
|
+
] },
|
|
116
|
+
enter: { duration: 240, delay: 80, easing: EASE_OUT,
|
|
117
|
+
keyframes: [
|
|
118
|
+
{ opacity: 0, transform: 'scale(0.97)' },
|
|
119
|
+
{ opacity: 1, transform: 'scale(1)' },
|
|
120
|
+
] },
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// FALL — mirrored Rise. Incoming page comes down from above.
|
|
124
|
+
const fall: SlideTransition = {
|
|
125
|
+
duration: 200,
|
|
126
|
+
exit: { duration: 140, easing: EASE_IN,
|
|
127
|
+
keyframes: [
|
|
128
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
129
|
+
{ opacity: 0, transform: 'translateY(4px)' },
|
|
130
|
+
] },
|
|
131
|
+
enter: { duration: 200, delay: 80, easing: EASE_OUT,
|
|
132
|
+
keyframes: [
|
|
133
|
+
{ opacity: 0, transform: 'translateY(-6px)' },
|
|
134
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
135
|
+
] },
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// BREATH — section break. Exit fully, hold 120 ms, then enter.
|
|
139
|
+
// Reserve for genuine chapter dividers; use at most 1–2× per deck.
|
|
140
|
+
const breath: SlideTransition = {
|
|
141
|
+
duration: 460,
|
|
142
|
+
exit: { duration: 180, easing: EASE_IN,
|
|
143
|
+
keyframes: [{ opacity: 1 }, { opacity: 0 }] },
|
|
144
|
+
enter: { duration: 240, delay: 300, easing: EASE_OUT,
|
|
145
|
+
keyframes: [
|
|
146
|
+
{ opacity: 0, transform: 'translateY(8px)' },
|
|
147
|
+
{ opacity: 1, transform: 'translateY(0)' },
|
|
148
|
+
] },
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
All six share the same DNA — they only differ in which property carries the small nudge. The reader perceives variety; the eye still reads one consistent hand.
|
|
153
|
+
|
|
154
|
+
## Direction-aware keyframes (use sparingly)
|
|
155
|
+
|
|
156
|
+
Most tasteful tools don't mirror on backward navigation. When you genuinely need to — e.g. a horizontal slide that should reverse — use `--osd-dir` inside `calc()`:
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
{ transform: 'translateX(calc(var(--osd-dir, 1) * 8px))' },
|
|
160
|
+
{ transform: 'translateX(0)' },
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
If you find yourself reaching for this on every transition, you're probably over-designing. Forward = backward is the more refined default.
|
|
164
|
+
|
|
165
|
+
## Anti-patterns
|
|
166
|
+
|
|
167
|
+
- ❌ Six different transitions across six pages — the single loudest "made in PowerPoint" tell.
|
|
168
|
+
- ❌ `translateX(100%)` slide-from-side — iOS modal / PowerPoint Push; not a slide change.
|
|
169
|
+
- ❌ Aggressive scale-pop (e.g. `0.85 → 1`) + blur — lightbox / photo-viewer vocabulary; implies zooming *into* something.
|
|
170
|
+
- ❌ `clip-path: inset(…)` reveals — After Effects vocabulary; theatrical.
|
|
171
|
+
- ❌ Parallel blur on both layers at once — visual mush; the eye can't fixate.
|
|
172
|
+
- ❌ Duration > 350 ms for a standard slide change — drags.
|
|
173
|
+
- ❌ Translate > 12 px or scale > 3% — reads as rupture, not continuity.
|
|
174
|
+
- ❌ `linear` easing — feels like a slideshow, not a product.
|
|
175
|
+
- ❌ Declaring a transition on every deck. **If you don't have a clear reason, omit it.** Snap-swap is fine.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Webfonts
|
|
2
|
+
|
|
3
|
+
The default is a system font stack — prefer it. When a deck genuinely needs a webfont (a brand font, or CJK / Thai / Arabic where system coverage is poor):
|
|
4
|
+
|
|
5
|
+
- **Load the stylesheet once, in `<head>` — never inside a per-page component.** Every page is mounted live at the same time (thumbnail rail, overview grid, and the PDF print root), so a `<style>@import</style>` / `<link>` rendered inside a `Page` registers the whole `@font-face` set once *per page*. Inject it once, idempotently, from module top level of `index.tsx` (top-level statements as in the snippet below — not inside a component or effect). **Key the element id to the slide** (e.g. `osd-webfont-<slide-id>`) — the home page mounts pages from *every* slide at once, so a generic shared id like `osd-webfont` would let the first slide's fonts suppress every other slide's:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
const FONT_HREF = 'https://fonts.googleapis.com/css2?family=...&display=swap';
|
|
9
|
+
const FONT_LINK_ID = 'osd-webfont-q2-roadmap'; // suffix = this slide's folder id
|
|
10
|
+
if (typeof document !== 'undefined' && !document.getElementById(FONT_LINK_ID)) {
|
|
11
|
+
const link = document.createElement('link');
|
|
12
|
+
link.id = FONT_LINK_ID;
|
|
13
|
+
link.rel = 'stylesheet';
|
|
14
|
+
link.href = FONT_HREF;
|
|
15
|
+
document.head.appendChild(link);
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **List only the weights you actually use.** Each extra weight multiplies the number of `@font-face` rules.
|
|
20
|
+
- **CJK fonts are large.** A Google Fonts CJK family registers hundreds of `unicode-range` subset faces (Noto Sans TC ≈ 105 subsets × each weight), and PDF export waits on fonts before printing. If the deck's text is fixed, add `&text=<unique chars>` to the URL to request a tiny single-face subset instead of the full set.
|
|
@@ -7,41 +7,36 @@ import {
|
|
|
7
7
|
type ReactNode,
|
|
8
8
|
} from 'react';
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type MorphElementProps = {
|
|
11
11
|
id: string;
|
|
12
12
|
children: ReactNode;
|
|
13
13
|
className?: string;
|
|
14
14
|
style?: CSSProperties;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
type
|
|
17
|
+
type MorphElementChildProps = {
|
|
18
18
|
className?: string;
|
|
19
19
|
style?: CSSProperties;
|
|
20
|
-
'data-osd-
|
|
20
|
+
'data-osd-morph'?: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export function
|
|
24
|
-
id,
|
|
25
|
-
children,
|
|
26
|
-
className,
|
|
27
|
-
style,
|
|
28
|
-
}: unstable_SharedElementProps) {
|
|
23
|
+
export function MorphElement({ id, children, className, style }: MorphElementProps) {
|
|
29
24
|
const child = Children.toArray(children)[0] ?? null;
|
|
30
25
|
|
|
31
26
|
if (
|
|
32
27
|
Children.count(children) === 1 &&
|
|
33
|
-
isValidElement<
|
|
28
|
+
isValidElement<MorphElementChildProps>(child) &&
|
|
34
29
|
typeof child.type === 'string'
|
|
35
30
|
) {
|
|
36
|
-
return cloneElement(child as ReactElement<
|
|
37
|
-
'data-osd-
|
|
31
|
+
return cloneElement(child as ReactElement<MorphElementChildProps>, {
|
|
32
|
+
'data-osd-morph': id,
|
|
38
33
|
className: [child.props.className, className].filter(Boolean).join(' ') || undefined,
|
|
39
34
|
style: style ? { ...child.props.style, ...style } : child.props.style,
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
return (
|
|
44
|
-
<div className={className} style={style} data-osd-
|
|
39
|
+
<div className={className} style={style} data-osd-morph={id}>
|
|
45
40
|
{children}
|
|
46
41
|
</div>
|
|
47
42
|
);
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
StepHost,
|
|
9
9
|
} from '../lib/step-context';
|
|
10
10
|
import {
|
|
11
|
+
type MorphTransition,
|
|
11
12
|
resolveTransition,
|
|
12
|
-
type SharedElementTransition,
|
|
13
13
|
type SlideTransition,
|
|
14
14
|
type TransitionPhase,
|
|
15
15
|
} from '../lib/transition';
|
|
@@ -28,9 +28,9 @@ type Props = {
|
|
|
28
28
|
type Direction = 'forward' | 'backward';
|
|
29
29
|
|
|
30
30
|
const DEFAULT_EASING = 'cubic-bezier(.4, 0, .2, 1)';
|
|
31
|
-
const
|
|
31
|
+
const MORPH_ELEMENT_SELECTOR = '[data-osd-morph]';
|
|
32
32
|
const TEXT_FILL_COLOR_PROPERTY = '-webkit-text-fill-color';
|
|
33
|
-
const
|
|
33
|
+
const MORPH_VISUAL_PROPERTIES = [
|
|
34
34
|
'opacity',
|
|
35
35
|
'color',
|
|
36
36
|
'background-color',
|
|
@@ -109,21 +109,21 @@ function runPhase(
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
type
|
|
112
|
+
type ResolvedMorphTransition = Required<MorphTransition>;
|
|
113
113
|
|
|
114
|
-
function
|
|
115
|
-
|
|
114
|
+
function resolveMorphTransition(
|
|
115
|
+
morph: SlideTransition['morph'],
|
|
116
116
|
fallbackDuration: number,
|
|
117
117
|
fallbackEasing: string,
|
|
118
|
-
):
|
|
119
|
-
if (!
|
|
120
|
-
if (
|
|
118
|
+
): ResolvedMorphTransition | null {
|
|
119
|
+
if (!morph) return null;
|
|
120
|
+
if (morph === true) {
|
|
121
121
|
return { duration: fallbackDuration, easing: fallbackEasing, delay: 0 };
|
|
122
122
|
}
|
|
123
123
|
return {
|
|
124
|
-
duration:
|
|
125
|
-
easing:
|
|
126
|
-
delay:
|
|
124
|
+
duration: morph.duration ?? fallbackDuration,
|
|
125
|
+
easing: morph.easing ?? fallbackEasing,
|
|
126
|
+
delay: morph.delay ?? 0,
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -165,10 +165,10 @@ function hasUsableRect(rect: LocalRect): boolean {
|
|
|
165
165
|
return rect.width > 0 && rect.height > 0;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
function
|
|
168
|
+
function collectMorphElements(root: HTMLElement): Map<string, HTMLElement> {
|
|
169
169
|
const elements = new Map<string, HTMLElement>();
|
|
170
|
-
for (const el of root.querySelectorAll<HTMLElement>(
|
|
171
|
-
const id = el.dataset.
|
|
170
|
+
for (const el of root.querySelectorAll<HTMLElement>(MORPH_ELEMENT_SELECTOR)) {
|
|
171
|
+
const id = el.dataset.osdMorph;
|
|
172
172
|
if (id && !elements.has(id)) elements.set(id, el);
|
|
173
173
|
}
|
|
174
174
|
return elements;
|
|
@@ -214,10 +214,10 @@ function copyComputedStyles(
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
function
|
|
217
|
+
function cloneMorphElement(source: HTMLElement): HTMLElement {
|
|
218
218
|
const clone = source.cloneNode(true) as HTMLElement;
|
|
219
219
|
copyComputedStyles(source, clone);
|
|
220
|
-
clone.removeAttribute('data-osd-
|
|
220
|
+
clone.removeAttribute('data-osd-morph');
|
|
221
221
|
return clone;
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -251,18 +251,13 @@ function localTransform(styles: CSSStyleDeclaration): string {
|
|
|
251
251
|
return styles.transform && styles.transform !== 'none' ? styles.transform : '';
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
function
|
|
255
|
-
rect: LocalRect,
|
|
256
|
-
scaleX: number,
|
|
257
|
-
scaleY: number,
|
|
258
|
-
local: string,
|
|
259
|
-
): string {
|
|
254
|
+
function morphTransform(rect: LocalRect, scaleX: number, scaleY: number, local: string): string {
|
|
260
255
|
return [`translate(${rect.left}px, ${rect.top}px)`, `scale(${scaleX}, ${scaleY})`, local]
|
|
261
256
|
.filter(Boolean)
|
|
262
257
|
.join(' ');
|
|
263
258
|
}
|
|
264
259
|
|
|
265
|
-
function
|
|
260
|
+
function morphTranslateTransform(rect: LocalRect, local: string): string {
|
|
266
261
|
return [`translate(${rect.left}px, ${rect.top}px)`, local].filter(Boolean).join(' ');
|
|
267
262
|
}
|
|
268
263
|
|
|
@@ -270,13 +265,19 @@ function getStyleProperty(styles: CSSStyleDeclaration, css: string): string {
|
|
|
270
265
|
return styles.getPropertyValue(css);
|
|
271
266
|
}
|
|
272
267
|
|
|
268
|
+
// element.animate() silently drops kebab-case keys; keyframe properties must
|
|
269
|
+
// use their IDL camelCase names.
|
|
270
|
+
function keyframeProperty(css: string): string {
|
|
271
|
+
return css.replace(/^-/, '').replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase());
|
|
272
|
+
}
|
|
273
|
+
|
|
273
274
|
function visualStyleKeyframe(
|
|
274
275
|
styles: CSSStyleDeclaration,
|
|
275
276
|
opacity?: string,
|
|
276
277
|
options: { includeBorderColors?: boolean } = {},
|
|
277
278
|
): Keyframe {
|
|
278
279
|
const frame: Record<string, string> = {};
|
|
279
|
-
for (const prop of
|
|
280
|
+
for (const prop of MORPH_VISUAL_PROPERTIES) {
|
|
280
281
|
if (
|
|
281
282
|
options.includeBorderColors === false &&
|
|
282
283
|
(BORDER_COLOR_PROPERTIES as readonly string[]).includes(prop)
|
|
@@ -285,7 +286,7 @@ function visualStyleKeyframe(
|
|
|
285
286
|
}
|
|
286
287
|
const value = getStyleProperty(styles, prop);
|
|
287
288
|
if (prop === TEXT_FILL_COLOR_PROPERTY && value === styles.color) continue;
|
|
288
|
-
if (value) frame[prop] = value;
|
|
289
|
+
if (value) frame[keyframeProperty(prop)] = value;
|
|
289
290
|
}
|
|
290
291
|
if (opacity !== undefined) frame.opacity = opacity;
|
|
291
292
|
return frame;
|
|
@@ -319,7 +320,7 @@ function borderFrameKeyframe(
|
|
|
319
320
|
width: `${rect.width}px`,
|
|
320
321
|
height: `${rect.height}px`,
|
|
321
322
|
opacity,
|
|
322
|
-
transform:
|
|
323
|
+
transform: morphTranslateTransform(rect, localTransform(styles)),
|
|
323
324
|
...radiusKeyframe(styles),
|
|
324
325
|
};
|
|
325
326
|
|
|
@@ -366,7 +367,7 @@ function appendBorderFrame(
|
|
|
366
367
|
}
|
|
367
368
|
|
|
368
369
|
function hasVisualStyleChange(from: CSSStyleDeclaration, to: CSSStyleDeclaration): boolean {
|
|
369
|
-
for (const prop of
|
|
370
|
+
for (const prop of MORPH_VISUAL_PROPERTIES) {
|
|
370
371
|
if (getStyleProperty(from, prop) !== getStyleProperty(to, prop)) return true;
|
|
371
372
|
}
|
|
372
373
|
return false;
|
|
@@ -401,7 +402,7 @@ function appendPositionedClone(
|
|
|
401
402
|
): HTMLElement {
|
|
402
403
|
if (!overlay.parentElement) wrapper.appendChild(overlay);
|
|
403
404
|
|
|
404
|
-
const clone =
|
|
405
|
+
const clone = cloneMorphElement(source);
|
|
405
406
|
Object.assign(clone.style, {
|
|
406
407
|
position: 'absolute',
|
|
407
408
|
left: '0',
|
|
@@ -417,9 +418,7 @@ function appendPositionedClone(
|
|
|
417
418
|
return clone;
|
|
418
419
|
}
|
|
419
420
|
|
|
420
|
-
function
|
|
421
|
-
phase: ResolvedSharedElementTransition,
|
|
422
|
-
): KeyframeAnimationOptions {
|
|
421
|
+
function morphAnimationOptions(phase: ResolvedMorphTransition): KeyframeAnimationOptions {
|
|
423
422
|
return {
|
|
424
423
|
duration: phase.duration,
|
|
425
424
|
easing: phase.easing,
|
|
@@ -432,7 +431,7 @@ function runDescendantVisualStyleTransitions(
|
|
|
432
431
|
clone: HTMLElement,
|
|
433
432
|
source: HTMLElement,
|
|
434
433
|
target: HTMLElement,
|
|
435
|
-
phase:
|
|
434
|
+
phase: ResolvedMorphTransition,
|
|
436
435
|
): Animation[] {
|
|
437
436
|
const animations: Animation[] = [];
|
|
438
437
|
const cloneChildren = clone.querySelectorAll<HTMLElement>('*');
|
|
@@ -451,7 +450,7 @@ function runDescendantVisualStyleTransitions(
|
|
|
451
450
|
animations.push(
|
|
452
451
|
cloneChild.animate(
|
|
453
452
|
[visualStyleKeyframe(sourceStyles), visualStyleKeyframe(targetStyles)],
|
|
454
|
-
|
|
453
|
+
morphAnimationOptions(phase),
|
|
455
454
|
),
|
|
456
455
|
);
|
|
457
456
|
}
|
|
@@ -459,15 +458,15 @@ function runDescendantVisualStyleTransitions(
|
|
|
459
458
|
return animations;
|
|
460
459
|
}
|
|
461
460
|
|
|
462
|
-
function
|
|
461
|
+
function runStationaryMorphAnimation(
|
|
463
462
|
clone: HTMLElement,
|
|
464
463
|
rect: LocalRect,
|
|
465
464
|
styles: CSSStyleDeclaration,
|
|
466
465
|
fromOpacity: string,
|
|
467
466
|
toOpacity: string,
|
|
468
|
-
phase:
|
|
467
|
+
phase: ResolvedMorphTransition,
|
|
469
468
|
): Animation {
|
|
470
|
-
const transform =
|
|
469
|
+
const transform = morphTransform(rect, 1, 1, localTransform(styles));
|
|
471
470
|
return clone.animate(
|
|
472
471
|
[
|
|
473
472
|
{
|
|
@@ -481,24 +480,24 @@ function runStationarySharedElementAnimation(
|
|
|
481
480
|
transform,
|
|
482
481
|
},
|
|
483
482
|
],
|
|
484
|
-
|
|
483
|
+
morphAnimationOptions(phase),
|
|
485
484
|
);
|
|
486
485
|
}
|
|
487
486
|
|
|
488
|
-
function
|
|
487
|
+
function runMorphTransition(
|
|
489
488
|
wrapper: HTMLElement,
|
|
490
489
|
outgoingLayer: HTMLElement,
|
|
491
490
|
incomingLayer: HTMLElement,
|
|
492
|
-
phase:
|
|
491
|
+
phase: ResolvedMorphTransition,
|
|
493
492
|
): { animations: Animation[]; cleanup: () => void } {
|
|
494
493
|
const wrapperRect = wrapper.getBoundingClientRect();
|
|
495
494
|
if (wrapperRect.width === 0 || wrapperRect.height === 0) {
|
|
496
495
|
return { animations: [], cleanup: () => {} };
|
|
497
496
|
}
|
|
498
497
|
|
|
499
|
-
const incoming =
|
|
498
|
+
const incoming = collectMorphElements(incomingLayer);
|
|
500
499
|
const overlay = document.createElement('div');
|
|
501
|
-
overlay.setAttribute('data-osd-
|
|
500
|
+
overlay.setAttribute('data-osd-morph-layer', '');
|
|
502
501
|
Object.assign(overlay.style, {
|
|
503
502
|
position: 'absolute',
|
|
504
503
|
inset: '0',
|
|
@@ -508,7 +507,7 @@ function runSharedElementTransition(
|
|
|
508
507
|
|
|
509
508
|
const animations: Animation[] = [];
|
|
510
509
|
const restore: Array<() => void> = [];
|
|
511
|
-
const outgoing =
|
|
510
|
+
const outgoing = collectMorphElements(outgoingLayer);
|
|
512
511
|
const handledIncoming = new Set<string>();
|
|
513
512
|
|
|
514
513
|
for (const [id, source] of outgoing) {
|
|
@@ -524,7 +523,7 @@ function runSharedElementTransition(
|
|
|
524
523
|
|
|
525
524
|
const targetStyles = getComputedStyle(target);
|
|
526
525
|
animations.push(
|
|
527
|
-
|
|
526
|
+
runStationaryMorphAnimation(
|
|
528
527
|
clone,
|
|
529
528
|
to,
|
|
530
529
|
targetStyles,
|
|
@@ -544,7 +543,7 @@ function runSharedElementTransition(
|
|
|
544
543
|
|
|
545
544
|
const sourceStyles = getComputedStyle(source);
|
|
546
545
|
animations.push(
|
|
547
|
-
|
|
546
|
+
runStationaryMorphAnimation(
|
|
548
547
|
clone,
|
|
549
548
|
from,
|
|
550
549
|
sourceStyles,
|
|
@@ -563,7 +562,7 @@ function runSharedElementTransition(
|
|
|
563
562
|
|
|
564
563
|
const sourceStyles = getComputedStyle(source);
|
|
565
564
|
animations.push(
|
|
566
|
-
|
|
565
|
+
runStationaryMorphAnimation(
|
|
567
566
|
clone,
|
|
568
567
|
from,
|
|
569
568
|
sourceStyles,
|
|
@@ -587,8 +586,8 @@ function runSharedElementTransition(
|
|
|
587
586
|
const needsBorderFrame = hasVisibleBorder(sourceStyles) || hasVisibleBorder(targetStyles);
|
|
588
587
|
const scaleX = to.width / from.width;
|
|
589
588
|
const scaleY = to.height / from.height;
|
|
590
|
-
const fromTransform =
|
|
591
|
-
const toTransform =
|
|
589
|
+
const fromTransform = morphTransform(from, 1, 1, localTransform(sourceStyles));
|
|
590
|
+
const toTransform = morphTransform(to, scaleX, scaleY, localTransform(targetStyles));
|
|
592
591
|
|
|
593
592
|
if (needsBorderFrame) {
|
|
594
593
|
hideBorderColors(clone);
|
|
@@ -599,7 +598,7 @@ function runSharedElementTransition(
|
|
|
599
598
|
borderFrameKeyframe(from, sourceStyles, fromOpacity),
|
|
600
599
|
borderFrameKeyframe(to, targetStyles, toOpacity),
|
|
601
600
|
],
|
|
602
|
-
|
|
601
|
+
morphAnimationOptions(phase),
|
|
603
602
|
),
|
|
604
603
|
);
|
|
605
604
|
}
|
|
@@ -622,7 +621,7 @@ function runSharedElementTransition(
|
|
|
622
621
|
transform: toTransform,
|
|
623
622
|
},
|
|
624
623
|
],
|
|
625
|
-
|
|
624
|
+
morphAnimationOptions(phase),
|
|
626
625
|
),
|
|
627
626
|
...runDescendantVisualStyleTransitions(clone, source, target, phase),
|
|
628
627
|
);
|
|
@@ -639,7 +638,7 @@ function runSharedElementTransition(
|
|
|
639
638
|
|
|
640
639
|
const targetStyles = getComputedStyle(target);
|
|
641
640
|
animations.push(
|
|
642
|
-
|
|
641
|
+
runStationaryMorphAnimation(
|
|
643
642
|
clone,
|
|
644
643
|
to,
|
|
645
644
|
targetStyles,
|
|
@@ -733,6 +732,13 @@ export function SlideTransitionLayer({
|
|
|
733
732
|
const easing = transition.easing ?? DEFAULT_EASING;
|
|
734
733
|
const duration = transition.duration;
|
|
735
734
|
|
|
735
|
+
// Morph elements must be measured before the enter/exit phases start:
|
|
736
|
+
// phase keyframes apply immediately (fill: both), so a transform in the
|
|
737
|
+
// enter's first keyframe would offset every measured target rect and land
|
|
738
|
+
// the clones off their true rest positions.
|
|
739
|
+
const morphPhase = resolveMorphTransition(transition.morph, duration, easing);
|
|
740
|
+
const morphRun = morphPhase ? runMorphTransition(wrapper, out, inc, morphPhase) : null;
|
|
741
|
+
|
|
736
742
|
const anims: Animation[] = [];
|
|
737
743
|
const exitAnim = runPhase(out, transition.exit, duration, easing);
|
|
738
744
|
const enterAnim = runPhase(inc, transition.enter, duration, easing);
|
|
@@ -740,12 +746,10 @@ export function SlideTransitionLayer({
|
|
|
740
746
|
if (enterAnim) anims.push(enterAnim);
|
|
741
747
|
|
|
742
748
|
const cleanups: Array<() => void> = [];
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
cleanups.push(shared.cleanup);
|
|
748
|
-
if (!exitAnim && shared.animations.length > 0) cleanups.push(hideOriginal(out));
|
|
749
|
+
if (morphRun) {
|
|
750
|
+
anims.push(...morphRun.animations);
|
|
751
|
+
cleanups.push(morphRun.cleanup);
|
|
752
|
+
if (!exitAnim && morphRun.animations.length > 0) cleanups.push(hideOriginal(out));
|
|
749
753
|
}
|
|
750
754
|
animsRef.current = anims;
|
|
751
755
|
|
|
@@ -41,6 +41,7 @@ type StepHostContextValue = {
|
|
|
41
41
|
reportRevealed: (id: object, revealed: number) => void;
|
|
42
42
|
entryDirection: EntryDirection;
|
|
43
43
|
controlled: boolean;
|
|
44
|
+
isActivePage: boolean;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
const GLOBAL_KEY = '__open_slide_step_host_context__';
|
|
@@ -163,13 +164,20 @@ export function StepHost({
|
|
|
163
164
|
},
|
|
164
165
|
entryDirection,
|
|
165
166
|
controlled: controlledRevealed != null,
|
|
167
|
+
isActivePage,
|
|
166
168
|
}),
|
|
167
|
-
[entryDirection, controlledRevealed, distributeControlled, notifyAggregate],
|
|
169
|
+
[entryDirection, controlledRevealed, distributeControlled, notifyAggregate, isActivePage],
|
|
168
170
|
);
|
|
169
171
|
|
|
170
172
|
return <StepHostContext.Provider value={value}>{children}</StepHostContext.Provider>;
|
|
171
173
|
}
|
|
172
174
|
|
|
175
|
+
// Hostless mounts (thumbnails, overview grid, print/export) are never the
|
|
176
|
+
// audience-facing instance, so no provider means false.
|
|
177
|
+
export function useIsActivePage(): boolean {
|
|
178
|
+
return useContext(StepHostContext)?.isActivePage ?? false;
|
|
179
|
+
}
|
|
180
|
+
|
|
173
181
|
export type StepsProps = PropsWithChildren;
|
|
174
182
|
|
|
175
183
|
export function Steps({ children }: StepsProps) {
|