feat: Update danmuku plugin with responsive behavior

This commit is contained in:
Harvey Zack committed 2024-06-12 21:40:17 +08:00
1 parent 744913b0bf
commit 665348ad55
10 files changed
+103 -24

No files matched your search

@@ -34,6 +34,29 @@ export default function autoOrientation(art) {
}
});
art.on('fullscreen', async (state) => {
if (!screen?.orientation?.lock) return;
const lastOrientation = screen.orientation.type;
if (state) {
const { videoWidth, videoHeight } = $video;
const { clientWidth: viewWidth, clientHeight: viewHeight } = document.documentElement;
if (
(videoWidth > videoHeight && viewWidth < viewHeight) ||
(videoWidth < videoHeight && viewWidth > viewHeight)
) {
const oppositeOrientation = lastOrientation.startsWith('portrait') ? 'landscape' : 'portrait';
await screen.orientation.lock(oppositeOrientation);
addClass($player, 'art-auto-orientation-fullscreen');
}
} else {
if (hasClass($player, 'art-auto-orientation-fullscreen')) {
await screen.orientation.lock(lastOrientation);
removeClass($player, 'art-auto-orientation-fullscreen');
}
}
});
return {
name: 'autoOrientation',
get state() {