Skip to content

Commit 5a7bfe5

Browse files
committed
Update dependencies
1 parent 1fd1198 commit 5a7bfe5

File tree

6 files changed

+342
-333
lines changed

6 files changed

+342
-333
lines changed

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The image component renders into:
5858
/>
5959
<img
6060
class="cool cats"
61-
src="path/to/jpg/1920"
61+
src="path/to/jpg-1920"
6262
srcset="path/to/jpg-480 480w, path/to/jpg-1024 1024w, path/to/jpg-1920 1920w"
6363
loading="lazy"
6464
decoding="async"
@@ -81,16 +81,16 @@ To change this globally, edit your `vite.config.js`:
8181

8282
```js
8383
import { sveltekit } from '@sveltejs/kit/vite'
84-
import { imagetools, set } from '@zerodevx/svelte-img/vite'
84+
import { imagetools } from '@zerodevx/svelte-img/vite'
8585

8686
/** @type {import('vite').UserConfig} */
8787
const config = {
8888
plugins: [
8989
sveltekit(),
9090
imagetools({
9191
// By default, directives are `?width=480;1024;1920&format=avif;webp;jpg`
92-
defaultDirectives: (url) => set(url, '?width=768;1920&format=avif;jpg')
93-
// Now this generates 5 variants - `avif/jpg` formats at `768/1024` + LQIP
92+
// Now we change it to generate 5 variants instead - `avif/jpg` formats at `640/1280` + LQIP
93+
defaultDirectives: () => new URLSearchParams('?width=640;1280&format=avif;jpg')
9494
})
9595
]
9696
}
@@ -105,28 +105,29 @@ Widths/formats can be applied to a particular image. From your `.svelte` file:
105105
<!-- prettier-ignore -->
106106
```html
107107
<script>
108-
import src from '$lib/a/cat.jpg?width=768;1920&format=avif;jpg&run'
108+
// We override defaults to generate 5 variants instead - `avif/jpg` formats at `768/1024` + LQIP
109+
import src from '$lib/a/cat.jpg?run&width=640;1024&format=avif;jpg'
109110
import Img from '@zerodevx/svelte-img'
110111
</script>
111112

112-
<Img {src} alt="cat" >
113+
<Img {src} alt="cat" />
113114
```
114115

115116
#### Change LQIP width
116117

117118
By default, LQIPs are 16px in width and set to `cover` the full image dimension. Increase for a
118119
higher quality LQIP at the expense of a larger `base64`, or set to 1px for a dominant single-colour
119-
background. To disable LQIP completely, set `?lqip=0`.
120+
background. To disable LQIP completely, set `?run&lqip=0`.
120121

121122
<!-- prettier-ignore -->
122123
```html
123124
<script>
124-
import src from '$lib/a/cat.jpg?lqip=1&run'
125+
import src from '$lib/a/cat.jpg?run&lqip=1'
125126
import Img from '@zerodevx/svelte-img'
126127
</script>
127128

128129
<!-- Render dominant colour background -->
129-
<Img {src} alt="cat" >
130+
<Img {src} alt="cat" />
130131
```
131132

132133
#### Other transformations
@@ -138,38 +139,43 @@ of transformation directives offered by
138139
<!-- prettier-ignore -->
139140
```html
140141
<script>
141-
import src from '$lib/a/cat.jpg?&height=600&fit=cover&normalize&run'
142+
import src from '$lib/a/cat.jpg?run&height=600&fit=cover&normalize'
142143
import Img from '@zerodevx/svelte-img'
143144
</script>
144145

145-
<Img {src} alt="cat" >
146+
<Img {src} alt="cat" />
146147
```
147148

148149
#### Remote images from an API
149150

150-
The `svelte-img` component can be used on its own and accepts `src` as an array of image objects
151-
like so:
151+
Use the `svelte-img` component on its own by passing an array of image objects into `src` like so:
152152

153153
<!-- prettier-ignore -->
154-
```js
155-
[
154+
```html
155+
<script>
156+
import Img from '@zerodevx/svelte-img'
157+
158+
const src = [
156159
{ format: 'avif', src: 'https://x.com/path/to/avif-480', width: 480 },
157160
{ format: 'webp', src: 'https://x.com//path/to/webp-480', width: 480 },
158161
{ format: 'jpg', src: 'https://x.com//path/to/jpg-480', width: 480 },
159162
{ format: 'avif', src: 'https://x.com//path/to/avif-1024', width: 1024 },
160163
... // all other variants
161164
{ base64: 'data:image/webp;base64,XXX' } // an optional LQIP with `base64` key
162165
]
166+
</script>
167+
168+
<Img {src} alt="hello" />
163169
```
164170

165-
The order doesn't matter; `svelte-img` internally sorts out the rendering priority based on:
171+
The order doesn't matter; `svelte-img` internally sorts out the source priority based on:
166172

167173
```js
168174
// Highest to lowest
169175
const priority = ['heic', 'heif', 'avif', 'webp', 'jpeg', 'jpg', 'png', 'gif', 'tiff']
170176
```
171177

172-
#### A better blur
178+
#### Blurred image placeholders
173179

174180
Natively, browsers do already apply _some_ blur when displaying low resolution images. That's enough
175181
for me, but you can apply your own using CSS.
@@ -181,7 +187,7 @@ import src from '$lib/a/cat.jpg?run'
181187
import Img from '@zerodevx/svelte-img'
182188
</script>
183189

184-
<Img {src} alt="cat" >
190+
<Img {src} alt="cat" />
185191

186192
<style>
187193
:global(img)::after {
@@ -196,9 +202,10 @@ import Img from '@zerodevx/svelte-img'
196202

197203
## To do
198204

199-
- [ ] Add type annotations
205+
- [ ] Add typings
200206
- [ ] Add tests
201-
- [ ] Document more features
207+
- [ ] Improve docs
208+
- [ ] Improve demo
202209

203210
## License
204211

0 commit comments

Comments
 (0)