@thi.ng/imago 0.7.6 → 0.7.8

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-06-21T19:34:38Z
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.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [0.7.8](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.7.8) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [0.7.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.7.3) (2024-04-20)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -357,7 +357,7 @@ For Node.js REPL:
357
357
  const imago = await import("@thi.ng/imago");
358
358
  ```
359
359
 
360
- Package sizes (brotli'd, pre-treeshake): ESM: 4.93 KB
360
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.92 KB
361
361
 
362
362
  ## Dependencies
363
363
 
package/api.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Fn, Fn3, IObjectOf, Keys, Range1_4, TypedArray } from "@thi.ng/api";
3
2
  import type { ILogger } from "@thi.ng/logger";
4
3
  import type { AvifOptions, Blend, Exif, ExtendWith, FitEnum, GifOptions, Jp2Options, JpegOptions, JxlOptions, KernelEnum, Metadata, OverlayOptions, PngOptions, Sharp, TiffOptions, TileOptions, WebpOptions } from "sharp";
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
@@ -9,13 +9,12 @@ const outputProc = async (spec, input, ctx) => {
9
9
  const outDir = resolve(ctx.opts.outDir || ".");
10
10
  let output = input.clone();
11
11
  if (opts.blurhash) {
12
- await outputBlurHash(opts, output, ctx);
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
- await outputRaw(opts, output, ctx, outDir);
17
+ await __outputRaw(opts, output, ctx, outDir);
19
18
  return [input, false];
20
19
  }
21
20
  if (ctx.meta.exif && ctx.opts.keepEXIF) {
@@ -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,
@@ -80,10 +69,9 @@ const outputProc = async (spec, input, ctx) => {
80
69
  ctx.outputs[opts.id] = path;
81
70
  return [input, false];
82
71
  };
83
- const outputRaw = async (opts, output, ctx, outDir) => {
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);
@@ -98,7 +86,7 @@ const outputRaw = async (opts, output, ctx, outDir) => {
98
86
  );
99
87
  }
100
88
  };
101
- const outputBlurHash = async (opts, output, ctx) => {
89
+ const __outputBlurHash = async (opts, output, ctx) => {
102
90
  const { data, info } = await output.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
103
91
  const detail = opts.blurhash === true ? 4 : opts.blurhash;
104
92
  const [dx, dy] = isNumber(detail) ? [detail, detail] : detail;
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.8",
4
4
  "description": "JSON & API-based declarative and extensible image processing trees/pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/imago#readme",
13
+ "homepage": "https://thi.ng/imago",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -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",
51
- "sharp": "^0.33.3"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/associative": "^6.3.61",
41
+ "@thi.ng/blurhash": "^0.1.25",
42
+ "@thi.ng/checks": "^3.6.5",
43
+ "@thi.ng/date": "^2.7.19",
44
+ "@thi.ng/defmulti": "^3.0.40",
45
+ "@thi.ng/errors": "^2.5.8",
46
+ "@thi.ng/file-io": "^2.1.3",
47
+ "@thi.ng/logger": "^3.0.13",
48
+ "@thi.ng/pixel": "^6.1.33",
49
+ "@thi.ng/pixel-dither": "^1.1.131",
50
+ "@thi.ng/prefixes": "^2.3.20",
51
+ "sharp": "^0.33.4"
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.47.0",
55
+ "@thi.ng/vectors": "^7.11.0",
56
+ "esbuild": "^0.21.5",
57
+ "typedoc": "^0.25.13",
58
+ "typescript": "^5.5.2"
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": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
189
189
  }
package/path.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { TypedArray } from "@thi.ng/api";
3
2
  import type { ImgProcCtx, OutputSpec } from "./api.js";
4
3
  /**
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
@@ -6,7 +6,7 @@ export declare const coerceColor: (col: Color) => string | {
6
6
  r: number;
7
7
  g: number;
8
8
  b: number;
9
- alpha?: number | undefined;
9
+ alpha?: number;
10
10
  };
11
11
  /**
12
12
  *
@@ -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]);