astro-lqip 1.8.0 → 1.8.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.
package/README.md CHANGED
@@ -1,46 +1,55 @@
1
1
  <a href="https://astro-lqip.web.app/">
2
- <img src="./assets/logo.png" alt="Astro LQIP Logo" width="200" height="200" />
2
+ ![astro-lqip](https://raw.githubusercontent.com/felixicaza/astro-lqip/HEAD/.github/assets/astro-lqip.jpg)
3
3
  </a>
4
4
 
5
5
  # 🖼️ astro-lqip
6
6
 
7
- [![GitHub Release](https://img.shields.io/github/v/release/felixicaza/astro-lqip?logo=npm)](https://npmx.dev/package/astro-lqip)
8
- [![GitHub License](https://img.shields.io/github/license/felixicaza/astro-lqip)](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE)
7
+ [![npm version](https://img.shields.io/npm/v/astro-lqip?color=4dae5f&logo=npm&logoColor=888888&labelColor=ffffff)](https://npmx.dev/package/astro-lqip)
8
+ ![GitHub actions workflow tests status](https://img.shields.io/github/actions/workflow/status/felixicaza/astro-lqip/tests.yml?color=4dae5f&logo=rocket&logoColor=888888&label=tests&labelColor=ffffff)
9
+ [![license](https://img.shields.io/github/license/felixicaza/astro-lqip?color=4dae5f&logo=googledocs&logoColor=888888&labelColor=ffffff)](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE)
9
10
 
10
- Native extended Astro components for generating low-quality image placeholders (LQIP), compatible with `<img>`, `<picture>` and CSS background images.
11
+ Native extended Astro components for generating low-quality image placeholders (LQIP), compatible with `<Image>`, `<Picture>` and CSS background images.
11
12
 
12
13
  ## ✨ Features
13
14
  - 🖼️ Supports both `<Image>` and `<Picture>` components and CSS background images.
14
15
  - 🎨 Multiple LQIP techniques: base64, solid color, CSS via gradients and SVG.
15
- - 🚀 Easy to use, just replace the native Astro components with the ones from [astro-lqip](https://astro-lqip.web.app/).
16
+ - 🚀 Easy to use, just replace the native Astro components by [astro-lqip](https://astro-lqip.web.app/).
16
17
  - ⚡️ Support images as static imports or using string paths.
17
18
  - 🔧 Fully compatible with [Astro's image optimization features](https://docs.astro.build/en/guides/images/).
18
19
  - 🌍 Supports both local and remote images.
19
20
  - ⚙️ Supports SSR mode with [Node Adapter](https://docs.astro.build/en/guides/integrations-guide/node/).
20
21
 
21
- ## ⬇️ Installation
22
+ ## 📦 Installation
22
23
 
23
- NPM:
24
+ You can install [`astro-lqip`](https://astro-lqip.web.app/) using npm:
24
25
 
25
- ```bash
26
- npm install astro-lqip
26
+ ```sh
27
+ $ npm install astro-lqip
27
28
  ```
28
29
 
29
- PNPM:
30
+ <details>
31
+ <summary>Using a different package manager?</summary>
32
+ <br/>
30
33
 
31
- ```bash
32
- pnpm add astro-lqip
33
- ```
34
+ Using pnpm:
35
+ ```sh
36
+ $ pnpm add astro-lqip
37
+ ```
34
38
 
35
- Yarn:
39
+ Using yarn:
40
+ ```sh
41
+ $ yarn add astro-lqip
42
+ ```
36
43
 
37
- ```bash
38
- yarn add astro-lqip
39
- ```
44
+ Using bun:
45
+ ```sh
46
+ $ bun add astro-lqip
47
+ ```
48
+ </details>
40
49
 
41
50
  ## 🚀 Usage
42
51
 
43
- In your current Astro project, just replace the import of the native Astro `<Image>` or `<Picture>` components with the ones provided by [astro-lqip](https://astro-lqip.web.app/) or import the `<Background>` component for CSS background images.
52
+ In your current Astro project, just replace the import of the native Astro `<Image>` or `<Picture>` components by [astro-lqip](https://astro-lqip.web.app/) or import the `<Background>` component for optimized CSS background images.
44
53
 
45
54
  ### Image
46
55
 
@@ -92,219 +101,294 @@ import backgroundImage from '/src/assets/images/background-image.png';
92
101
 
93
102
  > [!TIP]
94
103
  > Since version `1.6.0`, you can also put the image path as string directly in the `src` prop. Support absolute paths in `src`, relative paths and alias.
95
-
96
- Example with absolute path:
97
-
98
- ```astro
99
- ---
100
- import { Image, Picture, Background } from 'astro-lqip/components';
101
- ---
102
-
103
- <Image src="/src/assets/images/image.png" alt="Cover Image" width={220} height={220} />
104
- <Picture src="/src/assets/images/other-image.png" alt="Other Image" width={220} height={220} />
105
- <Background src="/src/assets/images/background-image.png">
106
- <section>
107
- <p>Optimized background</p>
108
- </section>
109
- </Background>
110
-
111
- <style>
112
- section {
113
- background-image: var(--background);
114
- background-size: cover;
115
- background-position: center;
116
- }
117
- </style>
118
- ```
119
-
120
- Example with relative path:
121
-
122
- ```astro
123
- ---
124
- import { Image, Picture, Background } from 'astro-lqip/components';
125
- ---
126
-
127
- <!-- assuming you are on the path `/src/pages/index.astro` -->
128
- <Image src="../assets/images/image.png" alt="Cover Image" width={220} height={220} />
129
- <Picture src="../assets/images/other-image.png" alt="Other Image" width={220} height={220} />
130
- <Background src="../assets/images/background-image.png">
131
- <section>
132
- <p>Optimized background</p>
133
- </section>
134
- </Background>
135
-
136
- <style>
137
- section {
138
- background-image: var(--background);
139
- background-size: cover;
140
- background-position: center;
141
- }
142
- </style>
143
- ```
144
-
145
- Example with alias:
146
-
147
- ```astro
148
- ---
149
- import { Image, Picture, Background } from 'astro-lqip/components';
150
- ---
151
-
152
- <Image src="@/assets/images/image.png" alt="Cover Image" width={220} height={220} />
153
- <Picture src="@/assets/images/other-image.png" alt="Other Image" width={220} height={220} />
154
- <Background src="@/assets/images/background-image.png">
155
- <section>
156
- <p>Optimized background</p>
157
- </section>
158
- </Background>
159
-
160
- <style>
161
- section {
162
- background-image: var(--background);
163
- background-size: cover;
164
- background-position: center;
165
- }
166
- </style>
167
- ```
104
+ >
105
+ >
106
+ > <details>
107
+ > <summary>Example with absolute path</summary>
108
+ > <br/>
109
+ >
110
+ > ```astro
111
+ > ---
112
+ > import { Image, Picture, Background } from 'astro-lqip/components';
113
+ > ---
114
+ >
115
+ > <Image src="/src/assets/images/image.png" alt="Cover Image" width={220} height={220} />
116
+ > <Picture src="/src/assets/images/other-image.png" alt="Other Image" width={220} height={220} />
117
+ > <Background src="/src/assets/images/background-image.png">
118
+ > <section>
119
+ > <p>Optimized background</p>
120
+ > </section>
121
+ > </Background>
122
+ >
123
+ > <style>
124
+ > section {
125
+ > background-image: var(--background);
126
+ > background-size: cover;
127
+ > background-position: center;
128
+ > }
129
+ > </style>
130
+ > ```
131
+ > </details>
132
+ >
133
+ > <details>
134
+ > <summary>Example with relative path</summary>
135
+ > <br/>
136
+ >
137
+ > ```astro
138
+ > ---
139
+ > import { Image, Picture, Background } from 'astro-lqip/components';
140
+ > ---
141
+ >
142
+ > <!-- assuming you are on the path `/src/pages/index.astro` -->
143
+ > <Image src="../assets/images/image.png" alt="Cover Image" width={220} height={220} />
144
+ > <Picture src="../assets/images/other-image.png" alt="Other Image" width={220} height={220} />
145
+ > <Background src="../assets/images/background-image.png">
146
+ > <section>
147
+ > <p>Optimized background</p>
148
+ > </section>
149
+ > </Background>
150
+ >
151
+ > <style>
152
+ > section {
153
+ > background-image: var(--background);
154
+ > background-size: cover;
155
+ > background-position: center;
156
+ > }
157
+ > </style>
158
+ > ```
159
+ > </details>
160
+ >
161
+ > <details>
162
+ > <summary>Example with alias</summary>
163
+ > <br/>
164
+ >
165
+ > ```astro
166
+ > ---
167
+ > import { Image, Picture, Background } from 'astro-lqip/components';
168
+ > ---
169
+ >
170
+ > <Image src="@/assets/images/image.png" alt="Cover Image" width={220} height={220} />
171
+ > <Picture src="@/assets/images/other-image.png" alt="Other Image" width={220} height={220} />
172
+ > <Background src="@/assets/images/background-image.png">
173
+ > <section>
174
+ > <p>Optimized background</p>
175
+ > </section>
176
+ > </Background>
177
+ >
178
+ > <style>
179
+ > section {
180
+ > background-image: var(--background);
181
+ > background-size: cover;
182
+ > background-position: center;
183
+ > }
184
+ > </style>
185
+ > ```
186
+ > </details>
168
187
 
169
188
  Learn how to configure path aliasing in the [Astro documentation](https://docs.astro.build/en/guides/typescript/#import-aliases). If you want more examples of uses you can see the [Usage Tips](https://astro-lqip.web.app/usage-tips/) page.
170
189
 
171
190
  ## ⚙️ Props
172
191
 
173
- ### Image and Picture
192
+ ### 🔩 Image and Picture
174
193
 
175
194
  Both `<Image>` and `<Picture>` components support all the props of the [native Astro components](https://docs.astro.build/en/reference/modules/astro-assets/), but adds a couple of props for LQIP management:
176
195
 
177
- - `lqip`: The LQIP type to use. It can be one of the following:
178
- - `base64`: Generates a Base64-encoded LQIP image. (default option)
179
- - `color`: Generates a solid color placeholder. Not compatible with `lqipSize`.
180
- - `css`: Generates a CSS-based LQIP image.
181
- - `svg`: Generates an SVG-based LQIP image.
182
- - `lqipSize`: The size of the LQIP image, which can be any number from `4` to `64`. (default is 4)
196
+ #### `lqip` (string) optional
197
+ The LQIP type to use. It can be one of the following:
198
+ - `base64` (default) Base64-encoded LQIP image
199
+ - `color` Solid color placeholder
200
+ - `css` CSS-based LQIP image
201
+ - `svg` SVG-based LQIP image
202
+ - `false` — Disables LQIP generation
203
+
204
+ #### `lqipSize` (number) — optional (default 4)
205
+ The size of the LQIP image, which can be any number from `4` to `64`.
183
206
 
184
207
  > [!WARNING]
185
208
  > A high value for `lqipSize` can significantly increase the total size of your website.
186
209
 
187
- Example:
210
+ <details>
211
+ <summary>Example</summary>
212
+ <br/>
188
213
 
189
- ```astro
190
- ---
191
- import { Image, Picture } from 'astro-lqip/components';
214
+ ```astro
215
+ ---
216
+ import { Image, Picture } from 'astro-lqip/components';
192
217
 
193
- import image from '/src/assets/images/image.png';
194
- import otherImage from '/src/assets/images/other-image.png';
195
- ---
218
+ import image from '/src/assets/images/image.png';
219
+ import otherImage from '/src/assets/images/other-image.png';
220
+ ---
196
221
 
197
- <Image src={image} alt="Cover Image" width={220} height={220} lqip="svg" lqipSize={10} />
198
- <Picture src={otherImage} alt="Other Image" width={220} height={220} lqip="css" lqipSize={7} />
199
- ```
222
+ <Image src={image} alt="Cover Image" width={220} height={220} lqip="svg" lqipSize={10} />
223
+ <Picture src={otherImage} alt="Other Image" width={220} height={220} lqip="css" lqipSize={7} />
224
+ ```
225
+ </details>
200
226
 
201
227
  > [!TIP]
202
- > For the `<Image>` component, a `parentAttributes` prop similar to `pictureAttributes` has been added.
228
+ > For the `<Image>` component, a `parentAttributes` prop similar to [`pictureAttributes`](https://docs.astro.build/en/reference/modules/astro-assets/#pictureattributes) has been added.
203
229
 
204
- ### Background
230
+ <details>
231
+ <summary>Example</summary>
232
+ <br/>
205
233
 
206
- The `<Background>` component supports the following props:
207
-
208
- - `src` (required): The source of the background image located in `src` folder. It can be a static import, absolute path, relative path, alias path or remote URL.
209
- - `lqip`: The LQIP type to use. It can be one of the following:
210
- - `base64`: Generates a Base64-encoded LQIP image. (default option)
211
- - `color`: Generates a solid color placeholder.
212
- - `cssVariable`: A string that represents the name of the CSS variable to store the background data.
213
- - By default, the background data is stored in a CSS variable named `--background`.
214
- - For responsive backgrounds, the CSS variable names are generated based on the provided widths, following the pattern `--background-small` (lower than 768px), `--background-medium` (768px to 1199px), `--background-large` (1200px to 1919px) and `--background-xlarge` (1920px and above). `--background` is also generated for the largest image for backward compatibility.
215
- - If the `cssVariable` prop is provided, the generated CSS variable names will follow the pattern `--{cssVariable}-small`, `--{cssVariable}-medium`, `--{cssVariable}-large` and `--{cssVariable}-xlarge`.
216
- - `format`: The image format to use for the background. It can be one of the following in string or an array of strings. If an array is provided, this generates multiple background images with the native [`image-set()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/image/image-set) CSS function, which allows the browser to choose the best format to use based on its support:
217
- - `avif`
218
- - `webp` (default option)
219
- - `jpeg`
220
- - `png`
221
- - `widths`: An array of numbers that represents the widths to use for responsive background images.
222
- - `width`: The width to use for the background image. This prop is ignored if the `widths` prop is provided.
223
- - `height`: The height to use for the background image. This prop is ignored if the `widths` prop is provided.
224
- - `quality`: The quality to use for the background image. It can be a number from `1` to `100`.
225
- - `fit`: The fit to use for the background image. It can be one of the following:
226
- - `cover`
227
- - `contain`
228
- - `fill`
229
- - `inside`
230
- - `outside`
231
-
232
- Example:
234
+ ```astro
235
+ ---
236
+ import { Image } from 'astro-lqip/components';
233
237
 
234
- ```astro
235
- ---
236
- import { Background } from 'astro-lqip/components';
237
- import backgroundImage from '/src/assets/images/background-image.png';
238
- ---
238
+ import image from '/src/assets/images/image.png';
239
+ ---
239
240
 
240
- <Background src={backgroundImage} lqip="color" cssVariable="--bg-lqip" format={["avif", "webp"]} width={500} height={300} quality={80} fit="cover">
241
- <section>
242
- <p>Optimized background</p>
243
- </section>
244
- </Background>
241
+ <Image
242
+ src={image}
243
+ alt="Cover Image"
244
+ width={220}
245
+ height={220}
246
+ lqip="svg"
247
+ lqipSize={10}
248
+ parentAttributes={{ style: "background-color: red;" }}
249
+ />
250
+ ```
251
+ </details>
245
252
 
246
- <style>
247
- section {
248
- background-image: var(--bg-lqip);
249
- background-size: cover;
250
- background-position: center;
251
- }
252
- </style>
253
- ```
253
+ ### 🔩 Background
254
254
 
255
- Example with responsive background:
256
-
257
- ```astro
258
- ---
259
- import { Background } from 'astro-lqip/components';
260
- import backgroundImage from '/src/assets/images/background-image.png';
261
- ---
262
-
263
- <Background src={backgroundImage} format="avif" widths={[475, 1000, 1536, 2100]}>
264
- <section>
265
- <p>Optimized background</p>
266
- </section>
267
- </Background>
268
-
269
- <style>
270
- section {
271
- background-image: var(--background-small); /* 475px */
272
- background-size: cover;
273
- background-position: center;
274
- }
255
+ The `<Background>` component supports the following props:
275
256
 
276
- @media (width >= 768px) {
257
+ #### `src` (string) required
258
+ The source of the background image located in `src` folder. It can be a static import, absolute path, relative path, alias path or remote URL.
259
+
260
+ #### `lqip` — optional
261
+ The LQIP type to use. It can be one of the following:
262
+ - `base64` (default) — Base64-encoded LQIP image
263
+ - `color` — Solid color placeholder
264
+ - `css` — CSS-based LQIP image
265
+ - `svg` — SVG-based LQIP image
266
+ - `false` — Disables LQIP generation
267
+
268
+ #### `cssVariable` (string) — optional
269
+ Represents the name of the CSS variable to store the background data.
270
+
271
+ - By default, the background data is stored in a CSS variable named `--background`.
272
+ - For responsive backgrounds, the CSS variable names are generated based on the provided widths, following the pattern:
273
+ - `--background-small` (lower than 768px)
274
+ - `--background-medium` (768px to 1199px)
275
+ - `--background-large` (1200px to 1919px)
276
+ - `--background-xlarge` (1920px and above), `--background` is also generated for the largest image for backward compatibility.
277
+ - If the `cssVariable` prop is provided, the generated CSS variable names will follow the pattern:
278
+ - `--{cssVariable}-small`
279
+ - `--{cssVariable}-medium`
280
+ - `--{cssVariable}-large`
281
+ - `--{cssVariable}-xlarge`, `--{cssVariable}` is also generated for the largest image for backward compatibility.
282
+
283
+ #### `format` (string | array&lt;string&gt;) — optional
284
+ The image format to use for the background. It can be one of the following in string or an array of strings. If an array is provided, this generates multiple background images with the native [`image-set()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/image/image-set) CSS function, which allows the browser to choose the best format to use based on its support:
285
+ - `avif`
286
+ - `webp` (default)
287
+ - `jpeg`
288
+ - `png`
289
+
290
+
291
+ #### `widths` (array) — optional
292
+ An array of numbers that represents the widths to use for responsive background images.
293
+
294
+ #### `width` (number) — optional
295
+ The width to use for the background image. This prop is ignored if the `widths` prop is provided.
296
+
297
+ #### `height` (number) — optional
298
+ The height to use for the background image. This prop is ignored if the `widths` prop is provided.
299
+
300
+ #### `quality` (number) — optional
301
+ The quality to use for the background image. It can be a number from `1` to `100`.
302
+
303
+ #### `fit` (string) — optional
304
+ The fit to use for the background image. It can be one of the following:
305
+ - `cover` (default)
306
+ - `contain`
307
+ - `fill`
308
+ - `inside`
309
+ - `outside`
310
+
311
+ <details>
312
+ <summary>Example</summary>
313
+ <br/>
314
+
315
+ ```astro
316
+ ---
317
+ import { Background } from 'astro-lqip/components';
318
+ import backgroundImage from '/src/assets/images/background-image.png';
319
+ ---
320
+
321
+ <Background src={backgroundImage} lqip="color" cssVariable="--bg-lqip" format={["avif", "webp"]} width={500} height={300} quality={80} fit="cover">
322
+ <section>
323
+ <p>Optimized background</p>
324
+ </section>
325
+ </Background>
326
+
327
+ <style>
277
328
  section {
278
- background-image: var(--background-medium); /* 1000px */
329
+ background-image: var(--bg-lqip);
330
+ background-size: cover;
331
+ background-position: center;
279
332
  }
280
- }
281
-
282
- @media (width >= 1200px) {
333
+ </style>
334
+ ```
335
+ </details>
336
+
337
+ <details>
338
+ <summary>Example with responsive background</summary>
339
+ <br/>
340
+
341
+ ```astro
342
+ ---
343
+ import { Background } from 'astro-lqip/components';
344
+ import backgroundImage from '/src/assets/images/background-image.png';
345
+ ---
346
+
347
+ <Background src={backgroundImage} format="avif" widths={[475, 1000, 1536, 2100]}>
348
+ <section>
349
+ <p>Optimized background</p>
350
+ </section>
351
+ </Background>
352
+
353
+ <style>
283
354
  section {
284
- background-image: var(--background-large); /* 1536px */
355
+ background-image: var(--background-small); /* 475px */
356
+ background-size: cover;
357
+ background-position: center;
285
358
  }
286
- }
287
359
 
288
- @media (width >= 1920px) {
289
- section {
290
- /* or var(--background), since it's the default variable for the largest image */
291
- background-image: var(--background-xlarge); /* 2100px */
360
+ @media (width >= 768px) {
361
+ section {
362
+ background-image: var(--background-medium); /* 1000px */
363
+ }
364
+ }
365
+
366
+ @media (width >= 1200px) {
367
+ section {
368
+ background-image: var(--background-large); /* 1536px */
369
+ }
292
370
  }
293
- }
294
- </style>
295
- ```
371
+
372
+ @media (width >= 1920px) {
373
+ section {
374
+ /* or var(--background), since it's the default variable for the largest image */
375
+ background-image: var(--background-xlarge); /* 2100px */
376
+ }
377
+ }
378
+ </style>
379
+ ```
380
+ </details>
296
381
 
297
382
  > [!NOTE]
298
383
  > The `lqipSize` prop is not compatible with this component, to avoid large CSS outputs.
299
384
 
300
385
  ## 💡 Knowledge
301
-
302
386
  Since this integration is built on top of Astro native `<Image>` and `<Picture>` components, you can refer to the [Astro documentation](https://docs.astro.build/en/guides/images/) for more information on how to use it.
303
387
 
304
388
  For some simple tips, visit the [Usage Tips](https://astro-lqip.web.app/usage-tips/) page.
305
389
 
306
390
  ## 🤝 Contributing
307
- If you wish to contribute to this project, you can do so by reading the [contribution guide](https://github.com/felixicaza/astro-lqip/blob/main/CONTRIBUTING.md).
391
+ Contributions to this library are welcome! If you have any ideas for improvements or new features, please feel free to open an issue or submit a pull request. I appreciate your help in making [`astro-lqip`](https://astro-lqip.web.app/) better for everyone. Please read the [CONTRIBUTING.md](https://github.com/felixicaza/astro-lqip/blob/main/CONTRIBUTING.md).
308
392
 
309
393
  ## 📄 License
310
- This project is licensed under the MIT License. See the [license file](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE) for more details.
394
+ This project is licensed under the MIT License. See the [LICENSE](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE) file for details.
@@ -0,0 +1 @@
1
+ @layer astro-lqip{[data-astro-lqip-bg]{display:contents}[data-astro-lqip]{--opacity:1;--z-index:0;isolation:isolate;width:fit-content;height:fit-content;line-height:0;display:inline-block;position:relative;overflow:clip;&:after{content:"";pointer-events:none;opacity:var(--opacity);z-index:var(--z-index);background:var(--lqip-background);background-position:50%;background-size:cover;transition:opacity 1s;position:absolute;inset:0}& img{z-index:1;position:relative}@media (scripting:none){--opacity:0;--z-index:1}}}