Skip to content

Commit 2ec1cdc

Browse files
authored
Merge pull request #641 from marp-team/safari-bespoke-transition-compatibility
Improve bespoke transition animations for Safari compatibility
2 parents 4033366 + 725a023 commit 2ec1cdc

File tree

16 files changed

+84
-25
lines changed

16 files changed

+84
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Use arm64 hosted runner to build container image for ARM64 ([#635](https://github.com/marp-team/marp-cli/issues/635), [#637](https://github.com/marp-team/marp-cli/pull/637))
88

9+
### Fixed
10+
11+
- Improve bespoke transition animations for Safari compatibility ([#572](https://github.com/marp-team/marp-cli/issues/572), [#641](https://github.com/marp-team/marp-cli/pull/641))
12+
913
## v4.1.1 - 2025-01-19
1014

1115
### Fixed

docs/bespoke-transitions/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To show transition animations, a viewer has to show HTML slide in the browser wh
2020

2121
- **Chrome**: ✅ (111-)
2222
- **Edge**: ✅ (111-)
23-
- **Safari**: ✅ (18.2- / [#572](https://github.com/marp-team/marp-cli/issues/572))
23+
- **Safari**: ✅ (18.2-)
2424
- **Firefox**: :x:
2525

2626
## `transition` local directive
@@ -231,7 +231,8 @@ Marp CLI has provided useful [33 built-in transitions](../../src/engine/transiti
231231
</tbody>
232232
</table>
233233

234-
> **Note**
234+
> [!NOTE]
235+
>
235236
> If the viewer has enabled the reduce motion feature on their device, the transition animation will be forced to a simple `fade` animation regardless of the specified transition. See also "[Reduce transitions by a viewer](#reduce-transitions-by-a-viewer)".
236237
237238
### Duration
@@ -252,6 +253,8 @@ For making custom transitions, all you have to know is only about CSS. Define an
252253

253254
Marp prefers the custom transition if defined the transition with same name as built-in transitions.
254255

256+
> [!TIP]
257+
>
255258
> See also our blog article: **"[Marp CLI: How to make custom transition](https://marp.app/blog/how-to-make-custom-transition)"**
256259

257260
### Simple keyframe declaration
@@ -487,7 +490,7 @@ If you want to swap the order of layers during animation, try to animate `z-inde
487490
}
488491
```
489492

490-
> `z-index` is always taking an integer value, and interpolated `z-index` value by animation does not take any decimal points too.
493+
`z-index` is always taking an integer value, and interpolated `z-index` value by animation does not take any decimal points too.
491494

492495
## Morphing animations
493496

@@ -505,7 +508,11 @@ The slide author can visualize the relationship between the different elements i
505508

506509
If there were multiple pairs defined by `view-transition-name` CSS property with different names, each elements will morph at the same time. Elements that were not marked by `view-transition-name` still follow the selected animation by `transition` local directive.
507510

508-
> **Warning** Each morphable elements marked by `view-transition-name` must have uniquely named in a slide page. If there were multiple elements named by `view-transition-name` with the same name in a single page, View Transition API does not apply _the whole of transition animation_.
511+
> [!WARNING]
512+
>
513+
> Each morphable elements marked by `view-transition-name` must have uniquely named in a slide page. If there were multiple elements named by `view-transition-name` with the same name in a single page, View Transition API does not apply _the whole of transition animation_.
514+
>
515+
> The morphing animation has been confirmed working correctly on Chrome and Edge. Safari also supports this kind of animation, but the correct animation is not granted, due to the effect of [WebKit's a long-standing bug](https://bugs.webkit.org/show_bug.cgi?id=23113) (and [marpit-svg-polyfill](https://github.com/marp-team/marpit-svg-polyfill) to patch that).
509516
510517
### Example
511518

7.62 KB
Loading
-26.5 KB
Loading

src/engine/transition/keyframes/cover.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
transform: translateX(10%);
77
animation-timing-function: ease-out;
88
}
9+
10+
to {
11+
transform: translateX(0%);
12+
}
913
}
1014

1115
@keyframes marp-outgoing-transition-backward-__builtin__cover {
1216
from {
1317
animation-timing-function: ease-out;
18+
transform: translateX(0%);
1419
}
1520

1621
to {

src/engine/transition/keyframes/drop.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
rgba(0, 0, 0, 30%) 0 3vh 5vh, rgba(0, 0, 0, 22%) 0 2vh 1.5vh;
44
}
55

6+
// [Safari CSS hack]
7+
// In Safari, applying shadow causes a rendering issue
8+
_::-webkit-full-page-media,
9+
_:future,
10+
:root {
11+
--bespoke-marp-transition-drop-shadow: none;
12+
}
13+
614
@keyframes marp-incoming-transition-__builtin__drop {
715
0% {
816
transform: translateY(-100%);
@@ -55,6 +63,7 @@
5563
@keyframes marp-outgoing-transition-backward-__builtin__drop {
5664
0% {
5765
z-index: 1;
66+
transform: translateY(0);
5867
animation-timing-function: ease-in;
5968
box-shadow: var(--bespoke-marp-transition-drop-shadow);
6069
}

src/engine/transition/keyframes/flip.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
}
55

66
50% {
7-
transform: perspective(800px) translateZ(-400px)
7+
transform: perspective(75vw)
88
rotateY(calc(var(--marp-transition-direction, 1) * -90deg));
9-
opacity: 0.5;
9+
opacity: 0.75;
1010
animation-timing-function: step-start;
1111
}
1212

@@ -22,9 +22,9 @@
2222
}
2323

2424
50% {
25-
transform: perspective(800px) translateZ(-400px)
25+
transform: perspective(75vw)
2626
rotateY(calc(var(--marp-transition-direction, 1) * 90deg));
27-
opacity: 0.5;
27+
opacity: 0.75;
2828
animation-timing-function: ease-out;
2929
}
3030
}

src/engine/transition/keyframes/pivot.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@keyframes marp-outgoing-transition-backward-__builtin__pivot {
2020
from {
2121
transform-origin: left top;
22+
transform: rotate(0deg);
2223
animation-timing-function: ease-in;
2324
}
2425

src/engine/transition/keyframes/pull.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@keyframes marp-outgoing-transition-__builtin__pull {
44
from {
55
animation-timing-function: ease-out;
6+
transform: translateX(0);
67
}
78

89
to {
@@ -19,6 +20,10 @@
1920
animation-timing-function: ease-out;
2021
transform: translateX(-100%);
2122
}
23+
24+
to {
25+
transform: translateX(0);
26+
}
2227
}
2328

2429
@keyframes marp-outgoing-transition-backward-__builtin__pull {

src/engine/transition/keyframes/push.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
animation-timing-function: ease-out;
66
transform: translateX(100%);
77
}
8+
9+
to {
10+
transform: translateX(0);
11+
}
812
}
913

1014
@keyframes marp-outgoing-transition-backward-__builtin__push {
1115
from {
1216
animation-timing-function: ease-out;
17+
transform: translateX(0);
1318
}
1419

1520
to {

src/engine/transition/keyframes/reveal.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@keyframes marp-outgoing-transition-__builtin__reveal {
44
from {
55
animation-timing-function: ease-out;
6+
transform: translateX(0%);
67
}
78

89
to {
@@ -24,4 +25,8 @@
2425
transform: translateX(-10%);
2526
animation-timing-function: ease-out;
2627
}
28+
29+
to {
30+
transform: translateX(0%);
31+
}
2732
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
@keyframes marp-outgoing-transition-__builtin__rotate {
22
from {
33
z-index: 1;
4-
transform: perspective(100vw) translateZ(-40vw) rotateY(0deg)
5-
translateZ(40vw);
4+
5+
// NOTE: 0.0001deg is a workaround for a bug in Safari
6+
transform: perspective(100vw) translateZ(-50vw) rotateY(0.0001deg)
7+
translateZ(50vw);
68
animation-timing-function: ease-in-out;
79
}
810

911
to {
1012
z-index: 0;
11-
transform: perspective(100vw) translateZ(-40vw)
13+
transform: perspective(100vw) translateZ(-50vw)
1214
rotateY(calc(var(--marp-transition-direction, 1) * -180deg))
13-
translateZ(40vw)
15+
translateZ(50vw)
1416
rotateY(calc(var(--marp-transition-direction, 1) * 180deg));
1517
opacity: 0;
1618
}
@@ -20,16 +22,16 @@
2022
from {
2123
opacity: 0;
2224
z-index: 0;
23-
transform: perspective(100vw) translateZ(-40vw)
25+
transform: perspective(100vw) translateZ(-50vw)
2426
rotateY(calc(var(--marp-transition-direction, 1) * 180deg))
25-
translateZ(40vw)
27+
translateZ(50vw)
2628
rotateY(calc(var(--marp-transition-direction, 1) * -180deg));
2729
animation-timing-function: ease-in-out;
2830
}
2931

3032
to {
3133
z-index: 1;
32-
transform: perspective(100vw) translateZ(-40vw) rotateY(0deg)
33-
translateZ(40vw);
34+
transform: perspective(100vw) translateZ(-50vw) rotateY(0.0001deg)
35+
translateZ(50vw);
3436
}
3537
}

src/engine/transition/keyframes/slide.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
transform: translateX(calc(var(--marp-transition-direction, 1) * 100vw));
44
animation-timing-function: ease-in-out;
55
}
6-
7-
to {
8-
animation-timing-function: ease-in-out;
9-
}
106
}
117

128
@keyframes marp-outgoing-transition-__builtin__slide {
139
from {
10+
transform: translateX(0);
1411
animation-timing-function: ease-in-out;
1512
}
1613

1714
to {
1815
transform: translateX(calc(var(--marp-transition-direction, 1) * -100vw));
19-
animation-timing-function: ease-in-out;
2016
}
2117
}

src/engine/transition/keyframes/swap.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@keyframes marp-outgoing-transition-__builtin__swap {
22
0% {
33
z-index: 1;
4+
transform: none;
45
transform-origin: calc(var(--marp-transition-direction, 1) * 50% + 50%)
56
calc(var(--marp-transition-direction, 1) * 50% + 50%);
67
animation-timing-function: ease-in-out;
@@ -13,6 +14,7 @@
1314
}
1415

1516
100% {
17+
transform: none;
1618
transform-origin: calc(var(--marp-transition-direction, 1) * 50% + 50%)
1719
calc(var(--marp-transition-direction, 1) * 50% + 50%);
1820
filter: brightness(0.5);
@@ -23,6 +25,7 @@
2325
@keyframes marp-incoming-transition-__builtin__swap {
2426
0% {
2527
filter: brightness(0.75);
28+
transform: none;
2629
transform-origin: calc(var(--marp-transition-direction, 1) * -50% + 50%)
2730
calc(var(--marp-transition-direction, 1) * -50% + 50%);
2831
animation-timing-function: ease-in-out;
@@ -35,6 +38,7 @@
3538
}
3639

3740
100% {
41+
transform: none;
3842
transform-origin: calc(var(--marp-transition-direction, 1) * -50% + 50%)
3943
calc(var(--marp-transition-direction, 1) * -50% + 50%);
4044
}

src/engine/transition/keyframes/swipe.scss

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
:root {
2+
--bespoke-marp-transition-swipe-shadow: 6px 6px 10px 6px rgba(0, 0, 0, 25%);
3+
}
4+
5+
// [Safari CSS hack]
6+
// In Safari, applying shadow causes a rendering issue
7+
_::-webkit-full-page-media,
8+
_:future,
9+
:root {
10+
--bespoke-marp-transition-swipe-shadow: none;
11+
}
12+
113
@keyframes marp-outgoing-transition-__builtin__swipe {
214
0% {
315
animation-timing-function: ease-in;
4-
box-shadow: 6px 6px 10px 6px rgba(0, 0, 0, 25%);
16+
box-shadow: var(--bespoke-marp-transition-swipe-shadow);
17+
transform: none;
518
transform-origin: 100% 100%;
619
z-index: 1;
720
}
821

922
100% {
10-
box-shadow: 6px 6px 10px 6px rgba(0, 0, 0, 25%);
23+
box-shadow: var(--bespoke-marp-transition-swipe-shadow);
1124
transform: translate(calc(-100vw - 30px), -30vh) rotate(-30deg);
1225
transform-origin: 100% 100%;
1326
z-index: 1;
@@ -29,6 +42,7 @@
2942

3043
@keyframes marp-outgoing-transition-backward-__builtin__swipe {
3144
0% {
45+
transform: none;
3246
animation-timing-function: ease-in-out;
3347
}
3448

@@ -41,14 +55,15 @@
4155
@keyframes marp-incoming-transition-backward-__builtin__swipe {
4256
0% {
4357
animation-timing-function: ease-out;
44-
box-shadow: 6px 6px 10px 6px rgba(0, 0, 0, 25%);
58+
box-shadow: var(--bespoke-marp-transition-swipe-shadow);
4559
transform: translate(calc(-100vw - 30px), 30vh) rotate(30deg);
4660
transform-origin: 100% 0%;
4761
z-index: 1;
4862
}
4963

5064
100% {
51-
box-shadow: 6px 6px 10px 6px rgba(0, 0, 0, 25%);
65+
box-shadow: var(--bespoke-marp-transition-swipe-shadow);
66+
transform: none;
5267
transform-origin: 100% 0%;
5368
z-index: 1;
5469
}

src/engine/transition/keyframes/zoom.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@keyframes marp-outgoing-transition-backward-__builtin__zoom {
1616
from {
17+
transform: none;
1718
animation-timing-function: ease-in;
1819
}
1920

0 commit comments

Comments
 (0)