ipx 3.1.1 → 4.0.0-alpha.2
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 +69 -42
- package/dist/THIRD-PARTY-LICENSES.md +539 -0
- package/dist/_chunks/libs/@fastify/accept-negotiator.mjs +71 -0
- package/dist/_chunks/libs/boolbase.mjs +12 -0
- package/dist/_chunks/libs/css-select.mjs +4139 -0
- package/dist/_chunks/libs/css-tree.mjs +31158 -0
- package/dist/_chunks/libs/csso.mjs +1834 -0
- package/dist/_chunks/libs/etag.mjs +25 -0
- package/dist/_chunks/libs/h3.mjs +267 -0
- package/dist/_chunks/libs/image-meta.d.mts +12 -0
- package/dist/_chunks/libs/image-meta.mjs +558 -0
- package/dist/_chunks/libs/sax.mjs +836 -0
- package/dist/_chunks/libs/svgo.mjs +5918 -0
- package/dist/_chunks/libs/ufo.mjs +41 -0
- package/dist/_chunks/node-fs.mjs +690 -0
- package/dist/_chunks/rolldown-runtime.mjs +42 -0
- package/dist/_chunks/svgo-node.mjs +3 -0
- package/dist/cli.d.mts +1 -2
- package/dist/cli.mjs +67 -59
- package/dist/index.d.mts +214 -321
- package/dist/index.mjs +30 -50
- package/package.json +44 -49
- package/bin/ipx.mjs +0 -2
- package/dist/cli.cjs +0 -63
- package/dist/cli.d.cts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/index.cjs +0 -62
- package/dist/index.d.cts +0 -397
- package/dist/index.d.ts +0 -397
- package/dist/shared/ipx.CXJeaylD.mjs +0 -764
- package/dist/shared/ipx.GUc23orS.cjs +0 -778
package/package.json
CHANGED
|
@@ -1,71 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ipx",
|
|
3
|
-
"version": "
|
|
4
|
-
"repository": "unjs/ipx",
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
5
4
|
"description": "High performance, secure and easy-to-use image optimizer.",
|
|
5
|
+
"repository": "unjs/ipx",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
7
9
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"types": "./dist/index.d.cts",
|
|
15
|
-
"default": "./dist/index.cjs"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"bin": {
|
|
15
|
+
"ipx": "./dist/cli.mjs"
|
|
18
16
|
},
|
|
19
|
-
"main": "./dist/index.cjs",
|
|
20
|
-
"module": "./dist/index.mjs",
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
|
-
"bin": "./bin/ipx.mjs",
|
|
23
17
|
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
"bin"
|
|
18
|
+
"dist"
|
|
26
19
|
],
|
|
27
20
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"
|
|
30
|
-
"ipx": "jiti ./src/cli.ts",
|
|
21
|
+
"build": "obuild",
|
|
22
|
+
"ipx": "node ./src/cli.ts",
|
|
31
23
|
"lint": "eslint . && prettier -c src test",
|
|
32
|
-
"lint:fix": "eslint . --fix && prettier -w src test",
|
|
24
|
+
"lint:fix": "automd && eslint . --fix && prettier -w src test",
|
|
33
25
|
"prepack": "pnpm build",
|
|
34
|
-
"release": "pnpm test && changelogen --release --
|
|
26
|
+
"release": "pnpm test && pnpm build && changelogen --release --prerelease --publish --publishTag alpha --push",
|
|
35
27
|
"start": "node bin/ipx.js",
|
|
36
|
-
"test": "pnpm lint && vitest run --coverage"
|
|
28
|
+
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
29
|
+
"test:types": "tsc --noEmit"
|
|
37
30
|
},
|
|
38
31
|
"dependencies": {
|
|
39
|
-
"@fastify/accept-negotiator": "^2.0.1",
|
|
40
|
-
"citty": "^0.1.6",
|
|
41
|
-
"consola": "^3.4.2",
|
|
42
|
-
"defu": "^6.1.4",
|
|
43
|
-
"destr": "^2.0.5",
|
|
44
|
-
"etag": "^1.8.1",
|
|
45
|
-
"h3": "^1.15.3",
|
|
46
|
-
"image-meta": "^0.2.1",
|
|
47
|
-
"listhen": "^1.9.0",
|
|
48
|
-
"ofetch": "^1.4.1",
|
|
49
32
|
"pathe": "^2.0.3",
|
|
50
|
-
"sharp": "^0.
|
|
51
|
-
"
|
|
52
|
-
"ufo": "^1.6.1",
|
|
53
|
-
"unstorage": "^1.16.1",
|
|
54
|
-
"xss": "^1.0.15"
|
|
33
|
+
"sharp": "^0.35.2",
|
|
34
|
+
"srvx": "^0.11.17"
|
|
55
35
|
},
|
|
56
36
|
"devDependencies": {
|
|
37
|
+
"@fastify/accept-negotiator": "^2.0.1",
|
|
57
38
|
"@types/etag": "^1.8.4",
|
|
58
39
|
"@types/is-valid-path": "^0.1.2",
|
|
59
|
-
"@vitest/coverage-v8": "^
|
|
40
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
41
|
+
"automd": "^0.4.3",
|
|
60
42
|
"changelogen": "^0.6.2",
|
|
61
|
-
"eslint": "^
|
|
62
|
-
"eslint-config-unjs": "^0.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
43
|
+
"eslint": "^10.5.0",
|
|
44
|
+
"eslint-config-unjs": "^0.6.2",
|
|
45
|
+
"etag": "^1.8.1",
|
|
46
|
+
"h3": "2.0.1-rc.22",
|
|
47
|
+
"image-meta": "^0.2.2",
|
|
48
|
+
"obuild": "^0.4.37",
|
|
49
|
+
"oxc-minify": "^0.137.0",
|
|
50
|
+
"prettier": "^3.8.4",
|
|
51
|
+
"svgo": "^4.0.1",
|
|
52
|
+
"typescript": "^6.0.3",
|
|
53
|
+
"ufo": "^1.6.4",
|
|
54
|
+
"unstorage": "^1.17.5",
|
|
55
|
+
"vitest": "^4.1.9"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"unstorage": "*"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"unstorage": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
69
64
|
},
|
|
70
|
-
"packageManager": "pnpm@
|
|
65
|
+
"packageManager": "pnpm@11.9.0"
|
|
71
66
|
}
|
package/bin/ipx.mjs
DELETED
package/dist/cli.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const listhen = require('listhen');
|
|
4
|
-
const citty = require('citty');
|
|
5
|
-
const cli = require('listhen/cli');
|
|
6
|
-
const nodeFs = require('./shared/ipx.GUc23orS.cjs');
|
|
7
|
-
require('defu');
|
|
8
|
-
require('ufo');
|
|
9
|
-
require('h3');
|
|
10
|
-
require('image-meta');
|
|
11
|
-
require('destr');
|
|
12
|
-
require('@fastify/accept-negotiator');
|
|
13
|
-
require('etag');
|
|
14
|
-
require('ofetch');
|
|
15
|
-
require('pathe');
|
|
16
|
-
|
|
17
|
-
const name = "ipx";
|
|
18
|
-
const version = "3.1.1";
|
|
19
|
-
const description = "High performance, secure and easy-to-use image optimizer.";
|
|
20
|
-
|
|
21
|
-
const serve = citty.defineCommand({
|
|
22
|
-
meta: {
|
|
23
|
-
description: "Start IPX Server"
|
|
24
|
-
},
|
|
25
|
-
args: {
|
|
26
|
-
dir: {
|
|
27
|
-
type: "string",
|
|
28
|
-
required: false,
|
|
29
|
-
description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
|
|
30
|
-
},
|
|
31
|
-
domains: {
|
|
32
|
-
type: "string",
|
|
33
|
-
required: false,
|
|
34
|
-
description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
|
|
35
|
-
},
|
|
36
|
-
...cli.getArgs()
|
|
37
|
-
},
|
|
38
|
-
async run({ args }) {
|
|
39
|
-
const ipx = nodeFs.createIPX({
|
|
40
|
-
storage: nodeFs.ipxFSStorage({
|
|
41
|
-
dir: args.dir
|
|
42
|
-
}),
|
|
43
|
-
httpStorage: nodeFs.ipxHttpStorage({
|
|
44
|
-
domains: args.domains
|
|
45
|
-
})
|
|
46
|
-
});
|
|
47
|
-
await listhen.listen(nodeFs.createIPXNodeServer(ipx), {
|
|
48
|
-
name: "IPX",
|
|
49
|
-
...cli.parseArgs(args)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const main = citty.defineCommand({
|
|
54
|
-
meta: {
|
|
55
|
-
name,
|
|
56
|
-
version,
|
|
57
|
-
description
|
|
58
|
-
},
|
|
59
|
-
subCommands: {
|
|
60
|
-
serve
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
citty.runMain(main);
|
package/dist/cli.d.cts
DELETED
package/dist/cli.d.ts
DELETED
package/dist/index.cjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const nodeFs = require('./shared/ipx.GUc23orS.cjs');
|
|
4
|
-
const h3 = require('h3');
|
|
5
|
-
require('defu');
|
|
6
|
-
require('ufo');
|
|
7
|
-
require('image-meta');
|
|
8
|
-
require('destr');
|
|
9
|
-
require('@fastify/accept-negotiator');
|
|
10
|
-
require('etag');
|
|
11
|
-
require('ofetch');
|
|
12
|
-
require('pathe');
|
|
13
|
-
|
|
14
|
-
function unstorageToIPXStorage(storage, _options = {}) {
|
|
15
|
-
const options = typeof _options === "string" ? { prefix: _options } : _options;
|
|
16
|
-
const resolveKey = (id) => options.prefix ? `${options.prefix}:${id}` : id;
|
|
17
|
-
return {
|
|
18
|
-
name: "ipx:" + (storage.name || "unstorage"),
|
|
19
|
-
async getMeta(id, opts = {}) {
|
|
20
|
-
if (!storage.getMeta) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const storageKey = resolveKey(id);
|
|
24
|
-
const meta = await storage.getMeta(storageKey, opts);
|
|
25
|
-
return meta;
|
|
26
|
-
},
|
|
27
|
-
async getData(id, opts = {}) {
|
|
28
|
-
if (!storage.getItemRaw) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const storageKey = resolveKey(id);
|
|
32
|
-
let data = await storage.getItemRaw(storageKey, opts);
|
|
33
|
-
if (!data) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (data instanceof Blob) {
|
|
37
|
-
data = await data.arrayBuffer();
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
return Buffer.from(data);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw h3.createError({
|
|
43
|
-
statusCode: 500,
|
|
44
|
-
statusText: `IPX_STORAGE_ERROR`,
|
|
45
|
-
message: `Failed to parse storage data to Buffer:
|
|
46
|
-
${error.message}`,
|
|
47
|
-
cause: error
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
exports.createIPX = nodeFs.createIPX;
|
|
55
|
-
exports.createIPXH3App = nodeFs.createIPXH3App;
|
|
56
|
-
exports.createIPXH3Handler = nodeFs.createIPXH3Handler;
|
|
57
|
-
exports.createIPXNodeServer = nodeFs.createIPXNodeServer;
|
|
58
|
-
exports.createIPXPlainServer = nodeFs.createIPXPlainServer;
|
|
59
|
-
exports.createIPXWebServer = nodeFs.createIPXWebServer;
|
|
60
|
-
exports.ipxFSStorage = nodeFs.ipxFSStorage;
|
|
61
|
-
exports.ipxHttpStorage = nodeFs.ipxHttpStorage;
|
|
62
|
-
exports.unstorageToIPXStorage = unstorageToIPXStorage;
|
package/dist/index.d.cts
DELETED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp';
|
|
2
|
-
import { ImageMeta } from 'image-meta';
|
|
3
|
-
import { Config } from 'svgo';
|
|
4
|
-
import * as h3 from 'h3';
|
|
5
|
-
import { Storage, Driver } from 'unstorage';
|
|
6
|
-
|
|
7
|
-
interface HandlerContext {
|
|
8
|
-
/**
|
|
9
|
-
* Optional quality setting for the output image, affects compression in certain formats.
|
|
10
|
-
* @optional
|
|
11
|
-
*/
|
|
12
|
-
quality?: number;
|
|
13
|
-
/**
|
|
14
|
-
* Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
|
|
15
|
-
* @optional
|
|
16
|
-
*/
|
|
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
|
-
*/
|
|
22
|
-
position?: number | string;
|
|
23
|
-
/**
|
|
24
|
-
* Background colour to be used if necessary, provided as a colour object. See {@link Color}.
|
|
25
|
-
* @optional
|
|
26
|
-
*/
|
|
27
|
-
background?: Color;
|
|
28
|
-
/**
|
|
29
|
-
* Specifies whether to enlarge the image if it is smaller than the desired size.
|
|
30
|
-
* @optional
|
|
31
|
-
*/
|
|
32
|
-
enlarge?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
|
|
35
|
-
* @optional
|
|
36
|
-
*/
|
|
37
|
-
kernel?: keyof KernelEnum;
|
|
38
|
-
/**
|
|
39
|
-
* Metadata about the image being processed.
|
|
40
|
-
*/
|
|
41
|
-
meta: ImageMeta;
|
|
42
|
-
}
|
|
43
|
-
interface Handler {
|
|
44
|
-
/**
|
|
45
|
-
* An array of functions that convert the given string arguments into usable forms.
|
|
46
|
-
*/
|
|
47
|
-
args: ((argument: string) => any)[];
|
|
48
|
-
/**
|
|
49
|
-
* Defines the order in which this handler should be applied relative to other handlers.
|
|
50
|
-
* @optional
|
|
51
|
-
*/
|
|
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
|
-
*/
|
|
59
|
-
apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
|
|
60
|
-
}
|
|
61
|
-
type IPXStorageMeta = {
|
|
62
|
-
/**
|
|
63
|
-
* The modification time of the stored item.
|
|
64
|
-
* @optional
|
|
65
|
-
*/
|
|
66
|
-
mtime?: Date | number | string;
|
|
67
|
-
/**
|
|
68
|
-
* The maximum age (in seconds) at which the stored item should be considered fresh.
|
|
69
|
-
* @optional
|
|
70
|
-
*/
|
|
71
|
-
maxAge?: number | string;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Options specific to image saving operations.
|
|
75
|
-
*/
|
|
76
|
-
type IPXStorageOptions = Record<string, unknown>;
|
|
77
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
78
|
-
interface IPXStorage {
|
|
79
|
-
/**
|
|
80
|
-
* A descriptive name for the storage type.
|
|
81
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
96
|
-
getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
declare const quality: Handler;
|
|
100
|
-
declare const fit: Handler;
|
|
101
|
-
declare const position: Handler;
|
|
102
|
-
declare const background: Handler;
|
|
103
|
-
declare const enlarge: Handler;
|
|
104
|
-
declare const kernel: Handler;
|
|
105
|
-
declare const width: Handler;
|
|
106
|
-
declare const height: Handler;
|
|
107
|
-
declare const resize: Handler;
|
|
108
|
-
declare const trim: Handler;
|
|
109
|
-
declare const extend: Handler;
|
|
110
|
-
declare const extract: Handler;
|
|
111
|
-
declare const rotate: Handler;
|
|
112
|
-
declare const flip: Handler;
|
|
113
|
-
declare const flop: Handler;
|
|
114
|
-
declare const sharpen: Handler;
|
|
115
|
-
declare const median: Handler;
|
|
116
|
-
declare const blur: Handler;
|
|
117
|
-
declare const flatten: Handler;
|
|
118
|
-
declare const gamma: Handler;
|
|
119
|
-
declare const negate: Handler;
|
|
120
|
-
declare const normalize: Handler;
|
|
121
|
-
declare const threshold: Handler;
|
|
122
|
-
declare const modulate: Handler;
|
|
123
|
-
declare const tint: Handler;
|
|
124
|
-
declare const grayscale: Handler;
|
|
125
|
-
declare const crop: Handler;
|
|
126
|
-
declare const q: Handler;
|
|
127
|
-
declare const b: Handler;
|
|
128
|
-
declare const w: Handler;
|
|
129
|
-
declare const h: Handler;
|
|
130
|
-
declare const s: Handler;
|
|
131
|
-
declare const pos: Handler;
|
|
132
|
-
|
|
133
|
-
declare const Handlers_b: typeof b;
|
|
134
|
-
declare const Handlers_background: typeof background;
|
|
135
|
-
declare const Handlers_blur: typeof blur;
|
|
136
|
-
declare const Handlers_crop: typeof crop;
|
|
137
|
-
declare const Handlers_enlarge: typeof enlarge;
|
|
138
|
-
declare const Handlers_extend: typeof extend;
|
|
139
|
-
declare const Handlers_extract: typeof extract;
|
|
140
|
-
declare const Handlers_fit: typeof fit;
|
|
141
|
-
declare const Handlers_flatten: typeof flatten;
|
|
142
|
-
declare const Handlers_flip: typeof flip;
|
|
143
|
-
declare const Handlers_flop: typeof flop;
|
|
144
|
-
declare const Handlers_gamma: typeof gamma;
|
|
145
|
-
declare const Handlers_grayscale: typeof grayscale;
|
|
146
|
-
declare const Handlers_h: typeof h;
|
|
147
|
-
declare const Handlers_height: typeof height;
|
|
148
|
-
declare const Handlers_kernel: typeof kernel;
|
|
149
|
-
declare const Handlers_median: typeof median;
|
|
150
|
-
declare const Handlers_modulate: typeof modulate;
|
|
151
|
-
declare const Handlers_negate: typeof negate;
|
|
152
|
-
declare const Handlers_normalize: typeof normalize;
|
|
153
|
-
declare const Handlers_pos: typeof pos;
|
|
154
|
-
declare const Handlers_position: typeof position;
|
|
155
|
-
declare const Handlers_q: typeof q;
|
|
156
|
-
declare const Handlers_quality: typeof quality;
|
|
157
|
-
declare const Handlers_resize: typeof resize;
|
|
158
|
-
declare const Handlers_rotate: typeof rotate;
|
|
159
|
-
declare const Handlers_s: typeof s;
|
|
160
|
-
declare const Handlers_sharpen: typeof sharpen;
|
|
161
|
-
declare const Handlers_threshold: typeof threshold;
|
|
162
|
-
declare const Handlers_tint: typeof tint;
|
|
163
|
-
declare const Handlers_trim: typeof trim;
|
|
164
|
-
declare const Handlers_w: typeof w;
|
|
165
|
-
declare const Handlers_width: typeof width;
|
|
166
|
-
declare namespace Handlers {
|
|
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
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
type HandlerName = keyof typeof Handlers;
|
|
205
|
-
|
|
206
|
-
type IPXSourceMeta = {
|
|
207
|
-
/**
|
|
208
|
-
* The modification time of the source. Used for cache validation.
|
|
209
|
-
* @optional
|
|
210
|
-
*/
|
|
211
|
-
mtime?: Date;
|
|
212
|
-
/**
|
|
213
|
-
* The maximum age (in seconds) that the source should be considered fresh.
|
|
214
|
-
* @optional
|
|
215
|
-
*/
|
|
216
|
-
maxAge?: number;
|
|
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
|
-
*/
|
|
235
|
-
type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
|
|
236
|
-
getSourceMeta: () => Promise<IPXSourceMeta>;
|
|
237
|
-
process: () => Promise<{
|
|
238
|
-
data: Buffer | string;
|
|
239
|
-
meta?: ImageMeta;
|
|
240
|
-
format?: string;
|
|
241
|
-
}>;
|
|
242
|
-
};
|
|
243
|
-
type IPXOptions = {
|
|
244
|
-
/**
|
|
245
|
-
* Default cache duration in seconds. If not specified, a default of 1 minute is used.
|
|
246
|
-
* @optional
|
|
247
|
-
*/
|
|
248
|
-
maxAge?: number;
|
|
249
|
-
/**
|
|
250
|
-
* A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
|
|
251
|
-
* @optional
|
|
252
|
-
*/
|
|
253
|
-
alias?: Record<string, string>;
|
|
254
|
-
/**
|
|
255
|
-
* Configuration options for the Sharp image processing library.
|
|
256
|
-
* @optional
|
|
257
|
-
*/
|
|
258
|
-
sharpOptions?: SharpOptions;
|
|
259
|
-
/**
|
|
260
|
-
* Primary storage backend for handling image assets.
|
|
261
|
-
*/
|
|
262
|
-
storage: IPXStorage;
|
|
263
|
-
/**
|
|
264
|
-
* An optional secondary storage backend used when images are fetched via HTTP.
|
|
265
|
-
* @optional
|
|
266
|
-
*/
|
|
267
|
-
httpStorage?: IPXStorage;
|
|
268
|
-
/**
|
|
269
|
-
* Configuration for the SVGO library used when processing SVG images.
|
|
270
|
-
* @optional
|
|
271
|
-
*/
|
|
272
|
-
svgo?: false | Config;
|
|
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
|
-
*/
|
|
280
|
-
declare function createIPX(userOptions: IPXOptions): IPX;
|
|
281
|
-
|
|
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> | {
|
|
290
|
-
error: {
|
|
291
|
-
message: string;
|
|
292
|
-
};
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
317
|
-
declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
|
|
318
|
-
|
|
319
|
-
type HTTPStorageOptions = {
|
|
320
|
-
/**
|
|
321
|
-
* Custom options for fetch operations, such as headers or method overrides.
|
|
322
|
-
* @optional
|
|
323
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
334
|
-
domains?: string | string[];
|
|
335
|
-
/**
|
|
336
|
-
* If set to true, allows retrieval from any domain. Overrides the domain whitelist.
|
|
337
|
-
* @optional
|
|
338
|
-
*/
|
|
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
|
-
*/
|
|
344
|
-
ignoreCacheControl?: boolean;
|
|
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
|
-
*/
|
|
354
|
-
declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
|
|
355
|
-
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
366
|
-
maxAge?: number;
|
|
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
|
-
*/
|
|
376
|
-
declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
|
|
377
|
-
|
|
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
|
-
*/
|
|
383
|
-
prefix?: string;
|
|
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
|
-
*/
|
|
394
|
-
declare function unstorageToIPXStorage(storage: Storage | Driver, _options?: UnstorageIPXStorageOptions | string): IPXStorage;
|
|
395
|
-
|
|
396
|
-
export { createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
|
|
397
|
-
export type { HTTPStorageOptions, Handler, HandlerContext, IPX, IPXOptions, IPXStorage, IPXStorageMeta, IPXStorageOptions, NodeFSSOptions, UnstorageIPXStorageOptions };
|