svelte-remote-image 0.3.4-0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,40 +6,32 @@ export const alt = "";
|
|
|
6
6
|
export const title = "";
|
|
7
7
|
const imgId = `svelte-remote-image-${alt.replaceAll(" ", "-")}-${Math.round(Math.random() * 1e7)}`;
|
|
8
8
|
const getImgElement = () => browser ? document.getElementById(imgId) : null;
|
|
9
|
+
let visibilityStyle = "invisible";
|
|
9
10
|
let imgSrc;
|
|
10
11
|
$: {
|
|
11
12
|
imgSrc = src;
|
|
12
|
-
|
|
13
|
-
if (img) {
|
|
14
|
-
img.style.visibility = "hidden";
|
|
15
|
-
}
|
|
13
|
+
visibilityStyle = "invisible";
|
|
16
14
|
}
|
|
17
15
|
afterUpdate(async () => {
|
|
18
16
|
const img = getImgElement();
|
|
19
|
-
if (!img) {
|
|
17
|
+
if (!img || !img.complete) {
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
20
|
if (img.naturalWidth !== 0 && img.naturalHeight !== 0) {
|
|
23
|
-
|
|
21
|
+
visibilityStyle = "visible";
|
|
24
22
|
} else {
|
|
25
23
|
handleImgError();
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
|
-
const handleImgError = (
|
|
29
|
-
if (e && e.type !== "error") {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
26
|
+
const handleImgError = () => {
|
|
32
27
|
if (!imgSrc.fallback) {
|
|
33
28
|
return;
|
|
34
29
|
}
|
|
30
|
+
visibilityStyle = "invisible";
|
|
35
31
|
const img = getImgElement();
|
|
36
32
|
if (!img) {
|
|
37
33
|
return;
|
|
38
34
|
}
|
|
39
|
-
img.style.visibility = "hidden";
|
|
40
|
-
if (!img.complete) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
35
|
let fallbackUrl = void 0;
|
|
44
36
|
const index = imgSrc.fallback.findIndex(
|
|
45
37
|
(url) => new URL(url).toString() === new URL(img.src).toString()
|
|
@@ -58,9 +50,8 @@ const handleImgError = (e) => {
|
|
|
58
50
|
srcsets: void 0
|
|
59
51
|
};
|
|
60
52
|
};
|
|
61
|
-
const handleLoaded = (
|
|
62
|
-
|
|
63
|
-
img.style.visibility = "visible";
|
|
53
|
+
const handleLoaded = () => {
|
|
54
|
+
visibilityStyle = "visible";
|
|
64
55
|
};
|
|
65
56
|
</script>
|
|
66
57
|
|
|
@@ -69,6 +60,7 @@ const handleLoaded = (e) => {
|
|
|
69
60
|
width={imgSrc.w}
|
|
70
61
|
height={imgSrc.h}
|
|
71
62
|
{style}
|
|
63
|
+
class={visibilityStyle}
|
|
72
64
|
src={imgSrc.img}
|
|
73
65
|
srcset={imgSrc.srcsets ? imgSrc.srcsets.map((s) => `${s.src} ${s.w}w`).join(', ') : ''}
|
|
74
66
|
alt={alt}
|
|
@@ -79,7 +71,10 @@ const handleLoaded = (e) => {
|
|
|
79
71
|
/>
|
|
80
72
|
|
|
81
73
|
<style>
|
|
82
|
-
|
|
74
|
+
.visible {
|
|
75
|
+
visibility: visible;
|
|
76
|
+
}
|
|
77
|
+
.invisible {
|
|
83
78
|
visibility: hidden;
|
|
84
79
|
}
|
|
85
80
|
</style>
|
|
@@ -24,7 +24,7 @@ $: {
|
|
|
24
24
|
}
|
|
25
25
|
afterUpdate(async () => {
|
|
26
26
|
const img = getImgElement();
|
|
27
|
-
if (!img) {
|
|
27
|
+
if (!img || !img.complete) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (img.naturalWidth !== 0 && img.naturalHeight !== 0) {
|
|
@@ -34,10 +34,7 @@ afterUpdate(async () => {
|
|
|
34
34
|
handleImgError();
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const handleImgError = (
|
|
38
|
-
if (e && e.type !== "error") {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
37
|
+
const handleImgError = () => {
|
|
41
38
|
if (!src.fallback) {
|
|
42
39
|
return;
|
|
43
40
|
}
|
|
@@ -46,9 +43,6 @@ const handleImgError = (e) => {
|
|
|
46
43
|
return;
|
|
47
44
|
}
|
|
48
45
|
img.style.visibility = "hidden";
|
|
49
|
-
if (!img.complete) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
46
|
let fallbackUrl = void 0;
|
|
53
47
|
const index = src.fallback.findIndex(
|
|
54
48
|
(url) => new URL(url).toString() === new URL(img.src).toString()
|