diff --git a/packages/frontend/src/components/MkAnalogClock.vue b/packages/frontend/src/components/MkAnalogClock.vue index f1e6fea9fb3..3411cfaa49a 100644 --- a/packages/frontend/src/components/MkAnalogClock.vue +++ b/packages/frontend/src/components/MkAnalogClock.vue @@ -45,7 +45,7 @@ SPDX-License-Identifier: AGPL-3.0-only { return angles; }); -let enabled = true; const majorGraduationColor = ref(); //let minorGraduationColor = $ref(); const sHandColor = ref(); @@ -150,9 +149,26 @@ const s = ref(0); const hAngle = ref(0); const mAngle = ref(0); const sAngle = ref(0); -const disableSAnimate = ref(false); -let sOneRound = false; -const sLine = ref(); +const sLine = ref(); +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; + +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(); @@ -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(); @@ -211,8 +213,8 @@ onMounted(() => { }); onBeforeUnmount(() => { - enabled = false; defaultIdlingRenderScheduler.delete(tick); + sHandAnimation?.cancel(); themeManager.off('themeChanged', calcColors); }); @@ -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); - } } diff --git a/packages/frontend/src/components/MkButton.vue b/packages/frontend/src/components/MkButton.vue index d7a622f1d92..1484303b2a9 100644 --- a/packages/frontend/src/components/MkButton.vue +++ b/packages/frontend/src/components/MkButton.vue @@ -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); } @@ -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 { diff --git a/packages/frontend/src/components/MkDigitalClock.vue b/packages/frontend/src/components/MkDigitalClock.vue index 8198356a76d..f667e6a7cc0 100644 --- a/packages/frontend/src/components/MkDigitalClock.vue +++ b/packages/frontend/src/components/MkDigitalClock.vue @@ -6,17 +6,17 @@ SPDX-License-Identifier: AGPL-3.0-only @@ -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)); - } } } } diff --git a/packages/frontend/src/components/MkReactionEffect.vue b/packages/frontend/src/components/MkReactionEffect.vue index 5a59a5e0556..ad591c1fbc5 100644 --- a/packages/frontend/src/components/MkReactionEffect.vue +++ b/packages/frontend/src/components/MkReactionEffect.vue @@ -5,14 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only @@ -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)); - } } diff --git a/packages/frontend/src/components/MkSparkle.vue b/packages/frontend/src/components/MkSparkle.vue index 47955a7fd7b..1a13e6b69d0 100644 --- a/packages/frontend/src/components/MkSparkle.vue +++ b/packages/frontend/src/components/MkSparkle.vue @@ -39,14 +39,10 @@ SPDX-License-Identifier: AGPL-3.0-only --> - + ([]); +}; + +const particles = ref([]); const el = useTemplateRef('el'); const width = ref(0); const height = ref(0); const colors = ['#FF1493', '#00FFFF', '#FFE202', '#FFE202', '#FFE202']; let stop = false; let ro: ResizeObserver | undefined; +const animatedEls = new WeakSet(); + +function animateParticle(el: SVGPathElement | null, particle: Particle) { + // 関数refは再レンダリングのたびに呼ばれるため、同じ要素で二重に再生しないようにする + if (el == null || animatedEls.has(el)) return; + animatedEls.add(el); + + const removeParticle = () => { + particles.value = particles.value.filter(x => x.id !== particle.id); + }; + el.animate({ + rotate: ['0deg', '360deg'], + scale: ['0', `${particle.size}`, '0'], + }, { + duration: particle.dur, + easing: 'linear', + }).finished.then(removeParticle, removeParticle); +} onMounted(() => { ro = new ResizeObserver((entries, observer) => { @@ -94,10 +110,10 @@ onMounted(() => { dur: 1000 + (sizeFactor * 1000), color: colors[Math.floor(Math.random() * colors.length)], }; - particles.value.push(particle); - window.setTimeout(() => { - particles.value = particles.value.filter(x => x.id !== particle.id); - }, particle.dur - 100); + // 非表示のタブではアニメーションのタイムラインが進まず、finished による削除が行われないため追加しない + if (window.document.visibilityState === 'visible') { + particles.value.push(particle); + } window.setTimeout(() => { add(); @@ -121,21 +137,6 @@ onUnmounted(() => { .particle { transform-origin: center; transform-box: fill-box; - translate: var(--translateX) var(--translateY); - animation: particleAnimation var(--duration) linear infinite; -} - -@keyframes particleAnimation { - 0% { - rotate: 0deg; - scale: 0; - } - 50% { - scale: var(--size); - } - 100% { - rotate: 360deg; - scale: 0; - } + scale: 0; } diff --git a/packages/frontend/src/directives/anim.ts b/packages/frontend/src/directives/anim.ts index a165fa11e08..a4fc46b5bf1 100644 --- a/packages/frontend/src/directives/anim.ts +++ b/packages/frontend/src/directives/anim.ts @@ -6,18 +6,17 @@ import type { Directive } from 'vue'; export const animDirective = { - beforeMount(src) { - src.style.opacity = '0'; - src.style.transform = 'scale(0.9)'; - // ページネーションと相性が悪いので - //if (typeof binding.value === 'number') src.style.transitionDelay = `${binding.value * 30}ms`; - src.classList.add('_zoom'); - }, - mounted(src) { - window.setTimeout(() => { - src.style.opacity = '1'; - src.style.transform = 'none'; - }, 1); + // 終了値は指定せず、要素本来のスタイルに向かってアニメーションさせる + src.animate([{ + offset: 0, + opacity: 0, + transform: 'scale(0.9)', + }], { + duration: 500, + easing: 'cubic-bezier(0,.5,.5,1)', + // ページネーションと相性が悪いので + //delay: typeof binding.value === 'number' ? binding.value * 30 : 0, + }); }, } as Directive; diff --git a/packages/frontend/src/directives/click-anime.ts b/packages/frontend/src/directives/click-anime.ts index 67adc0b7ec6..9cabc1f9b69 100644 --- a/packages/frontend/src/directives/click-anime.ts +++ b/packages/frontend/src/directives/click-anime.ts @@ -8,6 +8,13 @@ import { prefer } from '@/preferences.js'; const abortControllers = new WeakMap(); +const bounceKeyframes: Keyframe[] = [ + { offset: 0, transform: 'scale(0.9)', easing: 'ease' }, + { offset: 0.19, transform: 'scale(1.1)', easing: 'ease' }, + { offset: 0.48, transform: 'scale(0.95)', easing: 'ease' }, + { offset: 1, transform: 'scale(1)' }, +]; + export const clickAnimeDirective = { mounted(el) { if (!prefer.s.animation) return; @@ -19,12 +26,14 @@ export const clickAnimeDirective = { const abortController = new AbortController(); abortControllers.set(el, abortController); + let bounceAnimation: Animation | null = null; + target.classList.add('_anime_bounce_standBy'); el.addEventListener('mousedown', () => { - target.classList.remove('_anime_bounce'); + bounceAnimation?.cancel(); + bounceAnimation = null; - target.classList.add('_anime_bounce_standBy'); target.classList.add('_anime_bounce_ready'); target.addEventListener('mouseleave', () => { @@ -33,13 +42,10 @@ export const clickAnimeDirective = { }, { signal: abortController.signal }); el.addEventListener('click', () => { - target.classList.add('_anime_bounce'); target.classList.remove('_anime_bounce_ready'); - }, { signal: abortController.signal }); - el.addEventListener('animationend', () => { - target.classList.remove('_anime_bounce'); - target.classList.add('_anime_bounce_standBy'); + bounceAnimation?.cancel(); + bounceAnimation = target.animate(bounceKeyframes, { duration: 700 }); }, { signal: abortController.signal }); }, diff --git a/packages/frontend/src/style.scss b/packages/frontend/src/style.scss index bf68e268407..f55f32182fb 100644 --- a/packages/frontend/src/style.scss +++ b/packages/frontend/src/style.scss @@ -484,12 +484,6 @@ rt { font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace !important; } -._zoom { - transition-duration: 0.5s, 0.5s; - transition-property: opacity, transform; - transition-timing-function: cubic-bezier(0,.5,.5,1); -} - ._woodenFrame { padding: 7px; background: #8C4F26; @@ -567,12 +561,6 @@ html[data-color-scheme=dark] ._woodenFrame { } } -._anime_bounce { - will-change: transform; - animation: global-bounce ease 0.7s; - animation-iteration-count: 1; - transform-origin: 50% 50%; -} ._anime_bounce_ready { will-change: transform; transform: scaleX(0.90) scaleY(0.90) ; @@ -581,21 +569,6 @@ html[data-color-scheme=dark] ._woodenFrame { transition: transform 0.1s ease; } -@keyframes global-bounce { - 0% { - transform: scaleX(0.90) scaleY(0.90) ; - } - 19% { - transform: scaleX(1.10) scaleY(1.10) ; - } - 48% { - transform: scaleX(0.95) scaleY(0.95) ; - } - 100% { - transform: scaleX(1.00) scaleY(1.00) ; - } -} - // MFM ----------------------------- ._mfm_blur_ {