Skip to content

Commit 25467c1

Browse files
committed
feat(preact): add Preact components
1 parent 999d442 commit 25467c1

15 files changed

Lines changed: 1437 additions & 0 deletions

packages/preact/.size-limit.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"name": "All publics",
4+
"path": "dist/index.js",
5+
"import": "*",
6+
"limit": "1 kB"
7+
}
8+
]

packages/preact/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# @srcset/preact
2+
3+
[![ESM-only package][package]][package-url]
4+
[![NPM version][npm]][npm-url]
5+
[![Node version][node]][node-url]
6+
[![Dependencies status][deps]][deps-url]
7+
[![Install size][size]][size-url]
8+
[![Build status][build]][build-url]
9+
[![Coverage status][coverage]][coverage-url]
10+
11+
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
12+
[package-url]: https://nodejs.org/api/esm.html
13+
14+
[npm]: https://img.shields.io/npm/v/%40srcset%2Fpreact.svg
15+
[npm-url]: https://npmjs.com/package/@srcset/preact
16+
17+
[node]: https://img.shields.io/node/v/%40srcset%2Fpreact.svg
18+
[node-url]: https://nodejs.org
19+
20+
[deps]: https://img.shields.io/librariesio/release/npm/%40srcset%2Fpreact
21+
[deps-url]: https://libraries.io/npm/%40srcset%2Fpreact
22+
23+
[size]: https://deno.bundlejs.com/badge?q=%40srcset%2Fpreact
24+
[size-url]: https://bundlejs.com/?q=%40srcset%2Fpreact
25+
26+
[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/srcset/tests.yml?branch=main
27+
[build-url]: https://github.com/TrigenSoftware/srcset/actions
28+
29+
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/srcset.svg
30+
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/srcset
31+
32+
Preact components for responsive images: Picture and Image.
33+
34+
- 🖼 `<picture>` sources grouped by mime type and ordered by format efficiency
35+
- 🚀 Lazy loading and async decoding by default, `priority` for above-the-fold images
36+
- 🌫 Blur-up placeholder background until the image loads
37+
- 📐 Anti-CLS: intrinsic size from the image variant
38+
39+
## Install
40+
41+
```bash
42+
# pnpm
43+
pnpm add @srcset/preact @srcset/runtime
44+
# yarn
45+
yarn add @srcset/preact @srcset/runtime
46+
# npm
47+
npm i @srcset/preact @srcset/runtime
48+
```
49+
50+
## Usage
51+
52+
```tsx
53+
import { src, srcSet, placeholder } from './photo.jpg'
54+
import { Picture, Image } from '@srcset/preact'
55+
56+
function Hero() {
57+
return (
58+
<Picture srcSet={srcSet}>
59+
<Image
60+
alt='Hero photo'
61+
src={src}
62+
placeholder={placeholder}
63+
/>
64+
</Picture>
65+
)
66+
}
67+
```
68+
69+
## Documentation
70+
71+
For more details, guides and API references, check out the [documentation website](https://srcset.js.org/components/preact/).

packages/preact/oxlint.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig } from '@trigen/oxlint'
2+
import reactConfig from '@trigen/oxlint-config/react'
3+
import testConfig from '@trigen/oxlint-config/test'
4+
import tsTypeCheckedConfig from '@trigen/oxlint-config/typescript-type-checked'
5+
import rootConfig from '../../oxlint.config.ts'
6+
7+
export default defineConfig({
8+
extends: [
9+
rootConfig,
10+
reactConfig,
11+
tsTypeCheckedConfig,
12+
testConfig
13+
],
14+
env: {
15+
node: false,
16+
browser: true
17+
},
18+
rules: {
19+
// Preact JSX uses real DOM attribute names, like `fetchpriority`.
20+
'react/no-unknown-property': 'off'
21+
}
22+
})

packages/preact/package.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"name": "@srcset/preact",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "Preact components for responsive images: Picture and Image.",
6+
"author": {
7+
"name": "Dan Onoshko",
8+
"email": "danon0404@gmail.com",
9+
"url": "https://github.com/dangreen"
10+
},
11+
"license": "MIT",
12+
"homepage": "https://srcset.js.org/components/preact/",
13+
"funding": "https://ko-fi.com/dangreen",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/TrigenSoftware/srcset.git",
17+
"directory": "packages/preact"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/TrigenSoftware/srcset/issues"
21+
},
22+
"keywords": [
23+
"srcset",
24+
"image",
25+
"picture",
26+
"responsive",
27+
"preact",
28+
"components"
29+
],
30+
"engines": {
31+
"node": ">=22"
32+
},
33+
"sideEffects": false,
34+
"exports": {
35+
"./package.json": "./package.json",
36+
".": "./src/index.ts"
37+
},
38+
"publishConfig": {
39+
"exports": {
40+
"./package.json": "./package.json",
41+
".": {
42+
"types": "./dist/index.d.ts",
43+
"default": "./dist/index.js"
44+
}
45+
},
46+
"directory": "package",
47+
"linkDirectory": false
48+
},
49+
"files": [
50+
"dist"
51+
],
52+
"scripts": {
53+
"clear:package": "del ./package",
54+
"clear:dist": "del ./dist",
55+
"clear": "del ./package ./dist ./coverage",
56+
"prepublishOnly": "run build clear:package clean-publish",
57+
"postpublish": "pnpm clear:package",
58+
"emitDeclarations": "tsc -p ./tsconfig.build.json --emitDeclarationOnly",
59+
"build:dist": "run -p emitDeclarations [ vite build ]",
60+
"build": "run clear:dist build:dist",
61+
"lint": "oxlint",
62+
"format": "oxlint --fix",
63+
"test:unit": "vitest run --coverage",
64+
"test:unit:watch": "vitest watch",
65+
"test:size": "size-limit",
66+
"test:types": "tsc --noEmit",
67+
"test": "run -p lint test:unit test:types"
68+
},
69+
"peerDependencies": {
70+
"@srcset/runtime": "workspace:^",
71+
"preact": ">=10.11"
72+
},
73+
"devDependencies": {
74+
"@size-limit/preset-small-lib": "^12.0.0",
75+
"@srcset/runtime": "workspace:^",
76+
"@testing-library/dom": "^10.0.0",
77+
"@testing-library/jest-dom": "^6.6.3",
78+
"@testing-library/preact": "^3.2.4",
79+
"happy-dom": "^20.0.0",
80+
"preact": "^10.25.0",
81+
"size-limit": "^12.0.0"
82+
}
83+
}

0 commit comments

Comments
 (0)