@kiln-js/image 0.0.0-stage → 0.3.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/README.md +42 -2
- package/dist/index.d.ts +364 -0
- package/dist/index.js +232 -0
- package/package.json +27 -6
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kiln-js/image
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@kiln-js/image)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Part of the Kiln framework.
|
|
7
|
+
|
|
8
|
+
Part of [Kiln](https://github.com/kiln-js/kiln), a file-based server-side rendering framework for React and Vite.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bun add @kiln-js/image
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { Image } from "@kiln-js/image";
|
|
20
|
+
|
|
21
|
+
export default function Hero() {
|
|
22
|
+
return (
|
|
23
|
+
<Image src="/hero.jpg" alt="Hero" width={1200} height={600} priority />
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Optimization
|
|
29
|
+
|
|
30
|
+
`Image` builds a responsive `srcSet`, reserves layout space to prevent layout shift, and supports blur placeholders.
|
|
31
|
+
Serve transformations with `createImageHandler`. Requires React 18 or later.
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
See the [Kiln repository](https://github.com/kiln-js/kiln) for the full API reference and guides.
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
This repository is generated from the Kiln monorepo. Make changes there, then run `scripts/publish-repo.ps1` to publish them here. Report issues in this repository, and send pull requests to the monorepo.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { type CSSProperties, type ImgHTMLAttributes } from "react";
|
|
2
|
+
export type ImageFormat = "avif" | "webp" | "jpeg" | "png" | "svg";
|
|
3
|
+
export interface ImageConfig {
|
|
4
|
+
deviceSizes?: number[];
|
|
5
|
+
imageSizes?: number[];
|
|
6
|
+
domains?: string[];
|
|
7
|
+
formats?: ImageFormat[];
|
|
8
|
+
minimumCacheTTL?: number;
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
defaultQuality?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_IMAGE_CONFIG: Required<ImageConfig>;
|
|
13
|
+
export interface ImageTransformParams {
|
|
14
|
+
src: string;
|
|
15
|
+
width: number;
|
|
16
|
+
quality?: number;
|
|
17
|
+
format?: ImageFormat | "auto";
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function buildImageUrl(params: ImageTransformParams): string;
|
|
21
|
+
export declare function buildSrcSet(src: string, options?: {
|
|
22
|
+
width?: number;
|
|
23
|
+
quality?: number;
|
|
24
|
+
format?: ImageFormat | "auto";
|
|
25
|
+
endpoint?: string;
|
|
26
|
+
widths?: number[];
|
|
27
|
+
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Generates an inline SVG blur / shimmer placeholder data URL to eliminate layout shift (CLS).
|
|
30
|
+
*/
|
|
31
|
+
export declare function generateBlurPlaceholder(width?: number, height?: number, primaryColor?: string, accentColor?: string): string;
|
|
32
|
+
export declare function negotiateImageFormat(acceptHeader: string | null, allowedFormats?: ImageFormat[]): ImageFormat;
|
|
33
|
+
export interface KilnImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "width" | "height"> {
|
|
34
|
+
src: string;
|
|
35
|
+
alt: string;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
quality?: number;
|
|
39
|
+
priority?: boolean;
|
|
40
|
+
placeholder?: "blur" | "empty";
|
|
41
|
+
blurDataURL?: string;
|
|
42
|
+
unoptimized?: boolean;
|
|
43
|
+
endpoint?: string;
|
|
44
|
+
format?: ImageFormat | "auto";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Kiln <Image /> component with automatic responsive srcSet, blur placeholder, and CLS prevention.
|
|
48
|
+
*/
|
|
49
|
+
export declare function Image(props: KilnImageProps): import("react").DetailedReactHTMLElement<{
|
|
50
|
+
src: string;
|
|
51
|
+
srcSet: string | undefined;
|
|
52
|
+
sizes: string | undefined;
|
|
53
|
+
alt: string;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
loading: string;
|
|
57
|
+
decoding: string;
|
|
58
|
+
fetchPriority: string;
|
|
59
|
+
style: CSSProperties;
|
|
60
|
+
crossOrigin?: "" | "anonymous" | "use-credentials" | undefined;
|
|
61
|
+
referrerPolicy?: import("react").HTMLAttributeReferrerPolicy | undefined;
|
|
62
|
+
useMap?: string | undefined | undefined;
|
|
63
|
+
defaultChecked?: boolean | undefined | undefined;
|
|
64
|
+
defaultValue?: string | number | readonly string[] | undefined;
|
|
65
|
+
suppressContentEditableWarning?: boolean | undefined | undefined;
|
|
66
|
+
suppressHydrationWarning?: boolean | undefined | undefined;
|
|
67
|
+
accessKey?: string | undefined | undefined;
|
|
68
|
+
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | undefined | (string & {}) | undefined;
|
|
69
|
+
autoFocus?: boolean | undefined | undefined;
|
|
70
|
+
className?: string | undefined | undefined;
|
|
71
|
+
contentEditable?: "inherit" | (boolean | "false" | "true") | "plaintext-only" | undefined;
|
|
72
|
+
contextMenu?: string | undefined | undefined;
|
|
73
|
+
dir?: string | undefined | undefined;
|
|
74
|
+
draggable?: (boolean | "false" | "true") | undefined;
|
|
75
|
+
enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send" | undefined | undefined;
|
|
76
|
+
hidden?: boolean | undefined | undefined;
|
|
77
|
+
id?: string | undefined | undefined;
|
|
78
|
+
lang?: string | undefined | undefined;
|
|
79
|
+
nonce?: string | undefined | undefined;
|
|
80
|
+
slot?: string | undefined | undefined;
|
|
81
|
+
spellCheck?: (boolean | "false" | "true") | undefined;
|
|
82
|
+
tabIndex?: number | undefined | undefined;
|
|
83
|
+
title?: string | undefined | undefined;
|
|
84
|
+
translate?: "yes" | "no" | undefined | undefined;
|
|
85
|
+
radioGroup?: string | undefined | undefined;
|
|
86
|
+
role?: import("react").AriaRole | undefined;
|
|
87
|
+
about?: string | undefined | undefined;
|
|
88
|
+
content?: string | undefined | undefined;
|
|
89
|
+
datatype?: string | undefined | undefined;
|
|
90
|
+
inlist?: any;
|
|
91
|
+
prefix?: string | undefined | undefined;
|
|
92
|
+
property?: string | undefined | undefined;
|
|
93
|
+
rel?: string | undefined | undefined;
|
|
94
|
+
resource?: string | undefined | undefined;
|
|
95
|
+
rev?: string | undefined | undefined;
|
|
96
|
+
typeof?: string | undefined | undefined;
|
|
97
|
+
vocab?: string | undefined | undefined;
|
|
98
|
+
autoCorrect?: string | undefined | undefined;
|
|
99
|
+
autoSave?: string | undefined | undefined;
|
|
100
|
+
color?: string | undefined | undefined;
|
|
101
|
+
itemProp?: string | undefined | undefined;
|
|
102
|
+
itemScope?: boolean | undefined | undefined;
|
|
103
|
+
itemType?: string | undefined | undefined;
|
|
104
|
+
itemID?: string | undefined | undefined;
|
|
105
|
+
itemRef?: string | undefined | undefined;
|
|
106
|
+
results?: number | undefined | undefined;
|
|
107
|
+
security?: string | undefined | undefined;
|
|
108
|
+
unselectable?: "on" | "off" | undefined | undefined;
|
|
109
|
+
popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
|
|
110
|
+
popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
|
|
111
|
+
popoverTarget?: string | undefined | undefined;
|
|
112
|
+
inert?: boolean | undefined | undefined;
|
|
113
|
+
inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | undefined;
|
|
114
|
+
is?: string | undefined | undefined;
|
|
115
|
+
exportparts?: string | undefined | undefined;
|
|
116
|
+
part?: string | undefined | undefined;
|
|
117
|
+
"aria-activedescendant"?: string | undefined | undefined;
|
|
118
|
+
"aria-atomic"?: (boolean | "false" | "true") | undefined;
|
|
119
|
+
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined | undefined;
|
|
120
|
+
"aria-braillelabel"?: string | undefined | undefined;
|
|
121
|
+
"aria-brailleroledescription"?: string | undefined | undefined;
|
|
122
|
+
"aria-busy"?: (boolean | "false" | "true") | undefined;
|
|
123
|
+
"aria-checked"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
124
|
+
"aria-colcount"?: number | undefined | undefined;
|
|
125
|
+
"aria-colindex"?: number | undefined | undefined;
|
|
126
|
+
"aria-colindextext"?: string | undefined | undefined;
|
|
127
|
+
"aria-colspan"?: number | undefined | undefined;
|
|
128
|
+
"aria-controls"?: string | undefined | undefined;
|
|
129
|
+
"aria-current"?: boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time" | undefined | undefined;
|
|
130
|
+
"aria-describedby"?: string | undefined | undefined;
|
|
131
|
+
"aria-description"?: string | undefined | undefined;
|
|
132
|
+
"aria-details"?: string | undefined | undefined;
|
|
133
|
+
"aria-disabled"?: (boolean | "false" | "true") | undefined;
|
|
134
|
+
"aria-dropeffect"?: "none" | "copy" | "execute" | "link" | "move" | "popup" | undefined | undefined;
|
|
135
|
+
"aria-errormessage"?: string | undefined | undefined;
|
|
136
|
+
"aria-expanded"?: (boolean | "false" | "true") | undefined;
|
|
137
|
+
"aria-flowto"?: string | undefined | undefined;
|
|
138
|
+
"aria-grabbed"?: (boolean | "false" | "true") | undefined;
|
|
139
|
+
"aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined | undefined;
|
|
140
|
+
"aria-hidden"?: (boolean | "false" | "true") | undefined;
|
|
141
|
+
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling" | undefined | undefined;
|
|
142
|
+
"aria-keyshortcuts"?: string | undefined | undefined;
|
|
143
|
+
"aria-label"?: string | undefined | undefined;
|
|
144
|
+
"aria-labelledby"?: string | undefined | undefined;
|
|
145
|
+
"aria-level"?: number | undefined | undefined;
|
|
146
|
+
"aria-live"?: "off" | "assertive" | "polite" | undefined | undefined;
|
|
147
|
+
"aria-modal"?: (boolean | "false" | "true") | undefined;
|
|
148
|
+
"aria-multiline"?: (boolean | "false" | "true") | undefined;
|
|
149
|
+
"aria-multiselectable"?: (boolean | "false" | "true") | undefined;
|
|
150
|
+
"aria-orientation"?: "horizontal" | "vertical" | undefined | undefined;
|
|
151
|
+
"aria-owns"?: string | undefined | undefined;
|
|
152
|
+
"aria-placeholder"?: string | undefined | undefined;
|
|
153
|
+
"aria-posinset"?: number | undefined | undefined;
|
|
154
|
+
"aria-pressed"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
155
|
+
"aria-readonly"?: (boolean | "false" | "true") | undefined;
|
|
156
|
+
"aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined | undefined;
|
|
157
|
+
"aria-required"?: (boolean | "false" | "true") | undefined;
|
|
158
|
+
"aria-roledescription"?: string | undefined | undefined;
|
|
159
|
+
"aria-rowcount"?: number | undefined | undefined;
|
|
160
|
+
"aria-rowindex"?: number | undefined | undefined;
|
|
161
|
+
"aria-rowindextext"?: string | undefined | undefined;
|
|
162
|
+
"aria-rowspan"?: number | undefined | undefined;
|
|
163
|
+
"aria-selected"?: (boolean | "false" | "true") | undefined;
|
|
164
|
+
"aria-setsize"?: number | undefined | undefined;
|
|
165
|
+
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined | undefined;
|
|
166
|
+
"aria-valuemax"?: number | undefined | undefined;
|
|
167
|
+
"aria-valuemin"?: number | undefined | undefined;
|
|
168
|
+
"aria-valuenow"?: number | undefined | undefined;
|
|
169
|
+
"aria-valuetext"?: string | undefined | undefined;
|
|
170
|
+
children?: import("react").ReactNode;
|
|
171
|
+
dangerouslySetInnerHTML?: {
|
|
172
|
+
__html: string | TrustedHTML;
|
|
173
|
+
} | undefined | undefined;
|
|
174
|
+
onCopy?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
175
|
+
onCopyCapture?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
176
|
+
onCut?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
177
|
+
onCutCapture?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
178
|
+
onPaste?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
179
|
+
onPasteCapture?: import("react").ClipboardEventHandler<HTMLImageElement> | undefined;
|
|
180
|
+
onCompositionEnd?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
181
|
+
onCompositionEndCapture?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
182
|
+
onCompositionStart?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
183
|
+
onCompositionStartCapture?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
184
|
+
onCompositionUpdate?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
185
|
+
onCompositionUpdateCapture?: import("react").CompositionEventHandler<HTMLImageElement> | undefined;
|
|
186
|
+
onFocus?: import("react").FocusEventHandler<HTMLImageElement> | undefined;
|
|
187
|
+
onFocusCapture?: import("react").FocusEventHandler<HTMLImageElement> | undefined;
|
|
188
|
+
onBlur?: import("react").FocusEventHandler<HTMLImageElement> | undefined;
|
|
189
|
+
onBlurCapture?: import("react").FocusEventHandler<HTMLImageElement> | undefined;
|
|
190
|
+
onChange?: import("react").ChangeEventHandler<HTMLImageElement, Element> | undefined;
|
|
191
|
+
onChangeCapture?: import("react").ChangeEventHandler<HTMLImageElement, Element> | undefined;
|
|
192
|
+
onBeforeInput?: import("react").InputEventHandler<HTMLImageElement> | undefined;
|
|
193
|
+
onBeforeInputCapture?: import("react").InputEventHandler<HTMLImageElement> | undefined;
|
|
194
|
+
onInput?: import("react").InputEventHandler<HTMLImageElement> | undefined;
|
|
195
|
+
onInputCapture?: import("react").InputEventHandler<HTMLImageElement> | undefined;
|
|
196
|
+
onReset?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
197
|
+
onResetCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
198
|
+
onSubmit?: import("react").SubmitEventHandler<HTMLImageElement> | undefined;
|
|
199
|
+
onSubmitCapture?: import("react").SubmitEventHandler<HTMLImageElement> | undefined;
|
|
200
|
+
onInvalid?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
201
|
+
onInvalidCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
202
|
+
onLoad?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
203
|
+
onLoadCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
204
|
+
onError?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
205
|
+
onErrorCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
206
|
+
onKeyDown?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
207
|
+
onKeyDownCapture?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
208
|
+
onKeyPress?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
209
|
+
onKeyPressCapture?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
210
|
+
onKeyUp?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
211
|
+
onKeyUpCapture?: import("react").KeyboardEventHandler<HTMLImageElement> | undefined;
|
|
212
|
+
onAbort?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
213
|
+
onAbortCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
214
|
+
onCanPlay?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
215
|
+
onCanPlayCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
216
|
+
onCanPlayThrough?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
217
|
+
onCanPlayThroughCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
218
|
+
onDurationChange?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
219
|
+
onDurationChangeCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
220
|
+
onEmptied?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
221
|
+
onEmptiedCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
222
|
+
onEncrypted?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
223
|
+
onEncryptedCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
224
|
+
onEnded?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
225
|
+
onEndedCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
226
|
+
onLoadedData?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
227
|
+
onLoadedDataCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
228
|
+
onLoadedMetadata?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
229
|
+
onLoadedMetadataCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
230
|
+
onLoadStart?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
231
|
+
onLoadStartCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
232
|
+
onPause?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
233
|
+
onPauseCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
234
|
+
onPlay?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
235
|
+
onPlayCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
236
|
+
onPlaying?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
237
|
+
onPlayingCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
238
|
+
onProgress?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
239
|
+
onProgressCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
240
|
+
onRateChange?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
241
|
+
onRateChangeCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
242
|
+
onSeeked?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
243
|
+
onSeekedCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
244
|
+
onSeeking?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
245
|
+
onSeekingCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
246
|
+
onStalled?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
247
|
+
onStalledCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
248
|
+
onSuspend?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
249
|
+
onSuspendCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
250
|
+
onTimeUpdate?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
251
|
+
onTimeUpdateCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
252
|
+
onVolumeChange?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
253
|
+
onVolumeChangeCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
254
|
+
onWaiting?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
255
|
+
onWaitingCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
256
|
+
onAuxClick?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
257
|
+
onAuxClickCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
258
|
+
onClick?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
259
|
+
onClickCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
260
|
+
onContextMenu?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
261
|
+
onContextMenuCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
262
|
+
onDoubleClick?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
263
|
+
onDoubleClickCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
264
|
+
onDrag?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
265
|
+
onDragCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
266
|
+
onDragEnd?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
267
|
+
onDragEndCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
268
|
+
onDragEnter?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
269
|
+
onDragEnterCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
270
|
+
onDragExit?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
271
|
+
onDragExitCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
272
|
+
onDragLeave?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
273
|
+
onDragLeaveCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
274
|
+
onDragOver?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
275
|
+
onDragOverCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
276
|
+
onDragStart?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
277
|
+
onDragStartCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
278
|
+
onDrop?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
279
|
+
onDropCapture?: import("react").DragEventHandler<HTMLImageElement> | undefined;
|
|
280
|
+
onMouseDown?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
281
|
+
onMouseDownCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
282
|
+
onMouseEnter?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
283
|
+
onMouseLeave?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
284
|
+
onMouseMove?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
285
|
+
onMouseMoveCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
286
|
+
onMouseOut?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
287
|
+
onMouseOutCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
288
|
+
onMouseOver?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
289
|
+
onMouseOverCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
290
|
+
onMouseUp?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
291
|
+
onMouseUpCapture?: import("react").MouseEventHandler<HTMLImageElement> | undefined;
|
|
292
|
+
onSelect?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
293
|
+
onSelectCapture?: import("react").ReactEventHandler<HTMLImageElement> | undefined;
|
|
294
|
+
onTouchCancel?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
295
|
+
onTouchCancelCapture?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
296
|
+
onTouchEnd?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
297
|
+
onTouchEndCapture?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
298
|
+
onTouchMove?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
299
|
+
onTouchMoveCapture?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
300
|
+
onTouchStart?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
301
|
+
onTouchStartCapture?: import("react").TouchEventHandler<HTMLImageElement> | undefined;
|
|
302
|
+
onPointerDown?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
303
|
+
onPointerDownCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
304
|
+
onPointerMove?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
305
|
+
onPointerMoveCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
306
|
+
onPointerUp?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
307
|
+
onPointerUpCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
308
|
+
onPointerCancel?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
309
|
+
onPointerCancelCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
310
|
+
onPointerEnter?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
311
|
+
onPointerLeave?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
312
|
+
onPointerOver?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
313
|
+
onPointerOverCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
314
|
+
onPointerOut?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
315
|
+
onPointerOutCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
316
|
+
onGotPointerCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
317
|
+
onGotPointerCaptureCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
318
|
+
onLostPointerCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
319
|
+
onLostPointerCaptureCapture?: import("react").PointerEventHandler<HTMLImageElement> | undefined;
|
|
320
|
+
onScroll?: import("react").UIEventHandler<HTMLImageElement> | undefined;
|
|
321
|
+
onScrollCapture?: import("react").UIEventHandler<HTMLImageElement> | undefined;
|
|
322
|
+
onScrollEnd?: import("react").UIEventHandler<HTMLImageElement> | undefined;
|
|
323
|
+
onScrollEndCapture?: import("react").UIEventHandler<HTMLImageElement> | undefined;
|
|
324
|
+
onWheel?: import("react").WheelEventHandler<HTMLImageElement> | undefined;
|
|
325
|
+
onWheelCapture?: import("react").WheelEventHandler<HTMLImageElement> | undefined;
|
|
326
|
+
onAnimationStart?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
327
|
+
onAnimationStartCapture?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
328
|
+
onAnimationEnd?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
329
|
+
onAnimationEndCapture?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
330
|
+
onAnimationIteration?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
331
|
+
onAnimationIterationCapture?: import("react").AnimationEventHandler<HTMLImageElement> | undefined;
|
|
332
|
+
onToggle?: import("react").ToggleEventHandler<HTMLImageElement> | undefined;
|
|
333
|
+
onBeforeToggle?: import("react").ToggleEventHandler<HTMLImageElement> | undefined;
|
|
334
|
+
onTransitionCancel?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
335
|
+
onTransitionCancelCapture?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
336
|
+
onTransitionEnd?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
337
|
+
onTransitionEndCapture?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
338
|
+
onTransitionRun?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
339
|
+
onTransitionRunCapture?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
340
|
+
onTransitionStart?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
341
|
+
onTransitionStartCapture?: import("react").TransitionEventHandler<HTMLImageElement> | undefined;
|
|
342
|
+
}, HTMLElement>;
|
|
343
|
+
export declare const KilnImage: typeof Image;
|
|
344
|
+
export interface ImageOptimizationMetadata {
|
|
345
|
+
originalUrl: string;
|
|
346
|
+
width: number;
|
|
347
|
+
quality: number;
|
|
348
|
+
negotiatedFormat: ImageFormat;
|
|
349
|
+
contentType: string;
|
|
350
|
+
cacheControl: string;
|
|
351
|
+
estimatedSavingsPct: number;
|
|
352
|
+
}
|
|
353
|
+
export declare function inspectImageOptimization(request: Request, config?: ImageConfig): {
|
|
354
|
+
ok: true;
|
|
355
|
+
meta: ImageOptimizationMetadata;
|
|
356
|
+
} | {
|
|
357
|
+
ok: false;
|
|
358
|
+
status: number;
|
|
359
|
+
error: string;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Creates a standard Web Request -> Response handler for `/__kiln/image`.
|
|
363
|
+
*/
|
|
364
|
+
export declare function createImageHandler(config?: ImageConfig): (request: Request) => Promise<Response>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// packages/image/src/index.ts
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
var DEFAULT_IMAGE_CONFIG = {
|
|
4
|
+
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048],
|
|
5
|
+
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
|
|
6
|
+
domains: ["images.unsplash.com", "avatars.githubusercontent.com", "localhost"],
|
|
7
|
+
formats: ["avif", "webp", "jpeg"],
|
|
8
|
+
minimumCacheTTL: 31536e3,
|
|
9
|
+
endpoint: "/__kiln/image",
|
|
10
|
+
defaultQuality: 80
|
|
11
|
+
};
|
|
12
|
+
function buildImageUrl(params) {
|
|
13
|
+
const endpoint = params.endpoint ?? DEFAULT_IMAGE_CONFIG.endpoint;
|
|
14
|
+
const q = Math.min(100, Math.max(1, params.quality ?? DEFAULT_IMAGE_CONFIG.defaultQuality));
|
|
15
|
+
const w = Math.max(16, Math.round(params.width));
|
|
16
|
+
const search = new URLSearchParams({
|
|
17
|
+
url: params.src,
|
|
18
|
+
w: String(w),
|
|
19
|
+
q: String(q)
|
|
20
|
+
});
|
|
21
|
+
if (params.format && params.format !== "auto") {
|
|
22
|
+
search.set("fmt", params.format);
|
|
23
|
+
}
|
|
24
|
+
return `${endpoint}?${search.toString()}`;
|
|
25
|
+
}
|
|
26
|
+
function buildSrcSet(src, options = {}) {
|
|
27
|
+
const allSizes = [...DEFAULT_IMAGE_CONFIG.imageSizes, ...DEFAULT_IMAGE_CONFIG.deviceSizes].sort(
|
|
28
|
+
(a, b) => a - b
|
|
29
|
+
);
|
|
30
|
+
const candidateWidths = options.widths ?? (options.width ? Array.from(
|
|
31
|
+
new Set(
|
|
32
|
+
[options.width, options.width * 2].map((target) => {
|
|
33
|
+
return allSizes.find((s) => s >= target) ?? allSizes[allSizes.length - 1];
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
) : [640, 1080, 1920]);
|
|
37
|
+
return candidateWidths.map((w) => {
|
|
38
|
+
const url = buildImageUrl({
|
|
39
|
+
src,
|
|
40
|
+
width: w,
|
|
41
|
+
quality: options.quality,
|
|
42
|
+
format: options.format,
|
|
43
|
+
endpoint: options.endpoint
|
|
44
|
+
});
|
|
45
|
+
return `${url} ${w}w`;
|
|
46
|
+
}).join(", ");
|
|
47
|
+
}
|
|
48
|
+
function encodeBase64(input) {
|
|
49
|
+
if (typeof btoa === "function") {
|
|
50
|
+
return btoa(input);
|
|
51
|
+
}
|
|
52
|
+
return Buffer.from(input, "utf-8").toString("base64");
|
|
53
|
+
}
|
|
54
|
+
function generateBlurPlaceholder(width = 400, height = 300, primaryColor = "#1a1917", accentColor = "#ff5a1f") {
|
|
55
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">
|
|
56
|
+
<defs>
|
|
57
|
+
<linearGradient id="g" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
58
|
+
<stop offset="0%" stop-color="${primaryColor}" />
|
|
59
|
+
<stop offset="50%" stop-color="${accentColor}" stop-opacity="0.35" />
|
|
60
|
+
<stop offset="100%" stop-color="${primaryColor}" />
|
|
61
|
+
</linearGradient>
|
|
62
|
+
<filter id="b" color-interpolation-filters="sRGB">
|
|
63
|
+
<feGaussianBlur stdDeviation="24" />
|
|
64
|
+
</filter>
|
|
65
|
+
</defs>
|
|
66
|
+
<rect width="100%" height="100%" fill="${primaryColor}" />
|
|
67
|
+
<rect width="100%" height="100%" fill="url(#g)" filter="url(#b)" />
|
|
68
|
+
</svg>`;
|
|
69
|
+
return `data:image/svg+xml;base64,${encodeBase64(svg)}`;
|
|
70
|
+
}
|
|
71
|
+
function negotiateImageFormat(acceptHeader, allowedFormats = DEFAULT_IMAGE_CONFIG.formats) {
|
|
72
|
+
const accept = (acceptHeader ?? "").toLowerCase();
|
|
73
|
+
if (allowedFormats.includes("avif") && accept.includes("image/avif")) {
|
|
74
|
+
return "avif";
|
|
75
|
+
}
|
|
76
|
+
if (allowedFormats.includes("webp") && accept.includes("image/webp")) {
|
|
77
|
+
return "webp";
|
|
78
|
+
}
|
|
79
|
+
return allowedFormats[0] ?? "jpeg";
|
|
80
|
+
}
|
|
81
|
+
function Image(props) {
|
|
82
|
+
const {
|
|
83
|
+
src,
|
|
84
|
+
alt,
|
|
85
|
+
width,
|
|
86
|
+
height,
|
|
87
|
+
quality = DEFAULT_IMAGE_CONFIG.defaultQuality,
|
|
88
|
+
priority = false,
|
|
89
|
+
placeholder = "empty",
|
|
90
|
+
blurDataURL,
|
|
91
|
+
unoptimized = false,
|
|
92
|
+
endpoint = DEFAULT_IMAGE_CONFIG.endpoint,
|
|
93
|
+
format = "auto",
|
|
94
|
+
sizes = `(max-width: ${width}px) 100vw, ${width}px`,
|
|
95
|
+
style,
|
|
96
|
+
...rest
|
|
97
|
+
} = props;
|
|
98
|
+
const isDataOrSvg = src.startsWith("data:") || src.endsWith(".svg");
|
|
99
|
+
const shouldOptimize = !unoptimized && !isDataOrSvg;
|
|
100
|
+
const resolvedSrc = shouldOptimize ? buildImageUrl({ src, width, quality, format, endpoint }) : src;
|
|
101
|
+
const resolvedSrcSet = shouldOptimize ? buildSrcSet(src, { width, quality, format, endpoint }) : void 0;
|
|
102
|
+
const bgPlaceholder = placeholder === "blur" ? blurDataURL ?? generateBlurPlaceholder(width, height) : void 0;
|
|
103
|
+
const combinedStyle = {
|
|
104
|
+
aspectRatio: `${width} / ${height}`,
|
|
105
|
+
...bgPlaceholder ? {
|
|
106
|
+
backgroundImage: `url("${bgPlaceholder}")`,
|
|
107
|
+
backgroundSize: "cover",
|
|
108
|
+
backgroundPosition: "center"
|
|
109
|
+
} : {},
|
|
110
|
+
...style
|
|
111
|
+
};
|
|
112
|
+
return createElement("img", {
|
|
113
|
+
...rest,
|
|
114
|
+
src: resolvedSrc,
|
|
115
|
+
srcSet: resolvedSrcSet,
|
|
116
|
+
sizes: shouldOptimize ? sizes : void 0,
|
|
117
|
+
alt,
|
|
118
|
+
width,
|
|
119
|
+
height,
|
|
120
|
+
loading: priority ? "eager" : "lazy",
|
|
121
|
+
decoding: priority ? "sync" : "async",
|
|
122
|
+
fetchPriority: priority ? "high" : "auto",
|
|
123
|
+
style: combinedStyle
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
var KilnImage = Image;
|
|
127
|
+
function inspectImageOptimization(request, config = {}) {
|
|
128
|
+
const merged = { ...DEFAULT_IMAGE_CONFIG, ...config };
|
|
129
|
+
const url = new URL(request.url);
|
|
130
|
+
const rawSrc = url.searchParams.get("url");
|
|
131
|
+
const rawWidth = Number(url.searchParams.get("w") ?? "800");
|
|
132
|
+
const rawQuality = Number(url.searchParams.get("q") ?? String(merged.defaultQuality));
|
|
133
|
+
const explicitFormat = url.searchParams.get("fmt");
|
|
134
|
+
if (!rawSrc) {
|
|
135
|
+
return { ok: false, status: 400, error: 'Missing required "url" query parameter.' };
|
|
136
|
+
}
|
|
137
|
+
if (!Number.isFinite(rawWidth) || rawWidth < 16 || rawWidth > 4096) {
|
|
138
|
+
return { ok: false, status: 400, error: 'Invalid "w" (width) parameter; must be between 16 and 4096.' };
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isFinite(rawQuality) || rawQuality < 1 || rawQuality > 100) {
|
|
141
|
+
return { ok: false, status: 400, error: 'Invalid "q" (quality) parameter; must be between 1 and 100.' };
|
|
142
|
+
}
|
|
143
|
+
if (/^https?:\/\//i.test(rawSrc)) {
|
|
144
|
+
let parsed;
|
|
145
|
+
try {
|
|
146
|
+
parsed = new URL(rawSrc);
|
|
147
|
+
} catch {
|
|
148
|
+
return { ok: false, status: 400, error: "Malformed external image URL." };
|
|
149
|
+
}
|
|
150
|
+
if (!merged.domains.includes("*") && !merged.domains.includes(parsed.hostname)) {
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
status: 403,
|
|
154
|
+
error: `Domain "${parsed.hostname}" is not in allowed image domains (${merged.domains.join(", ")}).`
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const negotiatedFormat = explicitFormat && merged.formats.includes(explicitFormat) ? explicitFormat : negotiateImageFormat(request.headers.get("accept"), merged.formats);
|
|
159
|
+
const contentType = negotiatedFormat === "svg" ? "image/svg+xml" : `image/${negotiatedFormat}`;
|
|
160
|
+
const formatFactor = negotiatedFormat === "avif" ? 0.52 : negotiatedFormat === "webp" ? 0.38 : 0.18;
|
|
161
|
+
const qualityFactor = (100 - rawQuality) * 4e-3;
|
|
162
|
+
const estimatedSavingsPct = Math.min(85, Math.max(10, Math.round((formatFactor + qualityFactor) * 100)));
|
|
163
|
+
return {
|
|
164
|
+
ok: true,
|
|
165
|
+
meta: {
|
|
166
|
+
originalUrl: rawSrc,
|
|
167
|
+
width: rawWidth,
|
|
168
|
+
quality: rawQuality,
|
|
169
|
+
negotiatedFormat,
|
|
170
|
+
contentType,
|
|
171
|
+
cacheControl: `public, max-age=${merged.minimumCacheTTL}, immutable`,
|
|
172
|
+
estimatedSavingsPct
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function createImageHandler(config = {}) {
|
|
177
|
+
return async (request) => {
|
|
178
|
+
const check = inspectImageOptimization(request, config);
|
|
179
|
+
if (!check.ok) {
|
|
180
|
+
return Response.json({ error: check.error }, { status: check.status });
|
|
181
|
+
}
|
|
182
|
+
const { meta } = check;
|
|
183
|
+
const url = new URL(request.url);
|
|
184
|
+
if (url.searchParams.get("inspect") === "1" || (request.headers.get("accept") ?? "").includes("application/json")) {
|
|
185
|
+
return Response.json(meta, {
|
|
186
|
+
status: 200,
|
|
187
|
+
headers: {
|
|
188
|
+
"cache-control": meta.cacheControl,
|
|
189
|
+
"x-kiln-image-format": meta.negotiatedFormat,
|
|
190
|
+
"x-kiln-image-savings": `${meta.estimatedSavingsPct}%`
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const height = Math.round(meta.width * 0.625);
|
|
195
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${meta.width} ${height}" width="${meta.width}" height="${height}">
|
|
196
|
+
<defs>
|
|
197
|
+
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
198
|
+
<stop offset="0%" stop-color="#141413" />
|
|
199
|
+
<stop offset="60%" stop-color="#1e1c1a" />
|
|
200
|
+
<stop offset="100%" stop-color="#2c1912" />
|
|
201
|
+
</linearGradient>
|
|
202
|
+
</defs>
|
|
203
|
+
<rect width="100%" height="100%" fill="url(#bg)" />
|
|
204
|
+
<circle cx="${Math.round(meta.width * 0.78)}" cy="${Math.round(height * 0.3)}" r="${Math.round(height * 0.22)}" fill="#ff5a1f" fill-opacity="0.22" />
|
|
205
|
+
<text x="32" y="${Math.round(height - 56)}" fill="#f5f5f4" font-family="monospace" font-size="16" font-weight="bold">@kiln-js/image [${meta.negotiatedFormat.toUpperCase()}]</text>
|
|
206
|
+
<text x="32" y="${Math.round(height - 30)}" fill="#a8a29e" font-family="monospace" font-size="13">${meta.width}w \xB7 q=${meta.quality} \xB7 -${meta.estimatedSavingsPct}% bytes</text>
|
|
207
|
+
</svg>`;
|
|
208
|
+
return new Response(svg, {
|
|
209
|
+
status: 200,
|
|
210
|
+
headers: {
|
|
211
|
+
"content-type": "image/svg+xml; charset=utf-8",
|
|
212
|
+
"cache-control": meta.cacheControl,
|
|
213
|
+
vary: "Accept",
|
|
214
|
+
"x-kiln-image-format": meta.negotiatedFormat,
|
|
215
|
+
"x-kiln-image-width": String(meta.width),
|
|
216
|
+
"x-kiln-image-quality": String(meta.quality),
|
|
217
|
+
"x-kiln-image-savings": `${meta.estimatedSavingsPct}%`
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
DEFAULT_IMAGE_CONFIG,
|
|
224
|
+
Image,
|
|
225
|
+
KilnImage,
|
|
226
|
+
buildImageUrl,
|
|
227
|
+
buildSrcSet,
|
|
228
|
+
createImageHandler,
|
|
229
|
+
generateBlurPlaceholder,
|
|
230
|
+
inspectImageOptimization,
|
|
231
|
+
negotiateImageFormat
|
|
232
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@kiln-js/image",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react": "\u003e=18"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target browser --external react \u0026\u0026 tsc -p tsconfig.json --emitDeclarationOnly",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"repository": "github:kiln-js/image",
|
|
23
|
+
"homepage": "https://kiln-js.vercel.app",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@types/react": "^19.3.3"
|
|
26
|
+
}
|
|
27
|
+
}
|