blob: 7c2393bf5cc5399f6debc2ac05e4661a7202f7ed (
plain)
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
|
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<span>{{ number(Math.floor(tweened.number)) }}</span>
</template>
<script lang="ts" setup>
import { reactive, watch } from 'vue';
import number from '@/filters/number.js';
import { prefer } from '@/preferences';
const props = defineProps<{
value: number;
}>();
const tweened = reactive({
number: 0,
});
watch(() => props.value, (to, from) => {
// requestAnimationFrameを利用して、500msでfromからtoまでを1次関数的に変化させる
let start: number | null = null;
function step(timestamp: number) {
if (start === null) {
start = timestamp;
}
const elapsed = timestamp - start;
tweened.number = (from ?? 0) + (to - (from ?? 0)) * elapsed / 500;
if (elapsed < 500) {
window.requestAnimationFrame(step);
} else {
tweened.number = to;
}
}
if (prefer.s.animation) {
window.requestAnimationFrame(step);
} else {
tweened.number = to;
}
}, {
immediate: true,
});
</script>
|