2024-09-09 13:57:36 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
ref="rootEl"
|
|
|
|
:class="[
|
|
|
|
$style.rootForEmbedPage,
|
|
|
|
{
|
|
|
|
[$style.rounded]: embedRounded,
|
|
|
|
[$style.noBorder]: embedNoBorder,
|
|
|
|
}
|
|
|
|
]"
|
|
|
|
:style="maxHeight > 0 ? { maxHeight: `${maxHeight}px`, '--embedMaxHeight': `${maxHeight}px` } : {}"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
:class="$style.routerViewContainer"
|
|
|
|
>
|
2024-09-23 12:49:52 +02:00
|
|
|
<Suspense :timeout="0">
|
|
|
|
<EmNotePage v-if="page === 'notes'" :noteId="contentId"/>
|
|
|
|
<EmUserTimelinePage v-else-if="page === 'user-timeline'" :userId="contentId"/>
|
|
|
|
<EmClipPage v-else-if="page === 'clips'" :clipId="contentId"/>
|
|
|
|
<EmTagPage v-else-if="page === 'tags'" :tag="contentId"/>
|
|
|
|
<XNotFound v-else/>
|
|
|
|
<template #fallback>
|
|
|
|
<EmLoading/>
|
|
|
|
</template>
|
|
|
|
</Suspense>
|
2024-09-09 13:57:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref, shallowRef, onMounted, onUnmounted, inject } from 'vue';
|
|
|
|
import { postMessageToParentWindow } from '@/post-message.js';
|
|
|
|
import { DI } from '@/di.js';
|
|
|
|
import { defaultEmbedParams } from '@@/js/embed-page.js';
|
|
|
|
import EmNotePage from '@/pages/note.vue';
|
|
|
|
import EmUserTimelinePage from '@/pages/user-timeline.vue';
|
|
|
|
import EmClipPage from '@/pages/clip.vue';
|
|
|
|
import EmTagPage from '@/pages/tag.vue';
|
|
|
|
import XNotFound from '@/pages/not-found.vue';
|
2024-09-23 12:49:52 +02:00
|
|
|
import EmLoading from '@/components/EmLoading.vue';
|
2024-09-09 13:57:36 +02:00
|
|
|
|
2024-09-25 09:12:34 +02:00
|
|
|
function safeURIDecode(str: string): string {
|
|
|
|
try {
|
|
|
|
return decodeURIComponent(str);
|
|
|
|
} catch {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-09 13:57:36 +02:00
|
|
|
const page = location.pathname.split('/')[2];
|
2024-09-25 09:12:34 +02:00
|
|
|
const contentId = safeURIDecode(location.pathname.split('/')[3]);
|
2024-09-10 09:14:02 +02:00
|
|
|
if (_DEV_) console.log(page, contentId);
|
2024-09-09 13:57:36 +02:00
|
|
|
|
|
|
|
const embedParams = inject(DI.embedParams, defaultEmbedParams);
|
|
|
|
|
|
|
|
//#region Embed Style
|
|
|
|
const embedRounded = ref(embedParams.rounded);
|
|
|
|
const embedNoBorder = ref(!embedParams.border);
|
|
|
|
const maxHeight = ref(embedParams.maxHeight ?? 0);
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region Embed Resizer
|
|
|
|
const rootEl = shallowRef<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
let previousHeight = 0;
|
|
|
|
const resizeObserver = new ResizeObserver(async () => {
|
|
|
|
const height = rootEl.value!.scrollHeight + (embedNoBorder.value ? 0 : 2); // border 上下1px
|
|
|
|
if (Math.abs(previousHeight - height) < 1) return; // 1px未満の変化は無視
|
|
|
|
postMessageToParentWindow('misskey:embed:changeHeight', {
|
|
|
|
height: (maxHeight.value > 0 && height > maxHeight.value) ? maxHeight.value : height,
|
|
|
|
});
|
|
|
|
previousHeight = height;
|
|
|
|
});
|
|
|
|
onMounted(() => {
|
|
|
|
resizeObserver.observe(rootEl.value!);
|
|
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
|
|
resizeObserver.disconnect();
|
|
|
|
});
|
|
|
|
//#endregion
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.rootForEmbedPage {
|
|
|
|
box-sizing: border-box;
|
|
|
|
border: 1px solid var(--divider);
|
|
|
|
background-color: var(--bg);
|
|
|
|
overflow: hidden;
|
|
|
|
position: relative;
|
|
|
|
height: auto;
|
|
|
|
|
|
|
|
&.rounded {
|
|
|
|
border-radius: var(--radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.noBorder {
|
|
|
|
border: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.routerViewContainer {
|
|
|
|
container-type: inline-size;
|
|
|
|
max-height: var(--embedMaxHeight, none);
|
|
|
|
}
|
|
|
|
</style>
|