Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions packages/frontend/src/components/MkAnalogClock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<line
ref="sLine"
:class="[$style.s, { [$style.animate]: !disableSAnimate && sAnimation !== 'none', [$style.elastic]: sAnimation === 'elastic', [$style.easeOut]: sAnimation === 'easeOut' }]"
:class="$style.s"
:x1="5 - (0 * (sHandLengthRatio * handsTailLength))"
:y1="5 + (1 * (sHandLengthRatio * handsTailLength))"
:x2="5 + (0 * ((sHandLengthRatio * 5) - handsPadding))"
Expand Down Expand Up @@ -137,7 +137,6 @@ const texts = computed(() => {
return angles;
});

let enabled = true;
const majorGraduationColor = ref<string>();
//let minorGraduationColor = $ref<string>();
const sHandColor = ref<string>();
Expand All @@ -150,9 +149,26 @@ const s = ref<number>(0);
const hAngle = ref<number>(0);
const mAngle = ref<number>(0);
const sAngle = ref<number>(0);
const disableSAnimate = ref(false);
let sOneRound = false;
const sLine = ref<SVGPathElement>();
const sLine = ref<SVGLineElement>();
let sHandAnimation: Animation | null = null;

const sAnimationTimings = {
elastic: { duration: 200, easing: 'cubic-bezier(.4,2.08,.55,.44)' },
easeOut: { duration: 700, easing: 'cubic-bezier(0,.7,.3,1)' },
} as const satisfies Record<string, KeyframeAnimationOptions>;

function animateSecondHand(from: number, to: number) {
if (props.sAnimation === 'none' || sLine.value == null) return;

let delta = to - from;
if (delta < -Math.PI) delta += Math.PI * 2;

sHandAnimation?.cancel();
sHandAnimation = sLine.value.animate([
{ transform: `rotateZ(${from}rad)` },
{ transform: `rotateZ(${from + delta}rad)` },
], sAnimationTimings[props.sAnimation]);
}

