Skip to content

Commit 83df5ac

Browse files
authored
Set visibility: visible after animation finishes (#164)
* Set visibility: visible after animation finishes * update * update * Add changeset
1 parent 53cc17f commit 83df5ac

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

.changeset/cold-crews-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"slidev-addon-fancy-arrow": patch
3+
---
4+
5+
Animate overlay contents

components/FancyArrow.vue

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
type SnapAnchorPoint,
66
} from "./parse-option";
77
import { useEndpointResolution } from "./use-element-position";
8-
import { useRoughArrow, type AbsolutePosition } from "./use-rough-arrow";
8+
import {
9+
useRoughArrow,
10+
DEFAULT_ANIMATION_DURATION,
11+
type AbsolutePosition,
12+
} from "./use-rough-arrow";
913
1014
const props = defineProps<{
1115
from?: string; // Shorthand for (q1 and pos1) or (x1 and y1)
@@ -80,6 +84,14 @@ const point2: Ref<AbsolutePosition | undefined> = useEndpointResolution(
8084
},
8185
);
8286
87+
const animationEnabled = computed(() => {
88+
return (
89+
props.animated ||
90+
props.animationDuration != null ||
91+
props.animationDelay != null
92+
);
93+
});
94+
8395
const { arrowSvg, textPosition } = useRoughArrow({
8496
point1,
8597
point2,
@@ -90,19 +102,18 @@ const { arrowSvg, textPosition } = useRoughArrow({
90102
headSize: props.headSize ? Number(props.headSize) : null,
91103
roughness: props.roughness ? Number(props.roughness) : undefined,
92104
seed: props.seed ? Number(props.seed) : undefined,
93-
animation:
94-
props.animated || props.animationDuration || props.animationDelay
95-
? {
96-
duration:
97-
props.animationDuration != null
98-
? Number(props.animationDuration)
99-
: undefined,
100-
delay:
101-
props.animationDelay != null
102-
? Number(props.animationDelay)
103-
: undefined,
104-
}
105-
: undefined,
105+
animation: animationEnabled.value
106+
? {
107+
duration:
108+
props.animationDuration != null
109+
? Number(props.animationDuration)
110+
: undefined,
111+
delay:
112+
props.animationDelay != null
113+
? Number(props.animationDelay)
114+
: undefined,
115+
}
116+
: undefined,
106117
strokeAnimationKeyframeName: "rough-arrow-dash",
107118
fillAnimationKeyframeName: "rough-arrow-fill",
108119
});
@@ -131,6 +142,10 @@ const { arrowSvg, textPosition } = useRoughArrow({
131142
left: `${textPosition.x}px`,
132143
top: `${textPosition.y}px`,
133144
transform: 'translate(-50%, -50%)',
145+
visibility: animationEnabled ? 'hidden' : 'visible',
146+
animation: animationEnabled
147+
? `rough-arrow-content ${props.animationDuration ?? DEFAULT_ANIMATION_DURATION}ms ease-out ${props.animationDelay ?? 0}ms forwards`
148+
: 'none',
134149
}"
135150
>
136151
<slot />
@@ -158,4 +173,16 @@ const { arrowSvg, textPosition } = useRoughArrow({
158173
visibility: visible;
159174
}
160175
}
176+
177+
@keyframes rough-arrow-content {
178+
from {
179+
visibility: hidden;
180+
}
181+
99.99% {
182+
visibility: hidden;
183+
}
184+
100% {
185+
visibility: visible;
186+
}
187+
}
161188
</style>

components/use-rough-arrow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { splitPath } from "./split-path";
44

55
type RoughSVG = ReturnType<typeof roughjs.svg>;
66

7-
const DEFAULT_ANIMATION_DURATION = 800; // Same as https://github.com/rough-stuff/rough-notation/blob/668ba82ac89c903d6f59c9351b9b85855da9882c/src/model.ts#L3C14-L3C47
7+
export const DEFAULT_ANIMATION_DURATION = 800; // Same as https://github.com/rough-stuff/rough-notation/blob/668ba82ac89c903d6f59c9351b9b85855da9882c/src/model.ts#L3C14-L3C47
88

99
const createArrowHeadSvg = (
1010
roughSvg: RoughSVG,

slides.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,13 @@ If no snap target or absolute position is specified, the arrow will automaticall
712712
<img src="https://sli.dev/logo.svg" w-10 m-auto/>
713713
</FancyArrow>
714714

715-
<div mt-40>
715+
<FancyArrow x1="500" y1="100" x2="600" y2="200" animated>
716+
Animated
717+
</FancyArrow>
716718

717-
```html
719+
<div mt-40 h-70>
720+
721+
```html {*}{maxHeight: '100%'}
718722
<FancyArrow x1="100" y1="100" x2="200" y2="200" >
719723
Hello
720724
</FancyArrow>
@@ -731,6 +735,10 @@ If no snap target or absolute position is specified, the arrow will automaticall
731735
<span text-nowrap>Slidev logo</span>
732736
<img src="https://sli.dev/logo.svg" w-10 m-auto/>
733737
</FancyArrow>
738+
739+
<FancyArrow x1="500" y1="100" x2="600" y2="200" animated>
740+
Animated
741+
</FancyArrow>
734742
```
735743

736744
</div>

0 commit comments

Comments
 (0)