2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-12-31 12:36:49 +01:00
|
|
|
<template>
|
2022-12-31 13:10:25 +01:00
|
|
|
<span>{{ number(Math.floor(tweened.number)) }}</span>
|
2022-12-31 12:36:49 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { reactive, watch } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import number from '@/filters/number.js';
|
2022-12-31 12:36:49 +01:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
value: number;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const tweened = reactive({
|
|
|
|
number: 0,
|
|
|
|
});
|
|
|
|
|
2024-01-02 08:55:02 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.requestAnimationFrame(step);
|
2022-12-31 12:36:49 +01:00
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
|
|
|
</script>
|