From bb09f08f8465fa2e54ebdfa084c685f54237a24d Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 25 Aug 2025 14:39:45 +0900 Subject: [PATCH] :art: --- .../directives/flip-on-device-orientation.ts | 45 ------- packages/frontend/src/directives/index.ts | 2 - packages/frontend/src/pages/qr.show.vue | 123 +++++++++++++++--- packages/frontend/src/pages/qr.vue | 8 +- 4 files changed, 113 insertions(+), 65 deletions(-) delete mode 100644 packages/frontend/src/directives/flip-on-device-orientation.ts diff --git a/packages/frontend/src/directives/flip-on-device-orientation.ts b/packages/frontend/src/directives/flip-on-device-orientation.ts deleted file mode 100644 index 134482c1c2..0000000000 --- a/packages/frontend/src/directives/flip-on-device-orientation.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { Directive } from 'vue'; - -let initialized = false; -let styleEl: HTMLStyleElement | null = null; -const canUseDeviceOrientation = !!window.DeviceOrientationEvent; -const className = '_flipOnDeviceOrientation'; -const variableName = `--MI-flip_on_device_orientation_transform`; - -function handleOrientationChange(event: DeviceOrientationEvent) { - const isUpsideDown = event.beta ? event.beta < 5 : false; - const transform = isUpsideDown ? 'scale(-1, -1)' : ''; - window.document.documentElement.style.setProperty(variableName, transform); -} - -function registerListener() { - if (!canUseDeviceOrientation) return; - - if (!initialized) { - window.addEventListener('deviceorientation', handleOrientationChange); - if (!styleEl) { - styleEl = window.document.createElement('style'); - styleEl.textContent = `.${className} { transform: var(${variableName}); }`; - window.document.head.appendChild(styleEl); - } - initialized = true; - } else if (window.document.getElementsByClassName(className).length === 0) { - window.removeEventListener('deviceorientation', handleOrientationChange); - if (styleEl) { - window.document.head.removeChild(styleEl); - styleEl = null; - } - initialized = false; - } -} - -export default { - mounted(el) { - registerListener(); - el.classList.add(className); - }, - unmounted(el) { - el.classList.remove(className); - registerListener(); - }, -} as Directive; diff --git a/packages/frontend/src/directives/index.ts b/packages/frontend/src/directives/index.ts index c6948d8c06..9555045afe 100644 --- a/packages/frontend/src/directives/index.ts +++ b/packages/frontend/src/directives/index.ts @@ -16,7 +16,6 @@ import clickAnime from './click-anime.js'; import panel from './panel.js'; import adaptiveBorder from './adaptive-border.js'; import adaptiveBg from './adaptive-bg.js'; -import flipOnDeviceOrientation from './flip-on-device-orientation.js'; export default function(app: App) { for (const [key, value] of Object.entries(directives)) { @@ -37,5 +36,4 @@ export const directives = { 'panel': panel, 'adaptive-border': adaptiveBorder, 'adaptive-bg': adaptiveBg, - 'flip-on-device-orientation': flipOnDeviceOrientation, }; diff --git a/packages/frontend/src/pages/qr.show.vue b/packages/frontend/src/pages/qr.show.vue index ed8d33bc3c..3642579c46 100644 --- a/packages/frontend/src/pages/qr.show.vue +++ b/packages/frontend/src/pages/qr.show.vue @@ -4,7 +4,12 @@ SPDX-License-Identifier: AGPL-3.0-only -->