@pixelfiddler/next 0.1.2 → 1.0.1
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 +239 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1 +1,239 @@
|
|
|
1
|
-
|
|
1
|
+
# @pixelfiddler/next
|
|
2
|
+
|
|
3
|
+
Next.js image component for [PixelFiddler](https://pixel-fiddler.com) image transformations. A drop-in wrapper around `next/image` with automatic optimization through PixelFiddler CDN.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pixelfiddler/next
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @pixelfiddler/next
|
|
11
|
+
# or
|
|
12
|
+
yarn add @pixelfiddler/next
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Note:** This package requires `next` >= 13.0.0 and `react` >= 18.2.0 as peer dependencies.
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { PixelFiddlerImage } from '@pixelfiddler/next';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<PixelFiddlerImage
|
|
25
|
+
src="https://example.com/photo.jpg"
|
|
26
|
+
alt="A beautiful photo"
|
|
27
|
+
width={800}
|
|
28
|
+
height={600}
|
|
29
|
+
transformations={{ format: 'WEBP', quality: 80 }}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Components
|
|
36
|
+
|
|
37
|
+
### `PixelFiddlerImage`
|
|
38
|
+
|
|
39
|
+
A wrapper around Next.js `Image` component that uses PixelFiddler as the image loader for automatic optimization.
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { PixelFiddlerImage } from '@pixelfiddler/next';
|
|
43
|
+
|
|
44
|
+
// Basic usage with dimensions
|
|
45
|
+
<PixelFiddlerImage
|
|
46
|
+
src="https://example.com/photo.jpg"
|
|
47
|
+
alt="Profile photo"
|
|
48
|
+
width={400}
|
|
49
|
+
height={300}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
// Fill container
|
|
53
|
+
<PixelFiddlerImage
|
|
54
|
+
src="https://example.com/photo.jpg"
|
|
55
|
+
alt="Hero image"
|
|
56
|
+
fill
|
|
57
|
+
sizes="(max-width: 768px) 100vw, 50vw"
|
|
58
|
+
/>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Props
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Default | Description |
|
|
64
|
+
|------|------|---------|-------------|
|
|
65
|
+
| `src` | `string` | **required** | URL of the image (relative or absolute). Relative paths are attached to `baseUrl` |
|
|
66
|
+
| `baseUrl` | `string` | - | Base URL endpoint from PixelFiddler Dashboard. Can be set via `PixelFiddlerProvider` |
|
|
67
|
+
| `sizes` | `string` | - | Sizes attribute for responsive images (e.g., `"(max-width: 768px) 100vw, 50vw"`) |
|
|
68
|
+
| `responsive` | `boolean` | `true` | Enable automatic srcset generation via PixelFiddler loader |
|
|
69
|
+
| `transformations` | `TransformationOptions` | - | Image transformation options |
|
|
70
|
+
|
|
71
|
+
All standard Next.js `Image` props (`width`, `height`, `fill`, `quality`, `priority`, `placeholder`, `unoptimized`, `className`, etc.) are also supported.
|
|
72
|
+
|
|
73
|
+
### `PixelFiddlerProvider`
|
|
74
|
+
|
|
75
|
+
A context provider for sharing configuration across all `PixelFiddlerImage` components.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { PixelFiddlerProvider, PixelFiddlerImage } from '@pixelfiddler/next';
|
|
79
|
+
|
|
80
|
+
function App() {
|
|
81
|
+
return (
|
|
82
|
+
<PixelFiddlerProvider config={{ baseUrl: 'https://cdn.example.com' }}>
|
|
83
|
+
<PixelFiddlerImage src="/photos/hero.jpg" alt="Hero" fill sizes="100vw" />
|
|
84
|
+
<PixelFiddlerImage src="/photos/thumb.jpg" alt="Thumbnail" width={200} height={200} />
|
|
85
|
+
</PixelFiddlerProvider>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Props
|
|
91
|
+
|
|
92
|
+
| Prop | Type | Description |
|
|
93
|
+
|------|------|-------------|
|
|
94
|
+
| `config` | `PixelFiddlerConfig` | Configuration object with `baseUrl` and optional `maxDpr` |
|
|
95
|
+
| `children` | `ReactNode` | Child components |
|
|
96
|
+
|
|
97
|
+
## Usage Examples
|
|
98
|
+
|
|
99
|
+
### Basic Transformations
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
<PixelFiddlerImage
|
|
103
|
+
src="https://example.com/photo.jpg"
|
|
104
|
+
alt="Transformed image"
|
|
105
|
+
width={800}
|
|
106
|
+
height={600}
|
|
107
|
+
transformations={{
|
|
108
|
+
format: 'WEBP',
|
|
109
|
+
quality: 85,
|
|
110
|
+
blur: 10,
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Fill Container
|
|
116
|
+
|
|
117
|
+
Use `fill` prop for images that should fill their parent container:
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
<div style={{ position: 'relative', width: '100%', height: '400px' }}>
|
|
121
|
+
<PixelFiddlerImage
|
|
122
|
+
src="https://example.com/hero.jpg"
|
|
123
|
+
alt="Hero banner"
|
|
124
|
+
fill
|
|
125
|
+
sizes="100vw"
|
|
126
|
+
style={{ objectFit: 'cover' }}
|
|
127
|
+
transformations={{ format: 'WEBP' }}
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Priority Loading
|
|
133
|
+
|
|
134
|
+
For above-the-fold images, use `priority` to preload:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
<PixelFiddlerImage
|
|
138
|
+
src="https://example.com/hero.jpg"
|
|
139
|
+
alt="Hero image"
|
|
140
|
+
width={1200}
|
|
141
|
+
height={600}
|
|
142
|
+
priority
|
|
143
|
+
transformations={{ format: 'WEBP' }}
|
|
144
|
+
/>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Disable Responsive Behavior
|
|
148
|
+
|
|
149
|
+
When `responsive` is false, the image URL is built with exact transformations and no srcset is generated:
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
<PixelFiddlerImage
|
|
153
|
+
src="https://example.com/photo.jpg"
|
|
154
|
+
alt="Non-responsive"
|
|
155
|
+
width={400}
|
|
156
|
+
height={300}
|
|
157
|
+
responsive={false}
|
|
158
|
+
transformations={{ width: 400, height: 300, format: 'WEBP' }}
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Unoptimized Images
|
|
163
|
+
|
|
164
|
+
Skip the PixelFiddler loader entirely:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
<PixelFiddlerImage
|
|
168
|
+
src="https://example.com/photo.jpg"
|
|
169
|
+
alt="Unoptimized"
|
|
170
|
+
width={400}
|
|
171
|
+
height={300}
|
|
172
|
+
unoptimized
|
|
173
|
+
/>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### With Quality Override
|
|
177
|
+
|
|
178
|
+
The `quality` prop is passed to transformations:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
<PixelFiddlerImage
|
|
182
|
+
src="https://example.com/photo.jpg"
|
|
183
|
+
alt="High quality"
|
|
184
|
+
width={800}
|
|
185
|
+
height={600}
|
|
186
|
+
quality={95}
|
|
187
|
+
/>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Responsive Sizes
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
<PixelFiddlerImage
|
|
194
|
+
src="https://example.com/photo.jpg"
|
|
195
|
+
alt="Responsive image"
|
|
196
|
+
fill
|
|
197
|
+
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
|
198
|
+
transformations={{ format: 'WEBP' }}
|
|
199
|
+
/>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## How It Works
|
|
203
|
+
|
|
204
|
+
The component uses a custom Next.js image loader that:
|
|
205
|
+
|
|
206
|
+
1. Receives width requests from Next.js's responsive image system
|
|
207
|
+
2. Builds PixelFiddler transformation URLs with the requested width
|
|
208
|
+
3. Applies any additional transformations you specify
|
|
209
|
+
|
|
210
|
+
This means Next.js handles the responsive `srcset` generation while PixelFiddler handles the actual image transformations and delivery.
|
|
211
|
+
|
|
212
|
+
## TypeScript
|
|
213
|
+
|
|
214
|
+
Full TypeScript support with exported types:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import type {
|
|
218
|
+
PixelFiddlerImageProps,
|
|
219
|
+
PixelFiddlerContextValue,
|
|
220
|
+
TransformationOptions,
|
|
221
|
+
ResizeOptions,
|
|
222
|
+
FormatOptions,
|
|
223
|
+
EffectOptions,
|
|
224
|
+
CropOptions,
|
|
225
|
+
BorderOptions,
|
|
226
|
+
TextOptions,
|
|
227
|
+
WatermarkOptions,
|
|
228
|
+
PixelFiddlerConfig,
|
|
229
|
+
} from '@pixelfiddler/next';
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Related
|
|
233
|
+
|
|
234
|
+
- [@pixelfiddler/core](https://www.npmjs.com/package/@pixelfiddler/core) - Core utilities for building transformation URLs
|
|
235
|
+
- [@pixelfiddler/react](https://www.npmjs.com/package/@pixelfiddler/react) - React components for non-Next.js projects
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixelfiddler/next",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Next.js image component and loader for PixelFiddler image transformation SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@pixelfiddler/core": "0.
|
|
25
|
+
"@pixelfiddler/core": "1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"next": ">=13.0.0",
|
|
29
|
-
"react": ">=18.
|
|
29
|
+
"react": ">=18.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@testing-library/react": "^16.3.2",
|