@blazetrails/image-processing 0.0.0-stage → 0.1.0-alpha0.1
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/LICENSE +21 -0
- package/dist/builder.d.ts +17 -0
- package/dist/builder.js +36 -0
- package/dist/builder.js.map +1 -0
- package/dist/chainable.d.ts +49 -0
- package/dist/chainable.js +121 -0
- package/dist/chainable.js.map +1 -0
- package/dist/constants.generated.d.ts +2 -0
- package/dist/constants.generated.js +14 -0
- package/dist/constants.generated.js.map +1 -0
- package/dist/image-processing.d.ts +11 -0
- package/dist/image-processing.js +12 -0
- package/dist/image-processing.js.map +1 -0
- package/dist/mini-magick.d.ts +56 -0
- package/dist/mini-magick.js +240 -0
- package/dist/mini-magick.js.map +1 -0
- package/dist/namespaces.d.ts +18 -0
- package/dist/namespaces.js +14 -0
- package/dist/namespaces.js.map +1 -0
- package/dist/pipeline.d.ts +38 -0
- package/dist/pipeline.js +121 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/processor.d.ts +25 -0
- package/dist/processor.js +80 -0
- package/dist/processor.js.map +1 -0
- package/dist/vips.d.ts +66 -0
- package/dist/vips.js +425 -0
- package/dist/vips.js.map +1 -0
- package/package.json +62 -3
- package/README.md +0 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Autoload, extend } from "@blazetrails/activesupport";
|
|
2
|
+
import { TopLevel, constSet } from "@blazetrails/ruby-compat";
|
|
3
|
+
export const ImageProcessing = {
|
|
4
|
+
name: "ImageProcessing",
|
|
5
|
+
loadPath: {
|
|
6
|
+
"image_processing/mini_magick": () => import("./mini-magick.js"),
|
|
7
|
+
"image_processing/vips": () => import("./vips.js"),
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
extend(ImageProcessing, Autoload);
|
|
11
|
+
ImageProcessing.autoload("MiniMagick");
|
|
12
|
+
ImageProcessing.autoload("Vips");
|
|
13
|
+
constSet(TopLevel, "ImageProcessing", ImageProcessing);
|
|
14
|
+
//# sourceMappingURL=namespaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespaces.js","sourceRoot":"","sources":["../lib/namespaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAiB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAS9D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,QAAQ,EAAE;QACR,8BAA8B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC;QAChE,uBAAuB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;KACnD;CAUA,CAAC;AACJ,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;AAElC,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACvC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEjC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Operation, Options } from "./chainable.js";
|
|
2
|
+
export declare class Pipeline {
|
|
3
|
+
static DEFAULT_FORMAT: string;
|
|
4
|
+
private _source;
|
|
5
|
+
private _loader;
|
|
6
|
+
private _saver;
|
|
7
|
+
private _format;
|
|
8
|
+
private _operations;
|
|
9
|
+
private _processor;
|
|
10
|
+
private _destination;
|
|
11
|
+
constructor(options: Partial<Options> & {
|
|
12
|
+
destination?: string;
|
|
13
|
+
});
|
|
14
|
+
get loader(): Record<string, unknown>;
|
|
15
|
+
get saver(): Record<string, unknown>;
|
|
16
|
+
get format(): string | null;
|
|
17
|
+
get operations(): Operation[];
|
|
18
|
+
get processor(): {
|
|
19
|
+
call(options: Record<string, unknown>): unknown;
|
|
20
|
+
};
|
|
21
|
+
get destination(): string | null | undefined;
|
|
22
|
+
call(keywords?: {
|
|
23
|
+
save?: boolean;
|
|
24
|
+
}): Promise<unknown>;
|
|
25
|
+
sourcePath(): string | null;
|
|
26
|
+
destinationFormat(): string;
|
|
27
|
+
/** @internal */
|
|
28
|
+
private callProcessor;
|
|
29
|
+
/** @internal */
|
|
30
|
+
private createTempfile;
|
|
31
|
+
/** @internal */
|
|
32
|
+
private handleDestination;
|
|
33
|
+
/** @internal */
|
|
34
|
+
private source;
|
|
35
|
+
/** @internal */
|
|
36
|
+
private determineFormat;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ImageProcessing } from "./namespaces.js";
|
|
2
|
+
import { File, rbGetKwargs, rbObjRespondTo, Tempfile } from "@blazetrails/ruby-compat";
|
|
3
|
+
import { Error } from "./image-processing.js";
|
|
4
|
+
export class Pipeline {
|
|
5
|
+
static DEFAULT_FORMAT = "jpg";
|
|
6
|
+
constructor(options) {
|
|
7
|
+
if (options.source == null || options.source === false) {
|
|
8
|
+
throw new Error("source file is not provided");
|
|
9
|
+
}
|
|
10
|
+
for (const [name, value] of Object.entries(options)) {
|
|
11
|
+
this[`_${name}`] = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
get loader() {
|
|
15
|
+
return this._loader;
|
|
16
|
+
}
|
|
17
|
+
get saver() {
|
|
18
|
+
return this._saver;
|
|
19
|
+
}
|
|
20
|
+
get format() {
|
|
21
|
+
return this._format;
|
|
22
|
+
}
|
|
23
|
+
get operations() {
|
|
24
|
+
return this._operations;
|
|
25
|
+
}
|
|
26
|
+
get processor() {
|
|
27
|
+
return this._processor;
|
|
28
|
+
}
|
|
29
|
+
get destination() {
|
|
30
|
+
return this._destination;
|
|
31
|
+
}
|
|
32
|
+
async call(keywords = {}) {
|
|
33
|
+
rbGetKwargs(keywords, ["save"]);
|
|
34
|
+
const { save = true } = keywords;
|
|
35
|
+
if (save === false) {
|
|
36
|
+
return this.callProcessor();
|
|
37
|
+
}
|
|
38
|
+
else if (this.destination != null) {
|
|
39
|
+
const destination = this.destination;
|
|
40
|
+
return this.handleDestination(() => this.callProcessor({ destination }));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return this.createTempfile((tempfile) => this.callProcessor({ destination: tempfile.path() }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
sourcePath() {
|
|
47
|
+
const source = this.source();
|
|
48
|
+
return typeof source === "string" ? source : null;
|
|
49
|
+
}
|
|
50
|
+
destinationFormat() {
|
|
51
|
+
let format = this.destination != null ? this.determineFormat(this.destination) : null;
|
|
52
|
+
format ??= this.format;
|
|
53
|
+
const sourcePath = this.sourcePath();
|
|
54
|
+
if (format == null && sourcePath != null)
|
|
55
|
+
format = this.determineFormat(sourcePath);
|
|
56
|
+
return format ?? Pipeline.DEFAULT_FORMAT;
|
|
57
|
+
}
|
|
58
|
+
/** @internal */
|
|
59
|
+
async callProcessor(options = {}) {
|
|
60
|
+
return this.processor.call({
|
|
61
|
+
source: this.source(),
|
|
62
|
+
loader: this.loader,
|
|
63
|
+
operations: this.operations,
|
|
64
|
+
saver: this.saver,
|
|
65
|
+
...options,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** @internal */
|
|
69
|
+
async createTempfile(block) {
|
|
70
|
+
let tempfile;
|
|
71
|
+
try {
|
|
72
|
+
tempfile = Tempfile.new(["image_processing", `.${this.destinationFormat()}`], null, {
|
|
73
|
+
binmode: true,
|
|
74
|
+
});
|
|
75
|
+
await block(tempfile);
|
|
76
|
+
tempfile.open();
|
|
77
|
+
return tempfile;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (tempfile)
|
|
81
|
+
tempfile.closeBang();
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** @internal */
|
|
86
|
+
async handleDestination(block) {
|
|
87
|
+
const destination = this.destination;
|
|
88
|
+
const destinationExisted = await File.isExistAsync(destination);
|
|
89
|
+
try {
|
|
90
|
+
return await block();
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if ((await File.isExistAsync(destination)) && !destinationExisted) {
|
|
94
|
+
await File.deleteAsync(destination);
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** @internal */
|
|
100
|
+
source() {
|
|
101
|
+
if (typeof this._source === "string") {
|
|
102
|
+
return this._source;
|
|
103
|
+
}
|
|
104
|
+
else if (rbObjRespondTo(this._source, "path")) {
|
|
105
|
+
return this._source.path();
|
|
106
|
+
}
|
|
107
|
+
else if (rbObjRespondTo(this._source, "toPath")) {
|
|
108
|
+
return this._source.toPath();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return this._source;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** @internal */
|
|
115
|
+
determineFormat(filePath) {
|
|
116
|
+
const extension = File.extname(filePath);
|
|
117
|
+
return extension.length > 1 ? extension.slice(1) : null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
ImageProcessing.Pipeline = Pipeline;
|
|
121
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../lib/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEvF,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,MAAM,OAAO,QAAQ;IACnB,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC;IAU9B,YAAY,OAAoD;QAC9D,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,IAAI,OA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,CAAC;YACN,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;IACH,CAAC;IAED,gBAAgB;IACR,eAAe,CAAC,QAAgB;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEzC,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1D,CAAC;CACF;AAED,eAAe,CAAC,QAAQ,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Operation } from "./chainable.js";
|
|
2
|
+
type ProcessorClass = typeof Processor & {
|
|
3
|
+
loadImage(source: unknown, loader: Record<string, unknown>): unknown;
|
|
4
|
+
saveImage(accumulator: unknown, destination: string, saver: Record<string, unknown>): unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare class Processor {
|
|
7
|
+
static ACCUMULATOR_CLASS: abstract new (...args: never[]) => unknown;
|
|
8
|
+
protected _accumulator: unknown;
|
|
9
|
+
/** @inventedArm deleteAccumulator — PERMANENT */
|
|
10
|
+
static call(this: ProcessorClass, { source, loader, operations, saver, destination, }: {
|
|
11
|
+
source: unknown;
|
|
12
|
+
loader: Record<string, unknown>;
|
|
13
|
+
operations: Operation[];
|
|
14
|
+
saver: Record<string, unknown>;
|
|
15
|
+
destination?: string | null;
|
|
16
|
+
}): Promise<unknown>;
|
|
17
|
+
static accumulator(name: string, klass: abstract new (...args: never[]) => unknown): void;
|
|
18
|
+
static applyOperation(accumulator: unknown, [name, args, block]: Operation): unknown;
|
|
19
|
+
static isSupportsResizeOnLoad(): boolean;
|
|
20
|
+
constructor(accumulator?: unknown);
|
|
21
|
+
applyOperation(name: string, ...args: unknown[]): unknown;
|
|
22
|
+
custom(block?: (accumulator: unknown) => unknown): unknown;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ImageProcessing } from "./namespaces.js";
|
|
2
|
+
import { isPlainHash, rbBlockGivenP, rbFSend, rbInspect, constSet, rbModDefineMethod, rbObjRespondTo, } from "@blazetrails/ruby-compat";
|
|
3
|
+
import { Error } from "./image-processing.js";
|
|
4
|
+
/** @noRailsEquivalent PERMANENT */
|
|
5
|
+
function deleteAccumulator(accumulator) {
|
|
6
|
+
if (accumulator == null || typeof accumulator !== "object")
|
|
7
|
+
return;
|
|
8
|
+
const prototype = Object.getPrototypeOf(accumulator);
|
|
9
|
+
if (typeof prototype?.delete !== "function")
|
|
10
|
+
return;
|
|
11
|
+
const handle = accumulator;
|
|
12
|
+
if (!handle.isDeleted())
|
|
13
|
+
handle.delete();
|
|
14
|
+
}
|
|
15
|
+
export class Processor {
|
|
16
|
+
/** @inventedArm deleteAccumulator — PERMANENT */
|
|
17
|
+
static async call({ source, loader, operations, saver, destination = null, }) {
|
|
18
|
+
if (!(typeof source === "string" || source instanceof this.ACCUMULATOR_CLASS)) {
|
|
19
|
+
throw new Error(`invalid source: ${rbInspect(source)}`);
|
|
20
|
+
}
|
|
21
|
+
let accumulator;
|
|
22
|
+
if (/^resize[A-Z]/.test(String(operations[0]?.[0] ?? "")) &&
|
|
23
|
+
Object.keys(loader).length === 0 &&
|
|
24
|
+
this.isSupportsResizeOnLoad()) {
|
|
25
|
+
accumulator = source;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
accumulator = await this.loadImage(source, loader);
|
|
29
|
+
}
|
|
30
|
+
for (const operation of operations) {
|
|
31
|
+
const previous = accumulator;
|
|
32
|
+
accumulator = await this.applyOperation(accumulator, operation);
|
|
33
|
+
if (previous !== source && previous !== accumulator)
|
|
34
|
+
deleteAccumulator(previous);
|
|
35
|
+
}
|
|
36
|
+
if (destination != null) {
|
|
37
|
+
const result = await this.saveImage(accumulator, destination, saver);
|
|
38
|
+
if (accumulator !== source)
|
|
39
|
+
deleteAccumulator(accumulator);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return accumulator;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static accumulator(name, klass) {
|
|
47
|
+
rbModDefineMethod(this, name, {
|
|
48
|
+
get() {
|
|
49
|
+
return this._accumulator;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
constSet(this, "ACCUMULATOR_CLASS", klass);
|
|
53
|
+
}
|
|
54
|
+
static applyOperation(accumulator, [name, args, block]) {
|
|
55
|
+
return new this(accumulator).applyOperation(name, ...args, ...(block ? [block] : []));
|
|
56
|
+
}
|
|
57
|
+
static isSupportsResizeOnLoad() {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
constructor(accumulator = null) {
|
|
61
|
+
this._accumulator = accumulator;
|
|
62
|
+
}
|
|
63
|
+
applyOperation(name, ...args) {
|
|
64
|
+
const block = rbBlockGivenP(args.at(-1)) ? [args.pop()] : [];
|
|
65
|
+
const receiver = rbObjRespondTo(this, name) ? this : this._accumulator;
|
|
66
|
+
if (isPlainHash(args.at(-1))) {
|
|
67
|
+
const kwargs = args.pop();
|
|
68
|
+
return rbFSend(receiver, name, ...args, kwargs, ...block);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return rbFSend(receiver, name, ...args, ...block);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
custom(block) {
|
|
75
|
+
const result = block != null ? block(this._accumulator) : null;
|
|
76
|
+
return result != null && result !== false ? result : this._accumulator;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
ImageProcessing.Processor = Processor;
|
|
80
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../lib/processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,WA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"./processor.js";
|
|
3
|
+
type Options = Record<string, unknown>;
|
|
4
|
+
type Image = InstanceType<Awaited<ReturnType<typeof WasmVips>>["Image"]>;
|
|
5
|
+
/** @noRailsEquivalent PERMANENT */
|
|
6
|
+
export declare const vips: typeof WasmVips;
|
|
7
|
+
export declare class Processor extends BaseProcessor {
|
|
8
|
+
readonly image: Image | string;
|
|
9
|
+
static SHARPEN_MASK: WasmVips.Image;
|
|
10
|
+
/** @inventedArm delete — PERMANENT */
|
|
11
|
+
static loadImage(pathOrImage: string | Image, { loader, autorot, ...options }?: Options): Image;
|
|
12
|
+
static isSupportsResizeOnLoad(): boolean;
|
|
13
|
+
static saveImage(image: Image, path: string, { saver, quality, ...options }?: Options): unknown;
|
|
14
|
+
resizeToLimit(width: number | null, height: number | null, options?: Options): Image;
|
|
15
|
+
resizeToFit(width: number | null, height: number | null, options?: Options): Image;
|
|
16
|
+
resizeToFill(width: number, height: number, options?: Options): Image;
|
|
17
|
+
/**
|
|
18
|
+
* @missingRailsArgs gravity — PERMANENT
|
|
19
|
+
* @inventedArm delete — PERMANENT
|
|
20
|
+
*/
|
|
21
|
+
resizeAndPad(width: number, height: number, { gravity, extend, background, alpha, ...options }?: Options): Image;
|
|
22
|
+
/** @inventedArm delete — PERMANENT */
|
|
23
|
+
resizeToCover(width: number, height: number, options?: Options): Image;
|
|
24
|
+
rotate(degrees: number, options?: Options): Image;
|
|
25
|
+
/** @inventedArm delete — PERMANENT */
|
|
26
|
+
composite(overlay: unknown, _mode?: unknown, { mode, gravity, offset, ...options }?: Options): Image;
|
|
27
|
+
set(...args: [string, unknown]): Image;
|
|
28
|
+
setType(...args: [number, string, unknown]): Image;
|
|
29
|
+
setValue(...args: [string, unknown]): Image;
|
|
30
|
+
remove(...args: Parameters<Image["remove"]>): Image;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* @inventedArm delete — PERMANENT
|
|
34
|
+
*/
|
|
35
|
+
private thumbnail;
|
|
36
|
+
/** @internal */
|
|
37
|
+
private defaultDimensions;
|
|
38
|
+
/** @internal */
|
|
39
|
+
private convertToImage;
|
|
40
|
+
static Utils: {
|
|
41
|
+
selectValidLoaderOptions(sourcePath: string, options: Options): Options;
|
|
42
|
+
selectValidSaverOptions(destinationPath: string, options: Options): Options;
|
|
43
|
+
selectValidOptions(operationName: string, options: Options): Options;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare const Vips: {
|
|
47
|
+
Processor: typeof Processor;
|
|
48
|
+
isValidImage(file: {
|
|
49
|
+
path(): string;
|
|
50
|
+
}): boolean;
|
|
51
|
+
source(this: import("./chainable.js").ChainableHost, file: unknown): import("./builder.js").Builder;
|
|
52
|
+
convert(this: import("./chainable.js").ChainableHost, format: string | null): import("./builder.js").Builder;
|
|
53
|
+
loader(this: import("./chainable.js").ChainableHost, options?: Record<string, unknown>): import("./builder.js").Builder;
|
|
54
|
+
saver(this: import("./chainable.js").ChainableHost, options?: Record<string, unknown>): import("./builder.js").Builder;
|
|
55
|
+
instrumenter(this: import("./chainable.js").ChainableHost, block: import("./chainable.js").Options["instrumenter"]): import("./builder.js").Builder;
|
|
56
|
+
apply(this: import("./chainable.js").ChainableHost, operations: Record<string, unknown> | [string, unknown][]): import("./chainable.js").ChainableHost;
|
|
57
|
+
operation(this: import("./chainable.js").ChainableHost, name: string, ...args: unknown[]): import("./builder.js").Builder;
|
|
58
|
+
call(this: import("./chainable.js").ChainableHost, file?: unknown, { destination, ...callOptions }?: {
|
|
59
|
+
destination?: string | null;
|
|
60
|
+
save?: boolean;
|
|
61
|
+
}): Promise<unknown>;
|
|
62
|
+
branch(this: import("./chainable.js").ChainableHost, newOptions?: Record<string, unknown>): import("./builder.js").Builder;
|
|
63
|
+
methodMissing(this: import("./chainable.js").ChainableHost, name: string, ...args: unknown[]): unknown;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=vips.d.ts.map
|