svelte-remote-image 0.0.2 → 0.1.1
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.
- package/dist/components/Image.svelte +35 -35
- package/package.json +1 -1
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
src = { ...src, blur: src.blur === void 0 ? true : src.blur };
|
|
3
3
|
export let style = "";
|
|
4
4
|
let loadStatus = "loading";
|
|
5
|
-
let imageWrapperStyle = "";
|
|
6
5
|
if (src.placeholder) {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (src.placeholder.dataUri) {
|
|
7
|
+
style = `${style} background: url(${src.placeholder.dataUri}) no-repeat center/cover;`;
|
|
8
|
+
}
|
|
9
|
+
if (src.placeholder.color) {
|
|
10
|
+
style = `${style} background-color: ${src.placeholder.color};`;
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
13
|
const handleImgError = (e) => {
|
|
11
14
|
if (e.type !== "error") {
|
|
@@ -16,7 +19,11 @@ const handleImgError = (e) => {
|
|
|
16
19
|
img: src.failback,
|
|
17
20
|
webp: [],
|
|
18
21
|
jpeg: [],
|
|
19
|
-
png: []
|
|
22
|
+
png: [],
|
|
23
|
+
placeholder: {
|
|
24
|
+
color: src.placeholder?.color,
|
|
25
|
+
dataUri: src.placeholder?.dataUri
|
|
26
|
+
}
|
|
20
27
|
};
|
|
21
28
|
};
|
|
22
29
|
const handleLoaded = () => {
|
|
@@ -24,30 +31,28 @@ const handleLoaded = () => {
|
|
|
24
31
|
};
|
|
25
32
|
</script>
|
|
26
33
|
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</picture>
|
|
50
|
-
</div>
|
|
34
|
+
<picture>
|
|
35
|
+
{#if src.webp}
|
|
36
|
+
<source srcset={src.webp.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/webp" />
|
|
37
|
+
{/if}
|
|
38
|
+
{#if src.jpeg}
|
|
39
|
+
<source srcset={src.jpeg.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/jpeg" />
|
|
40
|
+
{/if}
|
|
41
|
+
{#if src.png}
|
|
42
|
+
<source srcset={src.png.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/png" />
|
|
43
|
+
{/if}
|
|
44
|
+
<img
|
|
45
|
+
width={src.w}
|
|
46
|
+
height={src.h}
|
|
47
|
+
{style}
|
|
48
|
+
class={src.blur ? `image-blur-${loadStatus}` : ''}
|
|
49
|
+
src={src.img}
|
|
50
|
+
alt={src.alt}
|
|
51
|
+
on:error={handleImgError}
|
|
52
|
+
on:load={handleLoaded}
|
|
53
|
+
loading="lazy"
|
|
54
|
+
/>
|
|
55
|
+
</picture>
|
|
51
56
|
|
|
52
57
|
<style>
|
|
53
58
|
.image-blur-loading {
|
|
@@ -72,20 +77,15 @@ const handleLoaded = () => {
|
|
|
72
77
|
|
|
73
78
|
@keyframes show {
|
|
74
79
|
from {
|
|
75
|
-
filter: blur(
|
|
80
|
+
filter: blur(10px);
|
|
76
81
|
opacity: 0.5;
|
|
77
82
|
}
|
|
78
83
|
to {
|
|
79
|
-
filter: blur(
|
|
84
|
+
filter: blur(5px);
|
|
80
85
|
opacity: 1;
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
.picture-wrapper {
|
|
85
|
-
width: fit-content;
|
|
86
|
-
height: fit-content;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
89
|
img {
|
|
90
90
|
display: block;
|
|
91
91
|
}
|