-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotFound.vue
201 lines (166 loc) · 4.59 KB
/
NotFound.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
<section class="icon-content-container">
<div ref="iconRef" class="icon">
<router-link to="/">
<img ref="outerRef" src="/svg/outer.svg" alt="loadicon" class="outer" />
<img ref="innerRef" src="/svg/inner.svg" alt="loadicon" class="inner" />
</router-link>
</div>
<h1 ref="textRef" v-hover="hover" class="text">
{{ revealErrorText ? errorData.details : errorData.code }}
</h1>
</section>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import anime from "animejs";
import { computedWithControl } from "@vueuse/core";
import type { FullGestureState } from "@vueuse/gesture";
import type { MotionProperties } from "@vueuse/motion";
import _ from "lodash";
import type { Nullable } from "@antfu/utils";
import { useTimeline, useSpringAnimation, useInitialProps } from "@common/composables";
import { bubbleAnimation, clearCSSProperties } from "@common/animations";
// template refs
const iconRef = ref<Nullable<HTMLElement>>(null);
const outerRef = ref<Nullable<HTMLElement>>(null);
const innerRef = ref<Nullable<HTMLElement>>(null);
const textRef = ref<Nullable<HTMLElement>>(null);
// shared
const errorData = {
code: 404,
details: "Not Found",
};
// reactive
const { timeline } = useTimeline({ duration: 750, delay: 250 });
const revealErrorText = ref(false);
const isTextAnimated = ref<boolean>();
// initial props
const initialProps = useInitialProps({ scale: 1 });
// spring-set function
const set = computedWithControl(
() => isTextAnimated.value,
() => {
if (isTextAnimated.value === false) {
const { set } = useSpringAnimation(textRef, initialProps, {
stiffness: 500,
});
return set;
}
return (properties: MotionProperties) => _.noop(properties);
}
);
// hovering
const hover = ({ hovering }: FullGestureState<"move">) => {
revealErrorText.value = hovering;
if (hovering) set.value({ scale: 1.1 });
else set.value(initialProps);
};
// hooks
onMounted(() => {
// center outer and inner in container because those absolutely positioned
anime.set(outerRef.value!, { translateX: "-50%", translateY: "-50%" });
anime.set(innerRef.value!, { translateX: "-50%", translateY: "-50%" });
timeline
.add({
targets: iconRef.value,
...bubbleAnimation,
// FIXME: `scale` property affects page
complete: () => clearCSSProperties(iconRef.value!, ["transform"]),
})
.add({
begin: () => (isTextAnimated.value = true),
targets: textRef.value,
...bubbleAnimation,
complete: () => {
clearCSSProperties(textRef.value!, ["transform"]);
isTextAnimated.value = false;
},
})
.finished.then(() => {
anime({
targets: outerRef.value,
rotate: [90, 180, 270, 360],
duration: 8000,
loop: true,
});
anime({
targets: innerRef.value,
rotate: [60, 120, 180, 240, 300, 360],
duration: 6000,
loop: true,
});
});
});
</script>
<style lang="scss" scoped>
$outer-icon-height: 10em;
$hovered-outer-icon-height: calc($outer-icon-height + 0.5em);
$inner-icon-height: calc($outer-icon-height / 1.5);
$hovered-inner-icon-height: calc($inner-icon-height + 0.5em);
$icon-container-size: calc($outer-icon-height * 1.5);
$text-font-weight: normal;
$text-font-size: calc($outer-icon-height / 7);
.icon-content-container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 100%;
height: 100%;
.icon {
height: $icon-container-size;
.outer,
.inner {
position: absolute;
top: 50%;
left: 50%;
// transform: translate(-50%, -50%);
transition: height 0.15s ease-out;
}
.outer {
height: $outer-icon-height;
&:hover {
height: $hovered-outer-icon-height;
}
}
.inner {
height: $inner-icon-height;
&:hover {
height: $hovered-inner-icon-height;
}
}
}
.text {
font-family: monospace;
font-size: $text-font-size;
font-weight: $text-font-weight;
padding: 0.25em;
transition: color 0.25s ease-out;
&:hover {
color: white;
&::selection {
color: black;
background: white;
}
&::after {
transform: scaleY(1);
transform-origin: bottom;
}
}
&::after {
content: "";
position: fixed;
left: 0;
bottom: 0;
z-index: -1;
width: 100%;
height: 100%;
background: black;
transform: scaleY(0);
transform-origin: top;
transition: transform 0.25s ease-out;
}
}
}
</style>