@bgord/bun 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command-envelope.d.ts +1 -1
- package/dist/csv-stringifier.adapter.d.ts +1 -1
- package/dist/image-alpha-sharp.adapter.d.ts +1 -0
- package/dist/image-alpha-sharp.adapter.d.ts.map +1 -1
- package/dist/image-alpha-sharp.adapter.js +18 -77
- package/dist/image-alpha-sharp.adapter.js.map +1 -1
- package/dist/image-blur-sharp.adapter.d.ts +1 -0
- package/dist/image-blur-sharp.adapter.d.ts.map +1 -1
- package/dist/image-blur-sharp.adapter.js +14 -73
- package/dist/image-blur-sharp.adapter.js.map +1 -1
- package/dist/image-compressor-sharp.adapter.d.ts +1 -0
- package/dist/image-compressor-sharp.adapter.d.ts.map +1 -1
- package/dist/image-compressor-sharp.adapter.js +15 -74
- package/dist/image-compressor-sharp.adapter.js.map +1 -1
- package/dist/image-exif-clear-sharp.adapter.d.ts +1 -0
- package/dist/image-exif-clear-sharp.adapter.d.ts.map +1 -1
- package/dist/image-exif-clear-sharp.adapter.js +12 -71
- package/dist/image-exif-clear-sharp.adapter.js.map +1 -1
- package/dist/image-formatter-sharp.adapter.d.ts +1 -0
- package/dist/image-formatter-sharp.adapter.d.ts.map +1 -1
- package/dist/image-formatter-sharp.adapter.js +17 -76
- package/dist/image-formatter-sharp.adapter.js.map +1 -1
- package/dist/image-info-sharp.adapter.d.ts +1 -0
- package/dist/image-info-sharp.adapter.d.ts.map +1 -1
- package/dist/image-info-sharp.adapter.js +14 -73
- package/dist/image-info-sharp.adapter.js.map +1 -1
- package/dist/image-processor-sharp.adapter.d.ts +1 -0
- package/dist/image-processor-sharp.adapter.d.ts.map +1 -1
- package/dist/image-processor-sharp.adapter.js +28 -87
- package/dist/image-processor-sharp.adapter.js.map +1 -1
- package/dist/image-resizer-sharp.adapter.d.ts +1 -0
- package/dist/image-resizer-sharp.adapter.d.ts.map +1 -1
- package/dist/image-resizer-sharp.adapter.js +23 -82
- package/dist/image-resizer-sharp.adapter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/src/image-alpha-sharp.adapter.ts +9 -3
- package/src/image-blur-sharp.adapter.ts +7 -2
- package/src/image-compressor-sharp.adapter.ts +7 -2
- package/src/image-exif-clear-sharp.adapter.ts +6 -1
- package/src/image-formatter-sharp.adapter.ts +7 -2
- package/src/image-info-sharp.adapter.ts +6 -1
- package/src/image-processor-sharp.adapter.ts +7 -2
- package/src/image-resizer-sharp.adapter.ts +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-formatter-sharp.adapter.js","sourceRoot":"","sources":["../src/image-formatter-sharp.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-formatter-sharp.adapter.js","sourceRoot":"","sources":["../src/image-formatter-sharp.adapter.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,0BAA0B;IACR;IAA7B,YAA6B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAE3C,KAAK,CAAC,IAAI;QAChB,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAA8B;QACzC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,KAAK,GACT,MAAM,CAAC,QAAQ,KAAK,aAAa;YAC/B,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAErF,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;QAEnF,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,CAAC;QACrD,MAAM,OAAO,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAqC,CAAC;QAE/F,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAChG,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAE/D,MAAM,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAErD,IAAI,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,KAAK,CAAC,GAAG,EAAE,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC;YACzE,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as tools from "@bgord/tools";
|
|
2
2
|
import type { ImageInfoPort } from "./image-info.port";
|
|
3
3
|
export declare class ImageInfoSharpAdapter implements ImageInfoPort {
|
|
4
|
+
private load;
|
|
4
5
|
inspect(filePath: tools.FilePathRelative | tools.FilePathAbsolute): Promise<{
|
|
5
6
|
width: number & import("zod").$brand<"ImageWidth">;
|
|
6
7
|
height: number & import("zod").$brand<"ImageHeight">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-info-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-info-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"image-info-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-info-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,qBAAsB,YAAW,aAAa;YAC3C,IAAI;IAIZ,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB;;;;;;CAiBxE"}
|
|
@@ -1,79 +1,20 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
1
|
import * as tools from "@bgord/tools";
|
|
54
|
-
import sharp from "sharp";
|
|
55
2
|
export class ImageInfoSharpAdapter {
|
|
3
|
+
async load() {
|
|
4
|
+
return (await import("sharp")).default;
|
|
5
|
+
}
|
|
56
6
|
async inspect(filePath) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
catch (e_1) {
|
|
71
|
-
env_1.error = e_1;
|
|
72
|
-
env_1.hasError = true;
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
__disposeResources(env_1);
|
|
76
|
-
}
|
|
7
|
+
const sharp = await this.load();
|
|
8
|
+
const path = filePath.get();
|
|
9
|
+
const pipeline = sharp(path);
|
|
10
|
+
using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
|
|
11
|
+
const metadata = await pipeline.metadata();
|
|
12
|
+
return {
|
|
13
|
+
width: tools.ImageWidth.parse(metadata.width),
|
|
14
|
+
height: tools.ImageHeight.parse(metadata.height),
|
|
15
|
+
mime: tools.Mime.fromExtension(tools.Extension.parse(metadata.format)),
|
|
16
|
+
size: tools.Size.fromBytes(Bun.file(path).size),
|
|
17
|
+
};
|
|
77
18
|
}
|
|
78
19
|
}
|
|
79
20
|
//# sourceMappingURL=image-info-sharp.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-info-sharp.adapter.js","sourceRoot":"","sources":["../src/image-info-sharp.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-info-sharp.adapter.js","sourceRoot":"","sources":["../src/image-info-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,MAAM,OAAO,qBAAqB;IACxB,KAAK,CAAC,IAAI;QAChB,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAyD;QACrE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;QAE5B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAE/D,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAE3C,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;YAC7C,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;YAChD,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACtE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;SAChD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -10,6 +10,7 @@ export declare class ImageProcessorSharpAdapter implements ImageProcessorPort {
|
|
|
10
10
|
private readonly deps;
|
|
11
11
|
private static readonly DEFAULT_QUALITY;
|
|
12
12
|
constructor(deps: Dependencies);
|
|
13
|
+
private load;
|
|
13
14
|
process(recipe: ImageProcessorStrategy): Promise<tools.FilePathRelative | tools.FilePathAbsolute>;
|
|
14
15
|
}
|
|
15
16
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-processor-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-processor-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"image-processor-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-processor-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEzF,KAAK,YAAY,GAAG;IAAE,WAAW,EAAE,eAAe,CAAC;IAAC,WAAW,EAAE,eAAe,CAAA;CAAE,CAAC;AAEnF,qBAAa,0BAA2B,YAAW,kBAAkB;IAGvD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAM;gBAEhB,IAAI,EAAE,YAAY;YAEjC,IAAI;IAIZ,OAAO,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC;CA0CxG"}
|
|
@@ -1,99 +1,40 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import sharp from "sharp";
|
|
54
1
|
export class ImageProcessorSharpAdapter {
|
|
55
2
|
deps;
|
|
56
3
|
static DEFAULT_QUALITY = 85;
|
|
57
4
|
constructor(deps) {
|
|
58
5
|
this.deps = deps;
|
|
59
6
|
}
|
|
7
|
+
async load() {
|
|
8
|
+
return (await import("sharp")).default;
|
|
9
|
+
}
|
|
60
10
|
async process(recipe) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
processor = processor.flatten({ background: recipe.background });
|
|
75
|
-
}
|
|
76
|
-
processor = processor.resize({
|
|
77
|
-
width: recipe.maxSide,
|
|
78
|
-
height: recipe.maxSide,
|
|
79
|
-
fit: "inside",
|
|
80
|
-
withoutEnlargement: true,
|
|
81
|
-
});
|
|
82
|
-
processor = processor.toFormat(encoder, { quality });
|
|
83
|
-
await processor.toFile(temporary.get());
|
|
84
|
-
await this.deps.FileRenamer.rename(temporary, final);
|
|
85
|
-
if (recipe.strategy === "in_place" && final.get() !== recipe.input.get()) {
|
|
86
|
-
await this.deps.FileCleaner.delete(recipe.input.get());
|
|
87
|
-
}
|
|
88
|
-
return final;
|
|
89
|
-
}
|
|
90
|
-
catch (e_1) {
|
|
91
|
-
env_1.error = e_1;
|
|
92
|
-
env_1.hasError = true;
|
|
11
|
+
const sharp = await this.load();
|
|
12
|
+
const final = recipe.strategy === "output_path"
|
|
13
|
+
? recipe.output
|
|
14
|
+
: recipe.input.withFilename(recipe.input.getFilename().withExtension(recipe.to));
|
|
15
|
+
const temporary = final.withFilename(final.getFilename().withSuffix("-processed"));
|
|
16
|
+
const extension = final.getFilename().getExtension();
|
|
17
|
+
const encoder = (extension === "jpg" ? "jpeg" : extension);
|
|
18
|
+
const quality = recipe.quality ?? ImageProcessorSharpAdapter.DEFAULT_QUALITY;
|
|
19
|
+
const pipeline = sharp(recipe.input.get());
|
|
20
|
+
using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
|
|
21
|
+
let processor = pipeline.rotate();
|
|
22
|
+
if (recipe.background) {
|
|
23
|
+
processor = processor.flatten({ background: recipe.background });
|
|
93
24
|
}
|
|
94
|
-
|
|
95
|
-
|
|
25
|
+
processor = processor.resize({
|
|
26
|
+
width: recipe.maxSide,
|
|
27
|
+
height: recipe.maxSide,
|
|
28
|
+
fit: "inside",
|
|
29
|
+
withoutEnlargement: true,
|
|
30
|
+
});
|
|
31
|
+
processor = processor.toFormat(encoder, { quality });
|
|
32
|
+
await processor.toFile(temporary.get());
|
|
33
|
+
await this.deps.FileRenamer.rename(temporary, final);
|
|
34
|
+
if (recipe.strategy === "in_place" && final.get() !== recipe.input.get()) {
|
|
35
|
+
await this.deps.FileCleaner.delete(recipe.input.get());
|
|
96
36
|
}
|
|
37
|
+
return final;
|
|
97
38
|
}
|
|
98
39
|
}
|
|
99
40
|
//# sourceMappingURL=image-processor-sharp.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-processor-sharp.adapter.js","sourceRoot":"","sources":["../src/image-processor-sharp.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-processor-sharp.adapter.js","sourceRoot":"","sources":["../src/image-processor-sharp.adapter.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,0BAA0B;IAGR;IAFrB,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IAE7C,YAA6B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAE3C,KAAK,CAAC,IAAI;QAChB,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAA8B;QAC1C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,KAAK,GACT,MAAM,CAAC,QAAQ,KAAK,aAAa;YAC/B,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAErF,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;QAEnF,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,CAAC;QACrD,MAAM,OAAO,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAqC,CAAC;QAE/F,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,0BAA0B,CAAC,eAAe,CAAC;QAE7E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAE/D,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QAElC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAiB,EAAE,CAAC,CAAC;QAC1E,CAAC;QAED,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;YAC3B,KAAK,EAAE,MAAM,CAAC,OAAO;YACrB,MAAM,EAAE,MAAM,CAAC,OAAO;YACtB,GAAG,EAAE,QAAQ;YACb,kBAAkB,EAAE,IAAI;SACzB,CAAC,CAAC;QAEH,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAErD,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;QACxC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAErD,IAAI,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,KAAK,CAAC,GAAG,EAAE,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC;YACzE,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC"}
|
|
@@ -6,6 +6,7 @@ type Dependencies = {
|
|
|
6
6
|
export declare class ImageResizerSharpAdapter implements ImageResizerPort {
|
|
7
7
|
private readonly deps;
|
|
8
8
|
constructor(deps: Dependencies);
|
|
9
|
+
private load;
|
|
9
10
|
resize(recipe: ImageResizerStrategy): Promise<import("@bgord/tools").FilePathRelative | import("@bgord/tools").FilePathAbsolute>;
|
|
10
11
|
}
|
|
11
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-resizer-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-resizer-sharp.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-resizer-sharp.adapter.d.ts","sourceRoot":"","sources":["../src/image-resizer-sharp.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,KAAK,YAAY,GAAG;IAAE,WAAW,EAAE,eAAe,CAAA;CAAE,CAAC;AAErD,qBAAa,wBAAyB,YAAW,gBAAgB;IACnD,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,YAAY;YAEjC,IAAI;IAIZ,MAAM,CAAC,MAAM,EAAE,oBAAoB;CA2B1C"}
|
|
@@ -1,91 +1,32 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import sharp from "sharp";
|
|
54
1
|
export class ImageResizerSharpAdapter {
|
|
55
2
|
deps;
|
|
56
3
|
constructor(deps) {
|
|
57
4
|
this.deps = deps;
|
|
58
5
|
}
|
|
6
|
+
async load() {
|
|
7
|
+
return (await import("sharp")).default;
|
|
8
|
+
}
|
|
59
9
|
async resize(recipe) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return final;
|
|
81
|
-
}
|
|
82
|
-
catch (e_1) {
|
|
83
|
-
env_1.error = e_1;
|
|
84
|
-
env_1.hasError = true;
|
|
85
|
-
}
|
|
86
|
-
finally {
|
|
87
|
-
__disposeResources(env_1);
|
|
88
|
-
}
|
|
10
|
+
const sharp = await this.load();
|
|
11
|
+
const final = recipe.strategy === "output_path" ? recipe.output : recipe.input;
|
|
12
|
+
const filename = final.getFilename();
|
|
13
|
+
const temporary = final.withFilename(filename.withSuffix("-resized"));
|
|
14
|
+
const extension = final.getFilename().getExtension();
|
|
15
|
+
const format = (extension === "jpg" ? "jpeg" : extension);
|
|
16
|
+
const pipeline = sharp(recipe.input.get());
|
|
17
|
+
using _sharp_ = { [Symbol.dispose]: () => pipeline.destroy() };
|
|
18
|
+
await pipeline
|
|
19
|
+
.rotate()
|
|
20
|
+
.resize({
|
|
21
|
+
width: recipe.maxSide,
|
|
22
|
+
height: recipe.maxSide,
|
|
23
|
+
fit: "inside",
|
|
24
|
+
withoutEnlargement: true,
|
|
25
|
+
})
|
|
26
|
+
.toFormat(format)
|
|
27
|
+
.toFile(temporary.get());
|
|
28
|
+
await this.deps.FileRenamer.rename(temporary, final);
|
|
29
|
+
return final;
|
|
89
30
|
}
|
|
90
31
|
}
|
|
91
32
|
//# sourceMappingURL=image-resizer-sharp.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-resizer-sharp.adapter.js","sourceRoot":"","sources":["../src/image-resizer-sharp.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-resizer-sharp.adapter.js","sourceRoot":"","sources":["../src/image-resizer-sharp.adapter.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,wBAAwB;IACN;IAA7B,YAA6B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAE3C,KAAK,CAAC,IAAI;QAChB,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/E,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;QAEtE,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAqC,CAAC;QAE9F,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAE/D,MAAM,QAAQ;aACX,MAAM,EAAE;aACR,MAAM,CAAC;YACN,KAAK,EAAE,MAAM,CAAC,OAAO;YACrB,MAAM,EAAE,MAAM,CAAC,OAAO;YACtB,GAAG,EAAE,QAAQ;YACb,kBAAkB,EAAE,IAAI;SACzB,CAAC;aACD,QAAQ,CAAC,MAAM,CAAC;aAChB,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3B,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAErD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|