function tick() {
const now = props.now();
Expand All @@ -168,25 +184,11 @@ function tick() {
}
hAngle.value = Math.PI * (h.value % (props.twentyfour ? 24 : 12) + (m.value + s.value / 60) / 60) / (props.twentyfour ? 12 : 6);
mAngle.value = Math.PI * (m.value + s.value / 60) / 30;
if (sOneRound && sLine.value) { // 秒針が一周した際のアニメーションをよしなに処理する(これが無いと秒が59->0になったときに期待したアニメーションにならない)
sAngle.value = Math.PI * 60 / 30;
defaultIdlingRenderScheduler.delete(tick);
sLine.value.addEventListener('transitionend', () => {
disableSAnimate.value = true;
requestAnimationFrame(() => {
sAngle.value = 0;
requestAnimationFrame(() => {
disableSAnimate.value = false;
if (enabled) {
defaultIdlingRenderScheduler.add(tick);
}
});
});
}, { once: true });
} else {
sAngle.value = Math.PI * s.value / 30;
const previousSAngle = sAngle.value;
sAngle.value = Math.PI * s.value / 30;
if (previousS !== s.value) {
animateSecondHand(previousSAngle, sAngle.value);
}
sOneRound = s.value === 59;
}

tick();
Expand All @@ -211,8 +213,8 @@ onMounted(() => {
});

onBeforeUnmount(() => {
enabled = false;
defaultIdlingRenderScheduler.delete(tick);
sHandAnimation?.cancel();
themeManager.off('themeChanged', calcColors);
});
</script>
Expand All @@ -225,13 +227,5 @@ onBeforeUnmount(() => {
.s {
will-change: transform;
transform-origin: 50% 50%;

&.animate.elastic {
transition: transform .2s cubic-bezier(.4,2.08,.55,.44);
}

&.animate.easeOut {
transition: transform .7s cubic-bezier(0,.7,.3,1);
}
}
</style>
30 changes: 17 additions & 13 deletions packages/frontend/src/components/MkButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,23 @@ function onMousedown(evt: MouseEvent): void {

const scale = calcCircleScale(target.clientWidth, target.clientHeight, circleCenterX, circleCenterY);

window.setTimeout(() => {
ripple.style.transform = 'scale(' + (scale / 2) + ')';
}, 1);
window.setTimeout(() => {
ripple.style.transition = 'all 1s ease';
ripple.style.opacity = '0';
}, 1000);
window.setTimeout(() => {
if (ripples.value) ripples.value.removeChild(ripple);
}, 2000);
ripple.animate({
transform: ['scale(1)', `scale(${scale / 2})`],
}, {
duration: 500,
easing: 'cubic-bezier(0,.5,0,1)',
fill: 'forwards',
});

const removeRipple = () => ripple.remove();
ripple.animate({
opacity: [1, 0],
}, {
delay: 1000,
duration: 1000,
easing: 'ease',
fill: 'forwards',
}).finished.then(removeRipple, removeRipple);
}
</script>

Expand Down Expand Up @@ -310,9 +317,6 @@ function onMousedown(evt: MouseEvent): void {
height: 2px;
border-radius: 100%;
background: rgba(0, 0, 0, 0.1);
opacity: 1;
transform: scale(1);
transition: all 0.5s cubic-bezier(0,.5,0,1);
}

.content {
Expand Down
37 changes: 19 additions & 18 deletions packages/frontend/src/components/MkDigitalClock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<span>
<span v-text="hh"></span>
<span :class="[$style.colon, { [$style.showColon]: showColon }]">:</span>
<span ref="colonMEl" :class="$style.colon">:</span>
<span v-text="mm"></span>
<span v-if="showS" :class="[$style.colon, { [$style.showColon]: showColon }]">:</span>
<span v-if="showS" ref="colonSEl" :class="$style.colon">:</span>
<span v-if="showS" v-text="ss"></span>
<span v-if="showMs" :class="[$style.colon, { [$style.showColon]: showColon }]">:</span>
<span v-if="showMs" ref="colonMsEl" :class="$style.colon">:</span>
<span v-if="showMs" v-text="ms"></span>
</span>
</template>

<script lang="ts" setup>
import { onMounted, onUnmounted, ref, watch } from 'vue';
import { onMounted, onUnmounted, ref, useTemplateRef } from 'vue';
import { defaultIdlingRenderScheduler } from '@/utility/idle-render.js';

const props = withDefaults(defineProps<{
Expand All @@ -35,16 +35,22 @@ const hh = ref('');
const mm = ref('');
const ss = ref('');
const ms = ref('');
const showColon = ref(false);
const colonMEl = useTemplateRef('colonMEl');
const colonSEl = useTemplateRef('colonSEl');
const colonMsEl = useTemplateRef('colonMsEl');
let prevSec: number | null = null;

watch(showColon, (v) => {
if (v) {
window.setTimeout(() => {
showColon.value = false;
}, 30);
function blinkColons() {
for (const el of [colonMEl.value, colonSEl.value, colonMsEl.value]) {
el?.animate([
{ opacity: 1 },
{ opacity: 0 },
], {
duration: 1000,
easing: 'ease',
});
}
});
}

const tick = (): void => {
const now = props.now();
Expand All @@ -53,13 +59,14 @@ const tick = (): void => {
mm.value = now.getMinutes().toString().padStart(2, '0');
ss.value = now.getSeconds().toString().padStart(2, '0');
ms.value = Math.floor(now.getMilliseconds() / 10).toString().padStart(2, '0');
if (now.getSeconds() !== prevSec) showColon.value = true;
if (now.getSeconds() !== prevSec) blinkColons();
prevSec = now.getSeconds();
};

tick();

onMounted(() => {
blinkColons();
defaultIdlingRenderScheduler.add(tick);
});

Expand All @@ -71,11 +78,5 @@ onUnmounted(() => {
<style lang="scss" module>
.colon {
opacity: 0;
transition: opacity 1s ease;

&.showColon {
opacity: 1;
transition: opacity 0s;
}
}
</style>
40 changes: 24 additions & 16 deletions packages/frontend/src/components/MkPlusOneEffect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div :class="$style.root" :style="{ zIndex, top: `${y - 64}px`, left: `${x - 64}px` }">
<span class="text" :class="{ up }">+{{ value }}</span>
<span ref="textEl" class="text">+{{ value }}</span>
</div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { onMounted, useTemplateRef } from 'vue';
import * as os from '@/os.js';

const props = withDefaults(defineProps<{
Expand All @@ -25,18 +25,33 @@ const emit = defineEmits<{
(ev: 'end'): void;
}>();

const up = ref(false);
const textEl = useTemplateRef('textEl');
const zIndex = os.claimZIndex('middle');
const angle = (45 - (Math.random() * 90)) + 'deg';

onMounted(() => {
window.setTimeout(() => {
up.value = true;
}, 10);

window.setTimeout(() => {
if (textEl.value == null) {
emit('end');
}, 1100);
return;
}

const end = () => emit('end');
Promise.all([
textEl.value.animate({
transform: ['translateY(0px)', `translateY(-50px) rotateZ(${angle})`],
}, {
duration: 1000,
easing: 'cubic-bezier(0,.5,0,1)',
fill: 'forwards',
}).finished,
textEl.value.animate({
opacity: [1, 0],
}, {
duration: 1000,
easing: 'cubic-bezier(.5,0,1,.5)',
fill: 'forwards',
}).finished,
]).then(end, end);
});
</script>

Expand All @@ -63,14 +78,7 @@ onMounted(() => {
text-shadow: 0 0 6px #000;
font-size: 18px;
font-weight: bold;
transform: translateY(0px);
transition: transform 1s cubic-bezier(0,.5,0,1), opacity 1s cubic-bezier(.5,0,1,.5);
will-change: opacity, transform;

&.up {
opacity: 0;
transform: translateY(-50px) rotateZ(v-bind(angle));
}
}
}
}
Expand Down
39 changes: 24 additions & 15 deletions packages/frontend/src/components/MkReactionEffect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div :class="$style.root" :style="{ zIndex, top: `${y - 64}px`, left: `${x - 64}px` }">
<span :class="[$style.text, { [$style.up]: up }]">
<span ref="textEl" :class="$style.text">
<MkReactionIcon class="icon" :reaction="reaction"/>
</span>
</div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { onMounted, useTemplateRef } from 'vue';
import * as os from '@/os.js';
import MkReactionIcon from '@/components/MkReactionIcon.vue';

Expand All @@ -27,18 +27,33 @@ const emit = defineEmits<{
(ev: 'end'): void;
}>();

const up = ref(false);
const textEl = useTemplateRef('textEl');
const zIndex = os.claimZIndex('middle');
const angle = (90 - (Math.random() * 180)) + 'deg';

onMounted(() => {
window.setTimeout(() => {
up.value = true;
}, 10);

window.setTimeout(() => {
if (textEl.value == null) {
emit('end');
}, 1100);
return;
}

const end = () => emit('end');
Promise.all([
textEl.value.animate({
transform: ['translateY(-30px)', `translateY(-50px) rotateZ(${angle})`],
}, {
duration: 1000,
easing: 'cubic-bezier(0,.5,0,1)',
fill: 'forwards',
}).finished,
textEl.value.animate({
opacity: [1, 0],
}, {
duration: 1000,
easing: 'cubic-bezier(.5,0,1,.5)',
fill: 'forwards',
}).finished,
]).then(end, end);
});
</script>

Expand All @@ -64,12 +79,6 @@ onMounted(() => {
font-size: 18px;
font-weight: bold;
transform: translateY(-30px);
transition: transform 1s cubic-bezier(0,.5,0,1), opacity 1s cubic-bezier(.5,0,1,.5);
will-change: opacity, transform;

&.up {
opacity: 0;
transform: translateY(-50px) rotateZ(v-bind(angle));
}
}
</style>
Loading
Loading