Skip to content

Commit 09aa62c

Browse files
committed
feat(imgproxy): add imgproxy runtime srcset builder
1 parent 1a0280b commit 09aa62c

18 files changed

Lines changed: 1022 additions & 0 deletions

‎packages/imgproxy/.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.5 kB"
7+
}
8+
]

‎packages/imgproxy/README.md‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# @srcset/imgproxy
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%2Fimgproxy.svg
15+
[npm-url]: https://npmjs.com/package/@srcset/imgproxy
16+
17+
[node]: https://img.shields.io/node/v/%40srcset%2Fimgproxy.svg
18+
[node-url]: https://nodejs.org
19+
20+
[deps]: https://img.shields.io/librariesio/release/npm/%40srcset%2Fimgproxy
21+
[deps-url]: https://libraries.io/npm/%40srcset%2Fimgproxy
22+
23+
[size]: https://deno.bundlejs.com/badge?q=%40srcset%2Fimgproxy
24+
[size-url]: https://bundlejs.com/?q=%40srcset%2Fimgproxy
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+
Adapter for [imgproxy](https://imgproxy.net/): srcset variant urls for content images, e.g. from an API or a CMS.
33+
34+
- 🌐 Runtime builder of loader-shaped srcset objects, isomorphic: browser and server
35+
- 🔒 Presets support via the `processing` hook - no transformations exposed to the browser
36+
- ✍️ Url signing on the server side
37+
- 🛠 Passthrough mode for local development without a running imgproxy instance
38+
39+
## Install
40+
41+
```bash
42+
# pnpm
43+
pnpm add @srcset/imgproxy @srcset/runtime
44+
# yarn
45+
yarn add @srcset/imgproxy @srcset/runtime
46+
# npm
47+
npm i @srcset/imgproxy @srcset/runtime
48+
```
49+
50+
## Usage
51+
52+
Srcset objects for CMS images:
53+
54+
```ts
55+
import { Imgproxy } from '@srcset/imgproxy'
56+
57+
const imgproxy = new Imgproxy({ endpoint: 'https://imgproxy.example.com' })
58+
const { src, srcSet, srcMap } = imgproxy.image(photo.url, {
59+
width: [600, 1200],
60+
format: ['webp', 'jpg']
61+
})
62+
```
63+
64+
Signed urls, on the server side:
65+
66+
```ts
67+
import { sign } from '@srcset/imgproxy/sign'
68+
69+
const imgproxy = new Imgproxy({
70+
endpoint: 'https://imgproxy.example.com',
71+
signer: sign({ key, salt })
72+
})
73+
```
74+
75+
Passthrough mode - untouched source urls, e.g. for local development without a running imgproxy instance:
76+
77+
```ts
78+
const imgproxy = new Imgproxy({
79+
endpoint: 'https://imgproxy.example.com',
80+
passthrough: import.meta.env.DEV
81+
})
82+
```
83+
84+
## Documentation
85+
86+
For more details, guides and API references, check out the [documentation website](https://srcset.js.org/proxies/imgproxy/).

‎packages/imgproxy/oxlint.config.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig } from '@trigen/oxlint'
2+
import testConfig from '@trigen/oxlint-config/test'
3+
import tsTypeCheckedConfig from '@trigen/oxlint-config/typescript-type-checked'
4+
import rootConfig from '../../oxlint.config.ts'
5+
6+
export default defineConfig({
7+
extends: [
8+
rootConfig,
9+
tsTypeCheckedConfig,
10+
testConfig
11+
],
12+
env: {
13+
node: false,
14+
browser: true
15+
}
16+
})

‎packages/imgproxy/package.json‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "@srcset/imgproxy",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "Adapter for imgproxy: srcset variant urls for content images and static assets.",
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/proxies/imgproxy/",
13+
"funding": "https://ko-fi.com/dangreen",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/TrigenSoftware/srcset.git",
17+
"directory": "packages/imgproxy"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/TrigenSoftware/srcset/issues"
21+
},
22+
"keywords": [
23+
"srcset",
24+
"image",
25+
"responsive",
26+
"imgproxy"
27+
],
28+
"engines": {
29+
"node": ">=22"
30+
},
31+
"sideEffects": false,
32+
"exports": {
33+
"./package.json": "./package.json",
34+
".": "./src/index.ts",
35+
"./sign": "./src/sign.ts"
36+
},
37+
"publishConfig": {
38+
"exports": {
39+
"./package.json": "./package.json",
40+
".": {
41+
"types": "./dist/index.d.ts",
42+
"default": "./dist/index.js"
43+
},
44+
"./sign": {
45+
"types": "./dist/sign.d.ts",
46+
"default": "./dist/sign.js"
47+
}
48+
},
49+
"directory": "package",
50+
"linkDirectory": false
51+
},
52+
"files": [
53+
"dist"
54+
],
55+
"scripts": {
56+
"clear:package": "del ./package",
57+
"clear:dist": "del ./dist",
58+
"clear": "del ./package ./dist ./coverage",
59+
"prepublishOnly": "run build clear:package clean-publish",
60+
"postpublish": "pnpm clear:package",
61+
"emitDeclarations": "tsc -p ./tsconfig.build.json --emitDeclarationOnly",
62+
"build:dist": "run -p emitDeclarations [ vite build ]",
63+
"build": "run clear:dist build:dist",
64+
"lint": "oxlint",
65+
"format": "oxlint --fix",
66+
"test:unit": "vitest run --coverage",
67+
"test:unit:watch": "vitest watch",
68+
"test:size": "size-limit",
69+
"test:types": "tsc --noEmit",
70+
"test": "run -p lint test:unit test:types"
71+
},
72+
"peerDependencies": {
73+
"@srcset/runtime": "workspace:^"
74+
},
75+
"devDependencies": {
76+
"@size-limit/preset-small-lib": "^12.0.0",
77+
"@srcset/runtime": "workspace:^",
78+
"@types/node": "^22.0.0",
79+
"sharp": "^0.35.3",
80+
"size-limit": "^12.0.0"
81+
}
82+
}

0 commit comments

Comments
 (0)