Skip to content

Commit 20f85d2

Browse files
committed
refactor: enhance documentation for GetImageAttributesOptions and ResponsiveImageAttributes interfaces
1 parent a86f515 commit 20f85d2

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/getResponsiveImageAttributes.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,42 @@ const DEFAULT_IMAGE_BREAKPOINTS = [16, 32, 48, 64, 96, 128, 256, 384] as const
77

88
export interface GetImageAttributesOptions extends SrcOptions {
99
/**
10-
* The intended display width (in pixels) of the image on screen.
11-
* Used for calculating `srcSet` with a pixel-density (DPR) strategy.
12-
* If omitted, a width-based strategy using breakpoints will be applied.
13-
*/
10+
* The intended display width of the image in pixels,
11+
* used **only when the `sizes` attribute is not provided**.
12+
*
13+
* Triggers a DPR-based strategy (1x and 2x variants) and generates `x` descriptors in `srcSet`.
14+
*
15+
* Ignored if `sizes` is present.
16+
*/
1417
width?: number
1518

1619
/**
17-
* The `sizes` attribute for the image element.
18-
* Typically used to indicate how the image will scale across different viewport sizes (e.g., "100vw").
19-
* Presence of `sizes` triggers a width-based `srcSet` strategy.
20+
* The value for the HTML `sizes` attribute
21+
* (e.g., `"100vw"` or `"(min-width:768px) 50vw, 100vw"`).
22+
*
23+
* - If it includes one or more `vw` units, breakpoints smaller than the corresponding percentage of the smallest device width are excluded.
24+
* - If it contains no `vw` units, the full breakpoint list is used.
25+
*
26+
* Enables a width-based strategy and generates `w` descriptors in `srcSet`.
2027
*/
2128
sizes?: string
2229

2330
/**
24-
* An optional custom list of device width breakpoints (in pixels).
25-
* If not specified, defaults to `[640, 750, 828, 1080, 1200, 1920, 2048, 3840]`.
26-
* Recommended to align with your target audience's common screen widths.
31+
* Custom list of **device-width breakpoints** in pixels.
32+
* These define common screen widths for responsive image generation.
33+
*
34+
* Defaults to `[640, 750, 828, 1080, 1200, 1920, 2048, 3840]`.
35+
* Sorted automatically.
2736
*/
2837
deviceBreakpoints?: number[]
2938

3039
/**
31-
* An optional list of custom image breakpoints (in pixels).
32-
* These are merged with the device breakpoints to compute the final list of candidate widths.
40+
* Custom list of **image-specific breakpoints** in pixels.
41+
* Useful for generating small variants (e.g., placeholders or thumbnails).
42+
*
43+
* Merged with `deviceBreakpoints` before calculating `srcSet`.
3344
* Defaults to `[16, 32, 48, 64, 96, 128, 256, 384]`.
45+
* Sorted automatically.
3446
*/
3547
imageBreakpoints?: number[]
3648
}
@@ -40,9 +52,13 @@ export interface GetImageAttributesOptions extends SrcOptions {
4052
* Useful for enabling responsive image loading.
4153
*/
4254
export interface ResponsiveImageAttributes {
55+
/** URL for the *largest* candidate (assigned to plain `src`). */
4356
src: string
57+
/** Candidate set with `w` or `x` descriptors. */
4458
srcSet?: string
59+
/** `sizes` returned (or synthesised as `100vw`). */
4560
sizes?: string
61+
/** Width as a number (if `width` was provided). */
4662
width?: number
4763
}
4864

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import type { SrcOptions, Transformation, UploadOptions, UploadResponse } from "
22
import { ImageKitAbortError, ImageKitInvalidRequestError, ImageKitServerError, ImageKitUploadNetworkError, upload } from "./upload";
33
import { buildSrc, buildTransformationString } from "./url";
44
import { getResponsiveImageAttributes } from "./getResponsiveImageAttributes";
5+
import type { GetImageAttributesOptions, ResponsiveImageAttributes } from "./getResponsiveImageAttributes";
56

67
export { buildSrc, buildTransformationString, upload, getResponsiveImageAttributes, ImageKitInvalidRequestError, ImageKitAbortError, ImageKitServerError, ImageKitUploadNetworkError };
78
export type {
89
Transformation,
910
SrcOptions,
1011
UploadOptions,
11-
UploadResponse
12+
UploadResponse,
13+
GetImageAttributesOptions, ResponsiveImageAttributes
1214
};

0 commit comments

Comments
 (0)