1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-12 13:48:33 +09:00
This commit is contained in:
kakkokari-gtyih 2024-06-25 21:08:58 +09:00
parent 3bd055b045
commit b5fe3e894b

View File

@ -197,6 +197,7 @@ function iframeOnLoad() {
});
});
}
function windowEventHandler(event: MessageEvent) {
if (event.source !== iframeEl.value?.contentWindow) {
return;
@ -217,6 +218,7 @@ function windowEventHandler(event: MessageEvent) {
});
}
}
function calcScale() {
if (!resizerRootEl.value) return;
const previewWidth = resizerRootEl.value.clientWidth - 40; // 20px
@ -225,15 +227,18 @@ function calcScale() {
const scale = Math.min(previewWidth / iframeWidth, previewHeight / iframeHeight.value, 1); //
iframeScale.value = scale;
}
onMounted(() => {
window.addEventListener('message', windowEventHandler);
if (!resizerRootEl.value) return;
resizeObserver.observe(resizerRootEl.value);
});
onDeactivated(() => {
window.removeEventListener('message', windowEventHandler);
resizeObserver.disconnect();
});
onUnmounted(() => {
window.removeEventListener('message', windowEventHandler);
resizeObserver.disconnect();