From 8fa97a173a7cafe8503e884c36512b92278dc6e2 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Mon, 3 Aug 2026 22:51:17 +0800 Subject: [PATCH] Remove animejs (#982) --- _vendors.yml | 5 --- scripts/helpers/next-vendors.js | 2 +- source/js/bookmark.js | 24 +++++++++----- source/js/motion.js | 59 ++++++++++++++++++++++----------- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/_vendors.yml b/_vendors.yml index 71311b5..326bfce 100644 --- a/_vendors.yml +++ b/_vendors.yml @@ -1,11 +1,6 @@ # This file is automatically generated # See https://github.com/next-theme/plugins -anime: - name: animejs - version: 3.2.1 - file: lib/anime.min.js - integrity: sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY= fontawesome: name: '@fortawesome/fontawesome-free' version: 7.0.0 diff --git a/scripts/helpers/next-vendors.js b/scripts/helpers/next-vendors.js index 0c06549..912a563 100644 --- a/scripts/helpers/next-vendors.js +++ b/scripts/helpers/next-vendors.js @@ -4,7 +4,7 @@ hexo.extend.helper.register('js_vendors', function() { const { config, theme } = this; - const vendors = ['anime']; + const vendors = []; if (theme.prism.enable && !config.prismjs.preprocess) { vendors.push('prism', 'prism_autoloader'); if (config.prismjs.line_number) { diff --git a/source/js/bookmark.js b/source/js/bookmark.js index a68880c..392d00d 100644 --- a/source/js/bookmark.js +++ b/source/js/bookmark.js @@ -31,17 +31,25 @@ document.addEventListener('DOMContentLoaded', () => { // Save the position by clicking the icon link.addEventListener('click', () => { doSaveScroll(); - window.anime({ - targets : link, + if (typeof link.animate !== 'function') { + link.style.top = '-30px'; + setTimeout(() => { + link.style.top = ''; + }, 600); + return; + } + const animation = link.animate([{}, { top: '-30px' }], { duration: 200, easing : 'linear', - top : -30, - complete: () => { - setTimeout(() => { - link.style.top = ''; - }, 400); - } + fill : 'forwards' }); + animation.finished.then(() => { + link.style.top = '-30px'; + animation.cancel(); + setTimeout(() => { + link.style.top = ''; + }, 400); + }).catch(() => {}); }); scrollToMark(); document.addEventListener('pjax:success', scrollToMark); diff --git a/source/js/motion.js b/source/js/motion.js index 0a472e0..6837331 100644 --- a/source/js/motion.js +++ b/source/js/motion.js @@ -14,16 +14,38 @@ NexT.motion.integrator = { return this; }, bootstrap() { + if (typeof Element.prototype.animate !== 'function') { + document.body.classList.remove('use-motion'); + CONFIG.motion.enable = false; + return; + } if (!CONFIG.motion.async) this.queue = [this.queue.flat()]; - this.queue.forEach(sequence => { - const timeline = window.anime.timeline({ - duration: CONFIG.motion?.duration ?? 200, - easing : 'linear' - }); - sequence.forEach(item => { - if (item.deltaT) timeline.add(item, item.deltaT); - else timeline.add(item); - }); + this.queue.forEach(sequence => this.schedule(sequence)); + }, + schedule(sequence) { + let cursor = 0; + sequence.forEach(item => { + const duration = item.duration ?? CONFIG.motion?.duration ?? 200; + const start = Math.max(0, cursor - (item.overlap ?? 0)); + const end = start + duration; + cursor = Math.max(cursor, end); + + if (item.styles) { + const targets = typeof item.targets === 'string' ? document.querySelectorAll(item.targets) : [item.targets].filter(Boolean); + targets.forEach(target => { + const animation = target.animate([{}, item.styles], { + delay : start, + duration, + easing: 'linear', + fill : 'forwards' + }); + animation.finished.then(() => { + Object.assign(target.style, item.styles); + animation.cancel(); + }).catch(() => {}); + }); + } + if (item.complete) setTimeout(item.complete, end); }); } }; @@ -35,18 +57,17 @@ NexT.motion.middleWares = { function getMistLineSettings(targets) { sequence.push({ targets, - scaleX : [0, 1], + styles : { transform: 'scaleX(1)' }, duration: 500, - deltaT : '-=200' + overlap : 200 }); } function pushToSequence(targets, sequenceQueue = false) { sequence.push({ targets, - opacity: 1, - top : 0, - deltaT : sequenceQueue ? '-=200' : '-=0' + styles : { opacity: 1, top: '0px' }, + overlap: sequenceQueue ? 200 : 0 }); } @@ -64,7 +85,7 @@ NexT.motion.middleWares = { sequence.push({ targets, complete: () => targets.classList.add('animated', menuItemTransition), - deltaT : '-=200' + overlap : 200 }); }); } @@ -92,7 +113,7 @@ NexT.motion.middleWares = { sequence.push({ targets, complete: () => targets.classList.add('animated', animation), - deltaT : '-=100' + overlap : 100 }); }); } @@ -101,7 +122,7 @@ NexT.motion.middleWares = { sequence.push({ targets, complete: () => targets.classList.add('animated', post_block), - deltaT : '-=100' + overlap : 100 }); animate(coll_header, targets.querySelectorAll('.collection-header')); animate(post_header, targets.querySelectorAll('.post-header')); @@ -123,7 +144,7 @@ NexT.motion.middleWares = { sequence.push({ targets, complete: () => targets.classList.add('animated', sidebarTransition), - deltaT : '-=100' + overlap : 100 }); }); } @@ -133,7 +154,7 @@ NexT.motion.middleWares = { footer() { return [{ targets: document.querySelector('.footer'), - opacity: 1 + styles : { opacity: 1 } }]; } };