svelte-remote-image 0.0.2 → 0.1.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.
@@ -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
- style = src.placeholder.dataUri ? `${style} background: url(${src.placeholder.dataUri}) no-repeat center/cover;` : style;
8
- imageWrapperStyle = src.placeholder.color ? `background-color: ${src.placeholder.color}` : "";
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") {
@@ -24,30 +27,28 @@ const handleLoaded = () => {
24
27
  };
25
28
  </script>
26
29
 
27
- <div class="picture-wrapper" style={imageWrapperStyle}>
28
- <picture>
29
- {#if src.webp}
30
- <source srcset={src.webp.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/webp" />
31
- {/if}
32
- {#if src.jpeg}
33
- <source srcset={src.jpeg.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/jpeg" />
34
- {/if}
35
- {#if src.png}
36
- <source srcset={src.png.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/png" />
37
- {/if}
38
- <img
39
- width={src.w}
40
- height={src.h}
41
- {style}
42
- class={src.blur ? `image-blur-${loadStatus}` : ''}
43
- src={src.img}
44
- alt={src.alt}
45
- on:error={handleImgError}
46
- on:load={handleLoaded}
47
- loading="lazy"
48
- />
49
- </picture>
50
- </div>
30
+ <picture>
31
+ {#if src.webp}
32
+ <source srcset={src.webp.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/webp" />
33
+ {/if}
34
+ {#if src.jpeg}
35
+ <source srcset={src.jpeg.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/jpeg" />
36
+ {/if}
37
+ {#if src.png}
38
+ <source srcset={src.png.map((s) => `${s.src} ${s.w}w`).join(', ')} type="image/png" />
39
+ {/if}
40
+ <img
41
+ width={src.w}
42
+ height={src.h}
43
+ {style}
44
+ class={src.blur ? `image-blur-${loadStatus}` : ''}
45
+ src={src.img}
46
+ alt={src.alt}
47
+ on:error={handleImgError}
48
+ on:load={handleLoaded}
49
+ loading="lazy"
50
+ />
51
+ </picture>
51
52
 
52
53
  <style>
53
54
  .image-blur-loading {
@@ -81,11 +82,6 @@ const handleLoaded = () => {
81
82
  }
82
83
  }
83
84
 
84
- .picture-wrapper {
85
- width: fit-content;
86
- height: fit-content;
87
- }
88
-
89
85
  img {
90
86
  display: block;
91
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-remote-image",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",