@thi.ng/imago 0.7.6 → 0.7.7

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-05-08T18:24:32Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/layers/image.js CHANGED
@@ -13,16 +13,13 @@ const imageLayerImpl = async (layer, _, ctx) => {
13
13
  unit,
14
14
  ...opts
15
15
  } = layer;
16
- if (!(path || buffer))
17
- illegalArgs("missing image source");
16
+ if (!(path || buffer)) illegalArgs("missing image source");
18
17
  const input = sharp(path || buffer);
19
18
  const meta = await input.metadata();
20
19
  let imgSize = [meta.width, meta.height];
21
- if (size)
22
- imgSize = computeSize(size, imgSize, ref, unit);
20
+ if (size) imgSize = computeSize(size, imgSize, ref, unit);
23
21
  const $pos = positionOrGravity(imgSize, ctx.size, layer);
24
- if (!size)
25
- return { input: path, ...$pos, ...opts };
22
+ if (!size) return { input: path, ...$pos, ...opts };
26
23
  ensureSize(meta);
27
24
  const { data, info } = await input.resize(imgSize[0], imgSize[1], { fit: "fill" }).raw().toBuffer({ resolveWithObject: true });
28
25
  return {
package/layers/svg.js CHANGED
@@ -13,10 +13,8 @@ const svgLayerImpl = async (layer, _, ctx) => {
13
13
  unit,
14
14
  ...opts
15
15
  } = layer;
16
- if (path)
17
- body = readText(path, ctx.logger);
18
- if (!body)
19
- illegalArgs("missing SVG doc");
16
+ if (path) body = readText(path, ctx.logger);
17
+ if (!body) illegalArgs("missing SVG doc");
20
18
  const w = +(/width="(\d+)"/.exec(body)?.[1] || 0);
21
19
  const h = +(/height="(\d+)"/.exec(body)?.[1] || 0);
22
20
  return {
package/layers/text.js CHANGED
@@ -28,8 +28,7 @@ const textLayerImpl = async (layer, _, ctx) => {
28
28
  const y = isN ? padding : isS ? h - padding : h / 2;
29
29
  const align = isW ? "start" : isE ? "end" : "middle";
30
30
  const valign = isN ? 0.75 : isS ? 0 : 0.25;
31
- if (path)
32
- body = readText(path, ctx.logger);
31
+ if (path) body = readText(path, ctx.logger);
33
32
  const $body = isFunction(body) ? body(ctx) : body;
34
33
  const svg = [
35
34
  `<svg xmlns="${XML_SVG}" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}">`,
package/ops/dither.js CHANGED
@@ -50,8 +50,7 @@ const ditherProc = async (spec, input, ctx) => {
50
50
  channels: rgb ? [Lane.RED, Lane.GREEN, Lane.BLUE] : void 0
51
51
  });
52
52
  }
53
- if (!rgb)
54
- img = img.as(ABGR8888);
53
+ if (!rgb) img = img.as(ABGR8888);
55
54
  return [
56
55
  sharp(new Uint8Array(img.data.buffer), {
57
56
  raw: {
package/ops/output.js CHANGED
@@ -12,8 +12,7 @@ const outputProc = async (spec, input, ctx) => {
12
12
  await outputBlurHash(opts, output, ctx);
13
13
  return [input, false];
14
14
  }
15
- if (!opts.path)
16
- illegalArgs("output path missing");
15
+ if (!opts.path) illegalArgs("output path missing");
17
16
  if (opts.raw) {
18
17
  await outputRaw(opts, output, ctx, outDir);
19
18
  return [input, false];
@@ -34,43 +33,33 @@ const outputProc = async (spec, input, ctx) => {
34
33
  let format = /\.(\w+)$/.exec(opts.path)?.[1];
35
34
  switch (format) {
36
35
  case "avif":
37
- if (opts.avif)
38
- output = output.avif(opts.avif);
36
+ if (opts.avif) output = output.avif(opts.avif);
39
37
  break;
40
38
  case "gif":
41
- if (opts.gif)
42
- output = output.gif(opts.gif);
39
+ if (opts.gif) output = output.gif(opts.gif);
43
40
  break;
44
41
  case "jpg":
45
42
  case "jpeg":
46
- if (opts.jpeg)
47
- output = output.jpeg(opts.jpeg);
43
+ if (opts.jpeg) output = output.jpeg(opts.jpeg);
48
44
  break;
49
45
  case "jp2":
50
- if (opts.jp2)
51
- output = output.jp2(opts.jp2);
46
+ if (opts.jp2) output = output.jp2(opts.jp2);
52
47
  break;
53
48
  case "jxl":
54
- if (opts.jxl)
55
- output = output.jxl(opts.jxl);
49
+ if (opts.jxl) output = output.jxl(opts.jxl);
56
50
  break;
57
51
  case "png":
58
- if (opts.png)
59
- output = output.png(opts.png);
52
+ if (opts.png) output = output.png(opts.png);
60
53
  break;
61
54
  case "tiff":
62
- if (opts.tiff)
63
- output = output.tiff(opts.tiff);
55
+ if (opts.tiff) output = output.tiff(opts.tiff);
64
56
  break;
65
57
  case "webp":
66
- if (opts.webp)
67
- output = output.webp(opts.webp);
58
+ if (opts.webp) output = output.webp(opts.webp);
68
59
  break;
69
60
  }
70
- if (opts.tile)
71
- output = output.tile(opts.tile);
72
- if (format)
73
- output = output.toFormat(format);
61
+ if (opts.tile) output = output.tile(opts.tile);
62
+ if (format) output = output.toFormat(format);
74
63
  const result = await output.toBuffer();
75
64
  const path = join(
76
65
  outDir,
@@ -82,8 +71,7 @@ const outputProc = async (spec, input, ctx) => {
82
71
  };
83
72
  const outputRaw = async (opts, output, ctx, outDir) => {
84
73
  const { alpha = false, meta = false } = isPlainObject(opts.raw) ? opts.raw : {};
85
- if (alpha)
86
- output = output.ensureAlpha();
74
+ if (alpha) output = output.ensureAlpha();
87
75
  const { data, info } = await output.raw().toBuffer({ resolveWithObject: true });
88
76
  const path = join(outDir, formatPath(opts.path, ctx, opts, data));
89
77
  writeFile(path, data, null, ctx.logger);
package/ops/rotate.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import { coerceColor } from "../units.js";
2
2
  const rotateProc = async (spec, input, _) => {
3
3
  const { angle, bg, flipX, flipY } = spec;
4
- if (flipX)
5
- input = input.flop();
6
- if (flipY)
7
- input = input.flip();
4
+ if (flipX) input = input.flop();
5
+ if (flipY) input = input.flip();
8
6
  return [
9
7
  input.rotate(angle, { background: coerceColor(bg || "#0000") }),
10
8
  true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/imago",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "JSON & API-based declarative and extensible image processing trees/pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,26 +36,26 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/associative": "^6.3.59",
41
- "@thi.ng/blurhash": "^0.1.23",
42
- "@thi.ng/checks": "^3.6.3",
43
- "@thi.ng/date": "^2.7.17",
44
- "@thi.ng/defmulti": "^3.0.38",
45
- "@thi.ng/errors": "^2.5.6",
46
- "@thi.ng/file-io": "^2.1.1",
47
- "@thi.ng/logger": "^3.0.11",
48
- "@thi.ng/pixel": "^6.1.31",
49
- "@thi.ng/pixel-dither": "^1.1.129",
50
- "@thi.ng/prefixes": "^2.3.18",
39
+ "@thi.ng/api": "^8.11.2",
40
+ "@thi.ng/associative": "^6.3.60",
41
+ "@thi.ng/blurhash": "^0.1.24",
42
+ "@thi.ng/checks": "^3.6.4",
43
+ "@thi.ng/date": "^2.7.18",
44
+ "@thi.ng/defmulti": "^3.0.39",
45
+ "@thi.ng/errors": "^2.5.7",
46
+ "@thi.ng/file-io": "^2.1.2",
47
+ "@thi.ng/logger": "^3.0.12",
48
+ "@thi.ng/pixel": "^6.1.32",
49
+ "@thi.ng/pixel-dither": "^1.1.130",
50
+ "@thi.ng/prefixes": "^2.3.19",
51
51
  "sharp": "^0.33.3"
52
52
  },
53
53
  "devDependencies": {
54
- "@microsoft/api-extractor": "^7.43.0",
55
- "@thi.ng/vectors": "^7.10.30",
56
- "esbuild": "^0.20.2",
57
- "typedoc": "^0.25.12",
58
- "typescript": "^5.4.3"
54
+ "@microsoft/api-extractor": "^7.43.2",
55
+ "@thi.ng/vectors": "^7.10.31",
56
+ "esbuild": "^0.21.1",
57
+ "typedoc": "^0.25.13",
58
+ "typescript": "^5.4.5"
59
59
  },
60
60
  "keywords": [
61
61
  "avif",
@@ -185,5 +185,5 @@
185
185
  "status": "alpha",
186
186
  "year": 2024
187
187
  },
188
- "gitHead": "0bec55821066c18eb977a7eabd42c0bb2b096d98\n"
188
+ "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
189
189
  }
package/proc.js CHANGED
@@ -63,8 +63,7 @@ const processImage = async (src, specs, opts = {}, parentCtx) => {
63
63
  }
64
64
  return { img, meta, env: ctx.env, outputs: ctx.outputs };
65
65
  } finally {
66
- if (ctx.iccFile)
67
- deleteFile(ctx.iccFile, ctx.logger);
66
+ if (ctx.iccFile) deleteFile(ctx.iccFile, ctx.logger);
68
67
  }
69
68
  };
70
69
  const processor = defmulti(
package/units.d.ts CHANGED
@@ -19,11 +19,11 @@ export declare const coerceColor: (col: Color) => string | {
19
19
  * @param opts
20
20
  */
21
21
  export declare const positionOrGravity: ([w, h]: Dim, parentSize: Dim, { pos, gravity, origin, ref, unit, }: {
22
- pos?: Position | undefined;
23
- gravity?: Gravity | undefined;
24
- origin?: Gravity | undefined;
25
- ref?: SizeRef | undefined;
26
- unit?: SizeUnit | undefined;
22
+ pos?: Position;
23
+ gravity?: Gravity;
24
+ origin?: Gravity;
25
+ ref?: SizeRef;
26
+ unit?: SizeUnit;
27
27
  }) => {
28
28
  gravity: string;
29
29
  left?: undefined;
package/units.js CHANGED
@@ -13,8 +13,7 @@ const positionOrGravity = ([w, h], parentSize, {
13
13
  ref,
14
14
  unit = "px"
15
15
  }) => {
16
- if (!pos)
17
- return gravity ? { gravity: GRAVITY_MAP[gravity] } : void 0;
16
+ if (!pos) return gravity ? { gravity: GRAVITY_MAP[gravity] } : void 0;
18
17
  const [parentW, parentH] = parentSize;
19
18
  let { l, r, t, b } = pos;
20
19
  [l, r, t, b] = computeMargins(
@@ -98,8 +97,7 @@ const computeSizeWithAspect = (size, [w, h], aspect, unit = "px", clamp = true)
98
97
  }
99
98
  if (clamp) {
100
99
  size = Math.min(size, max);
101
- if (size / aspect > min)
102
- size = min * aspect;
100
+ if (size / aspect > min) size = min * aspect;
103
101
  }
104
102
  res = origAspect > 1 ? [size, size / aspect] : [size / aspect, size];
105
103
  res[0] = round(res[0]);