@pixelfiddler/core 0.1.7 → 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 +149 -26
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,22 +15,23 @@ yarn add @pixelfiddler/core
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { buildTransformationUrl,
|
|
18
|
+
import { buildTransformationUrl, buildTransformationQueryParams } from '@pixelfiddler/core';
|
|
19
19
|
|
|
20
20
|
// Build a complete transformation URL
|
|
21
|
-
const url = buildTransformationUrl(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const url = buildTransformationUrl({
|
|
22
|
+
src: '/images/photo.jpg',
|
|
23
|
+
baseUrl: 'https://cdn.example.com',
|
|
24
|
+
transformations: {
|
|
24
25
|
width: 800,
|
|
25
26
|
height: 600,
|
|
26
|
-
format: '
|
|
27
|
+
format: 'WEBP',
|
|
27
28
|
quality: 85,
|
|
28
29
|
}
|
|
29
|
-
);
|
|
30
|
-
// => 'https://example
|
|
30
|
+
});
|
|
31
|
+
// => 'https://cdn.example.com/images/photo.jpg?w=800&h=600&f=WEBP&q=85'
|
|
31
32
|
|
|
32
33
|
// Or just get the query string
|
|
33
|
-
const params =
|
|
34
|
+
const params = buildTransformationQueryParams({
|
|
34
35
|
width: 400,
|
|
35
36
|
blur: 5,
|
|
36
37
|
grayscale: true,
|
|
@@ -40,25 +41,83 @@ const params = buildQueryParams({
|
|
|
40
41
|
|
|
41
42
|
## API
|
|
42
43
|
|
|
43
|
-
### `buildTransformationUrl(config
|
|
44
|
+
### `buildTransformationUrl(config)`
|
|
44
45
|
|
|
45
46
|
Builds a complete transformation URL.
|
|
46
47
|
|
|
48
|
+
```typescript
|
|
49
|
+
buildTransformationUrl({
|
|
50
|
+
src: '/photo.jpg',
|
|
51
|
+
baseUrl: 'https://cdn.example.com',
|
|
52
|
+
transformations: { width: 800, format: 'WEBP' },
|
|
53
|
+
mode: 'short' // optional, default: 'short'
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
47
57
|
| Parameter | Type | Description |
|
|
48
58
|
|-----------|------|-------------|
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
59
|
+
| `src` | `string` | Relative or absolute path to the image |
|
|
60
|
+
| `baseUrl` | `string` | Base URL endpoint from PixelFiddler Dashboard |
|
|
61
|
+
| `transformations` | `TransformationOptions` | Transformation options |
|
|
51
62
|
| `mode` | `'short' \| 'long'` | Parameter naming mode (default: `'short'`) |
|
|
52
63
|
|
|
53
|
-
### `
|
|
64
|
+
### `buildTransformationQueryParams(options, mode?)`
|
|
54
65
|
|
|
55
66
|
Converts transformation options to a URL-encoded query string.
|
|
56
67
|
|
|
68
|
+
```typescript
|
|
69
|
+
buildTransformationQueryParams({ width: 800, format: 'WEBP' });
|
|
70
|
+
// => 'w=800&f=WEBP'
|
|
71
|
+
|
|
72
|
+
buildTransformationQueryParams({ width: 800 }, 'long');
|
|
73
|
+
// => 'width=800'
|
|
74
|
+
```
|
|
75
|
+
|
|
57
76
|
| Parameter | Type | Description |
|
|
58
77
|
|-----------|------|-------------|
|
|
59
78
|
| `options` | `TransformationOptions` | Transformation options |
|
|
60
79
|
| `mode` | `'short' \| 'long'` | Parameter naming mode (default: `'short'`) |
|
|
61
80
|
|
|
81
|
+
### `createResponsiveAttributes(src, baseUrl?, options?)`
|
|
82
|
+
|
|
83
|
+
Generates responsive image attributes (src, srcSet, sizes) for optimal loading.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { createResponsiveAttributes } from '@pixelfiddler/core';
|
|
87
|
+
|
|
88
|
+
// Responsive image with sizes (uses `w` descriptors)
|
|
89
|
+
createResponsiveAttributes('/photo.jpg', 'https://cdn.example.com', {
|
|
90
|
+
sizes: '(max-width: 768px) 100vw, 50vw',
|
|
91
|
+
transformations: { format: 'WEBP' }
|
|
92
|
+
});
|
|
93
|
+
// => {
|
|
94
|
+
// src: '...?w=3840&f=WEBP',
|
|
95
|
+
// srcSet: '...?w=640&f=WEBP 640w, ...?w=1024&f=WEBP 1024w, ...',
|
|
96
|
+
// sizes: '(max-width: 768px) 100vw, 50vw'
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// Fixed-width image (uses `x` descriptors for DPR)
|
|
100
|
+
createResponsiveAttributes('/photo.jpg', 'https://cdn.example.com', {
|
|
101
|
+
width: 400
|
|
102
|
+
});
|
|
103
|
+
// => {
|
|
104
|
+
// src: '...?w=384',
|
|
105
|
+
// srcSet: '...?w=384 1x, ...?w=828 2x',
|
|
106
|
+
// width: 400
|
|
107
|
+
// }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Parameter | Type | Description |
|
|
111
|
+
|-----------|------|-------------|
|
|
112
|
+
| `src` | `string` | Relative or absolute path to the image |
|
|
113
|
+
| `baseUrl` | `string` | Base URL endpoint from PixelFiddler Dashboard |
|
|
114
|
+
| `options.sizes` | `string` | Sizes attribute for responsive layouts |
|
|
115
|
+
| `options.width` | `number` | Fixed display width (generates DPR variants) |
|
|
116
|
+
| `options.deviceBreakpoints` | `number[]` | Custom device breakpoints |
|
|
117
|
+
| `options.imageBreakpoints` | `number[]` | Custom image breakpoints |
|
|
118
|
+
| `options.transformations` | `TransformationOptions` | Base transformations to apply |
|
|
119
|
+
| `options.maxDpr` | `number` | Maximum DPR to support (default: 2) |
|
|
120
|
+
|
|
62
121
|
## Transformation Options
|
|
63
122
|
|
|
64
123
|
### Resize
|
|
@@ -68,7 +127,7 @@ Converts transformation options to a URL-encoded query string.
|
|
|
68
127
|
width: 800, // Target width (px)
|
|
69
128
|
height: 600, // Target height (px)
|
|
70
129
|
dpr: 2, // Device pixel ratio (1-4)
|
|
71
|
-
mode: 'FIT', // 'FILL' | 'FIT' | 'PAD'
|
|
130
|
+
mode: 'FIT', // 'FILL' | 'FIT' | 'PAD'
|
|
72
131
|
background: '#ffffff' // Background color for PAD mode
|
|
73
132
|
}
|
|
74
133
|
```
|
|
@@ -77,7 +136,7 @@ Converts transformation options to a URL-encoded query string.
|
|
|
77
136
|
|
|
78
137
|
```typescript
|
|
79
138
|
{
|
|
80
|
-
format: '
|
|
139
|
+
format: 'WEBP', // 'JPG' | 'PNG' | 'WEBP' | 'AVIF' | 'GIF'
|
|
81
140
|
quality: 80, // 1-100
|
|
82
141
|
stripMetadata: true // Remove EXIF data
|
|
83
142
|
}
|
|
@@ -106,7 +165,7 @@ Converts transformation options to a URL-encoded query string.
|
|
|
106
165
|
border: {
|
|
107
166
|
width: 2, // Border width (px)
|
|
108
167
|
color: '#000000', // Border color
|
|
109
|
-
radius: 8 // Corner radius (px)
|
|
168
|
+
radius: 8 // Corner radius (px, 1-2000)
|
|
110
169
|
}
|
|
111
170
|
}
|
|
112
171
|
```
|
|
@@ -114,20 +173,42 @@ Converts transformation options to a URL-encoded query string.
|
|
|
114
173
|
### Crop
|
|
115
174
|
|
|
116
175
|
```typescript
|
|
176
|
+
// Simple crop with auto focus
|
|
117
177
|
{
|
|
118
178
|
crop: {
|
|
119
|
-
type: 'SIMPLE',
|
|
120
|
-
objectType: 'FACE', // 'FACE' | 'UPPER_BODY' (for OBJECT type)
|
|
179
|
+
type: 'SIMPLE',
|
|
121
180
|
width: 400,
|
|
122
181
|
height: 300,
|
|
123
182
|
focus: {
|
|
124
|
-
type: 'AUTO',
|
|
125
|
-
strategy: 'SMART'
|
|
126
|
-
position: { x: 50, y: 50 } // For SPECIFIED type
|
|
183
|
+
type: 'AUTO',
|
|
184
|
+
strategy: 'SMART' // 'CENTER' | 'SMART' | 'DETAIL'
|
|
127
185
|
},
|
|
128
186
|
afterResize: true
|
|
129
187
|
}
|
|
130
188
|
}
|
|
189
|
+
|
|
190
|
+
// Simple crop with specified position
|
|
191
|
+
{
|
|
192
|
+
crop: {
|
|
193
|
+
type: 'SIMPLE',
|
|
194
|
+
width: 400,
|
|
195
|
+
height: 300,
|
|
196
|
+
focus: {
|
|
197
|
+
type: 'SPECIFIED',
|
|
198
|
+
position: { x: 50, y: 50 }
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Object detection crop
|
|
204
|
+
{
|
|
205
|
+
crop: {
|
|
206
|
+
type: 'OBJECT',
|
|
207
|
+
objectType: 'FACE', // 'FACE' | 'UPPER_BODY'
|
|
208
|
+
width: 400,
|
|
209
|
+
height: 300
|
|
210
|
+
}
|
|
211
|
+
}
|
|
131
212
|
```
|
|
132
213
|
|
|
133
214
|
### Text Overlay
|
|
@@ -137,11 +218,11 @@ Converts transformation options to a URL-encoded query string.
|
|
|
137
218
|
text: {
|
|
138
219
|
text: 'Hello World',
|
|
139
220
|
color: '#ffffff',
|
|
140
|
-
opacity: 80,
|
|
141
|
-
size: 50,
|
|
221
|
+
opacity: 80, // 0-100
|
|
222
|
+
size: 50, // Size as percentage (1-100)
|
|
142
223
|
font: 'Arial',
|
|
143
|
-
fontSize: 24,
|
|
144
|
-
position: 'CENTER',
|
|
224
|
+
fontSize: 24, // Font size in pixels
|
|
225
|
+
position: 'CENTER', // Position constant
|
|
145
226
|
background: '#000000',
|
|
146
227
|
backgroundOpacity: 50
|
|
147
228
|
}
|
|
@@ -163,6 +244,17 @@ Converts transformation options to a URL-encoded query string.
|
|
|
163
244
|
}
|
|
164
245
|
```
|
|
165
246
|
|
|
247
|
+
### Position Values
|
|
248
|
+
|
|
249
|
+
For `text.position` and `watermark.position`:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
'TOP_LEFT' | 'TOP' | 'TOP_RIGHT' |
|
|
253
|
+
'LEFT' | 'CENTER' | 'RIGHT' |
|
|
254
|
+
'BOTTOM_LEFT' | 'BOTTOM' | 'BOTTOM_RIGHT' |
|
|
255
|
+
'AUTO'
|
|
256
|
+
```
|
|
257
|
+
|
|
166
258
|
### Special Options
|
|
167
259
|
|
|
168
260
|
```typescript
|
|
@@ -188,7 +280,7 @@ By default, short parameter names are used for smaller URLs:
|
|
|
188
280
|
Use `mode: 'long'` for full parameter names:
|
|
189
281
|
|
|
190
282
|
```typescript
|
|
191
|
-
|
|
283
|
+
buildTransformationQueryParams({ width: 800 }, 'long');
|
|
192
284
|
// => 'width=800'
|
|
193
285
|
```
|
|
194
286
|
|
|
@@ -198,12 +290,43 @@ Full TypeScript support with exported types:
|
|
|
198
290
|
|
|
199
291
|
```typescript
|
|
200
292
|
import type {
|
|
293
|
+
// Main options
|
|
201
294
|
TransformationOptions,
|
|
295
|
+
PixelFiddlerConfig,
|
|
296
|
+
UrlBuilderConfig,
|
|
297
|
+
BuildTransformationConfig,
|
|
298
|
+
|
|
299
|
+
// Resize
|
|
202
300
|
ResizeOptions,
|
|
301
|
+
ResizeMode,
|
|
302
|
+
DevicePixelRatio,
|
|
303
|
+
|
|
304
|
+
// Format
|
|
305
|
+
FormatOptions,
|
|
306
|
+
ImageFormat,
|
|
307
|
+
|
|
308
|
+
// Effects
|
|
309
|
+
EffectOptions,
|
|
310
|
+
RotationAngle,
|
|
311
|
+
|
|
312
|
+
// Border
|
|
313
|
+
BorderOptions,
|
|
314
|
+
HexColor,
|
|
315
|
+
|
|
316
|
+
// Crop
|
|
203
317
|
CropOptions,
|
|
318
|
+
SimpleCropOptions,
|
|
319
|
+
ObjectCropOptions,
|
|
320
|
+
CropFocusOptions,
|
|
321
|
+
CropType,
|
|
322
|
+
CropFocus,
|
|
323
|
+
CropFocusStrategy,
|
|
324
|
+
CropObjectType,
|
|
325
|
+
|
|
326
|
+
// Overlays
|
|
204
327
|
TextOptions,
|
|
205
328
|
WatermarkOptions,
|
|
206
|
-
|
|
329
|
+
Position,
|
|
207
330
|
} from '@pixelfiddler/core';
|
|
208
331
|
```
|
|
209
332
|
|
package/dist/index.d.cts
CHANGED
|
@@ -79,7 +79,7 @@ type ObjectValue<T> = T[keyof T];
|
|
|
79
79
|
/**
|
|
80
80
|
* Resize mode for image transformations
|
|
81
81
|
*/
|
|
82
|
-
type ResizeMode = 'FILL' | 'FIT' | 'PAD'
|
|
82
|
+
type ResizeMode = 'FILL' | 'FIT' | 'PAD';
|
|
83
83
|
/**
|
|
84
84
|
* Output image format - null or empty means AUTO
|
|
85
85
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -79,7 +79,7 @@ type ObjectValue<T> = T[keyof T];
|
|
|
79
79
|
/**
|
|
80
80
|
* Resize mode for image transformations
|
|
81
81
|
*/
|
|
82
|
-
type ResizeMode = 'FILL' | 'FIT' | 'PAD'
|
|
82
|
+
type ResizeMode = 'FILL' | 'FIT' | 'PAD';
|
|
83
83
|
/**
|
|
84
84
|
* Output image format - null or empty means AUTO
|
|
85
85
|
*/
|