svelte-remote-image 0.2.0 → 0.2.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.
@@ -1,18 +1,28 @@
1
- <script>import { fail } from "@sveltejs/kit";
1
+ <script>import { browser } from "$app/environment";
2
2
  import { afterUpdate } from "svelte";
3
3
  export let src;
4
4
  export let style = "";
5
+ export const alt = "";
6
+ export const title = "";
5
7
  const imgId = `svelte-remote-image-${src.alt.replaceAll(" ", "-")}-${Math.round(Math.random() * 1e7)}`;
8
+ const getImgElement = () => browser ? document.getElementById(imgId) : null;
6
9
  let loadStatus = "loading";
7
- if (src.placeholder) {
8
- if (src.placeholder.dataUri) {
9
- style = `${style} background: url(${src.placeholder.dataUri}) no-repeat center/cover;`;
10
+ $: {
11
+ loadStatus = "loading";
12
+ if (src.placeholder) {
13
+ if (src.placeholder.dataUri) {
14
+ style = `${style} background: url(${src.placeholder.dataUri}) no-repeat center/cover;`;
15
+ }
16
+ if (src.placeholder.color) {
17
+ style = `${style} background-color: ${src.placeholder.color};`;
18
+ }
10
19
  }
11
- if (src.placeholder.color) {
12
- style = `${style} background-color: ${src.placeholder.color};`;
20
+ const img = getImgElement();
21
+ if (img) {
22
+ img.style.visibility = "hidden";
13
23
  }
14
24
  }
15
- afterUpdate(() => {
25
+ afterUpdate(async () => {
16
26
  const img = getImgElement();
17
27
  if (!img) {
18
28
  return;
@@ -32,7 +42,7 @@ const handleImgError = (e) => {
32
42
  if (!img) {
33
43
  return;
34
44
  }
35
- img.style.visibility = "hiddin";
45
+ img.style.visibility = "hidden";
36
46
  let failbackUrl = void 0;
37
47
  const index = src.failback.findIndex(
38
48
  (url) => new URL(url).toString() === new URL(img.src).toString()
@@ -62,7 +72,6 @@ const handleLoaded = (e) => {
62
72
  img.style.visibility = "visible";
63
73
  loadStatus = "loaded";
64
74
  };
65
- const getImgElement = () => document.getElementById(imgId);
66
75
  </script>
67
76
 
68
77
  <picture>
@@ -80,9 +89,10 @@ const getImgElement = () => document.getElementById(imgId);
80
89
  width={src.w}
81
90
  height={src.h}
82
91
  {style}
83
- class={src.blur ? `svelte-remote-image image-blur-${loadStatus}` : 'svelte-remote-image'}
92
+ class={src.blur ? `image-blur-${loadStatus}` : ''}
84
93
  src={src.img}
85
- alt={src.alt}
94
+ alt={alt}
95
+ title={title}
86
96
  on:error={handleImgError}
87
97
  on:load={handleLoaded}
88
98
  loading="lazy"
@@ -90,10 +100,6 @@ const getImgElement = () => document.getElementById(imgId);
90
100
  </picture>
91
101
 
92
102
  <style>
93
- img.svelte-remote-image {
94
- /* initial value */
95
- visibility: hidden;
96
- }
97
103
  .image-blur-loading {
98
104
  animation:
99
105
  0.5s linear 0s normal waiting,
@@ -4,6 +4,8 @@ declare const __propDef: {
4
4
  props: {
5
5
  src: ImageSrc;
6
6
  style?: string | undefined;
7
+ alt?: "" | undefined;
8
+ title?: "" | undefined;
7
9
  };
8
10
  events: {
9
11
  [evt: string]: CustomEvent<any>;
@@ -16,5 +18,7 @@ export type ImageProps = typeof __propDef.props;
16
18
  export type ImageEvents = typeof __propDef.events;
17
19
  export type ImageSlots = typeof __propDef.slots;
18
20
  export default class Image extends SvelteComponent<ImageProps, ImageEvents, ImageSlots> {
21
+ get alt(): "";
22
+ get title(): "";
19
23
  }
20
24
  export {};
@@ -10,7 +10,6 @@ export interface ImageSrc {
10
10
  jpeg?: Srcset[];
11
11
  png?: Srcset[];
12
12
  failback: string[];
13
- alt: string;
14
13
  placeholder?: {
15
14
  dataUri?: string;
16
15
  color?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-remote-image",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/ocknamo/svelte-remote-image",
6
6
  "scripts": {