astro-lqip 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Felix Icaza
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ <img src="./assets/cover.png" alt="Cover" width="896" height="280" style="object-fit: cover" />
2
+
3
+ # 🖼️ astro-lqip
4
+
5
+ [![GitHub Release](https://img.shields.io/github/v/release/felixicaza/astro-lqip?logo=npm)](https://www.npmjs.com/package/astro-lqip)
6
+ [![GitHub License](https://img.shields.io/github/license/felixicaza/astro-lqip)](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE)
7
+
8
+ A integration built over the native Astro component that generates low-quality image placeholders (LQIP) for your images.
9
+
10
+ ## ⬇️ Installation
11
+
12
+ NPM:
13
+
14
+ ```bash
15
+ npm install astro-lqip
16
+ ```
17
+
18
+ PNPM:
19
+
20
+ ```bash
21
+ pnpm add astro-lqip
22
+ ```
23
+
24
+ Yarn:
25
+
26
+ ```bash
27
+ yarn add astro-lqip
28
+ ```
29
+
30
+ ## 🚀 Usage
31
+
32
+ In your current Astro project, just replace the native Astro `<Picture>` component with the one provided by this integration.
33
+
34
+ ```astro
35
+ - import { Picture } from 'astro:assets';
36
+ + import { Picture } from 'astro-lqip/components';
37
+ ```
38
+
39
+ ## 📝 ToDo
40
+
41
+ - [ ] Add support for Image component.
42
+ - [ ] Add support for more lqip techniques.
43
+ - [ ] Optimize current CSS usage.
44
+ - [ ] Improve demo page.
45
+
46
+ ## 💡 Knowledge
47
+
48
+ Since this integration is built on top of Astro's native `<Picture>` component, you can refer to the [Astro documentation](https://docs.astro.build/en/guides/images/#picture-) for more information on how to use it.
49
+
50
+ ## 🤝 Contributing
51
+ 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).
52
+
53
+ ## 📄 License
54
+ This project is licensed under the MIT License. See the [license file](https://github.com/felixicaza/astro-lqip/blob/main/LICENSE) for more details.
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "astro-lqip",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "astro",
7
+ "astro-component",
8
+ "astro-integration",
9
+ "image",
10
+ "lqip"
11
+ ],
12
+ "homepage": "https://github.com/felixicaza/astro-lqip",
13
+ "bugs": {
14
+ "url": "https://github.com/felixicaza/astro-lqip/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/felixicaza/astro-lqip.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Felix Icaza",
22
+ "type": "module",
23
+ "exports": {
24
+ "./components": "./src/index.ts"
25
+ },
26
+ "files": [
27
+ "src"
28
+ ],
29
+ "simple-git-hooks": {
30
+ "pre-commit": "pnpm nano-staged"
31
+ },
32
+ "nano-staged": {
33
+ "*": "pnpm lint:fix"
34
+ },
35
+ "dependencies": {
36
+ "lqip-modern": "2.2.1"
37
+ },
38
+ "devDependencies": {
39
+ "@eslint/js": "9.30.0",
40
+ "@typescript-eslint/parser": "8.35.0",
41
+ "astro": "5.10.1",
42
+ "bumpp": "10.2.0",
43
+ "eslint": "9.30.0",
44
+ "eslint-plugin-astro": "1.3.1",
45
+ "eslint-plugin-jsonc": "2.20.1",
46
+ "eslint-plugin-jsx-a11y": "6.10.2",
47
+ "eslint-plugin-package-json": "0.42.0",
48
+ "eslint-plugin-yml": "1.18.0",
49
+ "globals": "16.2.0",
50
+ "jiti": "2.4.2",
51
+ "nano-staged": "0.8.0",
52
+ "neostandard": "0.12.1",
53
+ "simple-git-hooks": "2.13.0"
54
+ },
55
+ "peerDependencies": {
56
+ "astro": ">=3.3.0"
57
+ },
58
+ "scripts": {
59
+ "build": "pnpm -r build",
60
+ "dev": "pnpm -r dev",
61
+ "lint": "eslint --cache .",
62
+ "lint:fix": "eslint --cache --fix .",
63
+ "preview": "pnpm -r preview",
64
+ "release": "bumpp -r"
65
+ }
66
+ }
@@ -0,0 +1,86 @@
1
+ ---
2
+ import path from 'node:path'
3
+ import fs from 'node:fs/promises'
4
+
5
+ import lqipModern from 'lqip-modern'
6
+
7
+ import { Picture as PictureComponent } from 'astro:assets'
8
+ import type { Props as PictureProps } from 'astro/components/Picture.astro'
9
+
10
+ type Props = PictureProps
11
+
12
+ const { class: className, ...props } = Astro.props as Props
13
+
14
+ let imageMetadata
15
+ let lqip
16
+
17
+ if (typeof props.src === 'string') {
18
+ imageMetadata = null
19
+ } else if ('then' in props.src && typeof props.src.then === 'function') {
20
+ imageMetadata = (await props.src).default
21
+ } else if ('src' in props.src) {
22
+ imageMetadata = props.src
23
+ } else {
24
+ imageMetadata = null
25
+ }
26
+
27
+ if (import.meta.env.MODE === 'development') {
28
+ if (imageMetadata?.src?.startsWith('/@fs/')) {
29
+ const filePath = imageMetadata.src.replace(/^\/@fs/, '').split('?')[0]
30
+ const buffer = await fs.readFile(filePath)
31
+
32
+ const lqipModernBuffer = await lqipModern(buffer)
33
+ lqip = lqipModernBuffer.metadata?.dataURIBase64
34
+ }
35
+ } else {
36
+ if (imageMetadata?.src?.startsWith('/_astro/')) {
37
+ const publicPath = path.join(process.cwd(), 'dist', imageMetadata.src)
38
+
39
+ try {
40
+ const buffer = await fs.readFile(publicPath)
41
+ const lqipModernBuffer = await lqipModern(buffer)
42
+ lqip = lqipModernBuffer.metadata?.dataURIBase64
43
+ } catch (e) {
44
+ lqip = undefined
45
+ }
46
+ }
47
+ }
48
+ ---
49
+
50
+ <style is:inline>
51
+ picture {
52
+ --opacity: 1;
53
+ --z-index: 0;
54
+
55
+ position: relative;
56
+ display: inline-block;
57
+ }
58
+
59
+ picture::after {
60
+ content: "";
61
+ inset: 0;
62
+ width: 100%;
63
+ height: 100%;
64
+ position: absolute;
65
+ pointer-events: none;
66
+ transition: opacity 1s;
67
+ opacity: var(--opacity);
68
+ z-index: var(--z-index);
69
+ background: var(--lqip-background);
70
+ background-size: cover;
71
+ background-position: 50% 50%;
72
+ }
73
+
74
+ picture img {
75
+ z-index: 1;
76
+ position: relative;
77
+ overflow: hidden;
78
+ }
79
+ </style>
80
+
81
+ <PictureComponent
82
+ {...props}
83
+ class={className}
84
+ pictureAttributes={{ style: { '--lqip-background': `url('${lqip}')` } }}
85
+ onload="parentElement.style.setProperty('--z-index', 1), parentElement.style.setProperty('--opacity', 0)"
86
+ />
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as Picture } from './components/Picture.astro'