@thi.ng/imago 0.5.2 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-03-01T15:22:50Z
3
+ - **Last updated**: 2024-03-06T08:50:42Z
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,13 @@ 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.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.6.0) (2024-03-06)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update ImgProcOpts/Ctx, add custom env object ([2b160e0](https://github.com/thi-ng/umbrella/commit/2b160e0))
17
+ - update processImage() & result
18
+
12
19
  ## [0.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.5.0) (2024-03-01)
13
20
 
14
21
  #### 🚀 Features
package/README.md CHANGED
@@ -344,7 +344,7 @@ For Node.js REPL:
344
344
  const imago = await import("@thi.ng/imago");
345
345
  ```
346
346
 
347
- Package sizes (brotli'd, pre-treeshake): ESM: 4.81 KB
347
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.82 KB
348
348
 
349
349
  ## Dependencies
350
350
 
package/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { Fn, Fn3, Keys, Range1_4, TypedArray } from "@thi.ng/api";
2
+ import type { Fn, Fn3, IObjectOf, Keys, Range1_4, TypedArray } from "@thi.ng/api";
3
3
  import type { ILogger } from "@thi.ng/logger";
4
4
  import type { AvifOptions, Blend, Exif, ExtendWith, FitEnum, GifOptions, Jp2Options, JpegOptions, JxlOptions, KernelEnum, Metadata, OverlayOptions, PngOptions, Sharp, TiffOptions, TileOptions, WebpOptions } from "sharp";
5
5
  /**
@@ -407,6 +407,17 @@ export interface ImgProcOpts {
407
407
  * replacement IDs, e.g. allowing to override `name`, `date` etc.
408
408
  */
409
409
  pathParts: Record<string, Fn3<ImgProcCtx, OutputSpec, BufferLike, string> | string>;
410
+ /**
411
+ * User provided environment, i.e. an object to provide arbitrary values to
412
+ * {@link Processor}s and for them to store results in.
413
+ *
414
+ * @remarks
415
+ * Note: This option is optional. Processors should only access the
416
+ * environment via {@link ImgProcCtx.env} which ensures the object is
417
+ * defined and it is only that version which will also be returned as part
418
+ * of the results from {@link processImage}...
419
+ */
420
+ env?: IObjectOf<any>;
410
421
  }
411
422
  export interface ImgProcCtx {
412
423
  path?: string;
@@ -421,6 +432,10 @@ export interface ImgProcCtx {
421
432
  * {@link output}.
422
433
  */
423
434
  outputs: Record<string, string>;
435
+ /**
436
+ * See {@link ImgProcOpts.env} for details/comments.
437
+ */
438
+ env: IObjectOf<any>;
424
439
  }
425
440
  export declare const GRAVITY_POSITION: Record<Gravity, string>;
426
441
  export declare const GRAVITY_MAP: Record<Gravity, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/imago",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "JSON & API-based declarative and extensible image processing trees/pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -180,5 +180,5 @@
180
180
  "status": "alpha",
181
181
  "year": 2024
182
182
  },
183
- "gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
183
+ "gitHead": "f6bb0e172c5dcb574b961f5155a50040d5569685\n"
184
184
  }
package/proc.d.ts CHANGED
@@ -4,12 +4,14 @@ export declare const LOGGER: import("@thi.ng/logger").ProxyLogger;
4
4
  /**
5
5
  * Main API function. Takes an image input (file path, buffer or existing Sharp
6
6
  * instance) and applies given processing pipeline specs in sequence. Returns a
7
- * promise of final processed image, input metadata (if any) and an object of
8
- * all written output paths (keyed by each output's {@link OutputSpec.id}). The
9
- * process can be configured via provided options.
7
+ * promise of final processed image, input metadata (if any), an environment
8
+ * object of arbitrary data (likely produced by custom ops/processors) and an
9
+ * object of all written output paths (keyed by each output's
10
+ * {@link OutputSpec.id}). The process pipeline can be additionally configured
11
+ * via provided options.
10
12
  *
11
13
  * @remarks
12
- * The `parentCtx` arg is internal use only!
14
+ * The `parentCtx` arg is internal use only (nested processors)!
13
15
  *
14
16
  * @param src
15
17
  * @param specs
@@ -19,6 +21,7 @@ export declare const LOGGER: import("@thi.ng/logger").ProxyLogger;
19
21
  export declare const processImage: (src: string | BufferLike | ArrayBuffer | Sharp, specs: ProcSpec[], opts?: Partial<ImgProcOpts>, parentCtx?: ImgProcCtx) => Promise<{
20
22
  img: sharp.Sharp;
21
23
  meta: sharp.Metadata;
24
+ env: import("@thi.ng/api").IObjectOf<any>;
22
25
  outputs: Record<string, string>;
23
26
  }>;
24
27
  /**
package/proc.js CHANGED
@@ -25,6 +25,7 @@ const processImage = async (src, specs, opts = {}, parentCtx) => {
25
25
  const ctx = {
26
26
  path: isString(src) ? src : parentCtx?.path,
27
27
  outputs: parentCtx ? parentCtx.outputs : {},
28
+ env: parentCtx ? parentCtx.env : opts.env || {},
28
29
  logger: opts.logger || LOGGER,
29
30
  size: [meta.width, meta.height],
30
31
  exif: parentCtx ? structuredClone(parentCtx.exif) : {},
@@ -59,7 +60,7 @@ const processImage = async (src, specs, opts = {}, parentCtx) => {
59
60
  }
60
61
  });
61
62
  }
62
- return { img, meta, outputs: ctx.outputs };
63
+ return { img, meta, env: ctx.env, outputs: ctx.outputs };
63
64
  } finally {
64
65
  if (ctx.iccFile)
65
66
  deleteFile(ctx.iccFile, ctx.logger);