Revert "fetch image??"

This reverts commit 0925c28d5a.
This commit is contained in:
tamaina 2023-05-06 16:30:51 +00:00
parent 0925c28d5a
commit b19e4d290c
1 changed files with 9 additions and 18 deletions

View File

@ -1,5 +1,6 @@
<template>
<div :class="[$style.root, { [$style.cover]: cover }]" :title="title ?? ''">
<img v-if="!loaded && src" :class="$style.loader" :src="src" @load="onLoad"/>
<Transition
mode="in-out"
:enter-active-class="defaultStore.state.animation && (props.transition?.enterActiveClass ?? $style['transition_toggle_enterActive']) || undefined"
@ -9,8 +10,8 @@
:enter-to-class="defaultStore.state.animation && (props.transition?.enterToClass ?? $style['transition_toggle_enterTo']) || undefined"
:leave-from-class="defaultStore.state.animation && (props.transition?.leaveFromClass ?? $style['transition_toggle_leaveFrom']) || undefined"
>
<canvas v-if="!url || forceBlurhash" ref="canvas" :class="$style.canvas" :width="canvasWidth" :height="canvasHeight" :title="title ?? undefined"/>
<img v-else :class="$style.img" :width="props.width" :height="props.height" :src="url" :title="title ?? undefined" :alt="alt ?? undefined" loading="eager"/>
<canvas v-if="!loaded || forceBlurhash" ref="canvas" :class="$style.canvas" :width="canvasWidth" :height="canvasHeight" :title="title ?? undefined"/>
<img v-else :class="$style.img" :width="props.width" :height="props.height" :src="src ?? undefined" :title="title ?? undefined" :alt="alt ?? undefined"/>
</Transition>
</div>
</template>
@ -61,9 +62,13 @@ const offscreen = computed(() => {
}, [_offscreen]);
return _offscreen;
});
let loaded = $ref(false);
let canvasWidth = $ref(props.width);
let canvasHeight = $ref(props.height);
let url = $ref<string>();
function onLoad() {
loaded = true;
}
watch([() => props.width, () => props.height], () => {
const ratio = props.width / props.height;
@ -78,20 +83,6 @@ watch([() => props.width, () => props.height], () => {
immediate: true,
});
watch([() => props.src], () => {
if (url) {
URL.revokeObjectURL(url);
url = undefined;
}
if (props.src) {
fetch(props.src, { mode: 'no-cors' })
.then((res) => res.blob())
.then((blob) => {
url = URL.createObjectURL(blob);
});
}
}, { immediate: true });
function draw() {
if (props.hash == null || !offscreen.value) return;
worker.postMessage({
@ -112,7 +103,7 @@ onMounted(() => {
} else {
// 100msblurhash
setTimeout(() => {
if (!url) {
if (!loaded) {
draw();
}
}, 100);