2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
2024-02-12 02:37:45 +00:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-06-03 04:30:17 +00:00
|
|
|
<template>
|
2023-01-10 05:20:58 +00:00
|
|
|
<Transition
|
2023-05-19 04:58:09 +00:00
|
|
|
:enterActiveClass="defaultStore.state.animation ? $style.transition_tooltip_enterActive : ''"
|
|
|
|
:leaveActiveClass="defaultStore.state.animation ? $style.transition_tooltip_leaveActive : ''"
|
|
|
|
:enterFromClass="defaultStore.state.animation ? $style.transition_tooltip_enterFrom : ''"
|
|
|
|
:leaveToClass="defaultStore.state.animation ? $style.transition_tooltip_leaveTo : ''"
|
|
|
|
appear @afterLeave="emit('closed')"
|
2023-01-10 05:20:58 +00:00
|
|
|
>
|
|
|
|
<div v-show="showing" ref="el" :class="$style.root" class="_acrylic _shadow" :style="{ zIndex, maxWidth: maxWidth + 'px' }">
|
2022-06-16 07:05:43 +00:00
|
|
|
<slot>
|
2024-01-05 06:25:26 +00:00
|
|
|
<template v-if="text">
|
|
|
|
<Mfm v-if="asMfm" :text="text"/>
|
|
|
|
<span v-else>{{ text }}</span>
|
|
|
|
</template>
|
2022-06-16 07:05:43 +00:00
|
|
|
</slot>
|
2020-06-03 04:30:17 +00:00
|
|
|
</div>
|
2022-12-30 04:37:14 +00:00
|
|
|
</Transition>
|
2020-06-03 04:30:17 +00:00
|
|
|
</template>
|
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { nextTick, onMounted, onUnmounted, shallowRef } from 'vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { calcPopupPosition } from '@/scripts/popup-position.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2020-06-03 04:30:17 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
showing: boolean;
|
2022-01-31 12:07:33 +00:00
|
|
|
targetElement?: HTMLElement;
|
|
|
|
x?: number;
|
|
|
|
y?: number;
|
2024-01-05 06:25:26 +00:00
|
|
|
text?: string;
|
2022-06-16 07:05:43 +00:00
|
|
|
asMfm?: boolean;
|
2022-01-31 12:07:33 +00:00
|
|
|
maxWidth?: number;
|
2022-02-08 06:37:31 +00:00
|
|
|
direction?: 'top' | 'bottom' | 'right' | 'left';
|
|
|
|
innerMargin?: number;
|
2022-01-28 18:03:23 +00:00
|
|
|
}>(), {
|
|
|
|
maxWidth: 250,
|
2022-02-08 06:37:31 +00:00
|
|
|
direction: 'top',
|
|
|
|
innerMargin: 0,
|
2022-01-28 18:03:23 +00:00
|
|
|
});
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
}>();
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2023-05-15 05:29:35 +00:00
|
|
|
// タイミングによっては最初から showing = false な場合があり、その場合に closed 扱いにしないと永久にDOMに残ることになる
|
|
|
|
if (!props.showing) emit('closed');
|
|
|
|
|
2023-01-03 01:12:37 +00:00
|
|
|
const el = shallowRef<HTMLElement>();
|
2022-01-28 18:03:23 +00:00
|
|
|
const zIndex = os.claimZIndex('high');
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-07-17 12:06:33 +00:00
|
|
|
function setPosition() {
|
2024-01-30 10:53:53 +00:00
|
|
|
if (el.value == null) return;
|
2022-07-17 12:06:33 +00:00
|
|
|
const data = calcPopupPosition(el.value, {
|
|
|
|
anchorElement: props.targetElement,
|
|
|
|
direction: props.direction,
|
|
|
|
align: 'center',
|
|
|
|
innerMargin: props.innerMargin,
|
|
|
|
x: props.x,
|
|
|
|
y: props.y,
|
|
|
|
});
|
2022-01-28 18:03:23 +00:00
|
|
|
|
2022-07-17 12:06:33 +00:00
|
|
|
el.value.style.transformOrigin = data.transformOrigin;
|
|
|
|
el.value.style.left = data.left + 'px';
|
|
|
|
el.value.style.top = data.top + 'px';
|
|
|
|
}
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-02-12 08:29:15 +00:00
|
|
|
let loopHandler;
|
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
setPosition();
|
|
|
|
|
|
|
|
const loop = () => {
|
2023-05-15 04:57:36 +00:00
|
|
|
setPosition();
|
|
|
|
loopHandler = window.requestAnimationFrame(loop);
|
2021-11-28 11:07:37 +00:00
|
|
|
};
|
2022-01-28 18:03:23 +00:00
|
|
|
|
|
|
|
loop();
|
|
|
|
});
|
|
|
|
});
|
2022-02-12 08:29:15 +00:00
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.cancelAnimationFrame(loopHandler);
|
|
|
|
});
|
2020-06-03 04:30:17 +00:00
|
|
|
</script>
|
|
|
|
|
2023-01-10 05:20:58 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.transition_tooltip_enterActive,
|
|
|
|
.transition_tooltip_leaveActive {
|
2021-02-16 13:17:13 +00:00
|
|
|
opacity: 1;
|
|
|
|
transform: scale(1);
|
|
|
|
transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1), opacity 200ms cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
2023-01-10 05:20:58 +00:00
|
|
|
.transition_tooltip_enterFrom,
|
|
|
|
.transition_tooltip_leaveTo {
|
2021-02-16 13:17:13 +00:00
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.75);
|
|
|
|
}
|
|
|
|
|
2023-01-10 05:20:58 +00:00
|
|
|
.root {
|
2020-06-03 04:30:17 +00:00
|
|
|
position: absolute;
|
|
|
|
font-size: 0.8em;
|
2020-10-17 11:12:00 +00:00
|
|
|
padding: 8px 12px;
|
2021-10-24 05:39:24 +00:00
|
|
|
box-sizing: border-box;
|
2020-06-03 04:30:17 +00:00
|
|
|
text-align: center;
|
|
|
|
border-radius: 4px;
|
2021-10-24 05:39:24 +00:00
|
|
|
border: solid 0.5px var(--divider);
|
2020-06-03 04:30:17 +00:00
|
|
|
pointer-events: none;
|
2022-01-31 12:07:33 +00:00
|
|
|
transform-origin: center center;
|
2020-06-03 04:30:17 +00:00
|
|
|
}
|
|
|
|
</style>
|