mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 15:09:22 +00:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/* eslint-disable no-undef */
|
|
import { siteConfig } from '@/lib/config'
|
|
import { useGlobal } from '@/lib/global'
|
|
import { loadExternalResource } from '@/lib/utils'
|
|
import { useEffect } from 'react'
|
|
|
|
/**
|
|
* 网页动画
|
|
* @returns
|
|
*/
|
|
export default function Live2D() {
|
|
const { theme, switchTheme } = useGlobal()
|
|
const showPet = JSON.parse(siteConfig('WIDGET_PET'))
|
|
const petLink = siteConfig('WIDGET_PET_LINK')
|
|
|
|
useEffect(() => {
|
|
if (showPet) {
|
|
Promise.all([
|
|
loadExternalResource('https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/live2d.min.js', 'js')
|
|
]).then((e) => {
|
|
if (typeof window?.loadlive2d !== 'undefined') {
|
|
// https://github.com/xiazeyu/live2d-widget-models
|
|
try {
|
|
loadlive2d('live2d', petLink)
|
|
} catch (error) {
|
|
console.error('读取PET模型', error)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}, [theme])
|
|
|
|
function handleClick() {
|
|
if (JSON.parse(siteConfig('WIDGET_PET_SWITCH_THEME'))) {
|
|
switchTheme()
|
|
}
|
|
}
|
|
|
|
if (!showPet) {
|
|
return <></>
|
|
}
|
|
|
|
return <canvas id="live2d" width="280" height="250" onClick={handleClick}
|
|
className="cursor-grab"
|
|
onMouseDown={(e) => e.target.classList.add('cursor-grabbing')}
|
|
onMouseUp={(e) => e.target.classList.remove('cursor-grabbing')}
|
|
/>
|
|
}
|