ipx 3.0.1 → 3.0.3

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 CHANGED
@@ -95,6 +95,10 @@ Change format to `webp` and keep other things same as source:
95
95
 
96
96
  `/f_webp/static/buffalo.png`
97
97
 
98
+ Automatically convert to a preferred format (avif/webp/jpeg). Uses the browsers `accept` header to negotiate:
99
+
100
+ `/f_auto/static/buffalo.png`
101
+
98
102
  Keep original format (`png`) and set width to `200`:
99
103
 
100
104
  `/w_200/static/buffalo.png`
package/dist/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const listhen = require('listhen');
4
4
  const citty = require('citty');
5
5
  const cli = require('listhen/cli');
6
- const nodeFs = require('./shared/ipx.f2a173e6.cjs');
6
+ const nodeFs = require('./shared/ipx.987wBc_s.cjs');
7
7
  require('defu');
8
8
  require('ufo');
9
9
  require('h3');
@@ -15,7 +15,7 @@ require('ofetch');
15
15
  require('pathe');
16
16
 
17
17
  const name = "ipx";
18
- const version = "3.0.1";
18
+ const version = "3.0.3";
19
19
  const description = "High performance, secure and easy-to-use image optimizer.";
20
20
 
21
21
  const serve = citty.defineCommand({
package/dist/cli.d.cts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };
package/dist/cli.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { listen } from 'listhen';
2
2
  import { defineCommand, runMain } from 'citty';
3
3
  import { getArgs, parseArgs } from 'listhen/cli';
4
- import { c as createIPX, g as ipxFSStorage, i as ipxHttpStorage, e as createIPXNodeServer } from './shared/ipx.90a2d420.mjs';
4
+ import { c as createIPX, i as ipxHttpStorage, g as ipxFSStorage, e as createIPXNodeServer } from './shared/ipx.CTj1EgBv.mjs';
5
5
  import 'defu';
6
6
  import 'ufo';
7
7
  import 'h3';
@@ -13,7 +13,7 @@ import 'ofetch';
13
13
  import 'pathe';
14
14
 
15
15
  const name = "ipx";
16
- const version = "3.0.1";
16
+ const version = "3.0.3";
17
17
  const description = "High performance, secure and easy-to-use image optimizer.";
18
18
 
19
19
  const serve = defineCommand({
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const nodeFs = require('./shared/ipx.f2a173e6.cjs');
3
+ const nodeFs = require('./shared/ipx.987wBc_s.cjs');
4
4
  const h3 = require('h3');
5
5
  require('defu');
6
6
  require('ufo');
package/dist/index.d.cts CHANGED
@@ -5,28 +5,94 @@ import * as h3 from 'h3';
5
5
  import { Storage, Driver } from 'unstorage';
6
6
 
7
7
  interface HandlerContext {
8
+ /**
9
+ * Optional quality setting for the output image, affects compression in certain formats.
10
+ * @optional
11
+ */
8
12
  quality?: number;
13
+ /**
14
+ * Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
15
+ * @optional
16
+ */
9
17
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
18
+ /**
19
+ * The position used for cropping or positioning, specified as a number or string.
20
+ * @optional
21
+ */
10
22
  position?: number | string;
23
+ /**
24
+ * Background colour to be used if necessary, provided as a colour object. See {@link Color}.
25
+ * @optional
26
+ */
11
27
  background?: Color;
28
+ /**
29
+ * Specifies whether to enlarge the image if it is smaller than the desired size.
30
+ * @optional
31
+ */
12
32
  enlarge?: boolean;
33
+ /**
34
+ * The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
35
+ * @optional
36
+ */
13
37
  kernel?: keyof KernelEnum;
38
+ /**
39
+ * Metadata about the image being processed.
40
+ */
14
41
  meta: ImageMeta;
15
42
  }
16
43
  interface Handler {
44
+ /**
45
+ * An array of functions that convert the given string arguments into usable forms.
46
+ */
17
47
  args: ((argument: string) => any)[];
48
+ /**
49
+ * Defines the order in which this handler should be applied relative to other handlers.
50
+ * @optional
51
+ */
18
52
  order?: number;
53
+ /**
54
+ * Function to apply the effects of this handler to the image pipeline.
55
+ * @param {HandlerContext} context - The current image processing context. See {@link HandlerContext}.
56
+ * @param {Sharp} pipe - The Sharp instance to use for image processing. See {@link Sharp}.
57
+ * @param {...any} arguments_ - Transformed arguments to use in the handler.
58
+ */
19
59
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
20
60
  }
21
61
  type IPXStorageMeta = {
62
+ /**
63
+ * The modification time of the stored item.
64
+ * @optional
65
+ */
22
66
  mtime?: Date | number | string;
67
+ /**
68
+ * The maximum age (in seconds) at which the stored item should be considered fresh.
69
+ * @optional
70
+ */
23
71
  maxAge?: number | string;
24
72
  };
73
+ /**
74
+ * Options specific to image saving operations.
75
+ */
25
76
  type IPXStorageOptions = Record<string, unknown>;
26
77
  type MaybePromise<T> = T | Promise<T>;
27
78
  interface IPXStorage {
79
+ /**
80
+ * A descriptive name for the storage type.
81
+ */
28
82
  name: string;
83
+ /**
84
+ * Retrieves metadata for an image identified by 'id'.
85
+ * @param {string} id - The identifier for the image.
86
+ * @param {IPXStorageOptions} [opts] - Optional metadata retrieval options. See {@link IPXStorageOptions}.
87
+ * @returns {MaybePromise<IPXStorageMeta | undefined>} A promise or direct return of the metadata, or undefined if not found. See {@link IPXStorageMeta}.
88
+ */
29
89
  getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
90
+ /**
91
+ * Get the actual data for an image identified by 'id'.
92
+ * @param {string} id - The identifier for the image.
93
+ * @param {IPXStorageOptions} [opts] - Optional options for the data retrieval. See {@link IPXStorageOptions}.
94
+ * @returns {MaybePromise<ArrayBuffer | undefined>} A promise or direct return of the image data as an ArrayBuffer, or undefined if not found. See {@link ArrayBuffer}.
95
+ */
30
96
  getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
31
97
  }
32
98
 
@@ -98,15 +164,74 @@ declare const Handlers_trim: typeof trim;
98
164
  declare const Handlers_w: typeof w;
99
165
  declare const Handlers_width: typeof width;
100
166
  declare namespace Handlers {
101
- export { Handlers_b as b, Handlers_background as background, Handlers_blur as blur, Handlers_crop as crop, Handlers_enlarge as enlarge, Handlers_extend as extend, Handlers_extract as extract, Handlers_fit as fit, Handlers_flatten as flatten, Handlers_flip as flip, Handlers_flop as flop, Handlers_gamma as gamma, Handlers_grayscale as grayscale, Handlers_h as h, Handlers_height as height, Handlers_kernel as kernel, Handlers_median as median, Handlers_modulate as modulate, Handlers_negate as negate, Handlers_normalize as normalize, Handlers_pos as pos, Handlers_position as position, Handlers_q as q, Handlers_quality as quality, Handlers_resize as resize, Handlers_rotate as rotate, Handlers_s as s, Handlers_sharpen as sharpen, Handlers_threshold as threshold, Handlers_tint as tint, Handlers_trim as trim, Handlers_w as w, Handlers_width as width };
167
+ export {
168
+ Handlers_b as b,
169
+ Handlers_background as background,
170
+ Handlers_blur as blur,
171
+ Handlers_crop as crop,
172
+ Handlers_enlarge as enlarge,
173
+ Handlers_extend as extend,
174
+ Handlers_extract as extract,
175
+ Handlers_fit as fit,
176
+ Handlers_flatten as flatten,
177
+ Handlers_flip as flip,
178
+ Handlers_flop as flop,
179
+ Handlers_gamma as gamma,
180
+ Handlers_grayscale as grayscale,
181
+ Handlers_h as h,
182
+ Handlers_height as height,
183
+ Handlers_kernel as kernel,
184
+ Handlers_median as median,
185
+ Handlers_modulate as modulate,
186
+ Handlers_negate as negate,
187
+ Handlers_normalize as normalize,
188
+ Handlers_pos as pos,
189
+ Handlers_position as position,
190
+ Handlers_q as q,
191
+ Handlers_quality as quality,
192
+ Handlers_resize as resize,
193
+ Handlers_rotate as rotate,
194
+ Handlers_s as s,
195
+ Handlers_sharpen as sharpen,
196
+ Handlers_threshold as threshold,
197
+ Handlers_tint as tint,
198
+ Handlers_trim as trim,
199
+ Handlers_w as w,
200
+ Handlers_width as width,
201
+ };
102
202
  }
103
203
 
104
204
  type HandlerName = keyof typeof Handlers;
105
205
 
106
206
  type IPXSourceMeta = {
207
+ /**
208
+ * The modification time of the source. Used for cache validation.
209
+ * @optional
210
+ */
107
211
  mtime?: Date;
212
+ /**
213
+ * The maximum age (in seconds) that the source should be considered fresh.
214
+ * @optional
215
+ */
108
216
  maxAge?: number;
109
217
  };
218
+ /**
219
+ * A function type that defines an IPX image processing instance.
220
+ *
221
+ * This function takes an image identifier and optional modifiers and request options, then provides methods to retrieve
222
+ * image metadata and process the image according to the specified modifiers.
223
+ *
224
+ * @param {string} id - The identifier for the image. This can be a URL or a path, depending on the storage implementation.
225
+ * @param {partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>} [modifiers] - Modifiers to be applied to the image,
226
+ * such as resizing, cropping or format conversion. This record contains predefined keys such as 'f' or 'format' to specify the output to
227
+ * specify the output image format, and 'a' or 'animated' to specify whether the image should be processed as an animation. See
228
+ * {@link HandlerName}.
229
+ * @param {any} [requestOptions] - Additional options that may be needed for request handling, specific to the storage backend.
230
+ * Returns an object with methods:
231
+ * - `getSourceMeta`: A method that returns a promise resolving to the source image metadata (`IPXSourceMeta`).
232
+ * - `process`: A method that returns a promise resolving to an object containing the processed image data, metadata,
233
+ * and format. The image data can be in the form of a `buffer` or a string, depending on the format and processing.
234
+ */
110
235
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
111
236
  getSourceMeta: () => Promise<IPXSourceMeta>;
112
237
  process: () => Promise<{
@@ -116,43 +241,157 @@ type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format"
116
241
  }>;
117
242
  };
118
243
  type IPXOptions = {
244
+ /**
245
+ * Default cache duration in seconds. If not specified, a default of 1 minute is used.
246
+ * @optional
247
+ */
119
248
  maxAge?: number;
249
+ /**
250
+ * A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
251
+ * @optional
252
+ */
120
253
  alias?: Record<string, string>;
254
+ /**
255
+ * Configuration options for the Sharp image processing library.
256
+ * @optional
257
+ */
121
258
  sharpOptions?: SharpOptions;
259
+ /**
260
+ * Primary storage backend for handling image assets.
261
+ */
122
262
  storage: IPXStorage;
263
+ /**
264
+ * An optional secondary storage backend used when images are fetched via HTTP.
265
+ * @optional
266
+ */
123
267
  httpStorage?: IPXStorage;
268
+ /**
269
+ * Configuration for the SVGO library used when processing SVG images.
270
+ * @optional
271
+ */
124
272
  svgo?: false | Config;
125
273
  };
274
+ /**
275
+ * Creates an IPX image processing instance with the specified options.
276
+ * @param {IPXOptions} userOptions - Configuration options for the IPX instance. See {@link IPXOptions}.
277
+ * @returns {IPX} An IPX processing function configured with the given options. See {@link IPX}.
278
+ * @throws {Error} If critical options such as storage are missing or incorrectly configured.
279
+ */
126
280
  declare function createIPX(userOptions: IPXOptions): IPX;
127
281
 
128
- declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer | {
282
+ /**
283
+ * Creates an H3 handler to handle images using IPX.
284
+ * @param {IPX} ipx - An IPX instance to handle image requests.
285
+ * @returns {H3Event} An H3 event handler that processes image requests, applies modifiers, handles caching,
286
+ * and returns the processed image data. See {@link H3Event}.
287
+ * @throws {H3Error} If there are problems with the request parameters or processing the image. See {@link H3Error}.
288
+ */
289
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer<ArrayBufferLike> | {
129
290
  error: {
130
291
  message: string;
131
292
  };
132
293
  }>>;
294
+ /**
295
+ * Creates an H3 application configured to handle image processing using a supplied IPX instance.
296
+ * @param {IPX} ipx - An IPX instance to handle image handling requests.
297
+ * @returns {any} An H3 application configured to use the IPX image handler.
298
+ */
133
299
  declare function createIPXH3App(ipx: IPX): h3.App;
300
+ /**
301
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
302
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
303
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
304
+ */
134
305
  declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
306
+ /**
307
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
308
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
309
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
310
+ */
135
311
  declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
312
+ /**
313
+ * Creates a simple server that can handle IPX image processing requests using an H3 application.
314
+ * @param {IPX} ipx - An IPX instance configured for the server.
315
+ * @returns {any} A handler suitable for plain HTTP server environments that support the H3 library.
316
+ */
136
317
  declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
137
318
 
138
319
  type HTTPStorageOptions = {
320
+ /**
321
+ * Custom options for fetch operations, such as headers or method overrides.
322
+ * @optional
323
+ */
139
324
  fetchOptions?: RequestInit;
325
+ /**
326
+ * Default maximum age (in seconds) for cache control. If not specified, defaults to the environment setting or 300 seconds.
327
+ * @optional
328
+ */
140
329
  maxAge?: number;
330
+ /**
331
+ * Whitelist of domains from which resource fetching is allowed. Can be a single string or an array of strings.
332
+ * @optional
333
+ */
141
334
  domains?: string | string[];
335
+ /**
336
+ * If set to true, allows retrieval from any domain. Overrides the domain whitelist.
337
+ * @optional
338
+ */
142
339
  allowAllDomains?: boolean;
340
+ /**
341
+ * If set to true, ignore the cache control header in responses and use the default or specified maxAge.
342
+ * @optional
343
+ */
143
344
  ignoreCacheControl?: boolean;
144
345
  };
346
+ /**
347
+ * Creates an HTTP storage handler for IPX that fetches image data from external URLs.
348
+ * This handler allows configuration to specify allowed domains, caching behaviour and custom fetch options.
349
+ *
350
+ * @param {HTTPStorageOptions} [_options={}] - Configuration options for HTTP storage, with defaults possibly taken from environment variables. See {@link HTTPStorageOptions}.
351
+ * @returns {IPXStorage} An IPXStorage interface implementation for retrieving images over HTTP. See {@link IPXStorage}.
352
+ * @throws {H3Error} If validation of the requested URL fails due to a missing hostname or denied host access. See {@link H3Error}.
353
+ */
145
354
  declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
146
355
 
147
356
  type NodeFSSOptions = {
357
+ /**
358
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
359
+ * @optional
360
+ */
148
361
  dir?: string | string[];
362
+ /**
363
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
364
+ * @optional
365
+ */
149
366
  maxAge?: number;
150
367
  };
368
+ /**
369
+ * Creates a file system storage handler for IPX that allows images to be served from local directories specified in the options.
370
+ * This handler resolves directories and handles file access, ensuring that files are served safely.
371
+ *
372
+ * @param {NodeFSSOptions} [_options={}] - File system storage configuration options, with optional directory paths and caching configuration. See {@link NodeFSSOptions}.
373
+ * @returns {IPXStorage} An implementation of the IPXStorage interface for accessing images stored on the local file system. See {@link IPXStorage}.
374
+ * @throws {H3Error} If there is a problem accessing the file system module or resolving/reading files. See {@link H3Error}.
375
+ */
151
376
  declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
152
377
 
153
378
  type UnstorageIPXStorageOptions = {
379
+ /**
380
+ * Optional prefix to be placed in front of each storage key, which can help to name or categorise stored items.
381
+ * @optional
382
+ */
154
383
  prefix?: string;
155
384
  };
385
+ /**
386
+ * Adapts an Unstorage driver or storage system to comply with the IPXStorage interface required by IPX.
387
+ * This allows various Unstorage-compatible storage systems to be used to manage image data with IPX.
388
+ *
389
+ * @param {Storage | Driver} storage - The Unstorage driver or storage instance to adapt. See {@link Storage} and {@link Driver}.
390
+ * @param {UnstorageIPXStorageOptions | string} [_options={}] - Configuration options for the adapter, which can be a simple string prefix or an options object. See {@link UnstorageIPXStorageOptions}.
391
+ * @returns {IPXStorage}. An IPXStorage compliant object that implements the necessary methods to interact with the provided unstorage driver or storage system. See {@link IPXStorage}.
392
+ * @throws {H3Error} If there is a problem retrieving or converting the storage data, detailed error information is thrown. See {@link H3Error}.
393
+ */
156
394
  declare function unstorageToIPXStorage(storage: Storage | Driver, _options?: UnstorageIPXStorageOptions | string): IPXStorage;
157
395
 
158
- export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type NodeFSSOptions, type UnstorageIPXStorageOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
396
+ export { createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
397
+ export type { HTTPStorageOptions, Handler, HandlerContext, IPX, IPXOptions, IPXStorage, IPXStorageMeta, IPXStorageOptions, NodeFSSOptions, UnstorageIPXStorageOptions };
package/dist/index.d.mts CHANGED
@@ -5,28 +5,94 @@ import * as h3 from 'h3';
5
5
  import { Storage, Driver } from 'unstorage';
6
6
 
7
7
  interface HandlerContext {
8
+ /**
9
+ * Optional quality setting for the output image, affects compression in certain formats.
10
+ * @optional
11
+ */
8
12
  quality?: number;
13
+ /**
14
+ * Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
15
+ * @optional
16
+ */
9
17
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
18
+ /**
19
+ * The position used for cropping or positioning, specified as a number or string.
20
+ * @optional
21
+ */
10
22
  position?: number | string;
23
+ /**
24
+ * Background colour to be used if necessary, provided as a colour object. See {@link Color}.
25
+ * @optional
26
+ */
11
27
  background?: Color;
28
+ /**
29
+ * Specifies whether to enlarge the image if it is smaller than the desired size.
30
+ * @optional
31
+ */
12
32
  enlarge?: boolean;
33
+ /**
34
+ * The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
35
+ * @optional
36
+ */
13
37
  kernel?: keyof KernelEnum;
38
+ /**
39
+ * Metadata about the image being processed.
40
+ */
14
41
  meta: ImageMeta;
15
42
  }
16
43
  interface Handler {
44
+ /**
45
+ * An array of functions that convert the given string arguments into usable forms.
46
+ */
17
47
  args: ((argument: string) => any)[];
48
+ /**
49
+ * Defines the order in which this handler should be applied relative to other handlers.
50
+ * @optional
51
+ */
18
52
  order?: number;
53
+ /**
54
+ * Function to apply the effects of this handler to the image pipeline.
55
+ * @param {HandlerContext} context - The current image processing context. See {@link HandlerContext}.
56
+ * @param {Sharp} pipe - The Sharp instance to use for image processing. See {@link Sharp}.
57
+ * @param {...any} arguments_ - Transformed arguments to use in the handler.
58
+ */
19
59
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
20
60
  }
21
61
  type IPXStorageMeta = {
62
+ /**
63
+ * The modification time of the stored item.
64
+ * @optional
65
+ */
22
66
  mtime?: Date | number | string;
67
+ /**
68
+ * The maximum age (in seconds) at which the stored item should be considered fresh.
69
+ * @optional
70
+ */
23
71
  maxAge?: number | string;
24
72
  };
73
+ /**
74
+ * Options specific to image saving operations.
75
+ */
25
76
  type IPXStorageOptions = Record<string, unknown>;
26
77
  type MaybePromise<T> = T | Promise<T>;
27
78
  interface IPXStorage {
79
+ /**
80
+ * A descriptive name for the storage type.
81
+ */
28
82
  name: string;
83
+ /**
84
+ * Retrieves metadata for an image identified by 'id'.
85
+ * @param {string} id - The identifier for the image.
86
+ * @param {IPXStorageOptions} [opts] - Optional metadata retrieval options. See {@link IPXStorageOptions}.
87
+ * @returns {MaybePromise<IPXStorageMeta | undefined>} A promise or direct return of the metadata, or undefined if not found. See {@link IPXStorageMeta}.
88
+ */
29
89
  getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
90
+ /**
91
+ * Get the actual data for an image identified by 'id'.
92
+ * @param {string} id - The identifier for the image.
93
+ * @param {IPXStorageOptions} [opts] - Optional options for the data retrieval. See {@link IPXStorageOptions}.
94
+ * @returns {MaybePromise<ArrayBuffer | undefined>} A promise or direct return of the image data as an ArrayBuffer, or undefined if not found. See {@link ArrayBuffer}.
95
+ */
30
96
  getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
31
97
  }
32
98
 
@@ -98,15 +164,74 @@ declare const Handlers_trim: typeof trim;
98
164
  declare const Handlers_w: typeof w;
99
165
  declare const Handlers_width: typeof width;
100
166
  declare namespace Handlers {
101
- export { Handlers_b as b, Handlers_background as background, Handlers_blur as blur, Handlers_crop as crop, Handlers_enlarge as enlarge, Handlers_extend as extend, Handlers_extract as extract, Handlers_fit as fit, Handlers_flatten as flatten, Handlers_flip as flip, Handlers_flop as flop, Handlers_gamma as gamma, Handlers_grayscale as grayscale, Handlers_h as h, Handlers_height as height, Handlers_kernel as kernel, Handlers_median as median, Handlers_modulate as modulate, Handlers_negate as negate, Handlers_normalize as normalize, Handlers_pos as pos, Handlers_position as position, Handlers_q as q, Handlers_quality as quality, Handlers_resize as resize, Handlers_rotate as rotate, Handlers_s as s, Handlers_sharpen as sharpen, Handlers_threshold as threshold, Handlers_tint as tint, Handlers_trim as trim, Handlers_w as w, Handlers_width as width };
167
+ export {
168
+ Handlers_b as b,
169
+ Handlers_background as background,
170
+ Handlers_blur as blur,
171
+ Handlers_crop as crop,
172
+ Handlers_enlarge as enlarge,
173
+ Handlers_extend as extend,
174
+ Handlers_extract as extract,
175
+ Handlers_fit as fit,
176
+ Handlers_flatten as flatten,
177
+ Handlers_flip as flip,
178
+ Handlers_flop as flop,
179
+ Handlers_gamma as gamma,
180
+ Handlers_grayscale as grayscale,
181
+ Handlers_h as h,
182
+ Handlers_height as height,
183
+ Handlers_kernel as kernel,
184
+ Handlers_median as median,
185
+ Handlers_modulate as modulate,
186
+ Handlers_negate as negate,
187
+ Handlers_normalize as normalize,
188
+ Handlers_pos as pos,
189
+ Handlers_position as position,
190
+ Handlers_q as q,
191
+ Handlers_quality as quality,
192
+ Handlers_resize as resize,
193
+ Handlers_rotate as rotate,
194
+ Handlers_s as s,
195
+ Handlers_sharpen as sharpen,
196
+ Handlers_threshold as threshold,
197
+ Handlers_tint as tint,
198
+ Handlers_trim as trim,
199
+ Handlers_w as w,
200
+ Handlers_width as width,
201
+ };
102
202
  }
103
203
 
104
204
  type HandlerName = keyof typeof Handlers;
105
205
 
106
206
  type IPXSourceMeta = {
207
+ /**
208
+ * The modification time of the source. Used for cache validation.
209
+ * @optional
210
+ */
107
211
  mtime?: Date;
212
+ /**
213
+ * The maximum age (in seconds) that the source should be considered fresh.
214
+ * @optional
215
+ */
108
216
  maxAge?: number;
109
217
  };
218
+ /**
219
+ * A function type that defines an IPX image processing instance.
220
+ *
221
+ * This function takes an image identifier and optional modifiers and request options, then provides methods to retrieve
222
+ * image metadata and process the image according to the specified modifiers.
223
+ *
224
+ * @param {string} id - The identifier for the image. This can be a URL or a path, depending on the storage implementation.
225
+ * @param {partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>} [modifiers] - Modifiers to be applied to the image,
226
+ * such as resizing, cropping or format conversion. This record contains predefined keys such as 'f' or 'format' to specify the output to
227
+ * specify the output image format, and 'a' or 'animated' to specify whether the image should be processed as an animation. See
228
+ * {@link HandlerName}.
229
+ * @param {any} [requestOptions] - Additional options that may be needed for request handling, specific to the storage backend.
230
+ * Returns an object with methods:
231
+ * - `getSourceMeta`: A method that returns a promise resolving to the source image metadata (`IPXSourceMeta`).
232
+ * - `process`: A method that returns a promise resolving to an object containing the processed image data, metadata,
233
+ * and format. The image data can be in the form of a `buffer` or a string, depending on the format and processing.
234
+ */
110
235
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
111
236
  getSourceMeta: () => Promise<IPXSourceMeta>;
112
237
  process: () => Promise<{
@@ -116,43 +241,157 @@ type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format"
116
241
  }>;
117
242
  };
118
243
  type IPXOptions = {
244
+ /**
245
+ * Default cache duration in seconds. If not specified, a default of 1 minute is used.
246
+ * @optional
247
+ */
119
248
  maxAge?: number;
249
+ /**
250
+ * A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
251
+ * @optional
252
+ */
120
253
  alias?: Record<string, string>;
254
+ /**
255
+ * Configuration options for the Sharp image processing library.
256
+ * @optional
257
+ */
121
258
  sharpOptions?: SharpOptions;
259
+ /**
260
+ * Primary storage backend for handling image assets.
261
+ */
122
262
  storage: IPXStorage;
263
+ /**
264
+ * An optional secondary storage backend used when images are fetched via HTTP.
265
+ * @optional
266
+ */
123
267
  httpStorage?: IPXStorage;
268
+ /**
269
+ * Configuration for the SVGO library used when processing SVG images.
270
+ * @optional
271
+ */
124
272
  svgo?: false | Config;
125
273
  };
274
+ /**
275
+ * Creates an IPX image processing instance with the specified options.
276
+ * @param {IPXOptions} userOptions - Configuration options for the IPX instance. See {@link IPXOptions}.
277
+ * @returns {IPX} An IPX processing function configured with the given options. See {@link IPX}.
278
+ * @throws {Error} If critical options such as storage are missing or incorrectly configured.
279
+ */
126
280
  declare function createIPX(userOptions: IPXOptions): IPX;
127
281
 
128
- declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer | {
282
+ /**
283
+ * Creates an H3 handler to handle images using IPX.
284
+ * @param {IPX} ipx - An IPX instance to handle image requests.
285
+ * @returns {H3Event} An H3 event handler that processes image requests, applies modifiers, handles caching,
286
+ * and returns the processed image data. See {@link H3Event}.
287
+ * @throws {H3Error} If there are problems with the request parameters or processing the image. See {@link H3Error}.
288
+ */
289
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer<ArrayBufferLike> | {
129
290
  error: {
130
291
  message: string;
131
292
  };
132
293
  }>>;
294
+ /**
295
+ * Creates an H3 application configured to handle image processing using a supplied IPX instance.
296
+ * @param {IPX} ipx - An IPX instance to handle image handling requests.
297
+ * @returns {any} An H3 application configured to use the IPX image handler.
298
+ */
133
299
  declare function createIPXH3App(ipx: IPX): h3.App;
300
+ /**
301
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
302
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
303
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
304
+ */
134
305
  declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
306
+ /**
307
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
308
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
309
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
310
+ */
135
311
  declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
312
+ /**
313
+ * Creates a simple server that can handle IPX image processing requests using an H3 application.
314
+ * @param {IPX} ipx - An IPX instance configured for the server.
315
+ * @returns {any} A handler suitable for plain HTTP server environments that support the H3 library.
316
+ */
136
317
  declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
137
318
 
138
319
  type HTTPStorageOptions = {
320
+ /**
321
+ * Custom options for fetch operations, such as headers or method overrides.
322
+ * @optional
323
+ */
139
324
  fetchOptions?: RequestInit;
325
+ /**
326
+ * Default maximum age (in seconds) for cache control. If not specified, defaults to the environment setting or 300 seconds.
327
+ * @optional
328
+ */
140
329
  maxAge?: number;
330
+ /**
331
+ * Whitelist of domains from which resource fetching is allowed. Can be a single string or an array of strings.
332
+ * @optional
333
+ */
141
334
  domains?: string | string[];
335
+ /**
336
+ * If set to true, allows retrieval from any domain. Overrides the domain whitelist.
337
+ * @optional
338
+ */
142
339
  allowAllDomains?: boolean;
340
+ /**
341
+ * If set to true, ignore the cache control header in responses and use the default or specified maxAge.
342
+ * @optional
343
+ */
143
344
  ignoreCacheControl?: boolean;
144
345
  };
346
+ /**
347
+ * Creates an HTTP storage handler for IPX that fetches image data from external URLs.
348
+ * This handler allows configuration to specify allowed domains, caching behaviour and custom fetch options.
349
+ *
350
+ * @param {HTTPStorageOptions} [_options={}] - Configuration options for HTTP storage, with defaults possibly taken from environment variables. See {@link HTTPStorageOptions}.
351
+ * @returns {IPXStorage} An IPXStorage interface implementation for retrieving images over HTTP. See {@link IPXStorage}.
352
+ * @throws {H3Error} If validation of the requested URL fails due to a missing hostname or denied host access. See {@link H3Error}.
353
+ */
145
354
  declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
146
355
 
147
356
  type NodeFSSOptions = {
357
+ /**
358
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
359
+ * @optional
360
+ */
148
361
  dir?: string | string[];
362
+ /**
363
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
364
+ * @optional
365
+ */
149
366
  maxAge?: number;
150
367
  };
368
+ /**
369
+ * Creates a file system storage handler for IPX that allows images to be served from local directories specified in the options.
370
+ * This handler resolves directories and handles file access, ensuring that files are served safely.
371
+ *
372
+ * @param {NodeFSSOptions} [_options={}] - File system storage configuration options, with optional directory paths and caching configuration. See {@link NodeFSSOptions}.
373
+ * @returns {IPXStorage} An implementation of the IPXStorage interface for accessing images stored on the local file system. See {@link IPXStorage}.
374
+ * @throws {H3Error} If there is a problem accessing the file system module or resolving/reading files. See {@link H3Error}.
375
+ */
151
376
  declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
152
377
 
153
378
  type UnstorageIPXStorageOptions = {
379
+ /**
380
+ * Optional prefix to be placed in front of each storage key, which can help to name or categorise stored items.
381
+ * @optional
382
+ */
154
383
  prefix?: string;
155
384
  };
385
+ /**
386
+ * Adapts an Unstorage driver or storage system to comply with the IPXStorage interface required by IPX.
387
+ * This allows various Unstorage-compatible storage systems to be used to manage image data with IPX.
388
+ *
389
+ * @param {Storage | Driver} storage - The Unstorage driver or storage instance to adapt. See {@link Storage} and {@link Driver}.
390
+ * @param {UnstorageIPXStorageOptions | string} [_options={}] - Configuration options for the adapter, which can be a simple string prefix or an options object. See {@link UnstorageIPXStorageOptions}.
391
+ * @returns {IPXStorage}. An IPXStorage compliant object that implements the necessary methods to interact with the provided unstorage driver or storage system. See {@link IPXStorage}.
392
+ * @throws {H3Error} If there is a problem retrieving or converting the storage data, detailed error information is thrown. See {@link H3Error}.
393
+ */
156
394
  declare function unstorageToIPXStorage(storage: Storage | Driver, _options?: UnstorageIPXStorageOptions | string): IPXStorage;
157
395
 
158
- export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type NodeFSSOptions, type UnstorageIPXStorageOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
396
+ export { createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
397
+ export type { HTTPStorageOptions, Handler, HandlerContext, IPX, IPXOptions, IPXStorage, IPXStorageMeta, IPXStorageOptions, NodeFSSOptions, UnstorageIPXStorageOptions };
package/dist/index.d.ts CHANGED
@@ -5,28 +5,94 @@ import * as h3 from 'h3';
5
5
  import { Storage, Driver } from 'unstorage';
6
6
 
7
7
  interface HandlerContext {
8
+ /**
9
+ * Optional quality setting for the output image, affects compression in certain formats.
10
+ * @optional
11
+ */
8
12
  quality?: number;
13
+ /**
14
+ * Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
15
+ * @optional
16
+ */
9
17
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
18
+ /**
19
+ * The position used for cropping or positioning, specified as a number or string.
20
+ * @optional
21
+ */
10
22
  position?: number | string;
23
+ /**
24
+ * Background colour to be used if necessary, provided as a colour object. See {@link Color}.
25
+ * @optional
26
+ */
11
27
  background?: Color;
28
+ /**
29
+ * Specifies whether to enlarge the image if it is smaller than the desired size.
30
+ * @optional
31
+ */
12
32
  enlarge?: boolean;
33
+ /**
34
+ * The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
35
+ * @optional
36
+ */
13
37
  kernel?: keyof KernelEnum;
38
+ /**
39
+ * Metadata about the image being processed.
40
+ */
14
41
  meta: ImageMeta;
15
42
  }
16
43
  interface Handler {
44
+ /**
45
+ * An array of functions that convert the given string arguments into usable forms.
46
+ */
17
47
  args: ((argument: string) => any)[];
48
+ /**
49
+ * Defines the order in which this handler should be applied relative to other handlers.
50
+ * @optional
51
+ */
18
52
  order?: number;
53
+ /**
54
+ * Function to apply the effects of this handler to the image pipeline.
55
+ * @param {HandlerContext} context - The current image processing context. See {@link HandlerContext}.
56
+ * @param {Sharp} pipe - The Sharp instance to use for image processing. See {@link Sharp}.
57
+ * @param {...any} arguments_ - Transformed arguments to use in the handler.
58
+ */
19
59
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
20
60
  }
21
61
  type IPXStorageMeta = {
62
+ /**
63
+ * The modification time of the stored item.
64
+ * @optional
65
+ */
22
66
  mtime?: Date | number | string;
67
+ /**
68
+ * The maximum age (in seconds) at which the stored item should be considered fresh.
69
+ * @optional
70
+ */
23
71
  maxAge?: number | string;
24
72
  };
73
+ /**
74
+ * Options specific to image saving operations.
75
+ */
25
76
  type IPXStorageOptions = Record<string, unknown>;
26
77
  type MaybePromise<T> = T | Promise<T>;
27
78
  interface IPXStorage {
79
+ /**
80
+ * A descriptive name for the storage type.
81
+ */
28
82
  name: string;
83
+ /**
84
+ * Retrieves metadata for an image identified by 'id'.
85
+ * @param {string} id - The identifier for the image.
86
+ * @param {IPXStorageOptions} [opts] - Optional metadata retrieval options. See {@link IPXStorageOptions}.
87
+ * @returns {MaybePromise<IPXStorageMeta | undefined>} A promise or direct return of the metadata, or undefined if not found. See {@link IPXStorageMeta}.
88
+ */
29
89
  getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
90
+ /**
91
+ * Get the actual data for an image identified by 'id'.
92
+ * @param {string} id - The identifier for the image.
93
+ * @param {IPXStorageOptions} [opts] - Optional options for the data retrieval. See {@link IPXStorageOptions}.
94
+ * @returns {MaybePromise<ArrayBuffer | undefined>} A promise or direct return of the image data as an ArrayBuffer, or undefined if not found. See {@link ArrayBuffer}.
95
+ */
30
96
  getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
31
97
  }
32
98
 
@@ -98,15 +164,74 @@ declare const Handlers_trim: typeof trim;
98
164
  declare const Handlers_w: typeof w;
99
165
  declare const Handlers_width: typeof width;
100
166
  declare namespace Handlers {
101
- export { Handlers_b as b, Handlers_background as background, Handlers_blur as blur, Handlers_crop as crop, Handlers_enlarge as enlarge, Handlers_extend as extend, Handlers_extract as extract, Handlers_fit as fit, Handlers_flatten as flatten, Handlers_flip as flip, Handlers_flop as flop, Handlers_gamma as gamma, Handlers_grayscale as grayscale, Handlers_h as h, Handlers_height as height, Handlers_kernel as kernel, Handlers_median as median, Handlers_modulate as modulate, Handlers_negate as negate, Handlers_normalize as normalize, Handlers_pos as pos, Handlers_position as position, Handlers_q as q, Handlers_quality as quality, Handlers_resize as resize, Handlers_rotate as rotate, Handlers_s as s, Handlers_sharpen as sharpen, Handlers_threshold as threshold, Handlers_tint as tint, Handlers_trim as trim, Handlers_w as w, Handlers_width as width };
167
+ export {
168
+ Handlers_b as b,
169
+ Handlers_background as background,
170
+ Handlers_blur as blur,
171
+ Handlers_crop as crop,
172
+ Handlers_enlarge as enlarge,
173
+ Handlers_extend as extend,
174
+ Handlers_extract as extract,
175
+ Handlers_fit as fit,
176
+ Handlers_flatten as flatten,
177
+ Handlers_flip as flip,
178
+ Handlers_flop as flop,
179
+ Handlers_gamma as gamma,
180
+ Handlers_grayscale as grayscale,
181
+ Handlers_h as h,
182
+ Handlers_height as height,
183
+ Handlers_kernel as kernel,
184
+ Handlers_median as median,
185
+ Handlers_modulate as modulate,
186
+ Handlers_negate as negate,
187
+ Handlers_normalize as normalize,
188
+ Handlers_pos as pos,
189
+ Handlers_position as position,
190
+ Handlers_q as q,
191
+ Handlers_quality as quality,
192
+ Handlers_resize as resize,
193
+ Handlers_rotate as rotate,
194
+ Handlers_s as s,
195
+ Handlers_sharpen as sharpen,
196
+ Handlers_threshold as threshold,
197
+ Handlers_tint as tint,
198
+ Handlers_trim as trim,
199
+ Handlers_w as w,
200
+ Handlers_width as width,
201
+ };
102
202
  }
103
203
 
104
204
  type HandlerName = keyof typeof Handlers;
105
205
 
106
206
  type IPXSourceMeta = {
207
+ /**
208
+ * The modification time of the source. Used for cache validation.
209
+ * @optional
210
+ */
107
211
  mtime?: Date;
212
+ /**
213
+ * The maximum age (in seconds) that the source should be considered fresh.
214
+ * @optional
215
+ */
108
216
  maxAge?: number;
109
217
  };
218
+ /**
219
+ * A function type that defines an IPX image processing instance.
220
+ *
221
+ * This function takes an image identifier and optional modifiers and request options, then provides methods to retrieve
222
+ * image metadata and process the image according to the specified modifiers.
223
+ *
224
+ * @param {string} id - The identifier for the image. This can be a URL or a path, depending on the storage implementation.
225
+ * @param {partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>} [modifiers] - Modifiers to be applied to the image,
226
+ * such as resizing, cropping or format conversion. This record contains predefined keys such as 'f' or 'format' to specify the output to
227
+ * specify the output image format, and 'a' or 'animated' to specify whether the image should be processed as an animation. See
228
+ * {@link HandlerName}.
229
+ * @param {any} [requestOptions] - Additional options that may be needed for request handling, specific to the storage backend.
230
+ * Returns an object with methods:
231
+ * - `getSourceMeta`: A method that returns a promise resolving to the source image metadata (`IPXSourceMeta`).
232
+ * - `process`: A method that returns a promise resolving to an object containing the processed image data, metadata,
233
+ * and format. The image data can be in the form of a `buffer` or a string, depending on the format and processing.
234
+ */
110
235
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
111
236
  getSourceMeta: () => Promise<IPXSourceMeta>;
112
237
  process: () => Promise<{
@@ -116,43 +241,157 @@ type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format"
116
241
  }>;
117
242
  };
118
243
  type IPXOptions = {
244
+ /**
245
+ * Default cache duration in seconds. If not specified, a default of 1 minute is used.
246
+ * @optional
247
+ */
119
248
  maxAge?: number;
249
+ /**
250
+ * A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
251
+ * @optional
252
+ */
120
253
  alias?: Record<string, string>;
254
+ /**
255
+ * Configuration options for the Sharp image processing library.
256
+ * @optional
257
+ */
121
258
  sharpOptions?: SharpOptions;
259
+ /**
260
+ * Primary storage backend for handling image assets.
261
+ */
122
262
  storage: IPXStorage;
263
+ /**
264
+ * An optional secondary storage backend used when images are fetched via HTTP.
265
+ * @optional
266
+ */
123
267
  httpStorage?: IPXStorage;
268
+ /**
269
+ * Configuration for the SVGO library used when processing SVG images.
270
+ * @optional
271
+ */
124
272
  svgo?: false | Config;
125
273
  };
274
+ /**
275
+ * Creates an IPX image processing instance with the specified options.
276
+ * @param {IPXOptions} userOptions - Configuration options for the IPX instance. See {@link IPXOptions}.
277
+ * @returns {IPX} An IPX processing function configured with the given options. See {@link IPX}.
278
+ * @throws {Error} If critical options such as storage are missing or incorrectly configured.
279
+ */
126
280
  declare function createIPX(userOptions: IPXOptions): IPX;
127
281
 
128
- declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer | {
282
+ /**
283
+ * Creates an H3 handler to handle images using IPX.
284
+ * @param {IPX} ipx - An IPX instance to handle image requests.
285
+ * @returns {H3Event} An H3 event handler that processes image requests, applies modifiers, handles caching,
286
+ * and returns the processed image data. See {@link H3Event}.
287
+ * @throws {H3Error} If there are problems with the request parameters or processing the image. See {@link H3Error}.
288
+ */
289
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer<ArrayBufferLike> | {
129
290
  error: {
130
291
  message: string;
131
292
  };
132
293
  }>>;
294
+ /**
295
+ * Creates an H3 application configured to handle image processing using a supplied IPX instance.
296
+ * @param {IPX} ipx - An IPX instance to handle image handling requests.
297
+ * @returns {any} An H3 application configured to use the IPX image handler.
298
+ */
133
299
  declare function createIPXH3App(ipx: IPX): h3.App;
300
+ /**
301
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
302
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
303
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
304
+ */
134
305
  declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
306
+ /**
307
+ * Creates a web server that can handle IPX image processing requests using an H3 application.
308
+ * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
309
+ * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
310
+ */
135
311
  declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
312
+ /**
313
+ * Creates a simple server that can handle IPX image processing requests using an H3 application.
314
+ * @param {IPX} ipx - An IPX instance configured for the server.
315
+ * @returns {any} A handler suitable for plain HTTP server environments that support the H3 library.
316
+ */
136
317
  declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
137
318
 
138
319
  type HTTPStorageOptions = {
320
+ /**
321
+ * Custom options for fetch operations, such as headers or method overrides.
322
+ * @optional
323
+ */
139
324
  fetchOptions?: RequestInit;
325
+ /**
326
+ * Default maximum age (in seconds) for cache control. If not specified, defaults to the environment setting or 300 seconds.
327
+ * @optional
328
+ */
140
329
  maxAge?: number;
330
+ /**
331
+ * Whitelist of domains from which resource fetching is allowed. Can be a single string or an array of strings.
332
+ * @optional
333
+ */
141
334
  domains?: string | string[];
335
+ /**
336
+ * If set to true, allows retrieval from any domain. Overrides the domain whitelist.
337
+ * @optional
338
+ */
142
339
  allowAllDomains?: boolean;
340
+ /**
341
+ * If set to true, ignore the cache control header in responses and use the default or specified maxAge.
342
+ * @optional
343
+ */
143
344
  ignoreCacheControl?: boolean;
144
345
  };
346
+ /**
347
+ * Creates an HTTP storage handler for IPX that fetches image data from external URLs.
348
+ * This handler allows configuration to specify allowed domains, caching behaviour and custom fetch options.
349
+ *
350
+ * @param {HTTPStorageOptions} [_options={}] - Configuration options for HTTP storage, with defaults possibly taken from environment variables. See {@link HTTPStorageOptions}.
351
+ * @returns {IPXStorage} An IPXStorage interface implementation for retrieving images over HTTP. See {@link IPXStorage}.
352
+ * @throws {H3Error} If validation of the requested URL fails due to a missing hostname or denied host access. See {@link H3Error}.
353
+ */
145
354
  declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
146
355
 
147
356
  type NodeFSSOptions = {
357
+ /**
358
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
359
+ * @optional
360
+ */
148
361
  dir?: string | string[];
362
+ /**
363
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
364
+ * @optional
365
+ */
149
366
  maxAge?: number;
150
367
  };
368
+ /**
369
+ * Creates a file system storage handler for IPX that allows images to be served from local directories specified in the options.
370
+ * This handler resolves directories and handles file access, ensuring that files are served safely.
371
+ *
372
+ * @param {NodeFSSOptions} [_options={}] - File system storage configuration options, with optional directory paths and caching configuration. See {@link NodeFSSOptions}.
373
+ * @returns {IPXStorage} An implementation of the IPXStorage interface for accessing images stored on the local file system. See {@link IPXStorage}.
374
+ * @throws {H3Error} If there is a problem accessing the file system module or resolving/reading files. See {@link H3Error}.
375
+ */
151
376
  declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
152
377
 
153
378
  type UnstorageIPXStorageOptions = {
379
+ /**
380
+ * Optional prefix to be placed in front of each storage key, which can help to name or categorise stored items.
381
+ * @optional
382
+ */
154
383
  prefix?: string;
155
384
  };
385
+ /**
386
+ * Adapts an Unstorage driver or storage system to comply with the IPXStorage interface required by IPX.
387
+ * This allows various Unstorage-compatible storage systems to be used to manage image data with IPX.
388
+ *
389
+ * @param {Storage | Driver} storage - The Unstorage driver or storage instance to adapt. See {@link Storage} and {@link Driver}.
390
+ * @param {UnstorageIPXStorageOptions | string} [_options={}] - Configuration options for the adapter, which can be a simple string prefix or an options object. See {@link UnstorageIPXStorageOptions}.
391
+ * @returns {IPXStorage}. An IPXStorage compliant object that implements the necessary methods to interact with the provided unstorage driver or storage system. See {@link IPXStorage}.
392
+ * @throws {H3Error} If there is a problem retrieving or converting the storage data, detailed error information is thrown. See {@link H3Error}.
393
+ */
156
394
  declare function unstorageToIPXStorage(storage: Storage | Driver, _options?: UnstorageIPXStorageOptions | string): IPXStorage;
157
395
 
158
- export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type NodeFSSOptions, type UnstorageIPXStorageOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
396
+ export { createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
397
+ export type { HTTPStorageOptions, Handler, HandlerContext, IPX, IPXOptions, IPXStorage, IPXStorageMeta, IPXStorageOptions, NodeFSSOptions, UnstorageIPXStorageOptions };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { c as createIPX, b as createIPXH3App, a as createIPXH3Handler, e as createIPXNodeServer, f as createIPXPlainServer, d as createIPXWebServer, g as ipxFSStorage, i as ipxHttpStorage } from './shared/ipx.90a2d420.mjs';
1
+ export { c as createIPX, b as createIPXH3App, a as createIPXH3Handler, e as createIPXNodeServer, f as createIPXPlainServer, d as createIPXWebServer, g as ipxFSStorage, i as ipxHttpStorage } from './shared/ipx.CTj1EgBv.mjs';
2
2
  import { createError } from 'h3';
3
3
  import 'defu';
4
4
  import 'ufo';
@@ -501,9 +501,12 @@ function createIPXH3Handler(ipx) {
501
501
  const mFormat = modifiers.f || modifiers.format;
502
502
  if (mFormat === "auto") {
503
503
  const acceptHeader = h3.getRequestHeader(event, "accept") || "";
504
+ const animated = modifiers.animated ?? modifiers.a;
504
505
  const autoFormat = autoDetectFormat(
505
506
  acceptHeader,
506
- !!(modifiers.a || modifiers.animated)
507
+ // #234 "animated" param adds {animated: ''} to the modifiers
508
+ // TODO: fix modifiers to normalized to boolean
509
+ !!animated || animated === ""
507
510
  );
508
511
  delete modifiers.f;
509
512
  delete modifiers.format;
@@ -1,6 +1,6 @@
1
1
  import { defu } from 'defu';
2
2
  import { withLeadingSlash, hasProtocol, joinURL, decode } from 'ufo';
3
- import { createError, defineEventHandler, setResponseStatus, createApp, toWebHandler, toNodeListener, toPlainHandler, getRequestHeader, appendResponseHeader, send, getResponseHeader, setResponseHeader } from 'h3';
3
+ import { createError, toNodeListener, createApp, defineEventHandler, setResponseStatus, getRequestHeader, appendResponseHeader, send, getResponseHeader, setResponseHeader, toWebHandler, toPlainHandler } from 'h3';
4
4
  import { imageMeta } from 'image-meta';
5
5
  import destr from 'destr';
6
6
  import { negotiate } from '@fastify/accept-negotiator';
@@ -494,9 +494,12 @@ function createIPXH3Handler(ipx) {
494
494
  const mFormat = modifiers.f || modifiers.format;
495
495
  if (mFormat === "auto") {
496
496
  const acceptHeader = getRequestHeader(event, "accept") || "";
497
+ const animated = modifiers.animated ?? modifiers.a;
497
498
  const autoFormat = autoDetectFormat(
498
499
  acceptHeader,
499
- !!(modifiers.a || modifiers.animated)
500
+ // #234 "animated" param adds {animated: ''} to the modifiers
501
+ // TODO: fix modifiers to normalized to boolean
502
+ !!animated || animated === ""
500
503
  );
501
504
  delete modifiers.f;
502
505
  delete modifiers.format;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipx",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "repository": "unjs/ipx",
5
5
  "description": "High performance, secure and easy-to-use image optimizer.",
6
6
  "license": "MIT",
@@ -28,45 +28,45 @@
28
28
  "build": "unbuild",
29
29
  "dev": "listhen -w playground",
30
30
  "ipx": "jiti ./src/cli.ts",
31
- "lint": "eslint --ext .ts . && prettier -c src test",
32
- "lint:fix": "eslint --ext .ts . --fix && prettier -w src test",
31
+ "lint": "eslint . && prettier -c src test",
32
+ "lint:fix": "eslint . --fix && prettier -w src test",
33
33
  "prepack": "pnpm build",
34
34
  "release": "pnpm test && changelogen --release --push && npm publish",
35
- "prerelease": "pnpm test && pnpm build && changelogen --release --prerelease --push --publish --publishTag latest",
35
+ "prerelease": "pnpm test && pnpm build && changelogen --release --push --publish --publishTag latest",
36
36
  "start": "node bin/ipx.js",
37
37
  "test": "pnpm lint && vitest run --coverage"
38
38
  },
39
39
  "dependencies": {
40
- "@fastify/accept-negotiator": "^1.1.0",
41
- "citty": "^0.1.5",
42
- "consola": "^3.2.3",
40
+ "@fastify/accept-negotiator": "^2.0.1",
41
+ "citty": "^0.1.6",
42
+ "consola": "^3.4.2",
43
43
  "defu": "^6.1.4",
44
- "destr": "^2.0.2",
44
+ "destr": "^2.0.3",
45
45
  "etag": "^1.8.1",
46
- "h3": "^1.10.1",
47
- "image-meta": "^0.2.0",
48
- "listhen": "^1.6.0",
49
- "ofetch": "^1.3.3",
50
- "pathe": "^1.1.2",
51
- "sharp": "^0.33.2",
52
- "svgo": "^3.2.0",
53
- "ufo": "^1.4.0",
54
- "unstorage": "^1.10.1",
55
- "xss": "^1.0.14"
46
+ "h3": "^1.15.1",
47
+ "image-meta": "^0.2.1",
48
+ "listhen": "^1.9.0",
49
+ "ofetch": "^1.4.1",
50
+ "pathe": "^2.0.3",
51
+ "sharp": "^0.33.5",
52
+ "svgo": "^3.3.2",
53
+ "ufo": "^1.5.4",
54
+ "unstorage": "^1.15.0",
55
+ "xss": "^1.0.15"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/etag": "^1.8.3",
59
59
  "@types/is-valid-path": "^0.1.2",
60
- "@vitest/coverage-v8": "^1.2.2",
61
- "changelogen": "^0.5.5",
62
- "eslint": "^8.56.0",
63
- "eslint-config-unjs": "^0.2.1",
64
- "jiti": "^1.21.0",
65
- "prettier": "^3.2.5",
66
- "serve-handler": "^6.1.5",
67
- "typescript": "^5.3.3",
68
- "unbuild": "^2.0.0",
69
- "vitest": "^1.2.2"
60
+ "@vitest/coverage-v8": "^3.0.9",
61
+ "changelogen": "^0.6.1",
62
+ "eslint": "^9.22.0",
63
+ "eslint-config-unjs": "^0.4.2",
64
+ "jiti": "^2.4.2",
65
+ "prettier": "^3.5.3",
66
+ "serve-handler": "^6.1.6",
67
+ "typescript": "^5.8.2",
68
+ "unbuild": "^3.5.0",
69
+ "vitest": "^3.0.9"
70
70
  },
71
- "packageManager": "pnpm@8.15.2"
72
- }
71
+ "packageManager": "pnpm@10.6.5"
72
+ }