refactor: use import.meta.* properties

ref: https://github.com/nuxt/nuxt/issues/25323
This commit is contained in:
kakkokari-gtyih 2024-03-29 22:59:41 +09:00
parent 9d3a0e36d3
commit 835b1120c9
17 changed files with 25 additions and 25 deletions

View File

@ -159,13 +159,13 @@ async function updatePos() {
scrollPos.value = document.body.getBoundingClientRect().y; scrollPos.value = document.body.getBoundingClientRect().y;
} }
if (process.client) { if (import.meta.client) {
window.addEventListener('scroll', updatePos); window.addEventListener('scroll', updatePos);
window.addEventListener('resize', updatePos); window.addEventListener('resize', updatePos);
} }
onUnmounted(() => { onUnmounted(() => {
if (process.client) { if (import.meta.client) {
window.removeEventListener('scroll', updatePos); window.removeEventListener('scroll', updatePos);
window.removeEventListener('resize', updatePos); window.removeEventListener('resize', updatePos);
} }
@ -175,7 +175,7 @@ const hideFrom = computed(() => route.meta.scrollButton ? route.meta.scrollButto
const sbPosition = computed(() => route.meta.scrollButton ? { x: route.meta.scrollButton?.customPosition?.x ?? '2.5rem', y: route.meta.scrollButton?.customPosition?.y ?? '2.5rem' } ?? { x: '2.5rem', y: '2.5rem' } : { x: '2.5rem', y: '2.5rem' }); const sbPosition = computed(() => route.meta.scrollButton ? { x: route.meta.scrollButton?.customPosition?.x ?? '2.5rem', y: route.meta.scrollButton?.customPosition?.y ?? '2.5rem' } ?? { x: '2.5rem', y: '2.5rem' } : { x: '2.5rem', y: '2.5rem' });
function scrollToTop() { function scrollToTop() {
if (!process.client) return; if (!import.meta.client) return;
window.scrollTo({ window.scrollTo({
top: 0, top: 0,
behavior: 'smooth', behavior: 'smooth',

View File

@ -1,7 +1,7 @@
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
export const getIOMeta = async (): Promise<Misskey.entities.LiteInstanceMetadata> => { export const getIOMeta = async (): Promise<Misskey.entities.LiteInstanceMetadata> => {
if (!process.client) { if (!import.meta.client) {
return {}; return {};
} }
if (!sessionStorage.getItem('miHub_io_meta')) { if (!sessionStorage.getItem('miHub_io_meta')) {
@ -17,7 +17,7 @@ export const getIOMeta = async (): Promise<Misskey.entities.LiteInstanceMetadata
} }
export const getIOEmoji = async (): Promise<{ emojis: Misskey.entities.CustomEmoji[] }> => { export const getIOEmoji = async (): Promise<{ emojis: Misskey.entities.CustomEmoji[] }> => {
if (!process.client) { if (!import.meta.client) {
return { emojis: [] }; return { emojis: [] };
} }
if (!localStorage.getItem('miHub_io_emoji')) { if (!localStorage.getItem('miHub_io_emoji')) {

View File

@ -16,7 +16,7 @@ export async function getGhIssueUrl(options: {
template = '01_visitor-bug-report-ja.yml'; template = '01_visitor-bug-report-ja.yml';
} }
if (process.client) { if (import.meta.client) {
//@ts-ignore //@ts-ignore
if ('userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData) { if ('userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData) {
//@ts-ignore //@ts-ignore

View File

@ -78,7 +78,7 @@ export const findDeepObject = (obj: NavItem, condition: (v: NavItem) => boolean)
* Clipboardに値をコピー(TODO: 文字列以外も対応) * Clipboardに値をコピー(TODO: 文字列以外も対応)
*/ */
export function copyText(val: string) { export function copyText(val: string) {
if (!process.client) return; if (!import.meta.client) return;
// 空div 生成 // 空div 生成
const tmp = document.createElement('div'); const tmp = document.createElement('div');

View File

@ -1,5 +1,5 @@
export function scrollTo(qs: string) { export function scrollTo(qs: string) {
if (process.client) { if (import.meta.client) {
document.querySelector(qs)?.scrollIntoView({ document.querySelector(qs)?.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
}); });

View File

@ -7,7 +7,7 @@
<script setup lang="ts"> <script setup lang="ts">
const isEnabledAiChanMode = ref<boolean>(false); const isEnabledAiChanMode = ref<boolean>(false);
if (process.client) { if (import.meta.client) {
isEnabledAiChanMode.value = ((localStorage.getItem('miHub_aichan_mode') ?? '') == 'true'); isEnabledAiChanMode.value = ((localStorage.getItem('miHub_aichan_mode') ?? '') == 'true');
// migration // migration

View File

@ -36,7 +36,7 @@ const emit = defineEmits(['move', 'child-click']);
const { activeHeadings, updateHeadings } = useScrollspy(); const { activeHeadings, updateHeadings } = useScrollspy();
if (process.client) { if (import.meta.client) {
setTimeout(() => { setTimeout(() => {
updateHeadings([ updateHeadings([
...document.querySelectorAll('.markdown-body h1'), ...document.querySelectorAll('.markdown-body h1'),
@ -48,7 +48,7 @@ if (process.client) {
} }
function scrollToHeading (id: string) { function scrollToHeading (id: string) {
if (process.client) { if (import.meta.client) {
if (!decodeURIComponent(location.href).includes(`#${id}`)) { if (!decodeURIComponent(location.href).includes(`#${id}`)) {
// history API // history API
history.pushState({}, '', `#${id}`); history.pushState({}, '', `#${id}`);

View File

@ -6,7 +6,7 @@
const live2d = ref<HTMLIFrameElement>(); const live2d = ref<HTMLIFrameElement>();
const isEnabledAiChanMode = ref<boolean>(false); const isEnabledAiChanMode = ref<boolean>(false);
if (process.client) { if (import.meta.client) {
isEnabledAiChanMode.value = ((localStorage.getItem('miHub_aichan_mode') ?? '') == 'true'); isEnabledAiChanMode.value = ((localStorage.getItem('miHub_aichan_mode') ?? '') == 'true');
// migration // migration

View File

@ -155,7 +155,7 @@ const displayInstances = computed(() => [
const userDefinedInstanceInput = ref<string>(''); const userDefinedInstanceInput = ref<string>('');
async function getAndSetInstanceInfo() { async function getAndSetInstanceInfo() {
if (!process.client || !userDefinedInstanceInput.value || !userDefinedInstanceInput.value.includes('.')) return; if (!import.meta.client || !userDefinedInstanceInput.value || !userDefinedInstanceInput.value.includes('.')) return;
iFetching.value = true; iFetching.value = true;
nextTick(async () => { nextTick(async () => {
@ -234,7 +234,7 @@ async function handleClick(instance: ExtendedInstanceItem) {
} }
onMounted(async () => { onMounted(async () => {
if (process.client) { if (import.meta.client) {
const fetchedInfo = await window.fetch('https://instanceapp.misskey.page/instances.json'); const fetchedInfo = await window.fetch('https://instanceapp.misskey.page/instances.json');
if (![200, 304].includes(fetchedInfo.status)) { if (![200, 304].includes(fetchedInfo.status)) {
alert(t('_servers._system.fetchError')); alert(t('_servers._system.fetchError'));
@ -293,7 +293,7 @@ onMounted(async () => {
}); });
watch(userDefinedInstances, (to) => { watch(userDefinedInstances, (to) => {
if (process.client) { if (import.meta.client) {
localStorage.setItem('miHub_share_instances', JSON.stringify(to)); localStorage.setItem('miHub_share_instances', JSON.stringify(to));
} }
}, { }, {

View File

@ -31,7 +31,7 @@ onMounted(() => {
let loader: Loader; let loader: Loader;
watch(container, (to) => { watch(container, (to) => {
if (isMounted.value && process.client && to) { if (isMounted.value && import.meta.client && to) {
loader = new Loader(to); loader = new Loader(to);
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {

View File

@ -68,7 +68,7 @@ function initShaderProgram(gl: WebGLRenderingContext, vsSource: string, fsSource
let handle: ReturnType<typeof window['requestAnimationFrame']> | null = null; let handle: ReturnType<typeof window['requestAnimationFrame']> | null = null;
onMounted(() => { onMounted(() => {
if (!process.client) return; if (!import.meta.client) return;
const canvas = canvasEl.value!; const canvas = canvasEl.value!;
let width = canvas.offsetWidth; let width = canvas.offsetWidth;

View File

@ -166,7 +166,7 @@ type MiHubSFStorage = {
}; };
let savedSettings: MiHubSFStorage | null = null; let savedSettings: MiHubSFStorage | null = null;
if (process.client) { if (import.meta.client) {
savedSettings = JSON.parse(window.localStorage.getItem('miHub_server_finder') ?? 'null') as MiHubSFStorage | null; savedSettings = JSON.parse(window.localStorage.getItem('miHub_server_finder') ?? 'null') as MiHubSFStorage | null;
} }
@ -195,7 +195,7 @@ watch([f_langs, f_orderBy, f_order, f_registerAcceptance, v_view], (to, from) =>
v_view: to[4], v_view: to[4],
}; };
if (process.client) { if (import.meta.client) {
window.localStorage.setItem('miHub_server_finder', JSON.stringify(newSettings)); window.localStorage.setItem('miHub_server_finder', JSON.stringify(newSettings));
} }
}); });

View File

@ -44,7 +44,7 @@ const filteredQuery = computed(() => ({
const isCanvasLoaded = ref(false); const isCanvasLoaded = ref(false);
const showAnimBg = ref(false); const showAnimBg = ref(false);
if (process.client && window.innerWidth >= 768) { if (import.meta.client && window.innerWidth >= 768) {
showAnimBg.value = true; showAnimBg.value = true;
} }

View File

@ -155,7 +155,7 @@ const realDecorations = computed(() => {
}); });
function addDecoration() { function addDecoration() {
if (!process.client) return; if (!import.meta.client) return;
function createImage(file: Blob, callback: () => void) { function createImage(file: Blob, callback: () => void) {
const reader = new FileReader(); const reader = new FileReader();

View File

@ -124,7 +124,7 @@ function getEmojiUrl(emoji: { id: number; file: string | Blob; }) {
} }
function addEmoji() { function addEmoji() {
if (!process.client) return; if (!import.meta.client) return;
const input = document.createElement('input'); const input = document.createElement('input');
input.type = 'file'; input.type = 'file';

View File

@ -47,7 +47,7 @@ const normalizedAcct = computed(() => {
const canvas = ref<HTMLCanvasElement | null>(null); const canvas = ref<HTMLCanvasElement | null>(null);
function genIdenticon() { function genIdenticon() {
if (!process.client || !canvas.value) return; if (!import.meta.client || !canvas.value) return;
if (!normalizedAcct.value) { if (!normalizedAcct.value) {
onceGenerated.value = false; onceGenerated.value = false;
const ctx = canvas.value.getContext('2d'); const ctx = canvas.value.getContext('2d');
@ -61,7 +61,7 @@ function genIdenticon() {
} }
function download() { function download() {
if (!process.client || !normalizedAcct.value || !canvas.value) return; if (!import.meta.client || !normalizedAcct.value || !canvas.value) return;
const url = canvas.value.toDataURL('image/png'); const url = canvas.value.toDataURL('image/png');
const a = document.createElement('a'); const a = document.createElement('a');
a.href = url; a.href = url;

View File

@ -67,7 +67,7 @@ const shareURL = computed(() => {
}) })
function clearEmojiCache() { function clearEmojiCache() {
if (process.client) { if (import.meta.client) {
localStorage.clear(); localStorage.clear();
location.reload(); location.reload();
} }