Formatting

This commit is contained in:
ThatOneCalculator 2023-02-11 17:14:50 -08:00
parent 474a02bfe0
commit b02f62dba4
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
2 changed files with 331 additions and 330 deletions

2
.gitignore vendored
View File

@ -42,6 +42,8 @@ api-docs.json
files files
ormconfig.json ormconfig.json
packages/backend/assets/instance.css packages/backend/assets/instance.css
packages/backend/assets/sounds/None.mp3
# blender backups # blender backups
*.blend1 *.blend1

View File

@ -33,281 +33,223 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref, inject, watch, shallowReactive, nextTick, reactive } from 'vue'; import { computed, onMounted, onUnmounted, ref, inject, watch, shallowReactive, nextTick, reactive } from 'vue';
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
import { popupMenu } from '@/os'; import { popupMenu } from '@/os';
import { scrollToTop } from '@/scripts/scroll'; import { scrollToTop } from '@/scripts/scroll';
import { i18n } from '@/i18n'; import { globalEvents } from '@/events';
import { globalEvents } from '@/events'; import { deviceKind } from '@/scripts/device-kind';
import { deviceKind } from '@/scripts/device-kind'; import { isTouchUsing } from '@/scripts/touch';
import { isTouchUsing } from '@/scripts/touch'; import { injectPageMetadata } from '@/scripts/page-metadata';
import { injectPageMetadata } from '@/scripts/page-metadata'; import { $i, openAccountMenu as openAccountMenu_ } from '@/account';
import { $i, openAccountMenu as openAccountMenu_ } from '@/account';
type Tab = { type Tab = {
key?: string | null; key?: string | null;
title: string; title: string;
icon?: string; icon?: string;
iconOnly?: boolean; iconOnly?: boolean;
onClick?: (ev: MouseEvent) => void; onClick?: (ev: MouseEvent) => void;
}; };
const props = defineProps<{ const props = defineProps<{
tabs?: Tab[]; tabs?: Tab[];
tab?: string; tab?: string;
actions?: { actions?: {
text: string; text: string;
icon: string; icon: string;
handler: (ev: MouseEvent) => void; handler: (ev: MouseEvent) => void;
}[]; }[];
thin?: boolean; thin?: boolean;
displayMyAvatar?: boolean; displayMyAvatar?: boolean;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(ev: 'update:tab', key: string); (ev: 'update:tab', key: string);
}>(); }>();
const metadata = injectPageMetadata(); const metadata = injectPageMetadata();
const hideTitle = inject('shouldOmitHeaderTitle', false); const hideTitle = inject('shouldOmitHeaderTitle', false);
const thin_ = props.thin || inject('shouldHeaderThin', false); const thin_ = props.thin || inject('shouldHeaderThin', false);
const el = $ref<HTMLElement | null>(null); const el = $ref<HTMLElement | null>(null);
const tabRefs = {}; const tabRefs = {};
const tabHighlightEl = $ref<HTMLElement | null>(null); const tabHighlightEl = $ref<HTMLElement | null>(null);
const tabsEl = $ref<HTMLElement | null>(null); const tabsEl = $ref<HTMLElement | null>(null);
const bg = ref(null); const bg = ref(null);
let narrow = $ref(false); let narrow = $ref(false);
const height = ref(0); const height = ref(0);
const hasTabs = $computed(() => props.tabs && props.tabs.length > 0); const hasTabs = $computed(() => props.tabs && props.tabs.length > 0);
const hasActions = $computed(() => props.actions && props.actions.length > 0); const hasActions = $computed(() => props.actions && props.actions.length > 0);
const show = $computed(() => { const show = $computed(() => {
return !hideTitle || hasTabs || hasActions; return !hideTitle || hasTabs || hasActions;
}); });
const openAccountMenu = (ev: MouseEvent) => { const openAccountMenu = (ev: MouseEvent) => {
openAccountMenu_({ openAccountMenu_({
withExtraOperation: true, withExtraOperation: true,
}, ev); }, ev);
}; };
const showTabsPopup = (ev: MouseEvent) => { const showTabsPopup = (ev: MouseEvent) => {
if (!hasTabs) return; if (!hasTabs) return;
if (!narrow) return; if (!narrow) return;
ev.preventDefault();
ev.stopPropagation();
const menu = props.tabs.map(tab => ({
text: tab.title,
icon: tab.icon,
active: tab.key != null && tab.key === props.tab,
action: (ev) => {
onTabClick(tab, ev);
},
}));
popupMenu(menu, ev.currentTarget ?? ev.target);
};
const preventDrag = (ev: TouchEvent) => {
ev.stopPropagation();
};
const onClick = () => {
scrollToTop(el, { behavior: 'smooth' });
};
function onTabMousedown(tab: Tab, ev: MouseEvent): void {
// mousedownonClick
if (tab.key) {
emit('update:tab', tab.key);
}
}
function onTabClick(tab: Tab, ev: MouseEvent): void {
if (tab.onClick) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
const menu = props.tabs.map(tab => ({ tab.onClick(ev);
text: tab.title,
icon: tab.icon,
active: tab.key != null && tab.key === props.tab,
action: (ev) => {
onTabClick(tab, ev);
},
}));
popupMenu(menu, ev.currentTarget ?? ev.target);
};
const preventDrag = (ev: TouchEvent) => {
ev.stopPropagation();
};
const onClick = () => {
scrollToTop(el, { behavior: 'smooth' });
};
function onTabMousedown(tab: Tab, ev: MouseEvent): void {
// mousedownonClick
if (tab.key) {
emit('update:tab', tab.key);
}
} }
if (tab.key) {
function onTabClick(tab: Tab, ev: MouseEvent): void { emit('update:tab', tab.key);
if (tab.onClick) {
ev.preventDefault();
ev.stopPropagation();
tab.onClick(ev);
}
if (tab.key) {
emit('update:tab', tab.key);
}
} }
}
const calcBg = () => { const calcBg = () => {
const rawBg = metadata?.bg || 'var(--bg)'; const rawBg = metadata?.bg || 'var(--bg)';
const tinyBg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg); const tinyBg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
tinyBg.setAlpha(0.85); tinyBg.setAlpha(0.85);
bg.value = tinyBg.toRgbString(); bg.value = tinyBg.toRgbString();
}; };
let ro: ResizeObserver | null; let ro: ResizeObserver | null;
onMounted(() => { onMounted(() => {
calcBg(); calcBg();
globalEvents.on('themeChanged', calcBg); globalEvents.on('themeChanged', calcBg);
watch(() => [props.tab, props.tabs], () => { watch(() => [props.tab, props.tabs], () => {
nextTick(() => { nextTick(() => {
const tabEl = tabRefs[props.tab]; const tabEl = tabRefs[props.tab];
if (tabEl && tabHighlightEl) { if (tabEl && tabHighlightEl) {
// offsetWidth offsetLeft getBoundingClientRect 使 // offsetWidth offsetLeft getBoundingClientRect 使
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4 // https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
tabEl.addEventListener("transitionend", () => { tabEl.addEventListener("transitionend", () => {
const parentRect = tabsEl.getBoundingClientRect(); const parentRect = tabsEl.getBoundingClientRect();
const rect = tabEl.getBoundingClientRect(); const rect = tabEl.getBoundingClientRect();
const left = (rect.left - parentRect.left + tabsEl?.scrollLeft); const left = (rect.left - parentRect.left + tabsEl?.scrollLeft);
tabHighlightEl.style.width = rect.width + 'px'; tabHighlightEl.style.width = rect.width + 'px';
tabHighlightEl.style.left = left + 'px'; tabHighlightEl.style.left = left + 'px';
tabsEl?.scrollTo({left: left - 80, behavior: "smooth"}); tabsEl?.scrollTo({left: left - 80, behavior: "smooth"});
}) })
} }
});
}, {
immediate: true,
}); });
}, {
if (el && el.parentElement) { immediate: true,
narrow = el.parentElement.offsetWidth < 500;
ro = new ResizeObserver((entries, observer) => {
if (el.parentElement && document.body.contains(el)) {
narrow = el.parentElement.offsetWidth < 500;
}
});
ro.observe(el.parentElement);
}
}); });
onUnmounted(() => { if (el && el.parentElement) {
globalEvents.off('themeChanged', calcBg); narrow = el.parentElement.offsetWidth < 500;
if (ro) ro.disconnect(); ro = new ResizeObserver((entries, observer) => {
}); if (el.parentElement && document.body.contains(el)) {
narrow = el.parentElement.offsetWidth < 500;
}
});
ro.observe(el.parentElement);
}
});
onUnmounted(() => {
globalEvents.off('themeChanged', calcBg);
if (ro) ro.disconnect();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.fdidabkb { .fdidabkb {
--height: 55px; --height: 55px;
display: flex; display: flex;
width: 100%; width: 100%;
-webkit-backdrop-filter: var(--blur, blur(15px)); -webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px)); backdrop-filter: var(--blur, blur(15px));
border-bottom: solid 0.5px var(--divider); border-bottom: solid 0.5px var(--divider);
contain: strict; contain: strict;
height: var(--height); height: var(--height);
&.thin { &.thin {
--height: 45px; --height: 45px;
> .buttons {
> .button {
font-size: 0.9em;
}
}
}
&.slim {
> .titleContainer {
flex: 1;
margin: 0 auto;
> *:first-child {
margin-left: auto;
}
> *:last-child {
margin-right: auto;
}
}
> .tabs {
padding-inline: 12px;
mask: linear-gradient(to right, black 80%, transparent);
-webkit-mask: linear-gradient(to right, black 80%, transparent);
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
&::after { // Force right padding
content: "";
display: inline-block;
min-width: 20%;
}
> .tab {
&:not(.active) > .title {
font-size: 0;
opacity: 0;
margin-inline: 0;
transition: font-size .2s, opacity .1s;
}
}
}
}
> .buttons { > .buttons {
--margin: 8px; > .button {
display: flex; font-size: 0.9em;
align-items: center;
height: var(--height);
margin: 0 var(--margin);
&.left {
margin-right: auto;
> .avatar {
$size: 32px;
display: inline-block;
width: $size;
height: $size;
vertical-align: bottom;
margin: 0 8px;
pointer-events: none;
}
} }
}
}
&.right { &.slim {
> .titleContainer {
flex: 1;
margin: 0 auto;
> *:first-child {
margin-left: auto; margin-left: auto;
} }
&:empty { > *:last-child {
margin-right: auto;
}
}
> .tabs {
padding-inline: 12px;
mask: linear-gradient(to right, black 80%, transparent);
-webkit-mask: linear-gradient(to right, black 80%, transparent);
scrollbar-width: none;
&::-webkit-scrollbar {
display: none; display: none;
} }
&::after { // Force right padding
> .button { content: "";
display: flex; display: inline-block;
align-items: center; min-width: 20%;
justify-content: center;
height: calc(var(--height) - (var(--margin) * 2));
width: calc(var(--height) - (var(--margin) * 2));
box-sizing: border-box;
position: relative;
border-radius: 5px;
&:hover {
background: rgba(0, 0, 0, 0.05);
}
&.highlighted {
color: var(--accent);
}
} }
> .tab {
> .fullButton { &:not(.active) > .title {
& + .fullButton { font-size: 0;
margin-left: 12px; opacity: 0;
margin-inline: 0;
transition: font-size .2s, opacity .1s;
} }
} }
} }
}
> .titleContainer { > .buttons {
display: flex; --margin: 8px;
align-items: center; display: flex;
max-width: 400px; align-items: center;
overflow: auto; height: var(--height);
white-space: nowrap; margin: 0 var(--margin);
text-align: left;
font-weight: bold; &.left {
flex-shrink: 0; margin-right: auto;
margin-left: 24px;
margin-right: 1rem;
> .avatar { > .avatar {
$size: 32px; $size: 32px;
@ -318,86 +260,143 @@
margin: 0 8px; margin: 0 8px;
pointer-events: none; pointer-events: none;
} }
}
> .icon { &.right {
margin-right: 8px; margin-left: auto;
width: 16px; }
text-align: center;
transform: translate(0em); &:empty {
display: none;
}
> .button {
display: flex;
align-items: center;
justify-content: center;
height: calc(var(--height) - (var(--margin) * 2));
width: calc(var(--height) - (var(--margin) * 2));
box-sizing: border-box;
position: relative;
border-radius: 5px;
&:hover {
background: rgba(0, 0, 0, 0.05);
} }
> .title { &.highlighted {
min-width: 0; color: var(--accent);
}
}
> .fullButton {
& + .fullButton {
margin-left: 12px;
}
}
}
> .titleContainer {
display: flex;
align-items: center;
max-width: 400px;
overflow: auto;
white-space: nowrap;
text-align: left;
font-weight: bold;
flex-shrink: 0;
margin-left: 24px;
margin-right: 1rem;
> .avatar {
$size: 32px;
display: inline-block;
width: $size;
height: $size;
vertical-align: bottom;
margin: 0 8px;
pointer-events: none;
}
> .icon {
margin-right: 8px;
width: 16px;
text-align: center;
transform: translate(0em);
}
> .title {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
line-height: 1.1;
> .subtitle {
opacity: 0.6;
font-size: 0.8em;
font-weight: normal;
white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap;
line-height: 1.1;
> .subtitle { &.activeTab {
opacity: 0.6; text-align: center;
font-size: 0.8em;
font-weight: normal;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.activeTab { > .chevron {
text-align: center; display: inline-block;
margin-left: 6px;
> .chevron {
display: inline-block;
margin-left: 6px;
}
} }
} }
} }
} }
}
> .tabs { > .tabs {
position: relative;
width: 100%;
font-size: 1em;
overflow-x: auto;
white-space: nowrap;
> .tab {
display: inline-flex;
align-items: center;
position: relative; position: relative;
width: 100%; padding: 0 10px;
font-size: 1em; height: 100%;
overflow-x: auto; font-weight: normal;
white-space: nowrap; opacity: 0.7;
transition: color .2s, opacity .2s;
> .tab { &:hover {
display: inline-flex; opacity: 1;
align-items: center;
position: relative;
padding: 0 10px;
height: 100%;
font-weight: normal;
opacity: 0.7;
transition: color .2s, opacity .2s;
&:hover {
opacity: 1;
}
&.active {
opacity: 1;
color: var(--accent);
font-weight: 600;
}
> .icon + .title {
margin-left: 8px;
}
> .title {
transition: font-size .2s, opacity .2s .15s;
}
} }
> .highlight { &.active {
position: absolute; opacity: 1;
bottom: 0; color: var(--accent);
height: 3px; font-weight: 600;
background: var(--accent); }
border-radius: 999px;
transition: width .2s, left .2s; > .icon + .title {
transition-timing-function: cubic-bezier(0,0,0,1.2); margin-left: 8px;
pointer-events: none; }
> .title {
transition: font-size .2s, opacity .2s .15s;
} }
} }
> .highlight {
position: absolute;
bottom: 0;
height: 3px;
background: var(--accent);
border-radius: 999px;
transition: width .2s, left .2s;
transition-timing-function: cubic-bezier(0,0,0,1.2);
pointer-events: none;
}
} }
}
</style> </style>