svelte-remote-image 0.3.1 → 0.3.2

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,6 +6,7 @@ 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
+ $: imgSrc = src;
9
10
  afterUpdate(async () => {
10
11
  const img = getImgElement();
11
12
  if (!img) {
@@ -21,7 +22,7 @@ const handleImgError = (e) => {
21
22
  if (e && e.type !== "error") {
22
23
  return;
23
24
  }
24
- if (!src.fallback) {
25
+ if (!imgSrc.fallback) {
25
26
  return;
26
27
  }
27
28
  const img = getImgElement();
@@ -30,21 +31,21 @@ const handleImgError = (e) => {
30
31
  }
31
32
  img.style.visibility = "hidden";
32
33
  let fallbackUrl = void 0;
33
- const index = src.fallback.findIndex(
34
+ const index = imgSrc.fallback.findIndex(
34
35
  (url) => new URL(url).toString() === new URL(img.src).toString()
35
36
  );
36
37
  if (index === -1) {
37
- fallbackUrl = src.fallback[0];
38
+ fallbackUrl = imgSrc.fallback[0];
38
39
  } else {
39
- fallbackUrl = src.fallback[index + 1];
40
+ fallbackUrl = imgSrc.fallback[index + 1];
40
41
  }
41
42
  if (!fallbackUrl) {
42
43
  return;
43
44
  }
44
- src = {
45
- ...src,
45
+ imgSrc = {
46
+ ...imgSrc,
46
47
  img: fallbackUrl,
47
- srcsets: []
48
+ srcsets: void 0
48
49
  };
49
50
  };
50
51
  const handleLoaded = (e) => {
@@ -55,11 +56,11 @@ const handleLoaded = (e) => {
55
56
 
56
57
  <img
57
58
  id={imgId}
58
- width={src.w}
59
- height={src.h}
59
+ width={imgSrc.w}
60
+ height={imgSrc.h}
60
61
  {style}
61
- src={src.img}
62
- srcset={src.srcsets ? src.srcsets.map((s) => `${s.src} ${s.w}w`).join(', ') : ''}
62
+ src={imgSrc.img}
63
+ srcset={imgSrc.srcsets ? imgSrc.srcsets.map((s) => `${s.src} ${s.w}w`).join(', ') : ''}
63
64
  alt={alt}
64
65
  title={title}
65
66
  on:error={handleImgError}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-remote-image",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/ocknamo/svelte-remote-image",
6
6
  "scripts": {