@nonphoto/sanity-image 2.0.1 → 2.1.0
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/dist/index.d.ts +153 -3
- package/package.json +1 -1
- package/src/index.ts +6 -17
- package/src/types.ts +208 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type ImageUrlBuilderOptions = Partial<SanityProjectDetails> & {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
source?: SanityImageSource;
|
|
4
|
+
bg?: string;
|
|
5
|
+
dpr?: number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
focalPoint?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
maxHeight?: number;
|
|
14
|
+
minWidth?: number;
|
|
15
|
+
minHeight?: number;
|
|
16
|
+
blur?: number;
|
|
17
|
+
sharpen?: number;
|
|
18
|
+
rect?: {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
format?: ImageFormat;
|
|
25
|
+
invert?: boolean;
|
|
26
|
+
orientation?: Orientation;
|
|
27
|
+
quality?: number;
|
|
28
|
+
download?: boolean | string;
|
|
29
|
+
flipHorizontal?: boolean;
|
|
30
|
+
flipVertical?: boolean;
|
|
31
|
+
ignoreImageParams?: boolean;
|
|
32
|
+
fit?: FitMode;
|
|
33
|
+
crop?: CropMode;
|
|
34
|
+
saturation?: number;
|
|
35
|
+
auto?: AutoMode;
|
|
36
|
+
pad?: number;
|
|
37
|
+
vanityName?: string;
|
|
38
|
+
frame?: number;
|
|
39
|
+
};
|
|
40
|
+
type ImageUrlBuilderOptionsWithAliases = ImageUrlBuilderOptions & {
|
|
41
|
+
w?: number;
|
|
42
|
+
h?: number;
|
|
43
|
+
q?: number;
|
|
44
|
+
fm?: number;
|
|
45
|
+
dl?: boolean | string;
|
|
46
|
+
or?: Orientation;
|
|
47
|
+
sharp?: number;
|
|
48
|
+
"min-h"?: number;
|
|
49
|
+
"max-h"?: number;
|
|
50
|
+
"min-w"?: number;
|
|
51
|
+
"max-w"?: number;
|
|
52
|
+
sat?: number;
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
};
|
|
55
|
+
type ImageUrlBuilderOptionsWithAsset = ImageUrlBuilderOptions & {
|
|
56
|
+
asset: {
|
|
57
|
+
id: string;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
format: string;
|
|
61
|
+
};
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
};
|
|
64
|
+
type ImageFormat = "jpg" | "pjpg" | "png" | "webp";
|
|
65
|
+
type FitMode = "clip" | "crop" | "fill" | "fillmax" | "max" | "scale" | "min";
|
|
66
|
+
type CropMode = "top" | "bottom" | "left" | "right" | "center" | "focalpoint" | "entropy";
|
|
67
|
+
type AutoMode = "format";
|
|
68
|
+
type Orientation = 0 | 90 | 180 | 270;
|
|
69
|
+
interface SanityClientLike {
|
|
70
|
+
clientConfig: {
|
|
71
|
+
dataset?: string;
|
|
72
|
+
projectId?: string;
|
|
73
|
+
apiHost?: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
type SanityModernClientLike = {
|
|
77
|
+
config(): {
|
|
78
|
+
dataset?: string;
|
|
79
|
+
projectId?: string;
|
|
80
|
+
apiHost?: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
declare type SanityImageSource = string | SanityReference | SanityAsset | SanityImageObject | SanityImageWithAssetStub;
|
|
84
|
+
interface SanityProjectDetails {
|
|
85
|
+
baseUrl?: string;
|
|
86
|
+
projectId: string;
|
|
87
|
+
dataset: string;
|
|
88
|
+
}
|
|
89
|
+
interface SanityReference {
|
|
90
|
+
_ref: string;
|
|
91
|
+
}
|
|
92
|
+
interface SanityImageWithAssetStub {
|
|
93
|
+
asset: {
|
|
94
|
+
url: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
interface SanityAsset {
|
|
98
|
+
_id?: string;
|
|
99
|
+
url?: string;
|
|
100
|
+
path?: string;
|
|
101
|
+
assetId?: string;
|
|
102
|
+
extension?: string;
|
|
103
|
+
[key: string]: any;
|
|
104
|
+
}
|
|
105
|
+
interface SanityImageDimensions {
|
|
106
|
+
aspectRatio: number;
|
|
107
|
+
height: number;
|
|
108
|
+
width: number;
|
|
109
|
+
}
|
|
110
|
+
interface SanityImageFitResult {
|
|
111
|
+
width?: number;
|
|
112
|
+
height?: number;
|
|
113
|
+
rect: SanityImageRect;
|
|
114
|
+
}
|
|
115
|
+
interface SanityImageRect {
|
|
116
|
+
left: number;
|
|
117
|
+
top: number;
|
|
118
|
+
width: number;
|
|
119
|
+
height: number;
|
|
120
|
+
}
|
|
121
|
+
interface SanityImageCrop {
|
|
122
|
+
_type?: string;
|
|
123
|
+
left: number;
|
|
124
|
+
bottom: number;
|
|
125
|
+
right: number;
|
|
126
|
+
top: number;
|
|
127
|
+
}
|
|
128
|
+
interface SanityImageHotspot {
|
|
129
|
+
_type?: string;
|
|
130
|
+
width: number;
|
|
131
|
+
height: number;
|
|
132
|
+
x: number;
|
|
133
|
+
y: number;
|
|
134
|
+
}
|
|
135
|
+
interface SanityImageObject {
|
|
136
|
+
asset: SanityReference | SanityAsset;
|
|
137
|
+
crop?: SanityImageCrop;
|
|
138
|
+
hotspot?: SanityImageHotspot;
|
|
139
|
+
}
|
|
140
|
+
interface CropSpec {
|
|
141
|
+
left: number;
|
|
142
|
+
top: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}
|
|
146
|
+
interface HotspotSpec {
|
|
147
|
+
left: number;
|
|
148
|
+
top: number;
|
|
149
|
+
right: number;
|
|
150
|
+
bottom: number;
|
|
151
|
+
}
|
|
3
152
|
interface SanityImageObjectLike extends Pick<SanityImageObject, "asset"> {
|
|
4
153
|
[key: string]: any;
|
|
5
154
|
}
|
|
@@ -12,6 +161,7 @@ interface Size {
|
|
|
12
161
|
width: number;
|
|
13
162
|
height: number;
|
|
14
163
|
}
|
|
164
|
+
|
|
15
165
|
declare const defaultWidths: number[];
|
|
16
166
|
declare const defaultWidth = 1280;
|
|
17
167
|
declare const defaultQuality = 90;
|
|
@@ -55,4 +205,4 @@ declare function imageMetadata(source: SanityImageSource): SanityImageMetadata |
|
|
|
55
205
|
declare function imageCroppedSize(source: SanityImageSource): Size | undefined;
|
|
56
206
|
declare function imageAspectRatio(source: SanityImageSource): number | undefined;
|
|
57
207
|
|
|
58
|
-
export { type ImageSrcOptions, type ImageSrcsetOptions, type SanityImageMetadata, type SanityImageObjectLike, type Size, aspectRatio, croppedSize, defaultQuality, defaultWidth, defaultWidths, fit, fitComparators, imageAlt, imageAspectRatio, imageCroppedSize, imageMetadata, imageSrc, imageSrcset, isAsset, isCrop, isDimensions, isHotspot, isImageObject, isImageObjectLike, isMetadata, isReference, isSize };
|
|
208
|
+
export { type AutoMode, type CropMode, type CropSpec, type FitMode, type HotspotSpec, type ImageFormat, type ImageSrcOptions, type ImageSrcsetOptions, type ImageUrlBuilderOptions, type ImageUrlBuilderOptionsWithAliases, type ImageUrlBuilderOptionsWithAsset, type Orientation, type SanityAsset, type SanityClientLike, type SanityImageCrop, type SanityImageDimensions, type SanityImageFitResult, type SanityImageHotspot, type SanityImageMetadata, type SanityImageObject, type SanityImageObjectLike, type SanityImageRect, type SanityImageSource, type SanityImageWithAssetStub, type SanityModernClientLike, type SanityProjectDetails, type SanityReference, type Size, aspectRatio, croppedSize, defaultQuality, defaultWidth, defaultWidths, fit, fitComparators, imageAlt, imageAspectRatio, imageCroppedSize, imageMetadata, imageSrc, imageSrcset, isAsset, isCrop, isDimensions, isHotspot, isImageObject, isImageObjectLike, isMetadata, isReference, isSize };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
import imageUrlBuilder from "@sanity/image-url";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
3
|
SanityAsset,
|
|
4
4
|
SanityClientLike,
|
|
5
5
|
SanityImageCrop,
|
|
6
6
|
SanityImageDimensions,
|
|
7
7
|
SanityImageHotspot,
|
|
8
|
+
SanityImageMetadata,
|
|
8
9
|
SanityImageObject,
|
|
10
|
+
SanityImageObjectLike,
|
|
9
11
|
SanityImageSource,
|
|
10
12
|
SanityModernClientLike,
|
|
11
13
|
SanityProjectDetails,
|
|
12
14
|
SanityReference,
|
|
13
|
-
|
|
15
|
+
Size,
|
|
16
|
+
} from "./types";
|
|
14
17
|
|
|
15
|
-
export
|
|
16
|
-
extends Pick<SanityImageObject, "asset"> {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SanityImageMetadata {
|
|
21
|
-
lqip?: string;
|
|
22
|
-
dimensions?: SanityImageDimensions;
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface Size {
|
|
27
|
-
width: number;
|
|
28
|
-
height: number;
|
|
29
|
-
}
|
|
18
|
+
export * from "./types";
|
|
30
19
|
|
|
31
20
|
export const defaultWidths = [
|
|
32
21
|
6016, // 6K
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
export type ImageUrlBuilderOptions = Partial<SanityProjectDetails> & {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
source?: SanityImageSource;
|
|
4
|
+
bg?: string;
|
|
5
|
+
dpr?: number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
focalPoint?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
maxHeight?: number;
|
|
14
|
+
minWidth?: number;
|
|
15
|
+
minHeight?: number;
|
|
16
|
+
blur?: number;
|
|
17
|
+
sharpen?: number;
|
|
18
|
+
rect?: {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
format?: ImageFormat;
|
|
25
|
+
invert?: boolean;
|
|
26
|
+
orientation?: Orientation;
|
|
27
|
+
quality?: number;
|
|
28
|
+
download?: boolean | string;
|
|
29
|
+
flipHorizontal?: boolean;
|
|
30
|
+
flipVertical?: boolean;
|
|
31
|
+
ignoreImageParams?: boolean;
|
|
32
|
+
fit?: FitMode;
|
|
33
|
+
crop?: CropMode;
|
|
34
|
+
saturation?: number;
|
|
35
|
+
auto?: AutoMode;
|
|
36
|
+
pad?: number;
|
|
37
|
+
vanityName?: string;
|
|
38
|
+
frame?: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ImageUrlBuilderOptionsWithAliases = ImageUrlBuilderOptions & {
|
|
42
|
+
w?: number;
|
|
43
|
+
h?: number;
|
|
44
|
+
q?: number;
|
|
45
|
+
fm?: number;
|
|
46
|
+
dl?: boolean | string;
|
|
47
|
+
or?: Orientation;
|
|
48
|
+
sharp?: number;
|
|
49
|
+
"min-h"?: number;
|
|
50
|
+
"max-h"?: number;
|
|
51
|
+
"min-w"?: number;
|
|
52
|
+
"max-w"?: number;
|
|
53
|
+
sat?: number;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type ImageUrlBuilderOptionsWithAsset = ImageUrlBuilderOptions & {
|
|
58
|
+
asset: {
|
|
59
|
+
id: string;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
format: string;
|
|
63
|
+
};
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ImageFormat = "jpg" | "pjpg" | "png" | "webp";
|
|
68
|
+
|
|
69
|
+
export type FitMode =
|
|
70
|
+
| "clip"
|
|
71
|
+
| "crop"
|
|
72
|
+
| "fill"
|
|
73
|
+
| "fillmax"
|
|
74
|
+
| "max"
|
|
75
|
+
| "scale"
|
|
76
|
+
| "min";
|
|
77
|
+
|
|
78
|
+
export type CropMode =
|
|
79
|
+
| "top"
|
|
80
|
+
| "bottom"
|
|
81
|
+
| "left"
|
|
82
|
+
| "right"
|
|
83
|
+
| "center"
|
|
84
|
+
| "focalpoint"
|
|
85
|
+
| "entropy";
|
|
86
|
+
|
|
87
|
+
export type AutoMode = "format";
|
|
88
|
+
|
|
89
|
+
export type Orientation = 0 | 90 | 180 | 270;
|
|
90
|
+
|
|
91
|
+
export interface SanityClientLike {
|
|
92
|
+
clientConfig: {
|
|
93
|
+
dataset?: string;
|
|
94
|
+
projectId?: string;
|
|
95
|
+
apiHost?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type SanityModernClientLike = {
|
|
100
|
+
config(): {
|
|
101
|
+
dataset?: string;
|
|
102
|
+
projectId?: string;
|
|
103
|
+
apiHost?: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export declare type SanityImageSource =
|
|
108
|
+
| string
|
|
109
|
+
| SanityReference
|
|
110
|
+
| SanityAsset
|
|
111
|
+
| SanityImageObject
|
|
112
|
+
| SanityImageWithAssetStub;
|
|
113
|
+
|
|
114
|
+
export interface SanityProjectDetails {
|
|
115
|
+
baseUrl?: string;
|
|
116
|
+
projectId: string;
|
|
117
|
+
dataset: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface SanityReference {
|
|
121
|
+
_ref: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface SanityImageWithAssetStub {
|
|
125
|
+
asset: {
|
|
126
|
+
url: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface SanityAsset {
|
|
131
|
+
_id?: string;
|
|
132
|
+
url?: string;
|
|
133
|
+
path?: string;
|
|
134
|
+
assetId?: string;
|
|
135
|
+
extension?: string;
|
|
136
|
+
[key: string]: any;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface SanityImageDimensions {
|
|
140
|
+
aspectRatio: number;
|
|
141
|
+
height: number;
|
|
142
|
+
width: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface SanityImageFitResult {
|
|
146
|
+
width?: number;
|
|
147
|
+
height?: number;
|
|
148
|
+
rect: SanityImageRect;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface SanityImageRect {
|
|
152
|
+
left: number;
|
|
153
|
+
top: number;
|
|
154
|
+
width: number;
|
|
155
|
+
height: number;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface SanityImageCrop {
|
|
159
|
+
_type?: string;
|
|
160
|
+
left: number;
|
|
161
|
+
bottom: number;
|
|
162
|
+
right: number;
|
|
163
|
+
top: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface SanityImageHotspot {
|
|
167
|
+
_type?: string;
|
|
168
|
+
width: number;
|
|
169
|
+
height: number;
|
|
170
|
+
x: number;
|
|
171
|
+
y: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface SanityImageObject {
|
|
175
|
+
asset: SanityReference | SanityAsset;
|
|
176
|
+
crop?: SanityImageCrop;
|
|
177
|
+
hotspot?: SanityImageHotspot;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface CropSpec {
|
|
181
|
+
left: number;
|
|
182
|
+
top: number;
|
|
183
|
+
width: number;
|
|
184
|
+
height: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface HotspotSpec {
|
|
188
|
+
left: number;
|
|
189
|
+
top: number;
|
|
190
|
+
right: number;
|
|
191
|
+
bottom: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface SanityImageObjectLike
|
|
195
|
+
extends Pick<SanityImageObject, "asset"> {
|
|
196
|
+
[key: string]: any;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface SanityImageMetadata {
|
|
200
|
+
lqip?: string;
|
|
201
|
+
dimensions?: SanityImageDimensions;
|
|
202
|
+
[key: string]: any;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface Size {
|
|
206
|
+
width: number;
|
|
207
|
+
height: number;
|
|
208
|
+
}
|