@thi.ng/imago 1.4.15 → 1.5.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/README.md CHANGED
@@ -33,6 +33,7 @@
33
33
  - [grayscale](#grayscale)
34
34
  - [hsbl](#hsbl)
35
35
  - [icc](#icc)
36
+ - [maxsize](#maxsize)
36
37
  - [nest](#nest)
37
38
  - [output](#output)
38
39
  - [Templated output paths](#templated-output-paths)
@@ -234,6 +235,11 @@ Assign ICC profile (from preset: `p3`, `srgb`, `cmyk` or from file). Can only be
234
235
  given directly prior to [output](#output), overrides input ICC (if any) and only
235
236
  used if output format actually supports it.
236
237
 
238
+ ### maxsize
239
+
240
+ Conditional version of [resize](#resize) operator, only applied if one of the
241
+ sides exceeds the configured size limit.
242
+
237
243
  ### nest
238
244
 
239
245
  Performing nested branches/pipelines of operations with no effect on image state
@@ -375,7 +381,7 @@ For Node.js REPL:
375
381
  const imago = await import("@thi.ng/imago");
376
382
  ```
377
383
 
378
- Package sizes (brotli'd, pre-treeshake): ESM: 5.20 KB
384
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.31 KB
379
385
 
380
386
  ## Dependencies
381
387
 
package/api.d.ts CHANGED
@@ -283,6 +283,14 @@ export interface ICCSpec extends ProcSpec {
283
283
  */
284
284
  path?: string;
285
285
  }
286
+ export interface MaxSizeSpec extends Omit<ResizeSpec, "op" | "size" | "unit"> {
287
+ op: "maxsize";
288
+ /**
289
+ * Max. image size in pixels. If given as number, the longest side will be
290
+ * used.
291
+ */
292
+ maxSize: Size;
293
+ }
286
294
  export interface NestSpec extends ProcSpec {
287
295
  op: "nest";
288
296
  /**
package/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./ops/gamma.js";
18
18
  export * from "./ops/grayscale.js";
19
19
  export * from "./ops/hsbl.js";
20
20
  export * from "./ops/icc.js";
21
+ export * from "./ops/maxsize.js";
21
22
  export * from "./ops/nest.js";
22
23
  export * from "./ops/output.js";
23
24
  export * from "./ops/resize.js";
package/index.js CHANGED
@@ -18,6 +18,7 @@ export * from "./ops/gamma.js";
18
18
  export * from "./ops/grayscale.js";
19
19
  export * from "./ops/hsbl.js";
20
20
  export * from "./ops/icc.js";
21
+ export * from "./ops/maxsize.js";
21
22
  export * from "./ops/nest.js";
22
23
  export * from "./ops/output.js";
23
24
  export * from "./ops/resize.js";
@@ -0,0 +1,3 @@
1
+ import type { Processor } from "../api.js";
2
+ export declare const maxsizeProc: Processor;
3
+ //# sourceMappingURL=maxsize.d.ts.map
package/ops/maxsize.js ADDED
@@ -0,0 +1,30 @@
1
+ import { isNumber } from "@thi.ng/checks";
2
+ import { resizeProc } from "./resize.js";
3
+ const maxsizeProc = async (spec, input, ctx) => {
4
+ const { maxSize } = spec;
5
+ const [width, height] = ctx.size;
6
+ const result = [input, false];
7
+ if (isNumber(maxSize)) {
8
+ if (width > maxSize || height > maxSize)
9
+ return resizeProc(
10
+ { ...spec, size: maxSize, unit: "px" },
11
+ input,
12
+ ctx
13
+ );
14
+ } else {
15
+ const [maxW, maxH] = maxSize;
16
+ const resizeWidth = maxW > 0 && width > maxW;
17
+ const resizeHeight = maxH > 0 && height > maxH;
18
+ const specW = { ...spec, size: [maxW, -1], unit: "px" };
19
+ const specH = { ...specW, size: [-1, maxH] };
20
+ if (width >= height) {
21
+ return resizeWidth ? resizeProc(specW, input, ctx) : resizeHeight ? resizeProc(specH, input, ctx) : result;
22
+ } else {
23
+ return resizeHeight ? resizeProc(specH, input, ctx) : resizeWidth ? resizeProc(specW, input, ctx) : result;
24
+ }
25
+ }
26
+ return result;
27
+ };
28
+ export {
29
+ maxsizeProc
30
+ };
package/ops.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BlurSpec, ColorLayer, CompLayer, CompSpec, CropSpec, DitherSpec, EXIFSpec, ExtendSpec, GammaSpec, GrayscaleSpec, HSBLSpec, ICCSpec, ImgLayer, NestSpec, OutputSpec, ProcSpec, RawLayer, ResizeSpec, RotateSpec, SVGLayer, TextLayer } from "./api.js";
1
+ import type { BlurSpec, ColorLayer, CompLayer, CompSpec, CropSpec, DitherSpec, EXIFSpec, ExtendSpec, GammaSpec, GrayscaleSpec, HSBLSpec, ICCSpec, ImgLayer, MaxSizeSpec, NestSpec, OutputSpec, ProcSpec, RawLayer, ResizeSpec, RotateSpec, SVGLayer, TextLayer } from "./api.js";
2
2
  /** @internal */
3
3
  export declare const defSpec: <T extends ProcSpec>(op: T["op"]) => (opts: Omit<T, "op">) => T;
4
4
  /** @internal */
@@ -68,6 +68,10 @@ export declare const hsbl: (opts: Omit<HSBLSpec, "op">) => HSBLSpec;
68
68
  * Creates a new {@link ICCSpec} with given opts.
69
69
  */
70
70
  export declare const icc: (opts: Omit<ICCSpec, "op">) => ICCSpec;
71
+ /**
72
+ * Creates a new {@link MaxSizeSpec} with given opts.
73
+ */
74
+ export declare const maxsize: (opts: Omit<MaxSizeSpec, "op">) => MaxSizeSpec;
71
75
  /**
72
76
  * Creates a new {@link NestSpec} with given opts.
73
77
  */
package/ops.js CHANGED
@@ -15,6 +15,7 @@ const gamma = defSpec("gamma");
15
15
  const grayscale = defSpec("gray");
16
16
  const hsbl = defSpec("hsbl");
17
17
  const icc = defSpec("icc");
18
+ const maxsize = defSpec("maxsize");
18
19
  const nest = defSpec("nest");
19
20
  const output = defSpec("output");
20
21
  const resize = defSpec("resize");
@@ -34,6 +35,7 @@ export {
34
35
  hsbl,
35
36
  icc,
36
37
  imageLayer,
38
+ maxsize,
37
39
  nest,
38
40
  output,
39
41
  rawLayer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/imago",
3
- "version": "1.4.15",
3
+ "version": "1.5.0",
4
4
  "description": "JSON & API-based declarative and extensible image processing trees/pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -160,6 +160,9 @@
160
160
  "./ops/icc": {
161
161
  "default": "./ops/icc.js"
162
162
  },
163
+ "./ops/maxsize": {
164
+ "default": "./ops/maxsize.js"
165
+ },
163
166
  "./ops/nest": {
164
167
  "default": "./ops/nest.js"
165
168
  },
@@ -189,5 +192,5 @@
189
192
  "status": "alpha",
190
193
  "year": 2024
191
194
  },
192
- "gitHead": "74b6f319d8f52c9266d97f616be5298a6a5b96e4\n"
195
+ "gitHead": "88d4b13485639f44b3c5cb5e0a73e0a3490eba85\n"
193
196
  }
package/proc.js CHANGED
@@ -13,6 +13,7 @@ import { gammaProc } from "./ops/gamma.js";
13
13
  import { grayscaleProc } from "./ops/grayscale.js";
14
14
  import { hsblProc } from "./ops/hsbl.js";
15
15
  import { iccProc } from "./ops/icc.js";
16
+ import { maxsizeProc } from "./ops/maxsize.js";
16
17
  import { nestProc } from "./ops/nest.js";
17
18
  import { outputProc } from "./ops/output.js";
18
19
  import { resizeProc } from "./ops/resize.js";
@@ -93,6 +94,7 @@ const processor = defmulti(
93
94
  gray: grayscaleProc,
94
95
  hsbl: hsblProc,
95
96
  icc: iccProc,
97
+ maxsize: maxsizeProc,
96
98
  nest: nestProc,
97
99
  output: outputProc,
98
100
  resize: resizeProc,